Network Layer The Network Layer Recall: The network layer is responsible for the routing of packets The network layer is responsible for congestion control 1 2 Contents 4.1.1 Connection-Oriented and Connectionless Service Connection-Oriented (virtual circuit) and Connectionless Service (datagram service) The IP Protocol IP-Support Protocols Routing Algorithms Congestion Control Network layers can offer two types of service to the transport layer: Connection-oriented service (virtual circuit) Connection setup required before communication begins Network layer provides the Transport layer with a reliable service: in-sequence delivery, flow control Connectionless service (datagram service) No prior connection setup required Packets are stored and forwarded one at a time by IMPs 3 4
4.1.1 Connection-Oriented Service Connection-Oriented Service: Analogy How to provide connection-oriented service: Set up a route (virtual circuit) between source and destination That route is used for all traffic flowing over the virtual circuit Switch maintains an internal table to tell which outgoing line to forward packet on for each active virtual circuit Packets must contain a virtual circuit number so that the switch can figure out how to forward them Public Telephone Network Set up a virtual circuit (dial a number) Transmit data on the circuit (conversation) Close down the virtual circuit (hang up) Two users are provided with the illusion of a dedicated point-to-point channel Information is delivered to the receiver in the same order in which it is transmitted by the sender 5 6 Connectionless Service Connectionless Service: An Analogy How to provide connectionless service: Send the packet into the network and allow the network to forward it however it likes Switches maintain routing tables to look up the next switch for each arriving packet Each packet must contain a destination address so the switches can make routing decisions Postal service: Each packet (letter) is transported as an individual entity Each packet (letter) must carry the complete destination address If a packet (letter) is lost, error control is the user s responsibility Packets (letters) do not necessarily arrive in the order sent 7 8
4.1.2 Comparison between Connectionless and Connection- Oriented Services Comparison (cont d) Connection Setup Procedure: Connection-oriented service Explicit setup and tear-down required For short transaction oriented communication, the delay of connection setup may be expensive Connectionless service No setup or tear-down required For long continuous communication, the overhead of packet headers may be expensive Header Overhead Connection-oriented service Only the virtual circuit number Connectionless service The full destination address is required 9 10 Comparison (cont d) Message Sequence: Connection-oriented service Sequence of packets automatically maintained Connectionless service Destination may have to re-sequence out-oforder packets Comparison (cont d) Robustness Connection-oriented service Vulnerable: If a switch crashes, all virtual circuits passing through it have to be aborted and re-established Connectionless service Robust: If a router goes down, only hosts whose packets were queued at the time of the crash are lost. Other packets will be rerouted dynamically. 11 12
Comparison (cont d) Guaranteed service: Connection-oriented service Can provide guarantees on the delays and throughput of packets being sent Connectionless service It is very difficult to provide guarantees for timely packet delivery Summary Connection-oriented service Is useful for applications which prefer insequence delivery of packets. It is also preferable for applications that require guaranteed service Connectionless service Provides flexibility in the routing and handling of individual packets and is robust in the face of router crashes 13 14 4.4 The Internet Protocol (IP) Provides delivery of packets from one host in the Internet to any other host in the Internet, even if the hosts are on different networks Internet packets are called datagrams and may be up to 64 kilobytes in length (although they are typically much smaller) Internet IMPs are known as routers and they operate in a connectionless mode 4.4.1 IP Packet Format 32 bits Ver. IHL Type of Serv. Total Length D M Identification F F Fragment Offset Time to Live Protocol Header checksum Source address Destination address Options (0 or more 32-bit words) Data (0 to 65,515 bytes) 15 16
IP Packet Fields IP Packet Fields (cont d) Version IHL The IP version number (currently 4) IP Header Length in 32-bit words Type of Service Contains priority information, rarely used Total Length The total length of the datagram in bytes Includes header Identification When an IP packet is segmented into multiple fragments, each fragment is given the same identification This field is used to reassembly fragments DF Don t Fragment MF More Fragments When a packet is fragmented, all fragments except the last one have this bit set 17 18 IP Packet Fields (cont d) Fragment offset The fragment s position within the original packet Time to Live Hop count, decremented each time the packet reaches a new router When hop count = 0, packet is discarded Protocol Identifies which transport layer protocol is being used for this packet Header Checksum Verifies the contents of the IP header Not polynomial-based IP Packet Fields (cont d) Source and Destination Addresses Uniquely identify sender and receiver of the packet Options Up to 40 bytes in length Used to extend functionality of IP Examples: source routing, security, record route 19 20
IP Addresses IP Address Classes 32 bits long Notation: Each byte is written in decimal in MSB order, separated by decimals Example: 128.195.1.80 Address Classes Class A, B, C, D, E Loopback Broadcast Class A B C D E 0 Net 32 bits Type of Serv. 24 bit Host 10 Net 16 bit Host 110 Net 8 bit Host 1110 Multicast address 11110 Reserved 21 22 IP Address Classes Class A: For very large organizations 16 million hosts allowed Class B: For large organizations 65 thousand hosts allowed Class C For small organizations 255 hosts allowed Class D Multicast addresses No network/host hierarchy Example Class A 1.0.0.0 to 126.0.0.0 Class B 128.1.0.0 191.255.0.0 Class C 192.0.1.0 223.2555.255.0 Class D 224.0.0.0 239.255.255.255 Class E 240.0.0.0 to 255.255.255.254 All 0s, (this host) all 0 s for the network part All 1s, limited broadcast Net.id, host id all 1s directed broadcast for the network 127.x.y.z (often 1s) is used for loopback within the same host 23 24
IP Address Hierarchy Subnetting Note that Class A, Class B, and Class C addresses only support two levels of hierarchy Each address contains a network and a host portion, meaning two levels of hierarchy However, the host portion can be further split into subnets by the address class owner This allows for more than 2 levels of hierarchy Example Address: Example: Class B address with 8-bit subnetting 16 bits 8 bits 8 bits Network id Subnet id Host id 165.230.24.8 25 26 Subnet Masks Subnet Masks (cont d) Mask: Subnet masks allow hosts to determine if another IP address is on the same subnet or the same network 16 bits 8 bits 8 bits Network id Subnet id Host id 1111111111111111 11111111 00000000 255.255.255.0 27 Assume IP addresses A and B share subnet mask M. Are IP addresses A and B on the same subnet? 1. Compute (A and M). 2. Compute (B and M). 3. If (A and M) = (B and M) then A and B are on the same subnet. Example: A and B are class B addresses A = 165.230.82.52 Same network? B = 165.230.24.93 Same subnet? M = 255.255.255.0 28
Example Example Default netmasks Class A 98.0.0.0 (16 M hosts for each address) 255.0.0.0 net mask Class B 140.14.0.0 (64K hosts for each address) 255.255.0.0 net mask Class C address 192.6.8.0 (256 hosts for each address) 255.255.255.0 Subnetting allows subdivision of a network A rotorouter company is given 201.70.64.0 wants 8 subnets What is the subnet mask? How many host per subnet? 29 30 Example Variable length subnetting A bachelorette company is granted an address 181.56.0.0 The company needs 1000 subnets What is the subnet mask How many host per subnet Assume a company wants to have five subnets with 60, 60, 60, 30, 30 hosts Subnet masks allow power of 2 subnets Use a hierarchy of routers to allow subnets to be divided with different subnet masks Another approach: Variable length subnet masks or use two different subnet masks 255.255.255.192 for the first three and the fourth is subdivided into 2 more with 255.255.255.224 31 32
Variable length subnetting 2.3 IP Routing 64 (60) 64 (60) 255.255.255.192 255.255.255.192 L0 L1 How do you get a packet from one network to another? 64(60) 32 (60) 32 (60) 255.255.255.192 255.255.255.224 255.255.255.224 L2 L3 L4? A B C D W X Y Z 33 34 IP Routing (cont d) Example Answer: with a router (or a series of routers) Case 1: R Single hop Case 2: Multi-hop A B C D W X Y Z R Network Cloud A B C D W X Y Z R 35 N1 R1 R2 R3 N2 Routing table @ R2 N3 Dest Next hop N1 R1 N2 Deliver directly N3 Deliver directly N4 R3 N4 Actual routing table contains IP addresses, Flags indicating type of entries, net mask etc. (see Stevens pg. 113, sect 9.2) 36
Searching the routing table IP Support Protocols First, search for a matching host address Flag H is set Second, search for a matching network address Need to know the number of bits to use for network ID Third, search for a default entry Execute netstat -rn on your machine and find the contents of the routing table Default entry allows for a single entry for a list of entries that have the same next-hop value ARP RARP ICMP 37 38 ARP ARP (cont d) Address Resolution Protocol Returns a MAC sublayer address when given an Internet address Commonly used in broadcast LANs so that two hosts can communicate using IP addresses instead of MAC sublayer addresses 39 ARP Ethernet Address: 05:23:f4:3d:e1:04 IP Address: 128.195.1.20 Wants to transmit to 128.195.1.38 ARP packet containing 128.195.1.38? Ethernet Address: 12:04:2c:6e:11:9c IP Address: 128.195.1.122 Ignored Ethernet Address: 98:22:ee:f1:90:1a IP Address: 128.195.1.38 Answered 40
ARP (cont d) RARP Ethernet Address: 05:23:f4:3d:e1:04 IP Address: 128.195.1.20 Ethernet Address: 12:04:2c:6e:11:9c IP Address: 128.195.1.122 ARP response packet containing 98:22:ee:f1:90:1a Repl Ethernet Address: 98:22:ee:f1:90:1a IP Address: 128.195.1.38 Reverse Address Resolution Protocol RARP performs the inverse action of ARP RARP returns an IP address for a given MAC sublayer address Operationally, RARP is the same as ARP 41 42 ICMP ICMP Internet Control Message Protocol Handles special Internet control functions Responsibilities: Reporting unreachable destinations Reporting IP packet header problems Reporting routing problems Reporting echoes (pings) Protocol for error detection and reporting tightly coupled with IP, unreliable ICMP messages delivered in IP packets ICMP functions: Announce network errors Announce network congestion Assist trouble shooting Announce timeouts 43 44
ICMP MSG Specific uses of ICMP IP header Source, Destination Address, TTL,... ICMP MSG Message type, Code, Checksum, Data Message type examples (Figure 6.3 in Stevens book): 0 (8) echo request (reply) 3 destination unreachable 4 source quench Echo request reply Can be used to check if a host is alive Address mask request/reply Learn the subnet mask Destination unreachable Invalid address and/or port TTL expired Routing loops, or too far away 11 time exceeded 45 46 Ping Ping (cont d) Uses ICMP echo request/reply Source sends ICMP echo request message to the destination address Echo request packet contains sequence number and timestamp Destination replies with an ICMP echo reply message containing the data in the original echo request message Source can calculate round trip time (RTT) of packets If no echo reply comes back then the destination is unreachable Time A Echo request R1 R2 R3 B Echo reply 47 48
Traceroute Traceroute records the route that packets take A clever use of the TTL field When a router receives a packet, it decrements TTL If TTL=0, it sends an ICMP time exceeded message back to the sender To determine the route, progressively increase TTL Every time an ICMP time exceeded message is received, record the sender s (router s) address Repeat until the destination host is reached or an error message occurs 49 Time Traceroute (cont d) A R1 R2 R3 TTL=1, Dest = B, port = invalid Te (R1) TTL=2, Dest = B Te (R2) TTL=3, Dest = B Te (R3) TTL=4, Dest = B Te = Time exceeded Pu = Port unreachable Pu (B) B 50