Ns3 Projects for B.E/B.Tech M.E/M.Tech PhD Scholars.  Phone-Number:9790238391   E-mail: ns3simulation@gmail.com

How to Begin Implement Circular Topology in NS3

To implement and analyze a circular topology using NS3 which needs to associate the nodes within a ring in which every single node links to two other nodes for generating a closed-loop network. This topology is generally utilised for replicating token ring networks or scenarios in which redundancy and fault tolerance are crucial.

Below is a comprehensive mechanism to get started with implementing a Circular Topology in NS3:

Steps to Begin Implement Circular Topology in NS3

  1. Understand the Circular Topology
  • Every single node is linked to two neighbors for generating a closed loop.
  • Data packets can pass through the network in any direction.
  • Provides redundancy: Packets can even attain its end through the opposite direction if one link fails.
  1. Set Up NS3
  1. Install NS3:
    • We can download and install NS3 on the system.
    • Confirm the installation by executing:

./waf –run hello-simulator

  1. Install Wireshark (optional):
    • Examine .pcap files which are made by NS3 leveraging Wireshark.
  1. Design the Circular Topology

Make a circular topology with the nodes and associate them within a ring.

Define the Nodes

NodeContainer nodes;

uint32_t nNodes = 6; // Number of nodes in the circular topology

nodes.Create(nNodes);

Connect the Nodes in a Circle

Associate each node to their neighbors and close the loop with the support of PointToPointHelper:

PointToPointHelper p2p;

p2p.SetDeviceAttribute(“DataRate”, StringValue(“10Mbps”));

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

NetDeviceContainer devices;

for (uint32_t i = 0; i < nNodes; ++i) {

devices.Add(p2p.Install(nodes.Get(i), nodes.Get((i + 1) % nNodes))); // Connect i to (i+1)%nNodes

}

  1. Assign IP Addresses

We need to install the Internet stack and allocate an IP addresses to every link:

InternetStackHelper stack;

stack.Install(nodes);

Ipv4AddressHelper address;

std::vector<Ipv4InterfaceContainer> interfaces;

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

std::ostringstream subnet;

subnet << “192.168.” << i / 2 + 1 << “.0”; // Each link gets a unique subnet

address.SetBase(subnet.str().c_str(), “255.255.255.0”);

Ipv4InterfaceContainer iface = address.Assign(NetDeviceContainer(devices.Get(i), devices.Get(i + 1)));

interfaces.push_back(iface);

}

  1. Simulate Communication

Configure interaction among the certain nodes. For instance:

  • Node 0 behaves as a client.
  • Node 3 performs like a server.

Server Application

We will need to install a UDP echo server at Node 3:

UdpEchoServerHelper echoServer(9); // Server listens on port 9

ApplicationContainer serverApps = echoServer.Install(nodes.Get(3)); // Node 3 is the server

serverApps.Start(Seconds(1.0));

serverApps.Stop(Seconds(10.0));

Client Application

At Node 0, we can install a UDP echo client:

UdpEchoClientHelper echoClient(Ipv4Address(“192.168.2.2”), 9); // Node 3’s IP

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

echoClient.SetAttribute(“Interval”, TimeValue(Seconds(1.0))); // 1-second intervals

echoClient.SetAttribute(“PacketSize”, UintegerValue(1024)); // 1 KB packets

ApplicationContainer clientApps = echoClient.Install(nodes.Get(0)); // Node 0 is the client

clientApps.Start(Seconds(2.0));

clientApps.Stop(Seconds(10.0));

  1. Enable Packet Capture

Allow .pcap tracing for packet inspection:

p2p.EnablePcapAll(“circular-topology”);

  1. Run the Simulation

Here, run the simulation script in circular topology:

./waf –run circular-topology

  1. Example Code Skeleton

Below is a comprehensive structure of NS3 script for a circular topology:

#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[]) {

uint32_t nNodes = 6; // Number of nodes in the circular topology

// Create nodes

NodeContainer nodes;

nodes.Create(nNodes);

// Configure Point-to-Point links

PointToPointHelper p2p;

p2p.SetDeviceAttribute(“DataRate”, StringValue(“10Mbps”));

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

NetDeviceContainer devices;

// Connect nodes in a circular topology

for (uint32_t i = 0; i < nNodes; ++i) {

devices.Add(p2p.Install(nodes.Get(i), nodes.Get((i + 1) % nNodes))); // Connect i to (i+1)%nNodes

}

// Install Internet stack

InternetStackHelper stack;

stack.Install(nodes);

// Assign IP addresses

Ipv4AddressHelper address;

std::vector<Ipv4InterfaceContainer> interfaces;

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

std::ostringstream subnet;

subnet << “192.168.” << i / 2 + 1 << “.0”;

address.SetBase(subnet.str().c_str(), “255.255.255.0”);

Ipv4InterfaceContainer iface = address.Assign(NetDeviceContainer(devices.Get(i), devices.Get(i + 1)));

interfaces.push_back(iface);

}

// Set up server application

UdpEchoServerHelper echoServer(9);

ApplicationContainer serverApps = echoServer.Install(nodes.Get(3)); // Node 3 is the server

serverApps.Start(Seconds(1.0));

serverApps.Stop(Seconds(10.0));

// Set up client application

UdpEchoClientHelper echoClient(interfaces[1].GetAddress(1), 9); // Node 3’s IP

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

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

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

ApplicationContainer clientApps = echoClient.Install(nodes.Get(0)); // Node 0 is the client

clientApps.Start(Seconds(2.0));

clientApps.Stop(Seconds(10.0));

// Enable packet capture

p2p.EnablePcapAll(“circular-topology”);

// Run simulation

Simulator::Run();

Simulator::Destroy();

return 0;

}

  1. Extend the Simulation
  • Add More Nodes: In the ring, maximize the amount of nodes.
  • Simulate Failures: Detach a link and then monitor how data redirects within the loop.
  • Analyze Performance: Estimate the performance parameters such as delay, throughput, and packet loss.

By leveraging these steps, we were capable of implementing and examining the Circular Topology in NS3 simulator. If you have concerns or queries, they will be addressed in an upcoming guide.