Sub topic 8
Distance-vector protocols and RIP
This chapter assumes you know how a routing table, longest-prefix match and administrative distance work. It also assumes you have seen static routes configured. Here you will learn how distance-vector protocols build routes, why they can loop, and how RIP applies the idea.
The distance-vector idea
A distance-vector protocol makes each router share its own routing table with its neighbors. A router never sees the whole network. It knows only what its neighbors say: "I can reach network X at cost N."
A router that hears this adds the cost of the link to that neighbor. It keeps the route if it is better than what it already has. The next hop for that route is the neighbor that sent the advertisement.
The name has two parts:
- Distance is the metric, such as a hop count.
- Vector is the direction, meaning the next hop to use.
This method is the Bellman-Ford algorithm, spread across routers. It is sometimes called "routing by rumor", because a router trusts its neighbor's claim and cannot check it.
What every router exchanges
Each advertisement is a list of pairs: a destination prefix and a cost. A router sends this list to its neighbors at regular intervals. When a router receives an advertisement, it follows these steps:
- Add the cost of the incoming link to every advertised cost.
- If the destination is new, install it with the sender as next hop.
- If the new cost is lower than the stored cost, replace the route.
- If the sender is already the next hop and its cost changed, accept the change even when it is worse. The next hop is the only source of truth for that route.
Step 4 is what makes failures propagate. Step 4 is also what makes loops possible.
The count-to-infinity problem
Suppose C loses its connection to net-C. B still holds a route to net-C through C at cost 1. Before B hears the bad news, B advertises that route to C. C reasons that B can reach net-C at cost 1, so it installs a route through B at cost 2.
C now points at B, and B points at C. A packet for net-C bounces between them. B then hears from C that the cost is 2 and raises its own cost to 3. C hears that and raises its cost to 4. The costs keep growing, and they would grow forever if the protocol set no ceiling.
Distance-vector protocols limit the damage in four ways:
- A maximum metric. A cost at or above the limit means "unreachable". RIP sets the limit at 16.
- Split horizon. A router does not advertise a route out of the interface it learned that route from. B would never tell C about a route it learned from C.
- Poison reverse. A router advertises such a route back with the unreachable metric instead of staying silent. This removes stale information faster than silence does.
- Triggered updates and hold-down. A router sends a change immediately instead of waiting for the next timer. After a route fails, it ignores worse-looking news about that route for a set period.
The script below simulates three routers in a line (A, B, C). It makes C's own network fail, then counts how many exchange rounds pass before nothing changes. It runs once without split horizon and once with it.
INFINITY = 16
links = {"A": ["B"], "B": ["A", "C"], "C": ["B"]}
tables = {} # router -> {destination: (cost, next_hop)}
def advertise(sender, receiver, split_horizon):
ads = {}
for dest, (cost, next_hop) in tables[sender].items():
if split_horizon and next_hop == receiver:
continue
ads[dest] = cost
return ads
def update(receiver, sender, ads):
changed = False
for dest, cost in ads.items():
new = min(cost + 1, INFINITY)
current = tables[receiver].get(dest)
if current is None:
if new < INFINITY:
tables[receiver][dest] = (new, sender)
changed = True
elif new < current[0] or (current[1] == sender and new != current[0]):
tables[receiver][dest] = (new, sender)
changed = True
return changed
def converge(split_horizon, max_rounds=100):
rounds = 0
while rounds < max_rounds:
rounds += 1
sent = [(r, s, advertise(s, r, split_horizon))
for s in links for r in links[s]]
changed = False
for receiver, sender, ads in sent:
if update(receiver, sender, ads):
changed = True
if not changed:
break
return rounds
def scenario(split_horizon):
tables.clear()
tables.update({r: {f"net-{r}": (0, None)} for r in links})
converge(split_horizon)
tables["C"]["net-C"] = (INFINITY, None) # C's own network fails
rounds = converge(split_horizon)
cost = tables["A"]["net-C"][0]
print(f"split_horizon={split_horizon}: {rounds} rounds, "
f"A's final cost to net-C = {cost}")
scenario(False)
scenario(True)In both runs, A ends with cost 16 for net-C, which means unreachable. The run without split horizon needs many more rounds, because the two routers keep raising each other's cost one step at a time. With split horizon, B never sends C its own route back, so the bad news spreads in a few rounds.
RIP in practice
The Routing Information Protocol (RIP) is the best-known distance-vector protocol. It uses hop count as its metric: each router crossed adds one. A network 15 hops away is reachable, and 16 means unreachable. This limit caps the network diameter at 15 routers.
RIP sends its messages in UDP datagrams on port 520. Its default administrative distance on Cisco IOS is 120, so OSPF (110) beats it and a static route (1) beats it.
| Property | RIPv1 | RIPv2 |
|---|---|---|
| Transport | UDP 520, broadcast | UDP 520, multicast 224.0.0.9 |
| Subnet mask in updates | No (classful only) | Yes (supports CIDR and VLSM) |
| Authentication | None | Supported |
| Next-hop field | No | Yes |
RIPv1 does not carry masks, so it cannot handle variable-length subnets or discontiguous networks. Use RIPv2 whenever you must use RIP at all. IPv6 has its own version, RIPng, which uses UDP 521 and multicast ff02::9.
RIP timers
RIP depends on timers, and they set how slowly it reacts.
| Timer | Default | Purpose |
|---|---|---|
| Update | 30 s | Send the full table to neighbors |
| Invalid | 180 s | Mark a route unreachable if no update arrives |
| Hold-down | 180 s | Ignore worse news about a failed route |
| Flush | 240 s | Remove the route from the table |
A silent neighbor can therefore keep a dead route alive for three minutes. Triggered updates speed up the spread of news, but the router still has to notice the failure first.
Configuring RIPv2
This Cisco IOS example enables RIPv2 on interfaces in two classful networks:
router rip
version 2
no auto-summary
network 10.0.0.0
network 192.168.1.0The network command does two things. It enables RIP on every interface whose address falls inside that classful network. It also advertises the connected subnets of those interfaces. It does not take a mask, which is a common source of confusion.
no auto-summary stops the router from summarizing subnets to their classful boundary when it crosses a network boundary. Leaving auto-summary on is a frequent cause of missing routes in networks that use subnets of a larger block.
To check the result:
show ip protocols
show ip rip database
show ip route ripshow ip protocols lists the timers, the version, the networks and the neighbors that sent updates. show ip route rip shows only routes learned by RIP, marked with R. Each carries [120/N], where 120 is the administrative distance and N is the hop count.
Common errors
- Version mismatch. A RIPv2 router and a RIPv1 router on one link may disagree about masks. Set the version explicitly on every router.
- Auto-summary left on. Subnets disappear, or the router sends traffic to the wrong place, when discontiguous subnets exist.
- Missing or wrong
networkstatement. The interface sends no updates, so neighbors never learn its subnet. - Passive interface needed. On a LAN with no other routers, use
passive-interfaceso RIP stops sending updates there. The router still listens and still advertises the subnet. - Network wider than 15 hops. Destinations beyond that limit are unreachable by design.
Strengths and limits
The strengths of distance-vector routing are simple configuration, low memory use and low CPU use. The cost is that routers have no map of the network. They cannot check a neighbor's claim, so convergence is slow and loops are possible. RIP also ignores bandwidth. A path of two slow links beats a path of three fast ones, because it has fewer hops.
Larger networks usually need a link-state protocol, covered in a later chapter. Link-state routers hold a full map of the topology and compute paths themselves. Even so, RIP remains in use on small networks and in lab environments, and the distance-vector idea is the basis of BGP's path-vector design.
Exercise
Router X learns net-D from neighbor Y at RIP hop count 4. Later, Y advertises net-D at hop count 16. What does X do with its route, and why does X accept this change even though the new metric is worse?
Show answer
X marks net-D unreachable. Y is X's next hop for that route, so X must follow Y's latest information, even when the news is bad. If X ignored it, X would keep sending traffic toward a path that no longer works. A hop count of 16 means unreachable in RIP.
Exercise
A router running RIPv2 receives no update from a neighbor for 200 seconds. Using default timers, what has happened to the routes learned from that neighbor?
Show answer
The invalid timer (180 s) has expired, so the router has marked the routes unreachable and starts advertising them with metric 16. The flush timer (240 s) has not expired yet, so the entries are still in the table until then.