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

How to Implement Hierarchical Star Topology in ns3

To implement a ring-mesh hybrid topology in ns3, we need to create a network in which the nodes are connected to both ring topology and mesh topology. Here we can use point-to-point link for Ring Topology and CSMA links for Mesh Topology.

The below given steps will guide on how to implement topology in ns3.

Step-by-step to implement the topology in ns3

Step 1: Install ns3

Make sure ns3 is installed on the system

Step 2: Create a New Simulation Script

Create a new C++ script for the simulation.

Step 3: Include Necessary Headers

In the script, include the necessary ns3 headers:

#include “ns3/core-module.h”

#include “ns3/network-module.h”

#include “ns3/internet-module.h”

#include “ns3/point-to-point-module.h”

#include “ns3/csma-module.h”

#include “ns3/mobility-module.h”

#include “ns3/applications-module.h”

Step 4: Set Up the Ring-Mesh Hybrid Topology

Below given example script guide to set up a ring-mesh hybrid topology with six nodes:

using namespace ns3;

NS_LOG_COMPONENT_DEFINE (“RingMeshHybridTopology”);

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

{

// Configure command line parameters

CommandLine cmd;

cmd.Parse (argc, argv);

// Create nodes

NodeContainer nodes;

nodes.Create (6); // Create 6 nodes for the ring-mesh hybrid network

// Create point-to-point links to form a ring topology

PointToPointHelper pointToPoint;

pointToPoint.SetDeviceAttribute (“DataRate”, StringValue (“1Gbps”));

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

NetDeviceContainer devices;

Ipv4AddressHelper address;

Ipv4InterfaceContainer interfaces;

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

{

NodeContainer pair (nodes.Get (i), nodes.Get ((i + 1) % nodes.GetN ()));

NetDeviceContainer devicePair = pointToPoint.Install (pair);

devices.Add (devicePair);

 

std::ostringstream subnet;

subnet << “10.1.” << i << “.0”;

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

interfaces.Add (address.Assign (devicePair));

}

// Create CSMA links to form a mesh topology among the nodes

CsmaHelper csma;

csma.SetChannelAttribute (“DataRate”, StringValue (“1Gbps”));

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

NetDeviceContainer meshDevices;

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

{

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

{

NodeContainer pair (nodes.Get (i), nodes.Get (j));

NetDeviceContainer devicePair = csma.Install (pair);

meshDevices.Add (devicePair);

std::ostringstream subnet;

subnet << “10.2.” << i << “.” << j << “.0”;

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

interfaces.Add (address.Assign (devicePair));

}

}

// Install the internet stack

InternetStackHelper stack;

stack.Install (nodes);

// Assign IP addresses to the ring and mesh devices

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

{

Ipv4AddressHelper ipv4;

std::ostringstream subnet;

subnet << “10.1.” << (i / 2 + 1) << “.0”;

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

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

}

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

{

Ipv4AddressHelper ipv4;

std::ostringstream subnet;

subnet << “10.2.” << (i / 2 + 1) << “.0”;

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

ipv4.Assign (NetDeviceContainer (meshDevices.Get (i), meshDevices.Get (i + 1)));

}

// Set up mobility model (optional)

MobilityHelper mobility;

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

positionAlloc->Add (Vector (50.0, 50.0, 0.0)); // Node 0 position

positionAlloc->Add (Vector (100.0, 50.0, 0.0)); // Node 1 position

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

positionAlloc->Add (Vector (150.0, 100.0, 0.0)); // Node 3 position

positionAlloc->Add (Vector (100.0, 100.0, 0.0)); // Node 4 position

positionAlloc->Add (Vector (50.0, 100.0, 0.0)); // Node 5 position

mobility.SetPositionAllocator (positionAlloc);

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

mobility.Install (nodes);

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

uint16_t port = 9; // Port number for applications

// Install UDP Echo Server on node 0

UdpEchoServerHelper echoServer (port);

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

serverApps.Start (Seconds (1.0));

serverApps.Stop (Seconds (10.0));

// Install UDP Echo Clients on other nodes to communicate with node 0

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

{

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

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

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

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

ApplicationContainer clientApps = echoClient.Install (nodes.Get (i));

clientApps.Start (Seconds (2.0 + i)); // Stagger start times

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 ring-mesh-hybrid-topology.cc.
  2. Build the script using waf:

./waf configure –enable-examples

./waf build

  1. Run the simulation:

./waf –run scratch/ring-mesh-hybrid-topology

Explanation of the Script

  • Node Creation: Creates six nodes for the ring-mesh hybrid network.
  • Point-to-Point Links (Ring Topology): Configures point-to-point links to form a ring topology among the nodes.
  • CSMA Links (Mesh Topology): Uses CSMA links to interconnect the nodes in a mesh topology.
  • Internet Stack: Installs the internet stack on all nodes.
  • IP Addressing: Assigns IP addresses to both the ring and mesh devices using different subnets.
  • Mobility Model: (Optional) Sets the position of nodes in a specific layout using ListPositionAllocator and ConstantPositionMobilityModel.
  • Applications: Sets up a UDP echo server on node 0 and UDP echo clients on other nodes to demonstrate communication between nodes.

The basics instructions are provided above to set up a ring-mesh hybrid Topology in ns3 and the simulation process is explained elaborately.

All types of project Implementation on Hierarchical Star Topology in ns3 are carried on by us so for best outcome feel free to contact us.