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 protocols in ns3

To implement the delay tolerant networking (DTN) protocols in ns3 has various steps and DTN is made for scenarios where traditional IP networking protocol does not work well in space communication, mobile ad-hoc networks (MANETs) and other linked networks. Here is the procedure to help how to implement the DTN protocols in ns3.

Refer to the steps listed below, implementing the DTN protocols in ns3 are well tackled by our developers.

Prerequisites

  1. ns-3 Installation: Make certain ns-3 is installed in the computer.
  2. C++ Programming: Knowledge of C++ is required.
  3. Understanding of ns-3: Familiarity with ns-3 modules and basic simulation scripts.

Steps to Implement DTN Protocol

  1. Set up the Development Environment

Make sure ns3 is installed. If not then downloaded and installed it from official website.

  1. Create a New Protocol Module

Navigate to the src directory in ns-3 and create a new directory for your DTN protocol.

cd ns-3.XX/src

mkdir dtn

cd dtn

mkdir model helper test

3.      Define the Protocol Classes and Headers

Create header and implementation files for your protocol in the model directory.

dtn-routing-protocol.h

#ifndef DTN_ROUTING_PROTOCOL_H

#define DTN_ROUTING_PROTOCOL_H

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

#include “ns3/ipv4-address.h”

#include “ns3/timer.h”

#include “ns3/node.h”

#include “ns3/socket.h”

#include “ns3/net-device.h”

#include “ns3/packet.h”

#include “ns3/nstime.h”

namespace ns3 {

class DtnRoutingProtocol : public Ipv4RoutingProtocol {

public:

static TypeId GetTypeId (void);

DtnRoutingProtocol ();

virtual ~DtnRoutingProtocol ();

virtual void DoDispose (void);

// Implement required virtual functions from Ipv4RoutingProtocol

virtual Ptr<Ipv4Route> RouteOutput (Ptr<Packet> p, const Ipv4Header &header,

Ptr<NetDevice> oif,

Socket::SocketErrno &sockerr);

virtual bool RouteInput (Ptr<const Packet> p, const Ipv4Header &header,

Ptr<const NetDevice> idev,

UnicastForwardCallback ucb,

MulticastForwardCallback mcb,

LocalDeliverCallback lcb,

ErrorCallback ecb);

virtual void NotifyInterfaceUp (uint32_t interface);

virtual void NotifyInterfaceDown (uint32_t interface);

virtual void NotifyAddAddress (uint32_t interface, Ipv4InterfaceAddress address);

virtual void NotifyRemoveAddress (uint32_t interface, Ipv4InterfaceAddress address);

virtual void SetIpv4 (Ptr<Ipv4> ipv4);

private:

// Define internal states and methods here

Ptr<Ipv4> m_ipv4;

// Additional internal states and methods for DTN

};

} // namespace ns3

#endif // DTN_ROUTING_PROTOCOL_H

dtn-routing-protocol.cc

#include “dtn-routing-protocol.h”

#include “ns3/log.h”

#include “ns3/simulator.h”

#include “ns3/ipv4-header.h”

#include “ns3/ipv4-route.h”

#include “ns3/inet-socket-address.h”

#include “ns3/inet6-socket-address.h”

#include “ns3/udp-socket-factory.h”

#include “ns3/uinteger.h”

namespace ns3 {

NS_LOG_COMPONENT_DEFINE (“DtnRoutingProtocol”);

NS_OBJECT_ENSURE_REGISTERED (DtnRoutingProtocol);

TypeId DtnRoutingProtocol::GetTypeId (void) {

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

.SetParent<Ipv4RoutingProtocol> ()

.SetGroupName (“Internet”)

.AddConstructor<DtnRoutingProtocol> ();

return tid;

}

DtnRoutingProtocol::DtnRoutingProtocol () {

NS_LOG_FUNCTION (this);

}

DtnRoutingProtocol::~DtnRoutingProtocol () {

NS_LOG_FUNCTION (this);

}

void DtnRoutingProtocol::DoDispose () {

NS_LOG_FUNCTION (this);

Ipv4RoutingProtocol::DoDispose ();

}

Ptr<Ipv4Route> DtnRoutingProtocol::RouteOutput (Ptr<Packet> p, const Ipv4Header &header,

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

NS_LOG_FUNCTION (this << p << header << oif);

// Implement route output logic here

return Ptr<Ipv4Route> ();

}

bool DtnRoutingProtocol::RouteInput (Ptr<const Packet> p, const Ipv4Header &header,

Ptr<const NetDevice> idev, UnicastForwardCallback ucb,

MulticastForwardCallback mcb, LocalDeliverCallback lcb,

ErrorCallback ecb) {

NS_LOG_FUNCTION (this << p << header << idev);

// Implement route input logic here

return false;

}

void DtnRoutingProtocol::NotifyInterfaceUp (uint32_t interface) {

NS_LOG_FUNCTION (this << interface);

}

void DtnRoutingProtocol::NotifyInterfaceDown (uint32_t interface) {

NS_LOG_FUNCTION (this << interface);

}

void DtnRoutingProtocol::NotifyAddAddress (uint32_t interface, Ipv4InterfaceAddress address) {

NS_LOG_FUNCTION (this << interface << address);

}

void DtnRoutingProtocol::NotifyRemoveAddress (uint32_t interface, Ipv4InterfaceAddress address) {

NS_LOG_FUNCTION (this << interface << address);

}

void DtnRoutingProtocol::SetIpv4 (Ptr<Ipv4> ipv4) {

NS_LOG_FUNCTION (this << ipv4);

m_ipv4 = ipv4;

}

} // namespace ns3

4.     Integrate with ns-3 Build System

Update the wscript file in the src directory to include your new protocol.

src/dtn/wscript

def build(bld):

module = bld.create_ns3_module(‘dtn’, [‘core’, ‘network’, ‘internet’])

module.source = [

‘model/dtn-routing-protocol.cc’,

]

headers = bld(features=’ns3header’)

headers.module = ‘dtn’

headers.source = [

‘model/dtn-routing-protocol.h’,

]

5.      Create Helper and Test Classes

Create helper and test classes to facilitate the usage and testing of your protocol.

dtn-helper.h

#ifndef DTN_HELPER_H

#define DTN_HELPER_H

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

#include “ns3/node-container.h”

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

namespace ns3 {

class DtnHelper : public Ipv4RoutingHelper {

public:

DtnHelper ();

DtnHelper* Copy (void) const;

virtual Ptr<Ipv4RoutingProtocol> Create (Ptr<Node> node) const;

private:

};

} // namespace ns3

#endif // DTN_HELPER_H

dtn-helper.cc

#include “dtn-helper.h”

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

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

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

#include “ns3/log.h”

namespace ns3 {

NS_LOG_COMPONENT_DEFINE (“DtnHelper”);

DtnHelper::DtnHelper () {

}

DtnHelper* DtnHelper::Copy (void) const {

return new DtnHelper (*this);

}

Ptr<Ipv4RoutingProtocol> DtnHelper::Create (Ptr<Node> node) const {

Ptr<DtnRoutingProtocol> agent = CreateObject<DtnRoutingProtocol> ();

node->AggregateObject (agent);

return agent;

}

} // namespace ns3

  1. Build and Test
  • Rebuild ns-3 to include your new protocol.

./waf configure

./waf build

  • Create test scripts to verify the implementation of your protocol.

scratch/test-dtn.cc

#include “ns3/core-module.h”

#include “ns3/network-module.h”

#include “ns3/internet-module.h”

#include “ns3/dtn-helper.h”

#include “ns3/ipv4-static-routing-helper.h”

#include “ns3/ipv4-list-routing-helper.h”

using namespace ns3;

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

CommandLine cmd;

cmd.Parse (argc, argv);

NodeContainer nodes;

nodes.Create (2);

InternetStackHelper internet;

DtnHelper dtn;

Ipv4ListRoutingHelper list;

list.Add (dtn, 10);

internet.SetRoutingHelper (list);

internet.Install (nodes);

// Add additional setup code here

Simulator::Run ();

Simulator::Destroy ();

return 0;

}

7.      Run and Debug

Run your test script and debug any issues that arise.

./waf –run scratch/test-dtn

Finally, we discussed here about how to implement the DTN in ns3 simulation and we also provide further guidance about DTN network performs in your project with other simulation tools.