Sub topic 13
How Routes Are Learned: Distance Vector, Link State, and BGP
This chapter assumes you can read a routing table, understand longest prefix match, and know the difference between the control plane and the data plane. Static routes work for small networks. Larger networks use dynamic routing protocols, which are programs on routers that exchange information and fill the routing table automatically. They run in the control plane. The data plane only uses the result.
Why dynamic routing
A static route does not notice when a link fails. An administrator must edit every router by hand. A dynamic protocol lets neighbors share what they know, so routers can detect failures and switch to another path.
Protocols fall into two groups. An interior gateway protocol (IGP) runs inside one organization's network, which is called an autonomous system (AS). An exterior gateway protocol runs between autonomous systems. BGP is the only exterior protocol in use today.
Distance vector
In a distance vector protocol, each router tells its neighbors which networks it can reach and how far away they are. "Distance" is a metric such as hop count. A router does not see the whole network. It only knows what its neighbors report.
RIP is the classic example. It counts hops and treats 16 as unreachable. A router adds one to the distance it hears from a neighbor and keeps the lowest total.
Distance vector is simple, but it converges slowly. Convergence means all routers agree on the current topology. After a failure, routers can keep passing stale routes to each other and count upward, a problem called count to infinity. Protocols reduce it with split horizon, which never advertises a route back out of the interface it was learned on. They also use a small maximum metric.
Link state
In a link state protocol, each router describes its own links and floods that description to every router in the area. Every router then holds the same map of the network. Each one runs Dijkstra's shortest path algorithm on that map to compute its own best routes.
OSPF and IS-IS are the common link state protocols. They converge faster than RIP and scale better, but they need more memory and CPU. Large networks are split into areas, so a change in one area does not force every router to recompute everything.
BGP: a path vector protocol
BGP exchanges routes between autonomous systems. Each AS has a number (ASN). Each BGP route carries an AS path, the list of ASNs the announcement passed through. A router rejects any route whose AS path already contains its own ASN, which prevents loops. BGP is called a path vector protocol for this reason.
BGP does not simply choose the lowest metric. It follows policy. Operators set preferences based on business relationships, such as preferring a customer link over a paid transit link. When no policy decides, shorter AS paths usually win. Common BGP attributes include local preference and AS path length.
| Property | Distance vector (RIP) | Link state (OSPF) | BGP |
|---|---|---|---|
| Router knows | Neighbors' distances | Full network map | Paths of ASNs |
| Typical scope | Small networks | One organization | Between organizations |
| Selection based on | Hop count | Shortest path cost | Policy, then AS path |
| Convergence | Slow | Fast | Slow, by design |
Exercise
A router running a link state protocol and a router running a distance vector protocol both need the best path to a network three hops away. What does each router know about the network that lets it compute that path?
Show answer
The distance vector router only knows the distance its neighbors report for that network, plus its own link to each neighbor. The link state router has a full map of the area from flooded link descriptions, and runs Dijkstra's algorithm on it to find the shortest path itself.
Exercise
Why does BGP include the AS path in each route, and what does a router do if its own ASN appears in it?
Show answer
The AS path records every AS the announcement has crossed. If a router sees its own ASN in the path, the route has looped back to it, so the router rejects the route. This prevents routing loops between autonomous systems.