Help us improve your experience.

Let us know what you think.

Do you have time for a two-minute survey?

Navigation

Examples: Configuring OSPF Traffic Control

Understanding OSPF Traffic Control

Once a topology is shared across the network, OSPF uses the topology to route packets between network nodes. Each path between neighbors is assigned a cost based on the throughput, round-trip time, and reliability of the link. The sum of the costs across a particular path between hosts determines the overall cost of the path. Packets are then routed along the shortest path using the shortest-path-first (SPF) algorithm. Routes with lower total path metrics are preferred over those with higher path metrics.

You can use the following methods to control OSPF traffic:

  • Control the cost of individual OSPF network segments
  • Dynamically adjust OSPF interface metrics based on bandwidth
  • Control OSPF route selection

Controlling the Cost of Individual OSPF Network Segments

OSPF uses the following formula to determine the cost of a route:

cost = reference-bandwidth / interface bandwidth

You can modify the reference-bandwidth value, which is used to calculate the default interface cost. The interface bandwidth value is not user-configurable and refers to the actual bandwidth of the physical interface.

By default, OSPF assigns a default cost metric of 1 to any link faster than 100 Mbps, and a default cost metric of 0 to the loopback interface (lo0). No bandwidth is associated with the loopback interface.

To control the flow of packets across the network, OSPF allows you to manually assign a cost (or metric) to a particular path segment. When you specify a metric for a specific OSPF interface, that value is used to determine the cost of routes advertised from that interface. For example, if all routers in the OSPF network use default metric values, and you increase the metric on one interface to 5, all paths through that interface have a calculated metric higher than the default and are not preferred.

Note: Any value you configure for the metric overrides the default behavior of using the reference-bandwidth value to calculate the route cost for that interface.

When there are multiple equal-cost routes to the same destination in a routing table, an equal-cost multipath (ECMP) set is formed. If there is an ECMP set for the active route, the Junos OS software uses a hash algorithm to choose one of the next-hop addresses in the ECMP set to install in the forwarding table.

You can configure Junos OS so that multiple next-hop entries in an ECMP set are installed in the forwarding table. Define a load-balancing routing policy by including one or more policy-statement configuration statements at the [edit policy-options] hierarchy level, with the action load-balance per-packet. Then apply the routing policy to routes exported from the routing table to the forwarding table.

Dynamically Adjusting OSPF Interface Metrics Based on Bandwidth

You can specify a set of bandwidth threshold values and associated metric values for an OSPF interface or for a topology on an OSPF interface. When the bandwidth of an interface changes, the Junos OS automatically sets the interface metric to the value associated with the appropriate bandwidth threshold value. Junos OS uses the smallest configured bandwidth threshold value that is equal to or greater than the actual interface bandwidth to determine the metric value. If the interface bandwidth is greater than any of the configured bandwidth threshold values, the metric value configured for the interface is used instead of any of the bandwidth-based metric values configured. The ability to recalculate the metric for an interface when its bandwidth changes is especially useful for aggregate interfaces.

Note: You must also configure a metric for the interface when you enable bandwidth-based metrics.

Controlling OSPF Route Preferences

You can control the flow of packets through the network using route preferences. Route preferences are used to select which route is installed in the forwarding table when several protocols calculate routes to the same destination. The route with the lowest preference value is selected.

By default, internal OSPF routes have a preference value of 10, and external OSPF routes have a preference value of 150. Although the default settings are appropriate for most environments, you might want to modify the default settings if all of the routing devices in your OSPF network use the default preference values, or if you are planning to migrate from OSPF to a different interior gateway protocol (IGP). If all of the devices use the default route preference values, you can change the route preferences to ensure that the path through a particular device is selected for the forwarding table any time multiple equal-cost paths to a destination exist. When migrating from OSPF to a different IGP, modifying the route preferences allows you to perform the migration in a controlled manner.

Example: Controlling the Cost of Individual OSPF Network Segments

This example shows how to control the cost of individual OSPF network segments.

Requirements

Before you begin:

Overview

All OSPF interfaces have a cost, which is a routing metric that is used in the link-state calculation. Routes with lower total path metrics are preferred to those with higher path metrics. In this example, we explore how to control the cost of OSPF network segments.

By default, OSPF assigns a default cost metric of 1 to any link faster than 100 Mbps, and a default cost metric of 0 to the loopback interface (lo0). No bandwidth is associated with the loopback interface. This means that all interfaces faster than 100 Mbps have the same default cost metric of 1. If multiple equal-cost paths exist between a source and destination address, OSPF routes packets along each path alternately, in round-robin fashion.

Having the same default metric might not be a problem if all of the interfaces are running at the same speed. If the interfaces operate at different speeds, you might notice that traffic is not routed over the fastest interface because OSPF equally routes packets across the different interfaces. For example, if your routing device has Fast Ethernet and Gigabit Ethernet interfaces running OSPF, each of these interfaces have a default cost metric of 1.

