How to Simulate Data Centric Protocol Projects Using NS2

To simulate data-centric protocols within NS2, which has set of steps that includes concentrating on data dissemination, aggregation, or querying mechanisms that are specifically general in Wireless Sensor Networks (WSNs). Data-centric protocols consider data as the key component, and the communication is according to the data requests (queries) instead of node addresses. Protocols such as Directed Diffusion, Sensor Protocols for Information through Negotiation (SPIN), and Rumor Routing are general instances.

Here’s a common instruction on how to simulate data-centric protocol projects in NS2:

Steps to Simulate Data Centric Protocol Projects in NS2

  1. Install NS2

Make certain that NS2 is installed on the machine. Download it from the NS2 official website.

  1. Choose a Data-Centric Protocol

Numerous data-centric protocols are normally utilized in sensor networks:

  • Directed Diffusion: Data queries are transmitted from sinks, and gradients are established to transmit related data back.
  • SPIN: Nodes advertise data, and interested neighbours request it.
  • Rumor Routing: Rather than flooding the whole network, agents propagate queries along paths, which have heard regarding the event.

For this instance, we will configure Directed Diffusion as the data-centric protocol.

  1. Set Up Directed Diffusion Network Topology

Directed Diffusion includes configuring nodes (sensors and sinks) in which the sink node send out interest queries to accumulate informations from the network.

Example TCL Script for Directed Diffusion Network Topology:

# Create a new simulator instance

set ns [new Simulator]

# Define trace and nam files for logging and visualization

set tracefile [open diffusion_simulation.tr w]

$ns trace-all $tracefile

set namfile [open diffusion_simulation.nam w]

$ns namtrace-all $namfile

# Set up network parameters (wireless channel, propagation, MAC, etc.)

set val(chan)           Channel/WirelessChannel    ;# Channel type

set val(prop)           Propagation/TwoRayGround   ;# Propagation model

set val(netif)          Phy/WirelessPhy            ;# Network interface type

set val(mac)            Mac/802_11                 ;# MAC layer

set val(ifq)            Queue/DropTail/PriQueue    ;# Interface queue type

set val(ll)             LL                         ;# Link layer type

set val(ant)            Antenna/OmniAntenna        ;# Antenna type

set val(x)              1000                       ;# X dimension

set val(y)              1000                       ;# Y dimension

# Configure nodes to use Directed Diffusion behavior

$ns node-config -adhocRouting Diffusion \

-llType $val(ll) \

-macType $val(mac) \

-ifqType $val(ifq) \

-antType $val(ant) \

-propType $val(prop) \

-phyType $val(netif) \

-channelType $val(chan)

# Create sensor and sink nodes

set sink [$ns node]  ;# Sink node (query initiator)

set sensor1 [$ns node]  ;# Sensor node 1

set sensor2 [$ns node]  ;# Sensor node 2

set sensor3 [$ns node]  ;# Sensor node 3

set sensor4 [$ns node]  ;# Sensor node 4

# Set initial positions for nodes (optional)

$sink set X_ 50; $sink set Y_ 50; $sink set Z_ 0.0

$sensor1 set X_ 100; $sensor1 set Y_ 100; $sensor1 set Z_ 0.0

$sensor2 set X_ 150; $sensor2 set Y_ 150; $sensor2 set Z_ 0.0

$sensor3 set X_ 200; $sensor3 set Y_ 200; $sensor3 set Z_ 0.0

$sensor4 set X_ 250; $sensor4 set Y_ 250; $sensor4 set Z_ 0.0

# Establish wireless communication links between nodes

$ns simplex-link $sensor1 $sensor2 500Kb 10ms DropTail

$ns simplex-link $sensor2 $sensor3 500Kb 10ms DropTail

$ns simplex-link $sensor3 $sensor4 500Kb 10ms DropTail

$ns simplex-link $sensor4 $sink 500Kb 10ms DropTail

  1. Simulate Directed Diffusion Behavior

In Directed Diffusion, the sink node transmits out an interest to query data, and sensor nodes, which fits the query that react with data packets.

Example for Query and Data Dissemination:

# Function to simulate an interest query from the sink

proc send_interest {src dst query} {

global ns

$ns at 1.0 “$src send-interest $dst $query”

}

# Function to simulate data dissemination from sensor to sink

proc send_data {sensor sink data} {

global ns

$ns at 5.0 “$sensor send-data $sink $data”

}

# Simulate interest query from sink to sensor nodes

send_interest $sink $sensor1 “temperature”

# Simulate data dissemination from sensor nodes back to sink

send_data $sensor1 $sink “temperature_data”

This replicates the sink node transmitting an interest query for temperature data and the sensor node transmitting the data back to the sink.

  1. Set Up Traffic for Data-Centric Communication

When the interest query is determined then data can be transmitted among the nodes. The data-centric nature of the protocol permits the system to send data depends on the relevance (e.g., matching the query).

Example for UDP Traffic (Sensor Data):

# Set up UDP communication between sensor 1 and the sink

set udp0 [new Agent/UDP]

set null0 [new Agent/Null]

$ns attach-agent $sensor1 $udp0

$ns attach-agent $sink $null0

# Generate data over UDP (sensor sending data to sink)

set cbr0 [new Application/Traffic/CBR]

$cbr0 set packetSize_ 512

$cbr0 set rate_ 50kb

$cbr0 attach-agent $udp0

$ns at 2.5 “$cbr0 start”

$ns at 10.0 “$cbr0 stop”

  1. Run the Simulation

We need save the TCL script (e.g., diffusion_simulation.tcl) and execute it using NS2:

ns diffusion_simulation.tcl

It will make a trace file (.tr) and a NAM file (.nam) for visualization within Network Animator (NAM).

  1. Analyze the Simulation Results

We can examine the performance of the data-centric protocol utilizing parameters like:

  • Packet Delivery Ratio (PDR)
  • Latency for Data Query and Response
  • Routing Overhead

Example AWK Script for Packet Delivery Ratio:

BEGIN { sent = 0; received = 0; }

{

if ($1 == “s” && $4 == “AGT”) { sent++; }

if ($1 == “r” && $4 == “AGT”) { received++; }

}

END { print “Packet Delivery Ratio = “, received/sent*100, “%”; }

It will be computed the Packet Delivery Ratio rely on the amount of packets transmitted and received.

  1. Example Project Ideas for Data-Centric Protocol Simulation
  1. Performance Comparison Between Directed Diffusion and SPIN:
    • Replicate both Directed Diffusion and SPIN and relate their performance such as data delivery ratio, energy efficiency, and routing overhead.
  2. Energy-Efficient Data-Centric Protocol:
    • Execute an energy-saving methods (like data aggregation) in Directed Diffusion and measure their effect on energy consumption and network lifetime.
  3. Data-Centric Routing in Mobile Sensor Networks:
    • Mimic a mobile sensor network and evaluate on how data-centric protocols such as Directed Diffusion manage mobility like data delivery and query response.
  4. Data Aggregation and Compression in Data-Centric Networks:
    • Execute data aggregation such as averaging temperature readings from numerous sensors and estimate its effect on network traffic and performance.

In this manual, we focussed on how to simulate and examine the Data Centric Protocol projects with the help of simplified method using the tool NS2. Further specifics relevant to this subject will follow.

Discover expert insights on protocols like Directed Diffusion and Sensor Protocols at phdprime.com. We offer detailed, step-by-step instructions to help you replicate Data Centric Protocol Projects using NS2, customized to meet your specific needs.

Opening Time

9:00am

Lunch Time

12:30pm

Break Time

4:00pm

Closing Time

6:30pm

  • award1
  • award2