How to Simulate Data Centric Protocol Projects Using NS3

To simulate the data-centric protocols using NS3 that contains concentrating on the protocols in which data (instead of device addresses or specific node identities) is the key module of communication. This data-centric protocols are generally used in Wireless Sensor Networks (WSNs), Internet of Things (IoT), and other distributed systems in which data aggregation, dissemination, and query-based communication are significant. Instances contain protocols such as Directed Diffusion, SPIN (Sensor Protocols for Information via Negotiation), and Data-Centric Storage protocols. The simulation environment NS3 does not natively support data-centric protocols, however we can be replicated such protocols by tailoring existing tools and developing extensions.

Key Concepts of Data-Centric Protocols:

  1. Data Naming: Communication is according to the data, not the node IDs.
  2. Interest-Based Queries: Data requests are propagated via the network to discover related data.
  3. Aggregation: Redundant data is aggregated to reduce communication overhead.
  4. Energy Efficiency: Efficient use of resources (e.g., energy, bandwidth) is vital within sensor networks.

Example: Simulating Directed Diffusion Protocol (a Data-Centric Protocol) in NS3

To replicate a data-centric protocol such as Directed Diffusion in NS3, we can make a simple simulation which concentrates on data aggregation, interest propagation, and data forwarding. Below, we replicate a basic Directed Diffusion method using custom NS3 applications to simulate the behaviour of interest propagation and data matching.

Steps to Simulate a Data-Centric Protocol (Directed Diffusion) in NS3

  1. Install NS3

Make sure that NS3 is installed on the system. Unless, download and install it from the NS3 official website.

  1. Create a Custom Data-Centric Simulation

We will replicate the simple operations of Directed Diffusion in which:

  1. A sink node transmits interest queries into the network.
  2. Source nodes with related data respond to the query.
  3. Intermediate nodes are forward and aggregate the data.

Example Simulation Using a Simplified Data-Centric Protocol in NS3

  1. Include Necessary Headers

These headers are needed for configuring the wireless communication, mobility, and custom applications to replicate the data-centric protocol.

#include “ns3/core-module.h”

#include “ns3/network-module.h”

#include “ns3/internet-module.h”

#include “ns3/wifi-module.h”

#include “ns3/mobility-module.h”

#include “ns3/applications-module.h”

#include “ns3/netanim-module.h”

  1. Create and Install Nodes

Make a set of nodes are signifying the sink, source, and intermediate nodes in the data-centric network.

NodeContainer nodes;

nodes.Create(6);  // Create 6 nodes for the data-centric network

  1. Configure Wireless Communication (Wi-Fi)

We can use the WifiHelper and YansWifiChannelHelper to set up wireless communication among the nodes.

YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default();

YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default();

wifiPhy.SetChannel(wifiChannel.Create());

WifiHelper wifi;

wifi.SetStandard(WIFI_PHY_STANDARD_80211g);  // Set the Wi-Fi standard to 802.11g

wifi.SetRemoteStationManager(“ns3::AarfWifiManager”);

WifiMacHelper wifiMac;

wifiMac.SetType(“ns3::AdhocWifiMac”);  // Set the MAC layer to Ad-hoc mode

NetDeviceContainer devices = wifi.Install(wifiPhy, wifiMac, nodes);

  1. Install the Internet Stack

We can install the Internet stack (TCP/IP) on the nodes to enable communication among them.

InternetStackHelper internet;

internet.Install(nodes);

  1. Assign IP Addresses

Allocate an IP addresses to the wireless devices (nodes).

Ipv4AddressHelper address;

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

Ipv4InterfaceContainer interfaces = address.Assign(devices);

  1. Set Up Mobility Model for Nodes

We can use the MobilityHelper to describe the mobility model for the nodes in the network.

MobilityHelper mobility;

mobility.SetPositionAllocator(“ns3::GridPositionAllocator”,

“MinX”, DoubleValue(0.0),

“MinY”, DoubleValue(0.0),

“DeltaX”, DoubleValue(100.0),

“DeltaY”, DoubleValue(100.0),

“GridWidth”, UintegerValue(3),

“LayoutType”, StringValue(“RowFirst”));

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

mobility.Install(nodes);

  1. Create Custom Applications for Data-Centric Communication

We require to describe the custom applications, which replicate an interest propagation (query) from a sink node and data forwarding from source nodes. For simplicity, we can be made custom UDP applications for querying and responding.

  • Sink Node Application (Interest Propagation):

The sink node occasionally broadcasts interest packets (queries) to the network.

class SinkApplication : public Application

