How to Simulate DSR Protocol Projects Using NS3

To Simulate DSR Protocol Projects Using NS3  all you have to do is share with us all the research details you have by mail we will reply you immediately, get valuable and best outcomes from us. We have all the tools and resources to aid you in your work. without any hesitation you can approach us talk with pour experts to clarify your doubts. To simulate the DSR (Dynamic Source Routing) protocol within NS3, we follow these steps:

Steps to Simulate DSR Protocol Projects in NS3

  1. Install NS3

Make sure NS3 is installed on the computer. Unless, we download it from the NS3 official website and we follow the installation guide for the operating system.

  1. Check for DSR in NS3

NS3 contains the DSR as portion of the ad-hoc routing protocols. Thus, we don’t require to execute it from scratch. We just require to set up the simulation to utilise DSR.

  1. Create or Modify a Simulation Script

We can utilise the NS3 instance scripts or we make a new one. Then we follow these steps within the script to simulate DSR.

  1. Steps to Simulate DSR in NS3
  2. Include Necessary Headers:

We can require to consist of the suitable headers for DSR, mobility, and the network stack.

#include “ns3/core-module.h”

#include “ns3/network-module.h”

#include “ns3/internet-module.h”

#include “ns3/dsr-module.h”

#include “ns3/mobility-module.h”

#include “ns3/wifi-module.h”

#include “ns3/netanim-module.h”

  1. Set Up Nodes and Network:

Now, make the nodes and install the DSR routing protocol on them.

NodeContainer nodes;

nodes.Create(5);  // Create 5 nodes

// Set up Wifi devices

WifiHelper wifi;

wifi.SetStandard(WIFI_PHY_STANDARD_80211g);

WifiMacHelper wifiMac;

YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default();

YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default();

wifiPhy.SetChannel(wifiChannel.Create());

// Set ad-hoc wifi MAC protocol

wifiMac.SetType(“ns3::AdhocWifiMac”);

NetDeviceContainer devices = wifi.Install(wifiPhy, wifiMac, nodes);

// Install the Internet stack with DSR

InternetStackHelper stack;

DsrMainHelper dsrMainHelper;

DsrHelper dsrHelper;

stack.Install(nodes);

dsrMainHelper.Install(dsrHelper, nodes);

  1. Assign IP Addresses:

Allocate an IP addresses to the network interfaces of the nodes.

Ipv4AddressHelper ipv4;

ipv4.SetBase(“10.1.1.0”, “255.255.255.0”);

Ipv4InterfaceContainer interfaces = ipv4.Assign(devices);

  1. Configure Mobility:

Set the mobility model for the nodes that ascertains how the nodes are move.

MobilityHelper mobility;

mobility.SetPositionAllocator(“ns3::GridPositionAllocator”,

“MinX”, DoubleValue(0.0),

“MinY”, DoubleValue(0.0),

“DeltaX”, DoubleValue(5.0),

“DeltaY”, DoubleValue(10.0),

“GridWidth”, UintegerValue(3),

“LayoutType”, StringValue(“RowFirst”));

mobility.SetMobilityModel(“ns3::ConstantPositionMobilityModel”);

mobility.Install(nodes);

Also, we can utilise other mobility models such as RandomWaypointMobilityModel for dynamic movement.

  1. Set Up Traffic Generation:

Insert the traffic generation to analyse the routing protocol’s performance. Now, we use UDP Echo applications to generate traffic.

UdpEchoServerHelper echoServer(9);  // Port 9

ApplicationContainer serverApps = echoServer.Install(nodes.Get(1));  // Install server on node 1

serverApps.Start(Seconds(1.0));

serverApps.Stop(Seconds(10.0));

UdpEchoClientHelper echoClient(interfaces.GetAddress(1), 9);  // Server IP and port

echoClient.SetAttribute(“MaxPackets”, UintegerValue(1));

echoClient.SetAttribute(“Interval”, TimeValue(Seconds(1.0)));

echoClient.SetAttribute(“PacketSize”, UintegerValue(1024));

ApplicationContainer clientApps = echoClient.Install(nodes.Get(0));  // Install client on node 0

clientApps.Start(Seconds(2.0));

clientApps.Stop(Seconds(10.0));

  1. Run Simulation:

We can use the following commands to run the simulation and investigate outcomes.

Simulator::Stop(Seconds(10.0));

Simulator::Run();

Simulator::Destroy();

  1. Optional: Add Animation:

If we need to envision the simulation then we can use NetAnim to generate an animation file.

AnimationInterface anim(“dsr_simulation.xml”);  // Creates animation file

  1. Run the Simulation

After making the script then we compile and run it using waf:

./waf build

./waf –run <your_script>

  1. Analyze the Results

We can be investigated parameters such as packet delivery ratio, delay, or routing overhead. Also wee may generate trace files for further analysis using tools such as Wireshark.

Example Full Script

The following is a simple DSR example in NS3:

#include “ns3/core-module.h”

#include “ns3/network-module.h”

#include “ns3/internet-module.h”

#include “ns3/dsr-module.h”

#include “ns3/mobility-module.h”

#include “ns3/wifi-module.h”

#include “ns3/applications-module.h”

#include “ns3/netanim-module.h”

using namespace ns3;

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

NodeContainer nodes;

nodes.Create(5);  // Create 5 nodes

// Configure WiFi

WifiHelper wifi;

wifi.SetStandard(WIFI_PHY_STANDARD_80211g);

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

InternetStackHelper stack;

DsrMainHelper dsrMainHelper;

DsrHelper dsrHelper;

stack.Install(nodes);

dsrMainHelper.Install(dsrHelper, nodes);

// Assign IP addresses

Ipv4AddressHelper ipv4;

ipv4.SetBase(“10.1.1.0”, “255.255.255.0”);

Ipv4InterfaceContainer interfaces = ipv4.Assign(devices);

// Set up mobility model

MobilityHelper mobility;

mobility.SetPositionAllocator(“ns3::GridPositionAllocator”,

“MinX”, DoubleValue(0.0),

“MinY”, DoubleValue(0.0),

“DeltaX”, DoubleValue(5.0),

“DeltaY”, DoubleValue(10.0),

“GridWidth”, UintegerValue(3),

“LayoutType”, StringValue(“RowFirst”));

mobility.SetMobilityModel(“ns3::ConstantPositionMobilityModel”);

mobility.Install(nodes);

// Set up traffic (UDP Echo)

UdpEchoServerHelper echoServer(9);  // Port 9

ApplicationContainer serverApps = echoServer.Install(nodes.Get(1));

serverApps.Start(Seconds(1.0));

serverApps.Stop(Seconds(10.0));

UdpEchoClientHelper echoClient(interfaces.GetAddress(1), 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));

// Run simulation

Simulator::Stop(Seconds(10.0));

Simulator::Run();

Simulator::Destroy();

return 0;

}

This script configures a simple DSR protocol simulation in NS3. We can be extended and changed it based on the project requirements.

We performed a structured procedure on DSR Protocol projects, employing the simulation tool ns3 for its replicated and analysed. If you require, more comprehensive details we will be provided.

Opening Time

9:00am

Lunch Time

12:30pm

Break Time

4:00pm

Closing Time

6:30pm

  • award1
  • award2