Salta al contenuto
Note per Studenti Routing Algorithms - Link State and Distance Vector Report

Routing Algorithms - Link State and Distance Vector

In questa pagina 5
In questa pagina 4

Routing computes which path to follow; forwarding moves each packet to the output interface given by the table (Forwarding and Routing TablesForwarding moves each packet one hop at a time toward its destination; it is direct when the destination is on a local network (ARP gives its MAC) and indirect otherwise (the packet goes to the next hop or default gateway given by the routing table). With netmasks, delivery is direct on interface x if the destination AND the mask equals the interface address AND the mask; otherwise the table is scanned from the longest mask (longest prefix match) and the default route 0.0.0.0/0 always matches; route aggregation shortens tables.Forwarding and Routing Tables →). This note covers how routers fill their tables. The protocols implementing these algorithms (RIP, OSPF, BGP) are in 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 →.

The problem

Definition (routing). The procedures that determine a path from one point to another; possible only if every router has a forwarding table giving the next hop toward the destination.

Routing matters for capacity: with two flows S1→D1S_1\to D_1 and S2→D2S_2\to D_2 and links of capacity CC, if they share the same links the total deliverable traffic is CC, while spreading them over three parallel paths gives up to 3C3C.

The network as a weighted graph

Each router is a node, each network between two routers an edge with a cost (infinite if there is no edge). Cost is additive along a path.

Definition (least-cost route). From source ss to node vv, the path with minimum sum of edge costs. Each router needs the least-cost route to every other router; collecting them gives a least-cost tree rooted at the source (one tree per source, NN trees in all).

Metrics

criterion edge cost ci,jc_{i,j} note
minimum hops ci,j=1c_{i,j}=1 path cost = number of edges
minimum end-to-end delay ci,j=Li,j/Ri,j+tp(i,j)c_{i,j}=L_{i,j}/R_{i,j}+t_p(i,j) transmission plus propagation
minimum loss probability ci,j=−log⁡Pok(i,j)c_{i,j}=-\log P_{ok}(i,j) product of success probabilities becomes a sum
maximum throughput ci,j=1/Ri,j nc_{i,j}=1/R_{i,j}^{\,n}, n>1n>1 approximation, see below

Delay example. L=1500L=1500 bytes =12 000=12\,000 bits on R=10R=10 Mbit/s with tp=2t_p=2 ms: c=12 000/107 s+2 ms=1.2+2=3.2c=12\,000/10^7\ \text{s}+2\ \text{ms}=1.2+2=3.2 ms.

Loss example. Pok=0.9P_{ok}=0.9 and 0.80.8: success probability 0.9⋅0.8=0.720.9\cdot0.8=0.72; costs −ln⁡0.9−ln⁡0.8=0.1054+0.2231=0.3285=−ln⁡0.72-\ln0.9-\ln0.8=0.1054+0.2231=0.3285=-\ln0.72. Minimising the sum of costs maximises the success probability (the logarithm turns a product into a sum, and −ln⁡Pok≥0-\ln P_{ok}\ge0 as Dijkstra requires).

Throughput. The throughput of a path is the minimum bitrate along it (bottleneck), not a sum, so additivity fails and it cannot be reproduced exactly; it is approximated by c=1/Rnc=1/R^n with large nn. Path PP of ten 100 Mbit/s links versus QQ with links of 50 and 100 Mbit/s: n=1n=1 gives P=0.1P=0.1, Q=0.03Q=0.03 (wrongly QQ wins); n=6n=6 gives P=10−11P=10^{-11}, Q=6.5⋅10−11Q=6.5\cdot10^{-11} (correctly PP wins).

Static vs dynamic routing. Static tables are compiled by hand (small networks, no reaction to failures). Dynamic routing uses a protocol that updates tables when load or topology change, at the price of control traffic and possible inconsistency during transients.

link state distance vector path vector
algorithm Dijkstra Bellman-Ford spanning trees with policy
needs complete topology only neighbours only neighbours
exchanges own links with all nodes distances to all with neighbours whole paths with neighbours
objective least cost least cost reachability by policy
protocols OSPF, IS-IS RIP, IGRP BGP

