ppt

advertisement
EE 122: Shortest Path Routing
Ion Stoica
TAs: Junda Liu, DK Moon, David Zats
http://inst.eecs.berkeley.edu/~ee122/fa09
(Materials with thanks to Vern Paxson, Jennifer Rexford,
and colleagues at UC Berkeley)
1
What is Routing?
Routing implements the core function of a
network:
It ensures that information accepted for transfer
at a source node is delivered to the correct set
of destination nodes, at reasonable levels of
performance.
2
Internet Routing


Internet organized as a two level hierarchy
First level – autonomous systems (AS’s)


AS’s run an intra-domain routing protocols



AS – region of network under a single administrative
domain
Distance Vector, e.g., Routing Information Protocol (RIP)
Link State, e.g., Open Shortest Path First (OSPF)
Between AS’s runs inter-domain routing protocols,
e.g., Border Gateway Routing (BGP)

De facto standard today, BGP-4
3
Example
Interior router
BGP router
AS-1
AS-3
AS-2
4
Forwarding vs. Routing

Forwarding: “data plane”



Directing a data packet to an outgoing link
Individual router using a forwarding table
Routing: “control plane”



Computing paths the packets will follow
Routers talking amongst themselves
Individual router creating a forwarding table
5
Know Thy Network


Routing requires knowledge of the network structure
Centralized global state




Distributed global state




Single entity knows the complete network structure
Can calculate all routes centrally
Link State Routing
E.g. Algorithm: Dijkstra
Problems with this approach?
Every router knows the complete network structure
Independently calculates routes
Distance Vector Routing
Problems with this approach?
E.g. Algorithm: Bellman-Ford
Distributed no-global state



E.g. Protocol: OSPF
E.g. Protocol: RIP
Every router knows only about its neighboring routers
Independently calculates routes
Problems with this approach?
6
Modeling a Network

Modeled as a graph
5
Routers  nodes
Link  edges
B



Possible edge costs


delay
congestion level
3
2
A
2
3
1
5
F
1
1
D

C
E
2
Goal of Routing


Determine a “good” path through the network from source
to destination
Good usually means the shortest path
7
Link State: Control Traffic


Each node floods its local information to every other node
in the network
Each node ends up knowing the entire network topology 
use Dijkstra to compute the shortest path to every other
node
Host C
Host D
Host A
N1
N2
N3
N5
Host B
Host E
N4
N6
N7
8
Link State: Node State
C
C
A
Host C
D
A
C
A
D
D
Host D
Host A
B
B
E
B
N2
N1
E
E
C
A
D
N3
C
A
D
B
E
N5
B
Host B
C
A
D
C
E
A
D
B
N4
N6
B
E
9
N7
Host EE
Notation

c(i,j): link cost from node i
to j; cost infinite if not
direct neighbors; ≥ 0
 D(v): current value of cost
of path from source to
destination v
 p(v): predecessor node
along path from source to
v, that is next to v
 S: set of nodes whose
least cost path definitively
known
5
B
3
C
2
A
2
3
Source
1
F
1
1
D
5
E
2
10
Dijsktra’s Algorithm

c(i,j): link cost from node i to j
D(v): current cost source  v
p(v): predecessor node along
1 Initialization:

2 S = {A};

3 for all nodes v
path from source to v, that is
4
if v adjacent to A
next to v
5
then D(v) = c(A,v);
 S: set of nodes whose least
6
else D(v) = ;
cost path definitively known
7
8 Loop
9
find w not in S such that D(w) is a minimum;
10 add w to S;
11 update D(v) for all v adjacent to w and not in S:
12
if D(w) + c(w,v) < D(v) then
// w gives us a shorter path to v than we’ve found so far
13
D(v) = D(w) + c(w,v); p(v) = w;
14 until all nodes in S;
11
Example: Dijkstra’s Algorithm
Step
0
1
2
3
4
5
D(B),p(B) D(C),p(C) D(D),p(D)
2,A
1,A
5,A
start S
A
5
2
A
B
2
1
D
3
C
3
1
5
F
1
E
2
D(E),p(E) D(F),p(F)


1 Initialization:
2 S = {A};
3 for all nodes v
4
if v adjacent to A
5
then D(v) = c(A,v);
6
else D(v) = ;
…
12
Example: Dijkstra’s Algorithm
Step
0
1
2
3
4
5
D(B),p(B) D(C),p(C) D(D),p(D)
2,A
1,A
5,A
start S
A
5
2
A
B
2
1
D
3
C
3
1
5
F
1
E
2
D(E),p(E) D(F),p(F)


