blob: 8e36c95b4d41db9d886e52977f63cc28e929cfa7 [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
65 utilities.assert_equals(expect=main.TRUE,
66 actual= cell_file_result and cell_apply_result and\
67 verify_cell_result and checkout_result and\
68 pull_result and mvn_result and\
69 install_result and start_result,
andrewonlab8d29f122014-10-22 17:15:04 -040070 onpass="ONOS started successfully",
71 onfail="Failed to start ONOS")
andrewonlab2a6c9342014-10-16 13:40:15 -040072
andrewonlabba44bcf2014-10-16 16:54:41 -040073 def CASE2(self, main):
74 '''
75 Assign s1 to ONOS1 and measure latency
76 '''
77 import time
andrewonlabe6745342014-10-17 14:29:13 -040078 import subprocess
79 import json
80 import requests
81 import os
andrewonlabba44bcf2014-10-16 16:54:41 -040082
83 ONOS1_ip = main.params['CTRL']['ip1']
84 ONOS2_ip = main.params['CTRL']['ip2']
85 ONOS3_ip = main.params['CTRL']['ip3']
andrewonlabe6745342014-10-17 14:29:13 -040086 ONOS_user = main.params['CTRL']['user']
87
andrewonlabba44bcf2014-10-16 16:54:41 -040088 default_sw_port = main.params['CTRL']['port1']
89
90 #Number of iterations of case
91 num_iter = main.params['TEST']['numIter']
92
93 #Directory/file to store tshark results
94 tshark_of_output = "/tmp/tshark_of_topo.txt"
95 tshark_tcp_output = "/tmp/tshark_tcp_topo.txt"
96
97 #String to grep in tshark output
98 tshark_tcp_string = "TCP 74 "+default_sw_port
99 tshark_of_string = "OFP 86 Vendor"
andrewonlabe6745342014-10-17 14:29:13 -0400100
101 #Initialize assertion to TRUE
102 assertion = main.TRUE
103
andrewonlabba44bcf2014-10-16 16:54:41 -0400104 main.log.report("Latency of adding one switch")
105
106 for i in range(0, int(num_iter)):
107 main.log.info("Starting tshark capture")
108
109 #* TCP [ACK, SYN] is used as t0_a, the
110 # very first "exchange" between ONOS and
111 # the switch for end-to-end measurement
112 #* OFP [Stats Reply] is used for t0_b
113 # the very last OFP message between ONOS
114 # and the switch for ONOS measurement
115 main.ONOS1.tshark_grep(tshark_tcp_string,
116 tshark_tcp_output)
117 main.ONOS1.tshark_grep(tshark_of_string,
118 tshark_of_output)
119
120 #Wait and ensure tshark is started and
121 #capturing
122 time.sleep(10)
123
124 main.log.info("Assigning s1 to controller")
125
126 main.Mininet1.assign_sw_controller(sw="1",
127 ip1=ONOS1_ip, port1=default_sw_port)
128
129 #Wait and ensure switch is assigned
130 #before stopping tshark
andrewonlab8d29f122014-10-22 17:15:04 -0400131 time.sleep(20)
andrewonlabba44bcf2014-10-16 16:54:41 -0400132
133 main.ONOS1.stop_tshark()
134
andrewonlabe6745342014-10-17 14:29:13 -0400135 #tshark output is saved in ONOS. Use subprocess
136 #to copy over files to TestON for parsing
137 main.log.info("Copying over tshark files")
138
139 #TCP CAPTURE ****
andrewonlab8d29f122014-10-22 17:15:04 -0400140 #Copy the tshark output from ONOS machine to
141 #TestON machine in tshark_tcp_output directory>file
142 os.system("scp "+ONOS_user+"@"+ONOS1_ip+":"+
143 tshark_tcp_output+" /tmp/")
144 tcp_file = open(tshark_tcp_output, 'r')
145 temp_text = tcp_file.readline()
andrewonlabe6745342014-10-17 14:29:13 -0400146 temp_text = temp_text.split(" ")
andrewonlabba44bcf2014-10-16 16:54:41 -0400147
andrewonlabe6745342014-10-17 14:29:13 -0400148 main.log.info("Object read in from TCP capture: "+
149 str(temp_text))
150 if len(temp_text) > 0:
151 t0_tcp = int(float(temp_text[1])*1000)
152 else:
153 main.log.error("Tshark output file for TCP"+
154 " returned unexpected results")
155 t0_tcp = 0
156 assertion = main.FALSE
andrewonlab8d29f122014-10-22 17:15:04 -0400157
158 tcp_file.close()
andrewonlabe6745342014-10-17 14:29:13 -0400159 #****************
andrewonlabba44bcf2014-10-16 16:54:41 -0400160
andrewonlabe6745342014-10-17 14:29:13 -0400161 #OF CAPTURE ****
andrewonlab8d29f122014-10-22 17:15:04 -0400162 os.system("scp "+ONOS_user+"@"+ONOS1_ip+":"+
163 tshark_of_output+" /tmp/")
164 of_file = open(tshark_of_output, 'r')
165
166 line_ofp = ""
andrewonlabe6745342014-10-17 14:29:13 -0400167 while True:
andrewonlab8d29f122014-10-22 17:15:04 -0400168 temp_text = of_file.readline()
169 if temp_text !='':
andrewonlabe6745342014-10-17 14:29:13 -0400170 line_ofp = temp_text
171 else:
172 break
173 obj = line_ofp.split(" ")
174
175 main.log.info("Object read in from OFP capture: "+
176 str(line_ofp))
177
178 if len(line_ofp) > 0:
179 t0_ofp = int(float(obj[1])*1000)
180 else:
181 main.log.error("Tshark output file for OFP"+
182 " returned unexpected results")
183 t0_ofp = 0
184 assertion = main.FALSE
andrewonlab8d29f122014-10-22 17:15:04 -0400185
186 of_file.close()
andrewonlabe6745342014-10-17 14:29:13 -0400187 #****************
188
189 #TODO:
190 #Get json object from all 3 ONOS instances
191
192 #TODO:
193 #Parse json object for timestamp
194 topo_timestamp_1 = 0
195 topo_timestamp_2 = 0
196 topo_timestamp_3 = 0
andrewonlabba44bcf2014-10-16 16:54:41 -0400197
andrewonlabe6745342014-10-17 14:29:13 -0400198 #ONOS processing latency
199 delta_of_1 = int(topo_timestamp_1) - int(t0_ofp)
200 delta_of_2 = int(topo_timestamp_2) - int(t0_ofp)
201 delta_of_3 = int(topo_timestamp_3) - int(t0_ofp)
202
203 #End-to-end processing latency
204 delta_tcp_1 = int(topo_timestamp_1) - int(t0_tcp)
205 delta_tcp_2 = int(topo_timestamp_2) - int(t0_tcp)
206 delta_tcp_3 = int(topo_timestamp_3) - int(t0_tcp)
andrewonlabba44bcf2014-10-16 16:54:41 -0400207
andrewonlabe6745342014-10-17 14:29:13 -0400208 #TODO:
209 #Fetch logs upon threshold excess
andrewonlabba44bcf2014-10-16 16:54:41 -0400210
andrewonlabe6745342014-10-17 14:29:13 -0400211 main.log.info("ONOS1 delta OFP: "+str(delta_of_1))
212 main.log.info("ONOS2 delta OFP: "+str(delta_of_2))
213 main.log.info("ONOS3 delta OFP: "+str(delta_of_3))
andrewonlabba44bcf2014-10-16 16:54:41 -0400214
andrewonlabe6745342014-10-17 14:29:13 -0400215 main.log.info("ONOS1 delta TCP: "+str(delta_tcp_1))
216 main.log.info("ONOS2 delta TCP: "+str(delta_tcp_2))
217 main.log.info("ONOS3 delta TCP: "+str(delta_tcp_3))
218
andrewonlab8d29f122014-10-22 17:15:04 -0400219 main.step("Remove switch from controller")
220 main.Mininet1.delete_sw_controller("s1")
andrewonlabba44bcf2014-10-16 16:54:41 -0400221
andrewonlab8d29f122014-10-22 17:15:04 -0400222 time.sleep(5)
andrewonlabba44bcf2014-10-16 16:54:41 -0400223
andrewonlab8d29f122014-10-22 17:15:04 -0400224 utilities.assert_equals(expect=main.TRUE, actual=assertion,
225 onpass="Switch latency test successful",
226 onfail="Switch latency test failed")
227
andrewonlabba44bcf2014-10-16 16:54:41 -0400228
andrewonlab8d29f122014-10-22 17:15:04 -0400229 def CASE3(self, main):
230 '''
231 Bring port up / down and measure latency.
232 Port enable / disable is simulated by ifconfig up / down
233 '''
234 import time
235 import subprocess
236 import os
237 import requests
238 import json
andrewonlab2a6c9342014-10-16 13:40:15 -0400239
andrewonlab8d29f122014-10-22 17:15:04 -0400240 ONOS1_ip = main.params['CTRL']['ip1']
241 default_sw_port = main.params['CTRL']['port1']
242 ONOS_user = main.params['CTRL']['user']
243 num_iter = main.params['TEST']['numIter']
244
245 tshark_port_status = "OFP 130 Port Status"
246
247 tshark_port_up = "/tmp/tshark_port_up.txt"
248 tshark_port_down = "/tmp/tshark_port_down.txt"
249
250 main.log.report("Port enable / disable latency")
251
252 main.step("Assign switch to controller")
253 main.Mininet1.assign_sw_controller(sw="1",ip1=ONOS1_ip,
254 port1=default_sw_port)
255
256 main.step("Verify switch is assigned correctly")
257 result_s1 = main.Mininet1.get_sw_controller(sw="s1")
258 if result_s1 == main.FALSE:
259 main.log.info("Switch s1 was not assigned correctly")
260 assertion = main.FALSE
261 else:
262 main.log.info("Switch s1 was assigned correctly")
263
264 for i in range(0, int(num_iter)):
265 main.step("Starting wireshark capture for port status down")
266 main.ONOS1.tshark_grep(tshark_port_status,
267 tshark_port_down)
268
269 time.sleep(10)
270
271 main.step("Disable port (interface s1-eth2)")
272 main.Mininet2.handle.sendline("sudo ifconfig s1-eth2 down")
273 main.Mininet2.handle.expect("\$")
274 time.sleep(20)
275
276 main.ONOS1.tshark_stop()
277 time.sleep(5)
278
279 #Copy tshark output file from ONOS to TestON instance
280 #/tmp directory
281 os.system("scp "+ONOS_user+"@"+ONOS1_ip+":"+
282 tshark_port_down+" /tmp/")
283
284 f_port_down = open(tshark_port_down, 'r')
285 f_line = f_port_down.readline()
286 obj_down = f_line.split(" ")
287 if len(f_line) > 0:
288 timestamp_begin_pt_down = int(float(obj_down[1])*1000)
289 else:
290 main.log.info("Tshark output file returned unexpected"+
291 " results")
292 timestamp_begin_pt_down = 0
293
294 main.step("Obtain t1 by REST call")
295 #TODO: Implement json object parsing here
296
297 timestamp_end_pt_down_1 = 0
298 timestamp_end_pt_down_2 = 0
299 timestamp_end_pt_down_3 = 0
300
301 delta_pt_down_1 = int(timestamp_end_pt_down_1) - \
302 int(timestamp_begin_pt_down)
303 delta_pt_down_2 = int(timestamp_end_pt_down_2) - \
304 int(timestamp_begin_pt_down)
305 delta_pt_down_3 = int(timestamp_end_pt_down_3) - \
306 int(timestamp_begin_pt_down)
307
308 #TODO: Remove these logs. For test purposes only
309 main.log.info("Delta1: "+str(delta_pt_down_1))
310 main.log.info("Delta2: "+str(delta_pt_down_2))
311 main.log.info("Delta3: "+str(delta_pt_down_3))
312
313 #Port up events
314 main.step("Enable port and obtain timestamp")
315 main.step("Starting wireshark capture for port status up")
316 main.ONOS1.tshark_grep("OFP 130 Port Status", tshark_port_up)
317 time.sleep(10)
318
319 main.Mininet2.handle.sendline("sudo ifconfig s1-eth2 up")
320 main.Mininet2.handle.expect("\$")
321 time.sleep(20)
322
323 os.system("scp "+ONOS_user+"@"+ONOS1_ip+":"+
324 tshark_port_up+" /tmp/")
325
326 f_port_up = open(tshark_port_up, 'r')
327 f_line = f_port_down.readline()
328 obj_up = f_line.split(" ")
329 if len(f_line) > 0:
330 timestamp_begin_pt_up = int(float(obj_up[1])*1000)
331 else:
332 main.log.info("Tshark output file returned unexpected"+
333 " results.")
334 timestamp_begin_pt_up = 0
335
336 main.step("Obtain t1 by REST call")
337 #TODO: Implement json object parsing here
338
339 timestamp_end_pt_up_1 = 0
340 timestamp_end_pt_up_2 = 0
341 timestamp_end_pt_up_3 = 0
342
343 delta_pt_up_1 = int(timestamp_end_pt_up_1) - \
344 int(timestamp_begin_pt_up)
345 delta_pt_up_2 = int(timestamp_end_pt_up_2) - \
346 int(timestamp_begin_pt_up)
347 delta_pt_up_3 = int(timestamp_end_pt_up_3) - \
348 int(timestamp_begin_pt_up)
349
350 #TODO: Remove these logs. For test purposes only
351 main.log.info("Delta1: "+str(delta_pt_up_1))
352 main.log.info("Delta2: "+str(delta_pt_up_2))
353 main.log.info("Delta3: "+str(delta_pt_up_3))
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368