4.3.15Computer Networks

Distance vector routing — RIP, Bellman-Ford, count-to-infinity

2,434 words11 min readdifficulty · medium2 backlinks

WHAT is Distance Vector Routing?

Contrast this with Link-State routing (OSPF), where every router knows the whole topology. DV trades global knowledge for simplicity: "tell only neighbours, tell them everything."

WHY share with neighbours only? Because a router can only physically measure the cost to its direct neighbours (link cost). Everything beyond that must be learned second-hand. So information ripples outward, one hop per exchange.


HOW: deriving the Bellman-Ford update from scratch

Let dx(y)d_x(y) = the cheapest cost from node xx to node yy. Let c(x,v)c(x,v) = the cost of the direct link from xx to its neighbour vv.

Step 1 — first principles. Any path from xx to yy (with yxy\neq x) must leave xx through some neighbour vv. Once you commit to leaving via vv, the best you can do afterward is dv(y)d_v(y) (the best vv itself can do to reach yy).

Step 2 — cost of going via vv. cost via v=c(x,v)+dv(y)\text{cost via } v = c(x,v) + d_v(y) Why this step? The total = (price to step onto vv) + (best price vv knows to finish the journey).

Step 3 — pick the best neighbour. Since we want the cheapest path and we don't know which neighbour is best, we minimise over all neighbours:

Why is this correct? It's just the principle of optimality: a shortest path's sub-paths are also shortest. If the best route to yy goes xvyx\to v\to\ldots\to y, then the vyv\to\ldots\to y portion must itself be vv's shortest route to yy — otherwise we could swap in a cheaper tail and beat our own "shortest" path (contradiction).

The distributed twist: node xx doesn't compute dv(y)d_v(y) itself — vv tells xx its current estimate Dv(y)D_v(y) in its distance-vector message. So in practice each router runs: Dx(y)minv{c(x,v)+Dx(v)(y)}D_x(y) \leftarrow \min_{v}\{\, c(x,v) + D_x^{(v)}(y)\,\} where Dx(v)(y)D_x^{(v)}(y) is the latest estimate of dv(y)d_v(y) that xx received from vv. Whenever any Dx()D_x(\cdot) changes, xx broadcasts its new vector to neighbours.

Figure — Distance vector routing — RIP, Bellman-Ford, count-to-infinity

RIP — the real-world DV protocol

Key RIP facts (WHY they exist):

Feature Value Why
Metric hop count (1 per link) simple, no bandwidth measurement needed
Max valid cost 15 a cost of 16 = ∞ (unreachable) → caps count-to-infinity
Update period every 30 s periodic full-vector broadcast to neighbours
Route timeout 180 s if no update in 6 periods, route declared dead
Transport UDP 520 lightweight; lost updates fixed by next period

The Count-to-Infinity Problem

HOW it happens (WHY each step): Consider A — B — C, all link costs 1.

  • Steady state: BB reaches CC at cost 1 (direct); AA reaches CC at cost 2 via B.
  • The link B–C breaks.
  • BB should now see CC as unreachable. But AA recently told BB: "I can reach C at cost 2!" — BB doesn't know AA's route to C went through B itself.
  • So BB concludes: "I'll reach C via A: cost =1+2=3= 1 + 2 = 3." (WRONG — that path loops BABB\to A\to B.)
  • BB tells AA "C is at 3", so AA updates to "C via B at 1+3=41+3 = 4"… and they ping-pong: 5, 6, 7 … up to 16 = ∞.

The root cause: a router advertises a route back to the very neighbour it learned it from.

Fixes


Worked Example 1 — one Bellman-Ford update

Network: A—B=2, B—C=3, A—C=7. Find AA's cost to CC.

  • AA's neighbours: BB (cost 2) and CC (cost 7).
  • Via CC: c(A,C)+dC(C)=7+0=7c(A,C)+d_C(C) = 7 + 0 = 7. Why? Direct link to the destination.
  • Via BB: c(A,B)+dB(C)=2+3=5c(A,B)+d_B(C) = 2 + 3 = 5. Why? BB already advertised it reaches CC at 3.
  • dA(C)=min(7,5)=5d_A(C) = \min(7,5) = \mathbf{5}, next-hop =B= B. Why B? It's the cheaper of the two options.

Worked Example 2 — count-to-infinity trace

A—B—C, costs 1. Link B–C dies. Tables for "cost to C":

Exchange DB(C)D_B(C) DA(C)D_A(C) Why
before break 1 (direct) 2 (via B) steady state
break, no split horizon 3 (via A!) 2 B trusts A's stale "2"
next 3 4 (via B) A trusts B's "3"
5 6 ping-pong
eventually 16=∞ 16=∞ RIP cap halts it

Why this is the disaster: until they hit 16, packets to C loop A↔B forever.

Worked Example 3 — split horizon prevents it

