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

通讯编程

开发平台:

Visual C++

  1. # Copyright (c) 2000 by the University of Southern California
  2. Agent/TCP set precisionReduce_ false ;   # default changed on 2006/1/24.
  3. Agent/TCP set rtxcur_init_ 6.0 ;      # Default changed on 2006/01/21
  4. Agent/TCP set updated_rttvar_ false ;  # Variable added on 2006/1/21
  5. # All rights reserved.
  6. #
  7. #  This program is free software; you can redistribute it and/or
  8. #  modify it under the terms of the GNU General Public License,
  9. #  version 2, as published by the Free Software Foundation.
  10. #
  11. #  This program is distributed in the hope that it will be useful,
  12. #  but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. #  GNU General Public License for more details.
  15. #
  16. #  You should have received a copy of the GNU General Public License along
  17. #  with this program; if not, write to the Free Software Foundation, Inc.,
  18. #  59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
  19. #
  20. #  The copyright of this module includes the following
  21. #  linking-with-specific-other-licenses addition:
  22. #
  23. #  In addition, as a special exception, the copyright holders of
  24. #  this module give you permission to combine (via static or
  25. #  dynamic linking) this module with free software programs or
  26. #  libraries that are released under the GNU LGPL and with code
  27. #  included in the standard release of ns-2 under the Apache 2.0
  28. #  license or under otherwise-compatible licenses with advertising
  29. #  requirements (or modified versions of such code, with unchanged
  30. #  license).  You may copy and distribute such a system following the
  31. #  terms of the GNU GPL for this module and the licenses of the
  32. #  other code concerned, provided that you include the source code of
  33. #  that other code when and as the GNU GPL requires distribution of
  34. #  source code.
  35. #
  36. #  Note that people who make modified versions of this module
  37. #  are not obligated to grant this special exception for their
  38. #  modified versions; it is their choice whether to do so.  The GNU
  39. #  General Public License gives permission to release a modified
  40. #  version without this exception; this exception also makes it
  41. #  possible to release a modified version which carries forward this
  42. #  exception.
  43. #
  44. # Yuan Li(USC/ISI)
  45. #
  46. #
  47. # run SMAC in a 10-nodes multihop network with DSR routing
  48. # remove-all-packet-headers       ; # removes all except common
  49. # add-packet-header Flags IP TCP Diffusion ARP LL Mac SR
  50. # hdrs reqd for validation test
  51. set opt(chan)           Channel/WirelessChannel
  52. set opt(prop)           Propagation/TwoRayGround
  53. set opt(netif)          Phy/WirelessPhy
  54. set opt(mac)            Mac/SMAC
  55. set opt(ifq)            Queue/DropTail/PriQueue
  56. set opt(ll)             LL
  57. set opt(ant)            Antenna/OmniAntenna
  58. set opt(x)              2000              ;# X dimension of the topography
  59. set opt(y)              2000               ;# Y dimension of the topography
  60. set opt(ifqlen)         50                ;# max packet in ifq
  61. set opt(seed)           0.0
  62. set opt(tr)             temp.rands        ;# trace file
  63. set opt(adhocRouting)   DSR
  64. set opt(filters)        GradientFilter
  65. set opt(nn)             10                ;# how many nodes are simulated
  66. set opt(stop)           1000.0            ;# simulation time
  67. set opt(syncFlag)       1                 ;# is set to 1 when SMAC uses sleep-wakeup cycle
  68. set opt(selfConfigFlag) 1                 ;# is set to 0 when SMAC uses user configurable schedule start time
  69. set val(initialenergy)  100
  70. set val(radiomodel)     Radio/Simple      ;# generic radio hardware
  71. set val(receivepower)   .5                ;# Receiving Power
  72. set val(transmitpower)  .5                ;# Transmitting Power
  73. set val(idlepower)      .05               ;# Idle Power
  74.                                                                                                                                                             
  75.                                                                                                                                                             
  76. # =====================================================================
  77. # Other default settings
  78.                                                                                                                                                             
  79. LL set mindelay_                50us
  80. LL set delay_                   25us
  81. LL set bandwidth_               0         ;
  82.                                                                                                                                                             
  83. Agent/Null set sport_           0
  84. Agent/Null set dport_           0
  85.                                                                                                                                                             
  86. Agent/CBR set sport_            0
  87. Agent/CBR set dport_            0
  88.                                                                                                                                                             
  89. Agent/TCPSink set sport_        0
  90. Agent/TCPSink set dport_        0
  91.                                                                                                                                                             
  92. Agent/TCP set sport_            0
  93. Agent/TCP set dport_            0
  94. Agent/TCP set packetSize_       512
  95.                                                                                                                                                             
  96. Queue/DropTail/PriQueue set Prefer_Routing_Protocols    1
  97.                                                                                                                                                             
  98. # unity gain, omni-directional antennas
  99. # set up the antennas to be centered in the node and 1.5 meters above it
  100. Antenna/OmniAntenna set X_ 0
  101. Antenna/OmniAntenna set Y_ 0
  102. Antenna/OmniAntenna set Z_ 1.5
  103. Antenna/OmniAntenna set Gt_ 1.0
  104. Antenna/OmniAntenna set Gr_ 1.0
  105.                                                                                                                                                             
  106. # Initialize the SharedMedia interface with parameters to make
  107. # it work like the 914MHz Lucent WaveLAN DSSS radio interface
  108. Phy/WirelessPhy set CPThresh_ 10.0
  109. Phy/WirelessPhy set CSThresh_ 1.559e-11
  110. Phy/WirelessPhy set RXThresh_ 3.652e-10
  111. Phy/WirelessPhy set Rb_ 2*1e6
  112. Phy/WirelessPhy set Pt_ 0.2818
  113. Phy/WirelessPhy set freq_ 914e+6
  114. Phy/WirelessPhy set L_ 1.0
  115.                                                                                                                                                             
  116. # SMAC settings
  117. Mac/SMAC set syncFlag_ 1        ; # sleep wakeup cycles
  118. Mac/SMAC set SMAC_DUTY_CYCLE 10
  119. ErrorModel set rate_ 0.1
  120.                                                                                                                                                             
  121. proc UniformErrorProc {} {
  122.     global opt
  123.                                                                                                                                                             
  124.     set errObj [new ErrorModel]
  125.     $errObj unit packet
  126.     return $errObj
  127. }
  128.                                                                                                                                                             
  129. Class TestSuite
  130. Class Test/smac-multihop -superclass TestSuite
  131. proc usage {} {
  132.     global argv0
  133.     puts stderr "usage: ns $argv0 <tests>"
  134.     puts "Valid tests: smac-multihop"
  135. }
  136. Test/smac-multihop instproc init {} {
  137.                        
  138.     global opt                                                                                                                                      
  139. # create simulator instance
  140.     $self instvar ns_ 
  141.     set ns_ [new Simulator]
  142.                                                                                                                                                             
  143. # set wireless topography object
  144.     $self instvar wtopo
  145.     set wtopo [new Topography]
  146.                                                                                                                                                             
  147. # create trace object for ns
  148.     $self instvar tracefd
  149.     set tracefd [open $opt(tr) w]
  150.                                                                                                                                                             
  151.     $ns_ trace-all $tracefd
  152.                                                                                                                                                             
  153. # define topology
  154.     $wtopo load_flatgrid $opt(x) $opt(y)
  155.                                                                                                                                                             
  156. #
  157. # Create God
  158. #
  159.     $self instvar god_
  160.     set god_ [create-god $opt(nn)]
  161.                                                                                                                                                             
  162. #
  163. # define how node should be created
  164. #
  165.                                                                                                                                                             
  166. # node setting
  167.                                                                                                                                                             
  168.     $ns_ node-config -adhocRouting $opt(adhocRouting) 
  169.                  -llType $opt(ll) 
  170.                  -macType $opt(mac) 
  171.                  -ifqType $opt(ifq) 
  172.                  -ifqLen $opt(ifqlen) 
  173.                  -antType $opt(ant) 
  174.                  -propType $opt(prop) 
  175.                  -phyType $opt(netif) 
  176.                  -channelType $opt(chan) 
  177.                  -topoInstance $wtopo 
  178.                  -diffusionFilter $opt(filters) 
  179.                  -agentTrace ON 
  180.                  -routerTrace ON 
  181.                  -macTrace ON
  182.                #  -energyModel "EnergyModel" 
  183.                #  -initialEnergy $val(initialenergy) 
  184.                #  -rxPower $val(receivepower) 
  185.                #  -txPower $val(transmitpower) 
  186.                #  -idlePower $val(idlepower)
  187.                                                                                                                                                             
  188. #
  189. #  Create the specified number of nodes [$opt(nn)] and "attach" them
  190. #  to the channel.
  191.                                                                                                                                                             
  192.     for {set i 0} {$i < $opt(nn) } {incr i} {
  193.         set node_($i) [$ns_ node $i]
  194.         $node_($i) random-motion 0          ;# disable random motion
  195.     }
  196. #
  197. #  Create DSR Agent
  198. #  rt_rq_max_period indicates maximum time between rt reqs
  199. #  rt_rq_period indicates length of one backoff period
  200. #  send_timeout indicates how long a packet can live in sendbuf
  201. for {set i 0} {$i < $opt(nn)} {incr i} {
  202.     set dsr($i) [new Agent/DSRAgent]
  203.     $dsr($i)  node $node_($i)
  204.     $dsr($i) rt_rq_max_period 100
  205.     $dsr($i) rt_rq_period 30
  206.     $dsr($i) send_timeout 300
  207. }
  208. #
  209. #  Create the topology
  210. #
  211.                                                                                                                                                             
  212. $node_(0) set Z_ 0.0
  213. $node_(0) set Y_ 50.0
  214. $node_(0) set X_ 100.0
  215. $node_(1) set Z_ 0.0
  216. $node_(1) set Y_ 250.0
  217. $node_(1) set X_ 100.0
  218. $node_(2) set Z_ 0.0
  219. $node_(2) set Y_ 450.0
  220. $node_(2) set X_ 100.0
  221. $node_(3) set Z_ 0.0
  222. $node_(3) set Y_ 650.0
  223. $node_(3) set X_ 100.0
  224. $node_(4) set Z_ 0.0
  225. $node_(4) set Y_ 850.0
  226. $node_(4) set X_ 100.0
  227. $node_(5) set Z_ 0.0
  228. $node_(5) set Y_ 1050.0
  229. $node_(5) set X_ 100.0
  230. $node_(6) set Z_ 0.0
  231. $node_(6) set Y_ 1250.0
  232. $node_(6) set X_ 100.0
  233. $node_(7) set Z_ 0.0
  234. $node_(7) set Y_ 1450.0
  235. $node_(7) set X_ 100.0
  236. $node_(8) set Z_ 0.0
  237. $node_(8) set Y_ 1650.0
  238. $node_(8) set X_ 100.0
  239. $node_(9) set Z_ 0.0
  240. $node_(9) set Y_ 1850.0
  241. $node_(9) set X_ 100.0
  242.                                                                                                                                                             
  243. #
  244. # Define traffic model
  245. #
  246. puts "Loading connection pattern..."
  247.                                                                                                                                                             
  248. set udp_(0) [new Agent/UDP]
  249. $ns_ attach-agent $node_(0) $udp_(0)
  250. set null_(0) [new Agent/Null]
  251. $ns_ attach-agent $node_(9) $null_(0)
  252. set cbr_(0) [new Application/Traffic/CBR]
  253. $cbr_(0) set packetSize_ 50
  254. # Interval is measured in seconds
  255. $cbr_(0) set interval_ 200
  256. $cbr_(0) set random_ 1
  257. $cbr_(0) set maxpkts_ 10000
  258. $cbr_(0) set fid_ 0
  259. $cbr_(0) attach-agent $udp_(0)
  260. $ns_ connect $udp_(0) $null_(0)
  261. $ns_ at 100.0 "$cbr_(0) start"
  262.                                                                                                                                                             
  263. #
  264. # Tell nodes when the simulation ends
  265. #
  266. for {set i 0} {$i < $opt(nn) } {incr i} {
  267.     $ns_ at $opt(stop).000000001 "$node_($i) reset";
  268. }
  269.                                                                                                                                                             
  270. $ns_ at  $opt(stop).000000001 "puts "NS EXITING..." ; $ns_ halt"
  271. }
  272. Test/smac-multihop instproc run {} {
  273.     $self instvar ns_
  274.     puts "Starting Simulation..."
  275.     $ns_ run
  276. }
  277. proc runtest {arg} {
  278.                                                                                                                                                             
  279.     set b [llength $arg]
  280.     if {$b == 1} {
  281.         set test $arg
  282.     } else {
  283.         usage
  284.     }
  285.     set test "smac-multihop"
  286.     set t [new Test/$test]
  287.     $t run
  288. }
  289.                                                                                                                                                             
  290. runtest $argv