Research breakthrough possible @S-Logix

Office Address

  • 2nd Floor, #7a, High School Road, Secretariat Colony Ambattur, Chennai-600053 (Landmark: SRM School) Tamil Nadu, India
  • +91- 81240 01111

Social List

How to generate random waypoint model in NS2?


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.

Sample Code

./setdest [-n num_of_nodes] [-p pausetime] [-s maxspeed] [-t simtime] \ [-x maxx] [-y maxy] > [outdir/movement-file]

#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"