← all topics

12 · Distance vector (Bellman-Ford), link cost changes, LS vs DV ★

Slides 5-14 → 5-23 · K&R 5.2.2 · HW6 P5, P7 · Sample midterm Problem 3

Bellman-Ford equation (5-14)

dx(y) = min over all neighbors v of x { c(x,v) + dv(y) }
                                         ^^^^^^   ^^^^^
                          cost to neighbor v      cost from neighbor v to destination y

Slide example (5-15)

Graph of 5-6. u's neighbors: v (cost 2), x (cost 1), w (cost 5). Given dv(z) = 5, dx(z) = 3, dw(z) = 3:

du(z) = min { c(u,v) + dv(z),  c(u,x) + dx(z),  c(u,w) + dw(z) }
      = min { 2 + 5,           1 + 3,           5 + 3 }
      = min { 7, 4, 8 } = 4     → next hop x

What each node stores (5-16, 5-17)

The DV loop (5-18)

each node:
   wait     for (change in local link cost  or  DV message from a neighbor)
   recompute estimates (B-F for every destination)
   if DV to any destination changed → notify neighbors
   (loop)

Slide walk-through: x, y, z (5-19, 5-20)

Links: c(x,y) = 2, c(y,z) = 1, c(x,z) = 7. Each table: rows = "from" (whose vector), columns = "cost to" x y z.

Round 0: each node knows only its own links

node x        node y        node z
   x y z         x y z         x y z
x  0 2 7      x  ∞ ∞ ∞      x  ∞ ∞ ∞
y  ∞ ∞ ∞      y  2 0 1      y  ∞ ∞ ∞
z  ∞ ∞ ∞      z  ∞ ∞ ∞      z  7 1 0

Each node sends its own row to its neighbors.

Round 1: each node copies in its neighbors' rows and recomputes its own

x:  Dx(y) = min{c(x,y)+Dy(y), c(x,z)+Dz(y)} = min{2+0, 7+1} = 2
    Dx(z) = min{c(x,y)+Dy(z), c(x,z)+Dz(z)} = min{2+1, 7+0} = 3   ← changed (was 7)
y:  Dy(x) = min{2+0, 1+7} = 2;   Dy(z) = min{1+0, 2+7} = 1          ← no change
z:  Dz(x) = min{c(z,y)+Dy(x), c(z,x)+Dx(x)} = min{1+2, 7+0} = 3     ← changed (was 7)
    Dz(y) = min{1+0, 7+2} = 1

node x        node y        node z
   x y z         x y z         x y z
x  0 2 3      x  0 2 7      x  0 2 7
y  2 0 1      y  2 0 1      y  2 0 1
z  7 1 0      z  7 1 0      z  3 1 0

x and z changed, so they send their new vectors. y did not change, so y sends nothing new.

Round 2: everyone has the final vectors

node x        node y        node z
   x y z         x y z         x y z
x  0 2 3      x  0 2 3      x  0 2 3
y  2 0 1      y  2 0 1      y  2 0 1
z  3 1 0      z  3 1 0      z  3 1 0

Recomputing gives no change anywhere, so no more messages. Converged. Note x reaches z via y (cost 3), not over the direct 7 link.

Link cost changes (5-21, 5-22)

Topology on both slides: c(x,y) = 4, c(y,z) = 1, c(x,z) = 50. Before the change: Dy(x) = 4 (direct), Dz(x) = 5 (via y).

Good news travels fast (5-21): c(x,y) 4 → 1

t0: y detects the change. Dy(x) = min{1+0, 1+5} = 1. DV changed → y informs neighbors.
t1: z gets y's DV. Dz(x) = min{c(z,y)+Dy(x), c(z,x)} = min{1+1, 50} = 2. Changed → z sends its DV.
t2: y gets z's DV. Dy(x) = min{1, 1+2} = 1. No change → y does NOT send to z. Done.

Bad news travels slow, "count to infinity" (5-22): c(x,y) 4 → 60

