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