In the following sections, you will learn about the OSPF metric and how it is calculated.
Calculating the OSPF Metric
The OSPF metric is commonly referred to as the cost. The cost is derived from the bandwidth of a link using the formula 108 / bandwidth (in bps). This means that different links are assigned different cost values, depending on their bandwidth. Using this formula, the OSPF cost of a 10Mbps Ethernet interface would be calculated as follows:
- Cost = 108 / bandwidth (bps)
- Cost = 100 000 000 / 10 000 000
- Cost = 10
Using the same formula, the OSPF cost of a T1 link would be calculated as follows:
- Cost = 108 / bandwidth (bps)
- Cost = 100 000 000 / 1 544 000
- Cost = 64.77
NOTE: When calculating the OSPF metric, point math is not used. Therefore, any such values are always rounded down to the nearest integer. Regarding the previous example, the actual cost for a T1 link would be rounded down to 64.
The OSPF cost of an interface can be viewed using the show ip ospf interface [name] command, as was illustrated previously. The default reference bandwidth used in metric calculation can be viewed in the output of the show ip protocols command, as is illustrated in the following output:
| R4#show ip protocolsRouting Protocol is “ospf 4″Outgoing update filter list for all interfaces is not setIncoming update filter list for all interfaces is not set
Router ID 4.4.4.4 Number of areas in this router is 1. 1 normal 0 stub 0 nssa Maximum path: 4 Routing for Networks: 0.0.0.0 255.255.255.255 Area 2 Reference bandwidth unit is 100 mbps Routing Information Sources: Gateway Distance Last Update 3.3.3.3 110 00:00:03 Distance: (default is 110) |
The default reference bandwidth used in OSPF cost calculation can be adjusted using the auto-cost reference-bandwidth <1-4294967> router configuration command and specifying the reference bandwidth value in Mbps. This is particularly important in networks that have links that have a bandwidth value over 100Mbps, for example, GigabitEthernet links. In such networks, the default value assigned to the GigabitEthernet link would be the same as that of a FastEthernet link. In most cases, this is certainly not desirable, especially if OSPF attempts to load balance across both links.
To prevent this skewed calculation of cost value, the auto-cost reference-bandwidth 1000 router configuration command should be issued on the router. This results in a recalculation of cost values on the router using the new reference bandwidth value. For example, following this configuration, the cost of a T1 link would be recalculated as follows:
- Cost = 109 / bandwidth (bps)
- Cost = 1 000 000 000 / 1 544 000
- Cost = 647.66
NOTE: Again, because the OSPF metric does not support point values, this would be rounded down to a metric value of simply 647, as illustrated in the following output:
|
R4#show ip ospf interface Serial0/0 Serial0/0 is up, line protocol is up Internet Address 10.0.2.4/24, Area 2 Process ID 4, Router ID 4.4.4.4, Network Type POINT_TO_POINT, Cost: 647 Transmit Delay is 1 sec, State POINT_TO_POINT Timer intervals configured, Hello 10, Dead 60, Wait 60, Retransmit 5 oob-resync timeout 60 Hello due in 00:00:01 Supports Link-local Signaling (LLS) Index 2/2, flood queue length 0 Next 0x0(0)/0x0(0) Last flood scan length is 1, maximum is 1 Last flood scan time is 0 msec, maximum is 0 msec Neighbor Count is 0, Adjacent neighbor count is 0 Suppress Hello for 0 neighbor(s) |
When the auto-cost reference-bandwidth 1000 router configuration command is issued, Cisco IOS software prints the following message indicating that this same value should be applied to all routers within the OSPF domain. This is illustrated in the following output:
| R4(config)#router ospf 4R4(config-router)#auto-cost reference-bandwidth 1000% OSPF: Reference bandwidth is changed.Please ensure reference bandwidth is consistent across all routers. |
While this may seem like an important warning, keep in mind that the use of this command simply affects the local router. It is not mandatory to configure it on all routers; however, for exam purposes, ensure that a consistent configuration is implemented on all routers.
Influencing OSPF Metric Calculation
The calculation of the OSPF metric can be directly influenced by performing the following:
- Adjusting the interface bandwidth using the bandwidth command
- Manually specifying a cost using the ip ospf cost command
The use of the bandwidth command was described in a previous module when we discussed EIGRP metric calculation. As stated earlier, the default OSPF cost is calculated by dividing the link bandwidth by a reference bandwidth of 108, or 100 Mbps. Either incrementing or decrementing the link bandwidth directly affects the OSPF cost for the particular link. This is typically a path control mechanism used to ensure that one path is preferred over another.
However, as was described in the previous module, the bandwidth command affects more than just the routing protocol. It is for this reason that the second method, manually specifying a cost value, is the recommended method for influencing OSPF metric calculation.
The ip ospf cost <1-65535> interface configuration command is used to manually specify the cost of a link. The lower the value, the greater the probability that the link will be preferred over other links to the same destination network but with higher cost values. The following example illustrates how to configure an OSPF cost of 5 for a Serial (T1) link:
| R1(config)#interface Serial0/0R1(config-if)#ip ospf cost 5R1(config-if)#exit |
This configuration can be validated using the show ip ospf interface [name] command, as illustrated in the following output:
|
R1#show ip ospf interface Serial0/0 Serial0/0 is up, line protocol is up Internet Address 10.0.0.1/24, Area 0 Process ID 1, Router ID 1.1.1.1, Network Type POINT_TO_POINT, Cost: 5 Transmit Delay is 1 sec, State POINT_TO_POINT, Timer intervals configured, Hello 10, Dead 40, Wait 40, Retransmit 5 oob-resync timeout 40 Hello due in 00:00:04 Index 2/2, flood queue length 0 Next 0x0(0)/0x0(0) Last flood scan length is 1, maximum is 4 Last flood scan time is 0 msec, maximum is 0 msec Neighbor Count is 1, Adjacent neighbor count is 1 Adjacent with neighbor 2.2.2.2 Suppress Hello for 0 neighbor(s) |