The mobilenode is designed to move in a three dimensional topology. However the third dimension (Z) is not used. That is the mobilenode is assumed to move always on a flat terrain with Z always equal to 0. Thus the mobilenode has X, Y, Z(=0) co-ordinates that is continually adjusted as the node moves. There are two mechanisms to induce movement in mobilenodes. In the first method, starting position of the node and its future destinations may be set explicitly. These directives are normally included in a separate movement scenario file.
The start-position and future destinations for a mobilenode may be set by using the following APIs:
$node set X_ \<x1\> $node set Y_ \<y1\> $node set Z_ \<z1\> $ns at $time $node setdest \<x2\> \<y2\> \<speed\>At $time sec, the node would start moving from its initial position of (x1,y1) towards a destination (x2,y2) at the defined speed.
In this method the node-movement-updates are triggered whenever the position of the node at a given time is required to be known. This may be triggered by a query from a neighbouring node seeking to know the distance between them, or the setdest directive described above that changes the direction and speed of the node.
An example of a movement scenario file using the above APIs, can be found in ~ns/tcl/mobility/scene/scen-670x670-50-600-20-0. Here 670x670 defines the length and width of the topology with 50 nodes moving at a maximum speed of 20m/s with average pause time of 600s. These node movement files may be generated using CMU's scenario generator to be found under ~ns/indep-utils/cmu-scen-gen/setdest. See subsection 16.1.8 for details on generation of node movement scenarios.
The second method employs random movement of the node. The primitive to be used is:
$mobilenode startwhich starts the mobilenode with a random position and have routined updates to change the direction and speed of the node. The destination and speed values are generated in a random fashion. We have not used the second method and leave it to the user to explore the details. The mobilenode movement is implemented in C++. See methods in ~ns/mobilenode.{cc.h} for the implementational details.
Irrespective of the methods used to generate node movement, the topography for mobilenodes needs to be defined. It should be defined before creating mobilenodes. Normally flat topology is created by specifying the length and width of the topography using the following primitive:
set topo [new Topography] $topo load_flatgrid $opt(x) $opt(y)where opt(x) and opt(y) are the boundaries used in simulation.
The movement of mobilenodes may be logged by using a procedure like the following:
proc log-movement {} { global logtimer ns_ ns set ns $ns_ source ../mobility/timer.tcl Class LogTimer -superclass Timer LogTimer instproc timeout {} { global opt node_; for {set i 0} {$i \< $opt(nn)} {incr i} { $node_($i) log-movement } $self sched 0.1 } set logtimer [new LogTimer] $logtimer sched 0.1 }In this case, mobilenode positions would be logged every 0.1 sec.
Tom Henderson 2011-11-05