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

通讯编程

开发平台:

Visual C++

  1. #
  2. Agent/TCP set tcpTick_ 0.1
  3. # The default for tcpTick_ is being changed to reflect a changing reality.
  4. Agent/TCP set rfc2988_ false
  5. # The default for rfc2988_ is being changed to true.
  6. # FOR UPDATING GLOBAL DEFAULTS:
  7. Agent/TCP set precisionReduce_ false ;   # default changed on 2006/1/24.
  8. Agent/TCP set rtxcur_init_ 6.0 ;      # Default changed on 2006/01/21
  9. Agent/TCP set updated_rttvar_ false ;  # Variable added on 2006/1/21
  10. Agent/TCP set minrto_ 1
  11. # default changed on 10/14/2004.
  12. Agent/TCP set useHeaders_ false
  13. # The default is being changed to useHeaders_ true.
  14. Agent/TCP set windowInit_ 1
  15. # The default is being changed to 2.
  16. Agent/TCP set singledup_ 0
  17. # The default is being changed to 1
  18. # Copyright (c) 1998 University of Southern California.
  19. # All rights reserved.                                            
  20. #                                                                
  21. # Redistribution and use in source and binary forms are permitted
  22. # provided that the above copyright notice and this paragraph are
  23. # duplicated in all such forms and that any documentation, advertising
  24. # materials, and other materials related to such distribution and use
  25. # acknowledge that the software was developed by the University of
  26. # Southern California, Information Sciences Institute.  The name of the
  27. # University may not be used to endorse or promote products derived from
  28. # this software without specific prior written permission.
  29. # THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
  30. # WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
  31. # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  32. # This test suite is for validating sliding window
  33. # To run all tests: test-all-sliding-window
  34. # to run individual test:
  35. # ns test-suite-sliding-window.tcl sliding-normal
  36. # ns test-suite-sliding-window.tcl sliding-loss
  37. #
  38. # To view a list of available test to run with this script:
  39. # ns test-suite-sliding-window.tcl
  40. #
  41. # Each of the tests uses 6 nodes 
  42. #
  43. Class TestSuite
  44. Class Test/sliding-normal -superclass TestSuite
  45. # Simple sliding window without any packet loss
  46. Class Test/sliding-loss -superclass TestSuite
  47. # Simple sliding window with packet loss
  48. proc usage {} {
  49. global argv0
  50. puts stderr "usage: ns $argv0 <tests> "
  51. puts "Valid <tests> : sliding-normal sliding-loss"
  52. exit 1
  53. }
  54. TestSuite instproc init {} {
  55.     $self instvar ns_ n_
  56.     set ns_ [new Simulator]
  57.     $ns_ trace-all [open temp.rands w]
  58.     $ns_ namtrace-all [open temp.rands.nam w]
  59.     # setup sliding window topology
  60.        
  61.     foreach i " 0 1 2 3 4 5" {
  62. set n_($i) [$ns_ node]
  63.     }
  64.     $ns_ duplex-link $n_(0) $n_(2) 1Mb 20ms DropTail
  65.     $ns_ duplex-link $n_(1) $n_(2) 1Mb 20ms DropTail
  66.     $ns_ duplex-link $n_(2) $n_(3) 0.5Mb 20ms DropTail
  67.     $ns_ duplex-link $n_(3) $n_(4) 1Mb 20ms DropTail
  68.     $ns_ duplex-link $n_(3) $n_(5) 1Mb 20ms DropTail
  69.     $ns_ duplex-link-op $n_(0) $n_(2) orient right-down
  70.     $ns_ duplex-link-op $n_(1) $n_(2) orient right-up
  71.     $ns_ duplex-link-op $n_(2) $n_(3) orient right
  72.     $ns_ duplex-link-op $n_(3) $n_(4) orient right-up
  73.     $ns_ duplex-link-op $n_(3) $n_(5) orient right-down
  74.     $ns_ duplex-link-op $n_(2) $n_(3) queuePos 0.5
  75. }
  76. TestSuite instproc finish {} {
  77. $self instvar ns_
  78. global quiet
  79. $ns_ flush-trace
  80.         if { !$quiet } {
  81.                 puts "running nam..."
  82.                 exec nam temp.rands.nam &
  83.         }
  84. exit 0
  85. }
  86. Test/sliding-normal instproc init {flag} {
  87. $self instvar ns_ testName_ flag_
  88. set testName_ sliding-normal
  89. set flag_ $flag
  90. $self next
  91. }
  92. Test/sliding-normal instproc run {} {
  93. $self instvar ns_ n_ 
  94.         $ns_ queue-limit $n_(2) $n_(3) 50
  95.         ### TCP between n_(0) & n_(4)
  96.         Agent/TCP set maxcwnd_ 8
  97.         set sliding [new Agent/TCP/SlidingWindow]
  98.         $ns_ attach-agent $n_(0) $sliding
  99.         set sink [new Agent/TCPSink/SlidingWindowSink]
  100.         $ns_ attach-agent $n_(4) $sink
  101.         $ns_ connect $sliding $sink
  102.         set ftp [new Application/FTP]
  103.         $ftp attach-agent $sliding
  104.         ### CBR traffic between n_(1) & n_(5)
  105.         set udp0 [new Agent/UDP]
  106.         $ns_ attach-agent $n_(1) $udp0
  107.         set cbr0 [new Application/Traffic/CBR]
  108.         $cbr0 set packetSize_ 500
  109.         $cbr0 set interval_ 0.01
  110.         $cbr0 attach-agent $udp0
  111.         set null0 [new Agent/Null]
  112.         $ns_ attach-agent $n_(5) $null0
  113.         $ns_ connect $udp0 $null0
  114.         ### setup operation
  115. $ns_ at 0.1 "$cbr0 start"
  116.         $ns_ at 1.1 "$cbr0 stop"
  117.         $ns_ at 0.2 "$ftp start"
  118.         $ns_ at 1.1 "$ftp stop"
  119. $ns_ at 1.2 "$self finish"
  120. $ns_ run
  121. }
  122. Test/sliding-loss instproc init {flag} {
  123. $self instvar ns_ testName_ flag_
  124. set testName_ sliding-loss
  125. set flag_ $flag
  126. $self next 
  127. }
  128. Test/sliding-loss instproc run {} {
  129. $self instvar ns_ n_
  130.         $ns_ queue-limit $n_(2) $n_(3) 10
  131.         ### TCP between n_(0) & n_(4)
  132.         Agent/TCP set maxcwnd_ 8
  133.         set sliding [new Agent/TCP/SlidingWindow]
  134.         $ns_ attach-agent $n_(0) $sliding
  135.         set sink [new Agent/TCPSink/SlidingWindowSink]
  136.         $ns_ attach-agent $n_(4) $sink
  137.         $ns_ connect $sliding $sink
  138.         set ftp [new Application/FTP]
  139.         $ftp attach-agent $sliding
  140.         ### CBR traffic between n_(1) & n_(5)
  141.         set udp0 [new Agent/UDP]
  142.         $ns_ attach-agent $n_(1) $udp0
  143.         set cbr0 [new Application/Traffic/CBR]
  144.         $cbr0 attach-agent $udp0
  145.         set null0 [new Agent/Null]
  146.         $ns_ attach-agent $n_(5) $null0
  147.         $ns_ connect $udp0 $null0
  148.         ### setup operation
  149. $ns_ at 0.1 "$cbr0 start"
  150.         $ns_ at 1.1 "$cbr0 stop"
  151.         $ns_ at 0.2 "$ftp start"
  152.         $ns_ at 1.1 "$ftp stop"
  153. $ns_ at 1.2 "$self finish"
  154. $ns_ run
  155. }
  156. proc runtest {arg} {
  157. global quiet
  158. set quiet 0
  159. set b [llength $arg]
  160. if {$b == 1} {
  161. set test $arg
  162. } elseif {$b == 2} {
  163. set test [lindex $arg 0]
  164.     if {[lindex $arg 1] == "QUIET"} {
  165. set quiet 1
  166.     }
  167. } else {
  168. usage
  169. }
  170. switch $test {
  171.                 sliding-normal -
  172.                 sliding-loss {
  173. set t [new Test/$test 1]
  174. }
  175. default {
  176. stderr "Unknown test $test"
  177. exit 1
  178. }
  179. }
  180. $t run
  181. }
  182. global argv arg0
  183. runtest $argv