As previous section, this one is dedicated to an aspect related to Tcl implementation and not to MIRACLE. In these paragraph we'll explain how to insert some simulation parameters. You can do it by inserting them directly on the command line or pass them by a script.
The first difficulty we encounter is the format of the values given as input. They must be integers and sometimes this makes things a little more complicated. The solution is referring to an array of non integer values, so inputs will be the array indexes.
The structure of Tcl command is as follows:
set simNum_ [lindex $argv 5]
With this line the variable simNum_
is set equal to the fifth parameter inserted from the command line (or executed by a script). Remember that numeration of parameters starts from 0, but the first parameter is always ns
, the command you use to start each simulation.
To avoid errors, we suggest to add always a control on the parameters inserted, as follows:
if {$argc != 6 } { puts "usage: $argv0 Nuser rate burstSize speed iter SimulationNumber" exit 1 }
Sometimes it happens to insert less parameters than required caused, for example, by a space not welltyped (like this!).
The creation of an array is very simple. In the following lines we create an array composed by three elements which represent speed values in meters per second. Then, as seen before, we associate the third value inserted to a variable named s
. We'll use this one as the array index.
set speed(1) 0.55555555 set speed(2) 4.16666666 set speed(3) 0.0 set s [lindex $argv 3] $position(3) speedMean $speed(s)
In the last line we finally can set the mean speed of the node 3 by recalling the right value in our array. If you read the section about mobility and you have had a look at the code, you will easily recognize in this line the setting regarding a Gauss-Markov mobility model.