How to Begin Implement a Classful Protocol in NS3

To stimulate a classful routing protocol for instance RIP version 1 or early versions of IGRP does not helps for subnet masks in routing bring up-to-date and assumes the static subnet sizes such as Class A, B, or C. Executing the classful protocol in ns-3 has includes the replicate a behavior through making a custom routing protocol or changing an existing one.

Here’s how to begin:

Steps to Begin Implement a Classful Protocol in NS3

  1. Understand Classful Protocols
  • Key Features:
    • Variable Length Subnet Masks (VLSM) Does not helps for the protocols
    • Routes are replaced according to Class A, B, or C addresses.
    • Class A: IPs starting with 0 for sample 0.0.0.0 to 127.255.255.25, /8 prefix.
    • Class B: IPs starting with 10 for instance 128.0.0.0 to 191.255.255.255, /16 prefix.
    • Class C: IPs starting with 110 such as 192.0.0.0 to 223.255.255.255, /24 prefix.
  • Simulation Goals:
    • Apply and replicate a classful routing protocol.
    • Validate the routing behavior for network by static subnet sizes.
    • Associate the classful routing behavior through classless protocols.
  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. Authenticate the installation:

./ns3 run hello-simulator

  1. Plan the Network Topology
  • Components:
    • Routers are process the classful protocol.
    • Hosts are communicating by the routers.
  • Topology:
    • The network topology has numerous subnets through static prefixes.
  1. Implement the Classful Protocol
  2. Create a Custom Routing Protocol
  1. Define the Routing Class
    • Encompass the Ipv4RoutingProtocol base class.
    • Apply the route discovery and handle the logic assuming classful addressing.

Example (Skeleton Code):

#include “ns3/ipv4-routing-protocol.h”

#include “ns3/ipv4-route.h”

class ClassfulRoutingProtocol : public ns3::Ipv4RoutingProtocol {

public:

ClassfulRoutingProtocol() {}

virtual ~ClassfulRoutingProtocol() {}

Ptr<Ipv4Route> RouteOutput(Ptr<Packet> packet, const Ipv4Header &header,

Ptr<NetDevice> oif, Socket::SocketErrno &sockerr) override {

// Add logic to determine routes based on classful addressing

Ptr<Ipv4Route> route = Create<Ipv4Route>();

// Implement classful behavior

return route;

}

bool RouteInput(Ptr<const Packet> packet, const Ipv4Header &header,

Ptr<const NetDevice> idev, UnicastForwardCallback ucb,

MulticastForwardCallback mcb, LocalDeliverCallback lcb,

ErrorCallback ecb) override {

// Handle received packets and determine routing behavior

return true;

}

};

  1. Add Classful Routing Behavior:
    • Analyse the IP addresses and define their class like A, B, or C.
    • Limit the subnet sizes for /8, /16, or /24 according to the IP class.
    • Bring up-to-date are accordingly to the routing tables.
  1. Integrate the Protocol with ns-3
  1. Generate a assistant class for the protocol:

class ClassfulRoutingHelper : public Ipv4RoutingHelper {

public:

Ptr<Ipv4RoutingProtocol> Create(Ptr<Node> node) const override {

return CreateObject<ClassfulRoutingProtocol>();

}

};

  1. Use the supporter for the replication:

ClassfulRoutingHelper classfulRouting;

InternetStackHelper stack;

stack.SetRoutingHelper(classfulRouting);

stack.Install(nodes);

  1. Set up the Simulation
  2. Define Nodes and Links

ns3::NodeContainer routers, hosts;

routers.Create(3);  // Three routers

hosts.Create(2);    // Two end hosts (source and destination)

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)));  // Link R1-R2

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

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

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

  1. Assign IP Addresses

ns3::Ipv4AddressHelper address;

// Class A subnet

address.SetBase(“10.0.0.0”, “255.0.0.0”);

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

// Class B subnet

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

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

// Class C subnet

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

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

  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(2.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(3.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):
    • Ratio of packets has successfully delivered for complete packets are forwarding.
  • Routing Efficiency:
    • Associate the routes occupied for routing table sizes through classless protocols.
  • Overhead:
    • Study the control message overhead for handling the routes.

Tracing and Visualization:

  • Permit .pcap the tracing for complete packet investigation:

ns3::AsciiTraceHelper ascii;

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

p2p.EnablePcapAll(“classful”);

  • Use Wireshark for examine the packet flows and routing behavior.
  1. Iterate and Enhance
  • Test Scenarios:
    • It replicates the node/connection failures and calculates the recovery of protocol.
    • Launch the congestion from several sources for follow the load distribution.
  • Parameter Tuning:
    • Research through static subnet sizes and routing table are bringing up-to-date.
  • Comparison:
    • It replicates the classless protocol for instance OSPF or RIP v2 alongside and associates the performance of parameter metrics.

Concluded the entire process, you can obtain the simulation and execution process regarding the classful routing protocols project offered in it using ns3 tool. We will idea to suggest the more information regarding the classful routing protocols in additional manual.