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

How to Implement wan protocols in ns3

To implement WAN (Wide Area Network) protocols in ns3, by setting up network topology which is interconnected through routers to span multiple regions or areas. Generally WAN protocols use OSPF (Open Shortest Path First) and BGP (Border Gateway Protocol) routing protocols for simulation. Here the steps will guide on how to set up WAN protocol using BGP in ns3.

Step-by-Step Guide to Implementing WAN Protocols in ns-3 Using BGP

  1. Set Up Your Environment

Ensure that ns3 and the DCE module is installed.

  1. Create a New ns-3 Script

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

cd ns3-dce

cd source/ns-3-dce

mkdir -p scratch

cd scratch

touch wan-bgp-simulation.cc

3. Include Necessary Headers

In your wan-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”

#include “ns3/quagga-helper.h”

using namespace ns3;

4. Set Up the Network Topology

Define the network topology. Let’s create a more complex topology with multiple ASes (Autonomous Systems) and use BGP as the routing protocol.

int main (int argc, char *argv[])

{

  CommandLine cmd;

  cmd.Parse (argc, argv);

  NodeContainer nodesA, nodesB, nodesC, nodesD;

  nodesA.Create (2);

  nodesB.Create (2);

  nodesC.Create (2);

  nodesD.Create (2);

  // Set up point-to-point links within each AS

  PointToPointHelper pointToPoint;

  pointToPoint.SetDeviceAttribute (“DataRate”, StringValue (“1Gbps”));

  pointToPoint.SetChannelAttribute (“Delay”, StringValue (“2ms”));

  NetDeviceContainer devicesA, devicesB, devicesC, devicesD;

  devicesA = pointToPoint.Install (nodesA);

  devicesB = pointToPoint.Install (nodesB);

  devicesC = pointToPoint.Install (nodesC);

  devicesD = pointToPoint.Install (nodesD);

  // Interconnect the ASes

  NodeContainer interconnectAB, interconnectBC, interconnectCD;

  interconnectAB.Add (nodesA.Get (1));

  interconnectAB.Add (nodesB.Get (0));

  interconnectBC.Add (nodesB.Get (1));

  interconnectBC.Add (nodesC.Get (0));

  interconnectCD.Add (nodesC.Get (1));

  interconnectCD.Add (nodesD.Get (0));

  NetDeviceContainer devicesAB, devicesBC, devicesCD;

  devicesAB = pointToPoint.Install (interconnectAB);

  devicesBC = pointToPoint.Install (interconnectBC);

  devicesCD = pointToPoint.Install (interconnectCD);

  // Install the internet stack on nodes

  InternetStackHelper stack;

  stack.Install (nodesA);

  stack.Install (nodesB);

  stack.Install (nodesC);

  stack.Install (nodesD);

  // Assign IP addresses to the devices

  Ipv4AddressHelper address;

  Ipv4InterfaceContainer interfacesA, interfacesB, interfacesC, interfacesD;

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

  interfacesA = address.Assign (devicesA);

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

  interfacesB = address.Assign (devicesB);

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

  interfacesC = address.Assign (devicesC);

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

  interfacesD = address.Assign (devicesD);

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

  Ipv4InterfaceContainer interfacesAB = address.Assign (devicesAB);

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

  Ipv4InterfaceContainer interfacesBC = address.Assign (devicesBC);

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

  Ipv4InterfaceContainer interfacesCD = address.Assign (devicesCD);

  // Install DCE

  DceManagerHelper dceManager;

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

  dceManager.Install (nodesA);

  dceManager.Install (nodesB);

  dceManager.Install (nodesC);

  dceManager.Install (nodesD);

  // Install Quagga

  QuaggaHelper quagga;

  quagga.EnableRadvd (nodesA);

  quagga.EnableRadvd (nodesB);

  quagga.EnableRadvd (nodesC);

  quagga.EnableRadvd (nodesD);

  quagga.Install (nodesA);

  quagga.Install (nodesB);

  quagga.Install (nodesC);

  quagga.Install (nodesD);

  // Configure BGP on each AS

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

                        “interface *\n”

                        “ip forwarding\n”

                        “ipv6 forwarding\n”

                        “router bgp 100\n”

                        “bgp router-id 10.1.1.1\n”

                        “neighbor 10.2.1.2 remote-as 200\n”

                        “network 10.1.1.0/24\n”);

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

                        “interface *\n”

                        “ip forwarding\n”

                        “ipv6 forwarding\n”

                        “router bgp 200\n”

                        “bgp router-id 10.1.2.1\n”

                        “neighbor 10.2.1.1 remote-as 100\n”

                        “neighbor 10.2.2.2 remote-as 300\n”

                        “network 10.1.2.0/24\n”);

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

                        “interface *\n”

                        “ip forwarding\n”

                        “ipv6 forwarding\n”

                        “router bgp 300\n”

                        “bgp router-id 10.1.3.1\n”

                        “neighbor 10.2.2.1 remote-as 200\n”

                        “neighbor 10.2.3.2 remote-as 400\n”

                        “network 10.1.3.0/24\n”);

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

                        “interface *\n”

                        “ip forwarding\n”

                        “ipv6 forwarding\n”

                        “router bgp 400\n”

                        “bgp router-id 10.1.4.1\n”

                        “neighbor 10.2.3.1 remote-as 300\n”

                        “network 10.1.4.0/24\n”);

  // Enable tracing

  AsciiTraceHelper ascii;

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

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

