Faculty of
Engineering
Computer Network
Routing: Types and Algorithms
Computer Network
Dr. Ahmed Abdel Halim @ Helwan University
Fall 2018
Dr. Ahmed M. Abd El-Haleem
Assistant Professor in
Communication and Electronic Department
Faculty of Engineering, Helwan University
E-mail: dr.ahmed.m.abd.elhaleem@gmail.com
Types of Routing
3
IGP Interior Gateway Protocol EGP Exterior Gateway Protocol
RIP Routing Information Protocol OSPF Open Shortest Path First
IGRP Interior Gateway Routing Protocol EIGRP Enhanced IGRP
BGP Border Gateway Protocol
Types of Routing: Directly
Connected Networks
4
Directly connected networks are automatically
detected by the router without configuration.
Symbol in routing table is “ C ”.
Administrative Distance = 0
10.0.0.0 11.0.0.0 12.0.0.0 13.0.0.0
C 10.0.0.0 C 11.0.0.0 C 12.0.0.0
C 11.0.0.0 C 12.0.0.0 C 13.0.0.0
Types of Routing: Static Routing
5
A route (path) that a network administrator enters
into the router manually, to reach a certain network.
The administrator enters the route for each
destination into the table.
Symbol in routing table is “ S ”
Administrative Distance = 1.
Table cannot update automatically when there is a
change in the network.
A static routing table can be used in a small
networks.
It is poor strategy to use a static routing table in a
big networks such as the Internet.
Types of Routing: Static Routing
6
Purpose of a static route
A manually configured route used when routing
from a network to a stub network
This route allows the stub
network to reach all known
networks beyond router A
(gateway of last resort).
Types of Routing: Static Routing
7
Advantages
– Simplicity
– No extra resources are needed
– More secure
Disadvantages
– lack of flexibility
– Network changes require manual
reconfiguration
– Does not scale well in large topologies
Types of Routing: Dynamic Routing
8
Used by almost all packet switching networks.
A route (path) that a network routing protocol
discovers automatically and adjusted when topology
changes.
Failure: When a node or link fails, it can no longer
be used as part of a route.
Congestion: When a particular portion of the
network is heavily congested, it is desirable to
route packets around rather than through the area
of congestion.
Types of Routing: Dynamic Routing
9
The goal of a routing protocol is to build and maintain the
routing table.
A dynamic routing table is updated periodically by using one
of the dynamic routing protocols such as RIP, OSPF, or BGP.
Choosing the best path to destination networks
Ability to find a new best path if the current path is no longer
available
Symbol in routing
table according to
the routing protocol
used.
Routing protocol
must be configured
on the router.
Types of Routing: Dynamic Routing
10
The routing decision is more complex (processing on
nodes increased).
Tradeoff between quality of network info and
overhead. The more information that is exchanged, and
the more frequently it is exchanged, the better will be
the routing decisions.
Reacting too quickly can cause congestion-producing
oscillation.
Reacting to slowly means info may be irrelevant.
Types of Routing: Dynamic Routing
11
Advantages:
Improved performance , as seen by the
network user.
Aidcongestion control: Adaptive routing tends
to balance loads, it can delay the onset of
severe congestion.
Types of Routing: Dynamic Routing
12
Components of a routing protocol
– Routing protocol messages
• These are messages for discovering
neighbors and exchange of routing
information.
– Algorithm
• Is used for facilitating routing information
and best path determination.
Dynamic Routing: Algorithms
13
Virtually all packet-switching networks and all
internets base their routing decision on some form of
least-cost criterion.
Basis for routing decisions
If the criterion is to minimize the number of hops,
each link has a value of 1.
or the link value inversely proportional to its capacity,
or directly proportional to the current load on the
link, or some combination.
In any case, these link or hop costs are used as input
to a least-cost routing algorithm
Dynamic Routing: Algorithms
14
Defines cost of path between two nodes as sum
of costs of links traversed.
In network of nodes connected by bi-directional
links.
Each link has a cost in each direction.
For each pair of nodes, find path with least cost.
link costs in different directions may be different.
Alternatives: Dijkstra or Bellman-Ford
algorithms.
Algorithms: Dijkstra’s Shortest
Path First (SPF) Algorithm
15
Finds shortest paths
from given source node 𝒔
to all other nodes
Algorithm runs in stages
each time adding node
with next shortest path
Algorithm terminates when
all nodes processed by
algorithm (in set T)
Algorithms: Dijkstra’s Shortest
Path First (SPF) Algorithm
16
Definitions:
N = set of nodes in the network
s = source node
T = set of nodes so far incorporated by the algorithm
w(i, j) = link cost from node i to node j;
w(i, i) = 0; w(i, j) = ∞ if two nodes not directly connected;
w(i, j) ≥ 0 if two nodes are directly connected
L(n) = cost of the least-cost path from node s to node n that
is currently known to the algorithm; at termination, this is
the cost of the least-cost path in the graph from s to n.
Algorithms: Dijkstra’s Shortest
Path First (SPF) Algorithm
17
1) Start with the local node (router): the root of the tree.
2) Assign a cost of 0 to this node and make it the first
permanent node.
3) Examine each neighbor node of the node that was the last
permanent node.
4) Assign a cumulative cost to each node and make it tentative.
5) Among the list of tentative nodes
1) Find the node with the smallest cumulative cost and make it
permanent.
2) If a node can be reached from more than one direction
1) Select the direction with the shortest cumulative cost.
6) Repeat steps 3 to 5 until every node becomes permanent.
Algorithms: Dijkstra’s Shortest
Path First (SPF) Algorithm
18
Step 1 [Initialization]
T = {s} Set of nodes so far incorporated
L(n) = w(s, n) for n ≠ s
initial path costs to neighboring nodes are simply link costs
Step 2 [Get Next Node]
find neighboring node not in T with least-cost path from s
incorporate node into T
also incorporate the edge that is incident on that node and a node in T
that contributes to the path
Step 3 [Update Least-Cost Paths]
L(n) = min[L(n), L(x) + w(x, n)] for all n Ï T
f latter term is minimum, path from s to n is path from s to x
concatenated with edge from x to n
Algorithms: Dijkstra’s Shortest
Path First (SPF) Algorithm
19
Example: Apply Dijkstra's Shortest Path First
(SPF) algorithm to form the routing table for
node A of the network shown in Fig
Solution
Algorithms: Dijkstra’s Shortest
Path First (SPF) Algorithm
20
Algorithms: Dijkstra’s Shortest
Path First (SPF) Algorithm
21
Algorithms: Dijkstra’s Shortest
Path First (SPF) Algorithm
22
Algorithms: Dijkstra’s Shortest
Path First (SPF) Algorithm
23
Algorithms: Dijkstra’s Shortest
Path First (SPF) Algorithm
24
Algorithms: Dijkstra’s Shortest
Path First (SPF) Algorithm
25
Algorithms: Dijkstra’s Shortest
Path First (SPF) Algorithm
26
Algorithms: Dijkstra’s Shortest Path
First (SPF) Algorithm
Example
Algorithms: Bellman-Ford Algorithm
28
Find shortest paths from given node subject to constraint that
paths contain at most one link.
Find the shortest paths with a constraint of paths of at most
two links, and so on
definitions:
s = source node
w(i, j) = link cost from node i to node j
w(i, i) = 0, w(i, j) = if the two nodes are not directly connected
w(i, j) 0 if the two nodes are directly connected
h = maximum number of links in path at current stage of the
algorithm
Lh(n) = cost of least-cost path from s to n under constraint of
no more than h links
Algorithms: Bellman-Ford Algorithm
29
step 1 [Initialization]
L0(n) = , for all n s
Lh(s) = 0, for all h
step 2 [Update]
for each successive h 0
for each n ≠ s, compute: Lh+1(n)=minj[Lh(j) + w(j, n)]
Connect n with predecessor node j that gives min.
Eliminate any connection of n with different
predecessor node formed during an earlier
iteration
Path from s to n terminates with link from j to n
Algorithms: Bellman-Ford Example
30
5
B D
4
7
A 3 1 1
3
2
C 5
E
Algorithms: Bellman-Ford Example
31
5
Using vertex A B D
as the source 4
(setting its 7
distance to 0),
we initialize all A 3 1 1
the other
3
distances to ∞. 2
C 5
E
From A to
A B C D E
distance 0 ∞ ∞ ∞ ∞
path / / / / /
Algorithms: Bellman-Ford Example
32
Iteration 1: 5
Edges (uA,uB) 4
B D
and (uA,uC) 7
relax updating
the distances A 3 1 1
to B and C 3
2
C 5 E
From A to
A B C D E
distance 0 4 2 ∞ ∞
path A-B A-C / /
Algorithms: Bellman-Ford Example
33
Iteration 2: Edges 5
(uC,uB), (uB,uE), B D
(uB,uD), v and (uC,uD) 4
7
relax updating the
distances to B, D, A 3 1 1
and E respectively.
3
2
C 5 E
From A to
A B C D E
distance 0 3 2 9 7
path A-C-B A-C A-B/C-D A-B/C-E
Algorithms: Bellman-Ford Example
34
5
B D
4
7
A 3 1 1
3
2
C 5
E
From A to
A B C D E
distance 0 3 2 8 6
path A-C-B A-C A-C-B-D A-C-B-E
Algorithms: Bellman-Ford Example
35
5
B D
4
7
A 3 1 1
3
2
C 5
E
From A to
A B C D E
distance 0 3 2 7 6
path A-C-B A-C A-C-B-E-D A-C-B-E
Algorithms: Bellman-Ford Example
36
5
B D
4
7
A 3 1 1
3
2
C 5
E
From A to
A B C D E
distance 0 3 2 7 6
path A-C-B A-C A-C-B-E-D A-C-B-E
B D
37 A 1 1
3
2 E
C
From A to
A B C D E
∞ ∞ ∞ ∞ ∞
1 0 ∞ ∞ ∞ ∞
2 0 4 2 ∞ ∞
3 0 3 2 9 7
4 0 3 2 8 6
5 0 3 2 7 6
path A-C-B A-C A-C-B-E-D A-C-B-E
Algorithms: Bellman-Ford Example