blob: 45e4de554022d3f9c952dbe1b63b218f62c6c248 [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
100 for i in range( main.maxNodes ):
101 main.ONOSbench.onosDie( main.ONOSip[ i ] )
102
103 print "NODE COUNT = ", main.numCtrls
104
105 tempOnosIp = []
106 for i in range( main.numCtrls ):
107 tempOnosIp.append( main.ONOSip[i] )
108
109 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
121 main.step( "Creating ONOS package" )
122 packageResult = main.ONOSbench.onosPackage(opTimeout=30)
123 stepResult = packageResult
124 utilities.assert_equals( expect=main.TRUE,
125 actual=stepResult,
126 onpass="Successfully created ONOS package",
127 onfail="Failed to create ONOS package" )
128
129 time.sleep( main.startUpSleep )
130 main.step( "Uninstalling ONOS package" )
131 onosUninstallResult = main.TRUE
132 for i in range( main.numCtrls ):
133 onosUninstallResult = onosUninstallResult and \
134 main.ONOSbench.onosUninstall( nodeIp=main.ONOSip[ i ] )
135 stepResult = onosUninstallResult
136 utilities.assert_equals( expect=main.TRUE,
137 actual=stepResult,
138 onpass="Successfully uninstalled ONOS package",
139 onfail="Failed to uninstall ONOS package" )
140
141 time.sleep( main.startUpSleep )
142 main.step( "Installing ONOS package" )
143 onosInstallResult = main.TRUE
144 for i in range( main.numCtrls ):
145 onosInstallResult = onosInstallResult and \
146 main.ONOSbench.onosInstall( node=main.ONOSip[ i ] )
147 stepResult = onosInstallResult
148 utilities.assert_equals( expect=main.TRUE,
149 actual=stepResult,
150 onpass="Successfully installed ONOS package",
151 onfail="Failed to install ONOS package" )
152
153 time.sleep( main.startUpSleep )
154 main.step( "Starting ONOS service" )
155 stopResult = main.TRUE
156 startResult = main.TRUE
157 onosIsUp = main.TRUE
158
159 for i in range( main.numCtrls ):
160 onosIsUp = onosIsUp and main.ONOSbench.isup( main.ONOSip[ i ] )
161 if onosIsUp == main.TRUE:
162 main.log.report( "ONOS instance is up and ready" )
163 else:
164 main.log.report( "ONOS instance may not be up, stop and " +
165 "start ONOS again " )
166 for i in range( main.numCtrls ):
167 stopResult = stopResult and \
168 main.ONOSbench.onosStop( main.ONOSip[ i ] )
169 for i in range( main.numCtrls ):
170 startResult = startResult and \
171 main.ONOSbench.onosStart( main.ONOSip[ i ] )
172 stepResult = onosIsUp and stopResult and startResult
173 utilities.assert_equals( expect=main.TRUE,
174 actual=stepResult,
175 onpass="ONOS service is ready",
176 onfail="ONOS service did not start properly" )
177
178 main.step( "Start ONOS cli" )
179 cliResult = main.TRUE
180 for i in range( main.numCtrls ):
181 cliResult = cliResult and \
182 main.CLIs[ i ].startOnosCli( main.ONOSip[ i ], onosStartTimeout=30 )
183 stepResult = cliResult
184 utilities.assert_equals( expect=main.TRUE,
185 actual=stepResult,
186 onpass="Successfully start ONOS cli",
187 onfail="Failed to start ONOS cli" )
188
189 def CASE10( self, main ):
190 '''
191 Start Mininet
192 '''
193 import json
194
195 main.numSw = int(main.params['CASE10']['numSw'])
196 main.case( "Setup mininet and compare ONOS topology view to Mininet topology" )
197 main.caseExplanation = "Start mininet with custom topology and compare topology " +\
198 "elements between Mininet and ONOS"
199
200 main.step( "Setup Mininet Linear Topology with " + str(main.numSw) + " switches" )
201 stepResult = main.Mininet1.startNet( args = main.params['CASE10']['mnArgs'] )
202
203 utilities.assert_equals( expect=main.TRUE,
204 actual=stepResult,
205 onpass="Successfully loaded topology",
206 onfail="Failed to load topology" )
207
208 main.step( "Assign switches to controller" )
209 for i in range(1, main.numSw + 1):
210 main.Mininet1.assignSwController( "s" + str(i), main.ONOSip[0] )
211
212 utilities.assert_equals( expect=main.TRUE,
213 actual=stepResult,
214 onpass="Successfully assigned switch to controller",
215 onfail="Failed to assign switch to controller" )
216
217 time.sleep( main.startMNSleep )
218
219
220
221
222 def CASE1000( self, main ):
223 '''
224 create JSON object with batched flows
225 '''
226 import numpy
227 import time
228
229 main.case( "Create a json object for the batched flows" )
230
231 main.step( "Parse batch information" )
suibin zhanga82fe3f2016-03-29 11:26:21 -0700232 main.batchSize = int(main.params['CASE1000']['batchSize'])
233 main.log.info("Number of flows in a batch is:" + str(main.batchSize))
suibin zhangd0f09b32016-03-29 00:57:57 -0700234
235 main.flowJsonBatchList = []
236 postTimes = []
suibin zhanga82fe3f2016-03-29 11:26:21 -0700237 startSw = 1
suibin zhangd0f09b32016-03-29 00:57:57 -0700238
239 main.step("Creating a full list of batches")
240 for index in range(1, int(main.params['CASE1000']['batches']) + 1):
suibin zhanga82fe3f2016-03-29 11:26:21 -0700241 if startSw <= main.numSw:
suibin zhangff4abfe2016-03-29 11:52:08 -0700242 ind = startSw
243 else:
244 startSw = 1
245 ind = startSw
246
247 main.log.info("Creating batch: " + str(index))
248 flowJsonBatch = main.ONOSrest.createFlowBatch( numSw = main.numSw,
249 swIndex = ind,
suibin zhanga82fe3f2016-03-29 11:26:21 -0700250 batchSize = main.batchSize,
suibin zhangd0f09b32016-03-29 00:57:57 -0700251 batchIndex = index,
252 ingressPort = 2,
253 egressPort = 3)
suibin zhangff4abfe2016-03-29 11:52:08 -0700254 main.flowJsonBatchList.append(flowJsonBatch)
suibin zhanga82fe3f2016-03-29 11:26:21 -0700255
suibin zhangff4abfe2016-03-29 11:52:08 -0700256 startSw += 1
257
suibin zhanga82fe3f2016-03-29 11:26:21 -0700258
suibin zhangd0f09b32016-03-29 00:57:57 -0700259
260 main.step("Using REST API /flows/{} to post flow batch")
261 tStartPost = time.time()
262 for item in main.flowJsonBatchList:
263 ts = time.time()
264 resp = main.ONOSrest.sendFlowBatch(batch = item )
265 teBatch = time.time() - ts
266 postTimes.append(teBatch)
267 main.log.info("Batch Rest Post Elapse time is: " + str(teBatch))
268
269 tLastPostEnd = time.time()
270
271 main.step("Check to ensure all flows are in added state.")
272 resp = main.FALSE
273 while resp != main.TRUE:
274 resp = main.ONOSrest.checkFlowsState()
275 time.sleep(0.5)
276 tAllAdded = time.time()
277
278 numFlows = int(main.params['CASE1000']['batches']) *\
suibin zhanga82fe3f2016-03-29 11:26:21 -0700279 int(main.params['CASE1000']['batchSize'])
suibin zhangd0f09b32016-03-29 00:57:57 -0700280 main.log.info("Total number of flows: " + str (numFlows) )
281 main.log.info("Sum of each POST elapse time: " + str(numpy.sum(postTimes)) )
282 main.log.info("Total POST elapse time: " + str(tLastPostEnd-tStartPost))
283
284 duration = tAllAdded - tLastPostEnd
285 main.log.info("Elapse time from end of last REST POST to Flows in ADDED state: " +\
286 str(duration))
287 main.log.info("Rate of Batch Flow add is (flows/sec): " + str( numFlows / duration))
288
289 def CASE2000(self, main):
290 import time
291 import numpy
292
293 rmTimes = []
294
295 main.case("Remove flow timing")
296
297 tStartRemove = time.time()
298 for item in main.flowJsonBatchList:
299 ts = time.time()
300 resp = main.ONOSrest.removeFlowBatch(batch = item )
301 teBatch = time.time() - ts
302 rmTimes.append(teBatch)
303 main.log.info("Batch Rest Remove Elapse time is: " + str(teBatch))
304
305 tLastRemoveEnd = time.time()
306
307 main.step("Check to ensure all flows are in added state.")
308 resp = main.FALSE
309 while resp != main.TRUE:
310 resp = main.ONOSrest.checkFlowsState()
311 time.sleep(0.5)
312 tAllRemoved = time.time()
313
314 main.log.info("Total number of flows: " + str (int(main.params['CASE1000']['batches']) *\
suibin zhanga82fe3f2016-03-29 11:26:21 -0700315 int(main.params['CASE1000']['batchSize']) *\
suibin zhangd0f09b32016-03-29 00:57:57 -0700316 int(main.params['CASE10']['numSw'])) )
317 main.log.info("Sum of each DELETE elapse time: " + str(numpy.sum(rmTimes)) )
318 main.log.info("Total POST elapse time: " + str(tLastRemoveEnd-tStartRemove))
319
320 main.log.info("Elapse time from end of last REST POST to Flows in ADDED state: " +\
321 str(tAllRemoved - tLastRemoveEnd))
322
323 def CASE100(self,main):
324 from pprint import pprint
325
326 main.case( "Check to ensure onos flows." )
327
328 resp = main.ONOSrest.checkFlowsState()
329 pprint(resp)
330
331
332 def CASE110( self, main ):
333 '''
334 Report errors/warnings/exceptions
335 '''
336 main.log.info("Error report: \n" )
337 main.ONOSbench.logReport( main.ONOSip[ 0 ],
338 [ "INFO",
339 "FOLLOWER",
340 "WARN",
341 "flow",
342 "ERROR",
343 "Except" ],
344 "s" )
345 main.stop()
346