{

public:

SinkApplication() {}

virtual ~SinkApplication() {}

void Setup(Ptr<Socket> socket, Address address, uint32_t packetSize, uint32_t nPackets, Time interPacketInterval)

{

m_socket = socket;

m_peer = address;

m_packetSize = packetSize;

m_nPackets = nPackets;

m_interval = interPacketInterval;

m_packetsSent = 0;

}

private:

virtual void StartApplication(void)

{

m_socket->Bind();

SendPacket();

}

void SendPacket()

{

Ptr<Packet> packet = Create<Packet>(m_packetSize);

m_socket->SendTo(packet, 0, m_peer);

++m_packetsSent;

 

if (m_packetsSent < m_nPackets)

{

Simulator::Schedule(m_interval, &SinkApplication::SendPacket, this);

}

}

Ptr<Socket> m_socket;

Address m_peer;

uint32_t m_packetSize;

uint32_t m_nPackets;

Time m_interval;

uint32_t m_packetsSent;

};

// Create a sink node that broadcasts interest messages

Ptr<Socket> sinkSocket = Socket::CreateSocket(nodes.Get(0), UdpSocketFactory::GetTypeId());

Address sinkBroadcast = InetSocketAddress(Ipv4Address(“10.1.1.255”), 8080);  // Broadcast address for interest propagation

Ptr<SinkApplication> sinkApp = CreateObject<SinkApplication>();

sinkApp->Setup(sinkSocket, sinkBroadcast, 1024, 100, Seconds(1.0));  // Send interest every second

nodes.Get(0)->AddApplication(sinkApp);

sinkApp->SetStartTime(Seconds(1.0));

sinkApp->SetStopTime(Seconds(10.0));

  • Source Node Application (Data Response):

Source nodes are listen for interest messages and react with related data if they match the query.

class SourceApplication : public Application

{

public:

SourceApplication() {}

virtual ~SourceApplication() {}

void Setup(Ptr<Socket> socket, Address address)

{

m_socket = socket;

m_peer = address;

}

private:

virtual void StartApplication(void)

{

m_socket->Bind();

m_socket->SetRecvCallback(MakeCallback(&SourceApplication::HandleRead, this));

}

void HandleRead(Ptr<Socket> socket)

{

Ptr<Packet> packet = socket->Recv();

// Process interest query and send response

Ptr<Packet> response = Create<Packet>(1024);  // Send data if query matches

socket->SendTo(response, 0, m_peer);

}

Ptr<Socket> m_socket;

Address m_peer;

};

// Create source nodes that respond to interest queries

Ptr<Socket> sourceSocket = Socket::CreateSocket(nodes.Get(5), UdpSocketFactory::GetTypeId());

Address sinkAddress = InetSocketAddress(interfaces.GetAddress(0), 8080);  // Send data back to the sink

Ptr<SourceApplication> sourceApp = CreateObject<SourceApplication>();

sourceApp->Setup(sourceSocket, sinkAddress);

nodes.Get(5)->AddApplication(sourceApp);

sourceApp->SetStartTime(Seconds(2.0));

sourceApp->SetStopTime(Seconds(10.0));

  1. Enable Tracing and Animation

Allow PCAP tracing and NetAnim to monitor the packet exchanges and envision the network.

wifiPhy.EnablePcapAll(“data_centric_simulation”);

AnimationInterface anim(“data_centric_simulation.xml”);

  1. Run the Simulation

Set the simulation stop time and run the simulation.

Simulator::Stop(Seconds(20.0));

Simulator::Run();

Simulator::Destroy();

  1. Full Example Script for Data-Centric Simulation

The followings is a comprehensive script for replicating a basic data-centric protocol using Directed Diffusion concepts in NS3.

#include “ns3/core-module.h”

#include “ns3/network-module.h”

#include “ns3/internet-module.h”

#include “ns3/wifi-module.h”

#include “ns3/mobility-module.h”

#include “ns3/applications-module.h”

#include “ns3/netanim-module.h”

using namespace ns3;

class SinkApplication : public Application

{

public:

SinkApplication() {}

virtual ~SinkApplication() {}

void Setup(Ptr<Socket> socket, Address address, uint32_t packetSize, uint32_t nPackets, Time interPacketInterval)

{

m_socket = socket;

m_peer = address;

m_packetSize = packetSize;

m_nPackets = nPackets;

m_interval = interPacketInterval;

m_packetsSent = 0;

}

private:

virtual void StartApplication(void)

{

m_socket->Bind();

SendPacket();

}

void SendPacket()

{

Ptr<Packet> packet = Create<Packet>(m_packetSize);

m_socket->SendTo(packet, 0, m_peer);

++m_packetsSent;

if (m_packetsSent < m_nPackets)

{

Simulator::Schedule(m_interval, &SinkApplication::SendPacket, this);

}

}

Ptr<Socket> m_socket;

Address m_peer;

uint32_t m_packetSize;

uint32_t m_nPackets;

Time m_interval;

uint32_t m_packetsSent;

};

