How to Implement Cluster Topology in NS2
To implement the Cluster Topology in ns2, this topology is a network arrangement in which the nodes are formed into clusters with every cluster having cluster head (CH) accountable for coordinating communication inside the cluster and among the clusters. It is often used in wireless sensor networks in which the heads can handle the communication amongst nodes and pass data to a central base station or to other cluster heads. Follow the below guide to implement the cluster topology using ns2:
Steps to Implement Cluster Topology in NS2:
- Set Up the Cluster Network Topology:
- State nodes for each cluster.
- Choose a node in each cluster to behave like the Cluster Head (CH).
- Generate links amidst nodes in each cluster and the cluster head.
- Link cluster heads to each other and/or to a central node (like a base station).
- Simulate Traffic Flow:
- Set up traffic amongst nodes inside the same cluster and over clusters through the cluster heads.
Example of Cluster Topology Implementation in NS2:
The below sample script that explains how to configure a basic cluster topology with two clusters, each with a cluster head and numerous nodes. Traffic flows amongst nodes inside the same cluster and across clusters through the cluster heads.
# Create a new simulator
set ns [new Simulator]
# Open trace file for output
set tracefile [open out.tr w]
$ns trace-all $tracefile
# Define the cluster head and nodes for Cluster 1
set cluster_head1 [$ns node] ;# Cluster Head for Cluster 1
set node1_1 [$ns node] ;# Node 1 in Cluster 1
set node1_2 [$ns node] ;# Node 2 in Cluster 1
set node1_3 [$ns node] ;# Node 3 in Cluster 1
# Create duplex links between cluster nodes and the cluster head in Cluster 1
$ns duplex-link $node1_1 $cluster_head1 1Mb 10ms DropTail ;# Link between node1_1 and Cluster Head 1
$ns duplex-link $node1_2 $cluster_head1 1Mb 10ms DropTail ;# Link between node1_2 and Cluster Head 1
$ns duplex-link $node1_3 $cluster_head1 1Mb 10ms DropTail ;# Link between node1_3 and Cluster Head 1
# Define the cluster head and nodes for Cluster 2
set cluster_head2 [$ns node] ;# Cluster Head for Cluster 2
set node2_1 [$ns node] ;# Node 1 in Cluster 2
set node2_2 [$ns node] ;# Node 2 in Cluster 2
set node2_3 [$ns node] ;# Node 3 in Cluster 2
# Create duplex links between cluster nodes and the cluster head in Cluster 2
$ns duplex-link $node2_1 $cluster_head2 1Mb 10ms DropTail ;# Link between node2_1 and Cluster Head 2
$ns duplex-link $node2_2 $cluster_head2 1Mb 10ms DropTail ;# Link between node2_2 and Cluster Head 2
$ns duplex-link $node2_3 $cluster_head2 1Mb 10ms DropTail ;# Link between node2_3 and Cluster Head 2
# Create a duplex link between the cluster heads to allow inter-cluster communication
$ns duplex-link $cluster_head1 $cluster_head2 2Mb 10ms DropTail ;# Link between Cluster Head 1 and Cluster Head 2
# Define TCP agents for communication between nodes
# Traffic from node1_1 (Cluster 1) to node1_3 (within Cluster 1)
set tcp0 [new Agent/TCP]
set sink0 [new Agent/TCPSink]
$ns attach-agent $node1_1 $tcp0
$ns attach-agent $node1_3 $sink0
$ns connect $tcp0 $sink0
# Simulate FTP traffic from node1_1 to node1_3 (within Cluster 1)
set ftp0 [new Application/FTP]
$ftp0 attach-agent $tcp0
$ns at 1.0 “$ftp0 start” ;# Start traffic at 1 second
# Traffic from node2_2 (Cluster 2) to node1_2 (across clusters via cluster heads)
set tcp1 [new Agent/TCP]
set sink1 [new Agent/TCPSink]
$ns attach-agent $node2_2 $tcp1
$ns attach-agent $node1_2 $sink1
$ns connect $tcp1 $sink1
# Simulate FTP traffic from node2_2 (Cluster 2) to node1_2 (Cluster 1)
set ftp1 [new Application/FTP]
$ftp1 attach-agent $tcp1
$ns at 2.0 “$ftp1 start” ;# Start traffic at 2 seconds
# End the simulation after 10 seconds
$ns at 10.0 “finish”
proc finish {} {
global ns tracefile
$ns flush-trace
close $tracefile
exit 0
}
# Run the simulation
$ns run
Explanation of the Script:
- Cluster 1:
- cluster_head1: The cluster head accountable for handling communication inside Cluster 1.
- node1_1, node1_2, and node1_3: The regular nodes in Cluster 1.
- Duplex links connect the nodes to the cluster head.
- Cluster 2:
- cluster_head2: The cluster head for Cluster 2.
- node2_1, node2_2, and node2_3: The regular nodes in Cluster 2.
- Duplex links connect the nodes to the cluster head.
- Inter-cluster Communication:
- A duplex link connects cluster_head1 and cluster_head2, enabling communication amongst nodes in various clusters.
- Traffic Simulation:
- TCP agents replicate communication amidst nodes.
- FTP (File Transfer Protocol) produces traffic between the nodes.
- Traffic flows from node1_1 to node1_3 (within Cluster 1) and from node2_2 to node1_2 (across clusters through the cluster heads).
- Simulation Duration:
- The simulation runs for 10 seconds, during which traffic flows inside and over clusters.
Post-Simulation Analysis:
- Trace File Analysis:
- Monitor how packets are forwarded amongst nodes inside the same cluster and throughout clusters via cluster heads by opening the trace file (out.tr).
- NAM Visualization:
- Visualize the cluster topology by using NAM (Network Animator). You will observe nodes linked to their corresponding cluster heads, and how traffic flows between nodes in clusters and across clusters.
- Performance Metrics:
- Compute network performance metrics including delay, throughput, and packet loss to evaluate how well the cluster topology manages traffic.
Enhancing the Simulation:
- Adding More Clusters:
- Attach more clusters, each with its own cluster head and nodes, to replicate a larger network with more clusters.
- Simulating Traffic in Both Directions:
- Build extra traffic in both directions (such as from node1_3 to node1_1 or from node1_2 to node2_2) to recreate bidirectional communication.
- Changing Traffic Type:
- Change TCP with UDP or use CBR (Constant Bit Rate) instead of FTP to simulate various kinds of traffic and evaluate how the network functions.
- Cluster Head Mobility:
- Simulate environment where cluster heads or nodes adjust dynamically like choosing a new cluster head or nodes moving amongst clusters.
- Varying Link Parameters:
- Understand how the network performance vary in different conditions by researching with numerous link parameters includes bandwidth, delay, and queue type (e.g., DropTail or RED).
In this process, we had covered the details from the simulation set up to post simulation analysis and how to enhance the simulation for the implementation of Cluster Topology using ns2. For further analysis or requirements, we will help you with additional information as per your demands.
Our team specializes in Cluster Topology projects utilizing the NS2 tool.If you require customized research, please visit ns2project.com for personalized support. We guarantee exceptional implementation outcomes and also offer comparative analysis results. Our expertise extends to mobile nodes as well.