4.3.17Computer Networks

BGP — path vector, AS, policy routing

2,217 words10 min readdifficulty · medium3 backlinks

WHAT is BGP?

WHY a separate protocol from OSPF/RIP? Intra-domain protocols (OSPF, RIP) optimize a single metric (hops, link cost) and assume everyone cooperates. Across the internet that breaks: a transit provider may refuse to carry your traffic for free even if it's the shortest path. BGP must encode policy ("I won't route this"), scale to ~1M prefixes, and prevent loops between untrusting parties. That's a fundamentally different job.


Path Vector: WHY and HOW (derive it)

We want a loop-free routing protocol across ASes. Let's build it from scratch.

Steel-man the fix: What's the minimum extra info that kills loops? If each advertisement carried the entire list of ASes the route passes through, then any router seeing its own AS number already in the list knows: "accepting this creates a loop" → reject it.

So an advertisement looks like:

prefix 8.8.8.0/24    AS_PATH=[AS2,AS5,AS15169]\text{prefix } 8.8.8.0/24 \;\;\text{AS\_PATH} = [\,AS_2,\, AS_5,\, AS_{15169}\,]

read right-to-left: the prefix originates in AS15169, was passed to AS5, then AS2.


Figure — BGP — path vector, AS, policy routing

Policy Routing: WHY BGP isn't shortest-path

This produces valley-free paths: a path goes up (customer→provider) zero or more times, then optionally one peer hop, then down (provider→customer). It is never "up after down" — that would mean an AS gives free transit. Hence the shortest AS path is often NOT chosen — policy overrides distance.


The BGP Decision Process (how a route is actually picked)

Among multiple routes to the same prefix, BGP picks one, in this priority order:


Worked Example: full policy decision


Flashcards

What does an AS_PATH attribute contain?
The ordered list of AS numbers a route traverses; read right-to-left from origin.
How does BGP (path vector) prevent loops?
A router rejects any advertisement whose AS_PATH already contains its own ASN.
What does an AS re-advertising a route over eBGP do to the AS_PATH?
Prepends its own ASN to the front.
Why does BGP use path vector instead of distance vector?
Carrying the full AS path gives instant loop detection and avoids count-to-infinity.
What is the FIRST tie-breaker in BGP best-path selection?
Highest LOCAL_PREF (a policy knob), not shortest path.
Where in the decision process does AS_PATH length matter?
Step 2 — only after LOCAL_PREF.
Gao–Rexford: a route learned from a PEER may be exported to whom?
Only to customers (not to peers or providers).
Gao–Rexford: a route learned from a CUSTOMER may be exported to whom?
To everyone (customers, peers, providers).
What is a "valley-free" path?
A path of up-hops (cust→prov), then ≤1 peer hop, then down-hops (prov→cust); never up after down.
Difference between eBGP and iBGP?
eBGP runs between routers in different ASes; iBGP distributes externally-learned routes within one AS.
What is hot-potato routing?
Choosing the egress with lowest IGP cost — dump traffic out of your AS as fast as possible.
Why prefer customer routes over provider routes via LOCAL_PREF?
You earn money carrying customer traffic but pay for provider transit, so customer is cheapest.

Recall Feynman: explain to a 12-year-old

Imagine many neighborhoods, each owned by a different family. To send a letter across town you must hand it neighbor-to-neighbor. Each family stamps its name on the envelope's route list. If a family sees its own name already on the list, it knows the letter is going in circles and throws it out — no loops! And families don't just pick the shortest route: some neighbors charge money (providers), some are free friends (peers), and some are paying customers. A family always prefers handing letters to a paying customer (it makes money) over a route that costs it money — even if that customer's path is longer. That's BGP: route by who pays, not by who's nearest.


Connections

  • OSPF and link-state routing — intra-domain, single metric, full trust (contrast).
  • Distance Vector and Count-to-Infinity — the problem path vector solves.
  • Autonomous Systems and ASN allocation
  • IP addressing and CIDR prefixes — what BGP actually advertises.
  • Internet topology — Tier-1, transit, peering — economics behind policy.
  • Hot-potato vs Cold-potato routing
  • Route flap damping and BGP convergence

Concept Map

exchanged by

runs between ASes

runs within AS

advertises

insufficient for

suffers

motivates

uses

test X not in P

prepend own ASN

decides on

overrides

Autonomous System AS
single policy, ASN

BGP
inter-domain protocol

eBGP external

iBGP internal

Prefix
IP block

OSPF / RIP
single metric

Distance-Vector

Count-to-Infinity
slow convergence

Path Vector
AS_PATH attribute

Loop Prevention

Policy Routing
money, contracts

Shortest Path

Hinglish (regional understanding)

Intuition Hinglish mein samjho

Dekho, internet ek single network nahi hai — ye hazaaron alag-alag companies ke networks (ASes) ka jod hai, jinmein aapas mein koi trust nahi hota aur koi central boss bhi nahi hota. BGP wahi protocol hai jo in ASes ke beech batata hai ki "kaunsa prefix kahan se reachable hai aur kaun-kaun se AS se ho ke". Har AS ka ek number hota hai (ASN), jaise Google = AS15169.

BGP ek path vector protocol hai. Matlab har advertise me poora AS_PATH chalta hai — yaani route kin-kin ASes se guzra hai uski poori list. Iska sabse bada fayda: loop turant pakda jata hai. Jab kisi AS ko koi route milta hai aur usme uska apna ASN already present hai, to wo reject kar deta hai — kyunki accept karne se loop ban jaega. Aur jab AS route aage bhejta hai to apna ASN prepend kar deta hai. Isse RIP wali "count-to-infinity" problem hi khatam ho jati hai.

Sabse important baat jo students galat samajhte hain: BGP shortest path nahi chunta! Pehle dekhta hai LOCAL_PREF — ye ek policy knob hai jo paise ke hisaab se set hota hai. Rule simple hai: customer route > peer route > provider route, kyunki customer ko bhejne me paisa milta hai, provider use karne me paisa lagta hai. AS_PATH ki length to sirf doosra tie-breaker hai, LOCAL_PREF ke baad. Isiliye kabhi-kabhi 4-hop wala customer route 2-hop wale provider route ko hara deta hai.

Aur ek concept: Gao-Rexford rules (valley-free routing). Customer se sikha route sabko bata sakte ho, lekin peer ya provider se sikha route sirf apne customers ko. Kyunki muft me doosron ka traffic carry karna paisa kharch karna hai. Yaad rakho: "Customers hear everything, baaki sab sirf customers ke baare me sunte hain." Yahi BGP ka asli dimaag hai — routing by money, not by distance.

Go deeper — visual, from zero

Test yourself — Computer Networks

Connections