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

通讯编程

开发平台:

Visual C++

  1. # -*- Mode:tcl; tcl-indent-level:8; tab-width:8; indent-tabs-mode:t -*-
  2. Agent/TCP set tcpTick_ 0.1
  3. # The default for tcpTick_ is being changed to reflect a changing reality.
  4. Agent/TCP set rfc2988_ false
  5. # The default for rfc2988_ is being changed to true.
  6. # FOR UPDATING GLOBAL DEFAULTS:
  7. Agent/TCP set precisionReduce_ false ;   # default changed on 2006/1/24. Agent/TCP set rtxcur_init_ 6.0 ;      # Default changed on 2006/01/21 Agent/TCP set updated_rttvar_ false ;  # Variable added on 2006/1/21 Agent/TCP set minrto_ 1
  8. # default changed on 10/14/2004.
  9. Agent/TCP set useHeaders_ false
  10. # The default is being changed to useHeaders_ true.
  11. Agent/TCP set windowInit_ 1
  12. # The default is being changed to 2.
  13. Agent/TCP set singledup_ 0
  14. # The default is being changed to 1
  15. Mac/802_11 set bugFix_timer_ false;     # default changed 2006/1/30 #
  16. # Copyright (c) 1998 University of Southern California.
  17. # All rights reserved.                                            
  18. #                                                                
  19. # Redistribution and use in source and binary forms are permitted
  20. # provided that the above copyright notice and this paragraph are
  21. # duplicated in all such forms and that any documentation, advertising
  22. # materials, and other materials related to such distribution and use
  23. # acknowledge that the software was developed by the University of
  24. # Southern California, Information Sciences Institute.  The name of the
  25. # University may not be used to endorse or promote products derived from
  26. # this software without specific prior written permission.
  27. # THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
  28. # WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
  29. # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  30. # $Header: /cvsroot/nsnam/ns-2/tcl/test/test-suite-energy.tcl,v 1.15 2006/01/30 21:27:52 mweigle Exp $
  31. # To run all tests: test-all-energy
  32. # to run individual test:
  33. # ns test-suite-energy.tcl dsdv
  34. # ns test-suite-energy.tcl dsr
  35. # ns test-suite-energy.tcl aodv
  36. # ns test-suite-energy.tcl brdcast0
  37. # To view a list of available test to run with this script:
  38. # ns test-suite-energy.tcl
  39. # ======================================================================
  40. # Define options
  41. # ======================================================================
  42. global opt
  43. set opt(chan) Channel/WirelessChannel
  44. set opt(prop) Propagation/TwoRayGround
  45. set opt(netif) Phy/WirelessPhy
  46. set opt(mac) Mac/802_11
  47. set opt(ifq) Queue/DropTail/PriQueue
  48. set opt(ll) LL
  49. set opt(ant)            Antenna/OmniAntenna
  50. set opt(x) 670 ;# X dimension of the topography
  51. set opt(y) 670 ;# Y dimension of the topography
  52. set opt(cp) "cbr.tcl"
  53. set opt(sc) "mobility.tcl"
  54. set opt(ifqlen) 50 ;# max packet in ifq
  55. set opt(nn) 5 ;# number of nodes
  56. set opt(seed) 0.0
  57. set opt(stop) 500.0 ;# simulation time
  58. set opt(stop-newf)      700.0  ;# extended run time for new feature simulations
  59. set opt(tr) estudy.tr ;# trace file
  60. set opt(nam) temp.rands
  61. set opt(lm)             "off"           ;# log movement
  62. set opt(energymodel)    EnergyModel     ;
  63. set opt(initialenergy)  0.455               ;# Initial energy in Joules
  64. # ======================================================================
  65. # needs to be fixed later
  66. set AgentTrace ON
  67. set RouterTrace ON
  68. set MacTrace OFF
  69. LL set mindelay_ 50us
  70. LL set delay_ 25us
  71. LL set bandwidth_ 0 ;# not used
  72. Agent/Null set sport_ 0
  73. Agent/Null set dport_ 0
  74. Agent/CBR set sport_ 0
  75. Agent/CBR set dport_ 0
  76. Agent/TCPSink set sport_ 0
  77. Agent/TCPSink set dport_ 0
  78. Agent/TCP set sport_ 0
  79. Agent/TCP set dport_ 0
  80. Agent/TCP set packetSize_ 1460
  81. Queue/DropTail/PriQueue set Prefer_Routing_Protocols    1
  82. # unity gain, omni-directional antennas
  83. # set up the antennas to be centered in the node and 1.5 meters above it
  84. Antenna/OmniAntenna set X_ 0
  85. Antenna/OmniAntenna set Y_ 0
  86. Antenna/OmniAntenna set Z_ 1.5
  87. Antenna/OmniAntenna set Gt_ 1.0
  88. Antenna/OmniAntenna set Gr_ 1.0
  89. # Initialize the SharedMedia interface with parameters to make
  90. # it work like the 914MHz Lucent WaveLAN DSSS radio interface
  91. Phy/WirelessPhy set CPThresh_ 10.0
  92. Phy/WirelessPhy set CSThresh_ 1.559e-11
  93. Phy/WirelessPhy set RXThresh_ 3.652e-10
  94. Phy/WirelessPhy set Rb_ 2*1e6
  95. Phy/WirelessPhy set Pt_ 0.2818
  96. Phy/WirelessPhy set freq_ 914e+6 
  97. Phy/WirelessPhy set L_ 1.0
  98. # ======================================================================
  99. proc usage {}  {
  100.         global argv0
  101. puts stderr "usage: ns $argv0 <tests> "
  102. puts "Valid <tests> : dsdv dsr aodv brdcast0"
  103.         exit 1
  104. }
  105. proc getopt {argc argv} {
  106. global opt
  107. lappend optlist cp nn seed sc stop tr x y
  108. for {set i 0} {$i < $argc} {incr i} {
  109. set arg [lindex $argv $i]
  110. if {[string range $arg 0 0] != "-"} continue
  111. set name [string range $arg 1 end]
  112. set opt($name) [lindex $argv [expr $i+1]]
  113. }
  114. }
  115. Class TestSuite
  116. Class Test/brdcast0 -superclass TestSuite
  117. # 2 nodes brdcast req/replies to one another
  118. #This is a test for setting newly added features RADIO SLEEP MODE, Transition Energy Consumption, detailed energy trace
  119. Class Test/dsdv -superclass TestSuite
  120. Class Test/dsr -superclass TestSuite
  121. Class Test/aodv -superclass TestSuite
  122. TestSuite instproc init {} {
  123. global opt
  124. $self instvar ns_ topo  
  125. set ns_ [new Simulator]
  126. set topo [new Topography]
  127. set god_    [new God]
  128. set tracefd [open $opt(tr) w]
  129. set namtrace    [open $opt(nam) w]
  130. $topo load_flatgrid $opt(x) $opt(y)
  131. $ns_ trace-all $tracefd
  132. $ns_ namtrace-all-wireless $namtrace $opt(x) $opt(y)
  133. create-god $opt(nn)
  134. }
  135. TestSuite instproc finish {} {
  136.         $self instvar ns_
  137. global quiet
  138.         $ns_ flush-trace
  139.         if { !$quiet } {
  140.             puts "running nam..."
  141.             exec nam temp.rands &
  142.         }
  143.         exit 0
  144. }
  145. Test/brdcast0 instproc init {} {
  146.     global opt 
  147. #node_
  148. #    $self instvar ns_ topo
  149. #    set opt(chan)           Channel/WirelessChannel    ;# channel type
  150. #    set opt(prop)           Propagation/TwoRayGround   ;# radio-propagation model
  151. #    set opt(netif)          Phy/WirelessPhy            ;# network interface type
  152.     set opt(mac)            Mac/SMAC                   ;# MAC type
  153.     #set opt(mac)            Mac/802_11                 ;# MAC type
  154. #    set opt(ifq)            Queue/DropTail/PriQueue    ;# interface queue type
  155.     set opt(ll)             LL                         ;# link layer type
  156. #    set opt(ant)            Antenna/OmniAntenna        ;# antenna model
  157. #    set opt(ifqlen)         50                         ;# max packet in ifq
  158.     set opt(x)              800
  159.     set opt(y)              800
  160.     set opt(rp)             DumbAgent               ;# routing protocol
  161.     set opt(tr)             temp.rands
  162.  #   set opt(stop)           5.0
  163.  #   set opt(stop-sync)      100.0        ;# extended run time for sync simulations
  164.     set opt(stop)           700.0  ;# extended run time for new feature simulations
  165.     set opt(seed)           1
  166.  #   set opt(iP)           1.0 ;# IDLE Power
  167.  #   set opt(sP)           1.0 ;# SLEEP Power
  168.  #   set opt(tP)           1.0 ;# TRANS Power
  169.  #   set opt(rP)           1.0 ;# RECV Power
  170.  #   set opt(transT)       0.5 ;# TRANSITION Time
  171.  #   set opt(transP)       0.5 ;# TRANSITION Power
  172.     set opt(initialenergy)  1000     ;# Initial energy in Joules
  173.  #   set opt(energymodel)    EnergyModel     ;
  174.     set testname_ brdcast0
  175.    set opt(nn) 2
  176.   
  177.     create-god $opt(nn)
  178.  #   $self next
  179.     
  180.     
  181. }
  182. Test/brdcast0 instproc run {} {
  183.    global opt
  184.    $self instvar ns_ topo
  185. #   $self instvar ns_
  186.      set ns_         [new Simulator]
  187.       puts "Seeding Random number generator with $opt(seed)n"
  188.     ns-random $opt(seed)
  189.     
  190.     set tracefd_ [open $opt(tr) w]
  191.     $ns_ trace-all $tracefd_
  192.      set topo_     [new Topography]
  193.     $topo_ load_flatgrid $opt(x) $opt(y)
  194.     
  195.       $ns_ node-config -adhocRouting DumbAgent 
  196.  -llType $opt(ll) 
  197.  -macType Mac/SMAC 
  198.  -ifqType $opt(ifq) 
  199.  -ifqLen $opt(ifqlen) 
  200.  -antType $opt(ant) 
  201.  -propType $opt(prop) 
  202.  -phyType $opt(netif) 
  203.  -channelType $opt(chan) 
  204.  -topoInstance $topo_ 
  205.  -agentTrace ON 
  206.  -routerTrace ON 
  207.  -macTrace ON 
  208.  -energyModel $opt(energymodel) 
  209.  -idlePower 1.0 
  210.  -rxPower 1.0 
  211.  -txPower 2.0 
  212.             -sleepPower 0.001 
  213.             -transitionPower 0.2 
  214.             -transitionTime 0.005 
  215.  -initialEnergy $opt(initialenergy)
  216. Mac/SMAC set syncFlag_ 1
  217. Mac/SMAC set dutyCycle_ 10
  218. $ns_ set WirelessNewTrace_ ON
  219. for {set i 0} {$i < $opt(nn) } {incr i} {
  220. set node_($i) [$ns_ node]
  221. $node_($i) random-motion 0 ;# disable random motion
  222. }
  223. set udp_(0) [new Agent/UDP]
  224.      $ns_ attach-agent $node_(0) $udp_(0)
  225. set null_(0) [new Agent/Null]
  226. $ns_ attach-agent $node_(1) $null_(0)
  227. set cbr_(0) [new Application/Traffic/CBR]
  228. $cbr_(0) set packetSize_ 512
  229. $cbr_(0) set interval_ 10.0
  230. $cbr_(0) set random_ 1
  231. $cbr_(0) set maxpkts_ 50000
  232. $cbr_(0) attach-agent $udp_(0)
  233. $ns_ connect $udp_(0) $null_(0)
  234. $ns_ at 1.00 "$cbr_(0) start"
  235. #     $ns_ at 1.0 "$ping1 start-WL-brdcast"
  236. #
  237. # Tell all the nodes when the simulation ends
  238. #
  239. for {set i 0} {$i < $opt(nn) } {incr i} {
  240.     $ns_ at $opt(stop) "$node_($i) reset";
  241. }
  242. $ns_ at $opt(stop) "puts "NS EXITING...!!!" ; $ns_ halt"
  243. $ns_ run
  244. }
  245. Test/dsdv instproc init {} {
  246.    global opt
  247.    $self instvar ns_ topo
  248.    set opt(rp)             DSDV
  249.    $self next
  250. }
  251. Test/dsdv instproc run {} {
  252.    global opt
  253.    $self instvar ns_ topo
  254.         $ns_ node-config -adhocRouting $opt(rp) 
  255.  -llType $opt(ll) 
  256.  -macType $opt(mac) 
  257.  -ifqType $opt(ifq) 
  258.  -ifqLen $opt(ifqlen) 
  259.  -antType $opt(ant) 
  260.  -propType $opt(prop) 
  261.  -phyType $opt(netif) 
  262.  -channel [new $opt(chan)] 
  263.  -topoInstance $topo 
  264.  -energyModel $opt(energymodel) 
  265.  -macTrace ON 
  266.  -rxPower 0.3 
  267.  -txPower 0.6 
  268.  -initialEnergy $opt(initialenergy)
  269.  
  270. for {set i 0} {$i < $opt(nn) } {incr i} {
  271. set node_($i) [$ns_ node]
  272. $node_($i) random-motion 0 ;# disable random motion
  273. }
  274. #
  275. # Source the Connection and Movement scripts
  276. #
  277. if { $opt(cp) == "" } {
  278. puts "*** NOTE: no connection pattern specified."
  279.         set opt(cp) "none"
  280. } else {
  281. puts "Loading connection pattern..."
  282. source $opt(cp)
  283. }
  284. #
  285. # Tell all the nodes when the simulation ends
  286. #
  287. for {set i 0} {$i < $opt(nn) } {incr i} {
  288.     $ns_ at $opt(stop).000000001 "$node_($i) reset";
  289. }
  290. $ns_ at $opt(stop).00000001 "puts "NS EXITING..." ; $ns_ halt"
  291. if { $opt(sc) == "" } {
  292. puts "*** NOTE: no scenario file specified."
  293.         set opt(sc) "none"
  294. } else {
  295. puts "Loading scenario file..."
  296. source $opt(sc)
  297. puts "Load complete..."
  298. }
  299. # Define node initial position in nam
  300. for {set i 0} {$i < $opt(nn)} {incr i} {
  301.     # 20 defines the node size in nam, must adjust it according to your scenario
  302.     # The function must be called after mobility model is defined
  303.     $ns_ initial_node_pos $node_($i) 20
  304. }
  305. $ns_ run
  306. }
  307. Test/dsr instproc init {} {
  308.    global opt
  309.    $self instvar ns_ topo
  310.    set opt(rp)             DSR
  311.    set opt(ifq)            CMUPriQueue
  312.    $self next
  313. }
  314. Test/dsr instproc run {} {
  315.    global opt
  316.    $self instvar ns_ topo
  317.         $ns_ node-config -adhocRouting $opt(rp) 
  318.  -llType $opt(ll) 
  319.  -macType $opt(mac) 
  320.  -ifqType $opt(ifq) 
  321.  -ifqLen $opt(ifqlen) 
  322.  -antType $opt(ant) 
  323.  -propType $opt(prop) 
  324.  -phyType $opt(netif) 
  325.  -channel [new $opt(chan)] 
  326.  -topoInstance $topo 
  327.  -energyModel $opt(energymodel) 
  328.  -macTrace ON 
  329.  -rxPower 0.3 
  330.  -txPower 0.6 
  331.  -initialEnergy $opt(initialenergy)
  332.  
  333. for {set i 0} {$i < $opt(nn) } {incr i} {
  334. set node_($i) [$ns_ node]
  335. $node_($i) random-motion 0 ;# disable random motion
  336. }
  337. #
  338. # Source the Connection and Movement scripts
  339. #
  340. if { $opt(cp) == "" } {
  341. puts "*** NOTE: no connection pattern specified."
  342.         set opt(cp) "none"
  343. } else {
  344. puts "Loading connection pattern..."
  345. source $opt(cp)
  346. }
  347. #
  348. # Tell all the nodes when the simulation ends
  349. #
  350. for {set i 0} {$i < $opt(nn) } {incr i} {
  351.     $ns_ at $opt(stop).000000001 "$node_($i) reset";
  352. }
  353. $ns_ at $opt(stop).00000001 "puts "NS EXITING..." ; $ns_ halt"
  354. if { $opt(sc) == "" } {
  355. puts "*** NOTE: no scenario file specified."
  356.         set opt(sc) "none"
  357. } else {
  358. puts "Loading scenario file..."
  359. source $opt(sc)
  360. puts "Load complete..."
  361. }
  362. # Define node initial position in nam
  363. for {set i 0} {$i < $opt(nn)} {incr i} {
  364.     # 20 defines the node size in nam, must adjust it according to your scenario
  365.     # The function must be called after mobility model is defined
  366.     $ns_ initial_node_pos $node_($i) 20
  367. }
  368. $ns_ run
  369. }
  370. Test/aodv instproc init {} {
  371.    global opt
  372.    $self instvar ns_ topo
  373.    set opt(rp)             AODV
  374.    $self next
  375. }
  376. Test/aodv instproc run {} {
  377.    global opt
  378.    $self instvar ns_ topo
  379.         $ns_ node-config -adhocRouting $opt(rp) 
  380.  -llType $opt(ll) 
  381.  -macType $opt(mac) 
  382.  -ifqType $opt(ifq) 
  383.  -ifqLen $opt(ifqlen) 
  384.  -antType $opt(ant) 
  385.  -propType $opt(prop) 
  386.  -phyType $opt(netif) 
  387.  -channel [new $opt(chan)] 
  388.  -topoInstance $topo 
  389.  -energyModel $opt(energymodel) 
  390.  -macTrace ON 
  391.  -rxPower 0.3 
  392.  -txPower 0.6 
  393.  -initialEnergy $opt(initialenergy)
  394.  
  395. for {set i 0} {$i < $opt(nn) } {incr i} {
  396. set node_($i) [$ns_ node]
  397. $node_($i) random-motion 0 ;# disable random motion
  398. }
  399. #
  400. # Source the Connection and Movement scripts
  401. #
  402. if { $opt(cp) == "" } {
  403. puts "*** NOTE: no connection pattern specified."
  404.         set opt(cp) "none"
  405. } else {
  406. puts "Loading connection pattern..."
  407. source $opt(cp)
  408. }
  409. #
  410. # Tell all the nodes when the simulation ends
  411. #
  412. for {set i 0} {$i < $opt(nn) } {incr i} {
  413.     $ns_ at $opt(stop).000000001 "$node_($i) reset";
  414. }
  415. $ns_ at $opt(stop).00000001 "puts "NS EXITING..." ; $ns_ halt"
  416. if { $opt(sc) == "" } {
  417. puts "*** NOTE: no scenario file specified."
  418.         set opt(sc) "none"
  419. } else {
  420. puts "Loading scenario file..."
  421. source $opt(sc)
  422. puts "Load complete..."
  423. }
  424. # Define node initial position in nam
  425. for {set i 0} {$i < $opt(nn)} {incr i} {
  426.     # 20 defines the node size in nam, must adjust it according to your scenario
  427.     # The function must be called after mobility model is defined
  428.     $ns_ initial_node_pos $node_($i) 20
  429. }
  430. $ns_ run
  431. }
  432. proc runtest {arg} {
  433.         global quiet
  434.         set quiet 0
  435. set b [llength $arg]
  436. if {$b == 1} {
  437.         set test $arg
  438.         } elseif {$b == 2} {
  439.         set test [lindex $arg 0]
  440.             if {[lindex $arg 1] == "QUIET"} {
  441.         set quiet 1
  442.             }
  443.         } else {
  444.         usage
  445.         }
  446. switch $test {
  447.       brdcast0 -
  448. dsdv -
  449.        dsr -
  450. aodv {
  451.                      set t [new Test/$test]
  452.                 }
  453.                 default {
  454.              stderr "Unknown test $test"
  455.      exit 1
  456.                 }
  457.          }
  458.  $t run
  459. }
  460. global argv arg0 
  461. runtest $argv