TTR Networks

Beginner · OSPF Fundamentals · section 3 of 9

The LSDB and SPF

✓ Lab-tested 17 October 2026 on FRR 10.2.1

Every router in an area stores the same Link State Database (LSDB): a set of Link State Advertisements (LSAs), each originated by one router describing what it is connected to. Each LSA has a sequence number and an age, so routers always know which copy is newest. Routers refresh their own LSAs every 30 minutes and an LSA that reaches 60 minutes old is flushed.

From the LSDB, each router runs Dijkstra's shortest path first algorithm with itself as the root:

  1. Put yourself in the tree at cost 0.
  2. Look at the links of the node you just added. For every neighbour not yet in the tree, record a candidate cost = (cost to that node) + (link cost). Keep only the lowest candidate per neighbour — and keep all of them if they tie.
  3. Move the cheapest candidate into the tree.
  4. Repeat until there are no candidates left.

The result is a shortest-path tree rooted at this router. The routing table falls out of it: for each destination, the next hop is whichever directly connected neighbour the tree's branch starts with.

Try it below:

  • Step through from R1. Notice R2 is reached through R3 (5 + 3 = 8), not directly (10) — OSPF counts cost, not hops.
  • Change the R2—R3 cost to 5. Now R2 is 10 both ways: OSPF installs both next hops (ECMP), and R4 and R5 inherit both.
  • Set R4—R5 to 0 (link down) and watch R5 become unreachable.
  • Click R5 to run SPF from its point of view — same database, different tree.

Interactive: SPF simulator Five routers in one area. Edit costs, pick the root router, and step through Dijkstra one iteration at a time. Green links form the shortest-path tree; amber nodes are candidates. (needs JavaScript)

Check your understanding

Why can't a persistent routing loop form inside a converged OSPF area?

  • OSPF adds each router's ID to the route, like AS_PATH, and rejects loops
  • Every router computes shortest paths from the same database, so their trees agree
  • The DR checks every route for loops before flooding it
  • TTL expiry prevents them