Each node first discovers neighbours (HELLO packets) and measures local costs (e.g. ECHO packets for delay). It builds a Link State Packet (LSP) (its name followed by pairs neighbour-cost) and sends it to all other routers by flooding, repeated after every link change. With all LSPs the router has the entire graph and runs Dijkstra.

Example. Nodes A,…,GA,\dots,G, edges A ⁣− ⁣B=4A\!-\!B=4, A ⁣− ⁣F=1A\!-\!F=1, B ⁣− ⁣C=2B\!-\!C=2, B ⁣− ⁣G=1B\!-\!G=1, C ⁣− ⁣D=3C\!-\!D=3, C ⁣− ⁣G=4C\!-\!G=4, D ⁣− ⁣E=6D\!-\!E=6, E ⁣− ⁣F=3E\!-\!F=3, F ⁣− ⁣G=1F\!-\!G=1. LSPs: A: B 4, F 1; B: A 4, C 2, G 1; C: B 2, D 3, G 4; D: C 3, E 6; E: F 3, D 6; F: A 1, G 1, E 3; G: B 1, C 4, F 1.

Dijkstra

Each node ℓ\ell has a state (dℓ, p or t)(d_\ell,\ p\text{ or }t): dℓd_\ell is the current distance estimate from the source ss; the label is permanent (pp) if dℓd_\ell is final, temporary (tt) otherwise.

  1. Init. ss has (0,p)(0,p) and is the current node; all others (∞,t)(\infty,t).
  2. Relaxation. For each non-permanent neighbour vv of the current node uu: dv=min⁡{dv, du+cu,v}d_v=\min\{d_v,\ d_u+c_{u,v}\}; if the second term wins, set the predecessor of vv to uu.
  3. Choice. Among temporary nodes pick the one with minimum dd: it becomes permanent and current. Repeat from step 2 until no reachable temporary node remains.
  4. Paths. Follow predecessors from vv back to ss and read in reverse.
Dijkstra(Graph, source):
   for each vertex v: dist[v] = INF; prev[v] = undefined; put v in Q
   dist[source] = 0
   while Q not empty:
       u = vertex in Q with minimum dist; remove u from Q
       for each neighbour v of u still in Q:
           alt = dist[u] + length(u, v)
           if alt < dist[v]:  dist[v] = alt;  prev[v] = u
   return dist[], prev[]

Example 1 (6 nodes, source 1). Edges 1 ⁣− ⁣2=71\!-\!2=7, 1 ⁣− ⁣3=91\!-\!3=9, 1 ⁣− ⁣6=141\!-\!6=14, 2 ⁣− ⁣3=102\!-\!3=10, 2 ⁣− ⁣4=152\!-\!4=15, 3 ⁣− ⁣4=113\!-\!4=11, 3 ⁣− ⁣6=23\!-\!6=2, 4 ⁣− ⁣5=64\!-\!5=6, 5 ⁣− ⁣6=95\!-\!6=9.

step becomes permanent updates of temporary nodes (distance, predecessor)
1 1 (d=0d=0) 2:(7,1)2:(7,1), 3:(9,1)3:(9,1), 6:(14,1)6:(14,1)
2 2 (d=7d=7) 33 stays 9; 4:(22,2)4:(22,2)
3 3 (d=9d=9) 6:(11,3)6:(11,3); 4:(20,3)4:(20,3)
4 6 (d=11d=11) 5:(20,6)5:(20,6)
5 5 (d=20d=20) 44 unchanged
6 4 (d=20d=20)

Distances from 1: d2=7d_2=7, d3=9d_3=9, d6=11d_6=11, d4=20d_4=20, d5=20d_5=20. Path 1→51\to5: predecessors give 1→3→6→51\to3\to6\to5, cost 9+2+9=209+2+9=20.

Example 2 (graph A,…,GA,\dots,G, source AA; cells are distance-predecessor):

step permanent B C D E F G
0 {A}\{A\} 4-A ∞\infty ∞\infty ∞\infty 1-A ∞\infty
1 +F+F 4-A ∞\infty ∞\infty 4-F 1 2-F
2 +G+G 3-G 6-G ∞\infty 4-F 2
3 +B+B 3 5-B ∞\infty 4-F
4 +E+E 5-B 10-E 4
5 +C+C 5 8-C
6 +D+D 8

