Salta al contenuto
Note per Studenti Forwarding and Routing Tables Report

Forwarding and Routing Tables

In questa pagina 5
In questa pagina 3

Routing computes the tables (Routing Algorithms - Link State and Distance VectorRouting finds least-cost paths in a weighted graph where routers are nodes and networks between routers are edges. Link state floods each router's local links (LSPs) so every router knows the whole graph and runs Dijkstra; distance vector has each router exchange its distance vector with neighbours only and update it with Bellman-Ford, D(A,w)=min(D(A,w), D(A,Y)+d(Y,w)), which converges in at most n-1 rounds but suffers from count to infinity (limited infinity of 16, hold down, triggered updates, split horizon, poison reverse); path vector announces whole paths, chooses by policy and detects loops by finding itself in the path.Routing Algorithms - Link State and Distance Vector →, Internet Routing Protocols - RIP, OSPF and BGPInternet routing is hierarchical for scalability and administrative autonomy: each ISP is an autonomous system (AS) and uses an interior protocol inside it, either RIP (distance vector, hop count with maximum 15, updates about every 30 s, over UDP port 520) or OSPF (link state with Dijkstra, areas attached to backbone area 0, five LSA types, carried directly in IP), while BGP4 (path vector over TCP port 179, eBGP between ASes and iBGP inside) connects ASes with policy-based route choice and loop avoidance by discarding paths that contain the own AS.Internet Routing Protocols - RIP, OSPF and BGP →); forwarding uses them packet by packet. This note describes what a host or router does when it must send an IP datagram (IPv4 Datagram and FragmentationIPv4 is a connectionless, unreliable best-effort service; the header is 20 to 60 bytes (HLen counts 4-byte words), TTL limits hops, Protocol identifies the payload (1 ICMP, 6 TCP, 17 UDP) and the checksum covers only the header; a datagram larger than the link MTU is fragmented (only the payload is split, offsets are in units of 8 bytes, MF is 1 in all fragments but the last) and reassembled only at the destination.IPv4 Datagram and Fragmentation →).

Definition (forwarding). Putting the packet on the path toward its destination. Since the Internet is a combination of links, forwarding means delivering the packet to the next hop, hop by hop. In the datagram approach the decision is based on the destination address.

Direct and indirect forwarding

Direct: the destination is on the sender's local network. Example: B=193.17.31.55B=193.17.31.55 sends to A=193.17.31.45A=193.17.31.45, both in network 193.17.31.0193.17.31.0. BB compares NetIDs (equal), looks up MACA\text{MAC}_A in the ARP table (or asks with an ARP request: ARP - Address Resolution ProtocolTo place an IP datagram in a frame a node needs the MAC address of the next hop, obtained with ARP: a broadcast request (destination MAC FF:FF:FF:FF:FF:FF, carrying the sender's IP and MAC and the wanted IP) and a unicast reply with the wanted MAC, stored in the ARP cache; ARP always resolves the next hop (destination host or router), never the final destination, and since broadcasts do not leave the subnet a router can answer with its own MAC (proxy ARP).ARP - Address Resolution Protocol →) and builds a frame with destination MACA\text{MAC}_A.

Indirect: the destination is on another network. BB sends to D=131.17.23.4D=131.17.23.4: NetIDs differ, so BB sends to its default gateway (the router C=193.17.31.254C=193.17.31.254). The frame has destination MACC\text{MAC}_C (the router, not DD) while the IP datagram keeps source IPB\text{IP}_B and destination IPD\text{IP}_D. The host learns the default gateway from the DHCPACK, together with netmask and DNS server (DHCP - Dynamic Host ConfigurationBOOTP (obsolete) statically maps MAC addresses to IP addresses, while DHCP assigns addresses dynamically on lease, even after the operating system has started; the client-server dialogue runs over UDP (server port 67, client port 68) with DHCPDISCOVER, DHCPOFFER, DHCPREQUEST and DHCPACK (plus DHCPRELEASE), and the ACK delivers IP address, netmask, default gateway and DNS server, with lease renewal at 50 percent and rebinding at 87.5 percent of the lease.DHCP - Dynamic Host Configuration →).

Property. IP source and destination addresses stay the same from origin to final destination; MAC addresses change at every hop. (With a layer-2 switch the MACs do not change either.)

Router interfaces and tables

