blob: 077ce9c42d62165803245e65d56963113e14f42d [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 " )
120
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" )
129
130 time.sleep( main.startUpSleep )
131 main.step( "Uninstalling ONOS package" )
132 onosUninstallResult = main.TRUE
133 for i in range( main.numCtrls ):
134 onosUninstallResult = onosUninstallResult and \
135 main.ONOSbench.onosUninstall( nodeIp=main.ONOSip[ i ] )
136 stepResult = onosUninstallResult
137 utilities.assert_equals( expect=main.TRUE,
138 actual=stepResult,
139 onpass="Successfully uninstalled ONOS package",
140 onfail="Failed to uninstall ONOS package" )
141
142 time.sleep( main.startUpSleep )
143 main.step( "Installing ONOS package" )
144 onosInstallResult = main.TRUE
145 for i in range( main.numCtrls ):
146 onosInstallResult = onosInstallResult and \
147 main.ONOSbench.onosInstall( node=main.ONOSip[ i ] )
148 stepResult = onosInstallResult
149 utilities.assert_equals( expect=main.TRUE,
150 actual=stepResult,
151 onpass="Successfully installed ONOS package",
152 onfail="Failed to install ONOS package" )
153
154 time.sleep( main.startUpSleep )
155 main.step( "Starting ONOS service" )
156 stopResult = main.TRUE
157 startResult = main.TRUE
158 onosIsUp = main.TRUE
159
160 for i in range( main.numCtrls ):
161 onosIsUp = onosIsUp and main.ONOSbench.isup( main.ONOSip[ i ] )
162 if onosIsUp == main.TRUE:
163 main.log.report( "ONOS instance is up and ready" )
164 else:
165 main.log.report( "ONOS instance may not be up, stop and " +
166 "start ONOS again " )
167 for i in range( main.numCtrls ):
168 stopResult = stopResult and \
169 main.ONOSbench.onosStop( main.ONOSip[ i ] )
170 for i in range( main.numCtrls ):
171 startResult = startResult and \
172 main.ONOSbench.onosStart( main.ONOSip[ i ] )
173 stepResult = onosIsUp and stopResult and startResult
174 utilities.assert_equals( expect=main.TRUE,
175 actual=stepResult,
176 onpass="ONOS service is ready",
177 onfail="ONOS service did not start properly" )
178
suibin zhang9a8264f2016-04-03 21:18:59 -0700179 main.step( "Start ONOS cli" )
180 cliResult = main.TRUE
181 for i in range( i, main.numCtrls ):
182 cliResult = cliResult and \
183 main.CLIs[ i ].startOnosCli( ONOSIp=main.ONOSip[ i ] )
184 main.log.info("ONOSip is: " + main.ONOSip[i])
185 stepResult = cliResult
186 utilities.assert_equals( expect=main.TRUE,
187 actual=stepResult,
188 onpass="Successfully start ONOS cli",
189 onfail="Failed to start ONOS cli" )
190
191
suibin zhangd0f09b32016-03-29 00:57:57 -0700192
193 def CASE10( self, main ):
194 '''
195 Start Mininet
196 '''
suibin zhang5c735ca2016-03-30 16:01:06 -0700197 import time
suibin zhangd0f09b32016-03-29 00:57:57 -0700198
199 main.numSw = int(main.params['CASE10']['numSw'])
suibin zhang5c735ca2016-03-30 16:01:06 -0700200 main.case( "Enable openflow-base on onos and start Mininet." )
suibin zhangd0f09b32016-03-29 00:57:57 -0700201 main.caseExplanation = "Start mininet with custom topology and compare topology " +\
202 "elements between Mininet and ONOS"
203
suibin zhang5c735ca2016-03-30 16:01:06 -0700204 main.step("Activate openflow-base App")
205 stepResult = main.ONOSbench.onosCli( ONOSIp = main.ONOSip[0], cmdstr = "app activate org.onosproject.openflow-base" )
206 time.sleep(10)
207 print stepResult
208 time.sleep(5)
209
suibin zhangd0f09b32016-03-29 00:57:57 -0700210 main.step( "Setup Mininet Linear Topology with " + str(main.numSw) + " switches" )
211 stepResult = main.Mininet1.startNet( args = main.params['CASE10']['mnArgs'] )
212
213 utilities.assert_equals( expect=main.TRUE,
214 actual=stepResult,
215 onpass="Successfully loaded topology",
216 onfail="Failed to load topology" )
217
suibin zhang5c735ca2016-03-30 16:01:06 -0700218 time.sleep(int(main.params['SLEEP']['startMN']))
suibin zhangd0f09b32016-03-29 00:57:57 -0700219 main.step( "Assign switches to controller" )
220 for i in range(1, main.numSw + 1):
221 main.Mininet1.assignSwController( "s" + str(i), main.ONOSip[0] )
222
223 utilities.assert_equals( expect=main.TRUE,
224 actual=stepResult,
225 onpass="Successfully assigned switch to controller",
226 onfail="Failed to assign switch to controller" )
227
suibin zhang5c735ca2016-03-30 16:01:06 -0700228 main.deviceIdPrefix = "of:"
229
suibin zhangd0f09b32016-03-29 00:57:57 -0700230 time.sleep( main.startMNSleep )
231
suibin zhang5c735ca2016-03-30 16:01:06 -0700232 def CASE11( self, main ):
233 '''
234 Start Null Provider
235 '''
236 import time
237
238 main.numSw = int(main.params['CASE11']['numSw'])
239
240 main.case("Activate Null Provider App")
241 stepResult = main.ONOSbench.onosCli( ONOSIp = main.ONOSip[0], cmdstr = "app activate org.onosproject.null" )
242 time.sleep(10)
243 print stepResult
244 time.sleep(5)
245
246 main.case( "Setup Null Provider for linear Topology" )
247 main.step( "Setup Null Provider Linear Topology with " + str(main.numSw) + " devices." )
248 main.ONOSbench.onosCfgSet( main.ONOSip[0], "org.onosproject.provider.nil.NullProviders", "deviceCount " + str(main.numSw))
249 main.ONOSbench.onosCfgSet( main.ONOSip[0], "org.onosproject.provider.nil.NullProviders", "topoShape " + main.params['CASE11']['nullTopo'] )
250 main.ONOSbench.onosCfgSet( main.ONOSip[0], "org.onosproject.provider.nil.NullProviders", "enabled " + main.params['CASE11']['nullStart'])
251 time.sleep(5)
252
253 main.log.info("Check to make sure null providers are configured correctly.")
254 main.ONOSbench.handle.sendline("onos $OC1 summary")
255 stepResult = main.ONOSbench.handle.expect(":~")
256 main.log.info("ONOS Summary: " + main.ONOSbench.handle.before)
257
258 main.deviceIdPrefix = "null:"
259
260 time.sleep( main.startMNSleep )
suibin zhangd0f09b32016-03-29 00:57:57 -0700261
262
263
264 def CASE1000( self, main ):
265 '''
266 create JSON object with batched flows
267 '''
268 import numpy
269 import time
suibin zhang570cb452016-03-29 19:03:15 -0700270 from pprint import pprint
suibin zhangd0f09b32016-03-29 00:57:57 -0700271
272 main.case( "Create a json object for the batched flows" )
273
suibin zhanga5875da2016-04-02 20:54:50 -0700274 main.step( "Parse batch creation information" )
suibin zhanga82fe3f2016-03-29 11:26:21 -0700275 main.batchSize = int(main.params['CASE1000']['batchSize'])
276 main.log.info("Number of flows in a batch is:" + str(main.batchSize))
suibin zhangd0f09b32016-03-29 00:57:57 -0700277
278 main.flowJsonBatchList = []
279 postTimes = []
suibin zhanga82fe3f2016-03-29 11:26:21 -0700280 startSw = 1
suibin zhangd0f09b32016-03-29 00:57:57 -0700281
282 main.step("Creating a full list of batches")
283 for index in range(1, int(main.params['CASE1000']['batches']) + 1):
suibin zhanga82fe3f2016-03-29 11:26:21 -0700284 if startSw <= main.numSw:
suibin zhangff4abfe2016-03-29 11:52:08 -0700285 ind = startSw
286 else:
287 startSw = 1
288 ind = startSw
289
290 main.log.info("Creating batch: " + str(index))
291 flowJsonBatch = main.ONOSrest.createFlowBatch( numSw = main.numSw,
292 swIndex = ind,
suibin zhanga82fe3f2016-03-29 11:26:21 -0700293 batchSize = main.batchSize,
suibin zhangd0f09b32016-03-29 00:57:57 -0700294 batchIndex = index,
suibin zhang5c735ca2016-03-30 16:01:06 -0700295 deviceIdpreFix=main.deviceIdPrefix,
suibin zhangd0f09b32016-03-29 00:57:57 -0700296 ingressPort = 2,
297 egressPort = 3)
suibin zhangff4abfe2016-03-29 11:52:08 -0700298 main.flowJsonBatchList.append(flowJsonBatch)
suibin zhanga82fe3f2016-03-29 11:26:21 -0700299
suibin zhangff4abfe2016-03-29 11:52:08 -0700300 startSw += 1
suibin zhanga5875da2016-04-02 20:54:50 -0700301 main.log.info( "Number of items created in the batch list is: " + str(len(main.flowJsonBatchList)))
suibin zhangff4abfe2016-03-29 11:52:08 -0700302
suibin zhanga5875da2016-04-02 20:54:50 -0700303 def CASE2100(self, main):
304 '''
305 Posting flow batches using threads
306 '''
307 main.case("Using REST API /flows/{} to post flow batch - multi-threads")
308 main.step("Using REST API /flows/{} to post flow batch - multi-threads")
309
310 from Queue import Queue
311 from threading import Thread
312 import time
313
314 main.threadID = 0
315 main.addedBatchList = []
316 q = Queue()
317 tAllAdded = 0
318
319 def postWorker(id):
320 while True:
321 item = q.get()
322 status,response = main.ONOSrest.sendFlowBatch(batch = item)
323 main.log.info("Thread {} is working on posting. ".format(id))
324 main.addedBatchList.append(response[1])
325 q.task_done()
326
327 for i in range( int( main.params['CASE2100']['numThreads'])):
328 threadID = "ThreadID-" + str(i)
329 t = Thread(target = postWorker, name = threadID, args=(threadID,) )
330 t.daemon = True
331 t.start()
332
333 tStartPost = time.time()
334 for item in main.flowJsonBatchList:
335 q.put(item)
336
337 q.join()
338 tLastPostEnd = time.time()
339
340 main.step("Check to ensure all flows are in added state.")
341 #pprint(main.addedBatchList)
342 resp = main.FALSE
343 while resp != main.TRUE and ( tAllAdded - tLastPostEnd < int (main.params['CASE2100']['chkFlowTO']) ):
suibin zhang9a8264f2016-04-03 21:18:59 -0700344 if main.params['CASE2100']['RESTchkFlow'] == main.TRUE:
345 resp = main.ONOSrest.checkFlowsState()
346 else:
347 handle = main.CLIs[0].flows(state = " |grep PEND|wc -l", jsonFormat=False)
348 main.log.info("handle returns PENDING flows: " + handle)
349 if handle == "0":
350 resp = main.TRUE
351
suibin zhanga5875da2016-04-02 20:54:50 -0700352 time.sleep( float(main.params['SLEEP']['chkFlow']) )
353 tAllAdded = time.time()
354
355 if tAllAdded - tLastPostEnd >= int (main.params['CASE2100']['chkFlowTO']):
356 main.log.warn("ONOS Flows still in pending state after: {} seconds.".format(tAllAdded - tLastPostEnd))
357
358 main.numFlows = int(main.params['CASE1000']['batches']) *\
359 int(main.params['CASE1000']['batchSize'])
360 main.log.info("Total number of flows: " + str (main.numFlows) )
suibin zhang9a8264f2016-04-03 21:18:59 -0700361 #main.log.info("Sum of each POST elapse time: " + str(numpy.sum(postTimes)) )
suibin zhanga5875da2016-04-02 20:54:50 -0700362 main.log.info("Total POST elapse time: " + str(tLastPostEnd-tStartPost))
363 main.log.info("Rate of ADD Controller response: " + str(main.numFlows / (tLastPostEnd - tStartPost)))
364
365 duration = tAllAdded - tLastPostEnd
366 main.log.info("Elapse time from end of last REST POST to Flows in ADDED state: " +\
367 str(duration))
368 main.log.info("Rate of Confirmed Batch Flow ADD is (flows/sec): " + str( main.numFlows / duration))
369 main.log.info("Number of flow Batches in the addedBatchList is: " + str( len(main.addedBatchList)))
370
suibin zhanga5875da2016-04-02 20:54:50 -0700371 def CASE3100(self, main):
372 '''
373 DELETE flow batches using threads
374 '''
375 main.case("Using REST API /flows/{} to delete flow batch - multi-threads")
376 main.step("Using REST API /flows/{} to delete flow batch - multi-threads")
377
378 from Queue import Queue
379 from threading import Thread
380 import time
381 import json
382
383 main.threadID = 0
384 q = Queue()
385 tAllRemoved = 0
386
387 main.log.info("Number of flow batches at start of remove: " + str( len( main.addedBatchList)))
388 def removeWorker(id):
389 while True:
390 item = q.get()
391 response = main.ONOSrest.removeFlowBatch(batch = json.loads(item) )
392 main.log.info("Thread {} is working on deleting. ".format(id))
393 q.task_done()
394
395 for i in range( int( main.params['CASE2100']['numThreads'])):
396 threadID = "ThreadID-" + str(i)
397 t = Thread(target = removeWorker, name = threadID, args=(threadID,) )
398 t.daemon = True
399 t.start()
400
401 tStartDelete = time.time()
402 for item in main.addedBatchList:
403 q.put(item)
404
405 q.join()
406 tLastDeleteEnd = time.time()
407 main.log.info("Number of flow batches at end of remove: " + str( len( main.addedBatchList)))
408
409 main.step("Check to ensure all flows are in added state.")
410 #pprint(main.addedBatchList)
411 resp = main.FALSE
412 while resp != main.TRUE and ( tAllRemoved - tLastDeleteEnd < int (main.params['CASE3100']['chkFlowTO']) ):
suibin zhang9a8264f2016-04-03 21:18:59 -0700413 if main.params['CASE3100']['RESTchkFlow'] == main.TRUE:
414 resp = main.ONOSrest.checkFlowsState()
415 else:
416 handle = main.CLIs[0].flows(state = " |grep PEND|wc -l", jsonFormat=False)
417 main.log.info("handle returns PENDING flows: " + handle)
418 if handle == "0":
419 resp = main.TRUE
suibin zhanga5875da2016-04-02 20:54:50 -0700420 time.sleep( float(main.params['SLEEP']['chkFlow']) )
421 tAllRemoved = time.time()
422
423 if tLastDeleteEnd - tLastDeleteEnd >= int (main.params['CASE2100']['chkFlowTO']):
suibin zhang9a8264f2016-04-03 21:18:59 -0700424 main.log.warn("ONOS Flows still in pending state after: {} seconds.".format(tAllRemoved - tLastDeleteEnd))
suibin zhanga5875da2016-04-02 20:54:50 -0700425
426 main.numFlows = int(main.params['CASE1000']['batches']) *\
427 int(main.params['CASE1000']['batchSize'])
428 main.log.info("Total number of flows: " + str (main.numFlows) )
suibin zhang9a8264f2016-04-03 21:18:59 -0700429 #main.log.info("Sum of each DELETE elapse time: " + str(numpy.sum(postTimes)) )
suibin zhanga5875da2016-04-02 20:54:50 -0700430 main.log.info("Total DELETE elapse time: " + str(tLastDeleteEnd-tStartDelete))
431 main.log.info("Rate of DELETE Controller response: " + str(main.numFlows / (tLastDeleteEnd-tStartDelete)))
432
433 duration = tAllRemoved - tLastDeleteEnd
434 main.log.info("Elapse time from end of last REST DELETE to Flows in REMOVED state: " +\
435 str(duration))
436 main.log.info("Rate of Confirmed Batch Flow REMOVED is (flows/sec): " + str( main.numFlows / duration))
437
suibin zhangd0f09b32016-03-29 00:57:57 -0700438 def CASE100(self,main):
439 from pprint import pprint
440
441 main.case( "Check to ensure onos flows." )
442
443 resp = main.ONOSrest.checkFlowsState()
suibin zhangdec01c52016-03-29 19:23:33 -0700444 #pprint(resp)
suibin zhangd0f09b32016-03-29 00:57:57 -0700445
446
447 def CASE110( self, main ):
448 '''
449 Report errors/warnings/exceptions
450 '''
451 main.log.info("Error report: \n" )
452 main.ONOSbench.logReport( main.ONOSip[ 0 ],
453 [ "INFO",
454 "FOLLOWER",
455 "WARN",
456 "flow",
457 "ERROR",
458 "Except" ],
459 "s" )
460 main.stop()
461