blob: 37e29e45c8dd65036a0e3a71b0c1631b672395b2 [file] [log] [blame]
suibin zhangd0f09b32016-03-29 00:57:57 -07001class COMPflow:
2
3 def __init__( self ):
4 self.default = ''
5
6 def CASE1( self, main ):
7 import time
8 import os
9 import imp
10
11 """
12 - Construct tests variables
13 - GIT ( optional )
14 - Checkout ONOS master branch
15 - Pull latest ONOS code
16 - Building ONOS ( optional )
17 - Install ONOS package
18 - Build ONOS package
19 """
20
21 main.case( "Constructing test variables and building ONOS package" )
22 main.step( "Constructing test variables" )
23 stepResult = main.FALSE
24
25 # Test variables
26 main.testOnDirectory = os.path.dirname( os.getcwd ( ) )
27 main.cellName = main.params[ 'ENV' ][ 'cellName' ]
28 main.apps = main.params[ 'ENV' ][ 'cellApps' ]
29 gitBranch = main.params[ 'GIT' ][ 'branch' ]
30 gitPull = main.params[ 'GIT' ][ 'pull' ]
31 main.ONOSport = main.params[ 'CTRL' ][ 'port' ]
32 main.maxNodes = int( main.params[ 'SCALE' ][ 'max' ] )
33 main.startUpSleep = int( main.params[ 'SLEEP' ][ 'startup' ] )
34 main.startMNSleep = int( main.params[ 'SLEEP' ][ 'startMN' ] )
35 main.addFlowSleep = int( main.params[ 'SLEEP' ][ 'addFlow' ] )
36 main.delFlowSleep = int( main.params[ 'SLEEP' ][ 'delFlow' ] )
37 main.debug = main.params['DEBUG']
38 #main.swDPID = main.params[ 'TEST' ][ 'swDPID' ]
39 main.cellData = {} # for creating cell file
40 main.CLIs = []
41 main.ONOSip = []
42
43 main.debug = True if "on" in main.debug else False
44
45 main.ONOSip = main.ONOSbench.getOnosIps()
46
47 # Assigning ONOS cli handles to a list
48 for i in range( 1, main.maxNodes + 1 ):
49 main.CLIs.append( getattr( main, 'ONOScli' + str( i ) ) )
50
51
52 if main.CLIs:
53 stepResult = main.TRUE
54 else:
55 main.log.error( "Did not properly created list of ONOS CLI handle" )
56 stepResult = main.FALSE
57
58 utilities.assert_equals( expect=main.TRUE,
59 actual=stepResult,
60 onpass="Successfully construct " +
61 "test variables ",
62 onfail="Failed to construct test variables" )
63
64 if gitPull == 'True':
65 main.step( "Building ONOS in " + gitBranch + " branch" )
66 onosBuildResult = main.startUp.onosBuild( main, gitBranch )
67 stepResult = onosBuildResult
68 utilities.assert_equals( expect=main.TRUE,
69 actual=stepResult,
70 onpass="Successfully compiled " +
71 "latest ONOS",
72 onfail="Failed to compile " +
73 "latest ONOS" )
74 else:
75 main.log.warn( "Did not pull new code so skipping mvn " +
76 "clean install" )
77
78 def CASE2( self, main ):
79 """
80 - Set up cell
81 - Create cell file
82 - Set cell file
83 - Verify cell file
84 - Kill ONOS process
85 - Uninstall ONOS cluster
86 - Verify ONOS start up
87 - Install ONOS cluster
88 - Connect to cli
89 """
90
91 main.numCtrls = int( main.maxNodes )
92
93 main.case( "Starting up " + str( main.numCtrls ) +
94 " node(s) ONOS cluster" )
95
96 #kill off all onos processes
97 main.log.info( "Safety check, killing all ONOS processes" +
98 " before initiating environment setup" )
99
suibin zhangd0f09b32016-03-29 00:57:57 -0700100
101 print "NODE COUNT = ", main.numCtrls
102
103 tempOnosIp = []
104 for i in range( main.numCtrls ):
105 tempOnosIp.append( main.ONOSip[i] )
106
suibin zhang9a8264f2016-04-03 21:18:59 -0700107
suibin zhang5c735ca2016-03-30 16:01:06 -0700108 main.log.info("Apps in cell file: " + main.apps)
suibin zhangd0f09b32016-03-29 00:57:57 -0700109 main.ONOSbench.createCellFile( main.ONOSbench.ip_address, "temp", main.Mininet1.ip_address, main.apps, tempOnosIp )
110
111 main.step( "Apply cell to environment" )
112 cellResult = main.ONOSbench.setCell( "temp" )
113 verifyResult = main.ONOSbench.verifyCell()
114 stepResult = cellResult and verifyResult
115 utilities.assert_equals( expect=main.TRUE,
116 actual=stepResult,
117 onpass="Successfully applied cell to " + \
118 "environment",
119 onfail="Failed to apply cell to environment " )
suibin zhang8a0a2782016-04-07 20:13:52 -0700120 '''
suibin zhang9a8264f2016-04-03 21:18:59 -0700121 if main.params['CASE2']['incPackaging'] == main.TRUE:
122 main.step( "Creating ONOS package" )
123 packageResult = main.ONOSbench.onosPackage(opTimeout=240)
124 stepResult = packageResult
125 utilities.assert_equals( expect=main.TRUE,
suibin zhangd0f09b32016-03-29 00:57:57 -0700126 actual=stepResult,
127 onpass="Successfully created ONOS package",
128 onfail="Failed to create ONOS package" )
suibin zhang8a0a2782016-04-07 20:13:52 -0700129 '''
suibin zhangd0f09b32016-03-29 00:57:57 -0700130
131 time.sleep( main.startUpSleep )
132 main.step( "Uninstalling ONOS package" )
133 onosUninstallResult = main.TRUE
134 for i in range( main.numCtrls ):
135 onosUninstallResult = onosUninstallResult and \
136 main.ONOSbench.onosUninstall( nodeIp=main.ONOSip[ i ] )
137 stepResult = onosUninstallResult
138 utilities.assert_equals( expect=main.TRUE,
139 actual=stepResult,
140 onpass="Successfully uninstalled ONOS package",
141 onfail="Failed to uninstall ONOS package" )
142
143 time.sleep( main.startUpSleep )
144 main.step( "Installing ONOS package" )
145 onosInstallResult = main.TRUE
146 for i in range( main.numCtrls ):
147 onosInstallResult = onosInstallResult and \
148 main.ONOSbench.onosInstall( node=main.ONOSip[ i ] )
149 stepResult = onosInstallResult
150 utilities.assert_equals( expect=main.TRUE,
151 actual=stepResult,
152 onpass="Successfully installed ONOS package",
153 onfail="Failed to install ONOS package" )
154
155 time.sleep( main.startUpSleep )
156 main.step( "Starting ONOS service" )
157 stopResult = main.TRUE
158 startResult = main.TRUE
159 onosIsUp = main.TRUE
160
161 for i in range( main.numCtrls ):
162 onosIsUp = onosIsUp and main.ONOSbench.isup( main.ONOSip[ i ] )
163 if onosIsUp == main.TRUE:
164 main.log.report( "ONOS instance is up and ready" )
165 else:
166 main.log.report( "ONOS instance may not be up, stop and " +
167 "start ONOS again " )
168 for i in range( main.numCtrls ):
169 stopResult = stopResult and \
170 main.ONOSbench.onosStop( main.ONOSip[ i ] )
171 for i in range( main.numCtrls ):
172 startResult = startResult and \
173 main.ONOSbench.onosStart( main.ONOSip[ i ] )
174 stepResult = onosIsUp and stopResult and startResult
175 utilities.assert_equals( expect=main.TRUE,
176 actual=stepResult,
177 onpass="ONOS service is ready",
178 onfail="ONOS service did not start properly" )
179
suibin zhang9a8264f2016-04-03 21:18:59 -0700180 main.step( "Start ONOS cli" )
181 cliResult = main.TRUE
182 for i in range( i, main.numCtrls ):
183 cliResult = cliResult and \
184 main.CLIs[ i ].startOnosCli( ONOSIp=main.ONOSip[ i ] )
185 main.log.info("ONOSip is: " + main.ONOSip[i])
186 stepResult = cliResult
187 utilities.assert_equals( expect=main.TRUE,
188 actual=stepResult,
189 onpass="Successfully start ONOS cli",
190 onfail="Failed to start ONOS cli" )
191
192
suibin zhangd0f09b32016-03-29 00:57:57 -0700193
194 def CASE10( self, main ):
195 '''
196 Start Mininet
197 '''
suibin zhang5c735ca2016-03-30 16:01:06 -0700198 import time
suibin zhangd0f09b32016-03-29 00:57:57 -0700199
200 main.numSw = int(main.params['CASE10']['numSw'])
suibin zhang5c735ca2016-03-30 16:01:06 -0700201 main.case( "Enable openflow-base on onos and start Mininet." )
suibin zhangd0f09b32016-03-29 00:57:57 -0700202 main.caseExplanation = "Start mininet with custom topology and compare topology " +\
203 "elements between Mininet and ONOS"
204
suibin zhang5c735ca2016-03-30 16:01:06 -0700205 main.step("Activate openflow-base App")
206 stepResult = main.ONOSbench.onosCli( ONOSIp = main.ONOSip[0], cmdstr = "app activate org.onosproject.openflow-base" )
207 time.sleep(10)
208 print stepResult
suibin zhang8a0a2782016-04-07 20:13:52 -0700209 time.sleep(5)
suibin zhang5c735ca2016-03-30 16:01:06 -0700210
suibin zhangd0f09b32016-03-29 00:57:57 -0700211 main.step( "Setup Mininet Linear Topology with " + str(main.numSw) + " switches" )
212 stepResult = main.Mininet1.startNet( args = main.params['CASE10']['mnArgs'] )
213
214 utilities.assert_equals( expect=main.TRUE,
215 actual=stepResult,
216 onpass="Successfully loaded topology",
217 onfail="Failed to load topology" )
218
suibin zhang5c735ca2016-03-30 16:01:06 -0700219 time.sleep(int(main.params['SLEEP']['startMN']))
suibin zhangd0f09b32016-03-29 00:57:57 -0700220 main.step( "Assign switches to controller" )
221 for i in range(1, main.numSw + 1):
222 main.Mininet1.assignSwController( "s" + str(i), main.ONOSip[0] )
223
224 utilities.assert_equals( expect=main.TRUE,
225 actual=stepResult,
226 onpass="Successfully assigned switch to controller",
227 onfail="Failed to assign switch to controller" )
228
suibin zhang5c735ca2016-03-30 16:01:06 -0700229 main.deviceIdPrefix = "of:"
230
suibin zhangd0f09b32016-03-29 00:57:57 -0700231 time.sleep( main.startMNSleep )
232
suibin zhang5c735ca2016-03-30 16:01:06 -0700233 def CASE11( self, main ):
234 '''
235 Start Null Provider
236 '''
237 import time
238
239 main.numSw = int(main.params['CASE11']['numSw'])
240
241 main.case("Activate Null Provider App")
242 stepResult = main.ONOSbench.onosCli( ONOSIp = main.ONOSip[0], cmdstr = "app activate org.onosproject.null" )
243 time.sleep(10)
244 print stepResult
245 time.sleep(5)
246
247 main.case( "Setup Null Provider for linear Topology" )
248 main.step( "Setup Null Provider Linear Topology with " + str(main.numSw) + " devices." )
249 main.ONOSbench.onosCfgSet( main.ONOSip[0], "org.onosproject.provider.nil.NullProviders", "deviceCount " + str(main.numSw))
250 main.ONOSbench.onosCfgSet( main.ONOSip[0], "org.onosproject.provider.nil.NullProviders", "topoShape " + main.params['CASE11']['nullTopo'] )
251 main.ONOSbench.onosCfgSet( main.ONOSip[0], "org.onosproject.provider.nil.NullProviders", "enabled " + main.params['CASE11']['nullStart'])
252 time.sleep(5)
253
254 main.log.info("Check to make sure null providers are configured correctly.")
255 main.ONOSbench.handle.sendline("onos $OC1 summary")
256 stepResult = main.ONOSbench.handle.expect(":~")
257 main.log.info("ONOS Summary: " + main.ONOSbench.handle.before)
258
259 main.deviceIdPrefix = "null:"
260
261 time.sleep( main.startMNSleep )
suibin zhangd0f09b32016-03-29 00:57:57 -0700262
263
264
265 def CASE1000( self, main ):
266 '''
267 create JSON object with batched flows
268 '''
269 import numpy
270 import time
suibin zhang570cb452016-03-29 19:03:15 -0700271 from pprint import pprint
suibin zhangd0f09b32016-03-29 00:57:57 -0700272
273 main.case( "Create a json object for the batched flows" )
274
suibin zhanga5875da2016-04-02 20:54:50 -0700275 main.step( "Parse batch creation information" )
suibin zhanga82fe3f2016-03-29 11:26:21 -0700276 main.batchSize = int(main.params['CASE1000']['batchSize'])
277 main.log.info("Number of flows in a batch is:" + str(main.batchSize))
suibin zhangd0f09b32016-03-29 00:57:57 -0700278
279 main.flowJsonBatchList = []
280 postTimes = []
suibin zhanga82fe3f2016-03-29 11:26:21 -0700281 startSw = 1
suibin zhangd0f09b32016-03-29 00:57:57 -0700282
283 main.step("Creating a full list of batches")
284 for index in range(1, int(main.params['CASE1000']['batches']) + 1):
suibin zhanga82fe3f2016-03-29 11:26:21 -0700285 if startSw <= main.numSw:
suibin zhangff4abfe2016-03-29 11:52:08 -0700286 ind = startSw
287 else:
288 startSw = 1
289 ind = startSw
290
291 main.log.info("Creating batch: " + str(index))
292 flowJsonBatch = main.ONOSrest.createFlowBatch( numSw = main.numSw,
293 swIndex = ind,
suibin zhanga82fe3f2016-03-29 11:26:21 -0700294 batchSize = main.batchSize,
suibin zhangd0f09b32016-03-29 00:57:57 -0700295 batchIndex = index,
suibin zhang5c735ca2016-03-30 16:01:06 -0700296 deviceIdpreFix=main.deviceIdPrefix,
suibin zhangd0f09b32016-03-29 00:57:57 -0700297 ingressPort = 2,
298 egressPort = 3)
suibin zhangff4abfe2016-03-29 11:52:08 -0700299 main.flowJsonBatchList.append(flowJsonBatch)
suibin zhanga82fe3f2016-03-29 11:26:21 -0700300
suibin zhangff4abfe2016-03-29 11:52:08 -0700301 startSw += 1
suibin zhanga5875da2016-04-02 20:54:50 -0700302 main.log.info( "Number of items created in the batch list is: " + str(len(main.flowJsonBatchList)))
suibin zhangff4abfe2016-03-29 11:52:08 -0700303
suibin zhanga5875da2016-04-02 20:54:50 -0700304 def CASE2100(self, main):
305 '''
306 Posting flow batches using threads
307 '''
308 main.case("Using REST API /flows/{} to post flow batch - multi-threads")
309 main.step("Using REST API /flows/{} to post flow batch - multi-threads")
310
311 from Queue import Queue
312 from threading import Thread
313 import time
314
315 main.threadID = 0
316 main.addedBatchList = []
317 q = Queue()
318 tAllAdded = 0
319
suibin zhang34f01372016-04-07 15:40:15 -0700320
321 main.step( "Disable AdaptiveFlowSampling ")
322 main.ONOSbench.onosCfgSet( main.ONOSip[0], "org.onosproject.provider.of.flow.impl.OpenFlowRuleProvider",
323 "adaptiveFlowSampling " + main.params['CASE2100']['adaptiveFlowenabled'])
suibin zhang8a0a2782016-04-07 20:13:52 -0700324 time.sleep(5)
suibin zhang34f01372016-04-07 15:40:15 -0700325
suibin zhanga5875da2016-04-02 20:54:50 -0700326 def postWorker(id):
327 while True:
328 item = q.get()
329 status,response = main.ONOSrest.sendFlowBatch(batch = item)
330 main.log.info("Thread {} is working on posting. ".format(id))
331 main.addedBatchList.append(response[1])
332 q.task_done()
333
334 for i in range( int( main.params['CASE2100']['numThreads'])):
335 threadID = "ThreadID-" + str(i)
336 t = Thread(target = postWorker, name = threadID, args=(threadID,) )
337 t.daemon = True
338 t.start()
339
340 tStartPost = time.time()
341 for item in main.flowJsonBatchList:
342 q.put(item)
343
344 q.join()
345 tLastPostEnd = time.time()
346
347 main.step("Check to ensure all flows are in added state.")
348 #pprint(main.addedBatchList)
349 resp = main.FALSE
350 while resp != main.TRUE and ( tAllAdded - tLastPostEnd < int (main.params['CASE2100']['chkFlowTO']) ):
suibin zhang9a8264f2016-04-03 21:18:59 -0700351 if main.params['CASE2100']['RESTchkFlow'] == main.TRUE:
352 resp = main.ONOSrest.checkFlowsState()
353 else:
354 handle = main.CLIs[0].flows(state = " |grep PEND|wc -l", jsonFormat=False)
355 main.log.info("handle returns PENDING flows: " + handle)
356 if handle == "0":
357 resp = main.TRUE
358
suibin zhanga5875da2016-04-02 20:54:50 -0700359 time.sleep( float(main.params['SLEEP']['chkFlow']) )
360 tAllAdded = time.time()
361
362 if tAllAdded - tLastPostEnd >= int (main.params['CASE2100']['chkFlowTO']):
363 main.log.warn("ONOS Flows still in pending state after: {} seconds.".format(tAllAdded - tLastPostEnd))
364
365 main.numFlows = int(main.params['CASE1000']['batches']) *\
366 int(main.params['CASE1000']['batchSize'])
367 main.log.info("Total number of flows: " + str (main.numFlows) )
suibin zhang9a8264f2016-04-03 21:18:59 -0700368 #main.log.info("Sum of each POST elapse time: " + str(numpy.sum(postTimes)) )
suibin zhanga5875da2016-04-02 20:54:50 -0700369 main.log.info("Total POST elapse time: " + str(tLastPostEnd-tStartPost))
370 main.log.info("Rate of ADD Controller response: " + str(main.numFlows / (tLastPostEnd - tStartPost)))
371
372 duration = tAllAdded - tLastPostEnd
373 main.log.info("Elapse time from end of last REST POST to Flows in ADDED state: " +\
374 str(duration))
375 main.log.info("Rate of Confirmed Batch Flow ADD is (flows/sec): " + str( main.numFlows / duration))
376 main.log.info("Number of flow Batches in the addedBatchList is: " + str( len(main.addedBatchList)))
377
suibin zhanga5875da2016-04-02 20:54:50 -0700378 def CASE3100(self, main):
379 '''
380 DELETE flow batches using threads
381 '''
382 main.case("Using REST API /flows/{} to delete flow batch - multi-threads")
383 main.step("Using REST API /flows/{} to delete flow batch - multi-threads")
384
385 from Queue import Queue
386 from threading import Thread
387 import time
388 import json
389
390 main.threadID = 0
391 q = Queue()
392 tAllRemoved = 0
393
394 main.log.info("Number of flow batches at start of remove: " + str( len( main.addedBatchList)))
395 def removeWorker(id):
396 while True:
397 item = q.get()
398 response = main.ONOSrest.removeFlowBatch(batch = json.loads(item) )
399 main.log.info("Thread {} is working on deleting. ".format(id))
400 q.task_done()
401
402 for i in range( int( main.params['CASE2100']['numThreads'])):
403 threadID = "ThreadID-" + str(i)
404 t = Thread(target = removeWorker, name = threadID, args=(threadID,) )
405 t.daemon = True
406 t.start()
407
408 tStartDelete = time.time()
409 for item in main.addedBatchList:
410 q.put(item)
411
412 q.join()
413 tLastDeleteEnd = time.time()
414 main.log.info("Number of flow batches at end of remove: " + str( len( main.addedBatchList)))
415
416 main.step("Check to ensure all flows are in added state.")
417 #pprint(main.addedBatchList)
418 resp = main.FALSE
419 while resp != main.TRUE and ( tAllRemoved - tLastDeleteEnd < int (main.params['CASE3100']['chkFlowTO']) ):
suibin zhang9a8264f2016-04-03 21:18:59 -0700420 if main.params['CASE3100']['RESTchkFlow'] == main.TRUE:
421 resp = main.ONOSrest.checkFlowsState()
422 else:
423 handle = main.CLIs[0].flows(state = " |grep PEND|wc -l", jsonFormat=False)
424 main.log.info("handle returns PENDING flows: " + handle)
425 if handle == "0":
426 resp = main.TRUE
suibin zhanga5875da2016-04-02 20:54:50 -0700427 time.sleep( float(main.params['SLEEP']['chkFlow']) )
428 tAllRemoved = time.time()
429
430 if tLastDeleteEnd - tLastDeleteEnd >= int (main.params['CASE2100']['chkFlowTO']):
suibin zhang9a8264f2016-04-03 21:18:59 -0700431 main.log.warn("ONOS Flows still in pending state after: {} seconds.".format(tAllRemoved - tLastDeleteEnd))
suibin zhanga5875da2016-04-02 20:54:50 -0700432
433 main.numFlows = int(main.params['CASE1000']['batches']) *\
434 int(main.params['CASE1000']['batchSize'])
435 main.log.info("Total number of flows: " + str (main.numFlows) )
suibin zhang9a8264f2016-04-03 21:18:59 -0700436 #main.log.info("Sum of each DELETE elapse time: " + str(numpy.sum(postTimes)) )
suibin zhanga5875da2016-04-02 20:54:50 -0700437 main.log.info("Total DELETE elapse time: " + str(tLastDeleteEnd-tStartDelete))
438 main.log.info("Rate of DELETE Controller response: " + str(main.numFlows / (tLastDeleteEnd-tStartDelete)))
439
440 duration = tAllRemoved - tLastDeleteEnd
441 main.log.info("Elapse time from end of last REST DELETE to Flows in REMOVED state: " +\
442 str(duration))
443 main.log.info("Rate of Confirmed Batch Flow REMOVED is (flows/sec): " + str( main.numFlows / duration))
444
suibin zhangd0f09b32016-03-29 00:57:57 -0700445 def CASE100(self,main):
446 from pprint import pprint
447
448 main.case( "Check to ensure onos flows." )
449
450 resp = main.ONOSrest.checkFlowsState()
suibin zhangdec01c52016-03-29 19:23:33 -0700451 #pprint(resp)
suibin zhangd0f09b32016-03-29 00:57:57 -0700452
453
454 def CASE110( self, main ):
455 '''
456 Report errors/warnings/exceptions
457 '''
458 main.log.info("Error report: \n" )
459 main.ONOSbench.logReport( main.ONOSip[ 0 ],
460 [ "INFO",
461 "FOLLOWER",
462 "WARN",
463 "flow",
464 "ERROR",
465 "Except" ],
466 "s" )
467 main.stop()
468