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