📄 flows.v2.tcl
字号:
# this next part is xgraph specific # puts $outdesc "TitleText: $graphtitle" puts $outdesc "Device: Postscript" puts "writing flow xgraph data to $graphfile..." catch {exec sort -n +1 -o $flowfile $flowfile} result exec awk [$awkprocedure] $flowfile >@ $outdesc close $outdesc}# plot drops vs. arrivalsproc finish_flow { name } { global flowgraphfile xgraph awkprocedure create_flow_graph $name $flowgraphfile $awkprocedure puts "running xgraph for comparing drops and arrivals..." if { $xgraph == 1 } { exec xgraph -bb -tk -nl -m -lx 0,100 -ly 0,100 -x "% of data bytes" -y "% of discards" $flowgraphfile & } if { $xgraph == 0 } { exec csh diagonal.com $flowgraphfile & } exit 0}# plot drops vs. arrivals, for unforced drops.proc plot_dropsinpackets { name flowgraphfile } { global xgraph queuetype create_flow_graph $name $flowgraphfile unforcedmakeawk puts "running xgraph for comparing drops and arrivals..." if { $xgraph == 1 } { exec xgraph -bb -tk -nl -m -lx 0,100 -ly 0,100 -x "% of data bytes" -y "% of discards (in packets). Queue in $queuetype" $flowgraphfile & } if { $xgraph == 0 } { exec csh diagonal.com $flowgraphfile & } exit 0}# plot drops vs. arrivals, for unforced drops.proc plot_dropsinpackets1 { name flowgraphfile } { global xgraph queuetype create_flow_graph $name $flowgraphfile unforcedmakeawk1 puts "running xgraph for comparing drops and arrivals..." if { $xgraph == 1 } { exec xgraph -bb -tk -nl -m -lx 0,100 -ly 0,100 -x "% of data bytes" -y "% of discards (in packets). Queue in $queuetype" $flowgraphfile & } if { $xgraph == 0 } { exec csh diagonal.com $flowgraphfile & } exit 0}# plot drops vs. arrivals, for forced drops.proc plot_dropsinbytes { name flowgraphfile } { global xgraph queuetype create_flow_graph $name $flowgraphfile forcedmakeawk puts "running xgraph for comparing drops and arrivals..." if { $xgraph == 1 } { exec xgraph -bb -tk -nl -m -lx 0,100 -ly 0,100 -x "% of data bytes" -y "% of discards (in bytes) Queue in $queuetype" $flowgraphfile & } if { $xgraph == 0 } { exec csh diagonal.com $flowgraphfile & } exit 0}# plot drops vs. arrivals, for combined metric drops.proc plot_dropscombined { name flowgraphfile } { global xgraph create_flow_graph $name $flowgraphfile allmakeawk puts "running xgraph for comparing drops and arrivals..." if { $xgraph == 1 } { exec xgraph -bb -tk -nl -m -lx 0,100 -ly 0,100 -x "% of data bytes" -y "% of discards (combined metric)" $flowgraphfile & } if { $xgraph == 0 } { exec csh diagonal.com $flowgraphfile & } exit 0}#--------------------------------------------------------------------------# awk code used to produce:# x axis: time# y axis: per-flow drop ratiosproc time_awk { } { set awkCode { BEGIN { print "\"flow 0"} { if ($1 != prevtime && prevtime > 0){ if (cat1 + cat0 > 0) { cat1_part = frac_packets * cat1 / ( cat1 + cat0 ) cat0_part = frac_bytes * cat0 / ( cat1 + cat0 ) print prevtime, 100.0 * ( cat1_part + cat0_part ) } frac_bytes = 0; frac_packets = 0; cat1 = 0; cat0 = 0; prevtime = $1 } if ($5 != prev) { print " "; print "\"flow "prev; prev = $5 } if ($3==0) { if ($15>0) {frac_bytes = $11 / $15} else {frac_bytes = 0} cat0 = $14 } if ($3==1) { if ($14>0) {frac_packets = $10 / $14} else {frac_packets = 0} cat1 = $14 } prevtime = $1 } END { cat1_part = frac_packets * cat1 / ( cat1 + cat0 ) cat0_part = frac_bytes * cat0 / ( cat1 + cat0 ) print prevtime, 100.0 * ( cat1_part + cat0_part ) } } return $awkCode}# plot time vs. per-flow drop ratioproc create_time_graph { graphtitle graphfile } { global flowfile awkprocedure exec rm -f $graphfile set outdesc [open $graphfile w] # # this next part is xgraph specific # puts $outdesc "TitleText: $graphtitle" puts $outdesc "Device: Postscript" puts "writing flow xgraph data to $graphfile..." exec sort -n +1 -o $flowfile $flowfile exec awk [time_awk] $flowfile >@ $outdesc close $outdesc}# Plot per-flow bandwidth vs. time.proc plot_dropmetric { name } { global timegraphfile xgraph create_time_graph $name $timegraphfile puts "running time xgraph for plotting arrivals..." if { $xgraph == 1 } { exec xgraph -bb -tk -m -ly 0,100 -x "time" -y "Bandwidth(%)" $timegraphfile & } if { $xgraph == 0 } { exec csh bandwidth.com $timegraphfile & }}#--------------------------------------------------------------------------# awk code used to produce:# x axis: time# y axis: per-flow bytesproc byte_awk { } { set awkCode { BEGIN { new = 1 } { class = $1; time = $2; bytes = $3; if (class != prev) { prev = class; if (new==1) {new=0;} else {print " "; } print "\"flow "prev; } if (bytes > oldbytes[class]) { if (oldtime[class]==0) { interval = $4; } else { interval = time - oldtime[class]; } if (interval > 0) { bitsPerSecond = 8*(bytes - oldbytes[class])/interval; } print time, 100*bitsPerSecond/(bandwidth*1000); print time, 100*bitsPerSecond/(bandwidth*1000); } oldbytes[class] = bytes; oldtime[class] = time; } } return $awkCode}proc reclass_awk { } { set awkCode { { print " "; printf "\"%s\n", $3 print $1, 0; print $1, 100; } }}# plot time vs. per-flow bytesproc create_bytes_graph { graphtitle infile graphfile bandwidth } { global penaltyfile set tmpfile /tmp/fg1[pid] # print: time class bytes interval set awkCode { { printf "%4d %8d %16d $4d\n", $4, $2, $6, $7; } } exec rm -f $graphfile set outdesc [open $graphfile w] # # this next part is xgraph specific # puts $outdesc "TitleText: $graphtitle" puts $outdesc "Device: Postscript" exec rm -f $tmpfile puts "writing flow xgraph data to $graphfile..." exec awk $awkCode $infile | sort > $tmpfile exec awk [byte_awk] bandwidth=$bandwidth $tmpfile >@ $outdesc exec rm -f $tmpfile ## exec awk [reclass_awk] $penaltyfile >@ $outdesc close $outdesc}# Plot per-flow bytes vs. time.proc plot_bytes { name infile outfile bandwidth } { global xgraph create_bytes_graph $name $infile $outfile $bandwidth puts "running xgraph for plotting per-flow bytes..." if { $xgraph == 1 } { exec xgraph -bb -tk -m -ly 0,100 -x "time" -y "Bandwidth(%)" $outfile & } if { $xgraph == 0 } { exec csh bandwidth.com $outfile & }}#--------------------------------------------------------# awk code used to produce:# x axis: time# y axis: aggregate drop ratios in packetsproc frac_awk { } { set awkCode { { if ($1 > prevtime){ if (prevtime > 0) print prevtime, 100.0 * frac prevtime = $1 frac = $16/$12 } } END { print prevtime, 100.0 * frac } } return $awkCode}# plot time vs. aggregate drop ratioproc create_frac_graph { graphtitle graphfile } { global flowfile awkprocedure exec rm -f $graphfile set outdesc [open $graphfile w] # # this next part is xgraph specific # puts $outdesc "TitleText: $graphtitle" puts $outdesc "Device: Postscript" puts "writing flow xgraph data to $graphfile..." exec sort -n +1 -o $flowfile $flowfile exec awk [frac_awk] $flowfile >@ $outdesc close $outdesc}# plot true average of arriving packets that are droppedproc plot_dropave { name } { global flowgraphfile fracgraphfile xgraph awkprocedure create_frac_graph $name $fracgraphfile puts "running time xgraph for plotting drop ratios..." if { $xgraph == 1 } { exec xgraph -bb -tk -m -x "time" -y "Drop_Fraction(%)" $fracgraphfile & } if { $xgraph == 0 } { exec csh dropave.com $fracgraphfile & }}#--------------------------------------------------------------------# plot tcp-friendly bandwidth # "factor" is packetsize/rtt, for packetsize in bytes and rtt in msec.# bandwidth is in Kbps, goodbandwidth is in Bpsproc create_friendly_graph { graphtitle graphfile ratiofile bandwidth } { set awkCode { BEGIN { print "\"reference"; drops=0; packets=0;} { drops = $6 - drops; packets = $4 - packets; rtt = 0.06 if (drops > 0) { dropratio = drops/packets; goodbandwidth = 1.22*factor/sqrt(dropratio); print $2, 100*goodbandwidth*8/(bandwidth*1000); } drops = $6; packets = $4; } } set packetsize 1500 set rtt 0.06 set factor [expr $packetsize / $rtt] exec rm -f $graphfile set outdesc [open $graphfile w] # # this next part is xgraph specific # puts $outdesc "TitleText: $graphtitle" puts $outdesc "Device: Postscript" puts "writing friendly xgraph data to $graphfile..." exec cat Ref >@ $outdesc exec awk $awkCode bandwidth=$bandwidth factor=$factor $ratiofile >@ $outdesc close $outdesc}# Plot tcp-friendly bandwidth.proc plot_friendly { name bandwidth } { global friendlygraphfile xgraph ratiofile puts "beginning time xgraph for tcp-friendly bandwidth..." create_friendly_graph $name $friendlygraphfile $ratiofile $bandwidth puts "running time xgraph for tcp-friendly bandwidth..." if { $xgraph == 1 } { exec xgraph -bb -tk -m -ly 0,200 -x "time" -y "Bandwidth(%)" $friendlygraphfile & } if { $xgraph == 0 } { exec csh bandwidth.com $friendlygraphfile & }}#--------------------------------------------------------------------proc tcpDumpAll { tcpSrc interval label } { global ns proc dump { src interval label } { global ns $ns at [expr [$ns now] + $interval] "dump $src $interval $label" puts time=[$ns now]/class=$label/ack=[$src set ack_] } puts $label:window=[$tcpSrc set window_]/packet-size=[$tcpSrc set packetSize_] $ns at 0.0 "dump $tcpSrc $interval $label"}# dump stats for single flow f onlyproc printFlow { f outfile fm } { global ns puts $outfile [list [$ns now] [$f set flowid_] 0 0 [$f set flowid_] [$f set src_] [$f set dst_] [$f set parrivals_] [$f set barrivals_] [$f set epdrops_] [$f set ebdrops_] [$fm set parrivals_] [$fm set barrivals_] [$fm set epdrops_] [$fm set ebdrops_] [$fm set pdrops_] [$fm set bdrops_] [$f set pdrops_] [$f set bdrops_]]}proc flowDump { link fm } { global category pthresh drop_interval ns flowdesc if {$category == "unforced"} { if {[$fm set epdrops_] >= $pthresh} { $fm dump $fm reset foreach f [$fm flows] { $f reset } set drop_interval 2.0 } else { set drop_interval 1.0 } } elseif {[string compare $category "forced"] == 0} { if {[expr [$fm set pdrops_] - [$fm set epdrops_]] >= $pthresh} { $fm dump $fm reset foreach f [$fm flows] { $f reset } set drop_interval 2.0 } else { set drop_interval 1.0 } } elseif {[string compare $category "combined"] == 0} { if {[$fm set pdrops_] >= $pthresh} { $fm dump $fm reset foreach f [$fm flows] { $f reset } set drop_interval 2.0 } else { set drop_interval 1.0 } } else { puts stderr "Error: flowDump: drop category $category unknown." } # check data # if data good (if N > 2.3/p^2, N is field 14, flowid is 2, packet # drops is 10 ), # $fm resetcounter # $flowmgr total-drops-pthresh n # copy data to permanent file # if data not good, $flowmgr total-drops-pthresh n }proc flowDump1 { link fm } { flowDump $link $fm}proc new_tcp { startTime source dest window class dump size } { global ns set tcp [$ns create-connection TCP/Reno $source TCPSink $dest $class] $tcp set window_ $window if {$size > 0} { $tcp set packetSize_ $size } set ftp [$tcp attach-source FTP] $ns at $startTime "$ftp start" if {$dump == 1 } { tcpDumpAll $tcp 20.0 $class }}proc new_cbr { startTime source dest pktSize interval class } { global ns set cbr [$ns create-connection CBR $source LossMonitor $dest $class] if {$pktSize > 0} { $cbr set packetSize_ $pktSize } $cbr set interval_ $interval $ns at $startTime "$cbr start"}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -