OSPF
What
Link-state interior gateway protocol
Why
Link-state allows for rapid convergence
Hierarchical updates with areas -> better scalability
Each router has complete knowledge -> optimal path calculation
SPF guarantees a loop free path (loop is never shortest)
Load balancing among equal-cost paths
Concepts
- Link-state protocol: tell the world about your neighbours
- Areas
- Hierarchical design divides networks into areas
- Area 0: backbone, all areas must connect to this
- Link-state database (LSDB)
- Database of complete topology
- Identical on all routers within an area
- Metric
- In OSPF the metric is based on the bandwidth of each hop's outgoing interface
- Routing table: created from SPF calculation on the LSDB
- Router types
- Internal router (IR): all interfaces belong to the same area
- Area border router (ABR): has interfaces in multiple areas
- Backbone router (BBR): has an interface in area 0
- Autonomous System Boundary Router (ASBR): redistributes external routes learnt from other protocols/ASes
- LSA Types (Link-State Advertisements):
- Type 1 (Router LSA): Router's directly connected links, flooded within area only
- Contains 3 flags that indicate the role:
- B: border router
- E: external routing capability
- V: virtual link endpoint
- Contains 3 flags that indicate the role:
- Type 2 (Network LSA): Generated by DR for multi-access networks, flooded within area
- Type 3 (Network Summary LSA): Generated by ABR, summarizes inter-area routes
- Type 4 (ASBR Summary LSA): ABR advertises how to reach ASBR
- Type 5 (External LSA): Generated by ASBR, describes external routes, flooded throughout AS
- Type 6 (Group Membership LSA) Used in multicast OSPF
- Type 7 (NSSA External LSA) used inside a not-so-stubby-area, translated to type 5 by ABR
- Type 1 (Router LSA): Router's directly connected links, flooded within area only
- Neighbour States:
- Down: No hellos received
- Init: Hello received, but doesn't contain our Router ID
- 2-Way: Bidirectional communication established, neighbour sees us in hello
- ExStart: Master/slave relationship negotiated for LSDB exchange
- Exchange: Database Description (DBD) packets exchanged
- Loading: Requesting missing LSAs via Link-State Request (LSR)
- Full: LSDB fully synchronized, adjacency complete
- Router Roles:
- Designated Router (DR): forms adjacencies with ALL routers in the network
- Backup DR (BDR): forms adjacencies with ALL routers in the network, will act as temporary DR when the main DR fails
- DROther: any other router in the network
- OSPFv3
- For IPv6
- Uses multicast
ff02::5all OSPF speakersffo2::6: all designated routers (DRs)
- LSA:
- Header: LS Type, Link-State ID, Advertising Router
- Sequence Number: For versioning
- Age: For aging / flooding control
- Checksum: For integrity verification
- LSA Content: Depends on LS type: metric, links, network mask, external route info, etc
Data in OSPF
1. Neighbour Table
- Lists adjacent OSPF routers
- Tracks: Neighbour Router ID, IP address, interface, state, priority, DR/BDR role
- Command:
show ip ospf neighbor
2. Topology Table / Link-State Database (LSDB)
- Complete network topology map for each area
- Contains all LSAs received from all routers
- Identical on all routers within same area
- Command:
show ip ospf database
3. Routing Table
- Best paths calculated by SPF algorithm from LSDB
- Actually used for packet forwarding
- Command:
show ip route ospf
Packets in OSPF
Type 1: Hello
- Purpose: Discover and maintain neighbors
- Frequency: Every 10s (broadcast/P2P) or 60s (NBMA)
- Contains: Router ID, Area ID, timers, DR/BDR, neighbor list
- Reliable: No (no ACK required)
Type 2: Database Description (DBD)
- Purpose: Exchange LSA summaries during adjacency formation
- Contains: LSA headers (not full LSAs) - like table of contents
- When: During ExStart and Exchange states
- Reliable: Yes (sequence numbers)
Type 3: Link-State Request (LSR)
- Purpose: Request specific full LSAs
- Contains: List of needed LSAs (Type, Link-State ID, Advertising Router)
- When: During Loading state, after comparing DBDs
- Reliable: Yes (response expected)
Type 4: Link-State Update (LSU)
- Purpose: Deliver full LSAs (the actual routing data)
- Contains: One or more complete LSAs
- When: In response to LSR, or when flooding topology changes
- Reliable: Yes (requires LSAck)
Type 5: Link-State Acknowledgment (LSAck)
- Purpose: Acknowledge receipt of LSAs
- Contains: List of acknowledged LSA headers
- When: After receiving LSU
- Reliable: N/A (it is the acknowledgment)
Election
Within each network, a Designated Router (DR) and Backup DR (BDR) are selected
Election criteria:
- Highest priority (0-255, default 1, 0 = never become DR)
- Highest router ID
Router ID is created by:
- Manual configuration
- Highest IP on loopback interface
- Highest IP on any interface
Election occurs when the network comes up, or when DR/BDR fails
Roles are sticky, so if a new device with a higher priority joins, the existing DR will stay
BDR only acts as DR when initial DR fails, until the re-election has completed
Example:
Network: 192.168.1.0/24 (Ethernet)
R1: Priority 100, Router ID 3.3.3.3
R2: Priority 200, Router ID 2.2.2.2 ← Becomes DR (highest priority)
R3: Priority 100, Router ID 4.4.4.4 ← Becomes BDR (second highest priority, then highest RID)
R4: Priority 50, Router ID 1.1.1.1
Result:
DR: R2
BDR: R3
DROther: R1, R4
How
Neighbour discovery & adjacency formation
- Enable OSPF
- Send hello packet
R1 sends Hello on Gi0/0:
Source: 192.168.1.1
Destination: 224.0.0.5 (AllSPFRouters multicast)
Protocol: OSPF (IP protocol 89)
Hello Packet contents:
Router ID: 1.1.1.1
Area ID: 0.0.0.0 (Area 0)
Network Mask: 255.255.255.0
Hello Interval: 10 seconds
Dead Interval: 40 seconds
Priority: 1
DR: 0.0.0.0 (none yet)
BDR: 0.0.0.0 (none yet)
Neighbors: [] (empty list)
- R2 receives hello
R2 receives Hello from R1
Checks parameters:
- Area ID matches? ✅ (both Area 0)
- Subnet mask matches? ✅ (both /24)
- Hello/Dead intervals match? ✅
- Authentication matches? ✅ (if configured)
- Stub flag matches? ✅
R2: Parameters match, add R1 to neighbor table
R2 Neighbor Table:
Neighbor: 1.1.1.1 (R1)
Interface: Gi0/0
State: Init ← Saw R1's hello, but R1 hasn't seen ours yet
Dead timer: 40 seconds
Priority: 1
- R2 sends hello with R1 in neighbour list
- R1 receives hello with it's router ID in neighbour list
- R2 receives next hello from R1
They now both see one another, state fromInit -> 2-Way
DR/BDR Election
Situation:
R1: Router ID 1.1.1.1, Priority 1, IP 192.168.1.1
R2: Router ID 2.2.2.2, Priority 100, IP 192.168.1.2
R3: Router ID 3.3.3.3, Priority 1, IP 192.168.1.3
- Election happens:
All routers examine Hello packets received:
R1 sees: R2 (priority 100), R3 (priority 1), self (priority 1)
R2 sees: R1 (priority 1), R3 (priority 1), self (priority 100)
R3 sees: R1 (priority 1), R2 (priority 100), self (priority 1)
Election criteria:
1. Highest priority wins
2. Tie-breaker: Highest Router ID
DR election:
R2: Priority 100 ← WINNER (highest priority)
BDR election (exclude DR):
R3: Priority 1, RID 3.3.3.3 ← WINNER (highest RID among priority 1)
R1: Priority 1, RID 1.1.1.1
- Election results
DR: R2 (2.2.2.2)
BDR: R3 (3.3.3.3)
DROther: R1 (1.1.1.1)
R1 Neighbor Table:
R2: State 2-Way, DR
R3: State 2-Way, BDR
R2 Neighbor Table:
R1: State 2-Way, DROther
R3: State 2-Way, BDR
R3 Neighbor Table:
R1: State 2-Way, DROther
R2: State 2-Way, DR
- Form adjacencies
Adjacency rules on broadcast networks:
- DROther routers: Form adjacency with DR and BDR only
- DR: Forms adjacency with ALL routers
- BDR: Forms adjacency with ALL routers
R1 (DROther):
- Form adjacency with R2 (DR) ✅
- Form adjacency with R3 (BDR) ✅
- Stay in 2-Way with other DROthers
R2 (DR):
- Form adjacency with R1 ✅
- Form adjacency with R3 ✅
R3 (BDR):
- Form adjacency with R1 ✅
- Form adjacency with R2 ✅
Database/LSDB exchange
Example between R1 and R2
- Determine master/slave,
ExStartstate- Send Database Description (DBD) packets to one another
- The one with highest router ID become master
- Master controls the sequence numbers
- Send database summaries
- Master and slave both send DBD with Link State Advertisement (LSA) headers, so not full LSAs to save bandwidth
- Compare received summaries
- Both sides compare received summaries to their LSDB to see which LSAs they are missing / are outdated
Loading State: exchange missing LSAs
- R1/R2 sends headers of missing LSAs
- Other party responds with full LSAs
- R1/R2 acknowledges and installs them in LSDB
SPF calculation
With all LSAs exchanged, every router now has a complete view of the area/network
Then, they use Dijkstra to calculate the shortest path to each destination
These shortest paths end up in the actual routing table
Since every router has the same view, the results are consistent, so no special sauce is needed to make the packet follow the shortest path calculated, all routers will agree and cooperate
Updates
- A new network gets attached to R3
- R3 updates it's own LSA and sends it in a Link State Update (LSU) to the DR & BDR
- DR floods this to all other neighbours
- All routers run SPF and update their routing tables