File: test-suite-jobs.tcl

package info (click to toggle)
ns2 2.35%2Bdfsg-2.1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 78,780 kB
  • ctags: 27,490
  • sloc: cpp: 172,923; tcl: 107,130; perl: 6,391; sh: 6,143; ansic: 5,846; makefile: 816; awk: 525; csh: 355
file content (468 lines) | stat: -rw-r--r-- 13,426 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
#
# Copyright (c) 2000-2002, by the Rector and Board of Visitors of the 
# University of Virginia.
# All rights reserved.
#
# Redistribution and use in source and binary forms, 
# with or without modification, are permitted provided 
# that the following conditions are met:
#
# Redistributions of source code must retain the above 
# copyright notice, this list of conditions and the following 
# disclaimer. 
#
# Redistributions in binary form must reproduce the above 
# copyright notice, this list of conditions and the following 
# disclaimer in the documentation and/or other materials provided 
# with the distribution. 
#
# Neither the name of the University of Virginia nor the names 
# of its contributors may be used to endorse or promote products 
# derived from this software without specific prior written 
# permission. 
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
# CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 
# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 
# DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE 
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, 
# OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 
# IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 
# THE POSSIBILITY OF SUCH DAMAGE.
#
# $Id: test-suite-jobs.tcl,v 1.4 2005/06/11 04:42:09 sfloyd Exp $                  
remove-all-packet-headers       ; # removes all except common
add-packet-header Flags IP RTP TCP  ; # hdrs reqd for validation test
 
# FOR UPDATING GLOBAL DEFAULTS:

#                                                                     
# This test suite is for validating wireless lans 
# To run all tests: test-all-jobs
# to run individual test:
# ns test-suite-jobs.tcl jobs-rate
# ns test-suite-jobs.tcl jobs-lossdel
#
# To view a list of available test to run with this script:
# ns test-suite-jobs.tcl
#

Class TestSuite

# Rate allocation
Class Test/jobs-rate -superclass TestSuite

# Relative guarantees, TCP traffic
Class Test/jobs-lossdel -superclass TestSuite

# =====================================================================
# General setup
#

proc usage {} {
	global argv0
	puts stderr "usage: ns $argv0 <tests> "
	puts "Valid Tests: jobs-rate jobs-lossdel"
	exit 1
}

proc default_options {} {
	global opt
	set opt(queue_edg1)	Marker
	set opt(queue_edg2)	Demarker
	set opt(queue_core)	JoBS
	set opt(seed)		16.0
	set opt(tr)		temp.rands
	set opt(bw)		10000.0
	set opt(gw_buff)	800
	set opt(pktsz)		500
	set opt(start_tm)	0.0
	set opt(finish_tm)	10.0	
	set opt(hops)		2
	set opt(nsources)	4
	set opt(n_cl1)		1
	set opt(n_cl2)		1
	set opt(n_cl3)		1
	set opt(n_cl4)		1
	set opt(delay)		1.0
	set opt(sample)		1
}

# =====================================================================
# Other default settings
#

Queue/JoBS set drop_front_ false
Queue/JoBS set trace_hop_ false
Queue/JoBS set adc_resolution_type_ 0
Queue/JoBS set shared_buffer_ 0
Queue/JoBS set mean_pkt_size_ 4000
Queue/Demarker set demarker_arrvs1_ 0
Queue/Demarker set demarker_arrvs2_ 0
Queue/Demarker set demarker_arrvs3_ 0
Queue/Demarker set demarker_arrvs4_ 0
Queue/Marker set marker_arrvs1_ 0
Queue/Marker set marker_arrvs2_ 0
Queue/Marker set marker_arrvs3_ 0
Queue/Marker set marker_arrvs4_ 0

# =====================================================================
# The two tests
#

Test/jobs-rate instproc init {} {
    global opt core_node user_source user_source_agent user_sink user_sink_agent 
    $self instvar ns_ testName_
    set testName_       jobs-rate
    set opt(rp)         jobs-rate
    set opt(udp_source_rate) 5000.0

    $self next
    $self jobs-rate-topo
    $self traffic-setup 
    $ns_ at 0.0 "$self record_thru"
    $ns_ at [expr $opt(finish_tm)+.000000001] "puts \"Finishing Simulation...\" ;" 
    $ns_ at [expr $opt(finish_tm)+1] "$self finish"
}

