blob: b722974df5de1c27557965c6a8d20a1ed2813b4f [file] [log] [blame]
andrewonlab2a6c9342014-10-16 13:40:15 -04001#TopoPerfNext
2#
3#Topology Performance test for ONOS-next
4#
5#andrew@onlab.us
6
7import time
8import sys
9import os
10import re
11
12class TopoPerfNext:
13 def __init__(self):
14 self.default = ''
15
16 def CASE1(self, main):
17 '''
18 ONOS startup sequence
19 '''
andrewonlabe9fb6722014-10-24 12:20:35 -040020 import time
21
andrewonlab2a6c9342014-10-16 13:40:15 -040022 cell_name = main.params['ENV']['cellName']
23
24 git_pull = main.params['GIT']['autoPull']
25 checkout_branch = main.params['GIT']['checkout']
26
27 ONOS1_ip = main.params['CTRL']['ip1']
andrewonlabba44bcf2014-10-16 16:54:41 -040028 ONOS2_ip = main.params['CTRL']['ip2']
29 ONOS3_ip = main.params['CTRL']['ip3']
andrewonlab2a6c9342014-10-16 13:40:15 -040030 MN1_ip = main.params['MN']['ip1']
31 BENCH_ip = main.params['BENCH']['ip']
32
33 main.case("Setting up test environment")
34
35 main.step("Creating cell file")
36 cell_file_result = main.ONOSbench.create_cell_file(
andrewonlabe6745342014-10-17 14:29:13 -040037 BENCH_ip, cell_name, MN1_ip, "onos-core",
andrewonlabba44bcf2014-10-16 16:54:41 -040038 ONOS1_ip, ONOS2_ip, ONOS3_ip)
andrewonlab2a6c9342014-10-16 13:40:15 -040039
40 main.step("Applying cell file to environment")
41 cell_apply_result = main.ONOSbench.set_cell(cell_name)
42 verify_cell_result = main.ONOSbench.verify_cell()
43
44 main.step("Git checkout and pull "+checkout_branch)
45 if git_pull == 'on':
46 checkout_result = \
47 main.ONOSbench.git_checkout(checkout_branch)
48 pull_result = main.ONOSbench.git_pull()
49 else:
50 checkout_result = main.TRUE
51 pull_result = main.TRUE
52 main.log.info("Skipped git checkout and pull")
53
54 main.step("Using mvn clean & install")
andrewonlab8d29f122014-10-22 17:15:04 -040055 #mvn_result = main.ONOSbench.clean_install()
56 mvn_result = main.TRUE
andrewonlab2a6c9342014-10-16 13:40:15 -040057
58 main.step("Creating ONOS package")
59 package_result = main.ONOSbench.onos_package()
60
61 main.step("Installing ONOS package")
andrewonlabe9fb6722014-10-24 12:20:35 -040062 install1_result = main.ONOSbench.onos_install(node=ONOS1_ip)
63 install2_result = main.ONOSbench.onos_install(node=ONOS2_ip)
64 install3_result = main.ONOSbench.onos_install(node=ONOS3_ip)
andrewonlab2a6c9342014-10-16 13:40:15 -040065
andrewonlabe9fb6722014-10-24 12:20:35 -040066 #NOTE: This step may be unnecessary
67 #main.step("Starting ONOS service")
68 #start_result = main.ONOSbench.onos_start(ONOS1_ip)
andrewonlab2a6c9342014-10-16 13:40:15 -040069
andrewonlab867212a2014-10-22 20:13:38 -040070 main.step("Set cell for ONOS cli env")
71 main.ONOS1cli.set_cell(cell_name)
72 main.ONOS2cli.set_cell(cell_name)
73 main.ONOS3cli.set_cell(cell_name)
74
andrewonlabe9fb6722014-10-24 12:20:35 -040075 time.sleep(10)
76
andrewonlab867212a2014-10-22 20:13:38 -040077 main.step("Start onos cli")
andrewonlabe9fb6722014-10-24 12:20:35 -040078 cli1 = main.ONOS1cli.start_onos_cli(ONOS1_ip)
79 cli2 = main.ONOS2cli.start_onos_cli(ONOS2_ip)
80 cli3 = main.ONOS3cli.start_onos_cli(ONOS3_ip)
81
82 if not (cli1 and cli2 and cli3):
83 main.log.info("Attempting to start cli again")
84 cli1 = main.ONOS1cli.start_onos_cli(ONOS1_ip)
85 cli2 = main.ONOS2cli.start_onos_cli(ONOS2_ip)
86 cli3 = main.ONOS3cli.start_onos_cli(ONOS3_ip)
andrewonlab867212a2014-10-22 20:13:38 -040087
88 main.step("Enable metrics feature")
89 main.ONOS1cli.feature_install("onos-app-metrics-topology")
90 main.ONOS2cli.feature_install("onos-app-metrics-topology")
91 main.ONOS3cli.feature_install("onos-app-metrics-topology")
92
andrewonlab2a6c9342014-10-16 13:40:15 -040093 utilities.assert_equals(expect=main.TRUE,
94 actual= cell_file_result and cell_apply_result and\
95 verify_cell_result and checkout_result and\
96 pull_result and mvn_result and\
andrewonlabe9fb6722014-10-24 12:20:35 -040097 install1_result and install2_result and\
98 install3_result,
andrewonlab8d29f122014-10-22 17:15:04 -040099 onpass="ONOS started successfully",
100 onfail="Failed to start ONOS")
andrewonlab2a6c9342014-10-16 13:40:15 -0400101
andrewonlabba44bcf2014-10-16 16:54:41 -0400102 def CASE2(self, main):
103 '''
104 Assign s1 to ONOS1 and measure latency
105 '''
106 import time
andrewonlabe6745342014-10-17 14:29:13 -0400107 import subprocess
108 import json
109 import requests
110 import os
andrewonlabba44bcf2014-10-16 16:54:41 -0400111
112 ONOS1_ip = main.params['CTRL']['ip1']
113 ONOS2_ip = main.params['CTRL']['ip2']
114 ONOS3_ip = main.params['CTRL']['ip3']
andrewonlabe6745342014-10-17 14:29:13 -0400115 ONOS_user = main.params['CTRL']['user']
116
andrewonlabba44bcf2014-10-16 16:54:41 -0400117 default_sw_port = main.params['CTRL']['port1']
118
119 #Number of iterations of case
120 num_iter = main.params['TEST']['numIter']
121
122 #Directory/file to store tshark results
123 tshark_of_output = "/tmp/tshark_of_topo.txt"
124 tshark_tcp_output = "/tmp/tshark_tcp_topo.txt"
125
126 #String to grep in tshark output
127 tshark_tcp_string = "TCP 74 "+default_sw_port
128 tshark_of_string = "OFP 86 Vendor"
andrewonlabe6745342014-10-17 14:29:13 -0400129
130 #Initialize assertion to TRUE
131 assertion = main.TRUE
132
andrewonlabba44bcf2014-10-16 16:54:41 -0400133 main.log.report("Latency of adding one switch")
134
135 for i in range(0, int(num_iter)):
136 main.log.info("Starting tshark capture")
137
138 #* TCP [ACK, SYN] is used as t0_a, the
139 # very first "exchange" between ONOS and
140 # the switch for end-to-end measurement
141 #* OFP [Stats Reply] is used for t0_b
142 # the very last OFP message between ONOS
143 # and the switch for ONOS measurement
144 main.ONOS1.tshark_grep(tshark_tcp_string,
145 tshark_tcp_output)
146 main.ONOS1.tshark_grep(tshark_of_string,
147 tshark_of_output)
148
149 #Wait and ensure tshark is started and
150 #capturing
151 time.sleep(10)
152
153 main.log.info("Assigning s1 to controller")
154
155 main.Mininet1.assign_sw_controller(sw="1",
156 ip1=ONOS1_ip, port1=default_sw_port)
157
158 #Wait and ensure switch is assigned
159 #before stopping tshark
andrewonlab867212a2014-10-22 20:13:38 -0400160 time.sleep(30)
andrewonlabba44bcf2014-10-16 16:54:41 -0400161
162 main.ONOS1.stop_tshark()
163
andrewonlabe6745342014-10-17 14:29:13 -0400164 #tshark output is saved in ONOS. Use subprocess
165 #to copy over files to TestON for parsing
166 main.log.info("Copying over tshark files")
167
168 #TCP CAPTURE ****
andrewonlab8d29f122014-10-22 17:15:04 -0400169 #Copy the tshark output from ONOS machine to
170 #TestON machine in tshark_tcp_output directory>file
171 os.system("scp "+ONOS_user+"@"+ONOS1_ip+":"+
172 tshark_tcp_output+" /tmp/")
173 tcp_file = open(tshark_tcp_output, 'r')
174 temp_text = tcp_file.readline()
andrewonlabe6745342014-10-17 14:29:13 -0400175 temp_text = temp_text.split(" ")
andrewonlabba44bcf2014-10-16 16:54:41 -0400176
andrewonlabe6745342014-10-17 14:29:13 -0400177 main.log.info("Object read in from TCP capture: "+
178 str(temp_text))
andrewonlab867212a2014-10-22 20:13:38 -0400179 if len(temp_text) > 1:
andrewonlabe6745342014-10-17 14:29:13 -0400180 t0_tcp = int(float(temp_text[1])*1000)
181 else:
182 main.log.error("Tshark output file for TCP"+
183 " returned unexpected results")
184 t0_tcp = 0
185 assertion = main.FALSE
andrewonlab8d29f122014-10-22 17:15:04 -0400186
187 tcp_file.close()
andrewonlabe6745342014-10-17 14:29:13 -0400188 #****************
andrewonlabba44bcf2014-10-16 16:54:41 -0400189
andrewonlabe6745342014-10-17 14:29:13 -0400190 #OF CAPTURE ****
andrewonlab8d29f122014-10-22 17:15:04 -0400191 os.system("scp "+ONOS_user+"@"+ONOS1_ip+":"+
192 tshark_of_output+" /tmp/")
193 of_file = open(tshark_of_output, 'r')
194
195 line_ofp = ""
andrewonlabe6745342014-10-17 14:29:13 -0400196 while True:
andrewonlab8d29f122014-10-22 17:15:04 -0400197 temp_text = of_file.readline()
198 if temp_text !='':
andrewonlabe6745342014-10-17 14:29:13 -0400199 line_ofp = temp_text
200 else:
201 break
202 obj = line_ofp.split(" ")
203
204 main.log.info("Object read in from OFP capture: "+
205 str(line_ofp))
206
andrewonlab867212a2014-10-22 20:13:38 -0400207 if len(line_ofp) > 1:
andrewonlabe6745342014-10-17 14:29:13 -0400208 t0_ofp = int(float(obj[1])*1000)
209 else:
210 main.log.error("Tshark output file for OFP"+
211 " returned unexpected results")
212 t0_ofp = 0
213 assertion = main.FALSE
andrewonlab8d29f122014-10-22 17:15:04 -0400214
215 of_file.close()
andrewonlabe6745342014-10-17 14:29:13 -0400216 #****************
217
218 #TODO:
219 #Get json object from all 3 ONOS instances
andrewonlab867212a2014-10-22 20:13:38 -0400220 json_str_1 = main.ONOS1cli.topology_events_metrics()
221 json_str_2 = main.ONOS2cli.topology_events_metrics()
222 json_str_3 = main.ONOS3cli.topology_events_metrics()
andrewonlab867212a2014-10-22 20:13:38 -0400223
224 json_obj_1 = json.loads(json_str_1)
225 json_obj_2 = json.loads(json_str_2)
226 json_obj_3 = json.loads(json_str_3)
227
228 main.log.info(json_obj_1)
229 main.log.info(json_obj_2)
230 main.log.info(json_obj_3)
231
andrewonlabe6745342014-10-17 14:29:13 -0400232 #TODO:
233 #Parse json object for timestamp
andrewonlabe9fb6722014-10-24 12:20:35 -0400234 topo_timestamp_1 = \
235 json_obj_1['lastTopologyEventTimestamp']['value']
236 topo_timestamp_2 = \
237 json_obj_2['lastTopologyEventTimestamp']['value']
238 topo_timestamp_3 = \
239 json_obj_3['lastTopologyEventTimestamp']['value']
240
241 main.log.info(topo_timestamp_1)
242 main.log.info(topo_timestamp_2)
243 main.log.info(topo_timestamp_3)
andrewonlabba44bcf2014-10-16 16:54:41 -0400244
andrewonlabe6745342014-10-17 14:29:13 -0400245 #ONOS processing latency
246 delta_of_1 = int(topo_timestamp_1) - int(t0_ofp)
247 delta_of_2 = int(topo_timestamp_2) - int(t0_ofp)
248 delta_of_3 = int(topo_timestamp_3) - int(t0_ofp)
249
250 #End-to-end processing latency
251 delta_tcp_1 = int(topo_timestamp_1) - int(t0_tcp)
252 delta_tcp_2 = int(topo_timestamp_2) - int(t0_tcp)
253 delta_tcp_3 = int(topo_timestamp_3) - int(t0_tcp)
andrewonlabba44bcf2014-10-16 16:54:41 -0400254
andrewonlabe6745342014-10-17 14:29:13 -0400255 #TODO:
256 #Fetch logs upon threshold excess
andrewonlabba44bcf2014-10-16 16:54:41 -0400257
andrewonlabe6745342014-10-17 14:29:13 -0400258 main.log.info("ONOS1 delta OFP: "+str(delta_of_1))
259 main.log.info("ONOS2 delta OFP: "+str(delta_of_2))
260 main.log.info("ONOS3 delta OFP: "+str(delta_of_3))
andrewonlabba44bcf2014-10-16 16:54:41 -0400261
andrewonlabe6745342014-10-17 14:29:13 -0400262 main.log.info("ONOS1 delta TCP: "+str(delta_tcp_1))
263 main.log.info("ONOS2 delta TCP: "+str(delta_tcp_2))
264 main.log.info("ONOS3 delta TCP: "+str(delta_tcp_3))
265
andrewonlab8d29f122014-10-22 17:15:04 -0400266 main.step("Remove switch from controller")
267 main.Mininet1.delete_sw_controller("s1")
andrewonlabba44bcf2014-10-16 16:54:41 -0400268
andrewonlab8d29f122014-10-22 17:15:04 -0400269 time.sleep(5)
andrewonlabba44bcf2014-10-16 16:54:41 -0400270
andrewonlab8d29f122014-10-22 17:15:04 -0400271 utilities.assert_equals(expect=main.TRUE, actual=assertion,
272 onpass="Switch latency test successful",
273 onfail="Switch latency test failed")
274
andrewonlabba44bcf2014-10-16 16:54:41 -0400275
andrewonlab8d29f122014-10-22 17:15:04 -0400276 def CASE3(self, main):
277 '''
278 Bring port up / down and measure latency.
279 Port enable / disable is simulated by ifconfig up / down
280 '''
281 import time
282 import subprocess
283 import os
284 import requests
285 import json
andrewonlab2a6c9342014-10-16 13:40:15 -0400286
andrewonlab8d29f122014-10-22 17:15:04 -0400287 ONOS1_ip = main.params['CTRL']['ip1']
288 default_sw_port = main.params['CTRL']['port1']
289 ONOS_user = main.params['CTRL']['user']
290 num_iter = main.params['TEST']['numIter']
291
292 tshark_port_status = "OFP 130 Port Status"
293
294 tshark_port_up = "/tmp/tshark_port_up.txt"
295 tshark_port_down = "/tmp/tshark_port_down.txt"
296
297 main.log.report("Port enable / disable latency")
298
299 main.step("Assign switch to controller")
300 main.Mininet1.assign_sw_controller(sw="1",ip1=ONOS1_ip,
301 port1=default_sw_port)
302
303 main.step("Verify switch is assigned correctly")
304 result_s1 = main.Mininet1.get_sw_controller(sw="s1")
305 if result_s1 == main.FALSE:
306 main.log.info("Switch s1 was not assigned correctly")
307 assertion = main.FALSE
308 else:
309 main.log.info("Switch s1 was assigned correctly")
310
311 for i in range(0, int(num_iter)):
312 main.step("Starting wireshark capture for port status down")
313 main.ONOS1.tshark_grep(tshark_port_status,
314 tshark_port_down)
315
316 time.sleep(10)
317
318 main.step("Disable port (interface s1-eth2)")
319 main.Mininet2.handle.sendline("sudo ifconfig s1-eth2 down")
320 main.Mininet2.handle.expect("\$")
321 time.sleep(20)
322
323 main.ONOS1.tshark_stop()
324 time.sleep(5)
325
326 #Copy tshark output file from ONOS to TestON instance
327 #/tmp directory
328 os.system("scp "+ONOS_user+"@"+ONOS1_ip+":"+
329 tshark_port_down+" /tmp/")
330
331 f_port_down = open(tshark_port_down, 'r')
332 f_line = f_port_down.readline()
333 obj_down = f_line.split(" ")
334 if len(f_line) > 0:
335 timestamp_begin_pt_down = int(float(obj_down[1])*1000)
336 else:
337 main.log.info("Tshark output file returned unexpected"+
338 " results")
339 timestamp_begin_pt_down = 0
340
341 main.step("Obtain t1 by REST call")
342 #TODO: Implement json object parsing here
343
344 timestamp_end_pt_down_1 = 0
345 timestamp_end_pt_down_2 = 0
346 timestamp_end_pt_down_3 = 0
347
348 delta_pt_down_1 = int(timestamp_end_pt_down_1) - \
349 int(timestamp_begin_pt_down)
350 delta_pt_down_2 = int(timestamp_end_pt_down_2) - \
351 int(timestamp_begin_pt_down)
352 delta_pt_down_3 = int(timestamp_end_pt_down_3) - \
353 int(timestamp_begin_pt_down)
354
355 #TODO: Remove these logs. For test purposes only
356 main.log.info("Delta1: "+str(delta_pt_down_1))
357 main.log.info("Delta2: "+str(delta_pt_down_2))
358 main.log.info("Delta3: "+str(delta_pt_down_3))
359
360 #Port up events
361 main.step("Enable port and obtain timestamp")
362 main.step("Starting wireshark capture for port status up")
363 main.ONOS1.tshark_grep("OFP 130 Port Status", tshark_port_up)
364 time.sleep(10)
365
366 main.Mininet2.handle.sendline("sudo ifconfig s1-eth2 up")
367 main.Mininet2.handle.expect("\$")
368 time.sleep(20)
369
370 os.system("scp "+ONOS_user+"@"+ONOS1_ip+":"+
371 tshark_port_up+" /tmp/")
372
373 f_port_up = open(tshark_port_up, 'r')
374 f_line = f_port_down.readline()
375 obj_up = f_line.split(" ")
376 if len(f_line) > 0:
377 timestamp_begin_pt_up = int(float(obj_up[1])*1000)
378 else:
379 main.log.info("Tshark output file returned unexpected"+
380 " results.")
381 timestamp_begin_pt_up = 0
382
383 main.step("Obtain t1 by REST call")
384 #TODO: Implement json object parsing here
385
386 timestamp_end_pt_up_1 = 0
387 timestamp_end_pt_up_2 = 0
388 timestamp_end_pt_up_3 = 0
389
390 delta_pt_up_1 = int(timestamp_end_pt_up_1) - \
391 int(timestamp_begin_pt_up)
392 delta_pt_up_2 = int(timestamp_end_pt_up_2) - \
393 int(timestamp_begin_pt_up)
394 delta_pt_up_3 = int(timestamp_end_pt_up_3) - \
395 int(timestamp_begin_pt_up)
396
397 #TODO: Remove these logs. For test purposes only
398 main.log.info("Delta1: "+str(delta_pt_up_1))
399 main.log.info("Delta2: "+str(delta_pt_up_2))
400 main.log.info("Delta3: "+str(delta_pt_up_3))
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415