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