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