How to Simulate Cluster Topology Projects Using NS2

To simulate Cluster Topology in networking using ns2has includes numerous steps that  need to forming nodes into groups (clusters), in which each cluster has a central node (cluster head) which handles communication contained by the cluster and transmits data among the clusters. This topology is usually utilized in sensor networks, distributed systems, and IoT networks to improve scalability and manageability.

Here’s how to simulate a Cluster Topology in NS2:

Steps to Simulate Cluster Topology Projects in NS2

  1. Set up NS2 Environment:

Make sure that NS2 is installed and working properly on the system. The simulation will be accomplished by composing a TCL script to describe the cluster topology and replicate interaction among nodes in clusters.

  1. Understanding Cluster Topology:
  • In a Cluster Topology, nodes are assembled into clusters. Each cluster has a cluster head liable for handling intra-cluster communication and send on data among the cluster and other clusters.
  • Nodes in each cluster interact with their respective cluster heads, and the cluster heads manage communication among the clusters.
  1. Create a TCL Script for Cluster Topology:

Below is an instance TCL script to mimic a Cluster Topology with 2 clusters and 3 nodes in each cluster, using NS2:

# 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

# ======= Cluster 1 =======

# Create nodes for Cluster 1

set c1_head [$ns node]   ;# Cluster 1 Head

set c1_node1 [$ns node]  ;# Node 1 in Cluster 1

set c1_node2 [$ns node]  ;# Node 2 in Cluster 1

# ======= Cluster 2 =======

# Create nodes for Cluster 2

set c2_head [$ns node]   ;# Cluster 2 Head

set c2_node1 [$ns node]  ;# Node 1 in Cluster 2

set c2_node2 [$ns node]  ;# Node 2 in Cluster 2

# ======= Links in Cluster 1 =======

# Create intra-cluster links between nodes and the cluster head in Cluster 1

$ns duplex-link $c1_head $c1_node1 5Mb 10ms DropTail

$ns duplex-link $c1_head $c1_node2 5Mb 10ms DropTail

# ======= Links in Cluster 2 =======

# Create intra-cluster links between nodes and the cluster head in Cluster 2

$ns duplex-link $c2_head $c2_node1 5Mb 10ms DropTail

$ns duplex-link $c2_head $c2_node2 5Mb 10ms DropTail

# ======= Inter-Cluster Communication =======

# Create a link between the cluster heads of Cluster 1 and Cluster 2

$ns duplex-link $c1_head $c2_head 10Mb 20ms DropTail

# ======= Traffic Generation =======

# Attach UDP agents for intra-cluster communication in Cluster 1

set udp1 [new Agent/UDP]

$ns attach-agent $c1_node1 $udp1

set null1 [new Agent/Null]

$ns attach-agent $c1_node2 $null1

# Attach UDP agents for intra-cluster communication in Cluster 2

set udp2 [new Agent/UDP]

$ns attach-agent $c2_node1 $udp2

set null2 [new Agent/Null]

$ns attach-agent $c2_node2 $null2

# Attach UDP agents for inter-cluster communication

set udp_inter [new Agent/UDP]

$ns attach-agent $c1_head $udp_inter

set null_inter [new Agent/Null]

$ns attach-agent $c2_head $null_inter

# ======= CBR Traffic Setup =======

# Create CBR (Constant Bit Rate) traffic for intra-cluster communication in Cluster 1

set cbr1 [new Application/Traffic/CBR]

$cbr1 attach-agent $udp1

$cbr1 set packetSize_ 512

$cbr1 set rate_ 100Kb

# Create CBR traffic for intra-cluster communication in Cluster 2

set cbr2 [new Application/Traffic/CBR]

$cbr2 attach-agent $udp2

$cbr2 set packetSize_ 512

$cbr2 set rate_ 100Kb

# Create CBR traffic for inter-cluster communication between Cluster 1 Head and Cluster 2 Head

set cbr_inter [new Application/Traffic/CBR]

$cbr_inter attach-agent $udp_inter

