04 · cost and spf
OSPF Cost and Route Selection Visualization
R1 reaches 10.5.5.0/24 behind R5 either directly over R2 in two hops or the long way through R3 and R4 in three. Cost is reference bandwidth divided by interface bandwidth, not hop count, so set the interface speeds and the reference bandwidth to see which path wins, when two paths tie for equal-cost multipath, and how route source outranks metric.
- installed shortest path
- in the database, not used
Best cost
4
Equal-cost paths
1
Reference bw
100 Mb
Candidates seen
4
Candidate paths, cheapest first
OSPF sees all of them in the database and installs only the minimum.
| Path | Links | Per-hop cost | Total | |
|---|---|---|---|---|
| R1 → R3 → R4 → R5 → 10.5.5.0/24 | C D E LAN | 1 + 1 + 1 + 1 | 4 | installed |
| R1 → R3 → R4 → R2 → R5 → 10.5.5.0/24 | C D F B LAN | 1 + 1 + 10 + 1 + 1 | 14 | 10 worse |
| R1 → R2 → R5 → 10.5.5.0/24 | A B LAN | 64 + 1 + 1 | 66 | 62 worse |
| R1 → R2 → R4 → R5 → 10.5.5.0/24 | A F E LAN | 64 + 10 + 1 + 1 | 76 | 72 worse |
Slide sideways to see the whole table.
Cost per interface speed
Truncated, never below 1.
| Interface | ref 100 | ref 1000 | ref 10000 | ref 100000 |
|---|---|---|---|---|
| Serial T1 | 64 | 647 | 6476 | 64766 |
| 10 Mb | 10 | 100 | 1000 | 10000 |
| 100 Mb | 1 | 10 | 100 | 1000 |
| 1 Gb | 1 | 1 | 10 | 100 |
| 10 Gb | 1 | 1 | 1 | 10 |
Slide sideways to see the whole table.
R1(config)# router ospf 1 R1(config-ospf-1)# auto-cost reference-bandwidth 100 R1(config-ospf-1)# maximum-paths 4 R1(config)# interface 1/1/2 R1(config-if)# ip ospf 1 area 0 R1(config-if)# ip ospf cost 40 ! overrides the formula entirely R1# show ip ospf routes
Route source beats metric, always
OSPF compares these ranks before it ever looks at cost.
| Rank | Code | Source | Note |
|---|---|---|---|
| 1 | O | Intra-area | Learned from type 1 and 2 inside our own area. |
| 2 | O IA | Inter-area | Learned from a type 3 summary at an ABR. |
| 3 | O E1 | External type 1 | External metric plus the internal cost to the ASBR. |
| 4 | O E2 | External type 2 | External metric only; internal cost ignored. |
Slide sideways to see the whole table.
An intra-area route with cost 900 is preferred over an inter-area route with cost 3 for the same prefix. Longest prefix match still comes first: a /24 always beats a /16, whatever the code.
Three demonstrations worth doing live
Key point
Speed does not equal preference. Leave the defaults: A+B is two hops but costs 65, while C+D+E is three hops and costs 4. A hop-count protocol would have chosen the slower path.
Make a tie. Set A to 1 Gb and B to 1 Gb; both paths reach cost 3 and OSPF installs both. Point out maximum-paths and that load sharing is per-destination by default.
Break the reference bandwidth. Change it on one router only — in a real lab you get asymmetric routing and a mismatch warning, because cost is calculated locally but every router trusts what it is told.