How to Start On Demand Protocol Projects Using NS3
To start on-demand (reactive) routing protocols in NS3 that are optimal for Mobile Ad Hoc Networks (MANETs) in which nodes travel often, and routes want to be actively launched. In NS3, two of the generally utilized on-demand routing protocols obtainable that are AODV (Ad hoc On-demand Distance Vector) and DSR (Dynamic Source Routing). These protocols determine routes only when need that minimizes control overhead, to create them appropriate for dynamic networks.
Below is a stepwise method to configuring and executing on-demand protocol projects in NS3.
Steps to Start on Demand Protocol Projects in NS3
- Install NS3
We can configure NS3 using below commands (assuming a Linux environment), if doesn’t install NS3 on the system.
# 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 On-Demand Protocol Simulation
- In the NS3’s scratch directory, make a new file like on_demand_protocol_simulation.cc.
- We can utilise the below instance outline that illustrates on how to an on-demand routing protocol simulation. In the script, we can choose among AODV and DSR by uncommenting the corresponding lines.
Basic Structure of on_demand_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/dsr-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(“OnDemandProtocolSimulation”);
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
// 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: We generate ten nodes, making the mobile ad hoc network.
- Mobility Model: We can use RandomWaypointMobilityModel to replicate the node movement and a general model for MANETs.
- WiFi Setup: In ad hoc mode, WiFi is set up to permit direct interaction among the nodes without a centralized access point.
- Routing Protocols: We can be chosen one of the two on-demand routing protocols:
- AODV (Ad hoc On-Demand Distance Vector): It is a reactive protocol, which launches routes only when required.
- DSR (Dynamic Source Routing): This is another reactive protocol that utilises source routing and sustains route caches.
- UDP Echo Applications:
- A UDP Echo Server is configured at node 0 to perform like a sink.
- A UDP Echo Client transmits packets on node 9 to the server, analysing connectivity via on-demand routing protocol.
- Build and Run the Simulation
- In the NS3’s scratch directory, we can save on_demand_protocol_simulation.cc.
- Go to a terminal, pass through to the NS3 directory, and then make the script:
./ns3 build
- We execute the simulation including AODV or DSR by uncommenting the following lines:
./ns3 run scratch/on_demand_protocol_simulation
- Analyze the Results
This configuration will indicate the connectivity to utilize the chosen on-demand routing protocol among nodes. Depends on the behaviour of protocol, route discovery and packet forwarding will be occurred.
We want to observe in-depth records of the routing protocol activity, for AODV or DSR we can allow logging:
- AODV:
LogComponentEnable(“AodvRoutingProtocol”, LOG_LEVEL_ALL);
- DSR:
LogComponentEnable(“DsrRoutingProtocol”, LOG_LEVEL_ALL);
These logs will be indicated data regarding route requests, route replies, and route maintenance that is support to monitor how routes are actively launched and sustained.
Experimentation Ideas
To discover more advanced on-demand protocols, we can deliberate the following tests:
- Increase Network Size: Append additional nodes and then monitor how the protocol balances with network size.
- Change Mobility Patterns: Test with diverse speeds and stop times, learning the effect of mobility on protocol performance.
- Compare AODV and DSR: We can execute several replications including each protocol and also equate parameters such as route discovery time, packet delivery ratio, and control overhead.
- Add Traffic Load: Maximize the traffic rate among the nodes, observing how on-demand protocols manage the higher loads.
- Analyze Performance Metrics: Monitor packet delivery ratio, end-to-end delay, routing overhead, and packet loss using the FlowMonitor module.
Above guide effectively expounded the comprehensive method to start and simulate the On Demand Protocol Projects with the help of NS3 tool. More innovative approach will be presented later.
Rely on us to improve the performance of your project. You can be confident that our pricing is competitive, and our experts consistently deliver reliable, high-quality work within the agreed timelines. For additional support, please contact phdprojects.org. This platform offers innovative topics and project ideas in On Demand Protocol Projects Using NS3, providing customized and superior simulations for researchers. Our experienced team specializes in AODV (Ad hoc On-demand Distance Vector) and DSR (Dynamic Source Routing), ensuring you receive comprehensive explanations from our developers. To achieve outstanding results in your projects, allow our team to address your requirements.