# Flowspec (VRF w/ Redirect)

**Topology**: ine-spv4

<figure><img src="https://3072390383-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FkUz2C3GqnZcWhoVL6jfk%2Fuploads%2FKZeSzMgT7mscuJjobxHA%2Fimage.png?alt=media&#x26;token=d2b78c46-eb0d-4ef4-80d5-756a1895eaf5" alt=""><figcaption></figcaption></figure>

Load **flowspec.vrf.redir.init.cfg**

```
#IOS-XE
config replace flash:flowspec.vrf.redir.init.cfg
 
#IOS-XR (XRv1 only)
configure
load bootflash:flowspec.vrf.redir.init.cfg
commit replace
y
```

R1 and R7 are dual-stacked internet peers. Internet is running in an INET vrf in the core.

R8 is in a VRF called “ANALYZE”, in which it advertises a default route. Redirect traffic sourced from 1.1.1.1/32 and 2001:1::1/128 to this VRF for analysis. Use XR1 as the central policy control router using flowspec. BGP flowspec is already pre-configured.

## Answer <a href="#id-4fe81115-10b1-4b72-b085-c5a538f9421b" id="id-4fe81115-10b1-4b72-b085-c5a538f9421b"></a>

```
#R2, R4
vrf definition ANALYZE
 rd 100:666
 route-target export 100:666
 route-target import 100:666
 !
 address-family ipv4
 exit-address-family
 !
 address-family ipv6
 exit-address-family

#XR1
vrf INET
 address-family ipv4 flowspec
  import route-target
   100:100
  export route-target
   100:100
 !
 address-family ipv6 flowspec
  import route-target
   100:100
  export route-target
   100:100
!
router bgp 100
 vrf INET
  rd 100:100
  add ipv4 flowspec
  add ipv6 flowspec
!
class-map type traffic match-all CM_FLOWSPEC_V4_R1
 match source-address ipv4 1.1.1.1 255.255.255.255
 end-class-map
!
class-map type traffic match-all CM_FLOWSPEC_V6_R1
 match source-address ipv6 2001:1::1/128
 end-class-map
!
policy-map type pbr PM_FLOWSPEC_V4
 class type traffic CM_FLOWSPEC_V4_R1
 redirect nexthop route-target 100:666
!
policy-map type pbr PM_FLOWSPEC_V6
 class type traffic CM_FLOWSPEC_V6_R1
 redirect nexthop route-target 100:666
!
flowspec
 vrf INET
  address-family ipv4
   service-policy type pbr PM_FLOWSPEC_V4
  !
  address-family ipv6
   service-policy type pbr PM_FLOWSPEC_V6
```

## Explanation <a href="#id-6bc3deb5-4966-49c8-b7e2-3c0d1d6b8c47" id="id-6bc3deb5-4966-49c8-b7e2-3c0d1d6b8c47"></a>

Using a flowspec redirect in a VRF is quite similar to doing a redirect with flowspec in the global table. The main differences are:

* You must define the “ANALYZE” VRF on all PEs
* You use **redirect nexthop route-target** instead of **redirect ipv4|ipv6 nexthop**

Notice the difference in the policy-maps on XR1 now:

```
policy-map type pbr PM_FLOWSPEC_V4
 class type traffic CM_FLOWSPEC_V4_R1
  redirect nexthop route-target 100:666
!
policy-map type pbr PM_FLOWSPEC_V6
 class type traffic CM_FLOWSPEC_V6_R1
  redirect nexthop route-target 100:666
```

The route-target is obtained by looking at R5’s export RT for the ANALYZE VRF:

<div align="left"><figure><img src="https://3072390383-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FkUz2C3GqnZcWhoVL6jfk%2Fuploads%2FDx12b2GjKygEumIIslh2%2Fimage.png?alt=media&#x26;token=08ef0fe6-4b58-4021-86f5-937620e60312" alt=""><figcaption></figcaption></figure></div>

If you don’t define the ANALYZE VRF on the other PEs, they will not have a RIB for the VRF, and therefore can’t redirect traffic into the VRF.

```
#R2, R4
vrf definition ANALYZE
 rd 100:666
 route-target export 100:666
 route-target import 100:666
 !
 address-family ipv4
 exit-address-family
 !
 address-family ipv6
 exit-address-family
```

The PEs should learn the default route with a nexthop of R5, which is advertised by R8.

<div align="left"><figure><img src="https://3072390383-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FkUz2C3GqnZcWhoVL6jfk%2Fuploads%2FOhi2kHD3P0BpoerJrLf8%2Fimage.png?alt=media&#x26;token=16147feb-927f-4554-ac10-caea91ecf26d" alt=""><figcaption></figcaption></figure></div>

## Verification <a href="#id-0a0951b6-cc6b-4b6a-b519-13c9d0f550c6" id="id-0a0951b6-cc6b-4b6a-b519-13c9d0f550c6"></a>

On the PEs, notice that the VPNv4/v6 flowspec NLRI has a 0.0.0.0 nexthop again:

<div align="left"><figure><img src="https://3072390383-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FkUz2C3GqnZcWhoVL6jfk%2Fuploads%2Fn9j3OxIMEH12AYH5X7wk%2Fimage.png?alt=media&#x26;token=a7c0ad3f-de92-4d31-b0cd-013afd83f688" alt=""><figcaption></figcaption></figure></div>

Unlike the global redirect, which has the actual value of the IP to use to redirect the traffic to, a VRF redirect uses an extcommunity action instead of implementing the redirect with the BGP nexthop.

<div align="left"><figure><img src="https://3072390383-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FkUz2C3GqnZcWhoVL6jfk%2Fuploads%2Fo6iSLKGZisHtaaI27PTC%2Fimage.png?alt=media&#x26;token=f85b9782-f417-44f6-99b4-4476f63c55d6" alt=""><figcaption></figcaption></figure></div>

On PE2, we can see that the flowspec action is to redirect to the ANALYZE VRF:

<div align="left"><figure><img src="https://3072390383-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FkUz2C3GqnZcWhoVL6jfk%2Fuploads%2F4KS2IcYzYD36kzQoyfqm%2Fimage.png?alt=media&#x26;token=1f1c8be2-9177-4819-9403-6ce458308032" alt=""><figcaption></figcaption></figure></div>

If we run some pings to test this traffic out, we can see that the hits increment on these flowspec policies:

```
#R1
ping 7.7.7.7 so lo0 repeat 3
ping 2001:7::7 so lo0 repeat 3
```

<div align="left"><figure><img src="https://3072390383-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FkUz2C3GqnZcWhoVL6jfk%2Fuploads%2FFsLYGgsztI89EeqoAajP%2Fimage.png?alt=media&#x26;token=68f6b0ef-8cba-4760-bb74-9c6d013dfb82" alt=""><figcaption></figcaption></figure></div>

We see ACL hits for both IPv4 and IPv6 on R8.

<div align="left"><figure><img src="https://3072390383-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FkUz2C3GqnZcWhoVL6jfk%2Fuploads%2FQUWQo7PVqVprifkwL4tb%2Fimage.png?alt=media&#x26;token=546ee650-c9a1-44e9-af79-006dd5a55692" alt=""><figcaption></figcaption></figure></div>

By the way, the IPv6 redirect to a VRF works on CSR1000v version 17.x as well, while a global nexthop IPv6 redirect does not work. But both of these work on version 16.9.8.
