OSPF (Open Short Path First) Routing Protocol implemented using Dijkstra Algorithm

7 min readSep 26, 2021

Routing Information Protocol (RIP)

RIP stands for Routing Information Protocol. RIP is an intra-domain routing protocol used within an autonomous system. Here, intra-domain means routing the packets in a defined domain, for example, web browsing within an institutional area. To understand the RIP protocol, our main focus is to know the structure of the packet, how many fields it contains, and how these fields determine the routing table.

Before understanding the structure of the packet, we first look at the following points:

  • RIP is based on the distance vector-based strategy, so we consider the entire structure as a graph where nodes are the routers, and the links are the networks.
  • In a routing table, the first column is the destination, or we can say that it is a network address.
  • The cost metric is the number of hops to reach the destination. The number of hops available in a network would be the cost. The hop count is the number of networks required to reach the destination.
  • In RIP, infinity is defined as 16, which means that the RIP is useful for smaller networks or small autonomous systems. The maximum number of hops that RIP can contain is 15 hops, i.e., it should not have more than 15 hops as 16 is infinity.
  • The next column contains the address of the router to which the packet is to be sent to reach the destination.

RIP Message Format

Now, we look at the structure of the RIP message format. The message format is used to share information among different routers. The RIP contains the following fields in a message:

  • Command: It is an 8-bit field that is used for request or reply. The value of the request is 1, and the value of the reply is 2.
  • Version: Here, version means that which version of the protocol we are using. Suppose we are using the protocol of version1, then we put the 1 in this field.
  • Reserved: This is a reserved field, so it is filled with zeroes.
  • Family: It is a 16-bit field. As we are using the TCP/IP family, so we put 2 value in this field.
  • Network Address: It is defined as 14 bytes field. If we use the IPv4 version, then we use 4 bytes, and the other 10 bytes are all zeroes.
  • Distance: The distance field specifies the hop count, i.e., the number of hops used to reach the destination.

How does the RIP work?

If there are 8 routers in a network where Router 1 wants to send the data to Router 3. If the network is configured with RIP, it will choose the route which has the least number of hops. There are three routes in the above network, i.e., Route 1, Route 2, and Route 3. The Route 2 contains the least number of hops, i.e., 2 where Route 1 contains 3 hops, and Route 3 contains 4 hops, so RIP will choose Route 2.

Advantages of RIP:

The following are the advantages of a RIP protocol:

  • It is easy to configure
  • It has less complexity
  • The CPU utilization is less

Dijkstra’s Algorithm

Dijkstra’s algorithm allows us to find the shortest path between any two vertices of a graph.

It differs from the minimum spanning tree because the shortest distance between two vertices might not include all the vertices of the graph.

Basics of Dijkstra’s Algorithm

  • Dijkstra’s Algorithm basically starts at the node that you choose (the source node) and it analyzes the graph to find the shortest path between that node and all the other nodes in the graph.
  • The algorithm keeps track of the currently known shortest distance from each node to the source node and it updates these values if it finds a shorter path.
  • Once the algorithm has found the shortest path between the source node and another node, that node is marked as “visited” and added to the path.
  • The process continues until all the nodes in the graph have been added to the path. This way, we have a path that connects the source node to all other nodes following the shortest path possible to reach each node.

How Dijkstra’s Algorithm works

  • It starts at the node that you choose (the source node) and it analyzes the graph to find the shortest path between that node and all the other nodes in the graph.
  • The algorithm keeps track of the currently known shortest distance from each node to the source node and it updates these values if it finds a shorter path.
  • Once the algorithm has found the shortest path between the source node and another node, that node is marked as “visited” and added to the path.
  • Dijkstra’s Algorithm works on the basis that any sub path B -> D of the shortest path A -> D between vertices A and D is also the shortest path between vertices B and D.

Dijkstra used this property in the opposite direction i.e. we overestimate the distance of each vertex from the starting vertex. Then we visit each node and its neighbors to find the shortest sub path to those neighbors.

