Ns3 Projects for B.E/B.Tech M.E/M.Tech PhD Scholars.  Phone-Number:9790238391   E-mail: ns3simulation@gmail.com

How to implement AODV protocol in ns3

To implement the Ad hoc on-demand distance vector (AODV) routing protocol in ns3 we develop and must built-in AODV module. We  work on all types of AODV module, contact us for best programming outcomes.  Here is the step-by-step procedure on how to setup a general simulation using an AODV protocol in ns3:

Step-by-Step Guide to Implementation

  1. Set Up Your Environment

Make sure we have installed ns3 on the system. If not then install and download it from official website.

  1. Create a New ns3 Script

Create a new simulation script in the scratch directory of your ns3 installation. For example, you can create a file named aodv-simulation.cc.

cd ns-3.xx

cd scratch

touch aodv-simulation.cc

  1. Include Necessary Headers

In your aodv-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/mobility-module.h”

#include “ns3/aodv-module.h”

using namespace ns3;

  1. Set Up the Network Topology

Define the network topology. For simplicity, let’s create a basic topology with three nodes connected in 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;

  AodvHelper aodv;

  internet.SetRoutingHelper (aodv);

  internet.Install (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;

}

  1. Configure the AODV Protocol

In this example, the AODV protocol is installed and configured using the AodvHelper class. The AodvHelper class configures the AODV routing protocol on the nodes.

  1. Build and Run the Simulation

After writing your script, you need to build and run it.

./waf build

./waf –run scratch/aodv-simulation

  1. Analyze the Results

After running the simulation, you can analyze the results based on your needs. You may want to add logging or tracing to observe the behavior of the AODV protocol.

Example Script

Here is the sample script to complete the AODV protocol in ns3 environment for references:

#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/mobility-module.h”

#include “ns3/aodv-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;

  AodvHelper aodv;

  internet.SetRoutingHelper (aodv);

  internet.Install (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;

}

Finally, here we discussed about how to implement and process the Ad hoc on-demand distance vector network performs in ns3 environment and also we see the sample references clearly. We also provide all kinds of information related to Ad hoc on-demand distance vector networks with performance analysis guidance.