1. AS_Path
The AS_Path attribute has four forms, namely: AS_Sequence, AS_Set, AS_Confed_Sequence and AS_Confed_Set.
- AS_Sequence: It is an ordered set of AS numbers passed on the path to the destination. All ASs passed by the route are recorded in order.
- AS_Set: It is an unordered set of AS numbers passed on the path to the destination. AS_Set is usually used in route aggregation scenarios.
- AS_Confed_Sequence: is an ordered set of sub-ASs in the alliance.
- AS_Confed_Set: It is an unordered set of sub-ASs within the alliance. It is mainly used in the scenario of route aggregation within the alliance.
1. 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 BGP Speaker propagates routes learned from Update messages of other BGP Speakers:
- 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 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.
project |
describe |
---|---|
AS_Set |
No matter how many AS numbers are contained in AS_Set, the length is calculated as 1 during BGP route selection. When configuring the aggregate (BGP) command for manual route aggregation, if the as-set parameter is carried, AS_Set will be generated, otherwise AS_Set will not be generated. When generating AS_Set,
|
AS_Confed_Sequence and AS_Confed_Set |
BGP does not consider AS_Confed_Sequence and AS_Confed_Set when calculating the AS_Path length. |
bestroute as-path-ignore command |
After executing this command, AS_Path comparison is ignored when BGP route selection. |
apply as-path command |
By using this command in the routing policy, the AS number can be cleared, replaced, or appended. Note: The apply as-path command will directly affect the path that network traffic takes, and may also cause loops and routing errors. Please use it with caution. |
peer public-as-only command |
After executing this command, BGP deletes the private AS number and only carries the public AS number when sending Update messages. The private AS number range is 64512~65534. |
peer fake-as command |
After executing this command, BGP can hide the real AS number and use the pseudo AS number to establish neighbor with the peer. If the local end uses a real AS number to establish an EBGP neighbor with the peer, the AS_Path list of the route sent to the neighbor will carry the real AS number. If the local end uses a pseudo AS number to establish an EBGP neighbor with the peer, the AS_Path list of the route sent to the neighbor will only carry the pseudo AS number. |
peer substitute-as command |
After executing this command, when the PE advertises a route to the CE in the specified peer, if the route’s AS_Path contains the same AS number as the CE, it will be replaced with the AS number of the PE before being advertised. Note: peer substitute-as is only applicable to PE devices in BGP MPLS IP/VPN. Improper configuration may cause routing loops, so please use it with caution. |
The comparison of AS_Path can be simply summarized as comparing the number of AS numbers in AS_Sequence. If there is an AS_Set, the length of AS_Path is increased by one. Some of the above commonly used commands will be introduced in detail using examples below.
2. Examples
Experimental topology:
1. The interface IP of each device
[R1]display ip interface brief Interface IP Address/Mask Physical Protocol GigabitEthernet0/0/0 10.0.12.1/24 up up GigabitEthernet0/0/1 10.0.16.1/24 up up LoopBack0 10.0.1.1/32 up up(s) [R2]display ip interface brief Interface IP Address/Mask Physical Protocol GigabitEthernet0/0/0 10.0.12.2/24 up up GigabitEthernet0/0/1 10.0.23.2/24 up up LoopBack0 10.0.2.2/32 up up(s) [R3]display ip interface brief Interface IP Address/Mask Physical Protocol GigabitEthernet0/0/0 10.0.23.3/24 up up GigabitEthernet0/0/1 10.0.34.3/24 up up LoopBack0 10.0.3.3/32 up up(s) [R4]display ip interface brief Interface IP Address/Mask Physical Protocol GigabitEthernet0/0/0 10.0.34.4/24 up up GigabitEthernet0/0/1 10.0.45.4/24 up up LoopBack0 10.0.4.4/32 up up(s) [R5]display ip interface brief Interface IP Address/Mask Physical Protocol GigabitEthernet0/0/0 10.0.45.5/24 up up GigabitEthernet0/0/1 10.0.56.5/24 up up LoopBack0 10.0.5.5/32 up up(s) [R6]display ip interface brief Interface IP Address/Mask Physical Protocol GigabitEthernet0/0/0 10.0.56.6/24 up up GigabitEthernet0/0/1 10.0.16.6/24 up up LoopBack0 10.0.6.6/32 up up(s)
2. Configure BGP and use physical interfaces to establish neighbor relationships
[R1]bgp 100 [R1-bgp]router-id 10.0.1.1 [R1-bgp]peer 10.0.12.2 as-number 500 [R1-bgp]peer 10.0.16.6 as-number 300 [R1-bgp]network 10.0.1.1 32 [R2]bgp 500 -----Create BGP [R2-bgp]router-id 10.0.2.2 [R2-bgp]peer 10.0.12.1 as-number 100 -----Establish neighbor relationship [R2-bgp]peer 10.0.23.3 as-number 500 [R2-bgp]peer 10.0.23.3 next-hop-local -----Change next hop attributes [R3] bgp 500 [R3-bgp]router-id 10.0.3.3 [R3-bgp]peer 10.0.23.2 as-number 500 [R3-bgp]peer 10.0.23.2 next-hop-local [R3-bgp]peer 10.0.34.4 as-number 200 [R4]bgp 200 [R4-bgp]router-id 10.0.4.4 [R4-bgp]peer 10.0.34.3 as-number 500 [R4-bgp]peer 10.0.45.5 as-number 400 [R4-bgp]network 10.0.4.4 32 [R5]bgp 400 [R5-bgp]router-id 10.0.5.5 [R5-bgp]peer 10.0.45.4 as-number 200 [R5-bgp]peer 10.0.56.6 as-number 300 [R6] bgp 300 [R6-bgp]router-id 10.0.6.6 [R6-bgp]peer 10.0.16.1 as-number 100 [R6-bgp]peer 10.0.56.5 as-number 400
3. By checking the BGP route, you can see that there are two routes from R1 to 10.0.4.4. It should be that the AS_Path attribute selects the optimal route based on the least number of ASs passed through:
4. Next we can change the next hop attribute by adding the AS_Path attribute. There are two attributes:
[R1]ip ip-prefix as-path permit 10.0.4.4 32 ----Write a prefix list (customized number) [R1]route-policy as-path permit node 10 ----Write a routing policy (customized number) Info: New Sequence of this List. [R1-route-policy]if-match ip-prefix as-path ---- Use the routing policy area to match the prefix list [R1-route-policy]apply as-path 500 500 additive ----Add AS_Path (custom) (overwrite)----Change the AS path directly [R1-route-policy]q [R1]route-policy as-path permit node 20 Info: New Sequence of this List. [R1-route-policy]q Inject into BGP 10.0.12.2 [R1]bgp 100 [R1-bgp]peer 10.0.12.2 route-policy as-path import
5. After configuring AS_Path, you can find that the next hop attribute changes after adding AS_Path. R4 has the same configuration. You can change the added attribute to (overwrite) —- you can also directly change the AS path.
[R4]ip ip-prefix as-path permit 10.0.1.1 32 [R4]route-policy as-path permit node 10 Info: New Sequence of this List. [R4-route-policy]if-match ip-prefix as-path [R4-route-policy]apply as-path 100 200 300 400 500 overwrite Warning: The AS-Path lists of routes to which this route-policy is applied will be overwritten. Continue? [Y/N]y [R4-route-policy]q [R4]route-policy as-path permit node 20 Info: New Sequence of this List. [R4-route-policy]q [R4]bgp 200 [R4-bgp]peer 10.0.34.3 route-policy as-path import