1. A Link-State Routing Algorithm
Dijkstra’s algorithm Notation:
❒ net topology, link costs ❒ c(x,y): link cost from node
known to all nodes x to y; = ∞ if not direct
❍ accomplished via “link neighbors
state broadcast”
❒ D(v): current value of cost
❍ all nodes have same info of path from source to
❒ computes least cost paths dest. v
from one node (‘source”) to
❒ p(v): predecessor node
all other nodes
along path from source to v
❍ gives forwarding table
for that node ❒ N': set of nodes whose
least cost path definitively
❒ iterative: after k
known
iterations, know least cost
path to k dest.’s
Network Layer 4-75
2. 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'
Network Layer 4-76
3. Dijkstra’s algorithm: 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
v 3 w
2 5
u 2 1 z
3
1 2
x 1
y
Network Layer 4-77
4. Dijkstra’s algorithm: example (2)
Resulting shortest-path tree from u:
v w
u z
x y
Resulting forwarding table in u:
destination link
v (u,v)
x (u,x)
y (u,x)
w (u,x)
z (u,x)
Network Layer 4-78
5. Dijkstra’s algorithm, discussion
Algorithm complexity: n nodes
❒ each iteration: need to check all nodes, w, not in N
❒ n(n+1)/2 comparisons: O(n2)
❒ more efficient implementations possible: O(nlogn)
Oscillations possible:
❒ e.g., link cost = amount of carried traffic
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 1+e 1 B
1+e 1 0 0
0 e 0 0 1 1+e 0 e
1
C C C C
1
e
… recompute … recompute … recompute
initially
routing
Network Layer 4-79