Lecture 4 The Network Layer Antonio Cianfrani DIET Department Networking Group netlab.uniroma1.it
Network layer functions Transport packet from sending to receiving hosts Network layer protocols in every host, router three important functions: Addressing: association to each device of a unique ID application transport network data link physical network data link physical network data link physical network data link physical network data link physical network data link physical Path determination: route taken by packets from source to dest. Routing algorithms Fragmentation: splitting of network layer packets (and successive merging) due to Link Layer protocol constraint. network data link physical network data link physical network data link physical application transport network data link physical
The Internet Network layer Host, router network layer functions: Transport layer: TCP, UDP Network layer Routing protocols path selection RIP, OSPF, BGP routing table IP protocol addressing conventions datagram format IP fragmentation ICMP protocol error reporting router signaling Link layer physical layer
IP datagram format ver head. len 16-bit identifier time to live type of service upper layer 32 bits flgs length fragment offset Internet checksum 32 bit source IP address 32 bit destination IP address Options (if any) data (variable length, typically a TCP or UDP segment)
IP Addressing: introduction IP address: 32-bit identifier for host, router interface interface: connection between host, router and physical link router s typically have multiple interfaces host may have multiple interfaces IP addresses associated with interface, not host, router 223.1.1.1 223.1.2.1 223.1.1.2 223.1.1.4 223.1.2.9 223.1.1.3 223.1.3.1 223.1.3.27 223.1.2.2 223.1.3.2 223.1.1.1 = 11011111 00000001 00000001 00000001 223 1 1 1
IP Addressing: the structure IP address: network part (high order bits) host part (low order bits) What s a network? (from IP address perspective) device interfaces with same network part of IP address can physically reach each other without intervening router 223.1.1.1 223.1.2.1 223.1.1.2 223.1.1.4 223.1.2.9 223.1.1.3 223.1.3.1 223.1.3.27 223.1.2.2 Network (LAN) 223.1.3.2 network consisting of 3 IP networks (for IP addresses starting with 223, first 24 bits are network address)
IP Addressing: the netmask The network mask (netmask) is a 32 bits string used to identify the network part of an IP address. The netmask also defines the number of IP addresses available for a given network IP_Address= Net_Id. Host_Id Netmask = 1111.11. 00.000 Example: first 24 bits are network address Netmask = 1111111.11111111.11111111.00000000 255.255.255.0 /24 n of IP addresses = 2 8 = 256
IP Addresses: classfull classfull addressing: class A B C 0 network host 10 network host 110 network host 1.0.0.0 to 127.255.255.255 128.0.0.0 to 191.255.255.255 192.0.0.0 to 223.255.255.255 D 1110 multicast address 32 bits 224.0.0.0 to 239.255.255.255 The netmask information is coded into the first byte of the IP address
IP addressing: CIDR classfull addressing: inefficient use of address space, address space exhaustion e.g., class B net allocated enough addresses for 65K hosts, even if only 2K hosts in that network CIDR: Classless InterDomain Routing network portion of address of arbitrary length: the netmask information must be specified! address format: a.b.c.d/x, where x is # bits in network portion of address network part 11001000 00010111 00010000 00000000 200.23.16.0/23 host part
IP addresses: host configuration Hosts (host portion): hard-coded by system admin in a file (manual configuration) DHCP: Dynamic Host Configuration Protocol: dynamically get address: plug-and-play host broadcasts DHCP discover msg DHCP server responds with DHCP offer msg host requests IP address: DHCP request msg DHCP server sends address: DHCP ack msg
IP addressing: assignment Network portion: get allocated portion of ISP s address space: How does an ISP get block of addresses? ICANN: Internet Corporation for Assigned Names and Numbers ISP's block 11001000 00010111 00010000 00000000 200.23.16.0/20 Organization 0 11001000 00010111 00010000 00000000 200.23.16.0/23 Organization 1 11001000 00010111 00010010 00000000 200.23.18.0/23 Organization 2 11001000 00010111 00010100 00000000 200.23.20.0/23....... Organization 7 11001000 00010111 00011110 00000000 200.23.30.0/23
IP datagram format IP protocol version number header length (bytes) type of data max number remaining hops (decremented at each router) upper layer protocol to deliver payload to ver head. len 16-bit identifier time to live type of service upper layer 32 bits flgs length fragment offset Internet checksum 32 bit source IP address 32 bit destination IP address Options (if any) data (variable length, typically a TCP or UDP segment) total datagram length (bytes) for fragmentation/ reassembly E.g. timestamp, record route taken, pecify list of routers to visit.
IP Fragmentation & Reassembly network links have MTU (max.transfer unit) - largest possible link-level frame. different link types, different MTUs large IP datagram divided ( fragmented ) within net one datagram becomes several datagrams reassembled only at final destination IP header bits used to identify, order related fragments reassembly fragmentation: in: one large datagram out: 3 smaller datagrams
IP Fragmentation and Reassembly MTU = 1500 Byte Offset: The fragments are numbered on the basis of the position of their first data byte in the original packet Counted in blocks of 8 bytes ( fragment length must be a multiple of 8) Three fragments: - 1480 Byte (offset=0) - 1480 Byte (offset= 1480/8) - 1020 Byte (offset= 2960/8) length =4000 ID =x length =1500 length =1500 length =1040 fragflag =0 ID =x ID =x ID =x offset =0 fragflag =1 fragflag =1 fragflag =0 offset =0 offset =185 offset =370
Private IP addresses Problem: there are not enough IP addresses to be assigned to all Internet devices Introduction of private IP addresses: to be used only in the private networks (RFC 1918)
Private IP addresses Advantages No need to request public IP addresses for many devices (not all!) Reduction of public IP addresses Security improvement: real devices IP addresses hidden Drawbacks: Extra-load for access routers Breaking of the layers separation rule NAT: Network Address Translation protocol IPv6: IP addresses of 128 bit
NAT NAT router: a local interface and a public interface. The public interface has a public IP address (assigned by an ISP). The single public IP address will allow all hosts of the private network to connect to Internet. NAT operation: modifying IP header (source or destination IP address) and using port numbers. Private Network Public Network 192.168.10.0/24 NAT Router 192.168.10.2 192.168.10.254 209.235.168.3 Internet 192.168.10.3
NAT Private Network Public Network 192.168.1.2 SP 1024 SA 192.168.1.2 NAT SP 55001 SA 209.235.168.3 Internet 192.168.1.3 SA = Source IP Address SP = Source Port Inside Local IP Address & port NAT Table Inside Global IP Address & port 151.100.37.12:80 SERVER HTTP 192.168.1.2:1024 192.168.1.3:1723 209.235.168.3:55001 209.235.168.3:55002
IP packet forwarding IP router actions to be performed for each incoming packet: reading the IP destination field of the incoming packet; looking at the IP routing table to find the longest prefix matching for the IP destination address; detecting the next-hop router toward the destination; forwarding the packet toward the proper outgoing interface; 1 2 3 IP IP
The IP routing table is present in all network routers and hosts Routing information about known destination networks Each row is dedicated to a specific destination network and contains the following fields: IP routing table N, the IP destination network M, the destination netmask NH, the IP address of the first router (the next-hop router) in the path toward the destination I, the outgoing interface to reach the destination The Longest Prefix Matching rule is used: Given D as the IP destination address, for each row i the following operation is performed: If [D AND M(i)] = N then Matching(i)=M(i) The rule having the greatest Matching(i) value is used to forward the packet
IP routing table Rete 11.0.0.0/8 11.0.0.5 20.0.0.5 20.0.0.6 Tabella di instradamento di R2 130.11.0.6 213.2.97.7 eth0 Rete Rete R1 20.0.0.0/8 R2 R3 130.11.0.0/16 eth1 130.11.0.7 213.2.98.12 Rete 213.2.97.0/24 INTERNET Rete 213.2.98.0/24 Destinazione N Maschera M Next hop NH Interfaccia I 20.0.0.0 255.0.0.0 d.c. (20.0.0.6) eth0 130.11.0.0 255.255.0.0 d.c. (130.11.0.6) eth1 11.0.0.0 255.0.0.0 20.0.0.5 eth0 213.2.97.0 255.255.255.0 130.11.0.7 eth1 213.2.98.0 255.255.255.0 130.11.0.7 eth1 0.0.0.0 0.0.0.0 130.11.0.7 eth1
Static and dynamic routing Routing tables are computed/configured on the basis of network paths: Static Routing (configuration performed by network administrator); Dynamic Routing (exchange of control packets among routers Routing Protocols). Static Routing: manual configuration; not scalable; (very) slow to react to network changes.
Autonomous System An Autonomous System (AS) is a portion of Internet (routers and networks) managed by a single administrative entity An AS is identified by means of a 16 bit string (AS number) A routing protocol in each AS (chosen by the network administrator) A single routing protocol for the path computation among ASes (agreement) Routing protocol classification: 1) Distance Vector vs Link State 2) Intra-AS vs Inter-AS
Intra-AS and Inter-AS routing a Host h1 C.b AS13 b a d c b Intra-AS routing within AS 3 AS 3 A.a Inter-AS routing between AS3 and AS 88 A.c B.a Host c h2 a b AS 88 Intra-AS routing within AS 88
Routing Routing protocol Goal: determine good path (sequence of routers) thru network from source to dest. Graph abstraction for routing algorithms: graph nodes are routers graph edges are physical links link cost: delay, $ cost, or congestion level A 1 2 5 B D 2 3 1 3 good path: C E 1 5 2 F typically means minimum cost path other def s possible
Routing Algorithm classification Global or local network knowledge? Global: all routers have complete topology, link cost info Link State algorithm Local: router knows physically-connected neighbors, link costs to neighbors iterative process of computation, exchange of info with neighbors Distance Vector algorithms
A Link-State Routing Algorithm Dijkstra s algorithm network topology, link costs known to all nodes Flooding mechanism All nodes have same info computes least cost paths from one node ( source ) to all other nodes gives routing table for that node iterative: after k iterations, know least cost path to k dest. s Notation: c(i,j): link cost from node i to j. cost infinite if not direct neighbors D(v): current value of cost of path from source to dest. V p(v): predecessor node along path from source to v, that is next v N: set of nodes whose least cost path definitively known
Dijsktra s Algorithm 1 Initialization: 2 N = {A} 3 for all nodes v 4 if v adjacent to A 5 then D(v) = c(a,v) 6 else D(v) = infty 7 8 Loop 9 find w not in N such that D(w) is a minimum 10 add w to N 11 update D(v) for all v adjacent to w and not in N: 12 D(v) = min( D(v), D(w) + c(w,v) ) 13 /* new cost to v is either old cost to v or known 14 shortest path cost to w plus cost from w to v */ 15 until all nodes in N
Dijkstra s algorithm, discussion Algorithm complexity: n nodes O(n**2) more efficient implementations possible: O(nlogn) Re-computation: The whole algorithm must be executed if a network change happens: Link cost change Link failure/insertion Node failure/insertion
Distance Vector Routing Algorithm distributed: each node communicates only with directly-attached neighbors iterative: continues until no nodes exchange info. self-terminating: no signal to stop asynchronous: nodes need not exchange info/iterate in lock step! Distance Table data structure each node has its own row for each possible destination column for each directlyattached neighbor to node example: in node X, for dest. Y via neighbor Z: X D (Y,Z) = = distance from X to Y, via Z as next hop Z c(x,z) + min {D (Y,w)} w
Internet Routing Protocols Intra-AS, also known as Interior Gateway Protocols (IGP) RIP: Routing Information Protocol Distance Vector Link cost equal to 1 hop count OSPF: Open Shortest Path First Link State Link cost inversely proportional to its bandwidth Inter-AS, also known as Exterior Gateway Protocols (EGP) BGP: Border Gateway Protocol Path Vector protocol (the entire path is notified) Path: list of ASes crossed
ICMP: Internet Control Message Protocol used by hosts, routers, gateways to communication network-level information error reporting: unreachable host, network, port, protocol echo request/reply (used by ping and traceroute) network-layer above IP: ICMP msgs carried in IP datagrams ICMP message: type, code plus first 8 bytes of IP datagram causing error Type Code description 0 0 echo reply (ping) 3 0 dest. network unreachable 3 1 dest host unreachable 3 2 dest protocol unreachable 3 3 dest port unreachable 3 6 dest network unknown 3 7 dest host unknown 4 0 source quench (congestion control - not used) 8 0 echo request (ping) 9 0 route advertisement 10 0 router discovery 11 0 TTL expired 12 0 bad IP header
Exercise Subnetting from 192.168.0.0/24 Routing table of B pc-net 100 host A x-net-1 20 host B Link-1 Link-3 ws-net 50 host Link-2 INTERNET C