blob: 1106f833408c7b9f9d04a0c730a59006f3d98a04 [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
Devin Lim58046fa2017-07-05 16:55:00 -070024 try:
25 from tests.dependencies.ONOSSetup import ONOSSetup
26 main.testSetUp = ONOSSetup()
27 except ImportError:
28 main.log.error( "ONOSSetup not found. exiting the test" )
YPZhangcb86c5b2016-01-27 17:38:12 -080029 main.exit()
Devin Lim58046fa2017-07-05 16:55:00 -070030 main.testSetUp.envSetupDescription()
31 stepResult = main.FALSE
32 try:
33 # Test variables
34 main.dependencyPath = main.testOnDirectory + \
35 main.params[ 'DEPENDENCY' ][ 'path' ]
36 main.cellName = main.params[ 'ENV' ][ 'cellName' ]
37 main.apps = main.params[ 'ENV' ][ 'cellApps' ]
38 main.topology = main.params[ 'DEPENDENCY' ][ 'topology' ]
39 main.scale = ( main.params[ 'SCALE' ] ).split( "," )
40 main.ONOSport = main.params[ 'CTRL' ][ 'port' ]
41 main.timeout = int( main.params[ 'SLEEP' ][ 'timeout' ] )
42 main.startUpSleep = int( main.params[ 'SLEEP' ][ 'startup' ] )
43 main.installSleep = int( main.params[ 'SLEEP' ][ 'install' ] )
44 main.verifySleep = int( main.params[ 'SLEEP' ][ 'verify' ] )
45 main.rerouteSleep = int ( main.params[ 'SLEEP' ][ 'reroute' ] )
46 main.verifyAttempts = int( main.params[ 'ATTEMPTS' ][ 'verify' ] )
47 main.ingress = main.params[ 'LINK' ][ 'ingress' ]
48 main.egress = main.params[ 'LINK' ][ 'egress' ]
49 main.reroute = main.params[ 'reroute' ]
50 main.flowObj = main.params[ 'TEST' ][ 'flowObj' ]
51 if main.flowObj == "True":
52 main.flowObj = True
53 main.dbFileName = main.params[ 'DATABASE' ][ 'dbFlowObj' ]
54 else:
55 main.flowObj = False
56 main.dbFileName = main.params[ 'DATABASE' ][ 'dbName' ]
57 main.threadID = 0
YPZhangcb86c5b2016-01-27 17:38:12 -080058
Devin Lim58046fa2017-07-05 16:55:00 -070059 if main.reroute == "True":
60 main.reroute = True
61 else:
62 main.reroute = False
63 main.setupSkipped = False
YPZhangcb86c5b2016-01-27 17:38:12 -080064
Devin Lim58046fa2017-07-05 16:55:00 -070065 wrapperFile1 = main.params[ 'DEPENDENCY' ][ 'wrapper1' ]
66 nic = main.params[ 'DATABASE' ][ 'nic' ]
67 node = main.params[ 'DATABASE' ][ 'node' ]
68 stepResult = main.testSetUp.gitPulling()
69 main.log.info( "Cresting DB file" )
70 with open( main.dbFileName, "w+" ) as dbFile:
71 dbFile.write("")
72 except Exception as e:
73 main.testSetUp.envSetupException( e )
74 main.testSetUp.evnSetupConclusion( stepResult )
75 main.commit = main.commit.split( " " )[ 1 ]
76 with open( main.dbFileName, "a" ) as dbFile:
77 temp = "'" + main.commit + "',"
78 temp += "'" + nic + "',"
79 dbFile.write( temp )
80 def CASE1( self ):
81 main.testSetUp.getNumCtrls( True )
82 main.testSetUp.envSetup( includeGitPull=False, makeMaxNodes=False )
YPZhangcb86c5b2016-01-27 17:38:12 -080083 copyResult = main.ONOSbench.copyMininetFile( main.topology,
84 main.dependencyPath,
85 main.Mininet1.user_name,
86 main.Mininet1.ip_address )
87
YPZhangcb86c5b2016-01-27 17:38:12 -080088 def CASE2( self, main ):
89 """
90 - Uninstall ONOS cluster
91 - Verify ONOS start up
92 - Install ONOS cluster
93 - Connect to cli
94 """
Devin Lim58046fa2017-07-05 16:55:00 -070095 main.testSetUp.ONOSSetUp( main.Mininet1, True,
96 killRemoveMax=False, CtrlsSet=False )
YPZhangcb86c5b2016-01-27 17:38:12 -080097
98 def CASE10( self, main ):
99 """
100 Setting up null-provider
101 """
102 import json
103 # Activate apps
104 main.step("Activating null-provider")
105 appStatus = utilities.retry( main.CLIs[0].activateApp,
106 main.FALSE,
Devin Lim58046fa2017-07-05 16:55:00 -0700107 [ 'org.onosproject.null' ],
YPZhangcb86c5b2016-01-27 17:38:12 -0800108 sleep=main.verifySleep,
109 attempts=main.verifyAttempts )
110 utilities.assert_equals( expect=main.TRUE,
111 actual=appStatus,
112 onpass="Successfully activated null-provider",
113 onfail="Failed activate null-provider" )
114
115 # Setup the null-provider
116 main.step("Configuring null-provider")
117 cfgStatus = utilities.retry( main.ONOSbench.onosCfgSet,
118 main.FALSE,
119 [ main.ONOSip[0],
Devin Lim58046fa2017-07-05 16:55:00 -0700120 'org.onosproject.provider.nil.NullProviders', 'deviceCount 8' ],
YPZhangcb86c5b2016-01-27 17:38:12 -0800121 sleep=main.verifySleep,
122 attempts = main.verifyAttempts )
123 cfgStatus = cfgStatus and utilities.retry( main.ONOSbench.onosCfgSet,
124 main.FALSE,
125 [ main.ONOSip[0],
Devin Lim58046fa2017-07-05 16:55:00 -0700126 'org.onosproject.provider.nil.NullProviders', 'topoShape reroute' ],
YPZhangcb86c5b2016-01-27 17:38:12 -0800127 sleep=main.verifySleep,
128 attempts = main.verifyAttempts )
129
130 cfgStatus = cfgStatus and utilities.retry( main.ONOSbench.onosCfgSet,
131 main.FALSE,
132 [ main.ONOSip[0],
Devin Lim58046fa2017-07-05 16:55:00 -0700133 'org.onosproject.provider.nil.NullProviders', 'enabled true' ],
YPZhangcb86c5b2016-01-27 17:38:12 -0800134 sleep=main.verifySleep,
135 attempts = main.verifyAttempts )
136
137
138 utilities.assert_equals( expect=main.TRUE,
139 actual=cfgStatus,
140 onpass="Successfully configured null-provider",
141 onfail="Failed to configure null-provider" )
142
143 # give onos some time to settle
144 time.sleep(main.startUpSleep)
145
146 main.log.info("Setting default flows to zero")
147 main.defaultFlows = 0
148
149 main.step("Check status of null-provider setup")
150 caseResult = appStatus and cfgStatus
151 utilities.assert_equals( expect=main.TRUE,
152 actual=caseResult,
153 onpass="Setting up null-provider was successfull",
154 onfail="Failed to setup null-provider" )
155
156 # This tells the following cases if we are using the null-provider or ovs
157 main.switchType = "null:"
158
159 # If the null-provider setup was unsuccessfull, then there is no point to
160 # run the subsequent cases
161
162 time.sleep(main.startUpSleep)
163 main.step( "Balancing Masters" )
164
165 stepResult = main.FALSE
166 stepResult = utilities.retry( main.CLIs[0].balanceMasters,
167 main.FALSE,
168 [],
169 sleep=3,
170 attempts=3 )
171
172 utilities.assert_equals( expect=main.TRUE,
173 actual=stepResult,
174 onpass="Balance masters was successfull",
175 onfail="Failed to balance masters")
176
177 time.sleep( 5 )
178 if not caseResult:
179 main.setupSkipped = True
180
181 def CASE11( self, main):
182 '''
183 Setting up mininet
184 '''
185 import json
186 import time
YPZhangebf9eb52016-05-12 15:20:24 -0700187
188 devices = []
189 devices = main.CLIs[0].getAllDevicesId()
190 for d in devices:
191 main.CLIs[0].deviceRemove( d )
YPZhangcb86c5b2016-01-27 17:38:12 -0800192
193 time.sleep(main.startUpSleep)
YPZhange6ef82a2016-07-05 16:48:15 -0700194 if main.flowObj:
195 main.CLIs[0].setCfg("org.onosproject.net.intent.impl.compiler.IntentConfigurableRegistrator",
196 "useFlowObjectives", value="true")
You Wang106d0fa2017-05-15 17:22:15 -0700197 main.CLIs[0].setCfg("org.onosproject.net.intent.impl.compiler.IntentConfigurableRegistrator",
198 "defaultFlowObjectiveCompiler",
199 value='org.onosproject.net.intent.impl.compiler.LinkCollectionIntentObjectiveCompiler')
YPZhangcb86c5b2016-01-27 17:38:12 -0800200 main.step('Starting mininet topology')
201 mnStatus = main.Mininet1.startNet(topoFile='~/mininet/custom/rerouteTopo.py')
202 utilities.assert_equals( expect=main.TRUE,
203 actual=mnStatus,
204 onpass="Successfully started Mininet",
205 onfail="Failed to activate Mininet" )
206
207 main.step("Assinging masters to switches")
208 switches = main.Mininet1.getSwitches()
209 swStatus = main.Mininet1.assignSwController( sw=switches.keys(), ip=main.ONOSip )
210 utilities.assert_equals( expect=main.TRUE,
211 actual=swStatus,
212 onpass="Successfully assigned switches to masters",
213 onfail="Failed assign switches to masters" )
214
215 time.sleep(main.startUpSleep)
YPZhangebf9eb52016-05-12 15:20:24 -0700216 # Balancing Masters
217 main.step( "Balancing Masters" )
218 stepResult = main.FALSE
219 stepResult = utilities.retry( main.CLIs[0].balanceMasters,
220 main.FALSE,
221 [],
222 sleep=3,
223 attempts=3 )
224
225 utilities.assert_equals( expect=main.TRUE,
226 actual=stepResult,
227 onpass="Balance masters was successfull",
228 onfail="Failed to balance masters" )
YPZhangcb86c5b2016-01-27 17:38:12 -0800229
230 main.log.info("Getting default flows")
231 jsonSum = json.loads(main.CLIs[0].summary())
232 main.defaultFlows = jsonSum["flows"]
233
234 main.step("Check status of Mininet setup")
YPZhangebf9eb52016-05-12 15:20:24 -0700235 caseResult = mnStatus and swStatus
YPZhangcb86c5b2016-01-27 17:38:12 -0800236 utilities.assert_equals( expect=main.TRUE,
237 actual=caseResult,
238 onpass="Successfully setup Mininet",
239 onfail="Failed setup Mininet" )
240
241 # This tells the following cases if we are using the null-provider or ovs
242 main.switchType = "of:"
243
244 time.sleep(main.startUpSleep)
245 main.step( "Balancing Masters" )
246
247 stepResult = main.FALSE
248 stepResult = utilities.retry( main.CLIs[0].balanceMasters,
249 main.FALSE,
250 [],
251 sleep=3,
252 attempts=3 )
253
254 utilities.assert_equals( expect=main.TRUE,
255 actual=stepResult,
256 onpass="Balance masters was successfull",
257 onfail="Failed to balance masters")
258
259 time.sleep(5)
260 if not caseResult:
261 main.setupSkipped = True
262
263
264
265 def CASE20( self, main ):
Devin Lim58046fa2017-07-05 16:55:00 -0700266 try:
267 from tests.dependencies.utils import Utils
268 except ImportError:
269 main.log.error( "Utils not found exiting the test" )
270 main.exit()
271 try:
272 main.Utils
273 except ( NameError, AttributeError ):
274 main.Utils = Utils()
YPZhangcb86c5b2016-01-27 17:38:12 -0800275 if main.reroute:
Devin Lim58046fa2017-07-05 16:55:00 -0700276 main.minIntents = int(main.params[ 'NULL' ][ 'REROUTE' ][ 'min_intents' ] )
277 main.maxIntents = int(main.params[ 'NULL' ][ 'REROUTE' ][ 'max_intents' ] )
278 main.checkInterval = int(main.params[ 'NULL' ][ 'REROUTE' ][ 'check_interval' ] )
279 main.batchSize = int(main.params[ 'NULL' ][ 'REROUTE' ][ 'batch_size' ] )
YPZhangcb86c5b2016-01-27 17:38:12 -0800280 else:
Devin Lim58046fa2017-07-05 16:55:00 -0700281 main.minIntents = int(main.params[ 'NULL' ][ 'PUSH' ][ 'min_intents' ] )
282 main.maxIntents = int(main.params[ 'NULL' ][ 'PUSH' ][ 'max_intents' ] )
283 main.checkInterval = int(main.params[ 'NULL' ][ 'PUSH' ][ 'check_interval' ] )
284 main.batchSize = int(main.params[ 'NULL' ][ 'PUSH' ][ 'batch_size' ] )
YPZhangcb86c5b2016-01-27 17:38:12 -0800285
286 # check if the case needs to be skipped
287 if main.setupSkipped:
288 main.setupSkipped = False
289 main.skipCase()
290
291 # the index where the next intents will be installed
292 offfset = 0
293 # keeps track of how many intents have been installed
294 currIntents = 0
YPZhang3097ba92016-02-16 17:32:32 -0800295 # keeps track of how many flows have been installed, set to 0 at start
296 currFlows = 0
YPZhangcb86c5b2016-01-27 17:38:12 -0800297 # limit for the number of intents that can be installed
YPZhangebf9eb52016-05-12 15:20:24 -0700298 main.batchSize = int( int(main.batchSize)/int(main.numCtrls))
YPZhangcb86c5b2016-01-27 17:38:12 -0800299 limit = main.maxIntents / main.batchSize
300 # total intents installed
301 totalIntents = 0
302
303 intentsState = None
304
305 offtmp = 0
306 main.step( "Pushing intents" )
307 stepResult = main.TRUE
YPZhang47779c22016-03-07 13:03:07 -0800308 # temp variable to contain the number of flows
309 flowsNum = 0
YPZhangebf9eb52016-05-12 15:20:24 -0700310 if main.numCtrls > 1:
311 # if more than one onos nodes, we should check more frequently
312 main.checkInterval = main.checkInterval/4
YPZhangcb86c5b2016-01-27 17:38:12 -0800313
YPZhangebf9eb52016-05-12 15:20:24 -0700314 # make sure the checkInterval divisible batchSize
315 main.checkInterval = int( int( main.checkInterval / main.batchSize ) * main.batchSize )
YPZhangac53ebf2016-05-13 16:26:19 -0700316 flowTemp=0
YPZhang14a4aa92016-07-15 13:37:15 -0700317 intentVerifyTemp = 0
YPZhangac53ebf2016-05-13 16:26:19 -0700318 totalFlows=0
YPZhangcb86c5b2016-01-27 17:38:12 -0800319 for i in range(limit):
320
321 # Threads pool
322 pool = []
323
324 for j in range( int( main.numCtrls) ):
325 if main.numCtrls > 1:
326 time.sleep( 1 )
327 offtmp = offfset + main.maxIntents * j
328 # Push intents by using threads
329 t = main.Thread( target=main.CLIs[j].pushTestIntents,
330 threadID=main.threadID,
331 name="Push-Test-Intents",
332 args=[ main.switchType + main.ingress,
333 main.switchType + main.egress,
334 main.batchSize ],
335 kwargs={ "offset": offtmp,
336 "options": "-i",
337 "timeout": main.timeout,
YPZhangebf9eb52016-05-12 15:20:24 -0700338 "background":False,
339 "noExit":True} )
YPZhangcb86c5b2016-01-27 17:38:12 -0800340 pool.append(t)
341 t.start()
342 main.threadID = main.threadID + 1
343 for t in pool:
344 t.join()
345 stepResult = stepResult and t.result
346 offfset = offfset + main.batchSize
347
YPZhang3097ba92016-02-16 17:32:32 -0800348 totalIntents = main.batchSize * main.numCtrls + totalIntents
YPZhangcb86c5b2016-01-27 17:38:12 -0800349 if totalIntents >= main.minIntents and totalIntents % main.checkInterval == 0:
350 # if reach to minimum number and check interval, verify Intetns and flows
351 time.sleep( main.verifySleep * main.numCtrls )
352
353 main.log.info("Verify Intents states")
YPZhang3097ba92016-02-16 17:32:32 -0800354 # k is a control variable for verify retry attempts
YPZhangcb86c5b2016-01-27 17:38:12 -0800355 k = 1
YPZhang3097ba92016-02-16 17:32:32 -0800356 while k <= main.verifyAttempts:
YPZhang14a4aa92016-07-15 13:37:15 -0700357 # while loop for check intents by using CLI driver
YPZhangcb86c5b2016-01-27 17:38:12 -0800358 time.sleep(5)
YPZhang14a4aa92016-07-15 13:37:15 -0700359 intentsState = main.CLIs[0].checkIntentSummary(timeout=600, noExit=True)
YPZhangebf9eb52016-05-12 15:20:24 -0700360 if intentsState:
YPZhang14a4aa92016-07-15 13:37:15 -0700361 verifyTotalIntents = main.CLIs[0].getTotalIntentsNum(timeout=600, noExit=True)
362 if intentVerifyTemp < verifyTotalIntents:
363 intentVerifyTemp = verifyTotalIntents
YPZhangebf9eb52016-05-12 15:20:24 -0700364 else:
YPZhang14a4aa92016-07-15 13:37:15 -0700365 verifyTotalIntents = intentVerifyTemp
YPZhang6e758fb2016-07-26 09:20:55 -0700366 intentsState = False
YPZhang14a4aa92016-07-15 13:37:15 -0700367 main.log.info("Total Installed Intents: {}".format( verifyTotalIntents ) )
YPZhangcb86c5b2016-01-27 17:38:12 -0800368 break
YPZhangcb86c5b2016-01-27 17:38:12 -0800369 k = k+1
YPZhangac53ebf2016-05-13 16:26:19 -0700370
YPZhang14a4aa92016-07-15 13:37:15 -0700371 k = 1
372 flowVerify = True
373 while k <= main.verifyAttempts:
374 time.sleep(5)
375 totalFlows = main.CLIs[0].getTotalFlowsNum( timeout=600, noExit=True )
376 expectFlows = totalIntents * 7 + main.defaultFlows
377 if totalFlows == expectFlows:
378 main.log.info("Total Flows Added: {}".format(totalFlows))
379 break
380 else:
381 main.log.info("Some Flows are not added, retry...")
382 main.log.info("Total Flows Added: {} Expect Flows: {}".format(totalFlows, expectFlows))
383 flowVerify = False
YPZhangac53ebf2016-05-13 16:26:19 -0700384
YPZhang14a4aa92016-07-15 13:37:15 -0700385 k += 1
386 if flowTemp < totalFlows:
387 flowTemp = totalFlows
388 else:
389 totalFlows = flowTemp
390
391 if not intentsState or not flowVerify:
YPZhanga4acbb82016-03-02 17:28:25 -0800392 # If some intents are not installed, grep the previous flows list, and finished this test case
YPZhang14a4aa92016-07-15 13:37:15 -0700393 main.log.warn( "Intents or flows are not installed" )
394 verifyTotalIntents = main.CLIs[0].getTotalIntentsNum(timeout=600, noExit=True)
395 if intentVerifyTemp < verifyTotalIntents:
396 intentVerifyTemp = verifyTotalIntents
397 else:
398 verifyTotalIntents = intentVerifyTemp
399 if flowTemp < totalFlows:
400 flowTemp = totalFlows
401 else:
402 totalFlows = flowTemp
YPZhangac53ebf2016-05-13 16:26:19 -0700403 main.log.info("Total Intents: {}".format( verifyTotalIntents) )
YPZhangcb86c5b2016-01-27 17:38:12 -0800404 break
YPZhange96a3062016-05-12 16:18:35 -0700405
YPZhangcb86c5b2016-01-27 17:38:12 -0800406 utilities.assert_equals( expect = main.TRUE,
YPZhangebf9eb52016-05-12 15:20:24 -0700407 actual = intentsState,
YPZhangcb86c5b2016-01-27 17:38:12 -0800408 onpass = "Successfully pushed and verified intents",
409 onfail = "Failed to push and verify intents" )
410
YPZhangcb86c5b2016-01-27 17:38:12 -0800411 main.log.info( "Total Intents Installed before crash: {}".format( totalIntents ) )
412 main.log.info( "Total Flows ADDED before crash: {}".format( totalFlows ) )
413
Devin Lim58046fa2017-07-05 16:55:00 -0700414 main.Utils.mininetCleanup( main.Mininet1 )
415
YPZhangcb86c5b2016-01-27 17:38:12 -0800416 main.log.info("Writing results to DS file")
417 with open(main.dbFileName, "a") as dbFile:
418 # Scale number
419 temp = str(main.numCtrls)
420 temp += ",'" + "baremetal1" + "'"
421 # how many intents we installed before crash
YPZhangac53ebf2016-05-13 16:26:19 -0700422 temp += "," + str(verifyTotalIntents)
YPZhangcb86c5b2016-01-27 17:38:12 -0800423 # how many flows we installed before crash
424 temp += "," + str(totalFlows)
425 # other columns in database, but we didn't use in this test
426 temp += "," + "0,0,0,0,0,0"
427 temp += "\n"
428 dbFile.write( temp )