blob: 8e067471c41a7e104804bf6c1f610141aa48db3a [file] [log] [blame]
Jeremy Ronquillob27ce4c2017-07-17 12:41:28 -07001"""
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -07002Copyright 2016 Open Networking Foundation ( ONF )
Jeremy Ronquillob27ce4c2017-07-17 12:41:28 -07003
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
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070011 ( at your option ) any later version.
Jeremy Ronquillob27ce4c2017-07-17 12:41:28 -070012
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"""
kavitha Alagesan373e0552016-11-22 05:22:05 +053021class FUNCgroup:
22
23 def __init__( self ):
24 self.default = ''
25
26 def CASE1( self, main ):
27 import os
28 import imp
kavitha Alagesan373e0552016-11-22 05:22:05 +053029 """
30 - Construct tests variables
31 - GIT ( optional )
32 - Checkout ONOS master branch
33 - Pull latest ONOS code
34 - Building ONOS ( optional )
35 - Install ONOS package
36 - Build ONOS package
37 """
Devin Lim58046fa2017-07-05 16:55:00 -070038 try:
39 from tests.dependencies.ONOSSetup import ONOSSetup
40 main.testSetUp = ONOSSetup()
41 except ImportError:
42 main.log.error( "ONOSSetup not found. exiting the test" )
Devin Lim44075962017-08-11 10:56:37 -070043 main.cleanAndExit()
Devin Lim58046fa2017-07-05 16:55:00 -070044 main.testSetUp.envSetupDescription()
45 stepResult = main.FALSE
kavitha Alagesan373e0552016-11-22 05:22:05 +053046
Devin Lim58046fa2017-07-05 16:55:00 -070047 try:
48 # Test variables
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070049 main.cellName = main.params[ 'ENV' ][ 'cellName' ]
50 main.apps = main.params[ 'ENV' ][ 'cellApps' ]
51 main.ONOSport = main.params[ 'CTRL' ][ 'port' ]
Devin Lim58046fa2017-07-05 16:55:00 -070052 main.dependencyPath = main.testOnDirectory + \
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070053 main.params[ 'DEPENDENCY' ][ 'path' ]
54 wrapperFile1 = main.params[ 'DEPENDENCY' ][ 'wrapper1' ]
55 wrapperFile2 = main.params[ 'DEPENDENCY' ][ 'wrapper2' ]
56 main.topology = main.params[ 'DEPENDENCY' ][ 'topology' ]
57 bucket = main.params[ 'DEPENDENCY' ][ 'bucket' ]
58 main.startUpSleep = int( main.params[ 'SLEEP' ][ 'startup' ] )
59 main.startMNSleep = int( main.params[ 'SLEEP' ][ 'startMN' ] )
60 main.addFlowSleep = int( main.params[ 'SLEEP' ][ 'addFlow' ] )
61 main.delFlowSleep = int( main.params[ 'SLEEP' ][ 'delFlow' ] )
62 main.addGroupSleep = int( main.params[ 'SLEEP' ][ 'addGroup' ] )
63 main.delGroupSleep = int( main.params[ 'SLEEP' ][ 'delGroup' ] )
64 main.debug = main.params[ 'DEBUG' ]
65 main.swDPID = main.params[ 'TEST' ][ 'swDPID' ]
66 egressPort1 = main.params[ 'TEST' ][ 'egressPort1' ]
67 egressPort2 = main.params[ 'TEST' ][ 'egressPort2' ]
68 egressPort3 = main.params[ 'TEST' ][ 'egressPort3' ]
69 ingressPort = main.params[ 'TEST' ][ 'ingressPort' ]
70 appCookie = main.params[ 'TEST' ][ 'appCookie' ]
71 type1 = main.params[ 'TEST' ][ 'type1' ]
72 type2 = main.params[ 'TEST' ][ 'type2' ]
73 groupId = main.params[ 'TEST' ][ 'groupId' ]
74 priority = main.params[ 'TEST' ][ 'priority' ]
75 deviceId = main.params[ 'TEST' ][ 'swDPID' ]
kavitha Alagesan373e0552016-11-22 05:22:05 +053076
Devin Lim58046fa2017-07-05 16:55:00 -070077 main.debug = True if "on" in main.debug else False
78 # -- INIT SECTION, ONLY RUNS ONCE -- #
kavitha Alagesan373e0552016-11-22 05:22:05 +053079
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070080 main.buckets = imp.load_source( bucket,
81 main.dependencyPath +
82 bucket +
83 ".py" )
kavitha Alagesan373e0552016-11-22 05:22:05 +053084
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070085 copyResult = main.ONOSbench.scp( main.Mininet1,
86 main.dependencyPath + main.topology,
87 main.Mininet1.home + '/custom/',
88 direction="to" )
kavitha Alagesan373e0552016-11-22 05:22:05 +053089
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070090 utilities.assert_equals( expect=main.TRUE,
91 actual=copyResult,
92 onpass="Successfully copy " + "test variables ",
93 onfail="Failed to copy test variables" )
Devin Lim58046fa2017-07-05 16:55:00 -070094 stepResult = main.testSetUp.envSetup()
kavitha Alagesan373e0552016-11-22 05:22:05 +053095
Devin Lim58046fa2017-07-05 16:55:00 -070096 except Exception as e:
97 main.testSetUp.envSetupException( e )
kavitha Alagesan373e0552016-11-22 05:22:05 +053098
Devin Lim58046fa2017-07-05 16:55:00 -070099 main.testSetUp.evnSetupConclusion( stepResult )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530100
kavitha Alagesan373e0552016-11-22 05:22:05 +0530101 def CASE2( self, main ):
102 """
103 - Set up cell
104 - Create cell file
105 - Set cell file
106 - Verify cell file
107 - Kill ONOS process
108 - Uninstall ONOS cluster
109 - Verify ONOS start up
110 - Install ONOS cluster
111 - Connect to cli
112 """
Devin Lim142b5342017-07-20 15:22:39 -0700113 main.testSetUp.ONOSSetUp( main.Mininet1, main.Cluster )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530114
115 def CASE3( self, main ):
Jon Hall602d0a72017-05-24 16:06:53 -0700116 """
kavitha Alagesan373e0552016-11-22 05:22:05 +0530117 Start Mininet
Jon Hall602d0a72017-05-24 16:06:53 -0700118 """
kavitha Alagesan373e0552016-11-22 05:22:05 +0530119 import json
Devin Lim58046fa2017-07-05 16:55:00 -0700120 import time
121 try:
122 from tests.dependencies.topology import Topology
123 except ImportError:
124 main.log.error( "Topology not found exiting the test" )
Devin Lim44075962017-08-11 10:56:37 -0700125 main.cleanAndExit()
Devin Lim58046fa2017-07-05 16:55:00 -0700126 try:
127 main.topoRelated
128 except ( NameError, AttributeError ):
129 main.topoRelated = Topology()
kavitha Alagesan373e0552016-11-22 05:22:05 +0530130
131 main.case( "Setup mininet and compare ONOS topology view to Mininet topology" )
132 main.caseExplanation = "Start mininet with custom topology and compare topology " +\
133 "elements between Mininet and ONOS"
134
135 main.step( "Setup Mininet Topology" )
136 topology = main.Mininet1.home + '/custom/' + main.topology
Jon Hall602d0a72017-05-24 16:06:53 -0700137 stepResult = main.Mininet1.startNet( topoFile=topology )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530138
139 utilities.assert_equals( expect=main.TRUE,
140 actual=stepResult,
141 onpass="Successfully loaded topology",
142 onfail="Failed to load topology" )
143
144 main.step( "Assign switch to controller" )
Devin Lim142b5342017-07-20 15:22:39 -0700145 stepResult = main.Mininet1.assignSwController( "s1", main.Cluster.active( 0 ).ipAddress )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530146
147 utilities.assert_equals( expect=main.TRUE,
148 actual=stepResult,
149 onpass="Successfully assigned switch to controller",
150 onfail="Failed to assign switch to controller" )
151
152 time.sleep( main.startMNSleep )
153
Devin Lim58046fa2017-07-05 16:55:00 -0700154 main.topoRelated.compareTopos( main.Mininet1 )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530155
156 def CASE4( self, main ):
Jon Hall602d0a72017-05-24 16:06:53 -0700157 """
kavitha Alagesan373e0552016-11-22 05:22:05 +0530158 Testing scapy
Jon Hall602d0a72017-05-24 16:06:53 -0700159 """
kavitha Alagesan373e0552016-11-22 05:22:05 +0530160 main.case( "Testing scapy" )
161 main.step( "Creating Host1 component" )
162 main.Scapy.createHostComponent( "h1" )
163 main.Scapy.createHostComponent( "h2" )
164 hosts = [ main.h1, main.h2 ]
165 for host in hosts:
Jon Hall602d0a72017-05-24 16:06:53 -0700166 host.startHostCli()
167 host.startScapy()
168 host.updateSelf()
kavitha Alagesan373e0552016-11-22 05:22:05 +0530169 main.log.debug( host.name )
170 main.log.debug( host.hostIp )
171 main.log.debug( host.hostMac )
172
173 main.step( "Sending/Receiving Test packet - Filter doesn't match" )
174 main.log.info( "Starting Filter..." )
Jon Hall602d0a72017-05-24 16:06:53 -0700175 main.h2.startFilter()
kavitha Alagesan373e0552016-11-22 05:22:05 +0530176 main.log.info( "Building Ether frame..." )
177 main.h1.buildEther( dst=main.h2.hostMac )
178 main.log.info( "Sending Packet..." )
Jon Hall602d0a72017-05-24 16:06:53 -0700179 main.h1.sendPacket()
kavitha Alagesan373e0552016-11-22 05:22:05 +0530180 main.log.info( "Checking Filter..." )
Jon Hall602d0a72017-05-24 16:06:53 -0700181 finished = main.h2.checkFilter()
kavitha Alagesan373e0552016-11-22 05:22:05 +0530182 main.log.debug( finished )
183 i = ""
184 if finished:
Jon Hall602d0a72017-05-24 16:06:53 -0700185 a = main.h2.readPackets()
186 for i in a.splitlines():
kavitha Alagesan373e0552016-11-22 05:22:05 +0530187 main.log.info( i )
188 else:
Jon Hall602d0a72017-05-24 16:06:53 -0700189 kill = main.h2.killFilter()
kavitha Alagesan373e0552016-11-22 05:22:05 +0530190 main.log.debug( kill )
191 main.h2.handle.sendline( "" )
192 main.h2.handle.expect( main.h2.scapyPrompt )
193 main.log.debug( main.h2.handle.before )
194 utilities.assert_equals( expect=True,
195 actual="dst=00:00:00:00:00:02 src=00:00:00:00:00:01" in i,
196 onpass="Pass",
197 onfail="Fail" )
198
199 main.step( "Sending/Receiving Test packet - Filter matches" )
Jon Hall602d0a72017-05-24 16:06:53 -0700200 main.h2.startFilter()
kavitha Alagesan373e0552016-11-22 05:22:05 +0530201 main.h1.buildEther( dst=main.h2.hostMac )
202 main.h1.buildIP( dst=main.h2.hostIp )
Jon Hall602d0a72017-05-24 16:06:53 -0700203 main.h1.sendPacket()
204 finished = main.h2.checkFilter()
kavitha Alagesan373e0552016-11-22 05:22:05 +0530205 i = ""
206 if finished:
Jon Hall602d0a72017-05-24 16:06:53 -0700207 a = main.h2.readPackets()
208 for i in a.splitlines():
kavitha Alagesan373e0552016-11-22 05:22:05 +0530209 main.log.info( i )
210 else:
Jon Hall602d0a72017-05-24 16:06:53 -0700211 kill = main.h2.killFilter()
kavitha Alagesan373e0552016-11-22 05:22:05 +0530212 main.log.debug( kill )
213 main.h2.handle.sendline( "" )
214 main.h2.handle.expect( main.h2.scapyPrompt )
215 main.log.debug( main.h2.handle.before )
216 utilities.assert_equals( expect=True,
217 actual="dst=00:00:00:00:00:02 src=00:00:00:00:00:01" in i,
218 onpass="Pass",
219 onfail="Fail" )
220
kavitha Alagesan373e0552016-11-22 05:22:05 +0530221 main.step( "Clean up host components" )
222 for host in hosts:
Jon Hall602d0a72017-05-24 16:06:53 -0700223 host.stopScapy()
kavitha Alagesan373e0552016-11-22 05:22:05 +0530224 main.Mininet1.removeHostComponent( "h1" )
225 main.Mininet1.removeHostComponent( "h2" )
226
227 def CASE5( self, main ):
Jon Hall602d0a72017-05-24 16:06:53 -0700228 """
kavitha Alagesan373e0552016-11-22 05:22:05 +0530229 Adding Group of type "ALL" using Rest api
Jon Hall602d0a72017-05-24 16:06:53 -0700230 """
kavitha Alagesan373e0552016-11-22 05:22:05 +0530231 import json
232 import time
233 isAdded = main.FALSE
234 main.case( "Verify Group of type All are successfully Added" )
235 main.caseExplanation = " Install a Group of type ALL " +\
236 " Verify the Group is Added " +\
237 " Add a flow using the group " +\
238 " Send a packet that verifies the action bucket of the group"
239
240 main.step( "Add Group using Rest api" )
241 bucketList = []
Jon Hall602d0a72017-05-24 16:06:53 -0700242 bucket = main.buckets.addBucket( main, egressPort=egressPort1 )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530243 bucketList.append( bucket )
Jon Hall602d0a72017-05-24 16:06:53 -0700244 bucket = main.buckets.addBucket( main, egressPort=egressPort2 )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530245 bucketList.append( bucket )
Jon Hall602d0a72017-05-24 16:06:53 -0700246 bucket = main.buckets.addBucket( main, egressPort=egressPort3 )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530247 bucketList.append( bucket )
Devin Lim142b5342017-07-20 15:22:39 -0700248 ctrl = main.Cluster.active( 0 )
249 response = ctrl.REST.addGroup( deviceId=deviceId,
250 groupType=type1,
251 bucketList=bucketList,
252 appCookie=appCookie,
253 groupId=groupId )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530254
255 utilities.assert_equals( expect=main.TRUE,
256 actual=response,
257 onpass="Successfully added Groups of type ALL",
258 onfail="Failed to add Groups of type ALL" )
259
260 # Giving ONOS time to add the group
261 time.sleep( main.addGroupSleep )
262
263 main.step( "Check groups are in ADDED state" )
264
Devin Lim142b5342017-07-20 15:22:39 -0700265 response = ctrl.REST.getGroups( deviceId=deviceId,
266 appCookie=appCookie )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530267 responsejson = json.loads( response )
Jon Hall602d0a72017-05-24 16:06:53 -0700268 for item in responsejson:
269 if item[ "state" ] == "ADDED":
kavitha Alagesan373e0552016-11-22 05:22:05 +0530270 isAdded = main.TRUE
271
272 utilities.assert_equals( expect=main.TRUE,
273 actual=isAdded,
274 onpass="All Group is in Added State",
275 onfail="All Group is not in Added State" )
276
Jon Hall602d0a72017-05-24 16:06:53 -0700277 """
kavitha Alagesan373e0552016-11-22 05:22:05 +0530278 Adding flow using rest api
Jon Hall602d0a72017-05-24 16:06:53 -0700279 """
kavitha Alagesan373e0552016-11-22 05:22:05 +0530280 isAdded = main.FALSE
281
282 main.step( "Adding flow with Group using rest api" )
Devin Lim142b5342017-07-20 15:22:39 -0700283 response = ctrl.REST.addFlow( deviceId=deviceId,
284 priority=priority,
285 ingressPort=ingressPort,
286 groupId=groupId )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530287 utilities.assert_equals( expect=main.TRUE,
288 actual=response,
289 onpass="Successfully Added Flows",
290 onfail="Failed to Add flows" )
291
292 # Giving ONOS time to add the flow
293 time.sleep( main.addFlowSleep )
294
Devin Lim142b5342017-07-20 15:22:39 -0700295 response = ctrl.REST.getFlows( deviceId=deviceId )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530296 responsejson = json.loads( response )
Jon Hall602d0a72017-05-24 16:06:53 -0700297 for item in responsejson:
298 if item[ "priority" ] == int( priority ) and item[ "state" ] == "ADDED":
kavitha Alagesan373e0552016-11-22 05:22:05 +0530299 isAdded = main.TRUE
300
301 utilities.assert_equals( expect=main.TRUE,
302 actual=isAdded,
303 onpass="Flow is in Added State",
304 onfail="Flow is not in Added State" )
305
Jon Hall602d0a72017-05-24 16:06:53 -0700306 """
kavitha Alagesan373e0552016-11-22 05:22:05 +0530307 Sends a packet using scapy
Jon Hall602d0a72017-05-24 16:06:53 -0700308 """
Devin Lim58046fa2017-07-05 16:55:00 -0700309 main.step( "Testing Group by sending packet using Scapy" )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530310 main.log.info( "Creating host components" )
311 main.Scapy.createHostComponent( "h1" )
312 main.Scapy.createHostComponent( "h2" )
313 main.Scapy.createHostComponent( "h3" )
314 main.Scapy.createHostComponent( "h4" )
315
Jon Hall602d0a72017-05-24 16:06:53 -0700316 hosts = [ main.h1, main.h2, main.h3, main.h4 ]
kavitha Alagesan373e0552016-11-22 05:22:05 +0530317 for host in hosts:
Jon Hall602d0a72017-05-24 16:06:53 -0700318 host.startHostCli()
319 host.startScapy()
320 host.updateSelf()
kavitha Alagesan373e0552016-11-22 05:22:05 +0530321 main.log.info( "Constructing Packet" )
322 main.h1.buildEther( dst=main.h1.hostMac )
323 main.h1.buildIP( dst=main.h1.hostIp )
324 main.log.info( "Start Filter on host2,host3,host4" )
325 main.h2.startFilter( pktFilter="ether host %s and ip host %s" % ( main.h1.hostMac, main.h1.hostIp ) )
326 main.h3.startFilter( pktFilter="ether host %s and ip host %s" % ( main.h1.hostMac, main.h1.hostIp ) )
327 main.h4.startFilter( pktFilter="ether host %s and ip host %s" % ( main.h1.hostMac, main.h1.hostIp ) )
328 main.log.info( "sending packet to Host" )
Jon Hall602d0a72017-05-24 16:06:53 -0700329 main.h1.sendPacket()
kavitha Alagesan373e0552016-11-22 05:22:05 +0530330 main.log.info( "Checking filter for our packet" )
Jon Hall602d0a72017-05-24 16:06:53 -0700331 stepResultH2 = main.h2.checkFilter()
332 stepResultH3 = main.h3.checkFilter()
333 stepResultH4 = main.h4.checkFilter()
kavitha Alagesan373e0552016-11-22 05:22:05 +0530334
335 if stepResultH2:
Jon Hall602d0a72017-05-24 16:06:53 -0700336 main.log.info( "Packet : %s" % main.h2.readPackets() )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530337 else:
Jon Hall602d0a72017-05-24 16:06:53 -0700338 main.h2.killFilter()
kavitha Alagesan373e0552016-11-22 05:22:05 +0530339
340 if stepResultH3:
Jon Hall602d0a72017-05-24 16:06:53 -0700341 main.log.info( "Packet : %s" % main.h3.readPackets() )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530342 else:
Jon Hall602d0a72017-05-24 16:06:53 -0700343 main.h2.killFilter()
kavitha Alagesan373e0552016-11-22 05:22:05 +0530344
345 if stepResultH4:
Jon Hall602d0a72017-05-24 16:06:53 -0700346 main.log.info( "Packet : %s" % main.h4.readPackets() )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530347 else:
Jon Hall602d0a72017-05-24 16:06:53 -0700348 main.h4.killFilter()
kavitha Alagesan373e0552016-11-22 05:22:05 +0530349
Jon Hall602d0a72017-05-24 16:06:53 -0700350 if stepResultH2 and stepResultH3 and stepResultH4:
kavitha Alagesan373e0552016-11-22 05:22:05 +0530351 main.log.info( "Success!!!Packet sent to port 1 is received at port 2,3 and 4" )
352 stepResult = main.TRUE
353 else:
354 main.log.info( "Failure!!!Packet sent to port 1 is not received at port 2,3 and 4" )
355 stepResult = main.FALSE
356
357 main.log.info( "Clean up host components" )
358 for host in hosts:
Jon Hall602d0a72017-05-24 16:06:53 -0700359 host.stopScapy()
kavitha Alagesan373e0552016-11-22 05:22:05 +0530360 main.Mininet1.removeHostComponent( "h1" )
361 main.Mininet1.removeHostComponent( "h2" )
362 main.Mininet1.removeHostComponent( "h3" )
363 main.Mininet1.removeHostComponent( "h4" )
364
365 utilities.assert_equals( expect=main.TRUE,
366 actual=stepResult,
367 onpass="Packet sent to port 1 is received at port 2,3,4 ",
368 onfail="Packet sent to port 1 is not received at port 2,3,4 " )
369
370 def CASE6( self, main ):
Jon Hall602d0a72017-05-24 16:06:53 -0700371 """
kavitha Alagesan373e0552016-11-22 05:22:05 +0530372 Deleting the Group and Flow
Jon Hall602d0a72017-05-24 16:06:53 -0700373 """
kavitha Alagesan373e0552016-11-22 05:22:05 +0530374 import json
375 import time
376 respFlowId = 1
377
378 main.case( "Delete the Group and Flow added through Rest api " )
379 main.step( "Deleting Group and Flows" )
Devin Lim142b5342017-07-20 15:22:39 -0700380 ctrl = main.Cluster.active( 0 )
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700381 # Get Flow ID
Devin Lim142b5342017-07-20 15:22:39 -0700382 response = ctrl.REST.getFlows( deviceId=deviceId )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530383 responsejson = json.loads( response )
Jon Hall602d0a72017-05-24 16:06:53 -0700384 for item in responsejson:
385 if item[ "priority" ] == int( priority ):
386 respFlowId = item[ "id" ]
kavitha Alagesan373e0552016-11-22 05:22:05 +0530387
388 main.step( "Deleting the created flow by deviceId and flowId" )
Devin Lim142b5342017-07-20 15:22:39 -0700389 flowResponse = ctrl.REST.removeFlow( deviceId=deviceId,
390 flowId=respFlowId )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530391
392 utilities.assert_equals( expect=main.TRUE,
393 actual=flowResponse,
394 onpass="Deleting flow is successful!!!",
395 onfail="Deleting flow is failure!!!" )
396
397 # Giving ONOS time to delete the flow
398 time.sleep( main.delFlowSleep )
399
400 main.step( "Deleting the created group by deviceId and appCookie" )
Devin Lim142b5342017-07-20 15:22:39 -0700401 groupResponse = ctrl.REST.removeGroup( deviceId=deviceId,
402 appCookie=appCookie )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530403
404 utilities.assert_equals( expect=main.TRUE,
405 actual=groupResponse,
406 onpass="Deleting Group is successful!!!",
407 onfail="Deleting Group is failure!!!" )
408
409 # Giving ONOS time to delete the group
410 time.sleep( main.delGroupSleep )
411
412 def CASE7( self, main ):
Jon Hall602d0a72017-05-24 16:06:53 -0700413 """
kavitha Alagesan373e0552016-11-22 05:22:05 +0530414 Adding Group of type "INDIRECT" using Rest api.
Jon Hall602d0a72017-05-24 16:06:53 -0700415 """
kavitha Alagesan373e0552016-11-22 05:22:05 +0530416 import json
417 import time
418 isAdded = main.FALSE
419
420 main.case( "Verify Group of type INDIRECT are successfully Added" )
421 main.caseExplanation = " Install a Group of type INDIRECT " +\
422 " Verify the Group is Added " +\
423 " Add a flow using the group " +\
424 " Send a packet that verifies the action bucket of the group"
425
426 main.step( "Add Group using Rest api" )
Devin Lim142b5342017-07-20 15:22:39 -0700427 ctrl = main.Cluster.active( 0 )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530428 bucketList = []
Jon Hall602d0a72017-05-24 16:06:53 -0700429 bucket = main.buckets.addBucket( main, egressPort=egressPort1 )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530430 bucketList.append( bucket )
Devin Lim142b5342017-07-20 15:22:39 -0700431 response = ctrl.REST.addGroup( deviceId=deviceId,
432 groupType=type2,
433 bucketList=bucketList,
434 appCookie=appCookie,
435 groupId=groupId )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530436
437 utilities.assert_equals( expect=main.TRUE,
438 actual=response,
439 onpass="Successfully added Groups of type INDIRECT",
440 onfail="Failed to add Groups of type INDIRECT" )
441
442 # Giving ONOS time to add the group
443 time.sleep( main.addGroupSleep )
444
445 main.step( "Check groups are in ADDED state" )
446
Devin Lim142b5342017-07-20 15:22:39 -0700447 response = ctrl.REST.getGroups( deviceId=deviceId,
448 appCookie=appCookie )
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[ "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="INDIRECT Group is in Added State",
457 onfail="INDIRECT Group is not in Added State" )
458
Jon Hall602d0a72017-05-24 16:06:53 -0700459 """
kavitha Alagesan373e0552016-11-22 05:22:05 +0530460 Adding flows using rest api
Jon Hall602d0a72017-05-24 16:06:53 -0700461 """
kavitha Alagesan373e0552016-11-22 05:22:05 +0530462 isAdded = main.FALSE
463
464 main.step( "Adding flow with Group using rest api" )
Devin Lim142b5342017-07-20 15:22:39 -0700465 response = ctrl.REST.addFlow( deviceId=deviceId,
466 priority=priority,
467 ingressPort=ingressPort,
468 groupId=groupId )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530469 utilities.assert_equals( expect=main.TRUE,
470 actual=response,
471 onpass="Successfully Added Flows",
472 onfail="Failed to Add flows" )
473
474 # Giving ONOS time to add the flow
475 time.sleep( main.addFlowSleep )
476
Devin Lim142b5342017-07-20 15:22:39 -0700477 response = ctrl.REST.getFlows( deviceId=deviceId )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530478 responsejson = json.loads( response )
Jon Hall602d0a72017-05-24 16:06:53 -0700479 for item in responsejson:
480 if item[ "priority" ] == int( priority ) and item[ "state" ] == "ADDED":
kavitha Alagesan373e0552016-11-22 05:22:05 +0530481 isAdded = main.TRUE
482
483 utilities.assert_equals( expect=main.TRUE,
484 actual=isAdded,
485 onpass="Flow is in Added State",
486 onfail="Flow is not in Added State" )
487
Jon Hall602d0a72017-05-24 16:06:53 -0700488 """
kavitha Alagesan373e0552016-11-22 05:22:05 +0530489 Sends a packet using scapy
Jon Hall602d0a72017-05-24 16:06:53 -0700490 """
Devin Lim58046fa2017-07-05 16:55:00 -0700491 main.step( "Testing Group by sending packet using Scapy" )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530492 main.log.info( "Creating host components" )
493 main.Scapy.createHostComponent( "h1" )
494 main.Scapy.createHostComponent( "h2" )
495
Jon Hall602d0a72017-05-24 16:06:53 -0700496 hosts = [ main.h1, main.h2 ]
kavitha Alagesan373e0552016-11-22 05:22:05 +0530497 for host in hosts:
Jon Hall602d0a72017-05-24 16:06:53 -0700498 host.startHostCli()
499 host.startScapy()
500 host.updateSelf()
kavitha Alagesan373e0552016-11-22 05:22:05 +0530501 main.log.info( "Constructing Packet" )
502 main.h1.buildEther( dst=main.h1.hostMac )
503 main.h1.buildIP( dst=main.h1.hostIp )
504 main.log.info( "Start Filter on host2" )
505 main.h2.startFilter( pktFilter="ether host %s and ip host %s" % ( main.h1.hostMac, main.h1.hostIp ) )
506 main.log.info( "sending packet to Host" )
Jon Hall602d0a72017-05-24 16:06:53 -0700507 main.h1.sendPacket()
kavitha Alagesan373e0552016-11-22 05:22:05 +0530508 main.log.info( "Checking filter for our packet" )
Jon Hall602d0a72017-05-24 16:06:53 -0700509 stepResultH2 = main.h2.checkFilter()
kavitha Alagesan373e0552016-11-22 05:22:05 +0530510
511 if stepResultH2:
Jon Hall602d0a72017-05-24 16:06:53 -0700512 main.log.info( "Packet : %s" % main.h2.readPackets() )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530513 else:
Jon Hall602d0a72017-05-24 16:06:53 -0700514 main.h2.killFilter()
kavitha Alagesan373e0552016-11-22 05:22:05 +0530515
516 main.log.info( "Clean up host components" )
517 for host in hosts:
Jon Hall602d0a72017-05-24 16:06:53 -0700518 host.stopScapy()
kavitha Alagesan373e0552016-11-22 05:22:05 +0530519 main.Mininet1.removeHostComponent( "h1" )
520 main.Mininet1.removeHostComponent( "h2" )
521
522 utilities.assert_equals( expect=main.TRUE,
523 actual=stepResultH2,
524 onpass="Packet sent to port 1 is received at port 2 successfully!!!",
525 onfail="Failure!!!Packet sent to port 1 is not received at port 2" )
526
kavitha Alagesan373e0552016-11-22 05:22:05 +0530527 def CASE100( self, main ):
Jon Hall602d0a72017-05-24 16:06:53 -0700528 """
kavitha Alagesan373e0552016-11-22 05:22:05 +0530529 Report errors/warnings/exceptions
Jon Hall602d0a72017-05-24 16:06:53 -0700530 """
kavitha Alagesan373e0552016-11-22 05:22:05 +0530531 main.log.info( "Error report: \n" )
Devin Lim142b5342017-07-20 15:22:39 -0700532 main.ONOSbench.logReport( main.Cluster.active( 0 ).ipAddress,
kavitha Alagesan373e0552016-11-22 05:22:05 +0530533 [ "INFO",
534 "FOLLOWER",
535 "WARN",
536 "flow",
537 "group",
538 "ERROR",
539 "Except" ],
540 "s" )