Test/jobs-rate instproc run {} {
    $self instvar ns_
    puts "Starting Simulation..."
    $ns_ run
}

Test/jobs-lossdel instproc init {} {
    global opt core_node user_source user_source_agent user_sink user_sink_agent 
    $self instvar ns_ testName_
    set testName_       jobs-lossdel
    set opt(rp)         jobs-lossdel
    set opt(udp_source_rate) 2600.0

    $self next
    $self jobs-lossdel-topo
    $self traffic-setup 
    $ns_ at [expr $opt(finish_tm)+.000000001] "puts \"Finishing Simulation...\" ;" 
    $ns_ at [expr $opt(finish_tm)+1] "$self finish"
}

Test/jobs-lossdel instproc run {} {
    $self instvar ns_
    puts "Starting Simulation..."
    $ns_ run
}
#

# =====================================================================
# Traffic generation
#

TestSuite instproc traffic-setup {} {
    global opt user_source user_source_agent user_sink user_sink_agent 
    $self instvar ns_

    for {set i 1} {$i <= $opt(nsources)} {incr i} {
	set user_source_agent($i) [new Agent/UDP]
	set user_sink_agent($i) [new Agent/LossMonitor]
	set user_flow($i) [new Application/Traffic/CBR]
	$ns_ attach-agent $user_source($i) $user_source_agent($i)
	$ns_ attach-agent $user_sink($i) $user_sink_agent($i)
	$ns_ connect $user_source_agent($i) $user_sink_agent($i)
	$user_source_agent($i) set packetSize_ $opt(pktsz)
	$user_flow($i) set rate_ [expr $opt(udp_source_rate)*1000.0]
	$user_flow($i) attach-agent $user_source_agent($i)
	$ns_ at [expr $opt(start_tm)] "$user_flow($i) start"
    }
}

# =====================================================================
# Topology generation
#

TestSuite instproc jobs-rate-topo {} {    
    global opt core_node user_source user_sink
    $self instvar ns_ 
    set DETERM		1

    for {set i 1} {$i <= $opt(hops)} {incr i} {
	set core_node($i) [$ns_ node]
    }


    for {set i 1} {$i <= $opt(nsources)} {incr i} {
	set user_source($i) [$ns_ node]
	set user_sink($i) [$ns_ node]
    }

    for {set i 1} {$i < $opt(hops)} {incr i} {
	$ns_ duplex-link $core_node($i) $core_node([expr $i+1]) [expr $opt(bw)*1000.] [expr $opt(delay)/1000.] $opt(queue_core)
	$ns_ queue-limit $core_node($i) $core_node([expr $i+1]) $opt(gw_buff)
	$ns_ queue-limit $core_node([expr $i+1]) $core_node($i) $opt(gw_buff)
	set l [$ns_ get-link $core_node($i) $core_node([expr $i+1])]
	set q [$l queue]

	$q init-rdcs -1 -1 -1 -1
	$q init-rlcs -1 -1 -1 -1 
	$q init-alcs -1 -1 -1 -1 
	$q init-adcs -1 -1 -1 -1 
	$q init-arcs 4000000 3000000 2000000 1000000
	$q link [$l link]
	$q trace-file null
	$q sampling-period $opt(sample)
	$q id $i
	$q initialize
	
	# It's a duplex link, so we need to do exactly the same thing on the 
	# reverse path.
	
	set l [$ns_ get-link $core_node([expr $i+1]) $core_node($i)]
	set q [$l queue]
	
	$q init-rdcs -1 -1 -1 -1
	$q init-rlcs -1 -1 -1 -1 
	$q init-alcs -1 -1 -1 -1 
	$q init-adcs -1 -1 -1 -1 
	$q init-arcs 4000000 3000000 2000000 1000000
	$q link [$l link]
	$q trace-file null
	$q sampling-period $opt(sample)
	$q id [expr $i+$opt(hops)]
	$q initialize
    }

    for {set i 1} {$i <= $opt(nsources)} {incr i} {
	$ns_ simplex-link $user_source($i) $core_node(1) [expr $opt(bw)*1000.] [expr $opt(delay)/1000.] Marker
	$ns_ simplex-link $core_node(1) $user_source($i) [expr $opt(bw)*1000.] [expr $opt(delay)/1000.] Demarker
	$ns_ queue-limit $user_source($i) $core_node(1) $opt(gw_buff)
	$ns_ queue-limit $core_node(1) $user_source($i) $opt(gw_buff)

	set q [$ns_ get-queue $user_source($i) $core_node(1)]
	$q marker_type $DETERM

	if {$i == $opt(n_cl1)} {
	    $q marker_class 1
	} elseif {$i <= $opt(n_cl1)+$opt(n_cl2)} {
	    $q marker_class 2
	} elseif {$i <= $opt(n_cl1)+$opt(n_cl2)+$opt(n_cl3)} {
	    $q marker_class 3
	} else {
	    $q marker_class 4
	}

	set q [$ns_ get-queue $core_node(1) $user_source($i)]
	$q trace-file null
	
	$ns_ simplex-link $core_node($opt(hops)) $user_sink($i) [expr $opt(bw)*1000.] [expr $opt(delay)/1000.] Demarker
	$ns_ simplex-link $user_sink($i) $core_node($opt(hops)) [expr $opt(bw)*1000.] [expr $opt(delay)/1000.] Marker
	$ns_ queue-limit $core_node($opt(hops)) $user_sink($i) $opt(gw_buff)
	$ns_ queue-limit $user_sink($i) $core_node($opt(hops)) $opt(gw_buff)
	
	set q [$ns_ get-queue $core_node($opt(hops)) $user_sink($i)]
	$q trace-file null
	
	set q [$ns_ get-queue $user_sink($i) $core_node($opt(hops))]
	$q marker_type $DETERM
	
	if {$i == $opt(n_cl1)} {
	    $q marker_class 1
	} elseif {$i <= $opt(n_cl1)+$opt(n_cl2)} {
	    $q marker_class 2
	} elseif {$i <= $opt(n_cl1)+$opt(n_cl2)+$opt(n_cl3)} {
	    $q marker_class 3
	} else {
	    $q marker_class 4
	}
    }
}

