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

How to Implement Zigbee Topology in ns3

To implement the Zigbee topology in ns3, we need to generate the network of nodes that interacted by Zigbee protocol. The ns3 simulation tool offers the LR-WPAN module to estimate the Zigbee networks.

Now we can see how to implement the Zigbee topology in ns3 tool:

Step-by-Step Implementation:

Step 1: Install ns3

  • Make sure ns3 is installed in the computer.

Step 2: Create a New Simulation Script

  • Create a new C++ script for your simulation.

Step 3: Include Necessary Headers

  • In your script, include the necessary ns-3 headers:

#include “ns3/core-module.h”

#include “ns3/network-module.h”

#include “ns3/internet-module.h”

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

#include “ns3/mobility-module.h”

#include “ns3/internet-apps-module.h”

#include “ns3/energy-module.h”

Step 4: Set Up the Zigbee Topology

Here, we provide the sample setup of zigbee topology that has one coordinator and various end devices:

using namespace ns3;

NS_LOG_COMPONENT_DEFINE (“ZigbeeTopology”);

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

{

// Configure command line parameters

CommandLine cmd;

cmd.Parse (argc, argv);

// Create nodes

NodeContainer coordinator;

coordinator.Create (1); // Create the coordinator node

NodeContainer endDevices;

endDevices.Create (4); // Create 4 end devices

NodeContainer allNodes = NodeContainer (coordinator, endDevices);

// Configure mobility model

MobilityHelper mobility;

Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator> ();

positionAlloc->Add (Vector (50.0, 50.0, 0.0)); // Coordinator position

positionAlloc->Add (Vector (100.0, 50.0, 0.0)); // End device 1

positionAlloc->Add (Vector (50.0, 100.0, 0.0)); // End device 2

positionAlloc->Add (Vector (0.0, 50.0, 0.0)); // End device 3

positionAlloc->Add (Vector (50.0, 0.0, 0.0)); // End device 4

mobility.SetPositionAllocator (positionAlloc);

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

mobility.Install (allNodes);

// Install LR-WPAN devices

LrWpanHelper lrWpanHelper;

NetDeviceContainer lrwpanDevices = lrWpanHelper.Install (allNodes);

lrWpanHelper.AssociateToPan (lrwpanDevices, 0); // Associate devices to PAN ID 0

// Enable packet reception logging on the coordinator

lrWpanHelper.EnablePcap (“zigbee-topology”, lrwpanDevices);

// Install the internet stack on the coordinator

InternetStackHelper internet;

internet.Install (coordinator);

// Assign IP addresses to the coordinator

Ipv4AddressHelper ipv4;

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

Ipv4InterfaceContainer coordinatorInterface = ipv4.Assign (lrwpanDevices.Get (0));

// Set up applications (e.g., UDP echo server on the coordinator and clients on end devices)

uint16_t port = 9; // Port number for applications

// Install UDP Echo Server on the coordinator

UdpEchoServerHelper echoServer (port);

ApplicationContainer serverApps = echoServer.Install (coordinator.Get (0));

serverApps.Start (Seconds (1.0));

serverApps.Stop (Seconds (10.0));

// Install UDP Echo Clients on end devices to communicate with the coordinator

for (uint32_t i = 0; i < endDevices.GetN (); ++i)

{

UdpEchoClientHelper echoClient (coordinatorInterface.GetAddress (0), port);

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

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

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

ApplicationContainer clientApps = echoClient.Install (endDevices.Get (i));

clientApps.Start (Seconds (2.0 + i)); // Stagger start times

clientApps.Stop (Seconds (10.0));

}

// Run simulation

Simulator::Stop (Seconds (10.0));

Simulator::Run ();

Simulator::Destroy ();

return 0;

}

Step 5: Build and Run the Simulation

  1. Save the script as zigbee-topology.cc.
  2. Build the script using waf:

./waf configure –enable-examples

./waf build

  1. Run the simulation:

./waf –run scratch/zigbee-topology

Explanation of the Script

  • Node Creation: Creates one coordinator node and four end devices.
  • Mobility Model: Sets the position of nodes in a specific layout using ListPositionAllocator and ConstantPositionMobilityModel.
  • LR-WPAN Devices: Configures LR-WPAN (Zigbee) devices and associates them to a PAN (Personal Area Network).
  • Internet Stack: Installs the internet stack on the coordinator node to enable IP communication.
  • IP Addressing: Assigns an IP address to the coordinator node.
  • Applications: Sets up a UDP echo server on the coordinator and UDP echo clients on the end devices to demonstrate communication between nodes.

In the end, we had our simulation result for Zigbee Topology that creates the node for end users then download the stack to interact with nodes finally it shows how it communication among nodes using ns3.

If you require any help with implementing Zigbee Topology in ns3, feel free to reach out to us at ns3simulation.com. Our team of developers is dedicated to assisting you in achieving your desired results. Share your parameter details with us for a thorough networking performance analysis and optimal outcomes. Additionally, we can provide you with further insights on how Zigbee Topology functions in various simulation tools.