How to Begin Implementing an Ad Hoc Networks in NS3
To begin executing an Ad Hoc Network project in NS3, that needs to replicate a wireless network in which nodes are directly interact devoid of depending on a central infrastructure like routers or base stations. Here’s a comprehensive method to get started:
Steps to Begin Implementing an Ad Hoc Networks Projects in NS3
- Understand Ad Hoc Networks
Ad Hoc Networks are typified by:
- Decentralization: It has no fixed infrastructure; nodes are performs like routers.
- Dynamic Topology: Nodes could dynamically connect, exit, or transfer.
- Protocols: Routing protocols like AODV, OLSR, or DSDV are utilized.
- Define Project Objectives
Focus on the project’s goals of Ad Hoc Network:
- Replicate the basic interaction among nodes.
- Focus on performance parameters such as throughput, delay, and packet delivery ratio.
- Execute and measure the routing protocols in terms of AODV, OLSR, or DSDV.
- Examine impact on mobility network performance.
- Install and Set Up NS3
- We should set up NS3 environment on the system.
- Learn about the Ad Hoc routing components in NS3:
- DSDV (Destination-Sequenced Distance Vector): Table-driven routing.
- AODV (Ad hoc On-Demand Distance Vector): Reactive routing.
- OLSR (Optimized Link State Routing): Proactive routing.
- Design the Ad Hoc Network
Key Components:
- Nodes: It denotes mobile devices within the network.
- Routing Protocol: Make use of NS3 Ad Hoc routing component.
- Mobility Model: Replicate the node movement.
- Traffic Patterns: Describe interaction among the nodes.
- Implement the Simulation
Step A: Create Ad Hoc Nodes
Describe the amount of Ad Hoc nodes.
NodeContainer adHocNodes;
adHocNodes.Create(10); // 10 Ad Hoc nodes
Step B: Install the Internet Stack with Routing
Allow Ad Hoc routing protocols such as AODV, OLSR, or DSDV.
InternetStackHelper internet;
AodvHelper aodv;
internet.SetRoutingHelper(aodv); // Set AODV as the routing protocol
internet.Install(adHocNodes);
Step C: Configure Wireless Devices
Configure WiFi for wireless interaction.
WifiHelper wifi;
wifi.SetStandard(WIFI_STANDARD_80211g);
YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default();
YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default();
wifiPhy.SetChannel(wifiChannel.Create());
WifiMacHelper wifiMac;
wifiMac.SetType(“ns3::AdhocWifiMac”);
NetDeviceContainer devices = wifi.Install(wifiPhy, wifiMac, adHocNodes);
Step D: Assign IP Addresses
Allocate inimitable IP addresses to the nodes.
Ipv4AddressHelper ipv4;
ipv4.SetBase(“10.1.1.0”, “255.255.255.0”);
Ipv4InterfaceContainer interfaces = ipv4.Assign(devices);
Step E: Define Node Mobility
Mimic node mobility to leverage a movement pattern.
MobilityHelper mobility;
mobility.SetMobilityModel(“ns3::RandomWaypointMobilityModel”,
“Speed”, StringValue(“ns3::UniformRandomVariable[Min=1.0|Max=5.0]”),
“Pause”, StringValue(“ns3::ConstantRandomVariable[Constant=2.0]”),
“PositionAllocator”, StringValue(“ns3::RandomBoxPositionAllocator”));
mobility.Install(adHocNodes);
- Add Traffic Applications
- Source Application (On-Off Traffic):
- Replicate the interaction among nodes.
OnOffHelper onOff(“ns3::UdpSocketFactory”, InetSocketAddress(interfaces.GetAddress(1), 9));
onOff.SetAttribute(“DataRate”, StringValue(“2Mbps”));
onOff.SetAttribute(“PacketSize”, UintegerValue(1024));
ApplicationContainer sourceApp = onOff.Install(adHocNodes.Get(0)); // Node 0 is the source
sourceApp.Start(Seconds(1.0));
sourceApp.Stop(Seconds(10.0));
- Sink Application:
- We can set up a PacketSink on the end node for receiving traffic.
PacketSinkHelper packetSink(“ns3::UdpSocketFactory”, InetSocketAddress(Ipv4Address::GetAny(), 9));
ApplicationContainer sinkApp = packetSink.Install(adHocNodes.Get(1)); // Node 1 is the sink
sinkApp.Start(Seconds(1.0));
sinkApp.Stop(Seconds(10.0));
- Configure Simulation Parameters
Configure simulation time and then run it.
Simulator::Stop(Seconds(15.0));
Simulator::Run();
Simulator::Destroy();
- Evaluate Performance
- Metrics:
- Estimate the performance of throughput, delay, packet delivery ratio, and energy utilization.
- Visualization:
- For real-time visualization, we need to leverage NetAnim.
- Transfer outcomes to external tools such as Python or MATLAB toolsfor analysis.
- Advanced Features
- Multi-Hop Communication:
- Maximize the distance among the nodes to apply multi-hop routing.
- Performance Analysis:
- Equate the various routing protocols such as AODV vs. OLSR.
- Energy Models:
- Mimic energy utilization of nodes with the support of EnergyModel.
- Mobility Patterns:
- Test with various mobility patters such as Gauss-Markov or Random Walk.
Sample Complete Code Framework
#include “ns3/core-module.h”
#include “ns3/network-module.h”
#include “ns3/internet-module.h”
#include “ns3/wifi-module.h”
#include “ns3/mobility-module.h”
#include “ns3/applications-module.h”
using namespace ns3;
int main() {
// Create Ad Hoc Nodes
NodeContainer adHocNodes;
adHocNodes.Create(10);
// Install Internet Stack with AODV Routing
InternetStackHelper internet;
AodvHelper aodv;
internet.SetRoutingHelper(aodv);
internet.Install(adHocNodes);
// Configure WiFi Devices
WifiHelper wifi;
wifi.SetStandard(WIFI_STANDARD_80211g);
YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default();
YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default();
wifiPhy.SetChannel(wifiChannel.Create());
WifiMacHelper wifiMac;
wifiMac.SetType(“ns3::AdhocWifiMac”);
NetDeviceContainer devices = wifi.Install(wifiPhy, wifiMac, adHocNodes);
// Assign IP Addresses
Ipv4AddressHelper ipv4;
ipv4.SetBase(“10.1.1.0”, “255.255.255.0”);
Ipv4InterfaceContainer interfaces = ipv4.Assign(devices);
// Configure Mobility
MobilityHelper mobility;
mobility.SetMobilityModel(“ns3::RandomWaypointMobilityModel”,
“Speed”, StringValue(“ns3::UniformRandomVariable[Min=1.0|Max=5.0]”),
“Pause”, StringValue(“ns3::ConstantRandomVariable[Constant=2.0]”),
“PositionAllocator”, StringValue(“ns3::RandomBoxPositionAllocator”));
mobility.Install(adHocNodes);
// Install Traffic Applications
OnOffHelper onOff(“ns3::UdpSocketFactory”, InetSocketAddress(interfaces.GetAddress(1), 9));
onOff.SetAttribute(“DataRate”, StringValue(“2Mbps”));
onOff.SetAttribute(“PacketSize”, UintegerValue(1024));
ApplicationContainer sourceApp = onOff.Install(adHocNodes.Get(0));
sourceApp.Start(Seconds(1.0));
sourceApp.Stop(Seconds(10.0));
PacketSinkHelper packetSink(“ns3::UdpSocketFactory”, InetSocketAddress(Ipv4Address::GetAny(), 9));
ApplicationContainer sinkApp = packetSink.Install(adHocNodes.Get(1));
sinkApp.Start(Seconds(1.0));
sinkApp.Stop(Seconds(10.0));
// Run Simulation
Simulator::Stop(Seconds(15.0));
Simulator::Run();
Simulator::Destroy();
return 0;
}
This step-by-step approach ensures a solid foundation for implementing and analysing the Adhoc Networks Projects using NS3 environment. Start with a basic setup, and gradually add estimation and advanced features as your project evolves. More details will be offered on this subject in upcoming manual.
Click Here to watch our latest output video using NS3 simulator
Click Here to watch our latest projects screenshots using NS3 simulator