Jeremy Ronquillo | b27ce4c | 2017-07-17 12:41:28 -0700 | [diff] [blame] | 1 | """ |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 2 | Copyright 2015 Open Networking Foundation ( ONF ) |
Jeremy Ronquillo | b27ce4c | 2017-07-17 12:41:28 -0700 | [diff] [blame] | 3 | |
| 4 | Please refer questions to either the onos test mailing list at <onos-test@onosproject.org>, |
| 5 | the System Testing Plans and Results wiki page at <https://wiki.onosproject.org/x/voMg>, |
| 6 | or the System Testing Guide page at <https://wiki.onosproject.org/x/WYQg> |
| 7 | |
| 8 | TestON is free software: you can redistribute it and/or modify |
| 9 | it under the terms of the GNU General Public License as published by |
| 10 | the Free Software Foundation, either version 2 of the License, or |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 11 | ( at your option ) any later version. |
Jeremy Ronquillo | b27ce4c | 2017-07-17 12:41:28 -0700 | [diff] [blame] | 12 | |
| 13 | TestON is distributed in the hope that it will be useful, |
| 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | GNU General Public License for more details. |
| 17 | |
| 18 | You should have received a copy of the GNU General Public License |
| 19 | along with TestON. If not, see <http://www.gnu.org/licenses/>. |
| 20 | """ |
GlennRC | 5147a42 | 2015-10-06 17:26:17 -0700 | [diff] [blame] | 21 | class FUNCflow: |
| 22 | |
| 23 | def __init__( self ): |
| 24 | self.default = '' |
| 25 | |
| 26 | def CASE1( self, main ): |
GlennRC | 5147a42 | 2015-10-06 17:26:17 -0700 | [diff] [blame] | 27 | import os |
| 28 | import imp |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 29 | try: |
| 30 | from tests.dependencies.ONOSSetup import ONOSSetup |
| 31 | except ImportError: |
| 32 | main.log.error( "SetUp not found exiting the test" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 33 | main.cleanAndExit() |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 34 | try: |
| 35 | main.testSetUp |
| 36 | except ( NameError, AttributeError ): |
| 37 | main.testSetUp = ONOSSetup() |
GlennRC | 5147a42 | 2015-10-06 17:26:17 -0700 | [diff] [blame] | 38 | """ |
| 39 | - Construct tests variables |
| 40 | - GIT ( optional ) |
| 41 | - Checkout ONOS master branch |
| 42 | - Pull latest ONOS code |
GlennRC | 5147a42 | 2015-10-06 17:26:17 -0700 | [diff] [blame] | 43 | """ |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 44 | main.testSetUp.envSetupDescription() |
| 45 | stepResult = main.FALSE |
| 46 | try: |
| 47 | # Test variables |
| 48 | main.cellName = main.params[ 'ENV' ][ 'cellName' ] |
| 49 | main.apps = main.params[ 'ENV' ][ 'cellApps' ] |
| 50 | main.ONOSport = main.params[ 'CTRL' ][ 'port' ] |
| 51 | main.dependencyPath = main.testOnDirectory + \ |
| 52 | main.params[ 'DEPENDENCY' ][ 'path' ] |
| 53 | wrapperFile1 = main.params[ 'DEPENDENCY' ][ 'wrapper1' ] |
| 54 | wrapperFile2 = main.params[ 'DEPENDENCY' ][ 'wrapper2' ] |
| 55 | main.topology = main.params[ 'DEPENDENCY' ][ 'topology' ] |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 56 | main.startUpSleep = int( main.params[ 'SLEEP' ][ 'startup' ] ) |
| 57 | main.startMNSleep = int( main.params[ 'SLEEP' ][ 'startMN' ] ) |
| 58 | main.addFlowSleep = int( main.params[ 'SLEEP' ][ 'addFlow' ] ) |
| 59 | main.delFlowSleep = int( main.params[ 'SLEEP' ][ 'delFlow' ] ) |
| 60 | main.debug = main.params[ 'DEBUG' ] |
| 61 | main.swDPID = main.params[ 'TEST' ][ 'swDPID' ] |
You Wang | dafb6e2 | 2018-01-22 17:01:00 -0800 | [diff] [blame] | 62 | main.scapyHostNames = main.params[ 'SCAPY' ][ 'HOSTNAMES' ].split( ',' ) |
| 63 | main.scapyHosts = [] # List of scapy hosts for iterating |
GlennRC | 5147a42 | 2015-10-06 17:26:17 -0700 | [diff] [blame] | 64 | |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 65 | main.debug = True if "on" in main.debug else False |
GlennRC | 956ea74 | 2015-11-05 16:14:15 -0800 | [diff] [blame] | 66 | |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 67 | # -- INIT SECTION, ONLY RUNS ONCE -- # |
GlennRC | 5147a42 | 2015-10-06 17:26:17 -0700 | [diff] [blame] | 68 | |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 69 | try: |
| 70 | from tests.FUNC.FUNCflow.dependencies.checkingFlow import CheckingFlow |
| 71 | main.checkingFlow = CheckingFlow() |
| 72 | except ImportError as e: |
| 73 | print e |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 74 | main.log.error( "CheckingFlow not found exiting the test" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 75 | main.cleanAndExit() |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 76 | copyResult = main.ONOSbench.scp( main.Mininet1, |
| 77 | main.dependencyPath + main.topology, |
| 78 | main.Mininet1.home + '/custom/', |
| 79 | direction="to" ) |
GlennRC | 5147a42 | 2015-10-06 17:26:17 -0700 | [diff] [blame] | 80 | |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 81 | utilities.assert_equals( expect=main.TRUE, |
| 82 | actual=copyResult, |
| 83 | onpass="Successfully copy " + "test variables ", |
| 84 | onfail="Failed to copy test variables" ) |
GlennRC | 5147a42 | 2015-10-06 17:26:17 -0700 | [diff] [blame] | 85 | |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 86 | stepResult = main.testSetUp.envSetup() |
GlennRC | 1704d07 | 2015-10-07 18:40:45 -0700 | [diff] [blame] | 87 | |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 88 | except Exception as e: |
| 89 | main.testSetUp.envSetupException( e ) |
| 90 | main.testSetUp.evnSetupConclusion( stepResult ) |
Devin Lim | 8d7c778 | 2017-06-07 16:21:20 -0700 | [diff] [blame] | 91 | |
GlennRC | 5147a42 | 2015-10-06 17:26:17 -0700 | [diff] [blame] | 92 | def CASE2( self, main ): |
| 93 | """ |
| 94 | - Set up cell |
| 95 | - Create cell file |
| 96 | - Set cell file |
| 97 | - Verify cell file |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 98 | - Building ONOS |
| 99 | - Install ONOS package |
| 100 | - Build ONOS package |
GlennRC | 5147a42 | 2015-10-06 17:26:17 -0700 | [diff] [blame] | 101 | - Kill ONOS process |
| 102 | - Uninstall ONOS cluster |
| 103 | - Verify ONOS start up |
| 104 | - Install ONOS cluster |
| 105 | - Connect to cli |
| 106 | """ |
You Wang | a0f6ff6 | 2018-01-11 15:46:30 -0800 | [diff] [blame] | 107 | main.testSetUp.ONOSSetUp( main.Cluster ) |
GlennRC | 5147a42 | 2015-10-06 17:26:17 -0700 | [diff] [blame] | 108 | |
GlennRC | 6844994 | 2015-10-16 16:03:12 -0700 | [diff] [blame] | 109 | def CASE10( self, main ): |
Jon Hall | fc95107 | 2017-05-24 15:55:34 -0700 | [diff] [blame] | 110 | """ |
GlennRC | 6844994 | 2015-10-16 16:03:12 -0700 | [diff] [blame] | 111 | Start Mininet |
Jon Hall | fc95107 | 2017-05-24 15:55:34 -0700 | [diff] [blame] | 112 | """ |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 113 | import json |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 114 | import time |
| 115 | try: |
| 116 | from tests.dependencies.topology import Topology |
| 117 | except ImportError: |
| 118 | main.log.error( "Topology not found exiting the test" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 119 | main.cleanAndExit() |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 120 | try: |
| 121 | main.topoRelated |
| 122 | except ( NameError, AttributeError ): |
| 123 | main.topoRelated = Topology() |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 124 | |
| 125 | main.case( "Setup mininet and compare ONOS topology view to Mininet topology" ) |
| 126 | main.caseExplanation = "Start mininet with custom topology and compare topology " +\ |
| 127 | "elements between Mininet and ONOS" |
| 128 | |
GlennRC | 6844994 | 2015-10-16 16:03:12 -0700 | [diff] [blame] | 129 | main.step( "Setup Mininet Topology" ) |
| 130 | topology = main.Mininet1.home + '/custom/' + main.topology |
Jon Hall | fc95107 | 2017-05-24 15:55:34 -0700 | [diff] [blame] | 131 | stepResult = main.Mininet1.startNet( topoFile=topology ) |
GlennRC | 6844994 | 2015-10-16 16:03:12 -0700 | [diff] [blame] | 132 | |
| 133 | utilities.assert_equals( expect=main.TRUE, |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 134 | actual=stepResult, |
GlennRC | 6844994 | 2015-10-16 16:03:12 -0700 | [diff] [blame] | 135 | onpass="Successfully loaded topology", |
| 136 | onfail="Failed to load topology" ) |
| 137 | |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 138 | main.step( "Assign switch to controller" ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 139 | stepResult = main.Mininet1.assignSwController( "s1", main.Cluster.active( 0 ).ipAddress ) |
GlennRC | 6844994 | 2015-10-16 16:03:12 -0700 | [diff] [blame] | 140 | |
| 141 | utilities.assert_equals( expect=main.TRUE, |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 142 | actual=stepResult, |
| 143 | onpass="Successfully assigned switch to controller", |
| 144 | onfail="Failed to assign switch to controller" ) |
GlennRC | 6844994 | 2015-10-16 16:03:12 -0700 | [diff] [blame] | 145 | |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 146 | time.sleep( main.startMNSleep ) |
GlennRC | 6844994 | 2015-10-16 16:03:12 -0700 | [diff] [blame] | 147 | |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 148 | main.topoRelated.compareTopos( main.Mininet1 ) |
GlennRC | 6844994 | 2015-10-16 16:03:12 -0700 | [diff] [blame] | 149 | |
You Wang | dafb6e2 | 2018-01-22 17:01:00 -0800 | [diff] [blame] | 150 | def CASE11( self, main ): |
| 151 | """ |
| 152 | Start Scapy with Mininet |
| 153 | """ |
| 154 | main.case( "Starting scapy with Mininet" ) |
| 155 | main.step( "Creating Host component" ) |
| 156 | scapyResult = main.TRUE |
| 157 | for hostName in main.scapyHostNames: |
| 158 | main.Scapy.createHostComponent( hostName ) |
| 159 | main.scapyHosts.append( getattr( main, hostName ) ) |
| 160 | |
| 161 | main.step( "Start scapy components" ) |
| 162 | for host in main.scapyHosts: |
| 163 | host.startHostCli() |
| 164 | host.startScapy() |
| 165 | host.updateSelf() |
| 166 | main.log.debug( host.name ) |
| 167 | main.log.debug( host.hostIp ) |
| 168 | main.log.debug( host.hostMac ) |
| 169 | |
| 170 | utilities.assert_equals( expect=main.TRUE, |
| 171 | actual=scapyResult, |
| 172 | onpass="Successfully created Scapy Components", |
| 173 | onfail="Failed to discover Scapy Components" ) |
| 174 | |
| 175 | def CASE12( self, main ): |
| 176 | """ |
| 177 | Stop mininet and remove scapy host |
| 178 | """ |
| 179 | try: |
| 180 | from tests.dependencies.utils import Utils |
| 181 | except ImportError: |
| 182 | main.log.error( "Utils not found exiting the test" ) |
| 183 | main.cleanAndExit() |
| 184 | try: |
| 185 | main.Utils |
| 186 | except ( NameError, AttributeError ): |
| 187 | main.Utils = Utils() |
| 188 | main.log.report( "Stop Mininet and Scapy" ) |
| 189 | main.case( "Stop Mininet and Scapy" ) |
| 190 | main.caseExplanation = "Stopping the current mininet topology " +\ |
| 191 | "to start up fresh" |
| 192 | main.step( "Stopping and Removing Scapy Host Components" ) |
| 193 | scapyResult = main.TRUE |
| 194 | for host in main.scapyHosts: |
| 195 | scapyResult = scapyResult and host.stopScapy() |
| 196 | main.log.info( "Stopped Scapy Host: {0}".format( host.name ) ) |
| 197 | |
| 198 | for host in main.scapyHosts: |
| 199 | scapyResult = scapyResult and main.Scapy.removeHostComponent( host.name ) |
| 200 | main.log.info( "Removed Scapy Host Component: {0}".format( host.name ) ) |
| 201 | |
| 202 | main.scapyHosts = [] |
| 203 | |
| 204 | utilities.assert_equals( expect=main.TRUE, |
| 205 | actual=scapyResult, |
| 206 | onpass="Successfully stopped scapy and removed host components", |
| 207 | onfail="Failed to stop mininet and scapy" ) |
| 208 | |
| 209 | mininetResult = main.Utils.mininetCleanup( main.Mininet1 ) |
| 210 | # Exit if topology did not load properly |
| 211 | if not ( mininetResult and scapyResult ): |
| 212 | main.cleanAndExit() |
| 213 | |
Jon Hall | 892818c | 2015-10-20 17:58:34 -0700 | [diff] [blame] | 214 | def CASE66( self, main ): |
Jon Hall | fc95107 | 2017-05-24 15:55:34 -0700 | [diff] [blame] | 215 | """ |
Jon Hall | 892818c | 2015-10-20 17:58:34 -0700 | [diff] [blame] | 216 | Testing scapy |
Jon Hall | fc95107 | 2017-05-24 15:55:34 -0700 | [diff] [blame] | 217 | """ |
Jon Hall | 892818c | 2015-10-20 17:58:34 -0700 | [diff] [blame] | 218 | main.case( "Testing scapy" ) |
You Wang | dafb6e2 | 2018-01-22 17:01:00 -0800 | [diff] [blame] | 219 | for host in main.scapyHosts: |
| 220 | host.stopScapy() |
Jon Hall | fc95107 | 2017-05-24 15:55:34 -0700 | [diff] [blame] | 221 | host.startScapy() |
| 222 | host.updateSelf() |
Jon Hall | 892818c | 2015-10-20 17:58:34 -0700 | [diff] [blame] | 223 | main.log.debug( host.name ) |
| 224 | main.log.debug( host.hostIp ) |
| 225 | main.log.debug( host.hostMac ) |
| 226 | |
| 227 | main.step( "Sending/Receiving Test packet - Filter doesn't match" ) |
Jon Hall | a510a8a | 2016-05-04 15:09:28 -0700 | [diff] [blame] | 228 | main.log.info( "Starting Filter..." ) |
Jon Hall | fc95107 | 2017-05-24 15:55:34 -0700 | [diff] [blame] | 229 | main.h2.startFilter() |
Jon Hall | a510a8a | 2016-05-04 15:09:28 -0700 | [diff] [blame] | 230 | main.log.info( "Building Ether frame..." ) |
Jon Hall | 892818c | 2015-10-20 17:58:34 -0700 | [diff] [blame] | 231 | main.h1.buildEther( dst=main.h2.hostMac ) |
Jon Hall | a510a8a | 2016-05-04 15:09:28 -0700 | [diff] [blame] | 232 | main.log.info( "Sending Packet..." ) |
Jon Hall | fc95107 | 2017-05-24 15:55:34 -0700 | [diff] [blame] | 233 | main.h1.sendPacket() |
Jon Hall | a510a8a | 2016-05-04 15:09:28 -0700 | [diff] [blame] | 234 | main.log.info( "Checking Filter..." ) |
Jon Hall | fc95107 | 2017-05-24 15:55:34 -0700 | [diff] [blame] | 235 | finished = main.h2.checkFilter() |
Jon Hall | a510a8a | 2016-05-04 15:09:28 -0700 | [diff] [blame] | 236 | main.log.debug( finished ) |
Jon Hall | 892818c | 2015-10-20 17:58:34 -0700 | [diff] [blame] | 237 | i = "" |
| 238 | if finished: |
Jon Hall | fc95107 | 2017-05-24 15:55:34 -0700 | [diff] [blame] | 239 | a = main.h2.readPackets() |
| 240 | for i in a.splitlines(): |
Jon Hall | 892818c | 2015-10-20 17:58:34 -0700 | [diff] [blame] | 241 | main.log.info( i ) |
| 242 | else: |
Jon Hall | fc95107 | 2017-05-24 15:55:34 -0700 | [diff] [blame] | 243 | kill = main.h2.killFilter() |
Jon Hall | 892818c | 2015-10-20 17:58:34 -0700 | [diff] [blame] | 244 | main.log.debug( kill ) |
| 245 | main.h2.handle.sendline( "" ) |
| 246 | main.h2.handle.expect( main.h2.scapyPrompt ) |
| 247 | main.log.debug( main.h2.handle.before ) |
| 248 | utilities.assert_equals( expect=True, |
| 249 | actual="dst=00:00:00:00:00:02 src=00:00:00:00:00:01" in i, |
| 250 | onpass="Pass", |
| 251 | onfail="Fail" ) |
| 252 | |
| 253 | main.step( "Sending/Receiving Test packet - Filter matches" ) |
Jon Hall | fc95107 | 2017-05-24 15:55:34 -0700 | [diff] [blame] | 254 | main.h2.startFilter() |
Jon Hall | 892818c | 2015-10-20 17:58:34 -0700 | [diff] [blame] | 255 | main.h1.buildEther( dst=main.h2.hostMac ) |
| 256 | main.h1.buildIP( dst=main.h2.hostIp ) |
Jon Hall | fc95107 | 2017-05-24 15:55:34 -0700 | [diff] [blame] | 257 | main.h1.sendPacket() |
| 258 | finished = main.h2.checkFilter() |
Jon Hall | 892818c | 2015-10-20 17:58:34 -0700 | [diff] [blame] | 259 | i = "" |
| 260 | if finished: |
Jon Hall | fc95107 | 2017-05-24 15:55:34 -0700 | [diff] [blame] | 261 | a = main.h2.readPackets() |
| 262 | for i in a.splitlines(): |
Jon Hall | 892818c | 2015-10-20 17:58:34 -0700 | [diff] [blame] | 263 | main.log.info( i ) |
| 264 | else: |
Jon Hall | fc95107 | 2017-05-24 15:55:34 -0700 | [diff] [blame] | 265 | kill = main.h2.killFilter() |
Jon Hall | 892818c | 2015-10-20 17:58:34 -0700 | [diff] [blame] | 266 | main.log.debug( kill ) |
| 267 | main.h2.handle.sendline( "" ) |
| 268 | main.h2.handle.expect( main.h2.scapyPrompt ) |
| 269 | main.log.debug( main.h2.handle.before ) |
| 270 | utilities.assert_equals( expect=True, |
| 271 | actual="dst=00:00:00:00:00:02 src=00:00:00:00:00:01" in i, |
| 272 | onpass="Pass", |
| 273 | onfail="Fail" ) |
| 274 | |
GlennRC | 6844994 | 2015-10-16 16:03:12 -0700 | [diff] [blame] | 275 | def CASE1000( self, main ): |
Jon Hall | fc95107 | 2017-05-24 15:55:34 -0700 | [diff] [blame] | 276 | """ |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 277 | Add flows with MAC selectors and verify the flows |
Jon Hall | fc95107 | 2017-05-24 15:55:34 -0700 | [diff] [blame] | 278 | """ |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 279 | import json |
| 280 | import time |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 281 | ctrl = main.Cluster.active( 0 ) |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 282 | main.case( "Verify flow MAC selectors are correctly compiled" ) |
| 283 | main.caseExplanation = "Install two flows with only MAC selectors " +\ |
Jon Hall | fc95107 | 2017-05-24 15:55:34 -0700 | [diff] [blame] | 284 | "specified, then verify flows are added in ONOS, finally " +\ |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 285 | "send a packet that only specifies the MAC src and dst." |
GlennRC | 6844994 | 2015-10-16 16:03:12 -0700 | [diff] [blame] | 286 | |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 287 | main.step( "Add flows with MAC addresses as the only selectors" ) |
You Wang | dafb6e2 | 2018-01-22 17:01:00 -0800 | [diff] [blame] | 288 | for host in main.scapyHosts: |
| 289 | host.stopScapy() |
Jon Hall | fc95107 | 2017-05-24 15:55:34 -0700 | [diff] [blame] | 290 | host.startScapy() |
| 291 | host.updateSelf() |
You Wang | dafb6e2 | 2018-01-22 17:01:00 -0800 | [diff] [blame] | 292 | main.log.debug( host.name ) |
| 293 | main.log.debug( host.hostIp ) |
| 294 | main.log.debug( host.hostMac ) |
GlennRC | 6844994 | 2015-10-16 16:03:12 -0700 | [diff] [blame] | 295 | |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 296 | # Add a flow that connects host1 on port1 to host2 on port2 |
| 297 | # send output on port2 |
| 298 | # recieve input on port1 |
| 299 | egress = 2 |
| 300 | ingress = 1 |
| 301 | |
| 302 | # Add flows that sends packets from port1 to port2 with correct |
| 303 | # MAC src and dst addresses |
| 304 | main.log.info( "Adding flow with MAC selectors" ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 305 | stepResult = ctrl.REST.addFlow( deviceId=main.swDPID, |
| 306 | egressPort=egress, |
| 307 | ingressPort=ingress, |
| 308 | ethSrc=main.h1.hostMac, |
| 309 | ethDst=main.h2.hostMac, |
| 310 | debug=main.debug ) |
GlennRC | 6844994 | 2015-10-16 16:03:12 -0700 | [diff] [blame] | 311 | |
GlennRC | a539137 | 2015-10-14 17:28:15 -0700 | [diff] [blame] | 312 | utilities.assert_equals( expect=main.TRUE, |
| 313 | actual=stepResult, |
GlennRC | 6844994 | 2015-10-16 16:03:12 -0700 | [diff] [blame] | 314 | onpass="Successfully added flows", |
| 315 | onfail="Failed add flows" ) |
GlennRC | a539137 | 2015-10-14 17:28:15 -0700 | [diff] [blame] | 316 | |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 317 | # Giving ONOS time to add the flows |
| 318 | time.sleep( main.addFlowSleep ) |
GlennRC | 5147a42 | 2015-10-06 17:26:17 -0700 | [diff] [blame] | 319 | |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 320 | main.checkingFlow.checkFlow() |
GlennRC | 956ea74 | 2015-11-05 16:14:15 -0800 | [diff] [blame] | 321 | |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 322 | main.step( "Send a packet to verify the flows are correct" ) |
| 323 | |
| 324 | # Specify the src and dst MAC addr |
| 325 | main.log.info( "Constructing packet" ) |
| 326 | main.h1.buildEther( src=main.h1.hostMac, dst=main.h2.hostMac ) |
| 327 | |
| 328 | # Filter for packets with the correct host name. Otherwise, |
| 329 | # the filter we catch any packet that is sent to host2 |
| 330 | # NOTE: I believe it doesn't matter which host name it is, |
GlennRC | 956ea74 | 2015-11-05 16:14:15 -0800 | [diff] [blame] | 331 | # as long as the src and dst are both specified |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 332 | main.log.info( "Starting filter on host2" ) |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 333 | main.h2.startFilter( pktFilter="ether host %s" % main.h1.hostMac ) |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 334 | |
| 335 | main.log.info( "Sending packet to host2" ) |
| 336 | main.h1.sendPacket() |
| 337 | |
| 338 | main.log.info( "Checking filter for our packet" ) |
Jon Hall | fc95107 | 2017-05-24 15:55:34 -0700 | [diff] [blame] | 339 | stepResult = main.h2.checkFilter() |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 340 | if stepResult: |
Jon Hall | fc95107 | 2017-05-24 15:55:34 -0700 | [diff] [blame] | 341 | main.log.info( "Packet: %s" % main.h2.readPackets() ) |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 342 | else: |
Jon Hall | fc95107 | 2017-05-24 15:55:34 -0700 | [diff] [blame] | 343 | main.h2.killFilter() |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 344 | |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 345 | utilities.assert_equals( expect=main.TRUE, |
| 346 | actual=stepResult, |
| 347 | onpass="Successfully sent a packet", |
| 348 | onfail="Failed to send a packet" ) |
| 349 | |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 350 | def CASE1400( self, main ): |
Jon Hall | fc95107 | 2017-05-24 15:55:34 -0700 | [diff] [blame] | 351 | """ |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 352 | Add flows with IPv4 selectors and verify the flows |
Jon Hall | fc95107 | 2017-05-24 15:55:34 -0700 | [diff] [blame] | 353 | """ |
GlennRC | 6844994 | 2015-10-16 16:03:12 -0700 | [diff] [blame] | 354 | import json |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 355 | import time |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 356 | ctrl = main.Cluster.active( 0 ) |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 357 | main.case( "Verify flow IP selectors are correctly compiled" ) |
| 358 | main.caseExplanation = "Install two flows with only IP selectors " +\ |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 359 | "specified, then verify flows are added in ONOS, finally " +\ |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 360 | "send a packet that only specifies the IP src and dst." |
| 361 | |
| 362 | main.step( "Add flows with IPv4 addresses as the only selectors" ) |
You Wang | dafb6e2 | 2018-01-22 17:01:00 -0800 | [diff] [blame] | 363 | for host in main.scapyHosts: |
| 364 | host.stopScapy() |
Jon Hall | fc95107 | 2017-05-24 15:55:34 -0700 | [diff] [blame] | 365 | host.startScapy() |
| 366 | host.updateSelf() |
You Wang | dafb6e2 | 2018-01-22 17:01:00 -0800 | [diff] [blame] | 367 | main.log.debug( host.name ) |
| 368 | main.log.debug( host.hostIp ) |
| 369 | main.log.debug( host.hostMac ) |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 370 | |
| 371 | # Add a flow that connects host1 on port1 to host2 on port2 |
| 372 | # send output on port2 |
| 373 | # recieve input on port1 |
| 374 | egress = 2 |
| 375 | ingress = 1 |
| 376 | # IPv4 etherType = 0x800 |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 377 | ethType = main.params[ 'TEST' ][ 'ip4Type' ] |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 378 | |
| 379 | # Add flows that connects host1 to host2 |
| 380 | main.log.info( "Add flow with port ingress 1 to port egress 2" ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 381 | stepResult = ctrl.REST.addFlow( deviceId=main.swDPID, |
| 382 | egressPort=egress, |
| 383 | ingressPort=ingress, |
| 384 | ethType=ethType, |
| 385 | ipSrc=( "IPV4_SRC", main.h1.hostIp + "/32" ), |
| 386 | ipDst=( "IPV4_DST", main.h2.hostIp + "/32" ), |
| 387 | debug=main.debug ) |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 388 | |
| 389 | utilities.assert_equals( expect=main.TRUE, |
| 390 | actual=stepResult, |
| 391 | onpass="Successfully added flows", |
| 392 | onfail="Failed add flows" ) |
| 393 | |
| 394 | # Giving ONOS time to add the flow |
| 395 | time.sleep( main.addFlowSleep ) |
| 396 | |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 397 | main.checkingFlow.checkFlow() |
GlennRC | 956ea74 | 2015-11-05 16:14:15 -0800 | [diff] [blame] | 398 | |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 399 | main.step( "Send a packet to verify the flow is correct" ) |
| 400 | |
| 401 | main.log.info( "Constructing packet" ) |
| 402 | # No need for the MAC src dst |
| 403 | main.h1.buildEther( dst=main.h2.hostMac ) |
| 404 | main.h1.buildIP( src=main.h1.hostIp, dst=main.h2.hostIp ) |
| 405 | |
| 406 | main.log.info( "Starting filter on host2" ) |
| 407 | # Defaults to ip |
Jon Hall | fc95107 | 2017-05-24 15:55:34 -0700 | [diff] [blame] | 408 | main.h2.startFilter() |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 409 | |
| 410 | main.log.info( "Sending packet to host2" ) |
Jon Hall | fc95107 | 2017-05-24 15:55:34 -0700 | [diff] [blame] | 411 | main.h1.sendPacket() |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 412 | |
| 413 | main.log.info( "Checking filter for our packet" ) |
Jon Hall | fc95107 | 2017-05-24 15:55:34 -0700 | [diff] [blame] | 414 | stepResult = main.h2.checkFilter() |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 415 | if stepResult: |
Jon Hall | fc95107 | 2017-05-24 15:55:34 -0700 | [diff] [blame] | 416 | main.log.info( "Packet: %s" % main.h2.readPackets() ) |
| 417 | else: |
| 418 | main.h2.killFilter() |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 419 | |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 420 | utilities.assert_equals( expect=main.TRUE, |
| 421 | actual=stepResult, |
| 422 | onpass="Successfully sent a packet", |
| 423 | onfail="Failed to send a packet" ) |
| 424 | |
Jon Hall | fc95107 | 2017-05-24 15:55:34 -0700 | [diff] [blame] | 425 | def CASE1500( self, main ): |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 426 | """ |
| 427 | Add flow with IPv6 selector and verify the flow |
| 428 | """ |
| 429 | import json |
| 430 | import time |
| 431 | main.case( "Verify IPv6 selector is correctly compiled" ) |
| 432 | main.caseExplanation = "Install two flows with only IP selectors " + \ |
| 433 | "specified, then verify flows are added in ONOS, finally " + \ |
| 434 | "send a packet that only specifies the IP src and dst." |
| 435 | |
| 436 | main.step( "Add flows with IPv6 addresses as the only selectors" ) |
You Wang | dafb6e2 | 2018-01-22 17:01:00 -0800 | [diff] [blame] | 437 | for host in main.scapyHosts: |
| 438 | host.stopScapy() |
Jon Hall | fc95107 | 2017-05-24 15:55:34 -0700 | [diff] [blame] | 439 | host.startScapy() |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 440 | host.updateSelf( IPv6=True ) |
You Wang | dafb6e2 | 2018-01-22 17:01:00 -0800 | [diff] [blame] | 441 | main.log.debug( host.name ) |
| 442 | main.log.debug( host.hostIp ) |
| 443 | main.log.debug( host.hostMac ) |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 444 | |
| 445 | # Add a flow that connects host1 on port1 to host2 on port2 |
| 446 | # send output on port2 |
| 447 | # recieve input on port1 |
| 448 | egress = 6 |
| 449 | ingress = 5 |
| 450 | # IPv6 etherType = 0x86DD |
| 451 | ethType = main.params[ 'TEST' ][ 'ip6Type' ] |
| 452 | |
| 453 | # Add flows that connects host1 to host2 |
| 454 | main.log.info( "Add flow with port ingress 5 to port egress 6" ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 455 | stepResult = ctrl.REST.addFlow( deviceId=main.swDPID, |
| 456 | egressPort=egress, |
| 457 | ingressPort=ingress, |
| 458 | ethType=ethType, |
| 459 | ipSrc=( "IPV6_SRC", main.h5.hostIp + "/128" ), |
| 460 | ipDst=( "IPV6_DST", main.h6.hostIp + "/128" ), |
| 461 | debug=main.debug ) |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 462 | |
| 463 | utilities.assert_equals( expect=main.TRUE, |
| 464 | actual=stepResult, |
| 465 | onpass="Successfully added flows", |
| 466 | onfail="Failed add flows" ) |
| 467 | |
| 468 | # Giving ONOS time to add the flow |
| 469 | time.sleep( main.addFlowSleep ) |
| 470 | |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 471 | main.checkingFlow.checkFlow() |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 472 | |
| 473 | main.step( "Send a packet to verify the flow is correct" ) |
| 474 | |
| 475 | main.log.info( "Constructing packet" ) |
| 476 | # No need for the MAC src dst |
| 477 | main.h5.buildEther( dst=main.h6.hostMac ) |
| 478 | main.h5.buildIPv6( src=main.h5.hostIp, dst=main.h6.hostIp ) |
| 479 | |
| 480 | main.log.info( "Starting filter on host6" ) |
| 481 | # Defaults to ip |
| 482 | main.h6.startFilter( pktFilter="ip6" ) |
| 483 | main.log.info( "Sending packet to host6" ) |
Jon Hall | fc95107 | 2017-05-24 15:55:34 -0700 | [diff] [blame] | 484 | main.h5.sendPacket() |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 485 | |
| 486 | main.log.info( "Checking filter for our packet" ) |
Jon Hall | fc95107 | 2017-05-24 15:55:34 -0700 | [diff] [blame] | 487 | stepResult = main.h6.checkFilter() |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 488 | if stepResult: |
Jon Hall | fc95107 | 2017-05-24 15:55:34 -0700 | [diff] [blame] | 489 | main.log.info( "Packet: %s" % main.h6.readPackets() ) |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 490 | else: |
Jon Hall | fc95107 | 2017-05-24 15:55:34 -0700 | [diff] [blame] | 491 | main.h6.killFilter() |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 492 | |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 493 | utilities.assert_equals( expect=main.TRUE, |
| 494 | actual=stepResult, |
| 495 | onpass="Successfully sent a packet", |
| 496 | onfail="Failed to send a packet" ) |
| 497 | |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 498 | def CASE1100( self, main ): |
Jon Hall | fc95107 | 2017-05-24 15:55:34 -0700 | [diff] [blame] | 499 | """ |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 500 | Add flow with VLAN selector and verify the flow |
Jon Hall | fc95107 | 2017-05-24 15:55:34 -0700 | [diff] [blame] | 501 | """ |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 502 | import json |
| 503 | import time |
| 504 | |
| 505 | main.case( "Verify VLAN selector is correctly compiled" ) |
| 506 | main.caseExplanation = "Install one flow with only the VLAN selector " +\ |
Jon Hall | fc95107 | 2017-05-24 15:55:34 -0700 | [diff] [blame] | 507 | "specified, then verify the flow is added in ONOS, and finally " +\ |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 508 | "broadcast a packet with the correct VLAN tag." |
| 509 | |
You Wang | dafb6e2 | 2018-01-22 17:01:00 -0800 | [diff] [blame] | 510 | for host in main.scapyHosts: |
| 511 | host.stopScapy() |
Jon Hall | fc95107 | 2017-05-24 15:55:34 -0700 | [diff] [blame] | 512 | host.startScapy() |
| 513 | host.updateSelf() |
You Wang | dafb6e2 | 2018-01-22 17:01:00 -0800 | [diff] [blame] | 514 | main.log.debug( host.name ) |
| 515 | main.log.debug( host.hostIp ) |
| 516 | main.log.debug( host.hostMac ) |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 517 | |
| 518 | main.step( "Add a flow with the VLAN tag as the only selector" ) |
| 519 | |
| 520 | # Add flows that connects the two vlan hosts h3 and h4 |
| 521 | # Host 3 is on port 3 and host 4 is on port 4 |
| 522 | vlan = main.params[ 'TEST' ][ 'vlan' ] |
| 523 | egress = 4 |
| 524 | ingress = 3 |
| 525 | # VLAN ethType = 0x8100 |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 526 | ethType = main.params[ 'TEST' ][ 'vlanType' ] |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 527 | |
| 528 | # Add only one flow because we don't need a response |
| 529 | main.log.info( "Add flow with port ingress 1 to port egress 2" ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 530 | stepResult = ctrl.REST.addFlow( deviceId=main.swDPID, |
| 531 | egressPort=egress, |
| 532 | ingressPort=ingress, |
| 533 | ethType=ethType, |
| 534 | vlan=vlan, |
| 535 | debug=main.debug ) |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 536 | |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 537 | utilities.assert_equals( expect=main.TRUE, |
| 538 | actual=stepResult, |
| 539 | onpass="Successfully added flow", |
| 540 | onfail="Failed add flows" ) |
| 541 | |
| 542 | # Giving ONOS time to add the flows |
| 543 | time.sleep( main.addFlowSleep ) |
| 544 | |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 545 | main.checkingFlow.checkFlow() |
GlennRC | 956ea74 | 2015-11-05 16:14:15 -0800 | [diff] [blame] | 546 | |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 547 | main.step( "Send a packet to verify the flow are correct" ) |
| 548 | |
| 549 | # The receiving interface |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 550 | recIface = "{}-eth0.{}".format( main.h4.name, vlan ) |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 551 | main.log.info( "Starting filter on host2" ) |
| 552 | # 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] | 553 | main.h4.startFilter( ifaceName=recIface, pktFilter="" ) |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 554 | |
| 555 | # Broadcast the packet on the vlan interface. We only care if the flow forwards |
| 556 | # 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] | 557 | sendIface = "{}-eth0.{}".format( main.h3.name, vlan ) |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 558 | main.log.info( "Broadcasting the packet with a vlan tag" ) |
GlennRC | 956ea74 | 2015-11-05 16:14:15 -0800 | [diff] [blame] | 559 | main.h3.sendPacket( iface=sendIface, |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 560 | packet="Ether()/Dot1Q(vlan={})".format( vlan ) ) |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 561 | |
| 562 | main.log.info( "Checking filter for our packet" ) |
Jon Hall | fc95107 | 2017-05-24 15:55:34 -0700 | [diff] [blame] | 563 | stepResult = main.h4.checkFilter() |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 564 | if stepResult: |
Jon Hall | fc95107 | 2017-05-24 15:55:34 -0700 | [diff] [blame] | 565 | main.log.info( "Packet: %s" % main.h4.readPackets() ) |
| 566 | else: |
| 567 | main.h4.killFilter() |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 568 | |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 569 | utilities.assert_equals( expect=main.TRUE, |
| 570 | actual=stepResult, |
| 571 | onpass="Successfully sent a packet", |
| 572 | onfail="Failed to send a packet" ) |
GlennRC | 6844994 | 2015-10-16 16:03:12 -0700 | [diff] [blame] | 573 | |
GlennRC | 956ea74 | 2015-11-05 16:14:15 -0800 | [diff] [blame] | 574 | def CASE1300( self, main ): |
Jon Hall | fc95107 | 2017-05-24 15:55:34 -0700 | [diff] [blame] | 575 | """ |
GlennRC | 956ea74 | 2015-11-05 16:14:15 -0800 | [diff] [blame] | 576 | Add flows with MPLS selector and verify the flows |
Jon Hall | fc95107 | 2017-05-24 15:55:34 -0700 | [diff] [blame] | 577 | """ |
GlennRC | 956ea74 | 2015-11-05 16:14:15 -0800 | [diff] [blame] | 578 | import json |
| 579 | import time |
| 580 | |
| 581 | main.case( "Verify the MPLS selector is correctly compiled on the flow." ) |
| 582 | main.caseExplanation = "Install one flow with an MPLS selector, " +\ |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 583 | "verify the flow is added in ONOS, and finally " +\ |
GlennRC | 956ea74 | 2015-11-05 16:14:15 -0800 | [diff] [blame] | 584 | "send a packet via scapy that has a MPLS label." |
| 585 | |
| 586 | main.step( "Add a flow with a MPLS selector" ) |
You Wang | dafb6e2 | 2018-01-22 17:01:00 -0800 | [diff] [blame] | 587 | for host in main.scapyHosts: |
| 588 | host.stopScapy() |
GlennRC | 956ea74 | 2015-11-05 16:14:15 -0800 | [diff] [blame] | 589 | host.startScapy( main.dependencyPath ) |
Jon Hall | fc95107 | 2017-05-24 15:55:34 -0700 | [diff] [blame] | 590 | host.updateSelf() |
You Wang | dafb6e2 | 2018-01-22 17:01:00 -0800 | [diff] [blame] | 591 | main.log.debug( host.name ) |
| 592 | main.log.debug( host.hostIp ) |
| 593 | main.log.debug( host.hostMac ) |
| 594 | |
| 595 | ctrl = main.Cluster.active( 0 ) |
GlennRC | 956ea74 | 2015-11-05 16:14:15 -0800 | [diff] [blame] | 596 | |
| 597 | # ports |
| 598 | egress = 2 |
| 599 | ingress = 1 |
| 600 | # MPLS etherType |
| 601 | ethType = main.params[ 'TEST' ][ 'mplsType' ] |
| 602 | # MPLS label |
| 603 | mplsLabel = main.params[ 'TEST' ][ 'mpls' ] |
| 604 | |
| 605 | # Add a flow that connects host1 on port1 to host2 on port2 |
| 606 | main.log.info( "Adding flow with MPLS selector" ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 607 | stepResult = ctrl.REST.addFlow( deviceId=main.swDPID, |
| 608 | egressPort=egress, |
| 609 | ingressPort=ingress, |
| 610 | ethType=ethType, |
| 611 | mpls=mplsLabel, |
| 612 | debug=main.debug ) |
GlennRC | 956ea74 | 2015-11-05 16:14:15 -0800 | [diff] [blame] | 613 | |
| 614 | utilities.assert_equals( expect=main.TRUE, |
| 615 | actual=stepResult, |
| 616 | onpass="Successfully added flow", |
| 617 | onfail="Failed add flow" ) |
| 618 | |
| 619 | # Giving ONOS time to add the flow |
| 620 | time.sleep( main.addFlowSleep ) |
| 621 | |
| 622 | main.step( "Check flow is in the ADDED state" ) |
| 623 | |
| 624 | main.log.info( "Get the flows from ONOS" ) |
Jeremy | 8616099 | 2016-04-11 10:05:53 -0700 | [diff] [blame] | 625 | try: |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 626 | flows = json.loads( ctrl.REST.flows() ) |
GlennRC | 956ea74 | 2015-11-05 16:14:15 -0800 | [diff] [blame] | 627 | |
Jeremy | 8616099 | 2016-04-11 10:05:53 -0700 | [diff] [blame] | 628 | stepResult = main.TRUE |
| 629 | for f in flows: |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 630 | if "rest" in f.get( "appId" ): |
| 631 | if "ADDED" not in f.get( "state" ): |
Jeremy | 8616099 | 2016-04-11 10:05:53 -0700 | [diff] [blame] | 632 | stepResult = main.FALSE |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 633 | 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] | 634 | except TypeError: |
| 635 | main.log.error( "No Flows found by the REST API" ) |
| 636 | stepResult = main.FALSE |
| 637 | except ValueError: |
| 638 | main.log.error( "Problem getting Flows state from REST API. Exiting test" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 639 | main.cleanAndExit() |
GlennRC | 956ea74 | 2015-11-05 16:14:15 -0800 | [diff] [blame] | 640 | |
| 641 | utilities.assert_equals( expect=main.TRUE, |
| 642 | actual=stepResult, |
| 643 | onpass="All flows are in the ADDED state", |
| 644 | onfail="All flows are NOT in the ADDED state" ) |
| 645 | |
| 646 | main.step( "Check flows are in Mininet's flow table" ) |
| 647 | |
| 648 | # get the flow IDs that were added through rest |
| 649 | main.log.info( "Getting the flow IDs from ONOS" ) |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 650 | 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] | 651 | # convert the flowIDs to ints then hex and finally back to strings |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 652 | flowIds = [ str( hex( int( x ) ) ) for x in flowIds ] |
| 653 | main.log.info( "ONOS flow IDs: {}".format( flowIds ) ) |
GlennRC | 956ea74 | 2015-11-05 16:14:15 -0800 | [diff] [blame] | 654 | |
| 655 | stepResult = main.Mininet1.checkFlowId( "s1", flowIds, debug=True ) |
| 656 | |
| 657 | utilities.assert_equals( expect=main.TRUE, |
| 658 | actual=stepResult, |
| 659 | onpass="All flows are in mininet", |
| 660 | onfail="All flows are NOT in mininet" ) |
| 661 | |
| 662 | main.step( "Send a packet to verify the flow is correct" ) |
| 663 | |
| 664 | main.log.info( "Starting filter on host2" ) |
| 665 | main.h2.startFilter( pktFilter="mpls" ) |
| 666 | |
| 667 | main.log.info( "Constructing packet" ) |
| 668 | main.log.info( "Sending packet to host2" ) |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 669 | main.h1.sendPacket( packet='Ether()/MPLS(label={})'.format( mplsLabel ) ) |
GlennRC | 956ea74 | 2015-11-05 16:14:15 -0800 | [diff] [blame] | 670 | |
| 671 | main.log.info( "Checking filter for our packet" ) |
Jon Hall | fc95107 | 2017-05-24 15:55:34 -0700 | [diff] [blame] | 672 | stepResult = main.h2.checkFilter() |
GlennRC | 956ea74 | 2015-11-05 16:14:15 -0800 | [diff] [blame] | 673 | if stepResult: |
Jon Hall | fc95107 | 2017-05-24 15:55:34 -0700 | [diff] [blame] | 674 | main.log.info( "Packet: %s" % main.h2.readPackets() ) |
| 675 | else: |
| 676 | main.h2.killFilter() |
GlennRC | 956ea74 | 2015-11-05 16:14:15 -0800 | [diff] [blame] | 677 | |
GlennRC | 956ea74 | 2015-11-05 16:14:15 -0800 | [diff] [blame] | 678 | utilities.assert_equals( expect=main.TRUE, |
| 679 | actual=stepResult, |
| 680 | onpass="Successfully sent a packet", |
| 681 | onfail="Failed to send a packet" ) |
| 682 | |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 683 | def CASE1700( self, main ): |
Jon Hall | fc95107 | 2017-05-24 15:55:34 -0700 | [diff] [blame] | 684 | """ |
GlennRC | 956ea74 | 2015-11-05 16:14:15 -0800 | [diff] [blame] | 685 | Add flows with a TCP selector and verify the flow |
Jon Hall | fc95107 | 2017-05-24 15:55:34 -0700 | [diff] [blame] | 686 | """ |
GlennRC | 956ea74 | 2015-11-05 16:14:15 -0800 | [diff] [blame] | 687 | import json |
| 688 | import time |
| 689 | |
| 690 | main.case( "Verify the TCP selector is correctly compiled on the flow" ) |
| 691 | main.caseExplanation = "Install a flow with only the TCP selector " +\ |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 692 | "specified, verify the flow is added in ONOS, and finally " +\ |
GlennRC | 956ea74 | 2015-11-05 16:14:15 -0800 | [diff] [blame] | 693 | "send a TCP packet to verify the TCP selector is compiled correctly." |
| 694 | |
| 695 | main.step( "Add a flow with a TCP selector" ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 696 | ctrl = main.Cluster.active( 0 ) |
You Wang | dafb6e2 | 2018-01-22 17:01:00 -0800 | [diff] [blame] | 697 | for host in main.scapyHosts: |
| 698 | host.stopScapy() |
Jon Hall | fc95107 | 2017-05-24 15:55:34 -0700 | [diff] [blame] | 699 | host.startScapy() |
| 700 | host.updateSelf() |
You Wang | dafb6e2 | 2018-01-22 17:01:00 -0800 | [diff] [blame] | 701 | main.log.debug( host.name ) |
| 702 | main.log.debug( host.hostIp ) |
| 703 | main.log.debug( host.hostMac ) |
GlennRC | 956ea74 | 2015-11-05 16:14:15 -0800 | [diff] [blame] | 704 | |
| 705 | # Add a flow that connects host1 on port1 to host2 on port2 |
| 706 | egress = 2 |
| 707 | ingress = 1 |
| 708 | # IPv4 etherType |
| 709 | ethType = main.params[ 'TEST' ][ 'ip4Type' ] |
| 710 | # IP protocol |
| 711 | ipProto = main.params[ 'TEST' ][ 'tcpProto' ] |
| 712 | # TCP port destination |
| 713 | tcpDst = main.params[ 'TEST' ][ 'tcpDst' ] |
| 714 | |
| 715 | main.log.info( "Add a flow that connects host1 on port1 to host2 on port2" ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 716 | stepResult = ctrl.REST.addFlow( deviceId=main.swDPID, |
| 717 | egressPort=egress, |
| 718 | ingressPort=ingress, |
| 719 | ethType=ethType, |
| 720 | ipProto=ipProto, |
| 721 | tcpDst=tcpDst, |
| 722 | debug=main.debug ) |
GlennRC | 956ea74 | 2015-11-05 16:14:15 -0800 | [diff] [blame] | 723 | |
| 724 | utilities.assert_equals( expect=main.TRUE, |
| 725 | actual=stepResult, |
| 726 | onpass="Successfully added flows", |
| 727 | onfail="Failed add flows" ) |
| 728 | |
| 729 | # Giving ONOS time to add the flow |
| 730 | time.sleep( main.addFlowSleep ) |
| 731 | |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 732 | main.checkingFlow.checkFlow() |
GlennRC | 956ea74 | 2015-11-05 16:14:15 -0800 | [diff] [blame] | 733 | |
| 734 | main.step( "Send a packet to verify the flow is correct" ) |
| 735 | |
| 736 | main.log.info( "Constructing packet" ) |
| 737 | # No need for the MAC src dst |
| 738 | main.h1.buildEther( dst=main.h2.hostMac ) |
| 739 | main.h1.buildIP( dst=main.h2.hostIp ) |
| 740 | main.h1.buildTCP( dport=tcpDst ) |
| 741 | |
| 742 | main.log.info( "Starting filter on host2" ) |
| 743 | # Defaults to ip |
| 744 | main.h2.startFilter( pktFilter="tcp" ) |
| 745 | |
| 746 | main.log.info( "Sending packet to host2" ) |
Jon Hall | fc95107 | 2017-05-24 15:55:34 -0700 | [diff] [blame] | 747 | main.h1.sendPacket() |
GlennRC | 956ea74 | 2015-11-05 16:14:15 -0800 | [diff] [blame] | 748 | |
| 749 | main.log.info( "Checking filter for our packet" ) |
Jon Hall | fc95107 | 2017-05-24 15:55:34 -0700 | [diff] [blame] | 750 | stepResult = main.h2.checkFilter() |
GlennRC | 956ea74 | 2015-11-05 16:14:15 -0800 | [diff] [blame] | 751 | if stepResult: |
Jon Hall | fc95107 | 2017-05-24 15:55:34 -0700 | [diff] [blame] | 752 | main.log.info( "Packet: %s" % main.h2.readPackets() ) |
| 753 | else: |
| 754 | main.h2.killFilter() |
GlennRC | 956ea74 | 2015-11-05 16:14:15 -0800 | [diff] [blame] | 755 | |
GlennRC | 956ea74 | 2015-11-05 16:14:15 -0800 | [diff] [blame] | 756 | utilities.assert_equals( expect=main.TRUE, |
| 757 | actual=stepResult, |
| 758 | onpass="Successfully sent a packet", |
| 759 | onfail="Failed to send a packet" ) |
| 760 | |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 761 | def CASE1600( self, main ): |
Jon Hall | fc95107 | 2017-05-24 15:55:34 -0700 | [diff] [blame] | 762 | """ |
GlennRC | 956ea74 | 2015-11-05 16:14:15 -0800 | [diff] [blame] | 763 | Add flows with a UDP selector and verify the flow |
Jon Hall | fc95107 | 2017-05-24 15:55:34 -0700 | [diff] [blame] | 764 | """ |
GlennRC | 956ea74 | 2015-11-05 16:14:15 -0800 | [diff] [blame] | 765 | import json |
| 766 | import time |
| 767 | |
| 768 | main.case( "Verify the UDP selector is correctly compiled on the flow" ) |
| 769 | main.caseExplanation = "Install a flow with only the UDP selector " +\ |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 770 | "specified, verify the flow is added in ONOS, and finally " +\ |
GlennRC | 956ea74 | 2015-11-05 16:14:15 -0800 | [diff] [blame] | 771 | "send a UDP packet to verify the UDP selector is compiled correctly." |
| 772 | |
| 773 | main.step( "Add a flow with a UDP selector" ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 774 | ctrl = main.Cluster.active( 0 ) |
You Wang | dafb6e2 | 2018-01-22 17:01:00 -0800 | [diff] [blame] | 775 | for host in main.scapyHosts: |
| 776 | host.stopScapy() |
Jon Hall | fc95107 | 2017-05-24 15:55:34 -0700 | [diff] [blame] | 777 | host.startScapy() |
| 778 | host.updateSelf() |
You Wang | dafb6e2 | 2018-01-22 17:01:00 -0800 | [diff] [blame] | 779 | main.log.debug( host.name ) |
| 780 | main.log.debug( host.hostIp ) |
| 781 | main.log.debug( host.hostMac ) |
GlennRC | 956ea74 | 2015-11-05 16:14:15 -0800 | [diff] [blame] | 782 | |
| 783 | # Add a flow that connects host1 on port1 to host2 on port2 |
| 784 | egress = 2 |
| 785 | ingress = 1 |
| 786 | # IPv4 etherType |
| 787 | ethType = main.params[ 'TEST' ][ 'ip4Type' ] |
| 788 | # IP protocol |
| 789 | ipProto = main.params[ 'TEST' ][ 'udpProto' ] |
| 790 | # UDP port destination |
| 791 | udpDst = main.params[ 'TEST' ][ 'udpDst' ] |
| 792 | |
| 793 | main.log.info( "Add a flow that connects host1 on port1 to host2 on port2" ) |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 794 | stepResult = ctrl.REST.addFlow( deviceId=main.swDPID, |
GlennRC | 956ea74 | 2015-11-05 16:14:15 -0800 | [diff] [blame] | 795 | egressPort=egress, |
| 796 | ingressPort=ingress, |
| 797 | ethType=ethType, |
| 798 | ipProto=ipProto, |
| 799 | udpDst=udpDst, |
| 800 | debug=main.debug ) |
| 801 | |
| 802 | utilities.assert_equals( expect=main.TRUE, |
| 803 | actual=stepResult, |
| 804 | onpass="Successfully added flows", |
| 805 | onfail="Failed add flows" ) |
| 806 | |
| 807 | # Giving ONOS time to add the flow |
| 808 | time.sleep( main.addFlowSleep ) |
| 809 | |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 810 | main.checkingFlow.checkFlow() |
GlennRC | 956ea74 | 2015-11-05 16:14:15 -0800 | [diff] [blame] | 811 | |
| 812 | main.step( "Send a packet to verify the flow is correct" ) |
| 813 | |
| 814 | main.log.info( "Constructing packet" ) |
| 815 | # No need for the MAC src dst |
| 816 | main.h1.buildEther( dst=main.h2.hostMac ) |
| 817 | main.h1.buildIP( dst=main.h2.hostIp ) |
| 818 | main.h1.buildUDP( dport=udpDst ) |
| 819 | |
| 820 | main.log.info( "Starting filter on host2" ) |
| 821 | # Defaults to ip |
| 822 | main.h2.startFilter( pktFilter="udp" ) |
| 823 | |
| 824 | main.log.info( "Sending packet to host2" ) |
Jon Hall | fc95107 | 2017-05-24 15:55:34 -0700 | [diff] [blame] | 825 | main.h1.sendPacket() |
GlennRC | 956ea74 | 2015-11-05 16:14:15 -0800 | [diff] [blame] | 826 | |
| 827 | main.log.info( "Checking filter for our packet" ) |
Jon Hall | fc95107 | 2017-05-24 15:55:34 -0700 | [diff] [blame] | 828 | stepResult = main.h2.checkFilter() |
GlennRC | 956ea74 | 2015-11-05 16:14:15 -0800 | [diff] [blame] | 829 | if stepResult: |
Jon Hall | fc95107 | 2017-05-24 15:55:34 -0700 | [diff] [blame] | 830 | main.log.info( "Packet: %s" % main.h2.readPackets() ) |
| 831 | else: |
| 832 | main.h2.killFilter() |
GlennRC | 956ea74 | 2015-11-05 16:14:15 -0800 | [diff] [blame] | 833 | |
GlennRC | 956ea74 | 2015-11-05 16:14:15 -0800 | [diff] [blame] | 834 | utilities.assert_equals( expect=main.TRUE, |
| 835 | actual=stepResult, |
| 836 | onpass="Successfully sent a packet", |
| 837 | onfail="Failed to send a packet" ) |
| 838 | |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 839 | def CASE1900( self, main ): |
Jon Hall | fc95107 | 2017-05-24 15:55:34 -0700 | [diff] [blame] | 840 | """ |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 841 | Add flows with a ICMPv4 selector and verify the flow |
Jon Hall | fc95107 | 2017-05-24 15:55:34 -0700 | [diff] [blame] | 842 | """ |
GlennRC | 956ea74 | 2015-11-05 16:14:15 -0800 | [diff] [blame] | 843 | import json |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 844 | import time |
GlennRC | 956ea74 | 2015-11-05 16:14:15 -0800 | [diff] [blame] | 845 | |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 846 | main.case( "Verify the ICMPv4 selector is correctly compiled on the flow" ) |
| 847 | main.caseExplanation = "Install a flow with only the ICMPv4 selector " +\ |
| 848 | "specified, verify the flow is added in ONOS, and finally " +\ |
| 849 | "send a IMCPv4 packet to verify the ICMPv4 selector is compiled correctly." |
GlennRC | 956ea74 | 2015-11-05 16:14:15 -0800 | [diff] [blame] | 850 | |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 851 | main.step( "Add a flow with a ICMPv4 selector" ) |
| 852 | |
You Wang | dafb6e2 | 2018-01-22 17:01:00 -0800 | [diff] [blame] | 853 | for host in main.scapyHosts: |
| 854 | host.stopScapy() |
Jon Hall | fc95107 | 2017-05-24 15:55:34 -0700 | [diff] [blame] | 855 | host.startScapy() |
| 856 | host.updateSelf() |
You Wang | dafb6e2 | 2018-01-22 17:01:00 -0800 | [diff] [blame] | 857 | main.log.debug( host.name ) |
| 858 | main.log.debug( host.hostIp ) |
| 859 | main.log.debug( host.hostMac ) |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 860 | |
| 861 | # Add a flow that connects host1 on port1 to host2 on port2 |
| 862 | egress = 2 |
| 863 | ingress = 1 |
| 864 | # IPv4 etherType |
| 865 | ethType = main.params[ 'TEST' ][ 'ip4Type' ] |
| 866 | # IP protocol |
| 867 | ipProto = main.params[ 'TEST' ][ 'icmpProto' ] |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 868 | ctrl = main.Cluster.active( 0 ) |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 869 | main.log.info( "Add a flow that connects host1 on port1 to host2 on port2" ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 870 | stepResult = ctrl.REST.addFlow( deviceId=main.swDPID, |
| 871 | egressPort=egress, |
| 872 | ingressPort=ingress, |
| 873 | ethType=ethType, |
| 874 | ipProto=ipProto, |
| 875 | debug=main.debug ) |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 876 | |
| 877 | utilities.assert_equals( expect=main.TRUE, |
| 878 | actual=stepResult, |
| 879 | onpass="Successfully added flows", |
| 880 | onfail="Failed add flows" ) |
| 881 | |
| 882 | # Giving ONOS time to add the flow |
| 883 | time.sleep( main.addFlowSleep ) |
| 884 | |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 885 | main.checkingFlow.checkFlow() |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 886 | |
| 887 | main.step( "Send a packet to verify the flow is correct" ) |
| 888 | |
| 889 | main.log.info( "Constructing packet" ) |
| 890 | # No need for the MAC src dst |
| 891 | main.h1.buildEther( dst=main.h2.hostMac ) |
| 892 | main.h1.buildIP( dst=main.h2.hostIp ) |
Jon Hall | fc95107 | 2017-05-24 15:55:34 -0700 | [diff] [blame] | 893 | main.h1.buildICMP() |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 894 | |
| 895 | main.log.info( "Starting filter on host2" ) |
| 896 | # Defaults to ip |
| 897 | main.h2.startFilter( pktFilter="icmp" ) |
| 898 | |
| 899 | main.log.info( "Sending packet to host2" ) |
Jon Hall | fc95107 | 2017-05-24 15:55:34 -0700 | [diff] [blame] | 900 | main.h1.sendPacket() |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 901 | |
| 902 | main.log.info( "Checking filter for our packet" ) |
Jon Hall | fc95107 | 2017-05-24 15:55:34 -0700 | [diff] [blame] | 903 | stepResult = main.h2.checkFilter() |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 904 | if stepResult: |
Jon Hall | fc95107 | 2017-05-24 15:55:34 -0700 | [diff] [blame] | 905 | main.log.info( "Packet: %s" % main.h2.readPackets() ) |
| 906 | else: |
| 907 | main.h2.killFilter() |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 908 | |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 909 | utilities.assert_equals( expect=main.TRUE, |
| 910 | actual=stepResult, |
| 911 | onpass="Successfully sent a packet", |
| 912 | onfail="Failed to send a packet" ) |
| 913 | |
| 914 | def CASE2000( self, main ): |
Jon Hall | fc95107 | 2017-05-24 15:55:34 -0700 | [diff] [blame] | 915 | """ |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 916 | Add flows with a ICMPv6 selector and verify the flow |
Jon Hall | fc95107 | 2017-05-24 15:55:34 -0700 | [diff] [blame] | 917 | """ |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 918 | import json |
| 919 | import time |
| 920 | |
| 921 | main.case( "Verify the ICMPv6 selector is correctly compiled on the flow" ) |
| 922 | main.caseExplanation = "Install a flow with only the ICMPv6 selector " +\ |
| 923 | "specified, verify the flow is added in ONOS, and finally " +\ |
| 924 | "send a IMCPv6 packet to verify the ICMPv6 selector is compiled correctly." |
| 925 | |
| 926 | main.step( "Add a flow with a ICMPv6 selector" ) |
| 927 | |
You Wang | dafb6e2 | 2018-01-22 17:01:00 -0800 | [diff] [blame] | 928 | for host in main.scapyHosts: |
| 929 | host.stopScapy() |
Jon Hall | fc95107 | 2017-05-24 15:55:34 -0700 | [diff] [blame] | 930 | host.startScapy() |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 931 | host.updateSelf( IPv6=True ) |
You Wang | dafb6e2 | 2018-01-22 17:01:00 -0800 | [diff] [blame] | 932 | main.log.debug( host.name ) |
| 933 | main.log.debug( host.hostIp ) |
| 934 | main.log.debug( host.hostMac ) |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 935 | |
| 936 | # Add a flow that connects host1 on port1 to host2 on port2 |
Jon Hall | fc95107 | 2017-05-24 15:55:34 -0700 | [diff] [blame] | 937 | egress = 6 |
| 938 | ingress = 5 |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 939 | # IPv6 etherType |
| 940 | ethType = main.params[ 'TEST' ][ 'ip6Type' ] |
| 941 | # IP protocol |
| 942 | ipProto = main.params[ 'TEST' ][ 'icmp6Proto' ] |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 943 | ctrl = main.Cluster.active( 0 ) |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 944 | main.log.info( "Add a flow that connects host1 on port1 to host2 on port2" ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 945 | stepResult = ctrl.REST.addFlow( deviceId=main.swDPID, |
| 946 | egressPort=egress, |
| 947 | ingressPort=ingress, |
| 948 | ethType=ethType, |
| 949 | ipProto=ipProto, |
| 950 | debug=main.debug ) |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 951 | |
| 952 | utilities.assert_equals( expect=main.TRUE, |
| 953 | actual=stepResult, |
| 954 | onpass="Successfully added flows", |
| 955 | onfail="Failed add flows" ) |
| 956 | |
| 957 | # Giving ONOS time to add the flow |
| 958 | time.sleep( main.addFlowSleep ) |
| 959 | |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 960 | main.checkingFlow.checkFlow() |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 961 | |
| 962 | main.step( "Send a packet to verify the flow is correct" ) |
| 963 | |
| 964 | main.log.info( "Constructing packet" ) |
| 965 | # No need for the MAC src dst |
| 966 | main.h5.buildEther( dst=main.h6.hostMac ) |
| 967 | main.h5.buildIPv6( dst=main.h6.hostIp ) |
| 968 | main.h5.buildICMP( ipVersion=6 ) |
| 969 | |
| 970 | main.log.info( "Starting filter on host2" ) |
| 971 | # Defaults to ip |
| 972 | main.h6.startFilter( pktFilter="icmp6" ) |
| 973 | |
| 974 | main.log.info( "Sending packet to host2" ) |
Jon Hall | fc95107 | 2017-05-24 15:55:34 -0700 | [diff] [blame] | 975 | main.h5.sendPacket() |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 976 | |
| 977 | main.log.info( "Checking filter for our packet" ) |
Jon Hall | fc95107 | 2017-05-24 15:55:34 -0700 | [diff] [blame] | 978 | stepResult = main.h6.checkFilter() |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 979 | if stepResult: |
Jon Hall | fc95107 | 2017-05-24 15:55:34 -0700 | [diff] [blame] | 980 | main.log.info( "Packet: %s" % main.h6.readPackets() ) |
| 981 | else: |
| 982 | main.h6.killFilter() |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 983 | |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 984 | utilities.assert_equals( expect=main.TRUE, |
| 985 | actual=stepResult, |
| 986 | onpass="Successfully sent a packet", |
| 987 | onfail="Failed to send a packet" ) |
| 988 | |
| 989 | def CASE3000( self, main ): |
Jon Hall | fc95107 | 2017-05-24 15:55:34 -0700 | [diff] [blame] | 990 | """ |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 991 | Delete flow |
Jon Hall | fc95107 | 2017-05-24 15:55:34 -0700 | [diff] [blame] | 992 | """ |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 993 | import json |
| 994 | |
| 995 | main.case( "Delete flows that were added through rest" ) |
| 996 | main.step( "Deleting flows" ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 997 | ctrl = main.Cluster.active( 0 ) |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 998 | main.log.info( "Getting flows" ) |
| 999 | try: |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 1000 | flows = json.loads( ctrl.REST.flows() ) |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 1001 | |
| 1002 | stepResult = main.TRUE |
| 1003 | for f in flows: |
| 1004 | if "rest" in f.get( "appId" ): |
Jon Hall | fc95107 | 2017-05-24 15:55:34 -0700 | [diff] [blame] | 1005 | if main.debug: |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 1006 | main.log.debug( "Flow to be deleted:\n{}".format( ctrl.REST.pprint( f ) ) ) |
| 1007 | stepResult = stepResult and ctrl.REST.removeFlow( f.get( "deviceId" ), f.get( "id" ) ) |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 1008 | except TypeError: |
| 1009 | main.log.error( "No Flows found by the REST API" ) |
| 1010 | stepResult = main.FALSE |
| 1011 | except ValueError: |
| 1012 | main.log.error( "Problem getting Flows state from REST API. Exiting test" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 1013 | main.cleanAndExit() |
GlennRC | 956ea74 | 2015-11-05 16:14:15 -0800 | [diff] [blame] | 1014 | |
| 1015 | utilities.assert_equals( expect=main.TRUE, |
| 1016 | actual=stepResult, |
| 1017 | onpass="Successfully deleting flows", |
| 1018 | onfail="Failed to delete flows" ) |
| 1019 | |
| 1020 | time.sleep( main.delFlowSleep ) |
| 1021 | |
Jon Hall | fc95107 | 2017-05-24 15:55:34 -0700 | [diff] [blame] | 1022 | def CASE1200( self, main ): |
| 1023 | """ |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 1024 | Add flows with a ARP selector and verify the flow |
Jon Hall | fc95107 | 2017-05-24 15:55:34 -0700 | [diff] [blame] | 1025 | """ |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 1026 | import json |
| 1027 | import time |
| 1028 | |
| 1029 | main.case( "Verify flow IP selectors are correctly compiled" ) |
| 1030 | main.caseExplanation = "Install two flows with only IP selectors " + \ |
| 1031 | "specified, then verify flows are added in ONOS, finally " + \ |
| 1032 | "send a packet that only specifies the IP src and dst." |
| 1033 | |
| 1034 | main.step( "Add flows with ARP addresses as the only selectors" ) |
| 1035 | |
You Wang | dafb6e2 | 2018-01-22 17:01:00 -0800 | [diff] [blame] | 1036 | for host in main.scapyHosts: |
| 1037 | host.stopScapy() |
Jon Hall | fc95107 | 2017-05-24 15:55:34 -0700 | [diff] [blame] | 1038 | host.startScapy() |
| 1039 | host.updateSelf() |
You Wang | dafb6e2 | 2018-01-22 17:01:00 -0800 | [diff] [blame] | 1040 | main.log.debug( host.name ) |
| 1041 | main.log.debug( host.hostIp ) |
| 1042 | main.log.debug( host.hostMac ) |
| 1043 | |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 1044 | ctrl = main.Cluster.active( 0 ) |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 1045 | # Add a flow that connects host1 on port1 to host2 on port2 |
| 1046 | # send output on port2 |
| 1047 | # recieve input on port1 |
| 1048 | egress = 2 |
| 1049 | ingress = 1 |
| 1050 | # ARP etherType = 0x0806 |
| 1051 | ethType = main.params[ 'TEST' ][ 'arpType' ] |
| 1052 | |
| 1053 | # Add flows that connects host1 to host2 |
| 1054 | main.log.info( "Add flow with port ingress 1 to port egress 2" ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 1055 | stepResult = ctrl.REST.addFlow( deviceId=main.swDPID, |
| 1056 | egressPort=egress, |
| 1057 | ingressPort=ingress, |
| 1058 | ethType=ethType, |
| 1059 | priority=40001, |
| 1060 | debug=main.debug ) |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 1061 | |
| 1062 | utilities.assert_equals( expect=main.TRUE, |
| 1063 | actual=stepResult, |
| 1064 | onpass="Successfully added flows", |
| 1065 | onfail="Failed add flows" ) |
| 1066 | |
| 1067 | # Giving ONOS time to add the flow |
| 1068 | time.sleep( main.addFlowSleep ) |
| 1069 | |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 1070 | main.checkingFlow.checkFlow() |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 1071 | |
| 1072 | main.step( "Send a packet to verify the flow is correct" ) |
| 1073 | |
| 1074 | main.log.info( "Constructing packet" ) |
| 1075 | # No need for the MAC src dst |
| 1076 | main.h1.buildEther( src=main.h1.hostMac, dst=main.h2.hostMac ) |
| 1077 | main.h1.buildARP( pdst=main.h2.hostIp ) |
| 1078 | |
| 1079 | main.log.info( "Starting filter on host2" ) |
| 1080 | # Defaults to ip |
| 1081 | main.h2.startFilter( pktFilter="arp" ) |
| 1082 | |
| 1083 | main.log.info( "Sending packet to host2" ) |
Jon Hall | fc95107 | 2017-05-24 15:55:34 -0700 | [diff] [blame] | 1084 | main.h1.sendPacket() |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 1085 | |
| 1086 | main.log.info( "Checking filter for our packet" ) |
Jon Hall | fc95107 | 2017-05-24 15:55:34 -0700 | [diff] [blame] | 1087 | stepResult = main.h2.checkFilter() |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 1088 | if stepResult: |
Jon Hall | fc95107 | 2017-05-24 15:55:34 -0700 | [diff] [blame] | 1089 | main.log.info( "Packet: %s" % main.h2.readPackets() ) |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 1090 | else: |
Jon Hall | fc95107 | 2017-05-24 15:55:34 -0700 | [diff] [blame] | 1091 | main.h2.killFilter() |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 1092 | |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 1093 | utilities.assert_equals( expect=main.TRUE, |
| 1094 | actual=stepResult, |
| 1095 | onpass="Successfully sent a packet", |
| 1096 | onfail="Failed to send a packet" ) |
| 1097 | |
| 1098 | def CASE1800( self, main ): |
Jon Hall | fc95107 | 2017-05-24 15:55:34 -0700 | [diff] [blame] | 1099 | """ |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 1100 | Add flows with a SCTP selector and verify the flow |
Jon Hall | fc95107 | 2017-05-24 15:55:34 -0700 | [diff] [blame] | 1101 | """ |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 1102 | import json |
| 1103 | import time |
| 1104 | |
| 1105 | main.case( "Verify the UDP selector is correctly compiled on the flow" ) |
| 1106 | main.caseExplanation = "Install a flow with only the UDP selector " + \ |
| 1107 | "specified, verify the flow is added in ONOS, and finally " + \ |
| 1108 | "send a UDP packet to verify the UDP selector is compiled correctly." |
| 1109 | |
| 1110 | main.step( "Add a flow with a SCTP selector" ) |
| 1111 | |
You Wang | dafb6e2 | 2018-01-22 17:01:00 -0800 | [diff] [blame] | 1112 | for host in main.scapyHosts: |
| 1113 | host.stopScapy() |
Jon Hall | fc95107 | 2017-05-24 15:55:34 -0700 | [diff] [blame] | 1114 | host.startScapy() |
| 1115 | host.updateSelf() |
You Wang | dafb6e2 | 2018-01-22 17:01:00 -0800 | [diff] [blame] | 1116 | main.log.debug( host.name ) |
| 1117 | main.log.debug( host.hostIp ) |
| 1118 | main.log.debug( host.hostMac ) |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 1119 | |
| 1120 | # Add a flow that connects host1 on port1 to host2 on port2 |
| 1121 | egress = 2 |
| 1122 | ingress = 1 |
| 1123 | # IPv4 etherType |
| 1124 | ethType = main.params[ 'TEST' ][ 'ip4Type' ] |
| 1125 | # IP protocol |
| 1126 | ipProto = main.params[ 'TEST' ][ 'sctpProto' ] |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 1127 | ctrl = main.Cluster.active( 0 ) |
Jon Hall | fc95107 | 2017-05-24 15:55:34 -0700 | [diff] [blame] | 1128 | main.log.info( "Add a flow that connects host1 on port1 to host2 on port2" ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 1129 | stepResult = ctrl.REST.addFlow( deviceId=main.swDPID, |
| 1130 | egressPort=egress, |
| 1131 | ingressPort=ingress, |
| 1132 | ethType=ethType, |
| 1133 | ipProto=ipProto, |
| 1134 | debug=main.debug ) |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 1135 | |
| 1136 | utilities.assert_equals( expect=main.TRUE, |
| 1137 | actual=stepResult, |
| 1138 | onpass="Successfully added flows", |
| 1139 | onfail="Failed add flows" ) |
| 1140 | |
| 1141 | # Giving ONOS time to add the flow |
| 1142 | time.sleep( main.addFlowSleep ) |
| 1143 | |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 1144 | main.checkingFlow.checkFlow() |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 1145 | |
| 1146 | main.step( "Send a packet to verify the flow is correct" ) |
| 1147 | |
| 1148 | main.log.info( "Constructing packet" ) |
| 1149 | # No need for the MAC src dst |
| 1150 | main.h1.buildEther( dst=main.h2.hostMac ) |
| 1151 | main.h1.buildIP( dst=main.h2.hostIp ) |
Jon Hall | fc95107 | 2017-05-24 15:55:34 -0700 | [diff] [blame] | 1152 | main.h1.buildSCTP() |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 1153 | |
| 1154 | main.log.info( "Starting filter on host2" ) |
| 1155 | # Defaults to ip |
| 1156 | main.h2.startFilter( pktFilter="sctp" ) |
| 1157 | |
| 1158 | main.log.info( "Sending packet to host2" ) |
Jon Hall | fc95107 | 2017-05-24 15:55:34 -0700 | [diff] [blame] | 1159 | main.h1.sendPacket() |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 1160 | |
| 1161 | main.log.info( "Checking filter for our packet" ) |
Jon Hall | fc95107 | 2017-05-24 15:55:34 -0700 | [diff] [blame] | 1162 | stepResult = main.h2.checkFilter() |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 1163 | if stepResult: |
Jon Hall | fc95107 | 2017-05-24 15:55:34 -0700 | [diff] [blame] | 1164 | main.log.info( "Packet: %s" % main.h2.readPackets() ) |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 1165 | else: |
Jon Hall | fc95107 | 2017-05-24 15:55:34 -0700 | [diff] [blame] | 1166 | main.h2.killFilter() |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 1167 | |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 1168 | utilities.assert_equals( expect=main.TRUE, |
| 1169 | actual=stepResult, |
| 1170 | onpass="Successfully sent a packet", |
| 1171 | onfail="Failed to send a packet" ) |
| 1172 | |
GlennRC | 6844994 | 2015-10-16 16:03:12 -0700 | [diff] [blame] | 1173 | def CASE100( self, main ): |
Jon Hall | fc95107 | 2017-05-24 15:55:34 -0700 | [diff] [blame] | 1174 | """ |
GlennRC | 5147a42 | 2015-10-06 17:26:17 -0700 | [diff] [blame] | 1175 | Report errors/warnings/exceptions |
Jon Hall | fc95107 | 2017-05-24 15:55:34 -0700 | [diff] [blame] | 1176 | """ |
alison | e14d7b0 | 2016-07-06 10:31:51 -0700 | [diff] [blame] | 1177 | main.log.info( "Error report: \n" ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 1178 | main.ONOSbench.logReport( main.Cluster.active( 0 ).ipAddress, |
GlennRC | 5147a42 | 2015-10-06 17:26:17 -0700 | [diff] [blame] | 1179 | [ "INFO", |
| 1180 | "FOLLOWER", |
| 1181 | "WARN", |
| 1182 | "flow", |
| 1183 | "ERROR", |
| 1184 | "Except" ], |
GlennRC | 6844994 | 2015-10-16 16:03:12 -0700 | [diff] [blame] | 1185 | "s" ) |