class SourceApplication : public Application

{

public:

SourceApplication() {}

virtual ~SourceApplication() {}

void Setup(Ptr<Socket> socket, Address address)

{

m_socket = socket;

m_peer = address;

}

private:

virtual void StartApplication(void)

{

m_socket->Bind();

m_socket->SetRecvCallback(MakeCallback(&SourceApplication::HandleRead, this));

}

void HandleRead(Ptr<Socket> socket)

{

Ptr<Packet> packet = socket->Recv();

// Process interest query and send response

Ptr<Packet> response = Create<Packet>(1024);  // Send data if query matches

socket->SendTo(response, 0, m_peer);

}

Ptr<Socket> m_socket;

Address m_peer;

};

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

{

NodeContainer nodes;

nodes.Create(6);  // Create 6 nodes

YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default();

YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default();

wifiPhy.SetChannel(wifiChannel.Create());

WifiHelper wifi;

wifi.SetStandard(WIFI_PHY_STANDARD_80211g);

wifi.SetRemoteStationManager(“ns3::AarfWifiManager”);

WifiMacHelper wifiMac;

wifiMac.SetType(“ns3::AdhocWifiMac”);

NetDeviceContainer devices = wifi.Install(wifiPhy, wifiMac, nodes);

InternetStackHelper internet;

internet.Install(nodes);

Ipv4AddressHelper address;

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

Ipv4InterfaceContainer interfaces = address.Assign(devices);

MobilityHelper mobility;

mobility.SetPositionAllocator(“ns3::GridPositionAllocator”,

“MinX”, DoubleValue(0.0),

“MinY”, DoubleValue(0.0),

“DeltaX”, DoubleValue(100.0),

“DeltaY”, DoubleValue(100.0),

“GridWidth”, UintegerValue(3),

“LayoutType”, StringValue(“RowFirst”));

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

mobility.Install(nodes);

Ptr<Socket> sinkSocket = Socket::CreateSocket(nodes.Get(0), UdpSocketFactory::GetTypeId());

Address sinkBroadcast = InetSocketAddress(Ipv4Address(“10.1.1.255”), 8080);

Ptr<SinkApplication> sinkApp = CreateObject<SinkApplication>();

sinkApp->Setup(sinkSocket, sinkBroadcast, 1024, 100, Seconds(1.0));

nodes.Get(0)->AddApplication(sinkApp);

sinkApp->SetStartTime(Seconds(1.0));

sinkApp->SetStopTime(Seconds(10.0));

Ptr<Socket> sourceSocket = Socket::CreateSocket(nodes.Get(5), UdpSocketFactory::GetTypeId());

Address sinkAddress = InetSocketAddress(interfaces.GetAddress(0), 8080);

Ptr<SourceApplication> sourceApp = CreateObject<SourceApplication>();

sourceApp->Setup(sourceSocket, sinkAddress);

nodes.Get(5)->AddApplication(sourceApp);

sourceApp->SetStartTime(Seconds(2.0));

sourceApp->SetStopTime(Seconds(10.0));

wifiPhy.EnablePcapAll(“data_centric_simulation”);

AnimationInterface anim(“data_centric_simulation.xml”);

Simulator::Stop(Seconds(20.0));

Simulator::Run();

Simulator::Destroy();

return 0;

}

  1. Running the Simulation
  • Build and run the script using NS3’s waf build system:

./waf build

./waf –run data_centric_simulation

  1. Analyzing Results
  • PCAP Traces: The .pcap files are generated in the course of the simulation can be investigated using tools such as Wireshark to monitor the interest propagation and data transmission.
  • NetAnim: We can envision the node interactions in NetAnim using the .xml file generated during the simulation.
  1. Extending the Simulation

We can expand this simple data-centric protocol simulation by:

  • Inserting the aggregation at intermediate nodes to replicate data aggregation.
  • Mimicking a sensor network with several sources and sinks.
  • Executing energy-efficient communication in which nodes are decide to send data according to the obtainable energy.

We systematically carried out a detailed process on data centric protocol, with simulation and examine done through the simulation tool NS3. Additional informations regarding this topic will be shared, if required.

Phdprime.com will  assist you with the network assessment for your initiatives. To simulate Data Centric Protocol Projects with NS3, all you need to do is send us an email with all the research details you have. We’ll get back to you right away and provide you with the best possible results.

Opening Time

9:00am

Lunch Time

12:30pm

Break Time

4:00pm

Closing Time

6:30pm

  • award1
  • award2