…
8 Loop
9
find w not in S s.t. D(w) is a minimum;
10 add w to S;
11 update D(v) for all v adjacent
to w and not in S:
12 If D(w) + c(w,v) < D(v) then
13
D(v) = D(w) + c(w,v); p(v) = w;
14 until all nodes in S;
13
Example: Dijkstra’s Algorithm
Step
0
1
2
3
4
5
D(B),p(B) D(C),p(C) D(D),p(D)
2,A
1,A
5,A
start S
A
AD
5
2
A
B
2
1
D
3
C
3
1
5
F
1
E
2
D(E),p(E) D(F),p(F)


…
8 Loop
9
find w not in S s.t. D(w) is a minimum;
10 add w to S;
11 update D(v) for all v adjacent
to w and not in S:
12 If D(w) + c(w,v) < D(v) then
13
D(v) = D(w) + c(w,v); p(v) = w;
14 until all nodes in S;
14
Example: Dijkstra’s Algorithm
Step
0
1
2
3
4
5
D(B),p(B) D(C),p(C) D(D),p(D)
2,A
1,A
5,A
4,D
start S
A
AD
5
2
A
B
2
1
D
3
C
3
1
5
F
1
E
2
D(E),p(E) D(F),p(F)


2,D
…
8 Loop
9
find w not in S s.t. D(w) is a minimum;
10 add w to S;
11 update D(v) for all v adjacent
to w and not in S:
12 If D(w) + c(w,v) < D(v) then
13
D(v) = D(w) + c(w,v); p(v) = w;
14 until all nodes in S;
15
Example: Dijkstra’s Algorithm
Step
0
1
2
3
4
5
D(B),p(B) D(C),p(C) D(D),p(D) D(E),p(E) D(F),p(F)


2,A
1,A
5,A
4,D
2,D
3,E
4,E
start S
A
AD
ADE
5
2
A
B
2
1
D
3
C
3
1
5
F
1
E
2
…
8 Loop
9
find w not in S s.t. D(w) is a minimum;
10 add w to S;
11 update D(v) for all v adjacent
to w and not in S:
12 If D(w) + c(w,v) < D(v) then
13
D(v) = D(w) + c(w,v); p(v) = w;
14 until all nodes in S;
16
Example: Dijkstra’s Algorithm
Step
0
1
2
3
4
5
D(B),p(B) D(C),p(C) D(D),p(D) D(E),p(E) D(F),p(F)


2,A
1,A
5,A
4,D
2,D
3,E
4,E
start S
A
AD
ADE
ADEB
5
2
A
B
2
1
D
3
C
3
1
5
F
1
E
2
…
8 Loop
9
find w not in S s.t. D(w) is a minimum;
10 add w to S;
11 update D(v) for all v adjacent
to w and not in S:
12 If D(w) + c(w,v) < D(v) then
13
D(v) = D(w) + c(w,v); p(v) = w;
14 until all nodes in S;
17
Example: Dijkstra’s Algorithm
Step
0
1
2
3
4
5
D(B),p(B) D(C),p(C) D(D),p(D)
2,A
1,A
5,A
4,D
3,E
start S
A
AD
ADE
ADEB
ADEBC
5
2
A
B
2
1
D
3
C
3
1
5
F
1
E
2
D(E),p(E) D(F),p(F)


2,D
4,E
…
8 Loop
9
find w not in S s.t. D(w) is a minimum;
10 add w to S;
11 update D(v) for all v adjacent
to w and not in S:
12 If D(w) + c(w,v) < D(v) then
13
D(v) = D(w) + c(w,v); p(v) = w;
14 until all nodes in S;
18
Example: Dijkstra’s Algorithm
Step
0
1
2
3
4
5
D(B),p(B) D(C),p(C) D(D),p(D)
2,A
1,A
5,A
4,D
3,E
start S
A
AD
ADE
ADEB
ADEBC
ADEBCF
5
2
A
B
2
1
D
3
C
3
1
5
F
1
E
2
D(E),p(E) D(F),p(F)


2,D
4,E
…
8 Loop
9
find w not in S s.t. D(w) is a minimum;
10 add w to S;
11 update D(v) for all v adjacent
to w and not in S:
12 If D(w) + c(w,v) < D(v) then
13
D(v) = D(w) + c(w,v); p(v) = w;
14 until all nodes in S;
19
Example: Dijkstra’s Algorithm
Step
0
1
2
3
4
5
D(B),p(B) D(C),p(C) D(D),p(D)
2,A
1,A
5,A
4,D
3,E
start S
A
AD
ADE
ADEB
ADEBC
ADEBCF
5
2
A
B
2
1
D
3
C
3
1


