Ns3 Projects for B.E/B.Tech M.E/M.Tech PhD Scholars.  Phone-Number:9790238391   E-mail: ns3simulation@gmail.com

How to Implement DTN data management in ns3

To implement Delay-Tolerant Networking (DTN) data management in ns3, we need to simulate a network. In that network using intermediate nodes the data packets, or “bundles,” should be stored, carried, and forwarded, even if the network is intermittently connected it has to perform the functionalities until they reach their destination. The following steps will guide on how to implement DTN data management with store-carry-forward functionality.

Step-by-step guide on implementing DTN data management in ns3:

Step 1: Set Up the Simulation Environment

Make sure ns3 installed on the system.

Step 2: Create the Network Topology

Create a basic network topology using ns3 with multiple nodes. For this example, we had created three nodes where Node A sends data to Node C via Node B, which acts as an intermediate node.

Step 3: Define the DTN Application

Create a custom DTN application that implements the store-carry-forward functionality.

Step 4: Write the Script

An example provided here on how to create and configure a network topology in ns3 with a basic DTN application:

  1. Create a New File:
    • Save the following script as dtn-data-management.cc in the scratch directory of ns3 installation.

#include “ns3/core-module.h”

#include “ns3/network-module.h”

#include “ns3/internet-module.h”

#include “ns3/point-to-point-module.h”

#include “ns3/applications-module.h”

#include “ns3/mobility-module.h”

using namespace ns3;

NS_LOG_COMPONENT_DEFINE (“DtnDataManagementExample”);

class DtnApplication : public Application

{

public:

DtnApplication ();

virtual ~DtnApplication ();

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

void AddIntermediateNode (Ptr<Node> node);

protected:

virtual void StartApplication (void);

virtual void StopApplication (void);

private:

void SendPacket ();

void ReceivePacket (Ptr<Socket> socket);

Ptr<Socket> m_socket;

Address m_peer;

uint32_t m_packetSize;

uint32_t m_nPackets;

Time m_interval;

uint32_t m_sent;

std::vector<Ptr<Packet>> m_buffer;

std::vector<Ptr<Node>> m_intermediateNodes;

};

DtnApplication::DtnApplication ()

: m_socket (0),

m_packetSize (0),

m_nPackets (0),

m_sent (0)

{

}

DtnApplication::~DtnApplication ()

{

m_socket = 0;

}

void

DtnApplication::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;

}

void

DtnApplication::AddIntermediateNode (Ptr<Node> node)

{

m_intermediateNodes.push_back (node);

}

void

DtnApplication::StartApplication (void)

{

m_socket->Bind ();

m_socket->Connect (m_peer);

m_socket->SetRecvCallback (MakeCallback (&DtnApplication::ReceivePacket, this));

SendPacket ();

}

void

DtnApplication::StopApplication (void)

{

if (m_socket)

{

m_socket->Close ();

}

}

void

DtnApplication::SendPacket ()

{

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

m_buffer.push_back (packet);

if (++m_sent < m_nPackets)

{

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

}

for (auto &node : m_intermediateNodes)

{

Ptr<Socket> socket = Socket::CreateSocket (node, UdpSocketFactory::GetTypeId ());

socket->Bind ();

socket->Connect (InetSocketAddress (Ipv4Address::ConvertFrom (m_peer), 9));

socket->Send (packet);

}

m_socket->Send (packet);

}

void

DtnApplication::ReceivePacket (Ptr<Socket> socket)

{

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

NS_LOG_UNCOND (“Received packet of size ” << packet->GetSize ());

if (socket->GetNode () == m_intermediateNodes.back ())

{

m_socket->Send (packet);

}

}

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

{

CommandLine cmd;

cmd.Parse (argc, argv);

NodeContainer nodes;

nodes.Create (3); // A, B, C

PointToPointHelper pointToPoint;

pointToPoint.SetDeviceAttribute (“DataRate”, StringValue (“5Mbps”));

pointToPoint.SetChannelAttribute (“Delay”, StringValue (“2ms”));

NetDeviceContainer devicesAB, devicesBC;

devicesAB = pointToPoint.Install (nodes.Get (0), nodes.Get (1)); // A to B

devicesBC = pointToPoint.Install (nodes.Get (1), nodes.Get (2)); // B to C

InternetStackHelper stack;

stack.Install (nodes);

Ipv4AddressHelper address;

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

Ipv4InterfaceContainer interfacesAB = address.Assign (devicesAB);

 

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

Ipv4InterfaceContainer interfacesBC = address.Assign (devicesBC);

// Set up mobility

MobilityHelper mobility;

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

mobility.Install (nodes);

nodes.Get (0)->GetObject<MobilityModel> ()->SetPosition (Vector (0.0, 0.0, 0.0));

nodes.Get (1)->GetObject<MobilityModel> ()->SetPosition (Vector (50.0, 0.0, 0.0));

nodes.Get (2)->GetObject<MobilityModel> ()->SetPosition (Vector (100.0, 0.0, 0.0));

// Set up applications

uint32_t packetSize = 1024;

uint32_t nPackets = 10;

Time interPacketInterval = Seconds (1.0);

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

InetSocketAddress local = InetSocketAddress (Ipv4Address::GetAny (), 9);

recvSink->Bind (local);

recvSink->SetRecvCallback (MakeCallback (&DtnApplication::ReceivePacket, DynamicCast<DtnApplication> (nodes.Get (2)->GetApplication (0))));

 

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

Ptr<DtnApplication> app = CreateObject<DtnApplication> ();

app->Setup (source, InetSocketAddress (interfacesBC.GetAddress (1), 9), packetSize, nPackets, interPacketInterval);

app->AddIntermediateNode (nodes.Get (1)); // B as intermediate node

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

app->SetStartTime (Seconds (2.0));

app->SetStopTime (Seconds (20.0));

Simulator::Run ();

Simulator::Destroy ();

return 0;

}

Explanation:

  1. Create Nodes and Network:
    • Create three nodes (A, B, and C) and connect them using point-to-point links.
    • Install the Internet stack on the nodes.
    • Assign IP addresses to the devices.
  2. Define DTN Application:
    • Create a DtnApplication class that implements the store-carry-forward mechanism.
    • The application sends packets, stores them in a buffer, and forwards them to intermediate nodes.
    • The SendPacket function creates packets and sends them to intermediate nodes and the destination.
    • The ReceivePacket function handles incoming packets and forwards them if necessary.
  3. Install and Configure the Application:
    • Create sockets for sending and receiving.
    • Install the DtnApplication on the source node (A).
    • Configure the application with the necessary parameters, such as packet size, number of packets, and inter-packet interval.
    • Add the intermediate node (B) to the application.
  4. Run the Simulation:
    • Schedule the start and stop times for the application.
    • Run the simulation and log the results.

Step 4: Compile and Run the Script

  1. Save the script as dtn-data-management.cc in the scratch directory of ns3 installation.
  2. Compile the script using the following commands:

./waf configure

./waf build

./waf –run dtn-data-management

Step 5: Analyze the Results

By looking at the logs to verify the behavior of the DTN data management application, we can analyze the results after the simulation process.

From the example and steps given we came to an conclusion that we can implement the DTN Delay-Tolerant Networking by using intermediate node in which three nodes are connected one node act as an intermediate node for sending the data through it.

Get best and original project ideas and coding assistance for your DTN data management project. Our team is equipped with the essential tools to help you execute your work. Reach out to us for unparalleled support and achieve the implementation of DTN data management in ns3 for your projects through ns3simulation.com.