📄 plot.tcl
字号:
## routines to perform post processing, mostly for plotting#Class PostProcessPostProcess instproc init { l lf lg gf gg redqf} { $self instvar linkflowfile_ linkgraphfile_ $self instvar flowfile_ graphfile_ $self instvar redqfile_ $self instvar label_ post_ set label_ $l set linkflowfile_ $lf set linkgraphfile_ $lg set flowfile_ $gf set graphfile_ $gg set redqfile_ $redqf set format_ "xgraph" ; # default}## Plot the queue size and average queue size, for RED gateways.#PostProcess instproc plot_queue {} { $self instvar redqfile_ $self instvar label_ format_ #TestSuite instproc plotQueue file set awkCode { { if ($1 == "Q" && NF>2) { print $2, $3 >> "temp.q"; set end $2 } else if ($1 == "a" && NF>2) print $2, $3 >> "temp.a"; } } set graphFile $redqfile_.xgr set f [open $graphFile w] puts $f "TitleText: $label_" puts $f "Device: Postscript" exec rm -f temp.q temp.a exec touch temp.a temp.q exec awk $awkCode $redqfile_ puts $f \"queue exec cat temp.q >@ $f puts $f \n\"ave_queue exec cat temp.a >@ $f ###puts $f \n"thresh ###puts $f 0 [[ns link $r1 $r2] get thresh] ###puts $f $end [[ns link $r1 $r2] get thresh] close $f puts "running xgraph for queue dynamics ...." if { $format_ == "xgraph" } { exec xgraph -bb -tk -x time -y queue $graphFile & return } puts stderr "graph format $format_ unknown"}# x axis: # arrivals for this flow+category / # total arrivals [bytes]# y axis: # drops for this flow+category / # drops this category [pkts]PostProcess instproc unforcedmakeawk arg { if { $arg == "unforced" } { set awkCode { BEGIN { prev=-1; print "\"flow 0"; } { if ($5 != prev) { print " "; print "\"flow " $5; if ($13 > 0 && $14 > 0) { print 100.0 * $9/$13, 100.0 * $10 / $14; } prev = $5; } else if ($13 > 0 && $14 > 0) { print 100.0 * $9 / $13, 100.0 * $10 / $14; } } } } elseif { $arg == "forced" } { set awkCode { BEGIN { prev=-1; print "\"flow 0" } { if ($5 != prev) { print " "; print "\"flow " $5; if ($13 > 0 && ($16-$14) > 0) { print 100.0 * $9/$13, 100.0 * ($18-$10) / ($16-$14); } prev = $5; } else if ($13 > 0 && ($16-$14) > 0) { print 100.0 * $9 / $13, 100.0 * ($18-$10) / ($16-$14); } } } } else { puts stderr "Error: unforcedmakeawk: arg $arg unknown." return {} } return $awkCode}## awk code used to produce:# x axis: # arrivals for this flow+category / # total arrivals [bytes]# y axis: # drops for this flow+category / # drops this category [pkts]# Make sure that N > 2.3 / P^2, for N = # drops this category [pkts],# P = y axis valuePostProcess instproc unforcedmakeawk1 { } { return { BEGIN { print "\"flow 0" } { if ($5 != prev) { print " "; print "\"flow " $5; drops = 0; flow_drops = 0; arrivals = 0; flow_arrivals = 0; byte_arrivals = 0; flow_byte_arrivals = 0; } drops += $14; flow_drops += $10; arrivals += $12; byte_arrivals += $13; flow_arrivals += $8; flow_byte_arrivals += $9; p = flow_arrivals/arrivals; if (p*p*drops >= 2.3) { print 100.0 * flow_byte_arrivals/byte_arrivals, 100.0 * flow_drops / drops; drops = 0; flow_drops = 0; arrivals = 0; flow_arrivals = 0; byte_arrivals = 0; flow_byte_arrivals = 0; } else { printf "p: %8.2f drops: %d\n", p, drops } prev = $5 } }}#printf "prev=%d,13=%d,17=%d,15=%d\n",prev,$13,$17,$15;## awk code used to produce:# x axis: # arrivals for this flow+category / # total arrivals [bytes]# y axis: # drops for this flow+category / # drops this category [bytes]PostProcess instproc forcedmakeawk arg { if { $arg == "forced" } { set awkCode { BEGIN { prev=-1; print "\"flow 0"; } { if ($5 != prev) { print " "; print "\"flow " $5; if ($13 > 0 && ($17-$15) > 0) { print 100.0 * $9/$13, 100.0 * ($19-$11) / ($17-$15); prev = $5; } } else if ($13 > 0 && ($17-$15) > 0) { print 100.0 * $9 / $13, 100.0 * ($19-$11) / ($17-$15); } } } } elseif { $arg == "unforced" } { set awkCode { BEGIN { prev=-1; print "\"flow 0"; } { if ($5 != prev) { print " "; print "\"flow " $5; if ($13 > 0 && $15 > 0) { print 100.0 * $9/$13, 100.0 * $11 / $15; prev = $5; } } else if ($13 > 0 && $15 > 0) { print 100.0 * $9 / $13, 100.0 * $11 / $15; } } } } else { puts stderr "Error: forcedmakeawk: arg $arg unknown." return {} } return $awkCode}## awk code used to produce:# x axis: # arrivals for this flow+category / # total arrivals [bytes]# y axis: # drops for this flow / # drops [pkts and bytes combined]PostProcess instproc allmakeawk { } { set awkCode { BEGIN { prev=-1; frac_bytes=0; frac_packets=0; frac_arrivals=0; cat0=0; cat1=0} { if ($5 != prev) { print " "; print "\"flow "$5; prev = $5 } if ($1 != prevtime && cat1 + cat0 > 0) { if (frac_packets + frac_bytes > 0) { cat1_part = frac_packets * cat1 / ( cat1 + cat0 ) cat0_part = frac_bytes * cat0 / ( cat1 + cat0 ) print 100.0 * frac_arrivals, 100.0 * ( cat1_part + cat0_part ) } frac_bytes = 0; frac_packets = 0; frac_arrivals = 0; cat1 = 0; cat0 = 0; prevtime = $1 } if ($14 > 0) { frac_packets = $10/$14; } else { frac_packets = 0; } if (($17-$15) > 0) { frac_bytes = ($19-$11)/($17-$15); } else { frac_bytes = 0; } if ($13 > 0) { frac_arrivals = $9/$13; } else { frac_arrivals = 0; } cat0 = $16-$14; cat1 = $14; prevtime = $1 } END { if (frac_packets + frac_bytes > 0) { cat1_part = frac_packets * cat1 / ( cat1 + cat0 ) cat0_part = frac_bytes * cat0 / ( cat1 + cat0 ) print 100.0 * frac_arrivals, 100.0 * ( cat1_part + cat0_part ) } } } return $awkCode}#--------------------------------------------------------------PostProcess instproc create_flow_graph { graphtitle in out awkprocedure } { puts "removing graph file: $out" exec rm -f $out set outdesc [open $out w] # # this next part is xgraph specific # puts $outdesc "TitleText: $graphtitle" puts $outdesc "Device: Postscript" puts "writing flow data to $out ..." catch {exec sort -n +1 -o $in $in} result exec awk [$awkprocedure] $in >@ $outdesc close $outdesc}# plot drops vs. arrivalsPostProcess instproc finish_flow {} { $self instvar format_ $self instvar label_ linkflowfile_ linkgraphfile_ $self create_flow_graph $label_ $linkflowfile_ $linkgraphfile_ $awkprocedure puts "running xgraph for comparing drops and arrivals..." if { $format_ == "xgraph" } { exec xgraph -bb -tk -nl -m -lx 0,100 -ly 0,100 -x "% of data bytes" -y "% of discards" $linkgraphfile_ & } puts stderr "graph format $format_ unknown"}# plot drops vs. arrivals, for unforced drops.PostProcess instproc plot_dropsinpackets { name flowgraphfile } { $self instvar format_ $self instvar label_ linkflowfile_ linkgraphfile_ $self create_flow_graph $label_ $linkflowfile_ $linkgraphfile_ \ "$self unforcedmakeawk unforced" puts "running xgraph for comparing drops and arrivals..." if { $format_ == "xgraph" } { exec xgraph -bb -tk -nl -m -lx 0,100 -ly 0,100 -x "% of data bytes" -y "% of discards (in packets). Queue in SETME" $linkgraphfile_ & } puts stderr "graph format $format_ unknown"}# plot drops vs. arrivals, for unforced drops.PostProcess instproc plot_dropsinpackets1 { name flowgraphfile } { $self instvar format_ $self instvar label_ linkflowfile_ linkgraphfile_ $self create_flow_graph $label_ $linkflowfile_ $linkgraphfile_ \ "$self unforcedmakeawk1" puts "running xgraph for comparing drops and arrivals..." if { $format_ == "xgraph" } { exec xgraph -bb -tk -nl -m -lx 0,100 -ly 0,100 -x "% of data bytes" -y "% of discards (in packets). Queue in SETME" $linkgraphfile_ & } puts stderr "graph format $format_ unknown"}# plot drops vs. arrivals, for forced drops.PostProcess instproc plot_dropsinbytes { name flowgraphfile } { $self instvar format_ $self instvar label_ linkflowfile_ linkgraphfile_
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -