How to Implement Non Adaptive Routing in NS2
To implement the Non-Adaptive Routing in NS2 that has want to simulate a fixed routing scheme in which the routes do not alter actively in reaction to the network conditions like link failures or node mobility. This routing is called as static routing in which the routes are pre-determined and it don’t adjust to modify in the network. In the simulation NS2, the default routing protocol for wired networks that static routing in which we can be clearly described the routes with the support of the manual-routing method. We provide simple approach to executing it in NS2.
Steps to Implement Non-Adaptive (Static) Routing in NS2:
- Install and Set Up NS2
Make sure NS2 is installed and set up appropriately then we can download and install it from the authorised NS2 webpage.
- Modify Tcl Script for Non-Adaptive Routing
Now, we will write a Tcl script to manually set up the static routes for every node in the network. The important non-adaptive routing is to clearly described the route among the nodes and avoid the simulation from adjusting to any variance in the network.
Example of a Tcl Script for Non-Adaptive Routing:
# Create a new NS2 simulator instance
set ns [new Simulator]
# Create trace file and NAM visualization file
set tracefile [open “nonadaptive_trace.tr” w]
$ns trace-all $tracefile
set namfile [open “nonadaptive.nam” w]
$ns namtrace-all $namfile
# Define a simple topology with 4 nodes
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
# Create links between nodes with bandwidth and delay parameters
$ns duplex-link $n0 $n1 1Mb 10ms DropTail
$ns duplex-link $n1 $n2 1Mb 10ms DropTail
$ns duplex-link $n2 $n3 1Mb 10ms DropTail
$ns duplex-link $n0 $n3 1Mb 10ms DropTail
# Disable adaptive routing protocols (we will manually define routes)
$ns rtproto Manual
# Set up manual static routing for each node
$ns manual-route $n0 $n3 $n1 $n2
$ns manual-route $n3 $n0 $n2 $n1
# Attach TCP agent to node n0 and TCPSink agent to node n3
set tcp0 [new Agent/TCP]
$ns attach-agent $n0 $tcp0
set sink [new Agent/TCPSink]
$ns attach-agent $n3 $sink
# Establish connection between TCP and Sink agents
$ns connect $tcp0 $sink
# Create a CBR traffic source and attach it to TCP agent
set cbr [new Application/Traffic/CBR]
$cbr attach-agent $tcp0
$cbr set packetSize_ 512
$cbr set interval_ 0.1
# Schedule CBR traffic to start and stop at defined times
$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 nonadaptive.nam &
exit 0
}
# Run the simulation
$ns run
- Key Components of the Non-Adaptive Routing Tcl Script:
- Simulator Object: The Simulator sample (set ns [new Simulator]) is the primary environment in which the network simulation is defined.
- Nodes: In this sample, we make four nodes are n0, n1, n2, n3 to mimic a tiny network.
- Links: Duplex links including the bandwidth and delay are made among the nodes using $ns duplex-link.
- Manual Routing Protocol: We clearly disable any adaptive routing protocol including the $ns rtproto Manual that says NS2 which we are using manual static routing.
- Manual Route Definitions: These routes are clearly defined with the support of the manual-route command. For sample, the command $ns manual-route $n0 $n3 $n1 $n2 stipulates that the packets from the node n0 to node n3 would be routed through the nodes n1 and n2. This routes will not be altered, no matter what occurs in the network.
- Traffic Generation: A TCP agent is attached to the node n0 with a TCPSink agent is added to node n3. A CBR (Constant Bit Rate) traffic source is produces the traffic among the nodes.
- Static Routing Behavior: Because the routes are manually set up and it will remain the similar throughout the simulation, representing non-adaptive/static routing.
- Run the Simulation
When the Tcl script is prepared, run the simulation using NS2:
ns nonadaptive_simulation.tcl
It will produce trace files (nonadaptive_trace.tr) and a NAM file (nonadaptive.nam).
- Analyse the Results
We can evaluate the generated trace file or to visualize the network simulation using NAM:
nam nonadaptive.nam
In this NAM visualizer, we can monitor the packets being routed alongside the manually described the paths, and also we will observe that the routing does not adjust even if the network topology could permit the shorter paths.
- Testing Static Routes
If we require to analyse the performance of static routes, we can alter the network topology and also evaluate how the packets are still routed based on the pre-configured paths. For instance, replicate a link failure among the nodes are n1 and n2, and monitor that the routing table does not adjust to prevent this failure:
# Simulate link failure at 3.0 seconds
$ns at 3.0 “$ns duplex-link-op $n1 $n2 down”
Even the packets will continue to be routed based on the static routes, leading to packet loss or route failure, after the failure.
Conclusion:
- Non-adaptive routing or static routing in NS2 can be executed using the Manual routing protocol.
- By explicitly defining routes using the manual-route command, we make sure that the routes do not alter in the simulation.
- This technique is useful for mimicking networks in which the topology is fixed and it is no require for dynamic route adjustments.
The full process of implementing and enforcing the Non Adaptive Routing in the simulation tool ns2 has been demonstrated above. More insights will be given depending on your requirements. Get tailored assistance on Non Adaptive Routing in NS2 implementation.