Sub topic 9
Link-state protocols and OSPF
This chapter assumes you know IPv4 addressing and CIDR notation, the difference between a router and a host, and basic router command-line use. It also assumes you have read the chapters on metrics and distance-vector protocols.
The working model
A link-state protocol gives every router the same map of the network. Each router describes its own links and neighbors in a small advertisement. It floods that advertisement to every other router in the area. Each router stores the advertisements in a link-state database (LSDB). All routers in an area hold identical copies of that database.
Each router then runs the shortest path first (SPF) algorithm, also called Dijkstra's algorithm, on its LSDB. The router puts itself at the root of the tree and calculates the lowest-cost path to every prefix. The results go into the routing table.
Distance-vector routers only know what their neighbors tell them. Link-state routers see the whole topology, so they avoid many loops and usually converge faster.
How OSPF works
Open Shortest Path First (OSPF) is the most common link-state protocol inside one organization. OSPFv2 carries IPv4 routes.
- Routers send Hello packets on each interface to find neighbors.
- Neighbors agree on parameters such as area ID and timers, then exchange their databases. This forms an adjacency.
- Each router floods link-state advertisements (LSAs) describing its links.
- Each router runs SPF and installs the best routes.
- When a link changes, only the change is flooded, and every router reruns SPF.
OSPF uses cost as its metric. On Cisco IOS, cost is the reference bandwidth (100 Mbps by default) divided by the interface bandwidth. A route's total cost is the sum of the costs of the outgoing interfaces along the path.
Areas
Flooding and SPF cost grow with the size of the database. OSPF limits this with areas. Area 0 is the backbone, and all other areas connect to it. Routers inside an area share a full map. Routers between areas summarize what they pass along. A change in one area then causes less recalculation in the others.
A basic configuration
! Cisco IOS: enable OSPF on interfaces in 10.1.0.0/16 and put them in area 0
router ospf 1
router-id 1.1.1.1
network 10.1.0.0 0.0.255.255 area 0The network command uses a wildcard mask. 0.0.255.255 means the first two octets must match and the last two can be anything. Any interface whose address falls in that range runs OSPF in area 0 and its subnet is advertised.
To check the result:
show ip ospf neighbor
show ip ospf database
show ip route ospfCommon errors
| Symptom | Likely cause |
|---|---|
| Neighbor stuck and never reaches Full | Mismatched area ID, Hello/dead timers, subnet mask, or authentication |
| No neighbors at all | Interface not matched by a `network` statement, or marked passive |
| Wrong path chosen | Costs follow the default reference bandwidth, so fast links look equal |
| Route missing from the table | Another source with a lower administrative distance won |
Trade-offs
- Link-state needs more memory and CPU than distance-vector, because each router holds the full map and runs SPF.
- It converges quickly, since routers react to a flooded change instead of waiting for periodic updates.
- Areas and good address planning are needed to keep large networks manageable.
Exercise
Two routers on the same link never reach the Full state. Name two settings you would compare on both routers.
Show answer
Compare the area ID and the Hello/dead timers. Subnet mask and authentication settings are also valid answers, since any mismatch stops the adjacency from forming.
Exercise
Why does every router in an OSPF area get the same SPF result for the shape of the network, even though each computes its own routes?
Show answer
Every router holds an identical LSDB, so they all see the same topology. Each one runs SPF with itself as the root, so the routes differ but they are consistent with the same map.