Sub topic 4
Distance-vector routing: routing by rumor
This chapter assumes you know basic IP addressing, what a routing table is, how longest-prefix match picks a route, and the graph terms node, edge, weight and shortest path. It introduces the distance-vector idea and a first worked example. The exact update equation, convergence and loops come in later chapters.
The idea in one sentence
In distance-vector routing, each router tells its direct neighbors "here is every destination I can reach and how far away it is." Each router combines what its neighbors say with the cost of the link to each one. No router ever sees the whole network.
The name comes from what is exchanged. A distance vector is a list of (destination, cost) pairs. "Distance" is the metric, such as hop count. "Vector" means a list with one entry per destination.
Why "routing by rumor"
A router that hears "I can reach network X at cost 3" from a neighbor has no way to check the claim. It does not know the path, the intermediate routers, or whether the neighbor's information is current. It adds the cost of the link to that neighbor and treats the result as true.
This is why the approach is described as routing by rumor. Each router relies on second-hand news that has already passed through other routers. The approach is compact and simple, and it also explains the failure modes covered in later chapters.
What each router stores
A router keeps one table, with an entry per destination:
| Field | Meaning |
|---|---|
| Destination | A network or router the entry describes |
| Cost | Total metric from this router to the destination |
| Next hop | The neighbor to which packets for that destination are handed |
The next hop is the only path information stored. The router does not record the full path. When a packet arrives, the router forwards it to the next hop, and that neighbor repeats the lookup with its own table. Routing decisions are therefore hop-by-hop, and each router only needs its own table to be consistent with its neighbors'.
The cycle every router runs
- Start with what you know directly: yourself at cost 0, and each neighbor at the cost of its link.
- Send your vector to every neighbor, periodically and sometimes when it changes.
- When a neighbor's vector arrives, add the cost of the link to that neighbor to each advertised cost.
- If the result gives a cheaper route, or the neighbor is already your next hop for that destination, update your table.
- If your table changed, your next advertisement carries the change onward.
Information spreads one hop per exchange. A router three hops from a destination hears about it only after the news has crossed three links.
A worked example
Take three routers in a line. A and B are joined by a link of cost 1. B and C are joined by a link of cost 2.
At time 0, each router knows only itself and its direct neighbors:
| Router | Destination | Cost | Next hop |
|---|---|---|---|
| A | A | 0 | A |
| A | B | 1 | B |
| B | A | 1 | A |
| B | B | 0 | B |
| B | C | 2 | C |
| C | B | 2 | B |
| C | C | 0 | C |
In the first exchange, B tells A about C at cost 2. A adds the cost of the A–B link, 1, and records C at cost 3 through B. B also tells C about A at cost 1. C adds 2 and records A at cost 3 through B. In the second exchange, nothing new arrives, so the tables stop changing.
The same example in code
This script runs the exchange synchronously. In each round, every router reads a snapshot of its neighbors' vectors and updates its own table.
links = {"A": {"B": 1}, "B": {"A": 1, "C": 2}, "C": {"B": 2}}
def initial(node):
table = {node: (0, node)}
for nbr, cost in links[node].items():
table[nbr] = (cost, nbr)
return table
tables = {n: initial(n) for n in links}
for rnd in range(1, 10):
vectors = {n: {d: c for d, (c, _) in t.items()} for n, t in tables.items()}
changed = False
for node in links:
for nbr, link_cost in links[node].items():
for dest, adv in vectors[nbr].items():
new = link_cost + adv
cur = tables[node].get(dest)
if cur is None or new < cur[0]:
tables[node][dest] = (new, nbr)
changed = True
print("round", rnd, "changed =", changed)
if not changed:
break
print(tables["A"])The output is round 1 changed = True, then round 2 changed = False, then {'A': (0, 'A'), 'B': (1, 'B'), 'C': (3, 'B')}. Router A reaches C at cost 3 and sends packets to B. The simulation only adds routes and never handles a route getting worse. Real implementations must also react when a neighbor's advertised cost rises or a link fails.
Properties and trade-offs
- Small state. A router stores one entry per destination and does not store the topology. Memory use grows with the number of destinations, not with the number of links.
- Simple processing. Each update is an addition and a comparison. This made the approach practical on early, slow routers.
- Local view. A router cannot tell whether a neighbor's advertised path runs back through itself. This is the root of routing loops.
- Slow propagation. News moves one hop per exchange. If updates are sent on a timer, a change can take a full timer interval per hop to cross the network.
- Bandwidth cost. Each router sends its whole vector to every neighbor, so large tables are re-sent even when little has changed.
- Trust. A neighbor's advertisement is accepted at face value. A misconfigured or faulty router can attract traffic by advertising low costs.
Where this leads
The rule used in the code is a form of the Bellman-Ford equation, which the next chapter states precisely. After that, the tutorial covers how routers exchange vectors in practice, what "converged" means, and why bad news spreads more slowly than good news. Link-state protocols take the opposite approach, giving every router the full map, and are covered later for comparison.
Exercise
In the three-router example, the A–B link has cost 1 and the B–C link has cost 2. After the network has stabilized, what entry does router C hold for destination A, and which router sends the information that creates it?
Show answer
C holds destination A at cost 3 with next hop B. B sends the advertisement "A at cost 1". C adds the cost of the B–C link (2) to get 3.
Exercise
Why can a distance-vector router not detect that a neighbor's advertised route passes back through itself?
Show answer
The advertisement contains only a destination and a total cost. It does not list the path, so the receiving router cannot see which routers the route crosses. It accepts the cost plus the link cost as given.