2,D
4,E
To determine path A  C (say),
work backward from C via p(v)
5
F
1
E
D(E),p(E) D(F),p(F)
2
20
The Forwarding Table
•
•
Running Dijkstra at node A gives the shortest
path from A to all destinations
We then construct the forwarding table
5
2
A
B
2
1
D
3
C
3
1
5
Link
B
(A,B)
C
(A,D)
D
(A,D)
E
(A,D)
F
(A,D)
F
1
E
Destination
2
21
Complexity


How much processing does running the Dijkstra
algorithm take?
Assume a network consisting of N nodes



Each iteration: need to check all nodes, w, not in S
N(N+1)/2 comparisons: O(N2)
More efficient implementations possible: O(N log(N))
22
Obtaining Global State

Flooding


Each router sends link-state information out its links
The next node sends it out through all of its links


except the one where the information arrived
Note: need to remember previous msgs & suppress
duplicates!
X
A
X
A
C
B
D
C
(a)
X
A
C
B
(c)
B
D
(b)
D
X
A
C
B
(d)
D
23
Flooding the Link State



Reliable flooding
 Ensure all nodes receive link-state information
 Ensure all nodes use the latest version
Challenges
 Packet loss
 Out-of-order arrival
Solutions
 Acknowledgments and retransmissions
 Sequence numbers
 Time-to-live for each packet
24
When to Initiate Flooding

Topology change



Configuration change



Link or node failure
Link or node recovery
Link cost change
See next slide for hazards of dynamic link
costs based on current load
Periodically



Refresh the link-state information
Typically (say) 30 minutes
Corrects for possible corruption of the data
25
Oscillations

Assume link cost = amount of carried traffic
1
A
1+e
D 0 0 B
e
0
C
1
1
e
initially
2+e A
0
D 1+e 1 B
0
0
C
A
0
2+e
D
0 0 B
1
1+e
C
… recompute
routing

… recompute
2+e A
0
D 1+e 1 B
e
0
C
… recompute
How can you avoid oscillations?
26
5 Minute Break
Questions Before We Proceed?
27
Distance Vector Routing

Each router knows the links to its immediate
neighbors


Each router has some idea about the shortest
path to each destination


E.g.: Router A: “I can get to router B with cost 11 via
next hop router D”
Routers exchange this information with their
neighboring routers


Does not flood this information to the whole network
Again, no flooding the whole network
Routers update their idea of the best path using
info from neighbors
28
Information Flow in Distance
Vector
Host C
Host D
Host A
N1
N2
N3
N5
Host B
Host E
N4
N6
N7
29
Bellman-Ford Algorithm

INPUT:



Link costs to each neighbor
Not full topology
OUTPUT:


Next hop to each destination and the
corresponding cost
Does not give the complete path to the
destination
30
Bellman-Ford - Overview

Each router maintains a table



Row for each possible destination
Column for each directly-attached
neighbor to node
Entry in row Y and column Z of node
X  best known distance from X to Y,
via
Z as next hop = DZ(X,Y)
Neighbor
(next-hop)
Node A
2
1
A
7
D
3
B
C 1
B
C
B
2
8
C
3
7
D
4
8
Destinations
DC(A, D)
Bellman-Ford - Overview

Each router maintains a table



Row for each possible destination
Column for each directly-attached
neighbor to node
Entry in row Y and column Z of node
X  best known distance from X to Y,
via
Z as next hop = DZ(X,Y)
Node A
3
B
2
1
A
7
C 1
D
B
C
B
2
8
C
3
7
D
4
8
Smallest distance in row Y = shortest
Distance of A to Y, D(A, Y)
Bellman-Ford - Overview

Each router maintains a table




Each local iteration caused by:



Row for each possible destination Each node:
Column for each directly-attached
neighbor to node
wait for (change in local link
cost or msg from neighbor)
Entry in row Y and column Z of node
X  best known distance from X to Y,
via
Z as next hop = DZ(X,Y)
recompute distance table
Local link cost change
Message from neighbor
Notify neighbors only if least cost
path to any destination changes

