To simulate Hierarchical Routing projects utilizing NS2, we will require setting up a multi-layered or hierarchical network structure in which routing decisions are created according to the diverse hierarchical levels. Hierarchical routing normally splits the network into clusters or regions, with routing managed locally in clusters and via higher-level nodes among the clusters. Here’s a detailed guide for simulating Hierarchical Routing projects in NS2:
Steps to Simulate Hierarchical Routing in NS2:
- Set Up the NS2 Environment:
Make sure that NS2 is installed and working properly on the system. We can check it by running the ns command in the terminal:
ns
If NS2 is installed then this will open the NS2 shell.
- Define a TCL Script:
In hierarchical routing, the network is frequently split into clusters. Each cluster has a cluster head, which manages routing in the cluster and to other clusters. Following is an example of how to make a hierarchical routing network utilizing NS2:
# Create a new simulator object
set ns [new Simulator]
# Open files for tracing and NAM output
set tracefile [open out.tr w]
set namfile [open out.nam w]
$ns trace-all $tracefile
$ns namtrace-all $namfile
# Define a procedure to create a cluster of nodes
proc create_cluster {ns num_nodes x y dx} {
set nodes {}
for {set i 0} {$i < $num_nodes} {incr i} {
set node [$ns node]
$node set X_ [expr $x + ($i * $dx)]
$node set Y_ $y
lappend nodes $node
}
return $nodes
}
# Create cluster 1
set cluster1 [create_cluster $ns 5 100 100 50]
# Create cluster 2
set cluster2 [create_cluster $ns 5 100 200 50]
# Create links within the clusters
foreach node1 $cluster1 node2 $cluster1 {
if {$node1 != $node2} {
$ns duplex-link $node1 $node2 1Mb 10ms DropTail
}
}
foreach node1 $cluster2 node2 $cluster2 {
if {$node1 != $node2} {
$ns duplex-link $node1 $node2 1Mb 10ms DropTail
}
}
# Cluster heads (gateway nodes between clusters)
set ch1 [lindex $cluster1 0]
set ch2 [lindex $cluster2 0]
# Create an inter-cluster link between cluster heads
$ns duplex-link $ch1 $ch2 2Mb 20ms DropTail
# Set up hierarchical routing (simulate using AODV as an example)
$ns rtproto Hierarchical
# Define a traffic source
set udp0 [new Agent/UDP]
set null0 [new Agent/Null]
set cbr [new Application/Traffic/CBR]
$ns attach-agent [lindex $cluster1 1] $udp0
$ns attach-agent [lindex $cluster2 2] $null0
$ns connect $udp0 $null0
$cbr set packetSize_ 512
$cbr set interval_ 0.005
$cbr attach-agent $udp0
# Start the simulation
$ns at 1.0 “$cbr start”
$ns at 5.0 “$cbr stop”
$ns at 6.0 “finish”
# Finish procedure to end simulation
proc finish {} {
global ns tracefile namfile
$ns flush-trace
close $tracefile
close $namfile
exec nam out.nam &
exit 0
}
# Run the simulation
$ns run
- Explanation of the TCL Script:
- Cluster Creation: The create_cluster procedure makes a group of nodes, which are interconnected in the similar cluster.
- Intra-Cluster Links: For each cluster, a full mesh of connections is made (we can also modify this to be a star or other topology).
- Cluster Heads: Each cluster has a head node (the first node in each cluster), which performs as the gateway for communication among the clusters.
- Inter-Cluster Links: A link is established among the cluster heads to replicate communication between clusters.
- Traffic Source: A UDP agent is utilized to generate traffic among a node in one cluster and a node within another cluster.
- Hierarchical Routing: In this instance, we replicate a hierarchical routing protocol utilizing the general Hierarchical routing mechanism within NS2. It can be substituted with a more particular hierarchical protocol if necessary.
- Simulate Specific Hierarchical Routing Protocols:
The above simulation offers a common hierarchical structure. We can substitute the routing mechanism with any precise hierarchical routing protocol such as Hierarchical AODV (H-AODV) or Hierarchical OLSR; however this would need either executing those protocols within NS2 (by modifying its C++ code) or utilizing any extensions available online.
- Run the Simulation:
After writing the TCL script, we execute the simulation using the below command:
ns hierarchical_routing.tcl
This will make an output trace file (out.tr) and a NAM file (out.nam). We can envision the network using NAM:
nam out.nam
- Analyze Results:
The trace file (out.tr) will include records of all events in the network. We can investigate this file to estimate the performance parameters such as throughput, delay, and packet loss.
Example commands to parse the trace file:
awk ‘{ if ($1 == “r” && $4 == “udp”) print $0 }’ out.tr
We can further automate the extraction of related performance parameters.
- Modify and Extend the Simulation:
- Cluster Design: We can change the amount of clusters, the size of clusters, and the links among them to replicate diverse hierarchical topologies.
- Traffic Sources: Test with distinct traffic patterns such as TCP, UDP, and CBR (Constant Bit Rate) flows.
- Performance Metrics: Utilize NS2 tools or write scripts to compute the performance parameters like throughput, average delay, jitter, and packet loss.
Finally, we had successfully provided the detailed approach for Hierarchical routing projects that were simulated using NS2 simulation tool. We are furnished to extend the simulation with more information relevant to this subject as needed.
To simulate Hierarchical Routing projects utilizing NS2 tool we at phdprime.com will give you best quality services by sharing fresh topics and ideas that suits your interest. Get in touch with phdprime.com for novel guidance.