How to Develop DTN Protocols Projects Using NS3

To Develop DTN (Delay-Tolerant Network) Protocols Projects in NS3, we have to follow the given stepwise approach.

Steps to Develop DTN Protocols Projects in NS3

  1. Introduction to DTN (Delay-Tolerant Networking)

A Delay-Tolerant Network (DTN) is frequently used for environments where:

High latency and intermittent connectivity happen.

Store-carry-forward routing is leveraged rather than traditional packet switching.

Opportunistic interaction allows data transfer if nodes obtain the range.

  1. Setting Up NS3 for DTN

(a) Install NS3

Initially, we should install NS3 environment.

sudo apt update

sudo apt install git g++ python3 python3-pip cmake

git clone https://gitlab.com/nsnam/ns-3-dev.git

cd ns-3-dev

./ns3 configure –enable-examples –enable-tests

./ns3 build

  1. Implementing DTN in NS3

NS3 doesn’t offer inherent support for DTN module thus we can:

  1. We make a DTN routing protocol class.
  2. Execute the store-carry-forward logic.
  3. Replicate DTN within a mobility scenario.

Step 1: Create a DTN Routing Class

We will design a DTN Routing class as dtn-routing.h

#ifndef DTN_ROUTING_H

#define DTN_ROUTING_H

#include “ns3/ipv4-routing-protocol.h”

#include “ns3/node-container.h”

#include “ns3/ipv4-route.h”

#include “ns3/packet.h”

#include “ns3/socket.h”

#include “ns3/timer.h”

#include <queue>

class DtnRouting : public ns3::Ipv4RoutingProtocol {

public:

static ns3::TypeId GetTypeId(void);

DtnRouting();

virtual ~DtnRouting();

virtual ns3::Ptr<ns3::Ipv4Route> RouteOutput(

ns3::Ptr<ns3::Packet> packet,

const ns3::Ipv4Header &header,

ns3::Ptr<ns3::NetDevice> oif,

ns3::Socket::SocketErrno &sockerr) override;

virtual bool RouteInput(

ns3::Ptr<const ns3::Packet> packet,

const ns3::Ipv4Header &header,

ns3::Ptr<const ns3::NetDevice> idev,

UnicastForwardCallback ucb,

MulticastForwardCallback mcb,

LocalDeliverCallback lcb,

ErrorCallback ecb) override;

void StorePacket(ns3::Ptr<ns3::Packet> packet);

void ForwardStoredPackets();

private:

std::queue<ns3::Ptr<ns3::Packet>> m_packetBuffer;

ns3::Timer m_forwardTimer;

};

#endif // DTN_ROUTING_H

Step 2: Implement Store-Carry-Forward Mechanism

We can generate the dtn-routing.cc using Store-Carry-Forward techniques

#include “dtn-routing.h”

#include “ns3/log.h”

#include “ns3/simulator.h”

NS_LOG_COMPONENT_DEFINE(“DtnRouting”);

NS_OBJECT_ENSURE_REGISTERED(DtnRouting);

ns3::TypeId DtnRouting::GetTypeId(void) {

static ns3::TypeId tid = ns3::TypeId(“ns3::DtnRouting”)

.SetParent<ns3::Ipv4RoutingProtocol>()

.SetGroupName(“Internet”);

return tid;

}

DtnRouting::DtnRouting() {

m_forwardTimer.SetFunction(&DtnRouting::ForwardStoredPackets, this);

m_forwardTimer.Schedule(ns3::Seconds(5.0));

}

DtnRouting::~DtnRouting() {}

ns3::Ptr<ns3::Ipv4Route> DtnRouting::RouteOutput(

ns3::Ptr<ns3::Packet> packet, const ns3::Ipv4Header &header,

ns3::Ptr<ns3::NetDevice> oif, ns3::Socket::SocketErrno &sockerr) {

NS_LOG_INFO(“DTN RouteOutput: Storing packet for later forwarding”);

StorePacket(packet);

return 0;

}

