suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 1 | class SCPFbatchFlowResp: |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 2 | |
| 3 | """ |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 4 | 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 Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 7 | """ |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 8 | 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 |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 21 | """ |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 22 | try: |
| 23 | from tests.dependencies.ONOSSetup import ONOSSetup |
| 24 | main.testSetUp = ONOSSetup() |
| 25 | except ImportError: |
| 26 | main.log.error( "ONOSSetup not found. exiting the test" ) |
| 27 | main.exit() |
| 28 | main.testSetUp.envSetupDescription() |
| 29 | stepResult = main.FALSE |
| 30 | try: |
| 31 | # Test variables |
| 32 | main.testOnDirectory = os.path.dirname( os.getcwd() ) |
| 33 | main.cellName = main.params[ 'CASE1' ][ 'cellName' ] |
| 34 | main.apps = main.params[ 'CASE1' ][ 'cellApps' ] |
| 35 | main.maxNodes = int( main.params[ 'GLOBAL' ][ 'maxNodes' ] ) |
| 36 | main.startUpSleep = float( main.params[ 'GLOBAL' ][ 'SLEEP' ][ 'startup' ] ) |
| 37 | main.startMNSleep = float( main.params[ 'GLOBAL' ][ 'SLEEP' ][ 'startMN' ] ) |
| 38 | main.addFlowSleep = float( main.params[ 'GLOBAL' ][ 'SLEEP' ][ 'addFlow' ] ) |
| 39 | main.delFlowSleep = float( main.params[ 'GLOBAL' ][ 'SLEEP' ][ 'delFlow' ] ) |
| 40 | main.chkFlowSleep = float( main.params[ 'GLOBAL' ][ 'SLEEP' ][ 'chkFlow' ] ) |
| 41 | main.onosPackaging = main.params[ 'CASE2' ][ 'incPackaging' ] == "true" |
| 42 | main.cfgSleep = float( main.params[ 'GLOBAL' ][ 'SLEEP' ][ 'cfg' ] ) |
| 43 | main.numSw = int( main.params[ 'GLOBAL' ][ 'numSw' ] ) |
| 44 | main.numThreads = int( main.params[ 'GLOBAL' ][ 'numThreads' ] ) |
| 45 | main.cluster = main.params[ 'GLOBAL' ][ 'cluster' ] |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 46 | |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 47 | stepResult = main.testSetUp.envSetup() |
| 48 | except Exception as e: |
| 49 | main.testSetUp.envSetupException( e ) |
| 50 | main.testSetUp.evnSetupConclusion( stepResult ) |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 51 | main.commit = main.commit.split( " " )[ 1 ] |
YPZhang | 28909bc | 2016-06-20 13:29:11 -0700 | [diff] [blame] | 52 | |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 53 | |
| 54 | def CASE2( self, main ): |
| 55 | """ |
| 56 | - Set up cell |
| 57 | - Create cell file |
| 58 | - Set cell file |
| 59 | - Verify cell file |
| 60 | - Kill ONOS process |
| 61 | - Uninstall ONOS cluster |
| 62 | - Verify ONOS start up |
| 63 | - Install ONOS cluster |
| 64 | - Connect to cli |
| 65 | """ |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 66 | main.testSetUp.ONOSSetUp( main.Mininet1, skipPack=main.onosPackaging ) |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 67 | |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 68 | def CASE10( self, main ): |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 69 | """ |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 70 | Start Mininet |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 71 | """ |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 72 | import time |
| 73 | |
| 74 | main.case( "Enable openflow-base on onos and start Mininet." ) |
| 75 | |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 76 | main.step( "Activate openflow-base App" ) |
| 77 | app = main.params[ 'CASE10' ][ 'app' ] |
YPZhang | 5d0552f | 2016-05-18 13:02:52 -0700 | [diff] [blame] | 78 | stepResult = main.ONOScli1.activateApp( app ) |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 79 | time.sleep( main.cfgSleep ) |
| 80 | main.log.info( stepResult ) |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 81 | utilities.assert_equals( expect=main.TRUE, |
| 82 | actual=stepResult, |
| 83 | onpass="Successfully activate " + app, |
| 84 | onfail="Failed to activate app " + app ) |
| 85 | |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 86 | time.sleep( main.cfgSleep ) |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 87 | |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 88 | main.step( "Configure AdaptiveFlowSampling " ) |
| 89 | stepResult = main.ONOScli1.setCfg( component="org.onosproject.provider.of.flow.impl.OpenFlowRuleProvider", |
| 90 | propName="adaptiveFlowSampling ", value=main.params[ 'CASE10' ][ 'adaptiveFlowenabled' ] ) |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 91 | utilities.assert_equals( expect=main.TRUE, |
| 92 | actual=stepResult, |
| 93 | onpass="App Configuration Succeeded! ", |
| 94 | onfail="App Configuration Failed!" ) |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 95 | time.sleep( main.cfgSleep ) |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 96 | |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 97 | main.step( "Setup Mininet Linear Topology with " + str( main.numSw ) + " switches" ) |
| 98 | argStr = main.params[ 'CASE10' ][ 'mnArgs' ].format( main.numSw ) |
| 99 | stepResult = main.Mininet1.startNet( args=argStr ) |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 100 | |
| 101 | utilities.assert_equals( expect=main.TRUE, |
| 102 | actual=stepResult, |
| 103 | onpass="Successfully loaded topology", |
| 104 | onfail="Failed to load topology" ) |
| 105 | |
| 106 | time.sleep( main.startMNSleep ) |
| 107 | |
| 108 | main.step( "Assign switches to controller" ) |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 109 | for i in range( 1, main.numSw + 1 ): |
| 110 | main.Mininet1.assignSwController( "s" + str( i ), main.ONOSip[ 0 ] ) |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 111 | |
| 112 | utilities.assert_equals( expect=main.TRUE, |
| 113 | actual=stepResult, |
| 114 | onpass="Successfully assigned switch to controller", |
| 115 | onfail="Failed to assign switch to controller" ) |
| 116 | |
| 117 | main.deviceIdPrefix = "of:" |
| 118 | |
| 119 | time.sleep( main.startMNSleep ) |
| 120 | |
| 121 | def CASE11( self, main ): |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 122 | """ |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 123 | Start Null Provider |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 124 | """ |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 125 | import time |
| 126 | |
| 127 | main.case( "Setup Null Provider for linear Topology" ) |
| 128 | |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 129 | main.step( "Activate Null Provider App" ) |
| 130 | stepResult = main.ONOSbench.onosCli( ONOSIp=main.ONOSip[ 0 ], |
| 131 | cmdstr="app activate org.onosproject.null" ) |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 132 | utilities.assert_equals( expect=main.TRUE, |
| 133 | actual=stepResult, |
| 134 | onpass="Successfully activated org.onosproject.null", |
| 135 | onfail="Failed to activate org.onosproject.null" ) |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 136 | time.sleep( main.cfgSleep ) |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 137 | |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 138 | main.step( "Setup Null Provider Linear Topology with " + str( main.numSw ) + " devices." ) |
| 139 | r1 = main.ONOSbench.onosCfgSet( main.ONOSip[ 0 ], "org.onosproject.provider.nil.NullProviders", "deviceCount " + str( main.numSw ) ) |
| 140 | r2 = main.ONOSbench.onosCfgSet( main.ONOSip[ 0 ], "org.onosproject.provider.nil.NullProviders", "topoShape " + main.params[ 'CASE11' ][ 'nullTopo' ] ) |
| 141 | r3 = main.ONOSbench.onosCfgSet( main.ONOSip[ 0 ], "org.onosproject.provider.nil.NullProviders", "enabled " + main.params[ 'CASE11' ][ 'nullStart' ] ) |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 142 | stepResult = r1 & r2 & r3 |
| 143 | utilities.assert_equals( expect=main.TRUE, |
| 144 | actual=stepResult, |
| 145 | onpass="App Configuration Succeeded! ", |
| 146 | onfail="App Configuration Failed!" ) |
| 147 | time.sleep( main.cfgSleep ) |
| 148 | |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 149 | main.log.info( "Check to make sure null providers are configured correctly." ) |
| 150 | main.ONOSbench.handle.sendline( "onos $OC1 summary" ) |
| 151 | stepResult = main.ONOSbench.handle.expect( ":~" ) |
| 152 | main.log.info( "ONOS Summary: " + main.ONOSbench.handle.before ) |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 153 | |
| 154 | main.deviceIdPrefix = "null:" |
| 155 | |
| 156 | time.sleep( main.startMNSleep ) |
| 157 | |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 158 | def CASE1000( self, main ): |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 159 | """ |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 160 | create JSON object with batched flows |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 161 | """ |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 162 | import numpy |
| 163 | import time |
| 164 | from pprint import pprint |
| 165 | |
| 166 | main.case( "Create a json object for the batched flows" ) |
| 167 | |
| 168 | main.step( "Parse batch creation information" ) |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 169 | main.batchSize = int( main.params[ 'CASE1000' ][ 'batchSize' ] ) |
| 170 | main.log.info( "Number of flows in a batch is:" + str( main.batchSize ) ) |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 171 | |
| 172 | main.flowJsonBatchList = [] |
| 173 | startSw = 1 |
| 174 | |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 175 | main.step( "Creating a full list of batches" ) |
| 176 | for index in range( 1, int( main.params[ 'CASE1000' ][ 'batches' ] ) + 1 ): |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 177 | if startSw <= main.numSw: |
| 178 | ind = startSw |
| 179 | else: |
| 180 | startSw = 1 |
| 181 | ind = startSw |
| 182 | |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 183 | main.log.info( "Creating batch: " + str( index ) ) |
| 184 | flowJsonBatch = main.ONOSrest.createFlowBatch( numSw=main.numSw, |
| 185 | swIndex=ind, |
| 186 | batchSize=main.batchSize, |
| 187 | batchIndex=index, |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 188 | deviceIdpreFix=main.deviceIdPrefix, |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 189 | ingressPort=2, |
| 190 | egressPort=3 ) |
| 191 | main.flowJsonBatchList.append( flowJsonBatch ) |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 192 | |
| 193 | startSw += 1 |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 194 | main.log.info( "Number of items created in the batch list is: " + str( len( main.flowJsonBatchList ) ) ) |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 195 | |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 196 | def CASE2100( self, main ): |
| 197 | """ |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 198 | Posting flow batches using threads |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 199 | """ |
| 200 | main.case( "Using REST API /flows/{} to post flow batch - multi-threads" ) |
| 201 | main.step( "Using REST API /flows/{} to post flow batch - multi-threads" ) |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 202 | |
| 203 | from Queue import Queue |
| 204 | from threading import Thread |
| 205 | import time |
| 206 | import json |
| 207 | |
| 208 | main.threadID = 0 |
| 209 | main.addedBatchList = [] |
| 210 | q = Queue() |
| 211 | tAllAdded = 0 |
You Wang | 7b5b226 | 2016-11-10 13:54:56 -0800 | [diff] [blame] | 212 | main.postFailed = False |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 213 | |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 214 | def postWorker( id ): |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 215 | while True: |
| 216 | item = q.get() |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 217 | #print json.dumps( item ) |
| 218 | status, response = main.ONOSrest.sendFlowBatch( batch=item ) |
You Wang | 7b5b226 | 2016-11-10 13:54:56 -0800 | [diff] [blame] | 219 | if status == main.TRUE: |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 220 | main.log.info( "Thread {} is working on posting. ".format( id ) ) |
| 221 | #print json.dumps( response ) |
| 222 | main.addedBatchList.append( response[ 1 ] ) |
You Wang | 7b5b226 | 2016-11-10 13:54:56 -0800 | [diff] [blame] | 223 | else: |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 224 | main.log.error( "Thread {} failed to post.".format( id ) ) |
You Wang | 7b5b226 | 2016-11-10 13:54:56 -0800 | [diff] [blame] | 225 | main.postFailed = True |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 226 | q.task_done() |
| 227 | |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 228 | for i in range( int( main.params[ 'CASE2100' ][ 'numThreads' ] ) ): |
| 229 | threadID = "ThreadID-" + str( i ) |
| 230 | t = Thread( target=postWorker, name=threadID, args=( threadID, ) ) |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 231 | t.daemon = True |
| 232 | t.start() |
| 233 | |
| 234 | tStartPost = time.time() |
| 235 | for item in main.flowJsonBatchList: |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 236 | q.put( item ) |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 237 | |
| 238 | q.join() |
| 239 | tLastPostEnd = time.time() |
You Wang | 7b5b226 | 2016-11-10 13:54:56 -0800 | [diff] [blame] | 240 | if main.postFailed: |
| 241 | main.log.error( "Flow batch posting failed, exit test" ) |
| 242 | main.cleanup() |
| 243 | main.exit() |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 244 | |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 245 | main.step( "Check to ensure all flows are in added state." ) |
| 246 | #pprint( main.addedBatchList ) |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 247 | resp = main.FALSE |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 248 | while resp != main.TRUE and ( tAllAdded - tLastPostEnd < int( main.params[ 'CASE2100' ][ 'chkFlowTO' ] ) ): |
| 249 | if main.params[ 'CASE2100' ][ 'RESTchkFlow' ] == 'main.TRUE': |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 250 | resp = main.ONOSrest.checkFlowsState() |
| 251 | else: |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 252 | handle = main.CLIs[ 0 ].flows( state=" |grep PEND|wc -l", jsonFormat=False ) |
| 253 | main.log.info( "handle returns PENDING flows: " + handle ) |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 254 | if handle == "0": |
| 255 | resp = main.TRUE |
| 256 | |
| 257 | time.sleep( main.chkFlowSleep ) |
| 258 | tAllAdded = time.time() |
| 259 | |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 260 | if tAllAdded - tLastPostEnd >= int( main.params[ 'CASE2100' ][ 'chkFlowTO' ] ): |
| 261 | main.log.warn( "ONOS Flows still in pending state after: {} seconds.".format( tAllAdded - tLastPostEnd ) ) |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 262 | |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 263 | main.numFlows = int( main.params[ 'CASE1000' ][ 'batches' ] ) *\ |
| 264 | int( main.params[ 'CASE1000' ][ 'batchSize' ] ) |
| 265 | main.log.info( "Total number of flows: " + str( main.numFlows ) ) |
| 266 | main.elapsePOST = tLastPostEnd - tStartPost |
| 267 | main.log.info( "Total POST elapse time: " + str( main.elapsePOST ) ) |
| 268 | main.log.info( "Rate of ADD Controller response: " + str( main.numFlows / ( main.elapsePOST ) ) ) |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 269 | |
| 270 | main.POSTtoCONFRM = tAllAdded - tLastPostEnd |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 271 | main.log.info( "Elapse time from end of last REST POST to Flows in ADDED state: " + |
| 272 | str( main.POSTtoCONFRM ) ) |
| 273 | main.log.info( "Rate of Confirmed Batch Flow ADD is ( flows/sec ): " + |
| 274 | str( main.numFlows / main.POSTtoCONFRM ) ) |
| 275 | main.log.info( "Number of flow Batches in the addedBatchList is: " + |
| 276 | str( len( main.addedBatchList ) ) ) |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 277 | |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 278 | def CASE3100( self, main ): |
| 279 | """ |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 280 | DELETE flow batches using threads |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 281 | """ |
| 282 | main.case( "Using REST API /flows/{} to delete flow batch - multi-threads" ) |
| 283 | main.step( "Using REST API /flows/{} to delete flow batch - multi-threads" ) |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 284 | |
| 285 | from Queue import Queue |
| 286 | from threading import Thread |
| 287 | import time |
| 288 | import json |
| 289 | |
| 290 | main.threadID = 0 |
| 291 | q = Queue() |
| 292 | tAllRemoved = 0 |
| 293 | |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 294 | main.log.info( "Number of flow batches at start of remove: " + str( len( main.addedBatchList ) ) ) |
| 295 | |
| 296 | def removeWorker( id ): |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 297 | while True: |
| 298 | item = q.get() |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 299 | response = main.ONOSrest.removeFlowBatch( batch=json.loads( item ) ) |
| 300 | main.log.info( "Thread {} is working on deleting. ".format( id ) ) |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 301 | q.task_done() |
| 302 | |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 303 | for i in range( int( main.params[ 'CASE2100' ][ 'numThreads' ] ) ): |
| 304 | threadID = "ThreadID-" + str( i ) |
| 305 | t = Thread( target=removeWorker, name=threadID, args=( threadID, ) ) |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 306 | t.daemon = True |
| 307 | t.start() |
| 308 | |
| 309 | tStartDelete = time.time() |
| 310 | for item in main.addedBatchList: |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 311 | q.put( item ) |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 312 | |
| 313 | q.join() |
| 314 | tLastDeleteEnd = time.time() |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 315 | main.log.info( "Number of flow batches at end of remove: " + str( len( main.addedBatchList ) ) ) |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 316 | |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 317 | main.step( "Check to ensure all flows are in added state." ) |
| 318 | #pprint( main.addedBatchList ) |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 319 | resp = main.FALSE |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 320 | while resp != main.TRUE and ( tAllRemoved - tLastDeleteEnd < int( main.params[ 'CASE3100' ][ 'chkFlowTO' ] ) ): |
| 321 | if main.params[ 'CASE3100' ][ 'RESTchkFlow' ] == 'main.TRUE': |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 322 | resp = main.ONOSrest.checkFlowsState() |
| 323 | else: |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 324 | handle = main.CLIs[ 0 ].flows( state=" |grep PEND|wc -l", jsonFormat=False ) |
| 325 | main.log.info( "handle returns PENDING flows: " + handle ) |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 326 | if handle == "0": |
| 327 | resp = main.TRUE |
| 328 | time.sleep( main.chkFlowSleep ) |
| 329 | tAllRemoved = time.time() |
| 330 | |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 331 | if tLastDeleteEnd - tLastDeleteEnd >= int( main.params[ 'CASE2100' ][ 'chkFlowTO' ] ): |
| 332 | main.log.warn( "ONOS Flows still in pending state after: {} seconds.".format( tAllRemoved - tLastDeleteEnd ) ) |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 333 | |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 334 | main.numFlows = int( main.params[ 'CASE1000' ][ 'batches' ] ) *\ |
| 335 | int( main.params[ 'CASE1000' ][ 'batchSize' ] ) |
| 336 | main.log.info( "Total number of flows: " + str( main.numFlows ) ) |
| 337 | main.elapseDELETE = tLastDeleteEnd - tStartDelete |
| 338 | main.log.info( "Total DELETE elapse time: " + str( main.elapseDELETE ) ) |
| 339 | main.log.info( "Rate of DELETE Controller response: " + str( main.numFlows / ( main.elapseDELETE ) ) ) |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 340 | |
| 341 | main.DELtoCONFRM = tAllRemoved - tLastDeleteEnd |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 342 | main.log.info( "Elapse time from end of last REST DELETE to Flows in REMOVED state: " + |
| 343 | str( main.DELtoCONFRM ) ) |
| 344 | main.log.info( "Rate of Confirmed Batch Flow REMOVED is ( flows/sec ): " + str( main.numFlows / main.DELtoCONFRM ) ) |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 345 | |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 346 | def CASE100( self, main ): |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 347 | from pprint import pprint |
| 348 | |
| 349 | main.case( "Check to ensure onos flows." ) |
| 350 | |
| 351 | resp = main.ONOSrest.checkFlowsState() |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 352 | #pprint( resp ) |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 353 | |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 354 | def CASE210( self, main ): |
| 355 | main.case( "Log test results to a data file" ) |
| 356 | main.step( "Write test resulted data to a data file" ) |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 357 | main.scale = main.maxNodes |
| 358 | |
| 359 | try: |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 360 | dbFileName = "/tmp/SCPFbatchFlowRespData" |
| 361 | dbfile = open( dbFileName, "w+" ) |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 362 | temp = "'" + main.commit + "'," |
YPZhang | 28909bc | 2016-06-20 13:29:11 -0700 | [diff] [blame] | 363 | temp += "'1gig'," |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 364 | temp += "'" + str( main.scale ) + "'," |
| 365 | temp += "'" + main.cluster + "'," |
| 366 | temp += "'" + str( main.elapsePOST ) + "'," |
| 367 | temp += "'" + str( main.POSTtoCONFRM ) + "'," |
YPZhang | 28909bc | 2016-06-20 13:29:11 -0700 | [diff] [blame] | 368 | temp += "'" + str( main.numFlows / main.POSTtoCONFRM ) + "'," |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 369 | temp += "'" + str( main.elapseDELETE ) + "'," |
| 370 | temp += "'" + str( main.DELtoCONFRM ) + "'," |
YPZhang | 28909bc | 2016-06-20 13:29:11 -0700 | [diff] [blame] | 371 | temp += "'" + str( main.numFlows / main.DELtoCONFRM ) + "'," |
| 372 | temp += "'" + str( main.numSw ) + "'\n" |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 373 | dbfile.write( temp ) |
| 374 | dbfile.close() |
| 375 | stepResult = main.TRUE |
| 376 | except IOError: |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 377 | main.log.warn( "Error opening " + dbFileName + " to write results." ) |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 378 | stepResult = main.FALSE |
| 379 | |
| 380 | utilities.assert_equals( expect=main.TRUE, |
| 381 | actual=stepResult, |
| 382 | onpass="Succeeded to write results to datafile", |
| 383 | onfail="Failed to write results to datafile " ) |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 384 | |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 385 | def CASE110( self, main ): |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 386 | """ |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 387 | Report errors/warnings/exceptions |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 388 | """ |
| 389 | main.log.info( "Error report: \n" ) |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 390 | main.ONOSbench.logReport( main.ONOSip[ 0 ], |
| 391 | [ "INFO", |
| 392 | "FOLLOWER", |
| 393 | "WARN", |
| 394 | "flow", |
| 395 | "ERROR", |
| 396 | "Except" ], |
| 397 | "s" ) |
| 398 | #main.stop() |
| 399 | |