Ticker

6/recent/ticker-posts

BGP Best Path Selection Criteria

BGP Best Path Selection Criteria

After BGP receives updates about different neighbors from the same or different autonomous systems(AS), first it stores them in its database also known as the BGP table(show ip bgp), and then calculates the best path to reach each destination using some rules known as the BGP Best Path Selection Algorithm or BGP Best Path Selection Process.

Multiple paths might exist to reach a specific destination prefix and all the paths, either best or non best, are kept in the BGP table. As paths for the destination prefix/network are evaluated using BGP Best Path Selection Process, those determined not to be the best path are eliminated from the selection criteria but kept in the BGP table in case the best path becomes inaccessible. The best routes are used to form the routing table. BGP chooses only a single best path to reach a specific destination.

 

BGP Best Path Selection - Rules


BGP is not designed to perform load balancing and the paths are chosen because of policy, not based on bandwidth. The BGP selection process eliminates any multiple paths until a single best path is left.

Before jumping to the BGP Best Path Selection Method, it is mandatory that next-hop for a particular destination should be reachable. Else, BGP will ignore the path in the calculation.
The following are the rules of the BGP Best Path Selection Criteria.

BGP Attributes play an important role in how BGP selects the best path. An administrator can also manipulate the default values of various BGP Attributes to influence the best path as per the network requirements.

1. Prefer the route with the highest weight. (Recall that the weight is Cisco proprietary and is local to the router only.)

2. If multiple routes have the same weight, prefer the route with the highest local preference. (Just to remind that the Local Preference is used within an AS.)

3. If multiple routes have the same local preference, prefer the route that was originated by the local router. (A locally originated route has a next hop of 0.0.0.0 in the BGP table.)

4. If none of the routes were originated by the local router, prefer the route with the shortest AS-path.

5. If the AS-path length is the same, prefer the lowest-origin code (IGP < EGP < incomplete).

6. If all origin codes are the same, prefer the path with the lowest MED.
 
We must remember that the MED comparison is done only if the neighboring AS is the same for all routes considered, unless the bgp always-compare-med router configuration command is enabled.
 
Kindly also note that the most recent Internet Engineering Task Force (IETF) decision about BGP MED assigns a value of infinity to a missing MED, making a route lacking the MED variable the least preferred. The default behavior of BGP routers running Cisco IOS Software is to treat routes without the MED attribute as having a MED of 0, making a route lacking the MED variable the most preferred. To configure the router to conform to the IETF standard, use the bgp bestpath med missing-as-worst router configuration command.

7. If the routes have the same MED, prefer external paths (EBGP - 20 AD) over internal paths (IBGP 200).

8. If BGP synchronization is disabled and only internal paths remain, prefer the path through the closest IGP neighbor. This means that the router prefers the shortest internal path(via IGP) within the AS to reach the destination (the shortest path to the BGP next-hop).

9. For the EBGP paths, select the oldest route, to minimize the effect of routes going up and down (flapping).

10. Prefer the route with the lowest neighbor BGP router ID value.

11. If the BGP Router IDs are the same, prefer the route with the lowest neighbor IP address.
 

BGP Best Path Selection -  Explanation with Lab



  Let's review the BGP Best Path Selection Process using the above lab topology. For example, let's see which path is taken by Router R4 to reach R1's loopback prefix 10.10.0.1/32. Let's check the BGP table for the best path.

R4#show ip bgp
BGP table version is 41, local router ID is 10.10.0.4
    Network          Next Hop            Metric  LocPrf   Weight     Path
* i10.10.0.1/32     10.10.56.6               0     100          0           600 100 i
*>i                        10.10.23.2               0     100          0           200 100 i

