# How is the cost of an OSPF interface calculated

42

The principles of calculating the cost of an OSPF interface are as follows: The cost configured on the interface is preferred. If no cost is configured on the interface, the formula for calculating the cost of the interface is as follows: Cost = Reference bandwidth/Interface bandwidth. The default reference bandwidth of OSPF is 100 Mbit/s.

For example, the cost of a 10 Mbit/s Ethernet interface = 100 Mbits per second/10 Mbits per second = 10. If the calculation result is smaller than 1, the cost is set to 1. For example, the cost of a GE interface is 100 Mbits per second/1000 Mbits per second = 0.1, which is less than 1. Therefore, the cost of this interface is 1.

The default cost on the loopback interface, which is a virtual interface, is 0.

###### Other related questions:
Calculating the cost of an OSPF interface on the firewall
Calculating the cost of an OSPF interface on the USG2000&5000&6000 series as follows: The cost configured on the interface is preferred. If no cost is configured on the interface, the formula for calculating the cost of the interface is as follows: Cost = Reference bandwidth/Interface bandwidth. The default reference bandwidth of OSPF is 100 Mbit/s. For example, the cost of a 10 Mbit/s Ethernet interface = 100 Mbits per second/10 Mbits per second = 10. If the calculation result is smaller than 1, the cost is set to 1. For example, the cost of a GE interface is 100 Mbits per second/1000 Mbits per second = 0.1, which is less than 1. Therefore, the cost of this interface is 1. The default cost on the loopback interface, which is a virtual interface, is 0.

The USG configures the OSPF link cost method
The USG2000 & 5000 & 6000 configures the OSPF link cost as follows: 1. Run: system-view The system view is displayed. 2. Run: interface interface-type interface-number The interface view is displayed. 3. Run the ospf cost cost command to set the cost of the OSPF interface. The OSPF protocol cost of the interface is valid for the OSPF route learned from the interface. That is, the cost of the route generated in the device routing table is equal to the cost of the route advertised by the interface. The cost of the interface is set by the ospf cost command.

Why is the OSPF default cost incorrect
For example, after the OSPF process is enabled on the device, the information about the interface is displayed. The output information shows that the default OSPF cost of an Ethernet interface is 7. Generally, the default OSPF cost is 1. The default cost of an OSPF interface is calculated based on the bandwidth and bandwidth-reference. Bandwidth-reference is configured under the OSPF process. Normally, the default bandwidth-reference value is used. If the default bandwidth is 100 Mbit/s, the OSPF cost is calculated as 1.

OSPF cost of S series switches
The ospf cost command can be executed on an S series switch that supports OSPF to configure the cost required for running the OSPF protocol on an interface. Application scenario: The interface cost can be automatically calculated by OSPF based on the interface bandwidth or manually configured by using the ospf cost command. If the costs and destination IP addresses of multiple routes discovered by one routing protocol are the same, load balancing can be implemented among the routes. Modify interface costs to implement load balancing as required. Configuration impact: If no interface cost is configured by using the ospf cost command, OSPF automatically calculates the interface cost based on the interface bandwidth. The calculation formula is as follows: Cost of the interface = Bandwidth reference value/Interface bandwidth. The integer of the calculated result is the cost of the interface. If the calculated result is smaller than 1, the cost value is 1. Changing the bandwidth reference value can change the cost of an interface. By default, the bandwidth reference value is 100 Mbit/s. Therefore, the default cost value of an Ethernet (100 Mbit/s) interface is 1 (100,000,000/the interface bandwidth). Example: Set the cost required by VLANIF 100 for running OSPF to 65. [HUAWEI] interface vlanif 100 [HUAWEI-Vlanif100] ospf cost 65 Set the cost required by GE0/0/1 for running OSPF to 65. [HUAWEI] interface gigabitethernet 0/0/1 [HUAWEI-GigabitEthernet0/0/1] undo portswitch [HUAWEI-GigabitEthernet0/0/1] ospf cost 65 Note: The cost calculated by OSPF is the cost of the route to the outbound interface of the destination network.

Why is the default OSPF cost of an interface on an S series switch incorrect
Question: Why is default OSPF cost value incorrect? For example, after OSPF is enabled on a device, the default OSPF cost value of an Ethernet interface is 7. Generally, the default OSPF cost value of an interface is 1. Answer: The default OSPF cost value of an interface on an S series switch supporting OSPF depends on the values of bandwidth and bandwidth-reference. The value of bandwidth-reference is configured in an OSPF process. Generally, the default bandwidth-reference value is used. In this case, if the default bandwidth value is 100 Mbit/s, the OSPF cost value is 1.

###### If you have more questions, you can seek help from following ways:
To iKnow To Live Chat