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

通讯编程

开发平台:

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. #
  7. # Copyright (c) 2001 University of Southern California.
  8. # All rights reserved.                                            
  9. #                                                                
  10. # Redistribution and use in source and binary forms are permitted
  11. # provided that the above copyright notice and this paragraph are
  12. # duplicated in all such forms and that any documentation, advertising
  13. # materials, and other materials related to such distribution and use
  14. # acknowledge that the software was developed by the University of
  15. # Southern California, Information Sciences Institute.  The name of the
  16. # University may not be used to endorse or promote products derived from
  17. # this software without specific prior written permission.
  18. # THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
  19. # WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
  20. # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  21. # $Header: /cvsroot/nsnam/ns-2/tcl/test/test-suite-snoop.tcl,v 1.8 2006/01/24 23:00:07 sallyfloyd Exp $
  22. # This test suite is for validating the snoop protocol
  23. remove-all-packet-headers       ; # removes all except common
  24. add-packet-header Flags IP TCP Snoop Arp LL Mac ; # hdrs reqd for validation
  25. # FOR UPDATING GLOBAL DEFAULTS:
  26. Agent/TCP set precisionReduce_ false ;   # default changed on 2006/1/24.
  27. Agent/TCP set rtxcur_init_ 6.0 ;      # Default changed on 2006/01/21
  28. Agent/TCP set updated_rttvar_ false ;  # Variable added on 2006/1/21
  29. Agent/TCP set minrto_ 1
  30. # default changed on 10/14/2004.
  31. Agent/TCP set singledup_ 0
  32. # The default is being changed to 1
  33. Agent/TCP set useHeaders_ false
  34. # The default is being changed to useHeaders_ true.
  35. # global options
  36. set opt(tr) temp.rands
  37. set opt(seed) 0
  38. set opt(qsize) 100
  39. set opt(ll) LL
  40. set opt(ifq) Queue/DropTail
  41. set opt(mac) Mac/802_3
  42. set opt(loss) 20
  43. Class TestSuite
  44. proc usage {} {
  45.         global argv0
  46.         puts stderr "usage: ns $argv0 <test> "
  47.         puts "Valid Tests: simple"
  48.         exit 1
  49. }
  50. proc runtest {arg} {
  51.         global quiet
  52.         set quiet 0
  53.  
  54.         set b [llength $arg]
  55.         if {$b == 1} {
  56.                 set test $arg
  57.         } elseif {$b == 2} {
  58.                 set test [lindex $arg 0]
  59.                 if {[lindex $arg 1] == "QUIET"} {
  60.                         set quiet 1
  61.                 }
  62.         } else {
  63.                 usage
  64.         }
  65.         set t [new Test/$test]
  66.         $t run
  67. }
  68. TestSuite instproc init {} {
  69.   global opt tracefd
  70.   $self instvar ns_
  71.   set ns_ [new Simulator]
  72.   set tracefd [open $opt(tr) w]
  73.   $ns_ trace-all $tracefd
  74. }
  75. TestSuite instproc finish {} {
  76.   $self instvar ns_ testName_
  77.   global quiet
  78.   $ns_ flush-trace
  79.   puts "finishing.."
  80.   exit 0
  81.  }
  82. # simple test
  83. #
  84. # Network topology:
  85. #
  86. #  A----B
  87. #      _|_(lan)  
  88. #       |
  89. #       C----D
  90. #
  91. # A sends data to destination D
  92. #
  93. # B is snoop agent.  The link between C and D is lossy.
  94. #
  95. # Why the extra node C between B and D?  Because it's easier to model
  96. # error on a point-to-point link than on a LAN in the current implementation.
  97. Class Test/simple -superclass TestSuite
  98. Test/simple instproc init {} {
  99.   global opt
  100.   $self instvar ns_ testName_
  101.   set testName_ simple
  102.   $self next
  103.   
  104.   set A [$ns_ node]
  105.   set B [$ns_ node]
  106.   set C [$ns_ node]
  107.   set D [$ns_ node]
  108.   $ns_ duplex-link $A $B 10Mb 5ms DropTail
  109.   $ns_ duplex-link $C $D 10Mb 5ms DropTail
  110.   set lan [$ns_ make-lan [list $C] 11Mb 2ms LL $opt(ifq) $opt(mac)]
  111.   $lan addNode [list $B] 11Mb 2ms LL/LLSnoop $opt(ifq) $opt(mac)
  112.   # make the link between C and D drop $opt(loss) percent of the packets
  113.   set err [new ErrorModel]
  114.   $err drop-target [new Agent/Null] 
  115.   set rand [new RandomVariable/Uniform]
  116.   $rand set min_ 0
  117.   $rand set max_ 100
  118.   $err ranvar $rand
  119.   $err set rate_ $opt(loss)
  120.   [$ns_ link $C $D] errormodule $err
  121.   # set up TCP flow from A to D
  122.   set tcp [new Agent/TCP]
  123.   set sink [new Agent/TCPSink]
  124.   $ns_ attach-agent $A $tcp
  125.   $ns_ attach-agent $D $sink
  126.   $ns_ connect $tcp $sink
  127.   set ftp [new Application/FTP]
  128.   $ftp attach-agent $tcp
  129.   # set times to start/stop actions
  130.   $ns_ at 0.1 "$ftp start"
  131.   $ns_ at 1.9 "$ftp stop"
  132.   $ns_ at 2.0 "$self finish"
  133. }
  134. Test/simple instproc run {} {
  135.   $self instvar ns_
  136.   puts "Starting Simulation..."
  137.   $ns_ run
  138. }
  139. global argv arg0
  140. runtest $argv