To implement the Dynamic source routing (DSR) protocol in ns3 consists by using the DSR module that delivered by ns3. Implementation of DSR protocol in ns3 are handled by our developers in a well-mannered way. Here are the procedures to help you to setup and run the process using the DSR protocol in ns3 environment:
Step-by-step Implementation
- Set Up Your Environment
Make sure ns3 is installed. If, not done then installed it from official website.
- Create a New ns-3 Script
Create a new simulation script in the scratch directory of your ns-3 installation. For example, you can create a file named dsr-simulation.cc.
cd ns-3.xx
cd scratch
touch dsr-simulation.cc
3. Include Necessary Headers
In your dsr-simulation.cc file, include the necessary headers for your simulation.
#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/dsr-module.h”
using namespace ns3;
4. Set Up the Network Topology
Describe the network topology and then create a topology with three nodes that interconnects with a line.
int main (int argc, char *argv[])
{
CommandLine cmd;
cmd.Parse (argc, argv);
NodeContainer nodes;
nodes.Create (3);
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 internet;
DsrHelper dsr;
DsrMainHelper dsrMain;
internet.Install (nodes);
dsrMain.Install (dsr, nodes);
Ipv4AddressHelper address;
address.SetBase (“10.1.1.0”, “255.255.255.0”);
Ipv4InterfaceContainer interfaces = address.Assign (devices.Get (0));
interfaces.Add (address.Assign (devices.Get (1)));
address.SetBase (“10.1.2.0”, “255.255.255.0”);
interfaces.Add (address.Assign (devices.Get (2)));
// Set up applications (e.g., a UDP echo server and client)
UdpEchoServerHelper echoServer (9);
ApplicationContainer serverApps = echoServer.Install (nodes.Get (2));
serverApps.Start (Seconds (1.0));
serverApps.Stop (Seconds (10.0));
UdpEchoClientHelper echoClient (interfaces.GetAddress (2), 9);
echoClient.SetAttribute (“MaxPackets”, UintegerValue (1));
echoClient.SetAttribute (“Interval”, TimeValue (Seconds (1.0)));
echoClient.SetAttribute (“PacketSize”, UintegerValue (1024));
ApplicationContainer clientApps = echoClient.Install (nodes.Get (0));
clientApps.Start (Seconds (2.0));
clientApps.Stop (Seconds (10.0));
Simulator::Run ();
Simulator::Destroy ();
return 0;
}
5. Configure the DSR Protocol
In this example, the DSR protocol is installed and configured using the DsrHelper and DsrMainHelper classes. These classes configure the DSR routing protocol on the nodes.
6. Build and Run the Simulation
After writing your script, you need to build and run it
./waf build
./waf –run scratch/dsr-simulation
7. Analyze the Results
Based on your requirements we evaluate the performance and we can add logging or tracing to notice the activities of the DSR protocol.
Example Script
At this direction, we provide the sample references to complete the script for DSR protocol in ns3:
#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/dsr-module.h”
using namespace ns3;
int main (int argc, char *argv[])
{
CommandLine cmd;
cmd.Parse (argc, argv);
NodeContainer nodes;
nodes.Create (3);
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 internet;
DsrHelper dsr;
DsrMainHelper dsrMain;
internet.Install (nodes);
dsrMain.Install (dsr, nodes);
Ipv4AddressHelper address;
address.SetBase (“10.1.1.0”, “255.255.255.0”);
Ipv4InterfaceContainer interfaces = address.Assign (devices.Get (0));
interfaces.Add (address.Assign (devices.Get (1)));
address.SetBase (“10.1.2.0”, “255.255.255.0”);
interfaces.Add (address.Assign (devices.Get (2)));
// Set up applications (e.g., a UDP echo server and client)
UdpEchoServerHelper echoServer (9);
ApplicationContainer serverApps = echoServer.Install (nodes.Get (2));
serverApps.Start (Seconds (1.0));
serverApps.Stop (Seconds (10.0));
UdpEchoClientHelper echoClient (interfaces.GetAddress (2), 9);
echoClient.SetAttribute (“MaxPackets”, UintegerValue (1));
echoClient.SetAttribute (“Interval”, TimeValue (Seconds (1.0)));
echoClient.SetAttribute (“PacketSize”, UintegerValue (1024));
ApplicationContainer clientApps = echoClient.Install (nodes.Get (0));
clientApps.Start (Seconds (2.0));
clientApps.Stop (Seconds (10.0));
Simulator::Run ();
Simulator::Destroy ();
return 0;
}
Overall, we had implemented the DSR protocol to analyse the routing performance in ns3 environment. We provide the further support on comparative analysis about DSR protocol that adapts in diverse surroundings.