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.
- Weight
- Local preference
- Origin
- AS path length
- Origin code
- MED
- eBGP/iBGP
- IGP metric to BGP next hop
- Oldest path
- Router ID
- Neighbor address
Weight
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
Local Preference is the primary means of overriding egress route selection in BGP. Higher local preference means higher preference, and the default is 100.
Origin
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
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.
MED
The MED attribute optional and non-transitive, and is one that is not always honored by the neighbor. The lower MED takes priority.
eBGP/iBGP
eBGP sessions are preferred over iBGP ones. eBGP being different local and neighbor ASNs, iBGP being same ASN.
IGP Metric
BGP gives priority to the route with the lowest IGP metric internal to the AS. (To the BGP next hop)
Oldest path
The path that was imported first will take priority.
Router ID
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.
Neighbor address
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?