blob: 29b2d2a3d11c01292eccb6f1b2a4f2e0589f82a6 [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
kavitha Alagesan373e0552016-11-22 05:22:05 +0530104 def CASE2( self, main ):
105 """
106 - Set up cell
107 - Create cell file
108 - Set cell file
109 - Verify cell file
110 - Kill ONOS process
111 - Uninstall ONOS cluster
112 - Verify ONOS start up
113 - Install ONOS cluster
114 - Connect to cli
115 """
116 import time
117
118 main.numCtrls = int( main.maxNodes )
119
120 main.case( "Starting up " + str( main.numCtrls ) +
121 " node(s) ONOS cluster" )
122
123 #kill off all onos processes
124 main.log.info( "Safety check, killing all ONOS processes" +
125 " before initiating environment setup" )
126
127 for i in range( main.maxNodes ):
128 main.ONOSbench.onosDie( main.ONOSip[ i ] )
129
130 main.log.info( "NODE COUNT = " + str( main.numCtrls ) )
131
Jon Hall602d0a72017-05-24 16:06:53 -0700132 tempOnosIp = []
kavitha Alagesan373e0552016-11-22 05:22:05 +0530133 for i in range( main.numCtrls ):
134 tempOnosIp.append( main.ONOSip[ i ] )
135
136 main.ONOSbench.createCellFile( main.ONOSbench.ip_address,
137 "temp",
138 main.Mininet1.ip_address,
139 main.apps,
Devin Lim461f0872017-06-05 16:49:33 -0700140 tempOnosIp, main.ONOScli1.user_name )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530141
142 main.step( "Apply cell to environment" )
143 cellResult = main.ONOSbench.setCell( "temp" )
Jon Hall602d0a72017-05-24 16:06:53 -0700144 verifyResult = main.ONOSbench.verifyCell()
kavitha Alagesan373e0552016-11-22 05:22:05 +0530145 stepResult = cellResult and verifyResult
146 utilities.assert_equals( expect=main.TRUE,
147 actual=stepResult,
148 onpass="Successfully applied cell to " + "environment",
149 onfail="Failed to apply cell to environment " )
150
151 main.step( "Creating ONOS package" )
152 packageResult = main.ONOSbench.buckBuild()
153 stepResult = packageResult
154 utilities.assert_equals( expect=main.TRUE,
155 actual=stepResult,
156 onpass="Successfully created ONOS package",
157 onfail="Failed to create ONOS package" )
158
159 time.sleep( main.startUpSleep )
160 main.step( "Uninstalling ONOS package" )
161 onosUninstallResult = main.TRUE
162 for ip in main.ONOSip:
163 onosUninstallResult = onosUninstallResult and \
164 main.ONOSbench.onosUninstall( nodeIp=ip )
165 stepResult = onosUninstallResult
166 utilities.assert_equals( expect=main.TRUE,
167 actual=stepResult,
168 onpass="Successfully uninstalled ONOS package",
169 onfail="Failed to uninstall ONOS package" )
170 time.sleep( main.startUpSleep )
171 main.step( "Installing ONOS package" )
172 onosInstallResult = main.TRUE
173 for i in range( main.numCtrls ):
174 onosInstallResult = onosInstallResult and \
175 main.ONOSbench.onosInstall( node=main.ONOSip[ i ] )
176 stepResult = onosInstallResult
177 utilities.assert_equals( expect=main.TRUE,
178 actual=stepResult,
179 onpass="Successfully installed ONOS package",
180 onfail="Failed to install ONOS package" )
181
182 time.sleep( main.startUpSleep )
183 main.step( "Starting ONOS service" )
184 stopResult = main.TRUE
185 startResult = main.TRUE
186 onosIsUp = main.TRUE
187
188 for i in range( main.numCtrls ):
189 onosIsUp = onosIsUp and main.ONOSbench.isup( main.ONOSip[ i ] )
190 if onosIsUp == main.TRUE:
191 main.log.report( "ONOS instance is up and ready" )
192 else:
193 main.log.report( "ONOS instance may not be up, stop and " +
194 "start ONOS again " )
195 for i in range( main.numCtrls ):
196 stopResult = stopResult and \
197 main.ONOSbench.onosStop( main.ONOSip[ i ] )
198 for i in range( main.numCtrls ):
199 startResult = startResult and \
200 main.ONOSbench.onosStart( main.ONOSip[ i ] )
201 stepResult = onosIsUp and stopResult and startResult
202 utilities.assert_equals( expect=main.TRUE,
203 actual=stepResult,
204 onpass="ONOS service is ready",
205 onfail="ONOS service did not start properly" )
206
207 main.step( "Set up ONOS secure SSH" )
208 secureSshResult = main.TRUE
209 for i in range( int( main.numCtrls ) ):
Jon Hall602d0a72017-05-24 16:06:53 -0700210 secureSshResult = secureSshResult and main.ONOSbench.onosSecureSSH( node=main.ONOSip[ i ] )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530211 utilities.assert_equals( expect=main.TRUE, actual=secureSshResult,
212 onpass="Test step PASS",
213 onfail="Test step FAIL" )
214
215 main.step( "Start ONOS cli" )
216 cliResult = main.TRUE
217 for i in range( main.numCtrls ):
218 cliResult = cliResult and \
219 main.CLIs[ i ].startOnosCli( main.ONOSip[ i ] )
220 stepResult = cliResult
221 utilities.assert_equals( expect=main.TRUE,
222 actual=stepResult,
223 onpass="Successfully start ONOS cli",
224 onfail="Failed to start ONOS cli" )
225
226 def CASE3( self, main ):
Jon Hall602d0a72017-05-24 16:06:53 -0700227 """
kavitha Alagesan373e0552016-11-22 05:22:05 +0530228 Start Mininet
Jon Hall602d0a72017-05-24 16:06:53 -0700229 """
kavitha Alagesan373e0552016-11-22 05:22:05 +0530230 import json
231
232 main.case( "Setup mininet and compare ONOS topology view to Mininet topology" )
233 main.caseExplanation = "Start mininet with custom topology and compare topology " +\
234 "elements between Mininet and ONOS"
235
236 main.step( "Setup Mininet Topology" )
237 topology = main.Mininet1.home + '/custom/' + main.topology
Jon Hall602d0a72017-05-24 16:06:53 -0700238 stepResult = main.Mininet1.startNet( topoFile=topology )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530239
240 utilities.assert_equals( expect=main.TRUE,
241 actual=stepResult,
242 onpass="Successfully loaded topology",
243 onfail="Failed to load topology" )
244
245 main.step( "Assign switch to controller" )
Jon Hall602d0a72017-05-24 16:06:53 -0700246 stepResult = main.Mininet1.assignSwController( "s1", main.ONOSip[ 0 ] )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530247
248 utilities.assert_equals( expect=main.TRUE,
249 actual=stepResult,
250 onpass="Successfully assigned switch to controller",
251 onfail="Failed to assign switch to controller" )
252
253 time.sleep( main.startMNSleep )
254
255 main.step( "Comparing MN topology to ONOS topology" )
256 main.log.info( "Gathering topology information" )
257 devices = main.topo.getAllDevices( main )
258 hosts = main.topo.getAllHosts( main )
259 ports = main.topo.getAllPorts( main )
260 links = main.topo.getAllLinks( main )
261
Jon Hall602d0a72017-05-24 16:06:53 -0700262 mnSwitches = main.Mininet1.getSwitches()
263 mnLinks = main.Mininet1.getLinks()
264 mnHosts = main.Mininet1.getHosts()
kavitha Alagesan373e0552016-11-22 05:22:05 +0530265
266 for controller in range( main.numCtrls ):
267 controllerStr = str( controller + 1 )
268 if devices[ controller ] and ports[ controller ] and\
Jon Hall602d0a72017-05-24 16:06:53 -0700269 "Error" not in devices[ controller ] and\
270 "Error" not in ports[ controller ]:
kavitha Alagesan373e0552016-11-22 05:22:05 +0530271
272 currentDevicesResult = main.Mininet1.compareSwitches(
273 mnSwitches,
274 json.loads( devices[ controller ] ),
275 json.loads( ports[ controller ] ) )
276 else:
277 currentDevicesResult = main.FALSE
278 utilities.assert_equals( expect=main.TRUE,
279 actual=currentDevicesResult,
280 onpass="ONOS" + controllerStr +
281 " Switches view is correct",
282 onfail="ONOS" + controllerStr +
283 " Switches view is incorrect" )
284 if links[ controller ] and "Error" not in links[ controller ]:
285 currentLinksResult = main.Mininet1.compareLinks(
286 mnSwitches, mnLinks,
287 json.loads( links[ controller ] ) )
288 else:
289 currentLinksResult = main.FALSE
290 utilities.assert_equals( expect=main.TRUE,
291 actual=currentLinksResult,
292 onpass="ONOS" + controllerStr +
293 " links view is correct",
294 onfail="ONOS" + controllerStr +
295 " links view is incorrect" )
296
297 if hosts[ controller ] or "Error" not in hosts[ controller ]:
298 currentHostsResult = main.Mininet1.compareHosts(
299 mnHosts,
300 json.loads( hosts[ controller ] ) )
301 else:
302 currentHostsResult = main.FALSE
303 utilities.assert_equals( expect=main.TRUE,
304 actual=currentHostsResult,
305 onpass="ONOS" + controllerStr +
306 " hosts exist in Mininet",
307 onfail="ONOS" + controllerStr +
Jon Hall602d0a72017-05-24 16:06:53 -0700308 " hosts don't match Mininet" )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530309
310 def CASE4( self, main ):
Jon Hall602d0a72017-05-24 16:06:53 -0700311 """
kavitha Alagesan373e0552016-11-22 05:22:05 +0530312 Testing scapy
Jon Hall602d0a72017-05-24 16:06:53 -0700313 """
kavitha Alagesan373e0552016-11-22 05:22:05 +0530314 main.case( "Testing scapy" )
315 main.step( "Creating Host1 component" )
316 main.Scapy.createHostComponent( "h1" )
317 main.Scapy.createHostComponent( "h2" )
318 hosts = [ main.h1, main.h2 ]
319 for host in hosts:
Jon Hall602d0a72017-05-24 16:06:53 -0700320 host.startHostCli()
321 host.startScapy()
322 host.updateSelf()
kavitha Alagesan373e0552016-11-22 05:22:05 +0530323 main.log.debug( host.name )
324 main.log.debug( host.hostIp )
325 main.log.debug( host.hostMac )
326
327 main.step( "Sending/Receiving Test packet - Filter doesn't match" )
328 main.log.info( "Starting Filter..." )
Jon Hall602d0a72017-05-24 16:06:53 -0700329 main.h2.startFilter()
kavitha Alagesan373e0552016-11-22 05:22:05 +0530330 main.log.info( "Building Ether frame..." )
331 main.h1.buildEther( dst=main.h2.hostMac )
332 main.log.info( "Sending Packet..." )
Jon Hall602d0a72017-05-24 16:06:53 -0700333 main.h1.sendPacket()
kavitha Alagesan373e0552016-11-22 05:22:05 +0530334 main.log.info( "Checking Filter..." )
Jon Hall602d0a72017-05-24 16:06:53 -0700335 finished = main.h2.checkFilter()
kavitha Alagesan373e0552016-11-22 05:22:05 +0530336 main.log.debug( finished )
337 i = ""
338 if finished:
Jon Hall602d0a72017-05-24 16:06:53 -0700339 a = main.h2.readPackets()
340 for i in a.splitlines():
kavitha Alagesan373e0552016-11-22 05:22:05 +0530341 main.log.info( i )
342 else:
Jon Hall602d0a72017-05-24 16:06:53 -0700343 kill = main.h2.killFilter()
kavitha Alagesan373e0552016-11-22 05:22:05 +0530344 main.log.debug( kill )
345 main.h2.handle.sendline( "" )
346 main.h2.handle.expect( main.h2.scapyPrompt )
347 main.log.debug( main.h2.handle.before )
348 utilities.assert_equals( expect=True,
349 actual="dst=00:00:00:00:00:02 src=00:00:00:00:00:01" in i,
350 onpass="Pass",
351 onfail="Fail" )
352
353 main.step( "Sending/Receiving Test packet - Filter matches" )
Jon Hall602d0a72017-05-24 16:06:53 -0700354 main.h2.startFilter()
kavitha Alagesan373e0552016-11-22 05:22:05 +0530355 main.h1.buildEther( dst=main.h2.hostMac )
356 main.h1.buildIP( dst=main.h2.hostIp )
Jon Hall602d0a72017-05-24 16:06:53 -0700357 main.h1.sendPacket()
358 finished = main.h2.checkFilter()
kavitha Alagesan373e0552016-11-22 05:22:05 +0530359 i = ""
360 if finished:
Jon Hall602d0a72017-05-24 16:06:53 -0700361 a = main.h2.readPackets()
362 for i in a.splitlines():
kavitha Alagesan373e0552016-11-22 05:22:05 +0530363 main.log.info( i )
364 else:
Jon Hall602d0a72017-05-24 16:06:53 -0700365 kill = main.h2.killFilter()
kavitha Alagesan373e0552016-11-22 05:22:05 +0530366 main.log.debug( kill )
367 main.h2.handle.sendline( "" )
368 main.h2.handle.expect( main.h2.scapyPrompt )
369 main.log.debug( main.h2.handle.before )
370 utilities.assert_equals( expect=True,
371 actual="dst=00:00:00:00:00:02 src=00:00:00:00:00:01" in i,
372 onpass="Pass",
373 onfail="Fail" )
374
kavitha Alagesan373e0552016-11-22 05:22:05 +0530375 main.step( "Clean up host components" )
376 for host in hosts:
Jon Hall602d0a72017-05-24 16:06:53 -0700377 host.stopScapy()
kavitha Alagesan373e0552016-11-22 05:22:05 +0530378 main.Mininet1.removeHostComponent( "h1" )
379 main.Mininet1.removeHostComponent( "h2" )
380
381 def CASE5( self, main ):
Jon Hall602d0a72017-05-24 16:06:53 -0700382 """
kavitha Alagesan373e0552016-11-22 05:22:05 +0530383 Adding Group of type "ALL" using Rest api
Jon Hall602d0a72017-05-24 16:06:53 -0700384 """
kavitha Alagesan373e0552016-11-22 05:22:05 +0530385 import json
386 import time
387 isAdded = main.FALSE
388 main.case( "Verify Group of type All are successfully Added" )
389 main.caseExplanation = " Install a Group of type ALL " +\
390 " Verify the Group is Added " +\
391 " Add a flow using the group " +\
392 " Send a packet that verifies the action bucket of the group"
393
394 main.step( "Add Group using Rest api" )
395 bucketList = []
Jon Hall602d0a72017-05-24 16:06:53 -0700396 bucket = main.buckets.addBucket( main, egressPort=egressPort1 )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530397 bucketList.append( bucket )
Jon Hall602d0a72017-05-24 16:06:53 -0700398 bucket = main.buckets.addBucket( main, egressPort=egressPort2 )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530399 bucketList.append( bucket )
Jon Hall602d0a72017-05-24 16:06:53 -0700400 bucket = main.buckets.addBucket( main, egressPort=egressPort3 )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530401 bucketList.append( bucket )
Jon Hall602d0a72017-05-24 16:06:53 -0700402 response = main.ONOSrest.addGroup( deviceId=deviceId,
403 groupType=type1,
404 bucketList=bucketList,
405 appCookie=appCookie,
406 groupId=groupId )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530407
408 utilities.assert_equals( expect=main.TRUE,
409 actual=response,
410 onpass="Successfully added Groups of type ALL",
411 onfail="Failed to add Groups of type ALL" )
412
413 # Giving ONOS time to add the group
414 time.sleep( main.addGroupSleep )
415
416 main.step( "Check groups are in ADDED state" )
417
Jon Hall602d0a72017-05-24 16:06:53 -0700418 response = main.ONOSrest.getGroups( deviceId=deviceId,
419 appCookie=appCookie )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530420 responsejson = json.loads( response )
Jon Hall602d0a72017-05-24 16:06:53 -0700421 for item in responsejson:
422 if item[ "state" ] == "ADDED":
kavitha Alagesan373e0552016-11-22 05:22:05 +0530423 isAdded = main.TRUE
424
425 utilities.assert_equals( expect=main.TRUE,
426 actual=isAdded,
427 onpass="All Group is in Added State",
428 onfail="All Group is not in Added State" )
429
Jon Hall602d0a72017-05-24 16:06:53 -0700430 """
kavitha Alagesan373e0552016-11-22 05:22:05 +0530431 Adding flow using rest api
Jon Hall602d0a72017-05-24 16:06:53 -0700432 """
kavitha Alagesan373e0552016-11-22 05:22:05 +0530433 isAdded = main.FALSE
434
435 main.step( "Adding flow with Group using rest api" )
Jon Hall602d0a72017-05-24 16:06:53 -0700436 response = main.ONOSrest.addFlow( deviceId=deviceId,
437 priority=priority,
438 ingressPort=ingressPort,
439 groupId=groupId )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530440 utilities.assert_equals( expect=main.TRUE,
441 actual=response,
442 onpass="Successfully Added Flows",
443 onfail="Failed to Add flows" )
444
445 # Giving ONOS time to add the flow
446 time.sleep( main.addFlowSleep )
447
Jon Hall602d0a72017-05-24 16:06:53 -0700448 response = main.ONOSrest.getFlows( deviceId=deviceId )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530449 responsejson = json.loads( response )
Jon Hall602d0a72017-05-24 16:06:53 -0700450 for item in responsejson:
451 if item[ "priority" ] == int( priority ) and item[ "state" ] == "ADDED":
kavitha Alagesan373e0552016-11-22 05:22:05 +0530452 isAdded = main.TRUE
453
454 utilities.assert_equals( expect=main.TRUE,
455 actual=isAdded,
456 onpass="Flow is in Added State",
457 onfail="Flow is not in Added State" )
458
Jon Hall602d0a72017-05-24 16:06:53 -0700459 """
kavitha Alagesan373e0552016-11-22 05:22:05 +0530460 Sends a packet using scapy
Jon Hall602d0a72017-05-24 16:06:53 -0700461 """
kavitha Alagesan373e0552016-11-22 05:22:05 +0530462 main.step( "Testing Group by sending packet using Scapy" )
463 main.log.info( "Creating host components" )
464 main.Scapy.createHostComponent( "h1" )
465 main.Scapy.createHostComponent( "h2" )
466 main.Scapy.createHostComponent( "h3" )
467 main.Scapy.createHostComponent( "h4" )
468
Jon Hall602d0a72017-05-24 16:06:53 -0700469 hosts = [ main.h1, main.h2, main.h3, main.h4 ]
kavitha Alagesan373e0552016-11-22 05:22:05 +0530470 for host in hosts:
Jon Hall602d0a72017-05-24 16:06:53 -0700471 host.startHostCli()
472 host.startScapy()
473 host.updateSelf()
kavitha Alagesan373e0552016-11-22 05:22:05 +0530474 main.log.info( "Constructing Packet" )
475 main.h1.buildEther( dst=main.h1.hostMac )
476 main.h1.buildIP( dst=main.h1.hostIp )
477 main.log.info( "Start Filter on host2,host3,host4" )
478 main.h2.startFilter( pktFilter="ether host %s and ip host %s" % ( main.h1.hostMac, main.h1.hostIp ) )
479 main.h3.startFilter( pktFilter="ether host %s and ip host %s" % ( main.h1.hostMac, main.h1.hostIp ) )
480 main.h4.startFilter( pktFilter="ether host %s and ip host %s" % ( main.h1.hostMac, main.h1.hostIp ) )
481 main.log.info( "sending packet to Host" )
Jon Hall602d0a72017-05-24 16:06:53 -0700482 main.h1.sendPacket()
kavitha Alagesan373e0552016-11-22 05:22:05 +0530483 main.log.info( "Checking filter for our packet" )
Jon Hall602d0a72017-05-24 16:06:53 -0700484 stepResultH2 = main.h2.checkFilter()
485 stepResultH3 = main.h3.checkFilter()
486 stepResultH4 = main.h4.checkFilter()
kavitha Alagesan373e0552016-11-22 05:22:05 +0530487
488 if stepResultH2:
Jon Hall602d0a72017-05-24 16:06:53 -0700489 main.log.info( "Packet : %s" % main.h2.readPackets() )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530490 else:
Jon Hall602d0a72017-05-24 16:06:53 -0700491 main.h2.killFilter()
kavitha Alagesan373e0552016-11-22 05:22:05 +0530492
493 if stepResultH3:
Jon Hall602d0a72017-05-24 16:06:53 -0700494 main.log.info( "Packet : %s" % main.h3.readPackets() )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530495 else:
Jon Hall602d0a72017-05-24 16:06:53 -0700496 main.h2.killFilter()
kavitha Alagesan373e0552016-11-22 05:22:05 +0530497
498 if stepResultH4:
Jon Hall602d0a72017-05-24 16:06:53 -0700499 main.log.info( "Packet : %s" % main.h4.readPackets() )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530500 else:
Jon Hall602d0a72017-05-24 16:06:53 -0700501 main.h4.killFilter()
kavitha Alagesan373e0552016-11-22 05:22:05 +0530502
Jon Hall602d0a72017-05-24 16:06:53 -0700503 if stepResultH2 and stepResultH3 and stepResultH4:
kavitha Alagesan373e0552016-11-22 05:22:05 +0530504 main.log.info( "Success!!!Packet sent to port 1 is received at port 2,3 and 4" )
505 stepResult = main.TRUE
506 else:
507 main.log.info( "Failure!!!Packet sent to port 1 is not received at port 2,3 and 4" )
508 stepResult = main.FALSE
509
510 main.log.info( "Clean up host components" )
511 for host in hosts:
Jon Hall602d0a72017-05-24 16:06:53 -0700512 host.stopScapy()
kavitha Alagesan373e0552016-11-22 05:22:05 +0530513 main.Mininet1.removeHostComponent( "h1" )
514 main.Mininet1.removeHostComponent( "h2" )
515 main.Mininet1.removeHostComponent( "h3" )
516 main.Mininet1.removeHostComponent( "h4" )
517
518 utilities.assert_equals( expect=main.TRUE,
519 actual=stepResult,
520 onpass="Packet sent to port 1 is received at port 2,3,4 ",
521 onfail="Packet sent to port 1 is not received at port 2,3,4 " )
522
523 def CASE6( self, main ):
Jon Hall602d0a72017-05-24 16:06:53 -0700524 """
kavitha Alagesan373e0552016-11-22 05:22:05 +0530525 Deleting the Group and Flow
Jon Hall602d0a72017-05-24 16:06:53 -0700526 """
kavitha Alagesan373e0552016-11-22 05:22:05 +0530527 import json
528 import time
529 respFlowId = 1
530
531 main.case( "Delete the Group and Flow added through Rest api " )
532 main.step( "Deleting Group and Flows" )
533
534 #Get Flow ID
Jon Hall602d0a72017-05-24 16:06:53 -0700535 response = main.ONOSrest.getFlows( deviceId=deviceId )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530536 responsejson = json.loads( response )
Jon Hall602d0a72017-05-24 16:06:53 -0700537 for item in responsejson:
538 if item[ "priority" ] == int( priority ):
539 respFlowId = item[ "id" ]
kavitha Alagesan373e0552016-11-22 05:22:05 +0530540
541 main.step( "Deleting the created flow by deviceId and flowId" )
Jon Hall602d0a72017-05-24 16:06:53 -0700542 flowResponse = main.ONOSrest.removeFlow( deviceId=deviceId,
543 flowId=respFlowId )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530544
545 utilities.assert_equals( expect=main.TRUE,
546 actual=flowResponse,
547 onpass="Deleting flow is successful!!!",
548 onfail="Deleting flow is failure!!!" )
549
550 # Giving ONOS time to delete the flow
551 time.sleep( main.delFlowSleep )
552
553 main.step( "Deleting the created group by deviceId and appCookie" )
Jon Hall602d0a72017-05-24 16:06:53 -0700554 groupResponse = main.ONOSrest.removeGroup( deviceId=deviceId,
555 appCookie=appCookie )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530556
557 utilities.assert_equals( expect=main.TRUE,
558 actual=groupResponse,
559 onpass="Deleting Group is successful!!!",
560 onfail="Deleting Group is failure!!!" )
561
562 # Giving ONOS time to delete the group
563 time.sleep( main.delGroupSleep )
564
565 def CASE7( self, main ):
Jon Hall602d0a72017-05-24 16:06:53 -0700566 """
kavitha Alagesan373e0552016-11-22 05:22:05 +0530567 Adding Group of type "INDIRECT" using Rest api.
Jon Hall602d0a72017-05-24 16:06:53 -0700568 """
kavitha Alagesan373e0552016-11-22 05:22:05 +0530569 import json
570 import time
571 isAdded = main.FALSE
572
573 main.case( "Verify Group of type INDIRECT are successfully Added" )
574 main.caseExplanation = " Install a Group of type INDIRECT " +\
575 " Verify the Group is Added " +\
576 " Add a flow using the group " +\
577 " Send a packet that verifies the action bucket of the group"
578
579 main.step( "Add Group using Rest api" )
580 bucketList = []
Jon Hall602d0a72017-05-24 16:06:53 -0700581 bucket = main.buckets.addBucket( main, egressPort=egressPort1 )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530582 bucketList.append( bucket )
Jon Hall602d0a72017-05-24 16:06:53 -0700583 response = main.ONOSrest.addGroup( deviceId=deviceId,
584 groupType=type2,
585 bucketList=bucketList,
586 appCookie=appCookie,
587 groupId=groupId )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530588
589 utilities.assert_equals( expect=main.TRUE,
590 actual=response,
591 onpass="Successfully added Groups of type INDIRECT",
592 onfail="Failed to add Groups of type INDIRECT" )
593
594 # Giving ONOS time to add the group
595 time.sleep( main.addGroupSleep )
596
597 main.step( "Check groups are in ADDED state" )
598
Jon Hall602d0a72017-05-24 16:06:53 -0700599 response = main.ONOSrest.getGroups( deviceId=deviceId,
600 appCookie=appCookie )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530601 responsejson = json.loads( response )
Jon Hall602d0a72017-05-24 16:06:53 -0700602 for item in responsejson:
603 if item[ "state" ] == "ADDED":
kavitha Alagesan373e0552016-11-22 05:22:05 +0530604 isAdded = main.TRUE
605
606 utilities.assert_equals( expect=main.TRUE,
607 actual=isAdded,
608 onpass="INDIRECT Group is in Added State",
609 onfail="INDIRECT Group is not in Added State" )
610
Jon Hall602d0a72017-05-24 16:06:53 -0700611 """
kavitha Alagesan373e0552016-11-22 05:22:05 +0530612 Adding flows using rest api
Jon Hall602d0a72017-05-24 16:06:53 -0700613 """
kavitha Alagesan373e0552016-11-22 05:22:05 +0530614 isAdded = main.FALSE
615
616 main.step( "Adding flow with Group using rest api" )
Jon Hall602d0a72017-05-24 16:06:53 -0700617 response = main.ONOSrest.addFlow( deviceId=deviceId,
618 priority=priority,
619 ingressPort=ingressPort,
620 groupId=groupId )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530621 utilities.assert_equals( expect=main.TRUE,
622 actual=response,
623 onpass="Successfully Added Flows",
624 onfail="Failed to Add flows" )
625
626 # Giving ONOS time to add the flow
627 time.sleep( main.addFlowSleep )
628
Jon Hall602d0a72017-05-24 16:06:53 -0700629 response = main.ONOSrest.getFlows( deviceId=deviceId )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530630 responsejson = json.loads( response )
Jon Hall602d0a72017-05-24 16:06:53 -0700631 for item in responsejson:
632 if item[ "priority" ] == int( priority ) and item[ "state" ] == "ADDED":
kavitha Alagesan373e0552016-11-22 05:22:05 +0530633 isAdded = main.TRUE
634
635 utilities.assert_equals( expect=main.TRUE,
636 actual=isAdded,
637 onpass="Flow is in Added State",
638 onfail="Flow is not in Added State" )
639
Jon Hall602d0a72017-05-24 16:06:53 -0700640 """
kavitha Alagesan373e0552016-11-22 05:22:05 +0530641 Sends a packet using scapy
Jon Hall602d0a72017-05-24 16:06:53 -0700642 """
kavitha Alagesan373e0552016-11-22 05:22:05 +0530643 main.step( "Testing Group by sending packet using Scapy" )
644 main.log.info( "Creating host components" )
645 main.Scapy.createHostComponent( "h1" )
646 main.Scapy.createHostComponent( "h2" )
647
Jon Hall602d0a72017-05-24 16:06:53 -0700648 hosts = [ main.h1, main.h2 ]
kavitha Alagesan373e0552016-11-22 05:22:05 +0530649 for host in hosts:
Jon Hall602d0a72017-05-24 16:06:53 -0700650 host.startHostCli()
651 host.startScapy()
652 host.updateSelf()
kavitha Alagesan373e0552016-11-22 05:22:05 +0530653 main.log.info( "Constructing Packet" )
654 main.h1.buildEther( dst=main.h1.hostMac )
655 main.h1.buildIP( dst=main.h1.hostIp )
656 main.log.info( "Start Filter on host2" )
657 main.h2.startFilter( pktFilter="ether host %s and ip host %s" % ( main.h1.hostMac, main.h1.hostIp ) )
658 main.log.info( "sending packet to Host" )
Jon Hall602d0a72017-05-24 16:06:53 -0700659 main.h1.sendPacket()
kavitha Alagesan373e0552016-11-22 05:22:05 +0530660 main.log.info( "Checking filter for our packet" )
Jon Hall602d0a72017-05-24 16:06:53 -0700661 stepResultH2 = main.h2.checkFilter()
kavitha Alagesan373e0552016-11-22 05:22:05 +0530662
663 if stepResultH2:
Jon Hall602d0a72017-05-24 16:06:53 -0700664 main.log.info( "Packet : %s" % main.h2.readPackets() )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530665 else:
Jon Hall602d0a72017-05-24 16:06:53 -0700666 main.h2.killFilter()
kavitha Alagesan373e0552016-11-22 05:22:05 +0530667
668 main.log.info( "Clean up host components" )
669 for host in hosts:
Jon Hall602d0a72017-05-24 16:06:53 -0700670 host.stopScapy()
kavitha Alagesan373e0552016-11-22 05:22:05 +0530671 main.Mininet1.removeHostComponent( "h1" )
672 main.Mininet1.removeHostComponent( "h2" )
673
674 utilities.assert_equals( expect=main.TRUE,
675 actual=stepResultH2,
676 onpass="Packet sent to port 1 is received at port 2 successfully!!!",
677 onfail="Failure!!!Packet sent to port 1 is not received at port 2" )
678
679 def CASE8( self, main ):
Jon Hall602d0a72017-05-24 16:06:53 -0700680 """
kavitha Alagesan373e0552016-11-22 05:22:05 +0530681 Deleting the Group and Flow
Jon Hall602d0a72017-05-24 16:06:53 -0700682 """
kavitha Alagesan373e0552016-11-22 05:22:05 +0530683 import json
684 import time
685 respFlowId = 1
686
687 main.case( "Delete the Group and Flow added through Rest api " )
688 main.step( "Deleting Group and Flows" )
689
690 #Getting Flow ID
Jon Hall602d0a72017-05-24 16:06:53 -0700691 response = main.ONOSrest.getFlows( deviceId=deviceId )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530692 responsejson = json.loads( response )
Jon Hall602d0a72017-05-24 16:06:53 -0700693 for item in responsejson:
694 if item[ "priority" ] == int( priority ):
695 respFlowId = item[ "id" ]
kavitha Alagesan373e0552016-11-22 05:22:05 +0530696
697 main.step( "Deleting the created flow by deviceId and flowId" )
Jon Hall602d0a72017-05-24 16:06:53 -0700698 flowResponse = main.ONOSrest.removeFlow( deviceId=deviceId,
699 flowId=respFlowId )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530700
701 utilities.assert_equals( expect=main.TRUE,
702 actual=flowResponse,
703 onpass="Deleting flow is successful!!!",
704 onfail="Deleting flow is failure!!!" )
705
706 # Giving ONOS time to delete the flow
707 time.sleep( main.delFlowSleep )
708
Jon Hall602d0a72017-05-24 16:06:53 -0700709 groupResponse = main.ONOSrest.removeGroup( deviceId=deviceId,
710 appCookie=appCookie )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530711
712 utilities.assert_equals( expect=main.TRUE,
713 actual=groupResponse,
714 onpass="Deleting Group is successful!!!",
715 onfail="Deleting Group is failure!!!" )
716
717 # Giving ONOS time to delete the group
718 time.sleep( main.delGroupSleep )
719
720 def CASE100( self, main ):
Jon Hall602d0a72017-05-24 16:06:53 -0700721 """
kavitha Alagesan373e0552016-11-22 05:22:05 +0530722 Report errors/warnings/exceptions
Jon Hall602d0a72017-05-24 16:06:53 -0700723 """
kavitha Alagesan373e0552016-11-22 05:22:05 +0530724 main.log.info( "Error report: \n" )
725 main.ONOSbench.logReport( main.ONOSip[ 0 ],
726 [ "INFO",
727 "FOLLOWER",
728 "WARN",
729 "flow",
730 "group",
731 "ERROR",
732 "Except" ],
733 "s" )