To implement the bus star hybrid topology in ns3 has to generate the network that some nodes were linked in a bus topology and with other nodes are linked to a central node in a star topology.
Here is the procedure on how to implement the bus-star hybrid topology in ns3 framework:
Step-by-step Implementation
Step 1: Install ns-3
- Make certain ns3 is installed in the computer.
Step 2: Create a New Simulation Script
- Create a new C++ script for your simulation.
Step 3: Include Necessary Headers
- In your script, take account of the essential ns-3 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 Bus-Star Hybrid Topology
The given below is the sample set up on how to implement the bus-star hybrid topology with a bus of four nodes and a star with three nodes connected to one of the bus nodes:
using namespace ns3;
NS_LOG_COMPONENT_DEFINE (“BusStarHybridTopology”);
int main (int argc, char *argv[])
{
// Configure command line parameters
CommandLine cmd;
cmd.Parse (argc, argv);
// Create nodes
NodeContainer busNodes;
busNodes.Create (4); // Create 4 nodes for the bus
NodeContainer starNodes;
starNodes.Create (3); // Create 3 nodes for the star
NodeContainer allNodes = NodeContainer (busNodes, starNodes);
// Set up the CSMA bus
CsmaHelper csma;
csma.SetChannelAttribute (“DataRate”, StringValue (“1Gbps”));
csma.SetChannelAttribute (“Delay”, TimeValue (NanoSeconds (6560)));
NetDeviceContainer busDevices = csma.Install (busNodes);
// Set up the point-to-point links for the star
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 (busNodes.Get (1), starNodes.Get (i)); // Connect star nodes to the second bus node
NetDeviceContainer devicePair = pointToPoint.Install (pair);
starDevices.Add (devicePair);
}
// Install the internet stack
InternetStackHelper stack;
stack.Install (allNodes);
// Assign IP addresses to the bus devices
Ipv4AddressHelper address;
address.SetBase (“10.1.1.0”, “255.255.255.0”);
Ipv4InterfaceContainer busInterfaces = address.Assign (busDevices);
// Assign IP addresses to the star devices
address.SetBase (“10.1.2.0”, “255.255.255.0”);
Ipv4InterfaceContainer starInterfaces = address.Assign (starDevices);
// Set up mobility model (optional)
MobilityHelper mobility;
Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator> ();
positionAlloc->Add (Vector (50.0, 50.0, 0.0)); // Bus node 1 position
positionAlloc->Add (Vector (100.0, 50.0, 0.0)); // Bus node 2 position
positionAlloc->Add (Vector (150.0, 50.0, 0.0)); // Bus node 3 position
positionAlloc->Add (Vector (200.0, 50.0, 0.0)); // Bus node 4 position
positionAlloc->Add (Vector (100.0, 100.0, 0.0)); // Star node 1 position
positionAlloc->Add (Vector (100.0, 150.0, 0.0)); // Star node 2 position
positionAlloc->Add (Vector (100.0, 200.0, 0.0)); // Star node 3 position
mobility.SetPositionAllocator (positionAlloc);
mobility.SetMobilityModel (“ns3::ConstantPositionMobilityModel”);
mobility.Install (allNodes);
// Set up applications (e.g., UDP echo server and client)
uint16_t port = 9; // Port number for applications
// Install UDP Echo Server on bus node 0
UdpEchoServerHelper echoServer (port);
ApplicationContainer serverApps = echoServer.Install (busNodes.Get (0));
serverApps.Start (Seconds (1.0));
serverApps.Stop (Seconds (10.0));
// Install UDP Echo Clients on other nodes to communicate with bus node 0
for (uint32_t i = 1; i < busNodes.GetN (); ++i)
{
UdpEchoClientHelper echoClient (busInterfaces.GetAddress (0), 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));
clientApps.Stop (Seconds (10.0));
}
for (uint32_t i = 0; i < starNodes.GetN (); ++i)
{
UdpEchoClientHelper echoClient (busInterfaces.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));
}
// Run simulation
Simulator::Stop (Seconds (10.0));
Simulator::Run ();
Simulator::Destroy ();
return 0;
}
Step 5: Build and Run the Simulation
- Save the script as bus-star-hybrid-topology.cc.
- Build the script using waf:
./waf configure –enable-examples
./waf build
- Run the simulation:
./waf –run scratch/bus-star-hybrid-topology
Explanation of the Script
- Node Creation: Creates four nodes for the bus and three nodes for the star.
- CSMA Bus: Configures CSMA links to connect the bus nodes.
- Point-to-Point Star: Configures point-to-point links to connect the star nodes to the second node of the bus.
- Internet Stack: Installs the internet stack on all nodes.
- IP Addressing: Assigns IP addresses to the bus and star devices using different subnets.
- Mobility Model: (Optional) Sets the position of nodes using ListPositionAllocator and ConstantPositionMobilityModel.
- Applications: Sets up a UDP echo server on the first bus node and UDP echo clients on the other nodes to demonstrate communication between nodes.
The bus-star hybrid topology is configured with CSMA links that connected with the bus nodes and also it clearly shows the interaction among the nodes by using the ns3 simulation tool.
We give additional implantation support regarding to hybrid bus-star topology share with us all your parameter details to guide you more.