# [SR-MPLS] LAB Segment Routing with SR-TE and PCE

# **Lab topology** and sample configs for testing **Segment Routing with SR-TE and PCE** on Cisco IOS XE routers.

---

## 🖥️ Topology

```plaintext
[ R1 ]---[ R2 ]---[ R3 ]---[ R4 ]
   |                         |
   |-------------------------|
```

* **R1:** PCC (client), Source
    
* **R4:** Destination
    
* **R2 & R3:** Transit
    
* **Loopbacks:**
    
    * R1 = 1.1.1.1/32, SID 16001
        
    * R2 = 2.2.2.2/32, SID 16002
        
    * R3 = 3.3.3.3/32, SID 16003
        
    * R4 = 4.4.4.4/32, SID 16004
        

---

## 🔧 Common OSPF & SR Config (on all routers)

```plaintext
hostname R1
!
interface Loopback0
 ip address 1.1.1.1 255.255.255.255
!
interface Gig0/0
 ip address 10.0.12.1 255.255.255.0
 mpls ip
 ip ospf 1 area 0
!
router ospf 1
 router-id 1.1.1.1
 segment-routing mpls
!
mpls traffic-eng
!
segment-routing
 mpls
  global-block 16000 23999
  connected-prefix-sid-map
   address 1.1.1.1/32 absolute-sid 16001
```

Change IPs and SIDs accordingly for R2–R4.

---

## 🧠 On PCE Node (e.g., R2)

```plaintext
pce
 segment-routing
  peer 1.1.1.1
   source-address 2.2.2.2
   lsr-id 2.2.2.2
   capability pcc
   capability pce
!
pcc-address-family ipv4
 stateful-client
!
pce-address-family ipv4
 source-address 2.2.2.2
```

---

## 🧭 On PCC Node (R1)

```plaintext
pce
 segment-routing
  pcc
   peer 2.2.2.2
    source-address 1.1.1.1
```

---

## 🚀 Tunnel (SR-TE Policy on R1 to R4)

```plaintext
interface Tunnel100
 ip unnumbered Loopback0
 tunnel mode mpls traffic-eng
 tunnel destination 4.4.4.4
 tunnel mpls traffic-eng path-option 10 dynamic
 tunnel mpls traffic-eng autoroute announce
 segment-routing mpls
```

---

## 📋 Verification

* `show pce peer`
    
* `show pce lsp`
    
* `show segment-routing traffic-eng policy`
    
* `show mpls forwarding-table`
    

# More details

```plaintext
     [R1 - PCC]
        |
     (IGP + SR)
        |
     [R2 - PCE]
      /      \
     /        \
[R3]----(IGP)----[R4]
```

### Roles:

* **R1 (PCC)**: Requests a path from the PCE.
    
* **R2 (PCE)**: Computes the best SR-TE path based on constraints (e.g., low latency, bandwidth).
    
* **R3 & R4**: Intermediate and destination routers.
    

### Traffic Flow:

1. R1 uses IGP (e.g., OSPF or IS-IS) with Segment Routing enabled to advertise and receive labels (SIDs).
    
2. R1, as PCC, sends a path computation request (PCEP) to R2.
    
3. R2, as PCE, computes a TE path using available topology and policy constraints.
    
4. R1 receives the path and installs it as an SR-TE policy.
    
5. Traffic follows the SR policy instead of IGP’s default shortest path.
    

### Benefits of SR-TE with PCE:

* Centralized path computation (PCE).
    
* Dynamic re-optimization when network state changes.
    
* SLA-aware routing (e.g., avoid congested links or meet latency targets).
    
* Supports automation via NETCONF/YANG or CLI.
    

## The configuration to include **bandwidth**, **affinity (link color)**, and **explicit path constraints** in Cisco IOS-XR.

---

### 🧱 Example Network Setup

```plaintext
R1 -- R2 -- R3 -- R4

R1 = PCC (headend)
R2 = PCE (central controller)
R4 = destination
Links: SR-MPLS enabled, OSPF/ISIS as IGP
```

---

### 1️⃣ Add Affinity (Link Color) to Interfaces (on R2, R3)

> Suppose you want traffic to use only "green" links.

```plaintext
interface GigabitEthernet0/0/0/1
 description Link to R3 (green)
 segment-routing
  forwarding
  affinity 0x2
```

Here:

* `affinity 0x2` marks the link as "green".
    
* Affinity is a 32-bit bitmask — you define meanings separately.
    

---

### 2️⃣ Define Affinity Mapping (on PCE or router where policy is configured)

```plaintext
segment-routing
 traffic-eng
  affinity-map green 0x2
```

---

### 3️⃣ Define SR-TE Policy with Constraints (on R1 — PCC)

```plaintext
segment-routing
 traffic-eng
  policy SRTE-R1-R4
   color 100
   end-point ipv4 10.0.0.4
   candidate-paths
    preference 100
     constraints
      affinity include green
      bandwidth 1000000  ! in Kbps (1 Gbps)
     explicit segment-list R1-R2-R3-R4
```

---

### 4️⃣ Define Explicit Segment List (Optional for hard path pinning)

