How to Start Classless Protocol Projects Using NS3
To start classless routing in NS3, it can be executed through CIDR (Classless Inter-Domain Routing) that permits adaptable IP address allocation including variable-length subnet masking. Classless routing protocols like OSPF (Open Shortest Path First) or BGP (Border Gateway Protocol) that are typically utilised within inter-domain or complex internal networks, however NS3 does not support OSPF or BGP directly. But, we can replicate classless routing by means of setting up CIDR-based subnetting and configuring static routing tables otherwise utilise protocols for internal routing such as OLSR (Optimized Link State Routing) and DSDV (Destination-Sequenced Distance Vector).
This guide provides sequential steps to making a classless protocol simulation project in NS3 using CIDR.
Steps to Start Classless Protocol Projects in NS3
- Install NS3
Configure NS3 including below commands (assuming a Linux environment), if we doesn’t install NS3:
# Update system and install dependencies
sudo apt update
sudo apt install -y gcc g++ python3 python3-dev cmake libgsl-dev libsqlite3-dev
# Clone the NS-3 repository
git clone https://gitlab.com/nsnam/ns-3-dev.git ns-3
cd ns-3
# Configure and build NS-3
./ns3 configure –enable-examples –enable-tests
./ns3 build
- Create a New Script for Classless Protocol Simulation
- In the NS3’s scratch directory, make a new file like classless_protocol_simulation.cc.
- Configure a network including CIDR-based addressing and static routing to utilize OLSR or DSDV like an optional classless protocol with the help of below coding.
Basic Structure of classless_protocol_simulation.cc:
#include “ns3/core-module.h”
#include “ns3/network-module.h”
#include “ns3/internet-module.h”
#include “ns3/ipv4-static-routing-helper.h”
#include “ns3/olsr-helper.h”
#include “ns3/dsdv-helper.h”
#include “ns3/point-to-point-module.h”
#include “ns3/applications-module.h”
using namespace ns3;
NS_LOG_COMPONENT_DEFINE(“ClasslessProtocolSimulation”);
int main(int argc, char *argv[]) {
// Enable logging
LogComponentEnable(“UdpEchoClientApplication”, LOG_LEVEL_INFO);
LogComponentEnable(“UdpEchoServerApplication”, LOG_LEVEL_INFO);
// Create nodes in a network topology
NodeContainer nodes;
nodes.Create(4); // Example with 4 nodes in a small network
// Set up point-to-point links to form a simple topology
PointToPointHelper pointToPoint;
pointToPoint.SetDeviceAttribute(“DataRate”, StringValue(“10Mbps”));
pointToPoint.SetChannelAttribute(“Delay”, StringValue(“2ms”));
NetDeviceContainer deviceAB = pointToPoint.Install(nodes.Get(0), nodes.Get(1));
NetDeviceContainer deviceBC = pointToPoint.Install(nodes.Get(1), nodes.Get(2));
NetDeviceContainer deviceCD = pointToPoint.Install(nodes.Get(2), nodes.Get(3));
// Install Internet stack and configure routing
InternetStackHelper internet;
// Uncomment one of the following lines to select a routing protocol
OlsrHelper olsr;
internet.SetRoutingHelper(olsr); // Use OLSR for CIDR-based routing
// DsdvHelper dsdv;
// internet.SetRoutingHelper(dsdv); // Use DSDV for CIDR-based routing
internet.Install(nodes);
// Assign CIDR-based IP addresses to each link
Ipv4AddressHelper ipv4;
// Use a /30 subnet for each link
ipv4.SetBase(“192.168.1.0”, “255.255.255.252”);
ipv4.Assign(deviceAB);
ipv4.SetBase(“192.168.1.4”, “255.255.255.252”);
ipv4.Assign(deviceBC);
ipv4.SetBase(“192.168.1.8”, “255.255.255.252”);
ipv4.Assign(deviceCD);
// Set up static routing for classless routing behavior
Ipv4StaticRoutingHelper staticRoutingHelper;
// Node A’s routing configuration to reach Node D
Ptr<Ipv4> ipv4A = nodes.Get(0)->GetObject<Ipv4>();
Ptr<Ipv4StaticRouting> staticRoutingA = staticRoutingHelper.GetStaticRouting(ipv4A);
staticRoutingA->AddNetworkRouteTo(Ipv4Address(“192.168.1.8”), Ipv4Mask(“255.255.255.252”), Ipv4Address(“192.168.1.1”), 1);
// Node B’s routing configuration
Ptr<Ipv4> ipv4B = nodes.Get(1)->GetObject<Ipv4>();
Ptr<Ipv4StaticRouting> staticRoutingB = staticRoutingHelper.GetStaticRouting(ipv4B);
staticRoutingB->AddNetworkRouteTo(Ipv4Address(“192.168.1.8”), Ipv4Mask(“255.255.255.252”), Ipv4Address(“192.168.1.5”), 2);
staticRoutingB->AddNetworkRouteTo(Ipv4Address(“192.168.1.0”), Ipv4Mask(“255.255.255.252”), Ipv4Address(“192.168.1.1”), 1);
// Node C’s routing configuration
Ptr<Ipv4> ipv4C = nodes.Get(2)->GetObject<Ipv4>();
Ptr<Ipv4StaticRouting> staticRoutingC = staticRoutingHelper.GetStaticRouting(ipv4C);
staticRoutingC->AddNetworkRouteTo(Ipv4Address(“192.168.1.0”), Ipv4Mask(“255.255.255.252”), Ipv4Address(“192.168.1.6”), 1);
staticRoutingC->AddNetworkRouteTo(Ipv4Address(“192.168.1.8”), Ipv4Mask(“255.255.255.252”), Ipv4Address(“192.168.1.9”), 2);
// Node D does not require additional routing since it’s the destination
// Set up UDP echo server on Node D to test connectivity
UdpEchoServerHelper echoServer(9);
ApplicationContainer serverApps = echoServer.Install(nodes.Get(3));
serverApps.Start(Seconds(1.0));
serverApps.Stop(Seconds(10.0));
// Set up UDP echo client on Node A to communicate with Node D
UdpEchoClientHelper echoClient(Ipv4Address(“192.168.1.10”), 9);
echoClient.SetAttribute(“MaxPackets”, UintegerValue(5));
echoClient.SetAttribute(“Interval”, TimeValue(Seconds(1.0)));
echoClient.SetAttribute(“PacketSize”, UintegerValue(1024));
ApplicationContainer clientApps = echoClient.Install(nodes.Get(0));
clientApps.Start(Seconds(2.0));
clientApps.Stop(Seconds(10.0));
// Run the simulation
Simulator::Stop(Seconds(10.0));
Simulator::Run();
Simulator::Destroy();
return 0;
}
Explanation of the Code
- Node Setup: We make four nodes to replicate an internal network topology.
- CIDR-Based Subnetting: Links among the nodes are allocated for each 30 subnets (four IP addresses each subnet) that permit additional granular control across IP address assignment.
- Static Routing Setup: Every single node contains certain routes that are set up attaining other nodes to utilize CIDR. It simulates a classless routing environment in an internal network.
- Routing Protocol (Optional):
- For classless routing behavior, we can be allowed OLSR or DSDV rather than setting up static routes manually. Choose protocol only uncomment respective lines.
- Applications:
- A UDP Echo Server is configured at node 3 like the destination.
- A UDP Echo Client on node 0 interacts with the server, to experiment the end-to-end connectivity.
- Build and Run the Simulation
- In NS3’s scratch directory, we can save classless_protocol_simulation.cc.
- Go to terminal then pass through to the NS3 directory, and make the script:
./ns3 build
- Execute the simulation including either OLSR, DSDV, or static routing allowed:
./ns3 run scratch/classless_protocol_simulation
- Analyze the Results
The simulation will be recorded the connectivity among nodes to indicate how packets route over the CIDR-based network. By static routing, routes are clearly described, whereas utilising OLSR or DSDV will be handled routes actively, to employ CIDR-based IP assignment.
To observe the in-depth routing activities we can allow logging for OLSR or DSDV:
- For OLSR:
LogComponentEnable(“OlsrRoutingProtocol”, LOG_LEVEL_ALL);
- For DSDV:
LogComponentEnable(“DsdvRoutingProtocol”, LOG_LEVEL_ALL);
Experimentation Ideas
To discover more advance classless protocols, we can consider following experiment:
- Increase Network Size: Append additional nodes and links to experiment the scalability and subnet management.
- Experiment with Different Subnet Masks: Observe how smaller subnets impact the routing to utilise /28, /29, or other subnet masks.
- Compare Static vs. Dynamic Routing: Configure the replication including both static routes and dynamic protocols (OLSR/DSDV) and then monitor the dissimilarities in routing performance and flexibility.
- Simulate Network Failures: Detach certain links or nodes, in a classless routing configuration to experiment the dynamic protocol’s adaptability such as OLSR and DSDV.
From this guide, we observed the simulation process along with examples and further experimentation ideas on how to simulate the Classless Routing Protocol projects using CIDR (Classless Inter-Domain Routing) in NS3 simulation tool. Further information about this topic will be presented in another manual.
We specialize in OSPF (Open Shortest Path First) and BGP (Border Gateway Protocol). At phdprojects.org, we provide guidance on selecting optimal project topics and offer simulation results to assist you in initiating your Classless Protocol Projects utilizing the NS3 tool. By collaborating with us, you will gain insights into your project outcomes. Trust us to deliver exceptional project performance.