blob: 21f5f448a852e26f82333c7f7e9947df4ca92424 [file] [log] [blame]
andrewonlab2a6c9342014-10-16 13:40:15 -04001#TopoPerfNext
2#
3#Topology Performance test for ONOS-next
4#
5#andrew@onlab.us
andrewonlab4f50ec92014-11-11 14:24:45 -05006#
7#If your machine does not come with numpy
8#run the following command:
9#sudo apt-get install python-numpy python-scipy
andrewonlab2a6c9342014-10-16 13:40:15 -040010
11import time
12import sys
13import os
14import re
15
16class TopoPerfNext:
17 def __init__(self):
18 self.default = ''
19
20 def CASE1(self, main):
21 '''
22 ONOS startup sequence
23 '''
andrewonlabe9fb6722014-10-24 12:20:35 -040024 import time
25
andrewonlab2a6c9342014-10-16 13:40:15 -040026 cell_name = main.params['ENV']['cellName']
27
28 git_pull = main.params['GIT']['autoPull']
29 checkout_branch = main.params['GIT']['checkout']
30
31 ONOS1_ip = main.params['CTRL']['ip1']
andrewonlabba44bcf2014-10-16 16:54:41 -040032 ONOS2_ip = main.params['CTRL']['ip2']
33 ONOS3_ip = main.params['CTRL']['ip3']
andrewonlab6c8bbeb2014-11-14 12:43:48 -050034
35 #### Hardcoded ONOS nodes particular to my env ####
36 ONOS4_ip = "10.128.174.4"
37 ONOS5_ip = "10.128.174.5"
38 ONOS6_ip = "10.128.174.6"
39 ONOS7_ip = "10.128.174.7"
40 #### ####
41
andrewonlab2a6c9342014-10-16 13:40:15 -040042 MN1_ip = main.params['MN']['ip1']
43 BENCH_ip = main.params['BENCH']['ip']
44
45 main.case("Setting up test environment")
andrewonlabf9828f02014-11-10 14:50:27 -050046 main.log.report("Setting up test environment")
andrewonlab2a6c9342014-10-16 13:40:15 -040047
andrewonlab6c8bbeb2014-11-14 12:43:48 -050048 main.step("Cleaning previously installed ONOS if any")
49 main.ONOSbench.onos_uninstall(node_ip=ONOS4_ip)
50 main.ONOSbench.onos_uninstall(node_ip=ONOS5_ip)
51 main.ONOSbench.onos_uninstall(node_ip=ONOS6_ip)
52 main.ONOSbench.onos_uninstall(node_ip=ONOS7_ip)
53
andrewonlab2a6c9342014-10-16 13:40:15 -040054 main.step("Creating cell file")
55 cell_file_result = main.ONOSbench.create_cell_file(
andrewonlabe6745342014-10-17 14:29:13 -040056 BENCH_ip, cell_name, MN1_ip, "onos-core",
andrewonlabba44bcf2014-10-16 16:54:41 -040057 ONOS1_ip, ONOS2_ip, ONOS3_ip)
andrewonlab2a6c9342014-10-16 13:40:15 -040058
59 main.step("Applying cell file to environment")
60 cell_apply_result = main.ONOSbench.set_cell(cell_name)
61 verify_cell_result = main.ONOSbench.verify_cell()
62
andrewonlab6e78adf2014-11-14 12:57:29 -050063 #NOTE: This step may be removed after proper
64 # copy cat log functionality
65 main.step("Removing raft/copy-cat logs from ONOS nodes")
66 main.ONOSbench.onos_remove_raft_logs()
67
andrewonlab2a6c9342014-10-16 13:40:15 -040068 main.step("Git checkout and pull "+checkout_branch)
69 if git_pull == 'on':
70 checkout_result = \
71 main.ONOSbench.git_checkout(checkout_branch)
72 pull_result = main.ONOSbench.git_pull()
73 else:
74 checkout_result = main.TRUE
75 pull_result = main.TRUE
76 main.log.info("Skipped git checkout and pull")
77
andrewonlab92844342014-11-18 16:39:11 -050078 #TODO: Uncomment when wiki posting works
79 #main.log.report("Commit information - ")
80 #main.ONOSbench.get_version(report=True)
81
andrewonlab2a6c9342014-10-16 13:40:15 -040082 main.step("Using mvn clean & install")
andrewonlab8d29f122014-10-22 17:15:04 -040083 #mvn_result = main.ONOSbench.clean_install()
84 mvn_result = main.TRUE
andrewonlab2a6c9342014-10-16 13:40:15 -040085
andrewonlabb1998c52014-11-10 13:31:43 -050086 main.step("Set cell for ONOS cli env")
87 main.ONOS1cli.set_cell(cell_name)
88 main.ONOS2cli.set_cell(cell_name)
89 main.ONOS3cli.set_cell(cell_name)
90
andrewonlab2a6c9342014-10-16 13:40:15 -040091 main.step("Creating ONOS package")
92 package_result = main.ONOSbench.onos_package()
93
94 main.step("Installing ONOS package")
andrewonlabe9fb6722014-10-24 12:20:35 -040095 install1_result = main.ONOSbench.onos_install(node=ONOS1_ip)
96 install2_result = main.ONOSbench.onos_install(node=ONOS2_ip)
97 install3_result = main.ONOSbench.onos_install(node=ONOS3_ip)
andrewonlab2a6c9342014-10-16 13:40:15 -040098
andrewonlabe9fb6722014-10-24 12:20:35 -040099 time.sleep(10)
100
andrewonlab867212a2014-10-22 20:13:38 -0400101 main.step("Start onos cli")
andrewonlabe9fb6722014-10-24 12:20:35 -0400102 cli1 = main.ONOS1cli.start_onos_cli(ONOS1_ip)
103 cli2 = main.ONOS2cli.start_onos_cli(ONOS2_ip)
104 cli3 = main.ONOS3cli.start_onos_cli(ONOS3_ip)
105
andrewonlab867212a2014-10-22 20:13:38 -0400106 main.step("Enable metrics feature")
andrewonlabb1998c52014-11-10 13:31:43 -0500107 main.ONOS1cli.feature_install("onos-app-metrics")
108 main.ONOS2cli.feature_install("onos-app-metrics")
109 main.ONOS3cli.feature_install("onos-app-metrics")
andrewonlab867212a2014-10-22 20:13:38 -0400110
andrewonlab2a6c9342014-10-16 13:40:15 -0400111 utilities.assert_equals(expect=main.TRUE,
112 actual= cell_file_result and cell_apply_result and\
113 verify_cell_result and checkout_result and\
114 pull_result and mvn_result and\
andrewonlabe9fb6722014-10-24 12:20:35 -0400115 install1_result and install2_result and\
116 install3_result,
andrewonlabf9828f02014-11-10 14:50:27 -0500117 onpass="Test Environment setup successful",
118 onfail="Failed to setup test environment")
andrewonlab2a6c9342014-10-16 13:40:15 -0400119
andrewonlabba44bcf2014-10-16 16:54:41 -0400120 def CASE2(self, main):
121 '''
122 Assign s1 to ONOS1 and measure latency
andrewonlab3a7c3c72014-10-24 17:21:03 -0400123
124 There are 4 levels of latency measurements to this test:
125 1) End-to-end measurement: Complete end-to-end measurement
126 from TCP (SYN/ACK) handshake to Graph change
127 2) OFP-to-graph measurement: 'ONOS processing' snippet of
128 measurement from OFP Vendor message to Graph change
129 3) OFP-to-device measurement: 'ONOS processing without
130 graph change' snippet of measurement from OFP vendor
131 message to Device change timestamp
132 4) T0-to-device measurement: Measurement that includes
133 the switch handshake to devices timestamp without
134 the graph view change. (TCP handshake -> Device
135 change)
andrewonlabba44bcf2014-10-16 16:54:41 -0400136 '''
137 import time
andrewonlabe6745342014-10-17 14:29:13 -0400138 import subprocess
139 import json
140 import requests
141 import os
andrewonlab4f50ec92014-11-11 14:24:45 -0500142 import numpy
andrewonlabba44bcf2014-10-16 16:54:41 -0400143
144 ONOS1_ip = main.params['CTRL']['ip1']
145 ONOS2_ip = main.params['CTRL']['ip2']
146 ONOS3_ip = main.params['CTRL']['ip3']
andrewonlabe6745342014-10-17 14:29:13 -0400147 ONOS_user = main.params['CTRL']['user']
148
andrewonlabba44bcf2014-10-16 16:54:41 -0400149 default_sw_port = main.params['CTRL']['port1']
150
151 #Number of iterations of case
152 num_iter = main.params['TEST']['numIter']
andrewonlab4b5c8b92014-11-10 16:04:33 -0500153 #Number of first 'x' iterations to ignore:
154 iter_ignore = int(main.params['TEST']['iterIgnore'])
155
andrewonlab226024e2014-10-24 16:01:32 -0400156 #Timestamp 'keys' for json metrics output.
157 #These are subject to change, hence moved into params
158 deviceTimestamp = main.params['JSON']['deviceTimestamp']
159 graphTimestamp = main.params['JSON']['graphTimestamp']
160
andrewonlab58f7d702014-11-07 13:21:19 -0500161 debug_mode = main.params['TEST']['debugMode']
andrewonlabb1998c52014-11-10 13:31:43 -0500162 onos_log = main.params['TEST']['onosLogFile']
andrewonlab58f7d702014-11-07 13:21:19 -0500163
andrewonlabe5bcef92014-11-06 17:53:20 -0500164 #Threshold for the test
165 threshold_str = main.params['TEST']['singleSwThreshold']
166 threshold_obj = threshold_str.split(",")
167 threshold_min = int(threshold_obj[0])
168 threshold_max = int(threshold_obj[1])
169
andrewonlab226024e2014-10-24 16:01:32 -0400170 #List of switch add latency collected from
171 #all iterations
172 latency_end_to_end_list = []
173 latency_ofp_to_graph_list = []
174 latency_ofp_to_device_list = []
175 latency_t0_to_device_list = []
andrewonlab65d73892014-11-10 17:36:00 -0500176 latency_tcp_to_ofp_list = []
andrewonlab226024e2014-10-24 16:01:32 -0400177
andrewonlabba44bcf2014-10-16 16:54:41 -0400178 #Directory/file to store tshark results
179 tshark_of_output = "/tmp/tshark_of_topo.txt"
180 tshark_tcp_output = "/tmp/tshark_tcp_topo.txt"
181
182 #String to grep in tshark output
183 tshark_tcp_string = "TCP 74 "+default_sw_port
184 tshark_of_string = "OFP 86 Vendor"
andrewonlabe6745342014-10-17 14:29:13 -0400185
186 #Initialize assertion to TRUE
187 assertion = main.TRUE
andrewonlab58f7d702014-11-07 13:21:19 -0500188
189 local_time = time.strftime('%x %X')
andrewonlabb1998c52014-11-10 13:31:43 -0500190 local_time = local_time.replace("/","")
191 local_time = local_time.replace(" ","_")
192 local_time = local_time.replace(":","")
andrewonlab58f7d702014-11-07 13:21:19 -0500193 if debug_mode == 'on':
194 main.ONOS1.tshark_pcap("eth0",
andrewonlabb1998c52014-11-10 13:31:43 -0500195 "/tmp/single_sw_lat_pcap_"+local_time)
196
197 main.log.info("TEST")
andrewonlab58f7d702014-11-07 13:21:19 -0500198
andrewonlab4b5c8b92014-11-10 16:04:33 -0500199 main.log.report("Latency of adding one switch to controller")
200 main.log.report("First "+str(iter_ignore)+" iterations ignored"+
201 " for jvm warmup time")
202 main.log.report("Total iterations of test: "+str(num_iter))
andrewonlabba44bcf2014-10-16 16:54:41 -0400203
204 for i in range(0, int(num_iter)):
205 main.log.info("Starting tshark capture")
206
207 #* TCP [ACK, SYN] is used as t0_a, the
208 # very first "exchange" between ONOS and
209 # the switch for end-to-end measurement
210 #* OFP [Stats Reply] is used for t0_b
211 # the very last OFP message between ONOS
212 # and the switch for ONOS measurement
213 main.ONOS1.tshark_grep(tshark_tcp_string,
214 tshark_tcp_output)
215 main.ONOS1.tshark_grep(tshark_of_string,
216 tshark_of_output)
217
218 #Wait and ensure tshark is started and
219 #capturing
220 time.sleep(10)
221
222 main.log.info("Assigning s1 to controller")
223
224 main.Mininet1.assign_sw_controller(sw="1",
225 ip1=ONOS1_ip, port1=default_sw_port)
226
227 #Wait and ensure switch is assigned
228 #before stopping tshark
andrewonlab867212a2014-10-22 20:13:38 -0400229 time.sleep(30)
andrewonlab226024e2014-10-24 16:01:32 -0400230
231 main.log.info("Stopping all Tshark processes")
andrewonlabba44bcf2014-10-16 16:54:41 -0400232 main.ONOS1.stop_tshark()
233
andrewonlabe6745342014-10-17 14:29:13 -0400234 #tshark output is saved in ONOS. Use subprocess
235 #to copy over files to TestON for parsing
236 main.log.info("Copying over tshark files")
237
238 #TCP CAPTURE ****
andrewonlab8d29f122014-10-22 17:15:04 -0400239 #Copy the tshark output from ONOS machine to
240 #TestON machine in tshark_tcp_output directory>file
241 os.system("scp "+ONOS_user+"@"+ONOS1_ip+":"+
242 tshark_tcp_output+" /tmp/")
243 tcp_file = open(tshark_tcp_output, 'r')
244 temp_text = tcp_file.readline()
andrewonlabe6745342014-10-17 14:29:13 -0400245 temp_text = temp_text.split(" ")
andrewonlabba44bcf2014-10-16 16:54:41 -0400246
andrewonlabe6745342014-10-17 14:29:13 -0400247 main.log.info("Object read in from TCP capture: "+
248 str(temp_text))
andrewonlab867212a2014-10-22 20:13:38 -0400249 if len(temp_text) > 1:
andrewonlab3a7c3c72014-10-24 17:21:03 -0400250 t0_tcp = float(temp_text[1])*1000.0
andrewonlabe6745342014-10-17 14:29:13 -0400251 else:
252 main.log.error("Tshark output file for TCP"+
253 " returned unexpected results")
254 t0_tcp = 0
255 assertion = main.FALSE
andrewonlab8d29f122014-10-22 17:15:04 -0400256
257 tcp_file.close()
andrewonlabe6745342014-10-17 14:29:13 -0400258 #****************
andrewonlabba44bcf2014-10-16 16:54:41 -0400259
andrewonlabe6745342014-10-17 14:29:13 -0400260 #OF CAPTURE ****
andrewonlab8d29f122014-10-22 17:15:04 -0400261 os.system("scp "+ONOS_user+"@"+ONOS1_ip+":"+
262 tshark_of_output+" /tmp/")
263 of_file = open(tshark_of_output, 'r')
264
265 line_ofp = ""
andrewonlab226024e2014-10-24 16:01:32 -0400266 #Read until last line of file
andrewonlabe6745342014-10-17 14:29:13 -0400267 while True:
andrewonlab8d29f122014-10-22 17:15:04 -0400268 temp_text = of_file.readline()
269 if temp_text !='':
andrewonlabe6745342014-10-17 14:29:13 -0400270 line_ofp = temp_text
271 else:
272 break
273 obj = line_ofp.split(" ")
274
275 main.log.info("Object read in from OFP capture: "+
276 str(line_ofp))
277
andrewonlab867212a2014-10-22 20:13:38 -0400278 if len(line_ofp) > 1:
andrewonlab3a7c3c72014-10-24 17:21:03 -0400279 t0_ofp = float(obj[1])*1000.0
andrewonlabe6745342014-10-17 14:29:13 -0400280 else:
281 main.log.error("Tshark output file for OFP"+
282 " returned unexpected results")
283 t0_ofp = 0
284 assertion = main.FALSE
andrewonlab8d29f122014-10-22 17:15:04 -0400285
286 of_file.close()
andrewonlabe6745342014-10-17 14:29:13 -0400287 #****************
288
andrewonlab867212a2014-10-22 20:13:38 -0400289 json_str_1 = main.ONOS1cli.topology_events_metrics()
290 json_str_2 = main.ONOS2cli.topology_events_metrics()
291 json_str_3 = main.ONOS3cli.topology_events_metrics()
andrewonlab867212a2014-10-22 20:13:38 -0400292
293 json_obj_1 = json.loads(json_str_1)
294 json_obj_2 = json.loads(json_str_2)
295 json_obj_3 = json.loads(json_str_3)
296
andrewonlab226024e2014-10-24 16:01:32 -0400297 #Obtain graph timestamp. This timestsamp captures
298 #the epoch time at which the topology graph was updated.
299 graph_timestamp_1 = \
300 json_obj_1[graphTimestamp]['value']
301 graph_timestamp_2 = \
302 json_obj_2[graphTimestamp]['value']
303 graph_timestamp_3 = \
304 json_obj_3[graphTimestamp]['value']
andrewonlab867212a2014-10-22 20:13:38 -0400305
andrewonlab226024e2014-10-24 16:01:32 -0400306 #Obtain device timestamp. This timestamp captures
307 #the epoch time at which the device event happened
308 device_timestamp_1 = \
309 json_obj_1[deviceTimestamp]['value']
310 device_timestamp_2 = \
311 json_obj_2[deviceTimestamp]['value']
312 device_timestamp_3 = \
313 json_obj_3[deviceTimestamp]['value']
andrewonlabe9fb6722014-10-24 12:20:35 -0400314
andrewonlab226024e2014-10-24 16:01:32 -0400315 #t0 to device processing latency
316 delta_device_1 = int(device_timestamp_1) - int(t0_tcp)
317 delta_device_2 = int(device_timestamp_2) - int(t0_tcp)
318 delta_device_3 = int(device_timestamp_3) - int(t0_tcp)
319
320 #Get average of delta from all instances
321 avg_delta_device = \
322 (int(delta_device_1)+\
323 int(delta_device_2)+\
324 int(delta_device_3)) / 3
andrewonlabba44bcf2014-10-16 16:54:41 -0400325
andrewonlab226024e2014-10-24 16:01:32 -0400326 #Ensure avg delta meets the threshold before appending
andrewonlab4b5c8b92014-11-10 16:04:33 -0500327 if avg_delta_device > 0.0 and avg_delta_device < 10000\
andrewonlab65d73892014-11-10 17:36:00 -0500328 and int(i) > iter_ignore:
andrewonlab226024e2014-10-24 16:01:32 -0400329 latency_t0_to_device_list.append(avg_delta_device)
andrewonlabee4efeb2014-10-24 16:44:51 -0400330 else:
andrewonlab09d973e2014-10-24 18:56:58 -0400331 main.log.info("Results for t0-to-device ignored"+\
andrewonlab4b5c8b92014-11-10 16:04:33 -0500332 "due to excess in threshold / warmup iteration.")
andrewonlabee4efeb2014-10-24 16:44:51 -0400333
andrewonlab226024e2014-10-24 16:01:32 -0400334 #t0 to graph processing latency (end-to-end)
335 delta_graph_1 = int(graph_timestamp_1) - int(t0_tcp)
336 delta_graph_2 = int(graph_timestamp_2) - int(t0_tcp)
337 delta_graph_3 = int(graph_timestamp_3) - int(t0_tcp)
338
339 #Get average of delta from all instances
340 avg_delta_graph = \
341 (int(delta_graph_1)+\
342 int(delta_graph_2)+\
343 int(delta_graph_3)) / 3
344
andrewonlab226024e2014-10-24 16:01:32 -0400345 #Ensure avg delta meets the threshold before appending
andrewonlab4b5c8b92014-11-10 16:04:33 -0500346 if avg_delta_graph > 0.0 and avg_delta_graph < 10000\
andrewonlab65d73892014-11-10 17:36:00 -0500347 and int(i) > iter_ignore:
andrewonlab09d973e2014-10-24 18:56:58 -0400348 latency_end_to_end_list.append(avg_delta_graph)
andrewonlabee4efeb2014-10-24 16:44:51 -0400349 else:
andrewonlab09d973e2014-10-24 18:56:58 -0400350 main.log.info("Results for end-to-end ignored"+\
351 "due to excess in threshold")
andrewonlab226024e2014-10-24 16:01:32 -0400352
353 #ofp to graph processing latency (ONOS processing)
354 delta_ofp_graph_1 = int(graph_timestamp_1) - int(t0_ofp)
355 delta_ofp_graph_2 = int(graph_timestamp_2) - int(t0_ofp)
356 delta_ofp_graph_3 = int(graph_timestamp_3) - int(t0_ofp)
357
358 avg_delta_ofp_graph = \
359 (int(delta_ofp_graph_1)+\
360 int(delta_ofp_graph_2)+\
361 int(delta_ofp_graph_3)) / 3
362
andrewonlabe5bcef92014-11-06 17:53:20 -0500363 if avg_delta_ofp_graph > threshold_min \
andrewonlab4b5c8b92014-11-10 16:04:33 -0500364 and avg_delta_ofp_graph < threshold_max\
andrewonlab65d73892014-11-10 17:36:00 -0500365 and int(i) > iter_ignore:
andrewonlab226024e2014-10-24 16:01:32 -0400366 latency_ofp_to_graph_list.append(avg_delta_ofp_graph)
andrewonlab92844342014-11-18 16:39:11 -0500367 elif avg_delta_ofp_graph > (-10) and \
368 avg_delta_ofp_graph < 0.0 and\
369 int(i) > iter_ignore:
370 main.log.info("Sub-millisecond result likely; "+
371 "negative result was rounded to 0")
372 #NOTE: Current metrics framework does not
373 #support sub-millisecond accuracy. Therefore,
374 #if the result is negative, we can reasonably
375 #conclude sub-millisecond results and just
376 #append the best rounded effort - 0 ms.
377 latency_ofp_to_graph_list.append(0)
andrewonlabee4efeb2014-10-24 16:44:51 -0400378 else:
andrewonlab09d973e2014-10-24 18:56:58 -0400379 main.log.info("Results for ofp-to-graph "+\
380 "ignored due to excess in threshold")
andrewonlabee4efeb2014-10-24 16:44:51 -0400381
andrewonlab226024e2014-10-24 16:01:32 -0400382 #ofp to device processing latency (ONOS processing)
andrewonlabee4efeb2014-10-24 16:44:51 -0400383 delta_ofp_device_1 = float(device_timestamp_1) - float(t0_ofp)
384 delta_ofp_device_2 = float(device_timestamp_2) - float(t0_ofp)
385 delta_ofp_device_3 = float(device_timestamp_3) - float(t0_ofp)
andrewonlab226024e2014-10-24 16:01:32 -0400386
387 avg_delta_ofp_device = \
andrewonlabee4efeb2014-10-24 16:44:51 -0400388 (float(delta_ofp_device_1)+\
389 float(delta_ofp_device_2)+\
andrewonlab4b5c8b92014-11-10 16:04:33 -0500390 float(delta_ofp_device_3)) / 3
andrewonlab226024e2014-10-24 16:01:32 -0400391
andrewonlabf47993a2014-10-24 17:56:01 -0400392 #NOTE: ofp - delta measurements are occasionally negative
393 # due to system time misalignment.
andrewonlabf47993a2014-10-24 17:56:01 -0400394 latency_ofp_to_device_list.append(avg_delta_ofp_device)
andrewonlabba44bcf2014-10-16 16:54:41 -0400395
andrewonlab65d73892014-11-10 17:36:00 -0500396 delta_ofp_tcp = int(t0_ofp) - int(t0_tcp)
397 if delta_ofp_tcp > threshold_min \
398 and delta_ofp_tcp < threshold_max and\
399 int(i) > iter_ignore:
400 latency_tcp_to_ofp_list.append(delta_ofp_tcp)
401 else:
402 main.log.info("Results fo tcp-to-ofp "+\
403 "ignored due to excess in threshold")
404
andrewonlabe6745342014-10-17 14:29:13 -0400405 #TODO:
406 #Fetch logs upon threshold excess
andrewonlabba44bcf2014-10-16 16:54:41 -0400407
andrewonlab226024e2014-10-24 16:01:32 -0400408 main.log.info("ONOS1 delta end-to-end: "+
andrewonlab09d973e2014-10-24 18:56:58 -0400409 str(delta_graph_1) + " ms")
andrewonlab226024e2014-10-24 16:01:32 -0400410 main.log.info("ONOS2 delta end-to-end: "+
andrewonlab09d973e2014-10-24 18:56:58 -0400411 str(delta_graph_2) + " ms")
412 main.log.info("ONOS3 delta end-to-end: "+
413 str(delta_graph_3) + " ms")
andrewonlabba44bcf2014-10-16 16:54:41 -0400414
andrewonlab226024e2014-10-24 16:01:32 -0400415 main.log.info("ONOS1 delta OFP - graph: "+
andrewonlab09d973e2014-10-24 18:56:58 -0400416 str(delta_ofp_graph_1) + " ms")
andrewonlab226024e2014-10-24 16:01:32 -0400417 main.log.info("ONOS2 delta OFP - graph: "+
andrewonlab09d973e2014-10-24 18:56:58 -0400418 str(delta_ofp_graph_2) + " ms")
andrewonlab226024e2014-10-24 16:01:32 -0400419 main.log.info("ONOS3 delta OFP - graph: "+
andrewonlab09d973e2014-10-24 18:56:58 -0400420 str(delta_ofp_graph_3) + " ms")
andrewonlabe6745342014-10-17 14:29:13 -0400421
andrewonlab226024e2014-10-24 16:01:32 -0400422 main.log.info("ONOS1 delta device - t0: "+
andrewonlab09d973e2014-10-24 18:56:58 -0400423 str(delta_device_1) + " ms")
andrewonlab226024e2014-10-24 16:01:32 -0400424 main.log.info("ONOS2 delta device - t0: "+
andrewonlab09d973e2014-10-24 18:56:58 -0400425 str(delta_device_2) + " ms")
andrewonlab226024e2014-10-24 16:01:32 -0400426 main.log.info("ONOS3 delta device - t0: "+
andrewonlab09d973e2014-10-24 18:56:58 -0400427 str(delta_device_3) + " ms")
andrewonlab65d73892014-11-10 17:36:00 -0500428
429 main.log.info("TCP to OFP delta: "+
430 str(delta_ofp_tcp) + " ms")
andrewonlab8790abb2014-11-06 13:51:54 -0500431 #main.log.info("ONOS1 delta OFP - device: "+
432 # str(delta_ofp_device_1) + " ms")
433 #main.log.info("ONOS2 delta OFP - device: "+
434 # str(delta_ofp_device_2) + " ms")
435 #main.log.info("ONOS3 delta OFP - device: "+
436 # str(delta_ofp_device_3) + " ms")
andrewonlab226024e2014-10-24 16:01:32 -0400437
andrewonlab8d29f122014-10-22 17:15:04 -0400438 main.step("Remove switch from controller")
439 main.Mininet1.delete_sw_controller("s1")
andrewonlabba44bcf2014-10-16 16:54:41 -0400440
andrewonlab8d29f122014-10-22 17:15:04 -0400441 time.sleep(5)
andrewonlabba44bcf2014-10-16 16:54:41 -0400442
andrewonlab09d973e2014-10-24 18:56:58 -0400443 #END of for loop iteration
andrewonlabf47993a2014-10-24 17:56:01 -0400444
andrewonlabee4efeb2014-10-24 16:44:51 -0400445 #If there is at least 1 element in each list,
andrewonlabc15c9582014-10-24 16:35:52 -0400446 #pass the test case
447 if len(latency_end_to_end_list) > 0 and\
448 len(latency_ofp_to_graph_list) > 0 and\
449 len(latency_ofp_to_device_list) > 0 and\
andrewonlab65d73892014-11-10 17:36:00 -0500450 len(latency_t0_to_device_list) > 0 and\
451 len(latency_tcp_to_ofp_list) > 0:
andrewonlabc15c9582014-10-24 16:35:52 -0400452 assertion = main.TRUE
andrewonlabf47993a2014-10-24 17:56:01 -0400453 elif len(latency_end_to_end_list) == 0:
454 #The appending of 0 here is to prevent
455 #the min,max,sum functions from failing
456 #below
457 latency_end_to_end_list.append(0)
458 assertion = main.FALSE
459 elif len(latency_ofp_to_graph_list) == 0:
460 latency_ofp_to_graph_list.append(0)
461 assertion = main.FALSE
462 elif len(latency_ofp_to_device_list) == 0:
463 latency_ofp_to_device_list.append(0)
464 assertion = main.FALSE
465 elif len(latency_t0_to_device_list) == 0:
466 latency_t0_to_device_list.append(0)
467 assertion = main.FALSE
andrewonlab65d73892014-11-10 17:36:00 -0500468 elif len(latency_tcp_to_ofp_list) == 0:
469 latency_tcp_to_ofp_list.append(0)
470 assertion = main.FALSE
andrewonlabc15c9582014-10-24 16:35:52 -0400471
472 #Calculate min, max, avg of latency lists
473 latency_end_to_end_max = \
andrewonlabee4efeb2014-10-24 16:44:51 -0400474 int(max(latency_end_to_end_list))
andrewonlabc15c9582014-10-24 16:35:52 -0400475 latency_end_to_end_min = \
andrewonlabee4efeb2014-10-24 16:44:51 -0400476 int(min(latency_end_to_end_list))
andrewonlabc15c9582014-10-24 16:35:52 -0400477 latency_end_to_end_avg = \
andrewonlabc90667c2014-10-24 16:48:28 -0400478 (int(sum(latency_end_to_end_list)) / \
andrewonlabc15c9582014-10-24 16:35:52 -0400479 len(latency_end_to_end_list))
andrewonlab69864162014-11-11 16:28:48 -0500480 latency_end_to_end_std_dev = \
481 str(round(numpy.std(latency_end_to_end_list),1))
482
andrewonlabc15c9582014-10-24 16:35:52 -0400483 latency_ofp_to_graph_max = \
andrewonlabee4efeb2014-10-24 16:44:51 -0400484 int(max(latency_ofp_to_graph_list))
andrewonlabc15c9582014-10-24 16:35:52 -0400485 latency_ofp_to_graph_min = \
andrewonlabee4efeb2014-10-24 16:44:51 -0400486 int(min(latency_ofp_to_graph_list))
andrewonlabc15c9582014-10-24 16:35:52 -0400487 latency_ofp_to_graph_avg = \
andrewonlabee4efeb2014-10-24 16:44:51 -0400488 (int(sum(latency_ofp_to_graph_list)) / \
andrewonlabc15c9582014-10-24 16:35:52 -0400489 len(latency_ofp_to_graph_list))
andrewonlab69864162014-11-11 16:28:48 -0500490 latency_ofp_to_graph_std_dev = \
491 str(round(numpy.std(latency_ofp_to_graph_list),1))
andrewonlabc15c9582014-10-24 16:35:52 -0400492
493 latency_ofp_to_device_max = \
andrewonlabee4efeb2014-10-24 16:44:51 -0400494 int(max(latency_ofp_to_device_list))
andrewonlabc15c9582014-10-24 16:35:52 -0400495 latency_ofp_to_device_min = \
andrewonlabee4efeb2014-10-24 16:44:51 -0400496 int(min(latency_ofp_to_device_list))
andrewonlabc15c9582014-10-24 16:35:52 -0400497 latency_ofp_to_device_avg = \
andrewonlabee4efeb2014-10-24 16:44:51 -0400498 (int(sum(latency_ofp_to_device_list)) / \
andrewonlabc15c9582014-10-24 16:35:52 -0400499 len(latency_ofp_to_device_list))
andrewonlab69864162014-11-11 16:28:48 -0500500 latency_ofp_to_device_std_dev = \
501 str(round(numpy.std(latency_ofp_to_device_list),1))
andrewonlabc15c9582014-10-24 16:35:52 -0400502
503 latency_t0_to_device_max = \
andrewonlab4b5c8b92014-11-10 16:04:33 -0500504 int(max(latency_t0_to_device_list))
andrewonlabc15c9582014-10-24 16:35:52 -0400505 latency_t0_to_device_min = \
andrewonlab4b5c8b92014-11-10 16:04:33 -0500506 int(min(latency_t0_to_device_list))
andrewonlabc15c9582014-10-24 16:35:52 -0400507 latency_t0_to_device_avg = \
andrewonlab4b5c8b92014-11-10 16:04:33 -0500508 (int(sum(latency_t0_to_device_list)) / \
andrewonlab69864162014-11-11 16:28:48 -0500509 len(latency_t0_to_device_list))
510 latency_ofp_to_device_std_dev = \
511 str(round(numpy.std(latency_t0_to_device_list),1))
andrewonlabc15c9582014-10-24 16:35:52 -0400512
andrewonlab65d73892014-11-10 17:36:00 -0500513 latency_tcp_to_ofp_max = \
514 int(max(latency_tcp_to_ofp_list))
515 latency_tcp_to_ofp_min = \
516 int(min(latency_tcp_to_ofp_list))
517 latency_tcp_to_ofp_avg = \
518 (int(sum(latency_tcp_to_ofp_list)) / \
519 len(latency_tcp_to_ofp_list))
andrewonlab69864162014-11-11 16:28:48 -0500520 latency_tcp_to_ofp_std_dev = \
521 str(round(numpy.std(latency_tcp_to_ofp_list),1))
andrewonlab65d73892014-11-10 17:36:00 -0500522
andrewonlabf9828f02014-11-10 14:50:27 -0500523 main.log.report("Switch add - End-to-end latency: "+\
andrewonlab4f50ec92014-11-11 14:24:45 -0500524 "Avg: "+str(latency_end_to_end_avg)+" ms "+
andrewonlab69864162014-11-11 16:28:48 -0500525 "Std Deviation: "+latency_end_to_end_std_dev+" ms")
andrewonlabf9828f02014-11-10 14:50:27 -0500526 main.log.report("Switch add - OFP-to-Graph latency: "+\
andrewonlab92844342014-11-18 16:39:11 -0500527 "Note: results are not accurate to sub-millisecond. "+
528 "Any sub-millisecond results are rounded to 0 ms. ")
529 main.log.report("Avg: "+str(latency_ofp_to_graph_avg)+" ms "+
andrewonlab69864162014-11-11 16:28:48 -0500530 "Std Deviation: "+latency_ofp_to_graph_std_dev+" ms")
andrewonlab65d73892014-11-10 17:36:00 -0500531 main.log.report("Switch add - TCP-to-OFP latency: "+\
andrewonlab4f50ec92014-11-11 14:24:45 -0500532 "Avg: "+str(latency_tcp_to_ofp_avg)+" ms "+
andrewonlab69864162014-11-11 16:28:48 -0500533 "Std Deviation: "+latency_tcp_to_ofp_std_dev+" ms")
andrewonlab226024e2014-10-24 16:01:32 -0400534
andrewonlabb1998c52014-11-10 13:31:43 -0500535 if debug_mode == 'on':
536 main.ONOS1.cp_logs_to_dir("/opt/onos/log/karaf.log",
537 "/tmp/", copy_file_name="sw_lat_karaf")
538
andrewonlab8d29f122014-10-22 17:15:04 -0400539 utilities.assert_equals(expect=main.TRUE, actual=assertion,
540 onpass="Switch latency test successful",
541 onfail="Switch latency test failed")
andrewonlabba44bcf2014-10-16 16:54:41 -0400542
andrewonlab8d29f122014-10-22 17:15:04 -0400543 def CASE3(self, main):
544 '''
545 Bring port up / down and measure latency.
546 Port enable / disable is simulated by ifconfig up / down
andrewonlab393531a2014-10-27 18:36:26 -0400547
548 In ONOS-next, we must ensure that the port we are
549 manipulating is connected to another switch with a valid
550 connection. Otherwise, graph view will not be updated.
andrewonlab8d29f122014-10-22 17:15:04 -0400551 '''
552 import time
553 import subprocess
554 import os
555 import requests
556 import json
andrewonlab4f50ec92014-11-11 14:24:45 -0500557 import numpy
andrewonlab2a6c9342014-10-16 13:40:15 -0400558
andrewonlab8d29f122014-10-22 17:15:04 -0400559 ONOS1_ip = main.params['CTRL']['ip1']
andrewonlab393531a2014-10-27 18:36:26 -0400560 ONOS2_ip = main.params['CTRL']['ip2']
561 ONOS3_ip = main.params['CTRL']['ip3']
andrewonlab8d29f122014-10-22 17:15:04 -0400562 ONOS_user = main.params['CTRL']['user']
andrewonlab8d29f122014-10-22 17:15:04 -0400563
andrewonlab393531a2014-10-27 18:36:26 -0400564 default_sw_port = main.params['CTRL']['port1']
andrewonlab8790abb2014-11-06 13:51:54 -0500565
566 assertion = main.TRUE
andrewonlab393531a2014-10-27 18:36:26 -0400567 #Number of iterations of case
568 num_iter = main.params['TEST']['numIter']
569
570 #Timestamp 'keys' for json metrics output.
571 #These are subject to change, hence moved into params
572 deviceTimestamp = main.params['JSON']['deviceTimestamp']
573 graphTimestamp = main.params['JSON']['graphTimestamp']
andrewonlab58f7d702014-11-07 13:21:19 -0500574
575 debug_mode = main.params['TEST']['debugMode']
576
577 local_time = time.strftime('%x %X')
andrewonlabb1998c52014-11-10 13:31:43 -0500578 local_time = local_time.replace("/","")
579 local_time = local_time.replace(" ","_")
580 local_time = local_time.replace(":","")
andrewonlab58f7d702014-11-07 13:21:19 -0500581 if debug_mode == 'on':
582 main.ONOS1.tshark_pcap("eth0",
andrewonlabb1998c52014-11-10 13:31:43 -0500583 "/tmp/port_lat_pcap_"+local_time)
andrewonlab393531a2014-10-27 18:36:26 -0400584
andrewonlabe5bcef92014-11-06 17:53:20 -0500585 #Threshold for this test case
586 up_threshold_str = main.params['TEST']['portUpThreshold']
587 down_threshold_str = main.params['TEST']['portDownThreshold']
andrewonlabb1998c52014-11-10 13:31:43 -0500588
andrewonlabe5bcef92014-11-06 17:53:20 -0500589 up_threshold_obj = up_threshold_str.split(",")
590 down_threshold_obj = down_threshold_str.split(",")
591
592 up_threshold_min = int(up_threshold_obj[0])
593 up_threshold_max = int(up_threshold_obj[1])
594
595 down_threshold_min = int(down_threshold_obj[0])
596 down_threshold_max = int(down_threshold_obj[1])
597
andrewonlab393531a2014-10-27 18:36:26 -0400598 #NOTE: Some hardcoded variables you may need to configure
599 # besides the params
600
andrewonlab8d29f122014-10-22 17:15:04 -0400601 tshark_port_status = "OFP 130 Port Status"
602
603 tshark_port_up = "/tmp/tshark_port_up.txt"
604 tshark_port_down = "/tmp/tshark_port_down.txt"
andrewonlab393531a2014-10-27 18:36:26 -0400605 interface_config = "s1-eth1"
andrewonlab8d29f122014-10-22 17:15:04 -0400606
607 main.log.report("Port enable / disable latency")
andrewonlab4b5c8b92014-11-10 16:04:33 -0500608 main.log.report("Simulated by ifconfig up / down")
609 main.log.report("Total iterations of test: "+str(num_iter))
andrewonlab8d29f122014-10-22 17:15:04 -0400610
andrewonlab393531a2014-10-27 18:36:26 -0400611 main.step("Assign switches s1 and s2 to controller 1")
andrewonlab8d29f122014-10-22 17:15:04 -0400612 main.Mininet1.assign_sw_controller(sw="1",ip1=ONOS1_ip,
613 port1=default_sw_port)
andrewonlab393531a2014-10-27 18:36:26 -0400614 main.Mininet1.assign_sw_controller(sw="2",ip1=ONOS1_ip,
615 port1=default_sw_port)
andrewonlab8d29f122014-10-22 17:15:04 -0400616
andrewonlab8790abb2014-11-06 13:51:54 -0500617 #Give enough time for metrics to propagate the
618 #assign controller event. Otherwise, these events may
619 #carry over to our measurements
andrewonlabb1998c52014-11-10 13:31:43 -0500620 time.sleep(15)
andrewonlab8d29f122014-10-22 17:15:04 -0400621
andrewonlab393531a2014-10-27 18:36:26 -0400622 port_up_device_to_ofp_list = []
623 port_up_graph_to_ofp_list = []
624 port_down_device_to_ofp_list = []
625 port_down_graph_to_ofp_list = []
626
andrewonlab8d29f122014-10-22 17:15:04 -0400627 for i in range(0, int(num_iter)):
628 main.step("Starting wireshark capture for port status down")
629 main.ONOS1.tshark_grep(tshark_port_status,
630 tshark_port_down)
631
andrewonlabb1998c52014-11-10 13:31:43 -0500632 time.sleep(5)
andrewonlab8d29f122014-10-22 17:15:04 -0400633
andrewonlab393531a2014-10-27 18:36:26 -0400634 #Disable interface that is connected to switch 2
635 main.step("Disable port: "+interface_config)
andrewonlabb1998c52014-11-10 13:31:43 -0500636 main.Mininet1.handle.sendline("sh ifconfig "+
andrewonlab393531a2014-10-27 18:36:26 -0400637 interface_config+" down")
andrewonlabb1998c52014-11-10 13:31:43 -0500638 main.Mininet1.handle.expect("mininet>")
andrewonlab8d29f122014-10-22 17:15:04 -0400639
andrewonlabb1998c52014-11-10 13:31:43 -0500640 time.sleep(3)
andrewonlab8d29f122014-10-22 17:15:04 -0400641 main.ONOS1.tshark_stop()
andrewonlabb1998c52014-11-10 13:31:43 -0500642
643 main.step("Obtain t1 by metrics call")
644 json_str_up_1 = main.ONOS1cli.topology_events_metrics()
645 json_str_up_2 = main.ONOS2cli.topology_events_metrics()
646 json_str_up_3 = main.ONOS3cli.topology_events_metrics()
647
648 json_obj_1 = json.loads(json_str_up_1)
649 json_obj_2 = json.loads(json_str_up_2)
650 json_obj_3 = json.loads(json_str_up_3)
andrewonlab8d29f122014-10-22 17:15:04 -0400651
652 #Copy tshark output file from ONOS to TestON instance
653 #/tmp directory
654 os.system("scp "+ONOS_user+"@"+ONOS1_ip+":"+
655 tshark_port_down+" /tmp/")
656
657 f_port_down = open(tshark_port_down, 'r')
andrewonlab393531a2014-10-27 18:36:26 -0400658 #Get first line of port down event from tshark
andrewonlab8d29f122014-10-22 17:15:04 -0400659 f_line = f_port_down.readline()
660 obj_down = f_line.split(" ")
661 if len(f_line) > 0:
andrewonlabb1998c52014-11-10 13:31:43 -0500662 timestamp_begin_pt_down = int(float(obj_down[1])*1000)
andrewonlab393531a2014-10-27 18:36:26 -0400663 main.log.info("Port down begin timestamp: "+
664 str(timestamp_begin_pt_down))
andrewonlab8d29f122014-10-22 17:15:04 -0400665 else:
666 main.log.info("Tshark output file returned unexpected"+
andrewonlab393531a2014-10-27 18:36:26 -0400667 " results: "+str(obj_down))
andrewonlab8d29f122014-10-22 17:15:04 -0400668 timestamp_begin_pt_down = 0
andrewonlab393531a2014-10-27 18:36:26 -0400669
670 f_port_down.close()
andrewonlab8d29f122014-10-22 17:15:04 -0400671
andrewonlab4e124482014-11-04 13:37:25 -0500672 main.log.info("TEST tshark obj: "+str(obj_down))
673
andrewonlabb1998c52014-11-10 13:31:43 -0500674 time.sleep(3)
andrewonlab393531a2014-10-27 18:36:26 -0400675
676 #Obtain graph timestamp. This timestsamp captures
677 #the epoch time at which the topology graph was updated.
678 graph_timestamp_1 = \
679 json_obj_1[graphTimestamp]['value']
680 graph_timestamp_2 = \
681 json_obj_2[graphTimestamp]['value']
682 graph_timestamp_3 = \
683 json_obj_3[graphTimestamp]['value']
684
andrewonlabb1998c52014-11-10 13:31:43 -0500685 main.log.info("TEST graph timestamp ONOS1: "+
686 str(graph_timestamp_1))
687
andrewonlab393531a2014-10-27 18:36:26 -0400688 #Obtain device timestamp. This timestamp captures
689 #the epoch time at which the device event happened
690 device_timestamp_1 = \
691 json_obj_1[deviceTimestamp]['value']
692 device_timestamp_2 = \
693 json_obj_2[deviceTimestamp]['value']
694 device_timestamp_3 = \
695 json_obj_3[deviceTimestamp]['value']
andrewonlab393531a2014-10-27 18:36:26 -0400696
697 #Get delta between graph event and OFP
698 pt_down_graph_to_ofp_1 = int(graph_timestamp_1) -\
699 int(timestamp_begin_pt_down)
700 pt_down_graph_to_ofp_2 = int(graph_timestamp_2) -\
701 int(timestamp_begin_pt_down)
702 pt_down_graph_to_ofp_3 = int(graph_timestamp_3) -\
703 int(timestamp_begin_pt_down)
704
705 #Get delta between device event and OFP
706 pt_down_device_to_ofp_1 = int(device_timestamp_1) -\
707 int(timestamp_begin_pt_down)
708 pt_down_device_to_ofp_2 = int(device_timestamp_2) -\
709 int(timestamp_begin_pt_down)
710 pt_down_device_to_ofp_3 = int(device_timestamp_3) -\
711 int(timestamp_begin_pt_down)
712
713 #Caluclate average across clusters
714 pt_down_graph_to_ofp_avg =\
715 (int(pt_down_graph_to_ofp_1) +
716 int(pt_down_graph_to_ofp_2) +
andrewonlabf9828f02014-11-10 14:50:27 -0500717 int(pt_down_graph_to_ofp_3)) / 3
andrewonlab393531a2014-10-27 18:36:26 -0400718 pt_down_device_to_ofp_avg = \
719 (int(pt_down_device_to_ofp_1) +
720 int(pt_down_device_to_ofp_2) +
andrewonlabf9828f02014-11-10 14:50:27 -0500721 int(pt_down_device_to_ofp_3)) / 3
andrewonlab393531a2014-10-27 18:36:26 -0400722
andrewonlabb1998c52014-11-10 13:31:43 -0500723 if pt_down_graph_to_ofp_avg > down_threshold_min and \
724 pt_down_graph_to_ofp_avg < down_threshold_max:
andrewonlab393531a2014-10-27 18:36:26 -0400725 port_down_graph_to_ofp_list.append(
andrewonlababb11c32014-11-04 15:03:24 -0500726 pt_down_graph_to_ofp_avg)
727 main.log.info("Port down: graph to ofp avg: "+
728 str(pt_down_graph_to_ofp_avg) + " ms")
andrewonlab393531a2014-10-27 18:36:26 -0400729 else:
730 main.log.info("Average port down graph-to-ofp result" +
731 " exceeded the threshold: "+
732 str(pt_down_graph_to_ofp_avg))
733
andrewonlab3622beb2014-10-28 16:07:56 -0400734 if pt_down_device_to_ofp_avg > 0 and \
735 pt_down_device_to_ofp_avg < 1000:
736 port_down_device_to_ofp_list.append(
andrewonlababb11c32014-11-04 15:03:24 -0500737 pt_down_device_to_ofp_avg)
738 main.log.info("Port down: device to ofp avg: "+
739 str(pt_down_device_to_ofp_avg) + " ms")
andrewonlab3622beb2014-10-28 16:07:56 -0400740 else:
741 main.log.info("Average port down device-to-ofp result" +
742 " exceeded the threshold: "+
743 str(pt_down_device_to_ofp_avg))
744
andrewonlab8d29f122014-10-22 17:15:04 -0400745 #Port up events
746 main.step("Enable port and obtain timestamp")
747 main.step("Starting wireshark capture for port status up")
andrewonlabb1998c52014-11-10 13:31:43 -0500748 main.ONOS1.tshark_grep(tshark_port_status, tshark_port_up)
andrewonlab8790abb2014-11-06 13:51:54 -0500749 time.sleep(5)
andrewonlab8d29f122014-10-22 17:15:04 -0400750
andrewonlabb1998c52014-11-10 13:31:43 -0500751 main.Mininet1.handle.sendline("sh ifconfig "+
andrewonlab393531a2014-10-27 18:36:26 -0400752 interface_config+" up")
andrewonlabb1998c52014-11-10 13:31:43 -0500753 main.Mininet1.handle.expect("mininet>")
andrewonlab8790abb2014-11-06 13:51:54 -0500754
andrewonlabb1998c52014-11-10 13:31:43 -0500755 #Allow time for tshark to capture event
756 time.sleep(3)
andrewonlab8790abb2014-11-06 13:51:54 -0500757 main.ONOS1.tshark_stop()
andrewonlab8d29f122014-10-22 17:15:04 -0400758
andrewonlabb1998c52014-11-10 13:31:43 -0500759 #Obtain metrics shortly afterwards
760 #This timestsamp captures
761 #the epoch time at which the topology graph was updated.
762 main.step("Obtain t1 by REST call")
763 json_str_up_1 = main.ONOS1cli.topology_events_metrics()
764 json_str_up_2 = main.ONOS2cli.topology_events_metrics()
765 json_str_up_3 = main.ONOS3cli.topology_events_metrics()
766
767 json_obj_1 = json.loads(json_str_up_1)
768 json_obj_2 = json.loads(json_str_up_2)
769 json_obj_3 = json.loads(json_str_up_3)
770
andrewonlab8d29f122014-10-22 17:15:04 -0400771 os.system("scp "+ONOS_user+"@"+ONOS1_ip+":"+
772 tshark_port_up+" /tmp/")
773
774 f_port_up = open(tshark_port_up, 'r')
andrewonlab393531a2014-10-27 18:36:26 -0400775 f_line = f_port_up.readline()
andrewonlab8d29f122014-10-22 17:15:04 -0400776 obj_up = f_line.split(" ")
777 if len(f_line) > 0:
andrewonlabb1998c52014-11-10 13:31:43 -0500778 timestamp_begin_pt_up = int(float(obj_up[1])*1000)
andrewonlab393531a2014-10-27 18:36:26 -0400779 main.log.info("Port up begin timestamp: "+
780 str(timestamp_begin_pt_up))
andrewonlab8d29f122014-10-22 17:15:04 -0400781 else:
782 main.log.info("Tshark output file returned unexpected"+
783 " results.")
784 timestamp_begin_pt_up = 0
785
andrewonlab393531a2014-10-27 18:36:26 -0400786 f_port_up.close()
787
andrewonlab393531a2014-10-27 18:36:26 -0400788 graph_timestamp_1 = \
789 json_obj_1[graphTimestamp]['value']
790 graph_timestamp_2 = \
791 json_obj_2[graphTimestamp]['value']
792 graph_timestamp_3 = \
793 json_obj_3[graphTimestamp]['value']
794
795 #Obtain device timestamp. This timestamp captures
796 #the epoch time at which the device event happened
797 device_timestamp_1 = \
798 json_obj_1[deviceTimestamp]['value']
799 device_timestamp_2 = \
800 json_obj_2[deviceTimestamp]['value']
801 device_timestamp_3 = \
802 json_obj_3[deviceTimestamp]['value']
803
804 #Get delta between graph event and OFP
805 pt_up_graph_to_ofp_1 = int(graph_timestamp_1) -\
andrewonlab8d29f122014-10-22 17:15:04 -0400806 int(timestamp_begin_pt_up)
andrewonlab393531a2014-10-27 18:36:26 -0400807 pt_up_graph_to_ofp_2 = int(graph_timestamp_2) -\
andrewonlab8d29f122014-10-22 17:15:04 -0400808 int(timestamp_begin_pt_up)
andrewonlab393531a2014-10-27 18:36:26 -0400809 pt_up_graph_to_ofp_3 = int(graph_timestamp_3) -\
810 int(timestamp_begin_pt_up)
811
812 #Get delta between device event and OFP
813 pt_up_device_to_ofp_1 = int(device_timestamp_1) -\
814 int(timestamp_begin_pt_up)
815 pt_up_device_to_ofp_2 = int(device_timestamp_2) -\
816 int(timestamp_begin_pt_up)
817 pt_up_device_to_ofp_3 = int(device_timestamp_3) -\
andrewonlab8d29f122014-10-22 17:15:04 -0400818 int(timestamp_begin_pt_up)
andrewonlab3622beb2014-10-28 16:07:56 -0400819
andrewonlabb1998c52014-11-10 13:31:43 -0500820 main.log.info("ONOS1 delta G2O: "+str(pt_up_graph_to_ofp_1))
821 main.log.info("ONOS2 delta G2O: "+str(pt_up_graph_to_ofp_2))
822 main.log.info("ONOS3 delta G2O: "+str(pt_up_graph_to_ofp_3))
823
824 main.log.info("ONOS1 delta D2O: "+str(pt_up_device_to_ofp_1))
825 main.log.info("ONOS2 delta D2O: "+str(pt_up_device_to_ofp_2))
826 main.log.info("ONOS3 delta D2O: "+str(pt_up_device_to_ofp_3))
827
andrewonlab3622beb2014-10-28 16:07:56 -0400828 pt_up_graph_to_ofp_avg = \
andrewonlabf9828f02014-11-10 14:50:27 -0500829 (int(pt_up_graph_to_ofp_1) +
830 int(pt_up_graph_to_ofp_2) +
831 int(pt_up_graph_to_ofp_3)) / 3
andrewonlab3622beb2014-10-28 16:07:56 -0400832
833 pt_up_device_to_ofp_avg = \
andrewonlabf9828f02014-11-10 14:50:27 -0500834 (int(pt_up_device_to_ofp_1) +
835 int(pt_up_device_to_ofp_2) +
836 int(pt_up_device_to_ofp_3)) / 3
andrewonlab3622beb2014-10-28 16:07:56 -0400837
andrewonlabe5bcef92014-11-06 17:53:20 -0500838 if pt_up_graph_to_ofp_avg > up_threshold_min and \
839 pt_up_graph_to_ofp_avg < up_threshold_max:
andrewonlab3622beb2014-10-28 16:07:56 -0400840 port_up_graph_to_ofp_list.append(
841 pt_up_graph_to_ofp_avg)
andrewonlababb11c32014-11-04 15:03:24 -0500842 main.log.info("Port down: graph to ofp avg: "+
843 str(pt_up_graph_to_ofp_avg) + " ms")
andrewonlab3622beb2014-10-28 16:07:56 -0400844 else:
845 main.log.info("Average port up graph-to-ofp result"+
846 " exceeded the threshold: "+
847 str(pt_up_graph_to_ofp_avg))
848
andrewonlabe5bcef92014-11-06 17:53:20 -0500849 if pt_up_device_to_ofp_avg > up_threshold_min and \
850 pt_up_device_to_ofp_avg < up_threshold_max:
andrewonlab3622beb2014-10-28 16:07:56 -0400851 port_up_device_to_ofp_list.append(
852 pt_up_device_to_ofp_avg)
andrewonlababb11c32014-11-04 15:03:24 -0500853 main.log.info("Port up: device to ofp avg: "+
854 str(pt_up_device_to_ofp_avg) + " ms")
andrewonlab3622beb2014-10-28 16:07:56 -0400855 else:
andrewonlababb11c32014-11-04 15:03:24 -0500856 main.log.info("Average port up device-to-ofp result"+
andrewonlab3622beb2014-10-28 16:07:56 -0400857 " exceeded the threshold: "+
858 str(pt_up_device_to_ofp_avg))
andrewonlab8d29f122014-10-22 17:15:04 -0400859
andrewonlab3622beb2014-10-28 16:07:56 -0400860 #END ITERATION FOR LOOP
andrewonlab8790abb2014-11-06 13:51:54 -0500861
862 #Check all list for latency existence and set assertion
863 if (port_down_graph_to_ofp_list and port_down_device_to_ofp_list\
864 and port_up_graph_to_ofp_list and port_up_device_to_ofp_list):
865 assertion = main.TRUE
866
andrewonlababb11c32014-11-04 15:03:24 -0500867 #Calculate and report latency measurements
andrewonlab3622beb2014-10-28 16:07:56 -0400868 port_down_graph_to_ofp_min = min(port_down_graph_to_ofp_list)
869 port_down_graph_to_ofp_max = max(port_down_graph_to_ofp_list)
870 port_down_graph_to_ofp_avg = \
871 (sum(port_down_graph_to_ofp_list) /
872 len(port_down_graph_to_ofp_list))
andrewonlab69864162014-11-11 16:28:48 -0500873 port_down_graph_to_ofp_std_dev = \
874 str(round(numpy.std(port_down_graph_to_ofp_list),1))
andrewonlab3622beb2014-10-28 16:07:56 -0400875
andrewonlab4f50ec92014-11-11 14:24:45 -0500876 main.log.report("Port down graph-to-ofp "+
877 "Avg: "+str(port_down_graph_to_ofp_avg)+" ms "+
andrewonlab69864162014-11-11 16:28:48 -0500878 "Std Deviation: "+port_down_graph_to_ofp_std_dev+" ms")
andrewonlababb11c32014-11-04 15:03:24 -0500879
880 port_down_device_to_ofp_min = min(port_down_device_to_ofp_list)
881 port_down_device_to_ofp_max = max(port_down_device_to_ofp_list)
882 port_down_device_to_ofp_avg = \
883 (sum(port_down_device_to_ofp_list) /\
884 len(port_down_device_to_ofp_list))
andrewonlab69864162014-11-11 16:28:48 -0500885 port_down_device_to_ofp_std_dev = \
886 str(round(numpy.std(port_down_device_to_ofp_list),1))
andrewonlababb11c32014-11-04 15:03:24 -0500887
andrewonlab4f50ec92014-11-11 14:24:45 -0500888 main.log.report("Port down device-to-ofp "+
889 "Avg: "+str(port_down_device_to_ofp_avg)+" ms "+
andrewonlab69864162014-11-11 16:28:48 -0500890 "Std Deviation: "+port_down_device_to_ofp_std_dev+" ms")
andrewonlababb11c32014-11-04 15:03:24 -0500891
892 port_up_graph_to_ofp_min = min(port_up_graph_to_ofp_list)
893 port_up_graph_to_ofp_max = max(port_up_graph_to_ofp_list)
894 port_up_graph_to_ofp_avg = \
895 (sum(port_up_graph_to_ofp_list) /\
896 len(port_up_graph_to_ofp_list))
andrewonlab69864162014-11-11 16:28:48 -0500897 port_up_graph_to_ofp_std_dev = \
898 str(round(numpy.std(port_up_graph_to_ofp_list),1))
andrewonlab8790abb2014-11-06 13:51:54 -0500899
andrewonlab4f50ec92014-11-11 14:24:45 -0500900 main.log.report("Port up graph-to-ofp "+
901 "Avg: "+str(port_up_graph_to_ofp_avg)+" ms "+
andrewonlab69864162014-11-11 16:28:48 -0500902 "Std Deviation: "+port_up_graph_to_ofp_std_dev+" ms")
andrewonlab8790abb2014-11-06 13:51:54 -0500903
904 port_up_device_to_ofp_min = min(port_up_device_to_ofp_list)
905 port_up_device_to_ofp_max = max(port_up_device_to_ofp_list)
906 port_up_device_to_ofp_avg = \
907 (sum(port_up_device_to_ofp_list) /\
908 len(port_up_device_to_ofp_list))
andrewonlab69864162014-11-11 16:28:48 -0500909 port_up_device_to_ofp_std_dev = \
910 str(round(numpy.std(port_up_device_to_ofp_list),1))
andrewonlab8790abb2014-11-06 13:51:54 -0500911
andrewonlab4f50ec92014-11-11 14:24:45 -0500912 main.log.report("Port up device-to-ofp "+
913 "Avg: "+str(port_up_device_to_ofp_avg)+" ms "+
andrewonlab69864162014-11-11 16:28:48 -0500914 "Std Deviation: "+port_up_device_to_ofp_std_dev+" ms")
andrewonlab8790abb2014-11-06 13:51:54 -0500915
916 utilities.assert_equals(expect=main.TRUE, actual=assertion,
917 onpass="Port discovery latency calculation successful",
918 onfail="Port discovery test failed")
andrewonlababb11c32014-11-04 15:03:24 -0500919
andrewonlab3622beb2014-10-28 16:07:56 -0400920 def CASE4(self, main):
921 '''
922 Link down event using loss rate 100%
andrewonlab53b641c2014-10-31 19:44:44 -0400923
924 Important:
925 Use a simple 2 switch topology with 1 link between
926 the two switches. Ensure that mac addresses of the
927 switches are 1 / 2 respectively
andrewonlab3622beb2014-10-28 16:07:56 -0400928 '''
929 import time
930 import subprocess
931 import os
932 import requests
933 import json
andrewonlab4f50ec92014-11-11 14:24:45 -0500934 import numpy
935
andrewonlab3622beb2014-10-28 16:07:56 -0400936 ONOS1_ip = main.params['CTRL']['ip1']
937 ONOS2_ip = main.params['CTRL']['ip2']
938 ONOS3_ip = main.params['CTRL']['ip3']
939 ONOS_user = main.params['CTRL']['user']
940
941 default_sw_port = main.params['CTRL']['port1']
942
943 #Number of iterations of case
944 num_iter = main.params['TEST']['numIter']
945
946 #Timestamp 'keys' for json metrics output.
947 #These are subject to change, hence moved into params
948 deviceTimestamp = main.params['JSON']['deviceTimestamp']
949 linkTimestamp = main.params['JSON']['linkTimestamp']
andrewonlab53b641c2014-10-31 19:44:44 -0400950 graphTimestamp = main.params['JSON']['graphTimestamp']
andrewonlab58f7d702014-11-07 13:21:19 -0500951
952 debug_mode = main.params['TEST']['debugMode']
953
954 local_time = time.strftime('%x %X')
andrewonlabb1998c52014-11-10 13:31:43 -0500955 local_time = local_time.replace("/","")
956 local_time = local_time.replace(" ","_")
957 local_time = local_time.replace(":","")
andrewonlab58f7d702014-11-07 13:21:19 -0500958 if debug_mode == 'on':
959 main.ONOS1.tshark_pcap("eth0",
andrewonlabb1998c52014-11-10 13:31:43 -0500960 "/tmp/link_lat_pcap_"+local_time)
andrewonlab53b641c2014-10-31 19:44:44 -0400961
andrewonlabe5bcef92014-11-06 17:53:20 -0500962 #Threshold for this test case
963 up_threshold_str = main.params['TEST']['linkUpThreshold']
964 down_threshold_str = main.params['TEST']['linkDownThreshold']
965
966 up_threshold_obj = up_threshold_str.split(",")
967 down_threshold_obj = down_threshold_str.split(",")
968
969 up_threshold_min = int(up_threshold_obj[0])
970 up_threshold_max = int(up_threshold_obj[1])
971
972 down_threshold_min = int(down_threshold_obj[0])
973 down_threshold_max = int(down_threshold_obj[1])
974
andrewonlab3622beb2014-10-28 16:07:56 -0400975 assertion = main.TRUE
976 #Link event timestamp to system time list
977 link_down_link_to_system_list = []
978 link_up_link_to_system_list = []
979 #Graph event timestamp to system time list
980 link_down_graph_to_system_list = []
981 link_up_graph_to_system_list = []
982
andrewonlab4b5c8b92014-11-10 16:04:33 -0500983 main.log.report("Link up / down discovery latency between "+
andrewonlab3622beb2014-10-28 16:07:56 -0400984 "two switches")
andrewonlab4b5c8b92014-11-10 16:04:33 -0500985 main.log.report("Simulated by setting loss-rate 100%")
986 main.log.report("'tc qdisc add dev <intfs> root netem loss 100%'")
987 main.log.report("Total iterations of test: "+str(num_iter))
andrewonlab3622beb2014-10-28 16:07:56 -0400988
989 main.step("Assign all switches")
990 main.Mininet1.assign_sw_controller(sw="1",
991 ip1=ONOS1_ip, port1=default_sw_port)
992 main.Mininet1.assign_sw_controller(sw="2",
993 ip1=ONOS1_ip, port1=default_sw_port)
994
995 main.step("Verifying switch assignment")
996 result_s1 = main.Mininet1.get_sw_controller(sw="s1")
997 result_s2 = main.Mininet1.get_sw_controller(sw="s2")
andrewonlab3622beb2014-10-28 16:07:56 -0400998
999 #Allow time for events to finish before taking measurements
1000 time.sleep(10)
1001
andrewonlababb11c32014-11-04 15:03:24 -05001002 link_down1 = False
1003 link_down2 = False
1004 link_down3 = False
andrewonlab3622beb2014-10-28 16:07:56 -04001005 #Start iteration of link event test
1006 for i in range(0, int(num_iter)):
1007 main.step("Getting initial system time as t0")
andrewonlab8d29f122014-10-22 17:15:04 -04001008
andrewonlab3622beb2014-10-28 16:07:56 -04001009 timestamp_link_down_t0 = time.time() * 1000
1010 #Link down is simulated by 100% loss rate using traffic
1011 #control command
1012 main.Mininet1.handle.sendline(
1013 "sh tc qdisc add dev s1-eth1 root netem loss 100%")
1014
andrewonlab53b641c2014-10-31 19:44:44 -04001015 #TODO: Iterate through 'links' command to verify that
andrewonlababb11c32014-11-04 15:03:24 -05001016 # link s1 -> s2 went down (loop timeout 30 seconds)
1017 # on all 3 ONOS instances
andrewonlab53b641c2014-10-31 19:44:44 -04001018 main.log.info("Checking ONOS for link update")
1019 loop_count = 0
andrewonlababb11c32014-11-04 15:03:24 -05001020 while( not (link_down1 and link_down2 and link_down3)\
1021 and loop_count < 30 ):
1022 json_str1 = main.ONOS1cli.links()
1023 json_str2 = main.ONOS2cli.links()
1024 json_str3 = main.ONOS3cli.links()
1025
1026 if not (json_str1 and json_str2 and json_str3):
1027 main.log.error("CLI command returned error ")
andrewonlab53b641c2014-10-31 19:44:44 -04001028 break
1029 else:
andrewonlababb11c32014-11-04 15:03:24 -05001030 json_obj1 = json.loads(json_str1)
1031 json_obj2 = json.loads(json_str2)
1032 json_obj3 = json.loads(json_str3)
1033 for obj1 in json_obj1:
1034 if '01' not in obj1['src']['device']:
1035 link_down1 = True
andrewonlabf9828f02014-11-10 14:50:27 -05001036 main.log.info("Link down from "+
andrewonlababb11c32014-11-04 15:03:24 -05001037 "s1 -> s2 on ONOS1 detected")
1038 for obj2 in json_obj2:
1039 if '01' not in obj2['src']['device']:
1040 link_down2 = True
andrewonlabf9828f02014-11-10 14:50:27 -05001041 main.log.info("Link down from "+
andrewonlababb11c32014-11-04 15:03:24 -05001042 "s1 -> s2 on ONOS2 detected")
1043 for obj3 in json_obj3:
1044 if '01' not in obj3['src']['device']:
1045 link_down3 = True
andrewonlabf9828f02014-11-10 14:50:27 -05001046 main.log.info("Link down from "+
andrewonlababb11c32014-11-04 15:03:24 -05001047 "s1 -> s2 on ONOS3 detected")
1048
andrewonlab53b641c2014-10-31 19:44:44 -04001049 loop_count += 1
andrewonlababb11c32014-11-04 15:03:24 -05001050 #If CLI doesn't like the continuous requests
1051 #and exits in this loop, increase the sleep here.
1052 #Consequently, while loop timeout will increase
andrewonlab53b641c2014-10-31 19:44:44 -04001053 time.sleep(1)
1054
1055 #Give time for metrics measurement to catch up
andrewonlababb11c32014-11-04 15:03:24 -05001056 #NOTE: May need to be configured more accurately
andrewonlab53b641c2014-10-31 19:44:44 -04001057 time.sleep(10)
andrewonlababb11c32014-11-04 15:03:24 -05001058 #If we exited the while loop and link down 1,2,3 are still
andrewonlab53b641c2014-10-31 19:44:44 -04001059 #false, then ONOS has failed to discover link down event
andrewonlababb11c32014-11-04 15:03:24 -05001060 if not (link_down1 and link_down2 and link_down3):
andrewonlab53b641c2014-10-31 19:44:44 -04001061 main.log.info("Link down discovery failed")
1062
1063 link_down_lat_graph1 = 0
1064 link_down_lat_graph2 = 0
1065 link_down_lat_graph3 = 0
1066 link_down_lat_device1 = 0
1067 link_down_lat_device2 = 0
1068 link_down_lat_device3 = 0
1069
1070 assertion = main.FALSE
1071 else:
1072 json_topo_metrics_1 =\
1073 main.ONOS1cli.topology_events_metrics()
1074 json_topo_metrics_2 =\
1075 main.ONOS2cli.topology_events_metrics()
1076 json_topo_metrics_3 =\
1077 main.ONOS3cli.topology_events_metrics()
1078 json_topo_metrics_1 = json.loads(json_topo_metrics_1)
1079 json_topo_metrics_2 = json.loads(json_topo_metrics_2)
1080 json_topo_metrics_3 = json.loads(json_topo_metrics_3)
1081
1082 main.log.info("Obtaining graph and device timestamp")
1083 graph_timestamp_1 = \
1084 json_topo_metrics_1[graphTimestamp]['value']
1085 graph_timestamp_2 = \
1086 json_topo_metrics_2[graphTimestamp]['value']
1087 graph_timestamp_3 = \
1088 json_topo_metrics_3[graphTimestamp]['value']
1089
1090 link_timestamp_1 = \
1091 json_topo_metrics_1[linkTimestamp]['value']
1092 link_timestamp_2 = \
1093 json_topo_metrics_2[linkTimestamp]['value']
1094 link_timestamp_3 = \
1095 json_topo_metrics_3[linkTimestamp]['value']
1096
1097 if graph_timestamp_1 and graph_timestamp_2 and\
1098 graph_timestamp_3 and link_timestamp_1 and\
1099 link_timestamp_2 and link_timestamp_3:
1100 link_down_lat_graph1 = int(graph_timestamp_1) -\
andrewonlab4f50ec92014-11-11 14:24:45 -05001101 int(timestamp_link_down_t0)
andrewonlab53b641c2014-10-31 19:44:44 -04001102 link_down_lat_graph2 = int(graph_timestamp_2) -\
andrewonlab4f50ec92014-11-11 14:24:45 -05001103 int(timestamp_link_down_t0)
andrewonlab53b641c2014-10-31 19:44:44 -04001104 link_down_lat_graph3 = int(graph_timestamp_3) -\
andrewonlab4f50ec92014-11-11 14:24:45 -05001105 int(timestamp_link_down_t0)
andrewonlab53b641c2014-10-31 19:44:44 -04001106
1107 link_down_lat_link1 = int(link_timestamp_1) -\
andrewonlab4f50ec92014-11-11 14:24:45 -05001108 int(timestamp_link_down_t0)
andrewonlab53b641c2014-10-31 19:44:44 -04001109 link_down_lat_link2 = int(link_timestamp_2) -\
andrewonlab4f50ec92014-11-11 14:24:45 -05001110 int(timestamp_link_down_t0)
andrewonlab53b641c2014-10-31 19:44:44 -04001111 link_down_lat_link3 = int(link_timestamp_3) -\
andrewonlab4f50ec92014-11-11 14:24:45 -05001112 int(timestamp_link_down_t0)
andrewonlab53b641c2014-10-31 19:44:44 -04001113 else:
1114 main.log.error("There was an error calculating"+
1115 " the delta for link down event")
1116 link_down_lat_graph1 = 0
1117 link_down_lat_graph2 = 0
1118 link_down_lat_graph3 = 0
1119
1120 link_down_lat_device1 = 0
1121 link_down_lat_device2 = 0
1122 link_down_lat_device3 = 0
1123
andrewonlabf9828f02014-11-10 14:50:27 -05001124 main.log.info("Link down latency ONOS1 iteration "+
andrewonlab4e124482014-11-04 13:37:25 -05001125 str(i)+" (end-to-end): "+
andrewonlababb11c32014-11-04 15:03:24 -05001126 str(link_down_lat_graph1)+" ms")
andrewonlabf9828f02014-11-10 14:50:27 -05001127 main.log.info("Link down latency ONOS2 iteration "+
andrewonlab4e124482014-11-04 13:37:25 -05001128 str(i)+" (end-to-end): "+
andrewonlababb11c32014-11-04 15:03:24 -05001129 str(link_down_lat_graph2)+" ms")
andrewonlabf9828f02014-11-10 14:50:27 -05001130 main.log.info("Link down latency ONOS3 iteration "+
andrewonlab4e124482014-11-04 13:37:25 -05001131 str(i)+" (end-to-end): "+
andrewonlababb11c32014-11-04 15:03:24 -05001132 str(link_down_lat_graph3)+" ms")
andrewonlab4e124482014-11-04 13:37:25 -05001133
andrewonlabf9828f02014-11-10 14:50:27 -05001134 main.log.info("Link down latency ONOS1 iteration "+
andrewonlab4e124482014-11-04 13:37:25 -05001135 str(i)+" (link-event-to-system-timestamp): "+
andrewonlababb11c32014-11-04 15:03:24 -05001136 str(link_down_lat_link1)+" ms")
andrewonlabf9828f02014-11-10 14:50:27 -05001137 main.log.info("Link down latency ONOS2 iteration "+
andrewonlab4e124482014-11-04 13:37:25 -05001138 str(i)+" (link-event-to-system-timestamp): "+
andrewonlababb11c32014-11-04 15:03:24 -05001139 str(link_down_lat_link2)+" ms")
andrewonlabf9828f02014-11-10 14:50:27 -05001140 main.log.info("Link down latency ONOS3 iteration "+
andrewonlab4e124482014-11-04 13:37:25 -05001141 str(i)+" (link-event-to-system-timestamp): "+
1142 str(link_down_lat_link3))
1143
1144 #Calculate avg of node calculations
1145 link_down_lat_graph_avg =\
andrewonlababb11c32014-11-04 15:03:24 -05001146 (link_down_lat_graph1 +
1147 link_down_lat_graph2 +
andrewonlab65d73892014-11-10 17:36:00 -05001148 link_down_lat_graph3) / 3
andrewonlab4e124482014-11-04 13:37:25 -05001149 link_down_lat_link_avg =\
andrewonlababb11c32014-11-04 15:03:24 -05001150 (link_down_lat_link1 +
1151 link_down_lat_link2 +
andrewonlab65d73892014-11-10 17:36:00 -05001152 link_down_lat_link3) / 3
andrewonlab53b641c2014-10-31 19:44:44 -04001153
andrewonlab4e124482014-11-04 13:37:25 -05001154 #Set threshold and append latency to list
andrewonlabe5bcef92014-11-06 17:53:20 -05001155 if link_down_lat_graph_avg > down_threshold_min and\
1156 link_down_lat_graph_avg < down_threshold_max:
andrewonlab4e124482014-11-04 13:37:25 -05001157 link_down_graph_to_system_list.append(
1158 link_down_lat_graph_avg)
andrewonlab8790abb2014-11-06 13:51:54 -05001159 else:
1160 main.log.info("Link down latency exceeded threshold")
1161 main.log.info("Results for iteration "+str(i)+
1162 "have been omitted")
andrewonlabe5bcef92014-11-06 17:53:20 -05001163 if link_down_lat_link_avg > down_threshold_min and\
1164 link_down_lat_link_avg < down_threshold_max:
andrewonlab4e124482014-11-04 13:37:25 -05001165 link_down_link_to_system_list.append(
1166 link_down_lat_link_avg)
andrewonlab8790abb2014-11-06 13:51:54 -05001167 else:
1168 main.log.info("Link down latency exceeded threshold")
1169 main.log.info("Results for iteration "+str(i)+
1170 "have been omitted")
andrewonlab53b641c2014-10-31 19:44:44 -04001171
1172 #NOTE: To remove loss rate and measure latency:
1173 # 'sh tc qdisc del dev s1-eth1 root'
andrewonlababb11c32014-11-04 15:03:24 -05001174 timestamp_link_up_t0 = time.time() * 1000
andrewonlab53b641c2014-10-31 19:44:44 -04001175 main.Mininet1.handle.sendline("sh tc qdisc del dev "+
1176 "s1-eth1 root")
1177 main.Mininet1.handle.expect("mininet>")
andrewonlababb11c32014-11-04 15:03:24 -05001178
1179 main.log.info("Checking ONOS for link update")
1180
1181 link_down1 = True
1182 link_down2 = True
1183 link_down3 = True
1184 loop_count = 0
1185 while( (link_down1 and link_down2 and link_down3)\
1186 and loop_count < 30 ):
1187 json_str1 = main.ONOS1cli.links()
1188 json_str2 = main.ONOS2cli.links()
1189 json_str3 = main.ONOS3cli.links()
1190 if not (json_str1 and json_str2 and json_str3):
1191 main.log.error("CLI command returned error ")
1192 break
1193 else:
1194 json_obj1 = json.loads(json_str1)
1195 json_obj2 = json.loads(json_str2)
1196 json_obj3 = json.loads(json_str3)
1197
1198 for obj1 in json_obj1:
1199 if '01' in obj1['src']['device']:
1200 link_down1 = False
andrewonlabf9828f02014-11-10 14:50:27 -05001201 main.log.info("Link up from "+
andrewonlababb11c32014-11-04 15:03:24 -05001202 "s1 -> s2 on ONOS1 detected")
1203 for obj2 in json_obj2:
1204 if '01' in obj2['src']['device']:
1205 link_down2 = False
andrewonlabf9828f02014-11-10 14:50:27 -05001206 main.log.info("Link up from "+
andrewonlababb11c32014-11-04 15:03:24 -05001207 "s1 -> s2 on ONOS2 detected")
1208 for obj3 in json_obj3:
1209 if '01' in obj3['src']['device']:
1210 link_down3 = False
andrewonlabf9828f02014-11-10 14:50:27 -05001211 main.log.info("Link up from "+
andrewonlababb11c32014-11-04 15:03:24 -05001212 "s1 -> s2 on ONOS3 detected")
1213
1214 loop_count += 1
1215 time.sleep(1)
1216
1217 if (link_down1 and link_down2 and link_down3):
1218 main.log.info("Link up discovery failed")
1219
1220 link_up_lat_graph1 = 0
1221 link_up_lat_graph2 = 0
1222 link_up_lat_graph3 = 0
1223 link_up_lat_device1 = 0
1224 link_up_lat_device2 = 0
1225 link_up_lat_device3 = 0
1226
1227 assertion = main.FALSE
1228 else:
1229 json_topo_metrics_1 =\
1230 main.ONOS1cli.topology_events_metrics()
1231 json_topo_metrics_2 =\
1232 main.ONOS2cli.topology_events_metrics()
1233 json_topo_metrics_3 =\
1234 main.ONOS3cli.topology_events_metrics()
1235 json_topo_metrics_1 = json.loads(json_topo_metrics_1)
1236 json_topo_metrics_2 = json.loads(json_topo_metrics_2)
1237 json_topo_metrics_3 = json.loads(json_topo_metrics_3)
1238
1239 main.log.info("Obtaining graph and device timestamp")
1240 graph_timestamp_1 = \
1241 json_topo_metrics_1[graphTimestamp]['value']
1242 graph_timestamp_2 = \
1243 json_topo_metrics_2[graphTimestamp]['value']
1244 graph_timestamp_3 = \
1245 json_topo_metrics_3[graphTimestamp]['value']
1246
1247 link_timestamp_1 = \
1248 json_topo_metrics_1[linkTimestamp]['value']
1249 link_timestamp_2 = \
1250 json_topo_metrics_2[linkTimestamp]['value']
1251 link_timestamp_3 = \
1252 json_topo_metrics_3[linkTimestamp]['value']
1253
1254 if graph_timestamp_1 and graph_timestamp_2 and\
1255 graph_timestamp_3 and link_timestamp_1 and\
1256 link_timestamp_2 and link_timestamp_3:
1257 link_up_lat_graph1 = int(graph_timestamp_1) -\
andrewonlab4f50ec92014-11-11 14:24:45 -05001258 int(timestamp_link_up_t0)
andrewonlababb11c32014-11-04 15:03:24 -05001259 link_up_lat_graph2 = int(graph_timestamp_2) -\
andrewonlab4f50ec92014-11-11 14:24:45 -05001260 int(timestamp_link_up_t0)
andrewonlababb11c32014-11-04 15:03:24 -05001261 link_up_lat_graph3 = int(graph_timestamp_3) -\
andrewonlab4f50ec92014-11-11 14:24:45 -05001262 int(timestamp_link_up_t0)
andrewonlababb11c32014-11-04 15:03:24 -05001263
1264 link_up_lat_link1 = int(link_timestamp_1) -\
andrewonlab4f50ec92014-11-11 14:24:45 -05001265 int(timestamp_link_up_t0)
andrewonlababb11c32014-11-04 15:03:24 -05001266 link_up_lat_link2 = int(link_timestamp_2) -\
andrewonlab4f50ec92014-11-11 14:24:45 -05001267 int(timestamp_link_up_t0)
andrewonlababb11c32014-11-04 15:03:24 -05001268 link_up_lat_link3 = int(link_timestamp_3) -\
andrewonlab4f50ec92014-11-11 14:24:45 -05001269 int(timestamp_link_up_t0)
andrewonlababb11c32014-11-04 15:03:24 -05001270 else:
1271 main.log.error("There was an error calculating"+
1272 " the delta for link down event")
1273 link_up_lat_graph1 = 0
1274 link_up_lat_graph2 = 0
1275 link_up_lat_graph3 = 0
1276
1277 link_up_lat_device1 = 0
1278 link_up_lat_device2 = 0
1279 link_up_lat_device3 = 0
andrewonlab58f7d702014-11-07 13:21:19 -05001280
1281 if debug_mode == 'on':
1282 main.log.info("Link up latency ONOS1 iteration "+
andrewonlababb11c32014-11-04 15:03:24 -05001283 str(i)+" (end-to-end): "+
1284 str(link_up_lat_graph1)+" ms")
andrewonlab58f7d702014-11-07 13:21:19 -05001285 main.log.info("Link up latency ONOS2 iteration "+
andrewonlababb11c32014-11-04 15:03:24 -05001286 str(i)+" (end-to-end): "+
1287 str(link_up_lat_graph2)+" ms")
andrewonlab58f7d702014-11-07 13:21:19 -05001288 main.log.info("Link up latency ONOS3 iteration "+
andrewonlababb11c32014-11-04 15:03:24 -05001289 str(i)+" (end-to-end): "+
1290 str(link_up_lat_graph3)+" ms")
1291
andrewonlab58f7d702014-11-07 13:21:19 -05001292 main.log.info("Link up latency ONOS1 iteration "+
andrewonlababb11c32014-11-04 15:03:24 -05001293 str(i)+" (link-event-to-system-timestamp): "+
1294 str(link_up_lat_link1)+" ms")
andrewonlab58f7d702014-11-07 13:21:19 -05001295 main.log.info("Link up latency ONOS2 iteration "+
andrewonlababb11c32014-11-04 15:03:24 -05001296 str(i)+" (link-event-to-system-timestamp): "+
1297 str(link_up_lat_link2)+" ms")
andrewonlab58f7d702014-11-07 13:21:19 -05001298 main.log.info("Link up latency ONOS3 iteration "+
andrewonlababb11c32014-11-04 15:03:24 -05001299 str(i)+" (link-event-to-system-timestamp): "+
1300 str(link_up_lat_link3))
1301
1302 #Calculate avg of node calculations
1303 link_up_lat_graph_avg =\
1304 (link_up_lat_graph1 +
1305 link_up_lat_graph2 +
andrewonlabf9828f02014-11-10 14:50:27 -05001306 link_up_lat_graph3) / 3
andrewonlababb11c32014-11-04 15:03:24 -05001307 link_up_lat_link_avg =\
1308 (link_up_lat_link1 +
1309 link_up_lat_link2 +
andrewonlabf9828f02014-11-10 14:50:27 -05001310 link_up_lat_link3) / 3
andrewonlababb11c32014-11-04 15:03:24 -05001311
1312 #Set threshold and append latency to list
andrewonlabe5bcef92014-11-06 17:53:20 -05001313 if link_up_lat_graph_avg > up_threshold_min and\
1314 link_up_lat_graph_avg < up_threshold_max:
andrewonlababb11c32014-11-04 15:03:24 -05001315 link_up_graph_to_system_list.append(
1316 link_up_lat_graph_avg)
andrewonlab8790abb2014-11-06 13:51:54 -05001317 else:
1318 main.log.info("Link up latency exceeded threshold")
1319 main.log.info("Results for iteration "+str(i)+
1320 "have been omitted")
andrewonlabe5bcef92014-11-06 17:53:20 -05001321 if link_up_lat_link_avg > up_threshold_min and\
1322 link_up_lat_link_avg < up_threshold_max:
andrewonlababb11c32014-11-04 15:03:24 -05001323 link_up_link_to_system_list.append(
1324 link_up_lat_link_avg)
andrewonlab8790abb2014-11-06 13:51:54 -05001325 else:
1326 main.log.info("Link up latency exceeded threshold")
1327 main.log.info("Results for iteration "+str(i)+
1328 "have been omitted")
andrewonlab53b641c2014-10-31 19:44:44 -04001329
andrewonlab4e124482014-11-04 13:37:25 -05001330 #Calculate min, max, avg of list and report
1331 link_down_min = min(link_down_graph_to_system_list)
1332 link_down_max = max(link_down_graph_to_system_list)
1333 link_down_avg = sum(link_down_graph_to_system_list) / \
1334 len(link_down_graph_to_system_list)
andrewonlababb11c32014-11-04 15:03:24 -05001335 link_up_min = min(link_up_graph_to_system_list)
1336 link_up_max = max(link_up_graph_to_system_list)
1337 link_up_avg = sum(link_up_graph_to_system_list) / \
1338 len(link_up_graph_to_system_list)
andrewonlab69864162014-11-11 16:28:48 -05001339 link_down_std_dev = \
1340 str(round(numpy.std(link_down_graph_to_system_list),1))
1341 link_up_std_dev = \
1342 str(round(numpy.std(link_up_graph_to_system_list),1))
andrewonlababb11c32014-11-04 15:03:24 -05001343
andrewonlab4f50ec92014-11-11 14:24:45 -05001344 main.log.report("Link down latency " +
1345 "Avg: "+str(link_down_avg)+" ms "+
andrewonlab69864162014-11-11 16:28:48 -05001346 "Std Deviation: "+link_down_std_dev+" ms")
andrewonlab4f50ec92014-11-11 14:24:45 -05001347 main.log.report("Link up latency "+
1348 "Avg: "+str(link_up_avg)+" ms "+
andrewonlab69864162014-11-11 16:28:48 -05001349 "Std Deviation: "+link_up_std_dev+" ms")
andrewonlab4e124482014-11-04 13:37:25 -05001350
andrewonlab8790abb2014-11-06 13:51:54 -05001351 utilities.assert_equals(expect=main.TRUE, actual=assertion,
1352 onpass="Link discovery latency calculation successful",
1353 onfail="Link discovery latency case failed")
1354
andrewonlabb54b85b2014-10-28 18:43:57 -04001355 def CASE5(self, main):
1356 '''
1357 100 Switch discovery latency
1358
1359 Important:
andrewonlab16ce4852014-10-30 13:41:09 -04001360 This test case can be potentially dangerous if
1361 your machine has previously set iptables rules.
1362 One of the steps of the test case will flush
1363 all existing iptables rules.
andrewonlab8790abb2014-11-06 13:51:54 -05001364 Note:
1365 You can specify the number of switches in the
1366 params file to adjust the switch discovery size
1367 (and specify the corresponding topology in Mininet1
1368 .topo file)
andrewonlabb54b85b2014-10-28 18:43:57 -04001369 '''
1370 import time
1371 import subprocess
1372 import os
1373 import requests
1374 import json
1375
1376 ONOS1_ip = main.params['CTRL']['ip1']
1377 ONOS2_ip = main.params['CTRL']['ip2']
1378 ONOS3_ip = main.params['CTRL']['ip3']
1379 MN1_ip = main.params['MN']['ip1']
1380 ONOS_user = main.params['CTRL']['user']
1381
1382 default_sw_port = main.params['CTRL']['port1']
1383
1384 #Number of iterations of case
1385 num_iter = main.params['TEST']['numIter']
andrewonlab16ce4852014-10-30 13:41:09 -04001386 num_sw = main.params['TEST']['numSwitch']
1387
andrewonlabb54b85b2014-10-28 18:43:57 -04001388 #Timestamp 'keys' for json metrics output.
1389 #These are subject to change, hence moved into params
1390 deviceTimestamp = main.params['JSON']['deviceTimestamp']
andrewonlab16ce4852014-10-30 13:41:09 -04001391 graphTimestamp = main.params['JSON']['graphTimestamp']
andrewonlab58f7d702014-11-07 13:21:19 -05001392
1393 debug_mode = main.params['TEST']['debugMode']
1394
andrewonlabb1998c52014-11-10 13:31:43 -05001395 local_time = time.strftime('%X')
1396 local_time = local_time.replace("/","")
1397 local_time = local_time.replace(" ","_")
1398 local_time = local_time.replace(":","")
andrewonlab58f7d702014-11-07 13:21:19 -05001399 if debug_mode == 'on':
1400 main.ONOS1.tshark_pcap("eth0",
andrewonlabb1998c52014-11-10 13:31:43 -05001401 "/tmp/100_sw_lat_pcap_"+local_time)
andrewonlabe5bcef92014-11-06 17:53:20 -05001402
1403 #Threshold for this test case
1404 sw_disc_threshold_str = main.params['TEST']['swDisc100Threshold']
1405 sw_disc_threshold_obj = sw_disc_threshold_str.split(",")
1406 sw_disc_threshold_min = int(sw_disc_threshold_obj[0])
1407 sw_disc_threshold_max = int(sw_disc_threshold_obj[1])
1408
andrewonlab53b641c2014-10-31 19:44:44 -04001409 tshark_ofp_output = "/tmp/tshark_ofp_"+num_sw+"sw.txt"
1410 tshark_tcp_output = "/tmp/tshark_tcp_"+num_sw+"sw.txt"
1411
1412 tshark_ofp_result_list = []
1413 tshark_tcp_result_list = []
andrewonlabb54b85b2014-10-28 18:43:57 -04001414
andrewonlabe5bcef92014-11-06 17:53:20 -05001415 sw_discovery_lat_list = []
1416
andrewonlab16ce4852014-10-30 13:41:09 -04001417 main.case(num_sw+" Switch discovery latency")
andrewonlabb54b85b2014-10-28 18:43:57 -04001418 main.step("Assigning all switches to ONOS1")
andrewonlab16ce4852014-10-30 13:41:09 -04001419 for i in range(1, int(num_sw)+1):
andrewonlabb54b85b2014-10-28 18:43:57 -04001420 main.Mininet1.assign_sw_controller(
1421 sw=str(i),
1422 ip1=ONOS1_ip,
1423 port1=default_sw_port)
andrewonlab16ce4852014-10-30 13:41:09 -04001424
andrewonlabb54b85b2014-10-28 18:43:57 -04001425 #Ensure that nodes are configured with ptpd
andrewonlab16ce4852014-10-30 13:41:09 -04001426 #Just a warning message
1427 main.log.info("Please check ptpd configuration to ensure"+\
1428 " All nodes' system times are in sync")
1429 time.sleep(5)
andrewonlabb54b85b2014-10-28 18:43:57 -04001430
1431 for i in range(0, int(num_iter)):
andrewonlab8d29f122014-10-22 17:15:04 -04001432
andrewonlabb54b85b2014-10-28 18:43:57 -04001433 main.step("Set iptables rule to block incoming sw connections")
1434 #Set iptables rule to block incoming switch connections
andrewonlab53b641c2014-10-31 19:44:44 -04001435 #The rule description is as follows:
1436 # Append to INPUT rule,
1437 # behavior DROP that matches following:
1438 # * packet type: tcp
1439 # * source IP: MN1_ip
1440 # * destination PORT: 6633
andrewonlabb54b85b2014-10-28 18:43:57 -04001441 main.ONOS1.handle.sendline(
andrewonlab16ce4852014-10-30 13:41:09 -04001442 "sudo iptables -A INPUT -p tcp -s "+MN1_ip+
andrewonlabb54b85b2014-10-28 18:43:57 -04001443 " --dport "+default_sw_port+" -j DROP")
1444 main.ONOS1.handle.expect("\$")
andrewonlab53b641c2014-10-31 19:44:44 -04001445 # Append to OUTPUT rule,
1446 # behavior DROP that matches following:
1447 # * packet type: tcp
1448 # * source IP: MN1_ip
1449 # * destination PORT: 6633
1450 main.ONOS1.handle.sendline(
1451 "sudo iptables -A OUTPUT -p tcp -s "+MN1_ip+
1452 " --dport "+default_sw_port+" -j DROP")
1453 main.ONOS1.handle.expect("\$")
andrewonlabb54b85b2014-10-28 18:43:57 -04001454 #Give time to allow rule to take effect
andrewonlab8790abb2014-11-06 13:51:54 -05001455 #NOTE: Sleep period may need to be configured
1456 # based on the number of switches in the topology
andrewonlab16ce4852014-10-30 13:41:09 -04001457 main.log.info("Please wait for switch connection to "+
1458 "time out")
1459 time.sleep(60)
1460
1461 #Gather vendor OFP with tshark
1462 main.ONOS1.tshark_grep("OFP 86 Vendor",
1463 tshark_ofp_output)
andrewonlab53b641c2014-10-31 19:44:44 -04001464 main.ONOS1.tshark_grep("TCP 74 ",
1465 tshark_tcp_output)
andrewonlabb54b85b2014-10-28 18:43:57 -04001466
andrewonlab16ce4852014-10-30 13:41:09 -04001467 #NOTE: Remove all iptables rule quickly (flush)
andrewonlabb54b85b2014-10-28 18:43:57 -04001468 # Before removal, obtain TestON timestamp at which
andrewonlab16ce4852014-10-30 13:41:09 -04001469 # removal took place
1470 # (ensuring nodes are configured via ptp)
andrewonlabb54b85b2014-10-28 18:43:57 -04001471 # sudo iptables -F
andrewonlab16ce4852014-10-30 13:41:09 -04001472
1473 t0_system = time.time() * 1000
1474 main.ONOS1.handle.sendline(
1475 "sudo iptables -F")
andrewonlabb54b85b2014-10-28 18:43:57 -04001476
andrewonlab16ce4852014-10-30 13:41:09 -04001477 #Counter to track loop count
1478 counter_loop = 0
1479 counter_avail1 = 0
1480 counter_avail2 = 0
1481 counter_avail3 = 0
1482 onos1_dev = False
1483 onos2_dev = False
1484 onos3_dev = False
1485 while counter_loop < 60:
1486 #Continue to check devices for all device
1487 #availability. When all devices in all 3
1488 #ONOS instances indicate that devices are available
1489 #obtain graph event timestamp for t1.
1490 device_str_obj1 = main.ONOS1cli.devices()
1491 device_str_obj2 = main.ONOS2cli.devices()
1492 device_str_obj3 = main.ONOS3cli.devices()
1493
1494 device_json1 = json.loads(device_str_obj1)
1495 device_json2 = json.loads(device_str_obj2)
1496 device_json3 = json.loads(device_str_obj3)
1497
1498 for device1 in device_json1:
1499 if device1['available'] == True:
1500 counter_avail1 += 1
1501 if counter_avail1 == int(num_sw):
1502 onos1_dev = True
1503 main.log.info("All devices have been "+
1504 "discovered on ONOS1")
1505 else:
1506 counter_avail1 = 0
1507 for device2 in device_json2:
1508 if device2['available'] == True:
1509 counter_avail2 += 1
1510 if counter_avail2 == int(num_sw):
1511 onos2_dev = True
1512 main.log.info("All devices have been "+
1513 "discovered on ONOS2")
1514 else:
1515 counter_avail2 = 0
1516 for device3 in device_json3:
1517 if device3['available'] == True:
1518 counter_avail3 += 1
1519 if counter_avail3 == int(num_sw):
1520 onos3_dev = True
1521 main.log.info("All devices have been "+
1522 "discovered on ONOS3")
1523 else:
1524 counter_avail3 = 0
1525
1526 if onos1_dev and onos2_dev and onos3_dev:
1527 main.log.info("All devices have been discovered "+
1528 "on all ONOS instances")
1529 json_str_topology_metrics_1 =\
1530 main.ONOS1cli.topology_events_metrics()
1531 json_str_topology_metrics_2 =\
1532 main.ONOS2cli.topology_events_metrics()
1533 json_str_topology_metrics_3 =\
1534 main.ONOS3cli.topology_events_metrics()
andrewonlab53b641c2014-10-31 19:44:44 -04001535
1536 #Exit while loop if all devices discovered
andrewonlab16ce4852014-10-30 13:41:09 -04001537 break
1538
1539 counter_loop += 1
1540 #Give some time in between CLI calls
1541 #(will not affect measurement)
1542 time.sleep(3)
1543
1544 main.ONOS1.tshark_stop()
1545
1546 os.system("scp "+ONOS_user+"@"+ONOS1_ip+":"+
1547 tshark_ofp_output+" /tmp/")
andrewonlab53b641c2014-10-31 19:44:44 -04001548 os.system("scp "+ONOS_user+"@"+ONOS1_ip+":"+
1549 tshark_tcp_output+" /tmp/")
andrewonlab16ce4852014-10-30 13:41:09 -04001550
andrewonlab16ce4852014-10-30 13:41:09 -04001551 #TODO: Automate OFP output analysis
andrewonlab58f7d702014-11-07 13:21:19 -05001552 #Debug mode - print out packets captured at runtime
1553 if debug_mode == 'on':
1554 ofp_file = open(tshark_ofp_output, 'r')
1555 main.log.info("Tshark OFP Vendor output: ")
1556 for line in ofp_file:
1557 tshark_ofp_result_list.append(line)
andrewonlabe5bcef92014-11-06 17:53:20 -05001558 main.log.info(line)
andrewonlab58f7d702014-11-07 13:21:19 -05001559 ofp_file.close()
andrewonlab16ce4852014-10-30 13:41:09 -04001560
andrewonlab58f7d702014-11-07 13:21:19 -05001561 tcp_file = open(tshark_tcp_output, 'r')
1562 main.log.info("Tshark TCP 74 output: ")
1563 for line in tcp_file:
1564 tshark_tcp_result_list.append(line)
andrewonlabe5bcef92014-11-06 17:53:20 -05001565 main.log.info(line)
andrewonlab58f7d702014-11-07 13:21:19 -05001566 tcp_file.close()
andrewonlab53b641c2014-10-31 19:44:44 -04001567
andrewonlab16ce4852014-10-30 13:41:09 -04001568 json_obj_1 = json.loads(json_str_topology_metrics_1)
1569 json_obj_2 = json.loads(json_str_topology_metrics_2)
1570 json_obj_3 = json.loads(json_str_topology_metrics_3)
1571
1572 graph_timestamp_1 = \
1573 json_obj_1[graphTimestamp]['value']
1574 graph_timestamp_2 = \
1575 json_obj_2[graphTimestamp]['value']
1576 graph_timestamp_3 = \
1577 json_obj_3[graphTimestamp]['value']
1578
andrewonlabe5bcef92014-11-06 17:53:20 -05001579 graph_lat_1 = int(graph_timestamp_1) - int(t0_system)
1580 graph_lat_2 = int(graph_timestamp_2) - int(t0_system)
1581 graph_lat_3 = int(graph_timestamp_3) - int(t0_system)
andrewonlab16ce4852014-10-30 13:41:09 -04001582
andrewonlabe5bcef92014-11-06 17:53:20 -05001583 avg_graph_lat = \
1584 (int(graph_lat_1) +\
1585 int(graph_lat_2) +\
1586 int(graph_lat_3)) / 3
1587
1588 if avg_graph_lat > sw_disc_threshold_min \
1589 and avg_graph_lat < sw_disc_threshold_max:
1590 sw_discovery_lat_list.append(
1591 avg_graph_lat)
1592 else:
1593 main.log.info("100 Switch discovery latency "+
1594 "exceeded the threshold.")
1595
1596 #END ITERATION FOR LOOP
andrewonlab16ce4852014-10-30 13:41:09 -04001597
andrewonlabe5bcef92014-11-06 17:53:20 -05001598 sw_lat_min = min(sw_discovery_lat_list)
1599 sw_lat_max = max(sw_discovery_lat_list)
1600 sw_lat_avg = sum(sw_discovery_lat_list) /\
1601 len(sw_discovery_lat_list)
andrewonlab16ce4852014-10-30 13:41:09 -04001602
andrewonlabf9828f02014-11-10 14:50:27 -05001603 main.log.report("100 Switch discovery lat "+\
1604 "Min: "+str(sw_lat_min)+" ms"+\
1605 "Max: "+str(sw_lat_max)+" ms"+\
1606 "Avg: "+str(sw_lat_avg)+" ms")
andrewonlab16ce4852014-10-30 13:41:09 -04001607
andrewonlabb54b85b2014-10-28 18:43:57 -04001608