Unit IV Routing Algorithm
Unit IV Routing Algorithm
NETWORK LAYER
Routing is the process of establishing the routes that data packets must follow
to reach the destination. In this process, a routing table is created which
contains information regarding routes that data packets follow. Various routing
algorithms are used for the purpose of deciding which route an incoming data
packet needs to be transmitted on to reach the destination efficiently.
Classification of Routing Algorithms
1. Adaptive Algorithms
2. Non-Adaptive Algorithms
3. Hybrid Algorithms
Routing algorithms can be classified into various types such as distance vector,
link state, and hybrid routing algorithms. Each has its own strengths and
weaknesses depending on the network structure.
1. Adaptive Algorithms
These are the algorithms that change their routing decisions whenever network
topology or traffic load changes. The changes in routing decisions are reflected
in the topology as well as the traffic of the network. Also known as dynamic
routing, these make use of dynamic information such as current topology, load,
delay, etc. to select routes. Optimization parameters are distance, number of
hops, and estimated transit time.
Further, these are classified as follows:
Isolated: In this method each, node makes its routing decisions using the
information it has without seeking information from other nodes. The
sending nodes don’t have information about the status of a particular link.
The disadvantage is that packets may be sent through a congested network
which may result in delay. Examples: Hot potato routing, and backward
learning.
Centralized: In this method, a centralized node has entire information about
the network and makes all the routing decisions. The advantage of this is
only one node is required to keep the information of the entire network and
the disadvantage is that if the central node goes down the entire network is
done. The link state algorithm is referred to as a centralized algorithm since
it is aware of the cost of each link in the network.
Distributed: In this method, the node receives information from its
neighbors and then takes the decision about routing the packets. A
disadvantage is that the packet may be delayed if there is a change in
between intervals in which it receives information and sends packets. It is
also known as a decentralized algorithm as it computes the least-cost path
between source and destination.
2. Non-Adaptive Algorithms
These are the algorithms that do not change their routing decisions once they
have been selected. This is also known as static routing as a route to be taken is
computed in advance and downloaded to routers when a router is booted.
Further, these are classified as follows:
Flooding: This adapts the technique in which every incoming packet is sent
on every outgoing line except from which it arrived. One problem with this is
that packets may go in a loop and as a result of which a node may receive
duplicate packets. These problems can be overcome with the help of
sequence numbers, hop count, and spanning trees.
Random walk: In this method, packets are sent host by host or node by node
to one of its neighbors randomly. This is a highly robust method that is
usually implemented by sending packets onto the link which is least queued.
Random Walk
3. Hybrid Algorithms
As the name suggests, these algorithms are a combination of both adaptive and
non-adaptive algorithms. In this approach, the network is divided into several
regions, and each region uses a different algorithm.
Further, these are classified as follows:
Link-state: In this method, each router creates a detailed and complete map
of the network which is then shared with all other routers. This allows for
more accurate and efficient routing decisions to be made.
Distance vector: In this method, each router maintains a table that contains
information about the distance and direction to every other node in the
network. This table is then shared with other routers in the network. The
disadvantage of this method is that it may lead to routing loops.
Difference between Adaptive and Non-Adaptive Routing
Algorithms
The main difference between Adaptive and Non-Adaptive Algorithms is:
Adaptive Algorithms are the algorithms that change their routing decisions
whenever network topology or traffic load changes. It is called Dynamic
Routing. Adaptive Algorithm is used in a large amount of data, highly complex
network, and rerouting of data.
Non-Adaptive Algorithms are algorithms that do not change their routing
decisions once they have been selected. It is also called static Routing. Non-
Adaptive Algorithm is used in case of a small amount of data and a less complex
network.
For more differences, you can refer to Differences between Adaptive and Non-
Adaptive Routing Algorithms.
Non-Adaptive Routing
Adaptive Routing algorithm algorithm
The dynamic protocols are employed to The manual setup is performed for
update the routing table and determine the establishing an optimal path
best route between the source and between the source and destination
destination computers. computers.
Purposes-
Purposes-
It enables fine-grained control
Enhancement in network performance
over packet paths.
Prevents packet delivery failure
Suited for reliable networks with
Aid in controlling congestion
stable loads
May give the shortest path. Always gives the shortest path.
ROUING ALGORITHM
In computer networks, the shortest path algorithms aim to find the optimal
paths between the network nodes so that routing cost is minimized. They are
direct applications of the shortest path algorithms proposed in graph theory.
Explanation
Dijkstras Algorithm
Calculate the shortest distances iteratively. Repeat |V|- 1 times for each
node except s
The array dist[] contains the shortest path from s to every other node.
Dijkstras Algorithm
Initializations
An array of distances dist[] of size |V| (number of nodes), where dist[s]
= 0 and dist[u] = (infinite), where u represents a node in the graph
except s.
An array, Q, containing all nodes in the graph. When the algorithm runs
into completion, Q will become empty.
An empty set, S, to which the visited nodes will be added. When the
algorithm runs into completion, S will contain all the nodes in the graph.
o Remove from Q, the node, u having the smallest dist[u] and which
is not in S. In the first run, dist[s] is removed.
The array dist[] contains the shortest path from s to every other node.
Step-by-Step Implementation
1. Set dist=0 and all other distances as infinity.
2. Push the source node into the min heap as a pair <distance, node> →
i.e., <0, source>.
Bellman-Ford algorithm is
optimized for finding the
optimized for finding the
shortest path between a
shortest path between a
single source node and all
single source node and all
other nodes in a graph
other nodes in a graph
with non-negative edge
with negative edge
weights
Optimization weights.
the Bellman-Ford
Dijkstra’s algorithm uses a
algorithm relaxes all edges
greedy approach where it
in each iteration, updating
chooses the node with the
the distance of each node
smallest distance and
by considering all possible
updates its neighbors
Relaxation paths to that node
Input A cost adjacency matrix, adj[][], representing the paths between the
nodes in the network.
Output A shortest path cost matrix, cost[][], showing the shortest paths in
terms of cost between each pair of nodes in the graph.
Repeat for k = 1 to N
o Repeat for i = 1 to N
Repeat for j = 1 to N
The matrix cost[][] contains the shortest cost from each node, i , to
every other node, j.
What is an IP Address?
What is IPv4?
IPv4 Address Format is a 32-bit Address that comprises binary digits separated
by a dot (.).
Characteristics of IPv4
Drawbacks of IPv4
What is IPv6?
Another most common version of the Internet Protocol currently is IPv6. The
well-known IPv6 protocol is being used and deployed more often, especially in
mobile phone markets. IPv6 was designed by the Internet Engineering Task
Force (IETF) in December 1998 with the purpose of superseding IPv4 due to
the global exponentially growing internet of users.
IPv6 stands for Internet Protocol version 6. IPv6 is the new version of Internet
Protocol, which is way better than IPv4 in terms of complexity and
efficiency. IPv6 is written as a group of 8 hexadecimal numbers separated by
colon (:). It can be written as 128 bits of 0s and 1s.
IPv6 Address Format
IPv6 Address Format is a 128-bit IP Address, which is written in a group of 8
hexadecimal numbers separated by colon (:).
Characteristics of IPv6
IPv6 uses 128-bit addresses, offering a much larger address space than
IPv4’s 32-bit system.
IPv6 addresses use a combination of numbers and letters separated by
colons, allowing for more unique addresses.
The IPv6 header has fewer fields, making it more efficient for routers to
process.
IPv6 supports Unicast, Multicast, and Anycast, but no Broadcast, reducing
network traffic.
IPv6 allows flexible subnetting (VLSM) to divide networks based on specific
needs.
IPv6 uses Neighbor Discovery for MAC address resolution instead of ARP.
IPv6 uses advanced routing protocols like OSPFv3 and RIPng for better
address handling.
IPv6 devices can self-assign IP addresses using SLAAC, or use DHCPv6 for
more control.
IPv6 handles fragmentation at the sender side, not by routers, improving
speed.
IPv4 IPv6
IPv4 has a 32-bit address length IPv6 has a 128-bit address length
IPv4 can be converted to IPv6 Not all IPv6 can be converted to IPv4
Example of IPv6:
Example of IPv4: 66.94.29.13
2001:0000:3238:DFE1:0063:0000:0000:FEFB
Larger Address Space: IPv6 has a greater address space than IPv4, which is
required for expanding the IP Connected Devices. IPv6 has 128 bit IP
Address rather and IPv4 has a 32-bit Address.
Improved Security: IPv6 has some improved security which is built in with
it. IPv6 offers security like Data Authentication, Data Encryption, etc. Here,
an Internet Connection is more Secure.
Simplified Header Format: As compared to IPv4, IPv6 has a simpler and
more effective header Structure, which is more cost-effective and also
increases the speed of Internet Connection.
Prioritize: IPv6 contains stronger and more reliable support for QoS
features, which helps in increasing traffic over websites and increases audio
and video quality on pages.
Improved Support for Mobile Devices: IPv6 has increased and better support
for Mobile Devices. It helps in making quick connections over other Mobile
Devices and in a safer way than IPv4.
Why IPv4 is Still in Use?
1. Infrastructure Compatibility Many systems and devices are built for IPv4
and require significant updates to support IPv6, including routers, switches,
and computers.
2. Cost of Transition – Switching to IPv6 can be expensive and complex,
involving hardware updates, software upgrades, and training for personnel.
3. Lack of Immediate Need – Techniques like NAT (Network Address
Translation) help extend the life of IPv4 by allowing multiple devices to
share a single public IP address, reducing the urgency to switch to IPv6.
4. Coexistence Strategies – Technologies that allow IPv4 and IPv6 to run
simultaneously make it easier for organizations to adopt IPv6 gradually
while maintaining their existing IPv4 systems.
5. Slow Global Adoption – The adoption of IPv6 varies significantly around the
world, which necessitates the continued support of IPv4 for global
connectivity.
6. Lack of Visible Benefits – Many users and organizations don’t see immediate
improvements with IPv6 if they don’t face an IP address shortage, reducing
the incentive to upgrade.
Conclusion
The shift from IPv4 to IPv6 is more than just an expansion of address space; it
represents a necessary evolution in internet architecture to accommodate
future growth and innovation. Understanding these differences helps not only
in appreciating how the internet works but also in foreseeing how technology
will continue to evolve to meet the needs of an increasingly connected world.