How to Start Hierarchical Topology Projects Using NS2

To stimulate a Hierarchical Topology project in NS2 (Network Simulator 2) have includes the replicate of multi-tiered network architecture in which nodes are organized in level such as access, aggregation, and core layers. This topology is generally used in large-scale networks such as enterprise LANs, data centers, and hierarchical wireless sensor networks.

Here’s how to start and simulate a Hierarchical Topology project in NS2:

Steps to Start Hierarchical Topology Projects Using NS2

  1. Understand Hierarchical Topology
  • Hierarchical Topology:
    • Nodes are organized the layers or levels for instance access layer connects end devices, aggregation layer consolidates traffic, and core layer handles interconnections.
  • Use Cases:
    • It designs the scalable and modular network.
    • The multi-tier wireless sensor networks or data centers.
  • Key Metrics:
    • The topology considers the performance metrices such as Throughput, latency, packet delivery ratio (PDR), and fault tolerance.
  1. Set Up NS2
  1. Install NS2:
    • Install and validate the NS2 by a sample script:

ns example.tcl

  1. Tools:
    • NAM (Network Animator) intended for envision.
    • Trace File Analysis tools like AWK for processing the parameter metrics.
  1. Plan the Hierarchical Topology
  • Example Structure:
    • Access Layer: Nodes (hosts) are linked to the edge routers/switches.
    • Aggregation Layer: Linked the edge routers for aggregation switches/routers.
    • Core Layer: The core layer has high-capacity backbone network for interrelating the aggregation routers.
  1. Write the Simulation Script

Step 4.1: Create the TCL Script

Store the script as hierarchical_topology.tcl.

Step 4.2: Initialize the Simulator

Configure the replicator and tracing:

set ns [new Simulator]

set tracefile [open trace.tr w]

$ns trace-all $tracefile

set namfile [open hierarchical_topology.nam w]

$ns namtrace-all $namfile

Step 4.3: Define Nodes

  • Build a nodes for every layer:

# Core Layer Nodes

set core1 [$ns node]

set core2 [$ns node]

# Aggregation Layer Nodes

set agg1 [$ns node]

set agg2 [$ns node]

# Access Layer Nodes

set access1 [$ns node]

set access2 [$ns node]

set access3 [$ns node]

set access4 [$ns node]

Step 4.4: Configure Links

  • Nodes are connected the hierarchically:

# Core to Aggregation Links

$ns duplex-link $core1 $agg1 10Mb 10ms DropTail

$ns duplex-link $core2 $agg2 10Mb 10ms DropTail

# Aggregation to Access Links

$ns duplex-link $agg1 $access1 1Mb 5ms DropTail

$ns duplex-link $agg1 $access2 1Mb 5ms DropTail

$ns duplex-link $agg2 $access3 1Mb 5ms DropTail

$ns duplex-link $agg2 $access4 1Mb 5ms DropTail

Step 4.5: Configure Traffic

Set up traffic flows from access layer nodes to the core:

# Traffic from access1 to core2

set udp1 [new Agent/UDP]

$ns attach-agent $access1 $udp1

set null1 [new Agent/Null]

$ns attach-agent $core2 $null1

$ns connect $udp1 $null1

set cbr1 [new Application/Traffic/CBR]

$cbr1 attach-agent $udp1

$cbr1 set packetSize_ 512

$cbr1 set rate_ 100kb

$ns at 1.0 “$cbr1 start”

 

# Traffic from access3 to core1

set udp2 [new Agent/UDP]

$ns attach-agent $access3 $udp2

set null2 [new Agent/Null]

$ns attach-agent $core1 $null2

$ns connect $udp2 $null2

set cbr2 [new Application/Traffic/CBR]

$cbr2 attach-agent $udp2

$cbr2 set packetSize_ 512

$cbr2 set rate_ 100kb

$ns at 2.0 “$cbr2 start”

Step 4.6: Enable Routing

  • Use the tool for dynamic routing protocols like as AODV for the replication:

$ns rtproto DV

Step 4.7: Finalize the Script

Improve the replication end and visualization setting:

$ns at 10.0 “finish”

proc finish {} {

global ns tracefile namfile

$ns flush-trace

close $tracefile

close $namfile

exec nam hierarchical_topology.nam &

exit 0

}

$ns run

  1. Run the Simulation
  1. Store the script as hierarchical_topology.tcl.
  2. Implement the process:

ns hierarchical_topology.tcl

  1. Start the NAM file for visualization:

nam hierarchical_topology.nam

  1. Analyze Results
  • Trace File Analysis:
    • Use the tool trace.tr for examines the parameter metrices throughput, latency, and PDR.
    • Sample AWK script for throughput:

awk ‘{if ($1 == “r” && $4 == “udp”) sum += $8} END {print “Throughput: “, sum}’

  • Key Metrics:
    • Throughput: The complete data are successfully transmitted in the throughput.
    • Latency: The normal duration for during the delay in packet delivery.
    • Packet Delivery Ratio (PDR): Ratio of delivered packets for transmits the packets.
  1. Expand the Simulation
  1. Introduce Node or Link Failures:
    • Replicate the effect of failure in the aggregation or core layer:

$ns at 5.0 “$ns link-fail $agg1 $access2”

  1. Vary Traffic Patterns:
    • Enhance the TCP or FTP congestion for diverse environment.
  2. Increase the Network Size:
    • Increase the network through adding further layers or nodes.
  3. Implement Multicast Traffic:
    • It replicates the multicast data distribution for effective communication.
  1. Document the Project
  • Objective: Define the purpose of replicate a hierarchical topology.
  • Setup: State the network model, nodes, and congestion setting.
  • Results: Deliver the graphs and metrics for throughput, latency, and PDR.
  • Conclusions: Summarize outcomes and potential optimizations.

We clearly learned and demonstrate how to calculate and measure the network latency using the ns2 tool with sample code snippets and should you have any queries about this project, please refer to the additional manual.