OSPF Metric
๐ OSPF Cost โ Complete Technical Guide for Interview & Learning
Purpose: This guide is designed for learners, professionals, and interviewers who want a complete and technical understanding of how OSPF (Open Shortest Path First) uses Cost as its routing metric. It includes all important concepts, formulas, configurations, and commands in a structured format for learning, revision, and reference.
๐ง 1. What is OSPF Cost?
Definition: OSPF Cost is the metric used by OSPF to determine the best (shortest) path to a destination network. Lower cost = preferred path.
Key Points:
Every OSPF-enabled interface has an associated cost.
OSPF uses cumulative cost: the total cost of all outgoing interfaces in a path.
Cost and Metric are used interchangeably (Cost is more commonly used in OSPF).
Example: If a path traverses three links with costs 1, 1, and 2, the total OSPF cost = 1 + 1 + 2 = 4.
๐ก 2. How OSPF Cost is Calculated
Formula:
1
OSPF Cost = Reference Bandwidth / Interface Bandwidth
๐ข Default Reference Bandwidth: 100 Mbps(100,000,000 bps)
| Interface Bandwidth | OSPF Cost (Default) |
|---|---|
| 10 Mbps | 100 / 10 = 10 |
| 100 Mbps | 100 / 100 = 1 |
| 1 Gbps | 100 / 1000 = 0.1 โ Rounded up to 1 |
| 10 Gbps | 100 / 10000 = 0.01 โ Rounded up to 1 |
โ ๏ธ Important: OSPF cost values are always integers. Any value < 1 is rounded up to 1.
โ ๏ธ 3. Suboptimal Routing with Default Costs
With the default 100 Mbps reference bandwidth:
1 Gbps and 10 Gbps links get same cost as 100 Mbps: 1
Leads to suboptimal path selection in modern networks
Equal-Cost Multi-Path (ECMP) issues: OSPF may balance across unequal links
๐ ECMP Behavior:
OSPF supports up to 4 equal-cost paths by default
If unequal links have the same OSPF cost (e.g., 100 Mbps and 10 Gbps), traffic is unevenly balanced.
๐ ๏ธ 4. Manipulating OSPF Cost (Traffic Engineering Techniques)
๐ง Method 1: Change Reference Bandwidth (Recommended)
Use this to make OSPF cost calculations more accurate for high-speed links.
1
R1(config-router)# auto-cost reference-bandwidth 10000
This sets the reference bandwidth to 10 Gbps.
Best Practice:
Set same reference bandwidth on all routers in the OSPF domain
Choose a value equal to or greater than the fastest link
โ๏ธ Method 2: Manually Set OSPF Cost on Interface
Override cost calculation manually.
Command:
1
R1(config-if)# ip ospf cost 50
Use this when:
You want to influence OSPF route selection manually
Link speed does not reflect actual link desirability
๐งฎ Method 3: Change Interface Bandwidth Value
Affects the cost indirectly via the formula.
Command:
1
R1(config-if)# bandwidth 100000
Note:
Bandwidth is set in Kbps
Changing bandwidth affects QoS and other features
Does not change actual physical speed
๐ 5. Viewing OSPF Cost โ Key Show Commands
| Command | Purpose |
|---|---|
show ip ospf interface brief | Quick overview: interface cost, state, area, neighbor count |
show ip ospf interface [type/number] | Detailed interface OSPF data, including exact cost |
show ip ospf database router [router-id] | Displays LSA Type 1 data and associated metrics in the LSDB |
๐งฌ 6. Advanced: OSPF Two-Part Metric (RFC 8042)
What: OSPF extension allowing a two-part metric in special environments
Structure:
Router-to-Network Cost (outbound)
Network-to-Router Cost (inbound)
Use Case:
Helps in multi-access/broadcast environments (e.g., satellite links)
Reduces LSA update frequency
Advertised via Extended Link TLVs with Sub-TLVs in OSPFv2
Implementation Requirement:
- All routers in the area must support this extension
๐ Summary & Key Takeaways
| Concept | Description |
|---|---|
| OSPF Cost | Metric for selecting shortest path (lower = better) |
| Default Formula | Reference Bandwidth (100 Mbps) / Interface Bandwidth |
| Default Limitation | Fails to differentiate between fast links (โฅ 100 Mbps) |
| Traffic Engineering | Use methods like changing reference bandwidth, manual cost setting, or bandwidth adjustment |
| Advanced Topics | Two-part metrics for complex environments |
| Show Commands | Essential for troubleshooting and verification |
๐ฏ Pro Interview/Revision Tips
โ Memorize the default formula and common OSPF costs
โ Understand why and how to manipulate OSPF costs
โ Be ready to explain ECMP behavior and its drawbacks
โ Know commands to verify and troubleshoot OSPF cost
โ Stay updated on advanced OSPF enhancements like RFC 8042
๐งฉ Understanding OSPF Cost is critical for designing efficient networks and performing accurate traffic engineering. Misconfigured costs can lead to routing loops, suboptimal paths, and poor bandwidth utilization.