blob: 84f65d3fd0bfddfec0c81bb84f77f445e57cf729 [file] [log] [blame]
YPZhangcb86c5b2016-01-27 17:38:12 -08001import sys
2import json
3import time
4import os
5'''
6SCPFscalingMaxIntents
7Push test Intents to onos
8CASE10: set up Null Provider
9CASE11: set up Open Flows
YPZhang14a4aa92016-07-15 13:37:15 -070010Check flows number, if flows number is not as except, finished this test iteration
YPZhangcb86c5b2016-01-27 17:38:12 -080011Scale up when reach the Limited
12Start from 1 nodes, 8 devices. Then Scale up to 3,5,7 nodes
YPZhangcb86c5b2016-01-27 17:38:12 -080013'''
14class SCPFscalingMaxIntents:
15 def __init__( self ):
16 self.default = ''
17
18 def CASE0( self, main):
19 import sys
20 import json
21 import time
22 import os
23 import imp
24
25 main.case( "Constructing test variables and building ONOS package" )
26 main.step( "Constructing test variables" )
27 stepResult = main.FALSE
28
29 # Test variables
30 main.testOnDirectory = os.path.dirname( os.getcwd ( ) )
31 main.dependencyPath = main.testOnDirectory + \
32 main.params['DEPENDENCY']['path']
33 main.cellName = main.params[ 'ENV' ][ 'cellName' ]
34 main.apps = main.params[ 'ENV' ][ 'cellApps' ]
35 main.topology = main.params[ 'DEPENDENCY' ][ 'topology' ]
36 main.scale = ( main.params[ 'SCALE' ] ).split( "," )
37 main.ONOSport = main.params[ 'CTRL' ][ 'port' ]
38 main.timeout = int(main.params['SLEEP']['timeout'])
39 main.startUpSleep = int( main.params[ 'SLEEP' ][ 'startup' ] )
40 main.installSleep = int( main.params[ 'SLEEP' ][ 'install' ] )
41 main.verifySleep = int( main.params[ 'SLEEP' ][ 'verify' ] )
42 main.rerouteSleep = int ( main.params['SLEEP']['reroute'] )
43 main.verifyAttempts = int( main.params['ATTEMPTS']['verify'] )
44 main.ingress = main.params['LINK']['ingress']
45 main.egress = main.params['LINK']['egress']
YPZhangcb86c5b2016-01-27 17:38:12 -080046 main.cellData = {} # for creating cell file
47 main.reroute = main.params['reroute']
YPZhange6ef82a2016-07-05 16:48:15 -070048 main.flowObj = main.params['TEST']['flowObj']
49 if main.flowObj == "True":
50 main.flowObj = True
51 main.dbFileName = main.params['DATABASE']['dbFlowObj']
52 else:
53 main.flowObj = False
54 main.dbFileName = main.params['DATABASE']['dbName']
YPZhangcb86c5b2016-01-27 17:38:12 -080055 main.threadID = 0
56
57 if main.reroute == "True":
58 main.reroute = True
59 else:
60 main.reroute = False
61
62 main.CLIs = []
YPZhangcb86c5b2016-01-27 17:38:12 -080063 main.setupSkipped = False
64
65 wrapperFile1 = main.params[ 'DEPENDENCY' ][ 'wrapper1' ]
66 gitBranch = main.params[ 'GIT' ][ 'branch' ]
67 gitPull = main.params[ 'GIT' ][ 'pull' ]
68 nic = main.params['DATABASE']['nic']
69 node = main.params['DATABASE']['node']
70 nic = main.params['DATABASE']['nic']
71 node = main.params['DATABASE']['node']
72 stepResult = main.TRUE
73
74 main.log.info("Cresting DB file")
75 with open(main.dbFileName, "w+") as dbFile:
76 dbFile.write("")
77
78 utilities.assert_equals( expect=main.TRUE,
79 actual=stepResult,
80 onpass="environment set up successfull",
81 onfail="environment set up Failed" )
82
83 def CASE1( self ):
84 # main.scale[ 0 ] determines the current number of ONOS controller
85 main.CLIs = []
86 main.numCtrls = int( main.scale[ 0 ] )
YPZhangebf9eb52016-05-12 15:20:24 -070087 main.ONOSip = []
88 main.maxNumBatch = 0
89 main.AllONOSip = main.ONOSbench.getOnosIps()
90 for i in range(main.numCtrls):
91 main.ONOSip.append(main.AllONOSip[i])
92 main.log.info(main.ONOSip)
93
YPZhangcb86c5b2016-01-27 17:38:12 -080094 main.log.info( "Creating list of ONOS cli handles" )
95 for i in range(main.numCtrls):
96 main.CLIs.append( getattr( main, 'ONOScli%s' % (i+1) ) )
97
98 main.log.info(main.CLIs)
99 if not main.CLIs:
100 main.log.error( "Failed to create the list of ONOS cli handles" )
101 main.cleanup()
102 main.exit()
103
104 main.log.info( "Loading wrapper files" )
105 main.startUp = imp.load_source( wrapperFile1,
106 main.dependencyPath +
107 wrapperFile1 +
108 ".py" )
109
110 copyResult = main.ONOSbench.copyMininetFile( main.topology,
111 main.dependencyPath,
112 main.Mininet1.user_name,
113 main.Mininet1.ip_address )
114
115 commit = main.ONOSbench.getVersion(report=True)
116 commit = commit.split(" ")[1]
117
118 if gitPull == 'True':
119 if not main.startUp.onosBuild( main, gitBranch ):
120 main.log.error( "Failed to build ONOS" )
121 main.cleanup()
122 main.exit()
123 else:
124 main.log.warn( "Did not pull new code so skipping mvn " +
125 "clean install" )
126 with open(main.dbFileName, "a") as dbFile:
127 temp = "'" + commit + "',"
128 temp += "'" + nic + "',"
129 dbFile.write(temp)
130
131 def CASE2( self, main ):
132 """
133 - Uninstall ONOS cluster
134 - Verify ONOS start up
135 - Install ONOS cluster
136 - Connect to cli
137 """
138 main.log.info( "Starting up %s node(s) ONOS cluster" % main.numCtrls)
139 main.log.info( "Safety check, killing all ONOS processes" +
140 " before initiating environment setup" )
141
142 for i in range( main.numCtrls ):
143 main.ONOSbench.onosDie( main.ONOSip[ i ] )
144
145 main.log.info( "NODE COUNT = %s" % main.numCtrls)
146
147 tempOnosIp = []
148 for i in range( main.numCtrls ):
149 tempOnosIp.append( main.ONOSip[i] )
150
151 main.ONOSbench.createCellFile( main.ONOSbench.ip_address,
152 "temp",
153 main.Mininet1.ip_address,
154 main.apps,
155 tempOnosIp )
156
157 main.step( "Apply cell to environment" )
158 cellResult = main.ONOSbench.setCell( "temp" )
159 verifyResult = main.ONOSbench.verifyCell()
160 stepResult = cellResult and verifyResult
161 utilities.assert_equals( expect=main.TRUE,
162 actual=stepResult,
163 onpass="Successfully applied cell to " + \
164 "environment",
165 onfail="Failed to apply cell to environment " )
166
167 main.step( "Creating ONOS package" )
168 packageResult = main.ONOSbench.onosPackage()
169 stepResult = packageResult
170 utilities.assert_equals( expect=main.TRUE,
171 actual=stepResult,
172 onpass="Successfully created ONOS package",
173 onfail="Failed to create ONOS package" )
174
175 main.step( "Uninstall ONOS package on all Nodes" )
176 uninstallResult = main.TRUE
177 for i in range( int( main.numCtrls ) ):
178 main.log.info( "Uninstalling package on ONOS Node IP: " + main.ONOSip[i] )
179 u_result = main.ONOSbench.onosUninstall( main.ONOSip[i] )
180 utilities.assert_equals( expect=main.TRUE, actual=u_result,
181 onpass="Test step PASS",
182 onfail="Test step FAIL" )
183 uninstallResult = ( uninstallResult and u_result )
184
185 main.step( "Install ONOS package on all Nodes" )
186 installResult = main.TRUE
187 for i in range( int( main.numCtrls ) ):
188 main.log.info( "Installing package on ONOS Node IP: " + main.ONOSip[i] )
189 i_result = main.ONOSbench.onosInstall( node=main.ONOSip[i] )
190 utilities.assert_equals( expect=main.TRUE, actual=i_result,
191 onpass="Test step PASS",
192 onfail="Test step FAIL" )
193 installResult = installResult and i_result
194
195 main.step( "Verify ONOS nodes UP status" )
196 statusResult = main.TRUE
197 for i in range( int( main.numCtrls ) ):
198 main.log.info( "ONOS Node " + main.ONOSip[i] + " status:" )
199 onos_status = main.ONOSbench.onosStatus( node=main.ONOSip[i] )
200 utilities.assert_equals( expect=main.TRUE, actual=onos_status,
201 onpass="Test step PASS",
202 onfail="Test step FAIL" )
203 statusResult = ( statusResult and onos_status )
204
205 main.step( "Start ONOS CLI on all nodes" )
206 cliResult = main.TRUE
Jon Hall6509dbf2016-06-21 17:01:17 -0700207 main.step(" Start ONOS cli using thread ")
YPZhangcb86c5b2016-01-27 17:38:12 -0800208 startCliResult = main.TRUE
209 pool = []
210
211 for i in range( int( main.numCtrls) ):
212 t = main.Thread( target=main.CLIs[i].startOnosCli,
213 threadID=main.threadID,
214 name="startOnosCli",
215 args=[ main.ONOSip[i] ],
216 kwargs = {"onosStartTimeout":main.timeout} )
217 pool.append(t)
218 t.start()
219 main.threadID = main.threadID + 1
220 for t in pool:
221 t.join()
222 startCliResult = startCliResult and t.result
223 time.sleep( main.startUpSleep )
224
225 def CASE10( self, main ):
226 """
227 Setting up null-provider
228 """
229 import json
230 # Activate apps
231 main.step("Activating null-provider")
232 appStatus = utilities.retry( main.CLIs[0].activateApp,
233 main.FALSE,
234 ['org.onosproject.null'],
235 sleep=main.verifySleep,
236 attempts=main.verifyAttempts )
237 utilities.assert_equals( expect=main.TRUE,
238 actual=appStatus,
239 onpass="Successfully activated null-provider",
240 onfail="Failed activate null-provider" )
241
242 # Setup the null-provider
243 main.step("Configuring null-provider")
244 cfgStatus = utilities.retry( main.ONOSbench.onosCfgSet,
245 main.FALSE,
246 [ main.ONOSip[0],
247 'org.onosproject.provider.nil.NullProviders', 'deviceCount 8'],
248 sleep=main.verifySleep,
249 attempts = main.verifyAttempts )
250 cfgStatus = cfgStatus and utilities.retry( main.ONOSbench.onosCfgSet,
251 main.FALSE,
252 [ main.ONOSip[0],
253 'org.onosproject.provider.nil.NullProviders', 'topoShape reroute'],
254 sleep=main.verifySleep,
255 attempts = main.verifyAttempts )
256
257 cfgStatus = cfgStatus and utilities.retry( main.ONOSbench.onosCfgSet,
258 main.FALSE,
259 [ main.ONOSip[0],
260 'org.onosproject.provider.nil.NullProviders', 'enabled true'],
261 sleep=main.verifySleep,
262 attempts = main.verifyAttempts )
263
264
265 utilities.assert_equals( expect=main.TRUE,
266 actual=cfgStatus,
267 onpass="Successfully configured null-provider",
268 onfail="Failed to configure null-provider" )
269
270 # give onos some time to settle
271 time.sleep(main.startUpSleep)
272
273 main.log.info("Setting default flows to zero")
274 main.defaultFlows = 0
275
276 main.step("Check status of null-provider setup")
277 caseResult = appStatus and cfgStatus
278 utilities.assert_equals( expect=main.TRUE,
279 actual=caseResult,
280 onpass="Setting up null-provider was successfull",
281 onfail="Failed to setup null-provider" )
282
283 # This tells the following cases if we are using the null-provider or ovs
284 main.switchType = "null:"
285
286 # If the null-provider setup was unsuccessfull, then there is no point to
287 # run the subsequent cases
288
289 time.sleep(main.startUpSleep)
290 main.step( "Balancing Masters" )
291
292 stepResult = main.FALSE
293 stepResult = utilities.retry( main.CLIs[0].balanceMasters,
294 main.FALSE,
295 [],
296 sleep=3,
297 attempts=3 )
298
299 utilities.assert_equals( expect=main.TRUE,
300 actual=stepResult,
301 onpass="Balance masters was successfull",
302 onfail="Failed to balance masters")
303
304 time.sleep( 5 )
305 if not caseResult:
306 main.setupSkipped = True
307
308 def CASE11( self, main):
309 '''
310 Setting up mininet
311 '''
312 import json
313 import time
YPZhangebf9eb52016-05-12 15:20:24 -0700314
315 devices = []
316 devices = main.CLIs[0].getAllDevicesId()
317 for d in devices:
318 main.CLIs[0].deviceRemove( d )
YPZhangcb86c5b2016-01-27 17:38:12 -0800319
320 time.sleep(main.startUpSleep)
YPZhange6ef82a2016-07-05 16:48:15 -0700321 if main.flowObj:
322 main.CLIs[0].setCfg("org.onosproject.net.intent.impl.compiler.IntentConfigurableRegistrator",
323 "useFlowObjectives", value="true")
YPZhangcb86c5b2016-01-27 17:38:12 -0800324 main.step('Starting mininet topology')
325 mnStatus = main.Mininet1.startNet(topoFile='~/mininet/custom/rerouteTopo.py')
326 utilities.assert_equals( expect=main.TRUE,
327 actual=mnStatus,
328 onpass="Successfully started Mininet",
329 onfail="Failed to activate Mininet" )
330
331 main.step("Assinging masters to switches")
332 switches = main.Mininet1.getSwitches()
333 swStatus = main.Mininet1.assignSwController( sw=switches.keys(), ip=main.ONOSip )
334 utilities.assert_equals( expect=main.TRUE,
335 actual=swStatus,
336 onpass="Successfully assigned switches to masters",
337 onfail="Failed assign switches to masters" )
338
339 time.sleep(main.startUpSleep)
YPZhangebf9eb52016-05-12 15:20:24 -0700340 # Balancing Masters
341 main.step( "Balancing Masters" )
342 stepResult = main.FALSE
343 stepResult = utilities.retry( main.CLIs[0].balanceMasters,
344 main.FALSE,
345 [],
346 sleep=3,
347 attempts=3 )
348
349 utilities.assert_equals( expect=main.TRUE,
350 actual=stepResult,
351 onpass="Balance masters was successfull",
352 onfail="Failed to balance masters" )
YPZhangcb86c5b2016-01-27 17:38:12 -0800353
354 main.log.info("Getting default flows")
355 jsonSum = json.loads(main.CLIs[0].summary())
356 main.defaultFlows = jsonSum["flows"]
357
358 main.step("Check status of Mininet setup")
YPZhangebf9eb52016-05-12 15:20:24 -0700359 caseResult = mnStatus and swStatus
YPZhangcb86c5b2016-01-27 17:38:12 -0800360 utilities.assert_equals( expect=main.TRUE,
361 actual=caseResult,
362 onpass="Successfully setup Mininet",
363 onfail="Failed setup Mininet" )
364
365 # This tells the following cases if we are using the null-provider or ovs
366 main.switchType = "of:"
367
368 time.sleep(main.startUpSleep)
369 main.step( "Balancing Masters" )
370
371 stepResult = main.FALSE
372 stepResult = utilities.retry( main.CLIs[0].balanceMasters,
373 main.FALSE,
374 [],
375 sleep=3,
376 attempts=3 )
377
378 utilities.assert_equals( expect=main.TRUE,
379 actual=stepResult,
380 onpass="Balance masters was successfull",
381 onfail="Failed to balance masters")
382
383 time.sleep(5)
384 if not caseResult:
385 main.setupSkipped = True
386
387
388
389 def CASE20( self, main ):
390 if main.reroute:
391 main.minIntents = int(main.params['NULL']['REROUTE']['min_intents'])
392 main.maxIntents = int(main.params['NULL']['REROUTE']['max_intents'])
393 main.checkInterval = int(main.params['NULL']['REROUTE']['check_interval'])
394 main.batchSize = int(main.params['NULL']['REROUTE']['batch_size'])
395 else:
396 main.minIntents = int(main.params['NULL']['PUSH']['min_intents'])
397 main.maxIntents = int(main.params['NULL']['PUSH']['max_intents'])
398 main.checkInterval = int(main.params['NULL']['PUSH']['check_interval'])
399 main.batchSize = int(main.params['NULL']['PUSH']['batch_size'])
400
401 # check if the case needs to be skipped
402 if main.setupSkipped:
403 main.setupSkipped = False
404 main.skipCase()
405
406 # the index where the next intents will be installed
407 offfset = 0
408 # keeps track of how many intents have been installed
409 currIntents = 0
YPZhang3097ba92016-02-16 17:32:32 -0800410 # keeps track of how many flows have been installed, set to 0 at start
411 currFlows = 0
YPZhangcb86c5b2016-01-27 17:38:12 -0800412 # limit for the number of intents that can be installed
YPZhangebf9eb52016-05-12 15:20:24 -0700413 main.batchSize = int( int(main.batchSize)/int(main.numCtrls))
YPZhangcb86c5b2016-01-27 17:38:12 -0800414 limit = main.maxIntents / main.batchSize
415 # total intents installed
416 totalIntents = 0
417
418 intentsState = None
419
420 offtmp = 0
421 main.step( "Pushing intents" )
422 stepResult = main.TRUE
YPZhang47779c22016-03-07 13:03:07 -0800423 # temp variable to contain the number of flows
424 flowsNum = 0
YPZhangebf9eb52016-05-12 15:20:24 -0700425 if main.numCtrls > 1:
426 # if more than one onos nodes, we should check more frequently
427 main.checkInterval = main.checkInterval/4
YPZhangcb86c5b2016-01-27 17:38:12 -0800428
YPZhangebf9eb52016-05-12 15:20:24 -0700429 # make sure the checkInterval divisible batchSize
430 main.checkInterval = int( int( main.checkInterval / main.batchSize ) * main.batchSize )
YPZhangac53ebf2016-05-13 16:26:19 -0700431 flowTemp=0
YPZhang14a4aa92016-07-15 13:37:15 -0700432 intentVerifyTemp = 0
YPZhangac53ebf2016-05-13 16:26:19 -0700433 totalFlows=0
YPZhangcb86c5b2016-01-27 17:38:12 -0800434 for i in range(limit):
435
436 # Threads pool
437 pool = []
438
439 for j in range( int( main.numCtrls) ):
440 if main.numCtrls > 1:
441 time.sleep( 1 )
442 offtmp = offfset + main.maxIntents * j
443 # Push intents by using threads
444 t = main.Thread( target=main.CLIs[j].pushTestIntents,
445 threadID=main.threadID,
446 name="Push-Test-Intents",
447 args=[ main.switchType + main.ingress,
448 main.switchType + main.egress,
449 main.batchSize ],
450 kwargs={ "offset": offtmp,
451 "options": "-i",
452 "timeout": main.timeout,
YPZhangebf9eb52016-05-12 15:20:24 -0700453 "background":False,
454 "noExit":True} )
YPZhangcb86c5b2016-01-27 17:38:12 -0800455 pool.append(t)
456 t.start()
457 main.threadID = main.threadID + 1
458 for t in pool:
459 t.join()
460 stepResult = stepResult and t.result
461 offfset = offfset + main.batchSize
462
YPZhang3097ba92016-02-16 17:32:32 -0800463 totalIntents = main.batchSize * main.numCtrls + totalIntents
YPZhangcb86c5b2016-01-27 17:38:12 -0800464 if totalIntents >= main.minIntents and totalIntents % main.checkInterval == 0:
465 # if reach to minimum number and check interval, verify Intetns and flows
466 time.sleep( main.verifySleep * main.numCtrls )
467
468 main.log.info("Verify Intents states")
YPZhang3097ba92016-02-16 17:32:32 -0800469 # k is a control variable for verify retry attempts
YPZhangcb86c5b2016-01-27 17:38:12 -0800470 k = 1
YPZhang3097ba92016-02-16 17:32:32 -0800471 while k <= main.verifyAttempts:
YPZhang14a4aa92016-07-15 13:37:15 -0700472 # while loop for check intents by using CLI driver
YPZhangcb86c5b2016-01-27 17:38:12 -0800473 time.sleep(5)
YPZhang14a4aa92016-07-15 13:37:15 -0700474 intentsState = main.CLIs[0].checkIntentSummary(timeout=600, noExit=True)
YPZhangebf9eb52016-05-12 15:20:24 -0700475 if intentsState:
YPZhang14a4aa92016-07-15 13:37:15 -0700476 verifyTotalIntents = main.CLIs[0].getTotalIntentsNum(timeout=600, noExit=True)
477 if intentVerifyTemp < verifyTotalIntents:
478 intentVerifyTemp = verifyTotalIntents
YPZhangebf9eb52016-05-12 15:20:24 -0700479 else:
YPZhang14a4aa92016-07-15 13:37:15 -0700480 verifyTotalIntents = intentVerifyTemp
481 main.log.info("Total Installed Intents: {}".format( verifyTotalIntents ) )
YPZhangcb86c5b2016-01-27 17:38:12 -0800482 break
YPZhangcb86c5b2016-01-27 17:38:12 -0800483 k = k+1
YPZhangac53ebf2016-05-13 16:26:19 -0700484
YPZhang14a4aa92016-07-15 13:37:15 -0700485 k = 1
486 flowVerify = True
487 while k <= main.verifyAttempts:
488 time.sleep(5)
489 totalFlows = main.CLIs[0].getTotalFlowsNum( timeout=600, noExit=True )
490 expectFlows = totalIntents * 7 + main.defaultFlows
491 if totalFlows == expectFlows:
492 main.log.info("Total Flows Added: {}".format(totalFlows))
493 break
494 else:
495 main.log.info("Some Flows are not added, retry...")
496 main.log.info("Total Flows Added: {} Expect Flows: {}".format(totalFlows, expectFlows))
497 flowVerify = False
YPZhangac53ebf2016-05-13 16:26:19 -0700498
YPZhang14a4aa92016-07-15 13:37:15 -0700499 k += 1
500 if flowTemp < totalFlows:
501 flowTemp = totalFlows
502 else:
503 totalFlows = flowTemp
504
505 if not intentsState or not flowVerify:
YPZhanga4acbb82016-03-02 17:28:25 -0800506 # If some intents are not installed, grep the previous flows list, and finished this test case
YPZhang14a4aa92016-07-15 13:37:15 -0700507 main.log.warn( "Intents or flows are not installed" )
508 verifyTotalIntents = main.CLIs[0].getTotalIntentsNum(timeout=600, noExit=True)
509 if intentVerifyTemp < verifyTotalIntents:
510 intentVerifyTemp = verifyTotalIntents
511 else:
512 verifyTotalIntents = intentVerifyTemp
513 if flowTemp < totalFlows:
514 flowTemp = totalFlows
515 else:
516 totalFlows = flowTemp
YPZhangac53ebf2016-05-13 16:26:19 -0700517 main.log.info("Total Intents: {}".format( verifyTotalIntents) )
YPZhangcb86c5b2016-01-27 17:38:12 -0800518 break
YPZhange96a3062016-05-12 16:18:35 -0700519
YPZhangcb86c5b2016-01-27 17:38:12 -0800520 del main.scale[0]
521 utilities.assert_equals( expect = main.TRUE,
YPZhangebf9eb52016-05-12 15:20:24 -0700522 actual = intentsState,
YPZhangcb86c5b2016-01-27 17:38:12 -0800523 onpass = "Successfully pushed and verified intents",
524 onfail = "Failed to push and verify intents" )
525
YPZhangcb86c5b2016-01-27 17:38:12 -0800526 main.log.info( "Total Intents Installed before crash: {}".format( totalIntents ) )
527 main.log.info( "Total Flows ADDED before crash: {}".format( totalFlows ) )
528
529 main.step('clean up Mininet')
530 main.Mininet1.stopNet()
YPZhangcb86c5b2016-01-27 17:38:12 -0800531 main.log.info("Writing results to DS file")
532 with open(main.dbFileName, "a") as dbFile:
533 # Scale number
534 temp = str(main.numCtrls)
535 temp += ",'" + "baremetal1" + "'"
536 # how many intents we installed before crash
YPZhangac53ebf2016-05-13 16:26:19 -0700537 temp += "," + str(verifyTotalIntents)
YPZhangcb86c5b2016-01-27 17:38:12 -0800538 # how many flows we installed before crash
539 temp += "," + str(totalFlows)
540 # other columns in database, but we didn't use in this test
541 temp += "," + "0,0,0,0,0,0"
542 temp += "\n"
543 dbFile.write( temp )