blob: a710f826390dba5ce0972f33625672f93d5739fa [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
78 main.step("Using mvn clean & install")
andrewonlab8d29f122014-10-22 17:15:04 -040079 #mvn_result = main.ONOSbench.clean_install()
80 mvn_result = main.TRUE
andrewonlab2a6c9342014-10-16 13:40:15 -040081
andrewonlabb1998c52014-11-10 13:31:43 -050082 main.step("Set cell for ONOS cli env")
83 main.ONOS1cli.set_cell(cell_name)
84 main.ONOS2cli.set_cell(cell_name)
85 main.ONOS3cli.set_cell(cell_name)
86
andrewonlab2a6c9342014-10-16 13:40:15 -040087 main.step("Creating ONOS package")
88 package_result = main.ONOSbench.onos_package()
89
90 main.step("Installing ONOS package")
andrewonlabe9fb6722014-10-24 12:20:35 -040091 install1_result = main.ONOSbench.onos_install(node=ONOS1_ip)
92 install2_result = main.ONOSbench.onos_install(node=ONOS2_ip)
93 install3_result = main.ONOSbench.onos_install(node=ONOS3_ip)
andrewonlab2a6c9342014-10-16 13:40:15 -040094
andrewonlabe9fb6722014-10-24 12:20:35 -040095 time.sleep(10)
96
andrewonlab867212a2014-10-22 20:13:38 -040097 main.step("Start onos cli")
andrewonlabe9fb6722014-10-24 12:20:35 -040098 cli1 = main.ONOS1cli.start_onos_cli(ONOS1_ip)
99 cli2 = main.ONOS2cli.start_onos_cli(ONOS2_ip)
100 cli3 = main.ONOS3cli.start_onos_cli(ONOS3_ip)
101
andrewonlab867212a2014-10-22 20:13:38 -0400102 main.step("Enable metrics feature")
andrewonlabb1998c52014-11-10 13:31:43 -0500103 main.ONOS1cli.feature_install("onos-app-metrics")
104 main.ONOS2cli.feature_install("onos-app-metrics")
105 main.ONOS3cli.feature_install("onos-app-metrics")
andrewonlab867212a2014-10-22 20:13:38 -0400106
andrewonlab2a6c9342014-10-16 13:40:15 -0400107 utilities.assert_equals(expect=main.TRUE,
108 actual= cell_file_result and cell_apply_result and\
109 verify_cell_result and checkout_result and\
110 pull_result and mvn_result and\
andrewonlabe9fb6722014-10-24 12:20:35 -0400111 install1_result and install2_result and\
112 install3_result,
andrewonlabf9828f02014-11-10 14:50:27 -0500113 onpass="Test Environment setup successful",
114 onfail="Failed to setup test environment")
andrewonlab2a6c9342014-10-16 13:40:15 -0400115
andrewonlabba44bcf2014-10-16 16:54:41 -0400116 def CASE2(self, main):
117 '''
118 Assign s1 to ONOS1 and measure latency
andrewonlab3a7c3c72014-10-24 17:21:03 -0400119
120 There are 4 levels of latency measurements to this test:
121 1) End-to-end measurement: Complete end-to-end measurement
122 from TCP (SYN/ACK) handshake to Graph change
123 2) OFP-to-graph measurement: 'ONOS processing' snippet of
124 measurement from OFP Vendor message to Graph change
125 3) OFP-to-device measurement: 'ONOS processing without
126 graph change' snippet of measurement from OFP vendor
127 message to Device change timestamp
128 4) T0-to-device measurement: Measurement that includes
129 the switch handshake to devices timestamp without
130 the graph view change. (TCP handshake -> Device
131 change)
andrewonlabba44bcf2014-10-16 16:54:41 -0400132 '''
133 import time
andrewonlabe6745342014-10-17 14:29:13 -0400134 import subprocess
135 import json
136 import requests
137 import os
andrewonlab4f50ec92014-11-11 14:24:45 -0500138 import numpy
andrewonlabba44bcf2014-10-16 16:54:41 -0400139
140 ONOS1_ip = main.params['CTRL']['ip1']
141 ONOS2_ip = main.params['CTRL']['ip2']
142 ONOS3_ip = main.params['CTRL']['ip3']
andrewonlabe6745342014-10-17 14:29:13 -0400143 ONOS_user = main.params['CTRL']['user']
144
andrewonlabba44bcf2014-10-16 16:54:41 -0400145 default_sw_port = main.params['CTRL']['port1']
146
147 #Number of iterations of case
148 num_iter = main.params['TEST']['numIter']
andrewonlab4b5c8b92014-11-10 16:04:33 -0500149 #Number of first 'x' iterations to ignore:
150 iter_ignore = int(main.params['TEST']['iterIgnore'])
151
andrewonlab226024e2014-10-24 16:01:32 -0400152 #Timestamp 'keys' for json metrics output.
153 #These are subject to change, hence moved into params
154 deviceTimestamp = main.params['JSON']['deviceTimestamp']
155 graphTimestamp = main.params['JSON']['graphTimestamp']
156
andrewonlab58f7d702014-11-07 13:21:19 -0500157 debug_mode = main.params['TEST']['debugMode']
andrewonlabb1998c52014-11-10 13:31:43 -0500158 onos_log = main.params['TEST']['onosLogFile']
andrewonlab58f7d702014-11-07 13:21:19 -0500159
andrewonlabe5bcef92014-11-06 17:53:20 -0500160 #Threshold for the test
161 threshold_str = main.params['TEST']['singleSwThreshold']
162 threshold_obj = threshold_str.split(",")
163 threshold_min = int(threshold_obj[0])
164 threshold_max = int(threshold_obj[1])
165
andrewonlab226024e2014-10-24 16:01:32 -0400166 #List of switch add latency collected from
167 #all iterations
168 latency_end_to_end_list = []
169 latency_ofp_to_graph_list = []
170 latency_ofp_to_device_list = []
171 latency_t0_to_device_list = []
andrewonlab65d73892014-11-10 17:36:00 -0500172 latency_tcp_to_ofp_list = []
andrewonlab226024e2014-10-24 16:01:32 -0400173
andrewonlabba44bcf2014-10-16 16:54:41 -0400174 #Directory/file to store tshark results
175 tshark_of_output = "/tmp/tshark_of_topo.txt"
176 tshark_tcp_output = "/tmp/tshark_tcp_topo.txt"
177
178 #String to grep in tshark output
179 tshark_tcp_string = "TCP 74 "+default_sw_port
180 tshark_of_string = "OFP 86 Vendor"
andrewonlabe6745342014-10-17 14:29:13 -0400181
182 #Initialize assertion to TRUE
183 assertion = main.TRUE
andrewonlab58f7d702014-11-07 13:21:19 -0500184
185 local_time = time.strftime('%x %X')
andrewonlabb1998c52014-11-10 13:31:43 -0500186 local_time = local_time.replace("/","")
187 local_time = local_time.replace(" ","_")
188 local_time = local_time.replace(":","")
andrewonlab58f7d702014-11-07 13:21:19 -0500189 if debug_mode == 'on':
190 main.ONOS1.tshark_pcap("eth0",
andrewonlabb1998c52014-11-10 13:31:43 -0500191 "/tmp/single_sw_lat_pcap_"+local_time)
192
193 main.log.info("TEST")
andrewonlab58f7d702014-11-07 13:21:19 -0500194
andrewonlab4b5c8b92014-11-10 16:04:33 -0500195 main.log.report("Latency of adding one switch to controller")
196 main.log.report("First "+str(iter_ignore)+" iterations ignored"+
197 " for jvm warmup time")
198 main.log.report("Total iterations of test: "+str(num_iter))
andrewonlabba44bcf2014-10-16 16:54:41 -0400199
200 for i in range(0, int(num_iter)):
201 main.log.info("Starting tshark capture")
202
203 #* TCP [ACK, SYN] is used as t0_a, the
204 # very first "exchange" between ONOS and
205 # the switch for end-to-end measurement
206 #* OFP [Stats Reply] is used for t0_b
207 # the very last OFP message between ONOS
208 # and the switch for ONOS measurement
209 main.ONOS1.tshark_grep(tshark_tcp_string,
210 tshark_tcp_output)
211 main.ONOS1.tshark_grep(tshark_of_string,
212 tshark_of_output)
213
214 #Wait and ensure tshark is started and
215 #capturing
216 time.sleep(10)
217
218 main.log.info("Assigning s1 to controller")
219
220 main.Mininet1.assign_sw_controller(sw="1",
221 ip1=ONOS1_ip, port1=default_sw_port)
222
223 #Wait and ensure switch is assigned
224 #before stopping tshark
andrewonlab867212a2014-10-22 20:13:38 -0400225 time.sleep(30)
andrewonlab226024e2014-10-24 16:01:32 -0400226
227 main.log.info("Stopping all Tshark processes")
andrewonlabba44bcf2014-10-16 16:54:41 -0400228 main.ONOS1.stop_tshark()
229
andrewonlabe6745342014-10-17 14:29:13 -0400230 #tshark output is saved in ONOS. Use subprocess
231 #to copy over files to TestON for parsing
232 main.log.info("Copying over tshark files")
233
234 #TCP CAPTURE ****
andrewonlab8d29f122014-10-22 17:15:04 -0400235 #Copy the tshark output from ONOS machine to
236 #TestON machine in tshark_tcp_output directory>file
237 os.system("scp "+ONOS_user+"@"+ONOS1_ip+":"+
238 tshark_tcp_output+" /tmp/")
239 tcp_file = open(tshark_tcp_output, 'r')
240 temp_text = tcp_file.readline()
andrewonlabe6745342014-10-17 14:29:13 -0400241 temp_text = temp_text.split(" ")
andrewonlabba44bcf2014-10-16 16:54:41 -0400242
andrewonlabe6745342014-10-17 14:29:13 -0400243 main.log.info("Object read in from TCP capture: "+
244 str(temp_text))
andrewonlab867212a2014-10-22 20:13:38 -0400245 if len(temp_text) > 1:
andrewonlab3a7c3c72014-10-24 17:21:03 -0400246 t0_tcp = float(temp_text[1])*1000.0
andrewonlabe6745342014-10-17 14:29:13 -0400247 else:
248 main.log.error("Tshark output file for TCP"+
249 " returned unexpected results")
250 t0_tcp = 0
251 assertion = main.FALSE
andrewonlab8d29f122014-10-22 17:15:04 -0400252
253 tcp_file.close()
andrewonlabe6745342014-10-17 14:29:13 -0400254 #****************
andrewonlabba44bcf2014-10-16 16:54:41 -0400255
andrewonlabe6745342014-10-17 14:29:13 -0400256 #OF CAPTURE ****
andrewonlab8d29f122014-10-22 17:15:04 -0400257 os.system("scp "+ONOS_user+"@"+ONOS1_ip+":"+
258 tshark_of_output+" /tmp/")
259 of_file = open(tshark_of_output, 'r')
260
261 line_ofp = ""
andrewonlab226024e2014-10-24 16:01:32 -0400262 #Read until last line of file
andrewonlabe6745342014-10-17 14:29:13 -0400263 while True:
andrewonlab8d29f122014-10-22 17:15:04 -0400264 temp_text = of_file.readline()
265 if temp_text !='':
andrewonlabe6745342014-10-17 14:29:13 -0400266 line_ofp = temp_text
267 else:
268 break
269 obj = line_ofp.split(" ")
270
271 main.log.info("Object read in from OFP capture: "+
272 str(line_ofp))
273
andrewonlab867212a2014-10-22 20:13:38 -0400274 if len(line_ofp) > 1:
andrewonlab3a7c3c72014-10-24 17:21:03 -0400275 t0_ofp = float(obj[1])*1000.0
andrewonlabe6745342014-10-17 14:29:13 -0400276 else:
277 main.log.error("Tshark output file for OFP"+
278 " returned unexpected results")
279 t0_ofp = 0
280 assertion = main.FALSE
andrewonlab8d29f122014-10-22 17:15:04 -0400281
282 of_file.close()
andrewonlabe6745342014-10-17 14:29:13 -0400283 #****************
284
andrewonlab867212a2014-10-22 20:13:38 -0400285 json_str_1 = main.ONOS1cli.topology_events_metrics()
286 json_str_2 = main.ONOS2cli.topology_events_metrics()
287 json_str_3 = main.ONOS3cli.topology_events_metrics()
andrewonlab867212a2014-10-22 20:13:38 -0400288
289 json_obj_1 = json.loads(json_str_1)
290 json_obj_2 = json.loads(json_str_2)
291 json_obj_3 = json.loads(json_str_3)
292
andrewonlab226024e2014-10-24 16:01:32 -0400293 #Obtain graph timestamp. This timestsamp captures
294 #the epoch time at which the topology graph was updated.
295 graph_timestamp_1 = \
296 json_obj_1[graphTimestamp]['value']
297 graph_timestamp_2 = \
298 json_obj_2[graphTimestamp]['value']
299 graph_timestamp_3 = \
300 json_obj_3[graphTimestamp]['value']
andrewonlab867212a2014-10-22 20:13:38 -0400301
andrewonlab226024e2014-10-24 16:01:32 -0400302 #Obtain device timestamp. This timestamp captures
303 #the epoch time at which the device event happened
304 device_timestamp_1 = \
305 json_obj_1[deviceTimestamp]['value']
306 device_timestamp_2 = \
307 json_obj_2[deviceTimestamp]['value']
308 device_timestamp_3 = \
309 json_obj_3[deviceTimestamp]['value']
andrewonlabe9fb6722014-10-24 12:20:35 -0400310
andrewonlab226024e2014-10-24 16:01:32 -0400311 #t0 to device processing latency
312 delta_device_1 = int(device_timestamp_1) - int(t0_tcp)
313 delta_device_2 = int(device_timestamp_2) - int(t0_tcp)
314 delta_device_3 = int(device_timestamp_3) - int(t0_tcp)
315
316 #Get average of delta from all instances
317 avg_delta_device = \
318 (int(delta_device_1)+\
319 int(delta_device_2)+\
320 int(delta_device_3)) / 3
andrewonlabba44bcf2014-10-16 16:54:41 -0400321
andrewonlab226024e2014-10-24 16:01:32 -0400322 #Ensure avg delta meets the threshold before appending
andrewonlab4b5c8b92014-11-10 16:04:33 -0500323 if avg_delta_device > 0.0 and avg_delta_device < 10000\
andrewonlab65d73892014-11-10 17:36:00 -0500324 and int(i) > iter_ignore:
andrewonlab226024e2014-10-24 16:01:32 -0400325 latency_t0_to_device_list.append(avg_delta_device)
andrewonlabee4efeb2014-10-24 16:44:51 -0400326 else:
andrewonlab09d973e2014-10-24 18:56:58 -0400327 main.log.info("Results for t0-to-device ignored"+\
andrewonlab4b5c8b92014-11-10 16:04:33 -0500328 "due to excess in threshold / warmup iteration.")
andrewonlabee4efeb2014-10-24 16:44:51 -0400329
andrewonlab226024e2014-10-24 16:01:32 -0400330 #t0 to graph processing latency (end-to-end)
331 delta_graph_1 = int(graph_timestamp_1) - int(t0_tcp)
332 delta_graph_2 = int(graph_timestamp_2) - int(t0_tcp)
333 delta_graph_3 = int(graph_timestamp_3) - int(t0_tcp)
334
335 #Get average of delta from all instances
336 avg_delta_graph = \
337 (int(delta_graph_1)+\
338 int(delta_graph_2)+\
339 int(delta_graph_3)) / 3
340
andrewonlab226024e2014-10-24 16:01:32 -0400341 #Ensure avg delta meets the threshold before appending
andrewonlab4b5c8b92014-11-10 16:04:33 -0500342 if avg_delta_graph > 0.0 and avg_delta_graph < 10000\
andrewonlab65d73892014-11-10 17:36:00 -0500343 and int(i) > iter_ignore:
andrewonlab09d973e2014-10-24 18:56:58 -0400344 latency_end_to_end_list.append(avg_delta_graph)
andrewonlabee4efeb2014-10-24 16:44:51 -0400345 else:
andrewonlab09d973e2014-10-24 18:56:58 -0400346 main.log.info("Results for end-to-end ignored"+\
347 "due to excess in threshold")
andrewonlab226024e2014-10-24 16:01:32 -0400348
349 #ofp to graph processing latency (ONOS processing)
350 delta_ofp_graph_1 = int(graph_timestamp_1) - int(t0_ofp)
351 delta_ofp_graph_2 = int(graph_timestamp_2) - int(t0_ofp)
352 delta_ofp_graph_3 = int(graph_timestamp_3) - int(t0_ofp)
353
354 avg_delta_ofp_graph = \
355 (int(delta_ofp_graph_1)+\
356 int(delta_ofp_graph_2)+\
357 int(delta_ofp_graph_3)) / 3
358
andrewonlabe5bcef92014-11-06 17:53:20 -0500359 if avg_delta_ofp_graph > threshold_min \
andrewonlab4b5c8b92014-11-10 16:04:33 -0500360 and avg_delta_ofp_graph < threshold_max\
andrewonlab65d73892014-11-10 17:36:00 -0500361 and int(i) > iter_ignore:
andrewonlab226024e2014-10-24 16:01:32 -0400362 latency_ofp_to_graph_list.append(avg_delta_ofp_graph)
andrewonlabee4efeb2014-10-24 16:44:51 -0400363 else:
andrewonlab09d973e2014-10-24 18:56:58 -0400364 main.log.info("Results for ofp-to-graph "+\
365 "ignored due to excess in threshold")
andrewonlabee4efeb2014-10-24 16:44:51 -0400366
andrewonlab226024e2014-10-24 16:01:32 -0400367 #ofp to device processing latency (ONOS processing)
andrewonlabee4efeb2014-10-24 16:44:51 -0400368 delta_ofp_device_1 = float(device_timestamp_1) - float(t0_ofp)
369 delta_ofp_device_2 = float(device_timestamp_2) - float(t0_ofp)
370 delta_ofp_device_3 = float(device_timestamp_3) - float(t0_ofp)
andrewonlab226024e2014-10-24 16:01:32 -0400371
372 avg_delta_ofp_device = \
andrewonlabee4efeb2014-10-24 16:44:51 -0400373 (float(delta_ofp_device_1)+\
374 float(delta_ofp_device_2)+\
andrewonlab4b5c8b92014-11-10 16:04:33 -0500375 float(delta_ofp_device_3)) / 3
andrewonlab226024e2014-10-24 16:01:32 -0400376
andrewonlabf47993a2014-10-24 17:56:01 -0400377 #NOTE: ofp - delta measurements are occasionally negative
378 # due to system time misalignment.
andrewonlabf47993a2014-10-24 17:56:01 -0400379 latency_ofp_to_device_list.append(avg_delta_ofp_device)
andrewonlabba44bcf2014-10-16 16:54:41 -0400380
andrewonlab65d73892014-11-10 17:36:00 -0500381 delta_ofp_tcp = int(t0_ofp) - int(t0_tcp)
382 if delta_ofp_tcp > threshold_min \
383 and delta_ofp_tcp < threshold_max and\
384 int(i) > iter_ignore:
385 latency_tcp_to_ofp_list.append(delta_ofp_tcp)
386 else:
387 main.log.info("Results fo tcp-to-ofp "+\
388 "ignored due to excess in threshold")
389
andrewonlabe6745342014-10-17 14:29:13 -0400390 #TODO:
391 #Fetch logs upon threshold excess
andrewonlabba44bcf2014-10-16 16:54:41 -0400392
andrewonlab226024e2014-10-24 16:01:32 -0400393 main.log.info("ONOS1 delta end-to-end: "+
andrewonlab09d973e2014-10-24 18:56:58 -0400394 str(delta_graph_1) + " ms")
andrewonlab226024e2014-10-24 16:01:32 -0400395 main.log.info("ONOS2 delta end-to-end: "+
andrewonlab09d973e2014-10-24 18:56:58 -0400396 str(delta_graph_2) + " ms")
397 main.log.info("ONOS3 delta end-to-end: "+
398 str(delta_graph_3) + " ms")
andrewonlabba44bcf2014-10-16 16:54:41 -0400399
andrewonlab226024e2014-10-24 16:01:32 -0400400 main.log.info("ONOS1 delta OFP - graph: "+
andrewonlab09d973e2014-10-24 18:56:58 -0400401 str(delta_ofp_graph_1) + " ms")
andrewonlab226024e2014-10-24 16:01:32 -0400402 main.log.info("ONOS2 delta OFP - graph: "+
andrewonlab09d973e2014-10-24 18:56:58 -0400403 str(delta_ofp_graph_2) + " ms")
andrewonlab226024e2014-10-24 16:01:32 -0400404 main.log.info("ONOS3 delta OFP - graph: "+
andrewonlab09d973e2014-10-24 18:56:58 -0400405 str(delta_ofp_graph_3) + " ms")
andrewonlabe6745342014-10-17 14:29:13 -0400406
andrewonlab226024e2014-10-24 16:01:32 -0400407 main.log.info("ONOS1 delta device - t0: "+
andrewonlab09d973e2014-10-24 18:56:58 -0400408 str(delta_device_1) + " ms")
andrewonlab226024e2014-10-24 16:01:32 -0400409 main.log.info("ONOS2 delta device - t0: "+
andrewonlab09d973e2014-10-24 18:56:58 -0400410 str(delta_device_2) + " ms")
andrewonlab226024e2014-10-24 16:01:32 -0400411 main.log.info("ONOS3 delta device - t0: "+
andrewonlab09d973e2014-10-24 18:56:58 -0400412 str(delta_device_3) + " ms")
andrewonlab65d73892014-11-10 17:36:00 -0500413
414 main.log.info("TCP to OFP delta: "+
415 str(delta_ofp_tcp) + " ms")
andrewonlab8790abb2014-11-06 13:51:54 -0500416 #main.log.info("ONOS1 delta OFP - device: "+
417 # str(delta_ofp_device_1) + " ms")
418 #main.log.info("ONOS2 delta OFP - device: "+
419 # str(delta_ofp_device_2) + " ms")
420 #main.log.info("ONOS3 delta OFP - device: "+
421 # str(delta_ofp_device_3) + " ms")
andrewonlab226024e2014-10-24 16:01:32 -0400422
andrewonlab8d29f122014-10-22 17:15:04 -0400423 main.step("Remove switch from controller")
424 main.Mininet1.delete_sw_controller("s1")
andrewonlabba44bcf2014-10-16 16:54:41 -0400425
andrewonlab8d29f122014-10-22 17:15:04 -0400426 time.sleep(5)
andrewonlabba44bcf2014-10-16 16:54:41 -0400427
andrewonlab09d973e2014-10-24 18:56:58 -0400428 #END of for loop iteration
andrewonlabf47993a2014-10-24 17:56:01 -0400429
andrewonlabee4efeb2014-10-24 16:44:51 -0400430 #If there is at least 1 element in each list,
andrewonlabc15c9582014-10-24 16:35:52 -0400431 #pass the test case
432 if len(latency_end_to_end_list) > 0 and\
433 len(latency_ofp_to_graph_list) > 0 and\
434 len(latency_ofp_to_device_list) > 0 and\
andrewonlab65d73892014-11-10 17:36:00 -0500435 len(latency_t0_to_device_list) > 0 and\
436 len(latency_tcp_to_ofp_list) > 0:
andrewonlabc15c9582014-10-24 16:35:52 -0400437 assertion = main.TRUE
andrewonlabf47993a2014-10-24 17:56:01 -0400438 elif len(latency_end_to_end_list) == 0:
439 #The appending of 0 here is to prevent
440 #the min,max,sum functions from failing
441 #below
442 latency_end_to_end_list.append(0)
443 assertion = main.FALSE
444 elif len(latency_ofp_to_graph_list) == 0:
445 latency_ofp_to_graph_list.append(0)
446 assertion = main.FALSE
447 elif len(latency_ofp_to_device_list) == 0:
448 latency_ofp_to_device_list.append(0)
449 assertion = main.FALSE
450 elif len(latency_t0_to_device_list) == 0:
451 latency_t0_to_device_list.append(0)
452 assertion = main.FALSE
andrewonlab65d73892014-11-10 17:36:00 -0500453 elif len(latency_tcp_to_ofp_list) == 0:
454 latency_tcp_to_ofp_list.append(0)
455 assertion = main.FALSE
andrewonlabc15c9582014-10-24 16:35:52 -0400456
457 #Calculate min, max, avg of latency lists
458 latency_end_to_end_max = \
andrewonlabee4efeb2014-10-24 16:44:51 -0400459 int(max(latency_end_to_end_list))
andrewonlabc15c9582014-10-24 16:35:52 -0400460 latency_end_to_end_min = \
andrewonlabee4efeb2014-10-24 16:44:51 -0400461 int(min(latency_end_to_end_list))
andrewonlabc15c9582014-10-24 16:35:52 -0400462 latency_end_to_end_avg = \
andrewonlabc90667c2014-10-24 16:48:28 -0400463 (int(sum(latency_end_to_end_list)) / \
andrewonlabc15c9582014-10-24 16:35:52 -0400464 len(latency_end_to_end_list))
andrewonlab69864162014-11-11 16:28:48 -0500465 latency_end_to_end_std_dev = \
466 str(round(numpy.std(latency_end_to_end_list),1))
467
andrewonlabc15c9582014-10-24 16:35:52 -0400468 latency_ofp_to_graph_max = \
andrewonlabee4efeb2014-10-24 16:44:51 -0400469 int(max(latency_ofp_to_graph_list))
andrewonlabc15c9582014-10-24 16:35:52 -0400470 latency_ofp_to_graph_min = \
andrewonlabee4efeb2014-10-24 16:44:51 -0400471 int(min(latency_ofp_to_graph_list))
andrewonlabc15c9582014-10-24 16:35:52 -0400472 latency_ofp_to_graph_avg = \
andrewonlabee4efeb2014-10-24 16:44:51 -0400473 (int(sum(latency_ofp_to_graph_list)) / \
andrewonlabc15c9582014-10-24 16:35:52 -0400474 len(latency_ofp_to_graph_list))
andrewonlab69864162014-11-11 16:28:48 -0500475 latency_ofp_to_graph_std_dev = \
476 str(round(numpy.std(latency_ofp_to_graph_list),1))
andrewonlabc15c9582014-10-24 16:35:52 -0400477
478 latency_ofp_to_device_max = \
andrewonlabee4efeb2014-10-24 16:44:51 -0400479 int(max(latency_ofp_to_device_list))
andrewonlabc15c9582014-10-24 16:35:52 -0400480 latency_ofp_to_device_min = \
andrewonlabee4efeb2014-10-24 16:44:51 -0400481 int(min(latency_ofp_to_device_list))
andrewonlabc15c9582014-10-24 16:35:52 -0400482 latency_ofp_to_device_avg = \
andrewonlabee4efeb2014-10-24 16:44:51 -0400483 (int(sum(latency_ofp_to_device_list)) / \
andrewonlabc15c9582014-10-24 16:35:52 -0400484 len(latency_ofp_to_device_list))
andrewonlab69864162014-11-11 16:28:48 -0500485 latency_ofp_to_device_std_dev = \
486 str(round(numpy.std(latency_ofp_to_device_list),1))
andrewonlabc15c9582014-10-24 16:35:52 -0400487
488 latency_t0_to_device_max = \
andrewonlab4b5c8b92014-11-10 16:04:33 -0500489 int(max(latency_t0_to_device_list))
andrewonlabc15c9582014-10-24 16:35:52 -0400490 latency_t0_to_device_min = \
andrewonlab4b5c8b92014-11-10 16:04:33 -0500491 int(min(latency_t0_to_device_list))
andrewonlabc15c9582014-10-24 16:35:52 -0400492 latency_t0_to_device_avg = \
andrewonlab4b5c8b92014-11-10 16:04:33 -0500493 (int(sum(latency_t0_to_device_list)) / \
andrewonlab69864162014-11-11 16:28:48 -0500494 len(latency_t0_to_device_list))
495 latency_ofp_to_device_std_dev = \
496 str(round(numpy.std(latency_t0_to_device_list),1))
andrewonlabc15c9582014-10-24 16:35:52 -0400497
andrewonlab65d73892014-11-10 17:36:00 -0500498 latency_tcp_to_ofp_max = \
499 int(max(latency_tcp_to_ofp_list))
500 latency_tcp_to_ofp_min = \
501 int(min(latency_tcp_to_ofp_list))
502 latency_tcp_to_ofp_avg = \
503 (int(sum(latency_tcp_to_ofp_list)) / \
504 len(latency_tcp_to_ofp_list))
andrewonlab69864162014-11-11 16:28:48 -0500505 latency_tcp_to_ofp_std_dev = \
506 str(round(numpy.std(latency_tcp_to_ofp_list),1))
andrewonlab65d73892014-11-10 17:36:00 -0500507
andrewonlabf9828f02014-11-10 14:50:27 -0500508 main.log.report("Switch add - End-to-end latency: "+\
andrewonlab4f50ec92014-11-11 14:24:45 -0500509 "Avg: "+str(latency_end_to_end_avg)+" ms "+
andrewonlab69864162014-11-11 16:28:48 -0500510 "Std Deviation: "+latency_end_to_end_std_dev+" ms")
andrewonlabf9828f02014-11-10 14:50:27 -0500511 main.log.report("Switch add - OFP-to-Graph latency: "+\
andrewonlab4f50ec92014-11-11 14:24:45 -0500512 "Avg: "+str(latency_ofp_to_graph_avg)+" ms "+
andrewonlab69864162014-11-11 16:28:48 -0500513 "Std Deviation: "+latency_ofp_to_graph_std_dev+" ms")
andrewonlab65d73892014-11-10 17:36:00 -0500514 main.log.report("Switch add - TCP-to-OFP latency: "+\
andrewonlab4f50ec92014-11-11 14:24:45 -0500515 "Avg: "+str(latency_tcp_to_ofp_avg)+" ms "+
andrewonlab69864162014-11-11 16:28:48 -0500516 "Std Deviation: "+latency_tcp_to_ofp_std_dev+" ms")
andrewonlab226024e2014-10-24 16:01:32 -0400517
andrewonlabb1998c52014-11-10 13:31:43 -0500518 if debug_mode == 'on':
519 main.ONOS1.cp_logs_to_dir("/opt/onos/log/karaf.log",
520 "/tmp/", copy_file_name="sw_lat_karaf")
521
andrewonlab8d29f122014-10-22 17:15:04 -0400522 utilities.assert_equals(expect=main.TRUE, actual=assertion,
523 onpass="Switch latency test successful",
524 onfail="Switch latency test failed")
andrewonlabba44bcf2014-10-16 16:54:41 -0400525
andrewonlab8d29f122014-10-22 17:15:04 -0400526 def CASE3(self, main):
527 '''
528 Bring port up / down and measure latency.
529 Port enable / disable is simulated by ifconfig up / down
andrewonlab393531a2014-10-27 18:36:26 -0400530
531 In ONOS-next, we must ensure that the port we are
532 manipulating is connected to another switch with a valid
533 connection. Otherwise, graph view will not be updated.
andrewonlab8d29f122014-10-22 17:15:04 -0400534 '''
535 import time
536 import subprocess
537 import os
538 import requests
539 import json
andrewonlab4f50ec92014-11-11 14:24:45 -0500540 import numpy
andrewonlab2a6c9342014-10-16 13:40:15 -0400541
andrewonlab8d29f122014-10-22 17:15:04 -0400542 ONOS1_ip = main.params['CTRL']['ip1']
andrewonlab393531a2014-10-27 18:36:26 -0400543 ONOS2_ip = main.params['CTRL']['ip2']
544 ONOS3_ip = main.params['CTRL']['ip3']
andrewonlab8d29f122014-10-22 17:15:04 -0400545 ONOS_user = main.params['CTRL']['user']
andrewonlab8d29f122014-10-22 17:15:04 -0400546
andrewonlab393531a2014-10-27 18:36:26 -0400547 default_sw_port = main.params['CTRL']['port1']
andrewonlab8790abb2014-11-06 13:51:54 -0500548
549 assertion = main.TRUE
andrewonlab393531a2014-10-27 18:36:26 -0400550 #Number of iterations of case
551 num_iter = main.params['TEST']['numIter']
552
553 #Timestamp 'keys' for json metrics output.
554 #These are subject to change, hence moved into params
555 deviceTimestamp = main.params['JSON']['deviceTimestamp']
556 graphTimestamp = main.params['JSON']['graphTimestamp']
andrewonlab58f7d702014-11-07 13:21:19 -0500557
558 debug_mode = main.params['TEST']['debugMode']
559
560 local_time = time.strftime('%x %X')
andrewonlabb1998c52014-11-10 13:31:43 -0500561 local_time = local_time.replace("/","")
562 local_time = local_time.replace(" ","_")
563 local_time = local_time.replace(":","")
andrewonlab58f7d702014-11-07 13:21:19 -0500564 if debug_mode == 'on':
565 main.ONOS1.tshark_pcap("eth0",
andrewonlabb1998c52014-11-10 13:31:43 -0500566 "/tmp/port_lat_pcap_"+local_time)
andrewonlab393531a2014-10-27 18:36:26 -0400567
andrewonlabe5bcef92014-11-06 17:53:20 -0500568 #Threshold for this test case
569 up_threshold_str = main.params['TEST']['portUpThreshold']
570 down_threshold_str = main.params['TEST']['portDownThreshold']
andrewonlabb1998c52014-11-10 13:31:43 -0500571
andrewonlabe5bcef92014-11-06 17:53:20 -0500572 up_threshold_obj = up_threshold_str.split(",")
573 down_threshold_obj = down_threshold_str.split(",")
574
575 up_threshold_min = int(up_threshold_obj[0])
576 up_threshold_max = int(up_threshold_obj[1])
577
578 down_threshold_min = int(down_threshold_obj[0])
579 down_threshold_max = int(down_threshold_obj[1])
580
andrewonlab393531a2014-10-27 18:36:26 -0400581 #NOTE: Some hardcoded variables you may need to configure
582 # besides the params
583
andrewonlab8d29f122014-10-22 17:15:04 -0400584 tshark_port_status = "OFP 130 Port Status"
585
586 tshark_port_up = "/tmp/tshark_port_up.txt"
587 tshark_port_down = "/tmp/tshark_port_down.txt"
andrewonlab393531a2014-10-27 18:36:26 -0400588 interface_config = "s1-eth1"
andrewonlab8d29f122014-10-22 17:15:04 -0400589
590 main.log.report("Port enable / disable latency")
andrewonlab4b5c8b92014-11-10 16:04:33 -0500591 main.log.report("Simulated by ifconfig up / down")
592 main.log.report("Total iterations of test: "+str(num_iter))
andrewonlab8d29f122014-10-22 17:15:04 -0400593
andrewonlab393531a2014-10-27 18:36:26 -0400594 main.step("Assign switches s1 and s2 to controller 1")
andrewonlab8d29f122014-10-22 17:15:04 -0400595 main.Mininet1.assign_sw_controller(sw="1",ip1=ONOS1_ip,
596 port1=default_sw_port)
andrewonlab393531a2014-10-27 18:36:26 -0400597 main.Mininet1.assign_sw_controller(sw="2",ip1=ONOS1_ip,
598 port1=default_sw_port)
andrewonlab8d29f122014-10-22 17:15:04 -0400599
andrewonlab8790abb2014-11-06 13:51:54 -0500600 #Give enough time for metrics to propagate the
601 #assign controller event. Otherwise, these events may
602 #carry over to our measurements
andrewonlabb1998c52014-11-10 13:31:43 -0500603 time.sleep(15)
andrewonlab8d29f122014-10-22 17:15:04 -0400604
andrewonlab393531a2014-10-27 18:36:26 -0400605 port_up_device_to_ofp_list = []
606 port_up_graph_to_ofp_list = []
607 port_down_device_to_ofp_list = []
608 port_down_graph_to_ofp_list = []
609
andrewonlab8d29f122014-10-22 17:15:04 -0400610 for i in range(0, int(num_iter)):
611 main.step("Starting wireshark capture for port status down")
612 main.ONOS1.tshark_grep(tshark_port_status,
613 tshark_port_down)
614
andrewonlabb1998c52014-11-10 13:31:43 -0500615 time.sleep(5)
andrewonlab8d29f122014-10-22 17:15:04 -0400616
andrewonlab393531a2014-10-27 18:36:26 -0400617 #Disable interface that is connected to switch 2
618 main.step("Disable port: "+interface_config)
andrewonlabb1998c52014-11-10 13:31:43 -0500619 main.Mininet1.handle.sendline("sh ifconfig "+
andrewonlab393531a2014-10-27 18:36:26 -0400620 interface_config+" down")
andrewonlabb1998c52014-11-10 13:31:43 -0500621 main.Mininet1.handle.expect("mininet>")
andrewonlab8d29f122014-10-22 17:15:04 -0400622
andrewonlabb1998c52014-11-10 13:31:43 -0500623 time.sleep(3)
andrewonlab8d29f122014-10-22 17:15:04 -0400624 main.ONOS1.tshark_stop()
andrewonlabb1998c52014-11-10 13:31:43 -0500625
626 main.step("Obtain t1 by metrics call")
627 json_str_up_1 = main.ONOS1cli.topology_events_metrics()
628 json_str_up_2 = main.ONOS2cli.topology_events_metrics()
629 json_str_up_3 = main.ONOS3cli.topology_events_metrics()
630
631 json_obj_1 = json.loads(json_str_up_1)
632 json_obj_2 = json.loads(json_str_up_2)
633 json_obj_3 = json.loads(json_str_up_3)
andrewonlab8d29f122014-10-22 17:15:04 -0400634
635 #Copy tshark output file from ONOS to TestON instance
636 #/tmp directory
637 os.system("scp "+ONOS_user+"@"+ONOS1_ip+":"+
638 tshark_port_down+" /tmp/")
639
640 f_port_down = open(tshark_port_down, 'r')
andrewonlab393531a2014-10-27 18:36:26 -0400641 #Get first line of port down event from tshark
andrewonlab8d29f122014-10-22 17:15:04 -0400642 f_line = f_port_down.readline()
643 obj_down = f_line.split(" ")
644 if len(f_line) > 0:
andrewonlabb1998c52014-11-10 13:31:43 -0500645 timestamp_begin_pt_down = int(float(obj_down[1])*1000)
andrewonlab393531a2014-10-27 18:36:26 -0400646 main.log.info("Port down begin timestamp: "+
647 str(timestamp_begin_pt_down))
andrewonlab8d29f122014-10-22 17:15:04 -0400648 else:
649 main.log.info("Tshark output file returned unexpected"+
andrewonlab393531a2014-10-27 18:36:26 -0400650 " results: "+str(obj_down))
andrewonlab8d29f122014-10-22 17:15:04 -0400651 timestamp_begin_pt_down = 0
andrewonlab393531a2014-10-27 18:36:26 -0400652
653 f_port_down.close()
andrewonlab8d29f122014-10-22 17:15:04 -0400654
andrewonlab4e124482014-11-04 13:37:25 -0500655 main.log.info("TEST tshark obj: "+str(obj_down))
656
andrewonlabb1998c52014-11-10 13:31:43 -0500657 time.sleep(3)
andrewonlab393531a2014-10-27 18:36:26 -0400658
659 #Obtain graph timestamp. This timestsamp captures
660 #the epoch time at which the topology graph was updated.
661 graph_timestamp_1 = \
662 json_obj_1[graphTimestamp]['value']
663 graph_timestamp_2 = \
664 json_obj_2[graphTimestamp]['value']
665 graph_timestamp_3 = \
666 json_obj_3[graphTimestamp]['value']
667
andrewonlabb1998c52014-11-10 13:31:43 -0500668 main.log.info("TEST graph timestamp ONOS1: "+
669 str(graph_timestamp_1))
670
andrewonlab393531a2014-10-27 18:36:26 -0400671 #Obtain device timestamp. This timestamp captures
672 #the epoch time at which the device event happened
673 device_timestamp_1 = \
674 json_obj_1[deviceTimestamp]['value']
675 device_timestamp_2 = \
676 json_obj_2[deviceTimestamp]['value']
677 device_timestamp_3 = \
678 json_obj_3[deviceTimestamp]['value']
andrewonlab393531a2014-10-27 18:36:26 -0400679
680 #Get delta between graph event and OFP
681 pt_down_graph_to_ofp_1 = int(graph_timestamp_1) -\
682 int(timestamp_begin_pt_down)
683 pt_down_graph_to_ofp_2 = int(graph_timestamp_2) -\
684 int(timestamp_begin_pt_down)
685 pt_down_graph_to_ofp_3 = int(graph_timestamp_3) -\
686 int(timestamp_begin_pt_down)
687
688 #Get delta between device event and OFP
689 pt_down_device_to_ofp_1 = int(device_timestamp_1) -\
690 int(timestamp_begin_pt_down)
691 pt_down_device_to_ofp_2 = int(device_timestamp_2) -\
692 int(timestamp_begin_pt_down)
693 pt_down_device_to_ofp_3 = int(device_timestamp_3) -\
694 int(timestamp_begin_pt_down)
695
696 #Caluclate average across clusters
697 pt_down_graph_to_ofp_avg =\
698 (int(pt_down_graph_to_ofp_1) +
699 int(pt_down_graph_to_ofp_2) +
andrewonlabf9828f02014-11-10 14:50:27 -0500700 int(pt_down_graph_to_ofp_3)) / 3
andrewonlab393531a2014-10-27 18:36:26 -0400701 pt_down_device_to_ofp_avg = \
702 (int(pt_down_device_to_ofp_1) +
703 int(pt_down_device_to_ofp_2) +
andrewonlabf9828f02014-11-10 14:50:27 -0500704 int(pt_down_device_to_ofp_3)) / 3
andrewonlab393531a2014-10-27 18:36:26 -0400705
andrewonlabb1998c52014-11-10 13:31:43 -0500706 if pt_down_graph_to_ofp_avg > down_threshold_min and \
707 pt_down_graph_to_ofp_avg < down_threshold_max:
andrewonlab393531a2014-10-27 18:36:26 -0400708 port_down_graph_to_ofp_list.append(
andrewonlababb11c32014-11-04 15:03:24 -0500709 pt_down_graph_to_ofp_avg)
710 main.log.info("Port down: graph to ofp avg: "+
711 str(pt_down_graph_to_ofp_avg) + " ms")
andrewonlab393531a2014-10-27 18:36:26 -0400712 else:
713 main.log.info("Average port down graph-to-ofp result" +
714 " exceeded the threshold: "+
715 str(pt_down_graph_to_ofp_avg))
716
andrewonlab3622beb2014-10-28 16:07:56 -0400717 if pt_down_device_to_ofp_avg > 0 and \
718 pt_down_device_to_ofp_avg < 1000:
719 port_down_device_to_ofp_list.append(
andrewonlababb11c32014-11-04 15:03:24 -0500720 pt_down_device_to_ofp_avg)
721 main.log.info("Port down: device to ofp avg: "+
722 str(pt_down_device_to_ofp_avg) + " ms")
andrewonlab3622beb2014-10-28 16:07:56 -0400723 else:
724 main.log.info("Average port down device-to-ofp result" +
725 " exceeded the threshold: "+
726 str(pt_down_device_to_ofp_avg))
727
andrewonlab8d29f122014-10-22 17:15:04 -0400728 #Port up events
729 main.step("Enable port and obtain timestamp")
730 main.step("Starting wireshark capture for port status up")
andrewonlabb1998c52014-11-10 13:31:43 -0500731 main.ONOS1.tshark_grep(tshark_port_status, tshark_port_up)
andrewonlab8790abb2014-11-06 13:51:54 -0500732 time.sleep(5)
andrewonlab8d29f122014-10-22 17:15:04 -0400733
andrewonlabb1998c52014-11-10 13:31:43 -0500734 main.Mininet1.handle.sendline("sh ifconfig "+
andrewonlab393531a2014-10-27 18:36:26 -0400735 interface_config+" up")
andrewonlabb1998c52014-11-10 13:31:43 -0500736 main.Mininet1.handle.expect("mininet>")
andrewonlab8790abb2014-11-06 13:51:54 -0500737
andrewonlabb1998c52014-11-10 13:31:43 -0500738 #Allow time for tshark to capture event
739 time.sleep(3)
andrewonlab8790abb2014-11-06 13:51:54 -0500740 main.ONOS1.tshark_stop()
andrewonlab8d29f122014-10-22 17:15:04 -0400741
andrewonlabb1998c52014-11-10 13:31:43 -0500742 #Obtain metrics shortly afterwards
743 #This timestsamp captures
744 #the epoch time at which the topology graph was updated.
745 main.step("Obtain t1 by REST call")
746 json_str_up_1 = main.ONOS1cli.topology_events_metrics()
747 json_str_up_2 = main.ONOS2cli.topology_events_metrics()
748 json_str_up_3 = main.ONOS3cli.topology_events_metrics()
749
750 json_obj_1 = json.loads(json_str_up_1)
751 json_obj_2 = json.loads(json_str_up_2)
752 json_obj_3 = json.loads(json_str_up_3)
753
andrewonlab8d29f122014-10-22 17:15:04 -0400754 os.system("scp "+ONOS_user+"@"+ONOS1_ip+":"+
755 tshark_port_up+" /tmp/")
756
757 f_port_up = open(tshark_port_up, 'r')
andrewonlab393531a2014-10-27 18:36:26 -0400758 f_line = f_port_up.readline()
andrewonlab8d29f122014-10-22 17:15:04 -0400759 obj_up = f_line.split(" ")
760 if len(f_line) > 0:
andrewonlabb1998c52014-11-10 13:31:43 -0500761 timestamp_begin_pt_up = int(float(obj_up[1])*1000)
andrewonlab393531a2014-10-27 18:36:26 -0400762 main.log.info("Port up begin timestamp: "+
763 str(timestamp_begin_pt_up))
andrewonlab8d29f122014-10-22 17:15:04 -0400764 else:
765 main.log.info("Tshark output file returned unexpected"+
766 " results.")
767 timestamp_begin_pt_up = 0
768
andrewonlab393531a2014-10-27 18:36:26 -0400769 f_port_up.close()
770
andrewonlab393531a2014-10-27 18:36:26 -0400771 graph_timestamp_1 = \
772 json_obj_1[graphTimestamp]['value']
773 graph_timestamp_2 = \
774 json_obj_2[graphTimestamp]['value']
775 graph_timestamp_3 = \
776 json_obj_3[graphTimestamp]['value']
777
778 #Obtain device timestamp. This timestamp captures
779 #the epoch time at which the device event happened
780 device_timestamp_1 = \
781 json_obj_1[deviceTimestamp]['value']
782 device_timestamp_2 = \
783 json_obj_2[deviceTimestamp]['value']
784 device_timestamp_3 = \
785 json_obj_3[deviceTimestamp]['value']
786
787 #Get delta between graph event and OFP
788 pt_up_graph_to_ofp_1 = int(graph_timestamp_1) -\
andrewonlab8d29f122014-10-22 17:15:04 -0400789 int(timestamp_begin_pt_up)
andrewonlab393531a2014-10-27 18:36:26 -0400790 pt_up_graph_to_ofp_2 = int(graph_timestamp_2) -\
andrewonlab8d29f122014-10-22 17:15:04 -0400791 int(timestamp_begin_pt_up)
andrewonlab393531a2014-10-27 18:36:26 -0400792 pt_up_graph_to_ofp_3 = int(graph_timestamp_3) -\
793 int(timestamp_begin_pt_up)
794
795 #Get delta between device event and OFP
796 pt_up_device_to_ofp_1 = int(device_timestamp_1) -\
797 int(timestamp_begin_pt_up)
798 pt_up_device_to_ofp_2 = int(device_timestamp_2) -\
799 int(timestamp_begin_pt_up)
800 pt_up_device_to_ofp_3 = int(device_timestamp_3) -\
andrewonlab8d29f122014-10-22 17:15:04 -0400801 int(timestamp_begin_pt_up)
andrewonlab3622beb2014-10-28 16:07:56 -0400802
andrewonlabb1998c52014-11-10 13:31:43 -0500803 main.log.info("ONOS1 delta G2O: "+str(pt_up_graph_to_ofp_1))
804 main.log.info("ONOS2 delta G2O: "+str(pt_up_graph_to_ofp_2))
805 main.log.info("ONOS3 delta G2O: "+str(pt_up_graph_to_ofp_3))
806
807 main.log.info("ONOS1 delta D2O: "+str(pt_up_device_to_ofp_1))
808 main.log.info("ONOS2 delta D2O: "+str(pt_up_device_to_ofp_2))
809 main.log.info("ONOS3 delta D2O: "+str(pt_up_device_to_ofp_3))
810
andrewonlab3622beb2014-10-28 16:07:56 -0400811 pt_up_graph_to_ofp_avg = \
andrewonlabf9828f02014-11-10 14:50:27 -0500812 (int(pt_up_graph_to_ofp_1) +
813 int(pt_up_graph_to_ofp_2) +
814 int(pt_up_graph_to_ofp_3)) / 3
andrewonlab3622beb2014-10-28 16:07:56 -0400815
816 pt_up_device_to_ofp_avg = \
andrewonlabf9828f02014-11-10 14:50:27 -0500817 (int(pt_up_device_to_ofp_1) +
818 int(pt_up_device_to_ofp_2) +
819 int(pt_up_device_to_ofp_3)) / 3
andrewonlab3622beb2014-10-28 16:07:56 -0400820
andrewonlabe5bcef92014-11-06 17:53:20 -0500821 if pt_up_graph_to_ofp_avg > up_threshold_min and \
822 pt_up_graph_to_ofp_avg < up_threshold_max:
andrewonlab3622beb2014-10-28 16:07:56 -0400823 port_up_graph_to_ofp_list.append(
824 pt_up_graph_to_ofp_avg)
andrewonlababb11c32014-11-04 15:03:24 -0500825 main.log.info("Port down: graph to ofp avg: "+
826 str(pt_up_graph_to_ofp_avg) + " ms")
andrewonlab3622beb2014-10-28 16:07:56 -0400827 else:
828 main.log.info("Average port up graph-to-ofp result"+
829 " exceeded the threshold: "+
830 str(pt_up_graph_to_ofp_avg))
831
andrewonlabe5bcef92014-11-06 17:53:20 -0500832 if pt_up_device_to_ofp_avg > up_threshold_min and \
833 pt_up_device_to_ofp_avg < up_threshold_max:
andrewonlab3622beb2014-10-28 16:07:56 -0400834 port_up_device_to_ofp_list.append(
835 pt_up_device_to_ofp_avg)
andrewonlababb11c32014-11-04 15:03:24 -0500836 main.log.info("Port up: device to ofp avg: "+
837 str(pt_up_device_to_ofp_avg) + " ms")
andrewonlab3622beb2014-10-28 16:07:56 -0400838 else:
andrewonlababb11c32014-11-04 15:03:24 -0500839 main.log.info("Average port up device-to-ofp result"+
andrewonlab3622beb2014-10-28 16:07:56 -0400840 " exceeded the threshold: "+
841 str(pt_up_device_to_ofp_avg))
andrewonlab8d29f122014-10-22 17:15:04 -0400842
andrewonlab3622beb2014-10-28 16:07:56 -0400843 #END ITERATION FOR LOOP
andrewonlab8790abb2014-11-06 13:51:54 -0500844
845 #Check all list for latency existence and set assertion
846 if (port_down_graph_to_ofp_list and port_down_device_to_ofp_list\
847 and port_up_graph_to_ofp_list and port_up_device_to_ofp_list):
848 assertion = main.TRUE
849
andrewonlababb11c32014-11-04 15:03:24 -0500850 #Calculate and report latency measurements
andrewonlab3622beb2014-10-28 16:07:56 -0400851 port_down_graph_to_ofp_min = min(port_down_graph_to_ofp_list)
852 port_down_graph_to_ofp_max = max(port_down_graph_to_ofp_list)
853 port_down_graph_to_ofp_avg = \
854 (sum(port_down_graph_to_ofp_list) /
855 len(port_down_graph_to_ofp_list))
andrewonlab69864162014-11-11 16:28:48 -0500856 port_down_graph_to_ofp_std_dev = \
857 str(round(numpy.std(port_down_graph_to_ofp_list),1))
andrewonlab3622beb2014-10-28 16:07:56 -0400858
andrewonlab4f50ec92014-11-11 14:24:45 -0500859 main.log.report("Port down graph-to-ofp "+
860 "Avg: "+str(port_down_graph_to_ofp_avg)+" ms "+
andrewonlab69864162014-11-11 16:28:48 -0500861 "Std Deviation: "+port_down_graph_to_ofp_std_dev+" ms")
andrewonlababb11c32014-11-04 15:03:24 -0500862
863 port_down_device_to_ofp_min = min(port_down_device_to_ofp_list)
864 port_down_device_to_ofp_max = max(port_down_device_to_ofp_list)
865 port_down_device_to_ofp_avg = \
866 (sum(port_down_device_to_ofp_list) /\
867 len(port_down_device_to_ofp_list))
andrewonlab69864162014-11-11 16:28:48 -0500868 port_down_device_to_ofp_std_dev = \
869 str(round(numpy.std(port_down_device_to_ofp_list),1))
andrewonlababb11c32014-11-04 15:03:24 -0500870
andrewonlab4f50ec92014-11-11 14:24:45 -0500871 main.log.report("Port down device-to-ofp "+
872 "Avg: "+str(port_down_device_to_ofp_avg)+" ms "+
andrewonlab69864162014-11-11 16:28:48 -0500873 "Std Deviation: "+port_down_device_to_ofp_std_dev+" ms")
andrewonlababb11c32014-11-04 15:03:24 -0500874
875 port_up_graph_to_ofp_min = min(port_up_graph_to_ofp_list)
876 port_up_graph_to_ofp_max = max(port_up_graph_to_ofp_list)
877 port_up_graph_to_ofp_avg = \
878 (sum(port_up_graph_to_ofp_list) /\
879 len(port_up_graph_to_ofp_list))
andrewonlab69864162014-11-11 16:28:48 -0500880 port_up_graph_to_ofp_std_dev = \
881 str(round(numpy.std(port_up_graph_to_ofp_list),1))
andrewonlab8790abb2014-11-06 13:51:54 -0500882
andrewonlab4f50ec92014-11-11 14:24:45 -0500883 main.log.report("Port up graph-to-ofp "+
884 "Avg: "+str(port_up_graph_to_ofp_avg)+" ms "+
andrewonlab69864162014-11-11 16:28:48 -0500885 "Std Deviation: "+port_up_graph_to_ofp_std_dev+" ms")
andrewonlab8790abb2014-11-06 13:51:54 -0500886
887 port_up_device_to_ofp_min = min(port_up_device_to_ofp_list)
888 port_up_device_to_ofp_max = max(port_up_device_to_ofp_list)
889 port_up_device_to_ofp_avg = \
890 (sum(port_up_device_to_ofp_list) /\
891 len(port_up_device_to_ofp_list))
andrewonlab69864162014-11-11 16:28:48 -0500892 port_up_device_to_ofp_std_dev = \
893 str(round(numpy.std(port_up_device_to_ofp_list),1))
andrewonlab8790abb2014-11-06 13:51:54 -0500894
andrewonlab4f50ec92014-11-11 14:24:45 -0500895 main.log.report("Port up device-to-ofp "+
896 "Avg: "+str(port_up_device_to_ofp_avg)+" ms "+
andrewonlab69864162014-11-11 16:28:48 -0500897 "Std Deviation: "+port_up_device_to_ofp_std_dev+" ms")
andrewonlab8790abb2014-11-06 13:51:54 -0500898
899 utilities.assert_equals(expect=main.TRUE, actual=assertion,
900 onpass="Port discovery latency calculation successful",
901 onfail="Port discovery test failed")
andrewonlababb11c32014-11-04 15:03:24 -0500902
andrewonlab3622beb2014-10-28 16:07:56 -0400903 def CASE4(self, main):
904 '''
905 Link down event using loss rate 100%
andrewonlab53b641c2014-10-31 19:44:44 -0400906
907 Important:
908 Use a simple 2 switch topology with 1 link between
909 the two switches. Ensure that mac addresses of the
910 switches are 1 / 2 respectively
andrewonlab3622beb2014-10-28 16:07:56 -0400911 '''
912 import time
913 import subprocess
914 import os
915 import requests
916 import json
andrewonlab4f50ec92014-11-11 14:24:45 -0500917 import numpy
918
andrewonlab3622beb2014-10-28 16:07:56 -0400919 ONOS1_ip = main.params['CTRL']['ip1']
920 ONOS2_ip = main.params['CTRL']['ip2']
921 ONOS3_ip = main.params['CTRL']['ip3']
922 ONOS_user = main.params['CTRL']['user']
923
924 default_sw_port = main.params['CTRL']['port1']
925
926 #Number of iterations of case
927 num_iter = main.params['TEST']['numIter']
928
929 #Timestamp 'keys' for json metrics output.
930 #These are subject to change, hence moved into params
931 deviceTimestamp = main.params['JSON']['deviceTimestamp']
932 linkTimestamp = main.params['JSON']['linkTimestamp']
andrewonlab53b641c2014-10-31 19:44:44 -0400933 graphTimestamp = main.params['JSON']['graphTimestamp']
andrewonlab58f7d702014-11-07 13:21:19 -0500934
935 debug_mode = main.params['TEST']['debugMode']
936
937 local_time = time.strftime('%x %X')
andrewonlabb1998c52014-11-10 13:31:43 -0500938 local_time = local_time.replace("/","")
939 local_time = local_time.replace(" ","_")
940 local_time = local_time.replace(":","")
andrewonlab58f7d702014-11-07 13:21:19 -0500941 if debug_mode == 'on':
942 main.ONOS1.tshark_pcap("eth0",
andrewonlabb1998c52014-11-10 13:31:43 -0500943 "/tmp/link_lat_pcap_"+local_time)
andrewonlab53b641c2014-10-31 19:44:44 -0400944
andrewonlabe5bcef92014-11-06 17:53:20 -0500945 #Threshold for this test case
946 up_threshold_str = main.params['TEST']['linkUpThreshold']
947 down_threshold_str = main.params['TEST']['linkDownThreshold']
948
949 up_threshold_obj = up_threshold_str.split(",")
950 down_threshold_obj = down_threshold_str.split(",")
951
952 up_threshold_min = int(up_threshold_obj[0])
953 up_threshold_max = int(up_threshold_obj[1])
954
955 down_threshold_min = int(down_threshold_obj[0])
956 down_threshold_max = int(down_threshold_obj[1])
957
andrewonlab3622beb2014-10-28 16:07:56 -0400958 assertion = main.TRUE
959 #Link event timestamp to system time list
960 link_down_link_to_system_list = []
961 link_up_link_to_system_list = []
962 #Graph event timestamp to system time list
963 link_down_graph_to_system_list = []
964 link_up_graph_to_system_list = []
965
andrewonlab4b5c8b92014-11-10 16:04:33 -0500966 main.log.report("Link up / down discovery latency between "+
andrewonlab3622beb2014-10-28 16:07:56 -0400967 "two switches")
andrewonlab4b5c8b92014-11-10 16:04:33 -0500968 main.log.report("Simulated by setting loss-rate 100%")
969 main.log.report("'tc qdisc add dev <intfs> root netem loss 100%'")
970 main.log.report("Total iterations of test: "+str(num_iter))
andrewonlab3622beb2014-10-28 16:07:56 -0400971
972 main.step("Assign all switches")
973 main.Mininet1.assign_sw_controller(sw="1",
974 ip1=ONOS1_ip, port1=default_sw_port)
975 main.Mininet1.assign_sw_controller(sw="2",
976 ip1=ONOS1_ip, port1=default_sw_port)
977
978 main.step("Verifying switch assignment")
979 result_s1 = main.Mininet1.get_sw_controller(sw="s1")
980 result_s2 = main.Mininet1.get_sw_controller(sw="s2")
andrewonlab3622beb2014-10-28 16:07:56 -0400981
982 #Allow time for events to finish before taking measurements
983 time.sleep(10)
984
andrewonlababb11c32014-11-04 15:03:24 -0500985 link_down1 = False
986 link_down2 = False
987 link_down3 = False
andrewonlab3622beb2014-10-28 16:07:56 -0400988 #Start iteration of link event test
989 for i in range(0, int(num_iter)):
990 main.step("Getting initial system time as t0")
andrewonlab8d29f122014-10-22 17:15:04 -0400991
andrewonlab3622beb2014-10-28 16:07:56 -0400992 timestamp_link_down_t0 = time.time() * 1000
993 #Link down is simulated by 100% loss rate using traffic
994 #control command
995 main.Mininet1.handle.sendline(
996 "sh tc qdisc add dev s1-eth1 root netem loss 100%")
997
andrewonlab53b641c2014-10-31 19:44:44 -0400998 #TODO: Iterate through 'links' command to verify that
andrewonlababb11c32014-11-04 15:03:24 -0500999 # link s1 -> s2 went down (loop timeout 30 seconds)
1000 # on all 3 ONOS instances
andrewonlab53b641c2014-10-31 19:44:44 -04001001 main.log.info("Checking ONOS for link update")
1002 loop_count = 0
andrewonlababb11c32014-11-04 15:03:24 -05001003 while( not (link_down1 and link_down2 and link_down3)\
1004 and loop_count < 30 ):
1005 json_str1 = main.ONOS1cli.links()
1006 json_str2 = main.ONOS2cli.links()
1007 json_str3 = main.ONOS3cli.links()
1008
1009 if not (json_str1 and json_str2 and json_str3):
1010 main.log.error("CLI command returned error ")
andrewonlab53b641c2014-10-31 19:44:44 -04001011 break
1012 else:
andrewonlababb11c32014-11-04 15:03:24 -05001013 json_obj1 = json.loads(json_str1)
1014 json_obj2 = json.loads(json_str2)
1015 json_obj3 = json.loads(json_str3)
1016 for obj1 in json_obj1:
1017 if '01' not in obj1['src']['device']:
1018 link_down1 = True
andrewonlabf9828f02014-11-10 14:50:27 -05001019 main.log.info("Link down from "+
andrewonlababb11c32014-11-04 15:03:24 -05001020 "s1 -> s2 on ONOS1 detected")
1021 for obj2 in json_obj2:
1022 if '01' not in obj2['src']['device']:
1023 link_down2 = True
andrewonlabf9828f02014-11-10 14:50:27 -05001024 main.log.info("Link down from "+
andrewonlababb11c32014-11-04 15:03:24 -05001025 "s1 -> s2 on ONOS2 detected")
1026 for obj3 in json_obj3:
1027 if '01' not in obj3['src']['device']:
1028 link_down3 = True
andrewonlabf9828f02014-11-10 14:50:27 -05001029 main.log.info("Link down from "+
andrewonlababb11c32014-11-04 15:03:24 -05001030 "s1 -> s2 on ONOS3 detected")
1031
andrewonlab53b641c2014-10-31 19:44:44 -04001032 loop_count += 1
andrewonlababb11c32014-11-04 15:03:24 -05001033 #If CLI doesn't like the continuous requests
1034 #and exits in this loop, increase the sleep here.
1035 #Consequently, while loop timeout will increase
andrewonlab53b641c2014-10-31 19:44:44 -04001036 time.sleep(1)
1037
1038 #Give time for metrics measurement to catch up
andrewonlababb11c32014-11-04 15:03:24 -05001039 #NOTE: May need to be configured more accurately
andrewonlab53b641c2014-10-31 19:44:44 -04001040 time.sleep(10)
andrewonlababb11c32014-11-04 15:03:24 -05001041 #If we exited the while loop and link down 1,2,3 are still
andrewonlab53b641c2014-10-31 19:44:44 -04001042 #false, then ONOS has failed to discover link down event
andrewonlababb11c32014-11-04 15:03:24 -05001043 if not (link_down1 and link_down2 and link_down3):
andrewonlab53b641c2014-10-31 19:44:44 -04001044 main.log.info("Link down discovery failed")
1045
1046 link_down_lat_graph1 = 0
1047 link_down_lat_graph2 = 0
1048 link_down_lat_graph3 = 0
1049 link_down_lat_device1 = 0
1050 link_down_lat_device2 = 0
1051 link_down_lat_device3 = 0
1052
1053 assertion = main.FALSE
1054 else:
1055 json_topo_metrics_1 =\
1056 main.ONOS1cli.topology_events_metrics()
1057 json_topo_metrics_2 =\
1058 main.ONOS2cli.topology_events_metrics()
1059 json_topo_metrics_3 =\
1060 main.ONOS3cli.topology_events_metrics()
1061 json_topo_metrics_1 = json.loads(json_topo_metrics_1)
1062 json_topo_metrics_2 = json.loads(json_topo_metrics_2)
1063 json_topo_metrics_3 = json.loads(json_topo_metrics_3)
1064
1065 main.log.info("Obtaining graph and device timestamp")
1066 graph_timestamp_1 = \
1067 json_topo_metrics_1[graphTimestamp]['value']
1068 graph_timestamp_2 = \
1069 json_topo_metrics_2[graphTimestamp]['value']
1070 graph_timestamp_3 = \
1071 json_topo_metrics_3[graphTimestamp]['value']
1072
1073 link_timestamp_1 = \
1074 json_topo_metrics_1[linkTimestamp]['value']
1075 link_timestamp_2 = \
1076 json_topo_metrics_2[linkTimestamp]['value']
1077 link_timestamp_3 = \
1078 json_topo_metrics_3[linkTimestamp]['value']
1079
1080 if graph_timestamp_1 and graph_timestamp_2 and\
1081 graph_timestamp_3 and link_timestamp_1 and\
1082 link_timestamp_2 and link_timestamp_3:
1083 link_down_lat_graph1 = int(graph_timestamp_1) -\
andrewonlab4f50ec92014-11-11 14:24:45 -05001084 int(timestamp_link_down_t0)
andrewonlab53b641c2014-10-31 19:44:44 -04001085 link_down_lat_graph2 = int(graph_timestamp_2) -\
andrewonlab4f50ec92014-11-11 14:24:45 -05001086 int(timestamp_link_down_t0)
andrewonlab53b641c2014-10-31 19:44:44 -04001087 link_down_lat_graph3 = int(graph_timestamp_3) -\
andrewonlab4f50ec92014-11-11 14:24:45 -05001088 int(timestamp_link_down_t0)
andrewonlab53b641c2014-10-31 19:44:44 -04001089
1090 link_down_lat_link1 = int(link_timestamp_1) -\
andrewonlab4f50ec92014-11-11 14:24:45 -05001091 int(timestamp_link_down_t0)
andrewonlab53b641c2014-10-31 19:44:44 -04001092 link_down_lat_link2 = int(link_timestamp_2) -\
andrewonlab4f50ec92014-11-11 14:24:45 -05001093 int(timestamp_link_down_t0)
andrewonlab53b641c2014-10-31 19:44:44 -04001094 link_down_lat_link3 = int(link_timestamp_3) -\
andrewonlab4f50ec92014-11-11 14:24:45 -05001095 int(timestamp_link_down_t0)
andrewonlab53b641c2014-10-31 19:44:44 -04001096 else:
1097 main.log.error("There was an error calculating"+
1098 " the delta for link down event")
1099 link_down_lat_graph1 = 0
1100 link_down_lat_graph2 = 0
1101 link_down_lat_graph3 = 0
1102
1103 link_down_lat_device1 = 0
1104 link_down_lat_device2 = 0
1105 link_down_lat_device3 = 0
1106
andrewonlabf9828f02014-11-10 14:50:27 -05001107 main.log.info("Link down latency ONOS1 iteration "+
andrewonlab4e124482014-11-04 13:37:25 -05001108 str(i)+" (end-to-end): "+
andrewonlababb11c32014-11-04 15:03:24 -05001109 str(link_down_lat_graph1)+" ms")
andrewonlabf9828f02014-11-10 14:50:27 -05001110 main.log.info("Link down latency ONOS2 iteration "+
andrewonlab4e124482014-11-04 13:37:25 -05001111 str(i)+" (end-to-end): "+
andrewonlababb11c32014-11-04 15:03:24 -05001112 str(link_down_lat_graph2)+" ms")
andrewonlabf9828f02014-11-10 14:50:27 -05001113 main.log.info("Link down latency ONOS3 iteration "+
andrewonlab4e124482014-11-04 13:37:25 -05001114 str(i)+" (end-to-end): "+
andrewonlababb11c32014-11-04 15:03:24 -05001115 str(link_down_lat_graph3)+" ms")
andrewonlab4e124482014-11-04 13:37:25 -05001116
andrewonlabf9828f02014-11-10 14:50:27 -05001117 main.log.info("Link down latency ONOS1 iteration "+
andrewonlab4e124482014-11-04 13:37:25 -05001118 str(i)+" (link-event-to-system-timestamp): "+
andrewonlababb11c32014-11-04 15:03:24 -05001119 str(link_down_lat_link1)+" ms")
andrewonlabf9828f02014-11-10 14:50:27 -05001120 main.log.info("Link down latency ONOS2 iteration "+
andrewonlab4e124482014-11-04 13:37:25 -05001121 str(i)+" (link-event-to-system-timestamp): "+
andrewonlababb11c32014-11-04 15:03:24 -05001122 str(link_down_lat_link2)+" ms")
andrewonlabf9828f02014-11-10 14:50:27 -05001123 main.log.info("Link down latency ONOS3 iteration "+
andrewonlab4e124482014-11-04 13:37:25 -05001124 str(i)+" (link-event-to-system-timestamp): "+
1125 str(link_down_lat_link3))
1126
1127 #Calculate avg of node calculations
1128 link_down_lat_graph_avg =\
andrewonlababb11c32014-11-04 15:03:24 -05001129 (link_down_lat_graph1 +
1130 link_down_lat_graph2 +
andrewonlab65d73892014-11-10 17:36:00 -05001131 link_down_lat_graph3) / 3
andrewonlab4e124482014-11-04 13:37:25 -05001132 link_down_lat_link_avg =\
andrewonlababb11c32014-11-04 15:03:24 -05001133 (link_down_lat_link1 +
1134 link_down_lat_link2 +
andrewonlab65d73892014-11-10 17:36:00 -05001135 link_down_lat_link3) / 3
andrewonlab53b641c2014-10-31 19:44:44 -04001136
andrewonlab4e124482014-11-04 13:37:25 -05001137 #Set threshold and append latency to list
andrewonlabe5bcef92014-11-06 17:53:20 -05001138 if link_down_lat_graph_avg > down_threshold_min and\
1139 link_down_lat_graph_avg < down_threshold_max:
andrewonlab4e124482014-11-04 13:37:25 -05001140 link_down_graph_to_system_list.append(
1141 link_down_lat_graph_avg)
andrewonlab8790abb2014-11-06 13:51:54 -05001142 else:
1143 main.log.info("Link down latency exceeded threshold")
1144 main.log.info("Results for iteration "+str(i)+
1145 "have been omitted")
andrewonlabe5bcef92014-11-06 17:53:20 -05001146 if link_down_lat_link_avg > down_threshold_min and\
1147 link_down_lat_link_avg < down_threshold_max:
andrewonlab4e124482014-11-04 13:37:25 -05001148 link_down_link_to_system_list.append(
1149 link_down_lat_link_avg)
andrewonlab8790abb2014-11-06 13:51:54 -05001150 else:
1151 main.log.info("Link down latency exceeded threshold")
1152 main.log.info("Results for iteration "+str(i)+
1153 "have been omitted")
andrewonlab53b641c2014-10-31 19:44:44 -04001154
1155 #NOTE: To remove loss rate and measure latency:
1156 # 'sh tc qdisc del dev s1-eth1 root'
andrewonlababb11c32014-11-04 15:03:24 -05001157 timestamp_link_up_t0 = time.time() * 1000
andrewonlab53b641c2014-10-31 19:44:44 -04001158 main.Mininet1.handle.sendline("sh tc qdisc del dev "+
1159 "s1-eth1 root")
1160 main.Mininet1.handle.expect("mininet>")
andrewonlababb11c32014-11-04 15:03:24 -05001161
1162 main.log.info("Checking ONOS for link update")
1163
1164 link_down1 = True
1165 link_down2 = True
1166 link_down3 = True
1167 loop_count = 0
1168 while( (link_down1 and link_down2 and link_down3)\
1169 and loop_count < 30 ):
1170 json_str1 = main.ONOS1cli.links()
1171 json_str2 = main.ONOS2cli.links()
1172 json_str3 = main.ONOS3cli.links()
1173 if not (json_str1 and json_str2 and json_str3):
1174 main.log.error("CLI command returned error ")
1175 break
1176 else:
1177 json_obj1 = json.loads(json_str1)
1178 json_obj2 = json.loads(json_str2)
1179 json_obj3 = json.loads(json_str3)
1180
1181 for obj1 in json_obj1:
1182 if '01' in obj1['src']['device']:
1183 link_down1 = False
andrewonlabf9828f02014-11-10 14:50:27 -05001184 main.log.info("Link up from "+
andrewonlababb11c32014-11-04 15:03:24 -05001185 "s1 -> s2 on ONOS1 detected")
1186 for obj2 in json_obj2:
1187 if '01' in obj2['src']['device']:
1188 link_down2 = False
andrewonlabf9828f02014-11-10 14:50:27 -05001189 main.log.info("Link up from "+
andrewonlababb11c32014-11-04 15:03:24 -05001190 "s1 -> s2 on ONOS2 detected")
1191 for obj3 in json_obj3:
1192 if '01' in obj3['src']['device']:
1193 link_down3 = False
andrewonlabf9828f02014-11-10 14:50:27 -05001194 main.log.info("Link up from "+
andrewonlababb11c32014-11-04 15:03:24 -05001195 "s1 -> s2 on ONOS3 detected")
1196
1197 loop_count += 1
1198 time.sleep(1)
1199
1200 if (link_down1 and link_down2 and link_down3):
1201 main.log.info("Link up discovery failed")
1202
1203 link_up_lat_graph1 = 0
1204 link_up_lat_graph2 = 0
1205 link_up_lat_graph3 = 0
1206 link_up_lat_device1 = 0
1207 link_up_lat_device2 = 0
1208 link_up_lat_device3 = 0
1209
1210 assertion = main.FALSE
1211 else:
1212 json_topo_metrics_1 =\
1213 main.ONOS1cli.topology_events_metrics()
1214 json_topo_metrics_2 =\
1215 main.ONOS2cli.topology_events_metrics()
1216 json_topo_metrics_3 =\
1217 main.ONOS3cli.topology_events_metrics()
1218 json_topo_metrics_1 = json.loads(json_topo_metrics_1)
1219 json_topo_metrics_2 = json.loads(json_topo_metrics_2)
1220 json_topo_metrics_3 = json.loads(json_topo_metrics_3)
1221
1222 main.log.info("Obtaining graph and device timestamp")
1223 graph_timestamp_1 = \
1224 json_topo_metrics_1[graphTimestamp]['value']
1225 graph_timestamp_2 = \
1226 json_topo_metrics_2[graphTimestamp]['value']
1227 graph_timestamp_3 = \
1228 json_topo_metrics_3[graphTimestamp]['value']
1229
1230 link_timestamp_1 = \
1231 json_topo_metrics_1[linkTimestamp]['value']
1232 link_timestamp_2 = \
1233 json_topo_metrics_2[linkTimestamp]['value']
1234 link_timestamp_3 = \
1235 json_topo_metrics_3[linkTimestamp]['value']
1236
1237 if graph_timestamp_1 and graph_timestamp_2 and\
1238 graph_timestamp_3 and link_timestamp_1 and\
1239 link_timestamp_2 and link_timestamp_3:
1240 link_up_lat_graph1 = int(graph_timestamp_1) -\
andrewonlab4f50ec92014-11-11 14:24:45 -05001241 int(timestamp_link_up_t0)
andrewonlababb11c32014-11-04 15:03:24 -05001242 link_up_lat_graph2 = int(graph_timestamp_2) -\
andrewonlab4f50ec92014-11-11 14:24:45 -05001243 int(timestamp_link_up_t0)
andrewonlababb11c32014-11-04 15:03:24 -05001244 link_up_lat_graph3 = int(graph_timestamp_3) -\
andrewonlab4f50ec92014-11-11 14:24:45 -05001245 int(timestamp_link_up_t0)
andrewonlababb11c32014-11-04 15:03:24 -05001246
1247 link_up_lat_link1 = int(link_timestamp_1) -\
andrewonlab4f50ec92014-11-11 14:24:45 -05001248 int(timestamp_link_up_t0)
andrewonlababb11c32014-11-04 15:03:24 -05001249 link_up_lat_link2 = int(link_timestamp_2) -\
andrewonlab4f50ec92014-11-11 14:24:45 -05001250 int(timestamp_link_up_t0)
andrewonlababb11c32014-11-04 15:03:24 -05001251 link_up_lat_link3 = int(link_timestamp_3) -\
andrewonlab4f50ec92014-11-11 14:24:45 -05001252 int(timestamp_link_up_t0)
andrewonlababb11c32014-11-04 15:03:24 -05001253 else:
1254 main.log.error("There was an error calculating"+
1255 " the delta for link down event")
1256 link_up_lat_graph1 = 0
1257 link_up_lat_graph2 = 0
1258 link_up_lat_graph3 = 0
1259
1260 link_up_lat_device1 = 0
1261 link_up_lat_device2 = 0
1262 link_up_lat_device3 = 0
andrewonlab58f7d702014-11-07 13:21:19 -05001263
1264 if debug_mode == 'on':
1265 main.log.info("Link up latency ONOS1 iteration "+
andrewonlababb11c32014-11-04 15:03:24 -05001266 str(i)+" (end-to-end): "+
1267 str(link_up_lat_graph1)+" ms")
andrewonlab58f7d702014-11-07 13:21:19 -05001268 main.log.info("Link up latency ONOS2 iteration "+
andrewonlababb11c32014-11-04 15:03:24 -05001269 str(i)+" (end-to-end): "+
1270 str(link_up_lat_graph2)+" ms")
andrewonlab58f7d702014-11-07 13:21:19 -05001271 main.log.info("Link up latency ONOS3 iteration "+
andrewonlababb11c32014-11-04 15:03:24 -05001272 str(i)+" (end-to-end): "+
1273 str(link_up_lat_graph3)+" ms")
1274
andrewonlab58f7d702014-11-07 13:21:19 -05001275 main.log.info("Link up latency ONOS1 iteration "+
andrewonlababb11c32014-11-04 15:03:24 -05001276 str(i)+" (link-event-to-system-timestamp): "+
1277 str(link_up_lat_link1)+" ms")
andrewonlab58f7d702014-11-07 13:21:19 -05001278 main.log.info("Link up latency ONOS2 iteration "+
andrewonlababb11c32014-11-04 15:03:24 -05001279 str(i)+" (link-event-to-system-timestamp): "+
1280 str(link_up_lat_link2)+" ms")
andrewonlab58f7d702014-11-07 13:21:19 -05001281 main.log.info("Link up latency ONOS3 iteration "+
andrewonlababb11c32014-11-04 15:03:24 -05001282 str(i)+" (link-event-to-system-timestamp): "+
1283 str(link_up_lat_link3))
1284
1285 #Calculate avg of node calculations
1286 link_up_lat_graph_avg =\
1287 (link_up_lat_graph1 +
1288 link_up_lat_graph2 +
andrewonlabf9828f02014-11-10 14:50:27 -05001289 link_up_lat_graph3) / 3
andrewonlababb11c32014-11-04 15:03:24 -05001290 link_up_lat_link_avg =\
1291 (link_up_lat_link1 +
1292 link_up_lat_link2 +
andrewonlabf9828f02014-11-10 14:50:27 -05001293 link_up_lat_link3) / 3
andrewonlababb11c32014-11-04 15:03:24 -05001294
1295 #Set threshold and append latency to list
andrewonlabe5bcef92014-11-06 17:53:20 -05001296 if link_up_lat_graph_avg > up_threshold_min and\
1297 link_up_lat_graph_avg < up_threshold_max:
andrewonlababb11c32014-11-04 15:03:24 -05001298 link_up_graph_to_system_list.append(
1299 link_up_lat_graph_avg)
andrewonlab8790abb2014-11-06 13:51:54 -05001300 else:
1301 main.log.info("Link up latency exceeded threshold")
1302 main.log.info("Results for iteration "+str(i)+
1303 "have been omitted")
andrewonlabe5bcef92014-11-06 17:53:20 -05001304 if link_up_lat_link_avg > up_threshold_min and\
1305 link_up_lat_link_avg < up_threshold_max:
andrewonlababb11c32014-11-04 15:03:24 -05001306 link_up_link_to_system_list.append(
1307 link_up_lat_link_avg)
andrewonlab8790abb2014-11-06 13:51:54 -05001308 else:
1309 main.log.info("Link up latency exceeded threshold")
1310 main.log.info("Results for iteration "+str(i)+
1311 "have been omitted")
andrewonlab53b641c2014-10-31 19:44:44 -04001312
andrewonlab4e124482014-11-04 13:37:25 -05001313 #Calculate min, max, avg of list and report
1314 link_down_min = min(link_down_graph_to_system_list)
1315 link_down_max = max(link_down_graph_to_system_list)
1316 link_down_avg = sum(link_down_graph_to_system_list) / \
1317 len(link_down_graph_to_system_list)
andrewonlababb11c32014-11-04 15:03:24 -05001318 link_up_min = min(link_up_graph_to_system_list)
1319 link_up_max = max(link_up_graph_to_system_list)
1320 link_up_avg = sum(link_up_graph_to_system_list) / \
1321 len(link_up_graph_to_system_list)
andrewonlab69864162014-11-11 16:28:48 -05001322 link_down_std_dev = \
1323 str(round(numpy.std(link_down_graph_to_system_list),1))
1324 link_up_std_dev = \
1325 str(round(numpy.std(link_up_graph_to_system_list),1))
andrewonlababb11c32014-11-04 15:03:24 -05001326
andrewonlab4f50ec92014-11-11 14:24:45 -05001327 main.log.report("Link down latency " +
1328 "Avg: "+str(link_down_avg)+" ms "+
andrewonlab69864162014-11-11 16:28:48 -05001329 "Std Deviation: "+link_down_std_dev+" ms")
andrewonlab4f50ec92014-11-11 14:24:45 -05001330 main.log.report("Link up latency "+
1331 "Avg: "+str(link_up_avg)+" ms "+
andrewonlab69864162014-11-11 16:28:48 -05001332 "Std Deviation: "+link_up_std_dev+" ms")
andrewonlab4e124482014-11-04 13:37:25 -05001333
andrewonlab8790abb2014-11-06 13:51:54 -05001334 utilities.assert_equals(expect=main.TRUE, actual=assertion,
1335 onpass="Link discovery latency calculation successful",
1336 onfail="Link discovery latency case failed")
1337
andrewonlabb54b85b2014-10-28 18:43:57 -04001338 def CASE5(self, main):
1339 '''
1340 100 Switch discovery latency
1341
1342 Important:
andrewonlab16ce4852014-10-30 13:41:09 -04001343 This test case can be potentially dangerous if
1344 your machine has previously set iptables rules.
1345 One of the steps of the test case will flush
1346 all existing iptables rules.
andrewonlab8790abb2014-11-06 13:51:54 -05001347 Note:
1348 You can specify the number of switches in the
1349 params file to adjust the switch discovery size
1350 (and specify the corresponding topology in Mininet1
1351 .topo file)
andrewonlabb54b85b2014-10-28 18:43:57 -04001352 '''
1353 import time
1354 import subprocess
1355 import os
1356 import requests
1357 import json
1358
1359 ONOS1_ip = main.params['CTRL']['ip1']
1360 ONOS2_ip = main.params['CTRL']['ip2']
1361 ONOS3_ip = main.params['CTRL']['ip3']
1362 MN1_ip = main.params['MN']['ip1']
1363 ONOS_user = main.params['CTRL']['user']
1364
1365 default_sw_port = main.params['CTRL']['port1']
1366
1367 #Number of iterations of case
1368 num_iter = main.params['TEST']['numIter']
andrewonlab16ce4852014-10-30 13:41:09 -04001369 num_sw = main.params['TEST']['numSwitch']
1370
andrewonlabb54b85b2014-10-28 18:43:57 -04001371 #Timestamp 'keys' for json metrics output.
1372 #These are subject to change, hence moved into params
1373 deviceTimestamp = main.params['JSON']['deviceTimestamp']
andrewonlab16ce4852014-10-30 13:41:09 -04001374 graphTimestamp = main.params['JSON']['graphTimestamp']
andrewonlab58f7d702014-11-07 13:21:19 -05001375
1376 debug_mode = main.params['TEST']['debugMode']
1377
andrewonlabb1998c52014-11-10 13:31:43 -05001378 local_time = time.strftime('%X')
1379 local_time = local_time.replace("/","")
1380 local_time = local_time.replace(" ","_")
1381 local_time = local_time.replace(":","")
andrewonlab58f7d702014-11-07 13:21:19 -05001382 if debug_mode == 'on':
1383 main.ONOS1.tshark_pcap("eth0",
andrewonlabb1998c52014-11-10 13:31:43 -05001384 "/tmp/100_sw_lat_pcap_"+local_time)
andrewonlabe5bcef92014-11-06 17:53:20 -05001385
1386 #Threshold for this test case
1387 sw_disc_threshold_str = main.params['TEST']['swDisc100Threshold']
1388 sw_disc_threshold_obj = sw_disc_threshold_str.split(",")
1389 sw_disc_threshold_min = int(sw_disc_threshold_obj[0])
1390 sw_disc_threshold_max = int(sw_disc_threshold_obj[1])
1391
andrewonlab53b641c2014-10-31 19:44:44 -04001392 tshark_ofp_output = "/tmp/tshark_ofp_"+num_sw+"sw.txt"
1393 tshark_tcp_output = "/tmp/tshark_tcp_"+num_sw+"sw.txt"
1394
1395 tshark_ofp_result_list = []
1396 tshark_tcp_result_list = []
andrewonlabb54b85b2014-10-28 18:43:57 -04001397
andrewonlabe5bcef92014-11-06 17:53:20 -05001398 sw_discovery_lat_list = []
1399
andrewonlab16ce4852014-10-30 13:41:09 -04001400 main.case(num_sw+" Switch discovery latency")
andrewonlabb54b85b2014-10-28 18:43:57 -04001401 main.step("Assigning all switches to ONOS1")
andrewonlab16ce4852014-10-30 13:41:09 -04001402 for i in range(1, int(num_sw)+1):
andrewonlabb54b85b2014-10-28 18:43:57 -04001403 main.Mininet1.assign_sw_controller(
1404 sw=str(i),
1405 ip1=ONOS1_ip,
1406 port1=default_sw_port)
andrewonlab16ce4852014-10-30 13:41:09 -04001407
andrewonlabb54b85b2014-10-28 18:43:57 -04001408 #Ensure that nodes are configured with ptpd
andrewonlab16ce4852014-10-30 13:41:09 -04001409 #Just a warning message
1410 main.log.info("Please check ptpd configuration to ensure"+\
1411 " All nodes' system times are in sync")
1412 time.sleep(5)
andrewonlabb54b85b2014-10-28 18:43:57 -04001413
1414 for i in range(0, int(num_iter)):
andrewonlab8d29f122014-10-22 17:15:04 -04001415
andrewonlabb54b85b2014-10-28 18:43:57 -04001416 main.step("Set iptables rule to block incoming sw connections")
1417 #Set iptables rule to block incoming switch connections
andrewonlab53b641c2014-10-31 19:44:44 -04001418 #The rule description is as follows:
1419 # Append to INPUT rule,
1420 # behavior DROP that matches following:
1421 # * packet type: tcp
1422 # * source IP: MN1_ip
1423 # * destination PORT: 6633
andrewonlabb54b85b2014-10-28 18:43:57 -04001424 main.ONOS1.handle.sendline(
andrewonlab16ce4852014-10-30 13:41:09 -04001425 "sudo iptables -A INPUT -p tcp -s "+MN1_ip+
andrewonlabb54b85b2014-10-28 18:43:57 -04001426 " --dport "+default_sw_port+" -j DROP")
1427 main.ONOS1.handle.expect("\$")
andrewonlab53b641c2014-10-31 19:44:44 -04001428 # Append to OUTPUT rule,
1429 # behavior DROP that matches following:
1430 # * packet type: tcp
1431 # * source IP: MN1_ip
1432 # * destination PORT: 6633
1433 main.ONOS1.handle.sendline(
1434 "sudo iptables -A OUTPUT -p tcp -s "+MN1_ip+
1435 " --dport "+default_sw_port+" -j DROP")
1436 main.ONOS1.handle.expect("\$")
andrewonlabb54b85b2014-10-28 18:43:57 -04001437 #Give time to allow rule to take effect
andrewonlab8790abb2014-11-06 13:51:54 -05001438 #NOTE: Sleep period may need to be configured
1439 # based on the number of switches in the topology
andrewonlab16ce4852014-10-30 13:41:09 -04001440 main.log.info("Please wait for switch connection to "+
1441 "time out")
1442 time.sleep(60)
1443
1444 #Gather vendor OFP with tshark
1445 main.ONOS1.tshark_grep("OFP 86 Vendor",
1446 tshark_ofp_output)
andrewonlab53b641c2014-10-31 19:44:44 -04001447 main.ONOS1.tshark_grep("TCP 74 ",
1448 tshark_tcp_output)
andrewonlabb54b85b2014-10-28 18:43:57 -04001449
andrewonlab16ce4852014-10-30 13:41:09 -04001450 #NOTE: Remove all iptables rule quickly (flush)
andrewonlabb54b85b2014-10-28 18:43:57 -04001451 # Before removal, obtain TestON timestamp at which
andrewonlab16ce4852014-10-30 13:41:09 -04001452 # removal took place
1453 # (ensuring nodes are configured via ptp)
andrewonlabb54b85b2014-10-28 18:43:57 -04001454 # sudo iptables -F
andrewonlab16ce4852014-10-30 13:41:09 -04001455
1456 t0_system = time.time() * 1000
1457 main.ONOS1.handle.sendline(
1458 "sudo iptables -F")
andrewonlabb54b85b2014-10-28 18:43:57 -04001459
andrewonlab16ce4852014-10-30 13:41:09 -04001460 #Counter to track loop count
1461 counter_loop = 0
1462 counter_avail1 = 0
1463 counter_avail2 = 0
1464 counter_avail3 = 0
1465 onos1_dev = False
1466 onos2_dev = False
1467 onos3_dev = False
1468 while counter_loop < 60:
1469 #Continue to check devices for all device
1470 #availability. When all devices in all 3
1471 #ONOS instances indicate that devices are available
1472 #obtain graph event timestamp for t1.
1473 device_str_obj1 = main.ONOS1cli.devices()
1474 device_str_obj2 = main.ONOS2cli.devices()
1475 device_str_obj3 = main.ONOS3cli.devices()
1476
1477 device_json1 = json.loads(device_str_obj1)
1478 device_json2 = json.loads(device_str_obj2)
1479 device_json3 = json.loads(device_str_obj3)
1480
1481 for device1 in device_json1:
1482 if device1['available'] == True:
1483 counter_avail1 += 1
1484 if counter_avail1 == int(num_sw):
1485 onos1_dev = True
1486 main.log.info("All devices have been "+
1487 "discovered on ONOS1")
1488 else:
1489 counter_avail1 = 0
1490 for device2 in device_json2:
1491 if device2['available'] == True:
1492 counter_avail2 += 1
1493 if counter_avail2 == int(num_sw):
1494 onos2_dev = True
1495 main.log.info("All devices have been "+
1496 "discovered on ONOS2")
1497 else:
1498 counter_avail2 = 0
1499 for device3 in device_json3:
1500 if device3['available'] == True:
1501 counter_avail3 += 1
1502 if counter_avail3 == int(num_sw):
1503 onos3_dev = True
1504 main.log.info("All devices have been "+
1505 "discovered on ONOS3")
1506 else:
1507 counter_avail3 = 0
1508
1509 if onos1_dev and onos2_dev and onos3_dev:
1510 main.log.info("All devices have been discovered "+
1511 "on all ONOS instances")
1512 json_str_topology_metrics_1 =\
1513 main.ONOS1cli.topology_events_metrics()
1514 json_str_topology_metrics_2 =\
1515 main.ONOS2cli.topology_events_metrics()
1516 json_str_topology_metrics_3 =\
1517 main.ONOS3cli.topology_events_metrics()
andrewonlab53b641c2014-10-31 19:44:44 -04001518
1519 #Exit while loop if all devices discovered
andrewonlab16ce4852014-10-30 13:41:09 -04001520 break
1521
1522 counter_loop += 1
1523 #Give some time in between CLI calls
1524 #(will not affect measurement)
1525 time.sleep(3)
1526
1527 main.ONOS1.tshark_stop()
1528
1529 os.system("scp "+ONOS_user+"@"+ONOS1_ip+":"+
1530 tshark_ofp_output+" /tmp/")
andrewonlab53b641c2014-10-31 19:44:44 -04001531 os.system("scp "+ONOS_user+"@"+ONOS1_ip+":"+
1532 tshark_tcp_output+" /tmp/")
andrewonlab16ce4852014-10-30 13:41:09 -04001533
andrewonlab16ce4852014-10-30 13:41:09 -04001534 #TODO: Automate OFP output analysis
andrewonlab58f7d702014-11-07 13:21:19 -05001535 #Debug mode - print out packets captured at runtime
1536 if debug_mode == 'on':
1537 ofp_file = open(tshark_ofp_output, 'r')
1538 main.log.info("Tshark OFP Vendor output: ")
1539 for line in ofp_file:
1540 tshark_ofp_result_list.append(line)
andrewonlabe5bcef92014-11-06 17:53:20 -05001541 main.log.info(line)
andrewonlab58f7d702014-11-07 13:21:19 -05001542 ofp_file.close()
andrewonlab16ce4852014-10-30 13:41:09 -04001543
andrewonlab58f7d702014-11-07 13:21:19 -05001544 tcp_file = open(tshark_tcp_output, 'r')
1545 main.log.info("Tshark TCP 74 output: ")
1546 for line in tcp_file:
1547 tshark_tcp_result_list.append(line)
andrewonlabe5bcef92014-11-06 17:53:20 -05001548 main.log.info(line)
andrewonlab58f7d702014-11-07 13:21:19 -05001549 tcp_file.close()
andrewonlab53b641c2014-10-31 19:44:44 -04001550
andrewonlab16ce4852014-10-30 13:41:09 -04001551 json_obj_1 = json.loads(json_str_topology_metrics_1)
1552 json_obj_2 = json.loads(json_str_topology_metrics_2)
1553 json_obj_3 = json.loads(json_str_topology_metrics_3)
1554
1555 graph_timestamp_1 = \
1556 json_obj_1[graphTimestamp]['value']
1557 graph_timestamp_2 = \
1558 json_obj_2[graphTimestamp]['value']
1559 graph_timestamp_3 = \
1560 json_obj_3[graphTimestamp]['value']
1561
andrewonlabe5bcef92014-11-06 17:53:20 -05001562 graph_lat_1 = int(graph_timestamp_1) - int(t0_system)
1563 graph_lat_2 = int(graph_timestamp_2) - int(t0_system)
1564 graph_lat_3 = int(graph_timestamp_3) - int(t0_system)
andrewonlab16ce4852014-10-30 13:41:09 -04001565
andrewonlabe5bcef92014-11-06 17:53:20 -05001566 avg_graph_lat = \
1567 (int(graph_lat_1) +\
1568 int(graph_lat_2) +\
1569 int(graph_lat_3)) / 3
1570
1571 if avg_graph_lat > sw_disc_threshold_min \
1572 and avg_graph_lat < sw_disc_threshold_max:
1573 sw_discovery_lat_list.append(
1574 avg_graph_lat)
1575 else:
1576 main.log.info("100 Switch discovery latency "+
1577 "exceeded the threshold.")
1578
1579 #END ITERATION FOR LOOP
andrewonlab16ce4852014-10-30 13:41:09 -04001580
andrewonlabe5bcef92014-11-06 17:53:20 -05001581 sw_lat_min = min(sw_discovery_lat_list)
1582 sw_lat_max = max(sw_discovery_lat_list)
1583 sw_lat_avg = sum(sw_discovery_lat_list) /\
1584 len(sw_discovery_lat_list)
andrewonlab16ce4852014-10-30 13:41:09 -04001585
andrewonlabf9828f02014-11-10 14:50:27 -05001586 main.log.report("100 Switch discovery lat "+\
1587 "Min: "+str(sw_lat_min)+" ms"+\
1588 "Max: "+str(sw_lat_max)+" ms"+\
1589 "Avg: "+str(sw_lat_avg)+" ms")
andrewonlab16ce4852014-10-30 13:41:09 -04001590
andrewonlabb54b85b2014-10-28 18:43:57 -04001591