R4#show ip bgp 10.10.0.1
BGP routing table entry for 10.10.0.1/32, version 34
Paths: (2 available, best #2, table default)
  Not advertised to any peer
600 100
    10.10.56.6 (metric 2) from 10.10.0.5 (10.10.0.5)
    Origin IGP, metric 0, localpref 100, valid, internal
  200 100
    10.10.23.2 (metric 2) from 10.10.0.3 (10.10.0.3)
    Origin IGP, metric 0, localpref 100, valid, internal, best


From R4, to reach 10.10.0.1/32, the best path (denoted by ">") is via 10.10.23.2 (R3-R2) path.  Let's study the reason by reviewing all rules of BGP Best Path Selection Criteria.

Rule 1 says, select the path with the highest Weight which is 0 for both the paths, i.e. via 10.10.56.6 and via 10.10.23.2.  Therefore, we need to jump to Rule 2 as weight is equal (0) from both paths.
 
Rule 2 says, select the path with the highest Local Preference which is 100 for both the paths. Therefore, we need to jump to Rule 3.
 
Rule 3 says, select the locally originated route. i.e. the route which is generated by router R4 itself, which is not the case here because 10.10.0.1/32 is a remote prefix. Therefore, we need to jump to Rule 4.
 
Rule 4 says, select the path with the shortest AS path, which is again equal in this case because 10.10.0.1/32 can be reachable after crossing 2 AS from both directions. i.e. we have to cross AS 600 and then 100 (two AS in the path) if we go via 10.10.56.6 (via R6) and we have to cross AS 200 and then 100 (again 2 AS in the path) via 10.10.23.2 (via R2). Therefore, we need to jump to Rule 5.
 
Rule 5 says, prefer the path with the lowest origin code. Again the Origin is the same i.e. IGP(denoted by rightmost "i" for each path. Kindly note that as the route is advertised using protocol BGP, the origin code will show as "i". Therefore, we need to move to Rule 6 if we can get a tiebreaker.
 
Rule 6 says, prefer the path with the lowest MED which is again zero here because it is not set. Therefore, we need to jump to Rule 7.
 
Rule 7 says, prefer the path/route learned from an eBGP peer compared to an iBGP peer. On R4, the route is learned via the iBGP peers (R3 and R5) and not via an eBGP peer. This is denoted again by "i" but this time it is the leftmost one show after the  *  sign. Again, we have to jump to Rule 8 as prefix 10.10.0.1/32 is learned on R4 via iBGP peers.
 
Rule 8 says, if both paths are internal (route learned via iBGP peers) which is exactly the case here, prefer the path that has shortest IGP metric.  As highlighted in bolds in the output below, the route is learned with metric 2 (OSPF) from both paths.

R4#show ip bgp 10.10.0.1
BGP routing table entry for 10.10.0.1/32, version 34
Paths: (2 available, best #2, table default)
  Not advertised to any peer
  600 100
    10.10.56.6 (metric 2) from 10.10.0.5 (10.10.0.5)
      Origin IGP, metric 0, localpref 100, valid, internal
  200 100
    10.10.23.2 (metric 2) from 10.10.0.3 (10.10.0.3)
      Origin IGP, metric 0, localpref 100, valid, internal, best


We can also see this using the OSPF routing table, where the route to R3 and R5's loopbacks are learned with the OSPF metric 2 as highlighted in bold.


R4#show ip route ospf
      10.0.0.0/8 is variably subnetted, 14 subnets, 2 masks
O        10.10.0.3/32 [110/2] via 10.10.34.3, 01:07:19, FastEthernet1/0
O        10.10.0.5/32 [110/2] via 10.10.45.5, 01:05:13, FastEthernet1/1

Therefore, we need to move to Rule 9 to check for a tiebreaker.

Rule 9 says, if the paths are eBGP, prefer the oldest route, which is again not the case here because the route is learned via iBGP peers and we have to move to Rule 10.
 
Rule 10 says, prefer the path from the neighbor that has the lowest BGP Router-ID(RID) value. Here, Router R3 has the lowest Router ID (10.10.0.3) compared to the RID of R5 (10.10.0.5). So we got the tiebreaker here in Rule 10. R4 will prefer to reach R1's loopback 10.10.0.1/32 via R3 because it has the lowest RID value compared to the RID value of the iBGP neighbor R5.


I hope you have found this article informative and useful and now have a fair understanding of BGP Best Path Selection Criteria and BGP Attributes. For any of the related queries or feedback, kindly write to us at networkurge@gmail.com


Post a comment

0 Comments