blob: fc2dd6248b90a1494698e6752c1cf2f81962388f [file] [log] [blame]
kavitha Alagesan373e0552016-11-22 05:22:05 +05301class FUNCgroup:
2
3 def __init__( self ):
4 self.default = ''
5
6 def CASE1( self, main ):
7 import os
8 import imp
9
10 """
11 - Construct tests variables
12 - GIT ( optional )
13 - Checkout ONOS master branch
14 - Pull latest ONOS code
15 - Building ONOS ( optional )
16 - Install ONOS package
17 - Build ONOS package
18 """
19 main.case( "Constructing test variables and building ONOS package" )
20 main.step( "Constructing test variables" )
21
22 # Test variables
Jon Hall602d0a72017-05-24 16:06:53 -070023 main.testOnDirectory = os.path.dirname( os.getcwd() )
kavitha Alagesan373e0552016-11-22 05:22:05 +053024 main.cellName = main.params[ 'ENV' ][ 'cellName' ]
25 main.apps = main.params[ 'ENV' ][ 'cellApps' ]
26 gitBranch = main.params[ 'GIT' ][ 'branch' ]
27 gitPull = main.params[ 'GIT' ][ 'pull' ]
28 main.ONOSport = main.params[ 'CTRL' ][ 'port' ]
29 main.dependencyPath = main.testOnDirectory + \
30 main.params[ 'DEPENDENCY' ][ 'path' ]
31 wrapperFile1 = main.params[ 'DEPENDENCY' ][ 'wrapper1' ]
32 wrapperFile2 = main.params[ 'DEPENDENCY' ][ 'wrapper2' ]
33 main.topology = main.params[ 'DEPENDENCY' ][ 'topology' ]
34 bucket = main.params[ 'DEPENDENCY' ][ 'bucket' ]
35 main.maxNodes = int( main.params[ 'SCALE' ][ 'max' ] )
36 main.startUpSleep = int( main.params[ 'SLEEP' ][ 'startup' ] )
37 main.startMNSleep = int( main.params[ 'SLEEP' ][ 'startMN' ] )
38 main.addFlowSleep = int( main.params[ 'SLEEP' ][ 'addFlow' ] )
39 main.delFlowSleep = int( main.params[ 'SLEEP' ][ 'delFlow' ] )
40 main.addGroupSleep = int( main.params[ 'SLEEP' ][ 'addGroup' ] )
41 main.delGroupSleep = int( main.params[ 'SLEEP' ][ 'delGroup' ] )
42 main.debug = main.params[ 'DEBUG' ]
43 main.swDPID = main.params[ 'TEST' ][ 'swDPID' ]
44 egressPort1 = main.params[ 'TEST' ][ 'egressPort1' ]
45 egressPort2 = main.params[ 'TEST' ][ 'egressPort2' ]
46 egressPort3 = main.params[ 'TEST' ][ 'egressPort3' ]
47 ingressPort = main.params[ 'TEST' ][ 'ingressPort' ]
48 appCookie = main.params[ 'TEST' ][ 'appCookie' ]
49 type1 = main.params[ 'TEST' ][ 'type1' ]
50 type2 = main.params[ 'TEST' ][ 'type2' ]
51 groupId = main.params[ 'TEST' ][ 'groupId' ]
52 priority = main.params[ 'TEST' ][ 'priority' ]
53 deviceId = main.params[ 'TEST' ][ 'swDPID' ]
54
Jon Hall602d0a72017-05-24 16:06:53 -070055 main.cellData = {} # for creating cell file
56 main.CLIs = []
57 main.ONOSip = []
kavitha Alagesan373e0552016-11-22 05:22:05 +053058
59 main.debug = True if "on" in main.debug else False
60
Jon Hall602d0a72017-05-24 16:06:53 -070061 main.ONOSip = main.ONOSbench.getOnosIps()
kavitha Alagesan373e0552016-11-22 05:22:05 +053062
63 # Assigning ONOS cli handles to a list
Jon Hall602d0a72017-05-24 16:06:53 -070064 for i in range( 1, main.maxNodes + 1 ):
kavitha Alagesan373e0552016-11-22 05:22:05 +053065 main.CLIs.append( getattr( main, 'ONOScli' + str( i ) ) )
66
67 # -- INIT SECTION, ONLY RUNS ONCE -- #
68 main.startUp = imp.load_source( wrapperFile1,
69 main.dependencyPath +
70 wrapperFile1 +
71 ".py" )
72
73 main.topo = imp.load_source( wrapperFile2,
74 main.dependencyPath +
75 wrapperFile2 +
76 ".py" )
77
78 main.buckets = imp.load_source( bucket,
79 main.dependencyPath +
80 bucket +
81 ".py" )
82
83 copyResult = main.ONOSbench.scp( main.Mininet1,
84 main.dependencyPath + main.topology,
85 main.Mininet1.home + '/custom/',
86 direction="to" )
87
88 utilities.assert_equals( expect=main.TRUE,
89 actual=copyResult,
90 onpass="Successfully copy " + "test variables ",
91 onfail="Failed to copy test variables" )
92
93 if main.CLIs:
94 stepResult = main.TRUE
95 else:
96 main.log.error( "Did not properly created list of ONOS CLI handle" )
97 stepResult = main.FALSE
98
99 utilities.assert_equals( expect=main.TRUE,
100 actual=stepResult,
101 onpass="Successfully construct " + "test variables ",
102 onfail="Failed to construct test variables" )
103
104 if gitPull == 'True':
105 main.step( "Building ONOS in " + gitBranch + " branch" )
106 onosBuildResult = main.startUp.onosBuild( main, gitBranch )
107 stepResult = onosBuildResult
108 utilities.assert_equals( expect=main.TRUE,
109 actual=stepResult,
110 onpass="Successfully compiled " + "latest ONOS",
111 onfail="Failed to compile " + "latest ONOS" )
112 else:
113 main.log.warn( "Did not pull new code so skipping mvn " +
114 "clean install" )
115
116 def CASE2( self, main ):
117 """
118 - Set up cell
119 - Create cell file
120 - Set cell file
121 - Verify cell file
122 - Kill ONOS process
123 - Uninstall ONOS cluster
124 - Verify ONOS start up
125 - Install ONOS cluster
126 - Connect to cli
127 """
128 import time
129
130 main.numCtrls = int( main.maxNodes )
131
132 main.case( "Starting up " + str( main.numCtrls ) +
133 " node(s) ONOS cluster" )
134
135 #kill off all onos processes
136 main.log.info( "Safety check, killing all ONOS processes" +
137 " before initiating environment setup" )
138
139 for i in range( main.maxNodes ):
140 main.ONOSbench.onosDie( main.ONOSip[ i ] )
141
142 main.log.info( "NODE COUNT = " + str( main.numCtrls ) )
143
Jon Hall602d0a72017-05-24 16:06:53 -0700144 tempOnosIp = []
kavitha Alagesan373e0552016-11-22 05:22:05 +0530145 for i in range( main.numCtrls ):
146 tempOnosIp.append( main.ONOSip[ i ] )
147
148 main.ONOSbench.createCellFile( main.ONOSbench.ip_address,
149 "temp",
150 main.Mininet1.ip_address,
151 main.apps,
152 tempOnosIp )
153
154 main.step( "Apply cell to environment" )
155 cellResult = main.ONOSbench.setCell( "temp" )
Jon Hall602d0a72017-05-24 16:06:53 -0700156 verifyResult = main.ONOSbench.verifyCell()
kavitha Alagesan373e0552016-11-22 05:22:05 +0530157 stepResult = cellResult and verifyResult
158 utilities.assert_equals( expect=main.TRUE,
159 actual=stepResult,
160 onpass="Successfully applied cell to " + "environment",
161 onfail="Failed to apply cell to environment " )
162
163 main.step( "Creating ONOS package" )
164 packageResult = main.ONOSbench.buckBuild()
165 stepResult = packageResult
166 utilities.assert_equals( expect=main.TRUE,
167 actual=stepResult,
168 onpass="Successfully created ONOS package",
169 onfail="Failed to create ONOS package" )
170
171 time.sleep( main.startUpSleep )
172 main.step( "Uninstalling ONOS package" )
173 onosUninstallResult = main.TRUE
174 for ip in main.ONOSip:
175 onosUninstallResult = onosUninstallResult and \
176 main.ONOSbench.onosUninstall( nodeIp=ip )
177 stepResult = onosUninstallResult
178 utilities.assert_equals( expect=main.TRUE,
179 actual=stepResult,
180 onpass="Successfully uninstalled ONOS package",
181 onfail="Failed to uninstall ONOS package" )
182 time.sleep( main.startUpSleep )
183 main.step( "Installing ONOS package" )
184 onosInstallResult = main.TRUE
185 for i in range( main.numCtrls ):
186 onosInstallResult = onosInstallResult and \
187 main.ONOSbench.onosInstall( node=main.ONOSip[ i ] )
188 stepResult = onosInstallResult
189 utilities.assert_equals( expect=main.TRUE,
190 actual=stepResult,
191 onpass="Successfully installed ONOS package",
192 onfail="Failed to install ONOS package" )
193
194 time.sleep( main.startUpSleep )
195 main.step( "Starting ONOS service" )
196 stopResult = main.TRUE
197 startResult = main.TRUE
198 onosIsUp = main.TRUE
199
200 for i in range( main.numCtrls ):
201 onosIsUp = onosIsUp and main.ONOSbench.isup( main.ONOSip[ i ] )
202 if onosIsUp == main.TRUE:
203 main.log.report( "ONOS instance is up and ready" )
204 else:
205 main.log.report( "ONOS instance may not be up, stop and " +
206 "start ONOS again " )
207 for i in range( main.numCtrls ):
208 stopResult = stopResult and \
209 main.ONOSbench.onosStop( main.ONOSip[ i ] )
210 for i in range( main.numCtrls ):
211 startResult = startResult and \
212 main.ONOSbench.onosStart( main.ONOSip[ i ] )
213 stepResult = onosIsUp and stopResult and startResult
214 utilities.assert_equals( expect=main.TRUE,
215 actual=stepResult,
216 onpass="ONOS service is ready",
217 onfail="ONOS service did not start properly" )
218
219 main.step( "Set up ONOS secure SSH" )
220 secureSshResult = main.TRUE
221 for i in range( int( main.numCtrls ) ):
Jon Hall602d0a72017-05-24 16:06:53 -0700222 secureSshResult = secureSshResult and main.ONOSbench.onosSecureSSH( node=main.ONOSip[ i ] )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530223 utilities.assert_equals( expect=main.TRUE, actual=secureSshResult,
224 onpass="Test step PASS",
225 onfail="Test step FAIL" )
226
227 main.step( "Start ONOS cli" )
228 cliResult = main.TRUE
229 for i in range( main.numCtrls ):
230 cliResult = cliResult and \
231 main.CLIs[ i ].startOnosCli( main.ONOSip[ i ] )
232 stepResult = cliResult
233 utilities.assert_equals( expect=main.TRUE,
234 actual=stepResult,
235 onpass="Successfully start ONOS cli",
236 onfail="Failed to start ONOS cli" )
237
238 def CASE3( self, main ):
Jon Hall602d0a72017-05-24 16:06:53 -0700239 """
kavitha Alagesan373e0552016-11-22 05:22:05 +0530240 Start Mininet
Jon Hall602d0a72017-05-24 16:06:53 -0700241 """
kavitha Alagesan373e0552016-11-22 05:22:05 +0530242 import json
243
244 main.case( "Setup mininet and compare ONOS topology view to Mininet topology" )
245 main.caseExplanation = "Start mininet with custom topology and compare topology " +\
246 "elements between Mininet and ONOS"
247
248 main.step( "Setup Mininet Topology" )
249 topology = main.Mininet1.home + '/custom/' + main.topology
Jon Hall602d0a72017-05-24 16:06:53 -0700250 stepResult = main.Mininet1.startNet( topoFile=topology )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530251
252 utilities.assert_equals( expect=main.TRUE,
253 actual=stepResult,
254 onpass="Successfully loaded topology",
255 onfail="Failed to load topology" )
256
257 main.step( "Assign switch to controller" )
Jon Hall602d0a72017-05-24 16:06:53 -0700258 stepResult = main.Mininet1.assignSwController( "s1", main.ONOSip[ 0 ] )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530259
260 utilities.assert_equals( expect=main.TRUE,
261 actual=stepResult,
262 onpass="Successfully assigned switch to controller",
263 onfail="Failed to assign switch to controller" )
264
265 time.sleep( main.startMNSleep )
266
267 main.step( "Comparing MN topology to ONOS topology" )
268 main.log.info( "Gathering topology information" )
269 devices = main.topo.getAllDevices( main )
270 hosts = main.topo.getAllHosts( main )
271 ports = main.topo.getAllPorts( main )
272 links = main.topo.getAllLinks( main )
273
Jon Hall602d0a72017-05-24 16:06:53 -0700274 mnSwitches = main.Mininet1.getSwitches()
275 mnLinks = main.Mininet1.getLinks()
276 mnHosts = main.Mininet1.getHosts()
kavitha Alagesan373e0552016-11-22 05:22:05 +0530277
278 for controller in range( main.numCtrls ):
279 controllerStr = str( controller + 1 )
280 if devices[ controller ] and ports[ controller ] and\
Jon Hall602d0a72017-05-24 16:06:53 -0700281 "Error" not in devices[ controller ] and\
282 "Error" not in ports[ controller ]:
kavitha Alagesan373e0552016-11-22 05:22:05 +0530283
284 currentDevicesResult = main.Mininet1.compareSwitches(
285 mnSwitches,
286 json.loads( devices[ controller ] ),
287 json.loads( ports[ controller ] ) )
288 else:
289 currentDevicesResult = main.FALSE
290 utilities.assert_equals( expect=main.TRUE,
291 actual=currentDevicesResult,
292 onpass="ONOS" + controllerStr +
293 " Switches view is correct",
294 onfail="ONOS" + controllerStr +
295 " Switches view is incorrect" )
296 if links[ controller ] and "Error" not in links[ controller ]:
297 currentLinksResult = main.Mininet1.compareLinks(
298 mnSwitches, mnLinks,
299 json.loads( links[ controller ] ) )
300 else:
301 currentLinksResult = main.FALSE
302 utilities.assert_equals( expect=main.TRUE,
303 actual=currentLinksResult,
304 onpass="ONOS" + controllerStr +
305 " links view is correct",
306 onfail="ONOS" + controllerStr +
307 " links view is incorrect" )
308
309 if hosts[ controller ] or "Error" not in hosts[ controller ]:
310 currentHostsResult = main.Mininet1.compareHosts(
311 mnHosts,
312 json.loads( hosts[ controller ] ) )
313 else:
314 currentHostsResult = main.FALSE
315 utilities.assert_equals( expect=main.TRUE,
316 actual=currentHostsResult,
317 onpass="ONOS" + controllerStr +
318 " hosts exist in Mininet",
319 onfail="ONOS" + controllerStr +
Jon Hall602d0a72017-05-24 16:06:53 -0700320 " hosts don't match Mininet" )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530321
322 def CASE4( self, main ):
Jon Hall602d0a72017-05-24 16:06:53 -0700323 """
kavitha Alagesan373e0552016-11-22 05:22:05 +0530324 Testing scapy
Jon Hall602d0a72017-05-24 16:06:53 -0700325 """
kavitha Alagesan373e0552016-11-22 05:22:05 +0530326 main.case( "Testing scapy" )
327 main.step( "Creating Host1 component" )
328 main.Scapy.createHostComponent( "h1" )
329 main.Scapy.createHostComponent( "h2" )
330 hosts = [ main.h1, main.h2 ]
331 for host in hosts:
Jon Hall602d0a72017-05-24 16:06:53 -0700332 host.startHostCli()
333 host.startScapy()
334 host.updateSelf()
kavitha Alagesan373e0552016-11-22 05:22:05 +0530335 main.log.debug( host.name )
336 main.log.debug( host.hostIp )
337 main.log.debug( host.hostMac )
338
339 main.step( "Sending/Receiving Test packet - Filter doesn't match" )
340 main.log.info( "Starting Filter..." )
Jon Hall602d0a72017-05-24 16:06:53 -0700341 main.h2.startFilter()
kavitha Alagesan373e0552016-11-22 05:22:05 +0530342 main.log.info( "Building Ether frame..." )
343 main.h1.buildEther( dst=main.h2.hostMac )
344 main.log.info( "Sending Packet..." )
Jon Hall602d0a72017-05-24 16:06:53 -0700345 main.h1.sendPacket()
kavitha Alagesan373e0552016-11-22 05:22:05 +0530346 main.log.info( "Checking Filter..." )
Jon Hall602d0a72017-05-24 16:06:53 -0700347 finished = main.h2.checkFilter()
kavitha Alagesan373e0552016-11-22 05:22:05 +0530348 main.log.debug( finished )
349 i = ""
350 if finished:
Jon Hall602d0a72017-05-24 16:06:53 -0700351 a = main.h2.readPackets()
352 for i in a.splitlines():
kavitha Alagesan373e0552016-11-22 05:22:05 +0530353 main.log.info( i )
354 else:
Jon Hall602d0a72017-05-24 16:06:53 -0700355 kill = main.h2.killFilter()
kavitha Alagesan373e0552016-11-22 05:22:05 +0530356 main.log.debug( kill )
357 main.h2.handle.sendline( "" )
358 main.h2.handle.expect( main.h2.scapyPrompt )
359 main.log.debug( main.h2.handle.before )
360 utilities.assert_equals( expect=True,
361 actual="dst=00:00:00:00:00:02 src=00:00:00:00:00:01" in i,
362 onpass="Pass",
363 onfail="Fail" )
364
365 main.step( "Sending/Receiving Test packet - Filter matches" )
Jon Hall602d0a72017-05-24 16:06:53 -0700366 main.h2.startFilter()
kavitha Alagesan373e0552016-11-22 05:22:05 +0530367 main.h1.buildEther( dst=main.h2.hostMac )
368 main.h1.buildIP( dst=main.h2.hostIp )
Jon Hall602d0a72017-05-24 16:06:53 -0700369 main.h1.sendPacket()
370 finished = main.h2.checkFilter()
kavitha Alagesan373e0552016-11-22 05:22:05 +0530371 i = ""
372 if finished:
Jon Hall602d0a72017-05-24 16:06:53 -0700373 a = main.h2.readPackets()
374 for i in a.splitlines():
kavitha Alagesan373e0552016-11-22 05:22:05 +0530375 main.log.info( i )
376 else:
Jon Hall602d0a72017-05-24 16:06:53 -0700377 kill = main.h2.killFilter()
kavitha Alagesan373e0552016-11-22 05:22:05 +0530378 main.log.debug( kill )
379 main.h2.handle.sendline( "" )
380 main.h2.handle.expect( main.h2.scapyPrompt )
381 main.log.debug( main.h2.handle.before )
382 utilities.assert_equals( expect=True,
383 actual="dst=00:00:00:00:00:02 src=00:00:00:00:00:01" in i,
384 onpass="Pass",
385 onfail="Fail" )
386
kavitha Alagesan373e0552016-11-22 05:22:05 +0530387 main.step( "Clean up host components" )
388 for host in hosts:
Jon Hall602d0a72017-05-24 16:06:53 -0700389 host.stopScapy()
kavitha Alagesan373e0552016-11-22 05:22:05 +0530390 main.Mininet1.removeHostComponent( "h1" )
391 main.Mininet1.removeHostComponent( "h2" )
392
393 def CASE5( self, main ):
Jon Hall602d0a72017-05-24 16:06:53 -0700394 """
kavitha Alagesan373e0552016-11-22 05:22:05 +0530395 Adding Group of type "ALL" using Rest api
Jon Hall602d0a72017-05-24 16:06:53 -0700396 """
kavitha Alagesan373e0552016-11-22 05:22:05 +0530397 import json
398 import time
399 isAdded = main.FALSE
400 main.case( "Verify Group of type All are successfully Added" )
401 main.caseExplanation = " Install a Group of type ALL " +\
402 " Verify the Group is Added " +\
403 " Add a flow using the group " +\
404 " Send a packet that verifies the action bucket of the group"
405
406 main.step( "Add Group using Rest api" )
407 bucketList = []
Jon Hall602d0a72017-05-24 16:06:53 -0700408 bucket = main.buckets.addBucket( main, egressPort=egressPort1 )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530409 bucketList.append( bucket )
Jon Hall602d0a72017-05-24 16:06:53 -0700410 bucket = main.buckets.addBucket( main, egressPort=egressPort2 )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530411 bucketList.append( bucket )
Jon Hall602d0a72017-05-24 16:06:53 -0700412 bucket = main.buckets.addBucket( main, egressPort=egressPort3 )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530413 bucketList.append( bucket )
Jon Hall602d0a72017-05-24 16:06:53 -0700414 response = main.ONOSrest.addGroup( deviceId=deviceId,
415 groupType=type1,
416 bucketList=bucketList,
417 appCookie=appCookie,
418 groupId=groupId )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530419
420 utilities.assert_equals( expect=main.TRUE,
421 actual=response,
422 onpass="Successfully added Groups of type ALL",
423 onfail="Failed to add Groups of type ALL" )
424
425 # Giving ONOS time to add the group
426 time.sleep( main.addGroupSleep )
427
428 main.step( "Check groups are in ADDED state" )
429
Jon Hall602d0a72017-05-24 16:06:53 -0700430 response = main.ONOSrest.getGroups( deviceId=deviceId,
431 appCookie=appCookie )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530432 responsejson = json.loads( response )
Jon Hall602d0a72017-05-24 16:06:53 -0700433 for item in responsejson:
434 if item[ "state" ] == "ADDED":
kavitha Alagesan373e0552016-11-22 05:22:05 +0530435 isAdded = main.TRUE
436
437 utilities.assert_equals( expect=main.TRUE,
438 actual=isAdded,
439 onpass="All Group is in Added State",
440 onfail="All Group is not in Added State" )
441
Jon Hall602d0a72017-05-24 16:06:53 -0700442 """
kavitha Alagesan373e0552016-11-22 05:22:05 +0530443 Adding flow using rest api
Jon Hall602d0a72017-05-24 16:06:53 -0700444 """
kavitha Alagesan373e0552016-11-22 05:22:05 +0530445 isAdded = main.FALSE
446
447 main.step( "Adding flow with Group using rest api" )
Jon Hall602d0a72017-05-24 16:06:53 -0700448 response = main.ONOSrest.addFlow( deviceId=deviceId,
449 priority=priority,
450 ingressPort=ingressPort,
451 groupId=groupId )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530452 utilities.assert_equals( expect=main.TRUE,
453 actual=response,
454 onpass="Successfully Added Flows",
455 onfail="Failed to Add flows" )
456
457 # Giving ONOS time to add the flow
458 time.sleep( main.addFlowSleep )
459
Jon Hall602d0a72017-05-24 16:06:53 -0700460 response = main.ONOSrest.getFlows( deviceId=deviceId )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530461 responsejson = json.loads( response )
Jon Hall602d0a72017-05-24 16:06:53 -0700462 for item in responsejson:
463 if item[ "priority" ] == int( priority ) and item[ "state" ] == "ADDED":
kavitha Alagesan373e0552016-11-22 05:22:05 +0530464 isAdded = main.TRUE
465
466 utilities.assert_equals( expect=main.TRUE,
467 actual=isAdded,
468 onpass="Flow is in Added State",
469 onfail="Flow is not in Added State" )
470
Jon Hall602d0a72017-05-24 16:06:53 -0700471 """
kavitha Alagesan373e0552016-11-22 05:22:05 +0530472 Sends a packet using scapy
Jon Hall602d0a72017-05-24 16:06:53 -0700473 """
kavitha Alagesan373e0552016-11-22 05:22:05 +0530474 main.step( "Testing Group by sending packet using Scapy" )
475 main.log.info( "Creating host components" )
476 main.Scapy.createHostComponent( "h1" )
477 main.Scapy.createHostComponent( "h2" )
478 main.Scapy.createHostComponent( "h3" )
479 main.Scapy.createHostComponent( "h4" )
480
Jon Hall602d0a72017-05-24 16:06:53 -0700481 hosts = [ main.h1, main.h2, main.h3, main.h4 ]
kavitha Alagesan373e0552016-11-22 05:22:05 +0530482 for host in hosts:
Jon Hall602d0a72017-05-24 16:06:53 -0700483 host.startHostCli()
484 host.startScapy()
485 host.updateSelf()
kavitha Alagesan373e0552016-11-22 05:22:05 +0530486 main.log.info( "Constructing Packet" )
487 main.h1.buildEther( dst=main.h1.hostMac )
488 main.h1.buildIP( dst=main.h1.hostIp )
489 main.log.info( "Start Filter on host2,host3,host4" )
490 main.h2.startFilter( pktFilter="ether host %s and ip host %s" % ( main.h1.hostMac, main.h1.hostIp ) )
491 main.h3.startFilter( pktFilter="ether host %s and ip host %s" % ( main.h1.hostMac, main.h1.hostIp ) )
492 main.h4.startFilter( pktFilter="ether host %s and ip host %s" % ( main.h1.hostMac, main.h1.hostIp ) )
493 main.log.info( "sending packet to Host" )
Jon Hall602d0a72017-05-24 16:06:53 -0700494 main.h1.sendPacket()
kavitha Alagesan373e0552016-11-22 05:22:05 +0530495 main.log.info( "Checking filter for our packet" )
Jon Hall602d0a72017-05-24 16:06:53 -0700496 stepResultH2 = main.h2.checkFilter()
497 stepResultH3 = main.h3.checkFilter()
498 stepResultH4 = main.h4.checkFilter()
kavitha Alagesan373e0552016-11-22 05:22:05 +0530499
500 if stepResultH2:
Jon Hall602d0a72017-05-24 16:06:53 -0700501 main.log.info( "Packet : %s" % main.h2.readPackets() )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530502 else:
Jon Hall602d0a72017-05-24 16:06:53 -0700503 main.h2.killFilter()
kavitha Alagesan373e0552016-11-22 05:22:05 +0530504
505 if stepResultH3:
Jon Hall602d0a72017-05-24 16:06:53 -0700506 main.log.info( "Packet : %s" % main.h3.readPackets() )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530507 else:
Jon Hall602d0a72017-05-24 16:06:53 -0700508 main.h2.killFilter()
kavitha Alagesan373e0552016-11-22 05:22:05 +0530509
510 if stepResultH4:
Jon Hall602d0a72017-05-24 16:06:53 -0700511 main.log.info( "Packet : %s" % main.h4.readPackets() )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530512 else:
Jon Hall602d0a72017-05-24 16:06:53 -0700513 main.h4.killFilter()
kavitha Alagesan373e0552016-11-22 05:22:05 +0530514
Jon Hall602d0a72017-05-24 16:06:53 -0700515 if stepResultH2 and stepResultH3 and stepResultH4:
kavitha Alagesan373e0552016-11-22 05:22:05 +0530516 main.log.info( "Success!!!Packet sent to port 1 is received at port 2,3 and 4" )
517 stepResult = main.TRUE
518 else:
519 main.log.info( "Failure!!!Packet sent to port 1 is not received at port 2,3 and 4" )
520 stepResult = main.FALSE
521
522 main.log.info( "Clean up host components" )
523 for host in hosts:
Jon Hall602d0a72017-05-24 16:06:53 -0700524 host.stopScapy()
kavitha Alagesan373e0552016-11-22 05:22:05 +0530525 main.Mininet1.removeHostComponent( "h1" )
526 main.Mininet1.removeHostComponent( "h2" )
527 main.Mininet1.removeHostComponent( "h3" )
528 main.Mininet1.removeHostComponent( "h4" )
529
530 utilities.assert_equals( expect=main.TRUE,
531 actual=stepResult,
532 onpass="Packet sent to port 1 is received at port 2,3,4 ",
533 onfail="Packet sent to port 1 is not received at port 2,3,4 " )
534
535 def CASE6( self, main ):
Jon Hall602d0a72017-05-24 16:06:53 -0700536 """
kavitha Alagesan373e0552016-11-22 05:22:05 +0530537 Deleting the Group and Flow
Jon Hall602d0a72017-05-24 16:06:53 -0700538 """
kavitha Alagesan373e0552016-11-22 05:22:05 +0530539 import json
540 import time
541 respFlowId = 1
542
543 main.case( "Delete the Group and Flow added through Rest api " )
544 main.step( "Deleting Group and Flows" )
545
546 #Get Flow ID
Jon Hall602d0a72017-05-24 16:06:53 -0700547 response = main.ONOSrest.getFlows( deviceId=deviceId )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530548 responsejson = json.loads( response )
Jon Hall602d0a72017-05-24 16:06:53 -0700549 for item in responsejson:
550 if item[ "priority" ] == int( priority ):
551 respFlowId = item[ "id" ]
kavitha Alagesan373e0552016-11-22 05:22:05 +0530552
553 main.step( "Deleting the created flow by deviceId and flowId" )
Jon Hall602d0a72017-05-24 16:06:53 -0700554 flowResponse = main.ONOSrest.removeFlow( deviceId=deviceId,
555 flowId=respFlowId )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530556
557 utilities.assert_equals( expect=main.TRUE,
558 actual=flowResponse,
559 onpass="Deleting flow is successful!!!",
560 onfail="Deleting flow is failure!!!" )
561
562 # Giving ONOS time to delete the flow
563 time.sleep( main.delFlowSleep )
564
565 main.step( "Deleting the created group by deviceId and appCookie" )
Jon Hall602d0a72017-05-24 16:06:53 -0700566 groupResponse = main.ONOSrest.removeGroup( deviceId=deviceId,
567 appCookie=appCookie )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530568
569 utilities.assert_equals( expect=main.TRUE,
570 actual=groupResponse,
571 onpass="Deleting Group is successful!!!",
572 onfail="Deleting Group is failure!!!" )
573
574 # Giving ONOS time to delete the group
575 time.sleep( main.delGroupSleep )
576
577 def CASE7( self, main ):
Jon Hall602d0a72017-05-24 16:06:53 -0700578 """
kavitha Alagesan373e0552016-11-22 05:22:05 +0530579 Adding Group of type "INDIRECT" using Rest api.
Jon Hall602d0a72017-05-24 16:06:53 -0700580 """
kavitha Alagesan373e0552016-11-22 05:22:05 +0530581 import json
582 import time
583 isAdded = main.FALSE
584
585 main.case( "Verify Group of type INDIRECT are successfully Added" )
586 main.caseExplanation = " Install a Group of type INDIRECT " +\
587 " Verify the Group is Added " +\
588 " Add a flow using the group " +\
589 " Send a packet that verifies the action bucket of the group"
590
591 main.step( "Add Group using Rest api" )
592 bucketList = []
Jon Hall602d0a72017-05-24 16:06:53 -0700593 bucket = main.buckets.addBucket( main, egressPort=egressPort1 )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530594 bucketList.append( bucket )
Jon Hall602d0a72017-05-24 16:06:53 -0700595 response = main.ONOSrest.addGroup( deviceId=deviceId,
596 groupType=type2,
597 bucketList=bucketList,
598 appCookie=appCookie,
599 groupId=groupId )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530600
601 utilities.assert_equals( expect=main.TRUE,
602 actual=response,
603 onpass="Successfully added Groups of type INDIRECT",
604 onfail="Failed to add Groups of type INDIRECT" )
605
606 # Giving ONOS time to add the group
607 time.sleep( main.addGroupSleep )
608
609 main.step( "Check groups are in ADDED state" )
610
Jon Hall602d0a72017-05-24 16:06:53 -0700611 response = main.ONOSrest.getGroups( deviceId=deviceId,
612 appCookie=appCookie )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530613 responsejson = json.loads( response )
Jon Hall602d0a72017-05-24 16:06:53 -0700614 for item in responsejson:
615 if item[ "state" ] == "ADDED":
kavitha Alagesan373e0552016-11-22 05:22:05 +0530616 isAdded = main.TRUE
617
618 utilities.assert_equals( expect=main.TRUE,
619 actual=isAdded,
620 onpass="INDIRECT Group is in Added State",
621 onfail="INDIRECT Group is not in Added State" )
622
Jon Hall602d0a72017-05-24 16:06:53 -0700623 """
kavitha Alagesan373e0552016-11-22 05:22:05 +0530624 Adding flows using rest api
Jon Hall602d0a72017-05-24 16:06:53 -0700625 """
kavitha Alagesan373e0552016-11-22 05:22:05 +0530626 isAdded = main.FALSE
627
628 main.step( "Adding flow with Group using rest api" )
Jon Hall602d0a72017-05-24 16:06:53 -0700629 response = main.ONOSrest.addFlow( deviceId=deviceId,
630 priority=priority,
631 ingressPort=ingressPort,
632 groupId=groupId )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530633 utilities.assert_equals( expect=main.TRUE,
634 actual=response,
635 onpass="Successfully Added Flows",
636 onfail="Failed to Add flows" )
637
638 # Giving ONOS time to add the flow
639 time.sleep( main.addFlowSleep )
640
Jon Hall602d0a72017-05-24 16:06:53 -0700641 response = main.ONOSrest.getFlows( deviceId=deviceId )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530642 responsejson = json.loads( response )
Jon Hall602d0a72017-05-24 16:06:53 -0700643 for item in responsejson:
644 if item[ "priority" ] == int( priority ) and item[ "state" ] == "ADDED":
kavitha Alagesan373e0552016-11-22 05:22:05 +0530645 isAdded = main.TRUE
646
647 utilities.assert_equals( expect=main.TRUE,
648 actual=isAdded,
649 onpass="Flow is in Added State",
650 onfail="Flow is not in Added State" )
651
Jon Hall602d0a72017-05-24 16:06:53 -0700652 """
kavitha Alagesan373e0552016-11-22 05:22:05 +0530653 Sends a packet using scapy
Jon Hall602d0a72017-05-24 16:06:53 -0700654 """
kavitha Alagesan373e0552016-11-22 05:22:05 +0530655 main.step( "Testing Group by sending packet using Scapy" )
656 main.log.info( "Creating host components" )
657 main.Scapy.createHostComponent( "h1" )
658 main.Scapy.createHostComponent( "h2" )
659
Jon Hall602d0a72017-05-24 16:06:53 -0700660 hosts = [ main.h1, main.h2 ]
kavitha Alagesan373e0552016-11-22 05:22:05 +0530661 for host in hosts:
Jon Hall602d0a72017-05-24 16:06:53 -0700662 host.startHostCli()
663 host.startScapy()
664 host.updateSelf()
kavitha Alagesan373e0552016-11-22 05:22:05 +0530665 main.log.info( "Constructing Packet" )
666 main.h1.buildEther( dst=main.h1.hostMac )
667 main.h1.buildIP( dst=main.h1.hostIp )
668 main.log.info( "Start Filter on host2" )
669 main.h2.startFilter( pktFilter="ether host %s and ip host %s" % ( main.h1.hostMac, main.h1.hostIp ) )
670 main.log.info( "sending packet to Host" )
Jon Hall602d0a72017-05-24 16:06:53 -0700671 main.h1.sendPacket()
kavitha Alagesan373e0552016-11-22 05:22:05 +0530672 main.log.info( "Checking filter for our packet" )
Jon Hall602d0a72017-05-24 16:06:53 -0700673 stepResultH2 = main.h2.checkFilter()
kavitha Alagesan373e0552016-11-22 05:22:05 +0530674
675 if stepResultH2:
Jon Hall602d0a72017-05-24 16:06:53 -0700676 main.log.info( "Packet : %s" % main.h2.readPackets() )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530677 else:
Jon Hall602d0a72017-05-24 16:06:53 -0700678 main.h2.killFilter()
kavitha Alagesan373e0552016-11-22 05:22:05 +0530679
680 main.log.info( "Clean up host components" )
681 for host in hosts:
Jon Hall602d0a72017-05-24 16:06:53 -0700682 host.stopScapy()
kavitha Alagesan373e0552016-11-22 05:22:05 +0530683 main.Mininet1.removeHostComponent( "h1" )
684 main.Mininet1.removeHostComponent( "h2" )
685
686 utilities.assert_equals( expect=main.TRUE,
687 actual=stepResultH2,
688 onpass="Packet sent to port 1 is received at port 2 successfully!!!",
689 onfail="Failure!!!Packet sent to port 1 is not received at port 2" )
690
691 def CASE8( self, main ):
Jon Hall602d0a72017-05-24 16:06:53 -0700692 """
kavitha Alagesan373e0552016-11-22 05:22:05 +0530693 Deleting the Group and Flow
Jon Hall602d0a72017-05-24 16:06:53 -0700694 """
kavitha Alagesan373e0552016-11-22 05:22:05 +0530695 import json
696 import time
697 respFlowId = 1
698
699 main.case( "Delete the Group and Flow added through Rest api " )
700 main.step( "Deleting Group and Flows" )
701
702 #Getting Flow ID
Jon Hall602d0a72017-05-24 16:06:53 -0700703 response = main.ONOSrest.getFlows( deviceId=deviceId )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530704 responsejson = json.loads( response )
Jon Hall602d0a72017-05-24 16:06:53 -0700705 for item in responsejson:
706 if item[ "priority" ] == int( priority ):
707 respFlowId = item[ "id" ]
kavitha Alagesan373e0552016-11-22 05:22:05 +0530708
709 main.step( "Deleting the created flow by deviceId and flowId" )
Jon Hall602d0a72017-05-24 16:06:53 -0700710 flowResponse = main.ONOSrest.removeFlow( deviceId=deviceId,
711 flowId=respFlowId )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530712
713 utilities.assert_equals( expect=main.TRUE,
714 actual=flowResponse,
715 onpass="Deleting flow is successful!!!",
716 onfail="Deleting flow is failure!!!" )
717
718 # Giving ONOS time to delete the flow
719 time.sleep( main.delFlowSleep )
720
Jon Hall602d0a72017-05-24 16:06:53 -0700721 groupResponse = main.ONOSrest.removeGroup( deviceId=deviceId,
722 appCookie=appCookie )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530723
724 utilities.assert_equals( expect=main.TRUE,
725 actual=groupResponse,
726 onpass="Deleting Group is successful!!!",
727 onfail="Deleting Group is failure!!!" )
728
729 # Giving ONOS time to delete the group
730 time.sleep( main.delGroupSleep )
731
732 def CASE100( self, main ):
Jon Hall602d0a72017-05-24 16:06:53 -0700733 """
kavitha Alagesan373e0552016-11-22 05:22:05 +0530734 Report errors/warnings/exceptions
Jon Hall602d0a72017-05-24 16:06:53 -0700735 """
kavitha Alagesan373e0552016-11-22 05:22:05 +0530736 main.log.info( "Error report: \n" )
737 main.ONOSbench.logReport( main.ONOSip[ 0 ],
738 [ "INFO",
739 "FOLLOWER",
740 "WARN",
741 "flow",
742 "group",
743 "ERROR",
744 "Except" ],
745 "s" )