To simulate Hierarchical Topology in ns2 has includes to organizing the network in layers, in which each layer can have nodes associated in numerous topologies like star, bus, or mesh. This kind of topology is usually utilized in larger networks in which the scalability, control, and management are significant.
In NS2, we can mimic a Hierarchical Topology by generating different layers like core, distribution, and access layers, with each layer having its own sub network. The higher layers in the hierarchy handle communication among lower layers.
Here’s how to simulate a Hierarchical Topology in NS2:
Steps to Simulate Hierarchical Topology Projects in NS2
- Set up NS2 Environment:
Make sure that NS2 is installed and operating on the system. We will compose a TCL script to describe and replicate the hierarchical topology.
- Understanding Hierarchical Topology:
- A Hierarchical Topology usually encompasses of three layers:
- Core Layer: Offered high-speed, backbone connectivity.
- Distribution Layer: gathers connections from the access layer and routes data among different parts of the network.
- Access Layer: It offers connections to end devices such as computers or sensors.
- Each layer can have different kinds of connections or topologies such as star, mesh, etc..
- Create a TCL Script for Hierarchical Topology:
Below is an instance of a TCL script to replicate a Hierarchical Topology with a core layer, distribution layer, and access layer:
# Create a new simulator instance
set ns [new Simulator]
# Open a NAM trace file for visualization
set nf [open out.nam w]
$ns namtrace-all $nf
# ======= Core Layer ========
# Create core nodes (backbone of the network)
set core1 [$ns node]
set core2 [$ns node]
# Connect core nodes with a high-speed link
$ns duplex-link $core1 $core2 100Mb 5ms DropTail
# ======= Distribution Layer ========
# Create distribution nodes (middle layer)
set dist1 [$ns node]
set dist2 [$ns node]
set dist3 [$ns node]
# Connect core layer to distribution layer
$ns duplex-link $core1 $dist1 50Mb 10ms DropTail
$ns duplex-link $core1 $dist2 50Mb 10ms DropTail
$ns duplex-link $core2 $dist3 50Mb 10ms DropTail
# ======= Access Layer ========
# Create access layer nodes (end devices)
set access1 [$ns node]
set access2 [$ns node]
set access3 [$ns node]
set access4 [$ns node]
set access5 [$ns node]
set access6 [$ns node]
# Connect distribution layer to access layer nodes
$ns duplex-link $dist1 $access1 10Mb 20ms DropTail
$ns duplex-link $dist1 $access2 10Mb 20ms DropTail
$ns duplex-link $dist2 $access3 10Mb 20ms DropTail
$ns duplex-link $dist2 $access4 10Mb 20ms DropTail
$ns duplex-link $dist3 $access5 10Mb 20ms DropTail
$ns duplex-link $dist3 $access6 10Mb 20ms DropTail
# Attach UDP agents for traffic generation in the access layer
set udp_access1 [new Agent/UDP]
$ns attach-agent $access1 $udp_access1
set udp_access2 [new Agent/UDP]
$ns attach-agent $access4 $udp_access2
# Attach Null agents at receiving nodes in other access layer nodes
set null_access1 [new Agent/Null]
$ns attach-agent $access6 $null_access1
set null_access2 [new Agent/Null]
$ns attach-agent $access3 $null_access2
# Connect the UDP agents to Null agents
$ns connect $udp_access1 $null_access1
$ns connect $udp_access2 $null_access2
# Create CBR traffic generators for the UDP agents
set cbr_access1 [new Application/Traffic/CBR]
$cbr_access1 attach-agent $udp_access1
$cbr_access1 set packetSize_ 512
$cbr_access1 set rate_ 100Kb
set cbr_access2 [new Application/Traffic/CBR]
$cbr_access2 attach-agent $udp_access2
$cbr_access2 set packetSize_ 512
$cbr_access2 set rate_ 100Kb
# Schedule the CBR traffic to start and stop
$ns at 1.0 “$cbr_access1 start”
$ns at 1.5 “$cbr_access2 start”
$ns at 5.0 “$cbr_access1 stop”
$ns at 5.5 “$cbr_access2 stop”
# End the simulation at 7 seconds
$ns at 7.0 “finish”
proc finish {} {
global ns nf
$ns flush-trace
close $nf
exec nam out.nam &
exit 0
}
# Run the simulation
$ns run
- Explanation of the Code:
- Core Layer: Two core nodes (core1, core2) are linked by a high-speed link (100Mb, 5ms delay) signify the backbone of the network.
- Distribution Layer: Three distribution nodes (dist1, dist2, dist3) are associated to the core layer nodes using medium-speed links (50Mb, 10ms delay).
- Access Layer: Six access layer nodes (access1, access2, …, access6) are associated to the distribution layer using slower links (10Mb, 20ms delay). These signify the end devices in the network.
- UDP Traffic: Two UDP agents are generated in the access layer, transmit traffic to other nodes. Null agents perform as receivers.
- CBR Traffic: Constant Bit Rate (CBR) traffic generators replicate data flow from access nodes access1 and access4 to access6 and access3, respectively.
- Traffic Scheduling: Traffic initiates at 1 second and 1.5 seconds and terminates at 5 seconds and 5.5 seconds, correspondingly.
- Simulation End: The simulation terminates after 7 seconds, and the outcomes are saved in a .nam file for visualization.
- Run the Simulation:
- Save the script as hierarchical_topology.tcl.
- Open a terminal and navigate to the directory in which the script is saved.
- Execute the simulation using the following command:
ns hierarchical_topology.tcl
- The simulation will create out.nam file that can be opened using Network Animator (NAM) for visualization.
- Visualization in NAM:
- Open the out.nam file in NAM to envision the hierarchical topology. We should see the three layers such as core, distribution, and access with links among them.
- Customization and Enhancements:
- Increase the Number of Layers: we can incorporate more layers to the hierarchy, like a fourth layer for more complex networks.
- TCP Traffic: Replace the UDP agents with TCP agents to replicate reliable communication:
set tcp_access1 [new Agent/TCP]
$ns attach-agent $access1 $tcp_access1
set sink_access1 [new Agent/TCPSink]
$ns attach-agent $access6 $sink_access1
$ns connect $tcp_access1 $sink_access1
- Performance Analysis: we can incorporate trace files to measure parameters such as packet loss, delay, and throughput:
set tracefile [open trace.tr w]
$ns trace-all $tracefile
- Different Traffic Types: Test with different traffic patterns (such as FTP, HTTP) or upsurge the number of traffic sources.
- Performance Analysis:
To measure the performance of the hierarchical topology, we can:
- Assess throughput by monitoring on how much data is successfully routed among layers.
- Evaluate latency (delay) among nodes in different layers.
- Measure packet loss because of network congestion or bandwidth limits.
At the end of this manual, we clearly elaborated and deliver the details and shown examples of how to simulate Hierarchical Topology projects in ns2 tool by using the above discussed techniques. We will deliver more information according to your needs in these specific Hierarchical Topology project.
To simulate hierarchical topology projects utilizing NS2, we offer our expertise. Please contact us via email for exceptional research assistance and unique topic suggestions.