Help us improve your experience.

Let us know what you think.

Do you have time for a two-minute survey?


Example: OSPF Flexible Algorithm


This example shows how to configure flexible algorithm in an OSPFv2 network. The flexible algorithm allows networks without a controller to configure traffic engineering using segment routing without actually implementing a network controller.

Starting in Junos OS Release 21.1R1, you can thin-slice a network by defining flexible algorithms that compute paths using different parameters and link constraints based on your requirements. The set consisting of calculation-type, metric-type, and a set of constraints is referred to as a flexible algorithm definition (FAD). You can define FADs and advertise the same in an OSPFv2 network. A device can also be configured to participate in a certain flexible algorithm provided it supports the constraints for that specific FAD.


Figure 1 shows a flexible algorithm topology in which there are 6 devices R0, R1, R2, R3, R4, and R5. Two flexible algorithms 128 and 129 are defined on each of these devices. The admin-groups red, blue, and green are configured on the devices. The FADs with different parameters such as metric-types, calculation-types, and link constraints are defined on each of the devices.

Figure 1: Flexible Algorithm TopologyFlexible Algorithm Topology


This example uses the following hardware and software components:

  • Six MX Series routers.
  • Junos OS Release 21.1R1 or later running on all devices.


CLI Quick Configuration

To quickly configure this example, copy the following commands, paste them into a text file, remove any line breaks, change any details necessary to match your network configuration, and then copy and paste the commands into the CLI at the [edit] hierarchy level.

Device R0

Device R1

Device R2

Device R3

Device R4

Device R5

Configuring Device R0

To configure flexible algorithm for OSPFv2, perform the following steps on the device R0:

  1. Configure the device interfaces to enable IP transport.

  2. Configure the loopback interface (lo0) address that is used as router ID for OSPF sessions.

  3. Configure the router ID and autonomous system (AS) number to propagate routing information within a set of routing devices that belong to the same AS.

  4. Define a policy to load balance packets and apply the per-packet policy to enable load balancing of traffic.

  5. Configure the route filter for the routing policy term that enables the Device R0 to reach the network.

  6. Configure MPLS on all interfaces excluding the management interface.
  7. Configure the MPLS label range to assign static labels for the links.

  8. Configure TI-LFA to enable protection against link and node failures. SR using TI-LFA provides faster restoration of network connectivity by routing the traffic instantly to a backup or an alternate path if the primary path fails or becomes unavailable.

  9. Configure the maximum number of labels for segment routing routed paths for protection of backup shortest-path-first attributes.

  10. Configure prefix segment attributes, the start label and the index range for segment routing global blocks (SRGBs) in SPRING for the OSPF protocol.

  11. Enable node-link protection on the OSPF interfaces that follow post-convergence path.

  12. Configure the loopback interface as passive to ensure the protocols do not run over the loopback interface and that the loopback interface is advertised correctly throughout the network.

  13. Define flexible algorithms on the device R0. Assign a name for each of the FADs ranging from 128 through 255.

    Specify the parameters of the definition. OSPFv2 calculates the path based on these specified parameters of the FAD.

    1. Specify the calculation type based on which the OSPFv2 protocol calculates the path.

    2. Specify the metric type based on which OSPFv2 calculates the path.

    3. If you have enabled RSVP traffic engineering, you can configure admin-groups for many protocols to color an individual link.

    4. Assign the configured admin-groups policies to the device R0 interfaces.

    5. Define the admin-groups as per your requirement.


      For FADs with link-constraints to work, all relevant links should advertise the admin-colors in OSPFv2. You must either enable RSVP on the interfaces or if you have not configured RSVP for traffic engineering, make sure you configure set traffic-engineering advertise always at the [edit protocols ospf] hierarchy level.

  14. Configure the flexible algorithm participation on the device R0. The same device can advertise a FAD and also participate in a flexible algorithm.
  15. Advertise prefix segments through policy configuration.


Check the results of the configuration:

From configuration mode, confirm your configuration by entering the, show interfaces, show routing-options, show protocols, and show policy-options commands. If the output does not display the intended configuration, repeat the instructions in this example to correct the configuration.


To confirm that the configuration is working properly, perform the following tasks:

Verifying the OSPF Database


Verifying that the flexible algorithm signaling is displayed in the OSPF database.


From operational mode, run the show ospf database opaque-area extensive command.

On R0


This output on R0 illustrates that:

Three segment-routing algorithms (including two flexible algorithms) are advertised by this device.

Two FADs are advertised by this device.

Verifying the Flexible Algorithm Details


Verifying that the flexible algorithm details are displayed.


From operational mode, run the show ospf spring flex-algorithm <flex-algorithm-id> command.

On R0


The flexible algorithm details that are configured on R0 are displayed.

Verifying Flexible Algorithm Specific OSPF Internal Routes


Verifying that the fexible algorithm specific OSPF internal routes are displayed.


From operational mode, run the show ospf route flex-algorithm <flex-algorithm-id> command.

On R0


The show ospf route command is extended with flex-algorithm option to show flexible algorithm specific OSPF internal routes. Each route is prefixed with the flex-algo-id:

Verifying Flex Colored routes


Verifying that the fexible algorithm specific OSPF internal routes are displayed.


From operational mode, run the show route protocol ospf command.

On R0


The output displays all the colored flex routes programmed in inetcolor.0 table in the following format: prefix_address-flex-algo-id<c>/64

Verifying OSPF Logs


Verifying that the OSPF logs displays the flexible algorithm keyword.


From operational mode, run the show ospf log command.

On R0


The output displays the FlexAlgo keyword added for the SPF logs.