Sub topic 1
What a Routing Protocol Has to Do
Prerequisites
This chapter assumes you already know four things:
- Basic IP addressing and subnetting, including prefix notation such as
10.1.2.0/24. - The difference between a router and a switch. A router forwards packets between networks using IP addresses. A switch forwards frames inside one network using MAC addresses.
- What a routing table is, and how longest-prefix match picks the most specific route for a destination address.
- Basic graph terms: nodes, edges, weights, and shortest path.
You do not need to know any routing protocol yet. This chapter explains the problem that routing protocols solve. Later chapters cover the algorithms.
Routing and forwarding are different jobs
Two words are often mixed up, but they describe separate activities that run at different speeds.
- Forwarding is the per-packet action. A router reads the destination address of an incoming packet, looks it up in its forwarding table, and sends the packet out of the chosen interface to the chosen next hop. This must happen in microseconds or less, and in most routers it is done by dedicated hardware.
- Routing is the process that builds the table. It runs in software, reacts to events such as link failures, and can take milliseconds to minutes.
The routing process is the control plane. The forwarding action is the data plane. A routing protocol belongs to the control plane. It never touches user packets. Its output is a set of entries that the data plane uses.
| Aspect | Forwarding | Routing |
|---|---|---|
| Plane | Data plane | Control plane |
| Triggered by | Every packet | Topology or configuration changes, and timers |
| Input | Packet destination address | Messages from other routers, local interface state |
| Output | Packet sent out one interface | Entries in the routing table |
| Typical speed | Nanoseconds to microseconds | Milliseconds to minutes |
If you have used static routes, you have already done the routing job by hand: you decided which next hop reaches which prefix. A routing protocol automates that decision.
Why static routes are not enough
Static routes work for a small network with one path to each destination. They fail in three situations:
- Scale. A network with 200 routers and thousands of prefixes has too many entries to maintain by hand, and one typo can black-hole traffic.
- Failure. A static route has no idea that its next hop has died. It keeps sending packets into the failure until a human intervenes.
- Change. Adding a subnet means editing every router that needs to reach it.
A routing protocol replaces manual entry with a distributed computation. Each router learns about the network from other routers and decides for itself.
What a routing protocol must supply
Whatever its algorithm, every routing protocol has to provide the same five functions.
- Discover neighbors. A router must know which other routers are directly reachable and whether those links are up.
- Learn destinations. A router must learn which prefixes exist and which router can reach them. This includes the prefixes attached to its own interfaces.
- Choose the best path. When more than one path exists, the router needs a rule to compare them. That rule is the metric (covered in the chapter on link costs).
- Install routes. The best path for each prefix becomes a routing table entry: prefix, next hop, outgoing interface, and cost.
- React to change. When a link or router fails, or a new one appears, the router must update its table and tell others. The time it takes for all routers to agree again is the convergence time.
The two algorithm families in this tutorial differ mainly in how they do steps 2, 3, and 5.
- Distance-vector routers share their routing table, in summary form, with neighbors only. Each router knows only how far each destination is and which neighbor leads there.
- Link-state routers share the state of their own links with every router in the area. Each router builds a full map and computes paths itself.
Properties a good protocol must have
Beyond the five functions, a routing protocol is judged by how well it behaves.
- Correctness. The paths it installs must actually reach the destination and must be loop-free. A routing loop makes packets circle until their TTL reaches zero.
- Convergence speed. Traffic is lost or misdirected while routers disagree. Faster agreement means less damage.
- Scalability. Memory, CPU, and bandwidth use must grow slowly as routers and prefixes are added.
- Stability. A flapping link should not cause a storm of updates that overloads every router.
- Low overhead. Control traffic must not crowd out user traffic on slow links.
- Manageability. Configuration should be small and predictable, and failures should be diagnosable.
These goals conflict. Fast convergence usually costs more control traffic or more CPU. Full topology knowledge scales worse than neighbor-only knowledge. Most of the later chapters are about these trade-offs.
Where a routing protocol sits
A routing protocol does not feed the forwarding hardware directly. Several steps sit between them.
A router may run several protocols at once, and each offers its own candidate route for the same prefix. The router then picks one using administrative distance, a trust ranking assigned to each route source. A lower value wins. On Cisco IOS, a connected route is 0, a static route is 1, OSPF is 110, and RIP is 120. Metrics from different protocols are not comparable, so administrative distance is checked first. The metric is only used to choose between routes from the same protocol.
After the routing table picks a winner, longest-prefix match decides which entry applies to a given packet. A /24 route from RIP beats a /16 route from OSPF for an address inside the /24, because specificity is checked before administrative distance.
A small example
Consider a network of four routers, A to D, with these links and costs:
- A to B: 1
- B to C: 1
- A to D: 4
- C to D: 1
Router A needs to reach a prefix attached to D. There are two paths:
| Path | Total cost |
|---|---|
| A, D | 4 |
| A, B, C, D | 3 |
A good protocol chooses the three-hop path, because 3 is less than 4. Router A then installs one entry: the prefix, with next hop B and cost 3. A does not need to store the whole path, only the first hop. Each router along the way makes its own decision using its own table. This is hop-by-hop forwarding, and it is why routers must agree. If B believed the best path to D ran back through A, a loop would form.
Now suppose the link B to C fails. The protocol must:
- Detect the failure, through a missed message or a lost link signal.
- Withdraw or replace every route that used that link.
- Inform the other routers so they do the same.
After convergence, A's entry for D's prefix becomes next hop D with cost 4. Between failure and convergence, packets may be dropped or may loop.
Common errors and misconceptions
- "The routing protocol forwards packets." It does not. It only fills the table.
- "The lowest metric always wins across protocols." Administrative distance decides between protocols first.
- "Routers know the whole path." In hop-by-hop forwarding, each router knows only its next hop. Link-state routers know the full topology, but still install only a next hop.
- "Convergence is instant." It takes time, and the choice of protocol and timers decides how long.
- "More routing information is always better." Extra state increases CPU and memory cost and slows convergence in large networks.
Exercise
A router learns the prefix 192.0.2.0/24 from RIP with a metric of 2 and from OSPF with a cost of 30. Using the Cisco defaults in this chapter, which route does it install, and why is the lower number (2) not used?
Show answer
It installs the OSPF route. Administrative distance is compared first, and OSPF (110) beats RIP (120). The metrics 2 and 30 come from different protocols with different meanings (hop count versus bandwidth-based cost), so they cannot be compared. Metrics are only used to choose between routes from the same protocol.
Exercise
In the four-router example, the link A to D has its cost changed from 4 to 2. What are the new best path and the new next hop at A for D's prefix?
Show answer
The direct path A, D now costs 2, which is less than the 3 of A, B, C, D. The best path is A, D, so A's next hop for D's prefix is D with cost 2.