test-suite-red-pd.tcl
上传用户:rrhhcc
上传日期:2015-12-11
资源大小:54129k
文件大小:15k
源码类别:

通讯编程

开发平台:

Visual C++

  1. #
  2. # Copyright (c) 2000  International Computer Science Institute
  3. # All rights reserved.
  4. # Redistribution and use in source and binary forms, with or without
  5. # modification, are permitted provided that the following conditions
  6. # are met:
  7. # 1. Redistributions of source code must retain the above copyright
  8. #    notice, this list of conditions and the following disclaimer.
  9. # 2. Redistributions in binary form must reproduce the above copyright
  10. #    notice, this list of conditions and the following disclaimer in the
  11. #    documentation and/or other materials provided with the distribution.
  12. # 3. All advertising materials mentioning features or use of this software
  13. #    must display the following acknowledgement:
  14. #      This product includes software developed by ACIRI, the AT&T
  15. #      Center for Internet Research at ICSI (the International Computer
  16. #      Science Institute).
  17. # 4. Neither the name of ACIRI nor of ICSI may be used
  18. #    to endorse or promote products derived from this software without
  19. #    specific prior written permission.
  20. # THIS SOFTWARE IS PROVIDED BY ICSI AND CONTRIBUTORS ``AS IS'' AND
  21. # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  22. # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  23. # ARE DISCLAIMED.  IN NO EVENT SHALL ICSI OR CONTRIBUTORS BE LIABLE
  24. # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  25. # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  26. # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  27. # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  28. # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  29. # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  30. # SUCH DAMAGE.
  31. #
  32. set dir [pwd]
  33. catch "cd tcl/test"
  34. source misc_simple.tcl
  35. catch "cd $dir"
  36. remove-all-packet-headers       ; # removes all except common
  37. add-packet-header Flags IP RTP TCP  ; # hdrs reqd for validation test
  38.  
  39. # FOR UPDATING GLOBAL DEFAULTS:
  40. Agent/TCP set precisionReduce_ false ;   # default changed on 2006/1/24.
  41. Agent/TCP set rtxcur_init_ 6.0 ;      # Default changed on 2006/01/21
  42. Agent/TCP set updated_rttvar_ false ;  # Variable added on 2006/1/21
  43. Agent/TCP set tcpTick_ 0.1
  44. # The default for tcpTick_ is being changed to reflect a changing reality.
  45. Agent/TCP set rfc2988_ false
  46. # The default for rfc2988_ is being changed to true.
  47. # FOR UPDATING GLOBAL DEFAULTS:
  48. Queue/RED set bytes_ false              
  49. # default changed on 10/11/2004.
  50. Queue/RED set queue_in_bytes_ false
  51. # default changed on 10/11/2004.
  52. Queue/RED set q_weight_ 0.002
  53. Queue/RED set thresh_ 5 
  54. Queue/RED set maxthresh_ 15
  55. # The RED parameter defaults are being changed for automatic configuration.
  56. Agent/TCP set useHeaders_ false
  57. # The default is being changed to useHeaders_ true.
  58. Agent/TCP set windowInit_ 1
  59. # The default is being changed to 2.
  60. Agent/TCP set singledup_ 0
  61. # The default is being changed to 1
  62. Queue/RED set gentle_ true
  63. Agent/TCP set minrto_ 0
  64. # The default is being changed to minrto_ 1
  65. Agent/TCP set syn_ false
  66. Agent/TCP set delay_growth_ false
  67. # In preparation for changing the default values for syn_ and delay_growth_.
  68. Agent/TCP set timerfix_ false
  69. # The default is being changed to true.
  70. source ../ex/red-pd/monitoring.tcl
  71. set target_rtt_ 0.040
  72. set testIdent_ 0
  73. set verbosity_ -1
  74. set listMode_ multi
  75. set unresponsive_test_ 1
  76. source ../ex/red-pd/helper.tcl
  77. set flowfile fairflow.tr; # file where flow data is written
  78. set flowgraphfile fairflow.xgr; # file given to graph tool 
  79. TestSuite instproc finish file {
  80. global quiet PERL
  81. $self instvar ns_ tchan_ testName_
  82.         exec $PERL ../../bin/getrc -s 2 -d 3 all.tr | 
  83.           $PERL ../../bin/raw2xg -a -s 0.01 -m 90 -t $file > temp.rands
  84. if {$quiet == "false"} {
  85.          exec xgraph -bb -tk -nl -m -x time -y packets temp.rands &
  86. }
  87.         ## now use default graphing tool to make a data file
  88.         ## if so desired
  89. if { [info exists tchan_] && $quiet == "false" } {
  90. $self plotQueue $testName_
  91. }
  92. $ns_ halt
  93. }
  94. TestSuite instproc enable_tracequeue ns {
  95. $self instvar tchan_ node_
  96. set redq [[$ns link $node_(r1) $node_(r2)] queue]
  97. set tchan_ [open all.q w]
  98. $redq trace curq_
  99. $redq trace ave_
  100. $redq attach $tchan_
  101. }
  102. Class Topology
  103. Topology instproc node? num {
  104.     $self instvar node_
  105.     return $node_($num)
  106. }
  107. Class Topology/net2 -superclass Topology
  108. Topology/net2 instproc init ns {
  109.     $self instvar node_ redpdflowmon_ redpdq_ redpdlink_
  110.     set node_(s1) [$ns node]
  111.     set node_(s2) [$ns node]    
  112.     set node_(r1) [$ns node]    
  113.     set node_(r2) [$ns node]    
  114.     set node_(s3) [$ns node]    
  115.     set node_(s4) [$ns node]    
  116.     $self next 
  117.     $ns duplex-link $node_(s1) $node_(r1) 10Mb 2ms DropTail
  118.     $ns duplex-link $node_(s2) $node_(r1) 10Mb 3ms DropTail
  119.     $ns simplex-link $node_(r1) $node_(r2) 0.5Mb 20ms RED/PD 
  120.     $ns simplex-link $node_(r2) $node_(r1) 0.5Mb 20ms DropTail
  121.     $ns queue-limit $node_(r1) $node_(r2) 100
  122.     $ns queue-limit $node_(r2) $node_(r1) 100
  123.     $ns duplex-link $node_(s3) $node_(r2) 10Mb 4ms DropTail
  124.     $ns duplex-link $node_(s4) $node_(r2) 10Mb 5ms DropTail
  125.     set redpdlink_ [$ns link $node_(r1) $node_(r2)]
  126.     set redpdq_ [$redpdlink_ queue]
  127.     set redpdflowmon_ [$redpdq_ makeflowmon $redpdlink_]
  128.  
  129.     $ns duplex-link-op $node_(s1) $node_(r1) orient right-down
  130.     $ns duplex-link-op $node_(s2) $node_(r1) orient right-up
  131.     $ns duplex-link-op $node_(r1) $node_(r2) orient right
  132.     $ns duplex-link-op $node_(r1) $node_(r2) queuePos 0
  133.     $ns duplex-link-op $node_(r2) $node_(r1) queuePos 0
  134.     $ns duplex-link-op $node_(s3) $node_(r2) orient left-down
  135.     $ns duplex-link-op $node_(s4) $node_(r2) orient left-up
  136. }   
  137. TestSuite instproc plotQueue file {
  138. global quiet
  139. $self instvar tchan_
  140. #
  141. # Plot the queue size and average queue size, for RED gateways.
  142. #
  143. set awkCode {
  144. {
  145. if ($1 == "Q" && NF>2) {
  146. print $2, $3 >> "temp.q";
  147. set end $2
  148. }
  149. else if ($1 == "a" && NF>2)
  150. print $2, $3 >> "temp.a";
  151. }
  152. }
  153. set f [open temp.queue w]
  154. puts $f "TitleText: $file"
  155. puts $f "Device: Postscript"
  156. if { [info exists tchan_] } {
  157. close $tchan_
  158. }
  159. exec rm -f temp.q temp.a 
  160. exec touch temp.a temp.q
  161. exec awk $awkCode all.q
  162. puts $f "queue
  163. exec cat temp.q >@ $f  
  164. puts $f n"ave_queue
  165. exec cat temp.a >@ $f
  166. ###puts $f n"thresh
  167. ###puts $f 0 [[ns link $r1 $r2] get thresh]
  168. ###puts $f $end [[ns link $r1 $r2] get thresh]
  169. close $f
  170. if {$quiet == "false"} {
  171. exec xgraph -bb -tk -x time -y queue temp.queue &
  172. }
  173. }
  174. TestSuite instproc tcpDumpAll { tcpSrc interval label } {
  175.     global quiet
  176.     $self instvar dump_inst_ ns_
  177.     if ![info exists dump_inst_($tcpSrc)] {
  178. set dump_inst_($tcpSrc) 1
  179. set report $label/window=[$tcpSrc set window_]/packetSize=[$tcpSrc set packetSize_]
  180. if {$quiet == "false"} {
  181. puts $report
  182. }
  183. $ns_ at 0.0 "$self tcpDumpAll $tcpSrc $interval $label"
  184. return
  185.     }
  186.     $ns_ at [expr [$ns_ now] + $interval] "$self tcpDumpAll $tcpSrc $interval $label"
  187.     set report time=[$ns_ now]/class=$label/ack=[$tcpSrc set ack_]/packets_resent=[$tcpSrc set nrexmitpack_]
  188.     if {$quiet == "false"} {
  189.      puts $report
  190.     }
  191. }       
  192. TestSuite instproc monitorFlow {fid prob} {
  193.     $self instvar topo_ 
  194.     $topo_ instvar redpdflowmon_ redpdq_
  195.     foreach flow [$redpdflowmon_ flows] {
  196. if {[$flow set flowid_] == $fid} {
  197.     #monitor the flow with probability $prob
  198.     $redpdq_ monitor-flow $flow $prob 
  199. }
  200.     }
  201. }
  202. TestSuite instproc unmonitorFlow {fid} {
  203.     $self instvar topo_ 
  204.     $topo_ instvar redpdflowmon_ redpdq_
  205.     foreach flow [$redpdflowmon_ flows] {
  206. if {[$flow set flowid_] == $fid} {
  207.     #unmonitor the flow
  208.     $redpdq_ unmonitor-flow $flow 
  209. }
  210.     }
  211. }
  212. TestSuite instproc unresponsiveFlow {fid penalty} {
  213.     $self instvar topo_ 
  214.     $topo_ instvar redpdflowmon_ redpdq_
  215.     foreach flow [$redpdflowmon_ flows] {
  216. if {[$flow set flowid_] == $fid} {
  217.     #set the flow unresponsive 
  218.     $redpdq_ unresponsive-flow $flow 
  219.     #set unresponsive penalty imposed on an unresponsive flow
  220.     $redpdq_ set unresponsive_penalty_ $penalty
  221. }
  222.     }
  223. }
  224. #
  225. # Start monitoring tcp1 at time 10.0 with probability 0.1,
  226. # and unmonitor it at 20.0
  227. #
  228. Class Test/simple -superclass TestSuite
  229. Test/simple instproc init {} {
  230.     $self instvar net_ test_
  231.     set net_ net2 
  232.     set test_ simple
  233.     $self next pktTraceFile
  234. }
  235. Test/simple instproc run {} {
  236.     $self instvar ns_ node_ testName_ net_ topo_
  237.     $self setTopo
  238.     $topo_ instvar redpdflowmon_ redpdq_
  239.     set stoptime 30.0
  240.     set tcp1 [$ns_ create-connection TCP/Sack1 $node_(s1) TCPSink/Sack1 $node_(s3) 1]
  241.     $tcp1 set window_ 50
  242.     set tcp2 [$ns_ create-connection TCP/Sack1 $node_(s2) TCPSink/Sack1 $node_(s3) 2]
  243.     $tcp2 set window_ 50
  244.     set ftp1 [$tcp1 attach-app FTP]
  245.     set ftp2 [$tcp2 attach-app FTP]
  246.     $self enable_tracequeue $ns_
  247.     $ns_ at 0.0 "$ftp1 start"
  248.     $ns_ at 1.0 "$ftp2 start"
  249.     $ns_ at 10.0 "$self monitorFlow 1 0.1"
  250.     $ns_ at 20.0 "$self unmonitorFlow 1"
  251.     $self tcpDump $tcp1 5.0
  252.     # trace only the bottleneck link
  253.     #$self traceQueues $node_(r1) [$self openTrace $stoptime $testName_]
  254.     $ns_ at $stoptime "$self cleanupAll $testName_"
  255.     $ns_ run
  256. }
  257. #
  258. # Start monitoring udp at time 10.0 with probability 0.1, 
  259. # declare it unresponsive at 20.0 and set unresponsive_penalty_ 3.0
  260. #
  261. Class Test/unresponsive -superclass TestSuite
  262. Test/unresponsive instproc init {} {
  263.     $self instvar net_ test_
  264.     set net_ net2 
  265.     set test_ unresponsive
  266.     $self next pktTraceFile
  267. }
  268. Test/unresponsive instproc run {} {
  269.     $self instvar ns_ node_ testName_ net_ topo_
  270.     $self setTopo
  271.     $topo_ instvar redpdflowmon_ redpdq_
  272.     set stoptime 30.0
  273.     set tcp1 [$ns_ create-connection TCP/Sack1 $node_(s1) TCPSink/Sack1 $node_(s3) 1]
  274.     $tcp1 set window_ 50
  275.     set tcp2 [$ns_ create-connection TCP/Sack1 $node_(s2) TCPSink/Sack1 $node_(s3) 2]
  276.     $tcp2 set window_ 50
  277.     set ftp1 [$tcp1 attach-app FTP]
  278.     set ftp2 [$tcp2 attach-app FTP]
  279.     $self enable_tracequeue $ns_
  280.     $ns_ at 0.0 "$ftp1 start"
  281.     $ns_ at 1.0 "$ftp2 start"
  282.     set udp [$ns_ create-connection UDP $node_(s1) Null $node_(s4) 3]
  283.     set cbr [$udp attach-app Traffic/CBR]
  284.     $cbr set rate_ 0.5Mb
  285.     $ns_ at 1.0 "$cbr start"
  286.     
  287.     $ns_ at 10.0 "$self monitorFlow 3 0.1"
  288.     $ns_ at 20.0 "$self unresponsiveFlow 3 3"
  289.     $self tcpDump $tcp1 5.0
  290.     # trace only the bottleneck link
  291.     #$self traceQueues $node_(r1) [$self openTrace $stoptime $testName_]
  292.     $ns_ at $stoptime "$self cleanupAll $testName_"
  293.     $ns_ run
  294. }
  295. #
  296. # drop from all flows at a fixed configured probability
  297. #
  298. Class Test/frp -superclass TestSuite
  299. Test/frp instproc init {} {
  300.     $self instvar net_ test_
  301.     set net_ net2 
  302.     set test_ frp
  303.     $self next pktTraceFile
  304. }
  305. Test/frp instproc run {} {
  306.     $self instvar ns_ node_ testName_ net_ topo_
  307.     $self setTopo
  308.     $topo_ instvar redpdflowmon_ redpdq_
  309.     set stoptime 30.0
  310.     set tcp1 [$ns_ create-connection TCP/Sack1 $node_(s1) TCPSink/Sack1 $node_(s3) 1]
  311.     $tcp1 set window_ 50
  312.     set tcp2 [$ns_ create-connection TCP/Sack1 $node_(s2) TCPSink/Sack1 $node_(s3) 2]
  313.     $tcp2 set window_ 50
  314.     set ftp1 [$tcp1 attach-app FTP]
  315.     set ftp2 [$tcp2 attach-app FTP]
  316.     $self enable_tracequeue $ns_
  317.     $ns_ at 0.0 "$ftp1 start"
  318.     $ns_ at 1.0 "$ftp2 start"
  319.     #set the constant dropping probability
  320.     $redpdq_ set P_testFRp_ 0.1
  321.     $self tcpDump $tcp1 5.0
  322.     # trace only the bottleneck link
  323.     #$self traceQueues $node_(r1) [$self openTrace $stoptime $testName_]
  324.     $ns_ at $stoptime "$self cleanupAll $testName_"
  325.     $ns_ run
  326. }
  327. #
  328. # one complete test using the identification engine
  329. #
  330. Class Test/complete -superclass TestSuite
  331. Test/complete instproc init {} {
  332.     $self instvar net_ test_
  333.     set net_ net2 
  334.     set test_ complete
  335.     $self next pktTraceFile
  336. }
  337. Test/complete instproc run {} {
  338.     $self instvar ns_ node_ testName_ net_ topo_
  339.     $self setTopo
  340.     $topo_ instvar redpdflowmon_ redpdq_ redpdlink_
  341.     set stoptime 30.0
  342.     set tcp1 [$ns_ create-connection TCP/Sack1 $node_(s1) TCPSink/Sack1 $node_(s3) 1]
  343.     $tcp1 set window_ 50
  344.     set tcp2 [$ns_ create-connection TCP/Sack1 $node_(s2) TCPSink/Sack1 $node_(s3) 2]
  345.     $tcp2 set window_ 50
  346.     set ftp1 [$tcp1 attach-app FTP]
  347.     set ftp2 [$tcp2 attach-app FTP]
  348.     $self enable_tracequeue $ns_
  349.     $ns_ at 0.0 "$ftp1 start"
  350.     $ns_ at 1.0 "$ftp2 start"
  351.     set udp [$ns_ create-connection UDP $node_(s1) Null $node_(s4) 3]
  352.     set cbr [$udp attach-app Traffic/CBR]
  353.     $cbr set rate_ 0.5Mb
  354.     $ns_ at 1.0 "$cbr start"
  355.     set redpdsim [new REDPDSim $ns_ $redpdq_ $redpdflowmon_ $redpdlink_ 0 true]
  356.     
  357.     $self tcpDump $tcp1 5.0
  358.     # trace only the bottleneck link
  359.     #$self traceQueues $node_(r1) [$self openTrace $stoptime $testName_]
  360.     $ns_ at $stoptime "$self cleanupAll $testName_"
  361.     $ns_ run
  362. }
  363. TestSuite instproc printall { fmon time packetsize} {
  364. set packets [$fmon set pdepartures_]
  365. set linkBps [ expr 500000/8 ]
  366. set utilization [expr ($packets*$packetsize)/($time*$linkBps)]
  367. puts "link utilization [format %.3f $utilization]"
  368. }
  369. #
  370. # one complete test using the identification engine, with CBR flows only
  371. #
  372. Class Test/cbrs -superclass TestSuite
  373. Test/cbrs instproc init {} {
  374.     $self instvar net_ test_
  375.     set net_ net2 
  376.     set test_ cbrs
  377.     Queue/RED/PD set noidle_ false
  378.     $self next pktTraceFile
  379. }
  380. Test/cbrs instproc run {} {
  381.     $self instvar ns_ node_ testName_ net_ topo_
  382.     $self setTopo
  383.     $topo_ instvar redpdflowmon_ redpdq_ redpdlink_
  384.     set packetsize_ 200
  385.     Application/Traffic/CBR set random_ 0
  386.     Application/Traffic/CBR set packetSize_ $packetsize_
  387.     set slink [$ns_ link $node_(r1) $node_(r2)]; # link to collect stats on
  388.     set fmon [$ns_ makeflowmon Fid]
  389.     $ns_ attach-fmon $slink $fmon
  390.     set stoptime 30.0
  391.     #set stoptime 5.0
  392.     set udp1 [$ns_ create-connection UDP $node_(s1) Null $node_(s3) 1]
  393.     set cbr1 [$udp1 attach-app Traffic/CBR]
  394.     $cbr1 set rate_ 0.1Mb
  395.     $cbr1 set random_ 0.005
  396.     set udp2 [$ns_ create-connection UDP $node_(s2) Null $node_(s3) 2]
  397.     set cbr2 [$udp2 attach-app Traffic/CBR]
  398.     $cbr2 set rate_ 0.1Mb
  399.     $cbr2 set random_ 0.005
  400.     $self enable_tracequeue $ns_
  401.     $ns_ at 0.2 "$cbr1 start"
  402.     $ns_ at 0.1 "$cbr2 start"
  403.     set udp [$ns_ create-connection UDP $node_(s1) Null $node_(s4) 3]
  404.     set cbr [$udp attach-app Traffic/CBR]
  405.     $cbr set rate_ 0.5Mb
  406.     $cbr set random_ 0.001
  407.     $ns_ at 0.0 "$cbr start"
  408.     set redpdsim [new REDPDSim $ns_ $redpdq_ $redpdflowmon_ $redpdlink_ 0 true]
  409.     
  410.     $self timeDump 5.0
  411.     # trace only the bottleneck link
  412.     #$self traceQueues $node_(r1) [$self openTrace $stoptime $testName_]
  413.     $ns_ at $stoptime "$self printall $fmon $stoptime $packetsize_"
  414.     $ns_ at $stoptime "$self cleanupAll $testName_"
  415.     $ns_ run
  416. }
  417. #
  418. # one complete test using the identification engine, with CBR flows only,
  419. # with noidle set to true, so that we don't drop from unresponsive flows
  420. # when it would result in the link going idle
  421. #
  422. Class Test/cbrs-noidle -superclass TestSuite
  423. Test/cbrs-noidle instproc init {} {
  424.     $self instvar net_ test_
  425.     set net_ net2 
  426.     set test_ cbrs-noidle
  427.     Queue/RED/PD set noidle_ true
  428.     Test/cbrs-noidle instproc run {} [Test/cbrs info instbody run ]
  429.     $self next pktTraceFile
  430. }
  431. TestSuite runTest