How to Simulate Adaptive Routing Projects Using NS2

To simulate Adaptive Routing projects using NS2, we will require to execute routing, which modifies dynamically according to the changing network conditions, like traffic load, congestion, or link failures. In network simulator NS2, adaptive routing mechanisms can be replicated by changing the behaviour of the routing protocols or by making custom logic, which actively updates the routing decisions.

Steps to Simulate Adaptive Routing in NS2

  1. Set Up NS2 Environment

Make sure that NS2 is correctly installed. We can verify by running the below command:

ns

If it’s installed then we should monitor the NS2 prompt.

  1. Understanding Adaptive Routing

Adaptive routing protocols fine-tune their routes in response to modifies within network topology, traffic patterns, or link conditions. Instances of adaptive routing protocols contain:

  • Ad hoc On-Demand Distance Vector (AODV) routing
  • Dynamic Source Routing (DSR)
  • Optimized Link State Routing (OLSR)

In these protocols, routes are updated rely on real-time information like link quality or congestion levels.

  1. Configure the Adaptive Routing Protocol

NS2 offers built-in support for numerous adaptive routing protocols like AODV, DSR, and others. We can set up one of these protocols or modify them to contain the adaptive behaviours.

  1. Writing a TCL Script

Below is an instance of how to configure an adaptive routing simulation utilizing AODV in NS2.

# Create a simulator object

set ns [new Simulator]

# Open trace and NAM output files

set tracefile [open out.tr w]

set namfile [open out.nam w]

$ns trace-all $tracefile

$ns namtrace-all $namfile

# Define topology setup

set topo [new Topography]

$topo load_flatgrid 500 500

# Set up nodes

set n0 [$ns node]

set n1 [$ns node]

set n2 [$ns node]

set n3 [$ns node]

set n4 [$ns node]

# Create links between nodes (with adaptive nature by AODV protocol)

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

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

$ns duplex-link $n2 $n3 512Kb 50ms DropTail

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

# Set the routing protocol to be adaptive AODV

$ns rtproto AODV

# Create a UDP agent and attach it to n0

set udp0 [new Agent/UDP]

$ns attach-agent $n0 $udp0

# Create a Null agent and attach it to n4

set null0 [new Agent/Null]

$ns attach-agent $n4 $null0

# Connect agents (n0 -> n4)

$ns connect $udp0 $null0

# Generate CBR traffic

set cbr [new Application/Traffic/CBR]

$cbr set packetSize_ 512

$cbr set interval_ 0.005

$cbr attach-agent $udp0

# Schedule events

$ns at 0.5 “$cbr start”

$ns at 5.0 “$cbr stop”

$ns at 6.0 “finish”

# Define the finish procedure

proc finish {} {

global ns tracefile namfile

$ns flush-trace

close $tracefile

close $namfile

exec nam out.nam &

exit 0

}

# Run the simulation

$ns run

  1. Explanation of the Script
  • Routing Protocol: The $ns rtproto AODV command sets AODV as the routing protocol. AODV is an adaptive protocol, which discovers routes dynamically as required.
  • Topology: The script describes a basic topology with five nodes are associated by duplex links with diverse bandwidth and delay parameters.
  • Traffic: A UDP agent is utilized to transmit constant bit rate (CBR) traffic from node n0 to node n4. Adaptive routing will be selected the finest path depends on the recent network conditions.
  • Adaptive Behavior: If a link fails or acquires congested then AODV will modify routes consequently that illustrating the adaptive routing.
  1. Simulation Process
  1. Running the Simulation: We can execute the TCL script using the following command:

ns your_script.tcl

  1. Analyzing the Output:
    • Trace File (out.tr): Includes detailed data regarding packet transmissions, routing decisions, and link failures.
    • NAM Visualization (out.nam): Open the NAM file to visually check how routes adjust over time. To open NAM, run:

nam out.nam

  1. Modify for Advanced Adaptive Behaviour

To create the routing more adaptive according to the additional factors (e.g., link failure, congestion, or energy levels), we can change the simulation or even insert custom adaptive routing logic within C++ code:

  • Link Failure Simulation: We can manually replicate link failures in the course of the simulation by shutting down a link utilizing $ns rtmodel commands.

$ns rtmodel-at 3.0 down $n1 $n2

This command replicates a link failure among the nodes n1 and n2 at 3.0 seconds, which forcing the routing protocol to discover an alternative path.

  • Congestion Awareness: We can replicate congestion by modifying link capacities and utilizing custom traffic patterns to monitor how adaptive protocols such as AODV respond to congestion.
  • Custom Adaptive Protocols: If existing adaptive protocols do not meet the requirements then we can change or prolong the NS2’s C++ source code to make a new adaptive routing protocol.
  1. Collect and Analyse Results

To examine the performance of the adaptive routing, we can extract several parameters from the trace file, like:

  • Packet Delivery Ratio (PDR): Compute the ratio of packets effectively delivered.
  • End-to-End Delay: Measure the average delay from source to destination.
  • Routing Overhead: Calculate the amount of control messages are generated by the adaptive routing protocol.

Example to count received packets:

grep “r” out.tr | wc -l

  1. Performance Metrics

Compare the performance of adaptive routing protocols under diverse situations:

  • Scalability: Experiment how successfully the protocol executes as the number of nodes maximizes.
  • Network Load: Differ traffic intensity and learn how the adaptive protocol reacts.
  • Mobility: If mimicking mobile nodes then we monitor how the routing adapts to modifying topologies.

In this simulation, we expounded the simulation process and their performances for Adaptive Routing projects that are simulated by utilizing NS2 simulation platform. Also we outline the more advanced information on how will Adaptive Routing perform in other tools in another manual.

To simulate Adaptive Routing projects using NS2 tool we will give you good guidance, so send us all your project details we will help you out with good results.

Opening Time

9:00am

Lunch Time

12:30pm

Break Time

4:00pm

Closing Time

6:30pm

  • award1
  • award2