2pp-10n-4s-1r.tcl
上传用户:rrhhcc
上传日期:2015-12-11
资源大小:54129k
文件大小:5k
源码类别:

通讯编程

开发平台:

Visual C++

  1. #
  2. # A 2 phase pull example
  3. # This example tests directed diffusion in a 10 node scenario with a 4 senders and a single recvr
  4. #
  5. # ==================================================================
  6. # Define options
  7. # ===================================================================
  8. set opt(chan) Channel/WirelessChannel
  9. set opt(prop) Propagation/TwoRayGround
  10. set opt(netif) Phy/WirelessPhy
  11. set opt(mac) Mac/802_11
  12. set opt(ifq) Queue/DropTail/PriQueue
  13. set opt(ll) LL
  14. set opt(ant)            Antenna/OmniAntenna
  15. set opt(filters)        GradientFilter  ;# old name for twophasepull filter
  16. set opt(x) 670 ;# X dimension of the topography
  17. set opt(y) 670     ;# Y dimension of the topography
  18. set opt(ifqlen) 50 ;# max packet in ifq
  19. set opt(nn) 10 ;# number of nodes
  20. set opt(sndr)            4      ;# no of senders
  21. set opt(rcvr)            1      ;# no of recvrs
  22. set opt(seed) 0.0
  23. set opt(stop) 100 ;# simulation time
  24. set opt(prestop)        199       ;# time to prepare to stop
  25. set opt(tr) "2pp-10n-4s-1r.tr" ;# trace file
  26. set opt(nam)            "2pp-10n-4s-1r.nam"  ;# nam file
  27. set opt(adhocRouting)   Directed_Diffusion
  28. # ==================================================================
  29. LL set mindelay_ 50us
  30. LL set delay_ 25us
  31. LL set bandwidth_ 0 ;# not used
  32. Queue/DropTail/PriQueue set Prefer_Routing_Protocols    1
  33. # unity gain, omni-directional antennas
  34. # set up the antennas to be centered in the node and 1.5 meters above it
  35. Antenna/OmniAntenna set X_ 0
  36. Antenna/OmniAntenna set Y_ 0
  37. Antenna/OmniAntenna set Z_ 1.5
  38. Antenna/OmniAntenna set Gt_ 1.0
  39. Antenna/OmniAntenna set Gr_ 1.0
  40. # Initialize the SharedMedia interface with parameters to make
  41. # it work like the 914MHz Lucent WaveLAN DSSS radio interface
  42. Phy/WirelessPhy set CPThresh_ 10.0
  43. Phy/WirelessPhy set CSThresh_ 1.559e-11
  44. Phy/WirelessPhy set RXThresh_ 3.652e-10
  45. Phy/WirelessPhy set Rb_ 2*1e6
  46. Phy/WirelessPhy set Pt_ 0.2818
  47. Phy/WirelessPhy set freq_ 914e+6 
  48. Phy/WirelessPhy set L_ 1.0
  49. # ==================================================================
  50. # Main Program
  51. # =================================================================
  52. #
  53. # Initialize Global Variables
  54. #
  55. set ns_ [new Simulator] 
  56. set topo [new Topography]
  57. set tracefd [open $opt(tr) w]
  58. $ns_ trace-all $tracefd
  59. set nf [open $opt(nam) w]
  60. $ns_ namtrace-all-wireless $nf $opt(x) $opt(y)
  61. #$ns_ use-newtrace
  62. $topo load_flatgrid $opt(x) $opt(y)
  63. set god_ [create-god $opt(nn)]
  64. # log the mobile nodes movements if desired
  65. #if { $opt(lm) == "on" } {
  66. #    log-movement
  67. #}
  68. #global node setting
  69. $ns_ node-config -adhocRouting $opt(adhocRouting) 
  70.  -llType $opt(ll) 
  71.  -macType $opt(mac) 
  72.  -ifqType $opt(ifq) 
  73.  -ifqLen $opt(ifqlen) 
  74.  -antType $opt(ant) 
  75.  -propType $opt(prop) 
  76.  -phyType $opt(netif) 
  77.  -channelType $opt(chan) 
  78.  -topoInstance $topo 
  79.                  -diffusionFilter $opt(filters) 
  80.  -agentTrace ON 
  81.                  -routerTrace ON 
  82.                  -macTrace ON
  83.                   
  84. #  Create the specified number of nodes [$opt(nn)] and "attach" them
  85. #  to the channel. 
  86. for {set i 0} {$i < $opt(nn) } {incr i} {
  87. set node_($i) [$ns_ node $i]
  88.         $node_($i) color black
  89. $node_($i) random-motion 0 ;# disable random motion
  90.         $god_ new_node $node_($i)
  91. }
  92. puts "Loading connection pattern..."
  93. $node_(0) set X_ 18.587605569735
  94. $node_(0) set Y_ 401.886827012678
  95. $node_(0) set Z_ 0.000000000000
  96. $node_(1) set X_ 11.901958617639
  97. $node_(1) set Y_ 36.218497218617
  98. $node_(1) set Z_ 0.000000000000
  99. $node_(2) set X_ 224.282785411393
  100. $node_(2) set Y_ 20.774608253697
  101. $node_(2) set Z_ 0.000000000000
  102. $node_(3) set X_ 158.840938304009
  103. $node_(3) set Y_ 139.650216383776
  104. $node_(3) set Z_ 0.000000000000
  105. $node_(4) set X_ 101.186886005903
  106. $node_(4) set Y_ 147.993190973633
  107. $node_(4) set Z_ 0.000000000000
  108. $node_(5) set X_ 321.560825121175
  109. $node_(5) set Y_ 472.788096833600
  110. $node_(5) set Z_ 0.000000000000
  111. $node_(6) set X_ 149.543901734330
  112. $node_(6) set Y_ 384.356581531832
  113. $node_(6) set Z_ 0.000000000000
  114. $node_(7) set X_ 381.066146464027
  115. $node_(7) set Y_ 78.723958958779
  116. $node_(7) set Z_ 0.000000000000
  117. $node_(8) set X_ 113.578290026963
  118. $node_(8) set Y_ 410.320583900348
  119. $node_(8) set Z_ 0.000000000000
  120. $node_(9) set X_ 258.053977148981
  121. $node_(9) set Y_ 113.194171851670
  122. $node_(9) set Z_ 0.000000000000
  123. # 4 ping senders
  124. for {set i 0} {$i < $opt(sndr)} {incr i} {
  125.     set src_($i) [new Application/DiffApp/PingSender/TPP]
  126.     $ns_ attach-diffapp $node_([expr $i + 2]) $src_($i)
  127.     $ns_ at [expr 0.123 * $i] "$src_($i) publish"
  128. }
  129. # 1 ping receiver
  130. set snk_(0) [new Application/DiffApp/PingReceiver/TPP]
  131. $ns_ attach-diffapp $node_(9) $snk_(0)
  132. $ns_ at 1.456 "$snk_(0) subscribe"
  133. # Define node initial position in nam
  134. for {set i 0} {$i < $opt(nn)} {incr i} {
  135.     # 20 defines the node size in nam, must adjust it according to your scenario
  136.     # The function must be called after mobility model is defined
  137.     
  138.     $ns_ initial_node_pos $node_($i) 20
  139. }
  140. #
  141. # Tell nodes when the simulation ends
  142. #
  143. for {set i 0} {$i < $opt(nn) } {incr i} {
  144.     $ns_ at $opt(stop).000000001 "$node_($i) reset";
  145. }
  146. # tell nam the simulation stop time
  147. $ns_ at  $opt(stop) "$ns_ nam-end-wireless $opt(stop)"
  148. $ns_ at  $opt(stop).000000001 "puts "NS EXITING..." ; $ns_ halt"
  149. puts $tracefd "Directed Diffusion:2PP/5nodes/1sender/1rcvr"
  150. puts $tracefd "M 0.0 nn $opt(nn) x $opt(x) y $opt(y)"
  151. puts $tracefd "M 0.0 prop $opt(prop) ant $opt(ant)"
  152. puts "Starting Simulation..."
  153. $ns_ run