Advertisement
Guest User

test.sh

a guest
May 13th, 2012
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 4.82 KB | None | 0 0
  1. #!/bin/bash
  2. #
  3. # Test script to run multiple set of independent ns-2 simulations.
  4. # Copyright (C) 2007 Claudio Cicconetti <c.cicconetti@iet.unipi.it>
  5. #                    Dipartimento di Ingegneria dell'Informazione
  6. #                    University of Pisa - Italy
  7. #
  8. # This program is free software: you can redistribute it and/or modify
  9. # it under the terms of the GNU General Public License as published by
  10. # the Free Software Foundation, either version 3 of the License, or
  11. # (at your option) any later version.
  12. #
  13. # This program is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16. # GNU General Public License for more details <http://www.gnu.org/licenses/>.
  17. #
  18.  
  19. # set aths
  20. analyze=analyze
  21. check=check
  22. ns=ns
  23.  
  24. # scenario configuration
  25. name="test"                   # scenario identifier
  26. scenario="$name.tcl"          # name of the Tcl script to run simulations
  27. flock=$name.lck               # lockfile
  28. outdir="output"               # output directory
  29. savedir="savefile"            # savefile directory
  30. tmp=config.tmp                # temporary check/analyze configuration
  31. fifo=$name.fifo               # temporary FIFO name
  32. maxruns=100                   # maximum number of replics per scenario
  33. confidence=0.95               # output confidence level
  34. confthresh=0.05               # threshold to stop running further replics
  35.  
  36. # varying parameter(s)
  37. cbr_rate="50000 100000 150000 200000 250000 300000 350000 400000 450000"
  38.  
  39. # metrics that have to be output
  40. avg="e2e_owd_a e2e_owpl"
  41. dst="e2e_owd_d e2e_ipdv_d"
  42.  
  43. # metrics that are used to stop simulations
  44. avgcheck="e2e_tpt"
  45.  
  46. # identifiers that are output/checked
  47. measure_id="0 1 2"
  48.  
  49. #
  50. # perform some sanity check
  51. #
  52. check() {
  53.     if [ ! -e $fifo ] ; then
  54.         mkfifo $fifo
  55.     fi
  56.  
  57.     if [ ! -p $fifo ] ; then
  58.         echo "File '$fifo' must be a FIFO"
  59.         exit -1
  60.     fi
  61.  
  62.     if [ ! -e $outdir ] ; then
  63.         mkdir $outdir
  64.     fi
  65.  
  66.     if [ ! -d $outdir ] ; then
  67.         echo "File '$outdir' must be a directory"
  68.         exit -1
  69.     fi
  70.  
  71.     if [ ! -e $savedir ] ; then
  72.         mkdir $savedir
  73.     fi
  74.  
  75.     if [ ! -d $savedir ] ; then
  76.         echo "File '$savedir' must be a directory"
  77.         exit -1
  78.     fi
  79.  
  80.     if [ -e $flock ] ; then
  81.         echo "Lock file '$flock' present"
  82.         exit -1
  83.     fi
  84. }
  85.  
  86. #
  87. # terminate gracefully and remove temporary files
  88. #
  89. terminate() {
  90.     /bin/rm $tmp > /dev/null 2> /dev/null
  91.     /bin/rm $flock > /dev/null 2> /dev/null
  92.     /bin/rm $fifo > /dev/null 2> /dev/null
  93.     exit 0
  94. }
  95.  
  96. ################################################################################
  97. # MAIN BODY
  98. ################################################################################
  99.  
  100. for cr in $cbr_rate ; do
  101.  
  102.     mangle="$name-$cr"
  103.  
  104.     echo "save $savedir/$mangle" > $tmp
  105.     echo "header $outdir/$mangle-" >> $tmp
  106.  
  107.     for j in $measure_id ; do
  108.         for meas in $avg ; do
  109.                 echo "s $meas $j out $confidence" >> $tmp
  110.         done
  111.         for meas in $avgcheck ; do
  112.                 echo "s $meas $j out $confidence check $confidence $confthresh" >> $tmp
  113.         done
  114.         for meas in $dst ; do
  115.                 echo "d $meas $j median out $confidence" >> $tmp
  116.                 echo "d $meas $j mean out $confidence" >> $tmp
  117.                 echo "d $meas $j cdf out $confidence" >> $tmp
  118.                 echo "d $meas $j pmf out $confidence" >> $tmp
  119.                 echo "d $meas $j q95 out $confidence" >> $tmp
  120.                 echo "d $meas $j q99 out $confidence" >> $tmp
  121.         done
  122.     done
  123.  
  124.     #
  125.     # run simulations (or collect measures)
  126.     #
  127.  
  128.     cmd="$ns $scenario -rate $cr"
  129.  
  130.     if [ $# -le 0 ] ; then
  131.         echo "Usage: $0 <run|test|stat|conf>"
  132.         echo "Where:"
  133.         echo "   run      run simulations until the confidence level is"
  134.         echo "            reached or the number of replics is beyond maximum"
  135.         echo "   test     print the simulation commands that will be run"
  136.         echo "   stat     collect measures from the savefiles"
  137.         echo "   conf     test if the confidence level is reached in savefiles"
  138.         echo ""
  139.         echo "If $0 is run without arguments, it cleans up any stale lockfile"
  140.         terminate
  141.  
  142.     elif [ $1 == "run" ] ; then
  143.         check
  144.         touch $flock
  145.         echo -n "$mangle "
  146.         timestart=`date +%s`
  147.         for (( i = 1 ; i <= $maxruns ; i++ )) ; do
  148.             cat $fifo >> $savedir/$mangle &
  149.             $cmd -run $i -out $fifo 2> /dev/null 1> /dev/null
  150.             status=`$check $tmp`
  151.             if [ $status == 'ok' ] ; then
  152.                 break
  153.             elif [ $status == 'no' ] ; then
  154.                 echo -n "."
  155.             elif [ $status == 'err' ] ; then
  156.                 echo "An error occurred while executing '$mangle'"
  157.                 terminate
  158.             fi
  159.         done
  160.         timeend=`date +%s`
  161.         duration=$(( timeend - timestart ))
  162.         echo " done ($duration s)"
  163.         /bin/rm $flock > /dev/null
  164.  
  165.     elif [ $1 == "test" ] ; then
  166.         echo $cmd
  167.  
  168.     elif [ $1 == "conf" ] ; then
  169.         echo -n "checking $mangle..."
  170.         $check $tmp
  171.  
  172.     elif [ $1 == "stat" ] ; then
  173.         $analyze $tmp
  174.  
  175.     else
  176.         echo "unknown command '$1'"
  177.         terminate
  178.     fi
  179.  
  180. done
  181.  
  182. terminate
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement