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

How to Implement TSCH based Sensors Communication in ns3

To implement the TSCH (Time-Slotted Channel Hopping) based sensors communication in ns3 needs to configure the TSCH protocol consists of IEEE 802.15.4e standard.

Here, the below is the structure procedure to implement this process via ns3:

Step-by-Step Implementation:

Step 1: Set Up the ns3 Environment

  1. Install ns3: Make sure ns3 is installed in the computer.

sudo apt-get update

sudo apt-get install ns3

  1. Install the Required Modules: Make sure we have include necessary modules installed. For TSCH, you need to have the lr-wpan and internet

Step 2: Create a New ns3 Project

  1. Create a directory for your new project within the ns3 workspace:

cd ns-3

mkdir scratch/tsch-sensor-communication

Step 3: Implement TSCH Communication

  1. Create a New Simulation Script: Create a new script in your scratch directory to implement the simulation scenario.

// tsch-sensor-communication.cc

#include “ns3/core-module.h”

#include “ns3/network-module.h”

#include “ns3/internet-module.h”

#include “ns3/ipv6-address.h”

#include “ns3/ipv6-static-routing-helper.h”

#include “ns3/lr-wpan-module.h”

#include “ns3/ipv6.h”

#include “ns3/ipv6-routing-table-entry.h”

using namespace ns3;

NS_LOG_COMPONENT_DEFINE (“TschSensorCommunication”);

void ReceivePacket (Ptr<Socket> socket) {

Ptr<Packet> packet;

Address from;

while ((packet = socket->RecvFrom (from))) {

if (InetSocketAddress::IsMatchingType (from)) {

NS_LOG_UNCOND (“Received one packet!”);

}

}

}

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

CommandLine cmd;

cmd.Parse (argc, argv);

NodeContainer nodes;

nodes.Create (3);

// Configure TSCH

LrWpanHelper lrWpanHelper;

lrWpanHelper.SetChannelModelType (“ns3::TschSpectrumModel”);

lrWpanHelper.EnableLogComponents ();

NetDeviceContainer lrwpanDevices = lrWpanHelper.Install (nodes);

lrWpanHelper.AssociateToPan (lrwpanDevices, 0);

MobilityHelper mobility;

mobility.SetMobilityModel (“ns3::ConstantPositionMobilityModel”);

mobility.Install (nodes);

InternetStackHelper internetv6;

internetv6.Install (nodes);

Ipv6AddressHelper ipv6;

ipv6.SetBase (Ipv6Address (“2001:1::”), Ipv6Prefix (64));

Ipv6InterfaceContainer ipv6Interfaces = ipv6.Assign (lrwpanDevices);

// Set up routing

Ipv6StaticRoutingHelper ipv6RoutingHelper;

Ptr<Ipv6> ipv6Ptr = nodes.Get (0)->GetObject<Ipv6> ();

Ptr<Ipv6StaticRouting> staticRouting = ipv6RoutingHelper.GetStaticRouting (ipv6Ptr);

staticRouting->AddNetworkRouteTo (Ipv6Address (“2001:2::”), Ipv6Prefix (64), 1);

// Set up applications

uint16_t port = 9;

Address sinkAddress (Inet6SocketAddress (ipv6Interfaces.GetAddress (1, 1), port));

PacketSinkHelper packetSinkHelper (“ns3::UdpSocketFactory”, sinkAddress);

ApplicationContainer sinkApps = packetSinkHelper.Install (nodes.Get (1));

sinkApps.Start (Seconds (0.0));

sinkApps.Stop (Seconds (10.0));

Ptr<Socket> source = Socket::CreateSocket (nodes.Get (0), TypeId::LookupByName (“ns3::UdpSocketFactory”));

Inet6SocketAddress remote = Inet6SocketAddress (ipv6Interfaces.GetAddress (1,

Compile the Script: Compile your script using the waf build system.

./waf build

Run the Simulation: Run your simulation script and observe the results.

./waf –run scratch/tsch-sensor-communication

Step 4: Configure TSCH Communication

  1. Create Nodes and Set up Mobility: Create sensor nodes and set their positions.

NodeContainer nodes;

nodes.Create (3);

MobilityHelper mobility;

mobility.SetMobilityModel (“ns3::ConstantPositionMobilityModel”);

mobility.Install (nodes);

Install TSCH and Network Devices: Set up the TSCH network devices and associate them to a PAN (Personal Area Network).

LrWpanHelper lrWpanHelper;

lrWpanHelper.SetChannelModelType (“ns3::TschSpectrumModel”);

NetDeviceContainer lrwpanDevices = lrWpanHelper.Install (nodes);

lrWpanHelper.AssociateToPan (lrwpanDevices, 0);

Configure IPv6 Addressing: Assign IPv6 addresses to the nodes.

InternetStackHelper internetv6;

internetv6.Install (nodes);

Ipv6AddressHelper ipv6;

ipv6.SetBase (Ipv6Address (“2001:1::”), Ipv6Prefix (64));

Ipv6InterfaceContainer ipv6Interfaces = ipv6.Assign (lrwpanDevices);

Set up Routing: Configure static routing to establish paths between nodes.

Ipv6StaticRoutingHelper ipv6RoutingHelper;

Ptr<Ipv6> ipv6Ptr = nodes.Get (0)->GetObject<Ipv6> ();

Ptr<Ipv6StaticRouting> staticRouting = ipv6RoutingHelper.GetStaticRouting (ipv6Ptr);

staticRouting->AddNetworkRouteTo (Ipv6Address (“2001:2::”), Ipv6Prefix (64), 1);

Install Applications: Set up applications to generate and receive traffic.

uint16_t port = 9;

Address sinkAddress (Inet6SocketAddress (ipv6Interfaces.GetAddress (1, 1), port));

PacketSinkHelper packetSinkHelper (“ns3::UdpSocketFactory”, sinkAddress);

ApplicationContainer sinkApps = packetSinkHelper.Install (nodes.Get (1));

sinkApps.Start (Seconds (0.0));

sinkApps.Stop (Seconds (10.0));

Ptr<Socket> source = Socket::CreateSocket (nodes.Get (0), TypeId::LookupByName (“ns3::UdpSocketFactory”));

Inet6SocketAddress remote = Inet6SocketAddress (ipv6Interfaces.GetAddress (1, 1), port);

source->SetAllowBroadcast (true);

source->Connect (remote);

Step 5: Enable Tracing and Run the Simulation

  1. Enable Tracing: Enable tracing to collect data for analysis.

AsciiTraceHelper ascii;

lrWpanHelper.EnableAsciiAll (ascii.CreateFileStream (“tsch-sensor-communication.tr”));

Run the Simulation: Set the simulation stop time and run it.

Simulator::Stop (Seconds (10.0));

Simulator::Run ();

Simulator::Destroy ();

Here, we finally get knowledge about the Time-Slotted Channel Hopping based sensors communication that was implemented in ns3 tool. We will give further information on how the Time-Slotted Channel Hopping based sensors communication is executed in alternate simulations tool.

TSCH based Sensors Communication in ns3 are worked by us, get best implementation results we follow the protocols and carry on your work.