A router has several interfaces, each with an IP address and netmask. It stores the configuration of interfaces (networks reachable directly) and a routing table with rows (network, netmask, next hop). Example: eth0 =145.170.123.76/25=145.170.123.76/25 and eth1 =145.170.124.169/25=145.170.124.169/25 (mask 255.255.255.128255.255.255.128): eth0 network 145.170.123.76 AND 255.255.255.128=145.170.123.0145.170.123.76\ \text{AND}\ 255.255.255.128=145.170.123.0 (76=0100110076=01001100, first bit 0); eth1 network 145.170.124.128145.170.124.128 (169=10101001169=10101001, first bit 1).

The forwarding decision

Phase 1: direct delivery. For each interface xx: if IPdst AND NM(x)=IP(x) AND NM(x)\text{IP}_{\text{dst}}\ \text{AND}\ \text{NM}(x)=\text{IP}(x)\ \text{AND}\ \text{NM}(x) deliver directly through xx (using ARP). If no interface matches, forwarding is indirect.

Phase 2: routing table, longest prefix match. Scan the rows starting from the one with the longest netmask (the table is not necessarily ordered): for each row compute IPdst AND NMrow\text{IP}_{\text{dst}}\ \text{AND}\ \text{NM}_{\text{row}} and compare with the row's network; the first match gives the next hop, which must belong to one of the networks of the router's interfaces (this tells which interface to use and which MAC to ask ARP for). The longest prefix is the most specific description of the destination (like "Paris" versus "France" for a letter), and rows are nested as sets.

Default route: network 0.0.0.00.0.0.0, netmask 0.0.0.00.0.0.0; the AND is always 0.0.0.00.0.0.0, so it matches anything and is tried last.

forward(packet):
    for each interface x:
        if IP_dst AND NM(x) == IP(x) AND NM(x): deliver directly on x (ARP); stop
    sort table rows by decreasing netmask
    for each row r:
        if IP_dst AND NM(r) == network(r): next hop = r.nexthop; stop
    (the default row always matches)

Complete example. Interfaces eth0 =131.175.21.254/24=131.175.21.254/24 and eth1 =131.175.12.254/24=131.175.12.254/24; table:

network netmask next hop
131.175.15.0 255.255.255.0 131.175.21.1
131.175.16.0 255.255.255.0 131.175.21.2
131.175.17.0 255.255.255.0 131.175.21.3
131.180.23.0 255.255.255.0 131.175.21.4
131.180.18.0 255.255.255.0 131.175.21.4
131.180.21.0 255.255.255.0 131.175.21.4
131.180.0.0 255.255.0.0 131.175.21.5
0.0.0.0 0.0.0.0 131.175.12.254
  • 131.175.21.86131.175.21.86: AND with /24/24 gives 131.175.21.0131.175.21.0 = network of eth0: direct delivery on eth0.
  • 131.175.16.65131.175.16.65: no interface matches; row 2 matches (131.175.16.0131.175.16.0): next hop 131.175.21.2131.175.21.2, on the network of eth0, so eth0.
  • 131.180.21.78131.180.21.78: the /24 row 131.180.21.0131.180.21.0 matches, next hop 131.175.21.4131.175.21.4 (the /16 row would also match but has a shorter mask).
  • 131.180.5.9131.180.5.9: no /24 match, the /16 row matches: next hop 131.175.21.5131.175.21.5.
  • 200.45.21.84200.45.21.84: only the default route: next hop 131.175.12.254131.175.12.254 (eth1).

Use the right mask. Table rows 180.70.65.192/26→m2180.70.65.192/26\to m_2, 180.70.65.128/25→m0180.70.65.128/25\to m_0, default via 180.70.65.200180.70.65.200; destination 180.70.65.140180.70.65.140 (140=100011002140=10001100_2). With the /26 row: keep 2 bits, 10→12810\to128, 180.70.65.128≠180.70.65.192180.70.65.128\neq180.70.65.192: no match. With the /25 row: keep 1 bit, 128128: match, output m0m_0.

Special cases. A packet whose destination is the direct broadcast of the network it arrived from is not forwarded. An address 0.0.0.x0.0.0.x means "host xx of this network" and is discarded by a router. If the next hop is on the same network the packet came from, the router sends an ICMP redirect to the sender (ICMP, Ping and TracerouteICMP adds to IP the error reporting and queries it lacks; its messages travel inside IP datagrams with Protocol 1 and are either errors (destination unreachable type 3, time exceeded 11, redirect 5, parameter problem 12), always sent to the original source with the original IP header plus 8 bytes of data, or queries (echo request 8 and reply 0, timestamp 13 and 14); ICMP only reports and never corrects errors, and it supports ping (RTT), path MTU discovery with the D bit (maximum payload 1500-20-8=1472 bytes) and traceroute (TTL increasing, n+1 probes for n routers), but also attacks such as smurf and fake redirects.ICMP, Ping and Traceroute →). At each forwarding the TTL is decremented; at 0 the packet is dropped with an ICMP time exceeded.

