Post

OSPF Metric

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 BandwidthOSPF Cost (Default)
10 Mbps100 / 10 = 10
100 Mbps100 / 100 = 1
1 Gbps100 / 1000 = 0.1 โ†’ Rounded up to 1
10 Gbps100 / 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)

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

CommandPurpose
show ip ospf interface briefQuick 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:

  1. Router-to-Network Cost (outbound)

  2. 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

ConceptDescription
OSPF CostMetric for selecting shortest path (lower = better)
Default FormulaReference Bandwidth (100 Mbps) / Interface Bandwidth
Default LimitationFails to differentiate between fast links (โ‰ฅ 100 Mbps)
Traffic EngineeringUse methods like changing reference bandwidth, manual cost setting, or bandwidth adjustment
Advanced TopicsTwo-part metrics for complex environments
Show CommandsEssential 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.

๐Ÿ™Œ Connect With Me

GitHub LinkedIn YouTube Gmail

This post is licensed under CC BY 4.0 by the author.