How to Implement Hierarchical Star Topology in NS2
To implement the Hierarchical star topology in network simulator 2 (ns2), we have simulate a network with several star topologies which are interconnected in a hierarchical structure. This includes:
- At the lowest level, several nodes are linked to a central hub (star topology).
- The hubs from various star networks are linked to higher-level hubs, generating a hierarchical arrangement.
We work on several star topologies related to your projects for best guidance you can contact ns2project.com
Steps to Implement Hierarchical Star Topology in NS2
- Set Up NS2
Make sure to install and configure the ns2 on your computer. If NS2 is not installed, you can install it on Ubuntu/Linux using:
sudo apt-get update
sudo apt-get install ns2
- Define Hierarchical Star Topology
In a Hierarchical Star Topology:
- At each level of the hierarchy, multiple star topologies exist, with nodes linked to local hubs.
- The central hubs from various star networks are linked to higher-level hubs, forming a hierarchical structure.
- Create a TCL Script for Hierarchical Star Topology
Below is an example of a TCL script to execute a hierarchical star topology where two star topologies are linked through a higher-level hub.
Example TCL Script for Hierarchical Star Topology:
# Define the simulator
set ns [new Simulator]
# Open trace files
set tracefile [open hierarchical_star_out.tr w]
set namfile [open hierarchical_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]
# Top-level hub (higher-level hub in the hierarchy)
set top_hub [$ns node]
# Define hubs for lower-level star topologies
set hub_0 [$ns node]
set hub_1 [$ns node]
# Define the nodes for the first 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 the second 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 purposes in NAM)
$top_hub set X_ 300.0
$top_hub set Y_ 250.0
$hub_0 set X_ 200.0
$hub_0 set Y_ 200.0
$hub_1 set X_ 400.0
$hub_1 set Y_ 200.0
# Position the nodes connected to hub_0 (lower-level star topology)
$node_0 set X_ 150.0
$node_0 set Y_ 150.0
$node_1 set X_ 200.0
$node_1 set Y_ 100.0
$node_2 set X_ 250.0
$node_2 set Y_ 150.0
# Position the nodes connected to hub_1 (lower-level star topology)
$node_3 set X_ 350.0
$node_3 set Y_ 150.0
$node_4 set X_ 400.0
$node_4 set Y_ 100.0
$node_5 set X_ 450.0
$node_5 set Y_ 150.0
# Create links for the first star topology (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
# Create links for the second star topology (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 lower-level hubs (hub_0 and hub_1) to the top-level hub (top_hub)
$ns duplex-link $top_hub $hub_0 1Gb 5ms DropTail
$ns duplex-link $top_hub $hub_1 1Gb 5ms DropTail
# Setup traffic between nodes in different star clusters
# Traffic from node_0 (in hub_0’s star) to node_4 (in hub_1’s star)
set udp0 [new Agent/UDP]
set null0 [new Agent/Null]
$ns attach-agent $node_0 $udp0
$ns attach-agent $node_4 $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 hierarchical_star_out.nam &
exit 0
}
# Run the simulation
$ns run
Explanation of the Script:
- Hierarchy Levels:
- Top-level hub (top_hub): Indicates the higher-level hub that links the lower-level star topologies.
- Lower-level hubs (hub_0, hub_1): Signifies the hubs that form local star topologies.
- Star Topologies:
- Each lower-level hub (hub_0 and hub_1) has nodes linked to it, creating star topologies.
- In this sample, node_0, node_1, and node_2 are connected to hub_0, and node_3, node_4, and node_5 are connected to hub_1.
- Inter-hub Connections:
- Use higher-bandwidth links (1Gbps with 5ms delay) to link the low-level hubs with the top-level hub.
- Traffic Setup:
- Traffic is configure to flow from node_0 (in hub_0’s star) to node_4 (in hub_1’s star).
- Use CBR (Constant Bit Rate) application to generate traffic amongst these nodes.
- Trace and NAM Visualization:
- The script produces a trace file (hierarchical_star_out.tr) and a NAM file (hierarchical_star_out.nam). You can visualize the network in NAM (Network Animator).
- Run the Simulation
Store the script as hierarchical_star_topology.tcl and execute it in NS2:
ns hierarchical_star_topology.tcl
To visualize the network using NAM, use:
nam hierarchical_star_out.nam
Customization:
- Expanding the Topology:
- Design the larger hierarchical topology by adding more hubs and nodes.
- For instance, you could add more lower-level hubs linked to the top-level hub, each with its own star topology.
- Traffic Patterns:
- You can generate more difficult traffic flows amongst various nodes through the star topologies. For instance, you can set up traffic amongst nodes inside the same star topology or through various star topologies.
- Link Parameters:
- Replicate various network conditions by modifying the bandwidth and delay of the links. For example, you might want to simulate faster or slower connections amongst the top-level hub and lower-level hubs.
The given demonstration has the essential information about the implementation of Hierarchical star topology that will be executed in a simulation network called ns2 by combining numerous star topologies in a hierarchical manner. You can be able to customize the simulation as per your desires.