Least-cost tree of AA: A ⁣− ⁣FA\!-\!F, F ⁣− ⁣GF\!-\!G, G ⁣− ⁣BG\!-\!B, B ⁣− ⁣CB\!-\!C, C ⁣− ⁣DC\!-\!D, F ⁣− ⁣EF\!-\!E. Table of AA (destination, cost, next hop): B 3 F; C 5 F; D 8 F; E 4 F; F 1 F; G 2 F. Every router runs Dijkstra on its own.

Complexity. Scanning for the minimum gives O(n2)O(n^2); with a priority queue O((n+m)log⁡n)O((n+m)\log n).

Distance vector

No node knows the topology. Each node keeps a distance vector (DV): for every destination the distance and next hop of the best known path. Initially only neighbours are known (e.g. AA: B 4, F 1, others ∞\infty). Periodically (random interval 25-35 s) or when its DV changes, a node sends its DV to neighbours, who update with Bellman-Ford. If a row is not refreshed within the expiration timer (180 s) its cost becomes infinite; after another 120 s (garbage collection) it is deleted.

Formula (Bellman-Ford update). Node AA receives from neighbour YY the estimates dY,wd_{Y,w}. For every destination ww: DA,w=min⁡{DA,w, DA,Y+dY,w}.D_{A,w}=\min\{D_{A,w},\ D_{A,Y}+d_{Y,w}\}. If the path through YY is shorter, store the new cost and next hop =Y=Y. DA,YD_{A,Y} is the direct link cost to YY.

Example. AA receives from BB (dB,C=2d_{B,C}=2, dB,G=1d_{B,G}=1, rest ∞\infty) with DA,B=4D_{A,B}=4: C=min⁡{∞,4+2}=6C=\min\{\infty,4+2\}=6 via B; G=min⁡{∞,4+1}=5G=\min\{\infty,4+1\}=5 via B; DD stays ∞\infty. Then from FF (dF,G=1d_{F,G}=1, dF,E=3d_{F,E}=3) with DA,F=1D_{A,F}=1: G=min⁡{5,1+1}=2G=\min\{5,1+1\}=2 via F; E=4E=4 via F.

Convergence round by round (synchronous exchange; vector of AA):

round B C D E F G
0 4 ∞\infty ∞\infty ∞\infty 1 ∞\infty
1 4 6 ∞\infty 4 1 2
2 3 6 9 4 1 2
3 3 5 9 4 1 2
4 3 5 8 4 1 2
5 3 5 8 4 1 2

Round kk finds the shortest paths with at most k+1k+1 edges; the best A→DA\to D path (A ⁣− ⁣F ⁣− ⁣G ⁣− ⁣B ⁣− ⁣C ⁣− ⁣DA\!-\!F\!-\!G\!-\!B\!-\!C\!-\!D, cost 8) has 5 edges, hence round 4. The result equals Dijkstra's.

Link failure. If B ⁣− ⁣GB\!-\!G breaks, BB stops hearing HELLO from GG, drops GG and every row with next hop GG, then sends its new DV; tables converge to the tree without that link (e.g. BB reaches GG via CC at cost 2+4=62+4=6).

Count to infinity

After B ⁣− ⁣GB\!-\!G also C ⁣− ⁣DC\!-\!D breaks. Before, BB reached DD through CC at cost 5. CC deletes its row for DD but receives BB's DV ("DD at 5") and sets D=2+5=7D=2+5=7 via BB; it tells BB, who computes 2+7=92+7=9; BB tells CC, who computes 1111, and so on: the estimate is 5+2k5+2k after kk messages, growing to infinity while packets for DD bounce between BB and CC (two-hop loop).

