blob: 1a32bc1be2a6f281a7b726d52e862e9032647ba8 [file] [log] [blame]
kelvin-onlab44147802015-07-27 17:57:31 -07001
2# Testing the basic intent functionality of ONOS
Jeremy2f190ca2016-01-29 15:23:57 -08003# TODO: Replace the CLI calls with REST API equivalents as they become available.
4# - May need to write functions in the onosrestdriver.py file to do this
5# TODO: Complete implementation of case 3000, 4000, and 6000 as REST API allows
6# -Currently there is no support in the REST API for Multi to Single and Single to Multi point intents
7# As such, these cases are incomplete and should not be enabled in the .params file
kelvin-onlab44147802015-07-27 17:57:31 -07008
9import time
10import json
11
12class FUNCintentRest:
13
14 def __init__( self ):
15 self.default = ''
16
17 def CASE1( self, main ):
18 import time
kelvin-onlab44147802015-07-27 17:57:31 -070019 import imp
Jon Hallf7234882015-08-28 13:16:31 -070020 import re
kelvin-onlab44147802015-07-27 17:57:31 -070021
22 """
23 - Construct tests variables
24 - GIT ( optional )
25 - Checkout ONOS master branch
26 - Pull latest ONOS code
27 - Building ONOS ( optional )
28 - Install ONOS package
29 - Build ONOS package
30 """
31
32 main.case( "Constructing test variables and building ONOS package" )
33 main.step( "Constructing test variables" )
34 main.caseExplanation = "This test case is mainly for loading " +\
35 "from params file, and pull and build the " +\
36 " latest ONOS package"
37 stepResult = main.FALSE
38
39 # Test variables
40 try:
Jon Hallf7234882015-08-28 13:16:31 -070041 main.testOnDirectory = re.sub( "(/tests)$", "", main.testDir )
kelvin-onlab44147802015-07-27 17:57:31 -070042 main.apps = main.params[ 'ENV' ][ 'cellApps' ]
43 gitBranch = main.params[ 'GIT' ][ 'branch' ]
44 main.dependencyPath = main.testOnDirectory + \
45 main.params[ 'DEPENDENCY' ][ 'path' ]
46 main.topology = main.params[ 'DEPENDENCY' ][ 'topology' ]
47 main.scale = ( main.params[ 'SCALE' ][ 'size' ] ).split( "," )
48 if main.ONOSbench.maxNodes:
49 main.maxNodes = int( main.ONOSbench.maxNodes )
50 else:
51 main.maxNodes = 0
52 wrapperFile1 = main.params[ 'DEPENDENCY' ][ 'wrapper1' ]
53 wrapperFile2 = main.params[ 'DEPENDENCY' ][ 'wrapper2' ]
54 wrapperFile3 = main.params[ 'DEPENDENCY' ][ 'wrapper3' ]
55 main.startUpSleep = int( main.params[ 'SLEEP' ][ 'startup' ] )
Jeremy2f190ca2016-01-29 15:23:57 -080056 main.checkIntentSleep = int( main.params[ 'SLEEP' ][ 'checkintent' ] )
57 main.removeIntentsleeo = int( main.params[ 'SLEEP' ][ 'removeintent' ] )
kelvin-onlab44147802015-07-27 17:57:31 -070058 main.rerouteSleep = int( main.params[ 'SLEEP' ][ 'reroute' ] )
59 main.fwdSleep = int( main.params[ 'SLEEP' ][ 'fwd' ] )
kelvin-onlab0e684682015-08-11 18:51:41 -070060 main.addIntentSleep = int( main.params[ 'SLEEP' ][ 'addIntent' ] )
Jeremy2f190ca2016-01-29 15:23:57 -080061 main.checkTopoAttempts = int( main.params[ 'SLEEP' ][ 'topoAttempts' ] )
kelvin-onlab44147802015-07-27 17:57:31 -070062 gitPull = main.params[ 'GIT' ][ 'pull' ]
63 main.numSwitch = int( main.params[ 'MININET' ][ 'switch' ] )
64 main.numLinks = int( main.params[ 'MININET' ][ 'links' ] )
65 main.cellData = {} # for creating cell file
66 main.hostsData = {}
67 main.CLIs = []
Jeremye1ea0602016-02-08 16:35:05 -080068 main.CLIs2 = []
kelvin-onlab44147802015-07-27 17:57:31 -070069 main.ONOSip = []
Jeremy2f190ca2016-01-29 15:23:57 -080070 main.scapyHostNames = main.params[ 'SCAPY' ][ 'HOSTNAMES' ].split( ',' )
71 main.scapyHosts = [] # List of scapy hosts for iterating
72 main.assertReturnString = '' # Assembled assert return string
kelvin-onlab44147802015-07-27 17:57:31 -070073
74 main.ONOSip = main.ONOSbench.getOnosIps()
Jeremy2f190ca2016-01-29 15:23:57 -080075 print main.ONOSip
kelvin-onlab44147802015-07-27 17:57:31 -070076
77 # Assigning ONOS cli handles to a list
Jon Hallf7234882015-08-28 13:16:31 -070078 try:
79 for i in range( 1, main.maxNodes + 1 ):
80 main.CLIs.append( getattr( main, 'ONOSrest' + str( i ) ) )
Jeremye1ea0602016-02-08 16:35:05 -080081 main.CLIs2.append( getattr( main, 'ONOScli' + str( i ) ) )
Jon Hallf7234882015-08-28 13:16:31 -070082 except AttributeError:
83 main.log.warn( "A " + str( main.maxNodes ) + " node cluster " +
84 "was defined in env variables, but only " +
85 str( len( main.CLIs ) ) +
86 " nodes were defined in the .topo file. " +
87 "Using " + str( len( main.CLIs ) ) +
88 " nodes for the test." )
kelvin-onlab44147802015-07-27 17:57:31 -070089
90 # -- INIT SECTION, ONLY RUNS ONCE -- #
91 main.startUp = imp.load_source( wrapperFile1,
92 main.dependencyPath +
93 wrapperFile1 +
94 ".py" )
95
96 main.intentFunction = imp.load_source( wrapperFile2,
97 main.dependencyPath +
98 wrapperFile2 +
99 ".py" )
100
101 main.topo = imp.load_source( wrapperFile3,
102 main.dependencyPath +
103 wrapperFile3 +
104 ".py" )
105
Jon Hallf7234882015-08-28 13:16:31 -0700106 copyResult1 = main.ONOSbench.scp( main.Mininet1,
107 main.dependencyPath +
108 main.topology,
Jeremy2f190ca2016-01-29 15:23:57 -0800109 main.Mininet1.home + "custom/",
Jon Hallf7234882015-08-28 13:16:31 -0700110 direction="to" )
Jeremye1ea0602016-02-08 16:35:05 -0800111 if main.CLIs and main.CLIs2:
kelvin-onlab44147802015-07-27 17:57:31 -0700112 stepResult = main.TRUE
113 else:
114 main.log.error( "Did not properly created list of ONOS CLI handle" )
115 stepResult = main.FALSE
116 except Exception as e:
117 main.log.exception(e)
118 main.cleanup()
119 main.exit()
120
121 utilities.assert_equals( expect=main.TRUE,
122 actual=stepResult,
123 onpass="Successfully construct " +
124 "test variables ",
125 onfail="Failed to construct test variables" )
126
127 if gitPull == 'True':
128 main.step( "Building ONOS in " + gitBranch + " branch" )
129 onosBuildResult = main.startUp.onosBuild( main, gitBranch )
130 stepResult = onosBuildResult
131 utilities.assert_equals( expect=main.TRUE,
132 actual=stepResult,
133 onpass="Successfully compiled " +
134 "latest ONOS",
135 onfail="Failed to compile " +
136 "latest ONOS" )
137 else:
138 main.log.warn( "Did not pull new code so skipping mvn " +
139 "clean install" )
140 main.ONOSbench.getVersion( report=True )
141
142 def CASE2( self, main ):
143 """
144 - Set up cell
145 - Create cell file
146 - Set cell file
147 - Verify cell file
148 - Kill ONOS process
149 - Uninstall ONOS cluster
150 - Verify ONOS start up
151 - Install ONOS cluster
152 - Connect to cli
153 """
154
155 # main.scale[ 0 ] determines the current number of ONOS controller
156 main.numCtrls = int( main.scale[ 0 ] )
157
158 main.case( "Starting up " + str( main.numCtrls ) +
159 " node(s) ONOS cluster" )
160 main.caseExplanation = "Set up ONOS with " + str( main.numCtrls ) +\
161 " node(s) ONOS cluster"
162
163
164
165 #kill off all onos processes
166 main.log.info( "Safety check, killing all ONOS processes" +
Jon Hall70b2ff42015-11-17 15:49:44 -0800167 " before initiating environment setup" )
kelvin-onlab44147802015-07-27 17:57:31 -0700168
Jeremy2f190ca2016-01-29 15:23:57 -0800169 time.sleep( main.startUpSleep )
Jeremy42df2e72016-02-23 16:37:46 -0800170
Jeremy2f190ca2016-01-29 15:23:57 -0800171 main.step( "Uninstalling ONOS package" )
172 onosUninstallResult = main.TRUE
173 for ip in main.ONOSip:
174 onosUninstallResult = onosUninstallResult and \
175 main.ONOSbench.onosUninstall( nodeIp=ip )
176 stepResult = onosUninstallResult
177 utilities.assert_equals( expect=main.TRUE,
178 actual=stepResult,
179 onpass="Successfully uninstalled ONOS package",
180 onfail="Failed to uninstall ONOS package" )
181
Jeremy42df2e72016-02-23 16:37:46 -0800182 time.sleep( main.startUpSleep )
183
kelvin-onlab44147802015-07-27 17:57:31 -0700184 for i in range( main.maxNodes ):
185 main.ONOSbench.onosDie( main.ONOSip[ i ] )
186
187 print "NODE COUNT = ", main.numCtrls
188
189 tempOnosIp = []
190 for i in range( main.numCtrls ):
191 tempOnosIp.append( main.ONOSip[i] )
192
193 main.ONOSbench.createCellFile( main.ONOSbench.ip_address,
194 "temp", main.Mininet1.ip_address,
195 main.apps, tempOnosIp )
196
197 main.step( "Apply cell to environment" )
198 cellResult = main.ONOSbench.setCell( "temp" )
199 verifyResult = main.ONOSbench.verifyCell()
200 stepResult = cellResult and verifyResult
201 utilities.assert_equals( expect=main.TRUE,
202 actual=stepResult,
203 onpass="Successfully applied cell to " + \
204 "environment",
205 onfail="Failed to apply cell to environment " )
206
207 main.step( "Creating ONOS package" )
208 packageResult = main.ONOSbench.onosPackage()
209 stepResult = packageResult
210 utilities.assert_equals( expect=main.TRUE,
211 actual=stepResult,
212 onpass="Successfully created ONOS package",
213 onfail="Failed to create ONOS package" )
214
215 time.sleep( main.startUpSleep )
kelvin-onlab44147802015-07-27 17:57:31 -0700216 main.step( "Installing ONOS package" )
217 onosInstallResult = main.TRUE
218 for i in range( main.numCtrls ):
219 onosInstallResult = onosInstallResult and \
220 main.ONOSbench.onosInstall( node=main.ONOSip[ i ] )
221 stepResult = onosInstallResult
222 utilities.assert_equals( expect=main.TRUE,
223 actual=stepResult,
224 onpass="Successfully installed ONOS package",
225 onfail="Failed to install ONOS package" )
226
227 time.sleep( main.startUpSleep )
228 main.step( "Starting ONOS service" )
229 stopResult = main.TRUE
230 startResult = main.TRUE
231 onosIsUp = main.TRUE
232
233 for i in range( main.numCtrls ):
234 onosIsUp = onosIsUp and main.ONOSbench.isup( main.ONOSip[ i ] )
235 if onosIsUp == main.TRUE:
236 main.log.report( "ONOS instance is up and ready" )
237 else:
238 main.log.report( "ONOS instance may not be up, stop and " +
239 "start ONOS again " )
240 for i in range( main.numCtrls ):
241 stopResult = stopResult and \
242 main.ONOSbench.onosStop( main.ONOSip[ i ] )
243 for i in range( main.numCtrls ):
244 startResult = startResult and \
245 main.ONOSbench.onosStart( main.ONOSip[ i ] )
246 stepResult = onosIsUp and stopResult and startResult
247 utilities.assert_equals( expect=main.TRUE,
248 actual=stepResult,
249 onpass="ONOS service is ready",
250 onfail="ONOS service did not start properly" )
251
Jeremy2f190ca2016-01-29 15:23:57 -0800252 # Start an ONOS cli to provide functionality that is not currently
Jeremye1ea0602016-02-08 16:35:05 -0800253 # supported by the Rest API remove this when Leader Checking is supported
254 # by the REST API
Jeremy2f190ca2016-01-29 15:23:57 -0800255
Jeremye1ea0602016-02-08 16:35:05 -0800256 main.step( "Start ONOS cli" )
257 cliResult = main.TRUE
258 for i in range( main.numCtrls ):
259 cliResult = cliResult and \
260 main.CLIs2[ i ].startOnosCli( main.ONOSip[ i ] )
261 stepResult = cliResult
262 utilities.assert_equals( expect=main.TRUE,
263 actual=stepResult,
264 onpass="Successfully start ONOS cli",
265 onfail="Failed to start ONOS cli" )
Jeremy2f190ca2016-01-29 15:23:57 -0800266
kelvin-onlab44147802015-07-27 17:57:31 -0700267 # Remove the first element in main.scale list
268 main.scale.remove( main.scale[ 0 ] )
269
Jeremy2f190ca2016-01-29 15:23:57 -0800270 main.intentFunction.report( main )
271
kelvin-onlab44147802015-07-27 17:57:31 -0700272 def CASE8( self, main ):
Jeremy2f190ca2016-01-29 15:23:57 -0800273 # OLD FUNCintentRest CASE 8
274 # This remains here for archiving and reference purposes and will be
275 # removed when the new FUNCintentRest is verified to work.
276 # """
277 # Compare Topo
278 # """
279 # import json
280
281 # main.case( "Compare ONOS Topology view to Mininet topology" )
282 # main.caseExplanation = "Compare topology elements between Mininet" +\
283 # " and ONOS"
284
285 # main.step( "Gathering topology information" )
286 # # TODO: add a paramaterized sleep here
287 # devicesResults = main.TRUE # Overall Boolean for device correctness
288 # linksResults = main.TRUE # Overall Boolean for link correctness
289 # hostsResults = main.TRUE # Overall Boolean for host correctness
290 # devices = main.topo.getAllDevices( main )
291 # hosts = main.topo.getAllHosts( main )
292 # ports = main.topo.getAllPorts( main )
293 # links = main.topo.getAllLinks( main )
294 # clusters = main.topo.getAllClusters( main )
295
296 # mnSwitches = main.Mininet1.getSwitches()
297 # mnLinks = main.Mininet1.getLinks()
298 # mnHosts = main.Mininet1.getHosts()
299
300 # main.step( "Comparing MN topology to ONOS topology" )
301 # for controller in range( main.numCtrls ):
302 # controllerStr = str( controller + 1 )
303 # if devices[ controller ] and ports[ controller ] and\
304 # "Error" not in devices[ controller ] and\
305 # "Error" not in ports[ controller ]:
306
307 # currentDevicesResult = main.Mininet1.compareSwitches(
308 # mnSwitches,
309 # json.loads( devices[ controller ] ),
310 # json.loads( ports[ controller ] ) )
311 # else:
312 # currentDevicesResult = main.FALSE
313 # utilities.assert_equals( expect=main.TRUE,
314 # actual=currentDevicesResult,
315 # onpass="ONOS" + controllerStr +
316 # " Switches view is correct",
317 # onfail="ONOS" + controllerStr +
318 # " Switches view is incorrect" )
319
320 # if links[ controller ] and "Error" not in links[ controller ]:
321 # currentLinksResult = main.Mininet1.compareLinks(
322 # mnSwitches, mnLinks,
323 # json.loads( links[ controller ] ) )
324 # else:
325 # currentLinksResult = main.FALSE
326 # utilities.assert_equals( expect=main.TRUE,
327 # actual=currentLinksResult,
328 # onpass="ONOS" + controllerStr +
329 # " links view is correct",
330 # onfail="ONOS" + controllerStr +
331 # " links view is incorrect" )
332
333 # if hosts[ controller ] or "Error" not in hosts[ controller ]:
334 # currentHostsResult = main.Mininet1.compareHosts(
335 # mnHosts,
336 # json.loads( hosts[ controller ] ) )
337 # else:
338 # currentHostsResult = main.FALSE
339 # utilities.assert_equals( expect=main.TRUE,
340 # actual=currentHostsResult,
341 # onpass="ONOS" + controllerStr +
342 # " hosts exist in Mininet",
343 # onfail="ONOS" + controllerStr +
344 # " hosts don't match Mininet" )
345
346 # NEW FUNCintentRest Case 8 as based off of the CASE 8 from FUNCintent
kelvin-onlab44147802015-07-27 17:57:31 -0700347 """
Jeremy2f190ca2016-01-29 15:23:57 -0800348 Compare ONOS Topology to Mininet Topology
kelvin-onlab44147802015-07-27 17:57:31 -0700349 """
350 import json
351
352 main.case( "Compare ONOS Topology view to Mininet topology" )
353 main.caseExplanation = "Compare topology elements between Mininet" +\
354 " and ONOS"
355
Jeremy2f190ca2016-01-29 15:23:57 -0800356 main.log.info( "Gathering topology information from Mininet" )
357 devicesResults = main.FALSE # Overall Boolean for device correctness
358 linksResults = main.FALSE # Overall Boolean for link correctness
359 hostsResults = main.FALSE # Overall Boolean for host correctness
360 deviceFails = [] # Nodes where devices are incorrect
361 linkFails = [] # Nodes where links are incorrect
362 hostFails = [] # Nodes where hosts are incorrect
363 attempts = main.checkTopoAttempts # Remaining Attempts
kelvin-onlab44147802015-07-27 17:57:31 -0700364
365 mnSwitches = main.Mininet1.getSwitches()
366 mnLinks = main.Mininet1.getLinks()
367 mnHosts = main.Mininet1.getHosts()
368
Jeremy2f190ca2016-01-29 15:23:57 -0800369 main.step( "Comparing Mininet topology to ONOS topology" )
kelvin-onlab44147802015-07-27 17:57:31 -0700370
Jeremy2f190ca2016-01-29 15:23:57 -0800371 while ( attempts >= 0 ) and\
372 ( not devicesResults or not linksResults or not hostsResults ):
373 time.sleep( 2 )
374 if not devicesResults:
375 devices = main.topo.getAllDevices( main )
376 ports = main.topo.getAllPorts( main )
377 devicesResults = main.TRUE
378 deviceFails = [] # Reset for each failed attempt
379 if not linksResults:
380 links = main.topo.getAllLinks( main )
381 linksResults = main.TRUE
382 linkFails = [] # Reset for each failed attempt
383 if not hostsResults:
384 hosts = main.topo.getAllHosts( main )
385 hostsResults = main.TRUE
386 hostFails = [] # Reset for each failed attempt
kelvin-onlab44147802015-07-27 17:57:31 -0700387
Jeremy2f190ca2016-01-29 15:23:57 -0800388 # Check for matching topology on each node
389 for controller in range( main.numCtrls ):
390 controllerStr = str( controller + 1 ) # ONOS node number
391 # Compare Devices
392 if devices[ controller ] and ports[ controller ] and\
393 "Error" not in devices[ controller ] and\
394 "Error" not in ports[ controller ]:
kelvin-onlab44147802015-07-27 17:57:31 -0700395
Jeremy2f190ca2016-01-29 15:23:57 -0800396 try:
397 deviceData = json.loads( devices[ controller ] )
398 portData = json.loads( ports[ controller ] )
399 except (TypeError,ValueError):
400 main.log.error( "Could not load json: {0} or {1}".format( str( devices[ controller ] ), str( ports[ controller ] ) ) )
401 currentDevicesResult = main.FALSE
402 else:
403 currentDevicesResult = main.Mininet1.compareSwitches(
404 mnSwitches,deviceData,portData )
405 else:
406 currentDevicesResult = main.FALSE
407 if not currentDevicesResult:
408 deviceFails.append( controllerStr )
409 devicesResults = devicesResults and currentDevicesResult
410 # Compare Links
411 if links[ controller ] and "Error" not in links[ controller ]:
412 try:
413 linkData = json.loads( links[ controller ] )
414 except (TypeError,ValueError):
415 main.log.error("Could not load json:" + str( links[ controller ] ) )
416 currentLinksResult = main.FALSE
417 else:
418 currentLinksResult = main.Mininet1.compareLinks(
419 mnSwitches, mnLinks,linkData )
420 else:
421 currentLinksResult = main.FALSE
422 if not currentLinksResult:
423 linkFails.append( controllerStr )
424 linksResults = linksResults and currentLinksResult
425 # Compare Hosts
426 if hosts[ controller ] and "Error" not in hosts[ controller ]:
427 try:
428 hostData = json.loads( hosts[ controller ] )
429 except (TypeError,ValueError):
430 main.log.error("Could not load json:" + str( hosts[ controller ] ) )
431 currentHostsResult = main.FALSE
432 else:
433 currentHostsResult = main.Mininet1.compareHosts(
434 mnHosts,hostData )
435 else:
436 currentHostsResult = main.FALSE
437 if not currentHostsResult:
438 hostFails.append( controllerStr )
439 hostsResults = hostsResults and currentHostsResult
440 # Decrement Attempts Remaining
441 attempts -= 1
442
443
444 utilities.assert_equals( expect=[],
445 actual=deviceFails,
446 onpass="ONOS correctly discovered all devices",
447 onfail="ONOS incorrectly discovered devices on nodes: " +
448 str( deviceFails ) )
449 utilities.assert_equals( expect=[],
450 actual=linkFails,
451 onpass="ONOS correctly discovered all links",
452 onfail="ONOS incorrectly discovered links on nodes: " +
453 str( linkFails ) )
454 utilities.assert_equals( expect=[],
455 actual=hostFails,
456 onpass="ONOS correctly discovered all hosts",
457 onfail="ONOS incorrectly discovered hosts on nodes: " +
458 str( hostFails ) )
459 topoResults = hostsResults and linksResults and devicesResults
460 utilities.assert_equals( expect=main.TRUE,
461 actual=topoResults,
462 onpass="ONOS correctly discovered the topology",
463 onfail="ONOS incorrectly discovered the topology" )
kelvin-onlab44147802015-07-27 17:57:31 -0700464
465 def CASE9( self, main ):
466 '''
467 Report errors/warnings/exceptions
468 '''
469 main.log.info( "Error report: \n" )
470 main.ONOSbench.logReport( globalONOSip[0],
471 [ "INFO", "FOLLOWER", "WARN", "flow", "ERROR" , "Except" ],
472 "s" )
473 #main.ONOSbench.logReport( globalONOSip[1], [ "INFO" ], "d" )
474
475 def CASE10( self, main ):
476 """
477 Start Mininet topology with OF 1.0 switches
478 """
479 main.OFProtocol = "1.0"
480 main.log.report( "Start Mininet topology with OF 1.0 switches" )
481 main.case( "Start Mininet topology with OF 1.0 switches" )
482 main.caseExplanation = "Start mininet topology with OF 1.0 " +\
483 "switches to test intents, exits out if " +\
484 "topology did not start correctly"
485
486 main.step( "Starting Mininet topology with OF 1.0 switches" )
487 args = "--switch ovs,protocols=OpenFlow10"
488 topoResult = main.Mininet1.startNet( topoFile=main.dependencyPath +
489 main.topology,
490 args=args )
491 stepResult = topoResult
492 utilities.assert_equals( expect=main.TRUE,
493 actual=stepResult,
494 onpass="Successfully loaded topology",
495 onfail="Failed to load topology" )
496 # Exit if topology did not load properly
497 if not topoResult:
498 main.cleanup()
499 main.exit()
500
501 def CASE11( self, main ):
502 """
503 Start Mininet topology with OF 1.3 switches
504 """
505 main.OFProtocol = "1.3"
506 main.log.report( "Start Mininet topology with OF 1.3 switches" )
507 main.case( "Start Mininet topology with OF 1.3 switches" )
508 main.caseExplanation = "Start mininet topology with OF 1.3 " +\
509 "switches to test intents, exits out if " +\
510 "topology did not start correctly"
511
512 main.step( "Starting Mininet topology with OF 1.3 switches" )
513 args = "--switch ovs,protocols=OpenFlow13"
514 topoResult = main.Mininet1.startNet( topoFile=main.dependencyPath +
515 main.topology,
516 args=args )
517 stepResult = topoResult
518 utilities.assert_equals( expect=main.TRUE,
519 actual=stepResult,
520 onpass="Successfully loaded topology",
521 onfail="Failed to load topology" )
522 # Exit if topology did not load properly
523 if not topoResult:
524 main.cleanup()
525 main.exit()
526
527 def CASE12( self, main ):
528 """
529 Assign mastership to controllers
530 """
531 import re
532
533 main.case( "Assign switches to controllers" )
534 main.step( "Assigning switches to controllers" )
535 main.caseExplanation = "Assign OF " + main.OFProtocol +\
536 " switches to ONOS nodes"
537
538 assignResult = main.TRUE
539 switchList = []
540
541 # Creates a list switch name, use getSwitch() function later...
542 for i in range( 1, ( main.numSwitch + 1 ) ):
543 switchList.append( 's' + str( i ) )
544
545 tempONOSip = []
546 for i in range( main.numCtrls ):
547 tempONOSip.append( main.ONOSip[ i ] )
548
549 assignResult = main.Mininet1.assignSwController( sw=switchList,
550 ip=tempONOSip,
Charles Chan029be652015-08-24 01:46:10 +0800551 port='6653' )
kelvin-onlab44147802015-07-27 17:57:31 -0700552 if not assignResult:
553 main.cleanup()
554 main.exit()
555
556 for i in range( 1, ( main.numSwitch + 1 ) ):
557 response = main.Mininet1.getSwController( "s" + str( i ) )
558 print( "Response is " + str( response ) )
559 if re.search( "tcp:" + main.ONOSip[ 0 ], response ):
560 assignResult = assignResult and main.TRUE
561 else:
562 assignResult = main.FALSE
563 stepResult = assignResult
564 utilities.assert_equals( expect=main.TRUE,
565 actual=stepResult,
566 onpass="Successfully assigned switches" +
567 "to controller",
568 onfail="Failed to assign switches to " +
569 "controller" )
Jeremy2f190ca2016-01-29 15:23:57 -0800570
571 def CASE13( self,main ):
572 """
573 Create Scapy components
574 """
575 main.case( "Create scapy components" )
576 main.step( "Create scapy components" )
577 import json
578 scapyResult = main.TRUE
579 for hostName in main.scapyHostNames:
580 main.Scapy1.createHostComponent( hostName )
581 main.scapyHosts.append( getattr( main, hostName ) )
582
583 main.step( "Start scapy components" )
584 for host in main.scapyHosts:
585 host.startHostCli()
586 host.startScapy()
587 host.updateSelf()
588 main.log.debug( host.name )
589 main.log.debug( host.hostIp )
590 main.log.debug( host.hostMac )
591
592
593 utilities.assert_equals( expect=main.TRUE,
594 actual=scapyResult,
595 onpass="Successfully created Scapy Components",
596 onfail="Failed to discover Scapy Components" )
597
598 def CASE14( self, main ):
kelvin-onlab44147802015-07-27 17:57:31 -0700599 """
600 Discover all hosts and store its data to a dictionary
601 """
602 main.case( "Discover all hosts" )
603
604 stepResult = main.TRUE
kelvin-onlab0e684682015-08-11 18:51:41 -0700605 main.step( "Discover all ipv4 host hosts " )
606 hostList = []
607 # List of host with default vlan
608 defaultHosts = [ "h1", "h3", "h8", "h9", "h11", "h16", "h17", "h19", "h24" ]
609 # Lists of host with unique vlan
610 vlanHosts1 = [ "h4", "h12", "h20" ]
611 vlanHosts2 = [ "h5", "h13", "h21" ]
612 vlanHosts3 = [ "h6", "h14", "h22" ]
613 vlanHosts4 = [ "h7", "h15", "h23" ]
614 hostList.append( defaultHosts )
615 hostList.append( vlanHosts1 )
616 hostList.append( vlanHosts2 )
617 hostList.append( vlanHosts3 )
618 hostList.append( vlanHosts4 )
619
620 stepResult = main.intentFunction.getHostsData( main, hostList )
kelvin-onlab44147802015-07-27 17:57:31 -0700621 utilities.assert_equals( expect=main.TRUE,
622 actual=stepResult,
623 onpass="Successfully discovered hosts",
624 onfail="Failed to discover hosts" )
625
Jeremy2f190ca2016-01-29 15:23:57 -0800626 def CASE15( self, main ):
kelvin-onlab44147802015-07-27 17:57:31 -0700627 """
Jeremy2f190ca2016-01-29 15:23:57 -0800628 Discover all hosts with scapy arp packets and store its data to a dictionary
kelvin-onlab44147802015-07-27 17:57:31 -0700629 """
Jeremy2f190ca2016-01-29 15:23:57 -0800630 main.case( "Discover all hosts using scapy" )
631 main.step( "Send packets from each host to the first host and confirm onos discovery" )
632
633 import collections
634 if len( main.scapyHosts ) < 1:
635 main.log.error( "No scapy hosts have been created" )
636 main.skipCase()
637
638 # Send ARP packets from each scapy host component
639 main.intentFunction.sendDiscoveryArp( main, main.scapyHosts )
640
641 stepResult = utilities.retry( f=main.intentFunction.confirmHostDiscovery,
642 retValue=main.FALSE, args=[ main ],
643 attempts=main.checkTopoAttempts, sleep=2 )
644
645 utilities.assert_equals( expect=main.TRUE,
646 actual=stepResult,
647 onpass="ONOS correctly discovered all hosts",
648 onfail="ONOS incorrectly discovered hosts" )
649
650 main.step( "Populate hostsData" )
651 stepResult = main.intentFunction.populateHostData( main )
652 utilities.assert_equals( expect=main.TRUE,
653 actual=stepResult,
654 onpass="Successfully populated hostsData",
655 onfail="Failed to populate hostsData" )
656
657 def CASE16( self, main ):
658 """
Jeremy42df2e72016-02-23 16:37:46 -0800659 Balance Masters
660 """
661 main.case( "Balance mastership of switches" )
662 main.step( "Balancing mastership of switches" )
663
664 balanceResult = main.FALSE
665 balanceResult = utilities.retry( f=main.CLIs2[ 0 ].balanceMasters, retValue=main.FALSE, args=[] )
666
667 utilities.assert_equals( expect=main.TRUE,
668 actual=stepResult,
669 onpass="Successfully balanced mastership of switches",
670 onfail="Failed to balance mastership of switches" )
671
672 def CASE17( self, main ):
673 """
Jeremy2f190ca2016-01-29 15:23:57 -0800674 Stop mininet and remove scapy hosts
675 """
676 main.log.report( "Stop Mininet and Scapy" )
677 main.case( "Stop Mininet and Scapy" )
kelvin-onlab44147802015-07-27 17:57:31 -0700678 main.caseExplanation = "Stopping the current mininet topology " +\
679 "to start up fresh"
680
Jeremy2f190ca2016-01-29 15:23:57 -0800681 main.step( "Stopping and Removing Scapy Host Components" )
682 scapyResult = main.TRUE
683 for host in main.scapyHosts:
684 scapyResult = scapyResult and host.stopScapy()
685 main.log.info( "Stopped Scapy Host: {0}".format( host.name ) )
686
687 for host in main.scapyHosts:
688 scapyResult = scapyResult and main.Scapy1.removeHostComponent( host.name )
689 main.log.info( "Removed Scapy Host Component: {0}".format( host.name ) )
690
691 main.scapyHosts = []
692 main.scapyHostIPs = []
693
694 utilities.assert_equals( expect=main.TRUE,
695 actual=scapyResult,
696 onpass="Successfully stopped scapy and removed host components",
697 onfail="Failed to stop mininet and scapy" )
698
kelvin-onlab44147802015-07-27 17:57:31 -0700699 main.step( "Stopping Mininet Topology" )
Jeremy2f190ca2016-01-29 15:23:57 -0800700 mininetResult = main.Mininet1.stopNet( )
701
kelvin-onlab44147802015-07-27 17:57:31 -0700702 utilities.assert_equals( expect=main.TRUE,
703 actual=stepResult,
704 onpass="Successfully stop mininet",
705 onfail="Failed to stop mininet" )
706 # Exit if topology did not load properly
Jeremy2f190ca2016-01-29 15:23:57 -0800707 if not (mininetResult and scapyResult ):
kelvin-onlab44147802015-07-27 17:57:31 -0700708 main.cleanup()
709 main.exit()
710
711 def CASE1000( self, main ):
712 """
713 Add host intents between 2 host:
714 - Discover hosts
715 - Add host intents
716 - Check intents
717 - Verify flows
718 - Ping hosts
719 - Reroute
720 - Link down
721 - Verify flows
722 - Check topology
723 - Ping hosts
724 - Link up
725 - Verify flows
726 - Check topology
727 - Ping hosts
728 - Remove intents
729 """
730 import time
731 import json
732 import re
733
734 # Assert variables - These variable's name|format must be followed
735 # if you want to use the wrapper function
736 assert main, "There is no main"
737 assert main.CLIs, "There is no main.CLIs"
738 assert main.Mininet1, "Mininet handle should be named Mininet1"
739 assert main.numSwitch, "Placed the total number of switch topology in \
740 main.numSwitch"
741
Jeremye1ea0602016-02-08 16:35:05 -0800742 # Save leader candidates
743 intentLeadersOld = main.CLIs2[ 0 ].leaderCandidates()
744
kelvin-onlab44147802015-07-27 17:57:31 -0700745 main.case( "Host Intents Test - " + str( main.numCtrls ) +
746 " NODE(S) - OF " + main.OFProtocol )
747 main.caseExplanation = "This test case tests Host intents using " +\
748 str( main.numCtrls ) + " node(s) cluster;\n" +\
749 "Different type of hosts will be tested in " +\
750 "each step such as IPV4, Dual stack, VLAN " +\
751 "etc;\nThe test will use OF " + main.OFProtocol\
752 + " OVS running in Mininet"
753
Jeremy2f190ca2016-01-29 15:23:57 -0800754 main.step( "IPV4: Add and test host intents between h1 and h9" )
755 main.assertReturnString = "Assertion result for IPV4 host intent with mac addresses\n"
756 host1 = { "name":"h1","id":"00:00:00:00:00:01/-1" }
757 host2 = { "name":"h9","id":"00:00:00:00:00:09/-1" }
758 testResult = main.FALSE
759 installResult = main.intentFunction.installHostIntent( main,
kelvin-onlab44147802015-07-27 17:57:31 -0700760 name='IPV4',
Jeremy2f190ca2016-01-29 15:23:57 -0800761 onosNode='0',
762 host1=host1,
763 host2=host2 )
764
765 if installResult:
766 testResult = main.intentFunction.testHostIntent( main,
767 name='IPV4',
768 intentId = installResult,
769 onosNode='0',
770 host1=host1,
771 host2=host2,
kelvin-onlab44147802015-07-27 17:57:31 -0700772 sw1='s5',
773 sw2='s2',
Jeremy2f190ca2016-01-29 15:23:57 -0800774 expectedLink = 18 )
kelvin-onlab44147802015-07-27 17:57:31 -0700775
776 utilities.assert_equals( expect=main.TRUE,
Jeremy2f190ca2016-01-29 15:23:57 -0800777 actual=testResult,
778 onpass=main.assertReturnString,
779 onfail=main.assertReturnString )
kelvin-onlab44147802015-07-27 17:57:31 -0700780
781 main.step( "DUALSTACK1: Add host intents between h3 and h11" )
Jeremy2f190ca2016-01-29 15:23:57 -0800782 main.assertReturnString = "Assertion Result for dualstack IPV4 with MAC addresses\n"
783 host1 = { "name":"h3", "id":"00:00:00:00:00:03/-1" }
784 host2 = { "name":"h11","id":"00:00:00:00:00:0B/-1"}
785 testResult = main.FALSE
786 installResult = main.intentFunction.installHostIntent( main,
787 name='DUALSTACK1',
788 onosNode='0',
789 host1=host1,
790 host2=host2 )
791
792 if installResult:
793 testResult = main.intentFunction.testHostIntent( main,
794 name='DUALSTACK1',
795 intentId = installResult,
796 onosNode='0',
797 host1=host1,
798 host2=host2,
kelvin-onlab44147802015-07-27 17:57:31 -0700799 sw1='s5',
800 sw2='s2',
Jeremy2f190ca2016-01-29 15:23:57 -0800801 expectedLink = 18 )
kelvin-onlab44147802015-07-27 17:57:31 -0700802
803 utilities.assert_equals( expect=main.TRUE,
Jeremy2f190ca2016-01-29 15:23:57 -0800804 actual=testResult,
805 onpass=main.assertReturnString,
806 onfail=main.assertReturnString)
kelvin-onlab44147802015-07-27 17:57:31 -0700807
808 main.step( "DUALSTACK2: Add host intents between h1 and h11" )
Jeremy2f190ca2016-01-29 15:23:57 -0800809 main.assertReturnString = "Assertion Result for dualstack2 host intent\n"
810 host1 = { "name":"h1" }
811 host2 = { "name":"h11" }
812 testResult = main.FALSE
813 installResult = main.intentFunction.installHostIntent( main,
kelvin-onlab44147802015-07-27 17:57:31 -0700814 name='DUALSTACK2',
Jeremy2f190ca2016-01-29 15:23:57 -0800815 onosNode='0',
816 host1=host1,
817 host2=host2 )
818
819 if installResult:
820 testResult = main.intentFunction.testHostIntent( main,
821 name='DUALSTACK2',
822 intentId = installResult,
823 onosNode='0',
824 host1=host1,
825 host2=host2,
kelvin-onlab44147802015-07-27 17:57:31 -0700826 sw1='s5',
827 sw2='s2',
Jeremy2f190ca2016-01-29 15:23:57 -0800828 expectedLink = 18 )
kelvin-onlab44147802015-07-27 17:57:31 -0700829
830 utilities.assert_equals( expect=main.TRUE,
Jeremy2f190ca2016-01-29 15:23:57 -0800831 actual=testResult,
832 onpass=main.assertReturnString,
833 onfail=main.assertReturnString )
kelvin-onlab44147802015-07-27 17:57:31 -0700834
835 main.step( "1HOP: Add host intents between h1 and h3" )
Jeremy2f190ca2016-01-29 15:23:57 -0800836 main.assertReturnString = "Assertion Result for 1HOP for IPV4 same switch\n"
837 host1 = { "name":"h1" }
838 host2 = { "name":"h3" }
839 testResult = main.FALSE
840 installResult = main.intentFunction.installHostIntent( main,
kelvin-onlab44147802015-07-27 17:57:31 -0700841 name='1HOP',
Jeremy2f190ca2016-01-29 15:23:57 -0800842 onosNode='0',
843 host1=host1,
844 host2=host2 )
kelvin-onlab44147802015-07-27 17:57:31 -0700845
Jeremy2f190ca2016-01-29 15:23:57 -0800846 if installResult:
847 testResult = main.intentFunction.testHostIntent( main,
848 name='1HOP',
849 intentId = installResult,
850 onosNode='0',
851 host1=host1,
852 host2=host2,
kelvin-onlab44147802015-07-27 17:57:31 -0700853 sw1='s5',
854 sw2='s2',
Jeremy2f190ca2016-01-29 15:23:57 -0800855 expectedLink = 18 )
kelvin-onlab44147802015-07-27 17:57:31 -0700856
857 utilities.assert_equals( expect=main.TRUE,
Jeremy2f190ca2016-01-29 15:23:57 -0800858 actual=testResult,
859 onpass=main.assertReturnString,
860 onfail=main.assertReturnString )
861
862 main.step( "VLAN1: Add vlan host intents between h4 and h12" )
863 main.assertReturnString = "Assertion Result vlan IPV4\n"
864 host1 = { "name":"h4","id":"00:00:00:00:00:04/100" }
865 host2 = { "name":"h12","id":"00:00:00:00:00:0C/100" }
866 testResult = main.FALSE
867 installResult = main.intentFunction.installHostIntent( main,
868 name='VLAN1',
869 onosNode='0',
870 host1=host1,
871 host2=host2 )
872
873 if installResult:
874 testResult = main.intentFunction.testHostIntent( main,
875 name='VLAN1',
876 intentId = installResult,
877 onosNode='0',
878 host1=host1,
879 host2=host2,
880 sw1='s5',
881 sw2='s2',
882 expectedLink = 18 )
883
884 utilities.assert_equals( expect=main.TRUE,
885 actual=testResult,
886 onpass=main.assertReturnString,
887 onfail=main.assertReturnString )
kelvin-onlab44147802015-07-27 17:57:31 -0700888
889 main.step( "VLAN2: Add inter vlan host intents between h13 and h20" )
Jeremy2f190ca2016-01-29 15:23:57 -0800890 main.assertReturnString = "Assertion Result different VLAN negative test\n"
891 host1 = { "name":"h13" }
892 host2 = { "name":"h20" }
893 testResult = main.FALSE
894 installResult = main.intentFunction.installHostIntent( main,
kelvin-onlab44147802015-07-27 17:57:31 -0700895 name='VLAN2',
Jeremy2f190ca2016-01-29 15:23:57 -0800896 onosNode='0',
897 host1=host1,
898 host2=host2 )
kelvin-onlab44147802015-07-27 17:57:31 -0700899
Jeremy2f190ca2016-01-29 15:23:57 -0800900 if installResult:
901 testResult = main.intentFunction.testHostIntent( main,
902 name='VLAN2',
903 intentId = installResult,
904 onosNode='0',
905 host1=host1,
906 host2=host2,
907 sw1='s5',
908 sw2='s2',
909 expectedLink = 18 )
kelvin-onlab44147802015-07-27 17:57:31 -0700910
Jeremy2f190ca2016-01-29 15:23:57 -0800911 utilities.assert_equals( expect=main.TRUE,
912 actual=testResult,
913 onpass=main.assertReturnString,
914 onfail=main.assertReturnString )
915
Jeremye1ea0602016-02-08 16:35:05 -0800916 # Change the following to use the REST API when leader checking is
917 # supported by it
Jeremy2f190ca2016-01-29 15:23:57 -0800918
Jeremye1ea0602016-02-08 16:35:05 -0800919 main.step( "Confirm that ONOS leadership is unchanged")
920 intentLeadersNew = main.CLIs2[ 0 ].leaderCandidates()
921 main.intentFunction.checkLeaderChange( intentLeadersOld,
922 intentLeadersNew )
Jeremy2f190ca2016-01-29 15:23:57 -0800923
Jeremye1ea0602016-02-08 16:35:05 -0800924 utilities.assert_equals( expect=main.TRUE,
925 actual=testResult,
926 onpass="ONOS Leaders Unchanged",
927 onfail="ONOS Leader Mismatch")
Jeremy2f190ca2016-01-29 15:23:57 -0800928
929 main.intentFunction.report( main )
kelvin-onlab44147802015-07-27 17:57:31 -0700930
931 def CASE2000( self, main ):
932 """
933 Add point intents between 2 hosts:
934 - Get device ids | ports
935 - Add point intents
936 - Check intents
937 - Verify flows
938 - Ping hosts
939 - Reroute
940 - Link down
941 - Verify flows
942 - Check topology
943 - Ping hosts
944 - Link up
945 - Verify flows
946 - Check topology
947 - Ping hosts
948 - Remove intents
949 """
950 import time
951 import json
952 import re
953
954 # Assert variables - These variable's name|format must be followed
955 # if you want to use the wrapper function
956 assert main, "There is no main"
957 assert main.CLIs, "There is no main.CLIs"
958 assert main.Mininet1, "Mininet handle should be named Mininet1"
959 assert main.numSwitch, "Placed the total number of switch topology in \
960 main.numSwitch"
961
962 main.case( "Point Intents Test - " + str( main.numCtrls ) +
963 " NODE(S) - OF " + main.OFProtocol )
964 main.caseExplanation = "This test case will test point to point" +\
965 " intents using " + str( main.numCtrls ) +\
966 " node(s) cluster;\n" +\
967 "Different type of hosts will be tested in " +\
968 "each step such as IPV4, Dual stack, VLAN etc" +\
969 ";\nThe test will use OF " + main.OFProtocol +\
970 " OVS running in Mininet"
971
972 # No option point intents
973 main.step( "NOOPTION: Add point intents between h1 and h9" )
Jeremy2f190ca2016-01-29 15:23:57 -0800974 main.assertReturnString = "Assertion Result for NOOPTION point intent\n"
975 senders = [
976 { "name":"h1","device":"of:0000000000000005/1" }
977 ]
978 recipients = [
979 { "name":"h9","device":"of:0000000000000006/1" }
980 ]
981 testResult = main.FALSE
982 installResult = main.intentFunction.installPointIntent(
kelvin-onlab44147802015-07-27 17:57:31 -0700983 main,
984 name="NOOPTION",
Jeremy2f190ca2016-01-29 15:23:57 -0800985 senders=senders,
986 recipients=recipients )
987
988 if installResult:
989 testResult = main.intentFunction.testPointIntent(
990 main,
991 intentId=installResult,
992 name="NOOPTION",
993 senders=senders,
994 recipients=recipients,
995 sw1="s5",
996 sw2="s2",
997 expectedLink=18)
kelvin-onlab44147802015-07-27 17:57:31 -0700998
999 utilities.assert_equals( expect=main.TRUE,
Jeremy2f190ca2016-01-29 15:23:57 -08001000 actual=testResult,
1001 onpass=main.assertReturnString,
1002 onfail=main.assertReturnString )
kelvin-onlab44147802015-07-27 17:57:31 -07001003
kelvin-onlab44147802015-07-27 17:57:31 -07001004 main.step( "IPV4: Add point intents between h1 and h9" )
Jeremy2f190ca2016-01-29 15:23:57 -08001005 main.assertReturnString = "Assertion Result for IPV4 point intent\n"
1006 senders = [
1007 { "name":"h1","device":"of:0000000000000005/1","mac":"00:00:00:00:00:01" }
1008 ]
1009 recipients = [
1010 { "name":"h9","device":"of:0000000000000006/1","mac":"00:00:00:00:00:09" }
1011 ]
1012 installResult = main.intentFunction.installPointIntent(
kelvin-onlab44147802015-07-27 17:57:31 -07001013 main,
1014 name="IPV4",
Jeremy2f190ca2016-01-29 15:23:57 -08001015 senders=senders,
1016 recipients=recipients,
1017 ethType="IPV4" )
1018
1019 if installResult:
1020 testResult = main.intentFunction.testPointIntent(
1021 main,
1022 intentId=installResult,
1023 name="IPV4",
1024 senders=senders,
1025 recipients=recipients,
1026 sw1="s5",
1027 sw2="s2",
1028 expectedLink=18)
kelvin-onlab44147802015-07-27 17:57:31 -07001029
1030 utilities.assert_equals( expect=main.TRUE,
Jeremy2f190ca2016-01-29 15:23:57 -08001031 actual=testResult,
1032 onpass=main.assertReturnString,
1033 onfail=main.assertReturnString )
kelvin-onlab44147802015-07-27 17:57:31 -07001034 main.step( "IPV4_2: Add point intents between h1 and h9" )
Jeremy2f190ca2016-01-29 15:23:57 -08001035 main.assertReturnString = "Assertion Result for IPV4 no mac address point intents\n"
1036 senders = [
1037 { "name":"h1","device":"of:0000000000000005/1" }
1038 ]
1039 recipients = [
1040 { "name":"h9","device":"of:0000000000000006/1" }
1041 ]
1042 installResult = main.intentFunction.installPointIntent(
kelvin-onlab44147802015-07-27 17:57:31 -07001043 main,
1044 name="IPV4_2",
Jeremy2f190ca2016-01-29 15:23:57 -08001045 senders=senders,
1046 recipients=recipients,
1047 ethType="IPV4" )
1048
1049 if installResult:
1050 testResult = main.intentFunction.testPointIntent(
1051 main,
1052 intentId=installResult,
1053 name="IPV4_2",
1054 senders=senders,
1055 recipients=recipients,
1056 sw1="s5",
1057 sw2="s2",
1058 expectedLink=18)
kelvin-onlab44147802015-07-27 17:57:31 -07001059
1060 utilities.assert_equals( expect=main.TRUE,
Jeremy2f190ca2016-01-29 15:23:57 -08001061 actual=testResult,
1062 onpass=main.assertReturnString,
1063 onfail=main.assertReturnString )
kelvin-onlab44147802015-07-27 17:57:31 -07001064
kelvin-onlab0e684682015-08-11 18:51:41 -07001065 main.step( "SDNIP-ICMP: Add point intents between h1 and h9" )
Jeremy2f190ca2016-01-29 15:23:57 -08001066 main.assertReturnString = "Assertion Result for SDNIP-ICMP IPV4 using TCP point intents\n"
1067 senders = [
1068 { "name":"h1","device":"of:0000000000000005/1","mac":"00:00:00:00:00:01",
1069 "ip":main.h1.hostIp }
1070 ]
1071 recipients = [
1072 { "name":"h9","device":"of:0000000000000006/1","mac":"00:00:00:00:00:09",
1073 "ip":main.h9.hostIp }
1074 ]
kelvin-onlab44147802015-07-27 17:57:31 -07001075 ipProto = main.params[ 'SDNIP' ][ 'icmpProto' ]
1076 # Uneccessary, not including this in the selectors
Jeremy2f190ca2016-01-29 15:23:57 -08001077 tcpSrc = main.params[ 'SDNIP' ][ 'srcPort' ]
1078 tcpDst = main.params[ 'SDNIP' ][ 'dstPort' ]
kelvin-onlab44147802015-07-27 17:57:31 -07001079
Jeremy2f190ca2016-01-29 15:23:57 -08001080 installResult = main.intentFunction.installPointIntent(
1081 main,
1082 name="SDNIP-ICMP",
1083 senders=senders,
1084 recipients=recipients,
1085 ethType="IPV4",
1086 ipProto=ipProto,
1087 tcpSrc=tcpSrc,
1088 tcpDst=tcpDst )
1089
1090 if installResult:
1091 testResult = main.intentFunction.testPointIntent(
1092 main,
1093 intentId=installResult,
1094 name="SDNIP_ICMP",
1095 senders=senders,
1096 recipients=recipients,
1097 sw1="s5",
1098 sw2="s2",
1099 expectedLink=18)
kelvin-onlab44147802015-07-27 17:57:31 -07001100
1101 utilities.assert_equals( expect=main.TRUE,
Jeremy2f190ca2016-01-29 15:23:57 -08001102 actual=testResult,
1103 onpass=main.assertReturnString,
1104 onfail=main.assertReturnString )
kelvin-onlab44147802015-07-27 17:57:31 -07001105
kelvin-onlab0e684682015-08-11 18:51:41 -07001106 main.step( "SDNIP-TCP: Add point intents between h1 and h9" )
Jeremy2f190ca2016-01-29 15:23:57 -08001107 main.assertReturnString = "Assertion Result for SDNIP-TCP IPV4 using ICMP point intents\n"
kelvin-onlab44147802015-07-27 17:57:31 -07001108 mac1 = main.hostsData[ 'h1' ][ 'mac' ]
1109 mac2 = main.hostsData[ 'h9' ][ 'mac' ]
kelvin-onlab0e684682015-08-11 18:51:41 -07001110 ip1 = str( main.hostsData[ 'h1' ][ 'ipAddresses' ][ 0 ] ) + "/32"
1111 ip2 = str( main.hostsData[ 'h9' ][ 'ipAddresses' ][ 0 ] ) + "/32"
kelvin-onlab44147802015-07-27 17:57:31 -07001112 ipProto = main.params[ 'SDNIP' ][ 'tcpProto' ]
1113 tcp1 = main.params[ 'SDNIP' ][ 'srcPort' ]
1114 tcp2 = main.params[ 'SDNIP' ][ 'dstPort' ]
1115
kelvin-onlab0e684682015-08-11 18:51:41 -07001116 stepResult = main.intentFunction.pointIntentTcp(
kelvin-onlab44147802015-07-27 17:57:31 -07001117 main,
kelvin-onlab0e684682015-08-11 18:51:41 -07001118 name="SDNIP-TCP",
kelvin-onlab44147802015-07-27 17:57:31 -07001119 host1="h1",
1120 host2="h9",
1121 deviceId1="of:0000000000000005/1",
1122 deviceId2="of:0000000000000006/1",
1123 mac1=mac1,
1124 mac2=mac2,
1125 ethType="IPV4",
kelvin-onlab0e684682015-08-11 18:51:41 -07001126 ipProto=ipProto,
1127 ip1=ip1,
1128 ip2=ip2,
1129 tcp1=tcp1,
1130 tcp2=tcp2 )
kelvin-onlab44147802015-07-27 17:57:31 -07001131
1132 utilities.assert_equals( expect=main.TRUE,
1133 actual=stepResult,
Jeremy2f190ca2016-01-29 15:23:57 -08001134 onpass=main.assertReturnString,
1135 onfail=main.assertReturnString )
kelvin-onlab44147802015-07-27 17:57:31 -07001136
Jeremy2f190ca2016-01-29 15:23:57 -08001137 main.step( "DUALSTACK1: Add point intents between h3 and h11" )
1138 main.assertReturnString = "Assertion Result for Dualstack1 IPV4 with mac address point intents\n"
1139 senders = [
1140 { "name":"h3","device":"of:0000000000000005/3","mac":"00:00:00:00:00:03" }
1141 ]
1142 recipients = [
1143 { "name":"h11","device":"of:0000000000000006/3","mac":"00:00:00:00:00:0B" }
1144 ]
1145 installResult = main.intentFunction.installPointIntent(
kelvin-onlab44147802015-07-27 17:57:31 -07001146 main,
1147 name="DUALSTACK1",
Jeremy2f190ca2016-01-29 15:23:57 -08001148 senders=senders,
1149 recipients=recipients,
1150 ethType="IPV4" )
1151
1152 if installResult:
1153 testResult = main.intentFunction.testPointIntent(
1154 main,
1155 intentId=installResult,
1156 name="DUALSTACK1",
1157 senders=senders,
1158 recipients=recipients,
1159 sw1="s5",
1160 sw2="s2",
1161 expectedLink=18)
kelvin-onlab44147802015-07-27 17:57:31 -07001162
1163 utilities.assert_equals( expect=main.TRUE,
Jeremy2f190ca2016-01-29 15:23:57 -08001164 actual=testResult,
1165 onpass=main.assertReturnString,
1166 onfail=main.assertReturnString )
kelvin-onlab44147802015-07-27 17:57:31 -07001167
1168 main.step( "VLAN: Add point intents between h5 and h21" )
Jeremy2f190ca2016-01-29 15:23:57 -08001169 main.assertReturnString = "Assertion Result for VLAN IPV4 with mac address point intents\n"
1170 senders = [
1171 { "name":"h5","device":"of:0000000000000005/5","mac":"00:00:00:00:00:05" }
1172 ]
1173 recipients = [
1174 { "name":"h21","device":"of:0000000000000007/5","mac":"00:00:00:00:00:15" }
1175 ]
1176 installResult = main.intentFunction.installPointIntent(
kelvin-onlab44147802015-07-27 17:57:31 -07001177 main,
Jeremy2f190ca2016-01-29 15:23:57 -08001178 name="DUALSTACK1",
1179 senders=senders,
1180 recipients=recipients,
1181 ethType="IPV4" )
1182
1183 if installResult:
1184 testResult = main.intentFunction.testPointIntent(
1185 main,
1186 intentId=installResult,
1187 name="DUALSTACK1",
1188 senders=senders,
1189 recipients=recipients,
1190 sw1="s5",
1191 sw2="s2",
1192 expectedLink=18)
kelvin-onlab44147802015-07-27 17:57:31 -07001193
1194 utilities.assert_equals( expect=main.TRUE,
Jeremy2f190ca2016-01-29 15:23:57 -08001195 actual=testResult,
1196 onpass=main.assertReturnString,
1197 onfail=main.assertReturnString )
kelvin-onlab44147802015-07-27 17:57:31 -07001198
1199 main.step( "1HOP: Add point intents between h1 and h3" )
Jeremy2f190ca2016-01-29 15:23:57 -08001200 main.assertReturnString = "Assertion Result for 1HOP IPV4 with no mac address point intents\n"
1201 senders = [
1202 { "name":"h1","device":"of:0000000000000005/1","mac":"00:00:00:00:00:01" }
1203 ]
1204 recipients = [
1205 { "name":"h3","device":"of:0000000000000005/3","mac":"00:00:00:00:00:03" }
1206 ]
1207 installResult = main.intentFunction.installPointIntent(
1208 main,
1209 name="1HOP IPV4",
1210 senders=senders,
1211 recipients=recipients,
1212 ethType="IPV4" )
1213
1214 if installResult:
1215 testResult = main.intentFunction.testPointIntent(
1216 main,
1217 intentId=installResult,
1218 name="1HOP IPV4",
1219 senders=senders,
1220 recipients=recipients,
1221 sw1="s5",
1222 sw2="s2",
1223 expectedLink=18)
kelvin-onlab44147802015-07-27 17:57:31 -07001224
1225 utilities.assert_equals( expect=main.TRUE,
Jeremy2f190ca2016-01-29 15:23:57 -08001226 actual=testResult,
1227 onpass=main.assertReturnString,
1228 onfail=main.assertReturnString )
1229
1230 main.intentFunction.report( main )
kelvin-onlab44147802015-07-27 17:57:31 -07001231
1232 def CASE3000( self, main ):
1233 """
1234 Add single point to multi point intents
1235 - Get device ids
1236 - Add single point to multi point intents
1237 - Check intents
1238 - Verify flows
1239 - Ping hosts
1240 - Reroute
1241 - Link down
1242 - Verify flows
1243 - Check topology
1244 - Ping hosts
1245 - Link up
1246 - Verify flows
1247 - Check topology
1248 - Ping hosts
1249 - Remove intents
1250 """
1251 assert main, "There is no main"
1252 assert main.CLIs, "There is no main.CLIs"
1253 assert main.Mininet1, "Mininet handle should be named Mininet1"
1254 assert main.numSwitch, "Placed the total number of switch topology in \
1255 main.numSwitch"
1256
1257 main.case( "Single To Multi Point Intents Test - " +
1258 str( main.numCtrls ) + " NODE(S) - OF " + main.OFProtocol )
1259 main.caseExplanation = "This test case will test single point to" +\
1260 " multi point intents using " +\
1261 str( main.numCtrls ) + " node(s) cluster;\n" +\
1262 "Different type of hosts will be tested in " +\
1263 "each step such as IPV4, Dual stack, VLAN etc" +\
1264 ";\nThe test will use OF " + main.OFProtocol +\
1265 " OVS running in Mininet"
1266
1267 main.step( "NOOPTION: Add single point to multi point intents" )
1268 stepResult = main.TRUE
1269 hostNames = [ 'h8', 'h16', 'h24' ]
1270 devices = [ 'of:0000000000000005/8', 'of:0000000000000006/8', \
1271 'of:0000000000000007/8' ]
1272 macs = [ '00:00:00:00:00:08', '00:00:00:00:00:10', '00:00:00:00:00:18' ]
1273 stepResult = main.intentFunction.singleToMultiIntent(
1274 main,
1275 name="NOOPTION",
1276 hostNames=hostNames,
1277 devices=devices,
1278 sw1="s5",
1279 sw2="s2",
1280 expectedLink=18 )
1281
1282 utilities.assert_equals( expect=main.TRUE,
1283 actual=stepResult,
1284 onpass="NOOPTION: Successfully added single "
1285 + " point to multi point intents" +
1286 " with no match action",
1287 onfail="NOOPTION: Failed to add single point"
1288 + " point to multi point intents" +
1289 " with no match action" )
1290
1291 main.step( "IPV4: Add single point to multi point intents" )
1292 stepResult = main.TRUE
1293 stepResult = main.intentFunction.singleToMultiIntent(
1294 main,
1295 name="IPV4",
1296 hostNames=hostNames,
1297 devices=devices,
1298 ports=None,
1299 ethType="IPV4",
1300 macs=macs,
1301 bandwidth="",
1302 lambdaAlloc=False,
1303 ipProto="",
1304 ipAddresses="",
1305 tcp="",
1306 sw1="s5",
1307 sw2="s2",
1308 expectedLink=18 )
1309
1310 utilities.assert_equals( expect=main.TRUE,
1311 actual=stepResult,
1312 onpass="IPV4: Successfully added single "
1313 + " point to multi point intents" +
1314 " with IPV4 type and MAC addresses",
1315 onfail="IPV4: Failed to add single point"
1316 + " point to multi point intents" +
1317 " with IPV4 type and MAC addresses" )
1318
1319 main.step( "IPV4_2: Add single point to multi point intents" )
1320 stepResult = main.TRUE
1321 hostNames = [ 'h8', 'h16', 'h24' ]
1322 stepResult = main.intentFunction.singleToMultiIntent(
1323 main,
1324 name="IPV4",
1325 hostNames=hostNames,
1326 ethType="IPV4",
1327 lambdaAlloc=False )
1328
1329 utilities.assert_equals( expect=main.TRUE,
1330 actual=stepResult,
1331 onpass="IPV4_2: Successfully added single "
1332 + " point to multi point intents" +
1333 " with IPV4 type and no MAC addresses",
1334 onfail="IPV4_2: Failed to add single point"
1335 + " point to multi point intents" +
1336 " with IPV4 type and no MAC addresses" )
1337
1338 main.step( "VLAN: Add single point to multi point intents" )
1339 stepResult = main.TRUE
1340 hostNames = [ 'h4', 'h12', 'h20' ]
1341 devices = [ 'of:0000000000000005/4', 'of:0000000000000006/4', \
1342 'of:0000000000000007/4' ]
1343 macs = [ '00:00:00:00:00:04', '00:00:00:00:00:0C', '00:00:00:00:00:14' ]
1344 stepResult = main.intentFunction.singleToMultiIntent(
1345 main,
1346 name="VLAN",
1347 hostNames=hostNames,
1348 devices=devices,
1349 ports=None,
1350 ethType="IPV4",
1351 macs=macs,
1352 bandwidth="",
1353 lambdaAlloc=False,
1354 ipProto="",
1355 ipAddresses="",
1356 tcp="",
1357 sw1="s5",
1358 sw2="s2",
1359 expectedLink=18 )
1360
1361 utilities.assert_equals( expect=main.TRUE,
1362 actual=stepResult,
1363 onpass="VLAN: Successfully added single "
1364 + " point to multi point intents" +
1365 " with IPV4 type and MAC addresses" +
1366 " in the same VLAN",
1367 onfail="VLAN: Failed to add single point"
1368 + " point to multi point intents" +
1369 " with IPV4 type and MAC addresses" +
1370 " in the same VLAN")
1371
1372 def CASE4000( self, main ):
1373 """
1374 Add multi point to single point intents
1375 - Get device ids
1376 - Add multi point to single point intents
1377 - Check intents
1378 - Verify flows
1379 - Ping hosts
1380 - Reroute
1381 - Link down
1382 - Verify flows
1383 - Check topology
1384 - Ping hosts
1385 - Link up
1386 - Verify flows
1387 - Check topology
1388 - Ping hosts
1389 - Remove intents
1390 """
1391 assert main, "There is no main"
1392 assert main.CLIs, "There is no main.CLIs"
1393 assert main.Mininet1, "Mininet handle should be named Mininet1"
1394 assert main.numSwitch, "Placed the total number of switch topology in \
1395 main.numSwitch"
1396
1397 main.case( "Multi To Single Point Intents Test - " +
1398 str( main.numCtrls ) + " NODE(S) - OF " + main.OFProtocol )
1399 main.caseExplanation = "This test case will test single point to" +\
1400 " multi point intents using " +\
1401 str( main.numCtrls ) + " node(s) cluster;\n" +\
1402 "Different type of hosts will be tested in " +\
1403 "each step such as IPV4, Dual stack, VLAN etc" +\
1404 ";\nThe test will use OF " + main.OFProtocol +\
1405 " OVS running in Mininet"
1406
1407 main.step( "NOOPTION: Add multi point to single point intents" )
1408 stepResult = main.TRUE
1409 hostNames = [ 'h8', 'h16', 'h24' ]
1410 devices = [ 'of:0000000000000005/8', 'of:0000000000000006/8', \
1411 'of:0000000000000007/8' ]
1412 macs = [ '00:00:00:00:00:08', '00:00:00:00:00:10', '00:00:00:00:00:18' ]
1413 stepResult = main.intentFunction.multiToSingleIntent(
1414 main,
1415 name="NOOPTION",
1416 hostNames=hostNames,
1417 devices=devices,
1418 sw1="s5",
1419 sw2="s2",
1420 expectedLink=18 )
1421
1422 utilities.assert_equals( expect=main.TRUE,
1423 actual=stepResult,
1424 onpass="NOOPTION: Successfully added multi "
1425 + " point to single point intents" +
1426 " with no match action",
1427 onfail="NOOPTION: Failed to add multi point" +
1428 " to single point intents" +
1429 " with no match action" )
1430
1431 main.step( "IPV4: Add multi point to single point intents" )
1432 stepResult = main.TRUE
1433 stepResult = main.intentFunction.multiToSingleIntent(
1434 main,
1435 name="IPV4",
1436 hostNames=hostNames,
1437 devices=devices,
1438 ports=None,
1439 ethType="IPV4",
1440 macs=macs,
1441 bandwidth="",
1442 lambdaAlloc=False,
1443 ipProto="",
1444 ipAddresses="",
1445 tcp="",
1446 sw1="s5",
1447 sw2="s2",
1448 expectedLink=18 )
1449
1450 utilities.assert_equals( expect=main.TRUE,
1451 actual=stepResult,
1452 onpass="IPV4: Successfully added multi point"
1453 + " to single point intents" +
1454 " with IPV4 type and MAC addresses",
1455 onfail="IPV4: Failed to add multi point" +
1456 " to single point intents" +
1457 " with IPV4 type and MAC addresses" )
1458
1459 main.step( "IPV4_2: Add multi point to single point intents" )
1460 stepResult = main.TRUE
1461 hostNames = [ 'h8', 'h16', 'h24' ]
1462 stepResult = main.intentFunction.multiToSingleIntent(
1463 main,
1464 name="IPV4",
1465 hostNames=hostNames,
1466 ethType="IPV4",
1467 lambdaAlloc=False )
1468
1469 utilities.assert_equals( expect=main.TRUE,
1470 actual=stepResult,
1471 onpass="IPV4_2: Successfully added multi point"
1472 + " to single point intents" +
1473 " with IPV4 type and no MAC addresses",
1474 onfail="IPV4_2: Failed to add multi point" +
1475 " to single point intents" +
1476 " with IPV4 type and no MAC addresses" )
1477
1478 main.step( "VLAN: Add multi point to single point intents" )
1479 stepResult = main.TRUE
1480 hostNames = [ 'h5', 'h13', 'h21' ]
1481 devices = [ 'of:0000000000000005/5', 'of:0000000000000006/5', \
1482 'of:0000000000000007/5' ]
1483 macs = [ '00:00:00:00:00:05', '00:00:00:00:00:0D', '00:00:00:00:00:15' ]
1484 stepResult = main.intentFunction.multiToSingleIntent(
1485 main,
1486 name="VLAN",
1487 hostNames=hostNames,
1488 devices=devices,
1489 ports=None,
1490 ethType="IPV4",
1491 macs=macs,
1492 bandwidth="",
1493 lambdaAlloc=False,
1494 ipProto="",
1495 ipAddresses="",
1496 tcp="",
1497 sw1="s5",
1498 sw2="s2",
1499 expectedLink=18 )
1500
1501 utilities.assert_equals( expect=main.TRUE,
1502 actual=stepResult,
1503 onpass="VLAN: Successfully added multi point"
1504 + " to single point intents" +
1505 " with IPV4 type and MAC addresses" +
1506 " in the same VLAN",
1507 onfail="VLAN: Failed to add multi point" +
1508 " to single point intents" )
1509
1510 def CASE5000( self, main ):
Jeremy2f190ca2016-01-29 15:23:57 -08001511 # """
1512 # Will add description in next patch set
1513 # """
1514 # assert main, "There is no main"
1515 # assert main.CLIs, "There is no main.CLIs"
1516 # assert main.Mininet1, "Mininet handle should be named Mininet1"
1517 # assert main.numSwitch, "Placed the total number of switch topology in \
1518 # main.numSwitch"
1519 # main.case( "Test host mobility with host intents " )
1520 # main.step( " Testing host mobility by moving h1 from s5 to s6" )
1521 # h1PreMove = main.hostsData[ "h1" ][ "location" ][ 0:19 ]
1522
1523 # main.log.info( "Moving h1 from s5 to s6")
1524
1525 # main.Mininet1.moveHost( "h1","s5","s6" )
1526
1527 # main.intentFunction.getHostsData( main )
1528 # h1PostMove = main.hostsData[ "h1" ][ "location" ][ 0:19 ]
1529
1530 # utilities.assert_equals( expect="of:0000000000000006",
1531 # actual=h1PostMove,
1532 # onpass="Mobility: Successfully moved h1 to s6",
1533 # onfail="Mobility: Failed to moved h1 to s6" +
1534 # " to single point intents" +
1535 # " with IPV4 type and MAC addresses" +
1536 # " in the same VLAN" )
1537
1538 # main.step( "IPV4: Add host intents between h1 and h9" )
1539 # stepResult = main.TRUE
1540 # stepResult = main.intentFunction.hostIntent( main,
1541 # onosNode='0',
1542 # name='IPV4',
1543 # host1='h1',
1544 # host2='h9',
1545 # host1Id='00:00:00:00:00:01/-1',
1546 # host2Id='00:00:00:00:00:09/-1' )
1547
1548 # utilities.assert_equals( expect=main.TRUE,
1549 # actual=stepResult,
1550 # onpass="IPV4: Host intent test successful " +
1551 # "between two IPV4 hosts",
1552 # onfail="IPV4: Host intent test failed " +
1553 # "between two IPV4 hosts")
kelvin-onlab44147802015-07-27 17:57:31 -07001554 """
Jeremy2f190ca2016-01-29 15:23:57 -08001555 Tests Host Mobility
1556 Modifies the topology location of h1
kelvin-onlab44147802015-07-27 17:57:31 -07001557 """
1558 assert main, "There is no main"
1559 assert main.CLIs, "There is no main.CLIs"
1560 assert main.Mininet1, "Mininet handle should be named Mininet1"
1561 assert main.numSwitch, "Placed the total number of switch topology in \
1562 main.numSwitch"
1563 main.case( "Test host mobility with host intents " )
Jeremy2f190ca2016-01-29 15:23:57 -08001564 main.step( "Testing host mobility by moving h1 from s5 to s6" )
kelvin-onlab44147802015-07-27 17:57:31 -07001565 h1PreMove = main.hostsData[ "h1" ][ "location" ][ 0:19 ]
1566
1567 main.log.info( "Moving h1 from s5 to s6")
kelvin-onlab44147802015-07-27 17:57:31 -07001568 main.Mininet1.moveHost( "h1","s5","s6" )
1569
Jeremy2f190ca2016-01-29 15:23:57 -08001570 # Send discovery ping from moved host
1571 # Moving the host brings down the default interfaces and creates a new one.
1572 # Scapy is restarted on this host to detect the new interface
1573 main.h1.stopScapy()
1574 main.h1.startScapy()
1575
1576 # Discover new host location in ONOS and populate host data.
1577 # Host 1 IP and MAC should be unchanged
1578 main.intentFunction.sendDiscoveryArp( main, [ main.h1 ] )
1579 main.intentFunction.populateHostData( main )
1580
kelvin-onlab44147802015-07-27 17:57:31 -07001581 h1PostMove = main.hostsData[ "h1" ][ "location" ][ 0:19 ]
1582
1583 utilities.assert_equals( expect="of:0000000000000006",
1584 actual=h1PostMove,
1585 onpass="Mobility: Successfully moved h1 to s6",
Jeremy2f190ca2016-01-29 15:23:57 -08001586 onfail="Mobility: Failed to move h1 to s6" +
kelvin-onlab44147802015-07-27 17:57:31 -07001587 " to single point intents" +
1588 " with IPV4 type and MAC addresses" +
1589 " in the same VLAN" )
1590
1591 main.step( "IPV4: Add host intents between h1 and h9" )
Jeremy2f190ca2016-01-29 15:23:57 -08001592 main.assertReturnString = "Assert result for IPV4 host intent between h1, moved, and h9\n"
1593 host1 = { "name":"h1","id":"00:00:00:00:00:01/-1" }
1594 host2 = { "name":"h9","id":"00:00:00:00:00:09/-1" }
1595
1596 installResult = main.intentFunction.installHostIntent( main,
1597 name='IPV4 Mobility IPV4',
kelvin-onlab44147802015-07-27 17:57:31 -07001598 onosNode='0',
Jeremy2f190ca2016-01-29 15:23:57 -08001599 host1=host1,
1600 host2=host2)
1601 if installResult:
1602 testResult = main.intentFunction.testHostIntent( main,
1603 name='Host Mobility IPV4',
1604 intentId = installResult,
1605 onosNode='0',
1606 host1=host1,
1607 host2=host2,
1608 sw1="s6",
1609 sw2="s2",
1610 expectedLink=18 )
kelvin-onlab44147802015-07-27 17:57:31 -07001611
1612 utilities.assert_equals( expect=main.TRUE,
Jeremy2f190ca2016-01-29 15:23:57 -08001613 actual=testResult,
1614 onpass=main.assertReturnString,
1615 onfail=main.assertReturnString )
1616
1617 main.intentFunction.report( main )
1618