t0: y detects 60. Dy(x) = min{60+0, c(y,z)+Dz(x)} = min{60, 1+5} = 6   ← via z!
    But z's 5 was a path THROUGH y. Routing loop: y → z → y.
t1: z gets Dy(x)=6. Dz(x) = min{50, 1+6} = 7
t2: y gets Dz(x)=7. Dy(x) = min{60, 1+7} = 8
t3: z: min{50, 1+8} = 9
    ... each pair of messages adds 2 ...
end: z's cost via y finally exceeds 50, so z switches to its direct link.
     Final: Dz(x) = 50 (direct), Dy(x) = 51 (via z).

Poisoned reverse (5-22)

LS vs DV (5-23)

Link state (LS)Distance vector (DV)
Message complexityn routers, O(n²) messages sentExchange between neighbors only; convergence time varies
Speed of convergenceO(n²) algorithm, O(n²) messages; may have oscillationsConvergence time varies; may have routing loops; count-to-infinity problem
Robustness (router malfunctions or is compromised)Router can advertise an incorrect link cost; each router computes only its own table, so damage is limitedRouter can advertise an incorrect path cost ("I have a really low cost path to everywhere"): black-holing; each router's table is used by others, so errors propagate through the network

How to solve: one round of a DV update (sample midterm P3)

  1. List N1's link cost to each neighbor: c(N1,v).
  2. List each neighbor's reported cost to the destination: Dv(dest).
  3. For each neighbor compute c(N1,v) + Dv(dest).
  4. New cost = the minimum. Next hop = the neighbor that gave it.
  5. Recompute from scratch. Don't keep the old table value just because it was smaller: it was built from old reports.

Worked: sample midterm Problem 3

Q (sample midterm P3): The following tables are used in a distance-vector routing algorithm (the cost may be asymmetric). Node 1's routing table before the update (destination: cost, next node) is: 1: 0, –; 2: 2, 2; 3: 5, 3; 4: 1, 4; 5: 6, 3; 6: 7, 4 (shown below). Node 1 has three neighbors N2, N3, and N4. After one moment, N1 receives: N2 tells N1 its cost to N6 has changed to 7; N3 tells N1 its cost to N6 has changed to 3; N4 tells N1 its cost to N6 has changed to 9. N1 updates its routing table. After one round of the algorithm, in the new table, what is the cost from N1 to N6, and which node should be the next node to achieve that cost?

DestCostNext
10–
222
353
414
563
674

Neighbors N2, N3, N4 with costs from N1 of 2, 5, 1 (rows 2, 3, 4). New reports for N6: N2 → 7, N3 → 3, N4 → 9.

via N2: c(1,2) + D2(6) = 2 + 7 = 9
via N3: c(1,3) + D3(6) = 5 + 3 = 8   ← min
via N4: c(1,4) + D4(6) = 1 + 9 = 10

D1(6) = min{9, 8, 10} = 8, next hop N3

Answer: cost 8, next node N3. The old entry (7 via N4) is gone: it was 1 + 6 from N4's old report, and N4 now says 9.

