To implement network node deployment in ns3, we need to create a network topology. In that topology the nodes has to be deployed in specific positions according to a deployment strategy. This type of network node deployment can be useful for simulating scenarios such as wireless sensor networks, cellular networks, or IoT environments.
Here the instruction provided below will guide on how to implement NND in ns3.
Step-by-step to implement network node deployment:
- Set Up ns-3 Environment
Make sure ns3 is installed on the system..
- Create a New Simulation Script
Create a new C++ script for the simulation. For this example, we will use C++.
- Include Necessary Headers
Include the necessary ns3 headers in the script.
#include “ns3/core-module.h”
#include “ns3/network-module.h”
#include “ns3/internet-module.h”
#include “ns3/point-to-point-module.h”
#include “ns3/mobility-module.h”
#include “ns3/applications-module.h”
4. Define the Network Topology
Set up the basic network topology, including nodes, devices, and links. In this example, we’ll set up a simple wireless network with nodes deployed in a grid pattern.
using namespace ns3;
NS_LOG_COMPONENT_DEFINE (“NodeDeploymentExample”);
int main (int argc, char *argv[]) {
CommandLine cmd;
cmd.Parse (argc, argv);
// Create nodes
NodeContainer nodes;
nodes.Create (25); // Create 25 nodes
// Set up Wi-Fi
YansWifiChannelHelper channel = YansWifiChannelHelper::Default ();
YansWifiPhyHelper phy = YansWifiPhyHelper::Default ();
phy.SetChannel (channel.Create ());
WifiHelper wifi;
wifi.SetStandard (WIFI_STANDARD_80211g);
WifiMacHelper mac;
Ssid ssid = Ssid (“ns3-wifi”);
mac.SetType (“ns3::AdhocWifiMac”, “Ssid”, SsidValue (ssid));
NetDeviceContainer devices = wifi.Install (phy, mac, nodes);
// Install the internet stack
InternetStackHelper stack;
stack.Install (nodes);
Ipv4AddressHelper address;
address.SetBase (“10.1.1.0”, “255.255.255.0”);
Ipv4InterfaceContainer interfaces = address.Assign (devices);
// Set mobility
MobilityHelper mobility;
mobility.SetPositionAllocator (“ns3::GridPositionAllocator”,
“MinX”, DoubleValue (0.0),
“MinY”, DoubleValue (0.0),
“DeltaX”, DoubleValue (50.0),
“DeltaY”, DoubleValue (50.0),
“GridWidth”, UintegerValue (5),
“LayoutType”, StringValue (“RowFirst”));
mobility.SetMobilityModel (“ns3::ConstantPositionMobilityModel”);
mobility.Install (nodes);
// Install applications
uint16_t port = 9;
OnOffHelper onoff (“ns3::UdpSocketFactory”, InetSocketAddress (interfaces.GetAddress (24), port));
onoff.SetAttribute(“OnTime”,StringValue(“ns3::ConstantRandomVariable[Constant=1]”));
onoff.SetAttribute(“OffTime”,StringValue(“ns3::ConstantRandomVariable[Constant=0]”));
onoff.SetAttribute (“DataRate”, DataRateValue (DataRate (“1Mbps”)));
onoff.SetAttribute (“PacketSize”, UintegerValue (1024));
ApplicationContainer apps = onoff.Install (nodes.Get (0));
apps.Start (Seconds (1.0));
apps.Stop (Seconds (10.0));
PacketSinkHelper sink (“ns3::UdpSocketFactory”, InetSocketAddress (Ipv4Address::GetAny (), port));
ApplicationContainer sinkApps = sink.Install (nodes.Get (24));
sinkApps.Start (Seconds (0.0));
sinkApps.Stop (Seconds (10.0));
// Enable pcap tracing
phy.EnablePcap (“node-deployment”, devices.Get (0));
// Run simulation
Simulator::Stop (Seconds (10.0));
Simulator::Run ();
Simulator::Destroy ();
return 0;
}
Explanation
- Network Topology: The script sets up a simple wireless network with 25 nodes deployed in a 5×5 grid pattern.
- Wi-Fi Setup: The Wi-Fi network uses the 802.11g standard, and the nodes are configured with ad-hoc MAC addresses.
- Internet Stack: The InternetStackHelper is used to install the IP stack on all nodes.
- Mobility: The nodes are given fixed positions using the GridPositionAllocator and ConstantPositionMobilityModel.
- Applications: To generate UDP traffic to the last node, an OnOff application is installed on the first node. A PacketSink application is installed on the last node to receive the traffic.
- PCAP Tracing: For analysis PCAP tracing is enabled to capture packets.
5. Build and Run the Script
Save the script and build it using the ns3 build system (waf).
./waf configure
./waf build
./waf –run node-deployment
Extending the Example
We can extend this example to include more complex scenarios, such as:
- Dynamic Mobility Models: To simulate node movement, use more advanced mobility models such as RandomWaypointMobilityModel or GaussMarkovMobilityModel.
- Routing Protocols: To handle multi-hop communication, we have to implement routing protocols like OLSR or AODV.
- Network Monitoring: Use the FlowMonitor module to monitor network performance metrics such as throughput, delay, and packet loss.
- Energy Models: To simulate battery consumption and energy-efficient communication protocols, that incorporates energy models.
An example of setting up a random waypoint mobility model has given below:
// Set random waypoint mobility
MobilityHelper mobility;
Ptr<UniformRandomVariable> x = CreateObject<UniformRandomVariable> ();
x->SetAttribute (“Min”, DoubleValue (0.0));
x->SetAttribute (“Max”, DoubleValue (500.0));
Ptr<UniformRandomVariable> y = CreateObject<UniformRandomVariable> ();
y->SetAttribute (“Min”, DoubleValue (0.0));
y->SetAttribute (“Max”, DoubleValue (500.0));
Ptr<UniformRandomVariable> pause = CreateObject<UniformRandomVariable> ();
pause->SetAttribute (“Min”, DoubleValue (0.0));
pause->SetAttribute (“Max”, DoubleValue (2.0));
mobility.SetMobilityModel (“ns3::RandomWaypointMobilityModel”,
“Speed”, StringValue (“ns3::ConstantRandomVariable[Constant=20.0]”),
“Pause”, PointerValue (pause),
“PositionAllocator”, StringValue (“ns3::RandomBoxPositionAllocator”),
“X”, PointerValue (x),
“Y”, PointerValue (y),
“Z”, DoubleValue (0.0));
mobility.Install (nodes);
This network node deployment has implemented on ns3 by using the deployment strategy for nodes to fit in a specific position and we can also extend this example by using dynamic mobility models, routing protocols, network monitoring, Energy models.
Share with ns3simulation.com all your research details we will provide good guidance on performance analysis of network Node Deployment in ns3 tool.