Simulation Scripts
In addition to using the Project Editor or Simulation Sequence Editor, you can define simulation sequences via shell scripts or batch files. Both scripts and batch files are run outside of Riverbed Modeler. For the rest of this section, the term “script” will apply to both Linux shell scripts and Windows batch files and scripts. Simulation scripts allow users to execute a series of simulation runs, using different input parameter values for each run. Scripts have two advantages over the GUI, as listed below:
- Scripts don’t have the large memory overhead of Modeler, which frees up more memory for simulations
- Scripts can inject commands between simulations in a sequence; applications of this include preparing simulation input files, rearranging resources needed by the simulation, issuing messages indicating the state of the sequence, and consolidating results.
Two example scripts for simulation sequences are listed below. The scripts are written for the C Shell command interpreter, as are all other Modeler shell examples. They contain the suffix .csh, which identifies them as C shell scripts. The first script example, named frnet_seq.csh, simply runs a sequence of six simulations, each with a distinct combination of two user-defined preferences (parm_A and parm_B). parm_A is a real number preference which takes on the three values 50.0, 100.0, and 150.0; parm_B is a string preference which takes on the two values s_method and t_method (these values do not require quotes on the command-line, since they do not contain spaces). Note that the first line of the script causes it to be interpreted as a C Shell script (using /bin/csh), and lines that start with pound signs (#) are comments.
#!/bin/csh
# frnet_seq.csh: script to run frnet simulations
# S-method simulation runs
op_runsim -net_name frnet -duration 10.0 -parm_A 50.0 -parm_B s_method
op_runsim -net_name frnet -duration 10.0 -parm_A 100.0 -parm_B s_method
op_runsim -net_name frnet -duration 10.0 -parm_A 150.0 -parm_B s_method
# T-method simulation runs
op_runsim -net_name frnet -duration 10.0 -parm_A 50.0 -parm_B t_method
op_runsim -net_name frnet -duration 10.0 -parm_A 100.0 -parm_B t_method
op_runsim -net_name frnet -duration 10.0 -parm_A 150.0 -parm_B t_method
Script execution is performed the same way that any program is executed: the script’s name is typed as a command, as shown below. Under Linux, the permissions of the script file must be set to allow execution in order for execution to proceed; this is done with the chmod command, as illustrated in the example.
% chmod +x frnet_seq.csh
% frnet_seq.csh
...
In Windows, it is sufficient for the script to have the .bat file extension.
The second script example, named seed_seq.csh, runs a sequence of simulations with identical parameters, except for a changing seed value. This type of sequence may be useful when a simulation study incorporates stochastic driving functions (such as traffic generation), but requires a high degree of confidence in the output mean statistic values. The format of the example can be used whenever a simulation input parameter must be varied systematically over a large number of simulations.
#!/bin/csh
# seed_seq.csh: script to run simulations with a varying seed
@ seedval = 0
while ($seedval < 100)
echo ’Executing Simulation with Seed: ’$seedval
op_runsim -net_name example -alpha 10.1 -beta 100 -seed $seedval
@ seedval = ($seedval + 1)
end
Under Linux, simulation scripts can, of course, be even more sophisticated in structure than the second example. C Shell language statements such as if-then-else and switch can be used to tailor very complex sequences. Alternate Linux shells can be used to script simulation sequences. Further information on constructing shell scripts can be found in the Linux documentation for the host workstation.
The commands available under the standard Windows command shell are limited, although other shells and scripting utilities are available.