$cbr_inter set packetSize_ 512

$cbr_inter set rate_ 100Kb

# Schedule the traffic

$ns at 1.0 “$cbr1 start”    ;# Start intra-cluster traffic in Cluster 1

$ns at 1.5 “$cbr2 start”    ;# Start intra-cluster traffic in Cluster 2

$ns at 2.0 “$cbr_inter start”  ;# Start inter-cluster communication

# Stop the traffic

$ns at 5.0 “$cbr1 stop”

$ns at 5.5 “$cbr2 stop”

$ns at 6.0 “$cbr_inter 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

  1. Explanation of the Code:
  • Cluster Nodes: Two clusters are created, with each cluster containing of a cluster head and two nodes. Cluster 1 has nodes c1_head, c1_node1, and c1_node2, and Cluster 2 has nodes c2_head, c2_node1, and c2_node2.
  • Intra-Cluster Links: Duplex links are introduced among the cluster heads and their respective nodes in each cluster that construct intra-cluster communication paths.
  • Inter-Cluster Links: A duplex link is generated among the cluster heads of Cluster 1 and Cluster 2, permits an inter-cluster communication.
  • Traffic Generation:
    • UDP agents are attached to the nodes for intra-cluster communication within each cluster, and among the cluster heads for inter-cluster communication.
    • Constant Bit Rate (CBR) traffic is created within each cluster and between the cluster heads that replicates communication among the nodes within the clusters and via the clusters.
  • Traffic Scheduling: Traffic initiate at 1.0 seconds (Cluster 1), 1.5 seconds (Cluster 2), and 2.0 seconds (inter-cluster communication), and terminate at 5.0, 5.5, and 6.0 seconds, correspondingly.
  • Simulation End: The simulation terminates at 7 seconds, and the outcomes are saved in a .nam file for visualization.
  1. Run the Simulation:
  1. Save the script as cluster_topology.tcl.
  2. Open a terminal and navigate to the directory in which the script is saved.
  3. execute the simulation using:

ns cluster_topology.tcl

  1. The replication will create an out.nam file that can be opened using Network Animator (NAM) for visualization.
  1. Visualization in NAM:
  • Open the out.nam file in NAM to envision the cluster topology. We will see two clusters, with nodes in each cluster interacting with their cluster heads, and the cluster heads interacts with each other.
  1. Customization and Enhancements:
  • More Clusters and Nodes: we can add more clusters and nodes by prolonging the script. For example, we can generate additional cluster heads and nodes and associate them correspondingly to the current setup.
  • TCP Traffic: Exchange the UDP agents with TCP agents for reliable communication:

set tcp1 [new Agent/TCP]

$ns attach-agent $c1_node1 $tcp1

set sink1 [new Agent/TCPSink]

$ns attach-agent $c1_node2 $sink1

$ns connect $tcp1 $sink1

  • Cluster-Based Communication Patterns: we can generate the environment in which the cluster heads only forward information when essential or replicate hierarchical cluster structures.
  • Performance Metrics: Incorporate trace files to evaluate parameters like packet loss, delay, and throughput:

set tracefile [open trace.tr w]

$ns trace-all $tracefile

  1. Performance Analysis:

To evaluate the performance of the cluster topology, you can:

  • Evaluate throughput by monitoring on how much data is successfully routed among nodes in the same cluster and between clusters.
  • Assess latency (delay) as data transfer among nodes within clusters and across clusters.
  • Measure packet loss to regulate the reliability of the network, especially in high traffic conditions.

In this demonstration we clearly learned and gain knowledge on how the Cluster Topology project will perform in the network simulation environment using the tool of ns2 and also we deliver the sample snippets to complete the process. More details regarding this process will also be shared.

phdprime.com will help you simulate Cluster Topology Projects with the NS2 tool. If you need solid research guidance and simulation support, you can trust our experts.

Opening Time

9:00am

Lunch Time

12:30pm

Break Time

4:00pm

Closing Time

6:30pm

  • award1
  • award2