blob: 1db5752db36cd0d15a8f957d0d3856c4bfc4d0bb [file] [log] [blame]
cameron@onlab.uscd4e8a22015-05-11 10:58:43 -07001
2# Testing the basic functionality of ONOS Next
3# For sanity and driver functionality excercises only.
4
5import time
6import json
7
8time.sleep( 1 )
9
10class FuncIntent:
11
12 def __init__( self ):
13 self.default = ''
14
15 def CASE10( self, main ):
16 import time
17 import os
18 """
19 Startup sequence:
20 cell <name>
21 onos-verify-cell
22 onos-remove-raft-log
23 git pull
24 mvn clean install
25 onos-package
26 onos-install -f
27 onos-wait-for-start
28 """
29 global init
30 try:
31 if type(init) is not bool:
32 init = False
33 except NameError:
34 init = False
35 #Local variables
36 cellName = main.params[ 'ENV' ][ 'cellName' ]
37 apps = main.params[ 'ENV' ][ 'cellApps' ]
38 gitBranch = main.params[ 'GIT' ][ 'branch' ]
39 #benchIp = main.params[ 'BENCH' ][ 'ip1' ]
40 benchUser = main.params[ 'BENCH' ][ 'user' ]
41 topology = main.params[ 'MININET' ][ 'topo' ]
42 #maxNodes = int( main.params[ 'availableNodes' ] )
43 main.numSwitch = int( main.params[ 'MININET' ][ 'switch' ] )
44 main.numLinks = int( main.params[ 'MININET' ][ 'links' ] )
45 main.numCtrls = main.params[ 'CTRL' ][ 'num' ]
46 PULLCODE = False
47 if main.params[ 'GIT' ][ 'pull' ] == 'True':
48 PULLCODE = True
49 main.case( "Setting up test environment" )
50 main.CLIs = []
51 for i in range( 1, int( main.numCtrls ) + 1 ):
52 main.CLIs.append( getattr( main, 'ONOScli' + str( i ) ) )
53
54 # -- INIT SECTION, ONLY RUNS ONCE -- #
55 if init == False:
56 init = True
57
58 #main.ONOSip = []
59 main.ONOSport = []
60 main.scale = ( main.params[ 'SCALE' ] ).split( "," )
61 main.numCtrls = int( main.scale[ 0 ] )
62
63 if PULLCODE:
64 main.step( "Git checkout and pull " + gitBranch )
65 main.ONOSbench.gitCheckout( gitBranch )
66 gitPullResult = main.ONOSbench.gitPull()
67 if gitPullResult == main.ERROR:
68 main.log.error( "Error pulling git branch" )
69 main.step( "Using mvn clean & install" )
70 cleanInstallResult = main.ONOSbench.cleanInstall()
71 stepResult = cleanInstallResult
72 utilities.assert_equals( expect=main.TRUE,
73 actual=stepResult,
74 onpass="Successfully compiled " +
75 "latest ONOS",
76 onfail="Failed to compile " +
77 "latest ONOS" )
78 else:
79 main.log.warn( "Did not pull new code so skipping mvn " +
80 "clean install" )
81 # Populate main.ONOSip with ips from params
82 #for i in range( 1, maxNodes + 1):
83 # main.ONOSip.append( main.params[ 'CTRL' ][ 'ip' + str( i ) ] )
84 # main.ONOSport.append( main.params[ 'CTRL' ][ 'port' +
85 # str( i ) ])
86
87 ONOSip = main.ONOSbench.getOnosIpFromEnv()
88 main.log.info("\t\t CLUSTER IPs: \n\n" + str(ONOSip) + "\n\n")
89
90 main.numCtrls = int( main.scale[ 0 ] )
91 main.scale.remove( main.scale[ 0 ] )
92
93 #kill off all onos processes
94 main.log.info( "Safety check, killing all ONOS processes" +
95 " before initiating enviornment setup" )
96 for i in range( maxNodes ):
97 main.ONOSbench.onosDie( main.ONOSip[ i ] )
98 """
99 main.step( "Apply cell to environment" )
100 cellResult = main.ONOSbench.setCell( cellName )
101 verifyResult = main.ONOSbench.verifyCell()
102 stepResult = cellResult and verifyResult
103 utilities.assert_equals( expect=main.TRUE,
104 actual=stepResult,
105 onpass="Successfully applied cell to " + \
106 "environment",
107 onfail="Failed to apply cell to environment " )
108 """
109 """main.step( "Removing raft logs" )
110 removeRaftResult = main.ONOSbench.onosRemoveRaftLogs()
111 stepResult = removeRaftResult
112 utilities.assert_equals( expect=main.TRUE,
113 actual=stepResult,
114 onpass="Successfully removed raft logs",
115 onfail="Failed to remove raft logs" )
116 """
117 print "NODE COUNT = ", main.numCtrls
118 main.log.info( "Creating cell file" )
119 cellIp = []
120 for i in range( main.numCtrls ):
121 cellIp.append( str( main.ONOSip[ i ] ) )
122 print cellIp
123 main.ONOSbench.createCellFile( benchIp, cellName, "",
124 str( apps ), *cellIp )
125
126 main.step( "Apply cell to environment" )
127 cellResult = main.ONOSbench.setCell( cellName )
128 verifyResult = main.ONOSbench.verifyCell()
129 stepResult = cellResult and verifyResult
130 utilities.assert_equals( expect=main.TRUE,
131 actual=stepResult,
132 onpass="Successfully applied cell to " + \
133 "environment",
134 onfail="Failed to apply cell to environment " )
135
136 main.step( "Creating ONOS package" )
137 packageResult = main.ONOSbench.onosPackage()
138 stepResult = packageResult
139 utilities.assert_equals( expect=main.TRUE,
140 actual=stepResult,
141 onpass="Successfully created ONOS package",
142 onfail="Failed to create ONOS package" )
143
144 main.step( "Uninstalling ONOS package" )
145 onosUninstallResult = main.TRUE
146 for i in range( main.numCtrls):
147 onosUninstallResult = onosUninstallResult and \
148 main.ONOSbench.onosUninstall( nodeIp=main.ONOSip[ i ] )
149 stepResult = onosUninstallResult
150 utilities.assert_equals( expect=main.TRUE,
151 actual=stepResult,
152 onpass="Successfully uninstalled ONOS package",
153 onfail="Failed to uninstall ONOS package" )
154 time.sleep( 5 )
155 main.step( "Installing ONOS package" )
156 onosInstallResult = main.TRUE
157 for i in range( main.numCtrls):
158 onosInstallResult = onosInstallResult and \
159 main.ONOSbench.onosInstall( node=main.ONOSip[ i ] )
160 stepResult = onosInstallResult
161 utilities.assert_equals( expect=main.TRUE,
162 actual=stepResult,
163 onpass="Successfully installed ONOS package",
164 onfail="Failed to install ONOS package" )
165
166 time.sleep( 5 )
167 main.step( "Starting ONOS service" )
168 stopResult = main.TRUE
169 startResult = main.TRUE
170 onosIsUp = main.TRUE
171 for i in range( main.numCtrls ):
172 onosIsUp = onosIsUp and main.ONOSbench.isup( main.ONOSip[ i ] )
173 if onosIsUp == main.TRUE:
174 main.log.report( "ONOS instance is up and ready" )
175 else:
176 main.log.report( "ONOS instance may not be up, stop and " +
177 "start ONOS again " )
178 for i in range( main.numCtrls ):
179 stopResult = stopResult and \
180 main.ONOSbench.onosStop( main.ONOSip[ i ] )
181 for i in range( main.numCtrls ):
182 startResult = startResult and \
183 main.ONOSbench.onosStart( main.ONOSip[ i ] )
184 stepResult = onosIsUp and stopResult and startResult
185 utilities.assert_equals( expect=main.TRUE,
186 actual=stepResult,
187 onpass="ONOS service is ready",
188 onfail="ONOS service did not start properly" )
189
190 main.step( "Start ONOS cli" )
191 cliResult = main.TRUE
192 for i in range( main.numCtrls ):
193 cliResult = cliResult and \
194 main.CLIs[i].startOnosCli( main.ONOSip[ i ] )
195 stepResult = cliResult
196 utilities.assert_equals( expect=main.TRUE,
197 actual=stepResult,
198 onpass="Successfully start ONOS cli",
199 onfail="Failed to start ONOS cli" )
200
201 def CASE11( self, main ):
202 """
203 Start mininet
204 """
205 main.log.report( "Start Mininet topology" )
206 main.log.case( "Start Mininet topology" )
207
208 main.step( "Starting Mininet Topology" )
209 topoResult = main.Mininet1.startNet( topoFile=topology )
210 stepResult = topoResult
211 utilities.assert_equals( expect=main.TRUE,
212 actual=stepResult,
213 onpass="Successfully loaded topology",
214 onfail="Failed to load topology" )
215 # Exit if topology did not load properly
216 if not topoResult:
217 main.cleanup()
218 main.exit()
219
220 def CASE12( self, main ):
221 """
222 Assign mastership to controllers
223 """
224 import re
225
226 main.step( "Assigning switches to controllers" )
227 assignResult = main.TRUE
228 for i in range( 1, ( main.numSwitch + 1 ) ):
229 main.Mininet1.assignSwController( sw=str( i ),
230 count=1,
231 ip1=main.ONOSip[ 0 ],
232 port1=main.ONOSport[ 0 ] )
233 for i in range( 1, ( main.numSwitch + 1 ) ):
234 response = main.Mininet1.getSwController( "s" + str( i ) )
235 print( "Response is " + str( response ) )
236 if re.search( "tcp:" + main.ONOSip[ 0 ], response ):
237 assignResult = assignResult and main.TRUE
238 else:
239 assignResult = main.FALSE
240 stepResult = assignResult
241 utilities.assert_equals( expect=main.TRUE,
242 actual=stepResult,
243 onpass="Successfully assigned switches" +
244 "to controller",
245 onfail="Failed to assign switches to " +
246 "controller" )
247
248 def CASE1001( self, main ):
249 """
250 Add host intents between 2 host:
251 - Discover hosts
252 - Add host intents
253 - Check intents
254 - Check flows
255 - Ping hosts
256 - Reroute
257 - Link down
258 - Ping hosts
259 - Link up
260 - Ping hosts
261 - Remove intents
262 """
263 import time
264 import json
265 import re
266 """
267 Create your item(s) here
268 item = { 'name': '', 'host1':
269 { 'name': '', 'MAC': '00:00:00:00:00:0X',
270 'id':'00:00:00:00:00:0X/-X' } , 'host2':
271 { 'name': '', 'MAC': '00:00:00:00:00:0X',
272 'id':'00:00:00:00:00:0X/-X'}, 'link': { 'switch1': '',
273 'switch2': '', 'num':'' } }
274 """
275 # Local variables
276 items = []
277 ipv4 = { 'name': 'IPV4', 'host1':
278 { 'name': 'h1', 'MAC': '00:00:00:00:00:01',
279 'id':'00:00:00:00:00:01/-1' } , 'host2':
280 { 'name': 'h9', 'MAC': '00:00:00:00:00:09',
281 'id':'00:00:00:00:00:09/-1'}, 'link': { 'switch1': 's5',
282 'switch2': 's2', 'num':'18' } }
283 dualStack1 = { 'name': 'DUALSTACK1', 'host1':
284 { 'name': 'h3', 'MAC': '00:00:00:00:00:03',
285 'id':'00:00:00:00:00:03/-1' } , 'host2':
286 { 'name': 'h11', 'MAC': '00:00:00:00:00:0B',
287 'id':'00:00:00:00:00:0B/-1'}, 'link': { 'switch1': 's5',
288 'switch2': 's2', 'num':'18' } }
289 items.append( ipv4 )
290 items.append( dualStack1 )
291 # Global variables
292
293 main.log.case( "Add host intents between 2 host" )
294
295 for item in items:
296 stepResult = main.TRUE
297 itemName = item[ 'name' ]
298 h1Name = item[ 'host1' ][ 'name' ]
299 h2Name = item[ 'host2' ][ 'name' ]
300 h1Mac = item[ 'host1' ][ 'MAC' ]
301 h2Mac = item[ 'host2' ][ 'MAC' ]
302 h1Id = item[ 'host1' ][ 'id']
303 h2Id = item[ 'host2' ][ 'id']
304 # Link down/up for rerouting
305 sw1 = item[ 'link' ][ 'switch1' ]
306 sw2 = item[ 'link' ][ 'switch2' ]
307 remLink = item[ 'link' ][ 'num' ]
308 pingResult = main.TRUE
309 statusResult = main.TRUE
310 linkDownResult = main.TRUE
311 linkUpResult = main.TRUE
312 intentsId = []
313 main.step( itemName + ": Add host intents between " + h1Name
314 + " and " + h2Name )
315 main.log.info( itemName + ": Discover host using arping" )
316 main.Mininet1.arping( host=h1Name )
317 main.Mininet1.arping( host=h2Name )
318 host1 = main.CLIs[ 0 ].getHost( mac=h1Mac )
319 host2 = main.CLIs[ 0 ].getHost( mac=h2Mac )
320 print host1
321 print host2
322 # Adding intents
323 main.log.info( itemName + ": Adding host intents" )
324 intent1 = main.CLIs[ 0 ].addHostIntent( hostIdOne=h1Id,
325 hostIdTwo=h2Id )
326 intentsId.append( intent1 )
327 time.sleep( 5 )
328 intent2 = main.CLIs[ 0 ].addHostIntent( hostIdOne=h2Id,
329 hostIdTwo=h1Id )
330 intentsId.append( intent2 )
331 # Checking intents
332 main.log.info( itemName + ": Check host intents state" )
333 time.sleep( 30 )
334 for i in range( main.numCtrls ):
335 intentResult = main.CLIs[ i ].checkIntentState(
336 intentsId=intentsId )
337 if not intentResult:
338 main.log.info( itemName + ": Check host intents state" +
339 " again")
340 for i in range( main.numCtrls ):
341 intentResult = main.CLIs[ i ].checkIntentState(
342 intentsId=intentsId )
343 # Ping hosts
344 time.sleep( 10 )
345 main.log.info( itemName + ": Ping " + h1Name + " and " +
346 h2Name )
347 pingResult1 = main.Mininet1.pingHost( src=h1Name , target=h2Name )
348 if not pingResult1:
349 main.log.info( itemName + ": " + h1Name + " cannot ping "
350 + h2Name )
351 pingResult2 = main.Mininet1.pingHost( src=h2Name , target=h1Name )
352 if not pingResult2:
353 main.log.info( itemName + ": " + h2Name + " cannot ping "
354 + h1Name )
355 pingResult = pingResult1 and pingResult2
356 if pingResult:
357 main.log.info( itemName + ": Successfully pinged " +
358 "both hosts" )
359 else:
360 main.log.info( itemName + ": Failed to ping " +
361 "both hosts" )
362 # Rerouting ( link down )
363 main.log.info( itemName + ": Bring link down between " +
364 sw1 + " and " + sw2 )
365 main.Mininet1.link( end1=sw1,
366 end2=sw2,
367 option="down" )
368 time.sleep( 5 )
369
370 # Check onos topology
371 main.log.info( itemName + ": Checking ONOS topology " )
372
373 for i in range( main.numCtrls ):
374 topologyResult = main.CLIs[ i ].topology()
375 linkDownResult = main.ONOSbench.checkStatus( topologyResult,
376 main.numSwitch,
377 remLink )\
378 and linkDownResult
379 if not linkDownResult:
380 main.log.info( itemName + ": Topology mismatch" )
381 else:
382 main.log.info( itemName + ": Topology match" )
383
384 # Ping hosts
385 main.log.info( itemName + ": Ping " + h1Name + " and " +
386 h2Name )
387 pingResult1 = main.Mininet1.pingHost( src=h1Name , target=h2Name )
388 if not pingResult1:
389 main.log.info( itemName + ": " + h1Name + " cannot ping "
390 + h2Name )
391 pingResult2 = main.Mininet1.pingHost( src=h2Name , target=h1Name )
392 if not pingResult2:
393 main.log.info( itemName + ": " + h2Name + " cannot ping "
394 + h1Name )
395 pingResult = pingResult1 and pingResult2
396 if pingResult:
397 main.log.info( itemName + ": Successfully pinged " +
398 "both hosts" )
399 else:
400 main.log.info( itemName + ": Failed to ping " +
401 "both hosts" )
402 # link up
403 main.log.info( itemName + ": Bring link up between " +
404 sw1 + " and " + sw2 )
405 main.Mininet1.link( end1=sw1,
406 end2=sw2,
407 option="up" )
408 time.sleep( 5 )
409
410 # Check onos topology
411 main.log.info( itemName + ": Checking ONOS topology " )
412 for i in range( main.numCtrls ):
413 topologyResult = main.CLIs[ i ].topology()
414 linkUpResult = main.ONOSbench.checkStatus( topologyResult,
415 main.numSwitch,
416 main.numLinks )\
417 and linkUpResult
418 if not linkUpResult:
419 main.log.info( itemName + ": Topology mismatch" )
420 else:
421 main.log.info( itemName + ": Topology match" )
422
423 # Ping hosts
424 main.log.info( itemName + ": Ping " + h1Name + " and " +
425 h2Name )
426 pingResult1 = main.Mininet1.pingHost( src=h1Name , target=h2Name )
427 if not pingResult1:
428 main.log.info( itemName + ": " + h1Name + " cannot ping "
429 + h2Name )
430 pingResult2 = main.Mininet1.pingHost( src=h2Name , target=h1Name )
431 if not pingResult2:
432 main.log.info( itemName + ": " + h2Name + " cannot ping "
433 + h1Name )
434 pingResult = pingResult1 and pingResult2
435 if pingResult:
436 main.log.info( itemName + ": Successfully pinged " +
437 "both hosts" )
438 else:
439 main.log.info( itemName + ": Failed to ping " +
440 "both hosts" )
441
442 # Remove intents
443 for intent in intentsId:
444 main.CLIs[ 0 ].removeIntent( intentId=intent, purge=True )
445
446 print main.CLIs[ 0 ].intents()
447 stepResult = pingResult and linkDownResult and linkUpResult \
448 and intentResult
449 utilities.assert_equals( expect=main.TRUE,
450 actual=stepResult,
451 onpass=itemName +
452 ": host intent successful",
453 onfail=itemName +
454 ": Add host intent failed" )
455 def CASE1002( self, main ):
456 """
457 Add point intents between 2 hosts:
458 - Get device ids
459 - Add point intents
460 - Check intents
461 - Check flows
462 - Ping hosts
463 - Reroute
464 - Link down
465 - Ping hosts
466 - Link up
467 - Ping hosts
468 - Remove intents
469 """
470
471 def CASE1003( self, main ):
472 """
473 Add single point to multi point intents
474 - Get device ids
475 - Add single point to multi point intents
476 - Check intents
477 - Check flows
478 - Ping hosts
479 - Reroute
480 - Link down
481 - Ping hosts
482 - Link up
483 - Ping hosts
484 - Remove intents
485 """
486
487 def CASE1004( self, main ):
488 """
489 Add multi point to single point intents
490 - Get device ids
491 - Add multi point to single point intents
492 - Check intents
493 - Check flows
494 - Ping hosts
495 - Reroute
496 - Link down
497 - Ping hosts
498 - Link up
499 - Ping hosts
500 - Remove intents
501 """