File: http-single.tcl

package info (click to toggle)
ns2 2.35%2Bdfsg-3.1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 78,808 kB
  • sloc: cpp: 172,923; tcl: 107,130; perl: 6,391; sh: 6,143; ansic: 5,846; makefile: 816; awk: 525; csh: 355
file content (390 lines) | stat: -rw-r--r-- 10,869 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
#
# Copyright (c) 1997 Regents of the University of California.
# All rights reserved.
# 
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
# 2. 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.
# 3. All advertising materials mentioning features or use of this software
#    must display the following acknowledgement:
# 	This product includes software developed by the MASH Research
# 	Group at the University of California Berkeley.
# 4. Neither the name of the University nor of the Research Group may be
#    used to endorse or promote products derived from this software without
#    specific prior written permission.
# 
# THIS SOFTWARE IS PROVIDED BY THE REGENTS 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.
#
# This file contributed by Curtis Villamizar <curtis@ans.net>, May 1997.
# Maintainer: John Heidemann <johnh@isi.edu>.
#

#
# WARNING:  This code uses the compatibility library and so should not
# be used as an example.  Hopefully at some time in the future it will
# be updated.
#

# Create a three node test environment
#
#  c1 -------- isp1 -------- s1
#      28.8kb        1.54mb
#     modemdelay    netdelay
#

proc create_testnet { } {
    global testnet

    set testnet(c1) [ns node]
    set testnet(isp1) [ns node]
    set testnet(s1) [ns node]

    set testnet(L1) \
	    [ns_duplex $testnet(c1) $testnet(isp1) \
	    $testnet(modemspeed) $testnet(modemdelay) $testnet(qtype)]
    ns_duplex $testnet(isp1) $testnet(s1) \
	    $testnet(netspeed) $testnet(netdelay) drop-tail
    [lindex $testnet(L1) 0] set queue-limit $testnet(modemqueue)
    [lindex $testnet(L1) 1] set queue-limit $testnet(modemqueue)
    if {$testnet(qtype) == "red"} {
	set redlink [ns link $testnet(c1) $testnet(isp1)]
	$redlink set thresh [expr $testnet(modemqueue) * 0.25]
	$redlink set maxthresh [expr $testnet(modemqueue) * 0.85]
	$redlink set q_weight 0.001
	$redlink set wait_ 1
	$redlink set dropTail_ 1
    }
}

proc tcpDump { tcpSrc interval } {
    proc dump { src interval } {
	ns at [expr [ns now] + $interval] "dump $src $interval"
	puts [ns now]/ack=[$src get ack]
    }
    ns at 0.0 "dump $tcpSrc $interval"
}

proc trigger { xresults } {
    global testnet flows

    # NEEDSWORK:  should we really indirect once down results like this?
    set results "[lindex $xresults 0]"
    set type [lindex $results 0]
    if { $type != "-" && $type != "d" } {
	return;
    }
    set id [lindex $results 7]
    set counter [format "count%d" $id]
    if { [info exists flows($counter)] } {
	incr flows($counter)
    } else {
	set flows($counter) 1
    }
    if { $type != "-" } {
	return;
    }
    set got [expr 1 + [lindex $results 10]]
    set isrunning isrunning$id
    if { $id == 0 } {
	if { $got == $testnet(httpsize) } {
	    puts [format "http flow completed at %s" [lindex $results 1]]
	    incr flows(flows_running) -1
	    set flows($isrunning) 0
	}
    } else {
	if { $got == $testnet(inlinesize) } {
	    puts [format "inline%d completed at %s" $id [lindex $results 1]]
	    incr flows(flows_running) -1
	    incr flows(inlines_running) -1
	    set flows($isrunning) 0
	}
    }
    set flows(persist) 1
    if { $flows(count0) >= 1 } {
	while {$flows(inlines_started) < $flows(inlines_needed) \
		&& $flows(flows_running) < $flows(flows_allowed) \
		&& $flows(inlines_running) < $flows(inlines_allowed) } {
	    incr flows(inlines_started)
	    incr flows(flows_running)
	    incr flows(inlines_running)
	    set ident $flows(inlines_started)
	    set nextflow inline$ident
	    if {$flows(persist)} {
		for {set j 0} {$j < $ident} {incr j} {
		    set isrunning isrunning$j
		    if {$flows($isrunning) == 0} {
			set thisflow tcp$ident
			if {$j == 0} {
			    set otherflow tcp0
			} else {
			    set otherflow tcp$j
			}
			$flows($thisflow) persist $flows($otherflow)
			break
		    }
		}
	    }
	    $flows($nextflow) start
	    set isrunning isrunning$ident
	    set flows($isrunning) 1
	    puts [format "trigger at %s: start %d" \
		    [lindex $results 1] $flows(inlines_started)]
	}
    }
}

