Ns3 Projects for B.E/B.Tech M.E/M.Tech PhD Scholars.  Phone-Number:9790238391   E-mail: ns3simulation@gmail.com

How to Implement mesh protocols in ns3

To implement mesh protocol in ns3, we need to create a set-up of mesh network that configures mesh nodes, and which utilizes an existing mesh protocol such as HWMP (Hybrid Wireless Mesh Protocol).

The implementation process is simple because, ns3 has a built-in support for mesh networking. Here are the steps to implement mesh protocol in ns3.

Steps to implement Mesh protocol in ns3

  1. Set up your environment

Make sure that ns3 is installed in the computer. If not, install it from the official ns3 website.

 

  1. Create a new ns3 script

On your ns3 installation, create a new simulation script in the scratch directory.

 

  1. Implement the Mesh network

Below is the example script for setting up a Mesh network using HWMP in ns3.

#include “ns3/core-module.h”

#include “ns3/network-module.h”

#include “ns3/internet-module.h”

#include “ns3/mesh-module.h”

#include “ns3/mobility-module.h”

#include “ns3/applications-module.h”

using namespace ns3;

int main (int argc, char *argv[])

{

CommandLine cmd;

cmd.Parse (argc, argv);

// Create nodes

NodeContainer meshNodes;

meshNodes.Create (6);

// Set up mesh helper

MeshHelper meshHelper = MeshHelper::Default ();

meshHelper.SetStackInstaller (“ns3::Dot11sStack”);

meshHelper.SetSpreadInterfaceChannels (MeshHelper::SPREAD_CHANNELS);

meshHelper.SetMacType (“RandomStart”, TimeValue (Seconds (0.1)));

meshHelper.SetNumberOfInterfaces (1);

// Install mesh devices on nodes

NetDeviceContainer meshDevices = meshHelper.Install (WifiPhyHelper::Default (), meshNodes);

// Set up mobility model

MobilityHelper mobility;

mobility.SetPositionAllocator (“ns3::GridPositionAllocator”,

“MinX”, DoubleValue (0.0),

“MinY”, DoubleValue (0.0),

“DeltaX”, DoubleValue (50.0),

“DeltaY”, DoubleValue (50.0),

“GridWidth”, UintegerValue (3),

“LayoutType”, StringValue (“RowFirst”));

mobility.SetMobilityModel (“ns3::RandomWalk2dMobilityModel”,

“Bounds”, RectangleValue (Rectangle (-100, 100, -100, 100)));

mobility.Install (meshNodes);

// Install the internet stack on nodes

InternetStackHelper stack;

stack.Install (meshNodes);

// Assign IP addresses to the devices

Ipv4AddressHelper address;

address.SetBase (“10.1.1.0”, “255.255.255.0”);

Ipv4InterfaceContainer interfaces = address.Assign (meshDevices);

// Set up applications (e.g., a UDP echo server and client)

UdpEchoServerHelper echoServer (9);

ApplicationContainer serverApps = echoServer.Install (meshNodes.Get (5));

serverApps.Start (Seconds (1.0));

serverApps.Stop (Seconds (10.0));

UdpEchoClientHelper echoClient (interfaces.GetAddress (5), 9);

echoClient.SetAttribute (“MaxPackets”, UintegerValue (5));

echoClient.SetAttribute (“Interval”, TimeValue (Seconds (1.0)));

echoClient.SetAttribute (“PacketSize”, UintegerValue (1024));

ApplicationContainer clientApps = echoClient.Install (meshNodes.Get (0));

clientApps.Start (Seconds (2.0));

clientApps.Stop (Seconds (10.0));

// Enable tracing

AsciiTraceHelper ascii;

meshHelper.EnableAsciiAll (ascii.CreateFileStream (“mesh-simulation.tr”));

meshHelper.EnablePcapAll (“mesh-simulation”);

// Run the simulation

Simulator::Run ();

Simulator::Destroy ();

return 0;

}

Explanation

  • Node creation :

For the Mesh, create six nodes.

  • Mesh helper set up :

using the MeshHelper class, configure the Mesh network. Sets the mesh protocol stack to Dot11sStack, spreads channels, and sets MAC type with a random start.

  • Device installation :

