blob: d133bf723af795cc6efe7432a0ac619a6e14bf1f [file] [log] [blame]
Jeremy Ronquillob27ce4c2017-07-17 12:41:28 -07001"""
2Copyright 2015 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
GlennRC5147a422015-10-06 17:26:17 -070022class FUNCflow:
23
24 def __init__( self ):
25 self.default = ''
26
27 def CASE1( self, main ):
GlennRC5147a422015-10-06 17:26:17 -070028 import os
29 import imp
Devin Lim58046fa2017-07-05 16:55:00 -070030 try:
31 from tests.dependencies.ONOSSetup import ONOSSetup
32 except ImportError:
33 main.log.error( "SetUp not found exiting the test" )
34 main.exit()
35 try:
36 main.testSetUp
37 except ( NameError, AttributeError ):
38 main.testSetUp = ONOSSetup()
GlennRC5147a422015-10-06 17:26:17 -070039 """
40 - Construct tests variables
41 - GIT ( optional )
42 - Checkout ONOS master branch
43 - Pull latest ONOS code
GlennRC5147a422015-10-06 17:26:17 -070044 """
GlennRC5147a422015-10-06 17:26:17 -070045
Devin Lim58046fa2017-07-05 16:55:00 -070046 main.testSetUp.envSetupDescription()
47 stepResult = main.FALSE
48 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 main.maxNodes = int( main.params[ 'SCALE' ][ 'max' ] )
59 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.debug = main.params[ 'DEBUG' ]
64 main.swDPID = main.params[ 'TEST' ][ 'swDPID' ]
GlennRC5147a422015-10-06 17:26:17 -070065
Devin Lim58046fa2017-07-05 16:55:00 -070066 main.debug = True if "on" in main.debug else False
GlennRC956ea742015-11-05 16:14:15 -080067
Devin Lim58046fa2017-07-05 16:55:00 -070068 # -- INIT SECTION, ONLY RUNS ONCE -- #
GlennRC5147a422015-10-06 17:26:17 -070069
Devin Lim58046fa2017-07-05 16:55:00 -070070 try:
71 from tests.FUNC.FUNCflow.dependencies.checkingFlow import CheckingFlow
72 main.checkingFlow = CheckingFlow()
73 except ImportError as e:
74 print e
75 main.log.error("CheckingFlow not found exiting the test")
76 main.exit()
77 copyResult = main.ONOSbench.scp( main.Mininet1,
78 main.dependencyPath + main.topology,
79 main.Mininet1.home + '/custom/',
80 direction="to" )
GlennRC5147a422015-10-06 17:26:17 -070081
Devin Lim58046fa2017-07-05 16:55:00 -070082 utilities.assert_equals( expect=main.TRUE,
83 actual=copyResult,
84 onpass="Successfully copy " + "test variables ",
85 onfail="Failed to copy test variables" )
GlennRC5147a422015-10-06 17:26:17 -070086
Devin Lim58046fa2017-07-05 16:55:00 -070087 stepResult = main.testSetUp.envSetup()
GlennRC1704d072015-10-07 18:40:45 -070088
Devin Lim58046fa2017-07-05 16:55:00 -070089 except Exception as e:
90 main.testSetUp.envSetupException( e )
91 main.testSetUp.evnSetupConclusion( stepResult )
Devin Lim8d7c7782017-06-07 16:21:20 -070092
GlennRC5147a422015-10-06 17:26:17 -070093
94 def CASE2( self, main ):
95 """
96 - Set up cell
97 - Create cell file
98 - Set cell file
99 - Verify cell file
Devin Lim58046fa2017-07-05 16:55:00 -0700100 - Building ONOS
101 - Install ONOS package
102 - Build ONOS package
GlennRC5147a422015-10-06 17:26:17 -0700103 - Kill ONOS process
104 - Uninstall ONOS cluster
105 - Verify ONOS start up
106 - Install ONOS cluster
107 - Connect to cli
108 """
Devin Lim58046fa2017-07-05 16:55:00 -0700109 main.testSetUp.ONOSSetUp( main.Mininet1 )
GlennRC5147a422015-10-06 17:26:17 -0700110
GlennRC68449942015-10-16 16:03:12 -0700111 def CASE10( self, main ):
Jon Hallfc951072017-05-24 15:55:34 -0700112 """
GlennRC68449942015-10-16 16:03:12 -0700113 Start Mininet
Jon Hallfc951072017-05-24 15:55:34 -0700114 """
GlennRC073e8bc2015-10-27 17:11:28 -0700115 import json
Devin Lim58046fa2017-07-05 16:55:00 -0700116 import time
117 try:
118 from tests.dependencies.topology import Topology
119 except ImportError:
120 main.log.error( "Topology not found exiting the test" )
121 main.exit()
122 try:
123 main.topoRelated
124 except ( NameError, AttributeError ):
125 main.topoRelated = Topology()
GlennRC073e8bc2015-10-27 17:11:28 -0700126
127 main.case( "Setup mininet and compare ONOS topology view to Mininet topology" )
128 main.caseExplanation = "Start mininet with custom topology and compare topology " +\
129 "elements between Mininet and ONOS"
130
GlennRC68449942015-10-16 16:03:12 -0700131 main.step( "Setup Mininet Topology" )
132 topology = main.Mininet1.home + '/custom/' + main.topology
Jon Hallfc951072017-05-24 15:55:34 -0700133 stepResult = main.Mininet1.startNet( topoFile=topology )
GlennRC68449942015-10-16 16:03:12 -0700134
135 utilities.assert_equals( expect=main.TRUE,
GlennRC073e8bc2015-10-27 17:11:28 -0700136 actual=stepResult,
GlennRC68449942015-10-16 16:03:12 -0700137 onpass="Successfully loaded topology",
138 onfail="Failed to load topology" )
139
GlennRC073e8bc2015-10-27 17:11:28 -0700140 main.step( "Assign switch to controller" )
Jon Hallfc951072017-05-24 15:55:34 -0700141 stepResult = main.Mininet1.assignSwController( "s1", main.ONOSip[ 0 ] )
GlennRC68449942015-10-16 16:03:12 -0700142
143 utilities.assert_equals( expect=main.TRUE,
GlennRC073e8bc2015-10-27 17:11:28 -0700144 actual=stepResult,
145 onpass="Successfully assigned switch to controller",
146 onfail="Failed to assign switch to controller" )
GlennRC68449942015-10-16 16:03:12 -0700147
GlennRC073e8bc2015-10-27 17:11:28 -0700148 time.sleep( main.startMNSleep )
GlennRC68449942015-10-16 16:03:12 -0700149
Devin Lim58046fa2017-07-05 16:55:00 -0700150 main.topoRelated.compareTopos( main.Mininet1 )
GlennRC68449942015-10-16 16:03:12 -0700151
Jon Hall892818c2015-10-20 17:58:34 -0700152 def CASE66( self, main ):
Jon Hallfc951072017-05-24 15:55:34 -0700153 """
Jon Hall892818c2015-10-20 17:58:34 -0700154 Testing scapy
Jon Hallfc951072017-05-24 15:55:34 -0700155 """
Jon Hall892818c2015-10-20 17:58:34 -0700156 main.case( "Testing scapy" )
157 main.step( "Creating Host1 component" )
Jon Halla510a8a2016-05-04 15:09:28 -0700158 main.Scapy.createHostComponent( "h1" )
159 main.Scapy.createHostComponent( "h2" )
alisone14d7b02016-07-06 10:31:51 -0700160 hosts = [ main.h1, main.h2 ]
Jon Hall892818c2015-10-20 17:58:34 -0700161 for host in hosts:
Jon Hallfc951072017-05-24 15:55:34 -0700162 host.startHostCli()
163 host.startScapy()
164 host.updateSelf()
Jon Hall892818c2015-10-20 17:58:34 -0700165 main.log.debug( host.name )
166 main.log.debug( host.hostIp )
167 main.log.debug( host.hostMac )
168
169 main.step( "Sending/Receiving Test packet - Filter doesn't match" )
Jon Halla510a8a2016-05-04 15:09:28 -0700170 main.log.info( "Starting Filter..." )
Jon Hallfc951072017-05-24 15:55:34 -0700171 main.h2.startFilter()
Jon Halla510a8a2016-05-04 15:09:28 -0700172 main.log.info( "Building Ether frame..." )
Jon Hall892818c2015-10-20 17:58:34 -0700173 main.h1.buildEther( dst=main.h2.hostMac )
Jon Halla510a8a2016-05-04 15:09:28 -0700174 main.log.info( "Sending Packet..." )
Jon Hallfc951072017-05-24 15:55:34 -0700175 main.h1.sendPacket()
Jon Halla510a8a2016-05-04 15:09:28 -0700176 main.log.info( "Checking Filter..." )
Jon Hallfc951072017-05-24 15:55:34 -0700177 finished = main.h2.checkFilter()
Jon Halla510a8a2016-05-04 15:09:28 -0700178 main.log.debug( finished )
Jon Hall892818c2015-10-20 17:58:34 -0700179 i = ""
180 if finished:
Jon Hallfc951072017-05-24 15:55:34 -0700181 a = main.h2.readPackets()
182 for i in a.splitlines():
Jon Hall892818c2015-10-20 17:58:34 -0700183 main.log.info( i )
184 else:
Jon Hallfc951072017-05-24 15:55:34 -0700185 kill = main.h2.killFilter()
Jon Hall892818c2015-10-20 17:58:34 -0700186 main.log.debug( kill )
187 main.h2.handle.sendline( "" )
188 main.h2.handle.expect( main.h2.scapyPrompt )
189 main.log.debug( main.h2.handle.before )
190 utilities.assert_equals( expect=True,
191 actual="dst=00:00:00:00:00:02 src=00:00:00:00:00:01" in i,
192 onpass="Pass",
193 onfail="Fail" )
194
195 main.step( "Sending/Receiving Test packet - Filter matches" )
Jon Hallfc951072017-05-24 15:55:34 -0700196 main.h2.startFilter()
Jon Hall892818c2015-10-20 17:58:34 -0700197 main.h1.buildEther( dst=main.h2.hostMac )
198 main.h1.buildIP( dst=main.h2.hostIp )
Jon Hallfc951072017-05-24 15:55:34 -0700199 main.h1.sendPacket()
200 finished = main.h2.checkFilter()
Jon Hall892818c2015-10-20 17:58:34 -0700201 i = ""
202 if finished:
Jon Hallfc951072017-05-24 15:55:34 -0700203 a = main.h2.readPackets()
204 for i in a.splitlines():
Jon Hall892818c2015-10-20 17:58:34 -0700205 main.log.info( i )
206 else:
Jon Hallfc951072017-05-24 15:55:34 -0700207 kill = main.h2.killFilter()
Jon Hall892818c2015-10-20 17:58:34 -0700208 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
Jon Hall892818c2015-10-20 17:58:34 -0700217 main.step( "Clean up host components" )
218 for host in hosts:
Jon Hallfc951072017-05-24 15:55:34 -0700219 host.stopScapy()
alisone14d7b02016-07-06 10:31:51 -0700220 main.Mininet1.removeHostComponent( "h1" )
221 main.Mininet1.removeHostComponent( "h2" )
Jon Hall892818c2015-10-20 17:58:34 -0700222
GlennRC68449942015-10-16 16:03:12 -0700223 def CASE1000( self, main ):
Jon Hallfc951072017-05-24 15:55:34 -0700224 """
GlennRC073e8bc2015-10-27 17:11:28 -0700225 Add flows with MAC selectors and verify the flows
Jon Hallfc951072017-05-24 15:55:34 -0700226 """
GlennRC073e8bc2015-10-27 17:11:28 -0700227 import json
228 import time
GlennRC68449942015-10-16 16:03:12 -0700229
GlennRC073e8bc2015-10-27 17:11:28 -0700230 main.case( "Verify flow MAC selectors are correctly compiled" )
231 main.caseExplanation = "Install two flows with only MAC selectors " +\
Jon Hallfc951072017-05-24 15:55:34 -0700232 "specified, then verify flows are added in ONOS, finally " +\
GlennRC073e8bc2015-10-27 17:11:28 -0700233 "send a packet that only specifies the MAC src and dst."
GlennRC68449942015-10-16 16:03:12 -0700234
GlennRC073e8bc2015-10-27 17:11:28 -0700235 main.step( "Add flows with MAC addresses as the only selectors" )
GlennRC68449942015-10-16 16:03:12 -0700236
GlennRC073e8bc2015-10-27 17:11:28 -0700237 main.log.info( "Creating host components" )
Jon Halla510a8a2016-05-04 15:09:28 -0700238 main.Scapy.createHostComponent( "h1" )
239 main.Scapy.createHostComponent( "h2" )
alisone14d7b02016-07-06 10:31:51 -0700240 hosts = [ main.h1, main.h2 ]
GlennRC073e8bc2015-10-27 17:11:28 -0700241 for host in hosts:
Jon Hallfc951072017-05-24 15:55:34 -0700242 host.startHostCli()
243 host.startScapy()
244 host.updateSelf()
GlennRC68449942015-10-16 16:03:12 -0700245
GlennRC073e8bc2015-10-27 17:11:28 -0700246 # Add a flow that connects host1 on port1 to host2 on port2
247 # send output on port2
248 # recieve input on port1
249 egress = 2
250 ingress = 1
251
252 # Add flows that sends packets from port1 to port2 with correct
253 # MAC src and dst addresses
254 main.log.info( "Adding flow with MAC selectors" )
255 stepResult = main.ONOSrest.addFlow( deviceId=main.swDPID,
256 egressPort=egress,
257 ingressPort=ingress,
258 ethSrc=main.h1.hostMac,
259 ethDst=main.h2.hostMac,
GlennRC956ea742015-11-05 16:14:15 -0800260 debug=main.debug )
GlennRC68449942015-10-16 16:03:12 -0700261
GlennRCa5391372015-10-14 17:28:15 -0700262 utilities.assert_equals( expect=main.TRUE,
263 actual=stepResult,
GlennRC68449942015-10-16 16:03:12 -0700264 onpass="Successfully added flows",
265 onfail="Failed add flows" )
GlennRCa5391372015-10-14 17:28:15 -0700266
GlennRC073e8bc2015-10-27 17:11:28 -0700267 # Giving ONOS time to add the flows
268 time.sleep( main.addFlowSleep )
GlennRC5147a422015-10-06 17:26:17 -0700269
GlennRC073e8bc2015-10-27 17:11:28 -0700270 main.step( "Check flows are in the ADDED state" )
271
GlennRC073e8bc2015-10-27 17:11:28 -0700272 main.log.info( "Get the flows from ONOS" )
Jeremy86160992016-04-11 10:05:53 -0700273 try:
Jon Hallfc951072017-05-24 15:55:34 -0700274 flows = json.loads( main.ONOSrest.flows() )
GlennRC68449942015-10-16 16:03:12 -0700275
Jeremy86160992016-04-11 10:05:53 -0700276 stepResult = main.TRUE
277 for f in flows:
alisone14d7b02016-07-06 10:31:51 -0700278 if "rest" in f.get( "appId" ):
279 if "ADDED" not in f.get( "state" ):
Jeremy86160992016-04-11 10:05:53 -0700280 stepResult = main.FALSE
alisone14d7b02016-07-06 10:31:51 -0700281 main.log.error( "Flow: %s in state: %s" % ( f.get( "id" ), f.get( "state" ) ) )
Jeremy86160992016-04-11 10:05:53 -0700282 except TypeError:
283 main.log.error( "No Flows found by the REST API" )
284 stepResult = main.FALSE
285 except ValueError:
286 main.log.error( "Problem getting Flows state from REST API. Exiting test" )
Jon Hallfc951072017-05-24 15:55:34 -0700287 main.cleanup()
288 main.exit()
GlennRC68449942015-10-16 16:03:12 -0700289
290 utilities.assert_equals( expect=main.TRUE,
291 actual=stepResult,
292 onpass="All flows are in the ADDED state",
GlennRC073e8bc2015-10-27 17:11:28 -0700293 onfail="All flows are NOT in the ADDED state" )
GlennRC68449942015-10-16 16:03:12 -0700294
GlennRC956ea742015-11-05 16:14:15 -0800295 main.step( "Check flows are in Mininet's flow table" )
296
297 # get the flow IDs that were added through rest
298 main.log.info( "Getting the flow IDs from ONOS" )
alisone14d7b02016-07-06 10:31:51 -0700299 flowIds = [ f.get( "id" ) for f in flows if "rest" in f.get( "appId" ) ]
GlennRC956ea742015-11-05 16:14:15 -0800300 # convert the flowIDs to ints then hex and finally back to strings
alisone14d7b02016-07-06 10:31:51 -0700301 flowIds = [ str( hex( int( x ) ) ) for x in flowIds ]
302 main.log.info( "ONOS flow IDs: {}".format( flowIds ) )
GlennRC956ea742015-11-05 16:14:15 -0800303
304 stepResult = main.Mininet1.checkFlowId( "s1", flowIds, debug=False )
305
306 utilities.assert_equals( expect=main.TRUE,
307 actual=stepResult,
308 onpass="All flows are in mininet",
309 onfail="All flows are NOT in mininet" )
310
GlennRC073e8bc2015-10-27 17:11:28 -0700311 main.step( "Send a packet to verify the flows are correct" )
312
313 # Specify the src and dst MAC addr
314 main.log.info( "Constructing packet" )
315 main.h1.buildEther( src=main.h1.hostMac, dst=main.h2.hostMac )
316
317 # Filter for packets with the correct host name. Otherwise,
318 # the filter we catch any packet that is sent to host2
319 # NOTE: I believe it doesn't matter which host name it is,
GlennRC956ea742015-11-05 16:14:15 -0800320 # as long as the src and dst are both specified
GlennRC073e8bc2015-10-27 17:11:28 -0700321 main.log.info( "Starting filter on host2" )
alisone14d7b02016-07-06 10:31:51 -0700322 main.h2.startFilter( pktFilter="ether host %s" % main.h1.hostMac )
GlennRC073e8bc2015-10-27 17:11:28 -0700323
324 main.log.info( "Sending packet to host2" )
325 main.h1.sendPacket()
326
327 main.log.info( "Checking filter for our packet" )
Jon Hallfc951072017-05-24 15:55:34 -0700328 stepResult = main.h2.checkFilter()
GlennRC073e8bc2015-10-27 17:11:28 -0700329 if stepResult:
Jon Hallfc951072017-05-24 15:55:34 -0700330 main.log.info( "Packet: %s" % main.h2.readPackets() )
alisone14d7b02016-07-06 10:31:51 -0700331 else:
Jon Hallfc951072017-05-24 15:55:34 -0700332 main.h2.killFilter()
GlennRC073e8bc2015-10-27 17:11:28 -0700333
334 main.log.info( "Clean up host components" )
335 for host in hosts:
Jon Hallfc951072017-05-24 15:55:34 -0700336 host.stopScapy()
alisone14d7b02016-07-06 10:31:51 -0700337 main.Mininet1.removeHostComponent( "h1" )
338 main.Mininet1.removeHostComponent( "h2" )
GlennRC073e8bc2015-10-27 17:11:28 -0700339
340 utilities.assert_equals( expect=main.TRUE,
341 actual=stepResult,
342 onpass="Successfully sent a packet",
343 onfail="Failed to send a packet" )
344
alisone14d7b02016-07-06 10:31:51 -0700345 def CASE1400( self, main ):
Jon Hallfc951072017-05-24 15:55:34 -0700346 """
GlennRC073e8bc2015-10-27 17:11:28 -0700347 Add flows with IPv4 selectors and verify the flows
Jon Hallfc951072017-05-24 15:55:34 -0700348 """
GlennRC68449942015-10-16 16:03:12 -0700349 import json
GlennRC073e8bc2015-10-27 17:11:28 -0700350 import time
GlennRC68449942015-10-16 16:03:12 -0700351
GlennRC073e8bc2015-10-27 17:11:28 -0700352 main.case( "Verify flow IP selectors are correctly compiled" )
353 main.caseExplanation = "Install two flows with only IP selectors " +\
alisone14d7b02016-07-06 10:31:51 -0700354 "specified, then verify flows are added in ONOS, finally " +\
GlennRC073e8bc2015-10-27 17:11:28 -0700355 "send a packet that only specifies the IP src and dst."
356
357 main.step( "Add flows with IPv4 addresses as the only selectors" )
358
359 main.log.info( "Creating host components" )
Jon Halla510a8a2016-05-04 15:09:28 -0700360 main.Scapy.createHostComponent( "h1" )
361 main.Scapy.createHostComponent( "h2" )
alisone14d7b02016-07-06 10:31:51 -0700362 hosts = [ main.h1, main.h2 ]
GlennRC073e8bc2015-10-27 17:11:28 -0700363 for host in hosts:
Jon Hallfc951072017-05-24 15:55:34 -0700364 host.startHostCli()
365 host.startScapy()
366 host.updateSelf()
GlennRC073e8bc2015-10-27 17:11:28 -0700367
368 # Add a flow that connects host1 on port1 to host2 on port2
369 # send output on port2
370 # recieve input on port1
371 egress = 2
372 ingress = 1
373 # IPv4 etherType = 0x800
alisone14d7b02016-07-06 10:31:51 -0700374 ethType = main.params[ 'TEST' ][ 'ip4Type' ]
GlennRC073e8bc2015-10-27 17:11:28 -0700375
376 # Add flows that connects host1 to host2
377 main.log.info( "Add flow with port ingress 1 to port egress 2" )
378 stepResult = main.ONOSrest.addFlow( deviceId=main.swDPID,
379 egressPort=egress,
380 ingressPort=ingress,
alisone14d7b02016-07-06 10:31:51 -0700381 ethType=ethType,
Jon Hallfc951072017-05-24 15:55:34 -0700382 ipSrc=( "IPV4_SRC", main.h1.hostIp + "/32" ),
383 ipDst=( "IPV4_DST", main.h2.hostIp + "/32" ),
GlennRC956ea742015-11-05 16:14:15 -0800384 debug=main.debug )
GlennRC073e8bc2015-10-27 17:11:28 -0700385
386 utilities.assert_equals( expect=main.TRUE,
387 actual=stepResult,
388 onpass="Successfully added flows",
389 onfail="Failed add flows" )
390
391 # Giving ONOS time to add the flow
392 time.sleep( main.addFlowSleep )
393
Devin Lim58046fa2017-07-05 16:55:00 -0700394 main.checkingFlow.checkFlow()
GlennRC956ea742015-11-05 16:14:15 -0800395
GlennRC073e8bc2015-10-27 17:11:28 -0700396 main.step( "Send a packet to verify the flow is correct" )
397
398 main.log.info( "Constructing packet" )
399 # No need for the MAC src dst
400 main.h1.buildEther( dst=main.h2.hostMac )
401 main.h1.buildIP( src=main.h1.hostIp, dst=main.h2.hostIp )
402
403 main.log.info( "Starting filter on host2" )
404 # Defaults to ip
Jon Hallfc951072017-05-24 15:55:34 -0700405 main.h2.startFilter()
GlennRC073e8bc2015-10-27 17:11:28 -0700406
407 main.log.info( "Sending packet to host2" )
Jon Hallfc951072017-05-24 15:55:34 -0700408 main.h1.sendPacket()
GlennRC073e8bc2015-10-27 17:11:28 -0700409
410 main.log.info( "Checking filter for our packet" )
Jon Hallfc951072017-05-24 15:55:34 -0700411 stepResult = main.h2.checkFilter()
GlennRC073e8bc2015-10-27 17:11:28 -0700412 if stepResult:
Jon Hallfc951072017-05-24 15:55:34 -0700413 main.log.info( "Packet: %s" % main.h2.readPackets() )
414 else:
415 main.h2.killFilter()
GlennRC073e8bc2015-10-27 17:11:28 -0700416
417 main.log.info( "Clean up host components" )
418 for host in hosts:
Jon Hallfc951072017-05-24 15:55:34 -0700419 host.stopScapy()
alisone14d7b02016-07-06 10:31:51 -0700420 main.Mininet1.removeHostComponent( "h1" )
421 main.Mininet1.removeHostComponent( "h2" )
GlennRC073e8bc2015-10-27 17:11:28 -0700422
423 utilities.assert_equals( expect=main.TRUE,
424 actual=stepResult,
425 onpass="Successfully sent a packet",
426 onfail="Failed to send a packet" )
427
Jon Hallfc951072017-05-24 15:55:34 -0700428 def CASE1500( self, main ):
alisone14d7b02016-07-06 10:31:51 -0700429 """
430 Add flow with IPv6 selector and verify the flow
431 """
432 import json
433 import time
434 main.case( "Verify IPv6 selector is correctly compiled" )
435 main.caseExplanation = "Install two flows with only IP selectors " + \
436 "specified, then verify flows are added in ONOS, finally " + \
437 "send a packet that only specifies the IP src and dst."
438
439 main.step( "Add flows with IPv6 addresses as the only selectors" )
440
441 main.log.info( "Creating host components" )
442 main.Scapy.createHostComponent( "h5" )
443 main.Scapy.createHostComponent( "h6" )
444 hosts = [ main.h5, main.h6 ]
445
446 for host in hosts:
Jon Hallfc951072017-05-24 15:55:34 -0700447 host.startHostCli()
448 host.startScapy()
alisone14d7b02016-07-06 10:31:51 -0700449 host.updateSelf( IPv6=True )
450
451 # Add a flow that connects host1 on port1 to host2 on port2
452 # send output on port2
453 # recieve input on port1
454 egress = 6
455 ingress = 5
456 # IPv6 etherType = 0x86DD
457 ethType = main.params[ 'TEST' ][ 'ip6Type' ]
458
459 # Add flows that connects host1 to host2
460 main.log.info( "Add flow with port ingress 5 to port egress 6" )
461 stepResult = main.ONOSrest.addFlow( deviceId=main.swDPID,
462 egressPort=egress,
463 ingressPort=ingress,
464 ethType=ethType,
465 ipSrc=( "IPV6_SRC", main.h5.hostIp + "/128" ),
466 ipDst=( "IPV6_DST", main.h6.hostIp + "/128" ),
467 debug=main.debug )
468
469 utilities.assert_equals( expect=main.TRUE,
470 actual=stepResult,
471 onpass="Successfully added flows",
472 onfail="Failed add flows" )
473
474 # Giving ONOS time to add the flow
475 time.sleep( main.addFlowSleep )
476
Devin Lim58046fa2017-07-05 16:55:00 -0700477 main.checkingFlow.checkFlow()
alisone14d7b02016-07-06 10:31:51 -0700478
479 main.step( "Send a packet to verify the flow is correct" )
480
481 main.log.info( "Constructing packet" )
482 # No need for the MAC src dst
483 main.h5.buildEther( dst=main.h6.hostMac )
484 main.h5.buildIPv6( src=main.h5.hostIp, dst=main.h6.hostIp )
485
486 main.log.info( "Starting filter on host6" )
487 # Defaults to ip
488 main.h6.startFilter( pktFilter="ip6" )
489 main.log.info( "Sending packet to host6" )
Jon Hallfc951072017-05-24 15:55:34 -0700490 main.h5.sendPacket()
alisone14d7b02016-07-06 10:31:51 -0700491
492 main.log.info( "Checking filter for our packet" )
Jon Hallfc951072017-05-24 15:55:34 -0700493 stepResult = main.h6.checkFilter()
alisone14d7b02016-07-06 10:31:51 -0700494 if stepResult:
Jon Hallfc951072017-05-24 15:55:34 -0700495 main.log.info( "Packet: %s" % main.h6.readPackets() )
alisone14d7b02016-07-06 10:31:51 -0700496 else:
Jon Hallfc951072017-05-24 15:55:34 -0700497 main.h6.killFilter()
alisone14d7b02016-07-06 10:31:51 -0700498
499 main.log.info( "Clean up host components" )
500 for host in hosts:
Jon Hallfc951072017-05-24 15:55:34 -0700501 host.stopScapy()
alisone14d7b02016-07-06 10:31:51 -0700502 main.Mininet1.removeHostComponent( "h5" )
503 main.Mininet1.removeHostComponent( "h6" )
504
505 utilities.assert_equals( expect=main.TRUE,
506 actual=stepResult,
507 onpass="Successfully sent a packet",
508 onfail="Failed to send a packet" )
509
alisone14d7b02016-07-06 10:31:51 -0700510 def CASE1100( self, main ):
Jon Hallfc951072017-05-24 15:55:34 -0700511 """
GlennRC073e8bc2015-10-27 17:11:28 -0700512 Add flow with VLAN selector and verify the flow
Jon Hallfc951072017-05-24 15:55:34 -0700513 """
GlennRC073e8bc2015-10-27 17:11:28 -0700514 import json
515 import time
516
517 main.case( "Verify VLAN selector is correctly compiled" )
518 main.caseExplanation = "Install one flow with only the VLAN selector " +\
Jon Hallfc951072017-05-24 15:55:34 -0700519 "specified, then verify the flow is added in ONOS, and finally " +\
GlennRC073e8bc2015-10-27 17:11:28 -0700520 "broadcast a packet with the correct VLAN tag."
521
522 # We do this here to utilize the hosts information
523 main.log.info( "Creating host components" )
Jon Halla510a8a2016-05-04 15:09:28 -0700524 main.Scapy.createHostComponent( "h3" )
525 main.Scapy.createHostComponent( "h4" )
alisone14d7b02016-07-06 10:31:51 -0700526 hosts = [ main.h3, main.h4 ]
GlennRC073e8bc2015-10-27 17:11:28 -0700527 for host in hosts:
Jon Hallfc951072017-05-24 15:55:34 -0700528 host.startHostCli()
529 host.startScapy()
530 host.updateSelf()
GlennRC073e8bc2015-10-27 17:11:28 -0700531
532 main.step( "Add a flow with the VLAN tag as the only selector" )
533
534 # Add flows that connects the two vlan hosts h3 and h4
535 # Host 3 is on port 3 and host 4 is on port 4
536 vlan = main.params[ 'TEST' ][ 'vlan' ]
537 egress = 4
538 ingress = 3
539 # VLAN ethType = 0x8100
alisone14d7b02016-07-06 10:31:51 -0700540 ethType = main.params[ 'TEST' ][ 'vlanType' ]
GlennRC073e8bc2015-10-27 17:11:28 -0700541
542 # Add only one flow because we don't need a response
543 main.log.info( "Add flow with port ingress 1 to port egress 2" )
544 stepResult = main.ONOSrest.addFlow( deviceId=main.swDPID,
545 egressPort=egress,
546 ingressPort=ingress,
547 ethType=ethType,
548 vlan=vlan,
GlennRC956ea742015-11-05 16:14:15 -0800549 debug=main.debug )
GlennRC073e8bc2015-10-27 17:11:28 -0700550
GlennRC073e8bc2015-10-27 17:11:28 -0700551 utilities.assert_equals( expect=main.TRUE,
552 actual=stepResult,
553 onpass="Successfully added flow",
554 onfail="Failed add flows" )
555
556 # Giving ONOS time to add the flows
557 time.sleep( main.addFlowSleep )
558
559 main.step( "Check flows are in the ADDED state" )
560
561 main.log.info( "Get the flows from ONOS" )
Jeremy86160992016-04-11 10:05:53 -0700562 try:
Jon Hallfc951072017-05-24 15:55:34 -0700563 flows = json.loads( main.ONOSrest.flows() )
GlennRC073e8bc2015-10-27 17:11:28 -0700564
Jeremy86160992016-04-11 10:05:53 -0700565 stepResult = main.TRUE
566 for f in flows:
alisone14d7b02016-07-06 10:31:51 -0700567 if "rest" in f.get( "appId" ):
568 if "ADDED" not in f.get( "state" ):
Jeremy86160992016-04-11 10:05:53 -0700569 stepResult = main.FALSE
alisone14d7b02016-07-06 10:31:51 -0700570 main.log.error( "Flow: %s in state: %s" % ( f.get( "id" ), f.get( "state" ) ) )
Jeremy86160992016-04-11 10:05:53 -0700571 except TypeError:
572 main.log.error( "No Flows found by the REST API" )
573 stepResult = main.FALSE
574 except ValueError:
575 main.log.error( "Problem getting Flows state from REST API. Exiting test" )
Jon Hallfc951072017-05-24 15:55:34 -0700576 main.cleanup()
577 main.exit()
GlennRC073e8bc2015-10-27 17:11:28 -0700578
579 utilities.assert_equals( expect=main.TRUE,
580 actual=stepResult,
581 onpass="All flows are in the ADDED state",
582 onfail="All flows are NOT in the ADDED state" )
583
GlennRC956ea742015-11-05 16:14:15 -0800584 main.step( "Check flows are in Mininet's flow table" )
585
586 # get the flow IDs that were added through rest
587 main.log.info( "Getting the flow IDs from ONOS" )
alisone14d7b02016-07-06 10:31:51 -0700588 flowIds = [ f.get( "id" ) for f in flows if "rest" in f.get( "appId" ) ]
GlennRC956ea742015-11-05 16:14:15 -0800589 # convert the flowIDs to ints then hex and finally back to strings
alisone14d7b02016-07-06 10:31:51 -0700590 flowIds = [ str( hex( int( x ) ) ) for x in flowIds ]
591 main.log.info( "ONOS flow IDs: {}".format( flowIds ) )
GlennRC956ea742015-11-05 16:14:15 -0800592
593 stepResult = main.Mininet1.checkFlowId( "s1", flowIds, debug=False )
594
595 utilities.assert_equals( expect=main.TRUE,
596 actual=stepResult,
597 onpass="All flows are in mininet",
598 onfail="All flows are NOT in mininet" )
599
GlennRC073e8bc2015-10-27 17:11:28 -0700600 main.step( "Send a packet to verify the flow are correct" )
601
602 # The receiving interface
alisone14d7b02016-07-06 10:31:51 -0700603 recIface = "{}-eth0.{}".format( main.h4.name, vlan )
GlennRC073e8bc2015-10-27 17:11:28 -0700604 main.log.info( "Starting filter on host2" )
605 # Filter is setup to catch any packet on the vlan interface with the correct vlan tag
Jon Hallfc951072017-05-24 15:55:34 -0700606 main.h4.startFilter( ifaceName=recIface, pktFilter="" )
GlennRC073e8bc2015-10-27 17:11:28 -0700607
608 # Broadcast the packet on the vlan interface. We only care if the flow forwards
609 # the packet with the correct vlan tag, not if the mac addr is correct
alisone14d7b02016-07-06 10:31:51 -0700610 sendIface = "{}-eth0.{}".format( main.h3.name, vlan )
GlennRC073e8bc2015-10-27 17:11:28 -0700611 main.log.info( "Broadcasting the packet with a vlan tag" )
GlennRC956ea742015-11-05 16:14:15 -0800612 main.h3.sendPacket( iface=sendIface,
alisone14d7b02016-07-06 10:31:51 -0700613 packet="Ether()/Dot1Q(vlan={})".format( vlan ) )
GlennRC073e8bc2015-10-27 17:11:28 -0700614
615 main.log.info( "Checking filter for our packet" )
Jon Hallfc951072017-05-24 15:55:34 -0700616 stepResult = main.h4.checkFilter()
GlennRC073e8bc2015-10-27 17:11:28 -0700617 if stepResult:
Jon Hallfc951072017-05-24 15:55:34 -0700618 main.log.info( "Packet: %s" % main.h4.readPackets() )
619 else:
620 main.h4.killFilter()
GlennRC073e8bc2015-10-27 17:11:28 -0700621
622 main.log.info( "Clean up host components" )
623 for host in hosts:
Jon Hallfc951072017-05-24 15:55:34 -0700624 host.stopScapy()
alisone14d7b02016-07-06 10:31:51 -0700625 main.Mininet1.removeHostComponent( "h3" )
626 main.Mininet1.removeHostComponent( "h4" )
GlennRC073e8bc2015-10-27 17:11:28 -0700627
628 utilities.assert_equals( expect=main.TRUE,
629 actual=stepResult,
630 onpass="Successfully sent a packet",
631 onfail="Failed to send a packet" )
GlennRC68449942015-10-16 16:03:12 -0700632
GlennRC956ea742015-11-05 16:14:15 -0800633 def CASE1300( self, main ):
Jon Hallfc951072017-05-24 15:55:34 -0700634 """
GlennRC956ea742015-11-05 16:14:15 -0800635 Add flows with MPLS selector and verify the flows
Jon Hallfc951072017-05-24 15:55:34 -0700636 """
GlennRC956ea742015-11-05 16:14:15 -0800637 import json
638 import time
639
640 main.case( "Verify the MPLS selector is correctly compiled on the flow." )
641 main.caseExplanation = "Install one flow with an MPLS selector, " +\
alisone14d7b02016-07-06 10:31:51 -0700642 "verify the flow is added in ONOS, and finally " +\
GlennRC956ea742015-11-05 16:14:15 -0800643 "send a packet via scapy that has a MPLS label."
644
645 main.step( "Add a flow with a MPLS selector" )
646
647 main.log.info( "Creating host components" )
Jon Halla510a8a2016-05-04 15:09:28 -0700648 main.Scapy.createHostComponent( "h1" )
649 main.Scapy.createHostComponent( "h2" )
alisone14d7b02016-07-06 10:31:51 -0700650 hosts = [ main.h1, main.h2 ]
GlennRC956ea742015-11-05 16:14:15 -0800651 for host in hosts:
Jon Hallfc951072017-05-24 15:55:34 -0700652 host.startHostCli()
GlennRC956ea742015-11-05 16:14:15 -0800653 host.startScapy( main.dependencyPath )
Jon Hallfc951072017-05-24 15:55:34 -0700654 host.updateSelf()
GlennRC956ea742015-11-05 16:14:15 -0800655
656 # ports
657 egress = 2
658 ingress = 1
659 # MPLS etherType
660 ethType = main.params[ 'TEST' ][ 'mplsType' ]
661 # MPLS label
662 mplsLabel = main.params[ 'TEST' ][ 'mpls' ]
663
664 # Add a flow that connects host1 on port1 to host2 on port2
665 main.log.info( "Adding flow with MPLS selector" )
666 stepResult = main.ONOSrest.addFlow( deviceId=main.swDPID,
667 egressPort=egress,
668 ingressPort=ingress,
669 ethType=ethType,
670 mpls=mplsLabel,
671 debug=main.debug )
672
673 utilities.assert_equals( expect=main.TRUE,
674 actual=stepResult,
675 onpass="Successfully added flow",
676 onfail="Failed add flow" )
677
678 # Giving ONOS time to add the flow
679 time.sleep( main.addFlowSleep )
680
681 main.step( "Check flow is in the ADDED state" )
682
683 main.log.info( "Get the flows from ONOS" )
Jeremy86160992016-04-11 10:05:53 -0700684 try:
Jon Hallfc951072017-05-24 15:55:34 -0700685 flows = json.loads( main.ONOSrest.flows() )
GlennRC956ea742015-11-05 16:14:15 -0800686
Jeremy86160992016-04-11 10:05:53 -0700687 stepResult = main.TRUE
688 for f in flows:
alisone14d7b02016-07-06 10:31:51 -0700689 if "rest" in f.get( "appId" ):
690 if "ADDED" not in f.get( "state" ):
Jeremy86160992016-04-11 10:05:53 -0700691 stepResult = main.FALSE
alisone14d7b02016-07-06 10:31:51 -0700692 main.log.error( "Flow: %s in state: %s" % ( f.get( "id" ), f.get( "state" ) ) )
Jeremy86160992016-04-11 10:05:53 -0700693 except TypeError:
694 main.log.error( "No Flows found by the REST API" )
695 stepResult = main.FALSE
696 except ValueError:
697 main.log.error( "Problem getting Flows state from REST API. Exiting test" )
Jon Hallfc951072017-05-24 15:55:34 -0700698 main.cleanup()
699 main.exit()
GlennRC956ea742015-11-05 16:14:15 -0800700
701 utilities.assert_equals( expect=main.TRUE,
702 actual=stepResult,
703 onpass="All flows are in the ADDED state",
704 onfail="All flows are NOT in the ADDED state" )
705
706 main.step( "Check flows are in Mininet's flow table" )
707
708 # get the flow IDs that were added through rest
709 main.log.info( "Getting the flow IDs from ONOS" )
alisone14d7b02016-07-06 10:31:51 -0700710 flowIds = [ f.get( "id" ) for f in flows if "rest" in f.get( "appId" ) ]
GlennRC956ea742015-11-05 16:14:15 -0800711 # convert the flowIDs to ints then hex and finally back to strings
alisone14d7b02016-07-06 10:31:51 -0700712 flowIds = [ str( hex( int( x ) ) ) for x in flowIds ]
713 main.log.info( "ONOS flow IDs: {}".format( flowIds ) )
GlennRC956ea742015-11-05 16:14:15 -0800714
715 stepResult = main.Mininet1.checkFlowId( "s1", flowIds, debug=True )
716
717 utilities.assert_equals( expect=main.TRUE,
718 actual=stepResult,
719 onpass="All flows are in mininet",
720 onfail="All flows are NOT in mininet" )
721
722 main.step( "Send a packet to verify the flow is correct" )
723
724 main.log.info( "Starting filter on host2" )
725 main.h2.startFilter( pktFilter="mpls" )
726
727 main.log.info( "Constructing packet" )
728 main.log.info( "Sending packet to host2" )
alisone14d7b02016-07-06 10:31:51 -0700729 main.h1.sendPacket( packet='Ether()/MPLS(label={})'.format( mplsLabel ) )
GlennRC956ea742015-11-05 16:14:15 -0800730
731 main.log.info( "Checking filter for our packet" )
Jon Hallfc951072017-05-24 15:55:34 -0700732 stepResult = main.h2.checkFilter()
GlennRC956ea742015-11-05 16:14:15 -0800733 if stepResult:
Jon Hallfc951072017-05-24 15:55:34 -0700734 main.log.info( "Packet: %s" % main.h2.readPackets() )
735 else:
736 main.h2.killFilter()
GlennRC956ea742015-11-05 16:14:15 -0800737
738 main.log.info( "Clean up host components" )
739 for host in hosts:
Jon Hallfc951072017-05-24 15:55:34 -0700740 host.stopScapy()
alisone14d7b02016-07-06 10:31:51 -0700741 main.Mininet1.removeHostComponent( "h1" )
742 main.Mininet1.removeHostComponent( "h2" )
GlennRC956ea742015-11-05 16:14:15 -0800743
744 utilities.assert_equals( expect=main.TRUE,
745 actual=stepResult,
746 onpass="Successfully sent a packet",
747 onfail="Failed to send a packet" )
748
alisone14d7b02016-07-06 10:31:51 -0700749 def CASE1700( self, main ):
Jon Hallfc951072017-05-24 15:55:34 -0700750 """
GlennRC956ea742015-11-05 16:14:15 -0800751 Add flows with a TCP selector and verify the flow
Jon Hallfc951072017-05-24 15:55:34 -0700752 """
GlennRC956ea742015-11-05 16:14:15 -0800753 import json
754 import time
755
756 main.case( "Verify the TCP selector is correctly compiled on the flow" )
757 main.caseExplanation = "Install a flow with only the TCP selector " +\
alisone14d7b02016-07-06 10:31:51 -0700758 "specified, verify the flow is added in ONOS, and finally " +\
GlennRC956ea742015-11-05 16:14:15 -0800759 "send a TCP packet to verify the TCP selector is compiled correctly."
760
761 main.step( "Add a flow with a TCP selector" )
762
763 main.log.info( "Creating host components" )
Jon Halla510a8a2016-05-04 15:09:28 -0700764 main.Scapy.createHostComponent( "h1" )
765 main.Scapy.createHostComponent( "h2" )
alisone14d7b02016-07-06 10:31:51 -0700766 hosts = [ main.h1, main.h2 ]
GlennRC956ea742015-11-05 16:14:15 -0800767 for host in hosts:
Jon Hallfc951072017-05-24 15:55:34 -0700768 host.startHostCli()
769 host.startScapy()
770 host.updateSelf()
GlennRC956ea742015-11-05 16:14:15 -0800771
772 # Add a flow that connects host1 on port1 to host2 on port2
773 egress = 2
774 ingress = 1
775 # IPv4 etherType
776 ethType = main.params[ 'TEST' ][ 'ip4Type' ]
777 # IP protocol
778 ipProto = main.params[ 'TEST' ][ 'tcpProto' ]
779 # TCP port destination
780 tcpDst = main.params[ 'TEST' ][ 'tcpDst' ]
781
782 main.log.info( "Add a flow that connects host1 on port1 to host2 on port2" )
783 stepResult = main.ONOSrest.addFlow( deviceId=main.swDPID,
784 egressPort=egress,
785 ingressPort=ingress,
786 ethType=ethType,
787 ipProto=ipProto,
788 tcpDst=tcpDst,
789 debug=main.debug )
790
791 utilities.assert_equals( expect=main.TRUE,
792 actual=stepResult,
793 onpass="Successfully added flows",
794 onfail="Failed add flows" )
795
796 # Giving ONOS time to add the flow
797 time.sleep( main.addFlowSleep )
798
Devin Lim58046fa2017-07-05 16:55:00 -0700799 main.checkingFlow.checkFlow()
GlennRC956ea742015-11-05 16:14:15 -0800800
801 main.step( "Send a packet to verify the flow is correct" )
802
803 main.log.info( "Constructing packet" )
804 # No need for the MAC src dst
805 main.h1.buildEther( dst=main.h2.hostMac )
806 main.h1.buildIP( dst=main.h2.hostIp )
807 main.h1.buildTCP( dport=tcpDst )
808
809 main.log.info( "Starting filter on host2" )
810 # Defaults to ip
811 main.h2.startFilter( pktFilter="tcp" )
812
813 main.log.info( "Sending packet to host2" )
Jon Hallfc951072017-05-24 15:55:34 -0700814 main.h1.sendPacket()
GlennRC956ea742015-11-05 16:14:15 -0800815
816 main.log.info( "Checking filter for our packet" )
Jon Hallfc951072017-05-24 15:55:34 -0700817 stepResult = main.h2.checkFilter()
GlennRC956ea742015-11-05 16:14:15 -0800818 if stepResult:
Jon Hallfc951072017-05-24 15:55:34 -0700819 main.log.info( "Packet: %s" % main.h2.readPackets() )
820 else:
821 main.h2.killFilter()
GlennRC956ea742015-11-05 16:14:15 -0800822
823 main.log.info( "Clean up host components" )
824 for host in hosts:
Jon Hallfc951072017-05-24 15:55:34 -0700825 host.stopScapy()
alisone14d7b02016-07-06 10:31:51 -0700826 main.Mininet1.removeHostComponent( "h1" )
827 main.Mininet1.removeHostComponent( "h2" )
GlennRC956ea742015-11-05 16:14:15 -0800828
829 utilities.assert_equals( expect=main.TRUE,
830 actual=stepResult,
831 onpass="Successfully sent a packet",
832 onfail="Failed to send a packet" )
833
alisone14d7b02016-07-06 10:31:51 -0700834 def CASE1600( self, main ):
Jon Hallfc951072017-05-24 15:55:34 -0700835 """
GlennRC956ea742015-11-05 16:14:15 -0800836 Add flows with a UDP selector and verify the flow
Jon Hallfc951072017-05-24 15:55:34 -0700837 """
GlennRC956ea742015-11-05 16:14:15 -0800838 import json
839 import time
840
841 main.case( "Verify the UDP selector is correctly compiled on the flow" )
842 main.caseExplanation = "Install a flow with only the UDP selector " +\
alisone14d7b02016-07-06 10:31:51 -0700843 "specified, verify the flow is added in ONOS, and finally " +\
GlennRC956ea742015-11-05 16:14:15 -0800844 "send a UDP packet to verify the UDP selector is compiled correctly."
845
846 main.step( "Add a flow with a UDP selector" )
847
848 main.log.info( "Creating host components" )
Jon Halla510a8a2016-05-04 15:09:28 -0700849 main.Scapy.createHostComponent( "h1" )
850 main.Scapy.createHostComponent( "h2" )
alisone14d7b02016-07-06 10:31:51 -0700851 hosts = [ main.h1, main.h2 ]
GlennRC956ea742015-11-05 16:14:15 -0800852 for host in hosts:
Jon Hallfc951072017-05-24 15:55:34 -0700853 host.startHostCli()
854 host.startScapy()
855 host.updateSelf()
GlennRC956ea742015-11-05 16:14:15 -0800856
857 # Add a flow that connects host1 on port1 to host2 on port2
858 egress = 2
859 ingress = 1
860 # IPv4 etherType
861 ethType = main.params[ 'TEST' ][ 'ip4Type' ]
862 # IP protocol
863 ipProto = main.params[ 'TEST' ][ 'udpProto' ]
864 # UDP port destination
865 udpDst = main.params[ 'TEST' ][ 'udpDst' ]
866
867 main.log.info( "Add a flow that connects host1 on port1 to host2 on port2" )
868 stepResult = main.ONOSrest.addFlow( deviceId=main.swDPID,
869 egressPort=egress,
870 ingressPort=ingress,
871 ethType=ethType,
872 ipProto=ipProto,
873 udpDst=udpDst,
874 debug=main.debug )
875
876 utilities.assert_equals( expect=main.TRUE,
877 actual=stepResult,
878 onpass="Successfully added flows",
879 onfail="Failed add flows" )
880
881 # Giving ONOS time to add the flow
882 time.sleep( main.addFlowSleep )
883
Devin Lim58046fa2017-07-05 16:55:00 -0700884 main.checkingFlow.checkFlow()
GlennRC956ea742015-11-05 16:14:15 -0800885
886 main.step( "Send a packet to verify the flow is correct" )
887
888 main.log.info( "Constructing packet" )
889 # No need for the MAC src dst
890 main.h1.buildEther( dst=main.h2.hostMac )
891 main.h1.buildIP( dst=main.h2.hostIp )
892 main.h1.buildUDP( dport=udpDst )
893
894 main.log.info( "Starting filter on host2" )
895 # Defaults to ip
896 main.h2.startFilter( pktFilter="udp" )
897
898 main.log.info( "Sending packet to host2" )
Jon Hallfc951072017-05-24 15:55:34 -0700899 main.h1.sendPacket()
GlennRC956ea742015-11-05 16:14:15 -0800900
901 main.log.info( "Checking filter for our packet" )
Jon Hallfc951072017-05-24 15:55:34 -0700902 stepResult = main.h2.checkFilter()
GlennRC956ea742015-11-05 16:14:15 -0800903 if stepResult:
Jon Hallfc951072017-05-24 15:55:34 -0700904 main.log.info( "Packet: %s" % main.h2.readPackets() )
905 else:
906 main.h2.killFilter()
GlennRC956ea742015-11-05 16:14:15 -0800907
908 main.log.info( "Clean up host components" )
909 for host in hosts:
Jon Hallfc951072017-05-24 15:55:34 -0700910 host.stopScapy()
alisone14d7b02016-07-06 10:31:51 -0700911 main.Mininet1.removeHostComponent( "h1" )
912 main.Mininet1.removeHostComponent( "h2" )
GlennRC956ea742015-11-05 16:14:15 -0800913
914 utilities.assert_equals( expect=main.TRUE,
915 actual=stepResult,
916 onpass="Successfully sent a packet",
917 onfail="Failed to send a packet" )
918
alisone14d7b02016-07-06 10:31:51 -0700919 def CASE1900( self, main ):
Jon Hallfc951072017-05-24 15:55:34 -0700920 """
alisone14d7b02016-07-06 10:31:51 -0700921 Add flows with a ICMPv4 selector and verify the flow
Jon Hallfc951072017-05-24 15:55:34 -0700922 """
GlennRC956ea742015-11-05 16:14:15 -0800923 import json
alisone14d7b02016-07-06 10:31:51 -0700924 import time
GlennRC956ea742015-11-05 16:14:15 -0800925
alisone14d7b02016-07-06 10:31:51 -0700926 main.case( "Verify the ICMPv4 selector is correctly compiled on the flow" )
927 main.caseExplanation = "Install a flow with only the ICMPv4 selector " +\
928 "specified, verify the flow is added in ONOS, and finally " +\
929 "send a IMCPv4 packet to verify the ICMPv4 selector is compiled correctly."
GlennRC956ea742015-11-05 16:14:15 -0800930
alisone14d7b02016-07-06 10:31:51 -0700931 main.step( "Add a flow with a ICMPv4 selector" )
932
933 main.log.info( "Creating host components" )
934 main.Scapy.createHostComponent( "h1" )
935 main.Scapy.createHostComponent( "h2" )
936 hosts = [ main.h1, main.h2 ]
937 for host in hosts:
Jon Hallfc951072017-05-24 15:55:34 -0700938 host.startHostCli()
939 host.startScapy()
940 host.updateSelf()
alisone14d7b02016-07-06 10:31:51 -0700941
942 # Add a flow that connects host1 on port1 to host2 on port2
943 egress = 2
944 ingress = 1
945 # IPv4 etherType
946 ethType = main.params[ 'TEST' ][ 'ip4Type' ]
947 # IP protocol
948 ipProto = main.params[ 'TEST' ][ 'icmpProto' ]
949
950 main.log.info( "Add a flow that connects host1 on port1 to host2 on port2" )
951 stepResult = main.ONOSrest.addFlow( deviceId=main.swDPID,
952 egressPort=egress,
953 ingressPort=ingress,
954 ethType=ethType,
955 ipProto=ipProto,
956 debug=main.debug )
957
958 utilities.assert_equals( expect=main.TRUE,
959 actual=stepResult,
960 onpass="Successfully added flows",
961 onfail="Failed add flows" )
962
963 # Giving ONOS time to add the flow
964 time.sleep( main.addFlowSleep )
965
Devin Lim58046fa2017-07-05 16:55:00 -0700966 main.checkingFlow.checkFlow()
alisone14d7b02016-07-06 10:31:51 -0700967
968 main.step( "Send a packet to verify the flow is correct" )
969
970 main.log.info( "Constructing packet" )
971 # No need for the MAC src dst
972 main.h1.buildEther( dst=main.h2.hostMac )
973 main.h1.buildIP( dst=main.h2.hostIp )
Jon Hallfc951072017-05-24 15:55:34 -0700974 main.h1.buildICMP()
alisone14d7b02016-07-06 10:31:51 -0700975
976 main.log.info( "Starting filter on host2" )
977 # Defaults to ip
978 main.h2.startFilter( pktFilter="icmp" )
979
980 main.log.info( "Sending packet to host2" )
Jon Hallfc951072017-05-24 15:55:34 -0700981 main.h1.sendPacket()
alisone14d7b02016-07-06 10:31:51 -0700982
983 main.log.info( "Checking filter for our packet" )
Jon Hallfc951072017-05-24 15:55:34 -0700984 stepResult = main.h2.checkFilter()
alisone14d7b02016-07-06 10:31:51 -0700985 if stepResult:
Jon Hallfc951072017-05-24 15:55:34 -0700986 main.log.info( "Packet: %s" % main.h2.readPackets() )
987 else:
988 main.h2.killFilter()
alisone14d7b02016-07-06 10:31:51 -0700989
990 main.log.info( "Clean up host components" )
991 for host in hosts:
Jon Hallfc951072017-05-24 15:55:34 -0700992 host.stopScapy()
alisone14d7b02016-07-06 10:31:51 -0700993 main.Mininet1.removeHostComponent( "h1" )
994 main.Mininet1.removeHostComponent( "h2" )
995
996 utilities.assert_equals( expect=main.TRUE,
997 actual=stepResult,
998 onpass="Successfully sent a packet",
999 onfail="Failed to send a packet" )
1000
1001 def CASE2000( self, main ):
Jon Hallfc951072017-05-24 15:55:34 -07001002 """
alisone14d7b02016-07-06 10:31:51 -07001003 Add flows with a ICMPv6 selector and verify the flow
Jon Hallfc951072017-05-24 15:55:34 -07001004 """
alisone14d7b02016-07-06 10:31:51 -07001005 import json
1006 import time
1007
1008 main.case( "Verify the ICMPv6 selector is correctly compiled on the flow" )
1009 main.caseExplanation = "Install a flow with only the ICMPv6 selector " +\
1010 "specified, verify the flow is added in ONOS, and finally " +\
1011 "send a IMCPv6 packet to verify the ICMPv6 selector is compiled correctly."
1012
1013 main.step( "Add a flow with a ICMPv6 selector" )
1014
1015 main.log.info( "Creating host components" )
1016 main.Scapy.createHostComponent( "h5" )
1017 main.Scapy.createHostComponent( "h6" )
Jon Hallfc951072017-05-24 15:55:34 -07001018 hosts = [ main.h5, main.h6 ]
alisone14d7b02016-07-06 10:31:51 -07001019 for host in hosts:
Jon Hallfc951072017-05-24 15:55:34 -07001020 host.startHostCli()
1021 host.startScapy()
alisone14d7b02016-07-06 10:31:51 -07001022 host.updateSelf( IPv6=True )
1023
1024 # Add a flow that connects host1 on port1 to host2 on port2
Jon Hallfc951072017-05-24 15:55:34 -07001025 egress = 6
1026 ingress = 5
alisone14d7b02016-07-06 10:31:51 -07001027 # IPv6 etherType
1028 ethType = main.params[ 'TEST' ][ 'ip6Type' ]
1029 # IP protocol
1030 ipProto = main.params[ 'TEST' ][ 'icmp6Proto' ]
1031
1032 main.log.info( "Add a flow that connects host1 on port1 to host2 on port2" )
1033 stepResult = main.ONOSrest.addFlow( deviceId=main.swDPID,
1034 egressPort=egress,
1035 ingressPort=ingress,
1036 ethType=ethType,
1037 ipProto=ipProto,
1038 debug=main.debug )
1039
1040 utilities.assert_equals( expect=main.TRUE,
1041 actual=stepResult,
1042 onpass="Successfully added flows",
1043 onfail="Failed add flows" )
1044
1045 # Giving ONOS time to add the flow
1046 time.sleep( main.addFlowSleep )
1047
Devin Lim58046fa2017-07-05 16:55:00 -07001048 main.checkingFlow.checkFlow()
alisone14d7b02016-07-06 10:31:51 -07001049
1050 main.step( "Send a packet to verify the flow is correct" )
1051
1052 main.log.info( "Constructing packet" )
1053 # No need for the MAC src dst
1054 main.h5.buildEther( dst=main.h6.hostMac )
1055 main.h5.buildIPv6( dst=main.h6.hostIp )
1056 main.h5.buildICMP( ipVersion=6 )
1057
1058 main.log.info( "Starting filter on host2" )
1059 # Defaults to ip
1060 main.h6.startFilter( pktFilter="icmp6" )
1061
1062 main.log.info( "Sending packet to host2" )
Jon Hallfc951072017-05-24 15:55:34 -07001063 main.h5.sendPacket()
alisone14d7b02016-07-06 10:31:51 -07001064
1065 main.log.info( "Checking filter for our packet" )
Jon Hallfc951072017-05-24 15:55:34 -07001066 stepResult = main.h6.checkFilter()
alisone14d7b02016-07-06 10:31:51 -07001067 if stepResult:
Jon Hallfc951072017-05-24 15:55:34 -07001068 main.log.info( "Packet: %s" % main.h6.readPackets() )
1069 else:
1070 main.h6.killFilter()
alisone14d7b02016-07-06 10:31:51 -07001071
1072 main.log.info( "Clean up host components" )
1073 for host in hosts:
Jon Hallfc951072017-05-24 15:55:34 -07001074 host.stopScapy()
alisone14d7b02016-07-06 10:31:51 -07001075 main.Mininet1.removeHostComponent( "h5" )
1076 main.Mininet1.removeHostComponent( "h6" )
1077
1078 utilities.assert_equals( expect=main.TRUE,
1079 actual=stepResult,
1080 onpass="Successfully sent a packet",
1081 onfail="Failed to send a packet" )
1082
1083 def CASE3000( self, main ):
Jon Hallfc951072017-05-24 15:55:34 -07001084 """
alisone14d7b02016-07-06 10:31:51 -07001085 Delete flow
Jon Hallfc951072017-05-24 15:55:34 -07001086 """
alisone14d7b02016-07-06 10:31:51 -07001087 import json
1088
1089 main.case( "Delete flows that were added through rest" )
1090 main.step( "Deleting flows" )
1091
1092 main.log.info( "Getting flows" )
1093 try:
Jon Hallfc951072017-05-24 15:55:34 -07001094 flows = json.loads( main.ONOSrest.flows() )
alisone14d7b02016-07-06 10:31:51 -07001095
1096 stepResult = main.TRUE
1097 for f in flows:
1098 if "rest" in f.get( "appId" ):
Jon Hallfc951072017-05-24 15:55:34 -07001099 if main.debug:
1100 main.log.debug( "Flow to be deleted:\n{}".format( main.ONOSrest.pprint( f ) ) )
alisone14d7b02016-07-06 10:31:51 -07001101 stepResult = stepResult and main.ONOSrest.removeFlow( f.get( "deviceId" ), f.get( "id" ) )
1102 except TypeError:
1103 main.log.error( "No Flows found by the REST API" )
1104 stepResult = main.FALSE
1105 except ValueError:
1106 main.log.error( "Problem getting Flows state from REST API. Exiting test" )
Jon Hallfc951072017-05-24 15:55:34 -07001107 main.cleanup()
1108 main.exit()
GlennRC956ea742015-11-05 16:14:15 -08001109
1110 utilities.assert_equals( expect=main.TRUE,
1111 actual=stepResult,
1112 onpass="Successfully deleting flows",
1113 onfail="Failed to delete flows" )
1114
1115 time.sleep( main.delFlowSleep )
1116
Jon Hallfc951072017-05-24 15:55:34 -07001117 def CASE1200( self, main ):
1118 """
alisone14d7b02016-07-06 10:31:51 -07001119 Add flows with a ARP selector and verify the flow
Jon Hallfc951072017-05-24 15:55:34 -07001120 """
alisone14d7b02016-07-06 10:31:51 -07001121 import json
1122 import time
1123
1124 main.case( "Verify flow IP selectors are correctly compiled" )
1125 main.caseExplanation = "Install two flows with only IP selectors " + \
1126 "specified, then verify flows are added in ONOS, finally " + \
1127 "send a packet that only specifies the IP src and dst."
1128
1129 main.step( "Add flows with ARP addresses as the only selectors" )
1130
1131 main.log.info( "Creating host components" )
1132 main.Scapy.createHostComponent( "h1" )
1133 main.Scapy.createHostComponent( "h2" )
1134 hosts = [ main.h1, main.h2 ]
1135 for host in hosts:
Jon Hallfc951072017-05-24 15:55:34 -07001136 host.startHostCli()
1137 host.startScapy()
1138 host.updateSelf()
alisone14d7b02016-07-06 10:31:51 -07001139
1140 # Add a flow that connects host1 on port1 to host2 on port2
1141 # send output on port2
1142 # recieve input on port1
1143 egress = 2
1144 ingress = 1
1145 # ARP etherType = 0x0806
1146 ethType = main.params[ 'TEST' ][ 'arpType' ]
1147
1148 # Add flows that connects host1 to host2
1149 main.log.info( "Add flow with port ingress 1 to port egress 2" )
Jon Hallfc951072017-05-24 15:55:34 -07001150 stepResult = main.ONOSrest.addFlow( deviceId=main.swDPID,
1151 egressPort=egress,
1152 ingressPort=ingress,
1153 ethType=ethType,
1154 priority=40001,
1155 debug=main.debug )
alisone14d7b02016-07-06 10:31:51 -07001156
1157 utilities.assert_equals( expect=main.TRUE,
1158 actual=stepResult,
1159 onpass="Successfully added flows",
1160 onfail="Failed add flows" )
1161
1162 # Giving ONOS time to add the flow
1163 time.sleep( main.addFlowSleep )
1164
Devin Lim58046fa2017-07-05 16:55:00 -07001165 main.checkingFlow.checkFlow()
alisone14d7b02016-07-06 10:31:51 -07001166
1167 main.step( "Send a packet to verify the flow is correct" )
1168
1169 main.log.info( "Constructing packet" )
1170 # No need for the MAC src dst
1171 main.h1.buildEther( src=main.h1.hostMac, dst=main.h2.hostMac )
1172 main.h1.buildARP( pdst=main.h2.hostIp )
1173
1174 main.log.info( "Starting filter on host2" )
1175 # Defaults to ip
1176 main.h2.startFilter( pktFilter="arp" )
1177
1178 main.log.info( "Sending packet to host2" )
Jon Hallfc951072017-05-24 15:55:34 -07001179 main.h1.sendPacket()
alisone14d7b02016-07-06 10:31:51 -07001180
1181 main.log.info( "Checking filter for our packet" )
Jon Hallfc951072017-05-24 15:55:34 -07001182 stepResult = main.h2.checkFilter()
alisone14d7b02016-07-06 10:31:51 -07001183 if stepResult:
Jon Hallfc951072017-05-24 15:55:34 -07001184 main.log.info( "Packet: %s" % main.h2.readPackets() )
alisone14d7b02016-07-06 10:31:51 -07001185 else:
Jon Hallfc951072017-05-24 15:55:34 -07001186 main.h2.killFilter()
alisone14d7b02016-07-06 10:31:51 -07001187
1188 main.log.info( "Clean up host components" )
1189 for host in hosts:
Jon Hallfc951072017-05-24 15:55:34 -07001190 host.stopScapy()
alisone14d7b02016-07-06 10:31:51 -07001191 main.Mininet1.removeHostComponent( "h1" )
1192 main.Mininet1.removeHostComponent( "h2" )
1193
1194 utilities.assert_equals( expect=main.TRUE,
1195 actual=stepResult,
1196 onpass="Successfully sent a packet",
1197 onfail="Failed to send a packet" )
1198
1199 def CASE1800( self, main ):
Jon Hallfc951072017-05-24 15:55:34 -07001200 """
alisone14d7b02016-07-06 10:31:51 -07001201 Add flows with a SCTP selector and verify the flow
Jon Hallfc951072017-05-24 15:55:34 -07001202 """
alisone14d7b02016-07-06 10:31:51 -07001203 import json
1204 import time
1205
1206 main.case( "Verify the UDP selector is correctly compiled on the flow" )
1207 main.caseExplanation = "Install a flow with only the UDP selector " + \
1208 "specified, verify the flow is added in ONOS, and finally " + \
1209 "send a UDP packet to verify the UDP selector is compiled correctly."
1210
1211 main.step( "Add a flow with a SCTP selector" )
1212
1213 main.log.info( "Creating host components" )
1214 main.Scapy.createHostComponent( "h1" )
1215 main.Scapy.createHostComponent( "h2" )
1216 hosts = [ main.h1, main.h2 ]
1217 for host in hosts:
Jon Hallfc951072017-05-24 15:55:34 -07001218 host.startHostCli()
1219 host.startScapy()
1220 host.updateSelf()
alisone14d7b02016-07-06 10:31:51 -07001221
1222 # Add a flow that connects host1 on port1 to host2 on port2
1223 egress = 2
1224 ingress = 1
1225 # IPv4 etherType
1226 ethType = main.params[ 'TEST' ][ 'ip4Type' ]
1227 # IP protocol
1228 ipProto = main.params[ 'TEST' ][ 'sctpProto' ]
1229
Jon Hallfc951072017-05-24 15:55:34 -07001230 main.log.info( "Add a flow that connects host1 on port1 to host2 on port2" )
alisone14d7b02016-07-06 10:31:51 -07001231 stepResult = main.ONOSrest.addFlow( deviceId=main.swDPID,
1232 egressPort=egress,
1233 ingressPort=ingress,
1234 ethType=ethType,
1235 ipProto=ipProto,
1236 debug=main.debug )
1237
1238 utilities.assert_equals( expect=main.TRUE,
1239 actual=stepResult,
1240 onpass="Successfully added flows",
1241 onfail="Failed add flows" )
1242
1243 # Giving ONOS time to add the flow
1244 time.sleep( main.addFlowSleep )
1245
Devin Lim58046fa2017-07-05 16:55:00 -07001246 main.checkingFlow.checkFlow()
alisone14d7b02016-07-06 10:31:51 -07001247
1248 main.step( "Send a packet to verify the flow is correct" )
1249
1250 main.log.info( "Constructing packet" )
1251 # No need for the MAC src dst
1252 main.h1.buildEther( dst=main.h2.hostMac )
1253 main.h1.buildIP( dst=main.h2.hostIp )
Jon Hallfc951072017-05-24 15:55:34 -07001254 main.h1.buildSCTP()
alisone14d7b02016-07-06 10:31:51 -07001255
1256 main.log.info( "Starting filter on host2" )
1257 # Defaults to ip
1258 main.h2.startFilter( pktFilter="sctp" )
1259
1260 main.log.info( "Sending packet to host2" )
Jon Hallfc951072017-05-24 15:55:34 -07001261 main.h1.sendPacket()
alisone14d7b02016-07-06 10:31:51 -07001262
1263 main.log.info( "Checking filter for our packet" )
Jon Hallfc951072017-05-24 15:55:34 -07001264 stepResult = main.h2.checkFilter()
alisone14d7b02016-07-06 10:31:51 -07001265 if stepResult:
Jon Hallfc951072017-05-24 15:55:34 -07001266 main.log.info( "Packet: %s" % main.h2.readPackets() )
alisone14d7b02016-07-06 10:31:51 -07001267 else:
Jon Hallfc951072017-05-24 15:55:34 -07001268 main.h2.killFilter()
alisone14d7b02016-07-06 10:31:51 -07001269
1270 main.log.info( "Clean up host components" )
1271 for host in hosts:
Jon Hallfc951072017-05-24 15:55:34 -07001272 host.stopScapy()
alisone14d7b02016-07-06 10:31:51 -07001273 main.Mininet1.removeHostComponent( "h1" )
1274 main.Mininet1.removeHostComponent( "h2" )
1275
1276 utilities.assert_equals( expect=main.TRUE,
1277 actual=stepResult,
1278 onpass="Successfully sent a packet",
1279 onfail="Failed to send a packet" )
1280
GlennRC68449942015-10-16 16:03:12 -07001281 def CASE100( self, main ):
Jon Hallfc951072017-05-24 15:55:34 -07001282 """
GlennRC5147a422015-10-06 17:26:17 -07001283 Report errors/warnings/exceptions
Jon Hallfc951072017-05-24 15:55:34 -07001284 """
alisone14d7b02016-07-06 10:31:51 -07001285 main.log.info( "Error report: \n" )
GlennRC5147a422015-10-06 17:26:17 -07001286 main.ONOSbench.logReport( main.ONOSip[ 0 ],
1287 [ "INFO",
1288 "FOLLOWER",
1289 "WARN",
1290 "flow",
1291 "ERROR",
1292 "Except" ],
GlennRC68449942015-10-16 16:03:12 -07001293 "s" )