Flex-Algo, short for Flexible Algorithm, lets the IGP compute paths by rules other than the plain shortest path: a different metric, or a set of links to avoid. Networks otherwise build such paths with RSVP-TE tunnels or SR-TE policies; with Flex-Algo the IGP computes them.
By default, IS-IS computes its shortest paths with algorithm 0, which is plain SPF. Flex-Algo adds algorithms numbered 128 to 255. Each one is described by a Flexible Algorithm Definition (FAD): the metric to use and the links to leave out, for example, links with a given affinity. Only the routers that advertise an algorithm compute it, and the others are removed from its topology. Each participating router advertises a separate prefix-SID for each algorithm it takes part in, so the label an ingress PE pushes decides which path a packet takes.
In SP-B, Flex-Algo runs on B-P1, B-PE1, and B-PE2, the three XRv9k routers. B-P2, B-P3, B-P4, and B-ASBR are CSR1000v routers on IOS-XE, which has no Flex-Algo in the specific version I had in my lab.

Before this stage, B-PE1’s SR-MPLS path to B-PE2’s Loopback0 went through B-P1 at metric 20 (the SR-MPLS post). This stage defines algorithm 128 on the three XRv9k routers and raises the IS-IS metric of the two links through B-P1 from 10 to 100. Algorithm 0 between the PEs moves to the CSR routers, and algorithm 128 stays on B-P1. B-PE1’s algorithm-128 topology:
RP/0/RP0/CPU0:B-PE1#show isis topology level 2 flex-algo 128
Mon Jul 6 23:27:16.690 UTC
IS-IS 1 paths to IPv4 Unicast (Level-2) routers
System Id Metric Next-Hop Interface SNPA
B-P1 100 B-P1 Gi0/0/0/0 *PtoP*
B-P2 **
B-P3 **
B-P4 **
B-PE1 --
B-PE2 200 B-P1 Gi0/0/0/0 *PtoP*
B-RR **
B-ASBR **
The five routers without algorithm 128 have no next hop, marked **.
Topology file: topology.clab.yml · Addressing: ipam.md · Stage configs, 3 nodes (B-P1, B-PE1, B-PE2): stage_configs/lab03-s1-spb-flexalgo/
The Configuration
B-PE1’s configuration for this stage:
router isis 1
affinity-map CSR-EXIT bit-position 1
flex-algo 128
priority 100
affinity exclude-any CSR-EXIT
advertise-definition
!
interface Loopback0
address-family ipv4 unicast
prefix-sid algorithm 128 index 550
!
!
interface GigabitEthernet0/0/0/0
address-family ipv4 unicast
metric 100
!
!
interface GigabitEthernet0/0/0/1
affinity flex-algo CSR-EXIT
!
!
affinity-map gives bit position 1 the name CSR-EXIT. Under flex-algo 128, affinity exclude-any CSR-EXIT removes every link with that bit from the algorithm, and advertise-definition makes B-PE1 advertise this definition with priority 100. prefix-sid algorithm 128 index 550 gives Loopback0 its algorithm-128 SID, next to the algorithm-0 index 500 from the SR-MPLS post. affinity flex-algo CSR-EXIT sits on Gi0/0/0/1, the link to B-P2.
B-PE1 sets metric 100 on Gi0/0/0/0, its link to B-P1, and B-P1 and B-PE2 set it on their side, so both links through B-P1 cost 100 in each direction. The metric gives the two algorithms different paths between the PEs. At 10, algorithm 0 would take B-P1 as well, at 20 against 30 through B-P2 and B-P3; at 100 it takes B-P2 and B-P3. Algorithm 128 keeps B-P1, its only path between the PEs, because B-P2 and B-P3 do not take part in it.
Algorithm 128 in B-P1’s LSP
Part of B-P1’s LSP, from show isis database verbose B-P1.00-00:
Router Cap: 10.2.0.1 D:0 S:0
Segment Routing: I:1 V:0, SRGB Base: 16000 Range: 1000
SR Local Block: Base: 15000 Range: 1000
Node Maximum SID Depth:
Label Imposition: 10
SR Algorithm:
Algorithm: 0
Algorithm: 1
Algorithm: 128
Flex-Algo Definition:
Algorithm: 128 Metric-Type: 0 Alg-type: 0 Priority: 200
Flex-Algo Exclude-Any Ext Admin Group:
0x00000002
Metric: 0 IP-Extended 10.2.0.1/32
Prefix-SID Index: 100, Algorithm:0, R:0 N:1 P:0 E:0 V:0 L:0
Prefix-SID Index: 150, Algorithm:128, R:0 N:1 P:0 E:0 V:0 L:0
The SR Algorithm sub-TLV, inside the Router Capability TLV (TLV 242), lists the algorithms B-P1 takes part in: 0, 1 (strict SPF) and 128. The Flex-Algo Definition is B-P1’s FAD, and its exclude-any admin group 0x00000002 is bit position 1, CSR-EXIT.
The Definition Election
All three routers advertise a FAD for algorithm 128, B-P1 with priority 200 and the PEs with 100. Every router selects the same one: the highest priority wins, and a tie goes to the highest system-ID. B-PE1’s view:
RP/0/RP0/CPU0:B-PE1#show isis flex-algo 128
Mon Jul 6 23:26:36.557 UTC
IS-IS 1 Flex-Algo Database
Flex-Algo 128:
Level-2:
Definition Priority: 200
Definition Source: B-P1.00
Definition Equal to Local: Yes
Definition Metric Type: IGP
Definition Flex-Algo Prefix Metric: No
Exclude Any Affinity Bit Positions: 1
Include Any Affinity Bit Positions:
Include All Affinity Bit Positions:
Exclude SRLGs:
Disabled: No
Local Priority: 100
FRR Disabled: No
Microloop Avoidance Disabled: No
Data Plane Segemnt Routing: Yes
Data Plane IP: No
Definition Source is the router whose FAD won, and Local Priority is B-PE1’s own. On B-P1 the source reads B-P1.00, (Local). One advertised definition is enough for the algorithm to run. A router with no valid definition stops computing the algorithm, so the PEs’ copies keep algorithm 128 running if B-P1 stops advertising its definition.
Link Affinity
A link’s Flex-Algo affinity is advertised in an Application Specific Link Attributes (ASLA) sub-TLV. In B-PE1’s LSP, the entry for its link to B-P2:
Application Specific Link Attributes:
L flag: 0, SA-Length: 1, UDA-Length: 1
Standard Applications: 0x10 FLEX-ALGO
User Defined Applications: 0x10
Ext Admin Group:
0x00000002
Affinity: 0x00000002
Bit positions count from 0, so CSR-EXIT, bit position 1, has the value 2, shown as 0x00000002. affinity flex-algo CSR-EXIT on Gi0/0/0/1 sets that bit on the link, and the ASLA carries it as Ext Admin Group and Affinity, both 0x00000002. The exclude-any value in B-P1’s FAD is the same 0x00000002, so algorithm 128 excludes this link. Standard Applications: 0x10 FLEX-ALGO marks the attributes as Flex-Algo’s. B-PE2’s LSP carries the same block for its links to B-P3 and B-P4. Each of the three links ends on a CSR router that does not take part in algorithm 128, so participation already keeps them out of the algorithm-128 topology.
The CSR Routers
On B-P2, router isis has no flex-algo command:
B-P2(config)#router isis
B-P2(config-router)#flex-algo ?
% Unrecognized command
Algorithm 0 and Algorithm 128 Between the PEs
The path from B-PE1 to B-PE2 via B-P1 now costs 100 + 100 = 200. The path via B-P2 and B-P3 has three links of metric 10, a total of 30.

