How to Start Zigbee Topology Projects Using NS2

To stimulate a Zigbee Topology project in NS2 (Network Simulator 2) has replicate a Zigbee network according to the IEEE 802.15.4 standard. Zigbee is usually used in low-power, low-data-rate wireless networks, like as home automation, IoT devices, and sensor networks.

Here’s how to set up and simulate a Zigbee Topology project in NS2:

Steps to Start Zigbee Topology Projects Using NS2

  1. Understand Zigbee Topology
  • Zigbee Topologies:
    • Star Topology: One central node such as Coordinator links are directly by end devices.
    • Tree Topology: The hierarchy topology that coordinator connects the routers and routers linked the close devices.
    • Mesh Topology: Nodes are interconnected, permitting the multi-hop communication.
  • Key Components:
    • Coordinator: It handles the network and allocates the addresses.
    • Routers: Transmit the data and encompass the network area.
    • End Devices: Low-power devices which only communicate by a parent node.
  • Applications:
    • Home automation.
    • IoT networks.
    • Wireless sensor networks.
  1. Set Up NS2
  1. Install NS2:
    • Install and validate the NS2 functionality:

ns example.tcl

  1. Tools for Analysis:
    • NAM (Network Animator) intended for envision.
    • Trace Analysis Tools designed for estimate the parameter metrics like latency, throughput, and delivery ratio.
  2. Support for Zigbee:
    • NS2 helps for Zigbee replication using the extension of IEEE 802.15.4.
  1. Plan the Zigbee Topology
  • Network Design:
    • Choose the topology category: Star, Tree, or Mesh.
    • Deploy the nodes according to the application environment.
  • Metrics to Analyze:
    • Packet delivery ratio (PDR).
    • Latency.
    • Throughput.
    • Energy consumption.
  1. Write the Simulation Script

Step 4.1: Create the TCL Script

Store the script as zigbee_topology.tcl.

Step 4.2: Initialize the Simulator

Setting the wireless replicator:

# Initialize the simulator

set ns [new Simulator]

set tracefile [open trace.tr w]

$ns trace-all $tracefile

set namfile [open zigbee_topology.nam w]

$ns namtrace-all-wireless $namfile

# Set up the wireless parameters

set val(chan) Channel/WirelessChannel

set val(prop) Propagation/TwoRayGround

set val(netif) Phy/WirelessPhy

set val(mac) Mac/802_15_4

set val(ifq) Queue/DropTail/PriQueue

set val(ll) LL

set val(ant) Antenna/OmniAntenna

set val(x) 500

set val(y) 500

set val(ifqlen) 50

Step 4.3: Create Nodes

Express the coordinator, routers, and end devices:

# Create nodes

set coordinator [$ns node]

set router1 [$ns node]

set router2 [$ns node]

set end_device1 [$ns node]

set end_device2 [$ns node]

# Position the nodes

$coordinator set X_ 250

$coordinator set Y_ 250

$coordinator set Z_ 0.0

$router1 set X_ 150

$router1 set Y_ 250

$router1 set Z_ 0.0

$router2 set X_ 350

$router2 set Y_ 250

$router2 set Z_ 0.0

$end_device1 set X_ 100

$end_device1 set Y_ 250

$end_device1 set Z_ 0.0

$end_device2 set X_ 400

$end_device2 set Y_ 250

$end_device2 set Z_ 0.0

Step 4.4: Configure Links

Describe the logical connections:

# Coordinator to Routers

$ns duplex-link $coordinator $router1 250Kb 10ms DropTail

$ns duplex-link $coordinator $router2 250Kb 10ms DropTail

# Routers to End Devices

$ns duplex-link $router1 $end_device1 250Kb 10ms DropTail

$ns duplex-link $router2 $end_device2 250Kb 10ms DropTail

Step 4.5: Configure Traffic

It configures the data traffic from end devices for the coordinator:

# Traffic from end_device1 to coordinator

set udp1 [new Agent/UDP]

$ns attach-agent $end_device1 $udp1

set null1 [new Agent/Null]

$ns attach-agent $coordinator $null1

$ns connect $udp1 $null1

set cbr1 [new Application/Traffic/CBR]

$cbr1 attach-agent $udp1

$cbr1 set packetSize_ 100

$cbr1 set rate_ 20Kb

$ns at 1.0 “$cbr1 start”

# Traffic from end_device2 to coordinator

set udp2 [new Agent/UDP]

$ns attach-agent $end_device2 $udp2

set null2 [new Agent/Null]

$ns attach-agent $coordinator $null2

$ns connect $udp2 $null2

set cbr2 [new Application/Traffic/CBR]

$cbr2 attach-agent $udp2

$cbr2 set packetSize_ 100

$cbr2 set rate_ 20Kb

$ns at 2.0 “$cbr2 start”

Step 4.6: Enable Routing Protocol

It can use the AODV or Zigbee-compatible routing protocol:

# Enable AODV for multi-hop communication

$ns rtproto AODV

Step 4.7: Finalize the Script

Improve the replication of close surroundings:

# End simulation

$ns at 10.0 “finish”

proc finish {} {

global ns tracefile namfile

$ns flush-trace

close $tracefile

close $namfile

exec nam zigbee_topology.nam &

exit 0

}

$ns run

  1. Run the Simulation
  1. Save the script as zigbee_topology.tcl.
  2. It process for the replication:

ns zigbee_topology.tcl

  1. Go to NAM for envision the Zigbee topology:

nam zigbee_topology.nam

  1. Analyze Results
  • Trace File Analysis:
    • Make use of trace.tr for study the performance of metrics such as PDR, latency, and throughput.
    • Sample the tool AWK script for throughput:

awk ‘{if ($1 == “r” && $4 == “udp”) sum += $8} END {print “Throughput: “, sum}’

  • Metrics:
    • Packet Delivery Ratio (PDR): Reliability in data forwarding.
    • Latency: Delays for the communication.
    • Throughput: Data delivery for the effectiveness.
  1. Expand the Simulation
  1. Increase Network Size:
    • Improve the further routers and end devices for estimate the scalability.
  2. Introduce Mobility:
    • Ensure the arbitrary motion for end devices:

$end_device1 random-motion 1

  1. Simulate Failures:
    • Validate the network’s fault tolerance through disabling nodes or connection:

$ns at 5.0 “$ns link-fail $router1 $end_device1”

  1. Experiment with Routing Protocols:
    • Associate the performance using research for AODV, DSR, or Zigbee-specific routing protocols.
  1. Document the Project
  • Objective: Define the determination of replicate a Zigbee topology.
  • Setup: It contains the specific about node roles, congestion design, and routing protocols.
  • Results: Present parameter metrics such as PDR, latency, and throughput.
  • Conclusions: Summarize detection and refer the enhancements.

At the end of this manual, we clearly elaborated and deliver the details and shown examples of how to simulate ZigBee Topology projects in ns2 tool by using the above discussed techniques. Queries about the project will be answered in another manual.