Network Layer Packet and Packet Header Encapsulation
Total Page:16
File Type:pdf, Size:1020Kb
Network Layer DNS Where are we now? application socket API Computer Networks transport network link physical Lecture 6: IPv4, CIDR, ICMP Previously . the Internet is a packet switched network: • data is parceled into packets • each packet carries a destination address • each packet is routed independently Packet and Packet Header Encapsulation Each protocol has its own “envelope” Protocols are rules (“syntax” and “grammar” ) • each protocol attaches its header to the packet GoverninG communication between nodes • so we have a protocol wrapped/encapsulated inside another protocol • each layer of header contains a protocol de-multiplexinG field to identify the “packet handler” Just as with the postal system, the “content” you want source the next layer up, e.G., to send must be put into an envelope and the M application H M transport • protocol number t H H M envelope must be addressed n t network H H H M • port number l n t link physical Hl Hn Ht M H H H M link l n t The “envelope” in this case is the packet header physical switch The format of a packet header is part of the protocol packet not package H H M H H destination n t network n t M message H H H M H H H M M application l n t link l n t For the Internet, the network-layer protocol is the seGment Ht M transport physical dataGram/packet H H M n t network Internet Protocol (IP) H H H M frame l n t link router physical IPv4 Packet Header Format Packet ForwardinG 4 bits 4 bits 8 bits 16 bits Goal: deliver packets throuGh routers from source to hdr len Type of Service destination usually IPv4 version (bytes) (TOS) Total lenGth (bytes) • source node puts destination address in packet header 3-bit Identification flags 13-bit FraGment Offset • each router node on the Internet: routinG alGorithm upper layer protocol 20-byte • looks up destination address to whom payload is Time to Header Live (TTL) Protocol Header Checksum local forwardinG table delivered, e.G., ICMP in its routinG/forwardinG table dest address output link (1), UDP (17), TCP (6) • we’ll study several path selection 0100 3 Source IP Address 0101 2 (i.e., routinG) alGorithms 0111 2 1001 1 Destination IP Address • sends the packet to the next hop destination towards the destination address in e.g. timestamp, packet’s header record route, Options (if any) • routes may chanGe durinG session 1 source route 0111 • analoGy: drivinG, askinG directions 3 2 Payload (e.g., TCP/UDP packet, max size?) IPv4 AddressinG: Introduction Flat vs. Hierarchical AddressinG 4 223.1.1.1 Flat addressinG: 1 2 IPv4 address: 32-bit 2 2 223.1.2.1 • each router needs 10 entries 3 2 identifier for host/router 223.1.1.2 in its routinG table 4 - 223.1.1.4 223.1.2.9 5 5 6 6 interface 7 7 223.1.2.2 8 2 223.1.1.3 223.1.3.27 Hierarchical addressinG: 9 7 10 2 interface (if): connection • hosts only need to know the 11 2 between host/router and default router, usually its physical link 223.1.3.1 223.1.3.2 border router • each border router keeps in • routers typically have 3.1 its routinG table: 2.* 2.1 multiple interfaces 223.1.1.1 = 11011111 00000001 00000001 00000001 1.* 1.1 • addresses of all hosts within its own • 4.* 2.1 host may have 223 1 1 1 network 3.2 3.2 3.3 3.3 multiple interfaces • next hop address of other networks 3.4 3.4 (Cf. forwardinG table stores the outGoinG interface number) IPv4 AddressinG Subnets Independent of physical hardware address A network can be further 223.1.1.1 32-bit number represented as dotted decimal: 223.1.2.1 divided into subnets 223.1.1.2 • for ease of reference 223.1.1.4 223.1.2.9 • each # is the decimal representation of an octet What makes a subnet ? 223.1.2.2 223.1.1.3 223.1.3.27 Divided into two parts: • the IP addresses of all LAN • network prefix, globally assigned interfaces within a subnet • route to network first have the same network 223.1.3.1 223.1.3.2 • host ID, assigned locally 12 34 158 5 prefix 00001100 00100010 10011110 00000101 • hosts within a subnet can Network (24 bits) Host (8 bits) a network consistinG of 3 subnets Example: 12.34.158.0/24 physically reach each other without interveninG router is a 24-bit network prefix with 28 host addresses Classfull Addresses Classfull Addresses For the example network prefix: 12.34.158.0/24 Problems: • how many hosts can the network have? 1. everybody wanted a Class B address (the Goldilock problem) 2. address space usaGe became inefficient What is a Good partition of the 32-bit address 3. routinG table explosion 4. and then, address space became scarce… space between the network and host parts? • by 1992, half of Class B had been allocated, would have been exhausted by 3/94 Historically . classfull addresses: Class A: 0[10]*, very large /8 blocks (e.g., MIT has 18.0.0.0/8) Solution: Class B: 10[10]*, large /16 blocks (e.G,. UM has 141.213.0.0/16) Make network portion of address arbitrary lenGth, Class C: 110[10]*, small /24 blocks (e.g., AT&T Labs has determined by a prefix mask 192.20.225.0/24) • uses two 32-bit numbers to represent a network address Class D: 1110[10]*, multicast Groups • network address = IP address & prefix mask Class E: 11110[10]*, reserved for future use Classless InterDomain Routing (CIDR) CIDR: Hierarchical Address Allocation Usually written as a.b.c.d/x, where x is number of Prefixes are key to Internet routinG scalability bits in the network portion of the address: 12.4.0.0/15 • address allocation by ICANN, ARIN/RIPE/APNIC and by ISPs • IP address: routinG protocols and packet forwardinG based on prefixes 12.4.0.0 00001100 00000100 00000000 00000000 • today, routinG tables contain ~150,000-200,000 prefixes prefix mask: 12.0.0.0/16 255.254.0.0 11111111 11111110 00000000 00000000 12.1.0.0/16 12.3.0.0/24 : network prefix for hosts 12.2.0.0/16 12.3.1.0/24 : : 12.3.0.0/16 : Another example (not at octet boundary!): : 12.3.254.0/24 12.0.0.0/8 : 200.23.16.0/23 : 12.253.0.0/19 network host : 12.253.32.0/19 prefix part 12.253.64.0/19 11001000 00010111 00010000 00000000 12.253.0.0/16 12.253.96.0/19 12.253.128.0/19 12.254.0.0/16 12.253.160.0/19 12.253.192.0/19 CIDR: Route AGGreGation LonGest Prefix Match: Hierarchical addressinG allows efficient More Specific Routes advertisement of routinG information: ISPs-R-Us has a more specific route to Organization 1 Organization 0 200.23.16.0/23 Organization 0 Organization 1 200.23.16.0/23 “Send me anythinG 200.23.18.0/23 with addresses “Send me anythinG beginninG Organization 2 with addresses 200.23.16.0/20” Organization 2 beginning 200.23.20.0/23 . Fly-By-NiGht-ISP 200.23.16.0/20” . 200.23.20.0/23 . Fly-By-NiGht-ISP . Internet . Internet Organization 7 . 200.23.30.0/23 Organization 7 200.23.30.0/23 ISPs-R-Us “Send me anythinG with addresses ISPs-R-Us “Send me anythinG beginning with addresses 199.31.0.0/16” Organization 1 beginning 199.31.0.0/16 or 200.23.18.0/23” 200.23.18.0/23 Packet ForwardinG Summary Special IPv4 Addresses ForwardinG is destination-based: Network identification: • 0s on host part, e.G. ,141.212.0.0 (cannot be used to send packets) • packet has a destination address forwardinG table Directed broadcast: • router identifies lonGest-matchinG prefix 4.0.0.0/8 • 0xffff on host part, e.G., 141.212.255.255 4.83.128.0/17 destination 12.0.0.0/8 • broadcast to all hosts on a network (e.G., 141.212) (not implemented) ForwardinG table: 12.34.158.5 12.34.158.0/24 • maps each IP prefix to next-hop link(s) 126.255.103.0/24 Limited broadcast: • 0xffffffff, received by all hosts on LAN, not forwarded beyond LAN • entries can be statically confiGured outgoing link • e.G., “map 12.34.158.0/24 to Serial0/0.1” Serial0/0.1 This computer: • 0.0.0.0 used at startup to solicit IP address with RARP (deprecated) But, this doesn’t adapt to That is where routinG Loopback address: • failures protocols come in… • 127.*.*.* (usually 127.0.0.1), named localhost • new equipment [more on routinG later • packets sent to localhost traverse down the kernel networkinG code • the need to balance load to the network layer and back up to the application without traversinG in the term] the network, useful for testinG networkinG code • … Internet Control MessaGe Protocol Internet Control MessaGe Protocol ICMP is used by hosts and routers to communicate Type Code Description network-level information 0 0 echo reply (pinG) • error reportinG: unreachable host, network, port, protocol 3 0 dest network unreachable • echo request/reply (used by ping) 3 1 dest host unreachable • ICMP error message does not triGGer another ICMP messaGe 3 2 dest protocol unreachable 3 3 dest port unreachable ICMP runs on network-layer, but “above” IP: 3 4 fraG needed but DF set • ICMP messaGes are carried inside IP dataGrams 3 6 dest network unknown 8 bits 8 bits 16 bits 3 7 dest host unknown 8 0 echo request (pinG) ICMP messaGe format: type code checksum 9 0 route advertisement 10 0 router discovery The first 8 bytes of IP dataGram causinG error 11 0 TTL expired 12 0 bad IP header Traceroute and ICMP Traceroute and ICMP How to discover the routers alonG a path? When ICMP messaGe arrives back at the source, source calculates round-trip time (RTT) Source sends a series of UDP packets to destination • first 3 packets have TTL set to 1, spaced 3 secs apart StoppinG criterion: • next 3 packets have TTL set to 2, etc.