How to Implement Bus Star Hybrid Topology in NS2
To implement a Bus-Star Hybrid Topology in Network Simulator 2 (ns2), we have to integrate the components of both bus and star topologies. The bus topology contains nodes which are linked to a shared backbone or bus, however star topology consists of nodes connected to a central hub or switch.
In a hybrid topology, some nodes are linked in a star arrangement with central nodes (hubs), and these hubs are connected through a bus (or another shared medium).
Steps to Implement Bus-Star Hybrid Topology in NS2
- Set Up NS2
Make certain that you have installed the ns2 on your computer. If not, install it on Ubuntu/Linux using the below commands:
sudo apt-get update
sudo apt-get install ns2
- Define Nodes and Links for Hybrid Topology
In the hybrid topology:
- Several nodes will be linked to central nodes (hubs) using a star set up.
- The central nodes (or hubs) will be connected through a bus (shared backbone).
- Create a TCL Script for the Bus-Star Hybrid Topology
Here’s an example TCL script to execute a bus-star hybrid topology. In this sample, two central hubs link nodes in a star topology and the hubs are linked across a bus (shared medium).
Example TCL Script for Bus-Star Hybrid Topology:
# Define the simulator
set ns [new Simulator]
# Open trace files
set tracefile [open bus_star_out.tr w]
set namfile [open bus_star_out.nam w]
$ns trace-all $tracefile
$ns namtrace-all $namfile
# Create a topography object
set topo [new Topography]
$topo load_flatgrid 500 500
# Create a channel for wired links
set chan [new Channel/WiredChannel]
# Central nodes (hubs for the star topology)
set hub_0 [$ns node]
set hub_1 [$ns node]
# Define the nodes for Star Topology connected to hub_0
set node_0 [$ns node]
set node_1 [$ns node]
set node_2 [$ns node]
# Define the nodes for Star Topology connected to hub_1
set node_3 [$ns node]
set node_4 [$ns node]
set node_5 [$ns node]
# Position the hubs and nodes (for visualization in NAM)
$hub_0 set X_ 200.0
$hub_0 set Y_ 250.0
$hub_1 set X_ 400.0
$hub_1 set Y_ 250.0
# Position the star nodes around hub_0
$node_0 set X_ 150.0
$node_0 set Y_ 200.0
$node_1 set X_ 200.0
$node_1 set Y_ 150.0
$node_2 set X_ 250.0
$node_2 set Y_ 200.0
# Position the star nodes around hub_1
$node_3 set X_ 350.0
$node_3 set Y_ 200.0
$node_4 set X_ 400.0
$node_4 set Y_ 150.0
$node_5 set X_ 450.0
$node_5 set Y_ 200.0
# Connect the nodes in a Star Topology with hub_0
$ns duplex-link $hub_0 $node_0 100Mb 10ms DropTail
$ns duplex-link $hub_0 $node_1 100Mb 10ms DropTail
$ns duplex-link $hub_0 $node_2 100Mb 10ms DropTail
# Connect the nodes in a Star Topology with hub_1
$ns duplex-link $hub_1 $node_3 100Mb 10ms DropTail
$ns duplex-link $hub_1 $node_4 100Mb 10ms DropTail
$ns duplex-link $hub_1 $node_5 100Mb 10ms DropTail
# Connect the hubs using a Bus (Shared Backbone)
# Simulate the bus with duplex links that resemble a shared medium
$ns duplex-link $hub_0 $hub_1 1Gb 5ms DropTail
# Setup traffic flow between nodes across different star clusters
# Traffic from node_0 to node_5 (across the bus)
set udp0 [new Agent/UDP]
set null0 [new Agent/Null]
$ns attach-agent $node_0 $udp0
$ns attach-agent $node_5 $null0
$ns connect $udp0 $null0
# Create CBR (Constant Bit Rate) traffic
set cbr0 [new Application/Traffic/CBR]
$cbr0 set packetSize_ 512
$cbr0 set interval_ 0.05
$cbr0 attach-agent $udp0
# Start traffic at time 1.0 second
$ns at 1.0 “$cbr0 start”
# Schedule simulation end
$ns at 10.0 “finish”
# Finish procedure to close the simulation
proc finish {} {
global ns tracefile namfile
$ns flush-trace
close $tracefile
close $namfile
exec nam bus_star_out.nam &
exit 0
}
# Run the simulation
$ns run
Key Elements of the Script:
- Star Topology:
- The first group of nodes (node_0, node_1, node_2) are linked to the first hub (hub_0) using a star configuration.
- Likewise, the second group of nodes (node_3, node_4, node_5) are connected to the second hub (hub_1).
- Bus Connection:
- The two hubs (hub_0 and hub_1) are connected over a high-speed duplex link (replicating a bus). These links behave like the backbone for communication amongst the two star topologies.
- Traffic Setup:
- UDP traffic is produced from node_0 (in the first star) to node_5 (in the second star) through the bus.
- Use CBR (Constant Bit Rate) application to produce traffic amongst the nodes.
- Trace and NAM Visualization:
- The script creates a trace file (bus_star_out.tr) and a NAM file (bus_star_out.nam). Visualize the network by using NAM (Network Animator).
- Run the Simulation
Store the script as bus_star_hybrid.tcl and execute it in NS2:
ns bus_star_hybrid.tcl
To visualize the network using NAM, use:
nam bus_star_out.nam
Customization:
- Expanding the Topology:
- You can include more nodes and hubs to maximize the complexity of the star and bus topology. For instance, use extra bus links to attach more hubs and connect it.
- Traffic Flow:
- You can configure numerous traffic flows amongst various nodes in the star networks. For example, traffic can be set up among nodes linked to the same hub or between multiple hubs.
- Link Parameters:
- Replicate various network conditions by modifying the link bandwidth and delay. For instance, you can simulate a slower bus connection or various delays amongst the hubs.
We had explicitly aggregated and delivered the instructions which are essential for the implementation of Bus Star Hybrid Topology in the ns2 environment. Start by set up the simulation and incorporating both bus and star topology into simulation. You can refer the given examples and procedure to customize it.
For optimal implementation assistance, it is advisable to maintain communication with ns2project.com for superior guidance.