Statistics
| Branch: | Tag: | Revision:

sssimulator / test.sh @ master

History | View | Annotate | Download (15.5 KB)

1 6b38058b luca
#!/bin/bash
2
#********************************************************************
3
# Copyright (C) 2008  University of Trento
4
#
5
# Author:    Csaba Kiraly
6
#  	     surname (at) disi.unitn.it
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.
17
#
18
# You should have received a copy of the GNU General Public License
19
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
#********************************************************************
21
22
# Usage: set paramters in this script (after the usage function), then run it with the command line option below
23
function usage () {
24
   echo "Usage: $PROGNAME -d results_dir -t testcase [-p filename_prefix] [-s src_dir] [-c]"
25
   echo "        -d dir: directory for result files"
26
   echo "        -t test: name of the test to execute"
27
   echo "        -p prefix: filename prefix of result files"
28
   echo "        -s dir: directory with sources, used also for recompile"
29
   echo "        -c: copy sources to results directory, and compile there"
30
   exit $1
31
}
32
# examples:
33
#
34
# ./test.sh -d results -t chunkdelay-cdf
35
# Starts recompiling the program in place, and puts results in the "./results" directory.
36
# It runs the "chunkdelay-cdf" test case, i.e. it genates a CDF for all given combination of chunk and peer scheduling algorithms
37
# a copy of ./test.sh (i.e. paramters) will be saved in the "results" folder
38
# a script "rerun.sh" will also be created in the "results" directory, keeping track of the command line options below
39
#
40
# ./test.sh -d results2/047-bw1-homogbw-deg3-numnodes -p 047-bw1-homogbw-deg3_ -t numnodes -c
41
# -c means that it will make a snapshot of the sources under "results2/047-bw1-homogbw-deg3-numnodes/src"
42
# these sources will be used for compilation which will also be done in the new folder, thus it will not interfere with other simulations or modifications to the source
43
# finally, it goes into background.
44
45
# set common parameters below. These will be later overridden by the testcase, if needed.
46
# a lower case "s" at the end of the parameter name means that the parameter is a list, i.e. the script will iterate through all the given values
47
48
CYCLEs=1                # don't change, it does not make sense with the current code: seed guarantees deterministic behaviour, independent of the cycle
49
NUM_SEEDS=10             # number of random graphs to generate for the test. Note that MAX values will be averaged amond runs with different seeds
50
SEEDs=`seq 1 1 $NUM_SEEDS`
51
NUM_ITERATIONS=3        # number of runs done (with each algorithm) on the same graph. MAX values will be maxed among these runs
52
53
NUM_PEERSs=100          # number of peers, including the source
54
DEGREEs='($NUM_PEERS)'   # neighborhood size. Set in to "NUM_PEERS-1" for a full mesh. To be improved when better graph generation algorithms are implemented
55
MEANBWs=1.0             # mean bandwidth. 1:critical regime; <1:overload regime >1:undeload regime
56
PEERSCLASS1s=1.0        # ratio of peers in the first class
57
MEANCLASS1s='(($MEANBW-(1.0-$PEERSCLASS1)*$MEANCLASS2)/$PEERSCLASS1)' # BW of peers in the first class. It can be calcualted based on MEANBW = PC1*MC1 + (1-PC1)*MC2
58
PEERSCLASS2s='(1-$PEERSCLASS1)'
59
MEANCLASS2s=0.5        
60
61
NUM_CHUNKSs=200         # number of chunks
62
63
CSCHEDs="LUc MinDLc RUc" # #RUsLUc RUc EUsLUc         # chunk scheduling alogorithms used
64
PSCHEDs="U_LNNC_p RUp MDp" #RUp U_LC_p U_LNNUC_p BAp BAp_w U_DOWNUP_p U_STRIPE_p            # peer scheduling alogorithms used
65
WIN_SIZEs="50" # "NUM_CHUNKS"  # trading window size. Set to "NUM_CHUNKS" to disable
66
PLAYOUT_DEADLINEs="-1"  # playout deadline: chunk having more delay are not needed and dropped. Set to "-1" to disable
67
68
#==================================================================
69
HEADINGLINE="#cycle\tseed\tpeers\tdegree\tpeercl1\tbw1\tpeercl2\tbw2\tchunks\tcscheduler\tpscheduler\twinsize\tTESTresults\tlossratio\tavgdelay\tmaxdelay"
70
LINEHEAD='$CYCLE\t$SEED\t$NUM_PEERS\t$DEGREE\t$PEERSCLASS1\t$MEANCLASS1\t$PEERSCLASS2\t$MEANCLASS2\t$NUM_CHUNKS\t$CSCHED\t$PSCHED\t$WIN_SIZE' #will be evaluated later using eval
71
RESULTSINDEX=13
72
73
#==================================================================
74
#==================================================================
75
function configure_testcase {
76
case $1 in 
77
  winsize)
