######################################################## # Statistics Utilities - utils.tcl # # Michele Weigle and Pankaj Sharma # # - based on scripts from L. Xu, K. Harfoush, I. Rhee # # - based on scripts from S. Floyd and E. Souza # ######################################################## proc printlegend {} { global frep endtime bandwidth delay queue buffer global hstcp_type hstcpflows_num global cubic_tcp_mode # write to file puts $frep "clock = [clock format [clock seconds]]" puts $frep "endtime=$endtime bandwidth=$bandwidth delay=$delay buffer=$buffer" puts $frep "HS_Type_F0=$hstcp_type(0) HS_Type_F1=$hstcp_type(1) HS_Num=$hstcpflows_num" puts $frep "CUBIC_tcp_mode=$cubic_tcp_mode" puts $frep "forward HSTCP traffic: flows 0 to [expr $hstcpflows_num - 1]" # print to console puts "clock = [clock format [clock seconds]]" puts "endtime=$endtime bandwidth=$bandwidth delay=$delay buffer=$buffer" puts "HS_Type_F0=$hstcp_type(0) HS_Type_F1=$hstcp_type(1) HS_Num=$hstcpflows_num" puts "CUBIC_tcp_mode=$cubic_tcp_mode" puts "forward HSTCP traffic: flows 0 to [expr $hstcpflows_num - 1]" } proc finish {} { global ns frep urep qfp cfp_hs tput_hs hstcpflows_num begintime puts "Total Time=[clock format [expr [clock second]-$begintime] -format "%H:%M:%S" -gmt true]" puts $frep "Total Time=[clock format [expr [clock second]-$begintime] -format "%H:%M:%S" -gmt true]" for { set i 0} { $i < $hstcpflows_num } { incr i} { flush $cfp_hs($i) flush $tput_hs($i) close $cfp_hs($i) close $tput_hs($i) } flush $qfp close $qfp flush $frep close $frep flush $urep close $urep exit 0 } proc print-queue {interval fp} { global ns qmon set now [$ns now] puts $fp "[format %.2f $now] [$qmon set pkts_]" set nexttime [expr $now+$interval] $ns at $nexttime "print-queue $interval $fp" } proc print-cwnd {flow interval fp} { global ns set now [$ns now] puts $fp "[format %.2f $now] [$flow set cwnd_]" set nexttime [expr $now+$interval] $ns at $nexttime "print-cwnd $flow $interval $fp" } proc print-cwnd-bic {flow interval fp} { global ns set now [$ns now] puts $fp "[format %.2f $now] [$flow set cwnd_] [$flow set bic_delay_min_] [$flow set bic_delay_avg_] [$flow set bic_delay_max_] [$flow set bic_low_utilization_indication_]" set nexttime [expr $now+$interval] $ns at $nexttime "print-cwnd-bic $flow $interval $fp" } proc timeReport {interval} { global ns frep qfp cfp_hs tput_hs hstcpflows_num set now [$ns now] puts "Time=[clock format [clock second] -format "%H:%M"](min), Sim=[format %.1f $now](sec)" for { set i 0} { $i < $hstcpflows_num } { incr i} { flush $cfp_hs($i) flush $tput_hs($i) } flush $qfp flush $frep $ns at [expr $now+$interval] "timeReport $interval" } proc print-th-one {fid fmon interval} { global frep tput_hs lastKBytes ns set now [$ns now] set fcl [$fmon classifier]; # flow classifier set flow [$fcl lookup auto 0 0 $fid] if {$flow != "" } { set bytes [$flow set bdepartures_] set bytesDbl [ns-int64todbl $bytes] set Kbytes [expr $bytesDbl / 1000 ] set thruLastPeriod [ expr ( $Kbytes - $lastKBytes($fid) )*8 /$interval/1000] set lastKBytes($fid) $Kbytes # puts $frep "class $fid: $interval sec throughput(Mbps): [format "%.2f" $now] [format %.2f $thruLastPeriod]" puts $tput_hs($fid) "[format "%.2f" $now] [format %.2f $thruLastPeriod]" } $ns at [expr $now+$interval] "print-th-one $fid $fmon $interval" } proc print-stat-one-pre {fid fmon} { global halftime_bdep halftime_pdrop halftime_parr set fcl [$fmon classifier]; # flow classifier set flow [$fcl lookup auto 0 0 $fid] if {$flow != "" } { set halftime_bdep($fid) [ns-int64todbl [$flow set bdepartures_]] set halftime_pdrop($fid) [$flow set pdrops_] set halftime_parr($fid) [$flow set parrivals_] } } proc print-stat-one {fid fmon} { global bandwidth frep halftime endtime halftime_bdep halftime_pdrop halftime_parr set fcl [$fmon classifier]; # flow classifier set flow [$fcl lookup auto 0 0 $fid] if {$flow != "" } { set actualBytes [ns-int64todbl [$flow set bdepartures_]] set possibleBytes [expr $bandwidth * 1000000.0 * $endtime / 8.0 ] set util [expr $actualBytes * 100.0 / $possibleBytes] set lossrate [expr ("[$flow set pdrops_].0")/[$flow set parrivals_]] set throughput [ expr $actualBytes*8.0/$endtime/1000000] puts "class $fid: overall utilization (%) = [format %.2f $util]" puts "class $fid: overall lossrate = [format %f $lossrate]" puts "class $fid: overall throughput (Mbps) = [format %.2f $throughput]" puts $frep "class $fid: overall utilization (%) = [format %.2f $util]" puts $frep "class $fid: overall lossrate = [format %f $lossrate]" puts $frep "class $fid: overall throughput (Mbps) = [format %.2f $throughput]" set actualBytes [ns-int64todbl [$flow set bdepartures_]] set actualBytes [expr $actualBytes-$halftime_bdep($fid)] set possibleBytes [expr $bandwidth * 1000000.0 * $halftime / 8.0 ] set util [expr $actualBytes * 100.0 / $possibleBytes] set drop1 [expr [$flow set pdrops_] - $halftime_pdrop($fid)] set drop2 [expr [$flow set parrivals_] - $halftime_parr($fid)] set lossrate [expr $drop1*1.0/$drop2] set throughput [ expr $actualBytes*8.0/$halftime/1000000] puts "class $fid: second-half utilization (%) = [format %.2f $util]" puts "class $fid: second-half lossrate = [format %f $lossrate]" puts "class $fid: second-half throughput (Mbps) = [format %.2f $throughput]" puts $frep "class $fid: second-half utilization (%) = [format %.2f $util]" puts $frep "class $fid: second-half lossrate = [format %f $lossrate]" puts $frep "class $fid: second-half throughput (Mbps) = [format %.2f $throughput]" } } proc print-stat-all-pre {} { global qmon ns halftime_bdep_all halftime_pdrop_all halftime_parr_all $ns flush-trace set halftime_bdep_all [ns-int64todbl [$qmon set bdepartures_]] set halftime_pdrop_all [$qmon set pdrops_] set halftime_parr_all [$qmon set parrivals_] } proc print-util {interval prevBytesLeft} { global qmon ns urep bandwidth set now [$ns now] set actualBytes [ns-int64todbl [$qmon set bdepartures_]] set bytesLeft [expr $actualBytes - $prevBytesLeft] set prevBytesLeft $actualBytes set possibleBytes [expr $bandwidth * 1000000.0 * $interval / 8.0 ] set util [expr $bytesLeft * 100.0 / $possibleBytes] puts $urep "$now $util" set nexttime [expr $now+$interval] $ns at $nexttime "print-util $interval $prevBytesLeft" flush $urep } proc print-stat-all {} { global qmon ns frep bandwidth halftime halftime_bdep_all halftime_pdrop_all halftime_parr_all endtime $ns flush-trace set actualBytes [ns-int64todbl [$qmon set bdepartures_]] set possibleBytes [expr $bandwidth * 1000000.0 * $endtime / 8.0 ] set util [expr $actualBytes * 100.0 / $possibleBytes] set lossrate [expr ("[$qmon set pdrops_].0")/[$qmon set parrivals_]] set throughput [ expr $actualBytes*8.0/$endtime/1000000] puts "link: overall utilization (%) = [format %.2f $util]" puts "link: overall lossrate = [format %f $lossrate]" puts "link: overall throughput (Mbps) = [format %.2f $throughput]" puts $frep "link: overall utilization (%) = [format %.2f $util]" puts $frep "link: overall lossrate = [format %f $lossrate]" puts $frep "link: overall throughput (Mbps) = [format %.2f $throughput]" set actualBytes [ns-int64todbl [$qmon set bdepartures_]] set actualBytes [expr $actualBytes-$halftime_bdep_all] set possibleBytes [expr $bandwidth * 1000000.0 * $halftime / 8.0 ] set util [expr $actualBytes * 100.0 / $possibleBytes] set drop1 [expr [$qmon set pdrops_] - $halftime_pdrop_all] set drop2 [expr [$qmon set parrivals_] - $halftime_parr_all] set lossrate [expr $drop1*1.0/$drop2] set throughput [ expr $actualBytes*8.0/$halftime/1000000] puts "link: second-half utilization (%) = [format %.2f $util]" puts "link: second-half lossrate = [format %f $lossrate]" puts "link: second-half throughput (Mbps) = [format %.2f $throughput]" puts $frep "link: second-half utilization (%) = [format %.2f $util]" puts $frep "link: second-half lossrate = [format %f $lossrate]" puts $frep "link: second-half throughput (Mbps) = [format %.2f $throughput]" }