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

How to Implement exterior gateway protocol in ns3

To implement an Exterior Gateway Protocol (EGP) like BGP (Border Gateway Protocol) in ns3, we have to utilize external libraries or we have to create a custom implementation, because ns3 does not support BGP natively. But we can use Quagga or FR Routing (FRR), as both are open-source routing software that suites BGP and ns3 can integrate it by utilizing the Direct Code Execution (DCE) module. Here is a quick and detailed guide on implementing BGP in ns3 using Quagga through the DCE module.

Steps to implement BGP 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 bgp-simulation.cc.

cd ns-3-dce

cd source/ns-3-dce

mkdir -p scratch

cd scratch

touch bgp-simulation.cc

  1. Include the necessary header files

In the bgp-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/dce-module.h”

using namespace ns3;

  1. Set the network topology

Set the network topology by creating the basic topology that contains few nodes and utilizes the BGP as its routing protocol.

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;

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

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

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

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

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

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

  // Install DCE

  DceManagerHelper dceManager;

  dceManager.SetTaskManagerAttribute (“FiberManagerType”, StringValue (“UcontextFiberManager”));

  dceManager.Install (nodes);

  // Install Quagga

  QuaggaHelper quagga;

  quagga.EnableRadvd (nodes);

  quagga.Install (nodes);

  // Configure BGP on each node

  quagga.Config (nodes.Get (0), “zebra”, “log stdout\n”

                       “interface *\n”

                       “ip forwarding\n”

                       “ipv6 forwarding\n”

                       “router bgp 100\n”

                       “bgp router-id 10.0.0.1\n”

                       “neighbor 10.0.0.2 remote-as 200\n”

                       “network 10.0.0.0/24\n”);

  quagga.Config (nodes.Get (1), “zebra”, “log stdout\n”

                       “interface *\n”

                       “ip forwarding\n”

                       “ipv6 forwarding\n”

                       “router bgp 200\n”

                       “bgp router-id 10.0.0.2\n”

                       “neighbor 10.0.0.1 remote-as 100\n”

                       “neighbor 10.0.1.2 remote-as 300\n”

                       “network 10.0.1.0/24\n”);

  quagga.Config (nodes.Get (2), “zebra”, “log stdout\n”

                       “interface *\n”

                       “ip forwarding\n”

                       “ipv6 forwarding\n”

                       “router bgp 300\n”

                       “bgp router-id 10.0.1.2\n”

                       “neighbor 10.0.0.2 remote-as 200\n”

                       “neighbor 10.0.2.2 remote-as 400\n”

                       “network 10.0.2.0/24\n”);

  quagga.Config (nodes.Get (3), “zebra”, “log stdout\n”

                       “interface *\n”

                       “ip forwarding\n”

                       “ipv6 forwarding\n”

                       “router bgp 400\n”

                       “bgp router-id 10.0.2.2\n”

                       “neighbor 10.0.1.2 remote-as 300\n”

                       “network 10.0.2.0/24\n”);

  // Enable tracing

  AsciiTraceHelper ascii;

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

  pointToPoint.EnablePcapAll (“bgp-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/bgp-simulation

  1. Analyze the results

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

Example script for BGP

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/dce-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 (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;

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

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

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

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

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

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

  // Install DCE

  DceManagerHelper dceManager;

  dceManager.SetTaskManagerAttribute (“FiberManagerType”, StringValue (“UcontextFiberManager”));

  dceManager.Install (nodes);

  // Install Quagga

  QuaggaHelper quagga;

  quagga.EnableRadvd (nodes);

  quagga.Install (nodes);

  // Configure BGP on each node

  quagga.Config (nodes.Get (0), “zebra”, “log stdout\n”

                       “interface *\n”

                       “ip forwarding\n”

                       “ipv6 forwarding\n”

                       “router bgp 100\n”

                       “bgp router-id 10.0.0.1\n”

                       “neighbor 10.0.0.2 remote-as 200\n”

                       “network 10.0.0.0/24\n”);

  quagga.Config (nodes.Get (1), “zebra”, “log stdout\n”

                       “interface *\n”

                       “ip forwarding\n”

                       “ipv6 forwarding\n”

                       “router bgp 200\n”

                       “bgp router-id 10.0.0.2\n”

                       “neighbor 10.0.0.1 remote-as 100\n”

                       “neighbor 10.0.1.2 remote-as 300\n”

                       “network 10.0.1.0/24\n”);

  quagga.Config (nodes.Get (2), “zebra”, “log stdout\n”

                       “interface *\n”

                       “ip forwarding\n”

                       “ipv6 forwarding\n”

                       “router bgp 300\n”

                       “bgp router-id 10.0.1.2\n”

                       “neighbor 10.0.0.2 remote-as 200\n”

                       “neighbor 10.0.2.2 remote-as 400\n”

                       “network 10.0.2.0/24\n”);

  quagga.Config (nodes.Get (3), “zebra”, “log stdout\n”

                       “interface *\n”

                       “ip forwarding\n”

                       “ipv6 forwarding\n”

                       “router bgp 400\n”

                       “bgp router-id 10.0.2.2\n”

                       “neighbor 10.0.1.2 remote-as 300\n”

                       “network 10.0.2.0/24\n”);

  // Enable tracing

  AsciiTraceHelper ascii;

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

  pointToPoint.EnablePcapAll (“bgp-simulation”);

  // Run the simulation

  Simulator::Stop (Seconds (20.0));

  Simulator::Run ();

  Simulator::Destroy ();

  return 0;

}

Overall, we had successfully implemented the Exterior Gateway Protocol (EGP) in ns3 by simulating BGP using Quagga through the DCE module. Also, we provide more related interesting information on EGP protocol. Quagga or FR Routing (FRR) protocols are worked by us we provide ou with best project support .