blob: 3ab0df40c05c82c067c5152615a13678b763d920 [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' ]
43 wrapperFile2 = main.params[ 'DEPENDENCY' ][ 'wrapper2' ]
44 wrapperFile3 = main.params[ 'DEPENDENCY' ][ 'wrapper3' ]
45 main.startUpSleep = int( main.params[ 'SLEEP' ][ 'startup' ] )
46 main.checkIntentSleep = int( main.params[ 'SLEEP' ][ 'checkintent' ] )
47 main.removeIntentSleep = int( main.params[ 'SLEEP' ][ 'removeintent' ] )
48 main.rerouteSleep = int( main.params[ 'SLEEP' ][ 'reroute' ] )
49 main.fwdSleep = int( main.params[ 'SLEEP' ][ 'fwd' ] )
50 main.checkTopoAttempts = int( main.params[ 'SLEEP' ][ 'topoAttempts' ] )
51 gitPull = main.params[ 'GIT' ][ 'pull' ]
52 main.numSwitch = int( main.params[ 'MININET' ][ 'switch' ] )
53 main.numLinks = int( main.params[ 'MININET' ][ 'links' ] )
54 main.cellData = {} # For creating cell file
55 main.hostsData = {}
56 main.CLIs = []
57 main.ONOSip = [] # List of IPs of active ONOS nodes. CASE 2
58 main.activeONOSip = []
59 main.assertReturnString = '' # Assembled assert return string
60
61 main.ONOSip = main.ONOSbench.getOnosIps()
62
63 # Assigning ONOS cli handles to a list
64 for i in range( 1, main.maxNodes + 1 ):
65 main.CLIs.append( getattr( main, 'ONOScli' + str( i ) ) )
66
67 # -- INIT SECTION, ONLY RUNS ONCE -- #
68 main.startUp = imp.load_source( wrapperFile1,
69 main.dependencyPath +
70 wrapperFile1 +
71 ".py" )
72
73 main.intentFunction = imp.load_source( wrapperFile2,
74 main.dependencyPath +
75 wrapperFile2 +
76 ".py" )
77
78 main.topo = imp.load_source( wrapperFile3,
79 main.dependencyPath +
80 wrapperFile3 +
81 ".py" )
82
83 if main.CLIs:
84 stepResult = main.TRUE
85 else:
86 main.log.error( "Did not properly created list of ONOS CLI handle" )
87 stepResult = main.FALSE
88 except Exception as e:
89 main.log.exception(e)
90 main.cleanup()
91 main.exit()
92
93 utilities.assert_equals( expect=main.TRUE,
94 actual=stepResult,
95 onpass="Successfully construct " +
96 "test variables ",
97 onfail="Failed to construct test variables" )
98
99 if gitPull == 'True':
100 main.step( "Building ONOS in " + gitBranch + " branch" )
101 onosBuildResult = main.startUp.onosBuild( main, gitBranch )
102 stepResult = onosBuildResult
103 utilities.assert_equals( expect=main.TRUE,
104 actual=stepResult,
105 onpass="Successfully compiled " +
106 "latest ONOS",
107 onfail="Failed to compile " +
108 "latest ONOS" )
109 else:
110 main.log.warn( "Did not pull new code so skipping mvn " +
111 "clean install" )
112 main.ONOSbench.getVersion( report=True )
113
114 def CASE2( self, main ):
115 """
116 - Set up cell
117 - Create cell file
118 - Set cell file
119 - Verify cell file
120 - Kill ONOS process
121 - Uninstall ONOS cluster
122 - Verify ONOS start up
123 - Install ONOS cluster
124 - Connect to cli
125 """
126
127 # main.scale[ 0 ] determines the current number of ONOS controller
128 main.numCtrls = int( main.scale[ 0 ] )
129
130 main.case( "Starting up " + str( main.numCtrls ) +
131 " node(s) ONOS cluster" )
132 main.caseExplanation = "Set up ONOS with " + str( main.numCtrls ) +\
133 " node(s) ONOS cluster"
134
135
136
137 #kill off all onos processes
138 main.log.info( "Safety check, killing all ONOS processes" +
Jon Hall70b2ff42015-11-17 15:49:44 -0800139 " before initiating environment setup" )
acsmars51a7fe02015-10-29 18:33:32 -0700140
141 for i in range( main.maxNodes ):
142 main.ONOSbench.onosDie( main.ONOSip[ i ] )
143
144 print "NODE COUNT = ", main.numCtrls
145
146 tempOnosIp = []
147 for i in range( main.numCtrls ):
148 tempOnosIp.append( main.ONOSip[i] )
149
150 main.ONOSbench.createCellFile( main.ONOSbench.ip_address,
151 "temp", main.Mininet1.ip_address,
152 main.apps, tempOnosIp )
153
154 main.step( "Apply cell to environment" )
155 cellResult = main.ONOSbench.setCell( "temp" )
156 verifyResult = main.ONOSbench.verifyCell()
157 stepResult = cellResult and verifyResult
158 utilities.assert_equals( expect=main.TRUE,
159 actual=stepResult,
160 onpass="Successfully applied cell to " + \
161 "environment",
162 onfail="Failed to apply cell to environment " )
163
164 main.step( "Creating ONOS package" )
165 packageResult = main.ONOSbench.onosPackage()
166 stepResult = packageResult
167 utilities.assert_equals( expect=main.TRUE,
168 actual=stepResult,
169 onpass="Successfully created ONOS package",
170 onfail="Failed to create ONOS package" )
171
172 time.sleep( main.startUpSleep )
173 main.step( "Uninstalling ONOS package" )
174 onosUninstallResult = main.TRUE
175 for ip in main.ONOSip:
176 onosUninstallResult = onosUninstallResult and \
177 main.ONOSbench.onosUninstall( nodeIp=ip )
178 stepResult = onosUninstallResult
179 utilities.assert_equals( expect=main.TRUE,
180 actual=stepResult,
181 onpass="Successfully uninstalled ONOS package",
182 onfail="Failed to uninstall ONOS package" )
183
184 time.sleep( main.startUpSleep )
185 main.step( "Installing ONOS package" )
186 onosInstallResult = main.TRUE
187 for i in range( main.numCtrls ):
188 onosInstallResult = onosInstallResult and \
189 main.ONOSbench.onosInstall( node=main.ONOSip[ i ] )
190 # Populate activeONOSip
191 main.activeONOSip.append( main.ONOSip[ i ] )
192 stepResult = onosInstallResult
193 utilities.assert_equals( expect=main.TRUE,
194 actual=stepResult,
195 onpass="Successfully installed ONOS package",
196 onfail="Failed to install ONOS package" )
197
198 time.sleep( main.startUpSleep )
199 main.step( "Starting ONOS service" )
200 stopResult = main.TRUE
201 startResult = main.TRUE
202 onosIsUp = main.TRUE
203
204 for i in range( main.numCtrls ):
205 onosIsUp = onosIsUp and main.ONOSbench.isup( main.ONOSip[ i ] )
206 if onosIsUp == main.TRUE:
207 main.log.report( "ONOS instance is up and ready" )
208 else:
209 main.log.report( "ONOS instance may not be up, stop and " +
210 "start ONOS again " )
211
212 for i in range( main.numCtrls ):
213 stopResult = stopResult and \
214 main.ONOSbench.onosStop( main.ONOSip[ i ] )
215 for i in range( main.numCtrls ):
216 startResult = startResult and \
217 main.ONOSbench.onosStart( main.ONOSip[ i ] )
218 stepResult = onosIsUp and stopResult and startResult
219 utilities.assert_equals( expect=main.TRUE,
220 actual=stepResult,
221 onpass="ONOS service is ready",
222 onfail="ONOS service did not start properly" )
223
224 main.step( "Start ONOS cli" )
225 cliResult = main.TRUE
226 for i in range( main.numCtrls ):
227 cliResult = cliResult and \
228 main.CLIs[ i ].startOnosCli( main.ONOSip[ i ] )
229 stepResult = cliResult
230 utilities.assert_equals( expect=main.TRUE,
231 actual=stepResult,
232 onpass="Successfully start ONOS cli",
233 onfail="Failed to start ONOS cli" )
234
235 # Remove the first element in main.scale list
236 main.scale.remove( main.scale[ 0 ] )
237
238 main.intentFunction.report( main )
239
240
241 def CASE10( self, main ):
242 """
243 Start Mininet opticalTest Topology
244 """
245 main.case( "Mininet with Linc-OE startup")
246 main.caseExplanation = "Start opticalTest.py topology included with ONOS"
247 main.step( "Starting mininet and LINC-OE" )
248 topoResult = main.TRUE
249 time.sleep( 10 )
250 controllerIPs = ' '.join( main.activeONOSip )
251 opticalMnScript = main.LincOE.runOpticalMnScript(ctrllerIP = controllerIPs)
252 topoResult = opticalMnScript
253 utilities.assert_equals(
254 expect=main.TRUE,
255 actual=topoResult,
256 onpass="Started the topology successfully ",
257 onfail="Failed to start the topology")
258
259 # Exit if topology did not load properly
260 if not topoResult:
261 main.cleanup()
262 main.exit()
263
264
265
266
267 def CASE14( self, main ):
268 """
269 Stop mininet
270 """
271 main.log.report( "Stop Mininet topology" )
272 main.case( "Stop Mininet topology" )
273 main.caseExplanation = "Stopping the current mininet topology " +\
274 "to start up fresh"
275
276 main.step( "Stopping Mininet Topology" )
277 topoResult = main.LincOE.stopNet( timeout=180 )
278 utilities.assert_equals( expect=main.TRUE,
279 actual=topoResult,
280 onpass="Successfully stopped mininet",
281 onfail="Failed to stopped mininet" )
282 # Exit if topology did not load properly
283 if not topoResult:
284 main.cleanup()
285 main.exit()
286
287 def CASE21( self,main ):
288 """
289 Run pingall to discover all hosts
290 """
291 main.case( "Running Pingall" )
292 main.caseExplanation = "Use pingall to discover all hosts. Pingall is expected to fail."
293 main.step( "Discover Hosts through Pingall" )
294 pingResult = main.LincOE.pingall( timeout = 600 )
295
296 utilities.assert_equals( expect=main.FALSE,
297 actual=pingResult,
298 onpass="Pingall Completed",
299 onfail="Pingall did not complete or did not return fales" )
300
301 def CASE22( self,main ):
302 """
303 Send arpings to discover all hosts
304 """
305 main.case( "Discover Hosts with arping" )
306 main.caseExplanation = "Send arpings between all the hosts to discover and verify them"
307
308 main.step( "Send arping between all hosts" )
309
310 hosts = [ "h1","h2","h3","h4","h5","h6" ]
311
312 arpingHostResults = main.TRUE
313 for host in hosts:
314 if main.LincOE.arping( host ):
315 main.log.info( "Successfully reached host {} with arping".format( host ) )
316 else:
317 main.log.error( "Could not reach host {} with arping".format( host ) )
318 arpingHostResults = main.FALSE
319
320 utilities.assert_equals( expect=main.TRUE,
321 actual=arpingHostResults,
322 onpass="Successfully discovered all hosts",
323 onfail="Could not descover some hosts" )
324
325 def CASE23( self, main ):
326 """
327 Compare ONOS Topology to Mininet Topology
328 """
329 import json
330
331 main.case( "Compare ONOS Topology view to Mininet topology" )
332 main.caseExplanation = "Compare topology elements between Mininet" +\
333 " and ONOS"
334
335 main.log.info( "Gathering topology information from Mininet" )
336 devicesResults = main.FALSE # Overall Boolean for device correctness
337 linksResults = main.FALSE # Overall Boolean for link correctness
338 hostsResults = main.FALSE # Overall Boolean for host correctness
339 deviceFails = [] # Nodes where devices are incorrect
340 linkFails = [] # Nodes where links are incorrect
341 hostFails = [] # Nodes where hosts are incorrect
342 attempts = main.checkTopoAttempts # Remaining Attempts
343
344 mnSwitches = 16
345 mnLinks = 46
346 mnHosts = 6
347
Jon Hall70b2ff42015-11-17 15:49:44 -0800348 main.step( "Comparing Mininet topology to ONOS topology" )
acsmars51a7fe02015-10-29 18:33:32 -0700349
350 while ( attempts >= 0 ) and\
351 ( not devicesResults or not linksResults or not hostsResults ):
352 time.sleep( 2 )
353 if not devicesResults:
354 devices = main.topo.getAllDevices( main )
355 ports = main.topo.getAllPorts( main )
356 devicesResults = main.TRUE
357 deviceFails = [] # Reset for each attempt
358 if not linksResults:
359 links = main.topo.getAllLinks( main )
360 linksResults = main.TRUE
361 linkFails = [] # Reset for each attempt
362 if not hostsResults:
363 hosts = main.topo.getAllHosts( main )
364 hostsResults = main.TRUE
365 hostFails = [] # Reset for each attempt
366
367 # Check for matching topology on each node
368 for controller in range( main.numCtrls ):
369 controllerStr = str( controller + 1 ) # ONOS node number
370 # Compare Devices
371 if devices[ controller ] and ports[ controller ] and\
372 "Error" not in devices[ controller ] and\
373 "Error" not in ports[ controller ]:
374
375 try:
376 deviceData = json.loads( devices[ controller ] )
377 portData = json.loads( ports[ controller ] )
378 except (TypeError,ValueError):
379 main.log.error("Could not load json:" + str( devices[ controller ] ) + ' or ' + str( ports[ controller ] ))
380 currentDevicesResult = main.FALSE
381 else:
382 if mnSwitches == len( deviceData ):
383 currentDevicesResult = main.TRUE
384 else:
385 currentDevicesResult = main.FALSE
386 main.log.error( "Node {} only sees {} device(s) but {} exist".format(
387 controllerStr,len( deviceData ),mnSwitches ) )
388 else:
389 currentDevicesResult = main.FALSE
390 if not currentDevicesResult:
391 deviceFails.append( controllerStr )
392 devicesResults = devicesResults and currentDevicesResult
393 # Compare Links
394 if links[ controller ] and "Error" not in links[ controller ]:
395 try:
396 linkData = json.loads( links[ controller ] )
397 except (TypeError,ValueError):
398 main.log.error("Could not load json:" + str( links[ controller ] ) )
399 currentLinksResult = main.FALSE
400 else:
401 if mnLinks == len( linkData ):
402 currentLinksResult = main.TRUE
403 else:
404 currentLinksResult = main.FALSE
405 main.log.error( "Node {} only sees {} link(s) but {} exist".format(
406 controllerStr,len( linkData ),mnLinks ) )
407 else:
408 currentLinksResult = main.FALSE
409 if not currentLinksResult:
410 linkFails.append( controllerStr )
411 linksResults = linksResults and currentLinksResult
412 # Compare Hosts
413 if hosts[ controller ] and "Error" not in hosts[ controller ]:
414 try:
415 hostData = json.loads( hosts[ controller ] )
416 except (TypeError,ValueError):
417 main.log.error("Could not load json:" + str( hosts[ controller ] ) )
418 currentHostsResult = main.FALSE
419 else:
420 if mnHosts == len( hostData ):
421 currentHostsResult = main.TRUE
422 else:
423 currentHostsResult = main.FALSE
424 main.log.error( "Node {} only sees {} host(s) but {} exist".format(
425 controllerStr,len( hostData ),mnHosts ) )
426 else:
427 currentHostsResult = main.FALSE
428 if not currentHostsResult:
429 hostFails.append( controllerStr )
430 hostsResults = hostsResults and currentHostsResult
431 # Decrement Attempts Remaining
432 attempts -= 1
433
434 utilities.assert_equals( expect=[],
435 actual=deviceFails,
436 onpass="ONOS correctly discovered all devices",
437 onfail="ONOS incorrectly discovered devices on nodes: " +
438 str( deviceFails ) )
439 utilities.assert_equals( expect=[],
440 actual=linkFails,
441 onpass="ONOS correctly discovered all links",
442 onfail="ONOS incorrectly discovered links on nodes: " +
443 str( linkFails ) )
444 utilities.assert_equals( expect=[],
445 actual=hostFails,
446 onpass="ONOS correctly discovered all hosts",
447 onfail="ONOS incorrectly discovered hosts on nodes: " +
448 str( hostFails ) )
449 if hostsResults and linksResults and devicesResults:
450 topoResults = main.TRUE
451 else:
452 topoResults = main.FALSE
453 utilities.assert_equals( expect=main.TRUE,
454 actual=topoResults,
455 onpass="ONOS correctly discovered the topology",
456 onfail="ONOS incorrectly discovered the topology" )
457
458
459 def CASE31( self, main ):
460 import time
461 """
462 Add bidirectional point intents between 2 packet layer( mininet )
463 devices and ping mininet hosts
464 """
465 main.log.report(
466 "This testcase adds bidirectional point intents between 2 " +
467 "packet layer( mininet ) devices and ping mininet hosts" )
468 main.case( "Install point intents between 2 packet layer device and " +
469 "ping the hosts" )
470 main.caseExplanation = "This testcase adds bidirectional point intents between 2 " +\
471 "packet layer( mininet ) devices and ping mininet hosts"
472
473 main.step( "Adding point intents" )
474 checkFlowResult = main.TRUE
475 main.pIntentsId = []
476 pIntent1 = main.CLIs[ 0 ].addPointIntent(
477 "of:0000ffffffff0001/1",
478 "of:0000ffffffff0005/1" )
479 time.sleep( 10 )
480 pIntent2 = main.CLIs[ 0 ].addPointIntent(
481 "of:0000ffffffff0005/1",
482 "of:0000ffffffff0001/1" )
483 main.pIntentsId.append( pIntent1 )
484 main.pIntentsId.append( pIntent2 )
485 time.sleep( 10 )
486 main.log.info( "Checking intents state")
487 checkStateResult = main.CLIs[ 0 ].checkIntentState(
488 intentsId = main.pIntentsId )
489 time.sleep( 10 )
490 main.log.info( "Checking flows state")
491 checkFlowResult = main.CLIs[ 0 ].checkFlowsState()
492 # Sleep for 10 seconds to provide time for the intent state to change
493 time.sleep( 10 )
494 main.log.info( "Checking intents state one more time")
495 checkStateResult = main.CLIs[ 0 ].checkIntentState(
496 intentsId = main.pIntentsId )
497
498 if checkStateResult and checkFlowResult:
499 addIntentsResult = main.TRUE
500 else:
501 addIntentsResult = main.FALSE
502 utilities.assert_equals(
503 expect=main.TRUE,
504 actual=addIntentsResult,
505 onpass="Successfully added point intents",
506 onfail="Failed to add point intents")
507
508 if not addIntentsResult:
509 main.log.error( "Intents were not properly installed. Exiting case." )
510 main.skipCase()
511
512 main.step( "Ping h1 and h5" )
513 pingResult = main.LincOE.pingHostOptical( src="h1", target="h5" )
514 utilities.assert_equals(
515 expect=main.TRUE,
516 actual=pingResult,
517 onpass="Successfully pinged h1 and h5",
518 onfail="Failed to ping between h1 and h5")
519
520 def CASE32( self ):
521 """
522 Add host intents between 2 packet layer host
523 """
524 import time
525 import json
526 main.log.report( "Adding host intents between 2 optical layer host" )
527 main.case( "Test add host intents between optical layer host" )
528 main.caseExplanation = "Test host intents between 2 optical layer host"
529
530 main.step( "Adding host intents to h1 and h2" )
531 hostMACs = []
532 hostId = []
533 # Listing host MAC addresses
534 for i in range( 1 , 7 ):
535 hostMACs.append( "00:00:00:00:00:" +
536 str( hex( i )[ 2: ] ).zfill( 2 ).upper() )
537 for macs in hostMACs:
538 hostId.append( macs + "/-1" )
539 host1 = hostId[ 0 ]
540 host2 = hostId[ 1 ]
541
542 intentsId = []
543 intent1 = main.CLIs[ 0 ].addHostIntent( hostIdOne = host1,
544 hostIdTwo = host2 )
545 intentsId.append( intent1 )
546 # Checking intents state before pinging
547 main.log.info( "Checking intents state" )
548 intentResult = main.CLIs[ 0 ].checkIntentState( intentsId = intentsId )
549 # Check intent state again if intents are not in installed state
550
551
552 # If intent state is wrong, wait 3 sec and try again
553 if not intentResult:
554 time.sleep( 3 )
555 intentResult = main.CLIs[ 0 ].checkIntentState( intentsId = intentsId )
556
557 # If intent state is still wrong, display intent states
558 if not intentResult:
559 main.log.error( main.CLIs[ 0 ].intents() )
560
561 utilities.assert_equals( expect=main.TRUE,
562 actual=intentResult,
563 onpass="All intents are in INSTALLED state ",
564 onfail="Some of the intents are not in " +
565 "INSTALLED state " )
566
567 if not intentResult:
568 main.log.error( "Intents were not properly installed. Skipping Ping" )
569 else:
570 # Pinging h1 to h2 and then ping h2 to h1
571 main.step( "Pinging h1 and h2" )
572 pingResult = main.TRUE
573 pingResult = main.LincOE.pingHostOptical( src="h1", target="h2" ) \
574 and main.LincOE.pingHostOptical( src="h2",target="h1" )
575
576 utilities.assert_equals( expect=main.TRUE,
577 actual=pingResult,
578 onpass="Pinged successfully between h1 and h2",
579 onfail="Pinged failed between h1 and h2" )
580
581 # Removed all added host intents
582 main.step( "Removing host intents" )
583 removeResult = main.TRUE
584 # Check remaining intents
585 intentsJson = json.loads( main.CLIs[ 0 ].intents() )
586 main.CLIs[ 0 ].removeIntent( intentId=intent1, purge=True )
587 #main.CLIs[ 0 ].removeIntent( intentId=intent2, purge=True )
588 for intents in intentsJson:
589 main.CLIs[ 0 ].removeIntent( intentId=intents.get( 'id' ),
590 app='org.onosproject.optical',
591 purge=True )
592 # Check if any intents could not be removed
593 if len( json.loads( main.CLIs[ 0 ].intents() ) ):
594 print json.loads( main.CLIs[ 0 ].intents() )
595 removeResult = main.FALSE
596 utilities.assert_equals( expect=main.TRUE,
597 actual=removeResult,
598 onpass="Successfully removed host intents",
599 onfail="Failed to remove host intents" )
600