BGP path selection–AS_Path

  • AS_Path attribute

    The AS_Path attribute records all the AS numbers that a route passes through from the local to the destination address in vector order. When receiving a route, if the device finds that the AS number is in the AS_Path list, it will not receive the route, thus avoiding inter-AS routing loops.

    When the BGP Speaker broadcasts the routes introduced by itself:

    • When the BGP Speaker advertises this route to the EBGP peer, it creates an AS_Path list carrying the local AS number in the Update message.

    • When the BGP Speaker advertises this route to the IBGP peer, an empty AS_Path list is created in the Update message.

    When BGP Speaker propagates routes learned from Update messages of other BGP Speakers:

    • When the BGP Speaker advertises this route to the EBGP peer, it will add the local AS number to the front (leftmost) of the AS_Path list. The BGP device that receives this route can know the AS it needs to pass to reach the destination address based on the AS_Path attribute. The adjacent AS number closest to the local AS is listed first, and the other AS numbers are arranged in sequence.

    • When the BGP Speaker advertises this route to the IBGP peer, the AS_Path attribute related to this route will not be changed.

Experimental topology diagram

Experimental steps

All router IP configurations

R1 IP configuration

<Huawei>system-view
Enter system view, return user view with Ctrl + Z.
[Huawei]sysname R1
[R1]undo info-center enable
Info: Information center is disabled.

[R1]interface GigabitEthernet 0/0/0
[R1-GigabitEthernet0/0/0]ip address 192.168.1.1 24
[R1-GigabitEthernet0/0/0]quit

[R1]interface GigabitEthernet 0/0/1
[R1-GigabitEthernet0/0/1]ip address 192.168.2.1 24
[R1-GigabitEthernet0/0/1]quit

[R1]interface LoopBack 0
[R1-LoopBack0]ip address 172.16.1.1 32
[R1-LoopBack0]quit

R2 IP configuration

<Huawei>system-view
Enter system view, return user view with Ctrl + Z.
[Huawei]sysname R2
[R2]undo info-center enable
Info: Information center is disabled.

[R2]interface GigabitEthernet 0/0/0
[R2-GigabitEthernet0/0/0]ip address 192.168.6.2 24
[R2-GigabitEthernet0/0/0]quit

[R2]interface GigabitEthernet 0/0/1
[R2-GigabitEthernet0/0/1]ip address 192.168.4.2 24
[R2-GigabitEthernet0/0/1]quit
\t
[R2]interface LoopBack 0
[R2-LoopBack0]ip address 172.16.2.2 32
[R2-LoopBack0]quit

R3 IP configuration

<Huawei>system-view
Enter system view, return user view with Ctrl + Z.
[Huawei]sysname R3
[R3]undo info-center enable
Info: Information center is disabled.

[R3]interface GigabitEthernet 0/0/0
[R3-GigabitEthernet0/0/0]ip address 192.168.3.1 24
[R3-GigabitEthernet0/0/0]quit

[R3]interface GigabitEthernet 0/0/1
[R3-GigabitEthernet0/0/1]ip address 192.168.2.2 24
[R3-GigabitEthernet0/0/1]quit

R4 IP configuration

<Huawei>system-view
Enter system view, return user view with Ctrl + Z.
[Huawei]sysname R4
[R4]undo info-center enable
Info: Information center is disabled.
\t
[R4]interface GigabitEthernet 0/0/0
[R4-GigabitEthernet0/0/0]ip address 192.168.4.1 24
[R4-GigabitEthernet0/0/0]quit

[R4]interface GigabitEthernet 0/0/1
[R4-GigabitEthernet0/0/1]ip address 192.168.3.2 24
[R4-GigabitEthernet0/0/1]quit

R5 IP configuration

<Huawei>system-view
Enter system view, return user view with Ctrl + Z.
[Huawei]sysname R5
[R5]undo info-center enable
Info: Information center is disabled.
\t
[R5]interface GigabitEthernet 0/0/0
[R5-GigabitEthernet0/0/0]ip address 192.168.1.2 24
[R5-GigabitEthernet0/0/0]quit

[R5]interface g0/0/1
[R5-GigabitEthernet0/0/1]ip address 192.168.5.1 24
[R5-GigabitEthernet0/0/1]quit

R6 IP configuration

<Huawei>system-view
Enter system view, return user view with Ctrl + Z.
[Huawei]sysname R6
[R6]undo info-center enable
Info: Information center is disabled.

