blob: 58f995406a172e1f5345f155189287fdaedec553 [file] [log] [blame]
Jon Hall6aec96b2015-01-19 14:49:31 -08001"""
Jon Hallb1290e82014-11-18 16:17:48 -05002Description: This test is to determine if the HA test setup is
3 working correctly. There are no failures so this test should
4 have a 100% pass rate
5
6List of test cases:
7CASE1: Compile ONOS and push it to the test machines
8CASE2: Assign mastership to controllers
9CASE3: Assign intents
10CASE4: Ping across added host intents
11CASE5: Reading state of ONOS
12CASE6: The Failure case. Since this is the Sanity test, we do nothing.
Jon Hall368769f2014-11-19 15:43:35 -080013CASE7: Check state after control plane failure
Jon Hallb1290e82014-11-18 16:17:48 -050014CASE8: Compare topo
15CASE9: Link s3-s28 down
16CASE10: Link s3-s28 up
17CASE11: Switch down
18CASE12: Switch up
19CASE13: Clean up
Jon Hall669173b2014-12-17 11:36:30 -080020CASE14: start election app on all onos nodes
21CASE15: Check that Leadership Election is still functional
Jon Hall6aec96b2015-01-19 14:49:31 -080022"""
Jon Hall8f89dda2015-01-22 16:03:33 -080023
24
Jon Hallb1290e82014-11-18 16:17:48 -050025class HATestSanity:
26
Jon Hall6aec96b2015-01-19 14:49:31 -080027 def __init__( self ):
Jon Hallb1290e82014-11-18 16:17:48 -050028 self.default = ''
29
Jon Hall6aec96b2015-01-19 14:49:31 -080030 def CASE1( self, main ):
31 """
Jon Hallb1290e82014-11-18 16:17:48 -050032 CASE1 is to compile ONOS and push it to the test machines
33
34 Startup sequence:
35 git pull
36 mvn clean install
37 onos-package
38 cell <name>
39 onos-verify-cell
40 NOTE: temporary - onos-remove-raft-logs
41 onos-install -f
42 onos-wait-for-start
Jon Hall6aec96b2015-01-19 14:49:31 -080043 """
44 main.log.report( "ONOS HA Sanity test - initialization" )
45 main.case( "Setting up test environment" )
46 # TODO: save all the timers and output them for plotting
Jon Hallb1290e82014-11-18 16:17:48 -050047
48 # load some vairables from the params file
Jon Hall8f89dda2015-01-22 16:03:33 -080049 PULLCODE = False
Jon Hall6aec96b2015-01-19 14:49:31 -080050 if main.params[ 'Git' ] == 'True':
Jon Hall8f89dda2015-01-22 16:03:33 -080051 PULLCODE = True
Jon Hall529a37f2015-01-28 10:02:00 -080052 gitBranch = main.params[ 'branch' ]
Jon Hall8f89dda2015-01-22 16:03:33 -080053 cellName = main.params[ 'ENV' ][ 'cellName' ]
Jon Hall6aec96b2015-01-19 14:49:31 -080054
55 # set global variables
Jon Hall8f89dda2015-01-22 16:03:33 -080056 global ONOS1Ip
57 global ONOS1Port
58 global ONOS2Ip
59 global ONOS2Port
60 global ONOS3Ip
61 global ONOS3Port
62 global ONOS4Ip
63 global ONOS4Port
64 global ONOS5Ip
65 global ONOS5Port
66 global ONOS6Ip
67 global ONOS6Port
68 global ONOS7Ip
69 global ONOS7Port
70 global numControllers
Jon Hallb1290e82014-11-18 16:17:48 -050071
Jon Hall8f89dda2015-01-22 16:03:33 -080072 ONOS1Ip = main.params[ 'CTRL' ][ 'ip1' ]
73 ONOS1Port = main.params[ 'CTRL' ][ 'port1' ]
74 ONOS2Ip = main.params[ 'CTRL' ][ 'ip2' ]
75 ONOS2Port = main.params[ 'CTRL' ][ 'port2' ]
76 ONOS3Ip = main.params[ 'CTRL' ][ 'ip3' ]
77 ONOS3Port = main.params[ 'CTRL' ][ 'port3' ]
78 ONOS4Ip = main.params[ 'CTRL' ][ 'ip4' ]
79 ONOS4Port = main.params[ 'CTRL' ][ 'port4' ]
80 ONOS5Ip = main.params[ 'CTRL' ][ 'ip5' ]
81 ONOS5Port = main.params[ 'CTRL' ][ 'port5' ]
82 ONOS6Ip = main.params[ 'CTRL' ][ 'ip6' ]
83 ONOS6Port = main.params[ 'CTRL' ][ 'port6' ]
84 ONOS7Ip = main.params[ 'CTRL' ][ 'ip7' ]
85 ONOS7Port = main.params[ 'CTRL' ][ 'port7' ]
86 numControllers = int( main.params[ 'num_controllers' ] )
Jon Hallb1290e82014-11-18 16:17:48 -050087
Jon Hall6aec96b2015-01-19 14:49:31 -080088 main.step( "Applying cell variable to environment" )
Jon Hall8f89dda2015-01-22 16:03:33 -080089 cellResult = main.ONOSbench.setCell( cellName )
90 verifyResult = main.ONOSbench.verifyCell()
Jon Hall368769f2014-11-19 15:43:35 -080091
Jon Hall6aec96b2015-01-19 14:49:31 -080092 # FIXME:this is short term fix
93 main.log.report( "Removing raft logs" )
Jon Hall8f89dda2015-01-22 16:03:33 -080094 main.ONOSbench.onosRemoveRaftLogs()
Jon Hall6aec96b2015-01-19 14:49:31 -080095 main.log.report( "Uninstalling ONOS" )
Jon Hall8f89dda2015-01-22 16:03:33 -080096 main.ONOSbench.onosUninstall( ONOS1Ip )
97 main.ONOSbench.onosUninstall( ONOS2Ip )
98 main.ONOSbench.onosUninstall( ONOS3Ip )
99 main.ONOSbench.onosUninstall( ONOS4Ip )
100 main.ONOSbench.onosUninstall( ONOS5Ip )
101 main.ONOSbench.onosUninstall( ONOS6Ip )
102 main.ONOSbench.onosUninstall( ONOS7Ip )
Jon Hallb1290e82014-11-18 16:17:48 -0500103
Jon Hall8f89dda2015-01-22 16:03:33 -0800104 cleanInstallResult = main.TRUE
105 gitPullResult = main.TRUE
Jon Hallb1290e82014-11-18 16:17:48 -0500106
Jon Hall97f31752015-02-04 12:01:04 -0800107 main.step( "Starting Mininet" )
108 main.Mininet1.startNet( )
109
Jon Hall6aec96b2015-01-19 14:49:31 -0800110 main.step( "Compiling the latest version of ONOS" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800111 if PULLCODE:
Jon Hall6aec96b2015-01-19 14:49:31 -0800112 # TODO Configure branch in params
113 main.step( "Git checkout and pull master" )
Jon Hall529a37f2015-01-28 10:02:00 -0800114 main.ONOSbench.gitCheckout( gitBranch )
Jon Hall8f89dda2015-01-22 16:03:33 -0800115 gitPullResult = main.ONOSbench.gitPull()
Jon Hallb1290e82014-11-18 16:17:48 -0500116
Jon Hall6aec96b2015-01-19 14:49:31 -0800117 main.step( "Using mvn clean & install" )
Jon Hall529a37f2015-01-28 10:02:00 -0800118 cleanInstallResult = main.ONOSbench.cleanInstall()
119 else:
120 main.log.warn( "Did not pull new code so skipping mvn " +
121 "clean install" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800122 main.ONOSbench.getVersion( report=True )
Jon Hallb1290e82014-11-18 16:17:48 -0500123
Jon Hall6aec96b2015-01-19 14:49:31 -0800124 main.step( "Creating ONOS package" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800125 packageResult = main.ONOSbench.onosPackage()
Jon Hallb1290e82014-11-18 16:17:48 -0500126
Jon Hall6aec96b2015-01-19 14:49:31 -0800127 main.step( "Installing ONOS package" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800128 onos1InstallResult = main.ONOSbench.onosInstall( options="-f",
129 node=ONOS1Ip )
130 onos2InstallResult = main.ONOSbench.onosInstall( options="-f",
131 node=ONOS2Ip )
132 onos3InstallResult = main.ONOSbench.onosInstall( options="-f",
133 node=ONOS3Ip )
134 onos4InstallResult = main.ONOSbench.onosInstall( options="-f",
135 node=ONOS4Ip )
136 onos5InstallResult = main.ONOSbench.onosInstall( options="-f",
137 node=ONOS5Ip )
138 onos6InstallResult = main.ONOSbench.onosInstall( options="-f",
139 node=ONOS6Ip )
140 onos7InstallResult = main.ONOSbench.onosInstall( options="-f",
141 node=ONOS7Ip )
142 onosInstallResult = onos1InstallResult and onos2InstallResult\
143 and onos3InstallResult and onos4InstallResult\
144 and onos5InstallResult and onos6InstallResult\
145 and onos7InstallResult
Jon Hallb1290e82014-11-18 16:17:48 -0500146
Jon Hall6aec96b2015-01-19 14:49:31 -0800147 main.step( "Checking if ONOS is up yet" )
148 # TODO check bundle:list?
149 for i in range( 2 ):
Jon Hall8f89dda2015-01-22 16:03:33 -0800150 onos1Isup = main.ONOSbench.isup( ONOS1Ip )
151 if not onos1Isup:
Jon Hall6aec96b2015-01-19 14:49:31 -0800152 main.log.report( "ONOS1 didn't start!" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800153 onos2Isup = main.ONOSbench.isup( ONOS2Ip )
154 if not onos2Isup:
Jon Hall6aec96b2015-01-19 14:49:31 -0800155 main.log.report( "ONOS2 didn't start!" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800156 onos3Isup = main.ONOSbench.isup( ONOS3Ip )
157 if not onos3Isup:
Jon Hall6aec96b2015-01-19 14:49:31 -0800158 main.log.report( "ONOS3 didn't start!" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800159 onos4Isup = main.ONOSbench.isup( ONOS4Ip )
160 if not onos4Isup:
Jon Hall6aec96b2015-01-19 14:49:31 -0800161 main.log.report( "ONOS4 didn't start!" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800162 onos5Isup = main.ONOSbench.isup( ONOS5Ip )
163 if not onos5Isup:
Jon Hall6aec96b2015-01-19 14:49:31 -0800164 main.log.report( "ONOS5 didn't start!" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800165 onos6Isup = main.ONOSbench.isup( ONOS6Ip )
166 if not onos6Isup:
Jon Hall6aec96b2015-01-19 14:49:31 -0800167 main.log.report( "ONOS6 didn't start!" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800168 onos7Isup = main.ONOSbench.isup( ONOS7Ip )
169 if not onos7Isup:
Jon Hall6aec96b2015-01-19 14:49:31 -0800170 main.log.report( "ONOS7 didn't start!" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800171 onosIsupResult = onos1Isup and onos2Isup and onos3Isup\
172 and onos4Isup and onos5Isup and onos6Isup and onos7Isup
173 if onosIsupResult == main.TRUE:
Jon Hallffb386d2014-11-21 13:43:38 -0800174 break
Jon Hallb1290e82014-11-18 16:17:48 -0500175
Jon Hall8f89dda2015-01-22 16:03:33 -0800176 cliResult1 = main.ONOScli1.startOnosCli( ONOS1Ip )
177 cliResult2 = main.ONOScli2.startOnosCli( ONOS2Ip )
178 cliResult3 = main.ONOScli3.startOnosCli( ONOS3Ip )
179 cliResult4 = main.ONOScli4.startOnosCli( ONOS4Ip )
180 cliResult5 = main.ONOScli5.startOnosCli( ONOS5Ip )
181 cliResult6 = main.ONOScli6.startOnosCli( ONOS6Ip )
182 cliResult7 = main.ONOScli7.startOnosCli( ONOS7Ip )
183 cliResults = cliResult1 and cliResult2 and cliResult3 and\
184 cliResult4 and cliResult5 and cliResult6 and cliResult7
Jon Hallb1290e82014-11-18 16:17:48 -0500185
Jon Hall6aec96b2015-01-19 14:49:31 -0800186 main.step( "Start Packet Capture MN" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800187 main.Mininet2.startTcpdump(
Jon Hall6aec96b2015-01-19 14:49:31 -0800188 str( main.params[ 'MNtcpdump' ][ 'folder' ] ) + str( main.TEST )
189 + "-MN.pcap",
190 intf=main.params[ 'MNtcpdump' ][ 'intf' ],
191 port=main.params[ 'MNtcpdump' ][ 'port' ] )
Jon Hallb1290e82014-11-18 16:17:48 -0500192
Jon Hall8f89dda2015-01-22 16:03:33 -0800193 case1Result = ( cleanInstallResult and packageResult and
194 cellResult and verifyResult and onosInstallResult
195 and onosIsupResult and cliResults )
Jon Hallb1290e82014-11-18 16:17:48 -0500196
Jon Hall8f89dda2015-01-22 16:03:33 -0800197 utilities.assert_equals( expect=main.TRUE, actual=case1Result,
198 onpass="Test startup successful",
199 onfail="Test startup NOT successful" )
Jon Hallb1290e82014-11-18 16:17:48 -0500200
Jon Hall8f89dda2015-01-22 16:03:33 -0800201 if case1Result == main.FALSE:
Jon Hallffb386d2014-11-21 13:43:38 -0800202 main.cleanup()
203 main.exit()
Jon Hallb1290e82014-11-18 16:17:48 -0500204
Jon Hall6aec96b2015-01-19 14:49:31 -0800205 def CASE2( self, main ):
206 """
Jon Hallb1290e82014-11-18 16:17:48 -0500207 Assign mastership to controllers
Jon Hall6aec96b2015-01-19 14:49:31 -0800208 """
Jon Hallb1290e82014-11-18 16:17:48 -0500209 import re
210
Jon Hall6aec96b2015-01-19 14:49:31 -0800211 main.log.report( "Assigning switches to controllers" )
212 main.case( "Assigning Controllers" )
213 main.step( "Assign switches to controllers" )
Jon Hallb1290e82014-11-18 16:17:48 -0500214
Jon Hall6aec96b2015-01-19 14:49:31 -0800215 for i in range( 1, 29 ):
Jon Hall8f89dda2015-01-22 16:03:33 -0800216 main.Mininet1.assignSwController(
Jon Hall6aec96b2015-01-19 14:49:31 -0800217 sw=str( i ),
Jon Hall8f89dda2015-01-22 16:03:33 -0800218 count=numControllers,
219 ip1=ONOS1Ip, port1=ONOS1Port,
220 ip2=ONOS2Ip, port2=ONOS2Port,
221 ip3=ONOS3Ip, port3=ONOS3Port,
222 ip4=ONOS4Ip, port4=ONOS4Port,
223 ip5=ONOS5Ip, port5=ONOS5Port,
224 ip6=ONOS6Ip, port6=ONOS6Port,
225 ip7=ONOS7Ip, port7=ONOS7Port )
Jon Hallb1290e82014-11-18 16:17:48 -0500226
Jon Hall8f89dda2015-01-22 16:03:33 -0800227 mastershipCheck = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800228 for i in range( 1, 29 ):
Jon Hall8f89dda2015-01-22 16:03:33 -0800229 response = main.Mininet1.getSwController( "s" + str( i ) )
Jon Hallffb386d2014-11-21 13:43:38 -0800230 try:
Jon Hall6aec96b2015-01-19 14:49:31 -0800231 main.log.info( str( response ) )
Jon Hallffb386d2014-11-21 13:43:38 -0800232 except:
Jon Hall6aec96b2015-01-19 14:49:31 -0800233 main.log.info( repr( response ) )
Jon Hall8f89dda2015-01-22 16:03:33 -0800234 if re.search( "tcp:" + ONOS1Ip, response )\
235 and re.search( "tcp:" + ONOS2Ip, response )\
236 and re.search( "tcp:" + ONOS3Ip, response )\
237 and re.search( "tcp:" + ONOS4Ip, response )\
238 and re.search( "tcp:" + ONOS5Ip, response )\
239 and re.search( "tcp:" + ONOS6Ip, response )\
240 and re.search( "tcp:" + ONOS7Ip, response ):
241 mastershipCheck = mastershipCheck and main.TRUE
Jon Hallb1290e82014-11-18 16:17:48 -0500242 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800243 mastershipCheck = main.FALSE
244 if mastershipCheck == main.TRUE:
Jon Hall6aec96b2015-01-19 14:49:31 -0800245 main.log.report( "Switch mastership assigned correctly" )
246 utilities.assert_equals(
247 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800248 actual=mastershipCheck,
Jon Hall6aec96b2015-01-19 14:49:31 -0800249 onpass="Switch mastership assigned correctly",
250 onfail="Switches not assigned correctly to controllers" )
Jon Hallb1290e82014-11-18 16:17:48 -0500251
Jon Hall6aec96b2015-01-19 14:49:31 -0800252 # Manually assign mastership to the controller we want
Jon Hall8f89dda2015-01-22 16:03:33 -0800253 roleCall = main.TRUE
254 roleCheck = main.TRUE
Jon Hall94fd0472014-12-08 11:52:42 -0800255
Jon Hall6aec96b2015-01-19 14:49:31 -0800256 # Assign switch
Jon Hall8f89dda2015-01-22 16:03:33 -0800257 deviceId = main.ONOScli1.getDevice( "1000" ).get( 'id' )
258 roleCall = roleCall and main.ONOScli1.deviceRole(
259 deviceId,
260 ONOS1Ip )
Jon Hall6aec96b2015-01-19 14:49:31 -0800261 # Check assignment
Jon Hall8f89dda2015-01-22 16:03:33 -0800262 if ONOS1Ip in main.ONOScli1.getRole( deviceId ).get( 'master' ):
263 roleCheck = roleCheck and main.TRUE
Jon Hall94fd0472014-12-08 11:52:42 -0800264 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800265 roleCheck = roleCheck and main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -0800266
Jon Hall6aec96b2015-01-19 14:49:31 -0800267 # Assign switch
Jon Hall8f89dda2015-01-22 16:03:33 -0800268 deviceId = main.ONOScli1.getDevice( "2800" ).get( 'id' )
269 roleCall = roleCall and main.ONOScli1.deviceRole(
270 deviceId,
271 ONOS1Ip )
Jon Hall6aec96b2015-01-19 14:49:31 -0800272 # Check assignment
Jon Hall8f89dda2015-01-22 16:03:33 -0800273 if ONOS1Ip in main.ONOScli1.getRole( deviceId ).get( 'master' ):
274 roleCheck = roleCheck and main.TRUE
Jon Hall94fd0472014-12-08 11:52:42 -0800275 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800276 roleCheck = roleCheck and main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -0800277
Jon Hall6aec96b2015-01-19 14:49:31 -0800278 # Assign switch
Jon Hall8f89dda2015-01-22 16:03:33 -0800279 deviceId = main.ONOScli1.getDevice( "2000" ).get( 'id' )
280 roleCall = roleCall and main.ONOScli1.deviceRole(
281 deviceId,
282 ONOS2Ip )
Jon Hall6aec96b2015-01-19 14:49:31 -0800283 # Check assignment
Jon Hall8f89dda2015-01-22 16:03:33 -0800284 if ONOS2Ip in main.ONOScli1.getRole( deviceId ).get( 'master' ):
285 roleCheck = roleCheck and main.TRUE
Jon Hall94fd0472014-12-08 11:52:42 -0800286 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800287 roleCheck = roleCheck and main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -0800288
Jon Hall6aec96b2015-01-19 14:49:31 -0800289 # Assign switch
Jon Hall8f89dda2015-01-22 16:03:33 -0800290 deviceId = main.ONOScli1.getDevice( "3000" ).get( 'id' )
291 roleCall = roleCall and main.ONOScli1.deviceRole(
292 deviceId,
293 ONOS2Ip )
Jon Hall6aec96b2015-01-19 14:49:31 -0800294 # Check assignment
Jon Hall8f89dda2015-01-22 16:03:33 -0800295 if ONOS2Ip in main.ONOScli1.getRole( deviceId ).get( 'master' ):
296 roleCheck = roleCheck and main.TRUE
Jon Hall94fd0472014-12-08 11:52:42 -0800297 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800298 roleCheck = roleCheck and main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -0800299
Jon Hall6aec96b2015-01-19 14:49:31 -0800300 # Assign switch
Jon Hall8f89dda2015-01-22 16:03:33 -0800301 deviceId = main.ONOScli1.getDevice( "5000" ).get( 'id' )
302 roleCall = roleCall and main.ONOScli1.deviceRole(
303 deviceId,
304 ONOS3Ip )
Jon Hall6aec96b2015-01-19 14:49:31 -0800305 # Check assignment
Jon Hall8f89dda2015-01-22 16:03:33 -0800306 if ONOS3Ip in main.ONOScli1.getRole( deviceId ).get( 'master' ):
307 roleCheck = roleCheck and main.TRUE
Jon Hall94fd0472014-12-08 11:52:42 -0800308 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800309 roleCheck = roleCheck and main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -0800310
Jon Hall6aec96b2015-01-19 14:49:31 -0800311 # Assign switch
Jon Hall8f89dda2015-01-22 16:03:33 -0800312 deviceId = main.ONOScli1.getDevice( "6000" ).get( 'id' )
313 roleCall = roleCall and main.ONOScli1.deviceRole(
314 deviceId,
315 ONOS3Ip )
Jon Hall6aec96b2015-01-19 14:49:31 -0800316 # Check assignment
Jon Hall8f89dda2015-01-22 16:03:33 -0800317 if ONOS3Ip in main.ONOScli1.getRole( deviceId ).get( 'master' ):
318 roleCheck = roleCheck and main.TRUE
Jon Hall94fd0472014-12-08 11:52:42 -0800319 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800320 roleCheck = roleCheck and main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -0800321
Jon Hall6aec96b2015-01-19 14:49:31 -0800322 # Assign switch
Jon Hall8f89dda2015-01-22 16:03:33 -0800323 deviceId = main.ONOScli1.getDevice( "3004" ).get( 'id' )
324 roleCall = roleCall and main.ONOScli1.deviceRole(
325 deviceId,
326 ONOS4Ip )
Jon Hall6aec96b2015-01-19 14:49:31 -0800327 # Check assignment
Jon Hall8f89dda2015-01-22 16:03:33 -0800328 if ONOS4Ip in main.ONOScli1.getRole( deviceId ).get( 'master' ):
329 roleCheck = roleCheck and main.TRUE
Jon Hall94fd0472014-12-08 11:52:42 -0800330 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800331 roleCheck = roleCheck and main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -0800332
Jon Hall6aec96b2015-01-19 14:49:31 -0800333 for i in range( 8, 18 ):
334 dpid = '3' + str( i ).zfill( 3 )
Jon Hall8f89dda2015-01-22 16:03:33 -0800335 deviceId = main.ONOScli1.getDevice( dpid ).get( 'id' )
336 roleCall = roleCall and main.ONOScli1.deviceRole(
337 deviceId,
338 ONOS5Ip )
Jon Hall6aec96b2015-01-19 14:49:31 -0800339 # Check assignment
Jon Hall8f89dda2015-01-22 16:03:33 -0800340 if ONOS5Ip in main.ONOScli1.getRole( deviceId ).get( 'master' ):
341 roleCheck = roleCheck and main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800342 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800343 roleCheck = roleCheck and main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -0800344
Jon Hall8f89dda2015-01-22 16:03:33 -0800345 deviceId = main.ONOScli1.getDevice( "6007" ).get( 'id' )
346 roleCall = roleCall and main.ONOScli1.deviceRole(
347 deviceId,
348 ONOS6Ip )
Jon Hall6aec96b2015-01-19 14:49:31 -0800349 # Check assignment
Jon Hall8f89dda2015-01-22 16:03:33 -0800350 if ONOS6Ip in main.ONOScli1.getRole( deviceId ).get( 'master' ):
351 roleCheck = roleCheck and main.TRUE
Jon Hall94fd0472014-12-08 11:52:42 -0800352 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800353 roleCheck = roleCheck and main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -0800354
Jon Hall6aec96b2015-01-19 14:49:31 -0800355 for i in range( 18, 28 ):
356 dpid = '6' + str( i ).zfill( 3 )
Jon Hall8f89dda2015-01-22 16:03:33 -0800357 deviceId = main.ONOScli1.getDevice( dpid ).get( 'id' )
358 roleCall = roleCall and main.ONOScli1.deviceRole(
359 deviceId,
360 ONOS7Ip )
Jon Hall6aec96b2015-01-19 14:49:31 -0800361 # Check assignment
Jon Hall8f89dda2015-01-22 16:03:33 -0800362 if ONOS7Ip in main.ONOScli1.getRole( deviceId ).get( 'master' ):
363 roleCheck = roleCheck and main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800364 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800365 roleCheck = roleCheck and main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -0800366
Jon Hall6aec96b2015-01-19 14:49:31 -0800367 utilities.assert_equals(
368 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800369 actual=roleCall,
Jon Hall6aec96b2015-01-19 14:49:31 -0800370 onpass="Re-assigned switch mastership to designated controller",
Jon Hall8f89dda2015-01-22 16:03:33 -0800371 onfail="Something wrong with deviceRole calls" )
Jon Hall94fd0472014-12-08 11:52:42 -0800372
Jon Hall6aec96b2015-01-19 14:49:31 -0800373 utilities.assert_equals(
374 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800375 actual=roleCheck,
Jon Hall6aec96b2015-01-19 14:49:31 -0800376 onpass="Switches were successfully reassigned to designated " +
377 "controller",
378 onfail="Switches were not successfully reassigned" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800379 mastershipCheck = mastershipCheck and roleCall and roleCheck
380 utilities.assert_equals( expect=main.TRUE, actual=mastershipCheck,
Jon Hall6aec96b2015-01-19 14:49:31 -0800381 onpass="Switch mastership correctly assigned",
382 onfail="Error in (re)assigning switch" +
Jon Hall8f89dda2015-01-22 16:03:33 -0800383 " mastership" )
Jon Hallb1290e82014-11-18 16:17:48 -0500384
Jon Hall6aec96b2015-01-19 14:49:31 -0800385 def CASE3( self, main ):
Jon Hallb1290e82014-11-18 16:17:48 -0500386 """
387 Assign intents
Jon Hallb1290e82014-11-18 16:17:48 -0500388 """
389 import time
Jon Hall6aec96b2015-01-19 14:49:31 -0800390 main.log.report( "Adding host intents" )
391 main.case( "Adding host Intents" )
Jon Hallb1290e82014-11-18 16:17:48 -0500392
Jon Hall8f89dda2015-01-22 16:03:33 -0800393 main.step( "Discovering Hosts( Via pingall for now )" )
Jon Hall6aec96b2015-01-19 14:49:31 -0800394 # FIXME: Once we have a host discovery mechanism, use that instead
Jon Hallb1290e82014-11-18 16:17:48 -0500395
Jon Hall6aec96b2015-01-19 14:49:31 -0800396 # install onos-app-fwd
397 main.log.info( "Install reactive forwarding app" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800398 main.ONOScli1.featureInstall( "onos-app-fwd" )
399 main.ONOScli2.featureInstall( "onos-app-fwd" )
400 main.ONOScli3.featureInstall( "onos-app-fwd" )
401 main.ONOScli4.featureInstall( "onos-app-fwd" )
402 main.ONOScli5.featureInstall( "onos-app-fwd" )
403 main.ONOScli6.featureInstall( "onos-app-fwd" )
404 main.ONOScli7.featureInstall( "onos-app-fwd" )
Jon Hall94fd0472014-12-08 11:52:42 -0800405
Jon Hall6aec96b2015-01-19 14:49:31 -0800406 # REACTIVE FWD test
Jon Hall8f89dda2015-01-22 16:03:33 -0800407 pingResult = main.FALSE
Jon Hallb1290e82014-11-18 16:17:48 -0500408 time1 = time.time()
Jon Hall8f89dda2015-01-22 16:03:33 -0800409 pingResult = main.Mininet1.pingall()
Jon Hall529a37f2015-01-28 10:02:00 -0800410 utilities.assert_equals(
411 expect=main.TRUE,
412 actual=pingResult,
413 onpass="Reactive Pingall test passed",
414 onfail="Reactive Pingall failed, one or more ping pairs failed" )
Jon Hallb1290e82014-11-18 16:17:48 -0500415 time2 = time.time()
Jon Hall6aec96b2015-01-19 14:49:31 -0800416 main.log.info( "Time for pingall: %2f seconds" % ( time2 - time1 ) )
Jon Hallb1290e82014-11-18 16:17:48 -0500417
Jon Hall6aec96b2015-01-19 14:49:31 -0800418 # uninstall onos-app-fwd
419 main.log.info( "Uninstall reactive forwarding app" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800420 main.ONOScli1.featureUninstall( "onos-app-fwd" )
421 main.ONOScli2.featureUninstall( "onos-app-fwd" )
422 main.ONOScli3.featureUninstall( "onos-app-fwd" )
423 main.ONOScli4.featureUninstall( "onos-app-fwd" )
424 main.ONOScli5.featureUninstall( "onos-app-fwd" )
425 main.ONOScli6.featureUninstall( "onos-app-fwd" )
426 main.ONOScli7.featureUninstall( "onos-app-fwd" )
Jon Hall6aec96b2015-01-19 14:49:31 -0800427 # timeout for fwd flows
428 time.sleep( 10 )
Jon Hallb1290e82014-11-18 16:17:48 -0500429
Jon Hall6aec96b2015-01-19 14:49:31 -0800430 main.step( "Add host intents" )
431 # TODO: move the host numbers to params
Jon Hall8f89dda2015-01-22 16:03:33 -0800432 intentAddResult = True
Jon Hall6aec96b2015-01-19 14:49:31 -0800433 for i in range( 8, 18 ):
434 main.log.info( "Adding host intent between h" + str( i ) +
435 " and h" + str( i + 10 ) )
436 host1 = "00:00:00:00:00:" + \
437 str( hex( i )[ 2: ] ).zfill( 2 ).upper()
438 host2 = "00:00:00:00:00:" + \
439 str( hex( i + 10 )[ 2: ] ).zfill( 2 ).upper()
Jon Hall1b8f54a2015-02-04 13:24:20 -0800440 # NOTE: getHost can return None
441 host1Dict = main.ONOScli1.getHost( host1 )
442 host2Dict = main.ONOScli1.getHost( host2 )
443 host1Id = None
444 host2Id = None
445 if host1Dict and host2Dict:
446 host1Id = host1Dict.get( 'id', None )
447 host2Id = host2Dict.get( 'id', None )
Jon Hall8f89dda2015-01-22 16:03:33 -0800448 if host1Id and host2Id:
449 tmpResult = main.ONOScli1.addHostIntent(
450 host1Id,
451 host2Id )
Jon Hall669173b2014-12-17 11:36:30 -0800452 else:
Jon Hall8f89dda2015-01-22 16:03:33 -0800453 main.log.error( "Error, getHost() failed" )
Jon Hall1b8f54a2015-02-04 13:24:20 -0800454 main.log.warn( json.dumps( json.loads( main.ONOScli1.hosts() ),
455 sort_keys=True,
456 indent=4,
457 separators=( ',', ': ' ) ) )
Jon Hall8f89dda2015-01-22 16:03:33 -0800458 tmpResult = main.FALSE
459 intentAddResult = bool( pingResult and intentAddResult
460 and tmpResult )
461 # TODO Check that intents were added?
Jon Hall1b8f54a2015-02-04 13:24:20 -0800462 # Print the intent states
463 intents = main.ONOScli1.intents( )
464 intentStates = []
465 for intent in json.loads( intents ): # Iter through intents of a node
466 intentStates.append( intent.get( 'state', None ) )
467 out = [ (i, intentStates.count( i ) ) for i in set( intentStates ) ]
468 main.log.info( dict( out ) )
469
Jon Hall6aec96b2015-01-19 14:49:31 -0800470 utilities.assert_equals(
471 expect=True,
Jon Hall8f89dda2015-01-22 16:03:33 -0800472 actual=intentAddResult,
473 onpass="Pushed host intents to ONOS",
474 onfail="Error in pushing host intents to ONOS" )
Jon Hall6aec96b2015-01-19 14:49:31 -0800475 # TODO Check if intents all exist in datastore
Jon Hallb1290e82014-11-18 16:17:48 -0500476
Jon Hall6aec96b2015-01-19 14:49:31 -0800477 def CASE4( self, main ):
Jon Hallb1290e82014-11-18 16:17:48 -0500478 """
479 Ping across added host intents
480 """
Jon Hall368769f2014-11-19 15:43:35 -0800481 description = " Ping across added host intents"
Jon Hall6aec96b2015-01-19 14:49:31 -0800482 main.log.report( description )
483 main.case( description )
Jon Hall8f89dda2015-01-22 16:03:33 -0800484 PingResult = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800485 for i in range( 8, 18 ):
486 ping = main.Mininet1.pingHost(
487 src="h" + str( i ), target="h" + str( i + 10 ) )
Jon Hall8f89dda2015-01-22 16:03:33 -0800488 PingResult = PingResult and ping
Jon Hall6aec96b2015-01-19 14:49:31 -0800489 if ping == main.FALSE:
490 main.log.warn( "Ping failed between h" + str( i ) +
491 " and h" + str( i + 10 ) )
492 elif ping == main.TRUE:
493 main.log.info( "Ping test passed!" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800494 PingResult = main.TRUE
495 if PingResult == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -0800496 main.log.report(
497 "Intents have not been installed correctly, pings failed." )
Jon Hall529a37f2015-01-28 10:02:00 -0800498 #TODO: pretty print
499 main.log.warn( "ONSO1 intents: " )
500 main.log.warn( json.dumps( json.loads( main.ONOScli1.intents() ),
501 sort_keys=True,
502 indent=4,
503 separators=( ',', ': ' ) ) )
Jon Hall8f89dda2015-01-22 16:03:33 -0800504 if PingResult == main.TRUE:
Jon Hall6aec96b2015-01-19 14:49:31 -0800505 main.log.report(
506 "Intents have been installed correctly and verified by pings" )
507 utilities.assert_equals(
508 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800509 actual=PingResult,
Jon Hall6aec96b2015-01-19 14:49:31 -0800510 onpass="Intents have been installed correctly and pings work",
511 onfail="Intents have not been installed correctly, pings failed." )
Jon Hallb1290e82014-11-18 16:17:48 -0500512
Jon Hall6aec96b2015-01-19 14:49:31 -0800513 def CASE5( self, main ):
514 """
Jon Hallb1290e82014-11-18 16:17:48 -0500515 Reading state of ONOS
Jon Hall6aec96b2015-01-19 14:49:31 -0800516 """
Jon Hallb1290e82014-11-18 16:17:48 -0500517 import json
Jon Hall6aec96b2015-01-19 14:49:31 -0800518 # assumes that sts is already in you PYTHONPATH
519 from sts.topology.teston_topology import TestONTopology
Jon Hallb1290e82014-11-18 16:17:48 -0500520
Jon Hall6aec96b2015-01-19 14:49:31 -0800521 main.log.report( "Setting up and gathering data for current state" )
522 main.case( "Setting up and gathering data for current state" )
523 # The general idea for this test case is to pull the state of
524 # ( intents,flows, topology,... ) from each ONOS node
525 # We can then compare them with eachother and also with past states
Jon Hallb1290e82014-11-18 16:17:48 -0500526
Jon Hall6aec96b2015-01-19 14:49:31 -0800527 main.step( "Get the Mastership of each switch from each controller" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800528 global mastershipState
529 mastershipState = []
Jon Hall94fd0472014-12-08 11:52:42 -0800530
Jon Hall6aec96b2015-01-19 14:49:31 -0800531 # Assert that each device has a master
Jon Hall8f89dda2015-01-22 16:03:33 -0800532 ONOS1MasterNotNull = main.ONOScli1.rolesNotNull()
533 ONOS2MasterNotNull = main.ONOScli2.rolesNotNull()
534 ONOS3MasterNotNull = main.ONOScli3.rolesNotNull()
535 ONOS4MasterNotNull = main.ONOScli4.rolesNotNull()
536 ONOS5MasterNotNull = main.ONOScli5.rolesNotNull()
537 ONOS6MasterNotNull = main.ONOScli6.rolesNotNull()
538 ONOS7MasterNotNull = main.ONOScli7.rolesNotNull()
539 rolesNotNull = ONOS1MasterNotNull and ONOS2MasterNotNull and\
540 ONOS3MasterNotNull and ONOS4MasterNotNull and\
541 ONOS5MasterNotNull and ONOS6MasterNotNull and\
542 ONOS7MasterNotNull
Jon Hall6aec96b2015-01-19 14:49:31 -0800543 utilities.assert_equals(
544 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800545 actual=rolesNotNull,
Jon Hall6aec96b2015-01-19 14:49:31 -0800546 onpass="Each device has a master",
547 onfail="Some devices don't have a master assigned" )
Jon Hall94fd0472014-12-08 11:52:42 -0800548
Jon Hall8f89dda2015-01-22 16:03:33 -0800549 ONOS1Mastership = main.ONOScli1.roles()
550 ONOS2Mastership = main.ONOScli2.roles()
551 ONOS3Mastership = main.ONOScli3.roles()
552 ONOS4Mastership = main.ONOScli4.roles()
553 ONOS5Mastership = main.ONOScli5.roles()
554 ONOS6Mastership = main.ONOScli6.roles()
555 ONOS7Mastership = main.ONOScli7.roles()
556 # print json.dumps( json.loads( ONOS1Mastership ), sort_keys=True,
Jon Hall6aec96b2015-01-19 14:49:31 -0800557 # indent=4, separators=( ',', ': ' ) )
Jon Hall8f89dda2015-01-22 16:03:33 -0800558 if "Error" in ONOS1Mastership or not ONOS1Mastership\
559 or "Error" in ONOS2Mastership or not ONOS2Mastership\
560 or "Error" in ONOS3Mastership or not ONOS3Mastership\
561 or "Error" in ONOS4Mastership or not ONOS4Mastership\
562 or "Error" in ONOS5Mastership or not ONOS5Mastership\
563 or "Error" in ONOS6Mastership or not ONOS6Mastership\
564 or "Error" in ONOS7Mastership or not ONOS7Mastership:
Jon Hall6aec96b2015-01-19 14:49:31 -0800565 main.log.report( "Error in getting ONOS roles" )
566 main.log.warn(
567 "ONOS1 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800568 repr( ONOS1Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -0800569 main.log.warn(
570 "ONOS2 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800571 repr( ONOS2Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -0800572 main.log.warn(
573 "ONOS3 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800574 repr( ONOS3Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -0800575 main.log.warn(
576 "ONOS4 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800577 repr( ONOS4Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -0800578 main.log.warn(
579 "ONOS5 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800580 repr( ONOS5Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -0800581 main.log.warn(
582 "ONOS6 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800583 repr( ONOS6Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -0800584 main.log.warn(
585 "ONOS7 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800586 repr( ONOS7Mastership ) )
587 consistentMastership = main.FALSE
588 elif ONOS1Mastership == ONOS2Mastership\
589 and ONOS1Mastership == ONOS3Mastership\
590 and ONOS1Mastership == ONOS4Mastership\
591 and ONOS1Mastership == ONOS5Mastership\
592 and ONOS1Mastership == ONOS6Mastership\
593 and ONOS1Mastership == ONOS7Mastership:
594 mastershipState = ONOS1Mastership
595 consistentMastership = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800596 main.log.report(
597 "Switch roles are consistent across all ONOS nodes" )
Jon Hallb1290e82014-11-18 16:17:48 -0500598 else:
Jon Hall6aec96b2015-01-19 14:49:31 -0800599 main.log.warn(
600 "ONOS1 roles: ",
601 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800602 json.loads( ONOS1Mastership ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800603 sort_keys=True,
604 indent=4,
605 separators=(
606 ',',
607 ': ' ) ) )
608 main.log.warn(
609 "ONOS2 roles: ",
610 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800611 json.loads( ONOS2Mastership ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800612 sort_keys=True,
613 indent=4,
614 separators=(
615 ',',
616 ': ' ) ) )
617 main.log.warn(
618 "ONOS3 roles: ",
619 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800620 json.loads( ONOS3Mastership ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800621 sort_keys=True,
622 indent=4,
623 separators=(
624 ',',
625 ': ' ) ) )
626 main.log.warn(
627 "ONOS4 roles: ",
628 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800629 json.loads( ONOS4Mastership ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800630 sort_keys=True,
631 indent=4,
632 separators=(
633 ',',
634 ': ' ) ) )
635 main.log.warn(
636 "ONOS5 roles: ",
637 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800638 json.loads( ONOS5Mastership ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800639 sort_keys=True,
640 indent=4,
641 separators=(
642 ',',
643 ': ' ) ) )
644 main.log.warn(
645 "ONOS6 roles: ",
646 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800647 json.loads( ONOS6Mastership ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800648 sort_keys=True,
649 indent=4,
650 separators=(
651 ',',
652 ': ' ) ) )
653 main.log.warn(
654 "ONOS7 roles: ",
655 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800656 json.loads( ONOS7Mastership ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800657 sort_keys=True,
658 indent=4,
659 separators=(
660 ',',
661 ': ' ) ) )
Jon Hall8f89dda2015-01-22 16:03:33 -0800662 consistentMastership = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -0800663 utilities.assert_equals(
664 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800665 actual=consistentMastership,
Jon Hall6aec96b2015-01-19 14:49:31 -0800666 onpass="Switch roles are consistent across all ONOS nodes",
667 onfail="ONOS nodes have different views of switch roles" )
Jon Hallb1290e82014-11-18 16:17:48 -0500668
Jon Hall6aec96b2015-01-19 14:49:31 -0800669 main.step( "Get the intents from each controller" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800670 global intentState
671 intentState = []
672 ONOS1Intents = main.ONOScli1.intents( jsonFormat=True )
673 ONOS2Intents = main.ONOScli2.intents( jsonFormat=True )
674 ONOS3Intents = main.ONOScli3.intents( jsonFormat=True )
675 ONOS4Intents = main.ONOScli4.intents( jsonFormat=True )
676 ONOS5Intents = main.ONOScli5.intents( jsonFormat=True )
677 ONOS6Intents = main.ONOScli6.intents( jsonFormat=True )
678 ONOS7Intents = main.ONOScli7.intents( jsonFormat=True )
679 intentCheck = main.FALSE
680 if "Error" in ONOS1Intents or not ONOS1Intents\
681 or "Error" in ONOS2Intents or not ONOS2Intents\
682 or "Error" in ONOS3Intents or not ONOS3Intents\
683 or "Error" in ONOS4Intents or not ONOS4Intents\
684 or "Error" in ONOS5Intents or not ONOS5Intents\
685 or "Error" in ONOS6Intents or not ONOS6Intents\
686 or "Error" in ONOS7Intents or not ONOS7Intents:
Jon Hall6aec96b2015-01-19 14:49:31 -0800687 main.log.report( "Error in getting ONOS intents" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800688 main.log.warn( "ONOS1 intents response: " + repr( ONOS1Intents ) )
689 main.log.warn( "ONOS2 intents response: " + repr( ONOS2Intents ) )
690 main.log.warn( "ONOS3 intents response: " + repr( ONOS3Intents ) )
691 main.log.warn( "ONOS4 intents response: " + repr( ONOS4Intents ) )
692 main.log.warn( "ONOS5 intents response: " + repr( ONOS5Intents ) )
693 main.log.warn( "ONOS6 intents response: " + repr( ONOS6Intents ) )
694 main.log.warn( "ONOS7 intents response: " + repr( ONOS7Intents ) )
695 elif ONOS1Intents == ONOS2Intents\
696 and ONOS1Intents == ONOS3Intents\
697 and ONOS1Intents == ONOS4Intents\
698 and ONOS1Intents == ONOS5Intents\
699 and ONOS1Intents == ONOS6Intents\
700 and ONOS1Intents == ONOS7Intents:
701 intentState = ONOS1Intents
702 intentCheck = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800703 main.log.report( "Intents are consistent across all ONOS nodes" )
Jon Hallb1290e82014-11-18 16:17:48 -0500704 else:
Jon Hall6aec96b2015-01-19 14:49:31 -0800705 main.log.warn(
706 "ONOS1 intents: ",
707 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800708 json.loads( ONOS1Intents ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800709 sort_keys=True,
710 indent=4,
711 separators=(
712 ',',
713 ': ' ) ) )
714 main.log.warn(
715 "ONOS2 intents: ",
716 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800717 json.loads( ONOS2Intents ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800718 sort_keys=True,
719 indent=4,
720 separators=(
721 ',',
722 ': ' ) ) )
723 main.log.warn(
724 "ONOS3 intents: ",
725 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800726 json.loads( ONOS3Intents ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800727 sort_keys=True,
728 indent=4,
729 separators=(
730 ',',
731 ': ' ) ) )
732 main.log.warn(
733 "ONOS4 intents: ",
734 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800735 json.loads( ONOS4Intents ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800736 sort_keys=True,
737 indent=4,
738 separators=(
739 ',',
740 ': ' ) ) )
741 main.log.warn(
742 "ONOS5 intents: ",
743 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800744 json.loads( ONOS5Intents ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800745 sort_keys=True,
746 indent=4,
747 separators=(
748 ',',
749 ': ' ) ) )
750 main.log.warn(
751 "ONOS6 intents: ",
752 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800753 json.loads( ONOS6Intents ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800754 sort_keys=True,
755 indent=4,
756 separators=(
757 ',',
758 ': ' ) ) )
759 main.log.warn(
760 "ONOS7 intents: ",
761 json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -0800762 json.loads( ONOS7Intents ),
Jon Hall6aec96b2015-01-19 14:49:31 -0800763 sort_keys=True,
764 indent=4,
765 separators=(
766 ',',
767 ': ' ) ) )
768 utilities.assert_equals(
769 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800770 actual=intentCheck,
Jon Hall6aec96b2015-01-19 14:49:31 -0800771 onpass="Intents are consistent across all ONOS nodes",
772 onfail="ONOS nodes have different views of intents" )
Jon Hallb1290e82014-11-18 16:17:48 -0500773
Jon Hall6aec96b2015-01-19 14:49:31 -0800774 main.step( "Get the flows from each controller" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800775 global flowState
776 flowState = []
777 ONOS1Flows = main.ONOScli1.flows( jsonFormat=True )
778 ONOS2Flows = main.ONOScli2.flows( jsonFormat=True )
779 ONOS3Flows = main.ONOScli3.flows( jsonFormat=True )
780 ONOS4Flows = main.ONOScli4.flows( jsonFormat=True )
781 ONOS5Flows = main.ONOScli5.flows( jsonFormat=True )
782 ONOS6Flows = main.ONOScli6.flows( jsonFormat=True )
783 ONOS7Flows = main.ONOScli7.flows( jsonFormat=True )
784 ONOS1FlowsJson = json.loads( ONOS1Flows )
785 ONOS2FlowsJson = json.loads( ONOS2Flows )
786 ONOS3FlowsJson = json.loads( ONOS3Flows )
787 ONOS4FlowsJson = json.loads( ONOS4Flows )
788 ONOS5FlowsJson = json.loads( ONOS5Flows )
789 ONOS6FlowsJson = json.loads( ONOS6Flows )
790 ONOS7FlowsJson = json.loads( ONOS7Flows )
791 flowCheck = main.FALSE
792 if "Error" in ONOS1Flows or not ONOS1Flows\
793 or "Error" in ONOS2Flows or not ONOS2Flows\
794 or "Error" in ONOS3Flows or not ONOS3Flows\
795 or "Error" in ONOS4Flows or not ONOS4Flows\
796 or "Error" in ONOS5Flows or not ONOS5Flows\
797 or "Error" in ONOS6Flows or not ONOS6Flows\
798 or "Error" in ONOS7Flows or not ONOS7Flows:
Jon Hall6aec96b2015-01-19 14:49:31 -0800799 main.log.report( "Error in getting ONOS intents" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800800 main.log.warn( "ONOS1 flows repsponse: " + ONOS1Flows )
801 main.log.warn( "ONOS2 flows repsponse: " + ONOS2Flows )
802 main.log.warn( "ONOS3 flows repsponse: " + ONOS3Flows )
803 main.log.warn( "ONOS4 flows repsponse: " + ONOS4Flows )
804 main.log.warn( "ONOS5 flows repsponse: " + ONOS5Flows )
805 main.log.warn( "ONOS6 flows repsponse: " + ONOS6Flows )
806 main.log.warn( "ONOS7 flows repsponse: " + ONOS7Flows )
807 elif len( ONOS1FlowsJson ) == len( ONOS2FlowsJson )\
808 and len( ONOS1FlowsJson ) == len( ONOS3FlowsJson )\
809 and len( ONOS1FlowsJson ) == len( ONOS4FlowsJson )\
810 and len( ONOS1FlowsJson ) == len( ONOS5FlowsJson )\
811 and len( ONOS1FlowsJson ) == len( ONOS6FlowsJson )\
812 and len( ONOS1FlowsJson ) == len( ONOS7FlowsJson ):
Jon Hall6aec96b2015-01-19 14:49:31 -0800813 # TODO: Do a better check, maybe compare flows on switches?
Jon Hall8f89dda2015-01-22 16:03:33 -0800814 flowState = ONOS1Flows
815 flowCheck = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -0800816 main.log.report( "Flow count is consistent across all ONOS nodes" )
Jon Hallb1290e82014-11-18 16:17:48 -0500817 else:
Jon Hall6aec96b2015-01-19 14:49:31 -0800818 main.log.warn( "ONOS1 flows: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800819 json.dumps( ONOS1FlowsJson, sort_keys=True,
Jon Hall6aec96b2015-01-19 14:49:31 -0800820 indent=4, separators=( ',', ': ' ) ) )
821 main.log.warn( "ONOS2 flows: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800822 json.dumps( ONOS2FlowsJson, sort_keys=True,
Jon Hall6aec96b2015-01-19 14:49:31 -0800823 indent=4, separators=( ',', ': ' ) ) )
824 main.log.warn( "ONOS3 flows: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800825 json.dumps( ONOS3FlowsJson, sort_keys=True,
Jon Hall6aec96b2015-01-19 14:49:31 -0800826 indent=4, separators=( ',', ': ' ) ) )
827 main.log.warn( "ONOS4 flows: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800828 json.dumps( ONOS4FlowsJson, sort_keys=True,
Jon Hall6aec96b2015-01-19 14:49:31 -0800829 indent=4, separators=( ',', ': ' ) ) )
830 main.log.warn( "ONOS5 flows: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800831 json.dumps( ONOS5FlowsJson, sort_keys=True,
Jon Hall6aec96b2015-01-19 14:49:31 -0800832 indent=4, separators=( ',', ': ' ) ) )
833 main.log.warn( "ONOS6 flows: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800834 json.dumps( ONOS6FlowsJson, sort_keys=True,
Jon Hall6aec96b2015-01-19 14:49:31 -0800835 indent=4, separators=( ',', ': ' ) ) )
836 main.log.warn( "ONOS7 flows: " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800837 json.dumps( ONOS7FlowsJson, sort_keys=True,
Jon Hall6aec96b2015-01-19 14:49:31 -0800838 indent=4, separators=( ',', ': ' ) ) )
839 utilities.assert_equals(
840 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800841 actual=flowCheck,
Jon Hall6aec96b2015-01-19 14:49:31 -0800842 onpass="The flow count is consistent across all ONOS nodes",
843 onfail="ONOS nodes have different flow counts" )
Jon Hallb1290e82014-11-18 16:17:48 -0500844
Jon Hall6aec96b2015-01-19 14:49:31 -0800845 main.step( "Get the OF Table entries" )
Jon Hallb1290e82014-11-18 16:17:48 -0500846 global flows
Jon Hall6aec96b2015-01-19 14:49:31 -0800847 flows = []
848 for i in range( 1, 29 ):
Jon Hall8f89dda2015-01-22 16:03:33 -0800849 flows.append( main.Mininet2.getFlowTable( 1.3, "s" + str( i ) ) )
Jon Hallb1290e82014-11-18 16:17:48 -0500850
Jon Hall6aec96b2015-01-19 14:49:31 -0800851 # TODO: Compare switch flow tables with ONOS flow tables
Jon Hallb1290e82014-11-18 16:17:48 -0500852
Jon Hall6aec96b2015-01-19 14:49:31 -0800853 main.step( "Start continuous pings" )
854 main.Mininet2.pingLong(
855 src=main.params[ 'PING' ][ 'source1' ],
856 target=main.params[ 'PING' ][ 'target1' ],
857 pingTime=500 )
858 main.Mininet2.pingLong(
859 src=main.params[ 'PING' ][ 'source2' ],
860 target=main.params[ 'PING' ][ 'target2' ],
861 pingTime=500 )
862 main.Mininet2.pingLong(
863 src=main.params[ 'PING' ][ 'source3' ],
864 target=main.params[ 'PING' ][ 'target3' ],
865 pingTime=500 )
866 main.Mininet2.pingLong(
867 src=main.params[ 'PING' ][ 'source4' ],
868 target=main.params[ 'PING' ][ 'target4' ],
869 pingTime=500 )
870 main.Mininet2.pingLong(
871 src=main.params[ 'PING' ][ 'source5' ],
872 target=main.params[ 'PING' ][ 'target5' ],
873 pingTime=500 )
874 main.Mininet2.pingLong(
875 src=main.params[ 'PING' ][ 'source6' ],
876 target=main.params[ 'PING' ][ 'target6' ],
877 pingTime=500 )
878 main.Mininet2.pingLong(
879 src=main.params[ 'PING' ][ 'source7' ],
880 target=main.params[ 'PING' ][ 'target7' ],
881 pingTime=500 )
882 main.Mininet2.pingLong(
883 src=main.params[ 'PING' ][ 'source8' ],
884 target=main.params[ 'PING' ][ 'target8' ],
885 pingTime=500 )
886 main.Mininet2.pingLong(
887 src=main.params[ 'PING' ][ 'source9' ],
888 target=main.params[ 'PING' ][ 'target9' ],
889 pingTime=500 )
890 main.Mininet2.pingLong(
891 src=main.params[ 'PING' ][ 'source10' ],
892 target=main.params[ 'PING' ][ 'target10' ],
893 pingTime=500 )
Jon Hallb1290e82014-11-18 16:17:48 -0500894
Jon Hall6aec96b2015-01-19 14:49:31 -0800895 main.step( "Create TestONTopology object" )
Jon Hallb1290e82014-11-18 16:17:48 -0500896 ctrls = []
897 count = 1
898 while True:
899 temp = ()
Jon Hall6aec96b2015-01-19 14:49:31 -0800900 if ( 'ip' + str( count ) ) in main.params[ 'CTRL' ]:
901 temp = temp + ( getattr( main, ( 'ONOS' + str( count ) ) ), )
902 temp = temp + ( "ONOS" + str( count ), )
903 temp = temp + ( main.params[ 'CTRL' ][ 'ip' + str( count ) ], )
904 temp = temp + \
905 ( eval( main.params[ 'CTRL' ][ 'port' + str( count ) ] ), )
906 ctrls.append( temp )
Jon Hallb1290e82014-11-18 16:17:48 -0500907 count = count + 1
908 else:
909 break
Jon Hall6aec96b2015-01-19 14:49:31 -0800910 MNTopo = TestONTopology(
911 main.Mininet1,
912 ctrls ) # can also add Intent API info for intent operations
Jon Hallb1290e82014-11-18 16:17:48 -0500913
Jon Hall6aec96b2015-01-19 14:49:31 -0800914 main.step( "Collecting topology information from ONOS" )
Jon Hallb1290e82014-11-18 16:17:48 -0500915 devices = []
916 devices.append( main.ONOScli1.devices() )
917 devices.append( main.ONOScli2.devices() )
918 devices.append( main.ONOScli3.devices() )
919 devices.append( main.ONOScli4.devices() )
920 devices.append( main.ONOScli5.devices() )
921 devices.append( main.ONOScli6.devices() )
922 devices.append( main.ONOScli7.devices() )
Jon Hallb1290e82014-11-18 16:17:48 -0500923 hosts = []
924 hosts.append( main.ONOScli1.hosts() )
925 hosts.append( main.ONOScli2.hosts() )
926 hosts.append( main.ONOScli3.hosts() )
927 hosts.append( main.ONOScli4.hosts() )
928 hosts.append( main.ONOScli5.hosts() )
929 hosts.append( main.ONOScli6.hosts() )
930 hosts.append( main.ONOScli7.hosts() )
Jon Hallb1290e82014-11-18 16:17:48 -0500931 ports = []
932 ports.append( main.ONOScli1.ports() )
933 ports.append( main.ONOScli2.ports() )
934 ports.append( main.ONOScli3.ports() )
935 ports.append( main.ONOScli4.ports() )
936 ports.append( main.ONOScli5.ports() )
937 ports.append( main.ONOScli6.ports() )
938 ports.append( main.ONOScli7.ports() )
939 links = []
940 links.append( main.ONOScli1.links() )
941 links.append( main.ONOScli2.links() )
942 links.append( main.ONOScli3.links() )
943 links.append( main.ONOScli4.links() )
944 links.append( main.ONOScli5.links() )
945 links.append( main.ONOScli6.links() )
946 links.append( main.ONOScli7.links() )
Jon Hall94fd0472014-12-08 11:52:42 -0800947 clusters = []
948 clusters.append( main.ONOScli1.clusters() )
949 clusters.append( main.ONOScli2.clusters() )
950 clusters.append( main.ONOScli3.clusters() )
951 clusters.append( main.ONOScli4.clusters() )
952 clusters.append( main.ONOScli5.clusters() )
953 clusters.append( main.ONOScli6.clusters() )
954 clusters.append( main.ONOScli7.clusters() )
Jon Hall529a37f2015-01-28 10:02:00 -0800955 # Compare json objects for hosts and dataplane clusters
Jon Hall94fd0472014-12-08 11:52:42 -0800956
Jon Hall6aec96b2015-01-19 14:49:31 -0800957 # hosts
Jon Hall8f89dda2015-01-22 16:03:33 -0800958 consistentHostsResult = main.TRUE
Jon Hall94fd0472014-12-08 11:52:42 -0800959 for controller in range( len( hosts ) ):
Jon Hall8f89dda2015-01-22 16:03:33 -0800960 controllerStr = str( controller + 1 )
Jon Hall6aec96b2015-01-19 14:49:31 -0800961 if "Error" not in hosts[ controller ]:
962 if hosts[ controller ] == hosts[ 0 ]:
Jon Hall94fd0472014-12-08 11:52:42 -0800963 continue
Jon Hall6aec96b2015-01-19 14:49:31 -0800964 else: # hosts not consistent
965 main.log.report( "hosts from ONOS" +
Jon Hall8f89dda2015-01-22 16:03:33 -0800966 controllerStr +
Jon Hall6aec96b2015-01-19 14:49:31 -0800967 " is inconsistent with ONOS1" )
968 main.log.warn( repr( hosts[ controller ] ) )
Jon Hall8f89dda2015-01-22 16:03:33 -0800969 consistentHostsResult = main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -0800970
971 else:
Jon Hall6aec96b2015-01-19 14:49:31 -0800972 main.log.report( "Error in getting ONOS hosts from ONOS" +
Jon Hall8f89dda2015-01-22 16:03:33 -0800973 controllerStr )
974 consistentHostsResult = main.FALSE
975 main.log.warn( "ONOS" + controllerStr +
Jon Hall6aec96b2015-01-19 14:49:31 -0800976 " hosts response: " +
977 repr( hosts[ controller ] ) )
978 utilities.assert_equals(
979 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -0800980 actual=consistentHostsResult,
Jon Hall6aec96b2015-01-19 14:49:31 -0800981 onpass="Hosts view is consistent across all ONOS nodes",
982 onfail="ONOS nodes have different views of hosts" )
Jon Hall94fd0472014-12-08 11:52:42 -0800983
Jon Hall6aec96b2015-01-19 14:49:31 -0800984 # Strongly connected clusters of devices
Jon Hall8f89dda2015-01-22 16:03:33 -0800985 consistentClustersResult = main.TRUE
Jon Hall94fd0472014-12-08 11:52:42 -0800986 for controller in range( len( clusters ) ):
Jon Hall6aec96b2015-01-19 14:49:31 -0800987 if "Error" not in clusters[ controller ]:
988 if clusters[ controller ] == clusters[ 0 ]:
Jon Hall94fd0472014-12-08 11:52:42 -0800989 continue
Jon Hall6aec96b2015-01-19 14:49:31 -0800990 else: # clusters not consistent
991 main.log.report( "clusters from ONOS" +
Jon Hall8f89dda2015-01-22 16:03:33 -0800992 controllerStr +
Jon Hall6aec96b2015-01-19 14:49:31 -0800993 " is inconsistent with ONOS1" )
Jon Hall8f89dda2015-01-22 16:03:33 -0800994 consistentClustersResult = main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -0800995
996 else:
Jon Hall6aec96b2015-01-19 14:49:31 -0800997 main.log.report( "Error in getting dataplane clusters " +
Jon Hall8f89dda2015-01-22 16:03:33 -0800998 "from ONOS" + controllerStr )
999 consistentClustersResult = main.FALSE
1000 main.log.warn( "ONOS" + controllerStr +
Jon Hall6aec96b2015-01-19 14:49:31 -08001001 " clusters response: " +
1002 repr( clusters[ controller ] ) )
1003 utilities.assert_equals(
1004 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001005 actual=consistentClustersResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08001006 onpass="Clusters view is consistent across all ONOS nodes",
1007 onfail="ONOS nodes have different views of clusters" )
1008 # there should always only be one cluster
Jon Hall8f89dda2015-01-22 16:03:33 -08001009 numClusters = len( json.loads( clusters[ 0 ] ) )
Jon Hall6aec96b2015-01-19 14:49:31 -08001010 utilities.assert_equals(
1011 expect=1,
Jon Hall8f89dda2015-01-22 16:03:33 -08001012 actual=numClusters,
Jon Hall6aec96b2015-01-19 14:49:31 -08001013 onpass="ONOS shows 1 SCC",
1014 onfail="ONOS shows " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001015 str( numClusters ) +
Jon Hall6aec96b2015-01-19 14:49:31 -08001016 " SCCs" )
Jon Hall94fd0472014-12-08 11:52:42 -08001017
Jon Hall6aec96b2015-01-19 14:49:31 -08001018 main.step( "Comparing ONOS topology to MN" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001019 devicesResults = main.TRUE
1020 portsResults = main.TRUE
1021 linksResults = main.TRUE
1022 for controller in range( numControllers ):
1023 controllerStr = str( controller + 1 )
Jon Hall6aec96b2015-01-19 14:49:31 -08001024 if devices[ controller ] or "Error" not in devices[ controller ]:
Jon Hall8f89dda2015-01-22 16:03:33 -08001025 currentDevicesResult = main.Mininet1.compareSwitches(
Jon Hall6aec96b2015-01-19 14:49:31 -08001026 MNTopo,
1027 json.loads(
1028 devices[ controller ] ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001029 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08001030 currentDevicesResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001031 utilities.assert_equals( expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001032 actual=currentDevicesResult,
1033 onpass="ONOS" + controllerStr +
1034 " Switches view is correct",
1035 onfail="ONOS" + controllerStr +
1036 " Switches view is incorrect" )
Jon Hallb1290e82014-11-18 16:17:48 -05001037
Jon Hall6aec96b2015-01-19 14:49:31 -08001038 if ports[ controller ] or "Error" not in ports[ controller ]:
Jon Hall8f89dda2015-01-22 16:03:33 -08001039 currentPortsResult = main.Mininet1.comparePorts(
Jon Hall6aec96b2015-01-19 14:49:31 -08001040 MNTopo,
1041 json.loads(
1042 ports[ controller ] ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001043 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08001044 currentPortsResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001045 utilities.assert_equals( expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001046 actual=currentPortsResult,
1047 onpass="ONOS" + controllerStr +
1048 " ports view is correct",
1049 onfail="ONOS" + controllerStr +
1050 " ports view is incorrect" )
Jon Hallb1290e82014-11-18 16:17:48 -05001051
Jon Hall6aec96b2015-01-19 14:49:31 -08001052 if links[ controller ] or "Error" not in links[ controller ]:
Jon Hall8f89dda2015-01-22 16:03:33 -08001053 currentLinksResult = main.Mininet1.compareLinks(
Jon Hall6aec96b2015-01-19 14:49:31 -08001054 MNTopo,
1055 json.loads(
1056 links[ controller ] ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001057 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08001058 currentLinksResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001059 utilities.assert_equals( expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001060 actual=currentLinksResult,
1061 onpass="ONOS" + controllerStr +
1062 " links view is correct",
1063 onfail="ONOS" + controllerStr +
1064 " links view is incorrect" )
Jon Hallb1290e82014-11-18 16:17:48 -05001065
Jon Hall8f89dda2015-01-22 16:03:33 -08001066 devicesResults = devicesResults and currentDevicesResult
1067 portsResults = portsResults and currentPortsResult
1068 linksResults = linksResults and currentLinksResult
Jon Hallb1290e82014-11-18 16:17:48 -05001069
Jon Hall8f89dda2015-01-22 16:03:33 -08001070 topoResult = devicesResults and portsResults and linksResults\
Jon Hall529a37f2015-01-28 10:02:00 -08001071 and consistentHostsResult and consistentClustersResult
Jon Hall8f89dda2015-01-22 16:03:33 -08001072 utilities.assert_equals( expect=main.TRUE, actual=topoResult,
1073 onpass="Topology Check Test successful",
1074 onfail="Topology Check Test NOT successful" )
Jon Hallb1290e82014-11-18 16:17:48 -05001075
Jon Hall8f89dda2015-01-22 16:03:33 -08001076 finalAssert = main.TRUE
1077 finalAssert = finalAssert and topoResult and flowCheck \
1078 and intentCheck and consistentMastership and rolesNotNull
1079 utilities.assert_equals( expect=main.TRUE, actual=finalAssert,
1080 onpass="State check successful",
1081 onfail="State check NOT successful" )
Jon Hallb1290e82014-11-18 16:17:48 -05001082
Jon Hall6aec96b2015-01-19 14:49:31 -08001083 def CASE6( self, main ):
1084 """
Jon Hallb1290e82014-11-18 16:17:48 -05001085 The Failure case. Since this is the Sanity test, we do nothing.
Jon Hall6aec96b2015-01-19 14:49:31 -08001086 """
Jon Hall368769f2014-11-19 15:43:35 -08001087 import time
Jon Hall6aec96b2015-01-19 14:49:31 -08001088 main.log.report( "Wait 60 seconds instead of inducing a failure" )
1089 time.sleep( 60 )
1090 utilities.assert_equals(
1091 expect=main.TRUE,
1092 actual=main.TRUE,
1093 onpass="Sleeping 60 seconds",
1094 onfail="Something is terribly wrong with my math" )
Jon Hallb1290e82014-11-18 16:17:48 -05001095
Jon Hall6aec96b2015-01-19 14:49:31 -08001096 def CASE7( self, main ):
1097 """
Jon Hall368769f2014-11-19 15:43:35 -08001098 Check state after ONOS failure
Jon Hall6aec96b2015-01-19 14:49:31 -08001099 """
Jon Hallb1290e82014-11-18 16:17:48 -05001100 import json
Jon Hall6aec96b2015-01-19 14:49:31 -08001101 main.case( "Running ONOS Constant State Tests" )
Jon Hallb1290e82014-11-18 16:17:48 -05001102
Jon Hall6aec96b2015-01-19 14:49:31 -08001103 # Assert that each device has a master
Jon Hall8f89dda2015-01-22 16:03:33 -08001104 ONOS1MasterNotNull = main.ONOScli1.rolesNotNull()
1105 ONOS2MasterNotNull = main.ONOScli2.rolesNotNull()
1106 ONOS3MasterNotNull = main.ONOScli3.rolesNotNull()
1107 ONOS4MasterNotNull = main.ONOScli4.rolesNotNull()
1108 ONOS5MasterNotNull = main.ONOScli5.rolesNotNull()
1109 ONOS6MasterNotNull = main.ONOScli6.rolesNotNull()
1110 ONOS7MasterNotNull = main.ONOScli7.rolesNotNull()
1111 rolesNotNull = ONOS1MasterNotNull and ONOS2MasterNotNull and\
1112 ONOS3MasterNotNull and ONOS4MasterNotNull and\
1113 ONOS5MasterNotNull and ONOS6MasterNotNull and\
1114 ONOS7MasterNotNull
Jon Hall6aec96b2015-01-19 14:49:31 -08001115 utilities.assert_equals(
1116 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001117 actual=rolesNotNull,
Jon Hall6aec96b2015-01-19 14:49:31 -08001118 onpass="Each device has a master",
1119 onfail="Some devices don't have a master assigned" )
Jon Hall94fd0472014-12-08 11:52:42 -08001120
Jon Hall6aec96b2015-01-19 14:49:31 -08001121 main.step( "Check if switch roles are consistent across all nodes" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001122 ONOS1Mastership = main.ONOScli1.roles()
1123 ONOS2Mastership = main.ONOScli2.roles()
1124 ONOS3Mastership = main.ONOScli3.roles()
1125 ONOS4Mastership = main.ONOScli4.roles()
1126 ONOS5Mastership = main.ONOScli5.roles()
1127 ONOS6Mastership = main.ONOScli6.roles()
1128 ONOS7Mastership = main.ONOScli7.roles()
1129 # print json.dumps( json.loads( ONOS1Mastership ), sort_keys=True,
Jon Hall6aec96b2015-01-19 14:49:31 -08001130 # indent=4, separators=( ',', ': ' ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001131 if "Error" in ONOS1Mastership or not ONOS1Mastership\
1132 or "Error" in ONOS2Mastership or not ONOS2Mastership\
1133 or "Error" in ONOS3Mastership or not ONOS3Mastership\
1134 or "Error" in ONOS4Mastership or not ONOS4Mastership\
1135 or "Error" in ONOS5Mastership or not ONOS5Mastership\
1136 or "Error" in ONOS6Mastership or not ONOS6Mastership\
1137 or "Error" in ONOS7Mastership or not ONOS7Mastership:
Jon Hall6aec96b2015-01-19 14:49:31 -08001138 main.log.error( "Error in getting ONOS mastership" )
1139 main.log.warn( "ONOS1 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001140 repr( ONOS1Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -08001141 main.log.warn( "ONOS2 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001142 repr( ONOS2Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -08001143 main.log.warn( "ONOS3 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001144 repr( ONOS3Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -08001145 main.log.warn( "ONOS4 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001146 repr( ONOS4Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -08001147 main.log.warn( "ONOS5 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001148 repr( ONOS5Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -08001149 main.log.warn( "ONOS6 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001150 repr( ONOS6Mastership ) )
Jon Hall6aec96b2015-01-19 14:49:31 -08001151 main.log.warn( "ONOS7 mastership response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001152 repr( ONOS7Mastership ) )
1153 consistentMastership = main.FALSE
1154 elif ONOS1Mastership == ONOS2Mastership\
1155 and ONOS1Mastership == ONOS3Mastership\
1156 and ONOS1Mastership == ONOS4Mastership\
1157 and ONOS1Mastership == ONOS5Mastership\
1158 and ONOS1Mastership == ONOS6Mastership\
1159 and ONOS1Mastership == ONOS7Mastership:
1160 consistentMastership = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001161 main.log.report(
1162 "Switch roles are consistent across all ONOS nodes" )
Jon Hallb1290e82014-11-18 16:17:48 -05001163 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08001164 main.log.warn( "ONOS1 roles: ", json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -08001165 json.loads( ONOS1Mastership ), sort_keys=True, indent=4,
Jon Hall6aec96b2015-01-19 14:49:31 -08001166 separators=( ',', ': ' ) ) )
1167 main.log.warn( "ONOS2 roles: ", json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -08001168 json.loads( ONOS2Mastership ), sort_keys=True, indent=4,
Jon Hall6aec96b2015-01-19 14:49:31 -08001169 separators=( ',', ': ' ) ) )
1170 main.log.warn( "ONOS3 roles: ", json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -08001171 json.loads( ONOS3Mastership ), sort_keys=True, indent=4,
Jon Hall6aec96b2015-01-19 14:49:31 -08001172 separators=( ',', ': ' ) ) )
1173 main.log.warn( "ONOS4 roles: ", json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -08001174 json.loads( ONOS4Mastership ), sort_keys=True, indent=4,
Jon Hall6aec96b2015-01-19 14:49:31 -08001175 separators=( ',', ': ' ) ) )
1176 main.log.warn( "ONOS5 roles: ", json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -08001177 json.loads( ONOS5Mastership ), sort_keys=True, indent=4,
Jon Hall6aec96b2015-01-19 14:49:31 -08001178 separators=( ',', ': ' ) ) )
1179 main.log.warn( "ONOS6 roles: ", json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -08001180 json.loads( ONOS6Mastership ), sort_keys=True, indent=4,
Jon Hall6aec96b2015-01-19 14:49:31 -08001181 separators=( ',', ': ' ) ) )
1182 main.log.warn( "ONOS7 roles: ", json.dumps(
Jon Hall8f89dda2015-01-22 16:03:33 -08001183 json.loads( ONOS7Mastership ), sort_keys=True, indent=4,
Jon Hall6aec96b2015-01-19 14:49:31 -08001184 separators=( ',', ': ' ) ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001185 consistentMastership = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001186 utilities.assert_equals(
1187 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001188 actual=consistentMastership,
Jon Hall6aec96b2015-01-19 14:49:31 -08001189 onpass="Switch roles are consistent across all ONOS nodes",
1190 onfail="ONOS nodes have different views of switch roles" )
Jon Hallb1290e82014-11-18 16:17:48 -05001191
1192 description2 = "Compare switch roles from before failure"
Jon Hall6aec96b2015-01-19 14:49:31 -08001193 main.step( description2 )
Jon Hallb1290e82014-11-18 16:17:48 -05001194
Jon Hall8f89dda2015-01-22 16:03:33 -08001195 currentJson = json.loads( ONOS1Mastership )
1196 oldJson = json.loads( mastershipState )
1197 mastershipCheck = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001198 for i in range( 1, 29 ):
1199 switchDPID = str(
1200 main.Mininet1.getSwitchDPID(
1201 switch="s" +
1202 str( i ) ) )
Jon Hallb1290e82014-11-18 16:17:48 -05001203
Jon Hall8f89dda2015-01-22 16:03:33 -08001204 current = [ switch[ 'master' ] for switch in currentJson
Jon Hall6aec96b2015-01-19 14:49:31 -08001205 if switchDPID in switch[ 'id' ] ]
Jon Hall8f89dda2015-01-22 16:03:33 -08001206 old = [ switch[ 'master' ] for switch in oldJson
Jon Hall6aec96b2015-01-19 14:49:31 -08001207 if switchDPID in switch[ 'id' ] ]
Jon Hallb1290e82014-11-18 16:17:48 -05001208 if current == old:
Jon Hall8f89dda2015-01-22 16:03:33 -08001209 mastershipCheck = mastershipCheck and main.TRUE
Jon Hallb1290e82014-11-18 16:17:48 -05001210 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08001211 main.log.warn( "Mastership of switch %s changed" % switchDPID )
Jon Hall8f89dda2015-01-22 16:03:33 -08001212 mastershipCheck = main.FALSE
1213 if mastershipCheck == main.TRUE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001214 main.log.report( "Mastership of Switches was not changed" )
1215 utilities.assert_equals(
1216 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001217 actual=mastershipCheck,
Jon Hall6aec96b2015-01-19 14:49:31 -08001218 onpass="Mastership of Switches was not changed",
1219 onfail="Mastership of some switches changed" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001220 mastershipCheck = mastershipCheck and consistentMastership
Jon Hallb1290e82014-11-18 16:17:48 -05001221
Jon Hall6aec96b2015-01-19 14:49:31 -08001222 main.step( "Get the intents and compare across all nodes" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001223 ONOS1Intents = main.ONOScli1.intents( jsonFormat=True )
1224 ONOS2Intents = main.ONOScli2.intents( jsonFormat=True )
1225 ONOS3Intents = main.ONOScli3.intents( jsonFormat=True )
1226 ONOS4Intents = main.ONOScli4.intents( jsonFormat=True )
1227 ONOS5Intents = main.ONOScli5.intents( jsonFormat=True )
1228 ONOS6Intents = main.ONOScli6.intents( jsonFormat=True )
1229 ONOS7Intents = main.ONOScli7.intents( jsonFormat=True )
1230 intentCheck = main.FALSE
1231 if "Error" in ONOS1Intents or not ONOS1Intents\
1232 or "Error" in ONOS2Intents or not ONOS2Intents\
1233 or "Error" in ONOS3Intents or not ONOS3Intents\
1234 or "Error" in ONOS4Intents or not ONOS4Intents\
1235 or "Error" in ONOS5Intents or not ONOS5Intents\
1236 or "Error" in ONOS6Intents or not ONOS6Intents\
1237 or "Error" in ONOS7Intents or not ONOS7Intents:
Jon Hall6aec96b2015-01-19 14:49:31 -08001238 main.log.report( "Error in getting ONOS intents" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001239 main.log.warn( "ONOS1 intents response: " + repr( ONOS1Intents ) )
1240 main.log.warn( "ONOS2 intents response: " + repr( ONOS2Intents ) )
1241 main.log.warn( "ONOS3 intents response: " + repr( ONOS3Intents ) )
1242 main.log.warn( "ONOS4 intents response: " + repr( ONOS4Intents ) )
1243 main.log.warn( "ONOS5 intents response: " + repr( ONOS5Intents ) )
1244 main.log.warn( "ONOS6 intents response: " + repr( ONOS6Intents ) )
1245 main.log.warn( "ONOS7 intents response: " + repr( ONOS7Intents ) )
1246 elif ONOS1Intents == ONOS2Intents\
1247 and ONOS1Intents == ONOS3Intents\
1248 and ONOS1Intents == ONOS4Intents\
1249 and ONOS1Intents == ONOS5Intents\
1250 and ONOS1Intents == ONOS6Intents\
1251 and ONOS1Intents == ONOS7Intents:
1252 intentCheck = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001253 main.log.report( "Intents are consistent across all ONOS nodes" )
Jon Hallb1290e82014-11-18 16:17:48 -05001254 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08001255 main.log.warn( "ONOS1 intents: " )
Jon Hall8f89dda2015-01-22 16:03:33 -08001256 print json.dumps( json.loads( ONOS1Intents ), sort_keys=True,
Jon Hall6aec96b2015-01-19 14:49:31 -08001257 indent=4, separators=( ',', ': ' ) )
1258 main.log.warn( "ONOS2 intents: " )
Jon Hall8f89dda2015-01-22 16:03:33 -08001259 print json.dumps( json.loads( ONOS2Intents ), sort_keys=True,
Jon Hall6aec96b2015-01-19 14:49:31 -08001260 indent=4, separators=( ',', ': ' ) )
1261 main.log.warn( "ONOS3 intents: " )
Jon Hall8f89dda2015-01-22 16:03:33 -08001262 print json.dumps( json.loads( ONOS3Intents ), sort_keys=True,
Jon Hall6aec96b2015-01-19 14:49:31 -08001263 indent=4, separators=( ',', ': ' ) )
1264 main.log.warn( "ONOS4 intents: " )
Jon Hall8f89dda2015-01-22 16:03:33 -08001265 print json.dumps( json.loads( ONOS4Intents ), sort_keys=True,
Jon Hall6aec96b2015-01-19 14:49:31 -08001266 indent=4, separators=( ',', ': ' ) )
1267 main.log.warn( "ONOS5 intents: " )
Jon Hall8f89dda2015-01-22 16:03:33 -08001268 print json.dumps( json.loads( ONOS5Intents ), sort_keys=True,
Jon Hall6aec96b2015-01-19 14:49:31 -08001269 indent=4, separators=( ',', ': ' ) )
1270 main.log.warn( "ONOS6 intents: " )
Jon Hall8f89dda2015-01-22 16:03:33 -08001271 print json.dumps( json.loads( ONOS6Intents ), sort_keys=True,
Jon Hall6aec96b2015-01-19 14:49:31 -08001272 indent=4, separators=( ',', ': ' ) )
1273 main.log.warn( "ONOS7 intents: " )
Jon Hall8f89dda2015-01-22 16:03:33 -08001274 print json.dumps( json.loads( ONOS7Intents ), sort_keys=True,
Jon Hall6aec96b2015-01-19 14:49:31 -08001275 indent=4, separators=( ',', ': ' ) )
1276 utilities.assert_equals(
1277 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001278 actual=intentCheck,
Jon Hall6aec96b2015-01-19 14:49:31 -08001279 onpass="Intents are consistent across all ONOS nodes",
1280 onfail="ONOS nodes have different views of intents" )
Jon Hall1b8f54a2015-02-04 13:24:20 -08001281 # Print the intent states
1282 intents = []
1283 intents.append( ONOS1Intents )
1284 intents.append( ONOS2Intents )
1285 intents.append( ONOS3Intents )
1286 intents.append( ONOS4Intents )
1287 intents.append( ONOS5Intents )
1288 intents.append( ONOS6Intents )
1289 intents.append( ONOS7Intents )
1290 intentStates = []
1291 for node in intents: # Iter through ONOS nodes
1292 nodeStates = []
1293 for intent in json.loads( node ): # Iter through intents of a node
1294 nodeStates.append( intent[ 'state' ] )
1295 intentStates.append( nodeStates )
1296 out = [ (i, nodeStates.count( i ) ) for i in set( nodeStates ) ]
1297 main.log.info( dict( out ) )
1298
Jon Hallb1290e82014-11-18 16:17:48 -05001299
Jon Hall6aec96b2015-01-19 14:49:31 -08001300 # NOTE: Hazelcast has no durability, so intents are lost across system
1301 # restarts
1302 main.step( "Compare current intents with intents before the failure" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001303 # NOTE: this requires case 5 to pass for intentState to be set.
Jon Hall94fd0472014-12-08 11:52:42 -08001304 # maybe we should stop the test if that fails?
Jon Hall1b8f54a2015-02-04 13:24:20 -08001305 sameIntents = main.TRUE
1306 if intentState and intentState == ONOS1Intents:
Jon Hall8f89dda2015-01-22 16:03:33 -08001307 sameIntents = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001308 main.log.report( "Intents are consistent with before failure" )
1309 # TODO: possibly the states have changed? we may need to figure out
1310 # what the aceptable states are
Jon Hallb1290e82014-11-18 16:17:48 -05001311 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08001312 try:
1313 main.log.warn( "ONOS1 intents: " )
Jon Hall8f89dda2015-01-22 16:03:33 -08001314 print json.dumps( json.loads( ONOS1Intents ),
Jon Hall6aec96b2015-01-19 14:49:31 -08001315 sort_keys=True, indent=4,
1316 separators=( ',', ': ' ) )
1317 except:
1318 pass
Jon Hall8f89dda2015-01-22 16:03:33 -08001319 sameIntents = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001320 utilities.assert_equals(
1321 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001322 actual=sameIntents,
Jon Hall6aec96b2015-01-19 14:49:31 -08001323 onpass="Intents are consistent with before failure",
1324 onfail="The Intents changed during failure" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001325 intentCheck = intentCheck and sameIntents
Jon Hallb1290e82014-11-18 16:17:48 -05001326
Jon Hall6aec96b2015-01-19 14:49:31 -08001327 main.step( "Get the OF Table entries and compare to before " +
1328 "component failure" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001329 FlowTables = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001330 flows2 = []
1331 for i in range( 28 ):
1332 main.log.info( "Checking flow table on s" + str( i + 1 ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001333 tmpFlows = main.Mininet2.getFlowTable( 1.3, "s" + str( i + 1 ) )
1334 flows2.append( tmpFlows )
1335 tempResult = main.Mininet2.flowComp(
Jon Hall6aec96b2015-01-19 14:49:31 -08001336 flow1=flows[ i ],
Jon Hall8f89dda2015-01-22 16:03:33 -08001337 flow2=tmpFlows )
1338 FlowTables = FlowTables and tempResult
1339 if FlowTables == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001340 main.log.info( "Differences in flow table for switch: s" +
1341 str( i + 1 ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001342 if FlowTables == main.TRUE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001343 main.log.report( "No changes were found in the flow tables" )
1344 utilities.assert_equals(
1345 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001346 actual=FlowTables,
Jon Hall6aec96b2015-01-19 14:49:31 -08001347 onpass="No changes were found in the flow tables",
1348 onfail="Changes were found in the flow tables" )
Jon Hallb1290e82014-11-18 16:17:48 -05001349
Jon Hall6aec96b2015-01-19 14:49:31 -08001350 main.step( "Check the continuous pings to ensure that no packets " +
1351 "were dropped during component failure" )
1352 # FIXME: This check is always failing. Investigate cause
1353 # NOTE: this may be something to do with file permsissions
Jon Hallb1290e82014-11-18 16:17:48 -05001354 # or slight change in format
Jon Hall6aec96b2015-01-19 14:49:31 -08001355 main.Mininet2.pingKill(
1356 main.params[ 'TESTONUSER' ],
1357 main.params[ 'TESTONIP' ] )
Jon Hall8f89dda2015-01-22 16:03:33 -08001358 LossInPings = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001359 # NOTE: checkForLoss returns main.FALSE with 0% packet loss
1360 for i in range( 8, 18 ):
1361 main.log.info(
1362 "Checking for a loss in pings along flow from s" +
1363 str( i ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001364 LossInPings = main.Mininet2.checkForLoss(
Jon Hall6aec96b2015-01-19 14:49:31 -08001365 "/tmp/ping.h" +
Jon Hall8f89dda2015-01-22 16:03:33 -08001366 str( i ) ) or LossInPings
1367 if LossInPings == main.TRUE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001368 main.log.info( "Loss in ping detected" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001369 elif LossInPings == main.ERROR:
Jon Hall6aec96b2015-01-19 14:49:31 -08001370 main.log.info( "There are multiple mininet process running" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001371 elif LossInPings == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001372 main.log.info( "No Loss in the pings" )
1373 main.log.report( "No loss of dataplane connectivity" )
1374 utilities.assert_equals(
1375 expect=main.FALSE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001376 actual=LossInPings,
Jon Hall6aec96b2015-01-19 14:49:31 -08001377 onpass="No Loss of connectivity",
1378 onfail="Loss of dataplane connectivity detected" )
Jon Hallb1290e82014-11-18 16:17:48 -05001379
Jon Hall6aec96b2015-01-19 14:49:31 -08001380 # Test of LeadershipElection
1381 # NOTE: this only works for the sanity test. In case of failures,
1382 # leader will likely change
Jon Hall8f89dda2015-01-22 16:03:33 -08001383 leader = ONOS1Ip
1384 leaderResult = main.TRUE
1385 for controller in range( 1, numControllers + 1 ):
Jon Hall6aec96b2015-01-19 14:49:31 -08001386 # loop through ONOScli handlers
1387 node = getattr( main, ( 'ONOScli' + str( controller ) ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001388 leaderN = node.electionTestLeader()
Jon Hall6aec96b2015-01-19 14:49:31 -08001389 # verify leader is ONOS1
Jon Hall669173b2014-12-17 11:36:30 -08001390 if leaderN == leader:
Jon Hall6aec96b2015-01-19 14:49:31 -08001391 # all is well
1392 # NOTE: In failure scenario, this could be a new node, maybe
1393 # check != ONOS1
Jon Hall669173b2014-12-17 11:36:30 -08001394 pass
1395 elif leaderN == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001396 # error in response
1397 main.log.report( "Something is wrong with " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001398 "electionTestLeader function," +
Jon Hall6aec96b2015-01-19 14:49:31 -08001399 " check the error logs" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001400 leaderResult = main.FALSE
Jon Hall669173b2014-12-17 11:36:30 -08001401 elif leader != leaderN:
Jon Hall8f89dda2015-01-22 16:03:33 -08001402 leaderResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001403 main.log.report( "ONOS" + str( controller ) + " sees " +
1404 str( leaderN ) +
1405 " as the leader of the election app. " +
1406 "Leader should be " + str( leader ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001407 if leaderResult:
1408 main.log.report( "Leadership election tests passed( consistent " +
Jon Hall6aec96b2015-01-19 14:49:31 -08001409 "view of leader across listeners and a new " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001410 "leader was re-elected if applicable )" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001411 utilities.assert_equals(
1412 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001413 actual=leaderResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08001414 onpass="Leadership election passed",
1415 onfail="Something went wrong with Leadership election" )
Jon Hallb1290e82014-11-18 16:17:48 -05001416
Jon Hall8f89dda2015-01-22 16:03:33 -08001417 result = mastershipCheck and intentCheck and FlowTables and\
1418 ( not LossInPings ) and rolesNotNull and leaderResult
Jon Hall6aec96b2015-01-19 14:49:31 -08001419 result = int( result )
Jon Hallb1290e82014-11-18 16:17:48 -05001420 if result == main.TRUE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001421 main.log.report( "Constant State Tests Passed" )
1422 utilities.assert_equals( expect=main.TRUE, actual=result,
Jon Hall8f89dda2015-01-22 16:03:33 -08001423 onpass="Constant State Tests Passed",
1424 onfail="Constant state tests failed" )
Jon Hallb1290e82014-11-18 16:17:48 -05001425
Jon Hall6aec96b2015-01-19 14:49:31 -08001426 def CASE8( self, main ):
1427 """
Jon Hallb1290e82014-11-18 16:17:48 -05001428 Compare topo
Jon Hall6aec96b2015-01-19 14:49:31 -08001429 """
Jon Hallb1290e82014-11-18 16:17:48 -05001430 import sys
Jon Hall6aec96b2015-01-19 14:49:31 -08001431 # FIXME add this path to params
1432 sys.path.append( "/home/admin/sts" )
1433 # assumes that sts is already in you PYTHONPATH
1434 from sts.topology.teston_topology import TestONTopology
Jon Hallb1290e82014-11-18 16:17:48 -05001435 import json
Jon Hall73cf9cc2014-11-20 22:28:38 -08001436 import time
Jon Hallb1290e82014-11-18 16:17:48 -05001437
Jon Hall6aec96b2015-01-19 14:49:31 -08001438 description = "Compare ONOS Topology view to Mininet topology"
1439 main.case( description )
1440 main.log.report( description )
1441 main.step( "Create TestONTopology object" )
Jon Hallb1290e82014-11-18 16:17:48 -05001442 ctrls = []
1443 count = 1
1444 while True:
1445 temp = ()
Jon Hall6aec96b2015-01-19 14:49:31 -08001446 if ( 'ip' + str( count ) ) in main.params[ 'CTRL' ]:
1447 temp = temp + ( getattr( main, ( 'ONOS' + str( count ) ) ), )
1448 temp = temp + ( "ONOS" + str( count ), )
1449 temp = temp + ( main.params[ 'CTRL' ][ 'ip' + str( count ) ], )
1450 temp = temp + \
1451 ( eval( main.params[ 'CTRL' ][ 'port' + str( count ) ] ), )
1452 ctrls.append( temp )
Jon Hallb1290e82014-11-18 16:17:48 -05001453 count = count + 1
1454 else:
1455 break
Jon Hall6aec96b2015-01-19 14:49:31 -08001456 MNTopo = TestONTopology(
1457 main.Mininet1,
1458 ctrls ) # can also add Intent API info for intent operations
Jon Hallb1290e82014-11-18 16:17:48 -05001459
Jon Hall6aec96b2015-01-19 14:49:31 -08001460 main.step( "Comparing ONOS topology to MN" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001461 devicesResults = main.TRUE
1462 portsResults = main.TRUE
1463 linksResults = main.TRUE
1464 topoResult = main.FALSE
Jon Hall73cf9cc2014-11-20 22:28:38 -08001465 elapsed = 0
Jon Hallffb386d2014-11-21 13:43:38 -08001466 count = 0
Jon Hall6aec96b2015-01-19 14:49:31 -08001467 main.step( "Collecting topology information from ONOS" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001468 startTime = time.time()
1469 while topoResult == main.FALSE and elapsed < 60:
Jon Hallffb386d2014-11-21 13:43:38 -08001470 count = count + 1
Jon Hall94fd0472014-12-08 11:52:42 -08001471 if count > 1:
Jon Hall6aec96b2015-01-19 14:49:31 -08001472 # TODO: Depricate STS usage
1473 MNTopo = TestONTopology(
1474 main.Mininet1,
1475 ctrls )
Jon Hall8f89dda2015-01-22 16:03:33 -08001476 cliStart = time.time()
Jon Hall94fd0472014-12-08 11:52:42 -08001477 devices = []
1478 devices.append( main.ONOScli1.devices() )
1479 devices.append( main.ONOScli2.devices() )
1480 devices.append( main.ONOScli3.devices() )
1481 devices.append( main.ONOScli4.devices() )
1482 devices.append( main.ONOScli5.devices() )
1483 devices.append( main.ONOScli6.devices() )
1484 devices.append( main.ONOScli7.devices() )
1485 hosts = []
Jon Hall529a37f2015-01-28 10:02:00 -08001486 hosts.append( json.loads( main.ONOScli1.hosts() ) )
1487 hosts.append( json.loads( main.ONOScli2.hosts() ) )
1488 hosts.append( json.loads( main.ONOScli3.hosts() ) )
1489 hosts.append( json.loads( main.ONOScli4.hosts() ) )
1490 hosts.append( json.loads( main.ONOScli5.hosts() ) )
1491 hosts.append( json.loads( main.ONOScli6.hosts() ) )
1492 hosts.append( json.loads( main.ONOScli7.hosts() ) )
1493 for controller in range( 0, len( hosts ) ):
1494 controllerStr = str( controller + 1 )
1495 for host in hosts[ controller ]:
Jon Hall529a37f2015-01-28 10:02:00 -08001496 if host[ 'ips' ] == []:
1497 main.log.error(
1498 "DEBUG:Error with host ips on controller" +
1499 controllerStr + ": " + str( host ) )
Jon Hall94fd0472014-12-08 11:52:42 -08001500 ports = []
1501 ports.append( main.ONOScli1.ports() )
1502 ports.append( main.ONOScli2.ports() )
1503 ports.append( main.ONOScli3.ports() )
1504 ports.append( main.ONOScli4.ports() )
1505 ports.append( main.ONOScli5.ports() )
1506 ports.append( main.ONOScli6.ports() )
1507 ports.append( main.ONOScli7.ports() )
1508 links = []
1509 links.append( main.ONOScli1.links() )
1510 links.append( main.ONOScli2.links() )
1511 links.append( main.ONOScli3.links() )
1512 links.append( main.ONOScli4.links() )
1513 links.append( main.ONOScli5.links() )
1514 links.append( main.ONOScli6.links() )
1515 links.append( main.ONOScli7.links() )
1516 clusters = []
1517 clusters.append( main.ONOScli1.clusters() )
1518 clusters.append( main.ONOScli2.clusters() )
1519 clusters.append( main.ONOScli3.clusters() )
1520 clusters.append( main.ONOScli4.clusters() )
1521 clusters.append( main.ONOScli5.clusters() )
1522 clusters.append( main.ONOScli6.clusters() )
1523 clusters.append( main.ONOScli7.clusters() )
Jon Hallb1290e82014-11-18 16:17:48 -05001524
Jon Hall8f89dda2015-01-22 16:03:33 -08001525 elapsed = time.time() - startTime
1526 cliTime = time.time() - cliStart
1527 print "CLI time: " + str( cliTime )
Jon Hallb1290e82014-11-18 16:17:48 -05001528
Jon Hall529a37f2015-01-28 10:02:00 -08001529 try:
1530 for controller in range( numControllers ):
1531 controllerStr = str( controller + 1 )
1532 if devices[ controller ] or "Error" not in devices[
1533 controller ]:
1534 currentDevicesResult = main.Mininet1.compareSwitches(
1535 MNTopo,
1536 json.loads(
1537 devices[ controller ] ) )
1538 else:
1539 currentDevicesResult = main.FALSE
1540 utilities.assert_equals( expect=main.TRUE,
1541 actual=currentDevicesResult,
1542 onpass="ONOS" + controllerStr +
1543 " Switches view is correct",
1544 onfail="ONOS" + controllerStr +
1545 " Switches view is incorrect" )
Jon Hallb1290e82014-11-18 16:17:48 -05001546
Jon Hall529a37f2015-01-28 10:02:00 -08001547 if ports[ controller ] or "Error" not in ports[ controller ]:
1548 currentPortsResult = main.Mininet1.comparePorts(
1549 MNTopo,
1550 json.loads(
1551 ports[ controller ] ) )
1552 else:
1553 currentPortsResult = main.FALSE
1554 utilities.assert_equals( expect=main.TRUE,
1555 actual=currentPortsResult,
1556 onpass="ONOS" + controllerStr +
1557 " ports view is correct",
1558 onfail="ONOS" + controllerStr +
1559 " ports view is incorrect" )
Jon Hall94fd0472014-12-08 11:52:42 -08001560
Jon Hall529a37f2015-01-28 10:02:00 -08001561 if links[ controller ] or "Error" not in links[ controller ]:
1562 currentLinksResult = main.Mininet1.compareLinks(
1563 MNTopo,
1564 json.loads(
1565 links[ controller ] ) )
1566 else:
1567 currentLinksResult = main.FALSE
1568 utilities.assert_equals( expect=main.TRUE,
1569 actual=currentLinksResult,
1570 onpass="ONOS" + controllerStr +
1571 " links view is correct",
1572 onfail="ONOS" + controllerStr +
1573 " links view is incorrect" )
1574 devicesResults = devicesResults and currentDevicesResult
1575 portsResults = portsResults and currentPortsResult
1576 linksResults = linksResults and currentLinksResult
Jon Hall94fd0472014-12-08 11:52:42 -08001577
Jon Hall529a37f2015-01-28 10:02:00 -08001578 # Compare json objects for hosts and dataplane clusters
Jon Hall94fd0472014-12-08 11:52:42 -08001579
Jon Hall529a37f2015-01-28 10:02:00 -08001580 # hosts
1581 consistentHostsResult = main.TRUE
1582 for controller in range( len( hosts ) ):
1583 controllerStr = str( controller + 1 )
1584 if "Error" not in hosts[ controller ]:
1585 if hosts[ controller ] == hosts[ 0 ]:
1586 continue
1587 else: # hosts not consistent
1588 main.log.report( "hosts from ONOS" + controllerStr +
1589 " is inconsistent with ONOS1" )
1590 main.log.warn( repr( hosts[ controller ] ) )
1591 consistentHostsResult = main.FALSE
1592
1593 else:
1594 main.log.report( "Error in getting ONOS hosts from ONOS" +
1595 controllerStr )
Jon Hall8f89dda2015-01-22 16:03:33 -08001596 consistentHostsResult = main.FALSE
Jon Hall529a37f2015-01-28 10:02:00 -08001597 main.log.warn( "ONOS" + controllerStr +
1598 " hosts response: " +
1599 repr( hosts[ controller ] ) )
1600 utilities.assert_equals(
1601 expect=main.TRUE,
1602 actual=consistentHostsResult,
1603 onpass="Hosts view is consistent across all ONOS nodes",
1604 onfail="ONOS nodes have different views of hosts" )
Jon Hall94fd0472014-12-08 11:52:42 -08001605
Jon Hall529a37f2015-01-28 10:02:00 -08001606 # Strongly connected clusters of devices
1607 consistentClustersResult = main.TRUE
1608 for controller in range( len( clusters ) ):
1609 controllerStr = str( controller + 1 )
1610 if "Error" not in clusters[ controller ]:
1611 if clusters[ controller ] == clusters[ 0 ]:
1612 continue
1613 else: # clusters not consistent
1614 main.log.report( "clusters from ONOS" +
1615 controllerStr +
1616 " is inconsistent with ONOS1" )
1617 consistentClustersResult = main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -08001618
Jon Hall529a37f2015-01-28 10:02:00 -08001619 else:
1620 main.log.report( "Error in getting dataplane clusters " +
1621 "from ONOS" + controllerStr )
Jon Hall8f89dda2015-01-22 16:03:33 -08001622 consistentClustersResult = main.FALSE
Jon Hall529a37f2015-01-28 10:02:00 -08001623 main.log.warn( "ONOS" + controllerStr +
1624 " clusters response: " +
1625 repr( clusters[ controller ] ) )
1626 utilities.assert_equals(
1627 expect=main.TRUE,
1628 actual=consistentClustersResult,
1629 onpass="Clusters view is consistent across all ONOS nodes",
1630 onfail="ONOS nodes have different views of clusters" )
1631 # there should always only be one cluster
1632 numClusters = len( json.loads( clusters[ 0 ] ) )
1633 utilities.assert_equals(
1634 expect=1,
1635 actual=numClusters,
1636 onpass="ONOS shows 1 SCC",
1637 onfail="ONOS shows " +
1638 str( numClusters ) +
1639 " SCCs" )
Jon Hall94fd0472014-12-08 11:52:42 -08001640
Jon Hall529a37f2015-01-28 10:02:00 -08001641 topoResult = ( devicesResults and portsResults and linksResults
1642 and consistentHostsResult
1643 and consistentClustersResult )
Jon Hall94fd0472014-12-08 11:52:42 -08001644
Jon Hall529a37f2015-01-28 10:02:00 -08001645 topoResult = topoResult and int( count <= 2 )
1646 note = "note it takes about " + str( int( cliTime ) ) + \
1647 " seconds for the test to make all the cli calls to fetch " +\
1648 "the topology from each ONOS instance"
Jon Hall1b8f54a2015-02-04 13:24:20 -08001649 main.log.info(
Jon Hall529a37f2015-01-28 10:02:00 -08001650 "Very crass estimate for topology discovery/convergence( " +
1651 str( note ) + " ): " + str( elapsed ) + " seconds, " +
1652 str( count ) + " tries" )
1653 utilities.assert_equals( expect=main.TRUE, actual=topoResult,
1654 onpass="Topology Check Test successful",
1655 onfail="Topology Check Test NOT successful" )
1656 if topoResult == main.TRUE:
1657 main.log.report( "ONOS topology view matches Mininet topology" )
1658 except:
1659 main.log.info( self.name + " ::::::" )
1660 main.log.error( traceback.print_exc() )
1661 main.log.info( self.name + " ::::::" )
Jon Hall94fd0472014-12-08 11:52:42 -08001662
Jon Hallb1290e82014-11-18 16:17:48 -05001663
Jon Hall6aec96b2015-01-19 14:49:31 -08001664 def CASE9( self, main ):
1665 """
Jon Hallb1290e82014-11-18 16:17:48 -05001666 Link s3-s28 down
Jon Hall6aec96b2015-01-19 14:49:31 -08001667 """
1668 import time
1669 # NOTE: You should probably run a topology check after this
Jon Hallb1290e82014-11-18 16:17:48 -05001670
Jon Hall8f89dda2015-01-22 16:03:33 -08001671 linkSleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] )
Jon Hallb1290e82014-11-18 16:17:48 -05001672
Jon Hall6aec96b2015-01-19 14:49:31 -08001673 description = "Turn off a link to ensure that Link Discovery " +\
Jon Hall8f89dda2015-01-22 16:03:33 -08001674 "is working properly"
Jon Hall6aec96b2015-01-19 14:49:31 -08001675 main.log.report( description )
1676 main.case( description )
Jon Hallb1290e82014-11-18 16:17:48 -05001677
Jon Hall6aec96b2015-01-19 14:49:31 -08001678 main.step( "Kill Link between s3 and s28" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001679 LinkDown = main.Mininet1.link( END1="s3", END2="s28", OPTION="down" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001680 main.log.info(
1681 "Waiting " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001682 str( linkSleep ) +
Jon Hall6aec96b2015-01-19 14:49:31 -08001683 " seconds for link down to be discovered" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001684 time.sleep( linkSleep )
1685 utilities.assert_equals( expect=main.TRUE, actual=LinkDown,
1686 onpass="Link down succesful",
1687 onfail="Failed to bring link down" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001688 # TODO do some sort of check here
Jon Hallb1290e82014-11-18 16:17:48 -05001689
Jon Hall6aec96b2015-01-19 14:49:31 -08001690 def CASE10( self, main ):
1691 """
Jon Hallb1290e82014-11-18 16:17:48 -05001692 Link s3-s28 up
Jon Hall6aec96b2015-01-19 14:49:31 -08001693 """
1694 import time
1695 # NOTE: You should probably run a topology check after this
Jon Hallb1290e82014-11-18 16:17:48 -05001696
Jon Hall8f89dda2015-01-22 16:03:33 -08001697 linkSleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] )
Jon Hallb1290e82014-11-18 16:17:48 -05001698
Jon Hall6aec96b2015-01-19 14:49:31 -08001699 description = "Restore a link to ensure that Link Discovery is " + \
Jon Hall8f89dda2015-01-22 16:03:33 -08001700 "working properly"
Jon Hall6aec96b2015-01-19 14:49:31 -08001701 main.log.report( description )
1702 main.case( description )
Jon Hallb1290e82014-11-18 16:17:48 -05001703
Jon Hall6aec96b2015-01-19 14:49:31 -08001704 main.step( "Bring link between s3 and s28 back up" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001705 LinkUp = main.Mininet1.link( END1="s3", END2="s28", OPTION="up" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001706 main.log.info(
1707 "Waiting " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001708 str( linkSleep ) +
Jon Hall6aec96b2015-01-19 14:49:31 -08001709 " seconds for link up to be discovered" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001710 time.sleep( linkSleep )
1711 utilities.assert_equals( expect=main.TRUE, actual=LinkUp,
1712 onpass="Link up succesful",
1713 onfail="Failed to bring link up" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001714 # TODO do some sort of check here
Jon Hallb1290e82014-11-18 16:17:48 -05001715
Jon Hall6aec96b2015-01-19 14:49:31 -08001716 def CASE11( self, main ):
1717 """
Jon Hallb1290e82014-11-18 16:17:48 -05001718 Switch Down
Jon Hall6aec96b2015-01-19 14:49:31 -08001719 """
1720 # NOTE: You should probably run a topology check after this
Jon Hallb1290e82014-11-18 16:17:48 -05001721 import time
1722
Jon Hall8f89dda2015-01-22 16:03:33 -08001723 switchSleep = float( main.params[ 'timers' ][ 'SwitchDiscovery' ] )
Jon Hallb1290e82014-11-18 16:17:48 -05001724
1725 description = "Killing a switch to ensure it is discovered correctly"
Jon Hall6aec96b2015-01-19 14:49:31 -08001726 main.log.report( description )
1727 main.case( description )
1728 switch = main.params[ 'kill' ][ 'switch' ]
1729 switchDPID = main.params[ 'kill' ][ 'dpid' ]
Jon Hallb1290e82014-11-18 16:17:48 -05001730
Jon Hall6aec96b2015-01-19 14:49:31 -08001731 # TODO: Make this switch parameterizable
1732 main.step( "Kill " + switch )
1733 main.log.report( "Deleting " + switch )
Jon Hall8f89dda2015-01-22 16:03:33 -08001734 main.Mininet1.delSwitch( switch )
1735 main.log.info( "Waiting " + str( switchSleep ) +
Jon Hall6aec96b2015-01-19 14:49:31 -08001736 " seconds for switch down to be discovered" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001737 time.sleep( switchSleep )
1738 device = main.ONOScli1.getDevice( dpid=switchDPID )
Jon Hall6aec96b2015-01-19 14:49:31 -08001739 # Peek at the deleted switch
1740 main.log.warn( str( device ) )
Jon Hall94fd0472014-12-08 11:52:42 -08001741 result = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001742 if device and device[ 'available' ] is False:
Jon Hall94fd0472014-12-08 11:52:42 -08001743 result = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001744 utilities.assert_equals( expect=main.TRUE, actual=result,
Jon Hall8f89dda2015-01-22 16:03:33 -08001745 onpass="Kill switch succesful",
1746 onfail="Failed to kill switch?" )
Jon Hallb1290e82014-11-18 16:17:48 -05001747
Jon Hall6aec96b2015-01-19 14:49:31 -08001748 def CASE12( self, main ):
1749 """
Jon Hallb1290e82014-11-18 16:17:48 -05001750 Switch Up
Jon Hall6aec96b2015-01-19 14:49:31 -08001751 """
1752 # NOTE: You should probably run a topology check after this
Jon Hallb1290e82014-11-18 16:17:48 -05001753 import time
Jon Hall669173b2014-12-17 11:36:30 -08001754
Jon Hall8f89dda2015-01-22 16:03:33 -08001755 switchSleep = float( main.params[ 'timers' ][ 'SwitchDiscovery' ] )
Jon Hall6aec96b2015-01-19 14:49:31 -08001756 switch = main.params[ 'kill' ][ 'switch' ]
1757 switchDPID = main.params[ 'kill' ][ 'dpid' ]
1758 links = main.params[ 'kill' ][ 'links' ].split()
Jon Hallb1290e82014-11-18 16:17:48 -05001759 description = "Adding a switch to ensure it is discovered correctly"
Jon Hall6aec96b2015-01-19 14:49:31 -08001760 main.log.report( description )
1761 main.case( description )
Jon Hallb1290e82014-11-18 16:17:48 -05001762
Jon Hall6aec96b2015-01-19 14:49:31 -08001763 main.step( "Add back " + switch )
1764 main.log.report( "Adding back " + switch )
Jon Hall8f89dda2015-01-22 16:03:33 -08001765 main.Mininet1.addSwitch( switch, dpid=switchDPID )
Jon Hall6aec96b2015-01-19 14:49:31 -08001766 # TODO: New dpid or same? Ask Thomas?
1767 for peer in links:
Jon Hall8f89dda2015-01-22 16:03:33 -08001768 main.Mininet1.addLink( switch, peer )
1769 main.Mininet1.assignSwController(
Jon Hall6aec96b2015-01-19 14:49:31 -08001770 sw=switch.split( 's' )[ 1 ],
Jon Hall8f89dda2015-01-22 16:03:33 -08001771 count=numControllers,
1772 ip1=ONOS1Ip,
1773 port1=ONOS1Port,
1774 ip2=ONOS2Ip,
1775 port2=ONOS2Port,
1776 ip3=ONOS3Ip,
1777 port3=ONOS3Port,
1778 ip4=ONOS4Ip,
1779 port4=ONOS4Port,
1780 ip5=ONOS5Ip,
1781 port5=ONOS5Port,
1782 ip6=ONOS6Ip,
1783 port6=ONOS6Port,
1784 ip7=ONOS7Ip,
1785 port7=ONOS7Port )
Jon Hall6aec96b2015-01-19 14:49:31 -08001786 main.log.info(
1787 "Waiting " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001788 str( switchSleep ) +
Jon Hall6aec96b2015-01-19 14:49:31 -08001789 " seconds for switch up to be discovered" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001790 time.sleep( switchSleep )
1791 device = main.ONOScli1.getDevice( dpid=switchDPID )
Jon Hall6aec96b2015-01-19 14:49:31 -08001792 # Peek at the deleted switch
1793 main.log.warn( str( device ) )
Jon Hall94fd0472014-12-08 11:52:42 -08001794 result = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001795 if device and device[ 'available' ]:
Jon Hall94fd0472014-12-08 11:52:42 -08001796 result = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001797 utilities.assert_equals( expect=main.TRUE, actual=result,
Jon Hall8f89dda2015-01-22 16:03:33 -08001798 onpass="add switch succesful",
1799 onfail="Failed to add switch?" )
Jon Hallb1290e82014-11-18 16:17:48 -05001800
Jon Hall6aec96b2015-01-19 14:49:31 -08001801 def CASE13( self, main ):
1802 """
Jon Hallb1290e82014-11-18 16:17:48 -05001803 Clean up
Jon Hall6aec96b2015-01-19 14:49:31 -08001804 """
Jon Hall73cf9cc2014-11-20 22:28:38 -08001805 import os
1806 import time
Jon Hall6aec96b2015-01-19 14:49:31 -08001807 # TODO: make use of this elsewhere
1808 ips = []
Jon Hall8f89dda2015-01-22 16:03:33 -08001809 ips.append( ONOS1Ip )
1810 ips.append( ONOS2Ip )
1811 ips.append( ONOS3Ip )
1812 ips.append( ONOS4Ip )
1813 ips.append( ONOS5Ip )
1814 ips.append( ONOS6Ip )
1815 ips.append( ONOS7Ip )
Jon Hall6aec96b2015-01-19 14:49:31 -08001816
1817 # printing colors to terminal
Jon Hall669173b2014-12-17 11:36:30 -08001818 colors = {}
Jon Hall6aec96b2015-01-19 14:49:31 -08001819 colors[ 'cyan' ] = '\033[96m'
1820 colors[ 'purple' ] = '\033[95m'
1821 colors[ 'blue' ] = '\033[94m'
1822 colors[ 'green' ] = '\033[92m'
1823 colors[ 'yellow' ] = '\033[93m'
1824 colors[ 'red' ] = '\033[91m'
1825 colors[ 'end' ] = '\033[0m'
Jon Hall368769f2014-11-19 15:43:35 -08001826 description = "Test Cleanup"
Jon Hall6aec96b2015-01-19 14:49:31 -08001827 main.log.report( description )
1828 main.case( description )
1829 main.step( "Killing tcpdumps" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001830 main.Mininet2.stopTcpdump()
Jon Hallb1290e82014-11-18 16:17:48 -05001831
Jon Hall6aec96b2015-01-19 14:49:31 -08001832 main.step( "Checking ONOS Logs for errors" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001833 for i in range( 7 ):
Jon Hall6aec96b2015-01-19 14:49:31 -08001834 print colors[ 'purple' ] + "Checking logs for errors on " + \
Jon Hall8f89dda2015-01-22 16:03:33 -08001835 "ONOS" + str( i + 1 ) + ":" + colors[ 'end' ]
1836 print main.ONOSbench.checkLogs( ips[ i ] )
Jon Hall94fd0472014-12-08 11:52:42 -08001837
Jon Hall6aec96b2015-01-19 14:49:31 -08001838 main.step( "Copying MN pcap and ONOS log files to test station" )
Jon Hallb1290e82014-11-18 16:17:48 -05001839 testname = main.TEST
Jon Hall8f89dda2015-01-22 16:03:33 -08001840 teststationUser = main.params[ 'TESTONUSER' ]
1841 teststationIP = main.params[ 'TESTONIP' ]
Jon Hall6aec96b2015-01-19 14:49:31 -08001842 # NOTE: MN Pcap file is being saved to ~/packet_captures
Jon Hall73cf9cc2014-11-20 22:28:38 -08001843 # scp this file as MN and TestON aren't necessarily the same vm
Jon Hall6aec96b2015-01-19 14:49:31 -08001844 # FIXME: scp
1845 # mn files
1846 # TODO: Load these from params
1847 # NOTE: must end in /
Jon Hall8f89dda2015-01-22 16:03:33 -08001848 logFolder = "/opt/onos/log/"
1849 logFiles = [ "karaf.log", "karaf.log.1" ]
Jon Hall6aec96b2015-01-19 14:49:31 -08001850 # NOTE: must end in /
Jon Hall8f89dda2015-01-22 16:03:33 -08001851 dstDir = "~/packet_captures/"
1852 for f in logFiles:
1853 for i in range( 7 ):
1854 main.ONOSbench.handle.sendline( "scp sdn@" + ips[ i ] + ":" +
1855 logFolder + f + " " +
1856 teststationUser + "@" +
1857 teststationIP + ":" +
1858 dstDir + str( testname ) +
Jon Hall6aec96b2015-01-19 14:49:31 -08001859 "-ONOS" + str( i + 1 ) + "-" +
1860 f )
1861 # std*.log's
1862 # NOTE: must end in /
Jon Hall8f89dda2015-01-22 16:03:33 -08001863 logFolder = "/opt/onos/var/"
1864 logFiles = [ "stderr.log", "stdout.log" ]
Jon Hall6aec96b2015-01-19 14:49:31 -08001865 # NOTE: must end in /
Jon Hall8f89dda2015-01-22 16:03:33 -08001866 dstDir = "~/packet_captures/"
1867 for f in logFiles:
1868 for i in range( 7 ):
1869 main.ONOSbench.handle.sendline( "scp sdn@" + ips[ i ] + ":" +
1870 logFolder + f + " " +
1871 teststationUser + "@" +
1872 teststationIP + ":" +
1873 dstDir + str( testname ) +
Jon Hall6aec96b2015-01-19 14:49:31 -08001874 "-ONOS" + str( i + 1 ) + "-" +
1875 f )
1876 # sleep so scp can finish
1877 time.sleep( 10 )
1878 main.step( "Packing and rotating pcap archives" )
1879 os.system( "~/TestON/dependencies/rotate.sh " + str( testname ) )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001880
Jon Hall6aec96b2015-01-19 14:49:31 -08001881 # TODO: actually check something here
1882 utilities.assert_equals( expect=main.TRUE, actual=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001883 onpass="Test cleanup successful",
1884 onfail="Test cleanup NOT successful" )
Jon Hall73cf9cc2014-11-20 22:28:38 -08001885
Jon Hall6aec96b2015-01-19 14:49:31 -08001886 def CASE14( self, main ):
1887 """
Jon Hall94fd0472014-12-08 11:52:42 -08001888 start election app on all onos nodes
Jon Hall6aec96b2015-01-19 14:49:31 -08001889 """
Jon Hall8f89dda2015-01-22 16:03:33 -08001890 leaderResult = main.TRUE
Jon Hall6aec96b2015-01-19 14:49:31 -08001891 # install app on onos 1
1892 main.log.info( "Install leadership election app" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001893 main.ONOScli1.featureInstall( "onos-app-election" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001894 # wait for election
1895 # check for leader
Jon Hall8f89dda2015-01-22 16:03:33 -08001896 leader = main.ONOScli1.electionTestLeader()
Jon Hall6aec96b2015-01-19 14:49:31 -08001897 # verify leader is ONOS1
Jon Hall8f89dda2015-01-22 16:03:33 -08001898 if leader == ONOS1Ip:
Jon Hall6aec96b2015-01-19 14:49:31 -08001899 # all is well
Jon Hall669173b2014-12-17 11:36:30 -08001900 pass
Jon Hall6aec96b2015-01-19 14:49:31 -08001901 elif leader is None:
1902 # No leader elected
1903 main.log.report( "No leader was elected" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001904 leaderResult = main.FALSE
Jon Hall669173b2014-12-17 11:36:30 -08001905 elif leader == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001906 # error in response
1907 # TODO: add check for "Command not found:" in the driver, this
1908 # means the app isn't loaded
Jon Hall8f89dda2015-01-22 16:03:33 -08001909 main.log.report( "Something is wrong with electionTestLeader" +
Jon Hall6aec96b2015-01-19 14:49:31 -08001910 " function, check the error logs" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001911 leaderResult = main.FALSE
Jon Hall669173b2014-12-17 11:36:30 -08001912 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08001913 # error in response
1914 main.log.report(
Jon Hall8f89dda2015-01-22 16:03:33 -08001915 "Unexpected response from electionTestLeader function:'" +
1916 str( leader ) +
Jon Hall6aec96b2015-01-19 14:49:31 -08001917 "'" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001918 leaderResult = main.FALSE
Jon Hall94fd0472014-12-08 11:52:42 -08001919
Jon Hall6aec96b2015-01-19 14:49:31 -08001920 # install on other nodes and check for leader.
1921 # Should be onos1 and each app should show the same leader
Jon Hall8f89dda2015-01-22 16:03:33 -08001922 for controller in range( 2, numControllers + 1 ):
Jon Hall6aec96b2015-01-19 14:49:31 -08001923 # loop through ONOScli handlers
1924 node = getattr( main, ( 'ONOScli' + str( controller ) ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001925 node.featureInstall( "onos-app-election" )
1926 leaderN = node.electionTestLeader()
Jon Hall6aec96b2015-01-19 14:49:31 -08001927 # verify leader is ONOS1
Jon Hall8f89dda2015-01-22 16:03:33 -08001928 if leaderN == ONOS1Ip:
Jon Hall6aec96b2015-01-19 14:49:31 -08001929 # all is well
Jon Hall669173b2014-12-17 11:36:30 -08001930 pass
1931 elif leaderN == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -08001932 # error in response
1933 # TODO: add check for "Command not found:" in the driver, this
1934 # means the app isn't loaded
1935 main.log.report( "Something is wrong with " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001936 "electionTestLeader function, check the" +
Jon Hall6aec96b2015-01-19 14:49:31 -08001937 " error logs" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001938 leaderResult = main.FALSE
Jon Hall669173b2014-12-17 11:36:30 -08001939 elif leader != leaderN:
Jon Hall8f89dda2015-01-22 16:03:33 -08001940 leaderResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08001941 main.log.report( "ONOS" + str( controller ) + " sees " +
1942 str( leaderN ) +
1943 " as the leader of the election app. Leader" +
1944 " should be " +
1945 str( leader ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08001946 if leaderResult:
Jon Hall6aec96b2015-01-19 14:49:31 -08001947 main.log.report( "Leadership election tests passed( consistent " +
1948 "view of leader across listeners and a leader " +
Jon Hall8f89dda2015-01-22 16:03:33 -08001949 "was elected )" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001950 utilities.assert_equals(
1951 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001952 actual=leaderResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08001953 onpass="Leadership election passed",
1954 onfail="Something went wrong with Leadership election" )
Jon Hall94fd0472014-12-08 11:52:42 -08001955
Jon Hall6aec96b2015-01-19 14:49:31 -08001956 def CASE15( self, main ):
1957 """
Jon Hall669173b2014-12-17 11:36:30 -08001958 Check that Leadership Election is still functional
Jon Hall6aec96b2015-01-19 14:49:31 -08001959 """
Jon Hall8f89dda2015-01-22 16:03:33 -08001960 leaderResult = main.TRUE
Jon Hall669173b2014-12-17 11:36:30 -08001961 description = "Check that Leadership Election is still functional"
Jon Hall6aec96b2015-01-19 14:49:31 -08001962 main.log.report( description )
1963 main.case( description )
1964 main.step( "Find current leader and withdraw" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001965 leader = main.ONOScli1.electionTestLeader()
Jon Hall6aec96b2015-01-19 14:49:31 -08001966 # TODO: do some sanity checking on leader before using it
Jon Hall8f89dda2015-01-22 16:03:33 -08001967 withdrawResult = main.FALSE
1968 if leader == ONOS1Ip:
1969 oldLeader = getattr( main, "ONOScli1" )
1970 elif leader == ONOS2Ip:
1971 oldLeader = getattr( main, "ONOScli2" )
1972 elif leader == ONOS3Ip:
1973 oldLeader = getattr( main, "ONOScli3" )
1974 elif leader == ONOS4Ip:
1975 oldLeader = getattr( main, "ONOScli4" )
1976 elif leader == ONOS5Ip:
1977 oldLeader = getattr( main, "ONOScli5" )
1978 elif leader == ONOS6Ip:
1979 oldLeader = getattr( main, "ONOScli6" )
1980 elif leader == ONOS7Ip:
1981 oldLeader = getattr( main, "ONOScli7" )
Jon Hall6aec96b2015-01-19 14:49:31 -08001982 elif leader is None or leader == main.FALSE:
1983 main.log.report(
1984 "Leader for the election app should be an ONOS node," +
1985 "instead got '" +
Jon Hall8f89dda2015-01-22 16:03:33 -08001986 str( leader ) +
Jon Hall6aec96b2015-01-19 14:49:31 -08001987 "'" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001988 leaderResult = main.FALSE
1989 withdrawResult = oldLeader.electionTestWithdraw()
Jon Hall6aec96b2015-01-19 14:49:31 -08001990 utilities.assert_equals(
1991 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08001992 actual=withdrawResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08001993 onpass="App was withdrawn from election",
1994 onfail="App was not withdrawn from election" )
Jon Hall669173b2014-12-17 11:36:30 -08001995
Jon Hall6aec96b2015-01-19 14:49:31 -08001996 main.step( "Make sure new leader is elected" )
Jon Hall8f89dda2015-01-22 16:03:33 -08001997 leaderList = []
1998 for controller in range( 1, numControllers + 1 ):
Jon Hall6aec96b2015-01-19 14:49:31 -08001999 # loop through ONOScli handlers
2000 node = getattr( main, ( 'ONOScli' + str( controller ) ) )
Jon Hall8f89dda2015-01-22 16:03:33 -08002001 leaderList.append( node.electionTestLeader() )
2002 for leaderN in leaderList:
Jon Hall669173b2014-12-17 11:36:30 -08002003 if leaderN == leader:
Jon Hall6aec96b2015-01-19 14:49:31 -08002004 main.log.report(
2005 "ONOS" +
2006 str( controller ) +
2007 " still sees " +
2008 str( leader ) +
2009 " as leader after they withdrew" )
Jon Hall8f89dda2015-01-22 16:03:33 -08002010 leaderResult = main.FALSE
Jon Hall669173b2014-12-17 11:36:30 -08002011 elif leaderN == main.FALSE:
Jon Hall6aec96b2015-01-19 14:49:31 -08002012 # error in response
2013 # TODO: add check for "Command not found:" in the driver, this
2014 # means the app isn't loaded
2015 main.log.report( "Something is wrong with " +
Jon Hall8f89dda2015-01-22 16:03:33 -08002016 "electionTestLeader function, " +
Jon Hall6aec96b2015-01-19 14:49:31 -08002017 "check the error logs" )
Jon Hall8f89dda2015-01-22 16:03:33 -08002018 leaderResult = main.FALSE
2019 consistentLeader = main.FALSE
2020 if len( set( leaderList ) ) == 1:
Jon Hall6aec96b2015-01-19 14:49:31 -08002021 main.log.info( "Each Election-app sees '" +
Jon Hall8f89dda2015-01-22 16:03:33 -08002022 str( leaderList[ 0 ] ) +
Jon Hall6aec96b2015-01-19 14:49:31 -08002023 "' as the leader" )
Jon Hall8f89dda2015-01-22 16:03:33 -08002024 consistentLeader = main.TRUE
Jon Hall669173b2014-12-17 11:36:30 -08002025 else:
Jon Hall6aec96b2015-01-19 14:49:31 -08002026 main.log.report(
2027 "Inconsistent responses for leader of Election-app:" )
Jon Hall8f89dda2015-01-22 16:03:33 -08002028 for n in range( len( leaderList ) ):
Jon Hall6aec96b2015-01-19 14:49:31 -08002029 main.log.report( "ONOS" + str( n + 1 ) + " response: " +
Jon Hall8f89dda2015-01-22 16:03:33 -08002030 str( leaderList[ n ] ) )
2031 if leaderResult:
2032 main.log.report( "Leadership election tests passed( consistent " +
Jon Hall6aec96b2015-01-19 14:49:31 -08002033 "view of leader across listeners and a new " +
2034 "leader was elected when the old leader " +
Jon Hall8f89dda2015-01-22 16:03:33 -08002035 "resigned )" )
Jon Hall6aec96b2015-01-19 14:49:31 -08002036 utilities.assert_equals(
2037 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08002038 actual=leaderResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08002039 onpass="Leadership election passed",
2040 onfail="Something went wrong with Leadership election" )
Jon Hall669173b2014-12-17 11:36:30 -08002041
Jon Hall6aec96b2015-01-19 14:49:31 -08002042 main.step(
Jon Hall8f89dda2015-01-22 16:03:33 -08002043 "Run for election on old leader( just so everyone is in the hat )" )
2044 runResult = oldLeader.electionTestRun()
Jon Hall6aec96b2015-01-19 14:49:31 -08002045 utilities.assert_equals(
2046 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08002047 actual=runResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08002048 onpass="App re-ran for election",
2049 onfail="App failed to run for election" )
Jon Hall8f89dda2015-01-22 16:03:33 -08002050 if consistentLeader == main.TRUE:
2051 afterRun = main.ONOScli1.electionTestLeader()
Jon Hall6aec96b2015-01-19 14:49:31 -08002052 # verify leader didn't just change
Jon Hall8f89dda2015-01-22 16:03:33 -08002053 if afterRun == leaderList[ 0 ]:
2054 leaderResult = main.TRUE
Jon Hall669173b2014-12-17 11:36:30 -08002055 else:
Jon Hall8f89dda2015-01-22 16:03:33 -08002056 leaderResult = main.FALSE
Jon Hall6aec96b2015-01-19 14:49:31 -08002057 # TODO: assert on run and withdraw results?
Jon Hall669173b2014-12-17 11:36:30 -08002058
Jon Hall6aec96b2015-01-19 14:49:31 -08002059 utilities.assert_equals(
2060 expect=main.TRUE,
Jon Hall8f89dda2015-01-22 16:03:33 -08002061 actual=leaderResult,
Jon Hall6aec96b2015-01-19 14:49:31 -08002062 onpass="Leadership election passed",
2063 onfail="Something went wrong with Leadership election after " +
2064 "the old leader re-ran for election" )