# Distributed Systems

Δίκτυα και Επικοινωνίες

18 Ιουλ 2012 (πριν από 5 χρόνια και 11 μήνες)

332 εμφανίσεις

Dept. of CSE, IIT KGP
Routing Algorithms
Routing Algorithms
CS60002:
CS60002:
Distributed Systems
Distributed Systems
Pallab
Pallab
Dasgupta
Dasgupta
Dept. of Computer Sc. &
Dept. of Computer Sc. &
Engg
Engg
.,
.,
Indian Institute of Technology Kharagpur
Indian Institute of Technology Kharagpur
Dept. of CSE, IIT KGP
Main Features
Main Features

Table Computation
Table Computation

The routing tables must be computed when the network is
The routing tables must be computed when the network is
initialized and must be brought up
initialized and must be brought up
-
-
to
to
-
-
date if the topology of
date if the topology of
the network changes
the network changes

Packet Forwarding
Packet Forwarding

When a packet is to be sent through the network, it must be
When a packet is to be sent through the network, it must be
forwarded using the routing tables
forwarded using the routing tables
Dept. of CSE, IIT KGP
Performance Issues
Performance Issues
Correctness
Correctness
:
:
The algorithm must deliver every packet to its
The algorithm must deliver every packet to its
ultimate destination
ultimate destination
Complexity
Complexity
:
:
The algorithm for the computation of the tables
The algorithm for the computation of the tables
must use as few messages, time, and storage as possible
must use as few messages, time, and storage as possible
Efficiency
Efficiency
:
:
The algorithm must send packets through
The algorithm must send packets through
good
good
paths
paths
Robustness
Robustness
:
:
In the case of a topological change, the algorithm
In the case of a topological change, the algorithm
Fairness
Fairness
:
:
The algorithm must provide service to every user in
The algorithm must provide service to every user in
the same degree
the same degree
Dept. of CSE, IIT KGP
Good paths …
Good paths …
Minimum hop
Minimum hop
:
:
The cost of a path is the number of hops
The cost of a path is the number of hops
Shortest path
Shortest path
:
:
Each channel has a non
Each channel has a non
-
-
negative cost
negative cost

the path
the path
cost is the sum of the cost of the edges. Packets are routed
cost is the sum of the cost of the edges. Packets are routed
along shortest paths.
along shortest paths.
Minimum delay/congestion
Minimum delay/congestion
:
:
The bandwidth of a path is the
The bandwidth of a path is the
minimum among the bandwidths of the channels on that path.
minimum among the bandwidths of the channels on that path.
Most robust path
Most robust path
:
:
Given the probability of packet drops in each
Given the probability of packet drops in each
channel, packets are to be routed along the most reliable
channel, packets are to be routed along the most reliable
paths.
paths.
Dept. of CSE, IIT KGP
Destination
Destination
-
-
based Forwarding
based Forwarding
// A packet with destination d was received or generated at node
// A packet with destination d was received or generated at node
u
u
if
if
d = u
d = u
then
then
deliver the packet locally
deliver the packet locally
else
else
send the packet to
send the packet to
table_lookup
table_lookup
u
u
(
(
d
d
)
)
Dept. of CSE, IIT KGP
Floyd
Floyd
-
-
Warshall
Warshall
Algorithm
Algorithm
begin
begin
S =
S = Φ
Φ
;
;
forall
forall
u, v
u, v
do
do
if
if
u = v
u = v then
then D
D[
[u, v
u, v] = 0
] = 0
else if
else if
uv
uv

E
E
then D[
then D[
u, v
u, v
] =
] = w
wu,v
u,v
else D[
else D[
u, v
u, v
] =
] = ∞

;
;
while S
while S

V do
V do
// Loop invariant:
// Loop invariant:

u, v
u, v
:
:
D
D
[
[
u, v
u, v
] =
] = d
dS
S(
(
u
u
, v
, v)
)
begin pick
begin pick
w
w
from V
from V
\
\
S;
S;
forall
forall
u
u

V
V
do
do
forall
forall
v
v

