blob: eeed4515f730e212604fc60db001324089aca65b [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 ):
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' ]
GlennRC073e8bc2015-10-27 17:11:28 -070030 gitPull = main.params[ 'GIT' ][ 'pull' ]
31 main.ONOSport = main.params[ 'CTRL' ][ 'port' ]
GlennRC5147a422015-10-06 17:26:17 -070032 main.dependencyPath = main.testOnDirectory + \
33 main.params[ 'DEPENDENCY' ][ 'path' ]
GlennRC5147a422015-10-06 17:26:17 -070034 wrapperFile1 = main.params[ 'DEPENDENCY' ][ 'wrapper1' ]
GlennRC1704d072015-10-07 18:40:45 -070035 wrapperFile2 = main.params[ 'DEPENDENCY' ][ 'wrapper2' ]
GlennRC073e8bc2015-10-27 17:11:28 -070036 main.topology = main.params[ 'DEPENDENCY' ][ 'topology' ]
37 main.maxNodes = int( main.params[ 'SCALE' ][ 'max' ] )
GlennRC5147a422015-10-06 17:26:17 -070038 main.startUpSleep = int( main.params[ 'SLEEP' ][ 'startup' ] )
GlennRC073e8bc2015-10-27 17:11:28 -070039 main.startMNSleep = int( main.params[ 'SLEEP' ][ 'startMN' ] )
40 main.addFlowSleep = int( main.params[ 'SLEEP' ][ 'addFlow' ] )
41 main.delFlowSleep = int( main.params[ 'SLEEP' ][ 'delFlow' ] )
GlennRC956ea742015-11-05 16:14:15 -080042 main.debug = main.params['DEBUG']
GlennRC073e8bc2015-10-27 17:11:28 -070043 main.swDPID = main.params[ 'TEST' ][ 'swDPID' ]
GlennRC5147a422015-10-06 17:26:17 -070044 main.cellData = {} # for creating cell file
45 main.CLIs = []
46 main.ONOSip = []
47
GlennRC956ea742015-11-05 16:14:15 -080048 main.debug = True if "on" in main.debug else False
49
GlennRC5147a422015-10-06 17:26:17 -070050 main.ONOSip = main.ONOSbench.getOnosIps()
GlennRC5147a422015-10-06 17:26:17 -070051
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
GlennRC1704d072015-10-07 18:40:45 -070062 main.topo = imp.load_source( wrapperFile2,
63 main.dependencyPath +
64 wrapperFile2 +
65 ".py" )
66
GlennRC956ea742015-11-05 16:14:15 -080067
GlennRC94ed2232015-10-07 15:08:57 -070068 copyResult = main.ONOSbench.scp( main.Mininet1,
69 main.dependencyPath+main.topology,
70 main.Mininet1.home+'/custom/',
71 direction="to" )
72
GlennRC5147a422015-10-06 17:26:17 -070073 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" +
Jon Hall70b2ff42015-11-17 15:49:44 -0800119 " before initiating environment setup" )
GlennRC5147a422015-10-06 17:26:17 -0700120
121 for i in range( main.maxNodes ):
122 main.ONOSbench.onosDie( main.ONOSip[ i ] )
123
Jon Hall53c5e662016-04-13 16:06:56 -0700124 main.log.info( "NODE COUNT = " + str( main.numCtrls ) )
GlennRC5147a422015-10-06 17:26:17 -0700125
126 tempOnosIp = []
127 for i in range( main.numCtrls ):
128 tempOnosIp.append( main.ONOSip[i] )
129
Jon Hall53c5e662016-04-13 16:06:56 -0700130 main.ONOSbench.createCellFile( main.ONOSbench.ip_address,
131 "temp",
132 main.Mininet1.ip_address,
133 main.apps,
134 tempOnosIp )
GlennRC5147a422015-10-06 17:26:17 -0700135
136 main.step( "Apply cell to environment" )
137 cellResult = main.ONOSbench.setCell( "temp" )
138 verifyResult = main.ONOSbench.verifyCell()
139 stepResult = cellResult and verifyResult
140 utilities.assert_equals( expect=main.TRUE,
141 actual=stepResult,
142 onpass="Successfully applied cell to " + \
143 "environment",
144 onfail="Failed to apply cell to environment " )
145
146 main.step( "Creating ONOS package" )
147 packageResult = main.ONOSbench.onosPackage()
148 stepResult = packageResult
149 utilities.assert_equals( expect=main.TRUE,
150 actual=stepResult,
151 onpass="Successfully created ONOS package",
152 onfail="Failed to create ONOS package" )
153
154 time.sleep( main.startUpSleep )
155 main.step( "Uninstalling ONOS package" )
156 onosUninstallResult = main.TRUE
Jeremy86160992016-04-11 10:05:53 -0700157 for ip in main.ONOSip:
GlennRC5147a422015-10-06 17:26:17 -0700158 onosUninstallResult = onosUninstallResult and \
Jeremy86160992016-04-11 10:05:53 -0700159 main.ONOSbench.onosUninstall( nodeIp=ip )
GlennRC5147a422015-10-06 17:26:17 -0700160 stepResult = onosUninstallResult
161 utilities.assert_equals( expect=main.TRUE,
162 actual=stepResult,
163 onpass="Successfully uninstalled ONOS package",
164 onfail="Failed to uninstall ONOS package" )
GlennRC5147a422015-10-06 17:26:17 -0700165 time.sleep( main.startUpSleep )
166 main.step( "Installing ONOS package" )
167 onosInstallResult = main.TRUE
168 for i in range( main.numCtrls ):
169 onosInstallResult = onosInstallResult and \
170 main.ONOSbench.onosInstall( node=main.ONOSip[ i ] )
171 stepResult = onosInstallResult
172 utilities.assert_equals( expect=main.TRUE,
173 actual=stepResult,
174 onpass="Successfully installed ONOS package",
175 onfail="Failed to install ONOS package" )
176
177 time.sleep( main.startUpSleep )
178 main.step( "Starting ONOS service" )
179 stopResult = main.TRUE
180 startResult = main.TRUE
181 onosIsUp = main.TRUE
182
183 for i in range( main.numCtrls ):
184 onosIsUp = onosIsUp and main.ONOSbench.isup( main.ONOSip[ i ] )
185 if onosIsUp == main.TRUE:
186 main.log.report( "ONOS instance is up and ready" )
187 else:
188 main.log.report( "ONOS instance may not be up, stop and " +
189 "start ONOS again " )
190 for i in range( main.numCtrls ):
191 stopResult = stopResult and \
192 main.ONOSbench.onosStop( main.ONOSip[ i ] )
193 for i in range( main.numCtrls ):
194 startResult = startResult and \
195 main.ONOSbench.onosStart( main.ONOSip[ i ] )
196 stepResult = onosIsUp and stopResult and startResult
197 utilities.assert_equals( expect=main.TRUE,
198 actual=stepResult,
199 onpass="ONOS service is ready",
200 onfail="ONOS service did not start properly" )
201
202 main.step( "Start ONOS cli" )
203 cliResult = main.TRUE
204 for i in range( main.numCtrls ):
205 cliResult = cliResult and \
206 main.CLIs[ i ].startOnosCli( main.ONOSip[ i ] )
207 stepResult = cliResult
208 utilities.assert_equals( expect=main.TRUE,
209 actual=stepResult,
210 onpass="Successfully start ONOS cli",
211 onfail="Failed to start ONOS cli" )
212
GlennRC68449942015-10-16 16:03:12 -0700213 def CASE10( self, main ):
214 '''
215 Start Mininet
216 '''
GlennRC073e8bc2015-10-27 17:11:28 -0700217 import json
218
219 main.case( "Setup mininet and compare ONOS topology view to Mininet topology" )
220 main.caseExplanation = "Start mininet with custom topology and compare topology " +\
221 "elements between Mininet and ONOS"
222
GlennRC68449942015-10-16 16:03:12 -0700223 main.step( "Setup Mininet Topology" )
224 topology = main.Mininet1.home + '/custom/' + main.topology
GlennRC073e8bc2015-10-27 17:11:28 -0700225 stepResult = main.Mininet1.startNet( topoFile=topology )
GlennRC68449942015-10-16 16:03:12 -0700226
227 utilities.assert_equals( expect=main.TRUE,
GlennRC073e8bc2015-10-27 17:11:28 -0700228 actual=stepResult,
GlennRC68449942015-10-16 16:03:12 -0700229 onpass="Successfully loaded topology",
230 onfail="Failed to load topology" )
231
GlennRC073e8bc2015-10-27 17:11:28 -0700232 main.step( "Assign switch to controller" )
233 stepResult = main.Mininet1.assignSwController( "s1", main.ONOSip[0] )
GlennRC68449942015-10-16 16:03:12 -0700234
235 utilities.assert_equals( expect=main.TRUE,
GlennRC073e8bc2015-10-27 17:11:28 -0700236 actual=stepResult,
237 onpass="Successfully assigned switch to controller",
238 onfail="Failed to assign switch to controller" )
GlennRC68449942015-10-16 16:03:12 -0700239
GlennRC073e8bc2015-10-27 17:11:28 -0700240 time.sleep( main.startMNSleep )
GlennRC68449942015-10-16 16:03:12 -0700241
Jon Hall70b2ff42015-11-17 15:49:44 -0800242 main.step( "Comparing MN topology to ONOS topology" )
GlennRC073e8bc2015-10-27 17:11:28 -0700243 main.log.info( "Gathering topology information" )
GlennRC1704d072015-10-07 18:40:45 -0700244 devicesResults = main.TRUE
245 linksResults = main.TRUE
246 hostsResults = main.TRUE
247 devices = main.topo.getAllDevices( main )
248 hosts = main.topo.getAllHosts( main )
249 ports = main.topo.getAllPorts( main )
250 links = main.topo.getAllLinks( main )
251 clusters = main.topo.getAllClusters( main )
252
253 mnSwitches = main.Mininet1.getSwitches()
254 mnLinks = main.Mininet1.getLinks()
255 mnHosts = main.Mininet1.getHosts()
256
GlennRC1704d072015-10-07 18:40:45 -0700257 for controller in range( main.numCtrls ):
258 controllerStr = str( controller + 1 )
259 if devices[ controller ] and ports[ controller ] and\
260 "Error" not in devices[ controller ] and\
261 "Error" not in ports[ controller ]:
262
263 currentDevicesResult = main.Mininet1.compareSwitches(
264 mnSwitches,
265 json.loads( devices[ controller ] ),
266 json.loads( ports[ controller ] ) )
267 else:
268 currentDevicesResult = main.FALSE
269 utilities.assert_equals( expect=main.TRUE,
270 actual=currentDevicesResult,
271 onpass="ONOS" + controllerStr +
GlennRC68449942015-10-16 16:03:12 -0700272 " Switches view is correct",
GlennRC1704d072015-10-07 18:40:45 -0700273 onfail="ONOS" + controllerStr +
GlennRC68449942015-10-16 16:03:12 -0700274 " Switches view is incorrect" )
GlennRC1704d072015-10-07 18:40:45 -0700275 if links[ controller ] and "Error" not in links[ controller ]:
276 currentLinksResult = main.Mininet1.compareLinks(
277 mnSwitches, mnLinks,
278 json.loads( links[ controller ] ) )
279 else:
280 currentLinksResult = main.FALSE
281 utilities.assert_equals( expect=main.TRUE,
282 actual=currentLinksResult,
283 onpass="ONOS" + controllerStr +
GlennRC68449942015-10-16 16:03:12 -0700284 " links view is correct",
GlennRC1704d072015-10-07 18:40:45 -0700285 onfail="ONOS" + controllerStr +
GlennRC68449942015-10-16 16:03:12 -0700286 " links view is incorrect" )
GlennRC1704d072015-10-07 18:40:45 -0700287
288 if hosts[ controller ] or "Error" not in hosts[ controller ]:
289 currentHostsResult = main.Mininet1.compareHosts(
290 mnHosts,
291 json.loads( hosts[ controller ] ) )
292 else:
293 currentHostsResult = main.FALSE
294 utilities.assert_equals( expect=main.TRUE,
295 actual=currentHostsResult,
296 onpass="ONOS" + controllerStr +
GlennRC68449942015-10-16 16:03:12 -0700297 " hosts exist in Mininet",
GlennRC1704d072015-10-07 18:40:45 -0700298 onfail="ONOS" + controllerStr +
GlennRC68449942015-10-16 16:03:12 -0700299 " hosts don't match Mininet")
GlennRCa5391372015-10-14 17:28:15 -0700300
GlennRC68449942015-10-16 16:03:12 -0700301
Jon Hall892818c2015-10-20 17:58:34 -0700302 def CASE66( self, main ):
303 '''
304 Testing scapy
305 '''
306 main.case( "Testing scapy" )
307 main.step( "Creating Host1 component" )
Jon Halla510a8a2016-05-04 15:09:28 -0700308 main.Scapy.createHostComponent( "h1" )
309 main.Scapy.createHostComponent( "h2" )
Jon Hall892818c2015-10-20 17:58:34 -0700310 hosts = [main.h1, main.h2]
311 for host in hosts:
312 host.startHostCli()
313 host.startScapy()
314 host.updateSelf()
315 main.log.debug( host.name )
316 main.log.debug( host.hostIp )
317 main.log.debug( host.hostMac )
318
319 main.step( "Sending/Receiving Test packet - Filter doesn't match" )
Jon Halla510a8a2016-05-04 15:09:28 -0700320 main.log.info( "Starting Filter..." )
Jon Hall892818c2015-10-20 17:58:34 -0700321 main.h2.startFilter()
Jon Halla510a8a2016-05-04 15:09:28 -0700322 main.log.info( "Building Ether frame..." )
Jon Hall892818c2015-10-20 17:58:34 -0700323 main.h1.buildEther( dst=main.h2.hostMac )
Jon Halla510a8a2016-05-04 15:09:28 -0700324 main.log.info( "Sending Packet..." )
Jon Hall892818c2015-10-20 17:58:34 -0700325 main.h1.sendPacket( )
Jon Halla510a8a2016-05-04 15:09:28 -0700326 main.log.info( "Checking Filter..." )
Jon Hall892818c2015-10-20 17:58:34 -0700327 finished = main.h2.checkFilter()
Jon Halla510a8a2016-05-04 15:09:28 -0700328 main.log.debug( finished )
Jon Hall892818c2015-10-20 17:58:34 -0700329 i = ""
330 if finished:
331 a = main.h2.readPackets()
332 for i in a.splitlines():
333 main.log.info( i )
334 else:
335 kill = main.h2.killFilter()
336 main.log.debug( kill )
337 main.h2.handle.sendline( "" )
338 main.h2.handle.expect( main.h2.scapyPrompt )
339 main.log.debug( main.h2.handle.before )
340 utilities.assert_equals( expect=True,
341 actual="dst=00:00:00:00:00:02 src=00:00:00:00:00:01" in i,
342 onpass="Pass",
343 onfail="Fail" )
344
345 main.step( "Sending/Receiving Test packet - Filter matches" )
346 main.h2.startFilter()
347 main.h1.buildEther( dst=main.h2.hostMac )
348 main.h1.buildIP( dst=main.h2.hostIp )
349 main.h1.sendPacket( )
350 finished = main.h2.checkFilter()
351 i = ""
352 if finished:
353 a = main.h2.readPackets()
354 for i in a.splitlines():
355 main.log.info( i )
356 else:
357 kill = main.h2.killFilter()
358 main.log.debug( kill )
359 main.h2.handle.sendline( "" )
360 main.h2.handle.expect( main.h2.scapyPrompt )
361 main.log.debug( main.h2.handle.before )
362 utilities.assert_equals( expect=True,
363 actual="dst=00:00:00:00:00:02 src=00:00:00:00:00:01" in i,
364 onpass="Pass",
365 onfail="Fail" )
366
367
368
369 main.step( "Clean up host components" )
370 for host in hosts:
371 host.stopScapy()
372 main.Mininet1.removeHostComponent("h1")
373 main.Mininet1.removeHostComponent("h2")
374
GlennRC68449942015-10-16 16:03:12 -0700375 def CASE1000( self, main ):
376 '''
GlennRC073e8bc2015-10-27 17:11:28 -0700377 Add flows with MAC selectors and verify the flows
GlennRC68449942015-10-16 16:03:12 -0700378 '''
GlennRC073e8bc2015-10-27 17:11:28 -0700379 import json
380 import time
GlennRC68449942015-10-16 16:03:12 -0700381
GlennRC073e8bc2015-10-27 17:11:28 -0700382 main.case( "Verify flow MAC selectors are correctly compiled" )
383 main.caseExplanation = "Install two flows with only MAC selectors " +\
384 "specified, then verify flows are added in ONOS, finally "+\
385 "send a packet that only specifies the MAC src and dst."
GlennRC68449942015-10-16 16:03:12 -0700386
GlennRC073e8bc2015-10-27 17:11:28 -0700387 main.step( "Add flows with MAC addresses as the only selectors" )
GlennRC68449942015-10-16 16:03:12 -0700388
GlennRC073e8bc2015-10-27 17:11:28 -0700389 main.log.info( "Creating host components" )
Jon Halla510a8a2016-05-04 15:09:28 -0700390 main.Scapy.createHostComponent( "h1" )
391 main.Scapy.createHostComponent( "h2" )
GlennRC073e8bc2015-10-27 17:11:28 -0700392 hosts = [main.h1, main.h2]
393 stepResult = main.TRUE
394 for host in hosts:
395 host.startHostCli()
396 host.startScapy()
397 host.updateSelf()
GlennRC68449942015-10-16 16:03:12 -0700398
GlennRC073e8bc2015-10-27 17:11:28 -0700399 # Add a flow that connects host1 on port1 to host2 on port2
400 # send output on port2
401 # recieve input on port1
402 egress = 2
403 ingress = 1
404
405 # Add flows that sends packets from port1 to port2 with correct
406 # MAC src and dst addresses
407 main.log.info( "Adding flow with MAC selectors" )
408 stepResult = main.ONOSrest.addFlow( deviceId=main.swDPID,
409 egressPort=egress,
410 ingressPort=ingress,
411 ethSrc=main.h1.hostMac,
412 ethDst=main.h2.hostMac,
GlennRC956ea742015-11-05 16:14:15 -0800413 debug=main.debug )
GlennRC68449942015-10-16 16:03:12 -0700414
GlennRCa5391372015-10-14 17:28:15 -0700415 utilities.assert_equals( expect=main.TRUE,
416 actual=stepResult,
GlennRC68449942015-10-16 16:03:12 -0700417 onpass="Successfully added flows",
418 onfail="Failed add flows" )
GlennRCa5391372015-10-14 17:28:15 -0700419
GlennRC073e8bc2015-10-27 17:11:28 -0700420 # Giving ONOS time to add the flows
421 time.sleep( main.addFlowSleep )
GlennRC5147a422015-10-06 17:26:17 -0700422
GlennRC073e8bc2015-10-27 17:11:28 -0700423 main.step( "Check flows are in the ADDED state" )
424
GlennRC073e8bc2015-10-27 17:11:28 -0700425 main.log.info( "Get the flows from ONOS" )
Jeremy86160992016-04-11 10:05:53 -0700426 try:
427 flows = json.loads( main.ONOSrest.flows() )
GlennRC68449942015-10-16 16:03:12 -0700428
Jeremy86160992016-04-11 10:05:53 -0700429 stepResult = main.TRUE
430 for f in flows:
431 if "rest" in f.get("appId"):
432 if "ADDED" not in f.get("state"):
433 stepResult = main.FALSE
434 main.log.error( "Flow: %s in state: %s" % (f.get("id"), f.get("state")) )
435 except TypeError:
436 main.log.error( "No Flows found by the REST API" )
437 stepResult = main.FALSE
438 except ValueError:
439 main.log.error( "Problem getting Flows state from REST API. Exiting test" )
440 main.cleanup()
441 main.exit()
GlennRC68449942015-10-16 16:03:12 -0700442
443 utilities.assert_equals( expect=main.TRUE,
444 actual=stepResult,
445 onpass="All flows are in the ADDED state",
GlennRC073e8bc2015-10-27 17:11:28 -0700446 onfail="All flows are NOT in the ADDED state" )
GlennRC68449942015-10-16 16:03:12 -0700447
GlennRC956ea742015-11-05 16:14:15 -0800448 main.step( "Check flows are in Mininet's flow table" )
449
450 # get the flow IDs that were added through rest
451 main.log.info( "Getting the flow IDs from ONOS" )
452 flowIds = [ f.get("id") for f in flows if "rest" in f.get("appId") ]
453 # convert the flowIDs to ints then hex and finally back to strings
454 flowIds = [str(hex(int(x))) for x in flowIds]
455 main.log.info( "ONOS flow IDs: {}".format(flowIds) )
456
457 stepResult = main.Mininet1.checkFlowId( "s1", flowIds, debug=False )
458
459 utilities.assert_equals( expect=main.TRUE,
460 actual=stepResult,
461 onpass="All flows are in mininet",
462 onfail="All flows are NOT in mininet" )
463
GlennRC073e8bc2015-10-27 17:11:28 -0700464 main.step( "Send a packet to verify the flows are correct" )
465
466 # Specify the src and dst MAC addr
467 main.log.info( "Constructing packet" )
468 main.h1.buildEther( src=main.h1.hostMac, dst=main.h2.hostMac )
469
470 # Filter for packets with the correct host name. Otherwise,
471 # the filter we catch any packet that is sent to host2
472 # NOTE: I believe it doesn't matter which host name it is,
GlennRC956ea742015-11-05 16:14:15 -0800473 # as long as the src and dst are both specified
GlennRC073e8bc2015-10-27 17:11:28 -0700474 main.log.info( "Starting filter on host2" )
475 main.h2.startFilter( pktFilter="ether host %s" % main.h1.hostMac)
476
477 main.log.info( "Sending packet to host2" )
478 main.h1.sendPacket()
479
480 main.log.info( "Checking filter for our packet" )
481 stepResult = main.h2.checkFilter()
482 if stepResult:
483 main.log.info( "Packet: %s" % main.h2.readPackets() )
484 else: main.h2.killFilter()
485
486 main.log.info( "Clean up host components" )
487 for host in hosts:
488 host.stopScapy()
489 main.Mininet1.removeHostComponent("h1")
490 main.Mininet1.removeHostComponent("h2")
491
492 utilities.assert_equals( expect=main.TRUE,
493 actual=stepResult,
494 onpass="Successfully sent a packet",
495 onfail="Failed to send a packet" )
496
497 def CASE1100( self, main ):
GlennRC68449942015-10-16 16:03:12 -0700498 '''
GlennRC073e8bc2015-10-27 17:11:28 -0700499 Add flows with IPv4 selectors and verify the flows
GlennRC68449942015-10-16 16:03:12 -0700500 '''
501 import json
GlennRC073e8bc2015-10-27 17:11:28 -0700502 import time
GlennRC68449942015-10-16 16:03:12 -0700503
GlennRC073e8bc2015-10-27 17:11:28 -0700504 main.case( "Verify flow IP selectors are correctly compiled" )
505 main.caseExplanation = "Install two flows with only IP selectors " +\
506 "specified, then verify flows are added in ONOS, finally "+\
507 "send a packet that only specifies the IP src and dst."
508
509 main.step( "Add flows with IPv4 addresses as the only selectors" )
510
511 main.log.info( "Creating host components" )
Jon Halla510a8a2016-05-04 15:09:28 -0700512 main.Scapy.createHostComponent( "h1" )
513 main.Scapy.createHostComponent( "h2" )
GlennRC073e8bc2015-10-27 17:11:28 -0700514 hosts = [main.h1, main.h2]
515 stepResult = main.TRUE
516 for host in hosts:
517 host.startHostCli()
518 host.startScapy()
519 host.updateSelf()
520
521 # Add a flow that connects host1 on port1 to host2 on port2
522 # send output on port2
523 # recieve input on port1
524 egress = 2
525 ingress = 1
526 # IPv4 etherType = 0x800
527 IPv4=2048
528
529 # Add flows that connects host1 to host2
530 main.log.info( "Add flow with port ingress 1 to port egress 2" )
531 stepResult = main.ONOSrest.addFlow( deviceId=main.swDPID,
532 egressPort=egress,
533 ingressPort=ingress,
534 ethType=IPv4,
535 ipSrc=("IPV4_SRC", main.h1.hostIp+"/32"),
536 ipDst=("IPV4_DST", main.h2.hostIp+"/32"),
GlennRC956ea742015-11-05 16:14:15 -0800537 debug=main.debug )
GlennRC073e8bc2015-10-27 17:11:28 -0700538
539 utilities.assert_equals( expect=main.TRUE,
540 actual=stepResult,
541 onpass="Successfully added flows",
542 onfail="Failed add flows" )
543
544 # Giving ONOS time to add the flow
545 time.sleep( main.addFlowSleep )
546
547 main.step( "Check flow is in the ADDED state" )
548
549 main.log.info( "Get the flows from ONOS" )
Jeremy86160992016-04-11 10:05:53 -0700550 try:
551 flows = json.loads( main.ONOSrest.flows() )
GlennRC68449942015-10-16 16:03:12 -0700552
Jeremy86160992016-04-11 10:05:53 -0700553 stepResult = main.TRUE
554 for f in flows:
555 if "rest" in f.get("appId"):
556 if "ADDED" not in f.get("state"):
557 stepResult = main.FALSE
558 main.log.error( "Flow: %s in state: %s" % (f.get("id"), f.get("state")) )
559 except TypeError:
560 main.log.error( "No Flows found by the REST API" )
561 stepResult = main.FALSE
562 except ValueError:
563 main.log.error( "Problem getting Flows state from REST API. Exiting test" )
564 main.cleanup()
565 main.exit()
GlennRC68449942015-10-16 16:03:12 -0700566
567 utilities.assert_equals( expect=main.TRUE,
568 actual=stepResult,
GlennRC073e8bc2015-10-27 17:11:28 -0700569 onpass="All flows are in the ADDED state",
570 onfail="All flows are NOT in the ADDED state" )
571
GlennRC956ea742015-11-05 16:14:15 -0800572 main.step( "Check flows are in Mininet's flow table" )
573
574 # get the flow IDs that were added through rest
575 main.log.info( "Getting the flow IDs from ONOS" )
576 flowIds = [ f.get("id") for f in flows if "rest" in f.get("appId") ]
577 # convert the flowIDs to ints then hex and finally back to strings
578 flowIds = [str(hex(int(x))) for x in flowIds]
579 main.log.info( "ONOS flow IDs: {}".format(flowIds) )
580
581 stepResult = main.Mininet1.checkFlowId( "s1", flowIds, debug=False )
582
583 utilities.assert_equals( expect=main.TRUE,
584 actual=stepResult,
585 onpass="All flows are in mininet",
586 onfail="All flows are NOT in mininet" )
587
GlennRC073e8bc2015-10-27 17:11:28 -0700588 main.step( "Send a packet to verify the flow is correct" )
589
590 main.log.info( "Constructing packet" )
591 # No need for the MAC src dst
592 main.h1.buildEther( dst=main.h2.hostMac )
593 main.h1.buildIP( src=main.h1.hostIp, dst=main.h2.hostIp )
594
595 main.log.info( "Starting filter on host2" )
596 # Defaults to ip
597 main.h2.startFilter()
598
599 main.log.info( "Sending packet to host2" )
600 main.h1.sendPacket()
601
602 main.log.info( "Checking filter for our packet" )
603 stepResult = main.h2.checkFilter()
604 if stepResult:
605 main.log.info( "Packet: %s" % main.h2.readPackets() )
606 else: main.h2.killFilter()
607
608 main.log.info( "Clean up host components" )
609 for host in hosts:
610 host.stopScapy()
611 main.Mininet1.removeHostComponent("h1")
612 main.Mininet1.removeHostComponent("h2")
613
614 utilities.assert_equals( expect=main.TRUE,
615 actual=stepResult,
616 onpass="Successfully sent a packet",
617 onfail="Failed to send a packet" )
618
619 def CASE1200( self, main ):
620 '''
621 Add flow with VLAN selector and verify the flow
622 '''
623 import json
624 import time
625
626 main.case( "Verify VLAN selector is correctly compiled" )
627 main.caseExplanation = "Install one flow with only the VLAN selector " +\
628 "specified, then verify the flow is added in ONOS, and finally "+\
629 "broadcast a packet with the correct VLAN tag."
630
631 # We do this here to utilize the hosts information
632 main.log.info( "Creating host components" )
Jon Halla510a8a2016-05-04 15:09:28 -0700633 main.Scapy.createHostComponent( "h3" )
634 main.Scapy.createHostComponent( "h4" )
GlennRC073e8bc2015-10-27 17:11:28 -0700635 hosts = [main.h3, main.h4]
636 stepResult = main.TRUE
637 for host in hosts:
638 host.startHostCli()
639 host.startScapy()
640 host.updateSelf()
641
642
643 main.step( "Add a flow with the VLAN tag as the only selector" )
644
645 # Add flows that connects the two vlan hosts h3 and h4
646 # Host 3 is on port 3 and host 4 is on port 4
647 vlan = main.params[ 'TEST' ][ 'vlan' ]
648 egress = 4
649 ingress = 3
650 # VLAN ethType = 0x8100
651 ethType = 33024
652
653 # Add only one flow because we don't need a response
654 main.log.info( "Add flow with port ingress 1 to port egress 2" )
655 stepResult = main.ONOSrest.addFlow( deviceId=main.swDPID,
656 egressPort=egress,
657 ingressPort=ingress,
658 ethType=ethType,
659 vlan=vlan,
GlennRC956ea742015-11-05 16:14:15 -0800660 debug=main.debug )
GlennRC073e8bc2015-10-27 17:11:28 -0700661
662
663 utilities.assert_equals( expect=main.TRUE,
664 actual=stepResult,
665 onpass="Successfully added flow",
666 onfail="Failed add flows" )
667
668 # Giving ONOS time to add the flows
669 time.sleep( main.addFlowSleep )
670
671 main.step( "Check flows are in the ADDED state" )
672
673 main.log.info( "Get the flows from ONOS" )
Jeremy86160992016-04-11 10:05:53 -0700674 try:
675 flows = json.loads( main.ONOSrest.flows() )
GlennRC073e8bc2015-10-27 17:11:28 -0700676
Jeremy86160992016-04-11 10:05:53 -0700677 stepResult = main.TRUE
678 for f in flows:
679 if "rest" in f.get("appId"):
680 if "ADDED" not in f.get("state"):
681 stepResult = main.FALSE
682 main.log.error( "Flow: %s in state: %s" % (f.get("id"), f.get("state")) )
683 except TypeError:
684 main.log.error( "No Flows found by the REST API" )
685 stepResult = main.FALSE
686 except ValueError:
687 main.log.error( "Problem getting Flows state from REST API. Exiting test" )
688 main.cleanup()
689 main.exit()
GlennRC073e8bc2015-10-27 17:11:28 -0700690
691 utilities.assert_equals( expect=main.TRUE,
692 actual=stepResult,
693 onpass="All flows are in the ADDED state",
694 onfail="All flows are NOT in the ADDED state" )
695
GlennRC956ea742015-11-05 16:14:15 -0800696 main.step( "Check flows are in Mininet's flow table" )
697
698 # get the flow IDs that were added through rest
699 main.log.info( "Getting the flow IDs from ONOS" )
700 flowIds = [ f.get("id") for f in flows if "rest" in f.get("appId") ]
701 # convert the flowIDs to ints then hex and finally back to strings
702 flowIds = [str(hex(int(x))) for x in flowIds]
703 main.log.info( "ONOS flow IDs: {}".format(flowIds) )
704
705 stepResult = main.Mininet1.checkFlowId( "s1", flowIds, debug=False )
706
707 utilities.assert_equals( expect=main.TRUE,
708 actual=stepResult,
709 onpass="All flows are in mininet",
710 onfail="All flows are NOT in mininet" )
711
GlennRC073e8bc2015-10-27 17:11:28 -0700712 main.step( "Send a packet to verify the flow are correct" )
713
714 # The receiving interface
715 recIface = "{}-eth0.{}".format(main.h4.name, vlan)
716 main.log.info( "Starting filter on host2" )
717 # Filter is setup to catch any packet on the vlan interface with the correct vlan tag
718 main.h4.startFilter( ifaceName=recIface, pktFilter="" )
719
720 # Broadcast the packet on the vlan interface. We only care if the flow forwards
721 # the packet with the correct vlan tag, not if the mac addr is correct
GlennRC073e8bc2015-10-27 17:11:28 -0700722 sendIface = "{}-eth0.{}".format(main.h3.name, vlan)
723 main.log.info( "Broadcasting the packet with a vlan tag" )
GlennRC956ea742015-11-05 16:14:15 -0800724 main.h3.sendPacket( iface=sendIface,
725 packet="Ether()/Dot1Q(vlan={})".format(vlan) )
GlennRC073e8bc2015-10-27 17:11:28 -0700726
727 main.log.info( "Checking filter for our packet" )
728 stepResult = main.h4.checkFilter()
729 if stepResult:
730 main.log.info( "Packet: %s" % main.h4.readPackets() )
731 else: main.h4.killFilter()
732
733 main.log.info( "Clean up host components" )
734 for host in hosts:
735 host.stopScapy()
736 main.Mininet1.removeHostComponent("h3")
737 main.Mininet1.removeHostComponent("h4")
738
739 utilities.assert_equals( expect=main.TRUE,
740 actual=stepResult,
741 onpass="Successfully sent a packet",
742 onfail="Failed to send a packet" )
GlennRC68449942015-10-16 16:03:12 -0700743
GlennRC956ea742015-11-05 16:14:15 -0800744 def CASE1300( self, main ):
745 '''
746 Add flows with MPLS selector and verify the flows
747 '''
748 import json
749 import time
750
751 main.case( "Verify the MPLS selector is correctly compiled on the flow." )
752 main.caseExplanation = "Install one flow with an MPLS selector, " +\
753 "verify the flow is added in ONOS, and finally "+\
754 "send a packet via scapy that has a MPLS label."
755
756 main.step( "Add a flow with a MPLS selector" )
757
758 main.log.info( "Creating host components" )
Jon Halla510a8a2016-05-04 15:09:28 -0700759 main.Scapy.createHostComponent( "h1" )
760 main.Scapy.createHostComponent( "h2" )
GlennRC956ea742015-11-05 16:14:15 -0800761 hosts = [main.h1, main.h2]
762 stepResult = main.TRUE
763 for host in hosts:
764 host.startHostCli()
765 host.startScapy( main.dependencyPath )
766 host.updateSelf()
767
768 # ports
769 egress = 2
770 ingress = 1
771 # MPLS etherType
772 ethType = main.params[ 'TEST' ][ 'mplsType' ]
773 # MPLS label
774 mplsLabel = main.params[ 'TEST' ][ 'mpls' ]
775
776 # Add a flow that connects host1 on port1 to host2 on port2
777 main.log.info( "Adding flow with MPLS selector" )
778 stepResult = main.ONOSrest.addFlow( deviceId=main.swDPID,
779 egressPort=egress,
780 ingressPort=ingress,
781 ethType=ethType,
782 mpls=mplsLabel,
783 debug=main.debug )
784
785 utilities.assert_equals( expect=main.TRUE,
786 actual=stepResult,
787 onpass="Successfully added flow",
788 onfail="Failed add flow" )
789
790 # Giving ONOS time to add the flow
791 time.sleep( main.addFlowSleep )
792
793 main.step( "Check flow is in the ADDED state" )
794
795 main.log.info( "Get the flows from ONOS" )
Jeremy86160992016-04-11 10:05:53 -0700796 try:
797 flows = json.loads( main.ONOSrest.flows() )
GlennRC956ea742015-11-05 16:14:15 -0800798
Jeremy86160992016-04-11 10:05:53 -0700799 stepResult = main.TRUE
800 for f in flows:
801 if "rest" in f.get("appId"):
802 if "ADDED" not in f.get("state"):
803 stepResult = main.FALSE
804 main.log.error( "Flow: %s in state: %s" % (f.get("id"), f.get("state")) )
805 except TypeError:
806 main.log.error( "No Flows found by the REST API" )
807 stepResult = main.FALSE
808 except ValueError:
809 main.log.error( "Problem getting Flows state from REST API. Exiting test" )
810 main.cleanup()
811 main.exit()
GlennRC956ea742015-11-05 16:14:15 -0800812
813 utilities.assert_equals( expect=main.TRUE,
814 actual=stepResult,
815 onpass="All flows are in the ADDED state",
816 onfail="All flows are NOT in the ADDED state" )
817
818 main.step( "Check flows are in Mininet's flow table" )
819
820 # get the flow IDs that were added through rest
821 main.log.info( "Getting the flow IDs from ONOS" )
822 flowIds = [ f.get("id") for f in flows if "rest" in f.get("appId") ]
823 # convert the flowIDs to ints then hex and finally back to strings
824 flowIds = [str(hex(int(x))) for x in flowIds]
825 main.log.info( "ONOS flow IDs: {}".format(flowIds) )
826
827 stepResult = main.Mininet1.checkFlowId( "s1", flowIds, debug=True )
828
829 utilities.assert_equals( expect=main.TRUE,
830 actual=stepResult,
831 onpass="All flows are in mininet",
832 onfail="All flows are NOT in mininet" )
833
834 main.step( "Send a packet to verify the flow is correct" )
835
836 main.log.info( "Starting filter on host2" )
837 main.h2.startFilter( pktFilter="mpls" )
838
839 main.log.info( "Constructing packet" )
840 main.log.info( "Sending packet to host2" )
841 main.h1.sendPacket( packet='Ether()/MPLS(label={})'.format(mplsLabel) )
842
843 main.log.info( "Checking filter for our packet" )
844 stepResult = main.h2.checkFilter()
845 if stepResult:
846 main.log.info( "Packet: %s" % main.h2.readPackets() )
847 else: main.h2.killFilter()
848
849 main.log.info( "Clean up host components" )
850 for host in hosts:
851 host.stopScapy()
852 main.Mininet1.removeHostComponent("h1")
853 main.Mininet1.removeHostComponent("h2")
854
855 utilities.assert_equals( expect=main.TRUE,
856 actual=stepResult,
857 onpass="Successfully sent a packet",
858 onfail="Failed to send a packet" )
859
860 def CASE1400( self, main ):
861 '''
862 Add flows with a TCP selector and verify the flow
863 '''
864 import json
865 import time
866
867 main.case( "Verify the TCP selector is correctly compiled on the flow" )
868 main.caseExplanation = "Install a flow with only the TCP selector " +\
869 "specified, verify the flow is added in ONOS, and finally "+\
870 "send a TCP packet to verify the TCP selector is compiled correctly."
871
872 main.step( "Add a flow with a TCP selector" )
873
874 main.log.info( "Creating host components" )
Jon Halla510a8a2016-05-04 15:09:28 -0700875 main.Scapy.createHostComponent( "h1" )
876 main.Scapy.createHostComponent( "h2" )
GlennRC956ea742015-11-05 16:14:15 -0800877 hosts = [main.h1, main.h2]
878 stepResult = main.TRUE
879 for host in hosts:
880 host.startHostCli()
881 host.startScapy()
882 host.updateSelf()
883
884 # Add a flow that connects host1 on port1 to host2 on port2
885 egress = 2
886 ingress = 1
887 # IPv4 etherType
888 ethType = main.params[ 'TEST' ][ 'ip4Type' ]
889 # IP protocol
890 ipProto = main.params[ 'TEST' ][ 'tcpProto' ]
891 # TCP port destination
892 tcpDst = main.params[ 'TEST' ][ 'tcpDst' ]
893
894 main.log.info( "Add a flow that connects host1 on port1 to host2 on port2" )
895 stepResult = main.ONOSrest.addFlow( deviceId=main.swDPID,
896 egressPort=egress,
897 ingressPort=ingress,
898 ethType=ethType,
899 ipProto=ipProto,
900 tcpDst=tcpDst,
901 debug=main.debug )
902
903 utilities.assert_equals( expect=main.TRUE,
904 actual=stepResult,
905 onpass="Successfully added flows",
906 onfail="Failed add flows" )
907
908 # Giving ONOS time to add the flow
909 time.sleep( main.addFlowSleep )
910
911 main.step( "Check flow is in the ADDED state" )
912
913 main.log.info( "Get the flows from ONOS" )
Jeremy86160992016-04-11 10:05:53 -0700914 try:
915 flows = json.loads( main.ONOSrest.flows() )
GlennRC956ea742015-11-05 16:14:15 -0800916
Jeremy86160992016-04-11 10:05:53 -0700917 stepResult = main.TRUE
918 for f in flows:
919 if "rest" in f.get("appId"):
920 if "ADDED" not in f.get("state"):
921 stepResult = main.FALSE
922 main.log.error( "Flow: %s in state: %s" % (f.get("id"), f.get("state")) )
923 except TypeError:
924 main.log.error( "No Flows found by the REST API" )
925 stepResult = main.FALSE
926 except ValueError:
927 main.log.error( "Problem getting Flows state from REST API. Exiting test" )
928 main.cleanup()
929 main.exit()
GlennRC956ea742015-11-05 16:14:15 -0800930
931 utilities.assert_equals( expect=main.TRUE,
932 actual=stepResult,
933 onpass="All flows are in the ADDED state",
934 onfail="All flows are NOT in the ADDED state" )
935
936 main.step( "Check flows are in Mininet's flow table" )
937
938 # get the flow IDs that were added through rest
939 main.log.info( "Getting the flow IDs from ONOS" )
940 flowIds = [ f.get("id") for f in flows if "rest" in f.get("appId") ]
941 # convert the flowIDs to ints then hex and finally back to strings
942 flowIds = [str(hex(int(x))) for x in flowIds]
943 main.log.info( "ONOS flow IDs: {}".format(flowIds) )
944
945 stepResult = main.Mininet1.checkFlowId( "s1", flowIds, debug=False )
946
947 utilities.assert_equals( expect=main.TRUE,
948 actual=stepResult,
949 onpass="All flows are in mininet",
950 onfail="All flows are NOT in mininet" )
951
952 main.step( "Send a packet to verify the flow is correct" )
953
954 main.log.info( "Constructing packet" )
955 # No need for the MAC src dst
956 main.h1.buildEther( dst=main.h2.hostMac )
957 main.h1.buildIP( dst=main.h2.hostIp )
958 main.h1.buildTCP( dport=tcpDst )
959
960 main.log.info( "Starting filter on host2" )
961 # Defaults to ip
962 main.h2.startFilter( pktFilter="tcp" )
963
964 main.log.info( "Sending packet to host2" )
965 main.h1.sendPacket()
966
967 main.log.info( "Checking filter for our packet" )
968 stepResult = main.h2.checkFilter()
969 if stepResult:
970 main.log.info( "Packet: %s" % main.h2.readPackets() )
971 else: main.h2.killFilter()
972
973 main.log.info( "Clean up host components" )
974 for host in hosts:
975 host.stopScapy()
976 main.Mininet1.removeHostComponent("h1")
977 main.Mininet1.removeHostComponent("h2")
978
979 utilities.assert_equals( expect=main.TRUE,
980 actual=stepResult,
981 onpass="Successfully sent a packet",
982 onfail="Failed to send a packet" )
983
984 def CASE1500( self, main ):
985 '''
986 Add flows with a UDP selector and verify the flow
987 '''
988 import json
989 import time
990
991 main.case( "Verify the UDP selector is correctly compiled on the flow" )
992 main.caseExplanation = "Install a flow with only the UDP selector " +\
993 "specified, verify the flow is added in ONOS, and finally "+\
994 "send a UDP packet to verify the UDP selector is compiled correctly."
995
996 main.step( "Add a flow with a UDP selector" )
997
998 main.log.info( "Creating host components" )
Jon Halla510a8a2016-05-04 15:09:28 -0700999 main.Scapy.createHostComponent( "h1" )
1000 main.Scapy.createHostComponent( "h2" )
GlennRC956ea742015-11-05 16:14:15 -08001001 hosts = [main.h1, main.h2]
1002 stepResult = main.TRUE
1003 for host in hosts:
1004 host.startHostCli()
1005 host.startScapy()
1006 host.updateSelf()
1007
1008 # Add a flow that connects host1 on port1 to host2 on port2
1009 egress = 2
1010 ingress = 1
1011 # IPv4 etherType
1012 ethType = main.params[ 'TEST' ][ 'ip4Type' ]
1013 # IP protocol
1014 ipProto = main.params[ 'TEST' ][ 'udpProto' ]
1015 # UDP port destination
1016 udpDst = main.params[ 'TEST' ][ 'udpDst' ]
1017
1018 main.log.info( "Add a flow that connects host1 on port1 to host2 on port2" )
1019 stepResult = main.ONOSrest.addFlow( deviceId=main.swDPID,
1020 egressPort=egress,
1021 ingressPort=ingress,
1022 ethType=ethType,
1023 ipProto=ipProto,
1024 udpDst=udpDst,
1025 debug=main.debug )
1026
1027 utilities.assert_equals( expect=main.TRUE,
1028 actual=stepResult,
1029 onpass="Successfully added flows",
1030 onfail="Failed add flows" )
1031
1032 # Giving ONOS time to add the flow
1033 time.sleep( main.addFlowSleep )
1034
1035 main.step( "Check flow is in the ADDED state" )
1036
1037 main.log.info( "Get the flows from ONOS" )
Jeremy86160992016-04-11 10:05:53 -07001038 try:
1039 flows = json.loads( main.ONOSrest.flows() )
GlennRC956ea742015-11-05 16:14:15 -08001040
Jeremy86160992016-04-11 10:05:53 -07001041 stepResult = main.TRUE
1042 for f in flows:
1043 if "rest" in f.get("appId"):
1044 if "ADDED" not in f.get("state"):
1045 stepResult = main.FALSE
1046 main.log.error( "Flow: %s in state: %s" % (f.get("id"), f.get("state")) )
1047 except TypeError:
1048 main.log.error( "No Flows found by the REST API" )
1049 stepResult = main.FALSE
1050 except ValueError:
1051 main.log.error( "Problem getting Flows state from REST API. Exiting test" )
1052 main.cleanup()
1053 main.exit()
GlennRC956ea742015-11-05 16:14:15 -08001054
1055 utilities.assert_equals( expect=main.TRUE,
1056 actual=stepResult,
1057 onpass="All flows are in the ADDED state",
1058 onfail="All flows are NOT in the ADDED state" )
1059
1060 main.step( "Check flows are in Mininet's flow table" )
1061
1062 # get the flow IDs that were added through rest
1063 main.log.info( "Getting the flow IDs from ONOS" )
1064 flowIds = [ f.get("id") for f in flows if "rest" in f.get("appId") ]
1065 # convert the flowIDs to ints then hex and finally back to strings
1066 flowIds = [str(hex(int(x))) for x in flowIds]
1067 main.log.info( "ONOS flow IDs: {}".format(flowIds) )
1068
1069 stepResult = main.Mininet1.checkFlowId( "s1", flowIds, debug=False )
1070
1071 utilities.assert_equals( expect=main.TRUE,
1072 actual=stepResult,
1073 onpass="All flows are in mininet",
1074 onfail="All flows are NOT in mininet" )
1075
1076 main.step( "Send a packet to verify the flow is correct" )
1077
1078 main.log.info( "Constructing packet" )
1079 # No need for the MAC src dst
1080 main.h1.buildEther( dst=main.h2.hostMac )
1081 main.h1.buildIP( dst=main.h2.hostIp )
1082 main.h1.buildUDP( dport=udpDst )
1083
1084 main.log.info( "Starting filter on host2" )
1085 # Defaults to ip
1086 main.h2.startFilter( pktFilter="udp" )
1087
1088 main.log.info( "Sending packet to host2" )
1089 main.h1.sendPacket()
1090
1091 main.log.info( "Checking filter for our packet" )
1092 stepResult = main.h2.checkFilter()
1093 if stepResult:
1094 main.log.info( "Packet: %s" % main.h2.readPackets() )
1095 else: main.h2.killFilter()
1096
1097 main.log.info( "Clean up host components" )
1098 for host in hosts:
1099 host.stopScapy()
1100 main.Mininet1.removeHostComponent("h1")
1101 main.Mininet1.removeHostComponent("h2")
1102
1103 utilities.assert_equals( expect=main.TRUE,
1104 actual=stepResult,
1105 onpass="Successfully sent a packet",
1106 onfail="Failed to send a packet" )
1107
1108
1109 def CASE2000( self, main ):
1110 import json
1111
1112 main.case( "Delete flows that were added through rest" )
1113 main.step("Deleting flows")
1114
1115 main.log.info( "Getting flows" )
Jeremy86160992016-04-11 10:05:53 -07001116 try:
1117 flows = json.loads( main.ONOSrest.flows() )
GlennRC956ea742015-11-05 16:14:15 -08001118
Jeremy86160992016-04-11 10:05:53 -07001119 stepResult = main.TRUE
1120 for f in flows:
1121 if "rest" in f.get("appId"):
1122 if main.debug: main.log.debug( "Flow to be deleted:\n{}".format( main.ONOSrest.pprint(f) ) )
1123 stepResult = stepResult and main.ONOSrest.removeFlow( f.get("deviceId"), f.get("id") )
1124 except TypeError:
1125 main.log.error( "No Flows found by the REST API" )
1126 stepResult = main.FALSE
1127 except ValueError:
1128 main.log.error( "Problem getting Flows state from REST API. Exiting test" )
1129 main.cleanup()
1130 main.exit()
GlennRC956ea742015-11-05 16:14:15 -08001131
1132 utilities.assert_equals( expect=main.TRUE,
1133 actual=stepResult,
1134 onpass="Successfully deleting flows",
1135 onfail="Failed to delete flows" )
1136
1137 time.sleep( main.delFlowSleep )
1138
GlennRC68449942015-10-16 16:03:12 -07001139 def CASE100( self, main ):
GlennRC5147a422015-10-06 17:26:17 -07001140 '''
1141 Report errors/warnings/exceptions
1142 '''
1143 main.log.info("Error report: \n" )
1144 main.ONOSbench.logReport( main.ONOSip[ 0 ],
1145 [ "INFO",
1146 "FOLLOWER",
1147 "WARN",
1148 "flow",
1149 "ERROR",
1150 "Except" ],
GlennRC68449942015-10-16 16:03:12 -07001151 "s" )