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