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