blob: 7479135f13a8c4835bd1f25118083ee5317ceefc [file] [log] [blame]
Jon Hall6aec96b2015-01-19 14:49:31 -08001"""
Jon Hall73cf9cc2014-11-20 22:28:38 -08002Description: 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
Jon Hall669173b2014-12-17 11:36:30 -080019CASE14: start election app on all onos nodes
20CASE15: Check that Leadership Election is still functional
Jon Hall6aec96b2015-01-19 14:49:31 -080021"""
Jon Hall73cf9cc2014-11-20 22:28:38 -080022class HATestClusterRestart:
23
Jon Hall6aec96b2015-01-19 14:49:31 -080024 def __init__( self ):
Jon Hall73cf9cc2014-11-20 22:28:38 -080025 self.default = ''
26
Jon Hall6aec96b2015-01-19 14:49:31 -080027 def CASE1( self, main ):
28 """
Jon Hall73cf9cc2014-11-20 22:28:38 -080029 CASE1 is to compile ONOS and push it to the test machines
30
31 Startup sequence:
32 git pull
33 mvn clean install
34 onos-package
35 cell <name>
36 onos-verify-cell
37 NOTE: temporary - onos-remove-raft-logs
38 onos-install -f
39 onos-wait-for-start
Jon Hall6aec96b2015-01-19 14:49:31 -080040 """
41 main.log.report( "ONOS HA test: Restart all ONOS nodes - " +
42 "initialization" )
43 main.case( "Setting up test environment" )
44 # TODO: save all the timers and output them for plotting
Jon Hall73cf9cc2014-11-20 22:28:38 -080045
46 # load some vairables from the params file
47 PULL_CODE = False
Jon Hall6aec96b2015-01-19 14:49:31 -080048 if main.params[ 'Git' ] == 'True':
Jon Hall73cf9cc2014-11-20 22:28:38 -080049 PULL_CODE = True
Jon Hall73cf9cc2014-11-20 22:28:38 -080050
Jon Hall6aec96b2015-01-19 14:49:31 -080051 cell_name = main.params[ 'ENV' ][ 'cellName' ]
52
53 # set global variables
Jon Hall73cf9cc2014-11-20 22:28:38 -080054 global ONOS1_ip
55 global ONOS1_port
56 global ONOS2_ip
57 global ONOS2_port
58 global ONOS3_ip
59 global ONOS3_port
60 global ONOS4_ip
61 global ONOS4_port
62 global ONOS5_ip
63 global ONOS5_port
64 global ONOS6_ip
65 global ONOS6_port
66 global ONOS7_ip
67 global ONOS7_port
Jon Hall669173b2014-12-17 11:36:30 -080068 global num_controllers
Jon Hall73cf9cc2014-11-20 22:28:38 -080069
Jon Hall6aec96b2015-01-19 14:49:31 -080070 ONOS1_ip = main.params[ 'CTRL' ][ 'ip1' ]
71 ONOS1_port = main.params[ 'CTRL' ][ 'port1' ]
72 ONOS2_ip = main.params[ 'CTRL' ][ 'ip2' ]
73 ONOS2_port = main.params[ 'CTRL' ][ 'port2' ]
74 ONOS3_ip = main.params[ 'CTRL' ][ 'ip3' ]
75 ONOS3_port = main.params[ 'CTRL' ][ 'port3' ]
76 ONOS4_ip = main.params[ 'CTRL' ][ 'ip4' ]
77 ONOS4_port = main.params[ 'CTRL' ][ 'port4' ]
78 ONOS5_ip = main.params[ 'CTRL' ][ 'ip5' ]
79 ONOS5_port = main.params[ 'CTRL' ][ 'port5' ]
80 ONOS6_ip = main.params[ 'CTRL' ][ 'ip6' ]
81 ONOS6_port = main.params[ 'CTRL' ][ 'port6' ]
82 ONOS7_ip = main.params[ 'CTRL' ][ 'ip7' ]
83 ONOS7_port = main.params[ 'CTRL' ][ 'port7' ]
84 num_controllers = int( main.params[ 'num_controllers' ] )
Jon Hall73cf9cc2014-11-20 22:28:38 -080085
Jon Hall6aec96b2015-01-19 14:49:31 -080086 main.step( "Applying cell variable to environment" )
87 cell_result = main.ONOSbench.set_cell( cell_name )
Jon Hall73cf9cc2014-11-20 22:28:38 -080088 verify_result = main.ONOSbench.verify_cell()
89
Jon Hall6aec96b2015-01-19 14:49:31 -080090 # FIXME:this is short term fix
91 main.log.report( "Removing raft logs" )
Jon Hall73cf9cc2014-11-20 22:28:38 -080092 main.ONOSbench.onos_remove_raft_logs()
Jon Hall6aec96b2015-01-19 14:49:31 -080093 main.log.report( "Uninstalling ONOS" )
94 main.ONOSbench.onos_uninstall( ONOS1_ip )
95 main.ONOSbench.onos_uninstall( ONOS2_ip )
96 main.ONOSbench.onos_uninstall( ONOS3_ip )
97 main.ONOSbench.onos_uninstall( ONOS4_ip )
98 main.ONOSbench.onos_uninstall( ONOS5_ip )
99 main.ONOSbench.onos_uninstall( ONOS6_ip )
100 main.ONOSbench.onos_uninstall( ONOS7_ip )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800101
102 clean_install_result = main.TRUE
103 git_pull_result = main.TRUE
104
Jon Hall6aec96b2015-01-19 14:49:31 -0800105 main.step( "Compiling the latest version of ONOS" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800106 if PULL_CODE:
Jon Hall6aec96b2015-01-19 14:49:31 -0800107 # TODO Configure branch in params
108 main.step( "Git checkout and pull master" )
109 main.ONOSbench.git_checkout( "master" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800110 git_pull_result = main.ONOSbench.git_pull()
111
Jon Hall6aec96b2015-01-19 14:49:31 -0800112 main.step( "Using mvn clean & install" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800113 clean_install_result = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800114 # In Sanity test, always re-compile ONOS
115 if git_pull_result == main.TRUE:
116 clean_install_result = main.ONOSbench.clean_install()
117 else:
118 main.log.warn( "Did not pull new code so skipping mvn " +
119 "clean install" )
120 main.ONOSbench.get_version( report=True )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800121
Jon Hall6aec96b2015-01-19 14:49:31 -0800122 main.step( "Creating ONOS package" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800123 package_result = main.ONOSbench.onos_package()
124
Jon Hall6aec96b2015-01-19 14:49:31 -0800125 main.step( "Installing ONOS package" )
126 onos1_install_result = main.ONOSbench.onos_install( options="-f",
127 node=ONOS1_ip )
128 onos2_install_result = main.ONOSbench.onos_install( options="-f",
129 node=ONOS2_ip )
130 onos3_install_result = main.ONOSbench.onos_install( options="-f",
131 node=ONOS3_ip )
132 onos4_install_result = main.ONOSbench.onos_install( options="-f",
133 node=ONOS4_ip )
134 onos5_install_result = main.ONOSbench.onos_install( options="-f",
135 node=ONOS5_ip )
136 onos6_install_result = main.ONOSbench.onos_install( options="-f",
137 node=ONOS6_ip )
138 onos7_install_result = main.ONOSbench.onos_install( options="-f",
139 node=ONOS7_ip )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800140 onos_install_result = onos1_install_result and onos2_install_result\
Jon Hall6aec96b2015-01-19 14:49:31 -0800141 and onos3_install_result and onos4_install_result\
142 and onos5_install_result and onos6_install_result\
143 and onos7_install_result
Jon Hall73cf9cc2014-11-20 22:28:38 -0800144
Jon Hall6aec96b2015-01-19 14:49:31 -0800145 main.step( "Checking if ONOS is up yet" )
146 # TODO check bundle:list?
147 for i in range( 2 ):
148 onos1_isup = main.ONOSbench.isup( ONOS1_ip )
Jon Hall94fd0472014-12-08 11:52:42 -0800149 if not onos1_isup:
Jon Hall6aec96b2015-01-19 14:49:31 -0800150 main.log.report( "ONOS1 didn't start!" )
151 onos2_isup = main.ONOSbench.isup( ONOS2_ip )
Jon Hall94fd0472014-12-08 11:52:42 -0800152 if not onos2_isup:
Jon Hall6aec96b2015-01-19 14:49:31 -0800153 main.log.report( "ONOS2 didn't start!" )
154 onos3_isup = main.ONOSbench.isup( ONOS3_ip )
Jon Hall94fd0472014-12-08 11:52:42 -0800155 if not onos3_isup:
Jon Hall6aec96b2015-01-19 14:49:31 -0800156 main.log.report( "ONOS3 didn't start!" )
157 onos4_isup = main.ONOSbench.isup( ONOS4_ip )
Jon Hall94fd0472014-12-08 11:52:42 -0800158 if not onos4_isup:
Jon Hall6aec96b2015-01-19 14:49:31 -0800159 main.log.report( "ONOS4 didn't start!" )
160 onos5_isup = main.ONOSbench.isup( ONOS5_ip )
Jon Hall94fd0472014-12-08 11:52:42 -0800161 if not onos5_isup:
Jon Hall6aec96b2015-01-19 14:49:31 -0800162 main.log.report( "ONOS5 didn't start!" )
163 onos6_isup = main.ONOSbench.isup( ONOS6_ip )
Jon Hall94fd0472014-12-08 11:52:42 -0800164 if not onos6_isup:
Jon Hall6aec96b2015-01-19 14:49:31 -0800165 main.log.report( "ONOS6 didn't start!" )
166 onos7_isup = main.ONOSbench.isup( ONOS7_ip )
Jon Hall94fd0472014-12-08 11:52:42 -0800167 if not onos7_isup:
Jon Hall6aec96b2015-01-19 14:49:31 -0800168 main.log.report( "ONOS7 didn't start!" )
Jon Hall94fd0472014-12-08 11:52:42 -0800169 onos_isup_result = onos1_isup and onos2_isup and onos3_isup\
Jon Hall6aec96b2015-01-19 14:49:31 -0800170 and onos4_isup and onos5_isup and onos6_isup and onos7_isup
Jon Hall94fd0472014-12-08 11:52:42 -0800171 if onos_isup_result == main.TRUE:
172 break
Jon Hall73cf9cc2014-11-20 22:28:38 -0800173
Jon Hall6aec96b2015-01-19 14:49:31 -0800174 cli_result1 = main.ONOScli1.start_onos_cli( ONOS1_ip )
175 cli_result2 = main.ONOScli2.start_onos_cli( ONOS2_ip )
176 cli_result3 = main.ONOScli3.start_onos_cli( ONOS3_ip )
177 cli_result4 = main.ONOScli4.start_onos_cli( ONOS4_ip )
178 cli_result5 = main.ONOScli5.start_onos_cli( ONOS5_ip )
179 cli_result6 = main.ONOScli6.start_onos_cli( ONOS6_ip )
180 cli_result7 = main.ONOScli7.start_onos_cli( ONOS7_ip )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800181 cli_results = cli_result1 and cli_result2 and cli_result3 and\
Jon Hall6aec96b2015-01-19 14:49:31 -0800182 cli_result4 and cli_result5 and cli_result6 and cli_result7
Jon Hall73cf9cc2014-11-20 22:28:38 -0800183
Jon Hall6aec96b2015-01-19 14:49:31 -0800184 main.step( "Start Packet Capture MN" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800185 main.Mininet2.start_tcpdump(
Jon Hall6aec96b2015-01-19 14:49:31 -0800186 str( main.params[ 'MNtcpdump' ][ 'folder' ] ) + str( main.TEST )
187 + "-MN.pcap",
188 intf=main.params[ 'MNtcpdump' ][ 'intf' ],
189 port=main.params[ 'MNtcpdump' ][ 'port' ] )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800190
Jon Hall6aec96b2015-01-19 14:49:31 -0800191 case1_result = ( clean_install_result and package_result and
192 cell_result and verify_result and onos_install_result
193 and onos_isup_result and cli_results )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800194
Jon Hall6aec96b2015-01-19 14:49:31 -0800195 utilities.assert_equals( expect=main.TRUE, actual=case1_result,
196 onpass="Test startup successful",
197 onfail="Test startup NOT successful" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800198
Jon Hall6aec96b2015-01-19 14:49:31 -0800199 if case1_result == main.FALSE:
Jon Hall94fd0472014-12-08 11:52:42 -0800200 main.cleanup()
201 main.exit()
Jon Hall73cf9cc2014-11-20 22:28:38 -0800202
Jon Hall6aec96b2015-01-19 14:49:31 -0800203 def CASE2( self, main ):
204 """
Jon Hall73cf9cc2014-11-20 22:28:38 -0800205 Assign mastership to controllers
Jon Hall6aec96b2015-01-19 14:49:31 -0800206 """
Jon Hall73cf9cc2014-11-20 22:28:38 -0800207 import re
208
Jon Hall6aec96b2015-01-19 14:49:31 -0800209 main.log.report( "Assigning switches to controllers" )
210 main.case( "Assigning Controllers" )
211 main.step( "Assign switches to controllers" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800212
Jon Hall6aec96b2015-01-19 14:49:31 -0800213 for i in range( 1, 29 ):
214 main.Mininet1.assign_sw_controller(
215 sw=str( i ),
216 count=num_controllers,
217 ip1=ONOS1_ip, port1=ONOS1_port,
218 ip2=ONOS2_ip, port2=ONOS2_port,
219 ip3=ONOS3_ip, port3=ONOS3_port,
220 ip4=ONOS4_ip, port4=ONOS4_port,
221 ip5=ONOS5_ip, port5=ONOS5_port,
222 ip6=ONOS6_ip, port6=ONOS6_port,
223 ip7=ONOS7_ip, port7=ONOS7_port )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800224
225 mastership_check = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800226 for i in range( 1, 29 ):
227 response = main.Mininet1.get_sw_controller( "s" + str( i ) )
Jon Hallffb386d2014-11-21 13:43:38 -0800228 try:
Jon Hall6aec96b2015-01-19 14:49:31 -0800229 main.log.info( str( response ) )
Jon Hallffb386d2014-11-21 13:43:38 -0800230 except:
Jon Hall6aec96b2015-01-19 14:49:31 -0800231 main.log.info( repr( response ) )
232 if re.search( "tcp:" + ONOS1_ip, response )\
233 and re.search( "tcp:" + ONOS2_ip, response )\
234 and re.search( "tcp:" + ONOS3_ip, response )\
235 and re.search( "tcp:" + ONOS4_ip, response )\
236 and re.search( "tcp:" + ONOS5_ip, response )\
237 and re.search( "tcp:" + ONOS6_ip, response )\
238 and re.search( "tcp:" + ONOS7_ip, response ):
Jon Hall73cf9cc2014-11-20 22:28:38 -0800239 mastership_check = mastership_check and main.TRUE
240 else:
241 mastership_check = main.FALSE
242 if mastership_check == main.TRUE:
Jon Hall6aec96b2015-01-19 14:49:31 -0800243 main.log.report( "Switch mastership assigned correctly" )
244 utilities.assert_equals(
245 expect=main.TRUE,
246 actual=mastership_check,
247 onpass="Switch mastership assigned correctly",
248 onfail="Switches not assigned correctly to controllers" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800249
Jon Hall6aec96b2015-01-19 14:49:31 -0800250 # Manually assign mastership to the controller we want
Jon Hall94fd0472014-12-08 11:52:42 -0800251 role_call = main.TRUE
252 role_check = main.TRUE
253
Jon Hall6aec96b2015-01-19 14:49:31 -0800254 # Assign switch
255 device_id = main.ONOScli1.get_device( "1000" ).get( 'id' )
256 role_call = role_call and main.ONOScli1.device_role(
257 device_id,
258 ONOS1_ip )
259 # Check assignment
260 if ONOS1_ip in main.ONOScli1.get_role( device_id ).get( 'master' ):
Jon Hall94fd0472014-12-08 11:52:42 -0800261 role_check = role_check and main.TRUE
262 else:
263 role_check = role_check and main.FALSE
264
Jon Hall6aec96b2015-01-19 14:49:31 -0800265 # Assign switch
266 device_id = main.ONOScli1.get_device( "2800" ).get( 'id' )
267 role_call = role_call and main.ONOScli1.device_role(
268 device_id,
269 ONOS1_ip )
270 # Check assignment
271 if ONOS1_ip in main.ONOScli1.get_role( device_id ).get( 'master' ):
Jon Hall94fd0472014-12-08 11:52:42 -0800272 role_check = role_check and main.TRUE
273 else:
274 role_check = role_check and main.FALSE
275
Jon Hall6aec96b2015-01-19 14:49:31 -0800276 # Assign switch
277 device_id = main.ONOScli1.get_device( "2000" ).get( 'id' )
278 role_call = role_call and main.ONOScli1.device_role(
279 device_id,
280 ONOS2_ip )
281 # Check assignment
282 if ONOS2_ip in main.ONOScli1.get_role( device_id ).get( 'master' ):
Jon Hall94fd0472014-12-08 11:52:42 -0800283 role_check = role_check and main.TRUE
284 else:
285 role_check = role_check and main.FALSE
286
Jon Hall6aec96b2015-01-19 14:49:31 -0800287 # Assign switch
288 device_id = main.ONOScli1.get_device( "3000" ).get( 'id' )
289 role_call = role_call and main.ONOScli1.device_role(
290 device_id,
291 ONOS2_ip )
292 # Check assignment
293 if ONOS2_ip in main.ONOScli1.get_role( device_id ).get( 'master' ):
Jon Hall94fd0472014-12-08 11:52:42 -0800294 role_check = role_check and main.TRUE
295 else:
296 role_check = role_check and main.FALSE
297
Jon Hall6aec96b2015-01-19 14:49:31 -0800298 # Assign switch
299 device_id = main.ONOScli1.get_device( "5000" ).get( 'id' )
300 role_call = role_call and main.ONOScli1.device_role(
301 device_id,
302 ONOS3_ip )
303 # Check assignment
304 if ONOS3_ip in main.ONOScli1.get_role( device_id ).get( 'master' ):
Jon Hall94fd0472014-12-08 11:52:42 -0800305 role_check = role_check and main.TRUE
306 else:
307 role_check = role_check and main.FALSE
308
Jon Hall6aec96b2015-01-19 14:49:31 -0800309 # Assign switch
310 device_id = main.ONOScli1.get_device( "6000" ).get( 'id' )
311 role_call = role_call and main.ONOScli1.device_role(
312 device_id,
313 ONOS3_ip )
314 # Check assignment
315 if ONOS3_ip in main.ONOScli1.get_role( device_id ).get( 'master' ):
Jon Hall94fd0472014-12-08 11:52:42 -0800316 role_check = role_check and main.TRUE
317 else:
318 role_check = role_check and main.FALSE
319
Jon Hall6aec96b2015-01-19 14:49:31 -0800320 # Assign switch
321 device_id = main.ONOScli1.get_device( "3004" ).get( 'id' )
322 role_call = role_call and main.ONOScli1.device_role(
323 device_id,
324 ONOS4_ip )
325 # Check assignment
326 if ONOS4_ip in main.ONOScli1.get_role( device_id ).get( 'master' ):
Jon Hall94fd0472014-12-08 11:52:42 -0800327 role_check = role_check and main.TRUE
328 else:
329 role_check = role_check and main.FALSE
330
Jon Hall6aec96b2015-01-19 14:49:31 -0800331 for i in range( 8, 18 ):
332 dpid = '3' + str( i ).zfill( 3 )
333 device_id = main.ONOScli1.get_device( dpid ).get( 'id' )
334 role_call = role_call and main.ONOScli1.device_role(
335 device_id,
336 ONOS5_ip )
337 # Check assignment
338 if ONOS5_ip in main.ONOScli1.get_role( device_id ).get( 'master' ):
339 role_check = role_check and main.TRUE
340 else:
341 role_check = role_check and main.FALSE
342
343 device_id = main.ONOScli1.get_device( "6007" ).get( 'id' )
344 role_call = role_call and main.ONOScli1.device_role(
345 device_id,
346 ONOS6_ip )
347 # Check assignment
348 if ONOS6_ip in main.ONOScli1.get_role( device_id ).get( 'master' ):
Jon Hall94fd0472014-12-08 11:52:42 -0800349 role_check = role_check and main.TRUE
350 else:
351 role_check = role_check and main.FALSE
352
Jon Hall6aec96b2015-01-19 14:49:31 -0800353 for i in range( 18, 28 ):
354 dpid = '6' + str( i ).zfill( 3 )
355 device_id = main.ONOScli1.get_device( dpid ).get( 'id' )
356 role_call = role_call and main.ONOScli1.device_role(
357 device_id,
358 ONOS7_ip )
359 # Check assignment
360 if ONOS7_ip in main.ONOScli1.get_role( device_id ).get( 'master' ):
361 role_check = role_check and main.TRUE
362 else:
363 role_check = role_check and main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -0800364
Jon Hall6aec96b2015-01-19 14:49:31 -0800365 utilities.assert_equals(
366 expect=main.TRUE,
367 actual=role_call,
368 onpass="Re-assigned switch mastership to designated controller",
369 onfail="Something wrong with device_role calls" )
Jon Hall94fd0472014-12-08 11:52:42 -0800370
Jon Hall6aec96b2015-01-19 14:49:31 -0800371 utilities.assert_equals(
372 expect=main.TRUE,
373 actual=role_check,
374 onpass="Switches were successfully reassigned to designated " +
375 "controller",
376 onfail="Switches were not successfully reassigned" )
Jon Hall94fd0472014-12-08 11:52:42 -0800377 mastership_check = mastership_check and role_call and role_check
Jon Hall6aec96b2015-01-19 14:49:31 -0800378 utilities.assert_equals( expect=main.TRUE, actual=mastership_check,
379 onpass="Switch mastership correctly assigned",
380 onfail="Error in (re)assigning switch" +
381 " mastership" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800382
Jon Hall6aec96b2015-01-19 14:49:31 -0800383 def CASE3( self, main ):
Jon Hall73cf9cc2014-11-20 22:28:38 -0800384 """
385 Assign intents
386
387 """
Jon Hall6aec96b2015-01-19 14:49:31 -0800388 # FIXME: we must reinstall intents until we have a persistant
389 # datastore!
Jon Hall73cf9cc2014-11-20 22:28:38 -0800390 import time
Jon Hall6aec96b2015-01-19 14:49:31 -0800391 main.log.report( "Adding host intents" )
392 main.case( "Adding host Intents" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800393
Jon Hall6aec96b2015-01-19 14:49:31 -0800394 main.step( "Discovering Hosts( Via pingall for now)" )
395 # FIXME: Once we have a host discovery mechanism, use that instead
Jon Hall73cf9cc2014-11-20 22:28:38 -0800396
Jon Hall6aec96b2015-01-19 14:49:31 -0800397 # install onos-app-fwd
398 main.log.info( "Install reactive forwarding app" )
399 main.ONOScli1.feature_install( "onos-app-fwd" )
400 main.ONOScli2.feature_install( "onos-app-fwd" )
401 main.ONOScli3.feature_install( "onos-app-fwd" )
402 main.ONOScli4.feature_install( "onos-app-fwd" )
403 main.ONOScli5.feature_install( "onos-app-fwd" )
404 main.ONOScli6.feature_install( "onos-app-fwd" )
405 main.ONOScli7.feature_install( "onos-app-fwd" )
Jon Hall94fd0472014-12-08 11:52:42 -0800406
Jon Hall6aec96b2015-01-19 14:49:31 -0800407 # REACTIVE FWD test
Jon Hall73cf9cc2014-11-20 22:28:38 -0800408 ping_result = main.FALSE
409 time1 = time.time()
410 ping_result = main.Mininet1.pingall()
411 time2 = time.time()
Jon Hall6aec96b2015-01-19 14:49:31 -0800412 main.log.info( "Time for pingall: %2f seconds" % ( time2 - time1 ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800413
Jon Hall6aec96b2015-01-19 14:49:31 -0800414 # uninstall onos-app-fwd
415 main.log.info( "Uninstall reactive forwarding app" )
416 main.ONOScli1.feature_uninstall( "onos-app-fwd" )
417 main.ONOScli2.feature_uninstall( "onos-app-fwd" )
418 main.ONOScli3.feature_uninstall( "onos-app-fwd" )
419 main.ONOScli4.feature_uninstall( "onos-app-fwd" )
420 main.ONOScli5.feature_uninstall( "onos-app-fwd" )
421 main.ONOScli6.feature_uninstall( "onos-app-fwd" )
422 main.ONOScli7.feature_uninstall( "onos-app-fwd" )
423 # timeout for fwd flows
424 time.sleep( 10 )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800425
Jon Hall6aec96b2015-01-19 14:49:31 -0800426 main.step( "Add host intents" )
427 # TODO: move the host numbers to params
Jon Hall94fd0472014-12-08 11:52:42 -0800428 intent_add_result = True
Jon Hall6aec96b2015-01-19 14:49:31 -0800429 for i in range( 8, 18 ):
430 main.log.info( "Adding host intent between h" + str( i ) +
431 " and h" + str( i + 10 ) )
432 host1 = "00:00:00:00:00:" + \
433 str( hex( i )[ 2: ] ).zfill( 2 ).upper()
434 host2 = "00:00:00:00:00:" + \
435 str( hex( i + 10 )[ 2: ] ).zfill( 2 ).upper()
436 host1_id = main.ONOScli1.get_host( host1 )[ 'id' ]
437 host2_id = main.ONOScli1.get_host( host2 )[ 'id' ]
438 # NOTE: get host can return None
Jon Hall669173b2014-12-17 11:36:30 -0800439 if host1_id and host2_id:
Jon Hall6aec96b2015-01-19 14:49:31 -0800440 tmp_result = main.ONOScli1.add_host_intent(
441 host1_id,
442 host2_id )
Jon Hall669173b2014-12-17 11:36:30 -0800443 else:
Jon Hall6aec96b2015-01-19 14:49:31 -0800444 main.log.error( "Error, get_host() failed" )
Jon Hall669173b2014-12-17 11:36:30 -0800445 tmp_result = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -0800446 intent_add_result = bool( ping_result and intent_add_result
447 and tmp_result )
448 utilities.assert_equals(
449 expect=True,
450 actual=intent_add_result,
451 onpass="Switch mastership correctly assigned",
452 onfail="Error in (re)assigning switch mastership" )
453 # TODO Check if intents all exist in datastore
Jon Hall73cf9cc2014-11-20 22:28:38 -0800454
Jon Hall6aec96b2015-01-19 14:49:31 -0800455 def CASE4( self, main ):
Jon Hall73cf9cc2014-11-20 22:28:38 -0800456 """
457 Ping across added host intents
458 """
459 description = " Ping across added host intents"
Jon Hall6aec96b2015-01-19 14:49:31 -0800460 main.log.report( description )
461 main.case( description )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800462 Ping_Result = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800463 for i in range( 8, 18 ):
464 ping = main.Mininet1.pingHost(
465 src="h" + str( i ), target="h" + str( i + 10 ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800466 Ping_Result = Ping_Result and ping
Jon Hall6aec96b2015-01-19 14:49:31 -0800467 if ping == main.FALSE:
468 main.log.warn( "Ping failed between h" + str( i ) +
469 " and h" + str( i + 10 ) )
470 elif ping == main.TRUE:
471 main.log.info( "Ping test passed!" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800472 Ping_Result = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800473 if Ping_Result == main.FALSE:
474 main.log.report(
475 "Intents have not been installed correctly, pings failed." )
476 if Ping_Result == main.TRUE:
477 main.log.report(
478 "Intents have been installed correctly and verified by pings" )
479 utilities.assert_equals(
480 expect=main.TRUE,
481 actual=Ping_Result,
482 onpass="Intents have been installed correctly and pings work",
483 onfail="Intents have not been installed correctly, pings failed." )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800484
Jon Hall6aec96b2015-01-19 14:49:31 -0800485 def CASE5( self, main ):
486 """
Jon Hall73cf9cc2014-11-20 22:28:38 -0800487 Reading state of ONOS
Jon Hall6aec96b2015-01-19 14:49:31 -0800488 """
Jon Hall73cf9cc2014-11-20 22:28:38 -0800489 import json
Jon Hall6aec96b2015-01-19 14:49:31 -0800490 # assumes that sts is already in you PYTHONPATH
491 from sts.topology.teston_topology import TestONTopology
Jon Hall73cf9cc2014-11-20 22:28:38 -0800492
Jon Hall6aec96b2015-01-19 14:49:31 -0800493 main.log.report( "Setting up and gathering data for current state" )
494 main.case( "Setting up and gathering data for current state" )
495 # The general idea for this test case is to pull the state of
496 # ( intents,flows, topology,... ) from each ONOS node
497 # We can then compare them with eachother and also with past states
Jon Hall73cf9cc2014-11-20 22:28:38 -0800498
Jon Hall6aec96b2015-01-19 14:49:31 -0800499 main.step( "Get the Mastership of each switch from each controller" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800500 global mastership_state
Jon Hall94fd0472014-12-08 11:52:42 -0800501 mastership_state = []
502
Jon Hall6aec96b2015-01-19 14:49:31 -0800503 # Assert that each device has a master
Jon Hall94fd0472014-12-08 11:52:42 -0800504 ONOS1_master_not_null = main.ONOScli1.roles_not_null()
505 ONOS2_master_not_null = main.ONOScli2.roles_not_null()
506 ONOS3_master_not_null = main.ONOScli3.roles_not_null()
507 ONOS4_master_not_null = main.ONOScli4.roles_not_null()
508 ONOS5_master_not_null = main.ONOScli5.roles_not_null()
509 ONOS6_master_not_null = main.ONOScli6.roles_not_null()
510 ONOS7_master_not_null = main.ONOScli7.roles_not_null()
511 roles_not_null = ONOS1_master_not_null and ONOS2_master_not_null and\
Jon Hall6aec96b2015-01-19 14:49:31 -0800512 ONOS3_master_not_null and ONOS4_master_not_null and\
513 ONOS5_master_not_null and ONOS6_master_not_null and\
514 ONOS7_master_not_null
515 utilities.assert_equals(
516 expect=main.TRUE,
517 actual=roles_not_null,
518 onpass="Each device has a master",
519 onfail="Some devices don't have a master assigned" )
Jon Hall94fd0472014-12-08 11:52:42 -0800520
Jon Hall73cf9cc2014-11-20 22:28:38 -0800521 ONOS1_mastership = main.ONOScli1.roles()
522 ONOS2_mastership = main.ONOScli2.roles()
523 ONOS3_mastership = main.ONOScli3.roles()
524 ONOS4_mastership = main.ONOScli4.roles()
525 ONOS5_mastership = main.ONOScli5.roles()
526 ONOS6_mastership = main.ONOScli6.roles()
527 ONOS7_mastership = main.ONOScli7.roles()
Jon Hall73cf9cc2014-11-20 22:28:38 -0800528 if "Error" in ONOS1_mastership or not ONOS1_mastership\
529 or "Error" in ONOS2_mastership or not ONOS2_mastership\
530 or "Error" in ONOS3_mastership or not ONOS3_mastership\
531 or "Error" in ONOS4_mastership or not ONOS4_mastership\
532 or "Error" in ONOS5_mastership or not ONOS5_mastership\
533 or "Error" in ONOS6_mastership or not ONOS6_mastership\
534 or "Error" in ONOS7_mastership or not ONOS7_mastership:
Jon Hall6aec96b2015-01-19 14:49:31 -0800535 main.log.report( "Error in getting ONOS roles" )
536 main.log.warn(
537 "ONOS1 mastership response: " +
538 repr( ONOS1_mastership ) )
539 main.log.warn(
540 "ONOS2 mastership response: " +
541 repr( ONOS2_mastership ) )
542 main.log.warn(
543 "ONOS3 mastership response: " +
544 repr( ONOS3_mastership ) )
545 main.log.warn(
546 "ONOS4 mastership response: " +
547 repr( ONOS4_mastership ) )
548 main.log.warn(
549 "ONOS5 mastership response: " +
550 repr( ONOS5_mastership ) )
551 main.log.warn(
552 "ONOS6 mastership response: " +
553 repr( ONOS6_mastership ) )
554 main.log.warn(
555 "ONOS7 mastership response: " +
556 repr( ONOS7_mastership ) )
557 consistent_mastership = main.FALSE
Jon Hall73cf9cc2014-11-20 22:28:38 -0800558 elif ONOS1_mastership == ONOS2_mastership\
559 and ONOS1_mastership == ONOS3_mastership\
560 and ONOS1_mastership == ONOS4_mastership\
561 and ONOS1_mastership == ONOS5_mastership\
562 and ONOS1_mastership == ONOS6_mastership\
563 and ONOS1_mastership == ONOS7_mastership:
Jon Hall6aec96b2015-01-19 14:49:31 -0800564 mastership_state = ONOS1_mastership
565 consistent_mastership = main.TRUE
566 main.log.report(
567 "Switch roles are consistent across all ONOS nodes" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800568 else:
Jon Hall6aec96b2015-01-19 14:49:31 -0800569 main.log.warn(
570 "ONOS1 roles: ",
571 json.dumps(
572 json.loads( ONOS1_mastership ),
573 sort_keys=True,
574 indent=4,
575 separators=(
576 ',',
577 ': ' ) ) )
578 main.log.warn(
579 "ONOS2 roles: ",
580 json.dumps(
581 json.loads( ONOS2_mastership ),
582 sort_keys=True,
583 indent=4,
584 separators=(
585 ',',
586 ': ' ) ) )
587 main.log.warn(
588 "ONOS3 roles: ",
589 json.dumps(
590 json.loads( ONOS3_mastership ),
591 sort_keys=True,
592 indent=4,
593 separators=(
594 ',',
595 ': ' ) ) )
596 main.log.warn(
597 "ONOS4 roles: ",
598 json.dumps(
599 json.loads( ONOS4_mastership ),
600 sort_keys=True,
601 indent=4,
602 separators=(
603 ',',
604 ': ' ) ) )
605 main.log.warn(
606 "ONOS5 roles: ",
607 json.dumps(
608 json.loads( ONOS5_mastership ),
609 sort_keys=True,
610 indent=4,
611 separators=(
612 ',',
613 ': ' ) ) )
614 main.log.warn(
615 "ONOS6 roles: ",
616 json.dumps(
617 json.loads( ONOS6_mastership ),
618 sort_keys=True,
619 indent=4,
620 separators=(
621 ',',
622 ': ' ) ) )
623 main.log.warn(
624 "ONOS7 roles: ",
625 json.dumps(
626 json.loads( ONOS7_mastership ),
627 sort_keys=True,
628 indent=4,
629 separators=(
630 ',',
631 ': ' ) ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800632 consistent_mastership = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -0800633 utilities.assert_equals(
634 expect=main.TRUE,
635 actual=consistent_mastership,
636 onpass="Switch roles are consistent across all ONOS nodes",
637 onfail="ONOS nodes have different views of switch roles" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800638
Jon Hall6aec96b2015-01-19 14:49:31 -0800639 main.step( "Get the intents from each controller" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800640 global intent_state
Jon Hall94fd0472014-12-08 11:52:42 -0800641 intent_state = []
Jon Hall73cf9cc2014-11-20 22:28:38 -0800642 ONOS1_intents = main.ONOScli1.intents( json_format=True )
643 ONOS2_intents = main.ONOScli2.intents( json_format=True )
644 ONOS3_intents = main.ONOScli3.intents( json_format=True )
645 ONOS4_intents = main.ONOScli4.intents( json_format=True )
646 ONOS5_intents = main.ONOScli5.intents( json_format=True )
647 ONOS6_intents = main.ONOScli6.intents( json_format=True )
648 ONOS7_intents = main.ONOScli7.intents( json_format=True )
649 intent_check = main.FALSE
650 if "Error" in ONOS1_intents or not ONOS1_intents\
651 or "Error" in ONOS2_intents or not ONOS2_intents\
652 or "Error" in ONOS3_intents or not ONOS3_intents\
653 or "Error" in ONOS4_intents or not ONOS4_intents\
654 or "Error" in ONOS5_intents or not ONOS5_intents\
655 or "Error" in ONOS6_intents or not ONOS6_intents\
656 or "Error" in ONOS7_intents or not ONOS7_intents:
Jon Hall6aec96b2015-01-19 14:49:31 -0800657 main.log.report( "Error in getting ONOS intents" )
658 main.log.warn( "ONOS1 intents response: " + repr( ONOS1_intents ) )
659 main.log.warn( "ONOS2 intents response: " + repr( ONOS2_intents ) )
660 main.log.warn( "ONOS3 intents response: " + repr( ONOS3_intents ) )
661 main.log.warn( "ONOS4 intents response: " + repr( ONOS4_intents ) )
662 main.log.warn( "ONOS5 intents response: " + repr( ONOS5_intents ) )
663 main.log.warn( "ONOS6 intents response: " + repr( ONOS6_intents ) )
664 main.log.warn( "ONOS7 intents response: " + repr( ONOS7_intents ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800665 elif ONOS1_intents == ONOS2_intents\
666 and ONOS1_intents == ONOS3_intents\
667 and ONOS1_intents == ONOS4_intents\
668 and ONOS1_intents == ONOS5_intents\
669 and ONOS1_intents == ONOS6_intents\
670 and ONOS1_intents == ONOS7_intents:
Jon Hall6aec96b2015-01-19 14:49:31 -0800671 intent_state = ONOS1_intents
672 intent_check = main.TRUE
673 main.log.report( "Intents are consistent across all ONOS nodes" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800674 else:
Jon Hall6aec96b2015-01-19 14:49:31 -0800675 main.log.warn(
676 "ONOS1 intents: ",
677 json.dumps(
678 json.loads( ONOS1_intents ),
679 sort_keys=True,
680 indent=4,
681 separators=(
682 ',',
683 ': ' ) ) )
684 main.log.warn(
685 "ONOS2 intents: ",
686 json.dumps(
687 json.loads( ONOS2_intents ),
688 sort_keys=True,
689 indent=4,
690 separators=(
691 ',',
692 ': ' ) ) )
693 main.log.warn(
694 "ONOS3 intents: ",
695 json.dumps(
696 json.loads( ONOS3_intents ),
697 sort_keys=True,
698 indent=4,
699 separators=(
700 ',',
701 ': ' ) ) )
702 main.log.warn(
703 "ONOS4 intents: ",
704 json.dumps(
705 json.loads( ONOS4_intents ),
706 sort_keys=True,
707 indent=4,
708 separators=(
709 ',',
710 ': ' ) ) )
711 main.log.warn(
712 "ONOS5 intents: ",
713 json.dumps(
714 json.loads( ONOS5_intents ),
715 sort_keys=True,
716 indent=4,
717 separators=(
718 ',',
719 ': ' ) ) )
720 main.log.warn(
721 "ONOS6 intents: ",
722 json.dumps(
723 json.loads( ONOS6_intents ),
724 sort_keys=True,
725 indent=4,
726 separators=(
727 ',',
728 ': ' ) ) )
729 main.log.warn(
730 "ONOS7 intents: ",
731 json.dumps(
732 json.loads( ONOS7_intents ),
733 sort_keys=True,
734 indent=4,
735 separators=(
736 ',',
737 ': ' ) ) )
738 utilities.assert_equals(
739 expect=main.TRUE,
740 actual=intent_check,
741 onpass="Intents are consistent across all ONOS nodes",
742 onfail="ONOS nodes have different views of intents" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800743
Jon Hall6aec96b2015-01-19 14:49:31 -0800744 main.step( "Get the flows from each controller" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800745 global flow_state
Jon Hall94fd0472014-12-08 11:52:42 -0800746 flow_state = []
Jon Hall73cf9cc2014-11-20 22:28:38 -0800747 ONOS1_flows = main.ONOScli1.flows( json_format=True )
748 ONOS2_flows = main.ONOScli2.flows( json_format=True )
749 ONOS3_flows = main.ONOScli3.flows( json_format=True )
750 ONOS4_flows = main.ONOScli4.flows( json_format=True )
751 ONOS5_flows = main.ONOScli5.flows( json_format=True )
752 ONOS6_flows = main.ONOScli6.flows( json_format=True )
753 ONOS7_flows = main.ONOScli7.flows( json_format=True )
Jon Hall6aec96b2015-01-19 14:49:31 -0800754 ONOS1_flows_json = json.loads( ONOS1_flows )
755 ONOS2_flows_json = json.loads( ONOS2_flows )
756 ONOS3_flows_json = json.loads( ONOS3_flows )
757 ONOS4_flows_json = json.loads( ONOS4_flows )
758 ONOS5_flows_json = json.loads( ONOS5_flows )
759 ONOS6_flows_json = json.loads( ONOS6_flows )
760 ONOS7_flows_json = json.loads( ONOS7_flows )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800761 flow_check = main.FALSE
762 if "Error" in ONOS1_flows or not ONOS1_flows\
763 or "Error" in ONOS2_flows or not ONOS2_flows\
764 or "Error" in ONOS3_flows or not ONOS3_flows\
765 or "Error" in ONOS4_flows or not ONOS4_flows\
766 or "Error" in ONOS5_flows or not ONOS5_flows\
767 or "Error" in ONOS6_flows or not ONOS6_flows\
768 or "Error" in ONOS7_flows or not ONOS7_flows:
Jon Hall6aec96b2015-01-19 14:49:31 -0800769 main.log.report( "Error in getting ONOS intents" )
770 main.log.warn( "ONOS1 flows repsponse: " + ONOS1_flows )
771 main.log.warn( "ONOS2 flows repsponse: " + ONOS2_flows )
772 main.log.warn( "ONOS3 flows repsponse: " + ONOS3_flows )
773 main.log.warn( "ONOS4 flows repsponse: " + ONOS4_flows )
774 main.log.warn( "ONOS5 flows repsponse: " + ONOS5_flows )
775 main.log.warn( "ONOS6 flows repsponse: " + ONOS6_flows )
776 main.log.warn( "ONOS7 flows repsponse: " + ONOS7_flows )
777 elif len( ONOS1_flows_json ) == len( ONOS2_flows_json )\
778 and len( ONOS1_flows_json ) == len( ONOS3_flows_json )\
779 and len( ONOS1_flows_json ) == len( ONOS4_flows_json )\
780 and len( ONOS1_flows_json ) == len( ONOS5_flows_json )\
781 and len( ONOS1_flows_json ) == len( ONOS6_flows_json )\
782 and len( ONOS1_flows_json ) == len( ONOS7_flows_json ):
783 # TODO: Do a better check, maybe compare flows on switches?
784 flow_state = ONOS1_flows
785 flow_check = main.TRUE
786 main.log.report( "Flow count is consistent across all ONOS nodes" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800787 else:
Jon Hall6aec96b2015-01-19 14:49:31 -0800788 main.log.warn( "ONOS1 flows: " +
789 json.dumps( ONOS1_flows_json, sort_keys=True,
790 indent=4, separators=( ',', ': ' ) ) )
791 main.log.warn( "ONOS2 flows: " +
792 json.dumps( ONOS2_flows_json, sort_keys=True,
793 indent=4, separators=( ',', ': ' ) ) )
794 main.log.warn( "ONOS3 flows: " +
795 json.dumps( ONOS3_flows_json, sort_keys=True,
796 indent=4, separators=( ',', ': ' ) ) )
797 main.log.warn( "ONOS4 flows: " +
798 json.dumps( ONOS4_flows_json, sort_keys=True,
799 indent=4, separators=( ',', ': ' ) ) )
800 main.log.warn( "ONOS5 flows: " +
801 json.dumps( ONOS5_flows_json, sort_keys=True,
802 indent=4, separators=( ',', ': ' ) ) )
803 main.log.warn( "ONOS6 flows: " +
804 json.dumps( ONOS6_flows_json, sort_keys=True,
805 indent=4, separators=( ',', ': ' ) ) )
806 main.log.warn( "ONOS7 flows: " +
807 json.dumps( ONOS7_flows_json, sort_keys=True,
808 indent=4, separators=( ',', ': ' ) ) )
809 utilities.assert_equals(
810 expect=main.TRUE,
811 actual=flow_check,
812 onpass="The flow count is consistent across all ONOS nodes",
813 onfail="ONOS nodes have different flow counts" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800814
Jon Hall6aec96b2015-01-19 14:49:31 -0800815 main.step( "Get the OF Table entries" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800816 global flows
Jon Hall6aec96b2015-01-19 14:49:31 -0800817 flows = []
818 for i in range( 1, 29 ):
819 flows.append( main.Mininet2.get_flowTable( 1.3, "s" + str( i ) ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800820
Jon Hall6aec96b2015-01-19 14:49:31 -0800821 # TODO: Compare switch flow tables with ONOS flow tables
Jon Hall73cf9cc2014-11-20 22:28:38 -0800822
Jon Hall6aec96b2015-01-19 14:49:31 -0800823 main.step( "Start continuous pings" )
824 main.Mininet2.pingLong(
825 src=main.params[ 'PING' ][ 'source1' ],
826 target=main.params[ 'PING' ][ 'target1' ],
827 pingTime=500 )
828 main.Mininet2.pingLong(
829 src=main.params[ 'PING' ][ 'source2' ],
830 target=main.params[ 'PING' ][ 'target2' ],
831 pingTime=500 )
832 main.Mininet2.pingLong(
833 src=main.params[ 'PING' ][ 'source3' ],
834 target=main.params[ 'PING' ][ 'target3' ],
835 pingTime=500 )
836 main.Mininet2.pingLong(
837 src=main.params[ 'PING' ][ 'source4' ],
838 target=main.params[ 'PING' ][ 'target4' ],
839 pingTime=500 )
840 main.Mininet2.pingLong(
841 src=main.params[ 'PING' ][ 'source5' ],
842 target=main.params[ 'PING' ][ 'target5' ],
843 pingTime=500 )
844 main.Mininet2.pingLong(
845 src=main.params[ 'PING' ][ 'source6' ],
846 target=main.params[ 'PING' ][ 'target6' ],
847 pingTime=500 )
848 main.Mininet2.pingLong(
849 src=main.params[ 'PING' ][ 'source7' ],
850 target=main.params[ 'PING' ][ 'target7' ],
851 pingTime=500 )
852 main.Mininet2.pingLong(
853 src=main.params[ 'PING' ][ 'source8' ],
854 target=main.params[ 'PING' ][ 'target8' ],
855 pingTime=500 )
856 main.Mininet2.pingLong(
857 src=main.params[ 'PING' ][ 'source9' ],
858 target=main.params[ 'PING' ][ 'target9' ],
859 pingTime=500 )
860 main.Mininet2.pingLong(
861 src=main.params[ 'PING' ][ 'source10' ],
862 target=main.params[ 'PING' ][ 'target10' ],
863 pingTime=500 )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800864
Jon Hall6aec96b2015-01-19 14:49:31 -0800865 main.step( "Create TestONTopology object" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800866 ctrls = []
867 count = 1
868 while True:
869 temp = ()
Jon Hall6aec96b2015-01-19 14:49:31 -0800870 if ( 'ip' + str( count ) ) in main.params[ 'CTRL' ]:
871 temp = temp + ( getattr( main, ( 'ONOS' + str( count ) ) ), )
872 temp = temp + ( "ONOS" + str( count ), )
873 temp = temp + ( main.params[ 'CTRL' ][ 'ip' + str( count ) ], )
874 temp = temp + \
875 ( eval( main.params[ 'CTRL' ][ 'port' + str( count ) ] ), )
876 ctrls.append( temp )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800877 count = count + 1
878 else:
879 break
Jon Hall6aec96b2015-01-19 14:49:31 -0800880 MNTopo = TestONTopology(
881 main.Mininet1,
882 ctrls ) # can also add Intent API info for intent operations
Jon Hall73cf9cc2014-11-20 22:28:38 -0800883
Jon Hall6aec96b2015-01-19 14:49:31 -0800884 main.step( "Collecting topology information from ONOS" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800885 devices = []
886 devices.append( main.ONOScli1.devices() )
887 devices.append( main.ONOScli2.devices() )
888 devices.append( main.ONOScli3.devices() )
889 devices.append( main.ONOScli4.devices() )
890 devices.append( main.ONOScli5.devices() )
891 devices.append( main.ONOScli6.devices() )
892 devices.append( main.ONOScli7.devices() )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800893 hosts = []
894 hosts.append( main.ONOScli1.hosts() )
895 hosts.append( main.ONOScli2.hosts() )
896 hosts.append( main.ONOScli3.hosts() )
897 hosts.append( main.ONOScli4.hosts() )
898 hosts.append( main.ONOScli5.hosts() )
899 hosts.append( main.ONOScli6.hosts() )
900 hosts.append( main.ONOScli7.hosts() )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800901 ports = []
902 ports.append( main.ONOScli1.ports() )
903 ports.append( main.ONOScli2.ports() )
904 ports.append( main.ONOScli3.ports() )
905 ports.append( main.ONOScli4.ports() )
906 ports.append( main.ONOScli5.ports() )
907 ports.append( main.ONOScli6.ports() )
908 ports.append( main.ONOScli7.ports() )
909 links = []
910 links.append( main.ONOScli1.links() )
911 links.append( main.ONOScli2.links() )
912 links.append( main.ONOScli3.links() )
913 links.append( main.ONOScli4.links() )
914 links.append( main.ONOScli5.links() )
915 links.append( main.ONOScli6.links() )
916 links.append( main.ONOScli7.links() )
Jon Hall94fd0472014-12-08 11:52:42 -0800917 clusters = []
918 clusters.append( main.ONOScli1.clusters() )
919 clusters.append( main.ONOScli2.clusters() )
920 clusters.append( main.ONOScli3.clusters() )
921 clusters.append( main.ONOScli4.clusters() )
922 clusters.append( main.ONOScli5.clusters() )
923 clusters.append( main.ONOScli6.clusters() )
924 clusters.append( main.ONOScli7.clusters() )
925 paths = []
926 temp_topo = main.ONOSbench.get_topology( main.ONOScli1.topology() )
Jon Hall6aec96b2015-01-19 14:49:31 -0800927 paths.append( temp_topo.get( 'paths', False ) )
Jon Hall94fd0472014-12-08 11:52:42 -0800928 temp_topo = main.ONOSbench.get_topology( main.ONOScli2.topology() )
Jon Hall6aec96b2015-01-19 14:49:31 -0800929 paths.append( temp_topo.get( 'paths', False ) )
Jon Hall94fd0472014-12-08 11:52:42 -0800930 temp_topo = main.ONOSbench.get_topology( main.ONOScli3.topology() )
Jon Hall6aec96b2015-01-19 14:49:31 -0800931 paths.append( temp_topo.get( 'paths', False ) )
Jon Hall94fd0472014-12-08 11:52:42 -0800932 temp_topo = main.ONOSbench.get_topology( main.ONOScli4.topology() )
Jon Hall6aec96b2015-01-19 14:49:31 -0800933 paths.append( temp_topo.get( 'paths', False ) )
Jon Hall94fd0472014-12-08 11:52:42 -0800934 temp_topo = main.ONOSbench.get_topology( main.ONOScli5.topology() )
Jon Hall6aec96b2015-01-19 14:49:31 -0800935 paths.append( temp_topo.get( 'paths', False ) )
Jon Hall94fd0472014-12-08 11:52:42 -0800936 temp_topo = main.ONOSbench.get_topology( main.ONOScli6.topology() )
Jon Hall6aec96b2015-01-19 14:49:31 -0800937 paths.append( temp_topo.get( 'paths', False ) )
Jon Hall94fd0472014-12-08 11:52:42 -0800938 temp_topo = main.ONOSbench.get_topology( main.ONOScli7.topology() )
Jon Hall6aec96b2015-01-19 14:49:31 -0800939 paths.append( temp_topo.get( 'paths', False ) )
Jon Hall94fd0472014-12-08 11:52:42 -0800940
Jon Hall6aec96b2015-01-19 14:49:31 -0800941 # Compare json objects for hosts, dataplane clusters and paths
Jon Hall94fd0472014-12-08 11:52:42 -0800942
Jon Hall6aec96b2015-01-19 14:49:31 -0800943 # hosts
Jon Hall94fd0472014-12-08 11:52:42 -0800944 consistent_hosts_result = main.TRUE
945 for controller in range( len( hosts ) ):
Jon Hall6aec96b2015-01-19 14:49:31 -0800946 controller_str = str( controller + 1 )
947 if "Error" not in hosts[ controller ]:
948 if hosts[ controller ] == hosts[ 0 ]:
Jon Hall94fd0472014-12-08 11:52:42 -0800949 continue
Jon Hall6aec96b2015-01-19 14:49:31 -0800950 else: # hosts not consistent
951 main.log.report( "hosts from ONOS" +
952 controller_str +
953 " is inconsistent with ONOS1" )
954 main.log.warn( repr( hosts[ controller ] ) )
Jon Hall94fd0472014-12-08 11:52:42 -0800955 consistent_hosts_result = main.FALSE
956
957 else:
Jon Hall6aec96b2015-01-19 14:49:31 -0800958 main.log.report( "Error in getting ONOS hosts from ONOS" +
959 controller_str )
Jon Hall94fd0472014-12-08 11:52:42 -0800960 consistent_hosts_result = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -0800961 main.log.warn( "ONOS" + controller_str +
962 " hosts response: " +
963 repr( hosts[ controller ] ) )
964 utilities.assert_equals(
965 expect=main.TRUE,
966 actual=consistent_hosts_result,
967 onpass="Hosts view is consistent across all ONOS nodes",
968 onfail="ONOS nodes have different views of hosts" )
Jon Hall94fd0472014-12-08 11:52:42 -0800969
Jon Hall6aec96b2015-01-19 14:49:31 -0800970 # Strongly connected clusters of devices
Jon Hall94fd0472014-12-08 11:52:42 -0800971 consistent_clusters_result = main.TRUE
972 for controller in range( len( clusters ) ):
Jon Hall6aec96b2015-01-19 14:49:31 -0800973 if "Error" not in clusters[ controller ]:
974 if clusters[ controller ] == clusters[ 0 ]:
Jon Hall94fd0472014-12-08 11:52:42 -0800975 continue
Jon Hall6aec96b2015-01-19 14:49:31 -0800976 else: # clusters not consistent
977 main.log.report( "clusters from ONOS" +
978 controller_str +
979 " is inconsistent with ONOS1" )
Jon Hall94fd0472014-12-08 11:52:42 -0800980 consistent_clusters_result = main.FALSE
981
982 else:
Jon Hall6aec96b2015-01-19 14:49:31 -0800983 main.log.report( "Error in getting dataplane clusters " +
984 "from ONOS" + controller_str )
Jon Hall94fd0472014-12-08 11:52:42 -0800985 consistent_clusters_result = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -0800986 main.log.warn( "ONOS" + controller_str +
987 " clusters response: " +
988 repr( clusters[ controller ] ) )
989 utilities.assert_equals(
990 expect=main.TRUE,
991 actual=consistent_clusters_result,
992 onpass="Clusters view is consistent across all ONOS nodes",
993 onfail="ONOS nodes have different views of clusters" )
994 # there should always only be one cluster
995 num_clusters = len( json.loads( clusters[ 0 ] ) )
996 utilities.assert_equals(
997 expect=1,
998 actual=num_clusters,
999 onpass="ONOS shows 1 SCC",
1000 onfail="ONOS shows " +
1001 str( num_clusters ) +
1002 " SCCs" )
Jon Hall94fd0472014-12-08 11:52:42 -08001003
Jon Hall6aec96b2015-01-19 14:49:31 -08001004 # paths
Jon Hall94fd0472014-12-08 11:52:42 -08001005 consistent_paths_result = main.TRUE
1006 for controller in range( len( paths ) ):
Jon Hall6aec96b2015-01-19 14:49:31 -08001007 controller_str = str( controller + 1 )
1008 if "Error" not in paths[ controller ]:
1009 if paths[ controller ] == paths[ 0 ]:
Jon Hall94fd0472014-12-08 11:52:42 -08001010 continue
Jon Hall6aec96b2015-01-19 14:49:31 -08001011 else: # paths not consistent
1012 main.log.report( "paths from ONOS" + controller_str +
1013 " is inconsistent with ONOS1" )
Jon Hall94fd0472014-12-08 11:52:42 -08001014 consistent_paths_result = main.FALSE
1015
1016 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08001017 main.log.report( "Error in getting paths from ONOS" +
1018 controller_str )
Jon Hall94fd0472014-12-08 11:52:42 -08001019 consistent_paths_result = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001020 main.log.warn( "ONOS" + controller_str + " paths response: " +
1021 repr( paths[ controller ] ) )
1022 utilities.assert_equals(
1023 expect=main.TRUE,
1024 actual=consistent_paths_result,
1025 onpass="Paths count is consistent across all ONOS nodes",
1026 onfail="ONOS nodes have different counts of paths" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001027
Jon Hall6aec96b2015-01-19 14:49:31 -08001028 main.step( "Comparing ONOS topology to MN" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001029 devices_results = main.TRUE
1030 ports_results = main.TRUE
1031 links_results = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001032 for controller in range( num_controllers ):
1033 controller_str = str( controller + 1 )
1034 if devices[ controller ] or "Error" not in devices[ controller ]:
1035 current_devices_result = main.Mininet1.compare_switches(
1036 MNTopo,
1037 json.loads(
1038 devices[ controller ] ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001039 else:
1040 current_devices_result = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001041 utilities.assert_equals( expect=main.TRUE,
1042 actual=current_devices_result,
1043 onpass="ONOS" + controller_str +
1044 " Switches view is correct",
1045 onfail="ONOS" + controller_str +
1046 " Switches view is incorrect" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001047
Jon Hall6aec96b2015-01-19 14:49:31 -08001048 if ports[ controller ] or "Error" not in ports[ controller ]:
1049 current_ports_result = main.Mininet1.compare_ports(
1050 MNTopo,
1051 json.loads(
1052 ports[ controller ] ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001053 else:
1054 current_ports_result = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001055 utilities.assert_equals( expect=main.TRUE,
1056 actual=current_ports_result,
1057 onpass="ONOS" + controller_str +
1058 " ports view is correct",
1059 onfail="ONOS" + controller_str +
1060 " ports view is incorrect" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001061
Jon Hall6aec96b2015-01-19 14:49:31 -08001062 if links[ controller ] or "Error" not in links[ controller ]:
1063 current_links_result = main.Mininet1.compare_links(
1064 MNTopo,
1065 json.loads(
1066 links[ controller ] ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001067 else:
1068 current_links_result = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001069 utilities.assert_equals( expect=main.TRUE,
1070 actual=current_links_result,
1071 onpass="ONOS" + controller_str +
1072 " links view is correct",
1073 onfail="ONOS" + controller_str +
1074 " links view is incorrect" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001075
1076 devices_results = devices_results and current_devices_result
1077 ports_results = ports_results and current_ports_result
1078 links_results = links_results and current_links_result
1079
Jon Hall94fd0472014-12-08 11:52:42 -08001080 topo_result = devices_results and ports_results and links_results\
Jon Hall6aec96b2015-01-19 14:49:31 -08001081 and consistent_hosts_result and consistent_clusters_result\
1082 and consistent_paths_result
1083 utilities.assert_equals( expect=main.TRUE, actual=topo_result,
1084 onpass="Topology Check Test successful",
1085 onfail="Topology Check Test NOT successful" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001086
1087 final_assert = main.TRUE
1088 final_assert = final_assert and topo_result and flow_check \
Jon Hall6aec96b2015-01-19 14:49:31 -08001089 and intent_check and consistent_mastership and roles_not_null
1090 utilities.assert_equals( expect=main.TRUE, actual=final_assert,
1091 onpass="State check successful",
1092 onfail="State check NOT successful" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001093
Jon Hall6aec96b2015-01-19 14:49:31 -08001094 def CASE6( self, main ):
1095 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001096 The Failure case.
Jon Hall6aec96b2015-01-19 14:49:31 -08001097 """
1098 main.log.report( "Restart entire ONOS cluster" )
1099 main.log.case( "Restart entire ONOS cluster" )
1100 main.ONOSbench.onos_kill( ONOS1_ip )
1101 main.ONOSbench.onos_kill( ONOS2_ip )
1102 main.ONOSbench.onos_kill( ONOS3_ip )
1103 main.ONOSbench.onos_kill( ONOS4_ip )
1104 main.ONOSbench.onos_kill( ONOS5_ip )
1105 main.ONOSbench.onos_kill( ONOS6_ip )
1106 main.ONOSbench.onos_kill( ONOS7_ip )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001107
Jon Hall6aec96b2015-01-19 14:49:31 -08001108 main.step( "Checking if ONOS is up yet" )
Jon Hallffb386d2014-11-21 13:43:38 -08001109 count = 0
1110 onos_isup_result = main.FALSE
1111 while onos_isup_result == main.FALSE and count < 10:
Jon Hall6aec96b2015-01-19 14:49:31 -08001112 onos1_isup = main.ONOSbench.isup( ONOS1_ip )
1113 onos2_isup = main.ONOSbench.isup( ONOS2_ip )
1114 onos3_isup = main.ONOSbench.isup( ONOS3_ip )
1115 onos4_isup = main.ONOSbench.isup( ONOS4_ip )
1116 onos5_isup = main.ONOSbench.isup( ONOS5_ip )
1117 onos6_isup = main.ONOSbench.isup( ONOS6_ip )
1118 onos7_isup = main.ONOSbench.isup( ONOS7_ip )
Jon Hallffb386d2014-11-21 13:43:38 -08001119 onos_isup_result = onos1_isup and onos2_isup and onos3_isup\
Jon Hall6aec96b2015-01-19 14:49:31 -08001120 and onos4_isup and onos5_isup and onos6_isup and onos7_isup
Jon Hallffb386d2014-11-21 13:43:38 -08001121 count = count + 1
Jon Hall73cf9cc2014-11-20 22:28:38 -08001122 # TODO: if it becomes an issue, we can retry this step a few times
1123
Jon Hall6aec96b2015-01-19 14:49:31 -08001124 cli_result1 = main.ONOScli1.start_onos_cli( ONOS1_ip )
1125 cli_result2 = main.ONOScli2.start_onos_cli( ONOS2_ip )
1126 cli_result3 = main.ONOScli3.start_onos_cli( ONOS3_ip )
1127 cli_result4 = main.ONOScli4.start_onos_cli( ONOS4_ip )
1128 cli_result5 = main.ONOScli5.start_onos_cli( ONOS5_ip )
1129 cli_result6 = main.ONOScli6.start_onos_cli( ONOS6_ip )
1130 cli_result7 = main.ONOScli7.start_onos_cli( ONOS7_ip )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001131 cli_results = cli_result1 and cli_result2 and cli_result3\
Jon Hall6aec96b2015-01-19 14:49:31 -08001132 and cli_result4 and cli_result5 and cli_result6\
1133 and cli_result7
Jon Hall73cf9cc2014-11-20 22:28:38 -08001134
1135 case_results = main.TRUE and onos_isup_result and cli_results
Jon Hall6aec96b2015-01-19 14:49:31 -08001136 utilities.assert_equals( expect=main.TRUE, actual=case_results,
1137 onpass="ONOS restart successful",
1138 onfail="ONOS restart NOT successful" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001139
Jon Hall6aec96b2015-01-19 14:49:31 -08001140 def CASE7( self, main ):
1141 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001142 Check state after ONOS failure
Jon Hall6aec96b2015-01-19 14:49:31 -08001143 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001144 import json
Jon Hall6aec96b2015-01-19 14:49:31 -08001145 main.case( "Running ONOS Constant State Tests" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001146
Jon Hall6aec96b2015-01-19 14:49:31 -08001147 # Assert that each device has a master
Jon Hall94fd0472014-12-08 11:52:42 -08001148 ONOS1_master_not_null = main.ONOScli1.roles_not_null()
1149 ONOS2_master_not_null = main.ONOScli2.roles_not_null()
1150 ONOS3_master_not_null = main.ONOScli3.roles_not_null()
1151 ONOS4_master_not_null = main.ONOScli4.roles_not_null()
1152 ONOS5_master_not_null = main.ONOScli5.roles_not_null()
1153 ONOS6_master_not_null = main.ONOScli6.roles_not_null()
1154 ONOS7_master_not_null = main.ONOScli7.roles_not_null()
1155 roles_not_null = ONOS1_master_not_null and ONOS2_master_not_null and\
Jon Hall6aec96b2015-01-19 14:49:31 -08001156 ONOS3_master_not_null and ONOS4_master_not_null and\
1157 ONOS5_master_not_null and ONOS6_master_not_null and\
1158 ONOS7_master_not_null
1159 utilities.assert_equals(
1160 expect=main.TRUE,
1161 actual=roles_not_null,
1162 onpass="Each device has a master",
1163 onfail="Some devices don't have a master assigned" )
Jon Hall94fd0472014-12-08 11:52:42 -08001164
Jon Hall6aec96b2015-01-19 14:49:31 -08001165 main.step( "Check if switch roles are consistent across all nodes" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001166 ONOS1_mastership = main.ONOScli1.roles()
1167 ONOS2_mastership = main.ONOScli2.roles()
1168 ONOS3_mastership = main.ONOScli3.roles()
1169 ONOS4_mastership = main.ONOScli4.roles()
1170 ONOS5_mastership = main.ONOScli5.roles()
1171 ONOS6_mastership = main.ONOScli6.roles()
1172 ONOS7_mastership = main.ONOScli7.roles()
Jon Hall73cf9cc2014-11-20 22:28:38 -08001173 if "Error" in ONOS1_mastership or not ONOS1_mastership\
1174 or "Error" in ONOS2_mastership or not ONOS2_mastership\
1175 or "Error" in ONOS3_mastership or not ONOS3_mastership\
1176 or "Error" in ONOS4_mastership or not ONOS4_mastership\
1177 or "Error" in ONOS5_mastership or not ONOS5_mastership\
1178 or "Error" in ONOS6_mastership or not ONOS6_mastership\
1179 or "Error" in ONOS7_mastership or not ONOS7_mastership:
Jon Hall6aec96b2015-01-19 14:49:31 -08001180 main.log.error( "Error in getting ONOS mastership" )
1181 main.log.warn( "ONOS1 mastership response: " +
1182 repr( ONOS1_mastership ) )
1183 main.log.warn( "ONOS2 mastership response: " +
1184 repr( ONOS2_mastership ) )
1185 main.log.warn( "ONOS3 mastership response: " +
1186 repr( ONOS3_mastership ) )
1187 main.log.warn( "ONOS4 mastership response: " +
1188 repr( ONOS4_mastership ) )
1189 main.log.warn( "ONOS5 mastership response: " +
1190 repr( ONOS5_mastership ) )
1191 main.log.warn( "ONOS6 mastership response: " +
1192 repr( ONOS6_mastership ) )
1193 main.log.warn( "ONOS7 mastership response: " +
1194 repr( ONOS7_mastership ) )
1195 consistent_mastership = main.FALSE
Jon Hall73cf9cc2014-11-20 22:28:38 -08001196 elif ONOS1_mastership == ONOS2_mastership\
1197 and ONOS1_mastership == ONOS3_mastership\
1198 and ONOS1_mastership == ONOS4_mastership\
1199 and ONOS1_mastership == ONOS5_mastership\
1200 and ONOS1_mastership == ONOS6_mastership\
1201 and ONOS1_mastership == ONOS7_mastership:
Jon Hall6aec96b2015-01-19 14:49:31 -08001202 consistent_mastership = main.TRUE
1203 main.log.report(
1204 "Switch roles are consistent across all ONOS nodes" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001205 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08001206 main.log.warn( "ONOS1 roles: ", json.dumps(
1207 json.loads( ONOS1_mastership ), sort_keys=True, indent=4,
1208 separators=( ',', ': ' ) ) )
1209 main.log.warn( "ONOS2 roles: ", json.dumps(
1210 json.loads( ONOS2_mastership ), sort_keys=True, indent=4,
1211 separators=( ',', ': ' ) ) )
1212 main.log.warn( "ONOS3 roles: ", json.dumps(
1213 json.loads( ONOS3_mastership ), sort_keys=True, indent=4,
1214 separators=( ',', ': ' ) ) )
1215 main.log.warn( "ONOS4 roles: ", json.dumps(
1216 json.loads( ONOS4_mastership ), sort_keys=True, indent=4,
1217 separators=( ',', ': ' ) ) )
1218 main.log.warn( "ONOS5 roles: ", json.dumps(
1219 json.loads( ONOS5_mastership ), sort_keys=True, indent=4,
1220 separators=( ',', ': ' ) ) )
1221 main.log.warn( "ONOS6 roles: ", json.dumps(
1222 json.loads( ONOS6_mastership ), sort_keys=True, indent=4,
1223 separators=( ',', ': ' ) ) )
1224 main.log.warn( "ONOS7 roles: ", json.dumps(
1225 json.loads( ONOS7_mastership ), sort_keys=True, indent=4,
1226 separators=( ',', ': ' ) ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001227 consistent_mastership = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001228 utilities.assert_equals(
1229 expect=main.TRUE,
1230 actual=consistent_mastership,
1231 onpass="Switch roles are consistent across all ONOS nodes",
1232 onfail="ONOS nodes have different views of switch roles" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001233
1234 description2 = "Compare switch roles from before failure"
Jon Hall6aec96b2015-01-19 14:49:31 -08001235 main.step( description2 )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001236
Jon Hall6aec96b2015-01-19 14:49:31 -08001237 current_json = json.loads( ONOS1_mastership )
1238 old_json = json.loads( mastership_state )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001239 mastership_check = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001240 for i in range( 1, 29 ):
1241 switchDPID = str(
1242 main.Mininet1.getSwitchDPID(
1243 switch="s" +
1244 str( i ) ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001245
Jon Hall6aec96b2015-01-19 14:49:31 -08001246 current = [ switch[ 'master' ] for switch in current_json
1247 if switchDPID in switch[ 'id' ] ]
1248 old = [ switch[ 'master' ] for switch in old_json
1249 if switchDPID in switch[ 'id' ] ]
Jon Hall73cf9cc2014-11-20 22:28:38 -08001250 if current == old:
1251 mastership_check = mastership_check and main.TRUE
1252 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08001253 main.log.warn( "Mastership of switch %s changed" % switchDPID )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001254 mastership_check = main.FALSE
1255 if mastership_check == main.TRUE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001256 main.log.report( "Mastership of Switches was not changed" )
1257 utilities.assert_equals(
1258 expect=main.TRUE,
1259 actual=mastership_check,
1260 onpass="Mastership of Switches was not changed",
1261 onfail="Mastership of some switches changed" )
1262 # NOTE: we expect mastership to change on controller failure
1263 mastership_check = mastership_check and consistent_mastership
Jon Hall73cf9cc2014-11-20 22:28:38 -08001264
Jon Hall6aec96b2015-01-19 14:49:31 -08001265 main.step( "Get the intents and compare across all nodes" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001266 ONOS1_intents = main.ONOScli1.intents( json_format=True )
1267 ONOS2_intents = main.ONOScli2.intents( json_format=True )
1268 ONOS3_intents = main.ONOScli3.intents( json_format=True )
1269 ONOS4_intents = main.ONOScli4.intents( json_format=True )
1270 ONOS5_intents = main.ONOScli5.intents( json_format=True )
1271 ONOS6_intents = main.ONOScli6.intents( json_format=True )
1272 ONOS7_intents = main.ONOScli7.intents( json_format=True )
1273 intent_check = main.FALSE
1274 if "Error" in ONOS1_intents or not ONOS1_intents\
1275 or "Error" in ONOS2_intents or not ONOS2_intents\
1276 or "Error" in ONOS3_intents or not ONOS3_intents\
1277 or "Error" in ONOS4_intents or not ONOS4_intents\
1278 or "Error" in ONOS5_intents or not ONOS5_intents\
1279 or "Error" in ONOS6_intents or not ONOS6_intents\
1280 or "Error" in ONOS7_intents or not ONOS7_intents:
Jon Hall6aec96b2015-01-19 14:49:31 -08001281 main.log.report( "Error in getting ONOS intents" )
1282 main.log.warn( "ONOS1 intents response: " + repr( ONOS1_intents ) )
1283 main.log.warn( "ONOS2 intents response: " + repr( ONOS2_intents ) )
1284 main.log.warn( "ONOS3 intents response: " + repr( ONOS3_intents ) )
1285 main.log.warn( "ONOS4 intents response: " + repr( ONOS4_intents ) )
1286 main.log.warn( "ONOS5 intents response: " + repr( ONOS5_intents ) )
1287 main.log.warn( "ONOS6 intents response: " + repr( ONOS6_intents ) )
1288 main.log.warn( "ONOS7 intents response: " + repr( ONOS7_intents ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001289 elif ONOS1_intents == ONOS2_intents\
1290 and ONOS1_intents == ONOS3_intents\
1291 and ONOS1_intents == ONOS4_intents\
1292 and ONOS1_intents == ONOS5_intents\
1293 and ONOS1_intents == ONOS6_intents\
1294 and ONOS1_intents == ONOS7_intents:
Jon Hall6aec96b2015-01-19 14:49:31 -08001295 intent_check = main.TRUE
1296 main.log.report( "Intents are consistent across all ONOS nodes" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001297 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08001298 main.log.warn( "ONOS1 intents: " )
1299 print json.dumps( json.loads( ONOS1_intents ), sort_keys=True,
1300 indent=4, separators=( ',', ': ' ) )
1301 main.log.warn( "ONOS2 intents: " )
1302 print json.dumps( json.loads( ONOS2_intents ), sort_keys=True,
1303 indent=4, separators=( ',', ': ' ) )
1304 main.log.warn( "ONOS3 intents: " )
1305 print json.dumps( json.loads( ONOS3_intents ), sort_keys=True,
1306 indent=4, separators=( ',', ': ' ) )
1307 main.log.warn( "ONOS4 intents: " )
1308 print json.dumps( json.loads( ONOS4_intents ), sort_keys=True,
1309 indent=4, separators=( ',', ': ' ) )
1310 main.log.warn( "ONOS5 intents: " )
1311 print json.dumps( json.loads( ONOS5_intents ), sort_keys=True,
1312 indent=4, separators=( ',', ': ' ) )
1313 main.log.warn( "ONOS6 intents: " )
1314 print json.dumps( json.loads( ONOS6_intents ), sort_keys=True,
1315 indent=4, separators=( ',', ': ' ) )
1316 main.log.warn( "ONOS7 intents: " )
1317 print json.dumps( json.loads( ONOS7_intents ), sort_keys=True,
1318 indent=4, separators=( ',', ': ' ) )
1319 utilities.assert_equals(
1320 expect=main.TRUE,
1321 actual=intent_check,
1322 onpass="Intents are consistent across all ONOS nodes",
1323 onfail="ONOS nodes have different views of intents" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001324
Jon Hall6aec96b2015-01-19 14:49:31 -08001325 # NOTE: Hazelcast has no durability, so intents are lost across system
1326 # restarts
1327 """
1328 main.step( "Compare current intents with intents before the failure" )
1329 # NOTE: this requires case 5 to pass for intent_state to be set.
Jon Hall94fd0472014-12-08 11:52:42 -08001330 # maybe we should stop the test if that fails?
Jon Hall73cf9cc2014-11-20 22:28:38 -08001331 if intent_state == ONOS1_intents:
1332 same_intents = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001333 main.log.report( "Intents are consistent with before failure" )
1334 # TODO: possibly the states have changed? we may need to figure out
1335 # what the aceptable states are
Jon Hall73cf9cc2014-11-20 22:28:38 -08001336 else:
Jon Hall669173b2014-12-17 11:36:30 -08001337 try:
Jon Hall6aec96b2015-01-19 14:49:31 -08001338 main.log.warn( "ONOS1 intents: " )
1339 print json.dumps( json.loads( ONOS1_intents ),
1340 sort_keys=True, indent=4,
1341 separators=( ',', ': ' ) )
Jon Hall669173b2014-12-17 11:36:30 -08001342 except:
1343 pass
Jon Hall73cf9cc2014-11-20 22:28:38 -08001344 same_intents = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001345 utilities.assert_equals(
1346 expect=main.TRUE,
1347 actual=same_intents,
1348 onpass="Intents are consistent with before failure",
1349 onfail="The Intents changed during failure" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001350 intent_check = intent_check and same_intents
Jon Hall6aec96b2015-01-19 14:49:31 -08001351 """
1352 main.step( "Get the OF Table entries and compare to before " +
1353 "component failure" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001354 Flow_Tables = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001355 flows2 = []
1356 for i in range( 28 ):
1357 main.log.info( "Checking flow table on s" + str( i + 1 ) )
1358 tmp_flows = main.Mininet2.get_flowTable( 1.3, "s" + str( i + 1 ) )
1359 flows2.append( tmp_flows )
1360 temp_result = main.Mininet2.flow_comp(
1361 flow1=flows[ i ],
1362 flow2=tmp_flows )
Jon Hall94fd0472014-12-08 11:52:42 -08001363 Flow_Tables = Flow_Tables and temp_result
Jon Hall73cf9cc2014-11-20 22:28:38 -08001364 if Flow_Tables == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001365 main.log.info( "Differences in flow table for switch: s" +
1366 str( i + 1 ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001367 if Flow_Tables == main.TRUE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001368 main.log.report( "No changes were found in the flow tables" )
1369 utilities.assert_equals(
1370 expect=main.TRUE,
1371 actual=Flow_Tables,
1372 onpass="No changes were found in the flow tables",
1373 onfail="Changes were found in the flow tables" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001374
Jon Hall6aec96b2015-01-19 14:49:31 -08001375 main.step( "Check the continuous pings to ensure that no packets " +
1376 "were dropped during component failure" )
1377 # FIXME: This check is always failing. Investigate cause
1378 # NOTE: this may be something to do with file permsissions
Jon Hall73cf9cc2014-11-20 22:28:38 -08001379 # or slight change in format
Jon Hall6aec96b2015-01-19 14:49:31 -08001380 main.Mininet2.pingKill(
1381 main.params[ 'TESTONUSER' ],
1382 main.params[ 'TESTONIP' ] )
1383 Loss_In_Pings = main.FALSE
1384 # NOTE: checkForLoss returns main.FALSE with 0% packet loss
1385 for i in range( 8, 18 ):
1386 main.log.info(
1387 "Checking for a loss in pings along flow from s" +
1388 str( i ) )
1389 Loss_In_Pings = main.Mininet2.checkForLoss(
1390 "/tmp/ping.h" +
1391 str( i ) ) or Loss_In_Pings
Jon Hall73cf9cc2014-11-20 22:28:38 -08001392 if Loss_In_Pings == main.TRUE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001393 main.log.info( "Loss in ping detected" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001394 elif Loss_In_Pings == main.ERROR:
Jon Hall6aec96b2015-01-19 14:49:31 -08001395 main.log.info( "There are multiple mininet process running" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001396 elif Loss_In_Pings == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001397 main.log.info( "No Loss in the pings" )
1398 main.log.report( "No loss of dataplane connectivity" )
1399 utilities.assert_equals(
1400 expect=main.FALSE,
1401 actual=Loss_In_Pings,
1402 onpass="No Loss of connectivity",
1403 onfail="Loss of dataplane connectivity detected" )
1404 # NOTE: Since intents are not persisted with Hazelcast, we expect this
Jon Hall94fd0472014-12-08 11:52:42 -08001405 Loss_In_Pings = main.FALSE
Jon Hall73cf9cc2014-11-20 22:28:38 -08001406
Jon Hall6aec96b2015-01-19 14:49:31 -08001407 # Test of LeadershipElection
Jon Hall669173b2014-12-17 11:36:30 -08001408 leader_list = []
1409 leader_result = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001410 for controller in range( 1, num_controllers + 1 ):
1411 # loop through ONOScli handlers
1412 node = getattr( main, ( 'ONOScli' + str( controller ) ) )
Jon Hall669173b2014-12-17 11:36:30 -08001413 leaderN = node.election_test_leader()
Jon Hall6aec96b2015-01-19 14:49:31 -08001414 leader_list.append( leaderN )
Jon Hall669173b2014-12-17 11:36:30 -08001415 if leaderN == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001416 # error in response
1417 main.log.report( "Something is wrong with " +
1418 "election_test_leader function, check the" +
1419 " error logs" )
Jon Hall669173b2014-12-17 11:36:30 -08001420 leader_result = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001421 elif leaderN is None:
1422 main.log.report( "ONOS" + str( controller ) +
1423 " shows no leader for the election-app was" +
1424 " elected after the old one died" )
Jon Hall669173b2014-12-17 11:36:30 -08001425 leader_result = main.FALSE
1426 if len( set( leader_list ) ) != 1:
1427 leader_result = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001428 main.log.error(
1429 "Inconsistent view of leader for the election test app" )
1430 # TODO: print the list
Jon Hall669173b2014-12-17 11:36:30 -08001431 if leader_result:
Jon Hall6aec96b2015-01-19 14:49:31 -08001432 main.log.report( "Leadership election tests passed(consistent " +
1433 "view of leader across listeners and a new " +
1434 "leader was re-elected if applicable)" )
1435 utilities.assert_equals(
1436 expect=main.TRUE,
1437 actual=leader_result,
1438 onpass="Leadership election passed",
1439 onfail="Something went wrong with Leadership election" )
Jon Hall669173b2014-12-17 11:36:30 -08001440
Jon Hall6aec96b2015-01-19 14:49:31 -08001441 result = ( mastership_check and intent_check and Flow_Tables and
1442 ( not Loss_In_Pings ) and roles_not_null and leader_result )
1443 result = int( result )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001444 if result == main.TRUE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001445 main.log.report( "Constant State Tests Passed" )
1446 utilities.assert_equals( expect=main.TRUE, actual=result,
1447 onpass="Constant State Tests Passed",
1448 onfail="Constant state tests failed" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001449
Jon Hall6aec96b2015-01-19 14:49:31 -08001450 def CASE8( self, main ):
1451 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001452 Compare topo
Jon Hall6aec96b2015-01-19 14:49:31 -08001453 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001454 import sys
Jon Hall6aec96b2015-01-19 14:49:31 -08001455 # FIXME add this path to params
1456 sys.path.append( "/home/admin/sts" )
1457 # assumes that sts is already in you PYTHONPATH
1458 from sts.topology.teston_topology import TestONTopology
Jon Hall73cf9cc2014-11-20 22:28:38 -08001459 import json
1460 import time
1461
Jon Hall6aec96b2015-01-19 14:49:31 -08001462 description = "Compare ONOS Topology view to Mininet topology"
1463 main.case( description )
1464 main.log.report( description )
1465 main.step( "Create TestONTopology object" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001466 ctrls = []
1467 count = 1
1468 while True:
1469 temp = ()
Jon Hall6aec96b2015-01-19 14:49:31 -08001470 if ( 'ip' + str( count ) ) in main.params[ 'CTRL' ]:
1471 temp = temp + ( getattr( main, ( 'ONOS' + str( count ) ) ), )
1472 temp = temp + ( "ONOS" + str( count ), )
1473 temp = temp + ( main.params[ 'CTRL' ][ 'ip' + str( count ) ], )
1474 temp = temp + \
1475 ( eval( main.params[ 'CTRL' ][ 'port' + str( count ) ] ), )
1476 ctrls.append( temp )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001477 count = count + 1
1478 else:
1479 break
Jon Hall6aec96b2015-01-19 14:49:31 -08001480 MNTopo = TestONTopology(
1481 main.Mininet1,
1482 ctrls ) # can also add Intent API info for intent operations
Jon Hall73cf9cc2014-11-20 22:28:38 -08001483
Jon Hall6aec96b2015-01-19 14:49:31 -08001484 main.step( "Comparing ONOS topology to MN" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001485 devices_results = main.TRUE
1486 ports_results = main.TRUE
1487 links_results = main.TRUE
1488 topo_result = main.FALSE
Jon Hall73cf9cc2014-11-20 22:28:38 -08001489 elapsed = 0
Jon Hallffb386d2014-11-21 13:43:38 -08001490 count = 0
Jon Hall6aec96b2015-01-19 14:49:31 -08001491 main.step( "Collecting topology information from ONOS" )
Jon Hall94fd0472014-12-08 11:52:42 -08001492 start_time = time.time()
1493 while topo_result == main.FALSE and elapsed < 60:
Jon Hallffb386d2014-11-21 13:43:38 -08001494 count = count + 1
Jon Hall94fd0472014-12-08 11:52:42 -08001495 if count > 1:
Jon Hall6aec96b2015-01-19 14:49:31 -08001496 # TODO: Depricate STS usage
1497 MNTopo = TestONTopology(
1498 main.Mininet1,
1499 ctrls )
Jon Hall94fd0472014-12-08 11:52:42 -08001500 cli_start = time.time()
1501 devices = []
1502 devices.append( main.ONOScli1.devices() )
1503 devices.append( main.ONOScli2.devices() )
1504 devices.append( main.ONOScli3.devices() )
1505 devices.append( main.ONOScli4.devices() )
1506 devices.append( main.ONOScli5.devices() )
1507 devices.append( main.ONOScli6.devices() )
1508 devices.append( main.ONOScli7.devices() )
1509 hosts = []
1510 hosts.append( main.ONOScli1.hosts() )
1511 hosts.append( main.ONOScli2.hosts() )
1512 hosts.append( main.ONOScli3.hosts() )
1513 hosts.append( main.ONOScli4.hosts() )
1514 hosts.append( main.ONOScli5.hosts() )
1515 hosts.append( main.ONOScli6.hosts() )
1516 hosts.append( main.ONOScli7.hosts() )
1517 ports = []
1518 ports.append( main.ONOScli1.ports() )
1519 ports.append( main.ONOScli2.ports() )
1520 ports.append( main.ONOScli3.ports() )
1521 ports.append( main.ONOScli4.ports() )
1522 ports.append( main.ONOScli5.ports() )
1523 ports.append( main.ONOScli6.ports() )
1524 ports.append( main.ONOScli7.ports() )
1525 links = []
1526 links.append( main.ONOScli1.links() )
1527 links.append( main.ONOScli2.links() )
1528 links.append( main.ONOScli3.links() )
1529 links.append( main.ONOScli4.links() )
1530 links.append( main.ONOScli5.links() )
1531 links.append( main.ONOScli6.links() )
1532 links.append( main.ONOScli7.links() )
1533 clusters = []
1534 clusters.append( main.ONOScli1.clusters() )
1535 clusters.append( main.ONOScli2.clusters() )
1536 clusters.append( main.ONOScli3.clusters() )
1537 clusters.append( main.ONOScli4.clusters() )
1538 clusters.append( main.ONOScli5.clusters() )
1539 clusters.append( main.ONOScli6.clusters() )
1540 clusters.append( main.ONOScli7.clusters() )
1541 paths = []
1542 temp_topo = main.ONOSbench.get_topology( main.ONOScli1.topology() )
Jon Hall6aec96b2015-01-19 14:49:31 -08001543 paths.append( temp_topo.get( 'paths', False ) )
Jon Hall94fd0472014-12-08 11:52:42 -08001544 temp_topo = main.ONOSbench.get_topology( main.ONOScli2.topology() )
Jon Hall6aec96b2015-01-19 14:49:31 -08001545 paths.append( temp_topo.get( 'paths', False ) )
Jon Hall94fd0472014-12-08 11:52:42 -08001546 temp_topo = main.ONOSbench.get_topology( main.ONOScli3.topology() )
Jon Hall6aec96b2015-01-19 14:49:31 -08001547 paths.append( temp_topo.get( 'paths', False ) )
Jon Hall94fd0472014-12-08 11:52:42 -08001548 temp_topo = main.ONOSbench.get_topology( main.ONOScli4.topology() )
Jon Hall6aec96b2015-01-19 14:49:31 -08001549 paths.append( temp_topo.get( 'paths', False ) )
Jon Hall94fd0472014-12-08 11:52:42 -08001550 temp_topo = main.ONOSbench.get_topology( main.ONOScli5.topology() )
Jon Hall6aec96b2015-01-19 14:49:31 -08001551 paths.append( temp_topo.get( 'paths', False ) )
Jon Hall94fd0472014-12-08 11:52:42 -08001552 temp_topo = main.ONOSbench.get_topology( main.ONOScli6.topology() )
Jon Hall6aec96b2015-01-19 14:49:31 -08001553 paths.append( temp_topo.get( 'paths', False ) )
Jon Hall94fd0472014-12-08 11:52:42 -08001554 temp_topo = main.ONOSbench.get_topology( main.ONOScli7.topology() )
Jon Hall6aec96b2015-01-19 14:49:31 -08001555 paths.append( temp_topo.get( 'paths', False ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001556
Jon Hall94fd0472014-12-08 11:52:42 -08001557 elapsed = time.time() - start_time
1558 cli_time = time.time() - cli_start
Jon Hall6aec96b2015-01-19 14:49:31 -08001559 print "CLI time: " + str( cli_time )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001560
Jon Hall6aec96b2015-01-19 14:49:31 -08001561 for controller in range( num_controllers ):
1562 controller_str = str( controller + 1 )
1563 if devices[ controller ] or "Error" not in devices[
1564 controller ]:
1565 current_devices_result = main.Mininet1.compare_switches(
1566 MNTopo,
1567 json.loads(
1568 devices[ controller ] ) )
Jon Hall94fd0472014-12-08 11:52:42 -08001569 else:
1570 current_devices_result = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001571 utilities.assert_equals( expect=main.TRUE,
1572 actual=current_devices_result,
1573 onpass="ONOS" + controller_str +
1574 " Switches view is correct",
1575 onfail="ONOS" + controller_str +
1576 " Switches view is incorrect" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001577
Jon Hall6aec96b2015-01-19 14:49:31 -08001578 if ports[ controller ] or "Error" not in ports[ controller ]:
1579 current_ports_result = main.Mininet1.compare_ports(
1580 MNTopo,
1581 json.loads(
1582 ports[ controller ] ) )
Jon Hall94fd0472014-12-08 11:52:42 -08001583 else:
1584 current_ports_result = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001585 utilities.assert_equals( expect=main.TRUE,
1586 actual=current_ports_result,
1587 onpass="ONOS" + controller_str +
1588 " ports view is correct",
1589 onfail="ONOS" + controller_str +
1590 " ports view is incorrect" )
Jon Hall94fd0472014-12-08 11:52:42 -08001591
Jon Hall6aec96b2015-01-19 14:49:31 -08001592 if links[ controller ] or "Error" not in links[ controller ]:
1593 current_links_result = main.Mininet1.compare_links(
1594 MNTopo,
1595 json.loads(
1596 links[ controller ] ) )
Jon Hall94fd0472014-12-08 11:52:42 -08001597 else:
1598 current_links_result = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001599 utilities.assert_equals( expect=main.TRUE,
1600 actual=current_links_result,
1601 onpass="ONOS" + controller_str +
1602 " links view is correct",
1603 onfail="ONOS" + controller_str +
1604 " links view is incorrect" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001605 devices_results = devices_results and current_devices_result
1606 ports_results = ports_results and current_ports_result
1607 links_results = links_results and current_links_result
Jon Hall94fd0472014-12-08 11:52:42 -08001608
Jon Hall6aec96b2015-01-19 14:49:31 -08001609 # Compare json objects for hosts, dataplane clusters and paths
Jon Hall94fd0472014-12-08 11:52:42 -08001610
Jon Hall6aec96b2015-01-19 14:49:31 -08001611 # hosts
Jon Hall94fd0472014-12-08 11:52:42 -08001612 consistent_hosts_result = main.TRUE
1613 for controller in range( len( hosts ) ):
Jon Hall6aec96b2015-01-19 14:49:31 -08001614 controller_str = str( controller + 1 )
1615 if "Error" not in hosts[ controller ]:
1616 if hosts[ controller ] == hosts[ 0 ]:
Jon Hall94fd0472014-12-08 11:52:42 -08001617 continue
Jon Hall6aec96b2015-01-19 14:49:31 -08001618 else: # hosts not consistent
1619 main.log.report( "hosts from ONOS" + controller_str +
1620 " is inconsistent with ONOS1" )
1621 main.log.warn( repr( hosts[ controller ] ) )
Jon Hall94fd0472014-12-08 11:52:42 -08001622 consistent_hosts_result = main.FALSE
1623
1624 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08001625 main.log.report( "Error in getting ONOS hosts from ONOS" +
1626 controller_str )
Jon Hall94fd0472014-12-08 11:52:42 -08001627 consistent_hosts_result = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001628 main.log.warn( "ONOS" + controller_str +
1629 " hosts response: " +
1630 repr( hosts[ controller ] ) )
1631 utilities.assert_equals(
1632 expect=main.TRUE,
1633 actual=consistent_hosts_result,
1634 onpass="Hosts view is consistent across all ONOS nodes",
1635 onfail="ONOS nodes have different views of hosts" )
Jon Hall94fd0472014-12-08 11:52:42 -08001636
Jon Hall6aec96b2015-01-19 14:49:31 -08001637 # Strongly connected clusters of devices
Jon Hall94fd0472014-12-08 11:52:42 -08001638 consistent_clusters_result = main.TRUE
1639 for controller in range( len( clusters ) ):
Jon Hall6aec96b2015-01-19 14:49:31 -08001640 controller_str = str( controller + 1 )
1641 if "Error" not in clusters[ controller ]:
1642 if clusters[ controller ] == clusters[ 0 ]:
Jon Hall94fd0472014-12-08 11:52:42 -08001643 continue
Jon Hall6aec96b2015-01-19 14:49:31 -08001644 else: # clusters not consistent
1645 main.log.report( "clusters from ONOS" +
1646 controller_str +
1647 " is inconsistent with ONOS1" )
Jon Hall94fd0472014-12-08 11:52:42 -08001648 consistent_clusters_result = main.FALSE
1649
1650 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08001651 main.log.report( "Error in getting dataplane clusters " +
1652 "from ONOS" + controller_str )
Jon Hall94fd0472014-12-08 11:52:42 -08001653 consistent_clusters_result = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001654 main.log.warn( "ONOS" + controller_str +
1655 " clusters response: " +
1656 repr( clusters[ controller ] ) )
1657 utilities.assert_equals(
1658 expect=main.TRUE,
1659 actual=consistent_clusters_result,
1660 onpass="Clusters view is consistent across all ONOS nodes",
1661 onfail="ONOS nodes have different views of clusters" )
1662 # there should always only be one cluster
1663 num_clusters = len( json.loads( clusters[ 0 ] ) )
1664 utilities.assert_equals(
1665 expect=1,
1666 actual=num_clusters,
1667 onpass="ONOS shows 1 SCC",
1668 onfail="ONOS shows " +
1669 str( num_clusters ) +
1670 " SCCs" )
Jon Hall94fd0472014-12-08 11:52:42 -08001671
Jon Hall6aec96b2015-01-19 14:49:31 -08001672 # paths
Jon Hall94fd0472014-12-08 11:52:42 -08001673 consistent_paths_result = main.TRUE
1674 for controller in range( len( paths ) ):
Jon Hall6aec96b2015-01-19 14:49:31 -08001675 controller_str = str( controller + 1 )
1676 if "Error" not in paths[ controller ]:
1677 if paths[ controller ] == paths[ 0 ]:
Jon Hall94fd0472014-12-08 11:52:42 -08001678 continue
Jon Hall6aec96b2015-01-19 14:49:31 -08001679 else: # paths not consistent
1680 main.log.report( "paths from ONOS" + controller_str +
1681 " is inconsistent with ONOS1" )
Jon Hall94fd0472014-12-08 11:52:42 -08001682 consistent_paths_result = main.FALSE
1683
1684 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08001685 main.log.report( "Error in getting paths from ONOS" +
1686 controller_str )
Jon Hall94fd0472014-12-08 11:52:42 -08001687 consistent_paths_result = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001688 main.log.warn( "ONOS" + controller_str +
1689 " paths response: " +
1690 repr( paths[ controller ] ) )
1691 utilities.assert_equals(
1692 expect=main.TRUE,
1693 actual=consistent_paths_result,
1694 onpass="Paths count is consistent across all ONOS nodes",
1695 onfail="ONOS nodes have different counts of paths" )
Jon Hall94fd0472014-12-08 11:52:42 -08001696
Jon Hall6aec96b2015-01-19 14:49:31 -08001697 topo_result = ( devices_results and ports_results and links_results
1698 and consistent_hosts_result
1699 and consistent_clusters_result
1700 and consistent_paths_result )
Jon Hall94fd0472014-12-08 11:52:42 -08001701
Jon Hall6aec96b2015-01-19 14:49:31 -08001702 topo_result = topo_result and int( count <= 2 )
1703 note = "note it takes about " + str( int( cli_time ) ) + \
1704 " seconds for the test to make all the cli calls to fetch " +\
1705 "the topology from each ONOS instance"
1706 main.log.report(
1707 "Very crass estimate for topology discovery/convergence(" +
1708 str( note ) + "): " + str( elapsed ) + " seconds, " +
1709 str( count ) + " tries" )
1710 utilities.assert_equals( expect=main.TRUE, actual=topo_result,
1711 onpass="Topology Check Test successful",
1712 onfail="Topology Check Test NOT successful" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001713 if topo_result == main.TRUE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001714 main.log.report( "ONOS topology view matches Mininet topology" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001715
Jon Hall6aec96b2015-01-19 14:49:31 -08001716 def CASE9( self, main ):
1717 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001718 Link s3-s28 down
Jon Hall6aec96b2015-01-19 14:49:31 -08001719 """
1720 import time
1721 # NOTE: You should probably run a topology check after this
Jon Hall73cf9cc2014-11-20 22:28:38 -08001722
Jon Hall6aec96b2015-01-19 14:49:31 -08001723 link_sleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001724
Jon Hall6aec96b2015-01-19 14:49:31 -08001725 description = "Turn off a link to ensure that Link Discovery " +\
1726 "is working properly"
1727 main.log.report( description )
1728 main.case( description )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001729
Jon Hall6aec96b2015-01-19 14:49:31 -08001730 main.step( "Kill Link between s3 and s28" )
1731 Link_Down = main.Mininet1.link( END1="s3", END2="s28", OPTION="down" )
1732 main.log.info(
1733 "Waiting " +
1734 str( link_sleep ) +
1735 " seconds for link down to be discovered" )
1736 time.sleep( link_sleep )
1737 utilities.assert_equals( expect=main.TRUE, actual=Link_Down,
1738 onpass="Link down succesful",
1739 onfail="Failed to bring link down" )
1740 # TODO do some sort of check here
Jon Hall73cf9cc2014-11-20 22:28:38 -08001741
Jon Hall6aec96b2015-01-19 14:49:31 -08001742 def CASE10( self, main ):
1743 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001744 Link s3-s28 up
Jon Hall6aec96b2015-01-19 14:49:31 -08001745 """
1746 import time
1747 # NOTE: You should probably run a topology check after this
Jon Hall73cf9cc2014-11-20 22:28:38 -08001748
Jon Hall6aec96b2015-01-19 14:49:31 -08001749 link_sleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001750
Jon Hall6aec96b2015-01-19 14:49:31 -08001751 description = "Restore a link to ensure that Link Discovery is " + \
1752 "working properly"
1753 main.log.report( description )
1754 main.case( description )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001755
Jon Hall6aec96b2015-01-19 14:49:31 -08001756 main.step( "Bring link between s3 and s28 back up" )
1757 Link_Up = main.Mininet1.link( END1="s3", END2="s28", OPTION="up" )
1758 main.log.info(
1759 "Waiting " +
1760 str( link_sleep ) +
1761 " seconds for link up to be discovered" )
1762 time.sleep( link_sleep )
1763 utilities.assert_equals( expect=main.TRUE, actual=Link_Up,
1764 onpass="Link up succesful",
1765 onfail="Failed to bring link up" )
1766 # TODO do some sort of check here
Jon Hall73cf9cc2014-11-20 22:28:38 -08001767
Jon Hall6aec96b2015-01-19 14:49:31 -08001768 def CASE11( self, main ):
1769 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001770 Switch Down
Jon Hall6aec96b2015-01-19 14:49:31 -08001771 """
1772 # NOTE: You should probably run a topology check after this
Jon Hall73cf9cc2014-11-20 22:28:38 -08001773 import time
1774
Jon Hall6aec96b2015-01-19 14:49:31 -08001775 switch_sleep = float( main.params[ 'timers' ][ 'SwitchDiscovery' ] )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001776
1777 description = "Killing a switch to ensure it is discovered correctly"
Jon Hall6aec96b2015-01-19 14:49:31 -08001778 main.log.report( description )
1779 main.case( description )
1780 switch = main.params[ 'kill' ][ 'switch' ]
1781 switchDPID = main.params[ 'kill' ][ 'dpid' ]
Jon Hall73cf9cc2014-11-20 22:28:38 -08001782
Jon Hall6aec96b2015-01-19 14:49:31 -08001783 # TODO: Make this switch parameterizable
1784 main.step( "Kill " + switch )
1785 main.log.report( "Deleting " + switch )
1786 main.Mininet1.del_switch( switch )
1787 main.log.info( "Waiting " + str( switch_sleep ) +
1788 " seconds for switch down to be discovered" )
1789 time.sleep( switch_sleep )
1790 device = main.ONOScli1.get_device( dpid=switchDPID )
1791 # Peek at the deleted switch
1792 main.log.warn( str( device ) )
Jon Hall94fd0472014-12-08 11:52:42 -08001793 result = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001794 if device and device[ 'available' ] is False:
Jon Hall94fd0472014-12-08 11:52:42 -08001795 result = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001796 utilities.assert_equals( expect=main.TRUE, actual=result,
1797 onpass="Kill switch succesful",
1798 onfail="Failed to kill switch?" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001799
Jon Hall6aec96b2015-01-19 14:49:31 -08001800 def CASE12( self, main ):
1801 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001802 Switch Up
Jon Hall6aec96b2015-01-19 14:49:31 -08001803 """
1804 # NOTE: You should probably run a topology check after this
Jon Hall73cf9cc2014-11-20 22:28:38 -08001805 import time
Jon Hall669173b2014-12-17 11:36:30 -08001806
Jon Hall6aec96b2015-01-19 14:49:31 -08001807 switch_sleep = float( main.params[ 'timers' ][ 'SwitchDiscovery' ] )
1808 switch = main.params[ 'kill' ][ 'switch' ]
1809 switchDPID = main.params[ 'kill' ][ 'dpid' ]
1810 links = main.params[ 'kill' ][ 'links' ].split()
Jon Hall73cf9cc2014-11-20 22:28:38 -08001811 description = "Adding a switch to ensure it is discovered correctly"
Jon Hall6aec96b2015-01-19 14:49:31 -08001812 main.log.report( description )
1813 main.case( description )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001814
Jon Hall6aec96b2015-01-19 14:49:31 -08001815 main.step( "Add back " + switch )
1816 main.log.report( "Adding back " + switch )
1817 main.Mininet1.add_switch( switch, dpid=switchDPID )
1818 # TODO: New dpid or same? Ask Thomas?
1819 for peer in links:
1820 main.Mininet1.add_link( switch, peer )
1821 main.Mininet1.assign_sw_controller(
1822 sw=switch.split( 's' )[ 1 ],
1823 count=num_controllers,
1824 ip1=ONOS1_ip,
1825 port1=ONOS1_port,
1826 ip2=ONOS2_ip,
1827 port2=ONOS2_port,
1828 ip3=ONOS3_ip,
1829 port3=ONOS3_port,
1830 ip4=ONOS4_ip,
1831 port4=ONOS4_port,
1832 ip5=ONOS5_ip,
1833 port5=ONOS5_port,
1834 ip6=ONOS6_ip,
1835 port6=ONOS6_port,
1836 ip7=ONOS7_ip,
1837 port7=ONOS7_port )
1838 main.log.info(
1839 "Waiting " +
1840 str( switch_sleep ) +
1841 " seconds for switch up to be discovered" )
1842 time.sleep( switch_sleep )
1843 device = main.ONOScli1.get_device( dpid=switchDPID )
1844 # Peek at the deleted switch
1845 main.log.warn( str( device ) )
Jon Hall94fd0472014-12-08 11:52:42 -08001846 result = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001847 if device and device[ 'available' ]:
Jon Hall94fd0472014-12-08 11:52:42 -08001848 result = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001849 utilities.assert_equals( expect=main.TRUE, actual=result,
1850 onpass="add switch succesful",
1851 onfail="Failed to add switch?" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001852
Jon Hall6aec96b2015-01-19 14:49:31 -08001853 def CASE13( self, main ):
1854 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001855 Clean up
Jon Hall6aec96b2015-01-19 14:49:31 -08001856 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001857 import os
1858 import time
Jon Hall6aec96b2015-01-19 14:49:31 -08001859 # TODO: make use of this elsewhere
1860 ips = []
1861 ips.append(ONOS1_ip)
1862 ips.append(ONOS2_ip)
1863 ips.append(ONOS3_ip)
1864 ips.append(ONOS4_ip)
1865 ips.append(ONOS5_ip)
1866 ips.append(ONOS6_ip)
1867 ips.append(ONOS7_ip)
1868
1869 # printing colors to terminal
Jon Hall669173b2014-12-17 11:36:30 -08001870 colors = {}
Jon Hall6aec96b2015-01-19 14:49:31 -08001871 colors[ 'cyan' ] = '\033[96m'
1872 colors[ 'purple' ] = '\033[95m'
1873 colors[ 'blue' ] = '\033[94m'
1874 colors[ 'green' ] = '\033[92m'
1875 colors[ 'yellow' ] = '\033[93m'
1876 colors[ 'red' ] = '\033[91m'
1877 colors[ 'end' ] = '\033[0m'
Jon Hall73cf9cc2014-11-20 22:28:38 -08001878 description = "Test Cleanup"
Jon Hall6aec96b2015-01-19 14:49:31 -08001879 main.log.report( description )
1880 main.case( description )
1881 main.step( "Killing tcpdumps" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001882 main.Mininet2.stop_tcpdump()
1883
Jon Hall6aec96b2015-01-19 14:49:31 -08001884 main.step( "Checking ONOS Logs for errors" )
1885 for i in range(7):
1886 print colors[ 'purple' ] + "Checking logs for errors on " + \
1887 "ONOS" + str( i + 1 ) + ":" + colors[ 'end' ]
1888 print main.ONOSbench.check_logs( ips[i] )
Jon Hall94fd0472014-12-08 11:52:42 -08001889
Jon Hall6aec96b2015-01-19 14:49:31 -08001890 main.step( "Copying MN pcap and ONOS log files to test station" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001891 testname = main.TEST
Jon Hall6aec96b2015-01-19 14:49:31 -08001892 teststation_user = main.params[ 'TESTONUSER' ]
1893 teststation_IP = main.params[ 'TESTONIP' ]
1894 # NOTE: MN Pcap file is being saved to ~/packet_captures
Jon Hall73cf9cc2014-11-20 22:28:38 -08001895 # scp this file as MN and TestON aren't necessarily the same vm
Jon Hall6aec96b2015-01-19 14:49:31 -08001896 # FIXME: scp
1897 # mn files
1898 # TODO: Load these from params
1899 # NOTE: must end in /
Jon Hall73cf9cc2014-11-20 22:28:38 -08001900 log_folder = "/opt/onos/log/"
Jon Hall6aec96b2015-01-19 14:49:31 -08001901 log_files = [ "karaf.log", "karaf.log.1" ]
1902 # NOTE: must end in /
Jon Hall73cf9cc2014-11-20 22:28:38 -08001903 dst_dir = "~/packet_captures/"
1904 for f in log_files:
Jon Hall6aec96b2015-01-19 14:49:31 -08001905 for i in range(7):
1906 main.ONOSbench.handle.sendline( "scp sdn@" + ips[i] + ":" +
1907 log_folder + f + " " +
1908 teststation_user + "@" +
1909 teststation_IP + ":" +
1910 dst_dir + str( testname ) +
1911 "-ONOS" + str( i + 1 ) + "-" +
1912 f )
1913 # std*.log's
1914 # NOTE: must end in /
Jon Hall73cf9cc2014-11-20 22:28:38 -08001915 log_folder = "/opt/onos/var/"
Jon Hall6aec96b2015-01-19 14:49:31 -08001916 log_files = [ "stderr.log", "stdout.log" ]
1917 # NOTE: must end in /
Jon Hall73cf9cc2014-11-20 22:28:38 -08001918 dst_dir = "~/packet_captures/"
1919 for f in log_files:
Jon Hall6aec96b2015-01-19 14:49:31 -08001920 for i in range(7):
1921 main.ONOSbench.handle.sendline( "scp sdn@" + ips[i] + ":" +
1922 log_folder + f + " " +
1923 teststation_user + "@" +
1924 teststation_IP + ":" +
1925 dst_dir + str( testname ) +
1926 "-ONOS" + str( i + 1 ) + "-" +
1927 f )
1928 # sleep so scp can finish
1929 time.sleep( 10 )
1930 main.step( "Packing and rotating pcap archives" )
1931 os.system( "~/TestON/dependencies/rotate.sh " + str( testname ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001932
Jon Hall6aec96b2015-01-19 14:49:31 -08001933 # TODO: actually check something here
1934 utilities.assert_equals( expect=main.TRUE, actual=main.TRUE,
1935 onpass="Test cleanup successful",
1936 onfail="Test cleanup NOT successful" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001937
Jon Hall6aec96b2015-01-19 14:49:31 -08001938 def CASE14( self, main ):
1939 """
Jon Hall669173b2014-12-17 11:36:30 -08001940 start election app on all onos nodes
Jon Hall6aec96b2015-01-19 14:49:31 -08001941 """
Jon Hall669173b2014-12-17 11:36:30 -08001942 leader_result = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001943 # install app on onos 1
1944 main.log.info( "Install leadership election app" )
1945 main.ONOScli1.feature_install( "onos-app-election" )
1946 # wait for election
1947 # check for leader
Jon Hall669173b2014-12-17 11:36:30 -08001948 leader = main.ONOScli1.election_test_leader()
Jon Hall6aec96b2015-01-19 14:49:31 -08001949 # verify leader is ONOS1
Jon Hall669173b2014-12-17 11:36:30 -08001950 if leader == ONOS1_ip:
Jon Hall6aec96b2015-01-19 14:49:31 -08001951 # all is well
Jon Hall669173b2014-12-17 11:36:30 -08001952 pass
Jon Hall6aec96b2015-01-19 14:49:31 -08001953 elif leader is None:
1954 # No leader elected
1955 main.log.report( "No leader was elected" )
Jon Hall669173b2014-12-17 11:36:30 -08001956 leader_result = main.FALSE
1957 elif leader == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001958 # error in response
1959 # TODO: add check for "Command not found:" in the driver, this
1960 # means the app isn't loaded
1961 main.log.report( "Something is wrong with election_test_leader" +
1962 " function, check the error logs" )
Jon Hall669173b2014-12-17 11:36:30 -08001963 leader_result = main.FALSE
1964 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08001965 # error in response
1966 main.log.report(
1967 "Unexpected response from election_test_leader function:'" +
1968 str(leader) +
1969 "'" )
Jon Hall669173b2014-12-17 11:36:30 -08001970 leader_result = main.FALSE
1971
Jon Hall6aec96b2015-01-19 14:49:31 -08001972 # install on other nodes and check for leader.
1973 # Should be onos1 and each app should show the same leader
1974 for controller in range( 2, num_controllers + 1 ):
1975 # loop through ONOScli handlers
1976 node = getattr( main, ( 'ONOScli' + str( controller ) ) )
1977 node.feature_install( "onos-app-election" )
Jon Hall669173b2014-12-17 11:36:30 -08001978 leaderN = node.election_test_leader()
Jon Hall6aec96b2015-01-19 14:49:31 -08001979 # verify leader is ONOS1
Jon Hall669173b2014-12-17 11:36:30 -08001980 if leaderN == ONOS1_ip:
Jon Hall6aec96b2015-01-19 14:49:31 -08001981 # all is well
Jon Hall669173b2014-12-17 11:36:30 -08001982 pass
1983 elif leaderN == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001984 # error in response
1985 # TODO: add check for "Command not found:" in the driver, this
1986 # means the app isn't loaded
1987 main.log.report( "Something is wrong with " +
1988 "election_test_leader function, check the" +
1989 " error logs" )
Jon Hall669173b2014-12-17 11:36:30 -08001990 leader_result = main.FALSE
1991 elif leader != leaderN:
1992 leader_result = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001993 main.log.report( "ONOS" + str( controller ) + " sees " +
1994 str( leaderN ) +
1995 " as the leader of the election app. Leader" +
1996 " should be " +
1997 str( leader ) )
Jon Hall669173b2014-12-17 11:36:30 -08001998 if leader_result:
Jon Hall6aec96b2015-01-19 14:49:31 -08001999 main.log.report( "Leadership election tests passed( consistent " +
2000 "view of leader across listeners and a leader " +
2001 "was elected)" )
2002 utilities.assert_equals(
2003 expect=main.TRUE,
2004 actual=leader_result,
2005 onpass="Leadership election passed",
2006 onfail="Something went wrong with Leadership election" )
Jon Hall669173b2014-12-17 11:36:30 -08002007
Jon Hall6aec96b2015-01-19 14:49:31 -08002008 def CASE15( self, main ):
2009 """
Jon Hall669173b2014-12-17 11:36:30 -08002010 Check that Leadership Election is still functional
Jon Hall6aec96b2015-01-19 14:49:31 -08002011 """
Jon Hall669173b2014-12-17 11:36:30 -08002012 leader_result = main.TRUE
2013 description = "Check that Leadership Election is still functional"
Jon Hall6aec96b2015-01-19 14:49:31 -08002014 main.log.report( description )
2015 main.case( description )
2016 main.step( "Find current leader and withdraw" )
Jon Hall669173b2014-12-17 11:36:30 -08002017 leader = main.ONOScli1.election_test_leader()
Jon Hall6aec96b2015-01-19 14:49:31 -08002018 # TODO: do some sanity checking on leader before using it
Jon Hall669173b2014-12-17 11:36:30 -08002019 withdraw_result = main.FALSE
2020 if leader == ONOS1_ip:
2021 old_leader = getattr( main, "ONOScli1" )
2022 elif leader == ONOS2_ip:
2023 old_leader = getattr( main, "ONOScli2" )
2024 elif leader == ONOS3_ip:
2025 old_leader = getattr( main, "ONOScli3" )
2026 elif leader == ONOS4_ip:
2027 old_leader = getattr( main, "ONOScli4" )
2028 elif leader == ONOS5_ip:
2029 old_leader = getattr( main, "ONOScli5" )
2030 elif leader == ONOS6_ip:
2031 old_leader = getattr( main, "ONOScli6" )
2032 elif leader == ONOS7_ip:
2033 old_leader = getattr( main, "ONOScli7" )
Jon Hall6aec96b2015-01-19 14:49:31 -08002034 elif leader is None or leader == main.FALSE:
2035 main.log.report(
2036 "Leader for the election app should be an ONOS node," +
2037 "instead got '" +
2038 str(leader) +
2039 "'" )
Jon Hall669173b2014-12-17 11:36:30 -08002040 leader_result = main.FALSE
2041 withdraw_result = old_leader.election_test_withdraw()
Jon Hall6aec96b2015-01-19 14:49:31 -08002042 utilities.assert_equals(
2043 expect=main.TRUE,
2044 actual=withdraw_result,
2045 onpass="App was withdrawn from election",
2046 onfail="App was not withdrawn from election" )
Jon Hall669173b2014-12-17 11:36:30 -08002047
Jon Hall6aec96b2015-01-19 14:49:31 -08002048 main.step( "Make sure new leader is elected" )
Jon Hall669173b2014-12-17 11:36:30 -08002049 leader_list = []
Jon Hall6aec96b2015-01-19 14:49:31 -08002050 for controller in range( 1, num_controllers + 1 ):
2051 # loop through ONOScli handlers
2052 node = getattr( main, ( 'ONOScli' + str( controller ) ) )
Jon Hall669173b2014-12-17 11:36:30 -08002053 leader_list.append( node.election_test_leader() )
2054 for leaderN in leader_list:
2055 if leaderN == leader:
Jon Hall6aec96b2015-01-19 14:49:31 -08002056 main.log.report(
2057 "ONOS" +
2058 str( controller ) +
2059 " still sees " +
2060 str( leader ) +
2061 " as leader after they withdrew" )
Jon Hall669173b2014-12-17 11:36:30 -08002062 leader_result = main.FALSE
2063 elif leaderN == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -08002064 # error in response
2065 # TODO: add check for "Command not found:" in the driver, this
2066 # means the app isn't loaded
2067 main.log.report( "Something is wrong with " +
2068 "election_test_leader function, " +
2069 "check the error logs" )
Jon Hall669173b2014-12-17 11:36:30 -08002070 leader_result = main.FALSE
2071 consistent_leader = main.FALSE
2072 if len( set( leader_list ) ) == 1:
Jon Hall6aec96b2015-01-19 14:49:31 -08002073 main.log.info( "Each Election-app sees '" +
2074 str(leader_list[0]) +
2075 "' as the leader" )
Jon Hall669173b2014-12-17 11:36:30 -08002076 consistent_leader = main.TRUE
2077 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08002078 main.log.report(
2079 "Inconsistent responses for leader of Election-app:" )
2080 for n in range( len( leader_list ) ):
2081 main.log.report( "ONOS" + str( n + 1 ) + " response: " +
2082 str( leader_list[ n ] ) )
Jon Hall669173b2014-12-17 11:36:30 -08002083 if leader_result:
Jon Hall6aec96b2015-01-19 14:49:31 -08002084 main.log.report( "Leadership election tests passed(consistent " +
2085 "view of leader across listeners and a new " +
2086 "leader was elected when the old leader " +
2087 "resigned)" )
2088 utilities.assert_equals(
2089 expect=main.TRUE,
2090 actual=leader_result,
2091 onpass="Leadership election passed",
2092 onfail="Something went wrong with Leadership election" )
Jon Hall669173b2014-12-17 11:36:30 -08002093
Jon Hall6aec96b2015-01-19 14:49:31 -08002094 main.step(
2095 "Run for election on old leader(just so everyone is in the hat)" )
Jon Hall669173b2014-12-17 11:36:30 -08002096 run_result = old_leader.election_test_run()
Jon Hall6aec96b2015-01-19 14:49:31 -08002097 utilities.assert_equals(
2098 expect=main.TRUE,
2099 actual=run_result,
2100 onpass="App re-ran for election",
2101 onfail="App failed to run for election" )
Jon Hall669173b2014-12-17 11:36:30 -08002102 if consistent_leader == main.TRUE:
2103 after_run = main.ONOScli1.election_test_leader()
Jon Hall6aec96b2015-01-19 14:49:31 -08002104 # verify leader didn't just change
2105 if after_run == leader_list[ 0 ]:
Jon Hall669173b2014-12-17 11:36:30 -08002106 leader_result = main.TRUE
2107 else:
2108 leader_result = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08002109 # TODO: assert on run and withdraw results?
Jon Hall669173b2014-12-17 11:36:30 -08002110
Jon Hall6aec96b2015-01-19 14:49:31 -08002111 utilities.assert_equals(
2112 expect=main.TRUE,
2113 actual=leader_result,
2114 onpass="Leadership election passed",
2115 onfail="Something went wrong with Leadership election after " +
2116 "the old leader re-ran for election" )