Route aggregation

Classless addressing lengthens tables (scanning is O(n)O(n) in the number of rows). Hierarchical addressing with route aggregation announces routing information efficiently (Subnetting, VLSM and SupernettingSubnetting splits an address block into smaller subnets by lengthening the mask (2^s subnets when s bits are borrowed), supernetting does the opposite by shortening the prefix to merge contiguous blocks; design rules for variable-size subnets are power-of-two sizes M with M at least hosts plus 2, prefix 32 minus log2 M, and start addresses divisible by M (largest subnet first), while 2^j blocks of prefix n aggregate into one block of prefix n minus j only if contiguous and aligned.Subnetting, VLSM and Supernetting →).

Example. R1R_1 connects four organisations with 64 addresses each: 140.24.7.0/26140.24.7.0/26, .64/26.64/26, .128/26.128/26, .192/26.192/26. R1R_1 needs four /26 rows. A distant router R2R_2 needs only one row: 140.24.7.0/24140.24.7.0/24 out of interface m0m_0 (4×64=2564\times64=256 addresses; blocks must be contiguous, a power of 2 in number and aligned). A more specific row (an exception, such as a customer that moved) always wins over the aggregate thanks to the longest prefix rule.

Label-based forwarding: MPLS

Switching forwards on labels attached to packets (connection-oriented, virtual circuits). Routing needs a table search (prefix comparison); switching uses index access, because the circuit is already chosen, and is therefore faster. In MPLS (Multi-Protocol Label Switching) the IP packet is encapsulated in an intermediate layer between link and network with a 32-bit header containing a 20-bit label; packets can carry several labels (hierarchical switching).

Versione ripasso

Routing builds tables; forwarding uses them (Routing Algorithms - Link State and Distance VectorRouting finds least-cost paths in a weighted graph where routers are nodes and networks between routers are edges. Link state floods each router's local links (LSPs) so every router knows the whole graph and runs Dijkstra; distance vector has each router exchange its distance vector with neighbours only and update it with Bellman-Ford, D(A,w)=min(D(A,w), D(A,Y)+d(Y,w)), which converges in at most n-1 rounds but suffers from count to infinity (limited infinity of 16, hold down, triggered updates, split horizon, poison reverse); path vector announces whole paths, chooses by policy and detects loops by finding itself in the path.Routing Algorithms - Link State and Distance Vector →). Forwarding is hop by hop to the next hop.

Direct versus indirect

Decision with netmasks

Phase 1: direct on interface xx if IPdst AND NM(x)=IP(x) AND NM(x)\text{IP}_{\text{dst}}\ \text{AND}\ \text{NM}(x)=\text{IP}(x)\ \text{AND}\ \text{NM}(x). Phase 2: scan table rows from the longest mask; first row with IPdst AND NM=network\text{IP}_{\text{dst}}\ \text{AND}\ \text{NM}=\text{network} gives the next hop. Default route 0.0.0.0/00.0.0.0/0 matches always, tried last.

  • Router with eth0 131.175.21.254/24131.175.21.254/24, eth1 131.175.12.254/24131.175.12.254/24: 131.175.21.86131.175.21.86 direct on eth0; 131.175.16.65131.175.16.65 via next hop 131.175.21.2131.175.21.2; 131.180.21.78131.180.21.78 via 131.175.21.4131.175.21.4 (the /24 row beats the /16); 131.180.5.9131.180.5.9 via 131.175.21.5131.175.21.5 (/16); 200.45.21.84200.45.21.84 default via 131.175.12.254131.175.12.254.
  • 180.70.65.140180.70.65.140 with rows /26 (.192.192) and /25 (.128.128): /26 fails, /25 matches. Always use the mask of that row.
  • Direct broadcast of the arrival network is not forwarded; 0.0.0.x0.0.0.x discarded; next hop on arrival network gives ICMP redirect; TTL −1-1 per hop.

Aggregation and MPLS

  • Four /26 blocks 140.24.7.0140.24.7.0 to .192.192 aggregate into 140.24.7.0/24140.24.7.0/24 on distant routers; more specific rows win (longest prefix).
  • MPLS: forwarding on 20-bit labels (32-bit header), index access instead of search, faster; labels can be stacked.
  • Typical errors: wrong mask for the row; picking the first matching row instead of the longest; thinking MACs stay the same across routers.

Teoria collegata