GlennRC | 5147a42 | 2015-10-06 17:26:17 -0700 | [diff] [blame] | 1 | class FUNCflow: |
| 2 | |
| 3 | def __init__( self ): |
| 4 | self.default = '' |
| 5 | |
| 6 | def CASE1( self, main ): |
GlennRC | 5147a42 | 2015-10-06 17:26:17 -0700 | [diff] [blame] | 7 | import os |
| 8 | import imp |
| 9 | |
| 10 | """ |
| 11 | - Construct tests variables |
| 12 | - GIT ( optional ) |
| 13 | - Checkout ONOS master branch |
| 14 | - Pull latest ONOS code |
| 15 | - Building ONOS ( optional ) |
| 16 | - Install ONOS package |
| 17 | - Build ONOS package |
| 18 | """ |
| 19 | |
| 20 | main.case( "Constructing test variables and building ONOS package" ) |
| 21 | main.step( "Constructing test variables" ) |
GlennRC | 5147a42 | 2015-10-06 17:26:17 -0700 | [diff] [blame] | 22 | |
| 23 | # Test variables |
| 24 | main.testOnDirectory = os.path.dirname( os.getcwd ( ) ) |
| 25 | main.cellName = main.params[ 'ENV' ][ 'cellName' ] |
| 26 | main.apps = main.params[ 'ENV' ][ 'cellApps' ] |
| 27 | gitBranch = main.params[ 'GIT' ][ 'branch' ] |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 28 | gitPull = main.params[ 'GIT' ][ 'pull' ] |
| 29 | main.ONOSport = main.params[ 'CTRL' ][ 'port' ] |
GlennRC | 5147a42 | 2015-10-06 17:26:17 -0700 | [diff] [blame] | 30 | main.dependencyPath = main.testOnDirectory + \ |
| 31 | main.params[ 'DEPENDENCY' ][ 'path' ] |
GlennRC | 5147a42 | 2015-10-06 17:26:17 -0700 | [diff] [blame] | 32 | wrapperFile1 = main.params[ 'DEPENDENCY' ][ 'wrapper1' ] |
GlennRC | 1704d07 | 2015-10-07 18:40:45 -0700 | [diff] [blame] | 33 | wrapperFile2 = main.params[ 'DEPENDENCY' ][ 'wrapper2' ] |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 34 | main.topology = main.params[ 'DEPENDENCY' ][ 'topology' ] |
| 35 | main.maxNodes = int( main.params[ 'SCALE' ][ 'max' ] ) |
GlennRC | 5147a42 | 2015-10-06 17:26:17 -0700 | [diff] [blame] | 36 | main.startUpSleep = int( main.params[ 'SLEEP' ][ 'startup' ] ) |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 37 | main.startMNSleep = int( main.params[ 'SLEEP' ][ 'startMN' ] ) |
| 38 | main.addFlowSleep = int( main.params[ 'SLEEP' ][ 'addFlow' ] ) |
| 39 | main.delFlowSleep = int( main.params[ 'SLEEP' ][ 'delFlow' ] ) |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 40 | main.debug = main.params[ 'DEBUG' ] |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 41 | main.swDPID = main.params[ 'TEST' ][ 'swDPID' ] |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 42 | main.cellData = { } # for creating cell file |
| 43 | main.CLIs = [ ] |
| 44 | main.ONOSip = [ ] |
GlennRC | 5147a42 | 2015-10-06 17:26:17 -0700 | [diff] [blame] | 45 | |
GlennRC | 956ea74 | 2015-11-05 16:14:15 -0800 | [diff] [blame] | 46 | main.debug = True if "on" in main.debug else False |
| 47 | |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 48 | main.ONOSip = main.ONOSbench.getOnosIps( ) |
GlennRC | 5147a42 | 2015-10-06 17:26:17 -0700 | [diff] [blame] | 49 | |
| 50 | # Assigning ONOS cli handles to a list |
| 51 | for i in range( 1, main.maxNodes + 1 ): |
| 52 | main.CLIs.append( getattr( main, 'ONOScli' + str( i ) ) ) |
| 53 | |
| 54 | # -- INIT SECTION, ONLY RUNS ONCE -- # |
| 55 | main.startUp = imp.load_source( wrapperFile1, |
| 56 | main.dependencyPath + |
| 57 | wrapperFile1 + |
| 58 | ".py" ) |
| 59 | |
GlennRC | 1704d07 | 2015-10-07 18:40:45 -0700 | [diff] [blame] | 60 | main.topo = imp.load_source( wrapperFile2, |
| 61 | main.dependencyPath + |
| 62 | wrapperFile2 + |
| 63 | ".py" ) |
| 64 | |
GlennRC | 956ea74 | 2015-11-05 16:14:15 -0800 | [diff] [blame] | 65 | |
GlennRC | 94ed223 | 2015-10-07 15:08:57 -0700 | [diff] [blame] | 66 | copyResult = main.ONOSbench.scp( main.Mininet1, |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 67 | main.dependencyPath + main.topology, |
| 68 | main.Mininet1.home + '/custom/', |
GlennRC | 94ed223 | 2015-10-07 15:08:57 -0700 | [diff] [blame] | 69 | direction="to" ) |
| 70 | |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 71 | utilities.assert_equals( expect=main.TRUE, |
Jeremy Songster | e7f3b34 | 2016-08-17 14:56:49 -0700 | [diff] [blame] | 72 | actual=copyResult, |
| 73 | onpass="Successfully copy " + "test variables ", |
| 74 | onfail="Failed to copy test variables" ) |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 75 | |
| 76 | |
GlennRC | 5147a42 | 2015-10-06 17:26:17 -0700 | [diff] [blame] | 77 | if main.CLIs: |
| 78 | stepResult = main.TRUE |
| 79 | else: |
| 80 | main.log.error( "Did not properly created list of ONOS CLI handle" ) |
| 81 | stepResult = main.FALSE |
| 82 | |
| 83 | utilities.assert_equals( expect=main.TRUE, |
| 84 | actual=stepResult, |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 85 | onpass="Successfully construct " + "test variables ", |
GlennRC | 5147a42 | 2015-10-06 17:26:17 -0700 | [diff] [blame] | 86 | onfail="Failed to construct test variables" ) |
| 87 | |
| 88 | if gitPull == 'True': |
| 89 | main.step( "Building ONOS in " + gitBranch + " branch" ) |
| 90 | onosBuildResult = main.startUp.onosBuild( main, gitBranch ) |
| 91 | stepResult = onosBuildResult |
| 92 | utilities.assert_equals( expect=main.TRUE, |
| 93 | actual=stepResult, |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 94 | onpass="Successfully compiled " + "latest ONOS", |
| 95 | onfail="Failed to compile " + "latest ONOS" ) |
GlennRC | 5147a42 | 2015-10-06 17:26:17 -0700 | [diff] [blame] | 96 | else: |
| 97 | main.log.warn( "Did not pull new code so skipping mvn " + |
| 98 | "clean install" ) |
| 99 | |
| 100 | def CASE2( self, main ): |
| 101 | """ |
| 102 | - Set up cell |
| 103 | - Create cell file |
| 104 | - Set cell file |
| 105 | - Verify cell file |
| 106 | - Kill ONOS process |
| 107 | - Uninstall ONOS cluster |
| 108 | - Verify ONOS start up |
| 109 | - Install ONOS cluster |
| 110 | - Connect to cli |
| 111 | """ |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 112 | import time |
GlennRC | 5147a42 | 2015-10-06 17:26:17 -0700 | [diff] [blame] | 113 | |
| 114 | main.numCtrls = int( main.maxNodes ) |
| 115 | |
| 116 | main.case( "Starting up " + str( main.numCtrls ) + |
| 117 | " node(s) ONOS cluster" ) |
| 118 | |
| 119 | #kill off all onos processes |
| 120 | main.log.info( "Safety check, killing all ONOS processes" + |
Jon Hall | 70b2ff4 | 2015-11-17 15:49:44 -0800 | [diff] [blame] | 121 | " before initiating environment setup" ) |
GlennRC | 5147a42 | 2015-10-06 17:26:17 -0700 | [diff] [blame] | 122 | |
| 123 | for i in range( main.maxNodes ): |
| 124 | main.ONOSbench.onosDie( main.ONOSip[ i ] ) |
| 125 | |
Jon Hall | 53c5e66 | 2016-04-13 16:06:56 -0700 | [diff] [blame] | 126 | main.log.info( "NODE COUNT = " + str( main.numCtrls ) ) |
GlennRC | 5147a42 | 2015-10-06 17:26:17 -0700 | [diff] [blame] | 127 | |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 128 | tempOnosIp = [ ] |
GlennRC | 5147a42 | 2015-10-06 17:26:17 -0700 | [diff] [blame] | 129 | for i in range( main.numCtrls ): |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 130 | tempOnosIp.append( main.ONOSip[ i ] ) |
GlennRC | 5147a42 | 2015-10-06 17:26:17 -0700 | [diff] [blame] | 131 | |
Jon Hall | 53c5e66 | 2016-04-13 16:06:56 -0700 | [diff] [blame] | 132 | main.ONOSbench.createCellFile( main.ONOSbench.ip_address, |
| 133 | "temp", |
| 134 | main.Mininet1.ip_address, |
| 135 | main.apps, |
| 136 | tempOnosIp ) |
GlennRC | 5147a42 | 2015-10-06 17:26:17 -0700 | [diff] [blame] | 137 | |
| 138 | main.step( "Apply cell to environment" ) |
| 139 | cellResult = main.ONOSbench.setCell( "temp" ) |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 140 | verifyResult = main.ONOSbench.verifyCell( ) |
GlennRC | 5147a42 | 2015-10-06 17:26:17 -0700 | [diff] [blame] | 141 | stepResult = cellResult and verifyResult |
| 142 | utilities.assert_equals( expect=main.TRUE, |
| 143 | actual=stepResult, |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 144 | onpass="Successfully applied cell to " + "environment", |
GlennRC | 5147a42 | 2015-10-06 17:26:17 -0700 | [diff] [blame] | 145 | onfail="Failed to apply cell to environment " ) |
| 146 | |
| 147 | main.step( "Creating ONOS package" ) |
Jon Hall | bd60ea0 | 2016-08-23 10:03:59 -0700 | [diff] [blame] | 148 | packageResult = main.ONOSbench.buckBuild() |
GlennRC | 5147a42 | 2015-10-06 17:26:17 -0700 | [diff] [blame] | 149 | stepResult = packageResult |
| 150 | utilities.assert_equals( expect=main.TRUE, |
| 151 | actual=stepResult, |
| 152 | onpass="Successfully created ONOS package", |
| 153 | onfail="Failed to create ONOS package" ) |
| 154 | |
| 155 | time.sleep( main.startUpSleep ) |
| 156 | main.step( "Uninstalling ONOS package" ) |
| 157 | onosUninstallResult = main.TRUE |
Jeremy | 8616099 | 2016-04-11 10:05:53 -0700 | [diff] [blame] | 158 | for ip in main.ONOSip: |
GlennRC | 5147a42 | 2015-10-06 17:26:17 -0700 | [diff] [blame] | 159 | onosUninstallResult = onosUninstallResult and \ |
Jeremy Songster | e7f3b34 | 2016-08-17 14:56:49 -0700 | [diff] [blame] | 160 | main.ONOSbench.onosUninstall( nodeIp=ip ) |
GlennRC | 5147a42 | 2015-10-06 17:26:17 -0700 | [diff] [blame] | 161 | stepResult = onosUninstallResult |
| 162 | utilities.assert_equals( expect=main.TRUE, |
| 163 | actual=stepResult, |
| 164 | onpass="Successfully uninstalled ONOS package", |
| 165 | onfail="Failed to uninstall ONOS package" ) |
GlennRC | 5147a42 | 2015-10-06 17:26:17 -0700 | [diff] [blame] | 166 | time.sleep( main.startUpSleep ) |
| 167 | main.step( "Installing ONOS package" ) |
| 168 | onosInstallResult = main.TRUE |
| 169 | for i in range( main.numCtrls ): |
| 170 | onosInstallResult = onosInstallResult and \ |
Jeremy Songster | e7f3b34 | 2016-08-17 14:56:49 -0700 | [diff] [blame] | 171 | main.ONOSbench.onosInstall( node=main.ONOSip[ i ] ) |
GlennRC | 5147a42 | 2015-10-06 17:26:17 -0700 | [diff] [blame] | 172 | stepResult = onosInstallResult |
| 173 | utilities.assert_equals( expect=main.TRUE, |
| 174 | actual=stepResult, |
| 175 | onpass="Successfully installed ONOS package", |
| 176 | onfail="Failed to install ONOS package" ) |
| 177 | |
| 178 | time.sleep( main.startUpSleep ) |
| 179 | main.step( "Starting ONOS service" ) |
| 180 | stopResult = main.TRUE |
| 181 | startResult = main.TRUE |
| 182 | onosIsUp = main.TRUE |
| 183 | |
| 184 | for i in range( main.numCtrls ): |
| 185 | onosIsUp = onosIsUp and main.ONOSbench.isup( main.ONOSip[ i ] ) |
| 186 | if onosIsUp == main.TRUE: |
| 187 | main.log.report( "ONOS instance is up and ready" ) |
| 188 | else: |
| 189 | main.log.report( "ONOS instance may not be up, stop and " + |
| 190 | "start ONOS again " ) |
| 191 | for i in range( main.numCtrls ): |
| 192 | stopResult = stopResult and \ |
| 193 | main.ONOSbench.onosStop( main.ONOSip[ i ] ) |
| 194 | for i in range( main.numCtrls ): |
| 195 | startResult = startResult and \ |
| 196 | main.ONOSbench.onosStart( main.ONOSip[ i ] ) |
| 197 | stepResult = onosIsUp and stopResult and startResult |
| 198 | utilities.assert_equals( expect=main.TRUE, |
| 199 | actual=stepResult, |
| 200 | onpass="ONOS service is ready", |
| 201 | onfail="ONOS service did not start properly" ) |
| 202 | |
| 203 | main.step( "Start ONOS cli" ) |
| 204 | cliResult = main.TRUE |
| 205 | for i in range( main.numCtrls ): |
| 206 | cliResult = cliResult and \ |
| 207 | main.CLIs[ i ].startOnosCli( main.ONOSip[ i ] ) |
| 208 | stepResult = cliResult |
| 209 | utilities.assert_equals( expect=main.TRUE, |
| 210 | actual=stepResult, |
| 211 | onpass="Successfully start ONOS cli", |
| 212 | onfail="Failed to start ONOS cli" ) |
| 213 | |
GlennRC | 6844994 | 2015-10-16 16:03:12 -0700 | [diff] [blame] | 214 | def CASE10( self, main ): |
| 215 | ''' |
| 216 | Start Mininet |
| 217 | ''' |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 218 | import json |
| 219 | |
| 220 | main.case( "Setup mininet and compare ONOS topology view to Mininet topology" ) |
| 221 | main.caseExplanation = "Start mininet with custom topology and compare topology " +\ |
| 222 | "elements between Mininet and ONOS" |
| 223 | |
GlennRC | 6844994 | 2015-10-16 16:03:12 -0700 | [diff] [blame] | 224 | main.step( "Setup Mininet Topology" ) |
| 225 | topology = main.Mininet1.home + '/custom/' + main.topology |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 226 | stepResult = main.Mininet1.startNet( topoFile = topology ) |
GlennRC | 6844994 | 2015-10-16 16:03:12 -0700 | [diff] [blame] | 227 | |
| 228 | utilities.assert_equals( expect=main.TRUE, |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 229 | actual=stepResult, |
GlennRC | 6844994 | 2015-10-16 16:03:12 -0700 | [diff] [blame] | 230 | onpass="Successfully loaded topology", |
| 231 | onfail="Failed to load topology" ) |
| 232 | |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 233 | main.step( "Assign switch to controller" ) |
| 234 | stepResult = main.Mininet1.assignSwController( "s1", main.ONOSip[0] ) |
GlennRC | 6844994 | 2015-10-16 16:03:12 -0700 | [diff] [blame] | 235 | |
| 236 | utilities.assert_equals( expect=main.TRUE, |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 237 | actual=stepResult, |
| 238 | onpass="Successfully assigned switch to controller", |
| 239 | onfail="Failed to assign switch to controller" ) |
GlennRC | 6844994 | 2015-10-16 16:03:12 -0700 | [diff] [blame] | 240 | |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 241 | time.sleep( main.startMNSleep ) |
GlennRC | 6844994 | 2015-10-16 16:03:12 -0700 | [diff] [blame] | 242 | |
Jon Hall | 70b2ff4 | 2015-11-17 15:49:44 -0800 | [diff] [blame] | 243 | main.step( "Comparing MN topology to ONOS topology" ) |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 244 | main.log.info( "Gathering topology information" ) |
GlennRC | 1704d07 | 2015-10-07 18:40:45 -0700 | [diff] [blame] | 245 | devices = main.topo.getAllDevices( main ) |
| 246 | hosts = main.topo.getAllHosts( main ) |
| 247 | ports = main.topo.getAllPorts( main ) |
| 248 | links = main.topo.getAllLinks( main ) |
GlennRC | 1704d07 | 2015-10-07 18:40:45 -0700 | [diff] [blame] | 249 | |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 250 | mnSwitches = main.Mininet1.getSwitches( ) |
| 251 | mnLinks = main.Mininet1.getLinks( ) |
| 252 | mnHosts = main.Mininet1.getHosts( ) |
GlennRC | 1704d07 | 2015-10-07 18:40:45 -0700 | [diff] [blame] | 253 | |
GlennRC | 1704d07 | 2015-10-07 18:40:45 -0700 | [diff] [blame] | 254 | for controller in range( main.numCtrls ): |
| 255 | controllerStr = str( controller + 1 ) |
| 256 | if devices[ controller ] and ports[ controller ] and\ |
| 257 | "Error" not in devices[ controller ] and\ |
| 258 | "Error" not in ports[ controller ]: |
| 259 | |
| 260 | currentDevicesResult = main.Mininet1.compareSwitches( |
| 261 | mnSwitches, |
| 262 | json.loads( devices[ controller ] ), |
| 263 | json.loads( ports[ controller ] ) ) |
| 264 | else: |
| 265 | currentDevicesResult = main.FALSE |
| 266 | utilities.assert_equals( expect=main.TRUE, |
| 267 | actual=currentDevicesResult, |
| 268 | onpass="ONOS" + controllerStr + |
GlennRC | 6844994 | 2015-10-16 16:03:12 -0700 | [diff] [blame] | 269 | " Switches view is correct", |
GlennRC | 1704d07 | 2015-10-07 18:40:45 -0700 | [diff] [blame] | 270 | onfail="ONOS" + controllerStr + |
GlennRC | 6844994 | 2015-10-16 16:03:12 -0700 | [diff] [blame] | 271 | " Switches view is incorrect" ) |
GlennRC | 1704d07 | 2015-10-07 18:40:45 -0700 | [diff] [blame] | 272 | if links[ controller ] and "Error" not in links[ controller ]: |
| 273 | currentLinksResult = main.Mininet1.compareLinks( |
| 274 | mnSwitches, mnLinks, |
| 275 | json.loads( links[ controller ] ) ) |
| 276 | else: |
| 277 | currentLinksResult = main.FALSE |
| 278 | utilities.assert_equals( expect=main.TRUE, |
| 279 | actual=currentLinksResult, |
| 280 | onpass="ONOS" + controllerStr + |
GlennRC | 6844994 | 2015-10-16 16:03:12 -0700 | [diff] [blame] | 281 | " links view is correct", |
GlennRC | 1704d07 | 2015-10-07 18:40:45 -0700 | [diff] [blame] | 282 | onfail="ONOS" + controllerStr + |
GlennRC | 6844994 | 2015-10-16 16:03:12 -0700 | [diff] [blame] | 283 | " links view is incorrect" ) |
GlennRC | 1704d07 | 2015-10-07 18:40:45 -0700 | [diff] [blame] | 284 | |
| 285 | if hosts[ controller ] or "Error" not in hosts[ controller ]: |
| 286 | currentHostsResult = main.Mininet1.compareHosts( |
| 287 | mnHosts, |
| 288 | json.loads( hosts[ controller ] ) ) |
| 289 | else: |
| 290 | currentHostsResult = main.FALSE |
| 291 | utilities.assert_equals( expect=main.TRUE, |
| 292 | actual=currentHostsResult, |
| 293 | onpass="ONOS" + controllerStr + |
GlennRC | 6844994 | 2015-10-16 16:03:12 -0700 | [diff] [blame] | 294 | " hosts exist in Mininet", |
GlennRC | 1704d07 | 2015-10-07 18:40:45 -0700 | [diff] [blame] | 295 | onfail="ONOS" + controllerStr + |
GlennRC | 6844994 | 2015-10-16 16:03:12 -0700 | [diff] [blame] | 296 | " hosts don't match Mininet") |
GlennRC | a539137 | 2015-10-14 17:28:15 -0700 | [diff] [blame] | 297 | |
GlennRC | 6844994 | 2015-10-16 16:03:12 -0700 | [diff] [blame] | 298 | |
Jon Hall | 892818c | 2015-10-20 17:58:34 -0700 | [diff] [blame] | 299 | def CASE66( self, main ): |
| 300 | ''' |
| 301 | Testing scapy |
| 302 | ''' |
| 303 | main.case( "Testing scapy" ) |
| 304 | main.step( "Creating Host1 component" ) |
Jon Hall | a510a8a | 2016-05-04 15:09:28 -0700 | [diff] [blame] | 305 | main.Scapy.createHostComponent( "h1" ) |
| 306 | main.Scapy.createHostComponent( "h2" ) |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 307 | hosts = [ main.h1, main.h2 ] |
Jon Hall | 892818c | 2015-10-20 17:58:34 -0700 | [diff] [blame] | 308 | for host in hosts: |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 309 | host.startHostCli( ) |
| 310 | host.startScapy( ) |
| 311 | host.updateSelf( ) |
Jon Hall | 892818c | 2015-10-20 17:58:34 -0700 | [diff] [blame] | 312 | main.log.debug( host.name ) |
| 313 | main.log.debug( host.hostIp ) |
| 314 | main.log.debug( host.hostMac ) |
| 315 | |
| 316 | main.step( "Sending/Receiving Test packet - Filter doesn't match" ) |
Jon Hall | a510a8a | 2016-05-04 15:09:28 -0700 | [diff] [blame] | 317 | main.log.info( "Starting Filter..." ) |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 318 | main.h2.startFilter( ) |
Jon Hall | a510a8a | 2016-05-04 15:09:28 -0700 | [diff] [blame] | 319 | main.log.info( "Building Ether frame..." ) |
Jon Hall | 892818c | 2015-10-20 17:58:34 -0700 | [diff] [blame] | 320 | main.h1.buildEther( dst=main.h2.hostMac ) |
Jon Hall | a510a8a | 2016-05-04 15:09:28 -0700 | [diff] [blame] | 321 | main.log.info( "Sending Packet..." ) |
Jon Hall | 892818c | 2015-10-20 17:58:34 -0700 | [diff] [blame] | 322 | main.h1.sendPacket( ) |
Jon Hall | a510a8a | 2016-05-04 15:09:28 -0700 | [diff] [blame] | 323 | main.log.info( "Checking Filter..." ) |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 324 | finished = main.h2.checkFilter( ) |
Jon Hall | a510a8a | 2016-05-04 15:09:28 -0700 | [diff] [blame] | 325 | main.log.debug( finished ) |
Jon Hall | 892818c | 2015-10-20 17:58:34 -0700 | [diff] [blame] | 326 | i = "" |
| 327 | if finished: |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 328 | a = main.h2.readPackets( ) |
| 329 | for i in a.splitlines( ): |
Jon Hall | 892818c | 2015-10-20 17:58:34 -0700 | [diff] [blame] | 330 | main.log.info( i ) |
| 331 | else: |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 332 | kill = main.h2.killFilter( ) |
Jon Hall | 892818c | 2015-10-20 17:58:34 -0700 | [diff] [blame] | 333 | main.log.debug( kill ) |
| 334 | main.h2.handle.sendline( "" ) |
| 335 | main.h2.handle.expect( main.h2.scapyPrompt ) |
| 336 | main.log.debug( main.h2.handle.before ) |
| 337 | utilities.assert_equals( expect=True, |
| 338 | actual="dst=00:00:00:00:00:02 src=00:00:00:00:00:01" in i, |
| 339 | onpass="Pass", |
| 340 | onfail="Fail" ) |
| 341 | |
| 342 | main.step( "Sending/Receiving Test packet - Filter matches" ) |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 343 | main.h2.startFilter( ) |
Jon Hall | 892818c | 2015-10-20 17:58:34 -0700 | [diff] [blame] | 344 | main.h1.buildEther( dst=main.h2.hostMac ) |
| 345 | main.h1.buildIP( dst=main.h2.hostIp ) |
| 346 | main.h1.sendPacket( ) |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 347 | finished = main.h2.checkFilter( ) |
Jon Hall | 892818c | 2015-10-20 17:58:34 -0700 | [diff] [blame] | 348 | i = "" |
| 349 | if finished: |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 350 | a = main.h2.readPackets( ) |
| 351 | for i in a.splitlines( ): |
Jon Hall | 892818c | 2015-10-20 17:58:34 -0700 | [diff] [blame] | 352 | main.log.info( i ) |
| 353 | else: |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 354 | kill = main.h2.killFilter( ) |
Jon Hall | 892818c | 2015-10-20 17:58:34 -0700 | [diff] [blame] | 355 | main.log.debug( kill ) |
| 356 | main.h2.handle.sendline( "" ) |
| 357 | main.h2.handle.expect( main.h2.scapyPrompt ) |
| 358 | main.log.debug( main.h2.handle.before ) |
| 359 | utilities.assert_equals( expect=True, |
| 360 | actual="dst=00:00:00:00:00:02 src=00:00:00:00:00:01" in i, |
| 361 | onpass="Pass", |
| 362 | onfail="Fail" ) |
| 363 | |
| 364 | |
| 365 | |
| 366 | main.step( "Clean up host components" ) |
| 367 | for host in hosts: |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 368 | host.stopScapy( ) |
| 369 | main.Mininet1.removeHostComponent( "h1" ) |
| 370 | main.Mininet1.removeHostComponent( "h2" ) |
Jon Hall | 892818c | 2015-10-20 17:58:34 -0700 | [diff] [blame] | 371 | |
GlennRC | 6844994 | 2015-10-16 16:03:12 -0700 | [diff] [blame] | 372 | def CASE1000( self, main ): |
| 373 | ''' |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 374 | Add flows with MAC selectors and verify the flows |
GlennRC | 6844994 | 2015-10-16 16:03:12 -0700 | [diff] [blame] | 375 | ''' |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 376 | import json |
| 377 | import time |
GlennRC | 6844994 | 2015-10-16 16:03:12 -0700 | [diff] [blame] | 378 | |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 379 | main.case( "Verify flow MAC selectors are correctly compiled" ) |
| 380 | main.caseExplanation = "Install two flows with only MAC selectors " +\ |
| 381 | "specified, then verify flows are added in ONOS, finally "+\ |
| 382 | "send a packet that only specifies the MAC src and dst." |
GlennRC | 6844994 | 2015-10-16 16:03:12 -0700 | [diff] [blame] | 383 | |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 384 | main.step( "Add flows with MAC addresses as the only selectors" ) |
GlennRC | 6844994 | 2015-10-16 16:03:12 -0700 | [diff] [blame] | 385 | |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 386 | main.log.info( "Creating host components" ) |
Jon Hall | a510a8a | 2016-05-04 15:09:28 -0700 | [diff] [blame] | 387 | main.Scapy.createHostComponent( "h1" ) |
| 388 | main.Scapy.createHostComponent( "h2" ) |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 389 | hosts = [ main.h1, main.h2 ] |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 390 | for host in hosts: |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 391 | host.startHostCli( ) |
| 392 | host.startScapy( ) |
| 393 | host.updateSelf( ) |
GlennRC | 6844994 | 2015-10-16 16:03:12 -0700 | [diff] [blame] | 394 | |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 395 | # Add a flow that connects host1 on port1 to host2 on port2 |
| 396 | # send output on port2 |
| 397 | # recieve input on port1 |
| 398 | egress = 2 |
| 399 | ingress = 1 |
| 400 | |
| 401 | # Add flows that sends packets from port1 to port2 with correct |
| 402 | # MAC src and dst addresses |
| 403 | main.log.info( "Adding flow with MAC selectors" ) |
| 404 | stepResult = main.ONOSrest.addFlow( deviceId=main.swDPID, |
| 405 | egressPort=egress, |
| 406 | ingressPort=ingress, |
| 407 | ethSrc=main.h1.hostMac, |
| 408 | ethDst=main.h2.hostMac, |
GlennRC | 956ea74 | 2015-11-05 16:14:15 -0800 | [diff] [blame] | 409 | debug=main.debug ) |
GlennRC | 6844994 | 2015-10-16 16:03:12 -0700 | [diff] [blame] | 410 | |
GlennRC | a539137 | 2015-10-14 17:28:15 -0700 | [diff] [blame] | 411 | utilities.assert_equals( expect=main.TRUE, |
| 412 | actual=stepResult, |
GlennRC | 6844994 | 2015-10-16 16:03:12 -0700 | [diff] [blame] | 413 | onpass="Successfully added flows", |
| 414 | onfail="Failed add flows" ) |
GlennRC | a539137 | 2015-10-14 17:28:15 -0700 | [diff] [blame] | 415 | |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 416 | # Giving ONOS time to add the flows |
| 417 | time.sleep( main.addFlowSleep ) |
GlennRC | 5147a42 | 2015-10-06 17:26:17 -0700 | [diff] [blame] | 418 | |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 419 | main.step( "Check flows are in the ADDED state" ) |
| 420 | |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 421 | main.log.info( "Get the flows from ONOS" ) |
Jeremy | 8616099 | 2016-04-11 10:05:53 -0700 | [diff] [blame] | 422 | try: |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 423 | flows = json.loads( main.ONOSrest.flows( ) ) |
GlennRC | 6844994 | 2015-10-16 16:03:12 -0700 | [diff] [blame] | 424 | |
Jeremy | 8616099 | 2016-04-11 10:05:53 -0700 | [diff] [blame] | 425 | stepResult = main.TRUE |
| 426 | for f in flows: |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 427 | if "rest" in f.get( "appId" ): |
| 428 | if "ADDED" not in f.get( "state" ): |
Jeremy | 8616099 | 2016-04-11 10:05:53 -0700 | [diff] [blame] | 429 | stepResult = main.FALSE |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 430 | main.log.error( "Flow: %s in state: %s" % ( f.get( "id" ), f.get( "state" ) ) ) |
Jeremy | 8616099 | 2016-04-11 10:05:53 -0700 | [diff] [blame] | 431 | except TypeError: |
| 432 | main.log.error( "No Flows found by the REST API" ) |
| 433 | stepResult = main.FALSE |
| 434 | except ValueError: |
| 435 | main.log.error( "Problem getting Flows state from REST API. Exiting test" ) |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 436 | main.cleanup( ) |
| 437 | main.exit( ) |
GlennRC | 6844994 | 2015-10-16 16:03:12 -0700 | [diff] [blame] | 438 | |
| 439 | utilities.assert_equals( expect=main.TRUE, |
| 440 | actual=stepResult, |
| 441 | onpass="All flows are in the ADDED state", |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 442 | onfail="All flows are NOT in the ADDED state" ) |
GlennRC | 6844994 | 2015-10-16 16:03:12 -0700 | [diff] [blame] | 443 | |
GlennRC | 956ea74 | 2015-11-05 16:14:15 -0800 | [diff] [blame] | 444 | main.step( "Check flows are in Mininet's flow table" ) |
| 445 | |
| 446 | # get the flow IDs that were added through rest |
| 447 | main.log.info( "Getting the flow IDs from ONOS" ) |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 448 | flowIds = [ f.get( "id" ) for f in flows if "rest" in f.get( "appId" ) ] |
GlennRC | 956ea74 | 2015-11-05 16:14:15 -0800 | [diff] [blame] | 449 | # convert the flowIDs to ints then hex and finally back to strings |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 450 | flowIds = [ str( hex( int( x ) ) ) for x in flowIds ] |
| 451 | main.log.info( "ONOS flow IDs: {}".format( flowIds ) ) |
GlennRC | 956ea74 | 2015-11-05 16:14:15 -0800 | [diff] [blame] | 452 | |
| 453 | stepResult = main.Mininet1.checkFlowId( "s1", flowIds, debug=False ) |
| 454 | |
| 455 | utilities.assert_equals( expect=main.TRUE, |
| 456 | actual=stepResult, |
| 457 | onpass="All flows are in mininet", |
| 458 | onfail="All flows are NOT in mininet" ) |
| 459 | |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 460 | main.step( "Send a packet to verify the flows are correct" ) |
| 461 | |
| 462 | # Specify the src and dst MAC addr |
| 463 | main.log.info( "Constructing packet" ) |
| 464 | main.h1.buildEther( src=main.h1.hostMac, dst=main.h2.hostMac ) |
| 465 | |
| 466 | # Filter for packets with the correct host name. Otherwise, |
| 467 | # the filter we catch any packet that is sent to host2 |
| 468 | # NOTE: I believe it doesn't matter which host name it is, |
GlennRC | 956ea74 | 2015-11-05 16:14:15 -0800 | [diff] [blame] | 469 | # as long as the src and dst are both specified |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 470 | main.log.info( "Starting filter on host2" ) |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 471 | main.h2.startFilter( pktFilter="ether host %s" % main.h1.hostMac ) |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 472 | |
| 473 | main.log.info( "Sending packet to host2" ) |
| 474 | main.h1.sendPacket() |
| 475 | |
| 476 | main.log.info( "Checking filter for our packet" ) |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 477 | stepResult = main.h2.checkFilter( ) |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 478 | if stepResult: |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 479 | main.log.info( "Packet: %s" % main.h2.readPackets( ) ) |
| 480 | else: |
| 481 | main.h2.killFilter( ) |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 482 | |
| 483 | main.log.info( "Clean up host components" ) |
| 484 | for host in hosts: |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 485 | host.stopScapy( ) |
| 486 | main.Mininet1.removeHostComponent( "h1" ) |
| 487 | main.Mininet1.removeHostComponent( "h2" ) |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 488 | |
| 489 | utilities.assert_equals( expect=main.TRUE, |
| 490 | actual=stepResult, |
| 491 | onpass="Successfully sent a packet", |
| 492 | onfail="Failed to send a packet" ) |
| 493 | |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 494 | def CASE1400( self, main ): |
GlennRC | 6844994 | 2015-10-16 16:03:12 -0700 | [diff] [blame] | 495 | ''' |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 496 | Add flows with IPv4 selectors and verify the flows |
GlennRC | 6844994 | 2015-10-16 16:03:12 -0700 | [diff] [blame] | 497 | ''' |
| 498 | import json |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 499 | import time |
GlennRC | 6844994 | 2015-10-16 16:03:12 -0700 | [diff] [blame] | 500 | |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 501 | main.case( "Verify flow IP selectors are correctly compiled" ) |
| 502 | main.caseExplanation = "Install two flows with only IP selectors " +\ |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 503 | "specified, then verify flows are added in ONOS, finally " +\ |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 504 | "send a packet that only specifies the IP src and dst." |
| 505 | |
| 506 | main.step( "Add flows with IPv4 addresses as the only selectors" ) |
| 507 | |
| 508 | main.log.info( "Creating host components" ) |
Jon Hall | a510a8a | 2016-05-04 15:09:28 -0700 | [diff] [blame] | 509 | main.Scapy.createHostComponent( "h1" ) |
| 510 | main.Scapy.createHostComponent( "h2" ) |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 511 | hosts = [ main.h1, main.h2 ] |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 512 | for host in hosts: |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 513 | host.startHostCli( ) |
| 514 | host.startScapy( ) |
| 515 | host.updateSelf( ) |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 516 | |
| 517 | # Add a flow that connects host1 on port1 to host2 on port2 |
| 518 | # send output on port2 |
| 519 | # recieve input on port1 |
| 520 | egress = 2 |
| 521 | ingress = 1 |
| 522 | # IPv4 etherType = 0x800 |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 523 | ethType = main.params[ 'TEST' ][ 'ip4Type' ] |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 524 | |
| 525 | # Add flows that connects host1 to host2 |
| 526 | main.log.info( "Add flow with port ingress 1 to port egress 2" ) |
| 527 | stepResult = main.ONOSrest.addFlow( deviceId=main.swDPID, |
| 528 | egressPort=egress, |
| 529 | ingressPort=ingress, |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 530 | ethType=ethType, |
| 531 | ipSrc=( "IPV4_SRC", main.h1.hostIp+"/32" ), |
| 532 | ipDst=( "IPV4_DST", main.h2.hostIp+"/32" ), |
GlennRC | 956ea74 | 2015-11-05 16:14:15 -0800 | [diff] [blame] | 533 | debug=main.debug ) |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 534 | |
| 535 | utilities.assert_equals( expect=main.TRUE, |
| 536 | actual=stepResult, |
| 537 | onpass="Successfully added flows", |
| 538 | onfail="Failed add flows" ) |
| 539 | |
| 540 | # Giving ONOS time to add the flow |
| 541 | time.sleep( main.addFlowSleep ) |
| 542 | |
| 543 | main.step( "Check flow is in the ADDED state" ) |
| 544 | |
| 545 | main.log.info( "Get the flows from ONOS" ) |
Jeremy | 8616099 | 2016-04-11 10:05:53 -0700 | [diff] [blame] | 546 | try: |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 547 | flows = json.loads( main.ONOSrest.flows( ) ) |
GlennRC | 6844994 | 2015-10-16 16:03:12 -0700 | [diff] [blame] | 548 | |
Jeremy | 8616099 | 2016-04-11 10:05:53 -0700 | [diff] [blame] | 549 | stepResult = main.TRUE |
| 550 | for f in flows: |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 551 | if "rest" in f.get( "appId" ): |
| 552 | if "ADDED" not in f.get( "state" ): |
Jeremy | 8616099 | 2016-04-11 10:05:53 -0700 | [diff] [blame] | 553 | stepResult = main.FALSE |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 554 | main.log.error( "Flow: %s in state: %s" % ( f.get( "id" ), f.get( "state" ) ) ) |
Jeremy | 8616099 | 2016-04-11 10:05:53 -0700 | [diff] [blame] | 555 | except TypeError: |
| 556 | main.log.error( "No Flows found by the REST API" ) |
| 557 | stepResult = main.FALSE |
| 558 | except ValueError: |
| 559 | main.log.error( "Problem getting Flows state from REST API. Exiting test" ) |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 560 | main.cleanup( ) |
| 561 | main.exit( ) |
GlennRC | 6844994 | 2015-10-16 16:03:12 -0700 | [diff] [blame] | 562 | |
| 563 | utilities.assert_equals( expect=main.TRUE, |
| 564 | actual=stepResult, |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 565 | onpass="All flows are in the ADDED state", |
| 566 | onfail="All flows are NOT in the ADDED state" ) |
| 567 | |
GlennRC | 956ea74 | 2015-11-05 16:14:15 -0800 | [diff] [blame] | 568 | main.step( "Check flows are in Mininet's flow table" ) |
| 569 | |
| 570 | # get the flow IDs that were added through rest |
| 571 | main.log.info( "Getting the flow IDs from ONOS" ) |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 572 | flowIds = [ f.get( "id" ) for f in flows if "rest" in f.get( "appId" ) ] |
GlennRC | 956ea74 | 2015-11-05 16:14:15 -0800 | [diff] [blame] | 573 | # convert the flowIDs to ints then hex and finally back to strings |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 574 | flowIds = [ str( hex( int( x ) ) ) for x in flowIds ] |
| 575 | main.log.info( "ONOS flow IDs: {}".format( flowIds ) ) |
GlennRC | 956ea74 | 2015-11-05 16:14:15 -0800 | [diff] [blame] | 576 | |
| 577 | stepResult = main.Mininet1.checkFlowId( "s1", flowIds, debug=False ) |
| 578 | |
| 579 | utilities.assert_equals( expect=main.TRUE, |
| 580 | actual=stepResult, |
| 581 | onpass="All flows are in mininet", |
| 582 | onfail="All flows are NOT in mininet" ) |
| 583 | |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 584 | main.step( "Send a packet to verify the flow is correct" ) |
| 585 | |
| 586 | main.log.info( "Constructing packet" ) |
| 587 | # No need for the MAC src dst |
| 588 | main.h1.buildEther( dst=main.h2.hostMac ) |
| 589 | main.h1.buildIP( src=main.h1.hostIp, dst=main.h2.hostIp ) |
| 590 | |
| 591 | main.log.info( "Starting filter on host2" ) |
| 592 | # Defaults to ip |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 593 | main.h2.startFilter( ) |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 594 | |
| 595 | main.log.info( "Sending packet to host2" ) |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 596 | main.h1.sendPacket( ) |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 597 | |
| 598 | main.log.info( "Checking filter for our packet" ) |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 599 | stepResult = main.h2.checkFilter( ) |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 600 | if stepResult: |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 601 | main.log.info( "Packet: %s" % main.h2.readPackets( ) ) |
| 602 | else: main.h2.killFilter( ) |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 603 | |
| 604 | main.log.info( "Clean up host components" ) |
| 605 | for host in hosts: |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 606 | host.stopScapy( ) |
| 607 | main.Mininet1.removeHostComponent( "h1" ) |
| 608 | main.Mininet1.removeHostComponent( "h2" ) |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 609 | |
| 610 | utilities.assert_equals( expect=main.TRUE, |
| 611 | actual=stepResult, |
| 612 | onpass="Successfully sent a packet", |
| 613 | onfail="Failed to send a packet" ) |
| 614 | |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 615 | def CASE1500 (self, main ): |
| 616 | """ |
| 617 | Add flow with IPv6 selector and verify the flow |
| 618 | """ |
| 619 | import json |
| 620 | import time |
| 621 | main.case( "Verify IPv6 selector is correctly compiled" ) |
| 622 | main.caseExplanation = "Install two flows with only IP selectors " + \ |
| 623 | "specified, then verify flows are added in ONOS, finally " + \ |
| 624 | "send a packet that only specifies the IP src and dst." |
| 625 | |
| 626 | main.step( "Add flows with IPv6 addresses as the only selectors" ) |
| 627 | |
| 628 | main.log.info( "Creating host components" ) |
| 629 | main.Scapy.createHostComponent( "h5" ) |
| 630 | main.Scapy.createHostComponent( "h6" ) |
| 631 | hosts = [ main.h5, main.h6 ] |
| 632 | |
| 633 | for host in hosts: |
| 634 | host.startHostCli( ) |
| 635 | host.startScapy( ) |
| 636 | host.updateSelf( IPv6=True ) |
| 637 | |
| 638 | # Add a flow that connects host1 on port1 to host2 on port2 |
| 639 | # send output on port2 |
| 640 | # recieve input on port1 |
| 641 | egress = 6 |
| 642 | ingress = 5 |
| 643 | # IPv6 etherType = 0x86DD |
| 644 | ethType = main.params[ 'TEST' ][ 'ip6Type' ] |
| 645 | |
| 646 | # Add flows that connects host1 to host2 |
| 647 | main.log.info( "Add flow with port ingress 5 to port egress 6" ) |
| 648 | stepResult = main.ONOSrest.addFlow( deviceId=main.swDPID, |
| 649 | egressPort=egress, |
| 650 | ingressPort=ingress, |
| 651 | ethType=ethType, |
| 652 | ipSrc=( "IPV6_SRC", main.h5.hostIp + "/128" ), |
| 653 | ipDst=( "IPV6_DST", main.h6.hostIp + "/128" ), |
| 654 | debug=main.debug ) |
| 655 | |
| 656 | utilities.assert_equals( expect=main.TRUE, |
| 657 | actual=stepResult, |
| 658 | onpass="Successfully added flows", |
| 659 | onfail="Failed add flows" ) |
| 660 | |
| 661 | # Giving ONOS time to add the flow |
| 662 | time.sleep( main.addFlowSleep ) |
| 663 | |
| 664 | main.step( "Check flow is in the ADDED state" ) |
| 665 | |
| 666 | main.log.info( "Get the flows from ONOS" ) |
| 667 | try: |
| 668 | flows = json.loads( main.ONOSrest.flows( ) ) |
| 669 | |
| 670 | stepResult = main.TRUE |
| 671 | for f in flows: |
| 672 | if "rest" in f.get( "appId" ): |
| 673 | if "ADDED" not in f.get( "state" ): |
| 674 | stepResult = main.FALSE |
| 675 | main.log.error( "Flow: %s in state: %s" % ( f.get( "id" ), f.get( "state" ) ) ) |
| 676 | except TypeError: |
| 677 | main.log.error( "No Flows found by the REST API" ) |
| 678 | stepResult = main.FALSE |
| 679 | except ValueError: |
| 680 | main.log.error( "Problem getting Flows state from REST API. Exiting test" ) |
| 681 | main.cleanup( ) |
| 682 | main.exit( ) |
| 683 | |
| 684 | utilities.assert_equals( expect=main.TRUE, |
| 685 | actual=stepResult, |
| 686 | onpass="All flows are in the ADDED state", |
| 687 | onfail="All flows are NOT in the ADDED state" ) |
| 688 | |
| 689 | main.step( "Check flows are in Mininet's flow table" ) |
| 690 | |
| 691 | # get the flow IDs that were added through rest |
| 692 | main.log.info( "Getting the flow IDs from ONOS" ) |
| 693 | flowIds = [ f.get( "id" ) for f in flows if "rest" in f.get( "appId" ) ] |
| 694 | # convert the flowIDs to ints then hex and finally back to strings |
| 695 | flowIds = [ str( hex( int( x ) ) ) for x in flowIds ] |
| 696 | main.log.info( "ONOS flow IDs: {}".format( flowIds ) ) |
| 697 | |
| 698 | stepResult = main.Mininet1.checkFlowId( "s1", flowIds, debug=False ) |
| 699 | |
| 700 | utilities.assert_equals( expect=main.TRUE, |
| 701 | actual=stepResult, |
| 702 | onpass="All flows are in mininet", |
| 703 | onfail="All flows are NOT in mininet" ) |
| 704 | |
| 705 | main.step( "Send a packet to verify the flow is correct" ) |
| 706 | |
| 707 | main.log.info( "Constructing packet" ) |
| 708 | # No need for the MAC src dst |
| 709 | main.h5.buildEther( dst=main.h6.hostMac ) |
| 710 | main.h5.buildIPv6( src=main.h5.hostIp, dst=main.h6.hostIp ) |
| 711 | |
| 712 | main.log.info( "Starting filter on host6" ) |
| 713 | # Defaults to ip |
| 714 | main.h6.startFilter( pktFilter="ip6" ) |
| 715 | main.log.info( "Sending packet to host6" ) |
| 716 | main.h5.sendPacket( ) |
| 717 | |
| 718 | main.log.info( "Checking filter for our packet" ) |
| 719 | stepResult = main.h6.checkFilter( ) |
| 720 | if stepResult: |
| 721 | main.log.info( "Packet: %s" % main.h6.readPackets( ) ) |
| 722 | else: |
| 723 | main.h6.killFilter( ) |
| 724 | |
| 725 | main.log.info( "Clean up host components" ) |
| 726 | for host in hosts: |
| 727 | host.stopScapy( ) |
| 728 | main.Mininet1.removeHostComponent( "h5" ) |
| 729 | main.Mininet1.removeHostComponent( "h6" ) |
| 730 | |
| 731 | utilities.assert_equals( expect=main.TRUE, |
| 732 | actual=stepResult, |
| 733 | onpass="Successfully sent a packet", |
| 734 | onfail="Failed to send a packet" ) |
| 735 | |
| 736 | |
| 737 | def CASE1100( self, main ): |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 738 | ''' |
| 739 | Add flow with VLAN selector and verify the flow |
| 740 | ''' |
| 741 | import json |
| 742 | import time |
| 743 | |
| 744 | main.case( "Verify VLAN selector is correctly compiled" ) |
| 745 | main.caseExplanation = "Install one flow with only the VLAN selector " +\ |
| 746 | "specified, then verify the flow is added in ONOS, and finally "+\ |
| 747 | "broadcast a packet with the correct VLAN tag." |
| 748 | |
| 749 | # We do this here to utilize the hosts information |
| 750 | main.log.info( "Creating host components" ) |
Jon Hall | a510a8a | 2016-05-04 15:09:28 -0700 | [diff] [blame] | 751 | main.Scapy.createHostComponent( "h3" ) |
| 752 | main.Scapy.createHostComponent( "h4" ) |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 753 | hosts = [ main.h3, main.h4 ] |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 754 | for host in hosts: |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 755 | host.startHostCli( ) |
| 756 | host.startScapy( ) |
| 757 | host.updateSelf( ) |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 758 | |
| 759 | |
| 760 | main.step( "Add a flow with the VLAN tag as the only selector" ) |
| 761 | |
| 762 | # Add flows that connects the two vlan hosts h3 and h4 |
| 763 | # Host 3 is on port 3 and host 4 is on port 4 |
| 764 | vlan = main.params[ 'TEST' ][ 'vlan' ] |
| 765 | egress = 4 |
| 766 | ingress = 3 |
| 767 | # VLAN ethType = 0x8100 |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 768 | ethType = main.params[ 'TEST' ][ 'vlanType' ] |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 769 | |
| 770 | # Add only one flow because we don't need a response |
| 771 | main.log.info( "Add flow with port ingress 1 to port egress 2" ) |
| 772 | stepResult = main.ONOSrest.addFlow( deviceId=main.swDPID, |
| 773 | egressPort=egress, |
| 774 | ingressPort=ingress, |
| 775 | ethType=ethType, |
| 776 | vlan=vlan, |
GlennRC | 956ea74 | 2015-11-05 16:14:15 -0800 | [diff] [blame] | 777 | debug=main.debug ) |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 778 | |
| 779 | |
| 780 | utilities.assert_equals( expect=main.TRUE, |
| 781 | actual=stepResult, |
| 782 | onpass="Successfully added flow", |
| 783 | onfail="Failed add flows" ) |
| 784 | |
| 785 | # Giving ONOS time to add the flows |
| 786 | time.sleep( main.addFlowSleep ) |
| 787 | |
| 788 | main.step( "Check flows are in the ADDED state" ) |
| 789 | |
| 790 | main.log.info( "Get the flows from ONOS" ) |
Jeremy | 8616099 | 2016-04-11 10:05:53 -0700 | [diff] [blame] | 791 | try: |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 792 | flows = json.loads( main.ONOSrest.flows( ) ) |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 793 | |
Jeremy | 8616099 | 2016-04-11 10:05:53 -0700 | [diff] [blame] | 794 | stepResult = main.TRUE |
| 795 | for f in flows: |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 796 | if "rest" in f.get( "appId" ): |
| 797 | if "ADDED" not in f.get( "state" ): |
Jeremy | 8616099 | 2016-04-11 10:05:53 -0700 | [diff] [blame] | 798 | stepResult = main.FALSE |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 799 | main.log.error( "Flow: %s in state: %s" % ( f.get( "id" ), f.get( "state" ) ) ) |
Jeremy | 8616099 | 2016-04-11 10:05:53 -0700 | [diff] [blame] | 800 | except TypeError: |
| 801 | main.log.error( "No Flows found by the REST API" ) |
| 802 | stepResult = main.FALSE |
| 803 | except ValueError: |
| 804 | main.log.error( "Problem getting Flows state from REST API. Exiting test" ) |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 805 | main.cleanup( ) |
| 806 | main.exit( ) |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 807 | |
| 808 | utilities.assert_equals( expect=main.TRUE, |
| 809 | actual=stepResult, |
| 810 | onpass="All flows are in the ADDED state", |
| 811 | onfail="All flows are NOT in the ADDED state" ) |
| 812 | |
GlennRC | 956ea74 | 2015-11-05 16:14:15 -0800 | [diff] [blame] | 813 | main.step( "Check flows are in Mininet's flow table" ) |
| 814 | |
| 815 | # get the flow IDs that were added through rest |
| 816 | main.log.info( "Getting the flow IDs from ONOS" ) |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 817 | flowIds = [ f.get( "id" ) for f in flows if "rest" in f.get( "appId" ) ] |
GlennRC | 956ea74 | 2015-11-05 16:14:15 -0800 | [diff] [blame] | 818 | # convert the flowIDs to ints then hex and finally back to strings |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 819 | flowIds = [ str( hex( int( x ) ) ) for x in flowIds ] |
| 820 | main.log.info( "ONOS flow IDs: {}".format( flowIds ) ) |
GlennRC | 956ea74 | 2015-11-05 16:14:15 -0800 | [diff] [blame] | 821 | |
| 822 | stepResult = main.Mininet1.checkFlowId( "s1", flowIds, debug=False ) |
| 823 | |
| 824 | utilities.assert_equals( expect=main.TRUE, |
| 825 | actual=stepResult, |
| 826 | onpass="All flows are in mininet", |
| 827 | onfail="All flows are NOT in mininet" ) |
| 828 | |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 829 | main.step( "Send a packet to verify the flow are correct" ) |
| 830 | |
| 831 | # The receiving interface |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 832 | recIface = "{}-eth0.{}".format( main.h4.name, vlan ) |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 833 | main.log.info( "Starting filter on host2" ) |
| 834 | # Filter is setup to catch any packet on the vlan interface with the correct vlan tag |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 835 | main.h4.startFilter( ifaceName=recIface, pktFilter = "" ) |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 836 | |
| 837 | # Broadcast the packet on the vlan interface. We only care if the flow forwards |
| 838 | # the packet with the correct vlan tag, not if the mac addr is correct |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 839 | sendIface = "{}-eth0.{}".format( main.h3.name, vlan ) |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 840 | main.log.info( "Broadcasting the packet with a vlan tag" ) |
GlennRC | 956ea74 | 2015-11-05 16:14:15 -0800 | [diff] [blame] | 841 | main.h3.sendPacket( iface=sendIface, |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 842 | packet="Ether()/Dot1Q(vlan={})".format( vlan ) ) |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 843 | |
| 844 | main.log.info( "Checking filter for our packet" ) |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 845 | stepResult = main.h4.checkFilter( ) |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 846 | if stepResult: |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 847 | main.log.info( "Packet: %s" % main.h4.readPackets( ) ) |
| 848 | else: main.h4.killFilter( ) |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 849 | |
| 850 | main.log.info( "Clean up host components" ) |
| 851 | for host in hosts: |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 852 | host.stopScapy( ) |
| 853 | main.Mininet1.removeHostComponent( "h3" ) |
| 854 | main.Mininet1.removeHostComponent( "h4" ) |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 855 | |
| 856 | utilities.assert_equals( expect=main.TRUE, |
| 857 | actual=stepResult, |
| 858 | onpass="Successfully sent a packet", |
| 859 | onfail="Failed to send a packet" ) |
GlennRC | 6844994 | 2015-10-16 16:03:12 -0700 | [diff] [blame] | 860 | |
GlennRC | 956ea74 | 2015-11-05 16:14:15 -0800 | [diff] [blame] | 861 | def CASE1300( self, main ): |
| 862 | ''' |
| 863 | Add flows with MPLS selector and verify the flows |
| 864 | ''' |
| 865 | import json |
| 866 | import time |
| 867 | |
| 868 | main.case( "Verify the MPLS selector is correctly compiled on the flow." ) |
| 869 | main.caseExplanation = "Install one flow with an MPLS selector, " +\ |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 870 | "verify the flow is added in ONOS, and finally " +\ |
GlennRC | 956ea74 | 2015-11-05 16:14:15 -0800 | [diff] [blame] | 871 | "send a packet via scapy that has a MPLS label." |
| 872 | |
| 873 | main.step( "Add a flow with a MPLS selector" ) |
| 874 | |
| 875 | main.log.info( "Creating host components" ) |
Jon Hall | a510a8a | 2016-05-04 15:09:28 -0700 | [diff] [blame] | 876 | main.Scapy.createHostComponent( "h1" ) |
| 877 | main.Scapy.createHostComponent( "h2" ) |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 878 | hosts = [ main.h1, main.h2 ] |
GlennRC | 956ea74 | 2015-11-05 16:14:15 -0800 | [diff] [blame] | 879 | for host in hosts: |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 880 | host.startHostCli( ) |
GlennRC | 956ea74 | 2015-11-05 16:14:15 -0800 | [diff] [blame] | 881 | host.startScapy( main.dependencyPath ) |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 882 | host.updateSelf( ) |
GlennRC | 956ea74 | 2015-11-05 16:14:15 -0800 | [diff] [blame] | 883 | |
| 884 | # ports |
| 885 | egress = 2 |
| 886 | ingress = 1 |
| 887 | # MPLS etherType |
| 888 | ethType = main.params[ 'TEST' ][ 'mplsType' ] |
| 889 | # MPLS label |
| 890 | mplsLabel = main.params[ 'TEST' ][ 'mpls' ] |
| 891 | |
| 892 | # Add a flow that connects host1 on port1 to host2 on port2 |
| 893 | main.log.info( "Adding flow with MPLS selector" ) |
| 894 | stepResult = main.ONOSrest.addFlow( deviceId=main.swDPID, |
| 895 | egressPort=egress, |
| 896 | ingressPort=ingress, |
| 897 | ethType=ethType, |
| 898 | mpls=mplsLabel, |
| 899 | debug=main.debug ) |
| 900 | |
| 901 | utilities.assert_equals( expect=main.TRUE, |
| 902 | actual=stepResult, |
| 903 | onpass="Successfully added flow", |
| 904 | onfail="Failed add flow" ) |
| 905 | |
| 906 | # Giving ONOS time to add the flow |
| 907 | time.sleep( main.addFlowSleep ) |
| 908 | |
| 909 | main.step( "Check flow is in the ADDED state" ) |
| 910 | |
| 911 | main.log.info( "Get the flows from ONOS" ) |
Jeremy | 8616099 | 2016-04-11 10:05:53 -0700 | [diff] [blame] | 912 | try: |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 913 | flows = json.loads( main.ONOSrest.flows( ) ) |
GlennRC | 956ea74 | 2015-11-05 16:14:15 -0800 | [diff] [blame] | 914 | |
Jeremy | 8616099 | 2016-04-11 10:05:53 -0700 | [diff] [blame] | 915 | stepResult = main.TRUE |
| 916 | for f in flows: |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 917 | if "rest" in f.get( "appId" ): |
| 918 | if "ADDED" not in f.get( "state" ): |
Jeremy | 8616099 | 2016-04-11 10:05:53 -0700 | [diff] [blame] | 919 | stepResult = main.FALSE |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 920 | main.log.error( "Flow: %s in state: %s" % ( f.get( "id" ), f.get( "state" ) ) ) |
Jeremy | 8616099 | 2016-04-11 10:05:53 -0700 | [diff] [blame] | 921 | except TypeError: |
| 922 | main.log.error( "No Flows found by the REST API" ) |
| 923 | stepResult = main.FALSE |
| 924 | except ValueError: |
| 925 | main.log.error( "Problem getting Flows state from REST API. Exiting test" ) |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 926 | main.cleanup( ) |
| 927 | main.exit( ) |
GlennRC | 956ea74 | 2015-11-05 16:14:15 -0800 | [diff] [blame] | 928 | |
| 929 | utilities.assert_equals( expect=main.TRUE, |
| 930 | actual=stepResult, |
| 931 | onpass="All flows are in the ADDED state", |
| 932 | onfail="All flows are NOT in the ADDED state" ) |
| 933 | |
| 934 | main.step( "Check flows are in Mininet's flow table" ) |
| 935 | |
| 936 | # get the flow IDs that were added through rest |
| 937 | main.log.info( "Getting the flow IDs from ONOS" ) |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 938 | flowIds = [ f.get( "id" ) for f in flows if "rest" in f.get( "appId" ) ] |
GlennRC | 956ea74 | 2015-11-05 16:14:15 -0800 | [diff] [blame] | 939 | # convert the flowIDs to ints then hex and finally back to strings |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 940 | flowIds = [ str( hex( int( x ) ) ) for x in flowIds ] |
| 941 | main.log.info( "ONOS flow IDs: {}".format( flowIds ) ) |
GlennRC | 956ea74 | 2015-11-05 16:14:15 -0800 | [diff] [blame] | 942 | |
| 943 | stepResult = main.Mininet1.checkFlowId( "s1", flowIds, debug=True ) |
| 944 | |
| 945 | utilities.assert_equals( expect=main.TRUE, |
| 946 | actual=stepResult, |
| 947 | onpass="All flows are in mininet", |
| 948 | onfail="All flows are NOT in mininet" ) |
| 949 | |
| 950 | main.step( "Send a packet to verify the flow is correct" ) |
| 951 | |
| 952 | main.log.info( "Starting filter on host2" ) |
| 953 | main.h2.startFilter( pktFilter="mpls" ) |
| 954 | |
| 955 | main.log.info( "Constructing packet" ) |
| 956 | main.log.info( "Sending packet to host2" ) |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 957 | main.h1.sendPacket( packet='Ether()/MPLS(label={})'.format( mplsLabel ) ) |
GlennRC | 956ea74 | 2015-11-05 16:14:15 -0800 | [diff] [blame] | 958 | |
| 959 | main.log.info( "Checking filter for our packet" ) |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 960 | stepResult = main.h2.checkFilter( ) |
GlennRC | 956ea74 | 2015-11-05 16:14:15 -0800 | [diff] [blame] | 961 | if stepResult: |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 962 | main.log.info( "Packet: %s" % main.h2.readPackets( ) ) |
| 963 | else: main.h2.killFilter( ) |
GlennRC | 956ea74 | 2015-11-05 16:14:15 -0800 | [diff] [blame] | 964 | |
| 965 | main.log.info( "Clean up host components" ) |
| 966 | for host in hosts: |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 967 | host.stopScapy( ) |
| 968 | main.Mininet1.removeHostComponent( "h1" ) |
| 969 | main.Mininet1.removeHostComponent( "h2" ) |
GlennRC | 956ea74 | 2015-11-05 16:14:15 -0800 | [diff] [blame] | 970 | |
| 971 | utilities.assert_equals( expect=main.TRUE, |
| 972 | actual=stepResult, |
| 973 | onpass="Successfully sent a packet", |
| 974 | onfail="Failed to send a packet" ) |
| 975 | |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 976 | def CASE1700( self, main ): |
GlennRC | 956ea74 | 2015-11-05 16:14:15 -0800 | [diff] [blame] | 977 | ''' |
| 978 | Add flows with a TCP selector and verify the flow |
| 979 | ''' |
| 980 | import json |
| 981 | import time |
| 982 | |
| 983 | main.case( "Verify the TCP selector is correctly compiled on the flow" ) |
| 984 | main.caseExplanation = "Install a flow with only the TCP selector " +\ |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 985 | "specified, verify the flow is added in ONOS, and finally " +\ |
GlennRC | 956ea74 | 2015-11-05 16:14:15 -0800 | [diff] [blame] | 986 | "send a TCP packet to verify the TCP selector is compiled correctly." |
| 987 | |
| 988 | main.step( "Add a flow with a TCP selector" ) |
| 989 | |
| 990 | main.log.info( "Creating host components" ) |
Jon Hall | a510a8a | 2016-05-04 15:09:28 -0700 | [diff] [blame] | 991 | main.Scapy.createHostComponent( "h1" ) |
| 992 | main.Scapy.createHostComponent( "h2" ) |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 993 | hosts = [ main.h1, main.h2 ] |
GlennRC | 956ea74 | 2015-11-05 16:14:15 -0800 | [diff] [blame] | 994 | for host in hosts: |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 995 | host.startHostCli( ) |
| 996 | host.startScapy( ) |
| 997 | host.updateSelf( ) |
GlennRC | 956ea74 | 2015-11-05 16:14:15 -0800 | [diff] [blame] | 998 | |
| 999 | # Add a flow that connects host1 on port1 to host2 on port2 |
| 1000 | egress = 2 |
| 1001 | ingress = 1 |
| 1002 | # IPv4 etherType |
| 1003 | ethType = main.params[ 'TEST' ][ 'ip4Type' ] |
| 1004 | # IP protocol |
| 1005 | ipProto = main.params[ 'TEST' ][ 'tcpProto' ] |
| 1006 | # TCP port destination |
| 1007 | tcpDst = main.params[ 'TEST' ][ 'tcpDst' ] |
| 1008 | |
| 1009 | main.log.info( "Add a flow that connects host1 on port1 to host2 on port2" ) |
| 1010 | stepResult = main.ONOSrest.addFlow( deviceId=main.swDPID, |
| 1011 | egressPort=egress, |
| 1012 | ingressPort=ingress, |
| 1013 | ethType=ethType, |
| 1014 | ipProto=ipProto, |
| 1015 | tcpDst=tcpDst, |
| 1016 | debug=main.debug ) |
| 1017 | |
| 1018 | utilities.assert_equals( expect=main.TRUE, |
| 1019 | actual=stepResult, |
| 1020 | onpass="Successfully added flows", |
| 1021 | onfail="Failed add flows" ) |
| 1022 | |
| 1023 | # Giving ONOS time to add the flow |
| 1024 | time.sleep( main.addFlowSleep ) |
| 1025 | |
| 1026 | main.step( "Check flow is in the ADDED state" ) |
| 1027 | |
| 1028 | main.log.info( "Get the flows from ONOS" ) |
Jeremy | 8616099 | 2016-04-11 10:05:53 -0700 | [diff] [blame] | 1029 | try: |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 1030 | flows = json.loads( main.ONOSrest.flows( ) ) |
GlennRC | 956ea74 | 2015-11-05 16:14:15 -0800 | [diff] [blame] | 1031 | |
Jeremy | 8616099 | 2016-04-11 10:05:53 -0700 | [diff] [blame] | 1032 | stepResult = main.TRUE |
| 1033 | for f in flows: |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 1034 | if "rest" in f.get( "appId" ): |
| 1035 | if "ADDED" not in f.get( "state" ): |
Jeremy | 8616099 | 2016-04-11 10:05:53 -0700 | [diff] [blame] | 1036 | stepResult = main.FALSE |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 1037 | main.log.error( "Flow: %s in state: %s" % ( f.get( "id" ), f.get( "state" ) ) ) |
Jeremy | 8616099 | 2016-04-11 10:05:53 -0700 | [diff] [blame] | 1038 | except TypeError: |
| 1039 | main.log.error( "No Flows found by the REST API" ) |
| 1040 | stepResult = main.FALSE |
| 1041 | except ValueError: |
| 1042 | main.log.error( "Problem getting Flows state from REST API. Exiting test" ) |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 1043 | main.cleanup( ) |
| 1044 | main.exit( ) |
GlennRC | 956ea74 | 2015-11-05 16:14:15 -0800 | [diff] [blame] | 1045 | |
| 1046 | utilities.assert_equals( expect=main.TRUE, |
| 1047 | actual=stepResult, |
| 1048 | onpass="All flows are in the ADDED state", |
| 1049 | onfail="All flows are NOT in the ADDED state" ) |
| 1050 | |
| 1051 | main.step( "Check flows are in Mininet's flow table" ) |
| 1052 | |
| 1053 | # get the flow IDs that were added through rest |
| 1054 | main.log.info( "Getting the flow IDs from ONOS" ) |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 1055 | flowIds = [ f.get( "id" ) for f in flows if "rest" in f.get( "appId" ) ] |
GlennRC | 956ea74 | 2015-11-05 16:14:15 -0800 | [diff] [blame] | 1056 | # convert the flowIDs to ints then hex and finally back to strings |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 1057 | flowIds = [ str( hex( int( x ) ) ) for x in flowIds ] |
| 1058 | main.log.info( "ONOS flow IDs: {}".format( flowIds ) ) |
GlennRC | 956ea74 | 2015-11-05 16:14:15 -0800 | [diff] [blame] | 1059 | |
| 1060 | stepResult = main.Mininet1.checkFlowId( "s1", flowIds, debug=False ) |
| 1061 | |
| 1062 | utilities.assert_equals( expect=main.TRUE, |
| 1063 | actual=stepResult, |
| 1064 | onpass="All flows are in mininet", |
| 1065 | onfail="All flows are NOT in mininet" ) |
| 1066 | |
| 1067 | main.step( "Send a packet to verify the flow is correct" ) |
| 1068 | |
| 1069 | main.log.info( "Constructing packet" ) |
| 1070 | # No need for the MAC src dst |
| 1071 | main.h1.buildEther( dst=main.h2.hostMac ) |
| 1072 | main.h1.buildIP( dst=main.h2.hostIp ) |
| 1073 | main.h1.buildTCP( dport=tcpDst ) |
| 1074 | |
| 1075 | main.log.info( "Starting filter on host2" ) |
| 1076 | # Defaults to ip |
| 1077 | main.h2.startFilter( pktFilter="tcp" ) |
| 1078 | |
| 1079 | main.log.info( "Sending packet to host2" ) |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 1080 | main.h1.sendPacket( ) |
GlennRC | 956ea74 | 2015-11-05 16:14:15 -0800 | [diff] [blame] | 1081 | |
| 1082 | main.log.info( "Checking filter for our packet" ) |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 1083 | stepResult = main.h2.checkFilter( ) |
GlennRC | 956ea74 | 2015-11-05 16:14:15 -0800 | [diff] [blame] | 1084 | if stepResult: |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 1085 | main.log.info( "Packet: %s" % main.h2.readPackets( ) ) |
| 1086 | else: main.h2.killFilter( ) |
GlennRC | 956ea74 | 2015-11-05 16:14:15 -0800 | [diff] [blame] | 1087 | |
| 1088 | main.log.info( "Clean up host components" ) |
| 1089 | for host in hosts: |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 1090 | host.stopScapy( ) |
| 1091 | main.Mininet1.removeHostComponent( "h1" ) |
| 1092 | main.Mininet1.removeHostComponent( "h2" ) |
GlennRC | 956ea74 | 2015-11-05 16:14:15 -0800 | [diff] [blame] | 1093 | |
| 1094 | utilities.assert_equals( expect=main.TRUE, |
| 1095 | actual=stepResult, |
| 1096 | onpass="Successfully sent a packet", |
| 1097 | onfail="Failed to send a packet" ) |
| 1098 | |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 1099 | def CASE1600( self, main ): |
GlennRC | 956ea74 | 2015-11-05 16:14:15 -0800 | [diff] [blame] | 1100 | ''' |
| 1101 | Add flows with a UDP selector and verify the flow |
| 1102 | ''' |
| 1103 | import json |
| 1104 | import time |
| 1105 | |
| 1106 | main.case( "Verify the UDP selector is correctly compiled on the flow" ) |
| 1107 | main.caseExplanation = "Install a flow with only the UDP selector " +\ |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 1108 | "specified, verify the flow is added in ONOS, and finally " +\ |
GlennRC | 956ea74 | 2015-11-05 16:14:15 -0800 | [diff] [blame] | 1109 | "send a UDP packet to verify the UDP selector is compiled correctly." |
| 1110 | |
| 1111 | main.step( "Add a flow with a UDP selector" ) |
| 1112 | |
| 1113 | main.log.info( "Creating host components" ) |
Jon Hall | a510a8a | 2016-05-04 15:09:28 -0700 | [diff] [blame] | 1114 | main.Scapy.createHostComponent( "h1" ) |
| 1115 | main.Scapy.createHostComponent( "h2" ) |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 1116 | hosts = [ main.h1, main.h2 ] |
GlennRC | 956ea74 | 2015-11-05 16:14:15 -0800 | [diff] [blame] | 1117 | for host in hosts: |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 1118 | host.startHostCli( ) |
| 1119 | host.startScapy( ) |
| 1120 | host.updateSelf( ) |
GlennRC | 956ea74 | 2015-11-05 16:14:15 -0800 | [diff] [blame] | 1121 | |
| 1122 | # Add a flow that connects host1 on port1 to host2 on port2 |
| 1123 | egress = 2 |
| 1124 | ingress = 1 |
| 1125 | # IPv4 etherType |
| 1126 | ethType = main.params[ 'TEST' ][ 'ip4Type' ] |
| 1127 | # IP protocol |
| 1128 | ipProto = main.params[ 'TEST' ][ 'udpProto' ] |
| 1129 | # UDP port destination |
| 1130 | udpDst = main.params[ 'TEST' ][ 'udpDst' ] |
| 1131 | |
| 1132 | main.log.info( "Add a flow that connects host1 on port1 to host2 on port2" ) |
| 1133 | stepResult = main.ONOSrest.addFlow( deviceId=main.swDPID, |
| 1134 | egressPort=egress, |
| 1135 | ingressPort=ingress, |
| 1136 | ethType=ethType, |
| 1137 | ipProto=ipProto, |
| 1138 | udpDst=udpDst, |
| 1139 | debug=main.debug ) |
| 1140 | |
| 1141 | utilities.assert_equals( expect=main.TRUE, |
| 1142 | actual=stepResult, |
| 1143 | onpass="Successfully added flows", |
| 1144 | onfail="Failed add flows" ) |
| 1145 | |
| 1146 | # Giving ONOS time to add the flow |
| 1147 | time.sleep( main.addFlowSleep ) |
| 1148 | |
| 1149 | main.step( "Check flow is in the ADDED state" ) |
| 1150 | |
| 1151 | main.log.info( "Get the flows from ONOS" ) |
Jeremy | 8616099 | 2016-04-11 10:05:53 -0700 | [diff] [blame] | 1152 | try: |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 1153 | flows = json.loads( main.ONOSrest.flows( ) ) |
GlennRC | 956ea74 | 2015-11-05 16:14:15 -0800 | [diff] [blame] | 1154 | |
Jeremy | 8616099 | 2016-04-11 10:05:53 -0700 | [diff] [blame] | 1155 | stepResult = main.TRUE |
| 1156 | for f in flows: |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 1157 | if "rest" in f.get( "appId" ): |
| 1158 | if "ADDED" not in f.get( "state" ): |
Jeremy | 8616099 | 2016-04-11 10:05:53 -0700 | [diff] [blame] | 1159 | stepResult = main.FALSE |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 1160 | main.log.error( "Flow: %s in state: %s" % ( f.get( "id" ), f.get( "state" ) ) ) |
Jeremy | 8616099 | 2016-04-11 10:05:53 -0700 | [diff] [blame] | 1161 | except TypeError: |
| 1162 | main.log.error( "No Flows found by the REST API" ) |
| 1163 | stepResult = main.FALSE |
| 1164 | except ValueError: |
| 1165 | main.log.error( "Problem getting Flows state from REST API. Exiting test" ) |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 1166 | main.cleanup( ) |
| 1167 | main.exit( ) |
GlennRC | 956ea74 | 2015-11-05 16:14:15 -0800 | [diff] [blame] | 1168 | |
| 1169 | utilities.assert_equals( expect=main.TRUE, |
| 1170 | actual=stepResult, |
| 1171 | onpass="All flows are in the ADDED state", |
| 1172 | onfail="All flows are NOT in the ADDED state" ) |
| 1173 | |
| 1174 | main.step( "Check flows are in Mininet's flow table" ) |
| 1175 | |
| 1176 | # get the flow IDs that were added through rest |
| 1177 | main.log.info( "Getting the flow IDs from ONOS" ) |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 1178 | flowIds = [ f.get( "id" ) for f in flows if "rest" in f.get( "appId" ) ] |
GlennRC | 956ea74 | 2015-11-05 16:14:15 -0800 | [diff] [blame] | 1179 | # convert the flowIDs to ints then hex and finally back to strings |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 1180 | flowIds = [ str( hex( int( x ) ) ) for x in flowIds ] |
| 1181 | main.log.info( "ONOS flow IDs: {}".format( flowIds ) ) |
GlennRC | 956ea74 | 2015-11-05 16:14:15 -0800 | [diff] [blame] | 1182 | |
| 1183 | stepResult = main.Mininet1.checkFlowId( "s1", flowIds, debug=False ) |
| 1184 | |
| 1185 | utilities.assert_equals( expect=main.TRUE, |
| 1186 | actual=stepResult, |
| 1187 | onpass="All flows are in mininet", |
| 1188 | onfail="All flows are NOT in mininet" ) |
| 1189 | |
| 1190 | main.step( "Send a packet to verify the flow is correct" ) |
| 1191 | |
| 1192 | main.log.info( "Constructing packet" ) |
| 1193 | # No need for the MAC src dst |
| 1194 | main.h1.buildEther( dst=main.h2.hostMac ) |
| 1195 | main.h1.buildIP( dst=main.h2.hostIp ) |
| 1196 | main.h1.buildUDP( dport=udpDst ) |
| 1197 | |
| 1198 | main.log.info( "Starting filter on host2" ) |
| 1199 | # Defaults to ip |
| 1200 | main.h2.startFilter( pktFilter="udp" ) |
| 1201 | |
| 1202 | main.log.info( "Sending packet to host2" ) |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 1203 | main.h1.sendPacket( ) |
GlennRC | 956ea74 | 2015-11-05 16:14:15 -0800 | [diff] [blame] | 1204 | |
| 1205 | main.log.info( "Checking filter for our packet" ) |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 1206 | stepResult = main.h2.checkFilter( ) |
GlennRC | 956ea74 | 2015-11-05 16:14:15 -0800 | [diff] [blame] | 1207 | if stepResult: |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 1208 | main.log.info( "Packet: %s" % main.h2.readPackets( ) ) |
| 1209 | else: main.h2.killFilter( ) |
GlennRC | 956ea74 | 2015-11-05 16:14:15 -0800 | [diff] [blame] | 1210 | |
| 1211 | main.log.info( "Clean up host components" ) |
| 1212 | for host in hosts: |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 1213 | host.stopScapy( ) |
| 1214 | main.Mininet1.removeHostComponent( "h1" ) |
| 1215 | main.Mininet1.removeHostComponent( "h2" ) |
GlennRC | 956ea74 | 2015-11-05 16:14:15 -0800 | [diff] [blame] | 1216 | |
| 1217 | utilities.assert_equals( expect=main.TRUE, |
| 1218 | actual=stepResult, |
| 1219 | onpass="Successfully sent a packet", |
| 1220 | onfail="Failed to send a packet" ) |
| 1221 | |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 1222 | def CASE1900( self, main ): |
| 1223 | ''' |
| 1224 | Add flows with a ICMPv4 selector and verify the flow |
| 1225 | ''' |
GlennRC | 956ea74 | 2015-11-05 16:14:15 -0800 | [diff] [blame] | 1226 | import json |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 1227 | import time |
GlennRC | 956ea74 | 2015-11-05 16:14:15 -0800 | [diff] [blame] | 1228 | |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 1229 | main.case( "Verify the ICMPv4 selector is correctly compiled on the flow" ) |
| 1230 | main.caseExplanation = "Install a flow with only the ICMPv4 selector " +\ |
| 1231 | "specified, verify the flow is added in ONOS, and finally " +\ |
| 1232 | "send a IMCPv4 packet to verify the ICMPv4 selector is compiled correctly." |
GlennRC | 956ea74 | 2015-11-05 16:14:15 -0800 | [diff] [blame] | 1233 | |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 1234 | main.step( "Add a flow with a ICMPv4 selector" ) |
| 1235 | |
| 1236 | main.log.info( "Creating host components" ) |
| 1237 | main.Scapy.createHostComponent( "h1" ) |
| 1238 | main.Scapy.createHostComponent( "h2" ) |
| 1239 | hosts = [ main.h1, main.h2 ] |
| 1240 | for host in hosts: |
| 1241 | host.startHostCli( ) |
| 1242 | host.startScapy( ) |
| 1243 | host.updateSelf( ) |
| 1244 | |
| 1245 | # Add a flow that connects host1 on port1 to host2 on port2 |
| 1246 | egress = 2 |
| 1247 | ingress = 1 |
| 1248 | # IPv4 etherType |
| 1249 | ethType = main.params[ 'TEST' ][ 'ip4Type' ] |
| 1250 | # IP protocol |
| 1251 | ipProto = main.params[ 'TEST' ][ 'icmpProto' ] |
| 1252 | |
| 1253 | main.log.info( "Add a flow that connects host1 on port1 to host2 on port2" ) |
| 1254 | stepResult = main.ONOSrest.addFlow( deviceId=main.swDPID, |
| 1255 | egressPort=egress, |
| 1256 | ingressPort=ingress, |
| 1257 | ethType=ethType, |
| 1258 | ipProto=ipProto, |
| 1259 | debug=main.debug ) |
| 1260 | |
| 1261 | utilities.assert_equals( expect=main.TRUE, |
| 1262 | actual=stepResult, |
| 1263 | onpass="Successfully added flows", |
| 1264 | onfail="Failed add flows" ) |
| 1265 | |
| 1266 | # Giving ONOS time to add the flow |
| 1267 | time.sleep( main.addFlowSleep ) |
| 1268 | |
| 1269 | main.step( "Check flow is in the ADDED state" ) |
| 1270 | |
| 1271 | main.log.info( "Get the flows from ONOS" ) |
Jeremy | 8616099 | 2016-04-11 10:05:53 -0700 | [diff] [blame] | 1272 | try: |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 1273 | flows = json.loads( main.ONOSrest.flows( ) ) |
GlennRC | 956ea74 | 2015-11-05 16:14:15 -0800 | [diff] [blame] | 1274 | |
Jeremy | 8616099 | 2016-04-11 10:05:53 -0700 | [diff] [blame] | 1275 | stepResult = main.TRUE |
| 1276 | for f in flows: |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 1277 | if "rest" in f.get( "appId" ): |
| 1278 | if "ADDED" not in f.get( "state" ): |
| 1279 | stepResult = main.FALSE |
| 1280 | main.log.error( "Flow: %s in state: %s" % ( f.get( "id" ), f.get( "state" ) ) ) |
Jeremy | 8616099 | 2016-04-11 10:05:53 -0700 | [diff] [blame] | 1281 | except TypeError: |
| 1282 | main.log.error( "No Flows found by the REST API" ) |
| 1283 | stepResult = main.FALSE |
| 1284 | except ValueError: |
| 1285 | main.log.error( "Problem getting Flows state from REST API. Exiting test" ) |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 1286 | main.cleanup( ) |
| 1287 | main.exit( ) |
| 1288 | |
| 1289 | utilities.assert_equals( expect=main.TRUE, |
| 1290 | actual=stepResult, |
| 1291 | onpass="All flows are in the ADDED state", |
| 1292 | onfail="All flows are NOT in the ADDED state" ) |
| 1293 | |
| 1294 | main.step( "Check flows are in Mininet's flow table" ) |
| 1295 | |
| 1296 | # get the flow IDs that were added through rest |
| 1297 | main.log.info( "Getting the flow IDs from ONOS" ) |
| 1298 | flowIds = [ f.get( "id" ) for f in flows if "rest" in f.get( "appId" ) ] |
| 1299 | # convert the flowIDs to ints then hex and finally back to strings |
| 1300 | flowIds = [ str( hex( int( x ) ) ) for x in flowIds ] |
| 1301 | main.log.info( "ONOS flow IDs: {}".format( flowIds ) ) |
| 1302 | |
| 1303 | stepResult = main.Mininet1.checkFlowId( "s1", flowIds, debug=False ) |
| 1304 | |
| 1305 | utilities.assert_equals( expect=main.TRUE, |
| 1306 | actual=stepResult, |
| 1307 | onpass="All flows are in mininet", |
| 1308 | onfail="All flows are NOT in mininet" ) |
| 1309 | |
| 1310 | main.step( "Send a packet to verify the flow is correct" ) |
| 1311 | |
| 1312 | main.log.info( "Constructing packet" ) |
| 1313 | # No need for the MAC src dst |
| 1314 | main.h1.buildEther( dst=main.h2.hostMac ) |
| 1315 | main.h1.buildIP( dst=main.h2.hostIp ) |
| 1316 | main.h1.buildICMP( ) |
| 1317 | |
| 1318 | main.log.info( "Starting filter on host2" ) |
| 1319 | # Defaults to ip |
| 1320 | main.h2.startFilter( pktFilter="icmp" ) |
| 1321 | |
| 1322 | main.log.info( "Sending packet to host2" ) |
| 1323 | main.h1.sendPacket( ) |
| 1324 | |
| 1325 | main.log.info( "Checking filter for our packet" ) |
| 1326 | stepResult = main.h2.checkFilter( ) |
| 1327 | if stepResult: |
| 1328 | main.log.info( "Packet: %s" % main.h2.readPackets( ) ) |
| 1329 | else: main.h2.killFilter( ) |
| 1330 | |
| 1331 | main.log.info( "Clean up host components" ) |
| 1332 | for host in hosts: |
| 1333 | host.stopScapy( ) |
| 1334 | main.Mininet1.removeHostComponent( "h1" ) |
| 1335 | main.Mininet1.removeHostComponent( "h2" ) |
| 1336 | |
| 1337 | utilities.assert_equals( expect=main.TRUE, |
| 1338 | actual=stepResult, |
| 1339 | onpass="Successfully sent a packet", |
| 1340 | onfail="Failed to send a packet" ) |
| 1341 | |
| 1342 | def CASE2000( self, main ): |
| 1343 | ''' |
| 1344 | Add flows with a ICMPv6 selector and verify the flow |
| 1345 | ''' |
| 1346 | import json |
| 1347 | import time |
| 1348 | |
| 1349 | main.case( "Verify the ICMPv6 selector is correctly compiled on the flow" ) |
| 1350 | main.caseExplanation = "Install a flow with only the ICMPv6 selector " +\ |
| 1351 | "specified, verify the flow is added in ONOS, and finally " +\ |
| 1352 | "send a IMCPv6 packet to verify the ICMPv6 selector is compiled correctly." |
| 1353 | |
| 1354 | main.step( "Add a flow with a ICMPv6 selector" ) |
| 1355 | |
| 1356 | main.log.info( "Creating host components" ) |
| 1357 | main.Scapy.createHostComponent( "h5" ) |
| 1358 | main.Scapy.createHostComponent( "h6" ) |
| 1359 | hosts =[ main.h5, main.h6 ] |
| 1360 | for host in hosts: |
| 1361 | host.startHostCli( ) |
| 1362 | host.startScapy( ) |
| 1363 | host.updateSelf( IPv6=True ) |
| 1364 | |
| 1365 | # Add a flow that connects host1 on port1 to host2 on port2 |
| 1366 | egress =6 |
| 1367 | ingress =5 |
| 1368 | # IPv6 etherType |
| 1369 | ethType = main.params[ 'TEST' ][ 'ip6Type' ] |
| 1370 | # IP protocol |
| 1371 | ipProto = main.params[ 'TEST' ][ 'icmp6Proto' ] |
| 1372 | |
| 1373 | main.log.info( "Add a flow that connects host1 on port1 to host2 on port2" ) |
| 1374 | stepResult = main.ONOSrest.addFlow( deviceId=main.swDPID, |
| 1375 | egressPort=egress, |
| 1376 | ingressPort=ingress, |
| 1377 | ethType=ethType, |
| 1378 | ipProto=ipProto, |
| 1379 | debug=main.debug ) |
| 1380 | |
| 1381 | utilities.assert_equals( expect=main.TRUE, |
| 1382 | actual=stepResult, |
| 1383 | onpass="Successfully added flows", |
| 1384 | onfail="Failed add flows" ) |
| 1385 | |
| 1386 | # Giving ONOS time to add the flow |
| 1387 | time.sleep( main.addFlowSleep ) |
| 1388 | |
| 1389 | main.step( "Check flow is in the ADDED state" ) |
| 1390 | |
| 1391 | main.log.info( "Get the flows from ONOS" ) |
| 1392 | try: |
| 1393 | flows = json.loads( main.ONOSrest.flows( ) ) |
| 1394 | |
| 1395 | stepResult = main.TRUE |
| 1396 | for f in flows: |
| 1397 | if "rest" in f.get( "appId" ): |
| 1398 | if "ADDED" not in f.get( "state" ): |
| 1399 | stepResult = main.FALSE |
| 1400 | main.log.error( "Flow: %s in state: %s" % ( f.get( "id" ), f.get( "state" ) ) ) |
| 1401 | except TypeError: |
| 1402 | main.log.error( "No Flows found by the REST API" ) |
| 1403 | stepResult = main.FALSE |
| 1404 | except ValueError: |
| 1405 | main.log.error( "Problem getting Flows state from REST API. Exiting test" ) |
| 1406 | main.cleanup( ) |
| 1407 | main.exit( ) |
| 1408 | |
| 1409 | utilities.assert_equals( expect=main.TRUE, |
| 1410 | actual=stepResult, |
| 1411 | onpass="All flows are in the ADDED state", |
| 1412 | onfail="All flows are NOT in the ADDED state" ) |
| 1413 | |
| 1414 | main.step( "Check flows are in Mininet's flow table" ) |
| 1415 | |
| 1416 | # get the flow IDs that were added through rest |
| 1417 | main.log.info( "Getting the flow IDs from ONOS" ) |
| 1418 | flowIds = [ f.get( "id" ) for f in flows if "rest" in f.get( "appId" ) ] |
| 1419 | # convert the flowIDs to ints then hex and finally back to strings |
| 1420 | flowIds = [ str( hex( int( x ) ) ) for x in flowIds ] |
| 1421 | main.log.info( "ONOS flow IDs: {}".format( flowIds ) ) |
| 1422 | |
| 1423 | stepResult = main.Mininet1.checkFlowId( "s1", flowIds, debug=False ) |
| 1424 | |
| 1425 | utilities.assert_equals( expect=main.TRUE, |
| 1426 | actual=stepResult, |
| 1427 | onpass="All flows are in mininet", |
| 1428 | onfail="All flows are NOT in mininet" ) |
| 1429 | |
| 1430 | main.step( "Send a packet to verify the flow is correct" ) |
| 1431 | |
| 1432 | main.log.info( "Constructing packet" ) |
| 1433 | # No need for the MAC src dst |
| 1434 | main.h5.buildEther( dst=main.h6.hostMac ) |
| 1435 | main.h5.buildIPv6( dst=main.h6.hostIp ) |
| 1436 | main.h5.buildICMP( ipVersion=6 ) |
| 1437 | |
| 1438 | main.log.info( "Starting filter on host2" ) |
| 1439 | # Defaults to ip |
| 1440 | main.h6.startFilter( pktFilter="icmp6" ) |
| 1441 | |
| 1442 | main.log.info( "Sending packet to host2" ) |
| 1443 | main.h5.sendPacket( ) |
| 1444 | |
| 1445 | main.log.info( "Checking filter for our packet" ) |
| 1446 | stepResult = main.h6.checkFilter( ) |
| 1447 | if stepResult: |
| 1448 | main.log.info( "Packet: %s" % main.h6.readPackets( ) ) |
| 1449 | else: main.h6.killFilter( ) |
| 1450 | |
| 1451 | main.log.info( "Clean up host components" ) |
| 1452 | for host in hosts: |
| 1453 | host.stopScapy( ) |
| 1454 | main.Mininet1.removeHostComponent( "h5" ) |
| 1455 | main.Mininet1.removeHostComponent( "h6" ) |
| 1456 | |
| 1457 | utilities.assert_equals( expect=main.TRUE, |
| 1458 | actual=stepResult, |
| 1459 | onpass="Successfully sent a packet", |
| 1460 | onfail="Failed to send a packet" ) |
| 1461 | |
| 1462 | def CASE3000( self, main ): |
| 1463 | ''' |
| 1464 | Delete flow |
| 1465 | ''' |
| 1466 | import json |
| 1467 | |
| 1468 | main.case( "Delete flows that were added through rest" ) |
| 1469 | main.step( "Deleting flows" ) |
| 1470 | |
| 1471 | main.log.info( "Getting flows" ) |
| 1472 | try: |
| 1473 | flows = json.loads( main.ONOSrest.flows( ) ) |
| 1474 | |
| 1475 | stepResult = main.TRUE |
| 1476 | for f in flows: |
| 1477 | if "rest" in f.get( "appId" ): |
| 1478 | if main.debug: main.log.debug( "Flow to be deleted:\n{}".format( main.ONOSrest.pprint( f ) ) ) |
| 1479 | stepResult = stepResult and main.ONOSrest.removeFlow( f.get( "deviceId" ), f.get( "id" ) ) |
| 1480 | except TypeError: |
| 1481 | main.log.error( "No Flows found by the REST API" ) |
| 1482 | stepResult = main.FALSE |
| 1483 | except ValueError: |
| 1484 | main.log.error( "Problem getting Flows state from REST API. Exiting test" ) |
| 1485 | main.cleanup( ) |
| 1486 | main.exit( ) |
GlennRC | 956ea74 | 2015-11-05 16:14:15 -0800 | [diff] [blame] | 1487 | |
| 1488 | utilities.assert_equals( expect=main.TRUE, |
| 1489 | actual=stepResult, |
| 1490 | onpass="Successfully deleting flows", |
| 1491 | onfail="Failed to delete flows" ) |
| 1492 | |
| 1493 | time.sleep( main.delFlowSleep ) |
| 1494 | |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 1495 | |
| 1496 | def CASE1200(self, main ): |
| 1497 | ''' |
| 1498 | Add flows with a ARP selector and verify the flow |
| 1499 | ''' |
| 1500 | import json |
| 1501 | import time |
| 1502 | |
| 1503 | main.case( "Verify flow IP selectors are correctly compiled" ) |
| 1504 | main.caseExplanation = "Install two flows with only IP selectors " + \ |
| 1505 | "specified, then verify flows are added in ONOS, finally " + \ |
| 1506 | "send a packet that only specifies the IP src and dst." |
| 1507 | |
| 1508 | main.step( "Add flows with ARP addresses as the only selectors" ) |
| 1509 | |
| 1510 | main.log.info( "Creating host components" ) |
| 1511 | main.Scapy.createHostComponent( "h1" ) |
| 1512 | main.Scapy.createHostComponent( "h2" ) |
| 1513 | hosts = [ main.h1, main.h2 ] |
| 1514 | for host in hosts: |
| 1515 | host.startHostCli( ) |
| 1516 | host.startScapy( ) |
| 1517 | host.updateSelf( ) |
| 1518 | |
| 1519 | # Add a flow that connects host1 on port1 to host2 on port2 |
| 1520 | # send output on port2 |
| 1521 | # recieve input on port1 |
| 1522 | egress = 2 |
| 1523 | ingress = 1 |
| 1524 | # ARP etherType = 0x0806 |
| 1525 | ethType = main.params[ 'TEST' ][ 'arpType' ] |
| 1526 | |
| 1527 | # Add flows that connects host1 to host2 |
| 1528 | main.log.info( "Add flow with port ingress 1 to port egress 2" ) |
| 1529 | stepResult = main.ONOSrest.addFlow(deviceId=main.swDPID, |
| 1530 | egressPort=egress, |
| 1531 | ingressPort=ingress, |
| 1532 | ethType=ethType, |
| 1533 | priority=40001, |
| 1534 | debug=main.debug ) |
| 1535 | |
| 1536 | utilities.assert_equals( expect=main.TRUE, |
| 1537 | actual=stepResult, |
| 1538 | onpass="Successfully added flows", |
| 1539 | onfail="Failed add flows" ) |
| 1540 | |
| 1541 | # Giving ONOS time to add the flow |
| 1542 | time.sleep( main.addFlowSleep ) |
| 1543 | |
| 1544 | main.step( "Check flow is in the ADDED state" ) |
| 1545 | |
| 1546 | main.log.info( "Get the flows from ONOS" ) |
| 1547 | try: |
| 1548 | flows = json.loads( main.ONOSrest.flows( ) ) |
| 1549 | |
| 1550 | stepResult = main.TRUE |
| 1551 | for f in flows: |
| 1552 | if "rest" in f.get( "appId" ): |
| 1553 | if "ADDED" not in f.get( "state" ): |
| 1554 | stepResult = main.FALSE |
| 1555 | main.log.error("Flow: %s in state: %s" % ( f.get("id"), f.get( "state" ) ) ) |
| 1556 | except TypeError: |
| 1557 | main.log.error( "No Flows found by the REST API" ) |
| 1558 | stepResult = main.FALSE |
| 1559 | except ValueError: |
| 1560 | main.log.error( "Problem getting Flows state from REST API. Exiting test" ) |
| 1561 | main.cleanup( ) |
| 1562 | main.exit( ) |
| 1563 | |
| 1564 | utilities.assert_equals( expect=main.TRUE, |
| 1565 | actual=stepResult, |
| 1566 | onpass="All flows are in the ADDED state", |
| 1567 | onfail="All flows are NOT in the ADDED state" ) |
| 1568 | |
| 1569 | main.step( "Check flows are in Mininet's flow table" ) |
| 1570 | |
| 1571 | # get the flow IDs that were added through rest |
| 1572 | main.log.info( "Getting the flow IDs from ONOS" ) |
| 1573 | flowIds = [f.get( "id" ) for f in flows if "rest" in f.get( "appId" ) ] |
| 1574 | # convert the flowIDs to ints then hex and finally back to strings |
| 1575 | flowIds = [ str( hex( int( x ) ) ) for x in flowIds ] |
| 1576 | main.log.info("ONOS flow IDs: {}".format( flowIds ) ) |
| 1577 | |
| 1578 | stepResult = main.Mininet1.checkFlowId( "s1", flowIds, debug=False ) |
| 1579 | |
| 1580 | utilities.assert_equals( expect=main.TRUE, |
| 1581 | actual=stepResult, |
| 1582 | onpass="All flows are in mininet", |
| 1583 | onfail="All flows are NOT in mininet" ) |
| 1584 | |
| 1585 | main.step( "Send a packet to verify the flow is correct" ) |
| 1586 | |
| 1587 | main.log.info( "Constructing packet" ) |
| 1588 | # No need for the MAC src dst |
| 1589 | main.h1.buildEther( src=main.h1.hostMac, dst=main.h2.hostMac ) |
| 1590 | main.h1.buildARP( pdst=main.h2.hostIp ) |
| 1591 | |
| 1592 | main.log.info( "Starting filter on host2" ) |
| 1593 | # Defaults to ip |
| 1594 | main.h2.startFilter( pktFilter="arp" ) |
| 1595 | |
| 1596 | main.log.info( "Sending packet to host2" ) |
| 1597 | main.h1.sendPacket( ) |
| 1598 | |
| 1599 | main.log.info( "Checking filter for our packet" ) |
| 1600 | stepResult = main.h2.checkFilter( ) |
| 1601 | if stepResult: |
| 1602 | main.log.info( "Packet: %s" % main.h2.readPackets( ) ) |
| 1603 | else: |
| 1604 | main.h2.killFilter( ) |
| 1605 | |
| 1606 | main.log.info( "Clean up host components" ) |
| 1607 | for host in hosts: |
| 1608 | host.stopScapy( ) |
| 1609 | main.Mininet1.removeHostComponent( "h1" ) |
| 1610 | main.Mininet1.removeHostComponent( "h2" ) |
| 1611 | |
| 1612 | utilities.assert_equals( expect=main.TRUE, |
| 1613 | actual=stepResult, |
| 1614 | onpass="Successfully sent a packet", |
| 1615 | onfail="Failed to send a packet" ) |
| 1616 | |
| 1617 | def CASE1800( self, main ): |
| 1618 | ''' |
| 1619 | Add flows with a SCTP selector and verify the flow |
| 1620 | ''' |
| 1621 | import json |
| 1622 | import time |
| 1623 | |
| 1624 | main.case( "Verify the UDP selector is correctly compiled on the flow" ) |
| 1625 | main.caseExplanation = "Install a flow with only the UDP selector " + \ |
| 1626 | "specified, verify the flow is added in ONOS, and finally " + \ |
| 1627 | "send a UDP packet to verify the UDP selector is compiled correctly." |
| 1628 | |
| 1629 | main.step( "Add a flow with a SCTP selector" ) |
| 1630 | |
| 1631 | main.log.info( "Creating host components" ) |
| 1632 | main.Scapy.createHostComponent( "h1" ) |
| 1633 | main.Scapy.createHostComponent( "h2" ) |
| 1634 | hosts = [ main.h1, main.h2 ] |
| 1635 | for host in hosts: |
| 1636 | host.startHostCli( ) |
| 1637 | host.startScapy( ) |
| 1638 | host.updateSelf( ) |
| 1639 | |
| 1640 | # Add a flow that connects host1 on port1 to host2 on port2 |
| 1641 | egress = 2 |
| 1642 | ingress = 1 |
| 1643 | # IPv4 etherType |
| 1644 | ethType = main.params[ 'TEST' ][ 'ip4Type' ] |
| 1645 | # IP protocol |
| 1646 | ipProto = main.params[ 'TEST' ][ 'sctpProto' ] |
| 1647 | |
| 1648 | main.log.info("Add a flow that connects host1 on port1 to host2 on port2") |
| 1649 | stepResult = main.ONOSrest.addFlow( deviceId=main.swDPID, |
| 1650 | egressPort=egress, |
| 1651 | ingressPort=ingress, |
| 1652 | ethType=ethType, |
| 1653 | ipProto=ipProto, |
| 1654 | debug=main.debug ) |
| 1655 | |
| 1656 | utilities.assert_equals( expect=main.TRUE, |
| 1657 | actual=stepResult, |
| 1658 | onpass="Successfully added flows", |
| 1659 | onfail="Failed add flows" ) |
| 1660 | |
| 1661 | # Giving ONOS time to add the flow |
| 1662 | time.sleep( main.addFlowSleep ) |
| 1663 | |
| 1664 | main.step( "Check flow is in the ADDED state" ) |
| 1665 | |
| 1666 | main.log.info( "Get the flows from ONOS" ) |
| 1667 | try: |
| 1668 | flows = json.loads( main.ONOSrest.flows( ) ) |
| 1669 | |
| 1670 | stepResult = main.TRUE |
| 1671 | for f in flows: |
| 1672 | if "rest" in f.get( "appId" ): |
| 1673 | if "ADDED" not in f.get( "state" ): |
| 1674 | stepResult = main.FALSE |
| 1675 | main.log.error("Flow: %s in state: %s" % ( f.get( "id" ), f.get( "state" ) ) ) |
| 1676 | except TypeError: |
| 1677 | main.log.error( "No Flows found by the REST API" ) |
| 1678 | stepResult = main.FALSE |
| 1679 | except ValueError: |
| 1680 | main.log.error( "Problem getting Flows state from REST API. Exiting test" ) |
| 1681 | main.cleanup( ) |
| 1682 | main.exit( ) |
| 1683 | |
| 1684 | utilities.assert_equals( expect=main.TRUE, |
| 1685 | actual=stepResult, |
| 1686 | onpass="All flows are in the ADDED state", |
| 1687 | onfail="All flows are NOT in the ADDED state" ) |
| 1688 | |
| 1689 | main.step( "Check flows are in Mininet's flow table" ) |
| 1690 | |
| 1691 | # get the flow IDs that were added through rest |
| 1692 | main.log.info( "Getting the flow IDs from ONOS" ) |
| 1693 | flowIds = [ f.get( "id" ) for f in flows if "rest" in f.get( "appId" ) ] |
| 1694 | # convert the flowIDs to ints then hex and finally back to strings |
| 1695 | flowIds = [ str( hex( int( x ) ) ) for x in flowIds ] |
| 1696 | main.log.info( "ONOS flow IDs: {}".format( flowIds ) ) |
| 1697 | |
| 1698 | stepResult = main.Mininet1.checkFlowId( "s1", flowIds, debug=False ) |
| 1699 | |
| 1700 | utilities.assert_equals( expect=main.TRUE, |
| 1701 | actual=stepResult, |
| 1702 | onpass="All flows are in mininet", |
| 1703 | onfail="All flows are NOT in mininet" ) |
| 1704 | |
| 1705 | main.step( "Send a packet to verify the flow is correct" ) |
| 1706 | |
| 1707 | main.log.info( "Constructing packet" ) |
| 1708 | # No need for the MAC src dst |
| 1709 | main.h1.buildEther( dst=main.h2.hostMac ) |
| 1710 | main.h1.buildIP( dst=main.h2.hostIp ) |
| 1711 | main.h1.buildSCTP( ) |
| 1712 | |
| 1713 | main.log.info( "Starting filter on host2" ) |
| 1714 | # Defaults to ip |
| 1715 | main.h2.startFilter( pktFilter="sctp" ) |
| 1716 | |
| 1717 | main.log.info( "Sending packet to host2" ) |
| 1718 | main.h1.sendPacket( ) |
| 1719 | |
| 1720 | main.log.info( "Checking filter for our packet" ) |
| 1721 | stepResult = main.h2.checkFilter( ) |
| 1722 | if stepResult: |
| 1723 | main.log.info( "Packet: %s" % main.h2.readPackets( ) ) |
| 1724 | else: |
| 1725 | main.h2.killFilter( ) |
| 1726 | |
| 1727 | main.log.info( "Clean up host components" ) |
| 1728 | for host in hosts: |
| 1729 | host.stopScapy( ) |
| 1730 | main.Mininet1.removeHostComponent( "h1" ) |
| 1731 | main.Mininet1.removeHostComponent( "h2" ) |
| 1732 | |
| 1733 | utilities.assert_equals( expect=main.TRUE, |
| 1734 | actual=stepResult, |
| 1735 | onpass="Successfully sent a packet", |
| 1736 | onfail="Failed to send a packet" ) |
| 1737 | |
GlennRC | 6844994 | 2015-10-16 16:03:12 -0700 | [diff] [blame] | 1738 | def CASE100( self, main ): |
GlennRC | 5147a42 | 2015-10-06 17:26:17 -0700 | [diff] [blame] | 1739 | ''' |
| 1740 | Report errors/warnings/exceptions |
| 1741 | ''' |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 1742 | main.log.info( "Error report: \n" ) |
GlennRC | 5147a42 | 2015-10-06 17:26:17 -0700 | [diff] [blame] | 1743 | main.ONOSbench.logReport( main.ONOSip[ 0 ], |
| 1744 | [ "INFO", |
| 1745 | "FOLLOWER", |
| 1746 | "WARN", |
| 1747 | "flow", |
| 1748 | "ERROR", |
| 1749 | "Except" ], |
GlennRC | 6844994 | 2015-10-16 16:03:12 -0700 | [diff] [blame] | 1750 | "s" ) |