blob: f161202a924b6e0c70cbeea40785a1e8c6c05f5a [file] [log] [blame]
Jeremy Ronquillob27ce4c2017-07-17 12:41:28 -07001"""
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -07002Copyright 2015 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"""
GlennRC5147a422015-10-06 17:26:17 -070021class FUNCflow:
22
23 def __init__( self ):
24 self.default = ''
25
26 def CASE1( self, main ):
GlennRC5147a422015-10-06 17:26:17 -070027 import os
28 import imp
Devin Lim58046fa2017-07-05 16:55:00 -070029 try:
30 from tests.dependencies.ONOSSetup import ONOSSetup
31 except ImportError:
32 main.log.error( "SetUp not found exiting the test" )
Devin Lim44075962017-08-11 10:56:37 -070033 main.cleanAndExit()
Devin Lim58046fa2017-07-05 16:55:00 -070034 try:
35 main.testSetUp
36 except ( NameError, AttributeError ):
37 main.testSetUp = ONOSSetup()
GlennRC5147a422015-10-06 17:26:17 -070038 """
39 - Construct tests variables
40 - GIT ( optional )
41 - Checkout ONOS master branch
42 - Pull latest ONOS code
GlennRC5147a422015-10-06 17:26:17 -070043 """
Devin Lim58046fa2017-07-05 16:55:00 -070044 main.testSetUp.envSetupDescription()
45 stepResult = main.FALSE
46 try:
47 # Test variables
48 main.cellName = main.params[ 'ENV' ][ 'cellName' ]
49 main.apps = main.params[ 'ENV' ][ 'cellApps' ]
50 main.ONOSport = main.params[ 'CTRL' ][ 'port' ]
51 main.dependencyPath = main.testOnDirectory + \
52 main.params[ 'DEPENDENCY' ][ 'path' ]
53 wrapperFile1 = main.params[ 'DEPENDENCY' ][ 'wrapper1' ]
54 wrapperFile2 = main.params[ 'DEPENDENCY' ][ 'wrapper2' ]
55 main.topology = main.params[ 'DEPENDENCY' ][ 'topology' ]
Devin Lim58046fa2017-07-05 16:55:00 -070056 main.startUpSleep = int( main.params[ 'SLEEP' ][ 'startup' ] )
57 main.startMNSleep = int( main.params[ 'SLEEP' ][ 'startMN' ] )
58 main.addFlowSleep = int( main.params[ 'SLEEP' ][ 'addFlow' ] )
59 main.delFlowSleep = int( main.params[ 'SLEEP' ][ 'delFlow' ] )
60 main.debug = main.params[ 'DEBUG' ]
61 main.swDPID = main.params[ 'TEST' ][ 'swDPID' ]
You Wangdafb6e22018-01-22 17:01:00 -080062 main.scapyHostNames = main.params[ 'SCAPY' ][ 'HOSTNAMES' ].split( ',' )
63 main.scapyHosts = [] # List of scapy hosts for iterating
GlennRC5147a422015-10-06 17:26:17 -070064
Devin Lim58046fa2017-07-05 16:55:00 -070065 main.debug = True if "on" in main.debug else False
GlennRC956ea742015-11-05 16:14:15 -080066
Devin Lim58046fa2017-07-05 16:55:00 -070067 # -- INIT SECTION, ONLY RUNS ONCE -- #
GlennRC5147a422015-10-06 17:26:17 -070068
Devin Lim58046fa2017-07-05 16:55:00 -070069 try:
70 from tests.FUNC.FUNCflow.dependencies.checkingFlow import CheckingFlow
71 main.checkingFlow = CheckingFlow()
72 except ImportError as e:
73 print e
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070074 main.log.error( "CheckingFlow not found exiting the test" )
Devin Lim44075962017-08-11 10:56:37 -070075 main.cleanAndExit()
Devin Lim58046fa2017-07-05 16:55:00 -070076 copyResult = main.ONOSbench.scp( main.Mininet1,
77 main.dependencyPath + main.topology,
78 main.Mininet1.home + '/custom/',
79 direction="to" )
GlennRC5147a422015-10-06 17:26:17 -070080
Devin Lim58046fa2017-07-05 16:55:00 -070081 utilities.assert_equals( expect=main.TRUE,
82 actual=copyResult,
83 onpass="Successfully copy " + "test variables ",
84 onfail="Failed to copy test variables" )
GlennRC5147a422015-10-06 17:26:17 -070085
Devin Lim58046fa2017-07-05 16:55:00 -070086 stepResult = main.testSetUp.envSetup()
GlennRC1704d072015-10-07 18:40:45 -070087
Devin Lim58046fa2017-07-05 16:55:00 -070088 except Exception as e:
89 main.testSetUp.envSetupException( e )
90 main.testSetUp.evnSetupConclusion( stepResult )
Devin Lim8d7c7782017-06-07 16:21:20 -070091
GlennRC5147a422015-10-06 17:26:17 -070092 def CASE2( self, main ):
93 """
94 - Set up cell
95 - Create cell file
96 - Set cell file
97 - Verify cell file
Devin Lim58046fa2017-07-05 16:55:00 -070098 - Building ONOS
99 - Install ONOS package
100 - Build ONOS package
GlennRC5147a422015-10-06 17:26:17 -0700101 - Kill ONOS process
102 - Uninstall ONOS cluster
103 - Verify ONOS start up
104 - Install ONOS cluster
105 - Connect to cli
106 """
You Wanga0f6ff62018-01-11 15:46:30 -0800107 main.testSetUp.ONOSSetUp( main.Cluster )
GlennRC5147a422015-10-06 17:26:17 -0700108
GlennRC68449942015-10-16 16:03:12 -0700109 def CASE10( self, main ):
Jon Hallfc951072017-05-24 15:55:34 -0700110 """
GlennRC68449942015-10-16 16:03:12 -0700111 Start Mininet
Jon Hallfc951072017-05-24 15:55:34 -0700112 """
GlennRC073e8bc2015-10-27 17:11:28 -0700113 import json
Devin Lim58046fa2017-07-05 16:55:00 -0700114 import time
115 try:
116 from tests.dependencies.topology import Topology
117 except ImportError:
118 main.log.error( "Topology not found exiting the test" )
Devin Lim44075962017-08-11 10:56:37 -0700119 main.cleanAndExit()
Devin Lim58046fa2017-07-05 16:55:00 -0700120 try:
121 main.topoRelated
122 except ( NameError, AttributeError ):
123 main.topoRelated = Topology()
GlennRC073e8bc2015-10-27 17:11:28 -0700124
125 main.case( "Setup mininet and compare ONOS topology view to Mininet topology" )
126 main.caseExplanation = "Start mininet with custom topology and compare topology " +\
127 "elements between Mininet and ONOS"
128
GlennRC68449942015-10-16 16:03:12 -0700129 main.step( "Setup Mininet Topology" )
130 topology = main.Mininet1.home + '/custom/' + main.topology
Jon Hallfc951072017-05-24 15:55:34 -0700131 stepResult = main.Mininet1.startNet( topoFile=topology )
GlennRC68449942015-10-16 16:03:12 -0700132
133 utilities.assert_equals( expect=main.TRUE,
GlennRC073e8bc2015-10-27 17:11:28 -0700134 actual=stepResult,
GlennRC68449942015-10-16 16:03:12 -0700135 onpass="Successfully loaded topology",
136 onfail="Failed to load topology" )
137
GlennRC073e8bc2015-10-27 17:11:28 -0700138 main.step( "Assign switch to controller" )
Devin Lim142b5342017-07-20 15:22:39 -0700139 stepResult = main.Mininet1.assignSwController( "s1", main.Cluster.active( 0 ).ipAddress )
GlennRC68449942015-10-16 16:03:12 -0700140
141 utilities.assert_equals( expect=main.TRUE,
GlennRC073e8bc2015-10-27 17:11:28 -0700142 actual=stepResult,
143 onpass="Successfully assigned switch to controller",
144 onfail="Failed to assign switch to controller" )
GlennRC68449942015-10-16 16:03:12 -0700145
GlennRC073e8bc2015-10-27 17:11:28 -0700146 time.sleep( main.startMNSleep )
GlennRC68449942015-10-16 16:03:12 -0700147
Devin Lim58046fa2017-07-05 16:55:00 -0700148 main.topoRelated.compareTopos( main.Mininet1 )
GlennRC68449942015-10-16 16:03:12 -0700149
You Wangdafb6e22018-01-22 17:01:00 -0800150 def CASE11( self, main ):
151 """
152 Start Scapy with Mininet
153 """
154 main.case( "Starting scapy with Mininet" )
155 main.step( "Creating Host component" )
156 scapyResult = main.TRUE
157 for hostName in main.scapyHostNames:
158 main.Scapy.createHostComponent( hostName )
159 main.scapyHosts.append( getattr( main, hostName ) )
160
161 main.step( "Start scapy components" )
162 for host in main.scapyHosts:
163 host.startHostCli()
164 host.startScapy()
165 host.updateSelf()
166 main.log.debug( host.name )
167 main.log.debug( host.hostIp )
168 main.log.debug( host.hostMac )
169
170 utilities.assert_equals( expect=main.TRUE,
171 actual=scapyResult,
172 onpass="Successfully created Scapy Components",
173 onfail="Failed to discover Scapy Components" )
174
175 def CASE12( self, main ):
176 """
177 Stop mininet and remove scapy host
178 """
179 try:
180 from tests.dependencies.utils import Utils
181 except ImportError:
182 main.log.error( "Utils not found exiting the test" )
183 main.cleanAndExit()
184 try:
185 main.Utils
186 except ( NameError, AttributeError ):
187 main.Utils = Utils()
188 main.log.report( "Stop Mininet and Scapy" )
189 main.case( "Stop Mininet and Scapy" )
190 main.caseExplanation = "Stopping the current mininet topology " +\
191 "to start up fresh"
192 main.step( "Stopping and Removing Scapy Host Components" )
193 scapyResult = main.TRUE
194 for host in main.scapyHosts:
195 scapyResult = scapyResult and host.stopScapy()
196 main.log.info( "Stopped Scapy Host: {0}".format( host.name ) )
197
198 for host in main.scapyHosts:
199 scapyResult = scapyResult and main.Scapy.removeHostComponent( host.name )
200 main.log.info( "Removed Scapy Host Component: {0}".format( host.name ) )
201
202 main.scapyHosts = []
203
204 utilities.assert_equals( expect=main.TRUE,
205 actual=scapyResult,
206 onpass="Successfully stopped scapy and removed host components",
207 onfail="Failed to stop mininet and scapy" )
208
209 mininetResult = main.Utils.mininetCleanup( main.Mininet1 )
210 # Exit if topology did not load properly
211 if not ( mininetResult and scapyResult ):
212 main.cleanAndExit()
213
Jon Hall892818c2015-10-20 17:58:34 -0700214 def CASE66( self, main ):
Jon Hallfc951072017-05-24 15:55:34 -0700215 """
Jon Hall892818c2015-10-20 17:58:34 -0700216 Testing scapy
Jon Hallfc951072017-05-24 15:55:34 -0700217 """
Jon Hall892818c2015-10-20 17:58:34 -0700218 main.case( "Testing scapy" )
You Wangdafb6e22018-01-22 17:01:00 -0800219 for host in main.scapyHosts:
220 host.stopScapy()
Jon Hallfc951072017-05-24 15:55:34 -0700221 host.startScapy()
222 host.updateSelf()
Jon Hall892818c2015-10-20 17:58:34 -0700223 main.log.debug( host.name )
224 main.log.debug( host.hostIp )
225 main.log.debug( host.hostMac )
226
227 main.step( "Sending/Receiving Test packet - Filter doesn't match" )
Jon Halla510a8a2016-05-04 15:09:28 -0700228 main.log.info( "Starting Filter..." )
Jon Hallfc951072017-05-24 15:55:34 -0700229 main.h2.startFilter()
Jon Halla510a8a2016-05-04 15:09:28 -0700230 main.log.info( "Building Ether frame..." )
Jon Hall892818c2015-10-20 17:58:34 -0700231 main.h1.buildEther( dst=main.h2.hostMac )
Jon Halla510a8a2016-05-04 15:09:28 -0700232 main.log.info( "Sending Packet..." )
Jon Hallfc951072017-05-24 15:55:34 -0700233 main.h1.sendPacket()
Jon Halla510a8a2016-05-04 15:09:28 -0700234 main.log.info( "Checking Filter..." )
Jon Hallfc951072017-05-24 15:55:34 -0700235 finished = main.h2.checkFilter()
Jon Halla510a8a2016-05-04 15:09:28 -0700236 main.log.debug( finished )
Jon Hall892818c2015-10-20 17:58:34 -0700237 i = ""
238 if finished:
Jon Hallfc951072017-05-24 15:55:34 -0700239 a = main.h2.readPackets()
240 for i in a.splitlines():
Jon Hall892818c2015-10-20 17:58:34 -0700241 main.log.info( i )
242 else:
Jon Hallfc951072017-05-24 15:55:34 -0700243 kill = main.h2.killFilter()
Jon Hall892818c2015-10-20 17:58:34 -0700244 main.log.debug( kill )
245 main.h2.handle.sendline( "" )
246 main.h2.handle.expect( main.h2.scapyPrompt )
247 main.log.debug( main.h2.handle.before )
248 utilities.assert_equals( expect=True,
249 actual="dst=00:00:00:00:00:02 src=00:00:00:00:00:01" in i,
250 onpass="Pass",
251 onfail="Fail" )
252
253 main.step( "Sending/Receiving Test packet - Filter matches" )
Jon Hallfc951072017-05-24 15:55:34 -0700254 main.h2.startFilter()
Jon Hall892818c2015-10-20 17:58:34 -0700255 main.h1.buildEther( dst=main.h2.hostMac )
256 main.h1.buildIP( dst=main.h2.hostIp )
Jon Hallfc951072017-05-24 15:55:34 -0700257 main.h1.sendPacket()
258 finished = main.h2.checkFilter()
Jon Hall892818c2015-10-20 17:58:34 -0700259 i = ""
260 if finished:
Jon Hallfc951072017-05-24 15:55:34 -0700261 a = main.h2.readPackets()
262 for i in a.splitlines():
Jon Hall892818c2015-10-20 17:58:34 -0700263 main.log.info( i )
264 else:
Jon Hallfc951072017-05-24 15:55:34 -0700265 kill = main.h2.killFilter()
Jon Hall892818c2015-10-20 17:58:34 -0700266 main.log.debug( kill )
267 main.h2.handle.sendline( "" )
268 main.h2.handle.expect( main.h2.scapyPrompt )
269 main.log.debug( main.h2.handle.before )
270 utilities.assert_equals( expect=True,
271 actual="dst=00:00:00:00:00:02 src=00:00:00:00:00:01" in i,
272 onpass="Pass",
273 onfail="Fail" )
274
GlennRC68449942015-10-16 16:03:12 -0700275 def CASE1000( self, main ):
Jon Hallfc951072017-05-24 15:55:34 -0700276 """
GlennRC073e8bc2015-10-27 17:11:28 -0700277 Add flows with MAC selectors and verify the flows
Jon Hallfc951072017-05-24 15:55:34 -0700278 """
GlennRC073e8bc2015-10-27 17:11:28 -0700279 import json
280 import time
Devin Lim142b5342017-07-20 15:22:39 -0700281 ctrl = main.Cluster.active( 0 )
GlennRC073e8bc2015-10-27 17:11:28 -0700282 main.case( "Verify flow MAC selectors are correctly compiled" )
283 main.caseExplanation = "Install two flows with only MAC selectors " +\
Jon Hallfc951072017-05-24 15:55:34 -0700284 "specified, then verify flows are added in ONOS, finally " +\
GlennRC073e8bc2015-10-27 17:11:28 -0700285 "send a packet that only specifies the MAC src and dst."
GlennRC68449942015-10-16 16:03:12 -0700286
GlennRC073e8bc2015-10-27 17:11:28 -0700287 main.step( "Add flows with MAC addresses as the only selectors" )
You Wangdafb6e22018-01-22 17:01:00 -0800288 for host in main.scapyHosts:
289 host.stopScapy()
Jon Hallfc951072017-05-24 15:55:34 -0700290 host.startScapy()
291 host.updateSelf()
You Wangdafb6e22018-01-22 17:01:00 -0800292 main.log.debug( host.name )
293 main.log.debug( host.hostIp )
294 main.log.debug( host.hostMac )
GlennRC68449942015-10-16 16:03:12 -0700295
GlennRC073e8bc2015-10-27 17:11:28 -0700296 # Add a flow that connects host1 on port1 to host2 on port2
297 # send output on port2
298 # recieve input on port1
299 egress = 2
300 ingress = 1
301
302 # Add flows that sends packets from port1 to port2 with correct
303 # MAC src and dst addresses
304 main.log.info( "Adding flow with MAC selectors" )
Devin Lim142b5342017-07-20 15:22:39 -0700305 stepResult = ctrl.REST.addFlow( deviceId=main.swDPID,
306 egressPort=egress,
307 ingressPort=ingress,
308 ethSrc=main.h1.hostMac,
309 ethDst=main.h2.hostMac,
310 debug=main.debug )
GlennRC68449942015-10-16 16:03:12 -0700311
GlennRCa5391372015-10-14 17:28:15 -0700312 utilities.assert_equals( expect=main.TRUE,
313 actual=stepResult,
GlennRC68449942015-10-16 16:03:12 -0700314 onpass="Successfully added flows",
315 onfail="Failed add flows" )
GlennRCa5391372015-10-14 17:28:15 -0700316
GlennRC073e8bc2015-10-27 17:11:28 -0700317 # Giving ONOS time to add the flows
318 time.sleep( main.addFlowSleep )
GlennRC5147a422015-10-06 17:26:17 -0700319
Devin Lim142b5342017-07-20 15:22:39 -0700320 main.checkingFlow.checkFlow()
GlennRC956ea742015-11-05 16:14:15 -0800321
GlennRC073e8bc2015-10-27 17:11:28 -0700322 main.step( "Send a packet to verify the flows are correct" )
323
324 # Specify the src and dst MAC addr
325 main.log.info( "Constructing packet" )
326 main.h1.buildEther( src=main.h1.hostMac, dst=main.h2.hostMac )
327
328 # Filter for packets with the correct host name. Otherwise,
329 # the filter we catch any packet that is sent to host2
330 # NOTE: I believe it doesn't matter which host name it is,
GlennRC956ea742015-11-05 16:14:15 -0800331 # as long as the src and dst are both specified
GlennRC073e8bc2015-10-27 17:11:28 -0700332 main.log.info( "Starting filter on host2" )
alisone14d7b02016-07-06 10:31:51 -0700333 main.h2.startFilter( pktFilter="ether host %s" % main.h1.hostMac )
GlennRC073e8bc2015-10-27 17:11:28 -0700334
335 main.log.info( "Sending packet to host2" )
336 main.h1.sendPacket()
337
338 main.log.info( "Checking filter for our packet" )
Jon Hallfc951072017-05-24 15:55:34 -0700339 stepResult = main.h2.checkFilter()
GlennRC073e8bc2015-10-27 17:11:28 -0700340 if stepResult:
Jon Hallfc951072017-05-24 15:55:34 -0700341 main.log.info( "Packet: %s" % main.h2.readPackets() )
alisone14d7b02016-07-06 10:31:51 -0700342 else:
Jon Hallfc951072017-05-24 15:55:34 -0700343 main.h2.killFilter()
GlennRC073e8bc2015-10-27 17:11:28 -0700344
GlennRC073e8bc2015-10-27 17:11:28 -0700345 utilities.assert_equals( expect=main.TRUE,
346 actual=stepResult,
347 onpass="Successfully sent a packet",
348 onfail="Failed to send a packet" )
349
alisone14d7b02016-07-06 10:31:51 -0700350 def CASE1400( self, main ):
Jon Hallfc951072017-05-24 15:55:34 -0700351 """
GlennRC073e8bc2015-10-27 17:11:28 -0700352 Add flows with IPv4 selectors and verify the flows
Jon Hallfc951072017-05-24 15:55:34 -0700353 """
GlennRC68449942015-10-16 16:03:12 -0700354 import json
GlennRC073e8bc2015-10-27 17:11:28 -0700355 import time
Devin Lim142b5342017-07-20 15:22:39 -0700356 ctrl = main.Cluster.active( 0 )
GlennRC073e8bc2015-10-27 17:11:28 -0700357 main.case( "Verify flow IP selectors are correctly compiled" )
358 main.caseExplanation = "Install two flows with only IP selectors " +\
alisone14d7b02016-07-06 10:31:51 -0700359 "specified, then verify flows are added in ONOS, finally " +\
GlennRC073e8bc2015-10-27 17:11:28 -0700360 "send a packet that only specifies the IP src and dst."
361
362 main.step( "Add flows with IPv4 addresses as the only selectors" )
You Wangdafb6e22018-01-22 17:01:00 -0800363 for host in main.scapyHosts:
364 host.stopScapy()
Jon Hallfc951072017-05-24 15:55:34 -0700365 host.startScapy()
366 host.updateSelf()
You Wangdafb6e22018-01-22 17:01:00 -0800367 main.log.debug( host.name )
368 main.log.debug( host.hostIp )
369 main.log.debug( host.hostMac )
GlennRC073e8bc2015-10-27 17:11:28 -0700370
371 # Add a flow that connects host1 on port1 to host2 on port2
372 # send output on port2
373 # recieve input on port1
374 egress = 2
375 ingress = 1
376 # IPv4 etherType = 0x800
alisone14d7b02016-07-06 10:31:51 -0700377 ethType = main.params[ 'TEST' ][ 'ip4Type' ]
GlennRC073e8bc2015-10-27 17:11:28 -0700378
379 # Add flows that connects host1 to host2
380 main.log.info( "Add flow with port ingress 1 to port egress 2" )
Devin Lim142b5342017-07-20 15:22:39 -0700381 stepResult = ctrl.REST.addFlow( deviceId=main.swDPID,
382 egressPort=egress,
383 ingressPort=ingress,
384 ethType=ethType,
385 ipSrc=( "IPV4_SRC", main.h1.hostIp + "/32" ),
386 ipDst=( "IPV4_DST", main.h2.hostIp + "/32" ),
387 debug=main.debug )
GlennRC073e8bc2015-10-27 17:11:28 -0700388
389 utilities.assert_equals( expect=main.TRUE,
390 actual=stepResult,
391 onpass="Successfully added flows",
392 onfail="Failed add flows" )
393
394 # Giving ONOS time to add the flow
395 time.sleep( main.addFlowSleep )
396
Devin Lim58046fa2017-07-05 16:55:00 -0700397 main.checkingFlow.checkFlow()
GlennRC956ea742015-11-05 16:14:15 -0800398
GlennRC073e8bc2015-10-27 17:11:28 -0700399 main.step( "Send a packet to verify the flow is correct" )
400
401 main.log.info( "Constructing packet" )
402 # No need for the MAC src dst
403 main.h1.buildEther( dst=main.h2.hostMac )
404 main.h1.buildIP( src=main.h1.hostIp, dst=main.h2.hostIp )
405
406 main.log.info( "Starting filter on host2" )
407 # Defaults to ip
Jon Hallfc951072017-05-24 15:55:34 -0700408 main.h2.startFilter()
GlennRC073e8bc2015-10-27 17:11:28 -0700409
410 main.log.info( "Sending packet to host2" )
Jon Hallfc951072017-05-24 15:55:34 -0700411 main.h1.sendPacket()
GlennRC073e8bc2015-10-27 17:11:28 -0700412
413 main.log.info( "Checking filter for our packet" )
Jon Hallfc951072017-05-24 15:55:34 -0700414 stepResult = main.h2.checkFilter()
GlennRC073e8bc2015-10-27 17:11:28 -0700415 if stepResult:
Jon Hallfc951072017-05-24 15:55:34 -0700416 main.log.info( "Packet: %s" % main.h2.readPackets() )
417 else:
418 main.h2.killFilter()
GlennRC073e8bc2015-10-27 17:11:28 -0700419
GlennRC073e8bc2015-10-27 17:11:28 -0700420 utilities.assert_equals( expect=main.TRUE,
421 actual=stepResult,
422 onpass="Successfully sent a packet",
423 onfail="Failed to send a packet" )
424
Jon Hallfc951072017-05-24 15:55:34 -0700425 def CASE1500( self, main ):
alisone14d7b02016-07-06 10:31:51 -0700426 """
427 Add flow with IPv6 selector and verify the flow
428 """
429 import json
430 import time
431 main.case( "Verify IPv6 selector is correctly compiled" )
432 main.caseExplanation = "Install two flows with only IP selectors " + \
433 "specified, then verify flows are added in ONOS, finally " + \
434 "send a packet that only specifies the IP src and dst."
435
436 main.step( "Add flows with IPv6 addresses as the only selectors" )
You Wangdafb6e22018-01-22 17:01:00 -0800437 for host in main.scapyHosts:
438 host.stopScapy()
Jon Hallfc951072017-05-24 15:55:34 -0700439 host.startScapy()
alisone14d7b02016-07-06 10:31:51 -0700440 host.updateSelf( IPv6=True )
You Wangdafb6e22018-01-22 17:01:00 -0800441 main.log.debug( host.name )
442 main.log.debug( host.hostIp )
443 main.log.debug( host.hostMac )
alisone14d7b02016-07-06 10:31:51 -0700444
445 # Add a flow that connects host1 on port1 to host2 on port2
446 # send output on port2
447 # recieve input on port1
448 egress = 6
449 ingress = 5
450 # IPv6 etherType = 0x86DD
451 ethType = main.params[ 'TEST' ][ 'ip6Type' ]
452
453 # Add flows that connects host1 to host2
454 main.log.info( "Add flow with port ingress 5 to port egress 6" )
Devin Lim142b5342017-07-20 15:22:39 -0700455 stepResult = ctrl.REST.addFlow( deviceId=main.swDPID,
456 egressPort=egress,
457 ingressPort=ingress,
458 ethType=ethType,
459 ipSrc=( "IPV6_SRC", main.h5.hostIp + "/128" ),
460 ipDst=( "IPV6_DST", main.h6.hostIp + "/128" ),
461 debug=main.debug )
alisone14d7b02016-07-06 10:31:51 -0700462
463 utilities.assert_equals( expect=main.TRUE,
464 actual=stepResult,
465 onpass="Successfully added flows",
466 onfail="Failed add flows" )
467
468 # Giving ONOS time to add the flow
469 time.sleep( main.addFlowSleep )
470
Devin Lim58046fa2017-07-05 16:55:00 -0700471 main.checkingFlow.checkFlow()
alisone14d7b02016-07-06 10:31:51 -0700472
473 main.step( "Send a packet to verify the flow is correct" )
474
475 main.log.info( "Constructing packet" )
476 # No need for the MAC src dst
477 main.h5.buildEther( dst=main.h6.hostMac )
478 main.h5.buildIPv6( src=main.h5.hostIp, dst=main.h6.hostIp )
479
480 main.log.info( "Starting filter on host6" )
481 # Defaults to ip
482 main.h6.startFilter( pktFilter="ip6" )
483 main.log.info( "Sending packet to host6" )
Jon Hallfc951072017-05-24 15:55:34 -0700484 main.h5.sendPacket()
alisone14d7b02016-07-06 10:31:51 -0700485
486 main.log.info( "Checking filter for our packet" )
Jon Hallfc951072017-05-24 15:55:34 -0700487 stepResult = main.h6.checkFilter()
alisone14d7b02016-07-06 10:31:51 -0700488 if stepResult:
Jon Hallfc951072017-05-24 15:55:34 -0700489 main.log.info( "Packet: %s" % main.h6.readPackets() )
alisone14d7b02016-07-06 10:31:51 -0700490 else:
Jon Hallfc951072017-05-24 15:55:34 -0700491 main.h6.killFilter()
alisone14d7b02016-07-06 10:31:51 -0700492
alisone14d7b02016-07-06 10:31:51 -0700493 utilities.assert_equals( expect=main.TRUE,
494 actual=stepResult,
495 onpass="Successfully sent a packet",
496 onfail="Failed to send a packet" )
497
alisone14d7b02016-07-06 10:31:51 -0700498 def CASE1100( self, main ):
Jon Hallfc951072017-05-24 15:55:34 -0700499 """
GlennRC073e8bc2015-10-27 17:11:28 -0700500 Add flow with VLAN selector and verify the flow
Jon Hallfc951072017-05-24 15:55:34 -0700501 """
GlennRC073e8bc2015-10-27 17:11:28 -0700502 import json
503 import time
504
505 main.case( "Verify VLAN selector is correctly compiled" )
506 main.caseExplanation = "Install one flow with only the VLAN selector " +\
Jon Hallfc951072017-05-24 15:55:34 -0700507 "specified, then verify the flow is added in ONOS, and finally " +\
GlennRC073e8bc2015-10-27 17:11:28 -0700508 "broadcast a packet with the correct VLAN tag."
509
You Wangdafb6e22018-01-22 17:01:00 -0800510 for host in main.scapyHosts:
511 host.stopScapy()
Jon Hallfc951072017-05-24 15:55:34 -0700512 host.startScapy()
513 host.updateSelf()
You Wangdafb6e22018-01-22 17:01:00 -0800514 main.log.debug( host.name )
515 main.log.debug( host.hostIp )
516 main.log.debug( host.hostMac )
GlennRC073e8bc2015-10-27 17:11:28 -0700517
518 main.step( "Add a flow with the VLAN tag as the only selector" )
519
520 # Add flows that connects the two vlan hosts h3 and h4
521 # Host 3 is on port 3 and host 4 is on port 4
522 vlan = main.params[ 'TEST' ][ 'vlan' ]
523 egress = 4
524 ingress = 3
525 # VLAN ethType = 0x8100
alisone14d7b02016-07-06 10:31:51 -0700526 ethType = main.params[ 'TEST' ][ 'vlanType' ]
GlennRC073e8bc2015-10-27 17:11:28 -0700527
528 # Add only one flow because we don't need a response
529 main.log.info( "Add flow with port ingress 1 to port egress 2" )
Devin Lim142b5342017-07-20 15:22:39 -0700530 stepResult = ctrl.REST.addFlow( deviceId=main.swDPID,
531 egressPort=egress,
532 ingressPort=ingress,
533 ethType=ethType,
534 vlan=vlan,
535 debug=main.debug )
GlennRC073e8bc2015-10-27 17:11:28 -0700536
GlennRC073e8bc2015-10-27 17:11:28 -0700537 utilities.assert_equals( expect=main.TRUE,
538 actual=stepResult,
539 onpass="Successfully added flow",
540 onfail="Failed add flows" )
541
542 # Giving ONOS time to add the flows
543 time.sleep( main.addFlowSleep )
544
Devin Lim142b5342017-07-20 15:22:39 -0700545 main.checkingFlow.checkFlow()
GlennRC956ea742015-11-05 16:14:15 -0800546
GlennRC073e8bc2015-10-27 17:11:28 -0700547 main.step( "Send a packet to verify the flow are correct" )
548
549 # The receiving interface
alisone14d7b02016-07-06 10:31:51 -0700550 recIface = "{}-eth0.{}".format( main.h4.name, vlan )
GlennRC073e8bc2015-10-27 17:11:28 -0700551 main.log.info( "Starting filter on host2" )
552 # Filter is setup to catch any packet on the vlan interface with the correct vlan tag
Jon Hallfc951072017-05-24 15:55:34 -0700553 main.h4.startFilter( ifaceName=recIface, pktFilter="" )
GlennRC073e8bc2015-10-27 17:11:28 -0700554
555 # Broadcast the packet on the vlan interface. We only care if the flow forwards
556 # the packet with the correct vlan tag, not if the mac addr is correct
alisone14d7b02016-07-06 10:31:51 -0700557 sendIface = "{}-eth0.{}".format( main.h3.name, vlan )
GlennRC073e8bc2015-10-27 17:11:28 -0700558 main.log.info( "Broadcasting the packet with a vlan tag" )
GlennRC956ea742015-11-05 16:14:15 -0800559 main.h3.sendPacket( iface=sendIface,
alisone14d7b02016-07-06 10:31:51 -0700560 packet="Ether()/Dot1Q(vlan={})".format( vlan ) )
GlennRC073e8bc2015-10-27 17:11:28 -0700561
562 main.log.info( "Checking filter for our packet" )
Jon Hallfc951072017-05-24 15:55:34 -0700563 stepResult = main.h4.checkFilter()
GlennRC073e8bc2015-10-27 17:11:28 -0700564 if stepResult:
Jon Hallfc951072017-05-24 15:55:34 -0700565 main.log.info( "Packet: %s" % main.h4.readPackets() )
566 else:
567 main.h4.killFilter()
GlennRC073e8bc2015-10-27 17:11:28 -0700568
GlennRC073e8bc2015-10-27 17:11:28 -0700569 utilities.assert_equals( expect=main.TRUE,
570 actual=stepResult,
571 onpass="Successfully sent a packet",
572 onfail="Failed to send a packet" )
GlennRC68449942015-10-16 16:03:12 -0700573
GlennRC956ea742015-11-05 16:14:15 -0800574 def CASE1300( self, main ):
Jon Hallfc951072017-05-24 15:55:34 -0700575 """
GlennRC956ea742015-11-05 16:14:15 -0800576 Add flows with MPLS selector and verify the flows
Jon Hallfc951072017-05-24 15:55:34 -0700577 """
GlennRC956ea742015-11-05 16:14:15 -0800578 import json
579 import time
580
581 main.case( "Verify the MPLS selector is correctly compiled on the flow." )
582 main.caseExplanation = "Install one flow with an MPLS selector, " +\
alisone14d7b02016-07-06 10:31:51 -0700583 "verify the flow is added in ONOS, and finally " +\
GlennRC956ea742015-11-05 16:14:15 -0800584 "send a packet via scapy that has a MPLS label."
585
586 main.step( "Add a flow with a MPLS selector" )
You Wangdafb6e22018-01-22 17:01:00 -0800587 for host in main.scapyHosts:
588 host.stopScapy()
GlennRC956ea742015-11-05 16:14:15 -0800589 host.startScapy( main.dependencyPath )
Jon Hallfc951072017-05-24 15:55:34 -0700590 host.updateSelf()
You Wangdafb6e22018-01-22 17:01:00 -0800591 main.log.debug( host.name )
592 main.log.debug( host.hostIp )
593 main.log.debug( host.hostMac )
594
595 ctrl = main.Cluster.active( 0 )
GlennRC956ea742015-11-05 16:14:15 -0800596
597 # ports
598 egress = 2
599 ingress = 1
600 # MPLS etherType
601 ethType = main.params[ 'TEST' ][ 'mplsType' ]
602 # MPLS label
603 mplsLabel = main.params[ 'TEST' ][ 'mpls' ]
604
605 # Add a flow that connects host1 on port1 to host2 on port2
606 main.log.info( "Adding flow with MPLS selector" )
Devin Lim142b5342017-07-20 15:22:39 -0700607 stepResult = ctrl.REST.addFlow( deviceId=main.swDPID,
608 egressPort=egress,
609 ingressPort=ingress,
610 ethType=ethType,
611 mpls=mplsLabel,
612 debug=main.debug )
GlennRC956ea742015-11-05 16:14:15 -0800613
614 utilities.assert_equals( expect=main.TRUE,
615 actual=stepResult,
616 onpass="Successfully added flow",
617 onfail="Failed add flow" )
618
619 # Giving ONOS time to add the flow
620 time.sleep( main.addFlowSleep )
621
622 main.step( "Check flow is in the ADDED state" )
623
624 main.log.info( "Get the flows from ONOS" )
Jeremy86160992016-04-11 10:05:53 -0700625 try:
Devin Lim142b5342017-07-20 15:22:39 -0700626 flows = json.loads( ctrl.REST.flows() )
GlennRC956ea742015-11-05 16:14:15 -0800627
Jeremy86160992016-04-11 10:05:53 -0700628 stepResult = main.TRUE
629 for f in flows:
alisone14d7b02016-07-06 10:31:51 -0700630 if "rest" in f.get( "appId" ):
631 if "ADDED" not in f.get( "state" ):
Jeremy86160992016-04-11 10:05:53 -0700632 stepResult = main.FALSE
alisone14d7b02016-07-06 10:31:51 -0700633 main.log.error( "Flow: %s in state: %s" % ( f.get( "id" ), f.get( "state" ) ) )
Jeremy86160992016-04-11 10:05:53 -0700634 except TypeError:
635 main.log.error( "No Flows found by the REST API" )
636 stepResult = main.FALSE
637 except ValueError:
638 main.log.error( "Problem getting Flows state from REST API. Exiting test" )
Devin Lim44075962017-08-11 10:56:37 -0700639 main.cleanAndExit()
GlennRC956ea742015-11-05 16:14:15 -0800640
641 utilities.assert_equals( expect=main.TRUE,
642 actual=stepResult,
643 onpass="All flows are in the ADDED state",
644 onfail="All flows are NOT in the ADDED state" )
645
646 main.step( "Check flows are in Mininet's flow table" )
647
648 # get the flow IDs that were added through rest
649 main.log.info( "Getting the flow IDs from ONOS" )
alisone14d7b02016-07-06 10:31:51 -0700650 flowIds = [ f.get( "id" ) for f in flows if "rest" in f.get( "appId" ) ]
GlennRC956ea742015-11-05 16:14:15 -0800651 # convert the flowIDs to ints then hex and finally back to strings
alisone14d7b02016-07-06 10:31:51 -0700652 flowIds = [ str( hex( int( x ) ) ) for x in flowIds ]
653 main.log.info( "ONOS flow IDs: {}".format( flowIds ) )
GlennRC956ea742015-11-05 16:14:15 -0800654
655 stepResult = main.Mininet1.checkFlowId( "s1", flowIds, debug=True )
656
657 utilities.assert_equals( expect=main.TRUE,
658 actual=stepResult,
659 onpass="All flows are in mininet",
660 onfail="All flows are NOT in mininet" )
661
662 main.step( "Send a packet to verify the flow is correct" )
663
664 main.log.info( "Starting filter on host2" )
665 main.h2.startFilter( pktFilter="mpls" )
666
667 main.log.info( "Constructing packet" )
668 main.log.info( "Sending packet to host2" )
alisone14d7b02016-07-06 10:31:51 -0700669 main.h1.sendPacket( packet='Ether()/MPLS(label={})'.format( mplsLabel ) )
GlennRC956ea742015-11-05 16:14:15 -0800670
671 main.log.info( "Checking filter for our packet" )
Jon Hallfc951072017-05-24 15:55:34 -0700672 stepResult = main.h2.checkFilter()
GlennRC956ea742015-11-05 16:14:15 -0800673 if stepResult:
Jon Hallfc951072017-05-24 15:55:34 -0700674 main.log.info( "Packet: %s" % main.h2.readPackets() )
675 else:
676 main.h2.killFilter()
GlennRC956ea742015-11-05 16:14:15 -0800677
GlennRC956ea742015-11-05 16:14:15 -0800678 utilities.assert_equals( expect=main.TRUE,
679 actual=stepResult,
680 onpass="Successfully sent a packet",
681 onfail="Failed to send a packet" )
682
alisone14d7b02016-07-06 10:31:51 -0700683 def CASE1700( self, main ):
Jon Hallfc951072017-05-24 15:55:34 -0700684 """
GlennRC956ea742015-11-05 16:14:15 -0800685 Add flows with a TCP selector and verify the flow
Jon Hallfc951072017-05-24 15:55:34 -0700686 """
GlennRC956ea742015-11-05 16:14:15 -0800687 import json
688 import time
689
690 main.case( "Verify the TCP selector is correctly compiled on the flow" )
691 main.caseExplanation = "Install a flow with only the TCP selector " +\
alisone14d7b02016-07-06 10:31:51 -0700692 "specified, verify the flow is added in ONOS, and finally " +\
GlennRC956ea742015-11-05 16:14:15 -0800693 "send a TCP packet to verify the TCP selector is compiled correctly."
694
695 main.step( "Add a flow with a TCP selector" )
Devin Lim142b5342017-07-20 15:22:39 -0700696 ctrl = main.Cluster.active( 0 )
You Wangdafb6e22018-01-22 17:01:00 -0800697 for host in main.scapyHosts:
698 host.stopScapy()
Jon Hallfc951072017-05-24 15:55:34 -0700699 host.startScapy()
700 host.updateSelf()
You Wangdafb6e22018-01-22 17:01:00 -0800701 main.log.debug( host.name )
702 main.log.debug( host.hostIp )
703 main.log.debug( host.hostMac )
GlennRC956ea742015-11-05 16:14:15 -0800704
705 # Add a flow that connects host1 on port1 to host2 on port2
706 egress = 2
707 ingress = 1
708 # IPv4 etherType
709 ethType = main.params[ 'TEST' ][ 'ip4Type' ]
710 # IP protocol
711 ipProto = main.params[ 'TEST' ][ 'tcpProto' ]
712 # TCP port destination
713 tcpDst = main.params[ 'TEST' ][ 'tcpDst' ]
714
715 main.log.info( "Add a flow that connects host1 on port1 to host2 on port2" )
Devin Lim142b5342017-07-20 15:22:39 -0700716 stepResult = ctrl.REST.addFlow( deviceId=main.swDPID,
717 egressPort=egress,
718 ingressPort=ingress,
719 ethType=ethType,
720 ipProto=ipProto,
721 tcpDst=tcpDst,
722 debug=main.debug )
GlennRC956ea742015-11-05 16:14:15 -0800723
724 utilities.assert_equals( expect=main.TRUE,
725 actual=stepResult,
726 onpass="Successfully added flows",
727 onfail="Failed add flows" )
728
729 # Giving ONOS time to add the flow
730 time.sleep( main.addFlowSleep )
731
Devin Lim58046fa2017-07-05 16:55:00 -0700732 main.checkingFlow.checkFlow()
GlennRC956ea742015-11-05 16:14:15 -0800733
734 main.step( "Send a packet to verify the flow is correct" )
735
736 main.log.info( "Constructing packet" )
737 # No need for the MAC src dst
738 main.h1.buildEther( dst=main.h2.hostMac )
739 main.h1.buildIP( dst=main.h2.hostIp )
740 main.h1.buildTCP( dport=tcpDst )
741
742 main.log.info( "Starting filter on host2" )
743 # Defaults to ip
744 main.h2.startFilter( pktFilter="tcp" )
745
746 main.log.info( "Sending packet to host2" )
Jon Hallfc951072017-05-24 15:55:34 -0700747 main.h1.sendPacket()
GlennRC956ea742015-11-05 16:14:15 -0800748
749 main.log.info( "Checking filter for our packet" )
Jon Hallfc951072017-05-24 15:55:34 -0700750 stepResult = main.h2.checkFilter()
GlennRC956ea742015-11-05 16:14:15 -0800751 if stepResult:
Jon Hallfc951072017-05-24 15:55:34 -0700752 main.log.info( "Packet: %s" % main.h2.readPackets() )
753 else:
754 main.h2.killFilter()
GlennRC956ea742015-11-05 16:14:15 -0800755
GlennRC956ea742015-11-05 16:14:15 -0800756 utilities.assert_equals( expect=main.TRUE,
757 actual=stepResult,
758 onpass="Successfully sent a packet",
759 onfail="Failed to send a packet" )
760
alisone14d7b02016-07-06 10:31:51 -0700761 def CASE1600( self, main ):
Jon Hallfc951072017-05-24 15:55:34 -0700762 """
GlennRC956ea742015-11-05 16:14:15 -0800763 Add flows with a UDP selector and verify the flow
Jon Hallfc951072017-05-24 15:55:34 -0700764 """
GlennRC956ea742015-11-05 16:14:15 -0800765 import json
766 import time
767
768 main.case( "Verify the UDP selector is correctly compiled on the flow" )
769 main.caseExplanation = "Install a flow with only the UDP selector " +\
alisone14d7b02016-07-06 10:31:51 -0700770 "specified, verify the flow is added in ONOS, and finally " +\
GlennRC956ea742015-11-05 16:14:15 -0800771 "send a UDP packet to verify the UDP selector is compiled correctly."
772
773 main.step( "Add a flow with a UDP selector" )
Devin Lim142b5342017-07-20 15:22:39 -0700774 ctrl = main.Cluster.active( 0 )
You Wangdafb6e22018-01-22 17:01:00 -0800775 for host in main.scapyHosts:
776 host.stopScapy()
Jon Hallfc951072017-05-24 15:55:34 -0700777 host.startScapy()
778 host.updateSelf()
You Wangdafb6e22018-01-22 17:01:00 -0800779 main.log.debug( host.name )
780 main.log.debug( host.hostIp )
781 main.log.debug( host.hostMac )
GlennRC956ea742015-11-05 16:14:15 -0800782
783 # Add a flow that connects host1 on port1 to host2 on port2
784 egress = 2
785 ingress = 1
786 # IPv4 etherType
787 ethType = main.params[ 'TEST' ][ 'ip4Type' ]
788 # IP protocol
789 ipProto = main.params[ 'TEST' ][ 'udpProto' ]
790 # UDP port destination
791 udpDst = main.params[ 'TEST' ][ 'udpDst' ]
792
793 main.log.info( "Add a flow that connects host1 on port1 to host2 on port2" )
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700794 stepResult = ctrl.REST.addFlow( deviceId=main.swDPID,
GlennRC956ea742015-11-05 16:14:15 -0800795 egressPort=egress,
796 ingressPort=ingress,
797 ethType=ethType,
798 ipProto=ipProto,
799 udpDst=udpDst,
800 debug=main.debug )
801
802 utilities.assert_equals( expect=main.TRUE,
803 actual=stepResult,
804 onpass="Successfully added flows",
805 onfail="Failed add flows" )
806
807 # Giving ONOS time to add the flow
808 time.sleep( main.addFlowSleep )
809
Devin Lim58046fa2017-07-05 16:55:00 -0700810 main.checkingFlow.checkFlow()
GlennRC956ea742015-11-05 16:14:15 -0800811
812 main.step( "Send a packet to verify the flow is correct" )
813
814 main.log.info( "Constructing packet" )
815 # No need for the MAC src dst
816 main.h1.buildEther( dst=main.h2.hostMac )
817 main.h1.buildIP( dst=main.h2.hostIp )
818 main.h1.buildUDP( dport=udpDst )
819
820 main.log.info( "Starting filter on host2" )
821 # Defaults to ip
822 main.h2.startFilter( pktFilter="udp" )
823
824 main.log.info( "Sending packet to host2" )
Jon Hallfc951072017-05-24 15:55:34 -0700825 main.h1.sendPacket()
GlennRC956ea742015-11-05 16:14:15 -0800826
827 main.log.info( "Checking filter for our packet" )
Jon Hallfc951072017-05-24 15:55:34 -0700828 stepResult = main.h2.checkFilter()
GlennRC956ea742015-11-05 16:14:15 -0800829 if stepResult:
Jon Hallfc951072017-05-24 15:55:34 -0700830 main.log.info( "Packet: %s" % main.h2.readPackets() )
831 else:
832 main.h2.killFilter()
GlennRC956ea742015-11-05 16:14:15 -0800833
GlennRC956ea742015-11-05 16:14:15 -0800834 utilities.assert_equals( expect=main.TRUE,
835 actual=stepResult,
836 onpass="Successfully sent a packet",
837 onfail="Failed to send a packet" )
838
alisone14d7b02016-07-06 10:31:51 -0700839 def CASE1900( self, main ):
Jon Hallfc951072017-05-24 15:55:34 -0700840 """
alisone14d7b02016-07-06 10:31:51 -0700841 Add flows with a ICMPv4 selector and verify the flow
Jon Hallfc951072017-05-24 15:55:34 -0700842 """
GlennRC956ea742015-11-05 16:14:15 -0800843 import json
alisone14d7b02016-07-06 10:31:51 -0700844 import time
GlennRC956ea742015-11-05 16:14:15 -0800845
alisone14d7b02016-07-06 10:31:51 -0700846 main.case( "Verify the ICMPv4 selector is correctly compiled on the flow" )
847 main.caseExplanation = "Install a flow with only the ICMPv4 selector " +\
848 "specified, verify the flow is added in ONOS, and finally " +\
849 "send a IMCPv4 packet to verify the ICMPv4 selector is compiled correctly."
GlennRC956ea742015-11-05 16:14:15 -0800850
alisone14d7b02016-07-06 10:31:51 -0700851 main.step( "Add a flow with a ICMPv4 selector" )
852
You Wangdafb6e22018-01-22 17:01:00 -0800853 for host in main.scapyHosts:
854 host.stopScapy()
Jon Hallfc951072017-05-24 15:55:34 -0700855 host.startScapy()
856 host.updateSelf()
You Wangdafb6e22018-01-22 17:01:00 -0800857 main.log.debug( host.name )
858 main.log.debug( host.hostIp )
859 main.log.debug( host.hostMac )
alisone14d7b02016-07-06 10:31:51 -0700860
861 # Add a flow that connects host1 on port1 to host2 on port2
862 egress = 2
863 ingress = 1
864 # IPv4 etherType
865 ethType = main.params[ 'TEST' ][ 'ip4Type' ]
866 # IP protocol
867 ipProto = main.params[ 'TEST' ][ 'icmpProto' ]
Devin Lim142b5342017-07-20 15:22:39 -0700868 ctrl = main.Cluster.active( 0 )
alisone14d7b02016-07-06 10:31:51 -0700869 main.log.info( "Add a flow that connects host1 on port1 to host2 on port2" )
Devin Lim142b5342017-07-20 15:22:39 -0700870 stepResult = ctrl.REST.addFlow( deviceId=main.swDPID,
871 egressPort=egress,
872 ingressPort=ingress,
873 ethType=ethType,
874 ipProto=ipProto,
875 debug=main.debug )
alisone14d7b02016-07-06 10:31:51 -0700876
877 utilities.assert_equals( expect=main.TRUE,
878 actual=stepResult,
879 onpass="Successfully added flows",
880 onfail="Failed add flows" )
881
882 # Giving ONOS time to add the flow
883 time.sleep( main.addFlowSleep )
884
Devin Lim58046fa2017-07-05 16:55:00 -0700885 main.checkingFlow.checkFlow()
alisone14d7b02016-07-06 10:31:51 -0700886
887 main.step( "Send a packet to verify the flow is correct" )
888
889 main.log.info( "Constructing packet" )
890 # No need for the MAC src dst
891 main.h1.buildEther( dst=main.h2.hostMac )
892 main.h1.buildIP( dst=main.h2.hostIp )
Jon Hallfc951072017-05-24 15:55:34 -0700893 main.h1.buildICMP()
alisone14d7b02016-07-06 10:31:51 -0700894
895 main.log.info( "Starting filter on host2" )
896 # Defaults to ip
897 main.h2.startFilter( pktFilter="icmp" )
898
899 main.log.info( "Sending packet to host2" )
Jon Hallfc951072017-05-24 15:55:34 -0700900 main.h1.sendPacket()
alisone14d7b02016-07-06 10:31:51 -0700901
902 main.log.info( "Checking filter for our packet" )
Jon Hallfc951072017-05-24 15:55:34 -0700903 stepResult = main.h2.checkFilter()
alisone14d7b02016-07-06 10:31:51 -0700904 if stepResult:
Jon Hallfc951072017-05-24 15:55:34 -0700905 main.log.info( "Packet: %s" % main.h2.readPackets() )
906 else:
907 main.h2.killFilter()
alisone14d7b02016-07-06 10:31:51 -0700908
alisone14d7b02016-07-06 10:31:51 -0700909 utilities.assert_equals( expect=main.TRUE,
910 actual=stepResult,
911 onpass="Successfully sent a packet",
912 onfail="Failed to send a packet" )
913
914 def CASE2000( self, main ):
Jon Hallfc951072017-05-24 15:55:34 -0700915 """
alisone14d7b02016-07-06 10:31:51 -0700916 Add flows with a ICMPv6 selector and verify the flow
Jon Hallfc951072017-05-24 15:55:34 -0700917 """
alisone14d7b02016-07-06 10:31:51 -0700918 import json
919 import time
920
921 main.case( "Verify the ICMPv6 selector is correctly compiled on the flow" )
922 main.caseExplanation = "Install a flow with only the ICMPv6 selector " +\
923 "specified, verify the flow is added in ONOS, and finally " +\
924 "send a IMCPv6 packet to verify the ICMPv6 selector is compiled correctly."
925
926 main.step( "Add a flow with a ICMPv6 selector" )
927
You Wangdafb6e22018-01-22 17:01:00 -0800928 for host in main.scapyHosts:
929 host.stopScapy()
Jon Hallfc951072017-05-24 15:55:34 -0700930 host.startScapy()
alisone14d7b02016-07-06 10:31:51 -0700931 host.updateSelf( IPv6=True )
You Wangdafb6e22018-01-22 17:01:00 -0800932 main.log.debug( host.name )
933 main.log.debug( host.hostIp )
934 main.log.debug( host.hostMac )
alisone14d7b02016-07-06 10:31:51 -0700935
936 # Add a flow that connects host1 on port1 to host2 on port2
Jon Hallfc951072017-05-24 15:55:34 -0700937 egress = 6
938 ingress = 5
alisone14d7b02016-07-06 10:31:51 -0700939 # IPv6 etherType
940 ethType = main.params[ 'TEST' ][ 'ip6Type' ]
941 # IP protocol
942 ipProto = main.params[ 'TEST' ][ 'icmp6Proto' ]
Devin Lim142b5342017-07-20 15:22:39 -0700943 ctrl = main.Cluster.active( 0 )
alisone14d7b02016-07-06 10:31:51 -0700944 main.log.info( "Add a flow that connects host1 on port1 to host2 on port2" )
Devin Lim142b5342017-07-20 15:22:39 -0700945 stepResult = ctrl.REST.addFlow( deviceId=main.swDPID,
946 egressPort=egress,
947 ingressPort=ingress,
948 ethType=ethType,
949 ipProto=ipProto,
950 debug=main.debug )
alisone14d7b02016-07-06 10:31:51 -0700951
952 utilities.assert_equals( expect=main.TRUE,
953 actual=stepResult,
954 onpass="Successfully added flows",
955 onfail="Failed add flows" )
956
957 # Giving ONOS time to add the flow
958 time.sleep( main.addFlowSleep )
959
Devin Lim58046fa2017-07-05 16:55:00 -0700960 main.checkingFlow.checkFlow()
alisone14d7b02016-07-06 10:31:51 -0700961
962 main.step( "Send a packet to verify the flow is correct" )
963
964 main.log.info( "Constructing packet" )
965 # No need for the MAC src dst
966 main.h5.buildEther( dst=main.h6.hostMac )
967 main.h5.buildIPv6( dst=main.h6.hostIp )
968 main.h5.buildICMP( ipVersion=6 )
969
970 main.log.info( "Starting filter on host2" )
971 # Defaults to ip
972 main.h6.startFilter( pktFilter="icmp6" )
973
974 main.log.info( "Sending packet to host2" )
Jon Hallfc951072017-05-24 15:55:34 -0700975 main.h5.sendPacket()
alisone14d7b02016-07-06 10:31:51 -0700976
977 main.log.info( "Checking filter for our packet" )
Jon Hallfc951072017-05-24 15:55:34 -0700978 stepResult = main.h6.checkFilter()
alisone14d7b02016-07-06 10:31:51 -0700979 if stepResult:
Jon Hallfc951072017-05-24 15:55:34 -0700980 main.log.info( "Packet: %s" % main.h6.readPackets() )
981 else:
982 main.h6.killFilter()
alisone14d7b02016-07-06 10:31:51 -0700983
alisone14d7b02016-07-06 10:31:51 -0700984 utilities.assert_equals( expect=main.TRUE,
985 actual=stepResult,
986 onpass="Successfully sent a packet",
987 onfail="Failed to send a packet" )
988
989 def CASE3000( self, main ):
Jon Hallfc951072017-05-24 15:55:34 -0700990 """
alisone14d7b02016-07-06 10:31:51 -0700991 Delete flow
Jon Hallfc951072017-05-24 15:55:34 -0700992 """
alisone14d7b02016-07-06 10:31:51 -0700993 import json
994
995 main.case( "Delete flows that were added through rest" )
996 main.step( "Deleting flows" )
Devin Lim142b5342017-07-20 15:22:39 -0700997 ctrl = main.Cluster.active( 0 )
alisone14d7b02016-07-06 10:31:51 -0700998 main.log.info( "Getting flows" )
999 try:
Devin Lim142b5342017-07-20 15:22:39 -07001000 flows = json.loads( ctrl.REST.flows() )
alisone14d7b02016-07-06 10:31:51 -07001001
1002 stepResult = main.TRUE
1003 for f in flows:
1004 if "rest" in f.get( "appId" ):
Jon Hallfc951072017-05-24 15:55:34 -07001005 if main.debug:
Devin Lim142b5342017-07-20 15:22:39 -07001006 main.log.debug( "Flow to be deleted:\n{}".format( ctrl.REST.pprint( f ) ) )
1007 stepResult = stepResult and ctrl.REST.removeFlow( f.get( "deviceId" ), f.get( "id" ) )
alisone14d7b02016-07-06 10:31:51 -07001008 except TypeError:
1009 main.log.error( "No Flows found by the REST API" )
1010 stepResult = main.FALSE
1011 except ValueError:
1012 main.log.error( "Problem getting Flows state from REST API. Exiting test" )
Devin Lim44075962017-08-11 10:56:37 -07001013 main.cleanAndExit()
GlennRC956ea742015-11-05 16:14:15 -08001014
1015 utilities.assert_equals( expect=main.TRUE,
1016 actual=stepResult,
1017 onpass="Successfully deleting flows",
1018 onfail="Failed to delete flows" )
1019
1020 time.sleep( main.delFlowSleep )
1021
Jon Hallfc951072017-05-24 15:55:34 -07001022 def CASE1200( self, main ):
1023 """
alisone14d7b02016-07-06 10:31:51 -07001024 Add flows with a ARP selector and verify the flow
Jon Hallfc951072017-05-24 15:55:34 -07001025 """
alisone14d7b02016-07-06 10:31:51 -07001026 import json
1027 import time
1028
1029 main.case( "Verify flow IP selectors are correctly compiled" )
1030 main.caseExplanation = "Install two flows with only IP selectors " + \
1031 "specified, then verify flows are added in ONOS, finally " + \
1032 "send a packet that only specifies the IP src and dst."
1033
1034 main.step( "Add flows with ARP addresses as the only selectors" )
1035
You Wangdafb6e22018-01-22 17:01:00 -08001036 for host in main.scapyHosts:
1037 host.stopScapy()
Jon Hallfc951072017-05-24 15:55:34 -07001038 host.startScapy()
1039 host.updateSelf()
You Wangdafb6e22018-01-22 17:01:00 -08001040 main.log.debug( host.name )
1041 main.log.debug( host.hostIp )
1042 main.log.debug( host.hostMac )
1043
Devin Lim142b5342017-07-20 15:22:39 -07001044 ctrl = main.Cluster.active( 0 )
alisone14d7b02016-07-06 10:31:51 -07001045 # Add a flow that connects host1 on port1 to host2 on port2
1046 # send output on port2
1047 # recieve input on port1
1048 egress = 2
1049 ingress = 1
1050 # ARP etherType = 0x0806
1051 ethType = main.params[ 'TEST' ][ 'arpType' ]
1052
1053 # Add flows that connects host1 to host2
1054 main.log.info( "Add flow with port ingress 1 to port egress 2" )
Devin Lim142b5342017-07-20 15:22:39 -07001055 stepResult = ctrl.REST.addFlow( deviceId=main.swDPID,
1056 egressPort=egress,
1057 ingressPort=ingress,
1058 ethType=ethType,
1059 priority=40001,
1060 debug=main.debug )
alisone14d7b02016-07-06 10:31:51 -07001061
1062 utilities.assert_equals( expect=main.TRUE,
1063 actual=stepResult,
1064 onpass="Successfully added flows",
1065 onfail="Failed add flows" )
1066
1067 # Giving ONOS time to add the flow
1068 time.sleep( main.addFlowSleep )
1069
Devin Lim58046fa2017-07-05 16:55:00 -07001070 main.checkingFlow.checkFlow()
alisone14d7b02016-07-06 10:31:51 -07001071
1072 main.step( "Send a packet to verify the flow is correct" )
1073
1074 main.log.info( "Constructing packet" )
1075 # No need for the MAC src dst
1076 main.h1.buildEther( src=main.h1.hostMac, dst=main.h2.hostMac )
1077 main.h1.buildARP( pdst=main.h2.hostIp )
1078
1079 main.log.info( "Starting filter on host2" )
1080 # Defaults to ip
1081 main.h2.startFilter( pktFilter="arp" )
1082
1083 main.log.info( "Sending packet to host2" )
Jon Hallfc951072017-05-24 15:55:34 -07001084 main.h1.sendPacket()
alisone14d7b02016-07-06 10:31:51 -07001085
1086 main.log.info( "Checking filter for our packet" )
Jon Hallfc951072017-05-24 15:55:34 -07001087 stepResult = main.h2.checkFilter()
alisone14d7b02016-07-06 10:31:51 -07001088 if stepResult:
Jon Hallfc951072017-05-24 15:55:34 -07001089 main.log.info( "Packet: %s" % main.h2.readPackets() )
alisone14d7b02016-07-06 10:31:51 -07001090 else:
Jon Hallfc951072017-05-24 15:55:34 -07001091 main.h2.killFilter()
alisone14d7b02016-07-06 10:31:51 -07001092
alisone14d7b02016-07-06 10:31:51 -07001093 utilities.assert_equals( expect=main.TRUE,
1094 actual=stepResult,
1095 onpass="Successfully sent a packet",
1096 onfail="Failed to send a packet" )
1097
1098 def CASE1800( self, main ):
Jon Hallfc951072017-05-24 15:55:34 -07001099 """
alisone14d7b02016-07-06 10:31:51 -07001100 Add flows with a SCTP selector and verify the flow
Jon Hallfc951072017-05-24 15:55:34 -07001101 """
alisone14d7b02016-07-06 10:31:51 -07001102 import json
1103 import time
1104
1105 main.case( "Verify the UDP selector is correctly compiled on the flow" )
1106 main.caseExplanation = "Install a flow with only the UDP selector " + \
1107 "specified, verify the flow is added in ONOS, and finally " + \
1108 "send a UDP packet to verify the UDP selector is compiled correctly."
1109
1110 main.step( "Add a flow with a SCTP selector" )
1111
You Wangdafb6e22018-01-22 17:01:00 -08001112 for host in main.scapyHosts:
1113 host.stopScapy()
Jon Hallfc951072017-05-24 15:55:34 -07001114 host.startScapy()
1115 host.updateSelf()
You Wangdafb6e22018-01-22 17:01:00 -08001116 main.log.debug( host.name )
1117 main.log.debug( host.hostIp )
1118 main.log.debug( host.hostMac )
alisone14d7b02016-07-06 10:31:51 -07001119
1120 # Add a flow that connects host1 on port1 to host2 on port2
1121 egress = 2
1122 ingress = 1
1123 # IPv4 etherType
1124 ethType = main.params[ 'TEST' ][ 'ip4Type' ]
1125 # IP protocol
1126 ipProto = main.params[ 'TEST' ][ 'sctpProto' ]
Devin Lim142b5342017-07-20 15:22:39 -07001127 ctrl = main.Cluster.active( 0 )
Jon Hallfc951072017-05-24 15:55:34 -07001128 main.log.info( "Add a flow that connects host1 on port1 to host2 on port2" )
Devin Lim142b5342017-07-20 15:22:39 -07001129 stepResult = ctrl.REST.addFlow( deviceId=main.swDPID,
1130 egressPort=egress,
1131 ingressPort=ingress,
1132 ethType=ethType,
1133 ipProto=ipProto,
1134 debug=main.debug )
alisone14d7b02016-07-06 10:31:51 -07001135
1136 utilities.assert_equals( expect=main.TRUE,
1137 actual=stepResult,
1138 onpass="Successfully added flows",
1139 onfail="Failed add flows" )
1140
1141 # Giving ONOS time to add the flow
1142 time.sleep( main.addFlowSleep )
1143
Devin Lim58046fa2017-07-05 16:55:00 -07001144 main.checkingFlow.checkFlow()
alisone14d7b02016-07-06 10:31:51 -07001145
1146 main.step( "Send a packet to verify the flow is correct" )
1147
1148 main.log.info( "Constructing packet" )
1149 # No need for the MAC src dst
1150 main.h1.buildEther( dst=main.h2.hostMac )
1151 main.h1.buildIP( dst=main.h2.hostIp )
Jon Hallfc951072017-05-24 15:55:34 -07001152 main.h1.buildSCTP()
alisone14d7b02016-07-06 10:31:51 -07001153
1154 main.log.info( "Starting filter on host2" )
1155 # Defaults to ip
1156 main.h2.startFilter( pktFilter="sctp" )
1157
1158 main.log.info( "Sending packet to host2" )
Jon Hallfc951072017-05-24 15:55:34 -07001159 main.h1.sendPacket()
alisone14d7b02016-07-06 10:31:51 -07001160
1161 main.log.info( "Checking filter for our packet" )
Jon Hallfc951072017-05-24 15:55:34 -07001162 stepResult = main.h2.checkFilter()
alisone14d7b02016-07-06 10:31:51 -07001163 if stepResult:
Jon Hallfc951072017-05-24 15:55:34 -07001164 main.log.info( "Packet: %s" % main.h2.readPackets() )
alisone14d7b02016-07-06 10:31:51 -07001165 else:
Jon Hallfc951072017-05-24 15:55:34 -07001166 main.h2.killFilter()
alisone14d7b02016-07-06 10:31:51 -07001167
alisone14d7b02016-07-06 10:31:51 -07001168 utilities.assert_equals( expect=main.TRUE,
1169 actual=stepResult,
1170 onpass="Successfully sent a packet",
1171 onfail="Failed to send a packet" )
1172
GlennRC68449942015-10-16 16:03:12 -07001173 def CASE100( self, main ):
Jon Hallfc951072017-05-24 15:55:34 -07001174 """
GlennRC5147a422015-10-06 17:26:17 -07001175 Report errors/warnings/exceptions
Jon Hallfc951072017-05-24 15:55:34 -07001176 """
alisone14d7b02016-07-06 10:31:51 -07001177 main.log.info( "Error report: \n" )
Devin Lim142b5342017-07-20 15:22:39 -07001178 main.ONOSbench.logReport( main.Cluster.active( 0 ).ipAddress,
GlennRC5147a422015-10-06 17:26:17 -07001179 [ "INFO",
1180 "FOLLOWER",
1181 "WARN",
1182 "flow",
1183 "ERROR",
1184 "Except" ],
GlennRC68449942015-10-16 16:03:12 -07001185 "s" )