proc openTrace { stopTime testName } {
    exec rm -f out.tr temp.rands
    set traceFile [open out.tr w]
    ns at $stopTime "close $traceFile ; finish $testName"
    set T [ns trace]
    $T attach $traceFile
    return $T
}

proc finish file {
    global testnet flows

    set f [open temp.rands w]
    puts $f "TitleText: $file"
    puts $f "Device: Postscript"
    
    set total 0
    for { set i 0 } { $i <= $flows(inlines_needed) } { incr i } {
	set counter [format "count%d" $i]
	set got $flows($counter)
	incr total $got
	puts [format "flow %d : %d packets" $i $got]
    }
    set needed [expr $testnet(httpsize) \
	    + ( $flows(inlines_needed) * $testnet(inlinesize) )]
    set discard [expr $total - $needed]
    puts [format "%d sent : %d needed : %d discarded : %d %%" \
	    $total $needed $discard [expr 100 * $discard / $needed]]
    if { $testnet(dograph) == 0 } {
	exit 0
    }
    exec rm -f temp.p temp.d 
    exec touch temp.d temp.p
    #
    # split queue/drop events into two separate files.
    # we don't bother checking for the link we're interested in
    # since we know only such events are in our trace file
    #
    exec awk {
	{
	    if (($1 == "-" ) && \
		    ($5 == "tcp" || $5 == "ack") && \
		    ($8 == 0 || ($8 == 4 && $11 <= 6))) \
		    print $2, $8 + ($11 % 90) * 0.01
	}
    } out.tr > temp.p1
    exec awk {
	{
	    if (($1 == "-" ) && \
		    ($5 == "tcp" || $5 == "ack") && \
		    ($8 == 1 || ($8 == 4 && $11 > 6 && $11 <= 26))) \
		    print $2, $8 + ($11 % 90) * 0.01
	}
    } out.tr > temp.p2
    exec awk {
	{
	    if (($1 == "-" ) && \
		    ($5 == "tcp" || $5 == "ack") && \
		    ($8 == 2 || $8 == 3 || ($8 == 4 && $11 > 26))) \
		    print $2, $8 + ($11 % 90) * 0.01
	}
    } out.tr > temp.p3
    exec awk {
	{
	    if ($1 == "d")
	    print $2, $8 + ($11 % 90) * 0.01
	}
    } out.tr > temp.d

    puts $f \"packets
    flush $f
    exec cat temp.p1 >@ $f
    flush $f
    puts $f [format "\n\"1st-inline\n"]
    flush $f
    exec cat temp.p2 >@ $f
    flush $f
    puts $f [format "\n\"other-2\n"]
    flush $f
    exec cat temp.p3 >@ $f
    flush $f
    # insert dummy data sets so we get X's for marks in data-set 4
    # puts $f [format "\n\"skip-1\n0 1\n\n\"skip-2\n0 1\n\n"]
    
    puts $f [format "\n\"drops\n"]
    flush $f
    #
    # Repeat the first line twice in the drops file because
    # often we have only one drop and xgraph won't print marks
    # for data sets with only one point.
    #
    exec head -1 temp.d >@ $f
    exec cat temp.d >@ $f
    close $f
    exec xgraph -bb -tk -nl -m -x time -y packet temp.rands &
    
    exit 0
}

