blob: 7b9143108fa99ffdd727999088008eb168555bf0 [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 zhang5c735ca2016-03-30 16:01:06 -0700107 main.log.info("Apps in cell file: " + main.apps)
suibin zhangd0f09b32016-03-29 00:57:57 -0700108 main.ONOSbench.createCellFile( main.ONOSbench.ip_address, "temp", main.Mininet1.ip_address, main.apps, tempOnosIp )
109
110 main.step( "Apply cell to environment" )
111 cellResult = main.ONOSbench.setCell( "temp" )
112 verifyResult = main.ONOSbench.verifyCell()
113 stepResult = cellResult and verifyResult
114 utilities.assert_equals( expect=main.TRUE,
115 actual=stepResult,
116 onpass="Successfully applied cell to " + \
117 "environment",
118 onfail="Failed to apply cell to environment " )
119
120 main.step( "Creating ONOS package" )
suibin zhang5c735ca2016-03-30 16:01:06 -0700121 packageResult = main.ONOSbench.onosPackage(opTimeout=240)
suibin zhangd0f09b32016-03-29 00:57:57 -0700122 stepResult = packageResult
123 utilities.assert_equals( expect=main.TRUE,
124 actual=stepResult,
125 onpass="Successfully created ONOS package",
126 onfail="Failed to create ONOS package" )
127
128 time.sleep( main.startUpSleep )
129 main.step( "Uninstalling ONOS package" )
130 onosUninstallResult = main.TRUE
131 for i in range( main.numCtrls ):
132 onosUninstallResult = onosUninstallResult and \
133 main.ONOSbench.onosUninstall( nodeIp=main.ONOSip[ i ] )
134 stepResult = onosUninstallResult
135 utilities.assert_equals( expect=main.TRUE,
136 actual=stepResult,
137 onpass="Successfully uninstalled ONOS package",
138 onfail="Failed to uninstall ONOS package" )
139
140 time.sleep( main.startUpSleep )
141 main.step( "Installing ONOS package" )
142 onosInstallResult = main.TRUE
143 for i in range( main.numCtrls ):
144 onosInstallResult = onosInstallResult and \
145 main.ONOSbench.onosInstall( node=main.ONOSip[ i ] )
146 stepResult = onosInstallResult
147 utilities.assert_equals( expect=main.TRUE,
148 actual=stepResult,
149 onpass="Successfully installed ONOS package",
150 onfail="Failed to install ONOS package" )
151
152 time.sleep( main.startUpSleep )
153 main.step( "Starting ONOS service" )
154 stopResult = main.TRUE
155 startResult = main.TRUE
156 onosIsUp = main.TRUE
157
158 for i in range( main.numCtrls ):
159 onosIsUp = onosIsUp and main.ONOSbench.isup( main.ONOSip[ i ] )
160 if onosIsUp == main.TRUE:
161 main.log.report( "ONOS instance is up and ready" )
162 else:
163 main.log.report( "ONOS instance may not be up, stop and " +
164 "start ONOS again " )
165 for i in range( main.numCtrls ):
166 stopResult = stopResult and \
167 main.ONOSbench.onosStop( main.ONOSip[ i ] )
168 for i in range( main.numCtrls ):
169 startResult = startResult and \
170 main.ONOSbench.onosStart( main.ONOSip[ i ] )
171 stepResult = onosIsUp and stopResult and startResult
172 utilities.assert_equals( expect=main.TRUE,
173 actual=stepResult,
174 onpass="ONOS service is ready",
175 onfail="ONOS service did not start properly" )
176
suibin zhangd0f09b32016-03-29 00:57:57 -0700177
178 def CASE10( self, main ):
179 '''
180 Start Mininet
181 '''
suibin zhang5c735ca2016-03-30 16:01:06 -0700182 import time
suibin zhangd0f09b32016-03-29 00:57:57 -0700183
184 main.numSw = int(main.params['CASE10']['numSw'])
suibin zhang5c735ca2016-03-30 16:01:06 -0700185 main.case( "Enable openflow-base on onos and start Mininet." )
suibin zhangd0f09b32016-03-29 00:57:57 -0700186 main.caseExplanation = "Start mininet with custom topology and compare topology " +\
187 "elements between Mininet and ONOS"
188
suibin zhang5c735ca2016-03-30 16:01:06 -0700189 main.step("Activate openflow-base App")
190 stepResult = main.ONOSbench.onosCli( ONOSIp = main.ONOSip[0], cmdstr = "app activate org.onosproject.openflow-base" )
191 time.sleep(10)
192 print stepResult
193 time.sleep(5)
194
suibin zhangd0f09b32016-03-29 00:57:57 -0700195 main.step( "Setup Mininet Linear Topology with " + str(main.numSw) + " switches" )
196 stepResult = main.Mininet1.startNet( args = main.params['CASE10']['mnArgs'] )
197
198 utilities.assert_equals( expect=main.TRUE,
199 actual=stepResult,
200 onpass="Successfully loaded topology",
201 onfail="Failed to load topology" )
202
suibin zhang5c735ca2016-03-30 16:01:06 -0700203 time.sleep(int(main.params['SLEEP']['startMN']))
suibin zhangd0f09b32016-03-29 00:57:57 -0700204 main.step( "Assign switches to controller" )
205 for i in range(1, main.numSw + 1):
206 main.Mininet1.assignSwController( "s" + str(i), main.ONOSip[0] )
207
208 utilities.assert_equals( expect=main.TRUE,
209 actual=stepResult,
210 onpass="Successfully assigned switch to controller",
211 onfail="Failed to assign switch to controller" )
212
suibin zhang5c735ca2016-03-30 16:01:06 -0700213 main.deviceIdPrefix = "of:"
214
suibin zhangd0f09b32016-03-29 00:57:57 -0700215 time.sleep( main.startMNSleep )
216
suibin zhang5c735ca2016-03-30 16:01:06 -0700217 def CASE11( self, main ):
218 '''
219 Start Null Provider
220 '''
221 import time
222
223 main.numSw = int(main.params['CASE11']['numSw'])
224
225 main.case("Activate Null Provider App")
226 stepResult = main.ONOSbench.onosCli( ONOSIp = main.ONOSip[0], cmdstr = "app activate org.onosproject.null" )
227 time.sleep(10)
228 print stepResult
229 time.sleep(5)
230
231 main.case( "Setup Null Provider for linear Topology" )
232 main.step( "Setup Null Provider Linear Topology with " + str(main.numSw) + " devices." )
233 main.ONOSbench.onosCfgSet( main.ONOSip[0], "org.onosproject.provider.nil.NullProviders", "deviceCount " + str(main.numSw))
234 main.ONOSbench.onosCfgSet( main.ONOSip[0], "org.onosproject.provider.nil.NullProviders", "topoShape " + main.params['CASE11']['nullTopo'] )
235 main.ONOSbench.onosCfgSet( main.ONOSip[0], "org.onosproject.provider.nil.NullProviders", "enabled " + main.params['CASE11']['nullStart'])
236 time.sleep(5)
237
238 main.log.info("Check to make sure null providers are configured correctly.")
239 main.ONOSbench.handle.sendline("onos $OC1 summary")
240 stepResult = main.ONOSbench.handle.expect(":~")
241 main.log.info("ONOS Summary: " + main.ONOSbench.handle.before)
242
243 main.deviceIdPrefix = "null:"
244
245 time.sleep( main.startMNSleep )
suibin zhangd0f09b32016-03-29 00:57:57 -0700246
247
248
249 def CASE1000( self, main ):
250 '''
251 create JSON object with batched flows
252 '''
253 import numpy
254 import time
suibin zhang570cb452016-03-29 19:03:15 -0700255 from pprint import pprint
suibin zhangd0f09b32016-03-29 00:57:57 -0700256
257 main.case( "Create a json object for the batched flows" )
258
259 main.step( "Parse batch information" )
suibin zhanga82fe3f2016-03-29 11:26:21 -0700260 main.batchSize = int(main.params['CASE1000']['batchSize'])
261 main.log.info("Number of flows in a batch is:" + str(main.batchSize))
suibin zhangd0f09b32016-03-29 00:57:57 -0700262
263 main.flowJsonBatchList = []
suibin zhang570cb452016-03-29 19:03:15 -0700264 main.addedBatchList = []
suibin zhangd0f09b32016-03-29 00:57:57 -0700265 postTimes = []
suibin zhanga82fe3f2016-03-29 11:26:21 -0700266 startSw = 1
suibin zhangd0f09b32016-03-29 00:57:57 -0700267
268 main.step("Creating a full list of batches")
269 for index in range(1, int(main.params['CASE1000']['batches']) + 1):
suibin zhanga82fe3f2016-03-29 11:26:21 -0700270 if startSw <= main.numSw:
suibin zhangff4abfe2016-03-29 11:52:08 -0700271 ind = startSw
272 else:
273 startSw = 1
274 ind = startSw
275
276 main.log.info("Creating batch: " + str(index))
277 flowJsonBatch = main.ONOSrest.createFlowBatch( numSw = main.numSw,
278 swIndex = ind,
suibin zhanga82fe3f2016-03-29 11:26:21 -0700279 batchSize = main.batchSize,
suibin zhangd0f09b32016-03-29 00:57:57 -0700280 batchIndex = index,
suibin zhang5c735ca2016-03-30 16:01:06 -0700281 deviceIdpreFix=main.deviceIdPrefix,
suibin zhangd0f09b32016-03-29 00:57:57 -0700282 ingressPort = 2,
283 egressPort = 3)
suibin zhangff4abfe2016-03-29 11:52:08 -0700284 main.flowJsonBatchList.append(flowJsonBatch)
suibin zhanga82fe3f2016-03-29 11:26:21 -0700285
suibin zhangff4abfe2016-03-29 11:52:08 -0700286 startSw += 1
287
suibin zhanga82fe3f2016-03-29 11:26:21 -0700288
suibin zhangd0f09b32016-03-29 00:57:57 -0700289
290 main.step("Using REST API /flows/{} to post flow batch")
291 tStartPost = time.time()
292 for item in main.flowJsonBatchList:
293 ts = time.time()
suibin zhang570cb452016-03-29 19:03:15 -0700294 status, response = main.ONOSrest.sendFlowBatch(batch = item )
suibin zhangd0f09b32016-03-29 00:57:57 -0700295 teBatch = time.time() - ts
296 postTimes.append(teBatch)
297 main.log.info("Batch Rest Post Elapse time is: " + str(teBatch))
suibin zhang570cb452016-03-29 19:03:15 -0700298 main.addedBatchList.append(response[1])
suibin zhangd0f09b32016-03-29 00:57:57 -0700299
300 tLastPostEnd = time.time()
301
302 main.step("Check to ensure all flows are in added state.")
suibin zhang5c735ca2016-03-30 16:01:06 -0700303 #pprint(main.addedBatchList)
suibin zhangd0f09b32016-03-29 00:57:57 -0700304 resp = main.FALSE
305 while resp != main.TRUE:
306 resp = main.ONOSrest.checkFlowsState()
suibin zhang5c735ca2016-03-30 16:01:06 -0700307 time.sleep( float(main.params['SLEEP']['chkFlow']) )
suibin zhangd0f09b32016-03-29 00:57:57 -0700308 tAllAdded = time.time()
309
suibin zhangdec01c52016-03-29 19:23:33 -0700310 main.numFlows = int(main.params['CASE1000']['batches']) *\
suibin zhanga82fe3f2016-03-29 11:26:21 -0700311 int(main.params['CASE1000']['batchSize'])
suibin zhangdec01c52016-03-29 19:23:33 -0700312 main.log.info("Total number of flows: " + str (main.numFlows) )
suibin zhangd0f09b32016-03-29 00:57:57 -0700313 main.log.info("Sum of each POST elapse time: " + str(numpy.sum(postTimes)) )
314 main.log.info("Total POST elapse time: " + str(tLastPostEnd-tStartPost))
suibin zhangdec01c52016-03-29 19:23:33 -0700315 main.log.info("Rate of ADD Controller response: " + str(main.numFlows / (tLastPostEnd - tStartPost)))
suibin zhangd0f09b32016-03-29 00:57:57 -0700316
317 duration = tAllAdded - tLastPostEnd
318 main.log.info("Elapse time from end of last REST POST to Flows in ADDED state: " +\
319 str(duration))
suibin zhang5c735ca2016-03-30 16:01:06 -0700320 main.log.info("Rate of Confirmed Batch Flow ADD is (flows/sec): " + str( main.numFlows / duration))
suibin zhangd0f09b32016-03-29 00:57:57 -0700321
322 def CASE2000(self, main):
323 import time
324 import numpy
suibin zhang570cb452016-03-29 19:03:15 -0700325 import json
suibin zhangd0f09b32016-03-29 00:57:57 -0700326
327 rmTimes = []
328
329 main.case("Remove flow timing")
330
331 tStartRemove = time.time()
suibin zhang570cb452016-03-29 19:03:15 -0700332 for item in main.addedBatchList:
suibin zhangd0f09b32016-03-29 00:57:57 -0700333 ts = time.time()
suibin zhang570cb452016-03-29 19:03:15 -0700334 print(item)
335 resp = main.ONOSrest.removeFlowBatch(batch = json.loads(item) )
suibin zhangd0f09b32016-03-29 00:57:57 -0700336 teBatch = time.time() - ts
337 rmTimes.append(teBatch)
338 main.log.info("Batch Rest Remove Elapse time is: " + str(teBatch))
339
340 tLastRemoveEnd = time.time()
341
suibin zhangf59d3682016-03-29 19:27:13 -0700342 main.step("Check to ensure all flows are not in PENDING state.")
suibin zhangd0f09b32016-03-29 00:57:57 -0700343 resp = main.FALSE
344 while resp != main.TRUE:
345 resp = main.ONOSrest.checkFlowsState()
346 time.sleep(0.5)
347 tAllRemoved = time.time()
348
349 main.log.info("Total number of flows: " + str (int(main.params['CASE1000']['batches']) *\
suibin zhang5c735ca2016-03-30 16:01:06 -0700350 int(main.params['CASE1000']['batchSize']) ))
suibin zhangd0f09b32016-03-29 00:57:57 -0700351 main.log.info("Sum of each DELETE elapse time: " + str(numpy.sum(rmTimes)) )
suibin zhang570cb452016-03-29 19:03:15 -0700352 main.log.info("Total DELETE elapse time: " + str(tLastRemoveEnd-tStartRemove))
suibin zhang5c735ca2016-03-30 16:01:06 -0700353 main.log.info("Rate of DELETE Controller response (flows/sec): " + str(main.numFlows / (tLastRemoveEnd - tStartRemove)))
suibin zhangd0f09b32016-03-29 00:57:57 -0700354
suibin zhangdec01c52016-03-29 19:23:33 -0700355 duration = tAllRemoved - tLastRemoveEnd
suibin zhangf59d3682016-03-29 19:27:13 -0700356 main.log.info("Elapse time from end of last REST DELETE to Flows in REMOVED state: " +\
suibin zhangdec01c52016-03-29 19:23:33 -0700357 str(duration))
suibin zhang5c735ca2016-03-30 16:01:06 -0700358 main.log.info("Rate of Confirmed Batch Flow DELETE is (flows/sec): " + str( main.numFlows / duration))
suibin zhangd0f09b32016-03-29 00:57:57 -0700359
360 def CASE100(self,main):
361 from pprint import pprint
362
363 main.case( "Check to ensure onos flows." )
364
365 resp = main.ONOSrest.checkFlowsState()
suibin zhangdec01c52016-03-29 19:23:33 -0700366 #pprint(resp)
suibin zhangd0f09b32016-03-29 00:57:57 -0700367
368
369 def CASE110( self, main ):
370 '''
371 Report errors/warnings/exceptions
372 '''
373 main.log.info("Error report: \n" )
374 main.ONOSbench.logReport( main.ONOSip[ 0 ],
375 [ "INFO",
376 "FOLLOWER",
377 "WARN",
378 "flow",
379 "ERROR",
380 "Except" ],
381 "s" )
382 main.stop()
383