How to Begin Implement a On Demand Protocol in NS3

On-Demand Routing Protocols dynamically has launched the routes as required rather than handling a comprehensive routing table for all times. Samples are contains the AODV (Ad hoc On-Demand Distance Vector) and DSR (Dynamic Source Routing). The ns3 has includes the built-in executions for together the AODV and DSR, creation of directly replicate the study for on-demand protocols.

Here’s how to implement an on-demand routing protocol in ns-3:

Steps to Begin Implement a On Demand Protocol in NS3

  1. Understand On-Demand Protocols
  • Key Features:
    • Routes are discovered after needed for using the Route Request (RREQ) and Route Reply (RREP) packets.
    • It decreases the routing overhead in networks by infrequent communication.
    • Model for dynamic and mobile ad hoc networks (MANETs).
  • Common Protocols:
    • AODV: Each node maintains a table of routes.
    • DSR: The DSR used in the source routing; route information is surrounded for the packet headers.
  1. Set up ns-3 Environment
  1. Install ns-3:

git clone https://gitlab.com/nsnam/ns-3-dev.git

cd ns-3-dev

./build.py

  1. Validate the installation:

./ns3 run hello-simulator

  1. Plan the Network Topology
  • Components:
    • The mobile nodes in which communicate are dynamically.
    • The congestion sources are creating the data for transmission.
  • Topology:
    • Mobility models uses replicate a dynamic network topology.
  1. Write the Simulation Script
  2. Include Necessary Headers

#include “ns3/core-module.h”

#include “ns3/network-module.h”

#include “ns3/internet-module.h”

#include “ns3/mobility-module.h”

#include “ns3/aodv-helper.h”    // Replace with dsr-helper.h for DSR

#include “ns3/applications-module.h”

  1. Define Nodes

ns3::NodeContainer nodes;

nodes.Create(10);  // Create 10 mobile nodes

  1. Set Up Mobility

ns3::MobilityHelper mobility;

// Random waypoint mobility model

mobility.SetMobilityModel(“ns3::RandomWaypointMobilityModel”,

“Speed”, ns3::StringValue(“ns3::UniformRandomVariable[Min=5.0|Max=20.0]”),

“Pause”, ns3::StringValue(“ns3::ConstantRandomVariable[Constant=2.0]”),

“PositionAllocator”, ns3::StringValue(“ns3::RandomRectanglePositionAllocator”));

 

mobility.SetPositionAllocator(“ns3::RandomRectanglePositionAllocator”,

“X”, ns3::StringValue(“ns3::UniformRandomVariable[Min=0.0|Max=500.0]”),

“Y”, ns3::StringValue(“ns3::UniformRandomVariable[Min=0.0|Max=500.0]”));

mobility.Install(nodes);

  1. Set Up Wireless Communication

ns3::WifiHelper wifi;

wifi.SetStandard(ns3::WIFI_PHY_STANDARD_80211g);

ns3::WifiMacHelper mac;

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

ns3::WifiPhyHelper phy = ns3::WifiPhyHelper::Default();

phy.SetChannel(ns3::YansWifiChannelHelper::Default().Create());

ns3::NetDeviceContainer devices = wifi.Install(phy, mac, nodes);

  1. Install the On-Demand Routing Protocol
  2. AODV Example

ns3::AodvHelper aodv;

ns3::InternetStackHelper stack;

stack.SetRoutingHelper(aodv);  // Set AODV as the routing protocol

stack.Install(nodes);

  1. DSR Example

ns3::DsrHelper dsr;

ns3::DsrMainHelper dsrMain;

ns3::InternetStackHelper stack;

stack.Install(nodes);

dsrMain.Install(dsr, nodes);

  1. Assign IP Addresses

ns3::Ipv4AddressHelper address;

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

ns3::Ipv4InterfaceContainer interfaces = address.Assign(devices);

  1. Generate Traffic

UDP Traffic

// UDP Echo server on node 0

ns3::UdpEchoServerHelper echoServer(9);

ns3::ApplicationContainer serverApp = echoServer.Install(nodes.Get(0));

serverApp.Start(ns3::Seconds(1.0));

serverApp.Stop(ns3::Seconds(20.0));

// UDP Echo client on node 9

ns3::UdpEchoClientHelper echoClient(interfaces.GetAddress(0), 9);

echoClient.SetAttribute(“MaxPackets”, ns3::UintegerValue(10));

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

echoClient.SetAttribute(“PacketSize”, ns3::UintegerValue(512));

ns3::ApplicationContainer clientApp = echoClient.Install(nodes.Get(9));

clientApp.Start(ns3::Seconds(2.0));

clientApp.Stop(ns3::Seconds(20.0));

  1. Run the Simulation

ns3::Simulator::Run();

ns3::Simulator::Destroy();

  1. Analyze Results

Metrics:

  • Packet Delivery Ratio (PDR):
    • In PDR for ratio of successfully has delivered packets the total packets transmitting.
  • End-to-End Delay:
    • The normal duration takes for packets to reach their destination.
  • Routing Overhead:
    • Calculate the numbers of control packets are created the route discovery.

Tracing and Visualization:

  • .pcap ensure for tracing the packet analysis:

ns3::AsciiTraceHelper ascii;

phy.EnableAsciiAll(ascii.CreateFileStream(“on-demand.tr”));

phy.EnablePcapAll(“on-demand”);

  • For envision the use tool like NetAnim:

./waf –run “on-demand-simulation –vis”

  1. Iterate and Enhance
  • Advanced Scenarios:
    • Establish the node/connection failures for validate the protocol resilience.
    • It replicates the higher node mobility for examine the protocol performance.
  • Traffic Patterns:
    • Establish the TCP-based congestion or several concurrent UDP streams.
  • Comparison:
    • Associate the AODV and DSR below classify the network environments.
  1. Customize the Protocol

We encompass or alter the AODV or DSR:

  1. Place the protocol for execution:
    • src/aodv designed for AODV.
    • src/dsr used for DSR.
  2. Change the main files:
    • Key routing logic aodv-routing-protocol.cc or dsr-routing-protocol.cc.
    •  Helper setting :aodv-helper.cc or dsr-helper.cc:.
  3. Restructure the ns3:

./waf

As we discussed earlier about how the on demand protocol in AODV will perform in ns3 environment and we help to provide further information about how the AODV will adapt in different environments.