blob: 8f8f677f44f986321ad1d2ff9d31f69d1c254516 [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' ] )
Jeremy Songster306ed7a2016-07-19 10:59:07 -070062 main.flowDurationSleep = int( main.params[ 'SLEEP' ][ 'flowDuration' ] )
kelvin-onlab44147802015-07-27 17:57:31 -070063 gitPull = main.params[ 'GIT' ][ 'pull' ]
64 main.numSwitch = int( main.params[ 'MININET' ][ 'switch' ] )
65 main.numLinks = int( main.params[ 'MININET' ][ 'links' ] )
66 main.cellData = {} # for creating cell file
67 main.hostsData = {}
Jeremy Songstere7f3b342016-08-17 14:56:49 -070068 main.RESTs = []
kelvin-onlab44147802015-07-27 17:57:31 -070069 main.CLIs = []
70 main.ONOSip = []
Jeremy2f190ca2016-01-29 15:23:57 -080071 main.scapyHostNames = main.params[ 'SCAPY' ][ 'HOSTNAMES' ].split( ',' )
72 main.scapyHosts = [] # List of scapy hosts for iterating
73 main.assertReturnString = '' # Assembled assert return string
Jeremy Songster17147f22016-05-31 18:30:52 -070074 main.cycle = 0 # How many times FUNCintent has run through its tests
kelvin-onlab44147802015-07-27 17:57:31 -070075
76 main.ONOSip = main.ONOSbench.getOnosIps()
Jeremy2f190ca2016-01-29 15:23:57 -080077 print main.ONOSip
kelvin-onlab44147802015-07-27 17:57:31 -070078
79 # Assigning ONOS cli handles to a list
Jon Hallf7234882015-08-28 13:16:31 -070080 try:
81 for i in range( 1, main.maxNodes + 1 ):
Jeremy Songstere7f3b342016-08-17 14:56:49 -070082 main.RESTs.append( getattr( main, 'ONOSrest' + str( i ) ) )
83 main.CLIs.append( getattr( main, 'ONOScli' + str( i ) ) )
Jon Hallf7234882015-08-28 13:16:31 -070084 except AttributeError:
85 main.log.warn( "A " + str( main.maxNodes ) + " node cluster " +
86 "was defined in env variables, but only " +
Jeremy Songstere7f3b342016-08-17 14:56:49 -070087 str( len( main.RESTs ) ) +
Jon Hallf7234882015-08-28 13:16:31 -070088 " nodes were defined in the .topo file. " +
Jeremy Songstere7f3b342016-08-17 14:56:49 -070089 "Using " + str( len( main.RESTs ) ) +
Jon Hallf7234882015-08-28 13:16:31 -070090 " nodes for the test." )
kelvin-onlab44147802015-07-27 17:57:31 -070091
92 # -- INIT SECTION, ONLY RUNS ONCE -- #
93 main.startUp = imp.load_source( wrapperFile1,
94 main.dependencyPath +
95 wrapperFile1 +
96 ".py" )
97
98 main.intentFunction = imp.load_source( wrapperFile2,
99 main.dependencyPath +
100 wrapperFile2 +
101 ".py" )
102
103 main.topo = imp.load_source( wrapperFile3,
104 main.dependencyPath +
105 wrapperFile3 +
106 ".py" )
107
Jon Hallf7234882015-08-28 13:16:31 -0700108 copyResult1 = main.ONOSbench.scp( main.Mininet1,
109 main.dependencyPath +
110 main.topology,
Jeremy2f190ca2016-01-29 15:23:57 -0800111 main.Mininet1.home + "custom/",
Jon Hallf7234882015-08-28 13:16:31 -0700112 direction="to" )
Jeremy Songstere7f3b342016-08-17 14:56:49 -0700113 if main.RESTs and main.CLIs:
kelvin-onlab44147802015-07-27 17:57:31 -0700114 stepResult = main.TRUE
115 else:
116 main.log.error( "Did not properly created list of ONOS CLI handle" )
117 stepResult = main.FALSE
118 except Exception as e:
Jeremy Songstere7f3b342016-08-17 14:56:49 -0700119 main.log.exception( e )
kelvin-onlab44147802015-07-27 17:57:31 -0700120 main.cleanup()
121 main.exit()
122
123 utilities.assert_equals( expect=main.TRUE,
124 actual=stepResult,
125 onpass="Successfully construct " +
126 "test variables ",
127 onfail="Failed to construct test variables" )
128
129 if gitPull == 'True':
130 main.step( "Building ONOS in " + gitBranch + " branch" )
131 onosBuildResult = main.startUp.onosBuild( main, gitBranch )
132 stepResult = onosBuildResult
133 utilities.assert_equals( expect=main.TRUE,
134 actual=stepResult,
135 onpass="Successfully compiled " +
136 "latest ONOS",
137 onfail="Failed to compile " +
138 "latest ONOS" )
139 else:
140 main.log.warn( "Did not pull new code so skipping mvn " +
141 "clean install" )
142 main.ONOSbench.getVersion( report=True )
143
144 def CASE2( self, main ):
145 """
146 - Set up cell
147 - Create cell file
148 - Set cell file
149 - Verify cell file
150 - Kill ONOS process
151 - Uninstall ONOS cluster
152 - Verify ONOS start up
153 - Install ONOS cluster
154 - Connect to cli
155 """
156
Jeremy Songster17147f22016-05-31 18:30:52 -0700157 main.cycle += 1
158
kelvin-onlab44147802015-07-27 17:57:31 -0700159 # main.scale[ 0 ] determines the current number of ONOS controller
160 main.numCtrls = int( main.scale[ 0 ] )
Jeremyeb51cb12016-03-28 17:53:35 -0700161 main.flowCompiler = "Flow Rules"
Jeremydd9bda62016-04-18 12:02:32 -0700162 main.initialized = main.TRUE
kelvin-onlab44147802015-07-27 17:57:31 -0700163
164 main.case( "Starting up " + str( main.numCtrls ) +
165 " node(s) ONOS cluster" )
166 main.caseExplanation = "Set up ONOS with " + str( main.numCtrls ) +\
167 " node(s) ONOS cluster"
168
169
170
171 #kill off all onos processes
172 main.log.info( "Safety check, killing all ONOS processes" +
Jon Hall70b2ff42015-11-17 15:49:44 -0800173 " before initiating environment setup" )
kelvin-onlab44147802015-07-27 17:57:31 -0700174
Jeremy2f190ca2016-01-29 15:23:57 -0800175 time.sleep( main.startUpSleep )
Jeremy42df2e72016-02-23 16:37:46 -0800176
Jeremy2f190ca2016-01-29 15:23:57 -0800177 main.step( "Uninstalling ONOS package" )
178 onosUninstallResult = main.TRUE
179 for ip in main.ONOSip:
180 onosUninstallResult = onosUninstallResult and \
181 main.ONOSbench.onosUninstall( nodeIp=ip )
182 stepResult = onosUninstallResult
183 utilities.assert_equals( expect=main.TRUE,
184 actual=stepResult,
185 onpass="Successfully uninstalled ONOS package",
186 onfail="Failed to uninstall ONOS package" )
187
Jeremy42df2e72016-02-23 16:37:46 -0800188 time.sleep( main.startUpSleep )
189
kelvin-onlab44147802015-07-27 17:57:31 -0700190 for i in range( main.maxNodes ):
191 main.ONOSbench.onosDie( main.ONOSip[ i ] )
192
193 print "NODE COUNT = ", main.numCtrls
194
195 tempOnosIp = []
196 for i in range( main.numCtrls ):
197 tempOnosIp.append( main.ONOSip[i] )
198
199 main.ONOSbench.createCellFile( main.ONOSbench.ip_address,
200 "temp", main.Mininet1.ip_address,
201 main.apps, tempOnosIp )
202
203 main.step( "Apply cell to environment" )
204 cellResult = main.ONOSbench.setCell( "temp" )
205 verifyResult = main.ONOSbench.verifyCell()
206 stepResult = cellResult and verifyResult
207 utilities.assert_equals( expect=main.TRUE,
208 actual=stepResult,
209 onpass="Successfully applied cell to " + \
210 "environment",
211 onfail="Failed to apply cell to environment " )
212
213 main.step( "Creating ONOS package" )
Jon Hallbd60ea02016-08-23 10:03:59 -0700214 packageResult = main.ONOSbench.buckBuild()
kelvin-onlab44147802015-07-27 17:57:31 -0700215 stepResult = packageResult
216 utilities.assert_equals( expect=main.TRUE,
217 actual=stepResult,
218 onpass="Successfully created ONOS package",
219 onfail="Failed to create ONOS package" )
220
221 time.sleep( main.startUpSleep )
kelvin-onlab44147802015-07-27 17:57:31 -0700222 main.step( "Installing ONOS package" )
223 onosInstallResult = main.TRUE
224 for i in range( main.numCtrls ):
225 onosInstallResult = onosInstallResult and \
226 main.ONOSbench.onosInstall( node=main.ONOSip[ i ] )
227 stepResult = onosInstallResult
228 utilities.assert_equals( expect=main.TRUE,
229 actual=stepResult,
230 onpass="Successfully installed ONOS package",
231 onfail="Failed to install ONOS package" )
232
You Wangf5de25b2017-01-06 15:13:01 -0800233 main.step( "Set up ONOS secure SSH" )
234 secureSshResult = main.TRUE
235 for i in range( int( main.numCtrls ) ):
236 secureSshResult = secureSshResult and main.ONOSbench.onosSecureSSH( node=main.ONOSip[i] )
237 utilities.assert_equals( expect=main.TRUE, actual=secureSshResult,
238 onpass="Test step PASS",
239 onfail="Test step FAIL" )
240
kelvin-onlab44147802015-07-27 17:57:31 -0700241 time.sleep( main.startUpSleep )
242 main.step( "Starting ONOS service" )
243 stopResult = main.TRUE
244 startResult = main.TRUE
245 onosIsUp = main.TRUE
246
247 for i in range( main.numCtrls ):
248 onosIsUp = onosIsUp and main.ONOSbench.isup( main.ONOSip[ i ] )
Jeremydd9bda62016-04-18 12:02:32 -0700249 if onosIsUp == main.TRUE:
250 main.log.report( "ONOS instance {0} is up and ready".format( i + 1 ) )
251 else:
252 main.log.report( "ONOS instance {0} may not be up, stop and ".format( i + 1 ) +
253 "start ONOS again " )
254 stopResult = stopResult and main.ONOSbench.onosStop( main.ONOSip[ i ] )
255 startResult = startResult and main.ONOSbench.onosStart( main.ONOSip[ i ] )
256 if not startResult or stopResult:
257 main.log.report( "ONOS instance {0} did not start correctly.".format( i + 1 ) )
kelvin-onlab44147802015-07-27 17:57:31 -0700258 stepResult = onosIsUp and stopResult and startResult
259 utilities.assert_equals( expect=main.TRUE,
260 actual=stepResult,
261 onpass="ONOS service is ready",
262 onfail="ONOS service did not start properly" )
Jeremydd9bda62016-04-18 12:02:32 -0700263 if not stepResult:
264 main.initialized = main.FALSE
kelvin-onlab44147802015-07-27 17:57:31 -0700265
Jeremy2f190ca2016-01-29 15:23:57 -0800266 # Start an ONOS cli to provide functionality that is not currently
Jeremye1ea0602016-02-08 16:35:05 -0800267 # supported by the Rest API remove this when Leader Checking is supported
268 # by the REST API
Jeremy2f190ca2016-01-29 15:23:57 -0800269
Jeremye1ea0602016-02-08 16:35:05 -0800270 main.step( "Start ONOS cli" )
271 cliResult = main.TRUE
272 for i in range( main.numCtrls ):
273 cliResult = cliResult and \
Jeremy Songstere7f3b342016-08-17 14:56:49 -0700274 main.CLIs[ i ].startOnosCli( main.ONOSip[ i ] )
Jeremye1ea0602016-02-08 16:35:05 -0800275 stepResult = cliResult
276 utilities.assert_equals( expect=main.TRUE,
277 actual=stepResult,
278 onpass="Successfully start ONOS cli",
279 onfail="Failed to start ONOS cli" )
Jeremydd9bda62016-04-18 12:02:32 -0700280 if not stepResult:
281 main.initialized = main.FALSE
Jeremy2f190ca2016-01-29 15:23:57 -0800282
kelvin-onlab44147802015-07-27 17:57:31 -0700283 # Remove the first element in main.scale list
284 main.scale.remove( main.scale[ 0 ] )
285
Jeremy2f190ca2016-01-29 15:23:57 -0800286 main.intentFunction.report( main )
287
kelvin-onlab44147802015-07-27 17:57:31 -0700288 def CASE8( self, main ):
Jeremy2f190ca2016-01-29 15:23:57 -0800289 # OLD FUNCintentRest CASE 8
290 # This remains here for archiving and reference purposes and will be
291 # removed when the new FUNCintentRest is verified to work.
292 # """
293 # Compare Topo
294 # """
295 # import json
296
297 # main.case( "Compare ONOS Topology view to Mininet topology" )
298 # main.caseExplanation = "Compare topology elements between Mininet" +\
299 # " and ONOS"
300
301 # main.step( "Gathering topology information" )
302 # # TODO: add a paramaterized sleep here
303 # devicesResults = main.TRUE # Overall Boolean for device correctness
304 # linksResults = main.TRUE # Overall Boolean for link correctness
305 # hostsResults = main.TRUE # Overall Boolean for host correctness
306 # devices = main.topo.getAllDevices( main )
307 # hosts = main.topo.getAllHosts( main )
308 # ports = main.topo.getAllPorts( main )
309 # links = main.topo.getAllLinks( main )
310 # clusters = main.topo.getAllClusters( main )
311
312 # mnSwitches = main.Mininet1.getSwitches()
313 # mnLinks = main.Mininet1.getLinks()
314 # mnHosts = main.Mininet1.getHosts()
315
316 # main.step( "Comparing MN topology to ONOS topology" )
317 # for controller in range( main.numCtrls ):
318 # controllerStr = str( controller + 1 )
319 # if devices[ controller ] and ports[ controller ] and\
320 # "Error" not in devices[ controller ] and\
321 # "Error" not in ports[ controller ]:
322
323 # currentDevicesResult = main.Mininet1.compareSwitches(
324 # mnSwitches,
325 # json.loads( devices[ controller ] ),
326 # json.loads( ports[ controller ] ) )
327 # else:
328 # currentDevicesResult = main.FALSE
329 # utilities.assert_equals( expect=main.TRUE,
330 # actual=currentDevicesResult,
331 # onpass="ONOS" + controllerStr +
332 # " Switches view is correct",
333 # onfail="ONOS" + controllerStr +
334 # " Switches view is incorrect" )
335
336 # if links[ controller ] and "Error" not in links[ controller ]:
337 # currentLinksResult = main.Mininet1.compareLinks(
338 # mnSwitches, mnLinks,
339 # json.loads( links[ controller ] ) )
340 # else:
341 # currentLinksResult = main.FALSE
342 # utilities.assert_equals( expect=main.TRUE,
343 # actual=currentLinksResult,
344 # onpass="ONOS" + controllerStr +
345 # " links view is correct",
346 # onfail="ONOS" + controllerStr +
347 # " links view is incorrect" )
348
349 # if hosts[ controller ] or "Error" not in hosts[ controller ]:
350 # currentHostsResult = main.Mininet1.compareHosts(
351 # mnHosts,
352 # json.loads( hosts[ controller ] ) )
353 # else:
354 # currentHostsResult = main.FALSE
355 # utilities.assert_equals( expect=main.TRUE,
356 # actual=currentHostsResult,
357 # onpass="ONOS" + controllerStr +
358 # " hosts exist in Mininet",
359 # onfail="ONOS" + controllerStr +
360 # " hosts don't match Mininet" )
361
362 # NEW FUNCintentRest Case 8 as based off of the CASE 8 from FUNCintent
kelvin-onlab44147802015-07-27 17:57:31 -0700363 """
Jeremy2f190ca2016-01-29 15:23:57 -0800364 Compare ONOS Topology to Mininet Topology
kelvin-onlab44147802015-07-27 17:57:31 -0700365 """
366 import json
367
368 main.case( "Compare ONOS Topology view to Mininet topology" )
369 main.caseExplanation = "Compare topology elements between Mininet" +\
370 " and ONOS"
371
Jeremy2f190ca2016-01-29 15:23:57 -0800372 main.log.info( "Gathering topology information from Mininet" )
373 devicesResults = main.FALSE # Overall Boolean for device correctness
374 linksResults = main.FALSE # Overall Boolean for link correctness
375 hostsResults = main.FALSE # Overall Boolean for host correctness
376 deviceFails = [] # Nodes where devices are incorrect
377 linkFails = [] # Nodes where links are incorrect
378 hostFails = [] # Nodes where hosts are incorrect
379 attempts = main.checkTopoAttempts # Remaining Attempts
kelvin-onlab44147802015-07-27 17:57:31 -0700380
381 mnSwitches = main.Mininet1.getSwitches()
382 mnLinks = main.Mininet1.getLinks()
383 mnHosts = main.Mininet1.getHosts()
384
Jeremy2f190ca2016-01-29 15:23:57 -0800385 main.step( "Comparing Mininet topology to ONOS topology" )
kelvin-onlab44147802015-07-27 17:57:31 -0700386
Jeremy2f190ca2016-01-29 15:23:57 -0800387 while ( attempts >= 0 ) and\
388 ( not devicesResults or not linksResults or not hostsResults ):
389 time.sleep( 2 )
390 if not devicesResults:
391 devices = main.topo.getAllDevices( main )
392 ports = main.topo.getAllPorts( main )
393 devicesResults = main.TRUE
394 deviceFails = [] # Reset for each failed attempt
395 if not linksResults:
396 links = main.topo.getAllLinks( main )
397 linksResults = main.TRUE
398 linkFails = [] # Reset for each failed attempt
399 if not hostsResults:
400 hosts = main.topo.getAllHosts( main )
401 hostsResults = main.TRUE
402 hostFails = [] # Reset for each failed attempt
kelvin-onlab44147802015-07-27 17:57:31 -0700403
Jeremy2f190ca2016-01-29 15:23:57 -0800404 # Check for matching topology on each node
405 for controller in range( main.numCtrls ):
406 controllerStr = str( controller + 1 ) # ONOS node number
407 # Compare Devices
408 if devices[ controller ] and ports[ controller ] and\
409 "Error" not in devices[ controller ] and\
410 "Error" not in ports[ controller ]:
kelvin-onlab44147802015-07-27 17:57:31 -0700411
Jeremy2f190ca2016-01-29 15:23:57 -0800412 try:
413 deviceData = json.loads( devices[ controller ] )
414 portData = json.loads( ports[ controller ] )
415 except (TypeError,ValueError):
Ming Yan Shuab2f7f52016-08-03 15:21:24 -0700416 main.log.error( "Could not load json: {0} or {1}".format( str( devices[ controller ] ),
417 str( ports[ controller ] ) ) )
Jeremy2f190ca2016-01-29 15:23:57 -0800418 currentDevicesResult = main.FALSE
419 else:
420 currentDevicesResult = main.Mininet1.compareSwitches(
421 mnSwitches,deviceData,portData )
422 else:
423 currentDevicesResult = main.FALSE
424 if not currentDevicesResult:
425 deviceFails.append( controllerStr )
426 devicesResults = devicesResults and currentDevicesResult
427 # Compare Links
428 if links[ controller ] and "Error" not in links[ controller ]:
429 try:
430 linkData = json.loads( links[ controller ] )
431 except (TypeError,ValueError):
432 main.log.error("Could not load json:" + str( links[ controller ] ) )
433 currentLinksResult = main.FALSE
434 else:
435 currentLinksResult = main.Mininet1.compareLinks(
436 mnSwitches, mnLinks,linkData )
437 else:
438 currentLinksResult = main.FALSE
439 if not currentLinksResult:
440 linkFails.append( controllerStr )
441 linksResults = linksResults and currentLinksResult
442 # Compare Hosts
443 if hosts[ controller ] and "Error" not in hosts[ controller ]:
444 try:
445 hostData = json.loads( hosts[ controller ] )
446 except (TypeError,ValueError):
447 main.log.error("Could not load json:" + str( hosts[ controller ] ) )
448 currentHostsResult = main.FALSE
449 else:
450 currentHostsResult = main.Mininet1.compareHosts(
451 mnHosts,hostData )
452 else:
453 currentHostsResult = main.FALSE
454 if not currentHostsResult:
455 hostFails.append( controllerStr )
456 hostsResults = hostsResults and currentHostsResult
457 # Decrement Attempts Remaining
458 attempts -= 1
459
460
461 utilities.assert_equals( expect=[],
462 actual=deviceFails,
463 onpass="ONOS correctly discovered all devices",
464 onfail="ONOS incorrectly discovered devices on nodes: " +
465 str( deviceFails ) )
466 utilities.assert_equals( expect=[],
467 actual=linkFails,
468 onpass="ONOS correctly discovered all links",
469 onfail="ONOS incorrectly discovered links on nodes: " +
470 str( linkFails ) )
471 utilities.assert_equals( expect=[],
472 actual=hostFails,
473 onpass="ONOS correctly discovered all hosts",
474 onfail="ONOS incorrectly discovered hosts on nodes: " +
475 str( hostFails ) )
476 topoResults = hostsResults and linksResults and devicesResults
477 utilities.assert_equals( expect=main.TRUE,
478 actual=topoResults,
479 onpass="ONOS correctly discovered the topology",
480 onfail="ONOS incorrectly discovered the topology" )
kelvin-onlab44147802015-07-27 17:57:31 -0700481
482 def CASE9( self, main ):
483 '''
484 Report errors/warnings/exceptions
485 '''
486 main.log.info( "Error report: \n" )
Jeremy Songstere7f3b342016-08-17 14:56:49 -0700487 main.ONOSbench.logReport( globalONOSip[ 0 ],
kelvin-onlab44147802015-07-27 17:57:31 -0700488 [ "INFO", "FOLLOWER", "WARN", "flow", "ERROR" , "Except" ],
489 "s" )
490 #main.ONOSbench.logReport( globalONOSip[1], [ "INFO" ], "d" )
491
492 def CASE10( self, main ):
493 """
494 Start Mininet topology with OF 1.0 switches
495 """
Jeremydd9bda62016-04-18 12:02:32 -0700496 if main.initialized == main.FALSE:
497 main.log.error( "Test components did not start correctly, skipping further tests" )
498 main.skipCase()
kelvin-onlab44147802015-07-27 17:57:31 -0700499 main.OFProtocol = "1.0"
500 main.log.report( "Start Mininet topology with OF 1.0 switches" )
501 main.case( "Start Mininet topology with OF 1.0 switches" )
502 main.caseExplanation = "Start mininet topology with OF 1.0 " +\
503 "switches to test intents, exits out if " +\
504 "topology did not start correctly"
505
506 main.step( "Starting Mininet topology with OF 1.0 switches" )
507 args = "--switch ovs,protocols=OpenFlow10"
508 topoResult = main.Mininet1.startNet( topoFile=main.dependencyPath +
509 main.topology,
510 args=args )
511 stepResult = topoResult
512 utilities.assert_equals( expect=main.TRUE,
513 actual=stepResult,
514 onpass="Successfully loaded topology",
515 onfail="Failed to load topology" )
516 # Exit if topology did not load properly
517 if not topoResult:
Jeremydd9bda62016-04-18 12:02:32 -0700518 main.initialized = main.FALSE
kelvin-onlab44147802015-07-27 17:57:31 -0700519
520 def CASE11( self, main ):
521 """
522 Start Mininet topology with OF 1.3 switches
523 """
Jeremydd9bda62016-04-18 12:02:32 -0700524 if main.initialized == main.FALSE:
525 main.log.error( "Test components did not start correctly, skipping further tests" )
526 main.skipCase()
kelvin-onlab44147802015-07-27 17:57:31 -0700527 main.OFProtocol = "1.3"
528 main.log.report( "Start Mininet topology with OF 1.3 switches" )
529 main.case( "Start Mininet topology with OF 1.3 switches" )
530 main.caseExplanation = "Start mininet topology with OF 1.3 " +\
531 "switches to test intents, exits out if " +\
532 "topology did not start correctly"
533
534 main.step( "Starting Mininet topology with OF 1.3 switches" )
535 args = "--switch ovs,protocols=OpenFlow13"
536 topoResult = main.Mininet1.startNet( topoFile=main.dependencyPath +
537 main.topology,
538 args=args )
539 stepResult = topoResult
540 utilities.assert_equals( expect=main.TRUE,
541 actual=stepResult,
542 onpass="Successfully loaded topology",
543 onfail="Failed to load topology" )
544 # Exit if topology did not load properly
545 if not topoResult:
Jeremydd9bda62016-04-18 12:02:32 -0700546 main.initialized = main.FALSE
kelvin-onlab44147802015-07-27 17:57:31 -0700547
548 def CASE12( self, main ):
549 """
550 Assign mastership to controllers
551 """
552 import re
553
Jeremydd9bda62016-04-18 12:02:32 -0700554 if main.initialized == main.FALSE:
555 main.log.error( "Test components did not start correctly, skipping further tests" )
556 main.skipCase()
kelvin-onlab44147802015-07-27 17:57:31 -0700557 main.case( "Assign switches to controllers" )
558 main.step( "Assigning switches to controllers" )
559 main.caseExplanation = "Assign OF " + main.OFProtocol +\
560 " switches to ONOS nodes"
561
562 assignResult = main.TRUE
563 switchList = []
564
565 # Creates a list switch name, use getSwitch() function later...
566 for i in range( 1, ( main.numSwitch + 1 ) ):
567 switchList.append( 's' + str( i ) )
568
569 tempONOSip = []
570 for i in range( main.numCtrls ):
571 tempONOSip.append( main.ONOSip[ i ] )
572
573 assignResult = main.Mininet1.assignSwController( sw=switchList,
574 ip=tempONOSip,
Charles Chan029be652015-08-24 01:46:10 +0800575 port='6653' )
kelvin-onlab44147802015-07-27 17:57:31 -0700576 if not assignResult:
Jeremydd9bda62016-04-18 12:02:32 -0700577 main.log.error( "Problem assigning mastership of switches, skipping further test cases" )
578 main.initialized = main.FALSE
579 main.skipCase()
kelvin-onlab44147802015-07-27 17:57:31 -0700580
581 for i in range( 1, ( main.numSwitch + 1 ) ):
582 response = main.Mininet1.getSwController( "s" + str( i ) )
583 print( "Response is " + str( response ) )
584 if re.search( "tcp:" + main.ONOSip[ 0 ], response ):
585 assignResult = assignResult and main.TRUE
586 else:
587 assignResult = main.FALSE
588 stepResult = assignResult
589 utilities.assert_equals( expect=main.TRUE,
590 actual=stepResult,
591 onpass="Successfully assigned switches" +
592 "to controller",
593 onfail="Failed to assign switches to " +
594 "controller" )
Jeremydd9bda62016-04-18 12:02:32 -0700595 if not stepResult:
596 main.initialized = main.FALSE
Jeremy2f190ca2016-01-29 15:23:57 -0800597
598 def CASE13( self,main ):
599 """
600 Create Scapy components
601 """
Jeremydd9bda62016-04-18 12:02:32 -0700602 if main.initialized == main.FALSE:
603 main.log.error( "Test components did not start correctly, skipping further tests" )
604 main.skipCase()
Jeremy2f190ca2016-01-29 15:23:57 -0800605 main.case( "Create scapy components" )
606 main.step( "Create scapy components" )
607 import json
608 scapyResult = main.TRUE
609 for hostName in main.scapyHostNames:
610 main.Scapy1.createHostComponent( hostName )
611 main.scapyHosts.append( getattr( main, hostName ) )
612
613 main.step( "Start scapy components" )
614 for host in main.scapyHosts:
615 host.startHostCli()
616 host.startScapy()
617 host.updateSelf()
618 main.log.debug( host.name )
619 main.log.debug( host.hostIp )
620 main.log.debug( host.hostMac )
621
622
623 utilities.assert_equals( expect=main.TRUE,
624 actual=scapyResult,
625 onpass="Successfully created Scapy Components",
626 onfail="Failed to discover Scapy Components" )
Jeremydd9bda62016-04-18 12:02:32 -0700627 if not scapyResult:
628 main.initialized = main.FALSE
Jeremy2f190ca2016-01-29 15:23:57 -0800629
630 def CASE14( self, main ):
kelvin-onlab44147802015-07-27 17:57:31 -0700631 """
632 Discover all hosts and store its data to a dictionary
633 """
Jeremydd9bda62016-04-18 12:02:32 -0700634 if main.initialized == main.FALSE:
635 main.log.error( "Test components did not start correctly, skipping further tests" )
636 main.skipCase()
kelvin-onlab44147802015-07-27 17:57:31 -0700637 main.case( "Discover all hosts" )
638
639 stepResult = main.TRUE
kelvin-onlab0e684682015-08-11 18:51:41 -0700640 main.step( "Discover all ipv4 host hosts " )
641 hostList = []
642 # List of host with default vlan
643 defaultHosts = [ "h1", "h3", "h8", "h9", "h11", "h16", "h17", "h19", "h24" ]
644 # Lists of host with unique vlan
645 vlanHosts1 = [ "h4", "h12", "h20" ]
646 vlanHosts2 = [ "h5", "h13", "h21" ]
647 vlanHosts3 = [ "h6", "h14", "h22" ]
648 vlanHosts4 = [ "h7", "h15", "h23" ]
649 hostList.append( defaultHosts )
650 hostList.append( vlanHosts1 )
651 hostList.append( vlanHosts2 )
652 hostList.append( vlanHosts3 )
653 hostList.append( vlanHosts4 )
654
655 stepResult = main.intentFunction.getHostsData( main, hostList )
kelvin-onlab44147802015-07-27 17:57:31 -0700656 utilities.assert_equals( expect=main.TRUE,
657 actual=stepResult,
658 onpass="Successfully discovered hosts",
659 onfail="Failed to discover hosts" )
Jeremydd9bda62016-04-18 12:02:32 -0700660 if not stepResult:
661 main.initialized = main.FALSE
kelvin-onlab44147802015-07-27 17:57:31 -0700662
Jeremy2f190ca2016-01-29 15:23:57 -0800663 def CASE15( self, main ):
kelvin-onlab44147802015-07-27 17:57:31 -0700664 """
Jeremy2f190ca2016-01-29 15:23:57 -0800665 Discover all hosts with scapy arp packets and store its data to a dictionary
kelvin-onlab44147802015-07-27 17:57:31 -0700666 """
Jeremydd9bda62016-04-18 12:02:32 -0700667 if main.initialized == main.FALSE:
668 main.log.error( "Test components did not start correctly, skipping further tests" )
669 main.skipCase()
Jeremy2f190ca2016-01-29 15:23:57 -0800670 main.case( "Discover all hosts using scapy" )
671 main.step( "Send packets from each host to the first host and confirm onos discovery" )
672
673 import collections
674 if len( main.scapyHosts ) < 1:
675 main.log.error( "No scapy hosts have been created" )
Jeremydd9bda62016-04-18 12:02:32 -0700676 main.initialized = main.FALSE
Jeremy2f190ca2016-01-29 15:23:57 -0800677 main.skipCase()
678
679 # Send ARP packets from each scapy host component
680 main.intentFunction.sendDiscoveryArp( main, main.scapyHosts )
681
682 stepResult = utilities.retry( f=main.intentFunction.confirmHostDiscovery,
683 retValue=main.FALSE, args=[ main ],
684 attempts=main.checkTopoAttempts, sleep=2 )
685
686 utilities.assert_equals( expect=main.TRUE,
687 actual=stepResult,
688 onpass="ONOS correctly discovered all hosts",
689 onfail="ONOS incorrectly discovered hosts" )
Jeremydd9bda62016-04-18 12:02:32 -0700690 if not stepResult:
691 main.initialized = main.FALSE
692 main.skipCase()
Jeremy2f190ca2016-01-29 15:23:57 -0800693
694 main.step( "Populate hostsData" )
695 stepResult = main.intentFunction.populateHostData( main )
696 utilities.assert_equals( expect=main.TRUE,
697 actual=stepResult,
698 onpass="Successfully populated hostsData",
699 onfail="Failed to populate hostsData" )
Jeremydd9bda62016-04-18 12:02:32 -0700700 if not stepResult:
701 main.initialized = main.FALSE
Jeremy2f190ca2016-01-29 15:23:57 -0800702
703 def CASE16( self, main ):
704 """
Jeremy42df2e72016-02-23 16:37:46 -0800705 Balance Masters
706 """
Jeremydd9bda62016-04-18 12:02:32 -0700707 if main.initialized == main.FALSE:
708 main.log.error( "Test components did not start correctly, skipping further tests" )
709 main.skipCase()
Jeremy42df2e72016-02-23 16:37:46 -0800710 main.case( "Balance mastership of switches" )
711 main.step( "Balancing mastership of switches" )
712
713 balanceResult = main.FALSE
Jeremy Songstere7f3b342016-08-17 14:56:49 -0700714 balanceResult = utilities.retry( f=main.CLIs[ 0 ].balanceMasters, retValue=main.FALSE, args=[] )
Jeremy42df2e72016-02-23 16:37:46 -0800715
716 utilities.assert_equals( expect=main.TRUE,
717 actual=stepResult,
718 onpass="Successfully balanced mastership of switches",
719 onfail="Failed to balance mastership of switches" )
Jeremydd9bda62016-04-18 12:02:32 -0700720 if not stepResult:
721 main.initialized = main.FALSE
Jeremy42df2e72016-02-23 16:37:46 -0800722
723 def CASE17( self, main ):
724 """
Jeremyeb51cb12016-03-28 17:53:35 -0700725 Use Flow Objectives
726 """
Jeremydd9bda62016-04-18 12:02:32 -0700727 if main.initialized == main.FALSE:
728 main.log.error( "Test components did not start correctly, skipping further tests" )
729 main.skipCase()
Jeremyeb51cb12016-03-28 17:53:35 -0700730 main.case( "Enable intent compilation using Flow Objectives" )
731 main.step( "Enabling Flow Objectives" )
732
733 main.flowCompiler = "Flow Objectives"
734
735 cmd = "org.onosproject.net.intent.impl.compiler.IntentConfigurableRegistrator"
736
Jeremy Songstere7f3b342016-08-17 14:56:49 -0700737 stepResult = main.CLIs[ 0 ].setCfg( component=cmd,
Jeremyeb51cb12016-03-28 17:53:35 -0700738 propName="useFlowObjectives", value="true" )
You Wang106d0fa2017-05-15 17:22:15 -0700739 stepResult &= main.CLIs[ 0 ].setCfg( component=cmd,
740 propName="defaultFlowObjectiveCompiler",
741 value='org.onosproject.net.intent.impl.compiler.LinkCollectionIntentObjectiveCompiler')
Jeremyeb51cb12016-03-28 17:53:35 -0700742
743 utilities.assert_equals( expect=main.TRUE,
744 actual=stepResult,
745 onpass="Successfully activated Flow Objectives",
746 onfail="Failed to activate Flow Objectives" )
Jeremydd9bda62016-04-18 12:02:32 -0700747 if not stepResult:
748 main.initialized = main.FALSE
Jeremyeb51cb12016-03-28 17:53:35 -0700749
750 def CASE18( self, main ):
751 """
Jeremy2f190ca2016-01-29 15:23:57 -0800752 Stop mininet and remove scapy hosts
753 """
754 main.log.report( "Stop Mininet and Scapy" )
755 main.case( "Stop Mininet and Scapy" )
kelvin-onlab44147802015-07-27 17:57:31 -0700756 main.caseExplanation = "Stopping the current mininet topology " +\
757 "to start up fresh"
758
Jeremy2f190ca2016-01-29 15:23:57 -0800759 main.step( "Stopping and Removing Scapy Host Components" )
760 scapyResult = main.TRUE
761 for host in main.scapyHosts:
762 scapyResult = scapyResult and host.stopScapy()
763 main.log.info( "Stopped Scapy Host: {0}".format( host.name ) )
764
765 for host in main.scapyHosts:
766 scapyResult = scapyResult and main.Scapy1.removeHostComponent( host.name )
767 main.log.info( "Removed Scapy Host Component: {0}".format( host.name ) )
768
769 main.scapyHosts = []
770 main.scapyHostIPs = []
771
772 utilities.assert_equals( expect=main.TRUE,
773 actual=scapyResult,
774 onpass="Successfully stopped scapy and removed host components",
775 onfail="Failed to stop mininet and scapy" )
776
kelvin-onlab44147802015-07-27 17:57:31 -0700777 main.step( "Stopping Mininet Topology" )
Jeremy2f190ca2016-01-29 15:23:57 -0800778 mininetResult = main.Mininet1.stopNet( )
779
kelvin-onlab44147802015-07-27 17:57:31 -0700780 utilities.assert_equals( expect=main.TRUE,
781 actual=stepResult,
782 onpass="Successfully stop mininet",
783 onfail="Failed to stop mininet" )
784 # Exit if topology did not load properly
Jeremy2f190ca2016-01-29 15:23:57 -0800785 if not (mininetResult and scapyResult ):
kelvin-onlab44147802015-07-27 17:57:31 -0700786 main.cleanup()
787 main.exit()
788
Jeremy Songster17147f22016-05-31 18:30:52 -0700789 def CASE19( self, main ):
790 """
791 Copy the karaf.log files after each testcase cycle
792 """
793 main.log.report( "Copy karaf logs" )
794 main.case( "Copy karaf logs" )
795 main.caseExplanation = "Copying the karaf logs to preserve them through" +\
796 "reinstalling ONOS"
797 main.step( "Copying karaf logs" )
Jeremy Songster31aad312016-06-13 16:32:11 -0700798 stepResult = main.TRUE
799 scpResult = main.TRUE
800 copyResult = main.TRUE
Jeremy Songstercc5414b2016-07-11 10:59:53 -0700801 for i in range( main.numCtrls ):
Jeremy Songstere7f3b342016-08-17 14:56:49 -0700802 main.node = main.CLIs[ i ]
Jeremy Songster17147f22016-05-31 18:30:52 -0700803 ip = main.ONOSip[ i ]
804 main.node.ip_address = ip
Jeremy Songster31aad312016-06-13 16:32:11 -0700805 scpResult = scpResult and main.ONOSbench.scp( main.node ,
806 "/opt/onos/log/karaf.log",
807 "/tmp/karaf.log",
808 direction="from" )
809 copyResult = copyResult and main.ONOSbench.cpLogsToDir( "/tmp/karaf.log", main.logdir,
Ming Yan Shuab2f7f52016-08-03 15:21:24 -0700810 copyFileName=( "karaf.log.node{0}.cycle{1}".format(
811 str( i + 1 ), str( main.cycle ) ) ) )
Jeremy Songster31aad312016-06-13 16:32:11 -0700812 if scpResult and copyResult:
813 stepResult = main.TRUE and stepResult
814 else:
815 stepResult = main.FALSE and stepResult
Jeremy Songster31aad312016-06-13 16:32:11 -0700816 utilities.assert_equals( expect=main.TRUE,
817 actual=stepResult,
818 onpass="Successfully copied remote ONOS logs",
819 onfail="Failed to copy remote ONOS logs" )
Jeremy Songster17147f22016-05-31 18:30:52 -0700820
kelvin-onlab44147802015-07-27 17:57:31 -0700821 def CASE1000( self, main ):
822 """
823 Add host intents between 2 host:
824 - Discover hosts
825 - Add host intents
826 - Check intents
827 - Verify flows
828 - Ping hosts
829 - Reroute
830 - Link down
831 - Verify flows
832 - Check topology
833 - Ping hosts
834 - Link up
835 - Verify flows
836 - Check topology
837 - Ping hosts
838 - Remove intents
839 """
840 import time
841 import json
842 import re
Jeremydd9bda62016-04-18 12:02:32 -0700843 if main.initialized == main.FALSE:
844 main.log.error( "Test components did not start correctly, skipping further tests" )
845 main.skipCase()
kelvin-onlab44147802015-07-27 17:57:31 -0700846 # Assert variables - These variable's name|format must be followed
847 # if you want to use the wrapper function
848 assert main, "There is no main"
Jeremydd9bda62016-04-18 12:02:32 -0700849 try:
Jeremy Songstere7f3b342016-08-17 14:56:49 -0700850 assert main.RESTs
Jeremydd9bda62016-04-18 12:02:32 -0700851 except AssertionError:
Jeremy Songstere7f3b342016-08-17 14:56:49 -0700852 main.log.error( "There is no main.RESTs, skipping test cases" )
Jeremydd9bda62016-04-18 12:02:32 -0700853 main.initialized = main.FALSE
854 main.skipCase()
855 try:
856 assert main.Mininet1
857 except AssertionError:
858 main.log.error( "Mininet handle should be named Mininet1, skipping test cases" )
859 main.initialized = main.FALSE
860 main.skipCase()
861 try:
862 assert main.numSwitch
863 except AssertionError:
Jeremy Songstere7f3b342016-08-17 14:56:49 -0700864 main.log.error( "Place the total number of switch topology in "+\
865 main.numSwitch )
Jeremydd9bda62016-04-18 12:02:32 -0700866 main.initialized = main.FALSE
867 main.skipCase()
kelvin-onlab44147802015-07-27 17:57:31 -0700868
Jeremye1ea0602016-02-08 16:35:05 -0800869 # Save leader candidates
Jeremy Songstere7f3b342016-08-17 14:56:49 -0700870 intentLeadersOld = main.CLIs[ 0 ].leaderCandidates()
Jeremye1ea0602016-02-08 16:35:05 -0800871
kelvin-onlab44147802015-07-27 17:57:31 -0700872 main.case( "Host Intents Test - " + str( main.numCtrls ) +
Jeremyeb51cb12016-03-28 17:53:35 -0700873 " NODE(S) - OF " + main.OFProtocol + " - Using " + main.flowCompiler )
kelvin-onlab44147802015-07-27 17:57:31 -0700874 main.caseExplanation = "This test case tests Host intents using " +\
875 str( main.numCtrls ) + " node(s) cluster;\n" +\
876 "Different type of hosts will be tested in " +\
877 "each step such as IPV4, Dual stack, VLAN " +\
Jeremyeb51cb12016-03-28 17:53:35 -0700878 "etc;\nThe test will use OF " + main.OFProtocol +\
879 " OVS running in Mininet and compile intents" +\
880 " using " + main.flowCompiler
kelvin-onlab44147802015-07-27 17:57:31 -0700881
Jeremy2f190ca2016-01-29 15:23:57 -0800882 main.step( "IPV4: Add and test host intents between h1 and h9" )
883 main.assertReturnString = "Assertion result for IPV4 host intent with mac addresses\n"
884 host1 = { "name":"h1","id":"00:00:00:00:00:01/-1" }
885 host2 = { "name":"h9","id":"00:00:00:00:00:09/-1" }
886 testResult = main.FALSE
887 installResult = main.intentFunction.installHostIntent( main,
kelvin-onlab44147802015-07-27 17:57:31 -0700888 name='IPV4',
Jeremy2f190ca2016-01-29 15:23:57 -0800889 onosNode='0',
890 host1=host1,
891 host2=host2 )
892
893 if installResult:
894 testResult = main.intentFunction.testHostIntent( main,
895 name='IPV4',
896 intentId = installResult,
897 onosNode='0',
898 host1=host1,
899 host2=host2,
kelvin-onlab44147802015-07-27 17:57:31 -0700900 sw1='s5',
901 sw2='s2',
Jeremy Songstere7f3b342016-08-17 14:56:49 -0700902 expectedLink=18 )
kelvin-onlab44147802015-07-27 17:57:31 -0700903
904 utilities.assert_equals( expect=main.TRUE,
Jeremy2f190ca2016-01-29 15:23:57 -0800905 actual=testResult,
906 onpass=main.assertReturnString,
907 onfail=main.assertReturnString )
kelvin-onlab44147802015-07-27 17:57:31 -0700908
909 main.step( "DUALSTACK1: Add host intents between h3 and h11" )
Jeremy2f190ca2016-01-29 15:23:57 -0800910 main.assertReturnString = "Assertion Result for dualstack IPV4 with MAC addresses\n"
911 host1 = { "name":"h3", "id":"00:00:00:00:00:03/-1" }
Jeremy Songstere7f3b342016-08-17 14:56:49 -0700912 host2 = { "name":"h11","id":"00:00:00:00:00:0B/-1" }
Jeremy2f190ca2016-01-29 15:23:57 -0800913 testResult = main.FALSE
914 installResult = main.intentFunction.installHostIntent( main,
915 name='DUALSTACK1',
916 onosNode='0',
917 host1=host1,
918 host2=host2 )
919
920 if installResult:
921 testResult = main.intentFunction.testHostIntent( main,
922 name='DUALSTACK1',
923 intentId = installResult,
924 onosNode='0',
925 host1=host1,
926 host2=host2,
kelvin-onlab44147802015-07-27 17:57:31 -0700927 sw1='s5',
928 sw2='s2',
Jeremy Songstere7f3b342016-08-17 14:56:49 -0700929 expectedLink=18 )
kelvin-onlab44147802015-07-27 17:57:31 -0700930
931 utilities.assert_equals( expect=main.TRUE,
Jeremy2f190ca2016-01-29 15:23:57 -0800932 actual=testResult,
933 onpass=main.assertReturnString,
Jeremy Songstere7f3b342016-08-17 14:56:49 -0700934 onfail=main.assertReturnString )
kelvin-onlab44147802015-07-27 17:57:31 -0700935
936 main.step( "DUALSTACK2: Add host intents between h1 and h11" )
Jeremy2f190ca2016-01-29 15:23:57 -0800937 main.assertReturnString = "Assertion Result for dualstack2 host intent\n"
938 host1 = { "name":"h1" }
939 host2 = { "name":"h11" }
940 testResult = main.FALSE
941 installResult = main.intentFunction.installHostIntent( main,
kelvin-onlab44147802015-07-27 17:57:31 -0700942 name='DUALSTACK2',
Jeremy2f190ca2016-01-29 15:23:57 -0800943 onosNode='0',
944 host1=host1,
945 host2=host2 )
946
947 if installResult:
948 testResult = main.intentFunction.testHostIntent( main,
949 name='DUALSTACK2',
950 intentId = installResult,
951 onosNode='0',
952 host1=host1,
953 host2=host2,
kelvin-onlab44147802015-07-27 17:57:31 -0700954 sw1='s5',
955 sw2='s2',
Jeremy Songstere7f3b342016-08-17 14:56:49 -0700956 expectedLink=18 )
kelvin-onlab44147802015-07-27 17:57:31 -0700957
958 utilities.assert_equals( expect=main.TRUE,
Jeremy2f190ca2016-01-29 15:23:57 -0800959 actual=testResult,
960 onpass=main.assertReturnString,
961 onfail=main.assertReturnString )
kelvin-onlab44147802015-07-27 17:57:31 -0700962
963 main.step( "1HOP: Add host intents between h1 and h3" )
Jeremy2f190ca2016-01-29 15:23:57 -0800964 main.assertReturnString = "Assertion Result for 1HOP for IPV4 same switch\n"
965 host1 = { "name":"h1" }
966 host2 = { "name":"h3" }
967 testResult = main.FALSE
968 installResult = main.intentFunction.installHostIntent( main,
kelvin-onlab44147802015-07-27 17:57:31 -0700969 name='1HOP',
Jeremy2f190ca2016-01-29 15:23:57 -0800970 onosNode='0',
971 host1=host1,
972 host2=host2 )
kelvin-onlab44147802015-07-27 17:57:31 -0700973
Jeremy2f190ca2016-01-29 15:23:57 -0800974 if installResult:
975 testResult = main.intentFunction.testHostIntent( main,
976 name='1HOP',
977 intentId = installResult,
978 onosNode='0',
979 host1=host1,
980 host2=host2,
kelvin-onlab44147802015-07-27 17:57:31 -0700981 sw1='s5',
982 sw2='s2',
Jeremy Songstere7f3b342016-08-17 14:56:49 -0700983 expectedLink=18 )
kelvin-onlab44147802015-07-27 17:57:31 -0700984
985 utilities.assert_equals( expect=main.TRUE,
Jeremy2f190ca2016-01-29 15:23:57 -0800986 actual=testResult,
987 onpass=main.assertReturnString,
988 onfail=main.assertReturnString )
989
990 main.step( "VLAN1: Add vlan host intents between h4 and h12" )
991 main.assertReturnString = "Assertion Result vlan IPV4\n"
Jeremy Songsterae2dd452016-05-17 16:44:35 -0700992 host1 = { "name":"h4","id":"00:00:00:00:00:04/100", "vlanId":"100" }
993 host2 = { "name":"h12","id":"00:00:00:00:00:0C/100", "vlanId":"100" }
Jeremy2f190ca2016-01-29 15:23:57 -0800994 testResult = main.FALSE
995 installResult = main.intentFunction.installHostIntent( main,
996 name='VLAN1',
997 onosNode='0',
998 host1=host1,
999 host2=host2 )
1000
1001 if installResult:
1002 testResult = main.intentFunction.testHostIntent( main,
1003 name='VLAN1',
1004 intentId = installResult,
1005 onosNode='0',
1006 host1=host1,
1007 host2=host2,
1008 sw1='s5',
1009 sw2='s2',
Jeremy Songstere7f3b342016-08-17 14:56:49 -07001010 expectedLink=18 )
Jeremy2f190ca2016-01-29 15:23:57 -08001011
1012 utilities.assert_equals( expect=main.TRUE,
1013 actual=testResult,
1014 onpass=main.assertReturnString,
1015 onfail=main.assertReturnString )
kelvin-onlab44147802015-07-27 17:57:31 -07001016
Jeremy Songsterae2dd452016-05-17 16:44:35 -07001017 # This step isn't currently possible to perform in the REST API
1018 # main.step( "VLAN2: Add inter vlan host intents between h13 and h20" )
1019 # main.assertReturnString = "Assertion Result different VLAN negative test\n"
1020 # host1 = { "name":"h13" }
1021 # host2 = { "name":"h20" }
1022 # testResult = main.FALSE
1023 # installResult = main.intentFunction.installHostIntent( main,
1024 # name='VLAN2',
1025 # onosNode='0',
1026 # host1=host1,
1027 # host2=host2 )
kelvin-onlab44147802015-07-27 17:57:31 -07001028
Jeremy Songsterae2dd452016-05-17 16:44:35 -07001029 # if installResult:
1030 # testResult = main.intentFunction.testHostIntent( main,
1031 # name='VLAN2',
1032 # intentId = installResult,
1033 # onosNode='0',
1034 # host1=host1,
1035 # host2=host2,
1036 # sw1='s5',
1037 # sw2='s2',
Jeremy Songstere7f3b342016-08-17 14:56:49 -07001038 # expectedLink=18 )
kelvin-onlab44147802015-07-27 17:57:31 -07001039
Jeremy Songsterae2dd452016-05-17 16:44:35 -07001040 # utilities.assert_equals( expect=main.TRUE,
1041 # actual=testResult,
1042 # onpass=main.assertReturnString,
1043 # onfail=main.assertReturnString )
Jeremy2f190ca2016-01-29 15:23:57 -08001044
Jeremye1ea0602016-02-08 16:35:05 -08001045 # Change the following to use the REST API when leader checking is
1046 # supported by it
Jeremy2f190ca2016-01-29 15:23:57 -08001047
Jeremy Songstere7f3b342016-08-17 14:56:49 -07001048 main.step( "Confirm that ONOS leadership is unchanged" )
1049 intentLeadersNew = main.CLIs[ 0 ].leaderCandidates()
Jeremye1ea0602016-02-08 16:35:05 -08001050 main.intentFunction.checkLeaderChange( intentLeadersOld,
1051 intentLeadersNew )
Jeremy2f190ca2016-01-29 15:23:57 -08001052
Jeremye1ea0602016-02-08 16:35:05 -08001053 utilities.assert_equals( expect=main.TRUE,
1054 actual=testResult,
1055 onpass="ONOS Leaders Unchanged",
1056 onfail="ONOS Leader Mismatch")
Jeremy2f190ca2016-01-29 15:23:57 -08001057
1058 main.intentFunction.report( main )
kelvin-onlab44147802015-07-27 17:57:31 -07001059
1060 def CASE2000( self, main ):
1061 """
1062 Add point intents between 2 hosts:
1063 - Get device ids | ports
1064 - Add point intents
1065 - Check intents
1066 - Verify flows
1067 - Ping hosts
1068 - Reroute
1069 - Link down
1070 - Verify flows
1071 - Check topology
1072 - Ping hosts
1073 - Link up
1074 - Verify flows
1075 - Check topology
1076 - Ping hosts
1077 - Remove intents
1078 """
Jeremydd9bda62016-04-18 12:02:32 -07001079 if main.initialized == main.FALSE:
1080 main.log.error( "Test components did not start correctly, skipping further tests" )
1081 main.skipCase()
Ming Yan Shuab2f7f52016-08-03 15:21:24 -07001082 # Assert variables - These variable's name|format must be followed
1083 # if you want to use the wrapper function
kelvin-onlab44147802015-07-27 17:57:31 -07001084 assert main, "There is no main"
Jeremydd9bda62016-04-18 12:02:32 -07001085 try:
Jeremy Songstere7f3b342016-08-17 14:56:49 -07001086 assert main.RESTs
Jeremydd9bda62016-04-18 12:02:32 -07001087 except AssertionError:
Jeremy Songstere7f3b342016-08-17 14:56:49 -07001088 main.log.error( "There is no main.RESTs, skipping test cases" )
Jeremydd9bda62016-04-18 12:02:32 -07001089 main.initialized = main.FALSE
1090 main.skipCase()
1091 try:
1092 assert main.Mininet1
1093 except AssertionError:
1094 main.log.error( "Mininet handle should be named Mininet1, skipping test cases" )
1095 main.initialized = main.FALSE
1096 main.skipCase()
1097 try:
1098 assert main.numSwitch
1099 except AssertionError:
Jeremy Songstere7f3b342016-08-17 14:56:49 -07001100 main.log.error( "Place the total number of switch topology in "+\
1101 main.numSwitch )
Jeremydd9bda62016-04-18 12:02:32 -07001102 main.initialized = main.FALSE
1103 main.skipCase()
kelvin-onlab44147802015-07-27 17:57:31 -07001104
1105 main.case( "Point Intents Test - " + str( main.numCtrls ) +
Ming Yan Shuab2f7f52016-08-03 15:21:24 -07001106 " NODE(S) - OF " + main.OFProtocol + " - Using " + main.flowCompiler )
1107 main.caseExplanation = "This test case will test point to point" + \
1108 " intents using " + str( main.numCtrls ) + \
1109 " node(s) cluster;\n" + \
1110 "Different type of hosts will be tested in " + \
1111 "each step such as IPV4, Dual stack, VLAN etc" + \
1112 ";\nThe test will use OF " + main.OFProtocol + \
1113 " OVS running in Mininet and compile intents" + \
Jeremyeb51cb12016-03-28 17:53:35 -07001114 " using " + main.flowCompiler
kelvin-onlab44147802015-07-27 17:57:31 -07001115
Ming Yan Shuab2f7f52016-08-03 15:21:24 -07001116 # No option point intent
kelvin-onlab44147802015-07-27 17:57:31 -07001117 main.step( "NOOPTION: Add point intents between h1 and h9" )
Jeremy2f190ca2016-01-29 15:23:57 -08001118 main.assertReturnString = "Assertion Result for NOOPTION point intent\n"
1119 senders = [
Ming Yan Shuab2f7f52016-08-03 15:21:24 -07001120 { "name": "h1", "device": "of:0000000000000005/1" }
Jeremy2f190ca2016-01-29 15:23:57 -08001121 ]
1122 recipients = [
Ming Yan Shuab2f7f52016-08-03 15:21:24 -07001123 { "name": "h9", "device": "of:0000000000000006/1" }
Jeremy2f190ca2016-01-29 15:23:57 -08001124 ]
1125 testResult = main.FALSE
1126 installResult = main.intentFunction.installPointIntent(
Ming Yan Shuab2f7f52016-08-03 15:21:24 -07001127 main,
1128 name="NOOPTION",
1129 senders=senders,
1130 recipients=recipients )
Jeremy2f190ca2016-01-29 15:23:57 -08001131
1132 if installResult:
1133 testResult = main.intentFunction.testPointIntent(
1134 main,
1135 intentId=installResult,
1136 name="NOOPTION",
1137 senders=senders,
1138 recipients=recipients,
1139 sw1="s5",
1140 sw2="s2",
Jeremy Songstere7f3b342016-08-17 14:56:49 -07001141 expectedLink=18 )
kelvin-onlab44147802015-07-27 17:57:31 -07001142
1143 utilities.assert_equals( expect=main.TRUE,
Jeremy2f190ca2016-01-29 15:23:57 -08001144 actual=testResult,
1145 onpass=main.assertReturnString,
1146 onfail=main.assertReturnString )
kelvin-onlab44147802015-07-27 17:57:31 -07001147
kelvin-onlab44147802015-07-27 17:57:31 -07001148 main.step( "IPV4: Add point intents between h1 and h9" )
Jeremy2f190ca2016-01-29 15:23:57 -08001149 main.assertReturnString = "Assertion Result for IPV4 point intent\n"
1150 senders = [
Ming Yan Shuab2f7f52016-08-03 15:21:24 -07001151 { "name": "h1", "device": "of:0000000000000005/1", "mac": "00:00:00:00:00:01" }
Jeremy2f190ca2016-01-29 15:23:57 -08001152 ]
1153 recipients = [
Ming Yan Shuab2f7f52016-08-03 15:21:24 -07001154 { "name": "h9", "device": "of:0000000000000006/1", "mac": "00:00:00:00:00:09" }
Jeremy2f190ca2016-01-29 15:23:57 -08001155 ]
1156 installResult = main.intentFunction.installPointIntent(
Ming Yan Shuab2f7f52016-08-03 15:21:24 -07001157 main,
1158 name="IPV4",
1159 senders=senders,
1160 recipients=recipients,
1161 ethType="IPV4" )
Jeremy2f190ca2016-01-29 15:23:57 -08001162
1163 if installResult:
1164 testResult = main.intentFunction.testPointIntent(
1165 main,
1166 intentId=installResult,
1167 name="IPV4",
1168 senders=senders,
1169 recipients=recipients,
1170 sw1="s5",
1171 sw2="s2",
Jeremy Songstere7f3b342016-08-17 14:56:49 -07001172 expectedLink=18 )
kelvin-onlab44147802015-07-27 17:57:31 -07001173
1174 utilities.assert_equals( expect=main.TRUE,
Jeremy2f190ca2016-01-29 15:23:57 -08001175 actual=testResult,
1176 onpass=main.assertReturnString,
1177 onfail=main.assertReturnString )
Ming Yan Shuab2f7f52016-08-03 15:21:24 -07001178
alisonda157272016-12-22 01:13:21 -08001179 # main.step( "Protected: Add point intents between h1 and h9" )
1180 # main.assertReturnString = "Assertion Result for protected point intent\n"
1181 # senders = [
1182 # { "name": "h1", "device": "of:0000000000000005/1", "mac": "00:00:00:00:00:01" }
1183 # ]
1184 # recipients = [
1185 # { "name": "h9", "device": "of:0000000000000006/1", "mac": "00:00:00:00:00:09" }
1186 # ]
1187 # testResult = main.FALSE
1188 # installResult = main.intentFunction.installPointIntent(
1189 # main,
1190 # name="Protected",
1191 # senders=senders,
1192 # recipients=recipients,
1193 # protected=True )
1194 #
1195 # if installResult:
1196 # testResult = main.intentFunction.testPointIntent(
1197 # main,
1198 # name="Protected",
1199 # intentId=installResult,
1200 # senders=senders,
1201 # recipients=recipients,
1202 # sw1="s5",
1203 # sw2="s2",
1204 # protected=True,
1205 # expectedLink=18 )
1206 #
1207 # utilities.assert_equals( expect=main.TRUE,
1208 # actual=testResult,
1209 # onpass=main.assertReturnString,
1210 # onfail=main.assertReturnString )
1211
kelvin-onlab44147802015-07-27 17:57:31 -07001212 main.step( "IPV4_2: Add point intents between h1 and h9" )
Jeremy2f190ca2016-01-29 15:23:57 -08001213 main.assertReturnString = "Assertion Result for IPV4 no mac address point intents\n"
1214 senders = [
Ming Yan Shuab2f7f52016-08-03 15:21:24 -07001215 { "name": "h1", "device": "of:0000000000000005/1" }
Jeremy2f190ca2016-01-29 15:23:57 -08001216 ]
1217 recipients = [
Ming Yan Shuab2f7f52016-08-03 15:21:24 -07001218 { "name": "h9", "device": "of:0000000000000006/1" }
Jeremy2f190ca2016-01-29 15:23:57 -08001219 ]
1220 installResult = main.intentFunction.installPointIntent(
Ming Yan Shuab2f7f52016-08-03 15:21:24 -07001221 main,
1222 name="IPV4_2",
1223 senders=senders,
1224 recipients=recipients,
1225 ethType="IPV4" )
Jeremy2f190ca2016-01-29 15:23:57 -08001226
1227 if installResult:
1228 testResult = main.intentFunction.testPointIntent(
1229 main,
1230 intentId=installResult,
1231 name="IPV4_2",
1232 senders=senders,
1233 recipients=recipients,
1234 sw1="s5",
1235 sw2="s2",
Jeremy Songstere7f3b342016-08-17 14:56:49 -07001236 expectedLink=18 )
kelvin-onlab44147802015-07-27 17:57:31 -07001237
1238 utilities.assert_equals( expect=main.TRUE,
Jeremy2f190ca2016-01-29 15:23:57 -08001239 actual=testResult,
1240 onpass=main.assertReturnString,
1241 onfail=main.assertReturnString )
kelvin-onlab44147802015-07-27 17:57:31 -07001242
kelvin-onlab0e684682015-08-11 18:51:41 -07001243 main.step( "SDNIP-ICMP: Add point intents between h1 and h9" )
Jeremy2f190ca2016-01-29 15:23:57 -08001244 main.assertReturnString = "Assertion Result for SDNIP-ICMP IPV4 using TCP point intents\n"
1245 senders = [
Ming Yan Shuab2f7f52016-08-03 15:21:24 -07001246 { "name": "h1", "device": "of:0000000000000005/1", "mac": "00:00:00:00:00:01",
1247 "ip": ( main.h1.hostIp + "/24" ) }
Jeremy2f190ca2016-01-29 15:23:57 -08001248 ]
1249 recipients = [
Ming Yan Shuab2f7f52016-08-03 15:21:24 -07001250 { "name": "h9", "device": "of:0000000000000006/1", "mac": "00:00:00:00:00:09",
1251 "ip": ( main.h9.hostIp + "/24" ) }
Jeremy2f190ca2016-01-29 15:23:57 -08001252 ]
Ming Yan Shuab2f7f52016-08-03 15:21:24 -07001253 # ipProto = main.params['SDNIP']['icmpProto']
1254 ipProto = main.params[ 'SDNIP' ][ 'ipPrototype' ]
kelvin-onlab44147802015-07-27 17:57:31 -07001255 # Uneccessary, not including this in the selectors
Ming Yan Shuab2f7f52016-08-03 15:21:24 -07001256 tcpSrc = main.params['SDNIP']['srcPort']
1257 tcpDst = main.params['SDNIP']['dstPort']
kelvin-onlab44147802015-07-27 17:57:31 -07001258
Jeremy2f190ca2016-01-29 15:23:57 -08001259 installResult = main.intentFunction.installPointIntent(
Ming Yan Shuab2f7f52016-08-03 15:21:24 -07001260 main,
1261 name="SDNIP-ICMP",
1262 senders=senders,
1263 recipients=recipients,
1264 ethType="IPV4",
1265 ipProto=ipProto,
1266 tcpSrc=tcpSrc,
1267 tcpDst=tcpDst )
Jeremy2f190ca2016-01-29 15:23:57 -08001268
1269 if installResult:
1270 testResult = main.intentFunction.testPointIntent(
Ming Yan Shuab2f7f52016-08-03 15:21:24 -07001271 main,
1272 intentId=installResult,
1273 name="SDNIP_ICMP",
1274 senders=senders,
1275 recipients=recipients,
1276 sw1="s5",
1277 sw2="s2",
1278 expectedLink=18,
1279 useTCP=True )
kelvin-onlab44147802015-07-27 17:57:31 -07001280
1281 utilities.assert_equals( expect=main.TRUE,
Jeremy2f190ca2016-01-29 15:23:57 -08001282 actual=testResult,
1283 onpass=main.assertReturnString,
1284 onfail=main.assertReturnString )
kelvin-onlab44147802015-07-27 17:57:31 -07001285
kelvin-onlab0e684682015-08-11 18:51:41 -07001286 main.step( "SDNIP-TCP: Add point intents between h1 and h9" )
Jeremy2f190ca2016-01-29 15:23:57 -08001287 main.assertReturnString = "Assertion Result for SDNIP-TCP IPV4 using ICMP point intents\n"
Ming Yan Shuab2f7f52016-08-03 15:21:24 -07001288 mac1 = main.hostsData['h1']['mac']
1289 mac2 = main.hostsData['h9']['mac']
1290 ip1 = str(main.hostsData['h1']['ipAddresses'][0]) + "/32"
1291 ip2 = str(main.hostsData['h9']['ipAddresses'][0]) + "/32"
1292 ipProto = main.params['SDNIP']['tcpProto']
1293 tcp1 = main.params['SDNIP']['srcPort']
1294 tcp2 = main.params['SDNIP']['dstPort']
kelvin-onlab44147802015-07-27 17:57:31 -07001295
kelvin-onlab0e684682015-08-11 18:51:41 -07001296 stepResult = main.intentFunction.pointIntentTcp(
Ming Yan Shuab2f7f52016-08-03 15:21:24 -07001297 main,
1298 name="SDNIP-TCP",
1299 host1="h1",
1300 host2="h9",
1301 deviceId1="of:0000000000000005/1",
1302 deviceId2="of:0000000000000006/1",
1303 mac1=mac1,
1304 mac2=mac2,
1305 ethType="IPV4",
1306 ipProto=ipProto,
1307 ip1=ip1,
1308 ip2=ip2,
1309 tcp1=tcp1,
1310 tcp2=tcp2 )
kelvin-onlab44147802015-07-27 17:57:31 -07001311
1312 utilities.assert_equals( expect=main.TRUE,
Ming Yan Shuab2f7f52016-08-03 15:21:24 -07001313 actual=stepResult,
Jeremy2f190ca2016-01-29 15:23:57 -08001314 onpass=main.assertReturnString,
1315 onfail=main.assertReturnString )
kelvin-onlab44147802015-07-27 17:57:31 -07001316
Jeremy2f190ca2016-01-29 15:23:57 -08001317 main.step( "DUALSTACK1: Add point intents between h3 and h11" )
1318 main.assertReturnString = "Assertion Result for Dualstack1 IPV4 with mac address point intents\n"
1319 senders = [
Ming Yan Shuab2f7f52016-08-03 15:21:24 -07001320 { "name": "h3", "device": "of:0000000000000005/3", "mac": "00:00:00:00:00:03" }
Jeremy2f190ca2016-01-29 15:23:57 -08001321 ]
1322 recipients = [
Ming Yan Shuab2f7f52016-08-03 15:21:24 -07001323 { "name": "h11", "device": "of:0000000000000006/3", "mac": "00:00:00:00:00:0B" }
Jeremy2f190ca2016-01-29 15:23:57 -08001324 ]
1325 installResult = main.intentFunction.installPointIntent(
Ming Yan Shuab2f7f52016-08-03 15:21:24 -07001326 main,
1327 name="DUALSTACK1",
1328 senders=senders,
1329 recipients=recipients,
1330 ethType="IPV4" )
Jeremy2f190ca2016-01-29 15:23:57 -08001331
1332 if installResult:
1333 testResult = main.intentFunction.testPointIntent(
Ming Yan Shuab2f7f52016-08-03 15:21:24 -07001334 main,
1335 intentId=installResult,
1336 name="DUALSTACK1",
1337 senders=senders,
1338 recipients=recipients,
1339 sw1="s5",
1340 sw2="s2",
1341 expectedLink=18 )
kelvin-onlab44147802015-07-27 17:57:31 -07001342
1343 utilities.assert_equals( expect=main.TRUE,
Jeremy2f190ca2016-01-29 15:23:57 -08001344 actual=testResult,
1345 onpass=main.assertReturnString,
1346 onfail=main.assertReturnString )
kelvin-onlab44147802015-07-27 17:57:31 -07001347
1348 main.step( "VLAN: Add point intents between h5 and h21" )
Jeremy2f190ca2016-01-29 15:23:57 -08001349 main.assertReturnString = "Assertion Result for VLAN IPV4 with mac address point intents\n"
1350 senders = [
Ming Yan Shuab2f7f52016-08-03 15:21:24 -07001351 { "name": "h5", "device": "of:0000000000000005/5", "mac": "00:00:00:00:00:05", "vlanId": "200" }
Jeremy2f190ca2016-01-29 15:23:57 -08001352 ]
1353 recipients = [
Ming Yan Shuab2f7f52016-08-03 15:21:24 -07001354 { "name": "h21", "device": "of:0000000000000007/5", "mac": "00:00:00:00:00:15", "vlanId": "200" }
Jeremy2f190ca2016-01-29 15:23:57 -08001355 ]
1356 installResult = main.intentFunction.installPointIntent(
Ming Yan Shuab2f7f52016-08-03 15:21:24 -07001357 main,
1358 name="VLAN",
1359 senders=senders,
1360 recipients=recipients )
Jeremy2f190ca2016-01-29 15:23:57 -08001361
1362 if installResult:
1363 testResult = main.intentFunction.testPointIntent(
1364 main,
1365 intentId=installResult,
Jeremy Songsterae2dd452016-05-17 16:44:35 -07001366 name="VLAN",
Jeremy2f190ca2016-01-29 15:23:57 -08001367 senders=senders,
1368 recipients=recipients,
1369 sw1="s5",
1370 sw2="s2",
Jeremy Songstere7f3b342016-08-17 14:56:49 -07001371 expectedLink=18 )
kelvin-onlab44147802015-07-27 17:57:31 -07001372
1373 utilities.assert_equals( expect=main.TRUE,
Jeremy2f190ca2016-01-29 15:23:57 -08001374 actual=testResult,
1375 onpass=main.assertReturnString,
1376 onfail=main.assertReturnString )
kelvin-onlab44147802015-07-27 17:57:31 -07001377
Jeremy Songsterae2dd452016-05-17 16:44:35 -07001378 # TODO: implement VLAN selector REST API intent test once supported
1379
kelvin-onlab44147802015-07-27 17:57:31 -07001380 main.step( "1HOP: Add point intents between h1 and h3" )
Jeremy2f190ca2016-01-29 15:23:57 -08001381 main.assertReturnString = "Assertion Result for 1HOP IPV4 with no mac address point intents\n"
1382 senders = [
Ming Yan Shuab2f7f52016-08-03 15:21:24 -07001383 { "name": "h1", "device": "of:0000000000000005/1", "mac": "00:00:00:00:00:01" }
Jeremy2f190ca2016-01-29 15:23:57 -08001384 ]
1385 recipients = [
Ming Yan Shuab2f7f52016-08-03 15:21:24 -07001386 { "name": "h3", "device": "of:0000000000000005/3", "mac": "00:00:00:00:00:03" }
Jeremy2f190ca2016-01-29 15:23:57 -08001387 ]
1388 installResult = main.intentFunction.installPointIntent(
Ming Yan Shuab2f7f52016-08-03 15:21:24 -07001389 main,
1390 name="1HOP IPV4",
1391 senders=senders,
1392 recipients=recipients,
1393 ethType="IPV4" )
Jeremy2f190ca2016-01-29 15:23:57 -08001394
1395 if installResult:
1396 testResult = main.intentFunction.testPointIntent(
1397 main,
1398 intentId=installResult,
1399 name="1HOP IPV4",
1400 senders=senders,
1401 recipients=recipients,
1402 sw1="s5",
1403 sw2="s2",
Jeremy Songstere7f3b342016-08-17 14:56:49 -07001404 expectedLink=18 )
kelvin-onlab44147802015-07-27 17:57:31 -07001405
1406 utilities.assert_equals( expect=main.TRUE,
Jeremy2f190ca2016-01-29 15:23:57 -08001407 actual=testResult,
1408 onpass=main.assertReturnString,
1409 onfail=main.assertReturnString )
1410
1411 main.intentFunction.report( main )
kelvin-onlab44147802015-07-27 17:57:31 -07001412
Ming Yan Shuab2f7f52016-08-03 15:21:24 -07001413
kelvin-onlab44147802015-07-27 17:57:31 -07001414 def CASE3000( self, main ):
1415 """
1416 Add single point to multi point intents
1417 - Get device ids
1418 - Add single point to multi point intents
1419 - Check intents
1420 - Verify flows
1421 - Ping hosts
1422 - Reroute
1423 - Link down
1424 - Verify flows
1425 - Check topology
1426 - Ping hosts
1427 - Link up
1428 - Verify flows
1429 - Check topology
1430 - Ping hosts
1431 - Remove intents
1432 """
Ming Yan Shuab2f7f52016-08-03 15:21:24 -07001433 if main.initialized == main.FALSE:
1434 main.log.error( "Test components did not start correctly, skipping further tests" )
1435 main.skipCase()
kelvin-onlab44147802015-07-27 17:57:31 -07001436 assert main, "There is no main"
kelvin-onlab44147802015-07-27 17:57:31 -07001437
Ming Yan Shuab2f7f52016-08-03 15:21:24 -07001438 try:
1439 assert main.CLIs, "There is no main.CLIs, skipping test cases"
1440 assert main.Mininet1, "Mininet handle should be named Mininet1, skipping test cases"
1441 assert main.numSwitch, "Place the total number of switch topology in main.numSwitch"
1442 except AssertionError:
1443 main.initialized = main.FALSE
1444 main.skipCase()
1445
1446 main.testName = "Single to Multi Point Intents"
1447 main.case( main.testName + " Test - " + str( main.numCtrls ) +
1448 " NODE(S) - OF " + main.OFProtocol + " - Using " + main.flowCompiler )
1449 main.caseExplanation = "This test case will test single point to" + \
1450 " multi point intents using " + \
1451 str( main.numCtrls ) + " node(s) cluster;\n" + \
1452 "Different type of hosts will be tested in " + \
1453 "each step such as IPV4, Dual stack, VLAN etc" + \
1454 ";\nThe test will use OF " + main.OFProtocol + \
1455 " OVS running in Mininet and compile intents" + \
Jeremyeb51cb12016-03-28 17:53:35 -07001456 " using " + main.flowCompiler
kelvin-onlab44147802015-07-27 17:57:31 -07001457
Ming Yan Shuab2f7f52016-08-03 15:21:24 -07001458 main.step( "NOOPTION: Install and test single point to multi point intents" )
1459 main.assertReturnString = "Assertion results for IPV4 single to multi point intent with no options set\n"
1460 senders = [
1461 { "name": "h8", "device": "of:0000000000000005/8" }
1462 ]
1463 recipients = [
1464 { "name": "h16", "device": "of:0000000000000006/8" },
1465 { "name": "h24", "device": "of:0000000000000007/8" }
1466 ]
1467 badSenders = [ { "name": "h9" } ] # Senders that are not in the intent
1468 badRecipients = [ { "name": "h17" } ] # Recipients that are not in the intent
1469 testResult = main.FALSE
1470 installResult = main.intentFunction.installSingleToMultiIntent(
1471 main,
1472 name="NOOPTION",
1473 senders=senders,
1474 recipients=recipients )
1475
1476 if installResult:
1477 testResult = main.intentFunction.testPointIntent(
1478 main,
1479 intentId=installResult,
1480 name="NOOPTION",
1481 senders=senders,
1482 recipients=recipients,
1483 badSenders=badSenders,
1484 badRecipients=badRecipients,
1485 sw1="s5",
1486 sw2="s2",
1487 expectedLink=18 )
1488 else:
1489 main.CLIs[ 0 ].removeAllIntents( purge=True )
kelvin-onlab44147802015-07-27 17:57:31 -07001490
1491 utilities.assert_equals( expect=main.TRUE,
Ming Yan Shuab2f7f52016-08-03 15:21:24 -07001492 actual=testResult,
1493 onpass=main.assertReturnString,
1494 onfail=main.assertReturnString )
kelvin-onlab44147802015-07-27 17:57:31 -07001495
Ming Yan Shuab2f7f52016-08-03 15:21:24 -07001496 main.step("IPV4: Install and test single point to multi point intents")
1497 main.assertReturnString = "Assertion results for IPV4 single to multi point intent " \
1498 "with IPV4 type and MAC addresses\n"
1499 senders = [
1500 {"name": "h8", "device": "of:0000000000000005/8", "mac": "00:00:00:00:00:08"}
1501 ]
1502 recipients = [
1503 {"name": "h16", "device": "of:0000000000000006/8", "mac": "00:00:00:00:00:10"},
1504 {"name": "h24", "device": "of:0000000000000007/8", "mac": "00:00:00:00:00:18"}
1505 ]
1506 badSenders = [{"name": "h9"}] # Senders that are not in the intent
1507 badRecipients = [{"name": "h17"}] # Recipients that are not in the intent
1508 installResult = main.intentFunction.installSingleToMultiIntent(
1509 main,
1510 name="IPV4",
1511 senders=senders,
1512 recipients=recipients,
1513 ethType="IPV4")
1514
1515 if installResult:
1516 testResult = main.intentFunction.testPointIntent(
1517 main,
1518 intentId=installResult,
1519 name="IPV4",
1520 senders=senders,
1521 recipients=recipients,
1522 badSenders=badSenders,
1523 badRecipients=badRecipients,
1524 sw1="s5",
1525 sw2="s2",
1526 expectedLink=18 )
1527 else:
1528 main.CLIs[ 0 ].removeAllIntents( purge=True )
kelvin-onlab44147802015-07-27 17:57:31 -07001529
1530 utilities.assert_equals( expect=main.TRUE,
Ming Yan Shuab2f7f52016-08-03 15:21:24 -07001531 actual=testResult,
1532 onpass=main.assertReturnString,
1533 onfail=main.assertReturnString )
kelvin-onlab44147802015-07-27 17:57:31 -07001534
1535 main.step( "IPV4_2: Add single point to multi point intents" )
Ming Yan Shuab2f7f52016-08-03 15:21:24 -07001536 main.assertReturnString = "Assertion results for IPV4 single to multi point intent " \
1537 "with IPV4 type and no MAC addresses\n"
1538 senders = [
1539 { "name": "h8", "device": "of:0000000000000005/8" }
1540 ]
1541 recipients = [
1542 { "name": "h16", "device": "of:0000000000000006/8" },
1543 { "name": "h24", "device": "of:0000000000000007/8" }
1544 ]
1545 badSenders = [ { "name": "h9" } ] # Senders that are not in the intent
1546 badRecipients = [ { "name": "h17" } ] # Recipients that are not in the intent
1547 installResult = main.intentFunction.installSingleToMultiIntent(
1548 main,
1549 name="IPV4_2",
1550 senders=senders,
1551 recipients=recipients,
1552 ethType="IPV4" )
1553
1554 if installResult:
1555 testResult = main.intentFunction.testPointIntent(
1556 main,
1557 intentId=installResult,
1558 name="IPV4_2",
1559 senders=senders,
1560 recipients=recipients,
1561 badSenders=badSenders,
1562 badRecipients=badRecipients,
1563 sw1="s5",
1564 sw2="s2",
1565 expectedLink=18 )
1566 else:
1567 main.CLIs[ 0 ].removeAllIntents( purge=True )
kelvin-onlab44147802015-07-27 17:57:31 -07001568
1569 utilities.assert_equals( expect=main.TRUE,
Ming Yan Shuab2f7f52016-08-03 15:21:24 -07001570 actual=testResult,
1571 onpass=main.assertReturnString,
1572 onfail=main.assertReturnString )
kelvin-onlab44147802015-07-27 17:57:31 -07001573
1574 main.step( "VLAN: Add single point to multi point intents" )
Ming Yan Shuab2f7f52016-08-03 15:21:24 -07001575 main.assertReturnString = "Assertion results for IPV4 single to multi point intent with IPV4 type " \
1576 "and MAC addresses in the same VLAN\n"
1577 senders = [
1578 { "name": "h4", "device": "of:0000000000000005/4", "mac": "00:00:00:00:00:04", "vlan": "100" }
1579 ]
1580 recipients = [
1581 { "name": "h12", "device": "of:0000000000000006/4", "mac": "00:00:00:00:00:0C", "vlan": "100" },
1582 { "name": "h20", "device": "of:0000000000000007/4", "mac": "00:00:00:00:00:14", "vlan": "100" }
1583 ]
1584 badSenders = [ { "name": "h13" } ] # Senders that are not in the intent
1585 badRecipients = [ { "name": "h21" } ] # Recipients that are not in the intent
1586 installResult = main.intentFunction.installSingleToMultiIntent(
1587 main,
1588 name="VLAN",
1589 senders=senders,
1590 recipients=recipients,
1591 sw1="s5",
1592 sw2="s2" )
1593
1594 if installResult:
1595 testResult = main.intentFunction.testPointIntent(
1596 main,
1597 intentId=installResult,
1598 name="VLAN",
1599 senders=senders,
1600 recipients=recipients,
1601 badSenders=badSenders,
1602 badRecipients=badRecipients,
1603 sw1="s5",
1604 sw2="s2",
1605 expectedLink=18 )
1606 else:
1607 main.CLIs[ 0 ].removeAllIntents()
kelvin-onlab44147802015-07-27 17:57:31 -07001608
1609 utilities.assert_equals( expect=main.TRUE,
Ming Yan Shuab2f7f52016-08-03 15:21:24 -07001610 actual=testResult,
1611 onpass=main.assertReturnString,
1612 onfail=main.assertReturnString )
1613
1614 main.step( "VLAN: Add single point to multi point intents" )
1615 main.assertReturnString = "Assertion results for single to multi point intent with VLAN treatment\n"
1616 senders = [
1617 { "name": "h5", "vlan": "200" }
1618 ]
1619 recipients = [
1620 { "name": "h12", "device": "of:0000000000000006/4", "mac": "00:00:00:00:00:0C", "vlan": "100" },
1621 { "name": "h20", "device": "of:0000000000000007/4", "mac": "00:00:00:00:00:14", "vlan": "100" }
1622 ]
1623 badSenders = [ { "name": "h13" } ] # Senders that are not in the intent
1624 badRecipients = [ { "name": "h21" } ] # Recipients that are not in the intent
1625 testResult = main.FALSE
1626 installResult = main.intentFunction.installSingleToMultiIntent(
1627 main,
1628 name="VLAN2",
1629 senders=senders,
1630 recipients=recipients,
1631 sw1="s5",
1632 sw2="s2" )
1633 #setVlan=100 )
1634
1635 if installResult:
1636 testResult = main.intentFunction.testPointIntent(
1637 main,
1638 intentId=installResult,
1639 name="VLAN2",
1640 senders=senders,
1641 recipients=recipients,
1642 badSenders=badSenders,
1643 badRecipients=badRecipients,
1644 sw1="s5",
1645 sw2="s2",
1646 expectedLink=18 )
1647 else:
1648 main.CLIs[ 0 ].removeAllIntents()
1649
1650 utilities.assert_equals( expect=main.TRUE,
1651 actual=testResult,
1652 onpass=main.assertReturnString,
1653 onfail=main.assertReturnString )
1654
1655 main.intentFunction.report( main )
kelvin-onlab44147802015-07-27 17:57:31 -07001656
1657 def CASE4000( self, main ):
1658 """
1659 Add multi point to single point intents
1660 - Get device ids
1661 - Add multi point to single point intents
1662 - Check intents
1663 - Verify flows
1664 - Ping hosts
1665 - Reroute
1666 - Link down
1667 - Verify flows
1668 - Check topology
1669 - Ping hosts
1670 - Link up
1671 - Verify flows
1672 - Check topology
1673 - Ping hosts
1674 - Remove intents
1675 """
1676 assert main, "There is no main"
1677 assert main.CLIs, "There is no main.CLIs"
1678 assert main.Mininet1, "Mininet handle should be named Mininet1"
1679 assert main.numSwitch, "Placed the total number of switch topology in \
1680 main.numSwitch"
1681
1682 main.case( "Multi To Single Point Intents Test - " +
Jeremyeb51cb12016-03-28 17:53:35 -07001683 str( main.numCtrls ) + " NODE(S) - OF " + main.OFProtocol + " - Using " + main.flowCompiler )
kelvin-onlab44147802015-07-27 17:57:31 -07001684 main.caseExplanation = "This test case will test single point to" +\
1685 " multi point intents using " +\
1686 str( main.numCtrls ) + " node(s) cluster;\n" +\
1687 "Different type of hosts will be tested in " +\
1688 "each step such as IPV4, Dual stack, VLAN etc" +\
1689 ";\nThe test will use OF " + main.OFProtocol +\
Jeremyeb51cb12016-03-28 17:53:35 -07001690 " OVS running in Mininet and compile intents" +\
1691 " using " + main.flowCompiler
kelvin-onlab44147802015-07-27 17:57:31 -07001692
1693 main.step( "NOOPTION: Add multi point to single point intents" )
1694 stepResult = main.TRUE
1695 hostNames = [ 'h8', 'h16', 'h24' ]
1696 devices = [ 'of:0000000000000005/8', 'of:0000000000000006/8', \
1697 'of:0000000000000007/8' ]
1698 macs = [ '00:00:00:00:00:08', '00:00:00:00:00:10', '00:00:00:00:00:18' ]
1699 stepResult = main.intentFunction.multiToSingleIntent(
1700 main,
1701 name="NOOPTION",
1702 hostNames=hostNames,
1703 devices=devices,
1704 sw1="s5",
1705 sw2="s2",
1706 expectedLink=18 )
1707
1708 utilities.assert_equals( expect=main.TRUE,
1709 actual=stepResult,
1710 onpass="NOOPTION: Successfully added multi "
1711 + " point to single point intents" +
1712 " with no match action",
1713 onfail="NOOPTION: Failed to add multi point" +
1714 " to single point intents" +
1715 " with no match action" )
1716
1717 main.step( "IPV4: Add multi point to single point intents" )
1718 stepResult = main.TRUE
1719 stepResult = main.intentFunction.multiToSingleIntent(
1720 main,
1721 name="IPV4",
1722 hostNames=hostNames,
1723 devices=devices,
1724 ports=None,
1725 ethType="IPV4",
1726 macs=macs,
1727 bandwidth="",
1728 lambdaAlloc=False,
1729 ipProto="",
1730 ipAddresses="",
1731 tcp="",
1732 sw1="s5",
1733 sw2="s2",
1734 expectedLink=18 )
1735
1736 utilities.assert_equals( expect=main.TRUE,
1737 actual=stepResult,
1738 onpass="IPV4: Successfully added multi point"
1739 + " to single point intents" +
1740 " with IPV4 type and MAC addresses",
1741 onfail="IPV4: Failed to add multi point" +
1742 " to single point intents" +
1743 " with IPV4 type and MAC addresses" )
1744
1745 main.step( "IPV4_2: Add multi point to single point intents" )
1746 stepResult = main.TRUE
1747 hostNames = [ 'h8', 'h16', 'h24' ]
1748 stepResult = main.intentFunction.multiToSingleIntent(
1749 main,
1750 name="IPV4",
1751 hostNames=hostNames,
1752 ethType="IPV4",
1753 lambdaAlloc=False )
1754
1755 utilities.assert_equals( expect=main.TRUE,
1756 actual=stepResult,
1757 onpass="IPV4_2: Successfully added multi point"
1758 + " to single point intents" +
1759 " with IPV4 type and no MAC addresses",
1760 onfail="IPV4_2: Failed to add multi point" +
1761 " to single point intents" +
1762 " with IPV4 type and no MAC addresses" )
1763
1764 main.step( "VLAN: Add multi point to single point intents" )
1765 stepResult = main.TRUE
1766 hostNames = [ 'h5', 'h13', 'h21' ]
1767 devices = [ 'of:0000000000000005/5', 'of:0000000000000006/5', \
1768 'of:0000000000000007/5' ]
1769 macs = [ '00:00:00:00:00:05', '00:00:00:00:00:0D', '00:00:00:00:00:15' ]
1770 stepResult = main.intentFunction.multiToSingleIntent(
1771 main,
1772 name="VLAN",
1773 hostNames=hostNames,
1774 devices=devices,
1775 ports=None,
1776 ethType="IPV4",
1777 macs=macs,
1778 bandwidth="",
1779 lambdaAlloc=False,
1780 ipProto="",
1781 ipAddresses="",
1782 tcp="",
1783 sw1="s5",
1784 sw2="s2",
1785 expectedLink=18 )
1786
1787 utilities.assert_equals( expect=main.TRUE,
1788 actual=stepResult,
1789 onpass="VLAN: Successfully added multi point"
1790 + " to single point intents" +
1791 " with IPV4 type and MAC addresses" +
1792 " in the same VLAN",
1793 onfail="VLAN: Failed to add multi point" +
1794 " to single point intents" )
1795
1796 def CASE5000( self, main ):
1797 """
Jeremy2f190ca2016-01-29 15:23:57 -08001798 Tests Host Mobility
1799 Modifies the topology location of h1
kelvin-onlab44147802015-07-27 17:57:31 -07001800 """
Jeremydd9bda62016-04-18 12:02:32 -07001801 if main.initialized == main.FALSE:
1802 main.log.error( "Test components did not start correctly, skipping further tests" )
1803 main.skipCase()
1804 # Assert variables - These variable's name|format must be followed
1805 # if you want to use the wrapper function
kelvin-onlab44147802015-07-27 17:57:31 -07001806 assert main, "There is no main"
Jeremydd9bda62016-04-18 12:02:32 -07001807 try:
Jeremy Songstere7f3b342016-08-17 14:56:49 -07001808 assert main.RESTs
Jeremydd9bda62016-04-18 12:02:32 -07001809 except AssertionError:
Jeremy Songstere7f3b342016-08-17 14:56:49 -07001810 main.log.error( "There is no main.RESTs, skipping test cases" )
Jeremydd9bda62016-04-18 12:02:32 -07001811 main.initialized = main.FALSE
1812 main.skipCase()
1813 try:
1814 assert main.Mininet1
1815 except AssertionError:
1816 main.log.error( "Mininet handle should be named Mininet1, skipping test cases" )
1817 main.initialized = main.FALSE
1818 main.skipCase()
1819 try:
1820 assert main.numSwitch
1821 except AssertionError:
Jeremy Songstere7f3b342016-08-17 14:56:49 -07001822 main.log.error( "Place the total number of switch topology in " +\
1823 main.numSwitch )
Jeremydd9bda62016-04-18 12:02:32 -07001824 main.initialized = main.FALSE
1825 main.skipCase()
kelvin-onlab44147802015-07-27 17:57:31 -07001826 main.case( "Test host mobility with host intents " )
Jeremy2f190ca2016-01-29 15:23:57 -08001827 main.step( "Testing host mobility by moving h1 from s5 to s6" )
kelvin-onlab44147802015-07-27 17:57:31 -07001828 h1PreMove = main.hostsData[ "h1" ][ "location" ][ 0:19 ]
1829
Jeremy Songstere7f3b342016-08-17 14:56:49 -07001830 main.log.info( "Moving h1 from s5 to s6" )
1831 main.Mininet1.moveHost( "h1", "s5", "s6" )
kelvin-onlab44147802015-07-27 17:57:31 -07001832
Jeremy2f190ca2016-01-29 15:23:57 -08001833 # Send discovery ping from moved host
1834 # Moving the host brings down the default interfaces and creates a new one.
1835 # Scapy is restarted on this host to detect the new interface
1836 main.h1.stopScapy()
1837 main.h1.startScapy()
1838
1839 # Discover new host location in ONOS and populate host data.
1840 # Host 1 IP and MAC should be unchanged
1841 main.intentFunction.sendDiscoveryArp( main, [ main.h1 ] )
1842 main.intentFunction.populateHostData( main )
1843
kelvin-onlab44147802015-07-27 17:57:31 -07001844 h1PostMove = main.hostsData[ "h1" ][ "location" ][ 0:19 ]
1845
1846 utilities.assert_equals( expect="of:0000000000000006",
1847 actual=h1PostMove,
1848 onpass="Mobility: Successfully moved h1 to s6",
Jeremy2f190ca2016-01-29 15:23:57 -08001849 onfail="Mobility: Failed to move h1 to s6" +
kelvin-onlab44147802015-07-27 17:57:31 -07001850 " to single point intents" +
1851 " with IPV4 type and MAC addresses" +
1852 " in the same VLAN" )
1853
1854 main.step( "IPV4: Add host intents between h1 and h9" )
Jeremy2f190ca2016-01-29 15:23:57 -08001855 main.assertReturnString = "Assert result for IPV4 host intent between h1, moved, and h9\n"
1856 host1 = { "name":"h1","id":"00:00:00:00:00:01/-1" }
1857 host2 = { "name":"h9","id":"00:00:00:00:00:09/-1" }
1858
1859 installResult = main.intentFunction.installHostIntent( main,
1860 name='IPV4 Mobility IPV4',
kelvin-onlab44147802015-07-27 17:57:31 -07001861 onosNode='0',
Jeremy2f190ca2016-01-29 15:23:57 -08001862 host1=host1,
Jeremy Songstere7f3b342016-08-17 14:56:49 -07001863 host2=host2 )
Jeremy2f190ca2016-01-29 15:23:57 -08001864 if installResult:
1865 testResult = main.intentFunction.testHostIntent( main,
1866 name='Host Mobility IPV4',
1867 intentId = installResult,
1868 onosNode='0',
1869 host1=host1,
1870 host2=host2,
1871 sw1="s6",
1872 sw2="s2",
1873 expectedLink=18 )
kelvin-onlab44147802015-07-27 17:57:31 -07001874
1875 utilities.assert_equals( expect=main.TRUE,
Jeremy2f190ca2016-01-29 15:23:57 -08001876 actual=testResult,
1877 onpass=main.assertReturnString,
1878 onfail=main.assertReturnString )
1879
Jon Hallbd60ea02016-08-23 10:03:59 -07001880 main.intentFunction.report( main )