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

How to Implement Star Topology in ns3

To implement a star topology in ns3, we should create a central node (hub or switch) that is connected to multiple peripheral nodes (clients or servers). Each peripheral node communicates across the central node. Here is a complete guide to set up a star topology in ns3.

Steps to implement star topology

  1. Set Up ns3:
    • Make sure that ns3 is installed in the computer. If not, install it.
  2. Create the Nodes:
    • To represent the central node and the peripheral nodes, create a set of nodes.
  3. Set Up the Point-to-Point Channels:
    • To connect the central node to each peripheral node, use point-to-point helpers.
  4. Install Network Stack:
    • On all nodes, install the internet stack.
  5. Assign IP Addresses:
    • To the nodes connected to the point-to-point links, assign IP addresses.
  6. Set Up Applications:
    • To generate traffic and demonstrate communication between nodes, install applications.

Example code

Here is an example to set up a basic star 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 (“StarTopologyExample”);

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

{

CommandLine cmd;

cmd.Parse (argc, argv);

// Create nodes

NodeContainer centralNode;

centralNode.Create (1); // Central node

NodeContainer peripheralNodes;

peripheralNodes.Create (5); // Peripheral nodes

// Create point-to-point links

PointToPointHelper pointToPoint;

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

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

NetDeviceContainer devices;

Ipv4AddressHelper address;

InternetStackHelper stack;

stack.Install (centralNode);

stack.Install (peripheralNodes);

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

{

NetDeviceContainer link = pointToPoint.Install (NodeContainer (centralNode.Get (0), peripheralNodes.Get (i)));

devices.Add (link);

std::ostringstream subnet;

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

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

address.Assign (link);

}

// Enable routing

Ipv4GlobalRoutingHelper::PopulateRoutingTables ();

// Create a UDP server on node 1

UdpServerHelper udpServer (9);

ApplicationContainer serverApp = udpServer.Install (peripheralNodes.Get (1));

serverApp.Start (Seconds (1.0));

serverApp.Stop (Seconds (10.0));

// Create a UDP client on node 0

UdpClientHelper udpClient (Ipv4Address (“10.1.2.2”), 9); // Assuming node 1’s IP is 10.1.2.2

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

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

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

ApplicationContainer clientApp = udpClient.Install (peripheralNodes.Get (0));

clientApp.Start (Seconds (2.0));

clientApp.Stop (Seconds (10.0));

// Enable packet capture

pointToPoint.EnablePcapAll (“star-topology”);

// Enable logging

LogComponentEnable (“UdpClient”, LOG_LEVEL_INFO);

LogComponentEnable (“UdpServer”, LOG_LEVEL_INFO);

Simulator::Run ();

Simulator::Destroy ();

return 0;

}

Explanation

  1. Setup:

Created one central node and five peripheral nodes connected by point-to-point links.

  1. Point-to-Point Links:

To connect the central node to each peripheral node, Point-to-point links are created. The data rate and delay are configured for the links.

  1. Network Stack:

On all nodes, the internet stack is installed.

  1. IP Addresses:

To the nodes, IP addresses are assigned connected by the point-to-point links.

  1. Applications:

On one of the peripheral nodes, A UDP server is installed and a UDP client is installed on the central node to generate traffic and demonstrate communication.

  1. Packet Capture:

To observe network traffic, packet capture is enabled for the point-to-point links.

  1. Logging:

To provide detailed output during the simulation, logging is enabled for the UDP client and server applications.

Running the Simulation

Compile and run the simulation using the following commands :

./waf configure

./waf build

./waf –run star-topology-example

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

Overall, we had our simulation results by creating a central node (hub or switch) that is connected to multiple peripheral nodes. Also, we provide more related information on star topology.

Learn how to implement Star Topology in ns3 with detailed comparative analysis results and practical explanations available at ns3simulation.com.