blob: 0625ad0c34c2843ae8d22c291349f539c5d46b28 [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 a minority 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 HATestMinorityRestart:
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(
42 "ONOS HA test: Restart minority of ONOS nodes - 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
114 if git_pull_result == main.TRUE:
115 clean_install_result = main.ONOSbench.clean_install()
116 else:
Jon Hall6aec96b2015-01-19 14:49:31 -0800117 main.log.warn( "Did not pull new code so skipping mvn " +
118 "clean install" )
119 main.ONOSbench.get_version( report=True )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800120
Jon Hall6aec96b2015-01-19 14:49:31 -0800121 main.step( "Creating ONOS package" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800122 package_result = main.ONOSbench.onos_package()
123
Jon Hall6aec96b2015-01-19 14:49:31 -0800124 main.step( "Installing ONOS package" )
125 onos1_install_result = main.ONOSbench.onos_install( options="-f",
126 node=ONOS1_ip )
127 onos2_install_result = main.ONOSbench.onos_install( options="-f",
128 node=ONOS2_ip )
129 onos3_install_result = main.ONOSbench.onos_install( options="-f",
130 node=ONOS3_ip )
131 onos4_install_result = main.ONOSbench.onos_install( options="-f",
132 node=ONOS4_ip )
133 onos5_install_result = main.ONOSbench.onos_install( options="-f",
134 node=ONOS5_ip )
135 onos6_install_result = main.ONOSbench.onos_install( options="-f",
136 node=ONOS6_ip )
137 onos7_install_result = main.ONOSbench.onos_install( options="-f",
138 node=ONOS7_ip )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800139 onos_install_result = onos1_install_result and onos2_install_result\
Jon Hall6aec96b2015-01-19 14:49:31 -0800140 and onos3_install_result and onos4_install_result\
141 and onos5_install_result and onos6_install_result\
142 and onos7_install_result
Jon Hall73cf9cc2014-11-20 22:28:38 -0800143
Jon Hall6aec96b2015-01-19 14:49:31 -0800144 main.step( "Checking if ONOS is up yet" )
145 # TODO check bundle:list?
146 for i in range( 2 ):
147 onos1_isup = main.ONOSbench.isup( ONOS1_ip )
Jon Hall94fd0472014-12-08 11:52:42 -0800148 if not onos1_isup:
Jon Hall6aec96b2015-01-19 14:49:31 -0800149 main.log.report( "ONOS1 didn't start!" )
150 onos2_isup = main.ONOSbench.isup( ONOS2_ip )
Jon Hall94fd0472014-12-08 11:52:42 -0800151 if not onos2_isup:
Jon Hall6aec96b2015-01-19 14:49:31 -0800152 main.log.report( "ONOS2 didn't start!" )
153 onos3_isup = main.ONOSbench.isup( ONOS3_ip )
Jon Hall94fd0472014-12-08 11:52:42 -0800154 if not onos3_isup:
Jon Hall6aec96b2015-01-19 14:49:31 -0800155 main.log.report( "ONOS3 didn't start!" )
156 onos4_isup = main.ONOSbench.isup( ONOS4_ip )
Jon Hall94fd0472014-12-08 11:52:42 -0800157 if not onos4_isup:
Jon Hall6aec96b2015-01-19 14:49:31 -0800158 main.log.report( "ONOS4 didn't start!" )
159 onos5_isup = main.ONOSbench.isup( ONOS5_ip )
Jon Hall94fd0472014-12-08 11:52:42 -0800160 if not onos5_isup:
Jon Hall6aec96b2015-01-19 14:49:31 -0800161 main.log.report( "ONOS5 didn't start!" )
162 onos6_isup = main.ONOSbench.isup( ONOS6_ip )
Jon Hall94fd0472014-12-08 11:52:42 -0800163 if not onos6_isup:
Jon Hall6aec96b2015-01-19 14:49:31 -0800164 main.log.report( "ONOS6 didn't start!" )
165 onos7_isup = main.ONOSbench.isup( ONOS7_ip )
Jon Hall94fd0472014-12-08 11:52:42 -0800166 if not onos7_isup:
Jon Hall6aec96b2015-01-19 14:49:31 -0800167 main.log.report( "ONOS7 didn't start!" )
Jon Hall94fd0472014-12-08 11:52:42 -0800168 onos_isup_result = onos1_isup and onos2_isup and onos3_isup\
Jon Hall6aec96b2015-01-19 14:49:31 -0800169 and onos4_isup and onos5_isup and onos6_isup and onos7_isup
Jon Hall94fd0472014-12-08 11:52:42 -0800170 if onos_isup_result == main.TRUE:
171 break
Jon Hall73cf9cc2014-11-20 22:28:38 -0800172
Jon Hall6aec96b2015-01-19 14:49:31 -0800173 cli_result1 = main.ONOScli1.start_onos_cli( ONOS1_ip )
174 cli_result2 = main.ONOScli2.start_onos_cli( ONOS2_ip )
175 cli_result3 = main.ONOScli3.start_onos_cli( ONOS3_ip )
176 cli_result4 = main.ONOScli4.start_onos_cli( ONOS4_ip )
177 cli_result5 = main.ONOScli5.start_onos_cli( ONOS5_ip )
178 cli_result6 = main.ONOScli6.start_onos_cli( ONOS6_ip )
179 cli_result7 = main.ONOScli7.start_onos_cli( ONOS7_ip )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800180 cli_results = cli_result1 and cli_result2 and cli_result3 and\
Jon Hall6aec96b2015-01-19 14:49:31 -0800181 cli_result4 and cli_result5 and cli_result6 and cli_result7
Jon Hall73cf9cc2014-11-20 22:28:38 -0800182
Jon Hall6aec96b2015-01-19 14:49:31 -0800183 main.step( "Start Packet Capture MN" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800184 main.Mininet2.start_tcpdump(
Jon Hall6aec96b2015-01-19 14:49:31 -0800185 str( main.params[ 'MNtcpdump' ][ 'folder' ] ) + str( main.TEST )
186 + "-MN.pcap",
187 intf=main.params[ 'MNtcpdump' ][ 'intf' ],
188 port=main.params[ 'MNtcpdump' ][ 'port' ] )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800189
Jon Hall6aec96b2015-01-19 14:49:31 -0800190 case1_result = ( clean_install_result and package_result and
191 cell_result and verify_result and onos_install_result
192 and onos_isup_result and cli_results )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800193
Jon Hall6aec96b2015-01-19 14:49:31 -0800194 utilities.assert_equals( expect=main.TRUE, actual=case1_result,
195 onpass="Test startup successful",
196 onfail="Test startup NOT successful" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800197
Jon Hall6aec96b2015-01-19 14:49:31 -0800198 if case1_result == main.FALSE:
Jon Hall94fd0472014-12-08 11:52:42 -0800199 main.cleanup()
200 main.exit()
Jon Hall73cf9cc2014-11-20 22:28:38 -0800201
Jon Hall6aec96b2015-01-19 14:49:31 -0800202 def CASE2( self, main ):
203 """
Jon Hall73cf9cc2014-11-20 22:28:38 -0800204 Assign mastership to controllers
Jon Hall6aec96b2015-01-19 14:49:31 -0800205 """
Jon Hall73cf9cc2014-11-20 22:28:38 -0800206 import re
207
Jon Hall6aec96b2015-01-19 14:49:31 -0800208 main.log.report( "Assigning switches to controllers" )
209 main.case( "Assigning Controllers" )
210 main.step( "Assign switches to controllers" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800211
Jon Hall6aec96b2015-01-19 14:49:31 -0800212 for i in range( 1, 29 ):
213 main.Mininet1.assign_sw_controller(
214 sw=str( i ),
215 count=num_controllers,
216 ip1=ONOS1_ip, port1=ONOS1_port,
217 ip2=ONOS2_ip, port2=ONOS2_port,
218 ip3=ONOS3_ip, port3=ONOS3_port,
219 ip4=ONOS4_ip, port4=ONOS4_port,
220 ip5=ONOS5_ip, port5=ONOS5_port,
221 ip6=ONOS6_ip, port6=ONOS6_port,
222 ip7=ONOS7_ip, port7=ONOS7_port )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800223
224 mastership_check = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800225 for i in range( 1, 29 ):
226 response = main.Mininet1.get_sw_controller( "s" + str( i ) )
Jon Hallffb386d2014-11-21 13:43:38 -0800227 try:
Jon Hall6aec96b2015-01-19 14:49:31 -0800228 main.log.info( str( response ) )
Jon Hallffb386d2014-11-21 13:43:38 -0800229 except:
Jon Hall6aec96b2015-01-19 14:49:31 -0800230 main.log.info( repr( response ) )
231 if re.search( "tcp:" + ONOS1_ip, response )\
232 and re.search( "tcp:" + ONOS2_ip, response )\
233 and re.search( "tcp:" + ONOS3_ip, response )\
234 and re.search( "tcp:" + ONOS4_ip, response )\
235 and re.search( "tcp:" + ONOS5_ip, response )\
236 and re.search( "tcp:" + ONOS6_ip, response )\
237 and re.search( "tcp:" + ONOS7_ip, response ):
Jon Hall73cf9cc2014-11-20 22:28:38 -0800238 mastership_check = mastership_check and main.TRUE
239 else:
240 mastership_check = main.FALSE
241 if mastership_check == main.TRUE:
Jon Hall6aec96b2015-01-19 14:49:31 -0800242 main.log.report( "Switch mastership assigned correctly" )
243 utilities.assert_equals(
244 expect=main.TRUE,
245 actual=mastership_check,
246 onpass="Switch mastership assigned correctly",
247 onfail="Switches not assigned correctly to controllers" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800248
Jon Hall6aec96b2015-01-19 14:49:31 -0800249 # Manually assign mastership to the controller we want
Jon Hall94fd0472014-12-08 11:52:42 -0800250 role_call = main.TRUE
251 role_check = main.TRUE
252
Jon Hall6aec96b2015-01-19 14:49:31 -0800253 # Assign switch
254 device_id = main.ONOScli1.get_device( "1000" ).get( 'id' )
255 role_call = role_call and main.ONOScli1.device_role(
256 device_id,
257 ONOS1_ip )
258 # Check assignment
259 if ONOS1_ip in main.ONOScli1.get_role( device_id ).get( 'master' ):
Jon Hall94fd0472014-12-08 11:52:42 -0800260 role_check = role_check and main.TRUE
261 else:
262 role_check = role_check and main.FALSE
263
Jon Hall6aec96b2015-01-19 14:49:31 -0800264 # Assign switch
265 device_id = main.ONOScli1.get_device( "2800" ).get( 'id' )
266 role_call = role_call and main.ONOScli1.device_role(
267 device_id,
268 ONOS1_ip )
269 # Check assignment
270 if ONOS1_ip in main.ONOScli1.get_role( device_id ).get( 'master' ):
Jon Hall94fd0472014-12-08 11:52:42 -0800271 role_check = role_check and main.TRUE
272 else:
273 role_check = role_check and main.FALSE
274
Jon Hall6aec96b2015-01-19 14:49:31 -0800275 # Assign switch
276 device_id = main.ONOScli1.get_device( "2000" ).get( 'id' )
277 role_call = role_call and main.ONOScli1.device_role(
278 device_id,
279 ONOS2_ip )
280 # Check assignment
281 if ONOS2_ip in main.ONOScli1.get_role( device_id ).get( 'master' ):
Jon Hall94fd0472014-12-08 11:52:42 -0800282 role_check = role_check and main.TRUE
283 else:
284 role_check = role_check and main.FALSE
285
Jon Hall6aec96b2015-01-19 14:49:31 -0800286 # Assign switch
287 device_id = main.ONOScli1.get_device( "3000" ).get( 'id' )
288 role_call = role_call and main.ONOScli1.device_role(
289 device_id,
290 ONOS2_ip )
291 # Check assignment
292 if ONOS2_ip in main.ONOScli1.get_role( device_id ).get( 'master' ):
Jon Hall94fd0472014-12-08 11:52:42 -0800293 role_check = role_check and main.TRUE
294 else:
295 role_check = role_check and main.FALSE
296
Jon Hall6aec96b2015-01-19 14:49:31 -0800297 # Assign switch
298 device_id = main.ONOScli1.get_device( "5000" ).get( 'id' )
299 role_call = role_call and main.ONOScli1.device_role(
300 device_id,
301 ONOS3_ip )
302 # Check assignment
303 if ONOS3_ip in main.ONOScli1.get_role( device_id ).get( 'master' ):
Jon Hall94fd0472014-12-08 11:52:42 -0800304 role_check = role_check and main.TRUE
305 else:
306 role_check = role_check and main.FALSE
307
Jon Hall6aec96b2015-01-19 14:49:31 -0800308 # Assign switch
309 device_id = main.ONOScli1.get_device( "6000" ).get( 'id' )
310 role_call = role_call and main.ONOScli1.device_role(
311 device_id,
312 ONOS3_ip )
313 # Check assignment
314 if ONOS3_ip in main.ONOScli1.get_role( device_id ).get( 'master' ):
Jon Hall94fd0472014-12-08 11:52:42 -0800315 role_check = role_check and main.TRUE
316 else:
317 role_check = role_check and main.FALSE
318
Jon Hall6aec96b2015-01-19 14:49:31 -0800319 # Assign switch
320 device_id = main.ONOScli1.get_device( "3004" ).get( 'id' )
321 role_call = role_call and main.ONOScli1.device_role(
322 device_id,
323 ONOS4_ip )
324 # Check assignment
325 if ONOS4_ip in main.ONOScli1.get_role( device_id ).get( 'master' ):
Jon Hall94fd0472014-12-08 11:52:42 -0800326 role_check = role_check and main.TRUE
327 else:
328 role_check = role_check and main.FALSE
329
Jon Hall6aec96b2015-01-19 14:49:31 -0800330 for i in range( 8, 18 ):
331 dpid = '3' + str( i ).zfill( 3 )
332 device_id = main.ONOScli1.get_device( dpid ).get( 'id' )
333 role_call = role_call and main.ONOScli1.device_role(
334 device_id,
335 ONOS5_ip )
336 # Check assignment
337 if ONOS5_ip in main.ONOScli1.get_role( device_id ).get( 'master' ):
338 role_check = role_check and main.TRUE
339 else:
340 role_check = role_check and main.FALSE
341
342 device_id = main.ONOScli1.get_device( "6007" ).get( 'id' )
343 role_call = role_call and main.ONOScli1.device_role(
344 device_id,
345 ONOS6_ip )
346 # Check assignment
347 if ONOS6_ip in main.ONOScli1.get_role( device_id ).get( 'master' ):
Jon Hall94fd0472014-12-08 11:52:42 -0800348 role_check = role_check and main.TRUE
349 else:
350 role_check = role_check and main.FALSE
351
Jon Hall6aec96b2015-01-19 14:49:31 -0800352 for i in range( 18, 28 ):
353 dpid = '6' + str( i ).zfill( 3 )
354 device_id = main.ONOScli1.get_device( dpid ).get( 'id' )
355 role_call = role_call and main.ONOScli1.device_role(
356 device_id,
357 ONOS7_ip )
358 # Check assignment
359 if ONOS7_ip in main.ONOScli1.get_role( device_id ).get( 'master' ):
360 role_check = role_check and main.TRUE
361 else:
362 role_check = role_check and main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -0800363
Jon Hall6aec96b2015-01-19 14:49:31 -0800364 utilities.assert_equals(
365 expect=main.TRUE,
366 actual=role_call,
367 onpass="Re-assigned switch mastership to designated controller",
368 onfail="Something wrong with device_role calls" )
Jon Hall94fd0472014-12-08 11:52:42 -0800369
Jon Hall6aec96b2015-01-19 14:49:31 -0800370 utilities.assert_equals(
371 expect=main.TRUE,
372 actual=role_check,
373 onpass="Switches were successfully reassigned to designated " +
374 "controller",
375 onfail="Switches were not successfully reassigned" )
Jon Hall94fd0472014-12-08 11:52:42 -0800376 mastership_check = mastership_check and role_call and role_check
Jon Hall6aec96b2015-01-19 14:49:31 -0800377 utilities.assert_equals( expect=main.TRUE, actual=mastership_check,
378 onpass="Switch mastership correctly assigned",
379 onfail="Error in (re)assigning switch" +
380 " mastership" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800381
Jon Hall6aec96b2015-01-19 14:49:31 -0800382 def CASE3( self, main ):
Jon Hall73cf9cc2014-11-20 22:28:38 -0800383 """
384 Assign intents
385
386 """
387 import time
Jon Hall6aec96b2015-01-19 14:49:31 -0800388 main.log.report( "Adding host intents" )
389 main.case( "Adding host Intents" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800390
Jon Hall6aec96b2015-01-19 14:49:31 -0800391 main.step( "Discovering Hosts( Via pingall for now)" )
392 # FIXME: Once we have a host discovery mechanism, use that instead
Jon Hall73cf9cc2014-11-20 22:28:38 -0800393
Jon Hall6aec96b2015-01-19 14:49:31 -0800394 # install onos-app-fwd
395 main.log.info( "Install reactive forwarding app" )
396 main.ONOScli1.feature_install( "onos-app-fwd" )
397 main.ONOScli2.feature_install( "onos-app-fwd" )
398 main.ONOScli3.feature_install( "onos-app-fwd" )
399 main.ONOScli4.feature_install( "onos-app-fwd" )
400 main.ONOScli5.feature_install( "onos-app-fwd" )
401 main.ONOScli6.feature_install( "onos-app-fwd" )
402 main.ONOScli7.feature_install( "onos-app-fwd" )
Jon Hall94fd0472014-12-08 11:52:42 -0800403
Jon Hall6aec96b2015-01-19 14:49:31 -0800404 # REACTIVE FWD test
Jon Hall73cf9cc2014-11-20 22:28:38 -0800405 ping_result = main.FALSE
406 time1 = time.time()
407 ping_result = main.Mininet1.pingall()
408 time2 = time.time()
Jon Hall6aec96b2015-01-19 14:49:31 -0800409 main.log.info( "Time for pingall: %2f seconds" % ( time2 - time1 ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800410
Jon Hall6aec96b2015-01-19 14:49:31 -0800411 # uninstall onos-app-fwd
412 main.log.info( "Uninstall reactive forwarding app" )
413 main.ONOScli1.feature_uninstall( "onos-app-fwd" )
414 main.ONOScli2.feature_uninstall( "onos-app-fwd" )
415 main.ONOScli3.feature_uninstall( "onos-app-fwd" )
416 main.ONOScli4.feature_uninstall( "onos-app-fwd" )
417 main.ONOScli5.feature_uninstall( "onos-app-fwd" )
418 main.ONOScli6.feature_uninstall( "onos-app-fwd" )
419 main.ONOScli7.feature_uninstall( "onos-app-fwd" )
420 # timeout for fwd flows
421 time.sleep( 10 )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800422
Jon Hall6aec96b2015-01-19 14:49:31 -0800423 main.step( "Add host intents" )
424 # TODO: move the host numbers to params
Jon Hall94fd0472014-12-08 11:52:42 -0800425 intent_add_result = True
Jon Hall6aec96b2015-01-19 14:49:31 -0800426 for i in range( 8, 18 ):
427 main.log.info( "Adding host intent between h" + str( i ) +
428 " and h" + str( i + 10 ) )
429 host1 = "00:00:00:00:00:" + \
430 str( hex( i )[ 2: ] ).zfill( 2 ).upper()
431 host2 = "00:00:00:00:00:" + \
432 str( hex( i + 10 )[ 2: ] ).zfill( 2 ).upper()
433 host1_id = main.ONOScli1.get_host( host1 )[ 'id' ]
434 host2_id = main.ONOScli1.get_host( host2 )[ 'id' ]
435 # NOTE: get host can return None
Jon Hall669173b2014-12-17 11:36:30 -0800436 if host1_id and host2_id:
Jon Hall6aec96b2015-01-19 14:49:31 -0800437 tmp_result = main.ONOScli1.add_host_intent(
438 host1_id,
439 host2_id )
Jon Hall669173b2014-12-17 11:36:30 -0800440 else:
Jon Hall6aec96b2015-01-19 14:49:31 -0800441 main.log.error( "Error, get_host() failed" )
Jon Hall669173b2014-12-17 11:36:30 -0800442 tmp_result = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -0800443 intent_add_result = bool( ping_result and intent_add_result
444 and tmp_result )
445 utilities.assert_equals(
446 expect=True,
447 actual=intent_add_result,
448 onpass="Switch mastership correctly assigned",
449 onfail="Error in (re)assigning switch mastership" )
450 # TODO Check if intents all exist in datastore
Jon Hall73cf9cc2014-11-20 22:28:38 -0800451
Jon Hall6aec96b2015-01-19 14:49:31 -0800452 def CASE4( self, main ):
Jon Hall73cf9cc2014-11-20 22:28:38 -0800453 """
454 Ping across added host intents
455 """
456 description = " Ping across added host intents"
Jon Hall6aec96b2015-01-19 14:49:31 -0800457 main.log.report( description )
458 main.case( description )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800459 Ping_Result = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800460 for i in range( 8, 18 ):
461 ping = main.Mininet1.pingHost(
462 src="h" + str( i ), target="h" + str( i + 10 ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800463 Ping_Result = Ping_Result and ping
Jon Hall6aec96b2015-01-19 14:49:31 -0800464 if ping == main.FALSE:
465 main.log.warn( "Ping failed between h" + str( i ) +
466 " and h" + str( i + 10 ) )
467 elif ping == main.TRUE:
468 main.log.info( "Ping test passed!" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800469 Ping_Result = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800470 if Ping_Result == main.FALSE:
471 main.log.report(
472 "Intents have not been installed correctly, pings failed." )
473 if Ping_Result == main.TRUE:
474 main.log.report(
475 "Intents have been installed correctly and verified by pings" )
476 utilities.assert_equals(
477 expect=main.TRUE,
478 actual=Ping_Result,
479 onpass="Intents have been installed correctly and pings work",
480 onfail="Intents have not been installed correctly, pings failed." )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800481
Jon Hall6aec96b2015-01-19 14:49:31 -0800482 def CASE5( self, main ):
483 """
Jon Hall73cf9cc2014-11-20 22:28:38 -0800484 Reading state of ONOS
Jon Hall6aec96b2015-01-19 14:49:31 -0800485 """
Jon Hall73cf9cc2014-11-20 22:28:38 -0800486 import json
Jon Hall6aec96b2015-01-19 14:49:31 -0800487 # assumes that sts is already in you PYTHONPATH
488 from sts.topology.teston_topology import TestONTopology
Jon Hall73cf9cc2014-11-20 22:28:38 -0800489
Jon Hall6aec96b2015-01-19 14:49:31 -0800490 main.log.report( "Setting up and gathering data for current state" )
491 main.case( "Setting up and gathering data for current state" )
492 # The general idea for this test case is to pull the state of
493 # ( intents,flows, topology,... ) from each ONOS node
494 # We can then compare them with eachother and also with past states
Jon Hall73cf9cc2014-11-20 22:28:38 -0800495
Jon Hall6aec96b2015-01-19 14:49:31 -0800496 main.step( "Get the Mastership of each switch from each controller" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800497 global mastership_state
Jon Hall94fd0472014-12-08 11:52:42 -0800498 mastership_state = []
499
Jon Hall6aec96b2015-01-19 14:49:31 -0800500 # Assert that each device has a master
Jon Hall94fd0472014-12-08 11:52:42 -0800501 ONOS1_master_not_null = main.ONOScli1.roles_not_null()
502 ONOS2_master_not_null = main.ONOScli2.roles_not_null()
503 ONOS3_master_not_null = main.ONOScli3.roles_not_null()
504 ONOS4_master_not_null = main.ONOScli4.roles_not_null()
505 ONOS5_master_not_null = main.ONOScli5.roles_not_null()
506 ONOS6_master_not_null = main.ONOScli6.roles_not_null()
507 ONOS7_master_not_null = main.ONOScli7.roles_not_null()
508 roles_not_null = ONOS1_master_not_null and ONOS2_master_not_null and\
Jon Hall6aec96b2015-01-19 14:49:31 -0800509 ONOS3_master_not_null and ONOS4_master_not_null and\
510 ONOS5_master_not_null and ONOS6_master_not_null and\
511 ONOS7_master_not_null
512 utilities.assert_equals(
513 expect=main.TRUE,
514 actual=roles_not_null,
515 onpass="Each device has a master",
516 onfail="Some devices don't have a master assigned" )
Jon Hall94fd0472014-12-08 11:52:42 -0800517
Jon Hall73cf9cc2014-11-20 22:28:38 -0800518 ONOS1_mastership = main.ONOScli1.roles()
519 ONOS2_mastership = main.ONOScli2.roles()
520 ONOS3_mastership = main.ONOScli3.roles()
521 ONOS4_mastership = main.ONOScli4.roles()
522 ONOS5_mastership = main.ONOScli5.roles()
523 ONOS6_mastership = main.ONOScli6.roles()
524 ONOS7_mastership = main.ONOScli7.roles()
Jon Hall73cf9cc2014-11-20 22:28:38 -0800525 if "Error" in ONOS1_mastership or not ONOS1_mastership\
526 or "Error" in ONOS2_mastership or not ONOS2_mastership\
527 or "Error" in ONOS3_mastership or not ONOS3_mastership\
528 or "Error" in ONOS4_mastership or not ONOS4_mastership\
529 or "Error" in ONOS5_mastership or not ONOS5_mastership\
530 or "Error" in ONOS6_mastership or not ONOS6_mastership\
531 or "Error" in ONOS7_mastership or not ONOS7_mastership:
Jon Hall6aec96b2015-01-19 14:49:31 -0800532 main.log.report( "Error in getting ONOS roles" )
533 main.log.warn(
534 "ONOS1 mastership response: " +
535 repr( ONOS1_mastership ) )
536 main.log.warn(
537 "ONOS2 mastership response: " +
538 repr( ONOS2_mastership ) )
539 main.log.warn(
540 "ONOS3 mastership response: " +
541 repr( ONOS3_mastership ) )
542 main.log.warn(
543 "ONOS4 mastership response: " +
544 repr( ONOS4_mastership ) )
545 main.log.warn(
546 "ONOS5 mastership response: " +
547 repr( ONOS5_mastership ) )
548 main.log.warn(
549 "ONOS6 mastership response: " +
550 repr( ONOS6_mastership ) )
551 main.log.warn(
552 "ONOS7 mastership response: " +
553 repr( ONOS7_mastership ) )
554 consistent_mastership = main.FALSE
Jon Hall73cf9cc2014-11-20 22:28:38 -0800555 elif ONOS1_mastership == ONOS2_mastership\
556 and ONOS1_mastership == ONOS3_mastership\
557 and ONOS1_mastership == ONOS4_mastership\
558 and ONOS1_mastership == ONOS5_mastership\
559 and ONOS1_mastership == ONOS6_mastership\
560 and ONOS1_mastership == ONOS7_mastership:
Jon Hall6aec96b2015-01-19 14:49:31 -0800561 mastership_state = ONOS1_mastership
562 consistent_mastership = main.TRUE
563 main.log.report(
564 "Switch roles are consistent across all ONOS nodes" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800565 else:
Jon Hall6aec96b2015-01-19 14:49:31 -0800566 main.log.warn(
567 "ONOS1 roles: ",
568 json.dumps(
569 json.loads( ONOS1_mastership ),
570 sort_keys=True,
571 indent=4,
572 separators=(
573 ',',
574 ': ' ) ) )
575 main.log.warn(
576 "ONOS2 roles: ",
577 json.dumps(
578 json.loads( ONOS2_mastership ),
579 sort_keys=True,
580 indent=4,
581 separators=(
582 ',',
583 ': ' ) ) )
584 main.log.warn(
585 "ONOS3 roles: ",
586 json.dumps(
587 json.loads( ONOS3_mastership ),
588 sort_keys=True,
589 indent=4,
590 separators=(
591 ',',
592 ': ' ) ) )
593 main.log.warn(
594 "ONOS4 roles: ",
595 json.dumps(
596 json.loads( ONOS4_mastership ),
597 sort_keys=True,
598 indent=4,
599 separators=(
600 ',',
601 ': ' ) ) )
602 main.log.warn(
603 "ONOS5 roles: ",
604 json.dumps(
605 json.loads( ONOS5_mastership ),
606 sort_keys=True,
607 indent=4,
608 separators=(
609 ',',
610 ': ' ) ) )
611 main.log.warn(
612 "ONOS6 roles: ",
613 json.dumps(
614 json.loads( ONOS6_mastership ),
615 sort_keys=True,
616 indent=4,
617 separators=(
618 ',',
619 ': ' ) ) )
620 main.log.warn(
621 "ONOS7 roles: ",
622 json.dumps(
623 json.loads( ONOS7_mastership ),
624 sort_keys=True,
625 indent=4,
626 separators=(
627 ',',
628 ': ' ) ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800629 consistent_mastership = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -0800630 utilities.assert_equals(
631 expect=main.TRUE,
632 actual=consistent_mastership,
633 onpass="Switch roles are consistent across all ONOS nodes",
634 onfail="ONOS nodes have different views of switch roles" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800635
Jon Hall6aec96b2015-01-19 14:49:31 -0800636 main.step( "Get the intents from each controller" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800637 global intent_state
Jon Hall94fd0472014-12-08 11:52:42 -0800638 intent_state = []
Jon Hall73cf9cc2014-11-20 22:28:38 -0800639 ONOS1_intents = main.ONOScli1.intents( json_format=True )
640 ONOS2_intents = main.ONOScli2.intents( json_format=True )
641 ONOS3_intents = main.ONOScli3.intents( json_format=True )
642 ONOS4_intents = main.ONOScli4.intents( json_format=True )
643 ONOS5_intents = main.ONOScli5.intents( json_format=True )
644 ONOS6_intents = main.ONOScli6.intents( json_format=True )
645 ONOS7_intents = main.ONOScli7.intents( json_format=True )
646 intent_check = main.FALSE
647 if "Error" in ONOS1_intents or not ONOS1_intents\
648 or "Error" in ONOS2_intents or not ONOS2_intents\
649 or "Error" in ONOS3_intents or not ONOS3_intents\
650 or "Error" in ONOS4_intents or not ONOS4_intents\
651 or "Error" in ONOS5_intents or not ONOS5_intents\
652 or "Error" in ONOS6_intents or not ONOS6_intents\
653 or "Error" in ONOS7_intents or not ONOS7_intents:
Jon Hall6aec96b2015-01-19 14:49:31 -0800654 main.log.report( "Error in getting ONOS intents" )
655 main.log.warn( "ONOS1 intents response: " + repr( ONOS1_intents ) )
656 main.log.warn( "ONOS2 intents response: " + repr( ONOS2_intents ) )
657 main.log.warn( "ONOS3 intents response: " + repr( ONOS3_intents ) )
658 main.log.warn( "ONOS4 intents response: " + repr( ONOS4_intents ) )
659 main.log.warn( "ONOS5 intents response: " + repr( ONOS5_intents ) )
660 main.log.warn( "ONOS6 intents response: " + repr( ONOS6_intents ) )
661 main.log.warn( "ONOS7 intents response: " + repr( ONOS7_intents ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800662 elif ONOS1_intents == ONOS2_intents\
663 and ONOS1_intents == ONOS3_intents\
664 and ONOS1_intents == ONOS4_intents\
665 and ONOS1_intents == ONOS5_intents\
666 and ONOS1_intents == ONOS6_intents\
667 and ONOS1_intents == ONOS7_intents:
Jon Hall6aec96b2015-01-19 14:49:31 -0800668 intent_state = ONOS1_intents
669 intent_check = main.TRUE
670 main.log.report( "Intents are consistent across all ONOS nodes" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800671 else:
Jon Hall6aec96b2015-01-19 14:49:31 -0800672 main.log.warn(
673 "ONOS1 intents: ",
674 json.dumps(
675 json.loads( ONOS1_intents ),
676 sort_keys=True,
677 indent=4,
678 separators=(
679 ',',
680 ': ' ) ) )
681 main.log.warn(
682 "ONOS2 intents: ",
683 json.dumps(
684 json.loads( ONOS2_intents ),
685 sort_keys=True,
686 indent=4,
687 separators=(
688 ',',
689 ': ' ) ) )
690 main.log.warn(
691 "ONOS3 intents: ",
692 json.dumps(
693 json.loads( ONOS3_intents ),
694 sort_keys=True,
695 indent=4,
696 separators=(
697 ',',
698 ': ' ) ) )
699 main.log.warn(
700 "ONOS4 intents: ",
701 json.dumps(
702 json.loads( ONOS4_intents ),
703 sort_keys=True,
704 indent=4,
705 separators=(
706 ',',
707 ': ' ) ) )
708 main.log.warn(
709 "ONOS5 intents: ",
710 json.dumps(
711 json.loads( ONOS5_intents ),
712 sort_keys=True,
713 indent=4,
714 separators=(
715 ',',
716 ': ' ) ) )
717 main.log.warn(
718 "ONOS6 intents: ",
719 json.dumps(
720 json.loads( ONOS6_intents ),
721 sort_keys=True,
722 indent=4,
723 separators=(
724 ',',
725 ': ' ) ) )
726 main.log.warn(
727 "ONOS7 intents: ",
728 json.dumps(
729 json.loads( ONOS7_intents ),
730 sort_keys=True,
731 indent=4,
732 separators=(
733 ',',
734 ': ' ) ) )
735 utilities.assert_equals(
736 expect=main.TRUE,
737 actual=intent_check,
738 onpass="Intents are consistent across all ONOS nodes",
739 onfail="ONOS nodes have different views of intents" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800740
Jon Hall6aec96b2015-01-19 14:49:31 -0800741 main.step( "Get the flows from each controller" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800742 global flow_state
Jon Hall94fd0472014-12-08 11:52:42 -0800743 flow_state = []
Jon Hall73cf9cc2014-11-20 22:28:38 -0800744 ONOS1_flows = main.ONOScli1.flows( json_format=True )
745 ONOS2_flows = main.ONOScli2.flows( json_format=True )
746 ONOS3_flows = main.ONOScli3.flows( json_format=True )
747 ONOS4_flows = main.ONOScli4.flows( json_format=True )
748 ONOS5_flows = main.ONOScli5.flows( json_format=True )
749 ONOS6_flows = main.ONOScli6.flows( json_format=True )
750 ONOS7_flows = main.ONOScli7.flows( json_format=True )
Jon Hall6aec96b2015-01-19 14:49:31 -0800751 ONOS1_flows_json = json.loads( ONOS1_flows )
752 ONOS2_flows_json = json.loads( ONOS2_flows )
753 ONOS3_flows_json = json.loads( ONOS3_flows )
754 ONOS4_flows_json = json.loads( ONOS4_flows )
755 ONOS5_flows_json = json.loads( ONOS5_flows )
756 ONOS6_flows_json = json.loads( ONOS6_flows )
757 ONOS7_flows_json = json.loads( ONOS7_flows )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800758 flow_check = main.FALSE
759 if "Error" in ONOS1_flows or not ONOS1_flows\
760 or "Error" in ONOS2_flows or not ONOS2_flows\
761 or "Error" in ONOS3_flows or not ONOS3_flows\
762 or "Error" in ONOS4_flows or not ONOS4_flows\
763 or "Error" in ONOS5_flows or not ONOS5_flows\
764 or "Error" in ONOS6_flows or not ONOS6_flows\
765 or "Error" in ONOS7_flows or not ONOS7_flows:
Jon Hall6aec96b2015-01-19 14:49:31 -0800766 main.log.report( "Error in getting ONOS intents" )
767 main.log.warn( "ONOS1 flows repsponse: " + ONOS1_flows )
768 main.log.warn( "ONOS2 flows repsponse: " + ONOS2_flows )
769 main.log.warn( "ONOS3 flows repsponse: " + ONOS3_flows )
770 main.log.warn( "ONOS4 flows repsponse: " + ONOS4_flows )
771 main.log.warn( "ONOS5 flows repsponse: " + ONOS5_flows )
772 main.log.warn( "ONOS6 flows repsponse: " + ONOS6_flows )
773 main.log.warn( "ONOS7 flows repsponse: " + ONOS7_flows )
774 elif len( ONOS1_flows_json ) == len( ONOS2_flows_json )\
775 and len( ONOS1_flows_json ) == len( ONOS3_flows_json )\
776 and len( ONOS1_flows_json ) == len( ONOS4_flows_json )\
777 and len( ONOS1_flows_json ) == len( ONOS5_flows_json )\
778 and len( ONOS1_flows_json ) == len( ONOS6_flows_json )\
779 and len( ONOS1_flows_json ) == len( ONOS7_flows_json ):
780 # TODO: Do a better check, maybe compare flows on switches?
781 flow_state = ONOS1_flows
782 flow_check = main.TRUE
783 main.log.report( "Flow count is consistent across all ONOS nodes" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800784 else:
Jon Hall6aec96b2015-01-19 14:49:31 -0800785 main.log.warn( "ONOS1 flows: " +
786 json.dumps( ONOS1_flows_json, sort_keys=True,
787 indent=4, separators=( ',', ': ' ) ) )
788 main.log.warn( "ONOS2 flows: " +
789 json.dumps( ONOS2_flows_json, sort_keys=True,
790 indent=4, separators=( ',', ': ' ) ) )
791 main.log.warn( "ONOS3 flows: " +
792 json.dumps( ONOS3_flows_json, sort_keys=True,
793 indent=4, separators=( ',', ': ' ) ) )
794 main.log.warn( "ONOS4 flows: " +
795 json.dumps( ONOS4_flows_json, sort_keys=True,
796 indent=4, separators=( ',', ': ' ) ) )
797 main.log.warn( "ONOS5 flows: " +
798 json.dumps( ONOS5_flows_json, sort_keys=True,
799 indent=4, separators=( ',', ': ' ) ) )
800 main.log.warn( "ONOS6 flows: " +
801 json.dumps( ONOS6_flows_json, sort_keys=True,
802 indent=4, separators=( ',', ': ' ) ) )
803 main.log.warn( "ONOS7 flows: " +
804 json.dumps( ONOS7_flows_json, sort_keys=True,
805 indent=4, separators=( ',', ': ' ) ) )
806 utilities.assert_equals(
807 expect=main.TRUE,
808 actual=flow_check,
809 onpass="The flow count is consistent across all ONOS nodes",
810 onfail="ONOS nodes have different flow counts" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800811
Jon Hall6aec96b2015-01-19 14:49:31 -0800812 main.step( "Get the OF Table entries" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800813 global flows
Jon Hall6aec96b2015-01-19 14:49:31 -0800814 flows = []
815 for i in range( 1, 29 ):
816 flows.append( main.Mininet2.get_flowTable( 1.3, "s" + str( i ) ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800817
Jon Hall6aec96b2015-01-19 14:49:31 -0800818 # TODO: Compare switch flow tables with ONOS flow tables
Jon Hall73cf9cc2014-11-20 22:28:38 -0800819
Jon Hall6aec96b2015-01-19 14:49:31 -0800820 main.step( "Start continuous pings" )
821 main.Mininet2.pingLong(
822 src=main.params[ 'PING' ][ 'source1' ],
823 target=main.params[ 'PING' ][ 'target1' ],
824 pingTime=500 )
825 main.Mininet2.pingLong(
826 src=main.params[ 'PING' ][ 'source2' ],
827 target=main.params[ 'PING' ][ 'target2' ],
828 pingTime=500 )
829 main.Mininet2.pingLong(
830 src=main.params[ 'PING' ][ 'source3' ],
831 target=main.params[ 'PING' ][ 'target3' ],
832 pingTime=500 )
833 main.Mininet2.pingLong(
834 src=main.params[ 'PING' ][ 'source4' ],
835 target=main.params[ 'PING' ][ 'target4' ],
836 pingTime=500 )
837 main.Mininet2.pingLong(
838 src=main.params[ 'PING' ][ 'source5' ],
839 target=main.params[ 'PING' ][ 'target5' ],
840 pingTime=500 )
841 main.Mininet2.pingLong(
842 src=main.params[ 'PING' ][ 'source6' ],
843 target=main.params[ 'PING' ][ 'target6' ],
844 pingTime=500 )
845 main.Mininet2.pingLong(
846 src=main.params[ 'PING' ][ 'source7' ],
847 target=main.params[ 'PING' ][ 'target7' ],
848 pingTime=500 )
849 main.Mininet2.pingLong(
850 src=main.params[ 'PING' ][ 'source8' ],
851 target=main.params[ 'PING' ][ 'target8' ],
852 pingTime=500 )
853 main.Mininet2.pingLong(
854 src=main.params[ 'PING' ][ 'source9' ],
855 target=main.params[ 'PING' ][ 'target9' ],
856 pingTime=500 )
857 main.Mininet2.pingLong(
858 src=main.params[ 'PING' ][ 'source10' ],
859 target=main.params[ 'PING' ][ 'target10' ],
860 pingTime=500 )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800861
Jon Hall6aec96b2015-01-19 14:49:31 -0800862 main.step( "Create TestONTopology object" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800863 ctrls = []
864 count = 1
865 while True:
866 temp = ()
Jon Hall6aec96b2015-01-19 14:49:31 -0800867 if ( 'ip' + str( count ) ) in main.params[ 'CTRL' ]:
868 temp = temp + ( getattr( main, ( 'ONOS' + str( count ) ) ), )
869 temp = temp + ( "ONOS" + str( count ), )
870 temp = temp + ( main.params[ 'CTRL' ][ 'ip' + str( count ) ], )
871 temp = temp + \
872 ( eval( main.params[ 'CTRL' ][ 'port' + str( count ) ] ), )
873 ctrls.append( temp )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800874 count = count + 1
875 else:
876 break
Jon Hall6aec96b2015-01-19 14:49:31 -0800877 MNTopo = TestONTopology(
878 main.Mininet1,
879 ctrls ) # can also add Intent API info for intent operations
Jon Hall73cf9cc2014-11-20 22:28:38 -0800880
Jon Hall6aec96b2015-01-19 14:49:31 -0800881 main.step( "Collecting topology information from ONOS" )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800882 devices = []
883 devices.append( main.ONOScli1.devices() )
884 devices.append( main.ONOScli2.devices() )
885 devices.append( main.ONOScli3.devices() )
886 devices.append( main.ONOScli4.devices() )
887 devices.append( main.ONOScli5.devices() )
888 devices.append( main.ONOScli6.devices() )
889 devices.append( main.ONOScli7.devices() )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800890 hosts = []
Jon Hall6aec96b2015-01-19 14:49:31 -0800891 hosts.append( main.ONOScli1.hosts() )
892 hosts.append( main.ONOScli2.hosts() )
893 hosts.append( main.ONOScli3.hosts() )
894 hosts.append( main.ONOScli4.hosts() )
895 hosts.append( main.ONOScli5.hosts() )
896 hosts.append( main.ONOScli6.hosts() )
897 hosts.append( main.ONOScli7.hosts() )
898 for controller in range( 0, len( hosts ) ):
899 controller_str = str( controller + 1 )
900 for host in hosts[ controller ]:
901 if host[ 'ips' ] == []:
902 main.log.error( "DEBUG:Error with host ips on controller" +
903 controller_str + ": " + str( host ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -0800904 ports = []
905 ports.append( main.ONOScli1.ports() )
906 ports.append( main.ONOScli2.ports() )
907 ports.append( main.ONOScli3.ports() )
908 ports.append( main.ONOScli4.ports() )
909 ports.append( main.ONOScli5.ports() )
910 ports.append( main.ONOScli6.ports() )
911 ports.append( main.ONOScli7.ports() )
912 links = []
913 links.append( main.ONOScli1.links() )
914 links.append( main.ONOScli2.links() )
915 links.append( main.ONOScli3.links() )
916 links.append( main.ONOScli4.links() )
917 links.append( main.ONOScli5.links() )
918 links.append( main.ONOScli6.links() )
919 links.append( main.ONOScli7.links() )
Jon Hall94fd0472014-12-08 11:52:42 -0800920 clusters = []
921 clusters.append( main.ONOScli1.clusters() )
922 clusters.append( main.ONOScli2.clusters() )
923 clusters.append( main.ONOScli3.clusters() )
924 clusters.append( main.ONOScli4.clusters() )
925 clusters.append( main.ONOScli5.clusters() )
926 clusters.append( main.ONOScli6.clusters() )
927 clusters.append( main.ONOScli7.clusters() )
928 paths = []
929 temp_topo = main.ONOSbench.get_topology( main.ONOScli1.topology() )
Jon Hall6aec96b2015-01-19 14:49:31 -0800930 paths.append( temp_topo.get( 'paths', False ) )
Jon Hall94fd0472014-12-08 11:52:42 -0800931 temp_topo = main.ONOSbench.get_topology( main.ONOScli2.topology() )
Jon Hall6aec96b2015-01-19 14:49:31 -0800932 paths.append( temp_topo.get( 'paths', False ) )
Jon Hall94fd0472014-12-08 11:52:42 -0800933 temp_topo = main.ONOSbench.get_topology( main.ONOScli3.topology() )
Jon Hall6aec96b2015-01-19 14:49:31 -0800934 paths.append( temp_topo.get( 'paths', False ) )
Jon Hall94fd0472014-12-08 11:52:42 -0800935 temp_topo = main.ONOSbench.get_topology( main.ONOScli4.topology() )
Jon Hall6aec96b2015-01-19 14:49:31 -0800936 paths.append( temp_topo.get( 'paths', False ) )
Jon Hall94fd0472014-12-08 11:52:42 -0800937 temp_topo = main.ONOSbench.get_topology( main.ONOScli5.topology() )
Jon Hall6aec96b2015-01-19 14:49:31 -0800938 paths.append( temp_topo.get( 'paths', False ) )
Jon Hall94fd0472014-12-08 11:52:42 -0800939 temp_topo = main.ONOSbench.get_topology( main.ONOScli6.topology() )
Jon Hall6aec96b2015-01-19 14:49:31 -0800940 paths.append( temp_topo.get( 'paths', False ) )
Jon Hall94fd0472014-12-08 11:52:42 -0800941 temp_topo = main.ONOSbench.get_topology( main.ONOScli7.topology() )
Jon Hall6aec96b2015-01-19 14:49:31 -0800942 paths.append( temp_topo.get( 'paths', False ) )
Jon Hall94fd0472014-12-08 11:52:42 -0800943
Jon Hall6aec96b2015-01-19 14:49:31 -0800944 # Compare json objects for hosts, dataplane clusters and paths
Jon Hall94fd0472014-12-08 11:52:42 -0800945
Jon Hall6aec96b2015-01-19 14:49:31 -0800946 # hosts
Jon Hall94fd0472014-12-08 11:52:42 -0800947 consistent_hosts_result = main.TRUE
948 for controller in range( len( hosts ) ):
Jon Hall6aec96b2015-01-19 14:49:31 -0800949 controller_str = str( controller + 1 )
950 if "Error" not in hosts[ controller ]:
951 if hosts[ controller ] == hosts[ 0 ]:
Jon Hall94fd0472014-12-08 11:52:42 -0800952 continue
Jon Hall6aec96b2015-01-19 14:49:31 -0800953 else: # hosts not consistent
954 main.log.report( "hosts from ONOS" +
955 controller_str +
956 " is inconsistent with ONOS1" )
957 main.log.warn( repr( hosts[ controller ] ) )
Jon Hall94fd0472014-12-08 11:52:42 -0800958 consistent_hosts_result = main.FALSE
959
960 else:
Jon Hall6aec96b2015-01-19 14:49:31 -0800961 main.log.report( "Error in getting ONOS hosts from ONOS" +
962 controller_str )
Jon Hall94fd0472014-12-08 11:52:42 -0800963 consistent_hosts_result = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -0800964 main.log.warn( "ONOS" + controller_str +
965 " hosts response: " +
966 repr( hosts[ controller ] ) )
967 utilities.assert_equals(
968 expect=main.TRUE,
969 actual=consistent_hosts_result,
970 onpass="Hosts view is consistent across all ONOS nodes",
971 onfail="ONOS nodes have different views of hosts" )
Jon Hall94fd0472014-12-08 11:52:42 -0800972
Jon Hall6aec96b2015-01-19 14:49:31 -0800973 # Strongly connected clusters of devices
Jon Hall94fd0472014-12-08 11:52:42 -0800974 consistent_clusters_result = main.TRUE
975 for controller in range( len( clusters ) ):
Jon Hall6aec96b2015-01-19 14:49:31 -0800976 if "Error" not in clusters[ controller ]:
977 if clusters[ controller ] == clusters[ 0 ]:
Jon Hall94fd0472014-12-08 11:52:42 -0800978 continue
Jon Hall6aec96b2015-01-19 14:49:31 -0800979 else: # clusters not consistent
980 main.log.report( "clusters from ONOS" +
981 controller_str +
982 " is inconsistent with ONOS1" )
Jon Hall94fd0472014-12-08 11:52:42 -0800983 consistent_clusters_result = main.FALSE
984
985 else:
Jon Hall6aec96b2015-01-19 14:49:31 -0800986 main.log.report( "Error in getting dataplane clusters " +
987 "from ONOS" + controller_str )
Jon Hall94fd0472014-12-08 11:52:42 -0800988 consistent_clusters_result = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -0800989 main.log.warn( "ONOS" + controller_str +
990 " clusters response: " +
991 repr( clusters[ controller ] ) )
992 utilities.assert_equals(
993 expect=main.TRUE,
994 actual=consistent_clusters_result,
995 onpass="Clusters view is consistent across all ONOS nodes",
996 onfail="ONOS nodes have different views of clusters" )
997 # there should always only be one cluster
998 num_clusters = len( json.loads( clusters[ 0 ] ) )
999 utilities.assert_equals(
1000 expect=1,
1001 actual=num_clusters,
1002 onpass="ONOS shows 1 SCC",
1003 onfail="ONOS shows " +
1004 str( num_clusters ) +
1005 " SCCs" )
Jon Hall94fd0472014-12-08 11:52:42 -08001006
Jon Hall6aec96b2015-01-19 14:49:31 -08001007 # paths
Jon Hall94fd0472014-12-08 11:52:42 -08001008 consistent_paths_result = main.TRUE
1009 for controller in range( len( paths ) ):
Jon Hall6aec96b2015-01-19 14:49:31 -08001010 controller_str = str( controller + 1 )
1011 if "Error" not in paths[ controller ]:
1012 if paths[ controller ] == paths[ 0 ]:
Jon Hall94fd0472014-12-08 11:52:42 -08001013 continue
Jon Hall6aec96b2015-01-19 14:49:31 -08001014 else: # paths not consistent
1015 main.log.report( "paths from ONOS" + controller_str +
1016 " is inconsistent with ONOS1" )
Jon Hall94fd0472014-12-08 11:52:42 -08001017 consistent_paths_result = main.FALSE
1018
1019 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08001020 main.log.report( "Error in getting paths from ONOS" +
1021 controller_str )
Jon Hall94fd0472014-12-08 11:52:42 -08001022 consistent_paths_result = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001023 main.log.warn( "ONOS" + controller_str + " paths response: " +
1024 repr( paths[ controller ] ) )
1025 utilities.assert_equals(
1026 expect=main.TRUE,
1027 actual=consistent_paths_result,
1028 onpass="Paths count is consistent across all ONOS nodes",
1029 onfail="ONOS nodes have different counts of paths" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001030
Jon Hall6aec96b2015-01-19 14:49:31 -08001031 main.step( "Comparing ONOS topology to MN" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001032 devices_results = main.TRUE
1033 ports_results = main.TRUE
1034 links_results = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001035 for controller in range( num_controllers ):
1036 controller_str = str( controller + 1 )
1037 if devices[ controller ] or "Error" not in devices[ controller ]:
1038 current_devices_result = main.Mininet1.compare_switches(
1039 MNTopo,
1040 json.loads(
1041 devices[ controller ] ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001042 else:
1043 current_devices_result = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001044 utilities.assert_equals( expect=main.TRUE,
1045 actual=current_devices_result,
1046 onpass="ONOS" + controller_str +
1047 " Switches view is correct",
1048 onfail="ONOS" + controller_str +
1049 " Switches view is incorrect" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001050
Jon Hall6aec96b2015-01-19 14:49:31 -08001051 if ports[ controller ] or "Error" not in ports[ controller ]:
1052 current_ports_result = main.Mininet1.compare_ports(
1053 MNTopo,
1054 json.loads(
1055 ports[ controller ] ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001056 else:
1057 current_ports_result = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001058 utilities.assert_equals( expect=main.TRUE,
1059 actual=current_ports_result,
1060 onpass="ONOS" + controller_str +
1061 " ports view is correct",
1062 onfail="ONOS" + controller_str +
1063 " ports view is incorrect" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001064
Jon Hall6aec96b2015-01-19 14:49:31 -08001065 if links[ controller ] or "Error" not in links[ controller ]:
1066 current_links_result = main.Mininet1.compare_links(
1067 MNTopo,
1068 json.loads(
1069 links[ controller ] ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001070 else:
1071 current_links_result = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001072 utilities.assert_equals( expect=main.TRUE,
1073 actual=current_links_result,
1074 onpass="ONOS" + controller_str +
1075 " links view is correct",
1076 onfail="ONOS" + controller_str +
1077 " links view is incorrect" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001078
1079 devices_results = devices_results and current_devices_result
1080 ports_results = ports_results and current_ports_result
1081 links_results = links_results and current_links_result
1082
Jon Hall94fd0472014-12-08 11:52:42 -08001083 topo_result = devices_results and ports_results and links_results\
Jon Hall6aec96b2015-01-19 14:49:31 -08001084 and consistent_hosts_result and consistent_clusters_result\
1085 and consistent_paths_result
1086 utilities.assert_equals( expect=main.TRUE, actual=topo_result,
1087 onpass="Topology Check Test successful",
1088 onfail="Topology Check Test NOT successful" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001089
1090 final_assert = main.TRUE
1091 final_assert = final_assert and topo_result and flow_check \
Jon Hall6aec96b2015-01-19 14:49:31 -08001092 and intent_check and consistent_mastership and roles_not_null
1093 utilities.assert_equals( expect=main.TRUE, actual=final_assert,
1094 onpass="State check successful",
1095 onfail="State check NOT successful" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001096
Jon Hall6aec96b2015-01-19 14:49:31 -08001097 def CASE6( self, main ):
1098 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001099 The Failure case.
Jon Hall6aec96b2015-01-19 14:49:31 -08001100 """
Jon Hall94fd0472014-12-08 11:52:42 -08001101 import time
Jon Hall6aec96b2015-01-19 14:49:31 -08001102 main.log.report( "Killing 3 ONOS nodes" )
1103 main.log.case( "Restart minority of ONOS nodes" )
1104 # TODO: Randomize these nodes
1105 main.ONOSbench.onos_kill( ONOS1_ip )
1106 time.sleep( 10 )
1107 main.ONOSbench.onos_kill( ONOS2_ip )
1108 time.sleep( 10 )
1109 main.ONOSbench.onos_kill( ONOS3_ip )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001110
Jon Hall6aec96b2015-01-19 14:49:31 -08001111 main.step( "Checking if ONOS is up yet" )
Jon Hallffb386d2014-11-21 13:43:38 -08001112 count = 0
1113 onos_isup_result = main.FALSE
1114 while onos_isup_result == main.FALSE and count < 10:
Jon Hall6aec96b2015-01-19 14:49:31 -08001115 onos1_isup = main.ONOSbench.isup( ONOS1_ip )
1116 onos2_isup = main.ONOSbench.isup( ONOS2_ip )
1117 onos3_isup = main.ONOSbench.isup( ONOS3_ip )
Jon Hallffb386d2014-11-21 13:43:38 -08001118 onos_isup_result = onos1_isup and onos2_isup and onos3_isup
1119 count = count + 1
Jon Hall73cf9cc2014-11-20 22:28:38 -08001120 # TODO: if it becomes an issue, we can retry this step a few times
1121
Jon Hall6aec96b2015-01-19 14:49:31 -08001122 cli_result1 = main.ONOScli1.start_onos_cli( ONOS1_ip )
1123 cli_result2 = main.ONOScli2.start_onos_cli( ONOS2_ip )
1124 cli_result3 = main.ONOScli3.start_onos_cli( ONOS3_ip )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001125 cli_results = cli_result1 and cli_result2 and cli_result3
1126
Jon Hall6aec96b2015-01-19 14:49:31 -08001127 main.log.info( "Install leadership election app on restarted node" )
Jon Hall669173b2014-12-17 11:36:30 -08001128
Jon Hall73cf9cc2014-11-20 22:28:38 -08001129 case_results = main.TRUE and onos_isup_result and cli_results
Jon Hall6aec96b2015-01-19 14:49:31 -08001130 utilities.assert_equals( expect=main.TRUE, actual=case_results,
1131 onpass="ONOS restart successful",
1132 onfail="ONOS restart NOT successful" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001133
Jon Hall6aec96b2015-01-19 14:49:31 -08001134 def CASE7( self, main ):
1135 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001136 Check state after ONOS failure
Jon Hall6aec96b2015-01-19 14:49:31 -08001137 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001138 import json
Jon Hall6aec96b2015-01-19 14:49:31 -08001139 main.case( "Running ONOS Constant State Tests" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001140
Jon Hall6aec96b2015-01-19 14:49:31 -08001141 # Assert that each device has a master
Jon Hall94fd0472014-12-08 11:52:42 -08001142 ONOS1_master_not_null = main.ONOScli1.roles_not_null()
1143 ONOS2_master_not_null = main.ONOScli2.roles_not_null()
1144 ONOS3_master_not_null = main.ONOScli3.roles_not_null()
1145 ONOS4_master_not_null = main.ONOScli4.roles_not_null()
1146 ONOS5_master_not_null = main.ONOScli5.roles_not_null()
1147 ONOS6_master_not_null = main.ONOScli6.roles_not_null()
1148 ONOS7_master_not_null = main.ONOScli7.roles_not_null()
1149 roles_not_null = ONOS1_master_not_null and ONOS2_master_not_null and\
Jon Hall6aec96b2015-01-19 14:49:31 -08001150 ONOS3_master_not_null and ONOS4_master_not_null and\
1151 ONOS5_master_not_null and ONOS6_master_not_null and\
1152 ONOS7_master_not_null
1153 utilities.assert_equals(
1154 expect=main.TRUE,
1155 actual=roles_not_null,
1156 onpass="Each device has a master",
1157 onfail="Some devices don't have a master assigned" )
Jon Hall94fd0472014-12-08 11:52:42 -08001158
Jon Hall6aec96b2015-01-19 14:49:31 -08001159 main.step( "Check if switch roles are consistent across all nodes" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001160 ONOS1_mastership = main.ONOScli1.roles()
1161 ONOS2_mastership = main.ONOScli2.roles()
1162 ONOS3_mastership = main.ONOScli3.roles()
1163 ONOS4_mastership = main.ONOScli4.roles()
1164 ONOS5_mastership = main.ONOScli5.roles()
1165 ONOS6_mastership = main.ONOScli6.roles()
1166 ONOS7_mastership = main.ONOScli7.roles()
Jon Hall6aec96b2015-01-19 14:49:31 -08001167 # print json.dumps( json.loads( ONOS1_mastership ), sort_keys=True,
1168 # indent=4, separators=( ',', ': ' ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001169 if "Error" in ONOS1_mastership or not ONOS1_mastership\
1170 or "Error" in ONOS2_mastership or not ONOS2_mastership\
1171 or "Error" in ONOS3_mastership or not ONOS3_mastership\
1172 or "Error" in ONOS4_mastership or not ONOS4_mastership\
1173 or "Error" in ONOS5_mastership or not ONOS5_mastership\
1174 or "Error" in ONOS6_mastership or not ONOS6_mastership\
1175 or "Error" in ONOS7_mastership or not ONOS7_mastership:
Jon Hall6aec96b2015-01-19 14:49:31 -08001176 main.log.error( "Error in getting ONOS mastership" )
1177 main.log.warn( "ONOS1 mastership response: " +
1178 repr( ONOS1_mastership ) )
1179 main.log.warn( "ONOS2 mastership response: " +
1180 repr( ONOS2_mastership ) )
1181 main.log.warn( "ONOS3 mastership response: " +
1182 repr( ONOS3_mastership ) )
1183 main.log.warn( "ONOS4 mastership response: " +
1184 repr( ONOS4_mastership ) )
1185 main.log.warn( "ONOS5 mastership response: " +
1186 repr( ONOS5_mastership ) )
1187 main.log.warn( "ONOS6 mastership response: " +
1188 repr( ONOS6_mastership ) )
1189 main.log.warn( "ONOS7 mastership response: " +
1190 repr( ONOS7_mastership ) )
1191 consistent_mastership = main.FALSE
Jon Hall73cf9cc2014-11-20 22:28:38 -08001192 elif ONOS1_mastership == ONOS2_mastership\
1193 and ONOS1_mastership == ONOS3_mastership\
1194 and ONOS1_mastership == ONOS4_mastership\
1195 and ONOS1_mastership == ONOS5_mastership\
1196 and ONOS1_mastership == ONOS6_mastership\
1197 and ONOS1_mastership == ONOS7_mastership:
Jon Hall6aec96b2015-01-19 14:49:31 -08001198 consistent_mastership = main.TRUE
1199 main.log.report(
1200 "Switch roles are consistent across all ONOS nodes" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001201 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08001202 main.log.warn( "ONOS1 roles: ", json.dumps(
1203 json.loads( ONOS1_mastership ), sort_keys=True, indent=4,
1204 separators=( ',', ': ' ) ) )
1205 main.log.warn( "ONOS2 roles: ", json.dumps(
1206 json.loads( ONOS2_mastership ), sort_keys=True, indent=4,
1207 separators=( ',', ': ' ) ) )
1208 main.log.warn( "ONOS3 roles: ", json.dumps(
1209 json.loads( ONOS3_mastership ), sort_keys=True, indent=4,
1210 separators=( ',', ': ' ) ) )
1211 main.log.warn( "ONOS4 roles: ", json.dumps(
1212 json.loads( ONOS4_mastership ), sort_keys=True, indent=4,
1213 separators=( ',', ': ' ) ) )
1214 main.log.warn( "ONOS5 roles: ", json.dumps(
1215 json.loads( ONOS5_mastership ), sort_keys=True, indent=4,
1216 separators=( ',', ': ' ) ) )
1217 main.log.warn( "ONOS6 roles: ", json.dumps(
1218 json.loads( ONOS6_mastership ), sort_keys=True, indent=4,
1219 separators=( ',', ': ' ) ) )
1220 main.log.warn( "ONOS7 roles: ", json.dumps(
1221 json.loads( ONOS7_mastership ), sort_keys=True, indent=4,
1222 separators=( ',', ': ' ) ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001223 consistent_mastership = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001224 utilities.assert_equals(
1225 expect=main.TRUE,
1226 actual=consistent_mastership,
1227 onpass="Switch roles are consistent across all ONOS nodes",
1228 onfail="ONOS nodes have different views of switch roles" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001229
1230 description2 = "Compare switch roles from before failure"
Jon Hall6aec96b2015-01-19 14:49:31 -08001231 main.step( description2 )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001232
Jon Hall6aec96b2015-01-19 14:49:31 -08001233 current_json = json.loads( ONOS1_mastership )
1234 old_json = json.loads( mastership_state )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001235 mastership_check = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001236 for i in range( 1, 29 ):
1237 switchDPID = str(
1238 main.Mininet1.getSwitchDPID(
1239 switch="s" +
1240 str( i ) ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001241
Jon Hall6aec96b2015-01-19 14:49:31 -08001242 current = [ switch[ 'master' ] for switch in current_json
1243 if switchDPID in switch[ 'id' ] ]
1244 old = [ switch[ 'master' ] for switch in old_json
1245 if switchDPID in switch[ 'id' ] ]
Jon Hall73cf9cc2014-11-20 22:28:38 -08001246 if current == old:
1247 mastership_check = mastership_check and main.TRUE
1248 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08001249 main.log.warn( "Mastership of switch %s changed" % switchDPID )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001250 mastership_check = main.FALSE
1251 if mastership_check == main.TRUE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001252 main.log.report( "Mastership of Switches was not changed" )
1253 utilities.assert_equals(
1254 expect=main.TRUE,
1255 actual=mastership_check,
1256 onpass="Mastership of Switches was not changed",
1257 onfail="Mastership of some switches changed" )
1258 # NOTE: we expect mastership to change on controller failure
Jon Hall669173b2014-12-17 11:36:30 -08001259 mastership_check = consistent_mastership
Jon Hall73cf9cc2014-11-20 22:28:38 -08001260
Jon Hall6aec96b2015-01-19 14:49:31 -08001261 main.step( "Get the intents and compare across all nodes" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001262 ONOS1_intents = main.ONOScli1.intents( json_format=True )
1263 ONOS2_intents = main.ONOScli2.intents( json_format=True )
1264 ONOS3_intents = main.ONOScli3.intents( json_format=True )
1265 ONOS4_intents = main.ONOScli4.intents( json_format=True )
1266 ONOS5_intents = main.ONOScli5.intents( json_format=True )
1267 ONOS6_intents = main.ONOScli6.intents( json_format=True )
1268 ONOS7_intents = main.ONOScli7.intents( json_format=True )
1269 intent_check = main.FALSE
1270 if "Error" in ONOS1_intents or not ONOS1_intents\
1271 or "Error" in ONOS2_intents or not ONOS2_intents\
1272 or "Error" in ONOS3_intents or not ONOS3_intents\
1273 or "Error" in ONOS4_intents or not ONOS4_intents\
1274 or "Error" in ONOS5_intents or not ONOS5_intents\
1275 or "Error" in ONOS6_intents or not ONOS6_intents\
1276 or "Error" in ONOS7_intents or not ONOS7_intents:
Jon Hall6aec96b2015-01-19 14:49:31 -08001277 main.log.report( "Error in getting ONOS intents" )
1278 main.log.warn( "ONOS1 intents response: " + repr( ONOS1_intents ) )
1279 main.log.warn( "ONOS2 intents response: " + repr( ONOS2_intents ) )
1280 main.log.warn( "ONOS3 intents response: " + repr( ONOS3_intents ) )
1281 main.log.warn( "ONOS4 intents response: " + repr( ONOS4_intents ) )
1282 main.log.warn( "ONOS5 intents response: " + repr( ONOS5_intents ) )
1283 main.log.warn( "ONOS6 intents response: " + repr( ONOS6_intents ) )
1284 main.log.warn( "ONOS7 intents response: " + repr( ONOS7_intents ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001285 elif ONOS1_intents == ONOS2_intents\
1286 and ONOS1_intents == ONOS3_intents\
1287 and ONOS1_intents == ONOS4_intents\
1288 and ONOS1_intents == ONOS5_intents\
1289 and ONOS1_intents == ONOS6_intents\
1290 and ONOS1_intents == ONOS7_intents:
Jon Hall6aec96b2015-01-19 14:49:31 -08001291 intent_check = main.TRUE
1292 main.log.report( "Intents are consistent across all ONOS nodes" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001293 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08001294 main.log.warn( "ONOS1 intents: " )
1295 print json.dumps( json.loads( ONOS1_intents ), sort_keys=True,
1296 indent=4, separators=( ',', ': ' ) )
1297 main.log.warn( "ONOS2 intents: " )
1298 print json.dumps( json.loads( ONOS2_intents ), sort_keys=True,
1299 indent=4, separators=( ',', ': ' ) )
1300 main.log.warn( "ONOS3 intents: " )
1301 print json.dumps( json.loads( ONOS3_intents ), sort_keys=True,
1302 indent=4, separators=( ',', ': ' ) )
1303 main.log.warn( "ONOS4 intents: " )
1304 print json.dumps( json.loads( ONOS4_intents ), sort_keys=True,
1305 indent=4, separators=( ',', ': ' ) )
1306 main.log.warn( "ONOS5 intents: " )
1307 print json.dumps( json.loads( ONOS5_intents ), sort_keys=True,
1308 indent=4, separators=( ',', ': ' ) )
1309 main.log.warn( "ONOS6 intents: " )
1310 print json.dumps( json.loads( ONOS6_intents ), sort_keys=True,
1311 indent=4, separators=( ',', ': ' ) )
1312 main.log.warn( "ONOS7 intents: " )
1313 print json.dumps( json.loads( ONOS7_intents ), sort_keys=True,
1314 indent=4, separators=( ',', ': ' ) )
1315 utilities.assert_equals(
1316 expect=main.TRUE,
1317 actual=intent_check,
1318 onpass="Intents are consistent across all ONOS nodes",
1319 onfail="ONOS nodes have different views of intents" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001320
Jon Hall6aec96b2015-01-19 14:49:31 -08001321 # NOTE: Hazelcast has no durability, so intents are lost across system
1322 # restarts
1323 main.step( "Compare current intents with intents before the failure" )
1324 # NOTE: this requires case 5 to pass for intent_state to be set.
Jon Hall94fd0472014-12-08 11:52:42 -08001325 # maybe we should stop the test if that fails?
Jon Hall73cf9cc2014-11-20 22:28:38 -08001326 if intent_state == ONOS1_intents:
1327 same_intents = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001328 main.log.report( "Intents are consistent with before failure" )
1329 # TODO: possibly the states have changed? we may need to figure out
1330 # what the aceptable states are
Jon Hall73cf9cc2014-11-20 22:28:38 -08001331 else:
Jon Hall669173b2014-12-17 11:36:30 -08001332 try:
Jon Hall6aec96b2015-01-19 14:49:31 -08001333 main.log.warn( "ONOS1 intents: " )
1334 print json.dumps( json.loads( ONOS1_intents ),
1335 sort_keys=True, indent=4,
1336 separators=( ',', ': ' ) )
Jon Hall669173b2014-12-17 11:36:30 -08001337 except:
1338 pass
Jon Hall73cf9cc2014-11-20 22:28:38 -08001339 same_intents = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001340 utilities.assert_equals(
1341 expect=main.TRUE,
1342 actual=same_intents,
1343 onpass="Intents are consistent with before failure",
1344 onfail="The Intents changed during failure" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001345 intent_check = intent_check and same_intents
1346
Jon Hall6aec96b2015-01-19 14:49:31 -08001347 main.step( "Get the OF Table entries and compare to before " +
1348 "component failure" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001349 Flow_Tables = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001350 flows2 = []
1351 for i in range( 28 ):
1352 main.log.info( "Checking flow table on s" + str( i + 1 ) )
1353 tmp_flows = main.Mininet2.get_flowTable( 1.3, "s" + str( i + 1 ) )
1354 flows2.append( tmp_flows )
1355 temp_result = main.Mininet2.flow_comp(
1356 flow1=flows[ i ],
1357 flow2=tmp_flows )
Jon Hall94fd0472014-12-08 11:52:42 -08001358 Flow_Tables = Flow_Tables and temp_result
Jon Hall73cf9cc2014-11-20 22:28:38 -08001359 if Flow_Tables == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001360 main.log.info( "Differences in flow table for switch: s" +
1361 str( i + 1 ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001362 if Flow_Tables == main.TRUE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001363 main.log.report( "No changes were found in the flow tables" )
1364 utilities.assert_equals(
1365 expect=main.TRUE,
1366 actual=Flow_Tables,
1367 onpass="No changes were found in the flow tables",
1368 onfail="Changes were found in the flow tables" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001369
Jon Hall6aec96b2015-01-19 14:49:31 -08001370 main.step( "Check the continuous pings to ensure that no packets " +
1371 "were dropped during component failure" )
1372 # FIXME: This check is always failing. Investigate cause
1373 # NOTE: this may be something to do with file permsissions
Jon Hall73cf9cc2014-11-20 22:28:38 -08001374 # or slight change in format
Jon Hall6aec96b2015-01-19 14:49:31 -08001375 main.Mininet2.pingKill(
1376 main.params[ 'TESTONUSER' ],
1377 main.params[ 'TESTONIP' ] )
1378 Loss_In_Pings = main.FALSE
1379 # NOTE: checkForLoss returns main.FALSE with 0% packet loss
1380 for i in range( 8, 18 ):
1381 main.log.info(
1382 "Checking for a loss in pings along flow from s" +
1383 str( i ) )
1384 Loss_In_Pings = main.Mininet2.checkForLoss(
1385 "/tmp/ping.h" +
1386 str( i ) ) or Loss_In_Pings
Jon Hall73cf9cc2014-11-20 22:28:38 -08001387 if Loss_In_Pings == main.TRUE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001388 main.log.info( "Loss in ping detected" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001389 elif Loss_In_Pings == main.ERROR:
Jon Hall6aec96b2015-01-19 14:49:31 -08001390 main.log.info( "There are multiple mininet process running" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001391 elif Loss_In_Pings == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001392 main.log.info( "No Loss in the pings" )
1393 main.log.report( "No loss of dataplane connectivity" )
1394 utilities.assert_equals(
1395 expect=main.FALSE,
1396 actual=Loss_In_Pings,
1397 onpass="No Loss of connectivity",
1398 onfail="Loss of dataplane connectivity detected" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001399
Jon Hall6aec96b2015-01-19 14:49:31 -08001400 # Test of LeadershipElection
Jon Hall669173b2014-12-17 11:36:30 -08001401 leader_list = []
1402 leader_result = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001403 for controller in range( 1, num_controllers + 1 ):
1404 # loop through ONOScli handlers
1405 node = getattr( main, ( 'ONOScli' + str( controller ) ) )
Jon Hall669173b2014-12-17 11:36:30 -08001406 leaderN = node.election_test_leader()
Jon Hall6aec96b2015-01-19 14:49:31 -08001407 leader_list.append( leaderN )
Jon Hall669173b2014-12-17 11:36:30 -08001408 if leaderN == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001409 # error in response
1410 main.log.report( "Something is wrong with " +
1411 "election_test_leader function, check the" +
1412 " error logs" )
Jon Hall669173b2014-12-17 11:36:30 -08001413 leader_result = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001414 elif leaderN is None:
1415 main.log.report( "ONOS" + str( controller ) +
1416 " shows no leader for the election-app was" +
1417 " elected after the old one died" )
Jon Hall669173b2014-12-17 11:36:30 -08001418 leader_result = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001419 elif leaderN == ONOS1_ip or leaderN == ONOS2_ip or\
1420 leaderN == ONOS3_ip:
1421 main.log.report( "ONOS" + str( controller ) +
1422 " shows " + str( leaderN ) +
1423 " as leader for the election-app, but it " +
1424 "was restarted" )
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 = []
Jon Hall669173b2014-12-17 11:36:30 -08001510 hosts.append( json.loads( main.ONOScli1.hosts() ) )
1511 hosts.append( json.loads( main.ONOScli2.hosts() ) )
1512 hosts.append( json.loads( main.ONOScli3.hosts() ) )
1513 hosts.append( json.loads( main.ONOScli4.hosts() ) )
1514 hosts.append( json.loads( main.ONOScli5.hosts() ) )
1515 hosts.append( json.loads( main.ONOScli6.hosts() ) )
1516 hosts.append( json.loads( main.ONOScli7.hosts() ) )
Jon Hall6aec96b2015-01-19 14:49:31 -08001517 for controller in range( 0, len( hosts ) ):
1518 controller_str = str( controller + 1 )
1519 for host in hosts[ controller ]:
Jon Hall669173b2014-12-17 11:36:30 -08001520 host
Jon Hall6aec96b2015-01-19 14:49:31 -08001521 if host[ 'ips' ] == []:
1522 main.log.error(
1523 "DEBUG:Error with host ips on controller" +
1524 controller_str + ": " + str( host ) )
Jon Hall94fd0472014-12-08 11:52:42 -08001525 ports = []
1526 ports.append( main.ONOScli1.ports() )
1527 ports.append( main.ONOScli2.ports() )
1528 ports.append( main.ONOScli3.ports() )
1529 ports.append( main.ONOScli4.ports() )
1530 ports.append( main.ONOScli5.ports() )
1531 ports.append( main.ONOScli6.ports() )
1532 ports.append( main.ONOScli7.ports() )
1533 links = []
1534 links.append( main.ONOScli1.links() )
1535 links.append( main.ONOScli2.links() )
1536 links.append( main.ONOScli3.links() )
1537 links.append( main.ONOScli4.links() )
1538 links.append( main.ONOScli5.links() )
1539 links.append( main.ONOScli6.links() )
1540 links.append( main.ONOScli7.links() )
1541 clusters = []
1542 clusters.append( main.ONOScli1.clusters() )
1543 clusters.append( main.ONOScli2.clusters() )
1544 clusters.append( main.ONOScli3.clusters() )
1545 clusters.append( main.ONOScli4.clusters() )
1546 clusters.append( main.ONOScli5.clusters() )
1547 clusters.append( main.ONOScli6.clusters() )
1548 clusters.append( main.ONOScli7.clusters() )
1549 paths = []
1550 temp_topo = main.ONOSbench.get_topology( main.ONOScli1.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.ONOScli2.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.ONOScli3.topology() )
Jon Hall6aec96b2015-01-19 14:49:31 -08001555 paths.append( temp_topo.get( 'paths', False ) )
Jon Hall94fd0472014-12-08 11:52:42 -08001556 temp_topo = main.ONOSbench.get_topology( main.ONOScli4.topology() )
Jon Hall6aec96b2015-01-19 14:49:31 -08001557 paths.append( temp_topo.get( 'paths', False ) )
Jon Hall94fd0472014-12-08 11:52:42 -08001558 temp_topo = main.ONOSbench.get_topology( main.ONOScli5.topology() )
Jon Hall6aec96b2015-01-19 14:49:31 -08001559 paths.append( temp_topo.get( 'paths', False ) )
Jon Hall94fd0472014-12-08 11:52:42 -08001560 temp_topo = main.ONOSbench.get_topology( main.ONOScli6.topology() )
Jon Hall6aec96b2015-01-19 14:49:31 -08001561 paths.append( temp_topo.get( 'paths', False ) )
Jon Hall94fd0472014-12-08 11:52:42 -08001562 temp_topo = main.ONOSbench.get_topology( main.ONOScli7.topology() )
Jon Hall6aec96b2015-01-19 14:49:31 -08001563 paths.append( temp_topo.get( 'paths', False ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001564
Jon Hall94fd0472014-12-08 11:52:42 -08001565 elapsed = time.time() - start_time
1566 cli_time = time.time() - cli_start
Jon Hall6aec96b2015-01-19 14:49:31 -08001567 print "CLI time: " + str( cli_time )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001568
Jon Hall6aec96b2015-01-19 14:49:31 -08001569 for controller in range( num_controllers ):
1570 controller_str = str( controller + 1 )
1571 if devices[ controller ] or "Error" not in devices[
1572 controller ]:
1573 current_devices_result = main.Mininet1.compare_switches(
1574 MNTopo,
1575 json.loads(
1576 devices[ controller ] ) )
Jon Hall94fd0472014-12-08 11:52:42 -08001577 else:
1578 current_devices_result = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001579 utilities.assert_equals( expect=main.TRUE,
1580 actual=current_devices_result,
1581 onpass="ONOS" + controller_str +
1582 " Switches view is correct",
1583 onfail="ONOS" + controller_str +
1584 " Switches view is incorrect" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001585
Jon Hall6aec96b2015-01-19 14:49:31 -08001586 if ports[ controller ] or "Error" not in ports[ controller ]:
1587 current_ports_result = main.Mininet1.compare_ports(
1588 MNTopo,
1589 json.loads(
1590 ports[ controller ] ) )
Jon Hall94fd0472014-12-08 11:52:42 -08001591 else:
1592 current_ports_result = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001593 utilities.assert_equals( expect=main.TRUE,
1594 actual=current_ports_result,
1595 onpass="ONOS" + controller_str +
1596 " ports view is correct",
1597 onfail="ONOS" + controller_str +
1598 " ports view is incorrect" )
Jon Hall94fd0472014-12-08 11:52:42 -08001599
Jon Hall6aec96b2015-01-19 14:49:31 -08001600 if links[ controller ] or "Error" not in links[ controller ]:
1601 current_links_result = main.Mininet1.compare_links(
1602 MNTopo,
1603 json.loads(
1604 links[ controller ] ) )
Jon Hall94fd0472014-12-08 11:52:42 -08001605 else:
1606 current_links_result = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001607 utilities.assert_equals( expect=main.TRUE,
1608 actual=current_links_result,
1609 onpass="ONOS" + controller_str +
1610 " links view is correct",
1611 onfail="ONOS" + controller_str +
1612 " links view is incorrect" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001613 devices_results = devices_results and current_devices_result
1614 ports_results = ports_results and current_ports_result
1615 links_results = links_results and current_links_result
Jon Hall94fd0472014-12-08 11:52:42 -08001616
Jon Hall6aec96b2015-01-19 14:49:31 -08001617 # Compare json objects for hosts, dataplane clusters and paths
Jon Hall94fd0472014-12-08 11:52:42 -08001618
Jon Hall6aec96b2015-01-19 14:49:31 -08001619 # hosts
Jon Hall94fd0472014-12-08 11:52:42 -08001620 consistent_hosts_result = main.TRUE
1621 for controller in range( len( hosts ) ):
Jon Hall6aec96b2015-01-19 14:49:31 -08001622 controller_str = str( controller + 1 )
1623 if "Error" not in hosts[ controller ]:
1624 if hosts[ controller ] == hosts[ 0 ]:
Jon Hall94fd0472014-12-08 11:52:42 -08001625 continue
Jon Hall6aec96b2015-01-19 14:49:31 -08001626 else: # hosts not consistent
1627 main.log.report( "hosts from ONOS" + controller_str +
1628 " is inconsistent with ONOS1" )
1629 main.log.warn( repr( hosts[ controller ] ) )
Jon Hall94fd0472014-12-08 11:52:42 -08001630 consistent_hosts_result = main.FALSE
1631
1632 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08001633 main.log.report( "Error in getting ONOS hosts from ONOS" +
1634 controller_str )
Jon Hall94fd0472014-12-08 11:52:42 -08001635 consistent_hosts_result = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001636 main.log.warn( "ONOS" + controller_str +
1637 " hosts response: " +
1638 repr( hosts[ controller ] ) )
1639 utilities.assert_equals(
1640 expect=main.TRUE,
1641 actual=consistent_hosts_result,
1642 onpass="Hosts view is consistent across all ONOS nodes",
1643 onfail="ONOS nodes have different views of hosts" )
Jon Hall94fd0472014-12-08 11:52:42 -08001644
Jon Hall6aec96b2015-01-19 14:49:31 -08001645 # Strongly connected clusters of devices
Jon Hall94fd0472014-12-08 11:52:42 -08001646 consistent_clusters_result = main.TRUE
1647 for controller in range( len( clusters ) ):
Jon Hall6aec96b2015-01-19 14:49:31 -08001648 controller_str = str( controller + 1 )
1649 if "Error" not in clusters[ controller ]:
1650 if clusters[ controller ] == clusters[ 0 ]:
Jon Hall94fd0472014-12-08 11:52:42 -08001651 continue
Jon Hall6aec96b2015-01-19 14:49:31 -08001652 else: # clusters not consistent
1653 main.log.report( "clusters from ONOS" +
1654 controller_str +
1655 " is inconsistent with ONOS1" )
Jon Hall94fd0472014-12-08 11:52:42 -08001656 consistent_clusters_result = main.FALSE
1657
1658 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08001659 main.log.report( "Error in getting dataplane clusters " +
1660 "from ONOS" + controller_str )
Jon Hall94fd0472014-12-08 11:52:42 -08001661 consistent_clusters_result = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001662 main.log.warn( "ONOS" + controller_str +
1663 " clusters response: " +
1664 repr( clusters[ controller ] ) )
1665 utilities.assert_equals(
1666 expect=main.TRUE,
1667 actual=consistent_clusters_result,
1668 onpass="Clusters view is consistent across all ONOS nodes",
1669 onfail="ONOS nodes have different views of clusters" )
1670 # there should always only be one cluster
1671 num_clusters = len( json.loads( clusters[ 0 ] ) )
1672 utilities.assert_equals(
1673 expect=1,
1674 actual=num_clusters,
1675 onpass="ONOS shows 1 SCC",
1676 onfail="ONOS shows " +
1677 str( num_clusters ) +
1678 " SCCs" )
Jon Hall94fd0472014-12-08 11:52:42 -08001679
Jon Hall6aec96b2015-01-19 14:49:31 -08001680 # paths
Jon Hall94fd0472014-12-08 11:52:42 -08001681 consistent_paths_result = main.TRUE
1682 for controller in range( len( paths ) ):
Jon Hall6aec96b2015-01-19 14:49:31 -08001683 controller_str = str( controller + 1 )
1684 if "Error" not in paths[ controller ]:
1685 if paths[ controller ] == paths[ 0 ]:
Jon Hall94fd0472014-12-08 11:52:42 -08001686 continue
Jon Hall6aec96b2015-01-19 14:49:31 -08001687 else: # paths not consistent
1688 main.log.report( "paths from ONOS" + controller_str +
1689 " is inconsistent with ONOS1" )
Jon Hall94fd0472014-12-08 11:52:42 -08001690 consistent_paths_result = main.FALSE
1691
1692 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08001693 main.log.report( "Error in getting paths from ONOS" +
1694 controller_str )
Jon Hall94fd0472014-12-08 11:52:42 -08001695 consistent_paths_result = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001696 main.log.warn( "ONOS" + controller_str +
1697 " paths response: " +
1698 repr( paths[ controller ] ) )
1699 utilities.assert_equals(
1700 expect=main.TRUE,
1701 actual=consistent_paths_result,
1702 onpass="Paths count is consistent across all ONOS nodes",
1703 onfail="ONOS nodes have different counts of paths" )
Jon Hall94fd0472014-12-08 11:52:42 -08001704
Jon Hall6aec96b2015-01-19 14:49:31 -08001705 topo_result = ( devices_results and ports_results and links_results
1706 and consistent_hosts_result
1707 and consistent_clusters_result
1708 and consistent_paths_result )
Jon Hall94fd0472014-12-08 11:52:42 -08001709
Jon Hall6aec96b2015-01-19 14:49:31 -08001710 topo_result = topo_result and int( count <= 2 )
1711 note = "note it takes about " + str( int( cli_time ) ) + \
1712 " seconds for the test to make all the cli calls to fetch " +\
1713 "the topology from each ONOS instance"
1714 main.log.report(
1715 "Very crass estimate for topology discovery/convergence(" +
1716 str( note ) + "): " + str( elapsed ) + " seconds, " +
1717 str( count ) + " tries" )
1718 utilities.assert_equals( expect=main.TRUE, actual=topo_result,
1719 onpass="Topology Check Test successful",
1720 onfail="Topology Check Test NOT successful" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001721 if topo_result == main.TRUE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001722 main.log.report( "ONOS topology view matches Mininet topology" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001723
Jon Hall6aec96b2015-01-19 14:49:31 -08001724 def CASE9( self, main ):
1725 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001726 Link s3-s28 down
Jon Hall6aec96b2015-01-19 14:49:31 -08001727 """
1728 import time
1729 # NOTE: You should probably run a topology check after this
Jon Hall73cf9cc2014-11-20 22:28:38 -08001730
Jon Hall6aec96b2015-01-19 14:49:31 -08001731 link_sleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001732
Jon Hall6aec96b2015-01-19 14:49:31 -08001733 description = "Turn off a link to ensure that Link Discovery " +\
1734 "is working properly"
1735 main.log.report( description )
1736 main.case( description )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001737
Jon Hall6aec96b2015-01-19 14:49:31 -08001738 main.step( "Kill Link between s3 and s28" )
1739 Link_Down = main.Mininet1.link( END1="s3", END2="s28", OPTION="down" )
1740 main.log.info(
1741 "Waiting " +
1742 str( link_sleep ) +
1743 " seconds for link down to be discovered" )
1744 time.sleep( link_sleep )
1745 utilities.assert_equals( expect=main.TRUE, actual=Link_Down,
1746 onpass="Link down succesful",
1747 onfail="Failed to bring link down" )
1748 # TODO do some sort of check here
Jon Hall73cf9cc2014-11-20 22:28:38 -08001749
Jon Hall6aec96b2015-01-19 14:49:31 -08001750 def CASE10( self, main ):
1751 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001752 Link s3-s28 up
Jon Hall6aec96b2015-01-19 14:49:31 -08001753 """
1754 import time
1755 # NOTE: You should probably run a topology check after this
Jon Hall73cf9cc2014-11-20 22:28:38 -08001756
Jon Hall6aec96b2015-01-19 14:49:31 -08001757 link_sleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001758
Jon Hall6aec96b2015-01-19 14:49:31 -08001759 description = "Restore a link to ensure that Link Discovery is " + \
1760 "working properly"
1761 main.log.report( description )
1762 main.case( description )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001763
Jon Hall6aec96b2015-01-19 14:49:31 -08001764 main.step( "Bring link between s3 and s28 back up" )
1765 Link_Up = main.Mininet1.link( END1="s3", END2="s28", OPTION="up" )
1766 main.log.info(
1767 "Waiting " +
1768 str( link_sleep ) +
1769 " seconds for link up to be discovered" )
1770 time.sleep( link_sleep )
1771 utilities.assert_equals( expect=main.TRUE, actual=Link_Up,
1772 onpass="Link up succesful",
1773 onfail="Failed to bring link up" )
1774 # TODO do some sort of check here
Jon Hall73cf9cc2014-11-20 22:28:38 -08001775
Jon Hall6aec96b2015-01-19 14:49:31 -08001776 def CASE11( self, main ):
1777 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001778 Switch Down
Jon Hall6aec96b2015-01-19 14:49:31 -08001779 """
1780 # NOTE: You should probably run a topology check after this
Jon Hall73cf9cc2014-11-20 22:28:38 -08001781 import time
1782
Jon Hall6aec96b2015-01-19 14:49:31 -08001783 switch_sleep = float( main.params[ 'timers' ][ 'SwitchDiscovery' ] )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001784
1785 description = "Killing a switch to ensure it is discovered correctly"
Jon Hall6aec96b2015-01-19 14:49:31 -08001786 main.log.report( description )
1787 main.case( description )
1788 switch = main.params[ 'kill' ][ 'switch' ]
1789 switchDPID = main.params[ 'kill' ][ 'dpid' ]
Jon Hall73cf9cc2014-11-20 22:28:38 -08001790
Jon Hall6aec96b2015-01-19 14:49:31 -08001791 # TODO: Make this switch parameterizable
1792 main.step( "Kill " + switch )
1793 main.log.report( "Deleting " + switch )
1794 main.Mininet1.del_switch( switch )
1795 main.log.info( "Waiting " + str( switch_sleep ) +
1796 " seconds for switch down to be discovered" )
1797 time.sleep( switch_sleep )
1798 device = main.ONOScli1.get_device( dpid=switchDPID )
1799 # Peek at the deleted switch
1800 main.log.warn( str( device ) )
Jon Hall94fd0472014-12-08 11:52:42 -08001801 result = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001802 if device and device[ 'available' ] is False:
Jon Hall94fd0472014-12-08 11:52:42 -08001803 result = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001804 utilities.assert_equals( expect=main.TRUE, actual=result,
1805 onpass="Kill switch succesful",
1806 onfail="Failed to kill switch?" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001807
Jon Hall6aec96b2015-01-19 14:49:31 -08001808 def CASE12( self, main ):
1809 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001810 Switch Up
Jon Hall6aec96b2015-01-19 14:49:31 -08001811 """
1812 # NOTE: You should probably run a topology check after this
Jon Hall73cf9cc2014-11-20 22:28:38 -08001813 import time
Jon Hall669173b2014-12-17 11:36:30 -08001814
Jon Hall6aec96b2015-01-19 14:49:31 -08001815 switch_sleep = float( main.params[ 'timers' ][ 'SwitchDiscovery' ] )
1816 switch = main.params[ 'kill' ][ 'switch' ]
1817 switchDPID = main.params[ 'kill' ][ 'dpid' ]
1818 links = main.params[ 'kill' ][ 'links' ].split()
Jon Hall73cf9cc2014-11-20 22:28:38 -08001819 description = "Adding a switch to ensure it is discovered correctly"
Jon Hall6aec96b2015-01-19 14:49:31 -08001820 main.log.report( description )
1821 main.case( description )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001822
Jon Hall6aec96b2015-01-19 14:49:31 -08001823 main.step( "Add back " + switch )
1824 main.log.report( "Adding back " + switch )
1825 main.Mininet1.add_switch( switch, dpid=switchDPID )
1826 # TODO: New dpid or same? Ask Thomas?
1827 for peer in links:
1828 main.Mininet1.add_link( switch, peer )
1829 main.Mininet1.assign_sw_controller(
1830 sw=switch.split( 's' )[ 1 ],
1831 count=num_controllers,
1832 ip1=ONOS1_ip,
1833 port1=ONOS1_port,
1834 ip2=ONOS2_ip,
1835 port2=ONOS2_port,
1836 ip3=ONOS3_ip,
1837 port3=ONOS3_port,
1838 ip4=ONOS4_ip,
1839 port4=ONOS4_port,
1840 ip5=ONOS5_ip,
1841 port5=ONOS5_port,
1842 ip6=ONOS6_ip,
1843 port6=ONOS6_port,
1844 ip7=ONOS7_ip,
1845 port7=ONOS7_port )
1846 main.log.info(
1847 "Waiting " +
1848 str( switch_sleep ) +
1849 " seconds for switch up to be discovered" )
1850 time.sleep( switch_sleep )
1851 device = main.ONOScli1.get_device( dpid=switchDPID )
1852 # Peek at the deleted switch
1853 main.log.warn( str( device ) )
Jon Hall94fd0472014-12-08 11:52:42 -08001854 result = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001855 if device and device[ 'available' ]:
Jon Hall94fd0472014-12-08 11:52:42 -08001856 result = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001857 utilities.assert_equals( expect=main.TRUE, actual=result,
1858 onpass="add switch succesful",
1859 onfail="Failed to add switch?" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001860
Jon Hall6aec96b2015-01-19 14:49:31 -08001861 def CASE13( self, main ):
1862 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001863 Clean up
Jon Hall6aec96b2015-01-19 14:49:31 -08001864 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001865 import os
1866 import time
Jon Hall6aec96b2015-01-19 14:49:31 -08001867 # TODO: make use of this elsewhere
1868 ips = []
1869 ips.append(ONOS1_ip)
1870 ips.append(ONOS2_ip)
1871 ips.append(ONOS3_ip)
1872 ips.append(ONOS4_ip)
1873 ips.append(ONOS5_ip)
1874 ips.append(ONOS6_ip)
1875 ips.append(ONOS7_ip)
1876
1877 # printing colors to terminal
Jon Hall669173b2014-12-17 11:36:30 -08001878 colors = {}
Jon Hall6aec96b2015-01-19 14:49:31 -08001879 colors[ 'cyan' ] = '\033[96m'
1880 colors[ 'purple' ] = '\033[95m'
1881 colors[ 'blue' ] = '\033[94m'
1882 colors[ 'green' ] = '\033[92m'
1883 colors[ 'yellow' ] = '\033[93m'
1884 colors[ 'red' ] = '\033[91m'
1885 colors[ 'end' ] = '\033[0m'
Jon Hall73cf9cc2014-11-20 22:28:38 -08001886 description = "Test Cleanup"
Jon Hall6aec96b2015-01-19 14:49:31 -08001887 main.log.report( description )
1888 main.case( description )
1889 main.step( "Killing tcpdumps" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001890 main.Mininet2.stop_tcpdump()
1891
Jon Hall6aec96b2015-01-19 14:49:31 -08001892 main.step( "Checking ONOS Logs for errors" )
1893 for i in range(7):
1894 print colors[ 'purple' ] + "Checking logs for errors on " + \
1895 "ONOS" + str( i + 1 ) + ":" + colors[ 'end' ]
1896 print main.ONOSbench.check_logs( ips[i] )
Jon Hall94fd0472014-12-08 11:52:42 -08001897
Jon Hall6aec96b2015-01-19 14:49:31 -08001898 main.step( "Copying MN pcap and ONOS log files to test station" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001899 testname = main.TEST
Jon Hall6aec96b2015-01-19 14:49:31 -08001900 teststation_user = main.params[ 'TESTONUSER' ]
1901 teststation_IP = main.params[ 'TESTONIP' ]
1902 # NOTE: MN Pcap file is being saved to ~/packet_captures
Jon Hall73cf9cc2014-11-20 22:28:38 -08001903 # scp this file as MN and TestON aren't necessarily the same vm
Jon Hall6aec96b2015-01-19 14:49:31 -08001904 # FIXME: scp
1905 # mn files
1906 # TODO: Load these from params
1907 # NOTE: must end in /
Jon Hall73cf9cc2014-11-20 22:28:38 -08001908 log_folder = "/opt/onos/log/"
Jon Hall6aec96b2015-01-19 14:49:31 -08001909 log_files = [ "karaf.log", "karaf.log.1" ]
1910 # NOTE: must end in /
Jon Hall73cf9cc2014-11-20 22:28:38 -08001911 dst_dir = "~/packet_captures/"
1912 for f in log_files:
Jon Hall6aec96b2015-01-19 14:49:31 -08001913 for i in range(7):
1914 main.ONOSbench.handle.sendline( "scp sdn@" + ips[i] + ":" +
1915 log_folder + f + " " +
1916 teststation_user + "@" +
1917 teststation_IP + ":" +
1918 dst_dir + str( testname ) +
1919 "-ONOS" + str( i + 1 ) + "-" +
1920 f )
1921 # std*.log's
1922 # NOTE: must end in /
Jon Hall73cf9cc2014-11-20 22:28:38 -08001923 log_folder = "/opt/onos/var/"
Jon Hall6aec96b2015-01-19 14:49:31 -08001924 log_files = [ "stderr.log", "stdout.log" ]
1925 # NOTE: must end in /
Jon Hall73cf9cc2014-11-20 22:28:38 -08001926 dst_dir = "~/packet_captures/"
1927 for f in log_files:
Jon Hall6aec96b2015-01-19 14:49:31 -08001928 for i in range(7):
1929 main.ONOSbench.handle.sendline( "scp sdn@" + ips[i] + ":" +
1930 log_folder + f + " " +
1931 teststation_user + "@" +
1932 teststation_IP + ":" +
1933 dst_dir + str( testname ) +
1934 "-ONOS" + str( i + 1 ) + "-" +
1935 f )
1936 # sleep so scp can finish
1937 time.sleep( 10 )
1938 main.step( "Packing and rotating pcap archives" )
1939 os.system( "~/TestON/dependencies/rotate.sh " + str( testname ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001940
Jon Hall6aec96b2015-01-19 14:49:31 -08001941 # TODO: actually check something here
1942 utilities.assert_equals( expect=main.TRUE, actual=main.TRUE,
1943 onpass="Test cleanup successful",
1944 onfail="Test cleanup NOT successful" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001945
Jon Hall6aec96b2015-01-19 14:49:31 -08001946 def CASE14( self, main ):
1947 """
Jon Hall669173b2014-12-17 11:36:30 -08001948 start election app on all onos nodes
Jon Hall6aec96b2015-01-19 14:49:31 -08001949 """
Jon Hall669173b2014-12-17 11:36:30 -08001950 leader_result = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001951 # install app on onos 1
1952 main.log.info( "Install leadership election app" )
1953 main.ONOScli1.feature_install( "onos-app-election" )
1954 # wait for election
1955 # check for leader
Jon Hall669173b2014-12-17 11:36:30 -08001956 leader = main.ONOScli1.election_test_leader()
Jon Hall6aec96b2015-01-19 14:49:31 -08001957 # verify leader is ONOS1
Jon Hall669173b2014-12-17 11:36:30 -08001958 if leader == ONOS1_ip:
Jon Hall6aec96b2015-01-19 14:49:31 -08001959 # all is well
Jon Hall669173b2014-12-17 11:36:30 -08001960 pass
Jon Hall6aec96b2015-01-19 14:49:31 -08001961 elif leader is None:
1962 # No leader elected
1963 main.log.report( "No leader was elected" )
Jon Hall669173b2014-12-17 11:36:30 -08001964 leader_result = main.FALSE
1965 elif leader == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001966 # error in response
1967 # TODO: add check for "Command not found:" in the driver, this
1968 # means the app isn't loaded
1969 main.log.report( "Something is wrong with election_test_leader" +
1970 " function, check the error logs" )
Jon Hall669173b2014-12-17 11:36:30 -08001971 leader_result = main.FALSE
1972 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08001973 # error in response
1974 main.log.report(
1975 "Unexpected response from election_test_leader function:'" +
1976 str(leader) +
1977 "'" )
Jon Hall669173b2014-12-17 11:36:30 -08001978 leader_result = main.FALSE
1979
Jon Hall6aec96b2015-01-19 14:49:31 -08001980 # install on other nodes and check for leader.
1981 # Should be onos1 and each app should show the same leader
1982 for controller in range( 2, num_controllers + 1 ):
1983 # loop through ONOScli handlers
1984 node = getattr( main, ( 'ONOScli' + str( controller ) ) )
1985 node.feature_install( "onos-app-election" )
Jon Hall669173b2014-12-17 11:36:30 -08001986 leaderN = node.election_test_leader()
Jon Hall6aec96b2015-01-19 14:49:31 -08001987 # verify leader is ONOS1
Jon Hall669173b2014-12-17 11:36:30 -08001988 if leaderN == ONOS1_ip:
Jon Hall6aec96b2015-01-19 14:49:31 -08001989 # all is well
Jon Hall669173b2014-12-17 11:36:30 -08001990 pass
1991 elif leaderN == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001992 # error in response
1993 # TODO: add check for "Command not found:" in the driver, this
1994 # means the app isn't loaded
1995 main.log.report( "Something is wrong with " +
1996 "election_test_leader function, check the" +
1997 " error logs" )
Jon Hall669173b2014-12-17 11:36:30 -08001998 leader_result = main.FALSE
1999 elif leader != leaderN:
2000 leader_result = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08002001 main.log.report( "ONOS" + str( controller ) + " sees " +
2002 str( leaderN ) +
2003 " as the leader of the election app. Leader" +
2004 " should be " +
2005 str( leader ) )
Jon Hall669173b2014-12-17 11:36:30 -08002006 if leader_result:
Jon Hall6aec96b2015-01-19 14:49:31 -08002007 main.log.report( "Leadership election tests passed( consistent " +
2008 "view of leader across listeners and a leader " +
2009 "was elected)" )
2010 utilities.assert_equals(
2011 expect=main.TRUE,
2012 actual=leader_result,
2013 onpass="Leadership election passed",
2014 onfail="Something went wrong with Leadership election" )
Jon Hall669173b2014-12-17 11:36:30 -08002015
Jon Hall6aec96b2015-01-19 14:49:31 -08002016 def CASE15( self, main ):
2017 """
Jon Hall669173b2014-12-17 11:36:30 -08002018 Check that Leadership Election is still functional
Jon Hall6aec96b2015-01-19 14:49:31 -08002019 """
Jon Hall669173b2014-12-17 11:36:30 -08002020 leader_result = main.TRUE
2021 description = "Check that Leadership Election is still functional"
Jon Hall6aec96b2015-01-19 14:49:31 -08002022 main.log.report( description )
2023 main.case( description )
2024 main.step( "Find current leader and withdraw" )
Jon Hall669173b2014-12-17 11:36:30 -08002025 leader = main.ONOScli1.election_test_leader()
Jon Hall6aec96b2015-01-19 14:49:31 -08002026 # TODO: do some sanity checking on leader before using it
Jon Hall669173b2014-12-17 11:36:30 -08002027 withdraw_result = main.FALSE
2028 if leader == ONOS1_ip:
2029 old_leader = getattr( main, "ONOScli1" )
2030 elif leader == ONOS2_ip:
2031 old_leader = getattr( main, "ONOScli2" )
2032 elif leader == ONOS3_ip:
2033 old_leader = getattr( main, "ONOScli3" )
2034 elif leader == ONOS4_ip:
2035 old_leader = getattr( main, "ONOScli4" )
2036 elif leader == ONOS5_ip:
2037 old_leader = getattr( main, "ONOScli5" )
2038 elif leader == ONOS6_ip:
2039 old_leader = getattr( main, "ONOScli6" )
2040 elif leader == ONOS7_ip:
2041 old_leader = getattr( main, "ONOScli7" )
Jon Hall6aec96b2015-01-19 14:49:31 -08002042 elif leader is None or leader == main.FALSE:
2043 main.log.report(
2044 "Leader for the election app should be an ONOS node," +
2045 "instead got '" +
2046 str(leader) +
2047 "'" )
Jon Hall669173b2014-12-17 11:36:30 -08002048 leader_result = main.FALSE
2049 withdraw_result = old_leader.election_test_withdraw()
Jon Hall6aec96b2015-01-19 14:49:31 -08002050 utilities.assert_equals(
2051 expect=main.TRUE,
2052 actual=withdraw_result,
2053 onpass="App was withdrawn from election",
2054 onfail="App was not withdrawn from election" )
Jon Hall669173b2014-12-17 11:36:30 -08002055
Jon Hall6aec96b2015-01-19 14:49:31 -08002056 main.step( "Make sure new leader is elected" )
Jon Hall669173b2014-12-17 11:36:30 -08002057 leader_list = []
Jon Hall6aec96b2015-01-19 14:49:31 -08002058 for controller in range( 1, num_controllers + 1 ):
2059 # loop through ONOScli handlers
2060 node = getattr( main, ( 'ONOScli' + str( controller ) ) )
Jon Hall669173b2014-12-17 11:36:30 -08002061 leader_list.append( node.election_test_leader() )
2062 for leaderN in leader_list:
2063 if leaderN == leader:
Jon Hall6aec96b2015-01-19 14:49:31 -08002064 main.log.report(
2065 "ONOS" +
2066 str( controller ) +
2067 " still sees " +
2068 str( leader ) +
2069 " as leader after they withdrew" )
Jon Hall669173b2014-12-17 11:36:30 -08002070 leader_result = main.FALSE
2071 elif leaderN == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -08002072 # error in response
2073 # TODO: add check for "Command not found:" in the driver, this
2074 # means the app isn't loaded
2075 main.log.report( "Something is wrong with " +
2076 "election_test_leader function, " +
2077 "check the error logs" )
Jon Hall669173b2014-12-17 11:36:30 -08002078 leader_result = main.FALSE
2079 consistent_leader = main.FALSE
2080 if len( set( leader_list ) ) == 1:
Jon Hall6aec96b2015-01-19 14:49:31 -08002081 main.log.info( "Each Election-app sees '" +
2082 str(leader_list[0]) +
2083 "' as the leader" )
Jon Hall669173b2014-12-17 11:36:30 -08002084 consistent_leader = main.TRUE
2085 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08002086 main.log.report(
2087 "Inconsistent responses for leader of Election-app:" )
2088 for n in range( len( leader_list ) ):
2089 main.log.report( "ONOS" + str( n + 1 ) + " response: " +
2090 str( leader_list[ n ] ) )
Jon Hall669173b2014-12-17 11:36:30 -08002091 if leader_result:
Jon Hall6aec96b2015-01-19 14:49:31 -08002092 main.log.report( "Leadership election tests passed(consistent " +
2093 "view of leader across listeners and a new " +
2094 "leader was elected when the old leader " +
2095 "resigned)" )
2096 utilities.assert_equals(
2097 expect=main.TRUE,
2098 actual=leader_result,
2099 onpass="Leadership election passed",
2100 onfail="Something went wrong with Leadership election" )
Jon Hall669173b2014-12-17 11:36:30 -08002101
Jon Hall6aec96b2015-01-19 14:49:31 -08002102 main.step(
2103 "Run for election on old leader(just so everyone is in the hat)" )
Jon Hall669173b2014-12-17 11:36:30 -08002104 run_result = old_leader.election_test_run()
Jon Hall6aec96b2015-01-19 14:49:31 -08002105 utilities.assert_equals(
2106 expect=main.TRUE,
2107 actual=run_result,
2108 onpass="App re-ran for election",
2109 onfail="App failed to run for election" )
Jon Hall669173b2014-12-17 11:36:30 -08002110 if consistent_leader == main.TRUE:
2111 after_run = main.ONOScli1.election_test_leader()
Jon Hall6aec96b2015-01-19 14:49:31 -08002112 # verify leader didn't just change
2113 if after_run == leader_list[ 0 ]:
Jon Hall669173b2014-12-17 11:36:30 -08002114 leader_result = main.TRUE
2115 else:
2116 leader_result = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08002117 # TODO: assert on run and withdraw results?
Jon Hall669173b2014-12-17 11:36:30 -08002118
Jon Hall6aec96b2015-01-19 14:49:31 -08002119 utilities.assert_equals(
2120 expect=main.TRUE,
2121 actual=leader_result,
2122 onpass="Leadership election passed",
2123 onfail="Something went wrong with Leadership election after " +
2124 "the old leader re-ran for election" )