Skip to content

hop 17 of 32 · 6 min

How a router learns the way

A router forwards a packet towards its destination. Building the table that says which way is the interesting part, and there are two families.

Distance vector

Each router knows only its direct neighbours, and tells them its whole table periodically.

code
"I can reach network A in 3 hops, network B in 5"

A neighbour receiving that adds the cost of the link and updates anything it improves. Over several rounds the information spreads. This is the Bellman-Ford algorithm running continuously and distributed.

Count to infinity is its weakness. When a network becomes unreachable, the bad news spreads slowly:

code
A loses its link to X
B still advertises "X in 2 hops" (via A, which B does not know is gone)
A believes B, records "X in 3 hops"
B hears A, records "X in 4 hops"
... counting upward together

The mitigations are partial. Split horizon means not advertising a route back to the neighbour you learned it from. Poison reverse advertises it as infinite instead. Neither fixes loops involving three or more routers, which is why 16 is defined as infinity in RIP: it bounds how long the counting can go on.

Link state

Each router discovers its own links, then floods that description to every other router. Every router ends up with the full map and runs Dijkstra on it independently.

code
1. discover neighbours
2. flood a link state advertisement to everyone
3. build the complete topology
4. run shortest path from yourself

Converges fast, no count to infinity, because nobody is repeating second hand information. The cost is memory for the full map, CPU to run Dijkstra, and flooding traffic when anything changes.

Distance vectorLink state
Knowsneighbours' summariesthe whole topology
Computationsmall, distributedDijkstra, per router
Convergenceslowfast
Loopscount to infinityavoided by design
Scales tosmall networkslarge ones, with areas

Which is used where

Link state for networks under one administration, where the full map is knowable and trustworthy. Distance vector, in a path vector form, between organisations, where nobody will publish their internal topology and policy matters more than hop count.

That last point is the real reason BGP is not link state: a route between companies is chosen on business relationships, not on distance, and link state has no way to express that.