blob: b46fb7615c4045f0d3e8eb96a626bcb7dd5dca87 [file] [log] [blame]
andrewonlab2a6c9342014-10-16 13:40:15 -04001#TopoPerfNext
2#
3#Topology Performance test for ONOS-next
4#
5#andrew@onlab.us
6
7import time
8import sys
9import os
10import re
11
12class TopoPerfNext:
13 def __init__(self):
14 self.default = ''
15
16 def CASE1(self, main):
17 '''
18 ONOS startup sequence
19 '''
andrewonlabe9fb6722014-10-24 12:20:35 -040020 import time
21
andrewonlab2a6c9342014-10-16 13:40:15 -040022 cell_name = main.params['ENV']['cellName']
23
24 git_pull = main.params['GIT']['autoPull']
25 checkout_branch = main.params['GIT']['checkout']
26
27 ONOS1_ip = main.params['CTRL']['ip1']
andrewonlabba44bcf2014-10-16 16:54:41 -040028 ONOS2_ip = main.params['CTRL']['ip2']
29 ONOS3_ip = main.params['CTRL']['ip3']
andrewonlab2a6c9342014-10-16 13:40:15 -040030 MN1_ip = main.params['MN']['ip1']
31 BENCH_ip = main.params['BENCH']['ip']
32
33 main.case("Setting up test environment")
34
35 main.step("Creating cell file")
36 cell_file_result = main.ONOSbench.create_cell_file(
andrewonlabe6745342014-10-17 14:29:13 -040037 BENCH_ip, cell_name, MN1_ip, "onos-core",
andrewonlabba44bcf2014-10-16 16:54:41 -040038 ONOS1_ip, ONOS2_ip, ONOS3_ip)
andrewonlab2a6c9342014-10-16 13:40:15 -040039
40 main.step("Applying cell file to environment")
41 cell_apply_result = main.ONOSbench.set_cell(cell_name)
42 verify_cell_result = main.ONOSbench.verify_cell()
43
44 main.step("Git checkout and pull "+checkout_branch)
45 if git_pull == 'on':
46 checkout_result = \
47 main.ONOSbench.git_checkout(checkout_branch)
48 pull_result = main.ONOSbench.git_pull()
49 else:
50 checkout_result = main.TRUE
51 pull_result = main.TRUE
52 main.log.info("Skipped git checkout and pull")
53
54 main.step("Using mvn clean & install")
andrewonlab8d29f122014-10-22 17:15:04 -040055 #mvn_result = main.ONOSbench.clean_install()
56 mvn_result = main.TRUE
andrewonlab2a6c9342014-10-16 13:40:15 -040057
58 main.step("Creating ONOS package")
59 package_result = main.ONOSbench.onos_package()
60
61 main.step("Installing ONOS package")
andrewonlabe9fb6722014-10-24 12:20:35 -040062 install1_result = main.ONOSbench.onos_install(node=ONOS1_ip)
63 install2_result = main.ONOSbench.onos_install(node=ONOS2_ip)
64 install3_result = main.ONOSbench.onos_install(node=ONOS3_ip)
andrewonlab2a6c9342014-10-16 13:40:15 -040065
andrewonlabe9fb6722014-10-24 12:20:35 -040066 #NOTE: This step may be unnecessary
67 #main.step("Starting ONOS service")
68 #start_result = main.ONOSbench.onos_start(ONOS1_ip)
andrewonlab2a6c9342014-10-16 13:40:15 -040069
andrewonlab867212a2014-10-22 20:13:38 -040070 main.step("Set cell for ONOS cli env")
71 main.ONOS1cli.set_cell(cell_name)
72 main.ONOS2cli.set_cell(cell_name)
73 main.ONOS3cli.set_cell(cell_name)
74
andrewonlabe9fb6722014-10-24 12:20:35 -040075 time.sleep(10)
76
andrewonlab867212a2014-10-22 20:13:38 -040077 main.step("Start onos cli")
andrewonlabe9fb6722014-10-24 12:20:35 -040078 cli1 = main.ONOS1cli.start_onos_cli(ONOS1_ip)
79 cli2 = main.ONOS2cli.start_onos_cli(ONOS2_ip)
80 cli3 = main.ONOS3cli.start_onos_cli(ONOS3_ip)
81
andrewonlab867212a2014-10-22 20:13:38 -040082 main.step("Enable metrics feature")
83 main.ONOS1cli.feature_install("onos-app-metrics-topology")
84 main.ONOS2cli.feature_install("onos-app-metrics-topology")
85 main.ONOS3cli.feature_install("onos-app-metrics-topology")
86
andrewonlab2a6c9342014-10-16 13:40:15 -040087 utilities.assert_equals(expect=main.TRUE,
88 actual= cell_file_result and cell_apply_result and\
89 verify_cell_result and checkout_result and\
90 pull_result and mvn_result and\
andrewonlabe9fb6722014-10-24 12:20:35 -040091 install1_result and install2_result and\
92 install3_result,
andrewonlab8d29f122014-10-22 17:15:04 -040093 onpass="ONOS started successfully",
94 onfail="Failed to start ONOS")
andrewonlab2a6c9342014-10-16 13:40:15 -040095
andrewonlabba44bcf2014-10-16 16:54:41 -040096 def CASE2(self, main):
97 '''
98 Assign s1 to ONOS1 and measure latency
andrewonlab3a7c3c72014-10-24 17:21:03 -040099
100 There are 4 levels of latency measurements to this test:
101 1) End-to-end measurement: Complete end-to-end measurement
102 from TCP (SYN/ACK) handshake to Graph change
103 2) OFP-to-graph measurement: 'ONOS processing' snippet of
104 measurement from OFP Vendor message to Graph change
105 3) OFP-to-device measurement: 'ONOS processing without
106 graph change' snippet of measurement from OFP vendor
107 message to Device change timestamp
108 4) T0-to-device measurement: Measurement that includes
109 the switch handshake to devices timestamp without
110 the graph view change. (TCP handshake -> Device
111 change)
andrewonlabba44bcf2014-10-16 16:54:41 -0400112 '''
113 import time
andrewonlabe6745342014-10-17 14:29:13 -0400114 import subprocess
115 import json
116 import requests
117 import os
andrewonlabba44bcf2014-10-16 16:54:41 -0400118
119 ONOS1_ip = main.params['CTRL']['ip1']
120 ONOS2_ip = main.params['CTRL']['ip2']
121 ONOS3_ip = main.params['CTRL']['ip3']
andrewonlabe6745342014-10-17 14:29:13 -0400122 ONOS_user = main.params['CTRL']['user']
123
andrewonlabba44bcf2014-10-16 16:54:41 -0400124 default_sw_port = main.params['CTRL']['port1']
125
126 #Number of iterations of case
127 num_iter = main.params['TEST']['numIter']
128
andrewonlab226024e2014-10-24 16:01:32 -0400129 #Timestamp 'keys' for json metrics output.
130 #These are subject to change, hence moved into params
131 deviceTimestamp = main.params['JSON']['deviceTimestamp']
132 graphTimestamp = main.params['JSON']['graphTimestamp']
133
andrewonlabe5bcef92014-11-06 17:53:20 -0500134 #Threshold for the test
135 threshold_str = main.params['TEST']['singleSwThreshold']
136 threshold_obj = threshold_str.split(",")
137 threshold_min = int(threshold_obj[0])
138 threshold_max = int(threshold_obj[1])
139
andrewonlab226024e2014-10-24 16:01:32 -0400140 #List of switch add latency collected from
141 #all iterations
142 latency_end_to_end_list = []
143 latency_ofp_to_graph_list = []
144 latency_ofp_to_device_list = []
145 latency_t0_to_device_list = []
146
andrewonlabba44bcf2014-10-16 16:54:41 -0400147 #Directory/file to store tshark results
148 tshark_of_output = "/tmp/tshark_of_topo.txt"
149 tshark_tcp_output = "/tmp/tshark_tcp_topo.txt"
150
151 #String to grep in tshark output
152 tshark_tcp_string = "TCP 74 "+default_sw_port
153 tshark_of_string = "OFP 86 Vendor"
andrewonlabe6745342014-10-17 14:29:13 -0400154
155 #Initialize assertion to TRUE
156 assertion = main.TRUE
157
andrewonlabba44bcf2014-10-16 16:54:41 -0400158 main.log.report("Latency of adding one switch")
159
160 for i in range(0, int(num_iter)):
161 main.log.info("Starting tshark capture")
162
163 #* TCP [ACK, SYN] is used as t0_a, the
164 # very first "exchange" between ONOS and
165 # the switch for end-to-end measurement
166 #* OFP [Stats Reply] is used for t0_b
167 # the very last OFP message between ONOS
168 # and the switch for ONOS measurement
169 main.ONOS1.tshark_grep(tshark_tcp_string,
170 tshark_tcp_output)
171 main.ONOS1.tshark_grep(tshark_of_string,
172 tshark_of_output)
173
174 #Wait and ensure tshark is started and
175 #capturing
176 time.sleep(10)
177
178 main.log.info("Assigning s1 to controller")
179
180 main.Mininet1.assign_sw_controller(sw="1",
181 ip1=ONOS1_ip, port1=default_sw_port)
182
183 #Wait and ensure switch is assigned
184 #before stopping tshark
andrewonlab867212a2014-10-22 20:13:38 -0400185 time.sleep(30)
andrewonlab226024e2014-10-24 16:01:32 -0400186
187 main.log.info("Stopping all Tshark processes")
andrewonlabba44bcf2014-10-16 16:54:41 -0400188 main.ONOS1.stop_tshark()
189
andrewonlabe6745342014-10-17 14:29:13 -0400190 #tshark output is saved in ONOS. Use subprocess
191 #to copy over files to TestON for parsing
192 main.log.info("Copying over tshark files")
193
194 #TCP CAPTURE ****
andrewonlab8d29f122014-10-22 17:15:04 -0400195 #Copy the tshark output from ONOS machine to
196 #TestON machine in tshark_tcp_output directory>file
197 os.system("scp "+ONOS_user+"@"+ONOS1_ip+":"+
198 tshark_tcp_output+" /tmp/")
199 tcp_file = open(tshark_tcp_output, 'r')
200 temp_text = tcp_file.readline()
andrewonlabe6745342014-10-17 14:29:13 -0400201 temp_text = temp_text.split(" ")
andrewonlabba44bcf2014-10-16 16:54:41 -0400202
andrewonlabe6745342014-10-17 14:29:13 -0400203 main.log.info("Object read in from TCP capture: "+
204 str(temp_text))
andrewonlab867212a2014-10-22 20:13:38 -0400205 if len(temp_text) > 1:
andrewonlab3a7c3c72014-10-24 17:21:03 -0400206 t0_tcp = float(temp_text[1])*1000.0
andrewonlabe6745342014-10-17 14:29:13 -0400207 else:
208 main.log.error("Tshark output file for TCP"+
209 " returned unexpected results")
210 t0_tcp = 0
211 assertion = main.FALSE
andrewonlab8d29f122014-10-22 17:15:04 -0400212
213 tcp_file.close()
andrewonlabe6745342014-10-17 14:29:13 -0400214 #****************
andrewonlabba44bcf2014-10-16 16:54:41 -0400215
andrewonlabe6745342014-10-17 14:29:13 -0400216 #OF CAPTURE ****
andrewonlab8d29f122014-10-22 17:15:04 -0400217 os.system("scp "+ONOS_user+"@"+ONOS1_ip+":"+
218 tshark_of_output+" /tmp/")
219 of_file = open(tshark_of_output, 'r')
220
221 line_ofp = ""
andrewonlab226024e2014-10-24 16:01:32 -0400222 #Read until last line of file
andrewonlabe6745342014-10-17 14:29:13 -0400223 while True:
andrewonlab8d29f122014-10-22 17:15:04 -0400224 temp_text = of_file.readline()
225 if temp_text !='':
andrewonlabe6745342014-10-17 14:29:13 -0400226 line_ofp = temp_text
227 else:
228 break
229 obj = line_ofp.split(" ")
230
231 main.log.info("Object read in from OFP capture: "+
232 str(line_ofp))
233
andrewonlab867212a2014-10-22 20:13:38 -0400234 if len(line_ofp) > 1:
andrewonlab3a7c3c72014-10-24 17:21:03 -0400235 t0_ofp = float(obj[1])*1000.0
andrewonlabe6745342014-10-17 14:29:13 -0400236 else:
237 main.log.error("Tshark output file for OFP"+
238 " returned unexpected results")
239 t0_ofp = 0
240 assertion = main.FALSE
andrewonlab8d29f122014-10-22 17:15:04 -0400241
242 of_file.close()
andrewonlabe6745342014-10-17 14:29:13 -0400243 #****************
244
andrewonlab867212a2014-10-22 20:13:38 -0400245 json_str_1 = main.ONOS1cli.topology_events_metrics()
246 json_str_2 = main.ONOS2cli.topology_events_metrics()
247 json_str_3 = main.ONOS3cli.topology_events_metrics()
andrewonlab867212a2014-10-22 20:13:38 -0400248
249 json_obj_1 = json.loads(json_str_1)
250 json_obj_2 = json.loads(json_str_2)
251 json_obj_3 = json.loads(json_str_3)
252
andrewonlab226024e2014-10-24 16:01:32 -0400253 #Obtain graph timestamp. This timestsamp captures
254 #the epoch time at which the topology graph was updated.
255 graph_timestamp_1 = \
256 json_obj_1[graphTimestamp]['value']
257 graph_timestamp_2 = \
258 json_obj_2[graphTimestamp]['value']
259 graph_timestamp_3 = \
260 json_obj_3[graphTimestamp]['value']
andrewonlab867212a2014-10-22 20:13:38 -0400261
andrewonlab226024e2014-10-24 16:01:32 -0400262 #Obtain device timestamp. This timestamp captures
263 #the epoch time at which the device event happened
264 device_timestamp_1 = \
265 json_obj_1[deviceTimestamp]['value']
266 device_timestamp_2 = \
267 json_obj_2[deviceTimestamp]['value']
268 device_timestamp_3 = \
269 json_obj_3[deviceTimestamp]['value']
andrewonlabe9fb6722014-10-24 12:20:35 -0400270
andrewonlab226024e2014-10-24 16:01:32 -0400271 #t0 to device processing latency
272 delta_device_1 = int(device_timestamp_1) - int(t0_tcp)
273 delta_device_2 = int(device_timestamp_2) - int(t0_tcp)
274 delta_device_3 = int(device_timestamp_3) - int(t0_tcp)
275
276 #Get average of delta from all instances
277 avg_delta_device = \
278 (int(delta_device_1)+\
279 int(delta_device_2)+\
280 int(delta_device_3)) / 3
andrewonlabba44bcf2014-10-16 16:54:41 -0400281
andrewonlab226024e2014-10-24 16:01:32 -0400282 #Ensure avg delta meets the threshold before appending
283 if avg_delta_device > 0.0 and avg_delta_device < 10000:
284 latency_t0_to_device_list.append(avg_delta_device)
andrewonlabee4efeb2014-10-24 16:44:51 -0400285 else:
andrewonlab09d973e2014-10-24 18:56:58 -0400286 main.log.info("Results for t0-to-device ignored"+\
287 "due to excess in threshold")
andrewonlabee4efeb2014-10-24 16:44:51 -0400288
andrewonlab226024e2014-10-24 16:01:32 -0400289 #t0 to graph processing latency (end-to-end)
290 delta_graph_1 = int(graph_timestamp_1) - int(t0_tcp)
291 delta_graph_2 = int(graph_timestamp_2) - int(t0_tcp)
292 delta_graph_3 = int(graph_timestamp_3) - int(t0_tcp)
293
294 #Get average of delta from all instances
295 avg_delta_graph = \
296 (int(delta_graph_1)+\
297 int(delta_graph_2)+\
298 int(delta_graph_3)) / 3
299
andrewonlab226024e2014-10-24 16:01:32 -0400300 #Ensure avg delta meets the threshold before appending
301 if avg_delta_graph > 0.0 and avg_delta_graph < 10000:
andrewonlab09d973e2014-10-24 18:56:58 -0400302 latency_end_to_end_list.append(avg_delta_graph)
andrewonlabee4efeb2014-10-24 16:44:51 -0400303 else:
andrewonlab09d973e2014-10-24 18:56:58 -0400304 main.log.info("Results for end-to-end ignored"+\
305 "due to excess in threshold")
andrewonlab226024e2014-10-24 16:01:32 -0400306
307 #ofp to graph processing latency (ONOS processing)
308 delta_ofp_graph_1 = int(graph_timestamp_1) - int(t0_ofp)
309 delta_ofp_graph_2 = int(graph_timestamp_2) - int(t0_ofp)
310 delta_ofp_graph_3 = int(graph_timestamp_3) - int(t0_ofp)
311
312 avg_delta_ofp_graph = \
313 (int(delta_ofp_graph_1)+\
314 int(delta_ofp_graph_2)+\
315 int(delta_ofp_graph_3)) / 3
316
andrewonlabe5bcef92014-11-06 17:53:20 -0500317 if avg_delta_ofp_graph > threshold_min \
318 and avg_delta_ofp_graph < threshold_max:
andrewonlab226024e2014-10-24 16:01:32 -0400319 latency_ofp_to_graph_list.append(avg_delta_ofp_graph)
andrewonlabee4efeb2014-10-24 16:44:51 -0400320 else:
andrewonlab09d973e2014-10-24 18:56:58 -0400321 main.log.info("Results for ofp-to-graph "+\
322 "ignored due to excess in threshold")
andrewonlabee4efeb2014-10-24 16:44:51 -0400323
andrewonlab226024e2014-10-24 16:01:32 -0400324 #ofp to device processing latency (ONOS processing)
andrewonlabee4efeb2014-10-24 16:44:51 -0400325 delta_ofp_device_1 = float(device_timestamp_1) - float(t0_ofp)
326 delta_ofp_device_2 = float(device_timestamp_2) - float(t0_ofp)
327 delta_ofp_device_3 = float(device_timestamp_3) - float(t0_ofp)
andrewonlab226024e2014-10-24 16:01:32 -0400328
329 avg_delta_ofp_device = \
andrewonlabee4efeb2014-10-24 16:44:51 -0400330 (float(delta_ofp_device_1)+\
331 float(delta_ofp_device_2)+\
332 float(delta_ofp_device_3)) / 3.0
andrewonlab226024e2014-10-24 16:01:32 -0400333
andrewonlabf47993a2014-10-24 17:56:01 -0400334 #NOTE: ofp - delta measurements are occasionally negative
335 # due to system time misalignment.
andrewonlabf47993a2014-10-24 17:56:01 -0400336 latency_ofp_to_device_list.append(avg_delta_ofp_device)
andrewonlabba44bcf2014-10-16 16:54:41 -0400337
andrewonlabe6745342014-10-17 14:29:13 -0400338 #TODO:
339 #Fetch logs upon threshold excess
andrewonlabba44bcf2014-10-16 16:54:41 -0400340
andrewonlab226024e2014-10-24 16:01:32 -0400341 main.log.info("ONOS1 delta end-to-end: "+
andrewonlab09d973e2014-10-24 18:56:58 -0400342 str(delta_graph_1) + " ms")
andrewonlab226024e2014-10-24 16:01:32 -0400343 main.log.info("ONOS2 delta end-to-end: "+
andrewonlab09d973e2014-10-24 18:56:58 -0400344 str(delta_graph_2) + " ms")
345 main.log.info("ONOS3 delta end-to-end: "+
346 str(delta_graph_3) + " ms")
andrewonlabba44bcf2014-10-16 16:54:41 -0400347
andrewonlab226024e2014-10-24 16:01:32 -0400348 main.log.info("ONOS1 delta OFP - graph: "+
andrewonlab09d973e2014-10-24 18:56:58 -0400349 str(delta_ofp_graph_1) + " ms")
andrewonlab226024e2014-10-24 16:01:32 -0400350 main.log.info("ONOS2 delta OFP - graph: "+
andrewonlab09d973e2014-10-24 18:56:58 -0400351 str(delta_ofp_graph_2) + " ms")
andrewonlab226024e2014-10-24 16:01:32 -0400352 main.log.info("ONOS3 delta OFP - graph: "+
andrewonlab09d973e2014-10-24 18:56:58 -0400353 str(delta_ofp_graph_3) + " ms")
andrewonlabe6745342014-10-17 14:29:13 -0400354
andrewonlab226024e2014-10-24 16:01:32 -0400355 main.log.info("ONOS1 delta device - t0: "+
andrewonlab09d973e2014-10-24 18:56:58 -0400356 str(delta_device_1) + " ms")
andrewonlab226024e2014-10-24 16:01:32 -0400357 main.log.info("ONOS2 delta device - t0: "+
andrewonlab09d973e2014-10-24 18:56:58 -0400358 str(delta_device_2) + " ms")
andrewonlab226024e2014-10-24 16:01:32 -0400359 main.log.info("ONOS3 delta device - t0: "+
andrewonlab09d973e2014-10-24 18:56:58 -0400360 str(delta_device_3) + " ms")
andrewonlab226024e2014-10-24 16:01:32 -0400361
andrewonlab8790abb2014-11-06 13:51:54 -0500362 #main.log.info("ONOS1 delta OFP - device: "+
363 # str(delta_ofp_device_1) + " ms")
364 #main.log.info("ONOS2 delta OFP - device: "+
365 # str(delta_ofp_device_2) + " ms")
366 #main.log.info("ONOS3 delta OFP - device: "+
367 # str(delta_ofp_device_3) + " ms")
andrewonlab226024e2014-10-24 16:01:32 -0400368
andrewonlab8d29f122014-10-22 17:15:04 -0400369 main.step("Remove switch from controller")
370 main.Mininet1.delete_sw_controller("s1")
andrewonlabba44bcf2014-10-16 16:54:41 -0400371
andrewonlab8d29f122014-10-22 17:15:04 -0400372 time.sleep(5)
andrewonlabba44bcf2014-10-16 16:54:41 -0400373
andrewonlab09d973e2014-10-24 18:56:58 -0400374 #END of for loop iteration
andrewonlabf47993a2014-10-24 17:56:01 -0400375
andrewonlabee4efeb2014-10-24 16:44:51 -0400376 #If there is at least 1 element in each list,
andrewonlabc15c9582014-10-24 16:35:52 -0400377 #pass the test case
378 if len(latency_end_to_end_list) > 0 and\
379 len(latency_ofp_to_graph_list) > 0 and\
380 len(latency_ofp_to_device_list) > 0 and\
381 len(latency_t0_to_device_list) > 0:
382 assertion = main.TRUE
andrewonlabf47993a2014-10-24 17:56:01 -0400383 elif len(latency_end_to_end_list) == 0:
384 #The appending of 0 here is to prevent
385 #the min,max,sum functions from failing
386 #below
387 latency_end_to_end_list.append(0)
388 assertion = main.FALSE
389 elif len(latency_ofp_to_graph_list) == 0:
390 latency_ofp_to_graph_list.append(0)
391 assertion = main.FALSE
392 elif len(latency_ofp_to_device_list) == 0:
393 latency_ofp_to_device_list.append(0)
394 assertion = main.FALSE
395 elif len(latency_t0_to_device_list) == 0:
396 latency_t0_to_device_list.append(0)
397 assertion = main.FALSE
andrewonlabc15c9582014-10-24 16:35:52 -0400398
399 #Calculate min, max, avg of latency lists
400 latency_end_to_end_max = \
andrewonlabee4efeb2014-10-24 16:44:51 -0400401 int(max(latency_end_to_end_list))
andrewonlabc15c9582014-10-24 16:35:52 -0400402 latency_end_to_end_min = \
andrewonlabee4efeb2014-10-24 16:44:51 -0400403 int(min(latency_end_to_end_list))
andrewonlabc15c9582014-10-24 16:35:52 -0400404 latency_end_to_end_avg = \
andrewonlabc90667c2014-10-24 16:48:28 -0400405 (int(sum(latency_end_to_end_list)) / \
andrewonlabc15c9582014-10-24 16:35:52 -0400406 len(latency_end_to_end_list))
407
408 latency_ofp_to_graph_max = \
andrewonlabee4efeb2014-10-24 16:44:51 -0400409 int(max(latency_ofp_to_graph_list))
andrewonlabc15c9582014-10-24 16:35:52 -0400410 latency_ofp_to_graph_min = \
andrewonlabee4efeb2014-10-24 16:44:51 -0400411 int(min(latency_ofp_to_graph_list))
andrewonlabc15c9582014-10-24 16:35:52 -0400412 latency_ofp_to_graph_avg = \
andrewonlabee4efeb2014-10-24 16:44:51 -0400413 (int(sum(latency_ofp_to_graph_list)) / \
andrewonlabc15c9582014-10-24 16:35:52 -0400414 len(latency_ofp_to_graph_list))
415
416 latency_ofp_to_device_max = \
andrewonlabee4efeb2014-10-24 16:44:51 -0400417 int(max(latency_ofp_to_device_list))
andrewonlabc15c9582014-10-24 16:35:52 -0400418 latency_ofp_to_device_min = \
andrewonlabee4efeb2014-10-24 16:44:51 -0400419 int(min(latency_ofp_to_device_list))
andrewonlabc15c9582014-10-24 16:35:52 -0400420 latency_ofp_to_device_avg = \
andrewonlabee4efeb2014-10-24 16:44:51 -0400421 (int(sum(latency_ofp_to_device_list)) / \
andrewonlabc15c9582014-10-24 16:35:52 -0400422 len(latency_ofp_to_device_list))
423
424 latency_t0_to_device_max = \
andrewonlabee4efeb2014-10-24 16:44:51 -0400425 float(max(latency_t0_to_device_list))
andrewonlabc15c9582014-10-24 16:35:52 -0400426 latency_t0_to_device_min = \
andrewonlabee4efeb2014-10-24 16:44:51 -0400427 float(min(latency_t0_to_device_list))
andrewonlabc15c9582014-10-24 16:35:52 -0400428 latency_t0_to_device_avg = \
andrewonlabee4efeb2014-10-24 16:44:51 -0400429 (float(sum(latency_t0_to_device_list)) / \
andrewonlabc15c9582014-10-24 16:35:52 -0400430 len(latency_ofp_to_device_list))
431
432 main.log.report("Switch add - End-to-end latency: \n"+\
433 "Min: "+str(latency_end_to_end_min)+"\n"+\
434 "Max: "+str(latency_end_to_end_max)+"\n"+\
435 "Avg: "+str(latency_end_to_end_avg))
436 main.log.report("Switch add - OFP-to-Graph latency: \n"+\
437 "Min: "+str(latency_ofp_to_graph_min)+"\n"+\
438 "Max: "+str(latency_ofp_to_graph_max)+"\n"+\
439 "Avg: "+str(latency_ofp_to_graph_avg))
andrewonlabc15c9582014-10-24 16:35:52 -0400440 main.log.report("Switch add - t0-to-Device latency: \n"+\
441 "Min: "+str(latency_t0_to_device_min)+"\n"+\
442 "Max: "+str(latency_t0_to_device_max)+"\n"+\
443 "Avg: "+str(latency_t0_to_device_avg))
andrewonlab226024e2014-10-24 16:01:32 -0400444
andrewonlab8d29f122014-10-22 17:15:04 -0400445 utilities.assert_equals(expect=main.TRUE, actual=assertion,
446 onpass="Switch latency test successful",
447 onfail="Switch latency test failed")
andrewonlabba44bcf2014-10-16 16:54:41 -0400448
andrewonlab8d29f122014-10-22 17:15:04 -0400449 def CASE3(self, main):
450 '''
451 Bring port up / down and measure latency.
452 Port enable / disable is simulated by ifconfig up / down
andrewonlab393531a2014-10-27 18:36:26 -0400453
454 In ONOS-next, we must ensure that the port we are
455 manipulating is connected to another switch with a valid
456 connection. Otherwise, graph view will not be updated.
andrewonlab8d29f122014-10-22 17:15:04 -0400457 '''
458 import time
459 import subprocess
460 import os
461 import requests
462 import json
andrewonlab2a6c9342014-10-16 13:40:15 -0400463
andrewonlab8d29f122014-10-22 17:15:04 -0400464 ONOS1_ip = main.params['CTRL']['ip1']
andrewonlab393531a2014-10-27 18:36:26 -0400465 ONOS2_ip = main.params['CTRL']['ip2']
466 ONOS3_ip = main.params['CTRL']['ip3']
andrewonlab8d29f122014-10-22 17:15:04 -0400467 ONOS_user = main.params['CTRL']['user']
andrewonlab8d29f122014-10-22 17:15:04 -0400468
andrewonlab393531a2014-10-27 18:36:26 -0400469 default_sw_port = main.params['CTRL']['port1']
andrewonlab8790abb2014-11-06 13:51:54 -0500470
471 assertion = main.TRUE
andrewonlab393531a2014-10-27 18:36:26 -0400472 #Number of iterations of case
473 num_iter = main.params['TEST']['numIter']
474
475 #Timestamp 'keys' for json metrics output.
476 #These are subject to change, hence moved into params
477 deviceTimestamp = main.params['JSON']['deviceTimestamp']
478 graphTimestamp = main.params['JSON']['graphTimestamp']
479
andrewonlabe5bcef92014-11-06 17:53:20 -0500480 #Threshold for this test case
481 up_threshold_str = main.params['TEST']['portUpThreshold']
482 down_threshold_str = main.params['TEST']['portDownThreshold']
483 up_threshold_obj = up_threshold_str.split(",")
484 down_threshold_obj = down_threshold_str.split(",")
485
486 up_threshold_min = int(up_threshold_obj[0])
487 up_threshold_max = int(up_threshold_obj[1])
488
489 down_threshold_min = int(down_threshold_obj[0])
490 down_threshold_max = int(down_threshold_obj[1])
491
andrewonlab393531a2014-10-27 18:36:26 -0400492 #NOTE: Some hardcoded variables you may need to configure
493 # besides the params
494
andrewonlab8d29f122014-10-22 17:15:04 -0400495 tshark_port_status = "OFP 130 Port Status"
496
497 tshark_port_up = "/tmp/tshark_port_up.txt"
498 tshark_port_down = "/tmp/tshark_port_down.txt"
andrewonlab393531a2014-10-27 18:36:26 -0400499 interface_config = "s1-eth1"
andrewonlab8d29f122014-10-22 17:15:04 -0400500
501 main.log.report("Port enable / disable latency")
502
andrewonlab393531a2014-10-27 18:36:26 -0400503 main.step("Assign switches s1 and s2 to controller 1")
andrewonlab8d29f122014-10-22 17:15:04 -0400504 main.Mininet1.assign_sw_controller(sw="1",ip1=ONOS1_ip,
505 port1=default_sw_port)
andrewonlab393531a2014-10-27 18:36:26 -0400506 main.Mininet1.assign_sw_controller(sw="2",ip1=ONOS1_ip,
507 port1=default_sw_port)
andrewonlab8d29f122014-10-22 17:15:04 -0400508
andrewonlab8790abb2014-11-06 13:51:54 -0500509 #Give enough time for metrics to propagate the
510 #assign controller event. Otherwise, these events may
511 #carry over to our measurements
512 time.sleep(10)
513
andrewonlab8d29f122014-10-22 17:15:04 -0400514 main.step("Verify switch is assigned correctly")
515 result_s1 = main.Mininet1.get_sw_controller(sw="s1")
andrewonlab393531a2014-10-27 18:36:26 -0400516 result_s2 = main.Mininet1.get_sw_controller(sw="s2")
517 if result_s1 == main.FALSE or result_s2 == main.FALSE:
andrewonlab8d29f122014-10-22 17:15:04 -0400518 main.log.info("Switch s1 was not assigned correctly")
519 assertion = main.FALSE
520 else:
521 main.log.info("Switch s1 was assigned correctly")
522
andrewonlab393531a2014-10-27 18:36:26 -0400523 port_up_device_to_ofp_list = []
524 port_up_graph_to_ofp_list = []
525 port_down_device_to_ofp_list = []
526 port_down_graph_to_ofp_list = []
527
andrewonlab8d29f122014-10-22 17:15:04 -0400528 for i in range(0, int(num_iter)):
529 main.step("Starting wireshark capture for port status down")
530 main.ONOS1.tshark_grep(tshark_port_status,
531 tshark_port_down)
532
533 time.sleep(10)
534
andrewonlab393531a2014-10-27 18:36:26 -0400535 #Disable interface that is connected to switch 2
536 main.step("Disable port: "+interface_config)
537 main.Mininet2.handle.sendline("sudo ifconfig "+
538 interface_config+" down")
andrewonlab8d29f122014-10-22 17:15:04 -0400539 main.Mininet2.handle.expect("\$")
andrewonlab8790abb2014-11-06 13:51:54 -0500540 time.sleep(10)
andrewonlab8d29f122014-10-22 17:15:04 -0400541
542 main.ONOS1.tshark_stop()
543 time.sleep(5)
544
545 #Copy tshark output file from ONOS to TestON instance
546 #/tmp directory
547 os.system("scp "+ONOS_user+"@"+ONOS1_ip+":"+
548 tshark_port_down+" /tmp/")
549
550 f_port_down = open(tshark_port_down, 'r')
andrewonlab393531a2014-10-27 18:36:26 -0400551 #Get first line of port down event from tshark
andrewonlab8d29f122014-10-22 17:15:04 -0400552 f_line = f_port_down.readline()
553 obj_down = f_line.split(" ")
554 if len(f_line) > 0:
andrewonlab393531a2014-10-27 18:36:26 -0400555 timestamp_begin_pt_down = int(float(obj_down[1]))*1000
556 main.log.info("Port down begin timestamp: "+
557 str(timestamp_begin_pt_down))
andrewonlab8d29f122014-10-22 17:15:04 -0400558 else:
559 main.log.info("Tshark output file returned unexpected"+
andrewonlab393531a2014-10-27 18:36:26 -0400560 " results: "+str(obj_down))
andrewonlab8d29f122014-10-22 17:15:04 -0400561 timestamp_begin_pt_down = 0
andrewonlab393531a2014-10-27 18:36:26 -0400562
563 f_port_down.close()
andrewonlab8d29f122014-10-22 17:15:04 -0400564
andrewonlab4e124482014-11-04 13:37:25 -0500565 main.log.info("TEST tshark obj: "+str(obj_down))
566
andrewonlab8d29f122014-10-22 17:15:04 -0400567 main.step("Obtain t1 by REST call")
andrewonlab393531a2014-10-27 18:36:26 -0400568 json_str_1 = main.ONOS1cli.topology_events_metrics()
569 json_str_2 = main.ONOS2cli.topology_events_metrics()
570 json_str_3 = main.ONOS3cli.topology_events_metrics()
andrewonlab8d29f122014-10-22 17:15:04 -0400571
andrewonlab4e124482014-11-04 13:37:25 -0500572 main.log.info("TEST json_str 1: "+str(json_str_1))
573
andrewonlab393531a2014-10-27 18:36:26 -0400574 json_obj_1 = json.loads(json_str_1)
575 json_obj_2 = json.loads(json_str_2)
576 json_obj_3 = json.loads(json_str_3)
andrewonlab8d29f122014-10-22 17:15:04 -0400577
andrewonlab393531a2014-10-27 18:36:26 -0400578 time.sleep(5)
579
580 #Obtain graph timestamp. This timestsamp captures
581 #the epoch time at which the topology graph was updated.
582 graph_timestamp_1 = \
583 json_obj_1[graphTimestamp]['value']
584 graph_timestamp_2 = \
585 json_obj_2[graphTimestamp]['value']
586 graph_timestamp_3 = \
587 json_obj_3[graphTimestamp]['value']
588
andrewonlab393531a2014-10-27 18:36:26 -0400589 #Obtain device timestamp. This timestamp captures
590 #the epoch time at which the device event happened
591 device_timestamp_1 = \
592 json_obj_1[deviceTimestamp]['value']
593 device_timestamp_2 = \
594 json_obj_2[deviceTimestamp]['value']
595 device_timestamp_3 = \
596 json_obj_3[deviceTimestamp]['value']
andrewonlab393531a2014-10-27 18:36:26 -0400597
598 #Get delta between graph event and OFP
599 pt_down_graph_to_ofp_1 = int(graph_timestamp_1) -\
600 int(timestamp_begin_pt_down)
601 pt_down_graph_to_ofp_2 = int(graph_timestamp_2) -\
602 int(timestamp_begin_pt_down)
603 pt_down_graph_to_ofp_3 = int(graph_timestamp_3) -\
604 int(timestamp_begin_pt_down)
605
606 #Get delta between device event and OFP
607 pt_down_device_to_ofp_1 = int(device_timestamp_1) -\
608 int(timestamp_begin_pt_down)
609 pt_down_device_to_ofp_2 = int(device_timestamp_2) -\
610 int(timestamp_begin_pt_down)
611 pt_down_device_to_ofp_3 = int(device_timestamp_3) -\
612 int(timestamp_begin_pt_down)
613
614 #Caluclate average across clusters
615 pt_down_graph_to_ofp_avg =\
616 (int(pt_down_graph_to_ofp_1) +
617 int(pt_down_graph_to_ofp_2) +
andrewonlab8790abb2014-11-06 13:51:54 -0500618 int(pt_down_graph_to_ofp_3)) / 3.0
andrewonlab393531a2014-10-27 18:36:26 -0400619 pt_down_device_to_ofp_avg = \
620 (int(pt_down_device_to_ofp_1) +
621 int(pt_down_device_to_ofp_2) +
andrewonlab8790abb2014-11-06 13:51:54 -0500622 int(pt_down_device_to_ofp_3)) / 3.0
andrewonlab393531a2014-10-27 18:36:26 -0400623
andrewonlab4e124482014-11-04 13:37:25 -0500624 if pt_down_graph_to_ofp_avg > 0.0 and \
andrewonlab393531a2014-10-27 18:36:26 -0400625 pt_down_graph_to_ofp_avg < 1000:
626 port_down_graph_to_ofp_list.append(
andrewonlababb11c32014-11-04 15:03:24 -0500627 pt_down_graph_to_ofp_avg)
628 main.log.info("Port down: graph to ofp avg: "+
629 str(pt_down_graph_to_ofp_avg) + " ms")
andrewonlab393531a2014-10-27 18:36:26 -0400630 else:
631 main.log.info("Average port down graph-to-ofp result" +
632 " exceeded the threshold: "+
633 str(pt_down_graph_to_ofp_avg))
634
andrewonlab3622beb2014-10-28 16:07:56 -0400635 if pt_down_device_to_ofp_avg > 0 and \
636 pt_down_device_to_ofp_avg < 1000:
637 port_down_device_to_ofp_list.append(
andrewonlababb11c32014-11-04 15:03:24 -0500638 pt_down_device_to_ofp_avg)
639 main.log.info("Port down: device to ofp avg: "+
640 str(pt_down_device_to_ofp_avg) + " ms")
andrewonlab3622beb2014-10-28 16:07:56 -0400641 else:
642 main.log.info("Average port down device-to-ofp result" +
643 " exceeded the threshold: "+
644 str(pt_down_device_to_ofp_avg))
645
andrewonlab8d29f122014-10-22 17:15:04 -0400646 #Port up events
647 main.step("Enable port and obtain timestamp")
648 main.step("Starting wireshark capture for port status up")
649 main.ONOS1.tshark_grep("OFP 130 Port Status", tshark_port_up)
andrewonlab8790abb2014-11-06 13:51:54 -0500650 time.sleep(5)
andrewonlab8d29f122014-10-22 17:15:04 -0400651
andrewonlab393531a2014-10-27 18:36:26 -0400652 main.Mininet2.handle.sendline("sudo ifconfig "+
653 interface_config+" up")
andrewonlab8d29f122014-10-22 17:15:04 -0400654 main.Mininet2.handle.expect("\$")
andrewonlab8790abb2014-11-06 13:51:54 -0500655 time.sleep(10)
656
657 main.ONOS1.tshark_stop()
andrewonlab8d29f122014-10-22 17:15:04 -0400658
659 os.system("scp "+ONOS_user+"@"+ONOS1_ip+":"+
660 tshark_port_up+" /tmp/")
661
662 f_port_up = open(tshark_port_up, 'r')
andrewonlab393531a2014-10-27 18:36:26 -0400663 f_line = f_port_up.readline()
andrewonlab8d29f122014-10-22 17:15:04 -0400664 obj_up = f_line.split(" ")
665 if len(f_line) > 0:
andrewonlab393531a2014-10-27 18:36:26 -0400666 timestamp_begin_pt_up = int(float(obj_up[1]))*1000
667 main.log.info("Port up begin timestamp: "+
668 str(timestamp_begin_pt_up))
andrewonlab8d29f122014-10-22 17:15:04 -0400669 else:
670 main.log.info("Tshark output file returned unexpected"+
671 " results.")
672 timestamp_begin_pt_up = 0
673
andrewonlab393531a2014-10-27 18:36:26 -0400674 f_port_up.close()
675
andrewonlab8d29f122014-10-22 17:15:04 -0400676 main.step("Obtain t1 by REST call")
andrewonlab393531a2014-10-27 18:36:26 -0400677 json_str_1 = main.ONOS1cli.topology_events_metrics()
678 json_str_2 = main.ONOS2cli.topology_events_metrics()
679 json_str_3 = main.ONOS3cli.topology_events_metrics()
andrewonlab8d29f122014-10-22 17:15:04 -0400680
andrewonlab393531a2014-10-27 18:36:26 -0400681 json_obj_1 = json.loads(json_str_1)
682 json_obj_2 = json.loads(json_str_2)
683 json_obj_3 = json.loads(json_str_3)
andrewonlab8d29f122014-10-22 17:15:04 -0400684
andrewonlab393531a2014-10-27 18:36:26 -0400685 #Obtain graph timestamp. This timestsamp captures
686 #the epoch time at which the topology graph was updated.
687 graph_timestamp_1 = \
688 json_obj_1[graphTimestamp]['value']
689 graph_timestamp_2 = \
690 json_obj_2[graphTimestamp]['value']
691 graph_timestamp_3 = \
692 json_obj_3[graphTimestamp]['value']
693
694 #Obtain device timestamp. This timestamp captures
695 #the epoch time at which the device event happened
696 device_timestamp_1 = \
697 json_obj_1[deviceTimestamp]['value']
698 device_timestamp_2 = \
699 json_obj_2[deviceTimestamp]['value']
700 device_timestamp_3 = \
701 json_obj_3[deviceTimestamp]['value']
702
703 #Get delta between graph event and OFP
704 pt_up_graph_to_ofp_1 = int(graph_timestamp_1) -\
andrewonlab8d29f122014-10-22 17:15:04 -0400705 int(timestamp_begin_pt_up)
andrewonlab393531a2014-10-27 18:36:26 -0400706 pt_up_graph_to_ofp_2 = int(graph_timestamp_2) -\
andrewonlab8d29f122014-10-22 17:15:04 -0400707 int(timestamp_begin_pt_up)
andrewonlab393531a2014-10-27 18:36:26 -0400708 pt_up_graph_to_ofp_3 = int(graph_timestamp_3) -\
709 int(timestamp_begin_pt_up)
710
711 #Get delta between device event and OFP
712 pt_up_device_to_ofp_1 = int(device_timestamp_1) -\
713 int(timestamp_begin_pt_up)
714 pt_up_device_to_ofp_2 = int(device_timestamp_2) -\
715 int(timestamp_begin_pt_up)
716 pt_up_device_to_ofp_3 = int(device_timestamp_3) -\
andrewonlab8d29f122014-10-22 17:15:04 -0400717 int(timestamp_begin_pt_up)
andrewonlab3622beb2014-10-28 16:07:56 -0400718
719 pt_up_graph_to_ofp_avg = \
720 (float(pt_up_graph_to_ofp_1) +
721 float(pt_up_graph_to_ofp_2) +
722 float(pt_up_graph_to_ofp_3)) / 3
723
724 pt_up_device_to_ofp_avg = \
725 (float(pt_up_device_to_ofp_1) +
726 float(pt_up_device_to_ofp_2) +
727 float(pt_up_device_to_ofp_3)) / 3
728
andrewonlabe5bcef92014-11-06 17:53:20 -0500729 if pt_up_graph_to_ofp_avg > up_threshold_min and \
730 pt_up_graph_to_ofp_avg < up_threshold_max:
andrewonlab3622beb2014-10-28 16:07:56 -0400731 port_up_graph_to_ofp_list.append(
732 pt_up_graph_to_ofp_avg)
andrewonlababb11c32014-11-04 15:03:24 -0500733 main.log.info("Port down: graph to ofp avg: "+
734 str(pt_up_graph_to_ofp_avg) + " ms")
andrewonlab3622beb2014-10-28 16:07:56 -0400735 else:
736 main.log.info("Average port up graph-to-ofp result"+
737 " exceeded the threshold: "+
738 str(pt_up_graph_to_ofp_avg))
739
andrewonlabe5bcef92014-11-06 17:53:20 -0500740 if pt_up_device_to_ofp_avg > up_threshold_min and \
741 pt_up_device_to_ofp_avg < up_threshold_max:
andrewonlab3622beb2014-10-28 16:07:56 -0400742 port_up_device_to_ofp_list.append(
743 pt_up_device_to_ofp_avg)
andrewonlababb11c32014-11-04 15:03:24 -0500744 main.log.info("Port up: device to ofp avg: "+
745 str(pt_up_device_to_ofp_avg) + " ms")
andrewonlab3622beb2014-10-28 16:07:56 -0400746 else:
andrewonlababb11c32014-11-04 15:03:24 -0500747 main.log.info("Average port up device-to-ofp result"+
andrewonlab3622beb2014-10-28 16:07:56 -0400748 " exceeded the threshold: "+
749 str(pt_up_device_to_ofp_avg))
andrewonlab8d29f122014-10-22 17:15:04 -0400750
andrewonlab3622beb2014-10-28 16:07:56 -0400751 #END ITERATION FOR LOOP
andrewonlab8790abb2014-11-06 13:51:54 -0500752
753 #Check all list for latency existence and set assertion
754 if (port_down_graph_to_ofp_list and port_down_device_to_ofp_list\
755 and port_up_graph_to_ofp_list and port_up_device_to_ofp_list):
756 assertion = main.TRUE
757
andrewonlababb11c32014-11-04 15:03:24 -0500758 #Calculate and report latency measurements
andrewonlab3622beb2014-10-28 16:07:56 -0400759 port_down_graph_to_ofp_min = min(port_down_graph_to_ofp_list)
760 port_down_graph_to_ofp_max = max(port_down_graph_to_ofp_list)
761 port_down_graph_to_ofp_avg = \
762 (sum(port_down_graph_to_ofp_list) /
763 len(port_down_graph_to_ofp_list))
764
andrewonlababb11c32014-11-04 15:03:24 -0500765 main.log.report("Port down graph-to-ofp Min: "+
andrewonlab8790abb2014-11-06 13:51:54 -0500766 str(port_down_graph_to_ofp_min)+" ms Max: "+
767 str(port_down_graph_to_ofp_max)+" ms Avg: "+
andrewonlababb11c32014-11-04 15:03:24 -0500768 str(port_down_graph_to_ofp_avg))
769
770 port_down_device_to_ofp_min = min(port_down_device_to_ofp_list)
771 port_down_device_to_ofp_max = max(port_down_device_to_ofp_list)
772 port_down_device_to_ofp_avg = \
773 (sum(port_down_device_to_ofp_list) /\
774 len(port_down_device_to_ofp_list))
775
776 main.log.report("Port down device-to-ofp Min: "+
andrewonlab8790abb2014-11-06 13:51:54 -0500777 str(port_down_device_to_ofp_min)+" ms Max: "+
778 str(port_down_device_to_ofp_max)+" ms Avg: "+
andrewonlababb11c32014-11-04 15:03:24 -0500779 str(port_down_device_to_ofp_avg))
780
781 port_up_graph_to_ofp_min = min(port_up_graph_to_ofp_list)
782 port_up_graph_to_ofp_max = max(port_up_graph_to_ofp_list)
783 port_up_graph_to_ofp_avg = \
784 (sum(port_up_graph_to_ofp_list) /\
785 len(port_up_graph_to_ofp_list))
andrewonlab8790abb2014-11-06 13:51:54 -0500786
787 main.log.report("Port up graph-to-ofp Min: "+
788 str(port_up_graph_to_ofp_min)+" ms Max: "+
789 str(port_up_graph_to_ofp_max)+" ms Avg: "+
790 str(port_up_graph_to_ofp_avg))
791
792 port_up_device_to_ofp_min = min(port_up_device_to_ofp_list)
793 port_up_device_to_ofp_max = max(port_up_device_to_ofp_list)
794 port_up_device_to_ofp_avg = \
795 (sum(port_up_device_to_ofp_list) /\
796 len(port_up_device_to_ofp_list))
797
798 main.log.report("Port up device-to-ofp Min: "+
799 str(port_up_device_to_ofp_min)+" ms Max: "+
800 str(port_up_device_to_ofp_max)+" ms Avg: "+
801 str(port_up_device_to_ofp_avg))
802
803 utilities.assert_equals(expect=main.TRUE, actual=assertion,
804 onpass="Port discovery latency calculation successful",
805 onfail="Port discovery test failed")
andrewonlababb11c32014-11-04 15:03:24 -0500806
andrewonlab3622beb2014-10-28 16:07:56 -0400807 def CASE4(self, main):
808 '''
809 Link down event using loss rate 100%
andrewonlab53b641c2014-10-31 19:44:44 -0400810
811 Important:
812 Use a simple 2 switch topology with 1 link between
813 the two switches. Ensure that mac addresses of the
814 switches are 1 / 2 respectively
andrewonlab3622beb2014-10-28 16:07:56 -0400815 '''
816 import time
817 import subprocess
818 import os
819 import requests
820 import json
821
822 ONOS1_ip = main.params['CTRL']['ip1']
823 ONOS2_ip = main.params['CTRL']['ip2']
824 ONOS3_ip = main.params['CTRL']['ip3']
825 ONOS_user = main.params['CTRL']['user']
826
827 default_sw_port = main.params['CTRL']['port1']
828
829 #Number of iterations of case
830 num_iter = main.params['TEST']['numIter']
831
832 #Timestamp 'keys' for json metrics output.
833 #These are subject to change, hence moved into params
834 deviceTimestamp = main.params['JSON']['deviceTimestamp']
835 linkTimestamp = main.params['JSON']['linkTimestamp']
andrewonlab53b641c2014-10-31 19:44:44 -0400836 graphTimestamp = main.params['JSON']['graphTimestamp']
837
andrewonlabe5bcef92014-11-06 17:53:20 -0500838 #Threshold for this test case
839 up_threshold_str = main.params['TEST']['linkUpThreshold']
840 down_threshold_str = main.params['TEST']['linkDownThreshold']
841
842 up_threshold_obj = up_threshold_str.split(",")
843 down_threshold_obj = down_threshold_str.split(",")
844
845 up_threshold_min = int(up_threshold_obj[0])
846 up_threshold_max = int(up_threshold_obj[1])
847
848 down_threshold_min = int(down_threshold_obj[0])
849 down_threshold_max = int(down_threshold_obj[1])
850
andrewonlab3622beb2014-10-28 16:07:56 -0400851 assertion = main.TRUE
852 #Link event timestamp to system time list
853 link_down_link_to_system_list = []
854 link_up_link_to_system_list = []
855 #Graph event timestamp to system time list
856 link_down_graph_to_system_list = []
857 link_up_graph_to_system_list = []
858
859 main.log.report("Add / remove link latency between "+
860 "two switches")
861
862 main.step("Assign all switches")
863 main.Mininet1.assign_sw_controller(sw="1",
864 ip1=ONOS1_ip, port1=default_sw_port)
865 main.Mininet1.assign_sw_controller(sw="2",
866 ip1=ONOS1_ip, port1=default_sw_port)
867
868 main.step("Verifying switch assignment")
869 result_s1 = main.Mininet1.get_sw_controller(sw="s1")
870 result_s2 = main.Mininet1.get_sw_controller(sw="s2")
andrewonlab3622beb2014-10-28 16:07:56 -0400871
872 #Allow time for events to finish before taking measurements
873 time.sleep(10)
874
andrewonlababb11c32014-11-04 15:03:24 -0500875 link_down1 = False
876 link_down2 = False
877 link_down3 = False
andrewonlab3622beb2014-10-28 16:07:56 -0400878 #Start iteration of link event test
879 for i in range(0, int(num_iter)):
880 main.step("Getting initial system time as t0")
andrewonlab8d29f122014-10-22 17:15:04 -0400881
andrewonlab3622beb2014-10-28 16:07:56 -0400882 timestamp_link_down_t0 = time.time() * 1000
883 #Link down is simulated by 100% loss rate using traffic
884 #control command
885 main.Mininet1.handle.sendline(
886 "sh tc qdisc add dev s1-eth1 root netem loss 100%")
887
andrewonlab53b641c2014-10-31 19:44:44 -0400888 #TODO: Iterate through 'links' command to verify that
andrewonlababb11c32014-11-04 15:03:24 -0500889 # link s1 -> s2 went down (loop timeout 30 seconds)
890 # on all 3 ONOS instances
andrewonlab53b641c2014-10-31 19:44:44 -0400891 main.log.info("Checking ONOS for link update")
892 loop_count = 0
andrewonlababb11c32014-11-04 15:03:24 -0500893 while( not (link_down1 and link_down2 and link_down3)\
894 and loop_count < 30 ):
895 json_str1 = main.ONOS1cli.links()
896 json_str2 = main.ONOS2cli.links()
897 json_str3 = main.ONOS3cli.links()
898
899 if not (json_str1 and json_str2 and json_str3):
900 main.log.error("CLI command returned error ")
andrewonlab53b641c2014-10-31 19:44:44 -0400901 break
902 else:
andrewonlababb11c32014-11-04 15:03:24 -0500903 json_obj1 = json.loads(json_str1)
904 json_obj2 = json.loads(json_str2)
905 json_obj3 = json.loads(json_str3)
906 for obj1 in json_obj1:
907 if '01' not in obj1['src']['device']:
908 link_down1 = True
andrewonlab53b641c2014-10-31 19:44:44 -0400909 main.log.report("Link down from "+
andrewonlababb11c32014-11-04 15:03:24 -0500910 "s1 -> s2 on ONOS1 detected")
911 for obj2 in json_obj2:
912 if '01' not in obj2['src']['device']:
913 link_down2 = True
914 main.log.report("Link down from "+
915 "s1 -> s2 on ONOS2 detected")
916 for obj3 in json_obj3:
917 if '01' not in obj3['src']['device']:
918 link_down3 = True
919 main.log.report("Link down from "+
920 "s1 -> s2 on ONOS3 detected")
921
andrewonlab53b641c2014-10-31 19:44:44 -0400922 loop_count += 1
andrewonlababb11c32014-11-04 15:03:24 -0500923 #If CLI doesn't like the continuous requests
924 #and exits in this loop, increase the sleep here.
925 #Consequently, while loop timeout will increase
andrewonlab53b641c2014-10-31 19:44:44 -0400926 time.sleep(1)
927
928 #Give time for metrics measurement to catch up
andrewonlababb11c32014-11-04 15:03:24 -0500929 #NOTE: May need to be configured more accurately
andrewonlab53b641c2014-10-31 19:44:44 -0400930 time.sleep(10)
andrewonlababb11c32014-11-04 15:03:24 -0500931 #If we exited the while loop and link down 1,2,3 are still
andrewonlab53b641c2014-10-31 19:44:44 -0400932 #false, then ONOS has failed to discover link down event
andrewonlababb11c32014-11-04 15:03:24 -0500933 if not (link_down1 and link_down2 and link_down3):
andrewonlab53b641c2014-10-31 19:44:44 -0400934 main.log.info("Link down discovery failed")
935
936 link_down_lat_graph1 = 0
937 link_down_lat_graph2 = 0
938 link_down_lat_graph3 = 0
939 link_down_lat_device1 = 0
940 link_down_lat_device2 = 0
941 link_down_lat_device3 = 0
942
943 assertion = main.FALSE
944 else:
945 json_topo_metrics_1 =\
946 main.ONOS1cli.topology_events_metrics()
947 json_topo_metrics_2 =\
948 main.ONOS2cli.topology_events_metrics()
949 json_topo_metrics_3 =\
950 main.ONOS3cli.topology_events_metrics()
951 json_topo_metrics_1 = json.loads(json_topo_metrics_1)
952 json_topo_metrics_2 = json.loads(json_topo_metrics_2)
953 json_topo_metrics_3 = json.loads(json_topo_metrics_3)
954
955 main.log.info("Obtaining graph and device timestamp")
956 graph_timestamp_1 = \
957 json_topo_metrics_1[graphTimestamp]['value']
958 graph_timestamp_2 = \
959 json_topo_metrics_2[graphTimestamp]['value']
960 graph_timestamp_3 = \
961 json_topo_metrics_3[graphTimestamp]['value']
962
963 link_timestamp_1 = \
964 json_topo_metrics_1[linkTimestamp]['value']
965 link_timestamp_2 = \
966 json_topo_metrics_2[linkTimestamp]['value']
967 link_timestamp_3 = \
968 json_topo_metrics_3[linkTimestamp]['value']
969
970 if graph_timestamp_1 and graph_timestamp_2 and\
971 graph_timestamp_3 and link_timestamp_1 and\
972 link_timestamp_2 and link_timestamp_3:
973 link_down_lat_graph1 = int(graph_timestamp_1) -\
974 timestamp_link_down_t0
975 link_down_lat_graph2 = int(graph_timestamp_2) -\
976 timestamp_link_down_t0
977 link_down_lat_graph3 = int(graph_timestamp_3) -\
978 timestamp_link_down_t0
979
980 link_down_lat_link1 = int(link_timestamp_1) -\
981 timestamp_link_down_t0
982 link_down_lat_link2 = int(link_timestamp_2) -\
983 timestamp_link_down_t0
984 link_down_lat_link3 = int(link_timestamp_3) -\
985 timestamp_link_down_t0
986 else:
987 main.log.error("There was an error calculating"+
988 " the delta for link down event")
989 link_down_lat_graph1 = 0
990 link_down_lat_graph2 = 0
991 link_down_lat_graph3 = 0
992
993 link_down_lat_device1 = 0
994 link_down_lat_device2 = 0
995 link_down_lat_device3 = 0
996
andrewonlab4e124482014-11-04 13:37:25 -0500997 main.log.report("Link down latency ONOS1 iteration "+
998 str(i)+" (end-to-end): "+
andrewonlababb11c32014-11-04 15:03:24 -0500999 str(link_down_lat_graph1)+" ms")
andrewonlab4e124482014-11-04 13:37:25 -05001000 main.log.report("Link down latency ONOS2 iteration "+
1001 str(i)+" (end-to-end): "+
andrewonlababb11c32014-11-04 15:03:24 -05001002 str(link_down_lat_graph2)+" ms")
andrewonlab4e124482014-11-04 13:37:25 -05001003 main.log.report("Link down latency ONOS3 iteration "+
1004 str(i)+" (end-to-end): "+
andrewonlababb11c32014-11-04 15:03:24 -05001005 str(link_down_lat_graph3)+" ms")
andrewonlab4e124482014-11-04 13:37:25 -05001006
1007 main.log.report("Link down latency ONOS1 iteration "+
1008 str(i)+" (link-event-to-system-timestamp): "+
andrewonlababb11c32014-11-04 15:03:24 -05001009 str(link_down_lat_link1)+" ms")
andrewonlab4e124482014-11-04 13:37:25 -05001010 main.log.report("Link down latency ONOS2 iteration "+
1011 str(i)+" (link-event-to-system-timestamp): "+
andrewonlababb11c32014-11-04 15:03:24 -05001012 str(link_down_lat_link2)+" ms")
andrewonlab4e124482014-11-04 13:37:25 -05001013 main.log.report("Link down latency ONOS3 iteration "+
1014 str(i)+" (link-event-to-system-timestamp): "+
1015 str(link_down_lat_link3))
1016
1017 #Calculate avg of node calculations
1018 link_down_lat_graph_avg =\
andrewonlababb11c32014-11-04 15:03:24 -05001019 (link_down_lat_graph1 +
1020 link_down_lat_graph2 +
1021 link_down_lat_graph3) / 3.0
andrewonlab4e124482014-11-04 13:37:25 -05001022 link_down_lat_link_avg =\
andrewonlababb11c32014-11-04 15:03:24 -05001023 (link_down_lat_link1 +
1024 link_down_lat_link2 +
1025 link_down_lat_link3) / 3.0
andrewonlab53b641c2014-10-31 19:44:44 -04001026
andrewonlab4e124482014-11-04 13:37:25 -05001027 #Set threshold and append latency to list
andrewonlabe5bcef92014-11-06 17:53:20 -05001028 if link_down_lat_graph_avg > down_threshold_min and\
1029 link_down_lat_graph_avg < down_threshold_max:
andrewonlab4e124482014-11-04 13:37:25 -05001030 link_down_graph_to_system_list.append(
1031 link_down_lat_graph_avg)
andrewonlab8790abb2014-11-06 13:51:54 -05001032 else:
1033 main.log.info("Link down latency exceeded threshold")
1034 main.log.info("Results for iteration "+str(i)+
1035 "have been omitted")
andrewonlabe5bcef92014-11-06 17:53:20 -05001036 if link_down_lat_link_avg > down_threshold_min and\
1037 link_down_lat_link_avg < down_threshold_max:
andrewonlab4e124482014-11-04 13:37:25 -05001038 link_down_link_to_system_list.append(
1039 link_down_lat_link_avg)
andrewonlab8790abb2014-11-06 13:51:54 -05001040 else:
1041 main.log.info("Link down latency exceeded threshold")
1042 main.log.info("Results for iteration "+str(i)+
1043 "have been omitted")
andrewonlab53b641c2014-10-31 19:44:44 -04001044
1045 #NOTE: To remove loss rate and measure latency:
1046 # 'sh tc qdisc del dev s1-eth1 root'
andrewonlababb11c32014-11-04 15:03:24 -05001047 timestamp_link_up_t0 = time.time() * 1000
andrewonlab53b641c2014-10-31 19:44:44 -04001048 main.Mininet1.handle.sendline("sh tc qdisc del dev "+
1049 "s1-eth1 root")
1050 main.Mininet1.handle.expect("mininet>")
andrewonlababb11c32014-11-04 15:03:24 -05001051
1052 main.log.info("Checking ONOS for link update")
1053
1054 link_down1 = True
1055 link_down2 = True
1056 link_down3 = True
1057 loop_count = 0
1058 while( (link_down1 and link_down2 and link_down3)\
1059 and loop_count < 30 ):
1060 json_str1 = main.ONOS1cli.links()
1061 json_str2 = main.ONOS2cli.links()
1062 json_str3 = main.ONOS3cli.links()
1063 if not (json_str1 and json_str2 and json_str3):
1064 main.log.error("CLI command returned error ")
1065 break
1066 else:
1067 json_obj1 = json.loads(json_str1)
1068 json_obj2 = json.loads(json_str2)
1069 json_obj3 = json.loads(json_str3)
1070
1071 for obj1 in json_obj1:
1072 if '01' in obj1['src']['device']:
1073 link_down1 = False
1074 main.log.report("Link up from "+
1075 "s1 -> s2 on ONOS1 detected")
1076 for obj2 in json_obj2:
1077 if '01' in obj2['src']['device']:
1078 link_down2 = False
1079 main.log.report("Link up from "+
1080 "s1 -> s2 on ONOS2 detected")
1081 for obj3 in json_obj3:
1082 if '01' in obj3['src']['device']:
1083 link_down3 = False
1084 main.log.report("Link up from "+
1085 "s1 -> s2 on ONOS3 detected")
1086
1087 loop_count += 1
1088 time.sleep(1)
1089
1090 if (link_down1 and link_down2 and link_down3):
1091 main.log.info("Link up discovery failed")
1092
1093 link_up_lat_graph1 = 0
1094 link_up_lat_graph2 = 0
1095 link_up_lat_graph3 = 0
1096 link_up_lat_device1 = 0
1097 link_up_lat_device2 = 0
1098 link_up_lat_device3 = 0
1099
1100 assertion = main.FALSE
1101 else:
1102 json_topo_metrics_1 =\
1103 main.ONOS1cli.topology_events_metrics()
1104 json_topo_metrics_2 =\
1105 main.ONOS2cli.topology_events_metrics()
1106 json_topo_metrics_3 =\
1107 main.ONOS3cli.topology_events_metrics()
1108 json_topo_metrics_1 = json.loads(json_topo_metrics_1)
1109 json_topo_metrics_2 = json.loads(json_topo_metrics_2)
1110 json_topo_metrics_3 = json.loads(json_topo_metrics_3)
1111
1112 main.log.info("Obtaining graph and device timestamp")
1113 graph_timestamp_1 = \
1114 json_topo_metrics_1[graphTimestamp]['value']
1115 graph_timestamp_2 = \
1116 json_topo_metrics_2[graphTimestamp]['value']
1117 graph_timestamp_3 = \
1118 json_topo_metrics_3[graphTimestamp]['value']
1119
1120 link_timestamp_1 = \
1121 json_topo_metrics_1[linkTimestamp]['value']
1122 link_timestamp_2 = \
1123 json_topo_metrics_2[linkTimestamp]['value']
1124 link_timestamp_3 = \
1125 json_topo_metrics_3[linkTimestamp]['value']
1126
1127 if graph_timestamp_1 and graph_timestamp_2 and\
1128 graph_timestamp_3 and link_timestamp_1 and\
1129 link_timestamp_2 and link_timestamp_3:
1130 link_up_lat_graph1 = int(graph_timestamp_1) -\
1131 timestamp_link_up_t0
1132 link_up_lat_graph2 = int(graph_timestamp_2) -\
1133 timestamp_link_up_t0
1134 link_up_lat_graph3 = int(graph_timestamp_3) -\
1135 timestamp_link_up_t0
1136
1137 link_up_lat_link1 = int(link_timestamp_1) -\
1138 timestamp_link_up_t0
1139 link_up_lat_link2 = int(link_timestamp_2) -\
1140 timestamp_link_up_t0
1141 link_up_lat_link3 = int(link_timestamp_3) -\
1142 timestamp_link_up_t0
1143 else:
1144 main.log.error("There was an error calculating"+
1145 " the delta for link down event")
1146 link_up_lat_graph1 = 0
1147 link_up_lat_graph2 = 0
1148 link_up_lat_graph3 = 0
1149
1150 link_up_lat_device1 = 0
1151 link_up_lat_device2 = 0
1152 link_up_lat_device3 = 0
1153
1154 main.log.info("Link up latency ONOS1 iteration "+
1155 str(i)+" (end-to-end): "+
1156 str(link_up_lat_graph1)+" ms")
1157 main.log.info("Link up latency ONOS2 iteration "+
1158 str(i)+" (end-to-end): "+
1159 str(link_up_lat_graph2)+" ms")
1160 main.log.info("Link up latency ONOS3 iteration "+
1161 str(i)+" (end-to-end): "+
1162 str(link_up_lat_graph3)+" ms")
1163
1164 main.log.info("Link up latency ONOS1 iteration "+
1165 str(i)+" (link-event-to-system-timestamp): "+
1166 str(link_up_lat_link1)+" ms")
1167 main.log.info("Link up latency ONOS2 iteration "+
1168 str(i)+" (link-event-to-system-timestamp): "+
1169 str(link_up_lat_link2)+" ms")
1170 main.log.info("Link up latency ONOS3 iteration "+
1171 str(i)+" (link-event-to-system-timestamp): "+
1172 str(link_up_lat_link3))
1173
1174 #Calculate avg of node calculations
1175 link_up_lat_graph_avg =\
1176 (link_up_lat_graph1 +
1177 link_up_lat_graph2 +
1178 link_up_lat_graph3) / 3.0
1179 link_up_lat_link_avg =\
1180 (link_up_lat_link1 +
1181 link_up_lat_link2 +
1182 link_up_lat_link3) / 3.0
1183
1184 #Set threshold and append latency to list
andrewonlabe5bcef92014-11-06 17:53:20 -05001185 if link_up_lat_graph_avg > up_threshold_min and\
1186 link_up_lat_graph_avg < up_threshold_max:
andrewonlababb11c32014-11-04 15:03:24 -05001187 link_up_graph_to_system_list.append(
1188 link_up_lat_graph_avg)
andrewonlab8790abb2014-11-06 13:51:54 -05001189 else:
1190 main.log.info("Link up latency exceeded threshold")
1191 main.log.info("Results for iteration "+str(i)+
1192 "have been omitted")
andrewonlabe5bcef92014-11-06 17:53:20 -05001193 if link_up_lat_link_avg > up_threshold_min and\
1194 link_up_lat_link_avg < up_threshold_max:
andrewonlababb11c32014-11-04 15:03:24 -05001195 link_up_link_to_system_list.append(
1196 link_up_lat_link_avg)
andrewonlab8790abb2014-11-06 13:51:54 -05001197 else:
1198 main.log.info("Link up latency exceeded threshold")
1199 main.log.info("Results for iteration "+str(i)+
1200 "have been omitted")
andrewonlab53b641c2014-10-31 19:44:44 -04001201
andrewonlab4e124482014-11-04 13:37:25 -05001202 #Calculate min, max, avg of list and report
1203 link_down_min = min(link_down_graph_to_system_list)
1204 link_down_max = max(link_down_graph_to_system_list)
1205 link_down_avg = sum(link_down_graph_to_system_list) / \
1206 len(link_down_graph_to_system_list)
andrewonlababb11c32014-11-04 15:03:24 -05001207 link_up_min = min(link_up_graph_to_system_list)
1208 link_up_max = max(link_up_graph_to_system_list)
1209 link_up_avg = sum(link_up_graph_to_system_list) / \
1210 len(link_up_graph_to_system_list)
1211
1212 main.log.report("Link down latency - Min: "+
1213 str(link_down_min)+"ms Max: "+
1214 str(link_down_max)+"ms Avg: "+
1215 str(link_down_avg)+"ms")
1216 main.log.report("Link up latency - Min: "+
1217 str(link_up_min)+"ms Max: "+
1218 str(link_up_max)+"ms Avg: "+
1219 str(link_up_avg)+"ms")
andrewonlab4e124482014-11-04 13:37:25 -05001220
andrewonlab8790abb2014-11-06 13:51:54 -05001221 utilities.assert_equals(expect=main.TRUE, actual=assertion,
1222 onpass="Link discovery latency calculation successful",
1223 onfail="Link discovery latency case failed")
1224
andrewonlabb54b85b2014-10-28 18:43:57 -04001225 def CASE5(self, main):
1226 '''
1227 100 Switch discovery latency
1228
1229 Important:
andrewonlab16ce4852014-10-30 13:41:09 -04001230 This test case can be potentially dangerous if
1231 your machine has previously set iptables rules.
1232 One of the steps of the test case will flush
1233 all existing iptables rules.
andrewonlab8790abb2014-11-06 13:51:54 -05001234 Note:
1235 You can specify the number of switches in the
1236 params file to adjust the switch discovery size
1237 (and specify the corresponding topology in Mininet1
1238 .topo file)
andrewonlabb54b85b2014-10-28 18:43:57 -04001239 '''
1240 import time
1241 import subprocess
1242 import os
1243 import requests
1244 import json
1245
1246 ONOS1_ip = main.params['CTRL']['ip1']
1247 ONOS2_ip = main.params['CTRL']['ip2']
1248 ONOS3_ip = main.params['CTRL']['ip3']
1249 MN1_ip = main.params['MN']['ip1']
1250 ONOS_user = main.params['CTRL']['user']
1251
1252 default_sw_port = main.params['CTRL']['port1']
1253
1254 #Number of iterations of case
1255 num_iter = main.params['TEST']['numIter']
andrewonlab16ce4852014-10-30 13:41:09 -04001256 num_sw = main.params['TEST']['numSwitch']
1257
andrewonlabb54b85b2014-10-28 18:43:57 -04001258 #Timestamp 'keys' for json metrics output.
1259 #These are subject to change, hence moved into params
1260 deviceTimestamp = main.params['JSON']['deviceTimestamp']
andrewonlab16ce4852014-10-30 13:41:09 -04001261 graphTimestamp = main.params['JSON']['graphTimestamp']
andrewonlabe5bcef92014-11-06 17:53:20 -05001262
1263 #Threshold for this test case
1264 sw_disc_threshold_str = main.params['TEST']['swDisc100Threshold']
1265 sw_disc_threshold_obj = sw_disc_threshold_str.split(",")
1266 sw_disc_threshold_min = int(sw_disc_threshold_obj[0])
1267 sw_disc_threshold_max = int(sw_disc_threshold_obj[1])
1268
1269 print_packet_info = main.params['TEST']['printPacketInfo']
1270
andrewonlab53b641c2014-10-31 19:44:44 -04001271 tshark_ofp_output = "/tmp/tshark_ofp_"+num_sw+"sw.txt"
1272 tshark_tcp_output = "/tmp/tshark_tcp_"+num_sw+"sw.txt"
1273
1274 tshark_ofp_result_list = []
1275 tshark_tcp_result_list = []
andrewonlabb54b85b2014-10-28 18:43:57 -04001276
andrewonlabe5bcef92014-11-06 17:53:20 -05001277 sw_discovery_lat_list = []
1278
andrewonlab16ce4852014-10-30 13:41:09 -04001279 main.case(num_sw+" Switch discovery latency")
andrewonlabb54b85b2014-10-28 18:43:57 -04001280 main.step("Assigning all switches to ONOS1")
andrewonlab16ce4852014-10-30 13:41:09 -04001281 for i in range(1, int(num_sw)+1):
andrewonlabb54b85b2014-10-28 18:43:57 -04001282 main.Mininet1.assign_sw_controller(
1283 sw=str(i),
1284 ip1=ONOS1_ip,
1285 port1=default_sw_port)
andrewonlab16ce4852014-10-30 13:41:09 -04001286
andrewonlabb54b85b2014-10-28 18:43:57 -04001287 #Ensure that nodes are configured with ptpd
andrewonlab16ce4852014-10-30 13:41:09 -04001288 #Just a warning message
1289 main.log.info("Please check ptpd configuration to ensure"+\
1290 " All nodes' system times are in sync")
1291 time.sleep(5)
andrewonlabb54b85b2014-10-28 18:43:57 -04001292
1293 for i in range(0, int(num_iter)):
andrewonlab8d29f122014-10-22 17:15:04 -04001294
andrewonlabb54b85b2014-10-28 18:43:57 -04001295 main.step("Set iptables rule to block incoming sw connections")
1296 #Set iptables rule to block incoming switch connections
andrewonlab53b641c2014-10-31 19:44:44 -04001297 #The rule description is as follows:
1298 # Append to INPUT rule,
1299 # behavior DROP that matches following:
1300 # * packet type: tcp
1301 # * source IP: MN1_ip
1302 # * destination PORT: 6633
andrewonlabb54b85b2014-10-28 18:43:57 -04001303 main.ONOS1.handle.sendline(
andrewonlab16ce4852014-10-30 13:41:09 -04001304 "sudo iptables -A INPUT -p tcp -s "+MN1_ip+
andrewonlabb54b85b2014-10-28 18:43:57 -04001305 " --dport "+default_sw_port+" -j DROP")
1306 main.ONOS1.handle.expect("\$")
andrewonlab53b641c2014-10-31 19:44:44 -04001307 # Append to OUTPUT rule,
1308 # behavior DROP that matches following:
1309 # * packet type: tcp
1310 # * source IP: MN1_ip
1311 # * destination PORT: 6633
1312 main.ONOS1.handle.sendline(
1313 "sudo iptables -A OUTPUT -p tcp -s "+MN1_ip+
1314 " --dport "+default_sw_port+" -j DROP")
1315 main.ONOS1.handle.expect("\$")
andrewonlabb54b85b2014-10-28 18:43:57 -04001316 #Give time to allow rule to take effect
andrewonlab8790abb2014-11-06 13:51:54 -05001317 #NOTE: Sleep period may need to be configured
1318 # based on the number of switches in the topology
andrewonlab16ce4852014-10-30 13:41:09 -04001319 main.log.info("Please wait for switch connection to "+
1320 "time out")
1321 time.sleep(60)
1322
1323 #Gather vendor OFP with tshark
1324 main.ONOS1.tshark_grep("OFP 86 Vendor",
1325 tshark_ofp_output)
andrewonlab53b641c2014-10-31 19:44:44 -04001326 main.ONOS1.tshark_grep("TCP 74 ",
1327 tshark_tcp_output)
andrewonlabb54b85b2014-10-28 18:43:57 -04001328
andrewonlab16ce4852014-10-30 13:41:09 -04001329 #NOTE: Remove all iptables rule quickly (flush)
andrewonlabb54b85b2014-10-28 18:43:57 -04001330 # Before removal, obtain TestON timestamp at which
andrewonlab16ce4852014-10-30 13:41:09 -04001331 # removal took place
1332 # (ensuring nodes are configured via ptp)
andrewonlabb54b85b2014-10-28 18:43:57 -04001333 # sudo iptables -F
andrewonlab16ce4852014-10-30 13:41:09 -04001334
1335 t0_system = time.time() * 1000
1336 main.ONOS1.handle.sendline(
1337 "sudo iptables -F")
andrewonlabb54b85b2014-10-28 18:43:57 -04001338
andrewonlab16ce4852014-10-30 13:41:09 -04001339 #Counter to track loop count
1340 counter_loop = 0
1341 counter_avail1 = 0
1342 counter_avail2 = 0
1343 counter_avail3 = 0
1344 onos1_dev = False
1345 onos2_dev = False
1346 onos3_dev = False
1347 while counter_loop < 60:
1348 #Continue to check devices for all device
1349 #availability. When all devices in all 3
1350 #ONOS instances indicate that devices are available
1351 #obtain graph event timestamp for t1.
1352 device_str_obj1 = main.ONOS1cli.devices()
1353 device_str_obj2 = main.ONOS2cli.devices()
1354 device_str_obj3 = main.ONOS3cli.devices()
1355
1356 device_json1 = json.loads(device_str_obj1)
1357 device_json2 = json.loads(device_str_obj2)
1358 device_json3 = json.loads(device_str_obj3)
1359
1360 for device1 in device_json1:
1361 if device1['available'] == True:
1362 counter_avail1 += 1
1363 if counter_avail1 == int(num_sw):
1364 onos1_dev = True
1365 main.log.info("All devices have been "+
1366 "discovered on ONOS1")
1367 else:
1368 counter_avail1 = 0
1369 for device2 in device_json2:
1370 if device2['available'] == True:
1371 counter_avail2 += 1
1372 if counter_avail2 == int(num_sw):
1373 onos2_dev = True
1374 main.log.info("All devices have been "+
1375 "discovered on ONOS2")
1376 else:
1377 counter_avail2 = 0
1378 for device3 in device_json3:
1379 if device3['available'] == True:
1380 counter_avail3 += 1
1381 if counter_avail3 == int(num_sw):
1382 onos3_dev = True
1383 main.log.info("All devices have been "+
1384 "discovered on ONOS3")
1385 else:
1386 counter_avail3 = 0
1387
1388 if onos1_dev and onos2_dev and onos3_dev:
1389 main.log.info("All devices have been discovered "+
1390 "on all ONOS instances")
1391 json_str_topology_metrics_1 =\
1392 main.ONOS1cli.topology_events_metrics()
1393 json_str_topology_metrics_2 =\
1394 main.ONOS2cli.topology_events_metrics()
1395 json_str_topology_metrics_3 =\
1396 main.ONOS3cli.topology_events_metrics()
andrewonlab53b641c2014-10-31 19:44:44 -04001397
1398 #Exit while loop if all devices discovered
andrewonlab16ce4852014-10-30 13:41:09 -04001399 break
1400
1401 counter_loop += 1
1402 #Give some time in between CLI calls
1403 #(will not affect measurement)
1404 time.sleep(3)
1405
1406 main.ONOS1.tshark_stop()
1407
1408 os.system("scp "+ONOS_user+"@"+ONOS1_ip+":"+
1409 tshark_ofp_output+" /tmp/")
andrewonlab53b641c2014-10-31 19:44:44 -04001410 os.system("scp "+ONOS_user+"@"+ONOS1_ip+":"+
1411 tshark_tcp_output+" /tmp/")
andrewonlab16ce4852014-10-30 13:41:09 -04001412 ofp_file = open(tshark_ofp_output, 'r')
1413
1414 #The following is for information purpose only.
1415 #TODO: Automate OFP output analysis
1416 main.log.info("Tshark OFP Vendor output: ")
1417 for line in ofp_file:
andrewonlab53b641c2014-10-31 19:44:44 -04001418 tshark_ofp_result_list.append(line)
andrewonlabe5bcef92014-11-06 17:53:20 -05001419 if print_packet_info=='True':
1420 main.log.info(line)
andrewonlab16ce4852014-10-30 13:41:09 -04001421
andrewonlab53b641c2014-10-31 19:44:44 -04001422 ofp_file.close()
1423
1424 tcp_file = open(tshark_tcp_output, 'r')
1425 main.log.info("Tshark TCP 74 output: ")
1426 for line in tcp_file:
1427 tshark_tcp_result_list.append(line)
andrewonlabe5bcef92014-11-06 17:53:20 -05001428 if print_packet_info=='True':
1429 main.log.info(line)
andrewonlab53b641c2014-10-31 19:44:44 -04001430
1431 tcp_file.close()
1432
andrewonlab16ce4852014-10-30 13:41:09 -04001433 json_obj_1 = json.loads(json_str_topology_metrics_1)
1434 json_obj_2 = json.loads(json_str_topology_metrics_2)
1435 json_obj_3 = json.loads(json_str_topology_metrics_3)
1436
1437 graph_timestamp_1 = \
1438 json_obj_1[graphTimestamp]['value']
1439 graph_timestamp_2 = \
1440 json_obj_2[graphTimestamp]['value']
1441 graph_timestamp_3 = \
1442 json_obj_3[graphTimestamp]['value']
1443
andrewonlabe5bcef92014-11-06 17:53:20 -05001444 graph_lat_1 = int(graph_timestamp_1) - int(t0_system)
1445 graph_lat_2 = int(graph_timestamp_2) - int(t0_system)
1446 graph_lat_3 = int(graph_timestamp_3) - int(t0_system)
andrewonlab16ce4852014-10-30 13:41:09 -04001447
andrewonlabe5bcef92014-11-06 17:53:20 -05001448 avg_graph_lat = \
1449 (int(graph_lat_1) +\
1450 int(graph_lat_2) +\
1451 int(graph_lat_3)) / 3
1452
1453 if avg_graph_lat > sw_disc_threshold_min \
1454 and avg_graph_lat < sw_disc_threshold_max:
1455 sw_discovery_lat_list.append(
1456 avg_graph_lat)
1457 else:
1458 main.log.info("100 Switch discovery latency "+
1459 "exceeded the threshold.")
1460
1461 #END ITERATION FOR LOOP
andrewonlab16ce4852014-10-30 13:41:09 -04001462
andrewonlabe5bcef92014-11-06 17:53:20 -05001463 sw_lat_min = min(sw_discovery_lat_list)
1464 sw_lat_max = max(sw_discovery_lat_list)
1465 sw_lat_avg = sum(sw_discovery_lat_list) /\
1466 len(sw_discovery_lat_list)
andrewonlab16ce4852014-10-30 13:41:09 -04001467
andrewonlabe5bcef92014-11-06 17:53:20 -05001468 main.log.report("100 Switch discovery lat - \n"+\
1469 "Min: "+str(sw_lat_min)+" ms\n"+\
1470 "Max: "+str(sw_lat_max)+" ms\n"+\
1471 "Avg: "+str(sw_lat_avg)+" ms\n")
andrewonlab16ce4852014-10-30 13:41:09 -04001472
andrewonlabb54b85b2014-10-28 18:43:57 -04001473