blob: 47b536cdb2515642c421af425e3543740824d87f [file] [log] [blame]
GlennRC5147a422015-10-06 17:26:17 -07001class FUNCflow:
2
3 def __init__( self ):
4 self.default = ''
5
6 def CASE1( self, main ):
GlennRC5147a422015-10-06 17:26:17 -07007 import os
8 import imp
9
10 """
11 - Construct tests variables
12 - GIT ( optional )
13 - Checkout ONOS master branch
14 - Pull latest ONOS code
15 - Building ONOS ( optional )
16 - Install ONOS package
17 - Build ONOS package
18 """
19
20 main.case( "Constructing test variables and building ONOS package" )
21 main.step( "Constructing test variables" )
GlennRC5147a422015-10-06 17:26:17 -070022
23 # Test variables
24 main.testOnDirectory = os.path.dirname( os.getcwd ( ) )
25 main.cellName = main.params[ 'ENV' ][ 'cellName' ]
26 main.apps = main.params[ 'ENV' ][ 'cellApps' ]
27 gitBranch = main.params[ 'GIT' ][ 'branch' ]
GlennRC073e8bc2015-10-27 17:11:28 -070028 gitPull = main.params[ 'GIT' ][ 'pull' ]
29 main.ONOSport = main.params[ 'CTRL' ][ 'port' ]
GlennRC5147a422015-10-06 17:26:17 -070030 main.dependencyPath = main.testOnDirectory + \
31 main.params[ 'DEPENDENCY' ][ 'path' ]
GlennRC5147a422015-10-06 17:26:17 -070032 wrapperFile1 = main.params[ 'DEPENDENCY' ][ 'wrapper1' ]
GlennRC1704d072015-10-07 18:40:45 -070033 wrapperFile2 = main.params[ 'DEPENDENCY' ][ 'wrapper2' ]
GlennRC073e8bc2015-10-27 17:11:28 -070034 main.topology = main.params[ 'DEPENDENCY' ][ 'topology' ]
35 main.maxNodes = int( main.params[ 'SCALE' ][ 'max' ] )
GlennRC5147a422015-10-06 17:26:17 -070036 main.startUpSleep = int( main.params[ 'SLEEP' ][ 'startup' ] )
GlennRC073e8bc2015-10-27 17:11:28 -070037 main.startMNSleep = int( main.params[ 'SLEEP' ][ 'startMN' ] )
38 main.addFlowSleep = int( main.params[ 'SLEEP' ][ 'addFlow' ] )
39 main.delFlowSleep = int( main.params[ 'SLEEP' ][ 'delFlow' ] )
alisone14d7b02016-07-06 10:31:51 -070040 main.debug = main.params[ 'DEBUG' ]
GlennRC073e8bc2015-10-27 17:11:28 -070041 main.swDPID = main.params[ 'TEST' ][ 'swDPID' ]
alisone14d7b02016-07-06 10:31:51 -070042 main.cellData = { } # for creating cell file
43 main.CLIs = [ ]
44 main.ONOSip = [ ]
GlennRC5147a422015-10-06 17:26:17 -070045
GlennRC956ea742015-11-05 16:14:15 -080046 main.debug = True if "on" in main.debug else False
47
alisone14d7b02016-07-06 10:31:51 -070048 main.ONOSip = main.ONOSbench.getOnosIps( )
GlennRC5147a422015-10-06 17:26:17 -070049
50 # Assigning ONOS cli handles to a list
51 for i in range( 1, main.maxNodes + 1 ):
52 main.CLIs.append( getattr( main, 'ONOScli' + str( i ) ) )
53
54 # -- INIT SECTION, ONLY RUNS ONCE -- #
55 main.startUp = imp.load_source( wrapperFile1,
56 main.dependencyPath +
57 wrapperFile1 +
58 ".py" )
59
GlennRC1704d072015-10-07 18:40:45 -070060 main.topo = imp.load_source( wrapperFile2,
61 main.dependencyPath +
62 wrapperFile2 +
63 ".py" )
64
GlennRC956ea742015-11-05 16:14:15 -080065
GlennRC94ed2232015-10-07 15:08:57 -070066 copyResult = main.ONOSbench.scp( main.Mininet1,
alisone14d7b02016-07-06 10:31:51 -070067 main.dependencyPath + main.topology,
68 main.Mininet1.home + '/custom/',
GlennRC94ed2232015-10-07 15:08:57 -070069 direction="to" )
70
alisone14d7b02016-07-06 10:31:51 -070071 utilities.assert_equals( expect=main.TRUE,
Jeremy Songstere7f3b342016-08-17 14:56:49 -070072 actual=copyResult,
73 onpass="Successfully copy " + "test variables ",
74 onfail="Failed to copy test variables" )
alisone14d7b02016-07-06 10:31:51 -070075
76
GlennRC5147a422015-10-06 17:26:17 -070077 if main.CLIs:
78 stepResult = main.TRUE
79 else:
80 main.log.error( "Did not properly created list of ONOS CLI handle" )
81 stepResult = main.FALSE
82
83 utilities.assert_equals( expect=main.TRUE,
84 actual=stepResult,
alisone14d7b02016-07-06 10:31:51 -070085 onpass="Successfully construct " + "test variables ",
GlennRC5147a422015-10-06 17:26:17 -070086 onfail="Failed to construct test variables" )
87
88 if gitPull == 'True':
89 main.step( "Building ONOS in " + gitBranch + " branch" )
90 onosBuildResult = main.startUp.onosBuild( main, gitBranch )
91 stepResult = onosBuildResult
92 utilities.assert_equals( expect=main.TRUE,
93 actual=stepResult,
alisone14d7b02016-07-06 10:31:51 -070094 onpass="Successfully compiled " + "latest ONOS",
95 onfail="Failed to compile " + "latest ONOS" )
GlennRC5147a422015-10-06 17:26:17 -070096 else:
97 main.log.warn( "Did not pull new code so skipping mvn " +
98 "clean install" )
99
100 def CASE2( self, main ):
101 """
102 - Set up cell
103 - Create cell file
104 - Set cell file
105 - Verify cell file
106 - Kill ONOS process
107 - Uninstall ONOS cluster
108 - Verify ONOS start up
109 - Install ONOS cluster
110 - Connect to cli
111 """
alisone14d7b02016-07-06 10:31:51 -0700112 import time
GlennRC5147a422015-10-06 17:26:17 -0700113
114 main.numCtrls = int( main.maxNodes )
115
116 main.case( "Starting up " + str( main.numCtrls ) +
117 " node(s) ONOS cluster" )
118
119 #kill off all onos processes
120 main.log.info( "Safety check, killing all ONOS processes" +
Jon Hall70b2ff42015-11-17 15:49:44 -0800121 " before initiating environment setup" )
GlennRC5147a422015-10-06 17:26:17 -0700122
123 for i in range( main.maxNodes ):
124 main.ONOSbench.onosDie( main.ONOSip[ i ] )
125
Jon Hall53c5e662016-04-13 16:06:56 -0700126 main.log.info( "NODE COUNT = " + str( main.numCtrls ) )
GlennRC5147a422015-10-06 17:26:17 -0700127
alisone14d7b02016-07-06 10:31:51 -0700128 tempOnosIp = [ ]
GlennRC5147a422015-10-06 17:26:17 -0700129 for i in range( main.numCtrls ):
alisone14d7b02016-07-06 10:31:51 -0700130 tempOnosIp.append( main.ONOSip[ i ] )
GlennRC5147a422015-10-06 17:26:17 -0700131
Jon Hall53c5e662016-04-13 16:06:56 -0700132 main.ONOSbench.createCellFile( main.ONOSbench.ip_address,
133 "temp",
134 main.Mininet1.ip_address,
135 main.apps,
136 tempOnosIp )
GlennRC5147a422015-10-06 17:26:17 -0700137
138 main.step( "Apply cell to environment" )
139 cellResult = main.ONOSbench.setCell( "temp" )
alisone14d7b02016-07-06 10:31:51 -0700140 verifyResult = main.ONOSbench.verifyCell( )
GlennRC5147a422015-10-06 17:26:17 -0700141 stepResult = cellResult and verifyResult
142 utilities.assert_equals( expect=main.TRUE,
143 actual=stepResult,
alisone14d7b02016-07-06 10:31:51 -0700144 onpass="Successfully applied cell to " + "environment",
GlennRC5147a422015-10-06 17:26:17 -0700145 onfail="Failed to apply cell to environment " )
146
147 main.step( "Creating ONOS package" )
Jon Hallbd60ea02016-08-23 10:03:59 -0700148 packageResult = main.ONOSbench.buckBuild()
GlennRC5147a422015-10-06 17:26:17 -0700149 stepResult = packageResult
150 utilities.assert_equals( expect=main.TRUE,
151 actual=stepResult,
152 onpass="Successfully created ONOS package",
153 onfail="Failed to create ONOS package" )
154
155 time.sleep( main.startUpSleep )
156 main.step( "Uninstalling ONOS package" )
157 onosUninstallResult = main.TRUE
Jeremy86160992016-04-11 10:05:53 -0700158 for ip in main.ONOSip:
GlennRC5147a422015-10-06 17:26:17 -0700159 onosUninstallResult = onosUninstallResult and \
Jeremy Songstere7f3b342016-08-17 14:56:49 -0700160 main.ONOSbench.onosUninstall( nodeIp=ip )
GlennRC5147a422015-10-06 17:26:17 -0700161 stepResult = onosUninstallResult
162 utilities.assert_equals( expect=main.TRUE,
163 actual=stepResult,
164 onpass="Successfully uninstalled ONOS package",
165 onfail="Failed to uninstall ONOS package" )
GlennRC5147a422015-10-06 17:26:17 -0700166 time.sleep( main.startUpSleep )
167 main.step( "Installing ONOS package" )
168 onosInstallResult = main.TRUE
169 for i in range( main.numCtrls ):
170 onosInstallResult = onosInstallResult and \
Jeremy Songstere7f3b342016-08-17 14:56:49 -0700171 main.ONOSbench.onosInstall( node=main.ONOSip[ i ] )
GlennRC5147a422015-10-06 17:26:17 -0700172 stepResult = onosInstallResult
173 utilities.assert_equals( expect=main.TRUE,
174 actual=stepResult,
175 onpass="Successfully installed ONOS package",
176 onfail="Failed to install ONOS package" )
177
178 time.sleep( main.startUpSleep )
179 main.step( "Starting ONOS service" )
180 stopResult = main.TRUE
181 startResult = main.TRUE
182 onosIsUp = main.TRUE
183
184 for i in range( main.numCtrls ):
185 onosIsUp = onosIsUp and main.ONOSbench.isup( main.ONOSip[ i ] )
186 if onosIsUp == main.TRUE:
187 main.log.report( "ONOS instance is up and ready" )
188 else:
189 main.log.report( "ONOS instance may not be up, stop and " +
190 "start ONOS again " )
191 for i in range( main.numCtrls ):
192 stopResult = stopResult and \
193 main.ONOSbench.onosStop( main.ONOSip[ i ] )
194 for i in range( main.numCtrls ):
195 startResult = startResult and \
196 main.ONOSbench.onosStart( main.ONOSip[ i ] )
197 stepResult = onosIsUp and stopResult and startResult
198 utilities.assert_equals( expect=main.TRUE,
199 actual=stepResult,
200 onpass="ONOS service is ready",
201 onfail="ONOS service did not start properly" )
202
203 main.step( "Start ONOS cli" )
204 cliResult = main.TRUE
205 for i in range( main.numCtrls ):
206 cliResult = cliResult and \
207 main.CLIs[ i ].startOnosCli( main.ONOSip[ i ] )
208 stepResult = cliResult
209 utilities.assert_equals( expect=main.TRUE,
210 actual=stepResult,
211 onpass="Successfully start ONOS cli",
212 onfail="Failed to start ONOS cli" )
213
GlennRC68449942015-10-16 16:03:12 -0700214 def CASE10( self, main ):
215 '''
216 Start Mininet
217 '''
GlennRC073e8bc2015-10-27 17:11:28 -0700218 import json
219
220 main.case( "Setup mininet and compare ONOS topology view to Mininet topology" )
221 main.caseExplanation = "Start mininet with custom topology and compare topology " +\
222 "elements between Mininet and ONOS"
223
GlennRC68449942015-10-16 16:03:12 -0700224 main.step( "Setup Mininet Topology" )
225 topology = main.Mininet1.home + '/custom/' + main.topology
alisone14d7b02016-07-06 10:31:51 -0700226 stepResult = main.Mininet1.startNet( topoFile = topology )
GlennRC68449942015-10-16 16:03:12 -0700227
228 utilities.assert_equals( expect=main.TRUE,
GlennRC073e8bc2015-10-27 17:11:28 -0700229 actual=stepResult,
GlennRC68449942015-10-16 16:03:12 -0700230 onpass="Successfully loaded topology",
231 onfail="Failed to load topology" )
232
GlennRC073e8bc2015-10-27 17:11:28 -0700233 main.step( "Assign switch to controller" )
234 stepResult = main.Mininet1.assignSwController( "s1", main.ONOSip[0] )
GlennRC68449942015-10-16 16:03:12 -0700235
236 utilities.assert_equals( expect=main.TRUE,
GlennRC073e8bc2015-10-27 17:11:28 -0700237 actual=stepResult,
238 onpass="Successfully assigned switch to controller",
239 onfail="Failed to assign switch to controller" )
GlennRC68449942015-10-16 16:03:12 -0700240
GlennRC073e8bc2015-10-27 17:11:28 -0700241 time.sleep( main.startMNSleep )
GlennRC68449942015-10-16 16:03:12 -0700242
Jon Hall70b2ff42015-11-17 15:49:44 -0800243 main.step( "Comparing MN topology to ONOS topology" )
GlennRC073e8bc2015-10-27 17:11:28 -0700244 main.log.info( "Gathering topology information" )
GlennRC1704d072015-10-07 18:40:45 -0700245 devices = main.topo.getAllDevices( main )
246 hosts = main.topo.getAllHosts( main )
247 ports = main.topo.getAllPorts( main )
248 links = main.topo.getAllLinks( main )
GlennRC1704d072015-10-07 18:40:45 -0700249
alisone14d7b02016-07-06 10:31:51 -0700250 mnSwitches = main.Mininet1.getSwitches( )
251 mnLinks = main.Mininet1.getLinks( )
252 mnHosts = main.Mininet1.getHosts( )
GlennRC1704d072015-10-07 18:40:45 -0700253
GlennRC1704d072015-10-07 18:40:45 -0700254 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 +
GlennRC68449942015-10-16 16:03:12 -0700269 " Switches view is correct",
GlennRC1704d072015-10-07 18:40:45 -0700270 onfail="ONOS" + controllerStr +
GlennRC68449942015-10-16 16:03:12 -0700271 " Switches view is incorrect" )
GlennRC1704d072015-10-07 18:40:45 -0700272 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 +
GlennRC68449942015-10-16 16:03:12 -0700281 " links view is correct",
GlennRC1704d072015-10-07 18:40:45 -0700282 onfail="ONOS" + controllerStr +
GlennRC68449942015-10-16 16:03:12 -0700283 " links view is incorrect" )
GlennRC1704d072015-10-07 18:40:45 -0700284
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 +
GlennRC68449942015-10-16 16:03:12 -0700294 " hosts exist in Mininet",
GlennRC1704d072015-10-07 18:40:45 -0700295 onfail="ONOS" + controllerStr +
GlennRC68449942015-10-16 16:03:12 -0700296 " hosts don't match Mininet")
GlennRCa5391372015-10-14 17:28:15 -0700297
GlennRC68449942015-10-16 16:03:12 -0700298
Jon Hall892818c2015-10-20 17:58:34 -0700299 def CASE66( self, main ):
300 '''
301 Testing scapy
302 '''
303 main.case( "Testing scapy" )
304 main.step( "Creating Host1 component" )
Jon Halla510a8a2016-05-04 15:09:28 -0700305 main.Scapy.createHostComponent( "h1" )
306 main.Scapy.createHostComponent( "h2" )
alisone14d7b02016-07-06 10:31:51 -0700307 hosts = [ main.h1, main.h2 ]
Jon Hall892818c2015-10-20 17:58:34 -0700308 for host in hosts:
alisone14d7b02016-07-06 10:31:51 -0700309 host.startHostCli( )
310 host.startScapy( )
311 host.updateSelf( )
Jon Hall892818c2015-10-20 17:58:34 -0700312 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" )
Jon Halla510a8a2016-05-04 15:09:28 -0700317 main.log.info( "Starting Filter..." )
alisone14d7b02016-07-06 10:31:51 -0700318 main.h2.startFilter( )
Jon Halla510a8a2016-05-04 15:09:28 -0700319 main.log.info( "Building Ether frame..." )
Jon Hall892818c2015-10-20 17:58:34 -0700320 main.h1.buildEther( dst=main.h2.hostMac )
Jon Halla510a8a2016-05-04 15:09:28 -0700321 main.log.info( "Sending Packet..." )
Jon Hall892818c2015-10-20 17:58:34 -0700322 main.h1.sendPacket( )
Jon Halla510a8a2016-05-04 15:09:28 -0700323 main.log.info( "Checking Filter..." )
alisone14d7b02016-07-06 10:31:51 -0700324 finished = main.h2.checkFilter( )
Jon Halla510a8a2016-05-04 15:09:28 -0700325 main.log.debug( finished )
Jon Hall892818c2015-10-20 17:58:34 -0700326 i = ""
327 if finished:
alisone14d7b02016-07-06 10:31:51 -0700328 a = main.h2.readPackets( )
329 for i in a.splitlines( ):
Jon Hall892818c2015-10-20 17:58:34 -0700330 main.log.info( i )
331 else:
alisone14d7b02016-07-06 10:31:51 -0700332 kill = main.h2.killFilter( )
Jon Hall892818c2015-10-20 17:58:34 -0700333 main.log.debug( kill )
334 main.h2.handle.sendline( "" )
335 main.h2.handle.expect( main.h2.scapyPrompt )
336 main.log.debug( main.h2.handle.before )
337 utilities.assert_equals( expect=True,
338 actual="dst=00:00:00:00:00:02 src=00:00:00:00:00:01" in i,
339 onpass="Pass",
340 onfail="Fail" )
341
342 main.step( "Sending/Receiving Test packet - Filter matches" )
alisone14d7b02016-07-06 10:31:51 -0700343 main.h2.startFilter( )
Jon Hall892818c2015-10-20 17:58:34 -0700344 main.h1.buildEther( dst=main.h2.hostMac )
345 main.h1.buildIP( dst=main.h2.hostIp )
346 main.h1.sendPacket( )
alisone14d7b02016-07-06 10:31:51 -0700347 finished = main.h2.checkFilter( )
Jon Hall892818c2015-10-20 17:58:34 -0700348 i = ""
349 if finished:
alisone14d7b02016-07-06 10:31:51 -0700350 a = main.h2.readPackets( )
351 for i in a.splitlines( ):
Jon Hall892818c2015-10-20 17:58:34 -0700352 main.log.info( i )
353 else:
alisone14d7b02016-07-06 10:31:51 -0700354 kill = main.h2.killFilter( )
Jon Hall892818c2015-10-20 17:58:34 -0700355 main.log.debug( kill )
356 main.h2.handle.sendline( "" )
357 main.h2.handle.expect( main.h2.scapyPrompt )
358 main.log.debug( main.h2.handle.before )
359 utilities.assert_equals( expect=True,
360 actual="dst=00:00:00:00:00:02 src=00:00:00:00:00:01" in i,
361 onpass="Pass",
362 onfail="Fail" )
363
364
365
366 main.step( "Clean up host components" )
367 for host in hosts:
alisone14d7b02016-07-06 10:31:51 -0700368 host.stopScapy( )
369 main.Mininet1.removeHostComponent( "h1" )
370 main.Mininet1.removeHostComponent( "h2" )
Jon Hall892818c2015-10-20 17:58:34 -0700371
GlennRC68449942015-10-16 16:03:12 -0700372 def CASE1000( self, main ):
373 '''
GlennRC073e8bc2015-10-27 17:11:28 -0700374 Add flows with MAC selectors and verify the flows
GlennRC68449942015-10-16 16:03:12 -0700375 '''
GlennRC073e8bc2015-10-27 17:11:28 -0700376 import json
377 import time
GlennRC68449942015-10-16 16:03:12 -0700378
GlennRC073e8bc2015-10-27 17:11:28 -0700379 main.case( "Verify flow MAC selectors are correctly compiled" )
380 main.caseExplanation = "Install two flows with only MAC selectors " +\
381 "specified, then verify flows are added in ONOS, finally "+\
382 "send a packet that only specifies the MAC src and dst."
GlennRC68449942015-10-16 16:03:12 -0700383
GlennRC073e8bc2015-10-27 17:11:28 -0700384 main.step( "Add flows with MAC addresses as the only selectors" )
GlennRC68449942015-10-16 16:03:12 -0700385
GlennRC073e8bc2015-10-27 17:11:28 -0700386 main.log.info( "Creating host components" )
Jon Halla510a8a2016-05-04 15:09:28 -0700387 main.Scapy.createHostComponent( "h1" )
388 main.Scapy.createHostComponent( "h2" )
alisone14d7b02016-07-06 10:31:51 -0700389 hosts = [ main.h1, main.h2 ]
GlennRC073e8bc2015-10-27 17:11:28 -0700390 for host in hosts:
alisone14d7b02016-07-06 10:31:51 -0700391 host.startHostCli( )
392 host.startScapy( )
393 host.updateSelf( )
GlennRC68449942015-10-16 16:03:12 -0700394
GlennRC073e8bc2015-10-27 17:11:28 -0700395 # Add a flow that connects host1 on port1 to host2 on port2
396 # send output on port2
397 # recieve input on port1
398 egress = 2
399 ingress = 1
400
401 # Add flows that sends packets from port1 to port2 with correct
402 # MAC src and dst addresses
403 main.log.info( "Adding flow with MAC selectors" )
404 stepResult = main.ONOSrest.addFlow( deviceId=main.swDPID,
405 egressPort=egress,
406 ingressPort=ingress,
407 ethSrc=main.h1.hostMac,
408 ethDst=main.h2.hostMac,
GlennRC956ea742015-11-05 16:14:15 -0800409 debug=main.debug )
GlennRC68449942015-10-16 16:03:12 -0700410
GlennRCa5391372015-10-14 17:28:15 -0700411 utilities.assert_equals( expect=main.TRUE,
412 actual=stepResult,
GlennRC68449942015-10-16 16:03:12 -0700413 onpass="Successfully added flows",
414 onfail="Failed add flows" )
GlennRCa5391372015-10-14 17:28:15 -0700415
GlennRC073e8bc2015-10-27 17:11:28 -0700416 # Giving ONOS time to add the flows
417 time.sleep( main.addFlowSleep )
GlennRC5147a422015-10-06 17:26:17 -0700418
GlennRC073e8bc2015-10-27 17:11:28 -0700419 main.step( "Check flows are in the ADDED state" )
420
GlennRC073e8bc2015-10-27 17:11:28 -0700421 main.log.info( "Get the flows from ONOS" )
Jeremy86160992016-04-11 10:05:53 -0700422 try:
alisone14d7b02016-07-06 10:31:51 -0700423 flows = json.loads( main.ONOSrest.flows( ) )
GlennRC68449942015-10-16 16:03:12 -0700424
Jeremy86160992016-04-11 10:05:53 -0700425 stepResult = main.TRUE
426 for f in flows:
alisone14d7b02016-07-06 10:31:51 -0700427 if "rest" in f.get( "appId" ):
428 if "ADDED" not in f.get( "state" ):
Jeremy86160992016-04-11 10:05:53 -0700429 stepResult = main.FALSE
alisone14d7b02016-07-06 10:31:51 -0700430 main.log.error( "Flow: %s in state: %s" % ( f.get( "id" ), f.get( "state" ) ) )
Jeremy86160992016-04-11 10:05:53 -0700431 except TypeError:
432 main.log.error( "No Flows found by the REST API" )
433 stepResult = main.FALSE
434 except ValueError:
435 main.log.error( "Problem getting Flows state from REST API. Exiting test" )
alisone14d7b02016-07-06 10:31:51 -0700436 main.cleanup( )
437 main.exit( )
GlennRC68449942015-10-16 16:03:12 -0700438
439 utilities.assert_equals( expect=main.TRUE,
440 actual=stepResult,
441 onpass="All flows are in the ADDED state",
GlennRC073e8bc2015-10-27 17:11:28 -0700442 onfail="All flows are NOT in the ADDED state" )
GlennRC68449942015-10-16 16:03:12 -0700443
GlennRC956ea742015-11-05 16:14:15 -0800444 main.step( "Check flows are in Mininet's flow table" )
445
446 # get the flow IDs that were added through rest
447 main.log.info( "Getting the flow IDs from ONOS" )
alisone14d7b02016-07-06 10:31:51 -0700448 flowIds = [ f.get( "id" ) for f in flows if "rest" in f.get( "appId" ) ]
GlennRC956ea742015-11-05 16:14:15 -0800449 # convert the flowIDs to ints then hex and finally back to strings
alisone14d7b02016-07-06 10:31:51 -0700450 flowIds = [ str( hex( int( x ) ) ) for x in flowIds ]
451 main.log.info( "ONOS flow IDs: {}".format( flowIds ) )
GlennRC956ea742015-11-05 16:14:15 -0800452
453 stepResult = main.Mininet1.checkFlowId( "s1", flowIds, debug=False )
454
455 utilities.assert_equals( expect=main.TRUE,
456 actual=stepResult,
457 onpass="All flows are in mininet",
458 onfail="All flows are NOT in mininet" )
459
GlennRC073e8bc2015-10-27 17:11:28 -0700460 main.step( "Send a packet to verify the flows are correct" )
461
462 # Specify the src and dst MAC addr
463 main.log.info( "Constructing packet" )
464 main.h1.buildEther( src=main.h1.hostMac, dst=main.h2.hostMac )
465
466 # Filter for packets with the correct host name. Otherwise,
467 # the filter we catch any packet that is sent to host2
468 # NOTE: I believe it doesn't matter which host name it is,
GlennRC956ea742015-11-05 16:14:15 -0800469 # as long as the src and dst are both specified
GlennRC073e8bc2015-10-27 17:11:28 -0700470 main.log.info( "Starting filter on host2" )
alisone14d7b02016-07-06 10:31:51 -0700471 main.h2.startFilter( pktFilter="ether host %s" % main.h1.hostMac )
GlennRC073e8bc2015-10-27 17:11:28 -0700472
473 main.log.info( "Sending packet to host2" )
474 main.h1.sendPacket()
475
476 main.log.info( "Checking filter for our packet" )
alisone14d7b02016-07-06 10:31:51 -0700477 stepResult = main.h2.checkFilter( )
GlennRC073e8bc2015-10-27 17:11:28 -0700478 if stepResult:
alisone14d7b02016-07-06 10:31:51 -0700479 main.log.info( "Packet: %s" % main.h2.readPackets( ) )
480 else:
481 main.h2.killFilter( )
GlennRC073e8bc2015-10-27 17:11:28 -0700482
483 main.log.info( "Clean up host components" )
484 for host in hosts:
alisone14d7b02016-07-06 10:31:51 -0700485 host.stopScapy( )
486 main.Mininet1.removeHostComponent( "h1" )
487 main.Mininet1.removeHostComponent( "h2" )
GlennRC073e8bc2015-10-27 17:11:28 -0700488
489 utilities.assert_equals( expect=main.TRUE,
490 actual=stepResult,
491 onpass="Successfully sent a packet",
492 onfail="Failed to send a packet" )
493
alisone14d7b02016-07-06 10:31:51 -0700494 def CASE1400( self, main ):
GlennRC68449942015-10-16 16:03:12 -0700495 '''
GlennRC073e8bc2015-10-27 17:11:28 -0700496 Add flows with IPv4 selectors and verify the flows
GlennRC68449942015-10-16 16:03:12 -0700497 '''
498 import json
GlennRC073e8bc2015-10-27 17:11:28 -0700499 import time
GlennRC68449942015-10-16 16:03:12 -0700500
GlennRC073e8bc2015-10-27 17:11:28 -0700501 main.case( "Verify flow IP selectors are correctly compiled" )
502 main.caseExplanation = "Install two flows with only IP selectors " +\
alisone14d7b02016-07-06 10:31:51 -0700503 "specified, then verify flows are added in ONOS, finally " +\
GlennRC073e8bc2015-10-27 17:11:28 -0700504 "send a packet that only specifies the IP src and dst."
505
506 main.step( "Add flows with IPv4 addresses as the only selectors" )
507
508 main.log.info( "Creating host components" )
Jon Halla510a8a2016-05-04 15:09:28 -0700509 main.Scapy.createHostComponent( "h1" )
510 main.Scapy.createHostComponent( "h2" )
alisone14d7b02016-07-06 10:31:51 -0700511 hosts = [ main.h1, main.h2 ]
GlennRC073e8bc2015-10-27 17:11:28 -0700512 for host in hosts:
alisone14d7b02016-07-06 10:31:51 -0700513 host.startHostCli( )
514 host.startScapy( )
515 host.updateSelf( )
GlennRC073e8bc2015-10-27 17:11:28 -0700516
517 # Add a flow that connects host1 on port1 to host2 on port2
518 # send output on port2
519 # recieve input on port1
520 egress = 2
521 ingress = 1
522 # IPv4 etherType = 0x800
alisone14d7b02016-07-06 10:31:51 -0700523 ethType = main.params[ 'TEST' ][ 'ip4Type' ]
GlennRC073e8bc2015-10-27 17:11:28 -0700524
525 # Add flows that connects host1 to host2
526 main.log.info( "Add flow with port ingress 1 to port egress 2" )
527 stepResult = main.ONOSrest.addFlow( deviceId=main.swDPID,
528 egressPort=egress,
529 ingressPort=ingress,
alisone14d7b02016-07-06 10:31:51 -0700530 ethType=ethType,
531 ipSrc=( "IPV4_SRC", main.h1.hostIp+"/32" ),
532 ipDst=( "IPV4_DST", main.h2.hostIp+"/32" ),
GlennRC956ea742015-11-05 16:14:15 -0800533 debug=main.debug )
GlennRC073e8bc2015-10-27 17:11:28 -0700534
535 utilities.assert_equals( expect=main.TRUE,
536 actual=stepResult,
537 onpass="Successfully added flows",
538 onfail="Failed add flows" )
539
540 # Giving ONOS time to add the flow
541 time.sleep( main.addFlowSleep )
542
543 main.step( "Check flow is in the ADDED state" )
544
545 main.log.info( "Get the flows from ONOS" )
Jeremy86160992016-04-11 10:05:53 -0700546 try:
alisone14d7b02016-07-06 10:31:51 -0700547 flows = json.loads( main.ONOSrest.flows( ) )
GlennRC68449942015-10-16 16:03:12 -0700548
Jeremy86160992016-04-11 10:05:53 -0700549 stepResult = main.TRUE
550 for f in flows:
alisone14d7b02016-07-06 10:31:51 -0700551 if "rest" in f.get( "appId" ):
552 if "ADDED" not in f.get( "state" ):
Jeremy86160992016-04-11 10:05:53 -0700553 stepResult = main.FALSE
alisone14d7b02016-07-06 10:31:51 -0700554 main.log.error( "Flow: %s in state: %s" % ( f.get( "id" ), f.get( "state" ) ) )
Jeremy86160992016-04-11 10:05:53 -0700555 except TypeError:
556 main.log.error( "No Flows found by the REST API" )
557 stepResult = main.FALSE
558 except ValueError:
559 main.log.error( "Problem getting Flows state from REST API. Exiting test" )
alisone14d7b02016-07-06 10:31:51 -0700560 main.cleanup( )
561 main.exit( )
GlennRC68449942015-10-16 16:03:12 -0700562
563 utilities.assert_equals( expect=main.TRUE,
564 actual=stepResult,
GlennRC073e8bc2015-10-27 17:11:28 -0700565 onpass="All flows are in the ADDED state",
566 onfail="All flows are NOT in the ADDED state" )
567
GlennRC956ea742015-11-05 16:14:15 -0800568 main.step( "Check flows are in Mininet's flow table" )
569
570 # get the flow IDs that were added through rest
571 main.log.info( "Getting the flow IDs from ONOS" )
alisone14d7b02016-07-06 10:31:51 -0700572 flowIds = [ f.get( "id" ) for f in flows if "rest" in f.get( "appId" ) ]
GlennRC956ea742015-11-05 16:14:15 -0800573 # convert the flowIDs to ints then hex and finally back to strings
alisone14d7b02016-07-06 10:31:51 -0700574 flowIds = [ str( hex( int( x ) ) ) for x in flowIds ]
575 main.log.info( "ONOS flow IDs: {}".format( flowIds ) )
GlennRC956ea742015-11-05 16:14:15 -0800576
577 stepResult = main.Mininet1.checkFlowId( "s1", flowIds, debug=False )
578
579 utilities.assert_equals( expect=main.TRUE,
580 actual=stepResult,
581 onpass="All flows are in mininet",
582 onfail="All flows are NOT in mininet" )
583
GlennRC073e8bc2015-10-27 17:11:28 -0700584 main.step( "Send a packet to verify the flow is correct" )
585
586 main.log.info( "Constructing packet" )
587 # No need for the MAC src dst
588 main.h1.buildEther( dst=main.h2.hostMac )
589 main.h1.buildIP( src=main.h1.hostIp, dst=main.h2.hostIp )
590
591 main.log.info( "Starting filter on host2" )
592 # Defaults to ip
alisone14d7b02016-07-06 10:31:51 -0700593 main.h2.startFilter( )
GlennRC073e8bc2015-10-27 17:11:28 -0700594
595 main.log.info( "Sending packet to host2" )
alisone14d7b02016-07-06 10:31:51 -0700596 main.h1.sendPacket( )
GlennRC073e8bc2015-10-27 17:11:28 -0700597
598 main.log.info( "Checking filter for our packet" )
alisone14d7b02016-07-06 10:31:51 -0700599 stepResult = main.h2.checkFilter( )
GlennRC073e8bc2015-10-27 17:11:28 -0700600 if stepResult:
alisone14d7b02016-07-06 10:31:51 -0700601 main.log.info( "Packet: %s" % main.h2.readPackets( ) )
602 else: main.h2.killFilter( )
GlennRC073e8bc2015-10-27 17:11:28 -0700603
604 main.log.info( "Clean up host components" )
605 for host in hosts:
alisone14d7b02016-07-06 10:31:51 -0700606 host.stopScapy( )
607 main.Mininet1.removeHostComponent( "h1" )
608 main.Mininet1.removeHostComponent( "h2" )
GlennRC073e8bc2015-10-27 17:11:28 -0700609
610 utilities.assert_equals( expect=main.TRUE,
611 actual=stepResult,
612 onpass="Successfully sent a packet",
613 onfail="Failed to send a packet" )
614
alisone14d7b02016-07-06 10:31:51 -0700615 def CASE1500 (self, main ):
616 """
617 Add flow with IPv6 selector and verify the flow
618 """
619 import json
620 import time
621 main.case( "Verify IPv6 selector is correctly compiled" )
622 main.caseExplanation = "Install two flows with only IP selectors " + \
623 "specified, then verify flows are added in ONOS, finally " + \
624 "send a packet that only specifies the IP src and dst."
625
626 main.step( "Add flows with IPv6 addresses as the only selectors" )
627
628 main.log.info( "Creating host components" )
629 main.Scapy.createHostComponent( "h5" )
630 main.Scapy.createHostComponent( "h6" )
631 hosts = [ main.h5, main.h6 ]
632
633 for host in hosts:
634 host.startHostCli( )
635 host.startScapy( )
636 host.updateSelf( IPv6=True )
637
638 # Add a flow that connects host1 on port1 to host2 on port2
639 # send output on port2
640 # recieve input on port1
641 egress = 6
642 ingress = 5
643 # IPv6 etherType = 0x86DD
644 ethType = main.params[ 'TEST' ][ 'ip6Type' ]
645
646 # Add flows that connects host1 to host2
647 main.log.info( "Add flow with port ingress 5 to port egress 6" )
648 stepResult = main.ONOSrest.addFlow( deviceId=main.swDPID,
649 egressPort=egress,
650 ingressPort=ingress,
651 ethType=ethType,
652 ipSrc=( "IPV6_SRC", main.h5.hostIp + "/128" ),
653 ipDst=( "IPV6_DST", main.h6.hostIp + "/128" ),
654 debug=main.debug )
655
656 utilities.assert_equals( expect=main.TRUE,
657 actual=stepResult,
658 onpass="Successfully added flows",
659 onfail="Failed add flows" )
660
661 # Giving ONOS time to add the flow
662 time.sleep( main.addFlowSleep )
663
664 main.step( "Check flow is in the ADDED state" )
665
666 main.log.info( "Get the flows from ONOS" )
667 try:
668 flows = json.loads( main.ONOSrest.flows( ) )
669
670 stepResult = main.TRUE
671 for f in flows:
672 if "rest" in f.get( "appId" ):
673 if "ADDED" not in f.get( "state" ):
674 stepResult = main.FALSE
675 main.log.error( "Flow: %s in state: %s" % ( f.get( "id" ), f.get( "state" ) ) )
676 except TypeError:
677 main.log.error( "No Flows found by the REST API" )
678 stepResult = main.FALSE
679 except ValueError:
680 main.log.error( "Problem getting Flows state from REST API. Exiting test" )
681 main.cleanup( )
682 main.exit( )
683
684 utilities.assert_equals( expect=main.TRUE,
685 actual=stepResult,
686 onpass="All flows are in the ADDED state",
687 onfail="All flows are NOT in the ADDED state" )
688
689 main.step( "Check flows are in Mininet's flow table" )
690
691 # get the flow IDs that were added through rest
692 main.log.info( "Getting the flow IDs from ONOS" )
693 flowIds = [ f.get( "id" ) for f in flows if "rest" in f.get( "appId" ) ]
694 # convert the flowIDs to ints then hex and finally back to strings
695 flowIds = [ str( hex( int( x ) ) ) for x in flowIds ]
696 main.log.info( "ONOS flow IDs: {}".format( flowIds ) )
697
698 stepResult = main.Mininet1.checkFlowId( "s1", flowIds, debug=False )
699
700 utilities.assert_equals( expect=main.TRUE,
701 actual=stepResult,
702 onpass="All flows are in mininet",
703 onfail="All flows are NOT in mininet" )
704
705 main.step( "Send a packet to verify the flow is correct" )
706
707 main.log.info( "Constructing packet" )
708 # No need for the MAC src dst
709 main.h5.buildEther( dst=main.h6.hostMac )
710 main.h5.buildIPv6( src=main.h5.hostIp, dst=main.h6.hostIp )
711
712 main.log.info( "Starting filter on host6" )
713 # Defaults to ip
714 main.h6.startFilter( pktFilter="ip6" )
715 main.log.info( "Sending packet to host6" )
716 main.h5.sendPacket( )
717
718 main.log.info( "Checking filter for our packet" )
719 stepResult = main.h6.checkFilter( )
720 if stepResult:
721 main.log.info( "Packet: %s" % main.h6.readPackets( ) )
722 else:
723 main.h6.killFilter( )
724
725 main.log.info( "Clean up host components" )
726 for host in hosts:
727 host.stopScapy( )
728 main.Mininet1.removeHostComponent( "h5" )
729 main.Mininet1.removeHostComponent( "h6" )
730
731 utilities.assert_equals( expect=main.TRUE,
732 actual=stepResult,
733 onpass="Successfully sent a packet",
734 onfail="Failed to send a packet" )
735
736
737 def CASE1100( self, main ):
GlennRC073e8bc2015-10-27 17:11:28 -0700738 '''
739 Add flow with VLAN selector and verify the flow
740 '''
741 import json
742 import time
743
744 main.case( "Verify VLAN selector is correctly compiled" )
745 main.caseExplanation = "Install one flow with only the VLAN selector " +\
746 "specified, then verify the flow is added in ONOS, and finally "+\
747 "broadcast a packet with the correct VLAN tag."
748
749 # We do this here to utilize the hosts information
750 main.log.info( "Creating host components" )
Jon Halla510a8a2016-05-04 15:09:28 -0700751 main.Scapy.createHostComponent( "h3" )
752 main.Scapy.createHostComponent( "h4" )
alisone14d7b02016-07-06 10:31:51 -0700753 hosts = [ main.h3, main.h4 ]
GlennRC073e8bc2015-10-27 17:11:28 -0700754 for host in hosts:
alisone14d7b02016-07-06 10:31:51 -0700755 host.startHostCli( )
756 host.startScapy( )
757 host.updateSelf( )
GlennRC073e8bc2015-10-27 17:11:28 -0700758
759
760 main.step( "Add a flow with the VLAN tag as the only selector" )
761
762 # Add flows that connects the two vlan hosts h3 and h4
763 # Host 3 is on port 3 and host 4 is on port 4
764 vlan = main.params[ 'TEST' ][ 'vlan' ]
765 egress = 4
766 ingress = 3
767 # VLAN ethType = 0x8100
alisone14d7b02016-07-06 10:31:51 -0700768 ethType = main.params[ 'TEST' ][ 'vlanType' ]
GlennRC073e8bc2015-10-27 17:11:28 -0700769
770 # Add only one flow because we don't need a response
771 main.log.info( "Add flow with port ingress 1 to port egress 2" )
772 stepResult = main.ONOSrest.addFlow( deviceId=main.swDPID,
773 egressPort=egress,
774 ingressPort=ingress,
775 ethType=ethType,
776 vlan=vlan,
GlennRC956ea742015-11-05 16:14:15 -0800777 debug=main.debug )
GlennRC073e8bc2015-10-27 17:11:28 -0700778
779
780 utilities.assert_equals( expect=main.TRUE,
781 actual=stepResult,
782 onpass="Successfully added flow",
783 onfail="Failed add flows" )
784
785 # Giving ONOS time to add the flows
786 time.sleep( main.addFlowSleep )
787
788 main.step( "Check flows are in the ADDED state" )
789
790 main.log.info( "Get the flows from ONOS" )
Jeremy86160992016-04-11 10:05:53 -0700791 try:
alisone14d7b02016-07-06 10:31:51 -0700792 flows = json.loads( main.ONOSrest.flows( ) )
GlennRC073e8bc2015-10-27 17:11:28 -0700793
Jeremy86160992016-04-11 10:05:53 -0700794 stepResult = main.TRUE
795 for f in flows:
alisone14d7b02016-07-06 10:31:51 -0700796 if "rest" in f.get( "appId" ):
797 if "ADDED" not in f.get( "state" ):
Jeremy86160992016-04-11 10:05:53 -0700798 stepResult = main.FALSE
alisone14d7b02016-07-06 10:31:51 -0700799 main.log.error( "Flow: %s in state: %s" % ( f.get( "id" ), f.get( "state" ) ) )
Jeremy86160992016-04-11 10:05:53 -0700800 except TypeError:
801 main.log.error( "No Flows found by the REST API" )
802 stepResult = main.FALSE
803 except ValueError:
804 main.log.error( "Problem getting Flows state from REST API. Exiting test" )
alisone14d7b02016-07-06 10:31:51 -0700805 main.cleanup( )
806 main.exit( )
GlennRC073e8bc2015-10-27 17:11:28 -0700807
808 utilities.assert_equals( expect=main.TRUE,
809 actual=stepResult,
810 onpass="All flows are in the ADDED state",
811 onfail="All flows are NOT in the ADDED state" )
812
GlennRC956ea742015-11-05 16:14:15 -0800813 main.step( "Check flows are in Mininet's flow table" )
814
815 # get the flow IDs that were added through rest
816 main.log.info( "Getting the flow IDs from ONOS" )
alisone14d7b02016-07-06 10:31:51 -0700817 flowIds = [ f.get( "id" ) for f in flows if "rest" in f.get( "appId" ) ]
GlennRC956ea742015-11-05 16:14:15 -0800818 # convert the flowIDs to ints then hex and finally back to strings
alisone14d7b02016-07-06 10:31:51 -0700819 flowIds = [ str( hex( int( x ) ) ) for x in flowIds ]
820 main.log.info( "ONOS flow IDs: {}".format( flowIds ) )
GlennRC956ea742015-11-05 16:14:15 -0800821
822 stepResult = main.Mininet1.checkFlowId( "s1", flowIds, debug=False )
823
824 utilities.assert_equals( expect=main.TRUE,
825 actual=stepResult,
826 onpass="All flows are in mininet",
827 onfail="All flows are NOT in mininet" )
828
GlennRC073e8bc2015-10-27 17:11:28 -0700829 main.step( "Send a packet to verify the flow are correct" )
830
831 # The receiving interface
alisone14d7b02016-07-06 10:31:51 -0700832 recIface = "{}-eth0.{}".format( main.h4.name, vlan )
GlennRC073e8bc2015-10-27 17:11:28 -0700833 main.log.info( "Starting filter on host2" )
834 # Filter is setup to catch any packet on the vlan interface with the correct vlan tag
alisone14d7b02016-07-06 10:31:51 -0700835 main.h4.startFilter( ifaceName=recIface, pktFilter = "" )
GlennRC073e8bc2015-10-27 17:11:28 -0700836
837 # Broadcast the packet on the vlan interface. We only care if the flow forwards
838 # the packet with the correct vlan tag, not if the mac addr is correct
alisone14d7b02016-07-06 10:31:51 -0700839 sendIface = "{}-eth0.{}".format( main.h3.name, vlan )
GlennRC073e8bc2015-10-27 17:11:28 -0700840 main.log.info( "Broadcasting the packet with a vlan tag" )
GlennRC956ea742015-11-05 16:14:15 -0800841 main.h3.sendPacket( iface=sendIface,
alisone14d7b02016-07-06 10:31:51 -0700842 packet="Ether()/Dot1Q(vlan={})".format( vlan ) )
GlennRC073e8bc2015-10-27 17:11:28 -0700843
844 main.log.info( "Checking filter for our packet" )
alisone14d7b02016-07-06 10:31:51 -0700845 stepResult = main.h4.checkFilter( )
GlennRC073e8bc2015-10-27 17:11:28 -0700846 if stepResult:
alisone14d7b02016-07-06 10:31:51 -0700847 main.log.info( "Packet: %s" % main.h4.readPackets( ) )
848 else: main.h4.killFilter( )
GlennRC073e8bc2015-10-27 17:11:28 -0700849
850 main.log.info( "Clean up host components" )
851 for host in hosts:
alisone14d7b02016-07-06 10:31:51 -0700852 host.stopScapy( )
853 main.Mininet1.removeHostComponent( "h3" )
854 main.Mininet1.removeHostComponent( "h4" )
GlennRC073e8bc2015-10-27 17:11:28 -0700855
856 utilities.assert_equals( expect=main.TRUE,
857 actual=stepResult,
858 onpass="Successfully sent a packet",
859 onfail="Failed to send a packet" )
GlennRC68449942015-10-16 16:03:12 -0700860
GlennRC956ea742015-11-05 16:14:15 -0800861 def CASE1300( self, main ):
862 '''
863 Add flows with MPLS selector and verify the flows
864 '''
865 import json
866 import time
867
868 main.case( "Verify the MPLS selector is correctly compiled on the flow." )
869 main.caseExplanation = "Install one flow with an MPLS selector, " +\
alisone14d7b02016-07-06 10:31:51 -0700870 "verify the flow is added in ONOS, and finally " +\
GlennRC956ea742015-11-05 16:14:15 -0800871 "send a packet via scapy that has a MPLS label."
872
873 main.step( "Add a flow with a MPLS selector" )
874
875 main.log.info( "Creating host components" )
Jon Halla510a8a2016-05-04 15:09:28 -0700876 main.Scapy.createHostComponent( "h1" )
877 main.Scapy.createHostComponent( "h2" )
alisone14d7b02016-07-06 10:31:51 -0700878 hosts = [ main.h1, main.h2 ]
GlennRC956ea742015-11-05 16:14:15 -0800879 for host in hosts:
alisone14d7b02016-07-06 10:31:51 -0700880 host.startHostCli( )
GlennRC956ea742015-11-05 16:14:15 -0800881 host.startScapy( main.dependencyPath )
alisone14d7b02016-07-06 10:31:51 -0700882 host.updateSelf( )
GlennRC956ea742015-11-05 16:14:15 -0800883
884 # ports
885 egress = 2
886 ingress = 1
887 # MPLS etherType
888 ethType = main.params[ 'TEST' ][ 'mplsType' ]
889 # MPLS label
890 mplsLabel = main.params[ 'TEST' ][ 'mpls' ]
891
892 # Add a flow that connects host1 on port1 to host2 on port2
893 main.log.info( "Adding flow with MPLS selector" )
894 stepResult = main.ONOSrest.addFlow( deviceId=main.swDPID,
895 egressPort=egress,
896 ingressPort=ingress,
897 ethType=ethType,
898 mpls=mplsLabel,
899 debug=main.debug )
900
901 utilities.assert_equals( expect=main.TRUE,
902 actual=stepResult,
903 onpass="Successfully added flow",
904 onfail="Failed add flow" )
905
906 # Giving ONOS time to add the flow
907 time.sleep( main.addFlowSleep )
908
909 main.step( "Check flow is in the ADDED state" )
910
911 main.log.info( "Get the flows from ONOS" )
Jeremy86160992016-04-11 10:05:53 -0700912 try:
alisone14d7b02016-07-06 10:31:51 -0700913 flows = json.loads( main.ONOSrest.flows( ) )
GlennRC956ea742015-11-05 16:14:15 -0800914
Jeremy86160992016-04-11 10:05:53 -0700915 stepResult = main.TRUE
916 for f in flows:
alisone14d7b02016-07-06 10:31:51 -0700917 if "rest" in f.get( "appId" ):
918 if "ADDED" not in f.get( "state" ):
Jeremy86160992016-04-11 10:05:53 -0700919 stepResult = main.FALSE
alisone14d7b02016-07-06 10:31:51 -0700920 main.log.error( "Flow: %s in state: %s" % ( f.get( "id" ), f.get( "state" ) ) )
Jeremy86160992016-04-11 10:05:53 -0700921 except TypeError:
922 main.log.error( "No Flows found by the REST API" )
923 stepResult = main.FALSE
924 except ValueError:
925 main.log.error( "Problem getting Flows state from REST API. Exiting test" )
alisone14d7b02016-07-06 10:31:51 -0700926 main.cleanup( )
927 main.exit( )
GlennRC956ea742015-11-05 16:14:15 -0800928
929 utilities.assert_equals( expect=main.TRUE,
930 actual=stepResult,
931 onpass="All flows are in the ADDED state",
932 onfail="All flows are NOT in the ADDED state" )
933
934 main.step( "Check flows are in Mininet's flow table" )
935
936 # get the flow IDs that were added through rest
937 main.log.info( "Getting the flow IDs from ONOS" )
alisone14d7b02016-07-06 10:31:51 -0700938 flowIds = [ f.get( "id" ) for f in flows if "rest" in f.get( "appId" ) ]
GlennRC956ea742015-11-05 16:14:15 -0800939 # convert the flowIDs to ints then hex and finally back to strings
alisone14d7b02016-07-06 10:31:51 -0700940 flowIds = [ str( hex( int( x ) ) ) for x in flowIds ]
941 main.log.info( "ONOS flow IDs: {}".format( flowIds ) )
GlennRC956ea742015-11-05 16:14:15 -0800942
943 stepResult = main.Mininet1.checkFlowId( "s1", flowIds, debug=True )
944
945 utilities.assert_equals( expect=main.TRUE,
946 actual=stepResult,
947 onpass="All flows are in mininet",
948 onfail="All flows are NOT in mininet" )
949
950 main.step( "Send a packet to verify the flow is correct" )
951
952 main.log.info( "Starting filter on host2" )
953 main.h2.startFilter( pktFilter="mpls" )
954
955 main.log.info( "Constructing packet" )
956 main.log.info( "Sending packet to host2" )
alisone14d7b02016-07-06 10:31:51 -0700957 main.h1.sendPacket( packet='Ether()/MPLS(label={})'.format( mplsLabel ) )
GlennRC956ea742015-11-05 16:14:15 -0800958
959 main.log.info( "Checking filter for our packet" )
alisone14d7b02016-07-06 10:31:51 -0700960 stepResult = main.h2.checkFilter( )
GlennRC956ea742015-11-05 16:14:15 -0800961 if stepResult:
alisone14d7b02016-07-06 10:31:51 -0700962 main.log.info( "Packet: %s" % main.h2.readPackets( ) )
963 else: main.h2.killFilter( )
GlennRC956ea742015-11-05 16:14:15 -0800964
965 main.log.info( "Clean up host components" )
966 for host in hosts:
alisone14d7b02016-07-06 10:31:51 -0700967 host.stopScapy( )
968 main.Mininet1.removeHostComponent( "h1" )
969 main.Mininet1.removeHostComponent( "h2" )
GlennRC956ea742015-11-05 16:14:15 -0800970
971 utilities.assert_equals( expect=main.TRUE,
972 actual=stepResult,
973 onpass="Successfully sent a packet",
974 onfail="Failed to send a packet" )
975
alisone14d7b02016-07-06 10:31:51 -0700976 def CASE1700( self, main ):
GlennRC956ea742015-11-05 16:14:15 -0800977 '''
978 Add flows with a TCP selector and verify the flow
979 '''
980 import json
981 import time
982
983 main.case( "Verify the TCP selector is correctly compiled on the flow" )
984 main.caseExplanation = "Install a flow with only the TCP selector " +\
alisone14d7b02016-07-06 10:31:51 -0700985 "specified, verify the flow is added in ONOS, and finally " +\
GlennRC956ea742015-11-05 16:14:15 -0800986 "send a TCP packet to verify the TCP selector is compiled correctly."
987
988 main.step( "Add a flow with a TCP selector" )
989
990 main.log.info( "Creating host components" )
Jon Halla510a8a2016-05-04 15:09:28 -0700991 main.Scapy.createHostComponent( "h1" )
992 main.Scapy.createHostComponent( "h2" )
alisone14d7b02016-07-06 10:31:51 -0700993 hosts = [ main.h1, main.h2 ]
GlennRC956ea742015-11-05 16:14:15 -0800994 for host in hosts:
alisone14d7b02016-07-06 10:31:51 -0700995 host.startHostCli( )
996 host.startScapy( )
997 host.updateSelf( )
GlennRC956ea742015-11-05 16:14:15 -0800998
999 # Add a flow that connects host1 on port1 to host2 on port2
1000 egress = 2
1001 ingress = 1
1002 # IPv4 etherType
1003 ethType = main.params[ 'TEST' ][ 'ip4Type' ]
1004 # IP protocol
1005 ipProto = main.params[ 'TEST' ][ 'tcpProto' ]
1006 # TCP port destination
1007 tcpDst = main.params[ 'TEST' ][ 'tcpDst' ]
1008
1009 main.log.info( "Add a flow that connects host1 on port1 to host2 on port2" )
1010 stepResult = main.ONOSrest.addFlow( deviceId=main.swDPID,
1011 egressPort=egress,
1012 ingressPort=ingress,
1013 ethType=ethType,
1014 ipProto=ipProto,
1015 tcpDst=tcpDst,
1016 debug=main.debug )
1017
1018 utilities.assert_equals( expect=main.TRUE,
1019 actual=stepResult,
1020 onpass="Successfully added flows",
1021 onfail="Failed add flows" )
1022
1023 # Giving ONOS time to add the flow
1024 time.sleep( main.addFlowSleep )
1025
1026 main.step( "Check flow is in the ADDED state" )
1027
1028 main.log.info( "Get the flows from ONOS" )
Jeremy86160992016-04-11 10:05:53 -07001029 try:
alisone14d7b02016-07-06 10:31:51 -07001030 flows = json.loads( main.ONOSrest.flows( ) )
GlennRC956ea742015-11-05 16:14:15 -08001031
Jeremy86160992016-04-11 10:05:53 -07001032 stepResult = main.TRUE
1033 for f in flows:
alisone14d7b02016-07-06 10:31:51 -07001034 if "rest" in f.get( "appId" ):
1035 if "ADDED" not in f.get( "state" ):
Jeremy86160992016-04-11 10:05:53 -07001036 stepResult = main.FALSE
alisone14d7b02016-07-06 10:31:51 -07001037 main.log.error( "Flow: %s in state: %s" % ( f.get( "id" ), f.get( "state" ) ) )
Jeremy86160992016-04-11 10:05:53 -07001038 except TypeError:
1039 main.log.error( "No Flows found by the REST API" )
1040 stepResult = main.FALSE
1041 except ValueError:
1042 main.log.error( "Problem getting Flows state from REST API. Exiting test" )
alisone14d7b02016-07-06 10:31:51 -07001043 main.cleanup( )
1044 main.exit( )
GlennRC956ea742015-11-05 16:14:15 -08001045
1046 utilities.assert_equals( expect=main.TRUE,
1047 actual=stepResult,
1048 onpass="All flows are in the ADDED state",
1049 onfail="All flows are NOT in the ADDED state" )
1050
1051 main.step( "Check flows are in Mininet's flow table" )
1052
1053 # get the flow IDs that were added through rest
1054 main.log.info( "Getting the flow IDs from ONOS" )
alisone14d7b02016-07-06 10:31:51 -07001055 flowIds = [ f.get( "id" ) for f in flows if "rest" in f.get( "appId" ) ]
GlennRC956ea742015-11-05 16:14:15 -08001056 # convert the flowIDs to ints then hex and finally back to strings
alisone14d7b02016-07-06 10:31:51 -07001057 flowIds = [ str( hex( int( x ) ) ) for x in flowIds ]
1058 main.log.info( "ONOS flow IDs: {}".format( flowIds ) )
GlennRC956ea742015-11-05 16:14:15 -08001059
1060 stepResult = main.Mininet1.checkFlowId( "s1", flowIds, debug=False )
1061
1062 utilities.assert_equals( expect=main.TRUE,
1063 actual=stepResult,
1064 onpass="All flows are in mininet",
1065 onfail="All flows are NOT in mininet" )
1066
1067 main.step( "Send a packet to verify the flow is correct" )
1068
1069 main.log.info( "Constructing packet" )
1070 # No need for the MAC src dst
1071 main.h1.buildEther( dst=main.h2.hostMac )
1072 main.h1.buildIP( dst=main.h2.hostIp )
1073 main.h1.buildTCP( dport=tcpDst )
1074
1075 main.log.info( "Starting filter on host2" )
1076 # Defaults to ip
1077 main.h2.startFilter( pktFilter="tcp" )
1078
1079 main.log.info( "Sending packet to host2" )
alisone14d7b02016-07-06 10:31:51 -07001080 main.h1.sendPacket( )
GlennRC956ea742015-11-05 16:14:15 -08001081
1082 main.log.info( "Checking filter for our packet" )
alisone14d7b02016-07-06 10:31:51 -07001083 stepResult = main.h2.checkFilter( )
GlennRC956ea742015-11-05 16:14:15 -08001084 if stepResult:
alisone14d7b02016-07-06 10:31:51 -07001085 main.log.info( "Packet: %s" % main.h2.readPackets( ) )
1086 else: main.h2.killFilter( )
GlennRC956ea742015-11-05 16:14:15 -08001087
1088 main.log.info( "Clean up host components" )
1089 for host in hosts:
alisone14d7b02016-07-06 10:31:51 -07001090 host.stopScapy( )
1091 main.Mininet1.removeHostComponent( "h1" )
1092 main.Mininet1.removeHostComponent( "h2" )
GlennRC956ea742015-11-05 16:14:15 -08001093
1094 utilities.assert_equals( expect=main.TRUE,
1095 actual=stepResult,
1096 onpass="Successfully sent a packet",
1097 onfail="Failed to send a packet" )
1098
alisone14d7b02016-07-06 10:31:51 -07001099 def CASE1600( self, main ):
GlennRC956ea742015-11-05 16:14:15 -08001100 '''
1101 Add flows with a UDP selector and verify the flow
1102 '''
1103 import json
1104 import time
1105
1106 main.case( "Verify the UDP selector is correctly compiled on the flow" )
1107 main.caseExplanation = "Install a flow with only the UDP selector " +\
alisone14d7b02016-07-06 10:31:51 -07001108 "specified, verify the flow is added in ONOS, and finally " +\
GlennRC956ea742015-11-05 16:14:15 -08001109 "send a UDP packet to verify the UDP selector is compiled correctly."
1110
1111 main.step( "Add a flow with a UDP selector" )
1112
1113 main.log.info( "Creating host components" )
Jon Halla510a8a2016-05-04 15:09:28 -07001114 main.Scapy.createHostComponent( "h1" )
1115 main.Scapy.createHostComponent( "h2" )
alisone14d7b02016-07-06 10:31:51 -07001116 hosts = [ main.h1, main.h2 ]
GlennRC956ea742015-11-05 16:14:15 -08001117 for host in hosts:
alisone14d7b02016-07-06 10:31:51 -07001118 host.startHostCli( )
1119 host.startScapy( )
1120 host.updateSelf( )
GlennRC956ea742015-11-05 16:14:15 -08001121
1122 # Add a flow that connects host1 on port1 to host2 on port2
1123 egress = 2
1124 ingress = 1
1125 # IPv4 etherType
1126 ethType = main.params[ 'TEST' ][ 'ip4Type' ]
1127 # IP protocol
1128 ipProto = main.params[ 'TEST' ][ 'udpProto' ]
1129 # UDP port destination
1130 udpDst = main.params[ 'TEST' ][ 'udpDst' ]
1131
1132 main.log.info( "Add a flow that connects host1 on port1 to host2 on port2" )
1133 stepResult = main.ONOSrest.addFlow( deviceId=main.swDPID,
1134 egressPort=egress,
1135 ingressPort=ingress,
1136 ethType=ethType,
1137 ipProto=ipProto,
1138 udpDst=udpDst,
1139 debug=main.debug )
1140
1141 utilities.assert_equals( expect=main.TRUE,
1142 actual=stepResult,
1143 onpass="Successfully added flows",
1144 onfail="Failed add flows" )
1145
1146 # Giving ONOS time to add the flow
1147 time.sleep( main.addFlowSleep )
1148
1149 main.step( "Check flow is in the ADDED state" )
1150
1151 main.log.info( "Get the flows from ONOS" )
Jeremy86160992016-04-11 10:05:53 -07001152 try:
alisone14d7b02016-07-06 10:31:51 -07001153 flows = json.loads( main.ONOSrest.flows( ) )
GlennRC956ea742015-11-05 16:14:15 -08001154
Jeremy86160992016-04-11 10:05:53 -07001155 stepResult = main.TRUE
1156 for f in flows:
alisone14d7b02016-07-06 10:31:51 -07001157 if "rest" in f.get( "appId" ):
1158 if "ADDED" not in f.get( "state" ):
Jeremy86160992016-04-11 10:05:53 -07001159 stepResult = main.FALSE
alisone14d7b02016-07-06 10:31:51 -07001160 main.log.error( "Flow: %s in state: %s" % ( f.get( "id" ), f.get( "state" ) ) )
Jeremy86160992016-04-11 10:05:53 -07001161 except TypeError:
1162 main.log.error( "No Flows found by the REST API" )
1163 stepResult = main.FALSE
1164 except ValueError:
1165 main.log.error( "Problem getting Flows state from REST API. Exiting test" )
alisone14d7b02016-07-06 10:31:51 -07001166 main.cleanup( )
1167 main.exit( )
GlennRC956ea742015-11-05 16:14:15 -08001168
1169 utilities.assert_equals( expect=main.TRUE,
1170 actual=stepResult,
1171 onpass="All flows are in the ADDED state",
1172 onfail="All flows are NOT in the ADDED state" )
1173
1174 main.step( "Check flows are in Mininet's flow table" )
1175
1176 # get the flow IDs that were added through rest
1177 main.log.info( "Getting the flow IDs from ONOS" )
alisone14d7b02016-07-06 10:31:51 -07001178 flowIds = [ f.get( "id" ) for f in flows if "rest" in f.get( "appId" ) ]
GlennRC956ea742015-11-05 16:14:15 -08001179 # convert the flowIDs to ints then hex and finally back to strings
alisone14d7b02016-07-06 10:31:51 -07001180 flowIds = [ str( hex( int( x ) ) ) for x in flowIds ]
1181 main.log.info( "ONOS flow IDs: {}".format( flowIds ) )
GlennRC956ea742015-11-05 16:14:15 -08001182
1183 stepResult = main.Mininet1.checkFlowId( "s1", flowIds, debug=False )
1184
1185 utilities.assert_equals( expect=main.TRUE,
1186 actual=stepResult,
1187 onpass="All flows are in mininet",
1188 onfail="All flows are NOT in mininet" )
1189
1190 main.step( "Send a packet to verify the flow is correct" )
1191
1192 main.log.info( "Constructing packet" )
1193 # No need for the MAC src dst
1194 main.h1.buildEther( dst=main.h2.hostMac )
1195 main.h1.buildIP( dst=main.h2.hostIp )
1196 main.h1.buildUDP( dport=udpDst )
1197
1198 main.log.info( "Starting filter on host2" )
1199 # Defaults to ip
1200 main.h2.startFilter( pktFilter="udp" )
1201
1202 main.log.info( "Sending packet to host2" )
alisone14d7b02016-07-06 10:31:51 -07001203 main.h1.sendPacket( )
GlennRC956ea742015-11-05 16:14:15 -08001204
1205 main.log.info( "Checking filter for our packet" )
alisone14d7b02016-07-06 10:31:51 -07001206 stepResult = main.h2.checkFilter( )
GlennRC956ea742015-11-05 16:14:15 -08001207 if stepResult:
alisone14d7b02016-07-06 10:31:51 -07001208 main.log.info( "Packet: %s" % main.h2.readPackets( ) )
1209 else: main.h2.killFilter( )
GlennRC956ea742015-11-05 16:14:15 -08001210
1211 main.log.info( "Clean up host components" )
1212 for host in hosts:
alisone14d7b02016-07-06 10:31:51 -07001213 host.stopScapy( )
1214 main.Mininet1.removeHostComponent( "h1" )
1215 main.Mininet1.removeHostComponent( "h2" )
GlennRC956ea742015-11-05 16:14:15 -08001216
1217 utilities.assert_equals( expect=main.TRUE,
1218 actual=stepResult,
1219 onpass="Successfully sent a packet",
1220 onfail="Failed to send a packet" )
1221
alisone14d7b02016-07-06 10:31:51 -07001222 def CASE1900( self, main ):
1223 '''
1224 Add flows with a ICMPv4 selector and verify the flow
1225 '''
GlennRC956ea742015-11-05 16:14:15 -08001226 import json
alisone14d7b02016-07-06 10:31:51 -07001227 import time
GlennRC956ea742015-11-05 16:14:15 -08001228
alisone14d7b02016-07-06 10:31:51 -07001229 main.case( "Verify the ICMPv4 selector is correctly compiled on the flow" )
1230 main.caseExplanation = "Install a flow with only the ICMPv4 selector " +\
1231 "specified, verify the flow is added in ONOS, and finally " +\
1232 "send a IMCPv4 packet to verify the ICMPv4 selector is compiled correctly."
GlennRC956ea742015-11-05 16:14:15 -08001233
alisone14d7b02016-07-06 10:31:51 -07001234 main.step( "Add a flow with a ICMPv4 selector" )
1235
1236 main.log.info( "Creating host components" )
1237 main.Scapy.createHostComponent( "h1" )
1238 main.Scapy.createHostComponent( "h2" )
1239 hosts = [ main.h1, main.h2 ]
1240 for host in hosts:
1241 host.startHostCli( )
1242 host.startScapy( )
1243 host.updateSelf( )
1244
1245 # Add a flow that connects host1 on port1 to host2 on port2
1246 egress = 2
1247 ingress = 1
1248 # IPv4 etherType
1249 ethType = main.params[ 'TEST' ][ 'ip4Type' ]
1250 # IP protocol
1251 ipProto = main.params[ 'TEST' ][ 'icmpProto' ]
1252
1253 main.log.info( "Add a flow that connects host1 on port1 to host2 on port2" )
1254 stepResult = main.ONOSrest.addFlow( deviceId=main.swDPID,
1255 egressPort=egress,
1256 ingressPort=ingress,
1257 ethType=ethType,
1258 ipProto=ipProto,
1259 debug=main.debug )
1260
1261 utilities.assert_equals( expect=main.TRUE,
1262 actual=stepResult,
1263 onpass="Successfully added flows",
1264 onfail="Failed add flows" )
1265
1266 # Giving ONOS time to add the flow
1267 time.sleep( main.addFlowSleep )
1268
1269 main.step( "Check flow is in the ADDED state" )
1270
1271 main.log.info( "Get the flows from ONOS" )
Jeremy86160992016-04-11 10:05:53 -07001272 try:
alisone14d7b02016-07-06 10:31:51 -07001273 flows = json.loads( main.ONOSrest.flows( ) )
GlennRC956ea742015-11-05 16:14:15 -08001274
Jeremy86160992016-04-11 10:05:53 -07001275 stepResult = main.TRUE
1276 for f in flows:
alisone14d7b02016-07-06 10:31:51 -07001277 if "rest" in f.get( "appId" ):
1278 if "ADDED" not in f.get( "state" ):
1279 stepResult = main.FALSE
1280 main.log.error( "Flow: %s in state: %s" % ( f.get( "id" ), f.get( "state" ) ) )
Jeremy86160992016-04-11 10:05:53 -07001281 except TypeError:
1282 main.log.error( "No Flows found by the REST API" )
1283 stepResult = main.FALSE
1284 except ValueError:
1285 main.log.error( "Problem getting Flows state from REST API. Exiting test" )
alisone14d7b02016-07-06 10:31:51 -07001286 main.cleanup( )
1287 main.exit( )
1288
1289 utilities.assert_equals( expect=main.TRUE,
1290 actual=stepResult,
1291 onpass="All flows are in the ADDED state",
1292 onfail="All flows are NOT in the ADDED state" )
1293
1294 main.step( "Check flows are in Mininet's flow table" )
1295
1296 # get the flow IDs that were added through rest
1297 main.log.info( "Getting the flow IDs from ONOS" )
1298 flowIds = [ f.get( "id" ) for f in flows if "rest" in f.get( "appId" ) ]
1299 # convert the flowIDs to ints then hex and finally back to strings
1300 flowIds = [ str( hex( int( x ) ) ) for x in flowIds ]
1301 main.log.info( "ONOS flow IDs: {}".format( flowIds ) )
1302
1303 stepResult = main.Mininet1.checkFlowId( "s1", flowIds, debug=False )
1304
1305 utilities.assert_equals( expect=main.TRUE,
1306 actual=stepResult,
1307 onpass="All flows are in mininet",
1308 onfail="All flows are NOT in mininet" )
1309
1310 main.step( "Send a packet to verify the flow is correct" )
1311
1312 main.log.info( "Constructing packet" )
1313 # No need for the MAC src dst
1314 main.h1.buildEther( dst=main.h2.hostMac )
1315 main.h1.buildIP( dst=main.h2.hostIp )
1316 main.h1.buildICMP( )
1317
1318 main.log.info( "Starting filter on host2" )
1319 # Defaults to ip
1320 main.h2.startFilter( pktFilter="icmp" )
1321
1322 main.log.info( "Sending packet to host2" )
1323 main.h1.sendPacket( )
1324
1325 main.log.info( "Checking filter for our packet" )
1326 stepResult = main.h2.checkFilter( )
1327 if stepResult:
1328 main.log.info( "Packet: %s" % main.h2.readPackets( ) )
1329 else: main.h2.killFilter( )
1330
1331 main.log.info( "Clean up host components" )
1332 for host in hosts:
1333 host.stopScapy( )
1334 main.Mininet1.removeHostComponent( "h1" )
1335 main.Mininet1.removeHostComponent( "h2" )
1336
1337 utilities.assert_equals( expect=main.TRUE,
1338 actual=stepResult,
1339 onpass="Successfully sent a packet",
1340 onfail="Failed to send a packet" )
1341
1342 def CASE2000( self, main ):
1343 '''
1344 Add flows with a ICMPv6 selector and verify the flow
1345 '''
1346 import json
1347 import time
1348
1349 main.case( "Verify the ICMPv6 selector is correctly compiled on the flow" )
1350 main.caseExplanation = "Install a flow with only the ICMPv6 selector " +\
1351 "specified, verify the flow is added in ONOS, and finally " +\
1352 "send a IMCPv6 packet to verify the ICMPv6 selector is compiled correctly."
1353
1354 main.step( "Add a flow with a ICMPv6 selector" )
1355
1356 main.log.info( "Creating host components" )
1357 main.Scapy.createHostComponent( "h5" )
1358 main.Scapy.createHostComponent( "h6" )
1359 hosts =[ main.h5, main.h6 ]
1360 for host in hosts:
1361 host.startHostCli( )
1362 host.startScapy( )
1363 host.updateSelf( IPv6=True )
1364
1365 # Add a flow that connects host1 on port1 to host2 on port2
1366 egress =6
1367 ingress =5
1368 # IPv6 etherType
1369 ethType = main.params[ 'TEST' ][ 'ip6Type' ]
1370 # IP protocol
1371 ipProto = main.params[ 'TEST' ][ 'icmp6Proto' ]
1372
1373 main.log.info( "Add a flow that connects host1 on port1 to host2 on port2" )
1374 stepResult = main.ONOSrest.addFlow( deviceId=main.swDPID,
1375 egressPort=egress,
1376 ingressPort=ingress,
1377 ethType=ethType,
1378 ipProto=ipProto,
1379 debug=main.debug )
1380
1381 utilities.assert_equals( expect=main.TRUE,
1382 actual=stepResult,
1383 onpass="Successfully added flows",
1384 onfail="Failed add flows" )
1385
1386 # Giving ONOS time to add the flow
1387 time.sleep( main.addFlowSleep )
1388
1389 main.step( "Check flow is in the ADDED state" )
1390
1391 main.log.info( "Get the flows from ONOS" )
1392 try:
1393 flows = json.loads( main.ONOSrest.flows( ) )
1394
1395 stepResult = main.TRUE
1396 for f in flows:
1397 if "rest" in f.get( "appId" ):
1398 if "ADDED" not in f.get( "state" ):
1399 stepResult = main.FALSE
1400 main.log.error( "Flow: %s in state: %s" % ( f.get( "id" ), f.get( "state" ) ) )
1401 except TypeError:
1402 main.log.error( "No Flows found by the REST API" )
1403 stepResult = main.FALSE
1404 except ValueError:
1405 main.log.error( "Problem getting Flows state from REST API. Exiting test" )
1406 main.cleanup( )
1407 main.exit( )
1408
1409 utilities.assert_equals( expect=main.TRUE,
1410 actual=stepResult,
1411 onpass="All flows are in the ADDED state",
1412 onfail="All flows are NOT in the ADDED state" )
1413
1414 main.step( "Check flows are in Mininet's flow table" )
1415
1416 # get the flow IDs that were added through rest
1417 main.log.info( "Getting the flow IDs from ONOS" )
1418 flowIds = [ f.get( "id" ) for f in flows if "rest" in f.get( "appId" ) ]
1419 # convert the flowIDs to ints then hex and finally back to strings
1420 flowIds = [ str( hex( int( x ) ) ) for x in flowIds ]
1421 main.log.info( "ONOS flow IDs: {}".format( flowIds ) )
1422
1423 stepResult = main.Mininet1.checkFlowId( "s1", flowIds, debug=False )
1424
1425 utilities.assert_equals( expect=main.TRUE,
1426 actual=stepResult,
1427 onpass="All flows are in mininet",
1428 onfail="All flows are NOT in mininet" )
1429
1430 main.step( "Send a packet to verify the flow is correct" )
1431
1432 main.log.info( "Constructing packet" )
1433 # No need for the MAC src dst
1434 main.h5.buildEther( dst=main.h6.hostMac )
1435 main.h5.buildIPv6( dst=main.h6.hostIp )
1436 main.h5.buildICMP( ipVersion=6 )
1437
1438 main.log.info( "Starting filter on host2" )
1439 # Defaults to ip
1440 main.h6.startFilter( pktFilter="icmp6" )
1441
1442 main.log.info( "Sending packet to host2" )
1443 main.h5.sendPacket( )
1444
1445 main.log.info( "Checking filter for our packet" )
1446 stepResult = main.h6.checkFilter( )
1447 if stepResult:
1448 main.log.info( "Packet: %s" % main.h6.readPackets( ) )
1449 else: main.h6.killFilter( )
1450
1451 main.log.info( "Clean up host components" )
1452 for host in hosts:
1453 host.stopScapy( )
1454 main.Mininet1.removeHostComponent( "h5" )
1455 main.Mininet1.removeHostComponent( "h6" )
1456
1457 utilities.assert_equals( expect=main.TRUE,
1458 actual=stepResult,
1459 onpass="Successfully sent a packet",
1460 onfail="Failed to send a packet" )
1461
1462 def CASE3000( self, main ):
1463 '''
1464 Delete flow
1465 '''
1466 import json
1467
1468 main.case( "Delete flows that were added through rest" )
1469 main.step( "Deleting flows" )
1470
1471 main.log.info( "Getting flows" )
1472 try:
1473 flows = json.loads( main.ONOSrest.flows( ) )
1474
1475 stepResult = main.TRUE
1476 for f in flows:
1477 if "rest" in f.get( "appId" ):
1478 if main.debug: main.log.debug( "Flow to be deleted:\n{}".format( main.ONOSrest.pprint( f ) ) )
1479 stepResult = stepResult and main.ONOSrest.removeFlow( f.get( "deviceId" ), f.get( "id" ) )
1480 except TypeError:
1481 main.log.error( "No Flows found by the REST API" )
1482 stepResult = main.FALSE
1483 except ValueError:
1484 main.log.error( "Problem getting Flows state from REST API. Exiting test" )
1485 main.cleanup( )
1486 main.exit( )
GlennRC956ea742015-11-05 16:14:15 -08001487
1488 utilities.assert_equals( expect=main.TRUE,
1489 actual=stepResult,
1490 onpass="Successfully deleting flows",
1491 onfail="Failed to delete flows" )
1492
1493 time.sleep( main.delFlowSleep )
1494
alisone14d7b02016-07-06 10:31:51 -07001495
1496 def CASE1200(self, main ):
1497 '''
1498 Add flows with a ARP selector and verify the flow
1499 '''
1500 import json
1501 import time
1502
1503 main.case( "Verify flow IP selectors are correctly compiled" )
1504 main.caseExplanation = "Install two flows with only IP selectors " + \
1505 "specified, then verify flows are added in ONOS, finally " + \
1506 "send a packet that only specifies the IP src and dst."
1507
1508 main.step( "Add flows with ARP addresses as the only selectors" )
1509
1510 main.log.info( "Creating host components" )
1511 main.Scapy.createHostComponent( "h1" )
1512 main.Scapy.createHostComponent( "h2" )
1513 hosts = [ main.h1, main.h2 ]
1514 for host in hosts:
1515 host.startHostCli( )
1516 host.startScapy( )
1517 host.updateSelf( )
1518
1519 # Add a flow that connects host1 on port1 to host2 on port2
1520 # send output on port2
1521 # recieve input on port1
1522 egress = 2
1523 ingress = 1
1524 # ARP etherType = 0x0806
1525 ethType = main.params[ 'TEST' ][ 'arpType' ]
1526
1527 # Add flows that connects host1 to host2
1528 main.log.info( "Add flow with port ingress 1 to port egress 2" )
1529 stepResult = main.ONOSrest.addFlow(deviceId=main.swDPID,
1530 egressPort=egress,
1531 ingressPort=ingress,
1532 ethType=ethType,
1533 priority=40001,
1534 debug=main.debug )
1535
1536 utilities.assert_equals( expect=main.TRUE,
1537 actual=stepResult,
1538 onpass="Successfully added flows",
1539 onfail="Failed add flows" )
1540
1541 # Giving ONOS time to add the flow
1542 time.sleep( main.addFlowSleep )
1543
1544 main.step( "Check flow is in the ADDED state" )
1545
1546 main.log.info( "Get the flows from ONOS" )
1547 try:
1548 flows = json.loads( main.ONOSrest.flows( ) )
1549
1550 stepResult = main.TRUE
1551 for f in flows:
1552 if "rest" in f.get( "appId" ):
1553 if "ADDED" not in f.get( "state" ):
1554 stepResult = main.FALSE
1555 main.log.error("Flow: %s in state: %s" % ( f.get("id"), f.get( "state" ) ) )
1556 except TypeError:
1557 main.log.error( "No Flows found by the REST API" )
1558 stepResult = main.FALSE
1559 except ValueError:
1560 main.log.error( "Problem getting Flows state from REST API. Exiting test" )
1561 main.cleanup( )
1562 main.exit( )
1563
1564 utilities.assert_equals( expect=main.TRUE,
1565 actual=stepResult,
1566 onpass="All flows are in the ADDED state",
1567 onfail="All flows are NOT in the ADDED state" )
1568
1569 main.step( "Check flows are in Mininet's flow table" )
1570
1571 # get the flow IDs that were added through rest
1572 main.log.info( "Getting the flow IDs from ONOS" )
1573 flowIds = [f.get( "id" ) for f in flows if "rest" in f.get( "appId" ) ]
1574 # convert the flowIDs to ints then hex and finally back to strings
1575 flowIds = [ str( hex( int( x ) ) ) for x in flowIds ]
1576 main.log.info("ONOS flow IDs: {}".format( flowIds ) )
1577
1578 stepResult = main.Mininet1.checkFlowId( "s1", flowIds, debug=False )
1579
1580 utilities.assert_equals( expect=main.TRUE,
1581 actual=stepResult,
1582 onpass="All flows are in mininet",
1583 onfail="All flows are NOT in mininet" )
1584
1585 main.step( "Send a packet to verify the flow is correct" )
1586
1587 main.log.info( "Constructing packet" )
1588 # No need for the MAC src dst
1589 main.h1.buildEther( src=main.h1.hostMac, dst=main.h2.hostMac )
1590 main.h1.buildARP( pdst=main.h2.hostIp )
1591
1592 main.log.info( "Starting filter on host2" )
1593 # Defaults to ip
1594 main.h2.startFilter( pktFilter="arp" )
1595
1596 main.log.info( "Sending packet to host2" )
1597 main.h1.sendPacket( )
1598
1599 main.log.info( "Checking filter for our packet" )
1600 stepResult = main.h2.checkFilter( )
1601 if stepResult:
1602 main.log.info( "Packet: %s" % main.h2.readPackets( ) )
1603 else:
1604 main.h2.killFilter( )
1605
1606 main.log.info( "Clean up host components" )
1607 for host in hosts:
1608 host.stopScapy( )
1609 main.Mininet1.removeHostComponent( "h1" )
1610 main.Mininet1.removeHostComponent( "h2" )
1611
1612 utilities.assert_equals( expect=main.TRUE,
1613 actual=stepResult,
1614 onpass="Successfully sent a packet",
1615 onfail="Failed to send a packet" )
1616
1617 def CASE1800( self, main ):
1618 '''
1619 Add flows with a SCTP selector and verify the flow
1620 '''
1621 import json
1622 import time
1623
1624 main.case( "Verify the UDP selector is correctly compiled on the flow" )
1625 main.caseExplanation = "Install a flow with only the UDP selector " + \
1626 "specified, verify the flow is added in ONOS, and finally " + \
1627 "send a UDP packet to verify the UDP selector is compiled correctly."
1628
1629 main.step( "Add a flow with a SCTP selector" )
1630
1631 main.log.info( "Creating host components" )
1632 main.Scapy.createHostComponent( "h1" )
1633 main.Scapy.createHostComponent( "h2" )
1634 hosts = [ main.h1, main.h2 ]
1635 for host in hosts:
1636 host.startHostCli( )
1637 host.startScapy( )
1638 host.updateSelf( )
1639
1640 # Add a flow that connects host1 on port1 to host2 on port2
1641 egress = 2
1642 ingress = 1
1643 # IPv4 etherType
1644 ethType = main.params[ 'TEST' ][ 'ip4Type' ]
1645 # IP protocol
1646 ipProto = main.params[ 'TEST' ][ 'sctpProto' ]
1647
1648 main.log.info("Add a flow that connects host1 on port1 to host2 on port2")
1649 stepResult = main.ONOSrest.addFlow( deviceId=main.swDPID,
1650 egressPort=egress,
1651 ingressPort=ingress,
1652 ethType=ethType,
1653 ipProto=ipProto,
1654 debug=main.debug )
1655
1656 utilities.assert_equals( expect=main.TRUE,
1657 actual=stepResult,
1658 onpass="Successfully added flows",
1659 onfail="Failed add flows" )
1660
1661 # Giving ONOS time to add the flow
1662 time.sleep( main.addFlowSleep )
1663
1664 main.step( "Check flow is in the ADDED state" )
1665
1666 main.log.info( "Get the flows from ONOS" )
1667 try:
1668 flows = json.loads( main.ONOSrest.flows( ) )
1669
1670 stepResult = main.TRUE
1671 for f in flows:
1672 if "rest" in f.get( "appId" ):
1673 if "ADDED" not in f.get( "state" ):
1674 stepResult = main.FALSE
1675 main.log.error("Flow: %s in state: %s" % ( f.get( "id" ), f.get( "state" ) ) )
1676 except TypeError:
1677 main.log.error( "No Flows found by the REST API" )
1678 stepResult = main.FALSE
1679 except ValueError:
1680 main.log.error( "Problem getting Flows state from REST API. Exiting test" )
1681 main.cleanup( )
1682 main.exit( )
1683
1684 utilities.assert_equals( expect=main.TRUE,
1685 actual=stepResult,
1686 onpass="All flows are in the ADDED state",
1687 onfail="All flows are NOT in the ADDED state" )
1688
1689 main.step( "Check flows are in Mininet's flow table" )
1690
1691 # get the flow IDs that were added through rest
1692 main.log.info( "Getting the flow IDs from ONOS" )
1693 flowIds = [ f.get( "id" ) for f in flows if "rest" in f.get( "appId" ) ]
1694 # convert the flowIDs to ints then hex and finally back to strings
1695 flowIds = [ str( hex( int( x ) ) ) for x in flowIds ]
1696 main.log.info( "ONOS flow IDs: {}".format( flowIds ) )
1697
1698 stepResult = main.Mininet1.checkFlowId( "s1", flowIds, debug=False )
1699
1700 utilities.assert_equals( expect=main.TRUE,
1701 actual=stepResult,
1702 onpass="All flows are in mininet",
1703 onfail="All flows are NOT in mininet" )
1704
1705 main.step( "Send a packet to verify the flow is correct" )
1706
1707 main.log.info( "Constructing packet" )
1708 # No need for the MAC src dst
1709 main.h1.buildEther( dst=main.h2.hostMac )
1710 main.h1.buildIP( dst=main.h2.hostIp )
1711 main.h1.buildSCTP( )
1712
1713 main.log.info( "Starting filter on host2" )
1714 # Defaults to ip
1715 main.h2.startFilter( pktFilter="sctp" )
1716
1717 main.log.info( "Sending packet to host2" )
1718 main.h1.sendPacket( )
1719
1720 main.log.info( "Checking filter for our packet" )
1721 stepResult = main.h2.checkFilter( )
1722 if stepResult:
1723 main.log.info( "Packet: %s" % main.h2.readPackets( ) )
1724 else:
1725 main.h2.killFilter( )
1726
1727 main.log.info( "Clean up host components" )
1728 for host in hosts:
1729 host.stopScapy( )
1730 main.Mininet1.removeHostComponent( "h1" )
1731 main.Mininet1.removeHostComponent( "h2" )
1732
1733 utilities.assert_equals( expect=main.TRUE,
1734 actual=stepResult,
1735 onpass="Successfully sent a packet",
1736 onfail="Failed to send a packet" )
1737
GlennRC68449942015-10-16 16:03:12 -07001738 def CASE100( self, main ):
GlennRC5147a422015-10-06 17:26:17 -07001739 '''
1740 Report errors/warnings/exceptions
1741 '''
alisone14d7b02016-07-06 10:31:51 -07001742 main.log.info( "Error report: \n" )
GlennRC5147a422015-10-06 17:26:17 -07001743 main.ONOSbench.logReport( main.ONOSip[ 0 ],
1744 [ "INFO",
1745 "FOLLOWER",
1746 "WARN",
1747 "flow",
1748 "ERROR",
1749 "Except" ],
GlennRC68449942015-10-16 16:03:12 -07001750 "s" )