How to Implement Adaptive Routing in NS2

To implement the adaptive routing in ns2 which is a routing mechanism where network routes change dynamically depends on the real-time network conditions like traffic load, blockages, link failures, or other factors. NS2 (Network Simulator 2) does not directly establish a certain “adaptive routing” protocol, however you can replicate adaptive routing by altering routing activities dynamically during the simulation. Stay in touch with us we are ready to give you best implementation guidance.

We have to deploy the network topology and modify the routing tables dynamically according to the network conditions like delays, bandwidth, packet loss or jamming for the implementation of adaptive routing in ns2.

Follow the given procedure to implement this routing in ns2:

Steps to Implement Adaptive Routing in NS2

  1. Set Up NS2 Environment
    • Make sure that NS2 is installed and properly configured on your system.
  2. Understand Adaptive Routing
    • Adaptive routing fine-tunes the routing paths dynamically in reaction to differences in network conditions. It could involve link failures, overcrowding, or changes in available bandwidth.
    • In NS2, you can replicate adaptive routing by occasionally altering the routing tables or using available routing protocols like Link-State (LS) or Distance Vector (DV) and dynamically varying the routes based on monitored network conditions.

Example Adaptive Routing Simulation in NS2

We will replicate a network that dynamically alters routes based on link failures or congestion. This script will explain the concept of adaptive routing by dynamically modifying the routes during the simulation.

  1. Define the Network Topology and Initial Routes

# Define the simulation environment

set ns [new Simulator]

# Open the trace file for recording data

set tracefile [open out.tr w]

$ns trace-all $tracefile

# Define the finish procedure

proc finish {} {

global ns tracefile

$ns flush-trace

close $tracefile

exec nam out.nam &

exit 0

}

# Create network nodes

set node1 [$ns node]

set node2 [$ns node]

set node3 [$ns node]

set node4 [$ns node]

set node5 [$ns node]

# Create links between nodes with different delays

$ns duplex-link $node1 $node2 10Mb 10ms DropTail

$ns duplex-link $node2 $node3 10Mb 10ms DropTail

$ns duplex-link $node3 $node4 10Mb 10ms DropTail

$ns duplex-link $node4 $node5 10Mb 10ms DropTail

$ns duplex-link $node1 $node5 5Mb 50ms DropTail

$ns duplex-link $node2 $node4 5Mb 30ms DropTail

# Enable shortest path routing (Link-State)

$ns rtproto LS

# Attach TCP agents for traffic

set tcp1 [new Agent/TCP]

$ns attach-agent $node1 $tcp1

set sink1 [new Agent/TCPSink]

$ns attach-agent $node5 $sink1

# Connect TCP agent and sink

$ns connect $tcp1 $sink1

# Create an FTP application over TCP and start it

set ftp1 [new Application/FTP]

$ftp1 attach-agent $tcp1

$ns at 1.0 “$ftp1 start”

  1. Simulate Adaptive Routing (Dynamic Route Changes)

You can simulate adaptive routing by activating dynamic events in the network including link failures or congestion, and updating the routing tables correspondingly.

Dynamic Link Failure:

Simulate adaptive routing by generating a scenario where one of the links fails, forcing the network to redirect traffic using a numerous path.

# Simulate link failure between node2 and node3 at time 3.0

$ns rtmodel-at 3.0 down $node2 $node3

# Restore the link between node2 and node3 at time 7.0 (adaptive recovery)

$ns rtmodel-at 7.0 up $node2 $node3

Adaptive Routing Based on Congestion:

For a more dynamic approach, you can also alter routing based on simulated network congestion. This can be done by occasionally fine-tuning the routing table when particular network conditions are identified.

# At time 4.0, simulate high congestion on the direct link between node1 and node5

# Force the traffic to reroute through an alternative path

$ns at 4.0 “$node1 add-route $node5 2”

# After some time, restore the normal routing once the congestion subsides

$ns at 6.0 “$node1 add-route $node5 1”

  1. Run the Simulation

# Stop the simulation at 10.0 seconds

$ns at 10.0 “finish”

# Run the simulation

$ns run

Explanation of the Script

  1. Network Topology: The script states a network with five nodes. Links amongst nodes have various bandwidths and delays, allowing for dynamic routing alterations during the simulation.
  2. Traffic Generation: TCP traffic is generated amongst node1 (source) and node5 (destination), using an FTP application to replicate data transfer.
  3. Link Failure and Recovery: At time 3.0 seconds, the link amongst node2 and node3 goes down, simulating a link failure. At time 7.0, the link is restored, and the routing adapts consequently.
  4. Adaptive Routing Based on Congestion: At time 4.0 seconds, jamming is replicated on the direct link amidst node1 and node5, and traffic is forced to reroute through substitute path. At time 6.0 seconds, normal routing is restored.
  5. Routing Protocol: We use the built-in link-state routing (LS) for dynamic route computation, but you can adapt this for other protocols or custom routing mechanisms as demanded.

Running the Simulation

  1. Store the script to a file (e.g., adaptive_routing.tcl).
  2. Execute the script using NS2:

ns adaptive_routing.tcl

  1. The simulation will produce a trace file (out.tr) and a Network Animator (NAM) file (out.nam). Monitor how packets are routed and how the routing varies during link failures and overcrowding events to visualize the simulation using NAM.

Analyze the Results

  • Trace File: Assess the trace file (out.tr) to authenticate that packets are redirected when the link failure happens and when blockage is simulated. You should monitor changes in the packet paths.
  • NAM Visualization: Use NAM to visualize the network topology and see how traffic is rerouted when the link among node2 and node3 goes down and how it returns to normal once the link is restored.

Enhancements

  1. More Dynamic Conditions: Recreate real-time congestion by launching delays, packet drops, or changes in available bandwidth to monitor how the routing dynamically adapts.
  2. More Traffic Flows: Include additional traffic flows amongst various nodes and replicate adaptive routing through several traffic sources.
  3. Advanced Adaptive Algorithms: Execute more advanced adaptive routing algorithms like traffic-aware routing or load balancing, to dynamically allocate traffic based on network load.
  4. Mobility: Present node mobility (like using the setdest command) to mimic adaptive routing in mobile ad hoc networks (MANETs) and see how the routing adapts to modifications in the network topology.

This procedure offered the step-by-step guide to help you implement adaptive routing in ns2 environment and provides from the basic set up to analyzing the results like configuration of network topology and initializing routes. We will provide any details regarding this manual, if needed.