In the first example, you set the reference bandwidth to 10g (10 Gbps, as denoted by 10,000,000,000 bits) by including the reference-bandwidth statement. With this configuration, OSPF assigns the Fast Ethernet interface a default metric of 100, and the Gigabit Ethernet interface a metric of 10. Since the Gigabit Ethernet interface has the lowest metric, OSPF selects it when routing packets. The range is 9600 through 1,000,000,000,000 bits.

Figure 1 shows three routing devices in area 0.0.0.0 and assumes that the link between Device R2 and Device R3 is congested with other traffic. You can also control the flow of packets across the network by manually assigning a metric to a particular path segment. Any value you configure for the metric overrides the default behavior of using the reference-bandwidth value to calculate the route cost for that interface. To prevent the traffic from Device R3 going directly to Device R2, you adjust the metric on the interface on Device R3 that connects with Device R1 so that all traffic goes through Device R1.

In the second example, you set the metric to 5 on interface fe-1/0/1 on Device R3 that connects with Device R1 by including the metric statement. The range is 1 through 65,535.

Figure 1: OSPF Metric Configuration

OSPF Metric Configuration

Configuration

Configuring the Reference Bandwidth

CLI Quick Configuration

To quickly configure the reference bandwidth, copy the following command and paste it into the CLI.

[edit]set protocols ospf reference-bandwidth 10g

Step-by-Step Procedure

To configure the reference bandwidth:

  1. Configure the reference bandwidth to calculate the default interface cost.

    Note: To specify OSPFv3, include the ospf3 statement at the [edit protocols] hierarchy level.

    [edit]user@host# set protocols ospf reference-bandwidth 10g

    Tip: As a shortcut in this example, you enter 10g to specify 10 Gbps reference bandwidth. Whether you enter 10g or 10000000000, the output of show protocols ospf command displays 10 Gbps as 10g, not 10000000000.

  2. If you are done configuring the device, commit the configuration.
    [edit]user@host# commit

    Note: Repeat this entire configuration on all routing devices in a shared network.

Results

Confirm your configuration by entering the show protocols ospf command. If the output does not display the intended configuration, repeat the instructions in this example to correct the configuration.

user@host# show protocols ospf
reference-bandwidth 10g;

To confirm your OSPFv3 configuration, enter the show protocols ospf3 command.

Configuring a Metric for a Specific OSPF Interface

CLI Quick Configuration

To quickly configure a metric for a specific OSPF interface, copy the following command and paste it into the CLI.

[edit]set protocols ospf area 0.0.0.0 interface fe-1/0/1 metric 5

Step-by-Step Procedure

To configure the metric for a specific OSPF interface:

  1. Create an OSPF area.

    Note: To specify OSPFv3, include the ospf3 statement at the [edit protocols] hierarchy level.

    [edit]user@host# edit protocols ospf area 0.0.0.0
  2. Configure the metric of the OSPF network segment.
    [edit protocols ospf area 0.0.0.0 ]user@host# set interface fe-1/0/1 metric 5
  3. If you are done configuring the device, commit the configuration.
    [edit protocols ospf area 0.0.0.0 ]user@host# commit

Results

Confirm your configuration by entering the show protocols ospf command. If the output does not display the intended configuration, repeat the instructions in this example to correct the configuration.

user@host# show protocols ospf
area 0.0.0.0 { interface fe-1/0/1.0 {metric 5;}}

To confirm your OSPFv3 configuration, enter the show protocols ospf3 command.

Verification

Confirm that the configuration is working properly.

Verifying the Configured Metric

Purpose

Verify the metric setting on the interface. Confirm that the Cost field displays the interface’s configured metric (cost). When choosing paths to a destination, OSPF uses the path with the lowest cost.

Action

From operational mode, enter the show ospf interface detail command for OSPFv2, and enter the show ospf3 interface detail command for OSPFv3.

Verifying the Route

Purpose

When choosing paths to a destination, OSPF uses the path with the lowest total cost. Confirm that OSPF is using the appropriate path.

Action

From operational mode, enter the show route command.

Example: Dynamically Adjusting OSPF Interface Metrics Based on Bandwidth

This example shows how to dynamically adjust OSPF interface metrics based on bandwidth.

Requirements

Before you begin:

Overview

You can specify a set of bandwidth threshold values and associated metric values for an OSPF interface. When the bandwidth of an interface changes, the Junos OS automatically sets the interface metric to the value associated with the appropriate bandwidth threshold value. When you configure bandwidth-based metric values, you typically configure multiple bandwidth and metric values.

In this example, you configure OSPF interface ae0 for bandwidth-based metrics by including the bandwidth-based-metrics statement and the following settings:

  • bandwidth—Specifies the bandwidth threshold in bits per second. The range is 9600 through 1,000,000,000,000,000.
  • metric—Specifies the metric value to associate with a specific bandwidth value. The range is 1 through 65,535.

Configuration

CLI Quick Configuration

To quickly configure bandwidth threshold values and associated metric values for an OSPF interface, copy the following commands, remove any line breaks, and then paste the commands into the CLI.

[edit]set protocols ospf area 0.0.0.0 interface ae0.0 metric 5set protocols ospf area 0.0.0.0 interface ae0.0 bandwidth-based-metrics bandwidth 1g metric 60set protocols ospf area 0.0.0.0 interface ae0.0 bandwidth-based-metrics bandwidth 10g metric 50

Step-by-Step Procedure

To configure the metric for a specific OSPF interface:

  1. Create an OSPF area.

    Note: To specify OSPFv3, include the ospf3 statement at the [edit protocols] hierarchy level.

    [edit]user@host# edit protocols ospf area 0.0.0.0
  2. Configure the metric of the OSPF network segment.
    [edit protocols ospf area 0.0.0.0 ]user@host# set interface ae0 metric 5
  3. Configure the bandwidth threshold values and associated metric values.
    [edit protocols ospf area 0.0.0.0 ]user@host# set interface ae0.0 bandwidth-based-metrics bandwidth 1g metric 60user@host# set interface ae0.0 bandwidth-based-metrics bandwidth 10g metric 50
  4. If you are done configuring the device, commit the configuration.
    [edit protocols ospf area 0.0.0.0 ]user@host# commit

Results

Confirm your configuration by entering the show protocols ospf command. If the output does not display the intended configuration, repeat the instructions in this example to correct the configuration.

user@host# show protocols ospf
area 0.0.0.0 { interface ae0.0 { bandwidth-based-metrics {bandwidth 1g metric 60;bandwidth 10g metric 50;}metric 5;}}

To confirm your OSPFv3 configuration, enter the show protocols ospf3 command.

Verification

Confirm that the configuration is working properly.

Verifying the Configured Metric

Purpose

Verify the metric setting on the interface. Confirm that the Cost field displays the interface’s configured metric (cost). When choosing paths to a destination, OSPF uses the path with the lowest cost.

Action

From operational mode, enter the show ospf interface detail command for OSPFv2, and enter the show ospf3 interface detail command for OSPFv3.

Example: Controlling OSPF Route Preferences

This example shows how to control OSPF route selection in the forwarding table. This example also shows how you might control route selection if you are migrating from OSPF to another IGP.

Requirements

This example assumes that OSPF is properly configured and running in your network, and you want to control route selection because you are planning to migrate from OSPF to a different IGP.

Overview

Route preferences are used to select which route is installed in the forwarding table when several protocols calculate routes to the same destination. The route with the lowest preference value is selected.

By default, internal OSPF routes have a preference value of 10, and external OSPF routes have a preference value of 150. You might want to modify this setting if you are planning to migrate from OSPF to a different IGP. Modifying the route preferences enables you to perform the migration in a controlled manner.

This example makes the following assumptions:

  • OSPF is already running in your network.
  • You want to migrate from OSPF to IS-IS.
  • You configured IS-IS per your network requirements and confirmed it is working properly.

In this example, you increase the OSPF route preference values to make them less preferred than IS-IS routes by specifying 168 for internal OSPF routes and 169 for external OSPF routes. IS-IS internal routes have a preference of either 15 (for Level1) or 18 (for Level 2), and external routes have a preference of 160 (for Level 1) or 165 (for Level 2). In general, it is preferred to leave the new protocol at its default settings to minimize complexities and simplify any future addition of routing devices to the network. To modify the OSPF route preference values, configure the following settings:

  • preference—Specifies the route preference for internal OSPF routes. By default, internal OSPF routes have a value of 10. The range is from 0 through 4,294967,295 (232 – 1).
  • external-preference—Specifies the route preference for external OSPF routes. By default, external OSPF routes have a value of 150. The range is from 0 through 4,294967,295 (232 – 1).

Configuration

CLI Quick Configuration

To quickly configure the OSPF route preference values, copy the following command and paste it into the CLI.

[edit]set protocols ospf preference 168 external-preference 169

Step-by-Step Procedure

To configure route selection:

  1. Enter OSPF configuration mode and set the external and internal routing preferences.

    Note: To specify OSPFv3, include the ospf3 statement at the [edit protocols] hierarchy level.

    [edit]user@host# set protocols ospf preference 168 external-preference 169
  2. If you are done configuring the device, commit the configuration.
    [edit]user@host# commit

Results

Confirm your configuration by entering the show protocols ospf command. If the output does not display the intended configuration, repeat the instructions in this example to correct the configuration.

user@host# show protocols ospf
preference 168;external-preference 169;

To confirm your OSPFv3 configuration, enter the show protocols ospf3 command.

Verification

Confirm that the configuration is working properly.

Verifying the Route

Purpose

Verify that the IGP is using the appropriate route. After the new IGP becomes the preferred protocol (in this example, IS-IS), you should monitor the network for any issues. After you confirm that the new IGP is working properly, you can remove the OSPF configuration from the routing device by entering the delete ospf command at the [edit protocols] hierarchy level.

Action

From operational mode, enter the show route command.

Published: 2013-07-09

Published: 2013-07-09