Jeremy Ronquillo | b27ce4c | 2017-07-17 12:41:28 -0700 | [diff] [blame] | 1 | """ |
| 2 | Copyright 2015 Open Networking Foundation (ONF) |
| 3 | |
| 4 | Please refer questions to either the onos test mailing list at <onos-test@onosproject.org>, |
| 5 | the System Testing Plans and Results wiki page at <https://wiki.onosproject.org/x/voMg>, |
| 6 | or the System Testing Guide page at <https://wiki.onosproject.org/x/WYQg> |
| 7 | |
| 8 | TestON is free software: you can redistribute it and/or modify |
| 9 | it under the terms of the GNU General Public License as published by |
| 10 | the Free Software Foundation, either version 2 of the License, or |
| 11 | (at your option) any later version. |
| 12 | |
| 13 | TestON is distributed in the hope that it will be useful, |
| 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | GNU General Public License for more details. |
| 17 | |
| 18 | You should have received a copy of the GNU General Public License |
| 19 | along with TestON. If not, see <http://www.gnu.org/licenses/>. |
| 20 | """ |
| 21 | |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 22 | # Testing the basic intent functionality of ONOS |
| 23 | |
Jon Hall | e02505a | 2017-05-24 16:36:43 -0700 | [diff] [blame] | 24 | |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 25 | class FUNCoptical: |
| 26 | |
| 27 | def __init__( self ): |
| 28 | self.default = '' |
| 29 | |
| 30 | def CASE1( self, main ): |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 31 | import imp |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 32 | import time |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 33 | import re |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 34 | """ |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 35 | - Construct tests variables |
| 36 | - GIT ( optional ) |
| 37 | - Checkout ONOS master branch |
| 38 | - Pull latest ONOS code |
| 39 | - Building ONOS ( optional ) |
| 40 | - Install ONOS package |
| 41 | - Build ONOS package |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 42 | """ |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 43 | try: |
| 44 | from tests.dependencies.ONOSSetup import ONOSSetup |
| 45 | main.testSetUp = ONOSSetup() |
| 46 | except ImportError: |
| 47 | main.log.error( "ONOSSetup not found. exiting the test" ) |
| 48 | main.exit() |
| 49 | main.testSetUp.envSetupDescription() |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 50 | stepResult = main.FALSE |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 51 | # Test variables |
| 52 | try: |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 53 | main.apps = main.params[ 'ENV' ][ 'cellApps' ] |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 54 | main.dependencyPath = main.testOnDirectory + \ |
| 55 | main.params[ 'DEPENDENCY' ][ 'path' ] |
| 56 | main.scale = ( main.params[ 'SCALE' ][ 'size' ] ).split( "," ) |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 57 | wrapperFile1 = main.params[ 'DEPENDENCY' ][ 'wrapper1' ] |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 58 | main.startUpSleep = int( main.params[ 'SLEEP' ][ 'startup' ] ) |
| 59 | main.checkIntentSleep = int( main.params[ 'SLEEP' ][ 'checkintent' ] ) |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 60 | main.checkTopoAttempts = int( main.params[ 'SLEEP' ][ 'topoAttempts' ] ) |
Jeremy Songster | 5665f1b | 2016-06-20 14:38:22 -0700 | [diff] [blame] | 61 | main.switches = int( main.params[ 'MININET' ][ 'switch' ] ) |
| 62 | main.links = int( main.params[ 'MININET' ][ 'links' ] ) |
| 63 | main.hosts = int( main.params[ 'MININET' ][ 'hosts' ] ) |
| 64 | main.opticalTopo = main.params[ 'MININET' ][ 'toponame' ] |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 65 | main.hostsData = {} |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 66 | main.assertReturnString = '' # Assembled assert return string |
Jon Hall | e02505a | 2017-05-24 16:36:43 -0700 | [diff] [blame] | 67 | main.cycle = 0 # How many times FUNCintent has run through its tests |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 68 | # -- INIT SECTION, ONLY RUNS ONCE -- # |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 69 | stepResult = main.testSetUp.envSetup() |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 70 | except Exception as e: |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 71 | main.testSetUp.envSetupException( e ) |
| 72 | main.testSetUp.evnSetupConclusion( stepResult ) |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 73 | |
| 74 | def CASE2( self, main ): |
| 75 | """ |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 76 | - Set up cell |
| 77 | - Create cell file |
| 78 | - Set cell file |
| 79 | - Verify cell file |
| 80 | - Kill ONOS process |
| 81 | - Uninstall ONOS cluster |
| 82 | - Verify ONOS start up |
| 83 | - Install ONOS cluster |
| 84 | - Connect to cli |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 85 | """ |
Jeremy | e4bc713 | 2016-03-30 14:04:01 -0700 | [diff] [blame] | 86 | main.flowCompiler = "Flow Rules" |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 87 | main.testSetUp.ONOSSetUp( main.LincOE, main.Cluster, True ) |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 88 | |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 89 | def CASE10( self, main ): |
| 90 | """ |
| 91 | Start Mininet opticalTest Topology |
| 92 | """ |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 93 | |
Jon Hall | e02505a | 2017-05-24 16:36:43 -0700 | [diff] [blame] | 94 | main.case( "Mininet with Linc-OE startup" ) |
Devin Lim | 752dd7b | 2017-06-27 14:40:03 -0700 | [diff] [blame] | 95 | main.step( "Push TopoDDriver.json to ONOS through onos-netcfg" ) |
Devin Lim | 0207527 | 2017-07-10 15:33:21 -0700 | [diff] [blame] | 96 | topoResult = True |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 97 | for ctrl in main.Cluster.active(): |
Devin Lim | 0207527 | 2017-07-10 15:33:21 -0700 | [diff] [blame] | 98 | topoResult = topoResult and \ |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 99 | main.ONOSbench.onosNetCfg(controllerIp=ctrl.ipAddress, |
| 100 | path=main.dependencyPath, |
Devin Lim | 0207527 | 2017-07-10 15:33:21 -0700 | [diff] [blame] | 101 | fileName="TopoDDriver.json") |
Devin Lim | 752dd7b | 2017-06-27 14:40:03 -0700 | [diff] [blame] | 102 | #Exit if topology did not load properly |
| 103 | if not topoResult: |
| 104 | main.cleanup() |
| 105 | main.exit() |
| 106 | |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 107 | main.caseExplanation = "Start opticalTest.py topology included with ONOS" |
| 108 | main.step( "Starting mininet and LINC-OE" ) |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 109 | time.sleep( 10 ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 110 | controllerIPs = ','.join( main.Cluster.getIps() ) |
Devin Lim | 752dd7b | 2017-06-27 14:40:03 -0700 | [diff] [blame] | 111 | cIps = "" |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 112 | for i in range( 0, 4 ): |
Devin Lim | 752dd7b | 2017-06-27 14:40:03 -0700 | [diff] [blame] | 113 | cIps += controllerIPs + ' ' |
| 114 | opticalMnScript = main.LincOE.runOpticalMnScript( ctrllerIP=cIps, topology=main.opticalTopo ) |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 115 | topoResult = opticalMnScript |
| 116 | utilities.assert_equals( |
| 117 | expect=main.TRUE, |
| 118 | actual=topoResult, |
| 119 | onpass="Started the topology successfully ", |
Jon Hall | e02505a | 2017-05-24 16:36:43 -0700 | [diff] [blame] | 120 | onfail="Failed to start the topology" ) |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 121 | |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 122 | def CASE14( self, main ): |
| 123 | """ |
| 124 | Stop mininet |
| 125 | """ |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 126 | try: |
| 127 | from tests.dependencies.utils import Utils |
| 128 | except ImportError: |
| 129 | main.log.error( "Utils not found exiting the test" ) |
| 130 | main.exit() |
| 131 | try: |
| 132 | main.Utils |
| 133 | except ( NameError, AttributeError ): |
| 134 | main.Utils = Utils() |
| 135 | main.Utils.mininetCleanIntro() |
| 136 | topoResult = main.Utils.mininetCleanup( main.LincOE, timeout=180 ) |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 137 | # Exit if topology did not load properly |
| 138 | if not topoResult: |
| 139 | main.cleanup() |
| 140 | main.exit() |
| 141 | |
Jeremy Songster | 5665f1b | 2016-06-20 14:38:22 -0700 | [diff] [blame] | 142 | def CASE16( self, main ): |
| 143 | """ |
| 144 | Balance Masters |
| 145 | """ |
| 146 | main.case( "Balance mastership of switches" ) |
| 147 | main.step( "Balancing mastership of switches" ) |
| 148 | |
| 149 | balanceResult = main.FALSE |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 150 | balanceResult = utilities.retry( f=main.Cluster.active( 0 ).CLI.balanceMasters, retValue=main.FALSE, args=[] ) |
Jeremy Songster | 5665f1b | 2016-06-20 14:38:22 -0700 | [diff] [blame] | 151 | |
| 152 | utilities.assert_equals( expect=main.TRUE, |
| 153 | actual=balanceResult, |
| 154 | onpass="Successfully balanced mastership of switches", |
| 155 | onfail="Failed to balance mastership of switches" ) |
| 156 | if not balanceResult: |
| 157 | main.initialized = main.FALSE |
| 158 | |
Jeremy | e4bc713 | 2016-03-30 14:04:01 -0700 | [diff] [blame] | 159 | def CASE17( self, main ): |
| 160 | """ |
| 161 | Use Flow Objectives |
| 162 | """ |
| 163 | main.case( "Enable intent compilation using Flow Objectives" ) |
| 164 | main.step( "Enabling Flow Objectives" ) |
| 165 | |
| 166 | main.flowCompiler = "Flow Objectives" |
| 167 | |
| 168 | cmd = "org.onosproject.net.intent.impl.compiler.IntentConfigurableRegistrator" |
| 169 | |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 170 | stepResult = main.Cluster.active( 0 ).CLI.setCfg( component=cmd, |
| 171 | propName="useFlowObjectives", value="true" ) |
| 172 | stepResult &= main.Cluster.active( 0 ).CLI.setCfg( component=cmd, |
| 173 | propName="defaultFlowObjectiveCompiler", |
| 174 | value='org.onosproject.net.intent.impl.compiler.LinkCollectionIntentObjectiveCompiler' ) |
Jeremy | e4bc713 | 2016-03-30 14:04:01 -0700 | [diff] [blame] | 175 | |
| 176 | utilities.assert_equals( expect=main.TRUE, |
| 177 | actual=stepResult, |
| 178 | onpass="Successfully activated Flow Objectives", |
| 179 | onfail="Failed to activate Flow Objectives" ) |
| 180 | |
Jeremy Songster | 17147f2 | 2016-05-31 18:30:52 -0700 | [diff] [blame] | 181 | def CASE19( self, main ): |
| 182 | """ |
| 183 | Copy the karaf.log files after each testcase cycle |
| 184 | """ |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 185 | try: |
| 186 | from tests.dependencies.utils import Utils |
| 187 | except ImportError: |
| 188 | main.log.error( "Utils not found exiting the test" ) |
| 189 | main.exit() |
| 190 | try: |
| 191 | main.Utils |
| 192 | except ( NameError, AttributeError ): |
| 193 | main.Utils = Utils() |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 194 | main.Utils.copyKarafLog( "cycle" + str( main.cycle ) ) |
Jon Hall | e02505a | 2017-05-24 16:36:43 -0700 | [diff] [blame] | 195 | def CASE21( self, main ): |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 196 | """ |
| 197 | Run pingall to discover all hosts |
| 198 | """ |
| 199 | main.case( "Running Pingall" ) |
| 200 | main.caseExplanation = "Use pingall to discover all hosts. Pingall is expected to fail." |
| 201 | main.step( "Discover Hosts through Pingall" ) |
Jon Hall | e02505a | 2017-05-24 16:36:43 -0700 | [diff] [blame] | 202 | pingResult = main.LincOE.pingall( timeout=120 ) |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 203 | |
| 204 | utilities.assert_equals( expect=main.FALSE, |
| 205 | actual=pingResult, |
| 206 | onpass="Pingall Completed", |
| 207 | onfail="Pingall did not complete or did not return fales" ) |
| 208 | |
Jon Hall | e02505a | 2017-05-24 16:36:43 -0700 | [diff] [blame] | 209 | def CASE22( self, main ): |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 210 | """ |
| 211 | Send arpings to discover all hosts |
| 212 | """ |
| 213 | main.case( "Discover Hosts with arping" ) |
| 214 | main.caseExplanation = "Send arpings between all the hosts to discover and verify them" |
| 215 | |
| 216 | main.step( "Send arping between all hosts" ) |
| 217 | |
Jeremy Songster | 5665f1b | 2016-06-20 14:38:22 -0700 | [diff] [blame] | 218 | hosts = [] |
| 219 | for i in range( main.hosts ): |
| 220 | hosts.append( 'h{}'.format( i + 1 ) ) |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 221 | |
| 222 | arpingHostResults = main.TRUE |
| 223 | for host in hosts: |
Devin Lim | 752dd7b | 2017-06-27 14:40:03 -0700 | [diff] [blame] | 224 | if main.LincOE.arping( host, ethDevice=host+"-eth0" ): |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 225 | main.log.info( "Successfully reached host {} with arping".format( host ) ) |
| 226 | else: |
| 227 | main.log.error( "Could not reach host {} with arping".format( host ) ) |
| 228 | arpingHostResults = main.FALSE |
| 229 | |
| 230 | utilities.assert_equals( expect=main.TRUE, |
| 231 | actual=arpingHostResults, |
| 232 | onpass="Successfully discovered all hosts", |
| 233 | onfail="Could not descover some hosts" ) |
| 234 | |
| 235 | def CASE23( self, main ): |
| 236 | """ |
| 237 | Compare ONOS Topology to Mininet Topology |
| 238 | """ |
| 239 | import json |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 240 | try: |
| 241 | from tests.dependencies.topology import Topology |
| 242 | except ImportError: |
| 243 | main.log.error( "Topology not found exiting the test" ) |
| 244 | main.exit() |
| 245 | try: |
| 246 | main.topoRelated |
| 247 | except ( NameError, AttributeError ): |
| 248 | main.topoRelated = Topology() |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 249 | main.case( "Compare ONOS Topology view to Mininet topology" ) |
| 250 | main.caseExplanation = "Compare topology elements between Mininet" +\ |
| 251 | " and ONOS" |
| 252 | |
| 253 | main.log.info( "Gathering topology information from Mininet" ) |
| 254 | devicesResults = main.FALSE # Overall Boolean for device correctness |
| 255 | linksResults = main.FALSE # Overall Boolean for link correctness |
| 256 | hostsResults = main.FALSE # Overall Boolean for host correctness |
| 257 | deviceFails = [] # Nodes where devices are incorrect |
| 258 | linkFails = [] # Nodes where links are incorrect |
| 259 | hostFails = [] # Nodes where hosts are incorrect |
| 260 | attempts = main.checkTopoAttempts # Remaining Attempts |
| 261 | |
Jeremy Songster | 5665f1b | 2016-06-20 14:38:22 -0700 | [diff] [blame] | 262 | mnSwitches = main.switches |
| 263 | mnLinks = main.links |
| 264 | mnHosts = main.hosts |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 265 | |
Jon Hall | 70b2ff4 | 2015-11-17 15:49:44 -0800 | [diff] [blame] | 266 | main.step( "Comparing Mininet topology to ONOS topology" ) |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 267 | |
| 268 | while ( attempts >= 0 ) and\ |
Jon Hall | e02505a | 2017-05-24 16:36:43 -0700 | [diff] [blame] | 269 | ( not devicesResults or not linksResults or not hostsResults ): |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 270 | time.sleep( 2 ) |
| 271 | if not devicesResults: |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 272 | devices = main.topoRelated.getAll( "devices", False ) |
| 273 | ports = main.topoRelated.getAll( "ports", False ) |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 274 | devicesResults = main.TRUE |
| 275 | deviceFails = [] # Reset for each attempt |
| 276 | if not linksResults: |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 277 | links = main.topoRelated.getAll( "links", False ) |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 278 | linksResults = main.TRUE |
| 279 | linkFails = [] # Reset for each attempt |
| 280 | if not hostsResults: |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 281 | hosts = main.topoRelated.getAll( "hosts", False ) |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 282 | hostsResults = main.TRUE |
| 283 | hostFails = [] # Reset for each attempt |
| 284 | |
| 285 | # Check for matching topology on each node |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 286 | for controller in range( main.Cluster.numCtrls ): |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 287 | controllerStr = str( controller + 1 ) # ONOS node number |
| 288 | # Compare Devices |
| 289 | if devices[ controller ] and ports[ controller ] and\ |
Jon Hall | e02505a | 2017-05-24 16:36:43 -0700 | [diff] [blame] | 290 | "Error" not in devices[ controller ] and\ |
| 291 | "Error" not in ports[ controller ]: |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 292 | |
| 293 | try: |
| 294 | deviceData = json.loads( devices[ controller ] ) |
| 295 | portData = json.loads( ports[ controller ] ) |
Jon Hall | e02505a | 2017-05-24 16:36:43 -0700 | [diff] [blame] | 296 | except ( TypeError, ValueError ): |
| 297 | main.log.error( "Could not load json:" + str( devices[ controller ] ) + ' or ' + str( ports[ controller ] ) ) |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 298 | currentDevicesResult = main.FALSE |
| 299 | else: |
| 300 | if mnSwitches == len( deviceData ): |
| 301 | currentDevicesResult = main.TRUE |
| 302 | else: |
| 303 | currentDevicesResult = main.FALSE |
Jeremy | e4bc713 | 2016-03-30 14:04:01 -0700 | [diff] [blame] | 304 | main.log.error( "Node {} only sees {} device(s) but {} exist".format( |
Jon Hall | e02505a | 2017-05-24 16:36:43 -0700 | [diff] [blame] | 305 | controllerStr, len( deviceData ), mnSwitches ) ) |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 306 | else: |
| 307 | currentDevicesResult = main.FALSE |
| 308 | if not currentDevicesResult: |
| 309 | deviceFails.append( controllerStr ) |
| 310 | devicesResults = devicesResults and currentDevicesResult |
| 311 | # Compare Links |
| 312 | if links[ controller ] and "Error" not in links[ controller ]: |
| 313 | try: |
| 314 | linkData = json.loads( links[ controller ] ) |
Jon Hall | e02505a | 2017-05-24 16:36:43 -0700 | [diff] [blame] | 315 | except ( TypeError, ValueError ): |
| 316 | main.log.error( "Could not load json:" + str( links[ controller ] ) ) |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 317 | currentLinksResult = main.FALSE |
| 318 | else: |
| 319 | if mnLinks == len( linkData ): |
| 320 | currentLinksResult = main.TRUE |
| 321 | else: |
| 322 | currentLinksResult = main.FALSE |
Jeremy | e4bc713 | 2016-03-30 14:04:01 -0700 | [diff] [blame] | 323 | main.log.error( "Node {} only sees {} link(s) but {} exist".format( |
Jon Hall | e02505a | 2017-05-24 16:36:43 -0700 | [diff] [blame] | 324 | controllerStr, len( linkData ), mnLinks ) ) |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 325 | else: |
| 326 | currentLinksResult = main.FALSE |
| 327 | if not currentLinksResult: |
| 328 | linkFails.append( controllerStr ) |
| 329 | linksResults = linksResults and currentLinksResult |
| 330 | # Compare Hosts |
| 331 | if hosts[ controller ] and "Error" not in hosts[ controller ]: |
| 332 | try: |
| 333 | hostData = json.loads( hosts[ controller ] ) |
Jon Hall | e02505a | 2017-05-24 16:36:43 -0700 | [diff] [blame] | 334 | except ( TypeError, ValueError ): |
| 335 | main.log.error( "Could not load json:" + str( hosts[ controller ] ) ) |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 336 | currentHostsResult = main.FALSE |
| 337 | else: |
| 338 | if mnHosts == len( hostData ): |
| 339 | currentHostsResult = main.TRUE |
| 340 | else: |
| 341 | currentHostsResult = main.FALSE |
Jeremy | e4bc713 | 2016-03-30 14:04:01 -0700 | [diff] [blame] | 342 | main.log.error( "Node {} only sees {} host(s) but {} exist".format( |
Jon Hall | e02505a | 2017-05-24 16:36:43 -0700 | [diff] [blame] | 343 | controllerStr, len( hostData ), mnHosts ) ) |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 344 | else: |
| 345 | currentHostsResult = main.FALSE |
| 346 | if not currentHostsResult: |
| 347 | hostFails.append( controllerStr ) |
| 348 | hostsResults = hostsResults and currentHostsResult |
| 349 | # Decrement Attempts Remaining |
| 350 | attempts -= 1 |
| 351 | |
| 352 | utilities.assert_equals( expect=[], |
| 353 | actual=deviceFails, |
| 354 | onpass="ONOS correctly discovered all devices", |
| 355 | onfail="ONOS incorrectly discovered devices on nodes: " + |
| 356 | str( deviceFails ) ) |
| 357 | utilities.assert_equals( expect=[], |
| 358 | actual=linkFails, |
| 359 | onpass="ONOS correctly discovered all links", |
| 360 | onfail="ONOS incorrectly discovered links on nodes: " + |
| 361 | str( linkFails ) ) |
| 362 | utilities.assert_equals( expect=[], |
| 363 | actual=hostFails, |
| 364 | onpass="ONOS correctly discovered all hosts", |
| 365 | onfail="ONOS incorrectly discovered hosts on nodes: " + |
| 366 | str( hostFails ) ) |
| 367 | if hostsResults and linksResults and devicesResults: |
| 368 | topoResults = main.TRUE |
| 369 | else: |
| 370 | topoResults = main.FALSE |
| 371 | utilities.assert_equals( expect=main.TRUE, |
| 372 | actual=topoResults, |
| 373 | onpass="ONOS correctly discovered the topology", |
| 374 | onfail="ONOS incorrectly discovered the topology" ) |
| 375 | |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 376 | |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 377 | def CASE31( self, main ): |
| 378 | import time |
| 379 | """ |
| 380 | Add bidirectional point intents between 2 packet layer( mininet ) |
| 381 | devices and ping mininet hosts |
| 382 | """ |
| 383 | main.log.report( |
| 384 | "This testcase adds bidirectional point intents between 2 " + |
| 385 | "packet layer( mininet ) devices and ping mininet hosts" ) |
| 386 | main.case( "Install point intents between 2 packet layer device and " + |
| 387 | "ping the hosts" ) |
| 388 | main.caseExplanation = "This testcase adds bidirectional point intents between 2 " +\ |
| 389 | "packet layer( mininet ) devices and ping mininet hosts" |
| 390 | |
| 391 | main.step( "Adding point intents" ) |
| 392 | checkFlowResult = main.TRUE |
| 393 | main.pIntentsId = [] |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 394 | pIntent1 = main.Cluster.active( 0 ).CLI.addPointIntent( |
Devin Lim | 752dd7b | 2017-06-27 14:40:03 -0700 | [diff] [blame] | 395 | "of:0000000000000015/1", |
| 396 | "of:000000000000000b/2" ) |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 397 | time.sleep( 10 ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 398 | pIntent2 = main.Cluster.active( 0 ).CLI.addPointIntent( |
Devin Lim | 752dd7b | 2017-06-27 14:40:03 -0700 | [diff] [blame] | 399 | "of:000000000000000b/2", |
| 400 | "of:0000000000000015/1" ) |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 401 | main.pIntentsId.append( pIntent1 ) |
| 402 | main.pIntentsId.append( pIntent2 ) |
| 403 | time.sleep( 10 ) |
Jon Hall | e02505a | 2017-05-24 16:36:43 -0700 | [diff] [blame] | 404 | main.log.info( "Checking intents state" ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 405 | checkStateResult = main.Cluster.active( 0 ).CLI.checkIntentState( |
| 406 | intentsId=main.pIntentsId ) |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 407 | time.sleep( 10 ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 408 | checkStateResult = utilities.retry( f=main.Cluster.active( 0 ).CLI.checkIntentState, |
Devin Lim | 752dd7b | 2017-06-27 14:40:03 -0700 | [diff] [blame] | 409 | retValue=main.FALSE, args=( main.pIntentsId, "INSTALLED" ), |
| 410 | sleep=main.checkIntentSleep, attempts=10 ) |
Jon Hall | e02505a | 2017-05-24 16:36:43 -0700 | [diff] [blame] | 411 | main.log.info( "Checking flows state" ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 412 | checkFlowResult = main.Cluster.active( 0 ).CLI.checkFlowsState() |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 413 | # Sleep for 10 seconds to provide time for the intent state to change |
| 414 | time.sleep( 10 ) |
Jon Hall | e02505a | 2017-05-24 16:36:43 -0700 | [diff] [blame] | 415 | main.log.info( "Checking intents state one more time" ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 416 | checkStateResult = main.Cluster.active( 0 ).CLI.checkIntentState( |
Jon Hall | e02505a | 2017-05-24 16:36:43 -0700 | [diff] [blame] | 417 | intentsId=main.pIntentsId ) |
Jeremy | e4bc713 | 2016-03-30 14:04:01 -0700 | [diff] [blame] | 418 | |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 419 | if checkStateResult and checkFlowResult: |
| 420 | addIntentsResult = main.TRUE |
| 421 | else: |
| 422 | addIntentsResult = main.FALSE |
| 423 | utilities.assert_equals( |
| 424 | expect=main.TRUE, |
| 425 | actual=addIntentsResult, |
| 426 | onpass="Successfully added point intents", |
Jon Hall | e02505a | 2017-05-24 16:36:43 -0700 | [diff] [blame] | 427 | onfail="Failed to add point intents" ) |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 428 | |
Jeremy Songster | 5665f1b | 2016-06-20 14:38:22 -0700 | [diff] [blame] | 429 | pingResult = main.FALSE |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 430 | |
Jeremy Songster | 5665f1b | 2016-06-20 14:38:22 -0700 | [diff] [blame] | 431 | if not addIntentsResult: |
| 432 | main.log.error( "Intents were not properly installed. Skipping ping." ) |
| 433 | |
| 434 | else: |
| 435 | main.step( "Ping h1 and h2" ) |
| 436 | pingResult = main.LincOE.pingHostOptical( src="h1", target="h2" ) |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 437 | utilities.assert_equals( |
| 438 | expect=main.TRUE, |
| 439 | actual=pingResult, |
Jeremy Songster | 5665f1b | 2016-06-20 14:38:22 -0700 | [diff] [blame] | 440 | onpass="Successfully pinged h1 and h2", |
Jon Hall | e02505a | 2017-05-24 16:36:43 -0700 | [diff] [blame] | 441 | onfail="Failed to ping between h1 and h2" ) |
Jeremy Songster | 5665f1b | 2016-06-20 14:38:22 -0700 | [diff] [blame] | 442 | |
| 443 | main.step( "Remove Point to Point intents" ) |
Devin Lim | 752dd7b | 2017-06-27 14:40:03 -0700 | [diff] [blame] | 444 | removeResult = main.TRUE |
Jeremy Songster | 5665f1b | 2016-06-20 14:38:22 -0700 | [diff] [blame] | 445 | # Check remaining intents |
| 446 | try: |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 447 | intentsJson = json.loads( main.Cluster.active( 0 ).CLI.intents() ) |
Jeremy Songster | 5665f1b | 2016-06-20 14:38:22 -0700 | [diff] [blame] | 448 | main.log.debug( intentsJson ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 449 | main.Cluster.active( 0 ).CLI.removeIntent( intentId=pIntent1, purge=True ) |
| 450 | main.Cluster.active( 0 ).CLI.removeIntent( intentId=pIntent2, purge=True ) |
Jeremy Songster | 5665f1b | 2016-06-20 14:38:22 -0700 | [diff] [blame] | 451 | for intents in intentsJson: |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 452 | main.Cluster.active( 0 ).CLI.removeIntent( intentId=intents.get( 'id' ), |
| 453 | app='org.onosproject.cli', |
| 454 | purge=True ) |
Jeremy Songster | 5665f1b | 2016-06-20 14:38:22 -0700 | [diff] [blame] | 455 | time.sleep( 15 ) |
| 456 | |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 457 | for ctrl in main.Cluster.active(): |
Devin Lim | 752dd7b | 2017-06-27 14:40:03 -0700 | [diff] [blame] | 458 | if not any ( intent.get('state') == 'WITHDRAWING' for intent |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 459 | in json.loads( ctrl.CLI.intents() ) ): |
| 460 | main.log.debug( json.loads( ctrl.CLI.intents() ) ) |
Devin Lim | 752dd7b | 2017-06-27 14:40:03 -0700 | [diff] [blame] | 461 | removeResult = main.FALSE |
| 462 | break |
Jeremy Songster | 5665f1b | 2016-06-20 14:38:22 -0700 | [diff] [blame] | 463 | else: |
| 464 | removeResult = main.TRUE |
| 465 | except ( TypeError, ValueError ): |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 466 | main.log.error( "Cannot see intents on " + main.Cluster.active( 0 ).name + |
Jon Hall | e02505a | 2017-05-24 16:36:43 -0700 | [diff] [blame] | 467 | ". Removing all intents." ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 468 | main.Cluster.active( 0 ).CLI.removeAllIntents( purge=True ) |
| 469 | main.Cluster.active( 0 ).CLI.removeAllIntents( purge=True, app='org.onosproject.cli' ) |
Jeremy Songster | 5665f1b | 2016-06-20 14:38:22 -0700 | [diff] [blame] | 470 | |
| 471 | utilities.assert_equals( expect=main.TRUE, |
| 472 | actual=removeResult, |
| 473 | onpass="Successfully removed host intents", |
| 474 | onfail="Failed to remove host intents" ) |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 475 | |
| 476 | def CASE32( self ): |
| 477 | """ |
| 478 | Add host intents between 2 packet layer host |
| 479 | """ |
| 480 | import time |
| 481 | import json |
| 482 | main.log.report( "Adding host intents between 2 optical layer host" ) |
| 483 | main.case( "Test add host intents between optical layer host" ) |
| 484 | main.caseExplanation = "Test host intents between 2 optical layer host" |
| 485 | |
Jeremy Songster | 5665f1b | 2016-06-20 14:38:22 -0700 | [diff] [blame] | 486 | main.step( "Creating list of hosts" ) |
| 487 | hostnum = 0 |
| 488 | try: |
| 489 | hostData = json.loads( hosts[ controller ] ) |
| 490 | except( TypeError, ValueError ): |
Jon Hall | e02505a | 2017-05-24 16:36:43 -0700 | [diff] [blame] | 491 | main.log.error( "Could not load json:" + str( hosts[ controller ] ) ) |
Jeremy Songster | 5665f1b | 2016-06-20 14:38:22 -0700 | [diff] [blame] | 492 | |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 493 | main.step( "Adding host intents to h1 and h2" ) |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 494 | hostId = [] |
| 495 | # Listing host MAC addresses |
Jeremy Songster | 5665f1b | 2016-06-20 14:38:22 -0700 | [diff] [blame] | 496 | for host in hostData: |
Jon Hall | e02505a | 2017-05-24 16:36:43 -0700 | [diff] [blame] | 497 | hostId.append( host.get( "id" ) ) |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 498 | host1 = hostId[ 0 ] |
| 499 | host2 = hostId[ 1 ] |
Jeremy Songster | 5665f1b | 2016-06-20 14:38:22 -0700 | [diff] [blame] | 500 | main.log.debug( host1 ) |
| 501 | main.log.debug( host2 ) |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 502 | |
| 503 | intentsId = [] |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 504 | intent1 = main.Cluster.active( 0 ).CLI.addHostIntent( hostIdOne=host1, |
| 505 | hostIdTwo=host2 ) |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 506 | intentsId.append( intent1 ) |
| 507 | # Checking intents state before pinging |
| 508 | main.log.info( "Checking intents state" ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 509 | intentResult = utilities.retry( f=main.Cluster.active( 0 ).CLI.checkIntentState, |
Jeremy Songster | 5665f1b | 2016-06-20 14:38:22 -0700 | [diff] [blame] | 510 | retValue=main.FALSE, args=intentsId, |
| 511 | sleep=main.checkIntentSleep, attempts=10 ) |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 512 | |
| 513 | # If intent state is still wrong, display intent states |
| 514 | if not intentResult: |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 515 | main.log.error( main.Cluster.active( 0 ).CLI.intents() ) |
Jeremy | e4bc713 | 2016-03-30 14:04:01 -0700 | [diff] [blame] | 516 | |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 517 | utilities.assert_equals( expect=main.TRUE, |
| 518 | actual=intentResult, |
| 519 | onpass="All intents are in INSTALLED state ", |
| 520 | onfail="Some of the intents are not in " + |
| 521 | "INSTALLED state " ) |
| 522 | |
| 523 | if not intentResult: |
| 524 | main.log.error( "Intents were not properly installed. Skipping Ping" ) |
| 525 | else: |
| 526 | # Pinging h1 to h2 and then ping h2 to h1 |
| 527 | main.step( "Pinging h1 and h2" ) |
| 528 | pingResult = main.TRUE |
| 529 | pingResult = main.LincOE.pingHostOptical( src="h1", target="h2" ) \ |
Jon Hall | e02505a | 2017-05-24 16:36:43 -0700 | [diff] [blame] | 530 | and main.LincOE.pingHostOptical( src="h2", target="h1" ) |
Jeremy | e4bc713 | 2016-03-30 14:04:01 -0700 | [diff] [blame] | 531 | |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 532 | utilities.assert_equals( expect=main.TRUE, |
| 533 | actual=pingResult, |
| 534 | onpass="Pinged successfully between h1 and h2", |
| 535 | onfail="Pinged failed between h1 and h2" ) |
| 536 | |
| 537 | # Removed all added host intents |
| 538 | main.step( "Removing host intents" ) |
| 539 | removeResult = main.TRUE |
| 540 | # Check remaining intents |
Jeremy | 7134f5b | 2016-04-05 13:50:21 -0700 | [diff] [blame] | 541 | try: |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 542 | intentsJson = json.loads( main.Cluster.active( 0 ).CLI.intents() ) |
| 543 | main.Cluster.active( 0 ).CLI.removeIntent( intentId=intent1, purge=True ) |
Jon Hall | e02505a | 2017-05-24 16:36:43 -0700 | [diff] [blame] | 544 | main.log.debug( intentsJson ) |
Jeremy | 7134f5b | 2016-04-05 13:50:21 -0700 | [diff] [blame] | 545 | for intents in intentsJson: |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 546 | main.Cluster.active( 0 ).CLI.removeIntent( intentId=intents.get( 'id' ), |
| 547 | app='org.onosproject.optical', |
| 548 | purge=True ) |
Jeremy Songster | 5665f1b | 2016-06-20 14:38:22 -0700 | [diff] [blame] | 549 | time.sleep( 15 ) |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 550 | |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 551 | for ctrl in main.Cluster.active(): |
Devin Lim | 752dd7b | 2017-06-27 14:40:03 -0700 | [diff] [blame] | 552 | if not any ( intent.get('state') == 'WITHDRAWING' for intent |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 553 | in json.loads( ctrl.CLI.intents() ) ): |
| 554 | main.log.debug( json.loads( ctrl.CLI.intents() ) ) |
Devin Lim | 752dd7b | 2017-06-27 14:40:03 -0700 | [diff] [blame] | 555 | removeResult = main.FALSE |
| 556 | break |
Jeremy Songster | 5665f1b | 2016-06-20 14:38:22 -0700 | [diff] [blame] | 557 | else: |
| 558 | removeResult = main.TRUE |
Jeremy | 7134f5b | 2016-04-05 13:50:21 -0700 | [diff] [blame] | 559 | except ( TypeError, ValueError ): |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 560 | main.log.error( "Cannot see intents on " + main.Cluster.active( 0 ).name + |
Jon Hall | e02505a | 2017-05-24 16:36:43 -0700 | [diff] [blame] | 561 | ". Removing all intents." ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 562 | main.Cluster.active( 0 ).CLI.removeAllIntents( purge=True ) |
| 563 | main.Cluster.active( 0 ).CLI.removeAllIntents( purge=True, app='org.onosproject.optical' ) |
Jeremy | 7134f5b | 2016-04-05 13:50:21 -0700 | [diff] [blame] | 564 | |
| 565 | utilities.assert_equals( expect=main.TRUE, |
| 566 | actual=removeResult, |
| 567 | onpass="Successfully removed host intents", |
Chiyu Cheng | ef10950 | 2016-11-21 15:51:38 -0800 | [diff] [blame] | 568 | onfail="Failed to remove host intents" ) |