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