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