How to Start Data Centric Protocol Projects Using NS2

To start Data-Centric Protocol projects using NS2, we have concentrating the protocols which are intended for Wireless Sensor Networks (WSN) or same distributed networks in which data aggregation, energy efficiency, and data relevance are highlighted. Instances of data-centric protocols contains SPIN (Sensor Protocols for Information via Negotiation), Directed Diffusion, and LEACH. Below is a structured procedure for Data Centric Protocol projects using NS2:

Steps to Start Data-Centric Protocol Projects in NS2

  1. Set Up NS2 Environment

Make sure that we have installed NS2 and set it up.

Install NS2 (Ubuntu/Linux)

sudo apt-get update

sudo apt-get install ns2

Verify NS2 Installation

Run:

ns

If successfully installed NS2 then it will show prompt (%).

  1. Enable Data-Centric Protocol Support

NS2 environment have direct support for Directed Diffusion and SPIN, however other protocols such as LEACH that needs external patches.

Verify Directed Diffusion or SPIN Support

Confirm ns-default.tcl for verifying the Directed Diffusion or SPIN availability:

grep -i “DirectedDiffusion” ns-2.35/tcl/lib/ns-default.tcl

grep -i “SPIN” ns-2.35/tcl/lib/ns-default.tcl

If SPIN or Directed Diffusion is detailed then we will need to execute simulation script.

  1. Write a TCL Script for Directed Diffusion (Data-Centric Protocol)

Here’s an instance TCL script for replicating a simple Directed Diffusion scenario within a WSN:

Directed Diffusion Simulation Script:

# Initialize the simulator

set ns [new Simulator]

# Define trace and NAM files

set tr [open directed-diffusion.tr w]

$ns trace-all $tr

set nf [open directed-diffusion.nam w]

$ns namtrace-all-wireless $nf

# Define simulation 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(x)              500

set val(y)              500

set val(stop)           10.0

# Topology

set topo [new Topography]

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

# Create Nodes

set n(0) [$ns node]

set n(1) [$ns node]

set n(2) [$ns node]

set n(3) [$ns node]

set n(4) [$ns node]

# Set Node Positions

$ns at 0.0 “$n(0) setdest 100 200 0”

$ns at 0.0 “$n(1) setdest 150 250 0”

$ns at 0.0 “$n(2) setdest 300 400 0”

$ns at 0.0 “$n(3) setdest 400 300 0”

$ns at 0.0 “$n(4) setdest 250 100 0”

# Enable Directed Diffusion

$ns rtproto DirectedDiffusion

# Attach Traffic Sources (Sensors)

set udp [new Agent/UDP]

$ns attach-agent $n(0) $udp

set sink [new Agent/Null]

$ns attach-agent $n(4) $sink

$ns connect $udp $sink

set cbr [new Application/Traffic/CBR]

$cbr attach-agent $udp

$cbr set packetSize_ 512

$cbr set rate_ 10kb

# Start and Stop Traffic

$ns at 1.0 “$cbr start”

$ns at 9.5 “$cbr stop”

# Finish Procedure

$ns at $val(stop) “finish”

proc finish {} {

global ns tr nf

$ns flush-trace

close $tr

close $nf

exec nam directed-diffusion.nam &

exit 0

}

# Run the simulation

$ns run

  1. Run the Simulation
  1. We can store the script file like directed_diffusion.tcl in NS2.
  2. Then, execute the simulation script using tcl:

ns directed_diffusion.tcl

  1. Outputs:
    • NAM File: Go to an animation window for envisioning the node interaction.
    • Trace File (directed-diffusion.tr): It supports to records the simulation events.
  1. Analyze Simulation Results

Examine the key simulation performance parameters to apply trace file:

  1. Packet Delivery Ratio (PDR):

awk ‘{if($1==”r” && $4==”cbr”) count++} END {print “PDR:”, count}’ directed-diffusion.tr

  1. End-to-End Delay:

awk ‘{if($1==”r” && $4==”cbr”) {delay[$6] = $2 – start[$6]}} END {for (i in delay) sum += delay[i]; print “Avg Delay:”, sum/NR}’ directed-diffusion.tr

  1. Energy Consumption (For WSN):

If an energy pattern is integrated then we can estimate the energy utilization at every node for WSN.

  1. Enhance Your Data-Centric Protocol Project
  2. Simulate Larger Networks:
  • Examine the scalability as the volume of nodes in 50–100 maximizes.
  1. Add Mobility Models:
  • Make use of Random Waypoint or integrate other mobility patterns for dynamic WSNs:

$ns at 0.0 “$n(1) setdest 200 300 10”

  1. Compare SPIN vs Directed Diffusion:
  • We will estimate the packet delivery, delay, and energy consumption for comparison.
  1. Integrate Energy Models:
  • Integrate the node energy consumption patterns for replicating realistic WSN environments.
  1. Data Aggregation:
  • Mimic how data aggregation minimizes the redundancy at middle nodes.
  1. Simulate Fault Tolerance:
  • To monitor the resilience of protocol, we can launch node failures or link disruptions:

$ns rtmodel-at 5.0 down $n(2) $n(3)

  1. Tools for Performance Visualization
  • NAM: Envision the protocol operation and packet flow applying NAM.
  • AWK/Python: Examine the trace file to utilise AWK or Python tools for estimating the performance parameters.
  • Gnuplot/Matplotlib: Design the graphs using Gnuplot or Python’s Matplotlib libraries for assessing the:
    • Packet Delivery Ratio vs Node Density
    • End-to-End Delay vs Traffic Load
    • Energy Consumption vs Simulation Time

Example Data-Centric Project Ideas:

  1. Performance Comparison of SPIN and Directed Diffusion in WSN:
    • We will measure the energy efficiency and packet delivery in diverse node densities for comparing the performance of SPIN with Directed Diffusion.
  2. Energy-Efficient Directed Diffusion Protocol:
    • Execute and mimic an energy-aware variation of Directed Diffusion protocol in WSN.
  3. Data Aggregation in WSN:
    • We need to replicate the data aggregation mechanisms for minimizing the traffic overhead and power utilization.
  4. Fault-Tolerant Directed Diffusion:
    • Assess the performance of Directed Diffusion protocol including node/link failures.
  5. Scalability Analysis:
    • We will want to replicate the large-scale WSNs for examining the behaviour of protocol for scalability investigation.

The delivered process contains the entire instructions and examples with snippet codes to help you obtain the knowledge of Data Centric Protocol Projects and how to simulate and analyse it in ns2. More advanced concepts and mechanisms to be provided later.