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

通讯编程

开发平台:

Visual C++

  1. #
  2. # Copyright (c) 1995 The Regents of the University of California.
  3. # All rights reserved.
  4. #
  5. # Redistribution and use in source and binary forms, with or without
  6. # modification, are permitted provided that the following conditions
  7. # are met:
  8. # 1. Redistributions of source code must retain the above copyright
  9. #    notice, this list of conditions and the following disclaimer.
  10. # 2. Redistributions in binary form must reproduce the above copyright
  11. #    notice, this list of conditions and the following disclaimer in the
  12. #    documentation and/or other materials provided with the distribution.
  13. # 3. All advertising materials mentioning features or use of this software
  14. #    must display the following acknowledgement:
  15. # This product includes software developed by the Computer Systems
  16. # Engineering Group at Lawrence Berkeley Laboratory.
  17. # 4. Neither the name of the University nor of the Laboratory may be used
  18. #    to endorse or promote products derived from this software without
  19. #    specific prior written permission.
  20. #
  21. # THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  22. # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  23. # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  24. # ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  25. # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  26. # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  27. # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  28. # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  29. # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  30. # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  31. # SUCH DAMAGE.
  32. #
  33. remove-all-packet-headers       ; # removes all except common
  34. add-packet-header Flags IP RTP TCP  ; # hdrs reqd for validation test
  35.  
  36. # FOR UPDATING GLOBAL DEFAULTS:
  37. Simulator instproc get-link { node1 node2 } {
  38.     $self instvar link_
  39.     set id1 [$node1 id]
  40.     set id2 [$node2 id]
  41.     return $link_($id1:$id2)
  42. }
  43. #Simple SRR Test-suite 
  44. proc set_queue {} {
  45. global q 
  46. $q maxqueuenumber 256
  47. $q mtu 250
  48. $q granularity  10000
  49. # $q qlimit 30
  50. # $q maxqueuelen  20
  51. $q setqueue 1 0 
  52. $q setqueue 2 1 
  53. $q setqueue 3 2 
  54. $q setqueue 4 3 
  55. $q setrate 0 80000
  56. $q setrate 1 40000
  57. $q setrate 2 20000
  58. $q setrate 3 10000
  59. }
  60. # create 4 cbr sources 
  61. proc create_traffic {} {
  62. global ns lm0 n0 n1
  63. for {set i 0} {$i < 4} { incr i} {
  64. global udp$i cbr$i
  65. }
  66. for {set i 0} {$i < 4} { incr i} {
  67. set agt [new Agent/UDP]
  68. set app [new Application/Traffic/CBR]
  69. $agt set fid_ [expr $i + 1 ] 
  70. $ns attach-agent $n0 $agt
  71. $app attach-agent $agt
  72. $app set packetSize_ 250
  73. $app set rate_ 100kb
  74. $app set random_ 0 
  75. set udp$i $agt
  76. set cbr$i $app
  77. }
  78. # receiver 0 :
  79. set lm0 [new Agent/Null]
  80. $ns attach-agent $n1 $lm0
  81. for {set i 0} {$i < 4} { incr i} {
  82. global udp$i
  83. set agent [set udp$i]
  84. $ns connect $agent $lm0
  85. }
  86. }
  87. proc start_sim {} {
  88. global ns cbr0 cbr1 cbr2 cbr3
  89. $ns at 0.0 "$cbr0 start"
  90. $ns at 0.0 "$cbr1 start"
  91. $ns at 0.0 "$cbr2 start"
  92. $ns at 0.0 "$cbr3 start"
  93. }
  94. proc stop_sim {} {
  95. global ns f cbr0 cbr1 cbr2 cbr3
  96. $ns at 5.0 "$cbr0 stop"
  97. $ns at 5.0 "$cbr1 stop"
  98. $ns at 5.0 "$cbr2 stop"
  99. $ns at 5.0 "$cbr3 stop"
  100. $ns at 5.0 "close $f;finish"
  101. }
  102. proc finish {} {
  103.     puts "processing output ..."
  104.     exec awk  { 
  105. {
  106.     n[$8]=$8; 
  107.     if ($1=="-") r[$8]++; 
  108.     if ($1=="+") s[$8]++; 
  109.     if ($1=="d") d[$8]++ 
  110.     }
  111. END 
  112.     { 
  113. printf ("Flow#t#sentt#recvdt#dropt%%recvdn"); 
  114.     for (i in r) 
  115.     printf ("%dt%dt%dt%dt%fn",n[i],s[i],r[i],d[i],r[i]*1.0/s[i])
  116. }
  117.     } temp.rands > srr_out.txt
  118. #    exec cat srr_out.txt &
  119.     exit 0
  120. }
  121. proc test_srr {} {
  122. global  ns n0 n1 f l q argv
  123. set ns [new Simulator]
  124. set xx0 [$ns node]
  125. set xy0 [$ns node]
  126. set n0 [$ns node]
  127. set n1 [$ns node]
  128. set f [open temp.rands w]
  129. $ns duplex-link $n0 $n1 150kb 1ms SRR
  130. # trace the bottleneck queue 
  131. $ns trace-queue $n0 $n1 $f
  132. #Alternate way for setting parameters for the SRR queue
  133. set l [$ns get-link $n0 $n1]
  134. set q [$l queue]
  135. create_traffic
  136. set_queue
  137. start_sim 
  138. stop_sim
  139. $ns run
  140. }
  141. global argv arg0
  142. test_srr