Help us improve your experience.

Let us know what you think.

Do you have time for a two-minute survey?

Navigation

Example: Ignoring the AS Path Attribute When Selecting the Best Path

If multiple BGP routes to the same destination exist, BGP selects the best path based on the route attributes of the paths. One of the route attributes that affects the best-path decision is the length of the AS paths of each route. Routes with shorter AS paths are preferred over those with longer AS paths. Although not typically practical, some scenarios might require that the AS path length be ignored in the route selection process. This example shows how to configure a routing device to ignore the AS path attribute.

Requirements

No special configuration beyond device initialization is required before you configure this example.

Overview

On externally connected routing devices, the purpose of skipping the AS path comparison might be to force an external BGP (EBGP) versus internal BGP (IBGP) decision to remove traffic from your network as soon as possible. On internally connected routing devices, you might want your IBGP-only routers to default to the local externally connected gateway. The local IBGP-only (internal) routers skip the AS path comparison and move down the decision tree to use the closest interior gateway protocol (IGP) gateway (lowest IGP metric). Doing this might be an effective way to force these routers to use a LAN connection instead of their WAN connection.

Caution: When you include the as-path-ignore statement on a routing device in your network, you might need to include it on all other BGP-enabled devices in your network to prevent routing loops and convergence issues. This is especially true for IBGP path comparisons.

In this example, Device R2 is learning about the loopback interface address on Device R4 (4.4.4.4/32) from Device R1 and Device R3. Device R1 is advertising 4.4.4.4/32 with an AS-path of 1 5 4, and Device R3 is advertising 4.4.4.4/32 with an AS-path of 3 4. Device R2 selects the path for 4.4.4.4/32 from Device R3 as the best path because the AS path is shorter than the AS path from Device R1.

This example modifies the BGP configuration on Device R2 so that the AS-path length is not used in the best-path selection.

Device R1 has a lower router ID (1.1.1.1) than Device R3 (1.1.1.1). If all other path selection criteria are equal (or, as in this case, ignored), the route learned from Device R1 is used. Because the AS-path attribute is being ignored, the best path is toward Device R1 because of its lower router ID value.

Figure 1 shows the sample topology.

Figure 1: Topology for Ignoring the AS-Path Lengh

Topology for Ignoring the AS-Path
Lengh

Configuration

CLI Quick Configuration

To quickly configure this example, copy the following commands, paste them into a text file, remove any line breaks, change any details necessary to match your network configuration, and then copy and paste the commands into the CLI at the [edit] hierarchy level.

Device R1

set interfaces fe-1/2/0 unit 1 family inet address 192.168.10.1/24set interfaces fe-1/2/1 unit 10 family inet address 192.168.50.2/24set interfaces lo0 unit 1 family inet address 1.1.1.1/32set protocols bgp group ext type externalset protocols bgp group ext export send-directset protocols bgp group ext export send-staticset protocols bgp group ext export send-localset protocols bgp group ext neighbor 192.168.10.2 peer-as 2set protocols bgp group ext neighbor 192.168.50.1 peer-as 5set policy-options policy-statement send-direct term 1 from protocol directset policy-options policy-statement send-direct term 1 then acceptset policy-options policy-statement send-local term 1 from protocol localset policy-options policy-statement send-local term 1 then acceptset policy-options policy-statement send-static term 1 from protocol staticset policy-options policy-statement send-static term 1 then acceptset routing-options static route 192.168.20.0/24 next-hop 192.168.10.2set routing-options static route 192.168.30.0/24 next-hop 192.168.10.2set routing-options static route 192.168.40.0/24 next-hop 192.168.50.1set routing-options router-id 1.1.1.1set routing-options autonomous-system 1

Device R2

set interfaces fe-1/2/0 unit 2 family inet address 192.168.10.2/24set interfaces fe-1/2/1 unit 3 family inet address 192.168.20.2/24set interfaces lo0 unit 2 family inet address 2.2.2.2/32set protocols bgp path-selection as-path-ignoreset protocols bgp group ext type externalset protocols bgp group ext export send-directset protocols bgp group ext export send-staticset protocols bgp group ext export send-localset protocols bgp group ext neighbor 192.168.10.1 peer-as 1set protocols bgp group ext neighbor 192.168.20.1 peer-as 3set policy-options policy-statement send-direct term 1 from protocol directset policy-options policy-statement send-direct term 1 then acceptset policy-options policy-statement send-local term 1 from protocol localset policy-options policy-statement send-local term 1 then acceptset policy-options policy-statement send-static term 1 from protocol staticset policy-options policy-statement send-static term 1 then acceptset routing-options static route 192.168.50.0/24 next-hop 192.168.10.1set routing-options static route 192.168.40.0/24 next-hop 192.168.10.1set routing-options static route 192.168.30.0/24 next-hop 192.168.20.1set routing-options router-id 2.2.2.2set routing-options autonomous-system 2

