blob: 3e0a0552f95a4f59c818ad3cbb53f289b671e09a [file] [log] [blame]
Jon Hall73cf9cc2014-11-20 22:28:38 -08001'''
2Description: This test is to determine if ONOS can handle
3 all of it's nodes restarting
4
5List of test cases:
6CASE1: Compile ONOS and push it to the test machines
7CASE2: Assign mastership to controllers
8CASE3: Assign intents
9CASE4: Ping across added host intents
10CASE5: Reading state of ONOS
11CASE6: The Failure case.
12CASE7: Check state after control plane failure
13CASE8: Compare topo
14CASE9: Link s3-s28 down
15CASE10: Link s3-s28 up
16CASE11: Switch down
17CASE12: Switch up
18CASE13: Clean up
19'''
20class HATestClusterRestart:
21
22 def __init__(self) :
23 self.default = ''
24
25 def CASE1(self,main) :
26 '''
27 CASE1 is to compile ONOS and push it to the test machines
28
29 Startup sequence:
30 git pull
31 mvn clean install
32 onos-package
33 cell <name>
34 onos-verify-cell
35 NOTE: temporary - onos-remove-raft-logs
36 onos-install -f
37 onos-wait-for-start
38 '''
39 import time
40 main.log.report("ONOS HA test: Restart all ONOS nodes - initialization")
41 main.case("Setting up test environment")
42
43 # load some vairables from the params file
44 PULL_CODE = False
45 if main.params['Git'] == 'True':
46 PULL_CODE = True
47 cell_name = main.params['ENV']['cellName']
48
49 #set global variables
50 global ONOS1_ip
51 global ONOS1_port
52 global ONOS2_ip
53 global ONOS2_port
54 global ONOS3_ip
55 global ONOS3_port
56 global ONOS4_ip
57 global ONOS4_port
58 global ONOS5_ip
59 global ONOS5_port
60 global ONOS6_ip
61 global ONOS6_port
62 global ONOS7_ip
63 global ONOS7_port
64
65 ONOS1_ip = main.params['CTRL']['ip1']
66 ONOS1_port = main.params['CTRL']['port1']
67 ONOS2_ip = main.params['CTRL']['ip2']
68 ONOS2_port = main.params['CTRL']['port2']
69 ONOS3_ip = main.params['CTRL']['ip3']
70 ONOS3_port = main.params['CTRL']['port3']
71 ONOS4_ip = main.params['CTRL']['ip4']
72 ONOS4_port = main.params['CTRL']['port4']
73 ONOS5_ip = main.params['CTRL']['ip5']
74 ONOS5_port = main.params['CTRL']['port5']
75 ONOS6_ip = main.params['CTRL']['ip6']
76 ONOS6_port = main.params['CTRL']['port6']
77 ONOS7_ip = main.params['CTRL']['ip7']
78 ONOS7_port = main.params['CTRL']['port7']
79
80
81 main.step("Applying cell variable to environment")
82 cell_result = main.ONOSbench.set_cell(cell_name)
83 verify_result = main.ONOSbench.verify_cell()
84
Jon Hall94fd0472014-12-08 11:52:42 -080085 #FIXME:this is short term fix
Jon Hall73cf9cc2014-11-20 22:28:38 -080086 main.log.report("Removing raft logs")
87 main.ONOSbench.onos_remove_raft_logs()
88 main.log.report("Uninstalling ONOS")
89 main.ONOSbench.onos_uninstall(ONOS1_ip)
90 main.ONOSbench.onos_uninstall(ONOS2_ip)
91 main.ONOSbench.onos_uninstall(ONOS3_ip)
92 main.ONOSbench.onos_uninstall(ONOS4_ip)
93 main.ONOSbench.onos_uninstall(ONOS5_ip)
94 main.ONOSbench.onos_uninstall(ONOS6_ip)
95 main.ONOSbench.onos_uninstall(ONOS7_ip)
96
97 clean_install_result = main.TRUE
98 git_pull_result = main.TRUE
99
100 main.step("Compiling the latest version of ONOS")
101 if PULL_CODE:
102 main.step("Git checkout and pull master")
103 main.ONOSbench.git_checkout("master")
104 git_pull_result = main.ONOSbench.git_pull()
105
106 main.step("Using mvn clean & install")
107 clean_install_result = main.TRUE
108 if git_pull_result == main.TRUE:
109 clean_install_result = main.ONOSbench.clean_install()
110 else:
111 main.log.warn("Did not pull new code so skipping mvn "+ \
112 "clean install")
113 main.ONOSbench.get_version(report=True)
114
115 main.step("Creating ONOS package")
116 package_result = main.ONOSbench.onos_package()
117
118 main.step("Installing ONOS package")
119 onos1_install_result = main.ONOSbench.onos_install(options="-f",
120 node=ONOS1_ip)
121 onos2_install_result = main.ONOSbench.onos_install(options="-f",
122 node=ONOS2_ip)
123 onos3_install_result = main.ONOSbench.onos_install(options="-f",
124 node=ONOS3_ip)
125 onos4_install_result = main.ONOSbench.onos_install(options="-f",
126 node=ONOS4_ip)
127 onos5_install_result = main.ONOSbench.onos_install(options="-f",
128 node=ONOS5_ip)
129 onos6_install_result = main.ONOSbench.onos_install(options="-f",
130 node=ONOS6_ip)
131 onos7_install_result = main.ONOSbench.onos_install(options="-f",
132 node=ONOS7_ip)
133 onos_install_result = onos1_install_result and onos2_install_result\
134 and onos3_install_result and onos4_install_result\
135 and onos5_install_result and onos6_install_result\
136 and onos7_install_result
137 '''
138 #FIXME: work around until onos is less fragile
139 main.ONOSbench.handle.sendline("onos-cluster-install")
140 print main.ONOSbench.handle.expect("\$")
141 onos_install_result = main.TRUE
142 '''
143
144
145 main.step("Checking if ONOS is up yet")
146 #TODO: Refactor
147 # check bundle:list?
Jon Hall94fd0472014-12-08 11:52:42 -0800148 for i in range(2):
149 onos1_isup = main.ONOSbench.isup(ONOS1_ip)
150 if not onos1_isup:
151 main.log.report("ONOS1 didn't start!")
152 onos2_isup = main.ONOSbench.isup(ONOS2_ip)
153 if not onos2_isup:
154 main.log.report("ONOS2 didn't start!")
155 onos3_isup = main.ONOSbench.isup(ONOS3_ip)
156 if not onos3_isup:
157 main.log.report("ONOS3 didn't start!")
158 onos4_isup = main.ONOSbench.isup(ONOS4_ip)
159 if not onos4_isup:
160 main.log.report("ONOS4 didn't start!")
161 onos5_isup = main.ONOSbench.isup(ONOS5_ip)
162 if not onos5_isup:
163 main.log.report("ONOS5 didn't start!")
164 onos6_isup = main.ONOSbench.isup(ONOS6_ip)
165 if not onos6_isup:
166 main.log.report("ONOS6 didn't start!")
167 onos7_isup = main.ONOSbench.isup(ONOS7_ip)
168 if not onos7_isup:
169 main.log.report("ONOS7 didn't start!")
170 onos_isup_result = onos1_isup and onos2_isup and onos3_isup\
171 and onos4_isup and onos5_isup and onos6_isup and onos7_isup
172 if onos_isup_result == main.TRUE:
173 break
Jon Hall73cf9cc2014-11-20 22:28:38 -0800174 # TODO: if it becomes an issue, we can retry this step a few times
175
176
177 cli_result1 = main.ONOScli1.start_onos_cli(ONOS1_ip)
178 cli_result2 = main.ONOScli2.start_onos_cli(ONOS2_ip)
179 cli_result3 = main.ONOScli3.start_onos_cli(ONOS3_ip)
180 cli_result4 = main.ONOScli4.start_onos_cli(ONOS4_ip)
181 cli_result5 = main.ONOScli5.start_onos_cli(ONOS5_ip)
182 cli_result6 = main.ONOScli6.start_onos_cli(ONOS6_ip)
183 cli_result7 = main.ONOScli7.start_onos_cli(ONOS7_ip)
184 cli_results = cli_result1 and cli_result2 and cli_result3 and\
185 cli_result4 and cli_result5 and cli_result6 and cli_result7
186
187 main.step("Start Packet Capture MN")
188 main.Mininet2.start_tcpdump(
189 str(main.params['MNtcpdump']['folder'])+str(main.TEST)+"-MN.pcap",
190 intf = main.params['MNtcpdump']['intf'],
191 port = main.params['MNtcpdump']['port'])
192
193
194 case1_result = (clean_install_result and package_result and
195 cell_result and verify_result and onos_install_result and
196 onos_isup_result and cli_results)
197
198 utilities.assert_equals(expect=main.TRUE, actual=case1_result,
199 onpass="Test startup successful",
200 onfail="Test startup NOT successful")
201
202
Jon Hall94fd0472014-12-08 11:52:42 -0800203 if case1_result==main.FALSE:
204 main.cleanup()
205 main.exit()
Jon Hall73cf9cc2014-11-20 22:28:38 -0800206
207 def CASE2(self,main) :
208 '''
209 Assign mastership to controllers
210 '''
211 import time
212 import json
213 import re
214
Jon Hall73cf9cc2014-11-20 22:28:38 -0800215 main.log.report("Assigning switches to controllers")
216 main.case("Assigning Controllers")
217 main.step("Assign switches to controllers")
218
219 for i in range (1,29):
220 main.Mininet1.assign_sw_controller(sw=str(i),count=7,
221 ip1=ONOS1_ip,port1=ONOS1_port,
222 ip2=ONOS2_ip,port2=ONOS2_port,
223 ip3=ONOS3_ip,port3=ONOS3_port,
224 ip4=ONOS4_ip,port4=ONOS4_port,
225 ip5=ONOS5_ip,port5=ONOS5_port,
226 ip6=ONOS6_ip,port6=ONOS6_port,
227 ip7=ONOS7_ip,port7=ONOS7_port)
228
229 mastership_check = main.TRUE
230 for i in range (1,29):
231 response = main.Mininet1.get_sw_controller("s"+str(i))
Jon Hallffb386d2014-11-21 13:43:38 -0800232 try:
233 main.log.info(str(response))
234 except:
235 main.log.info(repr(response))
Jon Hall73cf9cc2014-11-20 22:28:38 -0800236 if re.search("tcp:"+ONOS1_ip,response)\
237 and re.search("tcp:"+ONOS2_ip,response)\
238 and re.search("tcp:"+ONOS3_ip,response)\
239 and re.search("tcp:"+ONOS4_ip,response)\
240 and re.search("tcp:"+ONOS5_ip,response)\
241 and re.search("tcp:"+ONOS6_ip,response)\
242 and re.search("tcp:"+ONOS7_ip,response):
243 mastership_check = mastership_check and main.TRUE
244 else:
245 mastership_check = main.FALSE
246 if mastership_check == main.TRUE:
247 main.log.report("Switch mastership assigned correctly")
248 utilities.assert_equals(expect = main.TRUE,actual=mastership_check,
249 onpass="Switch mastership assigned correctly",
250 onfail="Switches not assigned correctly to controllers")
251
Jon Hall94fd0472014-12-08 11:52:42 -0800252 #Manually assign mastership to the controller we want
253 role_call = main.TRUE
254 role_check = main.TRUE
255
256 device_id = main.ONOScli1.get_device("1000")['id']
257 role_call = role_call and main.ONOScli1.device_role(device_id, ONOS1_ip)
258 if ONOS1_ip in main.ONOScli1.get_role(device_id)['master']:
259 role_check = role_check and main.TRUE
260 else:
261 role_check = role_check and main.FALSE
262
263 device_id = main.ONOScli1.get_device("2800")['id']
264 role_call = role_call and main.ONOScli1.device_role(device_id, ONOS1_ip)
265 if ONOS1_ip in main.ONOScli1.get_role(device_id)['master']:
266 role_check = role_check and main.TRUE
267 else:
268 role_check = role_check and main.FALSE
269
270 device_id = main.ONOScli1.get_device("2000")['id']
271 role_call = role_call and main.ONOScli1.device_role(device_id, ONOS2_ip)
272 if ONOS2_ip in main.ONOScli1.get_role(device_id)['master']:
273 role_check = role_check and main.TRUE
274 else:
275 role_check = role_check and main.FALSE
276
277 device_id = main.ONOScli1.get_device("3000")['id']
278 role_call = role_call and main.ONOScli1.device_role(device_id, ONOS2_ip)
279 if ONOS2_ip in main.ONOScli1.get_role(device_id)['master']:
280 role_check = role_check and main.TRUE
281 else:
282 role_check = role_check and main.FALSE
283
284 device_id = main.ONOScli1.get_device("5000")['id']
285 role_call = role_call and main.ONOScli1.device_role(device_id, ONOS3_ip)
286 if ONOS3_ip in main.ONOScli1.get_role(device_id)['master']:
287 role_check = role_check and main.TRUE
288 else:
289 role_check = role_check and main.FALSE
290
291 device_id = main.ONOScli1.get_device("6000")['id']
292 role_call = role_call and main.ONOScli1.device_role(device_id, ONOS3_ip)
293 if ONOS3_ip in main.ONOScli1.get_role(device_id)['master']:
294 role_check = role_check and main.TRUE
295 else:
296 role_check = role_check and main.FALSE
297
298 device_id = main.ONOScli1.get_device("3004")['id']
299 role_call = role_call and main.ONOScli1.device_role(device_id, ONOS4_ip)
300 if ONOS4_ip in main.ONOScli1.get_role(device_id)['master']:
301 role_check = role_check and main.TRUE
302 else:
303 role_check = role_check and main.FALSE
304
305 device_id = main.ONOScli1.get_device("3008")['id']
306 role_call = role_call and main.ONOScli1.device_role(device_id, ONOS5_ip)
307 if ONOS5_ip in main.ONOScli1.get_role(device_id)['master']:
308 role_check = role_check and main.TRUE
309 else:
310 role_check = role_check and main.FALSE
311
312 device_id = main.ONOScli1.get_device("3009")['id']
313 role_call = role_call and main.ONOScli1.device_role(device_id, ONOS5_ip)
314 if ONOS5_ip in main.ONOScli1.get_role(device_id)['master']:
315 role_check = role_check and main.TRUE
316 else:
317 role_check = role_check and main.FALSE
318
319 device_id = main.ONOScli1.get_device("3010")['id']
320 role_call = role_call and main.ONOScli1.device_role(device_id, ONOS5_ip)
321 if ONOS5_ip in main.ONOScli1.get_role(device_id)['master']:
322 role_check = role_check and main.TRUE
323 else:
324 role_check = role_check and main.FALSE
325
326 device_id = main.ONOScli1.get_device("3011")['id']
327 role_call = role_call and main.ONOScli1.device_role(device_id, ONOS5_ip)
328 if ONOS5_ip in main.ONOScli1.get_role(device_id)['master']:
329 role_check = role_check and main.TRUE
330 else:
331 role_check = role_check and main.FALSE
332
333 device_id = main.ONOScli1.get_device("3012")['id']
334 role_call = role_call and main.ONOScli1.device_role(device_id, ONOS5_ip)
335 if ONOS5_ip in main.ONOScli1.get_role(device_id)['master']:
336 role_check = role_check and main.TRUE
337 else:
338 role_check = role_check and main.FALSE
339
340 device_id = main.ONOScli1.get_device("3013")['id']
341 role_call = role_call and main.ONOScli1.device_role(device_id, ONOS5_ip)
342 if ONOS5_ip in main.ONOScli1.get_role(device_id)['master']:
343 role_check = role_check and main.TRUE
344 else:
345 role_check = role_check and main.FALSE
346
347 device_id = main.ONOScli1.get_device("3014")['id']
348 role_call = role_call and main.ONOScli1.device_role(device_id, ONOS5_ip)
349 if ONOS5_ip in main.ONOScli1.get_role(device_id)['master']:
350 role_check = role_check and main.TRUE
351 else:
352 role_check = role_check and main.FALSE
353
354 device_id = main.ONOScli1.get_device("3015")['id']
355 role_call = role_call and main.ONOScli1.device_role(device_id, ONOS5_ip)
356 if ONOS5_ip in main.ONOScli1.get_role(device_id)['master']:
357 role_check = role_check and main.TRUE
358 else:
359 role_check = role_check and main.FALSE
360
361 device_id = main.ONOScli1.get_device("3016")['id']
362 role_call = role_call and main.ONOScli1.device_role(device_id, ONOS5_ip)
363 if ONOS5_ip in main.ONOScli1.get_role(device_id)['master']:
364 role_check = role_check and main.TRUE
365 else:
366 role_check = role_check and main.FALSE
367
368 device_id = main.ONOScli1.get_device("3017")['id']
369 role_call = role_call and main.ONOScli1.device_role(device_id, ONOS5_ip)
370 if ONOS5_ip in main.ONOScli1.get_role(device_id)['master']:
371 role_check = role_check and main.TRUE
372 else:
373 role_check = role_check and main.FALSE
374
375 device_id = main.ONOScli1.get_device("6007")['id']
376 role_call = role_call and main.ONOScli1.device_role(device_id, ONOS6_ip)
377 if ONOS6_ip in main.ONOScli1.get_role(device_id)['master']:
378 role_check = role_check and main.TRUE
379 else:
380 role_check = role_check and main.FALSE
381
382 device_id = main.ONOScli1.get_device("6018")['id']
383 role_call = role_call and main.ONOScli1.device_role(device_id, ONOS7_ip)
384 if ONOS7_ip in main.ONOScli1.get_role(device_id)['master']:
385 role_check = role_check and main.TRUE
386 else:
387 role_check = role_check and main.FALSE
388
389 device_id = main.ONOScli1.get_device("6019")['id']
390 role_call = role_call and main.ONOScli1.device_role(device_id, ONOS7_ip)
391 if ONOS7_ip in main.ONOScli1.get_role(device_id)['master']:
392 role_check = role_check and main.TRUE
393 else:
394 role_check = role_check and main.FALSE
395
396 device_id = main.ONOScli1.get_device("6020")['id']
397 role_call = role_call and main.ONOScli1.device_role(device_id, ONOS7_ip)
398 if ONOS7_ip in main.ONOScli1.get_role(device_id)['master']:
399 role_check = role_check and main.TRUE
400 else:
401 role_check = role_check and main.FALSE
402
403 device_id = main.ONOScli1.get_device("6021")['id']
404 role_call = role_call and main.ONOScli1.device_role(device_id, ONOS7_ip)
405 if ONOS7_ip in main.ONOScli1.get_role(device_id)['master']:
406 role_check = role_check and main.TRUE
407 else:
408 role_check = role_check and main.FALSE
409
410 device_id = main.ONOScli1.get_device("6022")['id']
411 role_call = role_call and main.ONOScli1.device_role(device_id, ONOS7_ip)
412 if ONOS7_ip in main.ONOScli1.get_role(device_id)['master']:
413 role_check = role_check and main.TRUE
414 else:
415 role_check = role_check and main.FALSE
416
417 device_id = main.ONOScli1.get_device("6023")['id']
418 role_call = role_call and main.ONOScli1.device_role(device_id, ONOS7_ip)
419 if ONOS7_ip in main.ONOScli1.get_role(device_id)['master']:
420 role_check = role_check and main.TRUE
421 else:
422 role_check = role_check and main.FALSE
423
424 device_id = main.ONOScli1.get_device("6024")['id']
425 role_call = role_call and main.ONOScli1.device_role(device_id, ONOS7_ip)
426 if ONOS7_ip in main.ONOScli1.get_role(device_id)['master']:
427 role_check = role_check and main.TRUE
428 else:
429 role_check = role_check and main.FALSE
430
431 device_id = main.ONOScli1.get_device("6025")['id']
432 role_call = role_call and main.ONOScli1.device_role(device_id, ONOS7_ip)
433 if ONOS7_ip in main.ONOScli1.get_role(device_id)['master']:
434 role_check = role_check and main.TRUE
435 else:
436 role_check = role_check and main.FALSE
437
438 device_id = main.ONOScli1.get_device("6026")['id']
439 role_call = role_call and main.ONOScli1.device_role(device_id, ONOS7_ip)
440 if ONOS7_ip in main.ONOScli1.get_role(device_id)['master']:
441 role_check = role_check and main.TRUE
442 else:
443 role_check = role_check and main.FALSE
444
445 device_id = main.ONOScli1.get_device("6027")['id']
446 role_call = role_call and main.ONOScli1.device_role(device_id, ONOS7_ip)
447 if ONOS7_ip in main.ONOScli1.get_role(device_id)['master']:
448 role_check = role_check and main.TRUE
449 else:
450 role_check = role_check and main.FALSE
451
452 utilities.assert_equals(expect = main.TRUE,actual=role_call,
453 onpass="Re-assigned switch mastership to designated controller",
454 onfail="Something wrong with device_role calls")
455
456 utilities.assert_equals(expect = main.TRUE,actual=role_check,
457 onpass="Switches were successfully reassigned to designated controller",
458 onfail="Switches were not successfully reassigned")
459 mastership_check = mastership_check and role_call and role_check
460 utilities.assert_equals(expect = main.TRUE,actual=mastership_check,
461 onpass="Switch mastership correctly assigned",
462 onfail="Error in (re)assigning switch mastership")
Jon Hall73cf9cc2014-11-20 22:28:38 -0800463
464
465 def CASE3(self,main) :
466 """
467 Assign intents
468
469 """
Jon Hall94fd0472014-12-08 11:52:42 -0800470 #FIXME: This should only be called once when we have persistence
Jon Hall73cf9cc2014-11-20 22:28:38 -0800471 import time
472 import json
473 import re
474 main.log.report("Adding host intents")
475 main.case("Adding host Intents")
476
477 main.step("Discovering Hosts( Via pingall for now)")
478 #FIXME: Once we have a host discovery mechanism, use that instead
479
Jon Hall94fd0472014-12-08 11:52:42 -0800480 #install onos-app-fwd
481 main.log.info("Install reactive forwarding app")
482 main.ONOScli1.feature_install("onos-app-fwd")
483 main.ONOScli2.feature_install("onos-app-fwd")
484 main.ONOScli3.feature_install("onos-app-fwd")
485 main.ONOScli4.feature_install("onos-app-fwd")
486 main.ONOScli5.feature_install("onos-app-fwd")
487 main.ONOScli6.feature_install("onos-app-fwd")
488 main.ONOScli7.feature_install("onos-app-fwd")
489
Jon Hall73cf9cc2014-11-20 22:28:38 -0800490 #REACTIVE FWD test
491 ping_result = main.FALSE
492 time1 = time.time()
493 ping_result = main.Mininet1.pingall()
494 time2 = time.time()
495 main.log.info("Time for pingall: %2f seconds" % (time2 - time1))
496
497 #uninstall onos-app-fwd
498 main.log.info("Uninstall reactive forwarding app")
499 main.ONOScli1.feature_uninstall("onos-app-fwd")
500 main.ONOScli2.feature_uninstall("onos-app-fwd")
501 main.ONOScli3.feature_uninstall("onos-app-fwd")
502 main.ONOScli4.feature_uninstall("onos-app-fwd")
503 main.ONOScli5.feature_uninstall("onos-app-fwd")
504 main.ONOScli6.feature_uninstall("onos-app-fwd")
505 main.ONOScli7.feature_uninstall("onos-app-fwd")
506
507 main.step("Add host intents")
508 #TODO: move the host numbers to params
509 import json
510 intents_json= json.loads(main.ONOScli1.hosts())
Jon Hall94fd0472014-12-08 11:52:42 -0800511 intent_add_result = True
Jon Hall73cf9cc2014-11-20 22:28:38 -0800512 for i in range(8,18):
513 main.log.info("Adding host intent between h"+str(i)+" and h"+str(i+10))
514 host1 = "00:00:00:00:00:" + str(hex(i)[2:]).zfill(2).upper()
515 host2 = "00:00:00:00:00:" + str(hex(i+10)[2:]).zfill(2).upper()
516 #NOTE: get host can return None
517 #TODO: handle this
518 host1_id = main.ONOScli1.get_host(host1)['id']
519 host2_id = main.ONOScli1.get_host(host2)['id']
520 tmp_result = main.ONOScli1.add_host_intent(host1_id, host2_id )
Jon Hall94fd0472014-12-08 11:52:42 -0800521 intent_add_result = bool(intent_add_result and tmp_result)
522 utilities.assert_equals(expect=True, actual=intent_add_result,
523 onpass="Switch mastership correctly assigned",
524 onfail="Error in (re)assigning switch mastership")
Jon Hall73cf9cc2014-11-20 22:28:38 -0800525 #TODO Check if intents all exist in datastore
526 #NOTE: Do we need to print this once the test is working?
527 #main.log.info(json.dumps(json.loads(main.ONOScli1.intents(json_format=True)),
528 # sort_keys=True, indent=4, separators=(',', ': ') ) )
529
530 def CASE4(self,main) :
531 """
532 Ping across added host intents
533 """
534 description = " Ping across added host intents"
535 main.log.report(description)
536 main.case(description)
537 Ping_Result = main.TRUE
538 for i in range(8,18):
539 ping = main.Mininet1.pingHost(src="h"+str(i),target="h"+str(i+10))
540 Ping_Result = Ping_Result and ping
541 if ping==main.FALSE:
542 main.log.warn("Ping failed between h"+str(i)+" and h" + str(i+10))
543 elif ping==main.TRUE:
544 main.log.info("Ping test passed!")
545 Ping_Result = main.TRUE
546 if Ping_Result==main.FALSE:
547 main.log.report("Intents have not been installed correctly, pings failed.")
548 if Ping_Result==main.TRUE:
549 main.log.report("Intents have been installed correctly and verified by pings")
550 utilities.assert_equals(expect = main.TRUE,actual=Ping_Result,
551 onpass="Intents have been installed correctly and pings work",
552 onfail ="Intents have not been installed correctly, pings failed." )
553
554 def CASE5(self,main) :
555 '''
556 Reading state of ONOS
557 '''
558 import time
559 import json
560 from subprocess import Popen, PIPE
561 from sts.topology.teston_topology import TestONTopology # assumes that sts is already in you PYTHONPATH
562
563 main.log.report("Setting up and gathering data for current state")
564 main.case("Setting up and gathering data for current state")
565 #The general idea for this test case is to pull the state of (intents,flows, topology,...) from each ONOS node
566 #We can then compare them with eachother and also with past states
567
568 main.step("Get the Mastership of each switch from each controller")
569 global mastership_state
Jon Hall94fd0472014-12-08 11:52:42 -0800570 mastership_state = []
571
572 #Assert that each device has a master
573 ONOS1_master_not_null = main.ONOScli1.roles_not_null()
574 ONOS2_master_not_null = main.ONOScli2.roles_not_null()
575 ONOS3_master_not_null = main.ONOScli3.roles_not_null()
576 ONOS4_master_not_null = main.ONOScli4.roles_not_null()
577 ONOS5_master_not_null = main.ONOScli5.roles_not_null()
578 ONOS6_master_not_null = main.ONOScli6.roles_not_null()
579 ONOS7_master_not_null = main.ONOScli7.roles_not_null()
580 roles_not_null = ONOS1_master_not_null and ONOS2_master_not_null and\
581 ONOS3_master_not_null and ONOS4_master_not_null and\
582 ONOS5_master_not_null and ONOS6_master_not_null and\
583 ONOS7_master_not_null
584 utilities.assert_equals(expect = main.TRUE,actual=roles_not_null,
585 onpass="Each device has a master",
586 onfail="Some devices don't have a master assigned")
587
588
Jon Hall73cf9cc2014-11-20 22:28:38 -0800589 ONOS1_mastership = main.ONOScli1.roles()
590 ONOS2_mastership = main.ONOScli2.roles()
591 ONOS3_mastership = main.ONOScli3.roles()
592 ONOS4_mastership = main.ONOScli4.roles()
593 ONOS5_mastership = main.ONOScli5.roles()
594 ONOS6_mastership = main.ONOScli6.roles()
595 ONOS7_mastership = main.ONOScli7.roles()
596 #print json.dumps(json.loads(ONOS1_mastership), sort_keys=True, indent=4, separators=(',', ': '))
597 if "Error" in ONOS1_mastership or not ONOS1_mastership\
598 or "Error" in ONOS2_mastership or not ONOS2_mastership\
599 or "Error" in ONOS3_mastership or not ONOS3_mastership\
600 or "Error" in ONOS4_mastership or not ONOS4_mastership\
601 or "Error" in ONOS5_mastership or not ONOS5_mastership\
602 or "Error" in ONOS6_mastership or not ONOS6_mastership\
603 or "Error" in ONOS7_mastership or not ONOS7_mastership:
604 main.log.report("Error in getting ONOS roles")
605 main.log.warn("ONOS1 mastership response: " + repr(ONOS1_mastership))
606 main.log.warn("ONOS2 mastership response: " + repr(ONOS2_mastership))
607 main.log.warn("ONOS3 mastership response: " + repr(ONOS3_mastership))
608 main.log.warn("ONOS4 mastership response: " + repr(ONOS4_mastership))
609 main.log.warn("ONOS5 mastership response: " + repr(ONOS5_mastership))
610 main.log.warn("ONOS6 mastership response: " + repr(ONOS6_mastership))
611 main.log.warn("ONOS7 mastership response: " + repr(ONOS7_mastership))
612 consistent_mastership = main.FALSE
613 elif ONOS1_mastership == ONOS2_mastership\
614 and ONOS1_mastership == ONOS3_mastership\
615 and ONOS1_mastership == ONOS4_mastership\
616 and ONOS1_mastership == ONOS5_mastership\
617 and ONOS1_mastership == ONOS6_mastership\
618 and ONOS1_mastership == ONOS7_mastership:
619 mastership_state = ONOS1_mastership
620 consistent_mastership = main.TRUE
621 main.log.report("Switch roles are consistent across all ONOS nodes")
622 else:
623 main.log.warn("ONOS1 roles: ", json.dumps(json.loads(ONOS1_mastership),
624 sort_keys=True, indent=4, separators=(',', ': ')))
625 main.log.warn("ONOS2 roles: ", json.dumps(json.loads(ONOS2_mastership),
626 sort_keys=True, indent=4, separators=(',', ': ')))
627 main.log.warn("ONOS3 roles: ", json.dumps(json.loads(ONOS3_mastership),
628 sort_keys=True, indent=4, separators=(',', ': ')))
629 main.log.warn("ONOS4 roles: ", json.dumps(json.loads(ONOS4_mastership),
630 sort_keys=True, indent=4, separators=(',', ': ')))
631 main.log.warn("ONOS5 roles: ", json.dumps(json.loads(ONOS5_mastership),
632 sort_keys=True, indent=4, separators=(',', ': ')))
633 main.log.warn("ONOS6 roles: ", json.dumps(json.loads(ONOS6_mastership),
634 sort_keys=True, indent=4, separators=(',', ': ')))
635 main.log.warn("ONOS7 roles: ", json.dumps(json.loads(ONOS7_mastership),
636 sort_keys=True, indent=4, separators=(',', ': ')))
637 consistent_mastership = main.FALSE
638 utilities.assert_equals(expect = main.TRUE,actual=consistent_mastership,
639 onpass="Switch roles are consistent across all ONOS nodes",
640 onfail="ONOS nodes have different views of switch roles")
641
642
643 main.step("Get the intents from each controller")
644 global intent_state
Jon Hall94fd0472014-12-08 11:52:42 -0800645 intent_state = []
Jon Hall73cf9cc2014-11-20 22:28:38 -0800646 ONOS1_intents = main.ONOScli1.intents( json_format=True )
647 ONOS2_intents = main.ONOScli2.intents( json_format=True )
648 ONOS3_intents = main.ONOScli3.intents( json_format=True )
649 ONOS4_intents = main.ONOScli4.intents( json_format=True )
650 ONOS5_intents = main.ONOScli5.intents( json_format=True )
651 ONOS6_intents = main.ONOScli6.intents( json_format=True )
652 ONOS7_intents = main.ONOScli7.intents( json_format=True )
653 intent_check = main.FALSE
654 if "Error" in ONOS1_intents or not ONOS1_intents\
655 or "Error" in ONOS2_intents or not ONOS2_intents\
656 or "Error" in ONOS3_intents or not ONOS3_intents\
657 or "Error" in ONOS4_intents or not ONOS4_intents\
658 or "Error" in ONOS5_intents or not ONOS5_intents\
659 or "Error" in ONOS6_intents or not ONOS6_intents\
660 or "Error" in ONOS7_intents or not ONOS7_intents:
661 main.log.report("Error in getting ONOS intents")
662 main.log.warn("ONOS1 intents response: " + repr(ONOS1_intents))
663 main.log.warn("ONOS2 intents response: " + repr(ONOS2_intents))
664 main.log.warn("ONOS3 intents response: " + repr(ONOS3_intents))
665 main.log.warn("ONOS4 intents response: " + repr(ONOS4_intents))
666 main.log.warn("ONOS5 intents response: " + repr(ONOS5_intents))
667 main.log.warn("ONOS6 intents response: " + repr(ONOS6_intents))
668 main.log.warn("ONOS7 intents response: " + repr(ONOS7_intents))
669 elif ONOS1_intents == ONOS2_intents\
670 and ONOS1_intents == ONOS3_intents\
671 and ONOS1_intents == ONOS4_intents\
672 and ONOS1_intents == ONOS5_intents\
673 and ONOS1_intents == ONOS6_intents\
674 and ONOS1_intents == ONOS7_intents:
675 intent_state = ONOS1_intents
676 intent_check = main.TRUE
677 main.log.report("Intents are consistent across all ONOS nodes")
678 else:
679 main.log.warn("ONOS1 intents: ", json.dumps(json.loads(ONOS1_intents),
680 sort_keys=True, indent=4, separators=(',', ': ')))
681 main.log.warn("ONOS2 intents: ", json.dumps(json.loads(ONOS2_intents),
682 sort_keys=True, indent=4, separators=(',', ': ')))
683 main.log.warn("ONOS3 intents: ", json.dumps(json.loads(ONOS3_intents),
684 sort_keys=True, indent=4, separators=(',', ': ')))
685 main.log.warn("ONOS4 intents: ", json.dumps(json.loads(ONOS4_intents),
686 sort_keys=True, indent=4, separators=(',', ': ')))
687 main.log.warn("ONOS5 intents: ", json.dumps(json.loads(ONOS5_intents),
688 sort_keys=True, indent=4, separators=(',', ': ')))
689 main.log.warn("ONOS6 intents: ", json.dumps(json.loads(ONOS6_intents),
690 sort_keys=True, indent=4, separators=(',', ': ')))
691 main.log.warn("ONOS7 intents: ", json.dumps(json.loads(ONOS7_intents),
692 sort_keys=True, indent=4, separators=(',', ': ')))
693 utilities.assert_equals(expect = main.TRUE,actual=intent_check,
694 onpass="Intents are consistent across all ONOS nodes",
695 onfail="ONOS nodes have different views of intents")
696
697
698 main.step("Get the flows from each controller")
699 global flow_state
Jon Hall94fd0472014-12-08 11:52:42 -0800700 flow_state = []
Jon Hall73cf9cc2014-11-20 22:28:38 -0800701 ONOS1_flows = main.ONOScli1.flows( json_format=True )
702 ONOS2_flows = main.ONOScli2.flows( json_format=True )
703 ONOS3_flows = main.ONOScli3.flows( json_format=True )
704 ONOS4_flows = main.ONOScli4.flows( json_format=True )
705 ONOS5_flows = main.ONOScli5.flows( json_format=True )
706 ONOS6_flows = main.ONOScli6.flows( json_format=True )
707 ONOS7_flows = main.ONOScli7.flows( json_format=True )
708 flow_check = main.FALSE
709 if "Error" in ONOS1_flows or not ONOS1_flows\
710 or "Error" in ONOS2_flows or not ONOS2_flows\
711 or "Error" in ONOS3_flows or not ONOS3_flows\
712 or "Error" in ONOS4_flows or not ONOS4_flows\
713 or "Error" in ONOS5_flows or not ONOS5_flows\
714 or "Error" in ONOS6_flows or not ONOS6_flows\
715 or "Error" in ONOS7_flows or not ONOS7_flows:
716 main.log.report("Error in getting ONOS intents")
717 main.log.warn("ONOS1 flows repsponse: "+ ONOS1_flows)
718 main.log.warn("ONOS2 flows repsponse: "+ ONOS2_flows)
719 main.log.warn("ONOS3 flows repsponse: "+ ONOS3_flows)
720 main.log.warn("ONOS4 flows repsponse: "+ ONOS4_flows)
721 main.log.warn("ONOS5 flows repsponse: "+ ONOS5_flows)
722 main.log.warn("ONOS6 flows repsponse: "+ ONOS6_flows)
723 main.log.warn("ONOS7 flows repsponse: "+ ONOS7_flows)
724 elif len(json.loads(ONOS1_flows)) == len(json.loads(ONOS2_flows))\
725 and len(json.loads(ONOS1_flows)) == len(json.loads(ONOS3_flows))\
726 and len(json.loads(ONOS1_flows)) == len(json.loads(ONOS4_flows))\
727 and len(json.loads(ONOS1_flows)) == len(json.loads(ONOS5_flows))\
728 and len(json.loads(ONOS1_flows)) == len(json.loads(ONOS6_flows))\
729 and len(json.loads(ONOS1_flows)) == len(json.loads(ONOS7_flows)):
730 #TODO: Do a better check, maybe compare flows on switches?
731 flow_state = ONOS1_flows
732 flow_check = main.TRUE
733 main.log.report("Flow count is consistent across all ONOS nodes")
734 else:
735 main.log.warn("ONOS1 flows: "+ json.dumps(json.loads(ONOS1_flows),
736 sort_keys=True, indent=4, separators=(',', ': ')))
737 main.log.warn("ONOS2 flows: "+ json.dumps(json.loads(ONOS2_flows),
738 sort_keys=True, indent=4, separators=(',', ': ')))
739 main.log.warn("ONOS3 flows: "+ json.dumps(json.loads(ONOS3_flows),
740 sort_keys=True, indent=4, separators=(',', ': ')))
741 main.log.warn("ONOS4 flows: "+ json.dumps(json.loads(ONOS4_flows),
742 sort_keys=True, indent=4, separators=(',', ': ')))
743 main.log.warn("ONOS5 flows: "+ json.dumps(json.loads(ONOS5_flows),
744 sort_keys=True, indent=4, separators=(',', ': ')))
745 main.log.warn("ONOS6 flows: "+ json.dumps(json.loads(ONOS6_flows),
746 sort_keys=True, indent=4, separators=(',', ': ')))
747 main.log.warn("ONOS7 flows: "+ json.dumps(json.loads(ONOS7_flows),
748 sort_keys=True, indent=4, separators=(',', ': ')))
749 utilities.assert_equals(expect = main.TRUE,actual=flow_check,
750 onpass="The flow count is consistent across all ONOS nodes",
751 onfail="ONOS nodes have different flow counts")
752
753
754 main.step("Get the OF Table entries")
755 global flows
756 flows=[]
757 for i in range(1,29):
Jon Hall94fd0472014-12-08 11:52:42 -0800758 flows.append(main.Mininet2.get_flowTable(1.3, "s"+str(i)))
Jon Hall73cf9cc2014-11-20 22:28:38 -0800759
760 #TODO: Compare switch flow tables with ONOS flow tables
761
762 main.step("Start continuous pings")
763 main.Mininet2.pingLong(src=main.params['PING']['source1'],
764 target=main.params['PING']['target1'],pingTime=500)
765 main.Mininet2.pingLong(src=main.params['PING']['source2'],
766 target=main.params['PING']['target2'],pingTime=500)
767 main.Mininet2.pingLong(src=main.params['PING']['source3'],
768 target=main.params['PING']['target3'],pingTime=500)
769 main.Mininet2.pingLong(src=main.params['PING']['source4'],
770 target=main.params['PING']['target4'],pingTime=500)
771 main.Mininet2.pingLong(src=main.params['PING']['source5'],
772 target=main.params['PING']['target5'],pingTime=500)
773 main.Mininet2.pingLong(src=main.params['PING']['source6'],
774 target=main.params['PING']['target6'],pingTime=500)
775 main.Mininet2.pingLong(src=main.params['PING']['source7'],
776 target=main.params['PING']['target7'],pingTime=500)
777 main.Mininet2.pingLong(src=main.params['PING']['source8'],
778 target=main.params['PING']['target8'],pingTime=500)
779 main.Mininet2.pingLong(src=main.params['PING']['source9'],
780 target=main.params['PING']['target9'],pingTime=500)
781 main.Mininet2.pingLong(src=main.params['PING']['source10'],
782 target=main.params['PING']['target10'],pingTime=500)
783
784 main.step("Create TestONTopology object")
785 ctrls = []
786 count = 1
787 while True:
788 temp = ()
789 if ('ip' + str(count)) in main.params['CTRL']:
790 temp = temp + (getattr(main,('ONOS' + str(count))),)
791 temp = temp + ("ONOS"+str(count),)
792 temp = temp + (main.params['CTRL']['ip'+str(count)],)
793 temp = temp + (eval(main.params['CTRL']['port'+str(count)]),)
794 ctrls.append(temp)
795 count = count + 1
796 else:
797 break
798 MNTopo = TestONTopology(main.Mininet1, ctrls) # can also add Intent API info for intent operations
799
800 main.step("Collecting topology information from ONOS")
801 devices = []
802 devices.append( main.ONOScli1.devices() )
803 devices.append( main.ONOScli2.devices() )
804 devices.append( main.ONOScli3.devices() )
805 devices.append( main.ONOScli4.devices() )
806 devices.append( main.ONOScli5.devices() )
807 devices.append( main.ONOScli6.devices() )
808 devices.append( main.ONOScli7.devices() )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800809 hosts = []
810 hosts.append( main.ONOScli1.hosts() )
811 hosts.append( main.ONOScli2.hosts() )
812 hosts.append( main.ONOScli3.hosts() )
813 hosts.append( main.ONOScli4.hosts() )
814 hosts.append( main.ONOScli5.hosts() )
815 hosts.append( main.ONOScli6.hosts() )
816 hosts.append( main.ONOScli7.hosts() )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800817 ports = []
818 ports.append( main.ONOScli1.ports() )
819 ports.append( main.ONOScli2.ports() )
820 ports.append( main.ONOScli3.ports() )
821 ports.append( main.ONOScli4.ports() )
822 ports.append( main.ONOScli5.ports() )
823 ports.append( main.ONOScli6.ports() )
824 ports.append( main.ONOScli7.ports() )
825 links = []
826 links.append( main.ONOScli1.links() )
827 links.append( main.ONOScli2.links() )
828 links.append( main.ONOScli3.links() )
829 links.append( main.ONOScli4.links() )
830 links.append( main.ONOScli5.links() )
831 links.append( main.ONOScli6.links() )
832 links.append( main.ONOScli7.links() )
Jon Hall94fd0472014-12-08 11:52:42 -0800833 clusters = []
834 clusters.append( main.ONOScli1.clusters() )
835 clusters.append( main.ONOScli2.clusters() )
836 clusters.append( main.ONOScli3.clusters() )
837 clusters.append( main.ONOScli4.clusters() )
838 clusters.append( main.ONOScli5.clusters() )
839 clusters.append( main.ONOScli6.clusters() )
840 clusters.append( main.ONOScli7.clusters() )
841 paths = []
842 temp_topo = main.ONOSbench.get_topology( main.ONOScli1.topology() )
843 paths.append( temp_topo.get('paths', False) )
844 temp_topo = main.ONOSbench.get_topology( main.ONOScli2.topology() )
845 paths.append( temp_topo.get('paths', False) )
846 temp_topo = main.ONOSbench.get_topology( main.ONOScli3.topology() )
847 paths.append( temp_topo.get('paths', False) )
848 temp_topo = main.ONOSbench.get_topology( main.ONOScli4.topology() )
849 paths.append( temp_topo.get('paths', False) )
850 temp_topo = main.ONOSbench.get_topology( main.ONOScli5.topology() )
851 paths.append( temp_topo.get('paths', False) )
852 temp_topo = main.ONOSbench.get_topology( main.ONOScli6.topology() )
853 paths.append( temp_topo.get('paths', False) )
854 temp_topo = main.ONOSbench.get_topology( main.ONOScli7.topology() )
855 paths.append( temp_topo.get('paths', False) )
856
857 #Compare json objects for hosts, dataplane clusters and paths
858
859 #hosts
860 consistent_hosts_result = main.TRUE
861 for controller in range( len( hosts ) ):
862 if not "Error" in hosts[controller]:
863 if hosts[controller] == hosts[0]:
864 continue
865 else:#hosts not consistent
866 main.log.report("hosts from ONOS" + str(controller + 1) + " is inconsistent with ONOS1")
867 main.log.warn( repr( hosts[controller] ) )
868 consistent_hosts_result = main.FALSE
869
870 else:
871 main.log.report("Error in getting ONOS hosts from ONOS" + str(controller + 1) )
872 consistent_hosts_result = main.FALSE
873 main.log.warn("ONOS" + str(controller + 1) + " hosts response: " + repr(hosts[controller]) )
874 utilities.assert_equals(expect = main.TRUE,actual=consistent_hosts_result,
875 onpass="Hosts view is consistent across all ONOS nodes",
876 onfail="ONOS nodes have different views of hosts")
877
878 #Strongly connected clusters of devices
879 consistent_clusters_result = main.TRUE
880 for controller in range( len( clusters ) ):
881 if not "Error" in clusters[controller]:
882 if clusters[controller] == clusters[0]:
883 continue
884 else:#clusters not consistent
885 main.log.report("clusters from ONOS" + str(controller + 1) + " is inconsistent with ONOS1")
886 consistent_clusters_result = main.FALSE
887
888 else:
889 main.log.report("Error in getting dataplane clusters from ONOS" + str(controller + 1) )
890 consistent_clusters_result = main.FALSE
891 main.log.warn("ONOS" + str(controller + 1) + " clusters response: " + repr(clusters[controller]) )
892 utilities.assert_equals(expect = main.TRUE,actual=consistent_clusters_result,
893 onpass="Clusters view is consistent across all ONOS nodes",
894 onfail="ONOS nodes have different views of clusters")
895 num_clusters = len(json.loads(clusters[0])) #there should always only be one cluster
896 utilities.assert_equals(expect = 1, actual = num_clusters,
897 onpass="ONOS shows 1 SCC",
898 onfail="ONOS shows "+str(num_clusters) +" SCCs")
899
900
901 #paths
902 consistent_paths_result = main.TRUE
903 for controller in range( len( paths ) ):
904 if not "Error" in paths[controller]:
905 if paths[controller] == paths[0]:
906 continue
907 else:#paths not consistent
908 main.log.report("paths from ONOS" + str(controller + 1) + " is inconsistent with ONOS1")
909 consistent_paths_result = main.FALSE
910
911 else:
912 main.log.report("Error in getting paths from ONOS" + str(controller + 1) )
913 consistent_paths_result = main.FALSE
914 main.log.warn("ONOS" + str(controller + 1) + " paths response: " + repr(paths[controller]) )
915 utilities.assert_equals(expect = main.TRUE,actual=consistent_paths_result,
916 onpass="Paths count is consistent across all ONOS nodes",
917 onfail="ONOS nodes have different counts of paths")
Jon Hall73cf9cc2014-11-20 22:28:38 -0800918
919
920 main.step("Comparing ONOS topology to MN")
921 devices_results = main.TRUE
922 ports_results = main.TRUE
923 links_results = main.TRUE
924 for controller in range(7): #TODO parameterize the number of controllers
925 if devices[controller] or not "Error" in devices[controller]:
926 current_devices_result = main.Mininet1.compare_switches(MNTopo, json.loads(devices[controller]))
927 else:
928 current_devices_result = main.FALSE
929 utilities.assert_equals(expect=main.TRUE, actual=current_devices_result,
930 onpass="ONOS"+str(int(controller+1))+" Switches view is correct",
931 onfail="ONOS"+str(int(controller+1))+" Switches view is incorrect")
932
933 if ports[controller] or not "Error" in ports[controller]:
934 current_ports_result = main.Mininet1.compare_ports(MNTopo, json.loads(ports[controller]))
935 else:
936 current_ports_result = main.FALSE
937 utilities.assert_equals(expect=main.TRUE, actual=current_ports_result,
938 onpass="ONOS"+str(int(controller+1))+" ports view is correct",
939 onfail="ONOS"+str(int(controller+1))+" ports view is incorrect")
940
941 if links[controller] or not "Error" in links[controller]:
942 current_links_result = main.Mininet1.compare_links(MNTopo, json.loads(links[controller]))
943 else:
944 current_links_result = main.FALSE
945 utilities.assert_equals(expect=main.TRUE, actual=current_links_result,
946 onpass="ONOS"+str(int(controller+1))+" links view is correct",
947 onfail="ONOS"+str(int(controller+1))+" links view is incorrect")
948
949 devices_results = devices_results and current_devices_result
950 ports_results = ports_results and current_ports_result
951 links_results = links_results and current_links_result
952
Jon Hall94fd0472014-12-08 11:52:42 -0800953 topo_result = devices_results and ports_results and links_results\
954 and consistent_hosts_result and consistent_clusters_result\
955 and consistent_paths_result
Jon Hall73cf9cc2014-11-20 22:28:38 -0800956 utilities.assert_equals(expect=main.TRUE, actual=topo_result,
957 onpass="Topology Check Test successful",
958 onfail="Topology Check Test NOT successful")
959
960 final_assert = main.TRUE
961 final_assert = final_assert and topo_result and flow_check \
Jon Hall94fd0472014-12-08 11:52:42 -0800962 and intent_check and consistent_mastership and roles_not_null
Jon Hall73cf9cc2014-11-20 22:28:38 -0800963 utilities.assert_equals(expect=main.TRUE, actual=final_assert,
964 onpass="State check successful",
965 onfail="State check NOT successful")
966
967
968 def CASE6(self,main) :
969 '''
970 The Failure case.
971 '''
972 main.log.report("Restart entire ONOS cluster")
973 main.log.case("Restart entire ONOS cluster")
974 main.ONOSbench.onos_kill(ONOS1_ip)
975 main.ONOSbench.onos_kill(ONOS2_ip)
976 main.ONOSbench.onos_kill(ONOS3_ip)
977 main.ONOSbench.onos_kill(ONOS4_ip)
978 main.ONOSbench.onos_kill(ONOS5_ip)
979 main.ONOSbench.onos_kill(ONOS6_ip)
980 main.ONOSbench.onos_kill(ONOS7_ip)
981
982 main.step("Checking if ONOS is up yet")
Jon Hallffb386d2014-11-21 13:43:38 -0800983 count = 0
984 onos_isup_result = main.FALSE
985 while onos_isup_result == main.FALSE and count < 10:
986 onos1_isup = main.ONOSbench.isup(ONOS1_ip)
987 onos2_isup = main.ONOSbench.isup(ONOS2_ip)
988 onos3_isup = main.ONOSbench.isup(ONOS3_ip)
989 onos4_isup = main.ONOSbench.isup(ONOS4_ip)
990 onos5_isup = main.ONOSbench.isup(ONOS5_ip)
991 onos6_isup = main.ONOSbench.isup(ONOS6_ip)
992 onos7_isup = main.ONOSbench.isup(ONOS7_ip)
993 onos_isup_result = onos1_isup and onos2_isup and onos3_isup\
994 and onos4_isup and onos5_isup and onos6_isup and onos7_isup
995 count = count + 1
Jon Hall73cf9cc2014-11-20 22:28:38 -0800996 # TODO: if it becomes an issue, we can retry this step a few times
997
998
999 cli_result1 = main.ONOScli1.start_onos_cli(ONOS1_ip)
1000 cli_result2 = main.ONOScli2.start_onos_cli(ONOS2_ip)
1001 cli_result3 = main.ONOScli3.start_onos_cli(ONOS3_ip)
1002 cli_result4 = main.ONOScli4.start_onos_cli(ONOS4_ip)
1003 cli_result5 = main.ONOScli5.start_onos_cli(ONOS5_ip)
1004 cli_result6 = main.ONOScli6.start_onos_cli(ONOS6_ip)
1005 cli_result7 = main.ONOScli7.start_onos_cli(ONOS7_ip)
1006 cli_results = cli_result1 and cli_result2 and cli_result3\
1007 and cli_result4 and cli_result5 and cli_result6\
1008 and cli_result7
1009
1010 case_results = main.TRUE and onos_isup_result and cli_results
1011 utilities.assert_equals(expect=main.TRUE, actual=case_results,
1012 onpass="ONOS restart successful",
1013 onfail="ONOS restart NOT successful")
1014
1015
1016 def CASE7(self,main) :
1017 '''
1018 Check state after ONOS failure
1019 '''
1020 import os
1021 import json
1022 main.case("Running ONOS Constant State Tests")
1023
Jon Hall94fd0472014-12-08 11:52:42 -08001024 #Assert that each device has a master
1025 ONOS1_master_not_null = main.ONOScli1.roles_not_null()
1026 ONOS2_master_not_null = main.ONOScli2.roles_not_null()
1027 ONOS3_master_not_null = main.ONOScli3.roles_not_null()
1028 ONOS4_master_not_null = main.ONOScli4.roles_not_null()
1029 ONOS5_master_not_null = main.ONOScli5.roles_not_null()
1030 ONOS6_master_not_null = main.ONOScli6.roles_not_null()
1031 ONOS7_master_not_null = main.ONOScli7.roles_not_null()
1032 roles_not_null = ONOS1_master_not_null and ONOS2_master_not_null and\
1033 ONOS3_master_not_null and ONOS4_master_not_null and\
1034 ONOS5_master_not_null and ONOS6_master_not_null and\
1035 ONOS7_master_not_null
1036 utilities.assert_equals(expect = main.TRUE,actual=roles_not_null,
1037 onpass="Each device has a master",
1038 onfail="Some devices don't have a master assigned")
1039
1040
1041
Jon Hall73cf9cc2014-11-20 22:28:38 -08001042 main.step("Check if switch roles are consistent across all nodes")
1043 ONOS1_mastership = main.ONOScli1.roles()
1044 ONOS2_mastership = main.ONOScli2.roles()
1045 ONOS3_mastership = main.ONOScli3.roles()
1046 ONOS4_mastership = main.ONOScli4.roles()
1047 ONOS5_mastership = main.ONOScli5.roles()
1048 ONOS6_mastership = main.ONOScli6.roles()
1049 ONOS7_mastership = main.ONOScli7.roles()
1050 #print json.dumps(json.loads(ONOS1_mastership), sort_keys=True, indent=4, separators=(',', ': '))
1051 if "Error" in ONOS1_mastership or not ONOS1_mastership\
1052 or "Error" in ONOS2_mastership or not ONOS2_mastership\
1053 or "Error" in ONOS3_mastership or not ONOS3_mastership\
1054 or "Error" in ONOS4_mastership or not ONOS4_mastership\
1055 or "Error" in ONOS5_mastership or not ONOS5_mastership\
1056 or "Error" in ONOS6_mastership or not ONOS6_mastership\
1057 or "Error" in ONOS7_mastership or not ONOS7_mastership:
1058 main.log.error("Error in getting ONOS mastership")
1059 main.log.warn("ONOS1 mastership response: " + repr(ONOS1_mastership))
1060 main.log.warn("ONOS2 mastership response: " + repr(ONOS2_mastership))
1061 main.log.warn("ONOS3 mastership response: " + repr(ONOS3_mastership))
1062 main.log.warn("ONOS4 mastership response: " + repr(ONOS4_mastership))
1063 main.log.warn("ONOS5 mastership response: " + repr(ONOS5_mastership))
1064 main.log.warn("ONOS6 mastership response: " + repr(ONOS6_mastership))
1065 main.log.warn("ONOS7 mastership response: " + repr(ONOS7_mastership))
1066 consistent_mastership = main.FALSE
1067 elif ONOS1_mastership == ONOS2_mastership\
1068 and ONOS1_mastership == ONOS3_mastership\
1069 and ONOS1_mastership == ONOS4_mastership\
1070 and ONOS1_mastership == ONOS5_mastership\
1071 and ONOS1_mastership == ONOS6_mastership\
1072 and ONOS1_mastership == ONOS7_mastership:
Jon Hall73cf9cc2014-11-20 22:28:38 -08001073 consistent_mastership = main.TRUE
1074 main.log.report("Switch roles are consistent across all ONOS nodes")
1075 else:
1076 main.log.warn("ONOS1 roles: ", json.dumps(json.loads(ONOS1_mastership),
1077 sort_keys=True, indent=4, separators=(',', ': ')))
1078 main.log.warn("ONOS2 roles: ", json.dumps(json.loads(ONOS2_mastership),
1079 sort_keys=True, indent=4, separators=(',', ': ')))
1080 main.log.warn("ONOS3 roles: ", json.dumps(json.loads(ONOS3_mastership),
1081 sort_keys=True, indent=4, separators=(',', ': ')))
1082 main.log.warn("ONOS4 roles: ", json.dumps(json.loads(ONOS4_mastership),
1083 sort_keys=True, indent=4, separators=(',', ': ')))
1084 main.log.warn("ONOS5 roles: ", json.dumps(json.loads(ONOS5_mastership),
1085 sort_keys=True, indent=4, separators=(',', ': ')))
1086 main.log.warn("ONOS6 roles: ", json.dumps(json.loads(ONOS6_mastership),
1087 sort_keys=True, indent=4, separators=(',', ': ')))
1088 main.log.warn("ONOS7 roles: ", json.dumps(json.loads(ONOS7_mastership),
1089 sort_keys=True, indent=4, separators=(',', ': ')))
1090 consistent_mastership = main.FALSE
1091 utilities.assert_equals(expect = main.TRUE,actual=consistent_mastership,
1092 onpass="Switch roles are consistent across all ONOS nodes",
1093 onfail="ONOS nodes have different views of switch roles")
1094
1095
1096 description2 = "Compare switch roles from before failure"
1097 main.step(description2)
1098
1099 current_json = json.loads(ONOS1_mastership)
1100 old_json = json.loads(mastership_state)
1101 mastership_check = main.TRUE
1102 for i in range(1,29):
1103 switchDPID = str(main.Mininet1.getSwitchDPID(switch="s"+str(i)))
1104
1105 current = [switch['master'] for switch in current_json if switchDPID in switch['id']]
1106 old = [switch['master'] for switch in old_json if switchDPID in switch['id']]
1107 if current == old:
1108 mastership_check = mastership_check and main.TRUE
1109 else:
1110 main.log.warn("Mastership of switch %s changed" % switchDPID)
1111 mastership_check = main.FALSE
1112 if mastership_check == main.TRUE:
1113 main.log.report("Mastership of Switches was not changed")
1114 utilities.assert_equals(expect=main.TRUE,actual=mastership_check,
1115 onpass="Mastership of Switches was not changed",
1116 onfail="Mastership of some switches changed")
1117 #NOTE: we expect mastership to change on controller failure
1118 mastership_check = mastership_check #and consistent_mastership
1119
1120
1121
1122 main.step("Get the intents and compare across all nodes")
1123 ONOS1_intents = main.ONOScli1.intents( json_format=True )
1124 ONOS2_intents = main.ONOScli2.intents( json_format=True )
1125 ONOS3_intents = main.ONOScli3.intents( json_format=True )
1126 ONOS4_intents = main.ONOScli4.intents( json_format=True )
1127 ONOS5_intents = main.ONOScli5.intents( json_format=True )
1128 ONOS6_intents = main.ONOScli6.intents( json_format=True )
1129 ONOS7_intents = main.ONOScli7.intents( json_format=True )
1130 intent_check = main.FALSE
1131 if "Error" in ONOS1_intents or not ONOS1_intents\
1132 or "Error" in ONOS2_intents or not ONOS2_intents\
1133 or "Error" in ONOS3_intents or not ONOS3_intents\
1134 or "Error" in ONOS4_intents or not ONOS4_intents\
1135 or "Error" in ONOS5_intents or not ONOS5_intents\
1136 or "Error" in ONOS6_intents or not ONOS6_intents\
1137 or "Error" in ONOS7_intents or not ONOS7_intents:
1138 main.log.report("Error in getting ONOS intents")
1139 main.log.warn("ONOS1 intents response: " + repr(ONOS1_intents))
1140 main.log.warn("ONOS2 intents response: " + repr(ONOS2_intents))
1141 main.log.warn("ONOS3 intents response: " + repr(ONOS3_intents))
1142 main.log.warn("ONOS4 intents response: " + repr(ONOS4_intents))
1143 main.log.warn("ONOS5 intents response: " + repr(ONOS5_intents))
1144 main.log.warn("ONOS6 intents response: " + repr(ONOS6_intents))
1145 main.log.warn("ONOS7 intents response: " + repr(ONOS7_intents))
1146 elif ONOS1_intents == ONOS2_intents\
1147 and ONOS1_intents == ONOS3_intents\
1148 and ONOS1_intents == ONOS4_intents\
1149 and ONOS1_intents == ONOS5_intents\
1150 and ONOS1_intents == ONOS6_intents\
1151 and ONOS1_intents == ONOS7_intents:
1152 intent_check = main.TRUE
1153 main.log.report("Intents are consistent across all ONOS nodes")
1154 else:
Jon Hall94fd0472014-12-08 11:52:42 -08001155 main.log.warn("ONOS1 intents: ")
1156 print json.dumps(json.loads(ONOS1_intents),
1157 sort_keys=True, indent=4, separators=(',', ': '))
1158 main.log.warn("ONOS2 intents: ")
1159 print json.dumps(json.loads(ONOS2_intents),
1160 sort_keys=True, indent=4, separators=(',', ': '))
1161 main.log.warn("ONOS3 intents: ")
1162 print json.dumps(json.loads(ONOS3_intents),
1163 sort_keys=True, indent=4, separators=(',', ': '))
1164 main.log.warn("ONOS4 intents: ")
1165 print json.dumps(json.loads(ONOS4_intents),
1166 sort_keys=True, indent=4, separators=(',', ': '))
1167 main.log.warn("ONOS5 intents: ")
1168 print json.dumps(json.loads(ONOS5_intents),
1169 sort_keys=True, indent=4, separators=(',', ': '))
1170 main.log.warn("ONOS6 intents: ")
1171 print json.dumps(json.loads(ONOS6_intents),
1172 sort_keys=True, indent=4, separators=(',', ': '))
1173 main.log.warn("ONOS7 intents: ")
1174 print json.dumps(json.loads(ONOS7_intents),
1175 sort_keys=True, indent=4, separators=(',', ': '))
Jon Hall73cf9cc2014-11-20 22:28:38 -08001176 utilities.assert_equals(expect = main.TRUE,actual=intent_check,
1177 onpass="Intents are consistent across all ONOS nodes",
1178 onfail="ONOS nodes have different views of intents")
1179
Jon Hall94fd0472014-12-08 11:52:42 -08001180 #NOTE: Hazelcast has no durability, so intents are lost
1181 '''
Jon Hall73cf9cc2014-11-20 22:28:38 -08001182 main.step("Compare current intents with intents before the failure")
Jon Hall94fd0472014-12-08 11:52:42 -08001183 #NOTE: this requires case 5 to pass for intent_state to be set.
1184 # maybe we should stop the test if that fails?
Jon Hall73cf9cc2014-11-20 22:28:38 -08001185 if intent_state == ONOS1_intents:
1186 same_intents = main.TRUE
1187 main.log.report("Intents are consistent with before failure")
1188 #TODO: possibly the states have changed? we may need to figure out what the aceptable states are
1189 else:
1190 same_intents = main.FALSE
1191 utilities.assert_equals(expect = main.TRUE,actual=same_intents,
1192 onpass="Intents are consistent with before failure",
1193 onfail="The Intents changed during failure")
1194 intent_check = intent_check and same_intents
Jon Hall94fd0472014-12-08 11:52:42 -08001195 '''
Jon Hall73cf9cc2014-11-20 22:28:38 -08001196
1197
1198
1199 main.step("Get the OF Table entries and compare to before component failure")
1200 Flow_Tables = main.TRUE
1201 flows2=[]
1202 for i in range(28):
1203 main.log.info("Checking flow table on s" + str(i+1))
Jon Hall94fd0472014-12-08 11:52:42 -08001204 tmp_flows = main.Mininet2.get_flowTable(1.3, "s"+str(i+1))
Jon Hall73cf9cc2014-11-20 22:28:38 -08001205 flows2.append(tmp_flows)
Jon Hall94fd0472014-12-08 11:52:42 -08001206 temp_result = main.Mininet2.flow_comp(flow1=flows[i],flow2=tmp_flows)
1207 Flow_Tables = Flow_Tables and temp_result
Jon Hall73cf9cc2014-11-20 22:28:38 -08001208 if Flow_Tables == main.FALSE:
1209 main.log.info("Differences in flow table for switch: "+str(i+1))
Jon Hall73cf9cc2014-11-20 22:28:38 -08001210 if Flow_Tables == main.TRUE:
1211 main.log.report("No changes were found in the flow tables")
1212 utilities.assert_equals(expect=main.TRUE,actual=Flow_Tables,
1213 onpass="No changes were found in the flow tables",
1214 onfail="Changes were found in the flow tables")
1215
1216 main.step("Check the continuous pings to ensure that no packets were dropped during component failure")
1217 #FIXME: This check is always failing. Investigate cause
1218 #NOTE: this may be something to do with file permsissions
1219 # or slight change in format
1220 main.Mininet2.pingKill(main.params['TESTONUSER'], main.params['TESTONIP'])
1221 Loss_In_Pings = main.FALSE
1222 #NOTE: checkForLoss returns main.FALSE with 0% packet loss
1223 for i in range(8,18):
1224 main.log.info("Checking for a loss in pings along flow from s" + str(i))
Jon Hall94fd0472014-12-08 11:52:42 -08001225 Loss_In_Pings = main.Mininet2.checkForLoss("/tmp/ping.h"+str(i)) or Loss_In_Pings
Jon Hall73cf9cc2014-11-20 22:28:38 -08001226 if Loss_In_Pings == main.TRUE:
1227 main.log.info("Loss in ping detected")
1228 elif Loss_In_Pings == main.ERROR:
1229 main.log.info("There are multiple mininet process running")
1230 elif Loss_In_Pings == main.FALSE:
1231 main.log.info("No Loss in the pings")
1232 main.log.report("No loss of dataplane connectivity")
1233 utilities.assert_equals(expect=main.FALSE,actual=Loss_In_Pings,
1234 onpass="No Loss of connectivity",
1235 onfail="Loss of dataplane connectivity detected")
Jon Hall94fd0472014-12-08 11:52:42 -08001236 #NOTE: Since intents are not persisted with Hazelcast, we expect this
1237 Loss_In_Pings = main.FALSE
Jon Hall73cf9cc2014-11-20 22:28:38 -08001238
1239
1240 #TODO:add topology to this or leave as a seperate case?
Jon Hall94fd0472014-12-08 11:52:42 -08001241 result = mastership_check and intent_check and Flow_Tables and (not Loss_In_Pings) and roles_not_null
Jon Hall73cf9cc2014-11-20 22:28:38 -08001242 result = int(result)
1243 if result == main.TRUE:
1244 main.log.report("Constant State Tests Passed")
1245 utilities.assert_equals(expect=main.TRUE,actual=result,
1246 onpass="Constant State Tests Passed",
1247 onfail="Constant state tests failed")
1248
1249 def CASE8 (self,main):
1250 '''
1251 Compare topo
1252 '''
1253 import sys
1254 sys.path.append("/home/admin/sts") # Trying to remove some dependancies, #FIXME add this path to params
1255 from sts.topology.teston_topology import TestONTopology # assumes that sts is already in you PYTHONPATH
1256 import json
1257 import time
1258
1259 description ="Compare ONOS Topology view to Mininet topology"
1260 main.case(description)
1261 main.log.report(description)
1262 main.step("Create TestONTopology object")
1263 ctrls = []
1264 count = 1
1265 while True:
1266 temp = ()
1267 if ('ip' + str(count)) in main.params['CTRL']:
1268 temp = temp + (getattr(main,('ONOS' + str(count))),)
1269 temp = temp + ("ONOS"+str(count),)
1270 temp = temp + (main.params['CTRL']['ip'+str(count)],)
1271 temp = temp + (eval(main.params['CTRL']['port'+str(count)]),)
1272 ctrls.append(temp)
1273 count = count + 1
1274 else:
1275 break
1276 MNTopo = TestONTopology(main.Mininet1, ctrls) # can also add Intent API info for intent operations
1277
Jon Hall73cf9cc2014-11-20 22:28:38 -08001278 main.step("Comparing ONOS topology to MN")
1279 devices_results = main.TRUE
1280 ports_results = main.TRUE
1281 links_results = main.TRUE
1282 topo_result = main.FALSE
Jon Hall73cf9cc2014-11-20 22:28:38 -08001283 elapsed = 0
Jon Hallffb386d2014-11-21 13:43:38 -08001284 count = 0
Jon Hall94fd0472014-12-08 11:52:42 -08001285 main.step("Collecting topology information from ONOS")
1286 start_time = time.time()
1287 while topo_result == main.FALSE and elapsed < 60:
Jon Hallffb386d2014-11-21 13:43:38 -08001288 count = count + 1
Jon Hall94fd0472014-12-08 11:52:42 -08001289 if count > 1:
1290 MNTopo = TestONTopology(main.Mininet1, ctrls) # can also add Intent API info for intent operations
1291 cli_start = time.time()
1292 devices = []
1293 devices.append( main.ONOScli1.devices() )
1294 devices.append( main.ONOScli2.devices() )
1295 devices.append( main.ONOScli3.devices() )
1296 devices.append( main.ONOScli4.devices() )
1297 devices.append( main.ONOScli5.devices() )
1298 devices.append( main.ONOScli6.devices() )
1299 devices.append( main.ONOScli7.devices() )
1300 hosts = []
1301 hosts.append( main.ONOScli1.hosts() )
1302 hosts.append( main.ONOScli2.hosts() )
1303 hosts.append( main.ONOScli3.hosts() )
1304 hosts.append( main.ONOScli4.hosts() )
1305 hosts.append( main.ONOScli5.hosts() )
1306 hosts.append( main.ONOScli6.hosts() )
1307 hosts.append( main.ONOScli7.hosts() )
1308 ports = []
1309 ports.append( main.ONOScli1.ports() )
1310 ports.append( main.ONOScli2.ports() )
1311 ports.append( main.ONOScli3.ports() )
1312 ports.append( main.ONOScli4.ports() )
1313 ports.append( main.ONOScli5.ports() )
1314 ports.append( main.ONOScli6.ports() )
1315 ports.append( main.ONOScli7.ports() )
1316 links = []
1317 links.append( main.ONOScli1.links() )
1318 links.append( main.ONOScli2.links() )
1319 links.append( main.ONOScli3.links() )
1320 links.append( main.ONOScli4.links() )
1321 links.append( main.ONOScli5.links() )
1322 links.append( main.ONOScli6.links() )
1323 links.append( main.ONOScli7.links() )
1324 clusters = []
1325 clusters.append( main.ONOScli1.clusters() )
1326 clusters.append( main.ONOScli2.clusters() )
1327 clusters.append( main.ONOScli3.clusters() )
1328 clusters.append( main.ONOScli4.clusters() )
1329 clusters.append( main.ONOScli5.clusters() )
1330 clusters.append( main.ONOScli6.clusters() )
1331 clusters.append( main.ONOScli7.clusters() )
1332 paths = []
1333 temp_topo = main.ONOSbench.get_topology( main.ONOScli1.topology() )
1334 paths.append( temp_topo.get('paths', False) )
1335 temp_topo = main.ONOSbench.get_topology( main.ONOScli2.topology() )
1336 paths.append( temp_topo.get('paths', False) )
1337 temp_topo = main.ONOSbench.get_topology( main.ONOScli3.topology() )
1338 paths.append( temp_topo.get('paths', False) )
1339 temp_topo = main.ONOSbench.get_topology( main.ONOScli4.topology() )
1340 paths.append( temp_topo.get('paths', False) )
1341 temp_topo = main.ONOSbench.get_topology( main.ONOScli5.topology() )
1342 paths.append( temp_topo.get('paths', False) )
1343 temp_topo = main.ONOSbench.get_topology( main.ONOScli6.topology() )
1344 paths.append( temp_topo.get('paths', False) )
1345 temp_topo = main.ONOSbench.get_topology( main.ONOScli7.topology() )
1346 paths.append( temp_topo.get('paths', False) )
Jon Hallffb386d2014-11-21 13:43:38 -08001347
Jon Hall73cf9cc2014-11-20 22:28:38 -08001348
Jon Hall94fd0472014-12-08 11:52:42 -08001349 elapsed = time.time() - start_time
1350 cli_time = time.time() - cli_start
1351 print "CLI time: " + str(cli_time)
Jon Hall73cf9cc2014-11-20 22:28:38 -08001352
Jon Hall94fd0472014-12-08 11:52:42 -08001353 for controller in range(7): #TODO parameterize the number of controllers
1354 if devices[controller] or not "Error" in devices[controller]:
1355 current_devices_result = main.Mininet1.compare_switches(MNTopo, json.loads(devices[controller]))
1356 else:
1357 current_devices_result = main.FALSE
1358 utilities.assert_equals(expect=main.TRUE, actual=current_devices_result,
1359 onpass="ONOS"+str(int(controller+1))+" Switches view is correct",
1360 onfail="ONOS"+str(int(controller+1))+" Switches view is incorrect")
Jon Hall73cf9cc2014-11-20 22:28:38 -08001361
Jon Hall94fd0472014-12-08 11:52:42 -08001362 if ports[controller] or not "Error" in ports[controller]:
1363 current_ports_result = main.Mininet1.compare_ports(MNTopo, json.loads(ports[controller]))
1364 else:
1365 current_ports_result = main.FALSE
1366 utilities.assert_equals(expect=main.TRUE, actual=current_ports_result,
1367 onpass="ONOS"+str(int(controller+1))+" ports view is correct",
1368 onfail="ONOS"+str(int(controller+1))+" ports view is incorrect")
1369
1370 if links[controller] or not "Error" in links[controller]:
1371 current_links_result = main.Mininet1.compare_links(MNTopo, json.loads(links[controller]))
1372 else:
1373 current_links_result = main.FALSE
1374 utilities.assert_equals(expect=main.TRUE, actual=current_links_result,
1375 onpass="ONOS"+str(int(controller+1))+" links view is correct",
1376 onfail="ONOS"+str(int(controller+1))+" links view is incorrect")
Jon Hall73cf9cc2014-11-20 22:28:38 -08001377 devices_results = devices_results and current_devices_result
1378 ports_results = ports_results and current_ports_result
1379 links_results = links_results and current_links_result
Jon Hall94fd0472014-12-08 11:52:42 -08001380
1381 #Compare json objects for hosts, dataplane clusters and paths
1382
1383 #hosts
1384 consistent_hosts_result = main.TRUE
1385 for controller in range( len( hosts ) ):
1386 if not "Error" in hosts[controller]:
1387 if hosts[controller] == hosts[0]:
1388 continue
1389 else:#hosts not consistent
1390 main.log.report("hosts from ONOS" + str(controller + 1) + " is inconsistent with ONOS1")
1391 main.log.warn( repr( hosts[controller] ) )
1392 consistent_hosts_result = main.FALSE
1393
1394 else:
1395 main.log.report("Error in getting ONOS hosts from ONOS" + str(controller + 1) )
1396 consistent_hosts_result = main.FALSE
1397 main.log.warn("ONOS" + str(controller + 1) + " hosts response: " + repr(hosts[controller]) )
1398 utilities.assert_equals(expect = main.TRUE,actual=consistent_hosts_result,
1399 onpass="Hosts view is consistent across all ONOS nodes",
1400 onfail="ONOS nodes have different views of hosts")
1401
1402 #Strongly connected clusters of devices
1403 consistent_clusters_result = main.TRUE
1404 for controller in range( len( clusters ) ):
1405 if not "Error" in clusters[controller]:
1406 if clusters[controller] == clusters[0]:
1407 continue
1408 else:#clusters not consistent
1409 main.log.report("clusters from ONOS" + str(controller + 1) + " is inconsistent with ONOS1")
1410 consistent_clusters_result = main.FALSE
1411
1412 else:
1413 main.log.report("Error in getting dataplane clusters from ONOS" + str(controller + 1) )
1414 consistent_clusters_result = main.FALSE
1415 main.log.warn("ONOS" + str(controller + 1) + " clusters response: " + repr(clusters[controller]) )
1416 utilities.assert_equals(expect = main.TRUE,actual=consistent_clusters_result,
1417 onpass="Clusters view is consistent across all ONOS nodes",
1418 onfail="ONOS nodes have different views of clusters")
1419 num_clusters = len(json.loads(clusters[0])) #there should always only be one cluster
1420 utilities.assert_equals(expect = 1, actual = num_clusters,
1421 onpass="ONOS shows 1 SCC",
1422 onfail="ONOS shows "+str(num_clusters) +" SCCs")
1423
1424
1425 #paths
1426 consistent_paths_result = main.TRUE
1427 for controller in range( len( paths ) ):
1428 if not "Error" in paths[controller]:
1429 if paths[controller] == paths[0]:
1430 continue
1431 else:#paths not consistent
1432 main.log.report("paths from ONOS" + str(controller + 1) + " is inconsistent with ONOS1")
1433 consistent_paths_result = main.FALSE
1434
1435 else:
1436 main.log.report("Error in getting paths from ONOS" + str(controller + 1) )
1437 consistent_paths_result = main.FALSE
1438 main.log.warn("ONOS" + str(controller + 1) + " paths response: " + repr(paths[controller]) )
1439 utilities.assert_equals(expect = main.TRUE,actual=consistent_paths_result,
1440 onpass="Paths count is consistent across all ONOS nodes",
1441 onfail="ONOS nodes have different counts of paths")
1442
1443
1444 topo_result = devices_results and ports_results and links_results\
1445 and consistent_hosts_result and consistent_clusters_result and consistent_paths_result
1446
1447 topo_result = topo_result and int(count <= 2)
1448 note = "note it takes about "+str( int(cli_time) )+" seconds for the test to make all the cli calls to fetch the topology from each ONOS instance"
1449 main.log.report("Very crass estimate for topology discovery/convergence("+ str(note) + "): " +\
Jon Hallffb386d2014-11-21 13:43:38 -08001450 str(elapsed) + " seconds, " + str(count) +" tries" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001451 utilities.assert_equals(expect=main.TRUE, actual=topo_result,
1452 onpass="Topology Check Test successful",
1453 onfail="Topology Check Test NOT successful")
1454 if topo_result == main.TRUE:
1455 main.log.report("ONOS topology view matches Mininet topology")
1456
1457
1458 def CASE9 (self,main):
1459 '''
1460 Link s3-s28 down
1461 '''
1462 #NOTE: You should probably run a topology check after this
1463
1464 link_sleep = int(main.params['timers']['LinkDiscovery'])
1465
1466 description = "Turn off a link to ensure that Link Discovery is working properly"
1467 main.log.report(description)
1468 main.case(description)
1469
1470
1471 main.step("Kill Link between s3 and s28")
1472 Link_Down = main.Mininet1.link(END1="s3",END2="s28",OPTION="down")
1473 main.log.info("Waiting " + str(link_sleep) + " seconds for link down to be discovered")
1474 time.sleep(link_sleep)
1475 utilities.assert_equals(expect=main.TRUE,actual=Link_Down,
1476 onpass="Link down succesful",
1477 onfail="Failed to bring link down")
1478 #TODO do some sort of check here
1479
1480 def CASE10 (self,main):
1481 '''
1482 Link s3-s28 up
1483 '''
1484 #NOTE: You should probably run a topology check after this
1485
1486 link_sleep = int(main.params['timers']['LinkDiscovery'])
1487
1488 description = "Restore a link to ensure that Link Discovery is working properly"
1489 main.log.report(description)
1490 main.case(description)
1491
1492 main.step("Bring link between s3 and s28 back up")
1493 Link_Up = main.Mininet1.link(END1="s3",END2="s28",OPTION="up")
1494 main.log.info("Waiting " + str(link_sleep) + " seconds for link up to be discovered")
1495 time.sleep(link_sleep)
1496 utilities.assert_equals(expect=main.TRUE,actual=Link_Up,
1497 onpass="Link up succesful",
1498 onfail="Failed to bring link up")
1499 #TODO do some sort of check here
1500
1501
1502 def CASE11 (self, main) :
1503 '''
1504 Switch Down
1505 '''
1506 #NOTE: You should probably run a topology check after this
1507 import time
1508
1509 switch_sleep = int(main.params['timers']['SwitchDiscovery'])
1510
1511 description = "Killing a switch to ensure it is discovered correctly"
1512 main.log.report(description)
1513 main.case(description)
1514
1515 #TODO: Make this switch parameterizable
1516 main.step("Kill s28 ")
1517 main.log.report("Deleting s28")
Jon Hall73cf9cc2014-11-20 22:28:38 -08001518 main.Mininet1.del_switch("s28")
1519 main.log.info("Waiting " + str(switch_sleep) + " seconds for switch down to be discovered")
1520 time.sleep(switch_sleep)
Jon Hall94fd0472014-12-08 11:52:42 -08001521 device = main.ONOScli1.get_device(dpid="0028")
Jon Hall73cf9cc2014-11-20 22:28:38 -08001522 #Peek at the deleted switch
Jon Hall94fd0472014-12-08 11:52:42 -08001523 main.log.warn( str(device) )
1524 result = main.FALSE
1525 if device and device['available'] == False:
1526 result = main.TRUE
1527 utilities.assert_equals(expect=main.TRUE,actual=result,
1528 onpass="Kill switch succesful",
1529 onfail="Failed to kill switch?")
Jon Hall73cf9cc2014-11-20 22:28:38 -08001530
1531 def CASE12 (self, main) :
1532 '''
1533 Switch Up
1534 '''
1535 #NOTE: You should probably run a topology check after this
1536 import time
Jon Hall73cf9cc2014-11-20 22:28:38 -08001537 description = "Adding a switch to ensure it is discovered correctly"
1538 main.log.report(description)
1539 main.case(description)
1540
1541 main.step("Add back s28")
1542 main.log.report("Adding back s28")
1543 main.Mininet1.add_switch("s28", dpid = '0000000000002800')
1544 #TODO: New dpid or same? Ask Thomas?
1545 main.Mininet1.add_link('s28', 's3')
1546 main.Mininet1.add_link('s28', 's6')
1547 main.Mininet1.add_link('s28', 'h28')
1548 main.Mininet1.assign_sw_controller(sw="28",count=7,
1549 ip1=ONOS1_ip,port1=ONOS1_port,
1550 ip2=ONOS2_ip,port2=ONOS2_port,
1551 ip3=ONOS3_ip,port3=ONOS3_port,
1552 ip4=ONOS4_ip,port4=ONOS4_port,
1553 ip5=ONOS5_ip,port5=ONOS5_port,
1554 ip6=ONOS6_ip,port6=ONOS6_port,
1555 ip7=ONOS7_ip,port7=ONOS7_port)
1556 main.log.info("Waiting " + str(switch_sleep) + " seconds for switch up to be discovered")
1557 time.sleep(switch_sleep)
Jon Hall94fd0472014-12-08 11:52:42 -08001558 device = main.ONOScli1.get_device(dpid="0028")
1559 #Peek at the deleted switch
1560 main.log.warn( str(device) )
1561 result = main.FALSE
1562 if device and device['available'] == True:
1563 result = main.TRUE
1564 utilities.assert_equals(expect=main.TRUE,actual=result,
1565 onpass="add switch succesful",
1566 onfail="Failed to add switch?")
Jon Hall73cf9cc2014-11-20 22:28:38 -08001567
1568 def CASE13 (self, main) :
1569 '''
1570 Clean up
1571 '''
1572 import os
1573 import time
1574 description = "Test Cleanup"
1575 main.log.report(description)
1576 main.case(description)
1577 main.step("Killing tcpdumps")
1578 main.Mininet2.stop_tcpdump()
1579
Jon Hall94fd0472014-12-08 11:52:42 -08001580 main.step("Checking ONOS Logs for errors")
1581 print "Checking logs for errors on ONOS1:"
1582 print main.ONOSbench.check_logs(ONOS1_ip)
1583 print "Checking logs for errors on ONOS2:"
1584 print main.ONOSbench.check_logs(ONOS2_ip)
1585 print "Checking logs for errors on ONOS3:"
1586 print main.ONOSbench.check_logs(ONOS3_ip)
1587 print "Checking logs for errors on ONOS4:"
1588 print main.ONOSbench.check_logs(ONOS4_ip)
1589 print "Checking logs for errors on ONOS5:"
1590 print main.ONOSbench.check_logs(ONOS5_ip)
1591 print "Checking logs for errors on ONOS6:"
1592 print main.ONOSbench.check_logs(ONOS6_ip)
1593 print "Checking logs for errors on ONOS7:"
1594 print main.ONOSbench.check_logs(ONOS7_ip)
1595
Jon Hall73cf9cc2014-11-20 22:28:38 -08001596 main.step("Copying MN pcap and ONOS log files to test station")
1597 testname = main.TEST
Jon Hall94fd0472014-12-08 11:52:42 -08001598 teststation_user = main.params['TESTONUSER']
1599 teststation_IP = main.params['TESTONIP']
Jon Hall73cf9cc2014-11-20 22:28:38 -08001600 #NOTE: MN Pcap file is being saved to ~/packet_captures
1601 # scp this file as MN and TestON aren't necessarily the same vm
1602 #FIXME: scp
1603 #####mn files
1604 #TODO: Load these from params
1605 #NOTE: must end in /
1606 log_folder = "/opt/onos/log/"
1607 log_files = ["karaf.log", "karaf.log.1"]
1608 #NOTE: must end in /
1609 dst_dir = "~/packet_captures/"
1610 for f in log_files:
Jon Hall94fd0472014-12-08 11:52:42 -08001611 main.ONOSbench.handle.sendline( "scp sdn@"+ONOS1_ip+":"+log_folder+f+" "+
1612 teststation_user +"@"+teststation_IP+":"+\
Jon Hall73cf9cc2014-11-20 22:28:38 -08001613 dst_dir + str(testname) + "-ONOS1-"+f )
Jon Hall94fd0472014-12-08 11:52:42 -08001614 main.ONOSbench.handle.sendline( "scp sdn@"+ONOS2_ip+":"+log_folder+f+" "+
1615 teststation_user +"@"+teststation_IP+":"+\
Jon Hall73cf9cc2014-11-20 22:28:38 -08001616 dst_dir + str(testname) + "-ONOS2-"+f )
Jon Hall94fd0472014-12-08 11:52:42 -08001617 main.ONOSbench.handle.sendline( "scp sdn@"+ONOS3_ip+":"+log_folder+f+" "+
1618 teststation_user +"@"+teststation_IP+":"+\
Jon Hall73cf9cc2014-11-20 22:28:38 -08001619 dst_dir + str(testname) + "-ONOS3-"+f )
Jon Hall94fd0472014-12-08 11:52:42 -08001620 main.ONOSbench.handle.sendline( "scp sdn@"+ONOS4_ip+":"+log_folder+f+" "+
1621 teststation_user +"@"+teststation_IP+":"+\
Jon Hall73cf9cc2014-11-20 22:28:38 -08001622 dst_dir + str(testname) + "-ONOS4-"+f )
Jon Hall94fd0472014-12-08 11:52:42 -08001623 main.ONOSbench.handle.sendline( "scp sdn@"+ONOS5_ip+":"+log_folder+f+" "+
1624 teststation_user +"@"+teststation_IP+":"+\
Jon Hall73cf9cc2014-11-20 22:28:38 -08001625 dst_dir + str(testname) + "-ONOS5-"+f )
Jon Hall94fd0472014-12-08 11:52:42 -08001626 main.ONOSbench.handle.sendline( "scp sdn@"+ONOS6_ip+":"+log_folder+f+" "+
1627 teststation_user +"@"+teststation_IP+":"+\
Jon Hall73cf9cc2014-11-20 22:28:38 -08001628 dst_dir + str(testname) + "-ONOS6-"+f )
Jon Hall94fd0472014-12-08 11:52:42 -08001629 main.ONOSbench.handle.sendline( "scp sdn@"+ONOS7_ip+":"+log_folder+f+" "+
1630 teststation_user +"@"+teststation_IP+":"+\
Jon Hall73cf9cc2014-11-20 22:28:38 -08001631 dst_dir + str(testname) + "-ONOS7-"+f )
1632
1633 #std*.log's
1634 #NOTE: must end in /
1635 log_folder = "/opt/onos/var/"
1636 log_files = ["stderr.log", "stdout.log"]
1637 #NOTE: must end in /
1638 dst_dir = "~/packet_captures/"
1639 for f in log_files:
Jon Hall94fd0472014-12-08 11:52:42 -08001640 main.ONOSbench.handle.sendline( "scp sdn@"+ONOS1_ip+":"+log_folder+f+" "+
1641 teststation_user +"@"+teststation_IP+":"+\
Jon Hall73cf9cc2014-11-20 22:28:38 -08001642 dst_dir + str(testname) + "-ONOS1-"+f )
Jon Hall94fd0472014-12-08 11:52:42 -08001643 main.ONOSbench.handle.sendline( "scp sdn@"+ONOS2_ip+":"+log_folder+f+" "+
1644 teststation_user +"@"+teststation_IP+":"+\
Jon Hall73cf9cc2014-11-20 22:28:38 -08001645 dst_dir + str(testname) + "-ONOS2-"+f )
Jon Hall94fd0472014-12-08 11:52:42 -08001646 main.ONOSbench.handle.sendline( "scp sdn@"+ONOS3_ip+":"+log_folder+f+" "+
1647 teststation_user +"@"+teststation_IP+":"+\
Jon Hall73cf9cc2014-11-20 22:28:38 -08001648 dst_dir + str(testname) + "-ONOS3-"+f )
Jon Hall94fd0472014-12-08 11:52:42 -08001649 main.ONOSbench.handle.sendline( "scp sdn@"+ONOS4_ip+":"+log_folder+f+" "+
1650 teststation_user +"@"+teststation_IP+":"+\
Jon Hall73cf9cc2014-11-20 22:28:38 -08001651 dst_dir + str(testname) + "-ONOS4-"+f )
Jon Hall94fd0472014-12-08 11:52:42 -08001652 main.ONOSbench.handle.sendline( "scp sdn@"+ONOS5_ip+":"+log_folder+f+" "+
1653 teststation_user +"@"+teststation_IP+":"+\
Jon Hall73cf9cc2014-11-20 22:28:38 -08001654 dst_dir + str(testname) + "-ONOS5-"+f )
Jon Hall94fd0472014-12-08 11:52:42 -08001655 main.ONOSbench.handle.sendline( "scp sdn@"+ONOS6_ip+":"+log_folder+f+" "+
1656 teststation_user +"@"+teststation_IP+":"+\
Jon Hall73cf9cc2014-11-20 22:28:38 -08001657 dst_dir + str(testname) + "-ONOS6-"+f )
Jon Hall94fd0472014-12-08 11:52:42 -08001658 main.ONOSbench.handle.sendline( "scp sdn@"+ONOS7_ip+":"+log_folder+f+" "+
1659 teststation_user +"@"+teststation_IP+":"+\
Jon Hall73cf9cc2014-11-20 22:28:38 -08001660 dst_dir + str(testname) + "-ONOS7-"+f )
1661
1662
Jon Hall73cf9cc2014-11-20 22:28:38 -08001663 #sleep so scp can finish
1664 time.sleep(10)
1665 main.step("Packing and rotating pcap archives")
1666 os.system("~/TestON/dependencies/rotate.sh "+ str(testname))
1667
1668
1669 #TODO: actually check something here
1670 utilities.assert_equals(expect=main.TRUE, actual=main.TRUE,
1671 onpass="Test cleanup successful",
1672 onfail="Test cleanup NOT successful")