blob: 1e4b4c0c6338c20f044b140455a9aeafaceea421 [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
andrewonlab867212a2014-10-22 20:13:38 -0400239 json_str_1 = main.ONOS1cli.topology_events_metrics()
240 json_str_2 = main.ONOS2cli.topology_events_metrics()
241 json_str_3 = main.ONOS3cli.topology_events_metrics()
andrewonlab867212a2014-10-22 20:13:38 -0400242
243 json_obj_1 = json.loads(json_str_1)
244 json_obj_2 = json.loads(json_str_2)
245 json_obj_3 = json.loads(json_str_3)
246
andrewonlab226024e2014-10-24 16:01:32 -0400247 #Obtain graph timestamp. This timestsamp captures
248 #the epoch time at which the topology graph was updated.
249 graph_timestamp_1 = \
250 json_obj_1[graphTimestamp]['value']
251 graph_timestamp_2 = \
252 json_obj_2[graphTimestamp]['value']
253 graph_timestamp_3 = \
254 json_obj_3[graphTimestamp]['value']
andrewonlab867212a2014-10-22 20:13:38 -0400255
andrewonlab226024e2014-10-24 16:01:32 -0400256 #Obtain device timestamp. This timestamp captures
257 #the epoch time at which the device event happened
258 device_timestamp_1 = \
259 json_obj_1[deviceTimestamp]['value']
260 device_timestamp_2 = \
261 json_obj_2[deviceTimestamp]['value']
262 device_timestamp_3 = \
263 json_obj_3[deviceTimestamp]['value']
andrewonlabe9fb6722014-10-24 12:20:35 -0400264
andrewonlab226024e2014-10-24 16:01:32 -0400265 #t0 to device processing latency
266 delta_device_1 = int(device_timestamp_1) - int(t0_tcp)
267 delta_device_2 = int(device_timestamp_2) - int(t0_tcp)
268 delta_device_3 = int(device_timestamp_3) - int(t0_tcp)
269
270 #Get average of delta from all instances
271 avg_delta_device = \
272 (int(delta_device_1)+\
273 int(delta_device_2)+\
274 int(delta_device_3)) / 3
andrewonlabba44bcf2014-10-16 16:54:41 -0400275
andrewonlab226024e2014-10-24 16:01:32 -0400276 #Ensure avg delta meets the threshold before appending
277 if avg_delta_device > 0.0 and avg_delta_device < 10000:
278 latency_t0_to_device_list.append(avg_delta_device)
andrewonlabee4efeb2014-10-24 16:44:51 -0400279 else:
andrewonlab09d973e2014-10-24 18:56:58 -0400280 main.log.info("Results for t0-to-device ignored"+\
281 "due to excess in threshold")
andrewonlabee4efeb2014-10-24 16:44:51 -0400282
andrewonlab226024e2014-10-24 16:01:32 -0400283 #t0 to graph processing latency (end-to-end)
284 delta_graph_1 = int(graph_timestamp_1) - int(t0_tcp)
285 delta_graph_2 = int(graph_timestamp_2) - int(t0_tcp)
286 delta_graph_3 = int(graph_timestamp_3) - int(t0_tcp)
287
288 #Get average of delta from all instances
289 avg_delta_graph = \
290 (int(delta_graph_1)+\
291 int(delta_graph_2)+\
292 int(delta_graph_3)) / 3
293
andrewonlab226024e2014-10-24 16:01:32 -0400294 #Ensure avg delta meets the threshold before appending
295 if avg_delta_graph > 0.0 and avg_delta_graph < 10000:
andrewonlab09d973e2014-10-24 18:56:58 -0400296 latency_end_to_end_list.append(avg_delta_graph)
andrewonlabee4efeb2014-10-24 16:44:51 -0400297 else:
andrewonlab09d973e2014-10-24 18:56:58 -0400298 main.log.info("Results for end-to-end ignored"+\
299 "due to excess in threshold")
andrewonlab226024e2014-10-24 16:01:32 -0400300
301 #ofp to graph processing latency (ONOS processing)
302 delta_ofp_graph_1 = int(graph_timestamp_1) - int(t0_ofp)
303 delta_ofp_graph_2 = int(graph_timestamp_2) - int(t0_ofp)
304 delta_ofp_graph_3 = int(graph_timestamp_3) - int(t0_ofp)
305
306 avg_delta_ofp_graph = \
307 (int(delta_ofp_graph_1)+\
308 int(delta_ofp_graph_2)+\
309 int(delta_ofp_graph_3)) / 3
310
311 if avg_delta_ofp_graph > 0.0 and avg_delta_ofp_graph < 10000:
312 latency_ofp_to_graph_list.append(avg_delta_ofp_graph)
andrewonlabee4efeb2014-10-24 16:44:51 -0400313 else:
andrewonlab09d973e2014-10-24 18:56:58 -0400314 main.log.info("Results for ofp-to-graph "+\
315 "ignored due to excess in threshold")
andrewonlabee4efeb2014-10-24 16:44:51 -0400316
andrewonlab226024e2014-10-24 16:01:32 -0400317 #ofp to device processing latency (ONOS processing)
andrewonlabee4efeb2014-10-24 16:44:51 -0400318 delta_ofp_device_1 = float(device_timestamp_1) - float(t0_ofp)
319 delta_ofp_device_2 = float(device_timestamp_2) - float(t0_ofp)
320 delta_ofp_device_3 = float(device_timestamp_3) - float(t0_ofp)
andrewonlab226024e2014-10-24 16:01:32 -0400321
322 avg_delta_ofp_device = \
andrewonlabee4efeb2014-10-24 16:44:51 -0400323 (float(delta_ofp_device_1)+\
324 float(delta_ofp_device_2)+\
325 float(delta_ofp_device_3)) / 3.0
andrewonlab226024e2014-10-24 16:01:32 -0400326
andrewonlabf47993a2014-10-24 17:56:01 -0400327 #NOTE: ofp - delta measurements are occasionally negative
328 # due to system time misalignment.
andrewonlabf47993a2014-10-24 17:56:01 -0400329 latency_ofp_to_device_list.append(avg_delta_ofp_device)
andrewonlabba44bcf2014-10-16 16:54:41 -0400330
andrewonlabe6745342014-10-17 14:29:13 -0400331 #TODO:
332 #Fetch logs upon threshold excess
andrewonlabba44bcf2014-10-16 16:54:41 -0400333
andrewonlab226024e2014-10-24 16:01:32 -0400334 main.log.info("ONOS1 delta end-to-end: "+
andrewonlab09d973e2014-10-24 18:56:58 -0400335 str(delta_graph_1) + " ms")
andrewonlab226024e2014-10-24 16:01:32 -0400336 main.log.info("ONOS2 delta end-to-end: "+
andrewonlab09d973e2014-10-24 18:56:58 -0400337 str(delta_graph_2) + " ms")
338 main.log.info("ONOS3 delta end-to-end: "+
339 str(delta_graph_3) + " ms")
andrewonlabba44bcf2014-10-16 16:54:41 -0400340
andrewonlab226024e2014-10-24 16:01:32 -0400341 main.log.info("ONOS1 delta OFP - graph: "+
andrewonlab09d973e2014-10-24 18:56:58 -0400342 str(delta_ofp_graph_1) + " ms")
andrewonlab226024e2014-10-24 16:01:32 -0400343 main.log.info("ONOS2 delta OFP - graph: "+
andrewonlab09d973e2014-10-24 18:56:58 -0400344 str(delta_ofp_graph_2) + " ms")
andrewonlab226024e2014-10-24 16:01:32 -0400345 main.log.info("ONOS3 delta OFP - graph: "+
andrewonlab09d973e2014-10-24 18:56:58 -0400346 str(delta_ofp_graph_3) + " ms")
andrewonlabe6745342014-10-17 14:29:13 -0400347
andrewonlab226024e2014-10-24 16:01:32 -0400348 main.log.info("ONOS1 delta device - t0: "+
andrewonlab09d973e2014-10-24 18:56:58 -0400349 str(delta_device_1) + " ms")
andrewonlab226024e2014-10-24 16:01:32 -0400350 main.log.info("ONOS2 delta device - t0: "+
andrewonlab09d973e2014-10-24 18:56:58 -0400351 str(delta_device_2) + " ms")
andrewonlab226024e2014-10-24 16:01:32 -0400352 main.log.info("ONOS3 delta device - t0: "+
andrewonlab09d973e2014-10-24 18:56:58 -0400353 str(delta_device_3) + " ms")
andrewonlab226024e2014-10-24 16:01:32 -0400354
andrewonlab8790abb2014-11-06 13:51:54 -0500355 #main.log.info("ONOS1 delta OFP - device: "+
356 # str(delta_ofp_device_1) + " ms")
357 #main.log.info("ONOS2 delta OFP - device: "+
358 # str(delta_ofp_device_2) + " ms")
359 #main.log.info("ONOS3 delta OFP - device: "+
360 # str(delta_ofp_device_3) + " ms")
andrewonlab226024e2014-10-24 16:01:32 -0400361
andrewonlab8d29f122014-10-22 17:15:04 -0400362 main.step("Remove switch from controller")
363 main.Mininet1.delete_sw_controller("s1")
andrewonlabba44bcf2014-10-16 16:54:41 -0400364
andrewonlab8d29f122014-10-22 17:15:04 -0400365 time.sleep(5)
andrewonlabba44bcf2014-10-16 16:54:41 -0400366
andrewonlab09d973e2014-10-24 18:56:58 -0400367 #END of for loop iteration
andrewonlabf47993a2014-10-24 17:56:01 -0400368
andrewonlabee4efeb2014-10-24 16:44:51 -0400369 #If there is at least 1 element in each list,
andrewonlabc15c9582014-10-24 16:35:52 -0400370 #pass the test case
371 if len(latency_end_to_end_list) > 0 and\
372 len(latency_ofp_to_graph_list) > 0 and\
373 len(latency_ofp_to_device_list) > 0 and\
374 len(latency_t0_to_device_list) > 0:
375 assertion = main.TRUE
andrewonlabf47993a2014-10-24 17:56:01 -0400376 elif len(latency_end_to_end_list) == 0:
377 #The appending of 0 here is to prevent
378 #the min,max,sum functions from failing
379 #below
380 latency_end_to_end_list.append(0)
381 assertion = main.FALSE
382 elif len(latency_ofp_to_graph_list) == 0:
383 latency_ofp_to_graph_list.append(0)
384 assertion = main.FALSE
385 elif len(latency_ofp_to_device_list) == 0:
386 latency_ofp_to_device_list.append(0)
387 assertion = main.FALSE
388 elif len(latency_t0_to_device_list) == 0:
389 latency_t0_to_device_list.append(0)
390 assertion = main.FALSE
andrewonlabc15c9582014-10-24 16:35:52 -0400391
392 #Calculate min, max, avg of latency lists
393 latency_end_to_end_max = \
andrewonlabee4efeb2014-10-24 16:44:51 -0400394 int(max(latency_end_to_end_list))
andrewonlabc15c9582014-10-24 16:35:52 -0400395 latency_end_to_end_min = \
andrewonlabee4efeb2014-10-24 16:44:51 -0400396 int(min(latency_end_to_end_list))
andrewonlabc15c9582014-10-24 16:35:52 -0400397 latency_end_to_end_avg = \
andrewonlabc90667c2014-10-24 16:48:28 -0400398 (int(sum(latency_end_to_end_list)) / \
andrewonlabc15c9582014-10-24 16:35:52 -0400399 len(latency_end_to_end_list))
400
401 latency_ofp_to_graph_max = \
andrewonlabee4efeb2014-10-24 16:44:51 -0400402 int(max(latency_ofp_to_graph_list))
andrewonlabc15c9582014-10-24 16:35:52 -0400403 latency_ofp_to_graph_min = \
andrewonlabee4efeb2014-10-24 16:44:51 -0400404 int(min(latency_ofp_to_graph_list))
andrewonlabc15c9582014-10-24 16:35:52 -0400405 latency_ofp_to_graph_avg = \
andrewonlabee4efeb2014-10-24 16:44:51 -0400406 (int(sum(latency_ofp_to_graph_list)) / \
andrewonlabc15c9582014-10-24 16:35:52 -0400407 len(latency_ofp_to_graph_list))
408
409 latency_ofp_to_device_max = \
andrewonlabee4efeb2014-10-24 16:44:51 -0400410 int(max(latency_ofp_to_device_list))
andrewonlabc15c9582014-10-24 16:35:52 -0400411 latency_ofp_to_device_min = \
andrewonlabee4efeb2014-10-24 16:44:51 -0400412 int(min(latency_ofp_to_device_list))
andrewonlabc15c9582014-10-24 16:35:52 -0400413 latency_ofp_to_device_avg = \
andrewonlabee4efeb2014-10-24 16:44:51 -0400414 (int(sum(latency_ofp_to_device_list)) / \
andrewonlabc15c9582014-10-24 16:35:52 -0400415 len(latency_ofp_to_device_list))
416
417 latency_t0_to_device_max = \
andrewonlabee4efeb2014-10-24 16:44:51 -0400418 float(max(latency_t0_to_device_list))
andrewonlabc15c9582014-10-24 16:35:52 -0400419 latency_t0_to_device_min = \
andrewonlabee4efeb2014-10-24 16:44:51 -0400420 float(min(latency_t0_to_device_list))
andrewonlabc15c9582014-10-24 16:35:52 -0400421 latency_t0_to_device_avg = \
andrewonlabee4efeb2014-10-24 16:44:51 -0400422 (float(sum(latency_t0_to_device_list)) / \
andrewonlabc15c9582014-10-24 16:35:52 -0400423 len(latency_ofp_to_device_list))
424
425 main.log.report("Switch add - End-to-end latency: \n"+\
426 "Min: "+str(latency_end_to_end_min)+"\n"+\
427 "Max: "+str(latency_end_to_end_max)+"\n"+\
428 "Avg: "+str(latency_end_to_end_avg))
429 main.log.report("Switch add - OFP-to-Graph latency: \n"+\
430 "Min: "+str(latency_ofp_to_graph_min)+"\n"+\
431 "Max: "+str(latency_ofp_to_graph_max)+"\n"+\
432 "Avg: "+str(latency_ofp_to_graph_avg))
andrewonlabc15c9582014-10-24 16:35:52 -0400433 main.log.report("Switch add - t0-to-Device latency: \n"+\
434 "Min: "+str(latency_t0_to_device_min)+"\n"+\
435 "Max: "+str(latency_t0_to_device_max)+"\n"+\
436 "Avg: "+str(latency_t0_to_device_avg))
andrewonlab226024e2014-10-24 16:01:32 -0400437
andrewonlab8d29f122014-10-22 17:15:04 -0400438 utilities.assert_equals(expect=main.TRUE, actual=assertion,
439 onpass="Switch latency test successful",
440 onfail="Switch latency test failed")
andrewonlabba44bcf2014-10-16 16:54:41 -0400441
andrewonlab8d29f122014-10-22 17:15:04 -0400442 def CASE3(self, main):
443 '''
444 Bring port up / down and measure latency.
445 Port enable / disable is simulated by ifconfig up / down
andrewonlab393531a2014-10-27 18:36:26 -0400446
447 In ONOS-next, we must ensure that the port we are
448 manipulating is connected to another switch with a valid
449 connection. Otherwise, graph view will not be updated.
andrewonlab8d29f122014-10-22 17:15:04 -0400450 '''
451 import time
452 import subprocess
453 import os
454 import requests
455 import json
andrewonlab2a6c9342014-10-16 13:40:15 -0400456
andrewonlab8d29f122014-10-22 17:15:04 -0400457 ONOS1_ip = main.params['CTRL']['ip1']
andrewonlab393531a2014-10-27 18:36:26 -0400458 ONOS2_ip = main.params['CTRL']['ip2']
459 ONOS3_ip = main.params['CTRL']['ip3']
andrewonlab8d29f122014-10-22 17:15:04 -0400460 ONOS_user = main.params['CTRL']['user']
andrewonlab8d29f122014-10-22 17:15:04 -0400461
andrewonlab393531a2014-10-27 18:36:26 -0400462 default_sw_port = main.params['CTRL']['port1']
andrewonlab8790abb2014-11-06 13:51:54 -0500463
464 assertion = main.TRUE
andrewonlab393531a2014-10-27 18:36:26 -0400465 #Number of iterations of case
466 num_iter = main.params['TEST']['numIter']
467
468 #Timestamp 'keys' for json metrics output.
469 #These are subject to change, hence moved into params
470 deviceTimestamp = main.params['JSON']['deviceTimestamp']
471 graphTimestamp = main.params['JSON']['graphTimestamp']
472
473 #NOTE: Some hardcoded variables you may need to configure
474 # besides the params
475
andrewonlab8d29f122014-10-22 17:15:04 -0400476 tshark_port_status = "OFP 130 Port Status"
477
478 tshark_port_up = "/tmp/tshark_port_up.txt"
479 tshark_port_down = "/tmp/tshark_port_down.txt"
andrewonlab393531a2014-10-27 18:36:26 -0400480 interface_config = "s1-eth1"
andrewonlab8d29f122014-10-22 17:15:04 -0400481
482 main.log.report("Port enable / disable latency")
483
andrewonlab393531a2014-10-27 18:36:26 -0400484 main.step("Assign switches s1 and s2 to controller 1")
andrewonlab8d29f122014-10-22 17:15:04 -0400485 main.Mininet1.assign_sw_controller(sw="1",ip1=ONOS1_ip,
486 port1=default_sw_port)
andrewonlab393531a2014-10-27 18:36:26 -0400487 main.Mininet1.assign_sw_controller(sw="2",ip1=ONOS1_ip,
488 port1=default_sw_port)
andrewonlab8d29f122014-10-22 17:15:04 -0400489
andrewonlab8790abb2014-11-06 13:51:54 -0500490 #Give enough time for metrics to propagate the
491 #assign controller event. Otherwise, these events may
492 #carry over to our measurements
493 time.sleep(10)
494
andrewonlab8d29f122014-10-22 17:15:04 -0400495 main.step("Verify switch is assigned correctly")
496 result_s1 = main.Mininet1.get_sw_controller(sw="s1")
andrewonlab393531a2014-10-27 18:36:26 -0400497 result_s2 = main.Mininet1.get_sw_controller(sw="s2")
498 if result_s1 == main.FALSE or result_s2 == main.FALSE:
andrewonlab8d29f122014-10-22 17:15:04 -0400499 main.log.info("Switch s1 was not assigned correctly")
500 assertion = main.FALSE
501 else:
502 main.log.info("Switch s1 was assigned correctly")
503
andrewonlab393531a2014-10-27 18:36:26 -0400504 port_up_device_to_ofp_list = []
505 port_up_graph_to_ofp_list = []
506 port_down_device_to_ofp_list = []
507 port_down_graph_to_ofp_list = []
508
andrewonlab8d29f122014-10-22 17:15:04 -0400509 for i in range(0, int(num_iter)):
510 main.step("Starting wireshark capture for port status down")
511 main.ONOS1.tshark_grep(tshark_port_status,
512 tshark_port_down)
513
514 time.sleep(10)
515
andrewonlab393531a2014-10-27 18:36:26 -0400516 #Disable interface that is connected to switch 2
517 main.step("Disable port: "+interface_config)
518 main.Mininet2.handle.sendline("sudo ifconfig "+
519 interface_config+" down")
andrewonlab8d29f122014-10-22 17:15:04 -0400520 main.Mininet2.handle.expect("\$")
andrewonlab8790abb2014-11-06 13:51:54 -0500521 time.sleep(10)
andrewonlab8d29f122014-10-22 17:15:04 -0400522
523 main.ONOS1.tshark_stop()
524 time.sleep(5)
525
526 #Copy tshark output file from ONOS to TestON instance
527 #/tmp directory
528 os.system("scp "+ONOS_user+"@"+ONOS1_ip+":"+
529 tshark_port_down+" /tmp/")
530
531 f_port_down = open(tshark_port_down, 'r')
andrewonlab393531a2014-10-27 18:36:26 -0400532 #Get first line of port down event from tshark
andrewonlab8d29f122014-10-22 17:15:04 -0400533 f_line = f_port_down.readline()
534 obj_down = f_line.split(" ")
535 if len(f_line) > 0:
andrewonlab393531a2014-10-27 18:36:26 -0400536 timestamp_begin_pt_down = int(float(obj_down[1]))*1000
537 main.log.info("Port down begin timestamp: "+
538 str(timestamp_begin_pt_down))
andrewonlab8d29f122014-10-22 17:15:04 -0400539 else:
540 main.log.info("Tshark output file returned unexpected"+
andrewonlab393531a2014-10-27 18:36:26 -0400541 " results: "+str(obj_down))
andrewonlab8d29f122014-10-22 17:15:04 -0400542 timestamp_begin_pt_down = 0
andrewonlab393531a2014-10-27 18:36:26 -0400543
544 f_port_down.close()
andrewonlab8d29f122014-10-22 17:15:04 -0400545
andrewonlab4e124482014-11-04 13:37:25 -0500546 main.log.info("TEST tshark obj: "+str(obj_down))
547
andrewonlab8d29f122014-10-22 17:15:04 -0400548 main.step("Obtain t1 by REST call")
andrewonlab393531a2014-10-27 18:36:26 -0400549 json_str_1 = main.ONOS1cli.topology_events_metrics()
550 json_str_2 = main.ONOS2cli.topology_events_metrics()
551 json_str_3 = main.ONOS3cli.topology_events_metrics()
andrewonlab8d29f122014-10-22 17:15:04 -0400552
andrewonlab4e124482014-11-04 13:37:25 -0500553 main.log.info("TEST json_str 1: "+str(json_str_1))
554
andrewonlab393531a2014-10-27 18:36:26 -0400555 json_obj_1 = json.loads(json_str_1)
556 json_obj_2 = json.loads(json_str_2)
557 json_obj_3 = json.loads(json_str_3)
andrewonlab8d29f122014-10-22 17:15:04 -0400558
andrewonlab393531a2014-10-27 18:36:26 -0400559 time.sleep(5)
560
561 #Obtain graph timestamp. This timestsamp captures
562 #the epoch time at which the topology graph was updated.
563 graph_timestamp_1 = \
564 json_obj_1[graphTimestamp]['value']
565 graph_timestamp_2 = \
566 json_obj_2[graphTimestamp]['value']
567 graph_timestamp_3 = \
568 json_obj_3[graphTimestamp]['value']
569
andrewonlab393531a2014-10-27 18:36:26 -0400570 #Obtain device timestamp. This timestamp captures
571 #the epoch time at which the device event happened
572 device_timestamp_1 = \
573 json_obj_1[deviceTimestamp]['value']
574 device_timestamp_2 = \
575 json_obj_2[deviceTimestamp]['value']
576 device_timestamp_3 = \
577 json_obj_3[deviceTimestamp]['value']
andrewonlab393531a2014-10-27 18:36:26 -0400578
579 #Get delta between graph event and OFP
580 pt_down_graph_to_ofp_1 = int(graph_timestamp_1) -\
581 int(timestamp_begin_pt_down)
582 pt_down_graph_to_ofp_2 = int(graph_timestamp_2) -\
583 int(timestamp_begin_pt_down)
584 pt_down_graph_to_ofp_3 = int(graph_timestamp_3) -\
585 int(timestamp_begin_pt_down)
586
587 #Get delta between device event and OFP
588 pt_down_device_to_ofp_1 = int(device_timestamp_1) -\
589 int(timestamp_begin_pt_down)
590 pt_down_device_to_ofp_2 = int(device_timestamp_2) -\
591 int(timestamp_begin_pt_down)
592 pt_down_device_to_ofp_3 = int(device_timestamp_3) -\
593 int(timestamp_begin_pt_down)
594
595 #Caluclate average across clusters
596 pt_down_graph_to_ofp_avg =\
597 (int(pt_down_graph_to_ofp_1) +
598 int(pt_down_graph_to_ofp_2) +
andrewonlab8790abb2014-11-06 13:51:54 -0500599 int(pt_down_graph_to_ofp_3)) / 3.0
andrewonlab393531a2014-10-27 18:36:26 -0400600 pt_down_device_to_ofp_avg = \
601 (int(pt_down_device_to_ofp_1) +
602 int(pt_down_device_to_ofp_2) +
andrewonlab8790abb2014-11-06 13:51:54 -0500603 int(pt_down_device_to_ofp_3)) / 3.0
andrewonlab393531a2014-10-27 18:36:26 -0400604
andrewonlab4e124482014-11-04 13:37:25 -0500605 if pt_down_graph_to_ofp_avg > 0.0 and \
andrewonlab393531a2014-10-27 18:36:26 -0400606 pt_down_graph_to_ofp_avg < 1000:
607 port_down_graph_to_ofp_list.append(
andrewonlababb11c32014-11-04 15:03:24 -0500608 pt_down_graph_to_ofp_avg)
609 main.log.info("Port down: graph to ofp avg: "+
610 str(pt_down_graph_to_ofp_avg) + " ms")
andrewonlab393531a2014-10-27 18:36:26 -0400611 else:
612 main.log.info("Average port down graph-to-ofp result" +
613 " exceeded the threshold: "+
614 str(pt_down_graph_to_ofp_avg))
615
andrewonlab3622beb2014-10-28 16:07:56 -0400616 if pt_down_device_to_ofp_avg > 0 and \
617 pt_down_device_to_ofp_avg < 1000:
618 port_down_device_to_ofp_list.append(
andrewonlababb11c32014-11-04 15:03:24 -0500619 pt_down_device_to_ofp_avg)
620 main.log.info("Port down: device to ofp avg: "+
621 str(pt_down_device_to_ofp_avg) + " ms")
andrewonlab3622beb2014-10-28 16:07:56 -0400622 else:
623 main.log.info("Average port down device-to-ofp result" +
624 " exceeded the threshold: "+
625 str(pt_down_device_to_ofp_avg))
626
andrewonlab8d29f122014-10-22 17:15:04 -0400627 #Port up events
628 main.step("Enable port and obtain timestamp")
629 main.step("Starting wireshark capture for port status up")
630 main.ONOS1.tshark_grep("OFP 130 Port Status", tshark_port_up)
andrewonlab8790abb2014-11-06 13:51:54 -0500631 time.sleep(5)
andrewonlab8d29f122014-10-22 17:15:04 -0400632
andrewonlab393531a2014-10-27 18:36:26 -0400633 main.Mininet2.handle.sendline("sudo ifconfig "+
634 interface_config+" up")
andrewonlab8d29f122014-10-22 17:15:04 -0400635 main.Mininet2.handle.expect("\$")
andrewonlab8790abb2014-11-06 13:51:54 -0500636 time.sleep(10)
637
638 main.ONOS1.tshark_stop()
andrewonlab8d29f122014-10-22 17:15:04 -0400639
640 os.system("scp "+ONOS_user+"@"+ONOS1_ip+":"+
641 tshark_port_up+" /tmp/")
642
643 f_port_up = open(tshark_port_up, 'r')
andrewonlab393531a2014-10-27 18:36:26 -0400644 f_line = f_port_up.readline()
andrewonlab8d29f122014-10-22 17:15:04 -0400645 obj_up = f_line.split(" ")
646 if len(f_line) > 0:
andrewonlab393531a2014-10-27 18:36:26 -0400647 timestamp_begin_pt_up = int(float(obj_up[1]))*1000
648 main.log.info("Port up begin timestamp: "+
649 str(timestamp_begin_pt_up))
andrewonlab8d29f122014-10-22 17:15:04 -0400650 else:
651 main.log.info("Tshark output file returned unexpected"+
652 " results.")
653 timestamp_begin_pt_up = 0
654
andrewonlab393531a2014-10-27 18:36:26 -0400655 f_port_up.close()
656
andrewonlab8d29f122014-10-22 17:15:04 -0400657 main.step("Obtain t1 by REST call")
andrewonlab393531a2014-10-27 18:36:26 -0400658 json_str_1 = main.ONOS1cli.topology_events_metrics()
659 json_str_2 = main.ONOS2cli.topology_events_metrics()
660 json_str_3 = main.ONOS3cli.topology_events_metrics()
andrewonlab8d29f122014-10-22 17:15:04 -0400661
andrewonlab393531a2014-10-27 18:36:26 -0400662 json_obj_1 = json.loads(json_str_1)
663 json_obj_2 = json.loads(json_str_2)
664 json_obj_3 = json.loads(json_str_3)
andrewonlab8d29f122014-10-22 17:15:04 -0400665
andrewonlab393531a2014-10-27 18:36:26 -0400666 #Obtain graph timestamp. This timestsamp captures
667 #the epoch time at which the topology graph was updated.
668 graph_timestamp_1 = \
669 json_obj_1[graphTimestamp]['value']
670 graph_timestamp_2 = \
671 json_obj_2[graphTimestamp]['value']
672 graph_timestamp_3 = \
673 json_obj_3[graphTimestamp]['value']
674
675 #Obtain device timestamp. This timestamp captures
676 #the epoch time at which the device event happened
677 device_timestamp_1 = \
678 json_obj_1[deviceTimestamp]['value']
679 device_timestamp_2 = \
680 json_obj_2[deviceTimestamp]['value']
681 device_timestamp_3 = \
682 json_obj_3[deviceTimestamp]['value']
683
684 #Get delta between graph event and OFP
685 pt_up_graph_to_ofp_1 = int(graph_timestamp_1) -\
andrewonlab8d29f122014-10-22 17:15:04 -0400686 int(timestamp_begin_pt_up)
andrewonlab393531a2014-10-27 18:36:26 -0400687 pt_up_graph_to_ofp_2 = int(graph_timestamp_2) -\
andrewonlab8d29f122014-10-22 17:15:04 -0400688 int(timestamp_begin_pt_up)
andrewonlab393531a2014-10-27 18:36:26 -0400689 pt_up_graph_to_ofp_3 = int(graph_timestamp_3) -\
690 int(timestamp_begin_pt_up)
691
692 #Get delta between device event and OFP
693 pt_up_device_to_ofp_1 = int(device_timestamp_1) -\
694 int(timestamp_begin_pt_up)
695 pt_up_device_to_ofp_2 = int(device_timestamp_2) -\
696 int(timestamp_begin_pt_up)
697 pt_up_device_to_ofp_3 = int(device_timestamp_3) -\
andrewonlab8d29f122014-10-22 17:15:04 -0400698 int(timestamp_begin_pt_up)
andrewonlab3622beb2014-10-28 16:07:56 -0400699
700 pt_up_graph_to_ofp_avg = \
701 (float(pt_up_graph_to_ofp_1) +
702 float(pt_up_graph_to_ofp_2) +
703 float(pt_up_graph_to_ofp_3)) / 3
704
705 pt_up_device_to_ofp_avg = \
706 (float(pt_up_device_to_ofp_1) +
707 float(pt_up_device_to_ofp_2) +
708 float(pt_up_device_to_ofp_3)) / 3
709
710 if pt_up_graph_to_ofp_avg > 0 and \
711 pt_up_graph_to_ofp_avg < 1000:
712 port_up_graph_to_ofp_list.append(
713 pt_up_graph_to_ofp_avg)
andrewonlababb11c32014-11-04 15:03:24 -0500714 main.log.info("Port down: graph to ofp avg: "+
715 str(pt_up_graph_to_ofp_avg) + " ms")
andrewonlab3622beb2014-10-28 16:07:56 -0400716 else:
717 main.log.info("Average port up graph-to-ofp result"+
718 " exceeded the threshold: "+
719 str(pt_up_graph_to_ofp_avg))
720
721 if pt_up_device_to_ofp_avg > 0 and \
722 pt_up_device_to_ofp_avg < 1000:
723 port_up_device_to_ofp_list.append(
724 pt_up_device_to_ofp_avg)
andrewonlababb11c32014-11-04 15:03:24 -0500725 main.log.info("Port up: device to ofp avg: "+
726 str(pt_up_device_to_ofp_avg) + " ms")
andrewonlab3622beb2014-10-28 16:07:56 -0400727 else:
andrewonlababb11c32014-11-04 15:03:24 -0500728 main.log.info("Average port up device-to-ofp result"+
andrewonlab3622beb2014-10-28 16:07:56 -0400729 " exceeded the threshold: "+
730 str(pt_up_device_to_ofp_avg))
andrewonlab8d29f122014-10-22 17:15:04 -0400731
andrewonlab3622beb2014-10-28 16:07:56 -0400732 #END ITERATION FOR LOOP
andrewonlab8790abb2014-11-06 13:51:54 -0500733
734 #Check all list for latency existence and set assertion
735 if (port_down_graph_to_ofp_list and port_down_device_to_ofp_list\
736 and port_up_graph_to_ofp_list and port_up_device_to_ofp_list):
737 assertion = main.TRUE
738
andrewonlababb11c32014-11-04 15:03:24 -0500739 #Calculate and report latency measurements
andrewonlab3622beb2014-10-28 16:07:56 -0400740 port_down_graph_to_ofp_min = min(port_down_graph_to_ofp_list)
741 port_down_graph_to_ofp_max = max(port_down_graph_to_ofp_list)
742 port_down_graph_to_ofp_avg = \
743 (sum(port_down_graph_to_ofp_list) /
744 len(port_down_graph_to_ofp_list))
745
andrewonlababb11c32014-11-04 15:03:24 -0500746 main.log.report("Port down graph-to-ofp Min: "+
andrewonlab8790abb2014-11-06 13:51:54 -0500747 str(port_down_graph_to_ofp_min)+" ms Max: "+
748 str(port_down_graph_to_ofp_max)+" ms Avg: "+
andrewonlababb11c32014-11-04 15:03:24 -0500749 str(port_down_graph_to_ofp_avg))
750
751 port_down_device_to_ofp_min = min(port_down_device_to_ofp_list)
752 port_down_device_to_ofp_max = max(port_down_device_to_ofp_list)
753 port_down_device_to_ofp_avg = \
754 (sum(port_down_device_to_ofp_list) /\
755 len(port_down_device_to_ofp_list))
756
757 main.log.report("Port down device-to-ofp Min: "+
andrewonlab8790abb2014-11-06 13:51:54 -0500758 str(port_down_device_to_ofp_min)+" ms Max: "+
759 str(port_down_device_to_ofp_max)+" ms Avg: "+
andrewonlababb11c32014-11-04 15:03:24 -0500760 str(port_down_device_to_ofp_avg))
761
762 port_up_graph_to_ofp_min = min(port_up_graph_to_ofp_list)
763 port_up_graph_to_ofp_max = max(port_up_graph_to_ofp_list)
764 port_up_graph_to_ofp_avg = \
765 (sum(port_up_graph_to_ofp_list) /\
766 len(port_up_graph_to_ofp_list))
andrewonlab8790abb2014-11-06 13:51:54 -0500767
768 main.log.report("Port up graph-to-ofp Min: "+
769 str(port_up_graph_to_ofp_min)+" ms Max: "+
770 str(port_up_graph_to_ofp_max)+" ms Avg: "+
771 str(port_up_graph_to_ofp_avg))
772
773 port_up_device_to_ofp_min = min(port_up_device_to_ofp_list)
774 port_up_device_to_ofp_max = max(port_up_device_to_ofp_list)
775 port_up_device_to_ofp_avg = \
776 (sum(port_up_device_to_ofp_list) /\
777 len(port_up_device_to_ofp_list))
778
779 main.log.report("Port up device-to-ofp Min: "+
780 str(port_up_device_to_ofp_min)+" ms Max: "+
781 str(port_up_device_to_ofp_max)+" ms Avg: "+
782 str(port_up_device_to_ofp_avg))
783
784 utilities.assert_equals(expect=main.TRUE, actual=assertion,
785 onpass="Port discovery latency calculation successful",
786 onfail="Port discovery test failed")
andrewonlababb11c32014-11-04 15:03:24 -0500787
andrewonlab3622beb2014-10-28 16:07:56 -0400788 def CASE4(self, main):
789 '''
790 Link down event using loss rate 100%
andrewonlab53b641c2014-10-31 19:44:44 -0400791
792 Important:
793 Use a simple 2 switch topology with 1 link between
794 the two switches. Ensure that mac addresses of the
795 switches are 1 / 2 respectively
andrewonlab3622beb2014-10-28 16:07:56 -0400796 '''
797 import time
798 import subprocess
799 import os
800 import requests
801 import json
802
803 ONOS1_ip = main.params['CTRL']['ip1']
804 ONOS2_ip = main.params['CTRL']['ip2']
805 ONOS3_ip = main.params['CTRL']['ip3']
806 ONOS_user = main.params['CTRL']['user']
807
808 default_sw_port = main.params['CTRL']['port1']
809
810 #Number of iterations of case
811 num_iter = main.params['TEST']['numIter']
812
813 #Timestamp 'keys' for json metrics output.
814 #These are subject to change, hence moved into params
815 deviceTimestamp = main.params['JSON']['deviceTimestamp']
816 linkTimestamp = main.params['JSON']['linkTimestamp']
andrewonlab53b641c2014-10-31 19:44:44 -0400817 graphTimestamp = main.params['JSON']['graphTimestamp']
818
andrewonlab3622beb2014-10-28 16:07:56 -0400819 assertion = main.TRUE
820 #Link event timestamp to system time list
821 link_down_link_to_system_list = []
822 link_up_link_to_system_list = []
823 #Graph event timestamp to system time list
824 link_down_graph_to_system_list = []
825 link_up_graph_to_system_list = []
826
827 main.log.report("Add / remove link latency between "+
828 "two switches")
829
830 main.step("Assign all switches")
831 main.Mininet1.assign_sw_controller(sw="1",
832 ip1=ONOS1_ip, port1=default_sw_port)
833 main.Mininet1.assign_sw_controller(sw="2",
834 ip1=ONOS1_ip, port1=default_sw_port)
835
836 main.step("Verifying switch assignment")
837 result_s1 = main.Mininet1.get_sw_controller(sw="s1")
838 result_s2 = main.Mininet1.get_sw_controller(sw="s2")
andrewonlab3622beb2014-10-28 16:07:56 -0400839
840 #Allow time for events to finish before taking measurements
841 time.sleep(10)
842
andrewonlababb11c32014-11-04 15:03:24 -0500843 link_down1 = False
844 link_down2 = False
845 link_down3 = False
andrewonlab3622beb2014-10-28 16:07:56 -0400846 #Start iteration of link event test
847 for i in range(0, int(num_iter)):
848 main.step("Getting initial system time as t0")
andrewonlab8d29f122014-10-22 17:15:04 -0400849
andrewonlab3622beb2014-10-28 16:07:56 -0400850 timestamp_link_down_t0 = time.time() * 1000
851 #Link down is simulated by 100% loss rate using traffic
852 #control command
853 main.Mininet1.handle.sendline(
854 "sh tc qdisc add dev s1-eth1 root netem loss 100%")
855
andrewonlab53b641c2014-10-31 19:44:44 -0400856 #TODO: Iterate through 'links' command to verify that
andrewonlababb11c32014-11-04 15:03:24 -0500857 # link s1 -> s2 went down (loop timeout 30 seconds)
858 # on all 3 ONOS instances
andrewonlab53b641c2014-10-31 19:44:44 -0400859 main.log.info("Checking ONOS for link update")
860 loop_count = 0
andrewonlababb11c32014-11-04 15:03:24 -0500861 while( not (link_down1 and link_down2 and link_down3)\
862 and loop_count < 30 ):
863 json_str1 = main.ONOS1cli.links()
864 json_str2 = main.ONOS2cli.links()
865 json_str3 = main.ONOS3cli.links()
866
867 if not (json_str1 and json_str2 and json_str3):
868 main.log.error("CLI command returned error ")
andrewonlab53b641c2014-10-31 19:44:44 -0400869 break
870 else:
andrewonlababb11c32014-11-04 15:03:24 -0500871 json_obj1 = json.loads(json_str1)
872 json_obj2 = json.loads(json_str2)
873 json_obj3 = json.loads(json_str3)
874 for obj1 in json_obj1:
875 if '01' not in obj1['src']['device']:
876 link_down1 = True
andrewonlab53b641c2014-10-31 19:44:44 -0400877 main.log.report("Link down from "+
andrewonlababb11c32014-11-04 15:03:24 -0500878 "s1 -> s2 on ONOS1 detected")
879 for obj2 in json_obj2:
880 if '01' not in obj2['src']['device']:
881 link_down2 = True
882 main.log.report("Link down from "+
883 "s1 -> s2 on ONOS2 detected")
884 for obj3 in json_obj3:
885 if '01' not in obj3['src']['device']:
886 link_down3 = True
887 main.log.report("Link down from "+
888 "s1 -> s2 on ONOS3 detected")
889
andrewonlab53b641c2014-10-31 19:44:44 -0400890 loop_count += 1
andrewonlababb11c32014-11-04 15:03:24 -0500891 #If CLI doesn't like the continuous requests
892 #and exits in this loop, increase the sleep here.
893 #Consequently, while loop timeout will increase
andrewonlab53b641c2014-10-31 19:44:44 -0400894 time.sleep(1)
895
896 #Give time for metrics measurement to catch up
andrewonlababb11c32014-11-04 15:03:24 -0500897 #NOTE: May need to be configured more accurately
andrewonlab53b641c2014-10-31 19:44:44 -0400898 time.sleep(10)
andrewonlababb11c32014-11-04 15:03:24 -0500899 #If we exited the while loop and link down 1,2,3 are still
andrewonlab53b641c2014-10-31 19:44:44 -0400900 #false, then ONOS has failed to discover link down event
andrewonlababb11c32014-11-04 15:03:24 -0500901 if not (link_down1 and link_down2 and link_down3):
andrewonlab53b641c2014-10-31 19:44:44 -0400902 main.log.info("Link down discovery failed")
903
904 link_down_lat_graph1 = 0
905 link_down_lat_graph2 = 0
906 link_down_lat_graph3 = 0
907 link_down_lat_device1 = 0
908 link_down_lat_device2 = 0
909 link_down_lat_device3 = 0
910
911 assertion = main.FALSE
912 else:
913 json_topo_metrics_1 =\
914 main.ONOS1cli.topology_events_metrics()
915 json_topo_metrics_2 =\
916 main.ONOS2cli.topology_events_metrics()
917 json_topo_metrics_3 =\
918 main.ONOS3cli.topology_events_metrics()
919 json_topo_metrics_1 = json.loads(json_topo_metrics_1)
920 json_topo_metrics_2 = json.loads(json_topo_metrics_2)
921 json_topo_metrics_3 = json.loads(json_topo_metrics_3)
922
923 main.log.info("Obtaining graph and device timestamp")
924 graph_timestamp_1 = \
925 json_topo_metrics_1[graphTimestamp]['value']
926 graph_timestamp_2 = \
927 json_topo_metrics_2[graphTimestamp]['value']
928 graph_timestamp_3 = \
929 json_topo_metrics_3[graphTimestamp]['value']
930
931 link_timestamp_1 = \
932 json_topo_metrics_1[linkTimestamp]['value']
933 link_timestamp_2 = \
934 json_topo_metrics_2[linkTimestamp]['value']
935 link_timestamp_3 = \
936 json_topo_metrics_3[linkTimestamp]['value']
937
938 if graph_timestamp_1 and graph_timestamp_2 and\
939 graph_timestamp_3 and link_timestamp_1 and\
940 link_timestamp_2 and link_timestamp_3:
941 link_down_lat_graph1 = int(graph_timestamp_1) -\
942 timestamp_link_down_t0
943 link_down_lat_graph2 = int(graph_timestamp_2) -\
944 timestamp_link_down_t0
945 link_down_lat_graph3 = int(graph_timestamp_3) -\
946 timestamp_link_down_t0
947
948 link_down_lat_link1 = int(link_timestamp_1) -\
949 timestamp_link_down_t0
950 link_down_lat_link2 = int(link_timestamp_2) -\
951 timestamp_link_down_t0
952 link_down_lat_link3 = int(link_timestamp_3) -\
953 timestamp_link_down_t0
954 else:
955 main.log.error("There was an error calculating"+
956 " the delta for link down event")
957 link_down_lat_graph1 = 0
958 link_down_lat_graph2 = 0
959 link_down_lat_graph3 = 0
960
961 link_down_lat_device1 = 0
962 link_down_lat_device2 = 0
963 link_down_lat_device3 = 0
964
andrewonlab4e124482014-11-04 13:37:25 -0500965 main.log.report("Link down latency ONOS1 iteration "+
966 str(i)+" (end-to-end): "+
andrewonlababb11c32014-11-04 15:03:24 -0500967 str(link_down_lat_graph1)+" ms")
andrewonlab4e124482014-11-04 13:37:25 -0500968 main.log.report("Link down latency ONOS2 iteration "+
969 str(i)+" (end-to-end): "+
andrewonlababb11c32014-11-04 15:03:24 -0500970 str(link_down_lat_graph2)+" ms")
andrewonlab4e124482014-11-04 13:37:25 -0500971 main.log.report("Link down latency ONOS3 iteration "+
972 str(i)+" (end-to-end): "+
andrewonlababb11c32014-11-04 15:03:24 -0500973 str(link_down_lat_graph3)+" ms")
andrewonlab4e124482014-11-04 13:37:25 -0500974
975 main.log.report("Link down latency ONOS1 iteration "+
976 str(i)+" (link-event-to-system-timestamp): "+
andrewonlababb11c32014-11-04 15:03:24 -0500977 str(link_down_lat_link1)+" ms")
andrewonlab4e124482014-11-04 13:37:25 -0500978 main.log.report("Link down latency ONOS2 iteration "+
979 str(i)+" (link-event-to-system-timestamp): "+
andrewonlababb11c32014-11-04 15:03:24 -0500980 str(link_down_lat_link2)+" ms")
andrewonlab4e124482014-11-04 13:37:25 -0500981 main.log.report("Link down latency ONOS3 iteration "+
982 str(i)+" (link-event-to-system-timestamp): "+
983 str(link_down_lat_link3))
984
985 #Calculate avg of node calculations
986 link_down_lat_graph_avg =\
andrewonlababb11c32014-11-04 15:03:24 -0500987 (link_down_lat_graph1 +
988 link_down_lat_graph2 +
989 link_down_lat_graph3) / 3.0
andrewonlab4e124482014-11-04 13:37:25 -0500990 link_down_lat_link_avg =\
andrewonlababb11c32014-11-04 15:03:24 -0500991 (link_down_lat_link1 +
992 link_down_lat_link2 +
993 link_down_lat_link3) / 3.0
andrewonlab53b641c2014-10-31 19:44:44 -0400994
andrewonlab4e124482014-11-04 13:37:25 -0500995 #Set threshold and append latency to list
996 if link_down_lat_graph_avg > 0.0 and\
997 link_down_lat_graph_avg < 30000:
998 link_down_graph_to_system_list.append(
999 link_down_lat_graph_avg)
andrewonlab8790abb2014-11-06 13:51:54 -05001000 else:
1001 main.log.info("Link down latency exceeded threshold")
1002 main.log.info("Results for iteration "+str(i)+
1003 "have been omitted")
andrewonlab4e124482014-11-04 13:37:25 -05001004 if link_down_lat_link_avg > 0.0 and\
1005 link_down_lat_link_avg < 30000:
1006 link_down_link_to_system_list.append(
1007 link_down_lat_link_avg)
andrewonlab8790abb2014-11-06 13:51:54 -05001008 else:
1009 main.log.info("Link down latency exceeded threshold")
1010 main.log.info("Results for iteration "+str(i)+
1011 "have been omitted")
andrewonlab53b641c2014-10-31 19:44:44 -04001012
1013 #NOTE: To remove loss rate and measure latency:
1014 # 'sh tc qdisc del dev s1-eth1 root'
andrewonlababb11c32014-11-04 15:03:24 -05001015 timestamp_link_up_t0 = time.time() * 1000
andrewonlab53b641c2014-10-31 19:44:44 -04001016 main.Mininet1.handle.sendline("sh tc qdisc del dev "+
1017 "s1-eth1 root")
1018 main.Mininet1.handle.expect("mininet>")
andrewonlababb11c32014-11-04 15:03:24 -05001019
1020 main.log.info("Checking ONOS for link update")
1021
1022 link_down1 = True
1023 link_down2 = True
1024 link_down3 = True
1025 loop_count = 0
1026 while( (link_down1 and link_down2 and link_down3)\
1027 and loop_count < 30 ):
1028 json_str1 = main.ONOS1cli.links()
1029 json_str2 = main.ONOS2cli.links()
1030 json_str3 = main.ONOS3cli.links()
1031 if not (json_str1 and json_str2 and json_str3):
1032 main.log.error("CLI command returned error ")
1033 break
1034 else:
1035 json_obj1 = json.loads(json_str1)
1036 json_obj2 = json.loads(json_str2)
1037 json_obj3 = json.loads(json_str3)
1038
1039 for obj1 in json_obj1:
1040 if '01' in obj1['src']['device']:
1041 link_down1 = False
1042 main.log.report("Link up from "+
1043 "s1 -> s2 on ONOS1 detected")
1044 for obj2 in json_obj2:
1045 if '01' in obj2['src']['device']:
1046 link_down2 = False
1047 main.log.report("Link up from "+
1048 "s1 -> s2 on ONOS2 detected")
1049 for obj3 in json_obj3:
1050 if '01' in obj3['src']['device']:
1051 link_down3 = False
1052 main.log.report("Link up from "+
1053 "s1 -> s2 on ONOS3 detected")
1054
1055 loop_count += 1
1056 time.sleep(1)
1057
1058 if (link_down1 and link_down2 and link_down3):
1059 main.log.info("Link up discovery failed")
1060
1061 link_up_lat_graph1 = 0
1062 link_up_lat_graph2 = 0
1063 link_up_lat_graph3 = 0
1064 link_up_lat_device1 = 0
1065 link_up_lat_device2 = 0
1066 link_up_lat_device3 = 0
1067
1068 assertion = main.FALSE
1069 else:
1070 json_topo_metrics_1 =\
1071 main.ONOS1cli.topology_events_metrics()
1072 json_topo_metrics_2 =\
1073 main.ONOS2cli.topology_events_metrics()
1074 json_topo_metrics_3 =\
1075 main.ONOS3cli.topology_events_metrics()
1076 json_topo_metrics_1 = json.loads(json_topo_metrics_1)
1077 json_topo_metrics_2 = json.loads(json_topo_metrics_2)
1078 json_topo_metrics_3 = json.loads(json_topo_metrics_3)
1079
1080 main.log.info("Obtaining graph and device timestamp")
1081 graph_timestamp_1 = \
1082 json_topo_metrics_1[graphTimestamp]['value']
1083 graph_timestamp_2 = \
1084 json_topo_metrics_2[graphTimestamp]['value']
1085 graph_timestamp_3 = \
1086 json_topo_metrics_3[graphTimestamp]['value']
1087
1088 link_timestamp_1 = \
1089 json_topo_metrics_1[linkTimestamp]['value']
1090 link_timestamp_2 = \
1091 json_topo_metrics_2[linkTimestamp]['value']
1092 link_timestamp_3 = \
1093 json_topo_metrics_3[linkTimestamp]['value']
1094
1095 if graph_timestamp_1 and graph_timestamp_2 and\
1096 graph_timestamp_3 and link_timestamp_1 and\
1097 link_timestamp_2 and link_timestamp_3:
1098 link_up_lat_graph1 = int(graph_timestamp_1) -\
1099 timestamp_link_up_t0
1100 link_up_lat_graph2 = int(graph_timestamp_2) -\
1101 timestamp_link_up_t0
1102 link_up_lat_graph3 = int(graph_timestamp_3) -\
1103 timestamp_link_up_t0
1104
1105 link_up_lat_link1 = int(link_timestamp_1) -\
1106 timestamp_link_up_t0
1107 link_up_lat_link2 = int(link_timestamp_2) -\
1108 timestamp_link_up_t0
1109 link_up_lat_link3 = int(link_timestamp_3) -\
1110 timestamp_link_up_t0
1111 else:
1112 main.log.error("There was an error calculating"+
1113 " the delta for link down event")
1114 link_up_lat_graph1 = 0
1115 link_up_lat_graph2 = 0
1116 link_up_lat_graph3 = 0
1117
1118 link_up_lat_device1 = 0
1119 link_up_lat_device2 = 0
1120 link_up_lat_device3 = 0
1121
1122 main.log.info("Link up latency ONOS1 iteration "+
1123 str(i)+" (end-to-end): "+
1124 str(link_up_lat_graph1)+" ms")
1125 main.log.info("Link up latency ONOS2 iteration "+
1126 str(i)+" (end-to-end): "+
1127 str(link_up_lat_graph2)+" ms")
1128 main.log.info("Link up latency ONOS3 iteration "+
1129 str(i)+" (end-to-end): "+
1130 str(link_up_lat_graph3)+" ms")
1131
1132 main.log.info("Link up latency ONOS1 iteration "+
1133 str(i)+" (link-event-to-system-timestamp): "+
1134 str(link_up_lat_link1)+" ms")
1135 main.log.info("Link up latency ONOS2 iteration "+
1136 str(i)+" (link-event-to-system-timestamp): "+
1137 str(link_up_lat_link2)+" ms")
1138 main.log.info("Link up latency ONOS3 iteration "+
1139 str(i)+" (link-event-to-system-timestamp): "+
1140 str(link_up_lat_link3))
1141
1142 #Calculate avg of node calculations
1143 link_up_lat_graph_avg =\
1144 (link_up_lat_graph1 +
1145 link_up_lat_graph2 +
1146 link_up_lat_graph3) / 3.0
1147 link_up_lat_link_avg =\
1148 (link_up_lat_link1 +
1149 link_up_lat_link2 +
1150 link_up_lat_link3) / 3.0
1151
1152 #Set threshold and append latency to list
1153 if link_up_lat_graph_avg > 0.0 and\
1154 link_up_lat_graph_avg < 30000:
1155 link_up_graph_to_system_list.append(
1156 link_up_lat_graph_avg)
andrewonlab8790abb2014-11-06 13:51:54 -05001157 else:
1158 main.log.info("Link up latency exceeded threshold")
1159 main.log.info("Results for iteration "+str(i)+
1160 "have been omitted")
andrewonlababb11c32014-11-04 15:03:24 -05001161 if link_up_lat_link_avg > 0.0 and\
1162 link_up_lat_link_avg < 30000:
1163 link_up_link_to_system_list.append(
1164 link_up_lat_link_avg)
andrewonlab8790abb2014-11-06 13:51:54 -05001165 else:
1166 main.log.info("Link up latency exceeded threshold")
1167 main.log.info("Results for iteration "+str(i)+
1168 "have been omitted")
andrewonlab53b641c2014-10-31 19:44:44 -04001169
andrewonlab4e124482014-11-04 13:37:25 -05001170 #Calculate min, max, avg of list and report
1171 link_down_min = min(link_down_graph_to_system_list)
1172 link_down_max = max(link_down_graph_to_system_list)
1173 link_down_avg = sum(link_down_graph_to_system_list) / \
1174 len(link_down_graph_to_system_list)
andrewonlababb11c32014-11-04 15:03:24 -05001175 link_up_min = min(link_up_graph_to_system_list)
1176 link_up_max = max(link_up_graph_to_system_list)
1177 link_up_avg = sum(link_up_graph_to_system_list) / \
1178 len(link_up_graph_to_system_list)
1179
1180 main.log.report("Link down latency - Min: "+
1181 str(link_down_min)+"ms Max: "+
1182 str(link_down_max)+"ms Avg: "+
1183 str(link_down_avg)+"ms")
1184 main.log.report("Link up latency - Min: "+
1185 str(link_up_min)+"ms Max: "+
1186 str(link_up_max)+"ms Avg: "+
1187 str(link_up_avg)+"ms")
andrewonlab4e124482014-11-04 13:37:25 -05001188
andrewonlab8790abb2014-11-06 13:51:54 -05001189 utilities.assert_equals(expect=main.TRUE, actual=assertion,
1190 onpass="Link discovery latency calculation successful",
1191 onfail="Link discovery latency case failed")
1192
andrewonlabb54b85b2014-10-28 18:43:57 -04001193 def CASE5(self, main):
1194 '''
1195 100 Switch discovery latency
1196
1197 Important:
andrewonlab16ce4852014-10-30 13:41:09 -04001198 This test case can be potentially dangerous if
1199 your machine has previously set iptables rules.
1200 One of the steps of the test case will flush
1201 all existing iptables rules.
andrewonlab8790abb2014-11-06 13:51:54 -05001202 Note:
1203 You can specify the number of switches in the
1204 params file to adjust the switch discovery size
1205 (and specify the corresponding topology in Mininet1
1206 .topo file)
andrewonlabb54b85b2014-10-28 18:43:57 -04001207 '''
1208 import time
1209 import subprocess
1210 import os
1211 import requests
1212 import json
1213
1214 ONOS1_ip = main.params['CTRL']['ip1']
1215 ONOS2_ip = main.params['CTRL']['ip2']
1216 ONOS3_ip = main.params['CTRL']['ip3']
1217 MN1_ip = main.params['MN']['ip1']
1218 ONOS_user = main.params['CTRL']['user']
1219
1220 default_sw_port = main.params['CTRL']['port1']
1221
1222 #Number of iterations of case
1223 num_iter = main.params['TEST']['numIter']
andrewonlab16ce4852014-10-30 13:41:09 -04001224 num_sw = main.params['TEST']['numSwitch']
1225
andrewonlabb54b85b2014-10-28 18:43:57 -04001226 #Timestamp 'keys' for json metrics output.
1227 #These are subject to change, hence moved into params
1228 deviceTimestamp = main.params['JSON']['deviceTimestamp']
andrewonlab16ce4852014-10-30 13:41:09 -04001229 graphTimestamp = main.params['JSON']['graphTimestamp']
1230
andrewonlab53b641c2014-10-31 19:44:44 -04001231 tshark_ofp_output = "/tmp/tshark_ofp_"+num_sw+"sw.txt"
1232 tshark_tcp_output = "/tmp/tshark_tcp_"+num_sw+"sw.txt"
1233
1234 tshark_ofp_result_list = []
1235 tshark_tcp_result_list = []
andrewonlabb54b85b2014-10-28 18:43:57 -04001236
andrewonlab16ce4852014-10-30 13:41:09 -04001237 main.case(num_sw+" Switch discovery latency")
andrewonlabb54b85b2014-10-28 18:43:57 -04001238 main.step("Assigning all switches to ONOS1")
andrewonlab16ce4852014-10-30 13:41:09 -04001239 for i in range(1, int(num_sw)+1):
andrewonlabb54b85b2014-10-28 18:43:57 -04001240 main.Mininet1.assign_sw_controller(
1241 sw=str(i),
1242 ip1=ONOS1_ip,
1243 port1=default_sw_port)
andrewonlab16ce4852014-10-30 13:41:09 -04001244
andrewonlabb54b85b2014-10-28 18:43:57 -04001245 #Ensure that nodes are configured with ptpd
andrewonlab16ce4852014-10-30 13:41:09 -04001246 #Just a warning message
1247 main.log.info("Please check ptpd configuration to ensure"+\
1248 " All nodes' system times are in sync")
1249 time.sleep(5)
andrewonlabb54b85b2014-10-28 18:43:57 -04001250
1251 for i in range(0, int(num_iter)):
andrewonlab8d29f122014-10-22 17:15:04 -04001252
andrewonlabb54b85b2014-10-28 18:43:57 -04001253 main.step("Set iptables rule to block incoming sw connections")
1254 #Set iptables rule to block incoming switch connections
andrewonlab53b641c2014-10-31 19:44:44 -04001255 #The rule description is as follows:
1256 # Append to INPUT rule,
1257 # behavior DROP that matches following:
1258 # * packet type: tcp
1259 # * source IP: MN1_ip
1260 # * destination PORT: 6633
andrewonlabb54b85b2014-10-28 18:43:57 -04001261 main.ONOS1.handle.sendline(
andrewonlab16ce4852014-10-30 13:41:09 -04001262 "sudo iptables -A INPUT -p tcp -s "+MN1_ip+
andrewonlabb54b85b2014-10-28 18:43:57 -04001263 " --dport "+default_sw_port+" -j DROP")
1264 main.ONOS1.handle.expect("\$")
andrewonlab53b641c2014-10-31 19:44:44 -04001265 # Append to OUTPUT rule,
1266 # behavior DROP that matches following:
1267 # * packet type: tcp
1268 # * source IP: MN1_ip
1269 # * destination PORT: 6633
1270 main.ONOS1.handle.sendline(
1271 "sudo iptables -A OUTPUT -p tcp -s "+MN1_ip+
1272 " --dport "+default_sw_port+" -j DROP")
1273 main.ONOS1.handle.expect("\$")
andrewonlabb54b85b2014-10-28 18:43:57 -04001274 #Give time to allow rule to take effect
andrewonlab8790abb2014-11-06 13:51:54 -05001275 #NOTE: Sleep period may need to be configured
1276 # based on the number of switches in the topology
andrewonlab16ce4852014-10-30 13:41:09 -04001277 main.log.info("Please wait for switch connection to "+
1278 "time out")
1279 time.sleep(60)
1280
1281 #Gather vendor OFP with tshark
1282 main.ONOS1.tshark_grep("OFP 86 Vendor",
1283 tshark_ofp_output)
andrewonlab53b641c2014-10-31 19:44:44 -04001284 main.ONOS1.tshark_grep("TCP 74 ",
1285 tshark_tcp_output)
andrewonlabb54b85b2014-10-28 18:43:57 -04001286
andrewonlab16ce4852014-10-30 13:41:09 -04001287 #NOTE: Remove all iptables rule quickly (flush)
andrewonlabb54b85b2014-10-28 18:43:57 -04001288 # Before removal, obtain TestON timestamp at which
andrewonlab16ce4852014-10-30 13:41:09 -04001289 # removal took place
1290 # (ensuring nodes are configured via ptp)
andrewonlabb54b85b2014-10-28 18:43:57 -04001291 # sudo iptables -F
andrewonlab16ce4852014-10-30 13:41:09 -04001292
1293 t0_system = time.time() * 1000
1294 main.ONOS1.handle.sendline(
1295 "sudo iptables -F")
andrewonlabb54b85b2014-10-28 18:43:57 -04001296
andrewonlab16ce4852014-10-30 13:41:09 -04001297 #Counter to track loop count
1298 counter_loop = 0
1299 counter_avail1 = 0
1300 counter_avail2 = 0
1301 counter_avail3 = 0
1302 onos1_dev = False
1303 onos2_dev = False
1304 onos3_dev = False
1305 while counter_loop < 60:
1306 #Continue to check devices for all device
1307 #availability. When all devices in all 3
1308 #ONOS instances indicate that devices are available
1309 #obtain graph event timestamp for t1.
1310 device_str_obj1 = main.ONOS1cli.devices()
1311 device_str_obj2 = main.ONOS2cli.devices()
1312 device_str_obj3 = main.ONOS3cli.devices()
1313
1314 device_json1 = json.loads(device_str_obj1)
1315 device_json2 = json.loads(device_str_obj2)
1316 device_json3 = json.loads(device_str_obj3)
1317
1318 for device1 in device_json1:
1319 if device1['available'] == True:
1320 counter_avail1 += 1
1321 if counter_avail1 == int(num_sw):
1322 onos1_dev = True
1323 main.log.info("All devices have been "+
1324 "discovered on ONOS1")
1325 else:
1326 counter_avail1 = 0
1327 for device2 in device_json2:
1328 if device2['available'] == True:
1329 counter_avail2 += 1
1330 if counter_avail2 == int(num_sw):
1331 onos2_dev = True
1332 main.log.info("All devices have been "+
1333 "discovered on ONOS2")
1334 else:
1335 counter_avail2 = 0
1336 for device3 in device_json3:
1337 if device3['available'] == True:
1338 counter_avail3 += 1
1339 if counter_avail3 == int(num_sw):
1340 onos3_dev = True
1341 main.log.info("All devices have been "+
1342 "discovered on ONOS3")
1343 else:
1344 counter_avail3 = 0
1345
1346 if onos1_dev and onos2_dev and onos3_dev:
1347 main.log.info("All devices have been discovered "+
1348 "on all ONOS instances")
1349 json_str_topology_metrics_1 =\
1350 main.ONOS1cli.topology_events_metrics()
1351 json_str_topology_metrics_2 =\
1352 main.ONOS2cli.topology_events_metrics()
1353 json_str_topology_metrics_3 =\
1354 main.ONOS3cli.topology_events_metrics()
andrewonlab53b641c2014-10-31 19:44:44 -04001355
1356 #Exit while loop if all devices discovered
andrewonlab16ce4852014-10-30 13:41:09 -04001357 break
1358
1359 counter_loop += 1
1360 #Give some time in between CLI calls
1361 #(will not affect measurement)
1362 time.sleep(3)
1363
1364 main.ONOS1.tshark_stop()
1365
1366 os.system("scp "+ONOS_user+"@"+ONOS1_ip+":"+
1367 tshark_ofp_output+" /tmp/")
andrewonlab53b641c2014-10-31 19:44:44 -04001368 os.system("scp "+ONOS_user+"@"+ONOS1_ip+":"+
1369 tshark_tcp_output+" /tmp/")
andrewonlab16ce4852014-10-30 13:41:09 -04001370 ofp_file = open(tshark_ofp_output, 'r')
1371
1372 #The following is for information purpose only.
1373 #TODO: Automate OFP output analysis
1374 main.log.info("Tshark OFP Vendor output: ")
1375 for line in ofp_file:
andrewonlab53b641c2014-10-31 19:44:44 -04001376 tshark_ofp_result_list.append(line)
andrewonlab16ce4852014-10-30 13:41:09 -04001377 main.log.info(line)
1378
andrewonlab53b641c2014-10-31 19:44:44 -04001379 ofp_file.close()
1380
1381 tcp_file = open(tshark_tcp_output, 'r')
1382 main.log.info("Tshark TCP 74 output: ")
1383 for line in tcp_file:
1384 tshark_tcp_result_list.append(line)
1385 main.log.info(line)
1386
1387 tcp_file.close()
1388
andrewonlab16ce4852014-10-30 13:41:09 -04001389 json_obj_1 = json.loads(json_str_topology_metrics_1)
1390 json_obj_2 = json.loads(json_str_topology_metrics_2)
1391 json_obj_3 = json.loads(json_str_topology_metrics_3)
1392
1393 graph_timestamp_1 = \
1394 json_obj_1[graphTimestamp]['value']
1395 graph_timestamp_2 = \
1396 json_obj_2[graphTimestamp]['value']
1397 graph_timestamp_3 = \
1398 json_obj_3[graphTimestamp]['value']
1399
1400 main.log.info(
1401 int(graph_timestamp_1) - int(t0_system))
1402 main.log.info(
1403 int(graph_timestamp_2) - int(t0_system))
1404 main.log.info(
1405 int(graph_timestamp_3) - int(t0_system))
1406
1407
1408
1409
1410
1411
andrewonlabb54b85b2014-10-28 18:43:57 -04001412