How to Implement XY Routing in NS2
To implement XY routing in ns2 has several steps and it is a deterministic routing algorithm often used in network-on-chip (NoC) systems. In XY routing, packets are transmitted first along the X-axis (horizontal) up to they reach the destination column, and then alongside the Y-axis (vertical) until they extent the destination node. XY routing is basic and deadlock-free hence it is primarily used in grid-based topologies, like mesh or torus networks.
NS2 doesn’t support directly for XY routing for NoC systems or grid-based topologies, so we will need to execute it manually. Here’s how we can mimic XY routing in NS2 by configuring a mesh topology and describing the routes consequently.
Steps to Implement XY Routing in NS2:
- Install and Set Up NS2
Ensure NS2 is installed and executing properly on the system.
- Define a Grid/Mesh Topology
XY routing usually performs in a grid-like topology. we will need to manually to configure a mesh network in which the nodes are organised in a grid and routes are computed based on the X and Y coordinates of the source and destination nodes.
- Modify Tcl Script for XY Routing
The given below is a simple Tcl script that states a 4×4 mesh topology and executes XY routing manually.
Example of a Tcl Script for XY Routing in NS2:
# Create a new NS2 simulator instance
set ns [new Simulator]
# Create trace and NAM files for output
set tracefile [open “xy_routing_trace.tr” w]
$ns trace-all $tracefile
set namfile [open “xy_routing.nam” w]
$ns namtrace-all $namfile
# Define the grid topology with 16 nodes (4×4 mesh)
set grid_size 4
for {set i 0} {$i < $grid_size} {incr i} {
for {set j 0} {$j < $grid_size} {incr j} {
set id [expr {$i*$grid_size + $j}]
set node_($id) [$ns node]
}
}
# Create duplex links between adjacent nodes (horizontal and vertical links)
# Horizontal links (X-axis)
for {set i 0} {$i < $grid_size} {incr i} {
for {set j 0} {$j < $grid_size-1} {incr j} {
set id1 [expr {$i*$grid_size + $j}]
set id2 [expr {$i*$grid_size + $j+1}]
$ns duplex-link $node_($id1) $node_($id2) 1Mb 10ms DropTail
}
}
# Vertical links (Y-axis)
for {set i 0} {$i < $grid_size-1} {incr i} {
for {set j 0} {$j < $grid_size} {incr j} {
set id1 [expr {$i*$grid_size + $j}]
set id2 [expr {($i+1)*$grid_size + $j}]
$ns duplex-link $node_($id1) $node_($id2) 1Mb 10ms DropTail
}
}
# Enable manual static routing
$ns rtproto Manual
# Define XY routing: First route in X-direction, then in Y-direction
# XY routing example from node 0 (0,0) to node 15 (3,3)
# Horizontal (X) routing from node 0 to node 3
$ns manual-route $node_(0) $node_(3) $node_(1) $node_(2) $node_(3)
# Vertical (Y) routing from node 3 to node 15
$ns manual-route $node_(3) $node_(15) $node_(7) $node_(11) $node_(15)
# Attach TCP agent to node 0 and TCPSink agent to node 15
set tcp0 [new Agent/TCP]
$ns attach-agent $node_(0) $tcp0
set sink [new Agent/TCPSink]
$ns attach-agent $node_(15) $sink
# Connect the agents
$ns connect $tcp0 $sink
# Create a CBR traffic source
set cbr [new Application/Traffic/CBR]
$cbr attach-agent $tcp0
$cbr set packetSize_ 512
$cbr set interval_ 0.05
# Start and stop CBR traffic
$ns at 1.0 “$cbr start”
$ns at 4.5 “$cbr stop”
# Define the end of the simulation at 5.0 seconds
$ns at 5.0 “finish”
# Procedure to finish the simulation
proc finish {} {
global ns tracefile namfile
$ns flush-trace
close $tracefile
close $namfile
exec nam xy_routing.nam &
exit 0
}
# Run the simulation
$ns run
- Key Components of the Tcl Script for XY Routing:
- Grid Topology: The script states a 4×4 mesh grid topology with 16 nodes, in which each node is associated to its horizontal (X-axis) and vertical (Y-axis) neighbors.
- Manual Routing: While NS2 doesn’t support XY routing directly, we physically setup the routes. In this instance, the packet follows the XY routing strategy: it first travels together with X-axis (node 0 to node 3) and then along the Y-axis (node 3 to node 15).
- Traffic Generation: A TCP agent is involved to the source node (node 0), and a TCPSink agent is attached to the destination node (node 15). A CBR (Constant Bit Rate) traffic source creates the traffic from node 0 to node 15.
- Run the Simulation
Once the script is ready, execute the simulation using NS2:
ns xy_routing_simulation.tcl
This will create the trace and NAM files (xy_routing_trace.tr and xy_routing.nam).
- Analyse the Results
We can visualize the network using NAM (Network Animator):
nam xy_routing.nam
In NAM, we need to monitor that the packets follow the XY routing strategy, moving first in the horizontal (X) direction and then in the vertical (Y) direction.
- Expand the XY Routing Implementation
To execute a more complex XY routing scheme, that can:
- Expand the grid size like a 5×5 or 6×6 mesh topologies.
- Execute dynamic routing policies in which the XY routing technique decides the path according to node coordinates.
- Adjust the Tcl script to manage various source-destination pairs and mimic the larger networks.
Conclusion:
- XY Routing in NS2 can be executed by physically configuring routes in a grid/mesh topology.
- The routing follows a basic rule: packets are first transmitted together with the X-axis, and then along the Y-axis.
- We can visualize the emulating using NAM and monitor on the traffic flow based on the XY routing strategy.
As we saw in this simulation, we will support you from the scratch to their extension regarding XY routing protocol’s implementation using ns2 simulation tool. We will give further information on how the XY routing protocol is executed in alternate simulations.
You van get innovative project ideas at ns2project.com. We specialize in providing unique research topics tailored to your needs. Our team is ready to assist you with implementing XY Routing in NS2. If you require further support, please feel free to contact us; we are dedicated to helping you achieve outstanding results in your project.