How to Start XY Routing Projects Using NS2
To start XY Routing using NS2 tool which is a simple and effective routing approach that normally utilised for grid-based networks like mesh networks or in network-on-chip (NoC). Packets are initially transmitted in the X direction (horizontally) and then routed in the Y direction (vertically) within XY Routing. This kind of routing is utilised for reducing path complexity within networks in which the topology is typical such as in grids, and for data transmission, there are predefined horizontal and vertical paths.
We need to execute the XY Routing by means of creating a network including grid topology in which every single node understands their location, and based on the XY path rule (first X direction, then Y direction), packets are routed in NS2. We follow these steps.
Steps to Start an XY Routing Project in NS2
- Install NS2
Make certain that we have NS2 installed on the system. Unless, we can install it through following steps:
- For Ubuntu (Linux-based):
sudo apt update
sudo apt install ns2
sudo apt install nam
- For Windows: We could utilise the Cygwin or a VM by executing Linux operating in NS2.
To confirm that NS2 is installed, we execute:
ns
- Understand XY Routing
Packets are transmitted via grid-based network within two stages in XY Routing:
- First phase (X-axis): Packets are initially transmitted in horizontal (X direction) to the destination column.
- Second phase (Y-axis): When we attain exact column then packets are transmitted vertically (Y direction) toward destination row.
This approach successfully functions within grid-like topologies in which each node understands their location and position of destination.
- Create the Network Topology
Network topology would be a grid for an XY Routing project. The volume of nodes will need to find the grid size (for instance, a 3×3 grid which is 9 nodes).
- Nodes: Every single node contains a location like X, Y coordinates.
- Links: The links associate the nodes within a regular grid fashion.
- Create the TCL Script for XY Routing
Replicate the XY Routing to utilise TCL script in NS2. We will want to create grid network topology and the routing approach.
Below is an instance of how to configure a XY Routing simulation using NS2:
Example TCL Script for XY Routing
# Create a simulator object
set ns [new Simulator]
# Define the size of the grid (number of rows and columns)
set rows 3
set cols 3
# Create nodes in a grid layout
for {set i 0} {$i < $rows} {incr i} {
for {set j 0} {$j < $cols} {incr j} {
set node_($i,$j) [$ns node]
}
}
# Create links between nodes (grid-based topology)
# The grid is fully connected in a 2D fashion
for {set i 0} {$i < $rows} {incr i} {
for {set j 0} {$j < $cols} {incr j} {
if {$j < $cols-1} {
$ns duplex-link $node_($i,$j) $node_($i,[expr $j+1]) 10Mb 10ms DropTail
}
if {$i < $rows-1} {
$ns duplex-link $node_($i,$j) $node_([expr $i+1],$j) 10Mb 10ms DropTail
}
}
}
# Define traffic flow (CBR) between source and destination
set udp1 [new Agent/UDP]
set sink1 [new Agent/Null]
$sink1 attach-agent $node_(2,2) ;# Destination node (bottom-right)
$udp1 attach-agent $node_(0,0) ;# Source node (top-left)
set cbr1 [new Application/Traffic/CBR]
$cbr1 set packetSize_ 512
$cbr1 set interval_ 0.1 ;# Set rate for CBR traffic
$cbr1 attach-agent $udp1
$ns connect $udp1 $sink1
# Set traffic start and stop times
$ns at 1.0 “$cbr1 start”
$ns at 5.0 “$cbr1 stop”
# Define XY routing logic (manually routing in two phases: X then Y)
# Example: From node (0,0) to node (2,2), route through X axis then Y axis.
proc routeXY {src dst} {
# Get the X and Y coordinates of source and destination
set src_x [lindex $src 0]
set src_y [lindex $src 1]
set dst_x [lindex $dst 0]
set dst_y [lindex $dst 1]
# First, route along the X direction (left to right or right to left)
if {$src_x < $dst_x} {
# Move right in X direction
return [list [expr $src_x+1] $src_y]
} elseif {$src_x > $dst_x} {
# Move left in X direction
return [list [expr $src_x-1] $src_y]
} else {
# Once we reach the destination X, route along the Y direction
if {$src_y < $dst_y} {
# Move down in Y direction
return [list $src_x [expr $src_y+1]]
} elseif {$src_y > $dst_y} {
# Move up in Y direction
return [list $src_x [expr $src_y-1]]
} else {
# Destination reached
return $dst
}
}
}
# Trace file and animation output
$ns trace-all “xy_routing_output.tr”
$ns namtrace-all “xy_routing_output.nam”
# Run the simulation
$ns run
- Explanation of the TCL Script
- Network Topology:
- It has 3×3 grid is created with 9 nodes. These nodes are generated to utilise the $ns node command in a loop.
- Links are associated among the neighbouring nodes both horizontally and vertically to utilise $ns duplex-link. Every single link contains bandwidth of 10Mb and a delay of 10ms.
- Traffic Flow:
- CBR traffic is created from the top-left corner (node (0,0)) to the bottom-right corner (node (2,2)).
- The traffic begins at 1.0s and ends at 5.0s of simulation time.
- XY Routing Logic:
- The XY routing logic is executed by using routeXY technique.
- In this case:
- Initially, the packet is transmitted within the X direction (horizontally) toward the column of destination.
- When the packet attains the destination’s column then it is transmitted in the Y direction (vertically) toward the destination’s row.
- The routeXY function give back the next hop depends on the present location and the position of destination.
- Trace and NAM:
- The simulation result is found with the support of $ns trace-all, and visual outcome is created to utilise $ns namtrace-all for envisioning the packet flow and routing within NAM.
- Run and Analyze the Results
When we execute the simulation then we can examine the outcomes to utilise NAM and trace files.
- NAM Visualization:
- Envision the packet flow to utilise NAM within the grid network:
nam xy_routing_output.nam
-
- We will need to observe the packets movement from the source (0,0) to the destination (2,2) to utilise the XY routing logic.
- Trace File Analysis:
- The trace file as xy_routing_output.tr has in-depth packet flow data.
- We can be utilised awk or same tools to analyse and examine the trace data:
awk ‘{print $1, $2, $3, $4}’ xy_routing_output.tr
- Extend the XY Routing Project
We need to prolong this project within numerous ways:
- Larger Grid:
- Maximize the grid size such as a 5×5 or 10×10 grid for replicating larger networks.
- Multiple Traffic Flows:
- Integrate several traffic flows among various source-destination pairs for monitoring the behavior of network including numerous data streams.
- Obstacles or Link Failures:
- Mimic network link failures or obstacles by means of inactivating certain links in the course of simulation and also we monitor how XY Routing manages some scenarios.
- Performance Metrics:
- Within the XY routing network, we need to estimate the end-to-end delay, throughput, and packet loss and equate them including other routing protocols such as Dijkstra’s or AODV.
- Different Packet Types:
- Measure the XY Routing performance under diverse network scenarios to utilise various kinds of traffic like FTP or TCP.
Above fundamental approach was demonstrated with sample coding for XY Routing Projects, was simulated and examined using NS2 environment, with more relevant details to follow.