How to Begin Implement a Classless Protocol in NS3

To stimulate the classless routing protocols, such as RIP v2, OSPF, or BGP, it helps for the Variable Length Subnet Masking (VLSM), this permits effective for IP address allocation through using the prefixes instead of fixed classes (A, B, C). Applying a classless protocol in ns3 tool typically includes the setting an existing protocol such as RIP v2, OSPF, or integrating tools like Quagga for protocols not directly executed in ns3.

Here’s how to begin implementing a classless protocol in ns-3:

Steps to Begin Implement a Classless Protocol in NS3

  1. Understand Classless Protocols
  • Key Features:
    • It helps for VLSM, in which the subnet sizes are determined through prefixes for instance /24, /16.
    • Effective used for IP addresses space.
    • Routing decisions according to the longest prefix match.
  • Examples of Classless Protocols:
    • RIP v2: Distance-vector protocol by help the intended for subnet masks.
    • OSPF: Link-state protocol designed for intra-domain routing.
    • BGP: Path-vector protocol aimed at inter-domain routing.
  1. Set up ns-3 Environment
  1. Install ns-3:

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

cd ns-3-dev

./build.py

  1. Verify the installation:

./ns3 run hello-simulator

  1. Plan the Network Topology
  • Components:
    • Routers using the classless protocol.
    • Subnets through changing a prefix length.
  • Topology:
    • Various routers through changed the subnets, interconnected to form a network.
  1. Implement a Classless Protocol
  2. Using RIP v2

RIP v2 is executed in ns-3 as part of the Ipv4ListRoutingHelper. Here’s how to set it up:

  1. 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 and Links

ns3::NodeContainer routers, hosts;

routers.Create(3);  // Three routers

hosts.Create(2);    // Two hosts

ns3::PointToPointHelper p2p;

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

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

ns3::NetDeviceContainer devices;

devices.Add(p2p.Install(routers.Get(0), routers.Get(1)));  // R1-R2

devices.Add(p2p.Install(routers.Get(1), routers.Get(2)));  // R2-R3

devices.Add(p2p.Install(routers.Get(0), hosts.Get(0)));    // R1-Host1

devices.Add(p2p.Install(routers.Get(2), hosts.Get(1)));    // R3-Host2

  1. Install Internet Stack

ns3::RipNgHelper ripNg;

ns3::InternetStackHelper stack;

stack.SetRoutingHelper(ripNg);

stack.Install(routers);

stack.Install(hosts);

  1. Assign IP Addresses

ns3::Ipv4AddressHelper address;

// Subnet 1: Between R1 and R2

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

address.Assign(devices.Get(0));

// Subnet 2: Between R2 and R3

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

address.Assign(devices.Get(1));

// Subnet 3: R1 to Host1

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

address.Assign(devices.Get(2));

// Subnet 4: R3 to Host2

address.SetBase(“172.16.1.0”, “255.255.0.0”);

address.Assign(devices.Get(3));

  1. Enable RIP v2

ripNg.AddRoutingInterface(routers.Get(0), devices.Get(0));

ripNg.AddRoutingInterface(routers.Get(1), devices.Get(1));

ripNg.AddRoutingInterface(routers.Get(2), devices.Get(2));

  1. Using OSPF or BGP
  1. Integrate Quagga: Install and configure Quagga for protocols such as OSPF or BGP.

sudo apt install quagga

  1. Configure Routing: Configure the routing settings in Quagga’s set-up files for sample zebra.conf and ospfd.conf for OSPF.
  2. Connect ns-3 with Quagga: Use TapBridge to connect the tool ns-3 nodes by Quagga routers.

ns3::TapBridgeHelper tapBridge;

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

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

  1. Generate Traffic

// UDP Echo server on Host 2

ns3::UdpEchoServerHelper echoServer(9);

ns3::ApplicationContainer serverApp = echoServer.Install(hosts.Get(1));

serverApp.Start(ns3::Seconds(1.0));

serverApp.Stop(ns3::Seconds(20.0));

// UDP Echo client on Host 1

ns3::UdpEchoClientHelper echoClient(address.Assign(devices.Get(1)).GetAddress(1), 9);

echoClient.SetAttribute(“MaxPackets”, ns3::UintegerValue(10));

echoClient.SetAttribute(“Interval”, ns3::TimeValue(ns3::Seconds(1.0)));

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

ns3::ApplicationContainer clientApp = echoClient.Install(hosts.Get(0));

clientApp.Start(ns3::Seconds(2.0));

clientApp.Stop(ns3::Seconds(20.0));

  1. Run the Simulation

ns3::Simulator::Run();

ns3::Simulator::Destroy();

  1. Analyze Results

Metrics:

  • Packet Delivery Ratio (PDR):
    • Ratios of successfully has delivered the packets to overall packets are forwarding.
  • Routing Efficiency:
    • Associate the routing decisions according to the prefix matching.
  • Routing Overhead:
    • Amount the number of control messages are altered.

Tracing and Visualization:

  • Allow the visualize for .pcap tracing the checked packet:

ns3::AsciiTraceHelper ascii;

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

p2p.EnablePcapAll(“classless”);

  • Use envision for Wireshark it examine the control messages and routing behavior.
  1. Iterate and Enhance
  • Advanced Scenarios:
    • Experiment through larger networks and diverse subnets.
    • Replicate the connection failures for examine the convergence time.
  • Traffic Patterns:
    • Used the design for TCP-based congestion or several sources/destinations.
  • Protocol Comparison:
    • It associates the RIP v2, OSPF, and BGP below same environments.
  1. Customizing Protocols

To modify or extend an existing protocol:

  1. It placed on the the protocol’s source files in src/routing or incorporate through Quagga/FRRouting.
  2. Alter the routing logic or enhance the advanced features.
  3. Recreate a tool ns-3:

./waf

Overall, we had implemented the classless routing protocol that is supports ns3 environment. We also help to provide related information about classless routing protocol.