blob: 0fa77a21407f4bb7a07a0409c9ee59cffaab1655 [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' ] )
42 main.swDPID = main.params[ 'TEST' ][ 'swDPID' ]
GlennRC5147a422015-10-06 17:26:17 -070043 main.cellData = {} # for creating cell file
44 main.CLIs = []
45 main.ONOSip = []
46
47 main.ONOSip = main.ONOSbench.getOnosIps()
GlennRC5147a422015-10-06 17:26:17 -070048
49 # Assigning ONOS cli handles to a list
50 for i in range( 1, main.maxNodes + 1 ):
51 main.CLIs.append( getattr( main, 'ONOScli' + str( i ) ) )
52
53 # -- INIT SECTION, ONLY RUNS ONCE -- #
54 main.startUp = imp.load_source( wrapperFile1,
55 main.dependencyPath +
56 wrapperFile1 +
57 ".py" )
58
GlennRC1704d072015-10-07 18:40:45 -070059 main.topo = imp.load_source( wrapperFile2,
60 main.dependencyPath +
61 wrapperFile2 +
62 ".py" )
63
GlennRC94ed2232015-10-07 15:08:57 -070064 copyResult = main.ONOSbench.scp( main.Mininet1,
65 main.dependencyPath+main.topology,
66 main.Mininet1.home+'/custom/',
67 direction="to" )
68
GlennRC5147a422015-10-06 17:26:17 -070069 if main.CLIs:
70 stepResult = main.TRUE
71 else:
72 main.log.error( "Did not properly created list of ONOS CLI handle" )
73 stepResult = main.FALSE
74
75 utilities.assert_equals( expect=main.TRUE,
76 actual=stepResult,
77 onpass="Successfully construct " +
78 "test variables ",
79 onfail="Failed to construct test variables" )
80
81 if gitPull == 'True':
82 main.step( "Building ONOS in " + gitBranch + " branch" )
83 onosBuildResult = main.startUp.onosBuild( main, gitBranch )
84 stepResult = onosBuildResult
85 utilities.assert_equals( expect=main.TRUE,
86 actual=stepResult,
87 onpass="Successfully compiled " +
88 "latest ONOS",
89 onfail="Failed to compile " +
90 "latest ONOS" )
91 else:
92 main.log.warn( "Did not pull new code so skipping mvn " +
93 "clean install" )
94
95 def CASE2( self, main ):
96 """
97 - Set up cell
98 - Create cell file
99 - Set cell file
100 - Verify cell file
101 - Kill ONOS process
102 - Uninstall ONOS cluster
103 - Verify ONOS start up
104 - Install ONOS cluster
105 - Connect to cli
106 """
107
108 main.numCtrls = int( main.maxNodes )
109
110 main.case( "Starting up " + str( main.numCtrls ) +
111 " node(s) ONOS cluster" )
112
113 #kill off all onos processes
114 main.log.info( "Safety check, killing all ONOS processes" +
115 " before initiating enviornment setup" )
116
117 for i in range( main.maxNodes ):
118 main.ONOSbench.onosDie( main.ONOSip[ i ] )
119
120 print "NODE COUNT = ", main.numCtrls
121
122 tempOnosIp = []
123 for i in range( main.numCtrls ):
124 tempOnosIp.append( main.ONOSip[i] )
125
126 main.ONOSbench.createCellFile( main.ONOSbench.ip_address, "temp", main.Mininet1.ip_address, main.apps, tempOnosIp )
127
128 main.step( "Apply cell to environment" )
129 cellResult = main.ONOSbench.setCell( "temp" )
130 verifyResult = main.ONOSbench.verifyCell()
131 stepResult = cellResult and verifyResult
132 utilities.assert_equals( expect=main.TRUE,
133 actual=stepResult,
134 onpass="Successfully applied cell to " + \
135 "environment",
136 onfail="Failed to apply cell to environment " )
137
138 main.step( "Creating ONOS package" )
139 packageResult = main.ONOSbench.onosPackage()
140 stepResult = packageResult
141 utilities.assert_equals( expect=main.TRUE,
142 actual=stepResult,
143 onpass="Successfully created ONOS package",
144 onfail="Failed to create ONOS package" )
145
146 time.sleep( main.startUpSleep )
147 main.step( "Uninstalling ONOS package" )
148 onosUninstallResult = main.TRUE
149 for i in range( main.numCtrls ):
150 onosUninstallResult = onosUninstallResult and \
151 main.ONOSbench.onosUninstall( nodeIp=main.ONOSip[ i ] )
152 stepResult = onosUninstallResult
153 utilities.assert_equals( expect=main.TRUE,
154 actual=stepResult,
155 onpass="Successfully uninstalled ONOS package",
156 onfail="Failed to uninstall ONOS package" )
157
158 time.sleep( main.startUpSleep )
159 main.step( "Installing ONOS package" )
160 onosInstallResult = main.TRUE
161 for i in range( main.numCtrls ):
162 onosInstallResult = onosInstallResult and \
163 main.ONOSbench.onosInstall( node=main.ONOSip[ i ] )
164 stepResult = onosInstallResult
165 utilities.assert_equals( expect=main.TRUE,
166 actual=stepResult,
167 onpass="Successfully installed ONOS package",
168 onfail="Failed to install ONOS package" )
169
170 time.sleep( main.startUpSleep )
171 main.step( "Starting ONOS service" )
172 stopResult = main.TRUE
173 startResult = main.TRUE
174 onosIsUp = main.TRUE
175
176 for i in range( main.numCtrls ):
177 onosIsUp = onosIsUp and main.ONOSbench.isup( main.ONOSip[ i ] )
178 if onosIsUp == main.TRUE:
179 main.log.report( "ONOS instance is up and ready" )
180 else:
181 main.log.report( "ONOS instance may not be up, stop and " +
182 "start ONOS again " )
183 for i in range( main.numCtrls ):
184 stopResult = stopResult and \
185 main.ONOSbench.onosStop( main.ONOSip[ i ] )
186 for i in range( main.numCtrls ):
187 startResult = startResult and \
188 main.ONOSbench.onosStart( main.ONOSip[ i ] )
189 stepResult = onosIsUp and stopResult and startResult
190 utilities.assert_equals( expect=main.TRUE,
191 actual=stepResult,
192 onpass="ONOS service is ready",
193 onfail="ONOS service did not start properly" )
194
195 main.step( "Start ONOS cli" )
196 cliResult = main.TRUE
197 for i in range( main.numCtrls ):
198 cliResult = cliResult and \
199 main.CLIs[ i ].startOnosCli( main.ONOSip[ i ] )
200 stepResult = cliResult
201 utilities.assert_equals( expect=main.TRUE,
202 actual=stepResult,
203 onpass="Successfully start ONOS cli",
204 onfail="Failed to start ONOS cli" )
205
GlennRC68449942015-10-16 16:03:12 -0700206 def CASE10( self, main ):
207 '''
208 Start Mininet
209 '''
GlennRC073e8bc2015-10-27 17:11:28 -0700210 import json
211
212 main.case( "Setup mininet and compare ONOS topology view to Mininet topology" )
213 main.caseExplanation = "Start mininet with custom topology and compare topology " +\
214 "elements between Mininet and ONOS"
215
GlennRC68449942015-10-16 16:03:12 -0700216 main.step( "Setup Mininet Topology" )
217 topology = main.Mininet1.home + '/custom/' + main.topology
GlennRC073e8bc2015-10-27 17:11:28 -0700218 stepResult = main.Mininet1.startNet( topoFile=topology )
GlennRC68449942015-10-16 16:03:12 -0700219
220 utilities.assert_equals( expect=main.TRUE,
GlennRC073e8bc2015-10-27 17:11:28 -0700221 actual=stepResult,
GlennRC68449942015-10-16 16:03:12 -0700222 onpass="Successfully loaded topology",
223 onfail="Failed to load topology" )
224
GlennRC073e8bc2015-10-27 17:11:28 -0700225 main.step( "Assign switch to controller" )
226 stepResult = main.Mininet1.assignSwController( "s1", main.ONOSip[0] )
GlennRC68449942015-10-16 16:03:12 -0700227
228 utilities.assert_equals( expect=main.TRUE,
GlennRC073e8bc2015-10-27 17:11:28 -0700229 actual=stepResult,
230 onpass="Successfully assigned switch to controller",
231 onfail="Failed to assign switch to controller" )
GlennRC68449942015-10-16 16:03:12 -0700232
GlennRC073e8bc2015-10-27 17:11:28 -0700233 time.sleep( main.startMNSleep )
GlennRC68449942015-10-16 16:03:12 -0700234
GlennRC073e8bc2015-10-27 17:11:28 -0700235 main.step( "Conmparing MN topology to ONOS topology" )
236 main.log.info( "Gathering topology information" )
GlennRC1704d072015-10-07 18:40:45 -0700237 devicesResults = main.TRUE
238 linksResults = main.TRUE
239 hostsResults = main.TRUE
240 devices = main.topo.getAllDevices( main )
241 hosts = main.topo.getAllHosts( main )
242 ports = main.topo.getAllPorts( main )
243 links = main.topo.getAllLinks( main )
244 clusters = main.topo.getAllClusters( main )
245
246 mnSwitches = main.Mininet1.getSwitches()
247 mnLinks = main.Mininet1.getLinks()
248 mnHosts = main.Mininet1.getHosts()
249
GlennRC1704d072015-10-07 18:40:45 -0700250 for controller in range( main.numCtrls ):
251 controllerStr = str( controller + 1 )
252 if devices[ controller ] and ports[ controller ] and\
253 "Error" not in devices[ controller ] and\
254 "Error" not in ports[ controller ]:
255
256 currentDevicesResult = main.Mininet1.compareSwitches(
257 mnSwitches,
258 json.loads( devices[ controller ] ),
259 json.loads( ports[ controller ] ) )
260 else:
261 currentDevicesResult = main.FALSE
262 utilities.assert_equals( expect=main.TRUE,
263 actual=currentDevicesResult,
264 onpass="ONOS" + controllerStr +
GlennRC68449942015-10-16 16:03:12 -0700265 " Switches view is correct",
GlennRC1704d072015-10-07 18:40:45 -0700266 onfail="ONOS" + controllerStr +
GlennRC68449942015-10-16 16:03:12 -0700267 " Switches view is incorrect" )
GlennRC1704d072015-10-07 18:40:45 -0700268 if links[ controller ] and "Error" not in links[ controller ]:
269 currentLinksResult = main.Mininet1.compareLinks(
270 mnSwitches, mnLinks,
271 json.loads( links[ controller ] ) )
272 else:
273 currentLinksResult = main.FALSE
274 utilities.assert_equals( expect=main.TRUE,
275 actual=currentLinksResult,
276 onpass="ONOS" + controllerStr +
GlennRC68449942015-10-16 16:03:12 -0700277 " links view is correct",
GlennRC1704d072015-10-07 18:40:45 -0700278 onfail="ONOS" + controllerStr +
GlennRC68449942015-10-16 16:03:12 -0700279 " links view is incorrect" )
GlennRC1704d072015-10-07 18:40:45 -0700280
281 if hosts[ controller ] or "Error" not in hosts[ controller ]:
282 currentHostsResult = main.Mininet1.compareHosts(
283 mnHosts,
284 json.loads( hosts[ controller ] ) )
285 else:
286 currentHostsResult = main.FALSE
287 utilities.assert_equals( expect=main.TRUE,
288 actual=currentHostsResult,
289 onpass="ONOS" + controllerStr +
GlennRC68449942015-10-16 16:03:12 -0700290 " hosts exist in Mininet",
GlennRC1704d072015-10-07 18:40:45 -0700291 onfail="ONOS" + controllerStr +
GlennRC68449942015-10-16 16:03:12 -0700292 " hosts don't match Mininet")
GlennRCa5391372015-10-14 17:28:15 -0700293
GlennRC68449942015-10-16 16:03:12 -0700294
Jon Hall892818c2015-10-20 17:58:34 -0700295 def CASE66( self, main ):
296 '''
297 Testing scapy
298 '''
299 main.case( "Testing scapy" )
300 main.step( "Creating Host1 component" )
301 main.Mininet1.createHostComponent( "h1" )
302 main.Mininet1.createHostComponent( "h2" )
303 hosts = [main.h1, main.h2]
304 for host in hosts:
305 host.startHostCli()
306 host.startScapy()
307 host.updateSelf()
308 main.log.debug( host.name )
309 main.log.debug( host.hostIp )
310 main.log.debug( host.hostMac )
311
312 main.step( "Sending/Receiving Test packet - Filter doesn't match" )
313 main.h2.startFilter()
314 main.h1.buildEther( dst=main.h2.hostMac )
315 main.h1.sendPacket( )
316 finished = main.h2.checkFilter()
317 i = ""
318 if finished:
319 a = main.h2.readPackets()
320 for i in a.splitlines():
321 main.log.info( i )
322 else:
323 kill = main.h2.killFilter()
324 main.log.debug( kill )
325 main.h2.handle.sendline( "" )
326 main.h2.handle.expect( main.h2.scapyPrompt )
327 main.log.debug( main.h2.handle.before )
328 utilities.assert_equals( expect=True,
329 actual="dst=00:00:00:00:00:02 src=00:00:00:00:00:01" in i,
330 onpass="Pass",
331 onfail="Fail" )
332
333 main.step( "Sending/Receiving Test packet - Filter matches" )
334 main.h2.startFilter()
335 main.h1.buildEther( dst=main.h2.hostMac )
336 main.h1.buildIP( dst=main.h2.hostIp )
337 main.h1.sendPacket( )
338 finished = main.h2.checkFilter()
339 i = ""
340 if finished:
341 a = main.h2.readPackets()
342 for i in a.splitlines():
343 main.log.info( i )
344 else:
345 kill = main.h2.killFilter()
346 main.log.debug( kill )
347 main.h2.handle.sendline( "" )
348 main.h2.handle.expect( main.h2.scapyPrompt )
349 main.log.debug( main.h2.handle.before )
350 utilities.assert_equals( expect=True,
351 actual="dst=00:00:00:00:00:02 src=00:00:00:00:00:01" in i,
352 onpass="Pass",
353 onfail="Fail" )
354
355
356
357 main.step( "Clean up host components" )
358 for host in hosts:
359 host.stopScapy()
360 main.Mininet1.removeHostComponent("h1")
361 main.Mininet1.removeHostComponent("h2")
362
GlennRC68449942015-10-16 16:03:12 -0700363 def CASE1000( self, main ):
364 '''
GlennRC073e8bc2015-10-27 17:11:28 -0700365 Add flows with MAC selectors and verify the flows
GlennRC68449942015-10-16 16:03:12 -0700366 '''
GlennRC073e8bc2015-10-27 17:11:28 -0700367 import json
368 import time
GlennRC68449942015-10-16 16:03:12 -0700369
GlennRC073e8bc2015-10-27 17:11:28 -0700370 main.case( "Verify flow MAC selectors are correctly compiled" )
371 main.caseExplanation = "Install two flows with only MAC selectors " +\
372 "specified, then verify flows are added in ONOS, finally "+\
373 "send a packet that only specifies the MAC src and dst."
GlennRC68449942015-10-16 16:03:12 -0700374
GlennRC073e8bc2015-10-27 17:11:28 -0700375 main.step( "Add flows with MAC addresses as the only selectors" )
GlennRC68449942015-10-16 16:03:12 -0700376
GlennRC073e8bc2015-10-27 17:11:28 -0700377 main.log.info( "Creating host components" )
378 main.Mininet1.createHostComponent( "h1" )
379 main.Mininet1.createHostComponent( "h2" )
380 hosts = [main.h1, main.h2]
381 stepResult = main.TRUE
382 for host in hosts:
383 host.startHostCli()
384 host.startScapy()
385 host.updateSelf()
GlennRC68449942015-10-16 16:03:12 -0700386
GlennRC073e8bc2015-10-27 17:11:28 -0700387 # Add a flow that connects host1 on port1 to host2 on port2
388 # send output on port2
389 # recieve input on port1
390 egress = 2
391 ingress = 1
392
393 # Add flows that sends packets from port1 to port2 with correct
394 # MAC src and dst addresses
395 main.log.info( "Adding flow with MAC selectors" )
396 stepResult = main.ONOSrest.addFlow( deviceId=main.swDPID,
397 egressPort=egress,
398 ingressPort=ingress,
399 ethSrc=main.h1.hostMac,
400 ethDst=main.h2.hostMac,
401 debug=True )
GlennRC68449942015-10-16 16:03:12 -0700402
GlennRCa5391372015-10-14 17:28:15 -0700403 utilities.assert_equals( expect=main.TRUE,
404 actual=stepResult,
GlennRC68449942015-10-16 16:03:12 -0700405 onpass="Successfully added flows",
406 onfail="Failed add flows" )
GlennRCa5391372015-10-14 17:28:15 -0700407
GlennRC073e8bc2015-10-27 17:11:28 -0700408 # Giving ONOS time to add the flows
409 time.sleep( main.addFlowSleep )
GlennRC5147a422015-10-06 17:26:17 -0700410
GlennRC073e8bc2015-10-27 17:11:28 -0700411 main.step( "Check flows are in the ADDED state" )
412
413 #TODO: We should check mininet if flows are added as well
414 main.log.info( "Get the flows from ONOS" )
GlennRC68449942015-10-16 16:03:12 -0700415 flows = json.loads( main.ONOSrest.flows() )
416
417 stepResult = main.TRUE
418 for f in flows:
419 if "rest" in f.get("appId"):
GlennRC073e8bc2015-10-27 17:11:28 -0700420 if "ADDED" not in f.get("state"):
421 stepResult = main.FALSE
422 main.log.error( "Flow: %s in state: %s" % (f.get("id"), f.get("state")) )
GlennRC68449942015-10-16 16:03:12 -0700423
424 utilities.assert_equals( expect=main.TRUE,
425 actual=stepResult,
426 onpass="All flows are in the ADDED state",
GlennRC073e8bc2015-10-27 17:11:28 -0700427 onfail="All flows are NOT in the ADDED state" )
GlennRC68449942015-10-16 16:03:12 -0700428
GlennRC073e8bc2015-10-27 17:11:28 -0700429 main.step( "Send a packet to verify the flows are correct" )
430
431 # Specify the src and dst MAC addr
432 main.log.info( "Constructing packet" )
433 main.h1.buildEther( src=main.h1.hostMac, dst=main.h2.hostMac )
434
435 # Filter for packets with the correct host name. Otherwise,
436 # the filter we catch any packet that is sent to host2
437 # NOTE: I believe it doesn't matter which host name it is,
438 # as long as its host1 or host2
439 main.log.info( "Starting filter on host2" )
440 main.h2.startFilter( pktFilter="ether host %s" % main.h1.hostMac)
441
442 main.log.info( "Sending packet to host2" )
443 main.h1.sendPacket()
444
445 main.log.info( "Checking filter for our packet" )
446 stepResult = main.h2.checkFilter()
447 if stepResult:
448 main.log.info( "Packet: %s" % main.h2.readPackets() )
449 else: main.h2.killFilter()
450
451 main.log.info( "Clean up host components" )
452 for host in hosts:
453 host.stopScapy()
454 main.Mininet1.removeHostComponent("h1")
455 main.Mininet1.removeHostComponent("h2")
456
457 utilities.assert_equals( expect=main.TRUE,
458 actual=stepResult,
459 onpass="Successfully sent a packet",
460 onfail="Failed to send a packet" )
461
462 def CASE1100( self, main ):
GlennRC68449942015-10-16 16:03:12 -0700463 '''
GlennRC073e8bc2015-10-27 17:11:28 -0700464 Add flows with IPv4 selectors and verify the flows
GlennRC68449942015-10-16 16:03:12 -0700465 '''
466 import json
GlennRC073e8bc2015-10-27 17:11:28 -0700467 import time
GlennRC68449942015-10-16 16:03:12 -0700468
GlennRC073e8bc2015-10-27 17:11:28 -0700469 main.case( "Verify flow IP selectors are correctly compiled" )
470 main.caseExplanation = "Install two flows with only IP selectors " +\
471 "specified, then verify flows are added in ONOS, finally "+\
472 "send a packet that only specifies the IP src and dst."
473
474 main.step( "Add flows with IPv4 addresses as the only selectors" )
475
476 main.log.info( "Creating host components" )
477 main.Mininet1.createHostComponent( "h1" )
478 main.Mininet1.createHostComponent( "h2" )
479 hosts = [main.h1, main.h2]
480 stepResult = main.TRUE
481 for host in hosts:
482 host.startHostCli()
483 host.startScapy()
484 host.updateSelf()
485
486 # Add a flow that connects host1 on port1 to host2 on port2
487 # send output on port2
488 # recieve input on port1
489 egress = 2
490 ingress = 1
491 # IPv4 etherType = 0x800
492 IPv4=2048
493
494 # Add flows that connects host1 to host2
495 main.log.info( "Add flow with port ingress 1 to port egress 2" )
496 stepResult = main.ONOSrest.addFlow( deviceId=main.swDPID,
497 egressPort=egress,
498 ingressPort=ingress,
499 ethType=IPv4,
500 ipSrc=("IPV4_SRC", main.h1.hostIp+"/32"),
501 ipDst=("IPV4_DST", main.h2.hostIp+"/32"),
502 debug=True )
503
504 utilities.assert_equals( expect=main.TRUE,
505 actual=stepResult,
506 onpass="Successfully added flows",
507 onfail="Failed add flows" )
508
509 # Giving ONOS time to add the flow
510 time.sleep( main.addFlowSleep )
511
512 main.step( "Check flow is in the ADDED state" )
513
514 main.log.info( "Get the flows from ONOS" )
GlennRC68449942015-10-16 16:03:12 -0700515 flows = json.loads( main.ONOSrest.flows() )
516
517 stepResult = main.TRUE
518 for f in flows:
519 if "rest" in f.get("appId"):
GlennRC073e8bc2015-10-27 17:11:28 -0700520 if "ADDED" not in f.get("state"):
521 stepResult = main.FALSE
522 main.log.error( "Flow: %s in state: %s" % (f.get("id"), f.get("state")) )
GlennRC68449942015-10-16 16:03:12 -0700523
524 utilities.assert_equals( expect=main.TRUE,
525 actual=stepResult,
GlennRC073e8bc2015-10-27 17:11:28 -0700526 onpass="All flows are in the ADDED state",
527 onfail="All flows are NOT in the ADDED state" )
528
529 main.step( "Send a packet to verify the flow is correct" )
530
531 main.log.info( "Constructing packet" )
532 # No need for the MAC src dst
533 main.h1.buildEther( dst=main.h2.hostMac )
534 main.h1.buildIP( src=main.h1.hostIp, dst=main.h2.hostIp )
535
536 main.log.info( "Starting filter on host2" )
537 # Defaults to ip
538 main.h2.startFilter()
539
540 main.log.info( "Sending packet to host2" )
541 main.h1.sendPacket()
542
543 main.log.info( "Checking filter for our packet" )
544 stepResult = main.h2.checkFilter()
545 if stepResult:
546 main.log.info( "Packet: %s" % main.h2.readPackets() )
547 else: main.h2.killFilter()
548
549 main.log.info( "Clean up host components" )
550 for host in hosts:
551 host.stopScapy()
552 main.Mininet1.removeHostComponent("h1")
553 main.Mininet1.removeHostComponent("h2")
554
555 utilities.assert_equals( expect=main.TRUE,
556 actual=stepResult,
557 onpass="Successfully sent a packet",
558 onfail="Failed to send a packet" )
559
560 def CASE1200( self, main ):
561 '''
562 Add flow with VLAN selector and verify the flow
563 '''
564 import json
565 import time
566
567 main.case( "Verify VLAN selector is correctly compiled" )
568 main.caseExplanation = "Install one flow with only the VLAN selector " +\
569 "specified, then verify the flow is added in ONOS, and finally "+\
570 "broadcast a packet with the correct VLAN tag."
571
572 # We do this here to utilize the hosts information
573 main.log.info( "Creating host components" )
574 main.Mininet1.createHostComponent( "h3" )
575 main.Mininet1.createHostComponent( "h4" )
576 hosts = [main.h3, main.h4]
577 stepResult = main.TRUE
578 for host in hosts:
579 host.startHostCli()
580 host.startScapy()
581 host.updateSelf()
582
583
584 main.step( "Add a flow with the VLAN tag as the only selector" )
585
586 # Add flows that connects the two vlan hosts h3 and h4
587 # Host 3 is on port 3 and host 4 is on port 4
588 vlan = main.params[ 'TEST' ][ 'vlan' ]
589 egress = 4
590 ingress = 3
591 # VLAN ethType = 0x8100
592 ethType = 33024
593
594 # Add only one flow because we don't need a response
595 main.log.info( "Add flow with port ingress 1 to port egress 2" )
596 stepResult = main.ONOSrest.addFlow( deviceId=main.swDPID,
597 egressPort=egress,
598 ingressPort=ingress,
599 ethType=ethType,
600 vlan=vlan,
601 debug=True )
602
603
604 utilities.assert_equals( expect=main.TRUE,
605 actual=stepResult,
606 onpass="Successfully added flow",
607 onfail="Failed add flows" )
608
609 # Giving ONOS time to add the flows
610 time.sleep( main.addFlowSleep )
611
612 main.step( "Check flows are in the ADDED state" )
613
614 main.log.info( "Get the flows from ONOS" )
615 flows = json.loads( main.ONOSrest.flows() )
616
617 stepResult = main.TRUE
618 for f in flows:
619 if "rest" in f.get("appId"):
620 if "ADDED" not in f.get("state"):
621 stepResult = main.FALSE
622 main.log.error( "Flow: %s in state: %s" % (f.get("id"), f.get("state")) )
623
624 utilities.assert_equals( expect=main.TRUE,
625 actual=stepResult,
626 onpass="All flows are in the ADDED state",
627 onfail="All flows are NOT in the ADDED state" )
628
629 main.step( "Send a packet to verify the flow are correct" )
630
631 # The receiving interface
632 recIface = "{}-eth0.{}".format(main.h4.name, vlan)
633 main.log.info( "Starting filter on host2" )
634 # Filter is setup to catch any packet on the vlan interface with the correct vlan tag
635 main.h4.startFilter( ifaceName=recIface, pktFilter="" )
636
637 # Broadcast the packet on the vlan interface. We only care if the flow forwards
638 # the packet with the correct vlan tag, not if the mac addr is correct
639 BROADCAST = "FF:FF:FF:FF:FF:FF"
640 sendIface = "{}-eth0.{}".format(main.h3.name, vlan)
641 main.log.info( "Broadcasting the packet with a vlan tag" )
642 main.h3.sendPacket( iface=sendIface, packet="Ether(dst='{}')/Dot1Q(vlan={})".format(BROADCAST, vlan))
643
644 main.log.info( "Checking filter for our packet" )
645 stepResult = main.h4.checkFilter()
646 if stepResult:
647 main.log.info( "Packet: %s" % main.h4.readPackets() )
648 else: main.h4.killFilter()
649
650 main.log.info( "Clean up host components" )
651 for host in hosts:
652 host.stopScapy()
653 main.Mininet1.removeHostComponent("h3")
654 main.Mininet1.removeHostComponent("h4")
655
656 utilities.assert_equals( expect=main.TRUE,
657 actual=stepResult,
658 onpass="Successfully sent a packet",
659 onfail="Failed to send a packet" )
GlennRC68449942015-10-16 16:03:12 -0700660
661 def CASE100( self, main ):
GlennRC5147a422015-10-06 17:26:17 -0700662 '''
663 Report errors/warnings/exceptions
664 '''
665 main.log.info("Error report: \n" )
666 main.ONOSbench.logReport( main.ONOSip[ 0 ],
667 [ "INFO",
668 "FOLLOWER",
669 "WARN",
670 "flow",
671 "ERROR",
672 "Except" ],
GlennRC68449942015-10-16 16:03:12 -0700673 "s" )
GlennRC5147a422015-10-06 17:26:17 -0700674