blob: d2a55bb0116ec47fc6f70e46951b1b8f40d51956 [file] [log] [blame]
suibin zhang17308622016-04-14 15:45:30 -07001class SCPFbatchFlowResp:
Jon Hall5c3ff722017-05-24 17:24:59 -07002
3 """
suibin zhang17308622016-04-14 15:45:30 -07004 Testing end-to-end ONOS response time from POST of batched flows to when ONOS returns
5 response confirmation of all flows ADDED; subsequently testing the response time from when REST DELETE to
6 ONOS confirmation of all flows REMOVED.
Jon Hall5c3ff722017-05-24 17:24:59 -07007 """
suibin zhang17308622016-04-14 15:45:30 -07008 def __init__( self ):
9 self.default = ''
10
11 def CASE1( self, main ):
12 import time
13 import os
14 import imp
15
16 """
17 - Construct tests variables
18 - GIT ( optional )
19 - Checkout ONOS master branch
20 - Pull latest ONOS code
21 - Building ONOS ( optional )
22 - Install ONOS package
23 - Build ONOS package
24 """
suibin zhang17308622016-04-14 15:45:30 -070025 main.case( "Constructing test variables and building ONOS package" )
26 main.step( "Constructing test variables" )
27
28 # Test variables
Jon Hall5c3ff722017-05-24 17:24:59 -070029 main.testOnDirectory = os.path.dirname( os.getcwd() )
suibin zhang17308622016-04-14 15:45:30 -070030 main.cellName = main.params[ 'CASE1' ][ 'cellName' ]
31 main.apps = main.params[ 'CASE1' ][ 'cellApps' ]
32 gitBranch = main.params[ 'CASE1' ][ 'gitBranch' ]
33 gitPull = main.params[ 'CASE1' ][ 'gitPull' ]
Jon Hall5c3ff722017-05-24 17:24:59 -070034 main.maxNodes = int( main.params[ 'GLOBAL' ][ 'maxNodes' ] )
35 main.startUpSleep = float( main.params[ 'GLOBAL' ][ 'SLEEP' ][ 'startup' ] )
36 main.startMNSleep = float( main.params[ 'GLOBAL' ][ 'SLEEP' ][ 'startMN' ] )
37 main.addFlowSleep = float( main.params[ 'GLOBAL' ][ 'SLEEP' ][ 'addFlow' ] )
38 main.delFlowSleep = float( main.params[ 'GLOBAL' ][ 'SLEEP' ][ 'delFlow' ] )
39 main.chkFlowSleep = float( main.params[ 'GLOBAL' ][ 'SLEEP' ][ 'chkFlow' ] )
40 main.cfgSleep = float( main.params[ 'GLOBAL' ][ 'SLEEP' ][ 'cfg' ] )
41 main.numSw = int( main.params[ 'GLOBAL' ][ 'numSw' ] )
42 main.numThreads = int( main.params[ 'GLOBAL' ][ 'numThreads' ] )
43 main.cellData = {} # for creating cell file
suibin zhang17308622016-04-14 15:45:30 -070044 main.CLIs = []
45 main.ONOSip = []
YPZhang28909bc2016-06-20 13:29:11 -070046
suibin zhang17308622016-04-14 15:45:30 -070047 main.ONOSip = main.ONOSbench.getOnosIps()
48 main.commit = main.ONOSbench.getVersion()
Jon Hall5c3ff722017-05-24 17:24:59 -070049 main.commit = main.commit.split( " " )[ 1 ]
YPZhang28909bc2016-06-20 13:29:11 -070050
Jon Hall5c3ff722017-05-24 17:24:59 -070051 main.cluster = main.params[ 'GLOBAL' ][ 'cluster' ]
suibin zhang17308622016-04-14 15:45:30 -070052
53 # Assigning ONOS cli handles to a list
Jon Hall5c3ff722017-05-24 17:24:59 -070054 for i in range( 1, main.maxNodes + 1 ):
suibin zhang17308622016-04-14 15:45:30 -070055 main.CLIs.append( getattr( main, 'ONOScli' + str( i ) ) )
56
suibin zhang17308622016-04-14 15:45:30 -070057 if main.CLIs:
58 stepResult = main.TRUE
59 else:
60 main.log.error( "Did not properly created list of ONOS CLI handle" )
61 stepResult = main.FALSE
62
63 utilities.assert_equals( expect=main.TRUE,
64 actual=stepResult,
65 onpass="Successfully construct " +
66 "test variables ",
67 onfail="Failed to construct test variables" )
68
suibin zhang17308622016-04-14 15:45:30 -070069
70 def CASE2( self, main ):
71 """
72 - Set up cell
73 - Create cell file
74 - Set cell file
75 - Verify cell file
76 - Kill ONOS process
77 - Uninstall ONOS cluster
78 - Verify ONOS start up
79 - Install ONOS cluster
80 - Connect to cli
81 """
suibin zhang17308622016-04-14 15:45:30 -070082 main.numCtrls = int( main.maxNodes )
83
84 main.case( "Starting up " + str( main.numCtrls ) +
Jon Hall5c3ff722017-05-24 17:24:59 -070085 " node( s ) ONOS cluster" )
suibin zhang17308622016-04-14 15:45:30 -070086
87 main.log.info( "Safety check, killing all ONOS processes" +
88 " before initiating environment setup" )
89
90 tempOnosIp = []
91 for i in range( main.numCtrls ):
Jon Hall5c3ff722017-05-24 17:24:59 -070092 tempOnosIp.append( main.ONOSip[ i ] )
suibin zhang17308622016-04-14 15:45:30 -070093
Jon Hall5c3ff722017-05-24 17:24:59 -070094 if main.params[ 'CASE2' ][ 'incPackaging' ] == "true":
95 main.step( "Create onos cell file with: " + main.apps )
suibin zhang17308622016-04-14 15:45:30 -070096 main.ONOSbench.createCellFile( main.ONOSbench.ip_address, "temp",
Devin Lim461f0872017-06-05 16:49:33 -070097 main.Mininet1.ip_address, main.apps,
Devin Limdc78e202017-06-09 18:30:07 -070098 tempOnosIp, main.ONOScli1.karafUser )
suibin zhang17308622016-04-14 15:45:30 -070099
100 main.step( "Apply cell to environment" )
101 cellResult = main.ONOSbench.setCell( "temp" )
102 verifyResult = main.ONOSbench.verifyCell()
103 stepResult = cellResult and verifyResult
104 utilities.assert_equals( expect=main.TRUE,
Jon Hall5c3ff722017-05-24 17:24:59 -0700105 actual=stepResult,
106 onpass="Successfully applied cell to " +
suibin zhang17308622016-04-14 15:45:30 -0700107 "environment",
Jon Hall5c3ff722017-05-24 17:24:59 -0700108 onfail="Failed to apply cell to environment " )
suibin zhang17308622016-04-14 15:45:30 -0700109
110 main.step( "Creating ONOS package" )
Jon Hallbd60ea02016-08-23 10:03:59 -0700111 packageResult = main.ONOSbench.buckBuild()
suibin zhang17308622016-04-14 15:45:30 -0700112 stepResult = packageResult
113 utilities.assert_equals( expect=main.TRUE,
Jon Hall5c3ff722017-05-24 17:24:59 -0700114 actual=stepResult,
115 onpass="Successfully created ONOS package",
116 onfail="Failed to create ONOS package" )
suibin zhang17308622016-04-14 15:45:30 -0700117 time.sleep( main.startUpSleep )
118
119 main.step( "Uninstalling ONOS package" )
120 onosUninstallResult = main.TRUE
121 for i in range( main.numCtrls ):
122 onosUninstallResult = onosUninstallResult and \
123 main.ONOSbench.onosUninstall( nodeIp=main.ONOSip[ i ] )
124 stepResult = onosUninstallResult
125 utilities.assert_equals( expect=main.TRUE,
Jon Hall5c3ff722017-05-24 17:24:59 -0700126 actual=stepResult,
127 onpass="Successfully uninstalled ONOS package",
128 onfail="Failed to uninstall ONOS package" )
suibin zhang17308622016-04-14 15:45:30 -0700129 time.sleep( main.startUpSleep )
130
131 else:
Jon Hall5c3ff722017-05-24 17:24:59 -0700132 main.log.info( "onos Packaging Skipped!" )
suibin zhang17308622016-04-14 15:45:30 -0700133
134 main.step( "Installing ONOS package" )
135 onosInstallResult = main.TRUE
136 for i in range( main.numCtrls ):
137 onosInstallResult = onosInstallResult and \
138 main.ONOSbench.onosInstall( node=main.ONOSip[ i ] )
139 stepResult = onosInstallResult
140 utilities.assert_equals( expect=main.TRUE,
141 actual=stepResult,
142 onpass="Successfully installed ONOS package",
143 onfail="Failed to install ONOS package" )
144 time.sleep( main.startUpSleep )
145
You Wang52590212017-05-04 17:35:20 -0700146 main.step( "Set up ONOS secure SSH" )
147 secureSshResult = main.TRUE
148 for i in range( main.numCtrls ):
149 secureSshResult = secureSshResult and main.ONOSbench.onosSecureSSH( node=main.ONOSip[ i ] )
150 utilities.assert_equals( expect=main.TRUE, actual=secureSshResult,
151 onpass="Test step PASS",
152 onfail="Test step FAIL" )
153
154 time.sleep( main.startUpSleep )
suibin zhang17308622016-04-14 15:45:30 -0700155 main.step( "Starting ONOS service" )
156 stopResult = main.TRUE
157 startResult = main.TRUE
158 onosIsUp = main.TRUE
159
160 for i in range( main.numCtrls ):
161 onosIsUp = onosIsUp and main.ONOSbench.isup( main.ONOSip[ i ] )
162 if onosIsUp == main.TRUE:
163 main.log.report( "ONOS instance is up and ready" )
164 else:
165 main.log.report( "ONOS instance may not be up, stop and " +
166 "start ONOS again " )
167 for i in range( main.numCtrls ):
168 stopResult = stopResult and \
169 main.ONOSbench.onosStop( main.ONOSip[ i ] )
170 for i in range( main.numCtrls ):
171 startResult = startResult and \
172 main.ONOSbench.onosStart( main.ONOSip[ i ] )
173 stepResult = onosIsUp and stopResult and startResult
174 utilities.assert_equals( expect=main.TRUE,
175 actual=stepResult,
176 onpass="ONOS service is ready",
177 onfail="ONOS service did not start properly" )
178
179 main.step( "Start ONOS cli" )
180 cliResult = main.TRUE
181 for i in range( i, main.numCtrls ):
182 cliResult = cliResult and \
You Wang52590212017-05-04 17:35:20 -0700183 main.ONOScli1.startOnosCli( main.ONOSip[ i ] )
suibin zhang17308622016-04-14 15:45:30 -0700184 stepResult = cliResult
185 utilities.assert_equals( expect=main.TRUE,
186 actual=stepResult,
187 onpass="Successfully start ONOS cli",
188 onfail="Failed to start ONOS cli" )
189
suibin zhang17308622016-04-14 15:45:30 -0700190 def CASE10( self, main ):
Jon Hall5c3ff722017-05-24 17:24:59 -0700191 """
suibin zhang17308622016-04-14 15:45:30 -0700192 Start Mininet
Jon Hall5c3ff722017-05-24 17:24:59 -0700193 """
suibin zhang17308622016-04-14 15:45:30 -0700194 import time
195
196 main.case( "Enable openflow-base on onos and start Mininet." )
197
Jon Hall5c3ff722017-05-24 17:24:59 -0700198 main.step( "Activate openflow-base App" )
199 app = main.params[ 'CASE10' ][ 'app' ]
YPZhang5d0552f2016-05-18 13:02:52 -0700200 stepResult = main.ONOScli1.activateApp( app )
Jon Hall5c3ff722017-05-24 17:24:59 -0700201 time.sleep( main.cfgSleep )
202 main.log.info( stepResult )
suibin zhang17308622016-04-14 15:45:30 -0700203 utilities.assert_equals( expect=main.TRUE,
204 actual=stepResult,
205 onpass="Successfully activate " + app,
206 onfail="Failed to activate app " + app )
207
Jon Hall5c3ff722017-05-24 17:24:59 -0700208 time.sleep( main.cfgSleep )
suibin zhang17308622016-04-14 15:45:30 -0700209
Jon Hall5c3ff722017-05-24 17:24:59 -0700210 main.step( "Configure AdaptiveFlowSampling " )
211 stepResult = main.ONOScli1.setCfg( component="org.onosproject.provider.of.flow.impl.OpenFlowRuleProvider",
212 propName="adaptiveFlowSampling ", value=main.params[ 'CASE10' ][ 'adaptiveFlowenabled' ] )
suibin zhang17308622016-04-14 15:45:30 -0700213 utilities.assert_equals( expect=main.TRUE,
214 actual=stepResult,
215 onpass="App Configuration Succeeded! ",
216 onfail="App Configuration Failed!" )
Jon Hall5c3ff722017-05-24 17:24:59 -0700217 time.sleep( main.cfgSleep )
suibin zhang17308622016-04-14 15:45:30 -0700218
Jon Hall5c3ff722017-05-24 17:24:59 -0700219 main.step( "Setup Mininet Linear Topology with " + str( main.numSw ) + " switches" )
220 argStr = main.params[ 'CASE10' ][ 'mnArgs' ].format( main.numSw )
221 stepResult = main.Mininet1.startNet( args=argStr )
suibin zhang17308622016-04-14 15:45:30 -0700222
223 utilities.assert_equals( expect=main.TRUE,
224 actual=stepResult,
225 onpass="Successfully loaded topology",
226 onfail="Failed to load topology" )
227
228 time.sleep( main.startMNSleep )
229
230 main.step( "Assign switches to controller" )
Jon Hall5c3ff722017-05-24 17:24:59 -0700231 for i in range( 1, main.numSw + 1 ):
232 main.Mininet1.assignSwController( "s" + str( i ), main.ONOSip[ 0 ] )
suibin zhang17308622016-04-14 15:45:30 -0700233
234 utilities.assert_equals( expect=main.TRUE,
235 actual=stepResult,
236 onpass="Successfully assigned switch to controller",
237 onfail="Failed to assign switch to controller" )
238
239 main.deviceIdPrefix = "of:"
240
241 time.sleep( main.startMNSleep )
242
243 def CASE11( self, main ):
Jon Hall5c3ff722017-05-24 17:24:59 -0700244 """
suibin zhang17308622016-04-14 15:45:30 -0700245 Start Null Provider
Jon Hall5c3ff722017-05-24 17:24:59 -0700246 """
suibin zhang17308622016-04-14 15:45:30 -0700247 import time
248
249 main.case( "Setup Null Provider for linear Topology" )
250
Jon Hall5c3ff722017-05-24 17:24:59 -0700251 main.step( "Activate Null Provider App" )
252 stepResult = main.ONOSbench.onosCli( ONOSIp=main.ONOSip[ 0 ],
253 cmdstr="app activate org.onosproject.null" )
suibin zhang17308622016-04-14 15:45:30 -0700254 utilities.assert_equals( expect=main.TRUE,
255 actual=stepResult,
256 onpass="Successfully activated org.onosproject.null",
257 onfail="Failed to activate org.onosproject.null" )
Jon Hall5c3ff722017-05-24 17:24:59 -0700258 time.sleep( main.cfgSleep )
suibin zhang17308622016-04-14 15:45:30 -0700259
Jon Hall5c3ff722017-05-24 17:24:59 -0700260 main.step( "Setup Null Provider Linear Topology with " + str( main.numSw ) + " devices." )
261 r1 = main.ONOSbench.onosCfgSet( main.ONOSip[ 0 ], "org.onosproject.provider.nil.NullProviders", "deviceCount " + str( main.numSw ) )
262 r2 = main.ONOSbench.onosCfgSet( main.ONOSip[ 0 ], "org.onosproject.provider.nil.NullProviders", "topoShape " + main.params[ 'CASE11' ][ 'nullTopo' ] )
263 r3 = main.ONOSbench.onosCfgSet( main.ONOSip[ 0 ], "org.onosproject.provider.nil.NullProviders", "enabled " + main.params[ 'CASE11' ][ 'nullStart' ] )
suibin zhang17308622016-04-14 15:45:30 -0700264 stepResult = r1 & r2 & r3
265 utilities.assert_equals( expect=main.TRUE,
266 actual=stepResult,
267 onpass="App Configuration Succeeded! ",
268 onfail="App Configuration Failed!" )
269 time.sleep( main.cfgSleep )
270
Jon Hall5c3ff722017-05-24 17:24:59 -0700271 main.log.info( "Check to make sure null providers are configured correctly." )
272 main.ONOSbench.handle.sendline( "onos $OC1 summary" )
273 stepResult = main.ONOSbench.handle.expect( ":~" )
274 main.log.info( "ONOS Summary: " + main.ONOSbench.handle.before )
suibin zhang17308622016-04-14 15:45:30 -0700275
276 main.deviceIdPrefix = "null:"
277
278 time.sleep( main.startMNSleep )
279
suibin zhang17308622016-04-14 15:45:30 -0700280 def CASE1000( self, main ):
Jon Hall5c3ff722017-05-24 17:24:59 -0700281 """
suibin zhang17308622016-04-14 15:45:30 -0700282 create JSON object with batched flows
Jon Hall5c3ff722017-05-24 17:24:59 -0700283 """
suibin zhang17308622016-04-14 15:45:30 -0700284 import numpy
285 import time
286 from pprint import pprint
287
288 main.case( "Create a json object for the batched flows" )
289
290 main.step( "Parse batch creation information" )
Jon Hall5c3ff722017-05-24 17:24:59 -0700291 main.batchSize = int( main.params[ 'CASE1000' ][ 'batchSize' ] )
292 main.log.info( "Number of flows in a batch is:" + str( main.batchSize ) )
suibin zhang17308622016-04-14 15:45:30 -0700293
294 main.flowJsonBatchList = []
295 startSw = 1
296
Jon Hall5c3ff722017-05-24 17:24:59 -0700297 main.step( "Creating a full list of batches" )
298 for index in range( 1, int( main.params[ 'CASE1000' ][ 'batches' ] ) + 1 ):
suibin zhang17308622016-04-14 15:45:30 -0700299 if startSw <= main.numSw:
300 ind = startSw
301 else:
302 startSw = 1
303 ind = startSw
304
Jon Hall5c3ff722017-05-24 17:24:59 -0700305 main.log.info( "Creating batch: " + str( index ) )
306 flowJsonBatch = main.ONOSrest.createFlowBatch( numSw=main.numSw,
307 swIndex=ind,
308 batchSize=main.batchSize,
309 batchIndex=index,
suibin zhang17308622016-04-14 15:45:30 -0700310 deviceIdpreFix=main.deviceIdPrefix,
Jon Hall5c3ff722017-05-24 17:24:59 -0700311 ingressPort=2,
312 egressPort=3 )
313 main.flowJsonBatchList.append( flowJsonBatch )
suibin zhang17308622016-04-14 15:45:30 -0700314
315 startSw += 1
Jon Hall5c3ff722017-05-24 17:24:59 -0700316 main.log.info( "Number of items created in the batch list is: " + str( len( main.flowJsonBatchList ) ) )
suibin zhang17308622016-04-14 15:45:30 -0700317
Jon Hall5c3ff722017-05-24 17:24:59 -0700318 def CASE2100( self, main ):
319 """
suibin zhang17308622016-04-14 15:45:30 -0700320 Posting flow batches using threads
Jon Hall5c3ff722017-05-24 17:24:59 -0700321 """
322 main.case( "Using REST API /flows/{} to post flow batch - multi-threads" )
323 main.step( "Using REST API /flows/{} to post flow batch - multi-threads" )
suibin zhang17308622016-04-14 15:45:30 -0700324
325 from Queue import Queue
326 from threading import Thread
327 import time
328 import json
329
330 main.threadID = 0
331 main.addedBatchList = []
332 q = Queue()
333 tAllAdded = 0
You Wang7b5b2262016-11-10 13:54:56 -0800334 main.postFailed = False
suibin zhang17308622016-04-14 15:45:30 -0700335
Jon Hall5c3ff722017-05-24 17:24:59 -0700336 def postWorker( id ):
suibin zhang17308622016-04-14 15:45:30 -0700337 while True:
338 item = q.get()
Jon Hall5c3ff722017-05-24 17:24:59 -0700339 #print json.dumps( item )
340 status, response = main.ONOSrest.sendFlowBatch( batch=item )
You Wang7b5b2262016-11-10 13:54:56 -0800341 if status == main.TRUE:
Jon Hall5c3ff722017-05-24 17:24:59 -0700342 main.log.info( "Thread {} is working on posting. ".format( id ) )
343 #print json.dumps( response )
344 main.addedBatchList.append( response[ 1 ] )
You Wang7b5b2262016-11-10 13:54:56 -0800345 else:
Jon Hall5c3ff722017-05-24 17:24:59 -0700346 main.log.error( "Thread {} failed to post.".format( id ) )
You Wang7b5b2262016-11-10 13:54:56 -0800347 main.postFailed = True
suibin zhang17308622016-04-14 15:45:30 -0700348 q.task_done()
349
Jon Hall5c3ff722017-05-24 17:24:59 -0700350 for i in range( int( main.params[ 'CASE2100' ][ 'numThreads' ] ) ):
351 threadID = "ThreadID-" + str( i )
352 t = Thread( target=postWorker, name=threadID, args=( threadID, ) )
suibin zhang17308622016-04-14 15:45:30 -0700353 t.daemon = True
354 t.start()
355
356 tStartPost = time.time()
357 for item in main.flowJsonBatchList:
Jon Hall5c3ff722017-05-24 17:24:59 -0700358 q.put( item )
suibin zhang17308622016-04-14 15:45:30 -0700359
360 q.join()
361 tLastPostEnd = time.time()
You Wang7b5b2262016-11-10 13:54:56 -0800362 if main.postFailed:
363 main.log.error( "Flow batch posting failed, exit test" )
364 main.cleanup()
365 main.exit()
suibin zhang17308622016-04-14 15:45:30 -0700366
Jon Hall5c3ff722017-05-24 17:24:59 -0700367 main.step( "Check to ensure all flows are in added state." )
368 #pprint( main.addedBatchList )
suibin zhang17308622016-04-14 15:45:30 -0700369 resp = main.FALSE
Jon Hall5c3ff722017-05-24 17:24:59 -0700370 while resp != main.TRUE and ( tAllAdded - tLastPostEnd < int( main.params[ 'CASE2100' ][ 'chkFlowTO' ] ) ):
371 if main.params[ 'CASE2100' ][ 'RESTchkFlow' ] == 'main.TRUE':
suibin zhang17308622016-04-14 15:45:30 -0700372 resp = main.ONOSrest.checkFlowsState()
373 else:
Jon Hall5c3ff722017-05-24 17:24:59 -0700374 handle = main.CLIs[ 0 ].flows( state=" |grep PEND|wc -l", jsonFormat=False )
375 main.log.info( "handle returns PENDING flows: " + handle )
suibin zhang17308622016-04-14 15:45:30 -0700376 if handle == "0":
377 resp = main.TRUE
378
379 time.sleep( main.chkFlowSleep )
380 tAllAdded = time.time()
381
Jon Hall5c3ff722017-05-24 17:24:59 -0700382 if tAllAdded - tLastPostEnd >= int( main.params[ 'CASE2100' ][ 'chkFlowTO' ] ):
383 main.log.warn( "ONOS Flows still in pending state after: {} seconds.".format( tAllAdded - tLastPostEnd ) )
suibin zhang17308622016-04-14 15:45:30 -0700384
Jon Hall5c3ff722017-05-24 17:24:59 -0700385 main.numFlows = int( main.params[ 'CASE1000' ][ 'batches' ] ) *\
386 int( main.params[ 'CASE1000' ][ 'batchSize' ] )
387 main.log.info( "Total number of flows: " + str( main.numFlows ) )
388 main.elapsePOST = tLastPostEnd - tStartPost
389 main.log.info( "Total POST elapse time: " + str( main.elapsePOST ) )
390 main.log.info( "Rate of ADD Controller response: " + str( main.numFlows / ( main.elapsePOST ) ) )
suibin zhang17308622016-04-14 15:45:30 -0700391
392 main.POSTtoCONFRM = tAllAdded - tLastPostEnd
Jon Hall5c3ff722017-05-24 17:24:59 -0700393 main.log.info( "Elapse time from end of last REST POST to Flows in ADDED state: " +
394 str( main.POSTtoCONFRM ) )
395 main.log.info( "Rate of Confirmed Batch Flow ADD is ( flows/sec ): " +
396 str( main.numFlows / main.POSTtoCONFRM ) )
397 main.log.info( "Number of flow Batches in the addedBatchList is: " +
398 str( len( main.addedBatchList ) ) )
suibin zhang17308622016-04-14 15:45:30 -0700399
Jon Hall5c3ff722017-05-24 17:24:59 -0700400 def CASE3100( self, main ):
401 """
suibin zhang17308622016-04-14 15:45:30 -0700402 DELETE flow batches using threads
Jon Hall5c3ff722017-05-24 17:24:59 -0700403 """
404 main.case( "Using REST API /flows/{} to delete flow batch - multi-threads" )
405 main.step( "Using REST API /flows/{} to delete flow batch - multi-threads" )
suibin zhang17308622016-04-14 15:45:30 -0700406
407 from Queue import Queue
408 from threading import Thread
409 import time
410 import json
411
412 main.threadID = 0
413 q = Queue()
414 tAllRemoved = 0
415
Jon Hall5c3ff722017-05-24 17:24:59 -0700416 main.log.info( "Number of flow batches at start of remove: " + str( len( main.addedBatchList ) ) )
417
418 def removeWorker( id ):
suibin zhang17308622016-04-14 15:45:30 -0700419 while True:
420 item = q.get()
Jon Hall5c3ff722017-05-24 17:24:59 -0700421 response = main.ONOSrest.removeFlowBatch( batch=json.loads( item ) )
422 main.log.info( "Thread {} is working on deleting. ".format( id ) )
suibin zhang17308622016-04-14 15:45:30 -0700423 q.task_done()
424
Jon Hall5c3ff722017-05-24 17:24:59 -0700425 for i in range( int( main.params[ 'CASE2100' ][ 'numThreads' ] ) ):
426 threadID = "ThreadID-" + str( i )
427 t = Thread( target=removeWorker, name=threadID, args=( threadID, ) )
suibin zhang17308622016-04-14 15:45:30 -0700428 t.daemon = True
429 t.start()
430
431 tStartDelete = time.time()
432 for item in main.addedBatchList:
Jon Hall5c3ff722017-05-24 17:24:59 -0700433 q.put( item )
suibin zhang17308622016-04-14 15:45:30 -0700434
435 q.join()
436 tLastDeleteEnd = time.time()
Jon Hall5c3ff722017-05-24 17:24:59 -0700437 main.log.info( "Number of flow batches at end of remove: " + str( len( main.addedBatchList ) ) )
suibin zhang17308622016-04-14 15:45:30 -0700438
Jon Hall5c3ff722017-05-24 17:24:59 -0700439 main.step( "Check to ensure all flows are in added state." )
440 #pprint( main.addedBatchList )
suibin zhang17308622016-04-14 15:45:30 -0700441 resp = main.FALSE
Jon Hall5c3ff722017-05-24 17:24:59 -0700442 while resp != main.TRUE and ( tAllRemoved - tLastDeleteEnd < int( main.params[ 'CASE3100' ][ 'chkFlowTO' ] ) ):
443 if main.params[ 'CASE3100' ][ 'RESTchkFlow' ] == 'main.TRUE':
suibin zhang17308622016-04-14 15:45:30 -0700444 resp = main.ONOSrest.checkFlowsState()
445 else:
Jon Hall5c3ff722017-05-24 17:24:59 -0700446 handle = main.CLIs[ 0 ].flows( state=" |grep PEND|wc -l", jsonFormat=False )
447 main.log.info( "handle returns PENDING flows: " + handle )
suibin zhang17308622016-04-14 15:45:30 -0700448 if handle == "0":
449 resp = main.TRUE
450 time.sleep( main.chkFlowSleep )
451 tAllRemoved = time.time()
452
Jon Hall5c3ff722017-05-24 17:24:59 -0700453 if tLastDeleteEnd - tLastDeleteEnd >= int( main.params[ 'CASE2100' ][ 'chkFlowTO' ] ):
454 main.log.warn( "ONOS Flows still in pending state after: {} seconds.".format( tAllRemoved - tLastDeleteEnd ) )
suibin zhang17308622016-04-14 15:45:30 -0700455
Jon Hall5c3ff722017-05-24 17:24:59 -0700456 main.numFlows = int( main.params[ 'CASE1000' ][ 'batches' ] ) *\
457 int( main.params[ 'CASE1000' ][ 'batchSize' ] )
458 main.log.info( "Total number of flows: " + str( main.numFlows ) )
459 main.elapseDELETE = tLastDeleteEnd - tStartDelete
460 main.log.info( "Total DELETE elapse time: " + str( main.elapseDELETE ) )
461 main.log.info( "Rate of DELETE Controller response: " + str( main.numFlows / ( main.elapseDELETE ) ) )
suibin zhang17308622016-04-14 15:45:30 -0700462
463 main.DELtoCONFRM = tAllRemoved - tLastDeleteEnd
Jon Hall5c3ff722017-05-24 17:24:59 -0700464 main.log.info( "Elapse time from end of last REST DELETE to Flows in REMOVED state: " +
465 str( main.DELtoCONFRM ) )
466 main.log.info( "Rate of Confirmed Batch Flow REMOVED is ( flows/sec ): " + str( main.numFlows / main.DELtoCONFRM ) )
suibin zhang17308622016-04-14 15:45:30 -0700467
Jon Hall5c3ff722017-05-24 17:24:59 -0700468 def CASE100( self, main ):
suibin zhang17308622016-04-14 15:45:30 -0700469 from pprint import pprint
470
471 main.case( "Check to ensure onos flows." )
472
473 resp = main.ONOSrest.checkFlowsState()
Jon Hall5c3ff722017-05-24 17:24:59 -0700474 #pprint( resp )
suibin zhang17308622016-04-14 15:45:30 -0700475
Jon Hall5c3ff722017-05-24 17:24:59 -0700476 def CASE210( self, main ):
477 main.case( "Log test results to a data file" )
478 main.step( "Write test resulted data to a data file" )
suibin zhang17308622016-04-14 15:45:30 -0700479 main.scale = main.maxNodes
480
481 try:
Jon Hall5c3ff722017-05-24 17:24:59 -0700482 dbFileName = "/tmp/SCPFbatchFlowRespData"
483 dbfile = open( dbFileName, "w+" )
suibin zhang17308622016-04-14 15:45:30 -0700484 temp = "'" + main.commit + "',"
YPZhang28909bc2016-06-20 13:29:11 -0700485 temp += "'1gig',"
suibin zhang17308622016-04-14 15:45:30 -0700486 temp += "'" + str( main.scale ) + "',"
487 temp += "'" + main.cluster + "',"
488 temp += "'" + str( main.elapsePOST ) + "',"
489 temp += "'" + str( main.POSTtoCONFRM ) + "',"
YPZhang28909bc2016-06-20 13:29:11 -0700490 temp += "'" + str( main.numFlows / main.POSTtoCONFRM ) + "',"
Jon Hall5c3ff722017-05-24 17:24:59 -0700491 temp += "'" + str( main.elapseDELETE ) + "',"
492 temp += "'" + str( main.DELtoCONFRM ) + "',"
YPZhang28909bc2016-06-20 13:29:11 -0700493 temp += "'" + str( main.numFlows / main.DELtoCONFRM ) + "',"
494 temp += "'" + str( main.numSw ) + "'\n"
suibin zhang17308622016-04-14 15:45:30 -0700495 dbfile.write( temp )
496 dbfile.close()
497 stepResult = main.TRUE
498 except IOError:
Jon Hall5c3ff722017-05-24 17:24:59 -0700499 main.log.warn( "Error opening " + dbFileName + " to write results." )
suibin zhang17308622016-04-14 15:45:30 -0700500 stepResult = main.FALSE
501
502 utilities.assert_equals( expect=main.TRUE,
503 actual=stepResult,
504 onpass="Succeeded to write results to datafile",
505 onfail="Failed to write results to datafile " )
Jon Hall5c3ff722017-05-24 17:24:59 -0700506
suibin zhang17308622016-04-14 15:45:30 -0700507 def CASE110( self, main ):
Jon Hall5c3ff722017-05-24 17:24:59 -0700508 """
suibin zhang17308622016-04-14 15:45:30 -0700509 Report errors/warnings/exceptions
Jon Hall5c3ff722017-05-24 17:24:59 -0700510 """
511 main.log.info( "Error report: \n" )
suibin zhang17308622016-04-14 15:45:30 -0700512 main.ONOSbench.logReport( main.ONOSip[ 0 ],
513 [ "INFO",
514 "FOLLOWER",
515 "WARN",
516 "flow",
517 "ERROR",
518 "Except" ],
519 "s" )
520 #main.stop()
521