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 |
| 21 | - Building ONOS ( optional ) |
| 22 | - Install ONOS package |
| 23 | - Build ONOS package |
| 24 | """ |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 25 | main.case( "Constructing test variables and building ONOS package" ) |
| 26 | main.step( "Constructing test variables" ) |
| 27 | |
| 28 | # Test variables |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 29 | main.testOnDirectory = os.path.dirname( os.getcwd() ) |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 30 | 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 Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 34 | 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 zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 44 | main.CLIs = [] |
| 45 | main.ONOSip = [] |
YPZhang | 28909bc | 2016-06-20 13:29:11 -0700 | [diff] [blame] | 46 | |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 47 | main.ONOSip = main.ONOSbench.getOnosIps() |
| 48 | main.commit = main.ONOSbench.getVersion() |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 49 | main.commit = main.commit.split( " " )[ 1 ] |
YPZhang | 28909bc | 2016-06-20 13:29:11 -0700 | [diff] [blame] | 50 | |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 51 | main.cluster = main.params[ 'GLOBAL' ][ 'cluster' ] |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 52 | |
| 53 | # Assigning ONOS cli handles to a list |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 54 | for i in range( 1, main.maxNodes + 1 ): |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 55 | main.CLIs.append( getattr( main, 'ONOScli' + str( i ) ) ) |
| 56 | |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 57 | 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 zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 95 | main.numCtrls = int( main.maxNodes ) |
| 96 | |
| 97 | main.case( "Starting up " + str( main.numCtrls ) + |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 98 | " node( s ) ONOS cluster" ) |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 99 | |
| 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 Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 105 | tempOnosIp.append( main.ONOSip[ i ] ) |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 106 | |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 107 | if main.params[ 'CASE2' ][ 'incPackaging' ] == "true": |
| 108 | main.step( "Create onos cell file with: " + main.apps ) |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 109 | main.ONOSbench.createCellFile( main.ONOSbench.ip_address, "temp", |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 110 | main.Mininet1.ip_address, main.apps, tempOnosIp ) |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 111 | |
| 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 Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 117 | actual=stepResult, |
| 118 | onpass="Successfully applied cell to " + |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 119 | "environment", |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 120 | onfail="Failed to apply cell to environment " ) |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 121 | |
| 122 | main.step( "Creating ONOS package" ) |
Jon Hall | bd60ea0 | 2016-08-23 10:03:59 -0700 | [diff] [blame] | 123 | packageResult = main.ONOSbench.buckBuild() |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 124 | stepResult = packageResult |
| 125 | utilities.assert_equals( expect=main.TRUE, |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 126 | actual=stepResult, |
| 127 | onpass="Successfully created ONOS package", |
| 128 | onfail="Failed to create ONOS package" ) |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 129 | 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 Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 138 | actual=stepResult, |
| 139 | onpass="Successfully uninstalled ONOS package", |
| 140 | onfail="Failed to uninstall ONOS package" ) |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 141 | time.sleep( main.startUpSleep ) |
| 142 | |
| 143 | else: |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 144 | main.log.info( "onos Packaging Skipped!" ) |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 145 | |
| 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 Wang | 5259021 | 2017-05-04 17:35:20 -0700 | [diff] [blame] | 158 | 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 zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 167 | 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 Wang | 5259021 | 2017-05-04 17:35:20 -0700 | [diff] [blame] | 195 | main.ONOScli1.startOnosCli( main.ONOSip[ i ] ) |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 196 | 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 zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 202 | def CASE10( self, main ): |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 203 | """ |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 204 | Start Mininet |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 205 | """ |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 206 | import time |
| 207 | |
| 208 | main.case( "Enable openflow-base on onos and start Mininet." ) |
| 209 | |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 210 | main.step( "Activate openflow-base App" ) |
| 211 | app = main.params[ 'CASE10' ][ 'app' ] |
YPZhang | 5d0552f | 2016-05-18 13:02:52 -0700 | [diff] [blame] | 212 | stepResult = main.ONOScli1.activateApp( app ) |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 213 | time.sleep( main.cfgSleep ) |
| 214 | main.log.info( stepResult ) |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 215 | utilities.assert_equals( expect=main.TRUE, |
| 216 | actual=stepResult, |
| 217 | onpass="Successfully activate " + app, |
| 218 | onfail="Failed to activate app " + app ) |
| 219 | |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 220 | time.sleep( main.cfgSleep ) |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 221 | |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 222 | 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 zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 225 | utilities.assert_equals( expect=main.TRUE, |
| 226 | actual=stepResult, |
| 227 | onpass="App Configuration Succeeded! ", |
| 228 | onfail="App Configuration Failed!" ) |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 229 | time.sleep( main.cfgSleep ) |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 230 | |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 231 | 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 zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 234 | |
| 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 Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 243 | for i in range( 1, main.numSw + 1 ): |
| 244 | main.Mininet1.assignSwController( "s" + str( i ), main.ONOSip[ 0 ] ) |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 245 | |
| 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 Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 256 | """ |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 257 | Start Null Provider |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 258 | """ |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 259 | import time |
| 260 | |
| 261 | main.case( "Setup Null Provider for linear Topology" ) |
| 262 | |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 263 | main.step( "Activate Null Provider App" ) |
| 264 | stepResult = main.ONOSbench.onosCli( ONOSIp=main.ONOSip[ 0 ], |
| 265 | cmdstr="app activate org.onosproject.null" ) |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 266 | 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 Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 270 | time.sleep( main.cfgSleep ) |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 271 | |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 272 | 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 zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 276 | 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 Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 283 | 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 zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 287 | |
| 288 | main.deviceIdPrefix = "null:" |
| 289 | |
| 290 | time.sleep( main.startMNSleep ) |
| 291 | |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 292 | def CASE1000( self, main ): |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 293 | """ |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 294 | create JSON object with batched flows |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 295 | """ |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 296 | 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 Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 303 | main.batchSize = int( main.params[ 'CASE1000' ][ 'batchSize' ] ) |
| 304 | 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] | 305 | |
| 306 | main.flowJsonBatchList = [] |
| 307 | startSw = 1 |
| 308 | |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 309 | main.step( "Creating a full list of batches" ) |
| 310 | for index in range( 1, int( main.params[ 'CASE1000' ][ 'batches' ] ) + 1 ): |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 311 | if startSw <= main.numSw: |
| 312 | ind = startSw |
| 313 | else: |
| 314 | startSw = 1 |
| 315 | ind = startSw |
| 316 | |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 317 | 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 zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 322 | deviceIdpreFix=main.deviceIdPrefix, |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 323 | ingressPort=2, |
| 324 | egressPort=3 ) |
| 325 | main.flowJsonBatchList.append( flowJsonBatch ) |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 326 | |
| 327 | startSw += 1 |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 328 | 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] | 329 | |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 330 | def CASE2100( self, main ): |
| 331 | """ |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 332 | Posting flow batches using threads |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 333 | """ |
| 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 zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 336 | |
| 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 Wang | 7b5b226 | 2016-11-10 13:54:56 -0800 | [diff] [blame] | 346 | main.postFailed = False |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 347 | |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 348 | def postWorker( id ): |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 349 | while True: |
| 350 | item = q.get() |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 351 | #print json.dumps( item ) |
| 352 | status, response = main.ONOSrest.sendFlowBatch( batch=item ) |
You Wang | 7b5b226 | 2016-11-10 13:54:56 -0800 | [diff] [blame] | 353 | if status == main.TRUE: |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 354 | main.log.info( "Thread {} is working on posting. ".format( id ) ) |
| 355 | #print json.dumps( response ) |
| 356 | main.addedBatchList.append( response[ 1 ] ) |
You Wang | 7b5b226 | 2016-11-10 13:54:56 -0800 | [diff] [blame] | 357 | else: |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 358 | main.log.error( "Thread {} failed to post.".format( id ) ) |
You Wang | 7b5b226 | 2016-11-10 13:54:56 -0800 | [diff] [blame] | 359 | main.postFailed = True |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 360 | q.task_done() |
| 361 | |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 362 | for i in range( int( main.params[ 'CASE2100' ][ 'numThreads' ] ) ): |
| 363 | threadID = "ThreadID-" + str( i ) |
| 364 | t = Thread( target=postWorker, name=threadID, args=( threadID, ) ) |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 365 | t.daemon = True |
| 366 | t.start() |
| 367 | |
| 368 | tStartPost = time.time() |
| 369 | for item in main.flowJsonBatchList: |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 370 | q.put( item ) |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 371 | |
| 372 | q.join() |
| 373 | tLastPostEnd = time.time() |
You Wang | 7b5b226 | 2016-11-10 13:54:56 -0800 | [diff] [blame] | 374 | if main.postFailed: |
| 375 | main.log.error( "Flow batch posting failed, exit test" ) |
| 376 | main.cleanup() |
| 377 | main.exit() |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 378 | |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 379 | main.step( "Check to ensure all flows are in added state." ) |
| 380 | #pprint( main.addedBatchList ) |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 381 | resp = main.FALSE |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 382 | while resp != main.TRUE and ( tAllAdded - tLastPostEnd < int( main.params[ 'CASE2100' ][ 'chkFlowTO' ] ) ): |
| 383 | if main.params[ 'CASE2100' ][ 'RESTchkFlow' ] == 'main.TRUE': |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 384 | resp = main.ONOSrest.checkFlowsState() |
| 385 | else: |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 386 | handle = main.CLIs[ 0 ].flows( state=" |grep PEND|wc -l", jsonFormat=False ) |
| 387 | main.log.info( "handle returns PENDING flows: " + handle ) |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 388 | if handle == "0": |
| 389 | resp = main.TRUE |
| 390 | |
| 391 | time.sleep( main.chkFlowSleep ) |
| 392 | tAllAdded = time.time() |
| 393 | |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 394 | if tAllAdded - tLastPostEnd >= int( main.params[ 'CASE2100' ][ 'chkFlowTO' ] ): |
| 395 | 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] | 396 | |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 397 | 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 zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 403 | |
| 404 | main.POSTtoCONFRM = tAllAdded - tLastPostEnd |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 405 | 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 zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 411 | |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 412 | def CASE3100( self, main ): |
| 413 | """ |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 414 | DELETE flow batches using threads |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 415 | """ |
| 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 zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 418 | |
| 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 Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 428 | main.log.info( "Number of flow batches at start of remove: " + str( len( main.addedBatchList ) ) ) |
| 429 | |
| 430 | def removeWorker( id ): |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 431 | while True: |
| 432 | item = q.get() |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 433 | response = main.ONOSrest.removeFlowBatch( batch=json.loads( item ) ) |
| 434 | main.log.info( "Thread {} is working on deleting. ".format( id ) ) |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 435 | q.task_done() |
| 436 | |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 437 | for i in range( int( main.params[ 'CASE2100' ][ 'numThreads' ] ) ): |
| 438 | threadID = "ThreadID-" + str( i ) |
| 439 | t = Thread( target=removeWorker, name=threadID, args=( threadID, ) ) |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 440 | t.daemon = True |
| 441 | t.start() |
| 442 | |
| 443 | tStartDelete = time.time() |
| 444 | for item in main.addedBatchList: |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 445 | q.put( item ) |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 446 | |
| 447 | q.join() |
| 448 | tLastDeleteEnd = time.time() |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 449 | 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] | 450 | |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 451 | main.step( "Check to ensure all flows are in added state." ) |
| 452 | #pprint( main.addedBatchList ) |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 453 | resp = main.FALSE |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 454 | while resp != main.TRUE and ( tAllRemoved - tLastDeleteEnd < int( main.params[ 'CASE3100' ][ 'chkFlowTO' ] ) ): |
| 455 | if main.params[ 'CASE3100' ][ 'RESTchkFlow' ] == 'main.TRUE': |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 456 | resp = main.ONOSrest.checkFlowsState() |
| 457 | else: |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 458 | handle = main.CLIs[ 0 ].flows( state=" |grep PEND|wc -l", jsonFormat=False ) |
| 459 | main.log.info( "handle returns PENDING flows: " + handle ) |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 460 | if handle == "0": |
| 461 | resp = main.TRUE |
| 462 | time.sleep( main.chkFlowSleep ) |
| 463 | tAllRemoved = time.time() |
| 464 | |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 465 | if tLastDeleteEnd - tLastDeleteEnd >= int( main.params[ 'CASE2100' ][ 'chkFlowTO' ] ): |
| 466 | 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] | 467 | |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 468 | 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 zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 474 | |
| 475 | main.DELtoCONFRM = tAllRemoved - tLastDeleteEnd |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 476 | 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 zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 479 | |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 480 | def CASE100( self, main ): |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 481 | from pprint import pprint |
| 482 | |
| 483 | main.case( "Check to ensure onos flows." ) |
| 484 | |
| 485 | resp = main.ONOSrest.checkFlowsState() |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 486 | #pprint( resp ) |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 487 | |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 488 | 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 zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 491 | main.scale = main.maxNodes |
| 492 | |
| 493 | try: |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 494 | dbFileName = "/tmp/SCPFbatchFlowRespData" |
| 495 | dbfile = open( dbFileName, "w+" ) |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 496 | temp = "'" + main.commit + "'," |
YPZhang | 28909bc | 2016-06-20 13:29:11 -0700 | [diff] [blame] | 497 | temp += "'1gig'," |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 498 | temp += "'" + str( main.scale ) + "'," |
| 499 | temp += "'" + main.cluster + "'," |
| 500 | temp += "'" + str( main.elapsePOST ) + "'," |
| 501 | temp += "'" + str( main.POSTtoCONFRM ) + "'," |
YPZhang | 28909bc | 2016-06-20 13:29:11 -0700 | [diff] [blame] | 502 | temp += "'" + str( main.numFlows / main.POSTtoCONFRM ) + "'," |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 503 | temp += "'" + str( main.elapseDELETE ) + "'," |
| 504 | temp += "'" + str( main.DELtoCONFRM ) + "'," |
YPZhang | 28909bc | 2016-06-20 13:29:11 -0700 | [diff] [blame] | 505 | temp += "'" + str( main.numFlows / main.DELtoCONFRM ) + "'," |
| 506 | temp += "'" + str( main.numSw ) + "'\n" |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 507 | dbfile.write( temp ) |
| 508 | dbfile.close() |
| 509 | stepResult = main.TRUE |
| 510 | except IOError: |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 511 | main.log.warn( "Error opening " + dbFileName + " to write results." ) |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 512 | 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 Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 518 | |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 519 | def CASE110( self, main ): |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 520 | """ |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 521 | Report errors/warnings/exceptions |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 522 | """ |
| 523 | main.log.info( "Error report: \n" ) |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 524 | main.ONOSbench.logReport( main.ONOSip[ 0 ], |
| 525 | [ "INFO", |
| 526 | "FOLLOWER", |
| 527 | "WARN", |
| 528 | "flow", |
| 529 | "ERROR", |
| 530 | "Except" ], |
| 531 | "s" ) |
| 532 | #main.stop() |
| 533 | |