To implement Delay Tolerant networks in ns-3 are categorised by their capability to manage the long delays and intermediate connectivity. All types of implementation guidance are laid by us.
Now we are going to see the step by step procedures to implement the DTN in ns-3 environment.
Step-by-Step Guide to Implement DTNs in ns-3
- Install ns-3:
- Ensure ns-3 is installed. You can follow the installation instructions provided in previous responses.
- Create a Simulation Script:
- Create a new script file, e.g., dtn-simulation.cc.
- Include Necessary Headers:
#include “ns3/core-module.h”
#include “ns3/network-module.h”
#include “ns3/internet-module.h”
#include “ns3/point-to-point-module.h”
#include “ns3/mobility-module.h”
#include “ns3/applications-module.h”
#include <iostream>
#include <vector>
- Define the Main Function:
using namespace ns3;
int main (int argc, char *argv[])
{
LogComponentEnable (“UdpEchoClientApplication”, LOG_LEVEL_INFO);
LogComponentEnable (“UdpEchoServerApplication”, LOG_LEVEL_INFO);
- Set Up the Network Topology:
- Create nodes and configure network settings:
NodeContainer nodes;
nodes.Create (3); // Three nodes for simplicity
PointToPointHelper pointToPoint;
pointToPoint.SetDeviceAttribute (“DataRate”, StringValue (“5Mbps”));
pointToPoint.SetChannelAttribute (“Delay”, StringValue (“2ms”));
NetDeviceContainer devices;
devices = pointToPoint.Install (nodes.Get(0), nodes.Get(1));
devices.Add(pointToPoint.Install(nodes.Get(1), nodes.Get(2)));
InternetStackHelper stack;
stack.Install (nodes);
Ipv4AddressHelper address;
address.SetBase (“10.1.1.0”, “255.255.255.0”);
Ipv4InterfaceContainer interfaces = address.Assign (devices);
- Configure Mobility:
- Set up mobility models for nodes
MobilityHelper mobility;
mobility.SetMobilityModel (“ns3::ConstantPositionMobilityModel”);
mobility.Install (nodes);
Ptr<ConstantPositionMobilityModel> mob0 = nodes.Get(0)->GetObject<ConstantPositionMobilityModel>();
Ptr<ConstantPositionMobilityModel> mob1 = nodes.Get(1)->GetObject<ConstantPositionMobilityModel>();
Ptr<ConstantPositionMobilityModel> mob2 = nodes.Get(2)->GetObject<ConstantPositionMobilityModel>();
mob0->SetPosition(Vector(0.0, 0.0, 0.0));
mob1->SetPosition(Vector(50.0, 0.0, 0.0));
mob2->SetPosition(Vector(100.0, 0.0, 0.0));
- Install Applications:
- Set up a UDP echo server on the last node and a UDP echo client on the first node:
UdpEchoServerHelper echoServer (9);
ApplicationContainer serverApps = echoServer.Install (nodes.Get (2));
serverApps.Start (Seconds (1.0));
serverApps.Stop (Seconds (20.0));
UdpEchoClientHelper echoClient (interfaces.GetAddress (2), 9);
echoClient.SetAttribute (“MaxPackets”, UintegerValue (5));
echoClient.SetAttribute (“Interval”, TimeValue (Seconds (5.0)));
echoClient.SetAttribute (“PacketSize”, UintegerValue (1024));
ApplicationContainer clientApps = echoClient.Install (nodes.Get (0));
clientApps.Start (Seconds (2.0));
clientApps.Stop (Seconds (20.0));
- Simulate Disruption and Delay:
- Schedule events to simulate network disruptions and delays:
Simulator::Schedule (Seconds (5.0), &PointToPointNetDevice::SetLinkDown, DynamicCast<PointToPointNetDevice>(devices.Get(1)));
Simulator::Schedule (Seconds (10.0), &PointToPointNetDevice::SetLinkUp, DynamicCast<PointToPointNetDevice>(devices.Get(1)));
- Run the Simulation:
- Define the simulation stop time and start the simulator:
Simulator::Run ();
Simulator::Destroy ();
return 0;
Example Complete Script (dtn-simulation.cc):
Here we provide the instances to complete the script for delay tolerant network in ns-3 simulation environment
#include “ns3/core-module.h”
#include “ns3/network-module.h”
#include “ns3/internet-module.h”
#include “ns3/point-to-point-module.h”
#include “ns3/mobility-module.h”
#include “ns3/applications-module.h”
#include <iostream>
#include <vector>
using namespace ns3;
int main (int argc, char *argv[])
{
LogComponentEnable (“UdpEchoClientApplication”, LOG_LEVEL_INFO);
LogComponentEnable (“UdpEchoServerApplication”, LOG_LEVEL_INFO);
NodeContainer nodes;
nodes.Create (3); // Three nodes for simplicity
PointToPointHelper pointToPoint;
pointToPoint.SetDeviceAttribute (“DataRate”, StringValue (“5Mbps”));
pointToPoint.SetChannelAttribute (“Delay”, StringValue (“2ms”));
NetDeviceContainer devices;
devices = pointToPoint.Install (nodes.Get(0), nodes.Get(1));
devices.Add(pointToPoint.Install(nodes.Get(1), nodes.Get(2)));
InternetStackHelper stack;
stack.Install (nodes);
Ipv4AddressHelper address;
address.SetBase (“10.1.1.0”, “255.255.255.0”);
Ipv4InterfaceContainer interfaces = address.Assign (devices);
MobilityHelper mobility;
mobility.SetMobilityModel (“ns3::ConstantPositionMobilityModel”);
mobility.Install (nodes);
Ptr<ConstantPositionMobilityModel> mob0 = nodes.Get(0)->GetObject<ConstantPositionMobilityModel>();
Ptr<ConstantPositionMobilityModel> mob1 = nodes.Get(1)->GetObject<ConstantPositionMobilityModel>();
Ptr<ConstantPositionMobilityModel> mob2 = nodes.Get(2)->GetObject<ConstantPositionMobilityModel>();
mob0->SetPosition(Vector(0.0, 0.0, 0.0));
mob1->SetPosition(Vector(50.0, 0.0, 0.0));
mob2->SetPosition(Vector(100.0, 0.0, 0.0));
UdpEchoServerHelper echoServer (9);
ApplicationContainer serverApps = echoServer.Install (nodes.Get (2));
serverApps.Start (Seconds (1.0));
serverApps.Stop (Seconds (20.0));
UdpEchoClientHelper echoClient (interfaces.GetAddress (2), 9);
echoClient.SetAttribute (“MaxPackets”, UintegerValue (5));
echoClient.SetAttribute (“Interval”, TimeValue (Seconds (5.0)));
echoClient.SetAttribute (“PacketSize”, UintegerValue (1024));
ApplicationContainer clientApps = echoClient.Install (nodes.Get (0));
clientApps.Start (Seconds (2.0));
clientApps.Stop (Seconds (20.0));
Simulator::Schedule (Seconds (5.0), &PointToPointNetDevice::SetLinkDown, DynamicCast<PointToPointNetDevice>(devices.Get(1)));
Simulator::Schedule (Seconds (10.0), &PointToPointNetDevice::SetLinkUp, DynamicCast<PointToPointNetDevice>(devices.Get(1)));
Simulator::Run ();
Simulator::Destroy ();
return 0;
}
Explanation:
At this direction we are describe the explanation for the process for DTN are
- Network Configuration:
- Nodes are created, and point-to-point links are set up between them.
- Internet stack and IP addresses are configured for the nodes.
- Mobility:
- The mobility model is set to place the nodes at specific positions.
- Applications:
- A UDP echo server is installed on one node.
- A UDP echo client is installed on another node to simulate data communication.
- Simulating Disruption:
- Events are scheduled to simulate network disruptions by bringing the link down and back up.
At last, we discussed about the delay tolerant network in ns-3 environment and also we support all kinds of delay tolerant network.