To implement an Exterior Gateway Protocol (EGP) like as BGP (Border Gateway Protocol) in ns-3 needs certain customization meanwhile ns3 doesn’t support the BGP. Furthermore, we use the Direct Code Execution (DCE) module in ns-3 to execute real-world implementation of BGP such as Quagga or FRRouting (FRR) inside the simulation. It permits you to make more real environment by making actual BGP software.
Here are the step by step procedures to implement the BGP in ns3 by Quagga via DCE module:
Step-by-Step Guide to Implementing BGP in ns-3 Using Quagga
- Set Up Your Environment
Make certain you have ns-3 and the DCE module installed. You can download and set it up from the official website. Follow the guidelines to set up DCE from the DCE website.
- Create a New ns-3 Script
Create a new simulation script in the scratch directory of your ns-3 installation. For example, 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
3. 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/dce-module.h”
using namespace ns3;
4. Set Up the Network Topology
Define the network topology. Let’s create a basic topology with a few nodes and use BGP as the 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;
}
5. Build and Run the Simulation
After writing your script, you need to build and run it.
./waf build
./waf –run scratch/bgp-simulation
6. Analyze the Results
After running the simulation, you can analyze the results using the generated trace files (bgp-simulation.tr and bgp-simulation-0-0.pcap).
Complete Example Script for BGP
The given below is the sample reference to complete the BGP in ns3 scenario:
Here’s a complete example script for 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/quagga-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 implemented the EGP protocol and analyse the performance using ns3 tool and also we provide the related information about EGP protocol. Get more project ideas on Direct Code Execution (DCE) module in ns-3 tool from our developers.