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

通讯编程

开发平台:

Visual C++

  1. # -*- Mode:tcl; tcl-indent-level:8; tab-width:8; indent-tabs-mode:t -*-
  2. #
  3. # Copyright (c) 2002 University of Southern California.
  4. # All rights reserved.                                            
  5. #                                                                
  6. # Redistribution and use in source and binary forms are permitted
  7. # provided that the above copyright notice and this paragraph are
  8. # duplicated in all such forms and that any documentation, advertising
  9. # materials, and other materials related to such distribution and use
  10. # acknowledge that the software was developed by the University of
  11. # Southern California, Information Sciences Institute.  The name of the
  12. # University may not be used to endorse or promote products derived from
  13. # this software without specific prior written permission.
  14. # THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
  15. # WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
  16. # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  17. # $Header: /cvsroot/nsnam/ns-2/tcl/test/test-suite-tagged-trace.tcl,v 1.8 2006/01/30 21:27:52 mweigle Exp $
  18. # FOR UPDATING GLOBAL DEFAULTS:
  19. Agent/TCP set precisionReduce_ false ;   # default changed on 2006/1/24.
  20. Agent/TCP set rtxcur_init_ 6.0 ;      # Default changed on 2006/01/21
  21. Agent/TCP set updated_rttvar_ false ;  # Variable added on 2006/1/21
  22. Mac/802_11 set bugFix_timer_ false;     # default changed 2006/1/30
  23. # This test suite is for validating the tagged trace format
  24. set opt(tr) "temp.rands"
  25. set opt(chan)         Channel/WirelessChannel  ;# channel type
  26. set opt(prop)         Propagation/TwoRayGround ;# radio-propagation model
  27. set opt(ant)          Antenna/OmniAntenna      ;# Antenna type
  28. set opt(ll)           LL                       ;# Link layer type
  29. set opt(ifq)          Queue/DropTail/PriQueue  ;# Interface queue type
  30. set opt(ifqlen)       50                       ;# max packet in ifq
  31. set opt(netif)        Phy/WirelessPhy          ;# network interface type
  32. set opt(mac)          Mac/802_11               ;# MAC type
  33. set opt(rp)           DSDV                     ;# ad-hoc routing protocol 
  34. Class TestSuite
  35. proc usage {} {
  36.         global argv0
  37.         puts stderr "usage: ns $argv0 <test> "
  38.         puts "Valid Tests: simple wireless Format-simple"
  39.         exit 1
  40. }
  41. proc runtest {arg} {
  42.         global quiet
  43.         set quiet 0
  44.  
  45.         set b [llength $arg]
  46.         if {$b == 1} {
  47.                 set test $arg
  48.         } elseif {$b == 2} {
  49.                 set test [lindex $arg 0]
  50.                 if {[lindex $arg 1] == "QUIET"} {
  51.                         set quiet 1
  52.                 }
  53.         } else {
  54.                 usage
  55.         }
  56.         set t [new Test/$test]
  57.         $t run
  58. }
  59. TestSuite instproc init {} {
  60.   global opt tracefd
  61.   $self instvar ns_
  62.   set ns_ [new Simulator]
  63.   $ns_ use-taggedtrace
  64.   set tracefd [open $opt(tr) w]
  65.   $ns_ trace-all $tracefd
  66. }
  67. TestSuite instproc finish {} {
  68.   $self instvar ns_ testName_
  69.   global quiet
  70.   $ns_ flush-trace
  71.   $ns_ halt
  72.  }
  73. # simple test
  74. #
  75. # Network topology:
  76. #
  77. #  A            E
  78. #             /
  79. #    ---C--D---
  80. #   /          
  81. #  B            F
  82. #
  83. # A->E ftp
  84. # B->F cbr
  85. #
  86. # C<->D link is lossy
  87. Class Test/simple -superclass TestSuite
  88. Test/simple instproc init {} {
  89.   $self instvar ns_ testName_
  90.   set testName_ simple
  91.   $self next
  92.   
  93.   set A [$ns_ node]
  94.   set B [$ns_ node]
  95.   set C [$ns_ node]
  96.   set D [$ns_ node]
  97.   set E [$ns_ node]
  98.   set F [$ns_ node]
  99.   $ns_ duplex-link $A $C 10Mb 5ms DropTail
  100.   $ns_ duplex-link $B $C 10Mb 5ms DropTail
  101.   $ns_ duplex-link $C $D 2Mb 20ms DropTail
  102.   $ns_ duplex-link $D $E 10Mb 5ms DropTail
  103.   $ns_ duplex-link $D $F 10Mb 5ms DropTail
  104.   # make the link between C and D drop 1% percent of the packets
  105.   set err [new ErrorModel]
  106.   $err drop-target [new Agent/Null] 
  107.   set rand [new RandomVariable/Uniform]
  108.   $rand set min_ 0
  109.   $rand set max_ 100
  110.   $err ranvar $rand
  111.   $err set rate_ 0.01
  112.   [$ns_ link $C $D] errormodule $err
  113.   # set up TCP flow from A to E
  114.   set tcp [new Agent/TCP]
  115.   set sink [new Agent/TCPSink]
  116.   $ns_ attach-agent $A $tcp
  117.   $ns_ attach-agent $E $sink
  118.   $ns_ connect $tcp $sink
  119.   set ftp [new Application/FTP]
  120.   $ftp attach-agent $tcp
  121.   # set up CBR flow from B to F
  122.   set udp [new Agent/UDP]
  123.   set null [new Agent/Null]
  124.   $ns_ attach-agent $B $udp
  125.   $ns_ attach-agent $F $null
  126.   $ns_ connect $udp $null
  127.   set cbr [new Application/Traffic/CBR]
  128.   $cbr set packetSize_ 500
  129.   $cbr set interval_ 0.005
  130.   $cbr attach-agent $udp
  131.   # set times to start/stop actions
  132.   $ns_ at 0.1 "$ftp start"
  133.   $ns_ at 0.2 "$cbr start"
  134.   $ns_ at 0.8 "$cbr stop"
  135.   $ns_ at 1.2 "$cbr start"
  136.   $ns_ at 1.8 "$cbr stop"
  137.   $ns_ at 1.9 "$ftp stop"
  138.   $ns_ at 2.0 "$self finish"
  139. }
  140. Test/simple instproc run {} {
  141.   $self instvar ns_
  142.   puts "Starting Simulation..."
  143.   $ns_ run
  144. }
  145. # wireless test
  146. #
  147. # A->B ftp
  148. # C->D cbr
  149. Class Test/wireless -superclass TestSuite
  150. Test/wireless instproc init {} {
  151.   global opt
  152.   $self instvar ns_ testName_
  153.   set testName_ simple
  154.   $self next
  155.   set topo [new Topography]
  156.   $topo load_flatgrid 100 100
  157.   create-god 4
  158.   $ns_ node-config -adhocRouting $opt(rp) 
  159.                    -llType $opt(ll) 
  160.                    -macType $opt(mac) 
  161.                    -ifqType $opt(ifq) 
  162.                    -ifqLen $opt(ifqlen) 
  163.                    -antType $opt(ant) 
  164.                    -propType $opt(prop) 
  165.                    -phyType $opt(netif) 
  166.                    -topoInstance $topo 
  167.                    -channel [new $opt(chan)] 
  168.                     -agentTrace ON 
  169.                     -routerTrace ON 
  170.                     -macTrace ON 
  171.                     -movementTrace OFF
  172.   set A [$ns_ node]
  173.   $A random-motion 0
  174.   $A set X_ 5.0
  175.   $A set Y_ 2.0
  176.   $A set Z_ 0.0
  177.   set B [$ns_ node]
  178.   $B random-motion 0
  179.   $B set X_ 15.0
  180.   $B set Y_ 15.0
  181.   $B set Z_ 0.0
  182.   set C [$ns_ node]
  183.   $C random-motion 0
  184.   $C set X_ 2.0
  185.   $C set Y_ 8.0
  186.   $C set Z_ 0.0
  187.   set D [$ns_ node]
  188.   $D random-motion 0
  189.   $D set X_ 10.0
  190.   $D set Y_ 1.0
  191.   $D set Z_ 0.0
  192.   # set up TCP flow from A to B
  193.   set tcp [new Agent/TCP]
  194.   set sink [new Agent/TCPSink]
  195.   $ns_ attach-agent $A $tcp
  196.   $ns_ attach-agent $B $sink
  197.   $ns_ connect $tcp $sink
  198.   set ftp [new Application/FTP]
  199.   $ftp attach-agent $tcp
  200.   # set up CBR flow from C to D
  201.   set udp [new Agent/UDP]
  202.   set null [new Agent/Null]
  203.   $ns_ attach-agent $C $udp
  204.   $ns_ attach-agent $D $null
  205.   $ns_ connect $udp $null
  206.   set cbr [new Application/Traffic/CBR]
  207.   $cbr set packetSize_ 500
  208.   $cbr set interval_ 0.005
  209.   $cbr attach-agent $udp
  210.   # set times to start/stop actions
  211.   $ns_ at 0.1 "$ftp start"
  212.   $ns_ at 0.2 "$cbr start"
  213.   $ns_ at 0.8 "$cbr stop"
  214.   $ns_ at 1.2 "$cbr start"
  215.   $ns_ at 1.8 "$cbr stop"
  216.   $ns_ at 1.9 "$ftp stop"
  217.   $ns_ at 2.0 "$self finish"
  218. }
  219. Test/wireless instproc run {} {
  220.   $self instvar ns_
  221.   puts "Starting Simulation..."
  222.   $ns_ run
  223. }
  224. # The following tests are for testing the file conversion utilities
  225. Class Test/Format-simple -superclass Test/simple
  226. Test/Format-simple instproc init {} {
  227.   global PERL
  228.   # check to make sure prereqs for file conversion are met
  229.   set foo [catch {exec $PERL -I../../bin -MNS::TraceFileEvent -MNS::TraceFileReader -MNS::TraceFileWriter -e exit 2>/dev/null}]
  230.   if [expr $foo != 0] then {
  231.     puts "Required Perl module not found, Format-simple test skipped."
  232.     exit 2
  233.   }
  234.   $self next
  235. }
  236. Test/Format-simple instproc run {} {
  237.   global opt PERL
  238.   # let parent class run ns
  239.   $self next
  240.   # now that ns is done, convert the output file
  241.   exec $PERL -I../../bin ../../bin/ns2oldns.pl < $opt(tr) > $opt(tr).tmp
  242.   exec cp $opt(tr).tmp $opt(tr)
  243. }
  244. # main program .. runs the test specified by the command line arguments
  245. global argv arg0
  246. runtest $argv