[R6]interface GigabitEthernet 0/0/0
[R6-GigabitEthernet0/0/0]ip address 192.168.5.2 24
[R6-GigabitEthernet0/0/0]quit

[R6]interface GigabitEthernet 0/0/1
[R6-GigabitEthernet0/0/1]ip address 192.168.6.1 24
[R6-GigabitEthernet0/0/1]quit




All router BGP configuration

R1 BGP configuration

[R1]bgp 100 create AS100
[R1-bgp]router-id 172.16.1.1 Specify router-id
[R1-bgp]peer 192.168.1.2 as-number 500 specifies the physical interface neighbor, located on AS500
[R1-bgp]peer 192.168.2.2 as-number 300 specifies the physical interface neighbor, located on AS300
[R1-bgp]network 172.16.1.1 32 Inject loopback 0 into bgp100
[R1-bgp]quit

R2 BGP configuration

[R2]bgp 200
[R2-bgp]router-id 172.16.2.2
[R2-bgp]peer 192.168.4.1 as-number 400
[R2-bgp]peer 192.168.6.1 as-number 500
[R2-bgp]network 172.16.2.2 32
[R2-bgp]quit

R3 BGP configuration

[R3] bgp 300
[R3-bgp]router-id 172.16.3.3
[R3-bgp]peer 192.168.2.1 as-number 100
[R3-bgp]peer 192.168.3.2 as-number 400
[R3-bgp]quit

R4 BGP configuration

[R4]bgp 400
[R4-bgp]router-id 172.16.4.4
[R4-bgp]peer 192.168.3.1 as-number 300
[R4-bgp]peer 192.168.4.2 as-number 200
[R4-bgp]quit

R5 BGP configuration

[R5] bgp 500
[R5-bgp]router-id 172.16.5.5
[R5-bgp]peer 192.168.5.2 as-number 500
[R5-bgp]peer 192.168.5.2 next-hop-local
[R5-bgp]peer 192.168.1.1 as-number 100
[R5-bgp]quit

R6 BGP configuration

[R6] bgp 500
[R6-bgp]router-id 172.16.6.6
[R6-bgp]peer 192.168.5.1 as-number 500
[R6-bgp]peer 192.168.5.1 next-hop-local
[R6-bgp]peer 192.168.6.2 as-number 200
[R6-bgp]quit

R1 prefix list configuration

R1 prefix list configuration

[R1]ip ip-prefix as_path permit 172.16.2.2 32 Write a prefix list to match the route of the R2 loopback interface
[R1]route-policy as_path permit node 10 Write a routing policy named as_path
Info: New Sequence of this List.
[R1-route-policy]if-match ip-prefix as_path if it matches the prefix list above
[R1-route-policy]apply as-path 500 500 additive will add path 500 500
[R1-route-policy]quit
[R1]route-policy as_path permit node 20 Finally, write a prefix list as the end
Info: New Sequence of this List.
[R1-route-policy]quit
 
[R1]bgp 100
[R1-bgp]peer 192.168.1.2 route-policy as_path import inject the above written
[R1-bgp]quit

Before configuring the prefix list, the next hop 192.168.1.2 to 172.16.2.2 is the optimal route because it only passes through AS500 and AS200.

After configuration, the next hop AS_Path and two AS500s are added, and 192.168.2.2 becomes the optimal route.

R2 prefix list configuration

R2 prefix list configuration

[R2]ip ip-prefix as_path permit 172.16.1.1 32
[R2]route-policy as_path permit node 10
Info: New Sequence of this List.
[R2-route-policy]if-match ip-prefix as_path if it matches the prefix list written above
[R2-route-policy]apply as-path 300 400 400 100 overwrite then modify the as-path path to 300 400 400 100
Warning: The AS-Path lists of routes to which this route-policy is applied will
be overwritten. Continue? [Y/N]y
[R2-route-policy]quit
[R2]route-policy as_path permit node 20
Info: New Sequence of this List.
[R2-route-policy]quit
\t
[R2]bgp 200
[R2-bgp]peer 192.168.6.1 route-policy as_path import inject the above written
[R2-bgp]quit

Before configuring the prefix list, the optimal next hop to 172.16.1.1 is 192.168.6.1

After configuration, the AS_Path of the next hop 192.168.6.1 is modified, and the next hop 192.168.4.1 becomes the optimal route.