The Network Layer: Routing

the Bellman-Ford algorithm

/ BEL-mun FORD /

Suppose you again want the cheapest route to a destination, but instead of holding the whole map, you only know the cost to step to each immediate neighbor and you trust each neighbor's own estimate of how far they are from the destination. Then your best cost is simply: the smallest, over all neighbors, of (the cost to reach that neighbor) plus (that neighbor's cost to the destination). That single, intuitive sentence is the Bellman-Ford equation, and it is the heart of distance-vector routing.

Written out, the least cost from x to destination y is d_x(y) = min over neighbors v of [ c(x, v) + d_v(y) ], where c(x, v) is the cost of the direct link and d_v(y) is v's own least cost to y. In a network, routers do not compute this once on a full graph; instead they apply the equation repeatedly and in a distributed way: each router keeps its current distance estimates, hears neighbors' estimates, recomputes the minimum, and re-advertises if anything changed. Given enough rounds and stable links, the estimates converge to the true least-cost distances — no router ever needing the global topology.

Why it matters: Bellman-Ford is what makes distance-vector routing possible, because it only ever requires a router to combine local link costs with neighbors' advertised numbers. It also, unlike Dijkstra, copes with negative edge weights in the centralized version (useful in theory, though network link costs are non-negative). RIP is essentially distributed Bellman-Ford on hop count.

An honest caveat: the distributed version's strength — relying on neighbors' estimates — is also its curse. When a destination becomes unreachable, routers can keep feeding each other slightly-larger stale numbers, incrementing toward infinity instead of converging quickly. This is the count-to-infinity problem, which split horizon and poison reverse only partly prevent.

x reaches y only via neighbors a and b. c(x,a)=2 with a reporting d_a(y)=4; c(x,b)=6 with b reporting d_b(y)=1. Bellman-Ford gives d_x(y) = min(2+4, 6+1) = 6, choosing the path through a.

The Bellman-Ford equation combines a local link cost with each neighbor's own distance estimate, then takes the minimum.

Distributed Bellman-Ford never sees the full topology, which is exactly why it can loop and count to infinity. Dijkstra avoids this by demanding the whole map.

Also called
distributed Bellman-FordBellman-Ford equation貝爾曼-福特方程