How to Begin Implement an Ad Hoc Protocols in NS3
To execute ad hoc protocols in ns3 has requires configuring a wireless ad hoc network in which nodes dynamically interact devoid of a fixed infrastructure. NS3 has numerous inherent ad hoc routing protocols like AODV, DSDV, OLSR, and DSR for creating it to configure and examine its behavior.
Given below is a series of steps to execute and test ad hoc protocols in ns3:
Steps to Begin Implement Ad Hoc Protocols in NS3
- Understand Ad Hoc Protocols
- Key Features:
- Nodes dynamically determine and sustain the paths.
- It supports for mobility and dynamic topology changes.
- These protocols can be proactive such as OLSR, DSDV or reactive like AODV, DSR.
- Built-in Protocols in ns-3:
- AODV: Ad hoc On-Demand Distance Vector.
- DSDV: Destination-Sequenced Distance Vector.
- OLSR: Optimized Link State Routing.
- DSR: Dynamic Source Routing.
- Set Up ns3 Environment
- Install ns3:
git clone https://gitlab.com/nsnam/ns-3-dev.git
cd ns-3-dev
./build.py
- Confirm the installation:
./ns3 run hello-simulator
- Plan the Network Topology
- Components:
- Mobile nodes are interacting within an ad hoc network.
- Traffic generators such as UDP or TCP applications.
- Topology:
- Replicate the dynamic topology changes to leverage random mobility patterns.
- Write the Simulation Script
- Include Necessary Headers
#include “ns3/core-module.h”
#include “ns3/network-module.h”
#include “ns3/internet-module.h”
#include “ns3/mobility-module.h”
#include “ns3/wifi-module.h”
#include “ns3/aodv-helper.h” // Replace with the desired protocol helper
#include “ns3/applications-module.h”
- Define Nodes
ns3::NodeContainer nodes;
nodes.Create(10); // Create 10 mobile nodes
- Set Up Mobility
ns3::MobilityHelper mobility;
// Random waypoint mobility model
mobility.SetMobilityModel(“ns3::RandomWaypointMobilityModel”,
“Speed”, ns3::StringValue(“ns3::UniformRandomVariable[Min=5.0|Max=20.0]”),
“Pause”, ns3::StringValue(“ns3::ConstantRandomVariable[Constant=2.0]”),
“PositionAllocator”, ns3::StringValue(“ns3::RandomRectanglePositionAllocator”));
mobility.SetPositionAllocator(“ns3::RandomRectanglePositionAllocator”,
“X”, ns3::StringValue(“ns3::UniformRandomVariable[Min=0.0|Max=500.0]”),
“Y”, ns3::StringValue(“ns3::UniformRandomVariable[Min=0.0|Max=500.0]”));
mobility.Install(nodes);
- Set Up Wi-Fi Communication
ns3::WifiHelper wifi;
wifi.SetStandard(ns3::WIFI_PHY_STANDARD_80211g);
ns3::WifiMacHelper mac;
mac.SetType(“ns3::AdhocWifiMac”);
ns3::WifiPhyHelper phy = ns3::WifiPhyHelper::Default();
phy.SetChannel(ns3::YansWifiChannelHelper::Default().Create());
ns3::NetDeviceContainer devices = wifi.Install(phy, mac, nodes);
- Install the Ad Hoc Routing Protocol
Select the preferred ad hoc routing protocol such as AODV, DSDV, OLSR, or DSR and configure it:
- AODV Example:
ns3::AodvHelper aodv;
ns3::InternetStackHelper stack;
stack.SetRoutingHelper(aodv); // Use AODV as the routing protocol
stack.Install(nodes);
- Other Protocols:
- Substitute AodvHelper including:
- OlsrHelper for OLSR.
- DsdvHelper for DSDV.
- DsrHelper for DSR.
- Substitute AodvHelper including:
- Assign IP Addresses
ns3::Ipv4AddressHelper address;
address.SetBase(“10.1.1.0”, “255.255.255.0”);
ns3::Ipv4InterfaceContainer interfaces = address.Assign(devices);
- Generate Traffic
UDP Traffic
// UDP Echo server on node 0
ns3::UdpEchoServerHelper echoServer(9);
ns3::ApplicationContainer serverApp = echoServer.Install(nodes.Get(0));
serverApp.Start(ns3::Seconds(1.0));
serverApp.Stop(ns3::Seconds(20.0));
// UDP Echo client on node 9
ns3::UdpEchoClientHelper echoClient(interfaces.GetAddress(0), 9);
echoClient.SetAttribute(“MaxPackets”, ns3::UintegerValue(10));
echoClient.SetAttribute(“Interval”, ns3::TimeValue(ns3::Seconds(1.0)));
echoClient.SetAttribute(“PacketSize”, ns3::UintegerValue(512));
ns3::ApplicationContainer clientApp = echoClient.Install(nodes.Get(9));
clientApp.Start(ns3::Seconds(2.0));
clientApp.Stop(ns3::Seconds(20.0));
- Run the Simulation
ns3::Simulator::Run();
ns3::Simulator::Destroy();
- Analyze Results
Metrics:
- Packet Delivery Ratio (PDR):
- Estimate the rate of packets which are effectively distributed to entire packets are transmitted.
- End-to-End Delay:
- Compute the average duration attaining its destination for packets.
- Routing Overhead:
- During the simulation, count the volume of control packets which are replaced.
Tracing and Visualization:
- Allow .pcap tracing for packet inspection:
ns3::AsciiTraceHelper ascii;
phy.EnableAsciiAll(ascii.CreateFileStream(“ad-hoc.tr”));
phy.EnablePcapAll(“ad-hoc”);
- Make use of NetAnim for envision:
./waf –run “ad-hoc-simulation –vis”
- Iterate and Enhance
- Advanced Scenarios:
- Experiment with higher node mobility or maximized node density.
- Replicate the link or node failures for estimating the robustness of protocol.
- Traffic Patterns:
- Establish numerous sources and destinations or TCP-based traffic models.
- Comparison:
- We need to equate the performance of several ad hoc protocols in same network scenarios.
- Extending the Protocol
To change or prolong an existing protocol, we can:
- Position the execution within the src directory as src/aodv for AODV.
- Fine-tune files such as:
- aodv-routing-protocol.cc: Core routing logic.
- aodv-helper.cc: Helper for protocol configuration.
- Rebuild ns3:
./waf
We elaborated on the sequential method guiding the Ad Hoc Protocols that were implemented and examined using NS3 platform. Upon request, we are equipped to provide comprehensive insights and delve deeper into this topic.