blob: 89a7e32d08ac92aa71980d2e521fd6441775f7c2 [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
GlennRC68449942015-10-16 16:03:12 -0700206 def CASE10( self, main ):
207 '''
208 Start Mininet
209 '''
210 main.case( "Setup mininet and assign switches to controllers" )
211 main.step( "Setup Mininet Topology" )
212 topology = main.Mininet1.home + '/custom/' + main.topology
213 mnCmd = 'mn --custom ' + topology + ' --mac --arp'
214 stepResult1 = main.Mininet1.startNet( mnCmd=mnCmd )
215
216 utilities.assert_equals( expect=main.TRUE,
217 actual=stepResult1,
218 onpass="Successfully loaded topology",
219 onfail="Failed to load topology" )
220
221 main.step( "Assign switches to controllers" )
222 for i in range( main.numSwitches ):
223 stepResult2 = main.Mininet1.assignSwController(
224 sw="s" + str( i+1 ),
225 ip=main.ONOSip )
226 if not stepResult2:
227 break
228
229 utilities.assert_equals( expect=main.TRUE,
230 actual=stepResult2,
231 onpass="Controller assignment successfull",
232 onfail="Controller assignment failed" )
233
234 time.sleep(5)
235
236 caseResult = stepResult1 and stepResult2
237 if not caseResult:
238 main.cleanup()
239 main.exit()
240
241 def CASE11( self, main ):
GlennRC5147a422015-10-06 17:26:17 -0700242 '''
243 Compare topology
244 '''
GlennRC1704d072015-10-07 18:40:45 -0700245 import json
246
247 main.case( "Compare ONOS Topology view to Mininet topology" )
248 main.caseExplanation = "Compare topology elements between Mininet" +\
249 " and ONOS"
250
251 main.step( "Gathering topology information" )
252 # TODO: add a paramaterized sleep here
253 devicesResults = main.TRUE
254 linksResults = main.TRUE
255 hostsResults = main.TRUE
256 devices = main.topo.getAllDevices( main )
257 hosts = main.topo.getAllHosts( main )
258 ports = main.topo.getAllPorts( main )
259 links = main.topo.getAllLinks( main )
260 clusters = main.topo.getAllClusters( main )
261
262 mnSwitches = main.Mininet1.getSwitches()
263 mnLinks = main.Mininet1.getLinks()
264 mnHosts = main.Mininet1.getHosts()
265
266 main.step( "Conmparing MN topology to ONOS topology" )
267 for controller in range( main.numCtrls ):
268 controllerStr = str( controller + 1 )
269 if devices[ controller ] and ports[ controller ] and\
270 "Error" not in devices[ controller ] and\
271 "Error" not in ports[ controller ]:
272
273 currentDevicesResult = main.Mininet1.compareSwitches(
274 mnSwitches,
275 json.loads( devices[ controller ] ),
276 json.loads( ports[ controller ] ) )
277 else:
278 currentDevicesResult = main.FALSE
279 utilities.assert_equals( expect=main.TRUE,
280 actual=currentDevicesResult,
281 onpass="ONOS" + controllerStr +
GlennRC68449942015-10-16 16:03:12 -0700282 " Switches view is correct",
GlennRC1704d072015-10-07 18:40:45 -0700283 onfail="ONOS" + controllerStr +
GlennRC68449942015-10-16 16:03:12 -0700284 " Switches view is incorrect" )
GlennRC1704d072015-10-07 18:40:45 -0700285 if links[ controller ] and "Error" not in links[ controller ]:
286 currentLinksResult = main.Mininet1.compareLinks(
287 mnSwitches, mnLinks,
288 json.loads( links[ controller ] ) )
289 else:
290 currentLinksResult = main.FALSE
291 utilities.assert_equals( expect=main.TRUE,
292 actual=currentLinksResult,
293 onpass="ONOS" + controllerStr +
GlennRC68449942015-10-16 16:03:12 -0700294 " links view is correct",
GlennRC1704d072015-10-07 18:40:45 -0700295 onfail="ONOS" + controllerStr +
GlennRC68449942015-10-16 16:03:12 -0700296 " links view is incorrect" )
GlennRC1704d072015-10-07 18:40:45 -0700297
298 if hosts[ controller ] or "Error" not in hosts[ controller ]:
299 currentHostsResult = main.Mininet1.compareHosts(
300 mnHosts,
301 json.loads( hosts[ controller ] ) )
302 else:
303 currentHostsResult = main.FALSE
304 utilities.assert_equals( expect=main.TRUE,
305 actual=currentHostsResult,
306 onpass="ONOS" + controllerStr +
GlennRC68449942015-10-16 16:03:12 -0700307 " hosts exist in Mininet",
GlennRC1704d072015-10-07 18:40:45 -0700308 onfail="ONOS" + controllerStr +
GlennRC68449942015-10-16 16:03:12 -0700309 " hosts don't match Mininet")
GlennRCa5391372015-10-14 17:28:15 -0700310
GlennRC68449942015-10-16 16:03:12 -0700311
312
Jon Hall892818c2015-10-20 17:58:34 -0700313 def CASE66( self, main ):
314 '''
315 Testing scapy
316 '''
317 main.case( "Testing scapy" )
318 main.step( "Creating Host1 component" )
319 main.Mininet1.createHostComponent( "h1" )
320 main.Mininet1.createHostComponent( "h2" )
321 hosts = [main.h1, main.h2]
322 for host in hosts:
323 host.startHostCli()
324 host.startScapy()
325 host.updateSelf()
326 main.log.debug( host.name )
327 main.log.debug( host.hostIp )
328 main.log.debug( host.hostMac )
329
330 main.step( "Sending/Receiving Test packet - Filter doesn't match" )
331 main.h2.startFilter()
332 main.h1.buildEther( dst=main.h2.hostMac )
333 main.h1.sendPacket( )
334 finished = main.h2.checkFilter()
335 i = ""
336 if finished:
337 a = main.h2.readPackets()
338 for i in a.splitlines():
339 main.log.info( i )
340 else:
341 kill = main.h2.killFilter()
342 main.log.debug( kill )
343 main.h2.handle.sendline( "" )
344 main.h2.handle.expect( main.h2.scapyPrompt )
345 main.log.debug( main.h2.handle.before )
346 utilities.assert_equals( expect=True,
347 actual="dst=00:00:00:00:00:02 src=00:00:00:00:00:01" in i,
348 onpass="Pass",
349 onfail="Fail" )
350
351 main.step( "Sending/Receiving Test packet - Filter matches" )
352 main.h2.startFilter()
353 main.h1.buildEther( dst=main.h2.hostMac )
354 main.h1.buildIP( dst=main.h2.hostIp )
355 main.h1.sendPacket( )
356 finished = main.h2.checkFilter()
357 i = ""
358 if finished:
359 a = main.h2.readPackets()
360 for i in a.splitlines():
361 main.log.info( i )
362 else:
363 kill = main.h2.killFilter()
364 main.log.debug( kill )
365 main.h2.handle.sendline( "" )
366 main.h2.handle.expect( main.h2.scapyPrompt )
367 main.log.debug( main.h2.handle.before )
368 utilities.assert_equals( expect=True,
369 actual="dst=00:00:00:00:00:02 src=00:00:00:00:00:01" in i,
370 onpass="Pass",
371 onfail="Fail" )
372
373
374
375 main.step( "Clean up host components" )
376 for host in hosts:
377 host.stopScapy()
378 main.Mininet1.removeHostComponent("h1")
379 main.Mininet1.removeHostComponent("h2")
380
GlennRC68449942015-10-16 16:03:12 -0700381 def CASE1000( self, main ):
382 '''
383 Add flows
384 '''
385
386 main.step("Add flows through rest")
387
388 deviceId = main.params['MININET']['deviceId']
389 host1_mac = main.params['MININET']['hostMac1']
390 host2_mac = main.params['MININET']['hostMac2']
391
392 # Add flows that connects host1 to host 2
393 stepResult = main.ONOSrest.addFlow( deviceId=deviceId,
394 egressPort=2,
395 ingressPort=1,
396 ethSrc=host1_mac,
397 ethDst=host2_mac)
398
399 stepResult = stepResult and main.ONOSrest.addFlow( deviceId=deviceId,
400 egressPort=1,
401 ingressPort=2,
402 ethSrc=host2_mac,
403 ethDst=host1_mac)
404
GlennRCa5391372015-10-14 17:28:15 -0700405 utilities.assert_equals( expect=main.TRUE,
406 actual=stepResult,
GlennRC68449942015-10-16 16:03:12 -0700407 onpass="Successfully added flows",
408 onfail="Failed add flows" )
GlennRCa5391372015-10-14 17:28:15 -0700409
GlennRC68449942015-10-16 16:03:12 -0700410 def CASE2000( self, main ):
411 '''
412 Check flows are ADDED
413 '''
414 import json
415 main.step("Check flows are in the ADDED state")
416 main.log.info("Check only the flows added through REST")
GlennRC5147a422015-10-06 17:26:17 -0700417
GlennRC68449942015-10-16 16:03:12 -0700418 flows = json.loads( main.ONOSrest.flows() )
419
420 stepResult = main.TRUE
421 for f in flows:
422 if "rest" in f.get("appId"):
423 if "ADDED" in f.get("state"):
424 stepResult = stepResult and main.ONOSrest.removeFlow( deviceId, flowId )
425
426 utilities.assert_equals( expect=main.TRUE,
427 actual=stepResult,
428 onpass="All flows are in the ADDED state",
429 onfail="All flows are in the ADDED state" )
430
431 def CASE3000( self, main ):
432 '''
433 Delete flows that were added through REST
434 '''
435 import json
436 main.step("Remove flows")
437 main.log.info("Remove the flows that were added through rest")
438
439 flows = json.loads( main.ONOSrest.flows() )
440
441 stepResult = main.TRUE
442 for f in flows:
443 if "rest" in f.get("appId"):
444 flowId = f.get("id")
445 deviceId = f.get("deviceId")
446 stepResult = stepResult and main.ONOSrest.removeFlow( deviceId, flowId )
447
448 utilities.assert_equals( expect=main.TRUE,
449 actual=stepResult,
450 onpass="Successfully removed all rest flows",
451 onfail="Failed to remove rest flows" )
452
453 def CASE100( self, main ):
GlennRC5147a422015-10-06 17:26:17 -0700454 '''
455 Report errors/warnings/exceptions
456 '''
457 main.log.info("Error report: \n" )
458 main.ONOSbench.logReport( main.ONOSip[ 0 ],
459 [ "INFO",
460 "FOLLOWER",
461 "WARN",
462 "flow",
463 "ERROR",
464 "Except" ],
GlennRC68449942015-10-16 16:03:12 -0700465 "s" )
GlennRC5147a422015-10-06 17:26:17 -0700466