BGP routing attribute_as path

BGP attributes

Routing attributes are specific descriptions of routes. All BGP routing attributes can be divided into the following four categories. Common BGP attribute types are shown in Table 1:

  • Well-known mandatory: All BGP devices can recognize this type of attribute and must exist in Update messages. If such attributes are missing, the routing information will be incorrect.

  • Well-known discretionary: All BGP devices can recognize this type of attribute, but it is not required to exist in the Update message. That is, even if this type of attribute is missing, the routing information will not be wrong.

  • Optional transitive: The BGP device does not need to recognize such attributes. If the BGP device does not recognize such attributes, it will still receive such attributes and notify them to other peers.

  • Optional non-transitive: The BGP device does not need to recognize such attributes. If the BGP device does not recognize such attributes, the attribute will be ignored and will not be advertised to other peers.

  • 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.

Topology

R1 basic configuration
<Huawei>system-view
[Huawei]sysname R1

[R1]interface GigabitEthernet 0/0/0
[R1-GigabitEthernet0/0/0]ip address 192.168.13.1 24
[R1-GigabitEthernet0/0/0]q

[R1]interface GigabitEthernet 0/0/1
[R1-GigabitEthernet0/0/1]ip address 192.168.15.1 24
[R1-GigabitEthernet0/0/1]q

[R1]interface LoopBack 0
[R1-LoopBack0]ip address 1.1.1.1 32

Configure BGP
[R1]bgp 100
[R1-bgp]router-id 1.1.1.1
[R1-bgp]peer 192.168.13.3 as-number 300
[R1-bgp]peer 192.168.15.5 as-number 500
[R1-bgp]network 1.1.1.1 32
[R1-bgp]q


Change the length of the Path/ogn path Change the route
[R1]ip ip-prefix as_path permit 2.2.2.2 32
[R1]route-policy as_path permit node 10
[R1-route-policy]if-match ip-prefix as_path
[R1-route-policy]apply as-path 1000 1000 additive
[R1-route-policy]q

[R1]route-policy as_path permit node 20
Info: New Sequence of this List.
[R1-route-policy]q

[R1]bgp 100
[R1-bgp]peer 192.168.15.5 reflect-client
[R1-bgp]peer 192.168.15.5 route-policy as_path import
[R1-bgp]q

Configuration completed results

R2 basic configuration
<Huawei>system-view
[Huawei]sysname R2

[R2]interface GigabitEthernet 0/0/0
[R2-GigabitEthernet0/0/0]ip address 192.168.42.2 24
[R2-GigabitEthernet0/0/0]q

[R2]interface GigabitEthernet 0/0/1
[R2-GigabitEthernet0/0/1]ip address 192.168.26.2 24
[R2-GigabitEthernet0/0/0]q

[R2]interface LoopBack 0
[R2-LoopBack0]ip address 2.2.2.2 32

Configure BGP
[R2]bgp 200
[R2-bgp]router-id 2.2.2.2
[R2-bgp]peer 192.168.26.6 as-number 500
[R2-bgp]peer 192.168.42.4 as-number 400
[R2-bgp]network 2.2.2.2 32





Use overwrite to force rewrite Path/ogn

[R2]ip ip-prefix as_path permit 1.1.1.1 32
[R2]route-policy as_path permit node 10

[R2-route-policy]if-match ip-prefix as_path
[R2-route-policy]apply as-path 300 500 500 100 overwrite
Warning: The AS-Path lists of routes to which this route-policy is applied will
be overwritten. Continue? [Y/N]y
[R2-route-policy]q
[R2]route-policy as_path permit node 20


[R2]bgp 200
[R2-bgp]peer 192.168.26.6 route-policy as_path import
[R2-bgp]q

R3 basic configuration
<Huawei>system-view
[Huawei]sysname R3

[R3]interface GigabitEthernet 0/0/0
[R3-GigabitEthernet0/0/0]ip address 192.168.13.3 24
[R3-GigabitEthernet0/0/0]q

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

Configure BGP
[R3] bgp 300
[R3-bgp]router-id 3.3.3.3
[R3-bgp]peer 192.168.13.1 as-number 100
[R3-bgp]peer 192.168.34.4 as-number 400
R4 basic configuration
<Huawei>system-view
[Huawei]sysname R4

[R4]interface GigabitEthernet 0/0/0
[R4-GigabitEthernet0/0/0]ip address 192.168.34.4 24
[R4-GigabitEthernet0/0/0]q

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

BGP configuration
[R4]bgp 400
[R4-bgp]router-id 4.4.4.4
[R4-bgp]peer 192.168.34.3 as-number 300
[R4-bgp]peer 192.168.42.2 as-number 200
R5 basic configuration
<Huawei>system-view
[Huawei]sysname R5

[R5]interface GigabitEthernet 0/0/0
[R5-GigabitEthernet0/0/0]ip address 192.168.65.5 24
[R5-GigabitEthernet0/0/0]q

[R5]interface GigabitEthernet 0/0/1
[R5-GigabitEthernet0/0/1]ip address 192.168.15.5 24

Configure BGP
[R5] bgp 500
[R5-bgp]router-id 5.5.5.5
[R5-bgp]peer 192.168.15.1 as-number 100
[R5-bgp]peer 192.168.65.6 as-number 500
[R5-bgp]peer 192.168.65.6 next-hop-local //R5 R6 next hop needs to be specified local
R6 basic configuration
<Huawei>system-view
[Huawei]sysname R6

[R6]interface GigabitEthernet 0/0/0
[R6-GigabitEthernet0/0/0]ip address 192.168.26.6 24
[R6-GigabitEthernet0/0/0]q

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

Configure BGP
[R6] bgp 500
[R6-bgp]router-id 6.6.6.6
[R6-bgp]peer 192.168.65.5 as-number 500
[R6-bgp]peer 192.168.26.2 as-number 200
[R6-bgp]peer 192.168.65.5 next-hop-local //R5 R6 next hop needs to be specified local