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

通讯编程

开发平台:

Visual C++

  1. # -*- Mode:tcl; tcl-indent-level:8; tab-width:8; indent-tabs-mode:t -*-
  2. #
  3. # Copyright (c) 1998 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-realaudio.tcl,v 1.4 2005/06/11 04:42:09 sfloyd Exp $
  18. # To run all tests: test-all-realaudio
  19. #
  20. # To view a list of available test to run with this script:
  21. # ns test-suite-realaudio.tcl
  22. remove-all-packet-headers       ; # removes all except common
  23. add-packet-header Flags IP RTP TCP  ; # hdrs reqd for validation test
  24. proc usage {}  {
  25.         global argv0
  26. puts stderr "usage: ns $argv0 realaudio"
  27.         exit 1
  28. }
  29. Class TestSuite
  30. Class Test/realaudio -superclass TestSuite
  31. TestSuite instproc init {} {
  32. }
  33. Test/realaudio instproc init {} {
  34. ##
  35. global seed packetsize nn cnn plottime
  36. set seed           1
  37. set packetsize     245
  38. set nn             3             ;# number of nodes
  39. set cnn            [expr $nn -2 ]   ;# number of clients
  40. set plottime 15000.0
  41. }
  42. Test/realaudio instproc run {} {
  43. global seed packetsize nn cnn plottime
  44. ns-random $seed
  45. ##user start time from a poisson distribution
  46. set starttime(2) 0
  47. #set tmp [new RandomVariable/Exponential] ;# Poisson process
  48. #$tmp set avg_ 5.4674 ;# average arrival interval
  49. #artificially syncronize flow start time
  50. #every flow starts at multiple of 1.8s
  51. set tmp [new RandomVariable/Empirical]
  52. $tmp loadCDF userintercdf1
  53. for {set i 3} {$i < $nn} {incr i} {
  54.     set p [$tmp value]
  55.     set i1 [expr $i - 1 ]
  56.     set starttime($i) [expr $starttime($i1) + $p ]
  57. }
  58. ##number of sequential flow per user
  59. set rv0 [new RandomVariable/Empirical]
  60. $rv0 loadCDF sflowcdf
  61. ##flow duration
  62. set rv1 [new RandomVariable/Empirical]
  63. $rv1 loadCDF flowdurcdf
  64. for {set i 2} {$i < $nn} {incr i} {
  65.   set q [$rv0 value]
  66.   set sflow($i) [expr int($q) ]
  67. #  puts "node $i has $sflow($i) flow "
  68.   set p [$rv1 value]
  69.   set dur($i) [expr $p * 60 ]
  70. #  puts "node $i duration : $dur($i)"
  71. }
  72. for {set i 2} {$i < $nn} {incr i} {
  73.     set flowstoptime($i) [expr $starttime($i) + $dur($i) ]
  74. }
  75. set ns [new Simulator]
  76. for {set i 0} {$i < $nn} {incr i} {
  77. set n($i) [$ns node]
  78. }
  79. set f [open temp.rands w]
  80. $ns trace-all $f
  81. $ns duplex-link $n(0) $n(1) 1.5Mb 10ms DropTail
  82. for {set j 2} {$j < $nn} {incr j} {
  83.     $ns duplex-link $n(0) $n($j) 10Mb 5ms DropTail
  84. }
  85. set rv2 [new RandomVariable/Empirical]
  86. $rv2 loadCDF ontimecdf
  87. set rv3 [new RandomVariable/Empirical]
  88. $rv3 loadCDF fratecdf
  89. for {set i 2} {$i < $nn} {incr i} {
  90.   set s($i) [new Agent/UDP]
  91.   $ns attach-agent $n(1) $s($i)
  92.   set null($i) [new Agent/Null]
  93.   $ns attach-agent $n($i) $null($i)
  94.   $ns connect $s($i) $null($i)
  95.   set realaudio($i) [new Application/Traffic/RealAudio]
  96.   $realaudio($i) set packetSize_ $packetsize
  97.   $realaudio($i) set burst_time_ 0.05ms
  98.   $realaudio($i) set idle_time_ 1800ms
  99.   set flow_rate  [$rv3 value]  
  100.   set r [ format "%fk"  $flow_rate ]
  101. #  puts "node $i flow rate $r"
  102.   $realaudio($i) set rate_ $r
  103.   $realaudio($i) attach-agent $s($i)
  104. }
  105. for {set i 2} {$i < $nn} {incr i} {
  106.       $ns at $starttime($i) "$realaudio($i) start"
  107.       $ns at $flowstoptime($i) "$realaudio($i) stop"
  108. #      puts "node $i starttime $starttime($i)"
  109. #      puts "node $i stoptime $flowstoptime($i)"
  110.   
  111.       ##schedule for next flow
  112.       for {set h 2} {$h <= $sflow($i)} {incr h} {
  113.           set starttime($i) [expr $flowstoptime($i) + 0.001 ]
  114.           set p [$rv1 value]
  115.           set dur($i) [expr $p * 60 ]
  116. #         puts "node $i duration : $dur($i)"
  117.   set flowstoptime($i) [expr $starttime($i) + $dur($i) ]
  118.           set realaudio($i) [new Application/Traffic/RealAudio]
  119.           $realaudio($i) set packetSize_ $packetsize
  120.           $realaudio($i) set burst_time_ 0.05ms
  121.           $realaudio($i) set idle_time_ 1800ms
  122.           set flow_rate  [$rv3 value]  
  123.           set r [ format "%fk"  $flow_rate ]
  124. #         puts "node $i flow rate $r"
  125.           $realaudio($i) set rate_ $r
  126.           $realaudio($i) attach-agent $s($i)
  127.           
  128.       }
  129. }
  130. $ns at $plottime "close $f"
  131. $ns at $plottime "puts "NS EXITING..." ; $ns halt"
  132. $ns run
  133. }
  134. TestSuite instproc finish {} {
  135. exec awk {
  136. {
  137. if (($1 == "+") && ($3 == 1) ) 
  138.      print $2, $10
  139. }
  140. } temp.rands > out.tr
  141.         exit 0
  142. }
  143. proc runtest {arg} {
  144.         global quiet
  145.         set quiet 0
  146. set b [llength $arg]
  147. if {$b == 1} {
  148.         set test $arg
  149.         } elseif {$b == 2} {
  150.         set test [lindex $arg 0]
  151.             if {[lindex $arg 1] == "QUIET"} {
  152.         set quiet 1
  153.             }
  154.         } else {
  155.         usage
  156.         }
  157. switch $test {
  158. realaudio {
  159.                      set t [new Test/$test]
  160.                 }
  161.                 default {
  162.              stderr "Unknown test $test"
  163.      exit 1
  164.                 }
  165.          }
  166.  $t run
  167. }
  168. global argv arg0 
  169. runtest $argv