PageRenderTime 46ms CodeModel.GetById 13ms RepoModel.GetById 1ms app.codeStats 0ms

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

http://uu-cope.googlecode.com/
TCL | 2264 lines | 1517 code | 364 blank | 383 comment | 106 complexity | 8fdd937cad856ddaeb8074f423a55d86 MD5 | raw file
Possible License(s): LGPL-2.0

Large files files are truncated, but you can click here to view the full file

  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-webcache.tcl,v 1.25 2006/01/24 23:00:08 sallyfloyd Exp $
  9. #----------------------------------------------------------------------
  10. # Related Files
  11. #----------------------------------------------------------------------
  12. source misc.tcl
  13. source topologies.tcl
  14. remove-all-packet-headers ; # removes all except common
  15. add-packet-header Flags IP TCP HttpInval ; # hdrs reqd for validation test
  16. # FOR UPDATING GLOBAL DEFAULTS:
  17. Agent/TCP set precisionReduce_ false ; # default changed on 2006/1/24.
  18. Agent/TCP set rtxcur_init_ 6.0 ; # Default changed on 2006/01/21
  19. Agent/TCP set updated_rttvar_ false ; # Variable added on 2006/1/21
  20. Agent/TCP set tcpTick_ 0.1
  21. # The default for tcpTick_ is being changed to reflect a changing reality.
  22. Agent/TCP set rfc2988_ false
  23. # The default for rfc2988_ is being changed to true.
  24. Agent/TCP set exitFastRetrans_ false
  25. #
  26. Agent/TCP set useHeaders_ false
  27. # The default is being changed to useHeaders_ true.
  28. Agent/TCP set windowInit_ 1
  29. # The default is being changed to 2.
  30. Agent/TCP set singledup_ 0
  31. # The default is being changed to 1
  32. Agent/TCP set minrto_ 0
  33. # The default is being changed to minrto_ 1
  34. Agent/TCP set timerfix_ false
  35. # The default is being changed to true.
  36. Agent/TCP set syn_ false
  37. Agent/TCP set delay_growth_ false
  38. # In preparation for changing the default values for syn_ and delay_growth_.
  39. #----------------------------------------------------------------------
  40. # Misc setup
  41. #----------------------------------------------------------------------
  42. set tcl_precision 10
  43. #----------------------------------------------------------------------
  44. # Topologies for cache testing
  45. #----------------------------------------------------------------------
  46. # Simplest topology: 1 client + 1 cache + 1 server
  47. Class Topology/cache0 -superclass SkelTopology
  48. Topology/cache0 instproc init ns {
  49. $self next
  50. $self instvar node_
  51. set node_(c) [$ns node]
  52. set node_(e) [$ns node]
  53. set node_(s) [$ns node]
  54. $ns duplex-link $node_(s) $node_(e) 1.5Mb 50ms DropTail
  55. $ns duplex-link $node_(e) $node_(c) 10Mb 2ms DropTail
  56. $ns duplex-link-op $node_(c) $node_(e) orient right
  57. $ns duplex-link-op $node_(e) $node_(s) orient right
  58. }
  59. # Hierarchical cache, 1 server + 7 cache + 4 clients, server linked to
  60. # a top-level cache
  61. Class Topology/cache2 -superclass SkelTopology
  62. Topology/cache2 instproc init ns {
  63. $self next
  64. $self instvar node_
  65. set node_(c0) [$ns node]
  66. set node_(c1) [$ns node]
  67. set node_(c2) [$ns node]
  68. set node_(c3) [$ns node]
  69. set node_(e0) [$ns node]
  70. set node_(e1) [$ns node]
  71. set node_(e2) [$ns node]
  72. set node_(e3) [$ns node]
  73. set node_(e4) [$ns node]
  74. set node_(e5) [$ns node]
  75. set node_(e6) [$ns node]
  76. set node_(s0) [$ns node]
  77. # between top-level cache: OC3
  78. $ns duplex-link $node_(e0) $node_(e1) 155Mb 100ms DropTail
  79. # server to top-level cache and inside a cache hierarchy: T1
  80. $ns duplex-link $node_(s0) $node_(e0) 1.5Mb 50ms DropTail
  81. $ns duplex-link $node_(e0) $node_(e2) 1.5Mb 50ms DropTail
  82. $ns duplex-link $node_(e0) $node_(e3) 1.5Mb 50ms DropTail
  83. $ns duplex-link $node_(e1) $node_(e4) 1.5Mb 50ms DropTail
  84. $ns duplex-link $node_(e1) $node_(e5) 1.5Mb 50ms DropTail
  85. $ns duplex-link $node_(e2) $node_(e6) 10Mb 2ms DropTail
  86. # client to caches: 10Mb ethernet
  87. $ns duplex-link $node_(e2) $node_(c0) 10Mb 2ms DropTail
  88. $ns duplex-link $node_(e6) $node_(c1) 10Mb 2ms DropTail
  89. $ns duplex-link $node_(e4) $node_(c2) 10Mb 2ms DropTail
  90. $ns duplex-link $node_(e1) $node_(c3) 10Mb 2ms DropTail
  91. $ns duplex-link-op $node_(s0) $node_(e0) orient right
  92. $ns duplex-link-op $node_(e0) $node_(e1) orient right
  93. $ns duplex-link-op $node_(e0) $node_(e2) orient left-down
  94. $ns duplex-link-op $node_(e0) $node_(e3) orient right-down
  95. $ns duplex-link-op $node_(e2) $node_(e6) orient down
  96. $ns duplex-link-op $node_(c0) $node_(e2) orient right
  97. $ns duplex-link-op $node_(c1) $node_(e6) orient right
  98. $ns duplex-link-op $node_(e1) $node_(e4) orient left-down
  99. $ns duplex-link-op $node_(e1) $node_(e5) orient right-down
  100. $ns duplex-link-op $node_(e4) $node_(c2) orient down
  101. $ns duplex-link-op $node_(e1) $node_(c3) orient right
  102. $self checkConfig $class $ns
  103. }
  104. # Hierarchical cache, 1 server + 7 cache + 4 clients, server linked to a
  105. # second-level cache.
  106. Class Topology/cache3 -superclass SkelTopology
  107. Topology/cache3 instproc init ns {
  108. $self next
  109. $self instvar node_
  110. set node_(c0) [$ns node]
  111. set node_(c1) [$ns node]
  112. set node_(c2) [$ns node]
  113. set node_(c3) [$ns node]
  114. set node_(e0) [$ns node]
  115. set node_(e1) [$ns node]
  116. set node_(e2) [$ns node]
  117. set node_(e3) [$ns node]
  118. set node_(e4) [$ns node]
  119. set node_(e5) [$ns node]
  120. set node_(e6) [$ns node]
  121. set node_(s0) [$ns node]
  122. # between top-level cache: OC3
  123. $ns duplex-link $node_(e0) $node_(e1) 155Mb 100ms DropTail
  124. # server to top-level cache and inside a cache hierarchy: T1
  125. $ns duplex-link $node_(s0) $node_(e5) 1.5Mb 50ms DropTail
  126. $ns duplex-link $node_(e0) $node_(e2) 1.5Mb 50ms DropTail
  127. $ns duplex-link $node_(e0) $node_(e3) 1.5Mb 50ms DropTail
  128. $ns duplex-link $node_(e1) $node_(e4) 1.5Mb 50ms DropTail
  129. $ns duplex-link $node_(e1) $node_(e5) 1.5Mb 50ms DropTail
  130. $ns duplex-link $node_(e2) $node_(e6) 10Mb 2ms DropTail
  131. # client to caches: 10Mb ethernet
  132. $ns duplex-link $node_(e2) $node_(c0) 10Mb 2ms DropTail
  133. $ns duplex-link $node_(e6) $node_(c1) 10Mb 2ms DropTail
  134. $ns duplex-link $node_(e4) $node_(c2) 10Mb 2ms DropTail
  135. $ns duplex-link $node_(e1) $node_(c3) 10Mb 2ms DropTail
  136. $ns duplex-link-op $node_(e5) $node_(s0) orient right
  137. $ns duplex-link-op $node_(e0) $node_(e1) orient right
  138. $ns duplex-link-op $node_(e0) $node_(e2) orient left-down
  139. $ns duplex-link-op $node_(e0) $node_(e3) orient right-down
  140. $ns duplex-link-op $node_(e2) $node_(e6) orient down
  141. $ns duplex-link-op $node_(c0) $node_(e2) orient right
  142. $ns duplex-link-op $node_(c1) $node_(e6) orient right
  143. $ns duplex-link-op $node_(e1) $node_(e4) orient left-down
  144. $ns duplex-link-op $node_(e1) $node_(e5) orient right-down
  145. $ns duplex-link-op $node_(e4) $node_(c2) orient down
  146. $ns duplex-link-op $node_(e1) $node_(c3) orient right
  147. $self checkConfig $class $ns
  148. }
  149. # Two level hierarchical cache. 1 server + 1 TLC + n 2nd caches with one
  150. # bottleneck link connecting TCL to other caches + n clients
  151. Class Topology/BottleNeck -superclass SkelTopology
  152. Class Topology/BottleNeck -superclass SkelTopology
  153. Topology/BottleNeck instproc init { ns } {
  154. $self next
  155. $self instvar node_
  156. global opts
  157. if [info exists opts(num-2nd-cache)] {
  158. set n $opts(num-2nd-cache)
  159. } else {
  160. error "Topology/BottleNeck requires option num-2nd-cache"
  161. }
  162. set node_(s0) [$ns node]
  163. # TLC is node e0
  164. for {set i 0} {$i <= $n} {incr i} {
  165. set node_(e$i) [$ns node]
  166. }
  167. # We create clients separately so we have consecutive ids for all
  168. # clients
  169. for {set i 0} {$i < $n} {incr i} {
  170. set node_(c$i) [$ns node]
  171. }
  172. # Between TLC and server: T1
  173. # $ns duplex-link $node_(e$n) $node_(s0) 1.5Mb 100ms DropTail
  174. # Server attached to a client via a LAN
  175. $ns duplex-link $node_(e0) $node_(s0) 1.5Mb 100ms DropTail
  176. #$ns duplex-link $node_(e0) $node_(s0) 10Mb 2ms DropTail
  177. # Bottleneck link
  178. $self instvar dummy_
  179. set dummy_ [$ns node]
  180. $ns duplex-link $node_(e$n) $dummy_ 1.5Mb 50ms DropTail
  181. for {set i 0} {$i < $n} {incr i} {
  182. $ns duplex-link $node_(e$i) $dummy_ 1.5Mb 50ms DropTail
  183. $ns duplex-link $node_(c$i) $node_(e$i) 10Mb 2ms DropTail
  184. }
  185. $self checkConfig $class $ns
  186. }
  187. Topology/BottleNeck instproc start-monitor { ns } {
  188. $self instvar qmon_ node_ dummy_
  189. # Traffic between server and its primary cache
  190. set qmon_(svr_f) [$ns monitor-queue $node_(s0) $node_(e0) ""]
  191. set qmon_(svr_t) [$ns monitor-queue $node_(e0) $node_(s0) ""]
  192. global opts
  193. set n $opts(num-2nd-cache)
  194. # Traffic between TLC and all others
  195. set qmon_(btnk_f) [$ns monitor-queue $node_(e$n) $dummy_ ""]
  196. set qmon_(btnk_t) [$ns monitor-queue $dummy_ $node_(e$n) ""]
  197. # Traffic for all the rest links
  198. for {set i 0} {$i < $n} {incr i} {
  199. set qmon_(e${i}_d_f) [$ns monitor-queue $node_(e$i) $dummy_ ""]
  200. set qmon_(e${i}_d_t) [$ns monitor-queue $dummy_ $node_(e$i) ""]
  201. set qmon_(e${i}_c${i}_f) \
  202. [$ns monitor-queue $node_(e$i) $node_(c$i) ""]
  203. set qmon_(e${i}_c${i}_t) \
  204. [$ns monitor-queue $node_(c$i) $node_(e$i) ""]
  205. }
  206. #puts "Monitors started at time [$ns now]"
  207. }
  208. Topology/BottleNeck instproc mon-stat {} {
  209. $self instvar qmon_
  210. set total_bw 0
  211. foreach n [array names qmon_] {
  212. set total_bw [expr $total_bw + \
  213. double([$qmon_($n) set bdepartures_])]
  214. }
  215. set svr_bw [expr double([$qmon_(svr_f) set bdepartures_]) + \
  216. double([$qmon_(svr_t) set bdepartures_])]
  217. set btnk_bw [expr double([$qmon_(btnk_f) set bdepartures_]) + \
  218. double([$qmon_(btnk_t) set bdepartures_])]
  219. return [list total_bw $total_bw svr_bw $svr_bw btnk_bw $btnk_bw]
  220. }
  221. #
  222. # Three level hierarchical cache, binary tree.
  223. #
  224. Class Topology/cache4 -superclass SkelTopology
  225. Topology/cache4 instproc init { ns } {
  226. $self next
  227. $self instvar node_
  228. # server attached to a leaf cache
  229. set node_(s0) [$ns node]
  230. # TLC is node e0
  231. for {set i 0} {$i <= 6} {incr i} {
  232. set node_(e$i) [$ns node]
  233. }
  234. # All clients attached to leaf caches
  235. for {set i 0} {$i <= 3} {incr i} {
  236. set node_(c$i) [$ns node]
  237. }
  238. # Bottleneck link between TLC and other caches
  239. set dummy [$ns node]
  240. $ns duplex-link $node_(e0) $dummy 100Mb 1ms DropTail
  241. $ns duplex-link $dummy $node_(e1) 1.5Mb 50ms DropTail
  242. $ns duplex-link $dummy $node_(e2) 1.5Mb 50ms DropTail
  243. $ns duplex-link $node_(e1) $node_(e3) 1.5Mb 10ms DropTail
  244. $ns duplex-link $node_(e1) $node_(e4) 1.5Mb 10ms DropTail
  245. $ns duplex-link $node_(e2) $node_(e5) 1.5Mb 10ms DropTail
  246. $ns duplex-link $node_(e2) $node_(e6) 1.5Mb 10ms DropTail
  247. $ns duplex-link $node_(e3) $node_(c0) 10Mb 1ms DropTail
  248. $ns duplex-link $node_(e4) $node_(c1) 10Mb 1ms DropTail
  249. $ns duplex-link $node_(e5) $node_(c2) 10Mb 1ms DropTail
  250. $ns duplex-link $node_(e6) $node_(c3) 10Mb 1ms DropTail
  251. $ns duplex-link $node_(s0) $node_(e3) 10Mb 10ms DropTail
  252. $ns duplex-link-op $node_(e0) $dummy orient down
  253. $ns duplex-link-op $dummy $node_(e1) orient left-down
  254. $ns duplex-link-op $dummy $node_(e2) orient right-down
  255. $ns duplex-link-op $node_(e1) $node_(e3) orient left-down
  256. $ns duplex-link-op $node_(e1) $node_(e4) orient right-down
  257. $ns duplex-link-op $node_(e2) $node_(e5) orient left-down
  258. $ns duplex-link-op $node_(e2) $node_(e6) orient right-down
  259. $ns duplex-link-op $node_(e3) $node_(c0) orient down
  260. $ns duplex-link-op $node_(e4) $node_(c1) orient down
  261. $ns duplex-link-op $node_(e5) $node_(c2) orient down
  262. $ns duplex-link-op $node_(e6) $node_(c3) orient down
  263. $ns duplex-link-op $node_(s0) $node_(e3) orient right
  264. $self checkConfig $class $ns
  265. }
  266. # Same as Topology/cache4, except adding a dynamic links
  267. Class Topology/cache4d -superclass Topology/cache4
  268. Topology/cache4d instproc init { ns } {
  269. $self next $ns
  270. $self instvar node_
  271. $ns rtmodel-at 500 down $node_(s0) $node_(e3)
  272. $ns rtmodel-at 1000 up $node_(s0) $node_(e3)
  273. $self checkConfig $class $ns
  274. }
  275. # 2-level topology with direct links from server to every client
  276. # Compare invalidation vs ttl with direct request
  277. Class Topology/cache5 -superclass SkelTopology
  278. Topology/cache5 instproc init { ns } {
  279. $self next
  280. $self instvar node_
  281. global opts
  282. if [info exists opts(num-2nd-cache)] {
  283. set n $opts(num-2nd-cache)
  284. } else {
  285. error "Topology/BottleNeck requires option num-2nd-cache"
  286. }
  287. set node_(s0) [$ns node]
  288. # TLC is node e0
  289. for {set i 0} {$i <= $n} {incr i} {
  290. set node_(e$i) [$ns node]
  291. }
  292. # We create clients separately so we have consecutive ids for all
  293. # clients
  294. for {set i 0} {$i < $n} {incr i} {
  295. set node_(c$i) [$ns node]
  296. }
  297. set sn [$ns node] ;# Dummy node for bottleneck link
  298. $ns duplex-link $node_(e$n) $sn 1.5Mb 50ms DropTail
  299. # Traffic on the duplex link.
  300. $self instvar qmon_
  301. set qmon_(btnk_f) [$ns monitor-queue $node_(e$n) $sn ""]
  302. set qmon_(btnk_t) [$ns monitor-queue $sn $node_(e$n) ""]
  303. for {set i 0} {$i < $n} {incr i} {
  304. $ns duplex-link $node_(e$i) $sn 1.5Mb 50ms DropTail
  305. $ns duplex-link $node_(c$i) $node_(e$i) 10Mb 2ms DropTail
  306. # Server attached to all clients, but its parent cache is e0
  307. # delay to server is proportional to its distance to e0
  308. set delay [expr 5 + $i*5]ms
  309. $ns duplex-link $node_(e$i) $node_(s0) 1.5Mb $delay DropTail
  310. set qmon_(svr_f$i) [$ns monitor-queue $node_(s0) $node_(e$i) ""]
  311. set qmon_(svr_t$i) [$ns monitor-queue $node_(e$i) $node_(s0) ""]
  312. }
  313. $self checkConfig $class $ns
  314. }
  315. #
  316. # Simple 2 node topology testing SimpleTcp and TcpApp
  317. #
  318. Class Topology/2node -superclass SkelTopology
  319. Topology/2node instproc init { ns } {
  320. $self next
  321. $self instvar node_
  322. set node_(0) [$ns node]
  323. set node_(1) [$ns node]
  324. $ns duplex-link $node_(0) $node_(1) 1.5Mb 10ms DropTail
  325. $ns duplex-link-op $node_(0) $node_(1) orient right
  326. $self checkConfig $class $ns
  327. }
  328. #
  329. # 3 node linear topology testing SimpleTcp and TcpApp
  330. #
  331. Class Topology/3node -superclass SkelTopology
  332. Topology/3node instproc init { ns } {
  333. $self next
  334. $self instvar node_
  335. set node_(0) [$ns node]
  336. set node_(1) [$ns node]
  337. set node_(2) [$ns node]
  338. $ns duplex-link $node_(0) $node_(1) 1.5Mb 50ms DropTail
  339. $ns duplex-link $node_(1) $node_(2) 1.5Mb 50ms DropTail
  340. $ns duplex-link-op $node_(0) $node_(1) orient right
  341. $ns duplex-link-op $node_(1) $node_(2) orient right
  342. }
  343. #
  344. # 5 node topology testing HTTP cache, with 3 clients, one server and
  345. # one cache
  346. #
  347. Class Topology/5node -superclass SkelTopology
  348. Topology/5node instproc init { ns } {
  349. $self next
  350. $self instvar node_
  351. for {set i 0} {$i < 5} {incr i} {
  352. set node_($i) [$ns node]
  353. }
  354. $ns duplex-link $node_(3) $node_(4) 1Mb 50ms DropTail
  355. $ns duplex-link $node_(0) $node_(3) 1Mb 50ms DropTail
  356. $ns duplex-link $node_(1) $node_(3) 1Mb 50ms DropTail
  357. $ns duplex-link $node_(2) $node_(3) 1Mb 50ms DropTail
  358. $ns duplex-link-op $node_(4) $node_(3) orient right
  359. $ns duplex-link-op $node_(0) $node_(3) orient down
  360. $ns duplex-link-op $node_(1) $node_(3) orient left
  361. $ns duplex-link-op $node_(2) $node_(3) orient up
  362. }
  363. #----------------------------------------------------------------------
  364. # Section 1: Base test class
  365. #----------------------------------------------------------------------
  366. Class Test
  367. Test instproc init-instvar v {
  368. set cl [$self info class]
  369. while { "$cl" != "" } {
  370. foreach c $cl {
  371. if ![catch "$c set $v" val] {
  372. $self set $v $val
  373. return
  374. }
  375. }
  376. set parents ""
  377. foreach c $cl {
  378. if { $cl != "Object" } {
  379. set parents "$parents [$c info superclass]"
  380. }
  381. }
  382. set cl $parents
  383. }
  384. }
  385. Test instproc init {} {
  386. $self instvar ns_ trace_ net_ defNet_ testName_ node_ test_ topo_
  387. set ns_ [new Simulator -multicast on]
  388. set cls [$self info class]
  389. set cls [split $cls /]
  390. set test_ [lindex $cls [expr [llength $cls] - 1]]
  391. global opts
  392. ns-random $opts(ns-random-seed)
  393. if $opts(nam-trace-all) {
  394. #set trace_ [open "$test_" w]
  395. # test-all-template1 requires data file to be temp.rands :(
  396. set trace_ [open "temp.rands" w]
  397. $ns_ trace-all $trace_
  398. }
  399. if ![info exists opts(net)] {
  400. set net_ $defNet_
  401. } else {
  402. set net_ $opts(net)
  403. }
  404. if ![Topology/$defNet_ info subclass Topology/$net_] {
  405. global argv0
  406. puts "$argv0: cannot run test $test_ over topology $net_"
  407. exit 1
  408. }
  409. set topo_ [new Topology/$net_ $ns_]
  410. foreach i [$topo_ array names node_] {
  411. # This would be cool, but lets try to be compatible
  412. # with test-suite.tcl as far as possible.
  413. #
  414. # $self instvar $i
  415. # set $i [$topo_ node? $i]
  416. #
  417. set node_($i) [$topo_ node? $i]
  418. }
  419. if {$net_ == $defNet_} {
  420. set testName_ "$test_"
  421. } else {
  422. set testName_ "$test_:$net_"
  423. }
  424. }
  425. # Use this so derived class would have a chance to overwrite the default net
  426. # of parent classes
  427. Test instproc set-defnet { defnet } {
  428. $self instvar defNet_
  429. if ![info exists defNet_] {
  430. set defNet_ $defnet
  431. }
  432. }
  433. Test instproc inherit-set { name val } {
  434. $self instvar $name
  435. if ![info exists $name] {
  436. set $name $val
  437. }
  438. }
  439. Test instproc write-testconf { file } {
  440. $self instvar test_ net_
  441. puts $file "# TESTNAME: $test_"
  442. puts $file "# TOPOLOGY: $net_"
  443. global opts
  444. foreach n [lsort [array names opts]] {
  445. # XXX Remove this after validating existing traces
  446. if {$n == "quiet"} { continue }
  447. puts $file "# $n: $opts($n)"
  448. }
  449. }
  450. Test instproc set-routing {} {
  451. }
  452. Test instproc set-members {} {
  453. }
  454. Test instproc finish {} {
  455. $self instvar ns_ trace_
  456. if [info exists trace_] {
  457. $ns_ flush-trace
  458. close $trace_
  459. }
  460. exit 0
  461. }
  462. Test instproc run {} {
  463. $self instvar finishTime_ ns_ trace_
  464. global opts
  465. if $opts(nam-trace-all) {
  466. $self write-testconf $trace_
  467. }
  468. $self set-routing
  469. $self set-members
  470. $ns_ at $finishTime_ "$self finish"
  471. $ns_ run
  472. }
  473. # option processing copied from John's ~ns/tcl/ex/rbp_demo.tcl
  474. proc default_options {} {
  475. global opts opt_wants_arg raw_opt_info
  476. # raw_opt_info can be set in user's script
  477. while {$raw_opt_info != ""} {
  478. if {![regexp "^\[^\n\]*\n" $raw_opt_info line]} {
  479. break
  480. }
  481. regsub "^\[^\n\]*\n" $raw_opt_info {} raw_opt_info
  482. set line [string trim $line]
  483. if {[regexp "^\[ \t\]*#" $line]} {
  484. continue
  485. }
  486. if {$line == ""} {
  487. continue
  488. } elseif [regexp {^([^ ]+)[ ]+([^ ]+)$} $line dummy key value] {
  489. set opts($key) $value
  490. set opt_wants_arg($key) 1
  491. } elseif [regexp {^([^ ]+)[ ]*$} $line dummy key] {
  492. # So we don't need to assign opt($key)
  493. set opt_wants_arg($key) 1
  494. } else {
  495. set opt_wants_arg($key) 0
  496. error "unknown stuff \"$line\" in raw_opt_info"
  497. }
  498. }
  499. }
  500. proc process_args {} {
  501. global argc argv opts opt_wants_arg
  502. default_options
  503. for {set i 0} {$i < $argc} {incr i} {
  504. set key [lindex $argv $i]
  505. if {$key == "-?" || $key == "--help" || $key == "-help" || $key == "-h"} {
  506. usage
  507. }
  508. regsub {^--} $key {} key
  509. if {![info exists opt_wants_arg($key)]} {
  510. #puts stderr "unknown option $key";
  511. #usage
  512. continue
  513. }
  514. if {$opt_wants_arg($key)} {
  515. incr i
  516. set opts($key) [lindex $argv $i]
  517. } else {
  518. set opts($key) [expr !opts($key)]
  519. }
  520. }
  521. }
  522. # Startup procedure, called at the end of the script
  523. proc run {} {
  524. global argc argv opts raw_opt_info
  525. # We don't actually have any real arguments, but we do have
  526. # various initializations, which the script depends on.
  527. process_args
  528. #set prot $opts(prot)
  529. # Calling convention by test-all-template1:
  530. # ns <file> <test> [QUIET]
  531. set prot [lindex $argv 0]
  532. set opts(prot) $prot
  533. if {$argc > 1} {
  534. set opts(quiet) 1
  535. } else {
  536. set opts(quiet) 0
  537. }
  538. set test [new Test/$prot]
  539. $test run
  540. }
  541. #----------------------------------------------------------------------
  542. # Section 2 Base class for cache testing
  543. #----------------------------------------------------------------------
  544. Class Test-Cache -superclass Test
  545. # Page lifetime is a uniform distribution in [min, max].
  546. Test-Cache set startTime_ 10
  547. Test-Cache instproc init {} {
  548. $self next
  549. $self instvar startTime_
  550. set startTime_ [$class set startTime_]
  551. $self set-pagepool
  552. global opts
  553. if [info exists opts(hb-interval)] {
  554. Http/Client set hb_interval_ $opts(hb-interval)
  555. Http/Cache/Inval/Mcast set hb_interval_ $opts(hb-interval)
  556. Http/Server/Inval/Yuc set hb_interval_ $opts(hb-interval)
  557. }
  558. if [info exists opts(upd-interval)] {
  559. Http/Cache/Inval/Mcast set upd_interval_ $opts(upd-interval)
  560. }
  561. if [info exists opts(cache-ims-size)] {
  562. Http set IMSSize_ $opts(cache-ims-size)
  563. }
  564. if [info exists opt(server-inv-size)] {
  565. Http set INVSize_ $opt(server-inv-size)
  566. }
  567. if [info exists opts(cache-ref-size)] {
  568. Http set REFSize_ $opts(cache-ref-size)
  569. }
  570. if [info exists opts(client-req-size)] {
  571. Http set REQSize_ $opts(client-req-size)
  572. }
  573. $self instvar ns_
  574. $ns_ color 40 red
  575. $ns_ color 41 orange
  576. # Set default transport to SimpleTcp
  577. Http set TRANSPORT_ SimpleTcp
  578. }
  579. # Allow global options to preempt, and derived classes to overwrite.
  580. Test-Cache instproc set-server-type { servertype } {
  581. $self instvar serverType_
  582. global opts
  583. if [info exists opts(server)] {
  584. set serverType_ $opts(server)
  585. } else {
  586. set serverType_ $servertype
  587. }
  588. }
  589. Test-Cache instproc set-cache-type { cachetype } {
  590. $self instvar cacheType_
  591. global opts
  592. if [info exists opts(cache)] {
  593. set cacheType_ $opts(cache)
  594. } else {
  595. set cacheType_ $cachetype
  596. }
  597. }
  598. Test-Cache instproc set-client-type { clienttype } {
  599. $self instvar clientType_
  600. global opts
  601. if [info exists opts(client)] {
  602. set clientType_ $opts(client)
  603. } else {
  604. set clientType_ $clienttype
  605. }
  606. }
  607. Test-Cache instproc set-pagepool {} {
  608. $self instvar startTime_ finishTime_ pgp_
  609. global opts
  610. if [info exists opts(page-file)] {
  611. set pgp_ [new PagePool/Trace $opts(page-file)]
  612. set max [$pgp_ get-poolsize]
  613. set tmp [new RandomVariable/Uniform]
  614. $tmp set min_ 0
  615. $tmp set max_ [expr $max - 1]
  616. $pgp_ ranvar $tmp
  617. $pgp_ set start_time_ $startTime_
  618. set finishTime_ [expr [$pgp_ get-duration] + $startTime_]
  619. } else {
  620. # Use PagePool/Math
  621. set pgp_ [new PagePool/Math]
  622. # Size generator
  623. set tmp [new RandomVariable/Constant]
  624. $tmp set val_ $opts(avg-page-size)
  625. $pgp_ ranvar-size $tmp
  626. # Age generator
  627. $self instvar ageRNG_
  628. if ![info exists ageRNG_] {
  629. set ageRNG_ [new RNG]
  630. $ageRNG_ seed $opts(ns-random-seed)
  631. }
  632. set tmp [new RandomVariable/Exponential]
  633. $tmp use-rng $ageRNG_
  634. $tmp set avg_ $opts(avg-page-age)
  635. $pgp_ ranvar-age $tmp
  636. $pgp_ set start_time_ $startTime_
  637. set finishTime_ [expr $startTime_ + $opts(duration)]
  638. }
  639. # puts "Start at $startTime_, stop at $finishTime_"
  640. }
  641. Test-Cache instproc set-req-generator { client } {
  642. $self instvar pgp_ reqRNG_
  643. global opts
  644. if ![info exists reqRNG_] {
  645. set reqRNG_ [new RNG]
  646. $reqRNG_ seed $opts(ns-random-seed)
  647. }
  648. set tmp [new RandomVariable/Exponential]
  649. $tmp use-rng $reqRNG_
  650. $tmp set avg_ $opts(avg-req-interval)
  651. $client set-interval-generator $tmp
  652. $client set-page-generator $pgp_
  653. }
  654. Test-Cache instproc create-members {} {
  655. $self instvar client_ server_ cache_ log_ test_ pgp_ node_ ns_ \
  656. serverType_ cacheType_ clientType_
  657. set st $serverType_
  658. set ct $cacheType_
  659. set lt $clientType_
  660. global opts
  661. if $opts(enable-log) {
  662. set log_ [open "$test_.log" w]
  663. $self write-testconf $log_
  664. }
  665. foreach n [array names node_] {
  666. set type [string range $n 0 0]
  667. set num [string range $n 1 end]
  668. if {$num == ""} {
  669. set num 0
  670. }
  671. switch $type {
  672. s {
  673. set server_($num) [new Http/Server$st $ns_ $node_($n)]
  674. $server_($num) set-page-generator $pgp_
  675. if $opts(enable-log) {
  676. $server_($num) log $log_
  677. }
  678. }
  679. e {
  680. set cache_($num) [new Http/Cache$ct $ns_ $node_($n)]
  681. if $opts(enable-log) {
  682. $cache_($num) log $log_
  683. }
  684. }
  685. c {
  686. set client_($num) [new Http/Client$lt $ns_ $node_($n)]
  687. $self set-req-generator $client_($num)
  688. if $opts(enable-log) {
  689. $client_($num) log $log_
  690. }
  691. }
  692. }
  693. }
  694. }
  695. Test-Cache instproc set-routing {} {
  696. $self instvar ns_ mh_
  697. set mh_ [$ns_ mrtproto CtrMcast {}]
  698. $ns_ rtproto Session
  699. }
  700. Test-Cache instproc set-members {} {
  701. $self instvar ns_ finishTime_ startTime_
  702. $ns_ at $startTime_ "$self start-connection"
  703. # $ns_ at $finishTime_ "$self finish-connection"
  704. }
  705. Test-Cache instproc set-groups {} {
  706. # Dummy proc
  707. }
  708. Test-Cache instproc start-connection {} {
  709. $self instvar ns_
  710. $self create-members
  711. $self set-connections
  712. $self set-groups
  713. # Let initializations settles down, then start requests
  714. $ns_ at [expr [$ns_ now] + 10] "$self start-requests"
  715. }
  716. # Empty
  717. Test-Cache instproc set-groups {} {
  718. }
  719. # Empty
  720. Test-Cache instproc set-connections {} {
  721. }
  722. Test-Cache instproc finish {} {
  723. $self instvar log_
  724. if [info exists log_] {
  725. close $log_
  726. }
  727. $self next
  728. }
  729. #----------------------------------------------------------------------
  730. # Section 3:
  731. # Tests of transport protocols and application data transmission over TCP
  732. #----------------------------------------------------------------------
  733. #
  734. # Test SimpleTcp
  735. #
  736. Class Test/SimpleTcp -superclass Test
  737. Test/SimpleTcp instproc init {} {
  738. $self set-defnet 2node
  739. $self next
  740. $self instvar startTime_ finishTime_
  741. set startTime_ 10
  742. set finishTime_ 20
  743. Http set TRANSPORT_ SimpleTcp
  744. }
  745. Test/SimpleTcp instproc set-routing {} {
  746. $self instvar ns_
  747. $ns_ rtproto Session
  748. }
  749. Test/SimpleTcp instproc set-members {} {
  750. $self instvar ns_ src_ dst_ node_ ftp1_
  751. $ns_ at 1.0 "$self start-connection 0 1"
  752. $ns_ at 9.0 "$self finish-connection 0 1"
  753. }
  754. # Connect TCP source and destination after simulator starts
  755. Test/SimpleTcp instproc start-connection { s d } {
  756. $self instvar ns_ src_ dst_ node_
  757. set src_ [new Agent/TCP/SimpleTcp]
  758. set dst_ [new Agent/TCP/SimpleTcp]
  759. $src_ set fid_ 0
  760. $dst_ set fid_ 0
  761. $ns_ attach-agent $node_($s) $src_
  762. $ns_ attach-agent $node_($d) $dst_
  763. $ns_ connect $src_ $dst_
  764. $src_ set dst_addr_ [$dst_ set agent_addr_]
  765. $src_ set dst_port_ [$dst_ set agent_port_]
  766. $src_ set window_ 100
  767. $dst_ listen
  768. $ns_ at [expr [$ns_ now] + 1.0] "$src_ send 1000"
  769. $ns_ at [expr [$ns_ now] + 3.0] "$dst_ send 100"
  770. }
  771. Test/SimpleTcp instproc finish-connection { s d } {
  772. $self instvar ns_ src_ dst_ node_
  773. $src_ close
  774. }
  775. #
  776. # Base class for testing TcpApp over SimpleTcp and FullTcp
  777. #
  778. Class Test-TcpApp -superclass Test
  779. Test-TcpApp instproc set-routing {} {
  780. $self instvar ns_
  781. $ns_ rtproto Session
  782. }
  783. Class Test/TcpApp-2node -superclass Test-TcpApp
  784. Test/TcpApp-2node instproc init {} {
  785. $self set-defnet 2node
  786. $self next
  787. $self instvar startTime_ finishTime_ ns_
  788. set startTime_ 10
  789. set finishTime_ 50
  790. $ns_ color 1 red
  791. $ns_ color 2 blue
  792. }
  793. Test/TcpApp-2node instproc send1 {} {
  794. $self instvar app1_ app2_
  795. $app1_ send 40 "$app2_ recv1 40"
  796. }
  797. Test/TcpApp-2node instproc send2 {} {
  798. $self instvar app1_ app2_ ns_
  799. $app2_ send 1024 "$app1_ recv2 1024"
  800. $ns_ at [expr [$ns_ now] + 1.0] "$self send2"
  801. }
  802. Application/TcpApp instproc recv1 { sz } {
  803. set now [[Simulator instance] now]
  804. #puts "$now app2 receives data $sz bytes from app1"
  805. }
  806. Application/TcpApp instproc recv2 { sz } {
  807. set now [[Simulator instance] now]
  808. #puts "$now app1 receives data $sz bytes from app1"
  809. }
  810. Test/TcpApp-2node instproc set-members {} {
  811. $self instvar app1_ app2_ ns_ node_
  812. set tcp1 [new Agent/TCP/FullTcp]
  813. set tcp2 [new Agent/TCP/FullTcp]
  814. $tcp1 set window_ 100
  815. $tcp1 set fid_ 1
  816. $tcp2 set window_ 100
  817. $tcp2 set fid_ 2
  818. $tcp2 set iss_ 1224
  819. $ns_ attach-agent $node_(0) $tcp1
  820. $ns_ attach-agent $node_(1) $tcp2
  821. $ns_ connect $tcp1 $tcp2
  822. $tcp2 listen
  823. set app1_ [new Application/TcpApp $tcp1]
  824. set app2_ [new Application/TcpApp $tcp2]
  825. $app1_ connect $app2_
  826. $ns_ at 1.0 "$self send1"
  827. $ns_ at 1.2 "$self send2"
  828. }
  829. #----------------------------------------------------------------------
  830. # Section 4: Tests of Cache
  831. #----------------------------------------------------------------------
  832. #
  833. # test simplest http setup: one client + one server
  834. #
  835. Class Test/http1 -superclass Test
  836. Test/http1 instproc init {} {
  837. $self set-defnet 3node
  838. $self next
  839. $self instvar finishTime_
  840. set finishTime_ 40
  841. # Use simple tcp agent
  842. Http set TRANSPORT_ SimpleTcp
  843. }
  844. Test/http1 instproc set-members {} {
  845. $self instvar ns_ src_ dst_ node_ ftp1_
  846. # set ftp1_ [$src_ attach-app FTP]
  847. $ns_ at 1.0 "$self start-connection 1 0"
  848. $ns_ at 9.0 "$self finish-connection 1 0"
  849. $ns_ at 10.0 "$self start-connection 1 2"
  850. $ns_ at 19.0 "$self finish-connection 1 2"
  851. }
  852. # Connect TCP source and destination after simulator starts
  853. Test/http1 instproc start-connection { s d } {
  854. $self instvar ns_ src_ dst_ node_
  855. set src_ [new Http/Client $ns_ $node_($s)]
  856. set dst_ [new Http/Server $ns_ $node_($d)]
  857. $src_ connect $dst_
  858. $src_ send-request $dst_ GET $dst_:1
  859. }
  860. Test/http1 instproc finish-connection { s d } {
  861. $self instvar ns_ src_ dst_ node_
  862. $src_ disconnect $dst_
  863. }
  864. Test/http1 instproc set-routing {} {
  865. $self instvar ns_
  866. $ns_ rtproto Session
  867. }
  868. Class Test/http1f -superclass Test/http1
  869. Test/http1f instproc init args {
  870. eval $self next $args
  871. Http set TRANSPORT_ FullTcp
  872. }
  873. #
  874. # Testing HTTP with one cache, one client and one server
  875. #
  876. Class Test/http2 -superclass Test
  877. Test/http2 instproc init {} {
  878. $self set-defnet 3node
  879. $self next
  880. $self instvar finishTime_
  881. set finishTime_ 40
  882. Http set TRANSPORT_ SimpleTcp
  883. }
  884. Test/http2 instproc set-routing {} {
  885. $self instvar ns_
  886. $ns_ rtproto Session
  887. }
  888. Test/http2 instproc set-members {} {
  889. $self instvar ns_ node_ client_ cache_ server_
  890. set client_ [new Http/Client $ns_ $node_(0)]
  891. set cache_ [new Http/Cache $ns_ $node_(1)]
  892. set server_ [new Http/Server $ns_ $node_(2)]
  893. $ns_ at 1.0 "$self start-connection"
  894. $ns_ at 9.0 "$self finish-connection"
  895. $ns_ at 21.0 "$self start-connection"
  896. $ns_ at 29.0 "$self finish-connection"
  897. }
  898. # Connect TCP source and destination after simulator starts
  899. Test/http2 instproc start-connection {} {
  900. $self instvar ns_ client_ server_ cache_ node_
  901. $client_ connect $cache_
  902. $cache_ connect $server_
  903. $cache_ set-parent $server_
  904. $client_ send-request $cache_ GET $server_:1
  905. }
  906. Test/http2 instproc finish-connection {} {
  907. $self instvar client_ server_ cache_
  908. $client_ disconnect $cache_
  909. $cache_ disconnect $server_
  910. }
  911. Class Test/http2f -superclass Test/http2
  912. Test/http2f instproc init args {
  913. eval $self next $args
  914. Http set TRANSPORT_ FullTcp
  915. }
  916. #----------------------------------------------------------------------
  917. # Testing HTTP with one cache, multiple client and one server
  918. #----------------------------------------------------------------------
  919. Class Test/http3 -superclass Test
  920. Test/http3 instproc init {} {
  921. $self set-defnet 5node
  922. $self next
  923. $self instvar finishTime_
  924. set finishTime_ 40
  925. Http set TRANSPORT_ SimpleTcp
  926. }
  927. Test/http3 instproc set-routing {} {
  928. $self instvar ns_
  929. $ns_ rtproto Session
  930. }
  931. Test/http3 instproc set-members {} {
  932. $self instvar ns_ client_ cache_ server_ node_ test_
  933. set client_(0) [new Http/Client $ns_ $node_(0)]
  934. set client_(1) [new Http/Client $ns_ $node_(1)]
  935. set client_(2) [new Http/Client $ns_ $node_(2)]
  936. set cache_ [new Http/Cache $ns_ $node_(3)]
  937. set server_ [new Http/Server $ns_ $node_(4)]
  938. $ns_ at 1.0 "$self start-connection"
  939. $ns_ at 9.0 "$self finish-connection"
  940. # XXX
  941. #
  942. # (1) If we set connection restarts time to 10.0, then we may
  943. # have a request sent out at 10.0 *before* the connection is
  944. # actually re-established, which will result in the lose of a
  945. # request packet and the blocking of subsequent requests.
  946. #
  947. # (2) Currently when a connection is shut down, we do *NOT*
  948. # clean up pending requests. This will result in the possible
  949. # blocking of requests after the connection is re-established.
  950. # This test illustrates this effect.
  951. #
  952. # The cleaning of a cache after disconnection is currently *NOT*
  953. # implemented. It can be disconnected but its behavior after
  954. # re-connection is not defined. NOTE: disconnection means
  955. # explicitly call Http::disconnect(). Link dynamics and losses
  956. # are supported.
  957. $ns_ at 9.9 "$self start-connection"
  958. $ns_ at 19.0 "$self finish-connection"
  959. }
  960. # Connect TCP source and destination after simulator starts
  961. Test/http3 instproc start-connection {} {
  962. $self instvar ns_ client_ server_ cache_ node_
  963. $client_(0) connect $cache_
  964. $client_(1) connect $cache_
  965. $client_(2) connect $cache_
  966. $cache_ connect $server_
  967. $cache_ set-parent $server_
  968. $self start-request
  969. }
  970. Test/http3 instproc start-request {} {
  971. $self instvar client_ ns_ cache_ server_
  972. $client_(0) send-request $cache_ GET $server_:0
  973. set tmp [expr [$ns_ now] + 1]
  974. $ns_ at $tmp "$client_(1) send-request $cache_ GET $server_:1"
  975. set tmp [expr $tmp + 1]
  976. $ns_ at $tmp "$client_(2) send-request $cache_ GET $server_:0"
  977. set tmp [expr $tmp + 2]
  978. $ns_ at $tmp "$self start-request"
  979. }
  980. Test/http3 instproc finish-connection {} {
  981. $self instvar client_ server_ cache_
  982. $client_(0) disconnect $cache_
  983. $client_(1) disconnect $cache_
  984. $client_(2) disconnect $cache_
  985. $cache_ disconnect $server_
  986. }
  987. Class Test/http3f -superclass Test/http3
  988. Test/http3f instproc init args {
  989. eval $self next $args
  990. Http set TRANSPORT_ FullTcp
  991. }
  992. #
  993. # Testing cache with TTL invalidation
  994. #
  995. Class Test/http4 -superclass Test
  996. Test/http4 instproc init {} {
  997. $self set-defnet 5node
  998. $self next
  999. $self instvar ns_ startTime_ finishTime_
  1000. set startTime_ 1
  1001. set finishTime_ 40
  1002. Http set TRANSPORT_ SimpleTcp
  1003. }
  1004. Test/http4 instproc set-routing {} {
  1005. $self instvar ns_
  1006. $ns_ rtproto Session
  1007. }
  1008. Test/http4 instproc set-topology {} {
  1009. $self instvar node_ ns_
  1010. for {set i 0} {$i < 5} {incr i} {
  1011. set node_($i) [$ns_ node]
  1012. }
  1013. $ns_ duplex-link $node_(3) $node_(4) 1Mb 50ms DropTail
  1014. $ns_ duplex-link $node_(0) $node_(3) 1Mb 50ms DropTail
  1015. $ns_ duplex-link $node_(1) $node_(3) 1Mb 50ms DropTail
  1016. $ns_ duplex-link $node_(2) $node_(3) 1Mb 50ms DropTail
  1017. }
  1018. Test/http4 instproc set-members {} {
  1019. $self instvar ns_ startTime_ client_ cache_ server_ node_ test_
  1020. set client_(0) [new Http/Client $ns_ $node_(0)]
  1021. set client_(1) [new Http/Client $ns_ $node_(1)]
  1022. set client_(2) [new Http/Client $ns_ $node_(2)]
  1023. set cache_ [new Http/Cache/TTL $ns_ $node_(3)]
  1024. set server_ [new Http/Server $ns_ $node_(4)]
  1025. $ns_ at $startTime_ "$self start-connection"
  1026. $ns_ at 10 "$self finish-connection"
  1027. }
  1028. Test/http4 instproc start-requests {} {
  1029. $self instvar client_ server_ cache_ ns_
  1030. $client_(0) send-request $cache_ GET $server_:0
  1031. set tmp [expr [$ns_ now] + 1]
  1032. $ns_ at $tmp "$client_(1) send-request $cache_ GET $server_:1"
  1033. incr tmp
  1034. $ns_ at $tmp "$client_(2) send-request $cache_ GET $server_:0"
  1035. incr tmp 3
  1036. $ns_ at $tmp "$self start-requests"
  1037. }
  1038. # Connect TCP source and destination after simulator starts
  1039. Test/http4 instproc start-connection {} {
  1040. $self instvar ns_ client_ server_ cache_ node_
  1041. $client_(0) connect $cache_
  1042. $client_(1) connect $cache_
  1043. $client_(2) connect $cache_
  1044. $cache_ connect $server_
  1045. $cache_ set-parent $server_
  1046. $self start-requests
  1047. }
  1048. Test/http4 instproc finish-connection {} {
  1049. $self instvar client_ server_ cache_
  1050. $client_(0) disconnect $cache_
  1051. $client_(1) disconnect $cache_
  1052. $client_(2) disconnect $cache_
  1053. $cache_ disconnect $server_
  1054. }
  1055. Class Test/http4f -superclass Test/http4
  1056. Test/http4f instproc init args {
  1057. eval $self next $args
  1058. Http set TRANSPORT_ FullTcp
  1059. }
  1060. #
  1061. # Testing PagePool
  1062. #
  1063. Class Test/PagePool -superclass Test
  1064. Test/PagePool instproc init {} {
  1065. $self instvar pgp_
  1066. global opts
  1067. set opts(page-file) pages
  1068. set pgp_ [new PagePool/Trace $opts(page-file)]
  1069. set max [$pgp_ get-poolsize]
  1070. set tmp [new RandomVariable/Uniform]
  1071. $tmp set min_ 0
  1072. $tmp set max_ [expr $max - 1]
  1073. $pgp_ ranvar $tmp
  1074. }
  1075. Test/PagePool instproc test-enumerate {} {
  1076. $self instvar pgp_ log_
  1077. set max [$pgp_ get-poolsize]
  1078. for {set i 0} {$i < $max} {incr i} {
  1079. puts -nonewline $log_ "Page $i: "
  1080. puts -nonewline $log_ "size [$pgp_ gen-size $i] "
  1081. set mtime [$pgp_ gen-modtime $i -1]
  1082. puts -nonewline $log_ "ctime $mtime "
  1083. set tmp [$pgp_ gen-modtime $i $mtime]
  1084. while {$tmp != $mtime} {
  1085. puts -nonewline $log_ "mtime $tmp "
  1086. set mtime $tmp
  1087. set tmp [$pgp_ gen-modtime $i $mtime]
  1088. }
  1089. puts $log_ ""
  1090. }
  1091. }
  1092. Test/PagePool instproc test-getpageid {} {
  1093. $self instvar pgp_ log_
  1094. set max [$pgp_ get-poolsize]
  1095. for {set i 0} {$i < $max} {incr i} {
  1096. set id [$pgp_ gen-pageid 0]
  1097. puts -nonewline $log_ "Page $id: "
  1098. puts -nonewline $log_ "size [$pgp_ gen-size $id] "
  1099. set mtime [$pgp_ gen-modtime $id -1]
  1100. puts -nonewline $log_ "ctime $mtime "
  1101. set tmp [$pgp_ gen-modtime $id $mtime]
  1102. while {$tmp != $mtime} {
  1103. puts -nonewline $log_ "mtime $tmp "
  1104. set mtime $tmp
  1105. set tmp [$pgp_ gen-modtime $id $mtime]
  1106. }
  1107. puts $log_ ""
  1108. }
  1109. }
  1110. Test/PagePool instproc run {} {
  1111. $self instvar log_
  1112. set log_ [open "temp.rands" w]
  1113. $self test-getpageid
  1114. $self test-enumerate
  1115. close $log_
  1116. }
  1117. #----------------------------------------------------------------------
  1118. # Testing simplest case for heartbeat message: 1 client+1 cache+1 server
  1119. #----------------------------------------------------------------------
  1120. # Multicast invalidation + server invalidation
  1121. Class Test/cache0-inv -superclass Test-Cache
  1122. Test/cache0-inv instproc init {} {
  1123. $self set-defnet cache0
  1124. $self next
  1125. $self set-server-type /Inval/Yuc
  1126. $self set-cache-type /Inval/Mcast
  1127. $self set-client-type ""
  1128. Http set TRANSPORT_ SimpleTcp
  1129. }
  1130. Test/cache0-inv instproc set-connections {} {
  1131. $self instvar client_ server_ cache_
  1132. # XXX Should always let server connects to cache first, then requests
  1133. $client_(0) connect $cache_(0)
  1134. $server_(0) connect $cache_(0)
  1135. $server_(0) set-parent-cache $cache_(0)
  1136. }
  1137. Test/cache0-inv instproc start-requests {} {
  1138. $self instvar client_ cache_ server_ ns_
  1139. $client_(0) start $cache_(0) $server_(0)
  1140. }
  1141. # Mcast inval
  1142. Class Test/cache0f-inv -superclass Test/cache0-inv
  1143. Test/cache0f-inv instproc init args {
  1144. eval $self next $args
  1145. Http set TRANSPORT_ FullTcp
  1146. }
  1147. # Push + mcast inval
  1148. Class Test/cache0-push -superclass Test/cache0-inv
  1149. Test/cache0-push instproc create-members {} {
  1150. $self next
  1151. $self instvar cache_ server_
  1152. $server_(0) set enable_upd_ 1
  1153. $cache_(0) set enable_upd_ 1
  1154. }
  1155. Class Test/cache0f-push -superclass {Test/cache0-push Test/cache0f-inv}
  1156. # TTL
  1157. Class Test/cache0-ttl -superclass Test/cache0-inv
  1158. Test/cache0-ttl instproc init args {
  1159. eval $self next $args
  1160. $self set-server-type ""
  1161. $self set-cache-type /TTL
  1162. $self set-client-type ""
  1163. }
  1164. Test/cache0-ttl instproc set-connections {} {
  1165. $self instvar client_ server_ cache_
  1166. # XXX Should always let server connects to cache first, then requests
  1167. $client_(0) connect $cache_(0)
  1168. $cache_(0) connect $server_(0)
  1169. $server_(0) set-parent-cache $cache_(0)
  1170. }
  1171. Class Test/cache0f-ttl -superclass {Test/cache0f-inv Test/cache0-ttl}
  1172. # Omniscient TTL
  1173. Class Test/cache0-ottl -superclass Test/cache0-ttl
  1174. Test/cache0-ottl instproc init args {
  1175. eval $self next $args
  1176. $self set-cache-type /TTL/Omniscient
  1177. }
  1178. Class Test/cache0f-ottl -superclass {Test/cache0-ottl Test/cache0f-ttl}
  1179. #----------------------------------------------------------------------
  1180. # Two hierarchies #1: server0 -> root cache 0
  1181. #----------------------------------------------------------------------
  1182. Class Test/TLC1 -superclass Test-Cache
  1183. Test/TLC1 instproc init {} {
  1184. # Do our own initialization
  1185. global opts
  1186. set opts(duration) 500
  1187. set opts(avg-page-age) 60
  1188. set opts(avg-req-interval) 6
  1189. set opts(hb-interval) 6
  1190. $self set-defnet cache2
  1191. $self next
  1192. $self set-cache-type /Inval/Mcast
  1193. $self set-server-type /Inval/Yuc
  1194. $self set-client-type ""
  1195. Http set TRANSPORT_ SimpleTcp
  1196. }
  1197. Test/TLC1 instproc start-requests {} {
  1198. $self instvar client_ cache_ server_
  1199. $client_(0) start $cache_(2) $server_(0)
  1200. $client_(1) start $cache_(6) $server_(0)
  1201. $client_(2) start $cache_(4) $server_(0)
  1202. $client_(3) start $cache_(1) $server_(0)
  1203. }
  1204. Test/TLC1 instproc set-connections {} {
  1205. $self instvar client_ cache_ server_
  1206. $client_(0) connect $cache_(2)
  1207. $client_(1) connect $cache_(6)
  1208. $client_(2) connect $cache_(4)
  1209. $client_(3) connect $cache_(1)
  1210. $cache_(2) connect $cache_(0)
  1211. $cache_(2) set-parent $cache_(0)
  1212. $cache_(3) connect $cache_(0)
  1213. $cache_(3) set-parent $cache_(0)
  1214. $cache_(6) connect $cache_(2)
  1215. $cache_(6) set-parent $cache_(2)
  1216. $cache_(4) connect $cache_(1)
  1217. $cache_(4) set-parent $cache_(1)
  1218. $cache_(5) connect $cache_(1)
  1219. $cache_(5) set-parent $cache_(1)
  1220. # XXX
  1221. # We also need TCP connections between TLCs, but the order in which
  1222. # they are connected is tricky. I.e., the cache that first sends
  1223. # out a packet should connect first. But how do we know which cache
  1224. # would send out a packet first???
  1225. $cache_(1) connect $cache_(0)
  1226. }
  1227. Test/TLC1 instproc set-groups {} {
  1228. $self instvar client_ cache_ server_ mh_
  1229. # TBA group setup stuff...
  1230. set grp [Node allocaddr]
  1231. $cache_(0) join-tlc-group $grp
  1232. $cache_(1) join-tlc-group $grp
  1233. $mh_ switch-treetype $grp
  1234. set grp [Node allocaddr]
  1235. $cache_(0) init-inval-group $grp
  1236. $cache_(2) join-inval-group $grp
  1237. $cache_(3) join-inval-group $grp
  1238. $mh_ switch-treetype $grp
  1239. set grp [Node allocaddr]
  1240. $cache_(1) init-inval-group $grp
  1241. $cache_(4) join-inval-group $grp
  1242. $cache_(5) join-inval-group $grp
  1243. $mh_ switch-treetype $grp
  1244. set grp [Node allocaddr]
  1245. $cache_(2) init-inval-group $grp
  1246. $cache_(6) join-inval-group $grp
  1247. $mh_ switch-treetype $grp
  1248. # XXX Must let the server to initialize connection, because it's
  1249. # going to send out the first packet
  1250. $cache_(1) connect $server_(0)
  1251. $server_(0) connect $cache_(0)
  1252. # XXX Must do this at the end. It'll trigger a lot of JOINs.
  1253. $server_(0) set-parent-cache $cache_(0)
  1254. # XXX Must do this when using multiple hierarchies
  1255. $server_(0) set-tlc $cache_(0)
  1256. }
  1257. Class Test/TLC1f -superclass Test/TLC1
  1258. Test/TLC1f instproc init {} {
  1259. $self next
  1260. Http set TRANSPORT_ FullTcp
  1261. }
  1262. #
  1263. # Two hierarchies with direct request
  1264. #
  1265. #Class Test/TLC1-dreq -superclass Test/TLC1
  1266. # Test/TLC1-dreq instproc init {} {
  1267. # $self next
  1268. # $self set-cache-type /Inval/Mcast/Perc
  1269. # }
  1270. # Set up direct connections from leaf caches (i.e., all caches who
  1271. # may connect to a browser) to the server
  1272. # Test/TLC1-dreq instproc set-connections {} {
  1273. # $self next
  1274. # $self instvar cache_ server_
  1275. # $cache_(1) connect $server_(0)
  1276. # $cache_(2) connect $server_(0)
  1277. # $cache_(4) connect $server_(0)
  1278. # $cache_(6) connect $server_(0)
  1279. # $cache_(1) set direct_request_ 1
  1280. # $cache_(2) set direct_request_ 1
  1281. # $cache_(4) set direct_request_ 1
  1282. # $cache_(6) set direct_request_ 1
  1283. # }
  1284. #----------------------------------------------------------------------
  1285. # Testing server/cache liveness messages and failure recovery
  1286. #----------------------------------------------------------------------
  1287. Class Test/Liveness -superclass Test-Cache
  1288. Test/Liveness instproc init {} {
  1289. # Set default initialization values
  1290. global opts
  1291. set opts(duration) 1200 ;# Link heals at time 1000.
  1292. set opts(avg-page-age) 60
  1293. set opts(avg-req-interval) 60
  1294. set opts(hb-interval) 30
  1295. $self set-defnet cache4d
  1296. $self next
  1297. $self set-cache-type /Inval/Mcast
  1298. $self set-server-type /Inval/Yuc
  1299. $self set-client-type ""
  1300. # Must use FullTcp, because we'll have packet loss, etc.
  1301. Http set TRANSPORT_ FullTcp
  1302. }
  1303. Test/Liveness instproc start-requests {} {
  1304. $self instvar client_ cache_ server_ ns_
  1305. $client_(0) start $cache_(3) $server_(0)
  1306. $client_(1) start $cache_(4) $server_(0)
  1307. $client_(2) start $cache_(5) $server_(0)
  1308. $client_(3) start $cache_(6) $server_(0)
  1309. # puts "At [$ns_ now], request starts"
  1310. }
  1311. Test/Liveness instproc set-connections {} {
  1312. $self instvar ns_ client_ server_ cache_
  1313. # Enable dynamics somewhere
  1314. $client_(0) connect $cache_(3)
  1315. $client_(1) connect $cache_(4)
  1316. $client_(2) connect $cache_(5)
  1317. $client_(3) connect $cache_(6)
  1318. $cache_(1) connect $cache_(0)
  1319. $cache_(2) connect $cache_(0)
  1320. $cache_(3) connect $cache_(1)
  1321. $cache_(4) connect $cache_(1)
  1322. $cache_(5) connect $cache_(2)
  1323. $cache_(6) connect $cache_(2)
  1324. $cache_(1) set-parent $cache_(0)
  1325. $cache_(2) set-parent $cache_(0)
  1326. $cache_(3) set-parent $cache_(1)
  1327. $cache_(4) set-parent $cache_(1)
  1328. $cache_(5) set-parent $cache_(2)
  1329. $cache_(6) set-parent $cache_(2)
  1330. # All TLCs have connection to server
  1331. $cache_(0) connect $server_(0)
  1332. # Parent cache of the server is e3
  1333. $server_(0) connect $cache_(3)
  1334. }
  1335. Test/Liveness instproc set-groups {} {
  1336. $self instvar cache_ mh_ server_
  1337. set grp [Node allocaddr]
  1338. $cache_(0) init-inval-group $grp
  1339. $cache_(1) join-inval-group $grp
  1340. $cache_(2) join-inval-group $grp
  1341. $mh_ switch-treetype $grp
  1342. set grp [Node allocaddr]
  1343. $cache_(1) init-inval-group $grp
  1344. $cache_(3) join-inval-group $grp
  1345. $cache_(4) join-inval-group $grp
  1346. $mh_ switch-treetype $grp
  1347. set grp [Node allocaddr]
  1348. $cache_(2) init-inval-group $grp
  1349. $cache_(5) join-inval-group $grp
  1350. $cache_(6) join-inval-group $grp
  1351. $mh_ switch-treetype $grp
  1352. $server_(0) set-parent-cache $cache_(3)
  1353. }
  1354. #----------------------------------------------------------------------
  1355. # Test Group 1:
  1356. #
  1357. # Poisson page mods and Poisson requests, one bottleneck link, 2-level
  1358. # cache hierarchy with a single TLC. No loss.
  1359. #
  1360. # Comparing Invalidation, TTL and OTTL.
  1361. #
  1362. # Testing Mcast+Yucd using a bottleneck topology
  1363. #----------------------------------------------------------------------
  1364. Class Test/Mcast-PB -superclass Test-Cache
  1365. Test/Mcast-PB instproc init {} {
  1366. # Our own initializations
  1367. global opts
  1368. set opts(duration) 200
  1369. set opts(avg-page-age) 10
  1370. set opts(avg-req-interval) 6
  1371. set opts(hb-interval) 6
  1372. set opts(num-2nd-cache) 5
  1373. $self set-defnet BottleNeck
  1374. $self next
  1375. $self instvar secondCaches_
  1376. set secondCaches_ $opts(num-2nd-cache)
  1377. $self set-cache-type /Inval/Mcast
  1378. $self set-server-type /Inval/Yuc
  1379. $self set-client-type ""
  1380. }
  1381. Test/Mcast-PB instproc start-requests {} {
  1382. $self instvar client_ cache_ server_ secondCaches_
  1383. set n $secondCaches_
  1384. for {set i 0} {$i < $n} {incr i} {
  1385. $client_($i) start $cache_($i) $server_(0)
  1386. }
  1387. $self instvar pgp_ topo_ ns_
  1388. # Because Test/Cache::init{} already did set-pagepool{}, now we
  1389. # know how many pages we have. Estimate the cache population time
  1390. # by NumPages*1+10, then start bandwidth monitoring after
  1391. # the caches are populated with pages
  1392. $ns_ at [expr [$ns_ now] + [$pgp_ get-poolsize] + 10] \
  1393. "$topo_ start-monitor $ns_"
  1394. }
  1395. Test/Mcast-PB instproc set-connections {} {
  1396. $self instvar ns_ client_ server_ cache_ secondCaches_
  1397. set n $secondCaches_
  1398. for {set i 0} {$i < $n} {incr i} {
  1399. $client_($i) connect $cache_($i)
  1400. $cache_($i) connect $cache_($n)
  1401. $cache_($i) set-parent $cache_($n)
  1402. }
  1403. $cache_($n) connect $server_(0)
  1404. $self connect-server
  1405. }
  1406. Test/Mcast-PB instproc connect-server {} {
  1407. $self instvar server_ cache_
  1408. $server_(0) connect $cache_(0)
  1409. }
  1410. Test/Mcast-PB instproc set-groups {} {
  1411. $self instvar cache_ server_ secondCaches_ mh_
  1412. set n $secondCaches_
  1413. set grp1 [Node allocaddr]
  1414. set grp2 [Node allocaddr]
  1415. $cache_($n) init-inval-group $grp1
  1416. $cache_($n) init-update-group $grp2
  1417. for {set i 0} {$i < $n} {incr i} {
  1418. $cache_($i) join-inval-group $grp1
  1419. $cache_($i) join-update-group $grp2
  1420. }
  1421. $mh_ switch-treetype $grp1
  1422. $mh_ switch-treetype $grp2
  1423. $server_(0) set-parent-cache $cache_(0)
  1424. }
  1425. Test/Mcast-PB instproc collect-stat {} {
  1426. $self instvar topo_ client_ server_ cache_ secondCaches_
  1427. set bw [$topo_ mon-stat]
  1428. set sn 0
  1429. set gn 0
  1430. set st(max) 0
  1431. set st(min) 98765432
  1432. set st(avg) 0
  1433. set rt(max) 0
  1434. set rt(min) 98765432
  1435. set rt(avg) 0
  1436. foreach c [array names client_] {
  1437. set gn [expr $gn + [$client_($c) stat req-num]]
  1438. set sn [expr $sn + [$client_($c) stat stale-num]]
  1439. set st(avg) [expr $st(avg) + [$client_($c) stat stale-time]]
  1440. set tmp [$client_($c) stat st-min]
  1441. if { $tmp < $st(min) } { set st(min) $tmp }
  1442. set tmp [$client_($c) stat st-max]
  1443. if { $tmp > $st(max) } { set st(max) $tmp }
  1444. set rt(avg) [expr $rt(avg) + [$client_($c) stat rep-time]]
  1445. set tmp [$client_($c) stat rt-max]
  1446. if { $tmp > $rt(max) } { set rt(max) $tmp }
  1447. set tmp [$client_($c) stat rt-min]
  1448. if { $tmp < $rt(min) } { set rt(min) $tmp }
  1449. }
  1450. if {$st(max) < $st(min)} {
  1451. set st(max) 0
  1452. set st(min) 0
  1453. }
  1454. if {$rt(max) < $rt(min)} {
  1455. set rt(max) 0
  1456. set rt(min) 0
  1457. }
  1458. set sr [expr double($sn) / $gn * 100]
  1459. if [catch {set st(avg) [expr double($st(avg)) / $sn]}] {
  1460. set st(avg) 0 ;# No stale hits
  1461. }
  1462. set rt(avg) [expr double($rt(avg)) / $gn]
  1463. set ims 0
  1464. foreach c [array names cache_] {
  1465. set ims [expr $ims + [$cache_($c) stat ims-num]]
  1466. }
  1467. set res [list sr $sr sh [$server_(0) stat hit-num] th [$cache_($secondCaches_) stat hit-num] st $st(avg) st-max $st(max) st-min $st(min) rt $rt(avg) rt-max $rt(max) rt-min $rt(min) mn [$server_(0) stat mod-num] ims-num $ims]
  1468. return [concat $bw $res]
  1469. }
  1470. Test/Mcast-PB instproc output-stat { args } {
  1471. eval array set d $args
  1472. global opts
  1473. # XXX Don't have statistics for total bandwidth. :(
  1474. #puts "$opts(hb-interval) Bandwidth*Hop -1 Stale $d(sr) AverageRepTime $d(rt) BottleneckBW $d(btnk_bw) ServerBW $d(svr_bw) StaleTime $d(st)"
  1475. }
  1476. Test/Mcast-PB instproc finish {} {
  1477. global opts
  1478. if $opts(quiet) {
  1479. $self output-stat [$self collect-stat]
  1480. }
  1481. $self next
  1482. }
  1483. #
  1484. # Same as mcast-PB, except using Inval/Mcast/Perc cache
  1485. #
  1486. Class Test/Mcast-PBP -superclass Test/Mcast-PB
  1487. Test/Mcast-PBP instproc init {} {
  1488. $self next
  1489. $self set-cache-type /Inval/Mcast/Perc
  1490. }
  1491. #
  1492. # Same as mcast-PB, except enabled selective push of updates
  1493. #
  1494. Class Test/Mcast-PBU -superclass Test/Mcast-PB
  1495. Test/Mcast-PBU instproc create-members {} {
  1496. $self next
  1497. $self instvar cache_ server_
  1498. foreach n [array names cache_] {
  1499. $cache_($n) set enable_upd_ 1
  1500. }
  1501. foreach n [array names server_] {
  1502. $server_($n) set enable_upd_ 1
  1503. }
  1504. }
  1505. #
  1506. # Mcast invalidation + selective push + mandatory push
  1507. #
  1508. Class Test/Mcast-PBU-MP -superclass Test/Mcast-PBU
  1509. Test/Mcast-PBU-MP instproc create-members {} {
  1510. $self next
  1511. $self instvar client_ ns_ server_
  1512. $ns_ at 100.0 "$client_(1) request-mpush $server_(0):0"
  1513. $ns_ at 500.0 "$client_(1) stop-mpush $server_(0):0"
  1514. }
  1515. #
  1516. # Testing TTL using a bottleneck topology
  1517. #
  1518. Class Test/ttl-PB -superclass Test/Mcast-PB
  1519. Test/ttl-PB instproc init {} {
  1520. global opts
  1521. set opts(ttl) 0.1
  1522. $self next
  1523. $self set-cache-type /TTL
  1524. $self set-server-type ""
  1525. $self set-client-type ""
  1526. }
  1527. Test/ttl-PB instproc create-members {} {
  1528. $self next
  1529. global opts
  1530. $self instvar cache_
  1531. foreach n [array names cache_] {
  1532. $cache_($n) set-thresh $opts(ttl)
  1533. }
  1534. }
  1535. Test/ttl-PB instproc set-groups {} {
  1536. # We do not set any mcast groups
  1537. }
  1538. Test/ttl-PB instproc connect-server {} {
  1539. $self instvar server_ cache_
  1540. $cache_(0) connect $server_(0)
  1541. }
  1542. Test/ttl-PB instproc output-stat { args } {
  1543. eval array set d $args
  1544. global opts
  1545. # XXX Don't have statistics for total bandwidth. :(
  1546. #puts "$opts(ttl) Bandwidth*Hop -1 Stale $d(sr) AverageRepTime $d(rt) BottleneckBW $d(btnk_bw) ServerBW $d(svr_bw) StaleTime $d(st)"
  1547. }
  1548. #
  1549. # Testing Omniscient TTL using a bottleneck topology
  1550. #
  1551. Class Test/ottl-PB -superclass {Test/ttl-PB Test/Mcast-PB}
  1552. Test/ottl-PB instproc init {} {
  1553. $self next
  1554. $self set-cache-type /TTL/Omniscient
  1555. $self set-server-type ""
  1556. $self set-client-type ""
  1557. }
  1558. Test/ottl-PB instproc output-stat { args } {
  1559. eval array set d $args
  1560. # XXX Don't have statistics for total bandwidth. :(
  1561. #puts "Bandwidth*Hop -1 Stale $d(sr) AverageRepTime $d(rt) Bottl…

Large files files are truncated, but you can click here to view the full file