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