blob: 9b504ba3cfdaaa6084c0ad5d374412894254cfca [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" )
Devin Lim44075962017-08-11 10:56:37 -070034 main.cleanAndExit()
Devin Lim58046fa2017-07-05 16:55:00 -070035 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")
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
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" )
Devin Lim44075962017-08-11 10:56:37 -0700120 main.cleanAndExit()
Devin Lim58046fa2017-07-05 16:55:00 -0700121 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" )
Devin Lim44075962017-08-11 10:56:37 -0700622 main.cleanAndExit()
GlennRC956ea742015-11-05 16:14:15 -0800623
624 utilities.assert_equals( expect=main.TRUE,
625 actual=stepResult,
626 onpass="All flows are in the ADDED state",
627 onfail="All flows are NOT in the ADDED state" )
628
629 main.step( "Check flows are in Mininet's flow table" )
630
631 # get the flow IDs that were added through rest
632 main.log.info( "Getting the flow IDs from ONOS" )
alisone14d7b02016-07-06 10:31:51 -0700633 flowIds = [ f.get( "id" ) for f in flows if "rest" in f.get( "appId" ) ]
GlennRC956ea742015-11-05 16:14:15 -0800634 # convert the flowIDs to ints then hex and finally back to strings
alisone14d7b02016-07-06 10:31:51 -0700635 flowIds = [ str( hex( int( x ) ) ) for x in flowIds ]
636 main.log.info( "ONOS flow IDs: {}".format( flowIds ) )
GlennRC956ea742015-11-05 16:14:15 -0800637
638 stepResult = main.Mininet1.checkFlowId( "s1", flowIds, debug=True )
639
640 utilities.assert_equals( expect=main.TRUE,
641 actual=stepResult,
642 onpass="All flows are in mininet",
643 onfail="All flows are NOT in mininet" )
644
645 main.step( "Send a packet to verify the flow is correct" )
646
647 main.log.info( "Starting filter on host2" )
648 main.h2.startFilter( pktFilter="mpls" )
649
650 main.log.info( "Constructing packet" )
651 main.log.info( "Sending packet to host2" )
alisone14d7b02016-07-06 10:31:51 -0700652 main.h1.sendPacket( packet='Ether()/MPLS(label={})'.format( mplsLabel ) )
GlennRC956ea742015-11-05 16:14:15 -0800653
654 main.log.info( "Checking filter for our packet" )
Jon Hallfc951072017-05-24 15:55:34 -0700655 stepResult = main.h2.checkFilter()
GlennRC956ea742015-11-05 16:14:15 -0800656 if stepResult:
Jon Hallfc951072017-05-24 15:55:34 -0700657 main.log.info( "Packet: %s" % main.h2.readPackets() )
658 else:
659 main.h2.killFilter()
GlennRC956ea742015-11-05 16:14:15 -0800660
661 main.log.info( "Clean up host components" )
662 for host in hosts:
Jon Hallfc951072017-05-24 15:55:34 -0700663 host.stopScapy()
alisone14d7b02016-07-06 10:31:51 -0700664 main.Mininet1.removeHostComponent( "h1" )
665 main.Mininet1.removeHostComponent( "h2" )
GlennRC956ea742015-11-05 16:14:15 -0800666
667 utilities.assert_equals( expect=main.TRUE,
668 actual=stepResult,
669 onpass="Successfully sent a packet",
670 onfail="Failed to send a packet" )
671
alisone14d7b02016-07-06 10:31:51 -0700672 def CASE1700( self, main ):
Jon Hallfc951072017-05-24 15:55:34 -0700673 """
GlennRC956ea742015-11-05 16:14:15 -0800674 Add flows with a TCP selector and verify the flow
Jon Hallfc951072017-05-24 15:55:34 -0700675 """
GlennRC956ea742015-11-05 16:14:15 -0800676 import json
677 import time
678
679 main.case( "Verify the TCP selector is correctly compiled on the flow" )
680 main.caseExplanation = "Install a flow with only the TCP selector " +\
alisone14d7b02016-07-06 10:31:51 -0700681 "specified, verify the flow is added in ONOS, and finally " +\
GlennRC956ea742015-11-05 16:14:15 -0800682 "send a TCP packet to verify the TCP selector is compiled correctly."
683
684 main.step( "Add a flow with a TCP selector" )
Devin Lim142b5342017-07-20 15:22:39 -0700685 ctrl = main.Cluster.active( 0 )
GlennRC956ea742015-11-05 16:14:15 -0800686 main.log.info( "Creating host components" )
Jon Halla510a8a2016-05-04 15:09:28 -0700687 main.Scapy.createHostComponent( "h1" )
688 main.Scapy.createHostComponent( "h2" )
alisone14d7b02016-07-06 10:31:51 -0700689 hosts = [ main.h1, main.h2 ]
GlennRC956ea742015-11-05 16:14:15 -0800690 for host in hosts:
Jon Hallfc951072017-05-24 15:55:34 -0700691 host.startHostCli()
692 host.startScapy()
693 host.updateSelf()
GlennRC956ea742015-11-05 16:14:15 -0800694
695 # Add a flow that connects host1 on port1 to host2 on port2
696 egress = 2
697 ingress = 1
698 # IPv4 etherType
699 ethType = main.params[ 'TEST' ][ 'ip4Type' ]
700 # IP protocol
701 ipProto = main.params[ 'TEST' ][ 'tcpProto' ]
702 # TCP port destination
703 tcpDst = main.params[ 'TEST' ][ 'tcpDst' ]
704
705 main.log.info( "Add a flow that connects host1 on port1 to host2 on port2" )
Devin Lim142b5342017-07-20 15:22:39 -0700706 stepResult = ctrl.REST.addFlow( deviceId=main.swDPID,
707 egressPort=egress,
708 ingressPort=ingress,
709 ethType=ethType,
710 ipProto=ipProto,
711 tcpDst=tcpDst,
712 debug=main.debug )
GlennRC956ea742015-11-05 16:14:15 -0800713
714 utilities.assert_equals( expect=main.TRUE,
715 actual=stepResult,
716 onpass="Successfully added flows",
717 onfail="Failed add flows" )
718
719 # Giving ONOS time to add the flow
720 time.sleep( main.addFlowSleep )
721
Devin Lim58046fa2017-07-05 16:55:00 -0700722 main.checkingFlow.checkFlow()
GlennRC956ea742015-11-05 16:14:15 -0800723
724 main.step( "Send a packet to verify the flow is correct" )
725
726 main.log.info( "Constructing packet" )
727 # No need for the MAC src dst
728 main.h1.buildEther( dst=main.h2.hostMac )
729 main.h1.buildIP( dst=main.h2.hostIp )
730 main.h1.buildTCP( dport=tcpDst )
731
732 main.log.info( "Starting filter on host2" )
733 # Defaults to ip
734 main.h2.startFilter( pktFilter="tcp" )
735
736 main.log.info( "Sending packet to host2" )
Jon Hallfc951072017-05-24 15:55:34 -0700737 main.h1.sendPacket()
GlennRC956ea742015-11-05 16:14:15 -0800738
739 main.log.info( "Checking filter for our packet" )
Jon Hallfc951072017-05-24 15:55:34 -0700740 stepResult = main.h2.checkFilter()
GlennRC956ea742015-11-05 16:14:15 -0800741 if stepResult:
Jon Hallfc951072017-05-24 15:55:34 -0700742 main.log.info( "Packet: %s" % main.h2.readPackets() )
743 else:
744 main.h2.killFilter()
GlennRC956ea742015-11-05 16:14:15 -0800745
746 main.log.info( "Clean up host components" )
747 for host in hosts:
Jon Hallfc951072017-05-24 15:55:34 -0700748 host.stopScapy()
alisone14d7b02016-07-06 10:31:51 -0700749 main.Mininet1.removeHostComponent( "h1" )
750 main.Mininet1.removeHostComponent( "h2" )
GlennRC956ea742015-11-05 16:14:15 -0800751
752 utilities.assert_equals( expect=main.TRUE,
753 actual=stepResult,
754 onpass="Successfully sent a packet",
755 onfail="Failed to send a packet" )
756
alisone14d7b02016-07-06 10:31:51 -0700757 def CASE1600( self, main ):
Jon Hallfc951072017-05-24 15:55:34 -0700758 """
GlennRC956ea742015-11-05 16:14:15 -0800759 Add flows with a UDP selector and verify the flow
Jon Hallfc951072017-05-24 15:55:34 -0700760 """
GlennRC956ea742015-11-05 16:14:15 -0800761 import json
762 import time
763
764 main.case( "Verify the UDP selector is correctly compiled on the flow" )
765 main.caseExplanation = "Install a flow with only the UDP selector " +\
alisone14d7b02016-07-06 10:31:51 -0700766 "specified, verify the flow is added in ONOS, and finally " +\
GlennRC956ea742015-11-05 16:14:15 -0800767 "send a UDP packet to verify the UDP selector is compiled correctly."
768
769 main.step( "Add a flow with a UDP selector" )
Devin Lim142b5342017-07-20 15:22:39 -0700770 ctrl = main.Cluster.active( 0 )
GlennRC956ea742015-11-05 16:14:15 -0800771 main.log.info( "Creating host components" )
Jon Halla510a8a2016-05-04 15:09:28 -0700772 main.Scapy.createHostComponent( "h1" )
773 main.Scapy.createHostComponent( "h2" )
alisone14d7b02016-07-06 10:31:51 -0700774 hosts = [ main.h1, main.h2 ]
GlennRC956ea742015-11-05 16:14:15 -0800775 for host in hosts:
Jon Hallfc951072017-05-24 15:55:34 -0700776 host.startHostCli()
777 host.startScapy()
778 host.updateSelf()
GlennRC956ea742015-11-05 16:14:15 -0800779
780 # Add a flow that connects host1 on port1 to host2 on port2
781 egress = 2
782 ingress = 1
783 # IPv4 etherType
784 ethType = main.params[ 'TEST' ][ 'ip4Type' ]
785 # IP protocol
786 ipProto = main.params[ 'TEST' ][ 'udpProto' ]
787 # UDP port destination
788 udpDst = main.params[ 'TEST' ][ 'udpDst' ]
789
790 main.log.info( "Add a flow that connects host1 on port1 to host2 on port2" )
Devin Lim142b5342017-07-20 15:22:39 -0700791 stepResult =ctrl.REST.addFlow( deviceId=main.swDPID,
GlennRC956ea742015-11-05 16:14:15 -0800792 egressPort=egress,
793 ingressPort=ingress,
794 ethType=ethType,
795 ipProto=ipProto,
796 udpDst=udpDst,
797 debug=main.debug )
798
799 utilities.assert_equals( expect=main.TRUE,
800 actual=stepResult,
801 onpass="Successfully added flows",
802 onfail="Failed add flows" )
803
804 # Giving ONOS time to add the flow
805 time.sleep( main.addFlowSleep )
806
Devin Lim58046fa2017-07-05 16:55:00 -0700807 main.checkingFlow.checkFlow()
GlennRC956ea742015-11-05 16:14:15 -0800808
809 main.step( "Send a packet to verify the flow is correct" )
810
811 main.log.info( "Constructing packet" )
812 # No need for the MAC src dst
813 main.h1.buildEther( dst=main.h2.hostMac )
814 main.h1.buildIP( dst=main.h2.hostIp )
815 main.h1.buildUDP( dport=udpDst )
816
817 main.log.info( "Starting filter on host2" )
818 # Defaults to ip
819 main.h2.startFilter( pktFilter="udp" )
820
821 main.log.info( "Sending packet to host2" )
Jon Hallfc951072017-05-24 15:55:34 -0700822 main.h1.sendPacket()
GlennRC956ea742015-11-05 16:14:15 -0800823
824 main.log.info( "Checking filter for our packet" )
Jon Hallfc951072017-05-24 15:55:34 -0700825 stepResult = main.h2.checkFilter()
GlennRC956ea742015-11-05 16:14:15 -0800826 if stepResult:
Jon Hallfc951072017-05-24 15:55:34 -0700827 main.log.info( "Packet: %s" % main.h2.readPackets() )
828 else:
829 main.h2.killFilter()
GlennRC956ea742015-11-05 16:14:15 -0800830
831 main.log.info( "Clean up host components" )
832 for host in hosts:
Jon Hallfc951072017-05-24 15:55:34 -0700833 host.stopScapy()
alisone14d7b02016-07-06 10:31:51 -0700834 main.Mininet1.removeHostComponent( "h1" )
835 main.Mininet1.removeHostComponent( "h2" )
GlennRC956ea742015-11-05 16:14:15 -0800836
837 utilities.assert_equals( expect=main.TRUE,
838 actual=stepResult,
839 onpass="Successfully sent a packet",
840 onfail="Failed to send a packet" )
841
alisone14d7b02016-07-06 10:31:51 -0700842 def CASE1900( self, main ):
Jon Hallfc951072017-05-24 15:55:34 -0700843 """
alisone14d7b02016-07-06 10:31:51 -0700844 Add flows with a ICMPv4 selector and verify the flow
Jon Hallfc951072017-05-24 15:55:34 -0700845 """
GlennRC956ea742015-11-05 16:14:15 -0800846 import json
alisone14d7b02016-07-06 10:31:51 -0700847 import time
GlennRC956ea742015-11-05 16:14:15 -0800848
alisone14d7b02016-07-06 10:31:51 -0700849 main.case( "Verify the ICMPv4 selector is correctly compiled on the flow" )
850 main.caseExplanation = "Install a flow with only the ICMPv4 selector " +\
851 "specified, verify the flow is added in ONOS, and finally " +\
852 "send a IMCPv4 packet to verify the ICMPv4 selector is compiled correctly."
GlennRC956ea742015-11-05 16:14:15 -0800853
alisone14d7b02016-07-06 10:31:51 -0700854 main.step( "Add a flow with a ICMPv4 selector" )
855
856 main.log.info( "Creating host components" )
857 main.Scapy.createHostComponent( "h1" )
858 main.Scapy.createHostComponent( "h2" )
859 hosts = [ main.h1, main.h2 ]
860 for host in hosts:
Jon Hallfc951072017-05-24 15:55:34 -0700861 host.startHostCli()
862 host.startScapy()
863 host.updateSelf()
alisone14d7b02016-07-06 10:31:51 -0700864
865 # Add a flow that connects host1 on port1 to host2 on port2
866 egress = 2
867 ingress = 1
868 # IPv4 etherType
869 ethType = main.params[ 'TEST' ][ 'ip4Type' ]
870 # IP protocol
871 ipProto = main.params[ 'TEST' ][ 'icmpProto' ]
Devin Lim142b5342017-07-20 15:22:39 -0700872 ctrl = main.Cluster.active( 0 )
alisone14d7b02016-07-06 10:31:51 -0700873 main.log.info( "Add a flow that connects host1 on port1 to host2 on port2" )
Devin Lim142b5342017-07-20 15:22:39 -0700874 stepResult = ctrl.REST.addFlow( deviceId=main.swDPID,
875 egressPort=egress,
876 ingressPort=ingress,
877 ethType=ethType,
878 ipProto=ipProto,
879 debug=main.debug )
alisone14d7b02016-07-06 10:31:51 -0700880
881 utilities.assert_equals( expect=main.TRUE,
882 actual=stepResult,
883 onpass="Successfully added flows",
884 onfail="Failed add flows" )
885
886 # Giving ONOS time to add the flow
887 time.sleep( main.addFlowSleep )
888
Devin Lim58046fa2017-07-05 16:55:00 -0700889 main.checkingFlow.checkFlow()
alisone14d7b02016-07-06 10:31:51 -0700890
891 main.step( "Send a packet to verify the flow is correct" )
892
893 main.log.info( "Constructing packet" )
894 # No need for the MAC src dst
895 main.h1.buildEther( dst=main.h2.hostMac )
896 main.h1.buildIP( dst=main.h2.hostIp )
Jon Hallfc951072017-05-24 15:55:34 -0700897 main.h1.buildICMP()
alisone14d7b02016-07-06 10:31:51 -0700898
899 main.log.info( "Starting filter on host2" )
900 # Defaults to ip
901 main.h2.startFilter( pktFilter="icmp" )
902
903 main.log.info( "Sending packet to host2" )
Jon Hallfc951072017-05-24 15:55:34 -0700904 main.h1.sendPacket()
alisone14d7b02016-07-06 10:31:51 -0700905
906 main.log.info( "Checking filter for our packet" )
Jon Hallfc951072017-05-24 15:55:34 -0700907 stepResult = main.h2.checkFilter()
alisone14d7b02016-07-06 10:31:51 -0700908 if stepResult:
Jon Hallfc951072017-05-24 15:55:34 -0700909 main.log.info( "Packet: %s" % main.h2.readPackets() )
910 else:
911 main.h2.killFilter()
alisone14d7b02016-07-06 10:31:51 -0700912
913 main.log.info( "Clean up host components" )
914 for host in hosts:
Jon Hallfc951072017-05-24 15:55:34 -0700915 host.stopScapy()
alisone14d7b02016-07-06 10:31:51 -0700916 main.Mininet1.removeHostComponent( "h1" )
917 main.Mininet1.removeHostComponent( "h2" )
918
919 utilities.assert_equals( expect=main.TRUE,
920 actual=stepResult,
921 onpass="Successfully sent a packet",
922 onfail="Failed to send a packet" )
923
924 def CASE2000( self, main ):
Jon Hallfc951072017-05-24 15:55:34 -0700925 """
alisone14d7b02016-07-06 10:31:51 -0700926 Add flows with a ICMPv6 selector and verify the flow
Jon Hallfc951072017-05-24 15:55:34 -0700927 """
alisone14d7b02016-07-06 10:31:51 -0700928 import json
929 import time
930
931 main.case( "Verify the ICMPv6 selector is correctly compiled on the flow" )
932 main.caseExplanation = "Install a flow with only the ICMPv6 selector " +\
933 "specified, verify the flow is added in ONOS, and finally " +\
934 "send a IMCPv6 packet to verify the ICMPv6 selector is compiled correctly."
935
936 main.step( "Add a flow with a ICMPv6 selector" )
937
938 main.log.info( "Creating host components" )
939 main.Scapy.createHostComponent( "h5" )
940 main.Scapy.createHostComponent( "h6" )
Jon Hallfc951072017-05-24 15:55:34 -0700941 hosts = [ main.h5, main.h6 ]
alisone14d7b02016-07-06 10:31:51 -0700942 for host in hosts:
Jon Hallfc951072017-05-24 15:55:34 -0700943 host.startHostCli()
944 host.startScapy()
alisone14d7b02016-07-06 10:31:51 -0700945 host.updateSelf( IPv6=True )
946
947 # Add a flow that connects host1 on port1 to host2 on port2
Jon Hallfc951072017-05-24 15:55:34 -0700948 egress = 6
949 ingress = 5
alisone14d7b02016-07-06 10:31:51 -0700950 # IPv6 etherType
951 ethType = main.params[ 'TEST' ][ 'ip6Type' ]
952 # IP protocol
953 ipProto = main.params[ 'TEST' ][ 'icmp6Proto' ]
Devin Lim142b5342017-07-20 15:22:39 -0700954 ctrl = main.Cluster.active( 0 )
alisone14d7b02016-07-06 10:31:51 -0700955 main.log.info( "Add a flow that connects host1 on port1 to host2 on port2" )
Devin Lim142b5342017-07-20 15:22:39 -0700956 stepResult = ctrl.REST.addFlow( deviceId=main.swDPID,
957 egressPort=egress,
958 ingressPort=ingress,
959 ethType=ethType,
960 ipProto=ipProto,
961 debug=main.debug )
alisone14d7b02016-07-06 10:31:51 -0700962
963 utilities.assert_equals( expect=main.TRUE,
964 actual=stepResult,
965 onpass="Successfully added flows",
966 onfail="Failed add flows" )
967
968 # Giving ONOS time to add the flow
969 time.sleep( main.addFlowSleep )
970
Devin Lim58046fa2017-07-05 16:55:00 -0700971 main.checkingFlow.checkFlow()
alisone14d7b02016-07-06 10:31:51 -0700972
973 main.step( "Send a packet to verify the flow is correct" )
974
975 main.log.info( "Constructing packet" )
976 # No need for the MAC src dst
977 main.h5.buildEther( dst=main.h6.hostMac )
978 main.h5.buildIPv6( dst=main.h6.hostIp )
979 main.h5.buildICMP( ipVersion=6 )
980
981 main.log.info( "Starting filter on host2" )
982 # Defaults to ip
983 main.h6.startFilter( pktFilter="icmp6" )
984
985 main.log.info( "Sending packet to host2" )
Jon Hallfc951072017-05-24 15:55:34 -0700986 main.h5.sendPacket()
alisone14d7b02016-07-06 10:31:51 -0700987
988 main.log.info( "Checking filter for our packet" )
Jon Hallfc951072017-05-24 15:55:34 -0700989 stepResult = main.h6.checkFilter()
alisone14d7b02016-07-06 10:31:51 -0700990 if stepResult:
Jon Hallfc951072017-05-24 15:55:34 -0700991 main.log.info( "Packet: %s" % main.h6.readPackets() )
992 else:
993 main.h6.killFilter()
alisone14d7b02016-07-06 10:31:51 -0700994
995 main.log.info( "Clean up host components" )
996 for host in hosts:
Jon Hallfc951072017-05-24 15:55:34 -0700997 host.stopScapy()
alisone14d7b02016-07-06 10:31:51 -0700998 main.Mininet1.removeHostComponent( "h5" )
999 main.Mininet1.removeHostComponent( "h6" )
1000
1001 utilities.assert_equals( expect=main.TRUE,
1002 actual=stepResult,
1003 onpass="Successfully sent a packet",
1004 onfail="Failed to send a packet" )
1005
1006 def CASE3000( self, main ):
Jon Hallfc951072017-05-24 15:55:34 -07001007 """
alisone14d7b02016-07-06 10:31:51 -07001008 Delete flow
Jon Hallfc951072017-05-24 15:55:34 -07001009 """
alisone14d7b02016-07-06 10:31:51 -07001010 import json
1011
1012 main.case( "Delete flows that were added through rest" )
1013 main.step( "Deleting flows" )
Devin Lim142b5342017-07-20 15:22:39 -07001014 ctrl = main.Cluster.active( 0 )
alisone14d7b02016-07-06 10:31:51 -07001015 main.log.info( "Getting flows" )
1016 try:
Devin Lim142b5342017-07-20 15:22:39 -07001017 flows = json.loads( ctrl.REST.flows() )
alisone14d7b02016-07-06 10:31:51 -07001018
1019 stepResult = main.TRUE
1020 for f in flows:
1021 if "rest" in f.get( "appId" ):
Jon Hallfc951072017-05-24 15:55:34 -07001022 if main.debug:
Devin Lim142b5342017-07-20 15:22:39 -07001023 main.log.debug( "Flow to be deleted:\n{}".format( ctrl.REST.pprint( f ) ) )
1024 stepResult = stepResult and ctrl.REST.removeFlow( f.get( "deviceId" ), f.get( "id" ) )
alisone14d7b02016-07-06 10:31:51 -07001025 except TypeError:
1026 main.log.error( "No Flows found by the REST API" )
1027 stepResult = main.FALSE
1028 except ValueError:
1029 main.log.error( "Problem getting Flows state from REST API. Exiting test" )
Devin Lim44075962017-08-11 10:56:37 -07001030 main.cleanAndExit()
GlennRC956ea742015-11-05 16:14:15 -08001031
1032 utilities.assert_equals( expect=main.TRUE,
1033 actual=stepResult,
1034 onpass="Successfully deleting flows",
1035 onfail="Failed to delete flows" )
1036
1037 time.sleep( main.delFlowSleep )
1038
Jon Hallfc951072017-05-24 15:55:34 -07001039 def CASE1200( self, main ):
1040 """
alisone14d7b02016-07-06 10:31:51 -07001041 Add flows with a ARP selector and verify the flow
Jon Hallfc951072017-05-24 15:55:34 -07001042 """
alisone14d7b02016-07-06 10:31:51 -07001043 import json
1044 import time
1045
1046 main.case( "Verify flow IP selectors are correctly compiled" )
1047 main.caseExplanation = "Install two flows with only IP selectors " + \
1048 "specified, then verify flows are added in ONOS, finally " + \
1049 "send a packet that only specifies the IP src and dst."
1050
1051 main.step( "Add flows with ARP addresses as the only selectors" )
1052
1053 main.log.info( "Creating host components" )
1054 main.Scapy.createHostComponent( "h1" )
1055 main.Scapy.createHostComponent( "h2" )
1056 hosts = [ main.h1, main.h2 ]
1057 for host in hosts:
Jon Hallfc951072017-05-24 15:55:34 -07001058 host.startHostCli()
1059 host.startScapy()
1060 host.updateSelf()
Devin Lim142b5342017-07-20 15:22:39 -07001061 ctrl = main.Cluster.active( 0 )
alisone14d7b02016-07-06 10:31:51 -07001062 # Add a flow that connects host1 on port1 to host2 on port2
1063 # send output on port2
1064 # recieve input on port1
1065 egress = 2
1066 ingress = 1
1067 # ARP etherType = 0x0806
1068 ethType = main.params[ 'TEST' ][ 'arpType' ]
1069
1070 # Add flows that connects host1 to host2
1071 main.log.info( "Add flow with port ingress 1 to port egress 2" )
Devin Lim142b5342017-07-20 15:22:39 -07001072 stepResult = ctrl.REST.addFlow( deviceId=main.swDPID,
1073 egressPort=egress,
1074 ingressPort=ingress,
1075 ethType=ethType,
1076 priority=40001,
1077 debug=main.debug )
alisone14d7b02016-07-06 10:31:51 -07001078
1079 utilities.assert_equals( expect=main.TRUE,
1080 actual=stepResult,
1081 onpass="Successfully added flows",
1082 onfail="Failed add flows" )
1083
1084 # Giving ONOS time to add the flow
1085 time.sleep( main.addFlowSleep )
1086
Devin Lim58046fa2017-07-05 16:55:00 -07001087 main.checkingFlow.checkFlow()
alisone14d7b02016-07-06 10:31:51 -07001088
1089 main.step( "Send a packet to verify the flow is correct" )
1090
1091 main.log.info( "Constructing packet" )
1092 # No need for the MAC src dst
1093 main.h1.buildEther( src=main.h1.hostMac, dst=main.h2.hostMac )
1094 main.h1.buildARP( pdst=main.h2.hostIp )
1095
1096 main.log.info( "Starting filter on host2" )
1097 # Defaults to ip
1098 main.h2.startFilter( pktFilter="arp" )
1099
1100 main.log.info( "Sending packet to host2" )
Jon Hallfc951072017-05-24 15:55:34 -07001101 main.h1.sendPacket()
alisone14d7b02016-07-06 10:31:51 -07001102
1103 main.log.info( "Checking filter for our packet" )
Jon Hallfc951072017-05-24 15:55:34 -07001104 stepResult = main.h2.checkFilter()
alisone14d7b02016-07-06 10:31:51 -07001105 if stepResult:
Jon Hallfc951072017-05-24 15:55:34 -07001106 main.log.info( "Packet: %s" % main.h2.readPackets() )
alisone14d7b02016-07-06 10:31:51 -07001107 else:
Jon Hallfc951072017-05-24 15:55:34 -07001108 main.h2.killFilter()
alisone14d7b02016-07-06 10:31:51 -07001109
1110 main.log.info( "Clean up host components" )
1111 for host in hosts:
Jon Hallfc951072017-05-24 15:55:34 -07001112 host.stopScapy()
alisone14d7b02016-07-06 10:31:51 -07001113 main.Mininet1.removeHostComponent( "h1" )
1114 main.Mininet1.removeHostComponent( "h2" )
1115
1116 utilities.assert_equals( expect=main.TRUE,
1117 actual=stepResult,
1118 onpass="Successfully sent a packet",
1119 onfail="Failed to send a packet" )
1120
1121 def CASE1800( self, main ):
Jon Hallfc951072017-05-24 15:55:34 -07001122 """
alisone14d7b02016-07-06 10:31:51 -07001123 Add flows with a SCTP selector and verify the flow
Jon Hallfc951072017-05-24 15:55:34 -07001124 """
alisone14d7b02016-07-06 10:31:51 -07001125 import json
1126 import time
1127
1128 main.case( "Verify the UDP selector is correctly compiled on the flow" )
1129 main.caseExplanation = "Install a flow with only the UDP selector " + \
1130 "specified, verify the flow is added in ONOS, and finally " + \
1131 "send a UDP packet to verify the UDP selector is compiled correctly."
1132
1133 main.step( "Add a flow with a SCTP selector" )
1134
1135 main.log.info( "Creating host components" )
1136 main.Scapy.createHostComponent( "h1" )
1137 main.Scapy.createHostComponent( "h2" )
1138 hosts = [ main.h1, main.h2 ]
1139 for host in hosts:
Jon Hallfc951072017-05-24 15:55:34 -07001140 host.startHostCli()
1141 host.startScapy()
1142 host.updateSelf()
alisone14d7b02016-07-06 10:31:51 -07001143
1144 # Add a flow that connects host1 on port1 to host2 on port2
1145 egress = 2
1146 ingress = 1
1147 # IPv4 etherType
1148 ethType = main.params[ 'TEST' ][ 'ip4Type' ]
1149 # IP protocol
1150 ipProto = main.params[ 'TEST' ][ 'sctpProto' ]
Devin Lim142b5342017-07-20 15:22:39 -07001151 ctrl = main.Cluster.active( 0 )
Jon Hallfc951072017-05-24 15:55:34 -07001152 main.log.info( "Add a flow that connects host1 on port1 to host2 on port2" )
Devin Lim142b5342017-07-20 15:22:39 -07001153 stepResult = ctrl.REST.addFlow( deviceId=main.swDPID,
1154 egressPort=egress,
1155 ingressPort=ingress,
1156 ethType=ethType,
1157 ipProto=ipProto,
1158 debug=main.debug )
alisone14d7b02016-07-06 10:31:51 -07001159
1160 utilities.assert_equals( expect=main.TRUE,
1161 actual=stepResult,
1162 onpass="Successfully added flows",
1163 onfail="Failed add flows" )
1164
1165 # Giving ONOS time to add the flow
1166 time.sleep( main.addFlowSleep )
1167
Devin Lim58046fa2017-07-05 16:55:00 -07001168 main.checkingFlow.checkFlow()
alisone14d7b02016-07-06 10:31:51 -07001169
1170 main.step( "Send a packet to verify the flow is correct" )
1171
1172 main.log.info( "Constructing packet" )
1173 # No need for the MAC src dst
1174 main.h1.buildEther( dst=main.h2.hostMac )
1175 main.h1.buildIP( dst=main.h2.hostIp )
Jon Hallfc951072017-05-24 15:55:34 -07001176 main.h1.buildSCTP()
alisone14d7b02016-07-06 10:31:51 -07001177
1178 main.log.info( "Starting filter on host2" )
1179 # Defaults to ip
1180 main.h2.startFilter( pktFilter="sctp" )
1181
1182 main.log.info( "Sending packet to host2" )
Jon Hallfc951072017-05-24 15:55:34 -07001183 main.h1.sendPacket()
alisone14d7b02016-07-06 10:31:51 -07001184
1185 main.log.info( "Checking filter for our packet" )
Jon Hallfc951072017-05-24 15:55:34 -07001186 stepResult = main.h2.checkFilter()
alisone14d7b02016-07-06 10:31:51 -07001187 if stepResult:
Jon Hallfc951072017-05-24 15:55:34 -07001188 main.log.info( "Packet: %s" % main.h2.readPackets() )
alisone14d7b02016-07-06 10:31:51 -07001189 else:
Jon Hallfc951072017-05-24 15:55:34 -07001190 main.h2.killFilter()
alisone14d7b02016-07-06 10:31:51 -07001191
1192 main.log.info( "Clean up host components" )
1193 for host in hosts:
Jon Hallfc951072017-05-24 15:55:34 -07001194 host.stopScapy()
alisone14d7b02016-07-06 10:31:51 -07001195 main.Mininet1.removeHostComponent( "h1" )
1196 main.Mininet1.removeHostComponent( "h2" )
1197
1198 utilities.assert_equals( expect=main.TRUE,
1199 actual=stepResult,
1200 onpass="Successfully sent a packet",
1201 onfail="Failed to send a packet" )
1202
GlennRC68449942015-10-16 16:03:12 -07001203 def CASE100( self, main ):
Jon Hallfc951072017-05-24 15:55:34 -07001204 """
GlennRC5147a422015-10-06 17:26:17 -07001205 Report errors/warnings/exceptions
Jon Hallfc951072017-05-24 15:55:34 -07001206 """
alisone14d7b02016-07-06 10:31:51 -07001207 main.log.info( "Error report: \n" )
Devin Lim142b5342017-07-20 15:22:39 -07001208 main.ONOSbench.logReport( main.Cluster.active( 0 ).ipAddress,
GlennRC5147a422015-10-06 17:26:17 -07001209 [ "INFO",
1210 "FOLLOWER",
1211 "WARN",
1212 "flow",
1213 "ERROR",
1214 "Except" ],
GlennRC68449942015-10-16 16:03:12 -07001215 "s" )