78
    XLABEL="\"window size (in chunks)\""
79
    XSHORTNAME=winsize
80
    XINDEX=12
81
    PLOTTITLE='Effect of window size \n
82
     homogenous bandwith, set to $MEANBWs \n
83
     peers=$NUM_PEERSs; degree=$DEGREEs; chunks=$NUM_CHUNKSs; iterations=$NUM_ITERATIONS; seeds=$NUM_SEEDS; window=$WIN_SIZEs'    #will be evaluated later using eval
84
    WIN_SIZEs="5 10 15 20 30 40 50 70 100 190 195 200"
85
    ;;
86
87
  highbwratio)
88
    XLABEL="\"ratio of high BW nodes (inhomogeneous)\""
89
    XSHORTNAME=highbwratio
90
    XINDEX=5
91
    PLOTTITLE='Effect of inhomogeneity \n
92
     average BW fixed at $MEANBWs, low BW fixed at $MEANCLASS2s \n
93
     peers=$NUM_PEERSs; degree=$DEGREEs; chunks=$NUM_CHUNKSs; iterations=$NUM_ITERATIONS; seeds=$NUM_SEEDS; window=$WIN_SIZEs'    #will be evaluated later using eval
94
    MEANBWs=1.0
95
    PEERSCLASS1s=`seq 0.05 0.05 1`
96
    MEANCLASS2s=0.5        
97
    ;;
98
99
  highbw)
100
    XLABEL="\"high BW (note that the number of such nodes decreases, the average is always the same)\""
101
    XSHORTNAME=highbw
102
    XINDEX=6
103
    PLOTTITLE='Effect of inhomogeneity \n
104
     average BW fixed at $MEANBWs, low BW fixed at $MEANCLASS2s \n
105
     peers=$NUM_PEERSs; degree=$DEGREEs; chunks=$NUM_CHUNKSs; iterations=$NUM_ITERATIONS; seeds=$NUM_SEEDS; window=$WIN_SIZEs'    #will be evaluated later using eval
106
    MEANBWs=1.0
107
    PEERSCLASS1s=`seq 0.05 0.05 1`
108
    MEANCLASS2s=0.5        
109
    ;;
110
111
  bw)
112
    XLABEL="\"homogeneous BW\""
113
    XSHORTNAME=bw
114
    XINDEX=6
115
    PLOTTITLE='Effect of homogeneous bandwidth\n
116
     peers=$NUM_PEERSs; degree=$DEGREEs; chunks=$NUM_CHUNKSs; iterations=$NUM_ITERATIONS; seeds=$NUM_SEEDS; window=$WIN_SIZEs'    #will be evaluated later using eval
117
    MEANBWs=`seq 0.9 0.10 3`
118
    PEERSCLASS1s=1.0
119
    ;;
120
121
  numnodes)
122
    XLABEL="\"Number of peers\""
123
    XSHORTNAME=numnodes
124
    XINDEX=3
125
    PLOTTITLE='Number of peers\n
126
     homogenous bandwith, set to $MEANBWs \n
127
     peers=$NUM_PEERSs; degree=$DEGREEs; chunks=$NUM_CHUNKSs; iterations=$NUM_ITERATIONS; seeds=$NUM_SEEDS; window=$WIN_SIZEs'    #will be evaluated later using eval
