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 Logical Topology in NS3

To implement a logical topology using NS3 we need to replicate the abstract links among the nodes that could not directly reflect the physical associations. Logical topologies are denoting how data flows among the nodes in spite of the physical arrangement. Below is a detailed guide to get started:

Steps to Begin Implement Logical Topology in NS3

  1. Understand Logical Topologies
  • Logical topology is according to the data flow or interaction paths among the nodes.
  • Instance of logical topologies:
    • Star: A central hub interacts with every node.
    • Ring: These nodes communicate within a circular arrangement.
    • Mesh: Logically each node associates to every other node.
    • Custom: Arbitrary logical connections among the nodes.
  1. Set Up NS3
  1. Install NS3:
    • We should install and download NS3 environment on the system.
    • Test the installation by executing:

./waf –run hello-simulator

  1. Install Wireshark:
    • Examine the network traffic with the help of .pcap files in wireshark.
  1. Design a Logical Topology

A logical topology can be executed by point-to-point links, CSMA, or a mix which is relying on the required structure.

Example 1: Logical Star Topology

In a star topology:

  • One node performs like a central hub.
  • All other nodes only interact with the hub.

NodeContainer nodes;

nodes.Create(5); // 1 hub + 4 spokes

PointToPointHelper p2p;

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

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

NetDeviceContainer devices;

for (uint32_t i = 1; i < nodes.GetN(); ++i) {

devices.Add(p2p.Install(nodes.Get(0), nodes.Get(i))); // Hub is node 0

}

InternetStackHelper stack;

stack.Install(nodes);

Ipv4AddressHelper address;

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”);

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

}

Example 2: Logical Ring Topology

In a ring topology:

  • Every single node is linked to two neighbors to make a loop.

NodeContainer nodes;

nodes.Create(6); // Create 6 nodes in a ring

PointToPointHelper p2p;

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

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

NetDeviceContainer devices;

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

devices.Add(p2p.Install(nodes.Get(i), nodes.Get((i + 1) % nodes.GetN()))); // Connect in a loop

}

InternetStackHelper stack;

stack.Install(nodes);

Ipv4AddressHelper address;

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”);

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

}

Example 3: Logical Mesh Topology

In a mesh topology:

  • Logically all other node interacted by each node.

NodeContainer nodes;

nodes.Create(4); // Create 4 nodes

PointToPointHelper p2p;

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

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

NetDeviceContainer devices;

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

for (uint32_t j = i + 1; j < nodes.GetN(); ++j) {

devices.Add(p2p.Install(nodes.Get(i), nodes.Get(j)));

}

}

InternetStackHelper stack;

stack.Install(nodes);

Ipv4AddressHelper address;

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”);

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

}

  1. Assign Logical Roles

Set up applications or routes for describing the data flow after configuring the logical connections.

Example Application for Communication

We should install applications at nodes for replicating the communication.

UdpEchoServerHelper echoServer(9);

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

serverApps.Start(Seconds(1.0));

serverApps.Stop(Seconds(10.0));

UdpEchoClientHelper echoClient(Ipv4Address(“192.168.1.1”), 9);

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

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

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

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

clientApps.Start(Seconds(2.0));

clientApps.Stop(Seconds(10.0));

  1. Enable Tracing

Allow tracing to seize the packets for packet inspection:

p2p.EnablePcapAll(“logical-topology”);

  1. Run the Simulation

Build and run the simulation script in logical topology:

./waf –run logical-topology

  1. Example Code Skeleton

Below is a sample NS3 script for implementing a star logical 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[]) {

// Create nodes

NodeContainer nodes;

nodes.Create(5); // 1 hub + 4 spokes

// Configure Point-to-Point links

PointToPointHelper p2p;

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

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

NetDeviceContainer devices;

for (uint32_t i = 1; i < nodes.GetN(); ++i) {

devices.Add(p2p.Install(nodes.Get(0), nodes.Get(i))); // Hub is node 0

}

// Install Internet stack

InternetStackHelper stack;

stack.Install(nodes);

// Assign IP addresses

Ipv4AddressHelper address;

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”);

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

}

// Set up server application

UdpEchoServerHelper echoServer(9);

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

serverApps.Start(Seconds(1.0));

serverApps.Stop(Seconds(10.0));

// Set up client applications

UdpEchoClientHelper echoClient(Ipv4Address(“192.168.1.1”), 9);

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

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

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

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

clientApps.Start(Seconds(2.0));

clientApps.Stop(Seconds(10.0));

// Enable packet capture

p2p.EnablePcapAll(“logical-topology”);

// Run simulation

Simulator::Run();

Simulator::Destroy();

return 0;

}

  1. Extend the Simulation
  • Add More Nodes: Maximize the volume of nodes within the topology.
  • Vary Topologies: Add numerous logical topologies such as ring and mesh.
  • Analyze Performance: Estimate the performance parameters like throughput, latency, and packet loss for various configurations.

Here, Logical Topology has been successfully implemented and analyzed using NS3, employing an innovative approach, with a detailed explanation to follow in the upcoming manual.