Skip to main content
RunBook Academy

OPNsenseXXX · Dynamic RoutingOSPF concepts

OSPF concepts — areas, LSAs, neighbours, and the shortest-path tree

Intermediate⏱ ~14 minvtyshtcpdumpnetstat

What you'll learn

  • Explain what OSPF is and the link-state paradigm it implements
  • Describe the OSPF area hierarchy and the role of the backbone area
  • Identify the LSA types (router, network, summary, external) and their function
  • Describe neighbour adjacency, the hello/dead timers, and the DR/BDR election
  • Recognise the SPF algorithm and the cost metric that drives path selection
  • Identify the failure modes OSPF introduces that static routing does not

Prerequisites

Verified against OPNsense 25.x · FreeBSD 14.x · PF (FreeBSD packet filter) FreeBSD 14.x · Unbound 1.20+ · Kea DHCP OPNsense 25.x plugin · WireGuard in-kernel + OPNsense plugin · strongSwan (IPsec plugin) OPNsense 25.x plugin · OpenVPN 2.6.x · Suricata 7.x · 2026-08-14

Not yet marked complete on this device.

OSPF is the interior gateway protocol most production networks reach for first. It is a link-state protocol, which means every router in an area builds the same map of the topology and runs the same shortest-path algorithm against it. The result is fast convergence, loop-free paths, and a routing table that the operator can reason about. The cost is the protocol’s surface area: areas, LSA types, neighbour states, DR/BDR election, timers, and a routing algorithm whose behaviour the operator must understand well enough to debug.

This lesson covers what OSPF is, how it builds the link-state database, the role of areas in scaling OSPF, the LSA types the operator must recognise, the neighbour adjacency and DR/BDR election on broadcast segments, and the SPF algorithm that produces the routing table.

What OSPF is

OSPF (Open Shortest Path First) is a link-state interior gateway protocol standardised in RFC 2328 (for IPv4) and RFC 5340 (for OSPFv3 / IPv6). The protocol’s distinguishing feature is the link-state database (LSDB): every router in an OSPF area maintains an identical database describing the topology, and every router runs the same algorithm (Dijkstra’s shortest-path-first) against that database to produce its routing table.

The trade-off vs distance-vector protocols (RIP, BGP-path-vector is a different beast):

PropertyDistance-vectorLink-state
What routers exchange“I know a route to X via Y”“My links are L1, L2, L3 with costs C1, C2, C3”
Topology knowledgeRoutes, not topologyFull topology within the area
ConvergenceSlow (Bellman-Ford can take minutes)Fast (seconds)
CPU per routerLowHigher (Dijkstra on every change)
Memory per routerLowerHigher (full LSDB)
Loop-free pathsEventually, after the protocol convergesYes, by construction
ScalingLimited by route count and convergence timeScales via area hierarchy

OSPF chooses the link-state model because production networks need fast convergence and loop-free paths. The cost — CPU and memory for the LSDB and SPF — is acceptable on modern hardware.

Areas and the backbone

OSPF scales through a two-level hierarchy: areas and the backbone (area 0). Every OSPF network has exactly one backbone area (area 0, written 0.0.0.0 in OSPF notation). Every other area must connect to the backbone — either directly, or through a virtual link if the topology requires it.

                       +----------+
                       | Area 0   |
                       | backbone |
                       +----+-----+
                            |
              +-------------+-------------+
              |                           |
        +-----+------+              +-----+------+
        |  Area 1    |              |  Area 2    |
        |  site A    |              |  site B    |
        +------------+              +------------+

The areas exist for two reasons:

  1. Limit the LSDB size. Every router in an area has the full LSDB for that area. A network with 1000 routers in one area has a 1000-router LSDB; a network with 10 areas of 100 routers each has 10 LSDBs of 100 routers each. The CPU and memory cost is per-router-per-area, not per-router-per-network.
  2. Limit the SPF computation. When the topology changes, every router in the area runs SPF. With areas, a change in area 1 only triggers SPF in area 1; routers in area 2 are unaffected. The CPU cost is bounded by area size.

The trade-off: routers in different areas do not see each other’s full topology. They see only summary routes injected by the area border routers (ABRs). The summary is less precise than the full topology, but it is enough for inter-area forwarding.

LSA types

OSPF describes the topology with Link-State Advertisements (LSAs). The LSA types the operator must recognise:

TypeNameCarriesFlooded within
1Router LSAA router’s links and their costsThe area
2Network LSAThe routers attached to a broadcast/NBMA segmentThe area
3Summary LSAAn inter-area route (an ABR injecting from another area)The area
4ASBR Summary LSAHow to reach an AS boundary routerThe area
5AS External LSAA route external to the OSPF AS (redistributed from another protocol)The entire AS (subject to areas)
7NSSA External LSAAn external route originated within a not-so-stubby areaTranslated to type 5 at the ABR

