How to Start Dijkstra’s Link State Projects Using NS3

To start the Dijkstra’s Link-State Routing using NS3, we adhere to these instructions:

Steps to Start Dijkstra’s Link-State Routing in NS3

  1. Install NS3

Make NS3 is installed on the machine. If doesn’t install NS3 then we can configure it using the following commands:

sudo apt update

sudo apt install g++ python3 git cmake

git clone https://gitlab.com/nsnam/ns-3-dev.git

cd ns-3-dev

./waf configure

./waf build

  1. Understand Dijkstra’s Algorithm and Link-State Routing
  • Dijkstra’s Algorithm:
    • It helps to determine the shortest paths from a source node to every other node within a graph.
    • It is generally used in link-state routing protocols such as OSPF.
  • Link-State Routing:
    • Each node collects data regarding their neighbors.
    • Nodes forward this information to create a global network topology.
    • Compute the shortest path using Dijkstra’s algorithm.
  1. Extend NS3 with Custom Routing Protocol

NS3 doesn’t support Dijkstra’s algorithm pre-implemented. We require making a custom routing protocol by prolonging the Ipv4RoutingProtocol class.

Step-by-Step Implementation

(a) Create a Custom Routing Protocol

Make a new folder like src/custom-routing, and then insert the execution.

  1. Header File (DijkstraRoutingProtocol.h):

#ifndef DIJKSTRA_ROUTING_PROTOCOL_H

#define DIJKSTRA_ROUTING_PROTOCOL_H

#include “ns3/ipv4-routing-protocol.h”

#include “ns3/node-container.h”

#include “ns3/nstime.h”

#include <map>

#include <vector>

namespace ns3 {

class DijkstraRoutingProtocol : public Ipv4RoutingProtocol {

public:

static TypeId GetTypeId();

DijkstraRoutingProtocol();

virtual ~DijkstraRoutingProtocol();

void ComputeShortestPath();

// Overriding methods

Ptr<Ipv4Route> RouteOutput(Ptr<Packet> packet, const Ipv4Header &header,

Ptr<NetDevice> oif, Socket::SocketErrno &sockerr) override;

private:

void InitializeAdjacencyMatrix();

void LinkStateUpdate();

std::map<uint32_t, std::vector<uint32_t>> adjacencyMatrix;

};

} // namespace ns3

#endif

  1. Implementation File (DijkstraRoutingProtocol.cc):

#include “DijkstraRoutingProtocol.h”

#include “ns3/log.h”

#include <queue>

#include <limits>

namespace ns3 {

NS_LOG_COMPONENT_DEFINE(“DijkstraRoutingProtocol”);

NS_OBJECT_ENSURE_REGISTERED(DijkstraRoutingProtocol);

TypeId DijkstraRoutingProtocol::GetTypeId() {

static TypeId tid = TypeId(“ns3::DijkstraRoutingProtocol”)

.SetParent<Ipv4RoutingProtocol>()

.SetGroupName(“Internet”)

.AddConstructor<DijkstraRoutingProtocol>();

return tid;

}

DijkstraRoutingProtocol::DijkstraRoutingProtocol() {}

DijkstraRoutingProtocol::~DijkstraRoutingProtocol() {}

void DijkstraRoutingProtocol::ComputeShortestPath() {

NS_LOG_INFO(“Computing shortest paths using Dijkstra’s Algorithm”);

uint32_t numNodes = adjacencyMatrix.size();

std::vector<uint32_t> distance(numNodes, std::numeric_limits<uint32_t>::max());

std::vector<bool> visited(numNodes, false);

distance[0] = 0; // Assuming node 0 is the source

for (uint32_t i = 0; i < numNodes; ++i) {

// Find the node with the smallest distance

uint32_t minDistance = std::numeric_limits<uint32_t>::max();

uint32_t minNode = 0;

for (uint32_t j = 0; j < numNodes; ++j) {

if (!visited[j] && distance[j] < minDistance) {

minDistance = distance[j];

minNode = j;

}

}

visited[minNode] = true;

// Update distances of neighboring nodes

for (uint32_t neighbor = 0; neighbor < numNodes; ++neighbor) {

if (adjacencyMatrix[minNode][neighbor] > 0 && !visited[neighbor]) {

uint32_t newDistance = distance[minNode] + adjacencyMatrix[minNode][neighbor];

if (newDistance < distance[neighbor]) {

distance[neighbor] = newDistance;

}

}

}

}

NS_LOG_INFO(“Shortest paths computed”);

}

void DijkstraRoutingProtocol::InitializeAdjacencyMatrix() {

// Initialize adjacency matrix with link weights

adjacencyMatrix[0] = {0, 1, 4, 0};

adjacencyMatrix[1] = {1, 0, 2, 6};

adjacencyMatrix[2] = {4, 2, 0, 3};

adjacencyMatrix[3] = {0, 6, 3, 0};

}

} // namespace ns3

(b) Integrate the Protocol into a Simulation

Following is how to configure a simple simulation to utilize custom routing protocol.

#include “ns3/core-module.h”

#include “ns3/network-module.h”

#include “ns3/internet-module.h”

#include “DijkstraRoutingProtocol.h”

using namespace ns3;

int main() {

NodeContainer nodes;

nodes.Create(4);

PointToPointHelper pointToPoint;

pointToPoint.SetDeviceAttribute(“DataRate”, StringValue(“5Mbps”));

pointToPoint.SetChannelAttribute(“Delay”, StringValue(“2ms”));

NetDeviceContainer devices1 = pointToPoint.Install(nodes.Get(0), nodes.Get(1));

NetDeviceContainer devices2 = pointToPoint.Install(nodes.Get(1), nodes.Get(2));

NetDeviceContainer devices3 = pointToPoint.Install(nodes.Get(2), nodes.Get(3));

InternetStackHelper stack;

stack.Install(nodes);

// Assign IP addresses

Ipv4AddressHelper address;

address.SetBase(“10.0.0.0”, “255.255.255.0”);

address.Assign(devices1);

address.Assign(devices2);

address.Assign(devices3);

// Set custom routing protocol

Ptr<DijkstraRoutingProtocol> dijkstraRouting = CreateObject<DijkstraRoutingProtocol>();

nodes.Get(0)->GetObject<Ipv4>()->SetRoutingProtocol(dijkstraRouting);

Simulator::Run();

Simulator::Destroy();

return 0;

}

  1. Testing and Debugging
  • Allow logging to observe the routing decisions:

NS_LOG=”DijkstraRoutingProtocol” ./waf –run dijkstra-simulation

  1. Visualizing Results
  • We want to examine the performance parameters like:
    • Path taken by packets.
    • Delay, throughput, and efficiency.
  • Envision the data with Python or MATLAB using Wireshark.

Above guide demonstrated the simple execution steps with necessary sample snippets for you to initiate and simulate the Dijkstra’s Link Start Projects with the help of NS3 environment. Further details will be added later as required.

We focus on performance metrics that match your needs. To work on Dijkstra’s Link State Projects using NS3, you need specific skills. Experts at phdprojects.org will provide you with valuable ideas and well-aligned topics that engage readers. Contact us for further guidance.