blob: 7fae518b9c86ea65c1673446eb4586261d6b753f [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:
242 main.log.info("Creating batch: " + str(index))
243 flowJsonBatch = main.ONOSrest.createFlowBatch( numSw = main.numSw,
244 swIndex = startSw,
245 batchSize = main.batchSize,
suibin zhangd0f09b32016-03-29 00:57:57 -0700246 batchIndex = index,
247 ingressPort = 2,
248 egressPort = 3)
suibin zhanga82fe3f2016-03-29 11:26:21 -0700249 main.flowJsonBatchList.append(flowJsonBatch)
250
251 startSw += 1
252 else:
253 startSw = 1
254
suibin zhangd0f09b32016-03-29 00:57:57 -0700255
256 main.step("Using REST API /flows/{} to post flow batch")
257 tStartPost = time.time()
258 for item in main.flowJsonBatchList:
259 ts = time.time()
260 resp = main.ONOSrest.sendFlowBatch(batch = item )
261 teBatch = time.time() - ts
262 postTimes.append(teBatch)
263 main.log.info("Batch Rest Post Elapse time is: " + str(teBatch))
264
265 tLastPostEnd = time.time()
266
267 main.step("Check to ensure all flows are in added state.")
268 resp = main.FALSE
269 while resp != main.TRUE:
270 resp = main.ONOSrest.checkFlowsState()
271 time.sleep(0.5)
272 tAllAdded = time.time()
273
274 numFlows = int(main.params['CASE1000']['batches']) *\
suibin zhanga82fe3f2016-03-29 11:26:21 -0700275 int(main.params['CASE1000']['batchSize'])
suibin zhangd0f09b32016-03-29 00:57:57 -0700276 main.log.info("Total number of flows: " + str (numFlows) )
277 main.log.info("Sum of each POST elapse time: " + str(numpy.sum(postTimes)) )
278 main.log.info("Total POST elapse time: " + str(tLastPostEnd-tStartPost))
279
280 duration = tAllAdded - tLastPostEnd
281 main.log.info("Elapse time from end of last REST POST to Flows in ADDED state: " +\
282 str(duration))
283 main.log.info("Rate of Batch Flow add is (flows/sec): " + str( numFlows / duration))
284
285 def CASE2000(self, main):
286 import time
287 import numpy
288
289 rmTimes = []
290
291 main.case("Remove flow timing")
292
293 tStartRemove = time.time()
294 for item in main.flowJsonBatchList:
295 ts = time.time()
296 resp = main.ONOSrest.removeFlowBatch(batch = item )
297 teBatch = time.time() - ts
298 rmTimes.append(teBatch)
299 main.log.info("Batch Rest Remove Elapse time is: " + str(teBatch))
300
301 tLastRemoveEnd = time.time()
302
303 main.step("Check to ensure all flows are in added state.")
304 resp = main.FALSE
305 while resp != main.TRUE:
306 resp = main.ONOSrest.checkFlowsState()
307 time.sleep(0.5)
308 tAllRemoved = time.time()
309
310 main.log.info("Total number of flows: " + str (int(main.params['CASE1000']['batches']) *\
suibin zhanga82fe3f2016-03-29 11:26:21 -0700311 int(main.params['CASE1000']['batchSize']) *\
suibin zhangd0f09b32016-03-29 00:57:57 -0700312 int(main.params['CASE10']['numSw'])) )
313 main.log.info("Sum of each DELETE elapse time: " + str(numpy.sum(rmTimes)) )
314 main.log.info("Total POST elapse time: " + str(tLastRemoveEnd-tStartRemove))
315
316 main.log.info("Elapse time from end of last REST POST to Flows in ADDED state: " +\
317 str(tAllRemoved - tLastRemoveEnd))
318
319 def CASE100(self,main):
320 from pprint import pprint
321
322 main.case( "Check to ensure onos flows." )
323
324 resp = main.ONOSrest.checkFlowsState()
325 pprint(resp)
326
327
328 def CASE110( self, main ):
329 '''
330 Report errors/warnings/exceptions
331 '''
332 main.log.info("Error report: \n" )
333 main.ONOSbench.logReport( main.ONOSip[ 0 ],
334 [ "INFO",
335 "FOLLOWER",
336 "WARN",
337 "flow",
338 "ERROR",
339 "Except" ],
340 "s" )
341 main.stop()
342