You are on page 1of 15

Link-State and Distance Vector Routing Examples

CPSC 441 University of Calgary

Link-State (LS) Routing Algorithm


Dijkstras algorithm topology and link costs known to all nodes accomplished via link state broadcast all nodes have same info computes least cost paths from one node (source) to all other nodes gives forwarding table for that node iterative: after k iterations, know least cost path to k destination nodes

Notation: c(x,y): link cost from node x to y; set to if a and y are not direct neighbors D(v): current value of cost of path from source to dest. v p(v): vs predecessor node along path from source to v N': set of nodes whose least cost path is definitively known

Dijsktras Algorithm
1 Initialization (u = source node): 2 N' = {u} /* path to self is all we know */ 3 for all nodes v 4 if v adjacent to u 5 then D(v) = c(u,v) /* assign link cost to neighbours */ 6 else D(v) = 7 8 Loop 9 find w not in N' such that D(w) is a minimum 10 add w to N' 11 update D(v) for all v adjacent to w and not in N' : 12 D(v) = min( D(v), D(w) + c(w,v) ) 13 /* new cost to v is either old cost to v or known 14 shortest path cost to w plus cost from w to v */ 15 until all nodes in N'
3

Textbook Problem 4.21 x is source


14

y
6

4 1 3 1 1

v
1

9 2

x
Step 0 N x

s
4
D(u),p(u) D(v),p(v) D(w),p(w) D(y),p(y) D(z),p(z)

w
D(s),p(s)

u
3
D(t),p(t)

3,x

1,x

6,x

Initialization: - Store source node x in N - Assign link cost to neighbours (v,w,y) - Keep track of predecessor to destination node
4

Textbook Problem 4.21 x is source


14

y
6

4 1 3 1 1

v
1

9 2

Node and its minimum cost are colour-coded in each step

x
Step 0 1 N x xw

s
4
D(u),p(u) D(v),p(v) D(w),p(w) D(y),p(y) D(z),p(z)

w
D(s),p(s)

u
3
D(t),p(t)

4,w

3,x

2,w

1,x

6,x 6,x

Loop step 1: - For all nodes not in N, find one that has minimum cost path (1) - Add this node (w) to N - Update cost for all neighbours of added node that are not in N repeat until all nodes are in N
5

Textbook Problem 4.21 x is source


14

y
6

4 1 3 1 1

v
1

9 2

Node and its minimum cost are colour-coded in each step

x
Step 0 1 2 3 4 5 6 N x xw

s
4
D(u),p(u) D(v),p(v) D(w),p(w) D(y),p(y) D(z),p(z)

w
D(s),p(s)

u
3
D(t),p(t)

7,u 7,u 6,t

11,v 5,u 5,u

xwv

4,w 3,v

3,x

2,w

1,x

6,x 6,x 3,v 3,v

17,y 7,t 7,t

xwvu

xwvuy

xwvuyt

xwvuyts

Textbook Problem 4.21 x is source


14

y
6

4 1 3 1 1

v
1

9 2

x
Step 0 1 2 3 4 5 6 N x xw

s
4
D(u),p(u) D(v),p(v)

w
D(s),p(s)

u
3
D(t),p(t)

We can now build xs forwarding table. E.g. the entry to s will be constructed by looking at predecessors along shortest path: 6,t 5,u 3,v 2,w (direct link) So forward to s via w
D(w),p(w) D(y),p(y)

7,u 7,u 6,t

11,v 5,u 5,u

xwv

4,w 3,v

3,x

2,w

1,x

6,x 6,x 3,v 3,v

D(z),p(z)

17,y 7,t 7,t

xwvu

xwvuy

xwvuyt

xwvuyts

Distance Vector Routing


Based on Bellman-Ford Equation Define dx(y) := cost of least-cost path from x to y c(x,v) := cost of direct link from x to v Then, for all v that are neighbours of x dx(y) = minv {c(x,v) + dv(y) }
c(x,v)

dv(y) dx(y)

Bellman-Ford Equation Example


Consider a path from u to z By inspection, dv(z) = 5, dx(z) = 3, dw(z) = 3
5 2

B-F equation says:


3

v
2

w
3 1

u
1

z
2

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} = 4

Node that achieves minimum is next hop in shortest path entry in forwarding table
9

Distance Vector Algorithm


Basic idea: Nodes keep vector (DV) of least costs to other nodes
These are estimates, Dx(y)

On each node: wait for (change in local link


cost or msg from neighbor)

Each node periodically sends its own DV to neighbors When node x receives DV from neighbor, it keeps it and updates its own DV using B-F:
Dx(y) minv{c(x,v) + Dv(y)} for each node y N

recompute estimates
if DV has changed, notify neighbors

Ideally, the estimate Dx(y) converges to the actual least cost dx(y)
10

node x table cost to x y z from

x 0 2 7 y z node y table cost to x y z from

x y 2 0 1 z node z table cost to x y z x y z 7 1 0 from

Step 1: Initialization Initialize costs of direct links Set to costs from neighbours

y
7

time

11

node x table cost to x y z from

Dx(y) = min{c(x,y) + Dy(y), c(x,z) + Dz(y)} = min{2+0 , 7+1} = 2 cost to x y z

Dx(z)=min{c(x,y)+Dy(z), c(x,z)+Dz(z)} = min{2+1 , 7+0} = 3

x 0 2 7 y z node y table cost to x y z from

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

from

x y 2 0 1 z node z table cost to x y z x y z 7 1 0 from

Step 2: Exchange DV and iterate -In first iteration, node x saves neighbours DVs -Then, it checks path costs to all nodes using received DVs -E.g. new cost Dx(z) is obtained by adding costs marked red time

y
7

12

In similar fashion, algorithm proceeds until all nodes have updated tables node x table cost to x y z from cost to x y z from cost to x y z

x 0 2 7 y z node y table cost to x y z from

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

x y 2 0 1 z node z table cost to x y z x y z 7 1 0 from

x 0 2 7 y 2 0 1 z 7 1 0 x 0 2 7 y 2 0 1 z 3 1 0 cost to x y z

cost to x y z

x 0 2 3 y 2 0 1 z 3 1 0 x 0 2 3 y 2 0 1 z 3 1 0 cost to x y z cost to x y z 2

from

y
7

from

from

x 0 2 3 y 2 0 1 z 3 1 0 time

from

from

13

Distance Vector: link cost changes


Link cost changes:
node detects local link cost change updates routing info, recalculates distance vector if DV changes, notify neighbors
1

y
50

good news travels fast

At time t0, y detects the link-cost change, updates its DV, and informs its neighbors. At time t1, z receives the update from y and updates its table. It computes a new least cost to x and sends neighbors its DV.

At time t2, y receives zs update and updates its distance table. ys least costs do not change and hence y does not send any message to z.
14

Distance Vector: link cost changes


Link cost changes:
bad news travels slow - count to infinity problem! When y detects cost change to 60, it will update its DV using the zs cost to x, which is 5 (via y), to obtain an incorrect new cost to x of 6, over the path y z y x that has a loop 44 iterations before algorithm stabilizes, while y and z exchange updates
60 4

y
50

Poisoned reverse:
If Z routes through Y to get to X :
Z tells Y its (Zs) distance to X is infinite (so Y wont route to X via Z)

Will this completely solve the problem?


15

You might also like