13 – Routing Algorithms
Network Layer 4-1
Graph abstraction
5
3
v w 5
2
u 2 1 z
3
1 2
x 1
y
Graph: G = (N,E)
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) }
Remark: Graph abstraction is useful in other network contexts
Example: P2P, where N is set of peers and E is set of TCP connections
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
Cost of path (x1, x2, x3,…, xp) = c(x1,x2) + c(x2,x3) + … + c(xp-1,xp)
Question: What’s the least-cost path between u and z ?
Routing algorithm: algorithm that finds least-cost path
3
Routing Algorithm classification
Global or decentralized information?
Global:
• all routers have complete topology, link cost info
• “link state” algorithms
• Eg. OSPF
Decentralized:
• router knows physically-connected neighbors, link costs to neighbors
• iterative process of computation, exchange of info with neighbors
• “distance vector” algorithms
• Eg. RIP, BGP
4
LINK STATE ALGORITHMS
5
A Link-State Routing Algorithm
Dijkstra’s algorithm Notation:
• net topology, link costs known to • c(x,y): link cost from node x to
all nodes y; = ∞ if not direct neighbors
– accomplished via “link state
• D(v): current value of cost of
broadcast”
path from source to dest. v
– all nodes have same info
• p(v): predecessor node along
• computes least cost paths from
path from source to v
one node (‘source”) to all other
nodes • N': set of nodes whose least cost
– gives forwarding table for path definitively known
that node
• iterative: after k iterations, know
least cost path to k dest.’s
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
Resulting forwarding table in u:
destination link
v (u,v)
x (u,x)
y (u,x)
w (u,x)
z (u,x)
12
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 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
DISTANCE VECTOR ALGORITHMS
14
Distance Vector Algorithm
Bellman-Ford Equation (dynamic programming)
Define
dx(y) := cost of least-cost path from x to y
Then
dx(y) = minv {c(x,v) + dv(y) }
where min is taken over all neighbors v of x
15
Distance Vector Algorithm
• Dx(y) = estimate of least cost from x to y
– x maintains distance vector Dx = [Dx(y): y є N ]
• node x:
– knows cost to each neighbor v: c(x,v)
– maintains its neighbors’ distance vectors. For each
neighbor v, x maintains
Dv = [Dv(y): y є N ]
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
under minor, natural conditions, the estimate Dx(y)
converge to the actual least cost dx(y)
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