Routing Algorithms- Shortest-Path Routing, Flooding, Hierarchical routing,
Broadcast, Multicast and Distance Vector Routing.
Routing
o A Router is a process of selecting path along which the data can be
transferred from source to the destination. Routing is performed by a special
device known as a router.
o A Router works at the network layer in the OSI model and internet layer in
TCP/IP model
o A router is a networking device that forwards the packet based on the
information available in the packet header and forwarding table.
o The routing algorithms are used for routing the packets. The routing
algorithm is nothing but a software responsible for deciding the optimal path
through which packet can be transmitted.
o The routing protocols use the metric to determine the best path for the packet
delivery. The metric is the standard of measurement such as hop count,
bandwidth, delay, current load on the path, etc. used by the routing algorithm
to determine the optimal path to the destination.
o The routing algorithm initializes and maintains the routing table for the
process of path determination.
Routing Metrics and Costs
Routing metrics and costs are used for determining the best route to the destination.
The factors used by the protocols to determine the shortest path, these factors are
known as a metric.
Metrics are the network variables used to determine the best route to the
destination. For some protocols use the static metrics means that their value cannot
be changed and for some other routing protocols use the dynamic metrics means
that their value can be assigned by the system administrator.
The most common metric values are given below:
o Hop count: Hop count is defined as a metric that specifies the number of
passes through internetworking devices such as a router, a packet must travel
in a route to move from source to the destination. If the routing protocol
considers the hop as a primary metric value, then the path with the least hop
count will be considered as the best path to move from source to the
destination.
o Delay: It is a time taken by the router to process, queue and transmit a
datagram to an interface. The protocols use this metric to determine the
delay values for all the links along thepath end-to-end. The path having the
lowest delay value will be considered as the best path.
o Bandwidth: The capacity of the link is known as a bandwidth of the link. The
bandwidth is measured in terms of bits per second. The link that has a higher
transfer rate like gigabit is preferred over the link that has the lower capacity
like 56 kb. The protocol will determine the bandwidth capacity for all the links
along the path, and the overall higher bandwidth will be considered as the best
route.
o Load: Load refers to the degree to which the network resource such as a
router or network link is busy. A Load can be calculated in a variety of ways
such as CPU utilization, packets processed per second. If the traffic
increases, then the load value will also be increased. The load value changes
with respect to the change in the traffic.
o Reliability: Reliability is a metric factor may be composed of a fixed
value. It depends on the network links, and its value is measured
dynamically. Some networks go down more often than others. After network
failure, some network links repaired more easily than other network links.
Any reliability factor can be considered for the assignment of reliability
ratings, which are generally numeric values assigned by the system
administrator.
Types of Routing
Routing can be classified into three categories:
o Static Routing
o Default Routing
o Dynamic Routing
Static Routing
o Static Routing is also known as Nonadaptive Routing.
o It is a technique in which the administrator manually adds the routes in
a routing table.
o A Router can send the packets for the destination along the route defined
by the administrator.In this technique, routing decisions are not made
based on the condition or topology of the networks
Advantages Of Static Routing
Following are the advantages of Static Routing:
o No Overhead: It has ho overhead on the CPU usage of the router. Therefore,
the cheaper router can be used to obtain static routing.
o Bandwidth: It has not bandwidth usage between the routers.
o Security: It provides security as the system administrator is allowed only to
have control over the routing to a particular network.
Disadvantages of Static Routing:
Following are the disadvantages of Static Routing:
o For a large network, it becomes a very difficult task to add each route
manually to the routing table.
o The system administrator should have a good knowledge of a topology as he
has to add each route manually.
Default Routing
o Default Routing is a technique in which a router is configured to send all the
packets to the same hop device, and it doesn't matter whether it belongs to a
particular network or not. A Packet is transmitted to the device for which it
is configured in default routing.
o Default Routing is used when networks deal with the single exit point.
o It is also useful when the bulk of transmission networks have to transmit the
data to the same hp device.
o When a specific route is mentioned in the routing table, the router will
choose the specific route rather than the default route. The default route is
chosen only when a specific route is not mentioned in the routing table.
Dynamic Routing
o It is also known as Adaptive Routing.
o It is a technique in which a router adds a new route in the routing table for
each packet in response to the changes in the condition or topology of
the network.
o Dynamic protocols are used to discover the new routes to reach the
destination.
o In Dynamic Routing, RIP and OSPF are the protocols used to discover the new
routes.
o If any route goes down, then the automatic adjustment will be made to reach
the destination.
The Dynamic protocol should have the following features:
o All the routers must have the same dynamic routing protocolin order to exchange the
routes.
o If the router discovers any change in the condition or topology, then router
broadcast this information to all other routers.
Advantages of Dynamic Routing:
o It is easier to configure.
o It is more effective in selecting the best route in response to the changes in
the condition or topology.
Disadvantages of Dynamic Routing:
o It is more expensive in terms of CPU and bandwidth usage.
o It is less secure as compared to default and static routing.
Routing algorithm
o In order to transfer the packets from source to the destination, the network
layer must determine the best route through which packets can be
transmitted.
o Whether the network layer provides datagram service or virtual circuit
service, the main job of the network layer is to provide the best route. The
routing protocol provides this job.
o The routing protocol is a routing algorithm that provides the best path from
the source to the destination. The best path is the path that has the "least-cost
path" from source to the destination.
o Routing is the process of forwarding the packets from source to the
destination but the best route to send the packets is determined by the
routing algorithm.
Classification of a Routing algorithm
The Routing algorithm is divided into two categories:
o Adaptive Routing algorithm
o Non-adaptive Routing algorithm
Adaptive Routing algorithm
o An adaptive routing algorithm is also known as dynamic routing
algorithm.This algorithm makes the routing decisions based on the topology
and network traffic.
o The main parameters related to this algorithm are hop count, distance and
estimated transit time.
An adaptive routing algorithm can be classified into three parts:
o Centralized algorithm: It is also known as global routing algorithm as it
computes the least-cost path between source and destination by using
complete and global knowledge about the network. This algorithm takes the
connectivity between the nodes and link cost as input, and this information
is obtained before actually performing any calculation. Link state algorithm
is referred to as a centralized algorithm since it is aware of the cost of each
link in the network.
o Isolation algorithm: It is an algorithm that obtains the routing information
by using local information rather than gathering information from other
nodes.
o Distributed algorithm: It is also known as decentralized algorithm as it
computes the least-cost path between source and destination in an iterative and
distributed manner. In the decentralized algorithm, no node has the knowledge
about the cost of all the network links. In the beginning, a node contains the
information only about its own directly attached links and through an iterative
process of calculation computes the least-cost path to the destination. A
Distance vector algorithm is a decentralized algorithm as it never knows the
complete path from source to the destination, instead it knows the direction
through which the packet is to be forwarded along with the least cost path.
Non-Adaptive Routing algorithm
o Non Adaptive routing algorithm is also known as a static routing algorithm.
o When booting up the network, the routing information stores to the routers.
o Non Adaptive routing algorithms do not take the routing decision based on the
network topology or network traffic.
The Non-Adaptive Routing algorithm is of two types:
Flooding: In case of flooding, every incoming packet is sent to all the outgoing
links except the one from it has been reached. The disadvantage of flooding is that
node may contain several copies of a particular packet.
Random walks: In case of random walks, a packet sent by the node to one of its
neighbors randomly. An advantage of using random walks is that it uses the
alternative routes very efficiently.
Differences b/w Adaptive and Non-Adaptive Routing Algorithm
Basis Of Adaptive Routing Non-Adaptive Routing
Comparison algorithm algorithm
Define Adaptive Routing algorithm The Non-Adaptive Routing
is an algorithm that algorithm is an algorithm that
constructs the routing table constructs the static table to
based on the network determine which
conditions. node to send the packet.
Usage Adaptive routing algorithm The Non-Adaptive Routing
is used by dynamic algorithm is used by static
routing. routing.
Routing decision Routing decisions are Routing decisions are the
made based on topology static tables.
and network traffic.
Categorization The types of adaptive The types of Non Adaptive
routing algorithm, are routing algorithm are flooding
Centralized, isolation and and random walks.
distributed algorithm.
Complexity Adaptive Routing Non-Adaptive Routing
algorithms are more algorithms are simple.
complex.
Shortest Path Routing
Links between routers have a cost associated with them. It could be a
function of distance, bandwidth, average traffic, communication cost, mean
queue length, measured delay, router processing speed, etc.
The shortest path algorithm finds the least expensive path through the
network based on the cost function.
Examples: Dijkstra's algorithm
Distance Vector Routing
Each router periodically shares knowledge about the entire network with its
neighbours in this routing scheme. Each router has a table with information
about the network. These tables are updated by exchanging information with the
immediate neighbours. It is also known as Belman-Ford or Ford-Fulkerson
Algorithm. It is used in the original ARPANET and the Internet as RIP.
Neighbouring nodes in the subnet exchange their tables periodically to update
each other on the state of the subnet (which makes this a dynamic algorithm).
If a neighbour claims to have a path to a node shorter than your path, you
start using that neighbour as the route to that node.
Distance vector protocols (a vector contains both distance and direction),
such as RIP, determine the path to remote networks using hop count as the
metric. A hop count is defined as the number of times a packet needs to
pass through a router to reach a remote destination.
For IP RIP, the maximum hop is 15. Therefore, a hop count of
16 indicates an unreachable network. Two versions of RIP exist version 1
and version 2.IGRP is another example of a distance vector protocol with a
higher hop count of 255 hops.
Periodic updates are sent at a set interval. For IP RIP, this interval is 30
seconds.
Updates are sent to the broadcast address 255.255.255.255. Only devices
running routing algorithms listen to these updates.
When an update is sent, the entire routing table is sent.
Link State Routing
The following sequence of steps can be executed in the Link State Routing. This
advertising is a short pack called a Link State Packet (LSP). OSPF (Open shortest
path first) and IS-IS are examples of Link state routing. Link State Packet(LSP)
contains the following information:
1. The ID of the node that created the LSP;
2. A list of directly connected neighbours of that node, with the cost of the
link to each one;
3. A sequence number;
4. A time to live(TTL) for this packet.
When a router floods the network with information about its
neighbourhood, it is said to be advertising.
1. Discover your neighbours
2. Measure delay to your neighbours
3. Bundle all the information about your neighbours together
4. Send this information to all other routers in the subnet
5. Compute the shortest path to every router with the
information you receive
6. Each router finds its own shortest path to the other routers using
Dijkstra's algorithm.
In link-state routing, each router shares its knowledge of its neighbourhood with all
routers in the network. Link-state protocols implement an algorithm called the
shortest path first (SPF, also known as Dijkstra's Algorithm) to determine the path
to a remote destination. There is no hop-count limit. (For an IP datagram, the
maximum time to live ensures that loops are avoided.).Only when changes occur, It
sends all summary information every 30 minutes by default. Only devices running
routing algorithms listen to these updates. Updates are sent to a multicast address.
As a result, updates are faster, and convergence times are reduced. Higher CPU and
memory requirements to maintain link-state databases. Link- state protocols
maintain three separate tables.
1. Neighbour table: It contains a list of all neighbours and the interface to
which each neighbour is connected. Neighbours are formed by sending
Hello packets.Topology table (Link- State table): It contains a map of all
links within an area, including each link’s status.
2. Routing table: It contains the best routes to each particular destination
Flooding Algorithm
It is a non-adaptive algorithm or static algorithm. When a router receives a packet,
it sends a copy of the packet out on each line (except the one on which it arrived).
Each router decrements a hop count contained in the packet header to prevent
looping forever. As soon as the hop count decrements to zero, the router discards
the packet.
Flow-Based Routing Algorithm
It is a non-adaptive routing algorithm.
It takes into account both the topology and the load in this routing
algorithm;
We can estimate the flow between all pairs of routers.
You can compute the mean packet delays using queuing theory from the
known average amount of traffic and the average length of a packet.
Flow-based routing then seeks to find a routing table to minimize the
average packet delay through the subnet.
Given the line capacity and the flow, we can determine the delay. It needs to
use the formula for delay time T.
Where, μ = Mean number of arrivals in packet/sec, 1/μ = The mean packet
size in the bits, and c = Line capacity (bits/s).
The Optimality Principle simply states that if router J is on the optimal path
from the router I to router k, then the optimal path from J to K also falls along
this same path.
Dijkstra's Algorithm
Dijkstra algorithm is a single-source shortest path algorithm. Here, single-source
means that only one source is given, and we have to find the shortest path from the
source to all the nodes.
Let's understand the working of Dijkstra's algorithm. Consider the below graph.
First, we have to consider any vertex as a source vertex. Suppose we consider
vertex 0 as a source vertex.
Here we assume that 0 as a source vertex, and distance to all the other vertices is
infinity. Initially, we do not know the distances. First, we will find out the vertices
which are directly connected to the vertex 0. As we can observe in the above graph
that two vertices are directly connected to vertex 0.
Let's assume that the vertex 0 is represented by 'x' and the vertex 1 is represented
by 'y'. The distance between the vertices can be calculated by using the below
formula:
1. d(x, y) = d(x) + c(x, y) < d(y) 2. = (0
+ 4) < ∞
3. = 4 < ∞
Since 4<∞ so we will update d(v) from ∞ to 4.
Therefore, we come to the conclusion that the formula for calculating the distance
between the vertices:
1. {if( d(u) + c(u, v) < d(v))
2. d(v) = d(u) +c(u, v) }
Now we consider vertex 0 same as 'x' and vertex 4 as 'y'.
1. d(x, y) = d(x) + c(x, y) < d(y) 2. = (0
+ 8) < ∞
3. = 8 < ∞
Therefore, the value of d(y) is 8. We replace the infinity value of vertices 1 and 4 with
the values 4 and 8 respectively. Now, we have found the shortest path from the vertex
0 to 1 and 0 to 4. Therefore, vertex 0 is selected. Now, we will compare all the
vertices except the vertex 0. Since vertex 1 has the lowest value, i.e., 4; therefore,
vertex 1 is selected.
Since vertex 1 is selected, so we consider the path from 1 to 2, and 1 to 4. We will
not consider the path from 1 to 0 as the vertex 0 is already selected.
First, we calculate the distance between the vertex 1 and 2. Consider the vertex 1
as 'x', and the vertex 2 as 'y'.
1. d(x, y) = d(x) + c(x, y) < d(y) 2. =
(4 + 8) < ∞
3. = 12 < ∞
Since 12<∞ so we will update d(2) from ∞ to 12.
Now, we calculate the distance between the vertex 1 and vertex 4. Consider the
vertex 1 as 'x' and the vertex 4 as 'y'.
1. d(x, y) = d(x) + c(x, y) < d(y) 2. =
(4 + 11) < 8
3. = 15 < 8Since 15 is not less than 8, we will not update the value d(4) from 8 to 12.
Till now, two nodes have been selected, i.e., 0 and 1. Now we have to compare the
nodes except the node 0 and 1. The node 4 has the minimum distance, i.e., 8.
Therefore, vertex 4 is selected.
Since vertex 4 is selected, so we will consider all the direct paths from the vertex 4.
The direct paths from vertex 4 are 4 to 0, 4 to 1,
4 to 8, and 4 to 5. Since the vertices 0 and 1 have already been selected so we will
not consider the vertices 0 and 1. We will consider only two vertices, i.e., 8 and 5.
First, we consider the vertex 8. First, we calculate the distance between the vertex 4
and 8. Consider the vertex 4 as 'x', and the vertex 8 as 'y'.
1. d(x, y) = d(x) + c(x, y) < d(y) 2. =
(8 + 7) < ∞
3. = 15 < ∞
Since 15 is less than the infinity so we update d(8) from infinity to 15.
Now, we consider the vertex 5. First, we calculate the distance between the vertex
4 and 5. Consider the vertex 4 as 'x', and the vertex 5 as 'y'.
1. d(x, y) = d(x) + c(x, y) < d(y) 2. =
(8 + 1) < ∞
3. = 9 < ∞
Since 5 is less than the infinity, we update d(5) from infinity to 9. Till now, three
nodes have been selected, i.e., 0, 1, and 4. Now we have to compare the nodes
except the nodes 0, 1 and 4. The node 5 has the minimum value, i.e., 9. Therefore,
vertex 5 is selected.
Since the vertex 5 is selected, so we will consider all the direct paths from vertex
5. The direct paths from vertex 5 are 5 to 8, and 5 to 6.
First, we consider the vertex 8. First, we calculate the distance between the vertex 5
and 8. Consider the vertex 5 as 'x', and the vertex 8 as 'y'.
1. d(x, y) = d(x) + c(x, y) < d(y) 2. =
(9 + 15) < 15
3. = 24 < 15
Since 24 is not less than 15 so we will not update the value d(8) from 15 to 24.
Now, we consider the vertex 6. First, we calculate the distance between the vertex
5 and 6. Consider the vertex 5 as 'x', and the vertex 6 as 'y'.
1. d(x, y) = d(x) + c(x, y) < d(y) 2. =
(9 + 2) < ∞</p>3. = 11 < ∞
Since 11 is less than infinity, we update d(6) from infinity to 11.
Till now, nodes 0, 1, 4 and 5 have been selected. We will compare the nodes except
the selected nodes. The node 6 has the lowest value as compared to other nodes.
Therefore, vertex 6 is selected.
Since vertex 6 is selected, we consider all the direct paths from vertex 6. The direct
paths from vertex 6 are 6 to 2, 6 to 3, and 6 to
7.
First, we consider the vertex 2. Consider the vertex 6 as 'x', and the vertex 2 as 'y'.
A Dutch computer scientist, Edsger Dijkstra, in 1959, proposed an algorithm
that can be applied to a weighted graph. The graph can either be directed or
undirected with the condition that the graph needs to embrace a non-negative value
on its every edge. He named this algorithm “Dijkstra’s Algorithm” at his name.
Let’s dive right into the blog and we will learn
Introduction to Graphs
1. What is Dijkstra’s Algorithm?
2. How to Implement the Dijkstra's Algorithm?
3. Working Example of Dijkstra's Algorithm
4. Applications of Dijkstra’s Algorithm
5. Advantages and Disadvantages of Dijkstra’s Algorithm
In the series of blogs, we particularly focus on the detailed study, based on graphs,
i.e., Group Theory and knowledge Graph, this blog will serve in building our
knowledge base to the next level.
Introduction to Graphs
In simple words, graphs are data structures that are used to depict connections
amidst a couple of elements where these elements are called nodes (or vertex) that
generally real-time objects, persons or entities and connections amid nodes are
termed as edges. Also, two nodes only get connected if there is an edge between
them.
"A graph is essentially an interrelationship of nodes/vertices connected by
edges."
Generally, graphs are suited to real-world applications, such as graphs can be used
to illustrate a transportation system/network, where nodes represent facilities that
transfer or obtain products and edges show routes or subways that connect nodes.
Graphs can be divided into two parts:
Undirected Graphs: For every couple of associated nodes, if an individual
could move from one node to another in both directions, then the graph is
termed as an undirected graph.
Directed Graphs: For every couple of associated graphs, if an individual could
move from one node to another in a specific (single) direction, then the graph is
known as the directed graph. In this case, arrows are implemented rather
than simple lines in order to represent directed edges.
Weighted Graphs
The weight graphs are the graphs where edges of the graph have “a weight” or
“cost” and also where weight could reflect distance, time, money or anything that
displays the “association” amid a couple of nodes it links. These weights are an
essential element under Dijkstra's Algorithm.
What is Dijkstra’s Algorithm?
What if you are provided with a graph of nodes where every node is linked to
several other nodes with varying distance. Now, if you begin from one of the
nodes in the graph, what is the shortest path to every other node in the graph?
Well simply explained, an algorithm that is used for finding the shortest
distance, or path, from starting node to target node in a weighted graph is
known as Dijkstra’s Algorithm.
This algorithm makes a tree of the shortest path from the starting node, the source, to
all other nodes (points) in the graph.
Dijkstra's algorithm makes use of weights of the edges for finding the path that
minimizes the total distance (weight) among the source node and all other nodes.
This algorithm is also known as the single-source shortest path algorithm.
Dijkstra’s algorithm is the iterative algorithmic process to provide us with the
shortest path from one specific starting node to all other nodes of a graph. It is
different from the minimum spanning tree as the shortest distance among two
vertices might not involve all the vertices of the graph.
It is important to note that Dijkstra’s algorithm is only applicable when all weights
are positive because, during the execution, the weights of the edges are added to
find the shortest path.
And therefore if any of the weights are introduced to be negative on the edges of
the graph, the algorithm would never work properly. However, some algorithms
like the Bellman-Ford Algorithm can be used in such cases.
It is also a known fact that breadth-first search(BFS) could be used for calculating
the shortest path for an unweighted graph, or for a weighted graph that has the
same cost at all its edges.
But if the weighted graph has unequal costs at all its edges, then BFS infers
uniform-cost search. Now what?
Instead of extending nodes in order of their depth from the root,
uniform-cost search develops the nodes in order of their costs from the root. And a
variant of this algorithm is accepted as Dijkstra’s Algorithm.
Generally, Dijkstra’s algorithm works on the principle of relaxation where an
approximation of the accurate distance is steadily displaced by more suitable values
until the shortest distance is achieved.
Also, the estimated distance to every node is always an overvalue of the true
distance and is generally substituted by the least of its previous value with the
distance of a recently determined path.
It uses a priority queue to greedily choose the nearest node that has not been
visited yet and executes the relaxation process on all of its edges.
Example Involved
For example, an individual wants to calculate the shortest distance between the
source, A, and the destination, D, while calculating a subpath which is also the
shortest path between its source and destination. Let’s see here how Dijkstra’s
algorithm works; It works on the fact that any subpath, let say a subpath B to D
of the shortest path between vertices A and D is also the shortest path between
vertices B and D, i.e., each subpath is the shortest path. Here, Dijkstra’s algorithm
uses this property in the reverse direction, that means, while determining distance,
we overestimate the distance of each vertex from the starting vertex then inspect
each node and its neighbours for detecting the shortest subpath to those
neighbours.
This way the algorithm deploys a greedy approach by searching for the next plausible
solution and expects that the end result would be the appropriate solution for the
entire problem.
How to Implement the Dijkstra Algorithm?
Before proceeding the step by step process for implementing the algorithm, let us
consider some essential characteristics of Dijkstra’s algorithm;
Basically, the Dijkstra’s algorithm begins from the node to be selected, the
source node, and it examines the entire graph to determine the shortest path
among that node and all the other nodes in the graph.
The algorithm maintains the track of the currently recognized shortest
distance from each node to the source code and updates these values if it
identifies another shortest path.
Once the algorithm has determined the shortest path amid the source code to
another node, the node is marked as “visited” and can be added to the path.
This process is being continued till all the nodes in the graph have been
added to the path, as this way, a path gets created that connects the source
node to all the other nodes following the plausible shortest path to reach
each node.
Now explaining the step by step process of algorithm implementation;
The very first step is to mark all nodes as unvisited,
1. Mark the picked starting node with a current distance of 0 and the rest
nodes with infinity,
2. Now, fix the starting node as the current node,
3. For the current node, analyse all of its unvisited neighbours and measure
their distances by adding the current distance of the current node to the
weight of the edge that connects the neighbour node and current node,
4. Compare the recently measured distance with the current distance assigned
to the neighbouring node and make it as the new current distance of the
neighbouring node,
5. After that, consider all of the unvisited neighbours of the current node, mark
the current node as visited,
6. If the destination node has been marked visited then stop, an algorithm has
ended, and
7. Else, choose the unvisited node that is marked with the least distance, fix it
as the new current node, and repeat the process again from step 4.
Working Example of Dijkstra's Algorithm
In the above section, you have gained the step by step process of Dijkstra’s
algorithm, now let’s study the algorithm with an explained example.
We will calculate the shortest path between node C and the other nodes in the
graph.
Example of Dijkstra's Algorithm
1. During the execution of the algorithm, each node will be marked with its
minimum distance to node C as we have selected node C.
In this case, the minimum distance is 0 for node C. Also, for the rest of the nodes,
as we don’t know this distance, they will be marked as infinity (∞), except node C
(currently marked as red dot).
Graphical Representation of Node C as Current Node
2. Now the neighbours of node C will be checked, i.e, node A, B, and D. We
start with B, here we will add the minimum distance of current node (0) with
the weight of the edge (7) that linked the node C to node B and get 0+ 7= 7.
Now, this value will be compared with the minimum distance of B (infinity), the
least value is the one that remains the minimum distance of B, like in this case,
7 is less than infinity, and marks the least value to node B.
Assign Node B a minimum distance value
3. Now, the same process is checked with neighbour A. We add 0 with 1
(weight of edge that connects node C to A), and get 1. Again, 1 is compared
with the minimum distance of A (infinity), and marks the lowest value.
Assign Node A a minimum distance value
The same is repeated with node D, and marked 2 as lowest value at D.
Assign Node D a minimum distance value
Since, all the neighbours of node C have checked, so node C is marked as visited
with a green check mark.
Marked Node C as visited
4. Now, we will select the new current node such that the node must be
unvisited with the lowest minimum distance, or the node with the least
number and no check mark. Here, node A is the unvisited with minimum
distance 1, marked as current node with red dot.
Graphical Representation of Node A as Current Node
We repeat the algorithm, checking the neighbour of the current node while ignoring
the visited node, so only node B will be checked.
For node B, we add 1 with 3 (weight of the edge connecting node A to B) and
obtain 4. This value, 4, will be compared with the minimum distance of B, 7, and
mark the lowest value at B as 4.
Assign Node B a minimum distance value
5. After this, node A marked as visited with a green check mark. The current
node is selected as node D, it is unvisited and has a smallest recent
distance. We repeat the algorithm and check for node B and E.
Graphical Representation of Node D as Current Node
For node B, we add 2 to 5, get 7 and compare it with the minimum distance value
of B, since 7>4, so leave the smallest distance value at node B as 4.
For node E, we obtain 2+ 7= 9, and compare it with the minimum distance of E
which is infinity, and mark the smallest value as node E as 9. The node D is
marked as visited with a green check mark.
Marked Node D as visited
6. The current node is set as node B, here we need to check only node E as it is
unvisited and the node D is visited. We obtain 4+ 1=5, compare it with the
minimum distance of the node.
As 9 > 5, leave the smallest value at node node E as 5.
We mark D as visited node with a green check mark, and node E is set as the current
node.
Marked Node B as visited
7. Since it doesn’t have any unvisited neighbours, so there is not any
requirement to check anything. Node E is marked as a visited node with a
green mark.
Marked Node E as visited
So, we are done as no unvisited node is left. The minimum distance of each node is
now representing the minimum distance of that node from node C.
Applications of Dijkstra’s Algorithm
Before learning any algorithm, we should know the fundamental purpose of using
an algorithm that could help us in real-world applications. Such as, for Dijkstra’s
algorithm, we are trying to find the solutions to least path based problems.
For example, if a person wants to travel from city A to city B where both cities are
connected with various routes. Which route commonly he/ she should choose?
Undoubtedly, we would adopt the route through which we could reach the
destination with the least possible time, distance and even cost.
Further, with the discussion, it has various real-world use cases, some of the
applications are the following:
For map applications, it is hugely deployed in measuring the least possible
distance and check direction amidst two geographical regions like Google
Maps, discovering map locations pointing to the vertices of a graph,
calculating traffic and delay-timing, etc.
For telephone networks, this is also extensively implemented in the
conducting of data in networking and telecommunication domains for
decreasing the obstacle taken place for transmission.
Wherever addressing the need for shortest path explications either in the
domain of robotics, transport, embedded systems, laboratory or production
plants, etc, this algorithm is applied.
Besides that, other applications are road conditions, road closures and
construction, and IP routing to detect Open Shortest Path First.
Advantages and Disadvantages of Dijkstra’s Algorithm Discussing
some advantages of Dijkstra’s algorithm;
1. One of the main advantages of it is its little complexity which is almost
linear.
2. It can be used to calculate the shortest path between a single node to all other
nodes and a single source node to a single destination node by stopping the
algorithm once the shortest distance is achieved for the destination node.
3. It only works for directed-, weighted graphs and all edges should have non-
negative values.
Despite various applications and advantages, Dijkstra’s algorithm has
disadvantages also, such as;
It does an obscured exploration that consumes a lot of time while processing,
1. It is unable to handle negative edges,
2. As it heads to the acyclic graph, so can’t achieve the accurate shortest path,
and
3. Also, there is a need to maintain tracking of vertices, have been visited.flooding in
Computer Network
Flooding is a non-adaptive routing technique following this simple method: when a
data packet arrives at a router, it is sent to all the outgoing links except the one it
has arrived on.
For example, let us consider the network in the figure, having six routers that are
connected through transmission lines.
Using flooding technique −
An incoming packet to A, will be sent to B, C and D.
B will send the packet to C and E.
C will send the packet to B, D and F.
D will send the packet to C and F.
E will send the packet to F.
F will send the packet to C and E. Types
of Flooding
Flooding may be of three types −
Uncontrolled flooding − Here, each router unconditionally transmits the
incoming data packets to all its neighbours.
Controlled flooding − They use some methods to control the transmission of
packets to the neighbouring nodes. The two popular algorithms for controlled
flooding are Sequence Number Controlled Flooding (SNCF) and Reverse Path
Forwarding (RPF).
Selective flooding − Here, the routers don't transmit the incoming packets only
along those paths which are heading towards approximately in the right
direction, instead of every available paths.
Advantages of Flooding
It is very simple to setup and implement, since a router may know only its
neighbours.
It is extremely robust. Even in case of malfunctioning of a large number
routers, the packets find a way to reach the destination.
All nodes which are directly or indirectly connected are visited. So, there
are no chances for any node to be left out.This is a main criteria in case
of broadcast messages.
The shortest path is always chosen by flooding.
Limitations of Flooding
Flooding tends to create an infinite number of duplicate data packets, unless
some measures are adopted to damp packet generation.
It is wasteful if a single destination needs the packet, since it delivers the
data packet to all nodes irrespective of the destination.
The network may be clogged with unwanted and duplicate data packets. This
may hamper delivery of other data packets.
What is the flooding routing algorithm?
Desirable Properties of Routing Algorithms:-
Correctness and Simplicity
Robustness: Ability of the network to deliver packets via some route even in
the face of failures.
Stability: The algorithm should converge to equilibrium fast in the face of
changing conditions in the network.
Fairness and Optimality
Efficiency: Minimum overhead.
Design Parameters of Routing Algorithms :
Performance Criteria: Number of hops, Cost(Send packet with high bandwidth
path as the cost is less), Delay(Size of Queue), Throughput time(Number of
packets delivered/time).
Decision Time: When to decide to route a packet? Per- Packet(Datagram) or
Per-session(Virtual-Circuit).
Decision Place: Who will decide about routing? Each Node(distributed),
Central Node (centralized),Originated Node (source) .
Network Information Source: None, Local, Adjacent node, Nodes along the
route, All nodes.
Network Information Update Time: Continuous, Periodic, Major Load
Change, Topology Change.
Routing Strategies :
1. Fixed Routing
2. Flooding
3. Dynamic Routing
4. Random Routing
5. Flow-based Routing
Fixed Routing –
A route is selected for each source and destination pair of nodes in the
network.
The route is fixed; changes only if the topology of the network changes.
Fixed Routing: Example (1)
Figure – A simple packet switching network with six nodes
(routers)
Figure – Central routing table based on least-cost path algorithm
A Central routing matrix is created based on the least-cost path which is
stored in the network control center
The matrix shows for each source-destination of the route, the identity
of the next node on the route.
Drawback: If the network control center fails, then everything will collapse.
Hence it is not reliable.
Fixed Routing: Example (2)
Figure – Routing table stored in different nodes of the network
Routing Table is created for each node. This is called a distributed routing
algorithm
Routing table can be created using the least-min path or min- hop reach
method. Two famous path algorithms
1. Dijkstra Algorithm
2. Bellman Ford Algorithm
Advantages –
Simple
Works well in reliable network with stable load in a reliable network
Same for virtual circuit and datagram
Disadvantages –
Lack of flexibility
Doesn’t react to failure or network congestion
Hop-Count –
A hop counter may be contained in the packet header which is
decremented at each hop. with the packet
being discarded when the counter becomes zero
The sender initializes the hop counter. If no estimate is
known, it is set to the full diameter of the subnet.
Keep track of the packets which are responsible for flooding using a sequence
number. Avoid sending them out a second time.Selective Flooding: Routers do not
send every incoming packet out on every line, only on those lines that go in
approximately in the direction of the destination.
What is hierarchical routing?
In hierarchical routing, the routers are divided into regions. Each router has
complete details about how to route packets to destinations within its own region.
But it does not have any idea about the internal structure of other regions.
As we know, in both LS and DV algorithms, every router needs to save some
information about other routers. When network size is growing, the number of routers
in the network will increase. Therefore, the size of routing table increases, then routers
cannot handle network traffic as efficiently. To overcome this problem we are
using hierarchical routing.
In hierarchical routing, routers are classified in groups called regions. Each router
has information about the routers in its own region and it has no information about
routers in other regions. So, routers save one record in their table for every other
region.
For huge networks, a two-level hierarchy may be insufficient hence, it may be
necessary to group the regions into clusters, the clusters into zones, the zones into
groups and so on.
Example
Consider an example of two-level hierarchy with five regions as shown in
figure −
Let see the full routing table for router 1A which has 17 entries, as shown below
−
Full Table for 1A
Dest. Line Hops
1A - -
1B 1B 1
1C 1C 1
2A 1B 2
2B 1B 3
2C 1B 3
2D 1B 4
3A 1C 3
3B 1C 2
4A 1C 3
4B 1C 4
4C 1C 4
5A 1C 4
5B 1C 5
5C 1B 5
5D 1C 6
5E 1C 5
When routing is done hierarchically then there will be only 7 entries as shown
below −
Hierarchical Table for 1A
Dest. Line Hops
1A - -
1B 1B 1
1C 1C 1
2 1B 2
3 1C 2
4 1C 3
5 1C 4
Unfortunately, this reduction in table space comes with the
increased path length.
Explanation
Step 1 − For example, the best path from 1A to 5C is via region 2, but hierarchical
routing of all traffic to region 5 goes via region 3 as it is better for most of the
other destinations of region 5.
Step 2 − Consider a subnet of 720 routers. If no hierarchy is used, each router will
have 720 entries in its routing table.
Step 3 − Now if the subnet is partitioned into 24 regions of 30 routers each, then
each router will require 30 local entries and 23 remote entries for a total of 53 entries.
Example
If the same subnet of 720 routers is partitioned into 8 clusters, each containing 9
regions and each region containing 10 routers. Then what will be the total number
of table entries in each router.
Solution
10 local entries + 8 remote regions + 7 clusters = 25 entries.
Difference between Hierarchical and Flat routing protocol
1. Hierarchical Routing Protocol:
Hierarchical Routing is the method of routing in networks that is based on
hierarchical addressing. Most transmission control protocol, Internet protocol
(TCPIP). Routing is based on two level of hierarchical routing in which IP address
is divided into a network, person and a host person. Gateways use only the network
a person tell an IP data until gateways delivered it directly.
It addresses the growth of routing tables. Routers are further divided into regions
and they know the route of their own regions only. It works like a telephone
routing.
Example –
City, State, Country, Continent.
2. Flat Routing Protocol:
In flat routing protocol, if any node needs to transmit data, it first searches for a
valid route to the base station and then transmits the data. Nodes to the base
station may drain their energy quickly. They are the flat networks in which every
incoming packet is sent out on every outgoing line except the one it arrived on.
Vast numbers of duplicate packets are generated. It is good for small networks and
offers high reliability.
Example –
Routing Information Protocol, Interior Gateway Routing Protocol.
Difference between Hierarchical and Flat Routing Protocol :
Hierarchical Routing Protocol Flat Routing Protocol
It is simple but non-optimal Routing can be made optimal but
routing. with an added complexity.
It is a Channel Reservation- It is a Contention-based
based scheduling. scheduling.
Collisions is avoided. Collisions over-head in attendance.
Overhead of cluster Routes form only in the regions
information all over the that have data for transmission.
network.
Fair channel allocation. Fairness is not guaranteed.
In this, Energy Dissipation is In this, Energy Dissipation depends
consistent. on traffic patterns.
Difference between Broadcast and Multicast
1. Broadcast :
Broadcast transfer (one-to-all) techniques and can be classified into two types :
Limited Broadcasting, Direct Broadcasting. In broadcasting mode, transmission
happens from one host to all the other hosts connected on the LAN. The devices
such as bridge uses
this. The protocol like ARP implement this, in order to know MAC address for the
corresponding IP address of the host machine. ARP does ip address to mac address
translation. RARP does the reverse.
2. Multicasting :
Multicasting has one/more senders and one/more recipients participate in data
transfer traffic. In multicasting traffic recline between the boundaries of unicast and
broadcast. It server’s direct single copies of data streams and that are then
simulated and routed to hosts that request it. IP multicast requires support of some
other protocols such as IGMP (Internet Group Management Protocol), Multicast
routing for its working. And also in Classful IP addressing Class D is reserved for
multicast groups.
Difference between Broadcast and Multicast :
S.No. Broadcast Multicast
1. It has one sender and It has one or more
multiple receivers. senders and multiple
receivers.
2. It sent data from one device to all It sent data from one
the other devices in a device to multiple devices.
network.
3. It works on star and bus It works on star, mesh, tree and
topology. hybrid topology.
4. It scale well across large It does not scale well
networks. across large networks.
5. Its bandwidth is wasted. It utilizes bandwidth
efficiently.
6. It has one-to-all mapping. It has one-to-many
mapping.
7. Hub is an example of a Switch is an example of a
broadcast device. multicast device.
Unicast, Broadcast, and Multicast in Computer Networks Casting in computer
networks means transmitting data (stream of packets) over a network. Following
are the different types of casting used in networking −
Unicast transmission
Broadcast transmission
Multicast transmission
Unicast Transmission (One-to-One)
In Unicast transmission, the data is transferred from a single sender (or a single
source host) to a single receiver (or a single destination host).
The network switches hear the MAC addresses of the devices on the networks
to which they are connected. They can then forward packets only onto those
networks containing devices with the connected MAC addresses. Unicast gradually
becomes less efficient as more receivers need to see identical data.
Example
In the following figure, Host A sends the IP address 11.1.2.2 data to the Host B
IP address 20.12.4.3.
Source Address = IP address of host A is 11.1.2.2
Destination Address = IP address of host B is 20.12.4.3
Broadcast Transmission (One-to-All)
In Broadcast transmission, the data is transmitted from one or more senders to all
the receivers within the same network or in other networks. This type of
transmission is useful in network management packets such as ARP (Address
Resolution Protocol) and RIP (Routing Information Protocol) where all the devices
must see the data.
There are two types of broadcast transmission −
Directed Broadcast, and
Limited Broadcast
Directed Broadcast
Directed Broadcast transmits data from one source host to all the other hosts that
exist in some other network. It is used in two scenarios −
When the hosts are responsible for parsing data from broadcast packets.
When all the hosts require the same data.
Limited Broadcast
In Limited Broadcast, the data is transmitted from a single source host to all the
other hosts residing in the same network.
Multicast Transmission (One-to-Many)
When the data is transmitted from a single source host to a specific group of hosts
having the interest to receive the data, it is known
as multicast transmission. Multicast can be more efficient than unicast when
different groups of receivers need to see the same data.
Example − Multicast is the technique used in Internet streaming of video or audio
teleconference, sending an email to a particular group of people, etc.
Distance Vector Routing Algorithm
o The Distance vector algorithm is iterative, asynchronous and
distributed.
o Distributed: It is distributed in that each node receives information from
one or more of its directly attached neighbors, performs calculation and
then distributes the result back to its neighbors.
o Iterative: It is iterative in that its process continues until no more
information is available to be exchanged between neighbors.
o Asynchronous: It does not require that all of its nodes operate in the
lock step with each other.
o The Distance vector algorithm is a dynamic algorithm.
o It is mainly used in ARPANET, and RIP.
o Each router maintains a distance table known as Vector. Three Keys to
understand the working of Distance Vector Routing Algorithm:
o Knowledge about the whole network: Each router shares its knowledge
through the entire network. The Router sends its collected knowledge about
the network to its neighbors.
o Routing only to neighbors: The router sends its knowledge about the network
to only those routers which have direct links. The router sends whatever it has
about the network through the ports. The information is received by the router
and uses the information to update its own routing table.
o Information sharing at regular intervals: Within 30 seconds, the router
sends the information to the neighboring routers.
Distance Vector Routing Algorithm
Let dx(y) be the cost of the least-cost path from node x to node y. The least costs
are related by Bellman-Ford equation,
dx(y) = minv{c(x,v) + dv(y)}
Where the minv is the equation taken for all x neighbors. After traveling from x to v, if
we consider the least-cost path from v to y, the path cost will be c(x,v)+dv(y). The
least cost from x to y is the minimum of c(x,v)+dv(y) taken over all neighbors.
With the Distance Vector Routing algorithm, the node x contains the
following routing information:
o For each neighbor v, the cost c(x,v) is the path cost from x to directly
attached neighbor, v.
o The distance vector x, i.e., Dx = [ Dx(y) : y in N ], containing its cost to all
destinations, y, in N.
o The distance vector of each of its neighbors, i.e., Dv = [ Dv(y) : y in N ]
for each neighbor v of x.
Distance vector routing is an asynchronous algorithm in which node x sends the
copy of its distance vector to all its neighbors. When node x receives the new
distance vector from one of its neighboring vector, v, it saves the distance vector of
v and uses the Bellman-Ford equation to update its own distance vector. The
equation is given below:
dx(y) = minv{ c(x,v) + dv(y)} for each node y in N
The node x has updated its own distance vector table by using the above equation
and sends its updated table to all its neighbors so that they can update their own
distance vectors.
Algorithm
At each node x,
Initialization
for all destinations y in N:
Dx(y) = c(x,y) // If y is not a neighbor then c(x,y) = ∞ for each
neighbor w
Dw(y) = ? for all destination y in N. for
each neighbor w
send distance vector Dx = [ Dx(y) : y in N ] to w
loop
wait(until I receive any distance vector from some neighbor w) for each y in N:
Dx(y) = minv{c(x,v)+Dv(y)}
If Dx(y) is changed for any destination y
Send distance vector Dx = [ Dx(y) : y in N ] to all neighbors
forever
Note: In Distance vector algorithm, node x update its table when it either see any
cost change in one directly linked nodes or receives any vector update from some
neighbor.
Let's understand through an example:
Sharing Information
o In the above figure, each cloud represents the network, and the number
inside the cloud represents the network ID.
o All the LANs are connected by routers, and they are represented in boxes
labeled as A, B, C, D, E, F.
o Distance vector routing algorithm simplifies the routing process by assuming
the cost of every link is one unit. Therefore, the efficiency of transmission
can be measured by the number of links to reach the destination.
o In Distance vector routing, the cost is based on hop count.
In the above figure, we observe that the router sends the knowledge to the
immediate neighbors. The neighbors add this knowledge to their own knowledge and
sends the updated table to their own neighbors. In this way, routers get its own
information plus the new information about the neighbors.
Routing Table
Two process occurs:
o Creating the Table
o Updating the Table
Creating the Table
Initially, the routing table is created for each router that contains atleast three types of
information such as Network ID, the cost and the next hop.
o NET ID: The Network ID defines the final destination of the packet.
o Cost: The cost is the number of hops that packet must take to get there.
o Next hop: It is the router to which the packet must be delivered.
o In the above figure, the original routing tables are shown of all the routers. In
a routing table, the first column represents the network ID, the second
column represents the cost of the link, and the third column is empty.
o These routing tables are sent to all the neighbors.
For Example:
1. A sends its routing table to B, F & E.
2. B sends its routing table to A & C.
3. C sends its routing table to B & D.
4. D sends its routing table to E & C.
5. E sends its routing table to A & D.
6. F sends its routing table to A.
Updating the Table
o When A receives a routing table from B, then it uses its information to update
the table.
o The routing table of B shows how the packets can move to the networks 1 and
4.
o The B is a neighbor to the A router, the packets from A to B can reach
in one hop. So, 1 is added to all the costs given in the B's table and the
sum will be the cost to reach a particular network.
o After adjustment, A then combines this table with its own table to create a
combined table.
o The combined table may contain some duplicate data. In the above figure,
the combined table of router A contains the duplicate data, so it keeps only
those data which has the lowest cost. For example, A can send the data to
network 1 in two ways. The first, which uses no next router, so it costs one
hop. The second requires two hops (A to B, then B to Network 1). The first
option has the lowest cost, therefore it is kept and the second one is dropped.
o The process of creating the routing table continues for all routers. Every router
receives the information from the neighbors, and update the routing table.
Final routing tables of all the routers are given below: