Flex Algo stands for Flexible Algorithm. Every prefix SID is associated with an algorithm, with the default being algorithm 0. By using different algorithms, paths to prefix SIDs can be calculated based on other metrics and constraints besides using lowest cost.
Have you noticed in the previous articles that the Prefix-SID IGP advertisements contain an algorithm associated with them?
RP/0/RP0/CPU0:R1#show ospf database opaque-area 7.0.0.1 self-originate
Wed Sep 7 19:11:59.534 UTC
OSPF Router with ID (1.1.1.1) (Process ID 2)
Type-10 Opaque Link Area Link States (Area 0)
LS age: 303
Options: (No TOS-capability, DC)
LS Type: Opaque Area Link
Link State ID: 7.0.0.1
Opaque Type: 7
Opaque ID: 1
Advertising Router: 1.1.1.1
LS Seq Number: 80000029
Checksum: 0x95d8
Length: 44
Extended Prefix TLV: Length: 20
Route-type: 1
AF : 0
Flags : 0x40
Prefix : 1.1.1.1/32
SID sub-TLV: Length: 8
Flags : 0x0
MTID : 0
Algo : 0
SID Index : 1
Algorithm 0 is the default IGP best path calculation algorithm. A prefix SID is an instruction to steer traffic towards the prefix using the IGP ECMP-aware best path. However, this is only because it is associated with algorithm 0 by default. We can use different algorithms to steer traffic towards a prefix SID using a completely different calculation. We can use lowest delay or include/exclude link colors just like with SR-TE policies.
Algorithms 0-127 are reserved, and 128-255 are available for you, the operator, to define and use. For example, you can choose for flex algo 128 to be the lowest delay. A router can advertise a prefix with multiple SID indexes, one for each algorithm.
One benefit of using flex algo is that the SID list can be reduced compared to using an SR-TE policy. An SR-TE policy may need to generate a SID list of length 3 or 4 to steer traffic along a TE path. However if all routers agree that flex algo #130 defines the set of constraints, then only a single SID is needed. All routers collectively calculate the best path using flex algo 130, instead of the headend calculating the path and preprogramming a list of SIDs.
Lab
On R1 let’s define flex algo #128 to mean “steer traffic along RED links only.” We’ll advertise the loopback with a prefix sid index of 1000 + R# on each router.
#R1
router ospf 2
! We must define the RED affinity under the IGP for flex-algo, even though it is currently present in SR-TE
affinity-map RED bit-position 20
! The following defines the constraints for flex algo 128
flex-algo 128
affinity include-all RED
! This instructs the router to advertise the flex-algo definition into the IGP
advertise-definition
!
area 0
int lo0
prefix-sid algorithm 128 index 1001
int Gi0/0/0/0
affinity flex-algo RED
You can see SID index 1001 for flex algo 128 in R1’s Extended Prefix Opaque LSA.
RP/0/RP0/CPU0:R1#show ospf database opaque-area 7.0.0.1 self-originate
Wed Sep 7 19:25:22.472 UTC
OSPF Router with ID (1.1.1.1) (Process ID 2)
Type-10 Opaque Link Area Link States (Area 0)
LS age: 11
Options: (No TOS-capability, DC)
LS Type: Opaque Area Link
Link State ID: 7.0.0.1
Opaque Type: 7
Opaque ID: 1
Advertising Router: 1.1.1.1
LS Seq Number: 8000002a
Checksum: 0x5687
Length: 56
Extended Prefix TLV: Length: 32
Route-type: 1
AF : 0
Flags : 0x40
Prefix : 1.1.1.1/32
SID sub-TLV: Length: 8
Flags : 0x0
MTID : 0
Algo : 0
SID Index : 1
SID sub-TLV: Length: 8
Flags : 0x0
MTID : 0
Algo : 128
SID Index : 1001
Additionally, the Router Information Opaque LSA includes Flex Algo 128 now:
RP/0/RP0/CPU0:R1#show ospf database opaque-area 4.0.0.0 self-originate
Wed Sep 7 19:46:38.697 UTC
OSPF Router with ID (1.1.1.1) (Process ID 2)
Type-10 Opaque Link Area Link States (Area 0)
LS age: 108
Options: (No TOS-capability, DC)
LS Type: Opaque Area Link
Link State ID: 4.0.0.0
Opaque Type: 4
Opaque ID: 0
Advertising Router: 1.1.1.1
LS Seq Number: 8000002d
Checksum: 0x8c3f
Length: 100
Router Information TLV: Length: 4
Capabilities:
Graceful Restart Helper Capable
Stub Router Capable
Traffic Engineering enabled area
All capability bits: 0x70000000
Segment Routing Algorithm TLV: Length: 3
Algorithm: 0
Algorithm: 1
Algorithm: 128
Segment Routing Range TLV: Length: 12
Range Size: 8000
SID sub-TLV: Length 3
Label: 16000
Node MSD TLV: Length: 2
Type: 1, Value 10
Segment Routing Local Block TLV: Length: 12
Range Size: 1000
SID sub-TLV: Length 3
Label: 15000
Segment Routing FAD TLV: Length: 12
Flex Algo Number : 128
Flex Algo Metric Type : 0
Flex Algo Priority : 128
Flex Algo Calc_type : 0
FAD Include All sub-TLV: Length 4
FAD Include All Group : 0x00100000
Dynamic Hostname TLV: Length: 2
Hostname: R1
Algorithm 0 is SPF, and algorithm 1 is strict SPF
You can see the Flex Algo definition at the bottom
Let’s repeat this on each router in the topology:
#R2
router ospf 2
flex-algo 128
affinity include-all RED
advertise-definition
!
area 0
int lo0
prefix-sid algorithm 128 index 1002
int Gi0/0/0/0
affinity flex-algo RED
!
router ospf 1
affinity-map RED bit-position 20
flex-algo 128
affinity include-all RED
advertise-definition
!
area 0
int lo0
prefix-sid algorithm 128 index 1002
int Gi0/0/0/0
affinity flex-algo RED
int Gi0/0/0/2
affinity flex-algo RED
#R3
router ospf 1
affinity-map RED bit-position 20
flex-algo 128
affinity include-all RED
advertise-definition
!
area 0
int lo0
prefix-sid algorithm 128 index 1003
int Gi0/0/0/0
affinity flex-algo RED
int Gi0/0/0/1
affinity flex-algo RED
#R4
router ospf 1
affinity-map RED bit-position 20
flex-algo 128
affinity include-all RED
advertise-definition
!
area 0
int lo0
prefix-sid algorithm 128 index 1004
int Gi0/0/0/0
affinity flex-algo RED
int Gi0/0/0/2
affinity flex-algo RED
#R6
router ospf 1
affinity-map RED bit-position 20
flex-algo 128
affinity include-all RED
advertise-definition
!
area 0
int lo0
prefix-sid algorithm 128 index 1006
int Gi0/0/0/0
affinity flex-algo RED
Examine R2’s LFIB. Notice that the outgoing interface for R6’s algo 0 prefix SID is the ECMP path via Gi0/0/0/1 and Gi0/0/0/3. The outgoing interface for R6’s algo 128 prefix SID is Gi0/0/0/2.
RP/0/RP0/CPU0:R2#show mpls forwarding labels 16006
Wed Sep 7 19:48:15.228 UTC
Local Outgoing Prefix Outgoing Next Hop Bytes
Label Label or ID Interface Switched
------ ----------- ------------------ ------------ --------------- ------------
16006 16006 SR Pfx (idx 6) Gi0/0/0/3 10.2.5.5 367903
16006 SR Pfx (idx 6) Gi0/0/0/1 10.2.4.4 856
RP/0/RP0/CPU0:R2#show mpls forwarding labels 17006
Wed Sep 7 19:48:18.542 UTC
Local Outgoing Prefix Outgoing Next Hop Bytes
Label Label or ID Interface Switched
------ ----------- ------------------ ------------ --------------- ------------
17006 17006 SR Pfx (idx 1006) Gi0/0/0/2 10.2.3.3 0
Unlike algo 0 prefix SIDs, there are no IP-to-MPLS forwarding entries in CEF for these algo 128 prefix SIDs. The only situation in which these labels will be used is when using SR-TE policies.
On R2 we’ll create the CUSTOMER_A VRF and observe the path that traffic towards the prefix 10.1.2.0/24 takes. We’ll create the same ODN definition as on R1, but instead of specifying the link affinity colors that must be included, we’ll specify that the path must use sid-algorithm 128.
R1 does not have 17006 in its LFIB, because R1 is in a different IGP domain compared to R6. However the PCE, R2, calculated the path and passed it onto R1.
You’ve now gained a deeper understanding of Prefix SIDs. The introductory definition is that a prefix SID represents the ECMP-aware IGP lowest cost path to a given prefix. The new definition is that a prefix SID represents the ECMP-aware path to a given prefix based on the algorithm for that prefix SID. Algorithm 0 is the default, which means to use basic SPF to find the shortest path based on lowest metric. The operator can define any other algorithms in the range 128-255 to create new shortest path calculations based on lowest delay or constraints. Additional algorithms are advertised in the IGP, and a given prefix can have multiple prefix SIDs associated with it, one per algorithm.