To develop Border Gateway Protocol (BGP) within NS3 simulator which is the internet’s primary routing protocol that can be created for interchanging routing data amongst autonomous systems (ASes). BGP is vital to inter-domain routing and functions in TCP (Port 179).
BGP in NS3
- NS3 doesn’t need inherent support for BGP implementation.
- But, BGP can be executed by utilising external BGP models, Quagga routing suite, or custom NS3 components.
Steps to Develop BGP Routing Projects in NS3
Approach 1: Implement BGP Using Quagga (Best Method)
- Install and Set Up NS3 with Quagga
Quagga is a software routing suite, which assists BGP, OSPF, and RIP. With the support of NS3 Direct Code Execution (DCE), it will be incorporated in NS3.
We can set up NS3 including DCE
git clone
cd ns-3-dev
./ns3 configure –enable-examples –enable-tests –with-quagga
./ns3 build
- Define a Network Topology with ASes
Now, we will design a basic BGP topology that contains numerous ASes which can be associated through the BGP routers.
Example: 3 ASes with BGP Routers
NodeContainer AS1, AS2, AS3;
AS1.Create(2); // AS1 routers
AS2.Create(2); // AS2 routers
AS3.Create(2); // AS3 routers
Connect the ASes Using Point-to-Point Links
PointToPointHelper p2p;
p2p.SetDeviceAttribute(“DataRate”, StringValue(“1Gbps”));
p2p.SetChannelAttribute(“Delay”, StringValue(“10ms”));
NetDeviceContainer devicesAS1 = p2p.Install(AS1.Get(0), AS1.Get(1));
NetDeviceContainer devicesAS2 = p2p.Install(AS2.Get(0), AS2.Get(1));
NetDeviceContainer devicesAS3 = p2p.Install(AS3.Get(0), AS3.Get(1));
NetDeviceContainer AS1_AS2 = p2p.Install(AS1.Get(1), AS2.Get(0));
NetDeviceContainer AS2_AS3 = p2p.Install(AS2.Get(1), AS3.Get(0));
- Assign IP Addresses
InternetStackHelper stack;
stack.Install(AS1);
stack.Install(AS2);
stack.Install(AS3);
Ipv4AddressHelper address;
address.SetBase(“192.168.1.0”, “255.255.255.0”);
Ipv4InterfaceContainer interfacesAS1 = address.Assign(devicesAS1);
address.SetBase(“192.168.2.0”, “255.255.255.0”);
Ipv4InterfaceContainer interfacesAS2 = address.Assign(devicesAS2);
address.SetBase(“192.168.3.0”, “255.255.255.0”);
Ipv4InterfaceContainer interfacesAS3 = address.Assign(devicesAS3);
address.SetBase(“10.1.1.0”, “255.255.255.252”);
Ipv4InterfaceContainer interfacesAS1_AS2 = address.Assign(AS1_AS2);
address.SetBase(“10.1.2.0”, “255.255.255.252”);
Ipv4InterfaceContainer interfacesAS2_AS3 = address.Assign(AS2_AS3);
- Enable BGP Using Quagga
Allow BGP for executing the Quagga’s BGP daemon (bgpd) by every single AS.
Configure Quagga on AS1 (Router ID: 1.1.1.1)
DceManagerHelper dceManager;
dceManager.Install(AS1.Get(0));
QuaggaHelper quagga;
quagga.EnableBgp(AS1.Get(0), “1.1.1.1”, “AS1”);
quagga.AddBgpNeighbor(AS1.Get(0), Ipv4Address(“10.1.1.2”), “AS2”);
quagga.Install(AS1);
Configure Quagga on AS2
quagga.EnableBgp(AS2.Get(0), “2.2.2.2”, “AS2”);
quagga.AddBgpNeighbor(AS2.Get(0), Ipv4Address(“10.1.1.1”), “AS1”);
quagga.AddBgpNeighbor(AS2.Get(0), Ipv4Address(“10.1.2.2”), “AS3”);
quagga.Install(AS2);
Configure Quagga on AS3
quagga.EnableBgp(AS3.Get(0), “3.3.3.3”, “AS3”);
quagga.AddBgpNeighbor(AS3.Get(0), Ipv4Address(“10.1.2.1”), “AS2”);
quagga.Install(AS3);
- Setup Traffic to Test BGP
Here, we experiment the BGP routing by configuring the traffic
UdpEchoServerHelper echoServer(9);
ApplicationContainer serverApps = echoServer.Install(AS3.Get(1));
serverApps.Start(Seconds(1.0));
serverApps.Stop(Seconds(10.0));
UdpEchoClientHelper echoClient(Ipv4Address(“192.168.3.2”), 9);
echoClient.SetAttribute(“MaxPackets”, UintegerValue(5));
echoClient.SetAttribute(“Interval”, TimeValue(Seconds(1.0)));
echoClient.SetAttribute(“PacketSize”, UintegerValue(512));
ApplicationContainer clientApps = echoClient.Install(AS1.Get(0));
clientApps.Start(Seconds(2.0));
clientApps.Stop(Seconds(10.0));
- Enable Tracing for Debugging
AsciiTraceHelper ascii;
p2p.EnableAsciiAll(ascii.CreateFileStream(“bgp-routing.tr”));
p2p.EnablePcapAll(“bgp-routing”);
- Run the Simulation
Simulator::Run();
Simulator::Destroy();
- Analyze Results
After that, we can envision the performance outcomes using NetAnim:
./waf –run bgp-routing
netanim
To verify BGP routes, use:
telnet 127.0.0.1 2605
Subsequently, we need to execute:
show ip bgp
Approach 2: Implement a Custom BGP Module in NS3
If we don’t need to utilize the Quagga, we will implement a custom BGP module by:
- Prolonging the Ipv4RoutingProtocol class for managing messages of BGP.
- Describing BGP Path Selection such as Longest Prefix Match, AS Path, Next Hop.
- Executing the BGP Update, KeepAlive, and Route Advertisement.
It is complex however it enables entire control over the behaviour of BGP.
Approach 3: External BGP Simulations
- Mininet + NS3: For BGP, we can utilize Mininet and use NS3 for simulation.
- ExaBGP: A Python-based BGP speaker, which will be incorporated by NS3.
- FRRouting (FRR): This routing is an alternative of Quagga that can be used for large-scale BGP simulation.
- Extend with Advanced BGP Features
- BGP Route Aggregation: Minimize the routing table size.
- BGP Route Flap Damping: Become stable routing updates.
- BGP Route Reflection: Minimize the volume of peer connections.
- SDN-Based BGP: For intelligent routing, we will aggregate the BGP using OpenFlow.
We have demonstrated the stepwise implementation approach for BGP Routing projects in NS3, offering comprehensive explanations to ensure practical understanding on how to develop this routing in three various ways. Additional details will be offered as per your needs.