How to Start Networking Projects Using NS3
To start networking projects in NS3, follow the below steps to configure the environment, to know the NS3 basics, and start operating on a simple networking project, in academia and industry a discrete-event network simulator generally utilized.
Steps to Start Networking Projects in NS3
- Set Up NS3
Installation:
- Linux/Ubuntu (recommended): Launch a terminal then execute the following commands installing the dependencies and NS3:
sudo apt-get update
sudo apt-get install -y build-essential autoconf cvs bzr unrar gdb valgrind gsl-bin libgsl-dev \
flex bison libfl-dev tcpdump sqlite sqlite3 libsqlite3-dev libxml2 libxml2-dev \
libgtk2.0-0 libgtk2.0-dev vtun lxc libboost-all-dev openmpi-bin openmpi-common \
openmpi-doc libopenmpi-dev
- Download NS3 from their official website or utilize Git:
git clone https://gitlab.com/nsnam/ns-3-dev.git
cd ns-3-dev
./waf configure –enable-examples –enable-tests
./waf build
- Windows: NS3 does not directly support however we can be utilized a virtual machine including Ubuntu or Windows Subsystem for Linux (WSL).
- Understand NS-3 Basics
File Structure:
- src/: Includes several modules such as internet, network, applications.
- examples/: Ready-to-run the sample snippet programs, which is helpful for learning.
- scratch/: Directory for custom programs and locate the new scripts here for analysing.
Key Components:
- Nodes: Denote the network devices like routers, hosts.
- NetDevices: Network interfaces, which permits associating such as WiFi, Ethernet.
- Channels: Link nodes and manage the data transmission among them.
- Applications: Indicate actions at nodes like to make traffic.
- Write a Basic NS3 Script
Following is a simple instance configuring two nodes that are associated using a point-to-point link and to replicate the packet transmission.
- Make a new file in the scratch/ directory, for instance, simple-network.cc:
#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”
using namespace ns3;
int main(int argc, char *argv[])
{
CommandLine cmd;
cmd.Parse(argc, argv);
// Create two nodes
NodeContainer nodes;
nodes.Create(2);
// Set up a point-to-point connection
PointToPointHelper pointToPoint;
pointToPoint.SetDeviceAttribute(“DataRate”, StringValue(“5Mbps”));
pointToPoint.SetChannelAttribute(“Delay”, StringValue(“2ms”));
// Install network interfaces on nodes
NetDeviceContainer devices;
devices = pointToPoint.Install(nodes);
// Install the Internet stack on nodes
InternetStackHelper stack;
stack.Install(nodes);
// Assign IP addresses
Ipv4AddressHelper address;
address.SetBase(“10.1.1.0”, “255.255.255.0”);
Ipv4InterfaceContainer interfaces = address.Assign(devices);
// Set up an application to send data
uint16_t port = 9; // Discard port (usually not used)
UdpEchoServerHelper server(port);
ApplicationContainer serverApp = server.Install(nodes.Get(1));
serverApp.Start(Seconds(1.0));
serverApp.Stop(Seconds(10.0));
UdpEchoClientHelper client(interfaces.GetAddress(1), port);
client.SetAttribute(“MaxPackets”, UintegerValue(1));
client.SetAttribute(“Interval”, TimeValue(Seconds(1.0)));
client.SetAttribute(“PacketSize”, UintegerValue(1024));
ApplicationContainer clientApp = client.Install(nodes.Get(0));
clientApp.Start(Seconds(2.0));
clientApp.Stop(Seconds(10.0));
Simulator::Run();
Simulator::Destroy();
return 0;
}
- Build and Run the Script: Compile and execute the script utilizing NS3’s waf.
./waf –run scratch/simple-network
- Experiment with Different Scenarios
When we need to execute a simple script, try to test with:
- Different topologies: Maximize nodes or alter the connections.
- Traffic types: Utilize diverse applications such as HTTP, TCP.
- Mobility: For simulations, we append mobility models like, RandomWalk2dMobilityModel that contains to travel nodes.
- Analyze Results
NS3 offers the tools such as FlowMonitor and support for transferring packet trace files for analysis:
FlowMonitorHelper flowmon;
Ptr<FlowMonitor> monitor = flowmon.InstallAll();
monitor->SerializeToXmlFile(“flowmon.xml”, true, true);
For animations or Wireshark for packet analysis, we can envision the outcomes to utilize the tools such as NetAnim.
- Explore More Complex Projects
Examine modules that certain to the research or project requirements like 5G, IoT, Vehicular Networks (VANETs), and Wireless Mesh Networks (WMNs). The NS3 documentation and community forums can contain useful resources for extending the comprehending and troubleshooting problems.
In this setup, we learned and gain more knowledge on how the Networking project performed and configured using NS3 platform and also we deliver the sample snippets to complete the process. More details about this process will also be shared.
Contact us for personalized assistance with configuration and networking projects utilizing NS3 simulation. For innovative outcomes that are expertly managed, visit phdprojects.org.