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

通讯编程

开发平台:

Visual C++

  1. # -*-  Mode:C++; c-basic-offset:8; tab-width:8; indent-tabs-mode:t -*- */
  2. #
  3. # Copyright (c) 2000  International Computer Science Institute
  4. # All rights reserved.
  5. #
  6. # Redistribution and use in source and binary forms, with or without
  7. # modification, are permitted provided that the following conditions
  8. # are met:
  9. # 1. Redistributions of source code must retain the above copyright
  10. #    notice, this list of conditions and the following disclaimer.
  11. # 2. Redistributions in binary form must reproduce the above copyright
  12. #    notice, this list of conditions and the following disclaimer in the
  13. #    documentation and/or other materials provided with the distribution.
  14. # 3. All advertising materials mentioning features or use of this software
  15. #    must display the following acknowledgement:
  16. # This product includes software developed by ACIRI, the AT&T 
  17. #      Center for Internet Research at ICSI (the International Computer
  18. #      Science Institute).
  19. # 4. Neither the name of ACIRI nor of ICSI may be used
  20. #    to endorse or promote products derived from this software without
  21. #    specific prior written permission.
  22. #
  23. # THIS SOFTWARE IS PROVIDED BY ICSI AND CONTRIBUTORS ``AS IS'' AND
  24. # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  25. # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  26. # ARE DISCLAIMED.  IN NO EVENT SHALL ICSI OR CONTRIBUTORS BE LIABLE
  27. # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  28. # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  29. # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  30. # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  31. # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  32. # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  33. # SUCH DAMAGE.
  34. #
  35. # @(#) $Header: /cvsroot/nsnam/ns-2/tcl/lib/ns-pushback.tcl,v 1.5 2001/01/20 20:48:38 ratul Exp $
  36. Node instproc add-pushback-agent {} {
  37. $self instvar pushback_
  38. set pushback_ [new Agent/Pushback]
  39. [Simulator instance] attach-agent $self $pushback_
  40. # puts "Pushback Agent = $pushback_"
  41. $pushback_ initialize $self [[Simulator instance] get-routelogic]
  42. return $pushback_
  43. }
  44. Node instproc get-pushback-agent {} {
  45. $self instvar pushback_
  46. if [info exists pushback_] {
  47. return $pushback_
  48. } else {
  49. return -1
  50. }
  51. }
  52. Simulator instproc pushback-duplex-link {n1 n2 bw delay} {
  53. $self pushback-simplex-link $n1 $n2 $bw $delay
  54. $self pushback-simplex-link $n2 $n1 $bw $delay
  55. }
  56. Simulator instproc pushback-simplex-link {n1 n2 bw delay} {
  57. set pba [$n1 get-pushback-agent]
  58. if {$pba == -1} {
  59. puts "Node does not have a pushback agent"
  60. exit
  61. }
  62. $self simplex-link $n1 $n2 $bw $delay RED/Pushback $pba
  63. set link [$self link $n1 $n2]
  64. set qmon [new QueueMonitor/ED]
  65. $link attach-monitors [new SnoopQueue/In] [new SnoopQueue/Out] [new SnoopQueue/Drop] $qmon
  66. set queue [$link queue]
  67. $queue set pushbackID_ [$pba add-queue $queue]
  68. $queue set-monitor $qmon
  69. $queue set-src-dst [$n1 set id_] [$n2 set id_]
  70. }
  71. Agent/Pushback instproc get-pba-port {nodeid} {
  72. set node [[Simulator instance] set Node_($nodeid)]
  73. set pba [$node get-pushback-agent]
  74. if {$pba == -1} {
  75. return -1
  76. } else {
  77. return [$pba set agent_port_]
  78. }
  79. }
  80. Agent/Pushback instproc check-queue { src dst qToCheck } {
  81. set link [[Simulator instance] set link_($src:$dst)]
  82. set queue [$link queue]
  83. if {$qToCheck == $queue} {
  84. return 1
  85. } else {
  86. return 0
  87. }
  88. }
  89. Queue/RED/Pushback set pushbackID_ -1
  90. Queue/RED/Pushback set rate_limiting_ 1
  91. Agent/Pushback set last_index_ 0
  92. Agent/Pushback set intResult_ -1
  93. Agent/Pushback set enable_pushback_ 1
  94. Agent/Pushback set verbose_ false
  95. #
  96. # Added to be able to trace the drops in rate-limiter
  97. #
  98. Queue/RED/Pushback instproc attach-traces {src dst file {op ""}} {
  99. $self next $src $dst $file $op
  100. set ns [Simulator instance]
  101. #set this up late if you want.
  102. # set type [$self mon-trace-type]
  103. #nam does not understand anything else yet
  104. # if {$op == "nam"} {
  105. # set type "Drop"
  106. # }
  107. set type "Drop"
  108. set rldrop_trace [$ns create-trace $type $file $src $dst $op]
  109. set oldTrace [$self rldrop-trace]
  110. if {$oldTrace!=0} {
  111. puts "exists"
  112. $rldrop_trace target $oldTrace
  113. } else {
  114. # puts "Does not exist"
  115. $rldrop_trace target [$ns set nullAgent_]
  116. }
  117. $self rldrop-trace $rldrop_trace
  118. }