blob: 65431f2530d0e2e883dd788a2095334b4ab415cd [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
107 main.ONOSbench.createCellFile( main.ONOSbench.ip_address, "temp", main.Mininet1.ip_address, main.apps, tempOnosIp )
108
109 main.step( "Apply cell to environment" )
110 cellResult = main.ONOSbench.setCell( "temp" )
111 verifyResult = main.ONOSbench.verifyCell()
112 stepResult = cellResult and verifyResult
113 utilities.assert_equals( expect=main.TRUE,
114 actual=stepResult,
115 onpass="Successfully applied cell to " + \
116 "environment",
117 onfail="Failed to apply cell to environment " )
118
119 main.step( "Creating ONOS package" )
suibin zhang570cb452016-03-29 19:03:15 -0700120 packageResult = main.ONOSbench.onosPackage(opTimeout=120)
suibin zhangd0f09b32016-03-29 00:57:57 -0700121 stepResult = packageResult
122 utilities.assert_equals( expect=main.TRUE,
123 actual=stepResult,
124 onpass="Successfully created ONOS package",
125 onfail="Failed to create ONOS package" )
126
127 time.sleep( main.startUpSleep )
128 main.step( "Uninstalling ONOS package" )
129 onosUninstallResult = main.TRUE
130 for i in range( main.numCtrls ):
131 onosUninstallResult = onosUninstallResult and \
132 main.ONOSbench.onosUninstall( nodeIp=main.ONOSip[ i ] )
133 stepResult = onosUninstallResult
134 utilities.assert_equals( expect=main.TRUE,
135 actual=stepResult,
136 onpass="Successfully uninstalled ONOS package",
137 onfail="Failed to uninstall ONOS package" )
138
139 time.sleep( main.startUpSleep )
140 main.step( "Installing ONOS package" )
141 onosInstallResult = main.TRUE
142 for i in range( main.numCtrls ):
143 onosInstallResult = onosInstallResult and \
144 main.ONOSbench.onosInstall( node=main.ONOSip[ i ] )
145 stepResult = onosInstallResult
146 utilities.assert_equals( expect=main.TRUE,
147 actual=stepResult,
148 onpass="Successfully installed ONOS package",
149 onfail="Failed to install ONOS package" )
150
151 time.sleep( main.startUpSleep )
152 main.step( "Starting ONOS service" )
153 stopResult = main.TRUE
154 startResult = main.TRUE
155 onosIsUp = main.TRUE
156
157 for i in range( main.numCtrls ):
158 onosIsUp = onosIsUp and main.ONOSbench.isup( main.ONOSip[ i ] )
159 if onosIsUp == main.TRUE:
160 main.log.report( "ONOS instance is up and ready" )
161 else:
162 main.log.report( "ONOS instance may not be up, stop and " +
163 "start ONOS again " )
164 for i in range( main.numCtrls ):
165 stopResult = stopResult and \
166 main.ONOSbench.onosStop( main.ONOSip[ i ] )
167 for i in range( main.numCtrls ):
168 startResult = startResult and \
169 main.ONOSbench.onosStart( main.ONOSip[ i ] )
170 stepResult = onosIsUp and stopResult and startResult
171 utilities.assert_equals( expect=main.TRUE,
172 actual=stepResult,
173 onpass="ONOS service is ready",
174 onfail="ONOS service did not start properly" )
175
suibin zhangd0f09b32016-03-29 00:57:57 -0700176
177 def CASE10( self, main ):
178 '''
179 Start Mininet
180 '''
181 import json
182
183 main.numSw = int(main.params['CASE10']['numSw'])
184 main.case( "Setup mininet and compare ONOS topology view to Mininet topology" )
185 main.caseExplanation = "Start mininet with custom topology and compare topology " +\
186 "elements between Mininet and ONOS"
187
188 main.step( "Setup Mininet Linear Topology with " + str(main.numSw) + " switches" )
189 stepResult = main.Mininet1.startNet( args = main.params['CASE10']['mnArgs'] )
190
191 utilities.assert_equals( expect=main.TRUE,
192 actual=stepResult,
193 onpass="Successfully loaded topology",
194 onfail="Failed to load topology" )
195
196 main.step( "Assign switches to controller" )
197 for i in range(1, main.numSw + 1):
198 main.Mininet1.assignSwController( "s" + str(i), main.ONOSip[0] )
199
200 utilities.assert_equals( expect=main.TRUE,
201 actual=stepResult,
202 onpass="Successfully assigned switch to controller",
203 onfail="Failed to assign switch to controller" )
204
205 time.sleep( main.startMNSleep )
206
207
208
209
210 def CASE1000( self, main ):
211 '''
212 create JSON object with batched flows
213 '''
214 import numpy
215 import time
suibin zhang570cb452016-03-29 19:03:15 -0700216 from pprint import pprint
suibin zhangd0f09b32016-03-29 00:57:57 -0700217
218 main.case( "Create a json object for the batched flows" )
219
220 main.step( "Parse batch information" )
suibin zhanga82fe3f2016-03-29 11:26:21 -0700221 main.batchSize = int(main.params['CASE1000']['batchSize'])
222 main.log.info("Number of flows in a batch is:" + str(main.batchSize))
suibin zhangd0f09b32016-03-29 00:57:57 -0700223
224 main.flowJsonBatchList = []
suibin zhang570cb452016-03-29 19:03:15 -0700225 main.addedBatchList = []
suibin zhangd0f09b32016-03-29 00:57:57 -0700226 postTimes = []
suibin zhanga82fe3f2016-03-29 11:26:21 -0700227 startSw = 1
suibin zhangd0f09b32016-03-29 00:57:57 -0700228
229 main.step("Creating a full list of batches")
230 for index in range(1, int(main.params['CASE1000']['batches']) + 1):
suibin zhanga82fe3f2016-03-29 11:26:21 -0700231 if startSw <= main.numSw:
suibin zhangff4abfe2016-03-29 11:52:08 -0700232 ind = startSw
233 else:
234 startSw = 1
235 ind = startSw
236
237 main.log.info("Creating batch: " + str(index))
238 flowJsonBatch = main.ONOSrest.createFlowBatch( numSw = main.numSw,
239 swIndex = ind,
suibin zhanga82fe3f2016-03-29 11:26:21 -0700240 batchSize = main.batchSize,
suibin zhangd0f09b32016-03-29 00:57:57 -0700241 batchIndex = index,
242 ingressPort = 2,
243 egressPort = 3)
suibin zhangff4abfe2016-03-29 11:52:08 -0700244 main.flowJsonBatchList.append(flowJsonBatch)
suibin zhanga82fe3f2016-03-29 11:26:21 -0700245
suibin zhangff4abfe2016-03-29 11:52:08 -0700246 startSw += 1
247
suibin zhanga82fe3f2016-03-29 11:26:21 -0700248
suibin zhangd0f09b32016-03-29 00:57:57 -0700249
250 main.step("Using REST API /flows/{} to post flow batch")
251 tStartPost = time.time()
252 for item in main.flowJsonBatchList:
253 ts = time.time()
suibin zhang570cb452016-03-29 19:03:15 -0700254 status, response = main.ONOSrest.sendFlowBatch(batch = item )
suibin zhangd0f09b32016-03-29 00:57:57 -0700255 teBatch = time.time() - ts
256 postTimes.append(teBatch)
257 main.log.info("Batch Rest Post Elapse time is: " + str(teBatch))
suibin zhang570cb452016-03-29 19:03:15 -0700258 main.addedBatchList.append(response[1])
suibin zhangd0f09b32016-03-29 00:57:57 -0700259
260 tLastPostEnd = time.time()
261
262 main.step("Check to ensure all flows are in added state.")
suibin zhang570cb452016-03-29 19:03:15 -0700263 pprint(main.addedBatchList)
suibin zhangd0f09b32016-03-29 00:57:57 -0700264 resp = main.FALSE
265 while resp != main.TRUE:
266 resp = main.ONOSrest.checkFlowsState()
267 time.sleep(0.5)
268 tAllAdded = time.time()
269
suibin zhangdec01c52016-03-29 19:23:33 -0700270 main.numFlows = int(main.params['CASE1000']['batches']) *\
suibin zhanga82fe3f2016-03-29 11:26:21 -0700271 int(main.params['CASE1000']['batchSize'])
suibin zhangdec01c52016-03-29 19:23:33 -0700272 main.log.info("Total number of flows: " + str (main.numFlows) )
suibin zhangd0f09b32016-03-29 00:57:57 -0700273 main.log.info("Sum of each POST elapse time: " + str(numpy.sum(postTimes)) )
274 main.log.info("Total POST elapse time: " + str(tLastPostEnd-tStartPost))
suibin zhangdec01c52016-03-29 19:23:33 -0700275 main.log.info("Rate of ADD Controller response: " + str(main.numFlows / (tLastPostEnd - tStartPost)))
suibin zhangd0f09b32016-03-29 00:57:57 -0700276
277 duration = tAllAdded - tLastPostEnd
278 main.log.info("Elapse time from end of last REST POST to Flows in ADDED state: " +\
279 str(duration))
suibin zhangdec01c52016-03-29 19:23:33 -0700280 main.log.info("Rate of Batch Flow add is (flows/sec): " + str( main.numFlows / duration))
suibin zhangd0f09b32016-03-29 00:57:57 -0700281
282 def CASE2000(self, main):
283 import time
284 import numpy
suibin zhang570cb452016-03-29 19:03:15 -0700285 import json
suibin zhangd0f09b32016-03-29 00:57:57 -0700286
287 rmTimes = []
288
289 main.case("Remove flow timing")
290
291 tStartRemove = time.time()
suibin zhang570cb452016-03-29 19:03:15 -0700292 for item in main.addedBatchList:
suibin zhangd0f09b32016-03-29 00:57:57 -0700293 ts = time.time()
suibin zhang570cb452016-03-29 19:03:15 -0700294 print(item)
295 resp = main.ONOSrest.removeFlowBatch(batch = json.loads(item) )
suibin zhangd0f09b32016-03-29 00:57:57 -0700296 teBatch = time.time() - ts
297 rmTimes.append(teBatch)
298 main.log.info("Batch Rest Remove Elapse time is: " + str(teBatch))
299
300 tLastRemoveEnd = time.time()
301
302 main.step("Check to ensure all flows are in added state.")
303 resp = main.FALSE
304 while resp != main.TRUE:
305 resp = main.ONOSrest.checkFlowsState()
306 time.sleep(0.5)
307 tAllRemoved = time.time()
308
309 main.log.info("Total number of flows: " + str (int(main.params['CASE1000']['batches']) *\
suibin zhanga82fe3f2016-03-29 11:26:21 -0700310 int(main.params['CASE1000']['batchSize']) *\
suibin zhangd0f09b32016-03-29 00:57:57 -0700311 int(main.params['CASE10']['numSw'])) )
312 main.log.info("Sum of each DELETE elapse time: " + str(numpy.sum(rmTimes)) )
suibin zhang570cb452016-03-29 19:03:15 -0700313 main.log.info("Total DELETE elapse time: " + str(tLastRemoveEnd-tStartRemove))
suibin zhangdec01c52016-03-29 19:23:33 -0700314 main.log.info("Rate of ADD Controller response: " + str(main.numFlows / (tLastRemoveEnd - tStartRemove)))
suibin zhangd0f09b32016-03-29 00:57:57 -0700315
suibin zhangdec01c52016-03-29 19:23:33 -0700316 duration = tAllRemoved - tLastRemoveEnd
317 main.log.info("Elapse time from end of last REST POST to Flows in ADDED state: " +\
318 str(duration))
319 main.log.info("Rate of Batch Flow add is (flows/sec): " + str( main.numFlows / duration))
suibin zhangd0f09b32016-03-29 00:57:57 -0700320
321 def CASE100(self,main):
322 from pprint import pprint
323
324 main.case( "Check to ensure onos flows." )
325
326 resp = main.ONOSrest.checkFlowsState()
suibin zhangdec01c52016-03-29 19:23:33 -0700327 #pprint(resp)
suibin zhangd0f09b32016-03-29 00:57:57 -0700328
329
330 def CASE110( self, main ):
331 '''
332 Report errors/warnings/exceptions
333 '''
334 main.log.info("Error report: \n" )
335 main.ONOSbench.logReport( main.ONOSip[ 0 ],
336 [ "INFO",
337 "FOLLOWER",
338 "WARN",
339 "flow",
340 "ERROR",
341 "Except" ],
342 "s" )
343 main.stop()
344