13 - Routing Algorithms: Network Layer 4-1
13 - Routing Algorithms: Network Layer 4-1
N = set of routers = { u, v, w, x, y, z }
E = set of links ={ (u,v), (u,x), (u,w), (v,x), (v,w), (x,w), (x,y), (w,y), (w,z), (y,z) }
2
Graph abstraction: costs
5 • c(x,x’) = cost of link (x,x’)
3
v w 5
2 - e.g., c(w,z) = 5
u 2 1 z
3 • cost could always be 1, or
1 2 inversely related to bandwidth,
x 1
y
or directly related to
congestion
4
LINK STATE ALGORITHMS
5
A Link-State Routing Algorithm
6
Animation
• Draw the resulting shortest path graph at the
end of the Animation.
7
Find the shortest path to all nodes from u.
3
v w
2 5
u 2 z
1
3
1
2
x y
1
8
Dijsktra’s Algorithm
1 Initialization:
2 N' = {u}
3 for all nodes v
4 if v adjacent to u
5 then D(v) = c(u,v)
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'
9
Dijkstra’s algorithm: example
D(v) D(w) D(x) D(y) D(z)
Step N' p(v) p(w) p(x) p(y) p(z)
0 u 7,u 3,u 5,u ∞ ∞
1 uw 6,w 5,u 11,w ∞
2 uwx 6,w 11,w 14,x
3 uwxv 10,v 14,x
4 uwxvy 12,y
5 uwxvyz x
9
Notes: 5 7
4
construct shortest path tree by
8
tracing predecessor nodes
3 w z
ties can exist (can be broken u y
2
arbitrarily)
3
7 4
v
10
Dijkstra’s algorithm: another example
Step N' D(v),p(v) D(w),p(w) D(x),p(x) D(y),p(y) D(z),p(z)
0 u 2,u 5,u 1,u ∞ ∞
1 ux 2,u 4,x 2,x ∞
2 uxy 2,u 3,y 4,y
3 uxyv 3,y 4,y
4 uxyvw 4,y
5 uxyvwz
5
3
v w 5
2
u 2 1 z
3
1 2
x 1
y
11
Dijkstra’s algorithm: example (2)
Resulting shortest-path tree from u:
v w
u z
x y
1 A A A A
1+e 2+e 0 0 2+e 2+e 0
D 0 0 B D B D B D B
1+e 1 0 0 1+e 1
0 e 0 0 1 1+e 0 e
1
C C C C
1
e
… recompute … recompute … recompute
initially
routing
13
Bellman Ford
14
Distance Vector Algorithm
Bellman-Ford Equation (dynamic programming)
Define
dx(y) := cost of least-cost path from x to y
Then
16
Distance vector algorithm (4)
Basic idea:
• from time-to-time, each node sends its own distance
vector estimate to neighbors
• when x receives new DV estimate from neighbor, it
updates its own DV using B-F equation:
Dx(y) ← minv{c(x,v) + Dv(y)} for each node y ∊ N
17
Dx(z) = min{c(x,y) +
Dx(y) = min{c(x,y) + Dy(y), c(x,z) + Dz(y)}
= min{2+0 , 7+1} = 2 Dy(z), c(x,z) + Dz(z)}
node x table = min{2+1 , 7+0} = 3
cost to cost to
x y z x y z
x 0 2 7 x 0 2 3
from
from
y ∞∞ ∞ y 2 0 1
z ∞∞ ∞ z 7 1 0
node y table
cost to
x y z y
2 1
x ∞∞ ∞
x z
from
y 2 0 1 7
z ∞∞ ∞
node z table
cost to
x y z
x ∞∞ ∞
from
y ∞∞ ∞
z 7 1 0
time
18
Dx(y) = min{c(x,y) + Dy(y), c(x,z) + Dz(y)} Dx(z) = min{c(x,y) +
= min{2+0 , 7+1} = 2 Dy(z), c(x,z) + Dz(z)}
node x table = min{2+1 , 7+0} = 3
cost to cost to cost to
x y z x y z x y z
x 0 2 7 x 0 2 3 x 0 2 3
from
from
from
y ∞∞ ∞ y 2 0 1 y 2 0 1
z ∞∞ ∞ z 7 1 0 z 3 1 0
node y table
cost to cost to cost to
x y z x y z x y z y
2 1
x ∞∞ ∞ x 0 2 7 x 0 2 3 x z
from
from
from
y 2 0 1 y 2 0 1 y 7
2 0 1
z ∞∞ ∞ z 7 1 0 z 3 1 0
node z table
cost to cost to cost to
x y z x y z x y z
x ∞∞ ∞ x 0 2 7 x 0 2 3
from
from
from
y ∞∞ ∞ y 2 0 1 y 2 0 1
z 7 1 0 z 3 1 0 z 3 1 0
time
19
Comparison of LS and DV algorithms
Message complexity Robustness: what happens if
• LS: with n nodes, E links, O(nE) router malfunctions?
msgs sent LS:
• DV: exchange between neighbors – node can advertise incorrect
only
link cost
– convergence time varies
– each node computes only its
Speed of Convergence own table
• LS: O(n2) algorithm requires O(nE) DV:
msgs – DV node can advertise
– may have oscillations incorrect path cost
• DV: convergence time varies – each node’s table used by
– may be routing loops others
– count-to-infinity problem • error propagate thru network
20