-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathremy.tcl
More file actions
executable file
·383 lines (340 loc) · 13.1 KB
/
remy.tcl
File metadata and controls
executable file
·383 lines (340 loc) · 13.1 KB
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
# Experiments with on-off sources that transmit data for a certain
# "on" time and then are silent for a certain "off" time. The on and
# off times come from exponential distributions at specifiable rates.
# During the "on" period, the data isn't sent at a constant bit rate
# as in the existing exponential on-off traffic model in
# tools/expoo.cc but is instead sent according to the underlying
# transport (agent) protocol, such as TCP. The "off" period is the
# same as in that traffic model.
#!/bin/sh
# the next line finds ns \
nshome=`dirname $0`; [ ! -x $nshome/ns ] && [ -x ../../../ns ] && nshome=../../..
# the next line starts ns \
export nshome; exec $nshome/ns "$0" "$@"
if [info exists env(nshome)] {
set nshome $env(nshome)
} elseif [file executable ../../../ns] {
set nshome ../../..
} elseif {[file executable ./ns] || [file executable ./ns.exe]} {
set nshome "[pwd]"
} else {
puts "$argv0 cannot find ns directory"
exit 1
}
set env(PATH) "$nshome/bin:$env(PATH)"
source logging-app.tcl
source stat-collector.tcl
set conffile [lindex $argv 0]
#set conffile remyconf/vz4gdown.tcl
#set conffile remyconf/equisource.tcl
proc Usage {} {
global opt argv0
puts "Usage: $argv0 \[-simtime seconds\] \[-seed value\] \[-nsrc numSources\]"
puts "\t\[-tr tracefile\]"
puts "\t\[-bw $opt(bneck)] \[-delay $opt(delay)\]"
exit 1
}
proc Getopt {} {
global opt argc argv
# if {$argc == 0} Usage
for {set i 1} {$i < $argc} {incr i} {
set key [lindex $argv $i]
if ![string match {-*} $key] continue
set key [string range $key 1 end]
set val [lindex $argv [incr i]]
set opt($key) $val
if [string match {-[A-z]*} $val] {
incr i -1
continue
}
}
}
#
# Create a simple dumbbell topology.
#
proc create-dumbbell-topology {bneckbw delay} {
global ns opt s gw d accessrate accessdelay nshome
for {set i 0} {$i < $opt(nsrc)} {incr i} {
# $ns duplex-link $s($i) $gw 10Mb 1ms DropTail
# $ns duplex-link $gw $d $bneckbw $delay DropTail
$ns duplex-link $s($i) $gw $accessrate($i) $accessdelay($i) $opt(gw)
$ns queue-limit $s($i) $gw $opt(maxq)
$ns queue-limit $gw $s($i) $opt(maxq)
if { $opt(gw) == "XCP" } {
# not clear why the XCP code doesn't do this automatically
set lnk [$ns link $s($i) $gw]
set q [$lnk queue]
$q set-link-capacity [ [$lnk set link_] set bandwidth_ ]
set rlnk [$ns link $gw $s($i)]
set rq [$rlnk queue]
$rq set-link-capacity [ [$rlnk set link_] set bandwidth_ ]
}
}
if { $opt(link) == "trace" } {
$ns simplex-link $d $gw [ bw_parse $bneckbw ] $delay $opt(gw)
# [ [ $ns link $d $gw ] link ] trace-file "$nshome/link/tracedata/uplink-verizon4g.pps"
source $nshome/link/trace.tcl
$ns simplex-link $gw $d [ bw_parse $bneckbw ] $delay $opt(gw)
[ [ $ns link $gw $d ] link ] trace-file $opt(linktrace)
} else {
$ns duplex-link $gw $d $bneckbw $delay $opt(gw)
}
$ns queue-limit $gw $d $opt(maxq)
$ns queue-limit $d $gw $opt(maxq)
if { $opt(gw) == "XCP" } {
# not clear why the XCP code doesn't do this automatically
set lnk [$ns link $gw $d]
set q [$lnk queue]
$q set-link-capacity [ [$lnk set link_] set bandwidth_ ]
set rlnk [$ns link $d $gw]
set rq [$rlnk queue]
$rq set-link-capacity [ [$rlnk set link_] set bandwidth_ ]
}
}
proc create-sources-sinks {} {
global ns opt s d src recvapp tp protocols protosinks f
set numsrc $opt(nsrc)
if { [string range $opt(tcp) 0 9] == "TCP/Linux/"} {
set linuxcc [ string range $opt(tcp) 10 [string length $opt(tcp)] ]
set opt(tcp) "TCP/Linux"
}
if { $opt(tcp) == "DCTCP" } {
Agent/TCP set dctcp_ true
Agent/TCP set ecn_ 1
Agent/TCP set old_ecn_ 1
Agent/TCP set packetSize_ $opt(pktsize)
Agent/TCP/FullTcp set segsize_ $opt(pktsize)
Agent/TCP set window_ 1256
Agent/TCP set slow_start_restart_ false
Agent/TCP set tcpTick_ 0.01
Agent/TCP set minrto_ 0.2 ; # minRTO = 200ms
Agent/TCP set windowOption_ 0
Queue/RED set bytes_ false
Queue/RED set queue_in_bytes_ true
Queue/RED set mean_pktsize_ $opt(pktsize)
Queue/RED set setbit_ true
Queue/RED set gentle_ false
Queue/RED set q_weight_ 1.0
Queue/RED set mark_p_ 1.0
Queue/RED set thresh_ 65
Queue/RED set maxthresh_ 65
DelayLink set avoidReordering_ true
set opt(tcp) "TCP/Newreno"
}
for {set i 0} {$i < $numsrc} {incr i} {
if { $opt(cycle_protocols) == true } {
set opt(tcp) [lindex $protocols [expr $i % $opt(nsrc)]]
set opt(sink) [lindex $protosinks [expr $i % $opt(nsrc)]]
if { [string range $opt(tcp) 0 9] == "TCP/Linux/"} {
set linuxcc [ string range $opt(tcp) 10 [string length $opt(tcp)] ]
set opt(tcp) "TCP/Linux"
}
if { $opt(tcp) == "DCTCP" } {
Agent/TCP set dctcp_ true
Agent/TCP set ecn_ 1
Agent/TCP set old_ecn_ 1
Agent/TCP set packetSize_ $opt(pktsize)
Agent/TCP/FullTcp set segsize_ $opt(pktsize)
Agent/TCP set window_ 1256
Agent/TCP set slow_start_restart_ false
Agent/TCP set tcpTick_ 0.01
Agent/TCP set minrto_ 0.2 ; # minRTO = 200ms
Agent/TCP set windowOption_ 0
Queue/RED set bytes_ false
Queue/RED set queue_in_bytes_ true
Queue/RED set mean_pktsize_ $opt(pktsize)
Queue/RED set setbit_ true
Queue/RED set gentle_ false
Queue/RED set q_weight_ 1.0
Queue/RED set mark_p_ 1.0
Queue/RED set thresh_ 65
Queue/RED set maxthresh_ 65
DelayLink set avoidReordering_ true
set opt(tcp) "TCP/Newreno"
}
}
set tp($i) [$ns create-connection-list $opt(tcp) $s($i) $opt(sink) $d $i]
set tcpsrc [lindex $tp($i) 0]
set tcpsink [lindex $tp($i) 1]
if { [info exists linuxcc] } {
$ns at 0.0 "$tcpsrc select_ca $linuxcc"
$ns at 0.0 "$tcpsrc set_ca_default_param linux debug_level 2"
}
if { [string first "Rational" $opt(tcp)] != -1 } {
if { $opt(tracewhisk) == "all" || $opt(tracewhisk) == $i } {
$tcpsrc set tracewhisk_ 1
puts "tracing ON for connection $i: $opt(tracewhisk)"
} else {
$tcpsrc set tracewhisk_ 0
puts "tracing OFF for connection $i: $opt(tracewhisk)"
}
}
$tcpsrc set window_ $opt(rcvwin)
$tcpsrc set packetSize_ $opt(pktsize)
if { [info exists opt(tr)] } {
$tcpsrc trace cwnd_
$tcpsrc trace rtt_
$tcpsrc trace maxseq_
$tcpsrc trace ack_
if { $opt(tcp) == "TCP/Rational" } {
$tcpsrc trace _intersend_time
}
$tcpsrc attach $f
}
# set src($i) [ $tcpsrc attach-app $opt(app) ]
set src($i) [ $tcpsrc attach-source $opt(app) ]
set recvapp($i) [new LoggingApp $i]
$recvapp($i) attach-agent $tcpsink
$ns at 0.0 "$recvapp($i) start"
}
}
proc showstats {final} {
global ns opt stats
for {set i 0} {$i < $opt(nsrc)} {incr i} {
set res [$stats($i) results]
set totalbytes [lindex $res 0]
set totaltime [lindex $res 1]
set totalrtt [lindex $res 2]
set nsamples [lindex $res 3]
set nconns [lindex $res 4]
if { $totaltime > 0.0 && $nsamples > 0} {
set throughput [expr 8.0 * $totalbytes / $totaltime]
set avgrtt [expr 1000*$totalrtt/$nsamples]
if { $avgrtt > 0.0 } {
set utility [expr log($throughput) - [expr $opt(alpha)*log($avgrtt)]]
} else {
set utility [expr log($throughput)
}
if { $final == True } {
puts [ format "FINAL %d %d %.3f %.1f %.2f %.2f %d" $i $totalbytes [expr $throughput/1000000.0] $avgrtt [expr 100.0*$totaltime/$opt(simtime)] $utility $nconns ]
} else {
puts [ format "----- %d %d %.3f %.1f %.2f %.2f %d" $i $totalbytes [expr $throughput/1000000.0] $avgrtt [expr 100.0*$totaltime/$opt(simtime)] $utility $nconns]
}
}
}
}
# proc showstats {final} {
# global ns opt stats
# for {set i 0} {$i < $opt(nsrc)} {incr i} {
# set res [$stats($i) results]
# set totalbytes [lindex $res 0]
# set totaltime [lindex $res 1]
# set totalrtt [lindex $res 2]
# set nsamples [lindex $res 3]
# set nconns [lindex $res 4]
# if { $nsamples > 0 } {
# set avgrtt [expr 1000*$totalrtt/$nsamples]
# } else {
# set avgrtt 0.0
# }
# if { $totaltime > 0.0} {
# set throughput [expr 8.0 * $totalbytes / $totaltime]
# set utility [expr log($throughput) - [expr $opt(alpha)*log($avgrtt)]]
# if { $final == True } {
# puts [ format "FINAL %d %d %.3f %.1f %.4f %.2f %d" $i $totalbytes [expr $throughput/1000000.0] $avgrtt [expr 100.0*$totaltime/$opt(simtime)] $utility $nconns ]
# } else {
# puts [ format "----- %d %d %.3f %.1f %.4f %.2f %d" $i $totalbytes [expr $throughput/1000000.0] $avgrtt [expr 100.0*$totaltime/$opt(simtime)] $utility $nconns]
# }
# }
# }
# }
proc finish {} {
global ns opt stats recvapp
global f
for {set i 0} {$i < $opt(nsrc)} {incr i} {
set rapp $recvapp($i)
if { [$rapp set state_] == ON} {
# If the current state is ON, then we have one more set of stats to update.
# Otherwise, we're all set and there's nothing to update.
set nbytes [$rapp set nbytes_]
set ontime [expr [$ns now] - [$rapp set laststart_] ]
set cumrtt [$rapp set cumrtt_]
set numsamples [$rapp set numsamples_]
set rttsamples [$rapp set rtt_samples_]
set srcid [$rapp set srcid_]
$stats($srcid) update $nbytes $ontime $cumrtt $numsamples $rttsamples
}
}
showstats True
if { [info exists f] } {
$ns flush-trace
close $f
}
exit 0
}
## MAIN ##
source $conffile
puts "Reading params from $conffile"
Getopt
set_access_params $opt(nsrc)
if { $opt(gw) == "XCP" } {
remove-all-packet-headers ; # removes all except common
add-packet-header Flags IP TCP XCP ; # hdrs reqd for validation
}
if { $opt(seed) >= 0 } {
ns-random $opt(seed)
}
set ns [new Simulator]
Queue set limit_ $opt(maxq)
#RandomVariable/Pareto set shape_ 0.5
if { [info exists opt(tr)] } {
# if we don't set up tracing early, trace output isn't created!!
set f [open $opt(tr).tr w]
$ns trace-all $f
}
set flowfile flowcdf-allman-icsi.tcl
# create sources, destinations, gateways
for {set i 0} {$i < $opt(nsrc)} {incr i} {
set s($i) [$ns node]
}
set d [$ns node]; # destination for all the TCPs
set gw [$ns node]; # bottleneck router
create-dumbbell-topology $opt(bneck) $opt(delay)
create-sources-sinks
for {set i 0} {$i < $opt(nsrc)} {incr i} {
if { [info exists opt(spike)] } {
$recvapp($i) reset
if {$i == 0} {
$recvapp($i) set endtime_ $opt(simtime)
set starttime [$ns now]
} else {
$recvapp($i) set endtime_ $opt(spikeduration)
set starttime [expr [$ns now] + $opt(spikestart)]
}
$recvapp($i) set state_ ON
$recvapp($i) set laststart_ $starttime
$ns at $starttime "$src($i) start"
} else {
set on_ranvar($i) [new RandomVariable/$opt(onrand)]
if { $opt(ontype) == "time" } {
$on_ranvar($i) set avg_ $opt(onavg)
} elseif { $opt(ontype) == "bytes" } {
$on_ranvar($i) set avg_ $opt(avgbytes)
} elseif { $opt(ontype) == "flowcdf" } {
source $flowfile
}
set off_ranvar($i) [new RandomVariable/$opt(offrand)]
$off_ranvar($i) set avg_ $opt(offavg)
if { [expr $i % 2] == 1 } {
# start only the odd-numbered connections immediately
$recvapp($i) go 0.0
} else {
$recvapp($i) go [$off_ranvar($i) value]
}
}
set stats($i) [new StatCollector $i $opt(tcp)]
}
if { $opt(cycle_protocols) == true } {
for {set i 0} {$i < $opt(nsrc)} {incr i} {
puts "$i: [lindex $protocols $i]"
}
} else {
if { [info exists linuxcc] } {
puts "Results for $opt(tcp)/$linuxcc $opt(gw) $opt(sink) over $opt(simtime) seconds:"
} else {
puts "Results for $opt(tcp) $opt(gw) $opt(sink) over $opt(simtime) seconds:"
}
}
puts " SrcID Bytes Mbits/s AvgRTT On% Utility NumConns"
$ns at $opt(simtime) "finish"
$ns run