blob: e205a0263e9f615b0df83250a233461284561f62 [file] [log] [blame]
Jon Hall6aec96b2015-01-19 14:49:31 -08001"""
Jon Hallb1290e82014-11-18 16:17:48 -05002Description: This test is to determine if the HA test setup is
3 working correctly. There are no failures so this test should
4 have a 100% pass rate
5
6List of test cases:
7CASE1: Compile ONOS and push it to the test machines
8CASE2: Assign mastership to controllers
9CASE3: Assign intents
10CASE4: Ping across added host intents
11CASE5: Reading state of ONOS
12CASE6: The Failure case. Since this is the Sanity test, we do nothing.
Jon Hall368769f2014-11-19 15:43:35 -080013CASE7: Check state after control plane failure
Jon Hallb1290e82014-11-18 16:17:48 -050014CASE8: Compare topo
15CASE9: Link s3-s28 down
16CASE10: Link s3-s28 up
17CASE11: Switch down
18CASE12: Switch up
19CASE13: Clean up
Jon Hall669173b2014-12-17 11:36:30 -080020CASE14: start election app on all onos nodes
21CASE15: Check that Leadership Election is still functional
Jon Hall6aec96b2015-01-19 14:49:31 -080022"""
Jon Hall8f89dda2015-01-22 16:03:33 -080023
24
Jon Hallb1290e82014-11-18 16:17:48 -050025class HATestSanity:
26
Jon Hall6aec96b2015-01-19 14:49:31 -080027 def __init__( self ):
Jon Hallb1290e82014-11-18 16:17:48 -050028 self.default = ''
29
Jon Hall6aec96b2015-01-19 14:49:31 -080030 def CASE1( self, main ):
31 """
Jon Hallb1290e82014-11-18 16:17:48 -050032 CASE1 is to compile ONOS and push it to the test machines
33
34 Startup sequence:
35 git pull
36 mvn clean install
37 onos-package
38 cell <name>
39 onos-verify-cell
40 NOTE: temporary - onos-remove-raft-logs
41 onos-install -f
42 onos-wait-for-start
Jon Hall6aec96b2015-01-19 14:49:31 -080043 """
44 main.log.report( "ONOS HA Sanity test - initialization" )
45 main.case( "Setting up test environment" )
46 # TODO: save all the timers and output them for plotting
Jon Hallb1290e82014-11-18 16:17:48 -050047
48 # load some vairables from the params file
Jon Hall8f89dda2015-01-22 16:03:33 -080049 PULLCODE = False
Jon Hall6aec96b2015-01-19 14:49:31 -080050 if main.params[ 'Git' ] == 'True':
Jon Hall8f89dda2015-01-22 16:03:33 -080051 PULLCODE = True
Jon Hall529a37f2015-01-28 10:02:00 -080052 gitBranch = main.params[ 'branch' ]
Jon Hall8f89dda2015-01-22 16:03:33 -080053 cellName = main.params[ 'ENV' ][ 'cellName' ]
Jon Hall6aec96b2015-01-19 14:49:31 -080054
55 # set global variables
Jon Hall8f89dda2015-01-22 16:03:33 -080056 global ONOS1Ip
57 global ONOS1Port
58 global ONOS2Ip
59 global ONOS2Port
60 global ONOS3Ip
61 global ONOS3Port
62 global ONOS4Ip
63 global ONOS4Port
64 global ONOS5Ip
65 global ONOS5Port
66 global ONOS6Ip
67 global ONOS6Port
68 global ONOS7Ip
69 global ONOS7Port
70 global numControllers
Jon Hallb1290e82014-11-18 16:17:48 -050071
Jon Hall8f89dda2015-01-22 16:03:33 -080072 ONOS1Ip = main.params[ 'CTRL' ][ 'ip1' ]
73 ONOS1Port = main.params[ 'CTRL' ][ 'port1' ]
74 ONOS2Ip = main.params[ 'CTRL' ][ 'ip2' ]
75 ONOS2Port = main.params[ 'CTRL' ][ 'port2' ]
76 ONOS3Ip = main.params[ 'CTRL' ][ 'ip3' ]
77 ONOS3Port = main.params[ 'CTRL' ][ 'port3' ]
78 ONOS4Ip = main.params[ 'CTRL' ][ 'ip4' ]
79 ONOS4Port = main.params[ 'CTRL' ][ 'port4' ]
80 ONOS5Ip = main.params[ 'CTRL' ][ 'ip5' ]
81 ONOS5Port = main.params[ 'CTRL' ][ 'port5' ]
82 ONOS6Ip = main.params[ 'CTRL' ][ 'ip6' ]
83 ONOS6Port = main.params[ 'CTRL' ][ 'port6' ]
84 ONOS7Ip = main.params[ 'CTRL' ][ 'ip7' ]
85 ONOS7Port = main.params[ 'CTRL' ][ 'port7' ]
86 numControllers = int( main.params[ 'num_controllers' ] )
Jon Hallb1290e82014-11-18 16:17:48 -050087
Jon Hall6aec96b2015-01-19 14:49:31 -080088 main.step( "Applying cell variable to environment" )
Jon Hall8f89dda2015-01-22 16:03:33 -080089 cellResult = main.ONOSbench.setCell( cellName )
90 verifyResult = main.ONOSbench.verifyCell()
Jon Hall368769f2014-11-19 15:43:35 -080091
Jon Hall6aec96b2015-01-19 14:49:31 -080092 # FIXME:this is short term fix
93 main.log.report( "Removing raft logs" )
Jon Hall8f89dda2015-01-22 16:03:33 -080094 main.ONOSbench.onosRemoveRaftLogs()
Jon Hall6aec96b2015-01-19 14:49:31 -080095 main.log.report( "Uninstalling ONOS" )
Jon Hall8f89dda2015-01-22 16:03:33 -080096 main.ONOSbench.onosUninstall( ONOS1Ip )
97 main.ONOSbench.onosUninstall( ONOS2Ip )
98 main.ONOSbench.onosUninstall( ONOS3Ip )
99 main.ONOSbench.onosUninstall( ONOS4Ip )
100 main.ONOSbench.onosUninstall( ONOS5Ip )
101 main.ONOSbench.onosUninstall( ONOS6Ip )
102 main.ONOSbench.onosUninstall( ONOS7Ip )
Jon Hallb1290e82014-11-18 16:17:48 -0500103
Jon Hall8f89dda2015-01-22 16:03:33 -0800104 cleanInstallResult = main.TRUE
105 gitPullResult = main.TRUE
Jon Hallb1290e82014-11-18 16:17:48 -0500106
Jon Hall97f31752015-02-04 12:01:04 -0800107 main.step( "Starting Mininet" )
108 main.Mininet1.startNet( )
109
Jon Hall6aec96b2015-01-19 14:49:31 -0800110 main.step( "Compiling the latest version of ONOS" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800111 if PULLCODE:
Jon Hall6aec96b2015-01-19 14:49:31 -0800112 # TODO Configure branch in params
113 main.step( "Git checkout and pull master" )
Jon Hall529a37f2015-01-28 10:02:00 -0800114 main.ONOSbench.gitCheckout( gitBranch )
Jon Hall8f89dda2015-01-22 16:03:33 -0800115 gitPullResult = main.ONOSbench.gitPull()
Jon Hallb1290e82014-11-18 16:17:48 -0500116
Jon Hall6aec96b2015-01-19 14:49:31 -0800117 main.step( "Using mvn clean & install" )
Jon Hall529a37f2015-01-28 10:02:00 -0800118 cleanInstallResult = main.ONOSbench.cleanInstall()
119 else:
120 main.log.warn( "Did not pull new code so skipping mvn " +
121 "clean install" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800122 main.ONOSbench.getVersion( report=True )
Jon Hallb1290e82014-11-18 16:17:48 -0500123
Jon Hall6aec96b2015-01-19 14:49:31 -0800124 main.step( "Creating ONOS package" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800125 packageResult = main.ONOSbench.onosPackage()
Jon Hallb1290e82014-11-18 16:17:48 -0500126
Jon Hall6aec96b2015-01-19 14:49:31 -0800127 main.step( "Installing ONOS package" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800128 onos1InstallResult = main.ONOSbench.onosInstall( options="-f",
129 node=ONOS1Ip )
130 onos2InstallResult = main.ONOSbench.onosInstall( options="-f",
131 node=ONOS2Ip )
132 onos3InstallResult = main.ONOSbench.onosInstall( options="-f",
133 node=ONOS3Ip )
134 onos4InstallResult = main.ONOSbench.onosInstall( options="-f",
135 node=ONOS4Ip )
136 onos5InstallResult = main.ONOSbench.onosInstall( options="-f",
137 node=ONOS5Ip )
138 onos6InstallResult = main.ONOSbench.onosInstall( options="-f",
139 node=ONOS6Ip )
140 onos7InstallResult = main.ONOSbench.onosInstall( options="-f",
141 node=ONOS7Ip )
142 onosInstallResult = onos1InstallResult and onos2InstallResult\
143 and onos3InstallResult and onos4InstallResult\
144 and onos5InstallResult and onos6InstallResult\
145 and onos7InstallResult
Jon Hallb1290e82014-11-18 16:17:48 -0500146
Jon Hall6aec96b2015-01-19 14:49:31 -0800147 main.step( "Checking if ONOS is up yet" )
148 # TODO check bundle:list?
149 for i in range( 2 ):
Jon Hall8f89dda2015-01-22 16:03:33 -0800150 onos1Isup = main.ONOSbench.isup( ONOS1Ip )
151 if not onos1Isup:
Jon Hall6aec96b2015-01-19 14:49:31 -0800152 main.log.report( "ONOS1 didn't start!" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800153 onos2Isup = main.ONOSbench.isup( ONOS2Ip )
154 if not onos2Isup:
Jon Hall6aec96b2015-01-19 14:49:31 -0800155 main.log.report( "ONOS2 didn't start!" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800156 onos3Isup = main.ONOSbench.isup( ONOS3Ip )
157 if not onos3Isup:
Jon Hall6aec96b2015-01-19 14:49:31 -0800158 main.log.report( "ONOS3 didn't start!" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800159 onos4Isup = main.ONOSbench.isup( ONOS4Ip )
160 if not onos4Isup:
Jon Hall6aec96b2015-01-19 14:49:31 -0800161 main.log.report( "ONOS4 didn't start!" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800162 onos5Isup = main.ONOSbench.isup( ONOS5Ip )
163 if not onos5Isup:
Jon Hall6aec96b2015-01-19 14:49:31 -0800164 main.log.report( "ONOS5 didn't start!" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800165 onos6Isup = main.ONOSbench.isup( ONOS6Ip )
166 if not onos6Isup:
Jon Hall6aec96b2015-01-19 14:49:31 -0800167 main.log.report( "ONOS6 didn't start!" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800168 onos7Isup = main.ONOSbench.isup( ONOS7Ip )
169 if not onos7Isup:
Jon Hall6aec96b2015-01-19 14:49:31 -0800170 main.log.report( "ONOS7 didn't start!" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800171 onosIsupResult = onos1Isup and onos2Isup and onos3Isup\
172 and onos4Isup and onos5Isup and onos6Isup and onos7Isup
173 if onosIsupResult == main.TRUE:
Jon Hallffb386d2014-11-21 13:43:38 -0800174 break
Jon Hallb1290e82014-11-18 16:17:48 -0500175
Jon Hall8f89dda2015-01-22 16:03:33 -0800176 cliResult1 = main.ONOScli1.startOnosCli( ONOS1Ip )
177 cliResult2 = main.ONOScli2.startOnosCli( ONOS2Ip )
178 cliResult3 = main.ONOScli3.startOnosCli( ONOS3Ip )
179 cliResult4 = main.ONOScli4.startOnosCli( ONOS4Ip )
180 cliResult5 = main.ONOScli5.startOnosCli( ONOS5Ip )
181 cliResult6 = main.ONOScli6.startOnosCli( ONOS6Ip )
182 cliResult7 = main.ONOScli7.startOnosCli( ONOS7Ip )
183 cliResults = cliResult1 and cliResult2 and cliResult3 and\
184 cliResult4 and cliResult5 and cliResult6 and cliResult7
Jon Hallb1290e82014-11-18 16:17:48 -0500185
Jon Hall6aec96b2015-01-19 14:49:31 -0800186 main.step( "Start Packet Capture MN" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800187 main.Mininet2.startTcpdump(
Jon Hall6aec96b2015-01-19 14:49:31 -0800188 str( main.params[ 'MNtcpdump' ][ 'folder' ] ) + str( main.TEST )
189 + "-MN.pcap",
190 intf=main.params[ 'MNtcpdump' ][ 'intf' ],
191 port=main.params[ 'MNtcpdump' ][ 'port' ] )
Jon Hallb1290e82014-11-18 16:17:48 -0500192
Jon Hall8f89dda2015-01-22 16:03:33 -0800193 case1Result = ( cleanInstallResult and packageResult and
194 cellResult and verifyResult and onosInstallResult
195 and onosIsupResult and cliResults )
Jon Hallb1290e82014-11-18 16:17:48 -0500196
Jon Hall8f89dda2015-01-22 16:03:33 -0800197 utilities.assert_equals( expect=main.TRUE, actual=case1Result,
198 onpass="Test startup successful",
199 onfail="Test startup NOT successful" )
Jon Hallb1290e82014-11-18 16:17:48 -0500200
Jon Hall8f89dda2015-01-22 16:03:33 -0800201 if case1Result == main.FALSE:
Jon Hallffb386d2014-11-21 13:43:38 -0800202 main.cleanup()
203 main.exit()
Jon Hallb1290e82014-11-18 16:17:48 -0500204
Jon Hall6aec96b2015-01-19 14:49:31 -0800205 def CASE2( self, main ):
206 """
Jon Hallb1290e82014-11-18 16:17:48 -0500207 Assign mastership to controllers
Jon Hall6aec96b2015-01-19 14:49:31 -0800208 """
Jon Hallb1290e82014-11-18 16:17:48 -0500209 import re
210
Jon Hall6aec96b2015-01-19 14:49:31 -0800211 main.log.report( "Assigning switches to controllers" )
212 main.case( "Assigning Controllers" )
213 main.step( "Assign switches to controllers" )
Jon Hallb1290e82014-11-18 16:17:48 -0500214
Jon Hall6aec96b2015-01-19 14:49:31 -0800215 for i in range( 1, 29 ):
Jon Hall8f89dda2015-01-22 16:03:33 -0800216 main.Mininet1.assignSwController(
Jon Hall6aec96b2015-01-19 14:49:31 -0800217 sw=str( i ),
Jon Hall8f89dda2015-01-22 16:03:33 -0800218 count=numControllers,
219 ip1=ONOS1Ip, port1=ONOS1Port,
220 ip2=ONOS2Ip, port2=ONOS2Port,
221 ip3=ONOS3Ip, port3=ONOS3Port,
222 ip4=ONOS4Ip, port4=ONOS4Port,
223 ip5=ONOS5Ip, port5=ONOS5Port,
224 ip6=ONOS6Ip, port6=ONOS6Port,
225 ip7=ONOS7Ip, port7=ONOS7Port )
Jon Hallb1290e82014-11-18 16:17:48 -0500226
Jon Hall8f89dda2015-01-22 16:03:33 -0800227 mastershipCheck = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800228 for i in range( 1, 29 ):
Jon Hall8f89dda2015-01-22 16:03:33 -0800229 response = main.Mininet1.getSwController( "s" + str( i ) )
Jon Hallffb386d2014-11-21 13:43:38 -0800230 try:
Jon Hall6aec96b2015-01-19 14:49:31 -0800231 main.log.info( str( response ) )
Jon Hallffb386d2014-11-21 13:43:38 -0800232 except:
Jon Hall6aec96b2015-01-19 14:49:31 -0800233 main.log.info( repr( response ) )
Jon Hall8f89dda2015-01-22 16:03:33 -0800234 if re.search( "tcp:" + ONOS1Ip, response )\
235 and re.search( "tcp:" + ONOS2Ip, response )\
236 and re.search( "tcp:" + ONOS3Ip, response )\
237 and re.search( "tcp:" + ONOS4Ip, response )\
238 and re.search( "tcp:" + ONOS5Ip, response )\
239 and re.search( "tcp:" + ONOS6Ip, response )\
240 and re.search( "tcp:" + ONOS7Ip, response ):
241 mastershipCheck = mastershipCheck and main.TRUE
Jon Hallb1290e82014-11-18 16:17:48 -0500242 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800243 mastershipCheck = main.FALSE
244 if mastershipCheck == main.TRUE:
Jon Hall6aec96b2015-01-19 14:49:31 -0800245 main.log.report( "Switch mastership assigned correctly" )
246 utilities.assert_equals(
247 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800248 actual=mastershipCheck,
Jon Hall6aec96b2015-01-19 14:49:31 -0800249 onpass="Switch mastership assigned correctly",
250 onfail="Switches not assigned correctly to controllers" )
Jon Hallb1290e82014-11-18 16:17:48 -0500251
Jon Hall6aec96b2015-01-19 14:49:31 -0800252 # Manually assign mastership to the controller we want
Jon Hall8f89dda2015-01-22 16:03:33 -0800253 roleCall = main.TRUE
254 roleCheck = main.TRUE
Jon Hall94fd0472014-12-08 11:52:42 -0800255
Jon Hall6aec96b2015-01-19 14:49:31 -0800256 # Assign switch
Jon Hall8f89dda2015-01-22 16:03:33 -0800257 deviceId = main.ONOScli1.getDevice( "1000" ).get( 'id' )
258 roleCall = roleCall and main.ONOScli1.deviceRole(
259 deviceId,
260 ONOS1Ip )
Jon Hall6aec96b2015-01-19 14:49:31 -0800261 # Check assignment
Jon Hall8f89dda2015-01-22 16:03:33 -0800262 if ONOS1Ip in main.ONOScli1.getRole( deviceId ).get( 'master' ):
263 roleCheck = roleCheck and main.TRUE
Jon Hall94fd0472014-12-08 11:52:42 -0800264 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800265 roleCheck = roleCheck and main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -0800266
Jon Hall6aec96b2015-01-19 14:49:31 -0800267 # Assign switch
Jon Hall8f89dda2015-01-22 16:03:33 -0800268 deviceId = main.ONOScli1.getDevice( "2800" ).get( 'id' )
269 roleCall = roleCall and main.ONOScli1.deviceRole(
270 deviceId,
271 ONOS1Ip )
Jon Hall6aec96b2015-01-19 14:49:31 -0800272 # Check assignment
Jon Hall8f89dda2015-01-22 16:03:33 -0800273 if ONOS1Ip in main.ONOScli1.getRole( deviceId ).get( 'master' ):
274 roleCheck = roleCheck and main.TRUE
Jon Hall94fd0472014-12-08 11:52:42 -0800275 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800276 roleCheck = roleCheck and main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -0800277
Jon Hall6aec96b2015-01-19 14:49:31 -0800278 # Assign switch
Jon Hall8f89dda2015-01-22 16:03:33 -0800279 deviceId = main.ONOScli1.getDevice( "2000" ).get( 'id' )
280 roleCall = roleCall and main.ONOScli1.deviceRole(
281 deviceId,
282 ONOS2Ip )
Jon Hall6aec96b2015-01-19 14:49:31 -0800283 # Check assignment
Jon Hall8f89dda2015-01-22 16:03:33 -0800284 if ONOS2Ip in main.ONOScli1.getRole( deviceId ).get( 'master' ):
285 roleCheck = roleCheck and main.TRUE
Jon Hall94fd0472014-12-08 11:52:42 -0800286 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800287 roleCheck = roleCheck and main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -0800288
Jon Hall6aec96b2015-01-19 14:49:31 -0800289 # Assign switch
Jon Hall8f89dda2015-01-22 16:03:33 -0800290 deviceId = main.ONOScli1.getDevice( "3000" ).get( 'id' )
291 roleCall = roleCall and main.ONOScli1.deviceRole(
292 deviceId,
293 ONOS2Ip )
Jon Hall6aec96b2015-01-19 14:49:31 -0800294 # Check assignment
Jon Hall8f89dda2015-01-22 16:03:33 -0800295 if ONOS2Ip in main.ONOScli1.getRole( deviceId ).get( 'master' ):
296 roleCheck = roleCheck and main.TRUE
Jon Hall94fd0472014-12-08 11:52:42 -0800297 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800298 roleCheck = roleCheck and main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -0800299
Jon Hall6aec96b2015-01-19 14:49:31 -0800300 # Assign switch
Jon Hall8f89dda2015-01-22 16:03:33 -0800301 deviceId = main.ONOScli1.getDevice( "5000" ).get( 'id' )
302 roleCall = roleCall and main.ONOScli1.deviceRole(
303 deviceId,
304 ONOS3Ip )
Jon Hall6aec96b2015-01-19 14:49:31 -0800305 # Check assignment
Jon Hall8f89dda2015-01-22 16:03:33 -0800306 if ONOS3Ip in main.ONOScli1.getRole( deviceId ).get( 'master' ):
307 roleCheck = roleCheck and main.TRUE
Jon Hall94fd0472014-12-08 11:52:42 -0800308 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800309 roleCheck = roleCheck and main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -0800310
Jon Hall6aec96b2015-01-19 14:49:31 -0800311 # Assign switch
Jon Hall8f89dda2015-01-22 16:03:33 -0800312 deviceId = main.ONOScli1.getDevice( "6000" ).get( 'id' )
313 roleCall = roleCall and main.ONOScli1.deviceRole(
314 deviceId,
315 ONOS3Ip )
Jon Hall6aec96b2015-01-19 14:49:31 -0800316 # Check assignment
Jon Hall8f89dda2015-01-22 16:03:33 -0800317 if ONOS3Ip in main.ONOScli1.getRole( deviceId ).get( 'master' ):
318 roleCheck = roleCheck and main.TRUE
Jon Hall94fd0472014-12-08 11:52:42 -0800319 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800320 roleCheck = roleCheck and main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -0800321
Jon Hall6aec96b2015-01-19 14:49:31 -0800322 # Assign switch
Jon Hall8f89dda2015-01-22 16:03:33 -0800323 deviceId = main.ONOScli1.getDevice( "3004" ).get( 'id' )
324 roleCall = roleCall and main.ONOScli1.deviceRole(
325 deviceId,
326 ONOS4Ip )
Jon Hall6aec96b2015-01-19 14:49:31 -0800327 # Check assignment
Jon Hall8f89dda2015-01-22 16:03:33 -0800328 if ONOS4Ip in main.ONOScli1.getRole( deviceId ).get( 'master' ):
329 roleCheck = roleCheck and main.TRUE
Jon Hall94fd0472014-12-08 11:52:42 -0800330 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800331 roleCheck = roleCheck and main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -0800332
Jon Hall6aec96b2015-01-19 14:49:31 -0800333 for i in range( 8, 18 ):
334 dpid = '3' + str( i ).zfill( 3 )
Jon Hall8f89dda2015-01-22 16:03:33 -0800335 deviceId = main.ONOScli1.getDevice( dpid ).get( 'id' )
336 roleCall = roleCall and main.ONOScli1.deviceRole(
337 deviceId,
338 ONOS5Ip )
Jon Hall6aec96b2015-01-19 14:49:31 -0800339 # Check assignment
Jon Hall8f89dda2015-01-22 16:03:33 -0800340 if ONOS5Ip in main.ONOScli1.getRole( deviceId ).get( 'master' ):
341 roleCheck = roleCheck and main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800342 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800343 roleCheck = roleCheck and main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -0800344
Jon Hall8f89dda2015-01-22 16:03:33 -0800345 deviceId = main.ONOScli1.getDevice( "6007" ).get( 'id' )
346 roleCall = roleCall and main.ONOScli1.deviceRole(
347 deviceId,
348 ONOS6Ip )
Jon Hall6aec96b2015-01-19 14:49:31 -0800349 # Check assignment
Jon Hall8f89dda2015-01-22 16:03:33 -0800350 if ONOS6Ip in main.ONOScli1.getRole( deviceId ).get( 'master' ):
351 roleCheck = roleCheck and main.TRUE
Jon Hall94fd0472014-12-08 11:52:42 -0800352 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800353 roleCheck = roleCheck and main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -0800354
Jon Hall6aec96b2015-01-19 14:49:31 -0800355 for i in range( 18, 28 ):
356 dpid = '6' + str( i ).zfill( 3 )
Jon Hall8f89dda2015-01-22 16:03:33 -0800357 deviceId = main.ONOScli1.getDevice( dpid ).get( 'id' )
358 roleCall = roleCall and main.ONOScli1.deviceRole(
359 deviceId,
360 ONOS7Ip )
Jon Hall6aec96b2015-01-19 14:49:31 -0800361 # Check assignment
Jon Hall8f89dda2015-01-22 16:03:33 -0800362 if ONOS7Ip in main.ONOScli1.getRole( deviceId ).get( 'master' ):
363 roleCheck = roleCheck and main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800364 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800365 roleCheck = roleCheck and main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -0800366
Jon Hall6aec96b2015-01-19 14:49:31 -0800367 utilities.assert_equals(
368 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800369 actual=roleCall,
Jon Hall6aec96b2015-01-19 14:49:31 -0800370 onpass="Re-assigned switch mastership to designated controller",
Jon Hall8f89dda2015-01-22 16:03:33 -0800371 onfail="Something wrong with deviceRole calls" )
Jon Hall94fd0472014-12-08 11:52:42 -0800372
Jon Hall6aec96b2015-01-19 14:49:31 -0800373 utilities.assert_equals(
374 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800375 actual=roleCheck,
Jon Hall6aec96b2015-01-19 14:49:31 -0800376 onpass="Switches were successfully reassigned to designated " +
377 "controller",
378 onfail="Switches were not successfully reassigned" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800379 mastershipCheck = mastershipCheck and roleCall and roleCheck
380 utilities.assert_equals( expect=main.TRUE, actual=mastershipCheck,
Jon Hall6aec96b2015-01-19 14:49:31 -0800381 onpass="Switch mastership correctly assigned",
382 onfail="Error in (re)assigning switch" +
Jon Hall8f89dda2015-01-22 16:03:33 -0800383 " mastership" )
Jon Hallb1290e82014-11-18 16:17:48 -0500384
Jon Hall6aec96b2015-01-19 14:49:31 -0800385 def CASE3( self, main ):
Jon Hallb1290e82014-11-18 16:17:48 -0500386 """
387 Assign intents
Jon Hallb1290e82014-11-18 16:17:48 -0500388 """
389 import time
Jon Hall6aec96b2015-01-19 14:49:31 -0800390 main.log.report( "Adding host intents" )
391 main.case( "Adding host Intents" )
Jon Hallb1290e82014-11-18 16:17:48 -0500392
Jon Hall8f89dda2015-01-22 16:03:33 -0800393 main.step( "Discovering Hosts( Via pingall for now )" )
Jon Hall6aec96b2015-01-19 14:49:31 -0800394 # FIXME: Once we have a host discovery mechanism, use that instead
Jon Hallb1290e82014-11-18 16:17:48 -0500395
Jon Hall6aec96b2015-01-19 14:49:31 -0800396 # install onos-app-fwd
397 main.log.info( "Install reactive forwarding app" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800398 main.ONOScli1.featureInstall( "onos-app-fwd" )
399 main.ONOScli2.featureInstall( "onos-app-fwd" )
400 main.ONOScli3.featureInstall( "onos-app-fwd" )
401 main.ONOScli4.featureInstall( "onos-app-fwd" )
402 main.ONOScli5.featureInstall( "onos-app-fwd" )
403 main.ONOScli6.featureInstall( "onos-app-fwd" )
404 main.ONOScli7.featureInstall( "onos-app-fwd" )
Jon Hall94fd0472014-12-08 11:52:42 -0800405
Jon Hall6aec96b2015-01-19 14:49:31 -0800406 # REACTIVE FWD test
Jon Hall8f89dda2015-01-22 16:03:33 -0800407 pingResult = main.FALSE
Jon Hallb1290e82014-11-18 16:17:48 -0500408 time1 = time.time()
Jon Hall8f89dda2015-01-22 16:03:33 -0800409 pingResult = main.Mininet1.pingall()
Jon Hall529a37f2015-01-28 10:02:00 -0800410 utilities.assert_equals(
411 expect=main.TRUE,
412 actual=pingResult,
413 onpass="Reactive Pingall test passed",
414 onfail="Reactive Pingall failed, one or more ping pairs failed" )
Jon Hallb1290e82014-11-18 16:17:48 -0500415 time2 = time.time()
Jon Hall6aec96b2015-01-19 14:49:31 -0800416 main.log.info( "Time for pingall: %2f seconds" % ( time2 - time1 ) )
Jon Hallb1290e82014-11-18 16:17:48 -0500417
Jon Hall6aec96b2015-01-19 14:49:31 -0800418 # uninstall onos-app-fwd
419 main.log.info( "Uninstall reactive forwarding app" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800420 main.ONOScli1.featureUninstall( "onos-app-fwd" )
421 main.ONOScli2.featureUninstall( "onos-app-fwd" )
422 main.ONOScli3.featureUninstall( "onos-app-fwd" )
423 main.ONOScli4.featureUninstall( "onos-app-fwd" )
424 main.ONOScli5.featureUninstall( "onos-app-fwd" )
425 main.ONOScli6.featureUninstall( "onos-app-fwd" )
426 main.ONOScli7.featureUninstall( "onos-app-fwd" )
Jon Hall6aec96b2015-01-19 14:49:31 -0800427 # timeout for fwd flows
428 time.sleep( 10 )
Jon Hallb1290e82014-11-18 16:17:48 -0500429
Jon Hall6aec96b2015-01-19 14:49:31 -0800430 main.step( "Add host intents" )
431 # TODO: move the host numbers to params
Jon Hall8f89dda2015-01-22 16:03:33 -0800432 intentAddResult = True
Jon Hall6aec96b2015-01-19 14:49:31 -0800433 for i in range( 8, 18 ):
434 main.log.info( "Adding host intent between h" + str( i ) +
435 " and h" + str( i + 10 ) )
436 host1 = "00:00:00:00:00:" + \
437 str( hex( i )[ 2: ] ).zfill( 2 ).upper()
438 host2 = "00:00:00:00:00:" + \
439 str( hex( i + 10 )[ 2: ] ).zfill( 2 ).upper()
Jon Hall8f89dda2015-01-22 16:03:33 -0800440 host1Id = main.ONOScli1.getHost( host1 )[ 'id' ]
441 host2Id = main.ONOScli1.getHost( host2 )[ 'id' ]
Jon Hall6aec96b2015-01-19 14:49:31 -0800442 # NOTE: get host can return None
Jon Hall8f89dda2015-01-22 16:03:33 -0800443 if host1Id and host2Id:
444 tmpResult = main.ONOScli1.addHostIntent(
445 host1Id,
446 host2Id )
Jon Hall669173b2014-12-17 11:36:30 -0800447 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800448 main.log.error( "Error, getHost() failed" )
449 tmpResult = main.FALSE
450 intentAddResult = bool( pingResult and intentAddResult
451 and tmpResult )
452 # TODO Check that intents were added?
Jon Hall6aec96b2015-01-19 14:49:31 -0800453 utilities.assert_equals(
454 expect=True,
Jon Hall8f89dda2015-01-22 16:03:33 -0800455 actual=intentAddResult,
456 onpass="Pushed host intents to ONOS",
457 onfail="Error in pushing host intents to ONOS" )
Jon Hall6aec96b2015-01-19 14:49:31 -0800458 # TODO Check if intents all exist in datastore
Jon Hallb1290e82014-11-18 16:17:48 -0500459
Jon Hall6aec96b2015-01-19 14:49:31 -0800460 def CASE4( self, main ):
Jon Hallb1290e82014-11-18 16:17:48 -0500461 """
462 Ping across added host intents
463 """
Jon Hall368769f2014-11-19 15:43:35 -0800464 description = " Ping across added host intents"
Jon Hall6aec96b2015-01-19 14:49:31 -0800465 main.log.report( description )
466 main.case( description )
Jon Hall8f89dda2015-01-22 16:03:33 -0800467 PingResult = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800468 for i in range( 8, 18 ):
469 ping = main.Mininet1.pingHost(
470 src="h" + str( i ), target="h" + str( i + 10 ) )
Jon Hall8f89dda2015-01-22 16:03:33 -0800471 PingResult = PingResult and ping
Jon Hall6aec96b2015-01-19 14:49:31 -0800472 if ping == main.FALSE:
473 main.log.warn( "Ping failed between h" + str( i ) +
474 " and h" + str( i + 10 ) )
475 elif ping == main.TRUE:
476 main.log.info( "Ping test passed!" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800477 PingResult = main.TRUE
478 if PingResult == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -0800479 main.log.report(
480 "Intents have not been installed correctly, pings failed." )
Jon Hall529a37f2015-01-28 10:02:00 -0800481 #TODO: pretty print
482 main.log.warn( "ONSO1 intents: " )
483 main.log.warn( json.dumps( json.loads( main.ONOScli1.intents() ),
484 sort_keys=True,
485 indent=4,
486 separators=( ',', ': ' ) ) )
Jon Hall8f89dda2015-01-22 16:03:33 -0800487 if PingResult == main.TRUE:
Jon Hall6aec96b2015-01-19 14:49:31 -0800488 main.log.report(
489 "Intents have been installed correctly and verified by pings" )
490 utilities.assert_equals(
491 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800492 actual=PingResult,
Jon Hall6aec96b2015-01-19 14:49:31 -0800493 onpass="Intents have been installed correctly and pings work",
494 onfail="Intents have not been installed correctly, pings failed." )
Jon Hallb1290e82014-11-18 16:17:48 -0500495
Jon Hall6aec96b2015-01-19 14:49:31 -0800496 def CASE5( self, main ):
497 """
Jon Hallb1290e82014-11-18 16:17:48 -0500498 Reading state of ONOS
Jon Hall6aec96b2015-01-19 14:49:31 -0800499 """
Jon Hallb1290e82014-11-18 16:17:48 -0500500 import json
Jon Hall6aec96b2015-01-19 14:49:31 -0800501 # assumes that sts is already in you PYTHONPATH
502 from sts.topology.teston_topology import TestONTopology
Jon Hallb1290e82014-11-18 16:17:48 -0500503
Jon Hall6aec96b2015-01-19 14:49:31 -0800504 main.log.report( "Setting up and gathering data for current state" )
505 main.case( "Setting up and gathering data for current state" )
506 # The general idea for this test case is to pull the state of
507 # ( intents,flows, topology,... ) from each ONOS node
508 # We can then compare them with eachother and also with past states
Jon Hallb1290e82014-11-18 16:17:48 -0500509
Jon Hall6aec96b2015-01-19 14:49:31 -0800510 main.step( "Get the Mastership of each switch from each controller" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800511 global mastershipState
512 mastershipState = []
Jon Hall94fd0472014-12-08 11:52:42 -0800513
Jon Hall6aec96b2015-01-19 14:49:31 -0800514 # Assert that each device has a master
Jon Hall8f89dda2015-01-22 16:03:33 -0800515 ONOS1MasterNotNull = main.ONOScli1.rolesNotNull()
516 ONOS2MasterNotNull = main.ONOScli2.rolesNotNull()
517 ONOS3MasterNotNull = main.ONOScli3.rolesNotNull()
518 ONOS4MasterNotNull = main.ONOScli4.rolesNotNull()
519 ONOS5MasterNotNull = main.ONOScli5.rolesNotNull()
520 ONOS6MasterNotNull = main.ONOScli6.rolesNotNull()
521 ONOS7MasterNotNull = main.ONOScli7.rolesNotNull()
522 rolesNotNull = ONOS1MasterNotNull and ONOS2MasterNotNull and\
523 ONOS3MasterNotNull and ONOS4MasterNotNull and\
524 ONOS5MasterNotNull and ONOS6MasterNotNull and\
525 ONOS7MasterNotNull
Jon Hall6aec96b2015-01-19 14:49:31 -0800526 utilities.assert_equals(
527 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800528 actual=rolesNotNull,
Jon Hall6aec96b2015-01-19 14:49:31 -0800529 onpass="Each device has a master",
530 onfail="Some devices don't have a master assigned" )
Jon Hall94fd0472014-12-08 11:52:42 -0800531
Jon Hall8f89dda2015-01-22 16:03:33 -0800532 ONOS1Mastership = main.ONOScli1.roles()
533 ONOS2Mastership = main.ONOScli2.roles()
534 ONOS3Mastership = main.ONOScli3.roles()
535 ONOS4Mastership = main.ONOScli4.roles()
536 ONOS5Mastership = main.ONOScli5.roles()
537 ONOS6Mastership = main.ONOScli6.roles()
538 ONOS7Mastership = main.ONOScli7.roles()
539 # print json.dumps( json.loads( ONOS1Mastership ), sort_keys=True,
Jon Hall6aec96b2015-01-19 14:49:31 -0800540 # indent=4, separators=( ',', ': ' ) )
Jon Hall8f89dda2015-01-22 16:03:33 -0800541 if "Error" in ONOS1Mastership or not ONOS1Mastership\
542 or "Error" in ONOS2Mastership or not ONOS2Mastership\
543 or "Error" in ONOS3Mastership or not ONOS3Mastership\
544 or "Error" in ONOS4Mastership or not ONOS4Mastership\
545 or "Error" in ONOS5Mastership or not ONOS5Mastership\
546 or "Error" in ONOS6Mastership or not ONOS6Mastership\
547 or "Error" in ONOS7Mastership or not ONOS7Mastership:
Jon Hall6aec96b2015-01-19 14:49:31 -0800548 main.log.report( "Error in getting ONOS roles" )
549 main.log.warn(
550 "ONOS1 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800551 repr( ONOS1Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -0800552 main.log.warn(
553 "ONOS2 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800554 repr( ONOS2Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -0800555 main.log.warn(
556 "ONOS3 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800557 repr( ONOS3Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -0800558 main.log.warn(
559 "ONOS4 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800560 repr( ONOS4Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -0800561 main.log.warn(
562 "ONOS5 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800563 repr( ONOS5Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -0800564 main.log.warn(
565 "ONOS6 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800566 repr( ONOS6Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -0800567 main.log.warn(
568 "ONOS7 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800569 repr( ONOS7Mastership ) )
570 consistentMastership = main.FALSE
571 elif ONOS1Mastership == ONOS2Mastership\
572 and ONOS1Mastership == ONOS3Mastership\
573 and ONOS1Mastership == ONOS4Mastership\
574 and ONOS1Mastership == ONOS5Mastership\
575 and ONOS1Mastership == ONOS6Mastership\
576 and ONOS1Mastership == ONOS7Mastership:
577 mastershipState = ONOS1Mastership
578 consistentMastership = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800579 main.log.report(
580 "Switch roles are consistent across all ONOS nodes" )
Jon Hallb1290e82014-11-18 16:17:48 -0500581 else:
Jon Hall6aec96b2015-01-19 14:49:31 -0800582 main.log.warn(
583 "ONOS1 roles: ",
584 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800585 json.loads( ONOS1Mastership ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800586 sort_keys=True,
587 indent=4,
588 separators=(
589 ',',
590 ': ' ) ) )
591 main.log.warn(
592 "ONOS2 roles: ",
593 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800594 json.loads( ONOS2Mastership ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800595 sort_keys=True,
596 indent=4,
597 separators=(
598 ',',
599 ': ' ) ) )
600 main.log.warn(
601 "ONOS3 roles: ",
602 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800603 json.loads( ONOS3Mastership ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800604 sort_keys=True,
605 indent=4,
606 separators=(
607 ',',
608 ': ' ) ) )
609 main.log.warn(
610 "ONOS4 roles: ",
611 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800612 json.loads( ONOS4Mastership ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800613 sort_keys=True,
614 indent=4,
615 separators=(
616 ',',
617 ': ' ) ) )
618 main.log.warn(
619 "ONOS5 roles: ",
620 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800621 json.loads( ONOS5Mastership ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800622 sort_keys=True,
623 indent=4,
624 separators=(
625 ',',
626 ': ' ) ) )
627 main.log.warn(
628 "ONOS6 roles: ",
629 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800630 json.loads( ONOS6Mastership ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800631 sort_keys=True,
632 indent=4,
633 separators=(
634 ',',
635 ': ' ) ) )
636 main.log.warn(
637 "ONOS7 roles: ",
638 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800639 json.loads( ONOS7Mastership ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800640 sort_keys=True,
641 indent=4,
642 separators=(
643 ',',
644 ': ' ) ) )
Jon Hall8f89dda2015-01-22 16:03:33 -0800645 consistentMastership = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -0800646 utilities.assert_equals(
647 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800648 actual=consistentMastership,
Jon Hall6aec96b2015-01-19 14:49:31 -0800649 onpass="Switch roles are consistent across all ONOS nodes",
650 onfail="ONOS nodes have different views of switch roles" )
Jon Hallb1290e82014-11-18 16:17:48 -0500651
Jon Hall6aec96b2015-01-19 14:49:31 -0800652 main.step( "Get the intents from each controller" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800653 global intentState
654 intentState = []
655 ONOS1Intents = main.ONOScli1.intents( jsonFormat=True )
656 ONOS2Intents = main.ONOScli2.intents( jsonFormat=True )
657 ONOS3Intents = main.ONOScli3.intents( jsonFormat=True )
658 ONOS4Intents = main.ONOScli4.intents( jsonFormat=True )
659 ONOS5Intents = main.ONOScli5.intents( jsonFormat=True )
660 ONOS6Intents = main.ONOScli6.intents( jsonFormat=True )
661 ONOS7Intents = main.ONOScli7.intents( jsonFormat=True )
662 intentCheck = main.FALSE
663 if "Error" in ONOS1Intents or not ONOS1Intents\
664 or "Error" in ONOS2Intents or not ONOS2Intents\
665 or "Error" in ONOS3Intents or not ONOS3Intents\
666 or "Error" in ONOS4Intents or not ONOS4Intents\
667 or "Error" in ONOS5Intents or not ONOS5Intents\
668 or "Error" in ONOS6Intents or not ONOS6Intents\
669 or "Error" in ONOS7Intents or not ONOS7Intents:
Jon Hall6aec96b2015-01-19 14:49:31 -0800670 main.log.report( "Error in getting ONOS intents" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800671 main.log.warn( "ONOS1 intents response: " + repr( ONOS1Intents ) )
672 main.log.warn( "ONOS2 intents response: " + repr( ONOS2Intents ) )
673 main.log.warn( "ONOS3 intents response: " + repr( ONOS3Intents ) )
674 main.log.warn( "ONOS4 intents response: " + repr( ONOS4Intents ) )
675 main.log.warn( "ONOS5 intents response: " + repr( ONOS5Intents ) )
676 main.log.warn( "ONOS6 intents response: " + repr( ONOS6Intents ) )
677 main.log.warn( "ONOS7 intents response: " + repr( ONOS7Intents ) )
678 elif ONOS1Intents == ONOS2Intents\
679 and ONOS1Intents == ONOS3Intents\
680 and ONOS1Intents == ONOS4Intents\
681 and ONOS1Intents == ONOS5Intents\
682 and ONOS1Intents == ONOS6Intents\
683 and ONOS1Intents == ONOS7Intents:
684 intentState = ONOS1Intents
685 intentCheck = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800686 main.log.report( "Intents are consistent across all ONOS nodes" )
Jon Hallb1290e82014-11-18 16:17:48 -0500687 else:
Jon Hall6aec96b2015-01-19 14:49:31 -0800688 main.log.warn(
689 "ONOS1 intents: ",
690 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800691 json.loads( ONOS1Intents ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800692 sort_keys=True,
693 indent=4,
694 separators=(
695 ',',
696 ': ' ) ) )
697 main.log.warn(
698 "ONOS2 intents: ",
699 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800700 json.loads( ONOS2Intents ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800701 sort_keys=True,
702 indent=4,
703 separators=(
704 ',',
705 ': ' ) ) )
706 main.log.warn(
707 "ONOS3 intents: ",
708 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800709 json.loads( ONOS3Intents ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800710 sort_keys=True,
711 indent=4,
712 separators=(
713 ',',
714 ': ' ) ) )
715 main.log.warn(
716 "ONOS4 intents: ",
717 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800718 json.loads( ONOS4Intents ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800719 sort_keys=True,
720 indent=4,
721 separators=(
722 ',',
723 ': ' ) ) )
724 main.log.warn(
725 "ONOS5 intents: ",
726 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800727 json.loads( ONOS5Intents ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800728 sort_keys=True,
729 indent=4,
730 separators=(
731 ',',
732 ': ' ) ) )
733 main.log.warn(
734 "ONOS6 intents: ",
735 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800736 json.loads( ONOS6Intents ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800737 sort_keys=True,
738 indent=4,
739 separators=(
740 ',',
741 ': ' ) ) )
742 main.log.warn(
743 "ONOS7 intents: ",
744 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800745 json.loads( ONOS7Intents ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800746 sort_keys=True,
747 indent=4,
748 separators=(
749 ',',
750 ': ' ) ) )
751 utilities.assert_equals(
752 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800753 actual=intentCheck,
Jon Hall6aec96b2015-01-19 14:49:31 -0800754 onpass="Intents are consistent across all ONOS nodes",
755 onfail="ONOS nodes have different views of intents" )
Jon Hallb1290e82014-11-18 16:17:48 -0500756
Jon Hall6aec96b2015-01-19 14:49:31 -0800757 main.step( "Get the flows from each controller" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800758 global flowState
759 flowState = []
760 ONOS1Flows = main.ONOScli1.flows( jsonFormat=True )
761 ONOS2Flows = main.ONOScli2.flows( jsonFormat=True )
762 ONOS3Flows = main.ONOScli3.flows( jsonFormat=True )
763 ONOS4Flows = main.ONOScli4.flows( jsonFormat=True )
764 ONOS5Flows = main.ONOScli5.flows( jsonFormat=True )
765 ONOS6Flows = main.ONOScli6.flows( jsonFormat=True )
766 ONOS7Flows = main.ONOScli7.flows( jsonFormat=True )
767 ONOS1FlowsJson = json.loads( ONOS1Flows )
768 ONOS2FlowsJson = json.loads( ONOS2Flows )
769 ONOS3FlowsJson = json.loads( ONOS3Flows )
770 ONOS4FlowsJson = json.loads( ONOS4Flows )
771 ONOS5FlowsJson = json.loads( ONOS5Flows )
772 ONOS6FlowsJson = json.loads( ONOS6Flows )
773 ONOS7FlowsJson = json.loads( ONOS7Flows )
774 flowCheck = main.FALSE
775 if "Error" in ONOS1Flows or not ONOS1Flows\
776 or "Error" in ONOS2Flows or not ONOS2Flows\
777 or "Error" in ONOS3Flows or not ONOS3Flows\
778 or "Error" in ONOS4Flows or not ONOS4Flows\
779 or "Error" in ONOS5Flows or not ONOS5Flows\
780 or "Error" in ONOS6Flows or not ONOS6Flows\
781 or "Error" in ONOS7Flows or not ONOS7Flows:
Jon Hall6aec96b2015-01-19 14:49:31 -0800782 main.log.report( "Error in getting ONOS intents" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800783 main.log.warn( "ONOS1 flows repsponse: " + ONOS1Flows )
784 main.log.warn( "ONOS2 flows repsponse: " + ONOS2Flows )
785 main.log.warn( "ONOS3 flows repsponse: " + ONOS3Flows )
786 main.log.warn( "ONOS4 flows repsponse: " + ONOS4Flows )
787 main.log.warn( "ONOS5 flows repsponse: " + ONOS5Flows )
788 main.log.warn( "ONOS6 flows repsponse: " + ONOS6Flows )
789 main.log.warn( "ONOS7 flows repsponse: " + ONOS7Flows )
790 elif len( ONOS1FlowsJson ) == len( ONOS2FlowsJson )\
791 and len( ONOS1FlowsJson ) == len( ONOS3FlowsJson )\
792 and len( ONOS1FlowsJson ) == len( ONOS4FlowsJson )\
793 and len( ONOS1FlowsJson ) == len( ONOS5FlowsJson )\
794 and len( ONOS1FlowsJson ) == len( ONOS6FlowsJson )\
795 and len( ONOS1FlowsJson ) == len( ONOS7FlowsJson ):
Jon Hall6aec96b2015-01-19 14:49:31 -0800796 # TODO: Do a better check, maybe compare flows on switches?
Jon Hall8f89dda2015-01-22 16:03:33 -0800797 flowState = ONOS1Flows
798 flowCheck = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800799 main.log.report( "Flow count is consistent across all ONOS nodes" )
Jon Hallb1290e82014-11-18 16:17:48 -0500800 else:
Jon Hall6aec96b2015-01-19 14:49:31 -0800801 main.log.warn( "ONOS1 flows: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800802 json.dumps( ONOS1FlowsJson, sort_keys=True,
Jon Hall6aec96b2015-01-19 14:49:31 -0800803 indent=4, separators=( ',', ': ' ) ) )
804 main.log.warn( "ONOS2 flows: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800805 json.dumps( ONOS2FlowsJson, sort_keys=True,
Jon Hall6aec96b2015-01-19 14:49:31 -0800806 indent=4, separators=( ',', ': ' ) ) )
807 main.log.warn( "ONOS3 flows: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800808 json.dumps( ONOS3FlowsJson, sort_keys=True,
Jon Hall6aec96b2015-01-19 14:49:31 -0800809 indent=4, separators=( ',', ': ' ) ) )
810 main.log.warn( "ONOS4 flows: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800811 json.dumps( ONOS4FlowsJson, sort_keys=True,
Jon Hall6aec96b2015-01-19 14:49:31 -0800812 indent=4, separators=( ',', ': ' ) ) )
813 main.log.warn( "ONOS5 flows: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800814 json.dumps( ONOS5FlowsJson, sort_keys=True,
Jon Hall6aec96b2015-01-19 14:49:31 -0800815 indent=4, separators=( ',', ': ' ) ) )
816 main.log.warn( "ONOS6 flows: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800817 json.dumps( ONOS6FlowsJson, sort_keys=True,
Jon Hall6aec96b2015-01-19 14:49:31 -0800818 indent=4, separators=( ',', ': ' ) ) )
819 main.log.warn( "ONOS7 flows: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800820 json.dumps( ONOS7FlowsJson, sort_keys=True,
Jon Hall6aec96b2015-01-19 14:49:31 -0800821 indent=4, separators=( ',', ': ' ) ) )
822 utilities.assert_equals(
823 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800824 actual=flowCheck,
Jon Hall6aec96b2015-01-19 14:49:31 -0800825 onpass="The flow count is consistent across all ONOS nodes",
826 onfail="ONOS nodes have different flow counts" )
Jon Hallb1290e82014-11-18 16:17:48 -0500827
Jon Hall6aec96b2015-01-19 14:49:31 -0800828 main.step( "Get the OF Table entries" )
Jon Hallb1290e82014-11-18 16:17:48 -0500829 global flows
Jon Hall6aec96b2015-01-19 14:49:31 -0800830 flows = []
831 for i in range( 1, 29 ):
Jon Hall8f89dda2015-01-22 16:03:33 -0800832 flows.append( main.Mininet2.getFlowTable( 1.3, "s" + str( i ) ) )
Jon Hallb1290e82014-11-18 16:17:48 -0500833
Jon Hall6aec96b2015-01-19 14:49:31 -0800834 # TODO: Compare switch flow tables with ONOS flow tables
Jon Hallb1290e82014-11-18 16:17:48 -0500835
Jon Hall6aec96b2015-01-19 14:49:31 -0800836 main.step( "Start continuous pings" )
837 main.Mininet2.pingLong(
838 src=main.params[ 'PING' ][ 'source1' ],
839 target=main.params[ 'PING' ][ 'target1' ],
840 pingTime=500 )
841 main.Mininet2.pingLong(
842 src=main.params[ 'PING' ][ 'source2' ],
843 target=main.params[ 'PING' ][ 'target2' ],
844 pingTime=500 )
845 main.Mininet2.pingLong(
846 src=main.params[ 'PING' ][ 'source3' ],
847 target=main.params[ 'PING' ][ 'target3' ],
848 pingTime=500 )
849 main.Mininet2.pingLong(
850 src=main.params[ 'PING' ][ 'source4' ],
851 target=main.params[ 'PING' ][ 'target4' ],
852 pingTime=500 )
853 main.Mininet2.pingLong(
854 src=main.params[ 'PING' ][ 'source5' ],
855 target=main.params[ 'PING' ][ 'target5' ],
856 pingTime=500 )
857 main.Mininet2.pingLong(
858 src=main.params[ 'PING' ][ 'source6' ],
859 target=main.params[ 'PING' ][ 'target6' ],
860 pingTime=500 )
861 main.Mininet2.pingLong(
862 src=main.params[ 'PING' ][ 'source7' ],
863 target=main.params[ 'PING' ][ 'target7' ],
864 pingTime=500 )
865 main.Mininet2.pingLong(
866 src=main.params[ 'PING' ][ 'source8' ],
867 target=main.params[ 'PING' ][ 'target8' ],
868 pingTime=500 )
869 main.Mininet2.pingLong(
870 src=main.params[ 'PING' ][ 'source9' ],
871 target=main.params[ 'PING' ][ 'target9' ],
872 pingTime=500 )
873 main.Mininet2.pingLong(
874 src=main.params[ 'PING' ][ 'source10' ],
875 target=main.params[ 'PING' ][ 'target10' ],
876 pingTime=500 )
Jon Hallb1290e82014-11-18 16:17:48 -0500877
Jon Hall6aec96b2015-01-19 14:49:31 -0800878 main.step( "Create TestONTopology object" )
Jon Hallb1290e82014-11-18 16:17:48 -0500879 ctrls = []
880 count = 1
881 while True:
882 temp = ()
Jon Hall6aec96b2015-01-19 14:49:31 -0800883 if ( 'ip' + str( count ) ) in main.params[ 'CTRL' ]:
884 temp = temp + ( getattr( main, ( 'ONOS' + str( count ) ) ), )
885 temp = temp + ( "ONOS" + str( count ), )
886 temp = temp + ( main.params[ 'CTRL' ][ 'ip' + str( count ) ], )
887 temp = temp + \
888 ( eval( main.params[ 'CTRL' ][ 'port' + str( count ) ] ), )
889 ctrls.append( temp )
Jon Hallb1290e82014-11-18 16:17:48 -0500890 count = count + 1
891 else:
892 break
Jon Hall6aec96b2015-01-19 14:49:31 -0800893 MNTopo = TestONTopology(
894 main.Mininet1,
895 ctrls ) # can also add Intent API info for intent operations
Jon Hallb1290e82014-11-18 16:17:48 -0500896
Jon Hall6aec96b2015-01-19 14:49:31 -0800897 main.step( "Collecting topology information from ONOS" )
Jon Hallb1290e82014-11-18 16:17:48 -0500898 devices = []
899 devices.append( main.ONOScli1.devices() )
900 devices.append( main.ONOScli2.devices() )
901 devices.append( main.ONOScli3.devices() )
902 devices.append( main.ONOScli4.devices() )
903 devices.append( main.ONOScli5.devices() )
904 devices.append( main.ONOScli6.devices() )
905 devices.append( main.ONOScli7.devices() )
Jon Hallb1290e82014-11-18 16:17:48 -0500906 hosts = []
907 hosts.append( main.ONOScli1.hosts() )
908 hosts.append( main.ONOScli2.hosts() )
909 hosts.append( main.ONOScli3.hosts() )
910 hosts.append( main.ONOScli4.hosts() )
911 hosts.append( main.ONOScli5.hosts() )
912 hosts.append( main.ONOScli6.hosts() )
913 hosts.append( main.ONOScli7.hosts() )
Jon Hallb1290e82014-11-18 16:17:48 -0500914 ports = []
915 ports.append( main.ONOScli1.ports() )
916 ports.append( main.ONOScli2.ports() )
917 ports.append( main.ONOScli3.ports() )
918 ports.append( main.ONOScli4.ports() )
919 ports.append( main.ONOScli5.ports() )
920 ports.append( main.ONOScli6.ports() )
921 ports.append( main.ONOScli7.ports() )
922 links = []
923 links.append( main.ONOScli1.links() )
924 links.append( main.ONOScli2.links() )
925 links.append( main.ONOScli3.links() )
926 links.append( main.ONOScli4.links() )
927 links.append( main.ONOScli5.links() )
928 links.append( main.ONOScli6.links() )
929 links.append( main.ONOScli7.links() )
Jon Hall94fd0472014-12-08 11:52:42 -0800930 clusters = []
931 clusters.append( main.ONOScli1.clusters() )
932 clusters.append( main.ONOScli2.clusters() )
933 clusters.append( main.ONOScli3.clusters() )
934 clusters.append( main.ONOScli4.clusters() )
935 clusters.append( main.ONOScli5.clusters() )
936 clusters.append( main.ONOScli6.clusters() )
937 clusters.append( main.ONOScli7.clusters() )
Jon Hall529a37f2015-01-28 10:02:00 -0800938 # Compare json objects for hosts and dataplane clusters
Jon Hall94fd0472014-12-08 11:52:42 -0800939
Jon Hall6aec96b2015-01-19 14:49:31 -0800940 # hosts
Jon Hall8f89dda2015-01-22 16:03:33 -0800941 consistentHostsResult = main.TRUE
Jon Hall94fd0472014-12-08 11:52:42 -0800942 for controller in range( len( hosts ) ):
Jon Hall8f89dda2015-01-22 16:03:33 -0800943 controllerStr = str( controller + 1 )
Jon Hall6aec96b2015-01-19 14:49:31 -0800944 if "Error" not in hosts[ controller ]:
945 if hosts[ controller ] == hosts[ 0 ]:
Jon Hall94fd0472014-12-08 11:52:42 -0800946 continue
Jon Hall6aec96b2015-01-19 14:49:31 -0800947 else: # hosts not consistent
948 main.log.report( "hosts from ONOS" +
Jon Hall8f89dda2015-01-22 16:03:33 -0800949 controllerStr +
Jon Hall6aec96b2015-01-19 14:49:31 -0800950 " is inconsistent with ONOS1" )
951 main.log.warn( repr( hosts[ controller ] ) )
Jon Hall8f89dda2015-01-22 16:03:33 -0800952 consistentHostsResult = main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -0800953
954 else:
Jon Hall6aec96b2015-01-19 14:49:31 -0800955 main.log.report( "Error in getting ONOS hosts from ONOS" +
Jon Hall8f89dda2015-01-22 16:03:33 -0800956 controllerStr )
957 consistentHostsResult = main.FALSE
958 main.log.warn( "ONOS" + controllerStr +
Jon Hall6aec96b2015-01-19 14:49:31 -0800959 " hosts response: " +
960 repr( hosts[ controller ] ) )
961 utilities.assert_equals(
962 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800963 actual=consistentHostsResult,
Jon Hall6aec96b2015-01-19 14:49:31 -0800964 onpass="Hosts view is consistent across all ONOS nodes",
965 onfail="ONOS nodes have different views of hosts" )
Jon Hall94fd0472014-12-08 11:52:42 -0800966
Jon Hall6aec96b2015-01-19 14:49:31 -0800967 # Strongly connected clusters of devices
Jon Hall8f89dda2015-01-22 16:03:33 -0800968 consistentClustersResult = main.TRUE
Jon Hall94fd0472014-12-08 11:52:42 -0800969 for controller in range( len( clusters ) ):
Jon Hall6aec96b2015-01-19 14:49:31 -0800970 if "Error" not in clusters[ controller ]:
971 if clusters[ controller ] == clusters[ 0 ]:
Jon Hall94fd0472014-12-08 11:52:42 -0800972 continue
Jon Hall6aec96b2015-01-19 14:49:31 -0800973 else: # clusters not consistent
974 main.log.report( "clusters from ONOS" +
Jon Hall8f89dda2015-01-22 16:03:33 -0800975 controllerStr +
Jon Hall6aec96b2015-01-19 14:49:31 -0800976 " is inconsistent with ONOS1" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800977 consistentClustersResult = main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -0800978
979 else:
Jon Hall6aec96b2015-01-19 14:49:31 -0800980 main.log.report( "Error in getting dataplane clusters " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800981 "from ONOS" + controllerStr )
982 consistentClustersResult = main.FALSE
983 main.log.warn( "ONOS" + controllerStr +
Jon Hall6aec96b2015-01-19 14:49:31 -0800984 " clusters response: " +
985 repr( clusters[ controller ] ) )
986 utilities.assert_equals(
987 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800988 actual=consistentClustersResult,
Jon Hall6aec96b2015-01-19 14:49:31 -0800989 onpass="Clusters view is consistent across all ONOS nodes",
990 onfail="ONOS nodes have different views of clusters" )
991 # there should always only be one cluster
Jon Hall8f89dda2015-01-22 16:03:33 -0800992 numClusters = len( json.loads( clusters[ 0 ] ) )
Jon Hall6aec96b2015-01-19 14:49:31 -0800993 utilities.assert_equals(
994 expect=1,
Jon Hall8f89dda2015-01-22 16:03:33 -0800995 actual=numClusters,
Jon Hall6aec96b2015-01-19 14:49:31 -0800996 onpass="ONOS shows 1 SCC",
997 onfail="ONOS shows " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800998 str( numClusters ) +
Jon Hall6aec96b2015-01-19 14:49:31 -0800999 " SCCs" )
Jon Hall94fd0472014-12-08 11:52:42 -08001000
Jon Hall6aec96b2015-01-19 14:49:31 -08001001 main.step( "Comparing ONOS topology to MN" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001002 devicesResults = main.TRUE
1003 portsResults = main.TRUE
1004 linksResults = main.TRUE
1005 for controller in range( numControllers ):
1006 controllerStr = str( controller + 1 )
Jon Hall6aec96b2015-01-19 14:49:31 -08001007 if devices[ controller ] or "Error" not in devices[ controller ]:
Jon Hall8f89dda2015-01-22 16:03:33 -08001008 currentDevicesResult = main.Mininet1.compareSwitches(
Jon Hall6aec96b2015-01-19 14:49:31 -08001009 MNTopo,
1010 json.loads(
1011 devices[ controller ] ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001012 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08001013 currentDevicesResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001014 utilities.assert_equals( expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001015 actual=currentDevicesResult,
1016 onpass="ONOS" + controllerStr +
1017 " Switches view is correct",
1018 onfail="ONOS" + controllerStr +
1019 " Switches view is incorrect" )
Jon Hallb1290e82014-11-18 16:17:48 -05001020
Jon Hall6aec96b2015-01-19 14:49:31 -08001021 if ports[ controller ] or "Error" not in ports[ controller ]:
Jon Hall8f89dda2015-01-22 16:03:33 -08001022 currentPortsResult = main.Mininet1.comparePorts(
Jon Hall6aec96b2015-01-19 14:49:31 -08001023 MNTopo,
1024 json.loads(
1025 ports[ controller ] ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001026 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08001027 currentPortsResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001028 utilities.assert_equals( expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001029 actual=currentPortsResult,
1030 onpass="ONOS" + controllerStr +
1031 " ports view is correct",
1032 onfail="ONOS" + controllerStr +
1033 " ports view is incorrect" )
Jon Hallb1290e82014-11-18 16:17:48 -05001034
Jon Hall6aec96b2015-01-19 14:49:31 -08001035 if links[ controller ] or "Error" not in links[ controller ]:
Jon Hall8f89dda2015-01-22 16:03:33 -08001036 currentLinksResult = main.Mininet1.compareLinks(
Jon Hall6aec96b2015-01-19 14:49:31 -08001037 MNTopo,
1038 json.loads(
1039 links[ controller ] ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001040 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08001041 currentLinksResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001042 utilities.assert_equals( expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001043 actual=currentLinksResult,
1044 onpass="ONOS" + controllerStr +
1045 " links view is correct",
1046 onfail="ONOS" + controllerStr +
1047 " links view is incorrect" )
Jon Hallb1290e82014-11-18 16:17:48 -05001048
Jon Hall8f89dda2015-01-22 16:03:33 -08001049 devicesResults = devicesResults and currentDevicesResult
1050 portsResults = portsResults and currentPortsResult
1051 linksResults = linksResults and currentLinksResult
Jon Hallb1290e82014-11-18 16:17:48 -05001052
Jon Hall8f89dda2015-01-22 16:03:33 -08001053 topoResult = devicesResults and portsResults and linksResults\
Jon Hall529a37f2015-01-28 10:02:00 -08001054 and consistentHostsResult and consistentClustersResult
Jon Hall8f89dda2015-01-22 16:03:33 -08001055 utilities.assert_equals( expect=main.TRUE, actual=topoResult,
1056 onpass="Topology Check Test successful",
1057 onfail="Topology Check Test NOT successful" )
Jon Hallb1290e82014-11-18 16:17:48 -05001058
Jon Hall8f89dda2015-01-22 16:03:33 -08001059 finalAssert = main.TRUE
1060 finalAssert = finalAssert and topoResult and flowCheck \
1061 and intentCheck and consistentMastership and rolesNotNull
1062 utilities.assert_equals( expect=main.TRUE, actual=finalAssert,
1063 onpass="State check successful",
1064 onfail="State check NOT successful" )
Jon Hallb1290e82014-11-18 16:17:48 -05001065
Jon Hall6aec96b2015-01-19 14:49:31 -08001066 def CASE6( self, main ):
1067 """
Jon Hallb1290e82014-11-18 16:17:48 -05001068 The Failure case. Since this is the Sanity test, we do nothing.
Jon Hall6aec96b2015-01-19 14:49:31 -08001069 """
Jon Hall368769f2014-11-19 15:43:35 -08001070 import time
Jon Hall6aec96b2015-01-19 14:49:31 -08001071 main.log.report( "Wait 60 seconds instead of inducing a failure" )
1072 time.sleep( 60 )
1073 utilities.assert_equals(
1074 expect=main.TRUE,
1075 actual=main.TRUE,
1076 onpass="Sleeping 60 seconds",
1077 onfail="Something is terribly wrong with my math" )
Jon Hallb1290e82014-11-18 16:17:48 -05001078
Jon Hall6aec96b2015-01-19 14:49:31 -08001079 def CASE7( self, main ):
1080 """
Jon Hall368769f2014-11-19 15:43:35 -08001081 Check state after ONOS failure
Jon Hall6aec96b2015-01-19 14:49:31 -08001082 """
Jon Hallb1290e82014-11-18 16:17:48 -05001083 import json
Jon Hall6aec96b2015-01-19 14:49:31 -08001084 main.case( "Running ONOS Constant State Tests" )
Jon Hallb1290e82014-11-18 16:17:48 -05001085
Jon Hall6aec96b2015-01-19 14:49:31 -08001086 # Assert that each device has a master
Jon Hall8f89dda2015-01-22 16:03:33 -08001087 ONOS1MasterNotNull = main.ONOScli1.rolesNotNull()
1088 ONOS2MasterNotNull = main.ONOScli2.rolesNotNull()
1089 ONOS3MasterNotNull = main.ONOScli3.rolesNotNull()
1090 ONOS4MasterNotNull = main.ONOScli4.rolesNotNull()
1091 ONOS5MasterNotNull = main.ONOScli5.rolesNotNull()
1092 ONOS6MasterNotNull = main.ONOScli6.rolesNotNull()
1093 ONOS7MasterNotNull = main.ONOScli7.rolesNotNull()
1094 rolesNotNull = ONOS1MasterNotNull and ONOS2MasterNotNull and\
1095 ONOS3MasterNotNull and ONOS4MasterNotNull and\
1096 ONOS5MasterNotNull and ONOS6MasterNotNull and\
1097 ONOS7MasterNotNull
Jon Hall6aec96b2015-01-19 14:49:31 -08001098 utilities.assert_equals(
1099 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001100 actual=rolesNotNull,
Jon Hall6aec96b2015-01-19 14:49:31 -08001101 onpass="Each device has a master",
1102 onfail="Some devices don't have a master assigned" )
Jon Hall94fd0472014-12-08 11:52:42 -08001103
Jon Hall6aec96b2015-01-19 14:49:31 -08001104 main.step( "Check if switch roles are consistent across all nodes" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001105 ONOS1Mastership = main.ONOScli1.roles()
1106 ONOS2Mastership = main.ONOScli2.roles()
1107 ONOS3Mastership = main.ONOScli3.roles()
1108 ONOS4Mastership = main.ONOScli4.roles()
1109 ONOS5Mastership = main.ONOScli5.roles()
1110 ONOS6Mastership = main.ONOScli6.roles()
1111 ONOS7Mastership = main.ONOScli7.roles()
1112 # print json.dumps( json.loads( ONOS1Mastership ), sort_keys=True,
Jon Hall6aec96b2015-01-19 14:49:31 -08001113 # indent=4, separators=( ',', ': ' ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001114 if "Error" in ONOS1Mastership or not ONOS1Mastership\
1115 or "Error" in ONOS2Mastership or not ONOS2Mastership\
1116 or "Error" in ONOS3Mastership or not ONOS3Mastership\
1117 or "Error" in ONOS4Mastership or not ONOS4Mastership\
1118 or "Error" in ONOS5Mastership or not ONOS5Mastership\
1119 or "Error" in ONOS6Mastership or not ONOS6Mastership\
1120 or "Error" in ONOS7Mastership or not ONOS7Mastership:
Jon Hall6aec96b2015-01-19 14:49:31 -08001121 main.log.error( "Error in getting ONOS mastership" )
1122 main.log.warn( "ONOS1 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001123 repr( ONOS1Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -08001124 main.log.warn( "ONOS2 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001125 repr( ONOS2Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -08001126 main.log.warn( "ONOS3 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001127 repr( ONOS3Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -08001128 main.log.warn( "ONOS4 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001129 repr( ONOS4Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -08001130 main.log.warn( "ONOS5 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001131 repr( ONOS5Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -08001132 main.log.warn( "ONOS6 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001133 repr( ONOS6Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -08001134 main.log.warn( "ONOS7 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001135 repr( ONOS7Mastership ) )
1136 consistentMastership = main.FALSE
1137 elif ONOS1Mastership == ONOS2Mastership\
1138 and ONOS1Mastership == ONOS3Mastership\
1139 and ONOS1Mastership == ONOS4Mastership\
1140 and ONOS1Mastership == ONOS5Mastership\
1141 and ONOS1Mastership == ONOS6Mastership\
1142 and ONOS1Mastership == ONOS7Mastership:
1143 consistentMastership = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001144 main.log.report(
1145 "Switch roles are consistent across all ONOS nodes" )
Jon Hallb1290e82014-11-18 16:17:48 -05001146 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08001147 main.log.warn( "ONOS1 roles: ", json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -08001148 json.loads( ONOS1Mastership ), sort_keys=True, indent=4,
Jon Hall6aec96b2015-01-19 14:49:31 -08001149 separators=( ',', ': ' ) ) )
1150 main.log.warn( "ONOS2 roles: ", json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -08001151 json.loads( ONOS2Mastership ), sort_keys=True, indent=4,
Jon Hall6aec96b2015-01-19 14:49:31 -08001152 separators=( ',', ': ' ) ) )
1153 main.log.warn( "ONOS3 roles: ", json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -08001154 json.loads( ONOS3Mastership ), sort_keys=True, indent=4,
Jon Hall6aec96b2015-01-19 14:49:31 -08001155 separators=( ',', ': ' ) ) )
1156 main.log.warn( "ONOS4 roles: ", json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -08001157 json.loads( ONOS4Mastership ), sort_keys=True, indent=4,
Jon Hall6aec96b2015-01-19 14:49:31 -08001158 separators=( ',', ': ' ) ) )
1159 main.log.warn( "ONOS5 roles: ", json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -08001160 json.loads( ONOS5Mastership ), sort_keys=True, indent=4,
Jon Hall6aec96b2015-01-19 14:49:31 -08001161 separators=( ',', ': ' ) ) )
1162 main.log.warn( "ONOS6 roles: ", json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -08001163 json.loads( ONOS6Mastership ), sort_keys=True, indent=4,
Jon Hall6aec96b2015-01-19 14:49:31 -08001164 separators=( ',', ': ' ) ) )
1165 main.log.warn( "ONOS7 roles: ", json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -08001166 json.loads( ONOS7Mastership ), sort_keys=True, indent=4,
Jon Hall6aec96b2015-01-19 14:49:31 -08001167 separators=( ',', ': ' ) ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001168 consistentMastership = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001169 utilities.assert_equals(
1170 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001171 actual=consistentMastership,
Jon Hall6aec96b2015-01-19 14:49:31 -08001172 onpass="Switch roles are consistent across all ONOS nodes",
1173 onfail="ONOS nodes have different views of switch roles" )
Jon Hallb1290e82014-11-18 16:17:48 -05001174
1175 description2 = "Compare switch roles from before failure"
Jon Hall6aec96b2015-01-19 14:49:31 -08001176 main.step( description2 )
Jon Hallb1290e82014-11-18 16:17:48 -05001177
Jon Hall8f89dda2015-01-22 16:03:33 -08001178 currentJson = json.loads( ONOS1Mastership )
1179 oldJson = json.loads( mastershipState )
1180 mastershipCheck = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001181 for i in range( 1, 29 ):
1182 switchDPID = str(
1183 main.Mininet1.getSwitchDPID(
1184 switch="s" +
1185 str( i ) ) )
Jon Hallb1290e82014-11-18 16:17:48 -05001186
Jon Hall8f89dda2015-01-22 16:03:33 -08001187 current = [ switch[ 'master' ] for switch in currentJson
Jon Hall6aec96b2015-01-19 14:49:31 -08001188 if switchDPID in switch[ 'id' ] ]
Jon Hall8f89dda2015-01-22 16:03:33 -08001189 old = [ switch[ 'master' ] for switch in oldJson
Jon Hall6aec96b2015-01-19 14:49:31 -08001190 if switchDPID in switch[ 'id' ] ]
Jon Hallb1290e82014-11-18 16:17:48 -05001191 if current == old:
Jon Hall8f89dda2015-01-22 16:03:33 -08001192 mastershipCheck = mastershipCheck and main.TRUE
Jon Hallb1290e82014-11-18 16:17:48 -05001193 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08001194 main.log.warn( "Mastership of switch %s changed" % switchDPID )
Jon Hall8f89dda2015-01-22 16:03:33 -08001195 mastershipCheck = main.FALSE
1196 if mastershipCheck == main.TRUE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001197 main.log.report( "Mastership of Switches was not changed" )
1198 utilities.assert_equals(
1199 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001200 actual=mastershipCheck,
Jon Hall6aec96b2015-01-19 14:49:31 -08001201 onpass="Mastership of Switches was not changed",
1202 onfail="Mastership of some switches changed" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001203 mastershipCheck = mastershipCheck and consistentMastership
Jon Hallb1290e82014-11-18 16:17:48 -05001204
Jon Hall6aec96b2015-01-19 14:49:31 -08001205 main.step( "Get the intents and compare across all nodes" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001206 ONOS1Intents = main.ONOScli1.intents( jsonFormat=True )
1207 ONOS2Intents = main.ONOScli2.intents( jsonFormat=True )
1208 ONOS3Intents = main.ONOScli3.intents( jsonFormat=True )
1209 ONOS4Intents = main.ONOScli4.intents( jsonFormat=True )
1210 ONOS5Intents = main.ONOScli5.intents( jsonFormat=True )
1211 ONOS6Intents = main.ONOScli6.intents( jsonFormat=True )
1212 ONOS7Intents = main.ONOScli7.intents( jsonFormat=True )
1213 intentCheck = main.FALSE
1214 if "Error" in ONOS1Intents or not ONOS1Intents\
1215 or "Error" in ONOS2Intents or not ONOS2Intents\
1216 or "Error" in ONOS3Intents or not ONOS3Intents\
1217 or "Error" in ONOS4Intents or not ONOS4Intents\
1218 or "Error" in ONOS5Intents or not ONOS5Intents\
1219 or "Error" in ONOS6Intents or not ONOS6Intents\
1220 or "Error" in ONOS7Intents or not ONOS7Intents:
Jon Hall6aec96b2015-01-19 14:49:31 -08001221 main.log.report( "Error in getting ONOS intents" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001222 main.log.warn( "ONOS1 intents response: " + repr( ONOS1Intents ) )
1223 main.log.warn( "ONOS2 intents response: " + repr( ONOS2Intents ) )
1224 main.log.warn( "ONOS3 intents response: " + repr( ONOS3Intents ) )
1225 main.log.warn( "ONOS4 intents response: " + repr( ONOS4Intents ) )
1226 main.log.warn( "ONOS5 intents response: " + repr( ONOS5Intents ) )
1227 main.log.warn( "ONOS6 intents response: " + repr( ONOS6Intents ) )
1228 main.log.warn( "ONOS7 intents response: " + repr( ONOS7Intents ) )
1229 elif ONOS1Intents == ONOS2Intents\
1230 and ONOS1Intents == ONOS3Intents\
1231 and ONOS1Intents == ONOS4Intents\
1232 and ONOS1Intents == ONOS5Intents\
1233 and ONOS1Intents == ONOS6Intents\
1234 and ONOS1Intents == ONOS7Intents:
1235 intentCheck = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001236 main.log.report( "Intents are consistent across all ONOS nodes" )
Jon Hallb1290e82014-11-18 16:17:48 -05001237 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08001238 main.log.warn( "ONOS1 intents: " )
Jon Hall8f89dda2015-01-22 16:03:33 -08001239 print json.dumps( json.loads( ONOS1Intents ), sort_keys=True,
Jon Hall6aec96b2015-01-19 14:49:31 -08001240 indent=4, separators=( ',', ': ' ) )
1241 main.log.warn( "ONOS2 intents: " )
Jon Hall8f89dda2015-01-22 16:03:33 -08001242 print json.dumps( json.loads( ONOS2Intents ), sort_keys=True,
Jon Hall6aec96b2015-01-19 14:49:31 -08001243 indent=4, separators=( ',', ': ' ) )
1244 main.log.warn( "ONOS3 intents: " )
Jon Hall8f89dda2015-01-22 16:03:33 -08001245 print json.dumps( json.loads( ONOS3Intents ), sort_keys=True,
Jon Hall6aec96b2015-01-19 14:49:31 -08001246 indent=4, separators=( ',', ': ' ) )
1247 main.log.warn( "ONOS4 intents: " )
Jon Hall8f89dda2015-01-22 16:03:33 -08001248 print json.dumps( json.loads( ONOS4Intents ), sort_keys=True,
Jon Hall6aec96b2015-01-19 14:49:31 -08001249 indent=4, separators=( ',', ': ' ) )
1250 main.log.warn( "ONOS5 intents: " )
Jon Hall8f89dda2015-01-22 16:03:33 -08001251 print json.dumps( json.loads( ONOS5Intents ), sort_keys=True,
Jon Hall6aec96b2015-01-19 14:49:31 -08001252 indent=4, separators=( ',', ': ' ) )
1253 main.log.warn( "ONOS6 intents: " )
Jon Hall8f89dda2015-01-22 16:03:33 -08001254 print json.dumps( json.loads( ONOS6Intents ), sort_keys=True,
Jon Hall6aec96b2015-01-19 14:49:31 -08001255 indent=4, separators=( ',', ': ' ) )
1256 main.log.warn( "ONOS7 intents: " )
Jon Hall8f89dda2015-01-22 16:03:33 -08001257 print json.dumps( json.loads( ONOS7Intents ), sort_keys=True,
Jon Hall6aec96b2015-01-19 14:49:31 -08001258 indent=4, separators=( ',', ': ' ) )
1259 utilities.assert_equals(
1260 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001261 actual=intentCheck,
Jon Hall6aec96b2015-01-19 14:49:31 -08001262 onpass="Intents are consistent across all ONOS nodes",
1263 onfail="ONOS nodes have different views of intents" )
Jon Hallb1290e82014-11-18 16:17:48 -05001264
Jon Hall6aec96b2015-01-19 14:49:31 -08001265 # NOTE: Hazelcast has no durability, so intents are lost across system
1266 # restarts
1267 main.step( "Compare current intents with intents before the failure" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001268 # NOTE: this requires case 5 to pass for intentState to be set.
Jon Hall94fd0472014-12-08 11:52:42 -08001269 # maybe we should stop the test if that fails?
Jon Hall8f89dda2015-01-22 16:03:33 -08001270 if intentState == ONOS1Intents:
1271 sameIntents = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001272 main.log.report( "Intents are consistent with before failure" )
1273 # TODO: possibly the states have changed? we may need to figure out
1274 # what the aceptable states are
Jon Hallb1290e82014-11-18 16:17:48 -05001275 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08001276 try:
1277 main.log.warn( "ONOS1 intents: " )
Jon Hall8f89dda2015-01-22 16:03:33 -08001278 print json.dumps( json.loads( ONOS1Intents ),
Jon Hall6aec96b2015-01-19 14:49:31 -08001279 sort_keys=True, indent=4,
1280 separators=( ',', ': ' ) )
1281 except:
1282 pass
Jon Hall8f89dda2015-01-22 16:03:33 -08001283 sameIntents = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001284 utilities.assert_equals(
1285 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001286 actual=sameIntents,
Jon Hall6aec96b2015-01-19 14:49:31 -08001287 onpass="Intents are consistent with before failure",
1288 onfail="The Intents changed during failure" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001289 intentCheck = intentCheck and sameIntents
Jon Hallb1290e82014-11-18 16:17:48 -05001290
Jon Hall6aec96b2015-01-19 14:49:31 -08001291 main.step( "Get the OF Table entries and compare to before " +
1292 "component failure" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001293 FlowTables = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001294 flows2 = []
1295 for i in range( 28 ):
1296 main.log.info( "Checking flow table on s" + str( i + 1 ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001297 tmpFlows = main.Mininet2.getFlowTable( 1.3, "s" + str( i + 1 ) )
1298 flows2.append( tmpFlows )
1299 tempResult = main.Mininet2.flowComp(
Jon Hall6aec96b2015-01-19 14:49:31 -08001300 flow1=flows[ i ],
Jon Hall8f89dda2015-01-22 16:03:33 -08001301 flow2=tmpFlows )
1302 FlowTables = FlowTables and tempResult
1303 if FlowTables == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001304 main.log.info( "Differences in flow table for switch: s" +
1305 str( i + 1 ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001306 if FlowTables == main.TRUE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001307 main.log.report( "No changes were found in the flow tables" )
1308 utilities.assert_equals(
1309 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001310 actual=FlowTables,
Jon Hall6aec96b2015-01-19 14:49:31 -08001311 onpass="No changes were found in the flow tables",
1312 onfail="Changes were found in the flow tables" )
Jon Hallb1290e82014-11-18 16:17:48 -05001313
Jon Hall6aec96b2015-01-19 14:49:31 -08001314 main.step( "Check the continuous pings to ensure that no packets " +
1315 "were dropped during component failure" )
1316 # FIXME: This check is always failing. Investigate cause
1317 # NOTE: this may be something to do with file permsissions
Jon Hallb1290e82014-11-18 16:17:48 -05001318 # or slight change in format
Jon Hall6aec96b2015-01-19 14:49:31 -08001319 main.Mininet2.pingKill(
1320 main.params[ 'TESTONUSER' ],
1321 main.params[ 'TESTONIP' ] )
Jon Hall8f89dda2015-01-22 16:03:33 -08001322 LossInPings = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001323 # NOTE: checkForLoss returns main.FALSE with 0% packet loss
1324 for i in range( 8, 18 ):
1325 main.log.info(
1326 "Checking for a loss in pings along flow from s" +
1327 str( i ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001328 LossInPings = main.Mininet2.checkForLoss(
Jon Hall6aec96b2015-01-19 14:49:31 -08001329 "/tmp/ping.h" +
Jon Hall8f89dda2015-01-22 16:03:33 -08001330 str( i ) ) or LossInPings
1331 if LossInPings == main.TRUE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001332 main.log.info( "Loss in ping detected" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001333 elif LossInPings == main.ERROR:
Jon Hall6aec96b2015-01-19 14:49:31 -08001334 main.log.info( "There are multiple mininet process running" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001335 elif LossInPings == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001336 main.log.info( "No Loss in the pings" )
1337 main.log.report( "No loss of dataplane connectivity" )
1338 utilities.assert_equals(
1339 expect=main.FALSE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001340 actual=LossInPings,
Jon Hall6aec96b2015-01-19 14:49:31 -08001341 onpass="No Loss of connectivity",
1342 onfail="Loss of dataplane connectivity detected" )
Jon Hallb1290e82014-11-18 16:17:48 -05001343
Jon Hall6aec96b2015-01-19 14:49:31 -08001344 # Test of LeadershipElection
1345 # NOTE: this only works for the sanity test. In case of failures,
1346 # leader will likely change
Jon Hall8f89dda2015-01-22 16:03:33 -08001347 leader = ONOS1Ip
1348 leaderResult = main.TRUE
1349 for controller in range( 1, numControllers + 1 ):
Jon Hall6aec96b2015-01-19 14:49:31 -08001350 # loop through ONOScli handlers
1351 node = getattr( main, ( 'ONOScli' + str( controller ) ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001352 leaderN = node.electionTestLeader()
Jon Hall6aec96b2015-01-19 14:49:31 -08001353 # verify leader is ONOS1
Jon Hall669173b2014-12-17 11:36:30 -08001354 if leaderN == leader:
Jon Hall6aec96b2015-01-19 14:49:31 -08001355 # all is well
1356 # NOTE: In failure scenario, this could be a new node, maybe
1357 # check != ONOS1
Jon Hall669173b2014-12-17 11:36:30 -08001358 pass
1359 elif leaderN == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001360 # error in response
1361 main.log.report( "Something is wrong with " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001362 "electionTestLeader function," +
Jon Hall6aec96b2015-01-19 14:49:31 -08001363 " check the error logs" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001364 leaderResult = main.FALSE
Jon Hall669173b2014-12-17 11:36:30 -08001365 elif leader != leaderN:
Jon Hall8f89dda2015-01-22 16:03:33 -08001366 leaderResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001367 main.log.report( "ONOS" + str( controller ) + " sees " +
1368 str( leaderN ) +
1369 " as the leader of the election app. " +
1370 "Leader should be " + str( leader ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001371 if leaderResult:
1372 main.log.report( "Leadership election tests passed( consistent " +
Jon Hall6aec96b2015-01-19 14:49:31 -08001373 "view of leader across listeners and a new " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001374 "leader was re-elected if applicable )" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001375 utilities.assert_equals(
1376 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001377 actual=leaderResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08001378 onpass="Leadership election passed",
1379 onfail="Something went wrong with Leadership election" )
Jon Hallb1290e82014-11-18 16:17:48 -05001380
Jon Hall8f89dda2015-01-22 16:03:33 -08001381 result = mastershipCheck and intentCheck and FlowTables and\
1382 ( not LossInPings ) and rolesNotNull and leaderResult
Jon Hall6aec96b2015-01-19 14:49:31 -08001383 result = int( result )
Jon Hallb1290e82014-11-18 16:17:48 -05001384 if result == main.TRUE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001385 main.log.report( "Constant State Tests Passed" )
1386 utilities.assert_equals( expect=main.TRUE, actual=result,
Jon Hall8f89dda2015-01-22 16:03:33 -08001387 onpass="Constant State Tests Passed",
1388 onfail="Constant state tests failed" )
Jon Hallb1290e82014-11-18 16:17:48 -05001389
Jon Hall6aec96b2015-01-19 14:49:31 -08001390 def CASE8( self, main ):
1391 """
Jon Hallb1290e82014-11-18 16:17:48 -05001392 Compare topo
Jon Hall6aec96b2015-01-19 14:49:31 -08001393 """
Jon Hallb1290e82014-11-18 16:17:48 -05001394 import sys
Jon Hall6aec96b2015-01-19 14:49:31 -08001395 # FIXME add this path to params
1396 sys.path.append( "/home/admin/sts" )
1397 # assumes that sts is already in you PYTHONPATH
1398 from sts.topology.teston_topology import TestONTopology
Jon Hallb1290e82014-11-18 16:17:48 -05001399 import json
Jon Hall73cf9cc2014-11-20 22:28:38 -08001400 import time
Jon Hallb1290e82014-11-18 16:17:48 -05001401
Jon Hall6aec96b2015-01-19 14:49:31 -08001402 description = "Compare ONOS Topology view to Mininet topology"
1403 main.case( description )
1404 main.log.report( description )
1405 main.step( "Create TestONTopology object" )
Jon Hallb1290e82014-11-18 16:17:48 -05001406 ctrls = []
1407 count = 1
1408 while True:
1409 temp = ()
Jon Hall6aec96b2015-01-19 14:49:31 -08001410 if ( 'ip' + str( count ) ) in main.params[ 'CTRL' ]:
1411 temp = temp + ( getattr( main, ( 'ONOS' + str( count ) ) ), )
1412 temp = temp + ( "ONOS" + str( count ), )
1413 temp = temp + ( main.params[ 'CTRL' ][ 'ip' + str( count ) ], )
1414 temp = temp + \
1415 ( eval( main.params[ 'CTRL' ][ 'port' + str( count ) ] ), )
1416 ctrls.append( temp )
Jon Hallb1290e82014-11-18 16:17:48 -05001417 count = count + 1
1418 else:
1419 break
Jon Hall6aec96b2015-01-19 14:49:31 -08001420 MNTopo = TestONTopology(
1421 main.Mininet1,
1422 ctrls ) # can also add Intent API info for intent operations
Jon Hallb1290e82014-11-18 16:17:48 -05001423
Jon Hall6aec96b2015-01-19 14:49:31 -08001424 main.step( "Comparing ONOS topology to MN" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001425 devicesResults = main.TRUE
1426 portsResults = main.TRUE
1427 linksResults = main.TRUE
1428 topoResult = main.FALSE
Jon Hall73cf9cc2014-11-20 22:28:38 -08001429 elapsed = 0
Jon Hallffb386d2014-11-21 13:43:38 -08001430 count = 0
Jon Hall6aec96b2015-01-19 14:49:31 -08001431 main.step( "Collecting topology information from ONOS" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001432 startTime = time.time()
1433 while topoResult == main.FALSE and elapsed < 60:
Jon Hallffb386d2014-11-21 13:43:38 -08001434 count = count + 1
Jon Hall94fd0472014-12-08 11:52:42 -08001435 if count > 1:
Jon Hall6aec96b2015-01-19 14:49:31 -08001436 # TODO: Depricate STS usage
1437 MNTopo = TestONTopology(
1438 main.Mininet1,
1439 ctrls )
Jon Hall8f89dda2015-01-22 16:03:33 -08001440 cliStart = time.time()
Jon Hall94fd0472014-12-08 11:52:42 -08001441 devices = []
1442 devices.append( main.ONOScli1.devices() )
1443 devices.append( main.ONOScli2.devices() )
1444 devices.append( main.ONOScli3.devices() )
1445 devices.append( main.ONOScli4.devices() )
1446 devices.append( main.ONOScli5.devices() )
1447 devices.append( main.ONOScli6.devices() )
1448 devices.append( main.ONOScli7.devices() )
1449 hosts = []
Jon Hall529a37f2015-01-28 10:02:00 -08001450 hosts.append( json.loads( main.ONOScli1.hosts() ) )
1451 hosts.append( json.loads( main.ONOScli2.hosts() ) )
1452 hosts.append( json.loads( main.ONOScli3.hosts() ) )
1453 hosts.append( json.loads( main.ONOScli4.hosts() ) )
1454 hosts.append( json.loads( main.ONOScli5.hosts() ) )
1455 hosts.append( json.loads( main.ONOScli6.hosts() ) )
1456 hosts.append( json.loads( main.ONOScli7.hosts() ) )
1457 for controller in range( 0, len( hosts ) ):
1458 controllerStr = str( controller + 1 )
1459 for host in hosts[ controller ]:
1460 host
1461 if host[ 'ips' ] == []:
1462 main.log.error(
1463 "DEBUG:Error with host ips on controller" +
1464 controllerStr + ": " + str( host ) )
Jon Hall94fd0472014-12-08 11:52:42 -08001465 ports = []
1466 ports.append( main.ONOScli1.ports() )
1467 ports.append( main.ONOScli2.ports() )
1468 ports.append( main.ONOScli3.ports() )
1469 ports.append( main.ONOScli4.ports() )
1470 ports.append( main.ONOScli5.ports() )
1471 ports.append( main.ONOScli6.ports() )
1472 ports.append( main.ONOScli7.ports() )
1473 links = []
1474 links.append( main.ONOScli1.links() )
1475 links.append( main.ONOScli2.links() )
1476 links.append( main.ONOScli3.links() )
1477 links.append( main.ONOScli4.links() )
1478 links.append( main.ONOScli5.links() )
1479 links.append( main.ONOScli6.links() )
1480 links.append( main.ONOScli7.links() )
1481 clusters = []
1482 clusters.append( main.ONOScli1.clusters() )
1483 clusters.append( main.ONOScli2.clusters() )
1484 clusters.append( main.ONOScli3.clusters() )
1485 clusters.append( main.ONOScli4.clusters() )
1486 clusters.append( main.ONOScli5.clusters() )
1487 clusters.append( main.ONOScli6.clusters() )
1488 clusters.append( main.ONOScli7.clusters() )
Jon Hallb1290e82014-11-18 16:17:48 -05001489
Jon Hall8f89dda2015-01-22 16:03:33 -08001490 elapsed = time.time() - startTime
1491 cliTime = time.time() - cliStart
1492 print "CLI time: " + str( cliTime )
Jon Hallb1290e82014-11-18 16:17:48 -05001493
Jon Hall529a37f2015-01-28 10:02:00 -08001494 try:
1495 for controller in range( numControllers ):
1496 controllerStr = str( controller + 1 )
1497 if devices[ controller ] or "Error" not in devices[
1498 controller ]:
1499 currentDevicesResult = main.Mininet1.compareSwitches(
1500 MNTopo,
1501 json.loads(
1502 devices[ controller ] ) )
1503 else:
1504 currentDevicesResult = main.FALSE
1505 utilities.assert_equals( expect=main.TRUE,
1506 actual=currentDevicesResult,
1507 onpass="ONOS" + controllerStr +
1508 " Switches view is correct",
1509 onfail="ONOS" + controllerStr +
1510 " Switches view is incorrect" )
Jon Hallb1290e82014-11-18 16:17:48 -05001511
Jon Hall529a37f2015-01-28 10:02:00 -08001512 if ports[ controller ] or "Error" not in ports[ controller ]:
1513 currentPortsResult = main.Mininet1.comparePorts(
1514 MNTopo,
1515 json.loads(
1516 ports[ controller ] ) )
1517 else:
1518 currentPortsResult = main.FALSE
1519 utilities.assert_equals( expect=main.TRUE,
1520 actual=currentPortsResult,
1521 onpass="ONOS" + controllerStr +
1522 " ports view is correct",
1523 onfail="ONOS" + controllerStr +
1524 " ports view is incorrect" )
Jon Hall94fd0472014-12-08 11:52:42 -08001525
Jon Hall529a37f2015-01-28 10:02:00 -08001526 if links[ controller ] or "Error" not in links[ controller ]:
1527 currentLinksResult = main.Mininet1.compareLinks(
1528 MNTopo,
1529 json.loads(
1530 links[ controller ] ) )
1531 else:
1532 currentLinksResult = main.FALSE
1533 utilities.assert_equals( expect=main.TRUE,
1534 actual=currentLinksResult,
1535 onpass="ONOS" + controllerStr +
1536 " links view is correct",
1537 onfail="ONOS" + controllerStr +
1538 " links view is incorrect" )
1539 devicesResults = devicesResults and currentDevicesResult
1540 portsResults = portsResults and currentPortsResult
1541 linksResults = linksResults and currentLinksResult
Jon Hall94fd0472014-12-08 11:52:42 -08001542
Jon Hall529a37f2015-01-28 10:02:00 -08001543 # Compare json objects for hosts and dataplane clusters
Jon Hall94fd0472014-12-08 11:52:42 -08001544
Jon Hall529a37f2015-01-28 10:02:00 -08001545 # hosts
1546 consistentHostsResult = main.TRUE
1547 for controller in range( len( hosts ) ):
1548 controllerStr = str( controller + 1 )
1549 if "Error" not in hosts[ controller ]:
1550 if hosts[ controller ] == hosts[ 0 ]:
1551 continue
1552 else: # hosts not consistent
1553 main.log.report( "hosts from ONOS" + controllerStr +
1554 " is inconsistent with ONOS1" )
1555 main.log.warn( repr( hosts[ controller ] ) )
1556 consistentHostsResult = main.FALSE
1557
1558 else:
1559 main.log.report( "Error in getting ONOS hosts from ONOS" +
1560 controllerStr )
Jon Hall8f89dda2015-01-22 16:03:33 -08001561 consistentHostsResult = main.FALSE
Jon Hall529a37f2015-01-28 10:02:00 -08001562 main.log.warn( "ONOS" + controllerStr +
1563 " hosts response: " +
1564 repr( hosts[ controller ] ) )
1565 utilities.assert_equals(
1566 expect=main.TRUE,
1567 actual=consistentHostsResult,
1568 onpass="Hosts view is consistent across all ONOS nodes",
1569 onfail="ONOS nodes have different views of hosts" )
Jon Hall94fd0472014-12-08 11:52:42 -08001570
Jon Hall529a37f2015-01-28 10:02:00 -08001571 # Strongly connected clusters of devices
1572 consistentClustersResult = main.TRUE
1573 for controller in range( len( clusters ) ):
1574 controllerStr = str( controller + 1 )
1575 if "Error" not in clusters[ controller ]:
1576 if clusters[ controller ] == clusters[ 0 ]:
1577 continue
1578 else: # clusters not consistent
1579 main.log.report( "clusters from ONOS" +
1580 controllerStr +
1581 " is inconsistent with ONOS1" )
1582 consistentClustersResult = main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -08001583
Jon Hall529a37f2015-01-28 10:02:00 -08001584 else:
1585 main.log.report( "Error in getting dataplane clusters " +
1586 "from ONOS" + controllerStr )
Jon Hall8f89dda2015-01-22 16:03:33 -08001587 consistentClustersResult = main.FALSE
Jon Hall529a37f2015-01-28 10:02:00 -08001588 main.log.warn( "ONOS" + controllerStr +
1589 " clusters response: " +
1590 repr( clusters[ controller ] ) )
1591 utilities.assert_equals(
1592 expect=main.TRUE,
1593 actual=consistentClustersResult,
1594 onpass="Clusters view is consistent across all ONOS nodes",
1595 onfail="ONOS nodes have different views of clusters" )
1596 # there should always only be one cluster
1597 numClusters = len( json.loads( clusters[ 0 ] ) )
1598 utilities.assert_equals(
1599 expect=1,
1600 actual=numClusters,
1601 onpass="ONOS shows 1 SCC",
1602 onfail="ONOS shows " +
1603 str( numClusters ) +
1604 " SCCs" )
Jon Hall94fd0472014-12-08 11:52:42 -08001605
Jon Hall529a37f2015-01-28 10:02:00 -08001606 topoResult = ( devicesResults and portsResults and linksResults
1607 and consistentHostsResult
1608 and consistentClustersResult )
Jon Hall94fd0472014-12-08 11:52:42 -08001609
Jon Hall529a37f2015-01-28 10:02:00 -08001610 topoResult = topoResult and int( count <= 2 )
1611 note = "note it takes about " + str( int( cliTime ) ) + \
1612 " seconds for the test to make all the cli calls to fetch " +\
1613 "the topology from each ONOS instance"
1614 main.log.report(
1615 "Very crass estimate for topology discovery/convergence( " +
1616 str( note ) + " ): " + str( elapsed ) + " seconds, " +
1617 str( count ) + " tries" )
1618 utilities.assert_equals( expect=main.TRUE, actual=topoResult,
1619 onpass="Topology Check Test successful",
1620 onfail="Topology Check Test NOT successful" )
1621 if topoResult == main.TRUE:
1622 main.log.report( "ONOS topology view matches Mininet topology" )
1623 except:
1624 main.log.info( self.name + " ::::::" )
1625 main.log.error( traceback.print_exc() )
1626 main.log.info( self.name + " ::::::" )
Jon Hall94fd0472014-12-08 11:52:42 -08001627
Jon Hallb1290e82014-11-18 16:17:48 -05001628
Jon Hall6aec96b2015-01-19 14:49:31 -08001629 def CASE9( self, main ):
1630 """
Jon Hallb1290e82014-11-18 16:17:48 -05001631 Link s3-s28 down
Jon Hall6aec96b2015-01-19 14:49:31 -08001632 """
1633 import time
1634 # NOTE: You should probably run a topology check after this
Jon Hallb1290e82014-11-18 16:17:48 -05001635
Jon Hall8f89dda2015-01-22 16:03:33 -08001636 linkSleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] )
Jon Hallb1290e82014-11-18 16:17:48 -05001637
Jon Hall6aec96b2015-01-19 14:49:31 -08001638 description = "Turn off a link to ensure that Link Discovery " +\
Jon Hall8f89dda2015-01-22 16:03:33 -08001639 "is working properly"
Jon Hall6aec96b2015-01-19 14:49:31 -08001640 main.log.report( description )
1641 main.case( description )
Jon Hallb1290e82014-11-18 16:17:48 -05001642
Jon Hall6aec96b2015-01-19 14:49:31 -08001643 main.step( "Kill Link between s3 and s28" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001644 LinkDown = main.Mininet1.link( END1="s3", END2="s28", OPTION="down" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001645 main.log.info(
1646 "Waiting " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001647 str( linkSleep ) +
Jon Hall6aec96b2015-01-19 14:49:31 -08001648 " seconds for link down to be discovered" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001649 time.sleep( linkSleep )
1650 utilities.assert_equals( expect=main.TRUE, actual=LinkDown,
1651 onpass="Link down succesful",
1652 onfail="Failed to bring link down" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001653 # TODO do some sort of check here
Jon Hallb1290e82014-11-18 16:17:48 -05001654
Jon Hall6aec96b2015-01-19 14:49:31 -08001655 def CASE10( self, main ):
1656 """
Jon Hallb1290e82014-11-18 16:17:48 -05001657 Link s3-s28 up
Jon Hall6aec96b2015-01-19 14:49:31 -08001658 """
1659 import time
1660 # NOTE: You should probably run a topology check after this
Jon Hallb1290e82014-11-18 16:17:48 -05001661
Jon Hall8f89dda2015-01-22 16:03:33 -08001662 linkSleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] )
Jon Hallb1290e82014-11-18 16:17:48 -05001663
Jon Hall6aec96b2015-01-19 14:49:31 -08001664 description = "Restore a link to ensure that Link Discovery is " + \
Jon Hall8f89dda2015-01-22 16:03:33 -08001665 "working properly"
Jon Hall6aec96b2015-01-19 14:49:31 -08001666 main.log.report( description )
1667 main.case( description )
Jon Hallb1290e82014-11-18 16:17:48 -05001668
Jon Hall6aec96b2015-01-19 14:49:31 -08001669 main.step( "Bring link between s3 and s28 back up" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001670 LinkUp = main.Mininet1.link( END1="s3", END2="s28", OPTION="up" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001671 main.log.info(
1672 "Waiting " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001673 str( linkSleep ) +
Jon Hall6aec96b2015-01-19 14:49:31 -08001674 " seconds for link up to be discovered" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001675 time.sleep( linkSleep )
1676 utilities.assert_equals( expect=main.TRUE, actual=LinkUp,
1677 onpass="Link up succesful",
1678 onfail="Failed to bring link up" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001679 # TODO do some sort of check here
Jon Hallb1290e82014-11-18 16:17:48 -05001680
Jon Hall6aec96b2015-01-19 14:49:31 -08001681 def CASE11( self, main ):
1682 """
Jon Hallb1290e82014-11-18 16:17:48 -05001683 Switch Down
Jon Hall6aec96b2015-01-19 14:49:31 -08001684 """
1685 # NOTE: You should probably run a topology check after this
Jon Hallb1290e82014-11-18 16:17:48 -05001686 import time
1687
Jon Hall8f89dda2015-01-22 16:03:33 -08001688 switchSleep = float( main.params[ 'timers' ][ 'SwitchDiscovery' ] )
Jon Hallb1290e82014-11-18 16:17:48 -05001689
1690 description = "Killing a switch to ensure it is discovered correctly"
Jon Hall6aec96b2015-01-19 14:49:31 -08001691 main.log.report( description )
1692 main.case( description )
1693 switch = main.params[ 'kill' ][ 'switch' ]
1694 switchDPID = main.params[ 'kill' ][ 'dpid' ]
Jon Hallb1290e82014-11-18 16:17:48 -05001695
Jon Hall6aec96b2015-01-19 14:49:31 -08001696 # TODO: Make this switch parameterizable
1697 main.step( "Kill " + switch )
1698 main.log.report( "Deleting " + switch )
Jon Hall8f89dda2015-01-22 16:03:33 -08001699 main.Mininet1.delSwitch( switch )
1700 main.log.info( "Waiting " + str( switchSleep ) +
Jon Hall6aec96b2015-01-19 14:49:31 -08001701 " seconds for switch down to be discovered" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001702 time.sleep( switchSleep )
1703 device = main.ONOScli1.getDevice( dpid=switchDPID )
Jon Hall6aec96b2015-01-19 14:49:31 -08001704 # Peek at the deleted switch
1705 main.log.warn( str( device ) )
Jon Hall94fd0472014-12-08 11:52:42 -08001706 result = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001707 if device and device[ 'available' ] is False:
Jon Hall94fd0472014-12-08 11:52:42 -08001708 result = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001709 utilities.assert_equals( expect=main.TRUE, actual=result,
Jon Hall8f89dda2015-01-22 16:03:33 -08001710 onpass="Kill switch succesful",
1711 onfail="Failed to kill switch?" )
Jon Hallb1290e82014-11-18 16:17:48 -05001712
Jon Hall6aec96b2015-01-19 14:49:31 -08001713 def CASE12( self, main ):
1714 """
Jon Hallb1290e82014-11-18 16:17:48 -05001715 Switch Up
Jon Hall6aec96b2015-01-19 14:49:31 -08001716 """
1717 # NOTE: You should probably run a topology check after this
Jon Hallb1290e82014-11-18 16:17:48 -05001718 import time
Jon Hall669173b2014-12-17 11:36:30 -08001719
Jon Hall8f89dda2015-01-22 16:03:33 -08001720 switchSleep = float( main.params[ 'timers' ][ 'SwitchDiscovery' ] )
Jon Hall6aec96b2015-01-19 14:49:31 -08001721 switch = main.params[ 'kill' ][ 'switch' ]
1722 switchDPID = main.params[ 'kill' ][ 'dpid' ]
1723 links = main.params[ 'kill' ][ 'links' ].split()
Jon Hallb1290e82014-11-18 16:17:48 -05001724 description = "Adding a switch to ensure it is discovered correctly"
Jon Hall6aec96b2015-01-19 14:49:31 -08001725 main.log.report( description )
1726 main.case( description )
Jon Hallb1290e82014-11-18 16:17:48 -05001727
Jon Hall6aec96b2015-01-19 14:49:31 -08001728 main.step( "Add back " + switch )
1729 main.log.report( "Adding back " + switch )
Jon Hall8f89dda2015-01-22 16:03:33 -08001730 main.Mininet1.addSwitch( switch, dpid=switchDPID )
Jon Hall6aec96b2015-01-19 14:49:31 -08001731 # TODO: New dpid or same? Ask Thomas?
1732 for peer in links:
Jon Hall8f89dda2015-01-22 16:03:33 -08001733 main.Mininet1.addLink( switch, peer )
1734 main.Mininet1.assignSwController(
Jon Hall6aec96b2015-01-19 14:49:31 -08001735 sw=switch.split( 's' )[ 1 ],
Jon Hall8f89dda2015-01-22 16:03:33 -08001736 count=numControllers,
1737 ip1=ONOS1Ip,
1738 port1=ONOS1Port,
1739 ip2=ONOS2Ip,
1740 port2=ONOS2Port,
1741 ip3=ONOS3Ip,
1742 port3=ONOS3Port,
1743 ip4=ONOS4Ip,
1744 port4=ONOS4Port,
1745 ip5=ONOS5Ip,
1746 port5=ONOS5Port,
1747 ip6=ONOS6Ip,
1748 port6=ONOS6Port,
1749 ip7=ONOS7Ip,
1750 port7=ONOS7Port )
Jon Hall6aec96b2015-01-19 14:49:31 -08001751 main.log.info(
1752 "Waiting " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001753 str( switchSleep ) +
Jon Hall6aec96b2015-01-19 14:49:31 -08001754 " seconds for switch up to be discovered" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001755 time.sleep( switchSleep )
1756 device = main.ONOScli1.getDevice( dpid=switchDPID )
Jon Hall6aec96b2015-01-19 14:49:31 -08001757 # Peek at the deleted switch
1758 main.log.warn( str( device ) )
Jon Hall94fd0472014-12-08 11:52:42 -08001759 result = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001760 if device and device[ 'available' ]:
Jon Hall94fd0472014-12-08 11:52:42 -08001761 result = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001762 utilities.assert_equals( expect=main.TRUE, actual=result,
Jon Hall8f89dda2015-01-22 16:03:33 -08001763 onpass="add switch succesful",
1764 onfail="Failed to add switch?" )
Jon Hallb1290e82014-11-18 16:17:48 -05001765
Jon Hall6aec96b2015-01-19 14:49:31 -08001766 def CASE13( self, main ):
1767 """
Jon Hallb1290e82014-11-18 16:17:48 -05001768 Clean up
Jon Hall6aec96b2015-01-19 14:49:31 -08001769 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001770 import os
1771 import time
Jon Hall6aec96b2015-01-19 14:49:31 -08001772 # TODO: make use of this elsewhere
1773 ips = []
Jon Hall8f89dda2015-01-22 16:03:33 -08001774 ips.append( ONOS1Ip )
1775 ips.append( ONOS2Ip )
1776 ips.append( ONOS3Ip )
1777 ips.append( ONOS4Ip )
1778 ips.append( ONOS5Ip )
1779 ips.append( ONOS6Ip )
1780 ips.append( ONOS7Ip )
Jon Hall6aec96b2015-01-19 14:49:31 -08001781
1782 # printing colors to terminal
Jon Hall669173b2014-12-17 11:36:30 -08001783 colors = {}
Jon Hall6aec96b2015-01-19 14:49:31 -08001784 colors[ 'cyan' ] = '\033[96m'
1785 colors[ 'purple' ] = '\033[95m'
1786 colors[ 'blue' ] = '\033[94m'
1787 colors[ 'green' ] = '\033[92m'
1788 colors[ 'yellow' ] = '\033[93m'
1789 colors[ 'red' ] = '\033[91m'
1790 colors[ 'end' ] = '\033[0m'
Jon Hall368769f2014-11-19 15:43:35 -08001791 description = "Test Cleanup"
Jon Hall6aec96b2015-01-19 14:49:31 -08001792 main.log.report( description )
1793 main.case( description )
1794 main.step( "Killing tcpdumps" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001795 main.Mininet2.stopTcpdump()
Jon Hallb1290e82014-11-18 16:17:48 -05001796
Jon Hall6aec96b2015-01-19 14:49:31 -08001797 main.step( "Checking ONOS Logs for errors" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001798 for i in range( 7 ):
Jon Hall6aec96b2015-01-19 14:49:31 -08001799 print colors[ 'purple' ] + "Checking logs for errors on " + \
Jon Hall8f89dda2015-01-22 16:03:33 -08001800 "ONOS" + str( i + 1 ) + ":" + colors[ 'end' ]
1801 print main.ONOSbench.checkLogs( ips[ i ] )
Jon Hall94fd0472014-12-08 11:52:42 -08001802
Jon Hall6aec96b2015-01-19 14:49:31 -08001803 main.step( "Copying MN pcap and ONOS log files to test station" )
Jon Hallb1290e82014-11-18 16:17:48 -05001804 testname = main.TEST
Jon Hall8f89dda2015-01-22 16:03:33 -08001805 teststationUser = main.params[ 'TESTONUSER' ]
1806 teststationIP = main.params[ 'TESTONIP' ]
Jon Hall6aec96b2015-01-19 14:49:31 -08001807 # NOTE: MN Pcap file is being saved to ~/packet_captures
Jon Hall73cf9cc2014-11-20 22:28:38 -08001808 # scp this file as MN and TestON aren't necessarily the same vm
Jon Hall6aec96b2015-01-19 14:49:31 -08001809 # FIXME: scp
1810 # mn files
1811 # TODO: Load these from params
1812 # NOTE: must end in /
Jon Hall8f89dda2015-01-22 16:03:33 -08001813 logFolder = "/opt/onos/log/"
1814 logFiles = [ "karaf.log", "karaf.log.1" ]
Jon Hall6aec96b2015-01-19 14:49:31 -08001815 # NOTE: must end in /
Jon Hall8f89dda2015-01-22 16:03:33 -08001816 dstDir = "~/packet_captures/"
1817 for f in logFiles:
1818 for i in range( 7 ):
1819 main.ONOSbench.handle.sendline( "scp sdn@" + ips[ i ] + ":" +
1820 logFolder + f + " " +
1821 teststationUser + "@" +
1822 teststationIP + ":" +
1823 dstDir + str( testname ) +
Jon Hall6aec96b2015-01-19 14:49:31 -08001824 "-ONOS" + str( i + 1 ) + "-" +
1825 f )
1826 # std*.log's
1827 # NOTE: must end in /
Jon Hall8f89dda2015-01-22 16:03:33 -08001828 logFolder = "/opt/onos/var/"
1829 logFiles = [ "stderr.log", "stdout.log" ]
Jon Hall6aec96b2015-01-19 14:49:31 -08001830 # NOTE: must end in /
Jon Hall8f89dda2015-01-22 16:03:33 -08001831 dstDir = "~/packet_captures/"
1832 for f in logFiles:
1833 for i in range( 7 ):
1834 main.ONOSbench.handle.sendline( "scp sdn@" + ips[ i ] + ":" +
1835 logFolder + f + " " +
1836 teststationUser + "@" +
1837 teststationIP + ":" +
1838 dstDir + str( testname ) +
Jon Hall6aec96b2015-01-19 14:49:31 -08001839 "-ONOS" + str( i + 1 ) + "-" +
1840 f )
1841 # sleep so scp can finish
1842 time.sleep( 10 )
1843 main.step( "Packing and rotating pcap archives" )
1844 os.system( "~/TestON/dependencies/rotate.sh " + str( testname ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001845
Jon Hall6aec96b2015-01-19 14:49:31 -08001846 # TODO: actually check something here
1847 utilities.assert_equals( expect=main.TRUE, actual=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001848 onpass="Test cleanup successful",
1849 onfail="Test cleanup NOT successful" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001850
Jon Hall6aec96b2015-01-19 14:49:31 -08001851 def CASE14( self, main ):
1852 """
Jon Hall94fd0472014-12-08 11:52:42 -08001853 start election app on all onos nodes
Jon Hall6aec96b2015-01-19 14:49:31 -08001854 """
Jon Hall8f89dda2015-01-22 16:03:33 -08001855 leaderResult = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001856 # install app on onos 1
1857 main.log.info( "Install leadership election app" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001858 main.ONOScli1.featureInstall( "onos-app-election" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001859 # wait for election
1860 # check for leader
Jon Hall8f89dda2015-01-22 16:03:33 -08001861 leader = main.ONOScli1.electionTestLeader()
Jon Hall6aec96b2015-01-19 14:49:31 -08001862 # verify leader is ONOS1
Jon Hall8f89dda2015-01-22 16:03:33 -08001863 if leader == ONOS1Ip:
Jon Hall6aec96b2015-01-19 14:49:31 -08001864 # all is well
Jon Hall669173b2014-12-17 11:36:30 -08001865 pass
Jon Hall6aec96b2015-01-19 14:49:31 -08001866 elif leader is None:
1867 # No leader elected
1868 main.log.report( "No leader was elected" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001869 leaderResult = main.FALSE
Jon Hall669173b2014-12-17 11:36:30 -08001870 elif leader == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001871 # error in response
1872 # TODO: add check for "Command not found:" in the driver, this
1873 # means the app isn't loaded
Jon Hall8f89dda2015-01-22 16:03:33 -08001874 main.log.report( "Something is wrong with electionTestLeader" +
Jon Hall6aec96b2015-01-19 14:49:31 -08001875 " function, check the error logs" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001876 leaderResult = main.FALSE
Jon Hall669173b2014-12-17 11:36:30 -08001877 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08001878 # error in response
1879 main.log.report(
Jon Hall8f89dda2015-01-22 16:03:33 -08001880 "Unexpected response from electionTestLeader function:'" +
1881 str( leader ) +
Jon Hall6aec96b2015-01-19 14:49:31 -08001882 "'" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001883 leaderResult = main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -08001884
Jon Hall6aec96b2015-01-19 14:49:31 -08001885 # install on other nodes and check for leader.
1886 # Should be onos1 and each app should show the same leader
Jon Hall8f89dda2015-01-22 16:03:33 -08001887 for controller in range( 2, numControllers + 1 ):
Jon Hall6aec96b2015-01-19 14:49:31 -08001888 # loop through ONOScli handlers
1889 node = getattr( main, ( 'ONOScli' + str( controller ) ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001890 node.featureInstall( "onos-app-election" )
1891 leaderN = node.electionTestLeader()
Jon Hall6aec96b2015-01-19 14:49:31 -08001892 # verify leader is ONOS1
Jon Hall8f89dda2015-01-22 16:03:33 -08001893 if leaderN == ONOS1Ip:
Jon Hall6aec96b2015-01-19 14:49:31 -08001894 # all is well
Jon Hall669173b2014-12-17 11:36:30 -08001895 pass
1896 elif leaderN == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001897 # error in response
1898 # TODO: add check for "Command not found:" in the driver, this
1899 # means the app isn't loaded
1900 main.log.report( "Something is wrong with " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001901 "electionTestLeader function, check the" +
Jon Hall6aec96b2015-01-19 14:49:31 -08001902 " error logs" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001903 leaderResult = main.FALSE
Jon Hall669173b2014-12-17 11:36:30 -08001904 elif leader != leaderN:
Jon Hall8f89dda2015-01-22 16:03:33 -08001905 leaderResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001906 main.log.report( "ONOS" + str( controller ) + " sees " +
1907 str( leaderN ) +
1908 " as the leader of the election app. Leader" +
1909 " should be " +
1910 str( leader ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001911 if leaderResult:
Jon Hall6aec96b2015-01-19 14:49:31 -08001912 main.log.report( "Leadership election tests passed( consistent " +
1913 "view of leader across listeners and a leader " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001914 "was elected )" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001915 utilities.assert_equals(
1916 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001917 actual=leaderResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08001918 onpass="Leadership election passed",
1919 onfail="Something went wrong with Leadership election" )
Jon Hall94fd0472014-12-08 11:52:42 -08001920
Jon Hall6aec96b2015-01-19 14:49:31 -08001921 def CASE15( self, main ):
1922 """
Jon Hall669173b2014-12-17 11:36:30 -08001923 Check that Leadership Election is still functional
Jon Hall6aec96b2015-01-19 14:49:31 -08001924 """
Jon Hall8f89dda2015-01-22 16:03:33 -08001925 leaderResult = main.TRUE
Jon Hall669173b2014-12-17 11:36:30 -08001926 description = "Check that Leadership Election is still functional"
Jon Hall6aec96b2015-01-19 14:49:31 -08001927 main.log.report( description )
1928 main.case( description )
1929 main.step( "Find current leader and withdraw" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001930 leader = main.ONOScli1.electionTestLeader()
Jon Hall6aec96b2015-01-19 14:49:31 -08001931 # TODO: do some sanity checking on leader before using it
Jon Hall8f89dda2015-01-22 16:03:33 -08001932 withdrawResult = main.FALSE
1933 if leader == ONOS1Ip:
1934 oldLeader = getattr( main, "ONOScli1" )
1935 elif leader == ONOS2Ip:
1936 oldLeader = getattr( main, "ONOScli2" )
1937 elif leader == ONOS3Ip:
1938 oldLeader = getattr( main, "ONOScli3" )
1939 elif leader == ONOS4Ip:
1940 oldLeader = getattr( main, "ONOScli4" )
1941 elif leader == ONOS5Ip:
1942 oldLeader = getattr( main, "ONOScli5" )
1943 elif leader == ONOS6Ip:
1944 oldLeader = getattr( main, "ONOScli6" )
1945 elif leader == ONOS7Ip:
1946 oldLeader = getattr( main, "ONOScli7" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001947 elif leader is None or leader == main.FALSE:
1948 main.log.report(
1949 "Leader for the election app should be an ONOS node," +
1950 "instead got '" +
Jon Hall8f89dda2015-01-22 16:03:33 -08001951 str( leader ) +
Jon Hall6aec96b2015-01-19 14:49:31 -08001952 "'" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001953 leaderResult = main.FALSE
1954 withdrawResult = oldLeader.electionTestWithdraw()
Jon Hall6aec96b2015-01-19 14:49:31 -08001955 utilities.assert_equals(
1956 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001957 actual=withdrawResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08001958 onpass="App was withdrawn from election",
1959 onfail="App was not withdrawn from election" )
Jon Hall669173b2014-12-17 11:36:30 -08001960
Jon Hall6aec96b2015-01-19 14:49:31 -08001961 main.step( "Make sure new leader is elected" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001962 leaderList = []
1963 for controller in range( 1, numControllers + 1 ):
Jon Hall6aec96b2015-01-19 14:49:31 -08001964 # loop through ONOScli handlers
1965 node = getattr( main, ( 'ONOScli' + str( controller ) ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001966 leaderList.append( node.electionTestLeader() )
1967 for leaderN in leaderList:
Jon Hall669173b2014-12-17 11:36:30 -08001968 if leaderN == leader:
Jon Hall6aec96b2015-01-19 14:49:31 -08001969 main.log.report(
1970 "ONOS" +
1971 str( controller ) +
1972 " still sees " +
1973 str( leader ) +
1974 " as leader after they withdrew" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001975 leaderResult = main.FALSE
Jon Hall669173b2014-12-17 11:36:30 -08001976 elif leaderN == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001977 # error in response
1978 # TODO: add check for "Command not found:" in the driver, this
1979 # means the app isn't loaded
1980 main.log.report( "Something is wrong with " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001981 "electionTestLeader function, " +
Jon Hall6aec96b2015-01-19 14:49:31 -08001982 "check the error logs" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001983 leaderResult = main.FALSE
1984 consistentLeader = main.FALSE
1985 if len( set( leaderList ) ) == 1:
Jon Hall6aec96b2015-01-19 14:49:31 -08001986 main.log.info( "Each Election-app sees '" +
Jon Hall8f89dda2015-01-22 16:03:33 -08001987 str( leaderList[ 0 ] ) +
Jon Hall6aec96b2015-01-19 14:49:31 -08001988 "' as the leader" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001989 consistentLeader = main.TRUE
Jon Hall669173b2014-12-17 11:36:30 -08001990 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08001991 main.log.report(
1992 "Inconsistent responses for leader of Election-app:" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001993 for n in range( len( leaderList ) ):
Jon Hall6aec96b2015-01-19 14:49:31 -08001994 main.log.report( "ONOS" + str( n + 1 ) + " response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001995 str( leaderList[ n ] ) )
1996 if leaderResult:
1997 main.log.report( "Leadership election tests passed( consistent " +
Jon Hall6aec96b2015-01-19 14:49:31 -08001998 "view of leader across listeners and a new " +
1999 "leader was elected when the old leader " +
Jon Hall8f89dda2015-01-22 16:03:33 -08002000 "resigned )" )
Jon Hall6aec96b2015-01-19 14:49:31 -08002001 utilities.assert_equals(
2002 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08002003 actual=leaderResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08002004 onpass="Leadership election passed",
2005 onfail="Something went wrong with Leadership election" )
Jon Hall669173b2014-12-17 11:36:30 -08002006
Jon Hall6aec96b2015-01-19 14:49:31 -08002007 main.step(
Jon Hall8f89dda2015-01-22 16:03:33 -08002008 "Run for election on old leader( just so everyone is in the hat )" )
2009 runResult = oldLeader.electionTestRun()
Jon Hall6aec96b2015-01-19 14:49:31 -08002010 utilities.assert_equals(
2011 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08002012 actual=runResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08002013 onpass="App re-ran for election",
2014 onfail="App failed to run for election" )
Jon Hall8f89dda2015-01-22 16:03:33 -08002015 if consistentLeader == main.TRUE:
2016 afterRun = main.ONOScli1.electionTestLeader()
Jon Hall6aec96b2015-01-19 14:49:31 -08002017 # verify leader didn't just change
Jon Hall8f89dda2015-01-22 16:03:33 -08002018 if afterRun == leaderList[ 0 ]:
2019 leaderResult = main.TRUE
Jon Hall669173b2014-12-17 11:36:30 -08002020 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08002021 leaderResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08002022 # TODO: assert on run and withdraw results?
Jon Hall669173b2014-12-17 11:36:30 -08002023
Jon Hall6aec96b2015-01-19 14:49:31 -08002024 utilities.assert_equals(
2025 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08002026 actual=leaderResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08002027 onpass="Leadership election passed",
2028 onfail="Something went wrong with Leadership election after " +
2029 "the old leader re-ran for election" )