How to Implement Tutorials Point Routing in NS2

To implement the tutorials point routing in ns2 has numerous steps. First we need to clearly know the concept of tutorial point routing. It does not directly relevant to the routing protocol. If you want to implement these routing you can follow the related techniques has mentioned in the tutorials for executing the standard routing protocols in NS2, like DSDV, AODV, or DSR. For more ideas you can reach us out.

Here, is the basic implementation using the Ad-hoc On-demand Distance Vector (AODV) protocol, as AODV is one of the common routing protocols covered in tutorials:

Implementing AODV in NS2

Steps to Implement AODV Routing in NS2:

  1. Install NS2: Ensure NS2 is installed on the computer.
  1. TCL Script for AODV Routing

The given below is the sample of TCL script for simulating AODV routing in NS2:

# Create the simulator object

set ns [new Simulator]

# Create a trace file for recording the simulation

set tracefile [open aodv_trace.tr w]

$ns trace-all $tracefile

# Create a file for Network Animator (NAM)

set namfile [open aodv_simulation.nam w]

$ns namtrace-all $namfile

# Define the ‘finish’ procedure

proc finish {} {

global ns tracefile namfile

$ns flush-trace

close $tracefile

close $namfile

exec nam aodv_simulation.nam &

exit 0

}

# Create nodes

set n0 [$ns node]

set n1 [$ns node]

set n2 [$ns node]

set n3 [$ns node]

set n4 [$ns node]

# Define the links between the nodes with bandwidth and delay

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

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

$ns duplex-link $n2 $n3 2Mb 10ms DropTail

$ns duplex-link $n3 $n4 2Mb 10ms DropTail

# Setup AODV as the routing protocol

set opt(adhocRouting) AODV

set val(rp) AODV

# Setup traffic agents (e.g., UDP)

set udp0 [new Agent/UDP]

$ns attach-agent $n0 $udp0

set null0 [new Agent/Null]

$ns attach-agent $n4 $null0

# Connect the agents

$ns connect $udp0 $null0

# Create CBR (Constant Bit Rate) traffic

set cbr0 [new Application/Traffic/CBR]

$cbr0 set packetSize_ 512

$cbr0 set interval_ 0.1

$cbr0 attach-agent $udp0

# Define the simulation events

$ns at 1.0 “$cbr0 start”

$ns at 5.0 “$cbr0 stop”

# Schedule the end of the simulation

$ns at 10.0 “finish”

# Start the simulation

$ns run

  1. Running the Simulation
  1. Save the above TCL script as aodv_example.tcl.
  2. Execute it using the command:

ns aodv_example.tcl

This command will make two output files:

  • aodv_trace.tr: A trace file with detailed simulation data.
  • aodv_simulation.nam: A file that can be visualized using NAM (Network Animator).

To visualize the simulation in NAM, use:

nam aodv_simulation.nam

  1. Explanation of the Script:
  • Nodes and Links: The script describes five nodes associated with duplex links having a bandwidth of 2Mbps and a delay of 10ms.
  • Routing Protocol: AODV is specified as the routing protocol using the command set opt(adhocRouting) AODV.
  • Traffic Setup: UDP and CBR agents are used to create traffic among the source (n0) and the destination (n4).
  • Simulation End: The simulation executes for 10 seconds, after that it automatically finishes.
  1. Adding Mobility (Optional)

For mobile ad hoc networks, we can add node mobility to see how AODV manages the dynamic topology changes:

$ns at 2.0 “$n1 setdest 400 300 10.0”

$ns at 5.0 “$n2 setdest 600 400 15.0”

  1. Trace File Analysis

We can evaluate the trace file (aodv_trace.tr) for parameters such as:

  • Packet Delivery Ratio
  • Average End-to-End Delay
  • Throughput

This can be completed using awk scripts or any custom parser to extract and evaluate relevant information.

In this manual, we understood what is tutorial point routing and we acquire tutorial routing protocol such as AODV, DSR, OSPF, or any other and also we gain knowledge on how to deploy the simulation process in the network. If you want to learn more about the tutorial routing point then we will support and provide it.