6. Analyze the Results

After running the simulation, you can analyze the results using the generated trace files (wan-bgp-simulation.tr and wan-bgp-simulation-0-0.pcap).

Complete Example Script for BGP in a WAN

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 nodesA, nodesB, nodesC, nodesD;

  nodesA.Create (2);

  nodesB.Create (2);

  nodesC.Create (2);

  nodesD.Create (2);

  // Set up point-to-point links within each AS

  PointToPointHelper pointToPoint;

  pointToPoint.SetDeviceAttribute (“DataRate”, StringValue (“1Gbps”));

  pointToPoint.SetChannelAttribute (“Delay”, StringValue (“2ms”));

  NetDeviceContainer devicesA, devicesB, devicesC, devicesD;

  devicesA = pointToPoint.Install (nodesA);

  devicesB = pointToPoint.Install (nodesB);

  devicesC = pointToPoint.Install (nodesC);

  devicesD = pointToPoint.Install (nodesD);

  // Interconnect the ASes

  NodeContainer interconnectAB, interconnectBC, interconnectCD;

  interconnectAB.Add (nodesA.Get (1));

  interconnectAB.Add (nodesB.Get (0));

  interconnectBC.Add (nodesB.Get (1));

  interconnectBC.Add (nodesC.Get (0));

  interconnectCD.Add (nodesC.Get (1));

  interconnectCD.Add (nodesD.Get (0));

  NetDeviceContainer devicesAB, devicesBC, devicesCD;

  devicesAB = pointToPoint.Install (interconnectAB);

  devicesBC = pointToPoint.Install (interconnectBC);

  devicesCD = pointToPoint.Install (interconnectCD);

  // Install the internet stack on nodes

  InternetStackHelper stack;

  stack.Install (nodesA);

  stack.Install (nodesB);

  stack.Install (nodesC);

  stack.Install (nodesD);

  // Assign IP addresses to the devices

  Ipv4AddressHelper address;

  Ipv4InterfaceContainer interfacesA, interfacesB, interfacesC, interfacesD;

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

  interfacesA = address.Assign (devicesA);

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

  interfacesB = address.Assign (devicesB);

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

  interfacesC = address.Assign (devicesC);

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

  interfacesD = address.Assign (devicesD);

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

  Ipv4InterfaceContainer interfacesAB = address.Assign (devicesAB);

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

  Ipv4InterfaceContainer interfacesBC = address.Assign (devicesBC);

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

  Ipv4InterfaceContainer interfacesCD = address.Assign (devicesCD);

  // Install DCE

  DceManagerHelper dceManager;

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

  dceManager.Install (nodesA);

  dceManager.Install (nodesB);

  dceManager.Install (nodesC);

  dceManager.Install (nodesD);

  // Install Quagga

  QuaggaHelper quagga;

  quagga.EnableRadvd (nodesA);

  quagga.EnableRadvd (nodesB);

  quagga.EnableRadvd (nodesC);

  quagga.EnableRadvd (nodesD);

  quagga.Install (nodesA);

  quagga.Install (nodesB);

  quagga.Install (nodesC);

  quagga.Install (nodesD);

  // Configure BGP on each AS

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

                        “interface *\n”

                        “ip forwarding\n”

                        “ipv6 forwarding\n”

                        “router bgp 100\n”

                        “bgp router-id 10.1.1.1\n”

                        “neighbor 10.2.1.2 remote-as 200\n”

                        “network 10.1.1.0/24\n”);

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

                        “interface *\n”

                        “ip forwarding\n”

                        “ipv6 forwarding\n”

                        “router bgp 200\n”

                        “bgp router-id 10.1.2.1\n”

                        “neighbor 10.2.1.1 remote-as 100\n”

                        “neighbor 10.2.2.2 remote-as 300\n”

                        “network 10.1.2.0/24\n”);

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

                        “interface *\n”

                        “ip forwarding\n”

                        “ipv6 forwarding\n”

                        “router bgp 300\n”

                        “bgp router-id 10.1.3.1\n”

                        “neighbor 10.2.2.1 remote-as 200\n”

                        “neighbor 10.2.3.2 remote-as 400\n”

                        “network 10.1.3.0/24\n”);

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

                        “interface *\n”

                        “ip forwarding\n”

                        “ipv6 forwarding\n”

                        “router bgp 400\n”

                        “bgp router-id 10.1.4.1\n”

                        “neighbor 10.2.3.1 remote-as 300\n”

                        “network 10.1.4.0/24\n”);

  // Enable tracing

  AsciiTraceHelper ascii;

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

  pointToPoint.EnablePcapAll (“wan-bgp-simulation”);

  // Run the simulation

  Simulator::Stop (Seconds (20.0));

  Simulator::Run ();

  Simulator::Destroy ();

  return 0;

}

Overall, We had generalised the implementation process of WAN (Wide Area Network) protocol in ns3, which uses BGP (Border Gateway Protocol) for simulation that covers multiple regions. OSPF (Open Shortest Path First) and BGP (Border Gateway Protocol) routing protocols with  simulation  help are shared by our developers for your project.