#!/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 c1   = 1250
set c    = 12500
set maxFlows = 3


# simulation duration is assumed 10 sec, packet size 1000 bytes, and link capacity 1.5 MBps

foreach tcpType (TCP Reno Newreno Sack)

    echo "TCP type: $tcpType"

    foreach type (csfq)

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

      echo "  Scheduling discipline: $type"

      # buffer size = 32000 bytes, threshold size = 8000 bytes
      ${ns_dir}ns TcpUdp.tcl -tcpType ${tcpType} -type ${type} -n ${maxFlows} -buf 32000 -thresh 8000

      foreach nFlow (0 1 2) 

        @ n = `awk '{print $1, $2, $3, $4, $8 "a"}' out.tr | grep " 0 1 " | grep "-" | grep " "${nFlow}"a" | wc -l`

        @ idx = $nFlow + 1
        echo $idx $n >> t

        # bandwidth of flow $nFlow 
        awk '{print $1, $2, $3, $4, $6, $8 "a"}' out.tr | grep " 0 1 " | grep "-" | grep " "${nFlow}"a" | awk '{print $2, $5}' >! t1
        ${util_dir}parse_bwidth t1 ${res_dir}TcpUdp-${tcpType}-${type}-${nFlow}.dat 0 1000
    
      end

      # compute throughput in MBps assumming the packet length 1000 bytes and sim. time = 100s
      ${util_dir}op_col t ${res_dir}TcpUdp-${tcpType}-${type}.dat 2 2 div $c1

  end
end

rm out.tr
rm t
rm t1

echo "making TcpUdp-TCP-csfq.ps" 
gnuplot TcpUdp-TCP-csfq.g
echo "making TcpUdp-Reno-csfq.ps" 
gnuplot TcpUdp-Reno-csfq.g
echo "making TcpUdp-Newreno-csfq.ps" 
gnuplot TcpUdp-Newreno-csfq.g
echo "making TcpUdp-Sack-csfq.ps" 
gnuplot TcpUdp-Sack-csfq.g
echo "DONE"




