4.3.13 · Coding › Computer Networks
Intuition Ek-line picture
Ek router ke paas do "kitaabein" hoti hain: ek hai planning book (jisme router sochta hai saare paths ke baare mein aur best decide karta hai) aur doosri hai action book (ek fast lookup — "agar packet X ke liye hai, toh ise is door se baahar bhejo"). Planning book hai routing table ; fast action book hai forwarding table . Routing = plan banao; forwarding = plan execute karo, har packet ke liye.
Definition Routing table (control plane)
Routing table ek aisi data structure hai jo routing algorithms/protocols (jaise OSPF, RIP, BGP) ke dwara banayi jaati hai. Isme best paths compute karne ke liye zaroori saari knowledge hoti hai: destination prefixes, next-hop, metric/cost, woh protocol jisne route seekha, administrative distance, etc. Yeh control plane mein rehti hai aur jab topology change hoti hai tab update hoti hai.
Definition Forwarding table (data plane / FIB)
Forwarding table (a.k.a. FIB — Forwarding Information Base) ek stripped-down, optimized table hai jo routing table se derive hoti hai. Har destination prefix ke liye isme sirf itna stored hota hai jitna packet ko abhi move karne ke liye chahiye: outgoing interface aur next-hop address. Yeh data plane mein rehti hai aur har packet ke liye consult ki jaati hai.
Intuition DO tables kyun, ek kyun nahi?
KYUN: Routing table rich hoti hai lekin search karne mein slow hoti hai (kaafi fields, ek destination ke liye multiple candidate routes, protocols dwara update hoti rehti hai). Packets millions/second ki speed se aate hain — aap har packet ke liye routing algorithm nahi chala sakte. Toh router heavy thinking ek baar karta hai (control plane) aur result ko ek lean, hardware-searchable table (data plane) mein bake kar deta hai. Separation = protocols se correctness + hardware se speed.
Ek packet apne saath ek 32-bit (IPv4) destination address leta hai. Forwarding table mein network prefixes stored hote hain jaise 192.168.1.0/24. Router poochta hai: "Mere table mein kaun sa prefix is address ke sabse zyada leading bits se match karta hai?" Winner hota hai longest prefix match (LPM) . Wahi entry outgoing interface batati hai.
Worked example Prefix length se mask banana
/24 ke liye: M = 24 ones phir 8 zeros = 11111111.11111111.11111111.00000000 = 255.255.255.0 .
Yeh step kyun? Ek /24 network ke liye 24 bits reserve karta hai, toh mask ko exactly unhi 24 bits ko 1s se mark karna hoga.
Forwarding table:
Prefix
Out interface
0.0.0.0/0 (default)
eth0
10.0.0.0/8
eth1
10.20.0.0/16
eth2
Packet destined for 10.20.30.40 .
Check 0.0.0.0/0 → match karta hai (har address default se match karta hai).
Yeh step kyun? Default route sab kuch match karta hai; yeh fallback hai.
Check 10.0.0.0/8 → top 8 bits 10, 10 se match karte hain ✓.
Kyun? 10.20.30.40 AND /8 mask = 10.0.0.0 = prefix.
Check 10.20.0.0/16 → top 16 bits 10.20 match ✓.
Kyun? 10.20.30.40 AND 255.255.0.0 = 10.20.0.0 = prefix.
Teen matches: lengths 0, 8, 16. Longest = 16 → eth2 se baahar bhejo.
Kyun? Sabse specific route sabse precisely batata hai ki destination kahaan hai.
Worked example Worked example 2 — overlapping subnets
Table: 192.168.0.0/16 → A, 192.168.5.0/24 → B, 192.168.5.128/25 → C.
Packet to 192.168.5.200 .
/16 match karta hai (top 16 bits 192.168).
/24 match karta hai (top 24 bits 192.168.5).
/25: mask = 25 ones → 255.255.255.128. 192.168.5.200 AND 255.255.255.128 = 192.168.5.128 = prefix ✓ (kyunki 200 = 11001000, last byte ka top bit 1 hai).
Yeh step kyun? /25 last byte ko 128 pe split karta hai; 128–255 addresses is half mein aate hain.
Lengths 16, 24, 25 → longest = 25 → interface C .
Intuition "Route resolution" step
Routing table keh sakti hai "10.20.0.0/16 tak pahunchne ke liye, next-hop 192.168.1.1 pe jao" . Lekin data plane ko ek physical interface chahiye, sirf ek IP nahi. Toh router recursively next-hop IP ko resolve karta hai ek directly-connected interface tak (aur ARP ke through MAC bhi). Yeh resolved (prefix → interface, next-hop) pair FIB mein install ho jaata hai.
Definition Administrative distance & metric (routing table EK kyun choose karta hai)
Agar do protocols ek hi prefix ke liye routes offer karein, toh routing table ties ko administrative distance se break karta hai (protocol ke anusaar trust, lower = zyada trusted), phir metric (ek protocol ke andar cost). Sirf winning route forwarding table mein push hota hai — isliye FIB mein har prefix ke liye ek entry hoti hai.
Common mistake "Routing table aur forwarding table ek hi cheez hain."
Kyun sahi lagta hai: Ek chhote home router pe dono identical lagte hain aur kaafi tools (route -n) ek hi table dikhate hain. Fix: Conceptually yeh alag planes hain — routing table knowledge ka superset hai (multiple candidate routes, metrics, protocol info); forwarding table distilled best-paths hai jo line rate pe har packet ke liye use hota hai. Bade routers pe yeh physically alag memories hoti hain (RIB CPU RAM mein vs FIB TCAM mein).
Common mistake "Jo pehla prefix match kare, wahi use karo."
Kyun sahi lagta hai: First-match ordered access-lists ke liye kaam karta hai, toh log assume karte hain ki routing bhi aisa hi karta hai. Fix: IP forwarding longest prefix match use karta hai, first match nahi. Aapko saare matching prefixes check karne hote hain aur sabse specific (largest L ) choose karna hota hai, table order se independent.
Common mistake "Longer mask matlab bada network."
Kyun sahi lagta hai: "Longer" sunne mein "zyada" lagta hai. Fix: Longer prefix = zyada network bits = kam host bits = chhota network. /24 (256 hosts) /25 (128 hosts) se bada hai.
Common mistake "Default route
0.0.0.0/0 sirf unknown weird addresses se match karta hai."
Kyun sahi lagta hai: Ise "default/gateway of last resort" kaha jaata hai. Fix: 0.0.0.0/0 actually har address se match karta hai (prefix length 0), lekin kyunki iska length sabse chhota hai, LPM ise tabhi pick karta hai jab koi zyada specific prefix match nahi karta.
Recall Feynman: ek 12-saal ke bachche ko samjhao
Post office imagine karo. Routing table postmaster ki badi map aur notebook jaisi hai jisme woh har shahar ka best rasta figure out karta hai — woh ise dhyaan se padhta hai aur jab roads band hoti hain tab update karta hai. Forwarding table woh chhoti cheat-sheet hai jo har sorting machine pe chipkayi hoti hai: "in digits se shuru hone wale letters → truck #3 pe rakh do." Machine sochti nahi; sirf cheat-sheet super fast padh leti hai. Aur jab do labels dono ek letter pe fit hote hain (ek "Springfield" kehta hai aur ek aur detailed "Springfield, Elm Street"), toh hamesha zyada detailed wala use hota hai. Yahi hai longest prefix match!
Mnemonic Split yaad rakho
"RIB plans, FIB ships." Routing table = R eason (control plane). Forwarding table = F ast (data plane). Aur LPM = "Longest is Pickiest = Most-specific."
Recall Active recall checkpoint
Forwarding table kaun se plane mein hai? (data plane)
Entry select karne ka rule kya hai? (longest prefix match)
Kaun si entry har address se match karti hai? (0.0.0.0/0)
Do tables kyun? (protocols se correctness + per-packet speed)
Routing table kya hai (kaun sa plane, kaun banata hai)? Control-plane structure jo routing protocols (OSPF/RIP/BGP) dwara banayi jaati hai; saare candidate routes, next-hops, metrics, administrative distances store karta hai.
Forwarding table / FIB kya hai? Data-plane table jo routing table se derive hoti hai; har destination prefix ko ek outgoing interface + next-hop se map karti hai, line rate pe har packet ke liye consult hoti hai.
Har packet ke liye route karne ki jagah alag forwarding table kyun rakho? Routing computation slow aur rich hoti hai; best paths ko ek lean table mein bake karne se hardware millions of packets/sec forward kar sakta hai.
Packet ke liye forwarding entry choose karne ka rule kya hai? Longest Prefix Match — sabse bade prefix length wala matching prefix jeet jaata hai.
Address D ka prefix P/L se match karne ki condition? (D AND M) == (P AND M) jahan M hai L ones ke baad (32-L) zeros (subnet mask).
Address ko mask ke saath AND karne se kya hota hai? Host bits zero ho jaate hain, sirf network bits bachte hain prefix se compare karne ke liye.
0.0.0.0/0 kya match karta hai aur kab use hota hai? Yeh har address match karta hai (length 0); sirf tab use hota hai jab koi zyada specific prefix match nahi karta (default route).
/25 /24 se bada network hai ya chhota? Chhota — zyada network bits matlab kam host bits (128 vs 256 addresses).
Alag protocols ke routes ke beech ties kaun break karta hai? Administrative distance (lower = zyada trusted), phir protocol ke andar metric.
IP forwarding first-match hai ya longest-match? Longest prefix match, table order se independent.
/26 ka subnet mask? 255.255.255.192 (26 ones = last byte mein ...11000000).
FIB mein install karte waqt route resolution kya karta hai? Next-hop IP ko recursively ek directly connected outgoing interface (aur ARP ke through MAC) tak resolve karta hai.
IP Addressing and Subnetting — masks, prefix lengths, CIDR
ARP — Address Resolution Protocol — next-hop IP → MAC for the FIB
OSPF and Link-State Routing — routing table populate karta hai
Distance Vector — RIP — routing table banane ka alternative tarika
TCAM and Line-rate Forwarding — woh hardware jo FIB store karta hai
Default Gateway and 0.0.0.0/0 — catch-all entry
Control Plane vs Data Plane — master distinction
Routing algorithms OSPF RIP BGP
Outgoing interface + next-hop