How to Implement Benes Network Routing in NS2

To implement Benes Network Routing in NS2 (Network Simulator 2), we have to simulate the structure of the Benes network which is a variant of reloadable multistage interconnection network. Below is the step-by-step approach on how to implement the routing in ns2:

Steps for Implementing Benes Network Routing in NS2:

  1. Understand the Benes Network Structure:
    • A Benes network has 2log⁡2(N)−12 \log_2(N) – 12log2​(N)−1 swapping stages for NNN input-output connections.
    • It is a layered architecture where each layer is composed of switches that link inputs to outputs, with two main stages: forward and backward.
  2. Modify or Extend NS2 Routing Protocol:
    • NS2 does not have default implementation for Benes Network routing. You need to expand or adjust an available routing protocol or generate a custom routing protocol.
    • You can alter protocols include DSR (Dynamic Source Routing) or AODV (Ad-hoc On-demand Distance Vector) routing protocol to put up Benes network activities.
  3. Create a Network Topology:
    • Use TCL script to develop the Benes network topology in NS2.
    • Each node in NS2 will indicate a switch in the Benes network. The links amongst the nodes will signify the interconnections amidst switches.
  4. Implement the Routing Algorithm:
    • Establish a custom routing logic where the data flows over the switches following the Benes network path.
    • You will need to write the logic in C++ in NS2. You can extend agent.cc and dsr.cc files for a new routing algorithm.
    • Evade contention in the network by using the concept of reorganizable routing paths.
  5. Simulation Script (TCL):
    • Once the protocol is executed, set up a TCL script that states the network, build the nodes, links, and data flows. In the script:
      • Develop the source and destination nodes.
      • Fixed the packet flow to follow the Benes network routing path.
  6. Validate the Implementation:
    • Verify the packets are properly directed over the Benes network paths by executing simulations.
    • Compute network metrics like latency, throughput, and packet delivery ratio to assess performance.

Example TCL Script:

Below is a sample to give you an idea of what the TCL script might look like for a small topology:

# Create NS2 simulator instance

set ns [new Simulator]

# Define the nodes

set node1 [$ns node]

set node2 [$ns node]

set node3 [$ns node]

set node4 [$ns node]

# Create links between nodes to form a small Benes-like network

$ns duplex-link $node1 $node2 1Mb 10ms DropTail

$ns duplex-link $node2 $node3 1Mb 10ms DropTail

$ns duplex-link $node3 $node4 1Mb 10ms DropTail

# Setup a UDP agent and CBR traffic

set udp [new Agent/UDP]

$ns attach-agent $node1 $udp

set null [new Agent/Null]

$ns attach-agent $node4 $null

$ns connect $udp $null

# Set up a CBR traffic generator

set cbr [new Application/Traffic/CBR]

$cbr set packetSize_ 500

$cbr set interval_ 0.005

$cbr attach-agent $udp

# Schedule events

$ns at 0.1 “$cbr start”

$ns at 4.0 “finish”

proc finish {} {

global ns

$ns flush-trace

exit 0

}

# Run the simulation

$ns run

C++ Code:

You need to adjust the C++ layer for the custom Benes routing algorithm. Below is a skeleton for where you might begin:

  1. Create a new routing agent by duplicating an available routing agent (like DSR or AODV).
  2. Modify the routing mechanism to accomplish Benes network-related routing by cutting out agent.cc and relevant files.

Compilation and Execution:

  • After altering the source code, recompile NS2 by running:

./configure

make clean

make

  • Then run your TCL simulation script to inspect the implementation.

As we saw in this manual, it will help you to set up the simulation network, to modify the ns2 and to implement the Benes network routing in the ns2 by defining routing protocol that offer some samples. If needed, we can help you with another approach of other simulation networks. We’re here to provide you with top-notch guidance on implementing Benes Network Routing in ns2.