# Routing algorithms

Networking and Communications

Oct 6, 2011 (6 years and 9 months ago)

541 views

Shortest path, Widest path, and constrained routing Olof Hagsand KTH CSC

1
Lecture 2:
Routing algorithms
Shortest path, Widest path, and constrained routing
Olof Hagsand KTH CSC
DD2490 p4 2011
This lecture contains new material for 2011.

2
Graphs vs networks

Algorithms are usually defined on graphs whereas
protocols work on networks

Graphs have nodes and edges whereas networks
hierarchical layering, etc.

3
RT1
N1
RT2
N2
3
3
N3
1
RT4
1
RT3
N4
2
1
1
RT5
RT6
8
8
8
6
N12
N13
N14
N15
8
8
8
6
7
RT9
N11
RT12
N10
3
10
N9
1
1
H1
2
1
RT11
2
N8
RT10
6
Ia
7
Ib
3
N6
1
RT8
1
4
N7
RT7
6
1
9
6
2

RFC 2328 fig 2
Network example
Network example
Note that the figure is taken from the OSPF RFC.
The broadcast links (N1, N2, N3) are denoted somewhat unusually by ellipses.
Note that there is one host H1.
Note also that the link metrics are asymmetrical.

4
RT1
N1
RT2
N2
3
3
N3
1
RT4
1
RT3
N4
2
1
1
RT5
RT6
8
8
8
6
N12
N13
N14
N15
8
8
8
6
7
RT9
N11
RT12
N10
3
10
N9
1
1
H1
2
1
RT11
2
N8
RT10
5
Ib
7
Ia
3
N6
1
RT8
0
4
N7
RT7
6
1
9
6
2
0
0
0
0
5
1
0
0
0
0
0
0
0
7
(Directed) graph example
adding a virtual network node (eg N3) to which the nodes connect (since all edges
connect only two nodes). Since this node is virtual, there is no physical
corresponding node, the cost of exiting the node is set to 0.
In many protocols such a virtual node (eg N3) 'belongs' to a router in the sense
that the router announces the network information of the virtual node. Such a
router is called the 'designated' router of the network. For example, RT1 is the
designated router of N3.

5
Example graph
A
B
C
E
D
F
1
1
1
2
1
1
2
1
1
13
1
is a typical backup path that normally is not used unless an error
occurs.

6
Shortest Path First (SPF)

Find the path (sequence of links) where the sum of
the metrics of all links (cumulative cost) is lowest

ECMP: A
set
of path with the least cost
A
B
C
E
D
F
1
1
1
2
1
1
2
1
1
13
1

7
Bellman-Ford shortest path
If it is possible to get from entity i to entity j directly, then a cost,
d(i,j), is associated with the hop between i and j. The cost is infinite
if i and j are not immediate neighbors. Let D(i,j) represent the metric of
the best route from entity i to entity j.
Then, the best metric is described by:

The algorithm:
For h=0 to N-1 do:
In words: Entity i gets estimates from neighbors k of their distances to
the destination j. Add d(i,k) to each of the numbers. This is the cost of
traversing the network between i and k. Compare the values from all of its
neighbors and pick the smallest.

D

i
,
i

=
0,
for
all
i.
D

i
,
j

=
min
k

j
[
d

i
,
k

D

k
,
j

]
,
otherwise
.
D
0

i
,
i

=
0,
for
all
i.
D
0

i
,
j

=

,
otherwise
.
D
h

1

i
,
i

=
0,
for
all
i.
D
h

1

i
,
j

=
min
k

i
[
d

i
,
k

D
h

k
,
j

]
,
otherwise
.
.

8
Exercise: Bellman-Ford
d(i,j)
A B C D E F
A
B
C
D
E
F
h
D(A,F)
D(B,F)
D(C,F)
D(D,F)
D(E,F)
0
1
2
3
4
5
The example network in earlier slide is used.

9
The distributed algorithm

Keep a table with an entry for each destination N in the network.

Store the distance D and next-hop G for each N in the table.

Periodically, send the table to all neighbors (the distance-
vector).

For each update that comes in from neighbor G' (to N with a new
distance):

Add the cost of the link to G' to the new distance to get D'.

Replace the route if D' < D.

If G = G', always replace the route.

