?? utils.tcl
字號:
################################################# Statistics Utilities - utils.tcl ## L. Xu, K. Harfoush, and I. Rhee ## based on scripts from S. Floyd and E. Souza #################################################proc printlegend {} {global frep endtime bandwidth delay queue bufferglobal hstcpflows_type hstcpflows_num hstcpflows_delayglobal regtcpflows_num cubic_tcp_modeglobal rev_regtcpflows # write to file puts $frep "clock = [clock format [clock seconds]]" puts $frep "endtime=$endtime bandwidth=$bandwidth delay=$delay RED/DT=$queue buffer=$buffer" puts $frep "HS_Type=$hstcpflows_type HS_Num=$hstcpflows_num HS_Delay=$hstcpflows_delay" puts $frep "TCP_Num=$regtcpflows_num CUBIC_tcp_mode=$cubic_tcp_mode" puts $frep "forward HSTCP traffic: flows 0 to [expr $hstcpflows_num - 1]" puts $frep "forward Regular TCP traffic: flows 1000 to [expr 1000 + $regtcpflows_num - 1]" puts $frep "backward Regular TCP traffic:flows 2000 to [expr 2000 + $rev_regtcpflows - 1]" puts $frep "forward WEB traffic: class 3000" puts $frep "backward WEB traffic: class 4000" puts $frep "forward small TCP traffic: class 5000" puts $frep "backward small TCP traffic: class 6000" # print to console puts "clock = [clock format [clock seconds]]" puts "endtime=$endtime bandwidth=$bandwidth delay=$delay RED/DT=$queue buffer=$buffer" puts "HS_Type=$hstcpflows_type HS_Num=$hstcpflows_num HS_Delay=$hstcpflows_delay" puts "TCP_Num=$regtcpflows_num CUBIC_tcp_mode=$cubic_tcp_mode" puts "forward HSTCP traffic: flows 0 to [expr $hstcpflows_num - 1]" puts "forward Regular TCP traffic: flows 1000 to [expr 1000 + $regtcpflows_num - 1]" puts "backward Regular TCP traffic:flows 2000 to [expr 2000 + $rev_regtcpflows - 1]" puts "forward WEB traffic: class 3000" puts "backward WEB traffic: class 4000" puts "forward small TCP traffic: class 5000" puts "backward small TCP traffic: class 6000"}proc finish {} { global ns frep urep qfp cfp_hs hstcpflows_num cfp_reg regtcpflows_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) close $cfp_hs($i) } for { set i 0} { $i < $regtcpflows_num } { incr i} { flush $cfp_reg($i) close $cfp_reg($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 hstcpflows_num cfp_reg regtcpflows_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) } for { set i 0} { $i < $regtcpflows_num } { incr i} { flush $cfp_reg($i) } flush $qfp flush $frep $ns at [expr $now+$interval] "timeReport $interval"}proc print-th-one {fid fmon interval} { global frep 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]" } $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]"}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -