blob: 6b6753920607015f00f50c32ed9fc9d8503b6f29 [file] [log] [blame]
andrewonlab2a6c9342014-10-16 13:40:15 -04001#TopoPerfNext
2#
3#Topology Performance test for ONOS-next
4#
5#andrew@onlab.us
6
7import time
8import sys
9import os
10import re
11
12class TopoPerfNext:
13 def __init__(self):
14 self.default = ''
15
16 def CASE1(self, main):
17 '''
18 ONOS startup sequence
19 '''
andrewonlabe9fb6722014-10-24 12:20:35 -040020 import time
21
andrewonlab2a6c9342014-10-16 13:40:15 -040022 cell_name = main.params['ENV']['cellName']
23
24 git_pull = main.params['GIT']['autoPull']
25 checkout_branch = main.params['GIT']['checkout']
26
27 ONOS1_ip = main.params['CTRL']['ip1']
andrewonlabba44bcf2014-10-16 16:54:41 -040028 ONOS2_ip = main.params['CTRL']['ip2']
29 ONOS3_ip = main.params['CTRL']['ip3']
andrewonlab2a6c9342014-10-16 13:40:15 -040030 MN1_ip = main.params['MN']['ip1']
31 BENCH_ip = main.params['BENCH']['ip']
32
33 main.case("Setting up test environment")
34
35 main.step("Creating cell file")
36 cell_file_result = main.ONOSbench.create_cell_file(
andrewonlabe6745342014-10-17 14:29:13 -040037 BENCH_ip, cell_name, MN1_ip, "onos-core",
andrewonlabba44bcf2014-10-16 16:54:41 -040038 ONOS1_ip, ONOS2_ip, ONOS3_ip)
andrewonlab2a6c9342014-10-16 13:40:15 -040039
40 main.step("Applying cell file to environment")
41 cell_apply_result = main.ONOSbench.set_cell(cell_name)
42 verify_cell_result = main.ONOSbench.verify_cell()
43
44 main.step("Git checkout and pull "+checkout_branch)
45 if git_pull == 'on':
46 checkout_result = \
47 main.ONOSbench.git_checkout(checkout_branch)
48 pull_result = main.ONOSbench.git_pull()
49 else:
50 checkout_result = main.TRUE
51 pull_result = main.TRUE
52 main.log.info("Skipped git checkout and pull")
53
54 main.step("Using mvn clean & install")
andrewonlab8d29f122014-10-22 17:15:04 -040055 #mvn_result = main.ONOSbench.clean_install()
56 mvn_result = main.TRUE
andrewonlab2a6c9342014-10-16 13:40:15 -040057
58 main.step("Creating ONOS package")
59 package_result = main.ONOSbench.onos_package()
60
61 main.step("Installing ONOS package")
andrewonlabe9fb6722014-10-24 12:20:35 -040062 install1_result = main.ONOSbench.onos_install(node=ONOS1_ip)
63 install2_result = main.ONOSbench.onos_install(node=ONOS2_ip)
64 install3_result = main.ONOSbench.onos_install(node=ONOS3_ip)
andrewonlab2a6c9342014-10-16 13:40:15 -040065
andrewonlabe9fb6722014-10-24 12:20:35 -040066 #NOTE: This step may be unnecessary
67 #main.step("Starting ONOS service")
68 #start_result = main.ONOSbench.onos_start(ONOS1_ip)
andrewonlab2a6c9342014-10-16 13:40:15 -040069
andrewonlab867212a2014-10-22 20:13:38 -040070 main.step("Set cell for ONOS cli env")
71 main.ONOS1cli.set_cell(cell_name)
72 main.ONOS2cli.set_cell(cell_name)
73 main.ONOS3cli.set_cell(cell_name)
74
andrewonlabe9fb6722014-10-24 12:20:35 -040075 time.sleep(10)
76
andrewonlab867212a2014-10-22 20:13:38 -040077 main.step("Start onos cli")
andrewonlabe9fb6722014-10-24 12:20:35 -040078 cli1 = main.ONOS1cli.start_onos_cli(ONOS1_ip)
79 cli2 = main.ONOS2cli.start_onos_cli(ONOS2_ip)
80 cli3 = main.ONOS3cli.start_onos_cli(ONOS3_ip)
81
andrewonlab867212a2014-10-22 20:13:38 -040082 main.step("Enable metrics feature")
83 main.ONOS1cli.feature_install("onos-app-metrics-topology")
84 main.ONOS2cli.feature_install("onos-app-metrics-topology")
85 main.ONOS3cli.feature_install("onos-app-metrics-topology")
86
andrewonlab2a6c9342014-10-16 13:40:15 -040087 utilities.assert_equals(expect=main.TRUE,
88 actual= cell_file_result and cell_apply_result and\
89 verify_cell_result and checkout_result and\
90 pull_result and mvn_result and\
andrewonlabe9fb6722014-10-24 12:20:35 -040091 install1_result and install2_result and\
92 install3_result,
andrewonlab8d29f122014-10-22 17:15:04 -040093 onpass="ONOS started successfully",
94 onfail="Failed to start ONOS")
andrewonlab2a6c9342014-10-16 13:40:15 -040095
andrewonlabba44bcf2014-10-16 16:54:41 -040096 def CASE2(self, main):
97 '''
98 Assign s1 to ONOS1 and measure latency
andrewonlab3a7c3c72014-10-24 17:21:03 -040099
100 There are 4 levels of latency measurements to this test:
101 1) End-to-end measurement: Complete end-to-end measurement
102 from TCP (SYN/ACK) handshake to Graph change
103 2) OFP-to-graph measurement: 'ONOS processing' snippet of
104 measurement from OFP Vendor message to Graph change
105 3) OFP-to-device measurement: 'ONOS processing without
106 graph change' snippet of measurement from OFP vendor
107 message to Device change timestamp
108 4) T0-to-device measurement: Measurement that includes
109 the switch handshake to devices timestamp without
110 the graph view change. (TCP handshake -> Device
111 change)
andrewonlabba44bcf2014-10-16 16:54:41 -0400112 '''
113 import time
andrewonlabe6745342014-10-17 14:29:13 -0400114 import subprocess
115 import json
116 import requests
117 import os
andrewonlabba44bcf2014-10-16 16:54:41 -0400118
119 ONOS1_ip = main.params['CTRL']['ip1']
120 ONOS2_ip = main.params['CTRL']['ip2']
121 ONOS3_ip = main.params['CTRL']['ip3']
andrewonlabe6745342014-10-17 14:29:13 -0400122 ONOS_user = main.params['CTRL']['user']
123
andrewonlabba44bcf2014-10-16 16:54:41 -0400124 default_sw_port = main.params['CTRL']['port1']
125
126 #Number of iterations of case
127 num_iter = main.params['TEST']['numIter']
128
andrewonlab226024e2014-10-24 16:01:32 -0400129 #Timestamp 'keys' for json metrics output.
130 #These are subject to change, hence moved into params
131 deviceTimestamp = main.params['JSON']['deviceTimestamp']
132 graphTimestamp = main.params['JSON']['graphTimestamp']
133
134 #List of switch add latency collected from
135 #all iterations
136 latency_end_to_end_list = []
137 latency_ofp_to_graph_list = []
138 latency_ofp_to_device_list = []
139 latency_t0_to_device_list = []
140
andrewonlabba44bcf2014-10-16 16:54:41 -0400141 #Directory/file to store tshark results
142 tshark_of_output = "/tmp/tshark_of_topo.txt"
143 tshark_tcp_output = "/tmp/tshark_tcp_topo.txt"
144
145 #String to grep in tshark output
146 tshark_tcp_string = "TCP 74 "+default_sw_port
147 tshark_of_string = "OFP 86 Vendor"
andrewonlabe6745342014-10-17 14:29:13 -0400148
149 #Initialize assertion to TRUE
150 assertion = main.TRUE
151
andrewonlabba44bcf2014-10-16 16:54:41 -0400152 main.log.report("Latency of adding one switch")
153
154 for i in range(0, int(num_iter)):
155 main.log.info("Starting tshark capture")
156
157 #* TCP [ACK, SYN] is used as t0_a, the
158 # very first "exchange" between ONOS and
159 # the switch for end-to-end measurement
160 #* OFP [Stats Reply] is used for t0_b
161 # the very last OFP message between ONOS
162 # and the switch for ONOS measurement
163 main.ONOS1.tshark_grep(tshark_tcp_string,
164 tshark_tcp_output)
165 main.ONOS1.tshark_grep(tshark_of_string,
166 tshark_of_output)
167
168 #Wait and ensure tshark is started and
169 #capturing
170 time.sleep(10)
171
172 main.log.info("Assigning s1 to controller")
173
174 main.Mininet1.assign_sw_controller(sw="1",
175 ip1=ONOS1_ip, port1=default_sw_port)
176
177 #Wait and ensure switch is assigned
178 #before stopping tshark
andrewonlab867212a2014-10-22 20:13:38 -0400179 time.sleep(30)
andrewonlab226024e2014-10-24 16:01:32 -0400180
181 main.log.info("Stopping all Tshark processes")
andrewonlabba44bcf2014-10-16 16:54:41 -0400182 main.ONOS1.stop_tshark()
183
andrewonlabe6745342014-10-17 14:29:13 -0400184 #tshark output is saved in ONOS. Use subprocess
185 #to copy over files to TestON for parsing
186 main.log.info("Copying over tshark files")
187
188 #TCP CAPTURE ****
andrewonlab8d29f122014-10-22 17:15:04 -0400189 #Copy the tshark output from ONOS machine to
190 #TestON machine in tshark_tcp_output directory>file
191 os.system("scp "+ONOS_user+"@"+ONOS1_ip+":"+
192 tshark_tcp_output+" /tmp/")
193 tcp_file = open(tshark_tcp_output, 'r')
194 temp_text = tcp_file.readline()
andrewonlabe6745342014-10-17 14:29:13 -0400195 temp_text = temp_text.split(" ")
andrewonlabba44bcf2014-10-16 16:54:41 -0400196
andrewonlabe6745342014-10-17 14:29:13 -0400197 main.log.info("Object read in from TCP capture: "+
198 str(temp_text))
andrewonlab867212a2014-10-22 20:13:38 -0400199 if len(temp_text) > 1:
andrewonlab3a7c3c72014-10-24 17:21:03 -0400200 t0_tcp = float(temp_text[1])*1000.0
andrewonlabe6745342014-10-17 14:29:13 -0400201 else:
202 main.log.error("Tshark output file for TCP"+
203 " returned unexpected results")
204 t0_tcp = 0
205 assertion = main.FALSE
andrewonlab8d29f122014-10-22 17:15:04 -0400206
207 tcp_file.close()
andrewonlabe6745342014-10-17 14:29:13 -0400208 #****************
andrewonlabba44bcf2014-10-16 16:54:41 -0400209
andrewonlabe6745342014-10-17 14:29:13 -0400210 #OF CAPTURE ****
andrewonlab8d29f122014-10-22 17:15:04 -0400211 os.system("scp "+ONOS_user+"@"+ONOS1_ip+":"+
212 tshark_of_output+" /tmp/")
213 of_file = open(tshark_of_output, 'r')
214
215 line_ofp = ""
andrewonlab226024e2014-10-24 16:01:32 -0400216 #Read until last line of file
andrewonlabe6745342014-10-17 14:29:13 -0400217 while True:
andrewonlab8d29f122014-10-22 17:15:04 -0400218 temp_text = of_file.readline()
219 if temp_text !='':
andrewonlabe6745342014-10-17 14:29:13 -0400220 line_ofp = temp_text
221 else:
222 break
223 obj = line_ofp.split(" ")
224
225 main.log.info("Object read in from OFP capture: "+
226 str(line_ofp))
227
andrewonlab867212a2014-10-22 20:13:38 -0400228 if len(line_ofp) > 1:
andrewonlab3a7c3c72014-10-24 17:21:03 -0400229 t0_ofp = float(obj[1])*1000.0
andrewonlabe6745342014-10-17 14:29:13 -0400230 else:
231 main.log.error("Tshark output file for OFP"+
232 " returned unexpected results")
233 t0_ofp = 0
234 assertion = main.FALSE
andrewonlab8d29f122014-10-22 17:15:04 -0400235
236 of_file.close()
andrewonlabe6745342014-10-17 14:29:13 -0400237 #****************
238
andrewonlab867212a2014-10-22 20:13:38 -0400239 json_str_1 = main.ONOS1cli.topology_events_metrics()
240 json_str_2 = main.ONOS2cli.topology_events_metrics()
241 json_str_3 = main.ONOS3cli.topology_events_metrics()
andrewonlab867212a2014-10-22 20:13:38 -0400242
243 json_obj_1 = json.loads(json_str_1)
244 json_obj_2 = json.loads(json_str_2)
245 json_obj_3 = json.loads(json_str_3)
246
andrewonlab226024e2014-10-24 16:01:32 -0400247 #Obtain graph timestamp. This timestsamp captures
248 #the epoch time at which the topology graph was updated.
249 graph_timestamp_1 = \
250 json_obj_1[graphTimestamp]['value']
251 graph_timestamp_2 = \
252 json_obj_2[graphTimestamp]['value']
253 graph_timestamp_3 = \
254 json_obj_3[graphTimestamp]['value']
andrewonlab867212a2014-10-22 20:13:38 -0400255
andrewonlab226024e2014-10-24 16:01:32 -0400256 #Obtain device timestamp. This timestamp captures
257 #the epoch time at which the device event happened
258 device_timestamp_1 = \
259 json_obj_1[deviceTimestamp]['value']
260 device_timestamp_2 = \
261 json_obj_2[deviceTimestamp]['value']
262 device_timestamp_3 = \
263 json_obj_3[deviceTimestamp]['value']
andrewonlabe9fb6722014-10-24 12:20:35 -0400264
andrewonlab226024e2014-10-24 16:01:32 -0400265 #t0 to device processing latency
266 delta_device_1 = int(device_timestamp_1) - int(t0_tcp)
267 delta_device_2 = int(device_timestamp_2) - int(t0_tcp)
268 delta_device_3 = int(device_timestamp_3) - int(t0_tcp)
269
270 #Get average of delta from all instances
271 avg_delta_device = \
272 (int(delta_device_1)+\
273 int(delta_device_2)+\
274 int(delta_device_3)) / 3
andrewonlabba44bcf2014-10-16 16:54:41 -0400275
andrewonlab226024e2014-10-24 16:01:32 -0400276 #Ensure avg delta meets the threshold before appending
277 if avg_delta_device > 0.0 and avg_delta_device < 10000:
278 latency_t0_to_device_list.append(avg_delta_device)
andrewonlabee4efeb2014-10-24 16:44:51 -0400279 else:
andrewonlab09d973e2014-10-24 18:56:58 -0400280 main.log.info("Results for t0-to-device ignored"+\
281 "due to excess in threshold")
andrewonlabee4efeb2014-10-24 16:44:51 -0400282
andrewonlab226024e2014-10-24 16:01:32 -0400283 #t0 to graph processing latency (end-to-end)
284 delta_graph_1 = int(graph_timestamp_1) - int(t0_tcp)
285 delta_graph_2 = int(graph_timestamp_2) - int(t0_tcp)
286 delta_graph_3 = int(graph_timestamp_3) - int(t0_tcp)
287
288 #Get average of delta from all instances
289 avg_delta_graph = \
290 (int(delta_graph_1)+\
291 int(delta_graph_2)+\
292 int(delta_graph_3)) / 3
293
andrewonlab226024e2014-10-24 16:01:32 -0400294 #Ensure avg delta meets the threshold before appending
295 if avg_delta_graph > 0.0 and avg_delta_graph < 10000:
andrewonlab09d973e2014-10-24 18:56:58 -0400296 latency_end_to_end_list.append(avg_delta_graph)
andrewonlabee4efeb2014-10-24 16:44:51 -0400297 else:
andrewonlab09d973e2014-10-24 18:56:58 -0400298 main.log.info("Results for end-to-end ignored"+\
299 "due to excess in threshold")
andrewonlab226024e2014-10-24 16:01:32 -0400300
301 #ofp to graph processing latency (ONOS processing)
302 delta_ofp_graph_1 = int(graph_timestamp_1) - int(t0_ofp)
303 delta_ofp_graph_2 = int(graph_timestamp_2) - int(t0_ofp)
304 delta_ofp_graph_3 = int(graph_timestamp_3) - int(t0_ofp)
305
306 avg_delta_ofp_graph = \
307 (int(delta_ofp_graph_1)+\
308 int(delta_ofp_graph_2)+\
309 int(delta_ofp_graph_3)) / 3
310
311 if avg_delta_ofp_graph > 0.0 and avg_delta_ofp_graph < 10000:
312 latency_ofp_to_graph_list.append(avg_delta_ofp_graph)
andrewonlabee4efeb2014-10-24 16:44:51 -0400313 else:
andrewonlab09d973e2014-10-24 18:56:58 -0400314 main.log.info("Results for ofp-to-graph "+\
315 "ignored due to excess in threshold")
andrewonlabee4efeb2014-10-24 16:44:51 -0400316
andrewonlab226024e2014-10-24 16:01:32 -0400317 #ofp to device processing latency (ONOS processing)
andrewonlabee4efeb2014-10-24 16:44:51 -0400318 delta_ofp_device_1 = float(device_timestamp_1) - float(t0_ofp)
319 delta_ofp_device_2 = float(device_timestamp_2) - float(t0_ofp)
320 delta_ofp_device_3 = float(device_timestamp_3) - float(t0_ofp)
andrewonlab226024e2014-10-24 16:01:32 -0400321
322 avg_delta_ofp_device = \
andrewonlabee4efeb2014-10-24 16:44:51 -0400323 (float(delta_ofp_device_1)+\
324 float(delta_ofp_device_2)+\
325 float(delta_ofp_device_3)) / 3.0
andrewonlab226024e2014-10-24 16:01:32 -0400326
andrewonlabf47993a2014-10-24 17:56:01 -0400327 #NOTE: ofp - delta measurements are occasionally negative
328 # due to system time misalignment.
329 #TODO: Implement ptp across all clusters
330 #Just add the calculation to list for now
331 latency_ofp_to_device_list.append(avg_delta_ofp_device)
andrewonlabba44bcf2014-10-16 16:54:41 -0400332
andrewonlabe6745342014-10-17 14:29:13 -0400333 #TODO:
334 #Fetch logs upon threshold excess
andrewonlabba44bcf2014-10-16 16:54:41 -0400335
andrewonlabf47993a2014-10-24 17:56:01 -0400336
andrewonlab226024e2014-10-24 16:01:32 -0400337 main.log.info("ONOS1 delta end-to-end: "+
andrewonlab09d973e2014-10-24 18:56:58 -0400338 str(delta_graph_1) + " ms")
andrewonlab226024e2014-10-24 16:01:32 -0400339 main.log.info("ONOS2 delta end-to-end: "+
andrewonlab09d973e2014-10-24 18:56:58 -0400340 str(delta_graph_2) + " ms")
341 main.log.info("ONOS3 delta end-to-end: "+
342 str(delta_graph_3) + " ms")
andrewonlabba44bcf2014-10-16 16:54:41 -0400343
andrewonlab226024e2014-10-24 16:01:32 -0400344 main.log.info("ONOS1 delta OFP - graph: "+
andrewonlab09d973e2014-10-24 18:56:58 -0400345 str(delta_ofp_graph_1) + " ms")
andrewonlab226024e2014-10-24 16:01:32 -0400346 main.log.info("ONOS2 delta OFP - graph: "+
andrewonlab09d973e2014-10-24 18:56:58 -0400347 str(delta_ofp_graph_2) + " ms")
andrewonlab226024e2014-10-24 16:01:32 -0400348 main.log.info("ONOS3 delta OFP - graph: "+
andrewonlab09d973e2014-10-24 18:56:58 -0400349 str(delta_ofp_graph_3) + " ms")
andrewonlabe6745342014-10-17 14:29:13 -0400350
andrewonlab226024e2014-10-24 16:01:32 -0400351 main.log.info("ONOS1 delta device - t0: "+
andrewonlab09d973e2014-10-24 18:56:58 -0400352 str(delta_device_1) + " ms")
andrewonlab226024e2014-10-24 16:01:32 -0400353 main.log.info("ONOS2 delta device - t0: "+
andrewonlab09d973e2014-10-24 18:56:58 -0400354 str(delta_device_2) + " ms")
andrewonlab226024e2014-10-24 16:01:32 -0400355 main.log.info("ONOS3 delta device - t0: "+
andrewonlab09d973e2014-10-24 18:56:58 -0400356 str(delta_device_3) + " ms")
andrewonlab226024e2014-10-24 16:01:32 -0400357
358 main.log.info("ONOS1 delta OFP - device: "+
andrewonlab09d973e2014-10-24 18:56:58 -0400359 str(delta_ofp_device_1) + " ms")
andrewonlab226024e2014-10-24 16:01:32 -0400360 main.log.info("ONOS2 delta OFP - device: "+
andrewonlab09d973e2014-10-24 18:56:58 -0400361 str(delta_ofp_device_2) + " ms")
andrewonlab226024e2014-10-24 16:01:32 -0400362 main.log.info("ONOS3 delta OFP - device: "+
andrewonlab09d973e2014-10-24 18:56:58 -0400363 str(delta_ofp_device_3) + " ms")
andrewonlab226024e2014-10-24 16:01:32 -0400364
andrewonlab8d29f122014-10-22 17:15:04 -0400365 main.step("Remove switch from controller")
366 main.Mininet1.delete_sw_controller("s1")
andrewonlabba44bcf2014-10-16 16:54:41 -0400367
andrewonlab8d29f122014-10-22 17:15:04 -0400368 time.sleep(5)
andrewonlabba44bcf2014-10-16 16:54:41 -0400369
andrewonlab09d973e2014-10-24 18:56:58 -0400370 #END of for loop iteration
andrewonlabf47993a2014-10-24 17:56:01 -0400371
andrewonlabee4efeb2014-10-24 16:44:51 -0400372 #If there is at least 1 element in each list,
andrewonlabc15c9582014-10-24 16:35:52 -0400373 #pass the test case
374 if len(latency_end_to_end_list) > 0 and\
375 len(latency_ofp_to_graph_list) > 0 and\
376 len(latency_ofp_to_device_list) > 0 and\
377 len(latency_t0_to_device_list) > 0:
378 assertion = main.TRUE
andrewonlabf47993a2014-10-24 17:56:01 -0400379 elif len(latency_end_to_end_list) == 0:
380 #The appending of 0 here is to prevent
381 #the min,max,sum functions from failing
382 #below
383 latency_end_to_end_list.append(0)
384 assertion = main.FALSE
385 elif len(latency_ofp_to_graph_list) == 0:
386 latency_ofp_to_graph_list.append(0)
387 assertion = main.FALSE
388 elif len(latency_ofp_to_device_list) == 0:
389 latency_ofp_to_device_list.append(0)
390 assertion = main.FALSE
391 elif len(latency_t0_to_device_list) == 0:
392 latency_t0_to_device_list.append(0)
393 assertion = main.FALSE
andrewonlabc15c9582014-10-24 16:35:52 -0400394
395 #Calculate min, max, avg of latency lists
396 latency_end_to_end_max = \
andrewonlabee4efeb2014-10-24 16:44:51 -0400397 int(max(latency_end_to_end_list))
andrewonlabc15c9582014-10-24 16:35:52 -0400398 latency_end_to_end_min = \
andrewonlabee4efeb2014-10-24 16:44:51 -0400399 int(min(latency_end_to_end_list))
andrewonlabc15c9582014-10-24 16:35:52 -0400400 latency_end_to_end_avg = \
andrewonlabc90667c2014-10-24 16:48:28 -0400401 (int(sum(latency_end_to_end_list)) / \
andrewonlabc15c9582014-10-24 16:35:52 -0400402 len(latency_end_to_end_list))
403
404 latency_ofp_to_graph_max = \
andrewonlabee4efeb2014-10-24 16:44:51 -0400405 int(max(latency_ofp_to_graph_list))
andrewonlabc15c9582014-10-24 16:35:52 -0400406 latency_ofp_to_graph_min = \
andrewonlabee4efeb2014-10-24 16:44:51 -0400407 int(min(latency_ofp_to_graph_list))
andrewonlabc15c9582014-10-24 16:35:52 -0400408 latency_ofp_to_graph_avg = \
andrewonlabee4efeb2014-10-24 16:44:51 -0400409 (int(sum(latency_ofp_to_graph_list)) / \
andrewonlabc15c9582014-10-24 16:35:52 -0400410 len(latency_ofp_to_graph_list))
411
412 latency_ofp_to_device_max = \
andrewonlabee4efeb2014-10-24 16:44:51 -0400413 int(max(latency_ofp_to_device_list))
andrewonlabc15c9582014-10-24 16:35:52 -0400414 latency_ofp_to_device_min = \
andrewonlabee4efeb2014-10-24 16:44:51 -0400415 int(min(latency_ofp_to_device_list))
andrewonlabc15c9582014-10-24 16:35:52 -0400416 latency_ofp_to_device_avg = \
andrewonlabee4efeb2014-10-24 16:44:51 -0400417 (int(sum(latency_ofp_to_device_list)) / \
andrewonlabc15c9582014-10-24 16:35:52 -0400418 len(latency_ofp_to_device_list))
419
420 latency_t0_to_device_max = \
andrewonlabee4efeb2014-10-24 16:44:51 -0400421 float(max(latency_t0_to_device_list))
andrewonlabc15c9582014-10-24 16:35:52 -0400422 latency_t0_to_device_min = \
andrewonlabee4efeb2014-10-24 16:44:51 -0400423 float(min(latency_t0_to_device_list))
andrewonlabc15c9582014-10-24 16:35:52 -0400424 latency_t0_to_device_avg = \
andrewonlabee4efeb2014-10-24 16:44:51 -0400425 (float(sum(latency_t0_to_device_list)) / \
andrewonlabc15c9582014-10-24 16:35:52 -0400426 len(latency_ofp_to_device_list))
427
428 main.log.report("Switch add - End-to-end latency: \n"+\
429 "Min: "+str(latency_end_to_end_min)+"\n"+\
430 "Max: "+str(latency_end_to_end_max)+"\n"+\
431 "Avg: "+str(latency_end_to_end_avg))
432 main.log.report("Switch add - OFP-to-Graph latency: \n"+\
433 "Min: "+str(latency_ofp_to_graph_min)+"\n"+\
434 "Max: "+str(latency_ofp_to_graph_max)+"\n"+\
435 "Avg: "+str(latency_ofp_to_graph_avg))
436 main.log.report("Switch add - OFP-to-Device latency: \n"+\
437 "Min: "+str(latency_ofp_to_device_min)+"\n"+\
438 "Max: "+str(latency_ofp_to_device_max)+"\n"+\
439 "Avg: "+str(latency_ofp_to_device_avg))
440 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']
470
471 #Number of iterations of case
472 num_iter = main.params['TEST']['numIter']
473
474 #Timestamp 'keys' for json metrics output.
475 #These are subject to change, hence moved into params
476 deviceTimestamp = main.params['JSON']['deviceTimestamp']
477 graphTimestamp = main.params['JSON']['graphTimestamp']
478
479 #NOTE: Some hardcoded variables you may need to configure
480 # besides the params
481
andrewonlab8d29f122014-10-22 17:15:04 -0400482 tshark_port_status = "OFP 130 Port Status"
483
484 tshark_port_up = "/tmp/tshark_port_up.txt"
485 tshark_port_down = "/tmp/tshark_port_down.txt"
andrewonlab393531a2014-10-27 18:36:26 -0400486 interface_config = "s1-eth1"
andrewonlab8d29f122014-10-22 17:15:04 -0400487
488 main.log.report("Port enable / disable latency")
489
andrewonlab393531a2014-10-27 18:36:26 -0400490 main.step("Assign switches s1 and s2 to controller 1")
andrewonlab8d29f122014-10-22 17:15:04 -0400491 main.Mininet1.assign_sw_controller(sw="1",ip1=ONOS1_ip,
492 port1=default_sw_port)
andrewonlab393531a2014-10-27 18:36:26 -0400493 main.Mininet1.assign_sw_controller(sw="2",ip1=ONOS1_ip,
494 port1=default_sw_port)
andrewonlab8d29f122014-10-22 17:15:04 -0400495
496 main.step("Verify switch is assigned correctly")
497 result_s1 = main.Mininet1.get_sw_controller(sw="s1")
andrewonlab393531a2014-10-27 18:36:26 -0400498 result_s2 = main.Mininet1.get_sw_controller(sw="s2")
499 if result_s1 == main.FALSE or result_s2 == main.FALSE:
andrewonlab8d29f122014-10-22 17:15:04 -0400500 main.log.info("Switch s1 was not assigned correctly")
501 assertion = main.FALSE
502 else:
503 main.log.info("Switch s1 was assigned correctly")
504
andrewonlab393531a2014-10-27 18:36:26 -0400505 port_up_device_to_ofp_list = []
506 port_up_graph_to_ofp_list = []
507 port_down_device_to_ofp_list = []
508 port_down_graph_to_ofp_list = []
509
andrewonlab8d29f122014-10-22 17:15:04 -0400510 for i in range(0, int(num_iter)):
511 main.step("Starting wireshark capture for port status down")
512 main.ONOS1.tshark_grep(tshark_port_status,
513 tshark_port_down)
514
515 time.sleep(10)
516
andrewonlab393531a2014-10-27 18:36:26 -0400517 #Disable interface that is connected to switch 2
518 main.step("Disable port: "+interface_config)
519 main.Mininet2.handle.sendline("sudo ifconfig "+
520 interface_config+" down")
andrewonlab8d29f122014-10-22 17:15:04 -0400521 main.Mininet2.handle.expect("\$")
522 time.sleep(20)
523
524 main.ONOS1.tshark_stop()
525 time.sleep(5)
526
527 #Copy tshark output file from ONOS to TestON instance
528 #/tmp directory
529 os.system("scp "+ONOS_user+"@"+ONOS1_ip+":"+
530 tshark_port_down+" /tmp/")
531
532 f_port_down = open(tshark_port_down, 'r')
andrewonlab393531a2014-10-27 18:36:26 -0400533 #Get first line of port down event from tshark
andrewonlab8d29f122014-10-22 17:15:04 -0400534 f_line = f_port_down.readline()
535 obj_down = f_line.split(" ")
536 if len(f_line) > 0:
andrewonlab393531a2014-10-27 18:36:26 -0400537 timestamp_begin_pt_down = int(float(obj_down[1]))*1000
538 main.log.info("Port down begin timestamp: "+
539 str(timestamp_begin_pt_down))
andrewonlab8d29f122014-10-22 17:15:04 -0400540 else:
541 main.log.info("Tshark output file returned unexpected"+
andrewonlab393531a2014-10-27 18:36:26 -0400542 " results: "+str(obj_down))
andrewonlab8d29f122014-10-22 17:15:04 -0400543 timestamp_begin_pt_down = 0
andrewonlab393531a2014-10-27 18:36:26 -0400544
545 f_port_down.close()
andrewonlab8d29f122014-10-22 17:15:04 -0400546
andrewonlab4e124482014-11-04 13:37:25 -0500547 main.log.info("TEST tshark obj: "+str(obj_down))
548
andrewonlab8d29f122014-10-22 17:15:04 -0400549 main.step("Obtain t1 by REST call")
andrewonlab393531a2014-10-27 18:36:26 -0400550 json_str_1 = main.ONOS1cli.topology_events_metrics()
551 json_str_2 = main.ONOS2cli.topology_events_metrics()
552 json_str_3 = main.ONOS3cli.topology_events_metrics()
andrewonlab8d29f122014-10-22 17:15:04 -0400553
andrewonlab4e124482014-11-04 13:37:25 -0500554 main.log.info("TEST json_str 1: "+str(json_str_1))
555
andrewonlab393531a2014-10-27 18:36:26 -0400556 json_obj_1 = json.loads(json_str_1)
557 json_obj_2 = json.loads(json_str_2)
558 json_obj_3 = json.loads(json_str_3)
andrewonlab8d29f122014-10-22 17:15:04 -0400559
andrewonlab393531a2014-10-27 18:36:26 -0400560 time.sleep(5)
561
562 #Obtain graph timestamp. This timestsamp captures
563 #the epoch time at which the topology graph was updated.
564 graph_timestamp_1 = \
565 json_obj_1[graphTimestamp]['value']
566 graph_timestamp_2 = \
567 json_obj_2[graphTimestamp]['value']
568 graph_timestamp_3 = \
569 json_obj_3[graphTimestamp]['value']
570
andrewonlab393531a2014-10-27 18:36:26 -0400571 #Obtain device timestamp. This timestamp captures
572 #the epoch time at which the device event happened
573 device_timestamp_1 = \
574 json_obj_1[deviceTimestamp]['value']
575 device_timestamp_2 = \
576 json_obj_2[deviceTimestamp]['value']
577 device_timestamp_3 = \
578 json_obj_3[deviceTimestamp]['value']
andrewonlab393531a2014-10-27 18:36:26 -0400579
580 #Get delta between graph event and OFP
581 pt_down_graph_to_ofp_1 = int(graph_timestamp_1) -\
582 int(timestamp_begin_pt_down)
583 pt_down_graph_to_ofp_2 = int(graph_timestamp_2) -\
584 int(timestamp_begin_pt_down)
585 pt_down_graph_to_ofp_3 = int(graph_timestamp_3) -\
586 int(timestamp_begin_pt_down)
587
588 #Get delta between device event and OFP
589 pt_down_device_to_ofp_1 = int(device_timestamp_1) -\
590 int(timestamp_begin_pt_down)
591 pt_down_device_to_ofp_2 = int(device_timestamp_2) -\
592 int(timestamp_begin_pt_down)
593 pt_down_device_to_ofp_3 = int(device_timestamp_3) -\
594 int(timestamp_begin_pt_down)
595
596 #Caluclate average across clusters
597 pt_down_graph_to_ofp_avg =\
598 (int(pt_down_graph_to_ofp_1) +
599 int(pt_down_graph_to_ofp_2) +
600 int(pt_down_graph_to_ofp_3)) / 3
601 pt_down_device_to_ofp_avg = \
602 (int(pt_down_device_to_ofp_1) +
603 int(pt_down_device_to_ofp_2) +
604 int(pt_down_device_to_ofp_3)) / 3
605
andrewonlab4e124482014-11-04 13:37:25 -0500606 if pt_down_graph_to_ofp_avg > 0.0 and \
andrewonlab393531a2014-10-27 18:36:26 -0400607 pt_down_graph_to_ofp_avg < 1000:
608 port_down_graph_to_ofp_list.append(
609 pt_down_graph_to_ofp_avg)
610 else:
611 main.log.info("Average port down graph-to-ofp result" +
612 " exceeded the threshold: "+
613 str(pt_down_graph_to_ofp_avg))
614
andrewonlab3622beb2014-10-28 16:07:56 -0400615 if pt_down_device_to_ofp_avg > 0 and \
616 pt_down_device_to_ofp_avg < 1000:
617 port_down_device_to_ofp_list.append(
618 pt_down_device_to_ofp_avg)
619 else:
620 main.log.info("Average port down device-to-ofp result" +
621 " exceeded the threshold: "+
622 str(pt_down_device_to_ofp_avg))
623
andrewonlab4e124482014-11-04 13:37:25 -0500624 main.log.info("Port down: graph to ofp avg: "+
625 str(pt_down_graph_to_ofp_avg) + " ms")
626 main.log.info("Port down: device to ofp avg: "+
627 str(pt_down_device_to_ofp_avg) + " ms")
andrewonlab393531a2014-10-27 18:36:26 -0400628
andrewonlab8d29f122014-10-22 17:15:04 -0400629 #Port up events
630 main.step("Enable port and obtain timestamp")
631 main.step("Starting wireshark capture for port status up")
632 main.ONOS1.tshark_grep("OFP 130 Port Status", tshark_port_up)
633 time.sleep(10)
634
andrewonlab393531a2014-10-27 18:36:26 -0400635 main.Mininet2.handle.sendline("sudo ifconfig "+
636 interface_config+" up")
andrewonlab8d29f122014-10-22 17:15:04 -0400637 main.Mininet2.handle.expect("\$")
638 time.sleep(20)
639
640 os.system("scp "+ONOS_user+"@"+ONOS1_ip+":"+
641 tshark_port_up+" /tmp/")
642
643 f_port_up = open(tshark_port_up, 'r')
andrewonlab393531a2014-10-27 18:36:26 -0400644 f_line = f_port_up.readline()
andrewonlab8d29f122014-10-22 17:15:04 -0400645 obj_up = f_line.split(" ")
646 if len(f_line) > 0:
andrewonlab393531a2014-10-27 18:36:26 -0400647 timestamp_begin_pt_up = int(float(obj_up[1]))*1000
648 main.log.info("Port up begin timestamp: "+
649 str(timestamp_begin_pt_up))
andrewonlab8d29f122014-10-22 17:15:04 -0400650 else:
651 main.log.info("Tshark output file returned unexpected"+
652 " results.")
653 timestamp_begin_pt_up = 0
654
andrewonlab393531a2014-10-27 18:36:26 -0400655 f_port_up.close()
656
andrewonlab8d29f122014-10-22 17:15:04 -0400657 main.step("Obtain t1 by REST call")
andrewonlab393531a2014-10-27 18:36:26 -0400658 json_str_1 = main.ONOS1cli.topology_events_metrics()
659 json_str_2 = main.ONOS2cli.topology_events_metrics()
660 json_str_3 = main.ONOS3cli.topology_events_metrics()
andrewonlab8d29f122014-10-22 17:15:04 -0400661
andrewonlab393531a2014-10-27 18:36:26 -0400662 json_obj_1 = json.loads(json_str_1)
663 json_obj_2 = json.loads(json_str_2)
664 json_obj_3 = json.loads(json_str_3)
andrewonlab8d29f122014-10-22 17:15:04 -0400665
andrewonlab393531a2014-10-27 18:36:26 -0400666 #Obtain graph timestamp. This timestsamp captures
667 #the epoch time at which the topology graph was updated.
668 graph_timestamp_1 = \
669 json_obj_1[graphTimestamp]['value']
670 graph_timestamp_2 = \
671 json_obj_2[graphTimestamp]['value']
672 graph_timestamp_3 = \
673 json_obj_3[graphTimestamp]['value']
674
675 #Obtain device timestamp. This timestamp captures
676 #the epoch time at which the device event happened
677 device_timestamp_1 = \
678 json_obj_1[deviceTimestamp]['value']
679 device_timestamp_2 = \
680 json_obj_2[deviceTimestamp]['value']
681 device_timestamp_3 = \
682 json_obj_3[deviceTimestamp]['value']
683
684 #Get delta between graph event and OFP
685 pt_up_graph_to_ofp_1 = int(graph_timestamp_1) -\
andrewonlab8d29f122014-10-22 17:15:04 -0400686 int(timestamp_begin_pt_up)
andrewonlab393531a2014-10-27 18:36:26 -0400687 pt_up_graph_to_ofp_2 = int(graph_timestamp_2) -\
andrewonlab8d29f122014-10-22 17:15:04 -0400688 int(timestamp_begin_pt_up)
andrewonlab393531a2014-10-27 18:36:26 -0400689 pt_up_graph_to_ofp_3 = int(graph_timestamp_3) -\
690 int(timestamp_begin_pt_up)
691
692 #Get delta between device event and OFP
693 pt_up_device_to_ofp_1 = int(device_timestamp_1) -\
694 int(timestamp_begin_pt_up)
695 pt_up_device_to_ofp_2 = int(device_timestamp_2) -\
696 int(timestamp_begin_pt_up)
697 pt_up_device_to_ofp_3 = int(device_timestamp_3) -\
andrewonlab8d29f122014-10-22 17:15:04 -0400698 int(timestamp_begin_pt_up)
andrewonlab3622beb2014-10-28 16:07:56 -0400699
700 pt_up_graph_to_ofp_avg = \
701 (float(pt_up_graph_to_ofp_1) +
702 float(pt_up_graph_to_ofp_2) +
703 float(pt_up_graph_to_ofp_3)) / 3
704
705 pt_up_device_to_ofp_avg = \
706 (float(pt_up_device_to_ofp_1) +
707 float(pt_up_device_to_ofp_2) +
708 float(pt_up_device_to_ofp_3)) / 3
709
710 if pt_up_graph_to_ofp_avg > 0 and \
711 pt_up_graph_to_ofp_avg < 1000:
712 port_up_graph_to_ofp_list.append(
713 pt_up_graph_to_ofp_avg)
714 else:
715 main.log.info("Average port up graph-to-ofp result"+
716 " exceeded the threshold: "+
717 str(pt_up_graph_to_ofp_avg))
718
719 if pt_up_device_to_ofp_avg > 0 and \
720 pt_up_device_to_ofp_avg < 1000:
721 port_up_device_to_ofp_list.append(
722 pt_up_device_to_ofp_avg)
723 else:
724 main.log.info("Average port up graph-to-ofp result"+
725 " exceeded the threshold: "+
726 str(pt_up_device_to_ofp_avg))
andrewonlab8d29f122014-10-22 17:15:04 -0400727
andrewonlab3622beb2014-10-28 16:07:56 -0400728 #END ITERATION FOR LOOP
729
730 port_down_graph_to_ofp_min = min(port_down_graph_to_ofp_list)
731 port_down_graph_to_ofp_max = max(port_down_graph_to_ofp_list)
732 port_down_graph_to_ofp_avg = \
733 (sum(port_down_graph_to_ofp_list) /
734 len(port_down_graph_to_ofp_list))
735
736 main.log.report("Port up graph-to-ofp Min: ")
737 main.log.report("Port up graph-to-ofp Max: ")
738 main.log.report("Port up graph-to-ofp Avg: ")
andrewonlab8d29f122014-10-22 17:15:04 -0400739
andrewonlab3622beb2014-10-28 16:07:56 -0400740 def CASE4(self, main):
741 '''
742 Link down event using loss rate 100%
andrewonlab53b641c2014-10-31 19:44:44 -0400743
744 Important:
745 Use a simple 2 switch topology with 1 link between
746 the two switches. Ensure that mac addresses of the
747 switches are 1 / 2 respectively
andrewonlab3622beb2014-10-28 16:07:56 -0400748 '''
749 import time
750 import subprocess
751 import os
752 import requests
753 import json
754
755 ONOS1_ip = main.params['CTRL']['ip1']
756 ONOS2_ip = main.params['CTRL']['ip2']
757 ONOS3_ip = main.params['CTRL']['ip3']
758 ONOS_user = main.params['CTRL']['user']
759
760 default_sw_port = main.params['CTRL']['port1']
761
762 #Number of iterations of case
763 num_iter = main.params['TEST']['numIter']
764
765 #Timestamp 'keys' for json metrics output.
766 #These are subject to change, hence moved into params
767 deviceTimestamp = main.params['JSON']['deviceTimestamp']
768 linkTimestamp = main.params['JSON']['linkTimestamp']
andrewonlab53b641c2014-10-31 19:44:44 -0400769 graphTimestamp = main.params['JSON']['graphTimestamp']
770
andrewonlab3622beb2014-10-28 16:07:56 -0400771 assertion = main.TRUE
772 #Link event timestamp to system time list
773 link_down_link_to_system_list = []
774 link_up_link_to_system_list = []
775 #Graph event timestamp to system time list
776 link_down_graph_to_system_list = []
777 link_up_graph_to_system_list = []
778
779 main.log.report("Add / remove link latency between "+
780 "two switches")
781
782 main.step("Assign all switches")
783 main.Mininet1.assign_sw_controller(sw="1",
784 ip1=ONOS1_ip, port1=default_sw_port)
785 main.Mininet1.assign_sw_controller(sw="2",
786 ip1=ONOS1_ip, port1=default_sw_port)
787
788 main.step("Verifying switch assignment")
789 result_s1 = main.Mininet1.get_sw_controller(sw="s1")
790 result_s2 = main.Mininet1.get_sw_controller(sw="s2")
andrewonlab3622beb2014-10-28 16:07:56 -0400791
792 #Allow time for events to finish before taking measurements
793 time.sleep(10)
794
andrewonlab53b641c2014-10-31 19:44:44 -0400795 link_down = False
andrewonlab3622beb2014-10-28 16:07:56 -0400796 #Start iteration of link event test
797 for i in range(0, int(num_iter)):
798 main.step("Getting initial system time as t0")
andrewonlab8d29f122014-10-22 17:15:04 -0400799
andrewonlab3622beb2014-10-28 16:07:56 -0400800 timestamp_link_down_t0 = time.time() * 1000
801 #Link down is simulated by 100% loss rate using traffic
802 #control command
803 main.Mininet1.handle.sendline(
804 "sh tc qdisc add dev s1-eth1 root netem loss 100%")
805
andrewonlab53b641c2014-10-31 19:44:44 -0400806 #TODO: Iterate through 'links' command to verify that
807 # link s1 -> s2 went down (timeout 30 seconds)
808 main.log.info("Checking ONOS for link update")
809 loop_count = 0
810 while( not link_down and loop_count < 30 ):
811 json_str = main.ONOS1cli.links()
812 if not json_str:
813 break
814 else:
815 json_obj = json.loads(json_str)
816 for obj in json_obj:
817 if '01' not in obj['src']['device']:
818 link_down = True
819 main.log.report("Link down from "+
820 "s1 -> s2 detected")
821 loop_count += 1
822 time.sleep(1)
823
824 #Give time for metrics measurement to catch up
825 time.sleep(10)
826 #If we exited the while loop and link down is still
827 #false, then ONOS has failed to discover link down event
828 if not link_down:
829 main.log.info("Link down discovery failed")
830
831 link_down_lat_graph1 = 0
832 link_down_lat_graph2 = 0
833 link_down_lat_graph3 = 0
834 link_down_lat_device1 = 0
835 link_down_lat_device2 = 0
836 link_down_lat_device3 = 0
837
838 assertion = main.FALSE
839 else:
840 json_topo_metrics_1 =\
841 main.ONOS1cli.topology_events_metrics()
842 json_topo_metrics_2 =\
843 main.ONOS2cli.topology_events_metrics()
844 json_topo_metrics_3 =\
845 main.ONOS3cli.topology_events_metrics()
846 json_topo_metrics_1 = json.loads(json_topo_metrics_1)
847 json_topo_metrics_2 = json.loads(json_topo_metrics_2)
848 json_topo_metrics_3 = json.loads(json_topo_metrics_3)
849
850 main.log.info("Obtaining graph and device timestamp")
851 graph_timestamp_1 = \
852 json_topo_metrics_1[graphTimestamp]['value']
853 graph_timestamp_2 = \
854 json_topo_metrics_2[graphTimestamp]['value']
855 graph_timestamp_3 = \
856 json_topo_metrics_3[graphTimestamp]['value']
857
858 link_timestamp_1 = \
859 json_topo_metrics_1[linkTimestamp]['value']
860 link_timestamp_2 = \
861 json_topo_metrics_2[linkTimestamp]['value']
862 link_timestamp_3 = \
863 json_topo_metrics_3[linkTimestamp]['value']
864
865 if graph_timestamp_1 and graph_timestamp_2 and\
866 graph_timestamp_3 and link_timestamp_1 and\
867 link_timestamp_2 and link_timestamp_3:
868 link_down_lat_graph1 = int(graph_timestamp_1) -\
869 timestamp_link_down_t0
870 link_down_lat_graph2 = int(graph_timestamp_2) -\
871 timestamp_link_down_t0
872 link_down_lat_graph3 = int(graph_timestamp_3) -\
873 timestamp_link_down_t0
874
875 link_down_lat_link1 = int(link_timestamp_1) -\
876 timestamp_link_down_t0
877 link_down_lat_link2 = int(link_timestamp_2) -\
878 timestamp_link_down_t0
879 link_down_lat_link3 = int(link_timestamp_3) -\
880 timestamp_link_down_t0
881 else:
882 main.log.error("There was an error calculating"+
883 " the delta for link down event")
884 link_down_lat_graph1 = 0
885 link_down_lat_graph2 = 0
886 link_down_lat_graph3 = 0
887
888 link_down_lat_device1 = 0
889 link_down_lat_device2 = 0
890 link_down_lat_device3 = 0
891
andrewonlab4e124482014-11-04 13:37:25 -0500892 main.log.report("Link down latency ONOS1 iteration "+
893 str(i)+" (end-to-end): "+
894 str(link_down_lat_graph1))
895 main.log.report("Link down latency ONOS2 iteration "+
896 str(i)+" (end-to-end): "+
897 str(link_down_lat_graph2))
898 main.log.report("Link down latency ONOS3 iteration "+
899 str(i)+" (end-to-end): "+
900 str(link_down_lat_graph3))
901
902 main.log.report("Link down latency ONOS1 iteration "+
903 str(i)+" (link-event-to-system-timestamp): "+
904 str(link_down_lat_link1))
905 main.log.report("Link down latency ONOS2 iteration "+
906 str(i)+" (link-event-to-system-timestamp): "+
907 str(link_down_lat_link2))
908 main.log.report("Link down latency ONOS3 iteration "+
909 str(i)+" (link-event-to-system-timestamp): "+
910 str(link_down_lat_link3))
911
912 #Calculate avg of node calculations
913 link_down_lat_graph_avg =\
914 (link_down_lat_graph_1 +
915 link_down_lat_graph_2 +
916 link_down_lat_graph_3) / 3.0
917 link_down_lat_link_avg =\
918 (link_down_lat_link_1 +
919 link_down_lat_link_2 +
920 link_down_lat_link_3) / 3.0
andrewonlab53b641c2014-10-31 19:44:44 -0400921
andrewonlab4e124482014-11-04 13:37:25 -0500922 #Set threshold and append latency to list
923 if link_down_lat_graph_avg > 0.0 and\
924 link_down_lat_graph_avg < 30000:
925 link_down_graph_to_system_list.append(
926 link_down_lat_graph_avg)
927 if link_down_lat_link_avg > 0.0 and\
928 link_down_lat_link_avg < 30000:
929 link_down_link_to_system_list.append(
930 link_down_lat_link_avg)
andrewonlab53b641c2014-10-31 19:44:44 -0400931
932 #NOTE: To remove loss rate and measure latency:
933 # 'sh tc qdisc del dev s1-eth1 root'
934 main.Mininet1.handle.sendline("sh tc qdisc del dev "+
935 "s1-eth1 root")
936 main.Mininet1.handle.expect("mininet>")
937
andrewonlab4e124482014-11-04 13:37:25 -0500938 #Calculate min, max, avg of list and report
939 link_down_min = min(link_down_graph_to_system_list)
940 link_down_max = max(link_down_graph_to_system_list)
941 link_down_avg = sum(link_down_graph_to_system_list) / \
942 len(link_down_graph_to_system_list)
943
andrewonlabb54b85b2014-10-28 18:43:57 -0400944 def CASE5(self, main):
945 '''
946 100 Switch discovery latency
947
948 Important:
949 If a simple topology was used in previous cases,
950 you will need to change the topology file in the
951 params for this case to proceed
andrewonlab16ce4852014-10-30 13:41:09 -0400952
953 This test case can be potentially dangerous if
954 your machine has previously set iptables rules.
955 One of the steps of the test case will flush
956 all existing iptables rules.
andrewonlabb54b85b2014-10-28 18:43:57 -0400957 '''
958 import time
959 import subprocess
960 import os
961 import requests
962 import json
963
964 ONOS1_ip = main.params['CTRL']['ip1']
965 ONOS2_ip = main.params['CTRL']['ip2']
966 ONOS3_ip = main.params['CTRL']['ip3']
967 MN1_ip = main.params['MN']['ip1']
968 ONOS_user = main.params['CTRL']['user']
969
970 default_sw_port = main.params['CTRL']['port1']
971
972 #Number of iterations of case
973 num_iter = main.params['TEST']['numIter']
andrewonlab16ce4852014-10-30 13:41:09 -0400974 num_sw = main.params['TEST']['numSwitch']
975
andrewonlabb54b85b2014-10-28 18:43:57 -0400976 #Timestamp 'keys' for json metrics output.
977 #These are subject to change, hence moved into params
978 deviceTimestamp = main.params['JSON']['deviceTimestamp']
andrewonlab16ce4852014-10-30 13:41:09 -0400979 graphTimestamp = main.params['JSON']['graphTimestamp']
980
andrewonlab53b641c2014-10-31 19:44:44 -0400981 tshark_ofp_output = "/tmp/tshark_ofp_"+num_sw+"sw.txt"
982 tshark_tcp_output = "/tmp/tshark_tcp_"+num_sw+"sw.txt"
983
984 tshark_ofp_result_list = []
985 tshark_tcp_result_list = []
andrewonlabb54b85b2014-10-28 18:43:57 -0400986
andrewonlab16ce4852014-10-30 13:41:09 -0400987 main.case(num_sw+" Switch discovery latency")
andrewonlabb54b85b2014-10-28 18:43:57 -0400988 main.step("Assigning all switches to ONOS1")
andrewonlab16ce4852014-10-30 13:41:09 -0400989 for i in range(1, int(num_sw)+1):
andrewonlabb54b85b2014-10-28 18:43:57 -0400990 main.Mininet1.assign_sw_controller(
991 sw=str(i),
992 ip1=ONOS1_ip,
993 port1=default_sw_port)
andrewonlab16ce4852014-10-30 13:41:09 -0400994
andrewonlabb54b85b2014-10-28 18:43:57 -0400995 #Ensure that nodes are configured with ptpd
andrewonlab16ce4852014-10-30 13:41:09 -0400996 #Just a warning message
997 main.log.info("Please check ptpd configuration to ensure"+\
998 " All nodes' system times are in sync")
999 time.sleep(5)
andrewonlabb54b85b2014-10-28 18:43:57 -04001000
1001 for i in range(0, int(num_iter)):
andrewonlab8d29f122014-10-22 17:15:04 -04001002
andrewonlabb54b85b2014-10-28 18:43:57 -04001003 main.step("Set iptables rule to block incoming sw connections")
1004 #Set iptables rule to block incoming switch connections
andrewonlab53b641c2014-10-31 19:44:44 -04001005 #The rule description is as follows:
1006 # Append to INPUT rule,
1007 # behavior DROP that matches following:
1008 # * packet type: tcp
1009 # * source IP: MN1_ip
1010 # * destination PORT: 6633
andrewonlabb54b85b2014-10-28 18:43:57 -04001011 main.ONOS1.handle.sendline(
andrewonlab16ce4852014-10-30 13:41:09 -04001012 "sudo iptables -A INPUT -p tcp -s "+MN1_ip+
andrewonlabb54b85b2014-10-28 18:43:57 -04001013 " --dport "+default_sw_port+" -j DROP")
1014 main.ONOS1.handle.expect("\$")
andrewonlab53b641c2014-10-31 19:44:44 -04001015 # Append to OUTPUT rule,
1016 # behavior DROP that matches following:
1017 # * packet type: tcp
1018 # * source IP: MN1_ip
1019 # * destination PORT: 6633
1020 main.ONOS1.handle.sendline(
1021 "sudo iptables -A OUTPUT -p tcp -s "+MN1_ip+
1022 " --dport "+default_sw_port+" -j DROP")
1023 main.ONOS1.handle.expect("\$")
andrewonlabb54b85b2014-10-28 18:43:57 -04001024 #Give time to allow rule to take effect
andrewonlab16ce4852014-10-30 13:41:09 -04001025 main.log.info("Please wait for switch connection to "+
1026 "time out")
1027 time.sleep(60)
1028
1029 #Gather vendor OFP with tshark
1030 main.ONOS1.tshark_grep("OFP 86 Vendor",
1031 tshark_ofp_output)
andrewonlab53b641c2014-10-31 19:44:44 -04001032 main.ONOS1.tshark_grep("TCP 74 ",
1033 tshark_tcp_output)
andrewonlabb54b85b2014-10-28 18:43:57 -04001034
andrewonlab16ce4852014-10-30 13:41:09 -04001035 #NOTE: Remove all iptables rule quickly (flush)
andrewonlabb54b85b2014-10-28 18:43:57 -04001036 # Before removal, obtain TestON timestamp at which
andrewonlab16ce4852014-10-30 13:41:09 -04001037 # removal took place
1038 # (ensuring nodes are configured via ptp)
andrewonlabb54b85b2014-10-28 18:43:57 -04001039 # sudo iptables -F
andrewonlab16ce4852014-10-30 13:41:09 -04001040
1041 t0_system = time.time() * 1000
1042 main.ONOS1.handle.sendline(
1043 "sudo iptables -F")
andrewonlabb54b85b2014-10-28 18:43:57 -04001044
andrewonlab16ce4852014-10-30 13:41:09 -04001045 #Counter to track loop count
1046 counter_loop = 0
1047 counter_avail1 = 0
1048 counter_avail2 = 0
1049 counter_avail3 = 0
1050 onos1_dev = False
1051 onos2_dev = False
1052 onos3_dev = False
1053 while counter_loop < 60:
1054 #Continue to check devices for all device
1055 #availability. When all devices in all 3
1056 #ONOS instances indicate that devices are available
1057 #obtain graph event timestamp for t1.
1058 device_str_obj1 = main.ONOS1cli.devices()
1059 device_str_obj2 = main.ONOS2cli.devices()
1060 device_str_obj3 = main.ONOS3cli.devices()
1061
1062 device_json1 = json.loads(device_str_obj1)
1063 device_json2 = json.loads(device_str_obj2)
1064 device_json3 = json.loads(device_str_obj3)
1065
1066 for device1 in device_json1:
1067 if device1['available'] == True:
1068 counter_avail1 += 1
1069 if counter_avail1 == int(num_sw):
1070 onos1_dev = True
1071 main.log.info("All devices have been "+
1072 "discovered on ONOS1")
1073 else:
1074 counter_avail1 = 0
1075 for device2 in device_json2:
1076 if device2['available'] == True:
1077 counter_avail2 += 1
1078 if counter_avail2 == int(num_sw):
1079 onos2_dev = True
1080 main.log.info("All devices have been "+
1081 "discovered on ONOS2")
1082 else:
1083 counter_avail2 = 0
1084 for device3 in device_json3:
1085 if device3['available'] == True:
1086 counter_avail3 += 1
1087 if counter_avail3 == int(num_sw):
1088 onos3_dev = True
1089 main.log.info("All devices have been "+
1090 "discovered on ONOS3")
1091 else:
1092 counter_avail3 = 0
1093
1094 if onos1_dev and onos2_dev and onos3_dev:
1095 main.log.info("All devices have been discovered "+
1096 "on all ONOS instances")
1097 json_str_topology_metrics_1 =\
1098 main.ONOS1cli.topology_events_metrics()
1099 json_str_topology_metrics_2 =\
1100 main.ONOS2cli.topology_events_metrics()
1101 json_str_topology_metrics_3 =\
1102 main.ONOS3cli.topology_events_metrics()
andrewonlab53b641c2014-10-31 19:44:44 -04001103
1104 #Exit while loop if all devices discovered
andrewonlab16ce4852014-10-30 13:41:09 -04001105 break
1106
1107 counter_loop += 1
1108 #Give some time in between CLI calls
1109 #(will not affect measurement)
1110 time.sleep(3)
1111
1112 main.ONOS1.tshark_stop()
1113
1114 os.system("scp "+ONOS_user+"@"+ONOS1_ip+":"+
1115 tshark_ofp_output+" /tmp/")
andrewonlab53b641c2014-10-31 19:44:44 -04001116 os.system("scp "+ONOS_user+"@"+ONOS1_ip+":"+
1117 tshark_tcp_output+" /tmp/")
andrewonlab16ce4852014-10-30 13:41:09 -04001118 ofp_file = open(tshark_ofp_output, 'r')
1119
1120 #The following is for information purpose only.
1121 #TODO: Automate OFP output analysis
1122 main.log.info("Tshark OFP Vendor output: ")
1123 for line in ofp_file:
andrewonlab53b641c2014-10-31 19:44:44 -04001124 tshark_ofp_result_list.append(line)
andrewonlab16ce4852014-10-30 13:41:09 -04001125 main.log.info(line)
1126
andrewonlab53b641c2014-10-31 19:44:44 -04001127 ofp_file.close()
1128
1129 tcp_file = open(tshark_tcp_output, 'r')
1130 main.log.info("Tshark TCP 74 output: ")
1131 for line in tcp_file:
1132 tshark_tcp_result_list.append(line)
1133 main.log.info(line)
1134
1135 tcp_file.close()
1136
andrewonlab16ce4852014-10-30 13:41:09 -04001137 json_obj_1 = json.loads(json_str_topology_metrics_1)
1138 json_obj_2 = json.loads(json_str_topology_metrics_2)
1139 json_obj_3 = json.loads(json_str_topology_metrics_3)
1140
1141 graph_timestamp_1 = \
1142 json_obj_1[graphTimestamp]['value']
1143 graph_timestamp_2 = \
1144 json_obj_2[graphTimestamp]['value']
1145 graph_timestamp_3 = \
1146 json_obj_3[graphTimestamp]['value']
1147
1148 main.log.info(
1149 int(graph_timestamp_1) - int(t0_system))
1150 main.log.info(
1151 int(graph_timestamp_2) - int(t0_system))
1152 main.log.info(
1153 int(graph_timestamp_3) - int(t0_system))
1154
1155
1156
1157
1158
1159
andrewonlabb54b85b2014-10-28 18:43:57 -04001160