File: test-suite-diffserv.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 (388 lines) | stat: -rw-r--r-- 10,210 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
#
# Copyright (c) 1998,2000 University of Southern California.
# All rights reserved.                                            
#                                                                
# Redistribution and use in source and binary forms are permitted
# provided that the above copyright notice and this paragraph are
# duplicated in all such forms and that any documentation, advertising
# materials, and other materials related to such distribution and use
# acknowledge that the software was developed by the University of
# Southern California, Information Sciences Institute.  The name of the
# University may not be used to endorse or promote products derived from
# this software without specific prior written permission.
# 
# THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
# WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
# 

# This test suite is for validating the diffserv module ported from Nortel
# To run all tests: test-all-diffserv
#
# To run individual test:
# ns test-suite-diffserv.tcl tb | tsw2cm | tsw3cm | srtcm | trtcm
#
# To view a list of available test to run with this script:
# ns test-suite-diffserv.tcl
#

remove-all-packet-headers       ; # removes all except common
add-packet-header Flags IP RTP TCP  ; # hdrs reqd for validation test

# FOR UPDATING GLOBAL DEFAULTS:
Agent/TCP set precisionReduce_ false ;   # default changed on 2006/1/24.
Agent/TCP set rtxcur_init_ 6.0 ;      # Default changed on 2006/01/21
Agent/TCP set updated_rttvar_ false ;  # Variable added on 2006/1/21
Agent/TCP set minrto_ 1
# default changed on 10/14/2004.
Queue/RED set bytes_ false              
# default changed on 10/11/2004.
Queue/RED set queue_in_bytes_ false
# default changed on 10/11/2004.
Queue/RED set q_weight_ 0.002
Queue/RED set thresh_ 5 
Queue/RED set maxthresh_ 15
# The RED parameter defaults are being changed for automatic configuration.

# The topology used in the test suite is:
#
#    s1 -------
#        10 Mb  \
#         5 ms   \
#                 e1 ----- core ------ e2 ------ dest
#                /   10 Mb       5 Mb      10 Mb 
#               /     5 ms       5 ms       5 ms
#    s2 -------
#        10 Mb
#         5 ms
#

Class TestSuite

# With Policy as Token Bucket
Class Test/tb -superclass TestSuite

# With Policy as Time Sliding Window Two Color Marker (tsw2cm)
Class Test/tsw2cm -superclass TestSuite

# With Policy as Time Sliding Window Two Color Marker (tsw3cm)
Class Test/tsw3cm -superclass TestSuite

# With Policy as Single Rate Three Color Marker (srtcm)
Class Test/srtcm -superclass TestSuite

# With Policy as Two Rate Three Color Marker (trtcm)
Class Test/trtcm -superclass TestSuite

proc usage {} {
	global argv0
	puts stderr "usage: ns $argv0 <tests> "
	puts "Valid Tests: tb tsw2cm tsw3cm srtcm trtcm"
	exit 1
}

