blob: c7ae4639b9ab98e9565c220a332327250f391598 [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
acsmars51a7fe02015-10-29 18:33:32 -070086 main.ONOSbench.getVersion( report=True )
87
88 def CASE2( self, main ):
89 """
90 - Set up cell
91 - Create cell file
92 - Set cell file
93 - Verify cell file
94 - Kill ONOS process
95 - Uninstall ONOS cluster
96 - Verify ONOS start up
97 - Install ONOS cluster
98 - Connect to cli
99 """
Jeremy Songster17147f22016-05-31 18:30:52 -0700100 main.cycle += 1
101
acsmars51a7fe02015-10-29 18:33:32 -0700102 # main.scale[ 0 ] determines the current number of ONOS controller
103 main.numCtrls = int( main.scale[ 0 ] )
Jeremye4bc7132016-03-30 14:04:01 -0700104 main.flowCompiler = "Flow Rules"
acsmars51a7fe02015-10-29 18:33:32 -0700105
106 main.case( "Starting up " + str( main.numCtrls ) +
107 " node(s) ONOS cluster" )
108 main.caseExplanation = "Set up ONOS with " + str( main.numCtrls ) +\
109 " node(s) ONOS cluster"
110
acsmars51a7fe02015-10-29 18:33:32 -0700111 #kill off all onos processes
112 main.log.info( "Safety check, killing all ONOS processes" +
Jon Hall70b2ff42015-11-17 15:49:44 -0800113 " before initiating environment setup" )
acsmars51a7fe02015-10-29 18:33:32 -0700114
115 for i in range( main.maxNodes ):
116 main.ONOSbench.onosDie( main.ONOSip[ i ] )
117
118 print "NODE COUNT = ", main.numCtrls
119
120 tempOnosIp = []
121 for i in range( main.numCtrls ):
Jon Halle02505a2017-05-24 16:36:43 -0700122 tempOnosIp.append( main.ONOSip[ i ] )
acsmars51a7fe02015-10-29 18:33:32 -0700123
124 main.ONOSbench.createCellFile( main.ONOSbench.ip_address,
125 "temp", main.Mininet1.ip_address,
Devin Limdc78e202017-06-09 18:30:07 -0700126 main.apps, tempOnosIp, main.ONOScli1.karafUser )
acsmars51a7fe02015-10-29 18:33:32 -0700127
128 main.step( "Apply cell to environment" )
129 cellResult = main.ONOSbench.setCell( "temp" )
130 verifyResult = main.ONOSbench.verifyCell()
131 stepResult = cellResult and verifyResult
132 utilities.assert_equals( expect=main.TRUE,
133 actual=stepResult,
Jon Halle02505a2017-05-24 16:36:43 -0700134 onpass="Successfully applied cell to " +
acsmars51a7fe02015-10-29 18:33:32 -0700135 "environment",
136 onfail="Failed to apply cell to environment " )
137
138 main.step( "Creating ONOS package" )
Jon Hallbd60ea02016-08-23 10:03:59 -0700139 packageResult = main.ONOSbench.buckBuild()
acsmars51a7fe02015-10-29 18:33:32 -0700140 stepResult = packageResult
141 utilities.assert_equals( expect=main.TRUE,
142 actual=stepResult,
143 onpass="Successfully created ONOS package",
144 onfail="Failed to create ONOS package" )
145
146 time.sleep( main.startUpSleep )
147 main.step( "Uninstalling ONOS package" )
148 onosUninstallResult = main.TRUE
149 for ip in main.ONOSip:
150 onosUninstallResult = onosUninstallResult and \
151 main.ONOSbench.onosUninstall( nodeIp=ip )
152 stepResult = onosUninstallResult
153 utilities.assert_equals( expect=main.TRUE,
154 actual=stepResult,
155 onpass="Successfully uninstalled ONOS package",
156 onfail="Failed to uninstall ONOS package" )
157
158 time.sleep( main.startUpSleep )
159 main.step( "Installing ONOS package" )
160 onosInstallResult = main.TRUE
Devin Lim752dd7b2017-06-27 14:40:03 -0700161 del main.activeONOSip[:]
acsmars51a7fe02015-10-29 18:33:32 -0700162 for i in range( main.numCtrls ):
163 onosInstallResult = onosInstallResult and \
164 main.ONOSbench.onosInstall( node=main.ONOSip[ i ] )
165 # Populate activeONOSip
166 main.activeONOSip.append( main.ONOSip[ i ] )
167 stepResult = onosInstallResult
168 utilities.assert_equals( expect=main.TRUE,
169 actual=stepResult,
170 onpass="Successfully installed ONOS package",
171 onfail="Failed to install ONOS package" )
172
You Wangf5de25b2017-01-06 15:13:01 -0800173 main.step( "Set up ONOS secure SSH" )
174 secureSshResult = main.TRUE
175 for i in range( int( main.numCtrls ) ):
Jon Halle02505a2017-05-24 16:36:43 -0700176 secureSshResult = secureSshResult and main.ONOSbench.onosSecureSSH( node=main.ONOSip[ i ] )
You Wangf5de25b2017-01-06 15:13:01 -0800177 utilities.assert_equals( expect=main.TRUE, actual=secureSshResult,
178 onpass="Test step PASS",
179 onfail="Test step FAIL" )
180
acsmars51a7fe02015-10-29 18:33:32 -0700181 time.sleep( main.startUpSleep )
182 main.step( "Starting ONOS service" )
183 stopResult = main.TRUE
184 startResult = main.TRUE
185 onosIsUp = main.TRUE
186
187 for i in range( main.numCtrls ):
Jeremy Songster7edb6632016-04-28 15:44:28 -0700188 isUp = main.ONOSbench.isup( main.ONOSip[ i ] )
189 onosIsUp = onosIsUp and isUp
190 if isUp == main.TRUE:
191 main.log.report( "ONOS instance {0} is up and ready".format( i + 1 ) )
192 else:
193 main.log.report( "ONOS instance {0} may not be up, stop and ".format( i + 1 ) +
194 "start ONOS again " )
195 stopResult = stopResult and main.ONOSbench.onosStop( main.ONOSip[ i ] )
196 startResult = startResult and main.ONOSbench.onosStart( main.ONOSip[ i ] )
197 if not startResult or stopResult:
Jon Halle02505a2017-05-24 16:36:43 -0700198 main.log.report( "ONOS instance {0} did not start correctly.".format( i + 1 ) )
acsmars51a7fe02015-10-29 18:33:32 -0700199 stepResult = onosIsUp and stopResult and startResult
200 utilities.assert_equals( expect=main.TRUE,
201 actual=stepResult,
Jeremy Songster7edb6632016-04-28 15:44:28 -0700202 onpass="ONOS service is ready on all nodes",
203 onfail="ONOS service did not start properly on all nodes" )
acsmars51a7fe02015-10-29 18:33:32 -0700204
205 main.step( "Start ONOS cli" )
206 cliResult = main.TRUE
207 for i in range( main.numCtrls ):
208 cliResult = cliResult and \
209 main.CLIs[ i ].startOnosCli( main.ONOSip[ i ] )
210 stepResult = cliResult
211 utilities.assert_equals( expect=main.TRUE,
212 actual=stepResult,
213 onpass="Successfully start ONOS cli",
214 onfail="Failed to start ONOS cli" )
215
216 # Remove the first element in main.scale list
217 main.scale.remove( main.scale[ 0 ] )
218
acsmars51a7fe02015-10-29 18:33:32 -0700219 def CASE10( self, main ):
220 """
221 Start Mininet opticalTest Topology
222 """
Jon Halle02505a2017-05-24 16:36:43 -0700223 main.case( "Mininet with Linc-OE startup" )
Devin Lim752dd7b2017-06-27 14:40:03 -0700224 main.step( "Push TopoDDriver.json to ONOS through onos-netcfg" )
225 topoResult = main.ONOSbench.onosNetCfg( controllerIps=main.activeONOSip, path=main.dependencyPath,
226 fileName="TopoDDriver" )
227 #Exit if topology did not load properly
228 if not topoResult:
229 main.cleanup()
230 main.exit()
231
acsmars51a7fe02015-10-29 18:33:32 -0700232 main.caseExplanation = "Start opticalTest.py topology included with ONOS"
233 main.step( "Starting mininet and LINC-OE" )
acsmars51a7fe02015-10-29 18:33:32 -0700234 time.sleep( 10 )
Devin Lim752dd7b2017-06-27 14:40:03 -0700235 controllerIPs = ','.join( main.activeONOSip )
236 cIps = ""
237 for i in range(0,4):
238 cIps += controllerIPs + ' '
239 opticalMnScript = main.LincOE.runOpticalMnScript( ctrllerIP=cIps, topology=main.opticalTopo )
acsmars51a7fe02015-10-29 18:33:32 -0700240 topoResult = opticalMnScript
241 utilities.assert_equals(
242 expect=main.TRUE,
243 actual=topoResult,
244 onpass="Started the topology successfully ",
Jon Halle02505a2017-05-24 16:36:43 -0700245 onfail="Failed to start the topology" )
acsmars51a7fe02015-10-29 18:33:32 -0700246
acsmars51a7fe02015-10-29 18:33:32 -0700247 def CASE14( self, main ):
248 """
249 Stop mininet
250 """
251 main.log.report( "Stop Mininet topology" )
252 main.case( "Stop Mininet topology" )
253 main.caseExplanation = "Stopping the current mininet topology " +\
254 "to start up fresh"
255
256 main.step( "Stopping Mininet Topology" )
257 topoResult = main.LincOE.stopNet( timeout=180 )
258 utilities.assert_equals( expect=main.TRUE,
259 actual=topoResult,
260 onpass="Successfully stopped mininet",
261 onfail="Failed to stopped mininet" )
262 # Exit if topology did not load properly
263 if not topoResult:
264 main.cleanup()
265 main.exit()
266
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700267 def CASE16( self, main ):
268 """
269 Balance Masters
270 """
271 main.case( "Balance mastership of switches" )
272 main.step( "Balancing mastership of switches" )
273
274 balanceResult = main.FALSE
275 balanceResult = utilities.retry( f=main.CLIs[ 0 ].balanceMasters, retValue=main.FALSE, args=[] )
276
277 utilities.assert_equals( expect=main.TRUE,
278 actual=balanceResult,
279 onpass="Successfully balanced mastership of switches",
280 onfail="Failed to balance mastership of switches" )
281 if not balanceResult:
282 main.initialized = main.FALSE
283
Jeremye4bc7132016-03-30 14:04:01 -0700284 def CASE17( self, main ):
285 """
286 Use Flow Objectives
287 """
288 main.case( "Enable intent compilation using Flow Objectives" )
289 main.step( "Enabling Flow Objectives" )
290
291 main.flowCompiler = "Flow Objectives"
292
293 cmd = "org.onosproject.net.intent.impl.compiler.IntentConfigurableRegistrator"
294
295 stepResult = main.CLIs[ 0 ].setCfg( component=cmd,
296 propName="useFlowObjectives", value="true" )
You Wang106d0fa2017-05-15 17:22:15 -0700297 stepResult &= main.CLIs[ 0 ].setCfg( component=cmd,
298 propName="defaultFlowObjectiveCompiler",
Jon Halle02505a2017-05-24 16:36:43 -0700299 value='org.onosproject.net.intent.impl.compiler.LinkCollectionIntentObjectiveCompiler' )
Jeremye4bc7132016-03-30 14:04:01 -0700300
301 utilities.assert_equals( expect=main.TRUE,
302 actual=stepResult,
303 onpass="Successfully activated Flow Objectives",
304 onfail="Failed to activate Flow Objectives" )
305
Jeremy Songster17147f22016-05-31 18:30:52 -0700306 def CASE19( self, main ):
307 """
308 Copy the karaf.log files after each testcase cycle
309 """
310 main.log.report( "Copy karaf logs" )
311 main.case( "Copy karaf logs" )
312 main.caseExplanation = "Copying the karaf logs to preserve them through" +\
313 "reinstalling ONOS"
314 main.step( "Copying karaf logs" )
Jeremy Songster31aad312016-06-13 16:32:11 -0700315 stepResult = main.TRUE
316 scpResult = main.TRUE
317 copyResult = main.TRUE
Jeremy Songstercc5414b2016-07-11 10:59:53 -0700318 for i in range( main.numCtrls ):
319 main.node = main.CLIs[ i ]
Jeremy Songster17147f22016-05-31 18:30:52 -0700320 ip = main.ONOSip[ i ]
321 main.node.ip_address = ip
Jon Halle02505a2017-05-24 16:36:43 -0700322 scpResult = scpResult and main.ONOSbench.scp( main.node,
323 "/opt/onos/log/karaf.log",
324 "/tmp/karaf.log",
325 direction="from" )
Jeremy Songster31aad312016-06-13 16:32:11 -0700326 copyResult = copyResult and main.ONOSbench.cpLogsToDir( "/tmp/karaf.log", main.logdir,
327 copyFileName=( "karaf.log.node{0}.cycle{1}".format( str( i + 1 ), str( main.cycle ) ) ) )
328 if scpResult and copyResult:
Jon Halle02505a2017-05-24 16:36:43 -0700329 stepResult = main.TRUE and stepResult
Jeremy Songster31aad312016-06-13 16:32:11 -0700330 else:
331 stepResult = main.FALSE and stepResult
Jeremy Songster31aad312016-06-13 16:32:11 -0700332 utilities.assert_equals( expect=main.TRUE,
333 actual=stepResult,
334 onpass="Successfully copied remote ONOS logs",
335 onfail="Failed to copy remote ONOS logs" )
Jeremy Songster17147f22016-05-31 18:30:52 -0700336
Jon Halle02505a2017-05-24 16:36:43 -0700337 def CASE21( self, main ):
acsmars51a7fe02015-10-29 18:33:32 -0700338 """
339 Run pingall to discover all hosts
340 """
341 main.case( "Running Pingall" )
342 main.caseExplanation = "Use pingall to discover all hosts. Pingall is expected to fail."
343 main.step( "Discover Hosts through Pingall" )
Jon Halle02505a2017-05-24 16:36:43 -0700344 pingResult = main.LincOE.pingall( timeout=120 )
acsmars51a7fe02015-10-29 18:33:32 -0700345
346 utilities.assert_equals( expect=main.FALSE,
347 actual=pingResult,
348 onpass="Pingall Completed",
349 onfail="Pingall did not complete or did not return fales" )
350
Jon Halle02505a2017-05-24 16:36:43 -0700351 def CASE22( self, main ):
acsmars51a7fe02015-10-29 18:33:32 -0700352 """
353 Send arpings to discover all hosts
354 """
355 main.case( "Discover Hosts with arping" )
356 main.caseExplanation = "Send arpings between all the hosts to discover and verify them"
357
358 main.step( "Send arping between all hosts" )
359
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700360 hosts = []
361 for i in range( main.hosts ):
362 hosts.append( 'h{}'.format( i + 1 ) )
acsmars51a7fe02015-10-29 18:33:32 -0700363
364 arpingHostResults = main.TRUE
365 for host in hosts:
Devin Lim752dd7b2017-06-27 14:40:03 -0700366 if main.LincOE.arping( host, ethDevice=host+"-eth0" ):
acsmars51a7fe02015-10-29 18:33:32 -0700367 main.log.info( "Successfully reached host {} with arping".format( host ) )
368 else:
369 main.log.error( "Could not reach host {} with arping".format( host ) )
370 arpingHostResults = main.FALSE
371
372 utilities.assert_equals( expect=main.TRUE,
373 actual=arpingHostResults,
374 onpass="Successfully discovered all hosts",
375 onfail="Could not descover some hosts" )
376
377 def CASE23( self, main ):
378 """
379 Compare ONOS Topology to Mininet Topology
380 """
381 import json
382
383 main.case( "Compare ONOS Topology view to Mininet topology" )
384 main.caseExplanation = "Compare topology elements between Mininet" +\
385 " and ONOS"
386
387 main.log.info( "Gathering topology information from Mininet" )
388 devicesResults = main.FALSE # Overall Boolean for device correctness
389 linksResults = main.FALSE # Overall Boolean for link correctness
390 hostsResults = main.FALSE # Overall Boolean for host correctness
391 deviceFails = [] # Nodes where devices are incorrect
392 linkFails = [] # Nodes where links are incorrect
393 hostFails = [] # Nodes where hosts are incorrect
394 attempts = main.checkTopoAttempts # Remaining Attempts
395
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700396 mnSwitches = main.switches
397 mnLinks = main.links
398 mnHosts = main.hosts
acsmars51a7fe02015-10-29 18:33:32 -0700399
Jon Hall70b2ff42015-11-17 15:49:44 -0800400 main.step( "Comparing Mininet topology to ONOS topology" )
acsmars51a7fe02015-10-29 18:33:32 -0700401
402 while ( attempts >= 0 ) and\
Jon Halle02505a2017-05-24 16:36:43 -0700403 ( not devicesResults or not linksResults or not hostsResults ):
acsmars51a7fe02015-10-29 18:33:32 -0700404 time.sleep( 2 )
405 if not devicesResults:
406 devices = main.topo.getAllDevices( main )
407 ports = main.topo.getAllPorts( main )
408 devicesResults = main.TRUE
409 deviceFails = [] # Reset for each attempt
410 if not linksResults:
411 links = main.topo.getAllLinks( main )
412 linksResults = main.TRUE
413 linkFails = [] # Reset for each attempt
414 if not hostsResults:
415 hosts = main.topo.getAllHosts( main )
416 hostsResults = main.TRUE
417 hostFails = [] # Reset for each attempt
418
419 # Check for matching topology on each node
420 for controller in range( main.numCtrls ):
421 controllerStr = str( controller + 1 ) # ONOS node number
422 # Compare Devices
423 if devices[ controller ] and ports[ controller ] and\
Jon Halle02505a2017-05-24 16:36:43 -0700424 "Error" not in devices[ controller ] and\
425 "Error" not in ports[ controller ]:
acsmars51a7fe02015-10-29 18:33:32 -0700426
427 try:
428 deviceData = json.loads( devices[ controller ] )
429 portData = json.loads( ports[ controller ] )
Jon Halle02505a2017-05-24 16:36:43 -0700430 except ( TypeError, ValueError ):
431 main.log.error( "Could not load json:" + str( devices[ controller ] ) + ' or ' + str( ports[ controller ] ) )
acsmars51a7fe02015-10-29 18:33:32 -0700432 currentDevicesResult = main.FALSE
433 else:
434 if mnSwitches == len( deviceData ):
435 currentDevicesResult = main.TRUE
436 else:
437 currentDevicesResult = main.FALSE
Jeremye4bc7132016-03-30 14:04:01 -0700438 main.log.error( "Node {} only sees {} device(s) but {} exist".format(
Jon Halle02505a2017-05-24 16:36:43 -0700439 controllerStr, len( deviceData ), mnSwitches ) )
acsmars51a7fe02015-10-29 18:33:32 -0700440 else:
441 currentDevicesResult = main.FALSE
442 if not currentDevicesResult:
443 deviceFails.append( controllerStr )
444 devicesResults = devicesResults and currentDevicesResult
445 # Compare Links
446 if links[ controller ] and "Error" not in links[ controller ]:
447 try:
448 linkData = json.loads( links[ controller ] )
Jon Halle02505a2017-05-24 16:36:43 -0700449 except ( TypeError, ValueError ):
450 main.log.error( "Could not load json:" + str( links[ controller ] ) )
acsmars51a7fe02015-10-29 18:33:32 -0700451 currentLinksResult = main.FALSE
452 else:
453 if mnLinks == len( linkData ):
454 currentLinksResult = main.TRUE
455 else:
456 currentLinksResult = main.FALSE
Jeremye4bc7132016-03-30 14:04:01 -0700457 main.log.error( "Node {} only sees {} link(s) but {} exist".format(
Jon Halle02505a2017-05-24 16:36:43 -0700458 controllerStr, len( linkData ), mnLinks ) )
acsmars51a7fe02015-10-29 18:33:32 -0700459 else:
460 currentLinksResult = main.FALSE
461 if not currentLinksResult:
462 linkFails.append( controllerStr )
463 linksResults = linksResults and currentLinksResult
464 # Compare Hosts
465 if hosts[ controller ] and "Error" not in hosts[ controller ]:
466 try:
467 hostData = json.loads( hosts[ controller ] )
Jon Halle02505a2017-05-24 16:36:43 -0700468 except ( TypeError, ValueError ):
469 main.log.error( "Could not load json:" + str( hosts[ controller ] ) )
acsmars51a7fe02015-10-29 18:33:32 -0700470 currentHostsResult = main.FALSE
471 else:
472 if mnHosts == len( hostData ):
473 currentHostsResult = main.TRUE
474 else:
475 currentHostsResult = main.FALSE
Jeremye4bc7132016-03-30 14:04:01 -0700476 main.log.error( "Node {} only sees {} host(s) but {} exist".format(
Jon Halle02505a2017-05-24 16:36:43 -0700477 controllerStr, len( hostData ), mnHosts ) )
acsmars51a7fe02015-10-29 18:33:32 -0700478 else:
479 currentHostsResult = main.FALSE
480 if not currentHostsResult:
481 hostFails.append( controllerStr )
482 hostsResults = hostsResults and currentHostsResult
483 # Decrement Attempts Remaining
484 attempts -= 1
485
486 utilities.assert_equals( expect=[],
487 actual=deviceFails,
488 onpass="ONOS correctly discovered all devices",
489 onfail="ONOS incorrectly discovered devices on nodes: " +
490 str( deviceFails ) )
491 utilities.assert_equals( expect=[],
492 actual=linkFails,
493 onpass="ONOS correctly discovered all links",
494 onfail="ONOS incorrectly discovered links on nodes: " +
495 str( linkFails ) )
496 utilities.assert_equals( expect=[],
497 actual=hostFails,
498 onpass="ONOS correctly discovered all hosts",
499 onfail="ONOS incorrectly discovered hosts on nodes: " +
500 str( hostFails ) )
501 if hostsResults and linksResults and devicesResults:
502 topoResults = main.TRUE
503 else:
504 topoResults = main.FALSE
505 utilities.assert_equals( expect=main.TRUE,
506 actual=topoResults,
507 onpass="ONOS correctly discovered the topology",
508 onfail="ONOS incorrectly discovered the topology" )
509
acsmars51a7fe02015-10-29 18:33:32 -0700510 def CASE31( self, main ):
511 import time
512 """
513 Add bidirectional point intents between 2 packet layer( mininet )
514 devices and ping mininet hosts
515 """
516 main.log.report(
517 "This testcase adds bidirectional point intents between 2 " +
518 "packet layer( mininet ) devices and ping mininet hosts" )
519 main.case( "Install point intents between 2 packet layer device and " +
520 "ping the hosts" )
521 main.caseExplanation = "This testcase adds bidirectional point intents between 2 " +\
522 "packet layer( mininet ) devices and ping mininet hosts"
523
524 main.step( "Adding point intents" )
525 checkFlowResult = main.TRUE
526 main.pIntentsId = []
527 pIntent1 = main.CLIs[ 0 ].addPointIntent(
Devin Lim752dd7b2017-06-27 14:40:03 -0700528 "of:0000000000000015/1",
529 "of:000000000000000b/2" )
acsmars51a7fe02015-10-29 18:33:32 -0700530 time.sleep( 10 )
531 pIntent2 = main.CLIs[ 0 ].addPointIntent(
Devin Lim752dd7b2017-06-27 14:40:03 -0700532 "of:000000000000000b/2",
533 "of:0000000000000015/1" )
acsmars51a7fe02015-10-29 18:33:32 -0700534 main.pIntentsId.append( pIntent1 )
535 main.pIntentsId.append( pIntent2 )
536 time.sleep( 10 )
Jon Halle02505a2017-05-24 16:36:43 -0700537 main.log.info( "Checking intents state" )
acsmars51a7fe02015-10-29 18:33:32 -0700538 checkStateResult = main.CLIs[ 0 ].checkIntentState(
Jon Halle02505a2017-05-24 16:36:43 -0700539 intentsId=main.pIntentsId )
acsmars51a7fe02015-10-29 18:33:32 -0700540 time.sleep( 10 )
Devin Lim752dd7b2017-06-27 14:40:03 -0700541 checkStateResult = utilities.retry( f=main.CLIs[0].checkIntentState,
542 retValue=main.FALSE, args=( main.pIntentsId, "INSTALLED" ),
543 sleep=main.checkIntentSleep, attempts=10 )
Jon Halle02505a2017-05-24 16:36:43 -0700544 main.log.info( "Checking flows state" )
acsmars51a7fe02015-10-29 18:33:32 -0700545 checkFlowResult = main.CLIs[ 0 ].checkFlowsState()
546 # Sleep for 10 seconds to provide time for the intent state to change
547 time.sleep( 10 )
Jon Halle02505a2017-05-24 16:36:43 -0700548 main.log.info( "Checking intents state one more time" )
acsmars51a7fe02015-10-29 18:33:32 -0700549 checkStateResult = main.CLIs[ 0 ].checkIntentState(
Jon Halle02505a2017-05-24 16:36:43 -0700550 intentsId=main.pIntentsId )
Jeremye4bc7132016-03-30 14:04:01 -0700551
acsmars51a7fe02015-10-29 18:33:32 -0700552 if checkStateResult and checkFlowResult:
553 addIntentsResult = main.TRUE
554 else:
555 addIntentsResult = main.FALSE
556 utilities.assert_equals(
557 expect=main.TRUE,
558 actual=addIntentsResult,
559 onpass="Successfully added point intents",
Jon Halle02505a2017-05-24 16:36:43 -0700560 onfail="Failed to add point intents" )
acsmars51a7fe02015-10-29 18:33:32 -0700561
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700562 pingResult = main.FALSE
acsmars51a7fe02015-10-29 18:33:32 -0700563
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700564 if not addIntentsResult:
565 main.log.error( "Intents were not properly installed. Skipping ping." )
566
567 else:
568 main.step( "Ping h1 and h2" )
569 pingResult = main.LincOE.pingHostOptical( src="h1", target="h2" )
acsmars51a7fe02015-10-29 18:33:32 -0700570 utilities.assert_equals(
571 expect=main.TRUE,
572 actual=pingResult,
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700573 onpass="Successfully pinged h1 and h2",
Jon Halle02505a2017-05-24 16:36:43 -0700574 onfail="Failed to ping between h1 and h2" )
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700575
576 main.step( "Remove Point to Point intents" )
Devin Lim752dd7b2017-06-27 14:40:03 -0700577 removeResult = main.TRUE
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700578 # Check remaining intents
579 try:
580 intentsJson = json.loads( main.CLIs[ 0 ].intents() )
581 main.log.debug( intentsJson )
582 main.CLIs[ 0 ].removeIntent( intentId=pIntent1, purge=True )
583 main.CLIs[ 0 ].removeIntent( intentId=pIntent2, purge=True )
584 for intents in intentsJson:
585 main.CLIs[ 0 ].removeIntent( intentId=intents.get( 'id' ),
586 app='org.onosproject.cli',
587 purge=True )
588 time.sleep( 15 )
589
590 for i in range( main.numCtrls ):
Devin Lim752dd7b2017-06-27 14:40:03 -0700591 if not any ( intent.get('state') == 'WITHDRAWING' for intent
592 in json.loads( main.CLIs[i].intents() ) ):
593 main.log.debug( json.loads( main.CLIs[i].intents ) )
594 removeResult = main.FALSE
595 break
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700596 else:
597 removeResult = main.TRUE
598 except ( TypeError, ValueError ):
Jon Halle02505a2017-05-24 16:36:43 -0700599 main.log.error( "Cannot see intents on Node " + str( main.CLIs[ 0 ] ) +
600 ". Removing all intents." )
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700601 main.CLIs[ 0 ].removeAllIntents( purge=True )
Jon Halle02505a2017-05-24 16:36:43 -0700602 main.CLIs[ 0 ].removeAllIntents( purge=True, app='org.onosproject.cli' )
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700603
604 utilities.assert_equals( expect=main.TRUE,
605 actual=removeResult,
606 onpass="Successfully removed host intents",
607 onfail="Failed to remove host intents" )
acsmars51a7fe02015-10-29 18:33:32 -0700608
609 def CASE32( self ):
610 """
611 Add host intents between 2 packet layer host
612 """
613 import time
614 import json
615 main.log.report( "Adding host intents between 2 optical layer host" )
616 main.case( "Test add host intents between optical layer host" )
617 main.caseExplanation = "Test host intents between 2 optical layer host"
618
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700619 main.step( "Creating list of hosts" )
620 hostnum = 0
621 try:
622 hostData = json.loads( hosts[ controller ] )
623 except( TypeError, ValueError ):
Jon Halle02505a2017-05-24 16:36:43 -0700624 main.log.error( "Could not load json:" + str( hosts[ controller ] ) )
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700625
acsmars51a7fe02015-10-29 18:33:32 -0700626 main.step( "Adding host intents to h1 and h2" )
acsmars51a7fe02015-10-29 18:33:32 -0700627 hostId = []
628 # Listing host MAC addresses
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700629 for host in hostData:
Jon Halle02505a2017-05-24 16:36:43 -0700630 hostId.append( host.get( "id" ) )
acsmars51a7fe02015-10-29 18:33:32 -0700631 host1 = hostId[ 0 ]
632 host2 = hostId[ 1 ]
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700633 main.log.debug( host1 )
634 main.log.debug( host2 )
acsmars51a7fe02015-10-29 18:33:32 -0700635
636 intentsId = []
Jon Halle02505a2017-05-24 16:36:43 -0700637 intent1 = main.CLIs[ 0 ].addHostIntent( hostIdOne=host1,
638 hostIdTwo=host2 )
acsmars51a7fe02015-10-29 18:33:32 -0700639 intentsId.append( intent1 )
640 # Checking intents state before pinging
641 main.log.info( "Checking intents state" )
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700642 intentResult = utilities.retry( f=main.CLIs[ 0 ].checkIntentState,
643 retValue=main.FALSE, args=intentsId,
644 sleep=main.checkIntentSleep, attempts=10 )
acsmars51a7fe02015-10-29 18:33:32 -0700645
646 # If intent state is still wrong, display intent states
647 if not intentResult:
648 main.log.error( main.CLIs[ 0 ].intents() )
Jeremye4bc7132016-03-30 14:04:01 -0700649
acsmars51a7fe02015-10-29 18:33:32 -0700650 utilities.assert_equals( expect=main.TRUE,
651 actual=intentResult,
652 onpass="All intents are in INSTALLED state ",
653 onfail="Some of the intents are not in " +
654 "INSTALLED state " )
655
656 if not intentResult:
657 main.log.error( "Intents were not properly installed. Skipping Ping" )
658 else:
659 # Pinging h1 to h2 and then ping h2 to h1
660 main.step( "Pinging h1 and h2" )
661 pingResult = main.TRUE
662 pingResult = main.LincOE.pingHostOptical( src="h1", target="h2" ) \
Jon Halle02505a2017-05-24 16:36:43 -0700663 and main.LincOE.pingHostOptical( src="h2", target="h1" )
Jeremye4bc7132016-03-30 14:04:01 -0700664
acsmars51a7fe02015-10-29 18:33:32 -0700665 utilities.assert_equals( expect=main.TRUE,
666 actual=pingResult,
667 onpass="Pinged successfully between h1 and h2",
668 onfail="Pinged failed between h1 and h2" )
669
670 # Removed all added host intents
671 main.step( "Removing host intents" )
672 removeResult = main.TRUE
673 # Check remaining intents
Jeremy7134f5b2016-04-05 13:50:21 -0700674 try:
675 intentsJson = json.loads( main.CLIs[ 0 ].intents() )
676 main.CLIs[ 0 ].removeIntent( intentId=intent1, purge=True )
677 #main.CLIs[ 0 ].removeIntent( intentId=intent2, purge=True )
Jon Halle02505a2017-05-24 16:36:43 -0700678 main.log.debug( intentsJson )
Jeremy7134f5b2016-04-05 13:50:21 -0700679 for intents in intentsJson:
Jeremye4bc7132016-03-30 14:04:01 -0700680 main.CLIs[ 0 ].removeIntent( intentId=intents.get( 'id' ),
681 app='org.onosproject.optical',
682 purge=True )
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700683 time.sleep( 15 )
acsmars51a7fe02015-10-29 18:33:32 -0700684
Jeremy7134f5b2016-04-05 13:50:21 -0700685 for i in range( main.numCtrls ):
Devin Lim752dd7b2017-06-27 14:40:03 -0700686 if not any ( intent.get('state') == 'WITHDRAWING' for intent
687 in json.loads( main.CLIs[i].intents() ) ):
688 main.log.debug( json.loads( main.CLIs[i].intents ) )
689 removeResult = main.FALSE
690 break
Jeremy Songster5665f1b2016-06-20 14:38:22 -0700691 else:
692 removeResult = main.TRUE
Jeremy7134f5b2016-04-05 13:50:21 -0700693 except ( TypeError, ValueError ):
Jon Halle02505a2017-05-24 16:36:43 -0700694 main.log.error( "Cannot see intents on Node " + str( main.CLIs[ 0 ] ) +
695 ". Removing all intents." )
Jeremy7134f5b2016-04-05 13:50:21 -0700696 main.CLIs[ 0 ].removeAllIntents( purge=True )
Jon Halle02505a2017-05-24 16:36:43 -0700697 main.CLIs[ 0 ].removeAllIntents( purge=True, app='org.onosproject.optical' )
Jeremy7134f5b2016-04-05 13:50:21 -0700698
699 utilities.assert_equals( expect=main.TRUE,
700 actual=removeResult,
701 onpass="Successfully removed host intents",
Chiyu Chengef109502016-11-21 15:51:38 -0800702 onfail="Failed to remove host intents" )