How to Start Ad Hoc Protocols Projects Using NS3
To start ad hoc network routing protocols using NS3 this particularly matched for Mobile Ad Hoc Networks (MANETs). For numerous ad hoc routing protocols with AODV (Ad hoc On-demand Distance Vector), OLSR (Optimized Link State Routing), DSDV (Destination-Sequenced Distance Vector), and DSR (Dynamic Source Routing), NS3 environment offers executions. Below is a stepwise approach to start and simulate the ad hoc protocol projects in NS3.
Steps to Start Ad Hoc Protocols Projects in NS3
- Install NS3
We can adhere to these steps configuring it (assuming a Linux environment) if NS3 doesn’t install:
# Update system and install dependencies
sudo apt update
sudo apt install -y gcc g++ python3 python3-dev cmake libgsl-dev libsqlite3-dev
# Clone the NS-3 repository
git clone https://gitlab.com/nsnam/ns-3-dev.git ns-3
cd ns-3
# Configure and build NS-3
./ns3 configure –enable-examples –enable-tests
./ns3 build
- Create a New Script for Ad Hoc Protocol Simulation
In this script, we will set up nodes utilising available ad hoc routing protocols then configure an ad hoc WiFi network, and set mobility for the nodes. We can be selected the preferred ad hoc protocol such as AODV, OLSR, DSDV, or DSR by uncommenting the respective lines within the code.
- In the NS3’s scratch directory, make a new file like adhoc_protocol_simulation.cc.
- Following outline illustrates how to configure an ad hoc network including selectable routing protocols.
Basic Structure of adhoc_protocol_simulation.cc:
#include “ns3/core-module.h”
#include “ns3/network-module.h”
#include “ns3/internet-module.h”
#include “ns3/aodv-helper.h”
#include “ns3/olsr-helper.h”
#include “ns3/dsdv-helper.h”
#include “ns3/dsr-module.h”
#include “ns3/mobility-module.h”
#include “ns3/wifi-module.h”
#include “ns3/applications-module.h”
using namespace ns3;
NS_LOG_COMPONENT_DEFINE(“AdHocProtocolSimulation”);
int main(int argc, char *argv[]) {
// Enable logging
LogComponentEnable(“UdpEchoClientApplication”, LOG_LEVEL_INFO);
LogComponentEnable(“UdpEchoServerApplication”, LOG_LEVEL_INFO);
// Create nodes for the MANET
NodeContainer nodes;
nodes.Create(10); // Example with 10 nodes
// Set up mobility model for the nodes
MobilityHelper mobility;
mobility.SetPositionAllocator(“ns3::RandomRectanglePositionAllocator”,
“X”, StringValue(“ns3::UniformRandomVariable[Min=0.0|Max=100.0]”),
“Y”, StringValue(“ns3::UniformRandomVariable[Min=0.0|Max=100.0]”));
mobility.SetMobilityModel(“ns3::RandomWaypointMobilityModel”,
“Speed”, StringValue(“ns3::UniformRandomVariable[Min=1.0|Max=5.0]”),
“Pause”, StringValue(“ns3::ConstantRandomVariable[Constant=2.0]”));
mobility.Install(nodes);
// Configure WiFi for ad hoc network
WifiHelper wifi;
wifi.SetStandard(WIFI_STANDARD_80211b);
YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default();
YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default();
wifiPhy.SetChannel(wifiChannel.Create());
WifiMacHelper wifiMac;
wifiMac.SetType(“ns3::AdhocWifiMac”);
NetDeviceContainer devices = wifi.Install(wifiPhy, wifiMac, nodes);
// Install Internet stack and set up routing protocols
InternetStackHelper internet;
// Uncomment one of the following lines to select a routing protocol
AodvHelper aodv;
internet.SetRoutingHelper(aodv); // Use AODV as the routing protocol
// OlsrHelper olsr;
// internet.SetRoutingHelper(olsr); // Use OLSR as the routing protocol
// DsdvHelper dsdv;
// internet.SetRoutingHelper(dsdv); // Use DSDV as the routing protocol
// DsrMainHelper dsrMain;
// DsrHelper dsr;
// internet.Install(nodes);
// dsrMain.Install(dsr, nodes);
internet.Install(nodes);
// Assign IP addresses
Ipv4AddressHelper ipv4;
ipv4.SetBase(“10.1.1.0”, “255.255.255.0”);
Ipv4InterfaceContainer interfaces = ipv4.Assign(devices);
// Set up a UDP echo server on one node to test connectivity
UdpEchoServerHelper echoServer(9);
ApplicationContainer serverApps = echoServer.Install(nodes.Get(0));
serverApps.Start(Seconds(1.0));
serverApps.Stop(Seconds(10.0));
// Set up a UDP echo client on another node to communicate with the server
UdpEchoClientHelper echoClient(interfaces.GetAddress(0), 9);
echoClient.SetAttribute(“MaxPackets”, UintegerValue(3));
echoClient.SetAttribute(“Interval”, TimeValue(Seconds(1.0)));
echoClient.SetAttribute(“PacketSize”, UintegerValue(1024));
ApplicationContainer clientApps = echoClient.Install(nodes.Get(9));
clientApps.Start(Seconds(2.0));
clientApps.Stop(Seconds(10.0));
// Run the simulation
Simulator::Stop(Seconds(10.0));
Simulator::Run();
Simulator::Destroy();
return 0;
}
Explanation of the Code
- Node Creation: In the ad hoc network, 10 nodes are made to signify the devices.
- Mobility Model: We configure RandomWaypointMobilityModel for node movement that is general within MANET simulations.
- WiFi Setup: WiFi is set up within ad hoc mode to permit direct interaction among the nodes.
- Routing Protocols: We can select available ad hoc routing protocols by uncommenting the respective lines within the code:
- AODV: On-demand distance vector routing protocol.
- OLSR: Proactive, table-driven protocol based on link-state routing.
- DSDV: Proactive, distance vector protocol with sequence numbers.
- DSR: Source routing protocol using route discovery and maintenance.
- Application Setup: A UDP Echo server and client are set up to experiment the connectivity via chosen routing protocol.
- Build and Run the Simulation
- In the scratch directory, we can save adhoc_protocol_simulation.cc.
- Go to a terminal, pass through to NS3 directory, and then make the script:
./ns3 build
- Run the simulation:
./ns3 run scratch/adhoc_protocol_simulation
- Analyze the Results
We utilise the chosen ad hoc routing protocol, this configuration will be indicated the connectivity among nodes. Based on their requirements, protocol will be managed route discovery and data forwarding.
To monitor in-depth routing activities such as route requests, route replies, or routing table updates, allow to log for certain protocols by inserting below lines:
- AODV:
LogComponentEnable(“AodvRoutingProtocol”, LOG_LEVEL_ALL);
- OLSR:
LogComponentEnable(“OlsrRoutingProtocol”, LOG_LEVEL_ALL);
- DSDV:
LogComponentEnable(“DsdvRoutingProtocol”, LOG_LEVEL_ALL);
- DSR:
LogComponentEnable(“DsrRoutingProtocol”, LOG_LEVEL_ALL);
Experimentation Ideas
To extend Ad Hoc Protocols simulation:
- Change Node Density: We maximize or minimize the number of nodes and monitor how the protocol balances.
- Adjust Mobility: Test with diverse speeds and stop times using RandomWaypointMobilityModel to focus on how mobility impacts the protocol.
- Compare Protocol Performance: We need to execute numerous simulations including various protocols and then monitor performance parameters like packet delivery ratio, end-to-end delay, and routing overhead.
- Measure Network Performance: Gather performance information on packet delivery, delays, and throughput to utilize tools such as the FlowMonitor module within NS3.
Through the entire process, you can get the simulation process for Ad Hoc protocols projects that were simulated and executed in NS3 tool. We will be shared more innovative approach on this subject in another manual.
To achieve excellence in your projects, let our team take care of the details. Reach out to us for further guidance. We specialize in Ad Hoc Protocols Projects using the NS3 tool, providing scholars with customized and impeccable documentation. Our team is proficient in ad hoc routing protocols such as AODV (Ad hoc On-demand Distance Vector), OLSR (Optimized Link State Routing), DSDV (Destination-Sequenced Distance Vector), and DSR (Dynamic Source Routing).
We are committed to delivering the best results along with comprehensive explanations. Rest assured, our services are affordable, and we guarantee high-quality work completed on time. Trust our experts to get the job done efficiently.