Cisco IOS XR RPL Route Policy: prefix-set Examples - 夜莺博客

Cisco IOS XR RPL Route Policy: prefix-set Examples

Classic IOS route-maps do not exist on IOS XR. Instead, ASR 9000, NCS and 8000 routers use the Route Policy Language (RPL), a more structured way to filter and manipulate BGP routes that is mandatory for eBGP peers - every neighbor needs at least a pass-all style policy before routes flow. RPL is built from named sets (prefix-sets, community-sets, as-path-sets) and route-policies that combine matching conditions with actions such as drop, pass, and set. This guide explains RPL with practical prefix-set examples, including the one behavior that surprises IOS veterans: sequential policies always evaluate the original attribute values, not the values a previous action just set.

RPL Building Blocks: prefix-set and route-policy

A prefix-set is a named collection of prefixes with optional length operators. The following example matches the RFC 1918 private ranges plus a couple of bogons, using le 32 to match the prefix and all of its longer subnets:

prefix-set PFX-MARTIANS
  10.0.0.0/8 le 32,
  172.16.0.0/12 le 32,
  192.168.0.0/16 le 32
end-set

Route-policies consume these sets. A policy to drop anything in the martian set and pass everything else looks like this:

route-policy FILTER-MARTIANS
  if destination in ( PFX-MARTIANS ) then
    drop
  endif
  pass
end-policy

Manipulating Attributes with RPL

RPL actions mirror route-map set clauses: set local-preference, set med, set origin, and set community. The if/elseif structure reads naturally:

route-policy SET-PREFS
  if destination in ( PFX-CUSTOMER ) then
    set local-preference 200
    set med 100
  else
    set local-preference 90
  endif
end-policy

An important gotcha: RPL evaluates every condition against the ORIGINAL values of the route. In the example below, a route whose MED was originally 100 is dropped - even though the first action set its MED to 200 - because the second condition is evaluated on the original MED of 100:

route-policy ORIGINAL-VALUES
  if med eq 100 then
    set med 200
  endif
  if med eq 200 then
    drop
  endif
end-policy

Applying an RPL Policy to a BGP Neighbor

Policies attach per neighbor and address family with the route-policy command, replacing IOS route-map inbound/outbound keywords:

router bgp 65000
  neighbor 10.0.0.2
    remote-as 65001
    address-family ipv4 unicast
      route-policy FILTER-MARTIANS in
      route-policy ANNOUNCE-CUSTOMER out
    !
  !
!

Editing and Verifying Route Policies

Re-entering a route-policy in configuration mode wipes the existing policy body, so keep your RPL in a text file and paste the full policy when you edit. Verify with the BGP show commands:

RP/0/0/CPU0:router# show running-config route-policy
RP/0/0/CPU0:router# show bgp neighbors 10.0.0.2
RP/0/0/CPU0:router# show bgp ipv4 unicast

Continue with our Cisco prefix-list and route-map BGP filtering guide, BGP communities configuration examples, and IOS XR BGP iBGP/eBGP configuration.

原文链接:https://community.cisco.com/t5/service-providers-knowledge-base/asr9000-xr-understanding-and-using-rpl-route-policy-language/tac-p/3117072