How to Start DSR Protocol Projects Using NS3
To start Dynamic Source Routing (DSR) protocol in NS3, which is a reactive routing protocol for mobile ad hoc networks (MANETs) that NS3 completely supports. To configure a DSR-based project within NS3, we can be utilized the dsr-helper module. Below is a simple method to start and simulate a DSR project in NS3.
Steps to Start DSR Protocol Projects in NS3
- Install NS3
We adhere to below steps to configure it (assuming a Linux environment), if we doesn’t already installed NS3:
# Update and install necessary dependencies
sudo apt update
sudo apt install -y gcc g++ python3 python3-dev cmake libgsl-dev libsqlite3-dev
# Clone NS-3 repository
git clone https://gitlab.com/nsnam/ns-3-dev.git ns-3
cd ns-3
# Configure and build NS-3
./ns3 configure –enable-examples –enable-tests
./ns3 build
- Create a New Script for DSR Simulation
- In the NS3’s scratch folder, we make a new file named dsr_simulation.cc.
- We can utilize below code like an outline configuring a simple simulation to utilize the DSR protocol:
#include “ns3/core-module.h”
#include “ns3/network-module.h”
#include “ns3/internet-module.h”
#include “ns3/mobility-module.h”
#include “ns3/dsr-module.h”
#include “ns3/wifi-module.h”
#include “ns3/ipv4-static-routing-helper.h”
using namespace ns3;
int main(int argc, char *argv[]) {
// Enable DSR logging
LogComponentEnable(“DsrRoutingProtocol”, LOG_LEVEL_INFO);
// Create nodes for the MANET
NodeContainer nodes;
nodes.Create(10); // Example with 10 nodes
// Set up mobility for the nodes
MobilityHelper mobility;
mobility.SetPositionAllocator(“ns3::RandomRectanglePositionAllocator”,
“X”, StringValue(“ns3::UniformRandomVariable[Min=0.0|Max=100.0]”),
“Y”, StringValue(“ns3::UniformRandomVariable[Min=0.0|Max=100.0]”));
mobility.SetMobilityModel(“ns3::RandomWaypointMobilityModel”,
“Speed”, StringValue(“ns3::UniformRandomVariable[Min=1.0|Max=5.0]”),
“Pause”, StringValue(“ns3::ConstantRandomVariable[Constant=2.0]”));
mobility.Install(nodes);
// Configure WiFi for ad hoc communication
WifiHelper wifi;
wifi.SetStandard(WIFI_STANDARD_80211b);
YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default();
YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default();
wifiPhy.SetChannel(wifiChannel.Create());
WifiMacHelper wifiMac;
wifiMac.SetType(“ns3::AdhocWifiMac”);
NetDeviceContainer devices = wifi.Install(wifiPhy, wifiMac, nodes);
// Install Internet stack with DSR routing
InternetStackHelper internet;
DsrMainHelper dsrMainHelper;
DsrHelper dsrHelper;
internet.Install(nodes);
dsrMainHelper.Install(dsrHelper, nodes);
// Assign IP addresses to the network interfaces
Ipv4AddressHelper ipv4;
ipv4.SetBase(“10.1.1.0”, “255.255.255.0”);
Ipv4InterfaceContainer interfaces = ipv4.Assign(devices);
// Set up a UDP echo server and client for testing DSR
UdpEchoServerHelper echoServer(9);
ApplicationContainer serverApps = echoServer.Install(nodes.Get(0));
serverApps.Start(Seconds(1.0));
serverApps.Stop(Seconds(10.0));
UdpEchoClientHelper echoClient(interfaces.GetAddress(0), 9);
echoClient.SetAttribute(“MaxPackets”, UintegerValue(1));
echoClient.SetAttribute(“Interval”, TimeValue(Seconds(1.0)));
echoClient.SetAttribute(“PacketSize”, UintegerValue(1024));
ApplicationContainer clientApps = echoClient.Install(nodes.Get(9));
clientApps.Start(Seconds(2.0));
clientApps.Stop(Seconds(10.0));
// Run the simulation
Simulator::Stop(Seconds(10.0));
Simulator::Run();
Simulator::Destroy();
return 0;
}
In this code:
-
- Nodes: We make 10 nodes to denote the devices within an ad hoc network.
- Mobility Model: The RandomWaypointMobilityModel configures random movement for nodes to replicate a mobile environment normal for MANETs.
- WiFi Configuration: We utilise IEEE 802.11b for ad hoc interaction along with AdhocWifiMac for MAC settings.
- DSR Routing: Now, we utilize DsrMainHelper and DsrHelper to install the DSR routing protocol on each node.
- Application Setup: A basic UDP echo server and client are set up, analysing the connectivity to utilize the DSR protocol.
- Build and Run the Simulation
- We can store dsr_simulation.cc in the scratch directory of NS3.
- Go to a terminal, pass through to the NS3 directory, and then construct the script:
./ns3 build
- Run the simulation:
./ns3 run scratch/dsr_simulation
- Analyze DSR Results
DSR logs will be offered data regarding route discovery and maintenance. We can be monitored how DSR determines and sustains the routes since nodes travel and interact. For DSR, allow in-depth logging:
LogComponentEnable(“DsrRoutingProtocol”, LOG_LEVEL_ALL);
It permits to monitor the route requests, route replies, and data packet forwarding events within further detail.
Experimentation Suggestions
We can prolong this simple DSR configuration:
- Vary Node Count and Mobility: Experiment the performance of DSR including additional nodes or various mobility models, monitoring the how DSR scales.
- Adjust Packet Transmission Rates: It maximizes traffic load learning the behaviour of DSR in higher network demand.
- Network Performance Analysis: Estimate network performance parameters such as packet delivery ratio, latency, and throughput, measuring the effectiveness of DSR.
We had presented step-by-step techniques and practical code snippets to effectively simulate and estimate the DSR Protocol projects using NS3 tool. We will also share additional insights on this topic.
The team at phdprojects.org consists of highly skilled and knowledgeable writers and developers dedicated to ensuring your projects are completed punctually. We specialize in configuring and replicating DSR Protocol scenarios. When embarking on DSR Protocol projects using NS3, it is essential to engage experts for optimal results. We emphasize the importance of selecting the right topic by sharing a wealth of innovative ideas.