How to Start Non-Adaptive Routing Projects using NS3
To start a Non-Adaptive Routing project using NS3 to follow the below steps:
Steps to Start Non-Adaptive Routing Projects using NS3
- Understand Non-Adaptive Routing
- Non-Adaptive Routing:
- The Routes are predefined and static.
- Do not change the Routing decisions based on the network conditions.
- For instance: Static Routing.
- Applications:
- It is a Simple and small network in which topology changes are rare.
- The Network planning and benchmarking.
- Set Up NS3
- Install NS3:
sudo apt update
sudo apt install g++ python3 git cmake
git clone https://gitlab.com/nsnam/ns-3-dev.git
cd ns-3-dev
./waf configure
./waf build
- Verify Installation:
./waf –run scratch/my-first
- Non-Adaptive Routing in NS3
The NS3 has built-in a support for Static Routing that is an example of non-adaptive routing. Routes are openly set up a using of Ipv4StaticRoutingHelper.
- Basic Non-Adaptive Routing Example
The following steps example establishes how to utilized their static routing in a network with 4 nodes.
Code Example:
#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/ipv4-static-routing-helper.h”
using namespace ns3;
int main() {
// Create 4 nodes
NodeContainer nodes;
nodes.Create(4);
// Create point-to-point links
PointToPointHelper pointToPoint;
pointToPoint.SetDeviceAttribute(“DataRate”, StringValue(“10Mbps”));
pointToPoint.SetChannelAttribute(“Delay”, StringValue(“2ms”));
NetDeviceContainer devices1 = pointToPoint.Install(nodes.Get(0), nodes.Get(1));
NetDeviceContainer devices2 = pointToPoint.Install(nodes.Get(1), nodes.Get(2));
NetDeviceContainer devices3 = pointToPoint.Install(nodes.Get(2), nodes.Get(3));
// Install Internet stack
InternetStackHelper stack;
stack.Install(nodes);
// Assign IP addresses
Ipv4AddressHelper address;
address.SetBase(“10.1.1.0”, “255.255.255.0”);
Ipv4InterfaceContainer interfaces1 = address.Assign(devices1);
address.SetBase(“10.1.2.0”, “255.255.255.0”);
Ipv4InterfaceContainer interfaces2 = address.Assign(devices2);
address.SetBase(“10.1.3.0”, “255.255.255.0”);
Ipv4InterfaceContainer interfaces3 = address.Assign(devices3);
// Configure static routes
Ipv4StaticRoutingHelper staticRoutingHelper;
// Node 0: Route to Node 3 via Node 1 and Node 2
Ptr<Ipv4StaticRouting> staticRoutingNode0 = staticRoutingHelper.GetStaticRouting(nodes.Get(0)->GetObject<Ipv4>());
staticRoutingNode0->AddHostRouteTo(Ipv4Address(“10.1.3.2”), Ipv4Address(“10.1.1.2”), 1);
// Node 1: Forward packets to Node 3 via Node 2
Ptr<Ipv4StaticRouting> staticRoutingNode1 = staticRoutingHelper.GetStaticRouting(nodes.Get(1)->GetObject<Ipv4>());
staticRoutingNode1->AddHostRouteTo(Ipv4Address(“10.1.3.2”), Ipv4Address(“10.1.2.2”), 2);
// Node 2: Forward packets to Node 3 directly
Ptr<Ipv4StaticRouting> staticRoutingNode2 = staticRoutingHelper.GetStaticRouting(nodes.Get(2)->GetObject<Ipv4>());
staticRoutingNode2->AddHostRouteTo(Ipv4Address(“10.1.3.2”), Ipv4Address(“10.1.3.2”), 3);
// Install applications
uint16_t port = 9;
UdpEchoServerHelper echoServer(port);
ApplicationContainer serverApp = echoServer.Install(nodes.Get(3)); // Server on Node 3
serverApp.Start(Seconds(1.0));
serverApp.Stop(Seconds(10.0));
UdpEchoClientHelper echoClient(Ipv4Address(“10.1.3.2”), port);
echoClient.SetAttribute(“MaxPackets”, UintegerValue(1));
echoClient.SetAttribute(“Interval”, TimeValue(Seconds(1.0)));
echoClient.SetAttribute(“PacketSize”, UintegerValue(1024));
ApplicationContainer clientApp = echoClient.Install(nodes.Get(0)); // Client on Node 0
clientApp.Start(Seconds(2.0));
clientApp.Stop(Seconds(10.0));
Simulator::Run();
Simulator::Destroy();
return 0;
}
- Features of Non-Adaptive Routing
- Predefined Routes: Manually setting an all routes utilized Ipv4StaticRouting.
- No Reaction to Changes: The Routes are remaining fixed and even if connections are failing or network topology changes.
- Simplicity: Utilized for validating their specific scenarios in which dynamic routing is unnecessary.
- Advanced Non-Adaptive Routing
Add Link Failures
We validate the behaviour of static routes after a connection fails.
Simulator::Schedule(Seconds(5.0), &NetDevice::SetDown, devices1.Get(0)); // Disable link at 5s
Configure Different Topologies
Testing with multiple network topologies such as tree, grid and setting a static routes accordingly.
Introduce Traffic Generators
Add TCP/UDP traffic generators to analyze the routing behavior.
- Testing and Debugging
- Enable Logging:
NS_LOG=”Ipv4StaticRouting” ./waf –run non-adaptive-routing
- Print Routing Tables: Print the routing table of a node to verify the static routes:
Ptr<Ipv4> ipv4 = nodes.Get(0)->GetObject<Ipv4>();
ipv4->GetRoutingProtocol()->PrintRoutingTable(std::cout);
- Capture Packets: Enable PCAP tracing to analyze packet flows:
pointToPoint.EnablePcapAll(“non-adaptive-routing”);
The given above is the fundamental approach that was illustrated with sample coding for non-adaptive routing project that were simulated across the NS3 environment. We plan to deliver more information regarding this project in further manual. So send to phdprojects.org all your project details we give you best results.