To implement a star-bus topology, we need to create nodes which is connected in a star configuration, with one of the star’s central nodes connected to bus topology.
Below are the steps to implement this in ns3.
Steps for implementation
Step 1: Install ns-3
Make sure that ns3 is installed in the computer. If not, install it.
Step 2: Create a New Simulation Script
For your simulation, create a new C++ script.
Step 3: Include Necessary Headers
include the necessary ns3 headers in your script.
#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 Star-Bus Hybrid Topology
Below is an example to set up a star-bus topology with one star and a bus.
using namespace ns3;
NS_LOG_COMPONENT_DEFINE (“StarBusHybridTopology”);
int main (int argc, char *argv[])
{
// Configure command line parameters
CommandLine cmd;
cmd.Parse (argc, argv);
// Create nodes
NodeContainer starCentralNode;
starCentralNode.Create (1); // Create the central node for the star topology
NodeContainer starNodes;
starNodes.Create (4); // Create 4 nodes for the star topology
NodeContainer busNodes;
busNodes.Create (4); // Create 4 nodes for the bus topology
// Set up point-to-point links for the star topology
PointToPointHelper pointToPoint;
pointToPoint.SetDeviceAttribute (“DataRate”, StringValue (“1Gbps”));
pointToPoint.SetChannelAttribute (“Delay”, StringValue (“2ms”));
NetDeviceContainer starDevices;
for (uint32_t i = 0; i < starNodes.GetN (); ++i)
{
NodeContainer pair (starCentralNode.Get (0), starNodes.Get (i));
NetDeviceContainer devicePair = pointToPoint.Install (pair);
starDevices.Add (devicePair);
}
// Set up CSMA links for the bus topology
CsmaHelper csma;
csma.SetChannelAttribute (“DataRate”, StringValue (“1Gbps”));
csma.SetChannelAttribute (“Delay”, TimeValue (NanoSeconds (6560)));
NetDeviceContainer busDevices = csma.Install (busNodes);
// Connect the central node of the star topology to the bus
NodeContainer busStarLink (starCentralNode.Get (0), busNodes.Get (0));
NetDeviceContainer busStarDevices = pointToPoint.Install (busStarLink);
// Install the internet stack
InternetStackHelper stack;
stack.Install (starCentralNode);
stack.Install (starNodes);
stack.Install (busNodes);
// Assign IP addresses to the star devices
Ipv4AddressHelper address;
address.SetBase (“10.1.1.0”, “255.255.255.0”);
Ipv4InterfaceContainer starInterfaces = address.Assign (starDevices);
// Assign IP addresses to the bus devices
address.SetBase (“10.1.2.0”, “255.255.255.0”);
Ipv4InterfaceContainer busInterfaces = address.Assign (busDevices);
// Assign IP addresses to the bus-star link
address.SetBase (“10.1.3.0”, “255.255.255.0”);
Ipv4InterfaceContainer busStarInterfaces = address.Assign (busStarDevices);
// Set up mobility model (optional)
MobilityHelper mobility;
Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator> ();
positionAlloc->Add (Vector (50.0, 50.0, 0.0)); // Star central node position
positionAlloc->Add (Vector (100.0, 50.0, 0.0)); // Star node 1 position
positionAlloc->Add (Vector (50.0, 100.0, 0.0)); // Star node 2 position
positionAlloc->Add (Vector (0.0, 50.0, 0.0)); // Star node 3 position
positionAlloc->Add (Vector (50.0, 0.0, 0.0)); // Star node 4 position
positionAlloc->Add (Vector (200.0, 50.0, 0.0)); // Bus node 1 position
positionAlloc->Add (Vector (250.0, 50.0, 0.0)); // Bus node 2 position
positionAlloc->Add (Vector (300.0, 50.0, 0.0)); // Bus node 3 position
positionAlloc->Add (Vector (350.0, 50.0, 0.0)); // Bus node 4 position
mobility.SetPositionAllocator (positionAlloc);
mobility.SetMobilityModel (“ns3::ConstantPositionMobilityModel”);
mobility.Install (starCentralNode);
mobility.Install (starNodes);
mobility.Install (busNodes);
// Set up applications (e.g., UDP echo server and client)
uint16_t port = 9; // Port number for applications
// Install UDP Echo Server on the central node of the star topology
UdpEchoServerHelper echoServer (port);
ApplicationContainer serverApps = echoServer.Install (starCentralNode.Get (0));
serverApps.Start (Seconds (1.0));
serverApps.Stop (Seconds (10.0));
// Install UDP Echo Clients on star nodes to communicate with the central node
for (uint32_t i = 0; i < starNodes.GetN (); ++i)
{
UdpEchoClientHelper echoClient (starInterfaces.GetAddress (0), port);
echoClient.SetAttribute (“MaxPackets”, UintegerValue (1));
echoClient.SetAttribute (“Interval”, TimeValue (Seconds (1.0)));
echoClient.SetAttribute (“PacketSize”, UintegerValue (1024));
ApplicationContainer clientApps = echoClient.Install (starNodes.Get (i));
clientApps.Start (Seconds (2.0 + i)); // Stagger start times
clientApps.Stop (Seconds (10.0));
}
// Install UDP Echo Clients on bus nodes to communicate with the central node
for (uint32_t i = 1; i < busNodes.GetN (); ++i)
{
UdpEchoClientHelper echoClient (busStarInterfaces.GetAddress (1), port);
echoClient.SetAttribute (“MaxPackets”, UintegerValue (1));
echoClient.SetAttribute (“Interval”, TimeValue (Seconds (1.0)));
echoClient.SetAttribute (“PacketSize”, UintegerValue (1024));
ApplicationContainer clientApps = echoClient.Install (busNodes.Get (i));
clientApps.Start (Seconds (2.0 + i + starNodes.GetN ())); // 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
Save the script as star-bus-hybrid-topology.cc and build the script using waf, then run the simulation.
./waf configure –enable-examples
./waf build
./waf –run scratch/ star-bus-hybrid -topology
Explanation of the script
- Node Creation: For star topology’s central node, the star nodes, and the bus nodes, creates several nodes.
- Point-to-Point Links: To form the star topology and to connect the central node to the bus topology, configured point-to-point links.
- CSMA links: To connect the bus nodes, configured CSMA links.
- Internet Stack: On all nodes, installs the internet stack.
- IP Addressing: To star devices, bus devices, and the link connecting the star central node to the bus, assigns IP addresses.
- Mobility Model: Sets the position of nodes using ListPositionAllocator and ConstantPositionMobilityModel. This is an optional step.
- Applications: On central node of the star topology, sets up a UDP echo server and a UDP echo client on star and bus nodes to demonstrate communication.
On the whole, we had a performance analysis on the implementation on star-bus hybrid topology by creating nodes connected in a star configuration, with one of the star’s central nodes connected to a bus topology.
Even after reading it if you find hard in Implementing Star Bus Hybrid Topology in ns3 then reach us out at ns3simulation.com our developers will give you good outcome.