forked from phonfin/Homa_NS2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
simpleDumbbell_homa.tcl
226 lines (166 loc) · 5.4 KB
/
simpleDumbbell_homa.tcl
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
set N 2
set BUFFER 240
set K 65
set RTT 0.0001
set enableNAM 0;
set enableTraceAll 1;
set simulationTime 2.0
set startMeasurementTime 1
set stopMeasurementTime 2
set flowClassifyTime 0.001
set lineRate 1Gb
set inputLineRate 1Gb
set trace_all_name "./Homa_trace_all_[lindex $argv 0].ta";
set nam_file "./Homa_nam_[lindex $argv 0].nam";
set packetSize 1460
set flowSize [expr 1000*$packetSize];
set flowSize_BG [expr 2000*$packetSize];
set traceSamplingInterval 0.0001
set throughputSamplingInterval 0.01
set ns [new Simulator]
Agent/TCP set packetSize_ $packetSize
Agent/TCP set window_ 2000
Agent/TCP set minrto_ 0.2 ; # minRTO = 200ms
Agent/TCP/FullTcp set interval_ 0.04 ; #delayed ACK interval = 40ms
Queue set limit_ 1000
if {$enableNAM != 0} {
set namfile [open out.nam w]
$ns namtrace-all $namfile
}
if {$enableTraceAll != 0} {
set traceall [open $trace_all_name w];
$ns trace-all $traceall;
}
set mytracefile [open mytracefile.tr w]
set throughputfile [open thrfile.tr w]
proc finish {} {
global ns traceall enableTraceAll enableNAM namfile mytracefile throughputfile
$ns flush-trace
close $mytracefile
close $throughputfile
if {$enableNAM != 0} {
close $namfile
exec nam out.nam &
}
if {$enableTraceAll != 0} {
close $traceall;
}
exit 0
}
proc myTrace {file} {
global ns N traceSamplingInterval tcp qfile MainLink nbow nclient packetSize enableBumpOnWire
set now [$ns now]
$qfile instvar parrivals_ pdepartures_ pdrops_ bdepartures_
puts -nonewline $file " [expr $parrivals_-$pdepartures_-$pdrops_]"
puts $file " $pdrops_"
$ns at [expr $now+$traceSamplingInterval] "myTrace $file"
}
proc throughputTrace {file} {
global ns throughputSamplingInterval qfile flowstats N flowClassifyTime
set now [$ns now]
$qfile instvar bdepartures_
puts -nonewline $file "$now [expr $bdepartures_*8/$throughputSamplingInterval/1000000]"
set bdepartures_ 0
if {$now <= $flowClassifyTime} {
for {set i 0} {$i < [expr $N-1]} {incr i} {
puts -nonewline $file " 0"
}
puts $file " 0"
}
if {$now > $flowClassifyTime} {
for {set i 0} {$i < [expr $N-1]} {incr i} {
$flowstats($i) instvar barrivals_
puts -nonewline $file " [expr $barrivals_*8/$throughputSamplingInterval/1000000]"
set barrivals_ 0
}
$flowstats([expr $N-1]) instvar barrivals_
puts $file " [expr $barrivals_*8/$throughputSamplingInterval/1000000]"
set barrivals_ 0
}
$ns at [expr $now+$throughputSamplingInterval] "throughputTrace $file"
}
$ns color 0 Red
$ns color 1 Orange
$ns color 2 Yellow
$ns color 3 Green
$ns color 4 Blue
$ns color 5 Violet
$ns color 6 Brown
$ns color 7 Black
for {set i 0} {$i < $N} {incr i} {
set n($i) [$ns node]
}
set nqueue [$ns node]
set nclient [$ns node]
$nqueue color red
$nqueue shape box
$nclient color blue
for {set i 0} {$i < $N} {incr i} {
$ns duplex-link $n($i) $nqueue $inputLineRate [expr $RTT/4] DropTail
$ns duplex-link-op $n($i) $nqueue queuePos 0.25
}
$ns simplex-link $nqueue $nclient $lineRate [expr $RTT/4] Homa_PriQueue
$ns simplex-link $nclient $nqueue $lineRate [expr $RTT/4] Homa_PriQueue
$ns queue-limit $nqueue $nclient $BUFFER
$ns duplex-link-op $nqueue $nclient color "green"
$ns duplex-link-op $nqueue $nclient queuePos 0.25
set qfile [$ns monitor-queue $nqueue $nclient [open queue.tr w] $traceSamplingInterval]
for {set i 0} {$i < $N} {incr i} {
set tcp($i) [new Agent/TCP/Newreno]
set sink($i) [new Agent/TCPSink]
$ns attach-agent $n($i) $tcp($i)
$ns attach-agent $nclient $sink($i)
$tcp($i) set fid_ [expr $i]
$sink($i) set fid_ [expr $i]
$tcp($i) set flowsize_ $flowSize;
# this nid_ is the identifier of receivers. Make sure the flows with the same receiver have the same nid_!
$sink($i) set nid_ 1;
$ns connect $tcp($i) $sink($i)
}
# $tcp(1) set flowsize_ $flowSize_BG;
for {set i 0} {$i < $N} {incr i} {
set ftp($i) [new Application/FTP]
$ftp($i) attach-agent $tcp($i)
}
$ns at $traceSamplingInterval "myTrace $mytracefile"
$ns at $throughputSamplingInterval "throughputTrace $throughputfile"
set ru [new RandomVariable/Uniform]
$ru set min_ 0
$ru set max_ 1.0
for {set i 0} {$i < $N} {incr i} {
$ns at 0.0 "$ftp($i) send 1"
# $ns at 0.1 "$ftp($i) send $flowSize"
}
for {set i 0} {$i < $N} {incr i} {
$ns at 0.1 "$ftp($i) send $flowSize";
}
# $ns at 0.1 "$ftp(1) send $flowSize_BG";
set flowmon [$ns makeflowmon Fid]
set MainLink [$ns link $nqueue $nclient]
$ns attach-fmon $MainLink $flowmon
set fcl [$flowmon classifier]
$ns at $flowClassifyTime "classifyFlows"
proc classifyFlows {} {
global N fcl flowstats
puts "NOW CLASSIFYING FLOWS"
for {set i 0} {$i < $N} {incr i} {
set flowstats($i) [$fcl lookup autp 0 0 $i]
}
}
set startPacketCount 0
set stopPacketCount 0
proc startMeasurement {} {
global qfile startPacketCount
$qfile instvar pdepartures_
set startPacketCount $pdepartures_
}
proc stopMeasurement {} {
global qfile startPacketCount stopPacketCount packetSize startMeasurementTime stopMeasurementTime simulationTime
$qfile instvar pdepartures_
set stopPacketCount $pdepartures_
puts "Throughput = [expr ($stopPacketCount-$startPacketCount)/(1024.0*1024*($stopMeasurementTime-$startMeasurementTime))*$packetSize*8] Mbps"
}
#$ns at $startMeasurementTime "startMeasurement"
#$ns at $stopMeasurementTime "stopMeasurement"
$ns at $simulationTime "finish"
$ns run