blob: c92f5522ed3a7f23316eeee706db694d4b1824be [file] [log] [blame]
kelvin-onlab4ff9cc12015-05-05 11:14:42 -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
kelvin-onlab05cf7732015-05-08 14:25:46 -070010class FuncIntent:
kelvin-onlab4ff9cc12015-05-05 11:14:42 -070011
12 def __init__( self ):
13 self.default = ''
14
15 def CASE10( self, main ):
16 import time
17 import os
kelvin-onlabe5239e52015-05-13 14:46:45 -070018 import imp
kelvin-onlab4ff9cc12015-05-05 11:14:42 -070019 """
20 Startup sequence:
21 cell <name>
22 onos-verify-cell
23 onos-remove-raft-log
24 git pull
25 mvn clean install
26 onos-package
27 onos-install -f
28 onos-wait-for-start
29 """
kelvin-onlabf70fd542015-05-07 18:41:40 -070030 global init
31 try:
32 if type(init) is not bool:
33 init = False
34 except NameError:
35 init = False
kelvin-onlab4ff9cc12015-05-05 11:14:42 -070036 #Local variables
37 cellName = main.params[ 'ENV' ][ 'cellName' ]
kelvin-onlabf70fd542015-05-07 18:41:40 -070038 apps = main.params[ 'ENV' ][ 'cellApps' ]
kelvin-onlabf70fd542015-05-07 18:41:40 -070039 gitBranch = main.params[ 'GIT' ][ 'branch' ]
kelvin-onlabf70fd542015-05-07 18:41:40 -070040 benchIp = main.params[ 'BENCH' ][ 'ip1' ]
41 benchUser = main.params[ 'BENCH' ][ 'user' ]
kelvin-onlab05cf7732015-05-08 14:25:46 -070042 topology = main.params[ 'MININET' ][ 'topo' ]
43 maxNodes = int( main.params[ 'availableNodes' ] )
kelvin-onlab4ff9cc12015-05-05 11:14:42 -070044 main.numSwitch = int( main.params[ 'MININET' ][ 'switch' ] )
kelvin-onlab65782a82015-05-07 14:12:13 -070045 main.numLinks = int( main.params[ 'MININET' ][ 'links' ] )
kelvin-onlabf70fd542015-05-07 18:41:40 -070046 main.numCtrls = main.params[ 'CTRL' ][ 'num' ]
kelvin-onlabe5239e52015-05-13 14:46:45 -070047 main.wrapper = imp.load_source( 'FuncIntentFunction',
48 '/home/admin/ONLabTest/TestON/tests/' +
49 'FuncIntent/Dependency/' +
50 'FuncIntentFunction.py' )
kelvin-onlab4ff9cc12015-05-05 11:14:42 -070051 PULLCODE = False
52 if main.params[ 'GIT' ][ 'pull' ] == 'True':
53 PULLCODE = True
54 main.case( "Setting up test environment" )
kelvin-onlabf70fd542015-05-07 18:41:40 -070055 main.CLIs = []
56 for i in range( 1, int( main.numCtrls ) + 1 ):
57 main.CLIs.append( getattr( main, 'ONOScli' + str( i ) ) )
58
59 # -- INIT SECTION, ONLY RUNS ONCE -- #
60 if init == False:
61 init = True
kelvin-onlabe5239e52015-05-13 14:46:45 -070062 main.MNisUp = main.FALSE
kelvin-onlabf70fd542015-05-07 18:41:40 -070063
kelvin-onlab05cf7732015-05-08 14:25:46 -070064 main.ONOSip = []
65 main.ONOSport = []
66 main.scale = ( main.params[ 'SCALE' ] ).split( "," )
67 main.numCtrls = int( main.scale[ 0 ] )
kelvin-onlabf70fd542015-05-07 18:41:40 -070068
69 if PULLCODE:
70 main.step( "Git checkout and pull " + gitBranch )
71 main.ONOSbench.gitCheckout( gitBranch )
72 gitPullResult = main.ONOSbench.gitPull()
73 if gitPullResult == main.ERROR:
74 main.log.error( "Error pulling git branch" )
75 main.step( "Using mvn clean & install" )
76 cleanInstallResult = main.ONOSbench.cleanInstall()
77 stepResult = cleanInstallResult
78 utilities.assert_equals( expect=main.TRUE,
79 actual=stepResult,
80 onpass="Successfully compiled " +
81 "latest ONOS",
82 onfail="Failed to compile " +
83 "latest ONOS" )
84 else:
85 main.log.warn( "Did not pull new code so skipping mvn " +
86 "clean install" )
kelvin-onlab05cf7732015-05-08 14:25:46 -070087 # Populate main.ONOSip with ips from params
kelvin-onlabf70fd542015-05-07 18:41:40 -070088 for i in range( 1, maxNodes + 1):
kelvin-onlab05cf7732015-05-08 14:25:46 -070089 main.ONOSip.append( main.params[ 'CTRL' ][ 'ip' + str( i ) ] )
90 main.ONOSport.append( main.params[ 'CTRL' ][ 'port' +
91 str( i ) ])
kelvin-onlabf70fd542015-05-07 18:41:40 -070092
kelvin-onlab05cf7732015-05-08 14:25:46 -070093 main.numCtrls = int( main.scale[ 0 ] )
94 main.scale.remove( main.scale[ 0 ] )
kelvin-onlabf70fd542015-05-07 18:41:40 -070095 #kill off all onos processes
96 main.log.info( "Safety check, killing all ONOS processes" +
97 " before initiating enviornment setup" )
98 for i in range( maxNodes ):
kelvin-onlab05cf7732015-05-08 14:25:46 -070099 main.ONOSbench.onosDie( main.ONOSip[ i ] )
kelvin-onlabf70fd542015-05-07 18:41:40 -0700100 """main.step( "Removing raft logs" )
101 removeRaftResult = main.ONOSbench.onosRemoveRaftLogs()
102 stepResult = removeRaftResult
103 utilities.assert_equals( expect=main.TRUE,
104 actual=stepResult,
105 onpass="Successfully removed raft logs",
106 onfail="Failed to remove raft logs" )
107 """
kelvin-onlab05cf7732015-05-08 14:25:46 -0700108 print "NODE COUNT = ", main.numCtrls
kelvin-onlabf70fd542015-05-07 18:41:40 -0700109 main.log.info( "Creating cell file" )
110 cellIp = []
kelvin-onlab05cf7732015-05-08 14:25:46 -0700111 for i in range( main.numCtrls ):
112 cellIp.append( str( main.ONOSip[ i ] ) )
kelvin-onlabf70fd542015-05-07 18:41:40 -0700113 print cellIp
114 main.ONOSbench.createCellFile( benchIp, cellName, "",
115 str( apps ), *cellIp )
kelvin-onlab4ff9cc12015-05-05 11:14:42 -0700116
117 main.step( "Apply cell to environment" )
118 cellResult = main.ONOSbench.setCell( cellName )
119 verifyResult = main.ONOSbench.verifyCell()
120 stepResult = cellResult and verifyResult
121 utilities.assert_equals( expect=main.TRUE,
122 actual=stepResult,
123 onpass="Successfully applied cell to " + \
124 "environment",
125 onfail="Failed to apply cell to environment " )
kelvin-onlab4ff9cc12015-05-05 11:14:42 -0700126
127 main.step( "Creating ONOS package" )
128 packageResult = main.ONOSbench.onosPackage()
129 stepResult = packageResult
130 utilities.assert_equals( expect=main.TRUE,
131 actual=stepResult,
132 onpass="Successfully created ONOS package",
133 onfail="Failed to create ONOS package" )
134
135 main.step( "Uninstalling ONOS package" )
kelvin-onlabf70fd542015-05-07 18:41:40 -0700136 onosUninstallResult = main.TRUE
kelvin-onlab05cf7732015-05-08 14:25:46 -0700137 for i in range( main.numCtrls):
kelvin-onlabf70fd542015-05-07 18:41:40 -0700138 onosUninstallResult = onosUninstallResult and \
kelvin-onlab05cf7732015-05-08 14:25:46 -0700139 main.ONOSbench.onosUninstall( nodeIp=main.ONOSip[ i ] )
kelvin-onlab4ff9cc12015-05-05 11:14:42 -0700140 stepResult = onosUninstallResult
141 utilities.assert_equals( expect=main.TRUE,
142 actual=stepResult,
143 onpass="Successfully uninstalled ONOS package",
144 onfail="Failed to uninstall ONOS package" )
145 time.sleep( 5 )
146 main.step( "Installing ONOS package" )
kelvin-onlabf70fd542015-05-07 18:41:40 -0700147 onosInstallResult = main.TRUE
kelvin-onlab05cf7732015-05-08 14:25:46 -0700148 for i in range( main.numCtrls):
kelvin-onlabf70fd542015-05-07 18:41:40 -0700149 onosInstallResult = onosInstallResult and \
kelvin-onlab05cf7732015-05-08 14:25:46 -0700150 main.ONOSbench.onosInstall( node=main.ONOSip[ i ] )
kelvin-onlab4ff9cc12015-05-05 11:14:42 -0700151 stepResult = onosInstallResult
152 utilities.assert_equals( expect=main.TRUE,
153 actual=stepResult,
154 onpass="Successfully installed ONOS package",
155 onfail="Failed to install ONOS package" )
156
kelvin-onlabf70fd542015-05-07 18:41:40 -0700157 time.sleep( 5 )
kelvin-onlab4ff9cc12015-05-05 11:14:42 -0700158 main.step( "Starting ONOS service" )
159 stopResult = main.TRUE
160 startResult = main.TRUE
kelvin-onlabf70fd542015-05-07 18:41:40 -0700161 onosIsUp = main.TRUE
kelvin-onlab05cf7732015-05-08 14:25:46 -0700162 for i in range( main.numCtrls ):
163 onosIsUp = onosIsUp and main.ONOSbench.isup( main.ONOSip[ i ] )
kelvin-onlab4ff9cc12015-05-05 11:14:42 -0700164 if onosIsUp == main.TRUE:
165 main.log.report( "ONOS instance is up and ready" )
166 else:
167 main.log.report( "ONOS instance may not be up, stop and " +
168 "start ONOS again " )
kelvin-onlab05cf7732015-05-08 14:25:46 -0700169 for i in range( main.numCtrls ):
kelvin-onlabf70fd542015-05-07 18:41:40 -0700170 stopResult = stopResult and \
kelvin-onlab05cf7732015-05-08 14:25:46 -0700171 main.ONOSbench.onosStop( main.ONOSip[ i ] )
172 for i in range( main.numCtrls ):
kelvin-onlabf70fd542015-05-07 18:41:40 -0700173 startResult = startResult and \
kelvin-onlab05cf7732015-05-08 14:25:46 -0700174 main.ONOSbench.onosStart( main.ONOSip[ i ] )
kelvin-onlab4ff9cc12015-05-05 11:14:42 -0700175 stepResult = onosIsUp and stopResult and startResult
176 utilities.assert_equals( expect=main.TRUE,
177 actual=stepResult,
178 onpass="ONOS service is ready",
179 onfail="ONOS service did not start properly" )
kelvin-onlabe5239e52015-05-13 14:46:45 -0700180
kelvin-onlab4ff9cc12015-05-05 11:14:42 -0700181 main.step( "Start ONOS cli" )
kelvin-onlabf70fd542015-05-07 18:41:40 -0700182 cliResult = main.TRUE
kelvin-onlab05cf7732015-05-08 14:25:46 -0700183 for i in range( main.numCtrls ):
184 cliResult = cliResult and \
185 main.CLIs[i].startOnosCli( main.ONOSip[ i ] )
kelvin-onlab4ff9cc12015-05-05 11:14:42 -0700186 stepResult = cliResult
187 utilities.assert_equals( expect=main.TRUE,
188 actual=stepResult,
189 onpass="Successfully start ONOS cli",
190 onfail="Failed to start ONOS cli" )
191
192 def CASE11( self, main ):
193 """
kelvin-onlab05cf7732015-05-08 14:25:46 -0700194 Start mininet
kelvin-onlab4ff9cc12015-05-05 11:14:42 -0700195 """
kelvin-onlabe5239e52015-05-13 14:46:45 -0700196 import time
kelvin-onlab05cf7732015-05-08 14:25:46 -0700197 main.log.report( "Start Mininet topology" )
kelvin-onlabe5239e52015-05-13 14:46:45 -0700198 main.case( "Start Mininet topology" )
199 if not main.MNisUp:
200 main.MNisUp = main.TRUE
201 else:
202 main.Mininet1.stopNet()
203 time.sleep( 30 )
kelvin-onlabf70fd542015-05-07 18:41:40 -0700204 main.step( "Starting Mininet Topology" )
205 topoResult = main.Mininet1.startNet( topoFile=topology )
206 stepResult = topoResult
207 utilities.assert_equals( expect=main.TRUE,
208 actual=stepResult,
209 onpass="Successfully loaded topology",
210 onfail="Failed to load topology" )
211 # Exit if topology did not load properly
212 if not topoResult:
213 main.cleanup()
214 main.exit()
215
kelvin-onlab05cf7732015-05-08 14:25:46 -0700216 def CASE12( self, main ):
217 """
218 Assign mastership to controllers
219 """
220 import re
221
kelvin-onlabe5239e52015-05-13 14:46:45 -0700222 main.case( "Assign switches to controllers" )
kelvin-onlab4ff9cc12015-05-05 11:14:42 -0700223 main.step( "Assigning switches to controllers" )
224 assignResult = main.TRUE
kelvin-onlab5cbf9992015-05-05 14:34:07 -0700225 for i in range( 1, ( main.numSwitch + 1 ) ):
kelvin-onlab4ff9cc12015-05-05 11:14:42 -0700226 main.Mininet1.assignSwController( sw=str( i ),
227 count=1,
kelvin-onlab05cf7732015-05-08 14:25:46 -0700228 ip1=main.ONOSip[ 0 ],
229 port1=main.ONOSport[ 0 ] )
kelvin-onlab5cbf9992015-05-05 14:34:07 -0700230 for i in range( 1, ( main.numSwitch + 1 ) ):
kelvin-onlab4ff9cc12015-05-05 11:14:42 -0700231 response = main.Mininet1.getSwController( "s" + str( i ) )
232 print( "Response is " + str( response ) )
kelvin-onlab05cf7732015-05-08 14:25:46 -0700233 if re.search( "tcp:" + main.ONOSip[ 0 ], response ):
kelvin-onlab4ff9cc12015-05-05 11:14:42 -0700234 assignResult = assignResult and main.TRUE
235 else:
236 assignResult = main.FALSE
237 stepResult = assignResult
238 utilities.assert_equals( expect=main.TRUE,
239 actual=stepResult,
240 onpass="Successfully assigned switches" +
241 "to controller",
242 onfail="Failed to assign switches to " +
243 "controller" )
244
kelvin-onlabf70fd542015-05-07 18:41:40 -0700245 def CASE1001( self, main ):
kelvin-onlab7c577e82015-05-07 10:45:16 -0700246 """
kelvin-onlab65782a82015-05-07 14:12:13 -0700247 Add host intents between 2 host:
248 - Discover hosts
249 - Add host intents
250 - Check intents
kelvin-onlabe5239e52015-05-13 14:46:45 -0700251 - Verify flows
kelvin-onlab65782a82015-05-07 14:12:13 -0700252 - Ping hosts
253 - Reroute
254 - Link down
kelvin-onlabe5239e52015-05-13 14:46:45 -0700255 - Verify flows
256 - Check topology
kelvin-onlab65782a82015-05-07 14:12:13 -0700257 - Ping hosts
258 - Link up
kelvin-onlabe5239e52015-05-13 14:46:45 -0700259 - Verify flows
260 - Check topology
kelvin-onlab65782a82015-05-07 14:12:13 -0700261 - Ping hosts
262 - Remove intents
kelvin-onlab7c577e82015-05-07 10:45:16 -0700263 """
264 import time
265 import json
kelvin-onlab65782a82015-05-07 14:12:13 -0700266 import re
267 """
268 Create your item(s) here
269 item = { 'name': '', 'host1':
270 { 'name': '', 'MAC': '00:00:00:00:00:0X',
271 'id':'00:00:00:00:00:0X/-X' } , 'host2':
272 { 'name': '', 'MAC': '00:00:00:00:00:0X',
273 'id':'00:00:00:00:00:0X/-X'}, 'link': { 'switch1': '',
kelvin-onlabe5239e52015-05-13 14:46:45 -0700274 'switch2': '', 'expect':'' } }
kelvin-onlab65782a82015-05-07 14:12:13 -0700275 """
kelvin-onlabe5239e52015-05-13 14:46:45 -0700276
277 # Assert variables - These variable's name|format must be followed
278 # if you want to use the wrapper function
279 assert main, "There is no main"
280 assert main.CLIs, "There is no main.CLIs"
281 assert main.Mininet1, "Mininet handle should be named Mininet1"
282 assert main.numSwitch, "Placed the total number of switch topology in \
283 main.numSwitch"
284
kelvin-onlab65782a82015-05-07 14:12:13 -0700285 # Local variables
kelvin-onlabe5239e52015-05-13 14:46:45 -0700286 ipv4 = { 'name':'IPV4', 'host1':
287 { 'name': 'h1', 'MAC':'00:00:00:00:00:01',
kelvin-onlab65782a82015-05-07 14:12:13 -0700288 'id':'00:00:00:00:00:01/-1' } , 'host2':
kelvin-onlabe5239e52015-05-13 14:46:45 -0700289 { 'name':'h9', 'MAC':'00:00:00:00:00:09',
290 'id':'00:00:00:00:00:09/-1'}, 'link': { 'switch1':'s5',
291 'switch2':'s2', 'expect':'18' } }
292 dualStack1 = { 'name':'DUALSTACK1', 'host1':
293 { 'name':'h3', 'MAC':'00:00:00:00:00:03',
kelvin-onlab65782a82015-05-07 14:12:13 -0700294 'id':'00:00:00:00:00:03/-1' } , 'host2':
kelvin-onlabe5239e52015-05-13 14:46:45 -0700295 { 'name':'h11', 'MAC':'00:00:00:00:00:0B',
296 'id':'00:00:00:00:00:0B/-1'}, 'link': { 'switch1':'s5',
297 'switch2':'s2', 'expect':'18' } }
kelvin-onlab7c577e82015-05-07 10:45:16 -0700298
kelvin-onlabe5239e52015-05-13 14:46:45 -0700299 main.case( "Add host intents between 2 host" )
kelvin-onlab05cf7732015-05-08 14:25:46 -0700300
kelvin-onlabe5239e52015-05-13 14:46:45 -0700301 stepResult = main.TRUE
302 main.step( ipv4[ 'name' ] + ": Add host intents between " +
303 ipv4[ 'host1' ][ 'name' ] + " and " +
304 ipv4[ 'host2' ][ 'name' ] )
305 stepResult = main.wrapper.addHostIntent( main, ipv4 )
306 utilities.assert_equals( expect=main.TRUE,
307 actual=stepResult,
308 onpass=ipv4[ 'name' ] +
309 ": Add host intent successful",
310 onfail=ipv4[ 'name' ] +
311 ": Add host intent failed" )
kelvin-onlab7c577e82015-05-07 10:45:16 -0700312
kelvin-onlabe5239e52015-05-13 14:46:45 -0700313 stepResult = main.TRUE
314 main.step( dualStack1[ 'name' ] + ": Add host intents between " +
315 dualStack1[ 'host1' ][ 'name' ] + " and " +
316 dualStack1[ 'host2' ][ 'name' ] )
317 stepResult = main.wrapper.addHostIntent( main, dualStack1 )
318 utilities.assert_equals( expect=main.TRUE,
319 actual=stepResult,
320 onpass=dualStack1[ 'name' ] +
321 ": Add host intent successful",
322 onfail=dualStack1[ 'name' ] +
323 ": Add host intent failed" )
kelvin-onlab7c577e82015-05-07 10:45:16 -0700324
kelvin-onlabf70fd542015-05-07 18:41:40 -0700325 def CASE1002( self, main ):
kelvin-onlab65782a82015-05-07 14:12:13 -0700326 """
327 Add point intents between 2 hosts:
kelvin-onlabe5239e52015-05-13 14:46:45 -0700328 - Get device ids | ports
kelvin-onlab65782a82015-05-07 14:12:13 -0700329 - Add point intents
330 - Check intents
kelvin-onlabe5239e52015-05-13 14:46:45 -0700331 - Verify flows
kelvin-onlab65782a82015-05-07 14:12:13 -0700332 - Ping hosts
333 - Reroute
334 - Link down
kelvin-onlabe5239e52015-05-13 14:46:45 -0700335 - Verify flows
336 - Check topology
kelvin-onlab65782a82015-05-07 14:12:13 -0700337 - Ping hosts
338 - Link up
kelvin-onlabe5239e52015-05-13 14:46:45 -0700339 - Verify flows
340 - Check topology
kelvin-onlab65782a82015-05-07 14:12:13 -0700341 - Ping hosts
342 - Remove intents
343 """
kelvin-onlabe5239e52015-05-13 14:46:45 -0700344 import time
345 import json
346 import re
347 """
348 Create your item(s) here
349 item = { 'name':'', 'ingress':'' , 'egress':'',
350 'option':{ 'ethType':'', 'ethSrc':'', 'ethDst':'' } ,
351 'link': { 'switch1': '', 'switch2':'', 'expect':'' } }
352
353 """
354
355 # Assert variables - These variable's name|format must be followed
356 # if you want to use the wrapper function
357 assert main, "There is no main"
358 assert main.CLIs, "There is no main.CLIs"
359 assert main.Mininet1, "Mininet handle should be named Mininet1"
360 assert main.numSwitch, "Placed the total number of switch topology in \
361 main.numSwitch"
362
363
364 ipv4 = { 'name':'IPV4', 'ingress':'0000000000000005/1' ,
365 'egress':'0000000000000006/1', 'option':
366 { 'ethType':'IPV4', 'ethSrc':'00:00:00:00:00:01',
367 'ethDst':'00:00:00:00:00:09' }, 'link': { 'switch1':'s5',
368 'switch2':'s2', 'expect':'18' } }
369
370 dualStack1 = { 'name':'DUALSTACK1', 'ingress':'0000000000000005/3' ,
371 'egress':'0000000000000006/3', 'option':
372 { 'ethType':'IPV4', 'ethSrc':'00:00:00:00:00:03',
373 'ethDst':'00:00:00:00:00:0B' }, 'link': { 'switch1':'s5',
374 'switch2':'s2', 'expect':'18' } }
375
376 main.wrapper.addPointIntent( main, ipv4 )
kelvin-onlab65782a82015-05-07 14:12:13 -0700377
kelvin-onlabf70fd542015-05-07 18:41:40 -0700378 def CASE1003( self, main ):
kelvin-onlab65782a82015-05-07 14:12:13 -0700379 """
380 Add single point to multi point intents
381 - Get device ids
382 - Add single point to multi point intents
383 - Check intents
kelvin-onlabe5239e52015-05-13 14:46:45 -0700384 - Verify flows
kelvin-onlab65782a82015-05-07 14:12:13 -0700385 - Ping hosts
386 - Reroute
387 - Link down
kelvin-onlabe5239e52015-05-13 14:46:45 -0700388 - Verify flows
389 - Check topology
kelvin-onlab65782a82015-05-07 14:12:13 -0700390 - Ping hosts
391 - Link up
kelvin-onlabe5239e52015-05-13 14:46:45 -0700392 - Verify flows
393 - Check topology
kelvin-onlab65782a82015-05-07 14:12:13 -0700394 - Ping hosts
395 - Remove intents
396 """
397
kelvin-onlabf70fd542015-05-07 18:41:40 -0700398 def CASE1004( self, main ):
kelvin-onlab65782a82015-05-07 14:12:13 -0700399 """
400 Add multi point to single point intents
401 - Get device ids
402 - Add multi point to single point intents
403 - Check intents
kelvin-onlabe5239e52015-05-13 14:46:45 -0700404 - Verify flows
kelvin-onlab65782a82015-05-07 14:12:13 -0700405 - Ping hosts
406 - Reroute
407 - Link down
kelvin-onlabe5239e52015-05-13 14:46:45 -0700408 - Verify flows
409 - Check topology
kelvin-onlab65782a82015-05-07 14:12:13 -0700410 - Ping hosts
411 - Link up
kelvin-onlabe5239e52015-05-13 14:46:45 -0700412 - Verify flows
413 - Check topology
kelvin-onlab65782a82015-05-07 14:12:13 -0700414 - Ping hosts
415 - Remove intents
416 """