Skip to main content

OSPF working with routing tables

Short answer

OSPF is a link-state protocol using Hello packets for neighbour discovery, LSA flooding to build identical link-state databases, and Dijkstra SPF to compute shortest paths. In the example, R1 reaches PC2's LAN 192.168.3.0/24 via next hop 10.0.12.2 with cost 21.

Describe the working process of OSPF with example. Illustrate your answer with routing tables between source and destination machine. (Assume IP address, cost and network diagram by yourself).

OSPF

Open Shortest Path First (OSPF) is a link-state interior gateway protocol (OSPFv2 in RFC 2328) that runs inside an autonomous system. Each router learns the whole topology and computes the shortest path to each network using Dijkstra's SPF algorithm. It is classless, supports VLSM, converges quickly, uses multicast 224.0.0.5/224.0.0.6, runs directly over IP (protocol 89) and uses cost as metric (cost = reference bandwidth / link bandwidth).

Working process

  1. Neighbour discovery: routers send Hello packets on each interface (every 10 s). Neighbours with matching area, timers and authentication reach the 2-Way state. On multi-access LANs a Designated Router (DR) and Backup DR are elected.
  2. Database exchange: neighbours exchange Database Descriptions (ExStart/Exchange), request missing records (Loading) and reach the Full state.
  3. LSA flooding: each router describes its links and costs in Link State Advertisements, flooded to all routers in the area, so every router has an identical Link State Database (LSDB).
  4. SPF calculation: each router runs Dijkstra with itself as the root and builds a shortest path tree.
  5. Routing table: best routes are installed. Equal-cost paths can be load-balanced.
  6. Maintenance: Hellos continue; if a link changes, a new LSA is flooded and SPF is re-run.

Example (assumed)

PC1--LAN1--[R1]---cost 10---[R2]--LAN2
 .1.10     |    10.0.12.0/30  |  192.168.2.0/24
           |                  |
     cost 30             cost 10
  10.0.13.0/30        10.0.23.0/30
           |                  |
           +------[R3]--------+
                    |
                  LAN3 --- PC2
              192.168.3.0/24 (.3.10)

Interfaces: R1: 192.168.1.1/24, 10.0.12.1, 10.0.13.1. R2: 10.0.12.2, 10.0.23.1, 192.168.2.1/24. R3: 10.0.23.2, 10.0.13.2, 192.168.3.1/24. LAN costs = 1.

SPF from R1: to R2 = 10; to R3 via R2 = 10 + 10 = 20 (direct link costs 30, so rejected); to LAN3 = 20 + 1 = 21 via R2.

Routing table of R1

DestinationTypeNext hopCost
192.168.1.0/24Connected-1
10.0.12.0/30Connected-10
10.0.13.0/30Connected-30
192.168.2.0/24OSPF10.0.12.211
10.0.23.0/30OSPF10.0.12.220
192.168.3.0/24OSPF10.0.12.221

Routing table of R2

DestinationTypeNext hopCost
192.168.2.0/24Connected-1
10.0.12.0/30Connected-10
10.0.23.0/30Connected-10
192.168.1.0/24OSPF10.0.12.111
192.168.3.0/24OSPF10.0.23.211
10.0.13.0/30OSPF10.0.12.1 or 10.0.23.2 (equal)40

Routing table of R3

DestinationTypeNext hopCost
192.168.3.0/24Connected-1
10.0.23.0/30Connected-10
10.0.13.0/30Connected-30
192.168.2.0/24OSPF10.0.23.111
10.0.12.0/30OSPF10.0.23.120
192.168.1.0/24OSPF10.0.23.121

(R3 reaches LAN1 via R2: 10 + 10 + 1 = 21, better than direct 30 + 1 = 31.)

Packet walk, PC1 (192.168.1.10) to PC2 (192.168.3.10):

  1. PC2 is outside PC1's subnet, so PC1 sends to its gateway 192.168.1.1 (R1).
  2. R1 matches 192.168.3.0/24 (cost 21), forwards to next hop 10.0.12.2 (R2).
  3. R2 matches 192.168.3.0/24 (cost 11), forwards to 10.0.23.2 (R3).
  4. R3 has 192.168.3.0/24 connected and delivers directly to PC2 (ARP, then frame). The reply follows R3 to R2 to R1 using the tables above.

Configuration on R1 (Cisco style)

router ospf 1
 network 192.168.1.0 0.0.0.255 area 0
 network 10.0.12.0 0.0.0.3 area 0
 network 10.0.13.0 0.0.0.3 area 0
interface s0/0
 ip ospf cost 10
interface s0/1
 ip ospf cost 30

✓ Answer checked by Claude Opus 5.5 (high effort)

All Internet and Intranet chapter 2 questions →