10
Dijkstra's shortest path first
From the link-state database, compute a shortest path delivery
tree using a permanent set S and a tentative set Q:
1.
Define the root of the tree: the router
2.
Assign a cost of 0 to this node and make it the first
permanent node.
3.
Examine each neighbor node of the last permanent node.
4.
Assign a cumulative cost to each node and make it
tentative.
5.
Among the list of tentative nodes:

Find the node with the smallest cumulative cost and make it
permanent.

If a node can be reached from more than one direction, select the
direction with the smallest cumulative cost.
6.
Repeat steps 3 to 5 until every node is permanent.
If you are unsure about Dijkstra, go through the extra material
including an example on the web-site

11
Dijkstra pseudo-code
(from Wikipedia)
function
Dijkstra(Graph, source):

for each
vertex v
in
Graph: // Initializations

dist[v] := infinity ; // Unknown distance function from source to v

previous[v] := undefined ; // Previous node in optimal path from source

dist[source] := 0 ; // Distance from source to source

Q := the set of all nodes in Graph ;

// All nodes in the graph are unoptimized - thus are in Q

while
Q is not empty: // The main loop

u := vertex in Q with smallest dist[] ;

remove u from Q ;

for each
neighbor v
of
u: // where v has not yet been removed from Q.

alt := dist[u] + dist_between(u, v) ;

if
alt < dist[v]: // Relax (u,v,a)

dist[v] := alt ;

previous[v] := u ;

12
Spanning-Tree Protocol
In Layer 2 networking (eg Ethernet), there is no
'routing' of individual flows. Instead, a
single
tree is
constructed to avoid loops. This spanning-tree is a
shortest path tree to all destinations from a single
root.
All traffic then follows this single tree, using source
learning
: Traffic is initially flooded
throughout the tree (up and down the branches),
but the nodes learn the location (incoming port) of
the sources by inspecting the source address in the
frames.
Spanning-tree is used in Ethernets including Metro-Ethernets being
built today. Very large networks (even global) are being built where
spanning-tree is the mechanism used to detect loops.

13
Spanning-tree algorithm

An ID number is assigned to each bridge, and a
cost to each port.

Process of finding the spanning tree:

The bridges choose a bridge to be the root bridge of the tree
by finding the bridge with the smallest ID.

Each bridge determines its root port, the port that has the
least root path cost to the root. The root path cost is the
accumulated cost of the path from the port to the root.

One designated bridge is chosen for each segment

Select ports to be included in the spanning tree (root port
plus designated ports)

Data traffic is forwarded only to and from ports
selected for inclusion in the spanning tree
STP (Spanning Tree Protocol) is not a routing protocol since it does
not identify individual routes. Instead, it tranforms a general graph to
a tree, and uses learning (flood and learn) to distribute information.

14
Spanning-tree exercise

How does traffic go between hosts A and B if
learning bridges X, Y, Z are root bridges,
respectively?
designated
root port
blocked/listening/forwarding
X
1
2
Y
Z
3
2
3
2
A
B
4
1
For generic solution, use priority vectors. Each bridge forms a priority
vector on each port/segment it is connected to and sends it out on that port.
The lowest priority vector 'succeeds' in the following sense: (1) Segment:
the bridge sending the lowest priority vector on a segment becomes the
designated bridge(port) of that segment; (2) Bridge: among the priority
vectors received on all ports on a bridge, the bridge selects port where the
lowest was received and assigns that as the root bridge (if not root itself).
Priority vector simple form:
<rootid, metric, bridgeid>,
where:

-
rootid
: id of elected root bridge

-
metric
: accumulated path metric frm sending bridge to root

-
bridgeid
: id of sending bridge
Priority vector complete form: <rootid, metric, bridgeid, srcport, dstport>
where

-
srcport
: port number of sending port (of the priority vector)

-
dstport
: port number where the priority vector is received.
The complete form is only used in cases where there are several ports on the
same bridge on a segment.

15

SPF may not utilize a given network well. An operator may
be interested in using the network resources better

This is called Traffic Engineering

A common metric is to

Example: Traffic in the network is as follows:

A->E 3 Mb/s

D->E 1 Mb/s

How does traffic flow given unary weights?

What is the optimal solution (using load-balancing)?

Can you modify
weights
to reach the optimal
solution?
A
B
D
E
C
Assume equal bandwidth on all links.
With unary weights, the D->E link has 4Mb/s
The minimal load criteria is to have a smallest maximum load in the
network.
With generic load-balancing, the optimal solution would be to send:
- 2 Mb/s A->B->C->E
- 1 Mb/s A->D->E
- 1 Mb/s D->E
By modifying weights (eg set weight of A->D to 2) and ECMP, all
you can get is:
- 1.5 Mb/s A->B->C->E
- 1.5 Mb/s A->D->E
- 1 Mb/s D->E
Thus the optimal solution is not obtainable with ECMP and weight

16

Flows:

A -> D, A -> E, C -> D, C -> E

Each flow 5Mb/s

What is the SPF solution?

max) of at most 10Mb/s
From A. Gunnar, ”Aspects of proactive traffic engineering
in IP networks” , PhD thesis, Feb 2011
A
B
C
E
D
2
5
2
1
10
2
In the solution above, all flows pass via C and E. The best solution is
to make the flows from A pass via B and D instead, while keeping the
flows from C via E.
This can be made by heightening the cost between A-> C to for
example 10, and lowering the cost from B -> D to 2.
If you are not careful, though, the traffic from C to D may start
leaking over B.
Consider also if there are further constraints between other routers,
and you see that this is difficult to do , at least intuitively.

17
Widest path first

Both Bellman-Ford and Dijkstra considers the shortest path
based on an additive scalar metrics.

That is, the shortest path cost is computed by adding all individual link
metrics

But suppose we need to optimize for bandwidth or load
consider the path with the highest bandwidth / lowest load.

Often used:
available bandwidth

Can be used in conjunction with resource reservation
protocols to solve a dynamic traffic engineering problem

We may then look at
widest
path computation

It is easy to extend Dijkstra (or Bellman-Ford) with a widest-
path computation rather than shortest path.
Dijkstra is extended as follows

minimum of all possible paths,

The minimum link metric of all possible paths is computed
and their maximum selected

18
Widest path first: exercise

Numbers denote width: load or bandwidth

What is the widest path from A -> E?
A
B
C
E
D
bw:30
bw:20
bw:10
bw:15
bw:50
bw:40
bw:10
The widest path is A->B->D->E. Its minimal width is 20,
which is higher than all other paths from A to E.

19
Constrained Shortest Path First

In traffic engineering a generalization of SPF is
normally used: Constrained Shortest Path (CSPF)

CSPF is implemented along with MPLS

Introduce a boolean condition which may remove
links, and compute SPF on that.

Examples of conditions:

Available bandwidth (No link avbw < min avbw)

Available bandwidth ratio (No link utilization > max %)

Delay bonds (No path delays > max delay)

Hop counts (No path hops > max hc)

Resiliency (No common network element w primary path)
The constraints can be provided with elaborate configuration syntax,
but often general constraints are not implemented. Typical useful
constraints are available bandwidth and resilience.

20
CSPF Example 1: Available bw

A->E with available bandwidth >= 20?
A
B
C
E
D
1
bw:30
1
bw:20
2
bw:10
1
bw:15
1
bw:50
2
bw:40
1
bw:10
Note: dashed lines do not meet the constraint (bw >= 20) and are
therefore removed from the network substrate.
Note that this happens to be the same result as the widest path, but
this is not generally so, since the underlying protocol is still SPF, not
WPF.

21
CSPF Example 2: Resiliency

Given primary SPF path A->B->E, form a
secondary
path
with resilience constraint A->E

This is used in MPLS to compute secondary paths
used in
fail-over
.
A
B
C
E
D
1
1
2
1
1
2
1

The primary path is given by the dashed lines, and can therefore not
be used by the resilient path. The path A->B->E is therefore removed
from the network substrate.

Answer: the secondary path is A->C->E
CSPF with resiliency constraint is similar to k-shortest path: Find a
set of (mutually disjoint) shortest paths:

Compute SPF in steps, remove a computed path from the substrate for next
iteration

22
Explicit routing

Explicit routing is a manual alternative to CSPF

Explicit Route Objects (ERO)

Provide a set of nodes and compute SPF via this
set.

Example: A->E via D.
A
B
C
E
D
1
1
2
1
1
2
1
Note that the route A->D is not explicitly provided and is therefore
computed with SPF.

23
Summary: Routing algorithms

Most routing protocols use Dijkstra or Bellman-Ford

IP routing protocols all use SPF

L2 Ethernet uses spanning-tree and learning to
transform a network to a tree.

In traffic engineering, IP routing protocols are
extended with Constrained SPF

MPLS is the primary example