Apr 3, 2012

How to program nodes movement using FOR loop in NS2

In fact, we know how to set the nodes` movement in NS2, it could be < $ns at TIME "$NODE1 setdest $val(X1) $val(Y1) SPEED" >. However, for some scenario, it may contain a large number of nodes` movement and simulation time could be one or several hours. It is impossible to program in this static way.

So we consider using a FOR loop. Here is an example where a node is moving up and down. The simulation time can be any value and we just need five lines program. The program is like the following,

for {set i 1} {$i < ($val(stop))} {set i [expr {$i + 10}]} {

$ns at $i "$node_(1) setdest $val(X1) $val(Y1) NodeSpeed"

set i [expr {$i + 10}]

$ns at $i "$node_(1) setdest $val(X2) $val(Y2) NodeSpeed"



  1. This comment has been removed by the author.

  2. Does this really work?? I could not implement it