BGP consists of two parts, Network Layer Reachability Information and Path Attributes.
The path attributes are a huge factor in deciding the preferred path for traffic to take. On top of this only the best path is advertised to neighbours in BGP.
BGP automatically installs the first route it receives for a new destination as the preferred path. If additional routes are received for the same network prefix with the same prefix length, there are comparisons made against the current preferred path with the path attributes.
There is a selected order of path attributes that are compared, and if that path attribute is equal in priority, it moves onto the next comparison in the list.
BGP attributes are compared in the following order:
- Local Preference
- Where did the local route originate from:
- Via a network statement
- Via Redistribution
- Via Aggregation
- Accumulated IGP Metric Attribute
- Origin type
- Lowest MED
- eBGP preferred over iBGP
- Lowest IGP next hop
- At this point, if both routes are eBGP, prefer the oldest route
- Prefer the route that comes from the BGP peer with the lower RID
- Prefer the route with the minimum cluster length list
- Prefer the path that comes from the lowest neighbour address
Network layer reachability information (NLRIs) and path attributes are maintained inside the BGP Loc-RIB table, with their best path pre-calculated. This best path is installed into the routing table, or routing information base of the router.
If the best path suddenly becomes unavailable, the BGP Loc-Rib can use any other known paths to recalculate the next preferred route to direct traffic into. The best path could become unavailable for a number of reasons such as:
- The next-hop reachability changes
- There is a failure of an interface connected to a BGP peer
- Redistribution into BGP changes
- New paths are entered into a route
- Paths are removed from a route