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