bool DtnRouting::RouteInput(

ns3::Ptr<const ns3::Packet> packet, const ns3::Ipv4Header &header,

ns3::Ptr<const ns3::NetDevice> idev,

UnicastForwardCallback ucb, MulticastForwardCallback mcb,

LocalDeliverCallback lcb, ErrorCallback ecb) {

NS_LOG_INFO(“DTN RouteInput: Received a packet, storing for forwarding”);

StorePacket(packet->Copy());

return true;

}

void DtnRouting::StorePacket(ns3::Ptr<ns3::Packet> packet) {

NS_LOG_INFO(“DTN Storing packet in buffer”);

m_packetBuffer.push(packet);

}

void DtnRouting::ForwardStoredPackets() {

if (!m_packetBuffer.empty()) {

NS_LOG_INFO(“DTN Forwarding stored packets”);

while (!m_packetBuffer.empty()) {

ns3::Ptr<ns3::Packet> packet = m_packetBuffer.front();

m_packetBuffer.pop();

// Logic to forward the packet when connectivity is available

}

}

m_forwardTimer.Schedule(ns3::Seconds(5.0));

}

Step 3: Integrate DTN into an NS-3 Simulation

After that, we have to make dtn-simulation.cc in NS3

#include “ns3/core-module.h”

#include “ns3/network-module.h”

#include “ns3/internet-module.h”

#include “ns3/mobility-module.h”

#include “dtn-routing.h”

using namespace ns3;

int main() {

NodeContainer nodes;

nodes.Create(5);

MobilityHelper mobility;

mobility.SetPositionAllocator(“ns3::GridPositionAllocator”,

“MinX”, DoubleValue(0.0),

“MinY”, DoubleValue(0.0),

“DeltaX”, DoubleValue(20.0),

“DeltaY”, DoubleValue(20.0),

“GridWidth”, UintegerValue(5),

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

mobility.SetMobilityModel(“ns3::RandomWalk2dMobilityModel”,

“Bounds”, RectangleValue(Rectangle(-50, 50, -50, 50)));

mobility.Install(nodes);

InternetStackHelper stack;

stack.Install(nodes);

Ptr<DtnRouting> dtnRouting = CreateObject<DtnRouting>();

nodes.Get(0)->AggregateObject(dtnRouting);

Ipv4AddressHelper address;

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

address.Assign(NetDeviceContainer());

Simulator::Run();

Simulator::Destroy();

return 0;

}

Step 4: Compile and Run the Simulation

📌 Compile

Now, we should build the simulation script

./waf

📌 Run

Execute it using NS3

./waf –run “scratch/dtn-simulation”

  1. Performance Evaluation for DTN

When execution is done, we can examine the performance using metrics like message delivery and delay with FlowMonitor:

Ptr<FlowMonitor> flowMonitor;

FlowMonitorHelper flowHelper;

flowMonitor = flowHelper.InstallAll();

Simulator::Stop(Seconds(100.0));

Simulator::Run();

flowMonitor->SerializeToXmlFile(“dtn_results.xml”, true, true);

📌 Run analysis

python3 analyze_results.py

  1. Example DTN Project Ideas in NS3

✅ 1. Epidemic Routing vs. Spray-and-Wait in DTN

  • Equate the performance of epidemic flooding vs. controlled message replication using DTN.

✅ 2. DTN for Space Communication

  • Execute the DTN protocols, which are utilised for interplanetary interaction.

✅ 3. Secure DTN Message Authentication

  • Avoid message tampering by integrating the cryptographic authentication.

✅ 4. Energy-Aware DTN for IoT Networks

  • Apply energy-efficient message forwarding in DTN for IoT networks.

✅ 5. DTN for Disaster Recovery Networks

  • We concentrate on how DTN will leverage for post-disaster emergency interaction.

Utilize the above explanation to acquire to know more about the DTN Protocols projects’ implementation and execution within NS3 environment using example projects ideas. It has captured the necessary details including the evaluation the outcomes. If you need extra details concerning this project, we will offer it.