BGP Path Selection
September 28, 2020
The most fundamental part of BGP is its best-path selection algorithm. BGP follows a strict order of route selection.
- Local preference
- AS path length
- Origin code
- IGP metric to BGP next hop
- Oldest path
- Router ID
- Neighbor address
Weight is an attribute specific to Cisco, and takes highest priority on their routers. Higher weight means higher preference, the default being 0.
Local Preference is the primary means of overriding egress route selection in BGP. Higher local preference means higher preference, and the default is 100.
If the BGP speaker is originating a route, (next hop 0.0.0.0) it’ll have priority over a route that is not originated by the local router.
AS path length
The length (number of ASNs in path) is the typical factor that comes into play if nothing else is tuned. Also keep in mind that networks can prepend their ASN multiple times, or broken routers (BGP optimizers) can fabricate a completely fake AS path and send that along. This can cause all sorts of problems. Shorter AS paths (lower number) takes priority.
Origin code is in the order IGP, EGP, and INCOMPLETE. If a route is marked as INCOMPLETE, it means it wasn’t learned through a BGP adjacency.
The MED attribute optional and non-transitive, and is one that is not always honored by the neighbor. The lower MED takes priority.
eBGP sessions are preferred over iBGP ones. eBGP being different local and neighbor ASNs, iBGP being same ASN.
BGP gives priority to the route with the lowest IGP metric internal to the AS. (To the BGP next hop)
The path that was imported first will take priority.
If BGP gets this far without a selection, it’ll prefer the route from the session with the lowest router ID. This has no real purpose other than a last resort.
If BGP gets this far without a selection, it’ll prefer the route from the session with the lowest neighbor IP address. This has no real purpose other than a last resort. This begs the question about what would be the true “last resort” in BGP route selection. Which BGP implementations support nonstandard ports (i.e. not 179) and would it be possible to set up multiple neighbors on the same address but different port, leading to no route selected?