# Set up parameters for ds redqs for a link.
TestSuite instproc create_q {qec_ qce_ s1 s2 d1 d2} {
    $self instvar packetSize_ testName_
    $self instvar cir0 cbs0 pir0 pbs0 ebs0 rate0 cir1 cbs1 pir1 pbs1 ebs1 rate1

    # Set DS RED parameters from Edge to Core:
    $qec_ meanPktSize $packetSize_
    $qec_ set numQueues_ 1
    $qec_ setNumPrec 2

    switch $testName_ {
	"tb" {          # Token bucket policy
	    $qec_ addPolicyEntry [$s1 id] [$d1 id] TokenBucket 10 $cir0 $cbs0
	    $qec_ addPolicyEntry [$s2 id] [$d2 id] TokenBucket 10 $cir1 $cbs1
	    $qec_ addPolicerEntry TokenBucket 10 11
	}

	"tsw2cm" { 	# TSW2CM policy
	    $qec_ addPolicyEntry [$s1 id] [$d1 id] TSW2CM 10 $cir0
	    $qec_ addPolicyEntry [$s2 id] [$d2 id] TSW2CM 10 $cir1
	    $qec_ addPolicerEntry TSW2CM 10 11
	}

	"tsw3cm" { 	# TSW3CM policy
	    $qec_ setNumPrec 3
	    $qec_ addPolicyEntry [$s1 id] [$d1 id] TSW3CM 10 $cir0 $pir0
	    $qec_ addPolicyEntry [$s2 id] [$d2 id] TSW3CM 10 $cir1 $pir1
	    $qec_ addPolicerEntry TSW3CM 10 11 12
	    $qec_ addPHBEntry 12 0 2
	    $qec_ configQ 0 2  5 10 0.20
	}

	"srtcm" { 	# SRTCM policy
	    $qec_ setNumPrec 3
	    $qec_ addPolicyEntry [$s1 id] [$d1 id] srTCM 10 $cir0 $cbs0 $ebs0
	    $qec_ addPolicyEntry [$s2 id] [$d2 id] srTCM 10 $cir1 $cbs1 $ebs1
	    $qec_ addPolicerEntry srTCM 10 11 12
	    $qec_ addPHBEntry 12 0 2
	    $qec_ configQ 0 2  5 10 0.20
	}
	
	"trtcm" { 	# TRTCM policy
	    $qec_ setNumPrec 3
	    $qec_ addPolicyEntry [$s1 id] [$d1 id] trTCM 10 $cir0 $cbs0 $pir0 $pbs0
	    $qec_ addPolicyEntry [$s2 id] [$d2 id] trTCM 10 $cir1 $cbs1 $pir1 $pbs1
	    $qec_ addPolicerEntry trTCM 10 11 12
	    $qec_ addPHBEntry 12 0 2
	    $qec_ configQ 0 2  5 10 0.20
	}

	default {error "Unknow policer!!! exist"}
    }

    $qec_ addPHBEntry 10 0 0
    $qec_ addPHBEntry 11 0 1
    $qec_ configQ 0 0 20 40 0.02
    $qec_ configQ 0 1 10 20 0.10

    # Set DS RED parameters from Core to Edge:
    $qce_ meanPktSize $packetSize_
    $qce_ set numQueues_ 1
    $qce_ setNumPrec 2
    $qce_ addPHBEntry 10 0 0
    $qce_ addPHBEntry 11 0 1
    $qce_ configQ 0 0 20 40 0.02
    $qce_ configQ 0 1 10 20 0.10

    if {$testName_ == "tsw3cm" || $testName_ == "srtcm" || $testName_ == "trtcm"} {
	$qce_ setNumPrec 3
	$qce_ addPHBEntry 12 0 2
	$qce_ configQ 0 2  5 10 0.20
    }
}


# Create the simulation scenario for the test suite.
TestSuite instproc create-scenario {} { 
    global quiet
    $self instvar ns_ packetSize_ finishTime_ testName_ rate0 rate1

    # Set up the network topology shown above:
    set s1 [$ns_ node]
    set s2 [$ns_ node]
    set e1 [$ns_ node]
    set core [$ns_ node]
    set e2 [$ns_ node]
    set dest [$ns_ node]

    $ns_ duplex-link $s1 $e1 10Mb 5ms DropTail
    $ns_ duplex-link $s2 $e1 10Mb 5ms DropTail
    
    $ns_ simplex-link $e1 $core 10Mb 5ms dsRED/edge
    $ns_ simplex-link $core $e1 10Mb 5ms dsRED/core
    
    $ns_ simplex-link $core $e2 5Mb 5ms dsRED/core
    $ns_ simplex-link $e2 $core 5Mb 5ms dsRED/edge
    
    $ns_ duplex-link $e2 $dest 10Mb 5ms DropTail

    # Config each RED queue.
    set qE1C [[$ns_ link $e1 $core] queue]
    set qE2C [[$ns_ link $e2 $core] queue]
    set qCE1 [[$ns_ link $core $e1] queue]
    set qCE2 [[$ns_ link $core $e2] queue]

    # Set DS RED parameters for Qs:
    $self create_q $qE1C $qCE1 $s1 $s2 $dest $dest
    $self create_q $qE2C $qCE2 $dest $dest $s1 $s2
    
    # Set up one CBR connection between each source and the destination:
    set udp0 [new Agent/UDP]
    $ns_ attach-agent $s1 $udp0
    set cbr0 [new Application/Traffic/CBR]
    $cbr0 attach-agent $udp0
    $cbr0 set packet_size_ $packetSize_
    $udp0 set packetSize_ $packetSize_
    $cbr0 set rate_ $rate0
    set null0 [new Agent/Null]
    $ns_ attach-agent $dest $null0
    $ns_ connect $udp0 $null0
    $ns_ at 0.0 "$cbr0 start"
    $ns_ at $finishTime_ "$cbr0 stop"

    set udp1 [new Agent/UDP]
    $ns_ attach-agent $s2 $udp1
    set cbr1 [new Application/Traffic/CBR]
    $cbr1 attach-agent $udp1
    $cbr1 set packet_size_ $packetSize_
    $udp1 set packetSize_ $packetSize_
    $cbr1 set rate_ $rate1
    set null1 [new Agent/Null]
    $ns_ attach-agent $dest $null1
    $ns_ connect $udp1 $null1
    $ns_ at 0.0 "$cbr1 start"
    $ns_ at $finishTime_ "$cbr1 stop"

    if {$quiet == 0} {
	$qE1C printPolicyTable
	$qE1C printPolicerTable
	$ns_ at 10.0 "$qCE2 printStats"
	$ns_ at 20.0 "$qCE2 printStats"
    }
}

