← Interview Prep

OSPF — Theory

Everything worth being able to explain about OSPF at a whiteboard: link-state mechanics, areas, LSAs, adjacencies, SPF, and convergence.

OSPF (Open Shortest Path First) is a link-state interior gateway protocol (IGP). Every router floods a description of its own links, so all routers in an area build an identical map of the topology — the Link-State Database (LSDB) — and then run Dijkstra's SPF algorithm independently to compute shortest paths. This differs fundamentally from distance-vector (RIP/EIGRP), where routers exchange computed routes and never see the full map.

Keep the mental model straight: link-state = flood the topology, compute routes locally. Because every router in an area has the same LSDB, routing loops within an area are structurally avoided. The metric is cost (lower is better), derived from interface bandwidth.

Overview: what OSPF is

PropertyValue
TypeLink-state IGP
AlgorithmDijkstra (SPF), run per area
MetricCost = reference-bandwidth ÷ interface-bandwidth (lower total wins)
TransportDirectly over IP, protocol number 89 (not TCP/UDP)
Administrative distance110 (Cisco)
ReliabilityIts own reliable flooding (LSU/LSAck), not TCP
Multicast224.0.0.5 (AllSPFRouters), 224.0.0.6 (AllDRouters)
HierarchyTwo-level: backbone area 0 + non-backbone areas

OSPFv2 vs OSPFv3

OSPFv2 (RFC 2328)OSPFv3 (RFC 5340)
Address familyIPv4IPv6 (extensible to IPv4 via AFs)
Runs overIPv4IPv6 (link-local source)
Adjacency scopePer subnetPer link (multiple subnets per link OK)
Addressing in LSAsPrefixes carried in Router/Network LSAsAddresses removed from topology LSAs; carried separately
AuthenticationBuilt-in (plaintext/MD5)Relies on IPsec (AH/ESP)

The area concept

An area is a set of routers that share an identical LSDB and run SPF together. Areas bound the scope of flooding and SPF, so a topology change in one area does not force every router in the domain to re-run SPF. Inter-area routing is summarized at Area Border Routers, which reintroduces a distance-vector-like behavior between areas (routers trust the summary, they don't see the far area's topology).

Router roles and the backbone rule

RoleDefinition
Internal routerAll interfaces in a single area.
Backbone routerHas at least one interface in area 0.
ABR (Area Border Router)Interfaces in two or more areas, one of which must be area 0. Generates inter-area summaries (Type 3) and maintains a separate LSDB per attached area.
ASBR (Autonomous System Boundary Router)Injects external routes into OSPF via redistribution (e.g. from BGP, static, another IGP). Originates Type 5 (or Type 7 in NSSA) LSAs.

The area 0 rule

            +----------------+
            |    Area 0      |   (backbone — every area
            |   backbone     |    must touch it)
            +--+---------+---+
   ABR1 -----/           \----- ABR2
      |                          |
  +---------+               +---------+
  | Area 1  |               | Area 2  |
  +---------+               +---------+

Neighbors, adjacencies, and the Hello protocol

OSPF discovers neighbors and maintains liveness with Hello packets, sent to 224.0.0.5. Two routers become neighbors when their Hellos agree on a set of parameters; only some neighbor pairs go on to form full adjacencies (exchange full LSDBs).

Parameters that must match to form an adjacency

Adjacency state machine

Down ─▶ Init ─▶ 2-Way ─▶ ExStart ─▶ Exchange ─▶ Loading ─▶ Full
 │        │        │         │           │           │         │
 │        │        │         │           │           │         └ full LSDB sync, adjacency up
 │        │        │         │           │           └ send LSRs for missing LSAs, get LSUs
 │        │        │         │           └ trade DBD (database description) headers
 │        │        │         └ elect master/slave, pick initial DBD seq #
 │        │        └ saw own RID in neighbor's Hello (bidirectional); DR/BDR election happens here
 │        └ received a Hello but not yet bidirectional
 └ no Hellos received
