📄 test-suite-simple.tcl
字号:
TestSuite instproc printpkts { label tcp } { global tcpTick_ puts "tcp $label highest_seqment_acked [$tcp set ack_]" puts "tcp $label data_bytes_sent [$tcp set ndatabytes_]" set numRtts [$tcp set rtt_] set tick $tcpTick_ set rtt [expr $numRtts * $tcpTick_] puts "tcp $label most_recent_rtt [format "%5.3f" $rtt]" }TestSuite instproc printdrops { fid fmon } { set fcl [$fmon classifier]; # flow classifier # # look up the flow using the classifier. Because we are # using a Fid classifier, the src/dst fields are not compared, # and can thus be just zero, as illustrated here. The "auto" # indicates we don't already know which bucket in the classifier's # hash table to find the flow we're looking for. # set flow [$fcl lookup auto 0 0 $fid] puts "fid: $fid per-link total_drops [$flow set pdrops_]" puts "fid: $fid per-link total_marks [$flow set pmarks_]" puts "fid: $fid per-link total_packets [$flow set pdepartures_]" puts "fid: $fid per-link total_bytes [$flow set bdepartures_]" # # note there is much more date available in $flow and $fmon # that isn't being printed here. #}TestSuite instproc printstop { stoptime } { puts "stop-time $stoptime"}TestSuite instproc printall { fmon } { puts "aggregate per-link total_drops [$fmon set pdrops_]" puts "aggregate per-link total_marks [$fmon set pmarks_]" puts "aggregate per-link total_packets [$fmon set pdepartures_]"}TestSuite instproc printPeakRates { fmon time } { $self instvar pastbytes set allflows [$fmon flows] foreach f $allflows { set fid [$f set flowid_] #set src [$f set src_] #set dst [$f set dst_] set bytes [$f set bdepartures_] if [info exists pastbytes($f)] { set newbytes [expr $bytes - $pastbytes($f)] } else { set newbytes $bytes } if {$newbytes > 0} { #src: $src d st: $dst puts "time: [format "%3.2f" $time] fid: $fid new_bytes $newbytes" set pastbytes($f) $bytes } }}TestSuite instproc printPeakRate { fmon time interval } { $self instvar ns_ set newTime [expr [$ns_ now] + $interval] $ns_ at $time "$self printPeakRates $fmon $time" $ns_ at $newTime "$self printPeakRate $fmon $newTime $interval"}Class Test/stats -superclass TestSuiteTest/stats instproc init topo { $self instvar net_ defNet_ test_ guide_ set net_ $topo set defNet_ net0 set test_ stats set guide_ \ "TCP statistics, and per-flow and aggregate link statistics." $self next}Test/stats instproc run {} { global quiet $self instvar ns_ node_ testName_ guide_ if {$quiet == "false"} {puts $guide_} $ns_ delay $node_(s2) $node_(r1) 200ms $ns_ delay $node_(r1) $node_(s2) 200ms $ns_ queue-limit $node_(r1) $node_(k1) 10 $ns_ queue-limit $node_(k1) $node_(r1) 10 set slink [$ns_ link $node_(r1) $node_(k1)]; # link to collect stats on set fmon [$ns_ makeflowmon Fid] $ns_ attach-fmon $slink $fmon set stoptime 10.1 set tcp0 [$ns_ create-connection TCP $node_(s1) TCPSink $node_(k1) 0] $tcp0 set window_ 30 set tcp1 [$ns_ create-connection TCP $node_(s2) TCPSink $node_(k1) 1] $tcp1 set window_ 30 set ftp0 [$tcp0 attach-app FTP] set ftp1 [$tcp1 attach-app FTP] $ns_ at 1.0 "$ftp0 start" $ns_ at 1.0 "$ftp1 start" $self tcpDumpAll $tcp0 5.0 tcp0 $self tcpDumpAll $tcp1 5.00001 tcp1 set almosttime [expr $stoptime - 0.001] $ns_ at $almosttime "$self printpkts 0 $tcp0" $ns_ at $almosttime "$self printpkts 1 $tcp1" $ns_ at $stoptime "$self printdrops 0 $fmon; $self printdrops 1 $fmon" $ns_ at $stoptime "$self printall $fmon" # trace only the bottleneck link $self traceQueues $node_(r1) [$self openTrace $stoptime $testName_] $ns_ run}Class Test/statsECN -superclass TestSuiteTest/statsECN instproc init topo { $self instvar net_ defNet_ test_ guide_ set net_ $topo set defNet_ net0a set test_ statsECN Queue/RED set setbit_ true Queue/RED set thresh_ 1 Queue/RED set maxthresh_ 0 Agent/TCP set ecn_ 1 set guide_ \ "Flow monitor statistics with ECN." $self next}Test/statsECN instproc run {} { global quiet $self instvar ns_ node_ testName_ guide_ if {$quiet == "false"} {puts $guide_} $ns_ delay $node_(s2) $node_(r1) 200ms $ns_ delay $node_(r1) $node_(s2) 200ms $ns_ queue-limit $node_(r1) $node_(k1) 100 $ns_ queue-limit $node_(k1) $node_(r1) 100 set slink [$ns_ link $node_(r1) $node_(k1)]; # link to collect stats on set fmon [$ns_ makeflowmon Fid] $ns_ attach-fmon $slink $fmon set stoptime 10.1 set tcp0 [$ns_ create-connection TCP $node_(s1) TCPSink $node_(k1) 0] $tcp0 set window_ 30 set tcp1 [$ns_ create-connection TCP $node_(s2) TCPSink $node_(k1) 1] $tcp1 set window_ 30 set ftp0 [$tcp0 attach-app FTP] set ftp1 [$tcp1 attach-app FTP] $ns_ at 1.0 "$ftp0 start" $ns_ at 1.0 "$ftp1 start" set almosttime [expr $stoptime - 0.001] $ns_ at $stoptime "$self printdrops 0 $fmon; $self printdrops 1 $fmon" $ns_ at $stoptime "$self printall $fmon" # trace only the bottleneck link $self traceQueues $node_(r1) [$self openTrace $stoptime $testName_] $ns_ run}Class Test/stats1 -superclass TestSuiteTest/stats1 instproc init topo { $self instvar net_ defNet_ test_ guide_ set net_ $topo set defNet_ net0 Queue/DropTail set summarystats_ true set test_ stats1 set guide_ \ "FTP statistics on bytes produced, and queue statistics. Should be: fid: 0 per-link total_bytes 940." $self next}Test/stats1 instproc run {} { global quiet $self instvar ns_ node_ testName_ guide_ if {$quiet == "false"} {puts $guide_} $ns_ delay $node_(s2) $node_(r1) 200ms $ns_ delay $node_(r1) $node_(s2) 200ms $ns_ queue-limit $node_(r1) $node_(k1) 10 $ns_ queue-limit $node_(k1) $node_(r1) 10 set packetSize_ 100 Agent/TCP set packetSize_ $packetSize_ puts "TCP packetSize [Agent/TCP set packetSize_]" set slink [$ns_ link $node_(r1) $node_(k1)]; # link to collect stats on set fmon [$ns_ makeflowmon Fid] $ns_ attach-fmon $slink $fmon set stoptime 10.1 set tcp0 [$ns_ create-connection TCP $node_(s1) TCPSink $node_(k1) 0] $tcp0 set window_ 30 set tcp1 [$ns_ create-connection TCP $node_(s2) TCPSink $node_(k1) 1] $tcp1 set window_ 30 set ftp0 [$tcp0 attach-app FTP] set ftp1 [$tcp1 attach-app FTP] set packets_ftp 9 set bytes_ftp [expr $packets_ftp * $packetSize_] $ns_ at 1.0 "$ftp0 produce $packets_ftp" puts "ftp 0 segments_produced $packets_ftp (using `FTP produce pktcnt')" $ns_ at 1.0 "$ftp1 send $bytes_ftp" puts "ftp 1 bytes_produced $bytes_ftp (using `FTP send nbytes')" set link1 [$ns_ link $node_(r1) $node_(k1)] set queue1 [$link1 queue] $ns_ at 10.0 "$queue1 printstats" set almosttime [expr $stoptime - 0.001] $ns_ at $almosttime "$self printpkts 0 $tcp0" $ns_ at $almosttime "$self printpkts 1 $tcp1" $ns_ at $stoptime "$self printdrops 0 $fmon; $self printdrops 1 $fmon" $ns_ at $stoptime "$self printall $fmon" # trace only the bottleneck link $self traceQueues $node_(r1) [$self openTrace $stoptime $testName_] $ns_ run}Class Test/stats1Bytes -superclass TestSuiteTest/stats1Bytes instproc init topo { $self instvar net_ defNet_ test_ guide_ set net_ $topo set defNet_ net0 Queue/DropTail set summarystats_ true Queue/DropTail set queue_in_bytes_ true set test_ stats1Bytes set guide_ "Queue statistics for a queue in bytes. Should be: True average queue: 0.439 (in bytes)" Test/stats1Bytes instproc run {} [Test/stats1 info instbody run] $self next}Class Test/stats1a -superclass TestSuiteTest/stats1a instproc init topo { $self instvar net_ defNet_ test_ guide_ set net_ $topo set defNet_ net0a Queue/RED set summarystats_ true set test_ stats1a set guide_ "Queue statistics for a RED queue. Should be: True average queue: 0.004" Test/stats1a instproc run {} [Test/stats1 info instbody run] $self next}Class Test/stats1aBytes -superclass TestSuiteTest/stats1aBytes instproc init topo { $self instvar net_ defNet_ test_ guide_ set net_ $topo set defNet_ net0a Queue/RED set summarystats_ true Queue/RED set queue_in_bytes_ true set test_ stats1aBytes set guide_ "Queue statistics for a RED queue in bytes. Should be: True average queue: 0.439 (in bytes)" Test/stats1aBytes instproc run {} [Test/stats1 info instbody run] $self next}Class Test/statsHeaders -superclass TestSuiteTest/statsHeaders instproc init topo { $self instvar net_ defNet_ test_ guide_ set net_ $topo set defNet_ net0a Queue/RED set summarystats_ true Agent/TCP set useHeaders_ true set test_ statsHeaders set guide_ \ "FTP and packet statistics for TCP with correct accounting for headers. Should be: fid: 0 per-link total_bytes 1300" Test/statsHeaders instproc run {} [Test/stats1 info instbody run] $self next}Class Test/stats2 -superclass TestSuiteTest/stats2 instproc init topo { $self instvar net_ defNet_ test_ guide_ set net_ $topo set defNet_ net2 Queue/RED set summarystats_ true set test_ stats2 set guide_ \ "Queue statistics for the true average queue size. Should be: True average queue: 8.632" $self next}Test/stats2 instproc run {} { global quiet $self instvar ns_ node_ testName_ guide_ if {$quiet == "false"} {puts $guide_} set stoptime 10.1 set tcp0 [$ns_ create-connection TCP $node_(s1) TCPSink $node_(s3) 0] $tcp0 set window_ 1000 set tcp1 [$ns_ create-connection TCP $node_(s2) TCPSink $node_(s3) 1] $tcp1 set window_ 1000 set ftp0 [$tcp0 attach-app FTP] set ftp1 [$tcp1 attach-app FTP] $ns_ at 0.0 "$ftp0 start" $ns_ at 1.0 "$ftp1 start" set link1 [$ns_ link $node_(r1) $node_(r2)] set queue1 [$link1 queue] $ns_ at 10.0 "$queue1 printstats" # trace only the bottleneck link $self traceQueues $node_(r1) [$self openTrace $stoptime $testName_] $ns_ run}Class Test/stats3 -superclass TestSuiteTest/stats3 instproc init topo { $self instvar net_ defNet_ test_ guide_ set net_ $topo set defNet_ net3 set test_ stats3 QueueMonitor set keepRTTstats_ 1 QueueMonitor set maxRTT_ 1 QueueMonitor set binsPerSec_ 100 QueueMonitor set keepSeqnoStats_ 1 QueueMonitor set maxSeqno_ 2000 QueueMonitor set SeqnoBinSize_ 100 Agent/TCP set tcpTick_ 0.01 set guide_ "Printing RTT and Seqno statistics." $self next}Test/stats3 instproc run {} { global quiet $self instvar ns_ node_ testName_ guide_ if {$quiet == "false"} {puts $guide_} set stoptime 1.1 set slink [$ns_ link $node_(r1) $node_(r2)]; set fmon [new QueueMonitor] #set outfile [open temp.stats w] set outfile stdout $fmon traceDist $outfile $ns_ attach-fmon $slink $fmon set tcp0 [$ns_ create-connection TCP $node_(s1) TCPSink $node_(s3) 0] $tcp0 set window_ 10 set tcp1 [$ns_ create-connection TCP $node_(s2) TCPSink $node_(s3) 1] $tcp1 set window_ 10 set ftp0 [$tcp0 attach-app FTP] set ftp1 [$tcp1 attach-app FTP] $ns_ at 0.0 "$ftp0 start" $ns_ at 0.1 "$ftp1 start" set link1 [$ns_ link $node_(r1) $node_(r2)] set queue1 [$link1 queue] $ns_ at $stoptime "$fmon printRTTs" # ## to plot RTTs: ## ./test-all-simple stats3 > out % ## awk -f rtts.awk out > data ## xgraph -bb -tk -x rtt -y frac_of_pkts data & # $ns_ at $stoptime "$fmon printSeqnos" # ## to plot seqnos: ## ./test-all-simple stats3 > out & ## awk -f seqnos.awk out > data ## xgraph -bb -tk -x seqno_bin -y frac_of_pkts data & # # trace only the bottleneck link $self traceQueues $node_(r1) [$self openTrace $stoptime $testName_] $ns_ run}Class Test/stats4 -superclass TestSuiteTest/stats4 instproc init topo { $self instvar net_ defNet_ test_ guide_ set net_ $topo set defNet_ net3 set test_ stats4 Agent/TCP set tcpTick_ 0.01 set guide_ "Printing peak rate statistics." $self next}Test/stats4 instproc run {} { global quiet $self instvar ns_ node_ testName_ guide_ if {$quiet == "false"} {puts $guide_} set stoptime 1.1 set PeakRateInterval 0.1 set slink [$ns_ link $node_(r1) $node_(r2)]; #set fmon [$ns_ makeflowmon SrcDestFid] set fmon [$ns_ makeflowmon Fid] set outfile stdout $fmon traceDist $outfile $ns_ attach-fmon $slink $fmon set tcp0 [$ns_ create-connection TCP $node_(s1) TCPSink $node_(s3) 0] $tcp0 set window_ 10 set tcp1 [$ns_ create-connection TCP $node_(s2) TCPSink $node_(s3) 1] $tcp1 set window_ 10 set ftp0 [$tcp0 attach-app FTP] set ftp1 [$tcp1 attach-app FTP] $ns_ at 0.0 "$ftp0 start" $ns_ at 0.1 "$ftp1 start" set link1 [$ns_ link $node_(r1) $node_(r2)] set queue1 [$link1 queue] $ns_ at 0.5 "$self printPeakRate $fmon 0.5 $PeakRateInterval" # trace only the bottleneck link $self traceQueues $node_(r1) [$self openTrace $stoptime $testName_] $ns_ run}# printTimestamps.TestSuite runTest### Local Variables:### mode: tcl### tcl-indent-level: 8### tcl-default-application: ns### End:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -