Routing Algorithms
Routing Algorithms
net/publication/357226470
Routing Algorithms
CITATIONS READS
0 5,020
1 author:
Husam K Salih
Al-Rasheed University College
39 PUBLICATIONS 89 CITATIONS
SEE PROFILE
All content following this page was uploaded by Husam K Salih on 21 December 2021.
• Dijkstra Algorithm
• Flooding Outlines
• Distance Vector Routing
• Bellman-Ford Algorithm
• References
• The main function of the network layer is routing packets from
the source machine to the destination machine.
• The algorithms that choose the routes and the data structures
that they use are a major area of network layer design.
Routing Algorithms
Principle
• The routing algorithm is that part of the network layer software
responsible for deciding which output line an incoming packet
should be transmitted on.
A routing algorithm is a procedure that lays down the route or path to transfer
data packets from source to the destination. They help in directing Internet traffic
efficiently. After a data packet leaves its source, it can choose among the many
different paths to reach its destination. Routing algorithm mathematically
computes the best path, i.e. “least – cost path” that the packet can be routed
through.
• Adaptive routing algorithms, also known as dynamic routing algorithms, makes routing
decisions dynamically depending on the network conditions. It constructs the routing table
depending upon the network traffic and topology. They try to compute the optimized route
depending upon the hop count, transit time and distance.
• Non-adaptive Routing algorithms, also known as static routing algorithms, construct a static
routing table to determine the path through which packets are to be sent. The static routing
table is constructed based upon the routing information stored in the routers when the
network is booted up.
• The idea is to build a graph of the subnet, with each node of the
graph representing a router and each arc of the graph
representing a communication line (often called a link).
Shortest Path • To choose a route between a given pair of routers, the algorithm
Routing just finds the shortest path between them on the graph.
Figure 1: The first five steps used in computing the shortest path
from A to D. The arrows indicate the working node.
• One algorithm for finding the shortest path from a
starting node to a target node in a weighted graph is
Dijkstra’s algorithm.
Dijkstra Algorithm • The algorithm creates a tree of shortest paths from the
starting vertex, the source, to all other points in the
graph.
Requirements
1. Dijkstra's Algorithm can only work with graphs that have positive weights.
This is because, during the process, the weights of the edges have to be
added to find the shortest path.
2. If there is a negative weight in the graph, then the algorithm will not work
properly. Once a node has been marked as "visited", the current path to that
node is marked as the shortest path to reach that node. And negative
weights can alter this if the total weight can be decremented after this step
has occurred.
Dijkstra Algorithm
1. Mark all nodes unvisited. Create a set of all the unvisited nodes called the unvisited set.
2. Assign to every node a tentative distance value: set it to zero for our initial node and to infinity for
all other nodes. The tentative distance of a node v is the length of the shortest path discovered so
far between the node v and the starting node. Since initially no path is known to any other vertex
than the source itself (which is a path of length zero), all other tentative distances are initially set
to infinity. Set the initial node as current.
3. For the current node, consider all of its unvisited neighbors and calculate their tentative distances
through the current node. Compare the newly calculated tentative distance to the current assigned
value and assign the smaller one. For example, if the current node A is marked with a distance of
6, and the edge connecting it with a neighbor B has length 2, then the distance to B through A will
be 6 + 2 = 8. If B was previously marked with a distance greater than 8 then change it to 8.
Otherwise, the current value will be kept.
4. When we are done considering all of the unvisited neighbors of the current node, mark the current
node as visited and remove it from the unvisited set. A visited node will never be checked again.
5. If the destination node has been marked visited (when planning a route between two specific
nodes) or if the smallest tentative distance among the nodes in the unvisited set is infinity (when
planning a complete traversal; occurs when there is no connection between the initial node and
remaining unvisited nodes), then stop. The algorithm has finished.
6. Otherwise, select the unvisited node that is marked with the smallest tentative distance, set it as
the new current node, and go back to step 3.
Dijkstra Algorithm
Example 1
Dijkstra Algorithm
Example 1
Dijkstra Algorithm
Example 1
Dijkstra Algorithm
Example 1
Dijkstra Algorithm
Example 1
Dijkstra Algorithm
Example 1
Dijkstra Algorithm
Example 1
Dijkstra Algorithm
Example 1
Dijkstra Algorithm
Example 1
Dijkstra Algorithm
Example 1
Dijkstra Algorithm
Example 1
0 1 2 3 4 5 6
0 ∞ ∞ ∞ ∞ ∞ ∞
0 - 2 6 ∞ ∞ ∞ ∞
1 - - - 7 ∞ ∞ ∞
2 - - - 14 ∞ ∞ ∞
3 - - - - 17 22 ∞
4 - - - - - 23 19
5 - - - - - - 29
6 - - - - - - 19 {0,1,3,4,6} = 19
Dijkstra Algorithm
Example 1
0 1 3 4 6 = 19
Dijkstra Algorithm
Home Work 3
Find the shortest path of the following Graph using Dijkstra Algorithm.
• Another static algorithm is flooding, in which every incoming
packet is sent out on every outgoing line except the one it
arrived on.
Flooding • If the sender does not know how long the path is, it can
initialize the counter to the worst case, namely, the full
diameter of the subnet.
• In distance vector routing, each router maintains a routing table indexed by, and
containing one entry for, each router in the subnet. This entry contains two parts;
the preferred outgoing line to use for that destination and an estimate of the time
or distance to that destination.
• The metric used might be number of hops, time delay in milliseconds, total number
of packets queued along the path, or something similar.
• The router is assumed to know the ''distance'' to each of its neighbors. If the metric
is hops, the distance is just one hop.
• If the metric is queue length, the router simply examines each queue. If the metric
is delay, the router can measure it directly with special ECHO packets that the
receiver just timestamps and sends back as fast as it can.
• The researchers who developed it (Bellman, 1957; and
Ford and Fulkerson, 1962).
Algorithm
Bellman-Ford Algorithm
Example 2
Bellman-Ford Algorithm
Example 2
Bellman-Ford Algorithm
Example 2
Bellman-Ford Algorithm
Example 2
Bellman-Ford Algorithm
Example 2
Bellman-Ford Algorithm
Example 2
Bellman-Ford Algorithm
Example 2
Bellman-Ford Algorithm
Home Work 4
Find the shortest path of the following Graph using Bellman-Ford Algorithm.
[1] Behrouz A. Forouzan, ' Data Communications And Networking', 5th
Edition.
[3] James F Kurose, Keith W Ross, ' Computer Networking A Top Down
REFERENCES Approach', 6th Edition.
View publication stats