On the nodes, install Mesh devices.

  • Mobility model setup :

Place the nodes in a grid and allow random movement within specified bounds for configuring the mobility model.

  • Internet stack installation :

On the mesh nodes, install the internet stack.

  • IP address assignment :

Assigns IP addresses to the Mesh devices.

  • Application setup :

On one node, set up a UDP echo server and on another node, setup a UDP echo client to test connectivity.

  • Tracing :

To capture packet information, enable ASCII and pcap tracing for analysis.

 

  • Simulation execution :

Run the simulation.

  1. Build and run the simulation

Build and run your script after writing.

./waf build

./waf –run scratch/mesh-simulation

  1. Analyze the results

You can analyze the results after running the simulation, by generating trace files (mesh-simulation.tr and mesh-simulation-0-0.pcap).

 

Example script for Mesh protocol

Below is the example script for your reference:

#include “ns3/core-module.h”

#include “ns3/network-module.h”

#include “ns3/internet-module.h”

#include “ns3/mesh-module.h”

#include “ns3/mobility-module.h”

#include “ns3/applications-module.h”

using namespace ns3;

int main (int argc, char *argv[])

{

CommandLine cmd;

cmd.Parse (argc, argv);

// Create nodes

NodeContainer meshNodes;

meshNodes.Create (6);

// Set up mesh helper

MeshHelper meshHelper = MeshHelper::Default ();

meshHelper.SetStackInstaller (“ns3::Dot11sStack”);

meshHelper.SetSpreadInterfaceChannels (MeshHelper::SPREAD_CHANNELS);

meshHelper.SetMacType (“RandomStart”, TimeValue (Seconds (0.1)));

meshHelper.SetNumberOfInterfaces (1);

// Install mesh devices on nodes

NetDeviceContainer meshDevices = meshHelper.Install (WifiPhyHelper::Default (), meshNodes);

// Set up mobility model

MobilityHelper mobility;

mobility.SetPositionAllocator (“ns3::GridPositionAllocator”,

“MinX”, DoubleValue (0.0),

“MinY”, DoubleValue (0.0),

“DeltaX”, DoubleValue (50.0),

“DeltaY”, DoubleValue (50.0),

“GridWidth”, UintegerValue (3),

“LayoutType”, StringValue (“RowFirst”));

mobility.SetMobilityModel (“ns3::RandomWalk2dMobilityModel”,

“Bounds”, RectangleValue (Rectangle (-100, 100, -100, 100)));

mobility.Install (meshNodes);

// Install the internet stack on nodes

InternetStackHelper stack;

stack.Install (meshNodes);

// Assign IP addresses to the devices

Ipv4AddressHelper address;

address.SetBase (“10.1.1.0”, “255.255.255.0”);

Ipv4InterfaceContainer interfaces = address.Assign (meshDevices);

// Set up applications (e.g., a UDP echo server and client)

UdpEchoServerHelper echoServer (9);

ApplicationContainer serverApps = echoServer.Install (meshNodes.Get (5));

serverApps.Start (Seconds (1.0));

serverApps.Stop (Seconds (10.0));

UdpEchoClientHelper echoClient (interfaces.GetAddress (5), 9);

echoClient.SetAttribute (“MaxPackets”, UintegerValue (5));

echoClient.SetAttribute (“Interval”, TimeValue (Seconds (1.0)));

echoClient.SetAttribute (“PacketSize”, UintegerValue (1024));

ApplicationContainer clientApps = echoClient.Install (meshNodes.Get (0));

clientApps.Start (Seconds (2.0));

clientApps.Stop (Seconds (10.0));

// Enable tracing

AsciiTraceHelper ascii;

meshHelper.EnableAsciiAll (ascii.CreateFileStream (“mesh-simulation.tr”));

meshHelper.EnablePcapAll (“mesh-simulation”);

// Run the simulation

Simulator::Run ();

Simulator::Destroy ();

return 0;

}

Overall, we had successfully implemented the Mesh protocol by creating a basic set up that configures mesh nodes, and uses an existing mesh protocol HWMP (Hybrid Wireless Mesh Protocol) using ns3 features. Also, we provide more implementation on Mesh protocol with project guidance.