What is SPF?
Shortest Path First
SPF (Shortest Path First) is Dijkstra's algorithm as used by link-state routing protocols to find the lowest-cost path from a router to every destination.
In OSPF and IS-IS every router in an area holds the same LSDB, a complete map of routers, links and their costs. Each router runs SPF with itself as the root:
- Start with only itself in the tree, at cost 0.
- Look at every neighbour reachable from the routers already in the tree and work out its total cost from the root.
- Add the cheapest candidate to the tree, then repeat from step 2.
- Stop when every router is in the tree; prefixes attached to each router inherit its path.
The result is a shortest-path tree, from which the router takes the next hop for each destination. If two paths have the same total cost, both are kept and traffic is shared across them with ECMP. In OSPF a link's cost is commonly derived from a reference bandwidth divided by the interface bandwidth, and costs only count in the outgoing direction.
Because every router calculates its own tree from the same data, they agree on paths without any of them telling the others what to do, which is what makes link-state protocols loop-free once they have converged. When anything changes, the new LSAs are flooded and routers rerun SPF, so implementations add throttle timers to avoid recalculating dozens of times during a burst of changes. A frequent confusion is assuming the default costs suit modern links: with a 100 Mbps reference bandwidth, 1 Gbps and 10 Gbps interfaces get the same cost, so many networks raise the reference or set costs by hand. Note too that the name has nothing to do with the email SPF record. The OSPF Fundamentals lesson shows SPF working on a real topology, and OSPF on VyOS steers traffic by changing costs.
Lessons that use SPF
- OSPF FundamentalsTeaches this term · Beginner · 70 min
The link-state IGP that runs inside most networks: neighbour adjacencies, LSA flooding, SPF, costs, DR/BDR, areas and LSA types, a hands-on FRR lab, and how OSPF underpins BGP.