V
V
do
do
D
D
[
[
u, v
u, v
] = min{
] = min{ D
D[
[u, v
u, v],
], D
D[
[u, w
u, w] +
] +
D
D
[
[
w, v
w, v
] }
] }
S = S U {
S = S U { w
w }
}
end
end
end
end
The algorithm computes the distance between each pair
The algorithm computes the distance between each pair
of nodes in O(N
of nodes in O(N3
3
) steps
) steps
Dept. of CSE, IIT KGP
The simple distributed algorithm
The simple distributed algorithm
// For node u …
// For node u …
var
var
S
S
u
u
: set of nodes;
: set of nodes;
D
D
u
u
: array of weights;
: array of weights;
Nb
Nb
u
u
: array of nodes;
: array of nodes;
begin
begin
S
S
u
u
=
=
Φ
Φ
;
;
forall
forall
v
v

V
V
do
do
if
if
v = u
v = u
then
then
begin
begin
D
D
u
u
[
[
v
v
] = 0;
] = 0;
Nb
Nb
u
u
[
[
v
v
] =
] =
udef
udef
end
end
else if
else if
v
v

Neigh
Neigh
u
u
then
then
begin
begin
D
D
u
u
[
[
v
v
] =
] =
w
w
u,v
u,v
;
;
Nb
Nb
u
u
[
[
v
v
] = v end
] = v end
else begin
else begin
D
D
u
u
[
[
v
v
] =
] =

;
;
Nb
Nbu
u
[
[
v
v
] =
] =
udef
udef
end;
end;
Dept. of CSE, IIT KGP
The simple distributed algorithm
The simple distributed algorithm
contd
contd

while S
while S
u
u

V do
V do
begin pick
begin pick
w
w
from V
from V
\
\
S
S
u
u
;
;
//
//
All nodes must pick the same w
All nodes must pick the same w
if
if
u = w
u = w
then
then
D
D
w
w
else
else
D
D
w
w
forall
forall
v
v

V
V
do
do
if
if
D
D
u
u
[
[
w
w
] +
] +
D
D
w
w
[
[
v
v
] <
] <
D
D
u
u
[
[
v
v
] then
] then
begin
begin
D
D
u
u
[
[
v
v
] =
] =
D
D
u
u
[
[
w
w
] +
] +
D
D
w
w
[
[
v
v
] ;
] ;
Nb
Nb
u
u
[
[
v
v
] =
] =
Nb
Nb
u
u
[
[
w
w
]
]
end ;
end ;
S
S
u
u
= S
= S
u
u
U {
U {
w
w
}
}
end
end
end
end
Dept. of CSE, IIT KGP
Important property of the simple algorithm
Important property of the simple algorithm
Let
Let
S
S
and
and
w
w
be given and suppose that
be given and suppose that
(1) for all
(1) for all
u
u
,
,
D
D
u
u
[
[
w
w
] =
] =
d
d
S
S
(
(
u
u
, w
, w
) and
) and
(2) if
(2) if
d
d
S
S
(
(
u
u
, w
, w
) <
) <

and
and u
u

w
w
, then
, then
Nb
Nbu
u
[
[
w
w
] is the first
] is the first
channel of a shortest S
channel of a shortest S
-
-
path to
path to
w
w
Then the directed graph
Then the directed graph
T
T
w
w
= (
= (
V
V
w
w
,
,
E
E
w
w
), where
), where
(
(
u
u

V
Vw
w

D
Du
u
[
[
w
w
] <
] < ∞

) and
) and
(
(
ux
ux

E
E
w
w

(
(
u
u

w
w

Nb
Nb
u
u
[
[
w
w
] =
] =
x
x
))
))
is a tree rooted towards
is a tree rooted towards
w.
w.
Dept. of CSE, IIT KGP
Toueg’s
Toueg’s
improvement
improvement

Toueg’s
Toueg’s
observation:
observation:

A node
A node
u
u
for which
for which
D
D
u
u
[
[
w
w
] =
] =

at the start of the
at the start of the
w
w
-
-
pivot
pivot
round does not change its tables during the
round does not change its tables during the w
w-
-
pivot round.
pivot round.

If
If
D
D
u
u
[
[
w
w
] =
] =

then
then D
Du
u
[
[
w
w
] +
] +
D
D
w
w
[
[
v
v
] <
] <
D
D
u
u[
[v
v] is false for every
] is false for every v
v.
.