128
    #NUM_PEERSs="2 3 5 7 10 15 20 30 50 70 100"
129
    NUM_PEERSs="200 300 500 700 1000 1500 2000 3000 5000 7500 10000"
130
    ;;
131
132
  degree)
133
    XLABEL="\"Neighborhood size\""
134
    XSHORTNAME=degree
135
    XINDEX=4
136
    PLOTTITLE='Neighborhood size\n
137
     homogenous bandwith, set to $MEANBWs \n
138
     peers=$NUM_PEERSs; degree=$DEGREEs; chunks=$NUM_CHUNKSs; iterations=$NUM_ITERATIONS; seeds=$NUM_SEEDS; window=$WIN_SIZEs'    #will be evaluated later using eval
139
    #DEGREEs="5 7 10 15 20 30 50 70 99"
140
    DEGREEs="10 13 14 15  50 100 250 500 750 1000 1500 2000 3000 5000 7000 10000"
141
    ;;
142
143
  numchunks)
144
    XLABEL="\"Stream length (number of chunks)\""
145
    XSHORTNAME=numchunks
146
    XINDEX=9
147
    PLOTTITLE='Stream length (number of chunks)\n
148
     homogenous bandwith, set to $MEANBWs \n
149
     peers=$NUM_PEERSs; degree=$DEGREEs; chunks=$NUM_CHUNKSs; iterations=$NUM_ITERATIONS; seeds=$NUM_SEEDS; window=$WIN_SIZEs'    #will be evaluated later using eval
150
    #NUM_CHUNKSs="5 20 50 100 200 500 1000 5000"
151
    NUM_CHUNKSs="50 200 500 1000 2000 5000 10000 15000 20000"
152
    ;;
153
154
  chunkdelay-cdf)
155
    XLABEL="\"chunk delay\""
156
    XSHORTNAME=delay
157
    PLOTTITLE='CDf of individual chunk delays\n
158
     homogenous bandwith, set to $MEANBWs \n
159
     peers=$NUM_PEERSs; degree=$DEGREEs; chunks=$NUM_CHUNKSs; iterations=$NUM_ITERATIONS; seeds=$NUM_SEEDS; window=$WIN_SIZEs'    #will be evaluated later using eval
160
    OUTPREFIX='$CSCHED-$PSCHED'
161
    STAT_CDF=1
162
    ;;
163
  *)
164
    echo "wrong testcase. Look in $0 for more details :)"
165
    exit 1
166
    ;;
