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

How to Implement IGP protocol in ns3

To implement Interior Gateway Protocol (IGP) like OSPF (Open Shortest Path First) or IS-IS (Intermediate System to Intermediate System) in ns-3, we have to use the available helper class and modules. Below are the steps that guide you to implement OSPF, a commonly used IGP in ns3.

Steps to implement IGP 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 ospf-simulation.cc.

cd ns-3.xx

cd scratch

touch ospf-simulation.cc

  1. Include the necessary header files

In the ospf-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/ipv4-global-routing-helper.h”

using namespace ns3;

  1. Set the network topology

Set the network topology by creating the basic topology that contains three nodes which are 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 stack;

  Ipv4GlobalRoutingHelper::PopulateRoutingTables ();

  stack.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) if needed

  Simulator::Run ();

  Simulator::Destroy ();

  return 0;

}

  1. Configure the OSPF protocol

The OSPF protocol is installed and configured using the OspfHelper class, in this example. On the nodes of the OSPF routing protocol, configure the OspfHelper class.

  1. Build and run the simulation

Build and run your script after writing.

./waf build

./waf –run scratch/ospf-simulation

  1. Analyze the results

You can analyze the results based on your needs after running the simulation. Also, you can add logging or tracing to observe the behavior of the OSPF protocol.

Example script

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/ipv4-global-routing-helper.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 stack;

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

  // Populate routing tables with OSPF

  Ipv4GlobalRoutingHelper::PopulateRoutingTables ();

  Simulator::Run ();

  Simulator::Destroy ();

  return 0;

}

Overall, we had successfully implemented Interior Gateway Protocol (IGP) in ns3 by simulating OSPF (Open Shortest Path First). Also, we provide a complete implementation help  on all concepts of IGP (Interior Gateway Protocol).