Same break, with split horizon: AA learned C via B, so AA advertises "C = ∞" to BB. Now when B–C dies, BB has no false alternative (A told it ∞), so BB immediately marks C unreachable. Why it works: the looping estimate was never injected back.


Flashcards

What equation does distance vector routing implement?
The Bellman-Ford equation dx(y)=minv{c(x,v)+dv(y)}d_x(y)=\min_{v}\{c(x,v)+d_v(y)\}, run distributed/asynchronously.
In DV routing, what does each router send and to whom?
Its entire distance vector (table of dest→cost), to its directly connected neighbours only.
What metric and transport does RIP use?
Metric = hop count (1 per link); runs over UDP port 520.
In RIP, what cost value means "unreachable"?
16 (i.e. 16 = infinity); max valid hop count is 15.
What is count-to-infinity?
After a link breaks, routers bounce stale route estimates back and forth, incrementing cost step-by-step toward ∞ ("bad news travels slowly").
Root cause of count-to-infinity?
A router advertises a route back to the same neighbour it originally learned it from.
What is split horizon?
Never advertise a route back to the neighbour you learned it from (breaks 2-node loops).
What is poison reverse?
Advertise such a route back explicitly with cost 16 (∞) instead of omitting it.
Why doesn't split horizon fully solve count-to-infinity?
It only stops 2-node loops; loops of 3+ routers can still count to infinity, so the 16-cap is still needed.
How many exchanges until DV converges in an n-node network (no failures)?
At most n−1, since each exchange propagates correct info one extra hop.
RIP route timeout period?
180 s (route declared dead if no update for 6 × 30s periods).
Why does "good news travel fast but bad news slow"?
A cheaper new route is adopted in one step; a broken route persists because neighbours keep echoing stale optimistic costs.

Recall Feynman: explain to a 12-year-old

Imagine kids in a line, each only able to whisper to the kid next to them. You want everyone to know "how many steps to the candy shop." The kid at the shop says "0 steps." The next kid hears "0" and says "I'm 1 step." Each kid just adds 1 to the smallest number they hear and passes it on. Soon everyone knows their distance — without anyone seeing the whole map! The trouble: if the shop suddenly closes, a kid might still hear an old "I'm near the shop" whisper from a friend whose path actually went through him. So he thinks "oh, I'll go to the shop through my friend!" — but his friend was going through him. They keep adding 1, 1, 1… counting up forever. The rule "don't tell a friend about a route you learned from that friend" stops them being silly together.

Connections

Concept Map

is distributed version of

maintains

sends full vector to

because router measures

justified by

picks cheapest via

uses

uses learned

contrasts with

converges after k

slow bad-news causes

real protocol

Distance Vector Routing

Bellman-Ford Equation

Table dest cost next-hop

Direct neighbours only

Link cost c x v

Principle of optimality

min over neighbours

Estimate D_v y from v

Link-State OSPF full topology

k exchanges reach k hops

Count-to-infinity

RIP

Hinglish (regional understanding)

Intuition Hinglish mein samjho

Dekho, Distance Vector routing ka basic idea simple hai: har router sirf apne direct neighbours ko jaanta hai, aur unko bolta hai "main har destination tak kitni door hun." Phir har router apni table update karta hai ye formula se — Bellman-Ford: dx(y)=minv{c(x,v)+dv(y)}d_x(y)=\min_v\{c(x,v)+d_v(y)\}. Matlab "destination tak jaane ka cost = neighbour tak pahunchne ka cost + woh neighbour aage jitna cost bolta hai", aur sabse sasta wala option choose karo. Koi bhi router pura network map nahi dekhta — info dheere-dheere hop-by-hop spread hoti hai. Isiliye nn nodes ke liye max n1n-1 rounds mein sab converge ho jaata hai.

RIP isi ka real protocol hai: metric = hop count (har link = 1), chalta hai UDP port 520 par, har 30 second mein full table neighbours ko bhejta hai, aur 16 ka matlab infinity (unreachable) hota hai. Ye 16-cap jaan-bujhkar lagaya gaya hai taaki ek nasty problem control mein rahe.

Woh problem hai count-to-infinity. Funda: "good news fast, bad news slow." Jab koi link toot jaata hai, toh ek router apne dead route ko bhool nahi paata kyunki uska neighbour purana optimistic cost wapas bhej deta hai — aur dono ek-doosre ko 1, 1, 1 add karke cost badhate rehte hain, infinity tak. Root cause: router usi neighbour ko route advertise karta hai jisse usne woh route seekha tha.

Iska fix hai Split Horizon — jis neighbour se route seekha, usi ko us route ke baare mein mat batao (ya Poison Reverse mein cost 16 bhej do). Par yaad rakhna: split horizon sirf 2-node loop fix karta hai; 3+ routers ke ring mein bug phir bhi aa sakta hai, isiliye RIP ko 16-cap bhi chahiye. Exam mein ye distinction bahut poocha jaata hai!

Go deeper — visual, from zero

Test yourself — Computer Networks

Connections