#!/bin/csh -f 

set ns_dir = "../../"
set res_dir = "./"
set util_dir = "../utils/"
# used for computing throughput in Mbps
# assumes packet size of 1000 bytes and simulation time of 10 sec
set c    = 0.00088

set num = 5

foreach exp (udp tcp)

  if ( ${exp} == "udp" ) then
    echo "Experiment: one UDP traversing n congested links (Figure 6(a))"
  else
    echo "Experiment: one TCP traversing n congested links (Figure 6(b))"
  endif

  foreach type (fifo red fred fredl drr csfq)

    if (-e ${res_dir}SerialLinks-${exp}-${type}.dat) then
      rm ${res_dir}SerialLinks-${exp}-${type}.dat
    endif
    if (-e t) then
      rm t
    endif

    echo $type

    foreach nclinks (1 2 3 4 5) 

      @ nn = $nclinks + 1
      echo "  ${nclinks} congested link"
      ${ns_dir}ns SerialLinks.tcl -exp ${exp} -type ${type} -n ${nn} -K 100 -kf 100 -buf 64000 -thresh 16000
      @ n = `awk '{print $1, $2, $8 "a"}' link.tr | grep " 1a" | grep "-" | wc -l`
      echo ${nclinks} $n >> t

      # compute throughput in MBps assumming the packet length 1000 bytes and sim. time = 10s
      ${util_dir}op_col t ${res_dir}SerialLinks-${exp}-${type}.dat 2 2 mul $c

    end
  end

end

rm t
rm link.tr

# use gnuplot to draw figures
echo "making SerialLinks-udp.ps (Figure 6.(a))"
gnuplot SerialLinks-udp.g
# compute the best results between the two version of FRED
${util_dir}max_2ndcol SerialLinks-tcp-fred.dat SerialLinks-tcp-fredl.dat SerialLinks-tcp-fred1.dat
echo "making SerialLinks-tcp.ps (Figure 6.(b))"
gnuplot SerialLinks-tcp.g

echo "DONE"



