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