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" ) |
| 44 | main.exit() |
| 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'] |
| 59 | main.maxNodes = int(main.params['SCALE']['max']) |
| 60 | main.startUpSleep = int(main.params['SLEEP']['startup']) |
| 61 | main.startMNSleep = int(main.params['SLEEP']['startMN']) |
| 62 | main.addFlowSleep = int(main.params['SLEEP']['addFlow']) |
| 63 | main.delFlowSleep = int(main.params['SLEEP']['delFlow']) |
| 64 | main.addGroupSleep = int(main.params['SLEEP']['addGroup']) |
| 65 | main.delGroupSleep = int(main.params['SLEEP']['delGroup']) |
| 66 | main.debug = main.params['DEBUG'] |
| 67 | main.swDPID = main.params['TEST']['swDPID'] |
| 68 | egressPort1 = main.params['TEST']['egressPort1'] |
| 69 | egressPort2 = main.params['TEST']['egressPort2'] |
| 70 | egressPort3 = main.params['TEST']['egressPort3'] |
| 71 | ingressPort = main.params['TEST']['ingressPort'] |
| 72 | appCookie = main.params['TEST']['appCookie'] |
| 73 | type1 = main.params['TEST']['type1'] |
| 74 | type2 = main.params['TEST']['type2'] |
| 75 | groupId = main.params['TEST']['groupId'] |
| 76 | priority = main.params['TEST']['priority'] |
| 77 | deviceId = main.params['TEST']['swDPID'] |
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 | |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -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 | |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -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 | |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -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") |
| 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 | |
kavitha Alagesan | 373e055 | 2016-11-22 05:22:05 +0530 | [diff] [blame] | 104 | |
kavitha Alagesan | 373e055 | 2016-11-22 05:22:05 +0530 | [diff] [blame] | 105 | def CASE2( self, main ): |
| 106 | """ |
| 107 | - Set up cell |
| 108 | - Create cell file |
| 109 | - Set cell file |
| 110 | - Verify cell file |
| 111 | - Kill ONOS process |
| 112 | - Uninstall ONOS cluster |
| 113 | - Verify ONOS start up |
| 114 | - Install ONOS cluster |
| 115 | - Connect to cli |
| 116 | """ |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 117 | main.testSetUp.ONOSSetUp( main.Mininet1 ) |
kavitha Alagesan | 373e055 | 2016-11-22 05:22:05 +0530 | [diff] [blame] | 118 | |
| 119 | def CASE3( self, main ): |
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 | Start Mininet |
Jon Hall | 602d0a7 | 2017-05-24 16:06:53 -0700 | [diff] [blame] | 122 | """ |
kavitha Alagesan | 373e055 | 2016-11-22 05:22:05 +0530 | [diff] [blame] | 123 | import json |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 124 | import time |
| 125 | try: |
| 126 | from tests.dependencies.topology import Topology |
| 127 | except ImportError: |
| 128 | main.log.error( "Topology not found exiting the test" ) |
| 129 | main.exit() |
| 130 | try: |
| 131 | main.topoRelated |
| 132 | except ( NameError, AttributeError ): |
| 133 | main.topoRelated = Topology() |
kavitha Alagesan | 373e055 | 2016-11-22 05:22:05 +0530 | [diff] [blame] | 134 | |
| 135 | main.case( "Setup mininet and compare ONOS topology view to Mininet topology" ) |
| 136 | main.caseExplanation = "Start mininet with custom topology and compare topology " +\ |
| 137 | "elements between Mininet and ONOS" |
| 138 | |
| 139 | main.step( "Setup Mininet Topology" ) |
| 140 | topology = main.Mininet1.home + '/custom/' + main.topology |
Jon Hall | 602d0a7 | 2017-05-24 16:06:53 -0700 | [diff] [blame] | 141 | stepResult = main.Mininet1.startNet( topoFile=topology ) |
kavitha Alagesan | 373e055 | 2016-11-22 05:22:05 +0530 | [diff] [blame] | 142 | |
| 143 | utilities.assert_equals( expect=main.TRUE, |
| 144 | actual=stepResult, |
| 145 | onpass="Successfully loaded topology", |
| 146 | onfail="Failed to load topology" ) |
| 147 | |
| 148 | main.step( "Assign switch to controller" ) |
Jon Hall | 602d0a7 | 2017-05-24 16:06:53 -0700 | [diff] [blame] | 149 | stepResult = main.Mininet1.assignSwController( "s1", main.ONOSip[ 0 ] ) |
kavitha Alagesan | 373e055 | 2016-11-22 05:22:05 +0530 | [diff] [blame] | 150 | |
| 151 | utilities.assert_equals( expect=main.TRUE, |
| 152 | actual=stepResult, |
| 153 | onpass="Successfully assigned switch to controller", |
| 154 | onfail="Failed to assign switch to controller" ) |
| 155 | |
| 156 | time.sleep( main.startMNSleep ) |
| 157 | |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 158 | main.topoRelated.compareTopos( main.Mininet1 ) |
kavitha Alagesan | 373e055 | 2016-11-22 05:22:05 +0530 | [diff] [blame] | 159 | |
| 160 | def CASE4( self, main ): |
Jon Hall | 602d0a7 | 2017-05-24 16:06:53 -0700 | [diff] [blame] | 161 | """ |
kavitha Alagesan | 373e055 | 2016-11-22 05:22:05 +0530 | [diff] [blame] | 162 | Testing scapy |
Jon Hall | 602d0a7 | 2017-05-24 16:06:53 -0700 | [diff] [blame] | 163 | """ |
kavitha Alagesan | 373e055 | 2016-11-22 05:22:05 +0530 | [diff] [blame] | 164 | main.case( "Testing scapy" ) |
| 165 | main.step( "Creating Host1 component" ) |
| 166 | main.Scapy.createHostComponent( "h1" ) |
| 167 | main.Scapy.createHostComponent( "h2" ) |
| 168 | hosts = [ main.h1, main.h2 ] |
| 169 | for host in hosts: |
Jon Hall | 602d0a7 | 2017-05-24 16:06:53 -0700 | [diff] [blame] | 170 | host.startHostCli() |
| 171 | host.startScapy() |
| 172 | host.updateSelf() |
kavitha Alagesan | 373e055 | 2016-11-22 05:22:05 +0530 | [diff] [blame] | 173 | main.log.debug( host.name ) |
| 174 | main.log.debug( host.hostIp ) |
| 175 | main.log.debug( host.hostMac ) |
| 176 | |
| 177 | main.step( "Sending/Receiving Test packet - Filter doesn't match" ) |
| 178 | main.log.info( "Starting Filter..." ) |
Jon Hall | 602d0a7 | 2017-05-24 16:06:53 -0700 | [diff] [blame] | 179 | main.h2.startFilter() |
kavitha Alagesan | 373e055 | 2016-11-22 05:22:05 +0530 | [diff] [blame] | 180 | main.log.info( "Building Ether frame..." ) |
| 181 | main.h1.buildEther( dst=main.h2.hostMac ) |
| 182 | main.log.info( "Sending Packet..." ) |
Jon Hall | 602d0a7 | 2017-05-24 16:06:53 -0700 | [diff] [blame] | 183 | main.h1.sendPacket() |
kavitha Alagesan | 373e055 | 2016-11-22 05:22:05 +0530 | [diff] [blame] | 184 | main.log.info( "Checking Filter..." ) |
Jon Hall | 602d0a7 | 2017-05-24 16:06:53 -0700 | [diff] [blame] | 185 | finished = main.h2.checkFilter() |
kavitha Alagesan | 373e055 | 2016-11-22 05:22:05 +0530 | [diff] [blame] | 186 | main.log.debug( finished ) |
| 187 | i = "" |
| 188 | if finished: |
Jon Hall | 602d0a7 | 2017-05-24 16:06:53 -0700 | [diff] [blame] | 189 | a = main.h2.readPackets() |
| 190 | for i in a.splitlines(): |
kavitha Alagesan | 373e055 | 2016-11-22 05:22:05 +0530 | [diff] [blame] | 191 | main.log.info( i ) |
| 192 | else: |
Jon Hall | 602d0a7 | 2017-05-24 16:06:53 -0700 | [diff] [blame] | 193 | kill = main.h2.killFilter() |
kavitha Alagesan | 373e055 | 2016-11-22 05:22:05 +0530 | [diff] [blame] | 194 | main.log.debug( kill ) |
| 195 | main.h2.handle.sendline( "" ) |
| 196 | main.h2.handle.expect( main.h2.scapyPrompt ) |
| 197 | main.log.debug( main.h2.handle.before ) |
| 198 | utilities.assert_equals( expect=True, |
| 199 | actual="dst=00:00:00:00:00:02 src=00:00:00:00:00:01" in i, |
| 200 | onpass="Pass", |
| 201 | onfail="Fail" ) |
| 202 | |
| 203 | main.step( "Sending/Receiving Test packet - Filter matches" ) |
Jon Hall | 602d0a7 | 2017-05-24 16:06:53 -0700 | [diff] [blame] | 204 | main.h2.startFilter() |
kavitha Alagesan | 373e055 | 2016-11-22 05:22:05 +0530 | [diff] [blame] | 205 | main.h1.buildEther( dst=main.h2.hostMac ) |
| 206 | main.h1.buildIP( dst=main.h2.hostIp ) |
Jon Hall | 602d0a7 | 2017-05-24 16:06:53 -0700 | [diff] [blame] | 207 | main.h1.sendPacket() |
| 208 | finished = main.h2.checkFilter() |
kavitha Alagesan | 373e055 | 2016-11-22 05:22:05 +0530 | [diff] [blame] | 209 | i = "" |
| 210 | if finished: |
Jon Hall | 602d0a7 | 2017-05-24 16:06:53 -0700 | [diff] [blame] | 211 | a = main.h2.readPackets() |
| 212 | for i in a.splitlines(): |
kavitha Alagesan | 373e055 | 2016-11-22 05:22:05 +0530 | [diff] [blame] | 213 | main.log.info( i ) |
| 214 | else: |
Jon Hall | 602d0a7 | 2017-05-24 16:06:53 -0700 | [diff] [blame] | 215 | kill = main.h2.killFilter() |
kavitha Alagesan | 373e055 | 2016-11-22 05:22:05 +0530 | [diff] [blame] | 216 | main.log.debug( kill ) |
| 217 | main.h2.handle.sendline( "" ) |
| 218 | main.h2.handle.expect( main.h2.scapyPrompt ) |
| 219 | main.log.debug( main.h2.handle.before ) |
| 220 | utilities.assert_equals( expect=True, |
| 221 | actual="dst=00:00:00:00:00:02 src=00:00:00:00:00:01" in i, |
| 222 | onpass="Pass", |
| 223 | onfail="Fail" ) |
| 224 | |
kavitha Alagesan | 373e055 | 2016-11-22 05:22:05 +0530 | [diff] [blame] | 225 | main.step( "Clean up host components" ) |
| 226 | for host in hosts: |
Jon Hall | 602d0a7 | 2017-05-24 16:06:53 -0700 | [diff] [blame] | 227 | host.stopScapy() |
kavitha Alagesan | 373e055 | 2016-11-22 05:22:05 +0530 | [diff] [blame] | 228 | main.Mininet1.removeHostComponent( "h1" ) |
| 229 | main.Mininet1.removeHostComponent( "h2" ) |
| 230 | |
| 231 | def CASE5( self, main ): |
Jon Hall | 602d0a7 | 2017-05-24 16:06:53 -0700 | [diff] [blame] | 232 | """ |
kavitha Alagesan | 373e055 | 2016-11-22 05:22:05 +0530 | [diff] [blame] | 233 | Adding Group of type "ALL" using Rest api |
Jon Hall | 602d0a7 | 2017-05-24 16:06:53 -0700 | [diff] [blame] | 234 | """ |
kavitha Alagesan | 373e055 | 2016-11-22 05:22:05 +0530 | [diff] [blame] | 235 | import json |
| 236 | import time |
| 237 | isAdded = main.FALSE |
| 238 | main.case( "Verify Group of type All are successfully Added" ) |
| 239 | main.caseExplanation = " Install a Group of type ALL " +\ |
| 240 | " Verify the Group is Added " +\ |
| 241 | " Add a flow using the group " +\ |
| 242 | " Send a packet that verifies the action bucket of the group" |
| 243 | |
| 244 | main.step( "Add Group using Rest api" ) |
| 245 | bucketList = [] |
Jon Hall | 602d0a7 | 2017-05-24 16:06:53 -0700 | [diff] [blame] | 246 | bucket = main.buckets.addBucket( main, egressPort=egressPort1 ) |
kavitha Alagesan | 373e055 | 2016-11-22 05:22:05 +0530 | [diff] [blame] | 247 | bucketList.append( bucket ) |
Jon Hall | 602d0a7 | 2017-05-24 16:06:53 -0700 | [diff] [blame] | 248 | bucket = main.buckets.addBucket( main, egressPort=egressPort2 ) |
kavitha Alagesan | 373e055 | 2016-11-22 05:22:05 +0530 | [diff] [blame] | 249 | bucketList.append( bucket ) |
Jon Hall | 602d0a7 | 2017-05-24 16:06:53 -0700 | [diff] [blame] | 250 | bucket = main.buckets.addBucket( main, egressPort=egressPort3 ) |
kavitha Alagesan | 373e055 | 2016-11-22 05:22:05 +0530 | [diff] [blame] | 251 | bucketList.append( bucket ) |
Jon Hall | 602d0a7 | 2017-05-24 16:06:53 -0700 | [diff] [blame] | 252 | response = main.ONOSrest.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 | |
Jon Hall | 602d0a7 | 2017-05-24 16:06:53 -0700 | [diff] [blame] | 268 | response = main.ONOSrest.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" ) |
Jon Hall | 602d0a7 | 2017-05-24 16:06:53 -0700 | [diff] [blame] | 286 | response = main.ONOSrest.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 | |
Jon Hall | 602d0a7 | 2017-05-24 16:06:53 -0700 | [diff] [blame] | 298 | response = main.ONOSrest.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" ) |
| 383 | |
| 384 | #Get Flow ID |
Jon Hall | 602d0a7 | 2017-05-24 16:06:53 -0700 | [diff] [blame] | 385 | response = main.ONOSrest.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" ) |
Jon Hall | 602d0a7 | 2017-05-24 16:06:53 -0700 | [diff] [blame] | 392 | flowResponse = main.ONOSrest.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" ) |
Jon Hall | 602d0a7 | 2017-05-24 16:06:53 -0700 | [diff] [blame] | 404 | groupResponse = main.ONOSrest.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" ) |
| 430 | bucketList = [] |
Jon Hall | 602d0a7 | 2017-05-24 16:06:53 -0700 | [diff] [blame] | 431 | bucket = main.buckets.addBucket( main, egressPort=egressPort1 ) |
kavitha Alagesan | 373e055 | 2016-11-22 05:22:05 +0530 | [diff] [blame] | 432 | bucketList.append( bucket ) |
Jon Hall | 602d0a7 | 2017-05-24 16:06:53 -0700 | [diff] [blame] | 433 | response = main.ONOSrest.addGroup( deviceId=deviceId, |
| 434 | groupType=type2, |
| 435 | bucketList=bucketList, |
| 436 | appCookie=appCookie, |
| 437 | groupId=groupId ) |
kavitha Alagesan | 373e055 | 2016-11-22 05:22:05 +0530 | [diff] [blame] | 438 | |
| 439 | utilities.assert_equals( expect=main.TRUE, |
| 440 | actual=response, |
| 441 | onpass="Successfully added Groups of type INDIRECT", |
| 442 | onfail="Failed to add Groups of type INDIRECT" ) |
| 443 | |
| 444 | # Giving ONOS time to add the group |
| 445 | time.sleep( main.addGroupSleep ) |
| 446 | |
| 447 | main.step( "Check groups are in ADDED state" ) |
| 448 | |
Jon Hall | 602d0a7 | 2017-05-24 16:06:53 -0700 | [diff] [blame] | 449 | response = main.ONOSrest.getGroups( deviceId=deviceId, |
| 450 | appCookie=appCookie ) |
kavitha Alagesan | 373e055 | 2016-11-22 05:22:05 +0530 | [diff] [blame] | 451 | responsejson = json.loads( response ) |
Jon Hall | 602d0a7 | 2017-05-24 16:06:53 -0700 | [diff] [blame] | 452 | for item in responsejson: |
| 453 | if item[ "state" ] == "ADDED": |
kavitha Alagesan | 373e055 | 2016-11-22 05:22:05 +0530 | [diff] [blame] | 454 | isAdded = main.TRUE |
| 455 | |
| 456 | utilities.assert_equals( expect=main.TRUE, |
| 457 | actual=isAdded, |
| 458 | onpass="INDIRECT Group is in Added State", |
| 459 | onfail="INDIRECT Group is not in Added State" ) |
| 460 | |
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 | Adding flows using rest api |
Jon Hall | 602d0a7 | 2017-05-24 16:06:53 -0700 | [diff] [blame] | 463 | """ |
kavitha Alagesan | 373e055 | 2016-11-22 05:22:05 +0530 | [diff] [blame] | 464 | isAdded = main.FALSE |
| 465 | |
| 466 | main.step( "Adding flow with Group using rest api" ) |
Jon Hall | 602d0a7 | 2017-05-24 16:06:53 -0700 | [diff] [blame] | 467 | response = main.ONOSrest.addFlow( deviceId=deviceId, |
| 468 | priority=priority, |
| 469 | ingressPort=ingressPort, |
| 470 | groupId=groupId ) |
kavitha Alagesan | 373e055 | 2016-11-22 05:22:05 +0530 | [diff] [blame] | 471 | utilities.assert_equals( expect=main.TRUE, |
| 472 | actual=response, |
| 473 | onpass="Successfully Added Flows", |
| 474 | onfail="Failed to Add flows" ) |
| 475 | |
| 476 | # Giving ONOS time to add the flow |
| 477 | time.sleep( main.addFlowSleep ) |
| 478 | |
Jon Hall | 602d0a7 | 2017-05-24 16:06:53 -0700 | [diff] [blame] | 479 | response = main.ONOSrest.getFlows( deviceId=deviceId ) |
kavitha Alagesan | 373e055 | 2016-11-22 05:22:05 +0530 | [diff] [blame] | 480 | responsejson = json.loads( response ) |
Jon Hall | 602d0a7 | 2017-05-24 16:06:53 -0700 | [diff] [blame] | 481 | for item in responsejson: |
| 482 | if item[ "priority" ] == int( priority ) and item[ "state" ] == "ADDED": |
kavitha Alagesan | 373e055 | 2016-11-22 05:22:05 +0530 | [diff] [blame] | 483 | isAdded = main.TRUE |
| 484 | |
| 485 | utilities.assert_equals( expect=main.TRUE, |
| 486 | actual=isAdded, |
| 487 | onpass="Flow is in Added State", |
| 488 | onfail="Flow is not in Added State" ) |
| 489 | |
Jon Hall | 602d0a7 | 2017-05-24 16:06:53 -0700 | [diff] [blame] | 490 | """ |
kavitha Alagesan | 373e055 | 2016-11-22 05:22:05 +0530 | [diff] [blame] | 491 | Sends a packet using scapy |
Jon Hall | 602d0a7 | 2017-05-24 16:06:53 -0700 | [diff] [blame] | 492 | """ |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 493 | main.step( "Testing Group by sending packet using Scapy" ) |
kavitha Alagesan | 373e055 | 2016-11-22 05:22:05 +0530 | [diff] [blame] | 494 | main.log.info( "Creating host components" ) |
| 495 | main.Scapy.createHostComponent( "h1" ) |
| 496 | main.Scapy.createHostComponent( "h2" ) |
| 497 | |
Jon Hall | 602d0a7 | 2017-05-24 16:06:53 -0700 | [diff] [blame] | 498 | hosts = [ main.h1, main.h2 ] |
kavitha Alagesan | 373e055 | 2016-11-22 05:22:05 +0530 | [diff] [blame] | 499 | for host in hosts: |
Jon Hall | 602d0a7 | 2017-05-24 16:06:53 -0700 | [diff] [blame] | 500 | host.startHostCli() |
| 501 | host.startScapy() |
| 502 | host.updateSelf() |
kavitha Alagesan | 373e055 | 2016-11-22 05:22:05 +0530 | [diff] [blame] | 503 | main.log.info( "Constructing Packet" ) |
| 504 | main.h1.buildEther( dst=main.h1.hostMac ) |
| 505 | main.h1.buildIP( dst=main.h1.hostIp ) |
| 506 | main.log.info( "Start Filter on host2" ) |
| 507 | main.h2.startFilter( pktFilter="ether host %s and ip host %s" % ( main.h1.hostMac, main.h1.hostIp ) ) |
| 508 | main.log.info( "sending packet to Host" ) |
Jon Hall | 602d0a7 | 2017-05-24 16:06:53 -0700 | [diff] [blame] | 509 | main.h1.sendPacket() |
kavitha Alagesan | 373e055 | 2016-11-22 05:22:05 +0530 | [diff] [blame] | 510 | main.log.info( "Checking filter for our packet" ) |
Jon Hall | 602d0a7 | 2017-05-24 16:06:53 -0700 | [diff] [blame] | 511 | stepResultH2 = main.h2.checkFilter() |
kavitha Alagesan | 373e055 | 2016-11-22 05:22:05 +0530 | [diff] [blame] | 512 | |
| 513 | if stepResultH2: |
Jon Hall | 602d0a7 | 2017-05-24 16:06:53 -0700 | [diff] [blame] | 514 | main.log.info( "Packet : %s" % main.h2.readPackets() ) |
kavitha Alagesan | 373e055 | 2016-11-22 05:22:05 +0530 | [diff] [blame] | 515 | else: |
Jon Hall | 602d0a7 | 2017-05-24 16:06:53 -0700 | [diff] [blame] | 516 | main.h2.killFilter() |
kavitha Alagesan | 373e055 | 2016-11-22 05:22:05 +0530 | [diff] [blame] | 517 | |
| 518 | main.log.info( "Clean up host components" ) |
| 519 | for host in hosts: |
Jon Hall | 602d0a7 | 2017-05-24 16:06:53 -0700 | [diff] [blame] | 520 | host.stopScapy() |
kavitha Alagesan | 373e055 | 2016-11-22 05:22:05 +0530 | [diff] [blame] | 521 | main.Mininet1.removeHostComponent( "h1" ) |
| 522 | main.Mininet1.removeHostComponent( "h2" ) |
| 523 | |
| 524 | utilities.assert_equals( expect=main.TRUE, |
| 525 | actual=stepResultH2, |
| 526 | onpass="Packet sent to port 1 is received at port 2 successfully!!!", |
| 527 | onfail="Failure!!!Packet sent to port 1 is not received at port 2" ) |
| 528 | |
kavitha Alagesan | 373e055 | 2016-11-22 05:22:05 +0530 | [diff] [blame] | 529 | def CASE100( self, main ): |
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 | Report errors/warnings/exceptions |
Jon Hall | 602d0a7 | 2017-05-24 16:06:53 -0700 | [diff] [blame] | 532 | """ |
kavitha Alagesan | 373e055 | 2016-11-22 05:22:05 +0530 | [diff] [blame] | 533 | main.log.info( "Error report: \n" ) |
| 534 | main.ONOSbench.logReport( main.ONOSip[ 0 ], |
| 535 | [ "INFO", |
| 536 | "FOLLOWER", |
| 537 | "WARN", |
| 538 | "flow", |
| 539 | "group", |
| 540 | "ERROR", |
| 541 | "Except" ], |
| 542 | "s" ) |