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 Topology in ns3

To implement a hierarchical topology in ns3, we need to follow several steps. Because, this type of topology is created by a multi-tier network structure where nodes are aligned in a hierarchy model which is commonly used in large-scale networks such as data centers and enterprise networks. The given below steps will guide on how to implement hierarchical topology in ns3.

Step-by-step to Implement a Hierarchical Topology in ns3

  1. Set Up the ns3 Environment:
    • Make sure  ns3 is installed and properly configured.
  2. Create the Nodes:
    • Create nodes to represent the different levels in the hierarchy, such as core, aggregation, and edge layers.
  3. Set Up the Point-to-Point Channels:
    • Use point-to-point helpers to connect the nodes within and across different hierarchical levels.
  4. Install Network Stack:
    • Install the internet stack on all nodes.
  5. Assign IP Addresses:
    • Assign IP addresses to the nodes connected by the point-to-point links.
  6. Set Up Applications:
    • Install applications to generate traffic and demonstrate communication between nodes.

Example Code

Here an example given to set up a simple hierarchical topology in ns3:

#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;

NS_LOG_COMPONENT_DEFINE (“HierarchicalTopologyExample”);

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

{

CommandLine cmd;

cmd.Parse (argc, argv);

// Create nodes

NodeContainer coreNodes;

coreNodes.Create (2); // Two core nodes

NodeContainer aggregationNodes;

aggregationNodes.Create (4); // Four aggregation nodes

NodeContainer edgeNodes;

edgeNodes.Create (8); // Eight edge nodes

// Create point-to-point links

PointToPointHelper pointToPoint;

pointToPoint.SetDeviceAttribute (“DataRate”, StringValue (“100Mbps”));

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

InternetStackHelper stack;

stack.Install (coreNodes);

stack.Install (aggregationNodes);

stack.Install (edgeNodes);

Ipv4AddressHelper address;

int subnet = 1;

// Connect core nodes to aggregation nodes

auto connectNodes = [&](NodeContainer& parentNodes, NodeContainer& childNodes, uint32_t parentIdx, uint32_t childIdx) {

NetDeviceContainer devices = pointToPoint.Install (NodeContainer (parentNodes.Get (parentIdx), childNodes.Get (childIdx)));

std::ostringstream subnetStream;

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

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

address.Assign (devices);

};

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

{

for (uint32_t j = 0; j < aggregationNodes.GetN (); ++j)

{

connectNodes(coreNodes, aggregationNodes, i, j);

}

}

// Connect aggregation nodes to edge nodes

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

{

for (uint32_t j = 0; j < edgeNodes.GetN () / aggregationNodes.GetN (); ++j)

{

connectNodes(aggregationNodes, edgeNodes, i, i * (edgeNodes.GetN () / aggregationNodes.GetN ()) + j);

}

}

// Enable routing

Ipv4GlobalRoutingHelper::PopulateRoutingTables ();

// Create a UDP server on one of the edge nodes

UdpServerHelper udpServer (9);

ApplicationContainer serverApp = udpServer.Install (edgeNodes.Get (0));

serverApp.Start (Seconds (1.0));

serverApp.Stop (Seconds (10.0));

// Create a UDP client on another edge node

UdpClientHelper udpClient (Ipv4Address (“10.1.9.1”), 9); // Assuming the server node’s IP is 10.1.9.1

udpClient.SetAttribute (“MaxPackets”, UintegerValue (320));

udpClient.SetAttribute (“Interval”, TimeValue (MilliSeconds (50)));

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

ApplicationContainer clientApp = udpClient.Install (edgeNodes.Get (7));

clientApp.Start (Seconds (2.0));

clientApp.Stop (Seconds (10.0));

// Enable packet capture

pointToPoint.EnablePcapAll (“hierarchical-topology”);

// Enable logging

LogComponentEnable (“UdpClient”, LOG_LEVEL_INFO);

LogComponentEnable (“UdpServer”, LOG_LEVEL_INFO);

Simulator::Run ();

Simulator::Destroy ();

return 0;

}

Explanation

  1. Setup: The code sets up a hierarchical topology with two core nodes, four aggregation nodes, and eight edge nodes connected by point-to-point links.
  2. Point-to-Point Links: Point-to-point links are created to connect core nodes to aggregation nodes and aggregation nodes to edge nodes. The data rate and delay are configured for the links.
  3. Network Stack: The internet stack is installed on all nodes.
  4. IP Addresses: IP addresses connected by the point-to-point links that are assigned to the nodes.
  5. Applications: A UDP server is installed on one of the edge nodes, and a UDP client is installed on another edge node to generate traffic and demonstrate communication.
  6. Packet Capture: Packet capture is enabled for the point-to-point links to observe network traffic.
  7. Logging: Logging is enabled for the UDP client and server applications to provide detailed output during the simulation.

Running the Simulation

Compile and run the simulation using the following commands in ns3 environment:

./waf configure

./waf build

./waf –run hierarchical-topology-example

Replace hierarchical-topology-example with the actual name of the script file.

The implementation process of Hierarchical topology is explained clearly with the example of setting up a simple hierarchical topology in ns3 by setting up the application to generate traffic and communication between nodes.

For system development in Hierarchical Topology, contact ns3simulation.com for the best results.