To develop the Routing Projects used the simulation environments in NS3 (Inspired by TutorialsPoint). We are observing for routing projects equal to those on TutorialsPoint using NS3, We can track the organized method to execute a various routing protocols such as AODV, DSDV, OLSR, RIP, and Dijkstra’s Procedure.
Steps to Develop Tutorials point Routing Projects Using NS3
- Install NS3
Before you start, ensure that NS3 is installed:
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
- Create a Basic Network Topology
We define a wireless ad-hoc network where nodes communicate using different routing protocols.
Example: Create a Network with AODV, OLSR, and DSDV
#include “ns3/core-module.h”
#include “ns3/network-module.h”
#include “ns3/internet-module.h”
#include “ns3/mobility-module.h”
#include “ns3/yans-wifi-helper.h”
#include “ns3/aodv-helper.h”
#include “ns3/dsdv-helper.h”
#include “ns3/olsr-helper.h”
using namespace ns3;
NS_LOG_COMPONENT_DEFINE(“RoutingExample”);
int main(int argc, char *argv[])
{
uint32_t numNodes = 10;
double simulationTime = 10.0;
std::string routingProtocol = “AODV”; // Change to “OLSR” or “DSDV” for other protocols
CommandLine cmd;
cmd.AddValue(“numNodes”, “Number of nodes in the network”, numNodes);
cmd.AddValue(“routingProtocol”, “Routing Protocol (AODV, OLSR, DSDV)”, routingProtocol);
cmd.Parse(argc, argv);
NodeContainer nodes;
nodes.Create(numNodes);
// Set mobility model (random waypoint)
MobilityHelper mobility;
mobility.SetPositionAllocator(“ns3::GridPositionAllocator”,
“MinX”, DoubleValue(0.0),
“MinY”, DoubleValue(0.0),
“DeltaX”, DoubleValue(20.0),
“DeltaY”, DoubleValue(20.0),
“GridWidth”, UintegerValue(5),
“LayoutType”, StringValue(“RowFirst”));
mobility.SetMobilityModel(“ns3::ConstantPositionMobilityModel”);
mobility.Install(nodes);
// Set up WiFi
YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default();
YansWifiPhyHelper wifiPhy;
wifiPhy.SetChannel(wifiChannel.Create());
WifiHelper wifi;
wifi.SetStandard(WIFI_STANDARD_80211b);
WifiMacHelper wifiMac;
wifiMac.SetType(“ns3::AdhocWifiMac”);
NetDeviceContainer devices = wifi.Install(wifiPhy, wifiMac, nodes);
// Install Internet stack and routing protocol
InternetStackHelper internet;
if (routingProtocol == “AODV”)
{
AodvHelper aodv;
internet.SetRoutingHelper(aodv);
}
else if (routingProtocol == “OLSR”)
{
OlsrHelper olsr;
internet.SetRoutingHelper(olsr);
}
else if (routingProtocol == “DSDV”)
{
DsdvHelper dsdv;
internet.SetRoutingHelper(dsdv);
}
internet.Install(nodes);
// Assign IP Addresses
Ipv4AddressHelper address;
address.SetBase(“10.1.1.0”, “255.255.255.0”);
address.Assign(devices);
// Populate routing tables
Ipv4GlobalRoutingHelper::PopulateRoutingTables();
Simulator::Stop(Seconds(simulationTime));
Simulator::Run();
Simulator::Destroy();
return 0;
}
- Implement Dijkstra’s Algorithm for Shortest Path Routing
If you want least-cost routing, you can integrate Dijkstra’s Algorithm into NS3.
Dijkstra’s Algorithm Implementation
#include <iostream>
#include <vector>
#include <limits>
#define INF std::numeric_limits<int>::max()
void dijkstra(int graph[6][6], 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[6][6] = {
{0, 7, 9, 0, 0, 14},
{7, 0, 10, 15, 0, 0},
{9, 10, 0, 11, 0, 2},
{0, 15, 11, 0, 6, 0},
{0, 0, 0, 6, 0, 9},
{14, 0, 2, 0, 9, 0}};
int source = 0;
dijkstra(graph, source, 6);
return 0;
}
- Run the Simulation
Compile and execute the script:
./ns3 run routing-example
To specify a different routing protocol:
./ns3 run routing-example –routingProtocol=OLSR
- Performance Analysis
Use FlowMonitor to analyze Packet Delivery Ratio (PDR), 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(“routing_results.xml”, true, true);
Simulator::Destroy();
- Possible Extensions
Implement Bellman-Ford Algorithm for Distance Vector Routing
Add Mobility Models to Simulate VANET/WSN Scenarios
Use Energy-Aware Routing for IoT Networks
These examples can be established and mimicked using the foundational tutorials available on platforms such as TutorialsPoint, especially in their sections on NS3 basics, simulation setup, and performance evaluation. We can identify a variety of protocols explained on the website that can serve as a starting point for NS3 routing projects. Any uncertainties about the project will be addressed in a follow-up manual.