The algorithm uses a greedy approach in the sense that we find the next best solution hoping that the end result is the best solution for the whole problem.

Purpose and Use Cases

With Dijkstra’s Algorithm, you can find the shortest path between nodes in a graph. Particularly, you can find the shortest path from a node (called the “source node”) to all other nodes in the graph, producing a shortest-path tree.

This algorithm is used in GPS devices to find the shortest path between the current location and the destination. It has broad applications in industry, specially in domains that require modeling networks.

Complexity :

  • Time complexity: Θ(E+V log V) (V for vertices & E for edges)
  • Space complexity: Θ(V)
  • Time complexity(If priority queue is not used): Θ(E+V²)

OSPF Protocol:

The OSPF (Open Shortest Path First) protocol is one of a family of IP Routing protocols, and is an Interior Gateway Protocol (IGP) for the Internet, used to distribute IP routing information throughout a single Autonomous System (AS) in an IP network.

The OSPF protocol is a link-state routing protocol, which means that the routers exchange topology information with their nearest neighbors. The topology information is flooded throughout the Autonomous System, so that every router within the Autonomous System has a complete picture of the topology of the Autonomous System. This picture is then used to calculate end-to-end paths through the Autonomous System, normally using a variant of the Dijkstra algorithm. Therefore, in a link-state routing protocol, the next hop address to which data is forwarded is determined by choosing the best end-to-end path to the eventual destination.

The main advantage of a link state routing protocol like OSPF is that the complete knowledge of topology allows routers to calculate routes that satisfy particular criteria. This can be useful for traffic engineering purposes, where routes can be constrained to meet particular quality of service requirements. The main disadvantage of a link state routing protocol is that it does not scale well as more routers are added to the routing domain. Increasing the number of routers increases the size and frequency of the topology updates, and also the length of time it takes to calculate end-to-end routes. This lack of scalability means that a link state routing protocol is unsuitable for routing across the Internet at large, which is the reason why IGPs only route traffic within a single Autonomous System.

Each OSPF router distributes information about its local state (usable interfaces and reachable neighbors, and the cost of using each interface) to other routers using a Link State Advertisement (LSA) message. Each router uses the received messages to build up an identical database that describes the topology of the Autonomous System.

From this database, each router calculates its own routing table using a Shortest Path First (SPF) or Dijkstra algorithm. This routing table contains all the destinations the routing protocol knows about, associated with a next hop IP address and outgoing interface.

  • The protocol recalculates routes when network topology changes, using the Dijkstra algorithm, and minimises the routing protocol traffic that it generates.
  • It provides support for multiple paths of equal cost.
  • It provides a multi-level hierarchy (two-level for OSPF) called “area routing,” so that information about the topology within a defined area of the Autonomous System is hidden from routers outside this area. This enables an additional level of routing protection and a reduction in routing protocol traffic.
  • All protocol exchanges can be authenticated so that only trusted routers can join in the routing exchanges for the Autonomous System.

Report this

Published by

Anudeep N.

GET at National Payments Corporation of India | 5x RedHat Certified (RHCE & OpenShift (DO180,DO280 & DO425) | 3x Microsoft Certified | 1x AWS Certified(AWSCSA) | DevOps | Terraform | K8s | Ansible | Jenkins | DevSecOps

Published • 1mo

58 articlesFollow

𝑯𝒆𝒍𝒍𝒐 𝑪𝒐𝒏𝒏𝒆𝒄𝒕𝒊𝒐𝒏𝒔!!✨ Successfully completed hashtag#Arth-Task-41 Task Description 📄 📌 Write a blog describing how OSPF (Open Short Path First) Routing Protocol implemented using Dijkstra Algorithm behind the scene. I would like to Thanks our Mentor Mr. Vimal Daga sir !! hashtag#vimaldaga hashtag#righteducation hashtag#educationredefine hashtag#rightmentor hashtag#worldrecordholder hashtag#linuxworld hashtag#makingindiafutureready hashtag#righeducation

--

--

No responses yet