167
168
esac
169
}
170
171
172
function set_schedulers {
173
  if [ $CSCHED = "LUc" ];
174
   then
175
    CS=latest_useful_chunk
176
  elif [ $CSCHED = "RUc" ];
177
   then
178
    CS=random_useful_chunk
179
  elif [ $CSCHED = "MinDLc" ];
180
   then
181
    CS=dl_sched
182
   fi
183
184
  if [ $PSCHED = "BAp_w" ];
185
   then
186
    echo "Unsupported Peer Scheduler BA";
187
    exit
188
  elif [ $PSCHED = "BAp" ];
189
   then
190
    echo "Unsupported Peer Scheduler BA";
191
    exit
192
  elif [ $PSCHED = "U_LNNUC_p" ];
193
   then
194
    echo "Unsupported Peer Scheduler U_LNNUC_p";
195
    exit
196
  elif [ $PSCHED = "U_LNNC_p" ];
197
    then
198
     PS=ch_earliest_free_peer
199
  elif [ $PSCHED = "MDp" ];
200
    then
201
     PS=ch_most_deprived_peer
202
  elif [ $PSCHED = "U_LC_p" ];
203
   then
204
    echo "Unsupported Peer Scheduler U_LC_p";
205
    exit
206
  elif [ $PSCHED = "U_DOWNUP_p" ];
207
   then
208
    echo "Unsupported Peer Scheduler U_DOWNUP_p";
209
    exit
210
  elif [ $PSCHED = "U_STRIPE_p" ];
211
   then
212
    echo "Unsupported Peer Scheduler U_STRIPE_p";
213
    exit
214
  elif [ $PSCHED = "RUp" ];
215
   then
216
     PS=ch_useful_peer_random
217
  fi
218
}
219
220
function recompile {
221
  cd $BUILDDIR
222
  make -f $SRCDIR/Makefile SRC=$SRCDIR clean
223
  make -f $SRCDIR/Makefile SRC=$SRCDIR CHUNK_SCHED=$CS PEER_SCHED=$PS
224
  cd -
225
}
226
227
function run {
228
  eval LINEHEAD2=\"$LINEHEAD\"
229
230
  if [[ $RESUME && `awk "/$LINEHEAD2/" $TESTOUT` ]] ; then
231
    echo "$LINEHEAD2 skipped by resume"
232
    return
233
  fi
234
235
  echo -e  $LINEHEAD2
236
  RESULTSLINE=$LINEHEAD2
237
  echo running: $SIMULATOR $@
238
  #RESULTSLINE+=`/usr/bin/time $SIMULATOR $@ | grep "TESTresults"`
239
  #/usr/bin/time -f "user %U sys %S mem %M" -o time.out $SIMULATOR $@ | tee run.out
240
  #RESULTSLINE+=`grep TESTresults run.out`
241
  #RESULTSLINE+=" "`cat time.out`
242
  $BUILDDIR/proc-time 2>&1 $SIMULATOR $@ | tee run.out
243
  RESULTSLINE+=`grep TESTresults run.out`
244
  RESULTSLINE+=" "`grep user run.out`
245
  RESULTSLINE+=" "`grep MAXSIZE run.out`
246
  RESULTSLINE+=" "`grep AVGSIZE run.out`
247
248
  echo -e $RESULTSLINE >>$TESTOUT
249
  if [[ $OUTPREFIX ]]; then
250
    eval OUTPREFIX2=\"$OUTPREFIX\"
251
    cp Perchunkinstance_cdf.out $OUTPREFIX2-Perchunkinstance_cdf.out
252
  fi
253
}
254
255
256
#parameters plotstr, title, outfile_prefix
257
function gnuplot_cdf {
258
cat >$3.gnuplot <<INPUT_END
259
set style data steps
260
set title "$2"
261
set xlabel $XLABEL
262
set ylabel $YLABEL
263
264
set terminal postscript eps color
265
set output "$3.eps"
266
267
$1
268
269
set terminal png size 1024,768
270
set output "$3.png"
271
replot
272
INPUT_END
273
274
gnuplot $3.gnuplot
275
276
}
277
278
#parameter: prefix
279
function plot_cdf {
280
  eval PLOTTITLE2=\"$PLOTTITLE\"
281
  PLOTSTR=""
282
283
  for CSCHED in $CSCHEDs ; do
284
  PLOTSTR2=""
285
  for PSCHED in $PSCHEDs ; do
286
    eval OUTPREFIX2=\"$OUTPREFIX\"
287
    TITLE=$OUTPREFIX2
288
    FILE="$OUTPREFIX2-Perchunkinstance_cdf.out"
289
    if [ "$PLOTSTR" ] ; then PLOTSTR+=$'\n replot' ; else PLOTSTR+='plot' ;  fi
290
    PLOTSTR="$PLOTSTR \"$FILE\" $USING title \"$TITLE\""
291
    if [ "$PLOTSTR2" ] ; then PLOTSTR2+=$'\n replot' ; else PLOTSTR2+='plot' ;  fi
292
    PLOTSTR2="$PLOTSTR2 \"$FILE\" $USING title \"$TITLE\""
293
  done;  
294
  gnuplot_cdf "$PLOTSTR2" "$PLOTTITLE2" $1-$CSCHED
295
  done;  
296
297
  gnuplot_cdf "$PLOTSTR" "$PLOTTITLE2" $1 
298
299
  for PSCHED in $PSCHEDs ; do
300
  PLOTSTR2=""
301
  for CSCHED in $CSCHEDs ; do
302
    eval OUTPREFIX2=\"$OUTPREFIX\"
303
    TITLE=$OUTPREFIX2
304
    FILE="$OUTPREFIX2-Perchunkinstance_cdf.out"
305
    if [ "$PLOTSTR2" ] ; then PLOTSTR2+=$'\n replot' ; else PLOTSTR2+='plot' ;  fi
306
    PLOTSTR2="$PLOTSTR2 \"$FILE\" $USING title \"$TITLE\""
307
  done;  
308
  gnuplot_cdf "$PLOTSTR2" "$PLOTTITLE2" $1-$PSCHED
309
  done;  
310
}
311
312
#parameter: prefix
313
function plot_one {
314
  PLOTSTR=""
315
316
  for CURVE1 in $CSCHEDs ; do
317
  for CURVE2 in $PSCHEDs ; do
318
    CASE="\t$CURVE1\t$CURVE2\t"
319
    TITLE="$CURVE1-$CURVE2"
320
    FILE="< awk '/$CASE/' $TESTOUT"
321
    if [ "$PLOTSTR" ] ; then PLOTSTR+=$'\n replot' ; else PLOTSTR+='plot' ;  fi
322
    PLOTSTR="$PLOTSTR \"$FILE\" $USING title \"$TITLE\""
323
  done;  
324
  done;  
325
326
  eval PLOTTITLE2=\"$PLOTTITLE\"
327
328
#prepare EPS
329
cat >$1.gnuplot <<INPUT_END
330
set style data yerrorlines
331
set title "$PLOTTITLE2"
332
set xlabel $XLABEL
333
set ylabel $YLABEL
334
335
$PLOTSTR
336
337
set terminal postscript eps color
338
set output "$1.eps"
339
replot
340
341
set terminal png size 1024,768
342
set output "$1.png"
343
replot
344
INPUT_END
345
346
347
}
348
349
function plotfiles {
350
if [[ $OUTPREFIX ]]; then
351
  YLABEL="\"CDF\""
352
  YSHORTNAME=cdf
353
  USING=""   #requires gnuplot stddev patch!
354
  plot_cdf ${PREFIX}${XSHORTNAME}-${YSHORTNAME}
355
else
356
  YLABEL="\"average delay [s]\""
357
  YSHORTNAME=avgdelay
358
  YINDEX=$(($RESULTSINDEX + 2))
359
#  USING="using $XINDEX:$YINDEX:$YINDEX:$YINDEX smooth unique"   #requires gnuplot stddev patch!
360
  USING="using $XINDEX:$YINDEX smooth unique"
361
  plot_one ${PREFIX}${XSHORTNAME}-${YSHORTNAME}
362
363
  YLABEL="\"max delay [s]\""
364
  YSHORTNAME=maxdelay
365
  YINDEX=$(($RESULTSINDEX + 3))
366
  USING="using $XINDEX:$YINDEX smooth unique"
367
  plot_one ${PREFIX}${XSHORTNAME}-${YSHORTNAME}
368
369
  YLABEL="\"chunk loss ratio\""
370
  YSHORTNAME=chunkloss
371
  YINDEX=$(($RESULTSINDEX + 1))
372
  USING="using $XINDEX:$YINDEX smooth unique"
373
  plot_one ${PREFIX}${XSHORTNAME}-${YSHORTNAME}
374
fi
375
}
376
377
function plot {
378
  for GNUPLOT_FILE in `ls *.gnuplot` ; do
379
	gnuplot $GNUPLOT_FILE
380
  done;
381
}
382
383
#===============================================================================
384
385
386
PROGNAME=$0
387
CMDLINE="$0 $*"
388
389
while getopts "S:d:p:cs:t:brh" opt; do
390
   case $opt in
