Skip to content

Route Policies

Route policies define the logic for filtering and manipulating routes on IOS-XR devices using Route Policy Language (RPL). They are applied at BGP neighbor attach points (import/export), redistribution boundaries, and other routing protocol interfaces to control route acceptance, modification of attributes such as local-preference, MED, and communities, and route advertisement.

Diagram
NameTypeConstraintMandatoryDefault Value
route_policiesList[route_policies]No

route_policies (iosxr.devices.configuration)

Section titled “route_policies (iosxr.devices.configuration)”
NameTypeConstraintMandatoryDefault Value
nameStringYes
rplStringYes

RPL YAML Formats

RPL can be expressed in two different formats in YAML:

  1. Inline format - Uses escaped newline characters (\n) within a quoted string. This matches how the device stores RPL data in the YANG model. Compact but harder to read for complex policies.
  2. Multi-line format - Uses the YAML literal block scalar (|) to preserve newlines. This closely mirrors the RPL CLI output on the device. More readable for complex policies with conditional logic.

Both formats produce identical results and can be used interchangeably. The normalization layer handles both before sending to the device.

Inline format:

route_policies:
- name: "CUSTOMER_A_IMPORT"
rpl: "route-policy CUSTOMER_A_IMPORT\n if destination in CUSTOMER_A_PREFIXES then\n set local-preference 150\n pass\n else\n drop\n endif\nend-policy\n"

Multi-line format:

route_policies:
- name: "CUSTOMER_A_IMPORT"
rpl: |
route-policy CUSTOMER_A_IMPORT
if destination in CUSTOMER_A_PREFIXES then
set local-preference 150
pass
else
drop
endif
end-policy

The following configuration describes how to configure a BGP inbound route policy on a Cisco IOS-XR device via CLI.

route-policy CUSTOMER_A_IMPORT
if destination in CUSTOMER_A_PREFIXES then
set local-preference 150
set extcommunity rt (65000:1001) additive
pass
else
drop
endif
end-policy

Example-1: BGP inbound policy with prefix filtering and RT tagging.

iosxr:
devices:
- name: router-1
host: 10.10.10.1:57400
configuration:
route_policies:
- name: "CUSTOMER_A_IMPORT"
rpl: |
route-policy CUSTOMER_A_IMPORT
if destination in CUSTOMER_A_PREFIXES then
set local-preference 150
set extcommunity rt (65000:1001) additive
pass
else
drop
endif
end-policy

Example-2: BGP outbound policy with community-based filtering and MED (inline).

iosxr:
devices:
- name: router-1
host: 10.10.10.1:57400
configuration:
route_policies:
- name: "PEER_EXPORT"
rpl: "route-policy PEER_EXPORT\n if community matches-any CUSTOMER_COMMUNITIES then\n set med 100\n pass\n else\n drop\n endif\nend-policy\n"

Example-3: BGP local-preference policy for primary/backup path selection.

iosxr:
devices:
- name: router-1
host: 10.10.10.1:57400
configuration:
route_policies:
- name: "PRIMARY_PATH"
rpl: |
route-policy PRIMARY_PATH
if as-path in TRANSIT_AS_PATHS then
set local-preference 200
elseif community matches-any TE_COMMUNITIES then
set local-preference 150
else
set local-preference 100
endif
pass
end-policy

Example-4: AS path prepending for outbound traffic engineering.

iosxr:
devices:
- name: router-1
host: 10.10.10.1:57400
configuration:
route_policies:
- name: "BACKUP_PEER_OUT"
rpl: |
route-policy BACKUP_PEER_OUT
if destination in CUSTOMER_A_PREFIXES then
prepend as-path 65000 3
set community (65000:666) additive
endif
pass
end-policy

Example-5: OSPF to BGP redistribution with tag-based filtering.

iosxr:
devices:
- name: router-1
host: 10.10.10.1:57400
configuration:
route_policies:
- name: "OSPF_TO_BGP_REDIST"
rpl: |
route-policy OSPF_TO_BGP_REDIST
if tag in OSPF_REDIST_TAGS then
set community (65000:500)
set med 200
pass
else
drop
endif
end-policy

Example-6: Simple pass-all policy for iBGP sessions.

iosxr:
devices:
- name: router-1
host: 10.10.10.1:57400
configuration:
route_policies:
- name: "IBGP_PASS_ALL"
rpl: |
route-policy IBGP_PASS_ALL
pass
end-policy