TestSuite instproc jobs-lossdel-topo {} {    
    global opt core_node user_source user_sink
    $self instvar ns_ 
    set DETERM		1

    Queue/JoBS set shared_buffer_ 1
    Queue/JoBS set trace_hop_ true

    for {set i 1} {$i <= $opt(hops)} {incr i} {
	set core_node($i) [$ns_ node]
    }


    for {set i 1} {$i <= $opt(nsources)} {incr i} {
	set user_source($i) [$ns_ node]
	set user_sink($i) [$ns_ node]
    }

    for {set i 1} {$i < $opt(hops)} {incr i} {
	$ns_ duplex-link $core_node($i) $core_node([expr $i+1]) [expr $opt(bw)*1000.] [expr $opt(delay)/1000.] $opt(queue_core)
	$ns_ queue-limit $core_node($i) $core_node([expr $i+1]) $opt(gw_buff)
	$ns_ queue-limit $core_node([expr $i+1]) $core_node($i) $opt(gw_buff)
	set l [$ns_ get-link $core_node($i) $core_node([expr $i+1])]
	set q [$l queue]

	$q init-rdcs -1 4 4 4 
	$q init-rlcs -1 2 2 2 
	$q init-alcs 0.01 -1 -1 -1
	$q init-adcs 0.005 -1 -1 -1
	$q init-arcs -1 -1 -1 -1
	$q link [$l link]
	$q trace-file $opt(tr) 
	$q sampling-period $opt(sample)
	$q id $i
	$q initialize
	
	# It's a duplex link, so we need to do exactly the same thing on the 
	# reverse path.
	
	set l [$ns_ get-link $core_node([expr $i+1]) $core_node($i)]
	set q [$l queue]
	
	$q init-rdcs -1 4 4 4 
	$q init-rlcs -1 2 2 2 
	$q init-alcs 0.01 -1 -1 -1
	$q init-adcs 0.005 -1 -1 -1
	$q init-arcs -1 -1 -1 -1
	$q link [$l link]
	$q trace-file null
	$q sampling-period $opt(sample)
	$q id [expr $i+$opt(hops)]
	$q initialize
    }

    for {set i 1} {$i <= $opt(nsources)} {incr i} {
	$ns_ simplex-link $user_source($i) $core_node(1) [expr $opt(bw)*1000.] [expr $opt(delay)/1000.] Marker
	$ns_ simplex-link $core_node(1) $user_source($i) [expr $opt(bw)*1000.] [expr $opt(delay)/1000.] Demarker
	$ns_ queue-limit $user_source($i) $core_node(1) $opt(gw_buff)
	$ns_ queue-limit $core_node(1) $user_source($i) $opt(gw_buff)

	set q [$ns_ get-queue $user_source($i) $core_node(1)]
	$q marker_type $DETERM

	if {$i == $opt(n_cl1)} {
	    $q marker_class 1
	} elseif {$i <= $opt(n_cl1)+$opt(n_cl2)} {
	    $q marker_class 2
	} elseif {$i <= $opt(n_cl1)+$opt(n_cl2)+$opt(n_cl3)} {
	    $q marker_class 3
	} else {
	    $q marker_class 4
	}

	set q [$ns_ get-queue $core_node(1) $user_source($i)]
	$q trace-file null
	
	$ns_ simplex-link $core_node($opt(hops)) $user_sink($i) [expr $opt(bw)*1000.] [expr $opt(delay)/1000.] Demarker
	$ns_ simplex-link $user_sink($i) $core_node($opt(hops)) [expr $opt(bw)*1000.] [expr $opt(delay)/1000.] Marker
	 $ns_ queue-limit $core_node($opt(hops)) $user_sink($i) $opt(gw_buff)
	$ns_ queue-limit $user_sink($i) $core_node($opt(hops)) $opt(gw_buff)
	
	set q [$ns_ get-queue $core_node($opt(hops)) $user_sink($i)]
	$q trace-file null
	
	set q [$ns_ get-queue $user_sink($i) $core_node($opt(hops))]
	$q marker_type $DETERM
	
	if {$i == $opt(n_cl1)} {
	    $q marker_class 1
	} elseif {$i <= $opt(n_cl1)+$opt(n_cl2)} {
	    $q marker_class 2
	} elseif {$i <= $opt(n_cl1)+$opt(n_cl2)+$opt(n_cl3)} {
	    $q marker_class 3
	} else {
	    $q marker_class 4
	}
    }
}


