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

Data in OSPF

1. Neighbour Table

2. Topology Table / Link-State Database (LSDB)

3. Routing Table

Packets in OSPF

Type 1: Hello

Type 2: Database Description (DBD)

Type 3: Link-State Request (LSR)

Type 4: Link-State Update (LSU)

Type 5: Link-State Acknowledgment (LSAck)

Election

Within each network, a Designated Router (DR) and Backup DR (BDR) are selected
Election criteria:

  1. Highest priority (0-255, default 1, 0 = never become DR)
  2. Highest router ID

Router ID is created by:

  1. Manual configuration
  2. Highest IP on loopback interface
  3. 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

  1. Enable OSPF
  2. 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)
  1. 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
  1. R2 sends hello with R1 in neighbour list
  2. R1 receives hello with it's router ID in neighbour list
  3. R2 receives next hello from R1
    They now both see one another, state from Init -> 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
  1. 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
  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
  1. 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

  1. Determine master/slave, ExStart state
    • Send Database Description (DBD) packets to one another
    • The one with highest router ID become master
    • Master controls the sequence numbers
  2. Send database summaries
    • Master and slave both send DBD with Link State Advertisement (LSA) headers, so not full LSAs to save bandwidth
  3. 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

  1. R1/R2 sends headers of missing LSAs
  2. Other party responds with full LSAs
  3. 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

  1. A new network gets attached to R3
  2. R3 updates it's own LSA and sends it in a Link State Update (LSU) to the DR & BDR
  3. DR floods this to all other neighbours
  4. All routers run SPF and update their routing tables