How to Start DSR Routing Projects Using NS3
To start Dynamic Source Routing (DSR) using NS3, it is a reactive protocol for ad-hoc networks. It utilizes source routing in which the complete path is contained within the packet header. In NS3, this protocol is executed, permitting to make the simulations for mobile ad-hoc networks (MANETs).
Steps to Start DSR Routing Projects in NS3
- Set Up NS3
- Install NS3:
sudo apt update
sudo apt install g++ python3 git cmake
git clone https://gitlab.com/nsnam/ns-3-dev.git
cd ns-3-dev
./waf configure
./waf build
- Verify Installation:
./waf –run scratch/my-first
- Plan Your DSR Simulation
- Define the Topology:
- We describe the topology that nodes are organised in a linear, grid, or random topology.
- Add Mobility:
- Replicate the node movement within the network to utilize mobility models.
- Configure DSR Protocol:
- Make use of DsrHelper, DSR can be allowed within NS3.
- Simulate Traffic:
- We make traffic using UDP or TCP applications.
- Basic DSR Example
Here’s an example explains a basic DSR simulation including mobile ad-hoc network.
Example Code:
#include “ns3/core-module.h”
#include “ns3/network-module.h”
#include “ns3/mobility-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() {
// Create nodes
NodeContainer nodes;
nodes.Create(5);
// Configure mobility
MobilityHelper mobility;
mobility.SetPositionAllocator(“ns3::GridPositionAllocator”,
“MinX”, DoubleValue(0.0),
“MinY”, DoubleValue(0.0),
“DeltaX”, DoubleValue(50.0),
“DeltaY”, DoubleValue(50.0),
“GridWidth”, UintegerValue(3),
“LayoutType”, StringValue(“RowFirst”));
mobility.SetMobilityModel(“ns3::RandomWalk2dMobilityModel”,
“Bounds”, RectangleValue(Rectangle(-100, 100, -100, 100)));
mobility.Install(nodes);
// Install the internet stack with DSR
InternetStackHelper stack;
DsrMainHelper dsrMain;
DsrHelper dsrHelper;
stack.Install(nodes);
dsrMain.Install(dsrHelper, nodes);
// Assign IP addresses
Ipv4AddressHelper address;
address.SetBase(“10.1.0.0”, “255.255.255.0”);
Ipv4InterfaceContainer interfaces = address.Assign(nodes);
// Create traffic
uint16_t port = 9;
UdpEchoServerHelper echoServer(port);
ApplicationContainer serverApps = echoServer.Install(nodes.Get(4)); // Node 4 as server
serverApps.Start(Seconds(1.0));
serverApps.Stop(Seconds(10.0));
UdpEchoClientHelper echoClient(interfaces.GetAddress(4), port); // Node 0 as client
echoClient.SetAttribute(“MaxPackets”, UintegerValue(5));
echoClient.SetAttribute(“Interval”, TimeValue(Seconds(2.0)));
echoClient.SetAttribute(“PacketSize”, UintegerValue(1024));
ApplicationContainer clientApps = echoClient.Install(nodes.Get(0));
clientApps.Start(Seconds(2.0));
clientApps.Stop(Seconds(10.0));
// Run simulation
Simulator::Run();
Simulator::Destroy();
return 0;
}
- Key Components of the Code
- Node Creation:
- Nodes signify devices within the ad-hoc network.
- Mobility:
- Nodes are allocated an arbitrary or predefined movement patterns to utilize MobilityHelper.
- DSR Configuration:
- Allow DSR protocol to utilize DsrHelper and DsrMainHelper.
- Traffic Generation:
- Make traffic to use UDP Echo or other applications and then estimate the routing performance.
- Advanced Features
Adding Mobility Models
mobility.SetMobilityModel(“ns3::ConstantVelocityMobilityModel”);
nodes.Get(0)->GetObject<ConstantVelocityMobilityModel>()->SetVelocity(Vector(5.0, 0.0, 0.0));
Monitoring Packet Flow
Allow PCAP tracing to examine the packets:
AsciiTraceHelper ascii;
pointToPoint.EnableAsciiAll(ascii.CreateFileStream(“dsr.tr”));
pointToPoint.EnablePcapAll(“dsr”);
Logging
Facilitate logging for in-depth protocol behavior:
NS_LOG=”DsrHelper” ./waf –run scratch/dsr-example
We demonstrated the valuable insights that show how to implement and simulate the DSR Routing Projects in NS3 environment. If you require extra information and detailed procedure about this topic, we will share it.
We are dedicated to assisting you in simulating your projects and offering you the most effective ideas and topics for your endeavors. Should you encounter difficulties in starting DSR Routing Projects utilizing the NS3 tool, we recommend reaching out to the researchers at phdprojects.org for support. Our commitment lies in executing your projects with remarkable efficiency and outstanding quality. We specialize in simulations for mobile ad-hoc networks (MANETs).