Rensselaer Polytechnic Institute CSCI-4220 – Network Programming David Goldschmidt, Ph.D. In reality, not all layers are always used.... The Internet uses only four layers: Application Transport Network Physical Each layer prepends or appends its information in a header or trailer HTTP Request TCP Hdr | HTTP Request IP Hdr | TCP Hdr | HTTP Request Ethernet Hdr | IP Hdr | TCP Hdr | HTTP Request | Cksum P Ethernet encompasses both the data link layer and the physical layer Ethernet (really IEEE 802.3) Ethernet provides a shared medium (multi-access) Ethernet Every Ethernet interface is assigned a unique 48-bit (hardware) address Represented as a sequence of 6 hexadecimal bytes delimited by ':' characters: ▪ 00:50:56:9F:27:3E ▪ (use /sbin/ifconfig to see network interfaces) Also known as MAC address or physical address Ethernet addresses are assigned to vendors by a central authority Messages are sent over Ethernet via frames: Preamble Destination Address Source Address Len Data CRC 8 bytes 6 bytes 6 bytes 2 ≤ 1500 bytes 4 bytes The Preamble is a sequence of alternating 1s and 0s for synchronization ▪ In hex: AAAAAAAAAAAAAAAB Transmitters are required to send an Interframe Gap of at least 12 octets How does an Ethernet interface know when it can transmit a frame? CSMA/CD Carrier Sense (CS): a transmitter can tell when another host is transmitting data Multiple Access (MA): many transmitters Collision Detection (CD): a transmitter can tell when another host is transmitting data that collides with its own transmission How does an Ethernet interface know when it should receive a frame? Receivers look at all frames, discarding frames not addressed to them Receivers only receive frames addressed to them (or broadcast messages) Each layer on the client side logically communicates with the same layer on the server side Q server client intermediate router P IP is the network layer IP provides host-to-host delivery service of packets (called datagrams) IP is connectionless IP is unreliable IP also provides translation between different data link protocols IP addresses are logical addresses at the network layer IP addresses are not Ethernet addresses Why is this important? IP must be able to provide communication between hosts on different types of networks (i.e. different data link implementations) An IP address contains information about what network the destination host is on This enables routing at the network layer An IP address (IPv4) is a series of 4 octets ▪ 128.113.2.68 (www.rpi.edu) ▪ 128.113.126.13 (www.cs.rpi.edu) ▪ 128.213.56.14 (mary-kate.cs.rpi.edu) Each IP address contains information that identifies the network ID and the host ID Routing tables rely on IP address classes: from, you guessed it, Wikipedia! Decoding IP Addresses: A 0 B 10 C 110 NetID D 1110 Multicast Address NetID HostID NetID HostID CLASS 8 bits 8 bits HostID 8 bits 8 bits An organization can further subdivide its host (HostID) space into subnets: B 10 NetID 10 NetID 8 bits 8 bits HostID SubnetID HostID 8 bits 8 bits router Subnet Q 128.213.1.x Subnet R 128.213.2.x Subnet S 128.213.3.x Other subnetting notes: Subnets can simplify routing IP subnet broadcasts have a HostID of all 1s It is possible to have a single wire network with multiple subnets: ▪ How would this work? IP addresses are logical addresses; therefore we need to map them to physical addresses If we know the IP address of a host, how do we find out the hardware address? Address resolution is the process of finding the hardware address of a host from a given IP address ARP is used by a host when it needs to determine a physical (Ethernet) address from a given IP address ARP is what’s known as a broadcast protocol Every host on the network That’s me! receives the ARP request Only the “right” one responds Address resolution does not need to be performed every time an IP datagram is sent Hosts cache IP-to-hardware I know! I remember you. address mappings This happens on both ends ▪ i.e. the receiver also caches the IP-to-hardware address mapping of the transmitter Me too! Hey everyone! Will IP 128.213.56.14 send me your Ethernet address? Not me. Not me. Not me. Sure, that’s me! My Ethernet address is 3F:55:83:02:AB:79. IP provides the following: Connectionless delivery ▪ i.e. each datagram is individually routed Unreliable (non-guaranteed) delivery Fragmentation and reassembly ▪ Only at the source and destination hosts ▪ If fragments are lost, the entire datagram is discarded Routing Error detection (via ICMP) http://tools.ietf.org/html/rfc1122 8 bits VERS HL 8 bits 8 bits Service Fragment Length Datagram ID TTL 8 bits FLAG Protocol Fragment Offset Header Checksum Source Address Destination Address Options (if any) Data http://tools.ietf.org/html/rfc792 Internet Control Message Protocol (ICMP): ICMP is used to transmit control (or out-of-band) messages ICMP uses IP for delivery ICMP messages are usually generated and processed by the IP software (not user processes) ICMP message types include: Echo Request (ping) Echo Response (ping) Destination Unreachable Redirect Time Exceeded etc. Two protocols at the Transport Layer: Transmission Control Protocol (TCP) ▪ Connection-oriented ▪ Reliable byte-streaming ▪ Full-duplex ▪ 3-way handshake (SYN/ACK/ACK) to establish a connection User Datagram Protocol (UDP) ▪ Connectionless and unreliable click me http://www.ietf.org/rfc/rfc768.txt Source Port Destination Port Length Checksum Data 8 bits 8 bits 8 bits 8 bits http://www.ietf.org/rfc/rfc793.txt 8 bits 8 bits 8 bits Source Port 8 bits Destination Port Sequence Number Acknowledgment Number Data Offset Reserved Window Control Urgent Pointer Checksum Options (if any) Data Which is better? TCP or UDP? Serving up Web pages Financial transaction processing Video-streaming server File transfer Email Chat Robotic surgery controlled remotely Get out of my way, humans!