BGP receives path updates from its peers, and then makes a decision as to which route is best. This is the route that is potentially transferred to the IP routing table and advertised to peers.

The synchronization rule also plays a part in this decision, and is investigated more closely.

Cisco has the BGP Best Path Selection Algorithm well explained, so what follows here is only a summary.

I look at the decision process as having three phases:

  1. Sanity checks
  2. Policy checks
  3. Tie Breakers

Sanity Checks

These checks make sure that the route is a valid route.

Firstly, an iBGP route must be synchronized if synchronization is enabled. To be synchronized, the route (or a more specific component of it) must be known through an IGP on the router.

In the example, R3 and R0 are in AS1. R0 is advertising 10.0.0.0/24 into iBGP. With synchronization on R3, the route is seen in BGP but not moved to the routing table:

r3#show ip bgp 10.0.0.0 255.255.255.0 longer-prefixes
BGP table version is 5, local router ID is 10.3.3.1
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal
Origin codes: i - IGP, e - EGP, ? - incomplete

   Network          Next Hop            Metric LocPrf Weight Path
* i10.0.0.0/24      10.50.0.1                0    100      0 i

r3#show ip route 10.0.0.0 255.255.255.0
% Subnet not in table

and therefore is not sent to peers:

r1#show ip route 10.0.0.0 255.255.255.0
% Subnet not in table

We could turn off synchronization with “no synchronization”, run an IGP between R0 and R3, or use a static:

r3(config)#ip route 10.0.0.0 255.255.255.0 10.50.0.1
r1#show ip route 10.0.0.0 255.255.255.0
Routing entry for 10.0.0.0/24
  Known via "bgp 2", distance 20, metric 0
  Tag 1, type external
  Last update from 192.168.3.1 00:00:02 ago
  Routing Descriptor Blocks:
  * 192.168.3.1, from 192.168.3.1, 00:00:02 ago
      Route metric is 0, traffic share count is 1
      AS Hops 1

In the real world, synchronization is usually disabled. It’s been the default since 12.2(8)T.

Next, the NEXT_HOP must be accessible. This is just common sense, since there is no point in sending packets to a next hop you can’t reach.

Cisco’s document lists a few more sanity checks, but these two are the important ones.

Policy Checks

These are the checks that follow your routing policy. Note that the “shortest path” check is left to the end, letting you make manual interventions at many places.
Using the Border Gateway Protocol for Interdomain Routing describes this in more detail.

The following rules are used to decide between routes

  1. Highest weight. Remember weight is Cisco proprietary, and not transmitted as part of the route, so it is a decision local to the router made through a route map.
  2. Highest local preference. Same idea as weight, but this is carried within the AS
  3. Prefer local routes. To quote Cisco,

    Prefer the path that was locally originated via a network or aggregate BGP subcommand, or through redistribution from an IGP. Local paths sourced by network or redistribute commands are preferred over local aggregates sourced by the aggregate-address command

  4. Shortest AS-PATH length. Even though the number of AS hops is smaller, this doesn’t necessarily mean it’ll be faster
  5. Lowest origin type (IGP Lowest multi-exit discriminator (MED), AKA BGP metric. This is used to tell a neighbouring AS which path to take if there are multiple ones between the two ASes. Practically, providers let you set a community that alters their local preference, making the decision earlier in the process.
  6. eBGP over iBGP. AD is 20 vs 200
  7. Lowest IGP metric to NEXT_HOP

Tie Breakers

At this point, the candidate routes are similar, so tie breaker rules come into play.

  1. Oldest route. This minimizes flapping
  2. Lowest routerid of the peer advertising the route
  3. Lowest neighbour address

Examples

This decision is made based on AS-Path length:

r1#show ip bgp 10.2.2.0
BGP routing table entry for 10.2.2.0/24, version 20
Paths: (2 available, best #2, table Default-IP-Routing-Table)
  Advertised to non peer-group peers:
  192.168.3.1
  1 3
    192.168.3.1 from 192.168.3.1 (10.3.3.1)
      Origin IGP, localpref 100, valid, external
      Community: no-export
  3
    192.168.3.10 from 192.168.3.10 (10.2.2.1)
      Origin IGP, metric 0, localpref 100, valid, external, best

We can alter this with either weight or local preference. I looked at this one when going over path attributes

References

  1. BGP Best Path Selection Algorithm
  2. Using the Border Gateway Protocol for Interdomain Routing
  3. path attributes