9. Distance-Vector Routing
How routers fill in their tables by telling their neighbours how far away everything is, and why bad news makes them count to infinity
Picture the old fingerposts at a country crossroads: Ashby 12 →, Barton 7 ←. Nobody who put up those signs had a map of the whole county. They only needed to know two things: how far it is to the next village down each road, and what the signposts in that village say. If the next village along the east road is 3 miles away and its own sign says "Ashby 9", then from here Ashby is 3 + 9 = 12 miles, that way. If the west road's village claims Ashby is 15, you ignore it, because 12 is shorter.
Now imagine every village repainting its signs every half hour from its neighbours' signs. New roads would appear on the signs a village at a time, and the whole county's signs would always be (nearly) right, without anyone ever drawing a map. That's distance-vector routing: every router keeps a list of how far it is to every destination (the distance vector) and which way to go, and tells its neighbours. Each router builds its table from its neighbours' tables, plus the cost of reaching them.
It's also where the trouble starts. What happens when a bridge washes away, but the village on the far side of it is still advertising "Ashby 9" because it got that number from your sign? In this article we'll see the idea work beautifully, then watch four routers spend minutes counting up to 16 because nobody can tell them the truth.
Why Routers Need to Talk
At the end of Routing Basics, almost every route was either connected (the router has an interface on that network) or static (somebody typed it in), R3's OSPF and BGP routes aside. That was fine for R1, R2 and R4, which have a couple of connected networks and a default route. It isn't fine for the ISP. Static routes have two problems:
- They don't scale. With n routers, each needs a route to every network behind every other router. Adding one customer network means logging in to every router that needs to reach it. Our small ISP grows a router a year; a big one has thousands.
- They don't adapt. A static route keeps pointing at its next hop until somebody changes it. If a fibre is cut, traffic is dropped until an engineer notices, even if there's a perfectly good second path, and it stays dropped until they fix it.
What we want instead is for routers to learn routes from each other and re-learn
them when something changes. That's what a routing protocol does, and the simplest family
of routing protocols is distance-vector. In the last article R3 learned the route to our
street, 198.51.100.0/24, from OSPF. Let's rewind to the ISP's early days, when its
routers still ran the classic distance-vector protocol, RIP, and see both why it worked and
why the ISP eventually moved on.
The ISP's Network
Back then, the network of the ISP from Routing Basics looked like this. Besides R2 (the edge router for our street) and R3 (the core router), it had R5, an edge router for a business park, and R6, an edge router for the next town. (Both have since been retired and their customers re-homed, which is why R3's present-day table in the last article has no routes through them.) Five links join the four routers, and every link has a cost: a number the ISP chooses, where lower is better. Most links cost 1. The R2–R5 link is a slow microwave backup, so it costs 5, and the R3–R5 link is leased from another carrier and costs 3, so the ISP would rather not use it.
The new links use the next free /30s from the ISP's 192.0.2.0/24, after the four from
the last article:
| Link | Subnet | Addresses | Cost |
|---|---|---|---|
| R2–R3 | 192.0.2.0/30 |
R2 .1, R3 .2 |
1 |
| R2–R5 | 192.0.2.16/30 |
R2 .17, R5 .18 |
5 |
| R3–R5 | 192.0.2.20/30 |
R3 .21, R5 .22 |
3 |
| R3–R6 | 192.0.2.24/30 |
R3 .25, R6 .26 |
1 |
| R5–R6 | 192.0.2.28/30 |
R5 .29, R6 .30 |
1 |
You can probably see the best paths at a glance. R2 shouldn't use its expensive link to reach R5: R2 → R3 → R6 → R5 costs 1 + 1 + 1 = 3, less than the direct 5. And R3 should reach R5 through R6 (cost 2) rather than over its own leased link (cost 3). The question is how the routers can work that out, when none of them can see the picture above.
The Idea: Tell Your Neighbours How Far
Here is the entire distance-vector protocol, in the signpost version:
-
Start with what you know
Each router knows its own networks (distance 0, or "connected") and the cost of each of its own links. It knows nothing else.
-
Tell your neighbours your distances
Every so often, each router sends every neighbour its distance vector: a list of destination, distance pairs. "I can reach R6 at cost 1, and R5 at cost 3." Notice what it doesn't send: no paths, no map, just one number per destination.
-
Recompute from what you hear
For each destination, a router adds the cost of the link to each neighbour to the distance that neighbour claims, and keeps the smallest total. The neighbour that gave the smallest total becomes the next hop. Then back to step 2.
That's it. A router never knows the whole path to a destination, only the first step and the total cost. It's exactly what a routing table needs, and it's the same "each junction only knows which way to send you next" from the Routing Basics analogy, now filled in automatically.
The "distance vector" a router sends is just the first two columns of its routing table. R3's, once things have settled, will be:
| Destination | Distance | Next hop (not sent) |
|---|---|---|
| R2 | 1 | R2 |
| R3 | 0 | (itself) |
| R5 | 2 | R6 |
| R6 | 1 | R6 |
Throughout the worked examples, a destination "R6" stands for the networks behind R6, such
as the next town's 192.0.2.128/25. Real protocols advertise prefixes, not router names,
but the arithmetic is identical.
Bellman–Ford: The Equation Behind It
Step 3 is a famous equation. Write c(x, v) for the cost of the link from router x to its neighbour v, and Dv(y) for the distance from v to destination y. Then the distance from x to y is:
where ranges over the neighbours of , and .
In words: the best way to get anywhere is to take one step to some neighbour, then take the best way from there. Whichever neighbour v gives the minimum is the next hop. This is the Bellman equation, the founding idea of dynamic programming, applied to shortest paths.
Where it comes from
Lester Ford Jr. described the procedure in a 1956 RAND Corporation paper, Network Flow Theory: start every distance at infinity (and the source at 0), then repeatedly find a link that offers a shorter distance and use it, until no link does. Richard Bellman published the equation and an iterative method for it in 1958, in On a Routing Problem. Edward Moore presented a similar method at a Harvard symposium in 1957. The name Bellman–Ford stuck, and Ford and Delbert Fulkerson's 1962 book Flows in Networks spread it further, which is why RFC 1058, the first RIP standard, calls this class of algorithms "Ford-Fulkerson" algorithms as well.
The textbook, centralised version runs on one computer that can see the whole graph. It "relaxes" every link, repeatedly:
function bellman_ford(nodes, links, source):
dist[n] = infinity for every node n; dist[source] = 0
repeat |nodes| - 1 times:
for each link (u, v, cost): # both directions for a network link
if dist[u] + cost < dist[v]: # "relax" the link
dist[v] = dist[u] + cost
next[v] = u # predecessor, for the path
for each link (u, v, cost): # one more pass:
if dist[u] + cost < dist[v]:
report "negative cycle" # still improving means no shortest path
return dist, next
After pass k, every node's distance is at least as good as the best path that uses k links, so |nodes| − 1 passes are always enough, for O(|nodes| · |links|) work in total. That's slower than Dijkstra's algorithm, but Bellman–Ford has one trick Dijkstra lacks: it copes with negative link costs, and the extra pass detects a negative cycle, a loop that gets cheaper every time round so that "shortest" stops meaning anything. Routing costs are never negative, so for us that's a curiosity.
The distributed version
The property that matters for routing is different: nobody needs to see the whole graph. Each router can evaluate the Bellman equation for itself, using only its own link costs and the latest vectors from its neighbours. Run that at every router at once, keep exchanging vectors, and the network computes all the shortest paths together.
# Runs independently on every router x
on startup:
for each destination y: D[y] = infinity, next[y] = none
D[x] = 0
send D to every neighbour
on receiving vector V from neighbour v:
heard[v] = V # remember the latest from each neighbour
recompute()
on link to neighbour v going down:
delete heard[v]; recompute()
function recompute():
for each destination y other than x:
best = infinity
for each neighbour v with heard[v]:
if cost(x, v) + heard[v][y] < best:
best = cost(x, v) + heard[v][y]; via = v
D[y] = best; next[y] = via # install in the routing table
if anything in D changed:
send D to every neighbour # and also periodically, regardless
It's also asynchronous: routers don't need to take turns or share a clock. Messages can arrive in any order, routers can recompute whenever they like, and as long as the link costs stop changing, the distances still settle on the correct shortest paths. (Dimitri Bertsekas proved this in 1982, long after it was already running.) Run like this, the algorithm is usually called distributed Bellman–Ford.
Older than the Internet
The ARPANET, the Internet's ancestor, routed with a distance-vector algorithm from the day its first packet switches went live in 1969. Will Crowther wrote most of it at BBN. Each switch sent its table to its neighbours about every two-thirds of a second, and the "cost" of a link was the length of the queue waiting to use it at that moment, plus a constant. That cost jumped around so fast that routes were unstable and loops formed under heavy load. In May 1979 the ARPANET switched to a new algorithm by John McQuillan, Ira Richer and Eric Rosen, in which every switch kept a map of the whole network and ran Dijkstra on it: the first link-state routing, and the ancestor of OSPF.
Worked Example: Four Routers Converge
Switch all four routers on at the same moment. To keep the arithmetic easy to follow, we'll run in synchronous rounds: in each round, every router sends its current vector to all its neighbours, then every router recomputes from what it received. (Real routers aren't this tidy, as we'll see later, but they reach the same answer.)
We'll write each entry as distance, next hop: "4 R3" means "cost 4, via R3".
-
Round 0: everyone knows only themselves
Each router's vector has a single finite entry: itself, at 0. Everything else is ∞.
-
Round 1: everyone learns their neighbours
R2 hears R3's vector ("R3: 0") and R5's ("R5: 0"). Adding the link costs, R2 can reach R3 at 1 + 0 = 1 and R5 at 5 + 0 = 5. It hears nothing about R6 yet, because neither neighbour knew anything about R6. Every router ends round 1 knowing its direct neighbours and nothing more.
-
Round 2: two-hop paths appear
Now the vectors carry the neighbours' neighbours. R2 hears from R3: "R2 1, R3 0, R5 3, R6 1", and from R5: "R2 5, R3 3, R5 0, R6 1". For R6, R2 can go via R3 (1 + 1 = 2) or via R5 (5 + 1 = 6), so it picks 2 via R3. For R5 it finds that going via R3 (1 + 3 = 4) beats its own direct link (5 + 0 = 5). Meanwhile R3 discovers that R6 is a cheaper way to R5 than its leased link: 1 + 1 = 2 against 3 + 0.
-
Round 3: R3's discovery reaches R2
R3's vector now says "R5: 2", so R2's best route to R5 improves again, to 1 + 2 = 3 via R3. That's the three-link path R2 → R3 → R6 → R5, which needed three rounds to discover. R5 learns the mirror image, 3 via R6 to R2.
-
Round 4: nothing changes
Every router recomputes and gets the same answers. The network has converged.
Here are R2's two calculations for R5, in round 2 and in round 3. Only R3's claim changed:
And here is every router's whole table after each round. Highlighted cells changed in that round. (∞ means "no route yet"; the simulator below writes unreachable as 16, RIP's infinity.)
Round 0 to R2 to R3 to R5 to R6
at R2 0 ∞ ∞ ∞
at R3 ∞ 0 ∞ ∞
at R5 ∞ ∞ 0 ∞
at R6 ∞ ∞ ∞ 0
Round 1 to R2 to R3 to R5 to R6
at R2 0 1 R3 5 R5 ∞
at R3 1 R2 0 3 R5 1 R6
at R5 5 R2 3 R3 0 1 R6
at R6 ∞ 1 R3 1 R5 0
Round 2 to R2 to R3 to R5 to R6
at R2 0 1 R3 4 R3 2 R3
at R3 1 R2 0 2 R6 1 R6
at R5 4 R3 2 R6 0 1 R6
at R6 2 R3 1 R3 1 R5 0
Round 3 to R2 to R3 to R5 to R6
at R2 0 1 R3 3 R3 2 R3
at R3 1 R2 0 2 R6 1 R6
at R5 3 R6 2 R6 0 1 R6
at R6 2 R3 1 R3 1 R5 0
Three things are worth noticing:
- Round k finds every best path of up to k links. That's the same reason the centralised algorithm needs at most |nodes| − 1 passes. The longest best path here, R2 to R5, has three links, so three rounds of change and one quiet round to confirm.
- Some answers get better more than once. R2's route to R5 went ∞ → 5 → 4 → 3. Between rounds, a router's table is correct for what it has heard so far, but not yet final.
- The tables are consistent. Follow the next hops from anywhere and you reach the destination, adding up exactly the cost the first router claimed: R5 → R6 → R3 → R2 is 1 + 1 + 1 = 3, the "3 R6" in R5's row.
If the routers update one at a time instead, in turn R2, R3, R5, R6 and around again, each recomputing as soon as it hears a vector, they arrive at exactly the same final tables after six messages. The order changes how the algorithm gets there, not where it ends up.
The network
One link per line, as from to cost. Edit a cost, add or delete a line, or rename a router; a name on a line of its own adds a router with no links (up to 8 routers).
Distances from the source
Highlighted cells changed in the latest pass. Pred is the router just before each one on its shortest path; First hop is where the source would send the packet, the routing-table view.
| Router | Dist | Pred | First hop | Changed |
|---|
Relaxations, in order
Good News Travels Fast, Bad News Travels Slowly
Distance-vector routing reacts beautifully to good news. Suppose R2's link to our street was down at power-on and comes up. RIP, as we'll see, counts a directly connected network as 1, so R2 now advertises "street: 1". To keep the numbers small, look at three routers in a row, R2 – R3 – R6, as if R5 were switched off for maintenance:
| Round | R2 | R3 | R6 |
|---|---|---|---|
| 0 | 1 (connected) | ∞ | ∞ |
| 1 | 1 | 2 via R2 | ∞ |
| 2 | 1 | 2 via R2 | 3 via R3 |
One hop per round, and nothing ever has to be undone. A shorter route always wins immediately, wherever it comes from.
Bad news: counting to infinity
Now the opposite. The tables have settled (R2 1, R3 2 via R2, R6 3 via R3), and a digger cuts the fibre to our street. R2's interface goes down, so R2 marks the street unreachable. In RIP, "unreachable" is written as a metric of 16, for reasons we'll see in a moment.
R2 knows the truth. But in the very same round, R3 is telling R2 what it has said all along: "street: 2". R2 has no way to know that R3's route goes through R2. To R2, it looks like a perfectly good alternative.
-
Round 1: R2 believes R3, and R3 believes R6
R2 hears "street: 2" from R3 and installs 3 via R3. R3 hears "16" from R2, which is its next hop, so its old route is gone, but in the same round R6 says "street: 3", so R3 installs 4 via R6. R6 still hears "2" from R3 and keeps 3 via R3. Now R3 sends street traffic to R6, and R6 sends it back to R3: a routing loop.
-
Round 2: the numbers creep up
R3 now says "4". R2 and R6 both route via R3, and a router always believes its own next hop, even when the news is worse, so both go to 4 + 1 = 5. R3 hears 3 from both neighbours, which is still 4, so it stays put.
-
Rounds 3 to 13: around and around
Each round, one side of the R3–R6 loop raises its number by one hop on top of the other's. The distances go up by 2 every two rounds. Meanwhile every packet for the street bounces between R3 and R6 until its TTL runs out.
-
Round 14: infinity at last
In round 13, R3 adds 1 to R6's 15 and gets 16: unreachable. In round 14, R2 and R6 add 1 to R3's 16 and get 16 too. Every router finally agrees the street is gone.
Round R2 R3 R6
0 16 (down) 2 R2 3 R3
1 3 R3 4 R6 3 R3
2 5 R3 4 R6 5 R3
3 5 R3 6 R6 5 R3
4 7 R3 6 R6 7 R3
5 7 R3 8 R6 7 R3
6 9 R3 8 R6 9 R3
7 9 R3 10 R6 9 R3
8 11 R3 10 R6 11 R3
9 11 R3 12 R6 11 R3
10 13 R3 12 R6 13 R3
11 13 R3 14 R6 13 R3
12 15 R3 14 R6 15 R3
13 15 R3 16 15 R3
14 16 16 16
That's count to infinity. The bad news (the street is gone) does travel, but it's drowned out by stale good news echoing back and forth, and the routers can only shake it off by counting up, a little at a time, until the number is so large it means "unreachable". It's exactly the loop from Routing Basics, except that this time nobody typed a bad route: the protocol built it.
Why infinity has to be small
If "unreachable" were a really large number, say 1,000,000, this would go on for a very long time. The counting stops only when the numbers reach infinity, so in RIP's designers' words, infinity must be "large enough that no real route is that big. But it shouldn't be any bigger than required." RIP's infinity is 16, which means no route in a RIP network can be longer than 15 hops. On our chain, the number of rounds is exactly infinity minus 2:
| Infinity | Rounds to agree | At 30 s per round |
|---|---|---|
| 16 (RIP) | 14 | 7 minutes |
| 32 | 30 | 15 minutes |
| 256 | 254 | about 2 hours |
Even 7 minutes is a long time to have packets looping. And notice the trade-off: RIP's 15-hop limit is fine for a campus, but it rules out large networks, and it bites sooner if you give some links costs higher than 1, as our ISP did. RFC 1058 warns about exactly that: "If the system administrator chooses to use larger costs, the upper bound of 15 can easily become a problem." Our R2–R5 link alone uses up a third of the budget.
Fixing It (Mostly)
Over the years distance-vector protocols collected a toolbox of fixes. Each one blocks some kind of stale news; none of them blocks all of it.
Route poisoning
When a router loses a route, it shouldn't just stop mentioning it, because then its neighbours would carry on using their old copy until it timed out. Instead it keeps advertising the route with an infinite metric, 16, for a while: "the street is now unreachable through me." That's route poisoning. RIP does it as standard: a dead route is advertised at 16 for two minutes before it's deleted. Our R2 was already doing this in round 1: its "16" is what made R3 drop its route.
Split horizon
Look again at round 1. R2's mistake was believing R3 about a route that R3 had learned from R2. The fix is obvious once you see it: never tell a neighbour about a route you learned from that neighbour. That's split horizon. If R3's route to the street goes via R2, R3 simply leaves the street out of the vector it sends to R2. RFC 1058 puts it neatly: "it is never useful to claim reachability for a destination network to the neighbor(s) from which the route was learned."
Poison reverse
Split horizon with poison reverse goes one step further. Instead of leaving the route out, R3 tells R2 the street is unreachable through R3: metric 16. It's a stronger statement. With plain split horizon, if two routers somehow end up pointing at each other, the bad routes linger until they time out; with poison reverse, each one hears "16" from the other on the next update, which breaks the loop at once. The cost is bigger update messages, full of routes marked 16.
Run the chain again with either of them switched on:
| Round | R2 | R3 | R6 |
|---|---|---|---|
| 0 | 16 (down) | 2 via R2 | 3 via R3 |
| 1 | 16 | 16 | 3 via R3 |
| 2 | 16 | 16 | 16 |
In round 1, R3 doesn't offer R2 its route (it learned it from R2), and R6 doesn't offer R3 its route (it learned it from R3). So R2's 16 is the only news R3 gets, and R3's 16 reaches R6 one round later. Two rounds instead of fourteen.
Where split horizon fails: a loop of three
Now switch R5 back on and cut the street's fibre again, with poison reverse on everywhere. Before the cut, the routes to the street are R2 1, R3 2 via R2, R6 3 via R3 and R5 4 via R6 (R5 → R6 → R3 → R2, cost 1 + 1 + 1 + 1). Here's what happens:
-
Round 1: the poison works where it can
R3 hears 16 from R2 and drops its route through R2. R6 poisons its reverse route to R3, so R3 doesn't believe R6. But R5 routes via R6, not via R3, so poison reverse lets it tell R3 the truth as it sees it: "street: 4". R3 has no way of knowing that R5's route runs through R3 itself. It installs 3 + 4 = 7 via R5. (R2, also desperate, takes R5's offer over the slow link: 5 + 4 = 9.)
-
A loop of three routers
Now R3 → R5 → R6 → R3. Every router poisons the route back towards its own next hop, exactly as designed, and it doesn't help: the stale news travels the other way round the triangle. Each lap adds the cost of the loop, 3 + 1 + 1 = 5.
-
Rounds 2 to 9: counting again
The loop goes round, picking up 5 each lap, until R3 adds 3 to R5's 14 and reaches 16 in round 7, and the 16s spread to everyone else by round 9.
Round R2 R3 R5 R6
0 16 2 R2 4 R6 3 R3
1 9 R5 7 R5 4 R6 3 R3
2 8 R3 7 R5 4 R6 8 R3
3 8 R3 7 R5 9 R6 8 R3
4 8 R3 12 R5 9 R6 8 R3
5 13 R3 12 R5 9 R6 13 R3
6 13 R3 12 R5 14 R6 13 R3
7 13 R3 16 14 R6 13 R3
8 16 16 14 R6 16
9 16 16 16 16
Poison reverse cut the count from 14 rounds to 9 here, but it couldn't prevent the loop. RFC 1058 is candid about it: split horizon with poison reverse "will prevent any routing loops that involve only two gateways", but if "A may believe it has a route through B, B through C, and C through A", then "split horizon cannot stop such a loop." Any network with a cycle of three or more routers, which is to say any network with redundancy, can still count to infinity.
Triggered updates
Waiting 30 seconds between rounds is what makes counting to infinity slow. So: whenever a router's metric for a route changes, it sends an update straight away, rather than at its next scheduled time. RIP waits a random 1 to 5 seconds first, so a burst of changes doesn't turn into a storm of updates. Bad news now races through the network in seconds, and usually reaches every router before stale good news can contradict it.
Usually. Regular updates keep going out on their own schedules, so a router that hasn't heard the bad news yet can still send an old route to one that has, and reseed the loop. Triggered updates make count to infinity much rarer and much faster, typically seconds instead of minutes, but not impossible. (In the simulator's async mode, triggered updates always jump the queue ahead of periodic ones, so the bad news wins the race and is flushed cleanly; real timing is messier. In synchronous rounds they only shorten each round to about 3 seconds.)
Hold-down timers
The bluntest fix: when a route goes bad, refuse to believe any news about that destination for a while. A router that loses a route puts it in hold-down, and for the hold-down period it ignores offers of a new path, so stale good news has time to die out. Hold-down isn't part of the RIP standards, but Cisco's RIP implementation uses one, 180 seconds by default. (Cisco's older IGRP protocol had one too, with a longer default.)
On the full network, with hold-down and no split horizon, R2 holds down as soon as its fibre is cut and ignores R3's "2" and R5's "4". R3 hears 16 from its next hop R2 in round 1, holds down and ignores R5. R6 does the same in round 2, when it hears 16 from R3, and R5 in round 3. Every router agrees on 16 by round 3, and no loop ever forms.
The price is that hold-down blocks good news too. If the street were reachable some other way, say through a second fibre into R5, every router in hold-down would ignore that path for three minutes, with the street cut off the whole time.
The scorecard
| Mechanism | Chain (no R5) | Full network |
|---|---|---|
| Nothing (just poisoning) | 14 rounds | 14 rounds |
| Split horizon or poison reverse | 2 rounds | 9 rounds |
| Hold-down | 2 rounds | 3 rounds |
Rounds are ~30 seconds each with periodic updates alone; triggered updates shrink each one to a few seconds. Real RIP routers use poison reverse (or split horizon), poisoning and triggered updates together, and Cisco's add hold-down on top. Together they make the problem rare, but the only real cure is to stop routers from accepting a route that could lead back through themselves. That needs more information than a bare distance, and we'll see how EIGRP, Babel and BGP supply it below.
Scenario
Fixes
Links
Tap a link on the diagram to cut or restore it, or pick one here and change its cost.
History
RIP: The Routing Information Protocol
Everything so far is how RIP works, the oldest routing protocol still in common use.
Its roots are at Xerox PARC: the PUP network protocols exchanged routes with a "Gateway
Information Protocol", which became the Routing Information Protocol in Xerox Network Systems
(XNS). Berkeley's routed daemon adapted it for IP, and because it shipped with BSD Unix
it spread everywhere before it was written down. Charles Hedrick of Rutgers finally
documented it in RFC 1058 in June 1988, "largely the same" as what routed already did.
The rules
- Metric. A hop count: each network crossed normally costs 1, and a directly connected network is 1 away. Administrators can raise the cost of a link (Cisco and FRR call the feature an offset list), which is how our ISP made its slow links cost 5 and 3.
- Infinity. 16. So the longest usable path is 15.
- Transport. UDP, port 520 at both ends. A router asks its neighbours for their whole table with a Request (command 1) when it starts up, and everything else is a Response (command 2), whether or not anyone asked.
- Updates. Every router sends its whole table to every neighbour every 30 seconds, plus triggered updates when something changes.
- Size. Up to 25 routes per packet; bigger tables take several packets.
The timers
| Timer | RFC 2453 | Cisco default | What it does |
|---|---|---|---|
| Update | 30 s | 30 s | Time between full-table updates |
| Timeout / invalid | 180 s | 180 s | No news for this long: route set to 16 |
| Garbage collection / flush | 120 s | 240 s | When the route is finally deleted |
| Hold-down | none | 180 s | Ignore new paths after a route goes bad |
RFC 2453 counts garbage collection from the timeout, so a route that stops being refreshed is advertised at 16 from 180 s and deleted at 300 s. Cisco's flush timer counts from the last update, deleting it at 240 s. Six missed updates in a row is a lot, but UDP packets do get lost, and RIP has no acknowledgements.
The 30 seconds isn't exact, either. RIP routers add a random offset of up to 5 seconds either way. Sally Floyd and Van Jacobson showed in 1993 that routers sending periodic updates on fixed timers tend to drift into synchronisation, all sending at the same instant, and the jitter keeps them apart.
RIPv1 and its classful blind spot
RIPv1 carries just an address and a metric per route, with no subnet mask. A router receiving one has to guess the prefix length: from the old address class (see From Classes to CIDR), or, if the address is in a network it has an interface on, from that interface's mask. RIPv1 also summarises at class boundaries, advertising a whole class network rather than its subnets. And it sends its updates to the broadcast address, so every host on the link has to look at them.
For our ISP that's fatal. Everything in 192.0.2.0 is one old class C network. R6 would
advertise the next town, 192.0.2.128/25, as plain 192.0.2.128, and R3, whose own
interfaces in that network have /30 masks, would assume it was a /30 too. Different
prefix lengths in one network, which is what the
VLSM plan relies on, simply can't be expressed.
RIPv2
RIPv2 (RFC 1388 in 1993, RFC 1723 in 1994, and the current standard, RFC 2453 in 1998) fills the unused zero fields in RIPv1's route entries:
- Subnet mask, so routes are CIDR prefixes and VLSM works.
- Next hop, so a router can say "send traffic for this to that router on our shared
link" when it's a better first hop than the advertising router itself.
0.0.0.0means "via me". - Route tag, a 16-bit label kept with the route, used to mark routes imported from other protocols, say with the number of the network they came from.
- Multicast. Updates go to
224.0.0.9, a group only RIPv2 routers join, instead of broadcast. - Authentication. If the first entry has address family
0xFFFF, it holds authentication data. RFC 2453 itself only defines a plain-text password (type 2), which anyone watching the link can read. RFC 2082 (1997) added keyed MD5, and RFC 4822 (2007) replaced it with HMAC-SHA cryptographic authentication.
A triggered update, byte by byte
Here is the first thing R2 sends when the digger cuts the street's fibre: a triggered update
poisoning the route, sent out of eth1 from 192.0.2.1 to 224.0.0.9. It's a RIPv2
Response with a single route entry. This is the UDP datagram; an IPv4 header (protocol 17)
goes in front:
R2's poisoned route: 32 bytes of UDP
0000 02 08 02 08 00 20 2e 4a 02 02 00 00 00 02 00 00
0010 c6 33 64 00 ff ff ff 00 00 00 00 00 00 00 00 10
UDP header
ports 520 → 520, length 32, checksum 2e4a ·
RIP header
Response, version 2 ·
route entry
·
metric
16: unreachable.
| Bytes | Field | Value here |
|---|---|---|
02 08 · 02 08 |
UDP source · destination port | 520 · 520 |
00 20 · 2e 4a |
UDP length · checksum | 32 bytes · see below |
02 · 02 · 00 00 |
Command · version · zero | Response · RIPv2 |
00 02 · 00 00 |
Address family · route tag | IPv4 · none |
c6 33 64 00 |
IP address | 198.51.100.0 |
ff ff ff 00 |
Subnet mask | 255.255.255.0, a /24 |
00 00 00 00 |
Next hop | 0.0.0.0: "via me" |
00 00 00 10 |
Metric | 16: unreachable |
The UDP checksum covers a pseudo-header (source and destination IP addresses, protocol and UDP length) as well as the datagram, summed as 16-bit words with the checksum field set to zero:
(pseudo-header), plus (UDP header), plus the twelve words of RIP data, totals . Fold the carry: , and flip the bits: .
R2 sends a second copy out of eth2 towards R5, from 192.0.2.17; only the source address
in the pseudo-header changes, so that copy's checksum differs. Both copies go out within a
few seconds of the cut, which is what triggered updates are for.
Configuring it
On a Linux router running FRR, R2's whole RIP configuration is a handful of lines. RIP runs on the two links towards the other ISP routers; the street is advertised by redistributing R2's connected networks, so R2 never sends RIP packets to customers:
router rip
version 2
network eth1
network eth2
redistribute connected
timers basic 30 180 120
!
interface eth1
ip rip split-horizon poisoned-reverse
!
interface eth2
ip rip split-horizon poisoned-reverse
FRR does plain split horizon by default; the interface lines switch on poison reverse.
timers basic gives the update, timeout and garbage-collection timers, here just the
defaults.
RIPng for IPv6
RIPng (RFC 2080, 1997) is the same protocol for IPv6. It uses UDP port 521 and the
multicast group ff02::9, and sends from the router's link-local address. Its route entries
are reorganised for 128-bit addresses: a 16-byte prefix, a 2-byte route tag, a 1-byte prefix
length and a 1-byte metric, still 20 bytes in all. Rather than a next hop in every entry, a
special entry with metric 0xFF sets the next hop for the entries after it. RIPng has no
authentication of its own; it relies on IPsec.
Loop-Free Distance Vector: EIGRP, Babel and BGP
Every fix in the toolbox works around the same blind spot: a router accepts a route without knowing whether that route runs back through itself. Later protocols close the gap, and stay distance-vector at heart: they still learn only from neighbours' advertisements.
EIGRP and DUAL
Cisco's EIGRP (Enhanced Interior Gateway Routing Protocol) dates from the early 1990s and was published as an informational RFC, RFC 7868, in 2016. Its metric combines bandwidth and delay rather than hops, it sends updates only when something changes rather than every 30 seconds, and it uses DUAL, the Diffusing Update Algorithm, from J.J. Garcia-Luna-Aceves' 1993 paper Loop-Free Routing Using Diffusing Computations. DUAL keeps routes loop-free at every instant, even while it's recalculating. The key idea is the feasibility condition:
The feasibility condition
A router's feasible distance (FD) for a destination is the best distance it has had to it since the route last settled. A neighbour's reported distance (RD) is the distance that neighbour advertises. A neighbour can only be used if its RD is strictly less than the router's own FD. A neighbour that is closer to the destination than you have ever been can't possibly be routing through you.
The best neighbour is the successor. Any other neighbour that meets the condition is a feasible successor, a backup that is guaranteed loop-free and can be switched to instantly. Let's try it on our network, using our link costs in place of EIGRP's metric:
- R2 to R6. FD = 2, via R3. R5 reports 1, and 1 < 2, so R5 is a feasible successor, at total cost 5 + 1 = 6. If the R2–R3 link fails, R2 switches to R5 immediately, with no messages at all, and it's provably safe.
- R3 to R2. FD = 1, via the direct link. R5 reports 3, and R6 would report 2 if split horizon weren't already hiding it from R3. Even if it did, neither is less than 1, so R3 has no feasible successor. That's exactly right: both of their routes to R2 go through R3. Those were the routes that caused the triangle loop above.
When a router loses its successor and has no feasible successor, it goes active: it asks its neighbours to recompute and waits for every one of them to reply before choosing a new route, freezing the destination rather than guessing. Cut the street's fibre under EIGRP and R2 withdraws the route. Each router that loses its successor with no feasible successor left goes active and queries its neighbours; since nobody has a path that avoids the cut, the replies all come back "unreachable", and the route is removed everywhere. No loop, no counting.
Babel
Babel, designed by Juliusz Chroboczek and standardised as RFC 8966 in 2021, is an
open distance-vector protocol built for networks where links come and go, such as wireless
mesh networks. It combines EIGRP's feasibility idea with sequence numbers, borrowed from
DSDV (Perkins and Bhagwat, 1994): only a destination can increase its own sequence number, and
a route with a newer sequence number is always acceptable. That lets a router recover from
a lost route without DUAL's wait-for-everyone queries. Babel runs over UDP port 6696, using
the multicast groups ff02::1:6 and 224.0.0.111.
BGP: a path-vector cousin
The one routing protocol that holds the Internet together is also a descendant of the distance-vector idea. Instead of a distance, every BGP route carries the whole list of networks it has passed through, its AS path. Loop detection is then trivial: a network that finds its own number in a route's path throws the route away. BGP routers then choose between routes by policy, not just by length. That's a path-vector protocol, and it's the subject of the BGP article.
Where Distance Vector Lives Today
RIP is still everywhere, in the sense that almost every router supports it: Cisco IOS, Junos, FRR, BIRD and MikroTik's RouterOS all have it. It turns up in small networks with a handful of routers, as a lowest-common-denominator protocol between equipment that shares nothing else, and in every networking course, because you can understand all of it in an afternoon. It needs almost no memory or CPU, and next to no configuration.
But our ISP would eventually move off it, for the reasons this article has piled up:
- The 15-hop limit, which gets tighter with link costs.
- Slow convergence and counting to infinity. Even with every fix, a bad failure means seconds to minutes of looping traffic.
- Chatter. Every router sends its whole table every 30 seconds, even when nothing has changed. That's fine for twenty routes, wasteful for twenty thousand.
- Crude metrics. Hop count treats a 10 Gb/s fibre and a slow radio link the same unless someone adjusts the costs by hand.
Larger networks use link-state protocols, OSPF and IS-IS, which take the opposite approach to the signposts. Instead of passing on conclusions, every router floods a description of its own links, so every router holds the same map of the whole network and computes its routes from it with Dijkstra's algorithm. Nothing a router hears is second-hand, so there's nothing stale to count up from. EIGRP and Babel are the main places distance-vector survives in modern designs, along with BGP's path-vector variation, which runs the whole Internet.
Where to Go Next
- Link-State Routing: flooding a map of the network and running Dijkstra on it, the approach the ARPANET switched to in 1979.
- BGP: path-vector routing between the Internet's networks, where policy matters as much as distance.
- Routing Basics: what a router does with the routes once it has them: longest-prefix match, the RIB and the FIB.
- Dijkstra's Algorithm: the other classic shortest-path algorithm, and how it compares with Bellman–Ford.
- IPv4 Addressing: classes, CIDR and VLSM, the reason RIPv1 had to go.
Key Takeaways
- In distance-vector routing, each router sends its neighbours a list of destinations and its distance to each. A router's distance to a destination is the minimum, over its neighbours, of the link cost plus that neighbour's claimed distance, and that neighbour becomes the next hop.
- That's the Bellman equation, Dx(y) = minv { c(x,v) + Dv(y) }. Ford (1956) and Bellman (1958) gave the centralised algorithm; run independently at every router, asynchronously, it's distributed Bellman–Ford, and the ARPANET used it from 1969 until 1979.
- Good news travels fast: in the worked example, the four routers found every shortest path in three rounds, one link per round. Bad news travels slowly: when a destination disappears, routers believe each other's stale routes and count to infinity. RIP's infinity is 16, which limits it to 15 hops, and our three-router chain took 14 rounds (7 minutes) to agree.
- Route poisoning advertises dead routes as 16. Split horizon (don't advertise a route back to the neighbour you learned it from) and poison reverse (advertise it back as 16) stop loops between two routers, but not loops of three or more. Triggered updates make convergence faster; hold-down timers stop loops by ignoring new paths, including good ones, for a while.
- RIP uses UDP port 520 and a hop-count metric, with 30 s updates, a 180 s timeout and 120 s garbage collection. RIPv1 (RFC 1058, 1988) is classful and broadcasts; RIPv2 (RFC 2453) adds masks, next hops, route tags, multicast to 224.0.0.9 and authentication; RIPng (RFC 2080) carries IPv6 on port 521 to ff02::9.
- EIGRP's DUAL uses the feasibility condition (a neighbour's reported distance must be below your own feasible distance) to stay loop-free at every instant; Babel adds sequence numbers; BGP carries the whole path. Bigger networks mostly use link-state routing instead.
Distance-vector routers pass on each other's conclusions, and when those conclusions go stale, they can't tell. In the next article the ISP's routers stop gossiping about distances and start sharing facts about their links, every router builds the same map, and the question "does this route lead back through me?" never comes up: Link-State Routing.