OSPF uses “Cost” as the value of the OSPF metric and uses a Reference Bandwidth of 100 Mbps for cost calculation. A lower-cost indicates a better path than a higher cost. A routing protocol uses a metric to determine the best path of a packet across a network. An OSPF metric provides a sign of the overhead across a certain interface for packet sending.
The cost of an interface is inversely proportional to the bandwidth of the interface. So, a higher bandwidth provides a lower cost and more overhead and time delays equal a higher cost. Therefore, a 100-Mb/s Ethernet line has a higher cost than a 1000-Mb/s Ethernet line. The image below illustrates the formula for cost calculation
The value of the reference cost is 100Mbps = 100,000,000 bps, So the formula:
The default OSPF cost formula doesn’t differentiate between interfaces with bandwidth faster than 100 Mbps. The FastEthernet, Gigabit Ethernet, and 10 GigE interfaces share the same cost because the OSPF cost value must be an integer. Therefore, the default reference bandwidth is set to 100 Mb/s, and all links that are faster than Fast Ethernet also have a cost of 1. The cost value for different types of interfaces are the following:
OSPF Accumulates Costs
The cost of an OSPF route is the accumulated value from the source to the destination network. For example, in Figure 2, there are two routes from Router1 LAN to Router2 LAN. The cost to reach the Router2 LAN from Router1 LAN as follows:
- Router1 Fast Ethernet 0/0 = 1
- Router2 Ethernet = 10
- The total cost to reach 192.168.20.0=11
- Router1 Giga Ethernet 0/1 = 1
- Router3 Serial 1/1/0 = 781
- Router2 Ethernet = 10
Total cost to reach 192.168.20.0= 792
The routing table of Router1 for network 192.168.20.0 in Figure 3 confirms the OSPF metric to reach the Router2 LAN is a cost of 11.
Adjusting the Reference Bandwidth
OSPF uses 100 Mbps bandwidth for reference of any links that are equal to or faster than a fast Ethernet connection. Therefore, the cost assigned to a fast Ethernet with reference; bandwidth of 100Mbps would equal to 1.
This calculation works for fast Ethernet interfaces, So links faster than 100 Mb/s calculation is not easy because the OSPF metric only uses integers as its final cost of a link. If the calculation is less than an integer, OSPF protocol rounds up the value to the closest integer.
So, from the OSPF point of view, an interface with an interface bandwidth of 100 Mb/s, has the same cost as an interface with a bandwidth of 1Gbps, 10Gbps and 100 Gbps. So, for making the best path determination the reference; bandwidth must be modified to a higher value than 100Mbps to accommodate faster links than 100Mbps.
Changing the Reference Bandwidth
Changing the reference bandwidth does not affect the actual bandwidth capacity on the link. It simply affects the OSPF metric calculation. We can change the reference; bandwidth with router configuration mode <auto-cost reference-bandwidth Mbps>.
The configuration must be same on every router in the OSPF domain. The value is in Mbps, so, to adjust the costs for GigaEthernet the command would <auto-cost reference-bandwidth 1000> and for 10 Gigabit Ethernet <auto-cost reference-bandwidth 10000>.
To cancel the default reference bandwidth, use the command <auto-cost reference-bandwidth 100> in router configuration mode. The table in Figure-1 illustrates the OSPF cost if the reference; bandwidth is set to Gigabit Ethernet (1000) and the table in figure-2 illustrates the OSPF cost if the reference; bandwidth is set to 10 Gigabit Ethernet links. In table-1 the OSPF make better choices because it can now differentiate between FastEthernet and Giga Ethernet links. In Table-2 it is also differentiated between 100Mbps, 1G and 10G links.