How to Start Cluster Topology Projects Using NS3

To start Cluster Topology using NS3 which gathers nodes to clusters, each cluster handled by a central node that is called as a cluster head. Cluster-based topologies are extensively utilized within wireless sensor networks, IoT networks, and hierarchical networking configurations. Below is a basic approach to start and simulate the Cluster Topology Projects in NS3 tool.

Steps to Start Cluster Topology Project in NS3

Step 1: Set Up NS3

  1. Install NS3:
    • Go to NS3 webpage to download NS3.
    • We adhere to the installation steps.
  2. Verify Installation: Execute a simple NS3 script making sure that functionality:

./waf –run scratch/my_first

Step 2: Understand Cluster Topology

  • Cluster Topology:
    • Nodes are splitted to clusters including each cluster to contain a cluster head.
    • For inter-cluster interaction, cluster heads can associate to other cluster heads or a central node.
    • This topology frequently utilized in hierarchical networking models for scalability and energy efficiency.

Step 3: Plan the Topology

  1. Define the network structure:
    • For instance:
      • We can define the network structure that has 2 clusters.
      • Every single cluster contains 1 cluster head and 5 regular nodes.
      • Cluster heads interact with a central node.
  2. Set simulation goals:
    • We can replicate an intra-cluster and inter-cluster interaction.
    • Compute the performance parameters such as delay, throughput, and energy efficiency.

Step 4: Set Up the Cluster Topology

  1. Create Nodes: We can describe the nodes for clusters, cluster heads, and the central node.

NodeContainer centralNode;

centralNode.Create(1); // Central node

NodeContainer clusterHeads;

clusterHeads.Create(2); // Two cluster heads

NodeContainer clusterNodes[2];

for (int i = 0; i < 2; ++i) {

clusterNodes[i].Create(5); // Five nodes per cluster

}

  1. Set Up Point-to-Point Links: Describe the links properties to utilize PointToPointHelper.

PointToPointHelper p2p;

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

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

  1. Connect Cluster Heads to the Central Node: Make links among the cluster heads and the central node.

NetDeviceContainer centralToClusterDevices;

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

NetDeviceContainer link = p2p.Install(centralNode.Get(0), clusterHeads.Get(i));

centralToClusterDevices.Add(link);

}

  1. Connect Cluster Nodes to Their Cluster Head: We able to make links among each cluster’s nodes and its corresponding cluster head.

NetDeviceContainer clusterDevices[2];

for (int i = 0; i < 2; ++i) {

for (uint32_t j = 0; j < clusterNodes[i].GetN(); ++j) {

NetDeviceContainer link = p2p.Install(clusterHeads.Get(i), clusterNodes[i].Get(j));

clusterDevices[i].Add(link);

}

}

  1. Install Internet Stack: Add the Internet stack to all nodes.

InternetStackHelper stack;

stack.Install(centralNode);

stack.Install(clusterHeads);

for (int i = 0; i < 2; ++i) {

stack.Install(clusterNodes[i]);

}

  1. Assign IP Addresses: We allocate a unique IP addresses to each link.

Ipv4AddressHelper address;

uint32_t subnetIndex = 1;

// Assign IPs for cluster heads to central node links

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

std::ostringstream subnet;

subnet << “10.1.” << subnetIndex++ << “.0”;

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

address.Assign(centralToClusterDevices.Get(i));

}

// Assign IPs for cluster nodes to cluster head links

for (int i = 0; i < 2; ++i) {

for (uint32_t j = 0; j < clusterDevices[i].GetN(); ++j) {

std::ostringstream subnet;

subnet << “10.1.” << subnetIndex++ << “.0”;

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

address.Assign(clusterDevices[i].Get(j));

}

}

Step 5: Set Up Applications

  1. Server Application: We need to insert a UDP echo server at central node.

UdpEchoServerHelper echoServer(9); // Port 9

ApplicationContainer serverApp = echoServer.Install(centralNode.Get(0)); // Central node

serverApp.Start(Seconds(1.0));

serverApp.Stop(Seconds(10.0));

  1. Client Applications: We install UDP echo clients at cluster nodes interacting with the central node.

for (int i = 0; i < 2; ++i) {

for (uint32_t j = 0; j < clusterNodes[i].GetN(); ++j) {

UdpEchoClientHelper echoClient(Ipv4Address(“10.1.1.1”), 9); // Central node’s IP

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

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

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

ApplicationContainer clientApp = echoClient.Install(clusterNodes[i].Get(j));

clientApp.Start(Seconds(2.0));

clientApp.Stop(Seconds(10.0));

}

}

Step 6: Run and Analyze

  1. Run the Simulation:

Simulator::Run();

Simulator::Destroy();

  1. Enable Packet Capture: We can store .pcap files for traffic analysis.

p2p.EnablePcapAll(“cluster_topology”);

  1. Trace Logs: Allow logging for debugging:

export NS_LOG=”UdpEchoClientApplication=level_all|prefix_func”

./waf –run scratch/cluster_topology

Example: Minimal NS3 Script for Cluster 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[]) {

NodeContainer centralNode;

centralNode.Create(1);

NodeContainer clusterHeads;

clusterHeads.Create(2);

NodeContainer clusterNodes[2];

for (int i = 0; i < 2; ++i) {

clusterNodes[i].Create(5);

}

PointToPointHelper p2p;

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

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

NetDeviceContainer centralToClusterDevices;

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

NetDeviceContainer link = p2p.Install(centralNode.Get(0), clusterHeads.Get(i));

centralToClusterDevices.Add(link);

}

NetDeviceContainer clusterDevices[2];

for (int i = 0; i < 2; ++i) {

for (uint32_t j = 0; j < clusterNodes[i].GetN(); ++j) {

NetDeviceContainer link = p2p.Install(clusterHeads.Get(i), clusterNodes[i].Get(j));

clusterDevices[i].Add(link);

}

}

InternetStackHelper stack;

stack.Install(centralNode);

stack.Install(clusterHeads);

for (int i = 0; i < 2; ++i) {

stack.Install(clusterNodes[i]);

}

Ipv4AddressHelper address;

uint32_t

for (uint32_t i = 0; i < centralToClusterDevices.GetN(); ++i) { std::ostringstream subnet; subnet << “10.1.” << subnetIndex++ << “.0”; address.SetBase(subnet.str().c_str(), “255.255.255.0”); address.Assign(centralToClusterDevices.Get(i)); } for (int i = 0; i < 2; ++i) { for (uint32_t j = 0; j < clusterDevices[i].GetN(); ++j) { std::ostringstream subnet; subnet << “10.1.” << subnetIndex++ << “.0”; address.SetBase(subnet.str().c_str(), “255.255.255.0”); address.Assign(clusterDevices[i].Get(j)); } } UdpEchoServerHelper echoServer(9); ApplicationContainer serverApp = echoServer.Install(centralNode.Get(0)); serverApp.Start(Seconds(1.0));

We have articulated the structured procedure of this project for simulating and analysing Cluster Topology with the support of NS3 environment and we are ready to elaborate with additional details upon demand. Send usĀ  message of your project details we will provide you with tailored research assistance.