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

How to Implement BGP protocol in ns3

To implement the Border Gateway Protocol (BGP) in ns3 needs to use of BGP module that is not concluded in the main ns3 distribution we share some basic ideas. Border Gateway Protocol  all types of projects with implementation support are aided by our team. As an alternative we make the separate module that can be incorporated. Here are the procedures to implement BGP in ns3:

Step-by-Step Implementation:

  1. Set up Your Environment

Make sure ns3 is installed. If not download it from official website and set it up by the following the instruction provided there.

  1. Install the BGP Module

The BGP module is available in the ns-3-dce (Direct Code Execution) project. You need to clone the ns-3-dce repository and integrate the BGP module into your ns-3 installation.

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

cd ns-3-dev

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

cd ns-3-dce

./waf configure –with-ns3=<path-to-ns-3>

./waf build

./waf install

Make sure to replace <path-to-ns-3> with the actual path to your ns-3 installation directory.

  1. Create a New ns3 Script

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

cd ns-3.xx

cd scratch

touch bgp-simulation.cc

  1. Include Necessary Headers

In your bgp-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/bgpd-helper.h”

using namespace ns3;

  1. Set Up the Network Topology

Explain the network topology. Let’s make a general topology with three nodes that links in line for simplicity.

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

  // Set up BGP on the nodes

  BgpdHelper bgp;

  bgp.SetAttribute (“LocalAs”, UintegerValue (65001));

  bgp.SetAttribute (“RouterId”, Ipv4AddressValue (“10.1.1.1”));

  bgp.SetAttribute (“Networks”, Ipv4AddressValue (“10.1.1.0”));

  bgp.SetAttribute (“NetworksMask”, Ipv4MaskValue (“255.255.255.0”));

  ApplicationContainer bgpApp = bgp.Install (nodes.Get (0));

  bgpApp.Start (Seconds (1.0));

  bgpApp.Stop (Seconds (10.0));

  bgp.SetAttribute (“LocalAs”, UintegerValue (65002));

  bgp.SetAttribute (“RouterId”, Ipv4AddressValue (“10.1.2.1”));

  bgp.SetAttribute (“Networks”, Ipv4AddressValue (“10.1.2.0”));

  bgp.SetAttribute (“NetworksMask”, Ipv4MaskValue (“255.255.255.0”));

  bgpApp = bgp.Install (nodes.Get (1));

  bgpApp.Start (Seconds (1.0));

  bgpApp.Stop (Seconds (10.0));

  bgp.SetAttribute (“LocalAs”, UintegerValue (65003));

  bgp.SetAttribute (“RouterId”, Ipv4AddressValue (“10.1.3.1”));

  bgp.SetAttribute (“Networks”, Ipv4AddressValue (“10.1.3.0”));

  bgp.SetAttribute (“NetworksMask”, Ipv4MaskValue (“255.255.255.0”));

  bgpApp = bgp.Install (nodes.Get (2));

  bgpApp.Start (Seconds (1.0));

  bgpApp.Stop (Seconds (10.0));

  Simulator::Run ();

  Simulator::Destroy ();

  return 0;

}

  1. Build and Run the Simulation

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

./waf build

./waf –run scratch/bgp-simulation

  1. Analyze the Results

Based on your requirements we need to analyse the outcomes and we need to add logging or tracing to notice the behaviour of the BGP protocol.

Example Script

Below is the complete script for BGP simulation in ns3:

#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/bgpd-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)));

  // Set up BGP on the nodes

  BgpdHelper bgp;

  bgp.SetAttribute (“LocalAs”, UintegerValue (65001));

  bgp.SetAttribute (“RouterId”, Ipv4AddressValue (“10.1.1.1”));

  bgp.SetAttribute (“Networks”, Ipv4AddressValue (“10.1.1.0”));

  bgp.SetAttribute (“NetworksMask”, Ipv4MaskValue (“255.255.255.0”));

  ApplicationContainer bgpApp = bgp.Install (nodes.Get (0));

  bgpApp.Start (Seconds (1.0));

  bgpApp.Stop (Seconds (10.0));

  bgp.SetAttribute (“LocalAs”, UintegerValue (65002));

  bgp.SetAttribute (“RouterId”, Ipv4AddressValue (“10.1.2.1”));

  bgp.SetAttribute (“Networks”, Ipv4AddressValue (“10.1.2.0”));

  bgp.SetAttribute (“NetworksMask”, Ipv4MaskValue (“255.255.255.0”));

  bgpApp = bgp.Install (nodes.Get (1));

  bgpApp.Start (Seconds (1.0));

  bgpApp.Stop (Seconds (10.0));

  bgp.SetAttribute (“LocalAs”, UintegerValue (65003));

  bgp.SetAttribute (“RouterId”, Ipv4AddressValue (“10.1.3.1”));

  bgp.SetAttribute (“Networks”, Ipv4AddressValue (“10.1.3.0”));

  bgp.SetAttribute (“NetworksMask”, Ipv4MaskValue (“255.255.255.0”));

  bgpApp = bgp.Install (nodes.Get (2));

  bgpApp.Start (Seconds (1.0));

  bgpApp.Stop (Seconds (10.0));

  Simulator::Run ();

  Simulator::Destroy ();

  return 0;

}

Here we have discussed here about how to analyze the simulation in ns3 environment for border gateway protocol and also provide the related information about border gateway protocol. For any types of programming results you can rely on our team.