To develop the Shortest Path Routing Projects utilize the NS3. The Shortest Path Routing in NS3 can be employed for used the different routing protocols like as AODV, OLSR, Dijkstra’s Procedure, and Bellman-Ford Procedure. Below is a structured approach to improving the Shortest Path Routing Projects using NS3:
Step-by-Step to Develop Shortest Path Routing Projects Using NS3
- Install NS3
Assure we have the NS3 installed on your system. If not, install it using the following commands:
sudo apt update
sudo apt install git g++ python3 cmake make
git clone
cd ns-3-dev
./ns3 configure –enable-examples –enable-tests
./ns3 build
- Set up the Network Topology
State the simple network topology by several nodes to replicate the Shortest Path Routing.
Example: Create a simple wired/wireless network
#include “ns3/core-module.h”
#include “ns3/network-module.h”
#include “ns3/internet-module.h”
#include “ns3/point-to-point-module.h”
#include “ns3/ipv4-global-routing-helper.h”
using namespace ns3;
int main()
{
NodeContainer nodes;
nodes.Create(4); // Create 4 nodes
PointToPointHelper pointToPoint;
pointToPoint.SetDeviceAttribute(“DataRate”, StringValue(“1Mbps”));
pointToPoint.SetChannelAttribute(“Delay”, StringValue(“10ms”));
NetDeviceContainer devices;
devices = pointToPoint.Install(nodes.Get(0), nodes.Get(1));
devices = pointToPoint.Install(nodes.Get(1), nodes.Get(2));
devices = pointToPoint.Install(nodes.Get(2), nodes.Get(3));
InternetStackHelper stack;
stack.Install(nodes);
Ipv4AddressHelper address;
address.SetBase(“10.1.1.0”, “255.255.255.0”);
Ipv4InterfaceContainer interfaces = address.Assign(devices);
Ipv4GlobalRoutingHelper::PopulateRoutingTables();
Simulator::Run();
Simulator::Destroy();
return 0;
}
- Implement a Shortest Path Algorithm
We can execute the Shortest Path Algorithm in Dijkstra’s Process or Bellman-Ford Procedure.
Dijkstra’s Algorithm Implementation in NS3
#include <iostream>
#include <vector>
#include <limits>
#define INF std::numeric_limits<int>::max()
void dijkstra(int graph[4][4], int src, int numNodes)
{
std::vector<int> dist(numNodes, INF);
std::vector<bool> visited(numNodes, false);
dist[src] = 0;
for (int i = 0; i < numNodes – 1; i++)
{
int min = INF, u;
for (int j = 0; j < numNodes; j++)
{
if (!visited[j] && dist[j] < min)
{
min = dist[j], u = j;
}
}
visited[u] = true;
for (int v = 0; v < numNodes; v++)
{
if (!visited[v] && graph[u][v] && dist[u] != INF && dist[u] + graph[u][v] < dist[v])
{
dist[v] = dist[u] + graph[u][v];
}
}
}
std::cout << “Node\tDistance from Source\n”;
for (int i = 0; i < numNodes; i++)
{
std::cout << i << “\t” << dist[i] << std::endl;
}
}
int main()
{
int graph[4][4] = {
{0, 10, 20, 0},
{10, 0, 5, 30},
{20, 5, 0, 15},
{0, 30, 15, 0}};
int source = 0;
dijkstra(graph, source, 4);
return 0;
}
- Use a Routing Protocol (AODV, OLSR, etc.)
We incorporate the Shortest Path Routing in NS3; use a protocol such as AODV or OLSR.
Permit for AODV Routing
#include “ns3/aodv-helper.h”
AodvHelper aodv;
internet.SetRoutingHelper(aodv);
stack.Install(nodes);
Allow the OLSR Routing
#include “ns3/olsr-helper.h”
OlsrHelper olsr;
internet.SetRoutingHelper(olsr);
stack.Install(nodes);
- Run the Simulation
Compile and implement process for your NS3 simulation script:
./ns3 run shortest-path-routing
- Analyze the Results
We can utilize the tool for FlowMonitor to calculate the performance of parameter metrices such as Packet Delivery Ratio, End-to-End Delay, and Throughput:
#include “ns3/flow-monitor-module.h”
FlowMonitorHelper flowmon;
Ptr<FlowMonitor> monitor = flowmon.InstallAll();
Simulator::Stop(Seconds(10.0));
Simulator::Run();
monitor->SerializeToXmlFile(“shortest_path.xml”, true, true);
Simulator::Destroy();
In the above following procedures is often support to simulate the Shortest Path Routing in ns3 that identify the shortest path among the nodes. We will provide answers to your queries in an additional project document