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

通讯编程

开发平台:

Visual C++

  1. source misc_simple.tcl
  2. remove-all-packet-headers       ; # removes all except common
  3. add-packet-header Flags IP TCP  ; # hdrs reqd for TCP
  4. # FOR UPDATING GLOBAL DEFAULTS:
  5. Agent/TCP set precisionReduce_ false ;   # default changed on 2006/1/24.
  6. Agent/TCP set rtxcur_init_ 6.0 ;      # Default changed on 2006/01/21
  7. Agent/TCP set updated_rttvar_ false ;  # Variable added on 2006/1/21
  8. Agent/TCP set tcpTick_ 0.1
  9. # The default for tcpTick_ is being changed to reflect a changing reality.
  10. Agent/TCP set minrto_ 1
  11. # default changed on 10/14/2004.
  12. Agent/TCP set useHeaders_ false
  13. # The default is being changed to useHeaders_ true.
  14. Agent/TCP set syn_ false
  15. Agent/TCP set delay_growth_ false
  16. # In preparation for changing the default values for syn_ and delay_growth_.
  17. Agent/TCP set rfc2988_ false
  18. Agent/TCP set windowInit_ 1
  19. Agent/TCP set singledup_ 0
  20. Agent/TCP set minrto_ 0
  21. Trace set show_tcphdr_ 1
  22. set wrap 90
  23. set wrap1 [expr 90 * 512 + 40]
  24. Class Topology
  25. Topology instproc node? num {
  26.     $self instvar node_
  27.     return $node_($num)
  28. }
  29. Class Topology/net8 -superclass Topology
  30. Topology/net8 instproc init ns {
  31.     $self instvar node_
  32.     set node_(s1) [$ns node]
  33.     set node_(r1) [$ns node]
  34.     set node_(k1) [$ns node]
  35.     set node_(k2) [$ns node]
  36.     set node_(k3) [$ns node]
  37.     set node_(k4) [$ns node]
  38.     set node_(k5) [$ns node]
  39.     set node_(k6) [$ns node]
  40.     set node_(r2) [$ns node]
  41.     set node_(d1) [$ns node]
  42.     $self next
  43.     $ns duplex-link $node_(s1)   $node_(r1)  10Mb        2ms    DropTail 
  44.     $ns duplex-link $node_(r1)   $node_(k1)  256Kb       10ms    DropTail
  45.     $ns duplex-link $node_(k1)   $node_(k2)  256Kb       10ms    DropTail
  46.     $ns duplex-link $node_(k2)   $node_(k3)  256Kb       10ms    DropTail
  47.     $ns duplex-link $node_(k3)   $node_(k4)  256Kb       10ms    DropTail
  48.     $ns duplex-link $node_(k4)   $node_(k5)  256Kb       10ms    DropTail
  49.     $ns duplex-link $node_(k5)   $node_(k6)  256Kb       10ms    DropTail
  50.     $ns duplex-link $node_(k6)   $node_(r2)  256Kb       10ms    DropTail
  51.     $ns duplex-link $node_(r2)   $node_(d1)  10Mb        2ms    DropTail
  52.     $ns duplex-link-op $node_(r1) $node_(k1) queuePos 0.5
  53.     $ns queue-limit $node_(r1) $node_(k1) 30
  54.     set qmon [$ns monitor-queue $node_(r1) $node_(k1) 1 2]
  55. }
  56. Class Topology/net7 -superclass Topology
  57. Topology/net7 instproc init ns {
  58.     $self instvar node_
  59.     set node_(s1) [$ns node]
  60.     set node_(r1) [$ns node]
  61.     set node_(k1) [$ns node]
  62.     
  63.     $self next
  64.     $ns duplex-link $node_(s1) $node_(r1) 1Mb 10s DropTail
  65.     $ns duplex-link $node_(r1) $node_(k1) 0.9Mb 100ms DropTail
  66.     
  67.     $ns duplex-link-op $node_(s1) $node_(r1) orient right-down
  68.     $ns duplex-link-op $node_(r1) $node_(k1) orient right
  69.     $ns duplex-link-op $node_(r1) $node_(k1) queuePos 0.5
  70.     $ns queue-limit $node_(r1) $node_(k1) 4000
  71.     set qmon [$ns monitor-queue $node_(r1) $node_(k1)  1 2]
  72. }
  73. Class Topology/net6 -superclass Topology
  74. Topology/net6 instproc init ns {
  75.     $self instvar node_
  76.     set node_(s1) [$ns node]
  77.     set node_(r1) [$ns node]
  78.     set node_(k1) [$ns node]
  79.     
  80.     $self next
  81.     $ns duplex-link $node_(s1) $node_(r1) 1Mb 100ms DropTail
  82.     $ns duplex-link $node_(r1) $node_(k1) 10Mb 10ms DropTail
  83.     
  84.     $ns duplex-link-op $node_(s1) $node_(r1) orient left-right
  85.     $ns duplex-link-op $node_(r1) $node_(k1) orient right
  86.     $ns duplex-link-op $node_(r1) $node_(k1) queuePos 0.5
  87.     $ns queue-limit $node_(r1) $node_(k1) 4000
  88.     set qmon [$ns monitor-queue $node_(r1) $node_(k1)  1 2]
  89.     lappend drops 60
  90.     set loss_module [new ErrorModel/List]
  91.     $loss_module droplist $drops
  92.     $loss_module drop-target [new Agent/Null]
  93.     $ns lossmodel $loss_module $node_(r1) $node_(k1)
  94. }
  95. Class Topology/net5 -superclass Topology
  96. Topology/net5 instproc init ns {
  97.     $self instvar node_
  98.     set node_(s1) [$ns node]
  99.     set node_(s2) [$ns node]
  100.     set node_(r1) [$ns node]
  101.     set node_(k1) [$ns node]
  102.     set node_(s3) [$ns node]   
  103.     
  104.     $self next
  105.     $ns duplex-link $node_(s1) $node_(r1) 1Mb 100ms DropTail
  106.     $ns duplex-link $node_(s2) $node_(r1) 1Mb 100ms DropTail
  107.     $ns duplex-link $node_(s3) $node_(r1) 1Mb 100ms DropTail
  108.     $ns duplex-link $node_(r1) $node_(k1) 0.5Mb 100ms DropTail
  109.     
  110.     $ns duplex-link-op $node_(s1) $node_(r1) orient right-down
  111.     $ns duplex-link-op $node_(s2) $node_(r1) orient right
  112.     $ns duplex-link-op $node_(s3) $node_(r1) orient right-up
  113.     $ns duplex-link-op $node_(r1) $node_(k1) orient right
  114.     $ns duplex-link-op $node_(r1) $node_(k1) queuePos 0.5
  115.     $ns queue-limit $node_(r1) $node_(k1) 200
  116.     set qmon [$ns monitor-queue $node_(r1) $node_(k1)  1 2]
  117. }
  118. TestSuite instproc finish testname {
  119.     global quiet wrap PERL 
  120.     $self instvar trace_
  121.     
  122.     if {$testname == "rtt-rfc793" || $testname == "rtt-jacobson"} {
  123. close $trace_(rto)
  124.         close $trace_(rtt)
  125. exec cp rtt.tr temp.rands
  126. if {$quiet == "false"} {
  127.     exec xgraph -x time -y "rtt,rto values"  rtt.tr rto.tr &
  128. }
  129.     } 
  130.     if {$testname == "rto-karn" || $testname == "rto-nokarn"} {
  131. close $trace_(srtt)
  132. exec cp srtt.tr temp.rands
  133. if {$quiet == "false"} {
  134.     exec xgraph  -x time -y "Estimated RTT"  srtt.tr &
  135. }
  136.     }
  137.     if {$testname == "seqno-fastrtx" || $testname == "seqno-nofastrtx" || $testname == "rto-karn" || $testname == "rto-nokarn"} {
  138.         exec $PERL ../../bin/getrc -s 1 -d 2 all.tr | 
  139. $PERL ../../bin/raw2xg -a -e -s 0.01 -m 10000000 -t $testname > temp.rands
  140.         if {$quiet == "false"} {
  141.     exec xgraph -bb -tk -nl -m -x time -y packets temp.rands &
  142. }
  143.     } 
  144.     if {$testname == "jacobson88-noss" || $testname ==
  145.     "jacobson88-ss"} {
  146. exec awk {
  147.                 {
  148.                         if (($1 == "+") && ($5 == "tcp") &&
  149.                             ($3 == "0") && ($4 == "1"))
  150.                                         print $2, $11
  151.                 }
  152.         } all.tr > out.seq
  153. exec cp out.seq temp.rands
  154. if {$quiet == "false"} {
  155.          exec xgraph -P out.seq & 
  156. }
  157.     }
  158.     
  159.     if {$quiet == "false"} {
  160.      exec nam all.nam &
  161.     }
  162.     exit 0
  163. }  
  164. TestSuite instproc printtimers { tcp time} {
  165.     global quiet
  166.     if {$quiet == "false"} {
  167. puts "time: $time sRTT(in ticks): [$tcp set srtt_]/8 RTTvar(in ticks): [$tcp set rttvar_]/4 backoff: [$tcp set backoff_]"
  168.     }
  169. }
  170. TestSuite instproc printtimersAll { tcp time interval } {
  171.     $self instvar dump_inst_ ns_
  172.     if ![info exists dump_inst_($tcp)] {
  173. set dump_inst_($tcp) 1
  174. $ns_ at $time "$self printtimersAll $tcp $time $interval"
  175. return
  176.     }
  177.     set newTime [expr [$ns_ now] + $interval]
  178.     $ns_ at $time "$self printtimers $tcp $time"
  179.     $ns_ at $newTime "$self printtimersAll $tcp $newTime $interval"
  180. }
  181. ## 
  182. TestSuite instproc setup {tcptype list} {
  183.     global wrap wrap1 quiet
  184.     $self instvar ns_ node_ testName_ guide_
  185.     $self setTopo
  186.     puts "Guide: $guide_"
  187.     
  188.     $ns_ color 1 Red
  189.     $ns_ color 2 Green
  190.     $ns_ color 3 Blue
  191.     $ns_ color 4 Yellow
  192.     set fid 1
  193.     # Set up TCP connection
  194.     if {$tcptype == "rtt-jacobson" || $tcptype == "rtt-rfc793"} {
  195. $self instvar trace_
  196. set trace_(rtt) [open "rtt.tr" w]
  197. set trace_(rto) [open "rto.tr" w]
  198. if {$quiet == "false"} {
  199. puts ""
  200. puts "                    RTT Test."
  201. puts "------------------------------------------------------------------------"
  202. puts "    s1 1Mb"
  203. puts "      \             - s1 implements RFC793 estimation or Jacobson's"
  204. puts "  1MB  \  0.5Mb     - s1 tx to k; at 1.5 both s2 and s3 tx big pkts for 1sec;"
  205. puts "    s2--r-------k    - nobody performs slowstart."
  206. puts "       /             - The queue in r grows fast and so does the RTT seen by s1."
  207. puts "      /1Mb           RFC793 RTO estimation can't adapt to the variance peak."
  208. puts "    s3               When the situation becomes normal again, RFC793 estimates"
  209. puts "                     RTO too pessimistically."
  210. }
  211. set tcp1 [$ns_ create-connection TCP/RFC793edu $node_(s1) 
  212. TCPSink $node_(k1) 1]
  213. set tcp2 [$ns_ create-connection TCP/RFC793edu $node_(s2) 
  214. TCPSink $node_(k1) 2]
  215. set tcp3 [$ns_ create-connection TCP/RFC793edu $node_(s3) 
  216. TCPSink $node_(k1) 3]
  217. set ftp1 [$tcp1 attach-app FTP]
  218. set ftp2 [$tcp2 attach-app FTP]
  219. set ftp3 [$tcp3 attach-app FTP]
  220. $tcp1 set window_ 50
  221. $tcp2 set packetSize_ 2000
  222. $tcp3 set packetSize_ 2000
  223. if {$tcptype == "rtt-jacobson"} { 
  224.     $tcp1 set add793jacobsonrtt_ true
  225. }
  226. $ns_ at 0.0  "$self plotrto $tcp1 0.25"
  227. $ns_ at 0.5  "$ftp1 start"
  228. $ns_ at 1.5  "$ftp2 start"
  229. $ns_ at 1.5  "$ftp3 start"
  230. $ns_ at 2.5 "$ftp2 stop"
  231. $ns_ at 2.5 "$ftp3 stop"
  232. ##$self traceQueues $node_(r1) [$self openTrace 20.0 $testName_]
  233. $ns_ at 20.0 "$self cleanupAll $testName_"
  234.     }
  235. ################################## seqno-{fastrtx, nofastrtx}
  236.     if {$tcptype == "seqno-fastrtx" || $tcptype == "seqno-nofastrtx" } {
  237. if {$quiet == "false"} {
  238. puts ""
  239. puts "                      Fast Retransmit"
  240. puts "------------------------------------------------------------------------"
  241. puts "         10Mb        - r1: Tahoe with/without fastrtx"
  242. puts " s1----r1----k1      - r1 tx to k1"
  243. puts "         10ms        - pkt 60 is dropped"
  244. puts ""
  245. puts "Without fast rtx., the source runs out of window and has to wait for a"
  246. puts "timeout to force the retransmission of the lost packet and the associated"
  247. puts "acknowledgement to open the window again."
  248. }
  249. $self instvar trace_
  250. set trace_(seqn) [open "seqn.tr" w]
  251. set tcp1 [$ns_ create-connection TCP/RFC793edu $node_(r1) 
  252. TCPSink $node_(k1) 1]
  253. set ftp1 [$tcp1 attach-app FTP]
  254. #$tcp1 set window_ 40
  255. if {$tcptype == "seqno-fastrtx"} {$tcp1 set add793fastrtx_ true}
  256. $tcp1 set add793expbackoff_ true
  257. $tcp1 set add793karnrtt_ true
  258. $tcp1 set add793jacobsonrtt_ true
  259. $tcp1 set add793slowstart_ true
  260. $ns_ at 0.5 "$ftp1 produce 100000"
  261. #$self traceQueues $node_(r1) [$self openTrace 1.25 $testName_]
  262. $ns_ at 1.25 "$self cleanupAll $testName_"
  263.     }
  264. ################################## rto-{karn, nokarn}
  265. if {$tcptype == "rto-karn" || $tcptype == "rto-nokarn" } {
  266. $self instvar trace_
  267. set trace_(srtt) [open "srtt.tr" w]
  268.     
  269. if {$quiet == "false"} {
  270. puts ""
  271. puts "Karn Algorithm --- (Karn's RTT sampling + RTO Exponential Binary Backoff)" 
  272. puts "------------------------------------------------------------------------"
  273. puts "   1Mb   0.9Mb        - s1 is a Tahoe source, (nokarn: without Karn's A.)"
  274. puts " s1----r1----k1       - s1 tx; ack does not arrive, so s1 rtx;"
  275. puts "    ^^                  if using karn, it will space exponentially"
  276. puts "  delay 10s!!           the retx"
  277. puts "                      - a packet will be rtx around t=18s; ack for the"
  278. puts "                        first pkt sent arrives at t=20s; if Karn's"
  279. puts "                        is not used, then we the RTT estimation is 2s!!"
  280. }
  281. set tcp1 [$ns_ create-connection TCP/RFC793edu $node_(s1) 
  282. TCPSink $node_(k1) 1]
  283. set ftp1 [$tcp1 attach-app FTP]
  284. $tcp1 set window_ 28
  285. if {$tcptype == "rto-karn"} {
  286. $tcp1 set add793karnrtt_ true
  287. $tcp1 set add793expbackoff_ true
  288. } else {
  289. $tcp1 set add793karnrtt_ false 
  290.                 $tcp1 set add793expbackoff_ false
  291. }
  292. $tcp1 set add793fastrtx_ true
  293. $tcp1 set add793jacobsonrtt_ false
  294. $tcp1 set add793slowstart_ true
  295. $ns_ at 0.0  "$self plotsrtt $tcp1 0.25"
  296. $ns_ at 0.5 "$ftp1 produce 100000"
  297. #$self traceQueues $node_(r1) [$self openTrace 50.0 $testName_]
  298. $ns_ at 50.0 "$self cleanupAll $testName_"
  299. }
  300. ##################################  jacobson88-noss
  301. if {$tcptype == "jacobson88-noss" || $tcptype == "jacobson88-ss" } {
  302. if {$quiet == "false"} {
  303. puts ""
  304. puts "Congestion avoidance and control" 
  305. puts "------------------------------------------------------------------------"
  306. puts ""
  307. puts " s1---r1---n1---n2---n3---n4---n5---n6---n7---n8---r2---d1"
  308. puts "    ^    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^    ^"
  309. puts " (10Mb,2ms)      (256Kb,10ms) all these links      (10Mb,2ms)"
  310. puts ""
  311. puts "Experiment based on Jacobson's SIGCOMM'88 paper:"
  312. puts "- s1 uses a 32 pkt's tx. window and Karn's algorithm"
  313. puts "- s1 performs slow-start (ss) or not (noss)"
  314. puts "- r1 has capacity for 30 packets only"
  315. puts "- the 8 hops have capacity for a complete window, but r1 not" 
  316. puts ""
  317. }
  318. set tcp1 [$ns_ create-connection TCP/RFC793edu $node_(s1) 
  319. TCPSink $node_(d1) 1]
  320. set ftp1 [$tcp1 attach-app FTP]
  321. $tcp1 set window_ 32
  322. $tcp1 set packetSize_ 512 
  323. $tcp1 set add793karnrtt_ true
  324. $tcp1 set add793expbackoff_ true
  325. if {$tcptype == "jacobson88-ss"} {
  326. $tcp1 set add793slowstart_ true
  327. }
  328. $ns_ at 0.0 "$ftp1 start"
  329. #$self traceQueues $node_(r1) [$self openTrace 10.0 $testName_]
  330. $ns_ at 10.0 "$self cleanupAll $testName_"
  331. }
  332.     
  333.     #$self tcpDump $tcp1 1.0
  334.     
  335.     
  336.     $ns_ run
  337. }
  338. TestSuite instproc plotseqn { tcp interval} {
  339.     $self instvar trace_ ns_  
  340.     set now [$ns_ now]
  341.     puts $trace_(seqn) "$now [$tcp set seqno_]"
  342.     $ns_ at [expr $now+$interval] "$self plotseqn $tcp $interval"
  343. }
  344. TestSuite instproc plotrto { tcp interval} {
  345.     $self instvar trace_ ns_  
  346.     set now [$ns_ now]
  347.     puts $trace_(rto) "$now [expr [$tcp set tcpTick_] *[$tcp set rto_]]"
  348.     puts $trace_(rtt) "$now [expr [$tcp set tcpTick_] *[$tcp set rtt_]]"
  349.     $ns_ at [expr $now+$interval] "$self plotrto $tcp $interval"
  350. }
  351. TestSuite instproc plotsrtt { tcp interval} {
  352.     $self instvar trace_ ns_  
  353.     set now [$ns_ now]
  354.     puts $trace_(srtt) "$now [expr [$tcp set tcpTick_] * ( [$tcp set srtt_] >> [$tcp set T_SRTT_BITS])]"
  355.     $ns_ at [expr $now+$interval] "$self plotsrtt $tcp $interval"
  356. }
  357. # Definition of test-suite tests
  358. ########## Jacobson/RFC793 RTT
  359. Class Test/rtt-jacobson -superclass TestSuite
  360. Test/rtt-jacobson instproc init {} {
  361.     $self instvar net_ test_ guide_ 
  362.     set net_ net5
  363.     set test_   rtt-jacobson
  364.     set guide_  "Van Jacobson RTO estimation."
  365.     $self next
  366. }
  367. Test/rtt-jacobson instproc run {} {
  368.     $self setup rtt-jacobson {}
  369. }
  370. Class Test/rtt-rfc793 -superclass TestSuite
  371. Test/rtt-rfc793 instproc init {} {
  372.     $self instvar net_ test_ guide_ 
  373.     set net_ net5
  374.     set test_       rtt-rfc793
  375.     set guide_  "RFC 793 RTO estimation."
  376.     $self next
  377. }
  378. Test/rtt-rfc793 instproc run {} {
  379.     $self setup rtt-rfc793 {}
  380. }
  381.  
  382. ########## Arrival rate with/without fast rtx
  383. Class Test/seqno-nofastrtx -superclass TestSuite   
  384. Test/seqno-nofastrtx instproc init {} {
  385.     $self instvar net_ test_ guide_ 
  386.     set net_ net6
  387.     set test_   seqno-nofastrtx
  388.     set guide_  "Without Fast Retransmit."
  389.     $self next
  390. }
  391. Test/seqno-nofastrtx instproc run {} {
  392.     $self setup seqno-nofastrtx {}
  393. }
  394. Class Test/seqno-fastrtx -superclass TestSuite
  395. Test/seqno-fastrtx instproc init {} {
  396.     $self instvar net_ test_ guide_ 
  397.     set net_ net6
  398.     set test_   seqno-fastrtx
  399.     set guide_  "With Fast Retransmit."
  400.     $self next
  401. }
  402. Test/seqno-fastrtx instproc run {} {
  403.     $self setup seqno-fastrtx {}
  404. }
  405. #### Karn Algorithm (RTT sampling + exp. backoff)
  406. Class Test/rto-karn -superclass TestSuite
  407. Test/rto-karn instproc init {} {
  408.     $self instvar net_ test_ guide_ 
  409.     set net_ net7
  410.     set test_   rto-karn
  411.     set guide_  "With Karn's RTT Sampling and Exponential Backoff."
  412.     $self next
  413. }
  414. Test/rto-karn instproc run {} {
  415.     $self setup rto-karn {}
  416. }
  417. Class Test/rto-nokarn -superclass TestSuite
  418. Test/rto-nokarn instproc init {} {
  419.     $self instvar net_ test_ guide_ 
  420.     set net_ net7
  421.     set test_   rto-nokarn
  422.     set guide_  "Without Karn's RTT Sampling and Exponential Backoff."
  423.     Agent/TCP set bugfix_ss_ 0
  424.     $self next
  425. }
  426. Test/rto-nokarn instproc run {} {
  427.     $self setup rto-nokarn {}
  428. }
  429. ########## Jacobson's SIGCOMM' 88 
  430. Class Test/jacobson88-noss -superclass TestSuite
  431. Test/jacobson88-noss instproc init {} {
  432.     $self instvar net_ test_ guide_ 
  433.     set net_ net8
  434.     set test_   jacobson88-noss
  435.     set guide_  "Without Slow-Start."
  436.     $self next
  437. }
  438. Test/jacobson88-noss instproc run {} {
  439.     $self setup jacobson88-noss {}
  440. }
  441. Class Test/jacobson88-ss -superclass TestSuite
  442. Test/jacobson88-ss instproc init {} {
  443.     $self instvar net_ test_ guide_ 
  444.     set net_ net8
  445.     set test_   jacobson88-ss
  446.     set guide_  "With Slow-Start."
  447.     $self next
  448. }
  449. Test/jacobson88-ss instproc run {} {
  450.     $self setup jacobson88-ss {}
  451. }
  452. ###
  453. TestSuite runTest