# =====================================================================
# Various helpers
#

Simulator instproc get-link { node1 node2 } {
    $self instvar link_
    set id1 [$node1 id]
    set id2 [$node2 id]
    return $link_($id1:$id2)
}

Simulator instproc get-queue { node1 node2 } {
    set l [$self get-link $node1 $node2]
    set q [$l queue]
    return $q
}

TestSuite instproc init {} {
	global opt tracefd 
	global node_ 
	$self instvar ns_ testName_
	set ns_         [new Simulator]
	set tracefd	[open $opt(tr) w]
}

TestSuite instproc finish {} {
	$self instvar ns_
	global quiet

	$ns_ flush-trace
	puts "finishing.."
	exit 0
}

TestSuite instproc record_thru {} {
    $self instvar ns_
	global tracefd opt user_sink_agent  
	set time 0.5
	set tot_recv 0
	set now [$ns_ now]
	for {set i 1} {$i <= $opt(nsources)} {incr i} {
		set recv($i) [$user_sink_agent($i) set bytes_]
		$user_sink_agent($i) set bytes_ 0
	}
	puts $tracefd [format "%.2f %.2f %.2f %.2f %.2f" $now [expr 8.*$recv(1)/$time] [expr 8.*$recv(2)/$time] [expr 8.*$recv(3)/$time] [expr 8.*$recv(4)/$time]]
	$ns_ at [expr $now+$time] "$self record_thru"
}

# =====================================================================
# Test launcher
#

proc runtest {arg} {
	global quiet
	set quiet 0

	set b [llength $arg]
	if {$b == 1} {
		set test $arg
	} elseif {$b == 2} {
		set test [lindex $arg 0]
		if {[lindex $arg 1] == "QUIET"} {
			set quiet 1
		}
	} else {
		usage
	}
	set t [new Test/$test]
	$t run
}

# =====================================================================
# Main
#

global argv arg0
default_options
runtest $argv