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

通讯编程

开发平台:

Visual C++

  1. #
  2. # Copyright (C) 1997 by USC/ISI
  3. # All rights reserved.                                            
  4. #                                                                
  5. # Redistribution and use in source and binary forms are permitted
  6. # provided that the above copyright notice and this paragraph are
  7. # duplicated in all such forms and that any documentation, advertising
  8. # materials, and other materials related to such distribution and use
  9. # acknowledge that the software was developed by the University of
  10. # Southern California, Information Sciences Institute.  The name of the
  11. # University may not be used to endorse or promote products derived from
  12. # this software without specific prior written permission.
  13. # THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
  14. # WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
  15. # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  16. #
  17. # Maintainer: Kannan Varadhan <kannan@isi.edu>
  18. #
  19. #
  20. # Simple example of an equal cost multi-path routing through
  21. # two equal cost routes.  Equal cost paths are achieved by diddling
  22. # link costs.
  23. #
  24. #
  25. # $n0       $n3
  26. #         /   
  27. #        /     
  28. #      $n2-------$n4
  29. #     /
  30. #    /
  31. # $n1
  32. #
  33. # However, this is not as simple.  Because $n2 is directly connected to $n4,
  34. # it prefers its ``Direct'' route over multiple equal cost routes learned
  35. # via DV.  Hence,we raise the preference of Direct routes over DV routes.
  36. #
  37. # Furthermore, in this example, link <$n2, $n4> is made dynamic.  This allows
  38. # us to watch traffic between $n2 and $n4 alternate between taking multiple
  39. # equi-cost routes, and the only available route.
  40. #
  41. set ns [new Simulator]
  42. Node set multiPath_ 1
  43. set n0 [$ns node]
  44. set n1 [$ns node]
  45. set n2 [$ns node]
  46. set n3 [$ns node]
  47. set n4 [$ns node]
  48. $n0 shape "circle"
  49. $n1 shape "circle"
  50. $n2 shape "other"
  51. $n3 shape "other"
  52. $n4 shape "box"
  53. set f [open out.tr w]
  54. $ns trace-all $f
  55. set nf [open out.nam w]
  56. $ns namtrace-all $nf
  57. $ns color 0 blue
  58. $ns color 1 red
  59. $ns color 2 white
  60. $ns duplex-link $n0 $n2 10Mb 2ms DropTail
  61. $ns duplex-link $n1 $n2 10Mb 2ms DropTail
  62. $ns duplex-link-op $n0 $n2 orient right-down
  63. $ns duplex-link-op $n1 $n2 orient right-up
  64. $ns duplex-link $n2 $n3 1.5Mb 10ms DropTail
  65. $ns duplex-link $n3 $n4 1.5Mb 10ms DropTail
  66. $ns queue-limit $n2 $n3 5
  67. $ns duplex-link-op $n2 $n3 orient right-up
  68. $ns duplex-link-op $n3 $n4 orient right-down
  69. $ns duplex-link-op $n2 $n3 queuePos 0
  70. $ns duplex-link $n2 $n4 1.5Mb 10ms DropTail
  71. $ns queue-limit $n2 $n4 5
  72. $ns duplex-link-op $n2 $n4 orient right
  73. $ns duplex-link-op $n2 $n3 queuePos 0
  74. $ns duplex-link-op $n2 $n4 queuePos 0
  75. [$ns link $n2 $n4] cost 2
  76. [$ns link $n4 $n2] cost 2
  77. proc build-tcp { n0 n1 startTime } {
  78. global ns
  79. set tcp [new Agent/TCP]
  80. $ns attach-agent $n0 $tcp
  81. set snk [new Agent/TCPSink]
  82. $ns attach-agent $n1 $snk
  83. $ns connect $tcp $snk
  84. set ftp [new Application/FTP]
  85. $ftp attach-agent $tcp
  86. $ns at $startTime "$ftp start"
  87. return $tcp
  88. }
  89. [build-tcp $n0 $n4 0.7] set class_ 0
  90. [build-tcp $n1 $n4 0.9] set class_ 1
  91. proc finish {} {
  92. global argv0
  93. global ns f nf
  94. $ns flush-trace
  95. close $f
  96. close $nf
  97. if [string match {*.tcl} $argv0] {
  98. set prog [string range $argv0 0 [expr [string length $argv0] - 5]]
  99. } else {
  100. set prog $argv0
  101. }
  102. puts "running nam..."
  103. exec nam -f dynamic-nam.conf out.nam &
  104. exit 0
  105. }
  106. Agent/rtProto/Direct set preference_ 200
  107. $ns rtmodel Deterministic {.5 .5} $n2 $n4
  108. [$ns link $n2 $n4] trace-dynamics $ns stdout
  109. $ns rtproto DV
  110. $ns at 8.0 "finish"
  111. $ns run