Archive 18 February 2019

OSPF Basics: From Neighbors to the SPF Tree

From zero to expert. OSPF (Open Shortest Path First) is the link-state IGP you meet on day one and keep meeting for the rest of your career. This guide starts with the absolute basics — what link-state means — and finishes on LSA types, area behaviour and the SPF algorithm itself. Almost every idea gets its own diagram.

1. What OSPF actually is: link-state

A distance-vector protocol tells its neighbours what it knows (routes and distances). A link-state protocol tells its neighbours what it sees (its directly connected links). Every router floods these link descriptions, so all routers in an area build an identical map — the Link-State Database (LSDB) — and each one independently runs Dijkstra to find its own shortest paths.

OSPF link-state modelNET BY MEEach router floods its links; all routers hold the SAME database, then compute paths independentlyR1LSDB copyR2LSDB copyR3LSDB copyR4LSDB copyIdentical Link-State Database → each router runs SPF (Dijkstra) locally

2. Areas and the two-level hierarchy

OSPF scales by splitting the domain into areas. Area 0 is the backbone; every other area must touch it. A router with interfaces in two areas is an ABR (Area Border Router) and summarises between them. A router that injects routes from outside OSPF is an ASBR (Autonomous System Boundary Router). Flooding is contained inside an area — a topology change in Area 1 never forces an SPF run in Area 2.

OSPF area hierarchyNET BY MEArea 0 — Backboneall areas must connect hereArea 1Area 2ABRABRABR = interfaces in two areas · ASBR = redistributes external routes into OSPF

3. How neighbours become adjacent

Two routers do not exchange databases until they walk a state machine. They discover each other with Hellos (Down → Init → 2-Way), elect a DR on multi-access links, then synchronise the LSDB (ExStart → Exchange → Loading → Full). Full is the only healthy end state for an adjacency that exchanges LSAs. Stuck in ExStart usually means an MTU mismatch; stuck in 2-Way between DROTHERs is normal.

OSPF neighbor state machineNET BY MEDownInit2-WayExStartExchangeLoadingFullHellos build 2-Way · DR elected · then DBD/LSR/LSU sync to Full. Stuck in ExStart → check MTU.

4. DR and BDR on multi-access links

On a broadcast segment, forming a full mesh of adjacencies would be O(n²) flooding. OSPF elects a Designated Router and Backup DR; everyone else (DROTHER) becomes Full with the DR/BDR only and stays 2-Way with each other. Election is highest priority (default 1), tiebreak highest Router-ID; priority 0 can never be DR. It is not pre-emptive — a higher-priority router joining later does not steal the role.

OSPF DR/BDR electionNET BY MEDRhighest prio / RIDBDRDROTHERDROTHERDROTHERDROTHERs go Full with DR & BDR only; they stay 2-Way with each other. Election is non-pre-emptive.

5. Cost: the OSPF metric

OSPF has no notion of bandwidth-as-metric the way EIGRP does; it uses a single additive cost per outgoing interface, cost = reference-bandwidth / interface-bandwidth, default reference 100 Mbps (10⁸). So a 10 Mbps link costs 10, FastEthernet costs 1, and — by default — Gigabit and 10 Gig both round to 1, which is the classic trap: raise auto-cost reference-bandwidth consistently everywhere or OSPF cannot tell a 1G link from a 100G one.

OSPF cost formulaNET BY MEcost = reference_bw (default 100 Mbps) ÷ interface_bw10 Mbpscost 10FastEthernetcost 1Gigabitcost 1 ⚠10 Gigcost 1 ⚠

⚠ Expertise: because cost is additive and per-interface, OSPF picks the path with the lowest sum of egress costs — it never load-balances unequally the way EIGRP can. Equal-cost paths (default up to 4) are used; everything else is ignored.

6. LSA types — reading the database like an expert

The LSDB is built from Link-State Advertisements. Knowing the six you meet daily is what separates “OSPF works” from “I can troubleshoot OSPF”:

OSPF LSA typesNET BY ME1Routerevery routerintra-area links and cost2NetworkDR onlythe multi-access segment and its routers3SummaryABRinter-area prefixes (area → area)4ASBR-SummaryABRhow to reach the ASBR5ExternalASBRredistributed routes, flooded domain-wide7NSSA ExternalASBR in NSSAexternal routes inside an NSSATypeLSAOriginated byDescribes

7. Area types — controlling what floods where

Stub-area flavours trade visibility for a smaller database. The rule to memorise: stub areas block Type 5 externals and inject a default; totally-stubby also blocks Type 3 inter-area; NSSA re-allows externals but carries them as Type 7, which the ABR translates back to Type 5 on the way to the backbone.

OSPF area typesNET BY MEStandardLSAs allowed1,2,3,4,5full visibilityStubLSAs allowed1,2,3 + defaultno Type 5Totally StubbyLSAs allowed1,2 + defaultno 3,4,5NSSALSAs allowed1,2,3,7 + defaultType 7 instead of 5

8. The SPF algorithm itself

Finally, the engine. Each router puts itself at the root and runs Dijkstra: it repeatedly moves the lowest-cost candidate from the tentative list onto the shortest-path tree, relaxing its neighbours. The result is a loop-free tree of lowest-cost paths to every prefix. Because every router in an area shares the same LSDB, their trees are consistent — which is why link-state does not form routing loops inside an area.

OSPF SPF shortest-path treeNET BY MEROOTABCDE1111Shortest-path tree from ROOT; dashed = higher-cost path pruned by SPF

Takeaway

OSPF is simple to say and deep to master: flood identical link-state, build one database per area, run Dijkstra. Everything advanced — areas, LSA types, stub flavours, cost tuning — is just controlling what enters that database and how far it floods. Get that mental model and the CLI stops surprising you.

Generic, vendor-neutral fundamentals from my own study and labs. No client- or employer-specific configuration.