391
392
   d )  PREFIXDIR=$OPTARG ;;
393
   p )  PREFIX=$OPTARG ;;
394
   s )  BUILDDIR=$OPTARG ;;
395
   c )  COPYSOURCE=1;;
396
   t )  TESTCASE=$OPTARG ;;
397
   b )  BACKGROUND=1;;
398
   S )  SRCDIR=$OPTARG;;
399
   r )  RESUME=1;;
400
   h )  usage 0 ;;
401
   \?)  usage 1 ;;
402
   esac
403
done
404
405
shift $(($OPTIND - 1))
406
if [[ $1 || ! $TESTCASE || ! $PREFIXDIR ]]; then
407
  usage 1
408
fi
409
410
[[ $BUILDDIR ]] || BUILDDIR=`pwd`
411
412
[[ $SRCDIR ]] || SRCDIR=`pwd`
413
414
SIMULATOR=$BUILDDIR/sssim
415
TESTOUT=${PREFIX}results.txt
416
417
mkdir -p $PREFIXDIR
418
419
#copy sources if needed
420
if [[ $COPYSOURCE ]]; then
421
  #git clone --depth 1 . "$PREFIXDIR/src" || exit 1
422
  SRCDIR2=`pwd`/"$PREFIXDIR/src"
423
  cd $SRCDIR
