Understanding BGP Best Path Selection &..
Understanding BGP Best Path Selection &..
Cisco Support Community / Network Infrastructure / Network Infrastructure Documents / Understanding BGP Best Path Selection &... Options
All community
Introduction
This document outlines the BGP best path selection algorithm, and covers speci c con guration examples on how to manipulate
BGP’s best path decision based on di erent attributes.
Initial Topology
The following topology will be referenced for the entirety of this document unless otherwise stated. EIGRP is being used as the
underlying IGP for basic connectivity.
In the topology above R1 is receiving a similar BGP route (172.16.1.0/24) via R2 and R3. Prior to any user manipulation, R1 prefers
the path advertised from R2 over the path advertised from R3. This can be seen in the following output:
R1#sh ip bgp
https://supportforums.cisco.com/t5/network-infrastructure-documents/understanding-bgp-best-path-selection-manipulation/ta-p/3150576 1/13
12/3/2017 Understanding BGP Best Path Selection &... - Cisco Support Community
The '>' shown in the output above indicates that the path with a next hop of 12.12.12.2 (R2) is the current best path.
Advertised to update-groups:
Refresh Epoch 1
200 300
Refresh Epoch 1
200 300
R1#
The above output further illustrates that the path with a next hop address of 12.12.12.2 is currently being chosen as 'best', as well
as the BGP path attributes associated to the paths that are being compared.
Once R1 has selected the best path it performs a recursive routing lookup on the associated next hop address. In this case the next
hop address is 12.12.12.2, so the lookup will result in a next hop interface of FastEthernet0/0.
https://supportforums.cisco.com/t5/network-infrastructure-documents/understanding-bgp-best-path-selection-manipulation/ta-p/3150576 2/13
12/3/2017 Understanding BGP Best Path Selection &... - Cisco Support Community
Once the lookup has been done for the Next Hop Address we now have the associated next hop interface which is installed for the
CEF entry:
172.16.1.0/24
The default Best Path Selection Algorithm includes the following steps:
1. Compare Weight
The path with the highest weight is preferred. If the weight is identical, move on to step 2.
This path attribute is only locally signi cant. If you change the weight on one router, it will not a ect any other router within the
Autonomous System. This is a Cisco Proprietary feature.
The path with the highest local preference is preferred. If the local preference is identical, move on to step 3.
This path attribute is not locally signi cant. If you change the local preference on one router, it will a ect other routers within the
Autonomous System.
Any path that has been originated on a local router will be preferred over any paths learned from a BGP Peer. If no locally originated
pre x exists in the BGP table for the paths being compared, move on to step 4.
In Cisco IOS this step is implemented by associating a weight of 32768 to any pre xes advertised into BGP on the local router.
For example, when R4 advertised the 172.16.1.0/24 pre x into BGP with the command network 172.16.1.0 mask 255.255.255.0
it automatically added a weight of 32768 to that pre x in the BGP table. This can be seen from the following output:
Advertised to update-groups:
Refresh Epoch 1
Local
https://supportforums.cisco.com/t5/network-infrastructure-documents/understanding-bgp-best-path-selection-manipulation/ta-p/3150576 3/13
12/3/2017 Understanding BGP Best Path Selection &... - Cisco Support Community
Origin IGP, metric 0, localpref 100, weight 32768, valid, sourced, local, best
This means that R4 will prefer its next hop address for the 172.16.1.0/24 subnet, regardless of similar paths learned via its BGP
peers.
4. Compare AS Path
The path with the shortest AS Path is preferred. If the AS Path is identical in length, move on to step 5.
5. Compare Origin
This step in the Best Path Selection process compares how BGP learned about a path originally. There are 3 origin codes:
IGP - the path was learned by BGP via the network statement and is interior to the originating Autonomous System
INCOMPLETE - the path was learned BGP in an unknown fashion, typically via Redistribution.
The path with the lowest MED is preferred. This check is only done if the rst hop AS is identical in the paths being compared. If
the rst hop AS is di erent or the MED is identical, move on to step 7.
7. Compare Neighbor Type
Paths learned from eBGP peers are preferred over paths learned from iBGP peers. If all paths were learned from the same type of
peer, move on to step 8. If the best path is selected during this step, skip step 8 and move on to step 9.
8. IGP Metric
BGP advertises a pre x and a next hop address with any path. The path with the lower IGP metric to the associated next hop
address is preferred. If the IGP metrics are identical on all paths, move on to step 9.
9. Are Multiple Paths Allowed?
BGP by default will only install one path as best. If you con gure the maximum-paths command to allow more than one path to be
installed, BGP will use the IGP to load balance to the associated destination pre x.
At this point if the best path has not been selected, move on to step 10.
10. Compare Route Age
When both paths are learned from eBGP peers, BGP prefers the route that was learned first.
The logic is that the longer a route has been in the BGP Table, the more stable that path must be. This does not apply to iBGP
routes.
11. Compare Neighbor's Router-ID
Prefer the path that is learned from the peer with the lower BGP Router-ID. If the Router-ID is identical, move on to step 12.
12. Compare Cluster List Length
The path with the minimum Cluster List Length is preferred. (This only comes into play in BGP Route-Re ector environments)
https://supportforums.cisco.com/t5/network-infrastructure-documents/understanding-bgp-best-path-selection-manipulation/ta-p/3150576 4/13
12/3/2017 Understanding BGP Best Path Selection &... - Cisco Support Community
This is the catch-all rule in the best path selection process. The path with the lower peer address (the IP address con gured with
the neighbor statement) is preferred. You cannot con gure multiple neighbors with the same IP address, so it is impossible for this
step to result in a tie.
- Weight
- Local Preference
- AS Path
- MED
NOTE: All best path manipulation covered in this section will be done on a per neighbor basis. Altering path attributes per
prefix is not discussed to reduce complexity.
In each of the following examples BGP has chosen R2 as the preferred next hop to the 172.16.1.0/24 subnet prior to any user
con guration.
Advertised to update-groups:
Refresh Epoch 1
200 300
Refresh Epoch 1
200 300
Manipulating WEIGHT
R1's weight can be altered to prefer the next hop address of 13.13.13.3 for the 172.16.1.0/24 pre x. The following example uses
the weight keyword to do so, instead of setting the value with a route-map.
On R1:
https://supportforums.cisco.com/t5/network-infrastructure-documents/understanding-bgp-best-path-selection-manipulation/ta-p/3150576 5/13
12/3/2017 Understanding BGP Best Path Selection &... - Cisco Support Community
Here we con gure a WEIGHT of 1 to all pre xes learned from the neighbor 13.13.13.3:
R1#conf t
R1(config-router)#end
R1#
The Pre xes learned from R3 must be updated for this con guration to take a ect. You can request a route refresh from R3 to
accomplish this with the command clear ip bgp 13.13.13.3 soft in.
Now when BGP goes to compare the Best Path Attributes of the two known paths the rst thing that is checked is weight. Since the
weight of the R3 path is 1, and the weight of the R2 path is 0 (by default) R1 prefers the path with a next hop address of
13.13.13.3.
Advertised to update-groups:
Refresh Epoch 2
200 300
Refresh Epoch 2
200 300
R1#
Weight is only illustrated in the show ip bgp output when a value is present. The Path with a next hop of 12.12.12.2 does not
illustrate the weight in this example because no value has been set by the user.
The next hop interface for tra c destined to the 172.16.1.0/24 pre x is now updated to FastEthernet0/1.
172.16.1.0/24
https://supportforums.cisco.com/t5/network-infrastructure-documents/understanding-bgp-best-path-selection-manipulation/ta-p/3150576 6/13
12/3/2017 Understanding BGP Best Path Selection &... - Cisco Support Community
R1#
R1's local preference can be altered to prefer the next hop address of 13.13.13.3 for the 172.16.1.0/24 pre x. The following
example uses a route-map to set the value.
On R1:
Here we con gure a Local Preference of 101 (the default is 100) to all pre xes learned from the neighbor 13.13.13.3:
R1#
R1#conf t
R1(config-route-map)#exit
R1(config)#
R1(config-router)#end
R1#
Since the weight of both paths are identical, BGP then checks the local preference to determine which path is best. Since the path
learned from R3 now has a higher local preference, it is preferred:
Advertised to update-groups:
Refresh Epoch 2
200 300
Refresh Epoch 3
200 300
R1#
https://supportforums.cisco.com/t5/network-infrastructure-documents/understanding-bgp-best-path-selection-manipulation/ta-p/3150576 7/13
12/3/2017 Understanding BGP Best Path Selection &... - Cisco Support Community
The next hop interface for tra c destined to the 172.16.1.0/24 pre x is now updated to FastEthernet0/1.
172.16.1.0/24
R1#
R1's AS Path can be altered to prefer the next hop address of 13.13.13.3 for the 172.16.1.0/24 pre x.The following example uses
a route-map to prepend additional hops onto the AS Path of the path learned from R2.
On R1:
Here we con gure an AS Path with 2 additional hops for all of pre xes learned from the neighbor 12.12.12.2:
R1#
R1#conf t
R1(config)#route-map RM_AS_PATH_PREPEND
R1(config-route-map)#exit
R1(config-router)#end
R1#
Now the path learned from R2 will have 2 additional hops associated to it. This will make the path from R3 more preferred since it is
shorter:
Advertised to update-groups:
Refresh Epoch 2
200 300
Refresh Epoch 3
https://supportforums.cisco.com/t5/network-infrastructure-documents/understanding-bgp-best-path-selection-manipulation/ta-p/3150576 8/13
12/3/2017 Understanding BGP Best Path Selection &... - Cisco Support Community
R1#
The next hop interface for tra c destined to the 172.16.1.0/24 pre x is now updated to FastEthernet0/1.
172.16.1.0/24
R1#
Manipulating MED
R1's MED can be altered to prefer the next hop address of 13.13.13.3 for the 172.16.1.0/24 pre x. The following example uses a
route-map to set the value.
On R2:
MED can only be con gured outbound to in uence which path is the preferred entry point into an Automonous System. We want to
in uence R1 to prefer the path via R3, so we con gure a higher MED value to be advertised from R2 to R1 than from R3 to R1.
R2#
R2#conf t
R2(config-route-map)#set metric 1 (In Cisco IOS, you use the metric keyword to alter MED for BGP)
R2(config-route-map)#exit
R2(config-router)#end
R2#
Now when R1 reaches step 6 in the best path selection process, it will choose the path learned from R3 since the MED is lower (a
default of 0) than what is advertised by R2:
Advertised to update-groups:
Refresh Epoch 2
https://supportforums.cisco.com/t5/network-infrastructure-documents/understanding-bgp-best-path-selection-manipulation/ta-p/3150576 9/13
12/3/2017 Understanding BGP Best Path Selection &... - Cisco Support Community
200 300
Refresh Epoch 3
200 300
R1#
If a MED value has not been set by the BGP peer, we will not show the value of 0 in the show ip bgp output.
The next hop interface for tra c destined to the 172.16.1.0/24 pre x is now updated to FastEthernet0/1.
172.16.1.0/24
R1#
By default BGP will only choose one path as best. If multiple paths are learned to a destination subnet the user can con gure BGP
to load balance with the underlying IGP.
On R1:
Adjusting the number of paths that BGP is allowed to install can be done as follows:
R1#
R1#conf t
R1(config-router)#maximum-paths 2
R1(config-router)#end
R1#
With this con guration in place BGP can now install 2 paths to the 172.16.1.0/24 subnet. The path that R2 and R3 advertise are
identical in the best path selection process up to step 9, so they're both candidates for installation in the Routing Table.
https://supportforums.cisco.com/t5/network-infrastructure-documents/understanding-bgp-best-path-selection-manipulation/ta-p/3150576 10/13
12/3/2017 Understanding BGP Best Path Selection &... - Cisco Support Community
Multipath: eBGP
Advertised to update-groups:
Refresh Epoch 4
200 300
Refresh Epoch 3
200 300
R1#
Now when BGP does the recursive routing lookup for the Next Hop addresses of each path it will use both next hop interfaces to
load balance tra c via the IGP (in this case EIGRP):
172.16.1.0/24
R1#
Final Thoughts
The advantage that BGP has over all other routing protocols is the ability to control path selection based on di erent routing
policies. The policy to apply to in uence tra c into and out of your network should be based on what ts within your existing
deployment and what you nd easiest to manage.
Version history
Revision #: 1 of 1
Last update: 02-12-2013 10:58 AM
Updated by: jawestbr
Labels (1)
https://supportforums.cisco.com/t5/network-infrastructure-documents/understanding-bgp-best-path-selection-manipulation/ta-p/3150576 11/13
12/3/2017 Understanding BGP Best Path Selection &... - Cisco Support Community
15 Helpful
Share
COMMENTS
02-20-2013 04:29 A
Anonymous N/A
Excelent document, I really liked that is is very concise. If someone needs to learn BGP path selection, I think this document is a great
starting point. It is also very good for refreshing what you already know. Thanks James!
11-19-2013 06:34 P
Dennis McLaughlin Cisco Employee
Great doc Brooks. Very detailed and easy to follow along. Keep up the good work.
Thanks,
troubleshoot catalyst_6500 con guration error_message catalyst_6000 ios catalyst_4500 faq catalyst_3750 ospf
ip_routing catalyst_4000 vlan cat_os bgp ipv6 routing catos router supervisor catalyst_3550 memory_issues
Top
Facebook
Twitter
+
Google
YouTube
LinkedIn
Instagram
https://supportforums.cisco.com/t5/network-infrastructure-documents/understanding-bgp-best-path-selection-manipulation/ta-p/3150576 12/13
12/3/2017 Understanding BGP Best Path Selection &... - Cisco Support Community
https://supportforums.cisco.com/t5/network-infrastructure-documents/understanding-bgp-best-path-selection-manipulation/ta-p/3150576 13/13