YPZhang | cb86c5b | 2016-01-27 17:38:12 -0800 | [diff] [blame] | 1 | import sys |
| 2 | import json |
| 3 | import time |
| 4 | import os |
| 5 | ''' |
| 6 | SCPFscalingMaxIntents |
| 7 | Push test Intents to onos |
| 8 | CASE10: set up Null Provider |
| 9 | CASE11: set up Open Flows |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 10 | Check flows number, if flows number is not as except, finished this test iteration |
YPZhang | cb86c5b | 2016-01-27 17:38:12 -0800 | [diff] [blame] | 11 | Scale up when reach the Limited |
| 12 | Start from 1 nodes, 8 devices. Then Scale up to 3,5,7 nodes |
YPZhang | cb86c5b | 2016-01-27 17:38:12 -0800 | [diff] [blame] | 13 | ''' |
| 14 | class SCPFscalingMaxIntents: |
| 15 | def __init__( self ): |
| 16 | self.default = '' |
| 17 | |
| 18 | def CASE0( self, main): |
| 19 | import sys |
| 20 | import json |
| 21 | import time |
| 22 | import os |
| 23 | import imp |
| 24 | |
| 25 | main.case( "Constructing test variables and building ONOS package" ) |
| 26 | main.step( "Constructing test variables" ) |
| 27 | stepResult = main.FALSE |
| 28 | |
| 29 | # Test variables |
| 30 | main.testOnDirectory = os.path.dirname( os.getcwd ( ) ) |
| 31 | main.dependencyPath = main.testOnDirectory + \ |
| 32 | main.params['DEPENDENCY']['path'] |
| 33 | main.cellName = main.params[ 'ENV' ][ 'cellName' ] |
| 34 | main.apps = main.params[ 'ENV' ][ 'cellApps' ] |
| 35 | main.topology = main.params[ 'DEPENDENCY' ][ 'topology' ] |
| 36 | main.scale = ( main.params[ 'SCALE' ] ).split( "," ) |
| 37 | main.ONOSport = main.params[ 'CTRL' ][ 'port' ] |
| 38 | main.timeout = int(main.params['SLEEP']['timeout']) |
| 39 | main.startUpSleep = int( main.params[ 'SLEEP' ][ 'startup' ] ) |
| 40 | main.installSleep = int( main.params[ 'SLEEP' ][ 'install' ] ) |
| 41 | main.verifySleep = int( main.params[ 'SLEEP' ][ 'verify' ] ) |
| 42 | main.rerouteSleep = int ( main.params['SLEEP']['reroute'] ) |
| 43 | main.verifyAttempts = int( main.params['ATTEMPTS']['verify'] ) |
| 44 | main.ingress = main.params['LINK']['ingress'] |
| 45 | main.egress = main.params['LINK']['egress'] |
YPZhang | cb86c5b | 2016-01-27 17:38:12 -0800 | [diff] [blame] | 46 | main.cellData = {} # for creating cell file |
| 47 | main.reroute = main.params['reroute'] |
YPZhang | e6ef82a | 2016-07-05 16:48:15 -0700 | [diff] [blame] | 48 | main.flowObj = main.params['TEST']['flowObj'] |
| 49 | if main.flowObj == "True": |
| 50 | main.flowObj = True |
| 51 | main.dbFileName = main.params['DATABASE']['dbFlowObj'] |
| 52 | else: |
| 53 | main.flowObj = False |
| 54 | main.dbFileName = main.params['DATABASE']['dbName'] |
YPZhang | cb86c5b | 2016-01-27 17:38:12 -0800 | [diff] [blame] | 55 | main.threadID = 0 |
| 56 | |
| 57 | if main.reroute == "True": |
| 58 | main.reroute = True |
| 59 | else: |
| 60 | main.reroute = False |
| 61 | |
| 62 | main.CLIs = [] |
YPZhang | cb86c5b | 2016-01-27 17:38:12 -0800 | [diff] [blame] | 63 | main.setupSkipped = False |
| 64 | |
| 65 | wrapperFile1 = main.params[ 'DEPENDENCY' ][ 'wrapper1' ] |
| 66 | gitBranch = main.params[ 'GIT' ][ 'branch' ] |
| 67 | gitPull = main.params[ 'GIT' ][ 'pull' ] |
| 68 | nic = main.params['DATABASE']['nic'] |
| 69 | node = main.params['DATABASE']['node'] |
| 70 | nic = main.params['DATABASE']['nic'] |
| 71 | node = main.params['DATABASE']['node'] |
| 72 | stepResult = main.TRUE |
| 73 | |
| 74 | main.log.info("Cresting DB file") |
| 75 | with open(main.dbFileName, "w+") as dbFile: |
| 76 | dbFile.write("") |
| 77 | |
| 78 | utilities.assert_equals( expect=main.TRUE, |
| 79 | actual=stepResult, |
| 80 | onpass="environment set up successfull", |
| 81 | onfail="environment set up Failed" ) |
| 82 | |
| 83 | def CASE1( self ): |
| 84 | # main.scale[ 0 ] determines the current number of ONOS controller |
| 85 | main.CLIs = [] |
| 86 | main.numCtrls = int( main.scale[ 0 ] ) |
YPZhang | ebf9eb5 | 2016-05-12 15:20:24 -0700 | [diff] [blame] | 87 | main.ONOSip = [] |
| 88 | main.maxNumBatch = 0 |
| 89 | main.AllONOSip = main.ONOSbench.getOnosIps() |
| 90 | for i in range(main.numCtrls): |
| 91 | main.ONOSip.append(main.AllONOSip[i]) |
| 92 | main.log.info(main.ONOSip) |
| 93 | |
YPZhang | cb86c5b | 2016-01-27 17:38:12 -0800 | [diff] [blame] | 94 | main.log.info( "Creating list of ONOS cli handles" ) |
| 95 | for i in range(main.numCtrls): |
| 96 | main.CLIs.append( getattr( main, 'ONOScli%s' % (i+1) ) ) |
| 97 | |
| 98 | main.log.info(main.CLIs) |
| 99 | if not main.CLIs: |
| 100 | main.log.error( "Failed to create the list of ONOS cli handles" ) |
| 101 | main.cleanup() |
| 102 | main.exit() |
| 103 | |
| 104 | main.log.info( "Loading wrapper files" ) |
| 105 | main.startUp = imp.load_source( wrapperFile1, |
| 106 | main.dependencyPath + |
| 107 | wrapperFile1 + |
| 108 | ".py" ) |
| 109 | |
| 110 | copyResult = main.ONOSbench.copyMininetFile( main.topology, |
| 111 | main.dependencyPath, |
| 112 | main.Mininet1.user_name, |
| 113 | main.Mininet1.ip_address ) |
| 114 | |
| 115 | commit = main.ONOSbench.getVersion(report=True) |
| 116 | commit = commit.split(" ")[1] |
| 117 | |
| 118 | if gitPull == 'True': |
| 119 | if not main.startUp.onosBuild( main, gitBranch ): |
| 120 | main.log.error( "Failed to build ONOS" ) |
| 121 | main.cleanup() |
| 122 | main.exit() |
| 123 | else: |
| 124 | main.log.warn( "Did not pull new code so skipping mvn " + |
| 125 | "clean install" ) |
| 126 | with open(main.dbFileName, "a") as dbFile: |
| 127 | temp = "'" + commit + "'," |
| 128 | temp += "'" + nic + "'," |
| 129 | dbFile.write(temp) |
| 130 | |
| 131 | def CASE2( self, main ): |
| 132 | """ |
| 133 | - Uninstall ONOS cluster |
| 134 | - Verify ONOS start up |
| 135 | - Install ONOS cluster |
| 136 | - Connect to cli |
| 137 | """ |
| 138 | main.log.info( "Starting up %s node(s) ONOS cluster" % main.numCtrls) |
| 139 | main.log.info( "Safety check, killing all ONOS processes" + |
| 140 | " before initiating environment setup" ) |
| 141 | |
| 142 | for i in range( main.numCtrls ): |
| 143 | main.ONOSbench.onosDie( main.ONOSip[ i ] ) |
| 144 | |
| 145 | main.log.info( "NODE COUNT = %s" % main.numCtrls) |
| 146 | |
| 147 | tempOnosIp = [] |
| 148 | for i in range( main.numCtrls ): |
| 149 | tempOnosIp.append( main.ONOSip[i] ) |
| 150 | |
| 151 | main.ONOSbench.createCellFile( main.ONOSbench.ip_address, |
| 152 | "temp", |
| 153 | main.Mininet1.ip_address, |
| 154 | main.apps, |
| 155 | tempOnosIp ) |
| 156 | |
| 157 | main.step( "Apply cell to environment" ) |
| 158 | cellResult = main.ONOSbench.setCell( "temp" ) |
| 159 | verifyResult = main.ONOSbench.verifyCell() |
| 160 | stepResult = cellResult and verifyResult |
| 161 | utilities.assert_equals( expect=main.TRUE, |
| 162 | actual=stepResult, |
| 163 | onpass="Successfully applied cell to " + \ |
| 164 | "environment", |
| 165 | onfail="Failed to apply cell to environment " ) |
| 166 | |
| 167 | main.step( "Creating ONOS package" ) |
Jon Hall | bd60ea0 | 2016-08-23 10:03:59 -0700 | [diff] [blame] | 168 | packageResult = main.ONOSbench.buckBuild() |
YPZhang | cb86c5b | 2016-01-27 17:38:12 -0800 | [diff] [blame] | 169 | stepResult = packageResult |
| 170 | utilities.assert_equals( expect=main.TRUE, |
| 171 | actual=stepResult, |
| 172 | onpass="Successfully created ONOS package", |
| 173 | onfail="Failed to create ONOS package" ) |
| 174 | |
| 175 | main.step( "Uninstall ONOS package on all Nodes" ) |
| 176 | uninstallResult = main.TRUE |
| 177 | for i in range( int( main.numCtrls ) ): |
| 178 | main.log.info( "Uninstalling package on ONOS Node IP: " + main.ONOSip[i] ) |
| 179 | u_result = main.ONOSbench.onosUninstall( main.ONOSip[i] ) |
| 180 | utilities.assert_equals( expect=main.TRUE, actual=u_result, |
| 181 | onpass="Test step PASS", |
| 182 | onfail="Test step FAIL" ) |
| 183 | uninstallResult = ( uninstallResult and u_result ) |
| 184 | |
| 185 | main.step( "Install ONOS package on all Nodes" ) |
| 186 | installResult = main.TRUE |
| 187 | for i in range( int( main.numCtrls ) ): |
| 188 | main.log.info( "Installing package on ONOS Node IP: " + main.ONOSip[i] ) |
| 189 | i_result = main.ONOSbench.onosInstall( node=main.ONOSip[i] ) |
| 190 | utilities.assert_equals( expect=main.TRUE, actual=i_result, |
| 191 | onpass="Test step PASS", |
| 192 | onfail="Test step FAIL" ) |
| 193 | installResult = installResult and i_result |
| 194 | |
| 195 | main.step( "Verify ONOS nodes UP status" ) |
| 196 | statusResult = main.TRUE |
| 197 | for i in range( int( main.numCtrls ) ): |
| 198 | main.log.info( "ONOS Node " + main.ONOSip[i] + " status:" ) |
| 199 | onos_status = main.ONOSbench.onosStatus( node=main.ONOSip[i] ) |
| 200 | utilities.assert_equals( expect=main.TRUE, actual=onos_status, |
| 201 | onpass="Test step PASS", |
| 202 | onfail="Test step FAIL" ) |
| 203 | statusResult = ( statusResult and onos_status ) |
| 204 | |
Chiyu Cheng | ef10950 | 2016-11-21 15:51:38 -0800 | [diff] [blame] | 205 | main.step( "Set up ONOS secure SSH" ) |
| 206 | secureSshResult = main.TRUE |
| 207 | for i in range( int( main.numCtrls ) ): |
| 208 | secureSshResult = secureSshResult and main.ONOSbench.onosSecureSSH( node=main.ONOSip[i] ) |
| 209 | utilities.assert_equals( expect=main.TRUE, actual=secureSshResult, |
| 210 | onpass="Test step PASS", |
| 211 | onfail="Test step FAIL" ) |
| 212 | |
YPZhang | cb86c5b | 2016-01-27 17:38:12 -0800 | [diff] [blame] | 213 | main.step( "Start ONOS CLI on all nodes" ) |
| 214 | cliResult = main.TRUE |
Jon Hall | 6509dbf | 2016-06-21 17:01:17 -0700 | [diff] [blame] | 215 | main.step(" Start ONOS cli using thread ") |
YPZhang | cb86c5b | 2016-01-27 17:38:12 -0800 | [diff] [blame] | 216 | startCliResult = main.TRUE |
| 217 | pool = [] |
| 218 | |
| 219 | for i in range( int( main.numCtrls) ): |
| 220 | t = main.Thread( target=main.CLIs[i].startOnosCli, |
| 221 | threadID=main.threadID, |
| 222 | name="startOnosCli", |
| 223 | args=[ main.ONOSip[i] ], |
| 224 | kwargs = {"onosStartTimeout":main.timeout} ) |
| 225 | pool.append(t) |
| 226 | t.start() |
| 227 | main.threadID = main.threadID + 1 |
| 228 | for t in pool: |
| 229 | t.join() |
| 230 | startCliResult = startCliResult and t.result |
| 231 | time.sleep( main.startUpSleep ) |
| 232 | |
| 233 | def CASE10( self, main ): |
| 234 | """ |
| 235 | Setting up null-provider |
| 236 | """ |
| 237 | import json |
| 238 | # Activate apps |
| 239 | main.step("Activating null-provider") |
| 240 | appStatus = utilities.retry( main.CLIs[0].activateApp, |
| 241 | main.FALSE, |
| 242 | ['org.onosproject.null'], |
| 243 | sleep=main.verifySleep, |
| 244 | attempts=main.verifyAttempts ) |
| 245 | utilities.assert_equals( expect=main.TRUE, |
| 246 | actual=appStatus, |
| 247 | onpass="Successfully activated null-provider", |
| 248 | onfail="Failed activate null-provider" ) |
| 249 | |
| 250 | # Setup the null-provider |
| 251 | main.step("Configuring null-provider") |
| 252 | cfgStatus = utilities.retry( main.ONOSbench.onosCfgSet, |
| 253 | main.FALSE, |
| 254 | [ main.ONOSip[0], |
| 255 | 'org.onosproject.provider.nil.NullProviders', 'deviceCount 8'], |
| 256 | sleep=main.verifySleep, |
| 257 | attempts = main.verifyAttempts ) |
| 258 | cfgStatus = cfgStatus and utilities.retry( main.ONOSbench.onosCfgSet, |
| 259 | main.FALSE, |
| 260 | [ main.ONOSip[0], |
| 261 | 'org.onosproject.provider.nil.NullProviders', 'topoShape reroute'], |
| 262 | sleep=main.verifySleep, |
| 263 | attempts = main.verifyAttempts ) |
| 264 | |
| 265 | cfgStatus = cfgStatus and utilities.retry( main.ONOSbench.onosCfgSet, |
| 266 | main.FALSE, |
| 267 | [ main.ONOSip[0], |
| 268 | 'org.onosproject.provider.nil.NullProviders', 'enabled true'], |
| 269 | sleep=main.verifySleep, |
| 270 | attempts = main.verifyAttempts ) |
| 271 | |
| 272 | |
| 273 | utilities.assert_equals( expect=main.TRUE, |
| 274 | actual=cfgStatus, |
| 275 | onpass="Successfully configured null-provider", |
| 276 | onfail="Failed to configure null-provider" ) |
| 277 | |
| 278 | # give onos some time to settle |
| 279 | time.sleep(main.startUpSleep) |
| 280 | |
| 281 | main.log.info("Setting default flows to zero") |
| 282 | main.defaultFlows = 0 |
| 283 | |
| 284 | main.step("Check status of null-provider setup") |
| 285 | caseResult = appStatus and cfgStatus |
| 286 | utilities.assert_equals( expect=main.TRUE, |
| 287 | actual=caseResult, |
| 288 | onpass="Setting up null-provider was successfull", |
| 289 | onfail="Failed to setup null-provider" ) |
| 290 | |
| 291 | # This tells the following cases if we are using the null-provider or ovs |
| 292 | main.switchType = "null:" |
| 293 | |
| 294 | # If the null-provider setup was unsuccessfull, then there is no point to |
| 295 | # run the subsequent cases |
| 296 | |
| 297 | time.sleep(main.startUpSleep) |
| 298 | main.step( "Balancing Masters" ) |
| 299 | |
| 300 | stepResult = main.FALSE |
| 301 | stepResult = utilities.retry( main.CLIs[0].balanceMasters, |
| 302 | main.FALSE, |
| 303 | [], |
| 304 | sleep=3, |
| 305 | attempts=3 ) |
| 306 | |
| 307 | utilities.assert_equals( expect=main.TRUE, |
| 308 | actual=stepResult, |
| 309 | onpass="Balance masters was successfull", |
| 310 | onfail="Failed to balance masters") |
| 311 | |
| 312 | time.sleep( 5 ) |
| 313 | if not caseResult: |
| 314 | main.setupSkipped = True |
| 315 | |
| 316 | def CASE11( self, main): |
| 317 | ''' |
| 318 | Setting up mininet |
| 319 | ''' |
| 320 | import json |
| 321 | import time |
YPZhang | ebf9eb5 | 2016-05-12 15:20:24 -0700 | [diff] [blame] | 322 | |
| 323 | devices = [] |
| 324 | devices = main.CLIs[0].getAllDevicesId() |
| 325 | for d in devices: |
| 326 | main.CLIs[0].deviceRemove( d ) |
YPZhang | cb86c5b | 2016-01-27 17:38:12 -0800 | [diff] [blame] | 327 | |
| 328 | time.sleep(main.startUpSleep) |
YPZhang | e6ef82a | 2016-07-05 16:48:15 -0700 | [diff] [blame] | 329 | if main.flowObj: |
| 330 | main.CLIs[0].setCfg("org.onosproject.net.intent.impl.compiler.IntentConfigurableRegistrator", |
| 331 | "useFlowObjectives", value="true") |
YPZhang | cb86c5b | 2016-01-27 17:38:12 -0800 | [diff] [blame] | 332 | main.step('Starting mininet topology') |
| 333 | mnStatus = main.Mininet1.startNet(topoFile='~/mininet/custom/rerouteTopo.py') |
| 334 | utilities.assert_equals( expect=main.TRUE, |
| 335 | actual=mnStatus, |
| 336 | onpass="Successfully started Mininet", |
| 337 | onfail="Failed to activate Mininet" ) |
| 338 | |
| 339 | main.step("Assinging masters to switches") |
| 340 | switches = main.Mininet1.getSwitches() |
| 341 | swStatus = main.Mininet1.assignSwController( sw=switches.keys(), ip=main.ONOSip ) |
| 342 | utilities.assert_equals( expect=main.TRUE, |
| 343 | actual=swStatus, |
| 344 | onpass="Successfully assigned switches to masters", |
| 345 | onfail="Failed assign switches to masters" ) |
| 346 | |
| 347 | time.sleep(main.startUpSleep) |
YPZhang | ebf9eb5 | 2016-05-12 15:20:24 -0700 | [diff] [blame] | 348 | # Balancing Masters |
| 349 | main.step( "Balancing Masters" ) |
| 350 | stepResult = main.FALSE |
| 351 | stepResult = utilities.retry( main.CLIs[0].balanceMasters, |
| 352 | main.FALSE, |
| 353 | [], |
| 354 | sleep=3, |
| 355 | attempts=3 ) |
| 356 | |
| 357 | utilities.assert_equals( expect=main.TRUE, |
| 358 | actual=stepResult, |
| 359 | onpass="Balance masters was successfull", |
| 360 | onfail="Failed to balance masters" ) |
YPZhang | cb86c5b | 2016-01-27 17:38:12 -0800 | [diff] [blame] | 361 | |
| 362 | main.log.info("Getting default flows") |
| 363 | jsonSum = json.loads(main.CLIs[0].summary()) |
| 364 | main.defaultFlows = jsonSum["flows"] |
| 365 | |
| 366 | main.step("Check status of Mininet setup") |
YPZhang | ebf9eb5 | 2016-05-12 15:20:24 -0700 | [diff] [blame] | 367 | caseResult = mnStatus and swStatus |
YPZhang | cb86c5b | 2016-01-27 17:38:12 -0800 | [diff] [blame] | 368 | utilities.assert_equals( expect=main.TRUE, |
| 369 | actual=caseResult, |
| 370 | onpass="Successfully setup Mininet", |
| 371 | onfail="Failed setup Mininet" ) |
| 372 | |
| 373 | # This tells the following cases if we are using the null-provider or ovs |
| 374 | main.switchType = "of:" |
| 375 | |
| 376 | time.sleep(main.startUpSleep) |
| 377 | main.step( "Balancing Masters" ) |
| 378 | |
| 379 | stepResult = main.FALSE |
| 380 | stepResult = utilities.retry( main.CLIs[0].balanceMasters, |
| 381 | main.FALSE, |
| 382 | [], |
| 383 | sleep=3, |
| 384 | attempts=3 ) |
| 385 | |
| 386 | utilities.assert_equals( expect=main.TRUE, |
| 387 | actual=stepResult, |
| 388 | onpass="Balance masters was successfull", |
| 389 | onfail="Failed to balance masters") |
| 390 | |
| 391 | time.sleep(5) |
| 392 | if not caseResult: |
| 393 | main.setupSkipped = True |
| 394 | |
| 395 | |
| 396 | |
| 397 | def CASE20( self, main ): |
| 398 | if main.reroute: |
| 399 | main.minIntents = int(main.params['NULL']['REROUTE']['min_intents']) |
| 400 | main.maxIntents = int(main.params['NULL']['REROUTE']['max_intents']) |
| 401 | main.checkInterval = int(main.params['NULL']['REROUTE']['check_interval']) |
| 402 | main.batchSize = int(main.params['NULL']['REROUTE']['batch_size']) |
| 403 | else: |
| 404 | main.minIntents = int(main.params['NULL']['PUSH']['min_intents']) |
| 405 | main.maxIntents = int(main.params['NULL']['PUSH']['max_intents']) |
| 406 | main.checkInterval = int(main.params['NULL']['PUSH']['check_interval']) |
| 407 | main.batchSize = int(main.params['NULL']['PUSH']['batch_size']) |
| 408 | |
| 409 | # check if the case needs to be skipped |
| 410 | if main.setupSkipped: |
| 411 | main.setupSkipped = False |
| 412 | main.skipCase() |
| 413 | |
| 414 | # the index where the next intents will be installed |
| 415 | offfset = 0 |
| 416 | # keeps track of how many intents have been installed |
| 417 | currIntents = 0 |
YPZhang | 3097ba9 | 2016-02-16 17:32:32 -0800 | [diff] [blame] | 418 | # keeps track of how many flows have been installed, set to 0 at start |
| 419 | currFlows = 0 |
YPZhang | cb86c5b | 2016-01-27 17:38:12 -0800 | [diff] [blame] | 420 | # limit for the number of intents that can be installed |
YPZhang | ebf9eb5 | 2016-05-12 15:20:24 -0700 | [diff] [blame] | 421 | main.batchSize = int( int(main.batchSize)/int(main.numCtrls)) |
YPZhang | cb86c5b | 2016-01-27 17:38:12 -0800 | [diff] [blame] | 422 | limit = main.maxIntents / main.batchSize |
| 423 | # total intents installed |
| 424 | totalIntents = 0 |
| 425 | |
| 426 | intentsState = None |
| 427 | |
| 428 | offtmp = 0 |
| 429 | main.step( "Pushing intents" ) |
| 430 | stepResult = main.TRUE |
YPZhang | 47779c2 | 2016-03-07 13:03:07 -0800 | [diff] [blame] | 431 | # temp variable to contain the number of flows |
| 432 | flowsNum = 0 |
YPZhang | ebf9eb5 | 2016-05-12 15:20:24 -0700 | [diff] [blame] | 433 | if main.numCtrls > 1: |
| 434 | # if more than one onos nodes, we should check more frequently |
| 435 | main.checkInterval = main.checkInterval/4 |
YPZhang | cb86c5b | 2016-01-27 17:38:12 -0800 | [diff] [blame] | 436 | |
YPZhang | ebf9eb5 | 2016-05-12 15:20:24 -0700 | [diff] [blame] | 437 | # make sure the checkInterval divisible batchSize |
| 438 | main.checkInterval = int( int( main.checkInterval / main.batchSize ) * main.batchSize ) |
YPZhang | ac53ebf | 2016-05-13 16:26:19 -0700 | [diff] [blame] | 439 | flowTemp=0 |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 440 | intentVerifyTemp = 0 |
YPZhang | ac53ebf | 2016-05-13 16:26:19 -0700 | [diff] [blame] | 441 | totalFlows=0 |
YPZhang | cb86c5b | 2016-01-27 17:38:12 -0800 | [diff] [blame] | 442 | for i in range(limit): |
| 443 | |
| 444 | # Threads pool |
| 445 | pool = [] |
| 446 | |
| 447 | for j in range( int( main.numCtrls) ): |
| 448 | if main.numCtrls > 1: |
| 449 | time.sleep( 1 ) |
| 450 | offtmp = offfset + main.maxIntents * j |
| 451 | # Push intents by using threads |
| 452 | t = main.Thread( target=main.CLIs[j].pushTestIntents, |
| 453 | threadID=main.threadID, |
| 454 | name="Push-Test-Intents", |
| 455 | args=[ main.switchType + main.ingress, |
| 456 | main.switchType + main.egress, |
| 457 | main.batchSize ], |
| 458 | kwargs={ "offset": offtmp, |
| 459 | "options": "-i", |
| 460 | "timeout": main.timeout, |
YPZhang | ebf9eb5 | 2016-05-12 15:20:24 -0700 | [diff] [blame] | 461 | "background":False, |
| 462 | "noExit":True} ) |
YPZhang | cb86c5b | 2016-01-27 17:38:12 -0800 | [diff] [blame] | 463 | pool.append(t) |
| 464 | t.start() |
| 465 | main.threadID = main.threadID + 1 |
| 466 | for t in pool: |
| 467 | t.join() |
| 468 | stepResult = stepResult and t.result |
| 469 | offfset = offfset + main.batchSize |
| 470 | |
YPZhang | 3097ba9 | 2016-02-16 17:32:32 -0800 | [diff] [blame] | 471 | totalIntents = main.batchSize * main.numCtrls + totalIntents |
YPZhang | cb86c5b | 2016-01-27 17:38:12 -0800 | [diff] [blame] | 472 | if totalIntents >= main.minIntents and totalIntents % main.checkInterval == 0: |
| 473 | # if reach to minimum number and check interval, verify Intetns and flows |
| 474 | time.sleep( main.verifySleep * main.numCtrls ) |
| 475 | |
| 476 | main.log.info("Verify Intents states") |
YPZhang | 3097ba9 | 2016-02-16 17:32:32 -0800 | [diff] [blame] | 477 | # k is a control variable for verify retry attempts |
YPZhang | cb86c5b | 2016-01-27 17:38:12 -0800 | [diff] [blame] | 478 | k = 1 |
YPZhang | 3097ba9 | 2016-02-16 17:32:32 -0800 | [diff] [blame] | 479 | while k <= main.verifyAttempts: |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 480 | # while loop for check intents by using CLI driver |
YPZhang | cb86c5b | 2016-01-27 17:38:12 -0800 | [diff] [blame] | 481 | time.sleep(5) |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 482 | intentsState = main.CLIs[0].checkIntentSummary(timeout=600, noExit=True) |
YPZhang | ebf9eb5 | 2016-05-12 15:20:24 -0700 | [diff] [blame] | 483 | if intentsState: |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 484 | verifyTotalIntents = main.CLIs[0].getTotalIntentsNum(timeout=600, noExit=True) |
| 485 | if intentVerifyTemp < verifyTotalIntents: |
| 486 | intentVerifyTemp = verifyTotalIntents |
YPZhang | ebf9eb5 | 2016-05-12 15:20:24 -0700 | [diff] [blame] | 487 | else: |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 488 | verifyTotalIntents = intentVerifyTemp |
YPZhang | 6e758fb | 2016-07-26 09:20:55 -0700 | [diff] [blame] | 489 | intentsState = False |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 490 | main.log.info("Total Installed Intents: {}".format( verifyTotalIntents ) ) |
YPZhang | cb86c5b | 2016-01-27 17:38:12 -0800 | [diff] [blame] | 491 | break |
YPZhang | cb86c5b | 2016-01-27 17:38:12 -0800 | [diff] [blame] | 492 | k = k+1 |
YPZhang | ac53ebf | 2016-05-13 16:26:19 -0700 | [diff] [blame] | 493 | |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 494 | k = 1 |
| 495 | flowVerify = True |
| 496 | while k <= main.verifyAttempts: |
| 497 | time.sleep(5) |
| 498 | totalFlows = main.CLIs[0].getTotalFlowsNum( timeout=600, noExit=True ) |
| 499 | expectFlows = totalIntents * 7 + main.defaultFlows |
| 500 | if totalFlows == expectFlows: |
| 501 | main.log.info("Total Flows Added: {}".format(totalFlows)) |
| 502 | break |
| 503 | else: |
| 504 | main.log.info("Some Flows are not added, retry...") |
| 505 | main.log.info("Total Flows Added: {} Expect Flows: {}".format(totalFlows, expectFlows)) |
| 506 | flowVerify = False |
YPZhang | ac53ebf | 2016-05-13 16:26:19 -0700 | [diff] [blame] | 507 | |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 508 | k += 1 |
| 509 | if flowTemp < totalFlows: |
| 510 | flowTemp = totalFlows |
| 511 | else: |
| 512 | totalFlows = flowTemp |
| 513 | |
| 514 | if not intentsState or not flowVerify: |
YPZhang | a4acbb8 | 2016-03-02 17:28:25 -0800 | [diff] [blame] | 515 | # If some intents are not installed, grep the previous flows list, and finished this test case |
YPZhang | 14a4aa9 | 2016-07-15 13:37:15 -0700 | [diff] [blame] | 516 | main.log.warn( "Intents or flows are not installed" ) |
| 517 | verifyTotalIntents = main.CLIs[0].getTotalIntentsNum(timeout=600, noExit=True) |
| 518 | if intentVerifyTemp < verifyTotalIntents: |
| 519 | intentVerifyTemp = verifyTotalIntents |
| 520 | else: |
| 521 | verifyTotalIntents = intentVerifyTemp |
| 522 | if flowTemp < totalFlows: |
| 523 | flowTemp = totalFlows |
| 524 | else: |
| 525 | totalFlows = flowTemp |
YPZhang | ac53ebf | 2016-05-13 16:26:19 -0700 | [diff] [blame] | 526 | main.log.info("Total Intents: {}".format( verifyTotalIntents) ) |
YPZhang | cb86c5b | 2016-01-27 17:38:12 -0800 | [diff] [blame] | 527 | break |
YPZhang | e96a306 | 2016-05-12 16:18:35 -0700 | [diff] [blame] | 528 | |
YPZhang | cb86c5b | 2016-01-27 17:38:12 -0800 | [diff] [blame] | 529 | del main.scale[0] |
| 530 | utilities.assert_equals( expect = main.TRUE, |
YPZhang | ebf9eb5 | 2016-05-12 15:20:24 -0700 | [diff] [blame] | 531 | actual = intentsState, |
YPZhang | cb86c5b | 2016-01-27 17:38:12 -0800 | [diff] [blame] | 532 | onpass = "Successfully pushed and verified intents", |
| 533 | onfail = "Failed to push and verify intents" ) |
| 534 | |
YPZhang | cb86c5b | 2016-01-27 17:38:12 -0800 | [diff] [blame] | 535 | main.log.info( "Total Intents Installed before crash: {}".format( totalIntents ) ) |
| 536 | main.log.info( "Total Flows ADDED before crash: {}".format( totalFlows ) ) |
| 537 | |
| 538 | main.step('clean up Mininet') |
| 539 | main.Mininet1.stopNet() |
YPZhang | cb86c5b | 2016-01-27 17:38:12 -0800 | [diff] [blame] | 540 | main.log.info("Writing results to DS file") |
| 541 | with open(main.dbFileName, "a") as dbFile: |
| 542 | # Scale number |
| 543 | temp = str(main.numCtrls) |
| 544 | temp += ",'" + "baremetal1" + "'" |
| 545 | # how many intents we installed before crash |
YPZhang | ac53ebf | 2016-05-13 16:26:19 -0700 | [diff] [blame] | 546 | temp += "," + str(verifyTotalIntents) |
YPZhang | cb86c5b | 2016-01-27 17:38:12 -0800 | [diff] [blame] | 547 | # how many flows we installed before crash |
| 548 | temp += "," + str(totalFlows) |
| 549 | # other columns in database, but we didn't use in this test |
| 550 | temp += "," + "0,0,0,0,0,0" |
| 551 | temp += "\n" |
| 552 | dbFile.write( temp ) |