To implement Cisco certified network associate (CCNA) protocol in ns3 concentrated to simulate the network protocols that usually protects in the CCNA curriculum. Get all types of CCNA protocols in ns3 from our developers. The routing protocols include RIP, OSPF or EIGRP and have numerous configuration networks. The ns3 can’t support directly OSPF or EIGRP, so we validate the process of RIP that is supported by ns3.
Implementing RIP in ns3
- Set Up Your Environment
Make sure ns3 is installed on your system. If, not done download it from official website.
- 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 ccna-rip-simulation.cc.
cd ns-3.xx
cd scratch
touch ccna-rip-simulation.cc
- Include Necessary Headers
In your ccna-rip-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/rip-helper.h”
using namespace ns3;
- Set Up the Network Topology
Initially describe the network topology then make a general topology with a limited nodes and use RIP 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 stack;
RipHelper ripRouting;
Ipv4ListRoutingHelper list;
list.Add (ripRouting, 0);
stack.SetRoutingHelper (list);
stack.Install (nodes);
// Assign IP addresses to the devices
Ipv4AddressHelper address;
address.SetBase (“10.1.1.0”, “255.255.255.0”);
Ipv4InterfaceContainer interfaces = address.Assign (devices.Get(0), devices.Get(1));
address.SetBase (“10.1.2.0”, “255.255.255.0”);
interfaces.Add (address.Assign (devices.Get(1), devices.Get(2)));
address.SetBase (“10.1.3.0”, “255.255.255.0”);
interfaces.Add (address.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), 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 (“ccna-rip-simulation.tr”));
pointToPoint.EnablePcapAll (“ccna-rip-simulation”);
// Run the simulation
Simulator::Run ();
Simulator::Destroy ();
return 0;
}
- Build and Run the Simulation
After writing your script, you need to build and run it.
./waf build
./waf –run scratch/ccna-rip-simulation
- Analyze the Results
After running the simulation, you can analyze the results using the generated trace files (ccna-rip-simulation.tr and ccna-rip-simulation-0-0.pcap).
Complete Example Script for RIP
Here is a sample script to complete the CCNA protocol in ns3 environment
#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/rip-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 stack;
RipHelper ripRouting;
Ipv4ListRoutingHelper list;
list.Add (ripRouting, 0);
stack.SetRoutingHelper (list);
stack.Install (nodes);
// Assign IP addresses to the devices
Ipv4AddressHelper address;
address.SetBase (“10.1.1.0”, “255.255.255.0”);
Ipv4InterfaceContainer interfaces = address.Assign (devices.Get(0), devices.Get(1));
address.SetBase (“10.1.2.0”, “255.255.255.0”);
interfaces.Add (address.Assign (devices.Get(1), devices.Get(2)));
address.SetBase (“10.1.3.0”, “255.255.255.0”);
interfaces.Add (address.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), 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 (“ccna-rip-simulation.tr”));
pointToPoint.EnablePcapAll (“ccna-rip-simulation”);
// Run the simulation
Simulator::Run ();
Simulator::Destroy ();
return 0;
}
Implementing OSPF and EIGRP in ns-3
To implement the OSPF and EIGRP are not supported by ns3 but we can use the external tools like Quagga or FR Routing with the Direct Code Execution (DCE) module. Here is a procedure to us the Quagga for OSPF via DCE.
Implementing OSPF Using Quagga and DCE
- Install DCE: Follow the instructions to set up DCE from the DCE website.
- Create a new script for OSPF 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/dce-module.h”
using namespace ns3;
int main (int argc, char *argv[])
{
CommandLine cmd;
cmd.Parse (argc, argv);
NodeContainer nodes;
nodes.Create (4);
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)));
InternetStackHelper stack;
stack.Install (nodes);
Ipv4AddressHelper address;
address.SetBase (“10.0.0.0”, “255.255.255.0”);
Ipv4InterfaceContainer interfaces = address.Assign (devices.Get(0), devices.Get(1));
address.SetBase (“10.0.1.0”, “255.255.255.0”);
interfaces.Add (address.Assign (devices.Get(1), devices.Get(2)));
address.SetBase (“10.0.2.0”, “255.255.255.0”);
interfaces.Add (address.Assign (devices.Get(2), devices.Get(3)));
DceManagerHelper dceManager;
dceManager.SetTaskManagerAttribute (“FiberManagerType”, StringValue (“UcontextFiberManager”));
dceManager.Install (nodes);
QuaggaHelper quagga;
quagga.EnableRadvd (nodes);
quagga.Install (nodes);
quagga.Config (nodes.Get (0), “zebra”, “log stdout\n”
“interface *\n”
“ip forwarding\n”
“router ospf\n”
” network 10.0.0.0/24 area 0\n”
” network 10.0.1.0/24 area 0\n”);
quagga.Config (nodes.Get (1), “zebra”, “log stdout\n”
“interface *\n”
“ip forwarding\n”
“router ospf\n”
” network 10.0.0.0/24 area 0\n”
” network 10.0.1.0/24 area 0\n”);
quagga.Config (nodes.Get (2), “zebra”, “log stdout\n”
“interface *\n”
“ip forwarding\n”
“router ospf\n”
” network 10.0.1.0/24 area 0\n”
” network 10.0.2.0/24 area 0\n”);
quagga.Config (nodes.Get (3), “zebra”, “log stdout\n”
“interface *\n”
“ip forwarding\n”
“router ospf\n”
” network 10.0.2.0/24 area 0\n”);
AsciiTraceHelper ascii;
pointToPoint.EnableAsciiAll (ascii.CreateFileStream (“ospf-simulation.tr”));
pointToPoint.EnablePcapAll (“ospf-simulation”);
Simulator::Stop (Seconds (20.0));
Simulator::Run ();
Simulator::Destroy ();
return 0;
}
Build and Run the Simulation:
./waf build
./waf –run scratch/ospf-simulation
Overall we shared the data about how the CCNA protocols will perform in ns3 and Quagga simulation and also we provide and support related information about CCNA protocols. In CCNA we tend to assist scholars with best coding and implementation support.