L3 · egp · reviewed
BGP
Border Gateway Protocol 4
A TCP session that exchanges path attributes, then picks one path with a total-order waterfall — not a shortest-path flood.
Presenter modeEmbed this figure
Why it exists
Interior protocols flood topology and compute the same tree. The Internet cannot flood 900 000 prefixes as link-state. BGP exchanges paths with attributes, then each speaker independently picks one with a documented total order. Decision ProcessRFC 4271 · DRAFT STANDARD · January 2006
Idle to Established
Two speakers open a TCP session on port 179, exchange OPEN with capabilities, then KEEPALIVE, and only then send UPDATE.
Both speakers are Idle. Nothing is sent until an operator (or a restart) moves the session to Connect or Active. R1 · AS 65001: FSM Idle. R2 · AS 65002: FSM Idle.
- Link
- Blocking
- Packet in flight
- Discarded
- Emphasis
Text equivalent of this diagram
| Element | Kind | State |
|---|---|---|
| R1 · AS 65001 | router | FSM: Idle |
| R2 · AS 65002 | router | FSM: Idle |
| R1 · AS 65001 — R2 · AS 65002 | link | up · eBGP |
Both speakers are Idle. Nothing is sent until an operator (or a restart) moves the session to Connect or Active.
What changed
- R1 · AS 65001: FSM → Idle
- R2 · AS 65002: FSM → Idle
How it works
A session is a TCP FSM (Idle → Connect/Active → OpenSent → OpenConfirm → Established). Only Established carries UPDATE. iBGP does not re-advertise iBGP-learned paths, which is why a full mesh, a route reflector, or a confederation exists. BGP Finite State Machine (FSM)RFC 4271 · DRAFT STANDARD · January 2006
Best-path after NEXT_HOP resolvability: Weight (Cisco), LOCAL_PREF, local origination, AS_PATH length (AS_SET counts as one; confed segments do not count), ORIGIN, MED (same neighboring AS unless always-compare), eBGP over iBGP, IGP metric to NEXT_HOP, BGP Identifier / ORIGINATOR_ID, CLUSTER_LIST, peer address. Breaking Ties (Phase 2)RFC 4271 · DRAFT STANDARD · January 2006
IPv6 unicast, VPNv4 and EVPN do not use the IPv4 NLRI field. They use MP_REACH_NLRI, type 14, with an AFI and SAFI. Multiprotocol Reachable NLRI - MP_REACH_NLRI (Type Code 14):RFC 4760 · DRAFT STANDARD · January 2007
Try it
Run the waterfall
Pick one of the 25 hand-built cases and watch which comparison eliminates the loser. Weight and ROV are labelled as local policy.
Winner: A · expected A on local-pref
- local-prefA has LOCAL_PREF 200; B has 100.
On the wire
Constructed examples, encoded from the field table below them — not captured traffic.
- TCP
- BGP messages ride a TCP session on port 179. RFC 4271
- BGP header
- 16-octet marker, 2-octet length, 1-octet type. RFC 4271
- UPDATE body
- Withdrawn-routes length, path attributes, then NLRI. RFC 4271
Configure it
router bgp 65001 bgp router-id 1.1.1.1 neighbor 192.0.2.2 remote-as 65002The AS in `router bgp` is this speaker. remote-as 65002 makes the session eBGP. Router-id is the BGP Identifier in OPEN.
RFC 4271 §4.2
address-family ipv4 unicast neighbor 192.0.2.2 activate network 192.0.2.0 mask 255.255.255.0IPv4 unicast must be activated. `network` originates a local prefix; it is not an IGP redistribution.
RFC 4271 §9.4
Verify
show ip bgp summary- Neighbor 192.0.2.2 state Established, AFI IPv4 unicast.
Caveats
- Draft syntax. IOS-XE default address-family activation varies by version.
When it breaks
Symptom first, because that is what you have when it happens.
Neighbor stuck in Idle or Active.
Narrow it down
- Confirm TCP to port 179 from both addresses.
- Diff the configured AS numbers and the source addresses.
Cause
TCP never establishes, or OPEN is refused (AS mismatch, hold time, capability).
Fix
Fix reachability and the OPEN fields. BGP will not skip TCP.
Finite State MachineRFC 4271 · DRAFT STANDARD · January 2006Prefix is in Adj-RIB-In and missing from LOC-RIB.
Narrow it down
- Check NEXT_HOP reachability in the IGP.
- Confirm the IGP interface is not a connected /32 that does not recurse.
Cause
RFC 4271 §9.1.2.1 dropped an unresolvable NEXT_HOP before the waterfall.
Fix
Advertise the next hop, or set next-hop-self on iBGP.
Route Resolvability ConditionRFC 4271 · DRAFT STANDARD · January 2006A prefix is learned from a customer with a foreign AS_PATH.
Narrow it down
- Inspect AS_PATH and communities on the customer session.
- Check whether OTC or roles are configured.
Cause
Export policy leaked a provider or peer path to another provider.
Fix
Apply RFC 9234 roles/OTC, and prefix-filter customer sessions to their AS.
BGP Only to Customer (OTC) AttributeRFC 9234 · PROPOSED STANDARD · May 2022iBGP path oscillates between reflectors.
Narrow it down
- Show ORIGINATOR_ID and CLUSTER_LIST on the oscillating prefix.
- Confirm cluster-ids are unique per reflector.
Cause
Reflectors share a cluster-id or ignore ORIGINATOR_ID.
Fix
Unique cluster-id per RR; never reflect a path whose ORIGINATOR_ID is self.
Avoiding Routing Information LoopsRFC 4456 · DRAFT STANDARD · April 2006A signed prefix is still preferred from an invalid origin AS.
Narrow it down
- Show origin-validation state Valid / NotFound / Invalid.
- Check whether invalid paths are eligible for best-path.
Cause
ROV is collected but not applied as policy before 9.1.2.2.
Fix
Prefer Valid, drop or deprefer Invalid. RFC 6811 is not automatic in 4271.
Prefix-to-AS Mapping DatabaseRFC 6811 · PROPOSED STANDARD · January 2013
Design notes
Missing MED may be treated as 0 or as infinity. RFC 4271 §5.1.4 allows either. Cisco uses 0. The waterfall model exposes both. MULTI_EXIT_DISCRFC 4271 · DRAFT STANDARD · January 2006
Route reflection replaces the iBGP mesh but needs ORIGINATOR_ID and CLUSTER_LIST so a reflected path is not re-reflected into a loop. Avoiding Routing Information LoopsRFC 4456 · DRAFT STANDARD · April 2006
Misconceptions
- “BGP always picks the shortest AS_PATH.”
- AS_PATH is the fourth RFC comparison, after LOCAL_PREF and local origination. Weight, if present, is even earlier and is not in the RFC. Breaking Ties (Phase 2)RFC 4271 · DRAFT STANDARD · January 2006
- “MED is compared between all paths.”
- By default MED is compared only among paths from the same neighboring AS. always-compare-med is an explicit local policy. MULTI_EXIT_DISCRFC 4271 · DRAFT STANDARD · January 2006
- “IPv6 routes use the same NLRI field as IPv4.”
- IPv6 unicast is MP_REACH_NLRI with AFI 2. The IPv4 NLRI field of RFC 4271 is not used. Multiprotocol Reachable NLRI - MP_REACH_NLRI (Type Code 14):RFC 4760 · DRAFT STANDARD · January 2007
More walkthroughs
Two eBGP paths, one winnerdesign-choice
R1 hears 192.0.2.0/24 from AS 65010 (LOCAL_PREF 80, AS_PATH 1) and AS 65020 (LOCAL_PREF 120, AS_PATH 3). LOCAL_PREF decides; AS_PATH is never consulted.
Both neighbors are Established. Two candidate paths exist for the same prefix. Best-path is a total order over those candidates, not a flood. R1 · chooser: candidates 2. ISP A · AS 65010. ISP B · AS 65020.
- Link
- Blocking
- Packet in flight
- Discarded
- Emphasis
Text equivalent of this diagram
| Element | Kind | State |
|---|---|---|
| R1 · chooser | router | candidates: 2 |
| ISP A · AS 65010 | router | — |
| ISP B · AS 65020 | router | — |
| R1 · chooser — ISP A · AS 65010 | link | up · eBGP |
| R1 · chooser — ISP B · AS 65020 | link | up · eBGP |
Both neighbors are Established. Two candidate paths exist for the same prefix. Best-path is a total order over those candidates, not a flood.
What changed
- Emphasis on R1 · chooser
- R1 · chooser: candidates → 2
A customer leaks a provider pathfailure
AS 65001 learns 203.0.113.0/24 from transit AS 64496 and exports it to transit AS 64497. 64497 prefers the customer path because it is shorter, and the prefix is now a leak.
AS 64496 originates or transits 203.0.113.0/24 and advertises it to its customer 65001. That is a provider-to-customer announcement. AS 64496 · transit. AS 65001 · customer. AS 64497 · transit. 203.0.113.0/24.
- Link
- Blocking
- Packet in flight
- Discarded
- Emphasis
Text equivalent of this diagram
| Element | Kind | State |
|---|---|---|
| AS 64496 · transit | router | — |
| AS 65001 · customer | router | — |
| AS 64497 · transit | router | — |
| 203.0.113.0/24 | cloud | — |
| AS 64496 · transit — AS 65001 · customer | link | up · provider→customer |
| AS 65001 · customer — AS 64497 · transit | link | up · customer→provider |
| AS 64496 · transit — 203.0.113.0/24 | link | up |
AS 64496 originates or transits 203.0.113.0/24 and advertises it to its customer 65001. That is a provider-to-customer announcement.
What changed
- UPDATE to customer: AS 64496 · transit → AS 65001 · customer
Terms
- LOCAL_PREF
- A well-known discretionary attribute. Higher is better. Compared in Phase 2 before AS_PATH length. Not sent to eBGP peers.
- AS_PATH
- The sequence (and optional set) of ASes a path has traversed. Shorter wins after LOCAL_PREF. An AS_SET counts as one, not as its cardinality.
- MULTI_EXIT_DISC
- An optional non-transitive metric. Lower is better. Compared only among paths from the same neighboring AS unless a local always-compare policy is on.
- Route reflector
- An iBGP speaker allowed to re-advertise iBGP-learned paths to clients. ORIGINATOR_ID and CLUSTER_LIST prevent reflection loops.
- Origin validation
- RFC 6811 maps a prefix to Valid, NotFound, or Invalid using RPKI. Applying those states to best-path is local policy, not a rewrite of RFC 4271 §9.1.2.2.