< Home

Setting a Link Cost for an OSPF Interface

Context

You can manually set a link cost for an OSPF interface or allow OSPF to automatically calculate the cost according to the interface bandwidth. The calculation formula is as follows:

Cost of an interface = Bandwidth reference value/Interface bandwidth.

The integer of the calculated result is used as 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. To manually set the link cost or change the bandwidth reference value and interface bandwidth, perform the following steps.

Procedure

  • Set a link cost for an OSPF interface.
    1. Run system-view

      The system view is displayed.

    2. Run interface interface-type interface-number

      The OSPF interface view is displayed.

    3. (Optional) On an Ethernet interface, run undo portswitch

      The interface is switched to Layer 3 mode.

      By default, an Ethernet interface works in Layer 2 mode.

      Only the S5720-EI, S5720-HI, S5730-HI, S5731-H, S5731-S, S5731S-H, S5731S-S, S5732-H, S6720-EI, S6720-HI, S6720S-EI, S6730-H, S6730S-H, S6730-S, and S6730S-S support switching between Layer 2 and Layer 3 modes.

    4. Run ospf cost cost

      A cost is set for the OSPF interface.

      By default, OSPF automatically calculates its cost based on its interface bandwidth. The default cost of a loopback interface is 0.

  • Configure bandwidth-based automatic OSPF interface cost calculation.

    The calculation formula is as follows: Cost of the interface = Bandwidth reference value/Interface bandwidth. The integer of the calculation result is used as the cost of the interface. If the result is less than 1, the cost is 1.

    • To use the bandwidth reference value to determine the interface cost, run the bandwidth-reference command.

    • To use the interface bandwidth to determine the interface cost, run the bandwidth command to set configuration bandwidth for an interface, and then run the bandwidth-config enable command to enable the device to calculate the cost for the interface based on the configuration bandwidth of the interface.

    • To use both the bandwidth reference value and interface bandwidth to determine the interface cost, select the preceding configuration.

    1. Run system-view

      The system view is displayed.

    2. Run interface interface-type interface-number

      The OSPF interface view is displayed.

    3. (Option) Run bandwidth bandwidth

      Configuration bandwidth is set for the interface.

      By default, if no configuration bandwidth is set for an interface, the OSPF interface cost is calculated based on the physical bandwidth of the interface.

    4. Run quit

      Exit from the interface view.

    5. Run ospf [ process-id ]

      The OSPF process view is displayed.

    6. (Option) Run bandwidth-reference value

      A bandwidth reference value is set.

      TThe default bandwidth reference value is 100 Mbit/s.

      Ensure that the bandwidth reference values of switches in an OSPF process are the same.

    7. (Option) Run bandwidth-config enable

      The device is enabled to use the configuration bandwidth of each OSPF interface to calculate the cost for the interface.

      By default, a device is not enabled to calculate the cost of an OSPF interface based on the configured interface bandwidth.

Copyright © Huawei Technologies Co., Ltd.
Copyright © Huawei Technologies Co., Ltd.
Next topic >