acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 1 | # Testing the basic intent functionality of ONOS |
| 2 | |
| 3 | class FUNCoptical: |
| 4 | |
| 5 | def __init__( self ): |
| 6 | self.default = '' |
| 7 | |
| 8 | def CASE1( self, main ): |
| 9 | import time |
| 10 | import imp |
| 11 | import re |
| 12 | |
| 13 | """ |
| 14 | - Construct tests variables |
| 15 | - GIT ( optional ) |
| 16 | - Checkout ONOS master branch |
| 17 | - Pull latest ONOS code |
| 18 | - Building ONOS ( optional ) |
| 19 | - Install ONOS package |
| 20 | - Build ONOS package |
| 21 | """ |
| 22 | |
| 23 | main.case( "Constructing test variables and building ONOS package" ) |
| 24 | main.step( "Constructing test variables" ) |
| 25 | main.caseExplanation = "This test case is mainly for loading " +\ |
| 26 | "from params file, and pull and build the " +\ |
| 27 | " latest ONOS package" |
| 28 | stepResult = main.FALSE |
| 29 | |
| 30 | # Test variables |
| 31 | try: |
| 32 | main.testOnDirectory = re.sub( "(/tests)$", "", main.testDir ) |
| 33 | main.apps = main.params[ 'ENV' ][ 'cellApps' ] |
| 34 | gitBranch = main.params[ 'GIT' ][ 'branch' ] |
| 35 | main.dependencyPath = main.testOnDirectory + \ |
| 36 | main.params[ 'DEPENDENCY' ][ 'path' ] |
| 37 | main.scale = ( main.params[ 'SCALE' ][ 'size' ] ).split( "," ) |
| 38 | if main.ONOSbench.maxNodes: |
| 39 | main.maxNodes = int( main.ONOSbench.maxNodes ) |
| 40 | else: |
| 41 | main.maxNodes = 0 |
| 42 | wrapperFile1 = main.params[ 'DEPENDENCY' ][ 'wrapper1' ] |
| 43 | wrapperFile2 = main.params[ 'DEPENDENCY' ][ 'wrapper2' ] |
| 44 | wrapperFile3 = main.params[ 'DEPENDENCY' ][ 'wrapper3' ] |
| 45 | main.startUpSleep = int( main.params[ 'SLEEP' ][ 'startup' ] ) |
| 46 | main.checkIntentSleep = int( main.params[ 'SLEEP' ][ 'checkintent' ] ) |
| 47 | main.removeIntentSleep = int( main.params[ 'SLEEP' ][ 'removeintent' ] ) |
| 48 | main.rerouteSleep = int( main.params[ 'SLEEP' ][ 'reroute' ] ) |
| 49 | main.fwdSleep = int( main.params[ 'SLEEP' ][ 'fwd' ] ) |
| 50 | main.checkTopoAttempts = int( main.params[ 'SLEEP' ][ 'topoAttempts' ] ) |
| 51 | gitPull = main.params[ 'GIT' ][ 'pull' ] |
| 52 | main.numSwitch = int( main.params[ 'MININET' ][ 'switch' ] ) |
| 53 | main.numLinks = int( main.params[ 'MININET' ][ 'links' ] ) |
| 54 | main.cellData = {} # For creating cell file |
| 55 | main.hostsData = {} |
| 56 | main.CLIs = [] |
| 57 | main.ONOSip = [] # List of IPs of active ONOS nodes. CASE 2 |
| 58 | main.activeONOSip = [] |
| 59 | main.assertReturnString = '' # Assembled assert return string |
| 60 | |
| 61 | main.ONOSip = main.ONOSbench.getOnosIps() |
| 62 | |
| 63 | # Assigning ONOS cli handles to a list |
| 64 | for i in range( 1, main.maxNodes + 1 ): |
| 65 | main.CLIs.append( getattr( main, 'ONOScli' + str( i ) ) ) |
| 66 | |
| 67 | # -- INIT SECTION, ONLY RUNS ONCE -- # |
| 68 | main.startUp = imp.load_source( wrapperFile1, |
| 69 | main.dependencyPath + |
| 70 | wrapperFile1 + |
| 71 | ".py" ) |
| 72 | |
| 73 | main.intentFunction = imp.load_source( wrapperFile2, |
| 74 | main.dependencyPath + |
| 75 | wrapperFile2 + |
| 76 | ".py" ) |
| 77 | |
| 78 | main.topo = imp.load_source( wrapperFile3, |
| 79 | main.dependencyPath + |
| 80 | wrapperFile3 + |
| 81 | ".py" ) |
| 82 | |
| 83 | if main.CLIs: |
| 84 | stepResult = main.TRUE |
| 85 | else: |
| 86 | main.log.error( "Did not properly created list of ONOS CLI handle" ) |
| 87 | stepResult = main.FALSE |
| 88 | except Exception as e: |
| 89 | main.log.exception(e) |
| 90 | main.cleanup() |
| 91 | main.exit() |
| 92 | |
| 93 | utilities.assert_equals( expect=main.TRUE, |
| 94 | actual=stepResult, |
| 95 | onpass="Successfully construct " + |
| 96 | "test variables ", |
| 97 | onfail="Failed to construct test variables" ) |
| 98 | |
| 99 | if gitPull == 'True': |
| 100 | main.step( "Building ONOS in " + gitBranch + " branch" ) |
| 101 | onosBuildResult = main.startUp.onosBuild( main, gitBranch ) |
| 102 | stepResult = onosBuildResult |
| 103 | utilities.assert_equals( expect=main.TRUE, |
| 104 | actual=stepResult, |
| 105 | onpass="Successfully compiled " + |
| 106 | "latest ONOS", |
| 107 | onfail="Failed to compile " + |
| 108 | "latest ONOS" ) |
| 109 | else: |
| 110 | main.log.warn( "Did not pull new code so skipping mvn " + |
| 111 | "clean install" ) |
| 112 | main.ONOSbench.getVersion( report=True ) |
| 113 | |
| 114 | def CASE2( self, main ): |
| 115 | """ |
| 116 | - Set up cell |
| 117 | - Create cell file |
| 118 | - Set cell file |
| 119 | - Verify cell file |
| 120 | - Kill ONOS process |
| 121 | - Uninstall ONOS cluster |
| 122 | - Verify ONOS start up |
| 123 | - Install ONOS cluster |
| 124 | - Connect to cli |
| 125 | """ |
| 126 | |
| 127 | # main.scale[ 0 ] determines the current number of ONOS controller |
| 128 | main.numCtrls = int( main.scale[ 0 ] ) |
Jeremy | e4bc713 | 2016-03-30 14:04:01 -0700 | [diff] [blame] | 129 | main.flowCompiler = "Flow Rules" |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 130 | |
| 131 | main.case( "Starting up " + str( main.numCtrls ) + |
| 132 | " node(s) ONOS cluster" ) |
| 133 | main.caseExplanation = "Set up ONOS with " + str( main.numCtrls ) +\ |
| 134 | " node(s) ONOS cluster" |
| 135 | |
| 136 | |
| 137 | |
| 138 | #kill off all onos processes |
| 139 | main.log.info( "Safety check, killing all ONOS processes" + |
Jon Hall | 70b2ff4 | 2015-11-17 15:49:44 -0800 | [diff] [blame] | 140 | " before initiating environment setup" ) |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 141 | |
| 142 | for i in range( main.maxNodes ): |
| 143 | main.ONOSbench.onosDie( main.ONOSip[ i ] ) |
| 144 | |
| 145 | print "NODE COUNT = ", 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", main.Mininet1.ip_address, |
| 153 | main.apps, tempOnosIp ) |
| 154 | |
| 155 | main.step( "Apply cell to environment" ) |
| 156 | cellResult = main.ONOSbench.setCell( "temp" ) |
| 157 | verifyResult = main.ONOSbench.verifyCell() |
| 158 | stepResult = cellResult and verifyResult |
| 159 | utilities.assert_equals( expect=main.TRUE, |
| 160 | actual=stepResult, |
| 161 | onpass="Successfully applied cell to " + \ |
| 162 | "environment", |
| 163 | onfail="Failed to apply cell to environment " ) |
| 164 | |
| 165 | main.step( "Creating ONOS package" ) |
| 166 | packageResult = main.ONOSbench.onosPackage() |
| 167 | stepResult = packageResult |
| 168 | utilities.assert_equals( expect=main.TRUE, |
| 169 | actual=stepResult, |
| 170 | onpass="Successfully created ONOS package", |
| 171 | onfail="Failed to create ONOS package" ) |
| 172 | |
| 173 | time.sleep( main.startUpSleep ) |
| 174 | main.step( "Uninstalling ONOS package" ) |
| 175 | onosUninstallResult = main.TRUE |
| 176 | for ip in main.ONOSip: |
| 177 | onosUninstallResult = onosUninstallResult and \ |
| 178 | main.ONOSbench.onosUninstall( nodeIp=ip ) |
| 179 | stepResult = onosUninstallResult |
| 180 | utilities.assert_equals( expect=main.TRUE, |
| 181 | actual=stepResult, |
| 182 | onpass="Successfully uninstalled ONOS package", |
| 183 | onfail="Failed to uninstall ONOS package" ) |
| 184 | |
| 185 | time.sleep( main.startUpSleep ) |
| 186 | main.step( "Installing ONOS package" ) |
| 187 | onosInstallResult = main.TRUE |
| 188 | for i in range( main.numCtrls ): |
| 189 | onosInstallResult = onosInstallResult and \ |
| 190 | main.ONOSbench.onosInstall( node=main.ONOSip[ i ] ) |
| 191 | # Populate activeONOSip |
| 192 | main.activeONOSip.append( main.ONOSip[ i ] ) |
| 193 | stepResult = onosInstallResult |
| 194 | utilities.assert_equals( expect=main.TRUE, |
| 195 | actual=stepResult, |
| 196 | onpass="Successfully installed ONOS package", |
| 197 | onfail="Failed to install ONOS package" ) |
| 198 | |
| 199 | time.sleep( main.startUpSleep ) |
| 200 | main.step( "Starting ONOS service" ) |
| 201 | stopResult = main.TRUE |
| 202 | startResult = main.TRUE |
| 203 | onosIsUp = main.TRUE |
| 204 | |
| 205 | for i in range( main.numCtrls ): |
Jeremy Songster | 7edb663 | 2016-04-28 15:44:28 -0700 | [diff] [blame] | 206 | isUp = main.ONOSbench.isup( main.ONOSip[ i ] ) |
| 207 | onosIsUp = onosIsUp and isUp |
| 208 | if isUp == main.TRUE: |
| 209 | main.log.report( "ONOS instance {0} is up and ready".format( i + 1 ) ) |
| 210 | else: |
| 211 | main.log.report( "ONOS instance {0} may not be up, stop and ".format( i + 1 ) + |
| 212 | "start ONOS again " ) |
| 213 | stopResult = stopResult and main.ONOSbench.onosStop( main.ONOSip[ i ] ) |
| 214 | startResult = startResult and main.ONOSbench.onosStart( main.ONOSip[ i ] ) |
| 215 | if not startResult or stopResult: |
| 216 | main.log.report( "ONOS instance {0} did not start correctly.".format( i + 1) ) |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 217 | stepResult = onosIsUp and stopResult and startResult |
| 218 | utilities.assert_equals( expect=main.TRUE, |
| 219 | actual=stepResult, |
Jeremy Songster | 7edb663 | 2016-04-28 15:44:28 -0700 | [diff] [blame] | 220 | onpass="ONOS service is ready on all nodes", |
| 221 | onfail="ONOS service did not start properly on all nodes" ) |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 222 | |
| 223 | main.step( "Start ONOS cli" ) |
| 224 | cliResult = main.TRUE |
| 225 | for i in range( main.numCtrls ): |
| 226 | cliResult = cliResult and \ |
| 227 | main.CLIs[ i ].startOnosCli( main.ONOSip[ i ] ) |
| 228 | stepResult = cliResult |
| 229 | utilities.assert_equals( expect=main.TRUE, |
| 230 | actual=stepResult, |
| 231 | onpass="Successfully start ONOS cli", |
| 232 | onfail="Failed to start ONOS cli" ) |
| 233 | |
| 234 | # Remove the first element in main.scale list |
| 235 | main.scale.remove( main.scale[ 0 ] ) |
| 236 | |
| 237 | main.intentFunction.report( main ) |
| 238 | |
| 239 | |
| 240 | def CASE10( self, main ): |
| 241 | """ |
| 242 | Start Mininet opticalTest Topology |
| 243 | """ |
| 244 | main.case( "Mininet with Linc-OE startup") |
| 245 | main.caseExplanation = "Start opticalTest.py topology included with ONOS" |
| 246 | main.step( "Starting mininet and LINC-OE" ) |
| 247 | topoResult = main.TRUE |
| 248 | time.sleep( 10 ) |
| 249 | controllerIPs = ' '.join( main.activeONOSip ) |
| 250 | opticalMnScript = main.LincOE.runOpticalMnScript(ctrllerIP = controllerIPs) |
| 251 | topoResult = opticalMnScript |
| 252 | utilities.assert_equals( |
| 253 | expect=main.TRUE, |
| 254 | actual=topoResult, |
| 255 | onpass="Started the topology successfully ", |
| 256 | onfail="Failed to start the topology") |
| 257 | |
| 258 | # Exit if topology did not load properly |
| 259 | if not topoResult: |
| 260 | main.cleanup() |
| 261 | main.exit() |
| 262 | |
Jeremy | e4bc713 | 2016-03-30 14:04:01 -0700 | [diff] [blame] | 263 | |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 264 | |
| 265 | |
| 266 | def CASE14( self, main ): |
| 267 | """ |
| 268 | Stop mininet |
| 269 | """ |
| 270 | main.log.report( "Stop Mininet topology" ) |
| 271 | main.case( "Stop Mininet topology" ) |
| 272 | main.caseExplanation = "Stopping the current mininet topology " +\ |
| 273 | "to start up fresh" |
| 274 | |
| 275 | main.step( "Stopping Mininet Topology" ) |
| 276 | topoResult = main.LincOE.stopNet( timeout=180 ) |
| 277 | utilities.assert_equals( expect=main.TRUE, |
| 278 | actual=topoResult, |
| 279 | onpass="Successfully stopped mininet", |
| 280 | onfail="Failed to stopped mininet" ) |
| 281 | # Exit if topology did not load properly |
| 282 | if not topoResult: |
| 283 | main.cleanup() |
| 284 | main.exit() |
| 285 | |
Jeremy | e4bc713 | 2016-03-30 14:04:01 -0700 | [diff] [blame] | 286 | def CASE17( self, main ): |
| 287 | """ |
| 288 | Use Flow Objectives |
| 289 | """ |
| 290 | main.case( "Enable intent compilation using Flow Objectives" ) |
| 291 | main.step( "Enabling Flow Objectives" ) |
| 292 | |
| 293 | main.flowCompiler = "Flow Objectives" |
| 294 | |
| 295 | cmd = "org.onosproject.net.intent.impl.compiler.IntentConfigurableRegistrator" |
| 296 | |
| 297 | stepResult = main.CLIs[ 0 ].setCfg( component=cmd, |
| 298 | propName="useFlowObjectives", value="true" ) |
| 299 | |
| 300 | utilities.assert_equals( expect=main.TRUE, |
| 301 | actual=stepResult, |
| 302 | onpass="Successfully activated Flow Objectives", |
| 303 | onfail="Failed to activate Flow Objectives" ) |
| 304 | |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 305 | def CASE21( self,main ): |
| 306 | """ |
| 307 | Run pingall to discover all hosts |
| 308 | """ |
| 309 | main.case( "Running Pingall" ) |
| 310 | main.caseExplanation = "Use pingall to discover all hosts. Pingall is expected to fail." |
| 311 | main.step( "Discover Hosts through Pingall" ) |
Jeremy Songster | 7edb663 | 2016-04-28 15:44:28 -0700 | [diff] [blame] | 312 | pingResult = main.LincOE.pingall( timeout = 120 ) |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 313 | |
| 314 | utilities.assert_equals( expect=main.FALSE, |
| 315 | actual=pingResult, |
| 316 | onpass="Pingall Completed", |
| 317 | onfail="Pingall did not complete or did not return fales" ) |
| 318 | |
| 319 | def CASE22( self,main ): |
| 320 | """ |
| 321 | Send arpings to discover all hosts |
| 322 | """ |
| 323 | main.case( "Discover Hosts with arping" ) |
| 324 | main.caseExplanation = "Send arpings between all the hosts to discover and verify them" |
| 325 | |
| 326 | main.step( "Send arping between all hosts" ) |
| 327 | |
| 328 | hosts = [ "h1","h2","h3","h4","h5","h6" ] |
| 329 | |
| 330 | arpingHostResults = main.TRUE |
| 331 | for host in hosts: |
| 332 | if main.LincOE.arping( host ): |
| 333 | main.log.info( "Successfully reached host {} with arping".format( host ) ) |
| 334 | else: |
| 335 | main.log.error( "Could not reach host {} with arping".format( host ) ) |
| 336 | arpingHostResults = main.FALSE |
| 337 | |
| 338 | utilities.assert_equals( expect=main.TRUE, |
| 339 | actual=arpingHostResults, |
| 340 | onpass="Successfully discovered all hosts", |
| 341 | onfail="Could not descover some hosts" ) |
| 342 | |
| 343 | def CASE23( self, main ): |
| 344 | """ |
| 345 | Compare ONOS Topology to Mininet Topology |
| 346 | """ |
| 347 | import json |
| 348 | |
| 349 | main.case( "Compare ONOS Topology view to Mininet topology" ) |
| 350 | main.caseExplanation = "Compare topology elements between Mininet" +\ |
| 351 | " and ONOS" |
| 352 | |
| 353 | main.log.info( "Gathering topology information from Mininet" ) |
| 354 | devicesResults = main.FALSE # Overall Boolean for device correctness |
| 355 | linksResults = main.FALSE # Overall Boolean for link correctness |
| 356 | hostsResults = main.FALSE # Overall Boolean for host correctness |
| 357 | deviceFails = [] # Nodes where devices are incorrect |
| 358 | linkFails = [] # Nodes where links are incorrect |
| 359 | hostFails = [] # Nodes where hosts are incorrect |
| 360 | attempts = main.checkTopoAttempts # Remaining Attempts |
| 361 | |
| 362 | mnSwitches = 16 |
| 363 | mnLinks = 46 |
| 364 | mnHosts = 6 |
| 365 | |
Jon Hall | 70b2ff4 | 2015-11-17 15:49:44 -0800 | [diff] [blame] | 366 | main.step( "Comparing Mininet topology to ONOS topology" ) |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 367 | |
| 368 | while ( attempts >= 0 ) and\ |
| 369 | ( not devicesResults or not linksResults or not hostsResults ): |
| 370 | time.sleep( 2 ) |
| 371 | if not devicesResults: |
| 372 | devices = main.topo.getAllDevices( main ) |
| 373 | ports = main.topo.getAllPorts( main ) |
| 374 | devicesResults = main.TRUE |
| 375 | deviceFails = [] # Reset for each attempt |
| 376 | if not linksResults: |
| 377 | links = main.topo.getAllLinks( main ) |
| 378 | linksResults = main.TRUE |
| 379 | linkFails = [] # Reset for each attempt |
| 380 | if not hostsResults: |
| 381 | hosts = main.topo.getAllHosts( main ) |
| 382 | hostsResults = main.TRUE |
| 383 | hostFails = [] # Reset for each attempt |
| 384 | |
| 385 | # Check for matching topology on each node |
| 386 | for controller in range( main.numCtrls ): |
| 387 | controllerStr = str( controller + 1 ) # ONOS node number |
| 388 | # Compare Devices |
| 389 | if devices[ controller ] and ports[ controller ] and\ |
| 390 | "Error" not in devices[ controller ] and\ |
| 391 | "Error" not in ports[ controller ]: |
| 392 | |
| 393 | try: |
| 394 | deviceData = json.loads( devices[ controller ] ) |
| 395 | portData = json.loads( ports[ controller ] ) |
| 396 | except (TypeError,ValueError): |
| 397 | main.log.error("Could not load json:" + str( devices[ controller ] ) + ' or ' + str( ports[ controller ] )) |
| 398 | currentDevicesResult = main.FALSE |
| 399 | else: |
| 400 | if mnSwitches == len( deviceData ): |
| 401 | currentDevicesResult = main.TRUE |
| 402 | else: |
| 403 | currentDevicesResult = main.FALSE |
Jeremy | e4bc713 | 2016-03-30 14:04:01 -0700 | [diff] [blame] | 404 | main.log.error( "Node {} only sees {} device(s) but {} exist".format( |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 405 | controllerStr,len( deviceData ),mnSwitches ) ) |
| 406 | else: |
| 407 | currentDevicesResult = main.FALSE |
| 408 | if not currentDevicesResult: |
| 409 | deviceFails.append( controllerStr ) |
| 410 | devicesResults = devicesResults and currentDevicesResult |
| 411 | # Compare Links |
| 412 | if links[ controller ] and "Error" not in links[ controller ]: |
| 413 | try: |
| 414 | linkData = json.loads( links[ controller ] ) |
| 415 | except (TypeError,ValueError): |
| 416 | main.log.error("Could not load json:" + str( links[ controller ] ) ) |
| 417 | currentLinksResult = main.FALSE |
| 418 | else: |
| 419 | if mnLinks == len( linkData ): |
| 420 | currentLinksResult = main.TRUE |
| 421 | else: |
| 422 | currentLinksResult = main.FALSE |
Jeremy | e4bc713 | 2016-03-30 14:04:01 -0700 | [diff] [blame] | 423 | main.log.error( "Node {} only sees {} link(s) but {} exist".format( |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 424 | controllerStr,len( linkData ),mnLinks ) ) |
| 425 | else: |
| 426 | currentLinksResult = main.FALSE |
| 427 | if not currentLinksResult: |
| 428 | linkFails.append( controllerStr ) |
| 429 | linksResults = linksResults and currentLinksResult |
| 430 | # Compare Hosts |
| 431 | if hosts[ controller ] and "Error" not in hosts[ controller ]: |
| 432 | try: |
| 433 | hostData = json.loads( hosts[ controller ] ) |
| 434 | except (TypeError,ValueError): |
| 435 | main.log.error("Could not load json:" + str( hosts[ controller ] ) ) |
| 436 | currentHostsResult = main.FALSE |
| 437 | else: |
| 438 | if mnHosts == len( hostData ): |
| 439 | currentHostsResult = main.TRUE |
| 440 | else: |
| 441 | currentHostsResult = main.FALSE |
Jeremy | e4bc713 | 2016-03-30 14:04:01 -0700 | [diff] [blame] | 442 | main.log.error( "Node {} only sees {} host(s) but {} exist".format( |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 443 | controllerStr,len( hostData ),mnHosts ) ) |
| 444 | else: |
| 445 | currentHostsResult = main.FALSE |
| 446 | if not currentHostsResult: |
| 447 | hostFails.append( controllerStr ) |
| 448 | hostsResults = hostsResults and currentHostsResult |
| 449 | # Decrement Attempts Remaining |
| 450 | attempts -= 1 |
| 451 | |
| 452 | utilities.assert_equals( expect=[], |
| 453 | actual=deviceFails, |
| 454 | onpass="ONOS correctly discovered all devices", |
| 455 | onfail="ONOS incorrectly discovered devices on nodes: " + |
| 456 | str( deviceFails ) ) |
| 457 | utilities.assert_equals( expect=[], |
| 458 | actual=linkFails, |
| 459 | onpass="ONOS correctly discovered all links", |
| 460 | onfail="ONOS incorrectly discovered links on nodes: " + |
| 461 | str( linkFails ) ) |
| 462 | utilities.assert_equals( expect=[], |
| 463 | actual=hostFails, |
| 464 | onpass="ONOS correctly discovered all hosts", |
| 465 | onfail="ONOS incorrectly discovered hosts on nodes: " + |
| 466 | str( hostFails ) ) |
| 467 | if hostsResults and linksResults and devicesResults: |
| 468 | topoResults = main.TRUE |
| 469 | else: |
| 470 | topoResults = main.FALSE |
| 471 | utilities.assert_equals( expect=main.TRUE, |
| 472 | actual=topoResults, |
| 473 | onpass="ONOS correctly discovered the topology", |
| 474 | onfail="ONOS incorrectly discovered the topology" ) |
| 475 | |
| 476 | |
| 477 | def CASE31( self, main ): |
| 478 | import time |
| 479 | """ |
| 480 | Add bidirectional point intents between 2 packet layer( mininet ) |
| 481 | devices and ping mininet hosts |
| 482 | """ |
| 483 | main.log.report( |
| 484 | "This testcase adds bidirectional point intents between 2 " + |
| 485 | "packet layer( mininet ) devices and ping mininet hosts" ) |
| 486 | main.case( "Install point intents between 2 packet layer device and " + |
| 487 | "ping the hosts" ) |
| 488 | main.caseExplanation = "This testcase adds bidirectional point intents between 2 " +\ |
| 489 | "packet layer( mininet ) devices and ping mininet hosts" |
| 490 | |
| 491 | main.step( "Adding point intents" ) |
| 492 | checkFlowResult = main.TRUE |
| 493 | main.pIntentsId = [] |
| 494 | pIntent1 = main.CLIs[ 0 ].addPointIntent( |
| 495 | "of:0000ffffffff0001/1", |
| 496 | "of:0000ffffffff0005/1" ) |
| 497 | time.sleep( 10 ) |
| 498 | pIntent2 = main.CLIs[ 0 ].addPointIntent( |
| 499 | "of:0000ffffffff0005/1", |
| 500 | "of:0000ffffffff0001/1" ) |
| 501 | main.pIntentsId.append( pIntent1 ) |
| 502 | main.pIntentsId.append( pIntent2 ) |
| 503 | time.sleep( 10 ) |
| 504 | main.log.info( "Checking intents state") |
| 505 | checkStateResult = main.CLIs[ 0 ].checkIntentState( |
| 506 | intentsId = main.pIntentsId ) |
| 507 | time.sleep( 10 ) |
| 508 | main.log.info( "Checking flows state") |
| 509 | checkFlowResult = main.CLIs[ 0 ].checkFlowsState() |
| 510 | # Sleep for 10 seconds to provide time for the intent state to change |
| 511 | time.sleep( 10 ) |
| 512 | main.log.info( "Checking intents state one more time") |
| 513 | checkStateResult = main.CLIs[ 0 ].checkIntentState( |
| 514 | intentsId = main.pIntentsId ) |
Jeremy | e4bc713 | 2016-03-30 14:04:01 -0700 | [diff] [blame] | 515 | |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 516 | if checkStateResult and checkFlowResult: |
| 517 | addIntentsResult = main.TRUE |
| 518 | else: |
| 519 | addIntentsResult = main.FALSE |
| 520 | utilities.assert_equals( |
| 521 | expect=main.TRUE, |
| 522 | actual=addIntentsResult, |
| 523 | onpass="Successfully added point intents", |
| 524 | onfail="Failed to add point intents") |
| 525 | |
| 526 | if not addIntentsResult: |
| 527 | main.log.error( "Intents were not properly installed. Exiting case." ) |
| 528 | main.skipCase() |
| 529 | |
| 530 | main.step( "Ping h1 and h5" ) |
| 531 | pingResult = main.LincOE.pingHostOptical( src="h1", target="h5" ) |
| 532 | utilities.assert_equals( |
| 533 | expect=main.TRUE, |
| 534 | actual=pingResult, |
| 535 | onpass="Successfully pinged h1 and h5", |
| 536 | onfail="Failed to ping between h1 and h5") |
| 537 | |
| 538 | def CASE32( self ): |
| 539 | """ |
| 540 | Add host intents between 2 packet layer host |
| 541 | """ |
| 542 | import time |
| 543 | import json |
| 544 | main.log.report( "Adding host intents between 2 optical layer host" ) |
| 545 | main.case( "Test add host intents between optical layer host" ) |
| 546 | main.caseExplanation = "Test host intents between 2 optical layer host" |
| 547 | |
| 548 | main.step( "Adding host intents to h1 and h2" ) |
| 549 | hostMACs = [] |
| 550 | hostId = [] |
| 551 | # Listing host MAC addresses |
| 552 | for i in range( 1 , 7 ): |
| 553 | hostMACs.append( "00:00:00:00:00:" + |
| 554 | str( hex( i )[ 2: ] ).zfill( 2 ).upper() ) |
| 555 | for macs in hostMACs: |
| 556 | hostId.append( macs + "/-1" ) |
| 557 | host1 = hostId[ 0 ] |
| 558 | host2 = hostId[ 1 ] |
| 559 | |
| 560 | intentsId = [] |
| 561 | intent1 = main.CLIs[ 0 ].addHostIntent( hostIdOne = host1, |
| 562 | hostIdTwo = host2 ) |
| 563 | intentsId.append( intent1 ) |
| 564 | # Checking intents state before pinging |
| 565 | main.log.info( "Checking intents state" ) |
| 566 | intentResult = main.CLIs[ 0 ].checkIntentState( intentsId = intentsId ) |
| 567 | # Check intent state again if intents are not in installed state |
Jeremy | e4bc713 | 2016-03-30 14:04:01 -0700 | [diff] [blame] | 568 | |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 569 | |
| 570 | # If intent state is wrong, wait 3 sec and try again |
| 571 | if not intentResult: |
| 572 | time.sleep( 3 ) |
| 573 | intentResult = main.CLIs[ 0 ].checkIntentState( intentsId = intentsId ) |
| 574 | |
| 575 | # If intent state is still wrong, display intent states |
| 576 | if not intentResult: |
| 577 | main.log.error( main.CLIs[ 0 ].intents() ) |
Jeremy | e4bc713 | 2016-03-30 14:04:01 -0700 | [diff] [blame] | 578 | |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 579 | utilities.assert_equals( expect=main.TRUE, |
| 580 | actual=intentResult, |
| 581 | onpass="All intents are in INSTALLED state ", |
| 582 | onfail="Some of the intents are not in " + |
| 583 | "INSTALLED state " ) |
| 584 | |
| 585 | if not intentResult: |
| 586 | main.log.error( "Intents were not properly installed. Skipping Ping" ) |
| 587 | else: |
| 588 | # Pinging h1 to h2 and then ping h2 to h1 |
| 589 | main.step( "Pinging h1 and h2" ) |
| 590 | pingResult = main.TRUE |
| 591 | pingResult = main.LincOE.pingHostOptical( src="h1", target="h2" ) \ |
| 592 | and main.LincOE.pingHostOptical( src="h2",target="h1" ) |
Jeremy | e4bc713 | 2016-03-30 14:04:01 -0700 | [diff] [blame] | 593 | |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 594 | utilities.assert_equals( expect=main.TRUE, |
| 595 | actual=pingResult, |
| 596 | onpass="Pinged successfully between h1 and h2", |
| 597 | onfail="Pinged failed between h1 and h2" ) |
| 598 | |
| 599 | # Removed all added host intents |
| 600 | main.step( "Removing host intents" ) |
| 601 | removeResult = main.TRUE |
| 602 | # Check remaining intents |
Jeremy | 7134f5b | 2016-04-05 13:50:21 -0700 | [diff] [blame] | 603 | try: |
| 604 | intentsJson = json.loads( main.CLIs[ 0 ].intents() ) |
| 605 | main.CLIs[ 0 ].removeIntent( intentId=intent1, purge=True ) |
| 606 | #main.CLIs[ 0 ].removeIntent( intentId=intent2, purge=True ) |
| 607 | main.log.debug(intentsJson) |
| 608 | for intents in intentsJson: |
Jeremy | e4bc713 | 2016-03-30 14:04:01 -0700 | [diff] [blame] | 609 | main.CLIs[ 0 ].removeIntent( intentId=intents.get( 'id' ), |
| 610 | app='org.onosproject.optical', |
| 611 | purge=True ) |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 612 | |
Jeremy | 7134f5b | 2016-04-05 13:50:21 -0700 | [diff] [blame] | 613 | for i in range( main.numCtrls ): |
| 614 | if len( json.loads( main.CLIs[ i ].intents() ) ): |
| 615 | print json.loads( main.CLIs[ i ].intents() ) |
| 616 | removeResult = main.FALSE |
| 617 | except ( TypeError, ValueError ): |
| 618 | main.log.error( "Cannot see intents on Node " + str( main.CLIs[ 0 ] ) +\ |
| 619 | ". Removing all intents.") |
| 620 | main.CLIs[ 0 ].removeAllIntents( purge=True ) |
| 621 | main.CLIs[ 0 ].removeAllIntents( purge=True, app='org.onosproject.optical') |
| 622 | |
| 623 | utilities.assert_equals( expect=main.TRUE, |
| 624 | actual=removeResult, |
| 625 | onpass="Successfully removed host intents", |
| 626 | onfail="Failed to remove host intents" ) |