424
  git clone . "$SRCDIR2" || exit 1
425
  git diff | patch -d "$SRCDIR2" -p1 || exit 1
426
  cd -
427
  cd $PREFIXDIR
428
  exec $SRCDIR2/`basename $0` -d . -p $PREFIX -t $TESTCASE -S $SRCDIR2 -s $SRCDIR2 -b -r &
429
  exit 0
430
else 
431
  cd $PREFIXDIR
432
fi
433
434
#save command line parameters
435
echo $CMDLINE >${PREFIX}rerun.sh
436
chmod u+x ${PREFIX}rerun.sh
437
438
#save code with parameters for later reference
439
#cp $SRCDIR/$0 ${PREFIX}`basename $0`
440
441
# redirect stdout(1) and stderr(2) to logfile and stdout:
442
if [[ $BACKGROUND ]]; then
443
  exec 2>${PREFIX}.err 1>${PREFIX}.out
444
else
445
  exec 2> >(tee ${PREFIX}.err) 1> >(tee ${PREFIX}.out)
446
fi
447
448
#set parameters for the given test case
449
configure_testcase $TESTCASE
450
451
#create results file
452
if [[ ! $RESUME || ! -f $TESTOUT ]]; then
453
  echo -e $HEADINGLINE >$TESTOUT
454
fi
455
456
#create gnuplot files
457
plotfiles
458
459
#start the big cycle
460
for CYCLE in $CYCLEs ; do
461
for SEED in $SEEDs ; do
462
for MEANBW in $MEANBWs ; do
463
for PEERSCLASS1 in $PEERSCLASS1s ; do
464
  PEERSCLASS1=$(eval echo \"scale=6 \; $PEERSCLASS1\" | bc)
465
for MEANCLASS2 in $MEANCLASS2s ; do        
466
  MEANCLASS2=$(eval echo \"scale=6 \; $MEANCLASS2\" | bc)
467
for MEANCLASS1 in $MEANCLASS1s ; do
468
  MEANCLASS1=$(eval echo \"scale=6 \; $MEANCLASS1\" | bc)
469
for PEERSCLASS2 in $PEERSCLASS2s ; do
470
  PEERSCLASS2=$(eval echo \"scale=6 \; $PEERSCLASS2\" | bc)
471
for WIN_SIZE in $WIN_SIZEs ; do
472
for PLAYOUT_DEADLINE in $PLAYOUT_DEADLINEs ; do
473
for CSCHED in $CSCHEDs ; do
474
for PSCHED in $PSCHEDs ; do
475
  date
476
  set_schedulers 
477
  recompile $BUILDDIR
478
for NUM_PEERS in $NUM_PEERSs ; do
479
for DEGREE in $DEGREEs ; do
480
  DEGREE=$(eval echo \"scale=6 \; $DEGREE\" | bc)
481
for NUM_CHUNKS in $NUM_CHUNKSs ; do
482
  run -s $SEED -n $NUM_PEERS -c $NUM_CHUNKS -o $DEGREE
483
done;
484
done;
485
done;
486
done;
487
done; #SCHED
488
plot
489
done;
490
done;
491
done;
492
done;
493
done;
494
done;
495
done;
496
done;
497
done;