blob: 614d514b4f6e419723abefdde01d315d071b9394 [file] [log] [blame]
Jon Hallb1290e82014-11-18 16:17:48 -05001'''
2Description: This test is to determine if the HA test setup is
3 working correctly. There are no failures so this test should
4 have a 100% pass rate
5
6List of test cases:
7CASE1: Compile ONOS and push it to the test machines
8CASE2: Assign mastership to controllers
9CASE3: Assign intents
10CASE4: Ping across added host intents
11CASE5: Reading state of ONOS
12CASE6: The Failure case. Since this is the Sanity test, we do nothing.
Jon Hall368769f2014-11-19 15:43:35 -080013CASE7: Check state after control plane failure
Jon Hallb1290e82014-11-18 16:17:48 -050014CASE8: Compare topo
15CASE9: Link s3-s28 down
16CASE10: Link s3-s28 up
17CASE11: Switch down
18CASE12: Switch up
19CASE13: Clean up
20'''
21class HATestSanity:
22
23 def __init__(self) :
24 self.default = ''
25
26 def CASE1(self,main) :
27 '''
28 CASE1 is to compile ONOS and push it to the test machines
29
30 Startup sequence:
31 git pull
32 mvn clean install
33 onos-package
34 cell <name>
35 onos-verify-cell
36 NOTE: temporary - onos-remove-raft-logs
37 onos-install -f
38 onos-wait-for-start
39 '''
40 import time
Jon Hall368769f2014-11-19 15:43:35 -080041 main.log.report("ONOS HA Sanity test - initialization")
Jon Hallb1290e82014-11-18 16:17:48 -050042 main.case("Setting up test environment")
Jon Hallffb386d2014-11-21 13:43:38 -080043 #TODO: save all the timers and output them for plotting
Jon Hallb1290e82014-11-18 16:17:48 -050044
45 # load some vairables from the params file
46 PULL_CODE = False
47 if main.params['Git'] == 'True':
48 PULL_CODE = True
49 cell_name = main.params['ENV']['cellName']
50
51 #set global variables
52 global ONOS1_ip
53 global ONOS1_port
54 global ONOS2_ip
55 global ONOS2_port
56 global ONOS3_ip
57 global ONOS3_port
58 global ONOS4_ip
59 global ONOS4_port
60 global ONOS5_ip
61 global ONOS5_port
62 global ONOS6_ip
63 global ONOS6_port
64 global ONOS7_ip
65 global ONOS7_port
66
67 ONOS1_ip = main.params['CTRL']['ip1']
68 ONOS1_port = main.params['CTRL']['port1']
69 ONOS2_ip = main.params['CTRL']['ip2']
70 ONOS2_port = main.params['CTRL']['port2']
71 ONOS3_ip = main.params['CTRL']['ip3']
72 ONOS3_port = main.params['CTRL']['port3']
73 ONOS4_ip = main.params['CTRL']['ip4']
74 ONOS4_port = main.params['CTRL']['port4']
75 ONOS5_ip = main.params['CTRL']['ip5']
76 ONOS5_port = main.params['CTRL']['port5']
77 ONOS6_ip = main.params['CTRL']['ip6']
78 ONOS6_port = main.params['CTRL']['port6']
79 ONOS7_ip = main.params['CTRL']['ip7']
80 ONOS7_port = main.params['CTRL']['port7']
81
82
83 main.step("Applying cell variable to environment")
84 cell_result = main.ONOSbench.set_cell(cell_name)
85 verify_result = main.ONOSbench.verify_cell()
Jon Hall368769f2014-11-19 15:43:35 -080086
Jon Hallffb386d2014-11-21 13:43:38 -080087 #FIXME:this is short term fix
Jon Hall73cf9cc2014-11-20 22:28:38 -080088 main.log.report("Removing raft logs")
Jon Hallb1290e82014-11-18 16:17:48 -050089 main.ONOSbench.onos_remove_raft_logs()
Jon Hall73cf9cc2014-11-20 22:28:38 -080090 main.log.report("Uninstalling ONOS")
91 main.ONOSbench.onos_uninstall(ONOS1_ip)
92 main.ONOSbench.onos_uninstall(ONOS2_ip)
93 main.ONOSbench.onos_uninstall(ONOS3_ip)
94 main.ONOSbench.onos_uninstall(ONOS4_ip)
95 main.ONOSbench.onos_uninstall(ONOS5_ip)
96 main.ONOSbench.onos_uninstall(ONOS6_ip)
97 main.ONOSbench.onos_uninstall(ONOS7_ip)
Jon Hallb1290e82014-11-18 16:17:48 -050098
99 clean_install_result = main.TRUE
100 git_pull_result = main.TRUE
101
102 main.step("Compiling the latest version of ONOS")
103 if PULL_CODE:
104 main.step("Git checkout and pull master")
105 main.ONOSbench.git_checkout("master")
106 git_pull_result = main.ONOSbench.git_pull()
107
108 main.step("Using mvn clean & install")
109 clean_install_result = main.TRUE
110 if git_pull_result == main.TRUE:
111 clean_install_result = main.ONOSbench.clean_install()
112 else:
Jon Hall368769f2014-11-19 15:43:35 -0800113 main.log.warn("Did not pull new code so skipping mvn "+ \
Jon Hallb1290e82014-11-18 16:17:48 -0500114 "clean install")
115 main.ONOSbench.get_version(report=True)
116
117 main.step("Creating ONOS package")
118 package_result = main.ONOSbench.onos_package()
119
120 main.step("Installing ONOS package")
121 onos1_install_result = main.ONOSbench.onos_install(options="-f",
122 node=ONOS1_ip)
123 onos2_install_result = main.ONOSbench.onos_install(options="-f",
124 node=ONOS2_ip)
125 onos3_install_result = main.ONOSbench.onos_install(options="-f",
126 node=ONOS3_ip)
127 onos4_install_result = main.ONOSbench.onos_install(options="-f",
128 node=ONOS4_ip)
129 onos5_install_result = main.ONOSbench.onos_install(options="-f",
130 node=ONOS5_ip)
131 onos6_install_result = main.ONOSbench.onos_install(options="-f",
132 node=ONOS6_ip)
133 onos7_install_result = main.ONOSbench.onos_install(options="-f",
134 node=ONOS7_ip)
135 onos_install_result = onos1_install_result and onos2_install_result\
136 and onos3_install_result and onos4_install_result\
137 and onos5_install_result and onos6_install_result\
138 and onos7_install_result
Jon Hall73cf9cc2014-11-20 22:28:38 -0800139 '''
140 #FIXME: work around until onos is less fragile
141 main.ONOSbench.handle.sendline("onos-cluster-install")
142 print main.ONOSbench.handle.expect("\$")
143 onos_install_result = main.TRUE
144 '''
Jon Hallb1290e82014-11-18 16:17:48 -0500145
146
147 main.step("Checking if ONOS is up yet")
Jon Hall73cf9cc2014-11-20 22:28:38 -0800148 #TODO: Refactor
149 # check bundle:list?
Jon Hallffb386d2014-11-21 13:43:38 -0800150 for i in range(2):
151 onos1_isup = main.ONOSbench.isup(ONOS1_ip)
152 if not onos1_isup:
153 main.log.report("ONOS1 didn't start!")
154 onos2_isup = main.ONOSbench.isup(ONOS2_ip)
155 if not onos2_isup:
156 main.log.report("ONOS2 didn't start!")
157 onos3_isup = main.ONOSbench.isup(ONOS3_ip)
158 if not onos3_isup:
159 main.log.report("ONOS3 didn't start!")
160 onos4_isup = main.ONOSbench.isup(ONOS4_ip)
161 if not onos4_isup:
162 main.log.report("ONOS4 didn't start!")
163 onos5_isup = main.ONOSbench.isup(ONOS5_ip)
164 if not onos5_isup:
165 main.log.report("ONOS5 didn't start!")
166 onos6_isup = main.ONOSbench.isup(ONOS6_ip)
167 if not onos6_isup:
168 main.log.report("ONOS6 didn't start!")
169 onos7_isup = main.ONOSbench.isup(ONOS7_ip)
170 if not onos7_isup:
171 main.log.report("ONOS7 didn't start!")
172 onos_isup_result = onos1_isup and onos2_isup and onos3_isup\
173 and onos4_isup and onos5_isup and onos6_isup and onos7_isup
174 if onos_isup_result == main.TRUE:
175 break
Jon Hallb1290e82014-11-18 16:17:48 -0500176 # TODO: if it becomes an issue, we can retry this step a few times
177
178
Jon Hall73cf9cc2014-11-20 22:28:38 -0800179 cli_result1 = main.ONOScli1.start_onos_cli(ONOS1_ip)
180 cli_result2 = main.ONOScli2.start_onos_cli(ONOS2_ip)
181 cli_result3 = main.ONOScli3.start_onos_cli(ONOS3_ip)
182 cli_result4 = main.ONOScli4.start_onos_cli(ONOS4_ip)
183 cli_result5 = main.ONOScli5.start_onos_cli(ONOS5_ip)
184 cli_result6 = main.ONOScli6.start_onos_cli(ONOS6_ip)
185 cli_result7 = main.ONOScli7.start_onos_cli(ONOS7_ip)
186 cli_results = cli_result1 and cli_result2 and cli_result3 and\
187 cli_result4 and cli_result5 and cli_result6 and cli_result7
Jon Hallb1290e82014-11-18 16:17:48 -0500188
Jon Hall368769f2014-11-19 15:43:35 -0800189 main.step("Start Packet Capture MN")
190 main.Mininet2.start_tcpdump(
191 str(main.params['MNtcpdump']['folder'])+str(main.TEST)+"-MN.pcap",
192 intf = main.params['MNtcpdump']['intf'],
193 port = main.params['MNtcpdump']['port'])
Jon Hallb1290e82014-11-18 16:17:48 -0500194
195
196 case1_result = (clean_install_result and package_result and
197 cell_result and verify_result and onos_install_result and
Jon Hall73cf9cc2014-11-20 22:28:38 -0800198 onos_isup_result and cli_results)
Jon Hallb1290e82014-11-18 16:17:48 -0500199
200 utilities.assert_equals(expect=main.TRUE, actual=case1_result,
201 onpass="Test startup successful",
202 onfail="Test startup NOT successful")
203
204
Jon Hallffb386d2014-11-21 13:43:38 -0800205 if case1_result==main.FALSE:
206 main.cleanup()
207 main.exit()
Jon Hallb1290e82014-11-18 16:17:48 -0500208
209 def CASE2(self,main) :
210 '''
211 Assign mastership to controllers
212 '''
213 import time
214 import json
215 import re
216
217
218 '''
219 ONOS1_ip = main.params['CTRL']['ip1']
220 ONOS1_port = main.params['CTRL']['port1']
221 ONOS2_ip = main.params['CTRL']['ip2']
222 ONOS2_port = main.params['CTRL']['port2']
223 ONOS3_ip = main.params['CTRL']['ip3']
224 ONOS3_port = main.params['CTRL']['port3']
225 ONOS4_ip = main.params['CTRL']['ip4']
226 ONOS4_port = main.params['CTRL']['port4']
227 ONOS5_ip = main.params['CTRL']['ip5']
228 ONOS5_port = main.params['CTRL']['port5']
229 ONOS6_ip = main.params['CTRL']['ip6']
230 ONOS6_port = main.params['CTRL']['port6']
231 ONOS7_ip = main.params['CTRL']['ip7']
232 ONOS7_port = main.params['CTRL']['port7']
233 '''
234
235
236 main.log.report("Assigning switches to controllers")
237 main.case("Assigning Controllers")
238 main.step("Assign switches to controllers")
239
240 for i in range (1,29):
241 main.Mininet1.assign_sw_controller(sw=str(i),count=7,
242 ip1=ONOS1_ip,port1=ONOS1_port,
243 ip2=ONOS2_ip,port2=ONOS2_port,
244 ip3=ONOS3_ip,port3=ONOS3_port,
245 ip4=ONOS4_ip,port4=ONOS4_port,
246 ip5=ONOS5_ip,port5=ONOS5_port,
247 ip6=ONOS6_ip,port6=ONOS6_port,
248 ip7=ONOS7_ip,port7=ONOS7_port)
249
250 mastership_check = main.TRUE
251 for i in range (1,29):
252 response = main.Mininet1.get_sw_controller("s"+str(i))
Jon Hallffb386d2014-11-21 13:43:38 -0800253 try:
254 main.log.info(str(response))
255 except:
256 main.log.info(repr(response))
Jon Hallb1290e82014-11-18 16:17:48 -0500257 if re.search("tcp:"+ONOS1_ip,response)\
258 and re.search("tcp:"+ONOS2_ip,response)\
259 and re.search("tcp:"+ONOS3_ip,response)\
260 and re.search("tcp:"+ONOS4_ip,response)\
261 and re.search("tcp:"+ONOS5_ip,response)\
262 and re.search("tcp:"+ONOS6_ip,response)\
263 and re.search("tcp:"+ONOS7_ip,response):
264 mastership_check = mastership_check and main.TRUE
265 else:
266 mastership_check = main.FALSE
267 if mastership_check == main.TRUE:
268 main.log.report("Switch mastership assigned correctly")
269 utilities.assert_equals(expect = main.TRUE,actual=mastership_check,
270 onpass="Switch mastership assigned correctly",
271 onfail="Switches not assigned correctly to controllers")
272
273 #TODO: If assign roles is working reliably then manually
274 # assign mastership to the controller we want
275
276
277 def CASE3(self,main) :
278 """
279 Assign intents
280
281 """
282 import time
283 import json
284 import re
285 main.log.report("Adding host intents")
286 main.case("Adding host Intents")
287
288 main.step("Discovering Hosts( Via pingall for now)")
289 #FIXME: Once we have a host discovery mechanism, use that instead
290
291 #REACTIVE FWD test
292 ping_result = main.FALSE
293 time1 = time.time()
294 ping_result = main.Mininet1.pingall()
295 time2 = time.time()
296 main.log.info("Time for pingall: %2f seconds" % (time2 - time1))
297
298 #uninstall onos-app-fwd
299 main.log.info("Uninstall reactive forwarding app")
300 main.ONOScli1.feature_uninstall("onos-app-fwd")
301 main.ONOScli2.feature_uninstall("onos-app-fwd")
302 main.ONOScli3.feature_uninstall("onos-app-fwd")
303 main.ONOScli4.feature_uninstall("onos-app-fwd")
304 main.ONOScli5.feature_uninstall("onos-app-fwd")
305 main.ONOScli6.feature_uninstall("onos-app-fwd")
306 main.ONOScli7.feature_uninstall("onos-app-fwd")
307
308 main.step("Add host intents")
309 #TODO: move the host numbers to params
310 import json
311 intents_json= json.loads(main.ONOScli1.hosts())
312 intent_add_result = main.FALSE
313 for i in range(8,18):
314 main.log.info("Adding host intent between h"+str(i)+" and h"+str(i+10))
315 host1 = "00:00:00:00:00:" + str(hex(i)[2:]).zfill(2).upper()
316 host2 = "00:00:00:00:00:" + str(hex(i+10)[2:]).zfill(2).upper()
317 #NOTE: get host can return None
318 #TODO: handle this
319 host1_id = main.ONOScli1.get_host(host1)['id']
320 host2_id = main.ONOScli1.get_host(host2)['id']
321 tmp_result = main.ONOScli1.add_host_intent(host1_id, host2_id )
322 intent_add_result = intent_add_result and tmp_result
323 #TODO Check if intents all exist in datastore
324 #NOTE: Do we need to print this once the test is working?
325 #main.log.info(json.dumps(json.loads(main.ONOScli1.intents(json_format=True)),
326 # sort_keys=True, indent=4, separators=(',', ': ') ) )
327
328 def CASE4(self,main) :
329 """
330 Ping across added host intents
331 """
Jon Hall368769f2014-11-19 15:43:35 -0800332 description = " Ping across added host intents"
333 main.log.report(description)
334 main.case(description)
Jon Hallb1290e82014-11-18 16:17:48 -0500335 Ping_Result = main.TRUE
336 for i in range(8,18):
337 ping = main.Mininet1.pingHost(src="h"+str(i),target="h"+str(i+10))
338 Ping_Result = Ping_Result and ping
339 if ping==main.FALSE:
340 main.log.warn("Ping failed between h"+str(i)+" and h" + str(i+10))
341 elif ping==main.TRUE:
342 main.log.info("Ping test passed!")
343 Ping_Result = main.TRUE
344 if Ping_Result==main.FALSE:
345 main.log.report("Intents have not been installed correctly, pings failed.")
346 if Ping_Result==main.TRUE:
Jon Hall368769f2014-11-19 15:43:35 -0800347 main.log.report("Intents have been installed correctly and verified by pings")
Jon Hallb1290e82014-11-18 16:17:48 -0500348 utilities.assert_equals(expect = main.TRUE,actual=Ping_Result,
Jon Hall368769f2014-11-19 15:43:35 -0800349 onpass="Intents have been installed correctly and pings work",
350 onfail ="Intents have not been installed correctly, pings failed." )
Jon Hallb1290e82014-11-18 16:17:48 -0500351
352 def CASE5(self,main) :
353 '''
354 Reading state of ONOS
355 '''
356 import time
357 import json
358 from subprocess import Popen, PIPE
359 from sts.topology.teston_topology import TestONTopology # assumes that sts is already in you PYTHONPATH
360
361 main.log.report("Setting up and gathering data for current state")
362 main.case("Setting up and gathering data for current state")
363 #The general idea for this test case is to pull the state of (intents,flows, topology,...) from each ONOS node
364 #We can then compare them with eachother and also with past states
365
366 main.step("Get the Mastership of each switch from each controller")
367 global mastership_state
368 ONOS1_mastership = main.ONOScli1.roles()
369 ONOS2_mastership = main.ONOScli2.roles()
370 ONOS3_mastership = main.ONOScli3.roles()
371 ONOS4_mastership = main.ONOScli4.roles()
372 ONOS5_mastership = main.ONOScli5.roles()
373 ONOS6_mastership = main.ONOScli6.roles()
374 ONOS7_mastership = main.ONOScli7.roles()
375 #print json.dumps(json.loads(ONOS1_mastership), sort_keys=True, indent=4, separators=(',', ': '))
Jon Hall73cf9cc2014-11-20 22:28:38 -0800376 if "Error" in ONOS1_mastership or not ONOS1_mastership\
377 or "Error" in ONOS2_mastership or not ONOS2_mastership\
378 or "Error" in ONOS3_mastership or not ONOS3_mastership\
379 or "Error" in ONOS4_mastership or not ONOS4_mastership\
380 or "Error" in ONOS5_mastership or not ONOS5_mastership\
381 or "Error" in ONOS6_mastership or not ONOS6_mastership\
382 or "Error" in ONOS7_mastership or not ONOS7_mastership:
383 main.log.report("Error in getting ONOS roles")
384 main.log.warn("ONOS1 mastership response: " + repr(ONOS1_mastership))
385 main.log.warn("ONOS2 mastership response: " + repr(ONOS2_mastership))
386 main.log.warn("ONOS3 mastership response: " + repr(ONOS3_mastership))
387 main.log.warn("ONOS4 mastership response: " + repr(ONOS4_mastership))
388 main.log.warn("ONOS5 mastership response: " + repr(ONOS5_mastership))
389 main.log.warn("ONOS6 mastership response: " + repr(ONOS6_mastership))
390 main.log.warn("ONOS7 mastership response: " + repr(ONOS7_mastership))
391 consistent_mastership = main.FALSE
392 elif ONOS1_mastership == ONOS2_mastership\
Jon Hallb1290e82014-11-18 16:17:48 -0500393 and ONOS1_mastership == ONOS3_mastership\
394 and ONOS1_mastership == ONOS4_mastership\
395 and ONOS1_mastership == ONOS5_mastership\
396 and ONOS1_mastership == ONOS6_mastership\
397 and ONOS1_mastership == ONOS7_mastership:
398 mastership_state = ONOS1_mastership
399 consistent_mastership = main.TRUE
400 main.log.report("Switch roles are consistent across all ONOS nodes")
401 else:
402 main.log.warn("ONOS1 roles: ", json.dumps(json.loads(ONOS1_mastership),
403 sort_keys=True, indent=4, separators=(',', ': ')))
404 main.log.warn("ONOS2 roles: ", json.dumps(json.loads(ONOS2_mastership),
405 sort_keys=True, indent=4, separators=(',', ': ')))
406 main.log.warn("ONOS3 roles: ", json.dumps(json.loads(ONOS3_mastership),
407 sort_keys=True, indent=4, separators=(',', ': ')))
408 main.log.warn("ONOS4 roles: ", json.dumps(json.loads(ONOS4_mastership),
409 sort_keys=True, indent=4, separators=(',', ': ')))
410 main.log.warn("ONOS5 roles: ", json.dumps(json.loads(ONOS5_mastership),
411 sort_keys=True, indent=4, separators=(',', ': ')))
412 main.log.warn("ONOS6 roles: ", json.dumps(json.loads(ONOS6_mastership),
413 sort_keys=True, indent=4, separators=(',', ': ')))
414 main.log.warn("ONOS7 roles: ", json.dumps(json.loads(ONOS7_mastership),
415 sort_keys=True, indent=4, separators=(',', ': ')))
416 consistent_mastership = main.FALSE
417 utilities.assert_equals(expect = main.TRUE,actual=consistent_mastership,
418 onpass="Switch roles are consistent across all ONOS nodes",
419 onfail="ONOS nodes have different views of switch roles")
420
421
422 main.step("Get the intents from each controller")
423 global intent_state
424 ONOS1_intents = main.ONOScli1.intents( json_format=True )
425 ONOS2_intents = main.ONOScli2.intents( json_format=True )
426 ONOS3_intents = main.ONOScli3.intents( json_format=True )
427 ONOS4_intents = main.ONOScli4.intents( json_format=True )
428 ONOS5_intents = main.ONOScli5.intents( json_format=True )
429 ONOS6_intents = main.ONOScli6.intents( json_format=True )
430 ONOS7_intents = main.ONOScli7.intents( json_format=True )
431 intent_check = main.FALSE
Jon Hall73cf9cc2014-11-20 22:28:38 -0800432 if "Error" in ONOS1_intents or not ONOS1_intents\
433 or "Error" in ONOS2_intents or not ONOS2_intents\
434 or "Error" in ONOS3_intents or not ONOS3_intents\
435 or "Error" in ONOS4_intents or not ONOS4_intents\
436 or "Error" in ONOS5_intents or not ONOS5_intents\
437 or "Error" in ONOS6_intents or not ONOS6_intents\
438 or "Error" in ONOS7_intents or not ONOS7_intents:
439 main.log.report("Error in getting ONOS intents")
440 main.log.warn("ONOS1 intents response: " + repr(ONOS1_intents))
441 main.log.warn("ONOS2 intents response: " + repr(ONOS2_intents))
442 main.log.warn("ONOS3 intents response: " + repr(ONOS3_intents))
443 main.log.warn("ONOS4 intents response: " + repr(ONOS4_intents))
444 main.log.warn("ONOS5 intents response: " + repr(ONOS5_intents))
445 main.log.warn("ONOS6 intents response: " + repr(ONOS6_intents))
446 main.log.warn("ONOS7 intents response: " + repr(ONOS7_intents))
Jon Hallb1290e82014-11-18 16:17:48 -0500447 elif ONOS1_intents == ONOS2_intents\
448 and ONOS1_intents == ONOS3_intents\
449 and ONOS1_intents == ONOS4_intents\
450 and ONOS1_intents == ONOS5_intents\
451 and ONOS1_intents == ONOS6_intents\
452 and ONOS1_intents == ONOS7_intents:
453 intent_state = ONOS1_intents
454 intent_check = main.TRUE
455 main.log.report("Intents are consistent across all ONOS nodes")
456 else:
457 main.log.warn("ONOS1 intents: ", json.dumps(json.loads(ONOS1_intents),
458 sort_keys=True, indent=4, separators=(',', ': ')))
459 main.log.warn("ONOS2 intents: ", json.dumps(json.loads(ONOS2_intents),
460 sort_keys=True, indent=4, separators=(',', ': ')))
461 main.log.warn("ONOS3 intents: ", json.dumps(json.loads(ONOS3_intents),
462 sort_keys=True, indent=4, separators=(',', ': ')))
463 main.log.warn("ONOS4 intents: ", json.dumps(json.loads(ONOS4_intents),
464 sort_keys=True, indent=4, separators=(',', ': ')))
465 main.log.warn("ONOS5 intents: ", json.dumps(json.loads(ONOS5_intents),
466 sort_keys=True, indent=4, separators=(',', ': ')))
467 main.log.warn("ONOS6 intents: ", json.dumps(json.loads(ONOS6_intents),
468 sort_keys=True, indent=4, separators=(',', ': ')))
469 main.log.warn("ONOS7 intents: ", json.dumps(json.loads(ONOS7_intents),
470 sort_keys=True, indent=4, separators=(',', ': ')))
471 utilities.assert_equals(expect = main.TRUE,actual=intent_check,
472 onpass="Intents are consistent across all ONOS nodes",
473 onfail="ONOS nodes have different views of intents")
474
475
476 main.step("Get the flows from each controller")
477 global flow_state
478 ONOS1_flows = main.ONOScli1.flows( json_format=True )
479 ONOS2_flows = main.ONOScli2.flows( json_format=True )
480 ONOS3_flows = main.ONOScli3.flows( json_format=True )
481 ONOS4_flows = main.ONOScli4.flows( json_format=True )
482 ONOS5_flows = main.ONOScli5.flows( json_format=True )
483 ONOS6_flows = main.ONOScli6.flows( json_format=True )
484 ONOS7_flows = main.ONOScli7.flows( json_format=True )
485 flow_check = main.FALSE
Jon Hall73cf9cc2014-11-20 22:28:38 -0800486 if "Error" in ONOS1_flows or not ONOS1_flows\
487 or "Error" in ONOS2_flows or not ONOS2_flows\
488 or "Error" in ONOS3_flows or not ONOS3_flows\
489 or "Error" in ONOS4_flows or not ONOS4_flows\
490 or "Error" in ONOS5_flows or not ONOS5_flows\
491 or "Error" in ONOS6_flows or not ONOS6_flows\
492 or "Error" in ONOS7_flows or not ONOS7_flows:
493 main.log.report("Error in getting ONOS intents")
Jon Hallb1290e82014-11-18 16:17:48 -0500494 main.log.warn("ONOS1 flows repsponse: "+ ONOS1_flows)
495 main.log.warn("ONOS2 flows repsponse: "+ ONOS2_flows)
496 main.log.warn("ONOS3 flows repsponse: "+ ONOS3_flows)
497 main.log.warn("ONOS4 flows repsponse: "+ ONOS4_flows)
498 main.log.warn("ONOS5 flows repsponse: "+ ONOS5_flows)
499 main.log.warn("ONOS6 flows repsponse: "+ ONOS6_flows)
500 main.log.warn("ONOS7 flows repsponse: "+ ONOS7_flows)
501 elif len(json.loads(ONOS1_flows)) == len(json.loads(ONOS2_flows))\
502 and len(json.loads(ONOS1_flows)) == len(json.loads(ONOS3_flows))\
503 and len(json.loads(ONOS1_flows)) == len(json.loads(ONOS4_flows))\
504 and len(json.loads(ONOS1_flows)) == len(json.loads(ONOS5_flows))\
505 and len(json.loads(ONOS1_flows)) == len(json.loads(ONOS6_flows))\
506 and len(json.loads(ONOS1_flows)) == len(json.loads(ONOS7_flows)):
507 #TODO: Do a better check, maybe compare flows on switches?
508 flow_state = ONOS1_flows
509 flow_check = main.TRUE
510 main.log.report("Flow count is consistent across all ONOS nodes")
511 else:
512 main.log.warn("ONOS1 flows: "+ json.dumps(json.loads(ONOS1_flows),
513 sort_keys=True, indent=4, separators=(',', ': ')))
514 main.log.warn("ONOS2 flows: "+ json.dumps(json.loads(ONOS2_flows),
515 sort_keys=True, indent=4, separators=(',', ': ')))
516 main.log.warn("ONOS3 flows: "+ json.dumps(json.loads(ONOS3_flows),
517 sort_keys=True, indent=4, separators=(',', ': ')))
518 main.log.warn("ONOS4 flows: "+ json.dumps(json.loads(ONOS4_flows),
519 sort_keys=True, indent=4, separators=(',', ': ')))
520 main.log.warn("ONOS5 flows: "+ json.dumps(json.loads(ONOS5_flows),
521 sort_keys=True, indent=4, separators=(',', ': ')))
522 main.log.warn("ONOS6 flows: "+ json.dumps(json.loads(ONOS6_flows),
523 sort_keys=True, indent=4, separators=(',', ': ')))
524 main.log.warn("ONOS7 flows: "+ json.dumps(json.loads(ONOS7_flows),
525 sort_keys=True, indent=4, separators=(',', ': ')))
526 utilities.assert_equals(expect = main.TRUE,actual=flow_check,
527 onpass="The flow count is consistent across all ONOS nodes",
528 onfail="ONOS nodes have different flow counts")
529
530
531 main.step("Get the OF Table entries")
532 global flows
533 flows=[]
534 for i in range(1,29):
535 flows.append(main.Mininet2.get_flowTable("s"+str(i),1.0))
536
537 #TODO: Compare switch flow tables with ONOS flow tables
538
539 main.step("Start continuous pings")
540 main.Mininet2.pingLong(src=main.params['PING']['source1'],
541 target=main.params['PING']['target1'],pingTime=500)
542 main.Mininet2.pingLong(src=main.params['PING']['source2'],
543 target=main.params['PING']['target2'],pingTime=500)
544 main.Mininet2.pingLong(src=main.params['PING']['source3'],
545 target=main.params['PING']['target3'],pingTime=500)
546 main.Mininet2.pingLong(src=main.params['PING']['source4'],
547 target=main.params['PING']['target4'],pingTime=500)
548 main.Mininet2.pingLong(src=main.params['PING']['source5'],
549 target=main.params['PING']['target5'],pingTime=500)
550 main.Mininet2.pingLong(src=main.params['PING']['source6'],
551 target=main.params['PING']['target6'],pingTime=500)
552 main.Mininet2.pingLong(src=main.params['PING']['source7'],
553 target=main.params['PING']['target7'],pingTime=500)
554 main.Mininet2.pingLong(src=main.params['PING']['source8'],
555 target=main.params['PING']['target8'],pingTime=500)
556 main.Mininet2.pingLong(src=main.params['PING']['source9'],
557 target=main.params['PING']['target9'],pingTime=500)
558 main.Mininet2.pingLong(src=main.params['PING']['source10'],
559 target=main.params['PING']['target10'],pingTime=500)
560
561 main.step("Create TestONTopology object")
562 ctrls = []
563 count = 1
564 while True:
565 temp = ()
566 if ('ip' + str(count)) in main.params['CTRL']:
567 temp = temp + (getattr(main,('ONOS' + str(count))),)
568 temp = temp + ("ONOS"+str(count),)
569 temp = temp + (main.params['CTRL']['ip'+str(count)],)
570 temp = temp + (eval(main.params['CTRL']['port'+str(count)]),)
571 ctrls.append(temp)
572 count = count + 1
573 else:
574 break
575 MNTopo = TestONTopology(main.Mininet1, ctrls) # can also add Intent API info for intent operations
576
577 main.step("Collecting topology information from ONOS")
578 devices = []
579 devices.append( main.ONOScli1.devices() )
580 devices.append( main.ONOScli2.devices() )
581 devices.append( main.ONOScli3.devices() )
582 devices.append( main.ONOScli4.devices() )
583 devices.append( main.ONOScli5.devices() )
584 devices.append( main.ONOScli6.devices() )
585 devices.append( main.ONOScli7.devices() )
586 '''
587 hosts = []
588 hosts.append( main.ONOScli1.hosts() )
589 hosts.append( main.ONOScli2.hosts() )
590 hosts.append( main.ONOScli3.hosts() )
591 hosts.append( main.ONOScli4.hosts() )
592 hosts.append( main.ONOScli5.hosts() )
593 hosts.append( main.ONOScli6.hosts() )
594 hosts.append( main.ONOScli7.hosts() )
595 '''
596 ports = []
597 ports.append( main.ONOScli1.ports() )
598 ports.append( main.ONOScli2.ports() )
599 ports.append( main.ONOScli3.ports() )
600 ports.append( main.ONOScli4.ports() )
601 ports.append( main.ONOScli5.ports() )
602 ports.append( main.ONOScli6.ports() )
603 ports.append( main.ONOScli7.ports() )
604 links = []
605 links.append( main.ONOScli1.links() )
606 links.append( main.ONOScli2.links() )
607 links.append( main.ONOScli3.links() )
608 links.append( main.ONOScli4.links() )
609 links.append( main.ONOScli5.links() )
610 links.append( main.ONOScli6.links() )
611 links.append( main.ONOScli7.links() )
612
613
614 main.step("Comparing ONOS topology to MN")
615 devices_results = main.TRUE
616 ports_results = main.TRUE
617 links_results = main.TRUE
618 for controller in range(7): #TODO parameterize the number of controllers
Jon Hall73cf9cc2014-11-20 22:28:38 -0800619 if devices[controller] or not "Error" in devices[controller]:
620 current_devices_result = main.Mininet1.compare_switches(MNTopo, json.loads(devices[controller]))
621 else:
622 current_devices_result = main.FALSE
Jon Hallb1290e82014-11-18 16:17:48 -0500623 utilities.assert_equals(expect=main.TRUE, actual=current_devices_result,
624 onpass="ONOS"+str(int(controller+1))+" Switches view is correct",
625 onfail="ONOS"+str(int(controller+1))+" Switches view is incorrect")
626
Jon Hall73cf9cc2014-11-20 22:28:38 -0800627 if ports[controller] or not "Error" in ports[controller]:
628 current_ports_result = main.Mininet1.compare_ports(MNTopo, json.loads(ports[controller]))
629 else:
630 current_ports_result = main.FALSE
Jon Hallb1290e82014-11-18 16:17:48 -0500631 utilities.assert_equals(expect=main.TRUE, actual=current_ports_result,
632 onpass="ONOS"+str(int(controller+1))+" ports view is correct",
633 onfail="ONOS"+str(int(controller+1))+" ports view is incorrect")
634
Jon Hall73cf9cc2014-11-20 22:28:38 -0800635 if links[controller] or not "Error" in links[controller]:
636 current_links_result = main.Mininet1.compare_links(MNTopo, json.loads(links[controller]))
637 else:
638 current_links_result = main.FALSE
Jon Hallb1290e82014-11-18 16:17:48 -0500639 utilities.assert_equals(expect=main.TRUE, actual=current_links_result,
640 onpass="ONOS"+str(int(controller+1))+" links view is correct",
641 onfail="ONOS"+str(int(controller+1))+" links view is incorrect")
642
643 devices_results = devices_results and current_devices_result
644 ports_results = ports_results and current_ports_result
645 links_results = links_results and current_links_result
646
647 topo_result = devices_results and ports_results and links_results
648 utilities.assert_equals(expect=main.TRUE, actual=topo_result,
649 onpass="Topology Check Test successful",
650 onfail="Topology Check Test NOT successful")
651
652 final_assert = main.TRUE
653 final_assert = final_assert and topo_result and flow_check \
654 and intent_check and consistent_mastership
655 utilities.assert_equals(expect=main.TRUE, actual=final_assert,
656 onpass="State check successful",
657 onfail="State check NOT successful")
658
659
660 def CASE6(self,main) :
661 '''
662 The Failure case. Since this is the Sanity test, we do nothing.
663 '''
Jon Hall368769f2014-11-19 15:43:35 -0800664 import time
Jon Hall73cf9cc2014-11-20 22:28:38 -0800665 main.log.report("Wait 60 seconds instead of inducing a failure")
Jon Hall368769f2014-11-19 15:43:35 -0800666 time.sleep(60)
667 utilities.assert_equals(expect=main.TRUE, actual=main.TRUE,
668 onpass="Sleeping 60 seconds",
669 onfail="Something is terribly wrong with my math")
Jon Hallb1290e82014-11-18 16:17:48 -0500670
671 def CASE7(self,main) :
672 '''
Jon Hall368769f2014-11-19 15:43:35 -0800673 Check state after ONOS failure
Jon Hallb1290e82014-11-18 16:17:48 -0500674 '''
675 import os
676 import json
677 main.case("Running ONOS Constant State Tests")
678
679 main.step("Check if switch roles are consistent across all nodes")
680 ONOS1_mastership = main.ONOScli1.roles()
681 ONOS2_mastership = main.ONOScli2.roles()
682 ONOS3_mastership = main.ONOScli3.roles()
683 ONOS4_mastership = main.ONOScli4.roles()
684 ONOS5_mastership = main.ONOScli5.roles()
685 ONOS6_mastership = main.ONOScli6.roles()
686 ONOS7_mastership = main.ONOScli7.roles()
687 #print json.dumps(json.loads(ONOS1_mastership), sort_keys=True, indent=4, separators=(',', ': '))
Jon Hall73cf9cc2014-11-20 22:28:38 -0800688 if "Error" in ONOS1_mastership or not ONOS1_mastership\
689 or "Error" in ONOS2_mastership or not ONOS2_mastership\
690 or "Error" in ONOS3_mastership or not ONOS3_mastership\
691 or "Error" in ONOS4_mastership or not ONOS4_mastership\
692 or "Error" in ONOS5_mastership or not ONOS5_mastership\
693 or "Error" in ONOS6_mastership or not ONOS6_mastership\
694 or "Error" in ONOS7_mastership or not ONOS7_mastership:
695 main.log.error("Error in getting ONOS mastership")
696 main.log.warn("ONOS1 mastership response: " + repr(ONOS1_mastership))
697 main.log.warn("ONOS2 mastership response: " + repr(ONOS2_mastership))
698 main.log.warn("ONOS3 mastership response: " + repr(ONOS3_mastership))
699 main.log.warn("ONOS4 mastership response: " + repr(ONOS4_mastership))
700 main.log.warn("ONOS5 mastership response: " + repr(ONOS5_mastership))
701 main.log.warn("ONOS6 mastership response: " + repr(ONOS6_mastership))
702 main.log.warn("ONOS7 mastership response: " + repr(ONOS7_mastership))
703 consistent_mastership = main.FALSE
704 elif ONOS1_mastership == ONOS2_mastership\
Jon Hallb1290e82014-11-18 16:17:48 -0500705 and ONOS1_mastership == ONOS3_mastership\
706 and ONOS1_mastership == ONOS4_mastership\
707 and ONOS1_mastership == ONOS5_mastership\
708 and ONOS1_mastership == ONOS6_mastership\
709 and ONOS1_mastership == ONOS7_mastership:
710 #mastership_state = ONOS1_mastership
711 consistent_mastership = main.TRUE
712 main.log.report("Switch roles are consistent across all ONOS nodes")
713 else:
714 main.log.warn("ONOS1 roles: ", json.dumps(json.loads(ONOS1_mastership),
715 sort_keys=True, indent=4, separators=(',', ': ')))
716 main.log.warn("ONOS2 roles: ", json.dumps(json.loads(ONOS2_mastership),
717 sort_keys=True, indent=4, separators=(',', ': ')))
718 main.log.warn("ONOS3 roles: ", json.dumps(json.loads(ONOS3_mastership),
719 sort_keys=True, indent=4, separators=(',', ': ')))
720 main.log.warn("ONOS4 roles: ", json.dumps(json.loads(ONOS4_mastership),
721 sort_keys=True, indent=4, separators=(',', ': ')))
722 main.log.warn("ONOS5 roles: ", json.dumps(json.loads(ONOS5_mastership),
723 sort_keys=True, indent=4, separators=(',', ': ')))
724 main.log.warn("ONOS6 roles: ", json.dumps(json.loads(ONOS6_mastership),
725 sort_keys=True, indent=4, separators=(',', ': ')))
726 main.log.warn("ONOS7 roles: ", json.dumps(json.loads(ONOS7_mastership),
727 sort_keys=True, indent=4, separators=(',', ': ')))
728 consistent_mastership = main.FALSE
729 utilities.assert_equals(expect = main.TRUE,actual=consistent_mastership,
730 onpass="Switch roles are consistent across all ONOS nodes",
731 onfail="ONOS nodes have different views of switch roles")
732
733
734 description2 = "Compare switch roles from before failure"
735 main.step(description2)
736
Jon Hallb1290e82014-11-18 16:17:48 -0500737 current_json = json.loads(ONOS1_mastership)
738 old_json = json.loads(mastership_state)
739 mastership_check = main.TRUE
740 for i in range(1,29):
741 switchDPID = str(main.Mininet1.getSwitchDPID(switch="s"+str(i)))
742
743 current = [switch['master'] for switch in current_json if switchDPID in switch['id']]
744 old = [switch['master'] for switch in old_json if switchDPID in switch['id']]
745 if current == old:
746 mastership_check = mastership_check and main.TRUE
747 else:
748 main.log.warn("Mastership of switch %s changed" % switchDPID)
749 mastership_check = main.FALSE
750 if mastership_check == main.TRUE:
751 main.log.report("Mastership of Switches was not changed")
752 utilities.assert_equals(expect=main.TRUE,actual=mastership_check,
753 onpass="Mastership of Switches was not changed",
754 onfail="Mastership of some switches changed")
755 mastership_check = mastership_check and consistent_mastership
756
757
758
759 main.step("Get the intents and compare across all nodes")
760 ONOS1_intents = main.ONOScli1.intents( json_format=True )
761 ONOS2_intents = main.ONOScli2.intents( json_format=True )
762 ONOS3_intents = main.ONOScli3.intents( json_format=True )
763 ONOS4_intents = main.ONOScli4.intents( json_format=True )
764 ONOS5_intents = main.ONOScli5.intents( json_format=True )
765 ONOS6_intents = main.ONOScli6.intents( json_format=True )
766 ONOS7_intents = main.ONOScli7.intents( json_format=True )
767 intent_check = main.FALSE
Jon Hall73cf9cc2014-11-20 22:28:38 -0800768 if "Error" in ONOS1_intents or not ONOS1_intents\
769 or "Error" in ONOS2_intents or not ONOS2_intents\
770 or "Error" in ONOS3_intents or not ONOS3_intents\
771 or "Error" in ONOS4_intents or not ONOS4_intents\
772 or "Error" in ONOS5_intents or not ONOS5_intents\
773 or "Error" in ONOS6_intents or not ONOS6_intents\
774 or "Error" in ONOS7_intents or not ONOS7_intents:
775 main.log.report("Error in getting ONOS intents")
776 main.log.warn("ONOS1 intents response: " + repr(ONOS1_intents))
777 main.log.warn("ONOS2 intents response: " + repr(ONOS2_intents))
778 main.log.warn("ONOS3 intents response: " + repr(ONOS3_intents))
779 main.log.warn("ONOS4 intents response: " + repr(ONOS4_intents))
780 main.log.warn("ONOS5 intents response: " + repr(ONOS5_intents))
781 main.log.warn("ONOS6 intents response: " + repr(ONOS6_intents))
782 main.log.warn("ONOS7 intents response: " + repr(ONOS7_intents))
Jon Hallb1290e82014-11-18 16:17:48 -0500783 elif ONOS1_intents == ONOS2_intents\
784 and ONOS1_intents == ONOS3_intents\
785 and ONOS1_intents == ONOS4_intents\
786 and ONOS1_intents == ONOS5_intents\
787 and ONOS1_intents == ONOS6_intents\
788 and ONOS1_intents == ONOS7_intents:
Jon Hallb1290e82014-11-18 16:17:48 -0500789 intent_check = main.TRUE
790 main.log.report("Intents are consistent across all ONOS nodes")
791 else:
792 main.log.warn("ONOS1 intents: ", json.dumps(json.loads(ONOS1_intents),
793 sort_keys=True, indent=4, separators=(',', ': ')))
794 main.log.warn("ONOS2 intents: ", json.dumps(json.loads(ONOS2_intents),
795 sort_keys=True, indent=4, separators=(',', ': ')))
796 main.log.warn("ONOS3 intents: ", json.dumps(json.loads(ONOS3_intents),
797 sort_keys=True, indent=4, separators=(',', ': ')))
798 main.log.warn("ONOS4 intents: ", json.dumps(json.loads(ONOS4_intents),
799 sort_keys=True, indent=4, separators=(',', ': ')))
800 main.log.warn("ONOS5 intents: ", json.dumps(json.loads(ONOS5_intents),
801 sort_keys=True, indent=4, separators=(',', ': ')))
802 main.log.warn("ONOS6 intents: ", json.dumps(json.loads(ONOS6_intents),
803 sort_keys=True, indent=4, separators=(',', ': ')))
804 main.log.warn("ONOS7 intents: ", json.dumps(json.loads(ONOS7_intents),
805 sort_keys=True, indent=4, separators=(',', ': ')))
806 utilities.assert_equals(expect = main.TRUE,actual=intent_check,
807 onpass="Intents are consistent across all ONOS nodes",
808 onfail="ONOS nodes have different views of intents")
809
810 main.step("Compare current intents with intents before the failure")
811 if intent_state == ONOS1_intents:
812 same_intents = main.TRUE
813 main.log.report("Intents are consistent with before failure")
814 #TODO: possibly the states have changed? we may need to figure out what the aceptable states are
815 else:
816 same_intents = main.FALSE
817 utilities.assert_equals(expect = main.TRUE,actual=same_intents,
818 onpass="Intents are consistent with before failure",
819 onfail="The Intents changed during failure")
820 intent_check = intent_check and same_intents
821
822
823
824 main.step("Get the OF Table entries and compare to before component failure")
825 Flow_Tables = main.TRUE
826 flows2=[]
827 for i in range(28):
828 main.log.info("Checking flow table on s" + str(i+1))
829 tmp_flows = main.Mininet2.get_flowTable("s"+str(i+1),1.0)
830 flows2.append(tmp_flows)
831 Flow_Tables = Flow_Tables and main.Mininet2.flow_comp(flow1=flows[i],flow2=tmp_flows)
832 if Flow_Tables == main.FALSE:
833 main.log.info("Differences in flow table for switch: "+str(i+1))
834 break
835 if Flow_Tables == main.TRUE:
836 main.log.report("No changes were found in the flow tables")
837 utilities.assert_equals(expect=main.TRUE,actual=Flow_Tables,
838 onpass="No changes were found in the flow tables",
839 onfail="Changes were found in the flow tables")
840
841 main.step("Check the continuous pings to ensure that no packets were dropped during component failure")
842 #FIXME: This check is always failing. Investigate cause
843 #NOTE: this may be something to do with file permsissions
844 # or slight change in format
845 main.Mininet2.pingKill(main.params['TESTONUSER'], main.params['TESTONIP'])
846 Loss_In_Pings = main.FALSE
847 #NOTE: checkForLoss returns main.FALSE with 0% packet loss
848 for i in range(8,18):
849 main.log.info("Checking for a loss in pings along flow from s" + str(i))
850 Loss_In_Pings = Loss_In_Pings or main.Mininet2.checkForLoss("/tmp/ping.h"+str(i))
851 if Loss_In_Pings == main.TRUE:
852 main.log.info("Loss in ping detected")
853 elif Loss_In_Pings == main.ERROR:
854 main.log.info("There are multiple mininet process running")
855 elif Loss_In_Pings == main.FALSE:
856 main.log.info("No Loss in the pings")
857 main.log.report("No loss of dataplane connectivity")
858 utilities.assert_equals(expect=main.FALSE,actual=Loss_In_Pings,
859 onpass="No Loss of connectivity",
860 onfail="Loss of dataplane connectivity detected")
861
862
863 #TODO:add topology to this or leave as a seperate case?
864 result = mastership_check and intent_check and Flow_Tables and (not Loss_In_Pings)
865 result = int(result)
866 if result == main.TRUE:
867 main.log.report("Constant State Tests Passed")
868 utilities.assert_equals(expect=main.TRUE,actual=result,
869 onpass="Constant State Tests Passed",
870 onfail="Constant state tests failed")
871
872 def CASE8 (self,main):
873 '''
874 Compare topo
875 '''
876 import sys
877 sys.path.append("/home/admin/sts") # Trying to remove some dependancies, #FIXME add this path to params
878 from sts.topology.teston_topology import TestONTopology # assumes that sts is already in you PYTHONPATH
879 import json
Jon Hall73cf9cc2014-11-20 22:28:38 -0800880 import time
Jon Hallb1290e82014-11-18 16:17:48 -0500881
882 description ="Compare ONOS Topology view to Mininet topology"
883 main.case(description)
884 main.log.report(description)
885 main.step("Create TestONTopology object")
886 ctrls = []
887 count = 1
888 while True:
889 temp = ()
890 if ('ip' + str(count)) in main.params['CTRL']:
891 temp = temp + (getattr(main,('ONOS' + str(count))),)
892 temp = temp + ("ONOS"+str(count),)
893 temp = temp + (main.params['CTRL']['ip'+str(count)],)
894 temp = temp + (eval(main.params['CTRL']['port'+str(count)]),)
895 ctrls.append(temp)
896 count = count + 1
897 else:
898 break
899 MNTopo = TestONTopology(main.Mininet1, ctrls) # can also add Intent API info for intent operations
900
Jon Hallb1290e82014-11-18 16:17:48 -0500901 main.step("Comparing ONOS topology to MN")
902 devices_results = main.TRUE
903 ports_results = main.TRUE
904 links_results = main.TRUE
Jon Hall73cf9cc2014-11-20 22:28:38 -0800905 topo_result = main.FALSE
906 start_time = time.time()
907 elapsed = 0
Jon Hallffb386d2014-11-21 13:43:38 -0800908 count = 0
Jon Hall73cf9cc2014-11-20 22:28:38 -0800909 while topo_result == main.FALSE and elapsed < 120:
Jon Hallffb386d2014-11-21 13:43:38 -0800910 print "cond 1:" + str(topo_result == main.FALSE)
911 print "cond 2:" + str(elapsed < 120)
912 count = count + 1
Jon Hall73cf9cc2014-11-20 22:28:38 -0800913 try:
Jon Hallffb386d2014-11-21 13:43:38 -0800914 main.step("Collecting topology information from ONOS")
915 devices = []
916 devices.append( main.ONOScli1.devices() )
917 devices.append( main.ONOScli2.devices() )
918 devices.append( main.ONOScli3.devices() )
919 devices.append( main.ONOScli4.devices() )
920 devices.append( main.ONOScli5.devices() )
921 devices.append( main.ONOScli6.devices() )
922 devices.append( main.ONOScli7.devices() )
923 '''
924 hosts = []
925 hosts.append( main.ONOScli1.hosts() )
926 hosts.append( main.ONOScli2.hosts() )
927 hosts.append( main.ONOScli3.hosts() )
928 hosts.append( main.ONOScli4.hosts() )
929 hosts.append( main.ONOScli5.hosts() )
930 hosts.append( main.ONOScli6.hosts() )
931 hosts.append( main.ONOScli7.hosts() )
932 '''
933 ports = []
934 ports.append( main.ONOScli1.ports() )
935 ports.append( main.ONOScli2.ports() )
936 ports.append( main.ONOScli3.ports() )
937 ports.append( main.ONOScli4.ports() )
938 ports.append( main.ONOScli5.ports() )
939 ports.append( main.ONOScli6.ports() )
940 ports.append( main.ONOScli7.ports() )
941 links = []
942 links.append( main.ONOScli1.links() )
943 links.append( main.ONOScli2.links() )
944 links.append( main.ONOScli3.links() )
945 links.append( main.ONOScli4.links() )
946 links.append( main.ONOScli5.links() )
947 links.append( main.ONOScli6.links() )
948 links.append( main.ONOScli7.links() )
949
Jon Hall73cf9cc2014-11-20 22:28:38 -0800950 for controller in range(7): #TODO parameterize the number of controllers
951 if devices[controller] or not "Error" in devices[controller]:
952 current_devices_result = main.Mininet1.compare_switches(MNTopo, json.loads(devices[controller]))
953 else:
954 current_devices_result = main.FALSE
955 utilities.assert_equals(expect=main.TRUE, actual=current_devices_result,
956 onpass="ONOS"+str(int(controller+1))+" Switches view is correct",
957 onfail="ONOS"+str(int(controller+1))+" Switches view is incorrect")
Jon Hallb1290e82014-11-18 16:17:48 -0500958
Jon Hall73cf9cc2014-11-20 22:28:38 -0800959 if ports[controller] or not "Error" in ports[controller]:
960 current_ports_result = main.Mininet1.compare_ports(MNTopo, json.loads(ports[controller]))
961 else:
962 current_ports_result = main.FALSE
963 utilities.assert_equals(expect=main.TRUE, actual=current_ports_result,
964 onpass="ONOS"+str(int(controller+1))+" ports view is correct",
965 onfail="ONOS"+str(int(controller+1))+" ports view is incorrect")
Jon Hallb1290e82014-11-18 16:17:48 -0500966
Jon Hall73cf9cc2014-11-20 22:28:38 -0800967 if links[controller] or not "Error" in links[controller]:
968 current_links_result = main.Mininet1.compare_links(MNTopo, json.loads(links[controller]))
969 else:
970 current_links_result = main.FALSE
971 utilities.assert_equals(expect=main.TRUE, actual=current_links_result,
972 onpass="ONOS"+str(int(controller+1))+" links view is correct",
973 onfail="ONOS"+str(int(controller+1))+" links view is incorrect")
974 except:
975 main.log.error("something went wrong in topo comparison")
976 main.log.warn( repr( devices ) )
977 main.log.warn( repr( ports ) )
978 main.log.warn( repr( links ) )
Jon Hallb1290e82014-11-18 16:17:48 -0500979
980 devices_results = devices_results and current_devices_result
981 ports_results = ports_results and current_ports_result
982 links_results = links_results and current_links_result
Jon Hallffb386d2014-11-21 13:43:38 -0800983 topo_result = devices_results and ports_results and links_results
984 elapsed = time.time() - start_time
Jon Hall73cf9cc2014-11-20 22:28:38 -0800985 time_threshold = elapsed < 1
Jon Hallffb386d2014-11-21 13:43:38 -0800986 topo_result = topo_result and time_threshold
Jon Hall73cf9cc2014-11-20 22:28:38 -0800987 #TODO make sure this step is non-blocking. IE add a timeout
Jon Hallffb386d2014-11-21 13:43:38 -0800988 main.log.report("Very crass estimate for topology discovery/convergence: " +\
989 str(elapsed) + " seconds, " + str(count) +" tries" )
Jon Hallb1290e82014-11-18 16:17:48 -0500990 utilities.assert_equals(expect=main.TRUE, actual=topo_result,
991 onpass="Topology Check Test successful",
992 onfail="Topology Check Test NOT successful")
993 if topo_result == main.TRUE:
994 main.log.report("ONOS topology view matches Mininet topology")
995
996
997 def CASE9 (self,main):
998 '''
999 Link s3-s28 down
1000 '''
1001 #NOTE: You should probably run a topology check after this
1002
1003 link_sleep = int(main.params['timers']['LinkDiscovery'])
1004
1005 description = "Turn off a link to ensure that Link Discovery is working properly"
1006 main.log.report(description)
1007 main.case(description)
1008
1009
1010 main.step("Kill Link between s3 and s28")
1011 Link_Down = main.Mininet1.link(END1="s3",END2="s28",OPTION="down")
1012 main.log.info("Waiting " + str(link_sleep) + " seconds for link down to be discovered")
1013 time.sleep(link_sleep)
1014 utilities.assert_equals(expect=main.TRUE,actual=Link_Down,
1015 onpass="Link down succesful",
1016 onfail="Failed to bring link down")
1017 #TODO do some sort of check here
1018
1019 def CASE10 (self,main):
1020 '''
1021 Link s3-s28 up
1022 '''
1023 #NOTE: You should probably run a topology check after this
1024
1025 link_sleep = int(main.params['timers']['LinkDiscovery'])
1026
1027 description = "Restore a link to ensure that Link Discovery is working properly"
1028 main.log.report(description)
1029 main.case(description)
1030
1031 main.step("Bring link between s3 and s28 back up")
1032 Link_Up = main.Mininet1.link(END1="s3",END2="s28",OPTION="up")
1033 main.log.info("Waiting " + str(link_sleep) + " seconds for link up to be discovered")
1034 time.sleep(link_sleep)
1035 utilities.assert_equals(expect=main.TRUE,actual=Link_Up,
1036 onpass="Link up succesful",
1037 onfail="Failed to bring link up")
1038 #TODO do some sort of check here
1039
1040
1041 def CASE11 (self, main) :
1042 '''
1043 Switch Down
1044 '''
1045 #NOTE: You should probably run a topology check after this
1046 import time
1047
1048 switch_sleep = int(main.params['timers']['SwitchDiscovery'])
1049
1050 description = "Killing a switch to ensure it is discovered correctly"
1051 main.log.report(description)
1052 main.case(description)
1053
1054 #TODO: Make this switch parameterizable
1055 main.step("Kill s28 ")
1056 main.log.report("Deleting s28")
1057 #FIXME: use new dynamic topo functions
1058 main.Mininet1.del_switch("s28")
1059 main.log.info("Waiting " + str(switch_sleep) + " seconds for switch down to be discovered")
1060 time.sleep(switch_sleep)
1061 #Peek at the deleted switch
1062 main.log.warn(main.ONOScli1.get_device(dpid="0028"))
1063 #TODO do some sort of check here
1064
1065 def CASE12 (self, main) :
1066 '''
1067 Switch Up
1068 '''
1069 #NOTE: You should probably run a topology check after this
1070 import time
1071 #FIXME: use new dynamic topo functions
1072 description = "Adding a switch to ensure it is discovered correctly"
1073 main.log.report(description)
1074 main.case(description)
1075
1076 main.step("Add back s28")
1077 main.log.report("Adding back s28")
1078 main.Mininet1.add_switch("s28", dpid = '0000000000002800')
1079 #TODO: New dpid or same? Ask Thomas?
1080 main.Mininet1.add_link('s28', 's3')
1081 main.Mininet1.add_link('s28', 's6')
1082 main.Mininet1.add_link('s28', 'h28')
1083 main.Mininet1.assign_sw_controller(sw="28",count=7,
1084 ip1=ONOS1_ip,port1=ONOS1_port,
1085 ip2=ONOS2_ip,port2=ONOS2_port,
1086 ip3=ONOS3_ip,port3=ONOS3_port,
1087 ip4=ONOS4_ip,port4=ONOS4_port,
1088 ip5=ONOS5_ip,port5=ONOS5_port,
1089 ip6=ONOS6_ip,port6=ONOS6_port,
1090 ip7=ONOS7_ip,port7=ONOS7_port)
1091 main.log.info("Waiting " + str(switch_sleep) + " seconds for switch up to be discovered")
1092 time.sleep(switch_sleep)
1093 #Peek at the added switch
1094 main.log.warn(main.ONOScli1.get_device(dpid="0028"))
1095 #TODO do some sort of check here
1096
1097 def CASE13 (self, main) :
1098 '''
1099 Clean up
1100 '''
Jon Hall73cf9cc2014-11-20 22:28:38 -08001101 import os
1102 import time
Jon Hall368769f2014-11-19 15:43:35 -08001103 description = "Test Cleanup"
1104 main.log.report(description)
1105 main.case(description)
Jon Hallb1290e82014-11-18 16:17:48 -05001106 main.step("Killing tcpdumps")
1107 main.Mininet2.stop_tcpdump()
1108
Jon Hall73cf9cc2014-11-20 22:28:38 -08001109 main.step("Copying MN pcap and ONOS log files to test station")
Jon Hallb1290e82014-11-18 16:17:48 -05001110 testname = main.TEST
Jon Hall73cf9cc2014-11-20 22:28:38 -08001111 #NOTE: MN Pcap file is being saved to ~/packet_captures
1112 # scp this file as MN and TestON aren't necessarily the same vm
1113 #FIXME: scp
1114 #####mn files
1115 #TODO: Load these from params
1116 #NOTE: must end in /
1117 log_folder = "/opt/onos/log/"
1118 log_files = ["karaf.log", "karaf.log.1"]
1119 #NOTE: must end in /
1120 dst_dir = "~/packet_captures/"
1121 for f in log_files:
1122 main.ONOSbench.secureCopy( "sdn", ONOS1_ip,log_folder+f,"rocks",\
1123 dst_dir + str(testname) + "-ONOS1-"+f )
1124 main.ONOSbench.secureCopy( "sdn", ONOS2_ip,log_folder+f,"rocks",\
1125 dst_dir + str(testname) + "-ONOS2-"+f )
1126 main.ONOSbench.secureCopy( "sdn", ONOS3_ip,log_folder+f,"rocks",\
1127 dst_dir + str(testname) + "-ONOS3-"+f )
1128 main.ONOSbench.secureCopy( "sdn", ONOS4_ip,log_folder+f,"rocks",\
1129 dst_dir + str(testname) + "-ONOS4-"+f )
1130 main.ONOSbench.secureCopy( "sdn", ONOS5_ip,log_folder+f,"rocks",\
1131 dst_dir + str(testname) + "-ONOS5-"+f )
1132 main.ONOSbench.secureCopy( "sdn", ONOS6_ip,log_folder+f,"rocks",\
1133 dst_dir + str(testname) + "-ONOS6-"+f )
1134 main.ONOSbench.secureCopy( "sdn", ONOS7_ip,log_folder+f,"rocks",\
1135 dst_dir + str(testname) + "-ONOS7-"+f )
1136
1137 #std*.log's
1138 #NOTE: must end in /
1139 log_folder = "/opt/onos/var/"
1140 log_files = ["stderr.log", "stdout.log"]
1141 #NOTE: must end in /
1142 dst_dir = "~/packet_captures/"
1143 for f in log_files:
1144 main.ONOSbench.secureCopy( "sdn", ONOS1_ip,log_folder+f,"rocks",\
1145 dst_dir + str(testname) + "-ONOS1-"+f )
1146 main.ONOSbench.secureCopy( "sdn", ONOS2_ip,log_folder+f,"rocks",\
1147 dst_dir + str(testname) + "-ONOS2-"+f )
1148 main.ONOSbench.secureCopy( "sdn", ONOS3_ip,log_folder+f,"rocks",\
1149 dst_dir + str(testname) + "-ONOS3-"+f )
1150 main.ONOSbench.secureCopy( "sdn", ONOS4_ip,log_folder+f,"rocks",\
1151 dst_dir + str(testname) + "-ONOS4-"+f )
1152 main.ONOSbench.secureCopy( "sdn", ONOS5_ip,log_folder+f,"rocks",\
1153 dst_dir + str(testname) + "-ONOS5-"+f )
1154 main.ONOSbench.secureCopy( "sdn", ONOS6_ip,log_folder+f,"rocks",\
1155 dst_dir + str(testname) + "-ONOS6-"+f )
1156 main.ONOSbench.secureCopy( "sdn", ONOS7_ip,log_folder+f,"rocks",\
1157 dst_dir + str(testname) + "-ONOS7-"+f )
1158
1159
1160
Jon Hallb1290e82014-11-18 16:17:48 -05001161
1162 #sleep so scp can finish
1163 time.sleep(10)
1164 main.step("Packing and rotating pcap archives")
Jon Hallb1290e82014-11-18 16:17:48 -05001165 os.system("~/TestON/dependencies/rotate.sh "+ str(testname))
Jon Hallb1290e82014-11-18 16:17:48 -05001166
Jon Hall368769f2014-11-19 15:43:35 -08001167
1168 #TODO: actually check something here
1169 utilities.assert_equals(expect=main.TRUE, actual=main.TRUE,
1170 onpass="Test cleanup successful",
1171 onfail="Test cleanup NOT successful")