71. OSPF in depth
71.1 The model
Open Shortest Path First (RFC 2328 for OSPFv2/IPv4; RFC 5340 for OSPFv3/IPv6) is the dominant enterprise link-state IGP.
1. Discover neighbours (Hello packets, multicast 224.0.0.5)
2. Form ADJACENCIES (not with everyone -- see DR/BDR)
3. Exchange the LINK-STATE DATABASE (LSDB) -- every router ends up with an
IDENTICAL copy for its area
4. Run DIJKSTRA (SPF) on that database, from itself, to get shortest paths
5. Install the results in the routing table
6. Re-flood on any change; re-run SPF
OSPF runs directly on IP, protocol number 89 — not TCP or UDP. It provides its own reliability (acknowledged LSAs).
71.2 Neighbour states and adjacency
Down -> Init -> 2-Way -> ExStart -> Exchange -> Loading -> FULL
^ ^
"I see you seeing me" databases synchronised
Stuck states are diagnostic:
| Stuck at | Almost always means |
|---|---|
Init |
Hellos are one-way — the other side isn't hearing you (ACL, unidirectional link) |
2-Way (on a broadcast segment) |
Normal — non-DR routers stay 2-Way with each other by design |
ExStart |
MTU mismatch between neighbours (Ch. 15 again) |
Loading |
Packet loss or LSA problems |
| Flapping | Hello/dead timer mismatch, or a genuinely unstable link |
Hello/dead intervals must match (default 10 s / 40 s on broadcast links), as must the area ID, authentication, and the stub-area flag, or the adjacency never forms.
71.3 DR and BDR
On a broadcast segment with n routers, full mesh adjacency would need
n(n-1)/2 relationships. OSPF elects a Designated Router and Backup DR;
everyone else forms full adjacency only with the DR/BDR and stays 2-Way
with each other.
Election: highest OSPF priority (default 1; 0 = never DR), tie-break on
highest Router ID.
NOT pre-emptive -- a better router arriving later does NOT take over.
DR/BDR does not exist on point-to-point links. On point-to-multipoint or NBMA topologies, misconfigured network types are a classic source of "adjacency won't form".
71.4 Areas and LSA types
OSPF scales by hierarchy. Every area must connect to area 0 (the backbone); inter-area traffic transits area 0.
+------------------ Area 0 (backbone) ------------------+
| |
[ABR]| |[ABR]
| |
Area 1 Area 2
(SPF runs only within an area; ABRs summarise between them)
| LSA type | Name | Carries | Scope |
|---|---|---|---|
| 1 | Router LSA | This router's own links and costs | within the area |
| 2 | Network LSA | The segment, generated by the DR | within the area |
| 3 | Summary LSA | Inter-area prefixes, generated by an ABR | into another area |
| 4 | ASBR Summary | How to reach an ASBR | between areas |
| 5 | External LSA | Routes redistributed from outside OSPF, by an ASBR | flooded domain-wide |
| 7 | NSSA External | Externals inside a not-so-stubby area (converted to type 5 at the ABR) | within an NSSA |
Area types control which LSAs are allowed in, trading visibility for size:
| Area type | Blocks | Result |
|---|---|---|
| Standard | nothing | Full LSDB |
| Stub | type 5 (externals) | ABR injects a default route instead |
| Totally stubby | types 3, 4, 5 | Only a default route — smallest tables |
| NSSA | type 5, but allows type 7 | A stub area that still has its own external connection |
Roles: ABR = Area Border Router (touches area 0 and another area); ASBR = Autonomous System Boundary Router (redistributes external routes in).
71.5 Cost, and the reference-bandwidth trap
cost = reference_bandwidth / interface_bandwidth
Default reference bandwidth = 100 Mbit/s. Therefore:
100 Mbit link -> cost 1
1 Gbit link -> cost 1 <-- same!
10 Gbit link -> cost 1 <-- same!
100 Gbit link -> cost 1 <-- same!
Every link at or above 100 Mbit/s has cost 1 by default, so OSPF cannot tell a
gigabit link from a 100-gigabit one, and picks by hop count instead. Fix:
auto-cost reference-bandwidth 100000 (100 Gbit/s) — and set it identically on
every router, or you get asymmetric routing.
Equal-cost paths are load-balanced (ECMP, Ch. 50.3).
71.6 OSPFv3 differences
- Runs over IPv6 (protocol 89 still), addresses in LSAs are separated from topology, so it can carry multiple address families.
- Adjacencies form over link-local addresses (
fe80::). - Authentication is delegated to IPsec rather than being built in.
- Router IDs are still 32-bit dotted-quad values, even in IPv6.
71.7 Real-world example
A campus network had two data centres connected by both a 10 Gbit/s dark-fibre link (2 hops) and a 1 Gbit/s backup (1 hop). Traffic consistently chose the 1 Gbit/s path. Cause: default reference bandwidth, so both links cost 1, and the 1-hop path had a lower total cost. Raising the reference bandwidth to 100 Gbit/s on every router made the fibre cost 10 and the backup cost 100 — traffic moved immediately. Check reference bandwidth on every OSPF network you inherit.
Try it yourself
# FRRouting on two Linux boxes/containers
sudo vtysh
configure terminal
router ospf
ospf router-id 1.1.1.1
auto-cost reference-bandwidth 100000
network 10.0.0.0/24 area 0
exit
end
show ip ospf neighbor # look for state FULL
show ip ospf database # the LSDB -- LSA types visible
show ip ospf interface eth0 # cost, hello/dead, DR/BDR, network type
show ip route ospf