PageRenderTime 49ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/ns-2.34/tcl/test/test-suite-mcache.tcl

http://uu-cope.googlecode.com/
TCL | 1177 lines | 811 code | 174 blank | 192 comment | 83 complexity | 191b9b54f3d1988e88514a5c4a2c7591 MD5 | raw file
Possible License(s): LGPL-2.0
  1. # Test suite for HTTP server, client, proxy cache.
  2. #
  3. # Also tests TcpApp, which is an Application used to transmit
  4. # application-level data. Because current TCP isn't capable of this,
  5. # we build this functionality based on byte-stream model of underlying
  6. # TCP connection.
  7. #
  8. # $Header: /cvsroot/nsnam/ns-2/tcl/test/test-suite-mcache.tcl,v 1.15 2006/01/24 23:00:06 sallyfloyd Exp $
  9. #----------------------------------------------------------------------
  10. # Related Files
  11. #----------------------------------------------------------------------
  12. #source misc.tcl
  13. remove-all-packet-headers ; # removes all except common
  14. add-packet-header Flags IP TCP HttpInval ; # hdrs reqd for validation test
  15. # FOR UPDATING GLOBAL DEFAULTS:
  16. Agent/TCP set precisionReduce_ false ; # default changed on 2006/1/24.
  17. Agent/TCP set rtxcur_init_ 6.0 ; # Default changed on 2006/01/21
  18. Agent/TCP set updated_rttvar_ false ; # Variable added on 2006/1/21
  19. Agent/TCP set tcpTick_ 0.1
  20. # The default for tcpTick_ is being changed to reflect a changing reality.
  21. Agent/TCP set rfc2988_ false
  22. # The default for rfc2988_ is being changed to true.
  23. Agent/TCP set useHeaders_ false
  24. # The default is being changed to useHeaders_ true.
  25. Agent/TCP set windowInit_ 1
  26. # The default is being changed to 2.
  27. Agent/TCP set singledup_ 0
  28. # The default is being changed to 1
  29. source topologies.tcl
  30. #----------------------------------------------------------------------
  31. # Misc setup
  32. #----------------------------------------------------------------------
  33. set tcl_precision 10
  34. Agent/TCP set minrto_ 0
  35. # The default is being changed to minrto_ 1
  36. #----------------------------------------------------------------------
  37. # Section 1: Base test class
  38. #----------------------------------------------------------------------
  39. Class Test
  40. # Copied from Simulator::instance{}
  41. Test proc instance {} {
  42. set t [Test info instances]
  43. if { $t != "" } {
  44. return $t
  45. }
  46. set tl [Test info subclass]
  47. while { $tl != "" } {
  48. set ntl {}
  49. foreach t $tl {
  50. set tt [$t info instances]
  51. if { $tt != "" } {
  52. return $tt
  53. }
  54. set ntl [eval lappend ntl [$t info subclass]]
  55. }
  56. set tl $ntl
  57. }
  58. error "Cannot find instance of Test"
  59. }
  60. Test instproc init-instvar v {
  61. set cl [$self info class]
  62. while { "$cl" != "" } {
  63. foreach c $cl {
  64. if ![catch "$c set $v" val] {
  65. $self set $v $val
  66. return
  67. }
  68. }
  69. set parents ""
  70. foreach c $cl {
  71. if { $cl != "Object" } {
  72. set parents "$parents [$c info superclass]"
  73. }
  74. }
  75. set cl $parents
  76. }
  77. }
  78. Test instproc init {} {
  79. $self instvar ns_ trace_ net_ defNet_ testName_ node_ test_ topo_ \
  80. ntrace_
  81. set ns_ [new Simulator -multicast on]
  82. set cls [$self info class]
  83. set cls [split $cls /]
  84. set test_ [lindex $cls [expr [llength $cls] - 1]]
  85. global opts
  86. ns-random $opts(ns-random-seed)
  87. # XXX We only output LOGs, but no packet traces.
  88. if ![info exists opts(net)] {
  89. set net_ $defNet_
  90. } else {
  91. set net_ $opts(net)
  92. }
  93. if ![Topology/$defNet_ info subclass Topology/$net_] {
  94. global argv0
  95. puts "$argv0: cannot run test $test_ over topology $net_"
  96. exit 1
  97. }
  98. set topo_ [new Topology/$net_ $ns_]
  99. foreach i [$topo_ array names node_] {
  100. # This would be cool, but lets try to be compatible
  101. # with test-suite.tcl as far as possible.
  102. #
  103. # $self instvar $i
  104. # set $i [$topo_ node? $i]
  105. #
  106. set node_($i) [$topo_ node? $i]
  107. }
  108. if {$net_ == $defNet_} {
  109. set testName_ "$test_"
  110. } else {
  111. set testName_ "$test_:$net_"
  112. }
  113. }
  114. Test instproc create-ranvar { dist args } {
  115. # options
  116. array set opts $args
  117. switch $dist {
  118. Constant {
  119. set tmp [new RandomVariable/Constant]
  120. $tmp set val_ $opts(avg)
  121. }
  122. Poisson {
  123. set tmp [new RandomVariable/Exponential]
  124. $tmp set avg_ $opts(avg)
  125. }
  126. Uniform {
  127. set tmp [new RandomVariable/Uniform]
  128. $tmp set min $opts(min)
  129. $tmp set max $opts(max)
  130. }
  131. Pareto {
  132. set tmp [new RandomVariable/Pareto]
  133. $tmp set avg_ $opts(avg)
  134. $tmp set shape_ $opts(shape)
  135. }
  136. default {
  137. error "Unknown random variable distribution $dist"
  138. }
  139. }
  140. if [info exists opts(rng)] {
  141. $tmp use-rng $opts(rng)
  142. }
  143. return $tmp
  144. }
  145. # Use this so derived class would have a chance to overwrite the default net
  146. # of parent classes
  147. Test instproc set-defnet { defnet } {
  148. $self instvar defNet_
  149. if ![info exists defNet_] {
  150. set defNet_ $defnet
  151. }
  152. }
  153. Test instproc inherit-set { name val } {
  154. $self instvar $name
  155. if ![info exists $name] {
  156. set $name $val
  157. }
  158. }
  159. Test instproc write-testconf { file } {
  160. $self instvar test_ net_
  161. puts $file "# TESTNAME: $test_"
  162. puts $file "# TOPOLOGY: $net_"
  163. global opts
  164. foreach n [lsort [array names opts]] {
  165. # XXX Remove this after validating existing traces
  166. if {$n == "quiet"} { continue }
  167. puts $file "# $n: $opts($n)"
  168. }
  169. }
  170. Test instproc set-routing {} {
  171. }
  172. Test instproc set-members {} {
  173. }
  174. Test instproc finish {} {
  175. $self instvar ns_ trace_ ntrace_
  176. if [info exists trace_] {
  177. $ns_ flush-trace
  178. close $trace_
  179. }
  180. if [info exists ntrace_] {
  181. close $ntrace_
  182. }
  183. exit 0
  184. }
  185. Test instproc run {} {
  186. $self instvar finishTime_ ns_ trace_
  187. $self set-routing
  188. $self set-members
  189. $ns_ set-abort-proc "$ns_ flush-trace; \
  190. $self finish"
  191. $ns_ at $finishTime_ "$self finish"
  192. $ns_ run
  193. }
  194. Simulator instproc set-abort-proc { exp } {
  195. $self instvar abortProc_
  196. set abortProc_ $exp
  197. }
  198. Simulator instproc abort {} {
  199. $self instvar abortProc_
  200. eval $abortProc_
  201. }
  202. # option processing copied from John's ~ns/tcl/ex/rbp_demo.tcl
  203. proc default_options {} {
  204. global opts opt_wants_arg raw_opt_info
  205. # raw_opt_info can be set in user's script
  206. while {$raw_opt_info != ""} {
  207. if {![regexp "^\[^\n\]*\n" $raw_opt_info line]} {
  208. break
  209. }
  210. regsub "^\[^\n\]*\n" $raw_opt_info {} raw_opt_info
  211. set line [string trim $line]
  212. if {[regexp "^\[ \t\]*#" $line]} {
  213. continue
  214. }
  215. if {$line == ""} {
  216. continue
  217. } elseif [regexp {^([^ ]+)[ ]+([^ ]+)$} $line dummy key value] {
  218. set opts($key) $value
  219. set opt_wants_arg($key) 1
  220. } elseif [regexp {^([^ ]+)[ ]*$} $line dummy key] {
  221. # So we don't need to assign opt($key)
  222. set opt_wants_arg($key) 1
  223. } else {
  224. set opt_wants_arg($key) 0
  225. error "unknown stuff \"$line\" in raw_opt_info"
  226. }
  227. }
  228. }
  229. proc process_args {} {
  230. global argc argv opts opt_wants_arg
  231. default_options
  232. for {set i 0} {$i < $argc} {incr i} {
  233. set key [lindex $argv $i]
  234. if {$key == "-?" || $key == "--help" || $key == "-help" || $key == "-h"} {
  235. usage
  236. }
  237. regsub {^--} $key {} key
  238. if {![info exists opt_wants_arg($key)]} {
  239. continue
  240. }
  241. if {$opt_wants_arg($key)} {
  242. incr i
  243. set opts($key) [lindex $argv $i]
  244. } else {
  245. set opts($key) [expr !opts($key)]
  246. }
  247. }
  248. }
  249. # XXX User can reset/append raw_opt_info in their scripts.
  250. # At the end of user test script, call proc run to start.
  251. # Startup procedure, called at the end of the script
  252. proc run {} {
  253. global argc argv opts raw_opt_info
  254. # We don't actually have any real arguments, but we do have
  255. # various initializations, which the script depends on.
  256. process_args
  257. # Calling convention by test-all-template1:
  258. # ns <file> <test> [QUIET]
  259. set prot [lindex $argv 0]
  260. set opts(prot) $prot
  261. if {$argc > 1} {
  262. set opts(quiet) 1
  263. } else {
  264. set opts(quiet) 0
  265. }
  266. set test [new Test/$prot]
  267. $test run
  268. }
  269. #----------------------------------------------------------------------
  270. # Section 2 Base class for cache testing
  271. #----------------------------------------------------------------------
  272. # Simple 2 node, one server, one client
  273. Class Topology/2node -superclass SkelTopology
  274. Topology/2node instproc init { ns } {
  275. $self next
  276. $self instvar node_
  277. set node_(c) [$ns node]
  278. set node_(s) [$ns node]
  279. # A modem link + a T1 cross-country link
  280. $ns duplex-link $node_(c) $node_(s) 10Mb 2ms DropTail
  281. $ns duplex-link-op $node_(c) $node_(s) orient right
  282. $ns duplex-link-op $node_(c) $node_(s) queuePos 0.5
  283. # Possible congestion near the client
  284. $ns queue-limit $node_(c) $node_(s) 10
  285. }
  286. #
  287. # 3 node linear topology testing SimpleTcp and TcpApp
  288. #
  289. Class Topology/3node -superclass SkelTopology
  290. Topology/3node instproc init { ns } {
  291. $self next
  292. $self instvar node_
  293. set node_(c) [$ns node]
  294. set node_(1) [$ns node]
  295. set node_(s) [$ns node]
  296. # A modem link + a T1 cross-country link
  297. $ns duplex-link $node_(c) $node_(1) 56Kb 100ms DropTail
  298. $ns duplex-link $node_(1) $node_(s) 1.5Mb 50ms DropTail
  299. $ns duplex-link-op $node_(c) $node_(1) orient right
  300. $ns duplex-link-op $node_(1) $node_(s) orient right
  301. $ns duplex-link-op $node_(c) $node_(1) queuePos 0.5
  302. $ns duplex-link-op $node_(1) $node_(s) queuePos 0.5
  303. # Possible congestion near the client
  304. $ns queue-limit $node_(c) $node_(1) 10
  305. $ns queue-limit $node_(1) $node_(c) 10
  306. }
  307. # Simplest topology: 1 client + 1 cache + 1 server
  308. Class Topology/cache0 -superclass SkelTopology
  309. Topology/cache0 instproc init ns {
  310. $self next
  311. $self instvar node_
  312. set node_(c) [$ns node]
  313. set node_(e) [$ns node]
  314. set node_(s) [$ns node]
  315. # A modem link + a T1 cross-country link
  316. $ns duplex-link $node_(c) $node_(e) 56Kb 100ms DropTail
  317. $ns duplex-link $node_(e) $node_(s) 1.5Mb 50ms DropTail
  318. $ns duplex-link-op $node_(c) $node_(e) orient right
  319. $ns duplex-link-op $node_(e) $node_(s) orient right
  320. $ns duplex-link-op $node_(c) $node_(e) queuePos 0.5
  321. $ns duplex-link-op $node_(e) $node_(s) queuePos 0.5
  322. $ns queue-limit $node_(c) $node_(e) 2
  323. $ns queue-limit $node_(e) $node_(c) 2
  324. $ns queue-limit $node_(e) $node_(s) 5
  325. $ns queue-limit $node_(s) $node_(e) 5
  326. }
  327. # Same as cache0 but with the bottleneck link at the server side
  328. Class Topology/cache1 -superclass SkelTopology
  329. Topology/cache1 instproc init ns {
  330. $self next
  331. $self instvar node_
  332. set node_(c) [$ns node]
  333. set node_(e) [$ns node]
  334. set node_(s) [$ns node]
  335. # A modem link + a T1 cross-country link
  336. $ns duplex-link $node_(c) $node_(e) 1.5Mb 50ms DropTail
  337. $ns duplex-link $node_(e) $node_(s) 56Kb 100ms DropTail
  338. $ns duplex-link-op $node_(c) $node_(e) orient right
  339. $ns duplex-link-op $node_(e) $node_(s) orient right
  340. $ns duplex-link-op $node_(c) $node_(e) queuePos 0.5
  341. $ns duplex-link-op $node_(e) $node_(s) queuePos 0.5
  342. $ns queue-limit $node_(c) $node_(e) 5
  343. $ns queue-limit $node_(e) $node_(c) 5
  344. $ns queue-limit $node_(e) $node_(s) 2
  345. $ns queue-limit $node_(s) $node_(e) 2
  346. }
  347. #
  348. # 4 nodes: one server, one cache, 2 clients
  349. #
  350. Class Topology/4node -superclass SkelTopology
  351. Topology/4node instproc init ns {
  352. $self next
  353. $self instvar node_
  354. set node_(c0) [$ns node]
  355. set node_(c1) [$ns node]
  356. set node_(e) [$ns node]
  357. set node_(s) [$ns node]
  358. # Ethernet from clients to cache
  359. $ns duplex-link $node_(c0) $node_(e) 1.5Mb 50ms DropTail
  360. $ns duplex-link $node_(c1) $node_(e) 1.5Mb 50ms DropTail
  361. # 56K link from cache to server
  362. $ns duplex-link $node_(e) $node_(s) 56K 100ms DropTail
  363. $ns duplex-link-op $node_(c0) $node_(e) orient left
  364. $ns duplex-link-op $node_(c1) $node_(e) orient down
  365. $ns duplex-link-op $node_(e) $node_(s) orient left
  366. $ns duplex-link-op $node_(c0) $node_(e) queuePos 0.5
  367. $ns duplex-link-op $node_(c1) $node_(e) queuePos 0.5
  368. $ns duplex-link-op $node_(e) $node_(s) queuePos 0.5
  369. $ns queue-limit $node_(c0) $node_(e) 5
  370. $ns queue-limit $node_(e) $node_(c0) 5
  371. $ns queue-limit $node_(c1) $node_(e) 5
  372. $ns queue-limit $node_(e) $node_(c1) 5
  373. $ns queue-limit $node_(e) $node_(s) 2
  374. $ns queue-limit $node_(s) $node_(e) 2
  375. }
  376. #
  377. # Heterogeneous 4 nodes: one server, one cache, 2 clients
  378. #
  379. Class Topology/4node-h -superclass SkelTopology
  380. Topology/4node-h instproc init ns {
  381. $self next
  382. $self instvar node_
  383. set node_(c0) [$ns node]
  384. set node_(c1) [$ns node]
  385. set node_(e) [$ns node]
  386. set node_(s) [$ns node]
  387. # Ethernet from clients to cache
  388. # node c0: abundant bw, node c1: limited bw
  389. $ns duplex-link $node_(c0) $node_(e) 1.5Mb 50ms DropTail
  390. $ns duplex-link $node_(c1) $node_(e) 56Kb 50ms DropTail
  391. # 56K link from cache to server
  392. $ns duplex-link $node_(e) $node_(s) 56Kb 100ms DropTail
  393. $ns duplex-link-op $node_(c0) $node_(e) orient left
  394. $ns duplex-link-op $node_(c1) $node_(e) orient down
  395. $ns duplex-link-op $node_(e) $node_(s) orient left
  396. $ns duplex-link-op $node_(c0) $node_(e) queuePos 0.5
  397. $ns duplex-link-op $node_(c1) $node_(e) queuePos 0.5
  398. $ns duplex-link-op $node_(e) $node_(s) queuePos 0.5
  399. $ns queue-limit $node_(c0) $node_(e) 5
  400. $ns queue-limit $node_(e) $node_(c0) 5
  401. $ns queue-limit $node_(c1) $node_(e) 2
  402. $ns queue-limit $node_(e) $node_(c1) 2
  403. $ns queue-limit $node_(e) $node_(s) 2
  404. $ns queue-limit $node_(s) $node_(e) 2
  405. }
  406. # 10 continuous TCP sessions and 10 continuous RAP sessions
  407. Class Topology/mess-h -superclass SkelTopology
  408. Topology/mess-h instproc init ns {
  409. $self next
  410. $self instvar node_
  411. set node_(c0) [$ns node]
  412. set node_(c1) [$ns node]
  413. set node_(e) [$ns node]
  414. set node_(s) [$ns node]
  415. set d1 [$ns node]
  416. set d2 [$ns node]
  417. # Ethernet from clients to cache
  418. # node c0: abundant bw, node c1: limited bw
  419. $ns duplex-link $node_(c0) $node_(e) 1.5Mb 50ms DropTail
  420. $ns duplex-link $node_(c1) $node_(e) 56Kb 50ms DropTail
  421. # 56K*20 links from cache to server
  422. $ns duplex-link $node_(e) $d1 1.5Mb 50ms DropTail
  423. $ns duplex-link $d2 $node_(s) 56Kb 50ms DropTail
  424. $ns duplex-link $d1 $d2 1.5Mb 100ms DropTail
  425. $ns duplex-link-op $node_(c0) $node_(e) queuePos 0.5
  426. $ns duplex-link-op $node_(c1) $node_(e) queuePos 0.5
  427. $ns duplex-link-op $node_(e) $d1 queuePos 0.5
  428. $ns duplex-link-op $d2 $d1 queuePos 0.5
  429. $ns duplex-link-op $node_(s) $d2 queuePos 0.5
  430. # Buffer: 1 RTT at every link, but 4 RTT at the bottleneck link
  431. $ns queue-limit $node_(c0) $node_(e) 18
  432. $ns queue-limit $node_(e) $node_(c0) 18
  433. $ns queue-limit $node_(c1) $node_(e) 3
  434. $ns queue-limit $node_(e) $node_(c1) 3
  435. $ns queue-limit $node_(e) $d1 18
  436. $ns queue-limit $d1 $node_(e) 18
  437. # 1 RTT for the bottleneck link
  438. $ns queue-limit $d1 $d2 37
  439. $ns queue-limit $d2 $d1 37
  440. # 1 RTT for web server link
  441. $ns queue-limit $d2 $node_(s) 3
  442. $ns queue-limit $node_(s) $d2 3
  443. # Create rap and tcp nodes
  444. for {set i 0} {$i < 10} {incr i} {
  445. set node_(t$i) [$ns node] ;# TCP client
  446. set node_(T$i) [$ns node] ;# TCP server
  447. set node_(r$i) [$ns node] ;# RAP client
  448. set node_(R$i) [$ns node] ;# RAP server
  449. # clients connect to cache, servers connect to dummy
  450. $ns duplex-link $node_(t$i) $d1 1.5Mb 50ms DropTail
  451. $ns duplex-link $node_(T$i) $d2 1.5Mb 50ms DropTail
  452. $ns duplex-link $node_(r$i) $d1 1.5Mb 50ms DropTail
  453. $ns duplex-link $node_(R$i) $d2 1.5Mb 50ms DropTail
  454. # Set all queue limits to 1 RTT
  455. $ns queue-limit $node_(t$i) $d1 18
  456. $ns queue-limit $d1 $node_(t$i) 18
  457. $ns queue-limit $node_(T$i) $d2 18
  458. $ns queue-limit $d2 $node_(T$i) 18
  459. $ns queue-limit $node_(r$i) $d1 18
  460. $ns queue-limit $d1 $node_(r$i) 18
  461. $ns queue-limit $node_(R$i) $d2 18
  462. $ns queue-limit $d2 $node_(R$i) 18
  463. }
  464. }
  465. Agent/TCP/FullTcp set segsize_ 1500 ;# segment size 1.5K
  466. Agent/TCP/FullTcp set nodelay_ true ;# don't use Nagle's algorithm
  467. PagePool/Media set page_size_ 1000
  468. # QA-related setup
  469. Application/MediaApp/QA set LAYERBW_ 2500 ;# Byte rate of layer consumption
  470. Application/MediaApp/QA set MAXACTIVELAYERS_ 10
  471. Application/MediaApp/QA set SRTTWEIGHT_ 0.95
  472. Application/MediaApp/QA set SMOOTHFACTOR_ 4
  473. Application/MediaApp/QA set MAXBKOFF_ 100
  474. Application/MediaApp/QA set pref_srtt_ 0.6
  475. Application/MediaApp/QA set debug_output_ 0
  476. #----------------------------------------------------------------------
  477. # Base class for web cache testing
  478. #----------------------------------------------------------------------
  479. Class Test-mcache -superclass Test
  480. Test-mcache set startTime_ 10
  481. Test-mcache instproc init {} {
  482. $self next
  483. $self instvar startTime_ log_
  484. set startTime_ [$class set startTime_]
  485. # XXX This is the main output of the test suite
  486. global opts
  487. if $opts(enable-log) {
  488. set log_ [open "temp.rands" w]
  489. $self write-testconf $log_
  490. }
  491. # By default set to selective push
  492. $self set-pagepool
  493. global opts
  494. if [info exists opts(cache-ims-size)] {
  495. Http set IMSSize_ $opts(cache-ims-size)
  496. }
  497. if [info exists opt(server-inv-size)] {
  498. Http set INVSize_ $opt(server-inv-size)
  499. }
  500. if [info exists opts(cache-ref-size)] {
  501. Http set REFSize_ $opts(cache-ref-size)
  502. }
  503. if [info exists opts(client-req-size)] {
  504. Http set REQSize_ $opts(client-req-size)
  505. }
  506. }
  507. # Allow global options to preempt, and derived classes to overwrite.
  508. Test-mcache instproc set-server-type { servertype } {
  509. $self instvar serverType_
  510. global opts
  511. if [info exists opts(server)] {
  512. set serverType_ $opts(server)
  513. } else {
  514. set serverType_ $servertype
  515. }
  516. }
  517. Test-mcache instproc set-cache-type { cachetype } {
  518. $self instvar cacheType_
  519. global opts
  520. if [info exists opts(cache)] {
  521. set cacheType_ $opts(cache)
  522. } else {
  523. set cacheType_ $cachetype
  524. }
  525. }
  526. Test-mcache instproc set-client-type { clienttype } {
  527. $self instvar clientType_
  528. global opts
  529. if [info exists opts(client)] {
  530. set clientType_ $opts(client)
  531. } else {
  532. set clientType_ $clienttype
  533. }
  534. }
  535. Test-mcache instproc set-pagepool {} {
  536. $self instvar startTime_ finishTime_ pgp_
  537. global opts
  538. # Use PagePool/Media
  539. set pgp_ [new PagePool/Media]
  540. # PagePool/Media MUST know the duration of the simulation; it needs
  541. # the info to set correct page modification time.
  542. $pgp_ set-duration $opts(duration)
  543. # Number of streams
  544. $pgp_ set-num-pages $opts(num-pages)
  545. # Page sizes
  546. # XXX Should be overwritten later
  547. for {set i 0} {$i < $opts(num-pages)} {incr i} {
  548. $pgp_ set-pagesize $i $opts(avg-page-size)
  549. }
  550. # Layers
  551. $pgp_ set-layer $opts(obj-layer)
  552. # Request generator
  553. set tmp [new RandomVariable/Uniform]
  554. $tmp set min_ 0
  555. $tmp set max_ $opts(num-pages)
  556. $pgp_ ranvar-req $tmp
  557. $pgp_ set-start-time $startTime_
  558. set finishTime_ [expr $startTime_ + $opts(duration)]
  559. }
  560. Test-mcache instproc set-req-generator { client } {
  561. $self instvar pgp_ reqRNG_
  562. global opts
  563. if ![info exists reqRNG_] {
  564. set reqRNG_ [new RNG]
  565. $reqRNG_ seed $opts(ns-random-seed)
  566. }
  567. switch $opts(req-dist) {
  568. Poisson {
  569. set tmp [new RandomVariable/Exponential]
  570. $tmp set avg_ $opts(avg-req-interval)
  571. }
  572. Pareto {
  573. set tmp [new RandomVariable/Pareto]
  574. $tmp set avg_ $opts(avg-req-interval)
  575. $tmp set shape_ $opts(req-rv-shape)
  576. }
  577. Uniform {
  578. set tmp [new RandomVariable/Uniform]
  579. set opts(min-req-interval) \
  580. [expr $opts(avg-req-interval)*0.84]
  581. set opts(max-req-interval) \
  582. [expr $opts(avg-req-interval)*1.17]
  583. $tmp set min_ $opts(min-req-interval)
  584. $tmp set max_ $opts(max-req-interval)
  585. }
  586. default {
  587. puts "Unkown page request distribution $opts(req-dist)"
  588. exit 1
  589. }
  590. }
  591. $tmp use-rng $reqRNG_
  592. $client set-interval-generator $tmp
  593. $client set-page-generator $pgp_
  594. }
  595. Test-mcache instproc flush-trace {} {
  596. $self instvar log_
  597. flush $log_
  598. [Simulator instance] flush-trace
  599. }
  600. Test-mcache instproc create-members {} {
  601. $self instvar client_ server_ cache_ log_ test_ pgp_ node_ ns_ \
  602. serverType_ cacheType_ clientType_
  603. set st $serverType_
  604. set lt $clientType_
  605. # We may not have cache
  606. if [info exists cacheType_] {
  607. set ct $cacheType_
  608. }
  609. global opts
  610. foreach n [array names node_] {
  611. set type [string range $n 0 0]
  612. set num [string range $n 1 end]
  613. if {$num == ""} {
  614. set num 0
  615. }
  616. switch $type {
  617. s {
  618. set server_($num) [new Http/Server$st $ns_ $node_($n)]
  619. if $opts(enable-log) {
  620. $server_($num) log $log_
  621. }
  622. $server_($num) set-page-generator $pgp_
  623. }
  624. e {
  625. set cache_($num) [new Http/Cache$ct $ns_ $node_($n)]
  626. if $opts(enable-log) {
  627. $cache_($num) log $log_
  628. }
  629. }
  630. c {
  631. set client_($num) [new Http/Client$lt $ns_ $node_($n)]
  632. $self set-req-generator $client_($num)
  633. if $opts(enable-log) {
  634. $client_($num) log $log_
  635. }
  636. }
  637. }
  638. }
  639. }
  640. Test-mcache instproc set-routing {} {
  641. $self instvar ns_
  642. $ns_ rtproto Session
  643. }
  644. Test-mcache instproc set-members {} {
  645. $self instvar ns_ finishTime_ startTime_
  646. $ns_ at $startTime_ "$self start-connection"
  647. }
  648. # Create media contents in servers
  649. Test-mcache instproc populate-server {} {
  650. $self instvar pgp_ cache_ server_
  651. for {set i 0} {$i < [$pgp_ get-poolsize]} {incr i} {
  652. set pageid $server_(0):$i
  653. $server_(0) gen-page $pageid
  654. }
  655. }
  656. Test-mcache instproc start-connection {} {
  657. $self instvar ns_
  658. $self create-members
  659. $self populate-server
  660. $self set-connections
  661. # Let initializations settles down, then start requests
  662. $ns_ at [expr [$ns_ now] + 10] "$self start-requests"
  663. }
  664. Test-mcache instproc finish {} {
  665. $self instvar log_
  666. if [info exists log_] {
  667. close $log_
  668. }
  669. $self next
  670. }
  671. # Transmitting a single stream from a client to a server via a bottleneck
  672. # 56Kb link. NO quality adaptation
  673. Class Test/media1 -superclass Test-mcache
  674. Test/media1 instproc init {} {
  675. $self set-defnet 3node
  676. global opts
  677. set opts(avg-page-size) 102400
  678. # Since we are NOT doing QA, must use a single layer!!
  679. set opts(obj-layer) 1
  680. $self next
  681. $self set-server-type /Media
  682. $self set-client-type /Media
  683. Http set TRANSPORT_ FullTcp
  684. Http set MEDIA_TRANSPORT_ RAP
  685. }
  686. Test/media1 instproc set-connections {} {
  687. $self instvar client_ server_ cache_
  688. $client_(0) connect $server_(0)
  689. }
  690. Test/media1 instproc start-requests {} {
  691. $self instvar client_ cache_ server_ ns_
  692. $client_(0) start-session $server_(0) $server_(0)
  693. }
  694. # Simple test of client/cache/server, no quality adaptation
  695. # Bottleneck link (56Kb) is near the client
  696. Class Test/media2 -superclass Test-mcache
  697. Test/media2 instproc init {} {
  698. $self set-defnet cache0
  699. global opts
  700. set opts(avg-page-size) 4096
  701. set opts(avg-req-interval) 600
  702. # Since we are NOT doing QA, must use a single layer!!
  703. set opts(obj-layer) 1
  704. $self next
  705. $self set-server-type /Media
  706. $self set-client-type /Media
  707. $self set-cache-type /Media
  708. Http set TRANSPORT_ FullTcp
  709. Http set MEDIA_TRANSPORT_ RAP
  710. }
  711. Test/media2 instproc set-connections {} {
  712. $self instvar client_ server_ cache_
  713. $client_(0) connect $cache_(0)
  714. $cache_(0) connect $server_(0)
  715. }
  716. Test/media2 instproc start-requests {} {
  717. $self instvar client_ cache_ server_ ns_
  718. $client_(0) start-session $cache_(0) $server_(0)
  719. }
  720. # Simple test of QA, one server, one client, 56Kb bottleneck link
  721. Class Test/media3 -superclass Test-mcache
  722. Test/media3 instproc init {} {
  723. $self set-defnet 3node
  724. global opts
  725. set opts(avg-page-size) 524288
  726. set opts(avg-req-interval) 2000
  727. set opts(obj-layer) 4
  728. set opts(duration) 800
  729. $self next
  730. $self set-server-type /Media
  731. $self set-client-type /Media
  732. Http set TRANSPORT_ FullTcp
  733. Http set MEDIA_TRANSPORT_ RAP
  734. Http set MEDIA_APP_ MediaApp/QA
  735. }
  736. Test/media3 instproc set-connections {} {
  737. $self instvar client_ server_ cache_
  738. $client_(0) connect $server_(0)
  739. }
  740. Test/media3 instproc start-requests {} {
  741. $self instvar client_ server_ ns_
  742. $client_(0) set-cache $server_(0)
  743. $client_(0) send-request $server_(0) GET $server_(0):0
  744. }
  745. # Same as above, but 10Mb bottleneck link (basically high enough to hold
  746. # all 8 layers)
  747. Class Test/media3a -superclass Test/media3
  748. Test/media3a instproc init {} {
  749. $self set-defnet 2node
  750. $self next
  751. }
  752. # One server, one cache and one client.
  753. # 56Kb bottleneck link between client and cache.
  754. Class Test/media4 -superclass Test-mcache
  755. Test/media4 instproc init {} {
  756. $self set-defnet cache0
  757. global opts
  758. set opts(avg-req-interval) 60
  759. set opts(duration) 400
  760. # Page size set to 300 seconds
  761. set opts(avg-page-size) 600000
  762. set opts(obj-layer) 8
  763. $self next
  764. $self set-server-type /Media
  765. $self set-client-type /Media
  766. $self set-cache-type /Media
  767. Http set TRANSPORT_ FullTcp
  768. Http set MEDIA_TRANSPORT_ RAP
  769. Http set MEDIA_APP_ MediaApp/QA
  770. }
  771. Test/media4 instproc set-connections {} {
  772. $self instvar client_ server_ cache_
  773. $client_(0) connect $cache_(0)
  774. $cache_(0) connect $server_(0)
  775. }
  776. Test/media4 instproc start-requests {} {
  777. $self instvar client_ cache_ server_ ns_
  778. $client_(0) set-cache $cache_(0)
  779. # First request
  780. $client_(0) send-request $cache_(0) GET $server_(0):0
  781. # 5 additional requests
  782. set time [$ns_ now]
  783. for {set i 1} {$i < 15} {incr i} {
  784. incr time 50
  785. $ns_ at $time "$client_(0) send-request $cache_(0) GET \
  786. $server_(0):0"
  787. }
  788. }
  789. # Same as media4, but with 56Kb bottleneck link between server and cache.
  790. #Class Test/media4a -superclass Test/media4
  791. #Test/media4a instproc init {} {
  792. # $self set-defnet cache1
  793. # $self next
  794. #}
  795. # Test cache replacement
  796. # Clients with heterogeneous bandwidth to the cache: client0-cache is 1.5Mb,
  797. # client1-cache is 56Kb, cache-server is the same as in media5, 56Kb.
  798. #
  799. # We distribute 95% of the requests to the low-bw client 1
  800. Class Test/media5 -superclass Test-mcache
  801. Test/media5 instproc init {} {
  802. $self set-defnet 4node-h
  803. global opts
  804. set opts(num-pages) 3
  805. set opts(obj-layer) 8
  806. set opts(cache-sizefac) 0.4
  807. set opts(total-requests) 10
  808. set opts(duration) [expr 50*$opts(total-requests)+50]
  809. $self next
  810. $self set-server-type /Media
  811. $self set-client-type /Media
  812. $self set-cache-type /Media
  813. Http set TRANSPORT_ FullTcp
  814. Http set MEDIA_TRANSPORT_ RAP
  815. Http set MEDIA_APP_ MediaApp/QA
  816. }
  817. Test/media5 instproc set-pagepool {} {
  818. $self next
  819. # Set sizes of the pages
  820. $self instvar pgp_ ns_
  821. global opts
  822. set layer $opts(obj-layer)
  823. set lbw [Application/MediaApp/QA set LAYERBW_]
  824. # Uniformly distribute stream lengths
  825. set rv [new RandomVariable/Uniform]
  826. $rv set min_ 10
  827. $rv set max_ 20
  828. $self instvar totalSize_ log_
  829. set totalSize_ 0
  830. for {set i 0} {$i < $opts(num-pages)} {incr i} {
  831. set tmp [expr int([$rv value]*$layer*$lbw)]
  832. puts $log_ "# Page $i has size $tmp"
  833. incr totalSize_ $tmp
  834. $pgp_ set-pagesize $i $tmp
  835. }
  836. delete $rv
  837. }
  838. Test/media5 instproc set-connections {} {
  839. $self instvar client_ server_ cache_ totalSize_
  840. # Set cache size to be
  841. global opts
  842. set np $opts(num-pages)
  843. set layer $opts(obj-layer)
  844. set lbw [Application/MediaApp/QA set LAYERBW_]
  845. # Set cache size to be 0.5 times total page size
  846. $cache_(0) set-cachesize [expr $opts(cache-sizefac) * $totalSize_]
  847. # Establish connection
  848. $client_(0) connect $cache_(0)
  849. $client_(1) connect $cache_(0)
  850. $cache_(0) connect $server_(0)
  851. }
  852. Test/media5 instproc start-requests {} {
  853. $self instvar client_ cache_ server_ ns_ log_
  854. # Client setting parent caches
  855. $client_(0) set-cache $cache_(0)
  856. $client_(1) set-cache $cache_(0)
  857. # Generate non-overlapping request sequence
  858. global opts
  859. set np $opts(num-pages)
  860. set time [$ns_ now]
  861. set tr $opts(total-requests)
  862. # Build page popularity table according to total requests and
  863. # Zipf's law
  864. set omega 0
  865. for {set i 1} {$i <= $np} {incr i} {
  866. set omega [expr $omega + 1.0/$i]
  867. }
  868. set omega [expr 1.0 / $omega]
  869. # Calculate number of requests for each page
  870. set j 0
  871. for {set i 0} {$i < $np} {incr i} {
  872. set nreq($i) [expr round($omega*$tr/($i+1.0))]
  873. for {set ii 0} {$ii < $nreq($i)} {incr ii} {
  874. set tmp1($j) 0 ;# Whether this request is occupied
  875. set tmp2($j) $i ;# which page this request belong to
  876. incr j
  877. }
  878. puts $log_ "# Total $nreq($i) requests for page $i"
  879. }
  880. if {$j != $tr} {
  881. error "Mis-calculated number of requests: this $j orig $tr"
  882. }
  883. # Build request sequence, uniform distribution
  884. set rv [new RandomVariable/Uniform]
  885. $rv set min_ 0
  886. $rv set max_ $j
  887. set i 0
  888. set time 0
  889. $self instvar reqlist_
  890. # Schedule requests, 500s interval should suffice for 56K bottleneck
  891. # link and 600s stream with 8 layers of 2.5K bw.
  892. while {$i < $j} {
  893. set rid [expr int([$rv value])]
  894. if {$tmp1($rid) != 0} {
  895. # Already allocated
  896. continue
  897. }
  898. set tmp1($rid) 1
  899. # Determine client ID
  900. set cid [$self req2client $tmp2($rid) [$rv value] $j]
  901. # Instead of scheduling a request right now, let's do it
  902. # step by step so that scheduler won't complain.
  903. lappend reqlist_ $cid $tmp2($rid)
  904. # XXX Interval 500 second. Should adjust it according to
  905. # maximum page size
  906. incr time 50
  907. incr i
  908. }
  909. $self next-request
  910. }
  911. # Get the first request from reqlist_
  912. Test/media5 instproc next-request {} {
  913. $self instvar server_ cache_ client_ reqlist_ ns_
  914. set cid [lindex $reqlist_ 0]
  915. set pagenum [lindex $reqlist_ 1]
  916. set reqlist_ [lrange $reqlist_ 2 end]
  917. $client_($cid) send-request $cache_(0) GET $server_(0):$pagenum
  918. # Do our next request 50 seconds later
  919. if {[llength $reqlist_] > 0} {
  920. # If we still have more requests, continue
  921. $ns_ at [expr [$ns_ now] + 50] "$self next-request"
  922. }
  923. }
  924. # Use a random number and the upper bound of the random number to
  925. # decide whether the request goes to client 0 or 1
  926. Test/media5 instproc req2client { pagenum ran max } {
  927. # Most requests go to the low-bw client
  928. set thresh [expr $max * 0.95]
  929. if {$ran > $thresh} {
  930. return 0
  931. } else {
  932. return 1
  933. }
  934. }
  935. # 95% requests go to the high-bw client
  936. #Class Test/media5a -superclass Test/media5
  937. #Test/media5a instproc req2client { pagenum ran max } {
  938. # # Distribute 95% requests of all pages to the high-bw client,
  939. # # and 5% to the low-bw client
  940. # set thresh [expr $max*0.05]
  941. # if {$ran > $thresh} {
  942. # return 0
  943. # } else {
  944. # return 1
  945. # }
  946. #}
  947. # 50:50 distribution among 2 clients
  948. #Class Test/media5b -superclass Test/media5
  949. #
  950. #Test/media5b instproc req2client { pagenum ran max } {
  951. # # Uniformly distribute requests of all pages
  952. # set thresh [expr $max*0.5]
  953. # if {$ran > $thresh} {
  954. # return 0
  955. # } else {
  956. # return 1
  957. # }
  958. #}
  959. # Configurations
  960. global raw_opt_info
  961. set raw_opt_info {
  962. # Random number seed; default is 0, so ns will give a
  963. # diff. one on each invocation.
  964. # XXX Get a "good" seed from predef_seeds[] in rng.cc
  965. ns-random-seed 188312339
  966. # Animation options; complete traces are useful
  967. # for nam only, so do those only when a tracefile
  968. # is being used for nam
  969. enable-log 1
  970. duration 500
  971. # Packet size configurations
  972. cache-ims-size 50
  973. cache-ref-size 50
  974. server-inv-size 43
  975. client-req-size 43
  976. # request intervals
  977. avg-req-interval 1000
  978. req-dist Poisson
  979. # Cache size factor, i.e., what % of the total stream size
  980. cache-sizefac 0.5
  981. # Object layers
  982. obj-layer 8
  983. # One media stream takes 5 layers, and 512K in total
  984. avg-page-size 512000
  985. # Number of pages
  986. num-pages 1
  987. # Total number of requests
  988. total-requests 10
  989. }
  990. #----------------------------------------------------------------------
  991. # Execution starts...
  992. #----------------------------------------------------------------------
  993. run