StateWhat is happening
DownNo Hellos heard from this neighbor.
InitA Hello was received, but it did not yet list our RID (one-way).
2-WayBidirectional: each sees its own RID in the other's Hello. DR/BDR election occurs. On multi-access, DROTHER pairs stop here (stay 2-Way).
ExStartMaster/slave negotiation and starting DBD sequence number.
ExchangeExchange DBD packets describing LSDB contents (headers only).
LoadingSend Link-State Requests for LSAs it lacks; receive Link-State Updates.
FullLSDBs synchronized; fully adjacent. This is the healthy steady state.
Interview trap: on a broadcast segment it is normal for two DROTHER routers to be stuck at 2-Way — they only go Full with the DR and BDR. Only stuck states like ExStart (MTU mismatch) or Init (one-way Hello / ACL) indicate a problem.

Network types

TypeDR/BDR?Neighbor discoveryExample
BroadcastYesDynamic (multicast Hellos)Ethernet LAN
Point-to-pointNoDynamicSerial link, /30, /31
NBMAYesManual (unicast) neighborsFrame Relay, classic hub-spoke
Point-to-multipointNoDynamic, treats as many p2pPartial-mesh WAN

DR/BDR election and why the DR exists

On a multi-access segment with n routers, forming a full mesh of adjacencies would need n(n-1)/2 adjacencies and each router would flood to every other — an O(n²) explosion of LSAs. OSPF elects a Designated Router (DR) that becomes the hub: every router forms a full adjacency only with the DR and the Backup DR (BDR), cutting adjacencies to O(n). The DR also originates the Type 2 (Network) LSA representing the segment as a pseudonode.

LSA types and the LSDB

The LSDB is built from Link-State Advertisements (LSAs). Each LSA type describes a different piece of the topology and has a defined flooding scope.

TypeNameOriginated byScopeDescribes
1Router LSAEvery routerAreaThe router's own links, states, and costs within the area.
2Network LSADR onlyAreaThe multi-access segment (pseudonode) and its attached routers.
3Summary / Inter-areaABRAreaAn IP prefix in another area (inter-area route), with cost.
4ASBR SummaryABRAreaHow to reach the ASBR (advertised into other areas so they can use Type 5s).
5AS ExternalASBRDomain (flooded everywhere except stub/NSSA)A route external to OSPF (redistributed).
7NSSA ExternalASBR in NSSANSSA area onlyExternal route inside an NSSA; the ABR translates it to a Type 5 at the area edge.

(Types 6 group-membership/MOSPF, 8–11 opaque LSAs exist; opaque Type 10 carries TE data for MPLS-TE. Types 1–5 and 7 are the interview core.)

Reliable flooding, sequence numbers, and age

SPF, cost, and ECMP

Each router runs Dijkstra's shortest-path-first over its LSDB, placing itself at the root of the SPF tree, then summing link costs to every destination.

cost = reference-bandwidth / interface-bandwidth

Cisco default reference-bandwidth = 100 Mbps
  10 Mbps  Ethernet   -> 100/10   = 10
  100 Mbps FastEth    -> 100/100  = 1
  1 Gbps   GigE       -> 100/1000 = 1  (rounds to 1 — a problem!)
  10 Gbps  10GigE     ->           = 1  (same as GigE)

Area types

Special area types reduce LSDB size by blocking certain LSAs at the ABR and substituting a default route. The tradeoff is always the same: less state, less optimal/granular routing.

Area typeType 3 (inter-area)Type 5 (external)Type 4Default routeCan hold ASBR?
StandardYesYesYesYes
StubYesBlockedBlockedABR injects defaultNo
Totally stubbyBlockedBlockedBlockedABR injects defaultNo
NSSAYesBlocked (uses Type 7)BlockedOptionalYes (via Type 7)
Totally NSSABlockedBlocked (uses Type 7)BlockedABR injects defaultYes (via Type 7)

Redistribution and external routes: E1 vs E2

When a route is redistributed into OSPF at an ASBR, it becomes an external route with one of two metric types:

E2 (default)E1
Metric seen by remote routersOnly the external metric (fixed, set at the ASBR)External + internal cost to reach the ASBR
Changes across the domain?No — same everywhereYes — grows with distance to the ASBR
Best forSingle exit / don't care about internal costMultiple ASBRs — picks the closest exit

Convergence, resilience, and authentication

OSPFv3 differences in depth

Likely follow-up questions

Related: TCP — Theory & Mechanisms · Life of a Packet.