How to Begin Implement a BGP Protocol in NS3

To execute the Border Gateway Protocol (BGP) utilising ns3 comprises of setting up a simulation to learn the inter-domain routing. Although ns3 doesn’t directly offer a BGP’s comprehensive execution, their adaptable architecture permits for executing the BGP-like behavior or incorporate external tools such as Quagga or FRRouting into ns3 for practical BGP simulations.

Below is a step-by-step instruction on how to get started:

Steps to Begin Implement a BGP Protocol in NS3

  1. Understand BGP and Simulation Goals
  • Key Concepts:
    • BGP: A protocol utilised to transmit among the Autonomous Systems (ASes) on the Internet.
    • AS: A set of IP networks and routers on its own administrative domain.
  • Simulation Goals:
    • Replicate inter-AS routing with BGP.
    • Focus on path selection, route advertisement, or policy enforcement.
    • Examine the BGP dynamics such as convergence time, stability.
  1. Set Up ns3 Environment
  1. Install ns3:

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

cd ns-3-dev

./build.py

  1. Confirm the installation:

./ns3 run hello-simulator

  1. Plan the BGP Simulation
  • Topology:
    • Numerous ASes associated through routers to replicate the BGP peering.
    • Every single AS can have internal networks including routers.
  • Components:
    • Routers: Mimic BGP speakers.
    • Links: Denote the inter-AS or intra-AS links.
  1. Write the Simulation Script
  2. Include Necessary Headers

#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”

  1. Define Nodes

ns3::NodeContainer as1Routers, as2Routers, as3Routers;

as1Routers.Create(2);  // Two routers in AS1

as2Routers.Create(2);  // Two routers in AS2

as3Routers.Create(2);  // Two routers in AS3

  1. Set Up Links

ns3::PointToPointHelper p2p;

p2p.SetDeviceAttribute(“DataRate”, ns3::StringValue(“1Gbps”));

p2p.SetChannelAttribute(“Delay”, ns3::StringValue(“2ms”));

// Links within AS1

p2p.Install(as1Routers.Get(0), as1Routers.Get(1));

// Links within AS2

p2p.Install(as2Routers.Get(0), as2Routers.Get(1));

// Links within AS3

p2p.Install(as3Routers.Get(0), as3Routers.Get(1));

// Links between AS1 and AS2

p2p.Install(as1Routers.Get(0), as2Routers.Get(0));

// Links between AS2 and AS3

p2p.Install(as2Routers.Get(1), as3Routers.Get(0));

  1. Install Internet Stack

ns3::InternetStackHelper internet;

internet.Install(as1Routers);

internet.Install(as2Routers);

internet.Install(as3Routers);

ns3::Ipv4AddressHelper address;

// Assign IP addresses to AS1 links

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

address.Assign(p2p.GetNetDeviceContainer());

// Repeat for AS2, AS3, and inter-AS links with unique subnets

  1. Simulate BGP-Like Behavior

Option 1: Use Custom BGP Logic

  1. Custom BGP Application: Execute a custom application, which replicates the BGP-like behavior by swapping routing updates among the routers.

class BgpApp : public ns3::Application {

private:

virtual void StartApplication() override {

// Exchange routing updates

std::cout << “BGP-like routing update exchanged\n”;

}

};

Ptr<BgpApp> bgpApp1 = CreateObject<BgpApp>();

as1Routers.Get(0)->AddApplication(bgpApp1);

bgpApp1->SetStartTime(ns3::Seconds(1.0));

  1. Routing Table Updates: Fine-tune routing tables according to the BGP-like path selection.

Option 2: Integrate with External BGP Tools

  1. Install Quagga or FRRouting: Quagga or FRRouting can perform like real BGP speakers.

sudo apt install quagga

  1. Configure Quagga: Configure BGP sets up within quagga.conf for each router.

Example:

router bgp 100

neighbor 192.168.1.2 remote-as 200

network 10.0.0.0/24

  1. Connect ns3 with Quagga: Combine Quagga including ns3 we can utilize the TapBridgeHelper:

ns3::TapBridgeHelper tapBridge;

tapBridge.SetAttribute(“Mode”, ns3::StringValue(“UseLocal”));

tapBridge.Install(as1Routers.Get(0), devices.Get(0));

  1. Add Traffic Generation

Replicate the traffic to experiment BGP path selection and forwarding:

// OnOff application simulating traffic between AS1 and AS3

ns3::OnOffHelper onOffHelper(“ns3::UdpSocketFactory”,

ns3::InetSocketAddress(as3Routers.Get(0)->GetObject<ns3::Ipv4>()->GetAddress(1, 0), 9));

onOffHelper.SetAttribute(“DataRate”, ns3::StringValue(“500Kbps”));

onOffHelper.SetAttribute(“PacketSize”, ns3::UintegerValue(512));

onOffHelper.Install(as1Routers.Get(0));

  1. Run the Simulation

ns3::Simulator::Run();

ns3::Simulator::Destroy();

  1. Analyze Results

Metrics:

  • Path Selection:
    • Confirm capability of BGP selecting the best routes.
  • Convergence Time:
    • Estimate the duration for routing tables to converge.
  • Throughput and Latency:
    • Examine the effect of BGP decisions on the traffic performance.

Tracing and Visualization:

  • Allow .pcap tracing for in-depth analysis:

ns3::AsciiTraceHelper ascii;

p2p.EnableAsciiAll(ascii.CreateFileStream(“bgp.tr”));

p2p.EnablePcapAll(“bgp”);

  • Analyze routing updates and data traffic utilising Wireshark tools.
  1. Iterate and Enhance
  • Policy Simulation:
    • Integrate the simulation strategies such as route preference or AS path filtering.
  • Scalability:
    • Replicate larger topologies including additional ASes.
  • Fault Scenarios:
    • During link or router failures, experiment the behaviour of BGP.

From this step-by-step technique, you can acquire to learn more about the BGP Protocol which were implemented and analysed using NS3 tool. We will deliver additional concepts using this tool in upcoming manual.