blob: 4a835813c2da9f2361d20e2f6842d3ac59976566 [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
Devin Lim58046fa2017-07-05 16:55:00 -070087 stepResult = main.testSetUp.envSetup()
kavitha Alagesan373e0552016-11-22 05:22:05 +053088
Devin Lim58046fa2017-07-05 16:55:00 -070089 except Exception as e:
90 main.testSetUp.envSetupException( e )
kavitha Alagesan373e0552016-11-22 05:22:05 +053091
Devin Lim58046fa2017-07-05 16:55:00 -070092 main.testSetUp.evnSetupConclusion( stepResult )
kavitha Alagesan373e0552016-11-22 05:22:05 +053093
kavitha Alagesan373e0552016-11-22 05:22:05 +053094 def CASE2( self, main ):
95 """
96 - Set up cell
97 - Create cell file
98 - Set cell file
99 - Verify cell file
100 - Kill ONOS process
101 - Uninstall ONOS cluster
102 - Verify ONOS start up
103 - Install ONOS cluster
104 - Connect to cli
105 """
You Wanga0f6ff62018-01-11 15:46:30 -0800106 main.testSetUp.ONOSSetUp( main.Cluster )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530107
108 def CASE3( self, main ):
Jon Hall602d0a72017-05-24 16:06:53 -0700109 """
kavitha Alagesan373e0552016-11-22 05:22:05 +0530110 Start Mininet
Jon Hall602d0a72017-05-24 16:06:53 -0700111 """
kavitha Alagesan373e0552016-11-22 05:22:05 +0530112 import json
Devin Lim58046fa2017-07-05 16:55:00 -0700113 import time
114 try:
115 from tests.dependencies.topology import Topology
116 except ImportError:
117 main.log.error( "Topology not found exiting the test" )
Devin Lim44075962017-08-11 10:56:37 -0700118 main.cleanAndExit()
Devin Lim58046fa2017-07-05 16:55:00 -0700119 try:
120 main.topoRelated
121 except ( NameError, AttributeError ):
122 main.topoRelated = Topology()
kavitha Alagesan373e0552016-11-22 05:22:05 +0530123
124 main.case( "Setup mininet and compare ONOS topology view to Mininet topology" )
125 main.caseExplanation = "Start mininet with custom topology and compare topology " +\
126 "elements between Mininet and ONOS"
127
You Wang84f981d2018-01-12 16:11:50 -0800128 main.step( "Copy Mininet topology file" )
129 copyResult = main.ONOSbench.scp( main.Mininet1,
130 main.dependencyPath + main.topology,
131 main.Mininet1.home + '/custom/',
132 direction="to" )
133 utilities.assert_equals( expect=main.TRUE,
134 actual=copyResult,
135 onpass="Successfully copy mininet topo file",
136 onfail="Failed to copy mininet topo file" )
137
kavitha Alagesan373e0552016-11-22 05:22:05 +0530138 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
You Wangdafb6e22018-01-22 17:01:00 -0800159 main.step( "Create hosts and start scapy" )
160 scapyResult = main.TRUE
161 for hostName in main.scapyHostNames:
162 main.Scapy.createHostComponent( hostName )
163 main.scapyHosts.append( getattr( main, hostName ) )
164
165 main.step( "Start scapy components" )
166 for host in main.scapyHosts:
167 host.startHostCli()
168 host.startScapy()
169 host.updateSelf()
170 main.log.debug( host.name )
171 main.log.debug( host.hostIp )
172 main.log.debug( host.hostMac )
173
174 utilities.assert_equals( expect=main.TRUE,
175 actual=scapyResult,
176 onpass="Successfully created Scapy Components",
177 onfail="Failed to discover Scapy Components" )
178
You Wang84f981d2018-01-12 16:11:50 -0800179 def CASE11( self, main ):
180 """
181 Connect to a physical network, assign controllers and start scapy
182 """
183 import time
184 main.case( "Connecting to physical network" )
185
186 main.step( "Connecting to physical network" )
187 topoResult = main.NetworkBench.connectToNet()
188 stepResult = topoResult
189 utilities.assert_equals( expect=main.TRUE,
190 actual=stepResult,
191 onpass="Successfully loaded topology",
192 onfail="Failed to load topology" )
193 # Exit if topology did not load properly
194 if not topoResult:
195 main.cleanAndExit()
196
197 main.step( "Assign switches to controllers." )
198 assignResult = main.TRUE
199 for i in range( 1, 2 ):
200 assignResult = assignResult & main.NetworkBench.assignSwController( sw="s" + str( i ),
201 ip=main.Cluster.getIps(),
202 port='6653' )
203 utilities.assert_equals( expect=main.TRUE,
204 actual=stepResult,
205 onpass="Successfully assign switches to controllers",
206 onfail="Failed to assign switches to controllers" )
207
208 main.step( "Start scapy" )
209 scapyResult = main.TRUE
210 for hostName in main.scapyHostNames:
211 main.scapyHosts.append( getattr( main, hostName ) )
212
213 for host in main.scapyHosts:
214 host.startScapy()
215 host.updateSelf()
216 main.log.debug( host.name )
217 main.log.debug( host.hostIp )
218 main.log.debug( host.hostMac )
219
220 utilities.assert_equals( expect=main.TRUE,
221 actual=scapyResult,
222 onpass="Successfully created Scapy Components",
223 onfail="Failed to discover Scapy Components" )
224
kavitha Alagesan373e0552016-11-22 05:22:05 +0530225 def CASE4( self, main ):
Jon Hall602d0a72017-05-24 16:06:53 -0700226 """
kavitha Alagesan373e0552016-11-22 05:22:05 +0530227 Testing scapy
Jon Hall602d0a72017-05-24 16:06:53 -0700228 """
kavitha Alagesan373e0552016-11-22 05:22:05 +0530229 main.case( "Testing scapy" )
You Wangdafb6e22018-01-22 17:01:00 -0800230 for host in main.scapyHosts:
231 host.stopScapy()
Jon Hall602d0a72017-05-24 16:06:53 -0700232 host.startScapy()
233 host.updateSelf()
kavitha Alagesan373e0552016-11-22 05:22:05 +0530234 main.log.debug( host.name )
235 main.log.debug( host.hostIp )
236 main.log.debug( host.hostMac )
237
238 main.step( "Sending/Receiving Test packet - Filter doesn't match" )
239 main.log.info( "Starting Filter..." )
Jon Hall602d0a72017-05-24 16:06:53 -0700240 main.h2.startFilter()
kavitha Alagesan373e0552016-11-22 05:22:05 +0530241 main.log.info( "Building Ether frame..." )
242 main.h1.buildEther( dst=main.h2.hostMac )
243 main.log.info( "Sending Packet..." )
Jon Hall602d0a72017-05-24 16:06:53 -0700244 main.h1.sendPacket()
kavitha Alagesan373e0552016-11-22 05:22:05 +0530245 main.log.info( "Checking Filter..." )
Jon Hall602d0a72017-05-24 16:06:53 -0700246 finished = main.h2.checkFilter()
kavitha Alagesan373e0552016-11-22 05:22:05 +0530247 main.log.debug( finished )
248 i = ""
249 if finished:
Jon Hall602d0a72017-05-24 16:06:53 -0700250 a = main.h2.readPackets()
251 for i in a.splitlines():
kavitha Alagesan373e0552016-11-22 05:22:05 +0530252 main.log.info( i )
253 else:
Jon Hall602d0a72017-05-24 16:06:53 -0700254 kill = main.h2.killFilter()
kavitha Alagesan373e0552016-11-22 05:22:05 +0530255 main.log.debug( kill )
256 main.h2.handle.sendline( "" )
257 main.h2.handle.expect( main.h2.scapyPrompt )
258 main.log.debug( main.h2.handle.before )
259 utilities.assert_equals( expect=True,
260 actual="dst=00:00:00:00:00:02 src=00:00:00:00:00:01" in i,
261 onpass="Pass",
262 onfail="Fail" )
263
264 main.step( "Sending/Receiving Test packet - Filter matches" )
Jon Hall602d0a72017-05-24 16:06:53 -0700265 main.h2.startFilter()
kavitha Alagesan373e0552016-11-22 05:22:05 +0530266 main.h1.buildEther( dst=main.h2.hostMac )
267 main.h1.buildIP( dst=main.h2.hostIp )
Jon Hall602d0a72017-05-24 16:06:53 -0700268 main.h1.sendPacket()
269 finished = main.h2.checkFilter()
kavitha Alagesan373e0552016-11-22 05:22:05 +0530270 i = ""
271 if finished:
Jon Hall602d0a72017-05-24 16:06:53 -0700272 a = main.h2.readPackets()
273 for i in a.splitlines():
kavitha Alagesan373e0552016-11-22 05:22:05 +0530274 main.log.info( i )
275 else:
Jon Hall602d0a72017-05-24 16:06:53 -0700276 kill = main.h2.killFilter()
kavitha Alagesan373e0552016-11-22 05:22:05 +0530277 main.log.debug( kill )
278 main.h2.handle.sendline( "" )
279 main.h2.handle.expect( main.h2.scapyPrompt )
280 main.log.debug( main.h2.handle.before )
281 utilities.assert_equals( expect=True,
282 actual="dst=00:00:00:00:00:02 src=00:00:00:00:00:01" in i,
283 onpass="Pass",
284 onfail="Fail" )
285
kavitha Alagesan373e0552016-11-22 05:22:05 +0530286 def CASE5( self, main ):
Jon Hall602d0a72017-05-24 16:06:53 -0700287 """
kavitha Alagesan373e0552016-11-22 05:22:05 +0530288 Adding Group of type "ALL" using Rest api
Jon Hall602d0a72017-05-24 16:06:53 -0700289 """
kavitha Alagesan373e0552016-11-22 05:22:05 +0530290 import json
291 import time
292 isAdded = main.FALSE
293 main.case( "Verify Group of type All are successfully Added" )
294 main.caseExplanation = " Install a Group of type ALL " +\
295 " Verify the Group is Added " +\
296 " Add a flow using the group " +\
297 " Send a packet that verifies the action bucket of the group"
298
299 main.step( "Add Group using Rest api" )
300 bucketList = []
Jon Hall602d0a72017-05-24 16:06:53 -0700301 bucket = main.buckets.addBucket( main, egressPort=egressPort1 )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530302 bucketList.append( bucket )
Jon Hall602d0a72017-05-24 16:06:53 -0700303 bucket = main.buckets.addBucket( main, egressPort=egressPort2 )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530304 bucketList.append( bucket )
Jon Hall602d0a72017-05-24 16:06:53 -0700305 bucket = main.buckets.addBucket( main, egressPort=egressPort3 )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530306 bucketList.append( bucket )
Devin Lim142b5342017-07-20 15:22:39 -0700307 ctrl = main.Cluster.active( 0 )
308 response = ctrl.REST.addGroup( deviceId=deviceId,
309 groupType=type1,
310 bucketList=bucketList,
311 appCookie=appCookie,
312 groupId=groupId )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530313
314 utilities.assert_equals( expect=main.TRUE,
315 actual=response,
316 onpass="Successfully added Groups of type ALL",
317 onfail="Failed to add Groups of type ALL" )
318
319 # Giving ONOS time to add the group
320 time.sleep( main.addGroupSleep )
321
322 main.step( "Check groups are in ADDED state" )
323
Devin Lim142b5342017-07-20 15:22:39 -0700324 response = ctrl.REST.getGroups( deviceId=deviceId,
325 appCookie=appCookie )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530326 responsejson = json.loads( response )
Jon Hall602d0a72017-05-24 16:06:53 -0700327 for item in responsejson:
328 if item[ "state" ] == "ADDED":
kavitha Alagesan373e0552016-11-22 05:22:05 +0530329 isAdded = main.TRUE
330
331 utilities.assert_equals( expect=main.TRUE,
332 actual=isAdded,
333 onpass="All Group is in Added State",
334 onfail="All Group is not in Added State" )
335
Jon Hall602d0a72017-05-24 16:06:53 -0700336 """
kavitha Alagesan373e0552016-11-22 05:22:05 +0530337 Adding flow using rest api
Jon Hall602d0a72017-05-24 16:06:53 -0700338 """
kavitha Alagesan373e0552016-11-22 05:22:05 +0530339 isAdded = main.FALSE
340
341 main.step( "Adding flow with Group using rest api" )
Devin Lim142b5342017-07-20 15:22:39 -0700342 response = ctrl.REST.addFlow( deviceId=deviceId,
343 priority=priority,
344 ingressPort=ingressPort,
345 groupId=groupId )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530346 utilities.assert_equals( expect=main.TRUE,
347 actual=response,
348 onpass="Successfully Added Flows",
349 onfail="Failed to Add flows" )
350
351 # Giving ONOS time to add the flow
352 time.sleep( main.addFlowSleep )
353
Devin Lim142b5342017-07-20 15:22:39 -0700354 response = ctrl.REST.getFlows( deviceId=deviceId )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530355 responsejson = json.loads( response )
Jon Hall602d0a72017-05-24 16:06:53 -0700356 for item in responsejson:
357 if item[ "priority" ] == int( priority ) and item[ "state" ] == "ADDED":
kavitha Alagesan373e0552016-11-22 05:22:05 +0530358 isAdded = main.TRUE
359
360 utilities.assert_equals( expect=main.TRUE,
361 actual=isAdded,
362 onpass="Flow is in Added State",
363 onfail="Flow is not in Added State" )
364
Jon Hall602d0a72017-05-24 16:06:53 -0700365 """
kavitha Alagesan373e0552016-11-22 05:22:05 +0530366 Sends a packet using scapy
Jon Hall602d0a72017-05-24 16:06:53 -0700367 """
Devin Lim58046fa2017-07-05 16:55:00 -0700368 main.step( "Testing Group by sending packet using Scapy" )
You Wangdafb6e22018-01-22 17:01:00 -0800369 for host in main.scapyHosts:
370 host.stopScapy()
Jon Hall602d0a72017-05-24 16:06:53 -0700371 host.startScapy()
372 host.updateSelf()
You Wangdafb6e22018-01-22 17:01:00 -0800373 main.log.debug( host.name )
374 main.log.debug( host.hostIp )
375 main.log.debug( host.hostMac )
376
kavitha Alagesan373e0552016-11-22 05:22:05 +0530377 main.log.info( "Constructing Packet" )
378 main.h1.buildEther( dst=main.h1.hostMac )
379 main.h1.buildIP( dst=main.h1.hostIp )
380 main.log.info( "Start Filter on host2,host3,host4" )
381 main.h2.startFilter( pktFilter="ether host %s and ip host %s" % ( main.h1.hostMac, main.h1.hostIp ) )
382 main.h3.startFilter( pktFilter="ether host %s and ip host %s" % ( main.h1.hostMac, main.h1.hostIp ) )
383 main.h4.startFilter( pktFilter="ether host %s and ip host %s" % ( main.h1.hostMac, main.h1.hostIp ) )
384 main.log.info( "sending packet to Host" )
Jon Hall602d0a72017-05-24 16:06:53 -0700385 main.h1.sendPacket()
kavitha Alagesan373e0552016-11-22 05:22:05 +0530386 main.log.info( "Checking filter for our packet" )
Jon Hall602d0a72017-05-24 16:06:53 -0700387 stepResultH2 = main.h2.checkFilter()
388 stepResultH3 = main.h3.checkFilter()
389 stepResultH4 = main.h4.checkFilter()
kavitha Alagesan373e0552016-11-22 05:22:05 +0530390
391 if stepResultH2:
Jon Hall602d0a72017-05-24 16:06:53 -0700392 main.log.info( "Packet : %s" % main.h2.readPackets() )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530393 else:
Jon Hall602d0a72017-05-24 16:06:53 -0700394 main.h2.killFilter()
kavitha Alagesan373e0552016-11-22 05:22:05 +0530395
396 if stepResultH3:
Jon Hall602d0a72017-05-24 16:06:53 -0700397 main.log.info( "Packet : %s" % main.h3.readPackets() )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530398 else:
Jon Hall602d0a72017-05-24 16:06:53 -0700399 main.h2.killFilter()
kavitha Alagesan373e0552016-11-22 05:22:05 +0530400
401 if stepResultH4:
Jon Hall602d0a72017-05-24 16:06:53 -0700402 main.log.info( "Packet : %s" % main.h4.readPackets() )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530403 else:
Jon Hall602d0a72017-05-24 16:06:53 -0700404 main.h4.killFilter()
kavitha Alagesan373e0552016-11-22 05:22:05 +0530405
Jon Hall602d0a72017-05-24 16:06:53 -0700406 if stepResultH2 and stepResultH3 and stepResultH4:
kavitha Alagesan373e0552016-11-22 05:22:05 +0530407 main.log.info( "Success!!!Packet sent to port 1 is received at port 2,3 and 4" )
408 stepResult = main.TRUE
409 else:
410 main.log.info( "Failure!!!Packet sent to port 1 is not received at port 2,3 and 4" )
411 stepResult = main.FALSE
412
kavitha Alagesan373e0552016-11-22 05:22:05 +0530413 utilities.assert_equals( expect=main.TRUE,
414 actual=stepResult,
415 onpass="Packet sent to port 1 is received at port 2,3,4 ",
416 onfail="Packet sent to port 1 is not received at port 2,3,4 " )
417
418 def CASE6( self, main ):
Jon Hall602d0a72017-05-24 16:06:53 -0700419 """
kavitha Alagesan373e0552016-11-22 05:22:05 +0530420 Deleting the Group and Flow
Jon Hall602d0a72017-05-24 16:06:53 -0700421 """
kavitha Alagesan373e0552016-11-22 05:22:05 +0530422 import json
423 import time
424 respFlowId = 1
425
426 main.case( "Delete the Group and Flow added through Rest api " )
427 main.step( "Deleting Group and Flows" )
Devin Lim142b5342017-07-20 15:22:39 -0700428 ctrl = main.Cluster.active( 0 )
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700429 # Get Flow ID
Devin Lim142b5342017-07-20 15:22:39 -0700430 response = ctrl.REST.getFlows( deviceId=deviceId )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530431 responsejson = json.loads( response )
Jon Hall602d0a72017-05-24 16:06:53 -0700432 for item in responsejson:
433 if item[ "priority" ] == int( priority ):
434 respFlowId = item[ "id" ]
kavitha Alagesan373e0552016-11-22 05:22:05 +0530435
436 main.step( "Deleting the created flow by deviceId and flowId" )
Devin Lim142b5342017-07-20 15:22:39 -0700437 flowResponse = ctrl.REST.removeFlow( deviceId=deviceId,
438 flowId=respFlowId )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530439
440 utilities.assert_equals( expect=main.TRUE,
441 actual=flowResponse,
442 onpass="Deleting flow is successful!!!",
443 onfail="Deleting flow is failure!!!" )
444
445 # Giving ONOS time to delete the flow
446 time.sleep( main.delFlowSleep )
447
448 main.step( "Deleting the created group by deviceId and appCookie" )
Devin Lim142b5342017-07-20 15:22:39 -0700449 groupResponse = ctrl.REST.removeGroup( deviceId=deviceId,
450 appCookie=appCookie )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530451
452 utilities.assert_equals( expect=main.TRUE,
453 actual=groupResponse,
454 onpass="Deleting Group is successful!!!",
455 onfail="Deleting Group is failure!!!" )
456
457 # Giving ONOS time to delete the group
458 time.sleep( main.delGroupSleep )
459
460 def CASE7( self, main ):
Jon Hall602d0a72017-05-24 16:06:53 -0700461 """
kavitha Alagesan373e0552016-11-22 05:22:05 +0530462 Adding Group of type "INDIRECT" using Rest api.
Jon Hall602d0a72017-05-24 16:06:53 -0700463 """
kavitha Alagesan373e0552016-11-22 05:22:05 +0530464 import json
465 import time
466 isAdded = main.FALSE
467
468 main.case( "Verify Group of type INDIRECT are successfully Added" )
469 main.caseExplanation = " Install a Group of type INDIRECT " +\
470 " Verify the Group is Added " +\
471 " Add a flow using the group " +\
472 " Send a packet that verifies the action bucket of the group"
473
474 main.step( "Add Group using Rest api" )
Devin Lim142b5342017-07-20 15:22:39 -0700475 ctrl = main.Cluster.active( 0 )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530476 bucketList = []
Jon Hall602d0a72017-05-24 16:06:53 -0700477 bucket = main.buckets.addBucket( main, egressPort=egressPort1 )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530478 bucketList.append( bucket )
Devin Lim142b5342017-07-20 15:22:39 -0700479 response = ctrl.REST.addGroup( deviceId=deviceId,
480 groupType=type2,
481 bucketList=bucketList,
482 appCookie=appCookie,
483 groupId=groupId )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530484
485 utilities.assert_equals( expect=main.TRUE,
486 actual=response,
487 onpass="Successfully added Groups of type INDIRECT",
488 onfail="Failed to add Groups of type INDIRECT" )
489
490 # Giving ONOS time to add the group
491 time.sleep( main.addGroupSleep )
492
493 main.step( "Check groups are in ADDED state" )
494
Devin Lim142b5342017-07-20 15:22:39 -0700495 response = ctrl.REST.getGroups( deviceId=deviceId,
496 appCookie=appCookie )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530497 responsejson = json.loads( response )
Jon Hall602d0a72017-05-24 16:06:53 -0700498 for item in responsejson:
499 if item[ "state" ] == "ADDED":
kavitha Alagesan373e0552016-11-22 05:22:05 +0530500 isAdded = main.TRUE
501
502 utilities.assert_equals( expect=main.TRUE,
503 actual=isAdded,
504 onpass="INDIRECT Group is in Added State",
505 onfail="INDIRECT Group is not in Added State" )
506
Jon Hall602d0a72017-05-24 16:06:53 -0700507 """
kavitha Alagesan373e0552016-11-22 05:22:05 +0530508 Adding flows using rest api
Jon Hall602d0a72017-05-24 16:06:53 -0700509 """
kavitha Alagesan373e0552016-11-22 05:22:05 +0530510 isAdded = main.FALSE
511
512 main.step( "Adding flow with Group using rest api" )
Devin Lim142b5342017-07-20 15:22:39 -0700513 response = ctrl.REST.addFlow( deviceId=deviceId,
514 priority=priority,
515 ingressPort=ingressPort,
516 groupId=groupId )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530517 utilities.assert_equals( expect=main.TRUE,
518 actual=response,
519 onpass="Successfully Added Flows",
520 onfail="Failed to Add flows" )
521
522 # Giving ONOS time to add the flow
523 time.sleep( main.addFlowSleep )
524
Devin Lim142b5342017-07-20 15:22:39 -0700525 response = ctrl.REST.getFlows( deviceId=deviceId )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530526 responsejson = json.loads( response )
Jon Hall602d0a72017-05-24 16:06:53 -0700527 for item in responsejson:
528 if item[ "priority" ] == int( priority ) and item[ "state" ] == "ADDED":
kavitha Alagesan373e0552016-11-22 05:22:05 +0530529 isAdded = main.TRUE
530
531 utilities.assert_equals( expect=main.TRUE,
532 actual=isAdded,
533 onpass="Flow is in Added State",
534 onfail="Flow is not in Added State" )
535
Jon Hall602d0a72017-05-24 16:06:53 -0700536 """
kavitha Alagesan373e0552016-11-22 05:22:05 +0530537 Sends a packet using scapy
Jon Hall602d0a72017-05-24 16:06:53 -0700538 """
Devin Lim58046fa2017-07-05 16:55:00 -0700539 main.step( "Testing Group by sending packet using Scapy" )
You Wangdafb6e22018-01-22 17:01:00 -0800540 for host in main.scapyHosts:
541 host.stopScapy()
Jon Hall602d0a72017-05-24 16:06:53 -0700542 host.startScapy()
543 host.updateSelf()
You Wangdafb6e22018-01-22 17:01:00 -0800544 main.log.debug( host.name )
545 main.log.debug( host.hostIp )
546 main.log.debug( host.hostMac )
547
kavitha Alagesan373e0552016-11-22 05:22:05 +0530548 main.log.info( "Constructing Packet" )
549 main.h1.buildEther( dst=main.h1.hostMac )
550 main.h1.buildIP( dst=main.h1.hostIp )
551 main.log.info( "Start Filter on host2" )
552 main.h2.startFilter( pktFilter="ether host %s and ip host %s" % ( main.h1.hostMac, main.h1.hostIp ) )
553 main.log.info( "sending packet to Host" )
Jon Hall602d0a72017-05-24 16:06:53 -0700554 main.h1.sendPacket()
kavitha Alagesan373e0552016-11-22 05:22:05 +0530555 main.log.info( "Checking filter for our packet" )
Jon Hall602d0a72017-05-24 16:06:53 -0700556 stepResultH2 = main.h2.checkFilter()
kavitha Alagesan373e0552016-11-22 05:22:05 +0530557
558 if stepResultH2:
Jon Hall602d0a72017-05-24 16:06:53 -0700559 main.log.info( "Packet : %s" % main.h2.readPackets() )
kavitha Alagesan373e0552016-11-22 05:22:05 +0530560 else:
Jon Hall602d0a72017-05-24 16:06:53 -0700561 main.h2.killFilter()
kavitha Alagesan373e0552016-11-22 05:22:05 +0530562
kavitha Alagesan373e0552016-11-22 05:22:05 +0530563 utilities.assert_equals( expect=main.TRUE,
564 actual=stepResultH2,
565 onpass="Packet sent to port 1 is received at port 2 successfully!!!",
566 onfail="Failure!!!Packet sent to port 1 is not received at port 2" )
567
You Wangdafb6e22018-01-22 17:01:00 -0800568 def CASE10( self, main ):
569 """
570 Stop mininet and remove scapy host
571 """
572 try:
573 from tests.dependencies.utils import Utils
574 except ImportError:
575 main.log.error( "Utils not found exiting the test" )
576 main.cleanAndExit()
577 try:
578 main.Utils
579 except ( NameError, AttributeError ):
580 main.Utils = Utils()
581 main.log.report( "Stop Mininet and Scapy" )
582 main.case( "Stop Mininet and Scapy" )
583 main.caseExplanation = "Stopping the current mininet topology " +\
584 "to start up fresh"
585 main.step( "Stopping and Removing Scapy Host Components" )
586 scapyResult = main.TRUE
587 for host in main.scapyHosts:
588 scapyResult = scapyResult and host.stopScapy()
589 main.log.info( "Stopped Scapy Host: {0}".format( host.name ) )
590
591 for host in main.scapyHosts:
592 scapyResult = scapyResult and main.Scapy.removeHostComponent( host.name )
593 main.log.info( "Removed Scapy Host Component: {0}".format( host.name ) )
594
595 main.scapyHosts = []
596
597 utilities.assert_equals( expect=main.TRUE,
598 actual=scapyResult,
599 onpass="Successfully stopped scapy and removed host components",
600 onfail="Failed to stop mininet and scapy" )
601
602 mininetResult = main.Utils.mininetCleanup( main.Mininet1 )
603 # Exit if topology did not load properly
604 if not ( mininetResult and scapyResult ):
605 main.cleanAndExit()
606
You Wang84f981d2018-01-12 16:11:50 -0800607 def CASE12( self, main ):
608 """
609 Stop Scapy on physical hosts
610 """
611 main.case( "Stop Scapy" )
612 main.step( "Stopping Scapy Hosts" )
613 scapyResult = main.TRUE
614 for host in main.scapyHosts:
615 host.stopScapy()
616 utilities.assert_equals( expect=main.TRUE,
617 actual=scapyResult,
618 onpass="Successfully stopped scapy",
619 onfail="Failed to stop scapy" )
620
kavitha Alagesan373e0552016-11-22 05:22:05 +0530621 def CASE100( self, main ):
Jon Hall602d0a72017-05-24 16:06:53 -0700622 """
kavitha Alagesan373e0552016-11-22 05:22:05 +0530623 Report errors/warnings/exceptions
Jon Hall602d0a72017-05-24 16:06:53 -0700624 """
kavitha Alagesan373e0552016-11-22 05:22:05 +0530625 main.log.info( "Error report: \n" )
Devin Lim142b5342017-07-20 15:22:39 -0700626 main.ONOSbench.logReport( main.Cluster.active( 0 ).ipAddress,
kavitha Alagesan373e0552016-11-22 05:22:05 +0530627 [ "INFO",
628 "FOLLOWER",
629 "WARN",
630 "flow",
631 "group",
632 "ERROR",
633 "Except" ],
634 "s" )