B-PE1’s route to 10.2.0.6:
RP/0/RP0/CPU0:B-PE1#show route 10.2.0.6/32
Mon Jul 6 23:27:01.640 UTC
Routing entry for 10.2.0.6/32
Known via "isis 1", distance 115, metric 30, labeled SR, type level-2
Installed Jul 6 23:23:54.018 for 00:03:07
Routing Descriptor Blocks
10.2.1.21, from 10.2.0.6, via GigabitEthernet0/0/0/0, Backup (Local-LFA)
Route metric is 120
10.2.1.25, from 10.2.0.6, via GigabitEthernet0/0/0/1, Protected
Route metric is 30
No advertising protos.
Algorithm 0 uses B-P2, 10.2.1.25, at metric 30, with the path through B-P1 as the LFA backup. A traceroute to the same address:
RP/0/RP0/CPU0:B-PE1#traceroute 10.2.0.6 source lo0
Mon Jul 6 23:27:40.036 UTC
Type escape sequence to abort.
Tracing the route to 10.2.0.6
1 *
10.2.1.25 [MPLS: Label 16600 Exp 0] 9 msec 2 msec
2 10.2.1.6 [MPLS: Label 16600 Exp 0] 2 msec 2 msec 4 msec
3 *
10.2.1.30 15 msec *
The hops are B-P2 (10.2.1.25), B-P3 (10.2.1.6) and B-PE2’s own interface (10.2.1.30). 16600 is B-PE2’s algorithm-0 label, index 600.
B-PE1 sends 16650, B-PE2’s algorithm-128 label, to B-P1:
RP/0/RP0/CPU0:B-PE1#show mpls forwarding labels 16650
Mon Jul 6 23:28:15.473 UTC
Local Outgoing Prefix Outgoing Next Hop Bytes
Label Label or ID Interface Switched
------ ----------- ------------------ ------------ --------------- ------------
16650 16650 SR Pfx (idx 650) Gi0/0/0/0 10.2.1.21 0
B-P1 pops it toward B-PE2, 10.2.1.50:
RP/0/RP0/CPU0:B-P1#show mpls forwarding labels 16650
Mon Jul 6 23:07:50.690 UTC
Local Outgoing Prefix Outgoing Next Hop Bytes
Label Label or ID Interface Switched
------ ----------- ------------------ ------------ --------------- ------------
16650 Pop SR Pfx (idx 650) Gi0/0/0/6 10.2.1.50 0
B-PE2 shows the same in the other direction. Its route to 10.2.0.5 goes through B-P3 at metric 30:
RP/0/RP0/CPU0:B-PE2#show route 10.2.0.5/32
Mon Jul 6 23:31:52.725 UTC
Routing entry for 10.2.0.5/32
Known via "isis 1", distance 115, metric 30, labeled SR, type level-2
Installed Jul 6 23:23:53.046 for 00:08:00
Routing Descriptor Blocks
10.2.1.29, from 10.2.0.5, via GigabitEthernet0/0/0/0, Protected
Route metric is 30
10.2.1.33, from 10.2.0.5, via GigabitEthernet0/0/0/1, Backup (Local-LFA)
Route metric is 40
No advertising protos.
B-PE2 sends B-PE1’s algorithm-128 label, 16550, to B-P1:
RP/0/RP0/CPU0:B-PE2#show mpls forwarding labels 16550
Mon Jul 6 23:32:20.392 UTC
Local Outgoing Prefix Outgoing Next Hop Bytes
Label Label or ID Interface Switched
------ ----------- ------------------ ------------ --------------- ------------
16550 16550 SR Pfx (idx 550) Gi0/0/0/4 10.2.1.49 0
On B-PE1, CustC’s route to Core3’s loopback, 10.30.0.3, has the next hop 10.2.0.6, so CustC’s IPv4 traffic from Core2 to Core3 now takes the algorithm-0 path through the CSR routers. Pings from Core2 to Core3’s loopback, IPv4 and IPv6:
CustC-Core2#ping 10.30.0.3 source lo0
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 10.30.0.3, timeout is 2 seconds:
Packet sent with a source address of 10.30.0.2
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 3/5/8 ms
CustC-Core2#ping 2001:DB8:30::3 source lo0
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 2001:DB8:30::3, timeout is 2 seconds:
Packet sent with a source address of 2001:DB8:30::2
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 2/3/4 ms
A Router’s Own Prefix-SID
On B-P1, the lookup for its own algorithm-128 label returns nothing:
RP/0/RP0/CPU0:B-P1#show mpls forwarding labels 16150
Mon Jul 6 23:07:39.112 UTC
B-P1’s prefix-SIDs carry P:0, so PHP is on: the router before B-P1 pops the label, and B-P1 never receives it. B-PE1 has the entry, with Pop toward B-P1:
RP/0/RP0/CPU0:B-PE1#show mpls forwarding labels 16150
Mon Jul 6 23:28:28.386 UTC
Local Outgoing Prefix Outgoing Next Hop Bytes
Label Label or ID Interface Switched
------ ----------- ------------------ ------------ --------------- ------------
16150 Pop SR Pfx (idx 150) Gi0/0/0/0 10.2.1.21 0
What’s Next
Algorithm 128 is in place, and no traffic uses it yet. The next post steers CustC onto it: an on-demand next-hop (ODN) SR-TE policy with sid-algorithm 128 moves CustC’s traffic between Core2 and Core3 to the path through B-P1.
Leave a Reply