How does OSPF use Dijkstra's algorithm to build its routing table?
HardConceptRouting Protocols
Answer
OSPF (Open Shortest Path First) is a link-state protocol. Each router discovers its neighbours with Hello messages and floods link-state advertisements (LSAs) that describe its links and their costs. Every router in an area ends up with the same link-state database, a full map of the topology, and runs Dijkstra's shortest-path algorithm with itself as the root to build its routing table.
- Link cost is usually derived from bandwidth (reference bandwidth ÷ interface bandwidth), so a path over fast links can beat a path with fewer hops.
- When a link changes, only that change is flooded and routers rerun Dijkstra, so OSPF converges quickly and avoids count-to-infinity.
- Large networks are divided into areas joined by a backbone, area 0, to limit flooding and computation.
Example: Router A's view, with link costs A–B = 2, A–C = 5, B–C = 1, B–D = 4 and C–D = 1:
Step Settled Tentative distances from A
1 A B=2, C=5, D=inf
2 B C=min(5, 2+1)=3, D=2+4=6
3 C D=min(6, 3+1)=4
4 D done
The shortest paths are B = 2, C = 3 (A→B→C) and D = 4 (A→B→C→D), so A sends traffic for C and D to next hop B, even though it has a direct link to C.