TestSuite instproc init {} {
    global tracefd quiet
    $self instvar ns_ testName_ finishTime_ packetSize_

    set ns_         [new Simulator]
    set tracefd	[open "temp.rands" w]
    $ns_ trace-all $tracefd

    set finishTime_ 10.0
    set packetSize_ 1000
    
    if {$quiet == 0} {
	$ns_ at $finishTime_ "puts \"NS EXITING...\" ;"
    }

    $ns_ at [expr $finishTime_ + 1.0] "$self finish"
}


Test/tb instproc init {} {
    $self instvar ns_ testName_ cir0 cbs0 rate0 cir1 cbs1 rate1
    set testName_       tb
    set cir0  1000000
    set cbs0     3000
    set rate0 2000000
    set cir1  1000000
    set cbs1    10000
    set rate1 3000000

    $self next
}

Test/tb instproc run {} {
    $self instvar ns_
    
    $self create-scenario
    $ns_ run
}

Test/tsw2cm instproc init {} {
    $self instvar ns_ testName_ cir0 rate0 cir1 rate1
    set testName_       tsw2cm
    set cir0  1000000
    set rate0 2000000
    set cir1  1000000
    set rate1 3000000

    $self next
}

Test/tsw2cm instproc run {} {
    $self instvar ns_

    $self create-scenario
    $ns_ run
}

Test/tsw3cm instproc init {} {
    $self instvar ns_ testName_ cir0 pir0 rate0 cir1 pir1 rate1
    set testName_       tsw3cm
    set cir0   100000
    set pir0   500000
    set rate0 4000000
    set cir1   400000
    set pir1  1000000
    set rate1 2000000

    $self next
}

Test/tsw3cm instproc run {} {
    $self instvar ns_

    $self create-scenario
    $ns_ run
}

Test/srtcm instproc init {} {
    $self instvar ns_ testName_ cir0 cbs0 ebs0 rate0 cir1 cbs1 ebs1 rate1
    set testName_ srtcm
    set cir0  1000000
    set cbs0     2000
    set ebs0     3000 
    set rate0 3000000
    set cir1  1000000
    set cbs1     2000
    set ebs1     6000
    set rate1 3000000

    $self next
}

Test/srtcm instproc run {} {
    $self instvar ns_

    $self create-scenario
    $ns_ run
}

Test/trtcm instproc init {} {
    $self instvar ns_ testName_ cir0 cbs0 pir0 pbs0 rate0 cir1 cbs1 pir1 pbs1 rate1
    set testName_ trtcm

    set cir0  1000000
    set cbs0     2000
    set pir0  2000000
    set pbs0     3000 
    set rate0 3000000
    set cir1  1000000
    set cbs1     2000
    set pir1  1000000
    set pbs1     3000
    set rate1 3000000

    $self next
}

Test/trtcm instproc run {} {
    $self instvar ns_

    $self create-scenario
    $ns_ run
}

TestSuite instproc finish {} {
    global quiet tracefd
    $self instvar ns_
    
    $ns_ flush-trace
    close $tracefd
    
    if {$quiet == 0} {
	puts "finishing.." }

    exit 0
}

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]
	if {$quiet == 0} {
	    puts "Starting Simulation..." }
	$t run
}

global argv arg0
runtest $argv