Remedies:

  • Limited infinity: a distance above 16 counts as infinite (works if the network diameter is below 16). Here 17>1617>16 stops the count at the sixth message.
  • Hold down: after learning a destination is unreachable, ignore updates for it for 60 s (slower reaction to genuine changes).
  • Triggered update: topology changes are announced immediately, without waiting for the timer.
  • Split horizon: to neighbour YY, send only rows whose next hop is not YY (BB does not tell CC about DD).
  • Poison reverse: send all rows but put ∞\infty for those reachable through the link on which you are sending (BB tells CC "DD costs +∞+\infty"), so the neighbour knows why the row is absent.

Split horizon and poison reverse remove two-hop loops but not all loops, so they are combined with limited infinity.

distance vector link state
typical protocol RIP typical protocol OSPF
Bellman-Ford Dijkstra
sends (a copy of) the whole table sends only link updates
topology not required topology required
frequent updates, slow convergence event-driven updates, fast convergence

Path vector

Costs do not let the source impose policies on the path. In path vector the best path is chosen by the source by policy; the objective is reachability, not minimum cost. The resulting tree is a spanning tree but not the least-cost tree. The algorithm is asynchronous and distributed like distance vector: a node builds a vector of paths from its neighbours, sends it to them, and on receiving the vector of neighbour vv updates with Path(x,y)=best{Path(x,y), x+Path(v,y)},∀v≠x,\text{Path}(x,y)=\text{best}\{\text{Path}(x,y),\ x+\text{Path}(v,y)\},\qquad\forall v\neq x, where "best" applies the node's own policy instead of minimum cost.

Loop detection. Every announcement contains the whole path; a node receiving a path that already contains itself discards it. Paths are loop-free and count to infinity cannot occur (this is what BGP does, with AS numbers).

Example. Edges A ⁣− ⁣BA\!-\!B, B ⁣− ⁣CB\!-\!C, A ⁣− ⁣DA\!-\!D, D ⁣− ⁣CD\!-\!C, C ⁣− ⁣EC\!-\!E, destination EE. AA hears "B C EB\,C\,E" from BB and "D C ED\,C\,E" from DD; with the policy "do not cross DD" it chooses A B C EA\,B\,C\,E even if going through DD were cheaper.

The result of any routing algorithm is a routing table with (1) destination network, (2) next hop, (3) cost.

Correctness

Let δ(s,v)\delta(s,v) be the true least cost and c(u,v)≥0c(u,v)\ge0.

Optimal substructure. Every sub-path of a shortest path is a shortest path (otherwise replacing it gives a cheaper s→vs\to v path), hence δ(s,v)=min⁡u{δ(s,u)+c(u,v)}\delta(s,v)=\min_u\{\delta(s,u)+c(u,v)\} over neighbours uu of vv.

Dijkstra (non-negative costs). Invariant: when uu becomes permanent, du=δ(s,u)d_u=\delta(s,u). Induction: take uu with minimal temporary dud_u and suppose a cheaper path Π\Pi exists. It leaves the permanent set PP at some edge (x,y)(x,y), x∈Px\in P, y∉Py\notin P. Then dy≤dx+c(x,y)=δ(s,x)+c(x,y)≤cost of the part of Π up to y≤cost(Π)<du,d_y\le d_x+c(x,y)=\delta(s,x)+c(x,y)\le\text{cost of the part of }\Pi\text{ up to }y\le\text{cost}(\Pi)<d_u, contradicting the choice of uu (the last inequality uses c≥0c\ge0). With a negative cost this fails: s→a=2s\to a=2, s→b=3s\to b=3, b→a=−2b\to a=-2 makes Dijkstra fix da=2d_a=2 although s→b→as\to b\to a costs 11. Router costs are always positive.

Bellman-Ford. Let Dk(A,w)D^k(A,w) be the estimate after kk synchronous rounds; then Dk+1(A,w)=min⁡{Dk(A,w), min⁡Y(c(A,Y)+Dk(Y,w))}D^{k+1}(A,w)=\min\Big\{D^k(A,w),\ \min_{Y}\big(c(A,Y)+D^k(Y,w)\big)\Big\} and by induction Dk(A,w)D^k(A,w) is the minimum cost over paths with at most k+1k+1 edges (base: paths of at most one edge; step: a path of k+2k+2 edges starts with an edge (A,Y)(A,Y) followed by a path of k+1k+1 edges). Shortest paths are simple, hence have at most n−1n-1 edges: after about n−1n-1 rounds all estimates are exact. The asynchronous version also converges, because estimates never fall below the true value as long as the topology is stable. After a link failure some estimates describe paths that no longer exist and circulate: that is the origin of count to infinity. Dijkstra works on a full snapshot of the graph and does not have the problem.

