/
control_path_profiler.py
424 lines (296 loc) · 13.9 KB
/
control_path_profiler.py
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
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
"""
Profiles the entire control path. In particular:
* ingress pkt rate vs pkt_in rate
* flow_mod rate vs successful rule installation rate
* pkt_out rate vs egress pkt rate
Each of these tests are modularized. They can be permutated arbitrarily to
simulate emergent behaviors.
To be run on the same host as tcpdump.
Written by: Danny Y. Huang
Nov 14, 2012
"""
from lib.packet_sender_receiver import PacketSender, PacketReceiver
from lib.pktgen import Pktgen
from lib.tcpdump import Tcpdump
from lib.state_proxy import StateProxyClient
import lib.config as config
import lib.util as util
import time, traceback
MAX_RUNNING_TIME = 70
TRIGGER_PORT = 32767
## HP
#FLEXI_CONTROLLER_HOST = '132.239.17.35'
#FLEXI_CONTROLLER_SSH_PORT = 2222
#FLEXI_CONTROLLER_SSH_USERNAME = 'root'
# Monaco
FLEXI_CONTROLLER_HOST = '172.22.16.67'
FLEXI_CONTROLLER_SSH_PORT = 22
FLEXI_CONTROLLER_SSH_USERNAME = 'root'
#POX_CMD = 'python pox/pox.py --no-cli log.level --CRITICAL openflow.of_01 --port=45678 forwarding.flexi_controller --of_port_1=32 --of_port_2=34;'
POX_CMD = 'python pox/pox.py --no-cli log.level --CRITICAL openflow.of_01 --port=36633 forwarding.flexi_controller --of_port_1=8 --of_port_2=20;'
def send_trigger_packet():
"""
Sends a reference packet to the controller, from which flow-mods or pkt-outs
can be constructed. Blocks until the packet is sent.
"""
util.ping_test(how_many_pings=4, dest_host=config.active_config.source_ip)
util.run_ssh('iperf -u -c ', config.active_config.dest_ip,
' -p ', TRIGGER_PORT, ' -t 1 -l 12',
hostname=config.active_config.source_ip).wait()
def start_controller():
""" Returns a Popen object. """
cmd = ['cd ~/swclone;',
'export PYTHONPATH=$PYTHONPATH:`pwd`;',
'cd ~/swclone/lib;',
'export PYTHONPATH=$PYTHONPATH:`pwd`;',
'cd ~/swclone;',
POX_CMD
]
return util.run_ssh(*cmd, verbose=True, hostname=FLEXI_CONTROLLER_HOST,
user=FLEXI_CONTROLLER_SSH_USERNAME, port=FLEXI_CONTROLLER_SSH_PORT)
class GenerateIngress(PacketSender):
def __init__(self, expected_pps, _, packet_size=1400):
self._pktgen = Pktgen(config.active_config)
self._pkt_size = packet_size
self._sent_pps = None
PacketSender.__init__(self, expected_pps)
def start(self):
gap = 1.0 / self._expected_pps
gap_ns = gap * 1000 * 1000 * 1000
max_pkt_count = int(MAX_RUNNING_TIME * self._expected_pps)
self._pktgen.low_level_start(pkt_count=max_pkt_count,
pkt_size=self._pkt_size,
gap_ns=gap_ns, flow_count=1)
PacketSender.start(self)
def stop(self):
pktgen_result = self._pktgen.stop_and_get_result()
self._sent_pps = pktgen_result.sent_pkt_count / pktgen_result.running_time
PacketSender.stop(self)
def get_sent_pps(self):
return self._sent_pps
class ReceivePktIn(PacketReceiver):
def __init__(self, state_proxy_client):
PacketReceiver.__init__(self)
self._proxy_client = state_proxy_client
self._proxy_client.set('pkt_in_stat', (0, None, None))
self._pkt_in_pps = None
def start(self):
PacketReceiver.start(self)
def stop(self):
(self._recvd_count, start, end) = self._proxy_client.get('pkt_in_stat')
self._pkt_in_pps = self._recvd_count / (end - start)
PacketReceiver.stop(self)
def get_received_pps(self):
return self._pkt_in_pps
class GenerateFlowMod(PacketSender):
def __init__(self, expected_pps, state_proxy_client, packet_size=None):
PacketSender.__init__(self, expected_pps)
self._proxy_client = state_proxy_client
self._proxy_client.set('flow_mod_stat', (0, None, None))
self._flow_mod_pps = None
def start(self):
assert self._proxy_client.run('trigger_event_is_ready')
self._proxy_client.run('start_loop_flow_mod', 1.0/self._expected_pps, MAX_RUNNING_TIME)
PacketSender.start(self)
def stop(self):
self._proxy_client.run('stop_loop_flow_mod')
(self._sent_count, start, end) = self._proxy_client.get('flow_mod_stat')
self._flow_mod_pps = self._sent_count / (end - start)
PacketSender.stop(self)
def get_sent_pps(self):
return self._flow_mod_pps
class CheckRuleInstallationRate(PacketReceiver):
def __init__(self, state_proxy_client, flow_stat_interval=7, steady_state_start=30, steady_state_end=60):
PacketReceiver.__init__(self)
self._flow_stat_interval = flow_stat_interval
self._steady_state_start = steady_state_start
self._steady_state_end = steady_state_end
self._proxy_client = state_proxy_client
self._proxy_client.set('flow_stat_interval', self._flow_stat_interval)
self._proxy_client.set('flow_count_dict', {})
def start(self):
PacketReceiver.start(self)
def get_received_pps(self):
""" Returns the average rate of successful flow_mod at steady state """
flow_count_dict = self._proxy_client.get('flow_count_dict')
steady_flow_count_list = []
steady_time_start = min(flow_count_dict.keys()) + self._steady_state_start
steady_time_end = min(flow_count_dict.keys()) + self._steady_state_end
for stat_time in flow_count_dict:
if steady_time_start <= stat_time <= steady_time_end:
steady_flow_count_list.append(flow_count_dict[stat_time])
if steady_flow_count_list:
return sum(steady_flow_count_list) / 10.0 / len(steady_flow_count_list)
else:
return 0.0
class GeneratePktOut(PacketSender):
def __init__(self, expected_pps, state_proxy_client, packet_size=1500):
PacketSender.__init__(self, expected_pps)
self._proxy_client = state_proxy_client
self._pkt_size = packet_size
self._pkt_out_pps = None
self._proxy_client.set('pkt_out_length', self._pkt_size)
self._proxy_client.set('pkt_out_stat', (0, None, None))
def start(self):
assert self._proxy_client.run('trigger_event_is_ready')
self._proxy_client.run('start_loop_pkt_out', 1.0/self._expected_pps, MAX_RUNNING_TIME)
PacketSender.start(self)
def stop(self):
self._proxy_client.run('stop_loop_pkt_out')
(self._sent_count, start, end) = self._proxy_client.get('pkt_out_stat')
self._pkt_out_pps = self._sent_count / (end - start)
PacketSender.stop(self)
def get_sent_pps(self):
return self._pkt_out_pps
class ReceiveEgress(PacketReceiver):
def __init__(self, _):
PacketReceiver.__init__(self)
self._tcpdump = Tcpdump(config.active_config,
filter='udp and dst port ' + str(TRIGGER_PORT))
def start(self):
self._tcpdump.start()
PacketReceiver.start(self)
def stop(self):
PacketReceiver.stop(self)
result = self._tcpdump.stop_and_get_result()
self._recvd_count = result.recvd_pkt_count
def main():
for pkt_size in [1500]:
run(pkt_size)
def _param_hash(ingress, flow_mod, pkt_out):
return ingress * 1000 * 1000 + flow_mod * 1000 + pkt_out
def run(packet_size=1500):
# Writer initial header to file.
#result_file = './data/hp_sensitivity_%d_byte.csv' % packet_size # HP
#result_file = './data/evs_verify_sensitivity_%d_byte.csv' % packet_size # EVS
result_file = './data/monaco_sensitivity_%d_byte.csv' % packet_size # MONACO
with open(result_file, 'w') as f:
print >> f, 'ingress_pps,flow_mod_pps,pkt_out_pps,pkt_in_pps,rule_pps,egress_pps,expected_ingress,expected_flow_mod,expected_pkt_out'
#input_list = [10, 100, 400, 700, 1000] # HP
#input_list = [10, 100, 1000] # OVS
#input_list = [10, 100, 400, 700, 1000]
input_list = [10,30,100,320,330]
for ingress_pps in input_list:
for flow_mod_pps in input_list:
for pkt_out_pps in input_list:
# Ignore certain params. TODO: Debug.
# if packet_size == 1500:
# if _param_hash(ingress_pps, flow_mod_pps, pkt_out_pps) <= \
# _param_hash(400, 1000, 10):
# continue
for attempt in range(3):
try:
start_controller()
while True:
try:
proxy_client = StateProxyClient(FLEXI_CONTROLLER_HOST)
proxy_client.hello()
break
except:
print 'Waiting for controller...'
time.sleep(2)
proxy_client.reset()
print proxy_client.getall()
send_trigger_packet()
# Confirm trigger.
while not proxy_client.run('trigger_event_is_ready'):
print proxy_client.getall()
print 'Waiting for trigger...'
time.sleep(2)
# Set up the pkt generators
ingress = GenerateIngress(ingress_pps, proxy_client, packet_size=packet_size)
flow_mod = GenerateFlowMod(flow_mod_pps, proxy_client)
pkt_out = GeneratePktOut(pkt_out_pps, proxy_client, packet_size=packet_size)
# Set up pkt receivers.
pkt_in = ReceivePktIn(proxy_client)
check_rule = CheckRuleInstallationRate(proxy_client)
egress = ReceiveEgress(proxy_client)
print proxy_client.getall()
# Start receiving and sending.
for obj in [pkt_in, check_rule, egress, ingress, flow_mod, pkt_out]:
obj.start()
# Wait.
prompt = '(ingress_pps, flow_mod_pps, pkt_out_pps) = '
prompt += str((ingress_pps, flow_mod_pps, pkt_out_pps))
util.verbose_sleep(MAX_RUNNING_TIME, prompt)
# Stop sending and receiving.
for obj in [ingress, flow_mod, pkt_out, pkt_in, check_rule, egress]:
obj.stop()
# Gather data.
data_list = [ingress.get_sent_pps(),
flow_mod.get_sent_pps(),
pkt_out.get_sent_pps(),
pkt_in.get_received_pps(),
check_rule.get_received_pps(),
egress.get_received_pps(),
ingress_pps,
flow_mod_pps,
pkt_out_pps]
# Write csv data.
data = ','.join(['%.4f' % pps for pps in data_list])
with open(result_file, 'a') as f:
print >> f, data
print '*' * 80
print data
print '*' * 80
proxy_client.exit()
util.verbose_sleep(5, 'Waiting for the next experiment...')
break
except:
proxy_client.exit()
if attempt == 2:
raise
else:
with open('./data/CRASH.log', 'a') as crash_f:
print >> crash_f, traceback.format_exc()
def test():
""" Sanity check. """
proxy_client = StateProxyClient(FLEXI_CONTROLLER_HOST)
proxy_client.reset()
send_trigger_packet()
# print '*' * 80
# print 'ingress -> pkt-in'
# print '*' * 80
#
# ingress = GenerateIngress(300, proxy_client)
# pkt_in = ReceivePktIn(proxy_client)
#
# pkt_in.start()
# ingress.start()
# util.verbose_sleep(20, 'Ingress -> pkt_in...')
# ingress.stop()
# pkt_in.stop()
#
# print 'sent pps:', ingress.get_sent_pps()
# print 'recvd pps:', pkt_in.get_received_pps()
#
# print '*' * 80
# print 'flow-mod -> rules'
# print '*' * 80
#
# flow_mod = GenerateFlowMod(200, proxy_client)
# check_rule = CheckRuleInstallationRate(proxy_client, flow_stat_interval=10, steady_state_start=30, steady_state_end=60)
#
# check_rule.start()
# flow_mod.start()
# util.verbose_sleep(60, 'flow-mod -> rules')
# flow_mod.stop()
# check_rule.stop()
#
# print 'sent pps:', flow_mod.get_sent_pps()
# print 'recvd pps:', check_rule.get_received_pps()
print '*' * 80
print 'pkt-out -> egress'
print '*' * 80
pkt_out = GeneratePktOut(200, proxy_client, packet_size=1500)
egress = ReceiveEgress(proxy_client)
egress.start()
pkt_out.start()
util.verbose_sleep(5, 'pkt-out -> egress')
pkt_out.stop()
egress.stop()
print 'sent pps:', pkt_out.get_sent_pps()
print 'recvd pps:', egress.get_received_pps()
#controller_p.kill()
if __name__ == '__main__':
main()