Worked: HW6 P5 (z's table from start to stable)

Q (HW6 P5): Consider the network with nodes u, v, x, y, z and undirected link costs u–v 1, u–y 2, v–x 3, v–z 6, x–y 3, x–z 2. Assume each node initially knows the costs to each of its neighbors. Using the distance-vector algorithm, show the distance table entries at node z. Give z's table entries at each step of the algorithm, from initialization until it stabilizes.

Link costs (HW6 figure)
u–v 1, u–y 2, v–x 3, v–z 6, x–y 3, x–z 2

z's neighbors are v (cost 6) and x (cost 2), so z's table has rows v, x, z. Every z entry is Dz(d) = min{ 6 + Dv(d), 2 + Dx(d) }.

Snapshot 1: initialization

from \ cost touvxyz
v∞∞∞∞∞
x∞∞∞∞∞
z∞62∞0

z knows only its own link costs. u and y are not neighbors → ∞. Neighbors' rows unknown → ∞.

Snapshot 2: z receives v's and x's initial vectors

from \ cost touvxyz
v103∞6
x∞3032
z75250
v's initial row: its own links u 1, x 3, z 6; y not adjacent → ∞
x's initial row: its own links v 3, y 3, z 2; u not adjacent → ∞
Dz(u) = min{6+1, 2+∞} = 7
Dz(v) = min{6+0, 2+3} = 5     (via x beats the direct 6)
Dz(x) = min{6+3, 2+0} = 2
Dz(y) = min{6+∞, 2+3} = 5

Snapshot 3: v and x have updated too and send new vectors

from \ cost touvxyz
v10335
x43032
z65250
v learned from u (u–y 2):  Dv(y) = 1+2 = 3;  from x (x–z 2): Dv(z) = 3+2 = 5
x learned from v (v–u 1):  Dx(u) = min{3+1, 3+2 (via y)} = 4
z recomputes:
Dz(u) = min{6+1, 2+4} = 6     (now via x)
Dz(v) = min{6+0, 2+3} = 5
Dz(x) = min{6+3, 2+0} = 2
Dz(y) = min{6+3, 2+3} = 5

Snapshot 4: stable

Identical to snapshot 3. No vector changes, so no more messages. z's final DV: u 6, v 5, x 2, y 5, z 0, all via x.

Worked: HW6 P7 (when does x tell its neighbors?)

Q (HW6 P7): Consider a network fragment where x has only two attached neighbors, w and y, with link costs c(x,w) = 2, c(w,y) = 2, c(x,y) = 5. w has a minimum-cost path to destination u (not shown) of 5, and y has a minimum-cost path to u of 6. The complete paths from w and y to u (and between w and y) are not shown. All link costs in the network are strictly positive integers.

  1. (a) Give x's distance vector for destinations w, y, and u.
  2. (b) Give a link-cost change for either c(x,w) or c(x,y) such that x will inform its neighbors of a new minimum-cost path to u as a result of running the distance-vector algorithm.
  3. (c) Give a link-cost change for either c(x,w) or c(x,y) such that x will not inform its neighbors of a new minimum-cost path to u as a result of running the distance-vector algorithm.

a. x's distance vector

Dx(w) = min{c(x,w), c(x,y)+Dy(w)} = min{2, 5+2} = 2
Dx(y) = min{c(x,y), c(x,w)+Dw(y)} = min{5, 2+2} = 4     (via w)
Dx(u) = min{c(x,w)+Dw(u), c(x,y)+Dy(u)} = min{2+5, 5+6} = 7   (via w)

Dx(w) = 2, Dx(y) = 4, Dx(u) = 7.

b. A change that makes x inform its neighbors (official)

c. A change that does NOT make x inform its neighbors

Any change in c(x,y) (keeping c(x,y) ≥ 1). Example: c(x,y) = 1 gives via y = 1 + 6 = 7, a tie with via w: Dx(u) stays 7. No new least cost to u, so no message about u.

Traps
• Add the link cost to the neighbor before taking the min. The neighbor's report alone is not your cost.
• Recompute from the latest reports. If your current next hop reports a worse cost, your cost goes up, even if the old table value was lower.
• The min is only over neighbors. A non-neighbor's vector never appears in your table.
• HW6 P7: Dx(u) via y uses c(x,y) = 5 + 6 = 11, not Dx(y) = 4 + 6. B-F uses the direct link cost to the neighbor.
• A node sends only if its own DV changed. Receiving a message does not by itself trigger sending.
• Good news (cost drops) converges in a couple of messages; bad news (cost rises) can count up slowly. Know which is which.
• Poisoned reverse does not solve loops of 3 or more nodes.

Quick check

1. Write the Bellman-Ford equation and say what each term is. dx(y) = minv{ c(x,v) + dv(y) }, min over all neighbors v of x. c(x,v) = cost to neighbor v; dv(y) = v's least cost to y. The v that wins is the next hop.
2. When does a DV node send its vector to its neighbors? Only when its own DV changed, after a local link cost change or a neighbor's DV update.
3. Sample P3 variant: same N1 table and link costs (N2 2, N3 5, N4 1). Reports for N6: N2 → 4, N3 → 6, N4 → 8. New cost and next hop?
via N2: 2 + 4 = 6   ← min
via N3: 5 + 6 = 11
via N4: 1 + 8 = 9
Cost 6, next hop N2.
4. Sample P3 variant: reports for N6: N2 → 9, N3 → 6, N4 → 8. The old entry was 7 via N4. New cost and next hop?
via N2: 2 + 9 = 11
via N3: 5 + 6 = 11
via N4: 1 + 8 = 9   ← min
Cost 9, next hop N4. It is worse than the old 7, but the old 7 was built on N4's old report (6). N1 must use the current reports.
5. Sample P3 variant with different link costs: c(N1,N2) = 3, c(N1,N3) = 4, c(N1,N4) = 6. Reports for N6: N2 → 10, N3 → 8, N4 → 3. New cost and next hop?
via N2: 3 + 10 = 13
via N3: 4 + 8  = 12
via N4: 6 + 3  = 9   ← min
Cost 9, next hop N4.
6. Count to infinity: c(x,y) = 3, c(y,z) = 1, c(x,z) = 20. Converged, then c(x,y) jumps to 40. Trace Dy(x) and Dz(x) to the end. Before: Dy(x) = 3 (direct), Dz(x) = min{20, 1+3} = 4 via y.
y: min{40, 1+4}  = 5   (via z: loop)
z: min{20, 1+5}  = 6
y: 7    z: 8    y: 9    z: 10   y: 11   z: 12
y: 13   z: 14   y: 15   z: 16   y: 17   z: 18
y: 19   z: min{20, 1+19} = 20
y: min{40, 1+20} = 21
z: min{20, 1+21} = 20  (direct) → no change, stop
Final: Dz(x) = 20 (direct link), Dy(x) = 21 (via z). y updated 9 times (5, 7, …, 21) because each exchange only adds 2.
7. Same slide topology (4, 1, 50). With poisoned reverse, c(x,y) goes 4 → 60. What happens? z routes to x via y, so z had told y Dz(x) = ∞. y: min{60, 1+∞} = 60 direct. z: min{50, 1+60} = 50 direct, and now tells y the truth (50). y: min{60, 1+50} = 51 via z, and poisons back to z. z stays 50. Done in a few messages, no count to infinity.
8. Slide topology (4, 1, 50), c(x,y) drops 4 → 2. Trace the messages. t0: y: Dy(x) = min{2, 1+5} = 2, changed → sends. t1: z: Dz(x) = min{50, 1+2} = 3, changed → sends. t2: y: min{2, 1+3} = 2, no change → no message. Converged after 2 messages ("good news travels fast").
9. Slide 5-15 graph, but c(u,x) rises from 1 to 6 (dv(z) = 5, dx(z) = 3, dw(z) = 3 unchanged). du(z)? min{2+5, 6+3, 5+3} = min{7, 9, 8} = 7, next hop v.
10. Does poisoned reverse solve count to infinity completely? No. It stops loops between two neighbors only. Loops involving 3 or more nodes are not detected.
11. Robustness: what can a bad router do in LS vs DV? LS: advertise a wrong link cost; each router still computes only its own table. DV: advertise a wrong path cost ("really low cost to everywhere") → black-holing, and the error propagates because every router's table is used by others.
12. What do "iterative, asynchronous, distributed" mean for DV? Iterative/asynchronous: each local iteration is caused by a local link cost change or a neighbor's DV message, not a global clock. Distributed: each node computes from neighbor info and notifies neighbors only when its DV changes.
13. In the x/y/z walk-through (2, 1, 7), why doesn't y send anything after round 1? Its vector stayed [2 0 1]: min{2+0, 1+7} = 2 and min{1+0, 2+7} = 1. No change → no message.

← prev · all topics · next →