blob: 0b024653845bf6b5677d85ffe15063a3f7a66f05 [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' ]
Devin Lim58046fa2017-07-05 16:55:00 -070058 main.startUpSleep = int( main.params[ 'SLEEP' ][ 'startup' ] )
59 main.startMNSleep = int( main.params[ 'SLEEP' ][ 'startMN' ] )
60 main.addFlowSleep = int( main.params[ 'SLEEP' ][ 'addFlow' ] )
61 main.delFlowSleep = int( main.params[ 'SLEEP' ][ 'delFlow' ] )
62 main.debug = main.params[ 'DEBUG' ]
63 main.swDPID = main.params[ 'TEST' ][ 'swDPID' ]
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
74 main.log.error("CheckingFlow not found exiting the test")
75 main.exit()
76 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
93 def CASE2( self, main ):
94 """
95 - Set up cell
96 - Create cell file
97 - Set cell file
98 - Verify cell file
Devin Lim58046fa2017-07-05 16:55:00 -070099 - Building ONOS
100 - Install ONOS package
101 - Build ONOS package
GlennRC5147a422015-10-06 17:26:17 -0700102 - Kill ONOS process
103 - Uninstall ONOS cluster
104 - Verify ONOS start up
105 - Install ONOS cluster
106 - Connect to cli
107 """
Devin Lim142b5342017-07-20 15:22:39 -0700108 main.testSetUp.ONOSSetUp( main.Mininet1, main.Cluster )
GlennRC5147a422015-10-06 17:26:17 -0700109
GlennRC68449942015-10-16 16:03:12 -0700110 def CASE10( self, main ):
Jon Hallfc951072017-05-24 15:55:34 -0700111 """
GlennRC68449942015-10-16 16:03:12 -0700112 Start Mininet
Jon Hallfc951072017-05-24 15:55:34 -0700113 """
GlennRC073e8bc2015-10-27 17:11:28 -0700114 import json
Devin Lim58046fa2017-07-05 16:55:00 -0700115 import time
116 try:
117 from tests.dependencies.topology import Topology
118 except ImportError:
119 main.log.error( "Topology not found exiting the test" )
120 main.exit()
121 try:
122 main.topoRelated
123 except ( NameError, AttributeError ):
124 main.topoRelated = Topology()
GlennRC073e8bc2015-10-27 17:11:28 -0700125
126 main.case( "Setup mininet and compare ONOS topology view to Mininet topology" )
127 main.caseExplanation = "Start mininet with custom topology and compare topology " +\
128 "elements between Mininet and ONOS"
129
GlennRC68449942015-10-16 16:03:12 -0700130 main.step( "Setup Mininet Topology" )
131 topology = main.Mininet1.home + '/custom/' + main.topology
Jon Hallfc951072017-05-24 15:55:34 -0700132 stepResult = main.Mininet1.startNet( topoFile=topology )
GlennRC68449942015-10-16 16:03:12 -0700133
134 utilities.assert_equals( expect=main.TRUE,
GlennRC073e8bc2015-10-27 17:11:28 -0700135 actual=stepResult,
GlennRC68449942015-10-16 16:03:12 -0700136 onpass="Successfully loaded topology",
137 onfail="Failed to load topology" )
138
GlennRC073e8bc2015-10-27 17:11:28 -0700139 main.step( "Assign switch to controller" )
Devin Lim142b5342017-07-20 15:22:39 -0700140 stepResult = main.Mininet1.assignSwController( "s1", main.Cluster.active( 0 ).ipAddress )
GlennRC68449942015-10-16 16:03:12 -0700141
142 utilities.assert_equals( expect=main.TRUE,
GlennRC073e8bc2015-10-27 17:11:28 -0700143 actual=stepResult,
144 onpass="Successfully assigned switch to controller",
145 onfail="Failed to assign switch to controller" )
GlennRC68449942015-10-16 16:03:12 -0700146
GlennRC073e8bc2015-10-27 17:11:28 -0700147 time.sleep( main.startMNSleep )
GlennRC68449942015-10-16 16:03:12 -0700148
Devin Lim58046fa2017-07-05 16:55:00 -0700149 main.topoRelated.compareTopos( main.Mininet1 )
GlennRC68449942015-10-16 16:03:12 -0700150
Jon Hall892818c2015-10-20 17:58:34 -0700151 def CASE66( self, main ):
Jon Hallfc951072017-05-24 15:55:34 -0700152 """
Jon Hall892818c2015-10-20 17:58:34 -0700153 Testing scapy
Jon Hallfc951072017-05-24 15:55:34 -0700154 """
Jon Hall892818c2015-10-20 17:58:34 -0700155 main.case( "Testing scapy" )
156 main.step( "Creating Host1 component" )
Jon Halla510a8a2016-05-04 15:09:28 -0700157 main.Scapy.createHostComponent( "h1" )
158 main.Scapy.createHostComponent( "h2" )
alisone14d7b02016-07-06 10:31:51 -0700159 hosts = [ main.h1, main.h2 ]
Jon Hall892818c2015-10-20 17:58:34 -0700160 for host in hosts:
Jon Hallfc951072017-05-24 15:55:34 -0700161 host.startHostCli()
162 host.startScapy()
163 host.updateSelf()
Jon Hall892818c2015-10-20 17:58:34 -0700164 main.log.debug( host.name )
165 main.log.debug( host.hostIp )
166 main.log.debug( host.hostMac )
167
168 main.step( "Sending/Receiving Test packet - Filter doesn't match" )
Jon Halla510a8a2016-05-04 15:09:28 -0700169 main.log.info( "Starting Filter..." )
Jon Hallfc951072017-05-24 15:55:34 -0700170 main.h2.startFilter()
Jon Halla510a8a2016-05-04 15:09:28 -0700171 main.log.info( "Building Ether frame..." )
Jon Hall892818c2015-10-20 17:58:34 -0700172 main.h1.buildEther( dst=main.h2.hostMac )
Jon Halla510a8a2016-05-04 15:09:28 -0700173 main.log.info( "Sending Packet..." )
Jon Hallfc951072017-05-24 15:55:34 -0700174 main.h1.sendPacket()
Jon Halla510a8a2016-05-04 15:09:28 -0700175 main.log.info( "Checking Filter..." )
Jon Hallfc951072017-05-24 15:55:34 -0700176 finished = main.h2.checkFilter()
Jon Halla510a8a2016-05-04 15:09:28 -0700177 main.log.debug( finished )
Jon Hall892818c2015-10-20 17:58:34 -0700178 i = ""
179 if finished:
Jon Hallfc951072017-05-24 15:55:34 -0700180 a = main.h2.readPackets()
181 for i in a.splitlines():
Jon Hall892818c2015-10-20 17:58:34 -0700182 main.log.info( i )
183 else:
Jon Hallfc951072017-05-24 15:55:34 -0700184 kill = main.h2.killFilter()
Jon Hall892818c2015-10-20 17:58:34 -0700185 main.log.debug( kill )
186 main.h2.handle.sendline( "" )
187 main.h2.handle.expect( main.h2.scapyPrompt )
188 main.log.debug( main.h2.handle.before )
189 utilities.assert_equals( expect=True,
190 actual="dst=00:00:00:00:00:02 src=00:00:00:00:00:01" in i,
191 onpass="Pass",
192 onfail="Fail" )
193
194 main.step( "Sending/Receiving Test packet - Filter matches" )
Jon Hallfc951072017-05-24 15:55:34 -0700195 main.h2.startFilter()
Jon Hall892818c2015-10-20 17:58:34 -0700196 main.h1.buildEther( dst=main.h2.hostMac )
197 main.h1.buildIP( dst=main.h2.hostIp )
Jon Hallfc951072017-05-24 15:55:34 -0700198 main.h1.sendPacket()
199 finished = main.h2.checkFilter()
Jon Hall892818c2015-10-20 17:58:34 -0700200 i = ""
201 if finished:
Jon Hallfc951072017-05-24 15:55:34 -0700202 a = main.h2.readPackets()
203 for i in a.splitlines():
Jon Hall892818c2015-10-20 17:58:34 -0700204 main.log.info( i )
205 else:
Jon Hallfc951072017-05-24 15:55:34 -0700206 kill = main.h2.killFilter()
Jon Hall892818c2015-10-20 17:58:34 -0700207 main.log.debug( kill )
208 main.h2.handle.sendline( "" )
209 main.h2.handle.expect( main.h2.scapyPrompt )
210 main.log.debug( main.h2.handle.before )
211 utilities.assert_equals( expect=True,
212 actual="dst=00:00:00:00:00:02 src=00:00:00:00:00:01" in i,
213 onpass="Pass",
214 onfail="Fail" )
215
Jon Hall892818c2015-10-20 17:58:34 -0700216 main.step( "Clean up host components" )
217 for host in hosts:
Jon Hallfc951072017-05-24 15:55:34 -0700218 host.stopScapy()
alisone14d7b02016-07-06 10:31:51 -0700219 main.Mininet1.removeHostComponent( "h1" )
220 main.Mininet1.removeHostComponent( "h2" )
Jon Hall892818c2015-10-20 17:58:34 -0700221
GlennRC68449942015-10-16 16:03:12 -0700222 def CASE1000( self, main ):
Jon Hallfc951072017-05-24 15:55:34 -0700223 """
GlennRC073e8bc2015-10-27 17:11:28 -0700224 Add flows with MAC selectors and verify the flows
Jon Hallfc951072017-05-24 15:55:34 -0700225 """
GlennRC073e8bc2015-10-27 17:11:28 -0700226 import json
227 import time
Devin Lim142b5342017-07-20 15:22:39 -0700228 ctrl = main.Cluster.active( 0 )
GlennRC073e8bc2015-10-27 17:11:28 -0700229 main.case( "Verify flow MAC selectors are correctly compiled" )
230 main.caseExplanation = "Install two flows with only MAC selectors " +\
Jon Hallfc951072017-05-24 15:55:34 -0700231 "specified, then verify flows are added in ONOS, finally " +\
GlennRC073e8bc2015-10-27 17:11:28 -0700232 "send a packet that only specifies the MAC src and dst."
GlennRC68449942015-10-16 16:03:12 -0700233
GlennRC073e8bc2015-10-27 17:11:28 -0700234 main.step( "Add flows with MAC addresses as the only selectors" )
GlennRC68449942015-10-16 16:03:12 -0700235
GlennRC073e8bc2015-10-27 17:11:28 -0700236 main.log.info( "Creating host components" )
Jon Halla510a8a2016-05-04 15:09:28 -0700237 main.Scapy.createHostComponent( "h1" )
238 main.Scapy.createHostComponent( "h2" )
alisone14d7b02016-07-06 10:31:51 -0700239 hosts = [ main.h1, main.h2 ]
GlennRC073e8bc2015-10-27 17:11:28 -0700240 for host in hosts:
Jon Hallfc951072017-05-24 15:55:34 -0700241 host.startHostCli()
242 host.startScapy()
243 host.updateSelf()
GlennRC68449942015-10-16 16:03:12 -0700244
GlennRC073e8bc2015-10-27 17:11:28 -0700245 # Add a flow that connects host1 on port1 to host2 on port2
246 # send output on port2
247 # recieve input on port1
248 egress = 2
249 ingress = 1
250
251 # Add flows that sends packets from port1 to port2 with correct
252 # MAC src and dst addresses
253 main.log.info( "Adding flow with MAC selectors" )
Devin Lim142b5342017-07-20 15:22:39 -0700254 stepResult = ctrl.REST.addFlow( deviceId=main.swDPID,
255 egressPort=egress,
256 ingressPort=ingress,
257 ethSrc=main.h1.hostMac,
258 ethDst=main.h2.hostMac,
259 debug=main.debug )
GlennRC68449942015-10-16 16:03:12 -0700260
GlennRCa5391372015-10-14 17:28:15 -0700261 utilities.assert_equals( expect=main.TRUE,
262 actual=stepResult,
GlennRC68449942015-10-16 16:03:12 -0700263 onpass="Successfully added flows",
264 onfail="Failed add flows" )
GlennRCa5391372015-10-14 17:28:15 -0700265
GlennRC073e8bc2015-10-27 17:11:28 -0700266 # Giving ONOS time to add the flows
267 time.sleep( main.addFlowSleep )
GlennRC5147a422015-10-06 17:26:17 -0700268
Devin Lim142b5342017-07-20 15:22:39 -0700269 main.checkingFlow.checkFlow()
GlennRC956ea742015-11-05 16:14:15 -0800270
GlennRC073e8bc2015-10-27 17:11:28 -0700271 main.step( "Send a packet to verify the flows are correct" )
272
273 # Specify the src and dst MAC addr
274 main.log.info( "Constructing packet" )
275 main.h1.buildEther( src=main.h1.hostMac, dst=main.h2.hostMac )
276
277 # Filter for packets with the correct host name. Otherwise,
278 # the filter we catch any packet that is sent to host2
279 # NOTE: I believe it doesn't matter which host name it is,
GlennRC956ea742015-11-05 16:14:15 -0800280 # as long as the src and dst are both specified
GlennRC073e8bc2015-10-27 17:11:28 -0700281 main.log.info( "Starting filter on host2" )
alisone14d7b02016-07-06 10:31:51 -0700282 main.h2.startFilter( pktFilter="ether host %s" % main.h1.hostMac )
GlennRC073e8bc2015-10-27 17:11:28 -0700283
284 main.log.info( "Sending packet to host2" )
285 main.h1.sendPacket()
286
287 main.log.info( "Checking filter for our packet" )
Jon Hallfc951072017-05-24 15:55:34 -0700288 stepResult = main.h2.checkFilter()
GlennRC073e8bc2015-10-27 17:11:28 -0700289 if stepResult:
Jon Hallfc951072017-05-24 15:55:34 -0700290 main.log.info( "Packet: %s" % main.h2.readPackets() )
alisone14d7b02016-07-06 10:31:51 -0700291 else:
Jon Hallfc951072017-05-24 15:55:34 -0700292 main.h2.killFilter()
GlennRC073e8bc2015-10-27 17:11:28 -0700293
294 main.log.info( "Clean up host components" )
295 for host in hosts:
Jon Hallfc951072017-05-24 15:55:34 -0700296 host.stopScapy()
alisone14d7b02016-07-06 10:31:51 -0700297 main.Mininet1.removeHostComponent( "h1" )
298 main.Mininet1.removeHostComponent( "h2" )
GlennRC073e8bc2015-10-27 17:11:28 -0700299
300 utilities.assert_equals( expect=main.TRUE,
301 actual=stepResult,
302 onpass="Successfully sent a packet",
303 onfail="Failed to send a packet" )
304
alisone14d7b02016-07-06 10:31:51 -0700305 def CASE1400( self, main ):
Jon Hallfc951072017-05-24 15:55:34 -0700306 """
GlennRC073e8bc2015-10-27 17:11:28 -0700307 Add flows with IPv4 selectors and verify the flows
Jon Hallfc951072017-05-24 15:55:34 -0700308 """
GlennRC68449942015-10-16 16:03:12 -0700309 import json
GlennRC073e8bc2015-10-27 17:11:28 -0700310 import time
Devin Lim142b5342017-07-20 15:22:39 -0700311 ctrl = main.Cluster.active( 0 )
GlennRC073e8bc2015-10-27 17:11:28 -0700312 main.case( "Verify flow IP selectors are correctly compiled" )
313 main.caseExplanation = "Install two flows with only IP selectors " +\
alisone14d7b02016-07-06 10:31:51 -0700314 "specified, then verify flows are added in ONOS, finally " +\
GlennRC073e8bc2015-10-27 17:11:28 -0700315 "send a packet that only specifies the IP src and dst."
316
317 main.step( "Add flows with IPv4 addresses as the only selectors" )
318
319 main.log.info( "Creating host components" )
Jon Halla510a8a2016-05-04 15:09:28 -0700320 main.Scapy.createHostComponent( "h1" )
321 main.Scapy.createHostComponent( "h2" )
alisone14d7b02016-07-06 10:31:51 -0700322 hosts = [ main.h1, main.h2 ]
GlennRC073e8bc2015-10-27 17:11:28 -0700323 for host in hosts:
Jon Hallfc951072017-05-24 15:55:34 -0700324 host.startHostCli()
325 host.startScapy()
326 host.updateSelf()
GlennRC073e8bc2015-10-27 17:11:28 -0700327
328 # Add a flow that connects host1 on port1 to host2 on port2
329 # send output on port2
330 # recieve input on port1
331 egress = 2
332 ingress = 1
333 # IPv4 etherType = 0x800
alisone14d7b02016-07-06 10:31:51 -0700334 ethType = main.params[ 'TEST' ][ 'ip4Type' ]
GlennRC073e8bc2015-10-27 17:11:28 -0700335
336 # Add flows that connects host1 to host2
337 main.log.info( "Add flow with port ingress 1 to port egress 2" )
Devin Lim142b5342017-07-20 15:22:39 -0700338 stepResult = ctrl.REST.addFlow( deviceId=main.swDPID,
339 egressPort=egress,
340 ingressPort=ingress,
341 ethType=ethType,
342 ipSrc=( "IPV4_SRC", main.h1.hostIp + "/32" ),
343 ipDst=( "IPV4_DST", main.h2.hostIp + "/32" ),
344 debug=main.debug )
GlennRC073e8bc2015-10-27 17:11:28 -0700345
346 utilities.assert_equals( expect=main.TRUE,
347 actual=stepResult,
348 onpass="Successfully added flows",
349 onfail="Failed add flows" )
350
351 # Giving ONOS time to add the flow
352 time.sleep( main.addFlowSleep )
353
Devin Lim58046fa2017-07-05 16:55:00 -0700354 main.checkingFlow.checkFlow()
GlennRC956ea742015-11-05 16:14:15 -0800355
GlennRC073e8bc2015-10-27 17:11:28 -0700356 main.step( "Send a packet to verify the flow is correct" )
357
358 main.log.info( "Constructing packet" )
359 # No need for the MAC src dst
360 main.h1.buildEther( dst=main.h2.hostMac )
361 main.h1.buildIP( src=main.h1.hostIp, dst=main.h2.hostIp )
362
363 main.log.info( "Starting filter on host2" )
364 # Defaults to ip
Jon Hallfc951072017-05-24 15:55:34 -0700365 main.h2.startFilter()
GlennRC073e8bc2015-10-27 17:11:28 -0700366
367 main.log.info( "Sending packet to host2" )
Jon Hallfc951072017-05-24 15:55:34 -0700368 main.h1.sendPacket()
GlennRC073e8bc2015-10-27 17:11:28 -0700369
370 main.log.info( "Checking filter for our packet" )
Jon Hallfc951072017-05-24 15:55:34 -0700371 stepResult = main.h2.checkFilter()
GlennRC073e8bc2015-10-27 17:11:28 -0700372 if stepResult:
Jon Hallfc951072017-05-24 15:55:34 -0700373 main.log.info( "Packet: %s" % main.h2.readPackets() )
374 else:
375 main.h2.killFilter()
GlennRC073e8bc2015-10-27 17:11:28 -0700376
377 main.log.info( "Clean up host components" )
378 for host in hosts:
Jon Hallfc951072017-05-24 15:55:34 -0700379 host.stopScapy()
alisone14d7b02016-07-06 10:31:51 -0700380 main.Mininet1.removeHostComponent( "h1" )
381 main.Mininet1.removeHostComponent( "h2" )
GlennRC073e8bc2015-10-27 17:11:28 -0700382
383 utilities.assert_equals( expect=main.TRUE,
384 actual=stepResult,
385 onpass="Successfully sent a packet",
386 onfail="Failed to send a packet" )
387
Jon Hallfc951072017-05-24 15:55:34 -0700388 def CASE1500( self, main ):
alisone14d7b02016-07-06 10:31:51 -0700389 """
390 Add flow with IPv6 selector and verify the flow
391 """
392 import json
393 import time
394 main.case( "Verify IPv6 selector is correctly compiled" )
395 main.caseExplanation = "Install two flows with only IP selectors " + \
396 "specified, then verify flows are added in ONOS, finally " + \
397 "send a packet that only specifies the IP src and dst."
398
399 main.step( "Add flows with IPv6 addresses as the only selectors" )
400
401 main.log.info( "Creating host components" )
Devin Lim142b5342017-07-20 15:22:39 -0700402 ctrl = main.Cluster.active( 0 )
alisone14d7b02016-07-06 10:31:51 -0700403 main.Scapy.createHostComponent( "h5" )
404 main.Scapy.createHostComponent( "h6" )
405 hosts = [ main.h5, main.h6 ]
406
407 for host in hosts:
Jon Hallfc951072017-05-24 15:55:34 -0700408 host.startHostCli()
409 host.startScapy()
alisone14d7b02016-07-06 10:31:51 -0700410 host.updateSelf( IPv6=True )
411
412 # Add a flow that connects host1 on port1 to host2 on port2
413 # send output on port2
414 # recieve input on port1
415 egress = 6
416 ingress = 5
417 # IPv6 etherType = 0x86DD
418 ethType = main.params[ 'TEST' ][ 'ip6Type' ]
419
420 # Add flows that connects host1 to host2
421 main.log.info( "Add flow with port ingress 5 to port egress 6" )
Devin Lim142b5342017-07-20 15:22:39 -0700422 stepResult = ctrl.REST.addFlow( deviceId=main.swDPID,
423 egressPort=egress,
424 ingressPort=ingress,
425 ethType=ethType,
426 ipSrc=( "IPV6_SRC", main.h5.hostIp + "/128" ),
427 ipDst=( "IPV6_DST", main.h6.hostIp + "/128" ),
428 debug=main.debug )
alisone14d7b02016-07-06 10:31:51 -0700429
430 utilities.assert_equals( expect=main.TRUE,
431 actual=stepResult,
432 onpass="Successfully added flows",
433 onfail="Failed add flows" )
434
435 # Giving ONOS time to add the flow
436 time.sleep( main.addFlowSleep )
437
Devin Lim58046fa2017-07-05 16:55:00 -0700438 main.checkingFlow.checkFlow()
alisone14d7b02016-07-06 10:31:51 -0700439
440 main.step( "Send a packet to verify the flow is correct" )
441
442 main.log.info( "Constructing packet" )
443 # No need for the MAC src dst
444 main.h5.buildEther( dst=main.h6.hostMac )
445 main.h5.buildIPv6( src=main.h5.hostIp, dst=main.h6.hostIp )
446
447 main.log.info( "Starting filter on host6" )
448 # Defaults to ip
449 main.h6.startFilter( pktFilter="ip6" )
450 main.log.info( "Sending packet to host6" )
Jon Hallfc951072017-05-24 15:55:34 -0700451 main.h5.sendPacket()
alisone14d7b02016-07-06 10:31:51 -0700452
453 main.log.info( "Checking filter for our packet" )
Jon Hallfc951072017-05-24 15:55:34 -0700454 stepResult = main.h6.checkFilter()
alisone14d7b02016-07-06 10:31:51 -0700455 if stepResult:
Jon Hallfc951072017-05-24 15:55:34 -0700456 main.log.info( "Packet: %s" % main.h6.readPackets() )
alisone14d7b02016-07-06 10:31:51 -0700457 else:
Jon Hallfc951072017-05-24 15:55:34 -0700458 main.h6.killFilter()
alisone14d7b02016-07-06 10:31:51 -0700459
460 main.log.info( "Clean up host components" )
461 for host in hosts:
Jon Hallfc951072017-05-24 15:55:34 -0700462 host.stopScapy()
alisone14d7b02016-07-06 10:31:51 -0700463 main.Mininet1.removeHostComponent( "h5" )
464 main.Mininet1.removeHostComponent( "h6" )
465
466 utilities.assert_equals( expect=main.TRUE,
467 actual=stepResult,
468 onpass="Successfully sent a packet",
469 onfail="Failed to send a packet" )
470
alisone14d7b02016-07-06 10:31:51 -0700471 def CASE1100( self, main ):
Jon Hallfc951072017-05-24 15:55:34 -0700472 """
GlennRC073e8bc2015-10-27 17:11:28 -0700473 Add flow with VLAN selector and verify the flow
Jon Hallfc951072017-05-24 15:55:34 -0700474 """
GlennRC073e8bc2015-10-27 17:11:28 -0700475 import json
476 import time
477
478 main.case( "Verify VLAN selector is correctly compiled" )
479 main.caseExplanation = "Install one flow with only the VLAN selector " +\
Jon Hallfc951072017-05-24 15:55:34 -0700480 "specified, then verify the flow is added in ONOS, and finally " +\
GlennRC073e8bc2015-10-27 17:11:28 -0700481 "broadcast a packet with the correct VLAN tag."
482
483 # We do this here to utilize the hosts information
484 main.log.info( "Creating host components" )
Devin Lim142b5342017-07-20 15:22:39 -0700485 ctrl = main.Cluster.active( 0 )
Jon Halla510a8a2016-05-04 15:09:28 -0700486 main.Scapy.createHostComponent( "h3" )
487 main.Scapy.createHostComponent( "h4" )
alisone14d7b02016-07-06 10:31:51 -0700488 hosts = [ main.h3, main.h4 ]
GlennRC073e8bc2015-10-27 17:11:28 -0700489 for host in hosts:
Jon Hallfc951072017-05-24 15:55:34 -0700490 host.startHostCli()
491 host.startScapy()
492 host.updateSelf()
GlennRC073e8bc2015-10-27 17:11:28 -0700493
494 main.step( "Add a flow with the VLAN tag as the only selector" )
495
496 # Add flows that connects the two vlan hosts h3 and h4
497 # Host 3 is on port 3 and host 4 is on port 4
498 vlan = main.params[ 'TEST' ][ 'vlan' ]
499 egress = 4
500 ingress = 3
501 # VLAN ethType = 0x8100
alisone14d7b02016-07-06 10:31:51 -0700502 ethType = main.params[ 'TEST' ][ 'vlanType' ]
GlennRC073e8bc2015-10-27 17:11:28 -0700503
504 # Add only one flow because we don't need a response
505 main.log.info( "Add flow with port ingress 1 to port egress 2" )
Devin Lim142b5342017-07-20 15:22:39 -0700506 stepResult = ctrl.REST.addFlow( deviceId=main.swDPID,
507 egressPort=egress,
508 ingressPort=ingress,
509 ethType=ethType,
510 vlan=vlan,
511 debug=main.debug )
GlennRC073e8bc2015-10-27 17:11:28 -0700512
GlennRC073e8bc2015-10-27 17:11:28 -0700513 utilities.assert_equals( expect=main.TRUE,
514 actual=stepResult,
515 onpass="Successfully added flow",
516 onfail="Failed add flows" )
517
518 # Giving ONOS time to add the flows
519 time.sleep( main.addFlowSleep )
520
Devin Lim142b5342017-07-20 15:22:39 -0700521 main.checkingFlow.checkFlow()
GlennRC956ea742015-11-05 16:14:15 -0800522
GlennRC073e8bc2015-10-27 17:11:28 -0700523 main.step( "Send a packet to verify the flow are correct" )
524
525 # The receiving interface
alisone14d7b02016-07-06 10:31:51 -0700526 recIface = "{}-eth0.{}".format( main.h4.name, vlan )
GlennRC073e8bc2015-10-27 17:11:28 -0700527 main.log.info( "Starting filter on host2" )
528 # Filter is setup to catch any packet on the vlan interface with the correct vlan tag
Jon Hallfc951072017-05-24 15:55:34 -0700529 main.h4.startFilter( ifaceName=recIface, pktFilter="" )
GlennRC073e8bc2015-10-27 17:11:28 -0700530
531 # Broadcast the packet on the vlan interface. We only care if the flow forwards
532 # the packet with the correct vlan tag, not if the mac addr is correct
alisone14d7b02016-07-06 10:31:51 -0700533 sendIface = "{}-eth0.{}".format( main.h3.name, vlan )
GlennRC073e8bc2015-10-27 17:11:28 -0700534 main.log.info( "Broadcasting the packet with a vlan tag" )
GlennRC956ea742015-11-05 16:14:15 -0800535 main.h3.sendPacket( iface=sendIface,
alisone14d7b02016-07-06 10:31:51 -0700536 packet="Ether()/Dot1Q(vlan={})".format( vlan ) )
GlennRC073e8bc2015-10-27 17:11:28 -0700537
538 main.log.info( "Checking filter for our packet" )
Jon Hallfc951072017-05-24 15:55:34 -0700539 stepResult = main.h4.checkFilter()
GlennRC073e8bc2015-10-27 17:11:28 -0700540 if stepResult:
Jon Hallfc951072017-05-24 15:55:34 -0700541 main.log.info( "Packet: %s" % main.h4.readPackets() )
542 else:
543 main.h4.killFilter()
GlennRC073e8bc2015-10-27 17:11:28 -0700544
545 main.log.info( "Clean up host components" )
546 for host in hosts:
Jon Hallfc951072017-05-24 15:55:34 -0700547 host.stopScapy()
alisone14d7b02016-07-06 10:31:51 -0700548 main.Mininet1.removeHostComponent( "h3" )
549 main.Mininet1.removeHostComponent( "h4" )
GlennRC073e8bc2015-10-27 17:11:28 -0700550
551 utilities.assert_equals( expect=main.TRUE,
552 actual=stepResult,
553 onpass="Successfully sent a packet",
554 onfail="Failed to send a packet" )
GlennRC68449942015-10-16 16:03:12 -0700555
GlennRC956ea742015-11-05 16:14:15 -0800556 def CASE1300( self, main ):
Jon Hallfc951072017-05-24 15:55:34 -0700557 """
GlennRC956ea742015-11-05 16:14:15 -0800558 Add flows with MPLS selector and verify the flows
Jon Hallfc951072017-05-24 15:55:34 -0700559 """
GlennRC956ea742015-11-05 16:14:15 -0800560 import json
561 import time
562
563 main.case( "Verify the MPLS selector is correctly compiled on the flow." )
564 main.caseExplanation = "Install one flow with an MPLS selector, " +\
alisone14d7b02016-07-06 10:31:51 -0700565 "verify the flow is added in ONOS, and finally " +\
GlennRC956ea742015-11-05 16:14:15 -0800566 "send a packet via scapy that has a MPLS label."
567
568 main.step( "Add a flow with a MPLS selector" )
569
570 main.log.info( "Creating host components" )
Devin Lim142b5342017-07-20 15:22:39 -0700571 ctrl = main.Cluster.active( 0 )
Jon Halla510a8a2016-05-04 15:09:28 -0700572 main.Scapy.createHostComponent( "h1" )
573 main.Scapy.createHostComponent( "h2" )
alisone14d7b02016-07-06 10:31:51 -0700574 hosts = [ main.h1, main.h2 ]
GlennRC956ea742015-11-05 16:14:15 -0800575 for host in hosts:
Jon Hallfc951072017-05-24 15:55:34 -0700576 host.startHostCli()
GlennRC956ea742015-11-05 16:14:15 -0800577 host.startScapy( main.dependencyPath )
Jon Hallfc951072017-05-24 15:55:34 -0700578 host.updateSelf()
GlennRC956ea742015-11-05 16:14:15 -0800579
580 # ports
581 egress = 2
582 ingress = 1
583 # MPLS etherType
584 ethType = main.params[ 'TEST' ][ 'mplsType' ]
585 # MPLS label
586 mplsLabel = main.params[ 'TEST' ][ 'mpls' ]
587
588 # Add a flow that connects host1 on port1 to host2 on port2
589 main.log.info( "Adding flow with MPLS selector" )
Devin Lim142b5342017-07-20 15:22:39 -0700590 stepResult = ctrl.REST.addFlow( deviceId=main.swDPID,
591 egressPort=egress,
592 ingressPort=ingress,
593 ethType=ethType,
594 mpls=mplsLabel,
595 debug=main.debug )
GlennRC956ea742015-11-05 16:14:15 -0800596
597 utilities.assert_equals( expect=main.TRUE,
598 actual=stepResult,
599 onpass="Successfully added flow",
600 onfail="Failed add flow" )
601
602 # Giving ONOS time to add the flow
603 time.sleep( main.addFlowSleep )
604
605 main.step( "Check flow is in the ADDED state" )
606
607 main.log.info( "Get the flows from ONOS" )
Jeremy86160992016-04-11 10:05:53 -0700608 try:
Devin Lim142b5342017-07-20 15:22:39 -0700609 flows = json.loads( ctrl.REST.flows() )
GlennRC956ea742015-11-05 16:14:15 -0800610
Jeremy86160992016-04-11 10:05:53 -0700611 stepResult = main.TRUE
612 for f in flows:
alisone14d7b02016-07-06 10:31:51 -0700613 if "rest" in f.get( "appId" ):
614 if "ADDED" not in f.get( "state" ):
Jeremy86160992016-04-11 10:05:53 -0700615 stepResult = main.FALSE
alisone14d7b02016-07-06 10:31:51 -0700616 main.log.error( "Flow: %s in state: %s" % ( f.get( "id" ), f.get( "state" ) ) )
Jeremy86160992016-04-11 10:05:53 -0700617 except TypeError:
618 main.log.error( "No Flows found by the REST API" )
619 stepResult = main.FALSE
620 except ValueError:
621 main.log.error( "Problem getting Flows state from REST API. Exiting test" )
Jon Hallfc951072017-05-24 15:55:34 -0700622 main.cleanup()
623 main.exit()
GlennRC956ea742015-11-05 16:14:15 -0800624
625 utilities.assert_equals( expect=main.TRUE,
626 actual=stepResult,
627 onpass="All flows are in the ADDED state",
628 onfail="All flows are NOT in the ADDED state" )
629
630 main.step( "Check flows are in Mininet's flow table" )
631
632 # get the flow IDs that were added through rest
633 main.log.info( "Getting the flow IDs from ONOS" )
alisone14d7b02016-07-06 10:31:51 -0700634 flowIds = [ f.get( "id" ) for f in flows if "rest" in f.get( "appId" ) ]
GlennRC956ea742015-11-05 16:14:15 -0800635 # convert the flowIDs to ints then hex and finally back to strings
alisone14d7b02016-07-06 10:31:51 -0700636 flowIds = [ str( hex( int( x ) ) ) for x in flowIds ]
637 main.log.info( "ONOS flow IDs: {}".format( flowIds ) )
GlennRC956ea742015-11-05 16:14:15 -0800638
639 stepResult = main.Mininet1.checkFlowId( "s1", flowIds, debug=True )
640
641 utilities.assert_equals( expect=main.TRUE,
642 actual=stepResult,
643 onpass="All flows are in mininet",
644 onfail="All flows are NOT in mininet" )
645
646 main.step( "Send a packet to verify the flow is correct" )
647
648 main.log.info( "Starting filter on host2" )
649 main.h2.startFilter( pktFilter="mpls" )
650
651 main.log.info( "Constructing packet" )
652 main.log.info( "Sending packet to host2" )
alisone14d7b02016-07-06 10:31:51 -0700653 main.h1.sendPacket( packet='Ether()/MPLS(label={})'.format( mplsLabel ) )
GlennRC956ea742015-11-05 16:14:15 -0800654
655 main.log.info( "Checking filter for our packet" )
Jon Hallfc951072017-05-24 15:55:34 -0700656 stepResult = main.h2.checkFilter()
GlennRC956ea742015-11-05 16:14:15 -0800657 if stepResult:
Jon Hallfc951072017-05-24 15:55:34 -0700658 main.log.info( "Packet: %s" % main.h2.readPackets() )
659 else:
660 main.h2.killFilter()
GlennRC956ea742015-11-05 16:14:15 -0800661
662 main.log.info( "Clean up host components" )
663 for host in hosts:
Jon Hallfc951072017-05-24 15:55:34 -0700664 host.stopScapy()
alisone14d7b02016-07-06 10:31:51 -0700665 main.Mininet1.removeHostComponent( "h1" )
666 main.Mininet1.removeHostComponent( "h2" )
GlennRC956ea742015-11-05 16:14:15 -0800667
668 utilities.assert_equals( expect=main.TRUE,
669 actual=stepResult,
670 onpass="Successfully sent a packet",
671 onfail="Failed to send a packet" )
672
alisone14d7b02016-07-06 10:31:51 -0700673 def CASE1700( self, main ):
Jon Hallfc951072017-05-24 15:55:34 -0700674 """
GlennRC956ea742015-11-05 16:14:15 -0800675 Add flows with a TCP selector and verify the flow
Jon Hallfc951072017-05-24 15:55:34 -0700676 """
GlennRC956ea742015-11-05 16:14:15 -0800677 import json
678 import time
679
680 main.case( "Verify the TCP selector is correctly compiled on the flow" )
681 main.caseExplanation = "Install a flow with only the TCP selector " +\
alisone14d7b02016-07-06 10:31:51 -0700682 "specified, verify the flow is added in ONOS, and finally " +\
GlennRC956ea742015-11-05 16:14:15 -0800683 "send a TCP packet to verify the TCP selector is compiled correctly."
684
685 main.step( "Add a flow with a TCP selector" )
Devin Lim142b5342017-07-20 15:22:39 -0700686 ctrl = main.Cluster.active( 0 )
GlennRC956ea742015-11-05 16:14:15 -0800687 main.log.info( "Creating host components" )
Jon Halla510a8a2016-05-04 15:09:28 -0700688 main.Scapy.createHostComponent( "h1" )
689 main.Scapy.createHostComponent( "h2" )
alisone14d7b02016-07-06 10:31:51 -0700690 hosts = [ main.h1, main.h2 ]
GlennRC956ea742015-11-05 16:14:15 -0800691 for host in hosts:
Jon Hallfc951072017-05-24 15:55:34 -0700692 host.startHostCli()
693 host.startScapy()
694 host.updateSelf()
GlennRC956ea742015-11-05 16:14:15 -0800695
696 # Add a flow that connects host1 on port1 to host2 on port2
697 egress = 2
698 ingress = 1
699 # IPv4 etherType
700 ethType = main.params[ 'TEST' ][ 'ip4Type' ]
701 # IP protocol
702 ipProto = main.params[ 'TEST' ][ 'tcpProto' ]
703 # TCP port destination
704 tcpDst = main.params[ 'TEST' ][ 'tcpDst' ]
705
706 main.log.info( "Add a flow that connects host1 on port1 to host2 on port2" )
Devin Lim142b5342017-07-20 15:22:39 -0700707 stepResult = ctrl.REST.addFlow( deviceId=main.swDPID,
708 egressPort=egress,
709 ingressPort=ingress,
710 ethType=ethType,
711 ipProto=ipProto,
712 tcpDst=tcpDst,
713 debug=main.debug )
GlennRC956ea742015-11-05 16:14:15 -0800714
715 utilities.assert_equals( expect=main.TRUE,
716 actual=stepResult,
717 onpass="Successfully added flows",
718 onfail="Failed add flows" )
719
720 # Giving ONOS time to add the flow
721 time.sleep( main.addFlowSleep )
722
Devin Lim58046fa2017-07-05 16:55:00 -0700723 main.checkingFlow.checkFlow()
GlennRC956ea742015-11-05 16:14:15 -0800724
725 main.step( "Send a packet to verify the flow is correct" )
726
727 main.log.info( "Constructing packet" )
728 # No need for the MAC src dst
729 main.h1.buildEther( dst=main.h2.hostMac )
730 main.h1.buildIP( dst=main.h2.hostIp )
731 main.h1.buildTCP( dport=tcpDst )
732
733 main.log.info( "Starting filter on host2" )
734 # Defaults to ip
735 main.h2.startFilter( pktFilter="tcp" )
736
737 main.log.info( "Sending packet to host2" )
Jon Hallfc951072017-05-24 15:55:34 -0700738 main.h1.sendPacket()
GlennRC956ea742015-11-05 16:14:15 -0800739
740 main.log.info( "Checking filter for our packet" )
Jon Hallfc951072017-05-24 15:55:34 -0700741 stepResult = main.h2.checkFilter()
GlennRC956ea742015-11-05 16:14:15 -0800742 if stepResult:
Jon Hallfc951072017-05-24 15:55:34 -0700743 main.log.info( "Packet: %s" % main.h2.readPackets() )
744 else:
745 main.h2.killFilter()
GlennRC956ea742015-11-05 16:14:15 -0800746
747 main.log.info( "Clean up host components" )
748 for host in hosts:
Jon Hallfc951072017-05-24 15:55:34 -0700749 host.stopScapy()
alisone14d7b02016-07-06 10:31:51 -0700750 main.Mininet1.removeHostComponent( "h1" )
751 main.Mininet1.removeHostComponent( "h2" )
GlennRC956ea742015-11-05 16:14:15 -0800752
753 utilities.assert_equals( expect=main.TRUE,
754 actual=stepResult,
755 onpass="Successfully sent a packet",
756 onfail="Failed to send a packet" )
757
alisone14d7b02016-07-06 10:31:51 -0700758 def CASE1600( self, main ):
Jon Hallfc951072017-05-24 15:55:34 -0700759 """
GlennRC956ea742015-11-05 16:14:15 -0800760 Add flows with a UDP selector and verify the flow
Jon Hallfc951072017-05-24 15:55:34 -0700761 """
GlennRC956ea742015-11-05 16:14:15 -0800762 import json
763 import time
764
765 main.case( "Verify the UDP selector is correctly compiled on the flow" )
766 main.caseExplanation = "Install a flow with only the UDP selector " +\
alisone14d7b02016-07-06 10:31:51 -0700767 "specified, verify the flow is added in ONOS, and finally " +\
GlennRC956ea742015-11-05 16:14:15 -0800768 "send a UDP packet to verify the UDP selector is compiled correctly."
769
770 main.step( "Add a flow with a UDP selector" )
Devin Lim142b5342017-07-20 15:22:39 -0700771 ctrl = main.Cluster.active( 0 )
GlennRC956ea742015-11-05 16:14:15 -0800772 main.log.info( "Creating host components" )
Jon Halla510a8a2016-05-04 15:09:28 -0700773 main.Scapy.createHostComponent( "h1" )
774 main.Scapy.createHostComponent( "h2" )
alisone14d7b02016-07-06 10:31:51 -0700775 hosts = [ main.h1, main.h2 ]
GlennRC956ea742015-11-05 16:14:15 -0800776 for host in hosts:
Jon Hallfc951072017-05-24 15:55:34 -0700777 host.startHostCli()
778 host.startScapy()
779 host.updateSelf()
GlennRC956ea742015-11-05 16:14:15 -0800780
781 # Add a flow that connects host1 on port1 to host2 on port2
782 egress = 2
783 ingress = 1
784 # IPv4 etherType
785 ethType = main.params[ 'TEST' ][ 'ip4Type' ]
786 # IP protocol
787 ipProto = main.params[ 'TEST' ][ 'udpProto' ]
788 # UDP port destination
789 udpDst = main.params[ 'TEST' ][ 'udpDst' ]
790
791 main.log.info( "Add a flow that connects host1 on port1 to host2 on port2" )
Devin Lim142b5342017-07-20 15:22:39 -0700792 stepResult =ctrl.REST.addFlow( deviceId=main.swDPID,
GlennRC956ea742015-11-05 16:14:15 -0800793 egressPort=egress,
794 ingressPort=ingress,
795 ethType=ethType,
796 ipProto=ipProto,
797 udpDst=udpDst,
798 debug=main.debug )
799
800 utilities.assert_equals( expect=main.TRUE,
801 actual=stepResult,
802 onpass="Successfully added flows",
803 onfail="Failed add flows" )
804
805 # Giving ONOS time to add the flow
806 time.sleep( main.addFlowSleep )
807
Devin Lim58046fa2017-07-05 16:55:00 -0700808 main.checkingFlow.checkFlow()
GlennRC956ea742015-11-05 16:14:15 -0800809
810 main.step( "Send a packet to verify the flow is correct" )
811
812 main.log.info( "Constructing packet" )
813 # No need for the MAC src dst
814 main.h1.buildEther( dst=main.h2.hostMac )
815 main.h1.buildIP( dst=main.h2.hostIp )
816 main.h1.buildUDP( dport=udpDst )
817
818 main.log.info( "Starting filter on host2" )
819 # Defaults to ip
820 main.h2.startFilter( pktFilter="udp" )
821
822 main.log.info( "Sending packet to host2" )
Jon Hallfc951072017-05-24 15:55:34 -0700823 main.h1.sendPacket()
GlennRC956ea742015-11-05 16:14:15 -0800824
825 main.log.info( "Checking filter for our packet" )
Jon Hallfc951072017-05-24 15:55:34 -0700826 stepResult = main.h2.checkFilter()
GlennRC956ea742015-11-05 16:14:15 -0800827 if stepResult:
Jon Hallfc951072017-05-24 15:55:34 -0700828 main.log.info( "Packet: %s" % main.h2.readPackets() )
829 else:
830 main.h2.killFilter()
GlennRC956ea742015-11-05 16:14:15 -0800831
832 main.log.info( "Clean up host components" )
833 for host in hosts:
Jon Hallfc951072017-05-24 15:55:34 -0700834 host.stopScapy()
alisone14d7b02016-07-06 10:31:51 -0700835 main.Mininet1.removeHostComponent( "h1" )
836 main.Mininet1.removeHostComponent( "h2" )
GlennRC956ea742015-11-05 16:14:15 -0800837
838 utilities.assert_equals( expect=main.TRUE,
839 actual=stepResult,
840 onpass="Successfully sent a packet",
841 onfail="Failed to send a packet" )
842
alisone14d7b02016-07-06 10:31:51 -0700843 def CASE1900( self, main ):
Jon Hallfc951072017-05-24 15:55:34 -0700844 """
alisone14d7b02016-07-06 10:31:51 -0700845 Add flows with a ICMPv4 selector and verify the flow
Jon Hallfc951072017-05-24 15:55:34 -0700846 """
GlennRC956ea742015-11-05 16:14:15 -0800847 import json
alisone14d7b02016-07-06 10:31:51 -0700848 import time
GlennRC956ea742015-11-05 16:14:15 -0800849
alisone14d7b02016-07-06 10:31:51 -0700850 main.case( "Verify the ICMPv4 selector is correctly compiled on the flow" )
851 main.caseExplanation = "Install a flow with only the ICMPv4 selector " +\
852 "specified, verify the flow is added in ONOS, and finally " +\
853 "send a IMCPv4 packet to verify the ICMPv4 selector is compiled correctly."
GlennRC956ea742015-11-05 16:14:15 -0800854
alisone14d7b02016-07-06 10:31:51 -0700855 main.step( "Add a flow with a ICMPv4 selector" )
856
857 main.log.info( "Creating host components" )
858 main.Scapy.createHostComponent( "h1" )
859 main.Scapy.createHostComponent( "h2" )
860 hosts = [ main.h1, main.h2 ]
861 for host in hosts:
Jon Hallfc951072017-05-24 15:55:34 -0700862 host.startHostCli()
863 host.startScapy()
864 host.updateSelf()
alisone14d7b02016-07-06 10:31:51 -0700865
866 # Add a flow that connects host1 on port1 to host2 on port2
867 egress = 2
868 ingress = 1
869 # IPv4 etherType
870 ethType = main.params[ 'TEST' ][ 'ip4Type' ]
871 # IP protocol
872 ipProto = main.params[ 'TEST' ][ 'icmpProto' ]
Devin Lim142b5342017-07-20 15:22:39 -0700873 ctrl = main.Cluster.active( 0 )
alisone14d7b02016-07-06 10:31:51 -0700874 main.log.info( "Add a flow that connects host1 on port1 to host2 on port2" )
Devin Lim142b5342017-07-20 15:22:39 -0700875 stepResult = ctrl.REST.addFlow( deviceId=main.swDPID,
876 egressPort=egress,
877 ingressPort=ingress,
878 ethType=ethType,
879 ipProto=ipProto,
880 debug=main.debug )
alisone14d7b02016-07-06 10:31:51 -0700881
882 utilities.assert_equals( expect=main.TRUE,
883 actual=stepResult,
884 onpass="Successfully added flows",
885 onfail="Failed add flows" )
886
887 # Giving ONOS time to add the flow
888 time.sleep( main.addFlowSleep )
889
Devin Lim58046fa2017-07-05 16:55:00 -0700890 main.checkingFlow.checkFlow()
alisone14d7b02016-07-06 10:31:51 -0700891
892 main.step( "Send a packet to verify the flow is correct" )
893
894 main.log.info( "Constructing packet" )
895 # No need for the MAC src dst
896 main.h1.buildEther( dst=main.h2.hostMac )
897 main.h1.buildIP( dst=main.h2.hostIp )
Jon Hallfc951072017-05-24 15:55:34 -0700898 main.h1.buildICMP()
alisone14d7b02016-07-06 10:31:51 -0700899
900 main.log.info( "Starting filter on host2" )
901 # Defaults to ip
902 main.h2.startFilter( pktFilter="icmp" )
903
904 main.log.info( "Sending packet to host2" )
Jon Hallfc951072017-05-24 15:55:34 -0700905 main.h1.sendPacket()
alisone14d7b02016-07-06 10:31:51 -0700906
907 main.log.info( "Checking filter for our packet" )
Jon Hallfc951072017-05-24 15:55:34 -0700908 stepResult = main.h2.checkFilter()
alisone14d7b02016-07-06 10:31:51 -0700909 if stepResult:
Jon Hallfc951072017-05-24 15:55:34 -0700910 main.log.info( "Packet: %s" % main.h2.readPackets() )
911 else:
912 main.h2.killFilter()
alisone14d7b02016-07-06 10:31:51 -0700913
914 main.log.info( "Clean up host components" )
915 for host in hosts:
Jon Hallfc951072017-05-24 15:55:34 -0700916 host.stopScapy()
alisone14d7b02016-07-06 10:31:51 -0700917 main.Mininet1.removeHostComponent( "h1" )
918 main.Mininet1.removeHostComponent( "h2" )
919
920 utilities.assert_equals( expect=main.TRUE,
921 actual=stepResult,
922 onpass="Successfully sent a packet",
923 onfail="Failed to send a packet" )
924
925 def CASE2000( self, main ):
Jon Hallfc951072017-05-24 15:55:34 -0700926 """
alisone14d7b02016-07-06 10:31:51 -0700927 Add flows with a ICMPv6 selector and verify the flow
Jon Hallfc951072017-05-24 15:55:34 -0700928 """
alisone14d7b02016-07-06 10:31:51 -0700929 import json
930 import time
931
932 main.case( "Verify the ICMPv6 selector is correctly compiled on the flow" )
933 main.caseExplanation = "Install a flow with only the ICMPv6 selector " +\
934 "specified, verify the flow is added in ONOS, and finally " +\
935 "send a IMCPv6 packet to verify the ICMPv6 selector is compiled correctly."
936
937 main.step( "Add a flow with a ICMPv6 selector" )
938
939 main.log.info( "Creating host components" )
940 main.Scapy.createHostComponent( "h5" )
941 main.Scapy.createHostComponent( "h6" )
Jon Hallfc951072017-05-24 15:55:34 -0700942 hosts = [ main.h5, main.h6 ]
alisone14d7b02016-07-06 10:31:51 -0700943 for host in hosts:
Jon Hallfc951072017-05-24 15:55:34 -0700944 host.startHostCli()
945 host.startScapy()
alisone14d7b02016-07-06 10:31:51 -0700946 host.updateSelf( IPv6=True )
947
948 # Add a flow that connects host1 on port1 to host2 on port2
Jon Hallfc951072017-05-24 15:55:34 -0700949 egress = 6
950 ingress = 5
alisone14d7b02016-07-06 10:31:51 -0700951 # IPv6 etherType
952 ethType = main.params[ 'TEST' ][ 'ip6Type' ]
953 # IP protocol
954 ipProto = main.params[ 'TEST' ][ 'icmp6Proto' ]
Devin Lim142b5342017-07-20 15:22:39 -0700955 ctrl = main.Cluster.active( 0 )
alisone14d7b02016-07-06 10:31:51 -0700956 main.log.info( "Add a flow that connects host1 on port1 to host2 on port2" )
Devin Lim142b5342017-07-20 15:22:39 -0700957 stepResult = ctrl.REST.addFlow( deviceId=main.swDPID,
958 egressPort=egress,
959 ingressPort=ingress,
960 ethType=ethType,
961 ipProto=ipProto,
962 debug=main.debug )
alisone14d7b02016-07-06 10:31:51 -0700963
964 utilities.assert_equals( expect=main.TRUE,
965 actual=stepResult,
966 onpass="Successfully added flows",
967 onfail="Failed add flows" )
968
969 # Giving ONOS time to add the flow
970 time.sleep( main.addFlowSleep )
971
Devin Lim58046fa2017-07-05 16:55:00 -0700972 main.checkingFlow.checkFlow()
alisone14d7b02016-07-06 10:31:51 -0700973
974 main.step( "Send a packet to verify the flow is correct" )
975
976 main.log.info( "Constructing packet" )
977 # No need for the MAC src dst
978 main.h5.buildEther( dst=main.h6.hostMac )
979 main.h5.buildIPv6( dst=main.h6.hostIp )
980 main.h5.buildICMP( ipVersion=6 )
981
982 main.log.info( "Starting filter on host2" )
983 # Defaults to ip
984 main.h6.startFilter( pktFilter="icmp6" )
985
986 main.log.info( "Sending packet to host2" )
Jon Hallfc951072017-05-24 15:55:34 -0700987 main.h5.sendPacket()
alisone14d7b02016-07-06 10:31:51 -0700988
989 main.log.info( "Checking filter for our packet" )
Jon Hallfc951072017-05-24 15:55:34 -0700990 stepResult = main.h6.checkFilter()
alisone14d7b02016-07-06 10:31:51 -0700991 if stepResult:
Jon Hallfc951072017-05-24 15:55:34 -0700992 main.log.info( "Packet: %s" % main.h6.readPackets() )
993 else:
994 main.h6.killFilter()
alisone14d7b02016-07-06 10:31:51 -0700995
996 main.log.info( "Clean up host components" )
997 for host in hosts:
Jon Hallfc951072017-05-24 15:55:34 -0700998 host.stopScapy()
alisone14d7b02016-07-06 10:31:51 -0700999 main.Mininet1.removeHostComponent( "h5" )
1000 main.Mininet1.removeHostComponent( "h6" )
1001
1002 utilities.assert_equals( expect=main.TRUE,
1003 actual=stepResult,
1004 onpass="Successfully sent a packet",
1005 onfail="Failed to send a packet" )
1006
1007 def CASE3000( self, main ):
Jon Hallfc951072017-05-24 15:55:34 -07001008 """
alisone14d7b02016-07-06 10:31:51 -07001009 Delete flow
Jon Hallfc951072017-05-24 15:55:34 -07001010 """
alisone14d7b02016-07-06 10:31:51 -07001011 import json
1012
1013 main.case( "Delete flows that were added through rest" )
1014 main.step( "Deleting flows" )
Devin Lim142b5342017-07-20 15:22:39 -07001015 ctrl = main.Cluster.active( 0 )
alisone14d7b02016-07-06 10:31:51 -07001016 main.log.info( "Getting flows" )
1017 try:
Devin Lim142b5342017-07-20 15:22:39 -07001018 flows = json.loads( ctrl.REST.flows() )
alisone14d7b02016-07-06 10:31:51 -07001019
1020 stepResult = main.TRUE
1021 for f in flows:
1022 if "rest" in f.get( "appId" ):
Jon Hallfc951072017-05-24 15:55:34 -07001023 if main.debug:
Devin Lim142b5342017-07-20 15:22:39 -07001024 main.log.debug( "Flow to be deleted:\n{}".format( ctrl.REST.pprint( f ) ) )
1025 stepResult = stepResult and ctrl.REST.removeFlow( f.get( "deviceId" ), f.get( "id" ) )
alisone14d7b02016-07-06 10:31:51 -07001026 except TypeError:
1027 main.log.error( "No Flows found by the REST API" )
1028 stepResult = main.FALSE
1029 except ValueError:
1030 main.log.error( "Problem getting Flows state from REST API. Exiting test" )
Jon Hallfc951072017-05-24 15:55:34 -07001031 main.cleanup()
1032 main.exit()
GlennRC956ea742015-11-05 16:14:15 -08001033
1034 utilities.assert_equals( expect=main.TRUE,
1035 actual=stepResult,
1036 onpass="Successfully deleting flows",
1037 onfail="Failed to delete flows" )
1038
1039 time.sleep( main.delFlowSleep )
1040
Jon Hallfc951072017-05-24 15:55:34 -07001041 def CASE1200( self, main ):
1042 """
alisone14d7b02016-07-06 10:31:51 -07001043 Add flows with a ARP selector and verify the flow
Jon Hallfc951072017-05-24 15:55:34 -07001044 """
alisone14d7b02016-07-06 10:31:51 -07001045 import json
1046 import time
1047
1048 main.case( "Verify flow IP selectors are correctly compiled" )
1049 main.caseExplanation = "Install two flows with only IP selectors " + \
1050 "specified, then verify flows are added in ONOS, finally " + \
1051 "send a packet that only specifies the IP src and dst."
1052
1053 main.step( "Add flows with ARP addresses as the only selectors" )
1054
1055 main.log.info( "Creating host components" )
1056 main.Scapy.createHostComponent( "h1" )
1057 main.Scapy.createHostComponent( "h2" )
1058 hosts = [ main.h1, main.h2 ]
1059 for host in hosts:
Jon Hallfc951072017-05-24 15:55:34 -07001060 host.startHostCli()
1061 host.startScapy()
1062 host.updateSelf()
Devin Lim142b5342017-07-20 15:22:39 -07001063 ctrl = main.Cluster.active( 0 )
alisone14d7b02016-07-06 10:31:51 -07001064 # Add a flow that connects host1 on port1 to host2 on port2
1065 # send output on port2
1066 # recieve input on port1
1067 egress = 2
1068 ingress = 1
1069 # ARP etherType = 0x0806
1070 ethType = main.params[ 'TEST' ][ 'arpType' ]
1071
1072 # Add flows that connects host1 to host2
1073 main.log.info( "Add flow with port ingress 1 to port egress 2" )
Devin Lim142b5342017-07-20 15:22:39 -07001074 stepResult = ctrl.REST.addFlow( deviceId=main.swDPID,
1075 egressPort=egress,
1076 ingressPort=ingress,
1077 ethType=ethType,
1078 priority=40001,
1079 debug=main.debug )
alisone14d7b02016-07-06 10:31:51 -07001080
1081 utilities.assert_equals( expect=main.TRUE,
1082 actual=stepResult,
1083 onpass="Successfully added flows",
1084 onfail="Failed add flows" )
1085
1086 # Giving ONOS time to add the flow
1087 time.sleep( main.addFlowSleep )
1088
Devin Lim58046fa2017-07-05 16:55:00 -07001089 main.checkingFlow.checkFlow()
alisone14d7b02016-07-06 10:31:51 -07001090
1091 main.step( "Send a packet to verify the flow is correct" )
1092
1093 main.log.info( "Constructing packet" )
1094 # No need for the MAC src dst
1095 main.h1.buildEther( src=main.h1.hostMac, dst=main.h2.hostMac )
1096 main.h1.buildARP( pdst=main.h2.hostIp )
1097
1098 main.log.info( "Starting filter on host2" )
1099 # Defaults to ip
1100 main.h2.startFilter( pktFilter="arp" )
1101
1102 main.log.info( "Sending packet to host2" )
Jon Hallfc951072017-05-24 15:55:34 -07001103 main.h1.sendPacket()
alisone14d7b02016-07-06 10:31:51 -07001104
1105 main.log.info( "Checking filter for our packet" )
Jon Hallfc951072017-05-24 15:55:34 -07001106 stepResult = main.h2.checkFilter()
alisone14d7b02016-07-06 10:31:51 -07001107 if stepResult:
Jon Hallfc951072017-05-24 15:55:34 -07001108 main.log.info( "Packet: %s" % main.h2.readPackets() )
alisone14d7b02016-07-06 10:31:51 -07001109 else:
Jon Hallfc951072017-05-24 15:55:34 -07001110 main.h2.killFilter()
alisone14d7b02016-07-06 10:31:51 -07001111
1112 main.log.info( "Clean up host components" )
1113 for host in hosts:
Jon Hallfc951072017-05-24 15:55:34 -07001114 host.stopScapy()
alisone14d7b02016-07-06 10:31:51 -07001115 main.Mininet1.removeHostComponent( "h1" )
1116 main.Mininet1.removeHostComponent( "h2" )
1117
1118 utilities.assert_equals( expect=main.TRUE,
1119 actual=stepResult,
1120 onpass="Successfully sent a packet",
1121 onfail="Failed to send a packet" )
1122
1123 def CASE1800( self, main ):
Jon Hallfc951072017-05-24 15:55:34 -07001124 """
alisone14d7b02016-07-06 10:31:51 -07001125 Add flows with a SCTP selector and verify the flow
Jon Hallfc951072017-05-24 15:55:34 -07001126 """
alisone14d7b02016-07-06 10:31:51 -07001127 import json
1128 import time
1129
1130 main.case( "Verify the UDP selector is correctly compiled on the flow" )
1131 main.caseExplanation = "Install a flow with only the UDP selector " + \
1132 "specified, verify the flow is added in ONOS, and finally " + \
1133 "send a UDP packet to verify the UDP selector is compiled correctly."
1134
1135 main.step( "Add a flow with a SCTP selector" )
1136
1137 main.log.info( "Creating host components" )
1138 main.Scapy.createHostComponent( "h1" )
1139 main.Scapy.createHostComponent( "h2" )
1140 hosts = [ main.h1, main.h2 ]
1141 for host in hosts:
Jon Hallfc951072017-05-24 15:55:34 -07001142 host.startHostCli()
1143 host.startScapy()
1144 host.updateSelf()
alisone14d7b02016-07-06 10:31:51 -07001145
1146 # Add a flow that connects host1 on port1 to host2 on port2
1147 egress = 2
1148 ingress = 1
1149 # IPv4 etherType
1150 ethType = main.params[ 'TEST' ][ 'ip4Type' ]
1151 # IP protocol
1152 ipProto = main.params[ 'TEST' ][ 'sctpProto' ]
Devin Lim142b5342017-07-20 15:22:39 -07001153 ctrl = main.Cluster.active( 0 )
Jon Hallfc951072017-05-24 15:55:34 -07001154 main.log.info( "Add a flow that connects host1 on port1 to host2 on port2" )
Devin Lim142b5342017-07-20 15:22:39 -07001155 stepResult = ctrl.REST.addFlow( deviceId=main.swDPID,
1156 egressPort=egress,
1157 ingressPort=ingress,
1158 ethType=ethType,
1159 ipProto=ipProto,
1160 debug=main.debug )
alisone14d7b02016-07-06 10:31:51 -07001161
1162 utilities.assert_equals( expect=main.TRUE,
1163 actual=stepResult,
1164 onpass="Successfully added flows",
1165 onfail="Failed add flows" )
1166
1167 # Giving ONOS time to add the flow
1168 time.sleep( main.addFlowSleep )
1169
Devin Lim58046fa2017-07-05 16:55:00 -07001170 main.checkingFlow.checkFlow()
alisone14d7b02016-07-06 10:31:51 -07001171
1172 main.step( "Send a packet to verify the flow is correct" )
1173
1174 main.log.info( "Constructing packet" )
1175 # No need for the MAC src dst
1176 main.h1.buildEther( dst=main.h2.hostMac )
1177 main.h1.buildIP( dst=main.h2.hostIp )
Jon Hallfc951072017-05-24 15:55:34 -07001178 main.h1.buildSCTP()
alisone14d7b02016-07-06 10:31:51 -07001179
1180 main.log.info( "Starting filter on host2" )
1181 # Defaults to ip
1182 main.h2.startFilter( pktFilter="sctp" )
1183
1184 main.log.info( "Sending packet to host2" )
Jon Hallfc951072017-05-24 15:55:34 -07001185 main.h1.sendPacket()
alisone14d7b02016-07-06 10:31:51 -07001186
1187 main.log.info( "Checking filter for our packet" )
Jon Hallfc951072017-05-24 15:55:34 -07001188 stepResult = main.h2.checkFilter()
alisone14d7b02016-07-06 10:31:51 -07001189 if stepResult:
Jon Hallfc951072017-05-24 15:55:34 -07001190 main.log.info( "Packet: %s" % main.h2.readPackets() )
alisone14d7b02016-07-06 10:31:51 -07001191 else:
Jon Hallfc951072017-05-24 15:55:34 -07001192 main.h2.killFilter()
alisone14d7b02016-07-06 10:31:51 -07001193
1194 main.log.info( "Clean up host components" )
1195 for host in hosts:
Jon Hallfc951072017-05-24 15:55:34 -07001196 host.stopScapy()
alisone14d7b02016-07-06 10:31:51 -07001197 main.Mininet1.removeHostComponent( "h1" )
1198 main.Mininet1.removeHostComponent( "h2" )
1199
1200 utilities.assert_equals( expect=main.TRUE,
1201 actual=stepResult,
1202 onpass="Successfully sent a packet",
1203 onfail="Failed to send a packet" )
1204
GlennRC68449942015-10-16 16:03:12 -07001205 def CASE100( self, main ):
Jon Hallfc951072017-05-24 15:55:34 -07001206 """
GlennRC5147a422015-10-06 17:26:17 -07001207 Report errors/warnings/exceptions
Jon Hallfc951072017-05-24 15:55:34 -07001208 """
alisone14d7b02016-07-06 10:31:51 -07001209 main.log.info( "Error report: \n" )
Devin Lim142b5342017-07-20 15:22:39 -07001210 main.ONOSbench.logReport( main.Cluster.active( 0 ).ipAddress,
GlennRC5147a422015-10-06 17:26:17 -07001211 [ "INFO",
1212 "FOLLOWER",
1213 "WARN",
1214 "flow",
1215 "ERROR",
1216 "Except" ],
GlennRC68449942015-10-16 16:03:12 -07001217 "s" )