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