How to Simulate PEGASIS Protocol Projects Using NS2

To simulate PEGASIS (Power-Efficient GAthering in Sensor Information Systems) protocol using NS2, we require to know that PEGASIS is a hierarchical chain-based routing protocol for wireless sensor networks (WSNs). It targets to enhance energy efficiency by systematizing nodes into chains and rotating the leader node responsible for communication with the base station (sink). PEGASIS protocol is frequently executed on top of existing wireless communication protocols within NS2, as NS2 doesn’t have native support for PEGASIS. Hence, custom execution is needed.

PEGASIS Protocol Projects  simulation are effectively guided by us , we at phdprime.com will be your  trusted partner who guides you in full success.

Here, we provide a step-by-step instruction to simulate PEGASIS protocol within NS2 by making the chain-based communication behaviour and executing leader node rotation.

Steps to Simulate PEGASIS Protocol in NS2

  1. Install NS2

Make certain that NS2 is installed on the machine. We can install NS2 using the below command on Linux systems:

sudo apt-get install ns2

For Windows, we can utilize Cygwin or download the precompiled NS2 package.

  1. Understanding PEGASIS Protocol Structure

In PEGASIS:

  • Nodes are systematized into chains.
  • Data is accumulated along the chain, and only one node (the leader) sends the aggregated data to the base station (sink).
  • The leader node rotates to distribute energy consumption between the nodes.
  1. Create the TCL Script for PEGASIS Simulation

We require to make a custom script to execute PEGASIS. It contains forming chains, rotating leader nodes, and describing energy consumption. The following is an instance of a basic execution.

Example TCL Script for PEGASIS Simulation

# Define the simulator object

set ns [new Simulator]

# Open trace file and NAM file for visualization

set tracefile [open pegasis.tr w]

$ns trace-all $tracefile

set namfile [open pegasis.nam w]

$ns namtrace-all $namfile

# Define simulation parameters

set val(nn) 10                ;# Number of nodes (sensor nodes)

set val(stop) 50.0            ;# Simulation stop time

set val(x) 500                ;# X dimension of topology

set val(y) 500                ;# Y dimension of topology

set leader_node 0             ;# Initial leader node

# Create a flat grid for node positioning

set topo [new Topography]

$topo load_flatgrid $val(x) $val(y)

# Create wireless channel and MAC parameters

set val(chan)   Channel/WirelessChannel

set val(prop)   Propagation/TwoRayGround

set val(netif)  Phy/WirelessPhy

set val(mac)    Mac/802_11

set val(ifq)    Queue/DropTail/PriQueue

set val(ll)     LL

set val(ant)    Antenna/OmniAntenna

set val(ifqlen) 50

set val(seed)   0.0

set val(stop)   100.0

set val(adhocRouting) DSDV   ;# Default routing, you can use AODV or DSDV

# Create sensor nodes

for {set i 0} {$i < $val(nn)} {incr i} {

set node_($i) [$ns node]

$node_($i) set X_ [expr rand()*$val(x)]

$node_($i) set Y_ [expr rand()*$val(y)]

$node_($i) set Z_ 0.0

}

# Define the sink/base station (fixed node at the center)

set sink [$ns node]

$sink set X_ [expr $val(x) / 2]

$sink set Y_ [expr $val(y) / 2]

$sink set Z_ 0.0

# Leader node initially node 0

set leader $node_(0)

# Function to rotate leader node

proc rotate_leader {} {

global leader node_

set current_leader $leader

set next_leader [expr ($current_leader + 1) % 10]

set leader $node_($next_leader)

puts “Leader node changed to: $next_leader”

}

# Schedule leader rotation every 10 seconds

for {set t 10.0} {$t <= $val(stop)} {set t [expr $t + 10.0]} {

$ns at $t “rotate_leader”

}

# Define communication within the PEGASIS chain

proc chain_communication {source dest} {

global ns node_

set udp [new Agent/UDP]

$ns attach-agent $source $udp

set null [new Agent/Null]

$ns attach-agent $dest $null

$ns connect $udp $null

set cbr [new Application/Traffic/CBR]

$cbr set packetSize_ 512

$cbr set interval_ 0.1

$cbr attach-agent $udp

return $cbr

}

# Form PEGASIS chain communication pattern

for {set i 0} {$i < $val(nn) – 1} {incr i} {

set app [chain_communication $node_($i) $node_([expr $i + 1])]

$ns at 1.0 “$app start”

$ns at $val(stop) “$app stop”

}

# Communication from leader node to sink

set app_sink [chain_communication $leader $sink]

$ns at 1.0 “$app_sink start”

$ns at $val(stop) “$app_sink stop”

# End the simulation

$ns at $val(stop) “finish”

proc finish {} {

global ns tracefile namfile

$ns flush-trace

close $tracefile

close $namfile

exec nam pegasis.nam &

exit 0

}

# Start simulation

$ns run

  1. Explanation of the Script
  • Nodes Creation: Ten sensor nodes are made and placed randomly on a flat grid. These nodes denote the sensors in the WSN.
  • Sink Node: The base station (sink node) is positioned at the center of the topology.
  • Leader Rotation: A technique is described to rotate the leader node every 10 seconds, simulating the energy-efficient leader rotation in PEGASIS.
  • Chain Communication: The chain_communication procedure ascertains communication among the nodes, simulating the data aggregation along the chain in PEGASIS.
  • Traffic: Constant Bit Rate (CBR) traffic is made among the nodes in the chain, with the leader node transmitted aggregated data to the sink.
  • Simulation End: The simulation runs for 50 seconds, after which it ends.
  1. Running the Simulation

We can save the script as pegasis.tcl and then we run it in NS2:

ns pegasis.tcl

  1. Visualizing the Simulation

We can envision the network behaviour, containing chain-based communication and leader node rotation, utilizing NAM (Network Animator):

nam pegasis.nam

  1. Analyzing the Trace File

The trace file (pegasis.tr) includes detailed data regarding the packet transmissions, routing updates, and node behaviour. We can examine the file to extract key performance parameters such as:

  • Energy Consumption: Since PEGASIS is regarding energy efficiency, we can model energy levels for each node and compute the remaining energy after each transmission.
  • Latency: Compute the delay in data transmission from sensor nodes to the sink.
  • Throughput: Measure the amount of data effectively sent to the sink.

We can be used AWK, Python, or other tools to process the trace file and calculate these parameters.

  1. Enhancements and Extensions

We can expand this simple simulation by inserting:

  • Energy Model: NS2 allows describing energy models, thus we can compute the energy consumed by each node and replicate energy depletion over time.
  • Advanced Leader Selection: Rather than rotating the leader node in a round-robin fashion, we can execute energy-aware leader selection in which the node with the most remaining energy becomes the leader.
  • Multiple Sink Nodes: We can launch several sink nodes to replicate a more complex WSN topology with several base stations.

These projects concentrated on how to simulate and enhance the PEGASIS Protocol projects through the above set of steps using NS2 simulator. We are furnished to provide additional concepts on this topic, if necessary.

Opening Time

9:00am

Lunch Time

12:30pm

Break Time

4:00pm

Closing Time

6:30pm

  • award1
  • award2