How to create a random waypoint model using NS2

Description

The most applied mobility model in wireless networks especially in Mobile Ad Hoc Network is Random WayPoint (RWP) model as it creates more realistic mobility model in which each node moves to the random point within the specific network area and remains in the position for certain period known as pause time and moves to random next random point and so on. The code given below provides methods to generate this mobility model.

Method1:
indep-utils/cmu-scen-gen/setdest.
./setdest [-n num_of_nodes] [-p pausetime] [-s maxspeed] [-t simtime] \ [-x maxx] [-y maxy] > [outdir/movement-file]

Method2:
#Fixing the co-ordinate of simutaion area
set val(x) 500
set val(y) 500
for {set i 0} {$i < 3} {incr i} {
$node_($i) set X_ [expr rand()*$val(x)]
$node_($i) set Y_ [expr rand()*$val(y)]
$node_($i) set Z_ 0
}
#******************Defining Mobility ************************#
# For mobility 300= movement x value, 100=movement y value, 50=speed in m/s
$ns at 2.0 "$node_(2) setdest 300 100 50"
#*****************Defining Random Mobility *******************#
#Random mobility for all the nodes
for { set i 1} {$i < 3} {incr i} {
set xr [expr rand()*$val(x)]
set yr [expr rand()*$val(y)]
$ns at 2.0 "$node_($i) setdest $xr $yr 50"
}