blob: eb49669e13ed66a61702c64c965c8313f688718e [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 '''
20 cell_name = main.params['ENV']['cellName']
21
22 git_pull = main.params['GIT']['autoPull']
23 checkout_branch = main.params['GIT']['checkout']
24
25 ONOS1_ip = main.params['CTRL']['ip1']
andrewonlabba44bcf2014-10-16 16:54:41 -040026 ONOS2_ip = main.params['CTRL']['ip2']
27 ONOS3_ip = main.params['CTRL']['ip3']
andrewonlab2a6c9342014-10-16 13:40:15 -040028 MN1_ip = main.params['MN']['ip1']
29 BENCH_ip = main.params['BENCH']['ip']
30
31 main.case("Setting up test environment")
32
33 main.step("Creating cell file")
34 cell_file_result = main.ONOSbench.create_cell_file(
andrewonlabe6745342014-10-17 14:29:13 -040035 BENCH_ip, cell_name, MN1_ip, "onos-core",
andrewonlabba44bcf2014-10-16 16:54:41 -040036 ONOS1_ip, ONOS2_ip, ONOS3_ip)
andrewonlab2a6c9342014-10-16 13:40:15 -040037
38 main.step("Applying cell file to environment")
39 cell_apply_result = main.ONOSbench.set_cell(cell_name)
40 verify_cell_result = main.ONOSbench.verify_cell()
41
42 main.step("Git checkout and pull "+checkout_branch)
43 if git_pull == 'on':
44 checkout_result = \
45 main.ONOSbench.git_checkout(checkout_branch)
46 pull_result = main.ONOSbench.git_pull()
47 else:
48 checkout_result = main.TRUE
49 pull_result = main.TRUE
50 main.log.info("Skipped git checkout and pull")
51
52 main.step("Using mvn clean & install")
andrewonlab8d29f122014-10-22 17:15:04 -040053 #mvn_result = main.ONOSbench.clean_install()
54 mvn_result = main.TRUE
andrewonlab2a6c9342014-10-16 13:40:15 -040055
56 main.step("Creating ONOS package")
57 package_result = main.ONOSbench.onos_package()
58
59 main.step("Installing ONOS package")
60 install_result = main.ONOSbench.onos_install()
61
62 main.step("Starting ONOS service")
63 start_result = main.ONOSbench.onos_start(ONOS1_ip)
64
andrewonlab867212a2014-10-22 20:13:38 -040065 main.step("Set cell for ONOS cli env")
66 main.ONOS1cli.set_cell(cell_name)
67 main.ONOS2cli.set_cell(cell_name)
68 main.ONOS3cli.set_cell(cell_name)
69
70 main.step("Start onos cli")
71 main.ONOS1cli.start_onos_cli(ONOS1_ip)
72 main.ONOS2cli.start_onos_cli(ONOS2_ip)
73 main.ONOS3cli.start_onos_cli(ONOS3_ip)
74
75 main.step("Enable metrics feature")
76 main.ONOS1cli.feature_install("onos-app-metrics-topology")
77 main.ONOS2cli.feature_install("onos-app-metrics-topology")
78 main.ONOS3cli.feature_install("onos-app-metrics-topology")
79
andrewonlab2a6c9342014-10-16 13:40:15 -040080 utilities.assert_equals(expect=main.TRUE,
81 actual= cell_file_result and cell_apply_result and\
82 verify_cell_result and checkout_result and\
83 pull_result and mvn_result and\
84 install_result and start_result,
andrewonlab8d29f122014-10-22 17:15:04 -040085 onpass="ONOS started successfully",
86 onfail="Failed to start ONOS")
andrewonlab2a6c9342014-10-16 13:40:15 -040087
andrewonlabba44bcf2014-10-16 16:54:41 -040088 def CASE2(self, main):
89 '''
90 Assign s1 to ONOS1 and measure latency
91 '''
92 import time
andrewonlabe6745342014-10-17 14:29:13 -040093 import subprocess
94 import json
95 import requests
96 import os
andrewonlabba44bcf2014-10-16 16:54:41 -040097
98 ONOS1_ip = main.params['CTRL']['ip1']
99 ONOS2_ip = main.params['CTRL']['ip2']
100 ONOS3_ip = main.params['CTRL']['ip3']
andrewonlabe6745342014-10-17 14:29:13 -0400101 ONOS_user = main.params['CTRL']['user']
102
andrewonlabba44bcf2014-10-16 16:54:41 -0400103 default_sw_port = main.params['CTRL']['port1']
104
105 #Number of iterations of case
106 num_iter = main.params['TEST']['numIter']
107
108 #Directory/file to store tshark results
109 tshark_of_output = "/tmp/tshark_of_topo.txt"
110 tshark_tcp_output = "/tmp/tshark_tcp_topo.txt"
111
112 #String to grep in tshark output
113 tshark_tcp_string = "TCP 74 "+default_sw_port
114 tshark_of_string = "OFP 86 Vendor"
andrewonlabe6745342014-10-17 14:29:13 -0400115
116 #Initialize assertion to TRUE
117 assertion = main.TRUE
118
andrewonlabba44bcf2014-10-16 16:54:41 -0400119 main.log.report("Latency of adding one switch")
120
121 for i in range(0, int(num_iter)):
122 main.log.info("Starting tshark capture")
123
124 #* TCP [ACK, SYN] is used as t0_a, the
125 # very first "exchange" between ONOS and
126 # the switch for end-to-end measurement
127 #* OFP [Stats Reply] is used for t0_b
128 # the very last OFP message between ONOS
129 # and the switch for ONOS measurement
130 main.ONOS1.tshark_grep(tshark_tcp_string,
131 tshark_tcp_output)
132 main.ONOS1.tshark_grep(tshark_of_string,
133 tshark_of_output)
134
135 #Wait and ensure tshark is started and
136 #capturing
137 time.sleep(10)
138
139 main.log.info("Assigning s1 to controller")
140
141 main.Mininet1.assign_sw_controller(sw="1",
142 ip1=ONOS1_ip, port1=default_sw_port)
143
144 #Wait and ensure switch is assigned
145 #before stopping tshark
andrewonlab867212a2014-10-22 20:13:38 -0400146 time.sleep(30)
andrewonlabba44bcf2014-10-16 16:54:41 -0400147
148 main.ONOS1.stop_tshark()
149
andrewonlabe6745342014-10-17 14:29:13 -0400150 #tshark output is saved in ONOS. Use subprocess
151 #to copy over files to TestON for parsing
152 main.log.info("Copying over tshark files")
153
154 #TCP CAPTURE ****
andrewonlab8d29f122014-10-22 17:15:04 -0400155 #Copy the tshark output from ONOS machine to
156 #TestON machine in tshark_tcp_output directory>file
157 os.system("scp "+ONOS_user+"@"+ONOS1_ip+":"+
158 tshark_tcp_output+" /tmp/")
159 tcp_file = open(tshark_tcp_output, 'r')
160 temp_text = tcp_file.readline()
andrewonlabe6745342014-10-17 14:29:13 -0400161 temp_text = temp_text.split(" ")
andrewonlabba44bcf2014-10-16 16:54:41 -0400162
andrewonlabe6745342014-10-17 14:29:13 -0400163 main.log.info("Object read in from TCP capture: "+
164 str(temp_text))
andrewonlab867212a2014-10-22 20:13:38 -0400165 if len(temp_text) > 1:
andrewonlabe6745342014-10-17 14:29:13 -0400166 t0_tcp = int(float(temp_text[1])*1000)
167 else:
168 main.log.error("Tshark output file for TCP"+
169 " returned unexpected results")
170 t0_tcp = 0
171 assertion = main.FALSE
andrewonlab8d29f122014-10-22 17:15:04 -0400172
173 tcp_file.close()
andrewonlabe6745342014-10-17 14:29:13 -0400174 #****************
andrewonlabba44bcf2014-10-16 16:54:41 -0400175
andrewonlabe6745342014-10-17 14:29:13 -0400176 #OF CAPTURE ****
andrewonlab8d29f122014-10-22 17:15:04 -0400177 os.system("scp "+ONOS_user+"@"+ONOS1_ip+":"+
178 tshark_of_output+" /tmp/")
179 of_file = open(tshark_of_output, 'r')
180
181 line_ofp = ""
andrewonlabe6745342014-10-17 14:29:13 -0400182 while True:
andrewonlab8d29f122014-10-22 17:15:04 -0400183 temp_text = of_file.readline()
184 if temp_text !='':
andrewonlabe6745342014-10-17 14:29:13 -0400185 line_ofp = temp_text
186 else:
187 break
188 obj = line_ofp.split(" ")
189
190 main.log.info("Object read in from OFP capture: "+
191 str(line_ofp))
192
andrewonlab867212a2014-10-22 20:13:38 -0400193 if len(line_ofp) > 1:
andrewonlabe6745342014-10-17 14:29:13 -0400194 t0_ofp = int(float(obj[1])*1000)
195 else:
196 main.log.error("Tshark output file for OFP"+
197 " returned unexpected results")
198 t0_ofp = 0
199 assertion = main.FALSE
andrewonlab8d29f122014-10-22 17:15:04 -0400200
201 of_file.close()
andrewonlabe6745342014-10-17 14:29:13 -0400202 #****************
203
204 #TODO:
205 #Get json object from all 3 ONOS instances
andrewonlab867212a2014-10-22 20:13:38 -0400206 json_str_1 = main.ONOS1cli.topology_events_metrics()
207 json_str_2 = main.ONOS2cli.topology_events_metrics()
208 json_str_3 = main.ONOS3cli.topology_events_metrics()
209
210 #TESTING:
211 main.log.info(json_str_1)
212 main.log.info(json_str_2)
213 main.log.info(json_str_3)
214
215 json_obj_1 = json.loads(json_str_1)
216 json_obj_2 = json.loads(json_str_2)
217 json_obj_3 = json.loads(json_str_3)
218
219 main.log.info(json_obj_1)
220 main.log.info(json_obj_2)
221 main.log.info(json_obj_3)
222
andrewonlabe6745342014-10-17 14:29:13 -0400223 #TODO:
224 #Parse json object for timestamp
225 topo_timestamp_1 = 0
226 topo_timestamp_2 = 0
227 topo_timestamp_3 = 0
andrewonlabba44bcf2014-10-16 16:54:41 -0400228
andrewonlabe6745342014-10-17 14:29:13 -0400229 #ONOS processing latency
230 delta_of_1 = int(topo_timestamp_1) - int(t0_ofp)
231 delta_of_2 = int(topo_timestamp_2) - int(t0_ofp)
232 delta_of_3 = int(topo_timestamp_3) - int(t0_ofp)
233
234 #End-to-end processing latency
235 delta_tcp_1 = int(topo_timestamp_1) - int(t0_tcp)
236 delta_tcp_2 = int(topo_timestamp_2) - int(t0_tcp)
237 delta_tcp_3 = int(topo_timestamp_3) - int(t0_tcp)
andrewonlabba44bcf2014-10-16 16:54:41 -0400238
andrewonlabe6745342014-10-17 14:29:13 -0400239 #TODO:
240 #Fetch logs upon threshold excess
andrewonlabba44bcf2014-10-16 16:54:41 -0400241
andrewonlabe6745342014-10-17 14:29:13 -0400242 main.log.info("ONOS1 delta OFP: "+str(delta_of_1))
243 main.log.info("ONOS2 delta OFP: "+str(delta_of_2))
244 main.log.info("ONOS3 delta OFP: "+str(delta_of_3))
andrewonlabba44bcf2014-10-16 16:54:41 -0400245
andrewonlabe6745342014-10-17 14:29:13 -0400246 main.log.info("ONOS1 delta TCP: "+str(delta_tcp_1))
247 main.log.info("ONOS2 delta TCP: "+str(delta_tcp_2))
248 main.log.info("ONOS3 delta TCP: "+str(delta_tcp_3))
249
andrewonlab8d29f122014-10-22 17:15:04 -0400250 main.step("Remove switch from controller")
251 main.Mininet1.delete_sw_controller("s1")
andrewonlabba44bcf2014-10-16 16:54:41 -0400252
andrewonlab8d29f122014-10-22 17:15:04 -0400253 time.sleep(5)
andrewonlabba44bcf2014-10-16 16:54:41 -0400254
andrewonlab8d29f122014-10-22 17:15:04 -0400255 utilities.assert_equals(expect=main.TRUE, actual=assertion,
256 onpass="Switch latency test successful",
257 onfail="Switch latency test failed")
258
andrewonlabba44bcf2014-10-16 16:54:41 -0400259
andrewonlab8d29f122014-10-22 17:15:04 -0400260 def CASE3(self, main):
261 '''
262 Bring port up / down and measure latency.
263 Port enable / disable is simulated by ifconfig up / down
264 '''
265 import time
266 import subprocess
267 import os
268 import requests
269 import json
andrewonlab2a6c9342014-10-16 13:40:15 -0400270
andrewonlab8d29f122014-10-22 17:15:04 -0400271 ONOS1_ip = main.params['CTRL']['ip1']
272 default_sw_port = main.params['CTRL']['port1']
273 ONOS_user = main.params['CTRL']['user']
274 num_iter = main.params['TEST']['numIter']
275
276 tshark_port_status = "OFP 130 Port Status"
277
278 tshark_port_up = "/tmp/tshark_port_up.txt"
279 tshark_port_down = "/tmp/tshark_port_down.txt"
280
281 main.log.report("Port enable / disable latency")
282
283 main.step("Assign switch to controller")
284 main.Mininet1.assign_sw_controller(sw="1",ip1=ONOS1_ip,
285 port1=default_sw_port)
286
287 main.step("Verify switch is assigned correctly")
288 result_s1 = main.Mininet1.get_sw_controller(sw="s1")
289 if result_s1 == main.FALSE:
290 main.log.info("Switch s1 was not assigned correctly")
291 assertion = main.FALSE
292 else:
293 main.log.info("Switch s1 was assigned correctly")
294
295 for i in range(0, int(num_iter)):
296 main.step("Starting wireshark capture for port status down")
297 main.ONOS1.tshark_grep(tshark_port_status,
298 tshark_port_down)
299
300 time.sleep(10)
301
302 main.step("Disable port (interface s1-eth2)")
303 main.Mininet2.handle.sendline("sudo ifconfig s1-eth2 down")
304 main.Mininet2.handle.expect("\$")
305 time.sleep(20)
306
307 main.ONOS1.tshark_stop()
308 time.sleep(5)
309
310 #Copy tshark output file from ONOS to TestON instance
311 #/tmp directory
312 os.system("scp "+ONOS_user+"@"+ONOS1_ip+":"+
313 tshark_port_down+" /tmp/")
314
315 f_port_down = open(tshark_port_down, 'r')
316 f_line = f_port_down.readline()
317 obj_down = f_line.split(" ")
318 if len(f_line) > 0:
319 timestamp_begin_pt_down = int(float(obj_down[1])*1000)
320 else:
321 main.log.info("Tshark output file returned unexpected"+
322 " results")
323 timestamp_begin_pt_down = 0
324
325 main.step("Obtain t1 by REST call")
326 #TODO: Implement json object parsing here
327
328 timestamp_end_pt_down_1 = 0
329 timestamp_end_pt_down_2 = 0
330 timestamp_end_pt_down_3 = 0
331
332 delta_pt_down_1 = int(timestamp_end_pt_down_1) - \
333 int(timestamp_begin_pt_down)
334 delta_pt_down_2 = int(timestamp_end_pt_down_2) - \
335 int(timestamp_begin_pt_down)
336 delta_pt_down_3 = int(timestamp_end_pt_down_3) - \
337 int(timestamp_begin_pt_down)
338
339 #TODO: Remove these logs. For test purposes only
340 main.log.info("Delta1: "+str(delta_pt_down_1))
341 main.log.info("Delta2: "+str(delta_pt_down_2))
342 main.log.info("Delta3: "+str(delta_pt_down_3))
343
344 #Port up events
345 main.step("Enable port and obtain timestamp")
346 main.step("Starting wireshark capture for port status up")
347 main.ONOS1.tshark_grep("OFP 130 Port Status", tshark_port_up)
348 time.sleep(10)
349
350 main.Mininet2.handle.sendline("sudo ifconfig s1-eth2 up")
351 main.Mininet2.handle.expect("\$")
352 time.sleep(20)
353
354 os.system("scp "+ONOS_user+"@"+ONOS1_ip+":"+
355 tshark_port_up+" /tmp/")
356
357 f_port_up = open(tshark_port_up, 'r')
358 f_line = f_port_down.readline()
359 obj_up = f_line.split(" ")
360 if len(f_line) > 0:
361 timestamp_begin_pt_up = int(float(obj_up[1])*1000)
362 else:
363 main.log.info("Tshark output file returned unexpected"+
364 " results.")
365 timestamp_begin_pt_up = 0
366
367 main.step("Obtain t1 by REST call")
368 #TODO: Implement json object parsing here
369
370 timestamp_end_pt_up_1 = 0
371 timestamp_end_pt_up_2 = 0
372 timestamp_end_pt_up_3 = 0
373
374 delta_pt_up_1 = int(timestamp_end_pt_up_1) - \
375 int(timestamp_begin_pt_up)
376 delta_pt_up_2 = int(timestamp_end_pt_up_2) - \
377 int(timestamp_begin_pt_up)
378 delta_pt_up_3 = int(timestamp_end_pt_up_3) - \
379 int(timestamp_begin_pt_up)
380
381 #TODO: Remove these logs. For test purposes only
382 main.log.info("Delta1: "+str(delta_pt_up_1))
383 main.log.info("Delta2: "+str(delta_pt_up_2))
384 main.log.info("Delta3: "+str(delta_pt_up_3))
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399