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", |
Devin Lim | 461f087 | 2017-06-05 16:49:33 -0700 | [diff] [blame^] | 110 | main.Mininet1.ip_address, main.apps, |
| 111 | tempOnosIp, main.ONOScli1.user_name ) |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 112 | |
| 113 | main.step( "Apply cell to environment" ) |
| 114 | cellResult = main.ONOSbench.setCell( "temp" ) |
| 115 | verifyResult = main.ONOSbench.verifyCell() |
| 116 | stepResult = cellResult and verifyResult |
| 117 | utilities.assert_equals( expect=main.TRUE, |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 118 | actual=stepResult, |
| 119 | onpass="Successfully applied cell to " + |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 120 | "environment", |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 121 | onfail="Failed to apply cell to environment " ) |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 122 | |
| 123 | main.step( "Creating ONOS package" ) |
Jon Hall | bd60ea0 | 2016-08-23 10:03:59 -0700 | [diff] [blame] | 124 | packageResult = main.ONOSbench.buckBuild() |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 125 | stepResult = packageResult |
| 126 | utilities.assert_equals( expect=main.TRUE, |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 127 | actual=stepResult, |
| 128 | onpass="Successfully created ONOS package", |
| 129 | onfail="Failed to create ONOS package" ) |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 130 | time.sleep( main.startUpSleep ) |
| 131 | |
| 132 | main.step( "Uninstalling ONOS package" ) |
| 133 | onosUninstallResult = main.TRUE |
| 134 | for i in range( main.numCtrls ): |
| 135 | onosUninstallResult = onosUninstallResult and \ |
| 136 | main.ONOSbench.onosUninstall( nodeIp=main.ONOSip[ i ] ) |
| 137 | stepResult = onosUninstallResult |
| 138 | utilities.assert_equals( expect=main.TRUE, |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 139 | actual=stepResult, |
| 140 | onpass="Successfully uninstalled ONOS package", |
| 141 | onfail="Failed to uninstall ONOS package" ) |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 142 | time.sleep( main.startUpSleep ) |
| 143 | |
| 144 | else: |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 145 | main.log.info( "onos Packaging Skipped!" ) |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 146 | |
| 147 | main.step( "Installing ONOS package" ) |
| 148 | onosInstallResult = main.TRUE |
| 149 | for i in range( main.numCtrls ): |
| 150 | onosInstallResult = onosInstallResult and \ |
| 151 | main.ONOSbench.onosInstall( node=main.ONOSip[ i ] ) |
| 152 | stepResult = onosInstallResult |
| 153 | utilities.assert_equals( expect=main.TRUE, |
| 154 | actual=stepResult, |
| 155 | onpass="Successfully installed ONOS package", |
| 156 | onfail="Failed to install ONOS package" ) |
| 157 | time.sleep( main.startUpSleep ) |
| 158 | |
You Wang | 5259021 | 2017-05-04 17:35:20 -0700 | [diff] [blame] | 159 | main.step( "Set up ONOS secure SSH" ) |
| 160 | secureSshResult = main.TRUE |
| 161 | for i in range( main.numCtrls ): |
| 162 | secureSshResult = secureSshResult and main.ONOSbench.onosSecureSSH( node=main.ONOSip[ i ] ) |
| 163 | utilities.assert_equals( expect=main.TRUE, actual=secureSshResult, |
| 164 | onpass="Test step PASS", |
| 165 | onfail="Test step FAIL" ) |
| 166 | |
| 167 | time.sleep( main.startUpSleep ) |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 168 | main.step( "Starting ONOS service" ) |
| 169 | stopResult = main.TRUE |
| 170 | startResult = main.TRUE |
| 171 | onosIsUp = main.TRUE |
| 172 | |
| 173 | for i in range( main.numCtrls ): |
| 174 | onosIsUp = onosIsUp and main.ONOSbench.isup( main.ONOSip[ i ] ) |
| 175 | if onosIsUp == main.TRUE: |
| 176 | main.log.report( "ONOS instance is up and ready" ) |
| 177 | else: |
| 178 | main.log.report( "ONOS instance may not be up, stop and " + |
| 179 | "start ONOS again " ) |
| 180 | for i in range( main.numCtrls ): |
| 181 | stopResult = stopResult and \ |
| 182 | main.ONOSbench.onosStop( main.ONOSip[ i ] ) |
| 183 | for i in range( main.numCtrls ): |
| 184 | startResult = startResult and \ |
| 185 | main.ONOSbench.onosStart( main.ONOSip[ i ] ) |
| 186 | stepResult = onosIsUp and stopResult and startResult |
| 187 | utilities.assert_equals( expect=main.TRUE, |
| 188 | actual=stepResult, |
| 189 | onpass="ONOS service is ready", |
| 190 | onfail="ONOS service did not start properly" ) |
| 191 | |
| 192 | main.step( "Start ONOS cli" ) |
| 193 | cliResult = main.TRUE |
| 194 | for i in range( i, main.numCtrls ): |
| 195 | cliResult = cliResult and \ |
You Wang | 5259021 | 2017-05-04 17:35:20 -0700 | [diff] [blame] | 196 | main.ONOScli1.startOnosCli( main.ONOSip[ i ] ) |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 197 | stepResult = cliResult |
| 198 | utilities.assert_equals( expect=main.TRUE, |
| 199 | actual=stepResult, |
| 200 | onpass="Successfully start ONOS cli", |
| 201 | onfail="Failed to start ONOS cli" ) |
| 202 | |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 203 | def CASE10( self, main ): |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 204 | """ |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 205 | Start Mininet |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 206 | """ |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 207 | import time |
| 208 | |
| 209 | main.case( "Enable openflow-base on onos and start Mininet." ) |
| 210 | |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 211 | main.step( "Activate openflow-base App" ) |
| 212 | app = main.params[ 'CASE10' ][ 'app' ] |
YPZhang | 5d0552f | 2016-05-18 13:02:52 -0700 | [diff] [blame] | 213 | stepResult = main.ONOScli1.activateApp( app ) |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 214 | time.sleep( main.cfgSleep ) |
| 215 | main.log.info( stepResult ) |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 216 | utilities.assert_equals( expect=main.TRUE, |
| 217 | actual=stepResult, |
| 218 | onpass="Successfully activate " + app, |
| 219 | onfail="Failed to activate app " + app ) |
| 220 | |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 221 | time.sleep( main.cfgSleep ) |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 222 | |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 223 | main.step( "Configure AdaptiveFlowSampling " ) |
| 224 | stepResult = main.ONOScli1.setCfg( component="org.onosproject.provider.of.flow.impl.OpenFlowRuleProvider", |
| 225 | propName="adaptiveFlowSampling ", value=main.params[ 'CASE10' ][ 'adaptiveFlowenabled' ] ) |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 226 | utilities.assert_equals( expect=main.TRUE, |
| 227 | actual=stepResult, |
| 228 | onpass="App Configuration Succeeded! ", |
| 229 | onfail="App Configuration Failed!" ) |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 230 | time.sleep( main.cfgSleep ) |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 231 | |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 232 | main.step( "Setup Mininet Linear Topology with " + str( main.numSw ) + " switches" ) |
| 233 | argStr = main.params[ 'CASE10' ][ 'mnArgs' ].format( main.numSw ) |
| 234 | stepResult = main.Mininet1.startNet( args=argStr ) |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 235 | |
| 236 | utilities.assert_equals( expect=main.TRUE, |
| 237 | actual=stepResult, |
| 238 | onpass="Successfully loaded topology", |
| 239 | onfail="Failed to load topology" ) |
| 240 | |
| 241 | time.sleep( main.startMNSleep ) |
| 242 | |
| 243 | main.step( "Assign switches to controller" ) |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 244 | for i in range( 1, main.numSw + 1 ): |
| 245 | main.Mininet1.assignSwController( "s" + str( i ), main.ONOSip[ 0 ] ) |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 246 | |
| 247 | utilities.assert_equals( expect=main.TRUE, |
| 248 | actual=stepResult, |
| 249 | onpass="Successfully assigned switch to controller", |
| 250 | onfail="Failed to assign switch to controller" ) |
| 251 | |
| 252 | main.deviceIdPrefix = "of:" |
| 253 | |
| 254 | time.sleep( main.startMNSleep ) |
| 255 | |
| 256 | def CASE11( self, main ): |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 257 | """ |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 258 | Start Null Provider |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 259 | """ |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 260 | import time |
| 261 | |
| 262 | main.case( "Setup Null Provider for linear Topology" ) |
| 263 | |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 264 | main.step( "Activate Null Provider App" ) |
| 265 | stepResult = main.ONOSbench.onosCli( ONOSIp=main.ONOSip[ 0 ], |
| 266 | cmdstr="app activate org.onosproject.null" ) |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 267 | utilities.assert_equals( expect=main.TRUE, |
| 268 | actual=stepResult, |
| 269 | onpass="Successfully activated org.onosproject.null", |
| 270 | onfail="Failed to activate org.onosproject.null" ) |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 271 | time.sleep( main.cfgSleep ) |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 272 | |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 273 | main.step( "Setup Null Provider Linear Topology with " + str( main.numSw ) + " devices." ) |
| 274 | r1 = main.ONOSbench.onosCfgSet( main.ONOSip[ 0 ], "org.onosproject.provider.nil.NullProviders", "deviceCount " + str( main.numSw ) ) |
| 275 | r2 = main.ONOSbench.onosCfgSet( main.ONOSip[ 0 ], "org.onosproject.provider.nil.NullProviders", "topoShape " + main.params[ 'CASE11' ][ 'nullTopo' ] ) |
| 276 | 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] | 277 | stepResult = r1 & r2 & r3 |
| 278 | utilities.assert_equals( expect=main.TRUE, |
| 279 | actual=stepResult, |
| 280 | onpass="App Configuration Succeeded! ", |
| 281 | onfail="App Configuration Failed!" ) |
| 282 | time.sleep( main.cfgSleep ) |
| 283 | |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 284 | main.log.info( "Check to make sure null providers are configured correctly." ) |
| 285 | main.ONOSbench.handle.sendline( "onos $OC1 summary" ) |
| 286 | stepResult = main.ONOSbench.handle.expect( ":~" ) |
| 287 | main.log.info( "ONOS Summary: " + main.ONOSbench.handle.before ) |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 288 | |
| 289 | main.deviceIdPrefix = "null:" |
| 290 | |
| 291 | time.sleep( main.startMNSleep ) |
| 292 | |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 293 | def CASE1000( self, main ): |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 294 | """ |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 295 | create JSON object with batched flows |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 296 | """ |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 297 | import numpy |
| 298 | import time |
| 299 | from pprint import pprint |
| 300 | |
| 301 | main.case( "Create a json object for the batched flows" ) |
| 302 | |
| 303 | main.step( "Parse batch creation information" ) |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 304 | main.batchSize = int( main.params[ 'CASE1000' ][ 'batchSize' ] ) |
| 305 | 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] | 306 | |
| 307 | main.flowJsonBatchList = [] |
| 308 | startSw = 1 |
| 309 | |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 310 | main.step( "Creating a full list of batches" ) |
| 311 | for index in range( 1, int( main.params[ 'CASE1000' ][ 'batches' ] ) + 1 ): |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 312 | if startSw <= main.numSw: |
| 313 | ind = startSw |
| 314 | else: |
| 315 | startSw = 1 |
| 316 | ind = startSw |
| 317 | |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 318 | main.log.info( "Creating batch: " + str( index ) ) |
| 319 | flowJsonBatch = main.ONOSrest.createFlowBatch( numSw=main.numSw, |
| 320 | swIndex=ind, |
| 321 | batchSize=main.batchSize, |
| 322 | batchIndex=index, |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 323 | deviceIdpreFix=main.deviceIdPrefix, |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 324 | ingressPort=2, |
| 325 | egressPort=3 ) |
| 326 | main.flowJsonBatchList.append( flowJsonBatch ) |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 327 | |
| 328 | startSw += 1 |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 329 | 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] | 330 | |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 331 | def CASE2100( self, main ): |
| 332 | """ |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 333 | Posting flow batches using threads |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 334 | """ |
| 335 | main.case( "Using REST API /flows/{} to post flow batch - multi-threads" ) |
| 336 | main.step( "Using REST API /flows/{} to post flow batch - multi-threads" ) |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 337 | |
| 338 | from Queue import Queue |
| 339 | from threading import Thread |
| 340 | import time |
| 341 | import json |
| 342 | |
| 343 | main.threadID = 0 |
| 344 | main.addedBatchList = [] |
| 345 | q = Queue() |
| 346 | tAllAdded = 0 |
You Wang | 7b5b226 | 2016-11-10 13:54:56 -0800 | [diff] [blame] | 347 | main.postFailed = False |
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 | def postWorker( id ): |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 350 | while True: |
| 351 | item = q.get() |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 352 | #print json.dumps( item ) |
| 353 | status, response = main.ONOSrest.sendFlowBatch( batch=item ) |
You Wang | 7b5b226 | 2016-11-10 13:54:56 -0800 | [diff] [blame] | 354 | if status == main.TRUE: |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 355 | main.log.info( "Thread {} is working on posting. ".format( id ) ) |
| 356 | #print json.dumps( response ) |
| 357 | main.addedBatchList.append( response[ 1 ] ) |
You Wang | 7b5b226 | 2016-11-10 13:54:56 -0800 | [diff] [blame] | 358 | else: |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 359 | main.log.error( "Thread {} failed to post.".format( id ) ) |
You Wang | 7b5b226 | 2016-11-10 13:54:56 -0800 | [diff] [blame] | 360 | main.postFailed = True |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 361 | q.task_done() |
| 362 | |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 363 | for i in range( int( main.params[ 'CASE2100' ][ 'numThreads' ] ) ): |
| 364 | threadID = "ThreadID-" + str( i ) |
| 365 | t = Thread( target=postWorker, name=threadID, args=( threadID, ) ) |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 366 | t.daemon = True |
| 367 | t.start() |
| 368 | |
| 369 | tStartPost = time.time() |
| 370 | for item in main.flowJsonBatchList: |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 371 | q.put( item ) |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 372 | |
| 373 | q.join() |
| 374 | tLastPostEnd = time.time() |
You Wang | 7b5b226 | 2016-11-10 13:54:56 -0800 | [diff] [blame] | 375 | if main.postFailed: |
| 376 | main.log.error( "Flow batch posting failed, exit test" ) |
| 377 | main.cleanup() |
| 378 | main.exit() |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 379 | |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 380 | main.step( "Check to ensure all flows are in added state." ) |
| 381 | #pprint( main.addedBatchList ) |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 382 | resp = main.FALSE |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 383 | while resp != main.TRUE and ( tAllAdded - tLastPostEnd < int( main.params[ 'CASE2100' ][ 'chkFlowTO' ] ) ): |
| 384 | if main.params[ 'CASE2100' ][ 'RESTchkFlow' ] == 'main.TRUE': |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 385 | resp = main.ONOSrest.checkFlowsState() |
| 386 | else: |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 387 | handle = main.CLIs[ 0 ].flows( state=" |grep PEND|wc -l", jsonFormat=False ) |
| 388 | main.log.info( "handle returns PENDING flows: " + handle ) |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 389 | if handle == "0": |
| 390 | resp = main.TRUE |
| 391 | |
| 392 | time.sleep( main.chkFlowSleep ) |
| 393 | tAllAdded = time.time() |
| 394 | |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 395 | if tAllAdded - tLastPostEnd >= int( main.params[ 'CASE2100' ][ 'chkFlowTO' ] ): |
| 396 | 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] | 397 | |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 398 | main.numFlows = int( main.params[ 'CASE1000' ][ 'batches' ] ) *\ |
| 399 | int( main.params[ 'CASE1000' ][ 'batchSize' ] ) |
| 400 | main.log.info( "Total number of flows: " + str( main.numFlows ) ) |
| 401 | main.elapsePOST = tLastPostEnd - tStartPost |
| 402 | main.log.info( "Total POST elapse time: " + str( main.elapsePOST ) ) |
| 403 | 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] | 404 | |
| 405 | main.POSTtoCONFRM = tAllAdded - tLastPostEnd |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 406 | main.log.info( "Elapse time from end of last REST POST to Flows in ADDED state: " + |
| 407 | str( main.POSTtoCONFRM ) ) |
| 408 | main.log.info( "Rate of Confirmed Batch Flow ADD is ( flows/sec ): " + |
| 409 | str( main.numFlows / main.POSTtoCONFRM ) ) |
| 410 | main.log.info( "Number of flow Batches in the addedBatchList is: " + |
| 411 | str( len( main.addedBatchList ) ) ) |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 412 | |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 413 | def CASE3100( self, main ): |
| 414 | """ |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 415 | DELETE flow batches using threads |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 416 | """ |
| 417 | main.case( "Using REST API /flows/{} to delete flow batch - multi-threads" ) |
| 418 | main.step( "Using REST API /flows/{} to delete flow batch - multi-threads" ) |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 419 | |
| 420 | from Queue import Queue |
| 421 | from threading import Thread |
| 422 | import time |
| 423 | import json |
| 424 | |
| 425 | main.threadID = 0 |
| 426 | q = Queue() |
| 427 | tAllRemoved = 0 |
| 428 | |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 429 | main.log.info( "Number of flow batches at start of remove: " + str( len( main.addedBatchList ) ) ) |
| 430 | |
| 431 | def removeWorker( id ): |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 432 | while True: |
| 433 | item = q.get() |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 434 | response = main.ONOSrest.removeFlowBatch( batch=json.loads( item ) ) |
| 435 | main.log.info( "Thread {} is working on deleting. ".format( id ) ) |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 436 | q.task_done() |
| 437 | |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 438 | for i in range( int( main.params[ 'CASE2100' ][ 'numThreads' ] ) ): |
| 439 | threadID = "ThreadID-" + str( i ) |
| 440 | t = Thread( target=removeWorker, name=threadID, args=( threadID, ) ) |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 441 | t.daemon = True |
| 442 | t.start() |
| 443 | |
| 444 | tStartDelete = time.time() |
| 445 | for item in main.addedBatchList: |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 446 | q.put( item ) |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 447 | |
| 448 | q.join() |
| 449 | tLastDeleteEnd = time.time() |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 450 | 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] | 451 | |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 452 | main.step( "Check to ensure all flows are in added state." ) |
| 453 | #pprint( main.addedBatchList ) |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 454 | resp = main.FALSE |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 455 | while resp != main.TRUE and ( tAllRemoved - tLastDeleteEnd < int( main.params[ 'CASE3100' ][ 'chkFlowTO' ] ) ): |
| 456 | if main.params[ 'CASE3100' ][ 'RESTchkFlow' ] == 'main.TRUE': |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 457 | resp = main.ONOSrest.checkFlowsState() |
| 458 | else: |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 459 | handle = main.CLIs[ 0 ].flows( state=" |grep PEND|wc -l", jsonFormat=False ) |
| 460 | main.log.info( "handle returns PENDING flows: " + handle ) |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 461 | if handle == "0": |
| 462 | resp = main.TRUE |
| 463 | time.sleep( main.chkFlowSleep ) |
| 464 | tAllRemoved = time.time() |
| 465 | |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 466 | if tLastDeleteEnd - tLastDeleteEnd >= int( main.params[ 'CASE2100' ][ 'chkFlowTO' ] ): |
| 467 | 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] | 468 | |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 469 | main.numFlows = int( main.params[ 'CASE1000' ][ 'batches' ] ) *\ |
| 470 | int( main.params[ 'CASE1000' ][ 'batchSize' ] ) |
| 471 | main.log.info( "Total number of flows: " + str( main.numFlows ) ) |
| 472 | main.elapseDELETE = tLastDeleteEnd - tStartDelete |
| 473 | main.log.info( "Total DELETE elapse time: " + str( main.elapseDELETE ) ) |
| 474 | 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] | 475 | |
| 476 | main.DELtoCONFRM = tAllRemoved - tLastDeleteEnd |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 477 | main.log.info( "Elapse time from end of last REST DELETE to Flows in REMOVED state: " + |
| 478 | str( main.DELtoCONFRM ) ) |
| 479 | 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] | 480 | |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 481 | def CASE100( self, main ): |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 482 | from pprint import pprint |
| 483 | |
| 484 | main.case( "Check to ensure onos flows." ) |
| 485 | |
| 486 | resp = main.ONOSrest.checkFlowsState() |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 487 | #pprint( resp ) |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 488 | |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 489 | def CASE210( self, main ): |
| 490 | main.case( "Log test results to a data file" ) |
| 491 | main.step( "Write test resulted data to a data file" ) |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 492 | main.scale = main.maxNodes |
| 493 | |
| 494 | try: |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 495 | dbFileName = "/tmp/SCPFbatchFlowRespData" |
| 496 | dbfile = open( dbFileName, "w+" ) |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 497 | temp = "'" + main.commit + "'," |
YPZhang | 28909bc | 2016-06-20 13:29:11 -0700 | [diff] [blame] | 498 | temp += "'1gig'," |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 499 | temp += "'" + str( main.scale ) + "'," |
| 500 | temp += "'" + main.cluster + "'," |
| 501 | temp += "'" + str( main.elapsePOST ) + "'," |
| 502 | temp += "'" + str( main.POSTtoCONFRM ) + "'," |
YPZhang | 28909bc | 2016-06-20 13:29:11 -0700 | [diff] [blame] | 503 | temp += "'" + str( main.numFlows / main.POSTtoCONFRM ) + "'," |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 504 | temp += "'" + str( main.elapseDELETE ) + "'," |
| 505 | temp += "'" + str( main.DELtoCONFRM ) + "'," |
YPZhang | 28909bc | 2016-06-20 13:29:11 -0700 | [diff] [blame] | 506 | temp += "'" + str( main.numFlows / main.DELtoCONFRM ) + "'," |
| 507 | temp += "'" + str( main.numSw ) + "'\n" |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 508 | dbfile.write( temp ) |
| 509 | dbfile.close() |
| 510 | stepResult = main.TRUE |
| 511 | except IOError: |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 512 | main.log.warn( "Error opening " + dbFileName + " to write results." ) |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 513 | stepResult = main.FALSE |
| 514 | |
| 515 | utilities.assert_equals( expect=main.TRUE, |
| 516 | actual=stepResult, |
| 517 | onpass="Succeeded to write results to datafile", |
| 518 | onfail="Failed to write results to datafile " ) |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 519 | |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 520 | def CASE110( self, main ): |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 521 | """ |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 522 | Report errors/warnings/exceptions |
Jon Hall | 5c3ff72 | 2017-05-24 17:24:59 -0700 | [diff] [blame] | 523 | """ |
| 524 | main.log.info( "Error report: \n" ) |
suibin zhang | 1730862 | 2016-04-14 15:45:30 -0700 | [diff] [blame] | 525 | main.ONOSbench.logReport( main.ONOSip[ 0 ], |
| 526 | [ "INFO", |
| 527 | "FOLLOWER", |
| 528 | "WARN", |
| 529 | "flow", |
| 530 | "ERROR", |
| 531 | "Except" ], |
| 532 | "s" ) |
| 533 | #main.stop() |
| 534 | |