⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lib.sh

📁 NSD2 QOS surpport tcl code
💻 SH
字号:
#!/bin/sh# Doug Leith, Hamilton Institute, 2007.  # local functions to do the donkey work#--------------------------------------------------------------------------function makeplots () {local bw=$1local rtt1=$2local rtt2=$3local qmax=$4local web=$5local iter=$6local LABEL=$7local TEST=$8# plot resultsplottitle="BW $bw Mbps, Flow 1 RTT $rtt1 ms, Flow 2 RTT $rtt ms, Buffer $qmax BDP, Web sessions=$web"${LIB}/makeplot.sh ${GNUPLOT} ${LABEL} "$plottitle" $EXT $TERM# and create web link for indexingweblink="RTT1 $rtt1 ms, RTT2 $rtt ms"if [ $iter -gt 1 ]; then   weblink="${weblink} ($iter)"fidir="$CCDESCRIPTION/${TEST}"dir=`echo $dir | sed -e 's/ /%20/g'` params="${URL}/plottest\.htm\?\&numimages=5\&img1=${dir}\/cwnd_${LABEL}.${EXT}\&img2=${dir}\/goodput_${LABEL}.${EXT}\&img3=${dir}\/srtt_${LABEL}.${EXT}\&img4=${dir}\/queue_${LABEL}.${EXT}\&img5=${dir}\/drops_${LABEL}.${EXT}"sed -e "s@+++@<a href=$params>${weblink}<\/a>\&nbsp +++@" index.htm > temp; mv temp index.htm}#--------------------------------------------------------------------------function newrow () {   sed -e "s@+++@${1}<\/td><\/tr><tr><td>+++@" index.htm > temp; mv temp index.htm}#--------------------------------------------------------------------------function endrow () {   sed -e "s@+++@<\/td><\/tr><tr><td>+++@" index.htm > temp; mv temp index.htm}#--------------------------------------------------------------------------function endindex () {   sed -e "s@+++@@" index.htm > temp; mv temp index.htm}function plottitle () {   sed -e "s@--title--@Test Results: ${CCDESCRIPTION}@" index.htm > temp; mv temp index.htm}#--------------------------------------------------------------------------function plotefficiency () {# collate results to plot link utilisation vs buffer provisioning#columns of file mgoodput are:#$qmax $rtt1 $rtt $bw $web mean_aggregate_goodput mean_flow1_goodput mean_flow2_goodput local TEST=$1local rtt=${2} ; # only show results for this rtt (to try to avoid information overload !)local web=${3} ; # only show results for this number of web_sessions (to try to avoid information overload !)local bw q n url dir marker url="${URL}/plottest\.htm\?"dir="$CCDESCRIPTION/${TEST}"dir=`echo $dir | sed -e 's/ /%20/g'` n=0for bw in ${BW}; do      # plot link utilisation vs q ...      LABEL="${TEST}_rtt${rtt}_bw${bw}_w${web}"      # suck out data of interest ...      echo "plotefficiency bw=$bw rtt=$rtt web=$web"      awk  -v bw_=${bw} -v rtt_=${rtt} -v web_=${web}  '($4==bw_ && $3==rtt_ && $5==web_) {print $1, $2, $3, $4, $5, $6*8/bw_/1000000}' mgoodput > efficiency_${LABEL}      if [ -s "efficiency_${LABEL}" -a `wc -l "efficiency_${LABEL}" | awk '{print $1}'` -gt 2 ]; then         # generate plot         $GNUPLOT <<EOFset terminal ${TERM}set xlabel "buffer provisioning (fraction of BDP)"set output "efficiency_${LABEL}.$EXT"set ylabel "link utilisation"set logscale xset title 'BW ${bw} Mbps, RTT ${rtt1}, #Web sessions=${web}'plot 'efficiency_${LABEL}' u 1:6 w l title ''EOF         # and construct web link to plot         n=$(($n+1))         url="${url}img${n}=${dir}/efficiency_${LABEL}.$EXT\&"      fidoneif [ $n -gt 0 ]; thenurl="${url}numimages=$n"marker="<font color=white>e${web}<\/font>"sed -e "s@<font color=white>---<\/font>@---@g" index.htm > temp; mv temp index.htmsed -e "s@${marker}.*${marker}@@g" index.htm > temp; mv temp index.htmsed -e "s@---@${marker}<br><a href=$url>Link utilisation (${TEST}, web=${web})<\/a>\&nbsp${marker}<font color=white>---<\/font>@" index.htm > temp; mv temp index.htmfi}function plotfairness () {# plot fairness vs rtt#columns of file mgoodput are:#$qmax $rtt1 $rtt $bw $web mean_aggregate_goodput mean_flow1_goodput mean_flow2_goodput local TEST=${1} ; # label for test (samertt, etc)local qmax=${2} ; # plot fairness for tests where buffer size is in list $2local w_=${3} ; # plot fairness for tests where #web_sessions=$3local bw local q local n url asymurl dir markerurl="${URL}/plottest\.htm\?"asymurl=$urldir="$CCDESCRIPTION/${TEST}"dir=`echo $dir | sed -e 's/ /%20/g'` n=0for bw in ${BW}; do    for q in $qmax; do       LABEL="${TEST}_q${q}_bw${bw}_w${w_}"      # suck out data of interest ...      awk -v bw_=${bw} -v q_=${q} -v w_=${w_} '($7>$8) {ratio=$8/$7}; ($8>=$7) {ratio=$7/$8}; ($9>$10) {asymratio=$10/$9}; ($10>=$9) {asymratio=$9/$10}; ($4==bw_ && $1==q_ && $5==w_) {print $1, $2, $3, $4, $5, $6, $7, $8, ratio, asymratio}'  mgoodput > fairness_${LABEL}      if [ -s "fairness_${LABEL}" -a `wc -l "fairness_${LABEL}" | awk '{print $1}'` -gt 2 ]; then         # generate plot         $GNUPLOT <<EOFset terminal ${TERM}set output "fairness_${LABEL}.$EXTset ylabel "Throughput ratio"set logscale yset xlabel "RTT (ms)"set title 'BW ${bw} Mbps, Q ${q} BDP, #Web sessions=${w_}'plot 'fairness_${LABEL}' u 3:9 w l title ''set output "asymfairness_${LABEL}.$EXTset title 'BW ${bw} Mbps, Q ${q} BDP, #Web sessions=${w_}'plot 'fairness_${LABEL}' u 3:10 w l title ''EOF          # and construct web link to plot         n=$(($n+1))         url="${url}img${n}=${dir}/fairness_${LABEL}.$EXT\&"         asymurl="${asymurl}img${n}=${dir}/asymfairness_${LABEL}.$EXT\&"      fi   donedoneif [ $n -gt 0 ]; thenurl="${url}numimages=${n}"asymurl="${asymurl}numimages=${n}"sed -e "s@<font color=white>---<\/font>@---@g" index.htm > temp; mv temp index.htmmarker="<font color=white>f${w_}<\/font>"sed -e "s@${marker}.*${marker}@@g" index.htm > temp; mv temp index.htmsed -e "s@---@${marker}<br><a href=${url}>Fairness (${TEST}, web=${w_})<\/a>\&nbsp<a href=${asymurl}>Asymptotic Fairness (${TEST}, web=${w_})<\/a>${marker}<font color=white>---<\/font>@" index.htm > temp; mv temp index.htmfi}#--------------------------------------------------------------------------function runtest () {# create a directory if needed, run test and put results there.  also create a web page index to test results# $1 is directory to use, $2 specifies rtt of flow 1 (same as rtt of flow 2 if $2=0), $3 specifies congestion control algorithm of flow 1.  other test parameters are set via global variables.local bw qmax web rtt rtt1 iter s1 s2 stot sasym1 sasym2 sasymtot count notdone title ww_# MODE variable controls if start a test from scratch (overwriting any previous test data), or if attempt to restart and continue where we left off on a previous test.if [ $MODE != "start" -a $MODE != "restart" ]; then   echo "Problem.  MODE=${MODE}."   exitfilocal TEST=$1if [ ! -d $TEST ]; then mkdir $TEST ; ficd $TEST#create blank web index page for these testscp ${LIB}/template.htm ./index.htmplottitlerm -f mgoodputfor bw in ${BW}; do   for qmax in ${QMAX}; do       for web in ${WEB}; do	 title="BW $bw Mbps, Buffer $qmax BDP, Web sessions=$web"	 newrow "$title"; # start a new row in html page         for rtt in ${RTT}; do 	    stot=0	    s1=0            s2=0	    sasymtot=0	    sasym1=0	    sasym2=0            count=0	    notdone=1	    for (( iter=1 ; $notdone ; iter=$(($iter+1)) )); do	       rtt1="$rtt" ; # defaults to same rtt for both flows	       if [ $2 -gt 1 ]; then		   rtt1=$2	       fi    	       echo "start test: cc1=$3, rtt1=$rtt1, rtt2=$rtt, bw=$bw, qmax=$qmax, web sessions=$web, iter=$iter"	       LABEL="rtt${rtt1}_rtt${rtt}_bw${bw}_q${qmax}_w${web}_${iter}"	       if [ -s "tcp1_${LABEL}.out.gz" ]; then gunzip "tcp1_${LABEL}.out.gz"; fi               if [ -s "tcp2_${LABEL}.out.gz" ]; then gunzip "tcp2_${LABEL}.out.gz"; fi               if [ -s "q_${LABEL}.out.gz" ]; then gunzip "q_${LABEL}.out.gz"; fi	       if [ $MODE != "restart" -o ! -s "tcp1_${LABEL}.out" -o ! -s "tcp2_${LABEL}.out" ]; then                  run="yes"	       else       	          run="no"         	          t=`tail -n 1 tcp1_${LABEL}.out | awk '{print int($1)+1}'`	          t=`echo $t | sed -e 's/ //g'` 	          #echo "t=$t, TIME=$TIME"                  if [ $t -lt $TIME ]; then run="yes"; fi               fi               if [ $run == "yes" ]; then	           # need to run simulation ...		   dir="`pwd`"                   $NS $3 $ALPHAOPT $bw $rtt1 $rtt $qmax $web $TIME $STAGGER1 $(($STAGGER2+$iter-1)) $iter $LABEL $NSLINUX "$dir" $SCALE $LAMBDA $NUMCLIENTS	       fi 	       makeplots $bw $rtt1 $rtt $qmax $web $iter $LABEL $TEST	       #get mean throughput of flows over full test               #bytes1=`tail -n 1 q_${LABEL}.out | awk ' {print $5}'`        	       #bytes2=`tail -n 1 q_${LABEL}.out | awk ' {print $6}'`	       #mean throughput of flows from time of startup of second flow               t=`tail -n 1 tcp1_${LABEL}.out | awk '{print int($1)+1}'`	       t=`echo $t | sed -e 's/ //g'` 	       dt=$(( $STAGGER1+$STAGGER2+$iter-1 ))	       bytes1=`awk -v asym=$dt 'BEGIN {b=0; sb=0;} ($1 <= asym) {sb=$5} ($1 > asym) {b=$5} END {print b-sb }' q_${LABEL}.out`	       bytes2=`awk -v asym=$dt 'BEGIN {b=0; sb=0;} ($1 <= asym) {sb=$6} ($1 > asym) {b=$6} END {print b-sb}' q_${LABEL}.out`	       dt=$(( $t - ($STAGGER1+$STAGGER2+$iter-1) ))	       totmeangoodput=`echo "$bytes1 $bytes2" | awk -v t=$dt '{print int(($1+$2)/t)}'`	       echo "$(($totmeangoodput*8)) (${bytes1}, ${bytes2})"	       #if [ $bytes1 -lt 0 -o $bytes2 -lt 0 ]; then	       #   echo "WARNING: looks like integer overflow on the byte counters in ns. $LABEL" >>warnings	       #fi	       meangoodput1=`echo "$bytes1" | awk -v t=$dt '{print int($1/t)}'`               meangoodput2=`echo "$bytes2" | awk -v t=$dt '{print int($1/t)}'`	       stot=$(($stot+$totmeangoodput )); s1=$(( $s1+$meangoodput1 )); s2=$(( $s2+$meangoodput2 ))	       #get mean throughput of flows starting after $ASYM seconds of test               bytes1=`awk -v asym=$ASYM 'BEGIN {b=0; sb=0;} ($1 <= asym) {sb=$5} ($1 > asym) {b=$5} END {print b-sb }' q_${LABEL}.out`      	       bytes2=`awk -v asym=$ASYM 'BEGIN {b=0; sb=0;} ($1 <= asym) {sb=$6} ($1 > asym) {b=$6} END {print b-sb}' q_${LABEL}.out` 	       dt=$(($t-$ASYM))               totmeangoodput=`echo "$bytes1 $bytes2" | awk -v t=$dt '{print int(($1+$2)/t)}'`               meangoodput1=`echo "$bytes1" | awk -v t=$dt '{print int($1/t)}'`	       meangoodput2=`echo "$bytes2" | awk -v t=$dt '{print int($1/t)}'`               #echo "$(($totmeangoodput*8)) ($bytes1, $bytes2)"	       sasymtot=$(($sasymtot+$totmeangoodput )); sasym1=$(( $sasym1+$meangoodput1 )); sasym2=$(( $sasym2+$meangoodput2 ))               count=$(($count+1))                gzip "tcp1_${LABEL}.out"               gzip "tcp2_${LABEL}.out"               gzip "q_${LABEL}.out"	       if [ $iter -ge $MAXITER ]; then notdone=0; fi	    done            # collect stats on mean per flow and aggregrate goodputs, averaged over MAXITER runs	                echo $qmax $rtt1 $rtt $bw $web $(($stot/$count)) $(($s1/$count)) $(($s2/$count)) $(($sasym1/$count)) $(($sasym2/$count)) >> mgoodput         done	 endrow         # update summary fairness statistics 	 for ww_ in $WEBSHORT; do            plotfairness ${TEST} "$QMAXSHORT" ${ww_}         done       done   done   for ww_ in $WEBSHORT; do       plotefficiency ${TEST} "$RTT1" ${ww_}   donedoneendindexcat warnings 2>/dev/null  ; # display any warnings generated.cd ..} 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -