BGP As-path is a mandatory BGP attribute which has to be sent in every BGP message. BGP as-path prepending is one of the BGP traffic engineering methods which will be explained in detail throughout this post.
What is BGP as-path attribute ? Why BGP as-path attribute is used ?
BGP As-path attribute is mainly used for loop presentation in EBGP. If the receiving AS finds its AS-number anywhere in the AS-path, BGP update is ignored.
Figure -1 BGP as-path attribute loop prevention
In Figure-1 R1 and R4 in AS 100 which are connected to AS 200.
When R2 receives prefixes from R1, it sends to R3 with BGP AS; ‘ AS 100 ‘ . When R3 sends a BGP update to its EBGP neighbor which is R4, it prepends AS 200 and the AS-Path is seen by the R4 as ‘ 200 100 ‘
When you examine BGP tables, at the left always last AS is seen. At the right originator BGP AS is seen.
When R4 receives a BGP update from R3, since its own BGP AS which is AS 100 is in the as-path ( 200 100), R4 doesn’t accept the BGP update.
In some scenarios you may need R4 to accept the prefixes.
For example in MPLS L3 VPN. If EBGP is used as PE-CE protocol in MPLS L3 VPN, R4 and R1 would need to accept the prefixes from each other. There are two ways two overcome the issue. Either on the Service provider site, BGP as-override feature or at the customer site (In this example, R1 and R4) BGP allow-as features are used.
What is BGP As-path prepending ?
BGP As-path prepending is used to influence inbound traffic to the company. Outbound traffic is usually done via BGP local preference attribute or BGP hot-potato routing.
BGP As-path prepending is used in active-standby link scenarios. When there are two BGP neighborship which prefix will be advertised, one link for set of prefixes or maybe all the prefixes can be used as backup. In this case, one way to achieve this setup is using BGP AS-path prepending.
What are the other alternatives for BGP as-path prepending ?
BGP MED attribute is also used to influence incoming traffic to the company. BGP Med attribute is not sent between the providers.
if company has multi home connection to the two Service Providers, those service providers won’t send the MED setting of the company to each other.
Thats why best practice with BGP MED, don’t use it if you have connection to more than one service provider to influence inbound path selection.
Another BGP as-path prepending alternative is BGP Communities. This will be explained in detail with the topology later in the article.
How BGP traffic engineering is achieved with BGP as-path prepending ?
As it is stated in the above, BGP as-path attribute is used to select one link as primary for set of prefixes or all the prefixes of the company.
Figure -2 BGP as-path prepending single ISP
In Figure -2 Customer AS 200 wants to use of the links as backup. 10.0.10.0/24 prefix is sent via backup link with the 3 prepend. Thus AS path is seen through the backup link by the upstream service provider which is AS 100 as ‘ 200 200 200 200 ‘.
Every BGP neighbor of the Service Provider (AS 100) will see only AS 200 without AS path prepend, because internal BGP speaker will chose the best path and that best path will be sent to EBGP neighbor of the Service Provider.
Internal BGP speakers will receive the prefixes from primary path as BGP AS 200 , from backup BGP AS 200 200 200 200 as prepended , thus they will choose the shorter AS Path and will use it.
In this topology BGP MED could be used as well since Customer AS 200 is connected to only one service provider which is AS 100.
Don’t forget that BGP as-path prepending will not effect outbound traffic from the customer to the Service Provider.
So if local preference is not implemented, backup link is still used to send the traffic from customer to the Internet. But from Internet to the company traffic is handled by BGP as-path prepending.
What are the challenges which BGP as-path prepending cannot handle and what are the solutions for incoming BGP path selections ?
There are some challenges with BGP as-path prepending when it is used in multi-homed BGP setup.
Figure -3 BGP As-path prepending multi homed setup
In Figure 3, Customer AS 20 is connected to two Service Providers. Customer is sending 10.0.10.0/24 prefix to both ISP.
They are advertising this prefix to their upstream ISPs and also each other through BGP peering.
AS 30 wants to be used as backup. Thus Customer is sending the 10.0.10.0/24 prefix towards AS30 with As-path prepends. Customer prepends its own AS path with 7 more AS.
You might think that link from AS 30 won’t be used anymore so it will be used as backup. But thats not totally true.
Traffic from their upstream ISPs will go to the AS 10 because all the other ASes over Internet will see the advertisement from AS 30 with lots of prepends. So far so good.
But all the customers of AS 30 will still send the traffic for 10.0.10.0/24 prefix over the link which wants to be used as backup, although AS 30 learns 10.0.10.0/24 prefix over BGP peering link with AS 10 as well, its upstream providers as well.
But important to know that, Service Providers always chooses to send the traffic for their customer prefixes over the customer link first, then peering links, lastly through upstream ISP. Because they want to utilise the customer link as much as possible to charge more money.
Service Providers implement local preference attribute to achieve this. Basic local preference policy could be; Local Pref 100 towards Customer, local pref 90 towards peering link and local pref 80 towards upstream ISP.
With this knowledge we can understand why customer of AS 30 would still use customer link for 10.0.10.0/24 prefix although customer wants that link to be used as backup.
Customer is sending that prefix with AS-path attribute and service provider implements local pref for that prefix. Since local preference attribute is more important in the BGP best path selection process, if the traffic comes to any of the BGP routers of AS 30, it is sent through customer link. Not through BGP peering link with AS 10 or any upstream provider of AS 30.
This problem can be solved with BGP community.
If Customer sends 10.0.10.0/24 prefix with the BGP community which effects local preference value of AS 30, link between customer and AS 30 is not used anymore.
Customer could send the community as 30:70 which reduces the local pref to 70 for the customer prefixes over the customer BGP session, AS 30 would start to use BGP peer link to reach to 10.0.10.0/24 prefix.
As a summary; instead of prepending AS, customer should use BGP community if it has multi homed BGP setup.