blob: ea39f445905123fcfbcee68fdecd40dbaf935be2 [file] [log] [blame]
Jeremy Ronquillob27ce4c2017-07-17 12:41:28 -07001"""
2Copyright 2016 Open Networking Foundation (ONF)
3
4Please refer questions to either the onos test mailing list at <onos-test@onosproject.org>,
5the System Testing Plans and Results wiki page at <https://wiki.onosproject.org/x/voMg>,
6or the System Testing Guide page at <https://wiki.onosproject.org/x/WYQg>
7
8 TestON is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 2 of the License, or
11 (at your option) any later version.
12
13 TestON is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with TestON. If not, see <http://www.gnu.org/licenses/>.
20"""
21
kavitha Alagesan373e0552016-11-22 05:22:05 +053022class FUNCgroup:
23
24 def __init__( self ):
25 self.default = ''
26
27 def CASE1( self, main ):
28 import os
29 import imp
kavitha Alagesan373e0552016-11-22 05:22:05 +053030 """
31 - Construct tests variables
32 - GIT ( optional )
33 - Checkout ONOS master branch
34 - Pull latest ONOS code
35 - Building ONOS ( optional )
36 - Install ONOS package
37 - Build ONOS package
38 """
Devin Lim58046fa2017-07-05 16:55:00 -070039 try:
40 from tests.dependencies.ONOSSetup import ONOSSetup
41 main.testSetUp = ONOSSetup()
42 except ImportError:
43 main.log.error( "ONOSSetup not found. exiting the test" )
44 main.exit()
45 main.testSetUp.envSetupDescription()
46 stepResult = main.FALSE
kavitha Alagesan373e0552016-11-22 05:22:05 +053047
Devin Lim58046fa2017-07-05 16:55:00 -070048 try:
49 # Test variables
50 main.cellName = main.params['ENV']['cellName']
51 main.apps = main.params['ENV']['cellApps']
52 main.ONOSport = main.params['CTRL']['port']
53 main.dependencyPath = main.testOnDirectory + \
54 main.params['DEPENDENCY']['path']
55 wrapperFile1 = main.params['DEPENDENCY']['wrapper1']
56 wrapperFile2 = main.params['DEPENDENCY']['wrapper2']
57 main.topology = main.params['DEPENDENCY']['topology']
58 bucket = main.params['DEPENDENCY']['bucket']
59 main.maxNodes = int(main.params['SCALE']['max'])
60 main.startUpSleep = int(main.params['SLEEP']['startup'])
61 main.startMNSleep = int(main.params['SLEEP']['startMN'])
62 main.addFlowSleep = int(main.params['SLEEP']['addFlow'])
63 main.delFlowSleep = int(main.params['SLEEP']['delFlow'])
64 main.addGroupSleep = int(main.params['SLEEP']['addGroup'])
65 main.delGroupSleep = int(main.params['SLEEP']['delGroup'])
66 main.debug = main.params['DEBUG']
67 main.swDPID = main.params['TEST']['swDPID']
68 egressPort1 = main.params['TEST']['egressPort1']
69 egressPort2 = main.params['TEST']['egressPort2']
70 egressPort3 = main.params['TEST']['egressPort3']
71 ingressPort = main.params['TEST']['ingressPort']
72 appCookie = main.params['TEST']['appCookie']
73 type1 = main.params['TEST']['type1']
74 type2 = main.params['TEST']['type2']
75 groupId = main.params['TEST']['groupId']
76 priority = main.params['TEST']['priority']
77 deviceId = main.params['TEST']['swDPID']
kavitha Alagesan373e0552016-11-22 05:22:05 +053078
Devin Lim58046fa2017-07-05 16:55:00 -070079 main.debug = True if "on" in main.debug else False
80 # -- INIT SECTION, ONLY RUNS ONCE -- #
kavitha Alagesan373e0552016-11-22 05:22:05 +053081
Devin Lim58046fa2017-07-05 16:55:00 -070082 main.buckets = imp.load_source(bucket,
83 main.dependencyPath +
84 bucket +
85 ".py")
kavitha Alagesan373e0552016-11-22 05:22:05 +053086
Devin Lim58046fa2017-07-05 16:55:00 -070087 copyResult = main.ONOSbench.scp(main.Mininet1,
88 main.dependencyPath + main.topology,
89 main.Mininet1.home + '/custom/',
90 direction="to")
kavitha Alagesan373e0552016-11-22 05:22:05 +053091
Devin Lim58046fa2017-07-05 16:55:00 -070092 utilities.assert_equals(expect=main.TRUE,
93 actual=copyResult,
94 onpass="Successfully copy " + "test variables ",
95 onfail="Failed to copy test variables")
96 stepResult = main.testSetUp.envSetup()
kavitha Alagesan373e0552016-11-22 05:22:05 +053097
Devin Lim58046fa2017-07-05 16:55:00 -070098 except Exception as e:
99 main.testSetUp.envSetupException( e )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530100
Devin Lim58046fa2017-07-05 16:55:00 -0700101 main.testSetUp.evnSetupConclusion( stepResult )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530102
kavitha Alagesan373e0552016-11-22 05:22:05 +0530103
kavitha Alagesan373e0552016-11-22 05:22:05 +0530104
kavitha Alagesan373e0552016-11-22 05:22:05 +0530105 def CASE2( self, main ):
106 """
107 - Set up cell
108 - Create cell file
109 - Set cell file
110 - Verify cell file
111 - Kill ONOS process
112 - Uninstall ONOS cluster
113 - Verify ONOS start up
114 - Install ONOS cluster
115 - Connect to cli
116 """
Devin Lim58046fa2017-07-05 16:55:00 -0700117 main.testSetUp.ONOSSetUp( main.Mininet1 )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530118
119 def CASE3( self, main ):
Jon Hall602d0a72017-05-24 16:06:53 -0700120 """
kavitha Alagesan373e0552016-11-22 05:22:05 +0530121 Start Mininet
Jon Hall602d0a72017-05-24 16:06:53 -0700122 """
kavitha Alagesan373e0552016-11-22 05:22:05 +0530123 import json
Devin Lim58046fa2017-07-05 16:55:00 -0700124 import time
125 try:
126 from tests.dependencies.topology import Topology
127 except ImportError:
128 main.log.error( "Topology not found exiting the test" )
129 main.exit()
130 try:
131 main.topoRelated
132 except ( NameError, AttributeError ):
133 main.topoRelated = Topology()
kavitha Alagesan373e0552016-11-22 05:22:05 +0530134
135 main.case( "Setup mininet and compare ONOS topology view to Mininet topology" )
136 main.caseExplanation = "Start mininet with custom topology and compare topology " +\
137 "elements between Mininet and ONOS"
138
139 main.step( "Setup Mininet Topology" )
140 topology = main.Mininet1.home + '/custom/' + main.topology
Jon Hall602d0a72017-05-24 16:06:53 -0700141 stepResult = main.Mininet1.startNet( topoFile=topology )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530142
143 utilities.assert_equals( expect=main.TRUE,
144 actual=stepResult,
145 onpass="Successfully loaded topology",
146 onfail="Failed to load topology" )
147
148 main.step( "Assign switch to controller" )
Jon Hall602d0a72017-05-24 16:06:53 -0700149 stepResult = main.Mininet1.assignSwController( "s1", main.ONOSip[ 0 ] )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530150
151 utilities.assert_equals( expect=main.TRUE,
152 actual=stepResult,
153 onpass="Successfully assigned switch to controller",
154 onfail="Failed to assign switch to controller" )
155
156 time.sleep( main.startMNSleep )
157
Devin Lim58046fa2017-07-05 16:55:00 -0700158 main.topoRelated.compareTopos( main.Mininet1 )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530159
160 def CASE4( self, main ):
Jon Hall602d0a72017-05-24 16:06:53 -0700161 """
kavitha Alagesan373e0552016-11-22 05:22:05 +0530162 Testing scapy
Jon Hall602d0a72017-05-24 16:06:53 -0700163 """
kavitha Alagesan373e0552016-11-22 05:22:05 +0530164 main.case( "Testing scapy" )
165 main.step( "Creating Host1 component" )
166 main.Scapy.createHostComponent( "h1" )
167 main.Scapy.createHostComponent( "h2" )
168 hosts = [ main.h1, main.h2 ]
169 for host in hosts:
Jon Hall602d0a72017-05-24 16:06:53 -0700170 host.startHostCli()
171 host.startScapy()
172 host.updateSelf()
kavitha Alagesan373e0552016-11-22 05:22:05 +0530173 main.log.debug( host.name )
174 main.log.debug( host.hostIp )
175 main.log.debug( host.hostMac )
176
177 main.step( "Sending/Receiving Test packet - Filter doesn't match" )
178 main.log.info( "Starting Filter..." )
Jon Hall602d0a72017-05-24 16:06:53 -0700179 main.h2.startFilter()
kavitha Alagesan373e0552016-11-22 05:22:05 +0530180 main.log.info( "Building Ether frame..." )
181 main.h1.buildEther( dst=main.h2.hostMac )
182 main.log.info( "Sending Packet..." )
Jon Hall602d0a72017-05-24 16:06:53 -0700183 main.h1.sendPacket()
kavitha Alagesan373e0552016-11-22 05:22:05 +0530184 main.log.info( "Checking Filter..." )
Jon Hall602d0a72017-05-24 16:06:53 -0700185 finished = main.h2.checkFilter()
kavitha Alagesan373e0552016-11-22 05:22:05 +0530186 main.log.debug( finished )
187 i = ""
188 if finished:
Jon Hall602d0a72017-05-24 16:06:53 -0700189 a = main.h2.readPackets()
190 for i in a.splitlines():
kavitha Alagesan373e0552016-11-22 05:22:05 +0530191 main.log.info( i )
192 else:
Jon Hall602d0a72017-05-24 16:06:53 -0700193 kill = main.h2.killFilter()
kavitha Alagesan373e0552016-11-22 05:22:05 +0530194 main.log.debug( kill )
195 main.h2.handle.sendline( "" )
196 main.h2.handle.expect( main.h2.scapyPrompt )
197 main.log.debug( main.h2.handle.before )
198 utilities.assert_equals( expect=True,
199 actual="dst=00:00:00:00:00:02 src=00:00:00:00:00:01" in i,
200 onpass="Pass",
201 onfail="Fail" )
202
203 main.step( "Sending/Receiving Test packet - Filter matches" )
Jon Hall602d0a72017-05-24 16:06:53 -0700204 main.h2.startFilter()
kavitha Alagesan373e0552016-11-22 05:22:05 +0530205 main.h1.buildEther( dst=main.h2.hostMac )
206 main.h1.buildIP( dst=main.h2.hostIp )
Jon Hall602d0a72017-05-24 16:06:53 -0700207 main.h1.sendPacket()
208 finished = main.h2.checkFilter()
kavitha Alagesan373e0552016-11-22 05:22:05 +0530209 i = ""
210 if finished:
Jon Hall602d0a72017-05-24 16:06:53 -0700211 a = main.h2.readPackets()
212 for i in a.splitlines():
kavitha Alagesan373e0552016-11-22 05:22:05 +0530213 main.log.info( i )
214 else:
Jon Hall602d0a72017-05-24 16:06:53 -0700215 kill = main.h2.killFilter()
kavitha Alagesan373e0552016-11-22 05:22:05 +0530216 main.log.debug( kill )
217 main.h2.handle.sendline( "" )
218 main.h2.handle.expect( main.h2.scapyPrompt )
219 main.log.debug( main.h2.handle.before )
220 utilities.assert_equals( expect=True,
221 actual="dst=00:00:00:00:00:02 src=00:00:00:00:00:01" in i,
222 onpass="Pass",
223 onfail="Fail" )
224
kavitha Alagesan373e0552016-11-22 05:22:05 +0530225 main.step( "Clean up host components" )
226 for host in hosts:
Jon Hall602d0a72017-05-24 16:06:53 -0700227 host.stopScapy()
kavitha Alagesan373e0552016-11-22 05:22:05 +0530228 main.Mininet1.removeHostComponent( "h1" )
229 main.Mininet1.removeHostComponent( "h2" )
230
231 def CASE5( self, main ):
Jon Hall602d0a72017-05-24 16:06:53 -0700232 """
kavitha Alagesan373e0552016-11-22 05:22:05 +0530233 Adding Group of type "ALL" using Rest api
Jon Hall602d0a72017-05-24 16:06:53 -0700234 """
kavitha Alagesan373e0552016-11-22 05:22:05 +0530235 import json
236 import time
237 isAdded = main.FALSE
238 main.case( "Verify Group of type All are successfully Added" )
239 main.caseExplanation = " Install a Group of type ALL " +\
240 " Verify the Group is Added " +\
241 " Add a flow using the group " +\
242 " Send a packet that verifies the action bucket of the group"
243
244 main.step( "Add Group using Rest api" )
245 bucketList = []
Jon Hall602d0a72017-05-24 16:06:53 -0700246 bucket = main.buckets.addBucket( main, egressPort=egressPort1 )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530247 bucketList.append( bucket )
Jon Hall602d0a72017-05-24 16:06:53 -0700248 bucket = main.buckets.addBucket( main, egressPort=egressPort2 )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530249 bucketList.append( bucket )
Jon Hall602d0a72017-05-24 16:06:53 -0700250 bucket = main.buckets.addBucket( main, egressPort=egressPort3 )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530251 bucketList.append( bucket )
Jon Hall602d0a72017-05-24 16:06:53 -0700252 response = main.ONOSrest.addGroup( deviceId=deviceId,
253 groupType=type1,
254 bucketList=bucketList,
255 appCookie=appCookie,
256 groupId=groupId )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530257
258 utilities.assert_equals( expect=main.TRUE,
259 actual=response,
260 onpass="Successfully added Groups of type ALL",
261 onfail="Failed to add Groups of type ALL" )
262
263 # Giving ONOS time to add the group
264 time.sleep( main.addGroupSleep )
265
266 main.step( "Check groups are in ADDED state" )
267
Jon Hall602d0a72017-05-24 16:06:53 -0700268 response = main.ONOSrest.getGroups( deviceId=deviceId,
269 appCookie=appCookie )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530270 responsejson = json.loads( response )
Jon Hall602d0a72017-05-24 16:06:53 -0700271 for item in responsejson:
272 if item[ "state" ] == "ADDED":
kavitha Alagesan373e0552016-11-22 05:22:05 +0530273 isAdded = main.TRUE
274
275 utilities.assert_equals( expect=main.TRUE,
276 actual=isAdded,
277 onpass="All Group is in Added State",
278 onfail="All Group is not in Added State" )
279
Jon Hall602d0a72017-05-24 16:06:53 -0700280 """
kavitha Alagesan373e0552016-11-22 05:22:05 +0530281 Adding flow using rest api
Jon Hall602d0a72017-05-24 16:06:53 -0700282 """
kavitha Alagesan373e0552016-11-22 05:22:05 +0530283 isAdded = main.FALSE
284
285 main.step( "Adding flow with Group using rest api" )
Jon Hall602d0a72017-05-24 16:06:53 -0700286 response = main.ONOSrest.addFlow( deviceId=deviceId,
287 priority=priority,
288 ingressPort=ingressPort,
289 groupId=groupId )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530290 utilities.assert_equals( expect=main.TRUE,
291 actual=response,
292 onpass="Successfully Added Flows",
293 onfail="Failed to Add flows" )
294
295 # Giving ONOS time to add the flow
296 time.sleep( main.addFlowSleep )
297
Jon Hall602d0a72017-05-24 16:06:53 -0700298 response = main.ONOSrest.getFlows( deviceId=deviceId )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530299 responsejson = json.loads( response )
Jon Hall602d0a72017-05-24 16:06:53 -0700300 for item in responsejson:
301 if item[ "priority" ] == int( priority ) and item[ "state" ] == "ADDED":
kavitha Alagesan373e0552016-11-22 05:22:05 +0530302 isAdded = main.TRUE
303
304 utilities.assert_equals( expect=main.TRUE,
305 actual=isAdded,
306 onpass="Flow is in Added State",
307 onfail="Flow is not in Added State" )
308
Jon Hall602d0a72017-05-24 16:06:53 -0700309 """
kavitha Alagesan373e0552016-11-22 05:22:05 +0530310 Sends a packet using scapy
Jon Hall602d0a72017-05-24 16:06:53 -0700311 """
Devin Lim58046fa2017-07-05 16:55:00 -0700312 main.step( "Testing Group by sending packet using Scapy" )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530313 main.log.info( "Creating host components" )
314 main.Scapy.createHostComponent( "h1" )
315 main.Scapy.createHostComponent( "h2" )
316 main.Scapy.createHostComponent( "h3" )
317 main.Scapy.createHostComponent( "h4" )
318
Jon Hall602d0a72017-05-24 16:06:53 -0700319 hosts = [ main.h1, main.h2, main.h3, main.h4 ]
kavitha Alagesan373e0552016-11-22 05:22:05 +0530320 for host in hosts:
Jon Hall602d0a72017-05-24 16:06:53 -0700321 host.startHostCli()
322 host.startScapy()
323 host.updateSelf()
kavitha Alagesan373e0552016-11-22 05:22:05 +0530324 main.log.info( "Constructing Packet" )
325 main.h1.buildEther( dst=main.h1.hostMac )
326 main.h1.buildIP( dst=main.h1.hostIp )
327 main.log.info( "Start Filter on host2,host3,host4" )
328 main.h2.startFilter( pktFilter="ether host %s and ip host %s" % ( main.h1.hostMac, main.h1.hostIp ) )
329 main.h3.startFilter( pktFilter="ether host %s and ip host %s" % ( main.h1.hostMac, main.h1.hostIp ) )
330 main.h4.startFilter( pktFilter="ether host %s and ip host %s" % ( main.h1.hostMac, main.h1.hostIp ) )
331 main.log.info( "sending packet to Host" )
Jon Hall602d0a72017-05-24 16:06:53 -0700332 main.h1.sendPacket()
kavitha Alagesan373e0552016-11-22 05:22:05 +0530333 main.log.info( "Checking filter for our packet" )
Jon Hall602d0a72017-05-24 16:06:53 -0700334 stepResultH2 = main.h2.checkFilter()
335 stepResultH3 = main.h3.checkFilter()
336 stepResultH4 = main.h4.checkFilter()
kavitha Alagesan373e0552016-11-22 05:22:05 +0530337
338 if stepResultH2:
Jon Hall602d0a72017-05-24 16:06:53 -0700339 main.log.info( "Packet : %s" % main.h2.readPackets() )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530340 else:
Jon Hall602d0a72017-05-24 16:06:53 -0700341 main.h2.killFilter()
kavitha Alagesan373e0552016-11-22 05:22:05 +0530342
343 if stepResultH3:
Jon Hall602d0a72017-05-24 16:06:53 -0700344 main.log.info( "Packet : %s" % main.h3.readPackets() )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530345 else:
Jon Hall602d0a72017-05-24 16:06:53 -0700346 main.h2.killFilter()
kavitha Alagesan373e0552016-11-22 05:22:05 +0530347
348 if stepResultH4:
Jon Hall602d0a72017-05-24 16:06:53 -0700349 main.log.info( "Packet : %s" % main.h4.readPackets() )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530350 else:
Jon Hall602d0a72017-05-24 16:06:53 -0700351 main.h4.killFilter()
kavitha Alagesan373e0552016-11-22 05:22:05 +0530352
Jon Hall602d0a72017-05-24 16:06:53 -0700353 if stepResultH2 and stepResultH3 and stepResultH4:
kavitha Alagesan373e0552016-11-22 05:22:05 +0530354 main.log.info( "Success!!!Packet sent to port 1 is received at port 2,3 and 4" )
355 stepResult = main.TRUE
356 else:
357 main.log.info( "Failure!!!Packet sent to port 1 is not received at port 2,3 and 4" )
358 stepResult = main.FALSE
359
360 main.log.info( "Clean up host components" )
361 for host in hosts:
Jon Hall602d0a72017-05-24 16:06:53 -0700362 host.stopScapy()
kavitha Alagesan373e0552016-11-22 05:22:05 +0530363 main.Mininet1.removeHostComponent( "h1" )
364 main.Mininet1.removeHostComponent( "h2" )
365 main.Mininet1.removeHostComponent( "h3" )
366 main.Mininet1.removeHostComponent( "h4" )
367
368 utilities.assert_equals( expect=main.TRUE,
369 actual=stepResult,
370 onpass="Packet sent to port 1 is received at port 2,3,4 ",
371 onfail="Packet sent to port 1 is not received at port 2,3,4 " )
372
373 def CASE6( self, main ):
Jon Hall602d0a72017-05-24 16:06:53 -0700374 """
kavitha Alagesan373e0552016-11-22 05:22:05 +0530375 Deleting the Group and Flow
Jon Hall602d0a72017-05-24 16:06:53 -0700376 """
kavitha Alagesan373e0552016-11-22 05:22:05 +0530377 import json
378 import time
379 respFlowId = 1
380
381 main.case( "Delete the Group and Flow added through Rest api " )
382 main.step( "Deleting Group and Flows" )
383
384 #Get Flow ID
Jon Hall602d0a72017-05-24 16:06:53 -0700385 response = main.ONOSrest.getFlows( deviceId=deviceId )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530386 responsejson = json.loads( response )
Jon Hall602d0a72017-05-24 16:06:53 -0700387 for item in responsejson:
388 if item[ "priority" ] == int( priority ):
389 respFlowId = item[ "id" ]
kavitha Alagesan373e0552016-11-22 05:22:05 +0530390
391 main.step( "Deleting the created flow by deviceId and flowId" )
Jon Hall602d0a72017-05-24 16:06:53 -0700392 flowResponse = main.ONOSrest.removeFlow( deviceId=deviceId,
393 flowId=respFlowId )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530394
395 utilities.assert_equals( expect=main.TRUE,
396 actual=flowResponse,
397 onpass="Deleting flow is successful!!!",
398 onfail="Deleting flow is failure!!!" )
399
400 # Giving ONOS time to delete the flow
401 time.sleep( main.delFlowSleep )
402
403 main.step( "Deleting the created group by deviceId and appCookie" )
Jon Hall602d0a72017-05-24 16:06:53 -0700404 groupResponse = main.ONOSrest.removeGroup( deviceId=deviceId,
405 appCookie=appCookie )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530406
407 utilities.assert_equals( expect=main.TRUE,
408 actual=groupResponse,
409 onpass="Deleting Group is successful!!!",
410 onfail="Deleting Group is failure!!!" )
411
412 # Giving ONOS time to delete the group
413 time.sleep( main.delGroupSleep )
414
415 def CASE7( self, main ):
Jon Hall602d0a72017-05-24 16:06:53 -0700416 """
kavitha Alagesan373e0552016-11-22 05:22:05 +0530417 Adding Group of type "INDIRECT" using Rest api.
Jon Hall602d0a72017-05-24 16:06:53 -0700418 """
kavitha Alagesan373e0552016-11-22 05:22:05 +0530419 import json
420 import time
421 isAdded = main.FALSE
422
423 main.case( "Verify Group of type INDIRECT are successfully Added" )
424 main.caseExplanation = " Install a Group of type INDIRECT " +\
425 " Verify the Group is Added " +\
426 " Add a flow using the group " +\
427 " Send a packet that verifies the action bucket of the group"
428
429 main.step( "Add Group using Rest api" )
430 bucketList = []
Jon Hall602d0a72017-05-24 16:06:53 -0700431 bucket = main.buckets.addBucket( main, egressPort=egressPort1 )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530432 bucketList.append( bucket )
Jon Hall602d0a72017-05-24 16:06:53 -0700433 response = main.ONOSrest.addGroup( deviceId=deviceId,
434 groupType=type2,
435 bucketList=bucketList,
436 appCookie=appCookie,
437 groupId=groupId )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530438
439 utilities.assert_equals( expect=main.TRUE,
440 actual=response,
441 onpass="Successfully added Groups of type INDIRECT",
442 onfail="Failed to add Groups of type INDIRECT" )
443
444 # Giving ONOS time to add the group
445 time.sleep( main.addGroupSleep )
446
447 main.step( "Check groups are in ADDED state" )
448
Jon Hall602d0a72017-05-24 16:06:53 -0700449 response = main.ONOSrest.getGroups( deviceId=deviceId,
450 appCookie=appCookie )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530451 responsejson = json.loads( response )
Jon Hall602d0a72017-05-24 16:06:53 -0700452 for item in responsejson:
453 if item[ "state" ] == "ADDED":
kavitha Alagesan373e0552016-11-22 05:22:05 +0530454 isAdded = main.TRUE
455
456 utilities.assert_equals( expect=main.TRUE,
457 actual=isAdded,
458 onpass="INDIRECT Group is in Added State",
459 onfail="INDIRECT Group is not in Added State" )
460
Jon Hall602d0a72017-05-24 16:06:53 -0700461 """
kavitha Alagesan373e0552016-11-22 05:22:05 +0530462 Adding flows using rest api
Jon Hall602d0a72017-05-24 16:06:53 -0700463 """
kavitha Alagesan373e0552016-11-22 05:22:05 +0530464 isAdded = main.FALSE
465
466 main.step( "Adding flow with Group using rest api" )
Jon Hall602d0a72017-05-24 16:06:53 -0700467 response = main.ONOSrest.addFlow( deviceId=deviceId,
468 priority=priority,
469 ingressPort=ingressPort,
470 groupId=groupId )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530471 utilities.assert_equals( expect=main.TRUE,
472 actual=response,
473 onpass="Successfully Added Flows",
474 onfail="Failed to Add flows" )
475
476 # Giving ONOS time to add the flow
477 time.sleep( main.addFlowSleep )
478
Jon Hall602d0a72017-05-24 16:06:53 -0700479 response = main.ONOSrest.getFlows( deviceId=deviceId )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530480 responsejson = json.loads( response )
Jon Hall602d0a72017-05-24 16:06:53 -0700481 for item in responsejson:
482 if item[ "priority" ] == int( priority ) and item[ "state" ] == "ADDED":
kavitha Alagesan373e0552016-11-22 05:22:05 +0530483 isAdded = main.TRUE
484
485 utilities.assert_equals( expect=main.TRUE,
486 actual=isAdded,
487 onpass="Flow is in Added State",
488 onfail="Flow is not in Added State" )
489
Jon Hall602d0a72017-05-24 16:06:53 -0700490 """
kavitha Alagesan373e0552016-11-22 05:22:05 +0530491 Sends a packet using scapy
Jon Hall602d0a72017-05-24 16:06:53 -0700492 """
Devin Lim58046fa2017-07-05 16:55:00 -0700493 main.step( "Testing Group by sending packet using Scapy" )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530494 main.log.info( "Creating host components" )
495 main.Scapy.createHostComponent( "h1" )
496 main.Scapy.createHostComponent( "h2" )
497
Jon Hall602d0a72017-05-24 16:06:53 -0700498 hosts = [ main.h1, main.h2 ]
kavitha Alagesan373e0552016-11-22 05:22:05 +0530499 for host in hosts:
Jon Hall602d0a72017-05-24 16:06:53 -0700500 host.startHostCli()
501 host.startScapy()
502 host.updateSelf()
kavitha Alagesan373e0552016-11-22 05:22:05 +0530503 main.log.info( "Constructing Packet" )
504 main.h1.buildEther( dst=main.h1.hostMac )
505 main.h1.buildIP( dst=main.h1.hostIp )
506 main.log.info( "Start Filter on host2" )
507 main.h2.startFilter( pktFilter="ether host %s and ip host %s" % ( main.h1.hostMac, main.h1.hostIp ) )
508 main.log.info( "sending packet to Host" )
Jon Hall602d0a72017-05-24 16:06:53 -0700509 main.h1.sendPacket()
kavitha Alagesan373e0552016-11-22 05:22:05 +0530510 main.log.info( "Checking filter for our packet" )
Jon Hall602d0a72017-05-24 16:06:53 -0700511 stepResultH2 = main.h2.checkFilter()
kavitha Alagesan373e0552016-11-22 05:22:05 +0530512
513 if stepResultH2:
Jon Hall602d0a72017-05-24 16:06:53 -0700514 main.log.info( "Packet : %s" % main.h2.readPackets() )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530515 else:
Jon Hall602d0a72017-05-24 16:06:53 -0700516 main.h2.killFilter()
kavitha Alagesan373e0552016-11-22 05:22:05 +0530517
518 main.log.info( "Clean up host components" )
519 for host in hosts:
Jon Hall602d0a72017-05-24 16:06:53 -0700520 host.stopScapy()
kavitha Alagesan373e0552016-11-22 05:22:05 +0530521 main.Mininet1.removeHostComponent( "h1" )
522 main.Mininet1.removeHostComponent( "h2" )
523
524 utilities.assert_equals( expect=main.TRUE,
525 actual=stepResultH2,
526 onpass="Packet sent to port 1 is received at port 2 successfully!!!",
527 onfail="Failure!!!Packet sent to port 1 is not received at port 2" )
528
kavitha Alagesan373e0552016-11-22 05:22:05 +0530529 def CASE100( self, main ):
Jon Hall602d0a72017-05-24 16:06:53 -0700530 """
kavitha Alagesan373e0552016-11-22 05:22:05 +0530531 Report errors/warnings/exceptions
Jon Hall602d0a72017-05-24 16:06:53 -0700532 """
kavitha Alagesan373e0552016-11-22 05:22:05 +0530533 main.log.info( "Error report: \n" )
534 main.ONOSbench.logReport( main.ONOSip[ 0 ],
535 [ "INFO",
536 "FOLLOWER",
537 "WARN",
538 "flow",
539 "group",
540 "ERROR",
541 "Except" ],
542 "s" )