Consequently, only the nodes that belong to
Consequently, only the nodes that belong to
T
T
w
w
need to
need to
w
w
’s
’s
table, and the broadcast operation can be done
table, and the broadcast operation can be done
efficiently by sending the table
efficiently by sending the table
D
D
w
w
only via the channels
only via the channels
that belong to the tree
that belong to the tree
T
T
w
w
Dept. of CSE, IIT KGP
The
The
Chandy
Chandy
-
-
Misra
Misra
Algorithm
Algorithm
var
var
D
D
u
u
[
[
v
v
0
0
] : weight
] : weight
init
init

;
;
Nb
Nb
u
u
[
[
v
v
0
0
] : node
] : node
init
init
udef
udef
;
;
For node
For node
v
v
0
0
only:
only:
begin
begin
D
D
v0
v0
[
[
v
v
0
0
] = 0 ;
] = 0 ;
forall
forall
w
w

Neigh
Neigh
v0
v0
do send
do send

mydist
mydist
,
,
v
v
0
0
, 0
, 0

to
to
w
w
end
end
Processing a
Processing a

mydist
mydist
,
,
v
v
0
0
,
,
d
d

message from neighbor
message from neighbor w
w by
by u
u:
:
{
{

mydist
mydist
,
,
v
v
0
0
,
,
d
d

M
Mwu
wu
}
}

mydist
mydist
,
,
v
v
0
0
,
,
d
d

from
from w
w
;
;
if
if
d +
d +
ω
ω
uw
uw
< D
< D
u
u[
[v
v0
0
] then
] then
begin
begin
D
D
u
u
[
[
v
v
0
0
] =
] =
d +
d +
ω
ω
uw
uw
;
;
Nb
Nb
u
u[
[v
v0
0
] =
] =
w
w
;
;
forall
forall
x
x

Neigh
Neigh
u
u
do send
do send 〈

mydist
mydist
,
,
v
v
0
0
,
,
D
D
u
u
[
[
v
v
0
0
]
]

to
to
x
x
end
end
end
end
Dept. of CSE, IIT KGP
The
The
Netchange
Netchange
Algorithm
Algorithm

Computes routing tables according to
Computes routing tables according to
minimum
minimum
-
-
hop
hop
measure
measure

Assumptions:
Assumptions:

N1:
N1:
The nodes know the size of the network (
The nodes know the size of the network (
N
N
)
)

N2:
N2:
The channels satisfy the FIFO assumption
The channels satisfy the FIFO assumption

N3:
N3:
Nodes are notified of failures and repairs of their adjacent
Nodes are notified of failures and repairs of their adjacent
channels
channels

N4:
N4:
The cost of a path equals the number of channels in the path
The cost of a path equals the number of channels in the path

Requirements:
Requirements:
R1.
R1.
If the topology of the network remains constant after a finite
If the topology of the network remains constant after a finite
number of topological changes, then the algorithm terminates
number of topological changes, then the algorithm terminates
after a finite number of steps.
after a finite number of steps.
R2.
R2.
When the algorithm terminates, the tables
When the algorithm terminates, the tables
Nb
Nb
u
u
[
[
v
v
] satisfy
] satisfy
(a) if
(a) if
v = u
v = u
then
then
Nb
Nb
u
u
[
[
v
v
] =
] =
local
local
;
;
(b) if a path from
(b) if a path from
u
u
to
to
v
v

u
u
exists then
exists then Nb
Nbu
u
[
[
v
v
] =
] =
w
w, where
, where w
w
is the
is the
first neighbor of
first neighbor of
u
u
on a shortest path from
on a shortest path from
u
u
to
to
v
v
;
;
(c) if no path from
(c) if no path from
u
u
to
to
v
v
exists then
exists then
Nb
Nb
u
u
[
[
v
v
] =
] =
udef
udef
.
.
Dept. of CSE, IIT KGP
The
The
Netchange
Netchange
Algorithm
Algorithm
var
var
Neigh
Neigh
u
u
: set of nodes ;
: set of nodes ;
// The neighbors of
// The neighbors of
u
u
D
D
u
u
: array of 0 .. N
: array of 0 .. N
;
;
//
//
D
D
u
u
[
[
v
v
] estimates
] estimates
d
d
(
(
u,v
u,v
)
)
Nb
Nb
u
u
: array of nodes ;
: array of nodes ;
//
//
Nb
Nb
u
u
[
[
v
v
] is preferred neighbor for
] is preferred neighbor for
v
v
ndis
ndis
u
u
: array of 0 .. N ;
: array of 0 .. N ;
//
//
ndis
ndis
u
u
[
[
w
w
, v
, v
] estimates
] estimates
d
d
(
(
w,v
w,v
)
)
Initialization:
Initialization:
begin
begin
forall
forall
w
w

