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 2016 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 | """ |
kavitha Alagesan | 373e055 | 2016-11-22 05:22:05 +0530 | [diff] [blame] | 21 | class FUNCgroup: |
| 22 | |
| 23 | def __init__( self ): |
| 24 | self.default = '' |
| 25 | |
| 26 | def CASE1( self, main ): |
| 27 | import os |
| 28 | import imp |
kavitha Alagesan | 373e055 | 2016-11-22 05:22:05 +0530 | [diff] [blame] | 29 | """ |
| 30 | - Construct tests variables |
| 31 | - GIT ( optional ) |
| 32 | - Checkout ONOS master branch |
| 33 | - Pull latest ONOS code |
| 34 | - Building ONOS ( optional ) |
| 35 | - Install ONOS package |
| 36 | - Build ONOS package |
| 37 | """ |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 38 | try: |
| 39 | from tests.dependencies.ONOSSetup import ONOSSetup |
| 40 | main.testSetUp = ONOSSetup() |
| 41 | except ImportError: |
| 42 | main.log.error( "ONOSSetup not found. exiting the test" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 43 | main.cleanAndExit() |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 44 | main.testSetUp.envSetupDescription() |
| 45 | stepResult = main.FALSE |
kavitha Alagesan | 373e055 | 2016-11-22 05:22:05 +0530 | [diff] [blame] | 46 | |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 47 | try: |
| 48 | # Test variables |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 49 | main.cellName = main.params[ 'ENV' ][ 'cellName' ] |
| 50 | main.apps = main.params[ 'ENV' ][ 'cellApps' ] |
| 51 | main.ONOSport = main.params[ 'CTRL' ][ 'port' ] |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 52 | main.dependencyPath = main.testOnDirectory + \ |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 53 | main.params[ 'DEPENDENCY' ][ 'path' ] |
| 54 | wrapperFile1 = main.params[ 'DEPENDENCY' ][ 'wrapper1' ] |
| 55 | wrapperFile2 = main.params[ 'DEPENDENCY' ][ 'wrapper2' ] |
| 56 | main.topology = main.params[ 'DEPENDENCY' ][ 'topology' ] |
| 57 | bucket = main.params[ 'DEPENDENCY' ][ 'bucket' ] |
| 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.addGroupSleep = int( main.params[ 'SLEEP' ][ 'addGroup' ] ) |
| 63 | main.delGroupSleep = int( main.params[ 'SLEEP' ][ 'delGroup' ] ) |
| 64 | main.debug = main.params[ 'DEBUG' ] |
| 65 | main.swDPID = main.params[ 'TEST' ][ 'swDPID' ] |
| 66 | egressPort1 = main.params[ 'TEST' ][ 'egressPort1' ] |
| 67 | egressPort2 = main.params[ 'TEST' ][ 'egressPort2' ] |
| 68 | egressPort3 = main.params[ 'TEST' ][ 'egressPort3' ] |
| 69 | ingressPort = main.params[ 'TEST' ][ 'ingressPort' ] |
| 70 | appCookie = main.params[ 'TEST' ][ 'appCookie' ] |
| 71 | type1 = main.params[ 'TEST' ][ 'type1' ] |
| 72 | type2 = main.params[ 'TEST' ][ 'type2' ] |
| 73 | groupId = main.params[ 'TEST' ][ 'groupId' ] |
| 74 | priority = main.params[ 'TEST' ][ 'priority' ] |
| 75 | deviceId = main.params[ 'TEST' ][ 'swDPID' ] |
kavitha Alagesan | 373e055 | 2016-11-22 05:22:05 +0530 | [diff] [blame] | 76 | |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 77 | main.debug = True if "on" in main.debug else False |
| 78 | # -- INIT SECTION, ONLY RUNS ONCE -- # |
kavitha Alagesan | 373e055 | 2016-11-22 05:22:05 +0530 | [diff] [blame] | 79 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 80 | main.buckets = imp.load_source( bucket, |
| 81 | main.dependencyPath + |
| 82 | bucket + |
| 83 | ".py" ) |
kavitha Alagesan | 373e055 | 2016-11-22 05:22:05 +0530 | [diff] [blame] | 84 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 85 | copyResult = main.ONOSbench.scp( main.Mininet1, |
| 86 | main.dependencyPath + main.topology, |
| 87 | main.Mininet1.home + '/custom/', |
| 88 | direction="to" ) |
kavitha Alagesan | 373e055 | 2016-11-22 05:22:05 +0530 | [diff] [blame] | 89 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 90 | utilities.assert_equals( expect=main.TRUE, |
| 91 | actual=copyResult, |
| 92 | onpass="Successfully copy " + "test variables ", |
| 93 | onfail="Failed to copy test variables" ) |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 94 | stepResult = main.testSetUp.envSetup() |
kavitha Alagesan | 373e055 | 2016-11-22 05:22:05 +0530 | [diff] [blame] | 95 | |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 96 | except Exception as e: |
| 97 | main.testSetUp.envSetupException( e ) |
kavitha Alagesan | 373e055 | 2016-11-22 05:22:05 +0530 | [diff] [blame] | 98 | |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 99 | main.testSetUp.evnSetupConclusion( stepResult ) |
kavitha Alagesan | 373e055 | 2016-11-22 05:22:05 +0530 | [diff] [blame] | 100 | |
kavitha Alagesan | 373e055 | 2016-11-22 05:22:05 +0530 | [diff] [blame] | 101 | def CASE2( self, main ): |
| 102 | """ |
| 103 | - Set up cell |
| 104 | - Create cell file |
| 105 | - Set cell file |
| 106 | - Verify cell file |
| 107 | - Kill ONOS process |
| 108 | - Uninstall ONOS cluster |
| 109 | - Verify ONOS start up |
| 110 | - Install ONOS cluster |
| 111 | - Connect to cli |
| 112 | """ |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 113 | main.testSetUp.ONOSSetUp( main.Mininet1, main.Cluster ) |
kavitha Alagesan | 373e055 | 2016-11-22 05:22:05 +0530 | [diff] [blame] | 114 | |
| 115 | def CASE3( self, main ): |
Jon Hall | 602d0a7 | 2017-05-24 16:06:53 -0700 | [diff] [blame] | 116 | """ |
kavitha Alagesan | 373e055 | 2016-11-22 05:22:05 +0530 | [diff] [blame] | 117 | Start Mininet |
Jon Hall | 602d0a7 | 2017-05-24 16:06:53 -0700 | [diff] [blame] | 118 | """ |
kavitha Alagesan | 373e055 | 2016-11-22 05:22:05 +0530 | [diff] [blame] | 119 | import json |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 120 | import time |
| 121 | try: |
| 122 | from tests.dependencies.topology import Topology |
| 123 | except ImportError: |
| 124 | main.log.error( "Topology not found exiting the test" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 125 | main.cleanAndExit() |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 126 | try: |
| 127 | main.topoRelated |
| 128 | except ( NameError, AttributeError ): |
| 129 | main.topoRelated = Topology() |
kavitha Alagesan | 373e055 | 2016-11-22 05:22:05 +0530 | [diff] [blame] | 130 | |
| 131 | main.case( "Setup mininet and compare ONOS topology view to Mininet topology" ) |
| 132 | main.caseExplanation = "Start mininet with custom topology and compare topology " +\ |
| 133 | "elements between Mininet and ONOS" |
| 134 | |
| 135 | main.step( "Setup Mininet Topology" ) |
| 136 | topology = main.Mininet1.home + '/custom/' + main.topology |
Jon Hall | 602d0a7 | 2017-05-24 16:06:53 -0700 | [diff] [blame] | 137 | stepResult = main.Mininet1.startNet( topoFile=topology ) |
kavitha Alagesan | 373e055 | 2016-11-22 05:22:05 +0530 | [diff] [blame] | 138 | |
| 139 | utilities.assert_equals( expect=main.TRUE, |
| 140 | actual=stepResult, |
| 141 | onpass="Successfully loaded topology", |
| 142 | onfail="Failed to load topology" ) |
| 143 | |
| 144 | main.step( "Assign switch to controller" ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 145 | stepResult = main.Mininet1.assignSwController( "s1", main.Cluster.active( 0 ).ipAddress ) |
kavitha Alagesan | 373e055 | 2016-11-22 05:22:05 +0530 | [diff] [blame] | 146 | |
| 147 | utilities.assert_equals( expect=main.TRUE, |
| 148 | actual=stepResult, |
| 149 | onpass="Successfully assigned switch to controller", |
| 150 | onfail="Failed to assign switch to controller" ) |
| 151 | |
| 152 | time.sleep( main.startMNSleep ) |
| 153 | |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 154 | main.topoRelated.compareTopos( main.Mininet1 ) |
kavitha Alagesan | 373e055 | 2016-11-22 05:22:05 +0530 | [diff] [blame] | 155 | |
| 156 | def CASE4( self, main ): |
Jon Hall | 602d0a7 | 2017-05-24 16:06:53 -0700 | [diff] [blame] | 157 | """ |
kavitha Alagesan | 373e055 | 2016-11-22 05:22:05 +0530 | [diff] [blame] | 158 | Testing scapy |
Jon Hall | 602d0a7 | 2017-05-24 16:06:53 -0700 | [diff] [blame] | 159 | """ |
kavitha Alagesan | 373e055 | 2016-11-22 05:22:05 +0530 | [diff] [blame] | 160 | main.case( "Testing scapy" ) |
| 161 | main.step( "Creating Host1 component" ) |
| 162 | main.Scapy.createHostComponent( "h1" ) |
| 163 | main.Scapy.createHostComponent( "h2" ) |
| 164 | hosts = [ main.h1, main.h2 ] |
| 165 | for host in hosts: |
Jon Hall | 602d0a7 | 2017-05-24 16:06:53 -0700 | [diff] [blame] | 166 | host.startHostCli() |
| 167 | host.startScapy() |
| 168 | host.updateSelf() |
kavitha Alagesan | 373e055 | 2016-11-22 05:22:05 +0530 | [diff] [blame] | 169 | main.log.debug( host.name ) |
| 170 | main.log.debug( host.hostIp ) |
| 171 | main.log.debug( host.hostMac ) |
| 172 | |
| 173 | main.step( "Sending/Receiving Test packet - Filter doesn't match" ) |
| 174 | main.log.info( "Starting Filter..." ) |
Jon Hall | 602d0a7 | 2017-05-24 16:06:53 -0700 | [diff] [blame] | 175 | main.h2.startFilter() |
kavitha Alagesan | 373e055 | 2016-11-22 05:22:05 +0530 | [diff] [blame] | 176 | main.log.info( "Building Ether frame..." ) |
| 177 | main.h1.buildEther( dst=main.h2.hostMac ) |
| 178 | main.log.info( "Sending Packet..." ) |
Jon Hall | 602d0a7 | 2017-05-24 16:06:53 -0700 | [diff] [blame] | 179 | main.h1.sendPacket() |
kavitha Alagesan | 373e055 | 2016-11-22 05:22:05 +0530 | [diff] [blame] | 180 | main.log.info( "Checking Filter..." ) |
Jon Hall | 602d0a7 | 2017-05-24 16:06:53 -0700 | [diff] [blame] | 181 | finished = main.h2.checkFilter() |
kavitha Alagesan | 373e055 | 2016-11-22 05:22:05 +0530 | [diff] [blame] | 182 | main.log.debug( finished ) |
| 183 | i = "" |
| 184 | if finished: |
Jon Hall | 602d0a7 | 2017-05-24 16:06:53 -0700 | [diff] [blame] | 185 | a = main.h2.readPackets() |
| 186 | for i in a.splitlines(): |
kavitha Alagesan | 373e055 | 2016-11-22 05:22:05 +0530 | [diff] [blame] | 187 | main.log.info( i ) |
| 188 | else: |
Jon Hall | 602d0a7 | 2017-05-24 16:06:53 -0700 | [diff] [blame] | 189 | kill = main.h2.killFilter() |
kavitha Alagesan | 373e055 | 2016-11-22 05:22:05 +0530 | [diff] [blame] | 190 | main.log.debug( kill ) |
| 191 | main.h2.handle.sendline( "" ) |
| 192 | main.h2.handle.expect( main.h2.scapyPrompt ) |
| 193 | main.log.debug( main.h2.handle.before ) |
| 194 | utilities.assert_equals( expect=True, |
| 195 | actual="dst=00:00:00:00:00:02 src=00:00:00:00:00:01" in i, |
| 196 | onpass="Pass", |
| 197 | onfail="Fail" ) |
| 198 | |
| 199 | main.step( "Sending/Receiving Test packet - Filter matches" ) |
Jon Hall | 602d0a7 | 2017-05-24 16:06:53 -0700 | [diff] [blame] | 200 | main.h2.startFilter() |
kavitha Alagesan | 373e055 | 2016-11-22 05:22:05 +0530 | [diff] [blame] | 201 | main.h1.buildEther( dst=main.h2.hostMac ) |
| 202 | main.h1.buildIP( dst=main.h2.hostIp ) |
Jon Hall | 602d0a7 | 2017-05-24 16:06:53 -0700 | [diff] [blame] | 203 | main.h1.sendPacket() |
| 204 | finished = main.h2.checkFilter() |
kavitha Alagesan | 373e055 | 2016-11-22 05:22:05 +0530 | [diff] [blame] | 205 | i = "" |
| 206 | if finished: |
Jon Hall | 602d0a7 | 2017-05-24 16:06:53 -0700 | [diff] [blame] | 207 | a = main.h2.readPackets() |
| 208 | for i in a.splitlines(): |
kavitha Alagesan | 373e055 | 2016-11-22 05:22:05 +0530 | [diff] [blame] | 209 | main.log.info( i ) |
| 210 | else: |
Jon Hall | 602d0a7 | 2017-05-24 16:06:53 -0700 | [diff] [blame] | 211 | kill = main.h2.killFilter() |
kavitha Alagesan | 373e055 | 2016-11-22 05:22:05 +0530 | [diff] [blame] | 212 | main.log.debug( kill ) |
| 213 | main.h2.handle.sendline( "" ) |
| 214 | main.h2.handle.expect( main.h2.scapyPrompt ) |
| 215 | main.log.debug( main.h2.handle.before ) |
| 216 | utilities.assert_equals( expect=True, |
| 217 | actual="dst=00:00:00:00:00:02 src=00:00:00:00:00:01" in i, |
| 218 | onpass="Pass", |
| 219 | onfail="Fail" ) |
| 220 | |
kavitha Alagesan | 373e055 | 2016-11-22 05:22:05 +0530 | [diff] [blame] | 221 | main.step( "Clean up host components" ) |
| 222 | for host in hosts: |
Jon Hall | 602d0a7 | 2017-05-24 16:06:53 -0700 | [diff] [blame] | 223 | host.stopScapy() |
kavitha Alagesan | 373e055 | 2016-11-22 05:22:05 +0530 | [diff] [blame] | 224 | main.Mininet1.removeHostComponent( "h1" ) |
| 225 | main.Mininet1.removeHostComponent( "h2" ) |
| 226 | |
| 227 | def CASE5( self, main ): |
Jon Hall | 602d0a7 | 2017-05-24 16:06:53 -0700 | [diff] [blame] | 228 | """ |
kavitha Alagesan | 373e055 | 2016-11-22 05:22:05 +0530 | [diff] [blame] | 229 | Adding Group of type "ALL" using Rest api |
Jon Hall | 602d0a7 | 2017-05-24 16:06:53 -0700 | [diff] [blame] | 230 | """ |
kavitha Alagesan | 373e055 | 2016-11-22 05:22:05 +0530 | [diff] [blame] | 231 | import json |
| 232 | import time |
| 233 | isAdded = main.FALSE |
| 234 | main.case( "Verify Group of type All are successfully Added" ) |
| 235 | main.caseExplanation = " Install a Group of type ALL " +\ |
| 236 | " Verify the Group is Added " +\ |
| 237 | " Add a flow using the group " +\ |
| 238 | " Send a packet that verifies the action bucket of the group" |
| 239 | |
| 240 | main.step( "Add Group using Rest api" ) |
| 241 | bucketList = [] |
Jon Hall | 602d0a7 | 2017-05-24 16:06:53 -0700 | [diff] [blame] | 242 | bucket = main.buckets.addBucket( main, egressPort=egressPort1 ) |
kavitha Alagesan | 373e055 | 2016-11-22 05:22:05 +0530 | [diff] [blame] | 243 | bucketList.append( bucket ) |
Jon Hall | 602d0a7 | 2017-05-24 16:06:53 -0700 | [diff] [blame] | 244 | bucket = main.buckets.addBucket( main, egressPort=egressPort2 ) |
kavitha Alagesan | 373e055 | 2016-11-22 05:22:05 +0530 | [diff] [blame] | 245 | bucketList.append( bucket ) |
Jon Hall | 602d0a7 | 2017-05-24 16:06:53 -0700 | [diff] [blame] | 246 | bucket = main.buckets.addBucket( main, egressPort=egressPort3 ) |
kavitha Alagesan | 373e055 | 2016-11-22 05:22:05 +0530 | [diff] [blame] | 247 | bucketList.append( bucket ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 248 | ctrl = main.Cluster.active( 0 ) |
| 249 | response = ctrl.REST.addGroup( deviceId=deviceId, |
| 250 | groupType=type1, |
| 251 | bucketList=bucketList, |
| 252 | appCookie=appCookie, |
| 253 | groupId=groupId ) |
kavitha Alagesan | 373e055 | 2016-11-22 05:22:05 +0530 | [diff] [blame] | 254 | |
| 255 | utilities.assert_equals( expect=main.TRUE, |
| 256 | actual=response, |
| 257 | onpass="Successfully added Groups of type ALL", |
| 258 | onfail="Failed to add Groups of type ALL" ) |
| 259 | |
| 260 | # Giving ONOS time to add the group |
| 261 | time.sleep( main.addGroupSleep ) |
| 262 | |
| 263 | main.step( "Check groups are in ADDED state" ) |
| 264 | |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 265 | response = ctrl.REST.getGroups( deviceId=deviceId, |
| 266 | appCookie=appCookie ) |
kavitha Alagesan | 373e055 | 2016-11-22 05:22:05 +0530 | [diff] [blame] | 267 | responsejson = json.loads( response ) |
Jon Hall | 602d0a7 | 2017-05-24 16:06:53 -0700 | [diff] [blame] | 268 | for item in responsejson: |
| 269 | if item[ "state" ] == "ADDED": |
kavitha Alagesan | 373e055 | 2016-11-22 05:22:05 +0530 | [diff] [blame] | 270 | isAdded = main.TRUE |
| 271 | |
| 272 | utilities.assert_equals( expect=main.TRUE, |
| 273 | actual=isAdded, |
| 274 | onpass="All Group is in Added State", |
| 275 | onfail="All Group is not in Added State" ) |
| 276 | |
Jon Hall | 602d0a7 | 2017-05-24 16:06:53 -0700 | [diff] [blame] | 277 | """ |
kavitha Alagesan | 373e055 | 2016-11-22 05:22:05 +0530 | [diff] [blame] | 278 | Adding flow using rest api |
Jon Hall | 602d0a7 | 2017-05-24 16:06:53 -0700 | [diff] [blame] | 279 | """ |
kavitha Alagesan | 373e055 | 2016-11-22 05:22:05 +0530 | [diff] [blame] | 280 | isAdded = main.FALSE |
| 281 | |
| 282 | main.step( "Adding flow with Group using rest api" ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 283 | response = ctrl.REST.addFlow( deviceId=deviceId, |
| 284 | priority=priority, |
| 285 | ingressPort=ingressPort, |
| 286 | groupId=groupId ) |
kavitha Alagesan | 373e055 | 2016-11-22 05:22:05 +0530 | [diff] [blame] | 287 | utilities.assert_equals( expect=main.TRUE, |
| 288 | actual=response, |
| 289 | onpass="Successfully Added Flows", |
| 290 | onfail="Failed to Add flows" ) |
| 291 | |
| 292 | # Giving ONOS time to add the flow |
| 293 | time.sleep( main.addFlowSleep ) |
| 294 | |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 295 | response = ctrl.REST.getFlows( deviceId=deviceId ) |
kavitha Alagesan | 373e055 | 2016-11-22 05:22:05 +0530 | [diff] [blame] | 296 | responsejson = json.loads( response ) |
Jon Hall | 602d0a7 | 2017-05-24 16:06:53 -0700 | [diff] [blame] | 297 | for item in responsejson: |
| 298 | if item[ "priority" ] == int( priority ) and item[ "state" ] == "ADDED": |
kavitha Alagesan | 373e055 | 2016-11-22 05:22:05 +0530 | [diff] [blame] | 299 | isAdded = main.TRUE |
| 300 | |
| 301 | utilities.assert_equals( expect=main.TRUE, |
| 302 | actual=isAdded, |
| 303 | onpass="Flow is in Added State", |
| 304 | onfail="Flow is not in Added State" ) |
| 305 | |
Jon Hall | 602d0a7 | 2017-05-24 16:06:53 -0700 | [diff] [blame] | 306 | """ |
kavitha Alagesan | 373e055 | 2016-11-22 05:22:05 +0530 | [diff] [blame] | 307 | Sends a packet using scapy |
Jon Hall | 602d0a7 | 2017-05-24 16:06:53 -0700 | [diff] [blame] | 308 | """ |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 309 | main.step( "Testing Group by sending packet using Scapy" ) |
kavitha Alagesan | 373e055 | 2016-11-22 05:22:05 +0530 | [diff] [blame] | 310 | main.log.info( "Creating host components" ) |
| 311 | main.Scapy.createHostComponent( "h1" ) |
| 312 | main.Scapy.createHostComponent( "h2" ) |
| 313 | main.Scapy.createHostComponent( "h3" ) |
| 314 | main.Scapy.createHostComponent( "h4" ) |
| 315 | |
Jon Hall | 602d0a7 | 2017-05-24 16:06:53 -0700 | [diff] [blame] | 316 | hosts = [ main.h1, main.h2, main.h3, main.h4 ] |
kavitha Alagesan | 373e055 | 2016-11-22 05:22:05 +0530 | [diff] [blame] | 317 | for host in hosts: |
Jon Hall | 602d0a7 | 2017-05-24 16:06:53 -0700 | [diff] [blame] | 318 | host.startHostCli() |
| 319 | host.startScapy() |
| 320 | host.updateSelf() |
kavitha Alagesan | 373e055 | 2016-11-22 05:22:05 +0530 | [diff] [blame] | 321 | main.log.info( "Constructing Packet" ) |
| 322 | main.h1.buildEther( dst=main.h1.hostMac ) |
| 323 | main.h1.buildIP( dst=main.h1.hostIp ) |
| 324 | main.log.info( "Start Filter on host2,host3,host4" ) |
| 325 | main.h2.startFilter( pktFilter="ether host %s and ip host %s" % ( main.h1.hostMac, main.h1.hostIp ) ) |
| 326 | main.h3.startFilter( pktFilter="ether host %s and ip host %s" % ( main.h1.hostMac, main.h1.hostIp ) ) |
| 327 | main.h4.startFilter( pktFilter="ether host %s and ip host %s" % ( main.h1.hostMac, main.h1.hostIp ) ) |
| 328 | main.log.info( "sending packet to Host" ) |
Jon Hall | 602d0a7 | 2017-05-24 16:06:53 -0700 | [diff] [blame] | 329 | main.h1.sendPacket() |
kavitha Alagesan | 373e055 | 2016-11-22 05:22:05 +0530 | [diff] [blame] | 330 | main.log.info( "Checking filter for our packet" ) |
Jon Hall | 602d0a7 | 2017-05-24 16:06:53 -0700 | [diff] [blame] | 331 | stepResultH2 = main.h2.checkFilter() |
| 332 | stepResultH3 = main.h3.checkFilter() |
| 333 | stepResultH4 = main.h4.checkFilter() |
kavitha Alagesan | 373e055 | 2016-11-22 05:22:05 +0530 | [diff] [blame] | 334 | |
| 335 | if stepResultH2: |
Jon Hall | 602d0a7 | 2017-05-24 16:06:53 -0700 | [diff] [blame] | 336 | main.log.info( "Packet : %s" % main.h2.readPackets() ) |
kavitha Alagesan | 373e055 | 2016-11-22 05:22:05 +0530 | [diff] [blame] | 337 | else: |
Jon Hall | 602d0a7 | 2017-05-24 16:06:53 -0700 | [diff] [blame] | 338 | main.h2.killFilter() |
kavitha Alagesan | 373e055 | 2016-11-22 05:22:05 +0530 | [diff] [blame] | 339 | |
| 340 | if stepResultH3: |
Jon Hall | 602d0a7 | 2017-05-24 16:06:53 -0700 | [diff] [blame] | 341 | main.log.info( "Packet : %s" % main.h3.readPackets() ) |
kavitha Alagesan | 373e055 | 2016-11-22 05:22:05 +0530 | [diff] [blame] | 342 | else: |
Jon Hall | 602d0a7 | 2017-05-24 16:06:53 -0700 | [diff] [blame] | 343 | main.h2.killFilter() |
kavitha Alagesan | 373e055 | 2016-11-22 05:22:05 +0530 | [diff] [blame] | 344 | |
| 345 | if stepResultH4: |
Jon Hall | 602d0a7 | 2017-05-24 16:06:53 -0700 | [diff] [blame] | 346 | main.log.info( "Packet : %s" % main.h4.readPackets() ) |
kavitha Alagesan | 373e055 | 2016-11-22 05:22:05 +0530 | [diff] [blame] | 347 | else: |
Jon Hall | 602d0a7 | 2017-05-24 16:06:53 -0700 | [diff] [blame] | 348 | main.h4.killFilter() |
kavitha Alagesan | 373e055 | 2016-11-22 05:22:05 +0530 | [diff] [blame] | 349 | |
Jon Hall | 602d0a7 | 2017-05-24 16:06:53 -0700 | [diff] [blame] | 350 | if stepResultH2 and stepResultH3 and stepResultH4: |
kavitha Alagesan | 373e055 | 2016-11-22 05:22:05 +0530 | [diff] [blame] | 351 | main.log.info( "Success!!!Packet sent to port 1 is received at port 2,3 and 4" ) |
| 352 | stepResult = main.TRUE |
| 353 | else: |
| 354 | main.log.info( "Failure!!!Packet sent to port 1 is not received at port 2,3 and 4" ) |
| 355 | stepResult = main.FALSE |
| 356 | |
| 357 | main.log.info( "Clean up host components" ) |
| 358 | for host in hosts: |
Jon Hall | 602d0a7 | 2017-05-24 16:06:53 -0700 | [diff] [blame] | 359 | host.stopScapy() |
kavitha Alagesan | 373e055 | 2016-11-22 05:22:05 +0530 | [diff] [blame] | 360 | main.Mininet1.removeHostComponent( "h1" ) |
| 361 | main.Mininet1.removeHostComponent( "h2" ) |
| 362 | main.Mininet1.removeHostComponent( "h3" ) |
| 363 | main.Mininet1.removeHostComponent( "h4" ) |
| 364 | |
| 365 | utilities.assert_equals( expect=main.TRUE, |
| 366 | actual=stepResult, |
| 367 | onpass="Packet sent to port 1 is received at port 2,3,4 ", |
| 368 | onfail="Packet sent to port 1 is not received at port 2,3,4 " ) |
| 369 | |
| 370 | def CASE6( self, main ): |
Jon Hall | 602d0a7 | 2017-05-24 16:06:53 -0700 | [diff] [blame] | 371 | """ |
kavitha Alagesan | 373e055 | 2016-11-22 05:22:05 +0530 | [diff] [blame] | 372 | Deleting the Group and Flow |
Jon Hall | 602d0a7 | 2017-05-24 16:06:53 -0700 | [diff] [blame] | 373 | """ |
kavitha Alagesan | 373e055 | 2016-11-22 05:22:05 +0530 | [diff] [blame] | 374 | import json |
| 375 | import time |
| 376 | respFlowId = 1 |
| 377 | |
| 378 | main.case( "Delete the Group and Flow added through Rest api " ) |
| 379 | main.step( "Deleting Group and Flows" ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 380 | ctrl = main.Cluster.active( 0 ) |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 381 | # Get Flow ID |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 382 | response = ctrl.REST.getFlows( deviceId=deviceId ) |
kavitha Alagesan | 373e055 | 2016-11-22 05:22:05 +0530 | [diff] [blame] | 383 | responsejson = json.loads( response ) |
Jon Hall | 602d0a7 | 2017-05-24 16:06:53 -0700 | [diff] [blame] | 384 | for item in responsejson: |
| 385 | if item[ "priority" ] == int( priority ): |
| 386 | respFlowId = item[ "id" ] |
kavitha Alagesan | 373e055 | 2016-11-22 05:22:05 +0530 | [diff] [blame] | 387 | |
| 388 | main.step( "Deleting the created flow by deviceId and flowId" ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 389 | flowResponse = ctrl.REST.removeFlow( deviceId=deviceId, |
| 390 | flowId=respFlowId ) |
kavitha Alagesan | 373e055 | 2016-11-22 05:22:05 +0530 | [diff] [blame] | 391 | |
| 392 | utilities.assert_equals( expect=main.TRUE, |
| 393 | actual=flowResponse, |
| 394 | onpass="Deleting flow is successful!!!", |
| 395 | onfail="Deleting flow is failure!!!" ) |
| 396 | |
| 397 | # Giving ONOS time to delete the flow |
| 398 | time.sleep( main.delFlowSleep ) |
| 399 | |
| 400 | main.step( "Deleting the created group by deviceId and appCookie" ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 401 | groupResponse = ctrl.REST.removeGroup( deviceId=deviceId, |
| 402 | appCookie=appCookie ) |
kavitha Alagesan | 373e055 | 2016-11-22 05:22:05 +0530 | [diff] [blame] | 403 | |
| 404 | utilities.assert_equals( expect=main.TRUE, |
| 405 | actual=groupResponse, |
| 406 | onpass="Deleting Group is successful!!!", |
| 407 | onfail="Deleting Group is failure!!!" ) |
| 408 | |
| 409 | # Giving ONOS time to delete the group |
| 410 | time.sleep( main.delGroupSleep ) |
| 411 | |
| 412 | def CASE7( self, main ): |
Jon Hall | 602d0a7 | 2017-05-24 16:06:53 -0700 | [diff] [blame] | 413 | """ |
kavitha Alagesan | 373e055 | 2016-11-22 05:22:05 +0530 | [diff] [blame] | 414 | Adding Group of type "INDIRECT" using Rest api. |
Jon Hall | 602d0a7 | 2017-05-24 16:06:53 -0700 | [diff] [blame] | 415 | """ |
kavitha Alagesan | 373e055 | 2016-11-22 05:22:05 +0530 | [diff] [blame] | 416 | import json |
| 417 | import time |
| 418 | isAdded = main.FALSE |
| 419 | |
| 420 | main.case( "Verify Group of type INDIRECT are successfully Added" ) |
| 421 | main.caseExplanation = " Install a Group of type INDIRECT " +\ |
| 422 | " Verify the Group is Added " +\ |
| 423 | " Add a flow using the group " +\ |
| 424 | " Send a packet that verifies the action bucket of the group" |
| 425 | |
| 426 | main.step( "Add Group using Rest api" ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 427 | ctrl = main.Cluster.active( 0 ) |
kavitha Alagesan | 373e055 | 2016-11-22 05:22:05 +0530 | [diff] [blame] | 428 | bucketList = [] |
Jon Hall | 602d0a7 | 2017-05-24 16:06:53 -0700 | [diff] [blame] | 429 | bucket = main.buckets.addBucket( main, egressPort=egressPort1 ) |
kavitha Alagesan | 373e055 | 2016-11-22 05:22:05 +0530 | [diff] [blame] | 430 | bucketList.append( bucket ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 431 | response = ctrl.REST.addGroup( deviceId=deviceId, |
| 432 | groupType=type2, |
| 433 | bucketList=bucketList, |
| 434 | appCookie=appCookie, |
| 435 | groupId=groupId ) |
kavitha Alagesan | 373e055 | 2016-11-22 05:22:05 +0530 | [diff] [blame] | 436 | |
| 437 | utilities.assert_equals( expect=main.TRUE, |
| 438 | actual=response, |
| 439 | onpass="Successfully added Groups of type INDIRECT", |
| 440 | onfail="Failed to add Groups of type INDIRECT" ) |
| 441 | |
| 442 | # Giving ONOS time to add the group |
| 443 | time.sleep( main.addGroupSleep ) |
| 444 | |
| 445 | main.step( "Check groups are in ADDED state" ) |
| 446 | |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 447 | response = ctrl.REST.getGroups( deviceId=deviceId, |
| 448 | appCookie=appCookie ) |
kavitha Alagesan | 373e055 | 2016-11-22 05:22:05 +0530 | [diff] [blame] | 449 | responsejson = json.loads( response ) |
Jon Hall | 602d0a7 | 2017-05-24 16:06:53 -0700 | [diff] [blame] | 450 | for item in responsejson: |
| 451 | if item[ "state" ] == "ADDED": |
kavitha Alagesan | 373e055 | 2016-11-22 05:22:05 +0530 | [diff] [blame] | 452 | isAdded = main.TRUE |
| 453 | |
| 454 | utilities.assert_equals( expect=main.TRUE, |
| 455 | actual=isAdded, |
| 456 | onpass="INDIRECT Group is in Added State", |
| 457 | onfail="INDIRECT Group is not in Added State" ) |
| 458 | |
Jon Hall | 602d0a7 | 2017-05-24 16:06:53 -0700 | [diff] [blame] | 459 | """ |
kavitha Alagesan | 373e055 | 2016-11-22 05:22:05 +0530 | [diff] [blame] | 460 | Adding flows using rest api |
Jon Hall | 602d0a7 | 2017-05-24 16:06:53 -0700 | [diff] [blame] | 461 | """ |
kavitha Alagesan | 373e055 | 2016-11-22 05:22:05 +0530 | [diff] [blame] | 462 | isAdded = main.FALSE |
| 463 | |
| 464 | main.step( "Adding flow with Group using rest api" ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 465 | response = ctrl.REST.addFlow( deviceId=deviceId, |
| 466 | priority=priority, |
| 467 | ingressPort=ingressPort, |
| 468 | groupId=groupId ) |
kavitha Alagesan | 373e055 | 2016-11-22 05:22:05 +0530 | [diff] [blame] | 469 | utilities.assert_equals( expect=main.TRUE, |
| 470 | actual=response, |
| 471 | onpass="Successfully Added Flows", |
| 472 | onfail="Failed to Add flows" ) |
| 473 | |
| 474 | # Giving ONOS time to add the flow |
| 475 | time.sleep( main.addFlowSleep ) |
| 476 | |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 477 | response = ctrl.REST.getFlows( deviceId=deviceId ) |
kavitha Alagesan | 373e055 | 2016-11-22 05:22:05 +0530 | [diff] [blame] | 478 | responsejson = json.loads( response ) |
Jon Hall | 602d0a7 | 2017-05-24 16:06:53 -0700 | [diff] [blame] | 479 | for item in responsejson: |
| 480 | if item[ "priority" ] == int( priority ) and item[ "state" ] == "ADDED": |
kavitha Alagesan | 373e055 | 2016-11-22 05:22:05 +0530 | [diff] [blame] | 481 | isAdded = main.TRUE |
| 482 | |
| 483 | utilities.assert_equals( expect=main.TRUE, |
| 484 | actual=isAdded, |
| 485 | onpass="Flow is in Added State", |
| 486 | onfail="Flow is not in Added State" ) |
| 487 | |
Jon Hall | 602d0a7 | 2017-05-24 16:06:53 -0700 | [diff] [blame] | 488 | """ |
kavitha Alagesan | 373e055 | 2016-11-22 05:22:05 +0530 | [diff] [blame] | 489 | Sends a packet using scapy |
Jon Hall | 602d0a7 | 2017-05-24 16:06:53 -0700 | [diff] [blame] | 490 | """ |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 491 | main.step( "Testing Group by sending packet using Scapy" ) |
kavitha Alagesan | 373e055 | 2016-11-22 05:22:05 +0530 | [diff] [blame] | 492 | main.log.info( "Creating host components" ) |
| 493 | main.Scapy.createHostComponent( "h1" ) |
| 494 | main.Scapy.createHostComponent( "h2" ) |
| 495 | |
Jon Hall | 602d0a7 | 2017-05-24 16:06:53 -0700 | [diff] [blame] | 496 | hosts = [ main.h1, main.h2 ] |
kavitha Alagesan | 373e055 | 2016-11-22 05:22:05 +0530 | [diff] [blame] | 497 | for host in hosts: |
Jon Hall | 602d0a7 | 2017-05-24 16:06:53 -0700 | [diff] [blame] | 498 | host.startHostCli() |
| 499 | host.startScapy() |
| 500 | host.updateSelf() |
kavitha Alagesan | 373e055 | 2016-11-22 05:22:05 +0530 | [diff] [blame] | 501 | main.log.info( "Constructing Packet" ) |
| 502 | main.h1.buildEther( dst=main.h1.hostMac ) |
| 503 | main.h1.buildIP( dst=main.h1.hostIp ) |
| 504 | main.log.info( "Start Filter on host2" ) |
| 505 | main.h2.startFilter( pktFilter="ether host %s and ip host %s" % ( main.h1.hostMac, main.h1.hostIp ) ) |
| 506 | main.log.info( "sending packet to Host" ) |
Jon Hall | 602d0a7 | 2017-05-24 16:06:53 -0700 | [diff] [blame] | 507 | main.h1.sendPacket() |
kavitha Alagesan | 373e055 | 2016-11-22 05:22:05 +0530 | [diff] [blame] | 508 | main.log.info( "Checking filter for our packet" ) |
Jon Hall | 602d0a7 | 2017-05-24 16:06:53 -0700 | [diff] [blame] | 509 | stepResultH2 = main.h2.checkFilter() |
kavitha Alagesan | 373e055 | 2016-11-22 05:22:05 +0530 | [diff] [blame] | 510 | |
| 511 | if stepResultH2: |
Jon Hall | 602d0a7 | 2017-05-24 16:06:53 -0700 | [diff] [blame] | 512 | main.log.info( "Packet : %s" % main.h2.readPackets() ) |
kavitha Alagesan | 373e055 | 2016-11-22 05:22:05 +0530 | [diff] [blame] | 513 | else: |
Jon Hall | 602d0a7 | 2017-05-24 16:06:53 -0700 | [diff] [blame] | 514 | main.h2.killFilter() |
kavitha Alagesan | 373e055 | 2016-11-22 05:22:05 +0530 | [diff] [blame] | 515 | |
| 516 | main.log.info( "Clean up host components" ) |
| 517 | for host in hosts: |
Jon Hall | 602d0a7 | 2017-05-24 16:06:53 -0700 | [diff] [blame] | 518 | host.stopScapy() |
kavitha Alagesan | 373e055 | 2016-11-22 05:22:05 +0530 | [diff] [blame] | 519 | main.Mininet1.removeHostComponent( "h1" ) |
| 520 | main.Mininet1.removeHostComponent( "h2" ) |
| 521 | |
| 522 | utilities.assert_equals( expect=main.TRUE, |
| 523 | actual=stepResultH2, |
| 524 | onpass="Packet sent to port 1 is received at port 2 successfully!!!", |
| 525 | onfail="Failure!!!Packet sent to port 1 is not received at port 2" ) |
| 526 | |
kavitha Alagesan | 373e055 | 2016-11-22 05:22:05 +0530 | [diff] [blame] | 527 | def CASE100( self, main ): |
Jon Hall | 602d0a7 | 2017-05-24 16:06:53 -0700 | [diff] [blame] | 528 | """ |
kavitha Alagesan | 373e055 | 2016-11-22 05:22:05 +0530 | [diff] [blame] | 529 | Report errors/warnings/exceptions |
Jon Hall | 602d0a7 | 2017-05-24 16:06:53 -0700 | [diff] [blame] | 530 | """ |
kavitha Alagesan | 373e055 | 2016-11-22 05:22:05 +0530 | [diff] [blame] | 531 | main.log.info( "Error report: \n" ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 532 | main.ONOSbench.logReport( main.Cluster.active( 0 ).ipAddress, |
kavitha Alagesan | 373e055 | 2016-11-22 05:22:05 +0530 | [diff] [blame] | 533 | [ "INFO", |
| 534 | "FOLLOWER", |
| 535 | "WARN", |
| 536 | "flow", |
| 537 | "group", |
| 538 | "ERROR", |
| 539 | "Except" ], |
| 540 | "s" ) |