To implement a classless routing protocol in ns3, it supports these protocols they are CIDR (Classless Inter-Domain Routing), like OSPF (Open Shortest Path First) or BGP (Border Gateway Protocol). Nevertheless ns3 can’t support OSPF or BGP functionalities.
For instances, we will show how to implement the RIPng (Routing Information Protocol next generation) for IPv6, this is a sample of classless protocol that supports in ns3 environment.
Setting Up RIPng in ns-3
- Set Up Your Environment
Make sure ns3 is installed. If not done download it from the official website and set it up.
- Create a New ns-3 Script
Create a new simulation script in the scratch directory of your ns-3 installation. For example, create a file named ripng-simulation.cc.
cd ns-3.xx
cd scratch
touch ripng-simulation.cc
3. Include Necessary Headers
In your ripng-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/mobility-module.h”
#include “ns3/ipv6-routing-helper.h”
#include “ns3/ripng-helper.h”
using namespace ns3;
4. Set Up the Network Topology
Define the network topology. Let’s create a basic topology with a few nodes and use RIPng as the routing protocol.
int main (int argc, char *argv[])
{
CommandLine cmd;
cmd.Parse (argc, argv);
NodeContainer nodes;
nodes.Create (4);
// Set up point-to-point links
PointToPointHelper pointToPoint;
pointToPoint.SetDeviceAttribute (“DataRate”, StringValue (“5Mbps”));
pointToPoint.SetChannelAttribute (“Delay”, StringValue (“2ms”));
NetDeviceContainer devices;
devices = pointToPoint.Install (nodes.Get(0), nodes.Get(1));
devices.Add (pointToPoint.Install (nodes.Get(1), nodes.Get(2)));
devices.Add (pointToPoint.Install (nodes.Get(2), nodes.Get(3)));
// Install the internet stack on nodes
InternetStackHelper internetv6;
RipNgHelper ripngRouting;
Ipv6ListRoutingHelper listRouting;
listRouting.Add (ripngRouting, 0);
internetv6.SetIpv6RoutingHelper (listRouting);
internetv6.Install (nodes);
// Assign IPv6 addresses to the devices
Ipv6AddressHelper ipv6;
ipv6.SetBase (Ipv6Address (“2001:1::”), Ipv6Prefix (64));
Ipv6InterfaceContainer interfaces = ipv6.Assign (devices.Get(0), devices.Get(1));
ipv6.SetBase (Ipv6Address (“2001:2::”), Ipv6Prefix (64));
interfaces.Add (ipv6.Assign (devices.Get(1), devices.Get(2)));
ipv6.SetBase (Ipv6Address (“2001:3::”), Ipv6Prefix (64));
interfaces.Add (ipv6.Assign (devices.Get(2), devices.Get(3)));
// Set up applications (e.g., a UDP echo server and client)
UdpEchoServerHelper echoServer (9);
ApplicationContainer serverApps = echoServer.Install (nodes.Get (3));
serverApps.Start (Seconds (1.0));
serverApps.Stop (Seconds (10.0));
UdpEchoClientHelper echoClient (interfaces.GetAddress (3, 1), 9);
echoClient.SetAttribute (“MaxPackets”, UintegerValue (1));
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));
// Enable tracing
AsciiTraceHelper ascii;
pointToPoint.EnableAsciiAll (ascii.CreateFileStream (“ripng-simulation.tr”));
pointToPoint.EnablePcapAll (“ripng-simulation”);
// Run the simulation
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/ripng-simulation
6. Analyze the Results
After running the simulation, you can analyze the results using the generated trace files (ripng-simulation.tr and ripng-simulation-0-0.pcap).
Complete Example Script for RIPng
Below are the sample references to complete the script for RIPng:
#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/mobility-module.h”
#include “ns3/ipv6-routing-helper.h”
#include “ns3/ripng-helper.h”
using namespace ns3;
int main (int argc, char *argv[])
{
CommandLine cmd;
cmd.Parse (argc, argv);
NodeContainer nodes;
nodes.Create (4);
// Set up point-to-point links
PointToPointHelper pointToPoint;
pointToPoint.SetDeviceAttribute (“DataRate”, StringValue (“5Mbps”));
pointToPoint.SetChannelAttribute (“Delay”, StringValue (“2ms”));
NetDeviceContainer devices;
devices = pointToPoint.Install (nodes.Get(0), nodes.Get(1));
devices.Add (pointToPoint.Install (nodes.Get(1), nodes.Get(2)));
devices.Add (pointToPoint.Install (nodes.Get(2), nodes.Get(3)));
// Install the internet stack on nodes
InternetStackHelper internetv6;
RipNgHelper ripngRouting;
Ipv6ListRoutingHelper listRouting;
listRouting.Add (ripngRouting, 0);
internetv6.SetIpv6RoutingHelper (listRouting);
internetv6.Install (nodes);
// Assign IPv6 addresses to the devices
Ipv6AddressHelper ipv6;
ipv6.SetBase (Ipv6Address (“2001:1::”), Ipv6Prefix (64));
Ipv6InterfaceContainer interfaces = ipv6.Assign (devices.Get(0), devices.Get(1));
ipv6.SetBase (Ipv6Address (“2001:2::”), Ipv6Prefix (64));
interfaces.Add (ipv6.Assign (devices.Get(1), devices.Get(2)));
ipv6.SetBase (Ipv6Address (“2001:3::”), Ipv6Prefix (64));
interfaces.Add (ipv6.Assign (devices.Get(2), devices.Get(3)));
// Set up applications (e.g., a UDP echo server and client)
UdpEchoServerHelper echoServer (9);
ApplicationContainer serverApps = echoServer.Install (nodes.Get (3));
serverApps.Start (Seconds (1.0));
serverApps.Stop (Seconds (10.0));
UdpEchoClientHelper echoClient (interfaces.GetAddress (3, 1), 9);
echoClient.SetAttribute (“MaxPackets”, UintegerValue (1));
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));
// Enable tracing
AsciiTraceHelper ascii;
pointToPoint.EnableAsciiAll (ascii.CreateFileStream (“ripng-simulation.tr”));
pointToPoint.EnablePcapAll (“ripng-simulation”);
// Run the simulation
Simulator::Run ();
Simulator::Destroy ();
return 0;
}
Overall, we had implemented the classless routing protocol that is RIPng that supports ns3 environment. We also help to provide related information about classless routing protocol. Implementation and programming on classless protocol in ns3 will be guided by our experts in a best way.