4.3.16 · HinglishComputer Networks

Link state routing — OSPF, Dijkstra

1,815 words8 min readRead in English

4.3.16 · Coding › Computer Networks



OSPF (Open Shortest Path First) Internet ka standard intra-domain (IGP) implementation hai is idea ka: ek open standard, directly IP ke upar chalta hai (protocol 89), areas, authentication, aur equal-cost multipath support karta hai.


Flooding correct KAISE rehti hai?


Dijkstra's algorithm — scratch se derive kiya hua

Procedure:

  1. , , .
  2. choose karo jiska minimum ho; ko mein add karo.
  3. se bahar jaane wale har edge ko relax karo.
  4. Tab tak repeat karo jab tak = saare nodes.

Binary heap ke saath complexity: .

Figure — Link state routing — OSPF, Dijkstra

Worked Example 1 — chhota graph

Graph (undirected, costs): A–B = 2, A–C = 5, B–C = 1, B–D = 7, C–D = 3. Source = A.

Step Finalized d[A] d[B] d[C] d[D]
init {} 0
pick A {A} 0 2 5
pick B (min=2) {A,B} 0 2 3 (via B:2+1) 9 (2+7)
pick C (min=3) {A,B,C} 0 2 3 6 (3+3)
pick D (min=6) all 0 2 3 6
  • B pehle KYUN pick kiya? Min tentative = 2 → finalized. Yeh step kyun? Greedy invariant guarantee karta hai ki B tak koi chhota path exist nahi karta.
  • C 5→3 KYUN ho gaya? B ki edge relax karne par: . Kyun? Path A→B→C, A→C direct se better hai.
  • D = 6 kyun, 9 kyun nahi? C finalize hone ke baad, C→D relax karo: . Kyun? C se jaana B se jaane se sasta hai.

A se final shortest paths: B(2), C(3, via B), D(6, via B,C).


Worked Example 2 — OSPF kya store karta hai

Maano router A ki Dijkstra ke baad table: D tak pahunchne ke liye, first hop B hai (kyunki path A→B→C→D hai).

  • Sirf next hop kyun store karo, poora path kyun nahi? Yeh step kyun? Forwarding hop-by-hop hoti hai; A ko sirf yeh jaanna chahiye ki packet kaunse neighbor ko dena hai. B ko apna khud ka next hop pata hoga, aur aage bhi aise hi. Yahi destination → next-hop forwarding table hai.

Common mistakes


Active recall

Recall Khud test karo (answers chhupao)
  • Link state routing ke 5 steps kya hain?
  • Dijkstra ko non-negative weights KYUN chahiye?
  • Ek LSP mein kya hota hai?
  • Flooding ko sequence numbers KYUN chahiye?
  • OSPF kiske upar chalta hai (protocol)?
Link state routing mein har router kya flood karta hai?
Apna Link State Packet (LSP): apni ID aur (neighbor, link-cost) pairs ki list.
Assembled topology par har router kaunsa algorithm chalta hai?
Dijkstra's shortest-path algorithm, khud ko source maanke.
Dijkstra mein relaxation rule batao.
.
Dijkstra ke edge weights non-negative KYUN hone chahiye?
Kyunki greedy step assume karta hai ki ek finalized node ki distance kabhi decrease nahi ho sakti; ek negative edge baad mein use shorten kar sakta hai, correctness tod ke.
Distance-vector ki kaunsi problem link state avoid karta hai?
Count-to-infinity / slow convergence aur routing loops.
OSPF ka full form kya hai aur yeh kahan chalta hai?
Open Shortest Path First; ek intra-domain IGP jo directly IP ke upar chalta hai (protocol number 89).
LSPs sequence numbers aur age KYUN carry karte hain?
Sirf newest copy rakhne ke liye, infinite flooding loops rokne ke liye, aur stale topology info expire karne ke liye.
Binary heap ke saath Dijkstra ki time complexity?
.
Forwarding table mein har router actually kya store karta hai?
Destination → next-hop (shortest path par pehla neighbor), poora path nahi.
Ek line mein LS vs DV?
LS = poora map share karo, akele compute karo (Dijkstra); DV = computed distances share karo, neighbors par bharosa karo (Bellman–Ford).

Recall Feynman: ek 12 saal ke bachche ko explain karo

Har router sabko ek chhoti si chit bhejta hai jisme likha hota hai "mere paas wali roads aur unki lambai ye hai." Jab sabne sabki chits padh li, toh har ek poora sheher ka naqsha bana leta hai. Phir, ek clever rule use karke, har router har jagah ka shortest rasta figure out karta hai — hamesha sabse kareeb wali incomplete jagah ko pehle pick karte hue, jaise maze explore karna hamesha sabse nazdik wale unexplored kamre mein qadam rakhke. Kyunki sab ek hi naqsha use karte hain, koi packets circles mein nahi bhejta.


Connections

  • Distance Vector Routing — alternative (Bellman–Ford, count-to-infinity)
  • Dijkstra's Algorithm — graph algorithm jo yahan reuse hoti hai
  • Bellman–Ford Algorithm — jab weights negative ho sakti hain
  • Flooding — reliable LSP distribution mechanism
  • OSPF Areas — link state ko bade networks par scale karna
  • BGP — inter-domain routing (path-vector, intra-domain OSPF se contrast)
  • Routing Table vs Forwarding Table

Concept Map

suffers

motivates

step 1-2

step 3

step 4

uses

keeps newest, expires stale

assembled into

step 5, run

core operation

greedy invariant needs

produces

standard implementation

Distance-Vector RIP

Count-to-Infinity

Link State Routing

Discover neighbors and costs

Build Link State Packet

Reliable Flooding

Sequence numbers and age

Full Topology Map

Dijkstra's Algorithm

Relaxation rule

Non-negative weights

Routing Table

OSPF over IP 89