-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathplotter.py
More file actions
executable file
·360 lines (291 loc) · 11 KB
/
Copy pathplotter.py
File metadata and controls
executable file
·360 lines (291 loc) · 11 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
#!/usr/bin/python
import sys
import re
import os
def main():
# Parse log file
log_filename = sys.argv[1]
logfile = open(log_filename, 'r')
avgmax = 0
count = 0
results = {}
results['sw'] = {}
results['mac'] = {}
i = 0
for line in logfile:
if i == 0 :
setting = line.split(' ') # fix_mac, fix_switch, max_threads
fix_mac = int(setting[0])
fix_switch = int(setting[1])
all_threads = int(setting[2])
#print {"%d %d %d" % (fix_mac, fix_switch, all_threads)}
if all_threads > 8:
max_threads = 8
else:
max_threads = all_threads
i += 1
continue
if i == 1 :
switch_list = line[0:-1]
#print switch_list
i += 1
continue
if i == 2 :
mac_list = line[0:-1]
#print mac_list
i += 1
continue
if line[0] == '-' and count != 0:
if not (controller in results[testcase]) :
results[testcase][controller] = {}
for j in range(1,(all_threads+1)) :
results[testcase][controller][j] = {}
if testcase == 'sw' :
results[testcase][controller][threads][switches] = avgmax/count
else :
results[testcase][controller][threads][macs] = avgmax/count
avgmax = 0
count = 0
continue
fields = line.split(' ')
if len(fields) <= 1 : continue
if fields[1][0:10] == 'controller' :
controller = fields[0]
continue
if fields[0] == 'switches:' :
switches = int(fields[1])
if fields[1] == 'MACs' :
testcase = 'sw'
continue
if fields[0] == "MACs" :
macs = int(fields[3])
if len(fields) > 2 and fields[0] == 'Fixed' and fields[2] == 'switches' :
testcase = 'mac'
continue
if fields[0] == 'Threads:' :
threads = int(fields[1])
continue
if fields[0] == 'RESULT:' :
count += 1
avgmax += float(fields[-2].split('/')[0])
#print results
logfile.close()
# Output stats to files
sw_files = {}
mac_files = {}
thr_stats = open('threads', 'w')
sw_stats = open('switches', 'w')
mac_stats = open('macs', 'w')
for controller in sorted(results['sw'].keys()) :
sw_files[controller] = open('sw_' + controller, 'w')
for controller in sorted(results['mac'].keys()) :
mac_files[controller] = open('mac_' + controller, 'w')
# Switch testcase
#thr_stats.write('threads')
#sw_stats.write('threads')
for controller in sorted(results['sw'].keys()) :
#thr_stats.write(' ' + controller)
#sw_stats.write(' ' + controller)
for threads in sorted(results['sw'][controller].keys()) :
#if threads == 1 :
#sw_files[controller].write('threads')
#for sw in sorted(results['sw'][controller][threads].keys()) :
# sw_files[controller].write(' ' + str(sw))
#sw_files[controller].write('\n')
sw_files[controller].write(str(threads))
for sw, flows in sorted(results['sw'][controller][threads].items()) :
sw_files[controller].write(' ' + str(flows))
sw_files[controller].write('\n')
#thr_stats.write('\n')
threads_pool = sorted(results['sw'][controller].keys())
for threads in threads_pool :
thr_stats.write(str(threads))
for controller in sorted(results['sw'].keys()) :
thr_stats.write(' ' + str(results['sw'][controller][threads][fix_switch]))
thr_stats.write('\n')
#sw_stats.write('\n')
switches_pool = sorted(results['sw'][controller][threads].keys())
for switches in switches_pool :
sw_stats.write(str(switches))
for controller in sorted(results['sw'].keys()) :
sw_stats.write(' ' + str(results['sw'][controller][max_threads][switches]))
sw_stats.write('\n')
for f in sw_files.keys() :
sw_files[f].close()
# Macs testcase
#mac_stats.write('threads')
for controller in sorted(results['mac'].keys()) :
#mac_stats.write(' ' + controller)
for threads in sorted(results['mac'][controller].keys()) :
#if threads == 1 :
#mac_files[controller].write('threads')
#for mac in sorted(results['mac'][controller][threads].keys()) :
# mac_files[controller].write(' ' + str(mac))
#mac_files[controller].write('\n')
mac_files[controller].write(str(threads))
for mac, flows in sorted(results['mac'][controller][threads].items()) :
mac_files[controller].write(' ' + str(flows))
mac_files[controller].write('\n')
#mac_stats.write('\n')
mac_pool = sorted(results['mac'][controller][threads].keys())
for mac in mac_pool :
mac_stats.write(str(mac))
for controller in sorted(results['mac'].keys()) :
mac_stats.write(' ' + str(results['mac'][controller][max_threads][mac]))
mac_stats.write('\n')
for f in mac_files.keys() :
mac_files[f].close()
thr_stats.close()
sw_stats.close()
mac_stats.close()
# Plot
def_header = """
#! /usr/bin/gnuplot -persist
set terminal png size 640, 320 enhanced
set key right outside
set size ratio 0.5
set format y "%2.0t{/Symbol \\327}10^{%L}"
set ylabel "Flows/sec"
"""
# Threads
plotscript = open('plotscript.graph', 'w')
plotscript.write(def_header + """
set xrange [1:]
set output "threads.png"
set xlabel "Threads"
""")
numcontr = len(results['sw'])
for i in range(1,numcontr) :
plotscript.write('set style line %d lt 1 lw 2 pt %d linecolor %d\n' % (i, i, i))
i = 0
plotscript.write('plot ')
for controller in sorted(results['sw'].keys()) :
i += 1
plotscript.write('"threads" using 1: %d with linespoints linestyle %d title "%s"' % (i+1, i, controller))
if i != len(results['sw'].keys()) :
plotscript.write(', ')
plotscript.close()
os.system('cat plotscript.graph | gnuplot')
# Switches
plotscript = open('plotscript.graph', 'w')
plotscript.write(def_header + """
set xrange [0:]
set output "switches.png"
set xlabel "Switches"
""")
plotscript.write('set xtics (')
i = 0
for sw in switch_list.split(' ') :
plotscript.write('"%s" %s' % (sw, i))
if i != len(switch_list.split(' ')) - 1 :
plotscript.write(', ')
i+=1
plotscript.write(')\n')
plotscript.write('')
numcontr = len(results['sw'])
for i in range(1,numcontr+1) :
plotscript.write('set style line %d lt 1 lw 2 pt %d linecolor %d\n' % (i, i, i))
i = 0
plotscript.write('plot ')
for controller in sorted(results['sw'].keys()) :
i += 1
plotscript.write('"switches" using %d with linespoints linestyle %d title "%s"' % (i+1, i, controller))
if i != len(results['sw'].keys()) :
plotscript.write(', ')
plotscript.close()
os.system('cat plotscript.graph | gnuplot')
# MACs
plotscript = open('plotscript.graph', 'w')
plotscript.write(def_header + """
set xrange [0:]
set output "macs.png"
set xlabel "MACs per switch"
""")
plotscript.write('set xtics (')
i = 0
for mac in mac_list.split(' ') :
plotscript.write('"%s" %s' % (mac, i))
if i != len(mac_list.split(' ')) - 1 :
plotscript.write(', ')
i+=1
plotscript.write(')\n')
numcontr = len(results['mac'])
for i in range(1,numcontr+1) :
plotscript.write('set style line %s lt 1 lw 2 pt %d linecolor %d\n' % (i, i, i))
i = 0
plotscript.write('plot ')
for controller in sorted(results['mac'].keys()) :
i += 1
plotscript.write('"macs" using %d with linespoints linestyle %d title "%s"' % (i+1, i, controller))
if i != len(results['mac'].keys()) :
plotscript.write(', ')
plotscript.close()
os.system('cat plotscript.graph | gnuplot')
# Controllers
switches = switch_list.split(' ')
macs = mac_list.split(' ')
for testcase in ['sw','mac'] :
for controller in sorted(results[testcase].keys()) :
plotscript = open('plotscript.graph', 'w')
plotscript.write(def_header + 'set output "' + testcase + '_' + controller + '.png"\n' + """
set xlabel "Threads"
set xrange [1:]
set yrange [0:7000000]
""")
if testcase == 'sw' :
title = 'Switches: '
rge = switches
else :
title = 'MACs per switch: '
rge = macs
for i in range(1,len(rge)+1) :
plotscript.write('set style line %d lt 1 lw 2 pt %d linecolor %d\n' % (i, i, i))
plotscript.write('plot ')
fname = testcase + '_' + controller
for i in range(0,len(rge)) :
if rge == switches :
legend = rge[i]
else :
exp = 0
base = int(rge[i])
while base >= 10 :
exp += 1
base = int(base / 10)
if base != 1 :
legend = str(base) + '{/Symbol \\327}10^' + str(exp)
else :
legend = '10^' + str(exp)
plotscript.write('"%s" using 1:%d with linespoints linestyle %d title "%s%s"' % (fname, i+2, i+1, title, legend))
if i != len(rge) -1 :
plotscript.write(', ')
plotscript.close()
os.system('cat plotscript.graph | gnuplot')
# Table
table = open('table.html', 'w')
table.write("""
<html>
<body>
<table width="500" border cellspacing="0">
<tr>
<th>Controller</th>
<th>Max Throughput,<br>Flows/sec</th>
<th>Threads</th>
</tr>
""")
for controller in sorted(results['sw'].keys()) :
table.write('<tr><td>%s</td>' % (controller))
maxthrough = 0
maxthread = 1
for threads in sorted(results['sw'][controller].keys()) :
if results['sw'][controller][threads][fix_switch] > maxthrough :
maxthrough = results['sw'][controller][threads][fix_switch]
maxthread = threads
table.write('<td>%.2f</td><td>%d</td></tr>\n' % (maxthrough, maxthread))
table.write("""
</table>
</body>
</html>
""")
table.close()
if __name__ == '__main__':
main()