How to Simulate Benes Network Routing Projects Using NS2

To simulate Benes Network Routing utilizing NS2, we will require setting up a Benes network topology and configuring the routing protocols or custom routing logic, which matches the features of a Benes network. The Benes network is a familiar structure in interconnection networks that frequently utilized in switching networks in which each input can be attached to any output with a rearrangeable set of switches.

We will guide you through the step-by-step approach to simulate a Benes network in NS2:

Steps to Simulate Benes Network Routing in NS2

  1. Set Up NS2 Environment

Make sure that NS2 is installed and working on the system. We can check this by running:

ns

It will open the NS2 shell if NS2 is appropriately installed.

  1. Understanding Benes Network Topology

A Benes network contains an interconnection of several switching stages. For a Benes network with n inputs and n outputs, there are 2 * log(n) – 1 stages. Each stage includes numerous switching elements, and the network permits any input to be associated to any output.

  1. Write a TCL Script for Benes Network Topology

To replicate the Benes network, we require describing the topology and routing rules. The following is a TCL script for configuring a Benes network with 8 inputs and 8 outputs (3-stage Benes network).

# Create a simulator object

set ns [new Simulator]

# Open trace and NAM output files

set tracefile [open out.tr w]

set namfile [open out.nam w]

$ns trace-all $tracefile

$ns namtrace-all $namfile

# Define nodes for a Benes Network (8 inputs, 3 stages, 8 outputs)

# Stage 1 (8 nodes for input stage)

set n0 [$ns node]

set n1 [$ns node]

set n2 [$ns node]

set n3 [$ns node]

set n4 [$ns node]

set n5 [$ns node]

set n6 [$ns node]

set n7 [$ns node]

# Stage 2 (8 nodes for middle stage)

set s0 [$ns node]

set s1 [$ns node]

set s2 [$ns node]

set s3 [$ns node]

set s4 [$ns node]

set s5 [$ns node]

set s6 [$ns node]

set s7 [$ns node]

# Stage 3 (8 nodes for output stage)

set o0 [$ns node]

set o1 [$ns node]

set o2 [$ns node]

set o3 [$ns node]

set o4 [$ns node]

set o5 [$ns node]

set o6 [$ns node]

set o7 [$ns node]

# Create links between stages (Stage 1 to Stage 2)

$ns duplex-link $n0 $s0 1Mb 10ms DropTail

$ns duplex-link $n1 $s1 1Mb 10ms DropTail

$ns duplex-link $n2 $s2 1Mb 10ms DropTail

$ns duplex-link $n3 $s3 1Mb 10ms DropTail

$ns duplex-link $n4 $s4 1Mb 10ms DropTail

$ns duplex-link $n5 $s5 1Mb 10ms DropTail

$ns duplex-link $n6 $s6 1Mb 10ms DropTail

$ns duplex-link $n7 $s7 1Mb 10ms DropTail

# Create links between Stage 2 and Stage 3 (middle stage to output stage)

$ns duplex-link $s0 $o0 1Mb 10ms DropTail

$ns duplex-link $s1 $o1 1Mb 10ms DropTail

$ns duplex-link $s2 $o2 1Mb 10ms DropTail

$ns duplex-link $s3 $o3 1Mb 10ms DropTail

$ns duplex-link $s4 $o4 1Mb 10ms DropTail

$ns duplex-link $s5 $o5 1Mb 10ms DropTail

$ns duplex-link $s6 $o6 1Mb 10ms DropTail

$ns duplex-link $s7 $o7 1Mb 10ms DropTail

# Add cross-stage links to make the Benes network rearrangeable

# (Example cross links from stage 1 to stage 2)

$ns duplex-link $n0 $s7 1Mb 10ms DropTail

$ns duplex-link $n1 $s6 1Mb 10ms DropTail

$ns duplex-link $n2 $s5 1Mb 10ms DropTail

$ns duplex-link $n3 $s4 1Mb 10ms DropTail

$ns duplex-link $n4 $s3 1Mb 10ms DropTail

$ns duplex-link $n5 $s2 1Mb 10ms DropTail

$ns duplex-link $n6 $s1 1Mb 10ms DropTail

