Sub topic 8
Routing loops and count to infinity
This chapter assumes you know how a distance-vector router builds its table from neighbors' advertisements (the Bellman-Ford update from the previous chapters). It also assumes you know what a next hop is and how convergence is defined. It explains why that update rule can fail when a link goes down, and why the failure takes a long time to resolve.
Why bad news travels slowly
Distance-vector routers never see the whole topology. A router knows only the cost a neighbor claims to have. It cannot check whether that neighbor's path runs back through itself.
The update rule in this tutorial accepts two kinds of news:
- A cost lower than the one you have, from any neighbor.
- Any cost, higher or lower, from your current next hop. The next hop is the authority on that route.
Good news (a new link, a cheaper path) spreads in one round per hop. Bad news (a failure) depends on the second rule, and that rule is the source of the problem.
A routing loop
A routing loop is a state in which a set of routers each point at the next one as the way to reach a destination, and the last points back at the first. A packet then circulates until its TTL expires. Loops waste bandwidth and starve legitimate traffic on the links involved. They also appear during convergence, when routers disagree about the topology.
Count to infinity
Take three routers in a line: A, B, and C. Every link costs 1. Router A reaches C through B at cost 2. Then the B–C link fails.
- B loses its direct route to C.
- Before B learns anything new, A advertises "C at cost 2" to B, as it always does.
- B sees a neighbor with a route to C, so it installs "C at cost 3 via A". B does not know that A's route goes through B itself.
- B advertises cost 3 to A. A's next hop for C is B, so A must accept it and installs "C at cost 4 via B".
- The exchange repeats, and each round raises both costs by 2.
A packet for C now bounces between A and B. The costs stop rising only when they reach the protocol's maximum metric, which the next sections cover. This behavior is called counting to infinity.
Watching it happen
The program below simulates only A and B and their routes to C. It runs three modes: plain, split horizon, and poison reverse. It uses INFINITY = 16, the value RIP uses.
INFINITY = 16
NEIGHBOR = {"A": "B", "B": "A"}
def advertisement(routes, sender, receiver, mode):
"""Cost the sender tells the receiver about C, or None if it stays silent."""
cost, next_hop = routes[sender]
if next_hop == receiver:
if mode == "split":
return None
if mode == "poison":
return INFINITY
return cost
def show(entry):
cost, next_hop = entry
return "inf" if cost >= INFINITY else f"{cost} via {next_hop}"
def run(mode):
# State just after the B-C link fails: A still routes through B.
routes = {"A": (2, "B"), "B": (INFINITY, None)}
print(f"mode={mode}")
for rnd in range(1, 40):
changed = False
for node in ("B", "A"):
other = NEIGHBOR[node]
adv = advertisement(routes, other, node, mode)
if adv is None:
continue
new = min(adv + 1, INFINITY)
cur = routes[node]
if new < cur[0] or cur[1] == other:
entry = (new, other) if new < INFINITY else (INFINITY, None)
if entry != cur:
routes[node] = entry
changed = True
if not changed:
print(f" round {rnd}: no change, converged")
return
print(f" round {rnd}: A={show(routes['A'])}, B={show(routes['B'])}")
for m in ("plain", "split", "poison"):
run(m)In plain mode, B holds cost 3 after round 1 and 15 after round 7, and both routers mark C unreachable in round 8. In the other two modes, A learns in round 1 that C is unreachable and nothing else changes.
If RIP sends updates every 30 seconds and nothing triggers an earlier update, those eight rounds take roughly four minutes. During that time the loop exists.
Techniques that limit the damage
| Technique | What it does | What it does not fix |
|---|---|---|
| Maximum metric | Defines a finite "infinity" (16 in RIP) so counting stops. | The count still happens. It only bounds it. Networks wider than 15 hops cannot be used. |
| Split horizon | Never advertises a route back out the interface or neighbor it was learned from. | Loops involving three or more routers. |
| Poison reverse | Advertises such routes back with cost infinity, so the neighbor drops any stale route through you immediately. | Larger loops, and it makes updates bigger. |
| Triggered updates | Sends a change at once instead of waiting for the periodic timer. | Does not prevent loops. It speeds up the exchange, which can also spread bad information faster. |
| Hold-down | After a route is lost, ignores worse or equal-looking news about it for a period. Cisco's RIP implementation defaults to 180 seconds. | Slows legitimate recovery, because a real alternative path is also ignored during the timer. |
Split horizon is the cheapest fix and handles the two-router case above. Poison reverse is slightly stronger. With plain split horizon, a stale route at the neighbor must wait for a timeout. With poison reverse, you tell it directly.
Where split horizon fails
Suppose A, B, and C form a triangle and D hangs off A. B and C both reach D through A. The A–D link fails.
- A tells B and C that D is unreachable.
- The two updates do not arrive at the same moment. Say C hears first and drops its route.
- B has not yet processed the update. B's advertisement of "D at cost 2" is already on its way to C, and split horizon allows it, because B's route to D goes through A, not C.
- C accepts it and installs "D via B at cost 3".
Now B points at A, A points (eventually) at C, and C points at B. Split horizon never stopped this, because no single router sent a route back to the neighbor it learned it from. Preventing such loops needs extra machinery (hold-down timers, or path information as in BGP and DUAL). Alternatively, the network can avoid the algorithm class, which is the motivation for link-state protocols.
Edge cases and common errors
- Setting infinity too low. If the maximum metric is 16 and your longest path is 17 hops, the far end is unreachable. RIP's limit is a hard design constraint.
- Setting infinity too high. A larger value lets legitimate paths exist but lengthens the count. Convergence time grows in proportion.
- Assuming split horizon solves everything. It handles only direct two-router loops. Many "it worked in the lab" failures come from testing only that case.
- Confusing loop prevention with loop detection. None of these techniques detect a loop after it forms. IP's TTL field is what eventually discards looping packets.
- Different timers on neighbors. Mismatched update or hold-down values make convergence slower or inconsistent.
Exercise
In the simulation, change INFINITY to 8 and run plain mode. After which round do A and B both mark C unreachable? State the trade-off of choosing 8 instead of 16 for a real protocol.
Show answer
Costs rise by 2 each round. B holds 3 after round 1, 5 after round 2, and 7 after round 3. In round 3 A computes min(8, 8) = 8 and marks C unreachable. In round 4 B follows, so both routers have the route marked unreachable after round 4, and round 5 reports no change. With 8 as the limit, counting ends much sooner, but any path longer than 7 hops would be treated as unreachable. A smaller maximum metric means faster loop resolution but a smaller usable network diameter.
Exercise
Why can a router safely accept any cost, even a higher one, from its current next hop, and why does that same rule enable counting to infinity?
Show answer
The next hop is the only source of truth for that route, so if it reports a higher cost (for example after a failure), the router must update or its table becomes wrong. The danger is that the next hop may be basing its new cost on an advertisement from the router itself. Each side then treats the other's rising number as authoritative, and the costs inflate by 2 per round until the maximum metric stops them.