How to Simulate XY Routing Projects Using NS2

To simulate XY routing in ns2, it is a simple deterministic routing approaches usually utilized in mesh or grid network topologies, like in Network-on-Chip (NoC) systems. In XY routing, packets are mainly transmitted along the X-axis (horizontal) to the proper column, and then along the Y-axis (vertical) to the destination row. This technique mitigate deadlock and make sure deterministic packet delivery.

Here’s how we can simulate XY routing in NS2 by generating a grid network in which the packets follow XY routing rules.

Steps to Simulate XY Routing in NS2

  1. Install NS2

Ensure that ns2is installed on the system.

  1. Create a TCL Script for XY Routing Simulation

We will physically describe the XY routing behaviour, in which the packets are transmitted first along the X-axis and then along the Y-axis. While NS2 does not have built-in support for XY routing, we required to replicate this behaviour explicitly by adjusting the routing among nodes.

Example TCL Script for XY Routing Simulation:

# Create a simulator object

set ns [new Simulator]

# Define trace and NAM files for analysis and visualization

set tracefile [open “xy_routing_trace.tr” w]

set namfile [open “xy_routing_simulation.nam” w]

$ns trace-all $tracefile

$ns namtrace-all $namfile

# Define a grid topology with nodes arranged in a 3×3 grid (for simplicity)

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]

set n8 [$ns node]

# Set up the grid connections using duplex links

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

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

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

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

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

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

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

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

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

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

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

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

# Set up static XY routing (first move in X direction, then Y direction)

proc xy-routing {src dst} {

global ns

# Route along the X-axis first

if {$src < $dst && ($src % 3 != 2)} {

$ns at 0.0 “$src add-route-to $dst 1”

}

# Then route along the Y-axis

if {$src > $dst && ($src % 3 == 0)} {

$ns at 0.0 “$src add-route-to $dst 1”

}

}

# Manually define routes following the XY routing logic

$ns at 0.0 “$n0 add-route-to $n4 1”

$ns at 0.0 “$n4 add-route-to $n8 1”

$ns at 0.0 “$n0 add-route-to $n3 1”

$ns at 0.0 “$n3 add-route-to $n6 1”

# Create UDP agents for sending and receiving traffic

set udp0 [new Agent/UDP]

set udp1 [new Agent/UDP]

# Attach the UDP agents to the source (n0) and destination (n8)

$ns attach-agent $n0 $udp0

$ns attach-agent $n8 $udp1

# Define a Constant Bit Rate (CBR) traffic generator

set cbr0 [new Application/Traffic/CBR]

$cbr0 set packetSize_ 512

$cbr0 set rate_ 1Mb

$cbr0 attach-agent $udp0

# Connect the source and destination agents

$ns connect $udp0 $udp1

# Schedule the traffic flow

$ns at 1.0 “$cbr0 start”

$ns at 4.5 “$cbr0 stop”

# Define the finish procedure

proc finish {} {

global ns tracefile namfile

$ns flush-trace

close $tracefile

close $namfile

exit 0

}

# End the simulation at 5 seconds

$ns at 5.0 “finish”

# Run the simulation

$ns run

  1. Run the Simulation

Save the script as xy_routing_simulation.tcl and execute it in NS2:

ns xy_routing_simulation.tcl

  1. Visualize the Simulation Using NAM

Open the generated .nam file in the Network Animator (NAM) to envision the XY routing:

nam xy_routing_simulation.nam

  1. Analyse the Trace File

The trace file (xy_routing_trace.tr) will encompass information of the packet transmissions and the routing decisions. We need to evaluate this file to examine:

  • Whether packets are transmitted along the X-axis first and then along the Y-axis.
  • Parameters like packet delivery ratio, end-to-end delay, and throughput.
  1. Modify the Simulation
  • Grid Size: Expand the grid size to generate a larger mesh network and track on how XY routing manages more complex topologies.
  • Traffic Patterns: incorporate multiple traffic sources and destinations to see how XY routing acts as with multiple flows.
  • Node Failures: Replicate node failures to validate on how XY routing manages the broken links.

Optional Enhancements:

  • Energy-Aware XY Routing: Adjust the routing techniques to deliberate node energy, routing packets via nodes with higher residual energy.
  • QoS Metrics: Incorporate Quality of Service (QoS) parameters into the routing decisions like selecting the routes with higher bandwidth or lower delay.

From the demonstration we provide the complete procedures to simulate the XY routing with example ideas and sample scenarios that were simulate and visualized using ns2 tool. If you did like to know more details regarding the XY routing we will provide it. Make sure your project performs at its best with our team. If you’re looking to simulate XY Routing Projects using NS2, we at phdprime.com guarantee top-notch results. Just send us your project details, and we’ll help you out from there.

Opening Time

9:00am

Lunch Time

12:30pm

Break Time

4:00pm

Closing Time

6:30pm

  • award1
  • award2