How to Start Network Projects Using NS3

To start the network projects using NS3 that contains to know the simple network sets up, traffic generation, and performance analysis. NS3 is flexible and it permits to replicate both wired and wireless networks, to create it appropriate for a various kinds of networking projects that contains performance estimation, protocol experimenting, and topology studies.

Below is a sequential method to getting started with common network projects in NS3:

Steps to Start Network Projects in NS3

  1. Install NS3
  1. Download and Install NS3:

git clone https://gitlab.com/nsnam/ns-3-dev.git ns-3

cd ns-3

./waf configure –enable-examples –enable-tests

./waf build

  1. Verify Installation: Experiment the installation by way of executing an example.

./waf –run=hello-simulator

  1. Understand NS3 Network Components

NS3 uses numerous modules replicating a network:

  • Nodes: Denote devices within the network such as clients, routers, servers.
  • NetDevices: Signify network interfaces at nodes like Ethernet, WiFi adapters.
  • Channels: It offers connectivity among nodes including Point-to-Point, WiFi channels.
  • Protocols: NS3 supports numerous protocols with TCP, UDP, IP, and custom protocols.
  1. Create a Basic Network Topology

Initially, we make a simple topology. A simple configuration should contain two nodes that are associated through a Point-to-Point link. It will support to know the NS3 fundamentals before travelling on more complex sets up.

Example: Simple Point-to-Point Network

Following is a simple instance of two nodes interacting across a Point-to-Point (P2P) link.

#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 Point-to-Point channel

PointToPointHelper pointToPoint;

pointToPoint.SetDeviceAttribute(“DataRate”, StringValue(“5Mbps”));

pointToPoint.SetChannelAttribute(“Delay”, StringValue(“2ms”));

NetDeviceContainer devices = pointToPoint.Install(nodes);

// Install Internet Stack (TCP/IP)

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 traffic

uint16_t port = 9; // Arbitrary port number

UdpEchoServerHelper echoServer(port);

ApplicationContainer serverApp = echoServer.Install(nodes.Get(1));

serverApp.Start(Seconds(1.0));

serverApp.Stop(Seconds(10.0));

UdpEchoClientHelper echoClient(interfaces.GetAddress(1), port);

echoClient.SetAttribute(“MaxPackets”, UintegerValue(10));

echoClient.SetAttribute(“Interval”, TimeValue(Seconds(1.0)));

echoClient.SetAttribute(“PacketSize”, UintegerValue(1024));

ApplicationContainer clientApp = echoClient.Install(nodes.Get(0));

clientApp.Start(Seconds(2.0));

clientApp.Stop(Seconds(10.0));

Simulator::Run();

Simulator::Destroy();

return 0;

}

  1. Add Network Complexity

When it comfortable with the fundamentals then we can append complexity to the network:

  • Multiple Nodes: Make larger topologies by way of associating several nodes.
  • Varied Connections: Aggregate the Point-to-Point, WiFi, or CSMA (Ethernet) links.
  • Routing Protocols: For dynamic routing, utilize routing protocols such as OLSR, AODV, or custom protocols.

Example: Simple Star Network with CSMA

In this instance, a star topology including a central server and several client nodes is made by Ethernet (CSMA) links.

#include “ns3/core-module.h”

#include “ns3/network-module.h”

#include “ns3/internet-module.h”

#include “ns3/csma-module.h”

#include “ns3/applications-module.h”

using namespace ns3;

int main(int argc, char *argv[]) {

CommandLine cmd;

cmd.Parse(argc, argv);

// Create nodes: one central server and four client nodes

NodeContainer serverNode;

serverNode.Create(1);

NodeContainer clientNodes;

clientNodes.Create(4);

NodeContainer allNodes = NodeContainer(serverNode, clientNodes);

// Set up CSMA (Ethernet) channel

CsmaHelper csma;

csma.SetChannelAttribute(“DataRate”, StringValue(“100Mbps”));

csma.SetChannelAttribute(“Delay”, TimeValue(NanoSeconds(6560)));

NetDeviceContainer csmaDevices = csma.Install(allNodes);

// Install Internet stack on all nodes

InternetStackHelper stack;

stack.Install(allNodes);

// Assign IP addresses

Ipv4AddressHelper address;

address.SetBase(“192.168.1.0”, “255.255.255.0”);

Ipv4InterfaceContainer interfaces = address.Assign(csmaDevices);

// Set up a UDP server on the central server node

uint16_t port = 9;

UdpEchoServerHelper echoServer(port);

ApplicationContainer serverApp = echoServer.Install(serverNode.Get(0));

serverApp.Start(Seconds(1.0));

serverApp.Stop(Seconds(10.0));

// Set up UDP clients on each client node

for (uint32_t i = 0; i < clientNodes.GetN(); ++i) {

UdpEchoClientHelper echoClient(interfaces.GetAddress(0), port); // Server IP

echoClient.SetAttribute(“MaxPackets”, UintegerValue(10));

echoClient.SetAttribute(“Interval”, TimeValue(Seconds(1.0)));

echoClient.SetAttribute(“PacketSize”, UintegerValue(1024));

ApplicationContainer clientApp = echoClient.Install(clientNodes.Get(i));

clientApp.Start(Seconds(2.0 + i));

clientApp.Stop(Seconds(10.0));

}

Simulator::Run();

Simulator::Destroy();

return 0;

}

  1. Experiment with Different Protocols

NS3 permits diverse network protocols:

  • TCP/UDP: Experiment diverse transport protocols by way of configuring TCP or UDP applications.
  • Routing Protocols: Utilize protocols such as OLSR, AODV for multi-hop networks, or custom routing protocols for dynamic routing.

For instance, we make a TCP-based application, to utilize OnOffHelper rather than UdpEchoHelper.

  1. Monitor and Collect Performance Metrics

For network performance analysis, we can accumulate parameters such as:

  • Throughput: Data rate among the nodes.
  • Latency: Delay between packet transmission and reception.
  • Packet Loss: During transmission, estimate the packets dropped.

Collect performance data utilizing NS3’s FlowMonitor:

FlowMonitorHelper flowmonHelper;

Ptr<FlowMonitor> monitor = flowmonHelper.InstallAll();

monitor->SerializeToXmlFile(“network-flowmon.xml”, true, true);

  1. Visualize the Network

We need to envision the simulation:

  • NetAnim: Visualize the topology, packet flow, and node movement in real-time utilizing NetAnim.
  • Trace Files: NS3 makes trace files for performance data, which can be examined.
  • Graphing Tools: Transfer trace data to graph parameters such as throughput and delay over time.
  1. Experiment with Network Configurations

Modify diverse sets up to know the network performance’s effect:

  • Network Size: Maximize the volume of nodes to experiment the scalability.
  • Link Characteristics: Modify data rates, delays, or packet loss rates at links.
  • Application Types: Test with distinct applications like video streaming, VoIP, or file transfer, replicating the real-world situations.

Through this manual, we clearly explain how to start, analyse and visualize the Network project using NS3 with the help of offered detailed procedure with sample coding snippet. We plan to deliver more information related to this network projects in upcoming manual.

Reach out to us for personalized assistance regarding configuration and network projects utilizing NS3 simulation. For innovative outcomes, please visit phdprojects.org, where we effectively manage performance estimation, protocol experimentation, and topology design.