Neigh
Neigh
u
u
, v
, v

V
V
do
do
ndis
ndis
u
u[
[w
w, v
, v] =
] =
N
N
;
;
forall
forall
v
v

V
V
do
do
begin
begin
D
D
u
u
[
[
v
v
] =
] =
N
N
;
;
Nb
Nb
u
u
[
[
v
v
] =
] =
udef
udef
end ;
end ;
D
D
u
u
[
[
u
u
] = 0 ;
] = 0 ;
Nb
Nb
u
u
[
[
u
u
] =
] =
local
local
;
;
forall
forall
w
w

Neigh
Neigh
u
u
do send
do send

mydist
mydist
,
,
u
u
, 0
, 0

to
to
w
w
end
end
Dept. of CSE, IIT KGP
The
The
Netchange
Netchange
Algorithm contd.
Algorithm contd.
Procedure
Procedure
Recompute
Recompute
(
(
v
v
):
):
begin if
begin if
v = u
v = u
then begin
then begin
D
D
u
u
[
[
v
v
] = 0 ;
] = 0 ;
Nb
Nb
u
u
[
[
v
v
] =
] =
local
local
end
end
else begin
else begin
// estimate distance to
// estimate distance to
v
v
d =
d =
1 + min{
1 + min{
ndis
ndis
u
u
[
[
w,v
w,v
] :
] :
w
w

Neigh
Neighu
u
} ;
} ;
if
if
d < N
d < N
then
then
begin
begin
D
D
u
u
[
[
v
v
] =
] =
d
d
;
;
Nb
Nb
u
u
[
[
v
v
] =
] =
w
w
with 1 +
with 1 +
ndis
ndis
u
u
[
[
w,v
w,v
] =
] =
d
d
end
end
else begin
else begin
D
D
u
u
[
[
v
v
] =
] =
N
N
;
;
Nb
Nb
u
u
[
[
v
v
] =
] =
udef
udef
end
end
end ;
end ;
if
if
D
D
u
u
[
[
v
v
] has changed then
] has changed then
forall
forall
x
x

Neigh
Neigh
u
u
do send
do send

mydist
mydist
,
,
v
v
,
,
D
D
u
u[
[v
v]
] 〉

to
to x
x
end
end
Dept. of CSE, IIT KGP
The
The
Netchange
Netchange
Algorithm contd.
Algorithm contd.
Processing a
Processing a

mydist
mydist
,
,
v
v
,
,
d
d

message from neighbor
message from neighbor
w
w
:
:
{ A
{ A

mydist
mydist
,
,
v
v
,
,
d
d

Q
Q
wv
wv
}
}

mydist
mydist
,
,
v
v
,
,
d
d

from
from
w
w
;
;
ndis
ndis
u
u
[
[
w,v
w,v
] =
] =
d
d
;
;
Recompute
Recompute
(
(
v
v
)
)
end
end
Upon failure of channel
Upon failure of channel
uw
uw
:
:

fail,
fail,
w
w

;
;
Neigh
Neighu
u
=
=
Neigh
Neigh
u
u
\
\
{
{
w
w
} ;
} ;
forall
forall
v
v

V
V
do
do
Recompute
Recompute
(
(
v
v
)
)
end
end
Upon repair of channel
Upon repair of channel
uw
uw
:
:

repair,
repair,
w
w

;
;
Neigh
Neigh
u
u
=
=
Neigh
Neighu
u
U {
U {
w
w
} ;
} ;
forall
forall
v
v

V
V
do
do
begin
begin
ndis
ndis
u
u
[
[
w,v
w,v
] =
] =
N
N
;
;
send
send

mydist
mydist
,
,
v
v
,
,
D
D
u
u
[
[
v
v
]
]

to
to
w
w
end
end
end
end