The BGP Decision Process and Route Selection
The BGP Decision Process and Route Selection
When a router receives multiple valid candidate paths for the same prefix from different peers, it executes a deterministic, multi-step tie-breaking pipeline: the BGP Decision Process. Understanding the hierarchy of these criteria is critical, as routing attacks and policy leaks frequently exploit specific tie-breaking stages to divert traffic.
The Step-by-Step BGP Decision Process
Before initiating the comparison steps, the router validates basic eligibility: - The candidate route must be installed in Adj-RIB-In with valid syntax. - The NEXT_HOP IP address must be resolvable in the routing table (IGP or connected interface). - The AS_PATH must not contain the local AS number (unless allowas-in is configured).
Once eligible, candidate paths are compared pairwise using the following strict hierarchy:
| Step | Attribute / Criterion | Preferred Candidate | Scope & Portability |
|---|---|---|---|
| 0 | Weight | Highest Weight | Local router only (vendor-specific: Cisco, Huawei; not transmitted in BGP) |
| 1 | LOCAL_PREF |
Highest LOCAL_PREF |
Entire local AS (disseminated over iBGP; stripped over eBGP) |
| 2 | Locally Originated | Local network or redistribute over received |
Local router origin preference |
| 3 | AS_PATH Length |
Shortest sequence of AS hops | Global metric (ignores AS_SET size per RFC 5065) |
| 4 | ORIGIN |
IGP (0) \(<\) EGP (1) \(<\) Incomplete (2) | Global attribute |
| 5 | MED (Multi-Exit Disc) |
Lowest MED | Between paths from the same neighboring AS (unless always-compare-med) |
| 6 | Peer Type | eBGP path over iBGP path | Boundary preference (prefers external exit over transit) |
| 7 | IGP Metric to NEXT_HOP |
Lowest metric in IGP to reach NEXT_HOP |
Hot-potato routing (exit local AS as rapidly as possible) |
| 8 | Multipath | Install multiple equal paths (if enabled) | ECMP load-balancing |
| 9 | Oldest Route | Path received first (eBGP paths only) | Route flap stabilization (prevents unnecessary churn) |
| 10 | Router ID (BGP Identifier) | Lowest BGP Router ID (IPv4 address) | Deterministic tie-breaker |
| 11 | Cluster List Length | Shortest CLUSTER_LIST length |
Route reflector topologies |
| 12 | Neighbor IP Address | Lowest peer IP address | Final deterministic tie-breaker |
[Candidate Paths for Prefix P]
|
v
Highest Weight? (Local)
|
v
Highest LOCAL_PREF? (AS-wide)
|
v
Shortest AS_PATH Length?
|
v
Lowest ORIGIN Code?
|
v
Lowest MED? (Same AS)
|
v
eBGP over iBGP?
|
v
Lowest IGP Metric to Next-Hop? (Hot-Potato)
|
v
Tie-breakers: Oldest -> Lowest Router ID -> Lowest Peer IP
|
v
[SINGLE BEST PATH INSTALLED IN LOC-RIB]
Weight, LOCAL_PREF and Administrative Distance
- Weight: A 16-bit integer (\(0\) to \(65,535\)) configured locally on a router interface or neighbor. Weight takes precedence over all other BGP attributes. It allows an operator on a single device to force all traffic out of Interface \(A\) without affecting any other router in the network.
- LOCAL_PREF: The universal AS-wide policy knob. In standard production practice, network operators assign
LOCAL_PREFvalues based on business relationships:- Customer Routes:
LOCAL_PREF = 200(highest priority; customer pays us). - Settlement-Free Peer Routes:
LOCAL_PREF = 150(medium priority; free transport). - Transit Provider Routes:
LOCAL_PREF = 100(lowest priority; we pay for bytes). - Backup Links:
LOCAL_PREF = 50.
- Customer Routes:
Because LOCAL_PREF sits above AS_PATH length in the decision pipeline, an operator will always prefer a 10-hop customer path over a 1-hop transit provider path.
- Administrative Distance / Route Preference: When BGP selects its best path, that path must still compete against other routing protocols (OSPF, IS-IS, Static, Connected) for installation into the kernel or ASIC FIB:
- Directly Connected: \(0\)
- Static Route: \(1\)
- eBGP: \(20\) (default on Cisco; Junos uses route preference \(170\))
- OSPF: \(110\)
- iBGP: \(200\) (default on Cisco; Junos uses route preference \(170\))
AS_PATH Length, ORIGIN and MED Comparisons
- AS_PATH Length: When
LOCAL_PREFis equal (e.g., comparing two transit providers), the router selects the path with the fewest AS hops. This exposes a primary attack surface: an adversary who announces a stolen prefix with a direct 1-hopAS_PATHwill defeat a legitimate path that is 3 hops away, winning traffic across the entire Internet. - MED and
always-compare-med: MED is designed to let an adjacent customer indicate which of multiple links to use. Comparing MED across different ASNs is disabled by default because it can create forwarding loops and nondeterministic oscillation (RFC 3345).
Route Preference and IGP Influence: eBGP vs iBGP vs Static vs IGP
Step 6 (eBGP over iBGP) prioritizes handing traffic directly to an external peer rather than routing it through internal core backbones.
Step 7 (Hot-Potato Routing) chooses the exit router whose NEXT_HOP IP has the lowest interior metric in OSPF/IS-IS. This shifts the computational burden and bandwidth cost to downstream networks as early as possible. However, if internal IGP metrics flap, the BGP decision engine will recompute its best path, inducing path instability across external sessions.
Multi-Exit Discrimination, Tie-Breakers and Stability
To prevent routing flaps from causing perpetual state changes, Step 9 prefers the oldest received route when comparing external eBGP paths. This dampens minor network oscillations. If all policy attributes, lengths, and metrics match, the router breaks the tie deterministically using the lowest peer Router ID and lowest IP socket address.