blob: 842f6c49100f66623c5f2d33ff72c9566709490e [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
andrewonlab867212a2014-10-22 20:13:38 -040082 main.step("Enable metrics feature")
83 main.ONOS1cli.feature_install("onos-app-metrics-topology")
84 main.ONOS2cli.feature_install("onos-app-metrics-topology")
85 main.ONOS3cli.feature_install("onos-app-metrics-topology")
86
andrewonlab2a6c9342014-10-16 13:40:15 -040087 utilities.assert_equals(expect=main.TRUE,
88 actual= cell_file_result and cell_apply_result and\
89 verify_cell_result and checkout_result and\
90 pull_result and mvn_result and\
andrewonlabe9fb6722014-10-24 12:20:35 -040091 install1_result and install2_result and\
92 install3_result,
andrewonlab8d29f122014-10-22 17:15:04 -040093 onpass="ONOS started successfully",
94 onfail="Failed to start ONOS")
andrewonlab2a6c9342014-10-16 13:40:15 -040095
andrewonlabba44bcf2014-10-16 16:54:41 -040096 def CASE2(self, main):
97 '''
98 Assign s1 to ONOS1 and measure latency
andrewonlab3a7c3c72014-10-24 17:21:03 -040099
100 There are 4 levels of latency measurements to this test:
101 1) End-to-end measurement: Complete end-to-end measurement
102 from TCP (SYN/ACK) handshake to Graph change
103 2) OFP-to-graph measurement: 'ONOS processing' snippet of
104 measurement from OFP Vendor message to Graph change
105 3) OFP-to-device measurement: 'ONOS processing without
106 graph change' snippet of measurement from OFP vendor
107 message to Device change timestamp
108 4) T0-to-device measurement: Measurement that includes
109 the switch handshake to devices timestamp without
110 the graph view change. (TCP handshake -> Device
111 change)
andrewonlabba44bcf2014-10-16 16:54:41 -0400112 '''
113 import time
andrewonlabe6745342014-10-17 14:29:13 -0400114 import subprocess
115 import json
116 import requests
117 import os
andrewonlabba44bcf2014-10-16 16:54:41 -0400118
119 ONOS1_ip = main.params['CTRL']['ip1']
120 ONOS2_ip = main.params['CTRL']['ip2']
121 ONOS3_ip = main.params['CTRL']['ip3']
andrewonlabe6745342014-10-17 14:29:13 -0400122 ONOS_user = main.params['CTRL']['user']
123
andrewonlabba44bcf2014-10-16 16:54:41 -0400124 default_sw_port = main.params['CTRL']['port1']
125
126 #Number of iterations of case
127 num_iter = main.params['TEST']['numIter']
128
andrewonlab226024e2014-10-24 16:01:32 -0400129 #Timestamp 'keys' for json metrics output.
130 #These are subject to change, hence moved into params
131 deviceTimestamp = main.params['JSON']['deviceTimestamp']
132 graphTimestamp = main.params['JSON']['graphTimestamp']
133
134 #List of switch add latency collected from
135 #all iterations
136 latency_end_to_end_list = []
137 latency_ofp_to_graph_list = []
138 latency_ofp_to_device_list = []
139 latency_t0_to_device_list = []
140
andrewonlabba44bcf2014-10-16 16:54:41 -0400141 #Directory/file to store tshark results
142 tshark_of_output = "/tmp/tshark_of_topo.txt"
143 tshark_tcp_output = "/tmp/tshark_tcp_topo.txt"
144
145 #String to grep in tshark output
146 tshark_tcp_string = "TCP 74 "+default_sw_port
147 tshark_of_string = "OFP 86 Vendor"
andrewonlabe6745342014-10-17 14:29:13 -0400148
149 #Initialize assertion to TRUE
150 assertion = main.TRUE
151
andrewonlabba44bcf2014-10-16 16:54:41 -0400152 main.log.report("Latency of adding one switch")
153
154 for i in range(0, int(num_iter)):
155 main.log.info("Starting tshark capture")
156
157 #* TCP [ACK, SYN] is used as t0_a, the
158 # very first "exchange" between ONOS and
159 # the switch for end-to-end measurement
160 #* OFP [Stats Reply] is used for t0_b
161 # the very last OFP message between ONOS
162 # and the switch for ONOS measurement
163 main.ONOS1.tshark_grep(tshark_tcp_string,
164 tshark_tcp_output)
165 main.ONOS1.tshark_grep(tshark_of_string,
166 tshark_of_output)
167
168 #Wait and ensure tshark is started and
169 #capturing
170 time.sleep(10)
171
172 main.log.info("Assigning s1 to controller")
173
174 main.Mininet1.assign_sw_controller(sw="1",
175 ip1=ONOS1_ip, port1=default_sw_port)
176
177 #Wait and ensure switch is assigned
178 #before stopping tshark
andrewonlab867212a2014-10-22 20:13:38 -0400179 time.sleep(30)
andrewonlab226024e2014-10-24 16:01:32 -0400180
181 main.log.info("Stopping all Tshark processes")
andrewonlabba44bcf2014-10-16 16:54:41 -0400182 main.ONOS1.stop_tshark()
183
andrewonlabe6745342014-10-17 14:29:13 -0400184 #tshark output is saved in ONOS. Use subprocess
185 #to copy over files to TestON for parsing
186 main.log.info("Copying over tshark files")
187
188 #TCP CAPTURE ****
andrewonlab8d29f122014-10-22 17:15:04 -0400189 #Copy the tshark output from ONOS machine to
190 #TestON machine in tshark_tcp_output directory>file
191 os.system("scp "+ONOS_user+"@"+ONOS1_ip+":"+
192 tshark_tcp_output+" /tmp/")
193 tcp_file = open(tshark_tcp_output, 'r')
194 temp_text = tcp_file.readline()
andrewonlabe6745342014-10-17 14:29:13 -0400195 temp_text = temp_text.split(" ")
andrewonlabba44bcf2014-10-16 16:54:41 -0400196
andrewonlabe6745342014-10-17 14:29:13 -0400197 main.log.info("Object read in from TCP capture: "+
198 str(temp_text))
andrewonlab867212a2014-10-22 20:13:38 -0400199 if len(temp_text) > 1:
andrewonlab3a7c3c72014-10-24 17:21:03 -0400200 t0_tcp = float(temp_text[1])*1000.0
andrewonlabe6745342014-10-17 14:29:13 -0400201 else:
202 main.log.error("Tshark output file for TCP"+
203 " returned unexpected results")
204 t0_tcp = 0
205 assertion = main.FALSE
andrewonlab8d29f122014-10-22 17:15:04 -0400206
207 tcp_file.close()
andrewonlabe6745342014-10-17 14:29:13 -0400208 #****************
andrewonlabba44bcf2014-10-16 16:54:41 -0400209
andrewonlabe6745342014-10-17 14:29:13 -0400210 #OF CAPTURE ****
andrewonlab8d29f122014-10-22 17:15:04 -0400211 os.system("scp "+ONOS_user+"@"+ONOS1_ip+":"+
212 tshark_of_output+" /tmp/")
213 of_file = open(tshark_of_output, 'r')
214
215 line_ofp = ""
andrewonlab226024e2014-10-24 16:01:32 -0400216 #Read until last line of file
andrewonlabe6745342014-10-17 14:29:13 -0400217 while True:
andrewonlab8d29f122014-10-22 17:15:04 -0400218 temp_text = of_file.readline()
219 if temp_text !='':
andrewonlabe6745342014-10-17 14:29:13 -0400220 line_ofp = temp_text
221 else:
222 break
223 obj = line_ofp.split(" ")
224
225 main.log.info("Object read in from OFP capture: "+
226 str(line_ofp))
227
andrewonlab867212a2014-10-22 20:13:38 -0400228 if len(line_ofp) > 1:
andrewonlab3a7c3c72014-10-24 17:21:03 -0400229 t0_ofp = float(obj[1])*1000.0
andrewonlabe6745342014-10-17 14:29:13 -0400230 else:
231 main.log.error("Tshark output file for OFP"+
232 " returned unexpected results")
233 t0_ofp = 0
234 assertion = main.FALSE
andrewonlab8d29f122014-10-22 17:15:04 -0400235
236 of_file.close()
andrewonlabe6745342014-10-17 14:29:13 -0400237 #****************
238
239 #TODO:
240 #Get json object from all 3 ONOS instances
andrewonlab867212a2014-10-22 20:13:38 -0400241 json_str_1 = main.ONOS1cli.topology_events_metrics()
242 json_str_2 = main.ONOS2cli.topology_events_metrics()
243 json_str_3 = main.ONOS3cli.topology_events_metrics()
andrewonlab867212a2014-10-22 20:13:38 -0400244
245 json_obj_1 = json.loads(json_str_1)
246 json_obj_2 = json.loads(json_str_2)
247 json_obj_3 = json.loads(json_str_3)
248
andrewonlab226024e2014-10-24 16:01:32 -0400249 #Obtain graph timestamp. This timestsamp captures
250 #the epoch time at which the topology graph was updated.
251 graph_timestamp_1 = \
252 json_obj_1[graphTimestamp]['value']
253 graph_timestamp_2 = \
254 json_obj_2[graphTimestamp]['value']
255 graph_timestamp_3 = \
256 json_obj_3[graphTimestamp]['value']
andrewonlab867212a2014-10-22 20:13:38 -0400257
andrewonlab226024e2014-10-24 16:01:32 -0400258 #Obtain device timestamp. This timestamp captures
259 #the epoch time at which the device event happened
260 device_timestamp_1 = \
261 json_obj_1[deviceTimestamp]['value']
262 device_timestamp_2 = \
263 json_obj_2[deviceTimestamp]['value']
264 device_timestamp_3 = \
265 json_obj_3[deviceTimestamp]['value']
andrewonlabe9fb6722014-10-24 12:20:35 -0400266
andrewonlab226024e2014-10-24 16:01:32 -0400267 #t0 to device processing latency
268 delta_device_1 = int(device_timestamp_1) - int(t0_tcp)
269 delta_device_2 = int(device_timestamp_2) - int(t0_tcp)
270 delta_device_3 = int(device_timestamp_3) - int(t0_tcp)
271
272 #Get average of delta from all instances
273 avg_delta_device = \
274 (int(delta_device_1)+\
275 int(delta_device_2)+\
276 int(delta_device_3)) / 3
andrewonlabba44bcf2014-10-16 16:54:41 -0400277
andrewonlab226024e2014-10-24 16:01:32 -0400278 #Ensure avg delta meets the threshold before appending
279 if avg_delta_device > 0.0 and avg_delta_device < 10000:
280 latency_t0_to_device_list.append(avg_delta_device)
andrewonlabee4efeb2014-10-24 16:44:51 -0400281 else:
282 main.log.info("Results ignored due to excess in "+\
283 "threshold")
284
andrewonlab226024e2014-10-24 16:01:32 -0400285 #t0 to graph processing latency (end-to-end)
286 delta_graph_1 = int(graph_timestamp_1) - int(t0_tcp)
287 delta_graph_2 = int(graph_timestamp_2) - int(t0_tcp)
288 delta_graph_3 = int(graph_timestamp_3) - int(t0_tcp)
289
290 #Get average of delta from all instances
291 avg_delta_graph = \
292 (int(delta_graph_1)+\
293 int(delta_graph_2)+\
294 int(delta_graph_3)) / 3
295
296 latency_end_to_end_list.append(avg_delta_graph)
297
298 #Ensure avg delta meets the threshold before appending
299 if avg_delta_graph > 0.0 and avg_delta_graph < 10000:
300 latency_t0_to_device_list.append(avg_delta_graph)
andrewonlabee4efeb2014-10-24 16:44:51 -0400301 else:
302 main.log.info("Results ignored due to excess in "+\
303 "threshold")
andrewonlab226024e2014-10-24 16:01:32 -0400304
305 #ofp to graph processing latency (ONOS processing)
306 delta_ofp_graph_1 = int(graph_timestamp_1) - int(t0_ofp)
307 delta_ofp_graph_2 = int(graph_timestamp_2) - int(t0_ofp)
308 delta_ofp_graph_3 = int(graph_timestamp_3) - int(t0_ofp)
309
310 avg_delta_ofp_graph = \
311 (int(delta_ofp_graph_1)+\
312 int(delta_ofp_graph_2)+\
313 int(delta_ofp_graph_3)) / 3
314
315 if avg_delta_ofp_graph > 0.0 and avg_delta_ofp_graph < 10000:
316 latency_ofp_to_graph_list.append(avg_delta_ofp_graph)
andrewonlabee4efeb2014-10-24 16:44:51 -0400317 else:
318 main.log.info("Results ignored due to excess in "+\
319 "threshold")
320
andrewonlab226024e2014-10-24 16:01:32 -0400321 #ofp to device processing latency (ONOS processing)
andrewonlabee4efeb2014-10-24 16:44:51 -0400322 delta_ofp_device_1 = float(device_timestamp_1) - float(t0_ofp)
323 delta_ofp_device_2 = float(device_timestamp_2) - float(t0_ofp)
324 delta_ofp_device_3 = float(device_timestamp_3) - float(t0_ofp)
andrewonlab226024e2014-10-24 16:01:32 -0400325
326 avg_delta_ofp_device = \
andrewonlabee4efeb2014-10-24 16:44:51 -0400327 (float(delta_ofp_device_1)+\
328 float(delta_ofp_device_2)+\
329 float(delta_ofp_device_3)) / 3.0
andrewonlab226024e2014-10-24 16:01:32 -0400330
andrewonlabf47993a2014-10-24 17:56:01 -0400331 #NOTE: ofp - delta measurements are occasionally negative
332 # due to system time misalignment.
333 #TODO: Implement ptp across all clusters
334 #Just add the calculation to list for now
335 latency_ofp_to_device_list.append(avg_delta_ofp_device)
andrewonlabba44bcf2014-10-16 16:54:41 -0400336
andrewonlabe6745342014-10-17 14:29:13 -0400337 #TODO:
338 #Fetch logs upon threshold excess
andrewonlabba44bcf2014-10-16 16:54:41 -0400339
andrewonlabf47993a2014-10-24 17:56:01 -0400340
andrewonlab226024e2014-10-24 16:01:32 -0400341 main.log.info("ONOS1 delta end-to-end: "+
342 str(delta_graph_1))
343 main.log.info("ONOS2 delta end-to-end: "+
344 str(delta_graph_2))
345 main.log.info("ONSO3 delta end-to-end: "+
346 str(delta_graph_3))
andrewonlabba44bcf2014-10-16 16:54:41 -0400347
andrewonlab226024e2014-10-24 16:01:32 -0400348 main.log.info("ONOS1 delta OFP - graph: "+
349 str(delta_ofp_graph_1))
350 main.log.info("ONOS2 delta OFP - graph: "+
351 str(delta_ofp_graph_2))
352 main.log.info("ONOS3 delta OFP - graph: "+
353 str(delta_ofp_graph_3))
andrewonlabe6745342014-10-17 14:29:13 -0400354
andrewonlab226024e2014-10-24 16:01:32 -0400355 main.log.info("ONOS1 delta device - t0: "+
356 str(delta_device_1))
357 main.log.info("ONOS2 delta device - t0: "+
358 str(delta_device_2))
359 main.log.info("ONOS3 delta device - t0: "+
360 str(delta_device_3))
361
362 main.log.info("ONOS1 delta OFP - device: "+
363 str(delta_ofp_device_1))
364 main.log.info("ONOS2 delta OFP - device: "+
365 str(delta_ofp_device_2))
366 main.log.info("ONOS3 delta OFP - device: "+
367 str(delta_ofp_device_3))
368
andrewonlab8d29f122014-10-22 17:15:04 -0400369 main.step("Remove switch from controller")
370 main.Mininet1.delete_sw_controller("s1")
andrewonlabba44bcf2014-10-16 16:54:41 -0400371
andrewonlab8d29f122014-10-22 17:15:04 -0400372 time.sleep(5)
andrewonlabba44bcf2014-10-16 16:54:41 -0400373
andrewonlabf47993a2014-10-24 17:56:01 -0400374 #END for loop for iteration
375
andrewonlabee4efeb2014-10-24 16:44:51 -0400376 #If there is at least 1 element in each list,
andrewonlabc15c9582014-10-24 16:35:52 -0400377 #pass the test case
378 if len(latency_end_to_end_list) > 0 and\
379 len(latency_ofp_to_graph_list) > 0 and\
380 len(latency_ofp_to_device_list) > 0 and\
381 len(latency_t0_to_device_list) > 0:
382 assertion = main.TRUE
andrewonlabf47993a2014-10-24 17:56:01 -0400383 elif len(latency_end_to_end_list) == 0:
384 #The appending of 0 here is to prevent
385 #the min,max,sum functions from failing
386 #below
387 latency_end_to_end_list.append(0)
388 assertion = main.FALSE
389 elif len(latency_ofp_to_graph_list) == 0:
390 latency_ofp_to_graph_list.append(0)
391 assertion = main.FALSE
392 elif len(latency_ofp_to_device_list) == 0:
393 latency_ofp_to_device_list.append(0)
394 assertion = main.FALSE
395 elif len(latency_t0_to_device_list) == 0:
396 latency_t0_to_device_list.append(0)
397 assertion = main.FALSE
andrewonlabc15c9582014-10-24 16:35:52 -0400398
399 #Calculate min, max, avg of latency lists
400 latency_end_to_end_max = \
andrewonlabee4efeb2014-10-24 16:44:51 -0400401 int(max(latency_end_to_end_list))
andrewonlabc15c9582014-10-24 16:35:52 -0400402 latency_end_to_end_min = \
andrewonlabee4efeb2014-10-24 16:44:51 -0400403 int(min(latency_end_to_end_list))
andrewonlabc15c9582014-10-24 16:35:52 -0400404 latency_end_to_end_avg = \
andrewonlabc90667c2014-10-24 16:48:28 -0400405 (int(sum(latency_end_to_end_list)) / \
andrewonlabc15c9582014-10-24 16:35:52 -0400406 len(latency_end_to_end_list))
407
408 latency_ofp_to_graph_max = \
andrewonlabee4efeb2014-10-24 16:44:51 -0400409 int(max(latency_ofp_to_graph_list))
andrewonlabc15c9582014-10-24 16:35:52 -0400410 latency_ofp_to_graph_min = \
andrewonlabee4efeb2014-10-24 16:44:51 -0400411 int(min(latency_ofp_to_graph_list))
andrewonlabc15c9582014-10-24 16:35:52 -0400412 latency_ofp_to_graph_avg = \
andrewonlabee4efeb2014-10-24 16:44:51 -0400413 (int(sum(latency_ofp_to_graph_list)) / \
andrewonlabc15c9582014-10-24 16:35:52 -0400414 len(latency_ofp_to_graph_list))
415
416 latency_ofp_to_device_max = \
andrewonlabee4efeb2014-10-24 16:44:51 -0400417 int(max(latency_ofp_to_device_list))
andrewonlabc15c9582014-10-24 16:35:52 -0400418 latency_ofp_to_device_min = \
andrewonlabee4efeb2014-10-24 16:44:51 -0400419 int(min(latency_ofp_to_device_list))
andrewonlabc15c9582014-10-24 16:35:52 -0400420 latency_ofp_to_device_avg = \
andrewonlabee4efeb2014-10-24 16:44:51 -0400421 (int(sum(latency_ofp_to_device_list)) / \
andrewonlabc15c9582014-10-24 16:35:52 -0400422 len(latency_ofp_to_device_list))
423
424 latency_t0_to_device_max = \
andrewonlabee4efeb2014-10-24 16:44:51 -0400425 float(max(latency_t0_to_device_list))
andrewonlabc15c9582014-10-24 16:35:52 -0400426 latency_t0_to_device_min = \
andrewonlabee4efeb2014-10-24 16:44:51 -0400427 float(min(latency_t0_to_device_list))
andrewonlabc15c9582014-10-24 16:35:52 -0400428 latency_t0_to_device_avg = \
andrewonlabee4efeb2014-10-24 16:44:51 -0400429 (float(sum(latency_t0_to_device_list)) / \
andrewonlabc15c9582014-10-24 16:35:52 -0400430 len(latency_ofp_to_device_list))
431
432 main.log.report("Switch add - End-to-end latency: \n"+\
433 "Min: "+str(latency_end_to_end_min)+"\n"+\
434 "Max: "+str(latency_end_to_end_max)+"\n"+\
435 "Avg: "+str(latency_end_to_end_avg))
436 main.log.report("Switch add - OFP-to-Graph latency: \n"+\
437 "Min: "+str(latency_ofp_to_graph_min)+"\n"+\
438 "Max: "+str(latency_ofp_to_graph_max)+"\n"+\
439 "Avg: "+str(latency_ofp_to_graph_avg))
440 main.log.report("Switch add - OFP-to-Device latency: \n"+\
441 "Min: "+str(latency_ofp_to_device_min)+"\n"+\
442 "Max: "+str(latency_ofp_to_device_max)+"\n"+\
443 "Avg: "+str(latency_ofp_to_device_avg))
444 main.log.report("Switch add - t0-to-Device latency: \n"+\
445 "Min: "+str(latency_t0_to_device_min)+"\n"+\
446 "Max: "+str(latency_t0_to_device_max)+"\n"+\
447 "Avg: "+str(latency_t0_to_device_avg))
andrewonlab226024e2014-10-24 16:01:32 -0400448
andrewonlab8d29f122014-10-22 17:15:04 -0400449 utilities.assert_equals(expect=main.TRUE, actual=assertion,
450 onpass="Switch latency test successful",
451 onfail="Switch latency test failed")
andrewonlabba44bcf2014-10-16 16:54:41 -0400452
andrewonlab8d29f122014-10-22 17:15:04 -0400453 def CASE3(self, main):
454 '''
455 Bring port up / down and measure latency.
456 Port enable / disable is simulated by ifconfig up / down
457 '''
458 import time
459 import subprocess
460 import os
461 import requests
462 import json
andrewonlab2a6c9342014-10-16 13:40:15 -0400463
andrewonlab8d29f122014-10-22 17:15:04 -0400464 ONOS1_ip = main.params['CTRL']['ip1']
465 default_sw_port = main.params['CTRL']['port1']
466 ONOS_user = main.params['CTRL']['user']
467 num_iter = main.params['TEST']['numIter']
468
469 tshark_port_status = "OFP 130 Port Status"
470
471 tshark_port_up = "/tmp/tshark_port_up.txt"
472 tshark_port_down = "/tmp/tshark_port_down.txt"
473
474 main.log.report("Port enable / disable latency")
475
476 main.step("Assign switch to controller")
477 main.Mininet1.assign_sw_controller(sw="1",ip1=ONOS1_ip,
478 port1=default_sw_port)
479
480 main.step("Verify switch is assigned correctly")
481 result_s1 = main.Mininet1.get_sw_controller(sw="s1")
482 if result_s1 == main.FALSE:
483 main.log.info("Switch s1 was not assigned correctly")
484 assertion = main.FALSE
485 else:
486 main.log.info("Switch s1 was assigned correctly")
487
488 for i in range(0, int(num_iter)):
489 main.step("Starting wireshark capture for port status down")
490 main.ONOS1.tshark_grep(tshark_port_status,
491 tshark_port_down)
492
493 time.sleep(10)
494
495 main.step("Disable port (interface s1-eth2)")
496 main.Mininet2.handle.sendline("sudo ifconfig s1-eth2 down")
497 main.Mininet2.handle.expect("\$")
498 time.sleep(20)
499
500 main.ONOS1.tshark_stop()
501 time.sleep(5)
502
503 #Copy tshark output file from ONOS to TestON instance
504 #/tmp directory
505 os.system("scp "+ONOS_user+"@"+ONOS1_ip+":"+
506 tshark_port_down+" /tmp/")
507
508 f_port_down = open(tshark_port_down, 'r')
509 f_line = f_port_down.readline()
510 obj_down = f_line.split(" ")
511 if len(f_line) > 0:
512 timestamp_begin_pt_down = int(float(obj_down[1])*1000)
513 else:
514 main.log.info("Tshark output file returned unexpected"+
515 " results")
516 timestamp_begin_pt_down = 0
517
518 main.step("Obtain t1 by REST call")
519 #TODO: Implement json object parsing here
520
521 timestamp_end_pt_down_1 = 0
522 timestamp_end_pt_down_2 = 0
523 timestamp_end_pt_down_3 = 0
524
525 delta_pt_down_1 = int(timestamp_end_pt_down_1) - \
526 int(timestamp_begin_pt_down)
527 delta_pt_down_2 = int(timestamp_end_pt_down_2) - \
528 int(timestamp_begin_pt_down)
529 delta_pt_down_3 = int(timestamp_end_pt_down_3) - \
530 int(timestamp_begin_pt_down)
531
532 #TODO: Remove these logs. For test purposes only
533 main.log.info("Delta1: "+str(delta_pt_down_1))
534 main.log.info("Delta2: "+str(delta_pt_down_2))
535 main.log.info("Delta3: "+str(delta_pt_down_3))
536
537 #Port up events
538 main.step("Enable port and obtain timestamp")
539 main.step("Starting wireshark capture for port status up")
540 main.ONOS1.tshark_grep("OFP 130 Port Status", tshark_port_up)
541 time.sleep(10)
542
543 main.Mininet2.handle.sendline("sudo ifconfig s1-eth2 up")
544 main.Mininet2.handle.expect("\$")
545 time.sleep(20)
546
547 os.system("scp "+ONOS_user+"@"+ONOS1_ip+":"+
548 tshark_port_up+" /tmp/")
549
550 f_port_up = open(tshark_port_up, 'r')
551 f_line = f_port_down.readline()
552 obj_up = f_line.split(" ")
553 if len(f_line) > 0:
554 timestamp_begin_pt_up = int(float(obj_up[1])*1000)
555 else:
556 main.log.info("Tshark output file returned unexpected"+
557 " results.")
558 timestamp_begin_pt_up = 0
559
560 main.step("Obtain t1 by REST call")
561 #TODO: Implement json object parsing here
562
563 timestamp_end_pt_up_1 = 0
564 timestamp_end_pt_up_2 = 0
565 timestamp_end_pt_up_3 = 0
566
567 delta_pt_up_1 = int(timestamp_end_pt_up_1) - \
568 int(timestamp_begin_pt_up)
569 delta_pt_up_2 = int(timestamp_end_pt_up_2) - \
570 int(timestamp_begin_pt_up)
571 delta_pt_up_3 = int(timestamp_end_pt_up_3) - \
572 int(timestamp_begin_pt_up)
573
574 #TODO: Remove these logs. For test purposes only
575 main.log.info("Delta1: "+str(delta_pt_up_1))
576 main.log.info("Delta2: "+str(delta_pt_up_2))
577 main.log.info("Delta3: "+str(delta_pt_up_3))
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592