proc init_tcp_flow {taskid flowid id size} {
    global testnet flows

    set flow [ns_create_connection tcp-reno \
	    $testnet(s1) tcp-sink $testnet(c1) $id]
    $flow set window $testnet(window)
    $flow set packet-size $testnet(mss)
    $flow set maxcwnd $testnet(window)
    set flows($flowid) $flow 
    set flows($taskid) [$flow source ftp]
    $flows($taskid) set maxpkts_ $size
    # tcpDump $flow $testnet(dumpincr)
}

proc setup_http_test {} {
    global testnet
    global flows

    create_testnet

    init_tcp_flow http tcp0 0 $testnet(httpsize)
    ns at 0.0 "$flows(http) start"
    set flows(isrunning0) 1
    set flows(flows_running) 1
    set flows(count0) 0

    for { set i 1 } { $i <= $flows(inlines_needed) } { incr i } {
	set nexttask [format "inline%d" $i]
	set nextflow [format "tcp%d" $i]
	init_tcp_flow $nexttask $nextflow $i $testnet(inlinesize)
    }

    # trace only the bottleneck link
    set traceme [openTrace $testnet(testlimit) test_http]
    set bottleneck [ns link $testnet(isp1) $testnet(c1)]
    $bottleneck trace $traceme
    $bottleneck callback { trigger }
}

proc set_globals {} {
    global testnet
    set testnet(netspeed) 1.54mb
    set testnet(modemspeed) 28.8kb
    set testnet(netdelay) 150ms
    set testnet(modemdelay) 50ms
    set testnet(mss) 512
    set testnet(window) 64
    set testnet(httpsize) 6
    set testnet(inlinesize) 40
    set testnet(modemqueue) 6
    set testnet(dumpincr) 5.0
    set testnet(testlimit) 50.0
    set testnet(dograph) 0
    set testnet(qtype) drop-tail

    global flows
    set flows(inlines_started) 0
    set flows(inlines_needed) 3
    set flows(flows_running) 0
    set flows(flows_allowed) 4
    set flows(inlines_running) 0
    set flows(inlines_allowed) $flows(flows_allowed)
}

proc process_args {} {
    global argc argv testnet flows

    for {set i 0} {$i < $argc} {incr i} {
	set arg [lindex $argv $i]
	switch x$arg {
	    x-window {
		incr i
		set testnet(window) [lindex $argv $i]
	    }
	    x-graph {
		set testnet(dograph) 1
		puts "match"
	    }
	    x-delayN {
		incr i
		set testnet(netdelay) [lindex $argv $i]
	    }
	    x-delayM {
		incr i
		set testnet(modemdelay) [lindex $argv $i]
	    }
	    x-mss {
		incr i
		set testnet(mss) [lindex $argv $i]
	    }
	    x-httpsize {
		incr i
		set testnet(httpsize) [lindex $argv $i]
	    }
	    x-inlinesize {
		incr i
		set testnet(inlinesize) [lindex $argv $i]
	    }
	    x-queue {
		incr i
		set testnet(modemqueue) [lindex $argv $i]
	    }
	    x-dumpincr {
		incr i
		set testnet(dumpincr) [lindex $argv $i]
	    }
	    x-testlimit {
		incr i
		set testnet(testlimit) [lindex $argv $i]
	    }
	    x-inlines {
		incr i
		set flows(inlines_needed) [lindex $argv $i]
	    }
	    x-maxflow {
		incr i
		set flows(flows_allowed) [lindex $argv $i]
	    }
	    x-maxinline {
		incr i
		set flows(inlines_allowed) [lindex $argv $i]
	    }
	    x-red {
		set testnet(qtype) red
	    }
	    x-sfq {
		set testnet(qtype) sfq
	    }
	    default {
		puts [format "unrecognized argument: %s" [lindex $argv $i]]
		exit 1
	    }
	}
    }
}

set_globals
process_args
setup_http_test
# ns gen-map
ns run