blob: 08c0aaab1b479b3a570127e15f5f4e0fb45c6e99 [file] [log] [blame]
acsmars51a7fe02015-10-29 18:33:32 -07001# Testing the basic intent functionality of ONOS
2
3class FUNCoptical:
4
5 def __init__( self ):
6 self.default = ''
7
8 def CASE1( self, main ):
9 import time
10 import imp
11 import re
12
13 """
14 - Construct tests variables
15 - GIT ( optional )
16 - Checkout ONOS master branch
17 - Pull latest ONOS code
18 - Building ONOS ( optional )
19 - Install ONOS package
20 - Build ONOS package
21 """
22
23 main.case( "Constructing test variables and building ONOS package" )
24 main.step( "Constructing test variables" )
25 main.caseExplanation = "This test case is mainly for loading " +\
26 "from params file, and pull and build the " +\
27 " latest ONOS package"
28 stepResult = main.FALSE
29
30 # Test variables
31 try:
32 main.testOnDirectory = re.sub( "(/tests)$", "", main.testDir )
33 main.apps = main.params[ 'ENV' ][ 'cellApps' ]
34 gitBranch = main.params[ 'GIT' ][ 'branch' ]
35 main.dependencyPath = main.testOnDirectory + \
36 main.params[ 'DEPENDENCY' ][ 'path' ]
37 main.scale = ( main.params[ 'SCALE' ][ 'size' ] ).split( "," )
38 if main.ONOSbench.maxNodes:
39 main.maxNodes = int( main.ONOSbench.maxNodes )
40 else:
41 main.maxNodes = 0
42 wrapperFile1 = main.params[ 'DEPENDENCY' ][ 'wrapper1' ]
acsmars51a7fe02015-10-29 18:33:32 -070043 main.startUpSleep = int( main.params[ 'SLEEP' ][ 'startup' ] )
44 main.checkIntentSleep = int( main.params[ 'SLEEP' ][ 'checkintent' ] )
acsmars51a7fe02015-10-29 18:33:32 -070045 main.checkTopoAttempts = int( main.params[ 'SLEEP' ][ 'topoAttempts' ] )
46 gitPull = main.params[ 'GIT' ][ 'pull' ]
Jeremy Songster5665f1b2016-06-20 14:38:22 -070047 main.switches = int( main.params[ 'MININET' ][ 'switch' ] )
48 main.links = int( main.params[ 'MININET' ][ 'links' ] )
49 main.hosts = int( main.params[ 'MININET' ][ 'hosts' ] )
50 main.opticalTopo = main.params[ 'MININET' ][ 'toponame' ]
acsmars51a7fe02015-10-29 18:33:32 -070051 main.cellData = {} # For creating cell file
52 main.hostsData = {}
53 main.CLIs = []
54 main.ONOSip = [] # List of IPs of active ONOS nodes. CASE 2
55 main.activeONOSip = []
56 main.assertReturnString = '' # Assembled assert return string
Jeremy Songster17147f22016-05-31 18:30:52 -070057 main.cycle = 0 # How many times FUNCintent has run through its tests
acsmars51a7fe02015-10-29 18:33:32 -070058
59 main.ONOSip = main.ONOSbench.getOnosIps()
60
61 # Assigning ONOS cli handles to a list
62 for i in range( 1, main.maxNodes + 1 ):
63 main.CLIs.append( getattr( main, 'ONOScli' + str( i ) ) )
64
65 # -- INIT SECTION, ONLY RUNS ONCE -- #
Jeremy Songster5665f1b2016-06-20 14:38:22 -070066 main.topo = imp.load_source( wrapperFile1,
acsmars51a7fe02015-10-29 18:33:32 -070067 main.dependencyPath +
Jeremy Songster5665f1b2016-06-20 14:38:22 -070068 wrapperFile1 +
acsmars51a7fe02015-10-29 18:33:32 -070069 ".py" )
acsmars51a7fe02015-10-29 18:33:32 -070070 if main.CLIs:
71 stepResult = main.TRUE
72 else:
73 main.log.error( "Did not properly created list of ONOS CLI handle" )
74 stepResult = main.FALSE
75 except Exception as e:
76 main.log.exception(e)
77 main.cleanup()
78 main.exit()
79
80 utilities.assert_equals( expect=main.TRUE,
81 actual=stepResult,
82 onpass="Successfully construct " +
83 "test variables ",
84 onfail="Failed to construct test variables" )
85
86 if gitPull == 'True':
87 main.step( "Building ONOS in " + gitBranch + " branch" )
88 onosBuildResult = main.startUp.onosBuild( main, gitBranch )
89 stepResult = onosBuildResult
90 utilities.assert_equals( expect=main.TRUE,
91 actual=stepResult,
92 onpass="Successfully compiled " +
93 "latest ONOS",
94 onfail="Failed to compile " +
95 "latest ONOS" )
96 else:
97 main.log.warn( "Did not pull new code so skipping mvn " +
98 "clean install" )
99 main.ONOSbench.getVersion( report=True )
100
101 def CASE2( self, main ):
102 """
103 - Set up cell
104 - Create cell file
105 - Set cell file
106 - Verify cell file
107 - Kill ONOS process
108 - Uninstall ONOS cluster
109 - Verify ONOS start up
110 - Install ONOS cluster
111 - Connect to cli
112 """
113
Jeremy Songster17147f22016-05-31 18:30:52 -0700114 main.cycle += 1
115
acsmars51a7fe02015-10-29 18:33:32 -0700116 # main.scale[ 0 ] determines the current number of ONOS controller
117 main.numCtrls = int( main.scale[ 0 ] )
Jeremye4bc7132016-03-30 14:04:01 -0700118 main.flowCompiler = "Flow Rules"
acsmars51a7fe02015-10-29 18:33:32 -0700119
120 main.case( "Starting up " + str( main.numCtrls ) +
121 " node(s) ONOS cluster" )
122 main.caseExplanation = "Set up ONOS with " + str( main.numCtrls ) +\
123 " node(s) ONOS cluster"
124
125
126
127 #kill off all onos processes
128 main.log.info( "Safety check, killing all ONOS processes" +
Jon Hall70b2ff42015-11-17 15:49:44 -0800129 " before initiating environment setup" )
acsmars51a7fe02015-10-29 18:33:32 -0700130
131 for i in range( main.maxNodes ):
132 main.ONOSbench.onosDie( main.ONOSip[ i ] )
133
134 print "NODE COUNT = ", main.numCtrls
135
136 tempOnosIp = []
137 for i in range( main.numCtrls ):
138 tempOnosIp.append( main.ONOSip[i] )
139
140 main.ONOSbench.createCellFile( main.ONOSbench.ip_address,
141 "temp", main.Mininet1.ip_address,
142 main.apps, tempOnosIp )
143
144 main.step( "Apply cell to environment" )
145 cellResult = main.ONOSbench.setCell( "temp" )
146 verifyResult = main.ONOSbench.verifyCell()
147 stepResult = cellResult and verifyResult
148 utilities.assert_equals( expect=main.TRUE,
149 actual=stepResult,
150 onpass="Successfully applied cell to " + \
151 "environment",
152 onfail="Failed to apply cell to environment " )
153
154 main.step( "Creating ONOS package" )
Jon Hallbd60ea02016-08-23 10:03:59 -0700155 packageResult = main.ONOSbench.buckBuild()
acsmars51a7fe02015-10-29 18:33:32 -0700156 stepResult = packageResult
157 utilities.assert_equals( expect=main.TRUE,
158 actual=stepResult,
159 onpass="Successfully created ONOS package",
160 onfail="Failed to create ONOS package" )
161
162 time.sleep( main.startUpSleep )
163 main.step( "Uninstalling ONOS package" )
164 onosUninstallResult = main.TRUE
165 for ip in main.ONOSip:
166 onosUninstallResult = onosUninstallResult and \
167 main.ONOSbench.onosUninstall( nodeIp=ip )
168 stepResult = onosUninstallResult
169 utilities.assert_equals( expect=main.TRUE,
170 actual=stepResult,
171 onpass="Successfully uninstalled ONOS package",
172 onfail="Failed to uninstall ONOS package" )
173
174 time.sleep( main.startUpSleep )
175 main.step( "Installing ONOS package" )
176 onosInstallResult = main.TRUE
177 for i in range( main.numCtrls ):
178 onosInstallResult = onosInstallResult and \
179 main.ONOSbench.onosInstall( node=main.ONOSip[ i ] )
180 # Populate activeONOSip
181 main.activeONOSip.append( main.ONOSip[ i ] )
182 stepResult = onosInstallResult
183 utilities.assert_equals( expect=main.TRUE,
184 actual=stepResult,
185 onpass="Successfully installed ONOS package",
186 onfail="Failed to install ONOS package" )
187
You Wangf5de25b2017-01-06 15:13:01 -0800188 main.step( "Set up ONOS secure SSH" )
189 secureSshResult = main.TRUE
190 for i in range( int( main.numCtrls ) ):
191 secureSshResult = secureSshResult and main.ONOSbench.onosSecureSSH( node=main.ONOSip[i] )
192 utilities.assert_equals( expect=main.TRUE, actual=secureSshResult,
193 onpass="Test step PASS",
194 onfail="Test step FAIL" )
195
acsmars51a7fe02015-10-29 18:33:32 -0700196 time.sleep( main.startUpSleep )
197 main.step( "Starting ONOS service" )
198 stopResult = main.TRUE
199 startResult = main.TRUE
200 onosIsUp = main.TRUE
201
202 for i in range( main.numCtrls ):
Jeremy Songster7edb6632016-04-28 15:44:28 -0700203 isUp = main.ONOSbench.isup( main.ONOSip[ i ] )
204 onosIsUp = onosIsUp and isUp
205 if isUp == main.TRUE:
206 main.log.report( "ONOS instance {0} is up and ready".format( i + 1 ) )
207 else:
208 main.log.report( "ONOS instance {0} may not be up, stop and ".format( i + 1 ) +
209 "start ONOS again " )
210 stopResult = stopResult and main.ONOSbench.onosStop( main.ONOSip[ i ] )
211 startResult = startResult and main.ONOSbench.onosStart( main.ONOSip[ i ] )
212 if not startResult or stopResult:
213 main.log.report( "ONOS instance {0} did not start correctly.".format( i + 1) )
acsmars51a7fe02015-10-29 18:33:32 -0700214 stepResult = onosIsUp and stopResult and startResult
215 utilities.assert_equals( expect=main.TRUE,
216 actual=stepResult,
Jeremy Songster7edb6632016-04-28 15:44:28 -0700217 onpass="ONOS service is ready on all nodes",
218 onfail="ONOS service did not start properly on all nodes" )
acsmars51a7fe02015-10-29 18:33:32 -0700219
220 main.step( "Start ONOS cli" )
221 cliResult = main.TRUE
222 for i in range( main.numCtrls ):
223 cliResult = cliResult and \
224 main.CLIs[ i ].startOnosCli( main.ONOSip[ i ] )
225 stepResult = cliResult
226 utilities.assert_equals( expect=main.TRUE,
227 actual=stepResult,
228 onpass="Successfully start ONOS cli",
229 onfail="Failed to start ONOS cli" )
230
231 # Remove the first element in main.scale list
232 main.scale.remove( main.scale[ 0 ] )
233
acsmars51a7fe02015-10-29 18:33:32 -0700234 def CASE10( self, main ):
235 """
236 Start Mininet opticalTest Topology
237 """
238 main.case( "Mininet with Linc-OE startup")
239 main.caseExplanation = "Start opticalTest.py topology included with ONOS"
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700240 if main.opticalTopo:
241 main.step( "Copying optical topology to $ONOS_ROOT/tools/test/topos/" )
242 main.ONOSbench.scp( main.ONOSbench,
243 "{0}{1}.py".format( main.dependencyPath, main.opticalTopo ),
244 "~/onos/tools/test/topos/{0}.py".format( main.opticalTopo ) )
acsmars51a7fe02015-10-29 18:33:32 -0700245 main.step( "Starting mininet and LINC-OE" )
246 topoResult = main.TRUE
247 time.sleep( 10 )
248 controllerIPs = ' '.join( main.activeONOSip )
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700249 opticalMnScript = main.LincOE.runOpticalMnScript(ctrllerIP = controllerIPs, topology=main.opticalTopo )
acsmars51a7fe02015-10-29 18:33:32 -0700250 topoResult = opticalMnScript
251 utilities.assert_equals(
252 expect=main.TRUE,
253 actual=topoResult,
254 onpass="Started the topology successfully ",
255 onfail="Failed to start the topology")
256
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700257 main.step( "Push Topology.json to ONOS through onos-netcfg" )
258 pushResult = main.TRUE
259 time.sleep( 20 )
260 main.ONOSbench.onosNetCfg( controllerIps=controllerIPs, path=main.dependencyPath, fileName="Topology" )
261
acsmars51a7fe02015-10-29 18:33:32 -0700262 # Exit if topology did not load properly
263 if not topoResult:
264 main.cleanup()
265 main.exit()
266
Jeremye4bc7132016-03-30 14:04:01 -0700267
acsmars51a7fe02015-10-29 18:33:32 -0700268
269
270 def CASE14( self, main ):
271 """
272 Stop mininet
273 """
274 main.log.report( "Stop Mininet topology" )
275 main.case( "Stop Mininet topology" )
276 main.caseExplanation = "Stopping the current mininet topology " +\
277 "to start up fresh"
278
279 main.step( "Stopping Mininet Topology" )
280 topoResult = main.LincOE.stopNet( timeout=180 )
281 utilities.assert_equals( expect=main.TRUE,
282 actual=topoResult,
283 onpass="Successfully stopped mininet",
284 onfail="Failed to stopped mininet" )
285 # Exit if topology did not load properly
286 if not topoResult:
287 main.cleanup()
288 main.exit()
289
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700290 def CASE16( self, main ):
291 """
292 Balance Masters
293 """
294 main.case( "Balance mastership of switches" )
295 main.step( "Balancing mastership of switches" )
296
297 balanceResult = main.FALSE
298 balanceResult = utilities.retry( f=main.CLIs[ 0 ].balanceMasters, retValue=main.FALSE, args=[] )
299
300 utilities.assert_equals( expect=main.TRUE,
301 actual=balanceResult,
302 onpass="Successfully balanced mastership of switches",
303 onfail="Failed to balance mastership of switches" )
304 if not balanceResult:
305 main.initialized = main.FALSE
306
Jeremye4bc7132016-03-30 14:04:01 -0700307 def CASE17( self, main ):
308 """
309 Use Flow Objectives
310 """
311 main.case( "Enable intent compilation using Flow Objectives" )
312 main.step( "Enabling Flow Objectives" )
313
314 main.flowCompiler = "Flow Objectives"
315
316 cmd = "org.onosproject.net.intent.impl.compiler.IntentConfigurableRegistrator"
317
318 stepResult = main.CLIs[ 0 ].setCfg( component=cmd,
319 propName="useFlowObjectives", value="true" )
320
321 utilities.assert_equals( expect=main.TRUE,
322 actual=stepResult,
323 onpass="Successfully activated Flow Objectives",
324 onfail="Failed to activate Flow Objectives" )
325
Jeremy Songster17147f22016-05-31 18:30:52 -0700326 def CASE19( self, main ):
327 """
328 Copy the karaf.log files after each testcase cycle
329 """
330 main.log.report( "Copy karaf logs" )
331 main.case( "Copy karaf logs" )
332 main.caseExplanation = "Copying the karaf logs to preserve them through" +\
333 "reinstalling ONOS"
334 main.step( "Copying karaf logs" )
Jeremy Songster31aad312016-06-13 16:32:11 -0700335 stepResult = main.TRUE
336 scpResult = main.TRUE
337 copyResult = main.TRUE
Jeremy Songstercc5414b2016-07-11 10:59:53 -0700338 for i in range( main.numCtrls ):
339 main.node = main.CLIs[ i ]
Jeremy Songster17147f22016-05-31 18:30:52 -0700340 ip = main.ONOSip[ i ]
341 main.node.ip_address = ip
Jeremy Songster31aad312016-06-13 16:32:11 -0700342 scpResult = scpResult and main.ONOSbench.scp( main.node ,
343 "/opt/onos/log/karaf.log",
344 "/tmp/karaf.log",
345 direction="from" )
346 copyResult = copyResult and main.ONOSbench.cpLogsToDir( "/tmp/karaf.log", main.logdir,
347 copyFileName=( "karaf.log.node{0}.cycle{1}".format( str( i + 1 ), str( main.cycle ) ) ) )
348 if scpResult and copyResult:
349 stepResult = main.TRUE and stepResult
350 else:
351 stepResult = main.FALSE and stepResult
Jeremy Songster31aad312016-06-13 16:32:11 -0700352 utilities.assert_equals( expect=main.TRUE,
353 actual=stepResult,
354 onpass="Successfully copied remote ONOS logs",
355 onfail="Failed to copy remote ONOS logs" )
Jeremy Songster17147f22016-05-31 18:30:52 -0700356
acsmars51a7fe02015-10-29 18:33:32 -0700357 def CASE21( self,main ):
358 """
359 Run pingall to discover all hosts
360 """
361 main.case( "Running Pingall" )
362 main.caseExplanation = "Use pingall to discover all hosts. Pingall is expected to fail."
363 main.step( "Discover Hosts through Pingall" )
Jeremy Songster7edb6632016-04-28 15:44:28 -0700364 pingResult = main.LincOE.pingall( timeout = 120 )
acsmars51a7fe02015-10-29 18:33:32 -0700365
366 utilities.assert_equals( expect=main.FALSE,
367 actual=pingResult,
368 onpass="Pingall Completed",
369 onfail="Pingall did not complete or did not return fales" )
370
371 def CASE22( self,main ):
372 """
373 Send arpings to discover all hosts
374 """
375 main.case( "Discover Hosts with arping" )
376 main.caseExplanation = "Send arpings between all the hosts to discover and verify them"
377
378 main.step( "Send arping between all hosts" )
379
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700380 hosts = []
381 for i in range( main.hosts ):
382 hosts.append( 'h{}'.format( i + 1 ) )
acsmars51a7fe02015-10-29 18:33:32 -0700383
384 arpingHostResults = main.TRUE
385 for host in hosts:
386 if main.LincOE.arping( host ):
387 main.log.info( "Successfully reached host {} with arping".format( host ) )
388 else:
389 main.log.error( "Could not reach host {} with arping".format( host ) )
390 arpingHostResults = main.FALSE
391
392 utilities.assert_equals( expect=main.TRUE,
393 actual=arpingHostResults,
394 onpass="Successfully discovered all hosts",
395 onfail="Could not descover some hosts" )
396
397 def CASE23( self, main ):
398 """
399 Compare ONOS Topology to Mininet Topology
400 """
401 import json
402
403 main.case( "Compare ONOS Topology view to Mininet topology" )
404 main.caseExplanation = "Compare topology elements between Mininet" +\
405 " and ONOS"
406
407 main.log.info( "Gathering topology information from Mininet" )
408 devicesResults = main.FALSE # Overall Boolean for device correctness
409 linksResults = main.FALSE # Overall Boolean for link correctness
410 hostsResults = main.FALSE # Overall Boolean for host correctness
411 deviceFails = [] # Nodes where devices are incorrect
412 linkFails = [] # Nodes where links are incorrect
413 hostFails = [] # Nodes where hosts are incorrect
414 attempts = main.checkTopoAttempts # Remaining Attempts
415
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700416 mnSwitches = main.switches
417 mnLinks = main.links
418 mnHosts = main.hosts
acsmars51a7fe02015-10-29 18:33:32 -0700419
Jon Hall70b2ff42015-11-17 15:49:44 -0800420 main.step( "Comparing Mininet topology to ONOS topology" )
acsmars51a7fe02015-10-29 18:33:32 -0700421
422 while ( attempts >= 0 ) and\
423 ( not devicesResults or not linksResults or not hostsResults ):
424 time.sleep( 2 )
425 if not devicesResults:
426 devices = main.topo.getAllDevices( main )
427 ports = main.topo.getAllPorts( main )
428 devicesResults = main.TRUE
429 deviceFails = [] # Reset for each attempt
430 if not linksResults:
431 links = main.topo.getAllLinks( main )
432 linksResults = main.TRUE
433 linkFails = [] # Reset for each attempt
434 if not hostsResults:
435 hosts = main.topo.getAllHosts( main )
436 hostsResults = main.TRUE
437 hostFails = [] # Reset for each attempt
438
439 # Check for matching topology on each node
440 for controller in range( main.numCtrls ):
441 controllerStr = str( controller + 1 ) # ONOS node number
442 # Compare Devices
443 if devices[ controller ] and ports[ controller ] and\
444 "Error" not in devices[ controller ] and\
445 "Error" not in ports[ controller ]:
446
447 try:
448 deviceData = json.loads( devices[ controller ] )
449 portData = json.loads( ports[ controller ] )
450 except (TypeError,ValueError):
451 main.log.error("Could not load json:" + str( devices[ controller ] ) + ' or ' + str( ports[ controller ] ))
452 currentDevicesResult = main.FALSE
453 else:
454 if mnSwitches == len( deviceData ):
455 currentDevicesResult = main.TRUE
456 else:
457 currentDevicesResult = main.FALSE
Jeremye4bc7132016-03-30 14:04:01 -0700458 main.log.error( "Node {} only sees {} device(s) but {} exist".format(
acsmars51a7fe02015-10-29 18:33:32 -0700459 controllerStr,len( deviceData ),mnSwitches ) )
460 else:
461 currentDevicesResult = main.FALSE
462 if not currentDevicesResult:
463 deviceFails.append( controllerStr )
464 devicesResults = devicesResults and currentDevicesResult
465 # Compare Links
466 if links[ controller ] and "Error" not in links[ controller ]:
467 try:
468 linkData = json.loads( links[ controller ] )
469 except (TypeError,ValueError):
470 main.log.error("Could not load json:" + str( links[ controller ] ) )
471 currentLinksResult = main.FALSE
472 else:
473 if mnLinks == len( linkData ):
474 currentLinksResult = main.TRUE
475 else:
476 currentLinksResult = main.FALSE
Jeremye4bc7132016-03-30 14:04:01 -0700477 main.log.error( "Node {} only sees {} link(s) but {} exist".format(
acsmars51a7fe02015-10-29 18:33:32 -0700478 controllerStr,len( linkData ),mnLinks ) )
479 else:
480 currentLinksResult = main.FALSE
481 if not currentLinksResult:
482 linkFails.append( controllerStr )
483 linksResults = linksResults and currentLinksResult
484 # Compare Hosts
485 if hosts[ controller ] and "Error" not in hosts[ controller ]:
486 try:
487 hostData = json.loads( hosts[ controller ] )
488 except (TypeError,ValueError):
489 main.log.error("Could not load json:" + str( hosts[ controller ] ) )
490 currentHostsResult = main.FALSE
491 else:
492 if mnHosts == len( hostData ):
493 currentHostsResult = main.TRUE
494 else:
495 currentHostsResult = main.FALSE
Jeremye4bc7132016-03-30 14:04:01 -0700496 main.log.error( "Node {} only sees {} host(s) but {} exist".format(
acsmars51a7fe02015-10-29 18:33:32 -0700497 controllerStr,len( hostData ),mnHosts ) )
498 else:
499 currentHostsResult = main.FALSE
500 if not currentHostsResult:
501 hostFails.append( controllerStr )
502 hostsResults = hostsResults and currentHostsResult
503 # Decrement Attempts Remaining
504 attempts -= 1
505
506 utilities.assert_equals( expect=[],
507 actual=deviceFails,
508 onpass="ONOS correctly discovered all devices",
509 onfail="ONOS incorrectly discovered devices on nodes: " +
510 str( deviceFails ) )
511 utilities.assert_equals( expect=[],
512 actual=linkFails,
513 onpass="ONOS correctly discovered all links",
514 onfail="ONOS incorrectly discovered links on nodes: " +
515 str( linkFails ) )
516 utilities.assert_equals( expect=[],
517 actual=hostFails,
518 onpass="ONOS correctly discovered all hosts",
519 onfail="ONOS incorrectly discovered hosts on nodes: " +
520 str( hostFails ) )
521 if hostsResults and linksResults and devicesResults:
522 topoResults = main.TRUE
523 else:
524 topoResults = main.FALSE
525 utilities.assert_equals( expect=main.TRUE,
526 actual=topoResults,
527 onpass="ONOS correctly discovered the topology",
528 onfail="ONOS incorrectly discovered the topology" )
529
530
531 def CASE31( self, main ):
532 import time
533 """
534 Add bidirectional point intents between 2 packet layer( mininet )
535 devices and ping mininet hosts
536 """
537 main.log.report(
538 "This testcase adds bidirectional point intents between 2 " +
539 "packet layer( mininet ) devices and ping mininet hosts" )
540 main.case( "Install point intents between 2 packet layer device and " +
541 "ping the hosts" )
542 main.caseExplanation = "This testcase adds bidirectional point intents between 2 " +\
543 "packet layer( mininet ) devices and ping mininet hosts"
544
545 main.step( "Adding point intents" )
546 checkFlowResult = main.TRUE
547 main.pIntentsId = []
548 pIntent1 = main.CLIs[ 0 ].addPointIntent(
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700549 "of:0000000000000001/1",
550 "of:0000000000000002/1" )
acsmars51a7fe02015-10-29 18:33:32 -0700551 time.sleep( 10 )
552 pIntent2 = main.CLIs[ 0 ].addPointIntent(
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700553 "of:0000000000000002/1",
554 "of:0000000000000001/1" )
acsmars51a7fe02015-10-29 18:33:32 -0700555 main.pIntentsId.append( pIntent1 )
556 main.pIntentsId.append( pIntent2 )
557 time.sleep( 10 )
558 main.log.info( "Checking intents state")
559 checkStateResult = main.CLIs[ 0 ].checkIntentState(
560 intentsId = main.pIntentsId )
561 time.sleep( 10 )
562 main.log.info( "Checking flows state")
563 checkFlowResult = main.CLIs[ 0 ].checkFlowsState()
564 # Sleep for 10 seconds to provide time for the intent state to change
565 time.sleep( 10 )
566 main.log.info( "Checking intents state one more time")
567 checkStateResult = main.CLIs[ 0 ].checkIntentState(
568 intentsId = main.pIntentsId )
Jeremye4bc7132016-03-30 14:04:01 -0700569
acsmars51a7fe02015-10-29 18:33:32 -0700570 if checkStateResult and checkFlowResult:
571 addIntentsResult = main.TRUE
572 else:
573 addIntentsResult = main.FALSE
574 utilities.assert_equals(
575 expect=main.TRUE,
576 actual=addIntentsResult,
577 onpass="Successfully added point intents",
578 onfail="Failed to add point intents")
579
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700580 pingResult = main.FALSE
acsmars51a7fe02015-10-29 18:33:32 -0700581
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700582 if not addIntentsResult:
583 main.log.error( "Intents were not properly installed. Skipping ping." )
584
585 else:
586 main.step( "Ping h1 and h2" )
587 pingResult = main.LincOE.pingHostOptical( src="h1", target="h2" )
acsmars51a7fe02015-10-29 18:33:32 -0700588 utilities.assert_equals(
589 expect=main.TRUE,
590 actual=pingResult,
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700591 onpass="Successfully pinged h1 and h2",
592 onfail="Failed to ping between h1 and h2")
593
594 main.step( "Remove Point to Point intents" )
595 removeResult = main.FALSE
596 # Check remaining intents
597 try:
598 intentsJson = json.loads( main.CLIs[ 0 ].intents() )
599 main.log.debug( intentsJson )
600 main.CLIs[ 0 ].removeIntent( intentId=pIntent1, purge=True )
601 main.CLIs[ 0 ].removeIntent( intentId=pIntent2, purge=True )
602 for intents in intentsJson:
603 main.CLIs[ 0 ].removeIntent( intentId=intents.get( 'id' ),
604 app='org.onosproject.cli',
605 purge=True )
606 time.sleep( 15 )
607
608 for i in range( main.numCtrls ):
609 if len( json.loads( main.CLIs[ i ].intents() ) ):
610 print json.loads( main.CLIs[ i ].intents() )
611 removeResult = main.FALSE
612 else:
613 removeResult = main.TRUE
614 except ( TypeError, ValueError ):
615 main.log.error( "Cannot see intents on Node " + str( main.CLIs[ 0 ] ) +\
616 ". Removing all intents.")
617 main.CLIs[ 0 ].removeAllIntents( purge=True )
618 main.CLIs[ 0 ].removeAllIntents( purge=True, app='org.onosproject.cli')
619
620 utilities.assert_equals( expect=main.TRUE,
621 actual=removeResult,
622 onpass="Successfully removed host intents",
623 onfail="Failed to remove host intents" )
acsmars51a7fe02015-10-29 18:33:32 -0700624
625 def CASE32( self ):
626 """
627 Add host intents between 2 packet layer host
628 """
629 import time
630 import json
631 main.log.report( "Adding host intents between 2 optical layer host" )
632 main.case( "Test add host intents between optical layer host" )
633 main.caseExplanation = "Test host intents between 2 optical layer host"
634
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700635 main.step( "Creating list of hosts" )
636 hostnum = 0
637 try:
638 hostData = json.loads( hosts[ controller ] )
639 except( TypeError, ValueError ):
640 main.log.error("Could not load json:" + str( hosts[ controller ] ) )
641
acsmars51a7fe02015-10-29 18:33:32 -0700642 main.step( "Adding host intents to h1 and h2" )
acsmars51a7fe02015-10-29 18:33:32 -0700643 hostId = []
644 # Listing host MAC addresses
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700645 for host in hostData:
646 hostId.append( host.get("id") )
acsmars51a7fe02015-10-29 18:33:32 -0700647 host1 = hostId[ 0 ]
648 host2 = hostId[ 1 ]
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700649 main.log.debug( host1 )
650 main.log.debug( host2 )
acsmars51a7fe02015-10-29 18:33:32 -0700651
652 intentsId = []
653 intent1 = main.CLIs[ 0 ].addHostIntent( hostIdOne = host1,
654 hostIdTwo = host2 )
655 intentsId.append( intent1 )
656 # Checking intents state before pinging
657 main.log.info( "Checking intents state" )
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700658 intentResult = utilities.retry( f=main.CLIs[ 0 ].checkIntentState,
659 retValue=main.FALSE, args=intentsId,
660 sleep=main.checkIntentSleep, attempts=10 )
acsmars51a7fe02015-10-29 18:33:32 -0700661
662 # If intent state is still wrong, display intent states
663 if not intentResult:
664 main.log.error( main.CLIs[ 0 ].intents() )
Jeremye4bc7132016-03-30 14:04:01 -0700665
acsmars51a7fe02015-10-29 18:33:32 -0700666 utilities.assert_equals( expect=main.TRUE,
667 actual=intentResult,
668 onpass="All intents are in INSTALLED state ",
669 onfail="Some of the intents are not in " +
670 "INSTALLED state " )
671
672 if not intentResult:
673 main.log.error( "Intents were not properly installed. Skipping Ping" )
674 else:
675 # Pinging h1 to h2 and then ping h2 to h1
676 main.step( "Pinging h1 and h2" )
677 pingResult = main.TRUE
678 pingResult = main.LincOE.pingHostOptical( src="h1", target="h2" ) \
679 and main.LincOE.pingHostOptical( src="h2",target="h1" )
Jeremye4bc7132016-03-30 14:04:01 -0700680
acsmars51a7fe02015-10-29 18:33:32 -0700681 utilities.assert_equals( expect=main.TRUE,
682 actual=pingResult,
683 onpass="Pinged successfully between h1 and h2",
684 onfail="Pinged failed between h1 and h2" )
685
686 # Removed all added host intents
687 main.step( "Removing host intents" )
688 removeResult = main.TRUE
689 # Check remaining intents
Jeremy7134f5b2016-04-05 13:50:21 -0700690 try:
691 intentsJson = json.loads( main.CLIs[ 0 ].intents() )
692 main.CLIs[ 0 ].removeIntent( intentId=intent1, purge=True )
693 #main.CLIs[ 0 ].removeIntent( intentId=intent2, purge=True )
694 main.log.debug(intentsJson)
695 for intents in intentsJson:
Jeremye4bc7132016-03-30 14:04:01 -0700696 main.CLIs[ 0 ].removeIntent( intentId=intents.get( 'id' ),
697 app='org.onosproject.optical',
698 purge=True )
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700699 time.sleep( 15 )
acsmars51a7fe02015-10-29 18:33:32 -0700700
Jeremy7134f5b2016-04-05 13:50:21 -0700701 for i in range( main.numCtrls ):
702 if len( json.loads( main.CLIs[ i ].intents() ) ):
703 print json.loads( main.CLIs[ i ].intents() )
704 removeResult = main.FALSE
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700705 else:
706 removeResult = main.TRUE
Jeremy7134f5b2016-04-05 13:50:21 -0700707 except ( TypeError, ValueError ):
708 main.log.error( "Cannot see intents on Node " + str( main.CLIs[ 0 ] ) +\
709 ". Removing all intents.")
710 main.CLIs[ 0 ].removeAllIntents( purge=True )
711 main.CLIs[ 0 ].removeAllIntents( purge=True, app='org.onosproject.optical')
712
713 utilities.assert_equals( expect=main.TRUE,
714 actual=removeResult,
715 onpass="Successfully removed host intents",
Chiyu Chengef109502016-11-21 15:51:38 -0800716 onfail="Failed to remove host intents" )