blob: 61da26b9c07449a9a617b9b30274b4103f1989fa [file] [log] [blame]
acsmars51a7fe02015-10-29 18:33:32 -07001# Testing the basic intent functionality of ONOS
2
Jon Halle02505a2017-05-24 16:36:43 -07003
acsmars51a7fe02015-10-29 18:33:32 -07004class FUNCoptical:
5
6 def __init__( self ):
7 self.default = ''
8
9 def CASE1( self, main ):
10 import time
11 import imp
12 import re
13
14 """
15 - Construct tests variables
16 - GIT ( optional )
17 - Checkout ONOS master branch
18 - Pull latest ONOS code
19 - Building ONOS ( optional )
20 - Install ONOS package
21 - Build ONOS package
22 """
acsmars51a7fe02015-10-29 18:33:32 -070023 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' ]
Jon Halle02505a2017-05-24 16:36:43 -070051 main.cellData = {} # For creating cell file
acsmars51a7fe02015-10-29 18:33:32 -070052 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
Jon Halle02505a2017-05-24 16:36:43 -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
Jon Halle02505a2017-05-24 16:36:43 -070062 for i in range( 1, main.maxNodes + 1 ):
acsmars51a7fe02015-10-29 18:33:32 -070063 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:
Jon Halle02505a2017-05-24 16:36:43 -070076 main.log.exception( e )
acsmars51a7fe02015-10-29 18:33:32 -070077 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 """
Jeremy Songster17147f22016-05-31 18:30:52 -0700113 main.cycle += 1
114
acsmars51a7fe02015-10-29 18:33:32 -0700115 # main.scale[ 0 ] determines the current number of ONOS controller
116 main.numCtrls = int( main.scale[ 0 ] )
Jeremye4bc7132016-03-30 14:04:01 -0700117 main.flowCompiler = "Flow Rules"
acsmars51a7fe02015-10-29 18:33:32 -0700118
119 main.case( "Starting up " + str( main.numCtrls ) +
120 " node(s) ONOS cluster" )
121 main.caseExplanation = "Set up ONOS with " + str( main.numCtrls ) +\
122 " node(s) ONOS cluster"
123
acsmars51a7fe02015-10-29 18:33:32 -0700124 #kill off all onos processes
125 main.log.info( "Safety check, killing all ONOS processes" +
Jon Hall70b2ff42015-11-17 15:49:44 -0800126 " before initiating environment setup" )
acsmars51a7fe02015-10-29 18:33:32 -0700127
128 for i in range( main.maxNodes ):
129 main.ONOSbench.onosDie( main.ONOSip[ i ] )
130
131 print "NODE COUNT = ", main.numCtrls
132
133 tempOnosIp = []
134 for i in range( main.numCtrls ):
Jon Halle02505a2017-05-24 16:36:43 -0700135 tempOnosIp.append( main.ONOSip[ i ] )
acsmars51a7fe02015-10-29 18:33:32 -0700136
137 main.ONOSbench.createCellFile( main.ONOSbench.ip_address,
138 "temp", main.Mininet1.ip_address,
Devin Lim461f0872017-06-05 16:49:33 -0700139 main.apps, tempOnosIp, main.ONOScli1.user_name )
acsmars51a7fe02015-10-29 18:33:32 -0700140
141 main.step( "Apply cell to environment" )
142 cellResult = main.ONOSbench.setCell( "temp" )
143 verifyResult = main.ONOSbench.verifyCell()
144 stepResult = cellResult and verifyResult
145 utilities.assert_equals( expect=main.TRUE,
146 actual=stepResult,
Jon Halle02505a2017-05-24 16:36:43 -0700147 onpass="Successfully applied cell to " +
acsmars51a7fe02015-10-29 18:33:32 -0700148 "environment",
149 onfail="Failed to apply cell to environment " )
150
151 main.step( "Creating ONOS package" )
Jon Hallbd60ea02016-08-23 10:03:59 -0700152 packageResult = main.ONOSbench.buckBuild()
acsmars51a7fe02015-10-29 18:33:32 -0700153 stepResult = packageResult
154 utilities.assert_equals( expect=main.TRUE,
155 actual=stepResult,
156 onpass="Successfully created ONOS package",
157 onfail="Failed to create ONOS package" )
158
159 time.sleep( main.startUpSleep )
160 main.step( "Uninstalling ONOS package" )
161 onosUninstallResult = main.TRUE
162 for ip in main.ONOSip:
163 onosUninstallResult = onosUninstallResult and \
164 main.ONOSbench.onosUninstall( nodeIp=ip )
165 stepResult = onosUninstallResult
166 utilities.assert_equals( expect=main.TRUE,
167 actual=stepResult,
168 onpass="Successfully uninstalled ONOS package",
169 onfail="Failed to uninstall ONOS package" )
170
171 time.sleep( main.startUpSleep )
172 main.step( "Installing ONOS package" )
173 onosInstallResult = main.TRUE
174 for i in range( main.numCtrls ):
175 onosInstallResult = onosInstallResult and \
176 main.ONOSbench.onosInstall( node=main.ONOSip[ i ] )
177 # Populate activeONOSip
178 main.activeONOSip.append( main.ONOSip[ i ] )
179 stepResult = onosInstallResult
180 utilities.assert_equals( expect=main.TRUE,
181 actual=stepResult,
182 onpass="Successfully installed ONOS package",
183 onfail="Failed to install ONOS package" )
184
You Wangf5de25b2017-01-06 15:13:01 -0800185 main.step( "Set up ONOS secure SSH" )
186 secureSshResult = main.TRUE
187 for i in range( int( main.numCtrls ) ):
Jon Halle02505a2017-05-24 16:36:43 -0700188 secureSshResult = secureSshResult and main.ONOSbench.onosSecureSSH( node=main.ONOSip[ i ] )
You Wangf5de25b2017-01-06 15:13:01 -0800189 utilities.assert_equals( expect=main.TRUE, actual=secureSshResult,
190 onpass="Test step PASS",
191 onfail="Test step FAIL" )
192
acsmars51a7fe02015-10-29 18:33:32 -0700193 time.sleep( main.startUpSleep )
194 main.step( "Starting ONOS service" )
195 stopResult = main.TRUE
196 startResult = main.TRUE
197 onosIsUp = main.TRUE
198
199 for i in range( main.numCtrls ):
Jeremy Songster7edb6632016-04-28 15:44:28 -0700200 isUp = main.ONOSbench.isup( main.ONOSip[ i ] )
201 onosIsUp = onosIsUp and isUp
202 if isUp == main.TRUE:
203 main.log.report( "ONOS instance {0} is up and ready".format( i + 1 ) )
204 else:
205 main.log.report( "ONOS instance {0} may not be up, stop and ".format( i + 1 ) +
206 "start ONOS again " )
207 stopResult = stopResult and main.ONOSbench.onosStop( main.ONOSip[ i ] )
208 startResult = startResult and main.ONOSbench.onosStart( main.ONOSip[ i ] )
209 if not startResult or stopResult:
Jon Halle02505a2017-05-24 16:36:43 -0700210 main.log.report( "ONOS instance {0} did not start correctly.".format( i + 1 ) )
acsmars51a7fe02015-10-29 18:33:32 -0700211 stepResult = onosIsUp and stopResult and startResult
212 utilities.assert_equals( expect=main.TRUE,
213 actual=stepResult,
Jeremy Songster7edb6632016-04-28 15:44:28 -0700214 onpass="ONOS service is ready on all nodes",
215 onfail="ONOS service did not start properly on all nodes" )
acsmars51a7fe02015-10-29 18:33:32 -0700216
217 main.step( "Start ONOS cli" )
218 cliResult = main.TRUE
219 for i in range( main.numCtrls ):
220 cliResult = cliResult and \
221 main.CLIs[ i ].startOnosCli( main.ONOSip[ i ] )
222 stepResult = cliResult
223 utilities.assert_equals( expect=main.TRUE,
224 actual=stepResult,
225 onpass="Successfully start ONOS cli",
226 onfail="Failed to start ONOS cli" )
227
228 # Remove the first element in main.scale list
229 main.scale.remove( main.scale[ 0 ] )
230
acsmars51a7fe02015-10-29 18:33:32 -0700231 def CASE10( self, main ):
232 """
233 Start Mininet opticalTest Topology
234 """
Jon Halle02505a2017-05-24 16:36:43 -0700235 main.case( "Mininet with Linc-OE startup" )
acsmars51a7fe02015-10-29 18:33:32 -0700236 main.caseExplanation = "Start opticalTest.py topology included with ONOS"
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700237 if main.opticalTopo:
238 main.step( "Copying optical topology to $ONOS_ROOT/tools/test/topos/" )
239 main.ONOSbench.scp( main.ONOSbench,
240 "{0}{1}.py".format( main.dependencyPath, main.opticalTopo ),
241 "~/onos/tools/test/topos/{0}.py".format( main.opticalTopo ) )
acsmars51a7fe02015-10-29 18:33:32 -0700242 main.step( "Starting mininet and LINC-OE" )
243 topoResult = main.TRUE
244 time.sleep( 10 )
245 controllerIPs = ' '.join( main.activeONOSip )
Jon Halle02505a2017-05-24 16:36:43 -0700246 opticalMnScript = main.LincOE.runOpticalMnScript( ctrllerIP=controllerIPs, topology=main.opticalTopo )
acsmars51a7fe02015-10-29 18:33:32 -0700247 topoResult = opticalMnScript
248 utilities.assert_equals(
249 expect=main.TRUE,
250 actual=topoResult,
251 onpass="Started the topology successfully ",
Jon Halle02505a2017-05-24 16:36:43 -0700252 onfail="Failed to start the topology" )
acsmars51a7fe02015-10-29 18:33:32 -0700253
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700254 main.step( "Push Topology.json to ONOS through onos-netcfg" )
255 pushResult = main.TRUE
256 time.sleep( 20 )
257 main.ONOSbench.onosNetCfg( controllerIps=controllerIPs, path=main.dependencyPath, fileName="Topology" )
258
acsmars51a7fe02015-10-29 18:33:32 -0700259 # Exit if topology did not load properly
260 if not topoResult:
261 main.cleanup()
262 main.exit()
263
acsmars51a7fe02015-10-29 18:33:32 -0700264 def CASE14( self, main ):
265 """
266 Stop mininet
267 """
268 main.log.report( "Stop Mininet topology" )
269 main.case( "Stop Mininet topology" )
270 main.caseExplanation = "Stopping the current mininet topology " +\
271 "to start up fresh"
272
273 main.step( "Stopping Mininet Topology" )
274 topoResult = main.LincOE.stopNet( timeout=180 )
275 utilities.assert_equals( expect=main.TRUE,
276 actual=topoResult,
277 onpass="Successfully stopped mininet",
278 onfail="Failed to stopped mininet" )
279 # Exit if topology did not load properly
280 if not topoResult:
281 main.cleanup()
282 main.exit()
283
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700284 def CASE16( self, main ):
285 """
286 Balance Masters
287 """
288 main.case( "Balance mastership of switches" )
289 main.step( "Balancing mastership of switches" )
290
291 balanceResult = main.FALSE
292 balanceResult = utilities.retry( f=main.CLIs[ 0 ].balanceMasters, retValue=main.FALSE, args=[] )
293
294 utilities.assert_equals( expect=main.TRUE,
295 actual=balanceResult,
296 onpass="Successfully balanced mastership of switches",
297 onfail="Failed to balance mastership of switches" )
298 if not balanceResult:
299 main.initialized = main.FALSE
300
Jeremye4bc7132016-03-30 14:04:01 -0700301 def CASE17( self, main ):
302 """
303 Use Flow Objectives
304 """
305 main.case( "Enable intent compilation using Flow Objectives" )
306 main.step( "Enabling Flow Objectives" )
307
308 main.flowCompiler = "Flow Objectives"
309
310 cmd = "org.onosproject.net.intent.impl.compiler.IntentConfigurableRegistrator"
311
312 stepResult = main.CLIs[ 0 ].setCfg( component=cmd,
313 propName="useFlowObjectives", value="true" )
You Wang106d0fa2017-05-15 17:22:15 -0700314 stepResult &= main.CLIs[ 0 ].setCfg( component=cmd,
315 propName="defaultFlowObjectiveCompiler",
Jon Halle02505a2017-05-24 16:36:43 -0700316 value='org.onosproject.net.intent.impl.compiler.LinkCollectionIntentObjectiveCompiler' )
Jeremye4bc7132016-03-30 14:04:01 -0700317
318 utilities.assert_equals( expect=main.TRUE,
319 actual=stepResult,
320 onpass="Successfully activated Flow Objectives",
321 onfail="Failed to activate Flow Objectives" )
322
Jeremy Songster17147f22016-05-31 18:30:52 -0700323 def CASE19( self, main ):
324 """
325 Copy the karaf.log files after each testcase cycle
326 """
327 main.log.report( "Copy karaf logs" )
328 main.case( "Copy karaf logs" )
329 main.caseExplanation = "Copying the karaf logs to preserve them through" +\
330 "reinstalling ONOS"
331 main.step( "Copying karaf logs" )
Jeremy Songster31aad312016-06-13 16:32:11 -0700332 stepResult = main.TRUE
333 scpResult = main.TRUE
334 copyResult = main.TRUE
Jeremy Songstercc5414b2016-07-11 10:59:53 -0700335 for i in range( main.numCtrls ):
336 main.node = main.CLIs[ i ]
Jeremy Songster17147f22016-05-31 18:30:52 -0700337 ip = main.ONOSip[ i ]
338 main.node.ip_address = ip
Jon Halle02505a2017-05-24 16:36:43 -0700339 scpResult = scpResult and main.ONOSbench.scp( main.node,
340 "/opt/onos/log/karaf.log",
341 "/tmp/karaf.log",
342 direction="from" )
Jeremy Songster31aad312016-06-13 16:32:11 -0700343 copyResult = copyResult and main.ONOSbench.cpLogsToDir( "/tmp/karaf.log", main.logdir,
344 copyFileName=( "karaf.log.node{0}.cycle{1}".format( str( i + 1 ), str( main.cycle ) ) ) )
345 if scpResult and copyResult:
Jon Halle02505a2017-05-24 16:36:43 -0700346 stepResult = main.TRUE and stepResult
Jeremy Songster31aad312016-06-13 16:32:11 -0700347 else:
348 stepResult = main.FALSE and stepResult
Jeremy Songster31aad312016-06-13 16:32:11 -0700349 utilities.assert_equals( expect=main.TRUE,
350 actual=stepResult,
351 onpass="Successfully copied remote ONOS logs",
352 onfail="Failed to copy remote ONOS logs" )
Jeremy Songster17147f22016-05-31 18:30:52 -0700353
Jon Halle02505a2017-05-24 16:36:43 -0700354 def CASE21( self, main ):
acsmars51a7fe02015-10-29 18:33:32 -0700355 """
356 Run pingall to discover all hosts
357 """
358 main.case( "Running Pingall" )
359 main.caseExplanation = "Use pingall to discover all hosts. Pingall is expected to fail."
360 main.step( "Discover Hosts through Pingall" )
Jon Halle02505a2017-05-24 16:36:43 -0700361 pingResult = main.LincOE.pingall( timeout=120 )
acsmars51a7fe02015-10-29 18:33:32 -0700362
363 utilities.assert_equals( expect=main.FALSE,
364 actual=pingResult,
365 onpass="Pingall Completed",
366 onfail="Pingall did not complete or did not return fales" )
367
Jon Halle02505a2017-05-24 16:36:43 -0700368 def CASE22( self, main ):
acsmars51a7fe02015-10-29 18:33:32 -0700369 """
370 Send arpings to discover all hosts
371 """
372 main.case( "Discover Hosts with arping" )
373 main.caseExplanation = "Send arpings between all the hosts to discover and verify them"
374
375 main.step( "Send arping between all hosts" )
376
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700377 hosts = []
378 for i in range( main.hosts ):
379 hosts.append( 'h{}'.format( i + 1 ) )
acsmars51a7fe02015-10-29 18:33:32 -0700380
381 arpingHostResults = main.TRUE
382 for host in hosts:
383 if main.LincOE.arping( host ):
384 main.log.info( "Successfully reached host {} with arping".format( host ) )
385 else:
386 main.log.error( "Could not reach host {} with arping".format( host ) )
387 arpingHostResults = main.FALSE
388
389 utilities.assert_equals( expect=main.TRUE,
390 actual=arpingHostResults,
391 onpass="Successfully discovered all hosts",
392 onfail="Could not descover some hosts" )
393
394 def CASE23( self, main ):
395 """
396 Compare ONOS Topology to Mininet Topology
397 """
398 import json
399
400 main.case( "Compare ONOS Topology view to Mininet topology" )
401 main.caseExplanation = "Compare topology elements between Mininet" +\
402 " and ONOS"
403
404 main.log.info( "Gathering topology information from Mininet" )
405 devicesResults = main.FALSE # Overall Boolean for device correctness
406 linksResults = main.FALSE # Overall Boolean for link correctness
407 hostsResults = main.FALSE # Overall Boolean for host correctness
408 deviceFails = [] # Nodes where devices are incorrect
409 linkFails = [] # Nodes where links are incorrect
410 hostFails = [] # Nodes where hosts are incorrect
411 attempts = main.checkTopoAttempts # Remaining Attempts
412
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700413 mnSwitches = main.switches
414 mnLinks = main.links
415 mnHosts = main.hosts
acsmars51a7fe02015-10-29 18:33:32 -0700416
Jon Hall70b2ff42015-11-17 15:49:44 -0800417 main.step( "Comparing Mininet topology to ONOS topology" )
acsmars51a7fe02015-10-29 18:33:32 -0700418
419 while ( attempts >= 0 ) and\
Jon Halle02505a2017-05-24 16:36:43 -0700420 ( not devicesResults or not linksResults or not hostsResults ):
acsmars51a7fe02015-10-29 18:33:32 -0700421 time.sleep( 2 )
422 if not devicesResults:
423 devices = main.topo.getAllDevices( main )
424 ports = main.topo.getAllPorts( main )
425 devicesResults = main.TRUE
426 deviceFails = [] # Reset for each attempt
427 if not linksResults:
428 links = main.topo.getAllLinks( main )
429 linksResults = main.TRUE
430 linkFails = [] # Reset for each attempt
431 if not hostsResults:
432 hosts = main.topo.getAllHosts( main )
433 hostsResults = main.TRUE
434 hostFails = [] # Reset for each attempt
435
436 # Check for matching topology on each node
437 for controller in range( main.numCtrls ):
438 controllerStr = str( controller + 1 ) # ONOS node number
439 # Compare Devices
440 if devices[ controller ] and ports[ controller ] and\
Jon Halle02505a2017-05-24 16:36:43 -0700441 "Error" not in devices[ controller ] and\
442 "Error" not in ports[ controller ]:
acsmars51a7fe02015-10-29 18:33:32 -0700443
444 try:
445 deviceData = json.loads( devices[ controller ] )
446 portData = json.loads( ports[ controller ] )
Jon Halle02505a2017-05-24 16:36:43 -0700447 except ( TypeError, ValueError ):
448 main.log.error( "Could not load json:" + str( devices[ controller ] ) + ' or ' + str( ports[ controller ] ) )
acsmars51a7fe02015-10-29 18:33:32 -0700449 currentDevicesResult = main.FALSE
450 else:
451 if mnSwitches == len( deviceData ):
452 currentDevicesResult = main.TRUE
453 else:
454 currentDevicesResult = main.FALSE
Jeremye4bc7132016-03-30 14:04:01 -0700455 main.log.error( "Node {} only sees {} device(s) but {} exist".format(
Jon Halle02505a2017-05-24 16:36:43 -0700456 controllerStr, len( deviceData ), mnSwitches ) )
acsmars51a7fe02015-10-29 18:33:32 -0700457 else:
458 currentDevicesResult = main.FALSE
459 if not currentDevicesResult:
460 deviceFails.append( controllerStr )
461 devicesResults = devicesResults and currentDevicesResult
462 # Compare Links
463 if links[ controller ] and "Error" not in links[ controller ]:
464 try:
465 linkData = json.loads( links[ controller ] )
Jon Halle02505a2017-05-24 16:36:43 -0700466 except ( TypeError, ValueError ):
467 main.log.error( "Could not load json:" + str( links[ controller ] ) )
acsmars51a7fe02015-10-29 18:33:32 -0700468 currentLinksResult = main.FALSE
469 else:
470 if mnLinks == len( linkData ):
471 currentLinksResult = main.TRUE
472 else:
473 currentLinksResult = main.FALSE
Jeremye4bc7132016-03-30 14:04:01 -0700474 main.log.error( "Node {} only sees {} link(s) but {} exist".format(
Jon Halle02505a2017-05-24 16:36:43 -0700475 controllerStr, len( linkData ), mnLinks ) )
acsmars51a7fe02015-10-29 18:33:32 -0700476 else:
477 currentLinksResult = main.FALSE
478 if not currentLinksResult:
479 linkFails.append( controllerStr )
480 linksResults = linksResults and currentLinksResult
481 # Compare Hosts
482 if hosts[ controller ] and "Error" not in hosts[ controller ]:
483 try:
484 hostData = json.loads( hosts[ controller ] )
Jon Halle02505a2017-05-24 16:36:43 -0700485 except ( TypeError, ValueError ):
486 main.log.error( "Could not load json:" + str( hosts[ controller ] ) )
acsmars51a7fe02015-10-29 18:33:32 -0700487 currentHostsResult = main.FALSE
488 else:
489 if mnHosts == len( hostData ):
490 currentHostsResult = main.TRUE
491 else:
492 currentHostsResult = main.FALSE
Jeremye4bc7132016-03-30 14:04:01 -0700493 main.log.error( "Node {} only sees {} host(s) but {} exist".format(
Jon Halle02505a2017-05-24 16:36:43 -0700494 controllerStr, len( hostData ), mnHosts ) )
acsmars51a7fe02015-10-29 18:33:32 -0700495 else:
496 currentHostsResult = main.FALSE
497 if not currentHostsResult:
498 hostFails.append( controllerStr )
499 hostsResults = hostsResults and currentHostsResult
500 # Decrement Attempts Remaining
501 attempts -= 1
502
503 utilities.assert_equals( expect=[],
504 actual=deviceFails,
505 onpass="ONOS correctly discovered all devices",
506 onfail="ONOS incorrectly discovered devices on nodes: " +
507 str( deviceFails ) )
508 utilities.assert_equals( expect=[],
509 actual=linkFails,
510 onpass="ONOS correctly discovered all links",
511 onfail="ONOS incorrectly discovered links on nodes: " +
512 str( linkFails ) )
513 utilities.assert_equals( expect=[],
514 actual=hostFails,
515 onpass="ONOS correctly discovered all hosts",
516 onfail="ONOS incorrectly discovered hosts on nodes: " +
517 str( hostFails ) )
518 if hostsResults and linksResults and devicesResults:
519 topoResults = main.TRUE
520 else:
521 topoResults = main.FALSE
522 utilities.assert_equals( expect=main.TRUE,
523 actual=topoResults,
524 onpass="ONOS correctly discovered the topology",
525 onfail="ONOS incorrectly discovered the topology" )
526
acsmars51a7fe02015-10-29 18:33:32 -0700527 def CASE31( self, main ):
528 import time
529 """
530 Add bidirectional point intents between 2 packet layer( mininet )
531 devices and ping mininet hosts
532 """
533 main.log.report(
534 "This testcase adds bidirectional point intents between 2 " +
535 "packet layer( mininet ) devices and ping mininet hosts" )
536 main.case( "Install point intents between 2 packet layer device and " +
537 "ping the hosts" )
538 main.caseExplanation = "This testcase adds bidirectional point intents between 2 " +\
539 "packet layer( mininet ) devices and ping mininet hosts"
540
541 main.step( "Adding point intents" )
542 checkFlowResult = main.TRUE
543 main.pIntentsId = []
544 pIntent1 = main.CLIs[ 0 ].addPointIntent(
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700545 "of:0000000000000001/1",
546 "of:0000000000000002/1" )
acsmars51a7fe02015-10-29 18:33:32 -0700547 time.sleep( 10 )
548 pIntent2 = main.CLIs[ 0 ].addPointIntent(
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700549 "of:0000000000000002/1",
550 "of:0000000000000001/1" )
acsmars51a7fe02015-10-29 18:33:32 -0700551 main.pIntentsId.append( pIntent1 )
552 main.pIntentsId.append( pIntent2 )
553 time.sleep( 10 )
Jon Halle02505a2017-05-24 16:36:43 -0700554 main.log.info( "Checking intents state" )
acsmars51a7fe02015-10-29 18:33:32 -0700555 checkStateResult = main.CLIs[ 0 ].checkIntentState(
Jon Halle02505a2017-05-24 16:36:43 -0700556 intentsId=main.pIntentsId )
acsmars51a7fe02015-10-29 18:33:32 -0700557 time.sleep( 10 )
Jon Halle02505a2017-05-24 16:36:43 -0700558 main.log.info( "Checking flows state" )
acsmars51a7fe02015-10-29 18:33:32 -0700559 checkFlowResult = main.CLIs[ 0 ].checkFlowsState()
560 # Sleep for 10 seconds to provide time for the intent state to change
561 time.sleep( 10 )
Jon Halle02505a2017-05-24 16:36:43 -0700562 main.log.info( "Checking intents state one more time" )
acsmars51a7fe02015-10-29 18:33:32 -0700563 checkStateResult = main.CLIs[ 0 ].checkIntentState(
Jon Halle02505a2017-05-24 16:36:43 -0700564 intentsId=main.pIntentsId )
Jeremye4bc7132016-03-30 14:04:01 -0700565
acsmars51a7fe02015-10-29 18:33:32 -0700566 if checkStateResult and checkFlowResult:
567 addIntentsResult = main.TRUE
568 else:
569 addIntentsResult = main.FALSE
570 utilities.assert_equals(
571 expect=main.TRUE,
572 actual=addIntentsResult,
573 onpass="Successfully added point intents",
Jon Halle02505a2017-05-24 16:36:43 -0700574 onfail="Failed to add point intents" )
acsmars51a7fe02015-10-29 18:33:32 -0700575
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700576 pingResult = main.FALSE
acsmars51a7fe02015-10-29 18:33:32 -0700577
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700578 if not addIntentsResult:
579 main.log.error( "Intents were not properly installed. Skipping ping." )
580
581 else:
582 main.step( "Ping h1 and h2" )
583 pingResult = main.LincOE.pingHostOptical( src="h1", target="h2" )
acsmars51a7fe02015-10-29 18:33:32 -0700584 utilities.assert_equals(
585 expect=main.TRUE,
586 actual=pingResult,
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700587 onpass="Successfully pinged h1 and h2",
Jon Halle02505a2017-05-24 16:36:43 -0700588 onfail="Failed to ping between h1 and h2" )
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700589
590 main.step( "Remove Point to Point intents" )
591 removeResult = main.FALSE
592 # Check remaining intents
593 try:
594 intentsJson = json.loads( main.CLIs[ 0 ].intents() )
595 main.log.debug( intentsJson )
596 main.CLIs[ 0 ].removeIntent( intentId=pIntent1, purge=True )
597 main.CLIs[ 0 ].removeIntent( intentId=pIntent2, purge=True )
598 for intents in intentsJson:
599 main.CLIs[ 0 ].removeIntent( intentId=intents.get( 'id' ),
600 app='org.onosproject.cli',
601 purge=True )
602 time.sleep( 15 )
603
604 for i in range( main.numCtrls ):
605 if len( json.loads( main.CLIs[ i ].intents() ) ):
606 print json.loads( main.CLIs[ i ].intents() )
607 removeResult = main.FALSE
608 else:
609 removeResult = main.TRUE
610 except ( TypeError, ValueError ):
Jon Halle02505a2017-05-24 16:36:43 -0700611 main.log.error( "Cannot see intents on Node " + str( main.CLIs[ 0 ] ) +
612 ". Removing all intents." )
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700613 main.CLIs[ 0 ].removeAllIntents( purge=True )
Jon Halle02505a2017-05-24 16:36:43 -0700614 main.CLIs[ 0 ].removeAllIntents( purge=True, app='org.onosproject.cli' )
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700615
616 utilities.assert_equals( expect=main.TRUE,
617 actual=removeResult,
618 onpass="Successfully removed host intents",
619 onfail="Failed to remove host intents" )
acsmars51a7fe02015-10-29 18:33:32 -0700620
621 def CASE32( self ):
622 """
623 Add host intents between 2 packet layer host
624 """
625 import time
626 import json
627 main.log.report( "Adding host intents between 2 optical layer host" )
628 main.case( "Test add host intents between optical layer host" )
629 main.caseExplanation = "Test host intents between 2 optical layer host"
630
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700631 main.step( "Creating list of hosts" )
632 hostnum = 0
633 try:
634 hostData = json.loads( hosts[ controller ] )
635 except( TypeError, ValueError ):
Jon Halle02505a2017-05-24 16:36:43 -0700636 main.log.error( "Could not load json:" + str( hosts[ controller ] ) )
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700637
acsmars51a7fe02015-10-29 18:33:32 -0700638 main.step( "Adding host intents to h1 and h2" )
acsmars51a7fe02015-10-29 18:33:32 -0700639 hostId = []
640 # Listing host MAC addresses
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700641 for host in hostData:
Jon Halle02505a2017-05-24 16:36:43 -0700642 hostId.append( host.get( "id" ) )
acsmars51a7fe02015-10-29 18:33:32 -0700643 host1 = hostId[ 0 ]
644 host2 = hostId[ 1 ]
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700645 main.log.debug( host1 )
646 main.log.debug( host2 )
acsmars51a7fe02015-10-29 18:33:32 -0700647
648 intentsId = []
Jon Halle02505a2017-05-24 16:36:43 -0700649 intent1 = main.CLIs[ 0 ].addHostIntent( hostIdOne=host1,
650 hostIdTwo=host2 )
acsmars51a7fe02015-10-29 18:33:32 -0700651 intentsId.append( intent1 )
652 # Checking intents state before pinging
653 main.log.info( "Checking intents state" )
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700654 intentResult = utilities.retry( f=main.CLIs[ 0 ].checkIntentState,
655 retValue=main.FALSE, args=intentsId,
656 sleep=main.checkIntentSleep, attempts=10 )
acsmars51a7fe02015-10-29 18:33:32 -0700657
658 # If intent state is still wrong, display intent states
659 if not intentResult:
660 main.log.error( main.CLIs[ 0 ].intents() )
Jeremye4bc7132016-03-30 14:04:01 -0700661
acsmars51a7fe02015-10-29 18:33:32 -0700662 utilities.assert_equals( expect=main.TRUE,
663 actual=intentResult,
664 onpass="All intents are in INSTALLED state ",
665 onfail="Some of the intents are not in " +
666 "INSTALLED state " )
667
668 if not intentResult:
669 main.log.error( "Intents were not properly installed. Skipping Ping" )
670 else:
671 # Pinging h1 to h2 and then ping h2 to h1
672 main.step( "Pinging h1 and h2" )
673 pingResult = main.TRUE
674 pingResult = main.LincOE.pingHostOptical( src="h1", target="h2" ) \
Jon Halle02505a2017-05-24 16:36:43 -0700675 and main.LincOE.pingHostOptical( src="h2", target="h1" )
Jeremye4bc7132016-03-30 14:04:01 -0700676
acsmars51a7fe02015-10-29 18:33:32 -0700677 utilities.assert_equals( expect=main.TRUE,
678 actual=pingResult,
679 onpass="Pinged successfully between h1 and h2",
680 onfail="Pinged failed between h1 and h2" )
681
682 # Removed all added host intents
683 main.step( "Removing host intents" )
684 removeResult = main.TRUE
685 # Check remaining intents
Jeremy7134f5b2016-04-05 13:50:21 -0700686 try:
687 intentsJson = json.loads( main.CLIs[ 0 ].intents() )
688 main.CLIs[ 0 ].removeIntent( intentId=intent1, purge=True )
689 #main.CLIs[ 0 ].removeIntent( intentId=intent2, purge=True )
Jon Halle02505a2017-05-24 16:36:43 -0700690 main.log.debug( intentsJson )
Jeremy7134f5b2016-04-05 13:50:21 -0700691 for intents in intentsJson:
Jeremye4bc7132016-03-30 14:04:01 -0700692 main.CLIs[ 0 ].removeIntent( intentId=intents.get( 'id' ),
693 app='org.onosproject.optical',
694 purge=True )
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700695 time.sleep( 15 )
acsmars51a7fe02015-10-29 18:33:32 -0700696
Jeremy7134f5b2016-04-05 13:50:21 -0700697 for i in range( main.numCtrls ):
698 if len( json.loads( main.CLIs[ i ].intents() ) ):
699 print json.loads( main.CLIs[ i ].intents() )
700 removeResult = main.FALSE
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700701 else:
702 removeResult = main.TRUE
Jeremy7134f5b2016-04-05 13:50:21 -0700703 except ( TypeError, ValueError ):
Jon Halle02505a2017-05-24 16:36:43 -0700704 main.log.error( "Cannot see intents on Node " + str( main.CLIs[ 0 ] ) +
705 ". Removing all intents." )
Jeremy7134f5b2016-04-05 13:50:21 -0700706 main.CLIs[ 0 ].removeAllIntents( purge=True )
Jon Halle02505a2017-05-24 16:36:43 -0700707 main.CLIs[ 0 ].removeAllIntents( purge=True, app='org.onosproject.optical' )
Jeremy7134f5b2016-04-05 13:50:21 -0700708
709 utilities.assert_equals( expect=main.TRUE,
710 actual=removeResult,
711 onpass="Successfully removed host intents",
Chiyu Chengef109502016-11-21 15:51:38 -0800712 onfail="Failed to remove host intents" )