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
Section titled “Diagram”Classes
Section titled “Classes”configuration (iosxr.devices)
Section titled “configuration (iosxr.devices)”| Name | Type | Constraint | Mandatory | Default Value |
|---|---|---|---|---|
| route_policies | List | [route_policies] | No |
route_policies (iosxr.devices.configuration)
Section titled “route_policies (iosxr.devices.configuration)”| Name | Type | Constraint | Mandatory | Default Value |
|---|---|---|---|---|
| name | String | Yes | ||
| rpl | String | Yes |
RPL Data Normalization
Section titled “RPL Data Normalization”RPL YAML Formats
RPL can be expressed in two different formats in YAML:
- 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. - 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.
Example YAML formats
Section titled “Example YAML formats”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-policySample Configuration:
Section titled “Sample Configuration:”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 endifend-policyExample YAML Code:
Section titled “Example YAML Code:”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-policyExample-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-policyExample-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-policyExample-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-policyExample-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