GlennRC | 5147a42 | 2015-10-06 17:26:17 -0700 | [diff] [blame] | 1 | class FUNCflow: |
| 2 | |
| 3 | def __init__( self ): |
| 4 | self.default = '' |
| 5 | |
| 6 | def CASE1( self, main ): |
| 7 | import time |
| 8 | import os |
| 9 | import imp |
| 10 | |
| 11 | """ |
| 12 | - Construct tests variables |
| 13 | - GIT ( optional ) |
| 14 | - Checkout ONOS master branch |
| 15 | - Pull latest ONOS code |
| 16 | - Building ONOS ( optional ) |
| 17 | - Install ONOS package |
| 18 | - Build ONOS package |
| 19 | """ |
| 20 | |
| 21 | main.case( "Constructing test variables and building ONOS package" ) |
| 22 | main.step( "Constructing test variables" ) |
| 23 | stepResult = main.FALSE |
| 24 | |
| 25 | # Test variables |
| 26 | main.testOnDirectory = os.path.dirname( os.getcwd ( ) ) |
| 27 | main.cellName = main.params[ 'ENV' ][ 'cellName' ] |
| 28 | main.apps = main.params[ 'ENV' ][ 'cellApps' ] |
| 29 | gitBranch = main.params[ 'GIT' ][ 'branch' ] |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 30 | gitPull = main.params[ 'GIT' ][ 'pull' ] |
| 31 | main.ONOSport = main.params[ 'CTRL' ][ 'port' ] |
GlennRC | 5147a42 | 2015-10-06 17:26:17 -0700 | [diff] [blame] | 32 | main.dependencyPath = main.testOnDirectory + \ |
| 33 | main.params[ 'DEPENDENCY' ][ 'path' ] |
GlennRC | 5147a42 | 2015-10-06 17:26:17 -0700 | [diff] [blame] | 34 | wrapperFile1 = main.params[ 'DEPENDENCY' ][ 'wrapper1' ] |
GlennRC | 1704d07 | 2015-10-07 18:40:45 -0700 | [diff] [blame] | 35 | wrapperFile2 = main.params[ 'DEPENDENCY' ][ 'wrapper2' ] |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 36 | main.topology = main.params[ 'DEPENDENCY' ][ 'topology' ] |
| 37 | main.maxNodes = int( main.params[ 'SCALE' ][ 'max' ] ) |
GlennRC | 5147a42 | 2015-10-06 17:26:17 -0700 | [diff] [blame] | 38 | main.startUpSleep = int( main.params[ 'SLEEP' ][ 'startup' ] ) |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 39 | main.startMNSleep = int( main.params[ 'SLEEP' ][ 'startMN' ] ) |
| 40 | main.addFlowSleep = int( main.params[ 'SLEEP' ][ 'addFlow' ] ) |
| 41 | main.delFlowSleep = int( main.params[ 'SLEEP' ][ 'delFlow' ] ) |
GlennRC | 956ea74 | 2015-11-05 16:14:15 -0800 | [diff] [blame] | 42 | main.debug = main.params['DEBUG'] |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 43 | main.swDPID = main.params[ 'TEST' ][ 'swDPID' ] |
GlennRC | 5147a42 | 2015-10-06 17:26:17 -0700 | [diff] [blame] | 44 | main.cellData = {} # for creating cell file |
| 45 | main.CLIs = [] |
| 46 | main.ONOSip = [] |
| 47 | |
GlennRC | 956ea74 | 2015-11-05 16:14:15 -0800 | [diff] [blame] | 48 | main.debug = True if "on" in main.debug else False |
| 49 | |
GlennRC | 5147a42 | 2015-10-06 17:26:17 -0700 | [diff] [blame] | 50 | main.ONOSip = main.ONOSbench.getOnosIps() |
GlennRC | 5147a42 | 2015-10-06 17:26:17 -0700 | [diff] [blame] | 51 | |
| 52 | # Assigning ONOS cli handles to a list |
| 53 | for i in range( 1, main.maxNodes + 1 ): |
| 54 | main.CLIs.append( getattr( main, 'ONOScli' + str( i ) ) ) |
| 55 | |
| 56 | # -- INIT SECTION, ONLY RUNS ONCE -- # |
| 57 | main.startUp = imp.load_source( wrapperFile1, |
| 58 | main.dependencyPath + |
| 59 | wrapperFile1 + |
| 60 | ".py" ) |
| 61 | |
GlennRC | 1704d07 | 2015-10-07 18:40:45 -0700 | [diff] [blame] | 62 | main.topo = imp.load_source( wrapperFile2, |
| 63 | main.dependencyPath + |
| 64 | wrapperFile2 + |
| 65 | ".py" ) |
| 66 | |
GlennRC | 956ea74 | 2015-11-05 16:14:15 -0800 | [diff] [blame] | 67 | |
GlennRC | 94ed223 | 2015-10-07 15:08:57 -0700 | [diff] [blame] | 68 | copyResult = main.ONOSbench.scp( main.Mininet1, |
| 69 | main.dependencyPath+main.topology, |
| 70 | main.Mininet1.home+'/custom/', |
| 71 | direction="to" ) |
| 72 | |
GlennRC | 5147a42 | 2015-10-06 17:26:17 -0700 | [diff] [blame] | 73 | if main.CLIs: |
| 74 | stepResult = main.TRUE |
| 75 | else: |
| 76 | main.log.error( "Did not properly created list of ONOS CLI handle" ) |
| 77 | stepResult = main.FALSE |
| 78 | |
| 79 | utilities.assert_equals( expect=main.TRUE, |
| 80 | actual=stepResult, |
| 81 | onpass="Successfully construct " + |
| 82 | "test variables ", |
| 83 | onfail="Failed to construct test variables" ) |
| 84 | |
| 85 | if gitPull == 'True': |
| 86 | main.step( "Building ONOS in " + gitBranch + " branch" ) |
| 87 | onosBuildResult = main.startUp.onosBuild( main, gitBranch ) |
| 88 | stepResult = onosBuildResult |
| 89 | utilities.assert_equals( expect=main.TRUE, |
| 90 | actual=stepResult, |
| 91 | onpass="Successfully compiled " + |
| 92 | "latest ONOS", |
| 93 | onfail="Failed to compile " + |
| 94 | "latest ONOS" ) |
| 95 | else: |
| 96 | main.log.warn( "Did not pull new code so skipping mvn " + |
| 97 | "clean install" ) |
| 98 | |
| 99 | def CASE2( self, main ): |
| 100 | """ |
| 101 | - Set up cell |
| 102 | - Create cell file |
| 103 | - Set cell file |
| 104 | - Verify cell file |
| 105 | - Kill ONOS process |
| 106 | - Uninstall ONOS cluster |
| 107 | - Verify ONOS start up |
| 108 | - Install ONOS cluster |
| 109 | - Connect to cli |
| 110 | """ |
| 111 | |
| 112 | main.numCtrls = int( main.maxNodes ) |
| 113 | |
| 114 | main.case( "Starting up " + str( main.numCtrls ) + |
| 115 | " node(s) ONOS cluster" ) |
| 116 | |
| 117 | #kill off all onos processes |
| 118 | main.log.info( "Safety check, killing all ONOS processes" + |
| 119 | " before initiating enviornment setup" ) |
| 120 | |
| 121 | for i in range( main.maxNodes ): |
| 122 | main.ONOSbench.onosDie( main.ONOSip[ i ] ) |
| 123 | |
| 124 | print "NODE COUNT = ", main.numCtrls |
| 125 | |
| 126 | tempOnosIp = [] |
| 127 | for i in range( main.numCtrls ): |
| 128 | tempOnosIp.append( main.ONOSip[i] ) |
| 129 | |
| 130 | main.ONOSbench.createCellFile( main.ONOSbench.ip_address, "temp", main.Mininet1.ip_address, main.apps, tempOnosIp ) |
| 131 | |
| 132 | main.step( "Apply cell to environment" ) |
| 133 | cellResult = main.ONOSbench.setCell( "temp" ) |
| 134 | verifyResult = main.ONOSbench.verifyCell() |
| 135 | stepResult = cellResult and verifyResult |
| 136 | utilities.assert_equals( expect=main.TRUE, |
| 137 | actual=stepResult, |
| 138 | onpass="Successfully applied cell to " + \ |
| 139 | "environment", |
| 140 | onfail="Failed to apply cell to environment " ) |
| 141 | |
| 142 | main.step( "Creating ONOS package" ) |
| 143 | packageResult = main.ONOSbench.onosPackage() |
| 144 | stepResult = packageResult |
| 145 | utilities.assert_equals( expect=main.TRUE, |
| 146 | actual=stepResult, |
| 147 | onpass="Successfully created ONOS package", |
| 148 | onfail="Failed to create ONOS package" ) |
| 149 | |
| 150 | time.sleep( main.startUpSleep ) |
| 151 | main.step( "Uninstalling ONOS package" ) |
| 152 | onosUninstallResult = main.TRUE |
| 153 | for i in range( main.numCtrls ): |
| 154 | onosUninstallResult = onosUninstallResult and \ |
| 155 | main.ONOSbench.onosUninstall( nodeIp=main.ONOSip[ i ] ) |
| 156 | stepResult = onosUninstallResult |
| 157 | utilities.assert_equals( expect=main.TRUE, |
| 158 | actual=stepResult, |
| 159 | onpass="Successfully uninstalled ONOS package", |
| 160 | onfail="Failed to uninstall ONOS package" ) |
| 161 | |
| 162 | time.sleep( main.startUpSleep ) |
| 163 | main.step( "Installing ONOS package" ) |
| 164 | onosInstallResult = main.TRUE |
| 165 | for i in range( main.numCtrls ): |
| 166 | onosInstallResult = onosInstallResult and \ |
| 167 | main.ONOSbench.onosInstall( node=main.ONOSip[ i ] ) |
| 168 | stepResult = onosInstallResult |
| 169 | utilities.assert_equals( expect=main.TRUE, |
| 170 | actual=stepResult, |
| 171 | onpass="Successfully installed ONOS package", |
| 172 | onfail="Failed to install ONOS package" ) |
| 173 | |
| 174 | time.sleep( main.startUpSleep ) |
| 175 | main.step( "Starting ONOS service" ) |
| 176 | stopResult = main.TRUE |
| 177 | startResult = main.TRUE |
| 178 | onosIsUp = main.TRUE |
| 179 | |
| 180 | for i in range( main.numCtrls ): |
| 181 | onosIsUp = onosIsUp and main.ONOSbench.isup( main.ONOSip[ i ] ) |
| 182 | if onosIsUp == main.TRUE: |
| 183 | main.log.report( "ONOS instance is up and ready" ) |
| 184 | else: |
| 185 | main.log.report( "ONOS instance may not be up, stop and " + |
| 186 | "start ONOS again " ) |
| 187 | for i in range( main.numCtrls ): |
| 188 | stopResult = stopResult and \ |
| 189 | main.ONOSbench.onosStop( main.ONOSip[ i ] ) |
| 190 | for i in range( main.numCtrls ): |
| 191 | startResult = startResult and \ |
| 192 | main.ONOSbench.onosStart( main.ONOSip[ i ] ) |
| 193 | stepResult = onosIsUp and stopResult and startResult |
| 194 | utilities.assert_equals( expect=main.TRUE, |
| 195 | actual=stepResult, |
| 196 | onpass="ONOS service is ready", |
| 197 | onfail="ONOS service did not start properly" ) |
| 198 | |
| 199 | main.step( "Start ONOS cli" ) |
| 200 | cliResult = main.TRUE |
| 201 | for i in range( main.numCtrls ): |
| 202 | cliResult = cliResult and \ |
| 203 | main.CLIs[ i ].startOnosCli( main.ONOSip[ i ] ) |
| 204 | stepResult = cliResult |
| 205 | utilities.assert_equals( expect=main.TRUE, |
| 206 | actual=stepResult, |
| 207 | onpass="Successfully start ONOS cli", |
| 208 | onfail="Failed to start ONOS cli" ) |
| 209 | |
GlennRC | 6844994 | 2015-10-16 16:03:12 -0700 | [diff] [blame] | 210 | def CASE10( self, main ): |
| 211 | ''' |
| 212 | Start Mininet |
| 213 | ''' |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 214 | import json |
| 215 | |
| 216 | main.case( "Setup mininet and compare ONOS topology view to Mininet topology" ) |
| 217 | main.caseExplanation = "Start mininet with custom topology and compare topology " +\ |
| 218 | "elements between Mininet and ONOS" |
| 219 | |
GlennRC | 6844994 | 2015-10-16 16:03:12 -0700 | [diff] [blame] | 220 | main.step( "Setup Mininet Topology" ) |
| 221 | topology = main.Mininet1.home + '/custom/' + main.topology |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 222 | stepResult = main.Mininet1.startNet( topoFile=topology ) |
GlennRC | 6844994 | 2015-10-16 16:03:12 -0700 | [diff] [blame] | 223 | |
| 224 | utilities.assert_equals( expect=main.TRUE, |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 225 | actual=stepResult, |
GlennRC | 6844994 | 2015-10-16 16:03:12 -0700 | [diff] [blame] | 226 | onpass="Successfully loaded topology", |
| 227 | onfail="Failed to load topology" ) |
| 228 | |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 229 | main.step( "Assign switch to controller" ) |
| 230 | stepResult = main.Mininet1.assignSwController( "s1", main.ONOSip[0] ) |
GlennRC | 6844994 | 2015-10-16 16:03:12 -0700 | [diff] [blame] | 231 | |
| 232 | utilities.assert_equals( expect=main.TRUE, |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 233 | actual=stepResult, |
| 234 | onpass="Successfully assigned switch to controller", |
| 235 | onfail="Failed to assign switch to controller" ) |
GlennRC | 6844994 | 2015-10-16 16:03:12 -0700 | [diff] [blame] | 236 | |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 237 | time.sleep( main.startMNSleep ) |
GlennRC | 6844994 | 2015-10-16 16:03:12 -0700 | [diff] [blame] | 238 | |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 239 | main.step( "Conmparing MN topology to ONOS topology" ) |
| 240 | main.log.info( "Gathering topology information" ) |
GlennRC | 1704d07 | 2015-10-07 18:40:45 -0700 | [diff] [blame] | 241 | devicesResults = main.TRUE |
| 242 | linksResults = main.TRUE |
| 243 | hostsResults = main.TRUE |
| 244 | devices = main.topo.getAllDevices( main ) |
| 245 | hosts = main.topo.getAllHosts( main ) |
| 246 | ports = main.topo.getAllPorts( main ) |
| 247 | links = main.topo.getAllLinks( main ) |
| 248 | clusters = main.topo.getAllClusters( main ) |
| 249 | |
| 250 | mnSwitches = main.Mininet1.getSwitches() |
| 251 | mnLinks = main.Mininet1.getLinks() |
| 252 | mnHosts = main.Mininet1.getHosts() |
| 253 | |
GlennRC | 1704d07 | 2015-10-07 18:40:45 -0700 | [diff] [blame] | 254 | for controller in range( main.numCtrls ): |
| 255 | controllerStr = str( controller + 1 ) |
| 256 | if devices[ controller ] and ports[ controller ] and\ |
| 257 | "Error" not in devices[ controller ] and\ |
| 258 | "Error" not in ports[ controller ]: |
| 259 | |
| 260 | currentDevicesResult = main.Mininet1.compareSwitches( |
| 261 | mnSwitches, |
| 262 | json.loads( devices[ controller ] ), |
| 263 | json.loads( ports[ controller ] ) ) |
| 264 | else: |
| 265 | currentDevicesResult = main.FALSE |
| 266 | utilities.assert_equals( expect=main.TRUE, |
| 267 | actual=currentDevicesResult, |
| 268 | onpass="ONOS" + controllerStr + |
GlennRC | 6844994 | 2015-10-16 16:03:12 -0700 | [diff] [blame] | 269 | " Switches view is correct", |
GlennRC | 1704d07 | 2015-10-07 18:40:45 -0700 | [diff] [blame] | 270 | onfail="ONOS" + controllerStr + |
GlennRC | 6844994 | 2015-10-16 16:03:12 -0700 | [diff] [blame] | 271 | " Switches view is incorrect" ) |
GlennRC | 1704d07 | 2015-10-07 18:40:45 -0700 | [diff] [blame] | 272 | if links[ controller ] and "Error" not in links[ controller ]: |
| 273 | currentLinksResult = main.Mininet1.compareLinks( |
| 274 | mnSwitches, mnLinks, |
| 275 | json.loads( links[ controller ] ) ) |
| 276 | else: |
| 277 | currentLinksResult = main.FALSE |
| 278 | utilities.assert_equals( expect=main.TRUE, |
| 279 | actual=currentLinksResult, |
| 280 | onpass="ONOS" + controllerStr + |
GlennRC | 6844994 | 2015-10-16 16:03:12 -0700 | [diff] [blame] | 281 | " links view is correct", |
GlennRC | 1704d07 | 2015-10-07 18:40:45 -0700 | [diff] [blame] | 282 | onfail="ONOS" + controllerStr + |
GlennRC | 6844994 | 2015-10-16 16:03:12 -0700 | [diff] [blame] | 283 | " links view is incorrect" ) |
GlennRC | 1704d07 | 2015-10-07 18:40:45 -0700 | [diff] [blame] | 284 | |
| 285 | if hosts[ controller ] or "Error" not in hosts[ controller ]: |
| 286 | currentHostsResult = main.Mininet1.compareHosts( |
| 287 | mnHosts, |
| 288 | json.loads( hosts[ controller ] ) ) |
| 289 | else: |
| 290 | currentHostsResult = main.FALSE |
| 291 | utilities.assert_equals( expect=main.TRUE, |
| 292 | actual=currentHostsResult, |
| 293 | onpass="ONOS" + controllerStr + |
GlennRC | 6844994 | 2015-10-16 16:03:12 -0700 | [diff] [blame] | 294 | " hosts exist in Mininet", |
GlennRC | 1704d07 | 2015-10-07 18:40:45 -0700 | [diff] [blame] | 295 | onfail="ONOS" + controllerStr + |
GlennRC | 6844994 | 2015-10-16 16:03:12 -0700 | [diff] [blame] | 296 | " hosts don't match Mininet") |
GlennRC | a539137 | 2015-10-14 17:28:15 -0700 | [diff] [blame] | 297 | |
GlennRC | 6844994 | 2015-10-16 16:03:12 -0700 | [diff] [blame] | 298 | |
Jon Hall | 892818c | 2015-10-20 17:58:34 -0700 | [diff] [blame] | 299 | def CASE66( self, main ): |
| 300 | ''' |
| 301 | Testing scapy |
| 302 | ''' |
| 303 | main.case( "Testing scapy" ) |
| 304 | main.step( "Creating Host1 component" ) |
| 305 | main.Mininet1.createHostComponent( "h1" ) |
| 306 | main.Mininet1.createHostComponent( "h2" ) |
| 307 | hosts = [main.h1, main.h2] |
| 308 | for host in hosts: |
| 309 | host.startHostCli() |
| 310 | host.startScapy() |
| 311 | host.updateSelf() |
| 312 | main.log.debug( host.name ) |
| 313 | main.log.debug( host.hostIp ) |
| 314 | main.log.debug( host.hostMac ) |
| 315 | |
| 316 | main.step( "Sending/Receiving Test packet - Filter doesn't match" ) |
| 317 | main.h2.startFilter() |
| 318 | main.h1.buildEther( dst=main.h2.hostMac ) |
| 319 | main.h1.sendPacket( ) |
| 320 | finished = main.h2.checkFilter() |
| 321 | i = "" |
| 322 | if finished: |
| 323 | a = main.h2.readPackets() |
| 324 | for i in a.splitlines(): |
| 325 | main.log.info( i ) |
| 326 | else: |
| 327 | kill = main.h2.killFilter() |
| 328 | main.log.debug( kill ) |
| 329 | main.h2.handle.sendline( "" ) |
| 330 | main.h2.handle.expect( main.h2.scapyPrompt ) |
| 331 | main.log.debug( main.h2.handle.before ) |
| 332 | utilities.assert_equals( expect=True, |
| 333 | actual="dst=00:00:00:00:00:02 src=00:00:00:00:00:01" in i, |
| 334 | onpass="Pass", |
| 335 | onfail="Fail" ) |
| 336 | |
| 337 | main.step( "Sending/Receiving Test packet - Filter matches" ) |
| 338 | main.h2.startFilter() |
| 339 | main.h1.buildEther( dst=main.h2.hostMac ) |
| 340 | main.h1.buildIP( dst=main.h2.hostIp ) |
| 341 | main.h1.sendPacket( ) |
| 342 | finished = main.h2.checkFilter() |
| 343 | i = "" |
| 344 | if finished: |
| 345 | a = main.h2.readPackets() |
| 346 | for i in a.splitlines(): |
| 347 | main.log.info( i ) |
| 348 | else: |
| 349 | kill = main.h2.killFilter() |
| 350 | main.log.debug( kill ) |
| 351 | main.h2.handle.sendline( "" ) |
| 352 | main.h2.handle.expect( main.h2.scapyPrompt ) |
| 353 | main.log.debug( main.h2.handle.before ) |
| 354 | utilities.assert_equals( expect=True, |
| 355 | actual="dst=00:00:00:00:00:02 src=00:00:00:00:00:01" in i, |
| 356 | onpass="Pass", |
| 357 | onfail="Fail" ) |
| 358 | |
| 359 | |
| 360 | |
| 361 | main.step( "Clean up host components" ) |
| 362 | for host in hosts: |
| 363 | host.stopScapy() |
| 364 | main.Mininet1.removeHostComponent("h1") |
| 365 | main.Mininet1.removeHostComponent("h2") |
| 366 | |
GlennRC | 6844994 | 2015-10-16 16:03:12 -0700 | [diff] [blame] | 367 | def CASE1000( self, main ): |
| 368 | ''' |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 369 | Add flows with MAC selectors and verify the flows |
GlennRC | 6844994 | 2015-10-16 16:03:12 -0700 | [diff] [blame] | 370 | ''' |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 371 | import json |
| 372 | import time |
GlennRC | 6844994 | 2015-10-16 16:03:12 -0700 | [diff] [blame] | 373 | |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 374 | main.case( "Verify flow MAC selectors are correctly compiled" ) |
| 375 | main.caseExplanation = "Install two flows with only MAC selectors " +\ |
| 376 | "specified, then verify flows are added in ONOS, finally "+\ |
| 377 | "send a packet that only specifies the MAC src and dst." |
GlennRC | 6844994 | 2015-10-16 16:03:12 -0700 | [diff] [blame] | 378 | |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 379 | main.step( "Add flows with MAC addresses as the only selectors" ) |
GlennRC | 6844994 | 2015-10-16 16:03:12 -0700 | [diff] [blame] | 380 | |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 381 | main.log.info( "Creating host components" ) |
| 382 | main.Mininet1.createHostComponent( "h1" ) |
| 383 | main.Mininet1.createHostComponent( "h2" ) |
| 384 | hosts = [main.h1, main.h2] |
| 385 | stepResult = main.TRUE |
| 386 | for host in hosts: |
| 387 | host.startHostCli() |
| 388 | host.startScapy() |
| 389 | host.updateSelf() |
GlennRC | 6844994 | 2015-10-16 16:03:12 -0700 | [diff] [blame] | 390 | |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 391 | # Add a flow that connects host1 on port1 to host2 on port2 |
| 392 | # send output on port2 |
| 393 | # recieve input on port1 |
| 394 | egress = 2 |
| 395 | ingress = 1 |
| 396 | |
| 397 | # Add flows that sends packets from port1 to port2 with correct |
| 398 | # MAC src and dst addresses |
| 399 | main.log.info( "Adding flow with MAC selectors" ) |
| 400 | stepResult = main.ONOSrest.addFlow( deviceId=main.swDPID, |
| 401 | egressPort=egress, |
| 402 | ingressPort=ingress, |
| 403 | ethSrc=main.h1.hostMac, |
| 404 | ethDst=main.h2.hostMac, |
GlennRC | 956ea74 | 2015-11-05 16:14:15 -0800 | [diff] [blame] | 405 | debug=main.debug ) |
GlennRC | 6844994 | 2015-10-16 16:03:12 -0700 | [diff] [blame] | 406 | |
GlennRC | a539137 | 2015-10-14 17:28:15 -0700 | [diff] [blame] | 407 | utilities.assert_equals( expect=main.TRUE, |
| 408 | actual=stepResult, |
GlennRC | 6844994 | 2015-10-16 16:03:12 -0700 | [diff] [blame] | 409 | onpass="Successfully added flows", |
| 410 | onfail="Failed add flows" ) |
GlennRC | a539137 | 2015-10-14 17:28:15 -0700 | [diff] [blame] | 411 | |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 412 | # Giving ONOS time to add the flows |
| 413 | time.sleep( main.addFlowSleep ) |
GlennRC | 5147a42 | 2015-10-06 17:26:17 -0700 | [diff] [blame] | 414 | |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 415 | main.step( "Check flows are in the ADDED state" ) |
| 416 | |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 417 | main.log.info( "Get the flows from ONOS" ) |
GlennRC | 6844994 | 2015-10-16 16:03:12 -0700 | [diff] [blame] | 418 | flows = json.loads( main.ONOSrest.flows() ) |
| 419 | |
| 420 | stepResult = main.TRUE |
| 421 | for f in flows: |
| 422 | if "rest" in f.get("appId"): |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 423 | if "ADDED" not in f.get("state"): |
| 424 | stepResult = main.FALSE |
| 425 | main.log.error( "Flow: %s in state: %s" % (f.get("id"), f.get("state")) ) |
GlennRC | 6844994 | 2015-10-16 16:03:12 -0700 | [diff] [blame] | 426 | |
| 427 | utilities.assert_equals( expect=main.TRUE, |
| 428 | actual=stepResult, |
| 429 | onpass="All flows are in the ADDED state", |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 430 | onfail="All flows are NOT in the ADDED state" ) |
GlennRC | 6844994 | 2015-10-16 16:03:12 -0700 | [diff] [blame] | 431 | |
GlennRC | 956ea74 | 2015-11-05 16:14:15 -0800 | [diff] [blame] | 432 | main.step( "Check flows are in Mininet's flow table" ) |
| 433 | |
| 434 | # get the flow IDs that were added through rest |
| 435 | main.log.info( "Getting the flow IDs from ONOS" ) |
| 436 | flowIds = [ f.get("id") for f in flows if "rest" in f.get("appId") ] |
| 437 | # convert the flowIDs to ints then hex and finally back to strings |
| 438 | flowIds = [str(hex(int(x))) for x in flowIds] |
| 439 | main.log.info( "ONOS flow IDs: {}".format(flowIds) ) |
| 440 | |
| 441 | stepResult = main.Mininet1.checkFlowId( "s1", flowIds, debug=False ) |
| 442 | |
| 443 | utilities.assert_equals( expect=main.TRUE, |
| 444 | actual=stepResult, |
| 445 | onpass="All flows are in mininet", |
| 446 | onfail="All flows are NOT in mininet" ) |
| 447 | |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 448 | main.step( "Send a packet to verify the flows are correct" ) |
| 449 | |
| 450 | # Specify the src and dst MAC addr |
| 451 | main.log.info( "Constructing packet" ) |
| 452 | main.h1.buildEther( src=main.h1.hostMac, dst=main.h2.hostMac ) |
| 453 | |
| 454 | # Filter for packets with the correct host name. Otherwise, |
| 455 | # the filter we catch any packet that is sent to host2 |
| 456 | # NOTE: I believe it doesn't matter which host name it is, |
GlennRC | 956ea74 | 2015-11-05 16:14:15 -0800 | [diff] [blame] | 457 | # as long as the src and dst are both specified |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 458 | main.log.info( "Starting filter on host2" ) |
| 459 | main.h2.startFilter( pktFilter="ether host %s" % main.h1.hostMac) |
| 460 | |
| 461 | main.log.info( "Sending packet to host2" ) |
| 462 | main.h1.sendPacket() |
| 463 | |
| 464 | main.log.info( "Checking filter for our packet" ) |
| 465 | stepResult = main.h2.checkFilter() |
| 466 | if stepResult: |
| 467 | main.log.info( "Packet: %s" % main.h2.readPackets() ) |
| 468 | else: main.h2.killFilter() |
| 469 | |
| 470 | main.log.info( "Clean up host components" ) |
| 471 | for host in hosts: |
| 472 | host.stopScapy() |
| 473 | main.Mininet1.removeHostComponent("h1") |
| 474 | main.Mininet1.removeHostComponent("h2") |
| 475 | |
| 476 | utilities.assert_equals( expect=main.TRUE, |
| 477 | actual=stepResult, |
| 478 | onpass="Successfully sent a packet", |
| 479 | onfail="Failed to send a packet" ) |
| 480 | |
| 481 | def CASE1100( self, main ): |
GlennRC | 6844994 | 2015-10-16 16:03:12 -0700 | [diff] [blame] | 482 | ''' |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 483 | Add flows with IPv4 selectors and verify the flows |
GlennRC | 6844994 | 2015-10-16 16:03:12 -0700 | [diff] [blame] | 484 | ''' |
| 485 | import json |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 486 | import time |
GlennRC | 6844994 | 2015-10-16 16:03:12 -0700 | [diff] [blame] | 487 | |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 488 | main.case( "Verify flow IP selectors are correctly compiled" ) |
| 489 | main.caseExplanation = "Install two flows with only IP selectors " +\ |
| 490 | "specified, then verify flows are added in ONOS, finally "+\ |
| 491 | "send a packet that only specifies the IP src and dst." |
| 492 | |
| 493 | main.step( "Add flows with IPv4 addresses as the only selectors" ) |
| 494 | |
| 495 | main.log.info( "Creating host components" ) |
| 496 | main.Mininet1.createHostComponent( "h1" ) |
| 497 | main.Mininet1.createHostComponent( "h2" ) |
| 498 | hosts = [main.h1, main.h2] |
| 499 | stepResult = main.TRUE |
| 500 | for host in hosts: |
| 501 | host.startHostCli() |
| 502 | host.startScapy() |
| 503 | host.updateSelf() |
| 504 | |
| 505 | # Add a flow that connects host1 on port1 to host2 on port2 |
| 506 | # send output on port2 |
| 507 | # recieve input on port1 |
| 508 | egress = 2 |
| 509 | ingress = 1 |
| 510 | # IPv4 etherType = 0x800 |
| 511 | IPv4=2048 |
| 512 | |
| 513 | # Add flows that connects host1 to host2 |
| 514 | main.log.info( "Add flow with port ingress 1 to port egress 2" ) |
| 515 | stepResult = main.ONOSrest.addFlow( deviceId=main.swDPID, |
| 516 | egressPort=egress, |
| 517 | ingressPort=ingress, |
| 518 | ethType=IPv4, |
| 519 | ipSrc=("IPV4_SRC", main.h1.hostIp+"/32"), |
| 520 | ipDst=("IPV4_DST", main.h2.hostIp+"/32"), |
GlennRC | 956ea74 | 2015-11-05 16:14:15 -0800 | [diff] [blame] | 521 | debug=main.debug ) |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 522 | |
| 523 | utilities.assert_equals( expect=main.TRUE, |
| 524 | actual=stepResult, |
| 525 | onpass="Successfully added flows", |
| 526 | onfail="Failed add flows" ) |
| 527 | |
| 528 | # Giving ONOS time to add the flow |
| 529 | time.sleep( main.addFlowSleep ) |
| 530 | |
| 531 | main.step( "Check flow is in the ADDED state" ) |
| 532 | |
| 533 | main.log.info( "Get the flows from ONOS" ) |
GlennRC | 6844994 | 2015-10-16 16:03:12 -0700 | [diff] [blame] | 534 | flows = json.loads( main.ONOSrest.flows() ) |
| 535 | |
| 536 | stepResult = main.TRUE |
| 537 | for f in flows: |
| 538 | if "rest" in f.get("appId"): |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 539 | if "ADDED" not in f.get("state"): |
| 540 | stepResult = main.FALSE |
| 541 | main.log.error( "Flow: %s in state: %s" % (f.get("id"), f.get("state")) ) |
GlennRC | 6844994 | 2015-10-16 16:03:12 -0700 | [diff] [blame] | 542 | |
| 543 | utilities.assert_equals( expect=main.TRUE, |
| 544 | actual=stepResult, |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 545 | onpass="All flows are in the ADDED state", |
| 546 | onfail="All flows are NOT in the ADDED state" ) |
| 547 | |
GlennRC | 956ea74 | 2015-11-05 16:14:15 -0800 | [diff] [blame] | 548 | main.step( "Check flows are in Mininet's flow table" ) |
| 549 | |
| 550 | # get the flow IDs that were added through rest |
| 551 | main.log.info( "Getting the flow IDs from ONOS" ) |
| 552 | flowIds = [ f.get("id") for f in flows if "rest" in f.get("appId") ] |
| 553 | # convert the flowIDs to ints then hex and finally back to strings |
| 554 | flowIds = [str(hex(int(x))) for x in flowIds] |
| 555 | main.log.info( "ONOS flow IDs: {}".format(flowIds) ) |
| 556 | |
| 557 | stepResult = main.Mininet1.checkFlowId( "s1", flowIds, debug=False ) |
| 558 | |
| 559 | utilities.assert_equals( expect=main.TRUE, |
| 560 | actual=stepResult, |
| 561 | onpass="All flows are in mininet", |
| 562 | onfail="All flows are NOT in mininet" ) |
| 563 | |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 564 | main.step( "Send a packet to verify the flow is correct" ) |
| 565 | |
| 566 | main.log.info( "Constructing packet" ) |
| 567 | # No need for the MAC src dst |
| 568 | main.h1.buildEther( dst=main.h2.hostMac ) |
| 569 | main.h1.buildIP( src=main.h1.hostIp, dst=main.h2.hostIp ) |
| 570 | |
| 571 | main.log.info( "Starting filter on host2" ) |
| 572 | # Defaults to ip |
| 573 | main.h2.startFilter() |
| 574 | |
| 575 | main.log.info( "Sending packet to host2" ) |
| 576 | main.h1.sendPacket() |
| 577 | |
| 578 | main.log.info( "Checking filter for our packet" ) |
| 579 | stepResult = main.h2.checkFilter() |
| 580 | if stepResult: |
| 581 | main.log.info( "Packet: %s" % main.h2.readPackets() ) |
| 582 | else: main.h2.killFilter() |
| 583 | |
| 584 | main.log.info( "Clean up host components" ) |
| 585 | for host in hosts: |
| 586 | host.stopScapy() |
| 587 | main.Mininet1.removeHostComponent("h1") |
| 588 | main.Mininet1.removeHostComponent("h2") |
| 589 | |
| 590 | utilities.assert_equals( expect=main.TRUE, |
| 591 | actual=stepResult, |
| 592 | onpass="Successfully sent a packet", |
| 593 | onfail="Failed to send a packet" ) |
| 594 | |
| 595 | def CASE1200( self, main ): |
| 596 | ''' |
| 597 | Add flow with VLAN selector and verify the flow |
| 598 | ''' |
| 599 | import json |
| 600 | import time |
| 601 | |
| 602 | main.case( "Verify VLAN selector is correctly compiled" ) |
| 603 | main.caseExplanation = "Install one flow with only the VLAN selector " +\ |
| 604 | "specified, then verify the flow is added in ONOS, and finally "+\ |
| 605 | "broadcast a packet with the correct VLAN tag." |
| 606 | |
| 607 | # We do this here to utilize the hosts information |
| 608 | main.log.info( "Creating host components" ) |
| 609 | main.Mininet1.createHostComponent( "h3" ) |
| 610 | main.Mininet1.createHostComponent( "h4" ) |
| 611 | hosts = [main.h3, main.h4] |
| 612 | stepResult = main.TRUE |
| 613 | for host in hosts: |
| 614 | host.startHostCli() |
| 615 | host.startScapy() |
| 616 | host.updateSelf() |
| 617 | |
| 618 | |
| 619 | main.step( "Add a flow with the VLAN tag as the only selector" ) |
| 620 | |
| 621 | # Add flows that connects the two vlan hosts h3 and h4 |
| 622 | # Host 3 is on port 3 and host 4 is on port 4 |
| 623 | vlan = main.params[ 'TEST' ][ 'vlan' ] |
| 624 | egress = 4 |
| 625 | ingress = 3 |
| 626 | # VLAN ethType = 0x8100 |
| 627 | ethType = 33024 |
| 628 | |
| 629 | # Add only one flow because we don't need a response |
| 630 | main.log.info( "Add flow with port ingress 1 to port egress 2" ) |
| 631 | stepResult = main.ONOSrest.addFlow( deviceId=main.swDPID, |
| 632 | egressPort=egress, |
| 633 | ingressPort=ingress, |
| 634 | ethType=ethType, |
| 635 | vlan=vlan, |
GlennRC | 956ea74 | 2015-11-05 16:14:15 -0800 | [diff] [blame] | 636 | debug=main.debug ) |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 637 | |
| 638 | |
| 639 | utilities.assert_equals( expect=main.TRUE, |
| 640 | actual=stepResult, |
| 641 | onpass="Successfully added flow", |
| 642 | onfail="Failed add flows" ) |
| 643 | |
| 644 | # Giving ONOS time to add the flows |
| 645 | time.sleep( main.addFlowSleep ) |
| 646 | |
| 647 | main.step( "Check flows are in the ADDED state" ) |
| 648 | |
| 649 | main.log.info( "Get the flows from ONOS" ) |
| 650 | flows = json.loads( main.ONOSrest.flows() ) |
| 651 | |
| 652 | stepResult = main.TRUE |
| 653 | for f in flows: |
| 654 | if "rest" in f.get("appId"): |
| 655 | if "ADDED" not in f.get("state"): |
| 656 | stepResult = main.FALSE |
| 657 | main.log.error( "Flow: %s in state: %s" % (f.get("id"), f.get("state")) ) |
| 658 | |
| 659 | utilities.assert_equals( expect=main.TRUE, |
| 660 | actual=stepResult, |
| 661 | onpass="All flows are in the ADDED state", |
| 662 | onfail="All flows are NOT in the ADDED state" ) |
| 663 | |
GlennRC | 956ea74 | 2015-11-05 16:14:15 -0800 | [diff] [blame] | 664 | main.step( "Check flows are in Mininet's flow table" ) |
| 665 | |
| 666 | # get the flow IDs that were added through rest |
| 667 | main.log.info( "Getting the flow IDs from ONOS" ) |
| 668 | flowIds = [ f.get("id") for f in flows if "rest" in f.get("appId") ] |
| 669 | # convert the flowIDs to ints then hex and finally back to strings |
| 670 | flowIds = [str(hex(int(x))) for x in flowIds] |
| 671 | main.log.info( "ONOS flow IDs: {}".format(flowIds) ) |
| 672 | |
| 673 | stepResult = main.Mininet1.checkFlowId( "s1", flowIds, debug=False ) |
| 674 | |
| 675 | utilities.assert_equals( expect=main.TRUE, |
| 676 | actual=stepResult, |
| 677 | onpass="All flows are in mininet", |
| 678 | onfail="All flows are NOT in mininet" ) |
| 679 | |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 680 | main.step( "Send a packet to verify the flow are correct" ) |
| 681 | |
| 682 | # The receiving interface |
| 683 | recIface = "{}-eth0.{}".format(main.h4.name, vlan) |
| 684 | main.log.info( "Starting filter on host2" ) |
| 685 | # Filter is setup to catch any packet on the vlan interface with the correct vlan tag |
| 686 | main.h4.startFilter( ifaceName=recIface, pktFilter="" ) |
| 687 | |
| 688 | # Broadcast the packet on the vlan interface. We only care if the flow forwards |
| 689 | # the packet with the correct vlan tag, not if the mac addr is correct |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 690 | sendIface = "{}-eth0.{}".format(main.h3.name, vlan) |
| 691 | main.log.info( "Broadcasting the packet with a vlan tag" ) |
GlennRC | 956ea74 | 2015-11-05 16:14:15 -0800 | [diff] [blame] | 692 | main.h3.sendPacket( iface=sendIface, |
| 693 | packet="Ether()/Dot1Q(vlan={})".format(vlan) ) |
GlennRC | 073e8bc | 2015-10-27 17:11:28 -0700 | [diff] [blame] | 694 | |
| 695 | main.log.info( "Checking filter for our packet" ) |
| 696 | stepResult = main.h4.checkFilter() |
| 697 | if stepResult: |
| 698 | main.log.info( "Packet: %s" % main.h4.readPackets() ) |
| 699 | else: main.h4.killFilter() |
| 700 | |
| 701 | main.log.info( "Clean up host components" ) |
| 702 | for host in hosts: |
| 703 | host.stopScapy() |
| 704 | main.Mininet1.removeHostComponent("h3") |
| 705 | main.Mininet1.removeHostComponent("h4") |
| 706 | |
| 707 | utilities.assert_equals( expect=main.TRUE, |
| 708 | actual=stepResult, |
| 709 | onpass="Successfully sent a packet", |
| 710 | onfail="Failed to send a packet" ) |
GlennRC | 6844994 | 2015-10-16 16:03:12 -0700 | [diff] [blame] | 711 | |
GlennRC | 956ea74 | 2015-11-05 16:14:15 -0800 | [diff] [blame] | 712 | def CASE1300( self, main ): |
| 713 | ''' |
| 714 | Add flows with MPLS selector and verify the flows |
| 715 | ''' |
| 716 | import json |
| 717 | import time |
| 718 | |
| 719 | main.case( "Verify the MPLS selector is correctly compiled on the flow." ) |
| 720 | main.caseExplanation = "Install one flow with an MPLS selector, " +\ |
| 721 | "verify the flow is added in ONOS, and finally "+\ |
| 722 | "send a packet via scapy that has a MPLS label." |
| 723 | |
| 724 | main.step( "Add a flow with a MPLS selector" ) |
| 725 | |
| 726 | main.log.info( "Creating host components" ) |
| 727 | main.Mininet1.createHostComponent( "h1" ) |
| 728 | main.Mininet1.createHostComponent( "h2" ) |
| 729 | hosts = [main.h1, main.h2] |
| 730 | stepResult = main.TRUE |
| 731 | for host in hosts: |
| 732 | host.startHostCli() |
| 733 | host.startScapy( main.dependencyPath ) |
| 734 | host.updateSelf() |
| 735 | |
| 736 | # ports |
| 737 | egress = 2 |
| 738 | ingress = 1 |
| 739 | # MPLS etherType |
| 740 | ethType = main.params[ 'TEST' ][ 'mplsType' ] |
| 741 | # MPLS label |
| 742 | mplsLabel = main.params[ 'TEST' ][ 'mpls' ] |
| 743 | |
| 744 | # Add a flow that connects host1 on port1 to host2 on port2 |
| 745 | main.log.info( "Adding flow with MPLS selector" ) |
| 746 | stepResult = main.ONOSrest.addFlow( deviceId=main.swDPID, |
| 747 | egressPort=egress, |
| 748 | ingressPort=ingress, |
| 749 | ethType=ethType, |
| 750 | mpls=mplsLabel, |
| 751 | debug=main.debug ) |
| 752 | |
| 753 | utilities.assert_equals( expect=main.TRUE, |
| 754 | actual=stepResult, |
| 755 | onpass="Successfully added flow", |
| 756 | onfail="Failed add flow" ) |
| 757 | |
| 758 | # Giving ONOS time to add the flow |
| 759 | time.sleep( main.addFlowSleep ) |
| 760 | |
| 761 | main.step( "Check flow is in the ADDED state" ) |
| 762 | |
| 763 | main.log.info( "Get the flows from ONOS" ) |
| 764 | flows = json.loads( main.ONOSrest.flows() ) |
| 765 | |
| 766 | stepResult = main.TRUE |
| 767 | for f in flows: |
| 768 | if "rest" in f.get("appId"): |
| 769 | if "ADDED" not in f.get("state"): |
| 770 | stepResult = main.FALSE |
| 771 | main.log.error( "Flow: %s in state: %s" % (f.get("id"), f.get("state")) ) |
| 772 | |
| 773 | utilities.assert_equals( expect=main.TRUE, |
| 774 | actual=stepResult, |
| 775 | onpass="All flows are in the ADDED state", |
| 776 | onfail="All flows are NOT in the ADDED state" ) |
| 777 | |
| 778 | main.step( "Check flows are in Mininet's flow table" ) |
| 779 | |
| 780 | # get the flow IDs that were added through rest |
| 781 | main.log.info( "Getting the flow IDs from ONOS" ) |
| 782 | flowIds = [ f.get("id") for f in flows if "rest" in f.get("appId") ] |
| 783 | # convert the flowIDs to ints then hex and finally back to strings |
| 784 | flowIds = [str(hex(int(x))) for x in flowIds] |
| 785 | main.log.info( "ONOS flow IDs: {}".format(flowIds) ) |
| 786 | |
| 787 | stepResult = main.Mininet1.checkFlowId( "s1", flowIds, debug=True ) |
| 788 | |
| 789 | utilities.assert_equals( expect=main.TRUE, |
| 790 | actual=stepResult, |
| 791 | onpass="All flows are in mininet", |
| 792 | onfail="All flows are NOT in mininet" ) |
| 793 | |
| 794 | main.step( "Send a packet to verify the flow is correct" ) |
| 795 | |
| 796 | main.log.info( "Starting filter on host2" ) |
| 797 | main.h2.startFilter( pktFilter="mpls" ) |
| 798 | |
| 799 | main.log.info( "Constructing packet" ) |
| 800 | main.log.info( "Sending packet to host2" ) |
| 801 | main.h1.sendPacket( packet='Ether()/MPLS(label={})'.format(mplsLabel) ) |
| 802 | |
| 803 | main.log.info( "Checking filter for our packet" ) |
| 804 | stepResult = main.h2.checkFilter() |
| 805 | if stepResult: |
| 806 | main.log.info( "Packet: %s" % main.h2.readPackets() ) |
| 807 | else: main.h2.killFilter() |
| 808 | |
| 809 | main.log.info( "Clean up host components" ) |
| 810 | for host in hosts: |
| 811 | host.stopScapy() |
| 812 | main.Mininet1.removeHostComponent("h1") |
| 813 | main.Mininet1.removeHostComponent("h2") |
| 814 | |
| 815 | utilities.assert_equals( expect=main.TRUE, |
| 816 | actual=stepResult, |
| 817 | onpass="Successfully sent a packet", |
| 818 | onfail="Failed to send a packet" ) |
| 819 | |
| 820 | def CASE1400( self, main ): |
| 821 | ''' |
| 822 | Add flows with a TCP selector and verify the flow |
| 823 | ''' |
| 824 | import json |
| 825 | import time |
| 826 | |
| 827 | main.case( "Verify the TCP selector is correctly compiled on the flow" ) |
| 828 | main.caseExplanation = "Install a flow with only the TCP selector " +\ |
| 829 | "specified, verify the flow is added in ONOS, and finally "+\ |
| 830 | "send a TCP packet to verify the TCP selector is compiled correctly." |
| 831 | |
| 832 | main.step( "Add a flow with a TCP selector" ) |
| 833 | |
| 834 | main.log.info( "Creating host components" ) |
| 835 | main.Mininet1.createHostComponent( "h1" ) |
| 836 | main.Mininet1.createHostComponent( "h2" ) |
| 837 | hosts = [main.h1, main.h2] |
| 838 | stepResult = main.TRUE |
| 839 | for host in hosts: |
| 840 | host.startHostCli() |
| 841 | host.startScapy() |
| 842 | host.updateSelf() |
| 843 | |
| 844 | # Add a flow that connects host1 on port1 to host2 on port2 |
| 845 | egress = 2 |
| 846 | ingress = 1 |
| 847 | # IPv4 etherType |
| 848 | ethType = main.params[ 'TEST' ][ 'ip4Type' ] |
| 849 | # IP protocol |
| 850 | ipProto = main.params[ 'TEST' ][ 'tcpProto' ] |
| 851 | # TCP port destination |
| 852 | tcpDst = main.params[ 'TEST' ][ 'tcpDst' ] |
| 853 | |
| 854 | main.log.info( "Add a flow that connects host1 on port1 to host2 on port2" ) |
| 855 | stepResult = main.ONOSrest.addFlow( deviceId=main.swDPID, |
| 856 | egressPort=egress, |
| 857 | ingressPort=ingress, |
| 858 | ethType=ethType, |
| 859 | ipProto=ipProto, |
| 860 | tcpDst=tcpDst, |
| 861 | debug=main.debug ) |
| 862 | |
| 863 | utilities.assert_equals( expect=main.TRUE, |
| 864 | actual=stepResult, |
| 865 | onpass="Successfully added flows", |
| 866 | onfail="Failed add flows" ) |
| 867 | |
| 868 | # Giving ONOS time to add the flow |
| 869 | time.sleep( main.addFlowSleep ) |
| 870 | |
| 871 | main.step( "Check flow is in the ADDED state" ) |
| 872 | |
| 873 | main.log.info( "Get the flows from ONOS" ) |
| 874 | flows = json.loads( main.ONOSrest.flows() ) |
| 875 | |
| 876 | stepResult = main.TRUE |
| 877 | for f in flows: |
| 878 | if "rest" in f.get("appId"): |
| 879 | if "ADDED" not in f.get("state"): |
| 880 | stepResult = main.FALSE |
| 881 | main.log.error( "Flow: %s in state: %s" % (f.get("id"), f.get("state")) ) |
| 882 | |
| 883 | utilities.assert_equals( expect=main.TRUE, |
| 884 | actual=stepResult, |
| 885 | onpass="All flows are in the ADDED state", |
| 886 | onfail="All flows are NOT in the ADDED state" ) |
| 887 | |
| 888 | main.step( "Check flows are in Mininet's flow table" ) |
| 889 | |
| 890 | # get the flow IDs that were added through rest |
| 891 | main.log.info( "Getting the flow IDs from ONOS" ) |
| 892 | flowIds = [ f.get("id") for f in flows if "rest" in f.get("appId") ] |
| 893 | # convert the flowIDs to ints then hex and finally back to strings |
| 894 | flowIds = [str(hex(int(x))) for x in flowIds] |
| 895 | main.log.info( "ONOS flow IDs: {}".format(flowIds) ) |
| 896 | |
| 897 | stepResult = main.Mininet1.checkFlowId( "s1", flowIds, debug=False ) |
| 898 | |
| 899 | utilities.assert_equals( expect=main.TRUE, |
| 900 | actual=stepResult, |
| 901 | onpass="All flows are in mininet", |
| 902 | onfail="All flows are NOT in mininet" ) |
| 903 | |
| 904 | main.step( "Send a packet to verify the flow is correct" ) |
| 905 | |
| 906 | main.log.info( "Constructing packet" ) |
| 907 | # No need for the MAC src dst |
| 908 | main.h1.buildEther( dst=main.h2.hostMac ) |
| 909 | main.h1.buildIP( dst=main.h2.hostIp ) |
| 910 | main.h1.buildTCP( dport=tcpDst ) |
| 911 | |
| 912 | main.log.info( "Starting filter on host2" ) |
| 913 | # Defaults to ip |
| 914 | main.h2.startFilter( pktFilter="tcp" ) |
| 915 | |
| 916 | main.log.info( "Sending packet to host2" ) |
| 917 | main.h1.sendPacket() |
| 918 | |
| 919 | main.log.info( "Checking filter for our packet" ) |
| 920 | stepResult = main.h2.checkFilter() |
| 921 | if stepResult: |
| 922 | main.log.info( "Packet: %s" % main.h2.readPackets() ) |
| 923 | else: main.h2.killFilter() |
| 924 | |
| 925 | main.log.info( "Clean up host components" ) |
| 926 | for host in hosts: |
| 927 | host.stopScapy() |
| 928 | main.Mininet1.removeHostComponent("h1") |
| 929 | main.Mininet1.removeHostComponent("h2") |
| 930 | |
| 931 | utilities.assert_equals( expect=main.TRUE, |
| 932 | actual=stepResult, |
| 933 | onpass="Successfully sent a packet", |
| 934 | onfail="Failed to send a packet" ) |
| 935 | |
| 936 | def CASE1500( self, main ): |
| 937 | ''' |
| 938 | Add flows with a UDP selector and verify the flow |
| 939 | ''' |
| 940 | import json |
| 941 | import time |
| 942 | |
| 943 | main.case( "Verify the UDP selector is correctly compiled on the flow" ) |
| 944 | main.caseExplanation = "Install a flow with only the UDP selector " +\ |
| 945 | "specified, verify the flow is added in ONOS, and finally "+\ |
| 946 | "send a UDP packet to verify the UDP selector is compiled correctly." |
| 947 | |
| 948 | main.step( "Add a flow with a UDP selector" ) |
| 949 | |
| 950 | main.log.info( "Creating host components" ) |
| 951 | main.Mininet1.createHostComponent( "h1" ) |
| 952 | main.Mininet1.createHostComponent( "h2" ) |
| 953 | hosts = [main.h1, main.h2] |
| 954 | stepResult = main.TRUE |
| 955 | for host in hosts: |
| 956 | host.startHostCli() |
| 957 | host.startScapy() |
| 958 | host.updateSelf() |
| 959 | |
| 960 | # Add a flow that connects host1 on port1 to host2 on port2 |
| 961 | egress = 2 |
| 962 | ingress = 1 |
| 963 | # IPv4 etherType |
| 964 | ethType = main.params[ 'TEST' ][ 'ip4Type' ] |
| 965 | # IP protocol |
| 966 | ipProto = main.params[ 'TEST' ][ 'udpProto' ] |
| 967 | # UDP port destination |
| 968 | udpDst = main.params[ 'TEST' ][ 'udpDst' ] |
| 969 | |
| 970 | main.log.info( "Add a flow that connects host1 on port1 to host2 on port2" ) |
| 971 | stepResult = main.ONOSrest.addFlow( deviceId=main.swDPID, |
| 972 | egressPort=egress, |
| 973 | ingressPort=ingress, |
| 974 | ethType=ethType, |
| 975 | ipProto=ipProto, |
| 976 | udpDst=udpDst, |
| 977 | debug=main.debug ) |
| 978 | |
| 979 | utilities.assert_equals( expect=main.TRUE, |
| 980 | actual=stepResult, |
| 981 | onpass="Successfully added flows", |
| 982 | onfail="Failed add flows" ) |
| 983 | |
| 984 | # Giving ONOS time to add the flow |
| 985 | time.sleep( main.addFlowSleep ) |
| 986 | |
| 987 | main.step( "Check flow is in the ADDED state" ) |
| 988 | |
| 989 | main.log.info( "Get the flows from ONOS" ) |
| 990 | flows = json.loads( main.ONOSrest.flows() ) |
| 991 | |
| 992 | stepResult = main.TRUE |
| 993 | for f in flows: |
| 994 | if "rest" in f.get("appId"): |
| 995 | if "ADDED" not in f.get("state"): |
| 996 | stepResult = main.FALSE |
| 997 | main.log.error( "Flow: %s in state: %s" % (f.get("id"), f.get("state")) ) |
| 998 | |
| 999 | utilities.assert_equals( expect=main.TRUE, |
| 1000 | actual=stepResult, |
| 1001 | onpass="All flows are in the ADDED state", |
| 1002 | onfail="All flows are NOT in the ADDED state" ) |
| 1003 | |
| 1004 | main.step( "Check flows are in Mininet's flow table" ) |
| 1005 | |
| 1006 | # get the flow IDs that were added through rest |
| 1007 | main.log.info( "Getting the flow IDs from ONOS" ) |
| 1008 | flowIds = [ f.get("id") for f in flows if "rest" in f.get("appId") ] |
| 1009 | # convert the flowIDs to ints then hex and finally back to strings |
| 1010 | flowIds = [str(hex(int(x))) for x in flowIds] |
| 1011 | main.log.info( "ONOS flow IDs: {}".format(flowIds) ) |
| 1012 | |
| 1013 | stepResult = main.Mininet1.checkFlowId( "s1", flowIds, debug=False ) |
| 1014 | |
| 1015 | utilities.assert_equals( expect=main.TRUE, |
| 1016 | actual=stepResult, |
| 1017 | onpass="All flows are in mininet", |
| 1018 | onfail="All flows are NOT in mininet" ) |
| 1019 | |
| 1020 | main.step( "Send a packet to verify the flow is correct" ) |
| 1021 | |
| 1022 | main.log.info( "Constructing packet" ) |
| 1023 | # No need for the MAC src dst |
| 1024 | main.h1.buildEther( dst=main.h2.hostMac ) |
| 1025 | main.h1.buildIP( dst=main.h2.hostIp ) |
| 1026 | main.h1.buildUDP( dport=udpDst ) |
| 1027 | |
| 1028 | main.log.info( "Starting filter on host2" ) |
| 1029 | # Defaults to ip |
| 1030 | main.h2.startFilter( pktFilter="udp" ) |
| 1031 | |
| 1032 | main.log.info( "Sending packet to host2" ) |
| 1033 | main.h1.sendPacket() |
| 1034 | |
| 1035 | main.log.info( "Checking filter for our packet" ) |
| 1036 | stepResult = main.h2.checkFilter() |
| 1037 | if stepResult: |
| 1038 | main.log.info( "Packet: %s" % main.h2.readPackets() ) |
| 1039 | else: main.h2.killFilter() |
| 1040 | |
| 1041 | main.log.info( "Clean up host components" ) |
| 1042 | for host in hosts: |
| 1043 | host.stopScapy() |
| 1044 | main.Mininet1.removeHostComponent("h1") |
| 1045 | main.Mininet1.removeHostComponent("h2") |
| 1046 | |
| 1047 | utilities.assert_equals( expect=main.TRUE, |
| 1048 | actual=stepResult, |
| 1049 | onpass="Successfully sent a packet", |
| 1050 | onfail="Failed to send a packet" ) |
| 1051 | |
| 1052 | |
| 1053 | def CASE2000( self, main ): |
| 1054 | import json |
| 1055 | |
| 1056 | main.case( "Delete flows that were added through rest" ) |
| 1057 | main.step("Deleting flows") |
| 1058 | |
| 1059 | main.log.info( "Getting flows" ) |
| 1060 | flows = json.loads( main.ONOSrest.flows() ) |
| 1061 | |
| 1062 | stepResult = main.TRUE |
| 1063 | for f in flows: |
| 1064 | if "rest" in f.get("appId"): |
| 1065 | if main.debug: main.log.debug( "Flow to be deleted:\n{}".format( main.ONOSrest.pprint(f) ) ) |
| 1066 | stepResult = stepResult and main.ONOSrest.removeFlow( f.get("deviceId"), f.get("id") ) |
| 1067 | |
| 1068 | utilities.assert_equals( expect=main.TRUE, |
| 1069 | actual=stepResult, |
| 1070 | onpass="Successfully deleting flows", |
| 1071 | onfail="Failed to delete flows" ) |
| 1072 | |
| 1073 | time.sleep( main.delFlowSleep ) |
| 1074 | |
GlennRC | 6844994 | 2015-10-16 16:03:12 -0700 | [diff] [blame] | 1075 | def CASE100( self, main ): |
GlennRC | 5147a42 | 2015-10-06 17:26:17 -0700 | [diff] [blame] | 1076 | ''' |
| 1077 | Report errors/warnings/exceptions |
| 1078 | ''' |
| 1079 | main.log.info("Error report: \n" ) |
| 1080 | main.ONOSbench.logReport( main.ONOSip[ 0 ], |
| 1081 | [ "INFO", |
| 1082 | "FOLLOWER", |
| 1083 | "WARN", |
| 1084 | "flow", |
| 1085 | "ERROR", |
| 1086 | "Except" ], |
GlennRC | 6844994 | 2015-10-16 16:03:12 -0700 | [diff] [blame] | 1087 | "s" ) |