Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #
- # Test script to run multiple set of independent ns-2 simulations.
- # Copyright (C) 2007 Claudio Cicconetti <c.cicconetti@iet.unipi.it>
- # Dipartimento di Ingegneria dell'Informazione
- # University of Pisa - Italy
- #
- # This program is free software: you can redistribute it and/or modify
- # it under the terms of the GNU General Public License as published by
- # the Free Software Foundation, either version 3 of the License, or
- # (at your option) any later version.
- #
- # This program is distributed in the hope that it will be useful,
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- # GNU General Public License for more details <http://www.gnu.org/licenses/>.
- #
- # set aths
- analyze=analyze
- check=check
- ns=ns
- # scenario configuration
- name="test" # scenario identifier
- scenario="$name.tcl" # name of the Tcl script to run simulations
- flock=$name.lck # lockfile
- outdir="output" # output directory
- savedir="savefile" # savefile directory
- tmp=config.tmp # temporary check/analyze configuration
- fifo=$name.fifo # temporary FIFO name
- maxruns=100 # maximum number of replics per scenario
- confidence=0.95 # output confidence level
- confthresh=0.05 # threshold to stop running further replics
- # varying parameter(s)
- cbr_rate="50000 100000 150000 200000 250000 300000 350000 400000 450000"
- # metrics that have to be output
- avg="e2e_owd_a e2e_owpl"
- dst="e2e_owd_d e2e_ipdv_d"
- # metrics that are used to stop simulations
- avgcheck="e2e_tpt"
- # identifiers that are output/checked
- measure_id="0 1 2"
- #
- # perform some sanity check
- #
- check() {
- if [ ! -e $fifo ] ; then
- mkfifo $fifo
- fi
- if [ ! -p $fifo ] ; then
- echo "File '$fifo' must be a FIFO"
- exit -1
- fi
- if [ ! -e $outdir ] ; then
- mkdir $outdir
- fi
- if [ ! -d $outdir ] ; then
- echo "File '$outdir' must be a directory"
- exit -1
- fi
- if [ ! -e $savedir ] ; then
- mkdir $savedir
- fi
- if [ ! -d $savedir ] ; then
- echo "File '$savedir' must be a directory"
- exit -1
- fi
- if [ -e $flock ] ; then
- echo "Lock file '$flock' present"
- exit -1
- fi
- }
- #
- # terminate gracefully and remove temporary files
- #
- terminate() {
- /bin/rm $tmp > /dev/null 2> /dev/null
- /bin/rm $flock > /dev/null 2> /dev/null
- /bin/rm $fifo > /dev/null 2> /dev/null
- exit 0
- }
- ################################################################################
- # MAIN BODY
- ################################################################################
- for cr in $cbr_rate ; do
- mangle="$name-$cr"
- echo "save $savedir/$mangle" > $tmp
- echo "header $outdir/$mangle-" >> $tmp
- for j in $measure_id ; do
- for meas in $avg ; do
- echo "s $meas $j out $confidence" >> $tmp
- done
- for meas in $avgcheck ; do
- echo "s $meas $j out $confidence check $confidence $confthresh" >> $tmp
- done
- for meas in $dst ; do
- echo "d $meas $j median out $confidence" >> $tmp
- echo "d $meas $j mean out $confidence" >> $tmp
- echo "d $meas $j cdf out $confidence" >> $tmp
- echo "d $meas $j pmf out $confidence" >> $tmp
- echo "d $meas $j q95 out $confidence" >> $tmp
- echo "d $meas $j q99 out $confidence" >> $tmp
- done
- done
- #
- # run simulations (or collect measures)
- #
- cmd="$ns $scenario -rate $cr"
- if [ $# -le 0 ] ; then
- echo "Usage: $0 <run|test|stat|conf>"
- echo "Where:"
- echo " run run simulations until the confidence level is"
- echo " reached or the number of replics is beyond maximum"
- echo " test print the simulation commands that will be run"
- echo " stat collect measures from the savefiles"
- echo " conf test if the confidence level is reached in savefiles"
- echo ""
- echo "If $0 is run without arguments, it cleans up any stale lockfile"
- terminate
- elif [ $1 == "run" ] ; then
- check
- touch $flock
- echo -n "$mangle "
- timestart=`date +%s`
- for (( i = 1 ; i <= $maxruns ; i++ )) ; do
- cat $fifo >> $savedir/$mangle &
- $cmd -run $i -out $fifo 2> /dev/null 1> /dev/null
- status=`$check $tmp`
- if [ $status == 'ok' ] ; then
- break
- elif [ $status == 'no' ] ; then
- echo -n "."
- elif [ $status == 'err' ] ; then
- echo "An error occurred while executing '$mangle'"
- terminate
- fi
- done
- timeend=`date +%s`
- duration=$(( timeend - timestart ))
- echo " done ($duration s)"
- /bin/rm $flock > /dev/null
- elif [ $1 == "test" ] ; then
- echo $cmd
- elif [ $1 == "conf" ] ; then
- echo -n "checking $mangle..."
- $check $tmp
- elif [ $1 == "stat" ] ; then
- $analyze $tmp
- else
- echo "unknown command '$1'"
- terminate
- fi
- done
- terminate
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement