How to Start Tree Topology Projects using NS3

To start a Tree Topology project in NS-3 for follow these steps in a project. Tree topology is a hierarchical in which of nodes are ordered in the levels of a root node at the top and every node has connected to one or more child nodes. We will discuss about the tree topology in this project for below following steps:

Steps to Start Tree Topology Projects using NS3

Step 1: Set Up NS-3

  1. Install NS-3:
    • Download NS-3.
    • Install required dependencies.
  2. Verify Installation: Run a test script:

./waf –run scratch/my_first

Step 2: Understand Tree Topology

  • Tree Topology:
    • The Root node at the top of the tree topology.
    • Every node connects the parent node and may have a multiple child node.
    • The tree topology nodes in the equal level are siblings.
    • It mixed the advantages of bus and star topologies.

Step 3: Plan the Topology

  1. Decide on the number of levels and branches:
    • For sample a Three-level tree with every node having two child nodes.
  2. Set goals for simulation:
    • Replicate the congestion among levels or across siblings.
    • Estimate the performance of parameter metrics such as delay, throughput, and packet loss.

Step 4: Set Up the Tree Topology

  1. Create Nodes: Utilized their tree topology in NodeContainer we build an overall the nodes in the tree.

NodeContainer nodes;

uint32_t numLevels = 3;

uint32_t branchesPerNode = 2;

uint32_t totalNodes = (pow(branchesPerNode, numLevels) – 1) / (branchesPerNode – 1); // Calculate total nodes

nodes.Create(totalNodes);

  1. Connect Nodes: Used in the connection nodes for PointToPointHelper we join the parent nodes to child nodes.

PointToPointHelper p2p;

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

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

NetDeviceContainer devices;

uint32_t currentIndex = 0;

for (uint32_t level = 0; level < numLevels – 1; ++level) {

uint32_t nodesInLevel = pow(branchesPerNode, level);

for (uint32_t i = 0; i < nodesInLevel; ++i) {

for (uint32_t j = 0; j < branchesPerNode; ++j) {

uint32_t childIndex = currentIndex + nodesInLevel + i * branchesPerNode + j;

NetDeviceContainer link = p2p.Install(nodes.Get(currentIndex + i), nodes.Get(childIndex));

devices.Add(link);

}

}

currentIndex += nodesInLevel;

}

  1. Install Internet Stack: Install the internet stack on overall nodes.

InternetStackHelper stack;

stack.Install(nodes);

  1. Assign IP Addresses: Allocate the IP addresses to overall devices.

Ipv4AddressHelper address;

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

address.Assign(devices);

Step 5: Set Up Applications

  1. Install a Server: Placed the server on the root node for install the server.

UdpEchoServerHelper echoServer(9);

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

serverApp.Start(Seconds(1.0));

serverApp.Stop(Seconds(10.0));

  1. Install Clients: Install client applications on leaf nodes or other nodes.

for (uint32_t i = 1; i < totalNodes; ++i) {

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

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

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

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

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

clientApp.Start(Seconds(2.0));

clientApp.Stop(Seconds(10.0));

}

Step 6: Run and Analyze

  1. Run the Simulation:

Simulator::Run();

Simulator::Destroy();

  1. Capture Packets: Ensure the seizure packets. pcap following for analysis.

p2p.EnablePcapAll(“tree_topology”);

  1. Trace Logs: Utilized the trace in NS-3 logging for debugging:

export NS_LOG=”UdpEchoClientApplication=level_all|prefix_func”

./waf –run scratch/tree_topology

Step 7: Enhance the Simulation

  • Establish the connection failures and calculate the effect.
  • Utilized the simulation of improve the multiple traffic designs such as FTP or HTTP.
  • Improve the mobility or dynamic routing.

Example: Minimal NS-3 Script for Tree 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[]) {

uint32_t numLevels = 3;

uint32_t branchesPerNode = 2;

uint32_t totalNodes = (pow(branchesPerNode, numLevels) – 1) / (branchesPerNode – 1);

NodeContainer nodes;

nodes.Create(totalNodes);

 

PointToPointHelper p2p;

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

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

NetDeviceContainer devices;

uint32_t currentIndex = 0;

for (uint32_t level = 0; level < numLevels – 1; ++level) {

uint32_t nodesInLevel = pow(branchesPerNode, level);

for (uint32_t i = 0; i < nodesInLevel; ++i) {

for (uint32_t j = 0; j < branchesPerNode; ++j) {

uint32_t childIndex = currentIndex + nodesInLevel + i * branchesPerNode + j;

NetDeviceContainer link = p2p.Install(nodes.Get(currentIndex + i), nodes.Get(childIndex));

devices.Add(link);

}

}

currentIndex += nodesInLevel;

}

InternetStackHelper stack;

stack.Install(nodes);

Ipv4AddressHelper address;

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

address.Assign(devices);

UdpEchoServerHelper echoServer(9);

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

serverApp.Start(Seconds(1.0));

serverApp.Stop(Seconds(10.0));

for (uint32_t i = 1; i < totalNodes; ++i) {

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

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

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

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

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

clientApp.Start(Seconds(2.0));

clientApp.Stop(Seconds(10.0));

}

p2p.EnablePcapAll(“tree_topology”);

Simulator::Run();

Simulator::Destroy();

return 0;

}

Save and Run the Script

  1. Save the script as tree_topology.cc.
  2. We compile and run:

./waf –run tree_topology

Next Steps

  • We Visualize the topology used in NetAnim.
  • Testing through multiple tree structures like as vary levels and branches.
  • Compared the tree topology by other topologies such as mesh or star.

In this report how to start the tree topology using NS3 environment. It has involved the installing process and understanding the tree topology for run and simulation results in how on enhance the simulation for run this project.

If you want additional information, we can send you a separate manual. Don’t hesitate to contact us regarding your simulation and project performance outcomes. Please include all important details about your Tree Topology Projects using NS3 when you reach out to phdprojects.org, and we’ll do our best to give you excellent results.