$ns duplex-link $n7 $s0 1Mb 10ms DropTail

# Add cross-stage links between Stage 2 and Stage 3

$ns duplex-link $s0 $o7 1Mb 10ms DropTail

$ns duplex-link $s1 $o6 1Mb 10ms DropTail

$ns duplex-link $s2 $o5 1Mb 10ms DropTail

$ns duplex-link $s3 $o4 1Mb 10ms DropTail

$ns duplex-link $s4 $o3 1Mb 10ms DropTail

$ns duplex-link $s5 $o2 1Mb 10ms DropTail

$ns duplex-link $s6 $o1 1Mb 10ms DropTail

$ns duplex-link $s7 $o0 1Mb 10ms DropTail

# Define traffic from input to output

# Create a UDP agent and attach it to node n0 (input)

set udp0 [new Agent/UDP]

$ns attach-agent $n0 $udp0

# Create a Null agent and attach it to node o7 (output)

set null0 [new Agent/Null]

$ns attach-agent $o7 $null0

# Connect the source (n0) to the destination (o7)

$ns connect $udp0 $null0

# Create a CBR traffic generator and attach it to the UDP agent

set cbr0 [new Application/Traffic/CBR]

$cbr0 set packetSize_ 512

$cbr0 set interval_ 0.01

$cbr0 attach-agent $udp0

# Schedule the traffic to start and stop

$ns at 1.0 “$cbr0 start”

$ns at 4.5 “$cbr0 stop”

$ns at 5.0 “finish”

# Define the finish procedure

proc finish {} {

global ns tracefile namfile

$ns flush-trace

close $tracefile

close $namfile

exec nam out.nam &

exit 0

}

# Run the simulation

$ns run

  1. Explanation of the Script
  • Topology: The script configures a 3-stage Benes network with 8 inputs and 8 outputs, with each stage are associated by duplex links.
  • Cross-Links: Cross-links among the stages that replicate the rearrangeable nature of the Benes network.
  • Traffic: A UDP agent is utilized to generate traffic from node n0 (input) to node o7 (output) that is managed by a CBR (Constant Bit Rate) traffic generator.
  1. Running the Simulation

We need to save the script as benes_network.tcl and then run it using:

ns benes_network.tcl

It will make a trace file (out.tr) and a NAM file (out.nam) for visualization.

  1. Visualizing the Simulation

To envision the Benes network and traffic flow using NAM, execute:

nam out.nam

We will observe the Benes network and how packets are routed via diverse stages to attain the final output node.

  1. Modifying the Traffic

We can alter the script to mimic distinct traffic patterns, routing policies, or congestion scenarios by modifying the traffic generator or inserting more traffic sources and destinations.

For example, to send traffic from n1 to o6, we can insert:

# Additional traffic from n1 to o6

set udp1 [new Agent/UDP]

$ns attach-agent $n1 $udp1

set null1 [new Agent/Null]

$ns attach-agent $o6 $null1

$ns connect $udp1 $null1

set cbr1 [new Application/Traffic/CBR]

$cbr1 set packetSize_ 512

$cbr1 set interval_ 0.02

$cbr1 attach-agent $udp1

$ns at 1.5 “$cbr1 start”

$ns at 4.5 “$cbr1 stop”

  1. Analyzing the Trace File

The trace file (out.tr) includes detailed data regarding packet transmissions, routing decisions, and traffic flows. We can examine the trace file to assess:

  • Packet Delivery Ratio (PDR): The percentage of efficiently delivered packets.
  • Latency: The time taken for packets to travel from the origin to the destination.
  • Congestion: Calculate how link congestion influences traffic flow

In this simulation setup, we presented the basic approaches that were demonstrated using the sample code snippets related to the Benes Network projects which were simulated and evaluated through NS2 tool. Some specific insights regarding this process will be provided later.

If you want to set up routing protocols or create custom routing logic for your projects, we can provide you with excellent guidance. To simulate Benes Network Routing Projects using the NS2 tool, just share your project details with us, and we’ll assist you in achieving great results.

Opening Time

9:00am

Lunch Time

12:30pm

Break Time

4:00pm

Closing Time

6:30pm

  • award1
  • award2