blob: ede34595f3f49587b6a80eccc3b569fa45667e57 [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 )
170 main.step( "Uninstalling ONOS package" )
171 onosUninstallResult = main.TRUE
172 for ip in main.ONOSip:
173 onosUninstallResult = onosUninstallResult and \
174 main.ONOSbench.onosUninstall( nodeIp=ip )
175 stepResult = onosUninstallResult
176 utilities.assert_equals( expect=main.TRUE,
177 actual=stepResult,
178 onpass="Successfully uninstalled ONOS package",
179 onfail="Failed to uninstall ONOS package" )
180
kelvin-onlab44147802015-07-27 17:57:31 -0700181 for i in range( main.maxNodes ):
182 main.ONOSbench.onosDie( main.ONOSip[ i ] )
183
184 print "NODE COUNT = ", main.numCtrls
185
186 tempOnosIp = []
187 for i in range( main.numCtrls ):
188 tempOnosIp.append( main.ONOSip[i] )
189
190 main.ONOSbench.createCellFile( main.ONOSbench.ip_address,
191 "temp", main.Mininet1.ip_address,
192 main.apps, tempOnosIp )
193
194 main.step( "Apply cell to environment" )
195 cellResult = main.ONOSbench.setCell( "temp" )
196 verifyResult = main.ONOSbench.verifyCell()
197 stepResult = cellResult and verifyResult
198 utilities.assert_equals( expect=main.TRUE,
199 actual=stepResult,
200 onpass="Successfully applied cell to " + \
201 "environment",
202 onfail="Failed to apply cell to environment " )
203
204 main.step( "Creating ONOS package" )
205 packageResult = main.ONOSbench.onosPackage()
206 stepResult = packageResult
207 utilities.assert_equals( expect=main.TRUE,
208 actual=stepResult,
209 onpass="Successfully created ONOS package",
210 onfail="Failed to create ONOS package" )
211
212 time.sleep( main.startUpSleep )
kelvin-onlab44147802015-07-27 17:57:31 -0700213 main.step( "Installing ONOS package" )
214 onosInstallResult = main.TRUE
215 for i in range( main.numCtrls ):
216 onosInstallResult = onosInstallResult and \
217 main.ONOSbench.onosInstall( node=main.ONOSip[ i ] )
218 stepResult = onosInstallResult
219 utilities.assert_equals( expect=main.TRUE,
220 actual=stepResult,
221 onpass="Successfully installed ONOS package",
222 onfail="Failed to install ONOS package" )
223
224 time.sleep( main.startUpSleep )
225 main.step( "Starting ONOS service" )
226 stopResult = main.TRUE
227 startResult = main.TRUE
228 onosIsUp = main.TRUE
229
230 for i in range( main.numCtrls ):
231 onosIsUp = onosIsUp and main.ONOSbench.isup( main.ONOSip[ i ] )
232 if onosIsUp == main.TRUE:
233 main.log.report( "ONOS instance is up and ready" )
234 else:
235 main.log.report( "ONOS instance may not be up, stop and " +
236 "start ONOS again " )
237 for i in range( main.numCtrls ):
238 stopResult = stopResult and \
239 main.ONOSbench.onosStop( main.ONOSip[ i ] )
240 for i in range( main.numCtrls ):
241 startResult = startResult and \
242 main.ONOSbench.onosStart( main.ONOSip[ i ] )
243 stepResult = onosIsUp and stopResult and startResult
244 utilities.assert_equals( expect=main.TRUE,
245 actual=stepResult,
246 onpass="ONOS service is ready",
247 onfail="ONOS service did not start properly" )
248
Jeremy2f190ca2016-01-29 15:23:57 -0800249 # Start an ONOS cli to provide functionality that is not currently
Jeremye1ea0602016-02-08 16:35:05 -0800250 # supported by the Rest API remove this when Leader Checking is supported
251 # by the REST API
Jeremy2f190ca2016-01-29 15:23:57 -0800252
Jeremye1ea0602016-02-08 16:35:05 -0800253 main.step( "Start ONOS cli" )
254 cliResult = main.TRUE
255 for i in range( main.numCtrls ):
256 cliResult = cliResult and \
257 main.CLIs2[ i ].startOnosCli( main.ONOSip[ i ] )
258 stepResult = cliResult
259 utilities.assert_equals( expect=main.TRUE,
260 actual=stepResult,
261 onpass="Successfully start ONOS cli",
262 onfail="Failed to start ONOS cli" )
Jeremy2f190ca2016-01-29 15:23:57 -0800263
kelvin-onlab44147802015-07-27 17:57:31 -0700264 # Remove the first element in main.scale list
265 main.scale.remove( main.scale[ 0 ] )
266
Jeremy2f190ca2016-01-29 15:23:57 -0800267 main.intentFunction.report( main )
268
kelvin-onlab44147802015-07-27 17:57:31 -0700269 def CASE8( self, main ):
Jeremy2f190ca2016-01-29 15:23:57 -0800270 # OLD FUNCintentRest CASE 8
271 # This remains here for archiving and reference purposes and will be
272 # removed when the new FUNCintentRest is verified to work.
273 # """
274 # Compare Topo
275 # """
276 # import json
277
278 # main.case( "Compare ONOS Topology view to Mininet topology" )
279 # main.caseExplanation = "Compare topology elements between Mininet" +\
280 # " and ONOS"
281
282 # main.step( "Gathering topology information" )
283 # # TODO: add a paramaterized sleep here
284 # devicesResults = main.TRUE # Overall Boolean for device correctness
285 # linksResults = main.TRUE # Overall Boolean for link correctness
286 # hostsResults = main.TRUE # Overall Boolean for host correctness
287 # devices = main.topo.getAllDevices( main )
288 # hosts = main.topo.getAllHosts( main )
289 # ports = main.topo.getAllPorts( main )
290 # links = main.topo.getAllLinks( main )
291 # clusters = main.topo.getAllClusters( main )
292
293 # mnSwitches = main.Mininet1.getSwitches()
294 # mnLinks = main.Mininet1.getLinks()
295 # mnHosts = main.Mininet1.getHosts()
296
297 # main.step( "Comparing MN topology to ONOS topology" )
298 # for controller in range( main.numCtrls ):
299 # controllerStr = str( controller + 1 )
300 # if devices[ controller ] and ports[ controller ] and\
301 # "Error" not in devices[ controller ] and\
302 # "Error" not in ports[ controller ]:
303
304 # currentDevicesResult = main.Mininet1.compareSwitches(
305 # mnSwitches,
306 # json.loads( devices[ controller ] ),
307 # json.loads( ports[ controller ] ) )
308 # else:
309 # currentDevicesResult = main.FALSE
310 # utilities.assert_equals( expect=main.TRUE,
311 # actual=currentDevicesResult,
312 # onpass="ONOS" + controllerStr +
313 # " Switches view is correct",
314 # onfail="ONOS" + controllerStr +
315 # " Switches view is incorrect" )
316
317 # if links[ controller ] and "Error" not in links[ controller ]:
318 # currentLinksResult = main.Mininet1.compareLinks(
319 # mnSwitches, mnLinks,
320 # json.loads( links[ controller ] ) )
321 # else:
322 # currentLinksResult = main.FALSE
323 # utilities.assert_equals( expect=main.TRUE,
324 # actual=currentLinksResult,
325 # onpass="ONOS" + controllerStr +
326 # " links view is correct",
327 # onfail="ONOS" + controllerStr +
328 # " links view is incorrect" )
329
330 # if hosts[ controller ] or "Error" not in hosts[ controller ]:
331 # currentHostsResult = main.Mininet1.compareHosts(
332 # mnHosts,
333 # json.loads( hosts[ controller ] ) )
334 # else:
335 # currentHostsResult = main.FALSE
336 # utilities.assert_equals( expect=main.TRUE,
337 # actual=currentHostsResult,
338 # onpass="ONOS" + controllerStr +
339 # " hosts exist in Mininet",
340 # onfail="ONOS" + controllerStr +
341 # " hosts don't match Mininet" )
342
343 # NEW FUNCintentRest Case 8 as based off of the CASE 8 from FUNCintent
kelvin-onlab44147802015-07-27 17:57:31 -0700344 """
Jeremy2f190ca2016-01-29 15:23:57 -0800345 Compare ONOS Topology to Mininet Topology
kelvin-onlab44147802015-07-27 17:57:31 -0700346 """
347 import json
348
349 main.case( "Compare ONOS Topology view to Mininet topology" )
350 main.caseExplanation = "Compare topology elements between Mininet" +\
351 " and ONOS"
352
Jeremy2f190ca2016-01-29 15:23:57 -0800353 main.log.info( "Gathering topology information from Mininet" )
354 devicesResults = main.FALSE # Overall Boolean for device correctness
355 linksResults = main.FALSE # Overall Boolean for link correctness
356 hostsResults = main.FALSE # Overall Boolean for host correctness
357 deviceFails = [] # Nodes where devices are incorrect
358 linkFails = [] # Nodes where links are incorrect
359 hostFails = [] # Nodes where hosts are incorrect
360 attempts = main.checkTopoAttempts # Remaining Attempts
kelvin-onlab44147802015-07-27 17:57:31 -0700361
362 mnSwitches = main.Mininet1.getSwitches()
363 mnLinks = main.Mininet1.getLinks()
364 mnHosts = main.Mininet1.getHosts()
365
Jeremy2f190ca2016-01-29 15:23:57 -0800366 main.step( "Comparing Mininet topology to ONOS topology" )
kelvin-onlab44147802015-07-27 17:57:31 -0700367
Jeremy2f190ca2016-01-29 15:23:57 -0800368 while ( attempts >= 0 ) and\
369 ( not devicesResults or not linksResults or not hostsResults ):
370 time.sleep( 2 )
371 if not devicesResults:
372 devices = main.topo.getAllDevices( main )
373 ports = main.topo.getAllPorts( main )
374 devicesResults = main.TRUE
375 deviceFails = [] # Reset for each failed attempt
376 if not linksResults:
377 links = main.topo.getAllLinks( main )
378 linksResults = main.TRUE
379 linkFails = [] # Reset for each failed attempt
380 if not hostsResults:
381 hosts = main.topo.getAllHosts( main )
382 hostsResults = main.TRUE
383 hostFails = [] # Reset for each failed attempt
kelvin-onlab44147802015-07-27 17:57:31 -0700384
Jeremy2f190ca2016-01-29 15:23:57 -0800385 # Check for matching topology on each node
386 for controller in range( main.numCtrls ):
387 controllerStr = str( controller + 1 ) # ONOS node number
388 # Compare Devices
389 if devices[ controller ] and ports[ controller ] and\
390 "Error" not in devices[ controller ] and\
391 "Error" not in ports[ controller ]:
kelvin-onlab44147802015-07-27 17:57:31 -0700392
Jeremy2f190ca2016-01-29 15:23:57 -0800393 try:
394 deviceData = json.loads( devices[ controller ] )
395 portData = json.loads( ports[ controller ] )
396 except (TypeError,ValueError):
397 main.log.error( "Could not load json: {0} or {1}".format( str( devices[ controller ] ), str( ports[ controller ] ) ) )
398 currentDevicesResult = main.FALSE
399 else:
400 currentDevicesResult = main.Mininet1.compareSwitches(
401 mnSwitches,deviceData,portData )
402 else:
403 currentDevicesResult = main.FALSE
404 if not currentDevicesResult:
405 deviceFails.append( controllerStr )
406 devicesResults = devicesResults and currentDevicesResult
407 # Compare Links
408 if links[ controller ] and "Error" not in links[ controller ]:
409 try:
410 linkData = json.loads( links[ controller ] )
411 except (TypeError,ValueError):
412 main.log.error("Could not load json:" + str( links[ controller ] ) )
413 currentLinksResult = main.FALSE
414 else:
415 currentLinksResult = main.Mininet1.compareLinks(
416 mnSwitches, mnLinks,linkData )
417 else:
418 currentLinksResult = main.FALSE
419 if not currentLinksResult:
420 linkFails.append( controllerStr )
421 linksResults = linksResults and currentLinksResult
422 # Compare Hosts
423 if hosts[ controller ] and "Error" not in hosts[ controller ]:
424 try:
425 hostData = json.loads( hosts[ controller ] )
426 except (TypeError,ValueError):
427 main.log.error("Could not load json:" + str( hosts[ controller ] ) )
428 currentHostsResult = main.FALSE
429 else:
430 currentHostsResult = main.Mininet1.compareHosts(
431 mnHosts,hostData )
432 else:
433 currentHostsResult = main.FALSE
434 if not currentHostsResult:
435 hostFails.append( controllerStr )
436 hostsResults = hostsResults and currentHostsResult
437 # Decrement Attempts Remaining
438 attempts -= 1
439
440
441 utilities.assert_equals( expect=[],
442 actual=deviceFails,
443 onpass="ONOS correctly discovered all devices",
444 onfail="ONOS incorrectly discovered devices on nodes: " +
445 str( deviceFails ) )
446 utilities.assert_equals( expect=[],
447 actual=linkFails,
448 onpass="ONOS correctly discovered all links",
449 onfail="ONOS incorrectly discovered links on nodes: " +
450 str( linkFails ) )
451 utilities.assert_equals( expect=[],
452 actual=hostFails,
453 onpass="ONOS correctly discovered all hosts",
454 onfail="ONOS incorrectly discovered hosts on nodes: " +
455 str( hostFails ) )
456 topoResults = hostsResults and linksResults and devicesResults
457 utilities.assert_equals( expect=main.TRUE,
458 actual=topoResults,
459 onpass="ONOS correctly discovered the topology",
460 onfail="ONOS incorrectly discovered the topology" )
kelvin-onlab44147802015-07-27 17:57:31 -0700461
462 def CASE9( self, main ):
463 '''
464 Report errors/warnings/exceptions
465 '''
466 main.log.info( "Error report: \n" )
467 main.ONOSbench.logReport( globalONOSip[0],
468 [ "INFO", "FOLLOWER", "WARN", "flow", "ERROR" , "Except" ],
469 "s" )
470 #main.ONOSbench.logReport( globalONOSip[1], [ "INFO" ], "d" )
471
472 def CASE10( self, main ):
473 """
474 Start Mininet topology with OF 1.0 switches
475 """
476 main.OFProtocol = "1.0"
477 main.log.report( "Start Mininet topology with OF 1.0 switches" )
478 main.case( "Start Mininet topology with OF 1.0 switches" )
479 main.caseExplanation = "Start mininet topology with OF 1.0 " +\
480 "switches to test intents, exits out if " +\
481 "topology did not start correctly"
482
483 main.step( "Starting Mininet topology with OF 1.0 switches" )
484 args = "--switch ovs,protocols=OpenFlow10"
485 topoResult = main.Mininet1.startNet( topoFile=main.dependencyPath +
486 main.topology,
487 args=args )
488 stepResult = topoResult
489 utilities.assert_equals( expect=main.TRUE,
490 actual=stepResult,
491 onpass="Successfully loaded topology",
492 onfail="Failed to load topology" )
493 # Exit if topology did not load properly
494 if not topoResult:
495 main.cleanup()
496 main.exit()
497
498 def CASE11( self, main ):
499 """
500 Start Mininet topology with OF 1.3 switches
501 """
502 main.OFProtocol = "1.3"
503 main.log.report( "Start Mininet topology with OF 1.3 switches" )
504 main.case( "Start Mininet topology with OF 1.3 switches" )
505 main.caseExplanation = "Start mininet topology with OF 1.3 " +\
506 "switches to test intents, exits out if " +\
507 "topology did not start correctly"
508
509 main.step( "Starting Mininet topology with OF 1.3 switches" )
510 args = "--switch ovs,protocols=OpenFlow13"
511 topoResult = main.Mininet1.startNet( topoFile=main.dependencyPath +
512 main.topology,
513 args=args )
514 stepResult = topoResult
515 utilities.assert_equals( expect=main.TRUE,
516 actual=stepResult,
517 onpass="Successfully loaded topology",
518 onfail="Failed to load topology" )
519 # Exit if topology did not load properly
520 if not topoResult:
521 main.cleanup()
522 main.exit()
523
524 def CASE12( self, main ):
525 """
526 Assign mastership to controllers
527 """
528 import re
529
530 main.case( "Assign switches to controllers" )
531 main.step( "Assigning switches to controllers" )
532 main.caseExplanation = "Assign OF " + main.OFProtocol +\
533 " switches to ONOS nodes"
534
535 assignResult = main.TRUE
536 switchList = []
537
538 # Creates a list switch name, use getSwitch() function later...
539 for i in range( 1, ( main.numSwitch + 1 ) ):
540 switchList.append( 's' + str( i ) )
541
542 tempONOSip = []
543 for i in range( main.numCtrls ):
544 tempONOSip.append( main.ONOSip[ i ] )
545
546 assignResult = main.Mininet1.assignSwController( sw=switchList,
547 ip=tempONOSip,
Charles Chan029be652015-08-24 01:46:10 +0800548 port='6653' )
kelvin-onlab44147802015-07-27 17:57:31 -0700549 if not assignResult:
550 main.cleanup()
551 main.exit()
552
553 for i in range( 1, ( main.numSwitch + 1 ) ):
554 response = main.Mininet1.getSwController( "s" + str( i ) )
555 print( "Response is " + str( response ) )
556 if re.search( "tcp:" + main.ONOSip[ 0 ], response ):
557 assignResult = assignResult and main.TRUE
558 else:
559 assignResult = main.FALSE
560 stepResult = assignResult
561 utilities.assert_equals( expect=main.TRUE,
562 actual=stepResult,
563 onpass="Successfully assigned switches" +
564 "to controller",
565 onfail="Failed to assign switches to " +
566 "controller" )
Jeremy2f190ca2016-01-29 15:23:57 -0800567
568 def CASE13( self,main ):
569 """
570 Create Scapy components
571 """
572 main.case( "Create scapy components" )
573 main.step( "Create scapy components" )
574 import json
575 scapyResult = main.TRUE
576 for hostName in main.scapyHostNames:
577 main.Scapy1.createHostComponent( hostName )
578 main.scapyHosts.append( getattr( main, hostName ) )
579
580 main.step( "Start scapy components" )
581 for host in main.scapyHosts:
582 host.startHostCli()
583 host.startScapy()
584 host.updateSelf()
585 main.log.debug( host.name )
586 main.log.debug( host.hostIp )
587 main.log.debug( host.hostMac )
588
589
590 utilities.assert_equals( expect=main.TRUE,
591 actual=scapyResult,
592 onpass="Successfully created Scapy Components",
593 onfail="Failed to discover Scapy Components" )
594
595 def CASE14( self, main ):
kelvin-onlab44147802015-07-27 17:57:31 -0700596 """
597 Discover all hosts and store its data to a dictionary
598 """
599 main.case( "Discover all hosts" )
600
601 stepResult = main.TRUE
kelvin-onlab0e684682015-08-11 18:51:41 -0700602 main.step( "Discover all ipv4 host hosts " )
603 hostList = []
604 # List of host with default vlan
605 defaultHosts = [ "h1", "h3", "h8", "h9", "h11", "h16", "h17", "h19", "h24" ]
606 # Lists of host with unique vlan
607 vlanHosts1 = [ "h4", "h12", "h20" ]
608 vlanHosts2 = [ "h5", "h13", "h21" ]
609 vlanHosts3 = [ "h6", "h14", "h22" ]
610 vlanHosts4 = [ "h7", "h15", "h23" ]
611 hostList.append( defaultHosts )
612 hostList.append( vlanHosts1 )
613 hostList.append( vlanHosts2 )
614 hostList.append( vlanHosts3 )
615 hostList.append( vlanHosts4 )
616
617 stepResult = main.intentFunction.getHostsData( main, hostList )
kelvin-onlab44147802015-07-27 17:57:31 -0700618 utilities.assert_equals( expect=main.TRUE,
619 actual=stepResult,
620 onpass="Successfully discovered hosts",
621 onfail="Failed to discover hosts" )
622
Jeremy2f190ca2016-01-29 15:23:57 -0800623 def CASE15( self, main ):
kelvin-onlab44147802015-07-27 17:57:31 -0700624 """
Jeremy2f190ca2016-01-29 15:23:57 -0800625 Discover all hosts with scapy arp packets and store its data to a dictionary
kelvin-onlab44147802015-07-27 17:57:31 -0700626 """
Jeremy2f190ca2016-01-29 15:23:57 -0800627 main.case( "Discover all hosts using scapy" )
628 main.step( "Send packets from each host to the first host and confirm onos discovery" )
629
630 import collections
631 if len( main.scapyHosts ) < 1:
632 main.log.error( "No scapy hosts have been created" )
633 main.skipCase()
634
635 # Send ARP packets from each scapy host component
636 main.intentFunction.sendDiscoveryArp( main, main.scapyHosts )
637
638 stepResult = utilities.retry( f=main.intentFunction.confirmHostDiscovery,
639 retValue=main.FALSE, args=[ main ],
640 attempts=main.checkTopoAttempts, sleep=2 )
641
642 utilities.assert_equals( expect=main.TRUE,
643 actual=stepResult,
644 onpass="ONOS correctly discovered all hosts",
645 onfail="ONOS incorrectly discovered hosts" )
646
647 main.step( "Populate hostsData" )
648 stepResult = main.intentFunction.populateHostData( main )
649 utilities.assert_equals( expect=main.TRUE,
650 actual=stepResult,
651 onpass="Successfully populated hostsData",
652 onfail="Failed to populate hostsData" )
653
654 def CASE16( self, main ):
655 """
656 Stop mininet and remove scapy hosts
657 """
658 main.log.report( "Stop Mininet and Scapy" )
659 main.case( "Stop Mininet and Scapy" )
kelvin-onlab44147802015-07-27 17:57:31 -0700660 main.caseExplanation = "Stopping the current mininet topology " +\
661 "to start up fresh"
662
Jeremy2f190ca2016-01-29 15:23:57 -0800663 main.step( "Stopping and Removing Scapy Host Components" )
664 scapyResult = main.TRUE
665 for host in main.scapyHosts:
666 scapyResult = scapyResult and host.stopScapy()
667 main.log.info( "Stopped Scapy Host: {0}".format( host.name ) )
668
669 for host in main.scapyHosts:
670 scapyResult = scapyResult and main.Scapy1.removeHostComponent( host.name )
671 main.log.info( "Removed Scapy Host Component: {0}".format( host.name ) )
672
673 main.scapyHosts = []
674 main.scapyHostIPs = []
675
676 utilities.assert_equals( expect=main.TRUE,
677 actual=scapyResult,
678 onpass="Successfully stopped scapy and removed host components",
679 onfail="Failed to stop mininet and scapy" )
680
kelvin-onlab44147802015-07-27 17:57:31 -0700681 main.step( "Stopping Mininet Topology" )
Jeremy2f190ca2016-01-29 15:23:57 -0800682 mininetResult = main.Mininet1.stopNet( )
683
kelvin-onlab44147802015-07-27 17:57:31 -0700684 utilities.assert_equals( expect=main.TRUE,
685 actual=stepResult,
686 onpass="Successfully stop mininet",
687 onfail="Failed to stop mininet" )
688 # Exit if topology did not load properly
Jeremy2f190ca2016-01-29 15:23:57 -0800689 if not (mininetResult and scapyResult ):
kelvin-onlab44147802015-07-27 17:57:31 -0700690 main.cleanup()
691 main.exit()
692
693 def CASE1000( self, main ):
694 """
695 Add host intents between 2 host:
696 - Discover hosts
697 - Add host intents
698 - Check intents
699 - Verify flows
700 - Ping hosts
701 - Reroute
702 - Link down
703 - Verify flows
704 - Check topology
705 - Ping hosts
706 - Link up
707 - Verify flows
708 - Check topology
709 - Ping hosts
710 - Remove intents
711 """
712 import time
713 import json
714 import re
715
716 # Assert variables - These variable's name|format must be followed
717 # if you want to use the wrapper function
718 assert main, "There is no main"
719 assert main.CLIs, "There is no main.CLIs"
720 assert main.Mininet1, "Mininet handle should be named Mininet1"
721 assert main.numSwitch, "Placed the total number of switch topology in \
722 main.numSwitch"
723
Jeremye1ea0602016-02-08 16:35:05 -0800724 # Save leader candidates
725 intentLeadersOld = main.CLIs2[ 0 ].leaderCandidates()
726
kelvin-onlab44147802015-07-27 17:57:31 -0700727 main.case( "Host Intents Test - " + str( main.numCtrls ) +
728 " NODE(S) - OF " + main.OFProtocol )
729 main.caseExplanation = "This test case tests Host intents using " +\
730 str( main.numCtrls ) + " node(s) cluster;\n" +\
731 "Different type of hosts will be tested in " +\
732 "each step such as IPV4, Dual stack, VLAN " +\
733 "etc;\nThe test will use OF " + main.OFProtocol\
734 + " OVS running in Mininet"
735
Jeremy2f190ca2016-01-29 15:23:57 -0800736 main.step( "IPV4: Add and test host intents between h1 and h9" )
737 main.assertReturnString = "Assertion result for IPV4 host intent with mac addresses\n"
738 host1 = { "name":"h1","id":"00:00:00:00:00:01/-1" }
739 host2 = { "name":"h9","id":"00:00:00:00:00:09/-1" }
740 testResult = main.FALSE
741 installResult = main.intentFunction.installHostIntent( main,
kelvin-onlab44147802015-07-27 17:57:31 -0700742 name='IPV4',
Jeremy2f190ca2016-01-29 15:23:57 -0800743 onosNode='0',
744 host1=host1,
745 host2=host2 )
746
747 if installResult:
748 testResult = main.intentFunction.testHostIntent( main,
749 name='IPV4',
750 intentId = installResult,
751 onosNode='0',
752 host1=host1,
753 host2=host2,
kelvin-onlab44147802015-07-27 17:57:31 -0700754 sw1='s5',
755 sw2='s2',
Jeremy2f190ca2016-01-29 15:23:57 -0800756 expectedLink = 18 )
kelvin-onlab44147802015-07-27 17:57:31 -0700757
758 utilities.assert_equals( expect=main.TRUE,
Jeremy2f190ca2016-01-29 15:23:57 -0800759 actual=testResult,
760 onpass=main.assertReturnString,
761 onfail=main.assertReturnString )
kelvin-onlab44147802015-07-27 17:57:31 -0700762
763 main.step( "DUALSTACK1: Add host intents between h3 and h11" )
Jeremy2f190ca2016-01-29 15:23:57 -0800764 main.assertReturnString = "Assertion Result for dualstack IPV4 with MAC addresses\n"
765 host1 = { "name":"h3", "id":"00:00:00:00:00:03/-1" }
766 host2 = { "name":"h11","id":"00:00:00:00:00:0B/-1"}
767 testResult = main.FALSE
768 installResult = main.intentFunction.installHostIntent( main,
769 name='DUALSTACK1',
770 onosNode='0',
771 host1=host1,
772 host2=host2 )
773
774 if installResult:
775 testResult = main.intentFunction.testHostIntent( main,
776 name='DUALSTACK1',
777 intentId = installResult,
778 onosNode='0',
779 host1=host1,
780 host2=host2,
kelvin-onlab44147802015-07-27 17:57:31 -0700781 sw1='s5',
782 sw2='s2',
Jeremy2f190ca2016-01-29 15:23:57 -0800783 expectedLink = 18 )
kelvin-onlab44147802015-07-27 17:57:31 -0700784
785 utilities.assert_equals( expect=main.TRUE,
Jeremy2f190ca2016-01-29 15:23:57 -0800786 actual=testResult,
787 onpass=main.assertReturnString,
788 onfail=main.assertReturnString)
kelvin-onlab44147802015-07-27 17:57:31 -0700789
790 main.step( "DUALSTACK2: Add host intents between h1 and h11" )
Jeremy2f190ca2016-01-29 15:23:57 -0800791 main.assertReturnString = "Assertion Result for dualstack2 host intent\n"
792 host1 = { "name":"h1" }
793 host2 = { "name":"h11" }
794 testResult = main.FALSE
795 installResult = main.intentFunction.installHostIntent( main,
kelvin-onlab44147802015-07-27 17:57:31 -0700796 name='DUALSTACK2',
Jeremy2f190ca2016-01-29 15:23:57 -0800797 onosNode='0',
798 host1=host1,
799 host2=host2 )
800
801 if installResult:
802 testResult = main.intentFunction.testHostIntent( main,
803 name='DUALSTACK2',
804 intentId = installResult,
805 onosNode='0',
806 host1=host1,
807 host2=host2,
kelvin-onlab44147802015-07-27 17:57:31 -0700808 sw1='s5',
809 sw2='s2',
Jeremy2f190ca2016-01-29 15:23:57 -0800810 expectedLink = 18 )
kelvin-onlab44147802015-07-27 17:57:31 -0700811
812 utilities.assert_equals( expect=main.TRUE,
Jeremy2f190ca2016-01-29 15:23:57 -0800813 actual=testResult,
814 onpass=main.assertReturnString,
815 onfail=main.assertReturnString )
kelvin-onlab44147802015-07-27 17:57:31 -0700816
817 main.step( "1HOP: Add host intents between h1 and h3" )
Jeremy2f190ca2016-01-29 15:23:57 -0800818 main.assertReturnString = "Assertion Result for 1HOP for IPV4 same switch\n"
819 host1 = { "name":"h1" }
820 host2 = { "name":"h3" }
821 testResult = main.FALSE
822 installResult = main.intentFunction.installHostIntent( main,
kelvin-onlab44147802015-07-27 17:57:31 -0700823 name='1HOP',
Jeremy2f190ca2016-01-29 15:23:57 -0800824 onosNode='0',
825 host1=host1,
826 host2=host2 )
kelvin-onlab44147802015-07-27 17:57:31 -0700827
Jeremy2f190ca2016-01-29 15:23:57 -0800828 if installResult:
829 testResult = main.intentFunction.testHostIntent( main,
830 name='1HOP',
831 intentId = installResult,
832 onosNode='0',
833 host1=host1,
834 host2=host2,
kelvin-onlab44147802015-07-27 17:57:31 -0700835 sw1='s5',
836 sw2='s2',
Jeremy2f190ca2016-01-29 15:23:57 -0800837 expectedLink = 18 )
kelvin-onlab44147802015-07-27 17:57:31 -0700838
839 utilities.assert_equals( expect=main.TRUE,
Jeremy2f190ca2016-01-29 15:23:57 -0800840 actual=testResult,
841 onpass=main.assertReturnString,
842 onfail=main.assertReturnString )
843
844 main.step( "VLAN1: Add vlan host intents between h4 and h12" )
845 main.assertReturnString = "Assertion Result vlan IPV4\n"
846 host1 = { "name":"h4","id":"00:00:00:00:00:04/100" }
847 host2 = { "name":"h12","id":"00:00:00:00:00:0C/100" }
848 testResult = main.FALSE
849 installResult = main.intentFunction.installHostIntent( main,
850 name='VLAN1',
851 onosNode='0',
852 host1=host1,
853 host2=host2 )
854
855 if installResult:
856 testResult = main.intentFunction.testHostIntent( main,
857 name='VLAN1',
858 intentId = installResult,
859 onosNode='0',
860 host1=host1,
861 host2=host2,
862 sw1='s5',
863 sw2='s2',
864 expectedLink = 18 )
865
866 utilities.assert_equals( expect=main.TRUE,
867 actual=testResult,
868 onpass=main.assertReturnString,
869 onfail=main.assertReturnString )
kelvin-onlab44147802015-07-27 17:57:31 -0700870
871 main.step( "VLAN2: Add inter vlan host intents between h13 and h20" )
Jeremy2f190ca2016-01-29 15:23:57 -0800872 main.assertReturnString = "Assertion Result different VLAN negative test\n"
873 host1 = { "name":"h13" }
874 host2 = { "name":"h20" }
875 testResult = main.FALSE
876 installResult = main.intentFunction.installHostIntent( main,
kelvin-onlab44147802015-07-27 17:57:31 -0700877 name='VLAN2',
Jeremy2f190ca2016-01-29 15:23:57 -0800878 onosNode='0',
879 host1=host1,
880 host2=host2 )
kelvin-onlab44147802015-07-27 17:57:31 -0700881
Jeremy2f190ca2016-01-29 15:23:57 -0800882 if installResult:
883 testResult = main.intentFunction.testHostIntent( main,
884 name='VLAN2',
885 intentId = installResult,
886 onosNode='0',
887 host1=host1,
888 host2=host2,
889 sw1='s5',
890 sw2='s2',
891 expectedLink = 18 )
kelvin-onlab44147802015-07-27 17:57:31 -0700892
Jeremy2f190ca2016-01-29 15:23:57 -0800893 utilities.assert_equals( expect=main.TRUE,
894 actual=testResult,
895 onpass=main.assertReturnString,
896 onfail=main.assertReturnString )
897
Jeremye1ea0602016-02-08 16:35:05 -0800898 # Change the following to use the REST API when leader checking is
899 # supported by it
Jeremy2f190ca2016-01-29 15:23:57 -0800900
Jeremye1ea0602016-02-08 16:35:05 -0800901 main.step( "Confirm that ONOS leadership is unchanged")
902 intentLeadersNew = main.CLIs2[ 0 ].leaderCandidates()
903 main.intentFunction.checkLeaderChange( intentLeadersOld,
904 intentLeadersNew )
Jeremy2f190ca2016-01-29 15:23:57 -0800905
Jeremye1ea0602016-02-08 16:35:05 -0800906 utilities.assert_equals( expect=main.TRUE,
907 actual=testResult,
908 onpass="ONOS Leaders Unchanged",
909 onfail="ONOS Leader Mismatch")
Jeremy2f190ca2016-01-29 15:23:57 -0800910
911 main.intentFunction.report( main )
kelvin-onlab44147802015-07-27 17:57:31 -0700912
913 def CASE2000( self, main ):
914 """
915 Add point intents between 2 hosts:
916 - Get device ids | ports
917 - Add point intents
918 - Check intents
919 - Verify flows
920 - Ping hosts
921 - Reroute
922 - Link down
923 - Verify flows
924 - Check topology
925 - Ping hosts
926 - Link up
927 - Verify flows
928 - Check topology
929 - Ping hosts
930 - Remove intents
931 """
932 import time
933 import json
934 import re
935
936 # Assert variables - These variable's name|format must be followed
937 # if you want to use the wrapper function
938 assert main, "There is no main"
939 assert main.CLIs, "There is no main.CLIs"
940 assert main.Mininet1, "Mininet handle should be named Mininet1"
941 assert main.numSwitch, "Placed the total number of switch topology in \
942 main.numSwitch"
943
944 main.case( "Point Intents Test - " + str( main.numCtrls ) +
945 " NODE(S) - OF " + main.OFProtocol )
946 main.caseExplanation = "This test case will test point to point" +\
947 " intents using " + str( main.numCtrls ) +\
948 " node(s) cluster;\n" +\
949 "Different type of hosts will be tested in " +\
950 "each step such as IPV4, Dual stack, VLAN etc" +\
951 ";\nThe test will use OF " + main.OFProtocol +\
952 " OVS running in Mininet"
953
954 # No option point intents
955 main.step( "NOOPTION: Add point intents between h1 and h9" )
Jeremy2f190ca2016-01-29 15:23:57 -0800956 main.assertReturnString = "Assertion Result for NOOPTION point intent\n"
957 senders = [
958 { "name":"h1","device":"of:0000000000000005/1" }
959 ]
960 recipients = [
961 { "name":"h9","device":"of:0000000000000006/1" }
962 ]
963 testResult = main.FALSE
964 installResult = main.intentFunction.installPointIntent(
kelvin-onlab44147802015-07-27 17:57:31 -0700965 main,
966 name="NOOPTION",
Jeremy2f190ca2016-01-29 15:23:57 -0800967 senders=senders,
968 recipients=recipients )
969
970 if installResult:
971 testResult = main.intentFunction.testPointIntent(
972 main,
973 intentId=installResult,
974 name="NOOPTION",
975 senders=senders,
976 recipients=recipients,
977 sw1="s5",
978 sw2="s2",
979 expectedLink=18)
kelvin-onlab44147802015-07-27 17:57:31 -0700980
981 utilities.assert_equals( expect=main.TRUE,
Jeremy2f190ca2016-01-29 15:23:57 -0800982 actual=testResult,
983 onpass=main.assertReturnString,
984 onfail=main.assertReturnString )
kelvin-onlab44147802015-07-27 17:57:31 -0700985
kelvin-onlab44147802015-07-27 17:57:31 -0700986 main.step( "IPV4: Add point intents between h1 and h9" )
Jeremy2f190ca2016-01-29 15:23:57 -0800987 main.assertReturnString = "Assertion Result for IPV4 point intent\n"
988 senders = [
989 { "name":"h1","device":"of:0000000000000005/1","mac":"00:00:00:00:00:01" }
990 ]
991 recipients = [
992 { "name":"h9","device":"of:0000000000000006/1","mac":"00:00:00:00:00:09" }
993 ]
994 installResult = main.intentFunction.installPointIntent(
kelvin-onlab44147802015-07-27 17:57:31 -0700995 main,
996 name="IPV4",
Jeremy2f190ca2016-01-29 15:23:57 -0800997 senders=senders,
998 recipients=recipients,
999 ethType="IPV4" )
1000
1001 if installResult:
1002 testResult = main.intentFunction.testPointIntent(
1003 main,
1004 intentId=installResult,
1005 name="IPV4",
1006 senders=senders,
1007 recipients=recipients,
1008 sw1="s5",
1009 sw2="s2",
1010 expectedLink=18)
kelvin-onlab44147802015-07-27 17:57:31 -07001011
1012 utilities.assert_equals( expect=main.TRUE,
Jeremy2f190ca2016-01-29 15:23:57 -08001013 actual=testResult,
1014 onpass=main.assertReturnString,
1015 onfail=main.assertReturnString )
kelvin-onlab44147802015-07-27 17:57:31 -07001016 main.step( "IPV4_2: Add point intents between h1 and h9" )
Jeremy2f190ca2016-01-29 15:23:57 -08001017 main.assertReturnString = "Assertion Result for IPV4 no mac address point intents\n"
1018 senders = [
1019 { "name":"h1","device":"of:0000000000000005/1" }
1020 ]
1021 recipients = [
1022 { "name":"h9","device":"of:0000000000000006/1" }
1023 ]
1024 installResult = main.intentFunction.installPointIntent(
kelvin-onlab44147802015-07-27 17:57:31 -07001025 main,
1026 name="IPV4_2",
Jeremy2f190ca2016-01-29 15:23:57 -08001027 senders=senders,
1028 recipients=recipients,
1029 ethType="IPV4" )
1030
1031 if installResult:
1032 testResult = main.intentFunction.testPointIntent(
1033 main,
1034 intentId=installResult,
1035 name="IPV4_2",
1036 senders=senders,
1037 recipients=recipients,
1038 sw1="s5",
1039 sw2="s2",
1040 expectedLink=18)
kelvin-onlab44147802015-07-27 17:57:31 -07001041
1042 utilities.assert_equals( expect=main.TRUE,
Jeremy2f190ca2016-01-29 15:23:57 -08001043 actual=testResult,
1044 onpass=main.assertReturnString,
1045 onfail=main.assertReturnString )
kelvin-onlab44147802015-07-27 17:57:31 -07001046
kelvin-onlab0e684682015-08-11 18:51:41 -07001047 main.step( "SDNIP-ICMP: Add point intents between h1 and h9" )
Jeremy2f190ca2016-01-29 15:23:57 -08001048 main.assertReturnString = "Assertion Result for SDNIP-ICMP IPV4 using TCP point intents\n"
1049 senders = [
1050 { "name":"h1","device":"of:0000000000000005/1","mac":"00:00:00:00:00:01",
1051 "ip":main.h1.hostIp }
1052 ]
1053 recipients = [
1054 { "name":"h9","device":"of:0000000000000006/1","mac":"00:00:00:00:00:09",
1055 "ip":main.h9.hostIp }
1056 ]
kelvin-onlab44147802015-07-27 17:57:31 -07001057 ipProto = main.params[ 'SDNIP' ][ 'icmpProto' ]
1058 # Uneccessary, not including this in the selectors
Jeremy2f190ca2016-01-29 15:23:57 -08001059 tcpSrc = main.params[ 'SDNIP' ][ 'srcPort' ]
1060 tcpDst = main.params[ 'SDNIP' ][ 'dstPort' ]
kelvin-onlab44147802015-07-27 17:57:31 -07001061
Jeremy2f190ca2016-01-29 15:23:57 -08001062 installResult = main.intentFunction.installPointIntent(
1063 main,
1064 name="SDNIP-ICMP",
1065 senders=senders,
1066 recipients=recipients,
1067 ethType="IPV4",
1068 ipProto=ipProto,
1069 tcpSrc=tcpSrc,
1070 tcpDst=tcpDst )
1071
1072 if installResult:
1073 testResult = main.intentFunction.testPointIntent(
1074 main,
1075 intentId=installResult,
1076 name="SDNIP_ICMP",
1077 senders=senders,
1078 recipients=recipients,
1079 sw1="s5",
1080 sw2="s2",
1081 expectedLink=18)
kelvin-onlab44147802015-07-27 17:57:31 -07001082
1083 utilities.assert_equals( expect=main.TRUE,
Jeremy2f190ca2016-01-29 15:23:57 -08001084 actual=testResult,
1085 onpass=main.assertReturnString,
1086 onfail=main.assertReturnString )
kelvin-onlab44147802015-07-27 17:57:31 -07001087
kelvin-onlab0e684682015-08-11 18:51:41 -07001088 main.step( "SDNIP-TCP: Add point intents between h1 and h9" )
Jeremy2f190ca2016-01-29 15:23:57 -08001089 main.assertReturnString = "Assertion Result for SDNIP-TCP IPV4 using ICMP point intents\n"
kelvin-onlab44147802015-07-27 17:57:31 -07001090 mac1 = main.hostsData[ 'h1' ][ 'mac' ]
1091 mac2 = main.hostsData[ 'h9' ][ 'mac' ]
kelvin-onlab0e684682015-08-11 18:51:41 -07001092 ip1 = str( main.hostsData[ 'h1' ][ 'ipAddresses' ][ 0 ] ) + "/32"
1093 ip2 = str( main.hostsData[ 'h9' ][ 'ipAddresses' ][ 0 ] ) + "/32"
kelvin-onlab44147802015-07-27 17:57:31 -07001094 ipProto = main.params[ 'SDNIP' ][ 'tcpProto' ]
1095 tcp1 = main.params[ 'SDNIP' ][ 'srcPort' ]
1096 tcp2 = main.params[ 'SDNIP' ][ 'dstPort' ]
1097
kelvin-onlab0e684682015-08-11 18:51:41 -07001098 stepResult = main.intentFunction.pointIntentTcp(
kelvin-onlab44147802015-07-27 17:57:31 -07001099 main,
kelvin-onlab0e684682015-08-11 18:51:41 -07001100 name="SDNIP-TCP",
kelvin-onlab44147802015-07-27 17:57:31 -07001101 host1="h1",
1102 host2="h9",
1103 deviceId1="of:0000000000000005/1",
1104 deviceId2="of:0000000000000006/1",
1105 mac1=mac1,
1106 mac2=mac2,
1107 ethType="IPV4",
kelvin-onlab0e684682015-08-11 18:51:41 -07001108 ipProto=ipProto,
1109 ip1=ip1,
1110 ip2=ip2,
1111 tcp1=tcp1,
1112 tcp2=tcp2 )
kelvin-onlab44147802015-07-27 17:57:31 -07001113
1114 utilities.assert_equals( expect=main.TRUE,
1115 actual=stepResult,
Jeremy2f190ca2016-01-29 15:23:57 -08001116 onpass=main.assertReturnString,
1117 onfail=main.assertReturnString )
kelvin-onlab44147802015-07-27 17:57:31 -07001118
Jeremy2f190ca2016-01-29 15:23:57 -08001119 main.step( "DUALSTACK1: Add point intents between h3 and h11" )
1120 main.assertReturnString = "Assertion Result for Dualstack1 IPV4 with mac address point intents\n"
1121 senders = [
1122 { "name":"h3","device":"of:0000000000000005/3","mac":"00:00:00:00:00:03" }
1123 ]
1124 recipients = [
1125 { "name":"h11","device":"of:0000000000000006/3","mac":"00:00:00:00:00:0B" }
1126 ]
1127 installResult = main.intentFunction.installPointIntent(
kelvin-onlab44147802015-07-27 17:57:31 -07001128 main,
1129 name="DUALSTACK1",
Jeremy2f190ca2016-01-29 15:23:57 -08001130 senders=senders,
1131 recipients=recipients,
1132 ethType="IPV4" )
1133
1134 if installResult:
1135 testResult = main.intentFunction.testPointIntent(
1136 main,
1137 intentId=installResult,
1138 name="DUALSTACK1",
1139 senders=senders,
1140 recipients=recipients,
1141 sw1="s5",
1142 sw2="s2",
1143 expectedLink=18)
kelvin-onlab44147802015-07-27 17:57:31 -07001144
1145 utilities.assert_equals( expect=main.TRUE,
Jeremy2f190ca2016-01-29 15:23:57 -08001146 actual=testResult,
1147 onpass=main.assertReturnString,
1148 onfail=main.assertReturnString )
kelvin-onlab44147802015-07-27 17:57:31 -07001149
1150 main.step( "VLAN: Add point intents between h5 and h21" )
Jeremy2f190ca2016-01-29 15:23:57 -08001151 main.assertReturnString = "Assertion Result for VLAN IPV4 with mac address point intents\n"
1152 senders = [
1153 { "name":"h5","device":"of:0000000000000005/5","mac":"00:00:00:00:00:05" }
1154 ]
1155 recipients = [
1156 { "name":"h21","device":"of:0000000000000007/5","mac":"00:00:00:00:00:15" }
1157 ]
1158 installResult = main.intentFunction.installPointIntent(
kelvin-onlab44147802015-07-27 17:57:31 -07001159 main,
Jeremy2f190ca2016-01-29 15:23:57 -08001160 name="DUALSTACK1",
1161 senders=senders,
1162 recipients=recipients,
1163 ethType="IPV4" )
1164
1165 if installResult:
1166 testResult = main.intentFunction.testPointIntent(
1167 main,
1168 intentId=installResult,
1169 name="DUALSTACK1",
1170 senders=senders,
1171 recipients=recipients,
1172 sw1="s5",
1173 sw2="s2",
1174 expectedLink=18)
kelvin-onlab44147802015-07-27 17:57:31 -07001175
1176 utilities.assert_equals( expect=main.TRUE,
Jeremy2f190ca2016-01-29 15:23:57 -08001177 actual=testResult,
1178 onpass=main.assertReturnString,
1179 onfail=main.assertReturnString )
kelvin-onlab44147802015-07-27 17:57:31 -07001180
1181 main.step( "1HOP: Add point intents between h1 and h3" )
Jeremy2f190ca2016-01-29 15:23:57 -08001182 main.assertReturnString = "Assertion Result for 1HOP IPV4 with no mac address point intents\n"
1183 senders = [
1184 { "name":"h1","device":"of:0000000000000005/1","mac":"00:00:00:00:00:01" }
1185 ]
1186 recipients = [
1187 { "name":"h3","device":"of:0000000000000005/3","mac":"00:00:00:00:00:03" }
1188 ]
1189 installResult = main.intentFunction.installPointIntent(
1190 main,
1191 name="1HOP IPV4",
1192 senders=senders,
1193 recipients=recipients,
1194 ethType="IPV4" )
1195
1196 if installResult:
1197 testResult = main.intentFunction.testPointIntent(
1198 main,
1199 intentId=installResult,
1200 name="1HOP IPV4",
1201 senders=senders,
1202 recipients=recipients,
1203 sw1="s5",
1204 sw2="s2",
1205 expectedLink=18)
kelvin-onlab44147802015-07-27 17:57:31 -07001206
1207 utilities.assert_equals( expect=main.TRUE,
Jeremy2f190ca2016-01-29 15:23:57 -08001208 actual=testResult,
1209 onpass=main.assertReturnString,
1210 onfail=main.assertReturnString )
1211
1212 main.intentFunction.report( main )
kelvin-onlab44147802015-07-27 17:57:31 -07001213
1214 def CASE3000( self, main ):
1215 """
1216 Add single point to multi point intents
1217 - Get device ids
1218 - Add single point to multi point intents
1219 - Check intents
1220 - Verify flows
1221 - Ping hosts
1222 - Reroute
1223 - Link down
1224 - Verify flows
1225 - Check topology
1226 - Ping hosts
1227 - Link up
1228 - Verify flows
1229 - Check topology
1230 - Ping hosts
1231 - Remove intents
1232 """
1233 assert main, "There is no main"
1234 assert main.CLIs, "There is no main.CLIs"
1235 assert main.Mininet1, "Mininet handle should be named Mininet1"
1236 assert main.numSwitch, "Placed the total number of switch topology in \
1237 main.numSwitch"
1238
1239 main.case( "Single To Multi Point Intents Test - " +
1240 str( main.numCtrls ) + " NODE(S) - OF " + main.OFProtocol )
1241 main.caseExplanation = "This test case will test single point to" +\
1242 " multi point intents using " +\
1243 str( main.numCtrls ) + " node(s) cluster;\n" +\
1244 "Different type of hosts will be tested in " +\
1245 "each step such as IPV4, Dual stack, VLAN etc" +\
1246 ";\nThe test will use OF " + main.OFProtocol +\
1247 " OVS running in Mininet"
1248
1249 main.step( "NOOPTION: Add single point to multi point intents" )
1250 stepResult = main.TRUE
1251 hostNames = [ 'h8', 'h16', 'h24' ]
1252 devices = [ 'of:0000000000000005/8', 'of:0000000000000006/8', \
1253 'of:0000000000000007/8' ]
1254 macs = [ '00:00:00:00:00:08', '00:00:00:00:00:10', '00:00:00:00:00:18' ]
1255 stepResult = main.intentFunction.singleToMultiIntent(
1256 main,
1257 name="NOOPTION",
1258 hostNames=hostNames,
1259 devices=devices,
1260 sw1="s5",
1261 sw2="s2",
1262 expectedLink=18 )
1263
1264 utilities.assert_equals( expect=main.TRUE,
1265 actual=stepResult,
1266 onpass="NOOPTION: Successfully added single "
1267 + " point to multi point intents" +
1268 " with no match action",
1269 onfail="NOOPTION: Failed to add single point"
1270 + " point to multi point intents" +
1271 " with no match action" )
1272
1273 main.step( "IPV4: Add single point to multi point intents" )
1274 stepResult = main.TRUE
1275 stepResult = main.intentFunction.singleToMultiIntent(
1276 main,
1277 name="IPV4",
1278 hostNames=hostNames,
1279 devices=devices,
1280 ports=None,
1281 ethType="IPV4",
1282 macs=macs,
1283 bandwidth="",
1284 lambdaAlloc=False,
1285 ipProto="",
1286 ipAddresses="",
1287 tcp="",
1288 sw1="s5",
1289 sw2="s2",
1290 expectedLink=18 )
1291
1292 utilities.assert_equals( expect=main.TRUE,
1293 actual=stepResult,
1294 onpass="IPV4: Successfully added single "
1295 + " point to multi point intents" +
1296 " with IPV4 type and MAC addresses",
1297 onfail="IPV4: Failed to add single point"
1298 + " point to multi point intents" +
1299 " with IPV4 type and MAC addresses" )
1300
1301 main.step( "IPV4_2: Add single point to multi point intents" )
1302 stepResult = main.TRUE
1303 hostNames = [ 'h8', 'h16', 'h24' ]
1304 stepResult = main.intentFunction.singleToMultiIntent(
1305 main,
1306 name="IPV4",
1307 hostNames=hostNames,
1308 ethType="IPV4",
1309 lambdaAlloc=False )
1310
1311 utilities.assert_equals( expect=main.TRUE,
1312 actual=stepResult,
1313 onpass="IPV4_2: Successfully added single "
1314 + " point to multi point intents" +
1315 " with IPV4 type and no MAC addresses",
1316 onfail="IPV4_2: Failed to add single point"
1317 + " point to multi point intents" +
1318 " with IPV4 type and no MAC addresses" )
1319
1320 main.step( "VLAN: Add single point to multi point intents" )
1321 stepResult = main.TRUE
1322 hostNames = [ 'h4', 'h12', 'h20' ]
1323 devices = [ 'of:0000000000000005/4', 'of:0000000000000006/4', \
1324 'of:0000000000000007/4' ]
1325 macs = [ '00:00:00:00:00:04', '00:00:00:00:00:0C', '00:00:00:00:00:14' ]
1326 stepResult = main.intentFunction.singleToMultiIntent(
1327 main,
1328 name="VLAN",
1329 hostNames=hostNames,
1330 devices=devices,
1331 ports=None,
1332 ethType="IPV4",
1333 macs=macs,
1334 bandwidth="",
1335 lambdaAlloc=False,
1336 ipProto="",
1337 ipAddresses="",
1338 tcp="",
1339 sw1="s5",
1340 sw2="s2",
1341 expectedLink=18 )
1342
1343 utilities.assert_equals( expect=main.TRUE,
1344 actual=stepResult,
1345 onpass="VLAN: Successfully added single "
1346 + " point to multi point intents" +
1347 " with IPV4 type and MAC addresses" +
1348 " in the same VLAN",
1349 onfail="VLAN: Failed to add single point"
1350 + " point to multi point intents" +
1351 " with IPV4 type and MAC addresses" +
1352 " in the same VLAN")
1353
1354 def CASE4000( self, main ):
1355 """
1356 Add multi point to single point intents
1357 - Get device ids
1358 - Add multi point to single point intents
1359 - Check intents
1360 - Verify flows
1361 - Ping hosts
1362 - Reroute
1363 - Link down
1364 - Verify flows
1365 - Check topology
1366 - Ping hosts
1367 - Link up
1368 - Verify flows
1369 - Check topology
1370 - Ping hosts
1371 - Remove intents
1372 """
1373 assert main, "There is no main"
1374 assert main.CLIs, "There is no main.CLIs"
1375 assert main.Mininet1, "Mininet handle should be named Mininet1"
1376 assert main.numSwitch, "Placed the total number of switch topology in \
1377 main.numSwitch"
1378
1379 main.case( "Multi To Single Point Intents Test - " +
1380 str( main.numCtrls ) + " NODE(S) - OF " + main.OFProtocol )
1381 main.caseExplanation = "This test case will test single point to" +\
1382 " multi point intents using " +\
1383 str( main.numCtrls ) + " node(s) cluster;\n" +\
1384 "Different type of hosts will be tested in " +\
1385 "each step such as IPV4, Dual stack, VLAN etc" +\
1386 ";\nThe test will use OF " + main.OFProtocol +\
1387 " OVS running in Mininet"
1388
1389 main.step( "NOOPTION: Add multi point to single point intents" )
1390 stepResult = main.TRUE
1391 hostNames = [ 'h8', 'h16', 'h24' ]
1392 devices = [ 'of:0000000000000005/8', 'of:0000000000000006/8', \
1393 'of:0000000000000007/8' ]
1394 macs = [ '00:00:00:00:00:08', '00:00:00:00:00:10', '00:00:00:00:00:18' ]
1395 stepResult = main.intentFunction.multiToSingleIntent(
1396 main,
1397 name="NOOPTION",
1398 hostNames=hostNames,
1399 devices=devices,
1400 sw1="s5",
1401 sw2="s2",
1402 expectedLink=18 )
1403
1404 utilities.assert_equals( expect=main.TRUE,
1405 actual=stepResult,
1406 onpass="NOOPTION: Successfully added multi "
1407 + " point to single point intents" +
1408 " with no match action",
1409 onfail="NOOPTION: Failed to add multi point" +
1410 " to single point intents" +
1411 " with no match action" )
1412
1413 main.step( "IPV4: Add multi point to single point intents" )
1414 stepResult = main.TRUE
1415 stepResult = main.intentFunction.multiToSingleIntent(
1416 main,
1417 name="IPV4",
1418 hostNames=hostNames,
1419 devices=devices,
1420 ports=None,
1421 ethType="IPV4",
1422 macs=macs,
1423 bandwidth="",
1424 lambdaAlloc=False,
1425 ipProto="",
1426 ipAddresses="",
1427 tcp="",
1428 sw1="s5",
1429 sw2="s2",
1430 expectedLink=18 )
1431
1432 utilities.assert_equals( expect=main.TRUE,
1433 actual=stepResult,
1434 onpass="IPV4: Successfully added multi point"
1435 + " to single point intents" +
1436 " with IPV4 type and MAC addresses",
1437 onfail="IPV4: Failed to add multi point" +
1438 " to single point intents" +
1439 " with IPV4 type and MAC addresses" )
1440
1441 main.step( "IPV4_2: Add multi point to single point intents" )
1442 stepResult = main.TRUE
1443 hostNames = [ 'h8', 'h16', 'h24' ]
1444 stepResult = main.intentFunction.multiToSingleIntent(
1445 main,
1446 name="IPV4",
1447 hostNames=hostNames,
1448 ethType="IPV4",
1449 lambdaAlloc=False )
1450
1451 utilities.assert_equals( expect=main.TRUE,
1452 actual=stepResult,
1453 onpass="IPV4_2: Successfully added multi point"
1454 + " to single point intents" +
1455 " with IPV4 type and no MAC addresses",
1456 onfail="IPV4_2: Failed to add multi point" +
1457 " to single point intents" +
1458 " with IPV4 type and no MAC addresses" )
1459
1460 main.step( "VLAN: Add multi point to single point intents" )
1461 stepResult = main.TRUE
1462 hostNames = [ 'h5', 'h13', 'h21' ]
1463 devices = [ 'of:0000000000000005/5', 'of:0000000000000006/5', \
1464 'of:0000000000000007/5' ]
1465 macs = [ '00:00:00:00:00:05', '00:00:00:00:00:0D', '00:00:00:00:00:15' ]
1466 stepResult = main.intentFunction.multiToSingleIntent(
1467 main,
1468 name="VLAN",
1469 hostNames=hostNames,
1470 devices=devices,
1471 ports=None,
1472 ethType="IPV4",
1473 macs=macs,
1474 bandwidth="",
1475 lambdaAlloc=False,
1476 ipProto="",
1477 ipAddresses="",
1478 tcp="",
1479 sw1="s5",
1480 sw2="s2",
1481 expectedLink=18 )
1482
1483 utilities.assert_equals( expect=main.TRUE,
1484 actual=stepResult,
1485 onpass="VLAN: Successfully added multi point"
1486 + " to single point intents" +
1487 " with IPV4 type and MAC addresses" +
1488 " in the same VLAN",
1489 onfail="VLAN: Failed to add multi point" +
1490 " to single point intents" )
1491
1492 def CASE5000( self, main ):
Jeremy2f190ca2016-01-29 15:23:57 -08001493 # """
1494 # Will add description in next patch set
1495 # """
1496 # assert main, "There is no main"
1497 # assert main.CLIs, "There is no main.CLIs"
1498 # assert main.Mininet1, "Mininet handle should be named Mininet1"
1499 # assert main.numSwitch, "Placed the total number of switch topology in \
1500 # main.numSwitch"
1501 # main.case( "Test host mobility with host intents " )
1502 # main.step( " Testing host mobility by moving h1 from s5 to s6" )
1503 # h1PreMove = main.hostsData[ "h1" ][ "location" ][ 0:19 ]
1504
1505 # main.log.info( "Moving h1 from s5 to s6")
1506
1507 # main.Mininet1.moveHost( "h1","s5","s6" )
1508
1509 # main.intentFunction.getHostsData( main )
1510 # h1PostMove = main.hostsData[ "h1" ][ "location" ][ 0:19 ]
1511
1512 # utilities.assert_equals( expect="of:0000000000000006",
1513 # actual=h1PostMove,
1514 # onpass="Mobility: Successfully moved h1 to s6",
1515 # onfail="Mobility: Failed to moved h1 to s6" +
1516 # " to single point intents" +
1517 # " with IPV4 type and MAC addresses" +
1518 # " in the same VLAN" )
1519
1520 # main.step( "IPV4: Add host intents between h1 and h9" )
1521 # stepResult = main.TRUE
1522 # stepResult = main.intentFunction.hostIntent( main,
1523 # onosNode='0',
1524 # name='IPV4',
1525 # host1='h1',
1526 # host2='h9',
1527 # host1Id='00:00:00:00:00:01/-1',
1528 # host2Id='00:00:00:00:00:09/-1' )
1529
1530 # utilities.assert_equals( expect=main.TRUE,
1531 # actual=stepResult,
1532 # onpass="IPV4: Host intent test successful " +
1533 # "between two IPV4 hosts",
1534 # onfail="IPV4: Host intent test failed " +
1535 # "between two IPV4 hosts")
kelvin-onlab44147802015-07-27 17:57:31 -07001536 """
Jeremy2f190ca2016-01-29 15:23:57 -08001537 Tests Host Mobility
1538 Modifies the topology location of h1
kelvin-onlab44147802015-07-27 17:57:31 -07001539 """
1540 assert main, "There is no main"
1541 assert main.CLIs, "There is no main.CLIs"
1542 assert main.Mininet1, "Mininet handle should be named Mininet1"
1543 assert main.numSwitch, "Placed the total number of switch topology in \
1544 main.numSwitch"
1545 main.case( "Test host mobility with host intents " )
Jeremy2f190ca2016-01-29 15:23:57 -08001546 main.step( "Testing host mobility by moving h1 from s5 to s6" )
kelvin-onlab44147802015-07-27 17:57:31 -07001547 h1PreMove = main.hostsData[ "h1" ][ "location" ][ 0:19 ]
1548
1549 main.log.info( "Moving h1 from s5 to s6")
kelvin-onlab44147802015-07-27 17:57:31 -07001550 main.Mininet1.moveHost( "h1","s5","s6" )
1551
Jeremy2f190ca2016-01-29 15:23:57 -08001552 # Send discovery ping from moved host
1553 # Moving the host brings down the default interfaces and creates a new one.
1554 # Scapy is restarted on this host to detect the new interface
1555 main.h1.stopScapy()
1556 main.h1.startScapy()
1557
1558 # Discover new host location in ONOS and populate host data.
1559 # Host 1 IP and MAC should be unchanged
1560 main.intentFunction.sendDiscoveryArp( main, [ main.h1 ] )
1561 main.intentFunction.populateHostData( main )
1562
kelvin-onlab44147802015-07-27 17:57:31 -07001563 h1PostMove = main.hostsData[ "h1" ][ "location" ][ 0:19 ]
1564
1565 utilities.assert_equals( expect="of:0000000000000006",
1566 actual=h1PostMove,
1567 onpass="Mobility: Successfully moved h1 to s6",
Jeremy2f190ca2016-01-29 15:23:57 -08001568 onfail="Mobility: Failed to move h1 to s6" +
kelvin-onlab44147802015-07-27 17:57:31 -07001569 " to single point intents" +
1570 " with IPV4 type and MAC addresses" +
1571 " in the same VLAN" )
1572
1573 main.step( "IPV4: Add host intents between h1 and h9" )
Jeremy2f190ca2016-01-29 15:23:57 -08001574 main.assertReturnString = "Assert result for IPV4 host intent between h1, moved, and h9\n"
1575 host1 = { "name":"h1","id":"00:00:00:00:00:01/-1" }
1576 host2 = { "name":"h9","id":"00:00:00:00:00:09/-1" }
1577
1578 installResult = main.intentFunction.installHostIntent( main,
1579 name='IPV4 Mobility IPV4',
kelvin-onlab44147802015-07-27 17:57:31 -07001580 onosNode='0',
Jeremy2f190ca2016-01-29 15:23:57 -08001581 host1=host1,
1582 host2=host2)
1583 if installResult:
1584 testResult = main.intentFunction.testHostIntent( main,
1585 name='Host Mobility IPV4',
1586 intentId = installResult,
1587 onosNode='0',
1588 host1=host1,
1589 host2=host2,
1590 sw1="s6",
1591 sw2="s2",
1592 expectedLink=18 )
kelvin-onlab44147802015-07-27 17:57:31 -07001593
1594 utilities.assert_equals( expect=main.TRUE,
Jeremy2f190ca2016-01-29 15:23:57 -08001595 actual=testResult,
1596 onpass=main.assertReturnString,
1597 onfail=main.assertReturnString )
1598
1599 main.intentFunction.report( main )
1600