Sub topic 19
RIP: hop count and the infinity value of 16
This chapter assumes you know distance-vector routing and the Bellman-Ford update from the earlier chapters. It also assumes you know what split horizon and poison reverse do. Here we look at the protocol that puts those ideas into practice, the Routing Information Protocol (RIP).
What RIP is
RIP is a distance-vector protocol for routing inside one autonomous system. Its metric is hop count, the number of routers a packet crosses on the way to a destination network. RIP ignores bandwidth, delay and load.
Each router keeps a table with three main columns: destination network, metric, and next-hop router. It sends its whole table to its neighbours and recomputes its own routes from what it hears. RIP messages travel in UDP datagrams on port 520.
The metric and the value 16
A valid RIP metric runs from 1 to 15. The value 16 means infinity, which means unreachable. A router that receives a route advertised with metric m computes min(m + 1, 16).
The choice of 16 is a trade-off:
- A small infinity bounds the count-to-infinity problem. A bad route stops growing once it reaches 16.
- A small infinity also caps the network diameter at 15 hops. A destination 16 or more hops away can never be reached.
Some textbooks count a directly connected network as 0 hops and some count it as 1. Both conventions appear in exam questions. Read the question to see which one it uses. The infinity value is 16 in both.
The update rule
When a router receives an advertisement from a neighbour, it applies three cases to each destination:
- If the destination is new and the computed metric is below 16, add the route.
- If the advertisement comes from the router's current next hop, accept the new metric even when it is worse. The next hop is the authority on that path.
- If the advertisement comes from any other neighbour, accept it only when its metric is strictly lower than the current one.
Case 2 is how bad news spreads. If your next hop says the destination is now farther away, your route to it must be farther away too.
INFINITY = 16
def process_update(table, neighbor, advertised):
"""table: destination -> (metric, next_hop)."""
for dest, m in advertised.items():
new = min(m + 1, INFINITY)
current = table.get(dest)
if current is None:
if new < INFINITY:
table[dest] = (new, neighbor)
elif current[1] == neighbor:
table[dest] = (new, neighbor)
elif new < current[0]:
table[dest] = (new, neighbor)
return table
table = {"N1": (2, "R2"), "N2": (3, "R3")}
print(process_update(table, "R2", {"N1": 15, "N2": 1, "N3": 4}))The program prints {'N1': (16, 'R2'), 'N2': (2, 'R2'), 'N3': (5, 'R2')}. The results follow the three cases:
N1comes from the current next hop R2, so the metric becomes 16 (15 + 1) even though it is worse.N2is cheaper through R2 (1 + 1 = 2 against 3), so the route switches.N3is new and costs 5.
Timers
RIP relies on timers, because a router that has crashed sends no "I am gone" message.
| Timer | Default | Purpose |
|---|---|---|
| Update | 30 s | Send the full table to neighbours |
| Timeout | 180 s | If no update refreshes a route, mark it invalid with metric 16 |
| Garbage collection | 120 s | Keep advertising the metric-16 route so neighbours learn the news, then delete it |
Count-to-infinity in RIP
Take a chain A, B, C, with destination network X attached to C. Count a connected network as 1 hop, so C has metric 1, B has 2 and A has 3.
Suppose C's link to X fails. C sets its metric to 16. Before C's news reaches B, B advertises "X at 2" to C. C now believes X is 3 hops away through B. B then hears "3" from its own next hop C and moves to 4. C hears 4 from B and moves to 5. The metric for X climbs 3, 4, 5, and so on, until it reaches 16 and both routers drop the route.
With 30-second periodic updates this takes minutes, and packets for X loop between B and C the whole time. Infinity = 16 is what ends the loop. Two fixes shorten it:
- Split horizon: B does not advertise X back to C, because B learned X from C.
- Poison reverse: B advertises X back to C with metric 16, so C is told explicitly that this path is unusable.
- Triggered updates: a router sends a change immediately instead of waiting for the next 30-second tick.
Split horizon stops two-router loops. It does not stop loops involving three or more routers.
RIPv1 and RIPv2
| Feature | RIPv1 | RIPv2 |
|---|---|---|
| Destination address | Broadcast | Multicast 224.0.0.9 |
| Subnet mask in updates | No (classful) | Yes (supports CIDR and VLSM) |
| Authentication | None | Supported |
| Metric range | 1 to 15, 16 = infinity | Same |
RIPv1 cannot carry masks, so it cannot handle VLSM or CIDR blocks. This is why RIPv2 exists.
Where RIP fits
RIP is simple and needs little configuration. It converges slowly and its 15-hop limit rules it out for large networks. Because hop count ignores link speed, it may prefer one slow link over two fast ones. Link-state protocols such as OSPF avoid these problems at the cost of more memory and CPU.
Exercise
A RIP router currently has a route to network N at metric 5 via next hop R1. Neighbour R2 advertises N with metric 3. Neighbour R1 then advertises N with metric 15. What are the metric and next hop after each advertisement, in that order?
Show answer
After R2's advertisement the route is metric 4 via R2, because 3 + 1 = 4 is lower than 5. R1 is no longer the next hop, so its later advertisement is compared as an ordinary neighbour. R1's metric would be 15 + 1 = 16, which is not lower than 4, so it is ignored. The final route is metric 4 via R2.
Exercise
Why can RIP not be used in a network where two hosts are 20 routers apart? Name one thing that gets worse if the infinity value were raised to 255.
Show answer
A metric of 16 means unreachable, so any destination 16 or more hops away cannot be reached. The network diameter is therefore limited to 15. Raising infinity to 255 would allow larger networks, but count-to-infinity would take far longer to finish, so routing loops would last much longer.