[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [ns] running scripts
On Wed, 1 Aug 2001, Sunil Gowda wrote:
> THis is related to tcl more than ns itself. Can anyone please help with
> running simulation batches.
> I need to run a set of simulations varying one of the parameters. What
> kind of script do i write? Or should i write seperate tcl files for each
> value.
Sunil,
I use a perl script (run.pl) to drive the simulation, a Tcl script
(sim-template.tcl) as a template for each simulation, and a shell script
(changeword) to convert the template to a suitable NS Tcl script. Then, I
just have a shell script that runs run.pl with the suitable parameters.
They're all short, so I've just appended them below my signature. If
someone else has an easier suggestion, I'd love to hear it, too.
Michele
--
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Michele C. Weigle
michele_weigle@unc.edu, clark@cs.unc.edu
http://www.cs.unc.edu/~clark
CB# 3175, Sitterson Hall
Department of Computer Science
University of North Carolina
Chapel Hill, NC 27599-3175
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
changeword:
#!/bin/csh -f
# changeword
if ($#argv < 3 ) then
echo usage: $0 oldword newword files ...
exit
endif
set word1=$1
set word2=$2
shift
shift
while ($#argv != 0)
sed "s@$word1@$word2@g" < $1 > tmp.$$
mv tmp.$$ $1
shift
end
sim-template.tcl:
# sim.tcl
# instantiate the Simulator
set ns [new Simulator]
# setup the variables
set exp EXP; # experiment number
set length LEN; # length of traced simulation (s)
set warmup $length; # warmup interval (s)
set duration [expr $warmup + $length]; # total simulation time (s)
# <setup topology here>
# <tracing routine here>
# control the simulation
$ns at 0.0 "start"
$ns at $warmup "trace"
$ns at [expr $duration + 1] "finish"
$ns run
run.pl:
#!/usr/local/bin/perl
# run.pl Michele Weigle March 19, 2001
#
# Usage: run.pl exp length
# exp = experiment number
# length = time of data collection, total duration will be
# 2*time because of the warm-up interval
#
# Example: run.pl 01 300
#
$EXPDIR = "/playpen1/clark/nsexps/";
$exp = @ARGV[0];
$length = @ARGV[1];
$warmup = $length;
$total = $length + $warmup;
$minutes = $total / 60;
# create sim.tcl from sim-template.tcl
`cp $EXPDIR/sim-template.tcl $EXPDIR/sim.tcl`;
`changeword EXP $exp $EXPDIR/sim.tcl`;
`changeword LEN $length $EXPDIR/sim.tcl`;
printf ("Starting run %d for %d minutes (%d s)...\n",
$exp, $minutes, $total);
`ns $EXPDIR/sim.tcl >$exp-${length}s.out 2>$exp-${length}s.err`;
print "DONE\n";