Device R3

set interfaces fe-1/2/0 unit 4 family inet address 192.168.20.1/24set interfaces fe-1/2/1 unit 5 family inet address 192.168.30.1/24set interfaces lo0 unit 3 family inet address 1.1.1.1/32set protocols bgp group ext type externalset protocols bgp group ext export send-directset protocols bgp group ext export send-staticset protocols bgp group ext export send-localset protocols bgp group ext neighbor 192.168.20.2 peer-as 2set protocols bgp group ext neighbor 192.168.30.2 peer-as 4set policy-options policy-statement send-direct term 1 from protocol directset policy-options policy-statement send-direct term 1 then acceptset policy-options policy-statement send-local term 1 from protocol localset policy-options policy-statement send-local term 1 then acceptset policy-options policy-statement send-static term 1 from protocol staticset policy-options policy-statement send-static term 1 then acceptset routing-options static route 192.168.10.0/24 next-hop 192.168.20.2set routing-options static route 192.168.50.0/24 next-hop 192.168.20.2set routing-options static route 192.168.40.0/24 next-hop 192.168.30.2set routing-options router-id 3.3.3.3set routing-options autonomous-system 3

Device R4

set interfaces fe-1/2/0 unit 6 family inet address 192.168.30.2/24set interfaces fe-1/2/1 unit 7 family inet address 192.168.40.1/24set interfaces lo0 unit 4 family inet address 4.4.4.4/32set protocols bgp group ext type externalset protocols bgp group ext export send-directset protocols bgp group ext export send-staticset protocols bgp group ext export send-localset protocols bgp group ext neighbor 192.168.30.1 peer-as 3set protocols bgp group ext neighbor 192.168.40.2 peer-as 5set policy-options policy-statement send-direct term 1 from protocol directset policy-options policy-statement send-direct term 1 then acceptset policy-options policy-statement send-local term 1 from protocol localset policy-options policy-statement send-local term 1 then acceptset policy-options policy-statement send-static term 1 from protocol staticset policy-options policy-statement send-static term 1 then acceptset routing-options static route 192.168.10.0/24 next-hop 192.168.40.2set routing-options static route 192.168.50.0/24 next-hop 192.168.40.2set routing-options static route 192.168.40.0/24 next-hop 192.168.30.1set routing-options router-id 4.4.4.4set routing-options autonomous-system 4

Device R5

set interfaces fe-1/2/0 unit 8 family inet address 192.168.40.2/24set interfaces fe-1/2/1 unit 9 family inet address 192.168.50.1/24set interfaces lo0 unit 5 family inet address 5.5.5.5/32set protocols bgp group ext type externalset protocols bgp group ext export send-directset protocols bgp group ext export send-staticset protocols bgp group ext export send-localset protocols bgp group ext neighbor 192.168.40.1 peer-as 4set protocols bgp group ext neighbor 192.168.50.2 peer-as 1set policy-options policy-statement send-direct term 1 from protocol directset policy-options policy-statement send-direct term 1 then acceptset policy-options policy-statement send-local term 1 from protocol localset policy-options policy-statement send-local term 1 then acceptset policy-options policy-statement send-static term 1 from protocol staticset policy-options policy-statement send-static term 1 then acceptset routing-options static route 192.168.10.0/24 next-hop 192.168.50.2set routing-options static route 192.168.20.0/24 next-hop 192.168.50.2set routing-options static route 192.168.30.0/24 next-hop 192.168.40.1set routing-options router-id 5.5.5.5set routing-options autonomous-system 5

Configuring Device R2

Step-by-Step Procedure

The following example requires you to navigate various levels in the configuration hierarchy. For information about navigating the CLI, see Using the CLI Editor in Configuration Mode in the CLI User Guide.

