blob: 65d82ae04ede6dc060f22414ef0b1392f68f5d4a [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
69 if gitPull == 'True':
70 main.step( "Building ONOS in " + gitBranch + " branch" )
71 onosBuildResult = main.startUp.onosBuild( main, gitBranch )
72 stepResult = onosBuildResult
73 utilities.assert_equals( expect=main.TRUE,
74 actual=stepResult,
75 onpass="Successfully compiled " +
76 "latest ONOS",
77 onfail="Failed to compile " +
78 "latest ONOS" )
79 else:
80 main.log.warn( "Did not pull new code so skipping mvn " +
81 "clean install" )
82
83 def CASE2( self, main ):
84 """
85 - Set up cell
86 - Create cell file
87 - Set cell file
88 - Verify cell file
89 - Kill ONOS process
90 - Uninstall ONOS cluster
91 - Verify ONOS start up
92 - Install ONOS cluster
93 - Connect to cli
94 """
suibin zhang17308622016-04-14 15:45:30 -070095 main.numCtrls = int( main.maxNodes )
96
97 main.case( "Starting up " + str( main.numCtrls ) +
Jon Hall5c3ff722017-05-24 17:24:59 -070098 " node( s ) ONOS cluster" )
suibin zhang17308622016-04-14 15:45:30 -070099
100 main.log.info( "Safety check, killing all ONOS processes" +
101 " before initiating environment setup" )
102
103 tempOnosIp = []
104 for i in range( main.numCtrls ):
Jon Hall5c3ff722017-05-24 17:24:59 -0700105 tempOnosIp.append( main.ONOSip[ i ] )
suibin zhang17308622016-04-14 15:45:30 -0700106
Jon Hall5c3ff722017-05-24 17:24:59 -0700107 if main.params[ 'CASE2' ][ 'incPackaging' ] == "true":
108 main.step( "Create onos cell file with: " + main.apps )
suibin zhang17308622016-04-14 15:45:30 -0700109 main.ONOSbench.createCellFile( main.ONOSbench.ip_address, "temp",
Jon Hall5c3ff722017-05-24 17:24:59 -0700110 main.Mininet1.ip_address, main.apps, tempOnosIp )
suibin zhang17308622016-04-14 15:45:30 -0700111
112 main.step( "Apply cell to environment" )
113 cellResult = main.ONOSbench.setCell( "temp" )
114 verifyResult = main.ONOSbench.verifyCell()
115 stepResult = cellResult and verifyResult
116 utilities.assert_equals( expect=main.TRUE,
Jon Hall5c3ff722017-05-24 17:24:59 -0700117 actual=stepResult,
118 onpass="Successfully applied cell to " +
suibin zhang17308622016-04-14 15:45:30 -0700119 "environment",
Jon Hall5c3ff722017-05-24 17:24:59 -0700120 onfail="Failed to apply cell to environment " )
suibin zhang17308622016-04-14 15:45:30 -0700121
122 main.step( "Creating ONOS package" )
Jon Hallbd60ea02016-08-23 10:03:59 -0700123 packageResult = main.ONOSbench.buckBuild()
suibin zhang17308622016-04-14 15:45:30 -0700124 stepResult = packageResult
125 utilities.assert_equals( expect=main.TRUE,
Jon Hall5c3ff722017-05-24 17:24:59 -0700126 actual=stepResult,
127 onpass="Successfully created ONOS package",
128 onfail="Failed to create ONOS package" )
suibin zhang17308622016-04-14 15:45:30 -0700129 time.sleep( main.startUpSleep )
130
131 main.step( "Uninstalling ONOS package" )
132 onosUninstallResult = main.TRUE
133 for i in range( main.numCtrls ):
134 onosUninstallResult = onosUninstallResult and \
135 main.ONOSbench.onosUninstall( nodeIp=main.ONOSip[ i ] )
136 stepResult = onosUninstallResult
137 utilities.assert_equals( expect=main.TRUE,
Jon Hall5c3ff722017-05-24 17:24:59 -0700138 actual=stepResult,
139 onpass="Successfully uninstalled ONOS package",
140 onfail="Failed to uninstall ONOS package" )
suibin zhang17308622016-04-14 15:45:30 -0700141 time.sleep( main.startUpSleep )
142
143 else:
Jon Hall5c3ff722017-05-24 17:24:59 -0700144 main.log.info( "onos Packaging Skipped!" )
suibin zhang17308622016-04-14 15:45:30 -0700145
146 main.step( "Installing ONOS package" )
147 onosInstallResult = main.TRUE
148 for i in range( main.numCtrls ):
149 onosInstallResult = onosInstallResult and \
150 main.ONOSbench.onosInstall( node=main.ONOSip[ i ] )
151 stepResult = onosInstallResult
152 utilities.assert_equals( expect=main.TRUE,
153 actual=stepResult,
154 onpass="Successfully installed ONOS package",
155 onfail="Failed to install ONOS package" )
156 time.sleep( main.startUpSleep )
157
You Wang52590212017-05-04 17:35:20 -0700158 main.step( "Set up ONOS secure SSH" )
159 secureSshResult = main.TRUE
160 for i in range( main.numCtrls ):
161 secureSshResult = secureSshResult and main.ONOSbench.onosSecureSSH( node=main.ONOSip[ i ] )
162 utilities.assert_equals( expect=main.TRUE, actual=secureSshResult,
163 onpass="Test step PASS",
164 onfail="Test step FAIL" )
165
166 time.sleep( main.startUpSleep )
suibin zhang17308622016-04-14 15:45:30 -0700167 main.step( "Starting ONOS service" )
168 stopResult = main.TRUE
169 startResult = main.TRUE
170 onosIsUp = main.TRUE
171
172 for i in range( main.numCtrls ):
173 onosIsUp = onosIsUp and main.ONOSbench.isup( main.ONOSip[ i ] )
174 if onosIsUp == main.TRUE:
175 main.log.report( "ONOS instance is up and ready" )
176 else:
177 main.log.report( "ONOS instance may not be up, stop and " +
178 "start ONOS again " )
179 for i in range( main.numCtrls ):
180 stopResult = stopResult and \
181 main.ONOSbench.onosStop( main.ONOSip[ i ] )
182 for i in range( main.numCtrls ):
183 startResult = startResult and \
184 main.ONOSbench.onosStart( main.ONOSip[ i ] )
185 stepResult = onosIsUp and stopResult and startResult
186 utilities.assert_equals( expect=main.TRUE,
187 actual=stepResult,
188 onpass="ONOS service is ready",
189 onfail="ONOS service did not start properly" )
190
191 main.step( "Start ONOS cli" )
192 cliResult = main.TRUE
193 for i in range( i, main.numCtrls ):
194 cliResult = cliResult and \
You Wang52590212017-05-04 17:35:20 -0700195 main.ONOScli1.startOnosCli( main.ONOSip[ i ] )
suibin zhang17308622016-04-14 15:45:30 -0700196 stepResult = cliResult
197 utilities.assert_equals( expect=main.TRUE,
198 actual=stepResult,
199 onpass="Successfully start ONOS cli",
200 onfail="Failed to start ONOS cli" )
201
suibin zhang17308622016-04-14 15:45:30 -0700202 def CASE10( self, main ):
Jon Hall5c3ff722017-05-24 17:24:59 -0700203 """
suibin zhang17308622016-04-14 15:45:30 -0700204 Start Mininet
Jon Hall5c3ff722017-05-24 17:24:59 -0700205 """
suibin zhang17308622016-04-14 15:45:30 -0700206 import time
207
208 main.case( "Enable openflow-base on onos and start Mininet." )
209
Jon Hall5c3ff722017-05-24 17:24:59 -0700210 main.step( "Activate openflow-base App" )
211 app = main.params[ 'CASE10' ][ 'app' ]
YPZhang5d0552f2016-05-18 13:02:52 -0700212 stepResult = main.ONOScli1.activateApp( app )
Jon Hall5c3ff722017-05-24 17:24:59 -0700213 time.sleep( main.cfgSleep )
214 main.log.info( stepResult )
suibin zhang17308622016-04-14 15:45:30 -0700215 utilities.assert_equals( expect=main.TRUE,
216 actual=stepResult,
217 onpass="Successfully activate " + app,
218 onfail="Failed to activate app " + app )
219
Jon Hall5c3ff722017-05-24 17:24:59 -0700220 time.sleep( main.cfgSleep )
suibin zhang17308622016-04-14 15:45:30 -0700221
Jon Hall5c3ff722017-05-24 17:24:59 -0700222 main.step( "Configure AdaptiveFlowSampling " )
223 stepResult = main.ONOScli1.setCfg( component="org.onosproject.provider.of.flow.impl.OpenFlowRuleProvider",
224 propName="adaptiveFlowSampling ", value=main.params[ 'CASE10' ][ 'adaptiveFlowenabled' ] )
suibin zhang17308622016-04-14 15:45:30 -0700225 utilities.assert_equals( expect=main.TRUE,
226 actual=stepResult,
227 onpass="App Configuration Succeeded! ",
228 onfail="App Configuration Failed!" )
Jon Hall5c3ff722017-05-24 17:24:59 -0700229 time.sleep( main.cfgSleep )
suibin zhang17308622016-04-14 15:45:30 -0700230
Jon Hall5c3ff722017-05-24 17:24:59 -0700231 main.step( "Setup Mininet Linear Topology with " + str( main.numSw ) + " switches" )
232 argStr = main.params[ 'CASE10' ][ 'mnArgs' ].format( main.numSw )
233 stepResult = main.Mininet1.startNet( args=argStr )
suibin zhang17308622016-04-14 15:45:30 -0700234
235 utilities.assert_equals( expect=main.TRUE,
236 actual=stepResult,
237 onpass="Successfully loaded topology",
238 onfail="Failed to load topology" )
239
240 time.sleep( main.startMNSleep )
241
242 main.step( "Assign switches to controller" )
Jon Hall5c3ff722017-05-24 17:24:59 -0700243 for i in range( 1, main.numSw + 1 ):
244 main.Mininet1.assignSwController( "s" + str( i ), main.ONOSip[ 0 ] )
suibin zhang17308622016-04-14 15:45:30 -0700245
246 utilities.assert_equals( expect=main.TRUE,
247 actual=stepResult,
248 onpass="Successfully assigned switch to controller",
249 onfail="Failed to assign switch to controller" )
250
251 main.deviceIdPrefix = "of:"
252
253 time.sleep( main.startMNSleep )
254
255 def CASE11( self, main ):
Jon Hall5c3ff722017-05-24 17:24:59 -0700256 """
suibin zhang17308622016-04-14 15:45:30 -0700257 Start Null Provider
Jon Hall5c3ff722017-05-24 17:24:59 -0700258 """
suibin zhang17308622016-04-14 15:45:30 -0700259 import time
260
261 main.case( "Setup Null Provider for linear Topology" )
262
Jon Hall5c3ff722017-05-24 17:24:59 -0700263 main.step( "Activate Null Provider App" )
264 stepResult = main.ONOSbench.onosCli( ONOSIp=main.ONOSip[ 0 ],
265 cmdstr="app activate org.onosproject.null" )
suibin zhang17308622016-04-14 15:45:30 -0700266 utilities.assert_equals( expect=main.TRUE,
267 actual=stepResult,
268 onpass="Successfully activated org.onosproject.null",
269 onfail="Failed to activate org.onosproject.null" )
Jon Hall5c3ff722017-05-24 17:24:59 -0700270 time.sleep( main.cfgSleep )
suibin zhang17308622016-04-14 15:45:30 -0700271
Jon Hall5c3ff722017-05-24 17:24:59 -0700272 main.step( "Setup Null Provider Linear Topology with " + str( main.numSw ) + " devices." )
273 r1 = main.ONOSbench.onosCfgSet( main.ONOSip[ 0 ], "org.onosproject.provider.nil.NullProviders", "deviceCount " + str( main.numSw ) )
274 r2 = main.ONOSbench.onosCfgSet( main.ONOSip[ 0 ], "org.onosproject.provider.nil.NullProviders", "topoShape " + main.params[ 'CASE11' ][ 'nullTopo' ] )
275 r3 = main.ONOSbench.onosCfgSet( main.ONOSip[ 0 ], "org.onosproject.provider.nil.NullProviders", "enabled " + main.params[ 'CASE11' ][ 'nullStart' ] )
suibin zhang17308622016-04-14 15:45:30 -0700276 stepResult = r1 & r2 & r3
277 utilities.assert_equals( expect=main.TRUE,
278 actual=stepResult,
279 onpass="App Configuration Succeeded! ",
280 onfail="App Configuration Failed!" )
281 time.sleep( main.cfgSleep )
282
Jon Hall5c3ff722017-05-24 17:24:59 -0700283 main.log.info( "Check to make sure null providers are configured correctly." )
284 main.ONOSbench.handle.sendline( "onos $OC1 summary" )
285 stepResult = main.ONOSbench.handle.expect( ":~" )
286 main.log.info( "ONOS Summary: " + main.ONOSbench.handle.before )
suibin zhang17308622016-04-14 15:45:30 -0700287
288 main.deviceIdPrefix = "null:"
289
290 time.sleep( main.startMNSleep )
291
suibin zhang17308622016-04-14 15:45:30 -0700292 def CASE1000( self, main ):
Jon Hall5c3ff722017-05-24 17:24:59 -0700293 """
suibin zhang17308622016-04-14 15:45:30 -0700294 create JSON object with batched flows
Jon Hall5c3ff722017-05-24 17:24:59 -0700295 """
suibin zhang17308622016-04-14 15:45:30 -0700296 import numpy
297 import time
298 from pprint import pprint
299
300 main.case( "Create a json object for the batched flows" )
301
302 main.step( "Parse batch creation information" )
Jon Hall5c3ff722017-05-24 17:24:59 -0700303 main.batchSize = int( main.params[ 'CASE1000' ][ 'batchSize' ] )
304 main.log.info( "Number of flows in a batch is:" + str( main.batchSize ) )
suibin zhang17308622016-04-14 15:45:30 -0700305
306 main.flowJsonBatchList = []
307 startSw = 1
308
Jon Hall5c3ff722017-05-24 17:24:59 -0700309 main.step( "Creating a full list of batches" )
310 for index in range( 1, int( main.params[ 'CASE1000' ][ 'batches' ] ) + 1 ):
suibin zhang17308622016-04-14 15:45:30 -0700311 if startSw <= main.numSw:
312 ind = startSw
313 else:
314 startSw = 1
315 ind = startSw
316
Jon Hall5c3ff722017-05-24 17:24:59 -0700317 main.log.info( "Creating batch: " + str( index ) )
318 flowJsonBatch = main.ONOSrest.createFlowBatch( numSw=main.numSw,
319 swIndex=ind,
320 batchSize=main.batchSize,
321 batchIndex=index,
suibin zhang17308622016-04-14 15:45:30 -0700322 deviceIdpreFix=main.deviceIdPrefix,
Jon Hall5c3ff722017-05-24 17:24:59 -0700323 ingressPort=2,
324 egressPort=3 )
325 main.flowJsonBatchList.append( flowJsonBatch )
suibin zhang17308622016-04-14 15:45:30 -0700326
327 startSw += 1
Jon Hall5c3ff722017-05-24 17:24:59 -0700328 main.log.info( "Number of items created in the batch list is: " + str( len( main.flowJsonBatchList ) ) )
suibin zhang17308622016-04-14 15:45:30 -0700329
Jon Hall5c3ff722017-05-24 17:24:59 -0700330 def CASE2100( self, main ):
331 """
suibin zhang17308622016-04-14 15:45:30 -0700332 Posting flow batches using threads
Jon Hall5c3ff722017-05-24 17:24:59 -0700333 """
334 main.case( "Using REST API /flows/{} to post flow batch - multi-threads" )
335 main.step( "Using REST API /flows/{} to post flow batch - multi-threads" )
suibin zhang17308622016-04-14 15:45:30 -0700336
337 from Queue import Queue
338 from threading import Thread
339 import time
340 import json
341
342 main.threadID = 0
343 main.addedBatchList = []
344 q = Queue()
345 tAllAdded = 0
You Wang7b5b2262016-11-10 13:54:56 -0800346 main.postFailed = False
suibin zhang17308622016-04-14 15:45:30 -0700347
Jon Hall5c3ff722017-05-24 17:24:59 -0700348 def postWorker( id ):
suibin zhang17308622016-04-14 15:45:30 -0700349 while True:
350 item = q.get()
Jon Hall5c3ff722017-05-24 17:24:59 -0700351 #print json.dumps( item )
352 status, response = main.ONOSrest.sendFlowBatch( batch=item )
You Wang7b5b2262016-11-10 13:54:56 -0800353 if status == main.TRUE:
Jon Hall5c3ff722017-05-24 17:24:59 -0700354 main.log.info( "Thread {} is working on posting. ".format( id ) )
355 #print json.dumps( response )
356 main.addedBatchList.append( response[ 1 ] )
You Wang7b5b2262016-11-10 13:54:56 -0800357 else:
Jon Hall5c3ff722017-05-24 17:24:59 -0700358 main.log.error( "Thread {} failed to post.".format( id ) )
You Wang7b5b2262016-11-10 13:54:56 -0800359 main.postFailed = True
suibin zhang17308622016-04-14 15:45:30 -0700360 q.task_done()
361
Jon Hall5c3ff722017-05-24 17:24:59 -0700362 for i in range( int( main.params[ 'CASE2100' ][ 'numThreads' ] ) ):
363 threadID = "ThreadID-" + str( i )
364 t = Thread( target=postWorker, name=threadID, args=( threadID, ) )
suibin zhang17308622016-04-14 15:45:30 -0700365 t.daemon = True
366 t.start()
367
368 tStartPost = time.time()
369 for item in main.flowJsonBatchList:
Jon Hall5c3ff722017-05-24 17:24:59 -0700370 q.put( item )
suibin zhang17308622016-04-14 15:45:30 -0700371
372 q.join()
373 tLastPostEnd = time.time()
You Wang7b5b2262016-11-10 13:54:56 -0800374 if main.postFailed:
375 main.log.error( "Flow batch posting failed, exit test" )
376 main.cleanup()
377 main.exit()
suibin zhang17308622016-04-14 15:45:30 -0700378
Jon Hall5c3ff722017-05-24 17:24:59 -0700379 main.step( "Check to ensure all flows are in added state." )
380 #pprint( main.addedBatchList )
suibin zhang17308622016-04-14 15:45:30 -0700381 resp = main.FALSE
Jon Hall5c3ff722017-05-24 17:24:59 -0700382 while resp != main.TRUE and ( tAllAdded - tLastPostEnd < int( main.params[ 'CASE2100' ][ 'chkFlowTO' ] ) ):
383 if main.params[ 'CASE2100' ][ 'RESTchkFlow' ] == 'main.TRUE':
suibin zhang17308622016-04-14 15:45:30 -0700384 resp = main.ONOSrest.checkFlowsState()
385 else:
Jon Hall5c3ff722017-05-24 17:24:59 -0700386 handle = main.CLIs[ 0 ].flows( state=" |grep PEND|wc -l", jsonFormat=False )
387 main.log.info( "handle returns PENDING flows: " + handle )
suibin zhang17308622016-04-14 15:45:30 -0700388 if handle == "0":
389 resp = main.TRUE
390
391 time.sleep( main.chkFlowSleep )
392 tAllAdded = time.time()
393
Jon Hall5c3ff722017-05-24 17:24:59 -0700394 if tAllAdded - tLastPostEnd >= int( main.params[ 'CASE2100' ][ 'chkFlowTO' ] ):
395 main.log.warn( "ONOS Flows still in pending state after: {} seconds.".format( tAllAdded - tLastPostEnd ) )
suibin zhang17308622016-04-14 15:45:30 -0700396
Jon Hall5c3ff722017-05-24 17:24:59 -0700397 main.numFlows = int( main.params[ 'CASE1000' ][ 'batches' ] ) *\
398 int( main.params[ 'CASE1000' ][ 'batchSize' ] )
399 main.log.info( "Total number of flows: " + str( main.numFlows ) )
400 main.elapsePOST = tLastPostEnd - tStartPost
401 main.log.info( "Total POST elapse time: " + str( main.elapsePOST ) )
402 main.log.info( "Rate of ADD Controller response: " + str( main.numFlows / ( main.elapsePOST ) ) )
suibin zhang17308622016-04-14 15:45:30 -0700403
404 main.POSTtoCONFRM = tAllAdded - tLastPostEnd
Jon Hall5c3ff722017-05-24 17:24:59 -0700405 main.log.info( "Elapse time from end of last REST POST to Flows in ADDED state: " +
406 str( main.POSTtoCONFRM ) )
407 main.log.info( "Rate of Confirmed Batch Flow ADD is ( flows/sec ): " +
408 str( main.numFlows / main.POSTtoCONFRM ) )
409 main.log.info( "Number of flow Batches in the addedBatchList is: " +
410 str( len( main.addedBatchList ) ) )
suibin zhang17308622016-04-14 15:45:30 -0700411
Jon Hall5c3ff722017-05-24 17:24:59 -0700412 def CASE3100( self, main ):
413 """
suibin zhang17308622016-04-14 15:45:30 -0700414 DELETE flow batches using threads
Jon Hall5c3ff722017-05-24 17:24:59 -0700415 """
416 main.case( "Using REST API /flows/{} to delete flow batch - multi-threads" )
417 main.step( "Using REST API /flows/{} to delete flow batch - multi-threads" )
suibin zhang17308622016-04-14 15:45:30 -0700418
419 from Queue import Queue
420 from threading import Thread
421 import time
422 import json
423
424 main.threadID = 0
425 q = Queue()
426 tAllRemoved = 0
427
Jon Hall5c3ff722017-05-24 17:24:59 -0700428 main.log.info( "Number of flow batches at start of remove: " + str( len( main.addedBatchList ) ) )
429
430 def removeWorker( id ):
suibin zhang17308622016-04-14 15:45:30 -0700431 while True:
432 item = q.get()
Jon Hall5c3ff722017-05-24 17:24:59 -0700433 response = main.ONOSrest.removeFlowBatch( batch=json.loads( item ) )
434 main.log.info( "Thread {} is working on deleting. ".format( id ) )
suibin zhang17308622016-04-14 15:45:30 -0700435 q.task_done()
436
Jon Hall5c3ff722017-05-24 17:24:59 -0700437 for i in range( int( main.params[ 'CASE2100' ][ 'numThreads' ] ) ):
438 threadID = "ThreadID-" + str( i )
439 t = Thread( target=removeWorker, name=threadID, args=( threadID, ) )
suibin zhang17308622016-04-14 15:45:30 -0700440 t.daemon = True
441 t.start()
442
443 tStartDelete = time.time()
444 for item in main.addedBatchList:
Jon Hall5c3ff722017-05-24 17:24:59 -0700445 q.put( item )
suibin zhang17308622016-04-14 15:45:30 -0700446
447 q.join()
448 tLastDeleteEnd = time.time()
Jon Hall5c3ff722017-05-24 17:24:59 -0700449 main.log.info( "Number of flow batches at end of remove: " + str( len( main.addedBatchList ) ) )
suibin zhang17308622016-04-14 15:45:30 -0700450
Jon Hall5c3ff722017-05-24 17:24:59 -0700451 main.step( "Check to ensure all flows are in added state." )
452 #pprint( main.addedBatchList )
suibin zhang17308622016-04-14 15:45:30 -0700453 resp = main.FALSE
Jon Hall5c3ff722017-05-24 17:24:59 -0700454 while resp != main.TRUE and ( tAllRemoved - tLastDeleteEnd < int( main.params[ 'CASE3100' ][ 'chkFlowTO' ] ) ):
455 if main.params[ 'CASE3100' ][ 'RESTchkFlow' ] == 'main.TRUE':
suibin zhang17308622016-04-14 15:45:30 -0700456 resp = main.ONOSrest.checkFlowsState()
457 else:
Jon Hall5c3ff722017-05-24 17:24:59 -0700458 handle = main.CLIs[ 0 ].flows( state=" |grep PEND|wc -l", jsonFormat=False )
459 main.log.info( "handle returns PENDING flows: " + handle )
suibin zhang17308622016-04-14 15:45:30 -0700460 if handle == "0":
461 resp = main.TRUE
462 time.sleep( main.chkFlowSleep )
463 tAllRemoved = time.time()
464
Jon Hall5c3ff722017-05-24 17:24:59 -0700465 if tLastDeleteEnd - tLastDeleteEnd >= int( main.params[ 'CASE2100' ][ 'chkFlowTO' ] ):
466 main.log.warn( "ONOS Flows still in pending state after: {} seconds.".format( tAllRemoved - tLastDeleteEnd ) )
suibin zhang17308622016-04-14 15:45:30 -0700467
Jon Hall5c3ff722017-05-24 17:24:59 -0700468 main.numFlows = int( main.params[ 'CASE1000' ][ 'batches' ] ) *\
469 int( main.params[ 'CASE1000' ][ 'batchSize' ] )
470 main.log.info( "Total number of flows: " + str( main.numFlows ) )
471 main.elapseDELETE = tLastDeleteEnd - tStartDelete
472 main.log.info( "Total DELETE elapse time: " + str( main.elapseDELETE ) )
473 main.log.info( "Rate of DELETE Controller response: " + str( main.numFlows / ( main.elapseDELETE ) ) )
suibin zhang17308622016-04-14 15:45:30 -0700474
475 main.DELtoCONFRM = tAllRemoved - tLastDeleteEnd
Jon Hall5c3ff722017-05-24 17:24:59 -0700476 main.log.info( "Elapse time from end of last REST DELETE to Flows in REMOVED state: " +
477 str( main.DELtoCONFRM ) )
478 main.log.info( "Rate of Confirmed Batch Flow REMOVED is ( flows/sec ): " + str( main.numFlows / main.DELtoCONFRM ) )
suibin zhang17308622016-04-14 15:45:30 -0700479
Jon Hall5c3ff722017-05-24 17:24:59 -0700480 def CASE100( self, main ):
suibin zhang17308622016-04-14 15:45:30 -0700481 from pprint import pprint
482
483 main.case( "Check to ensure onos flows." )
484
485 resp = main.ONOSrest.checkFlowsState()
Jon Hall5c3ff722017-05-24 17:24:59 -0700486 #pprint( resp )
suibin zhang17308622016-04-14 15:45:30 -0700487
Jon Hall5c3ff722017-05-24 17:24:59 -0700488 def CASE210( self, main ):
489 main.case( "Log test results to a data file" )
490 main.step( "Write test resulted data to a data file" )
suibin zhang17308622016-04-14 15:45:30 -0700491 main.scale = main.maxNodes
492
493 try:
Jon Hall5c3ff722017-05-24 17:24:59 -0700494 dbFileName = "/tmp/SCPFbatchFlowRespData"
495 dbfile = open( dbFileName, "w+" )
suibin zhang17308622016-04-14 15:45:30 -0700496 temp = "'" + main.commit + "',"
YPZhang28909bc2016-06-20 13:29:11 -0700497 temp += "'1gig',"
suibin zhang17308622016-04-14 15:45:30 -0700498 temp += "'" + str( main.scale ) + "',"
499 temp += "'" + main.cluster + "',"
500 temp += "'" + str( main.elapsePOST ) + "',"
501 temp += "'" + str( main.POSTtoCONFRM ) + "',"
YPZhang28909bc2016-06-20 13:29:11 -0700502 temp += "'" + str( main.numFlows / main.POSTtoCONFRM ) + "',"
Jon Hall5c3ff722017-05-24 17:24:59 -0700503 temp += "'" + str( main.elapseDELETE ) + "',"
504 temp += "'" + str( main.DELtoCONFRM ) + "',"
YPZhang28909bc2016-06-20 13:29:11 -0700505 temp += "'" + str( main.numFlows / main.DELtoCONFRM ) + "',"
506 temp += "'" + str( main.numSw ) + "'\n"
suibin zhang17308622016-04-14 15:45:30 -0700507 dbfile.write( temp )
508 dbfile.close()
509 stepResult = main.TRUE
510 except IOError:
Jon Hall5c3ff722017-05-24 17:24:59 -0700511 main.log.warn( "Error opening " + dbFileName + " to write results." )
suibin zhang17308622016-04-14 15:45:30 -0700512 stepResult = main.FALSE
513
514 utilities.assert_equals( expect=main.TRUE,
515 actual=stepResult,
516 onpass="Succeeded to write results to datafile",
517 onfail="Failed to write results to datafile " )
Jon Hall5c3ff722017-05-24 17:24:59 -0700518
suibin zhang17308622016-04-14 15:45:30 -0700519 def CASE110( self, main ):
Jon Hall5c3ff722017-05-24 17:24:59 -0700520 """
suibin zhang17308622016-04-14 15:45:30 -0700521 Report errors/warnings/exceptions
Jon Hall5c3ff722017-05-24 17:24:59 -0700522 """
523 main.log.info( "Error report: \n" )
suibin zhang17308622016-04-14 15:45:30 -0700524 main.ONOSbench.logReport( main.ONOSip[ 0 ],
525 [ "INFO",
526 "FOLLOWER",
527 "WARN",
528 "flow",
529 "ERROR",
530 "Except" ],
531 "s" )
532 #main.stop()
533