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 and and links of capacity , if they share the same links the total deliverable traffic is , while spreading them over three parallel paths gives up to .
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 to node , 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, trees in all).
Metrics
| criterion | edge cost | note |
|---|---|---|
| minimum hops | path cost = number of edges | |
| minimum end-to-end delay | transmission plus propagation | |
| minimum loss probability | product of success probabilities becomes a sum | |
| maximum throughput | , | approximation, see below |
Delay example. bytes bits on Mbit/s with ms: ms.
Loss example. and : success probability ; costs . Minimising the sum of costs maximises the success probability (the logarithm turns a product into a sum, and 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 with large . Path of ten 100 Mbit/s links versus with links of 50 and 100 Mbit/s: gives , (wrongly wins); gives , (correctly 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 |
Link state
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 , edges , , , , , , , , . 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 has a state : is the current distance estimate from the source ; the label is permanent () if is final, temporary () otherwise.
- Init. has and is the current node; all others .
- Relaxation. For each non-permanent neighbour of the current node : ; if the second term wins, set the predecessor of to .
- Choice. Among temporary nodes pick the one with minimum : it becomes permanent and current. Repeat from step 2 until no reachable temporary node remains.
- Paths. Follow predecessors from back to 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 , , , , , , , , .
| step | becomes permanent | updates of temporary nodes (distance, predecessor) |
|---|---|---|
| 1 | 1 () | , , |
| 2 | 2 () | stays 9; |
| 3 | 3 () | ; |
| 4 | 6 () | |
| 5 | 5 () | unchanged |
| 6 | 4 () |
Distances from 1: , , , , . Path : predecessors give , cost .
Example 2 (graph , source ; cells are distance-predecessor):
| step | permanent | B | C | D | E | F | G |
|---|---|---|---|---|---|---|---|
| 0 | 4-A | 1-A | |||||
| 1 | 4-A | 4-F | 1 | 2-F | |||
| 2 | 3-G | 6-G | 4-F | 2 | |||
| 3 | 3 | 5-B | 4-F | ||||
| 4 | 5-B | 10-E | 4 | ||||
| 5 | 5 | 8-C | |||||
| 6 | 8 |
Least-cost tree of : , , , , , . Table of (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 ; with a priority queue .
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. : B 4, F 1, others ). 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 receives from neighbour the estimates . For every destination : If the path through is shorter, store the new cost and next hop . is the direct link cost to .
Example. receives from (, , rest ) with : via B; via B; stays . Then from (, ) with : via F; via F.
Convergence round by round (synchronous exchange; vector of ):
| round | B | C | D | E | F | G |
|---|---|---|---|---|---|---|
| 0 | 4 | 1 | ||||
| 1 | 4 | 6 | 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 finds the shortest paths with at most edges; the best path (, cost 8) has 5 edges, hence round 4. The result equals Dijkstra's.
Link failure. If breaks, stops hearing HELLO from , drops and every row with next hop , then sends its new DV; tables converge to the tree without that link (e.g. reaches via at cost ).
Count to infinity
After also breaks. Before, reached through at cost 5. deletes its row for but receives 's DV (" at 5") and sets via ; it tells , who computes ; tells , who computes , and so on: the estimate is after messages, growing to infinity while packets for bounce between and (two-hop loop).
Remedies:
- Limited infinity: a distance above 16 counts as infinite (works if the network diameter is below 16). Here 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 , send only rows whose next hop is not ( does not tell about ).
- Poison reverse: send all rows but put for those reachable through the link on which you are sending ( tells " costs "), 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 updates with 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 , , , , , destination . hears "" from and "" from ; with the policy "do not cross " it chooses even if going through were cheaper.
The result of any routing algorithm is a routing table with (1) destination network, (2) next hop, (3) cost.
Correctness
Let be the true least cost and .
Optimal substructure. Every sub-path of a shortest path is a shortest path (otherwise replacing it gives a cheaper path), hence over neighbours of .
Dijkstra (non-negative costs). Invariant: when becomes permanent, . Induction: take with minimal temporary and suppose a cheaper path exists. It leaves the permanent set at some edge , , . Then contradicting the choice of (the last inequality uses ). With a negative cost this fails: , , makes Dijkstra fix although costs . Router costs are always positive.
Bellman-Ford. Let be the estimate after synchronous rounds; then and by induction is the minimum cost over paths with at most edges (base: paths of at most one edge; step: a path of edges starts with an edge followed by a path of edges). Shortest paths are simple, hence have at most edges: after about 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: . Delay: ( B at Mbit/s with ms: ms). Loss: (sum of costs minimal success probability maximal). Throughput: with large (bottleneck is a minimum, not additive).
- Static (manual) versus dynamic (protocol, control traffic, transients).
Link state (Dijkstra)
- HELLO/ECHO discover neighbours and costs; each router floods its LSP (neighbour, cost pairs); everyone builds the whole graph.
- Dijkstra: state ; init , others ; relax and set predecessor; the temporary node with minimum becomes permanent; next hop from predecessor chain. Cost , or with a priority queue.
- Example source 1: , , , , (path ). Example : B 3, C 5, D 8, E 4, F 1, G 2, all via F.
- Correct for (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).
, next hop if improved.
- hears (, , ): , ; then : , . 's vector converges in 4 rounds ( needs a 5-edge path); round gives paths of at most edges; rounds suffice.
- Timers: expiration 180 s, garbage collection 120 s.
- Count to infinity: loop, estimate . Fixes: limited infinity (), 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 ). 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; .
- 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.