To configure Device R2:

  1. Configure the interfaces.
    [edit interfaces]user@R2# set fe-1/2/0 unit 2 family inet address 192.168.10.2/24user@R2# set fe-1/2/1 unit 3 family inet address 192.168.20.2/24user@R2# set lo0 unit 2 family inet address 2.2.2.2/32
  2. Configure EBGP.
    [edit protocols bgp group ext]user@R2# set type externaluser@R2# set export send-directuser@R2# set export send-staticuser@R2# set export send-localuser@R2# set neighbor 192.168.10.1 peer-as 1user@R2# set neighbor 192.168.20.1 peer-as 3
  3. Configure the autonomous system (AS) path attribute to be ignored in the Junos OS path selection algorithm.
    [edit protocols bgp]user@R2# set path-selection as-path-ignore
  4. Configure the routing policy.
    [edit policy-options]user@R2# set policy-statement send-direct term 1 from protocol directuser@R2# set policy-statement send-direct term 1 then acceptuser@R2# set policy-statement send-local term 1 from protocol localuser@R2# set policy-statement send-local term 1 then acceptuser@R2# set policy-statement send-static term 1 from protocol staticuser@R2# set policy-statement send-static term 1 then accept
  5. Configure some static routes.
    [edit routing-options static]user@R2# set route 192.168.50.0/24 next-hop 192.168.10.1user@R2# set route 192.168.40.0/24 next-hop 192.168.10.1user@R2# set route 192.168.30.0/24 next-hop 192.168.20.1
  6. Configure the autonomous system (AS) number and the router ID.
    [edit routing-options]user@R2# set router-id 2.2.2.2user@R2# set autonomous-system 2

Results

From configuration mode, confirm your configuration by entering the show interfaces, show policy-options, show protocols, and show routing-options commands. If the output does not display the intended configuration, repeat the instructions in this example to correct the configuration.

user@R2# show interfacesfe-1/2/0 {unit 2 {family inet {address 192.168.10.2/24;}}}fe-1/2/1 {unit 3 {family inet {address 192.168.20.2/24;}}}lo0 {unit 2 {family inet {address 2.2.2.2/32;}}}
user@R2# show policy-optionspolicy-statement send-direct {term 1 {from protocol direct;then accept;}}policy-statement send-local {term 1 {from protocol local;then accept;}}policy-statement send-static {term 1 {from protocol static;then accept;}}
user@R2# show protocolsbgp {path-selection as-path-ignore;group ext {type external;export [ send-direct send-static send-local ];neighbor 192.168.10.1 {peer-as 1;}neighbor 192.168.20.1 {peer-as 3;}}}
user@R21# show routing-optionsstatic {route 192.168.50.0/24 next-hop 192.168.10.1;route 192.168.40.0/24 next-hop 192.168.10.1;route 192.168.30.0/24 next-hop 192.168.20.1;}router-id 2.2.2.2;autonomous-system 2;

If you are done configuring the device, enter commit from configuration mode. Repeat the configuration on the other devices in the network, changing the interface names and IP addresses, as needed.

Verification

Confirm that the configuration is working properly.

Checking the Neighbor Status

Purpose

Make sure that from Device R2, the active path to get to AS 4 is through AS 1 and AS 5, not through AS 3.

Note: To verify the functionality of the as-path-ignore statement, you might need to run the restart routing command to force reevaluation of the active path. This is because for BGP, if both paths are external, the Junos OS behavior is to prefer the currently active path. This behavior helps to minimize route-flapping. Use caution when restarting the routing protocol process in a production network.

Action

From operational mode, enter the restart routing command.

user@R2> restart routing
Routing protocols process started, pid 49396

From operational mode, enter the show route 4.4.4.4 protocol bgp command.

user@R2> show route 4.4.4.4 protocol bgp
inet.0: 12 destinations, 25 routes (12 active, 0 holddown, 4 hidden)
+ = Active Route, - = Last Active, * = Both

4.4.4.4/32         *[BGP/170] 00:00:12, localpref 100
                      AS path: 1 5 4 I
                    > to 192.168.10.1 via fe-1/2/0.2
                    [BGP/170] 00:00:08, localpref 100
                      AS path: 3 4 I
                    > to 192.168.20.1 via fe-1/2/1.3

Meaning

The asterisk (*) is next to the path learned from R1, meaning that this is the active path. The AS path for the active path is 1 5 4, which is longer than the AS path (3 4) for the nonactive path learned from Router R3.

Published: 2012-12-08