blob: 9a95e788694183a7739bdbf6a00e3c04bde4c724 [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 Hall6aec96b2015-01-19 14:49:31 -0800107 main.step( "Compiling the latest version of ONOS" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800108 if PULLCODE:
Jon Hall6aec96b2015-01-19 14:49:31 -0800109 # TODO Configure branch in params
110 main.step( "Git checkout and pull master" )
Jon Hall529a37f2015-01-28 10:02:00 -0800111 main.ONOSbench.gitCheckout( gitBranch )
Jon Hall8f89dda2015-01-22 16:03:33 -0800112 gitPullResult = main.ONOSbench.gitPull()
Jon Hallb1290e82014-11-18 16:17:48 -0500113
Jon Hall6aec96b2015-01-19 14:49:31 -0800114 main.step( "Using mvn clean & install" )
Jon Hall529a37f2015-01-28 10:02:00 -0800115 cleanInstallResult = main.ONOSbench.cleanInstall()
116 else:
117 main.log.warn( "Did not pull new code so skipping mvn " +
118 "clean install" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800119 main.ONOSbench.getVersion( report=True )
Jon Hallb1290e82014-11-18 16:17:48 -0500120
Jon Hall6aec96b2015-01-19 14:49:31 -0800121 main.step( "Creating ONOS package" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800122 packageResult = main.ONOSbench.onosPackage()
Jon Hallb1290e82014-11-18 16:17:48 -0500123
Jon Hall6aec96b2015-01-19 14:49:31 -0800124 main.step( "Installing ONOS package" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800125 onos1InstallResult = main.ONOSbench.onosInstall( options="-f",
126 node=ONOS1Ip )
127 onos2InstallResult = main.ONOSbench.onosInstall( options="-f",
128 node=ONOS2Ip )
129 onos3InstallResult = main.ONOSbench.onosInstall( options="-f",
130 node=ONOS3Ip )
131 onos4InstallResult = main.ONOSbench.onosInstall( options="-f",
132 node=ONOS4Ip )
133 onos5InstallResult = main.ONOSbench.onosInstall( options="-f",
134 node=ONOS5Ip )
135 onos6InstallResult = main.ONOSbench.onosInstall( options="-f",
136 node=ONOS6Ip )
137 onos7InstallResult = main.ONOSbench.onosInstall( options="-f",
138 node=ONOS7Ip )
139 onosInstallResult = onos1InstallResult and onos2InstallResult\
140 and onos3InstallResult and onos4InstallResult\
141 and onos5InstallResult and onos6InstallResult\
142 and onos7InstallResult
Jon Hallb1290e82014-11-18 16:17:48 -0500143
Jon Hall6aec96b2015-01-19 14:49:31 -0800144 main.step( "Checking if ONOS is up yet" )
145 # TODO check bundle:list?
146 for i in range( 2 ):
Jon Hall8f89dda2015-01-22 16:03:33 -0800147 onos1Isup = main.ONOSbench.isup( ONOS1Ip )
148 if not onos1Isup:
Jon Hall6aec96b2015-01-19 14:49:31 -0800149 main.log.report( "ONOS1 didn't start!" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800150 onos2Isup = main.ONOSbench.isup( ONOS2Ip )
151 if not onos2Isup:
Jon Hall6aec96b2015-01-19 14:49:31 -0800152 main.log.report( "ONOS2 didn't start!" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800153 onos3Isup = main.ONOSbench.isup( ONOS3Ip )
154 if not onos3Isup:
Jon Hall6aec96b2015-01-19 14:49:31 -0800155 main.log.report( "ONOS3 didn't start!" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800156 onos4Isup = main.ONOSbench.isup( ONOS4Ip )
157 if not onos4Isup:
Jon Hall6aec96b2015-01-19 14:49:31 -0800158 main.log.report( "ONOS4 didn't start!" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800159 onos5Isup = main.ONOSbench.isup( ONOS5Ip )
160 if not onos5Isup:
Jon Hall6aec96b2015-01-19 14:49:31 -0800161 main.log.report( "ONOS5 didn't start!" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800162 onos6Isup = main.ONOSbench.isup( ONOS6Ip )
163 if not onos6Isup:
Jon Hall6aec96b2015-01-19 14:49:31 -0800164 main.log.report( "ONOS6 didn't start!" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800165 onos7Isup = main.ONOSbench.isup( ONOS7Ip )
166 if not onos7Isup:
Jon Hall6aec96b2015-01-19 14:49:31 -0800167 main.log.report( "ONOS7 didn't start!" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800168 onosIsupResult = onos1Isup and onos2Isup and onos3Isup\
169 and onos4Isup and onos5Isup and onos6Isup and onos7Isup
170 if onosIsupResult == main.TRUE:
Jon Hallffb386d2014-11-21 13:43:38 -0800171 break
Jon Hallb1290e82014-11-18 16:17:48 -0500172
Jon Hall8f89dda2015-01-22 16:03:33 -0800173 cliResult1 = main.ONOScli1.startOnosCli( ONOS1Ip )
174 cliResult2 = main.ONOScli2.startOnosCli( ONOS2Ip )
175 cliResult3 = main.ONOScli3.startOnosCli( ONOS3Ip )
176 cliResult4 = main.ONOScli4.startOnosCli( ONOS4Ip )
177 cliResult5 = main.ONOScli5.startOnosCli( ONOS5Ip )
178 cliResult6 = main.ONOScli6.startOnosCli( ONOS6Ip )
179 cliResult7 = main.ONOScli7.startOnosCli( ONOS7Ip )
180 cliResults = cliResult1 and cliResult2 and cliResult3 and\
181 cliResult4 and cliResult5 and cliResult6 and cliResult7
Jon Hallb1290e82014-11-18 16:17:48 -0500182
Jon Hall6aec96b2015-01-19 14:49:31 -0800183 main.step( "Start Packet Capture MN" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800184 main.Mininet2.startTcpdump(
Jon Hall6aec96b2015-01-19 14:49:31 -0800185 str( main.params[ 'MNtcpdump' ][ 'folder' ] ) + str( main.TEST )
186 + "-MN.pcap",
187 intf=main.params[ 'MNtcpdump' ][ 'intf' ],
188 port=main.params[ 'MNtcpdump' ][ 'port' ] )
Jon Hallb1290e82014-11-18 16:17:48 -0500189
Jon Hall8f89dda2015-01-22 16:03:33 -0800190 case1Result = ( cleanInstallResult and packageResult and
191 cellResult and verifyResult and onosInstallResult
192 and onosIsupResult and cliResults )
Jon Hallb1290e82014-11-18 16:17:48 -0500193
Jon Hall8f89dda2015-01-22 16:03:33 -0800194 utilities.assert_equals( expect=main.TRUE, actual=case1Result,
195 onpass="Test startup successful",
196 onfail="Test startup NOT successful" )
Jon Hallb1290e82014-11-18 16:17:48 -0500197
Jon Hall8f89dda2015-01-22 16:03:33 -0800198 if case1Result == main.FALSE:
Jon Hallffb386d2014-11-21 13:43:38 -0800199 main.cleanup()
200 main.exit()
Jon Hallb1290e82014-11-18 16:17:48 -0500201
Jon Hall6aec96b2015-01-19 14:49:31 -0800202 def CASE2( self, main ):
203 """
Jon Hallb1290e82014-11-18 16:17:48 -0500204 Assign mastership to controllers
Jon Hall6aec96b2015-01-19 14:49:31 -0800205 """
Jon Hallb1290e82014-11-18 16:17:48 -0500206 import re
207
Jon Hall6aec96b2015-01-19 14:49:31 -0800208 main.log.report( "Assigning switches to controllers" )
209 main.case( "Assigning Controllers" )
210 main.step( "Assign switches to controllers" )
Jon Hallb1290e82014-11-18 16:17:48 -0500211
Jon Hall6aec96b2015-01-19 14:49:31 -0800212 for i in range( 1, 29 ):
Jon Hall8f89dda2015-01-22 16:03:33 -0800213 main.Mininet1.assignSwController(
Jon Hall6aec96b2015-01-19 14:49:31 -0800214 sw=str( i ),
Jon Hall8f89dda2015-01-22 16:03:33 -0800215 count=numControllers,
216 ip1=ONOS1Ip, port1=ONOS1Port,
217 ip2=ONOS2Ip, port2=ONOS2Port,
218 ip3=ONOS3Ip, port3=ONOS3Port,
219 ip4=ONOS4Ip, port4=ONOS4Port,
220 ip5=ONOS5Ip, port5=ONOS5Port,
221 ip6=ONOS6Ip, port6=ONOS6Port,
222 ip7=ONOS7Ip, port7=ONOS7Port )
Jon Hallb1290e82014-11-18 16:17:48 -0500223
Jon Hall8f89dda2015-01-22 16:03:33 -0800224 mastershipCheck = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800225 for i in range( 1, 29 ):
Jon Hall8f89dda2015-01-22 16:03:33 -0800226 response = main.Mininet1.getSwController( "s" + str( i ) )
Jon Hallffb386d2014-11-21 13:43:38 -0800227 try:
Jon Hall6aec96b2015-01-19 14:49:31 -0800228 main.log.info( str( response ) )
Jon Hallffb386d2014-11-21 13:43:38 -0800229 except:
Jon Hall6aec96b2015-01-19 14:49:31 -0800230 main.log.info( repr( response ) )
Jon Hall8f89dda2015-01-22 16:03:33 -0800231 if re.search( "tcp:" + ONOS1Ip, response )\
232 and re.search( "tcp:" + ONOS2Ip, response )\
233 and re.search( "tcp:" + ONOS3Ip, response )\
234 and re.search( "tcp:" + ONOS4Ip, response )\
235 and re.search( "tcp:" + ONOS5Ip, response )\
236 and re.search( "tcp:" + ONOS6Ip, response )\
237 and re.search( "tcp:" + ONOS7Ip, response ):
238 mastershipCheck = mastershipCheck and main.TRUE
Jon Hallb1290e82014-11-18 16:17:48 -0500239 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800240 mastershipCheck = main.FALSE
241 if mastershipCheck == main.TRUE:
Jon Hall6aec96b2015-01-19 14:49:31 -0800242 main.log.report( "Switch mastership assigned correctly" )
243 utilities.assert_equals(
244 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800245 actual=mastershipCheck,
Jon Hall6aec96b2015-01-19 14:49:31 -0800246 onpass="Switch mastership assigned correctly",
247 onfail="Switches not assigned correctly to controllers" )
Jon Hallb1290e82014-11-18 16:17:48 -0500248
Jon Hall6aec96b2015-01-19 14:49:31 -0800249 # Manually assign mastership to the controller we want
Jon Hall8f89dda2015-01-22 16:03:33 -0800250 roleCall = main.TRUE
251 roleCheck = main.TRUE
Jon Hall94fd0472014-12-08 11:52:42 -0800252
Jon Hall6aec96b2015-01-19 14:49:31 -0800253 # Assign switch
Jon Hall8f89dda2015-01-22 16:03:33 -0800254 deviceId = main.ONOScli1.getDevice( "1000" ).get( 'id' )
255 roleCall = roleCall and main.ONOScli1.deviceRole(
256 deviceId,
257 ONOS1Ip )
Jon Hall6aec96b2015-01-19 14:49:31 -0800258 # Check assignment
Jon Hall8f89dda2015-01-22 16:03:33 -0800259 if ONOS1Ip in main.ONOScli1.getRole( deviceId ).get( 'master' ):
260 roleCheck = roleCheck and main.TRUE
Jon Hall94fd0472014-12-08 11:52:42 -0800261 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800262 roleCheck = roleCheck and main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -0800263
Jon Hall6aec96b2015-01-19 14:49:31 -0800264 # Assign switch
Jon Hall8f89dda2015-01-22 16:03:33 -0800265 deviceId = main.ONOScli1.getDevice( "2800" ).get( 'id' )
266 roleCall = roleCall and main.ONOScli1.deviceRole(
267 deviceId,
268 ONOS1Ip )
Jon Hall6aec96b2015-01-19 14:49:31 -0800269 # Check assignment
Jon Hall8f89dda2015-01-22 16:03:33 -0800270 if ONOS1Ip in main.ONOScli1.getRole( deviceId ).get( 'master' ):
271 roleCheck = roleCheck and main.TRUE
Jon Hall94fd0472014-12-08 11:52:42 -0800272 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800273 roleCheck = roleCheck and main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -0800274
Jon Hall6aec96b2015-01-19 14:49:31 -0800275 # Assign switch
Jon Hall8f89dda2015-01-22 16:03:33 -0800276 deviceId = main.ONOScli1.getDevice( "2000" ).get( 'id' )
277 roleCall = roleCall and main.ONOScli1.deviceRole(
278 deviceId,
279 ONOS2Ip )
Jon Hall6aec96b2015-01-19 14:49:31 -0800280 # Check assignment
Jon Hall8f89dda2015-01-22 16:03:33 -0800281 if ONOS2Ip in main.ONOScli1.getRole( deviceId ).get( 'master' ):
282 roleCheck = roleCheck and main.TRUE
Jon Hall94fd0472014-12-08 11:52:42 -0800283 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800284 roleCheck = roleCheck and main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -0800285
Jon Hall6aec96b2015-01-19 14:49:31 -0800286 # Assign switch
Jon Hall8f89dda2015-01-22 16:03:33 -0800287 deviceId = main.ONOScli1.getDevice( "3000" ).get( 'id' )
288 roleCall = roleCall and main.ONOScli1.deviceRole(
289 deviceId,
290 ONOS2Ip )
Jon Hall6aec96b2015-01-19 14:49:31 -0800291 # Check assignment
Jon Hall8f89dda2015-01-22 16:03:33 -0800292 if ONOS2Ip in main.ONOScli1.getRole( deviceId ).get( 'master' ):
293 roleCheck = roleCheck and main.TRUE
Jon Hall94fd0472014-12-08 11:52:42 -0800294 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800295 roleCheck = roleCheck and main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -0800296
Jon Hall6aec96b2015-01-19 14:49:31 -0800297 # Assign switch
Jon Hall8f89dda2015-01-22 16:03:33 -0800298 deviceId = main.ONOScli1.getDevice( "5000" ).get( 'id' )
299 roleCall = roleCall and main.ONOScli1.deviceRole(
300 deviceId,
301 ONOS3Ip )
Jon Hall6aec96b2015-01-19 14:49:31 -0800302 # Check assignment
Jon Hall8f89dda2015-01-22 16:03:33 -0800303 if ONOS3Ip in main.ONOScli1.getRole( deviceId ).get( 'master' ):
304 roleCheck = roleCheck and main.TRUE
Jon Hall94fd0472014-12-08 11:52:42 -0800305 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800306 roleCheck = roleCheck and main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -0800307
Jon Hall6aec96b2015-01-19 14:49:31 -0800308 # Assign switch
Jon Hall8f89dda2015-01-22 16:03:33 -0800309 deviceId = main.ONOScli1.getDevice( "6000" ).get( 'id' )
310 roleCall = roleCall and main.ONOScli1.deviceRole(
311 deviceId,
312 ONOS3Ip )
Jon Hall6aec96b2015-01-19 14:49:31 -0800313 # Check assignment
Jon Hall8f89dda2015-01-22 16:03:33 -0800314 if ONOS3Ip in main.ONOScli1.getRole( deviceId ).get( 'master' ):
315 roleCheck = roleCheck and main.TRUE
Jon Hall94fd0472014-12-08 11:52:42 -0800316 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800317 roleCheck = roleCheck and main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -0800318
Jon Hall6aec96b2015-01-19 14:49:31 -0800319 # Assign switch
Jon Hall8f89dda2015-01-22 16:03:33 -0800320 deviceId = main.ONOScli1.getDevice( "3004" ).get( 'id' )
321 roleCall = roleCall and main.ONOScli1.deviceRole(
322 deviceId,
323 ONOS4Ip )
Jon Hall6aec96b2015-01-19 14:49:31 -0800324 # Check assignment
Jon Hall8f89dda2015-01-22 16:03:33 -0800325 if ONOS4Ip in main.ONOScli1.getRole( deviceId ).get( 'master' ):
326 roleCheck = roleCheck and main.TRUE
Jon Hall94fd0472014-12-08 11:52:42 -0800327 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800328 roleCheck = roleCheck and main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -0800329
Jon Hall6aec96b2015-01-19 14:49:31 -0800330 for i in range( 8, 18 ):
331 dpid = '3' + str( i ).zfill( 3 )
Jon Hall8f89dda2015-01-22 16:03:33 -0800332 deviceId = main.ONOScli1.getDevice( dpid ).get( 'id' )
333 roleCall = roleCall and main.ONOScli1.deviceRole(
334 deviceId,
335 ONOS5Ip )
Jon Hall6aec96b2015-01-19 14:49:31 -0800336 # Check assignment
Jon Hall8f89dda2015-01-22 16:03:33 -0800337 if ONOS5Ip in main.ONOScli1.getRole( deviceId ).get( 'master' ):
338 roleCheck = roleCheck and main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800339 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800340 roleCheck = roleCheck and main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -0800341
Jon Hall8f89dda2015-01-22 16:03:33 -0800342 deviceId = main.ONOScli1.getDevice( "6007" ).get( 'id' )
343 roleCall = roleCall and main.ONOScli1.deviceRole(
344 deviceId,
345 ONOS6Ip )
Jon Hall6aec96b2015-01-19 14:49:31 -0800346 # Check assignment
Jon Hall8f89dda2015-01-22 16:03:33 -0800347 if ONOS6Ip in main.ONOScli1.getRole( deviceId ).get( 'master' ):
348 roleCheck = roleCheck and main.TRUE
Jon Hall94fd0472014-12-08 11:52:42 -0800349 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800350 roleCheck = roleCheck and main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -0800351
Jon Hall6aec96b2015-01-19 14:49:31 -0800352 for i in range( 18, 28 ):
353 dpid = '6' + str( i ).zfill( 3 )
Jon Hall8f89dda2015-01-22 16:03:33 -0800354 deviceId = main.ONOScli1.getDevice( dpid ).get( 'id' )
355 roleCall = roleCall and main.ONOScli1.deviceRole(
356 deviceId,
357 ONOS7Ip )
Jon Hall6aec96b2015-01-19 14:49:31 -0800358 # Check assignment
Jon Hall8f89dda2015-01-22 16:03:33 -0800359 if ONOS7Ip in main.ONOScli1.getRole( deviceId ).get( 'master' ):
360 roleCheck = roleCheck and main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800361 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800362 roleCheck = roleCheck and main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -0800363
Jon Hall6aec96b2015-01-19 14:49:31 -0800364 utilities.assert_equals(
365 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800366 actual=roleCall,
Jon Hall6aec96b2015-01-19 14:49:31 -0800367 onpass="Re-assigned switch mastership to designated controller",
Jon Hall8f89dda2015-01-22 16:03:33 -0800368 onfail="Something wrong with deviceRole calls" )
Jon Hall94fd0472014-12-08 11:52:42 -0800369
Jon Hall6aec96b2015-01-19 14:49:31 -0800370 utilities.assert_equals(
371 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800372 actual=roleCheck,
Jon Hall6aec96b2015-01-19 14:49:31 -0800373 onpass="Switches were successfully reassigned to designated " +
374 "controller",
375 onfail="Switches were not successfully reassigned" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800376 mastershipCheck = mastershipCheck and roleCall and roleCheck
377 utilities.assert_equals( expect=main.TRUE, actual=mastershipCheck,
Jon Hall6aec96b2015-01-19 14:49:31 -0800378 onpass="Switch mastership correctly assigned",
379 onfail="Error in (re)assigning switch" +
Jon Hall8f89dda2015-01-22 16:03:33 -0800380 " mastership" )
Jon Hallb1290e82014-11-18 16:17:48 -0500381
Jon Hall6aec96b2015-01-19 14:49:31 -0800382 def CASE3( self, main ):
Jon Hallb1290e82014-11-18 16:17:48 -0500383 """
384 Assign intents
Jon Hallb1290e82014-11-18 16:17:48 -0500385 """
386 import time
Jon Hall6aec96b2015-01-19 14:49:31 -0800387 main.log.report( "Adding host intents" )
388 main.case( "Adding host Intents" )
Jon Hallb1290e82014-11-18 16:17:48 -0500389
Jon Hall8f89dda2015-01-22 16:03:33 -0800390 main.step( "Discovering Hosts( Via pingall for now )" )
Jon Hall6aec96b2015-01-19 14:49:31 -0800391 # FIXME: Once we have a host discovery mechanism, use that instead
Jon Hallb1290e82014-11-18 16:17:48 -0500392
Jon Hall6aec96b2015-01-19 14:49:31 -0800393 # install onos-app-fwd
394 main.log.info( "Install reactive forwarding app" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800395 main.ONOScli1.featureInstall( "onos-app-fwd" )
396 main.ONOScli2.featureInstall( "onos-app-fwd" )
397 main.ONOScli3.featureInstall( "onos-app-fwd" )
398 main.ONOScli4.featureInstall( "onos-app-fwd" )
399 main.ONOScli5.featureInstall( "onos-app-fwd" )
400 main.ONOScli6.featureInstall( "onos-app-fwd" )
401 main.ONOScli7.featureInstall( "onos-app-fwd" )
Jon Hall94fd0472014-12-08 11:52:42 -0800402
Jon Hall6aec96b2015-01-19 14:49:31 -0800403 # REACTIVE FWD test
Jon Hall8f89dda2015-01-22 16:03:33 -0800404 pingResult = main.FALSE
Jon Hallb1290e82014-11-18 16:17:48 -0500405 time1 = time.time()
Jon Hall8f89dda2015-01-22 16:03:33 -0800406 pingResult = main.Mininet1.pingall()
Jon Hall529a37f2015-01-28 10:02:00 -0800407 utilities.assert_equals(
408 expect=main.TRUE,
409 actual=pingResult,
410 onpass="Reactive Pingall test passed",
411 onfail="Reactive Pingall failed, one or more ping pairs failed" )
Jon Hallb1290e82014-11-18 16:17:48 -0500412 time2 = time.time()
Jon Hall6aec96b2015-01-19 14:49:31 -0800413 main.log.info( "Time for pingall: %2f seconds" % ( time2 - time1 ) )
Jon Hallb1290e82014-11-18 16:17:48 -0500414
Jon Hall6aec96b2015-01-19 14:49:31 -0800415 # uninstall onos-app-fwd
416 main.log.info( "Uninstall reactive forwarding app" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800417 main.ONOScli1.featureUninstall( "onos-app-fwd" )
418 main.ONOScli2.featureUninstall( "onos-app-fwd" )
419 main.ONOScli3.featureUninstall( "onos-app-fwd" )
420 main.ONOScli4.featureUninstall( "onos-app-fwd" )
421 main.ONOScli5.featureUninstall( "onos-app-fwd" )
422 main.ONOScli6.featureUninstall( "onos-app-fwd" )
423 main.ONOScli7.featureUninstall( "onos-app-fwd" )
Jon Hall6aec96b2015-01-19 14:49:31 -0800424 # timeout for fwd flows
425 time.sleep( 10 )
Jon Hallb1290e82014-11-18 16:17:48 -0500426
Jon Hall6aec96b2015-01-19 14:49:31 -0800427 main.step( "Add host intents" )
428 # TODO: move the host numbers to params
Jon Hall8f89dda2015-01-22 16:03:33 -0800429 intentAddResult = True
Jon Hall6aec96b2015-01-19 14:49:31 -0800430 for i in range( 8, 18 ):
431 main.log.info( "Adding host intent between h" + str( i ) +
432 " and h" + str( i + 10 ) )
433 host1 = "00:00:00:00:00:" + \
434 str( hex( i )[ 2: ] ).zfill( 2 ).upper()
435 host2 = "00:00:00:00:00:" + \
436 str( hex( i + 10 )[ 2: ] ).zfill( 2 ).upper()
Jon Hall8f89dda2015-01-22 16:03:33 -0800437 host1Id = main.ONOScli1.getHost( host1 )[ 'id' ]
438 host2Id = main.ONOScli1.getHost( host2 )[ 'id' ]
Jon Hall6aec96b2015-01-19 14:49:31 -0800439 # NOTE: get host can return None
Jon Hall8f89dda2015-01-22 16:03:33 -0800440 if host1Id and host2Id:
441 tmpResult = main.ONOScli1.addHostIntent(
442 host1Id,
443 host2Id )
Jon Hall669173b2014-12-17 11:36:30 -0800444 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800445 main.log.error( "Error, getHost() failed" )
446 tmpResult = main.FALSE
447 intentAddResult = bool( pingResult and intentAddResult
448 and tmpResult )
449 # TODO Check that intents were added?
Jon Hall6aec96b2015-01-19 14:49:31 -0800450 utilities.assert_equals(
451 expect=True,
Jon Hall8f89dda2015-01-22 16:03:33 -0800452 actual=intentAddResult,
453 onpass="Pushed host intents to ONOS",
454 onfail="Error in pushing host intents to ONOS" )
Jon Hall6aec96b2015-01-19 14:49:31 -0800455 # TODO Check if intents all exist in datastore
Jon Hallb1290e82014-11-18 16:17:48 -0500456
Jon Hall6aec96b2015-01-19 14:49:31 -0800457 def CASE4( self, main ):
Jon Hallb1290e82014-11-18 16:17:48 -0500458 """
459 Ping across added host intents
460 """
Jon Hall368769f2014-11-19 15:43:35 -0800461 description = " Ping across added host intents"
Jon Hall6aec96b2015-01-19 14:49:31 -0800462 main.log.report( description )
463 main.case( description )
Jon Hall8f89dda2015-01-22 16:03:33 -0800464 PingResult = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800465 for i in range( 8, 18 ):
466 ping = main.Mininet1.pingHost(
467 src="h" + str( i ), target="h" + str( i + 10 ) )
Jon Hall8f89dda2015-01-22 16:03:33 -0800468 PingResult = PingResult and ping
Jon Hall6aec96b2015-01-19 14:49:31 -0800469 if ping == main.FALSE:
470 main.log.warn( "Ping failed between h" + str( i ) +
471 " and h" + str( i + 10 ) )
472 elif ping == main.TRUE:
473 main.log.info( "Ping test passed!" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800474 PingResult = main.TRUE
475 if PingResult == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -0800476 main.log.report(
477 "Intents have not been installed correctly, pings failed." )
Jon Hall529a37f2015-01-28 10:02:00 -0800478 #TODO: pretty print
479 main.log.warn( "ONSO1 intents: " )
480 main.log.warn( json.dumps( json.loads( main.ONOScli1.intents() ),
481 sort_keys=True,
482 indent=4,
483 separators=( ',', ': ' ) ) )
Jon Hall8f89dda2015-01-22 16:03:33 -0800484 if PingResult == main.TRUE:
Jon Hall6aec96b2015-01-19 14:49:31 -0800485 main.log.report(
486 "Intents have been installed correctly and verified by pings" )
487 utilities.assert_equals(
488 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800489 actual=PingResult,
Jon Hall6aec96b2015-01-19 14:49:31 -0800490 onpass="Intents have been installed correctly and pings work",
491 onfail="Intents have not been installed correctly, pings failed." )
Jon Hallb1290e82014-11-18 16:17:48 -0500492
Jon Hall6aec96b2015-01-19 14:49:31 -0800493 def CASE5( self, main ):
494 """
Jon Hallb1290e82014-11-18 16:17:48 -0500495 Reading state of ONOS
Jon Hall6aec96b2015-01-19 14:49:31 -0800496 """
Jon Hallb1290e82014-11-18 16:17:48 -0500497 import json
Jon Hall6aec96b2015-01-19 14:49:31 -0800498 # assumes that sts is already in you PYTHONPATH
499 from sts.topology.teston_topology import TestONTopology
Jon Hallb1290e82014-11-18 16:17:48 -0500500
Jon Hall6aec96b2015-01-19 14:49:31 -0800501 main.log.report( "Setting up and gathering data for current state" )
502 main.case( "Setting up and gathering data for current state" )
503 # The general idea for this test case is to pull the state of
504 # ( intents,flows, topology,... ) from each ONOS node
505 # We can then compare them with eachother and also with past states
Jon Hallb1290e82014-11-18 16:17:48 -0500506
Jon Hall6aec96b2015-01-19 14:49:31 -0800507 main.step( "Get the Mastership of each switch from each controller" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800508 global mastershipState
509 mastershipState = []
Jon Hall94fd0472014-12-08 11:52:42 -0800510
Jon Hall6aec96b2015-01-19 14:49:31 -0800511 # Assert that each device has a master
Jon Hall8f89dda2015-01-22 16:03:33 -0800512 ONOS1MasterNotNull = main.ONOScli1.rolesNotNull()
513 ONOS2MasterNotNull = main.ONOScli2.rolesNotNull()
514 ONOS3MasterNotNull = main.ONOScli3.rolesNotNull()
515 ONOS4MasterNotNull = main.ONOScli4.rolesNotNull()
516 ONOS5MasterNotNull = main.ONOScli5.rolesNotNull()
517 ONOS6MasterNotNull = main.ONOScli6.rolesNotNull()
518 ONOS7MasterNotNull = main.ONOScli7.rolesNotNull()
519 rolesNotNull = ONOS1MasterNotNull and ONOS2MasterNotNull and\
520 ONOS3MasterNotNull and ONOS4MasterNotNull and\
521 ONOS5MasterNotNull and ONOS6MasterNotNull and\
522 ONOS7MasterNotNull
Jon Hall6aec96b2015-01-19 14:49:31 -0800523 utilities.assert_equals(
524 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800525 actual=rolesNotNull,
Jon Hall6aec96b2015-01-19 14:49:31 -0800526 onpass="Each device has a master",
527 onfail="Some devices don't have a master assigned" )
Jon Hall94fd0472014-12-08 11:52:42 -0800528
Jon Hall8f89dda2015-01-22 16:03:33 -0800529 ONOS1Mastership = main.ONOScli1.roles()
530 ONOS2Mastership = main.ONOScli2.roles()
531 ONOS3Mastership = main.ONOScli3.roles()
532 ONOS4Mastership = main.ONOScli4.roles()
533 ONOS5Mastership = main.ONOScli5.roles()
534 ONOS6Mastership = main.ONOScli6.roles()
535 ONOS7Mastership = main.ONOScli7.roles()
536 # print json.dumps( json.loads( ONOS1Mastership ), sort_keys=True,
Jon Hall6aec96b2015-01-19 14:49:31 -0800537 # indent=4, separators=( ',', ': ' ) )
Jon Hall8f89dda2015-01-22 16:03:33 -0800538 if "Error" in ONOS1Mastership or not ONOS1Mastership\
539 or "Error" in ONOS2Mastership or not ONOS2Mastership\
540 or "Error" in ONOS3Mastership or not ONOS3Mastership\
541 or "Error" in ONOS4Mastership or not ONOS4Mastership\
542 or "Error" in ONOS5Mastership or not ONOS5Mastership\
543 or "Error" in ONOS6Mastership or not ONOS6Mastership\
544 or "Error" in ONOS7Mastership or not ONOS7Mastership:
Jon Hall6aec96b2015-01-19 14:49:31 -0800545 main.log.report( "Error in getting ONOS roles" )
546 main.log.warn(
547 "ONOS1 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800548 repr( ONOS1Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -0800549 main.log.warn(
550 "ONOS2 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800551 repr( ONOS2Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -0800552 main.log.warn(
553 "ONOS3 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800554 repr( ONOS3Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -0800555 main.log.warn(
556 "ONOS4 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800557 repr( ONOS4Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -0800558 main.log.warn(
559 "ONOS5 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800560 repr( ONOS5Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -0800561 main.log.warn(
562 "ONOS6 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800563 repr( ONOS6Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -0800564 main.log.warn(
565 "ONOS7 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800566 repr( ONOS7Mastership ) )
567 consistentMastership = main.FALSE
568 elif ONOS1Mastership == ONOS2Mastership\
569 and ONOS1Mastership == ONOS3Mastership\
570 and ONOS1Mastership == ONOS4Mastership\
571 and ONOS1Mastership == ONOS5Mastership\
572 and ONOS1Mastership == ONOS6Mastership\
573 and ONOS1Mastership == ONOS7Mastership:
574 mastershipState = ONOS1Mastership
575 consistentMastership = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800576 main.log.report(
577 "Switch roles are consistent across all ONOS nodes" )
Jon Hallb1290e82014-11-18 16:17:48 -0500578 else:
Jon Hall6aec96b2015-01-19 14:49:31 -0800579 main.log.warn(
580 "ONOS1 roles: ",
581 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800582 json.loads( ONOS1Mastership ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800583 sort_keys=True,
584 indent=4,
585 separators=(
586 ',',
587 ': ' ) ) )
588 main.log.warn(
589 "ONOS2 roles: ",
590 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800591 json.loads( ONOS2Mastership ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800592 sort_keys=True,
593 indent=4,
594 separators=(
595 ',',
596 ': ' ) ) )
597 main.log.warn(
598 "ONOS3 roles: ",
599 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800600 json.loads( ONOS3Mastership ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800601 sort_keys=True,
602 indent=4,
603 separators=(
604 ',',
605 ': ' ) ) )
606 main.log.warn(
607 "ONOS4 roles: ",
608 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800609 json.loads( ONOS4Mastership ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800610 sort_keys=True,
611 indent=4,
612 separators=(
613 ',',
614 ': ' ) ) )
615 main.log.warn(
616 "ONOS5 roles: ",
617 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800618 json.loads( ONOS5Mastership ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800619 sort_keys=True,
620 indent=4,
621 separators=(
622 ',',
623 ': ' ) ) )
624 main.log.warn(
625 "ONOS6 roles: ",
626 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800627 json.loads( ONOS6Mastership ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800628 sort_keys=True,
629 indent=4,
630 separators=(
631 ',',
632 ': ' ) ) )
633 main.log.warn(
634 "ONOS7 roles: ",
635 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800636 json.loads( ONOS7Mastership ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800637 sort_keys=True,
638 indent=4,
639 separators=(
640 ',',
641 ': ' ) ) )
Jon Hall8f89dda2015-01-22 16:03:33 -0800642 consistentMastership = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -0800643 utilities.assert_equals(
644 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800645 actual=consistentMastership,
Jon Hall6aec96b2015-01-19 14:49:31 -0800646 onpass="Switch roles are consistent across all ONOS nodes",
647 onfail="ONOS nodes have different views of switch roles" )
Jon Hallb1290e82014-11-18 16:17:48 -0500648
Jon Hall6aec96b2015-01-19 14:49:31 -0800649 main.step( "Get the intents from each controller" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800650 global intentState
651 intentState = []
652 ONOS1Intents = main.ONOScli1.intents( jsonFormat=True )
653 ONOS2Intents = main.ONOScli2.intents( jsonFormat=True )
654 ONOS3Intents = main.ONOScli3.intents( jsonFormat=True )
655 ONOS4Intents = main.ONOScli4.intents( jsonFormat=True )
656 ONOS5Intents = main.ONOScli5.intents( jsonFormat=True )
657 ONOS6Intents = main.ONOScli6.intents( jsonFormat=True )
658 ONOS7Intents = main.ONOScli7.intents( jsonFormat=True )
659 intentCheck = main.FALSE
660 if "Error" in ONOS1Intents or not ONOS1Intents\
661 or "Error" in ONOS2Intents or not ONOS2Intents\
662 or "Error" in ONOS3Intents or not ONOS3Intents\
663 or "Error" in ONOS4Intents or not ONOS4Intents\
664 or "Error" in ONOS5Intents or not ONOS5Intents\
665 or "Error" in ONOS6Intents or not ONOS6Intents\
666 or "Error" in ONOS7Intents or not ONOS7Intents:
Jon Hall6aec96b2015-01-19 14:49:31 -0800667 main.log.report( "Error in getting ONOS intents" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800668 main.log.warn( "ONOS1 intents response: " + repr( ONOS1Intents ) )
669 main.log.warn( "ONOS2 intents response: " + repr( ONOS2Intents ) )
670 main.log.warn( "ONOS3 intents response: " + repr( ONOS3Intents ) )
671 main.log.warn( "ONOS4 intents response: " + repr( ONOS4Intents ) )
672 main.log.warn( "ONOS5 intents response: " + repr( ONOS5Intents ) )
673 main.log.warn( "ONOS6 intents response: " + repr( ONOS6Intents ) )
674 main.log.warn( "ONOS7 intents response: " + repr( ONOS7Intents ) )
675 elif ONOS1Intents == ONOS2Intents\
676 and ONOS1Intents == ONOS3Intents\
677 and ONOS1Intents == ONOS4Intents\
678 and ONOS1Intents == ONOS5Intents\
679 and ONOS1Intents == ONOS6Intents\
680 and ONOS1Intents == ONOS7Intents:
681 intentState = ONOS1Intents
682 intentCheck = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800683 main.log.report( "Intents are consistent across all ONOS nodes" )
Jon Hallb1290e82014-11-18 16:17:48 -0500684 else:
Jon Hall6aec96b2015-01-19 14:49:31 -0800685 main.log.warn(
686 "ONOS1 intents: ",
687 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800688 json.loads( ONOS1Intents ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800689 sort_keys=True,
690 indent=4,
691 separators=(
692 ',',
693 ': ' ) ) )
694 main.log.warn(
695 "ONOS2 intents: ",
696 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800697 json.loads( ONOS2Intents ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800698 sort_keys=True,
699 indent=4,
700 separators=(
701 ',',
702 ': ' ) ) )
703 main.log.warn(
704 "ONOS3 intents: ",
705 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800706 json.loads( ONOS3Intents ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800707 sort_keys=True,
708 indent=4,
709 separators=(
710 ',',
711 ': ' ) ) )
712 main.log.warn(
713 "ONOS4 intents: ",
714 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800715 json.loads( ONOS4Intents ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800716 sort_keys=True,
717 indent=4,
718 separators=(
719 ',',
720 ': ' ) ) )
721 main.log.warn(
722 "ONOS5 intents: ",
723 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800724 json.loads( ONOS5Intents ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800725 sort_keys=True,
726 indent=4,
727 separators=(
728 ',',
729 ': ' ) ) )
730 main.log.warn(
731 "ONOS6 intents: ",
732 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800733 json.loads( ONOS6Intents ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800734 sort_keys=True,
735 indent=4,
736 separators=(
737 ',',
738 ': ' ) ) )
739 main.log.warn(
740 "ONOS7 intents: ",
741 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800742 json.loads( ONOS7Intents ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800743 sort_keys=True,
744 indent=4,
745 separators=(
746 ',',
747 ': ' ) ) )
748 utilities.assert_equals(
749 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800750 actual=intentCheck,
Jon Hall6aec96b2015-01-19 14:49:31 -0800751 onpass="Intents are consistent across all ONOS nodes",
752 onfail="ONOS nodes have different views of intents" )
Jon Hallb1290e82014-11-18 16:17:48 -0500753
Jon Hall6aec96b2015-01-19 14:49:31 -0800754 main.step( "Get the flows from each controller" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800755 global flowState
756 flowState = []
757 ONOS1Flows = main.ONOScli1.flows( jsonFormat=True )
758 ONOS2Flows = main.ONOScli2.flows( jsonFormat=True )
759 ONOS3Flows = main.ONOScli3.flows( jsonFormat=True )
760 ONOS4Flows = main.ONOScli4.flows( jsonFormat=True )
761 ONOS5Flows = main.ONOScli5.flows( jsonFormat=True )
762 ONOS6Flows = main.ONOScli6.flows( jsonFormat=True )
763 ONOS7Flows = main.ONOScli7.flows( jsonFormat=True )
764 ONOS1FlowsJson = json.loads( ONOS1Flows )
765 ONOS2FlowsJson = json.loads( ONOS2Flows )
766 ONOS3FlowsJson = json.loads( ONOS3Flows )
767 ONOS4FlowsJson = json.loads( ONOS4Flows )
768 ONOS5FlowsJson = json.loads( ONOS5Flows )
769 ONOS6FlowsJson = json.loads( ONOS6Flows )
770 ONOS7FlowsJson = json.loads( ONOS7Flows )
771 flowCheck = main.FALSE
772 if "Error" in ONOS1Flows or not ONOS1Flows\
773 or "Error" in ONOS2Flows or not ONOS2Flows\
774 or "Error" in ONOS3Flows or not ONOS3Flows\
775 or "Error" in ONOS4Flows or not ONOS4Flows\
776 or "Error" in ONOS5Flows or not ONOS5Flows\
777 or "Error" in ONOS6Flows or not ONOS6Flows\
778 or "Error" in ONOS7Flows or not ONOS7Flows:
Jon Hall6aec96b2015-01-19 14:49:31 -0800779 main.log.report( "Error in getting ONOS intents" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800780 main.log.warn( "ONOS1 flows repsponse: " + ONOS1Flows )
781 main.log.warn( "ONOS2 flows repsponse: " + ONOS2Flows )
782 main.log.warn( "ONOS3 flows repsponse: " + ONOS3Flows )
783 main.log.warn( "ONOS4 flows repsponse: " + ONOS4Flows )
784 main.log.warn( "ONOS5 flows repsponse: " + ONOS5Flows )
785 main.log.warn( "ONOS6 flows repsponse: " + ONOS6Flows )
786 main.log.warn( "ONOS7 flows repsponse: " + ONOS7Flows )
787 elif len( ONOS1FlowsJson ) == len( ONOS2FlowsJson )\
788 and len( ONOS1FlowsJson ) == len( ONOS3FlowsJson )\
789 and len( ONOS1FlowsJson ) == len( ONOS4FlowsJson )\
790 and len( ONOS1FlowsJson ) == len( ONOS5FlowsJson )\
791 and len( ONOS1FlowsJson ) == len( ONOS6FlowsJson )\
792 and len( ONOS1FlowsJson ) == len( ONOS7FlowsJson ):
Jon Hall6aec96b2015-01-19 14:49:31 -0800793 # TODO: Do a better check, maybe compare flows on switches?
Jon Hall8f89dda2015-01-22 16:03:33 -0800794 flowState = ONOS1Flows
795 flowCheck = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800796 main.log.report( "Flow count is consistent across all ONOS nodes" )
Jon Hallb1290e82014-11-18 16:17:48 -0500797 else:
Jon Hall6aec96b2015-01-19 14:49:31 -0800798 main.log.warn( "ONOS1 flows: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800799 json.dumps( ONOS1FlowsJson, sort_keys=True,
Jon Hall6aec96b2015-01-19 14:49:31 -0800800 indent=4, separators=( ',', ': ' ) ) )
801 main.log.warn( "ONOS2 flows: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800802 json.dumps( ONOS2FlowsJson, sort_keys=True,
Jon Hall6aec96b2015-01-19 14:49:31 -0800803 indent=4, separators=( ',', ': ' ) ) )
804 main.log.warn( "ONOS3 flows: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800805 json.dumps( ONOS3FlowsJson, sort_keys=True,
Jon Hall6aec96b2015-01-19 14:49:31 -0800806 indent=4, separators=( ',', ': ' ) ) )
807 main.log.warn( "ONOS4 flows: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800808 json.dumps( ONOS4FlowsJson, sort_keys=True,
Jon Hall6aec96b2015-01-19 14:49:31 -0800809 indent=4, separators=( ',', ': ' ) ) )
810 main.log.warn( "ONOS5 flows: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800811 json.dumps( ONOS5FlowsJson, sort_keys=True,
Jon Hall6aec96b2015-01-19 14:49:31 -0800812 indent=4, separators=( ',', ': ' ) ) )
813 main.log.warn( "ONOS6 flows: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800814 json.dumps( ONOS6FlowsJson, sort_keys=True,
Jon Hall6aec96b2015-01-19 14:49:31 -0800815 indent=4, separators=( ',', ': ' ) ) )
816 main.log.warn( "ONOS7 flows: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800817 json.dumps( ONOS7FlowsJson, sort_keys=True,
Jon Hall6aec96b2015-01-19 14:49:31 -0800818 indent=4, separators=( ',', ': ' ) ) )
819 utilities.assert_equals(
820 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800821 actual=flowCheck,
Jon Hall6aec96b2015-01-19 14:49:31 -0800822 onpass="The flow count is consistent across all ONOS nodes",
823 onfail="ONOS nodes have different flow counts" )
Jon Hallb1290e82014-11-18 16:17:48 -0500824
Jon Hall6aec96b2015-01-19 14:49:31 -0800825 main.step( "Get the OF Table entries" )
Jon Hallb1290e82014-11-18 16:17:48 -0500826 global flows
Jon Hall6aec96b2015-01-19 14:49:31 -0800827 flows = []
828 for i in range( 1, 29 ):
Jon Hall8f89dda2015-01-22 16:03:33 -0800829 flows.append( main.Mininet2.getFlowTable( 1.3, "s" + str( i ) ) )
Jon Hallb1290e82014-11-18 16:17:48 -0500830
Jon Hall6aec96b2015-01-19 14:49:31 -0800831 # TODO: Compare switch flow tables with ONOS flow tables
Jon Hallb1290e82014-11-18 16:17:48 -0500832
Jon Hall6aec96b2015-01-19 14:49:31 -0800833 main.step( "Start continuous pings" )
834 main.Mininet2.pingLong(
835 src=main.params[ 'PING' ][ 'source1' ],
836 target=main.params[ 'PING' ][ 'target1' ],
837 pingTime=500 )
838 main.Mininet2.pingLong(
839 src=main.params[ 'PING' ][ 'source2' ],
840 target=main.params[ 'PING' ][ 'target2' ],
841 pingTime=500 )
842 main.Mininet2.pingLong(
843 src=main.params[ 'PING' ][ 'source3' ],
844 target=main.params[ 'PING' ][ 'target3' ],
845 pingTime=500 )
846 main.Mininet2.pingLong(
847 src=main.params[ 'PING' ][ 'source4' ],
848 target=main.params[ 'PING' ][ 'target4' ],
849 pingTime=500 )
850 main.Mininet2.pingLong(
851 src=main.params[ 'PING' ][ 'source5' ],
852 target=main.params[ 'PING' ][ 'target5' ],
853 pingTime=500 )
854 main.Mininet2.pingLong(
855 src=main.params[ 'PING' ][ 'source6' ],
856 target=main.params[ 'PING' ][ 'target6' ],
857 pingTime=500 )
858 main.Mininet2.pingLong(
859 src=main.params[ 'PING' ][ 'source7' ],
860 target=main.params[ 'PING' ][ 'target7' ],
861 pingTime=500 )
862 main.Mininet2.pingLong(
863 src=main.params[ 'PING' ][ 'source8' ],
864 target=main.params[ 'PING' ][ 'target8' ],
865 pingTime=500 )
866 main.Mininet2.pingLong(
867 src=main.params[ 'PING' ][ 'source9' ],
868 target=main.params[ 'PING' ][ 'target9' ],
869 pingTime=500 )
870 main.Mininet2.pingLong(
871 src=main.params[ 'PING' ][ 'source10' ],
872 target=main.params[ 'PING' ][ 'target10' ],
873 pingTime=500 )
Jon Hallb1290e82014-11-18 16:17:48 -0500874
Jon Hall6aec96b2015-01-19 14:49:31 -0800875 main.step( "Create TestONTopology object" )
Jon Hallb1290e82014-11-18 16:17:48 -0500876 ctrls = []
877 count = 1
878 while True:
879 temp = ()
Jon Hall6aec96b2015-01-19 14:49:31 -0800880 if ( 'ip' + str( count ) ) in main.params[ 'CTRL' ]:
881 temp = temp + ( getattr( main, ( 'ONOS' + str( count ) ) ), )
882 temp = temp + ( "ONOS" + str( count ), )
883 temp = temp + ( main.params[ 'CTRL' ][ 'ip' + str( count ) ], )
884 temp = temp + \
885 ( eval( main.params[ 'CTRL' ][ 'port' + str( count ) ] ), )
886 ctrls.append( temp )
Jon Hallb1290e82014-11-18 16:17:48 -0500887 count = count + 1
888 else:
889 break
Jon Hall6aec96b2015-01-19 14:49:31 -0800890 MNTopo = TestONTopology(
891 main.Mininet1,
892 ctrls ) # can also add Intent API info for intent operations
Jon Hallb1290e82014-11-18 16:17:48 -0500893
Jon Hall6aec96b2015-01-19 14:49:31 -0800894 main.step( "Collecting topology information from ONOS" )
Jon Hallb1290e82014-11-18 16:17:48 -0500895 devices = []
896 devices.append( main.ONOScli1.devices() )
897 devices.append( main.ONOScli2.devices() )
898 devices.append( main.ONOScli3.devices() )
899 devices.append( main.ONOScli4.devices() )
900 devices.append( main.ONOScli5.devices() )
901 devices.append( main.ONOScli6.devices() )
902 devices.append( main.ONOScli7.devices() )
Jon Hallb1290e82014-11-18 16:17:48 -0500903 hosts = []
904 hosts.append( main.ONOScli1.hosts() )
905 hosts.append( main.ONOScli2.hosts() )
906 hosts.append( main.ONOScli3.hosts() )
907 hosts.append( main.ONOScli4.hosts() )
908 hosts.append( main.ONOScli5.hosts() )
909 hosts.append( main.ONOScli6.hosts() )
910 hosts.append( main.ONOScli7.hosts() )
Jon Hallb1290e82014-11-18 16:17:48 -0500911 ports = []
912 ports.append( main.ONOScli1.ports() )
913 ports.append( main.ONOScli2.ports() )
914 ports.append( main.ONOScli3.ports() )
915 ports.append( main.ONOScli4.ports() )
916 ports.append( main.ONOScli5.ports() )
917 ports.append( main.ONOScli6.ports() )
918 ports.append( main.ONOScli7.ports() )
919 links = []
920 links.append( main.ONOScli1.links() )
921 links.append( main.ONOScli2.links() )
922 links.append( main.ONOScli3.links() )
923 links.append( main.ONOScli4.links() )
924 links.append( main.ONOScli5.links() )
925 links.append( main.ONOScli6.links() )
926 links.append( main.ONOScli7.links() )
Jon Hall94fd0472014-12-08 11:52:42 -0800927 clusters = []
928 clusters.append( main.ONOScli1.clusters() )
929 clusters.append( main.ONOScli2.clusters() )
930 clusters.append( main.ONOScli3.clusters() )
931 clusters.append( main.ONOScli4.clusters() )
932 clusters.append( main.ONOScli5.clusters() )
933 clusters.append( main.ONOScli6.clusters() )
934 clusters.append( main.ONOScli7.clusters() )
Jon Hall529a37f2015-01-28 10:02:00 -0800935 # Compare json objects for hosts and dataplane clusters
Jon Hall94fd0472014-12-08 11:52:42 -0800936
Jon Hall6aec96b2015-01-19 14:49:31 -0800937 # hosts
Jon Hall8f89dda2015-01-22 16:03:33 -0800938 consistentHostsResult = main.TRUE
Jon Hall94fd0472014-12-08 11:52:42 -0800939 for controller in range( len( hosts ) ):
Jon Hall8f89dda2015-01-22 16:03:33 -0800940 controllerStr = str( controller + 1 )
Jon Hall6aec96b2015-01-19 14:49:31 -0800941 if "Error" not in hosts[ controller ]:
942 if hosts[ controller ] == hosts[ 0 ]:
Jon Hall94fd0472014-12-08 11:52:42 -0800943 continue
Jon Hall6aec96b2015-01-19 14:49:31 -0800944 else: # hosts not consistent
945 main.log.report( "hosts from ONOS" +
Jon Hall8f89dda2015-01-22 16:03:33 -0800946 controllerStr +
Jon Hall6aec96b2015-01-19 14:49:31 -0800947 " is inconsistent with ONOS1" )
948 main.log.warn( repr( hosts[ controller ] ) )
Jon Hall8f89dda2015-01-22 16:03:33 -0800949 consistentHostsResult = main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -0800950
951 else:
Jon Hall6aec96b2015-01-19 14:49:31 -0800952 main.log.report( "Error in getting ONOS hosts from ONOS" +
Jon Hall8f89dda2015-01-22 16:03:33 -0800953 controllerStr )
954 consistentHostsResult = main.FALSE
955 main.log.warn( "ONOS" + controllerStr +
Jon Hall6aec96b2015-01-19 14:49:31 -0800956 " hosts response: " +
957 repr( hosts[ controller ] ) )
958 utilities.assert_equals(
959 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800960 actual=consistentHostsResult,
Jon Hall6aec96b2015-01-19 14:49:31 -0800961 onpass="Hosts view is consistent across all ONOS nodes",
962 onfail="ONOS nodes have different views of hosts" )
Jon Hall94fd0472014-12-08 11:52:42 -0800963
Jon Hall6aec96b2015-01-19 14:49:31 -0800964 # Strongly connected clusters of devices
Jon Hall8f89dda2015-01-22 16:03:33 -0800965 consistentClustersResult = main.TRUE
Jon Hall94fd0472014-12-08 11:52:42 -0800966 for controller in range( len( clusters ) ):
Jon Hall6aec96b2015-01-19 14:49:31 -0800967 if "Error" not in clusters[ controller ]:
968 if clusters[ controller ] == clusters[ 0 ]:
Jon Hall94fd0472014-12-08 11:52:42 -0800969 continue
Jon Hall6aec96b2015-01-19 14:49:31 -0800970 else: # clusters not consistent
971 main.log.report( "clusters from ONOS" +
Jon Hall8f89dda2015-01-22 16:03:33 -0800972 controllerStr +
Jon Hall6aec96b2015-01-19 14:49:31 -0800973 " is inconsistent with ONOS1" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800974 consistentClustersResult = main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -0800975
976 else:
Jon Hall6aec96b2015-01-19 14:49:31 -0800977 main.log.report( "Error in getting dataplane clusters " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800978 "from ONOS" + controllerStr )
979 consistentClustersResult = main.FALSE
980 main.log.warn( "ONOS" + controllerStr +
Jon Hall6aec96b2015-01-19 14:49:31 -0800981 " clusters response: " +
982 repr( clusters[ controller ] ) )
983 utilities.assert_equals(
984 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800985 actual=consistentClustersResult,
Jon Hall6aec96b2015-01-19 14:49:31 -0800986 onpass="Clusters view is consistent across all ONOS nodes",
987 onfail="ONOS nodes have different views of clusters" )
988 # there should always only be one cluster
Jon Hall8f89dda2015-01-22 16:03:33 -0800989 numClusters = len( json.loads( clusters[ 0 ] ) )
Jon Hall6aec96b2015-01-19 14:49:31 -0800990 utilities.assert_equals(
991 expect=1,
Jon Hall8f89dda2015-01-22 16:03:33 -0800992 actual=numClusters,
Jon Hall6aec96b2015-01-19 14:49:31 -0800993 onpass="ONOS shows 1 SCC",
994 onfail="ONOS shows " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800995 str( numClusters ) +
Jon Hall6aec96b2015-01-19 14:49:31 -0800996 " SCCs" )
Jon Hall94fd0472014-12-08 11:52:42 -0800997
Jon Hall6aec96b2015-01-19 14:49:31 -0800998 main.step( "Comparing ONOS topology to MN" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800999 devicesResults = main.TRUE
1000 portsResults = main.TRUE
1001 linksResults = main.TRUE
1002 for controller in range( numControllers ):
1003 controllerStr = str( controller + 1 )
Jon Hall6aec96b2015-01-19 14:49:31 -08001004 if devices[ controller ] or "Error" not in devices[ controller ]:
Jon Hall8f89dda2015-01-22 16:03:33 -08001005 currentDevicesResult = main.Mininet1.compareSwitches(
Jon Hall6aec96b2015-01-19 14:49:31 -08001006 MNTopo,
1007 json.loads(
1008 devices[ controller ] ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001009 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08001010 currentDevicesResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001011 utilities.assert_equals( expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001012 actual=currentDevicesResult,
1013 onpass="ONOS" + controllerStr +
1014 " Switches view is correct",
1015 onfail="ONOS" + controllerStr +
1016 " Switches view is incorrect" )
Jon Hallb1290e82014-11-18 16:17:48 -05001017
Jon Hall6aec96b2015-01-19 14:49:31 -08001018 if ports[ controller ] or "Error" not in ports[ controller ]:
Jon Hall8f89dda2015-01-22 16:03:33 -08001019 currentPortsResult = main.Mininet1.comparePorts(
Jon Hall6aec96b2015-01-19 14:49:31 -08001020 MNTopo,
1021 json.loads(
1022 ports[ controller ] ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001023 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08001024 currentPortsResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001025 utilities.assert_equals( expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001026 actual=currentPortsResult,
1027 onpass="ONOS" + controllerStr +
1028 " ports view is correct",
1029 onfail="ONOS" + controllerStr +
1030 " ports view is incorrect" )
Jon Hallb1290e82014-11-18 16:17:48 -05001031
Jon Hall6aec96b2015-01-19 14:49:31 -08001032 if links[ controller ] or "Error" not in links[ controller ]:
Jon Hall8f89dda2015-01-22 16:03:33 -08001033 currentLinksResult = main.Mininet1.compareLinks(
Jon Hall6aec96b2015-01-19 14:49:31 -08001034 MNTopo,
1035 json.loads(
1036 links[ controller ] ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001037 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08001038 currentLinksResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001039 utilities.assert_equals( expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001040 actual=currentLinksResult,
1041 onpass="ONOS" + controllerStr +
1042 " links view is correct",
1043 onfail="ONOS" + controllerStr +
1044 " links view is incorrect" )
Jon Hallb1290e82014-11-18 16:17:48 -05001045
Jon Hall8f89dda2015-01-22 16:03:33 -08001046 devicesResults = devicesResults and currentDevicesResult
1047 portsResults = portsResults and currentPortsResult
1048 linksResults = linksResults and currentLinksResult
Jon Hallb1290e82014-11-18 16:17:48 -05001049
Jon Hall8f89dda2015-01-22 16:03:33 -08001050 topoResult = devicesResults and portsResults and linksResults\
Jon Hall529a37f2015-01-28 10:02:00 -08001051 and consistentHostsResult and consistentClustersResult
Jon Hall8f89dda2015-01-22 16:03:33 -08001052 utilities.assert_equals( expect=main.TRUE, actual=topoResult,
1053 onpass="Topology Check Test successful",
1054 onfail="Topology Check Test NOT successful" )
Jon Hallb1290e82014-11-18 16:17:48 -05001055
Jon Hall8f89dda2015-01-22 16:03:33 -08001056 finalAssert = main.TRUE
1057 finalAssert = finalAssert and topoResult and flowCheck \
1058 and intentCheck and consistentMastership and rolesNotNull
1059 utilities.assert_equals( expect=main.TRUE, actual=finalAssert,
1060 onpass="State check successful",
1061 onfail="State check NOT successful" )
Jon Hallb1290e82014-11-18 16:17:48 -05001062
Jon Hall6aec96b2015-01-19 14:49:31 -08001063 def CASE6( self, main ):
1064 """
Jon Hallb1290e82014-11-18 16:17:48 -05001065 The Failure case. Since this is the Sanity test, we do nothing.
Jon Hall6aec96b2015-01-19 14:49:31 -08001066 """
Jon Hall368769f2014-11-19 15:43:35 -08001067 import time
Jon Hall6aec96b2015-01-19 14:49:31 -08001068 main.log.report( "Wait 60 seconds instead of inducing a failure" )
1069 time.sleep( 60 )
1070 utilities.assert_equals(
1071 expect=main.TRUE,
1072 actual=main.TRUE,
1073 onpass="Sleeping 60 seconds",
1074 onfail="Something is terribly wrong with my math" )
Jon Hallb1290e82014-11-18 16:17:48 -05001075
Jon Hall6aec96b2015-01-19 14:49:31 -08001076 def CASE7( self, main ):
1077 """
Jon Hall368769f2014-11-19 15:43:35 -08001078 Check state after ONOS failure
Jon Hall6aec96b2015-01-19 14:49:31 -08001079 """
Jon Hallb1290e82014-11-18 16:17:48 -05001080 import json
Jon Hall6aec96b2015-01-19 14:49:31 -08001081 main.case( "Running ONOS Constant State Tests" )
Jon Hallb1290e82014-11-18 16:17:48 -05001082
Jon Hall6aec96b2015-01-19 14:49:31 -08001083 # Assert that each device has a master
Jon Hall8f89dda2015-01-22 16:03:33 -08001084 ONOS1MasterNotNull = main.ONOScli1.rolesNotNull()
1085 ONOS2MasterNotNull = main.ONOScli2.rolesNotNull()
1086 ONOS3MasterNotNull = main.ONOScli3.rolesNotNull()
1087 ONOS4MasterNotNull = main.ONOScli4.rolesNotNull()
1088 ONOS5MasterNotNull = main.ONOScli5.rolesNotNull()
1089 ONOS6MasterNotNull = main.ONOScli6.rolesNotNull()
1090 ONOS7MasterNotNull = main.ONOScli7.rolesNotNull()
1091 rolesNotNull = ONOS1MasterNotNull and ONOS2MasterNotNull and\
1092 ONOS3MasterNotNull and ONOS4MasterNotNull and\
1093 ONOS5MasterNotNull and ONOS6MasterNotNull and\
1094 ONOS7MasterNotNull
Jon Hall6aec96b2015-01-19 14:49:31 -08001095 utilities.assert_equals(
1096 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001097 actual=rolesNotNull,
Jon Hall6aec96b2015-01-19 14:49:31 -08001098 onpass="Each device has a master",
1099 onfail="Some devices don't have a master assigned" )
Jon Hall94fd0472014-12-08 11:52:42 -08001100
Jon Hall6aec96b2015-01-19 14:49:31 -08001101 main.step( "Check if switch roles are consistent across all nodes" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001102 ONOS1Mastership = main.ONOScli1.roles()
1103 ONOS2Mastership = main.ONOScli2.roles()
1104 ONOS3Mastership = main.ONOScli3.roles()
1105 ONOS4Mastership = main.ONOScli4.roles()
1106 ONOS5Mastership = main.ONOScli5.roles()
1107 ONOS6Mastership = main.ONOScli6.roles()
1108 ONOS7Mastership = main.ONOScli7.roles()
1109 # print json.dumps( json.loads( ONOS1Mastership ), sort_keys=True,
Jon Hall6aec96b2015-01-19 14:49:31 -08001110 # indent=4, separators=( ',', ': ' ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001111 if "Error" in ONOS1Mastership or not ONOS1Mastership\
1112 or "Error" in ONOS2Mastership or not ONOS2Mastership\
1113 or "Error" in ONOS3Mastership or not ONOS3Mastership\
1114 or "Error" in ONOS4Mastership or not ONOS4Mastership\
1115 or "Error" in ONOS5Mastership or not ONOS5Mastership\
1116 or "Error" in ONOS6Mastership or not ONOS6Mastership\
1117 or "Error" in ONOS7Mastership or not ONOS7Mastership:
Jon Hall6aec96b2015-01-19 14:49:31 -08001118 main.log.error( "Error in getting ONOS mastership" )
1119 main.log.warn( "ONOS1 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001120 repr( ONOS1Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -08001121 main.log.warn( "ONOS2 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001122 repr( ONOS2Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -08001123 main.log.warn( "ONOS3 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001124 repr( ONOS3Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -08001125 main.log.warn( "ONOS4 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001126 repr( ONOS4Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -08001127 main.log.warn( "ONOS5 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001128 repr( ONOS5Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -08001129 main.log.warn( "ONOS6 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001130 repr( ONOS6Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -08001131 main.log.warn( "ONOS7 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001132 repr( ONOS7Mastership ) )
1133 consistentMastership = main.FALSE
1134 elif ONOS1Mastership == ONOS2Mastership\
1135 and ONOS1Mastership == ONOS3Mastership\
1136 and ONOS1Mastership == ONOS4Mastership\
1137 and ONOS1Mastership == ONOS5Mastership\
1138 and ONOS1Mastership == ONOS6Mastership\
1139 and ONOS1Mastership == ONOS7Mastership:
1140 consistentMastership = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001141 main.log.report(
1142 "Switch roles are consistent across all ONOS nodes" )
Jon Hallb1290e82014-11-18 16:17:48 -05001143 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08001144 main.log.warn( "ONOS1 roles: ", json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -08001145 json.loads( ONOS1Mastership ), sort_keys=True, indent=4,
Jon Hall6aec96b2015-01-19 14:49:31 -08001146 separators=( ',', ': ' ) ) )
1147 main.log.warn( "ONOS2 roles: ", json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -08001148 json.loads( ONOS2Mastership ), sort_keys=True, indent=4,
Jon Hall6aec96b2015-01-19 14:49:31 -08001149 separators=( ',', ': ' ) ) )
1150 main.log.warn( "ONOS3 roles: ", json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -08001151 json.loads( ONOS3Mastership ), sort_keys=True, indent=4,
Jon Hall6aec96b2015-01-19 14:49:31 -08001152 separators=( ',', ': ' ) ) )
1153 main.log.warn( "ONOS4 roles: ", json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -08001154 json.loads( ONOS4Mastership ), sort_keys=True, indent=4,
Jon Hall6aec96b2015-01-19 14:49:31 -08001155 separators=( ',', ': ' ) ) )
1156 main.log.warn( "ONOS5 roles: ", json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -08001157 json.loads( ONOS5Mastership ), sort_keys=True, indent=4,
Jon Hall6aec96b2015-01-19 14:49:31 -08001158 separators=( ',', ': ' ) ) )
1159 main.log.warn( "ONOS6 roles: ", json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -08001160 json.loads( ONOS6Mastership ), sort_keys=True, indent=4,
Jon Hall6aec96b2015-01-19 14:49:31 -08001161 separators=( ',', ': ' ) ) )
1162 main.log.warn( "ONOS7 roles: ", json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -08001163 json.loads( ONOS7Mastership ), sort_keys=True, indent=4,
Jon Hall6aec96b2015-01-19 14:49:31 -08001164 separators=( ',', ': ' ) ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001165 consistentMastership = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001166 utilities.assert_equals(
1167 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001168 actual=consistentMastership,
Jon Hall6aec96b2015-01-19 14:49:31 -08001169 onpass="Switch roles are consistent across all ONOS nodes",
1170 onfail="ONOS nodes have different views of switch roles" )
Jon Hallb1290e82014-11-18 16:17:48 -05001171
1172 description2 = "Compare switch roles from before failure"
Jon Hall6aec96b2015-01-19 14:49:31 -08001173 main.step( description2 )
Jon Hallb1290e82014-11-18 16:17:48 -05001174
Jon Hall8f89dda2015-01-22 16:03:33 -08001175 currentJson = json.loads( ONOS1Mastership )
1176 oldJson = json.loads( mastershipState )
1177 mastershipCheck = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001178 for i in range( 1, 29 ):
1179 switchDPID = str(
1180 main.Mininet1.getSwitchDPID(
1181 switch="s" +
1182 str( i ) ) )
Jon Hallb1290e82014-11-18 16:17:48 -05001183
Jon Hall8f89dda2015-01-22 16:03:33 -08001184 current = [ switch[ 'master' ] for switch in currentJson
Jon Hall6aec96b2015-01-19 14:49:31 -08001185 if switchDPID in switch[ 'id' ] ]
Jon Hall8f89dda2015-01-22 16:03:33 -08001186 old = [ switch[ 'master' ] for switch in oldJson
Jon Hall6aec96b2015-01-19 14:49:31 -08001187 if switchDPID in switch[ 'id' ] ]
Jon Hallb1290e82014-11-18 16:17:48 -05001188 if current == old:
Jon Hall8f89dda2015-01-22 16:03:33 -08001189 mastershipCheck = mastershipCheck and main.TRUE
Jon Hallb1290e82014-11-18 16:17:48 -05001190 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08001191 main.log.warn( "Mastership of switch %s changed" % switchDPID )
Jon Hall8f89dda2015-01-22 16:03:33 -08001192 mastershipCheck = main.FALSE
1193 if mastershipCheck == main.TRUE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001194 main.log.report( "Mastership of Switches was not changed" )
1195 utilities.assert_equals(
1196 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001197 actual=mastershipCheck,
Jon Hall6aec96b2015-01-19 14:49:31 -08001198 onpass="Mastership of Switches was not changed",
1199 onfail="Mastership of some switches changed" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001200 mastershipCheck = mastershipCheck and consistentMastership
Jon Hallb1290e82014-11-18 16:17:48 -05001201
Jon Hall6aec96b2015-01-19 14:49:31 -08001202 main.step( "Get the intents and compare across all nodes" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001203 ONOS1Intents = main.ONOScli1.intents( jsonFormat=True )
1204 ONOS2Intents = main.ONOScli2.intents( jsonFormat=True )
1205 ONOS3Intents = main.ONOScli3.intents( jsonFormat=True )
1206 ONOS4Intents = main.ONOScli4.intents( jsonFormat=True )
1207 ONOS5Intents = main.ONOScli5.intents( jsonFormat=True )
1208 ONOS6Intents = main.ONOScli6.intents( jsonFormat=True )
1209 ONOS7Intents = main.ONOScli7.intents( jsonFormat=True )
1210 intentCheck = main.FALSE
1211 if "Error" in ONOS1Intents or not ONOS1Intents\
1212 or "Error" in ONOS2Intents or not ONOS2Intents\
1213 or "Error" in ONOS3Intents or not ONOS3Intents\
1214 or "Error" in ONOS4Intents or not ONOS4Intents\
1215 or "Error" in ONOS5Intents or not ONOS5Intents\
1216 or "Error" in ONOS6Intents or not ONOS6Intents\
1217 or "Error" in ONOS7Intents or not ONOS7Intents:
Jon Hall6aec96b2015-01-19 14:49:31 -08001218 main.log.report( "Error in getting ONOS intents" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001219 main.log.warn( "ONOS1 intents response: " + repr( ONOS1Intents ) )
1220 main.log.warn( "ONOS2 intents response: " + repr( ONOS2Intents ) )
1221 main.log.warn( "ONOS3 intents response: " + repr( ONOS3Intents ) )
1222 main.log.warn( "ONOS4 intents response: " + repr( ONOS4Intents ) )
1223 main.log.warn( "ONOS5 intents response: " + repr( ONOS5Intents ) )
1224 main.log.warn( "ONOS6 intents response: " + repr( ONOS6Intents ) )
1225 main.log.warn( "ONOS7 intents response: " + repr( ONOS7Intents ) )
1226 elif ONOS1Intents == ONOS2Intents\
1227 and ONOS1Intents == ONOS3Intents\
1228 and ONOS1Intents == ONOS4Intents\
1229 and ONOS1Intents == ONOS5Intents\
1230 and ONOS1Intents == ONOS6Intents\
1231 and ONOS1Intents == ONOS7Intents:
1232 intentCheck = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001233 main.log.report( "Intents are consistent across all ONOS nodes" )
Jon Hallb1290e82014-11-18 16:17:48 -05001234 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08001235 main.log.warn( "ONOS1 intents: " )
Jon Hall8f89dda2015-01-22 16:03:33 -08001236 print json.dumps( json.loads( ONOS1Intents ), sort_keys=True,
Jon Hall6aec96b2015-01-19 14:49:31 -08001237 indent=4, separators=( ',', ': ' ) )
1238 main.log.warn( "ONOS2 intents: " )
Jon Hall8f89dda2015-01-22 16:03:33 -08001239 print json.dumps( json.loads( ONOS2Intents ), sort_keys=True,
Jon Hall6aec96b2015-01-19 14:49:31 -08001240 indent=4, separators=( ',', ': ' ) )
1241 main.log.warn( "ONOS3 intents: " )
Jon Hall8f89dda2015-01-22 16:03:33 -08001242 print json.dumps( json.loads( ONOS3Intents ), sort_keys=True,
Jon Hall6aec96b2015-01-19 14:49:31 -08001243 indent=4, separators=( ',', ': ' ) )
1244 main.log.warn( "ONOS4 intents: " )
Jon Hall8f89dda2015-01-22 16:03:33 -08001245 print json.dumps( json.loads( ONOS4Intents ), sort_keys=True,
Jon Hall6aec96b2015-01-19 14:49:31 -08001246 indent=4, separators=( ',', ': ' ) )
1247 main.log.warn( "ONOS5 intents: " )
Jon Hall8f89dda2015-01-22 16:03:33 -08001248 print json.dumps( json.loads( ONOS5Intents ), sort_keys=True,
Jon Hall6aec96b2015-01-19 14:49:31 -08001249 indent=4, separators=( ',', ': ' ) )
1250 main.log.warn( "ONOS6 intents: " )
Jon Hall8f89dda2015-01-22 16:03:33 -08001251 print json.dumps( json.loads( ONOS6Intents ), sort_keys=True,
Jon Hall6aec96b2015-01-19 14:49:31 -08001252 indent=4, separators=( ',', ': ' ) )
1253 main.log.warn( "ONOS7 intents: " )
Jon Hall8f89dda2015-01-22 16:03:33 -08001254 print json.dumps( json.loads( ONOS7Intents ), sort_keys=True,
Jon Hall6aec96b2015-01-19 14:49:31 -08001255 indent=4, separators=( ',', ': ' ) )
1256 utilities.assert_equals(
1257 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001258 actual=intentCheck,
Jon Hall6aec96b2015-01-19 14:49:31 -08001259 onpass="Intents are consistent across all ONOS nodes",
1260 onfail="ONOS nodes have different views of intents" )
Jon Hallb1290e82014-11-18 16:17:48 -05001261
Jon Hall6aec96b2015-01-19 14:49:31 -08001262 # NOTE: Hazelcast has no durability, so intents are lost across system
1263 # restarts
1264 main.step( "Compare current intents with intents before the failure" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001265 # NOTE: this requires case 5 to pass for intentState to be set.
Jon Hall94fd0472014-12-08 11:52:42 -08001266 # maybe we should stop the test if that fails?
Jon Hall8f89dda2015-01-22 16:03:33 -08001267 if intentState == ONOS1Intents:
1268 sameIntents = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001269 main.log.report( "Intents are consistent with before failure" )
1270 # TODO: possibly the states have changed? we may need to figure out
1271 # what the aceptable states are
Jon Hallb1290e82014-11-18 16:17:48 -05001272 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08001273 try:
1274 main.log.warn( "ONOS1 intents: " )
Jon Hall8f89dda2015-01-22 16:03:33 -08001275 print json.dumps( json.loads( ONOS1Intents ),
Jon Hall6aec96b2015-01-19 14:49:31 -08001276 sort_keys=True, indent=4,
1277 separators=( ',', ': ' ) )
1278 except:
1279 pass
Jon Hall8f89dda2015-01-22 16:03:33 -08001280 sameIntents = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001281 utilities.assert_equals(
1282 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001283 actual=sameIntents,
Jon Hall6aec96b2015-01-19 14:49:31 -08001284 onpass="Intents are consistent with before failure",
1285 onfail="The Intents changed during failure" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001286 intentCheck = intentCheck and sameIntents
Jon Hallb1290e82014-11-18 16:17:48 -05001287
Jon Hall6aec96b2015-01-19 14:49:31 -08001288 main.step( "Get the OF Table entries and compare to before " +
1289 "component failure" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001290 FlowTables = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001291 flows2 = []
1292 for i in range( 28 ):
1293 main.log.info( "Checking flow table on s" + str( i + 1 ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001294 tmpFlows = main.Mininet2.getFlowTable( 1.3, "s" + str( i + 1 ) )
1295 flows2.append( tmpFlows )
1296 tempResult = main.Mininet2.flowComp(
Jon Hall6aec96b2015-01-19 14:49:31 -08001297 flow1=flows[ i ],
Jon Hall8f89dda2015-01-22 16:03:33 -08001298 flow2=tmpFlows )
1299 FlowTables = FlowTables and tempResult
1300 if FlowTables == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001301 main.log.info( "Differences in flow table for switch: s" +
1302 str( i + 1 ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001303 if FlowTables == main.TRUE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001304 main.log.report( "No changes were found in the flow tables" )
1305 utilities.assert_equals(
1306 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001307 actual=FlowTables,
Jon Hall6aec96b2015-01-19 14:49:31 -08001308 onpass="No changes were found in the flow tables",
1309 onfail="Changes were found in the flow tables" )
Jon Hallb1290e82014-11-18 16:17:48 -05001310
Jon Hall6aec96b2015-01-19 14:49:31 -08001311 main.step( "Check the continuous pings to ensure that no packets " +
1312 "were dropped during component failure" )
1313 # FIXME: This check is always failing. Investigate cause
1314 # NOTE: this may be something to do with file permsissions
Jon Hallb1290e82014-11-18 16:17:48 -05001315 # or slight change in format
Jon Hall6aec96b2015-01-19 14:49:31 -08001316 main.Mininet2.pingKill(
1317 main.params[ 'TESTONUSER' ],
1318 main.params[ 'TESTONIP' ] )
Jon Hall8f89dda2015-01-22 16:03:33 -08001319 LossInPings = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001320 # NOTE: checkForLoss returns main.FALSE with 0% packet loss
1321 for i in range( 8, 18 ):
1322 main.log.info(
1323 "Checking for a loss in pings along flow from s" +
1324 str( i ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001325 LossInPings = main.Mininet2.checkForLoss(
Jon Hall6aec96b2015-01-19 14:49:31 -08001326 "/tmp/ping.h" +
Jon Hall8f89dda2015-01-22 16:03:33 -08001327 str( i ) ) or LossInPings
1328 if LossInPings == main.TRUE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001329 main.log.info( "Loss in ping detected" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001330 elif LossInPings == main.ERROR:
Jon Hall6aec96b2015-01-19 14:49:31 -08001331 main.log.info( "There are multiple mininet process running" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001332 elif LossInPings == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001333 main.log.info( "No Loss in the pings" )
1334 main.log.report( "No loss of dataplane connectivity" )
1335 utilities.assert_equals(
1336 expect=main.FALSE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001337 actual=LossInPings,
Jon Hall6aec96b2015-01-19 14:49:31 -08001338 onpass="No Loss of connectivity",
1339 onfail="Loss of dataplane connectivity detected" )
Jon Hallb1290e82014-11-18 16:17:48 -05001340
Jon Hall6aec96b2015-01-19 14:49:31 -08001341 # Test of LeadershipElection
1342 # NOTE: this only works for the sanity test. In case of failures,
1343 # leader will likely change
Jon Hall8f89dda2015-01-22 16:03:33 -08001344 leader = ONOS1Ip
1345 leaderResult = main.TRUE
1346 for controller in range( 1, numControllers + 1 ):
Jon Hall6aec96b2015-01-19 14:49:31 -08001347 # loop through ONOScli handlers
1348 node = getattr( main, ( 'ONOScli' + str( controller ) ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001349 leaderN = node.electionTestLeader()
Jon Hall6aec96b2015-01-19 14:49:31 -08001350 # verify leader is ONOS1
Jon Hall669173b2014-12-17 11:36:30 -08001351 if leaderN == leader:
Jon Hall6aec96b2015-01-19 14:49:31 -08001352 # all is well
1353 # NOTE: In failure scenario, this could be a new node, maybe
1354 # check != ONOS1
Jon Hall669173b2014-12-17 11:36:30 -08001355 pass
1356 elif leaderN == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001357 # error in response
1358 main.log.report( "Something is wrong with " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001359 "electionTestLeader function," +
Jon Hall6aec96b2015-01-19 14:49:31 -08001360 " check the error logs" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001361 leaderResult = main.FALSE
Jon Hall669173b2014-12-17 11:36:30 -08001362 elif leader != leaderN:
Jon Hall8f89dda2015-01-22 16:03:33 -08001363 leaderResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001364 main.log.report( "ONOS" + str( controller ) + " sees " +
1365 str( leaderN ) +
1366 " as the leader of the election app. " +
1367 "Leader should be " + str( leader ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001368 if leaderResult:
1369 main.log.report( "Leadership election tests passed( consistent " +
Jon Hall6aec96b2015-01-19 14:49:31 -08001370 "view of leader across listeners and a new " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001371 "leader was re-elected if applicable )" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001372 utilities.assert_equals(
1373 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001374 actual=leaderResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08001375 onpass="Leadership election passed",
1376 onfail="Something went wrong with Leadership election" )
Jon Hallb1290e82014-11-18 16:17:48 -05001377
Jon Hall8f89dda2015-01-22 16:03:33 -08001378 result = mastershipCheck and intentCheck and FlowTables and\
1379 ( not LossInPings ) and rolesNotNull and leaderResult
Jon Hall6aec96b2015-01-19 14:49:31 -08001380 result = int( result )
Jon Hallb1290e82014-11-18 16:17:48 -05001381 if result == main.TRUE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001382 main.log.report( "Constant State Tests Passed" )
1383 utilities.assert_equals( expect=main.TRUE, actual=result,
Jon Hall8f89dda2015-01-22 16:03:33 -08001384 onpass="Constant State Tests Passed",
1385 onfail="Constant state tests failed" )
Jon Hallb1290e82014-11-18 16:17:48 -05001386
Jon Hall6aec96b2015-01-19 14:49:31 -08001387 def CASE8( self, main ):
1388 """
Jon Hallb1290e82014-11-18 16:17:48 -05001389 Compare topo
Jon Hall6aec96b2015-01-19 14:49:31 -08001390 """
Jon Hallb1290e82014-11-18 16:17:48 -05001391 import sys
Jon Hall6aec96b2015-01-19 14:49:31 -08001392 # FIXME add this path to params
1393 sys.path.append( "/home/admin/sts" )
1394 # assumes that sts is already in you PYTHONPATH
1395 from sts.topology.teston_topology import TestONTopology
Jon Hallb1290e82014-11-18 16:17:48 -05001396 import json
Jon Hall73cf9cc2014-11-20 22:28:38 -08001397 import time
Jon Hallb1290e82014-11-18 16:17:48 -05001398
Jon Hall6aec96b2015-01-19 14:49:31 -08001399 description = "Compare ONOS Topology view to Mininet topology"
1400 main.case( description )
1401 main.log.report( description )
1402 main.step( "Create TestONTopology object" )
Jon Hallb1290e82014-11-18 16:17:48 -05001403 ctrls = []
1404 count = 1
1405 while True:
1406 temp = ()
Jon Hall6aec96b2015-01-19 14:49:31 -08001407 if ( 'ip' + str( count ) ) in main.params[ 'CTRL' ]:
1408 temp = temp + ( getattr( main, ( 'ONOS' + str( count ) ) ), )
1409 temp = temp + ( "ONOS" + str( count ), )
1410 temp = temp + ( main.params[ 'CTRL' ][ 'ip' + str( count ) ], )
1411 temp = temp + \
1412 ( eval( main.params[ 'CTRL' ][ 'port' + str( count ) ] ), )
1413 ctrls.append( temp )
Jon Hallb1290e82014-11-18 16:17:48 -05001414 count = count + 1
1415 else:
1416 break
Jon Hall6aec96b2015-01-19 14:49:31 -08001417 MNTopo = TestONTopology(
1418 main.Mininet1,
1419 ctrls ) # can also add Intent API info for intent operations
Jon Hallb1290e82014-11-18 16:17:48 -05001420
Jon Hall6aec96b2015-01-19 14:49:31 -08001421 main.step( "Comparing ONOS topology to MN" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001422 devicesResults = main.TRUE
1423 portsResults = main.TRUE
1424 linksResults = main.TRUE
1425 topoResult = main.FALSE
Jon Hall73cf9cc2014-11-20 22:28:38 -08001426 elapsed = 0
Jon Hallffb386d2014-11-21 13:43:38 -08001427 count = 0
Jon Hall6aec96b2015-01-19 14:49:31 -08001428 main.step( "Collecting topology information from ONOS" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001429 startTime = time.time()
1430 while topoResult == main.FALSE and elapsed < 60:
Jon Hallffb386d2014-11-21 13:43:38 -08001431 count = count + 1
Jon Hall94fd0472014-12-08 11:52:42 -08001432 if count > 1:
Jon Hall6aec96b2015-01-19 14:49:31 -08001433 # TODO: Depricate STS usage
1434 MNTopo = TestONTopology(
1435 main.Mininet1,
1436 ctrls )
Jon Hall8f89dda2015-01-22 16:03:33 -08001437 cliStart = time.time()
Jon Hall94fd0472014-12-08 11:52:42 -08001438 devices = []
1439 devices.append( main.ONOScli1.devices() )
1440 devices.append( main.ONOScli2.devices() )
1441 devices.append( main.ONOScli3.devices() )
1442 devices.append( main.ONOScli4.devices() )
1443 devices.append( main.ONOScli5.devices() )
1444 devices.append( main.ONOScli6.devices() )
1445 devices.append( main.ONOScli7.devices() )
1446 hosts = []
Jon Hall529a37f2015-01-28 10:02:00 -08001447 hosts.append( json.loads( main.ONOScli1.hosts() ) )
1448 hosts.append( json.loads( main.ONOScli2.hosts() ) )
1449 hosts.append( json.loads( main.ONOScli3.hosts() ) )
1450 hosts.append( json.loads( main.ONOScli4.hosts() ) )
1451 hosts.append( json.loads( main.ONOScli5.hosts() ) )
1452 hosts.append( json.loads( main.ONOScli6.hosts() ) )
1453 hosts.append( json.loads( main.ONOScli7.hosts() ) )
1454 for controller in range( 0, len( hosts ) ):
1455 controllerStr = str( controller + 1 )
1456 for host in hosts[ controller ]:
1457 host
1458 if host[ 'ips' ] == []:
1459 main.log.error(
1460 "DEBUG:Error with host ips on controller" +
1461 controllerStr + ": " + str( host ) )
Jon Hall94fd0472014-12-08 11:52:42 -08001462 ports = []
1463 ports.append( main.ONOScli1.ports() )
1464 ports.append( main.ONOScli2.ports() )
1465 ports.append( main.ONOScli3.ports() )
1466 ports.append( main.ONOScli4.ports() )
1467 ports.append( main.ONOScli5.ports() )
1468 ports.append( main.ONOScli6.ports() )
1469 ports.append( main.ONOScli7.ports() )
1470 links = []
1471 links.append( main.ONOScli1.links() )
1472 links.append( main.ONOScli2.links() )
1473 links.append( main.ONOScli3.links() )
1474 links.append( main.ONOScli4.links() )
1475 links.append( main.ONOScli5.links() )
1476 links.append( main.ONOScli6.links() )
1477 links.append( main.ONOScli7.links() )
1478 clusters = []
1479 clusters.append( main.ONOScli1.clusters() )
1480 clusters.append( main.ONOScli2.clusters() )
1481 clusters.append( main.ONOScli3.clusters() )
1482 clusters.append( main.ONOScli4.clusters() )
1483 clusters.append( main.ONOScli5.clusters() )
1484 clusters.append( main.ONOScli6.clusters() )
1485 clusters.append( main.ONOScli7.clusters() )
Jon Hallb1290e82014-11-18 16:17:48 -05001486
Jon Hall8f89dda2015-01-22 16:03:33 -08001487 elapsed = time.time() - startTime
1488 cliTime = time.time() - cliStart
1489 print "CLI time: " + str( cliTime )
Jon Hallb1290e82014-11-18 16:17:48 -05001490
Jon Hall529a37f2015-01-28 10:02:00 -08001491 try:
1492 for controller in range( numControllers ):
1493 controllerStr = str( controller + 1 )
1494 if devices[ controller ] or "Error" not in devices[
1495 controller ]:
1496 currentDevicesResult = main.Mininet1.compareSwitches(
1497 MNTopo,
1498 json.loads(
1499 devices[ controller ] ) )
1500 else:
1501 currentDevicesResult = main.FALSE
1502 utilities.assert_equals( expect=main.TRUE,
1503 actual=currentDevicesResult,
1504 onpass="ONOS" + controllerStr +
1505 " Switches view is correct",
1506 onfail="ONOS" + controllerStr +
1507 " Switches view is incorrect" )
Jon Hallb1290e82014-11-18 16:17:48 -05001508
Jon Hall529a37f2015-01-28 10:02:00 -08001509 if ports[ controller ] or "Error" not in ports[ controller ]:
1510 currentPortsResult = main.Mininet1.comparePorts(
1511 MNTopo,
1512 json.loads(
1513 ports[ controller ] ) )
1514 else:
1515 currentPortsResult = main.FALSE
1516 utilities.assert_equals( expect=main.TRUE,
1517 actual=currentPortsResult,
1518 onpass="ONOS" + controllerStr +
1519 " ports view is correct",
1520 onfail="ONOS" + controllerStr +
1521 " ports view is incorrect" )
Jon Hall94fd0472014-12-08 11:52:42 -08001522
Jon Hall529a37f2015-01-28 10:02:00 -08001523 if links[ controller ] or "Error" not in links[ controller ]:
1524 currentLinksResult = main.Mininet1.compareLinks(
1525 MNTopo,
1526 json.loads(
1527 links[ controller ] ) )
1528 else:
1529 currentLinksResult = main.FALSE
1530 utilities.assert_equals( expect=main.TRUE,
1531 actual=currentLinksResult,
1532 onpass="ONOS" + controllerStr +
1533 " links view is correct",
1534 onfail="ONOS" + controllerStr +
1535 " links view is incorrect" )
1536 devicesResults = devicesResults and currentDevicesResult
1537 portsResults = portsResults and currentPortsResult
1538 linksResults = linksResults and currentLinksResult
Jon Hall94fd0472014-12-08 11:52:42 -08001539
Jon Hall529a37f2015-01-28 10:02:00 -08001540 # Compare json objects for hosts and dataplane clusters
Jon Hall94fd0472014-12-08 11:52:42 -08001541
Jon Hall529a37f2015-01-28 10:02:00 -08001542 # hosts
1543 consistentHostsResult = main.TRUE
1544 for controller in range( len( hosts ) ):
1545 controllerStr = str( controller + 1 )
1546 if "Error" not in hosts[ controller ]:
1547 if hosts[ controller ] == hosts[ 0 ]:
1548 continue
1549 else: # hosts not consistent
1550 main.log.report( "hosts from ONOS" + controllerStr +
1551 " is inconsistent with ONOS1" )
1552 main.log.warn( repr( hosts[ controller ] ) )
1553 consistentHostsResult = main.FALSE
1554
1555 else:
1556 main.log.report( "Error in getting ONOS hosts from ONOS" +
1557 controllerStr )
Jon Hall8f89dda2015-01-22 16:03:33 -08001558 consistentHostsResult = main.FALSE
Jon Hall529a37f2015-01-28 10:02:00 -08001559 main.log.warn( "ONOS" + controllerStr +
1560 " hosts response: " +
1561 repr( hosts[ controller ] ) )
1562 utilities.assert_equals(
1563 expect=main.TRUE,
1564 actual=consistentHostsResult,
1565 onpass="Hosts view is consistent across all ONOS nodes",
1566 onfail="ONOS nodes have different views of hosts" )
Jon Hall94fd0472014-12-08 11:52:42 -08001567
Jon Hall529a37f2015-01-28 10:02:00 -08001568 # Strongly connected clusters of devices
1569 consistentClustersResult = main.TRUE
1570 for controller in range( len( clusters ) ):
1571 controllerStr = str( controller + 1 )
1572 if "Error" not in clusters[ controller ]:
1573 if clusters[ controller ] == clusters[ 0 ]:
1574 continue
1575 else: # clusters not consistent
1576 main.log.report( "clusters from ONOS" +
1577 controllerStr +
1578 " is inconsistent with ONOS1" )
1579 consistentClustersResult = main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -08001580
Jon Hall529a37f2015-01-28 10:02:00 -08001581 else:
1582 main.log.report( "Error in getting dataplane clusters " +
1583 "from ONOS" + controllerStr )
Jon Hall8f89dda2015-01-22 16:03:33 -08001584 consistentClustersResult = main.FALSE
Jon Hall529a37f2015-01-28 10:02:00 -08001585 main.log.warn( "ONOS" + controllerStr +
1586 " clusters response: " +
1587 repr( clusters[ controller ] ) )
1588 utilities.assert_equals(
1589 expect=main.TRUE,
1590 actual=consistentClustersResult,
1591 onpass="Clusters view is consistent across all ONOS nodes",
1592 onfail="ONOS nodes have different views of clusters" )
1593 # there should always only be one cluster
1594 numClusters = len( json.loads( clusters[ 0 ] ) )
1595 utilities.assert_equals(
1596 expect=1,
1597 actual=numClusters,
1598 onpass="ONOS shows 1 SCC",
1599 onfail="ONOS shows " +
1600 str( numClusters ) +
1601 " SCCs" )
Jon Hall94fd0472014-12-08 11:52:42 -08001602
Jon Hall529a37f2015-01-28 10:02:00 -08001603 topoResult = ( devicesResults and portsResults and linksResults
1604 and consistentHostsResult
1605 and consistentClustersResult )
Jon Hall94fd0472014-12-08 11:52:42 -08001606
Jon Hall529a37f2015-01-28 10:02:00 -08001607 topoResult = topoResult and int( count <= 2 )
1608 note = "note it takes about " + str( int( cliTime ) ) + \
1609 " seconds for the test to make all the cli calls to fetch " +\
1610 "the topology from each ONOS instance"
1611 main.log.report(
1612 "Very crass estimate for topology discovery/convergence( " +
1613 str( note ) + " ): " + str( elapsed ) + " seconds, " +
1614 str( count ) + " tries" )
1615 utilities.assert_equals( expect=main.TRUE, actual=topoResult,
1616 onpass="Topology Check Test successful",
1617 onfail="Topology Check Test NOT successful" )
1618 if topoResult == main.TRUE:
1619 main.log.report( "ONOS topology view matches Mininet topology" )
1620 except:
1621 main.log.info( self.name + " ::::::" )
1622 main.log.error( traceback.print_exc() )
1623 main.log.info( self.name + " ::::::" )
Jon Hall94fd0472014-12-08 11:52:42 -08001624
Jon Hallb1290e82014-11-18 16:17:48 -05001625
Jon Hall6aec96b2015-01-19 14:49:31 -08001626 def CASE9( self, main ):
1627 """
Jon Hallb1290e82014-11-18 16:17:48 -05001628 Link s3-s28 down
Jon Hall6aec96b2015-01-19 14:49:31 -08001629 """
1630 import time
1631 # NOTE: You should probably run a topology check after this
Jon Hallb1290e82014-11-18 16:17:48 -05001632
Jon Hall8f89dda2015-01-22 16:03:33 -08001633 linkSleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] )
Jon Hallb1290e82014-11-18 16:17:48 -05001634
Jon Hall6aec96b2015-01-19 14:49:31 -08001635 description = "Turn off a link to ensure that Link Discovery " +\
Jon Hall8f89dda2015-01-22 16:03:33 -08001636 "is working properly"
Jon Hall6aec96b2015-01-19 14:49:31 -08001637 main.log.report( description )
1638 main.case( description )
Jon Hallb1290e82014-11-18 16:17:48 -05001639
Jon Hall6aec96b2015-01-19 14:49:31 -08001640 main.step( "Kill Link between s3 and s28" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001641 LinkDown = main.Mininet1.link( END1="s3", END2="s28", OPTION="down" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001642 main.log.info(
1643 "Waiting " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001644 str( linkSleep ) +
Jon Hall6aec96b2015-01-19 14:49:31 -08001645 " seconds for link down to be discovered" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001646 time.sleep( linkSleep )
1647 utilities.assert_equals( expect=main.TRUE, actual=LinkDown,
1648 onpass="Link down succesful",
1649 onfail="Failed to bring link down" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001650 # TODO do some sort of check here
Jon Hallb1290e82014-11-18 16:17:48 -05001651
Jon Hall6aec96b2015-01-19 14:49:31 -08001652 def CASE10( self, main ):
1653 """
Jon Hallb1290e82014-11-18 16:17:48 -05001654 Link s3-s28 up
Jon Hall6aec96b2015-01-19 14:49:31 -08001655 """
1656 import time
1657 # NOTE: You should probably run a topology check after this
Jon Hallb1290e82014-11-18 16:17:48 -05001658
Jon Hall8f89dda2015-01-22 16:03:33 -08001659 linkSleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] )
Jon Hallb1290e82014-11-18 16:17:48 -05001660
Jon Hall6aec96b2015-01-19 14:49:31 -08001661 description = "Restore a link to ensure that Link Discovery is " + \
Jon Hall8f89dda2015-01-22 16:03:33 -08001662 "working properly"
Jon Hall6aec96b2015-01-19 14:49:31 -08001663 main.log.report( description )
1664 main.case( description )
Jon Hallb1290e82014-11-18 16:17:48 -05001665
Jon Hall6aec96b2015-01-19 14:49:31 -08001666 main.step( "Bring link between s3 and s28 back up" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001667 LinkUp = main.Mininet1.link( END1="s3", END2="s28", OPTION="up" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001668 main.log.info(
1669 "Waiting " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001670 str( linkSleep ) +
Jon Hall6aec96b2015-01-19 14:49:31 -08001671 " seconds for link up to be discovered" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001672 time.sleep( linkSleep )
1673 utilities.assert_equals( expect=main.TRUE, actual=LinkUp,
1674 onpass="Link up succesful",
1675 onfail="Failed to bring link up" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001676 # TODO do some sort of check here
Jon Hallb1290e82014-11-18 16:17:48 -05001677
Jon Hall6aec96b2015-01-19 14:49:31 -08001678 def CASE11( self, main ):
1679 """
Jon Hallb1290e82014-11-18 16:17:48 -05001680 Switch Down
Jon Hall6aec96b2015-01-19 14:49:31 -08001681 """
1682 # NOTE: You should probably run a topology check after this
Jon Hallb1290e82014-11-18 16:17:48 -05001683 import time
1684
Jon Hall8f89dda2015-01-22 16:03:33 -08001685 switchSleep = float( main.params[ 'timers' ][ 'SwitchDiscovery' ] )
Jon Hallb1290e82014-11-18 16:17:48 -05001686
1687 description = "Killing a switch to ensure it is discovered correctly"
Jon Hall6aec96b2015-01-19 14:49:31 -08001688 main.log.report( description )
1689 main.case( description )
1690 switch = main.params[ 'kill' ][ 'switch' ]
1691 switchDPID = main.params[ 'kill' ][ 'dpid' ]
Jon Hallb1290e82014-11-18 16:17:48 -05001692
Jon Hall6aec96b2015-01-19 14:49:31 -08001693 # TODO: Make this switch parameterizable
1694 main.step( "Kill " + switch )
1695 main.log.report( "Deleting " + switch )
Jon Hall8f89dda2015-01-22 16:03:33 -08001696 main.Mininet1.delSwitch( switch )
1697 main.log.info( "Waiting " + str( switchSleep ) +
Jon Hall6aec96b2015-01-19 14:49:31 -08001698 " seconds for switch down to be discovered" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001699 time.sleep( switchSleep )
1700 device = main.ONOScli1.getDevice( dpid=switchDPID )
Jon Hall6aec96b2015-01-19 14:49:31 -08001701 # Peek at the deleted switch
1702 main.log.warn( str( device ) )
Jon Hall94fd0472014-12-08 11:52:42 -08001703 result = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001704 if device and device[ 'available' ] is False:
Jon Hall94fd0472014-12-08 11:52:42 -08001705 result = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001706 utilities.assert_equals( expect=main.TRUE, actual=result,
Jon Hall8f89dda2015-01-22 16:03:33 -08001707 onpass="Kill switch succesful",
1708 onfail="Failed to kill switch?" )
Jon Hallb1290e82014-11-18 16:17:48 -05001709
Jon Hall6aec96b2015-01-19 14:49:31 -08001710 def CASE12( self, main ):
1711 """
Jon Hallb1290e82014-11-18 16:17:48 -05001712 Switch Up
Jon Hall6aec96b2015-01-19 14:49:31 -08001713 """
1714 # NOTE: You should probably run a topology check after this
Jon Hallb1290e82014-11-18 16:17:48 -05001715 import time
Jon Hall669173b2014-12-17 11:36:30 -08001716
Jon Hall8f89dda2015-01-22 16:03:33 -08001717 switchSleep = float( main.params[ 'timers' ][ 'SwitchDiscovery' ] )
Jon Hall6aec96b2015-01-19 14:49:31 -08001718 switch = main.params[ 'kill' ][ 'switch' ]
1719 switchDPID = main.params[ 'kill' ][ 'dpid' ]
1720 links = main.params[ 'kill' ][ 'links' ].split()
Jon Hallb1290e82014-11-18 16:17:48 -05001721 description = "Adding a switch to ensure it is discovered correctly"
Jon Hall6aec96b2015-01-19 14:49:31 -08001722 main.log.report( description )
1723 main.case( description )
Jon Hallb1290e82014-11-18 16:17:48 -05001724
Jon Hall6aec96b2015-01-19 14:49:31 -08001725 main.step( "Add back " + switch )
1726 main.log.report( "Adding back " + switch )
Jon Hall8f89dda2015-01-22 16:03:33 -08001727 main.Mininet1.addSwitch( switch, dpid=switchDPID )
Jon Hall6aec96b2015-01-19 14:49:31 -08001728 # TODO: New dpid or same? Ask Thomas?
1729 for peer in links:
Jon Hall8f89dda2015-01-22 16:03:33 -08001730 main.Mininet1.addLink( switch, peer )
1731 main.Mininet1.assignSwController(
Jon Hall6aec96b2015-01-19 14:49:31 -08001732 sw=switch.split( 's' )[ 1 ],
Jon Hall8f89dda2015-01-22 16:03:33 -08001733 count=numControllers,
1734 ip1=ONOS1Ip,
1735 port1=ONOS1Port,
1736 ip2=ONOS2Ip,
1737 port2=ONOS2Port,
1738 ip3=ONOS3Ip,
1739 port3=ONOS3Port,
1740 ip4=ONOS4Ip,
1741 port4=ONOS4Port,
1742 ip5=ONOS5Ip,
1743 port5=ONOS5Port,
1744 ip6=ONOS6Ip,
1745 port6=ONOS6Port,
1746 ip7=ONOS7Ip,
1747 port7=ONOS7Port )
Jon Hall6aec96b2015-01-19 14:49:31 -08001748 main.log.info(
1749 "Waiting " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001750 str( switchSleep ) +
Jon Hall6aec96b2015-01-19 14:49:31 -08001751 " seconds for switch up to be discovered" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001752 time.sleep( switchSleep )
1753 device = main.ONOScli1.getDevice( dpid=switchDPID )
Jon Hall6aec96b2015-01-19 14:49:31 -08001754 # Peek at the deleted switch
1755 main.log.warn( str( device ) )
Jon Hall94fd0472014-12-08 11:52:42 -08001756 result = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001757 if device and device[ 'available' ]:
Jon Hall94fd0472014-12-08 11:52:42 -08001758 result = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001759 utilities.assert_equals( expect=main.TRUE, actual=result,
Jon Hall8f89dda2015-01-22 16:03:33 -08001760 onpass="add switch succesful",
1761 onfail="Failed to add switch?" )
Jon Hallb1290e82014-11-18 16:17:48 -05001762
Jon Hall6aec96b2015-01-19 14:49:31 -08001763 def CASE13( self, main ):
1764 """
Jon Hallb1290e82014-11-18 16:17:48 -05001765 Clean up
Jon Hall6aec96b2015-01-19 14:49:31 -08001766 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001767 import os
1768 import time
Jon Hall6aec96b2015-01-19 14:49:31 -08001769 # TODO: make use of this elsewhere
1770 ips = []
Jon Hall8f89dda2015-01-22 16:03:33 -08001771 ips.append( ONOS1Ip )
1772 ips.append( ONOS2Ip )
1773 ips.append( ONOS3Ip )
1774 ips.append( ONOS4Ip )
1775 ips.append( ONOS5Ip )
1776 ips.append( ONOS6Ip )
1777 ips.append( ONOS7Ip )
Jon Hall6aec96b2015-01-19 14:49:31 -08001778
1779 # printing colors to terminal
Jon Hall669173b2014-12-17 11:36:30 -08001780 colors = {}
Jon Hall6aec96b2015-01-19 14:49:31 -08001781 colors[ 'cyan' ] = '\033[96m'
1782 colors[ 'purple' ] = '\033[95m'
1783 colors[ 'blue' ] = '\033[94m'
1784 colors[ 'green' ] = '\033[92m'
1785 colors[ 'yellow' ] = '\033[93m'
1786 colors[ 'red' ] = '\033[91m'
1787 colors[ 'end' ] = '\033[0m'
Jon Hall368769f2014-11-19 15:43:35 -08001788 description = "Test Cleanup"
Jon Hall6aec96b2015-01-19 14:49:31 -08001789 main.log.report( description )
1790 main.case( description )
1791 main.step( "Killing tcpdumps" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001792 main.Mininet2.stopTcpdump()
Jon Hallb1290e82014-11-18 16:17:48 -05001793
Jon Hall6aec96b2015-01-19 14:49:31 -08001794 main.step( "Checking ONOS Logs for errors" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001795 for i in range( 7 ):
Jon Hall6aec96b2015-01-19 14:49:31 -08001796 print colors[ 'purple' ] + "Checking logs for errors on " + \
Jon Hall8f89dda2015-01-22 16:03:33 -08001797 "ONOS" + str( i + 1 ) + ":" + colors[ 'end' ]
1798 print main.ONOSbench.checkLogs( ips[ i ] )
Jon Hall94fd0472014-12-08 11:52:42 -08001799
Jon Hall6aec96b2015-01-19 14:49:31 -08001800 main.step( "Copying MN pcap and ONOS log files to test station" )
Jon Hallb1290e82014-11-18 16:17:48 -05001801 testname = main.TEST
Jon Hall8f89dda2015-01-22 16:03:33 -08001802 teststationUser = main.params[ 'TESTONUSER' ]
1803 teststationIP = main.params[ 'TESTONIP' ]
Jon Hall6aec96b2015-01-19 14:49:31 -08001804 # NOTE: MN Pcap file is being saved to ~/packet_captures
Jon Hall73cf9cc2014-11-20 22:28:38 -08001805 # scp this file as MN and TestON aren't necessarily the same vm
Jon Hall6aec96b2015-01-19 14:49:31 -08001806 # FIXME: scp
1807 # mn files
1808 # TODO: Load these from params
1809 # NOTE: must end in /
Jon Hall8f89dda2015-01-22 16:03:33 -08001810 logFolder = "/opt/onos/log/"
1811 logFiles = [ "karaf.log", "karaf.log.1" ]
Jon Hall6aec96b2015-01-19 14:49:31 -08001812 # NOTE: must end in /
Jon Hall8f89dda2015-01-22 16:03:33 -08001813 dstDir = "~/packet_captures/"
1814 for f in logFiles:
1815 for i in range( 7 ):
1816 main.ONOSbench.handle.sendline( "scp sdn@" + ips[ i ] + ":" +
1817 logFolder + f + " " +
1818 teststationUser + "@" +
1819 teststationIP + ":" +
1820 dstDir + str( testname ) +
Jon Hall6aec96b2015-01-19 14:49:31 -08001821 "-ONOS" + str( i + 1 ) + "-" +
1822 f )
1823 # std*.log's
1824 # NOTE: must end in /
Jon Hall8f89dda2015-01-22 16:03:33 -08001825 logFolder = "/opt/onos/var/"
1826 logFiles = [ "stderr.log", "stdout.log" ]
Jon Hall6aec96b2015-01-19 14:49:31 -08001827 # NOTE: must end in /
Jon Hall8f89dda2015-01-22 16:03:33 -08001828 dstDir = "~/packet_captures/"
1829 for f in logFiles:
1830 for i in range( 7 ):
1831 main.ONOSbench.handle.sendline( "scp sdn@" + ips[ i ] + ":" +
1832 logFolder + f + " " +
1833 teststationUser + "@" +
1834 teststationIP + ":" +
1835 dstDir + str( testname ) +
Jon Hall6aec96b2015-01-19 14:49:31 -08001836 "-ONOS" + str( i + 1 ) + "-" +
1837 f )
1838 # sleep so scp can finish
1839 time.sleep( 10 )
1840 main.step( "Packing and rotating pcap archives" )
1841 os.system( "~/TestON/dependencies/rotate.sh " + str( testname ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001842
Jon Hall6aec96b2015-01-19 14:49:31 -08001843 # TODO: actually check something here
1844 utilities.assert_equals( expect=main.TRUE, actual=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001845 onpass="Test cleanup successful",
1846 onfail="Test cleanup NOT successful" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001847
Jon Hall6aec96b2015-01-19 14:49:31 -08001848 def CASE14( self, main ):
1849 """
Jon Hall94fd0472014-12-08 11:52:42 -08001850 start election app on all onos nodes
Jon Hall6aec96b2015-01-19 14:49:31 -08001851 """
Jon Hall8f89dda2015-01-22 16:03:33 -08001852 leaderResult = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001853 # install app on onos 1
1854 main.log.info( "Install leadership election app" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001855 main.ONOScli1.featureInstall( "onos-app-election" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001856 # wait for election
1857 # check for leader
Jon Hall8f89dda2015-01-22 16:03:33 -08001858 leader = main.ONOScli1.electionTestLeader()
Jon Hall6aec96b2015-01-19 14:49:31 -08001859 # verify leader is ONOS1
Jon Hall8f89dda2015-01-22 16:03:33 -08001860 if leader == ONOS1Ip:
Jon Hall6aec96b2015-01-19 14:49:31 -08001861 # all is well
Jon Hall669173b2014-12-17 11:36:30 -08001862 pass
Jon Hall6aec96b2015-01-19 14:49:31 -08001863 elif leader is None:
1864 # No leader elected
1865 main.log.report( "No leader was elected" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001866 leaderResult = main.FALSE
Jon Hall669173b2014-12-17 11:36:30 -08001867 elif leader == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001868 # error in response
1869 # TODO: add check for "Command not found:" in the driver, this
1870 # means the app isn't loaded
Jon Hall8f89dda2015-01-22 16:03:33 -08001871 main.log.report( "Something is wrong with electionTestLeader" +
Jon Hall6aec96b2015-01-19 14:49:31 -08001872 " function, check the error logs" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001873 leaderResult = main.FALSE
Jon Hall669173b2014-12-17 11:36:30 -08001874 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08001875 # error in response
1876 main.log.report(
Jon Hall8f89dda2015-01-22 16:03:33 -08001877 "Unexpected response from electionTestLeader function:'" +
1878 str( leader ) +
Jon Hall6aec96b2015-01-19 14:49:31 -08001879 "'" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001880 leaderResult = main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -08001881
Jon Hall6aec96b2015-01-19 14:49:31 -08001882 # install on other nodes and check for leader.
1883 # Should be onos1 and each app should show the same leader
Jon Hall8f89dda2015-01-22 16:03:33 -08001884 for controller in range( 2, numControllers + 1 ):
Jon Hall6aec96b2015-01-19 14:49:31 -08001885 # loop through ONOScli handlers
1886 node = getattr( main, ( 'ONOScli' + str( controller ) ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001887 node.featureInstall( "onos-app-election" )
1888 leaderN = node.electionTestLeader()
Jon Hall6aec96b2015-01-19 14:49:31 -08001889 # verify leader is ONOS1
Jon Hall8f89dda2015-01-22 16:03:33 -08001890 if leaderN == ONOS1Ip:
Jon Hall6aec96b2015-01-19 14:49:31 -08001891 # all is well
Jon Hall669173b2014-12-17 11:36:30 -08001892 pass
1893 elif leaderN == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001894 # error in response
1895 # TODO: add check for "Command not found:" in the driver, this
1896 # means the app isn't loaded
1897 main.log.report( "Something is wrong with " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001898 "electionTestLeader function, check the" +
Jon Hall6aec96b2015-01-19 14:49:31 -08001899 " error logs" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001900 leaderResult = main.FALSE
Jon Hall669173b2014-12-17 11:36:30 -08001901 elif leader != leaderN:
Jon Hall8f89dda2015-01-22 16:03:33 -08001902 leaderResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001903 main.log.report( "ONOS" + str( controller ) + " sees " +
1904 str( leaderN ) +
1905 " as the leader of the election app. Leader" +
1906 " should be " +
1907 str( leader ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001908 if leaderResult:
Jon Hall6aec96b2015-01-19 14:49:31 -08001909 main.log.report( "Leadership election tests passed( consistent " +
1910 "view of leader across listeners and a leader " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001911 "was elected )" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001912 utilities.assert_equals(
1913 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001914 actual=leaderResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08001915 onpass="Leadership election passed",
1916 onfail="Something went wrong with Leadership election" )
Jon Hall94fd0472014-12-08 11:52:42 -08001917
Jon Hall6aec96b2015-01-19 14:49:31 -08001918 def CASE15( self, main ):
1919 """
Jon Hall669173b2014-12-17 11:36:30 -08001920 Check that Leadership Election is still functional
Jon Hall6aec96b2015-01-19 14:49:31 -08001921 """
Jon Hall8f89dda2015-01-22 16:03:33 -08001922 leaderResult = main.TRUE
Jon Hall669173b2014-12-17 11:36:30 -08001923 description = "Check that Leadership Election is still functional"
Jon Hall6aec96b2015-01-19 14:49:31 -08001924 main.log.report( description )
1925 main.case( description )
1926 main.step( "Find current leader and withdraw" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001927 leader = main.ONOScli1.electionTestLeader()
Jon Hall6aec96b2015-01-19 14:49:31 -08001928 # TODO: do some sanity checking on leader before using it
Jon Hall8f89dda2015-01-22 16:03:33 -08001929 withdrawResult = main.FALSE
1930 if leader == ONOS1Ip:
1931 oldLeader = getattr( main, "ONOScli1" )
1932 elif leader == ONOS2Ip:
1933 oldLeader = getattr( main, "ONOScli2" )
1934 elif leader == ONOS3Ip:
1935 oldLeader = getattr( main, "ONOScli3" )
1936 elif leader == ONOS4Ip:
1937 oldLeader = getattr( main, "ONOScli4" )
1938 elif leader == ONOS5Ip:
1939 oldLeader = getattr( main, "ONOScli5" )
1940 elif leader == ONOS6Ip:
1941 oldLeader = getattr( main, "ONOScli6" )
1942 elif leader == ONOS7Ip:
1943 oldLeader = getattr( main, "ONOScli7" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001944 elif leader is None or leader == main.FALSE:
1945 main.log.report(
1946 "Leader for the election app should be an ONOS node," +
1947 "instead got '" +
Jon Hall8f89dda2015-01-22 16:03:33 -08001948 str( leader ) +
Jon Hall6aec96b2015-01-19 14:49:31 -08001949 "'" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001950 leaderResult = main.FALSE
1951 withdrawResult = oldLeader.electionTestWithdraw()
Jon Hall6aec96b2015-01-19 14:49:31 -08001952 utilities.assert_equals(
1953 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001954 actual=withdrawResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08001955 onpass="App was withdrawn from election",
1956 onfail="App was not withdrawn from election" )
Jon Hall669173b2014-12-17 11:36:30 -08001957
Jon Hall6aec96b2015-01-19 14:49:31 -08001958 main.step( "Make sure new leader is elected" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001959 leaderList = []
1960 for controller in range( 1, numControllers + 1 ):
Jon Hall6aec96b2015-01-19 14:49:31 -08001961 # loop through ONOScli handlers
1962 node = getattr( main, ( 'ONOScli' + str( controller ) ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001963 leaderList.append( node.electionTestLeader() )
1964 for leaderN in leaderList:
Jon Hall669173b2014-12-17 11:36:30 -08001965 if leaderN == leader:
Jon Hall6aec96b2015-01-19 14:49:31 -08001966 main.log.report(
1967 "ONOS" +
1968 str( controller ) +
1969 " still sees " +
1970 str( leader ) +
1971 " as leader after they withdrew" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001972 leaderResult = main.FALSE
Jon Hall669173b2014-12-17 11:36:30 -08001973 elif leaderN == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001974 # error in response
1975 # TODO: add check for "Command not found:" in the driver, this
1976 # means the app isn't loaded
1977 main.log.report( "Something is wrong with " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001978 "electionTestLeader function, " +
Jon Hall6aec96b2015-01-19 14:49:31 -08001979 "check the error logs" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001980 leaderResult = main.FALSE
1981 consistentLeader = main.FALSE
1982 if len( set( leaderList ) ) == 1:
Jon Hall6aec96b2015-01-19 14:49:31 -08001983 main.log.info( "Each Election-app sees '" +
Jon Hall8f89dda2015-01-22 16:03:33 -08001984 str( leaderList[ 0 ] ) +
Jon Hall6aec96b2015-01-19 14:49:31 -08001985 "' as the leader" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001986 consistentLeader = main.TRUE
Jon Hall669173b2014-12-17 11:36:30 -08001987 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08001988 main.log.report(
1989 "Inconsistent responses for leader of Election-app:" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001990 for n in range( len( leaderList ) ):
Jon Hall6aec96b2015-01-19 14:49:31 -08001991 main.log.report( "ONOS" + str( n + 1 ) + " response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001992 str( leaderList[ n ] ) )
1993 if leaderResult:
1994 main.log.report( "Leadership election tests passed( consistent " +
Jon Hall6aec96b2015-01-19 14:49:31 -08001995 "view of leader across listeners and a new " +
1996 "leader was elected when the old leader " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001997 "resigned )" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001998 utilities.assert_equals(
1999 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08002000 actual=leaderResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08002001 onpass="Leadership election passed",
2002 onfail="Something went wrong with Leadership election" )
Jon Hall669173b2014-12-17 11:36:30 -08002003
Jon Hall6aec96b2015-01-19 14:49:31 -08002004 main.step(
Jon Hall8f89dda2015-01-22 16:03:33 -08002005 "Run for election on old leader( just so everyone is in the hat )" )
2006 runResult = oldLeader.electionTestRun()
Jon Hall6aec96b2015-01-19 14:49:31 -08002007 utilities.assert_equals(
2008 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08002009 actual=runResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08002010 onpass="App re-ran for election",
2011 onfail="App failed to run for election" )
Jon Hall8f89dda2015-01-22 16:03:33 -08002012 if consistentLeader == main.TRUE:
2013 afterRun = main.ONOScli1.electionTestLeader()
Jon Hall6aec96b2015-01-19 14:49:31 -08002014 # verify leader didn't just change
Jon Hall8f89dda2015-01-22 16:03:33 -08002015 if afterRun == leaderList[ 0 ]:
2016 leaderResult = main.TRUE
Jon Hall669173b2014-12-17 11:36:30 -08002017 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08002018 leaderResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08002019 # TODO: assert on run and withdraw results?
Jon Hall669173b2014-12-17 11:36:30 -08002020
Jon Hall6aec96b2015-01-19 14:49:31 -08002021 utilities.assert_equals(
2022 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08002023 actual=leaderResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08002024 onpass="Leadership election passed",
2025 onfail="Something went wrong with Leadership election after " +
2026 "the old leader re-ran for election" )