blob: 74c3464db111be6ed3a1254572c65d82bc93220f [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 +
274 " hosts don't match Mininet" )
GlennRC5147a422015-10-06 17:26:17 -0700275
276 def CASE9( self, main ):
277 '''
278 Report errors/warnings/exceptions
279 '''
280 main.log.info("Error report: \n" )
281 main.ONOSbench.logReport( main.ONOSip[ 0 ],
282 [ "INFO",
283 "FOLLOWER",
284 "WARN",
285 "flow",
286 "ERROR",
287 "Except" ],
GlennRC1704d072015-10-07 18:40:45 -0700288 "s" )
GlennRC5147a422015-10-06 17:26:17 -0700289
290 def CASE10( self, main ):
291 '''
GlennRC94ed2232015-10-07 15:08:57 -0700292 Start Mininet with
GlennRC5147a422015-10-06 17:26:17 -0700293 '''
GlennRC94ed2232015-10-07 15:08:57 -0700294 main.case( "Setup mininet and assign switches to controllers" )
295 main.step( "Setup Mininet Topology" )
296 topology = main.Mininet1.home + '/custom/' + main.topology
297 stepResult1 = main.Mininet1.startNet( topoFile=topology )
GlennRC5147a422015-10-06 17:26:17 -0700298
GlennRC94ed2232015-10-07 15:08:57 -0700299 utilities.assert_equals( expect=main.TRUE,
300 actual=stepResult1,
301 onpass="Successfully loaded topology",
302 onfail="Failed to load topology" )
303
304 main.step( "Assign switches to controllers" )
305 for i in range( main.numSwitches ):
306 stepResult2 = main.Mininet1.assignSwController(
307 sw="s" + str( i+1 ),
308 ip=main.ONOSip )
309 if not stepResult2:
310 break
311
312 utilities.assert_equals( expect=main.TRUE,
313 actual=stepResult2,
314 onpass="Controller assignment successfull",
315 onfail="Controller assignment failed" )
316
GlennRC1704d072015-10-07 18:40:45 -0700317 time.sleep(5)
318
319 main.step( "Pingall hosts for discovery" )
320 stepResult3 = main.Mininet1.pingall()
321 if not stepResult3:
322 stepResult3 = main.Mininet1.pingall()
323 utilities.assert_equals( expect=main.TRUE,
324 actual=stepResult3,
325 onpass="Pingall successfull",
326 onfail="Pingall unsuccessfull" )
327
328 caseResult = stepResult1 and stepResult2 and stepResult3
GlennRC94ed2232015-10-07 15:08:57 -0700329 if not caseResult:
330 main.cleanup()
331 main.exit()
GlennRC5147a422015-10-06 17:26:17 -0700332
333 def CASE1000( self, main ):
334 '''
335 Add flows
336 '''
337
338 def CASE2000( self, main ):
339 '''
340 Delete flows
341 '''
342
343 def CASE3000( self, main ):
344 '''
345 Modify flow rule selectors
346 '''
347
348 def CASE4000( self, main ):
349 '''
350 Modify flow rule treatment
351 '''
352
353 def CASE5000( self, main ):
354 '''
355 Modify flow rule controller
356 '''
357
358 def CASE100( self, main ):
359 '''
360 Compare switch flow table with ONOS
361 '''
362