blob: de5015500eafe7ec5247f32088327e25a2feaf8f [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" )
Devin Lim44075962017-08-11 10:56:37 -070044 main.cleanAndExit()
Devin Lim58046fa2017-07-05 16:55:00 -070045 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']
Devin Lim58046fa2017-07-05 16:55:00 -070059 main.startUpSleep = int(main.params['SLEEP']['startup'])
60 main.startMNSleep = int(main.params['SLEEP']['startMN'])
61 main.addFlowSleep = int(main.params['SLEEP']['addFlow'])
62 main.delFlowSleep = int(main.params['SLEEP']['delFlow'])
63 main.addGroupSleep = int(main.params['SLEEP']['addGroup'])
64 main.delGroupSleep = int(main.params['SLEEP']['delGroup'])
65 main.debug = main.params['DEBUG']
66 main.swDPID = main.params['TEST']['swDPID']
67 egressPort1 = main.params['TEST']['egressPort1']
68 egressPort2 = main.params['TEST']['egressPort2']
69 egressPort3 = main.params['TEST']['egressPort3']
70 ingressPort = main.params['TEST']['ingressPort']
71 appCookie = main.params['TEST']['appCookie']
72 type1 = main.params['TEST']['type1']
73 type2 = main.params['TEST']['type2']
74 groupId = main.params['TEST']['groupId']
75 priority = main.params['TEST']['priority']
76 deviceId = main.params['TEST']['swDPID']
kavitha Alagesan373e0552016-11-22 05:22:05 +053077
Devin Lim58046fa2017-07-05 16:55:00 -070078 main.debug = True if "on" in main.debug else False
79 # -- INIT SECTION, ONLY RUNS ONCE -- #
kavitha Alagesan373e0552016-11-22 05:22:05 +053080
Devin Lim58046fa2017-07-05 16:55:00 -070081 main.buckets = imp.load_source(bucket,
82 main.dependencyPath +
83 bucket +
84 ".py")
kavitha Alagesan373e0552016-11-22 05:22:05 +053085
Devin Lim58046fa2017-07-05 16:55:00 -070086 copyResult = main.ONOSbench.scp(main.Mininet1,
87 main.dependencyPath + main.topology,
88 main.Mininet1.home + '/custom/',
89 direction="to")
kavitha Alagesan373e0552016-11-22 05:22:05 +053090
Devin Lim58046fa2017-07-05 16:55:00 -070091 utilities.assert_equals(expect=main.TRUE,
92 actual=copyResult,
93 onpass="Successfully copy " + "test variables ",
94 onfail="Failed to copy test variables")
95 stepResult = main.testSetUp.envSetup()
kavitha Alagesan373e0552016-11-22 05:22:05 +053096
Devin Lim58046fa2017-07-05 16:55:00 -070097 except Exception as e:
98 main.testSetUp.envSetupException( e )
kavitha Alagesan373e0552016-11-22 05:22:05 +053099
Devin Lim58046fa2017-07-05 16:55:00 -0700100 main.testSetUp.evnSetupConclusion( stepResult )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530101
kavitha Alagesan373e0552016-11-22 05:22:05 +0530102
kavitha Alagesan373e0552016-11-22 05:22:05 +0530103
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 """
Devin Lim142b5342017-07-20 15:22:39 -0700116 main.testSetUp.ONOSSetUp( main.Mininet1, main.Cluster )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530117
118 def CASE3( self, main ):
Jon Hall602d0a72017-05-24 16:06:53 -0700119 """
kavitha Alagesan373e0552016-11-22 05:22:05 +0530120 Start Mininet
Jon Hall602d0a72017-05-24 16:06:53 -0700121 """
kavitha Alagesan373e0552016-11-22 05:22:05 +0530122 import json
Devin Lim58046fa2017-07-05 16:55:00 -0700123 import time
124 try:
125 from tests.dependencies.topology import Topology
126 except ImportError:
127 main.log.error( "Topology not found exiting the test" )
Devin Lim44075962017-08-11 10:56:37 -0700128 main.cleanAndExit()
Devin Lim58046fa2017-07-05 16:55:00 -0700129 try:
130 main.topoRelated
131 except ( NameError, AttributeError ):
132 main.topoRelated = Topology()
kavitha Alagesan373e0552016-11-22 05:22:05 +0530133
134 main.case( "Setup mininet and compare ONOS topology view to Mininet topology" )
135 main.caseExplanation = "Start mininet with custom topology and compare topology " +\
136 "elements between Mininet and ONOS"
137
138 main.step( "Setup Mininet Topology" )
139 topology = main.Mininet1.home + '/custom/' + main.topology
Jon Hall602d0a72017-05-24 16:06:53 -0700140 stepResult = main.Mininet1.startNet( topoFile=topology )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530141
142 utilities.assert_equals( expect=main.TRUE,
143 actual=stepResult,
144 onpass="Successfully loaded topology",
145 onfail="Failed to load topology" )
146
147 main.step( "Assign switch to controller" )
Devin Lim142b5342017-07-20 15:22:39 -0700148 stepResult = main.Mininet1.assignSwController( "s1", main.Cluster.active( 0 ).ipAddress )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530149
150 utilities.assert_equals( expect=main.TRUE,
151 actual=stepResult,
152 onpass="Successfully assigned switch to controller",
153 onfail="Failed to assign switch to controller" )
154
155 time.sleep( main.startMNSleep )
156
Devin Lim58046fa2017-07-05 16:55:00 -0700157 main.topoRelated.compareTopos( main.Mininet1 )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530158
159 def CASE4( self, main ):
Jon Hall602d0a72017-05-24 16:06:53 -0700160 """
kavitha Alagesan373e0552016-11-22 05:22:05 +0530161 Testing scapy
Jon Hall602d0a72017-05-24 16:06:53 -0700162 """
kavitha Alagesan373e0552016-11-22 05:22:05 +0530163 main.case( "Testing scapy" )
164 main.step( "Creating Host1 component" )
165 main.Scapy.createHostComponent( "h1" )
166 main.Scapy.createHostComponent( "h2" )
167 hosts = [ main.h1, main.h2 ]
168 for host in hosts:
Jon Hall602d0a72017-05-24 16:06:53 -0700169 host.startHostCli()
170 host.startScapy()
171 host.updateSelf()
kavitha Alagesan373e0552016-11-22 05:22:05 +0530172 main.log.debug( host.name )
173 main.log.debug( host.hostIp )
174 main.log.debug( host.hostMac )
175
176 main.step( "Sending/Receiving Test packet - Filter doesn't match" )
177 main.log.info( "Starting Filter..." )
Jon Hall602d0a72017-05-24 16:06:53 -0700178 main.h2.startFilter()
kavitha Alagesan373e0552016-11-22 05:22:05 +0530179 main.log.info( "Building Ether frame..." )
180 main.h1.buildEther( dst=main.h2.hostMac )
181 main.log.info( "Sending Packet..." )
Jon Hall602d0a72017-05-24 16:06:53 -0700182 main.h1.sendPacket()
kavitha Alagesan373e0552016-11-22 05:22:05 +0530183 main.log.info( "Checking Filter..." )
Jon Hall602d0a72017-05-24 16:06:53 -0700184 finished = main.h2.checkFilter()
kavitha Alagesan373e0552016-11-22 05:22:05 +0530185 main.log.debug( finished )
186 i = ""
187 if finished:
Jon Hall602d0a72017-05-24 16:06:53 -0700188 a = main.h2.readPackets()
189 for i in a.splitlines():
kavitha Alagesan373e0552016-11-22 05:22:05 +0530190 main.log.info( i )
191 else:
Jon Hall602d0a72017-05-24 16:06:53 -0700192 kill = main.h2.killFilter()
kavitha Alagesan373e0552016-11-22 05:22:05 +0530193 main.log.debug( kill )
194 main.h2.handle.sendline( "" )
195 main.h2.handle.expect( main.h2.scapyPrompt )
196 main.log.debug( main.h2.handle.before )
197 utilities.assert_equals( expect=True,
198 actual="dst=00:00:00:00:00:02 src=00:00:00:00:00:01" in i,
199 onpass="Pass",
200 onfail="Fail" )
201
202 main.step( "Sending/Receiving Test packet - Filter matches" )
Jon Hall602d0a72017-05-24 16:06:53 -0700203 main.h2.startFilter()
kavitha Alagesan373e0552016-11-22 05:22:05 +0530204 main.h1.buildEther( dst=main.h2.hostMac )
205 main.h1.buildIP( dst=main.h2.hostIp )
Jon Hall602d0a72017-05-24 16:06:53 -0700206 main.h1.sendPacket()
207 finished = main.h2.checkFilter()
kavitha Alagesan373e0552016-11-22 05:22:05 +0530208 i = ""
209 if finished:
Jon Hall602d0a72017-05-24 16:06:53 -0700210 a = main.h2.readPackets()
211 for i in a.splitlines():
kavitha Alagesan373e0552016-11-22 05:22:05 +0530212 main.log.info( i )
213 else:
Jon Hall602d0a72017-05-24 16:06:53 -0700214 kill = main.h2.killFilter()
kavitha Alagesan373e0552016-11-22 05:22:05 +0530215 main.log.debug( kill )
216 main.h2.handle.sendline( "" )
217 main.h2.handle.expect( main.h2.scapyPrompt )
218 main.log.debug( main.h2.handle.before )
219 utilities.assert_equals( expect=True,
220 actual="dst=00:00:00:00:00:02 src=00:00:00:00:00:01" in i,
221 onpass="Pass",
222 onfail="Fail" )
223
kavitha Alagesan373e0552016-11-22 05:22:05 +0530224 main.step( "Clean up host components" )
225 for host in hosts:
Jon Hall602d0a72017-05-24 16:06:53 -0700226 host.stopScapy()
kavitha Alagesan373e0552016-11-22 05:22:05 +0530227 main.Mininet1.removeHostComponent( "h1" )
228 main.Mininet1.removeHostComponent( "h2" )
229
230 def CASE5( self, main ):
Jon Hall602d0a72017-05-24 16:06:53 -0700231 """
kavitha Alagesan373e0552016-11-22 05:22:05 +0530232 Adding Group of type "ALL" using Rest api
Jon Hall602d0a72017-05-24 16:06:53 -0700233 """
kavitha Alagesan373e0552016-11-22 05:22:05 +0530234 import json
235 import time
236 isAdded = main.FALSE
237 main.case( "Verify Group of type All are successfully Added" )
238 main.caseExplanation = " Install a Group of type ALL " +\
239 " Verify the Group is Added " +\
240 " Add a flow using the group " +\
241 " Send a packet that verifies the action bucket of the group"
242
243 main.step( "Add Group using Rest api" )
244 bucketList = []
Jon Hall602d0a72017-05-24 16:06:53 -0700245 bucket = main.buckets.addBucket( main, egressPort=egressPort1 )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530246 bucketList.append( bucket )
Jon Hall602d0a72017-05-24 16:06:53 -0700247 bucket = main.buckets.addBucket( main, egressPort=egressPort2 )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530248 bucketList.append( bucket )
Jon Hall602d0a72017-05-24 16:06:53 -0700249 bucket = main.buckets.addBucket( main, egressPort=egressPort3 )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530250 bucketList.append( bucket )
Devin Lim142b5342017-07-20 15:22:39 -0700251 ctrl = main.Cluster.active( 0 )
252 response = ctrl.REST.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
Devin Lim142b5342017-07-20 15:22:39 -0700268 response = ctrl.REST.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" )
Devin Lim142b5342017-07-20 15:22:39 -0700286 response = ctrl.REST.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
Devin Lim142b5342017-07-20 15:22:39 -0700298 response = ctrl.REST.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" )
Devin Lim142b5342017-07-20 15:22:39 -0700383 ctrl = main.Cluster.active( 0 )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530384 #Get Flow ID
Devin Lim142b5342017-07-20 15:22:39 -0700385 response = ctrl.REST.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" )
Devin Lim142b5342017-07-20 15:22:39 -0700392 flowResponse = ctrl.REST.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" )
Devin Lim142b5342017-07-20 15:22:39 -0700404 groupResponse = ctrl.REST.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" )
Devin Lim142b5342017-07-20 15:22:39 -0700430 ctrl = main.Cluster.active( 0 )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530431 bucketList = []
Jon Hall602d0a72017-05-24 16:06:53 -0700432 bucket = main.buckets.addBucket( main, egressPort=egressPort1 )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530433 bucketList.append( bucket )
Devin Lim142b5342017-07-20 15:22:39 -0700434 response = ctrl.REST.addGroup( deviceId=deviceId,
435 groupType=type2,
436 bucketList=bucketList,
437 appCookie=appCookie,
438 groupId=groupId )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530439
440 utilities.assert_equals( expect=main.TRUE,
441 actual=response,
442 onpass="Successfully added Groups of type INDIRECT",
443 onfail="Failed to add Groups of type INDIRECT" )
444
445 # Giving ONOS time to add the group
446 time.sleep( main.addGroupSleep )
447
448 main.step( "Check groups are in ADDED state" )
449
Devin Lim142b5342017-07-20 15:22:39 -0700450 response = ctrl.REST.getGroups( deviceId=deviceId,
451 appCookie=appCookie )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530452 responsejson = json.loads( response )
Jon Hall602d0a72017-05-24 16:06:53 -0700453 for item in responsejson:
454 if item[ "state" ] == "ADDED":
kavitha Alagesan373e0552016-11-22 05:22:05 +0530455 isAdded = main.TRUE
456
457 utilities.assert_equals( expect=main.TRUE,
458 actual=isAdded,
459 onpass="INDIRECT Group is in Added State",
460 onfail="INDIRECT Group is not in Added State" )
461
Jon Hall602d0a72017-05-24 16:06:53 -0700462 """
kavitha Alagesan373e0552016-11-22 05:22:05 +0530463 Adding flows using rest api
Jon Hall602d0a72017-05-24 16:06:53 -0700464 """
kavitha Alagesan373e0552016-11-22 05:22:05 +0530465 isAdded = main.FALSE
466
467 main.step( "Adding flow with Group using rest api" )
Devin Lim142b5342017-07-20 15:22:39 -0700468 response = ctrl.REST.addFlow( deviceId=deviceId,
469 priority=priority,
470 ingressPort=ingressPort,
471 groupId=groupId )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530472 utilities.assert_equals( expect=main.TRUE,
473 actual=response,
474 onpass="Successfully Added Flows",
475 onfail="Failed to Add flows" )
476
477 # Giving ONOS time to add the flow
478 time.sleep( main.addFlowSleep )
479
Devin Lim142b5342017-07-20 15:22:39 -0700480 response = ctrl.REST.getFlows( deviceId=deviceId )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530481 responsejson = json.loads( response )
Jon Hall602d0a72017-05-24 16:06:53 -0700482 for item in responsejson:
483 if item[ "priority" ] == int( priority ) and item[ "state" ] == "ADDED":
kavitha Alagesan373e0552016-11-22 05:22:05 +0530484 isAdded = main.TRUE
485
486 utilities.assert_equals( expect=main.TRUE,
487 actual=isAdded,
488 onpass="Flow is in Added State",
489 onfail="Flow is not in Added State" )
490
Jon Hall602d0a72017-05-24 16:06:53 -0700491 """
kavitha Alagesan373e0552016-11-22 05:22:05 +0530492 Sends a packet using scapy
Jon Hall602d0a72017-05-24 16:06:53 -0700493 """
Devin Lim58046fa2017-07-05 16:55:00 -0700494 main.step( "Testing Group by sending packet using Scapy" )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530495 main.log.info( "Creating host components" )
496 main.Scapy.createHostComponent( "h1" )
497 main.Scapy.createHostComponent( "h2" )
498
Jon Hall602d0a72017-05-24 16:06:53 -0700499 hosts = [ main.h1, main.h2 ]
kavitha Alagesan373e0552016-11-22 05:22:05 +0530500 for host in hosts:
Jon Hall602d0a72017-05-24 16:06:53 -0700501 host.startHostCli()
502 host.startScapy()
503 host.updateSelf()
kavitha Alagesan373e0552016-11-22 05:22:05 +0530504 main.log.info( "Constructing Packet" )
505 main.h1.buildEther( dst=main.h1.hostMac )
506 main.h1.buildIP( dst=main.h1.hostIp )
507 main.log.info( "Start Filter on host2" )
508 main.h2.startFilter( pktFilter="ether host %s and ip host %s" % ( main.h1.hostMac, main.h1.hostIp ) )
509 main.log.info( "sending packet to Host" )
Jon Hall602d0a72017-05-24 16:06:53 -0700510 main.h1.sendPacket()
kavitha Alagesan373e0552016-11-22 05:22:05 +0530511 main.log.info( "Checking filter for our packet" )
Jon Hall602d0a72017-05-24 16:06:53 -0700512 stepResultH2 = main.h2.checkFilter()
kavitha Alagesan373e0552016-11-22 05:22:05 +0530513
514 if stepResultH2:
Jon Hall602d0a72017-05-24 16:06:53 -0700515 main.log.info( "Packet : %s" % main.h2.readPackets() )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530516 else:
Jon Hall602d0a72017-05-24 16:06:53 -0700517 main.h2.killFilter()
kavitha Alagesan373e0552016-11-22 05:22:05 +0530518
519 main.log.info( "Clean up host components" )
520 for host in hosts:
Jon Hall602d0a72017-05-24 16:06:53 -0700521 host.stopScapy()
kavitha Alagesan373e0552016-11-22 05:22:05 +0530522 main.Mininet1.removeHostComponent( "h1" )
523 main.Mininet1.removeHostComponent( "h2" )
524
525 utilities.assert_equals( expect=main.TRUE,
526 actual=stepResultH2,
527 onpass="Packet sent to port 1 is received at port 2 successfully!!!",
528 onfail="Failure!!!Packet sent to port 1 is not received at port 2" )
529
kavitha Alagesan373e0552016-11-22 05:22:05 +0530530 def CASE100( self, main ):
Jon Hall602d0a72017-05-24 16:06:53 -0700531 """
kavitha Alagesan373e0552016-11-22 05:22:05 +0530532 Report errors/warnings/exceptions
Jon Hall602d0a72017-05-24 16:06:53 -0700533 """
kavitha Alagesan373e0552016-11-22 05:22:05 +0530534 main.log.info( "Error report: \n" )
Devin Lim142b5342017-07-20 15:22:39 -0700535 main.ONOSbench.logReport( main.Cluster.active( 0 ).ipAddress,
kavitha Alagesan373e0552016-11-22 05:22:05 +0530536 [ "INFO",
537 "FOLLOWER",
538 "WARN",
539 "flow",
540 "group",
541 "ERROR",
542 "Except" ],
543 "s" )