Versione ripasso

Routing computes tables, forwarding uses them (Forwarding and Routing TablesForwarding moves each packet one hop at a time toward its destination; it is direct when the destination is on a local network (ARP gives its MAC) and indirect otherwise (the packet goes to the next hop or default gateway given by the routing table). With netmasks, delivery is direct on interface x if the destination AND the mask equals the interface address AND the mask; otherwise the table is scanned from the longest mask (longest prefix match) and the default route 0.0.0.0/0 always matches; route aggregation shortens tables.Forwarding and Routing Tables →). Network = weighted graph (routers = nodes, networks = edges); goal: least-cost tree from each router. Protocols: 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 →.

Metrics

  • Hops: c=1c=1. Delay: c=L/R+tpc=L/R+t_p (15001500 B at 1010 Mbit/s with 22 ms: 3.23.2 ms). Loss: c=−log⁡Pokc=-\log P_{ok} (sum of costs minimal ⇔\Leftrightarrow success probability maximal). Throughput: c=1/Rnc=1/R^n with large nn (bottleneck is a minimum, not additive).
  • Static (manual) versus dynamic (protocol, control traffic, transients).
  • HELLO/ECHO discover neighbours and costs; each router floods its LSP (neighbour, cost pairs); everyone builds the whole graph.
  • Dijkstra: state (d,p/t)(d,p/t); init s=(0,p)s=(0,p), others (∞,t)(\infty,t); relax dv=min⁡{dv,du+cu,v}d_v=\min\{d_v,d_u+c_{u,v}\} and set predecessor; the temporary node with minimum dd becomes permanent; next hop from predecessor chain. Cost O(n2)O(n^2), or O((n+m)log⁡n)O((n+m)\log n) with a priority queue.
  • Example source 1: d2=7d_2=7, d3=9d_3=9, d6=11d_6=11, d4=20d_4=20, d5=20d_5=20 (path 1→3→6→51\to3\to6\to5). Example AA: B 3, C 5, D 8, E 4, F 1, G 2, all via F.
  • Correct for c≥0c\ge0 (invariant: a permanent node has its true distance).

Distance vector (Bellman-Ford)

  • Nodes know only neighbours and exchange their DV with them (every 25-35 s or on change).

DA,w=min⁡{DA,w, DA,Y+dY,w}D_{A,w}=\min\{D_{A,w},\ D_{A,Y}+d_{Y,w}\}, next hop =Y=Y if improved.

  • AA hears BB (dB,C=2d_{B,C}=2, dB,G=1d_{B,G}=1, DA,B=4D_{A,B}=4): C=6C=6, G=5G=5; then FF: G=2G=2, E=4E=4. AA's vector converges in 4 rounds (D=8D=8 needs a 5-edge path); round kk gives paths of at most k+1k+1 edges; n−1n-1 rounds suffice.
  • Timers: expiration 180 s, garbage collection 120 s.
  • Count to infinity: B↔CB\leftrightarrow C loop, estimate 5+2k5+2k. Fixes: limited infinity (1616), hold down (60 s), triggered updates, split horizon (do not send a row to the neighbour that is its next hop), poison reverse (send it as ∞\infty). They kill two-hop loops only.
  • DV: RIP, Bellman-Ford, whole table, slow convergence. LS: OSPF, Dijkstra, link updates, fast convergence.

Path vector

  • Source picks the path by policy; goal is reachability; Path(x,y)=best{Path(x,y), x+Path(v,y)}\text{Path}(x,y)=\text{best}\{\text{Path}(x,y),\,x+\text{Path}(v,y)\}.
  • Loop detection: discard a path containing yourself, so no count to infinity (BGP).
  • Typical errors: using Dijkstra with negative costs; forgetting that DV needs several rounds; confusing split horizon and poison reverse.

Teoria collegata