BGP Path Selection Logic
The Hierarchical Decision Algorithm
Introduction to BGP Decision Making
Unlike Interior Gateway Protocols (IGPs) like OSPF or EIGRP, which typically use a simple metric like cost or bandwidth, the Border Gateway Protocol (BGP) uses a complex, hierarchical list of attributes to select the "Best Path." BGP is a path-vector protocol designed for policy enforcement, not just shortest-path calculation.
The Selection Algorithm Hierarchy
When a BGP router receives multiple routes to the same prefix, it applies the following tie-breaking rules in order. The first rule that produces a single winner stops the process:
BGP Traffic Engineering Flow
Simulate inbound/outbound path selection metrics
- Weight (Cisco Proprietary): Highest weight is preferred. Local to the router.
- Local Preference: Highest local preference (default 100) is preferred. Shared within the AS.
- Locally Originated: Prefer routes originated by this router (network/aggregate commands).
- AS-Path Length: Shortest AS-Path is preferred.
- Origin Type: Prefer IGP over EGP, and EGP over Incomplete.
- Multi-Exit Discriminator (MED): Lowest MED is preferred (usually exchanged between neighboring ASes).
- External vs. Internal: Prefer eBGP paths over iBGP paths.
- IGP Metric to Next Hop: Prefer the path with the lowest IGP metric to the BGP next hop.
Mathematical Influence: AS-Path Prepending
Network engineers often use "AS-Path Prepending" to discourage inbound traffic from choosing a specific link. By artificially inflating the AS-Path length, the path becomes less attractive to the selection algorithm.
Where is the number of times the local AS number is repeated in the path attribute.
Conclusion
Understanding this hierarchy is critical for traffic engineering. By adjusting these attributes, engineers can control how their data leaves the network (Outbound Policy via Local Preference) and how external traffic enters (Inbound Policy via AS-Path Prepending or MED).