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

How to Implement RIPv2 protocol in ns3

Implementing the RIP version 2 (RIPv2) protocol in ns3 includes configuring the existing RIP protocol provided by ns3. The internet module of ns3 incorporates a RipHelper class which permits us to set up and configure the RIP protocol. ns3 can differentiate RIP and RIPv2 specifically. So, the functionalities involves cover typical RIP operations, that can be seen as representative of RIPv2.

Steps to implement RIPv2 in ns3

  1. Set up your environment

Make sure that ns3 is installed in the computer. If not, install it from the official ns3 website.

  1. Create a new ns3 script

On your ns3 installation, create a new simulation script in the scratch directory. For Example, you can create a file named ripv2-simulation.cc.

cd ns-3.xx

cd scratch

touch ripv2-simulation.cc

  1. Include the necessary header files

In the ripv2-simulation.cc file, create the necessary header files 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/rip-helper.h”

using namespace ns3;

 

  1. Set the network topology

Set the network topology by creating the basic topology that contains several nodes which uses point-to-point links and configure RIP on them.

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

{

  CommandLine cmd;

  cmd.Parse (argc, argv);

  NodeContainer nodes;

  nodes.Create (4);

  // Set up point-to-point links

  PointToPointHelper pointToPoint;

  pointToPoint.SetDeviceAttribute (“DataRate”, StringValue (“1Gbps”));

  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)));

  devices.Add (pointToPoint.Install (nodes.Get(2), nodes.Get(3)));

  // Install the internet stack on nodes

  InternetStackHelper stack;

  stack.Install (nodes);

  // Assign IP addresses to the devices

  Ipv4AddressHelper address;

  Ipv4InterfaceContainer interfaces;

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

  interfaces = address.Assign (devices.Get(0), devices.Get(1));

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

  interfaces.Add (address.Assign (devices.Get(1), devices.Get(2)));

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

  interfaces.Add (address.Assign (devices.Get(2), devices.Get(3)));

  // Configure RIP

  RipHelper ripRouting;

  Ipv4ListRoutingHelper list;

  list.Add (ripRouting, 0);

  stack.SetRoutingHelper (list);

  stack.Install (nodes);

  // Set up applications (e.g., a UDP echo server and client)

  UdpEchoServerHelper echoServer (9);

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

  serverApps.Start (Seconds (1.0));

  serverApps.Stop (Seconds (20.0));

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

  // Enable tracing

  AsciiTraceHelper ascii;

  pointToPoint.EnableAsciiAll (ascii.CreateFileStream (“ripv2-simulation.tr”));

  pointToPoint.EnablePcapAll (“ripv2-simulation”);

  // Run the simulation

  Simulator::Stop (Seconds (20.0));

  Simulator::Run ();

  Simulator::Destroy ();

  return 0;

}

  1. Build and run the simulation

Build and run your script after writing.

./waf build

./waf –run scratch/ripv2-simulation

  1. Analyze the results

You can analyze the results after running the simulation, by using the generated trace files (ripv2-simulation.tr and ripv2-simulation-0-0.pcap).

Example script for RIPv2 protocol

Below is the example script for your reference:

#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/rip-helper.h”

using namespace ns3;

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

{

  CommandLine cmd;

  cmd.Parse (argc, argv);

  NodeContainer nodes;

  nodes.Create (4);

  // Set up point-to-point links

  PointToPointHelper pointToPoint;

  pointToPoint.SetDeviceAttribute (“DataRate”, StringValue (“1Gbps”));

  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)));

  devices.Add (pointToPoint.Install (nodes.Get(2), nodes.Get(3)));

  // Install the internet stack on nodes

  InternetStackHelper stack;

  stack.Install (nodes);

  // Assign IP addresses to the devices

  Ipv4AddressHelper address;

  Ipv4InterfaceContainer interfaces;

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

  interfaces = address.Assign (devices.Get(0), devices.Get(1));

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

  interfaces.Add (address.Assign (devices.Get(1), devices.Get(2)));

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

  interfaces.Add (address.Assign (devices.Get(2), devices.Get(3)));

  // Configure RIP

  RipHelper ripRouting;

  Ipv4ListRoutingHelper list;

  list.Add (ripRouting, 0);

  stack.SetRoutingHelper (list);

  stack.Install (nodes);

  // Set up applications (e.g., a UDP echo server and client)

  UdpEchoServerHelper echoServer (9);

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

  serverApps.Start (Seconds (1.0));

  serverApps.Stop (Seconds (20.0));

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

  // Enable tracing

  AsciiTraceHelper ascii;

  pointToPoint.EnableAsciiAll (ascii.CreateFileStream (“ripv2-simulation.tr”));

  pointToPoint.EnablePcapAll (“ripv2-simulation”);

  // Run the simulation

  Simulator::Stop (Seconds (20.0));

  Simulator::Run ();

  Simulator::Destroy ();

  return 0;

}

Overall, we had successfully implemented the RIP version 2 (RIPv2) by configuring the existing RIP protocol using ns3 features. Also, we provide more related simulation on RIP version 2.