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

How to Implement Cluster Topology in ns3

To implement the cluster topology in ns3 has encompasses to forming the nodes into clusters with each cluster had a cluster head that interact with other cluster heads or a base station.in the given below is the detailed procedure on how to achieve this in ns3:

Step-by-Step Implementation:

Step 1: Install ns3

  • Make certain ns3 is installed in the computer and configured correctly.

Step 2: Create a New Simulation Script

  • Create a new C++ script for your simulation.

Step 3: Include Necessary Headers

  • In your script, include the necessary ns3 headers:

#include “ns3/core-module.h”

#include “ns3/network-module.h”

#include “ns3/internet-module.h”

#include “ns3/applications-module.h”

#include “ns3/mobility-module.h”

#include “ns3/wifi-module.h”

Step 4: Set Up the Cluster Topology

We offer the instance on how to setup a cluster topology with three clusters, each having a cluster head and several member nodes:

using namespace ns3;

NS_LOG_COMPONENT_DEFINE (“ClusterTopology”);

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

{

// Configure command line parameters

CommandLine cmd;

cmd.Parse (argc, argv);

// Create nodes

NodeContainer clusterHeads;

clusterHeads.Create (3); // Create 3 cluster heads

NodeContainer cluster1Nodes, cluster2Nodes, cluster3Nodes;

cluster1Nodes.Create (5); // Create 5 nodes for cluster 1

cluster2Nodes.Create (5); // Create 5 nodes for cluster 2

cluster3Nodes.Create (5); // Create 5 nodes for cluster 3

// Configure Mobility

MobilityHelper mobility;

// Set cluster head positions

Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator> ();

positionAlloc->Add (Vector (50.0, 50.0, 0.0)); // Cluster 1 head position

positionAlloc->Add (Vector (150.0, 50.0, 0.0)); // Cluster 2 head position

positionAlloc->Add (Vector (250.0, 50.0, 0.0)); // Cluster 3 head position

mobility.SetPositionAllocator (positionAlloc);

mobility.SetMobilityModel (“ns3::ConstantPositionMobilityModel”);

mobility.Install (clusterHeads);

// Set cluster 1 node positions around the cluster head

Ptr<PositionAllocator> cluster1PosAlloc = CreateObjectWithAttributes<RandomRectanglePositionAllocator> (

“X”, StringValue (“ns3::UniformRandomVariable[Min=40.0|Max=60.0]”),

“Y”, StringValue (“ns3::UniformRandomVariable[Min=40.0|Max=60.0]”));

mobility.SetPositionAllocator (cluster1PosAlloc);

mobility.Install (cluster1Nodes);

// Set cluster 2 node positions around the cluster head

Ptr<PositionAllocator> cluster2PosAlloc = CreateObjectWithAttributes<RandomRectanglePositionAllocator> (

“X”, StringValue (“ns3::UniformRandomVariable[Min=140.0|Max=160.0]”),

“Y”, StringValue (“ns3::UniformRandomVariable[Min=40.0|Max=60.0]”));

mobility.SetPositionAllocator (cluster2PosAlloc);

mobility.Install (cluster2Nodes);

// Set cluster 3 node positions around the cluster head

Ptr<PositionAllocator> cluster3PosAlloc = CreateObjectWithAttributes<RandomRectanglePositionAllocator> (

“X”, StringValue (“ns3::UniformRandomVariable[Min=240.0|Max=260.0]”),

“Y”, StringValue (“ns3::UniformRandomVariable[Min=40.0|Max=60.0]”));

mobility.SetPositionAllocator (cluster3PosAlloc);

mobility.Install (cluster3Nodes);

// Set up WiFi

WifiHelper wifi;

wifi.SetStandard (WIFI_PHY_STANDARD_80211g);

YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default ();

YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default ();

wifiPhy.SetChannel (wifiChannel.Create ());

WifiMacHelper wifiMac;

wifi.SetRemoteStationManager (“ns3::AarfWifiManager”);

Ssid ssid = Ssid (“ns-3-cluster”);

// Set up WiFi for cluster heads

wifiMac.SetType (“ns3::AdhocWifiMac”, “Ssid”, SsidValue (ssid));

NetDeviceContainer clusterHeadDevices = wifi.Install (wifiPhy, wifiMac, clusterHeads);

// Set up WiFi for cluster 1 nodes

NetDeviceContainer cluster1Devices = wifi.Install (wifiPhy, wifiMac, cluster1Nodes);

// Set up WiFi for cluster 2 nodes

NetDeviceContainer cluster2Devices = wifi.Install (wifiPhy, wifiMac, cluster2Nodes);

// Set up WiFi for cluster 3 nodes

NetDeviceContainer cluster3Devices = wifi.Install (wifiPhy, wifiMac, cluster3Nodes);

// Install the IP stack

InternetStackHelper internet;

internet.Install (clusterHeads);

internet.Install (cluster1Nodes);

internet.Install (cluster2Nodes);

internet.Install (cluster3Nodes);

// Assign IP addresses

Ipv4AddressHelper ipv4;

ipv4.SetBase (“10.1.1.0”, “255.255.255.0”);

Ipv4InterfaceContainer clusterHeadInterfaces = ipv4.Assign (clusterHeadDevices);

Ipv4InterfaceContainer cluster1Interfaces = ipv4.Assign (cluster1Devices);

ipv4.SetBase (“10.1.2.0”, “255.255.255.0”);

Ipv4InterfaceContainer cluster2Interfaces = ipv4.Assign (cluster2Devices);

ipv4.SetBase (“10.1.3.0”, “255.255.255.0”);

Ipv4InterfaceContainer cluster3Interfaces = ipv4.Assign (cluster3Devices);

// Set up applications (e.g., UDP echo server and client)

uint16_t port = 9; // Port number for applications

// Install UDP Echo Server on cluster head 1

UdpEchoServerHelper echoServer (port);

ApplicationContainer serverApps = echoServer.Install (clusterHeads.Get (0));

serverApps.Start (Seconds (1.0));

serverApps.Stop (Seconds (10.0));

// Install UDP Echo Client on a node in cluster 2 to communicate with cluster head 1

UdpEchoClientHelper echoClient (clusterHeadInterfaces.GetAddress (0), port);

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

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

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

ApplicationContainer clientApps = echoClient.Install (cluster2Nodes.Get (0));

clientApps.Start (Seconds (2.0));

clientApps.Stop (Seconds (10.0));

// Run simulation

Simulator::Stop (Seconds (10.0));

Simulator::Run ();

Simulator::Destroy ();

return 0;

}

Step 5: Build and Run the Simulation

  1. Save the script as cluster-topology.cc.
  2. Build the script using waf:

./waf configure –enable-examples

./waf build

  1. Run the simulation:

./waf –run scratch/cluster-topology

Explanation of the Script

  • Node Creation: Creates three cluster heads and three clusters, each with five nodes.
  • Mobility Model: Sets the mobility model to ConstantPositionMobilityModel and places the cluster heads at specific positions and the cluster nodes around them.
  • WiFi Setup: Configures WiFi settings for the nodes.
  • IP Stack and Addressing: Installs the IP stack on all nodes and assigns IP addresses.
  • Applications: Sets up a UDP echo server on one of the cluster heads and a UDP echo client on a node from another cluster to demonstrate inter-cluster communication.

So here, we talked about the performance of Cluster Topology in ns3 and how it can adapt to various frameworks. Kindly provide us with your parameters for further implementation support.