BGP — path vector, AS, policy routing
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:
read right-to-left: the prefix originates in AS15169, was passed to AS5, then AS2.

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?
How does BGP (path vector) prevent loops?
What does an AS re-advertising a route over eBGP do to the AS_PATH?
Why does BGP use path vector instead of distance vector?
What is the FIRST tie-breaker in BGP best-path selection?
Where in the decision process does AS_PATH length matter?
Gao–Rexford: a route learned from a PEER may be exported to whom?
Gao–Rexford: a route learned from a CUSTOMER may be exported to whom?
What is a "valley-free" path?
Difference between eBGP and iBGP?
What is hot-potato routing?
Why prefer customer routes over provider routes via LOCAL_PREF?
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
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.