To implement a Mobile Ad hoc Network (MANET) for Internet of Things (IoT) in ns3, we need to follow several steps. First, we have to set-up a dynamic network in which communication happens between each other IoT devices in an ad hoc manner. Below given step will guide on implementing MANET IoT in ns3.
Step-by-step guide to set up a MANET IoT scenario in ns3:
Step 1: Install ns3
Make sure that ns3 is installed on the system.
Step 2: Set Up the Simulation Environment
Create a new simulation script or modify an existing one. This script will define the network topology, nodes, mobility models, and communication protocols.
Step 3: Define Network Topology
Create nodes and define the network topology, focusing on IoT devices with ad hoc communication capabilities. Here’s an example of setting up a basic MANET for IoT devices.
#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/olsr-helper.h”
#include “ns3/applications-module.h”
#include “ns3/flow-monitor-module.h”
using namespace ns3;
NS_LOG_COMPONENT_DEFINE (“ManetIotExample”);
int main (int argc, char *argv[])
{
// Enable logging
LogComponentEnable (“ManetIotExample”, LOG_LEVEL_INFO);
// Create nodes
NodeContainer iotNodes;
iotNodes.Create (25); // Example with 25 IoT devices
// Set up Wi-Fi
WifiHelper wifi;
wifi.SetStandard (WIFI_PHY_STANDARD_80211b);
YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default ();
YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default ();
wifiPhy.SetChannel (wifiChannel.Create ());
WifiMacHelper wifiMac;
wifiMac.SetType (“ns3::AdhocWifiMac”);
NetDeviceContainer devices;
devices = wifi.Install (wifiPhy, wifiMac, iotNodes);
// Install Internet stack
InternetStackHelper internet;
OlsrHelper olsr;
internet.SetRoutingHelper (olsr); // Enable OLSR routing protocol
internet.Install (iotNodes);
// Assign IP addresses
Ipv4AddressHelper address;
address.SetBase (“10.1.1.0”, “255.255.255.0”);
Ipv4InterfaceContainer interfaces = address.Assign (devices);
// Set up mobility model
MobilityHelper mobility;
mobility.SetPositionAllocator (“ns3::GridPositionAllocator”,
“MinX”, DoubleValue (0.0),
“MinY”, DoubleValue (0.0),
“DeltaX”, DoubleValue (10.0),
“DeltaY”, DoubleValue (10.0),
“GridWidth”, UintegerValue (5),
“LayoutType”, StringValue (“RowFirst”));
mobility.SetMobilityModel (“ns3::RandomWalk2dMobilityModel”,
“Bounds”, RectangleValue (Rectangle (0, 50, 0, 50)));
mobility.Install (iotNodes);
// Install and start applications on nodes
uint16_t port = 9;
UdpServerHelper server (port);
ApplicationContainer serverApp = server.Install (iotNodes.Get (0));
serverApp.Start (Seconds (1.0));
serverApp.Stop (Seconds (10.0));
UdpClientHelper client (interfaces.GetAddress (0), port);
client.SetAttribute (“MaxPackets”, UintegerValue (100));
client.SetAttribute (“Interval”, TimeValue (Seconds (1.0)));
client.SetAttribute (“PacketSize”, UintegerValue (1024));
ApplicationContainer clientApps;
for (uint32_t i = 1; i < iotNodes.GetN (); ++i)
{
clientApps.Add (client.Install (iotNodes.Get (i)));
}
clientApps.Start (Seconds (2.0));
clientApps.Stop (Seconds (10.0));
// Set up FlowMonitor
FlowMonitorHelper flowmon;
Ptr<FlowMonitor> monitor = flowmon.InstallAll ();
// Run the simulation
Simulator::Stop (Seconds (10.0));
Simulator::Run ();
// Print statistics
monitor->CheckForLostPackets ();
Ptr<Ipv4FlowClassifier> classifier = DynamicCast<Ipv4FlowClassifier> (flowmon.GetClassifier ());
std::map<FlowId, FlowMonitor::FlowStats> stats = monitor->GetFlowStats ();
for (std::map<FlowId, FlowMonitor::FlowStats>::const_iterator i = stats.begin (); i != stats.end (); ++i)
{
Ipv4FlowClassifier::FiveTuple t = classifier->FindFlow (i->first);
NS_LOG_UNCOND (“Flow ” << i->first << ” (” << t.sourceAddress << ” -> ” << t.destinationAddress << “)”);
NS_LOG_UNCOND (” Tx Packets: ” << i->second.txPackets);
NS_LOG_UNCOND (” Tx Bytes: ” << i->second.txBytes);
NS_LOG_UNCOND (” Rx Packets: ” << i->second.rxPackets);
NS_LOG_UNCOND (” Rx Bytes: ” << i->second.rxBytes);
NS_LOG_UNCOND (” Throughput: ” << i->second.rxBytes * 8.0 / (i->second.timeLastRxPacket.GetSeconds () – i->second.timeFirstTxPacket.GetSeconds ()) / 1024 / 1024 << ” Mbps”);
}
// Clean up
Simulator::Destroy ();
return 0;
}
Step 4: Set Up Mobility Models
In the example, the GridPositionAllocator is used to place nodes in a grid layout initially, and the RandomWalk2dMobilityModel is used for nodes to simulate random movement within a bounded area.
Step 5: Set Up Traffic Generation
We set up a UDP server on one IoT device and UDP clients on the other devices to generate traffic. The traffic configuration can be adjusted to simulate different types of communication.
Step 6: Run the Simulation
Compile and run your simulation script to see the effect of MANET IoT on network performance. The output will include statistics such as the number of packets transmitted and received, throughput, and any packet loss.
Over all, we all learnt about how to implement MANET IoT in ns3 by setting up dynamic network, mobility models, Traffic generation for running the simulation process.
Obtain optimal outcomes and concise conclusions regarding various project concepts and performance evaluations associated with MANET IoT using the ns3 tool. We provide a range of project ideas aligned with your vision, along with thorough execution plans. Our team specializes in implementing IoT devices in an ad hoc fashion.