blob: 30608a6a2690b146dec4501d9f8a5bfca24079f8 [file] [log] [blame]
GlennRC5147a422015-10-06 17:26:17 -07001class FUNCflow:
2
3 def __init__( self ):
4 self.default = ''
5
6 def CASE1( self, main ):
7 import time
8 import os
9 import imp
10
11 """
12 - Construct tests variables
13 - GIT ( optional )
14 - Checkout ONOS master branch
15 - Pull latest ONOS code
16 - Building ONOS ( optional )
17 - Install ONOS package
18 - Build ONOS package
19 """
20
21 main.case( "Constructing test variables and building ONOS package" )
22 main.step( "Constructing test variables" )
23 stepResult = main.FALSE
24
25 # Test variables
26 main.testOnDirectory = os.path.dirname( os.getcwd ( ) )
27 main.cellName = main.params[ 'ENV' ][ 'cellName' ]
28 main.apps = main.params[ 'ENV' ][ 'cellApps' ]
29 gitBranch = main.params[ 'GIT' ][ 'branch' ]
30 main.dependencyPath = main.testOnDirectory + \
31 main.params[ 'DEPENDENCY' ][ 'path' ]
32 main.topology = main.params[ 'DEPENDENCY' ][ 'topology' ]
33 main.maxNodes = int( main.params[ 'SCALE' ][ 'max' ] )
34 main.ONOSport = main.params[ 'CTRL' ][ 'port' ]
GlennRC94ed2232015-10-07 15:08:57 -070035 main.numSwitches = int( main.params[ 'TOPO' ][ 'numSwitches' ] )
36 main.numHosts = int( main.params[ 'TOPO' ][ 'numHosts' ] )
37 main.numLinks = int( main.params[ 'TOPO' ][ 'numLinks' ] )
GlennRC5147a422015-10-06 17:26:17 -070038 wrapperFile1 = main.params[ 'DEPENDENCY' ][ 'wrapper1' ]
GlennRC1704d072015-10-07 18:40:45 -070039 wrapperFile2 = main.params[ 'DEPENDENCY' ][ 'wrapper2' ]
GlennRC5147a422015-10-06 17:26:17 -070040 main.startUpSleep = int( main.params[ 'SLEEP' ][ 'startup' ] )
41 gitPull = main.params[ 'GIT' ][ 'pull' ]
42 main.cellData = {} # for creating cell file
43 main.CLIs = []
44 main.ONOSip = []
45
46 main.ONOSip = main.ONOSbench.getOnosIps()
47 print main.ONOSip
48
49 # Assigning ONOS cli handles to a list
50 for i in range( 1, main.maxNodes + 1 ):
51 main.CLIs.append( getattr( main, 'ONOScli' + str( i ) ) )
52
53 # -- INIT SECTION, ONLY RUNS ONCE -- #
54 main.startUp = imp.load_source( wrapperFile1,
55 main.dependencyPath +
56 wrapperFile1 +
57 ".py" )
58
GlennRC1704d072015-10-07 18:40:45 -070059 main.topo = imp.load_source( wrapperFile2,
60 main.dependencyPath +
61 wrapperFile2 +
62 ".py" )
63
GlennRC94ed2232015-10-07 15:08:57 -070064 copyResult = main.ONOSbench.scp( main.Mininet1,
65 main.dependencyPath+main.topology,
66 main.Mininet1.home+'/custom/',
67 direction="to" )
68
GlennRC5147a422015-10-06 17:26:17 -070069 if main.CLIs:
70 stepResult = main.TRUE
71 else:
72 main.log.error( "Did not properly created list of ONOS CLI handle" )
73 stepResult = main.FALSE
74
75 utilities.assert_equals( expect=main.TRUE,
76 actual=stepResult,
77 onpass="Successfully construct " +
78 "test variables ",
79 onfail="Failed to construct test variables" )
80
81 if gitPull == 'True':
82 main.step( "Building ONOS in " + gitBranch + " branch" )
83 onosBuildResult = main.startUp.onosBuild( main, gitBranch )
84 stepResult = onosBuildResult
85 utilities.assert_equals( expect=main.TRUE,
86 actual=stepResult,
87 onpass="Successfully compiled " +
88 "latest ONOS",
89 onfail="Failed to compile " +
90 "latest ONOS" )
91 else:
92 main.log.warn( "Did not pull new code so skipping mvn " +
93 "clean install" )
94
95 def CASE2( self, main ):
96 """
97 - Set up cell
98 - Create cell file
99 - Set cell file
100 - Verify cell file
101 - Kill ONOS process
102 - Uninstall ONOS cluster
103 - Verify ONOS start up
104 - Install ONOS cluster
105 - Connect to cli
106 """
107
108 main.numCtrls = int( main.maxNodes )
109
110 main.case( "Starting up " + str( main.numCtrls ) +
111 " node(s) ONOS cluster" )
112
113 #kill off all onos processes
114 main.log.info( "Safety check, killing all ONOS processes" +
115 " before initiating enviornment setup" )
116
117 for i in range( main.maxNodes ):
118 main.ONOSbench.onosDie( main.ONOSip[ i ] )
119
120 print "NODE COUNT = ", main.numCtrls
121
122 tempOnosIp = []
123 for i in range( main.numCtrls ):
124 tempOnosIp.append( main.ONOSip[i] )
125
126 main.ONOSbench.createCellFile( main.ONOSbench.ip_address, "temp", main.Mininet1.ip_address, main.apps, tempOnosIp )
127
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,
134 onpass="Successfully applied cell to " + \
135 "environment",
136 onfail="Failed to apply cell to environment " )
137
138 main.step( "Creating ONOS package" )
139 packageResult = main.ONOSbench.onosPackage()
140 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 i in range( main.numCtrls ):
150 onosUninstallResult = onosUninstallResult and \
151 main.ONOSbench.onosUninstall( nodeIp=main.ONOSip[ i ] )
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
161 for i in range( main.numCtrls ):
162 onosInstallResult = onosInstallResult and \
163 main.ONOSbench.onosInstall( node=main.ONOSip[ i ] )
164 stepResult = onosInstallResult
165 utilities.assert_equals( expect=main.TRUE,
166 actual=stepResult,
167 onpass="Successfully installed ONOS package",
168 onfail="Failed to install ONOS package" )
169
170 time.sleep( main.startUpSleep )
171 main.step( "Starting ONOS service" )
172 stopResult = main.TRUE
173 startResult = main.TRUE
174 onosIsUp = main.TRUE
175
176 for i in range( main.numCtrls ):
177 onosIsUp = onosIsUp and main.ONOSbench.isup( main.ONOSip[ i ] )
178 if onosIsUp == main.TRUE:
179 main.log.report( "ONOS instance is up and ready" )
180 else:
181 main.log.report( "ONOS instance may not be up, stop and " +
182 "start ONOS again " )
183 for i in range( main.numCtrls ):
184 stopResult = stopResult and \
185 main.ONOSbench.onosStop( main.ONOSip[ i ] )
186 for i in range( main.numCtrls ):
187 startResult = startResult and \
188 main.ONOSbench.onosStart( main.ONOSip[ i ] )
189 stepResult = onosIsUp and stopResult and startResult
190 utilities.assert_equals( expect=main.TRUE,
191 actual=stepResult,
192 onpass="ONOS service is ready",
193 onfail="ONOS service did not start properly" )
194
195 main.step( "Start ONOS cli" )
196 cliResult = main.TRUE
197 for i in range( main.numCtrls ):
198 cliResult = cliResult and \
199 main.CLIs[ i ].startOnosCli( main.ONOSip[ i ] )
200 stepResult = cliResult
201 utilities.assert_equals( expect=main.TRUE,
202 actual=stepResult,
203 onpass="Successfully start ONOS cli",
204 onfail="Failed to start ONOS cli" )
205
206 def CASE8( self, main ):
207 '''
208 Compare topology
209 '''
GlennRC1704d072015-10-07 18:40:45 -0700210 import json
211
212 main.case( "Compare ONOS Topology view to Mininet topology" )
213 main.caseExplanation = "Compare topology elements between Mininet" +\
214 " and ONOS"
215
216 main.step( "Gathering topology information" )
217 # TODO: add a paramaterized sleep here
218 devicesResults = main.TRUE
219 linksResults = main.TRUE
220 hostsResults = main.TRUE
221 devices = main.topo.getAllDevices( main )
222 hosts = main.topo.getAllHosts( main )
223 ports = main.topo.getAllPorts( main )
224 links = main.topo.getAllLinks( main )
225 clusters = main.topo.getAllClusters( main )
226
227 mnSwitches = main.Mininet1.getSwitches()
228 mnLinks = main.Mininet1.getLinks()
229 mnHosts = main.Mininet1.getHosts()
230
231 main.step( "Conmparing MN topology to ONOS topology" )
232 for controller in range( main.numCtrls ):
233 controllerStr = str( controller + 1 )
234 if devices[ controller ] and ports[ controller ] and\
235 "Error" not in devices[ controller ] and\
236 "Error" not in ports[ controller ]:
237
238 currentDevicesResult = main.Mininet1.compareSwitches(
239 mnSwitches,
240 json.loads( devices[ controller ] ),
241 json.loads( ports[ controller ] ) )
242 else:
243 currentDevicesResult = main.FALSE
244 utilities.assert_equals( expect=main.TRUE,
245 actual=currentDevicesResult,
246 onpass="ONOS" + controllerStr +
247 " Switches view is correct",
248 onfail="ONOS" + controllerStr +
249 " Switches view is incorrect" )
250 if links[ controller ] and "Error" not in links[ controller ]:
251 currentLinksResult = main.Mininet1.compareLinks(
252 mnSwitches, mnLinks,
253 json.loads( links[ controller ] ) )
254 else:
255 currentLinksResult = main.FALSE
256 utilities.assert_equals( expect=main.TRUE,
257 actual=currentLinksResult,
258 onpass="ONOS" + controllerStr +
259 " links view is correct",
260 onfail="ONOS" + controllerStr +
261 " links view is incorrect" )
262
263 if hosts[ controller ] or "Error" not in hosts[ controller ]:
264 currentHostsResult = main.Mininet1.compareHosts(
265 mnHosts,
266 json.loads( hosts[ controller ] ) )
267 else:
268 currentHostsResult = main.FALSE
269 utilities.assert_equals( expect=main.TRUE,
270 actual=currentHostsResult,
271 onpass="ONOS" + controllerStr +
272 " hosts exist in Mininet",
273 onfail="ONOS" + controllerStr +
GlennRCa5391372015-10-14 17:28:15 -0700274 " hosts don't match Mininet")
275
276 main.step( "Deactiviate reactive fwd" )
277 stepResult = main.CLIs[0].deactivateApp( 'org.onosproject.fwd' )
278 utilities.assert_equals( expect=main.TRUE,
279 actual=stepResult,
280 onpass="Successfully deactived fwd app",
281 onfail="Failed to deactivate fwd app" )
282
283 main.log.info("Wait for the flows to dissappear")
284 time.sleep(5)
GlennRC5147a422015-10-06 17:26:17 -0700285
286 def CASE9( self, main ):
287 '''
288 Report errors/warnings/exceptions
289 '''
290 main.log.info("Error report: \n" )
291 main.ONOSbench.logReport( main.ONOSip[ 0 ],
292 [ "INFO",
293 "FOLLOWER",
294 "WARN",
295 "flow",
296 "ERROR",
297 "Except" ],
GlennRC1704d072015-10-07 18:40:45 -0700298 "s" )
GlennRC5147a422015-10-06 17:26:17 -0700299
300 def CASE10( self, main ):
301 '''
GlennRCa5391372015-10-14 17:28:15 -0700302 Start Mininet
GlennRC5147a422015-10-06 17:26:17 -0700303 '''
GlennRC94ed2232015-10-07 15:08:57 -0700304 main.case( "Setup mininet and assign switches to controllers" )
305 main.step( "Setup Mininet Topology" )
306 topology = main.Mininet1.home + '/custom/' + main.topology
307 stepResult1 = main.Mininet1.startNet( topoFile=topology )
GlennRC5147a422015-10-06 17:26:17 -0700308
GlennRC94ed2232015-10-07 15:08:57 -0700309 utilities.assert_equals( expect=main.TRUE,
310 actual=stepResult1,
311 onpass="Successfully loaded topology",
312 onfail="Failed to load topology" )
313
314 main.step( "Assign switches to controllers" )
315 for i in range( main.numSwitches ):
316 stepResult2 = main.Mininet1.assignSwController(
317 sw="s" + str( i+1 ),
318 ip=main.ONOSip )
319 if not stepResult2:
320 break
321
322 utilities.assert_equals( expect=main.TRUE,
323 actual=stepResult2,
324 onpass="Controller assignment successfull",
325 onfail="Controller assignment failed" )
326
GlennRC1704d072015-10-07 18:40:45 -0700327 time.sleep(5)
328
329 main.step( "Pingall hosts for discovery" )
330 stepResult3 = main.Mininet1.pingall()
331 if not stepResult3:
332 stepResult3 = main.Mininet1.pingall()
333 utilities.assert_equals( expect=main.TRUE,
334 actual=stepResult3,
335 onpass="Pingall successfull",
336 onfail="Pingall unsuccessfull" )
337
338 caseResult = stepResult1 and stepResult2 and stepResult3
GlennRC94ed2232015-10-07 15:08:57 -0700339 if not caseResult:
340 main.cleanup()
341 main.exit()
GlennRC5147a422015-10-06 17:26:17 -0700342
343 def CASE1000( self, main ):
344 '''
345 Add flows
346 '''
347
GlennRCa5391372015-10-14 17:28:15 -0700348 main.step("Add some flows")
349
350 deviceId = main.params['TOPO']['deviceId']
351 host1_mac = main.params['TOPO']['hostMac1']
352 host2_mac = main.params['TOPO']['hostMac2']
353
354
355 flowResult1 = main.ONOSrest.addFlow( deviceId=deviceId,
356 egressPort=-3,
357 ethType="IPV4" )
358
359 flowResult2 = main.ONOSrest.addFlow( deviceId=deviceId,
360 egressPort=2,
361 ingressPort=1,
362 ethSrc=host1_mac,
363 ethDst=host2_mac)
364
365 flowResult3 = main.ONOSrest.addFlow( deviceId=deviceId,
366 egressPort=1,
367 ingressPort=2,
368 ethSrc=host2_mac,
369 ethDst=host1_mac)
370
371 flowResult = flowResult1 and flowResult2 and flowResult3
372
373 utilities.assert_equals( expect=main.TRUE,
374 actual=flowResult,
375 onpass="Successfully added flows",
376 onfail="Failed add flows" )
377
378 main.step("Verify flows with pingall")
379 main.log.info("wait for flows to install")
380 time.sleep(5)
381
382 pingResult = main.Mininet1.pingall()
383 if not pingResult:
384 main.log.warn("First pingall failed. Retrying")
385 pingResult = main.Mininet1.pingall()
386
387 utilities.assert_equals( expect=main.TRUE,
388 actual=pingResult,
389 onpass="Pingall successfull",
390 onfail="Pingall failed" )
391
392 time.sleep(100)
393
GlennRC5147a422015-10-06 17:26:17 -0700394 def CASE2000( self, main ):
395 '''
396 Delete flows
397 '''
398
399 def CASE3000( self, main ):
400 '''
401 Modify flow rule selectors
402 '''
403
404 def CASE4000( self, main ):
405 '''
406 Modify flow rule treatment
407 '''
408
409 def CASE5000( self, main ):
410 '''
411 Modify flow rule controller
412 '''
413
414 def CASE100( self, main ):
415 '''
416 Compare switch flow table with ONOS
417 '''