if least cost path to any dest
has changed, notify
neighbors
Neighbors then notify their neighbors
if necessary
33
Distance Vector Algorithm
(cont’d)
1 Initialization:
 c(i,j): link cost from node i to j
2 for all neighbors V do
3
if V adjacent to A
 DZ(A,V): cost from A to V via Z
4
D(A, V) = c(A,V);
 D(A,V): cost of A’s best path to V
5
else
6
D(A, V) = ∞;
7
send D(A, Y) to all neighbors
loop:
8 wait (until A sees a link cost change to neighbor V /* case 1 */
9
or until A receives update from neighbor V) /* case 2 */
10 if (c(A,V) changes by ±d) /*  case 1 */
11
for all destinations Y that go through V do
12
DV(A,Y) = DV(A,Y) ± d
13 else if (update D(V, Y) received from V) /*  case 2 */
/* shortest path from V to some Y has changed */
14
DV(A,Y) = DV(A,V) + D(V, Y); /* may also change D(A,Y) */
15 if (there is a new minimum for destination Y)
16
send D(A, Y) to all neighbors
34
17 forever
Example:1st Iteration (C  A)
Node A
2
1
A
D
3
B
C
1
Node B
A
C
D
B
C
B
2
8
A
C
∞
7
C
∞
1
∞
D
∞
8
D
∞
∞
3
∞
2
∞
7
DC(A, B) = DC(A,C) + D(C, B) = 7 + 1 = 8
DC(A, D) = DC(A,C) + D(C, D) = 7 + 1 = 8
7
loop:
…
13 else if (update D(A, Y) from C)
14 DC(A,Y) = DC(A,C) + D(C, Y);
15 if (new min. for destination Y)
16 send D(A, Y) to all neighbors
17 forever
Node C
Node D
A
A
7
B
∞
D
∞
B
∞
D
B
C
∞
A
∞
∞
1
∞
B
3
∞
∞
1
C
∞
1
Example: 1st Iteration (B  A)
Node A
2
1
A
D
3
B
C
1
Node B
A
C
D
B
C
B
2
8
A
C
3
7
C
∞
1
∞
D
5
8
D
∞
∞
3
∞
2
∞
7
DB(A, C) = DB(A,B) + D(B, C) = 2 + 1 = 3
DB(A, D) = DB(A,B) + D(B, D) = 2 + 3 = 5
7
loop:
…
13 else if (update D(A, Y) from B)
14 DB(A,Y) = DB(A,B) + D(B, Y);
15 if (new min. for destination Y)
16 send D(A, Y) to all neighbors
17 forever
Node C
Node D
A
B
∞
A
7
B
∞
1
D
∞
∞
D
∞
1
B
C
A
∞
∞
B
3
∞
C
∞
1
Example: End of 1st Iteration
Node A
2
1
A
D
3
B
C
1
Node B
A
C
D
A
2
3
∞
7
C
9
1
4
8
D
∞
2
3
B
C
B
C
B
2
8
C
3
D
5
7
Node C
End of 1st Iteration
All nodes knows the
best two-hop paths
Node D
A
B
D
A
7
3
∞
A
5
8
B
9
1
4
B
3
2
D
∞
4
1
C
4
1
Example: 2nd Iteration (A  B)
Node A
2
1
A
D
3
B
C
1
Node B
A
C
D
A
2
3
∞
7
C
5
1
4
8
D
7
2
3
B
C
B
2
8
C
3
D
5
7
DA(B, C) = DA(B,A) + D(A, C) = 2 + 3 = 5
DA(B, D) = DA(B,A) + D(A, D) = 2 + 5 = 7
7
loop:
…
13 else if (update D(B, Y) from A)
14 DA(B,Y) = DA(B,A) + D(A, Y);
15 if (new min. for destination Y)
16 send D(B, Y) to all neighbors
17 forever
Node C
Node D
A
B
D
B
C
A
7
3
∞
A
5
8
B
9
1
4
B
3
2
D
∞
4
1
C
4
1
Example: End of 2nd Iteration
Node A
2
1
A
D
3
B
C
1
Node B
A
C
D
A
2
3
11
7
C
5
1
4
8
D
7
2
3
B
C
B
C
B
2
8
C
3
D
4
7
Node C
End of 2nd Iteration
All nodes knows the
best three-hop paths
Node D
A
B
D
A
7
3
6
A
5
4
B
9
1
4
B
3
2
D
12
4
1
C
4
1
Example: End of 3rd Iteration
Node A
2
1
A
D
3
B
C
1
Node B
A
C
D
A
2
3
6
7
C
5
1
4
8
D
7
2
3
B
C
B
C
B
2
8
C
3
D
4
7
Node C
End of 2nd Iteration:
Algorithm
Converges!
Node D
A
B
D
A
7
3
5
A
5
4
B
9
1
4
B
3
2
D
11
4
1
C
4
1
Distance Vector: Link Cost
Changes
loop:
8 wait (until A sees a link cost change to neighbor V
9
or until A receives update from neighbor V) /
10 if (c(A,V) changes by ±d) /*  case 1 */
11
for all destinations Y that go through V do
12
DV(A,Y) = DV(A,Y) ± d
13 else if (update D(V, Y) received from V) /*  case 2 */
14
DV(A,Y) = DV(A,V) + D(V, Y);
15 if (there is a new minimum for destination Y)
16
send D(A, Y) to all neighbors
17 forever
A
Node B
Node C
C
A
C
A
C
1
6
9
1
1
B
4
1
A
C
50
A
C
A
1
3
C
3
1
A
4
6
A
1
6
A
C
9
1
C
9
1
C
A
B
A
B
A
B
A
B
A 50
5
A 50
5
A 50
2
A 50
2
B 54
1
B 54
1
B 51
1
B 51
1
Link cost changes here
time
Algorithm terminates
“good
news
travels
fast”
41
Distance Vector: Count to Infinity
Problem
loop:
8 wait (until A sees a link cost change to neighbor V
9
or until A receives update from neighbor V) /
10 if (c(A,V) changes by ±d) /*  case 1 */
11
for all destinations Y that go through V do
12
DV(A,Y) = DV(A,Y) ± d
13 else if (update D(V, Y) received from V) /*  case 2 */
14
DV(A,Y) = DV(A,V) + D(V, Y);
15 if (there is a new minimum for destination Y)
16
send D(A, Y) to all neighbors
17 forever
A
C
A
C
A
4
6
A
60
6
C
9
1
C
9
1
A
B
A
B
A 50
5
A 50
5
B 54
1
B 54
1
Node B
Node C
Link cost changes here
A
C
A
60
6
C
9
1
A
B
A
50
7
B
101
1
60
B
4
1
A
C
50
A
C
A
60
8
C
9
1
A
B
A
50
7
B
101
1
…
time
“bad
news
travels
slowly”
42
Distance Vector: Poisoned
Reverse
•
If B routes through C to get to A:
60
- B tells C its (B’s) distance to A is infinite (so
C won’t route to A via B)
- Will this completely solve count to infinity
problem?
A
C
A
C
A
4
6
A
60
6
C
9
1
C
9
1
A
B
A
B
A 50
5
A 50
5
∞
1
B
∞
1
Node B
Node C
B
A
C
A
60
6
C
9
1
A
B
A
50
∞
B
∞
1
4
1
A
C
50
A
C
A
60
51
C
9
1
A
B
A
50
∞
B
∞
1
Link cost changes here; C updates D(C, A) = 60 as
B has advertised D(B, A) = ∞
B
A
C
A
60
51
C
9
1
A
B
A
50
∞
B
∞
1
time
Algorithm terminates
43
Routing Information Protocol
(RIP)

Simple distance-vector protocol



Link costs in RIP





Nodes send distance vectors every 30 seconds
… or, when an update causes a change in routing
All links have cost 1
Valid distances of 1 through 15
… with 16 representing infinity
Small “infinity”  smaller “counting to infinity” problem
RIP is limited to fairly small networks

E.g., campus
44
Link State vs. Distance Vector
Per-node message
complexity:
 LS: O(e) messages


e: number of edges

DV: O(d) messages,
many times


Requires global flooding
DV: convergence time
varies


d is node’s degree
Complexity/Convergence
 LS: O(N log N)
computation

Robustness: what happens
if router malfunctions?
 LS:
Count-to-infinity problem

Node can advertise
incorrect link cost
Each node computes only
its own table
DV:


Node can advertise
incorrect path cost
Each node’s table used by
others; errors propagate
through network
45
Summary

Routing is a distributed algorithm




Two main shortest-path algorithms



Dijkstra  link-state routing (e.g., OSPF, IS-IS)
Bellman-Ford  distance-vector routing (e.g., RIP)
Convergence process



Different from forwarding
React to changes in the topology
Compute the shortest paths
Changing from one topology to another
Transient periods of inconsistency across routers
Next time: BGP

Reading: K&R 4.6.3
46
Download