Distance-Vector Routing, Bellman-Ford, and Convergence Problems
Distance-Vector Routing
The distance-vector algorithm is distributed: each node receives information from one or more directly attached neighbors, performs a calculation, and then distributes the results back to its neighbors.
The distance-vector algorithm is derived from the Bellman-Ford equation , where is the least cost from x to y, is the cost from x to its neighbor v, and is the cost from neighbor v to destination y.
The equation is intuitive: if x first goes to neighbor v and then follows v's least-cost path to y, the cost is . x only needs to choose the neighbor that minimizes this sum, and that neighbor is also x's next hop toward y.
The only information a node has is the cost of the links to its directly attached neighbors and the information it receives from those neighbors. Each node waits for updates from any of its neighbors.
Each node x maintains three things: the cost of the link to each neighbor v; its own distance vector , its estimate of its least cost to every destination; and the latest distance vector received from each neighbor. The algorithm runs as follows:
Initialization:
for each destination y: D_x(y) = c(x, y) (∞ if not a neighbor), D_x(x) = 0
send D_x to all neighbors
Loop:
wait (until a directly attached link cost changes or a neighbor's vector arrives)
for each destination y: D_x(y) = min_v{c(x, v) + D_v(y)}
if any value in D_x changed, send the new D_x to all neighborsDistance-vector routing is iterative (exchanges continue until there is no new information), asynchronous (nodes need not compute in lockstep), and self-terminating (nodes stop sending when nothing changes).
Exchange distance vectors until nothing changes
Unlock the complete interactive lab, deeper explanations, and curated reference answers.
KNOWLEDGE QUIZ
Link-Cost Changes and Count-to-Infinity
When a link cost decreases, the "good news" spreads quickly: each node that computes a smaller cost immediately tells its neighbors, and the network converges in a few rounds.
Increases behave differently. Consider three nodes x, y, z with , , and . Initially (direct) and (through y). Now rises to 60:
- y detects the change and computes with the that z advertised earlier: , so it now routes to x through z. But z's path to x goes through y, so a routing loop has formed.
- z receives y's new vector, computes , and advertises it to y.
- y computes 8, z computes 9, … the two take turns adding 1.
These exchanges repeat more than forty times, until z finds that the cost through y exceeds 50 and switches to its direct link to x. If were also huge or the link did not exist, the cost would keep growing forever. This is the count-to-infinity problem.
Poisoned reverse prevents such loops between two nodes: if z routes through y to reach x, z advertises to y. y then never chooses to route back through z; in the example, y immediately computes and the network converges quickly. Poisoned reverse cannot, however, fix loops involving three or more nodes.
Watch bad news count to infinity
Unlock the complete interactive lab, deeper explanations, and curated reference answers.
KNOWLEDGE QUIZ
Comparing Link-State and Distance-Vector Routing
| Link state (LS) | Distance vector (DV) | |
|---|---|---|
| What each node knows | The whole topology and every link cost | Costs to neighbors and the neighbors' vectors |
| Messages | Every node floods LSAs to the whole network | Vectors are exchanged only with neighbors |
| Convergence | Local Dijkstra, | Can be slow, with loops and count-to-infinity |
| Robustness | Each node computes its own table; errors stay limited | One node's wrong cost can spread through the network |
Both are used in the Internet: OSPF is based on link state and RIP on distance vectors. RIP uses hop count as its cost, with a maximum of 15 hops; 16 means unreachable ("infinity"), which caps count-to-infinity.
Compute one node's new distance vector
Node a has neighbors b, c, d with link costs c(a,b) = 3, c(a,c) = 1, c(a,d) = 6. It has just received these distance vectors (destinations a, b, c, d, e):
Use the Bellman-Ford equation to compute D_a(b), D_a(c), D_a(d), D_a(e) and the next hop for each.
Simulate synchronous distance-vector rounds in Python
Model the network below in Python. Start with each node knowing only its direct links. In each round, every node recomputes its whole vector from the vectors its neighbors had at the start of that round. Print every node's cost to d after each round, and stop after the first round in which nothing changes.