```plaintext
segment-routing
 traffic-eng
  segment-list R1-R2-R3-R4
   index 10
    mpls label 16002  ! R2 SID
   index 20
    mpls label 16003  ! R3 SID
   index 30
    mpls label 16004  ! R4 SID
```

---

### ✅ What This Does:

* **Bandwidth**: Allocates bandwidth-aware paths via the PCE.
    
* **Affinity**: Ensures only “green” tagged links are used.
    
* **Explicit path**: You can pin the SR path manually using segment SIDs.
    

Here is the full configuration for a Cisco SR-TE setup using a PCE-PCC model across four routers (R1 to R4). R1 is the PCC, R2 is the PCE, and R3/R4 are transit/destination nodes.

* ```plaintext
    !
    ! R1 Configuration (PCC)
    !
    hostname R1
    !
    interface Loopback0
     ip address 1.1.1.1 255.255.255.255
    !
    interface GigabitEthernet0/0
     ip address 10.0.12.1 255.255.255.0
     mpls ip
     ip ospf 1 area 0
    !
    interface GigabitEthernet0/1
     ip address 10.0.14.1 255.255.255.0
     mpls ip
     ip ospf 1 area 0
    !
    router ospf 1
     router-id 1.1.1.1
     network 10.0.12.0 0.0.0.255 area 0
     network 10.0.14.0 0.0.0.255 area 0
     network 1.1.1.1 0.0.0.0 area 0
     segment-routing mpls
    !
    mpls traffic-eng
    !
    segment-routing
     mpls
      global-block 16000 23999
      connected-prefix-sid-map
       address 1.1.1.1/32 absolute-sid 16001
    !
    pce
     segment-routing
      pcc
       peer 2.2.2.2
        source-address 1.1.1.1
    !
    interface Tunnel100
     ip unnumbered Loopback0
     tunnel mode mpls traffic-eng
     tunnel destination 4.4.4.4
     tunnel mpls traffic-eng path-option 10 dynamic
     tunnel mpls traffic-eng autoroute announce
     segment-routing mpls
    
    
    !
    ! R2 Configuration (PCE)
    !
    hostname R2
    !
    interface Loopback0
     ip address 2.2.2.2 255.255.255.255
    !
    interface GigabitEthernet0/0
     ip address 10.0.12.2 255.255.255.0
     mpls ip
     ip ospf 1 area 0
    !
    interface GigabitEthernet0/1
     ip address 10.0.23.1 255.255.255.0
     mpls ip
     ip ospf 1 area 0
    !
    router ospf 1
     router-id 2.2.2.2
     network 10.0.12.0 0.0.0.255 area 0
     network 10.0.23.0 0.0.0.255 area 0
     network 2.2.2.2 0.0.0.0 area 0
     segment-routing mpls
    !
    mpls traffic-eng
    !
    segment-routing
     mpls
      global-block 16000 23999
      connected-prefix-sid-map
       address 2.2.2.2/32 absolute-sid 16002
    !
    pce
     segment-routing
      peer 1.1.1.1
       source-address 2.2.2.2
       lsr-id 2.2.2.2
       capability pcc
       capability pce
    !
    pcc-address-family ipv4
     stateful-client
    !
    pce-address-family ipv4
     source-address 2.2.2.2
    
    
    !
    ! R3 Configuration (Transit)
    !
    hostname R3
    !
    interface Loopback0
     ip address 3.3.3.3 255.255.255.255
    !
    interface GigabitEthernet0/0
     ip address 10.0.23.2 255.255.255.0
     mpls ip
     ip ospf 1 area 0
    !
    interface GigabitEthernet0/1
     ip address 10.0.34.1 255.255.255.0
     mpls ip
     ip ospf 1 area 0
    !
    router ospf 1
     router-id 3.3.3.3
     network 10.0.23.0 0.0.0.255 area 0
     network 10.0.34.0 0.0.0.255 area 0
     network 3.3.3.3 0.0.0.0 area 0
     segment-routing mpls
    !
    mpls traffic-eng
    !
    segment-routing
     mpls
      global-block 16000 23999
      connected-prefix-sid-map
       address 3.3.3.3/32 absolute-sid 16003
    
    
    !
    ! R4 Configuration (Destination)
    !
    hostname R4
    !
    interface Loopback0
     ip address 4.4.4.4 255.255.255.255
    !
    interface GigabitEthernet0/0
     ip address 10.0.34.2 255.255.255.0
     mpls ip
     ip ospf 1 area 0
    !
    interface GigabitEthernet0/1
     ip address 10.0.14.2 255.255.255.0
     mpls ip
     ip ospf 1 area 0
    !
    router ospf 1
     router-id 4.4.4.4
     network 10.0.34.0 0.0.0.255 area 0
     network 10.0.14.0 0.0.0.255 area 0
     network 4.4.4.4 0.0.0.0 area 0
     segment-routing mpls
    !
    mpls traffic-eng
    !
    segment-routing
     mpls
      global-block 16000 23999
      connected-prefix-sid-map
       address 4.4.4.4/32 absolute-sid 16004
    ```
