blob: bbe759d11b05f423c3f6aa2b122ae9fb0c12518a [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' ]
You Wangdafb6e22018-01-22 17:01:00 -080076 main.scapyHostNames = main.params[ 'SCAPY' ][ 'HOSTNAMES' ].split( ',' )
77 main.scapyHosts = [] # List of scapy hosts for iterating
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
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070082 main.buckets = imp.load_source( bucket,
83 main.dependencyPath +
84 bucket +
85 ".py" )
kavitha Alagesan373e0552016-11-22 05:22:05 +053086
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -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
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070092 utilities.assert_equals( expect=main.TRUE,
93 actual=copyResult,
94 onpass="Successfully copy " + "test variables ",
95 onfail="Failed to copy test variables" )
Devin Lim58046fa2017-07-05 16:55:00 -070096 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 def CASE2( self, main ):
104 """
105 - Set up cell
106 - Create cell file
107 - Set cell file
108 - Verify cell file
109 - Kill ONOS process
110 - Uninstall ONOS cluster
111 - Verify ONOS start up
112 - Install ONOS cluster
113 - Connect to cli
114 """
You Wanga0f6ff62018-01-11 15:46:30 -0800115 main.testSetUp.ONOSSetUp( main.Cluster )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530116
117 def CASE3( self, main ):
Jon Hall602d0a72017-05-24 16:06:53 -0700118 """
kavitha Alagesan373e0552016-11-22 05:22:05 +0530119 Start Mininet
Jon Hall602d0a72017-05-24 16:06:53 -0700120 """
kavitha Alagesan373e0552016-11-22 05:22:05 +0530121 import json
Devin Lim58046fa2017-07-05 16:55:00 -0700122 import time
123 try:
124 from tests.dependencies.topology import Topology
125 except ImportError:
126 main.log.error( "Topology not found exiting the test" )
Devin Lim44075962017-08-11 10:56:37 -0700127 main.cleanAndExit()
Devin Lim58046fa2017-07-05 16:55:00 -0700128 try:
129 main.topoRelated
130 except ( NameError, AttributeError ):
131 main.topoRelated = Topology()
kavitha Alagesan373e0552016-11-22 05:22:05 +0530132
133 main.case( "Setup mininet and compare ONOS topology view to Mininet topology" )
134 main.caseExplanation = "Start mininet with custom topology and compare topology " +\
135 "elements between Mininet and ONOS"
136
137 main.step( "Setup Mininet Topology" )
138 topology = main.Mininet1.home + '/custom/' + main.topology
Jon Hall602d0a72017-05-24 16:06:53 -0700139 stepResult = main.Mininet1.startNet( topoFile=topology )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530140
141 utilities.assert_equals( expect=main.TRUE,
142 actual=stepResult,
143 onpass="Successfully loaded topology",
144 onfail="Failed to load topology" )
145
146 main.step( "Assign switch to controller" )
Devin Lim142b5342017-07-20 15:22:39 -0700147 stepResult = main.Mininet1.assignSwController( "s1", main.Cluster.active( 0 ).ipAddress )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530148
149 utilities.assert_equals( expect=main.TRUE,
150 actual=stepResult,
151 onpass="Successfully assigned switch to controller",
152 onfail="Failed to assign switch to controller" )
153
154 time.sleep( main.startMNSleep )
155
Devin Lim58046fa2017-07-05 16:55:00 -0700156 main.topoRelated.compareTopos( main.Mininet1 )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530157
You Wangdafb6e22018-01-22 17:01:00 -0800158 main.step( "Create hosts and start scapy" )
159 scapyResult = main.TRUE
160 for hostName in main.scapyHostNames:
161 main.Scapy.createHostComponent( hostName )
162 main.scapyHosts.append( getattr( main, hostName ) )
163
164 main.step( "Start scapy components" )
165 for host in main.scapyHosts:
166 host.startHostCli()
167 host.startScapy()
168 host.updateSelf()
169 main.log.debug( host.name )
170 main.log.debug( host.hostIp )
171 main.log.debug( host.hostMac )
172
173 utilities.assert_equals( expect=main.TRUE,
174 actual=scapyResult,
175 onpass="Successfully created Scapy Components",
176 onfail="Failed to discover Scapy Components" )
177
kavitha Alagesan373e0552016-11-22 05:22:05 +0530178 def CASE4( self, main ):
Jon Hall602d0a72017-05-24 16:06:53 -0700179 """
kavitha Alagesan373e0552016-11-22 05:22:05 +0530180 Testing scapy
Jon Hall602d0a72017-05-24 16:06:53 -0700181 """
kavitha Alagesan373e0552016-11-22 05:22:05 +0530182 main.case( "Testing scapy" )
You Wangdafb6e22018-01-22 17:01:00 -0800183 for host in main.scapyHosts:
184 host.stopScapy()
Jon Hall602d0a72017-05-24 16:06:53 -0700185 host.startScapy()
186 host.updateSelf()
kavitha Alagesan373e0552016-11-22 05:22:05 +0530187 main.log.debug( host.name )
188 main.log.debug( host.hostIp )
189 main.log.debug( host.hostMac )
190
191 main.step( "Sending/Receiving Test packet - Filter doesn't match" )
192 main.log.info( "Starting Filter..." )
Jon Hall602d0a72017-05-24 16:06:53 -0700193 main.h2.startFilter()
kavitha Alagesan373e0552016-11-22 05:22:05 +0530194 main.log.info( "Building Ether frame..." )
195 main.h1.buildEther( dst=main.h2.hostMac )
196 main.log.info( "Sending Packet..." )
Jon Hall602d0a72017-05-24 16:06:53 -0700197 main.h1.sendPacket()
kavitha Alagesan373e0552016-11-22 05:22:05 +0530198 main.log.info( "Checking Filter..." )
Jon Hall602d0a72017-05-24 16:06:53 -0700199 finished = main.h2.checkFilter()
kavitha Alagesan373e0552016-11-22 05:22:05 +0530200 main.log.debug( finished )
201 i = ""
202 if finished:
Jon Hall602d0a72017-05-24 16:06:53 -0700203 a = main.h2.readPackets()
204 for i in a.splitlines():
kavitha Alagesan373e0552016-11-22 05:22:05 +0530205 main.log.info( i )
206 else:
Jon Hall602d0a72017-05-24 16:06:53 -0700207 kill = main.h2.killFilter()
kavitha Alagesan373e0552016-11-22 05:22:05 +0530208 main.log.debug( kill )
209 main.h2.handle.sendline( "" )
210 main.h2.handle.expect( main.h2.scapyPrompt )
211 main.log.debug( main.h2.handle.before )
212 utilities.assert_equals( expect=True,
213 actual="dst=00:00:00:00:00:02 src=00:00:00:00:00:01" in i,
214 onpass="Pass",
215 onfail="Fail" )
216
217 main.step( "Sending/Receiving Test packet - Filter matches" )
Jon Hall602d0a72017-05-24 16:06:53 -0700218 main.h2.startFilter()
kavitha Alagesan373e0552016-11-22 05:22:05 +0530219 main.h1.buildEther( dst=main.h2.hostMac )
220 main.h1.buildIP( dst=main.h2.hostIp )
Jon Hall602d0a72017-05-24 16:06:53 -0700221 main.h1.sendPacket()
222 finished = main.h2.checkFilter()
kavitha Alagesan373e0552016-11-22 05:22:05 +0530223 i = ""
224 if finished:
Jon Hall602d0a72017-05-24 16:06:53 -0700225 a = main.h2.readPackets()
226 for i in a.splitlines():
kavitha Alagesan373e0552016-11-22 05:22:05 +0530227 main.log.info( i )
228 else:
Jon Hall602d0a72017-05-24 16:06:53 -0700229 kill = main.h2.killFilter()
kavitha Alagesan373e0552016-11-22 05:22:05 +0530230 main.log.debug( kill )
231 main.h2.handle.sendline( "" )
232 main.h2.handle.expect( main.h2.scapyPrompt )
233 main.log.debug( main.h2.handle.before )
234 utilities.assert_equals( expect=True,
235 actual="dst=00:00:00:00:00:02 src=00:00:00:00:00:01" in i,
236 onpass="Pass",
237 onfail="Fail" )
238
kavitha Alagesan373e0552016-11-22 05:22:05 +0530239 def CASE5( self, main ):
Jon Hall602d0a72017-05-24 16:06:53 -0700240 """
kavitha Alagesan373e0552016-11-22 05:22:05 +0530241 Adding Group of type "ALL" using Rest api
Jon Hall602d0a72017-05-24 16:06:53 -0700242 """
kavitha Alagesan373e0552016-11-22 05:22:05 +0530243 import json
244 import time
245 isAdded = main.FALSE
246 main.case( "Verify Group of type All are successfully Added" )
247 main.caseExplanation = " Install a Group of type ALL " +\
248 " Verify the Group is Added " +\
249 " Add a flow using the group " +\
250 " Send a packet that verifies the action bucket of the group"
251
252 main.step( "Add Group using Rest api" )
253 bucketList = []
Jon Hall602d0a72017-05-24 16:06:53 -0700254 bucket = main.buckets.addBucket( main, egressPort=egressPort1 )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530255 bucketList.append( bucket )
Jon Hall602d0a72017-05-24 16:06:53 -0700256 bucket = main.buckets.addBucket( main, egressPort=egressPort2 )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530257 bucketList.append( bucket )
Jon Hall602d0a72017-05-24 16:06:53 -0700258 bucket = main.buckets.addBucket( main, egressPort=egressPort3 )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530259 bucketList.append( bucket )
Devin Lim142b5342017-07-20 15:22:39 -0700260 ctrl = main.Cluster.active( 0 )
261 response = ctrl.REST.addGroup( deviceId=deviceId,
262 groupType=type1,
263 bucketList=bucketList,
264 appCookie=appCookie,
265 groupId=groupId )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530266
267 utilities.assert_equals( expect=main.TRUE,
268 actual=response,
269 onpass="Successfully added Groups of type ALL",
270 onfail="Failed to add Groups of type ALL" )
271
272 # Giving ONOS time to add the group
273 time.sleep( main.addGroupSleep )
274
275 main.step( "Check groups are in ADDED state" )
276
Devin Lim142b5342017-07-20 15:22:39 -0700277 response = ctrl.REST.getGroups( deviceId=deviceId,
278 appCookie=appCookie )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530279 responsejson = json.loads( response )
Jon Hall602d0a72017-05-24 16:06:53 -0700280 for item in responsejson:
281 if item[ "state" ] == "ADDED":
kavitha Alagesan373e0552016-11-22 05:22:05 +0530282 isAdded = main.TRUE
283
284 utilities.assert_equals( expect=main.TRUE,
285 actual=isAdded,
286 onpass="All Group is in Added State",
287 onfail="All Group is not in Added State" )
288
Jon Hall602d0a72017-05-24 16:06:53 -0700289 """
kavitha Alagesan373e0552016-11-22 05:22:05 +0530290 Adding flow using rest api
Jon Hall602d0a72017-05-24 16:06:53 -0700291 """
kavitha Alagesan373e0552016-11-22 05:22:05 +0530292 isAdded = main.FALSE
293
294 main.step( "Adding flow with Group using rest api" )
Devin Lim142b5342017-07-20 15:22:39 -0700295 response = ctrl.REST.addFlow( deviceId=deviceId,
296 priority=priority,
297 ingressPort=ingressPort,
298 groupId=groupId )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530299 utilities.assert_equals( expect=main.TRUE,
300 actual=response,
301 onpass="Successfully Added Flows",
302 onfail="Failed to Add flows" )
303
304 # Giving ONOS time to add the flow
305 time.sleep( main.addFlowSleep )
306
Devin Lim142b5342017-07-20 15:22:39 -0700307 response = ctrl.REST.getFlows( deviceId=deviceId )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530308 responsejson = json.loads( response )
Jon Hall602d0a72017-05-24 16:06:53 -0700309 for item in responsejson:
310 if item[ "priority" ] == int( priority ) and item[ "state" ] == "ADDED":
kavitha Alagesan373e0552016-11-22 05:22:05 +0530311 isAdded = main.TRUE
312
313 utilities.assert_equals( expect=main.TRUE,
314 actual=isAdded,
315 onpass="Flow is in Added State",
316 onfail="Flow is not in Added State" )
317
Jon Hall602d0a72017-05-24 16:06:53 -0700318 """
kavitha Alagesan373e0552016-11-22 05:22:05 +0530319 Sends a packet using scapy
Jon Hall602d0a72017-05-24 16:06:53 -0700320 """
Devin Lim58046fa2017-07-05 16:55:00 -0700321 main.step( "Testing Group by sending packet using Scapy" )
You Wangdafb6e22018-01-22 17:01:00 -0800322 for host in main.scapyHosts:
323 host.stopScapy()
Jon Hall602d0a72017-05-24 16:06:53 -0700324 host.startScapy()
325 host.updateSelf()
You Wangdafb6e22018-01-22 17:01:00 -0800326 main.log.debug( host.name )
327 main.log.debug( host.hostIp )
328 main.log.debug( host.hostMac )
329
kavitha Alagesan373e0552016-11-22 05:22:05 +0530330 main.log.info( "Constructing Packet" )
331 main.h1.buildEther( dst=main.h1.hostMac )
332 main.h1.buildIP( dst=main.h1.hostIp )
333 main.log.info( "Start Filter on host2,host3,host4" )
334 main.h2.startFilter( pktFilter="ether host %s and ip host %s" % ( main.h1.hostMac, main.h1.hostIp ) )
335 main.h3.startFilter( pktFilter="ether host %s and ip host %s" % ( main.h1.hostMac, main.h1.hostIp ) )
336 main.h4.startFilter( pktFilter="ether host %s and ip host %s" % ( main.h1.hostMac, main.h1.hostIp ) )
337 main.log.info( "sending packet to Host" )
Jon Hall602d0a72017-05-24 16:06:53 -0700338 main.h1.sendPacket()
kavitha Alagesan373e0552016-11-22 05:22:05 +0530339 main.log.info( "Checking filter for our packet" )
Jon Hall602d0a72017-05-24 16:06:53 -0700340 stepResultH2 = main.h2.checkFilter()
341 stepResultH3 = main.h3.checkFilter()
342 stepResultH4 = main.h4.checkFilter()
kavitha Alagesan373e0552016-11-22 05:22:05 +0530343
344 if stepResultH2:
Jon Hall602d0a72017-05-24 16:06:53 -0700345 main.log.info( "Packet : %s" % main.h2.readPackets() )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530346 else:
Jon Hall602d0a72017-05-24 16:06:53 -0700347 main.h2.killFilter()
kavitha Alagesan373e0552016-11-22 05:22:05 +0530348
349 if stepResultH3:
Jon Hall602d0a72017-05-24 16:06:53 -0700350 main.log.info( "Packet : %s" % main.h3.readPackets() )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530351 else:
Jon Hall602d0a72017-05-24 16:06:53 -0700352 main.h2.killFilter()
kavitha Alagesan373e0552016-11-22 05:22:05 +0530353
354 if stepResultH4:
Jon Hall602d0a72017-05-24 16:06:53 -0700355 main.log.info( "Packet : %s" % main.h4.readPackets() )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530356 else:
Jon Hall602d0a72017-05-24 16:06:53 -0700357 main.h4.killFilter()
kavitha Alagesan373e0552016-11-22 05:22:05 +0530358
Jon Hall602d0a72017-05-24 16:06:53 -0700359 if stepResultH2 and stepResultH3 and stepResultH4:
kavitha Alagesan373e0552016-11-22 05:22:05 +0530360 main.log.info( "Success!!!Packet sent to port 1 is received at port 2,3 and 4" )
361 stepResult = main.TRUE
362 else:
363 main.log.info( "Failure!!!Packet sent to port 1 is not received at port 2,3 and 4" )
364 stepResult = main.FALSE
365
kavitha Alagesan373e0552016-11-22 05:22:05 +0530366 utilities.assert_equals( expect=main.TRUE,
367 actual=stepResult,
368 onpass="Packet sent to port 1 is received at port 2,3,4 ",
369 onfail="Packet sent to port 1 is not received at port 2,3,4 " )
370
371 def CASE6( self, main ):
Jon Hall602d0a72017-05-24 16:06:53 -0700372 """
kavitha Alagesan373e0552016-11-22 05:22:05 +0530373 Deleting the Group and Flow
Jon Hall602d0a72017-05-24 16:06:53 -0700374 """
kavitha Alagesan373e0552016-11-22 05:22:05 +0530375 import json
376 import time
377 respFlowId = 1
378
379 main.case( "Delete the Group and Flow added through Rest api " )
380 main.step( "Deleting Group and Flows" )
Devin Lim142b5342017-07-20 15:22:39 -0700381 ctrl = main.Cluster.active( 0 )
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700382 # Get Flow ID
Devin Lim142b5342017-07-20 15:22:39 -0700383 response = ctrl.REST.getFlows( deviceId=deviceId )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530384 responsejson = json.loads( response )
Jon Hall602d0a72017-05-24 16:06:53 -0700385 for item in responsejson:
386 if item[ "priority" ] == int( priority ):
387 respFlowId = item[ "id" ]
kavitha Alagesan373e0552016-11-22 05:22:05 +0530388
389 main.step( "Deleting the created flow by deviceId and flowId" )
Devin Lim142b5342017-07-20 15:22:39 -0700390 flowResponse = ctrl.REST.removeFlow( deviceId=deviceId,
391 flowId=respFlowId )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530392
393 utilities.assert_equals( expect=main.TRUE,
394 actual=flowResponse,
395 onpass="Deleting flow is successful!!!",
396 onfail="Deleting flow is failure!!!" )
397
398 # Giving ONOS time to delete the flow
399 time.sleep( main.delFlowSleep )
400
401 main.step( "Deleting the created group by deviceId and appCookie" )
Devin Lim142b5342017-07-20 15:22:39 -0700402 groupResponse = ctrl.REST.removeGroup( deviceId=deviceId,
403 appCookie=appCookie )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530404
405 utilities.assert_equals( expect=main.TRUE,
406 actual=groupResponse,
407 onpass="Deleting Group is successful!!!",
408 onfail="Deleting Group is failure!!!" )
409
410 # Giving ONOS time to delete the group
411 time.sleep( main.delGroupSleep )
412
413 def CASE7( self, main ):
Jon Hall602d0a72017-05-24 16:06:53 -0700414 """
kavitha Alagesan373e0552016-11-22 05:22:05 +0530415 Adding Group of type "INDIRECT" using Rest api.
Jon Hall602d0a72017-05-24 16:06:53 -0700416 """
kavitha Alagesan373e0552016-11-22 05:22:05 +0530417 import json
418 import time
419 isAdded = main.FALSE
420
421 main.case( "Verify Group of type INDIRECT are successfully Added" )
422 main.caseExplanation = " Install a Group of type INDIRECT " +\
423 " Verify the Group is Added " +\
424 " Add a flow using the group " +\
425 " Send a packet that verifies the action bucket of the group"
426
427 main.step( "Add Group using Rest api" )
Devin Lim142b5342017-07-20 15:22:39 -0700428 ctrl = main.Cluster.active( 0 )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530429 bucketList = []
Jon Hall602d0a72017-05-24 16:06:53 -0700430 bucket = main.buckets.addBucket( main, egressPort=egressPort1 )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530431 bucketList.append( bucket )
Devin Lim142b5342017-07-20 15:22:39 -0700432 response = ctrl.REST.addGroup( deviceId=deviceId,
433 groupType=type2,
434 bucketList=bucketList,
435 appCookie=appCookie,
436 groupId=groupId )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530437
438 utilities.assert_equals( expect=main.TRUE,
439 actual=response,
440 onpass="Successfully added Groups of type INDIRECT",
441 onfail="Failed to add Groups of type INDIRECT" )
442
443 # Giving ONOS time to add the group
444 time.sleep( main.addGroupSleep )
445
446 main.step( "Check groups are in ADDED state" )
447
Devin Lim142b5342017-07-20 15:22:39 -0700448 response = ctrl.REST.getGroups( deviceId=deviceId,
449 appCookie=appCookie )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530450 responsejson = json.loads( response )
Jon Hall602d0a72017-05-24 16:06:53 -0700451 for item in responsejson:
452 if item[ "state" ] == "ADDED":
kavitha Alagesan373e0552016-11-22 05:22:05 +0530453 isAdded = main.TRUE
454
455 utilities.assert_equals( expect=main.TRUE,
456 actual=isAdded,
457 onpass="INDIRECT Group is in Added State",
458 onfail="INDIRECT Group is not in Added State" )
459
Jon Hall602d0a72017-05-24 16:06:53 -0700460 """
kavitha Alagesan373e0552016-11-22 05:22:05 +0530461 Adding flows using rest api
Jon Hall602d0a72017-05-24 16:06:53 -0700462 """
kavitha Alagesan373e0552016-11-22 05:22:05 +0530463 isAdded = main.FALSE
464
465 main.step( "Adding flow with Group using rest api" )
Devin Lim142b5342017-07-20 15:22:39 -0700466 response = ctrl.REST.addFlow( deviceId=deviceId,
467 priority=priority,
468 ingressPort=ingressPort,
469 groupId=groupId )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530470 utilities.assert_equals( expect=main.TRUE,
471 actual=response,
472 onpass="Successfully Added Flows",
473 onfail="Failed to Add flows" )
474
475 # Giving ONOS time to add the flow
476 time.sleep( main.addFlowSleep )
477
Devin Lim142b5342017-07-20 15:22:39 -0700478 response = ctrl.REST.getFlows( deviceId=deviceId )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530479 responsejson = json.loads( response )
Jon Hall602d0a72017-05-24 16:06:53 -0700480 for item in responsejson:
481 if item[ "priority" ] == int( priority ) and item[ "state" ] == "ADDED":
kavitha Alagesan373e0552016-11-22 05:22:05 +0530482 isAdded = main.TRUE
483
484 utilities.assert_equals( expect=main.TRUE,
485 actual=isAdded,
486 onpass="Flow is in Added State",
487 onfail="Flow is not in Added State" )
488
Jon Hall602d0a72017-05-24 16:06:53 -0700489 """
kavitha Alagesan373e0552016-11-22 05:22:05 +0530490 Sends a packet using scapy
Jon Hall602d0a72017-05-24 16:06:53 -0700491 """
Devin Lim58046fa2017-07-05 16:55:00 -0700492 main.step( "Testing Group by sending packet using Scapy" )
You Wangdafb6e22018-01-22 17:01:00 -0800493 for host in main.scapyHosts:
494 host.stopScapy()
Jon Hall602d0a72017-05-24 16:06:53 -0700495 host.startScapy()
496 host.updateSelf()
You Wangdafb6e22018-01-22 17:01:00 -0800497 main.log.debug( host.name )
498 main.log.debug( host.hostIp )
499 main.log.debug( host.hostMac )
500
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
kavitha Alagesan373e0552016-11-22 05:22:05 +0530516 utilities.assert_equals( expect=main.TRUE,
517 actual=stepResultH2,
518 onpass="Packet sent to port 1 is received at port 2 successfully!!!",
519 onfail="Failure!!!Packet sent to port 1 is not received at port 2" )
520
You Wangdafb6e22018-01-22 17:01:00 -0800521 def CASE10( self, main ):
522 """
523 Stop mininet and remove scapy host
524 """
525 try:
526 from tests.dependencies.utils import Utils
527 except ImportError:
528 main.log.error( "Utils not found exiting the test" )
529 main.cleanAndExit()
530 try:
531 main.Utils
532 except ( NameError, AttributeError ):
533 main.Utils = Utils()
534 main.log.report( "Stop Mininet and Scapy" )
535 main.case( "Stop Mininet and Scapy" )
536 main.caseExplanation = "Stopping the current mininet topology " +\
537 "to start up fresh"
538 main.step( "Stopping and Removing Scapy Host Components" )
539 scapyResult = main.TRUE
540 for host in main.scapyHosts:
541 scapyResult = scapyResult and host.stopScapy()
542 main.log.info( "Stopped Scapy Host: {0}".format( host.name ) )
543
544 for host in main.scapyHosts:
545 scapyResult = scapyResult and main.Scapy.removeHostComponent( host.name )
546 main.log.info( "Removed Scapy Host Component: {0}".format( host.name ) )
547
548 main.scapyHosts = []
549
550 utilities.assert_equals( expect=main.TRUE,
551 actual=scapyResult,
552 onpass="Successfully stopped scapy and removed host components",
553 onfail="Failed to stop mininet and scapy" )
554
555 mininetResult = main.Utils.mininetCleanup( main.Mininet1 )
556 # Exit if topology did not load properly
557 if not ( mininetResult and scapyResult ):
558 main.cleanAndExit()
559
kavitha Alagesan373e0552016-11-22 05:22:05 +0530560 def CASE100( self, main ):
Jon Hall602d0a72017-05-24 16:06:53 -0700561 """
kavitha Alagesan373e0552016-11-22 05:22:05 +0530562 Report errors/warnings/exceptions
Jon Hall602d0a72017-05-24 16:06:53 -0700563 """
kavitha Alagesan373e0552016-11-22 05:22:05 +0530564 main.log.info( "Error report: \n" )
Devin Lim142b5342017-07-20 15:22:39 -0700565 main.ONOSbench.logReport( main.Cluster.active( 0 ).ipAddress,
kavitha Alagesan373e0552016-11-22 05:22:05 +0530566 [ "INFO",
567 "FOLLOWER",
568 "WARN",
569 "flow",
570 "group",
571 "ERROR",
572 "Except" ],
573 "s" )