The operator who runs OSPF must be able to look at the LSDB and identify which LSA types are present. A type 1 or 2 LSA is intra-area; a type 3 is inter-area; a type 5 is external. A network that suddenly shows type 5 LSAs it did not have yesterday has had a new route redistributed into OSPF — possibly by accident.

Neighbour adjacency and DR/BDR

OSPF routers do not talk to every other router on a segment; they talk to a designated router (DR) and a backup designated router (BDR). The DR is elected from the routers on a broadcast or NBMA segment; the BDR is the runner-up. Every other router on the segment forms an adjacency only with the DR and BDR, not with each other.

The election is based on the OSPF priority (configurable, default 1) and the router ID (a 32-bit identifier, defaulting to the highest IP on a loopback). Higher priority wins; if priorities tie, higher router ID wins. A router with priority 0 is ineligible to be DR — useful for routers that should never be DR (a small firewall that should not bear the DR load).

The reason for DR/BDR: on a broadcast segment with N routers, the naive approach produces N*(N-1)/2 adjacencies and floods every LSA N times. With DR/BDR, every router forms one adjacency (with the DR), and the DR floods one LSA per change to all routers on the segment. The scaling is O(N) instead of O(N²).

Read-only / SafeOSPF neighbour state
ospf-node# vtysh -c 'show ip ospf neighbor'
Neighbor ID     Pri   State         Dead Time   Address         Interface
10.0.0.2        1     Full/DR       00:00:38    10.0.0.2        igb1:10.0.0.1
10.0.0.3        1     Full/Backup   00:00:39    10.0.0.3        igb1:10.0.0.1
10.0.0.4        1     2-Way/DROther 00:00:37   10.0.0.4        igb1:10.0.0.1

Illustrative output

On point-to-point links (PPP, a /30 between two routers), there is no DR/BDR election — the segment type is point-to-point and the two routers form a full adjacency with each other.

Hello and dead timers

OSPF neighbours send hello packets every Hello interval (default 10 seconds on broadcast segments, 30 on point-to-point). A neighbour is considered down after the Dead interval (default 4 × Hello, so 40 seconds on broadcast). The hello packet carries the router ID, the area ID, the authentication, the hello/dead intervals, and a list of neighbours the sender has heard from recently. Two OSPF routers only become neighbours if they agree on the area, the hello/dead intervals, the authentication, and the network mask.

A common production failure: one router’s hello interval is 10 seconds and the other’s is 30. The hellos never match; the adjacency never forms. The error message is “neighbour not coming up” and the fix is making the timers match.

The SPF algorithm and cost

Once the LSDB is consistent, every router runs Dijkstra’s shortest-path-first (SPF) algorithm against it. The result is a tree rooted at the router, with the cheapest-cost path to every destination. The cost metric is configurable per-interface (the ip ospf cost in Cisco terminology; in FRR it is ip ospf cost or bandwidth-derived). The default reference bandwidth is 100 Mbps; the cost of a 100 Mbps link is 1, the cost of a 1 Gbps link is 1 (capped at the reference), the cost of a 10 Gbps link is 1. The operator who wants cost to differentiate between link speeds must raise the reference bandwidth.

The SPF run is CPU-intensive. A network with 1000 LSAs in the area runs Dijkstra against 1000 nodes on every change; a flapping link produces constant SPF runs. The operator tunes SPF throttling (timers throttle spf in FRR) to bound the CPU impact.

Summary

  • OSPF is a link-state interior gateway protocol with fast convergence and loop-free paths by construction.
  • Areas limit the LSDB size and SPF cost; the backbone (area 0) connects all other areas.
  • The LSA types (1, 2, 3, 4, 5, 7) describe different parts of the topology; the operator must recognise which type is which.
  • DR/BDR on broadcast segments reduces the adjacency count from O(N²) to O(N); point-to-point links have no DR/BDR.
  • Hello and dead timers must match on both ends of an adjacency; a mismatch produces a silent failure.
  • SPF runs Dijkstra against the LSDB; the cost metric drives path selection.

Knowledge check · 4 questions

  1. Q1. A network has 200 routers in a single OSPF area. The operator is considering splitting into 4 areas of 50 routers each. What is the main benefit?

  2. Q2. OSPF should be used to peer with a public ISP because OSPF is the standard interior gateway protocol.

  3. Q3. Which OSPF LSA types describe intra-area topology (within a single area)? Select all that apply.

  4. Q4. A new OSPF router is configured but show ip ospf neighbor on the existing router shows the new router stuck in "Down" or "Init". The hello and dead timers appear to be set the same on both sides. What is the most likely cause?

Passing score: 75%. Answers are checked in this browser.