blob: e900648c52a7619650d04688bd094a067892d380 [file] [log] [blame]
Jeremy Ronquillob27ce4c2017-07-17 12:41:28 -07001"""
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -07002Copyright 2015 Open Networking Foundation ( ONF )
Jeremy Ronquillob27ce4c2017-07-17 12:41:28 -07003
4Please refer questions to either the onos test mailing list at <onos-test@onosproject.org>,
5the System Testing Plans and Results wiki page at <https://wiki.onosproject.org/x/voMg>,
6or the System Testing Guide page at <https://wiki.onosproject.org/x/WYQg>
7
8 TestON is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 2 of the License, or
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070011 ( at your option ) any later version.
Jeremy Ronquillob27ce4c2017-07-17 12:41:28 -070012
13 TestON is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with TestON. If not, see <http://www.gnu.org/licenses/>.
20"""
GlennRC5147a422015-10-06 17:26:17 -070021class FUNCflow:
22
23 def __init__( self ):
24 self.default = ''
25
26 def CASE1( self, main ):
GlennRC5147a422015-10-06 17:26:17 -070027 import os
28 import imp
Devin Lim58046fa2017-07-05 16:55:00 -070029 try:
30 from tests.dependencies.ONOSSetup import ONOSSetup
31 except ImportError:
32 main.log.error( "SetUp not found exiting the test" )
Devin Lim44075962017-08-11 10:56:37 -070033 main.cleanAndExit()
Devin Lim58046fa2017-07-05 16:55:00 -070034 try:
35 main.testSetUp
36 except ( NameError, AttributeError ):
37 main.testSetUp = ONOSSetup()
GlennRC5147a422015-10-06 17:26:17 -070038 """
39 - Construct tests variables
40 - GIT ( optional )
41 - Checkout ONOS master branch
42 - Pull latest ONOS code
GlennRC5147a422015-10-06 17:26:17 -070043 """
Devin Lim58046fa2017-07-05 16:55:00 -070044 main.testSetUp.envSetupDescription()
45 stepResult = main.FALSE
46 try:
47 # Test variables
48 main.cellName = main.params[ 'ENV' ][ 'cellName' ]
49 main.apps = main.params[ 'ENV' ][ 'cellApps' ]
50 main.ONOSport = main.params[ 'CTRL' ][ 'port' ]
51 main.dependencyPath = main.testOnDirectory + \
52 main.params[ 'DEPENDENCY' ][ 'path' ]
53 wrapperFile1 = main.params[ 'DEPENDENCY' ][ 'wrapper1' ]
54 wrapperFile2 = main.params[ 'DEPENDENCY' ][ 'wrapper2' ]
55 main.topology = main.params[ 'DEPENDENCY' ][ 'topology' ]
Devin Lim58046fa2017-07-05 16:55:00 -070056 main.startUpSleep = int( main.params[ 'SLEEP' ][ 'startup' ] )
57 main.startMNSleep = int( main.params[ 'SLEEP' ][ 'startMN' ] )
58 main.addFlowSleep = int( main.params[ 'SLEEP' ][ 'addFlow' ] )
59 main.delFlowSleep = int( main.params[ 'SLEEP' ][ 'delFlow' ] )
60 main.debug = main.params[ 'DEBUG' ]
61 main.swDPID = main.params[ 'TEST' ][ 'swDPID' ]
GlennRC5147a422015-10-06 17:26:17 -070062
Devin Lim58046fa2017-07-05 16:55:00 -070063 main.debug = True if "on" in main.debug else False
GlennRC956ea742015-11-05 16:14:15 -080064
Devin Lim58046fa2017-07-05 16:55:00 -070065 # -- INIT SECTION, ONLY RUNS ONCE -- #
GlennRC5147a422015-10-06 17:26:17 -070066
Devin Lim58046fa2017-07-05 16:55:00 -070067 try:
68 from tests.FUNC.FUNCflow.dependencies.checkingFlow import CheckingFlow
69 main.checkingFlow = CheckingFlow()
70 except ImportError as e:
71 print e
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070072 main.log.error( "CheckingFlow not found exiting the test" )
Devin Lim44075962017-08-11 10:56:37 -070073 main.cleanAndExit()
Devin Lim58046fa2017-07-05 16:55:00 -070074 copyResult = main.ONOSbench.scp( main.Mininet1,
75 main.dependencyPath + main.topology,
76 main.Mininet1.home + '/custom/',
77 direction="to" )
GlennRC5147a422015-10-06 17:26:17 -070078
Devin Lim58046fa2017-07-05 16:55:00 -070079 utilities.assert_equals( expect=main.TRUE,
80 actual=copyResult,
81 onpass="Successfully copy " + "test variables ",
82 onfail="Failed to copy test variables" )
GlennRC5147a422015-10-06 17:26:17 -070083
Devin Lim58046fa2017-07-05 16:55:00 -070084 stepResult = main.testSetUp.envSetup()
GlennRC1704d072015-10-07 18:40:45 -070085
Devin Lim58046fa2017-07-05 16:55:00 -070086 except Exception as e:
87 main.testSetUp.envSetupException( e )
88 main.testSetUp.evnSetupConclusion( stepResult )
Devin Lim8d7c7782017-06-07 16:21:20 -070089
GlennRC5147a422015-10-06 17:26:17 -070090 def CASE2( self, main ):
91 """
92 - Set up cell
93 - Create cell file
94 - Set cell file
95 - Verify cell file
Devin Lim58046fa2017-07-05 16:55:00 -070096 - Building ONOS
97 - Install ONOS package
98 - Build ONOS package
GlennRC5147a422015-10-06 17:26:17 -070099 - Kill ONOS process
100 - Uninstall ONOS cluster
101 - Verify ONOS start up
102 - Install ONOS cluster
103 - Connect to cli
104 """
Devin Lim142b5342017-07-20 15:22:39 -0700105 main.testSetUp.ONOSSetUp( main.Mininet1, main.Cluster )
GlennRC5147a422015-10-06 17:26:17 -0700106
GlennRC68449942015-10-16 16:03:12 -0700107 def CASE10( self, main ):
Jon Hallfc951072017-05-24 15:55:34 -0700108 """
GlennRC68449942015-10-16 16:03:12 -0700109 Start Mininet
Jon Hallfc951072017-05-24 15:55:34 -0700110 """
GlennRC073e8bc2015-10-27 17:11:28 -0700111 import json
Devin Lim58046fa2017-07-05 16:55:00 -0700112 import time
113 try:
114 from tests.dependencies.topology import Topology
115 except ImportError:
116 main.log.error( "Topology not found exiting the test" )
Devin Lim44075962017-08-11 10:56:37 -0700117 main.cleanAndExit()
Devin Lim58046fa2017-07-05 16:55:00 -0700118 try:
119 main.topoRelated
120 except ( NameError, AttributeError ):
121 main.topoRelated = Topology()
GlennRC073e8bc2015-10-27 17:11:28 -0700122
123 main.case( "Setup mininet and compare ONOS topology view to Mininet topology" )
124 main.caseExplanation = "Start mininet with custom topology and compare topology " +\
125 "elements between Mininet and ONOS"
126
GlennRC68449942015-10-16 16:03:12 -0700127 main.step( "Setup Mininet Topology" )
128 topology = main.Mininet1.home + '/custom/' + main.topology
Jon Hallfc951072017-05-24 15:55:34 -0700129 stepResult = main.Mininet1.startNet( topoFile=topology )
GlennRC68449942015-10-16 16:03:12 -0700130
131 utilities.assert_equals( expect=main.TRUE,
GlennRC073e8bc2015-10-27 17:11:28 -0700132 actual=stepResult,
GlennRC68449942015-10-16 16:03:12 -0700133 onpass="Successfully loaded topology",
134 onfail="Failed to load topology" )
135
GlennRC073e8bc2015-10-27 17:11:28 -0700136 main.step( "Assign switch to controller" )
Devin Lim142b5342017-07-20 15:22:39 -0700137 stepResult = main.Mininet1.assignSwController( "s1", main.Cluster.active( 0 ).ipAddress )
GlennRC68449942015-10-16 16:03:12 -0700138
139 utilities.assert_equals( expect=main.TRUE,
GlennRC073e8bc2015-10-27 17:11:28 -0700140 actual=stepResult,
141 onpass="Successfully assigned switch to controller",
142 onfail="Failed to assign switch to controller" )
GlennRC68449942015-10-16 16:03:12 -0700143
GlennRC073e8bc2015-10-27 17:11:28 -0700144 time.sleep( main.startMNSleep )
GlennRC68449942015-10-16 16:03:12 -0700145
Devin Lim58046fa2017-07-05 16:55:00 -0700146 main.topoRelated.compareTopos( main.Mininet1 )
GlennRC68449942015-10-16 16:03:12 -0700147
Jon Hall892818c2015-10-20 17:58:34 -0700148 def CASE66( self, main ):
Jon Hallfc951072017-05-24 15:55:34 -0700149 """
Jon Hall892818c2015-10-20 17:58:34 -0700150 Testing scapy
Jon Hallfc951072017-05-24 15:55:34 -0700151 """
Jon Hall892818c2015-10-20 17:58:34 -0700152 main.case( "Testing scapy" )
153 main.step( "Creating Host1 component" )
Jon Halla510a8a2016-05-04 15:09:28 -0700154 main.Scapy.createHostComponent( "h1" )
155 main.Scapy.createHostComponent( "h2" )
alisone14d7b02016-07-06 10:31:51 -0700156 hosts = [ main.h1, main.h2 ]
Jon Hall892818c2015-10-20 17:58:34 -0700157 for host in hosts:
Jon Hallfc951072017-05-24 15:55:34 -0700158 host.startHostCli()
159 host.startScapy()
160 host.updateSelf()
Jon Hall892818c2015-10-20 17:58:34 -0700161 main.log.debug( host.name )
162 main.log.debug( host.hostIp )
163 main.log.debug( host.hostMac )
164
165 main.step( "Sending/Receiving Test packet - Filter doesn't match" )
Jon Halla510a8a2016-05-04 15:09:28 -0700166 main.log.info( "Starting Filter..." )
Jon Hallfc951072017-05-24 15:55:34 -0700167 main.h2.startFilter()
Jon Halla510a8a2016-05-04 15:09:28 -0700168 main.log.info( "Building Ether frame..." )
Jon Hall892818c2015-10-20 17:58:34 -0700169 main.h1.buildEther( dst=main.h2.hostMac )
Jon Halla510a8a2016-05-04 15:09:28 -0700170 main.log.info( "Sending Packet..." )
Jon Hallfc951072017-05-24 15:55:34 -0700171 main.h1.sendPacket()
Jon Halla510a8a2016-05-04 15:09:28 -0700172 main.log.info( "Checking Filter..." )
Jon Hallfc951072017-05-24 15:55:34 -0700173 finished = main.h2.checkFilter()
Jon Halla510a8a2016-05-04 15:09:28 -0700174 main.log.debug( finished )
Jon Hall892818c2015-10-20 17:58:34 -0700175 i = ""
176 if finished:
Jon Hallfc951072017-05-24 15:55:34 -0700177 a = main.h2.readPackets()
178 for i in a.splitlines():
Jon Hall892818c2015-10-20 17:58:34 -0700179 main.log.info( i )
180 else:
Jon Hallfc951072017-05-24 15:55:34 -0700181 kill = main.h2.killFilter()
Jon Hall892818c2015-10-20 17:58:34 -0700182 main.log.debug( kill )
183 main.h2.handle.sendline( "" )
184 main.h2.handle.expect( main.h2.scapyPrompt )
185 main.log.debug( main.h2.handle.before )
186 utilities.assert_equals( expect=True,
187 actual="dst=00:00:00:00:00:02 src=00:00:00:00:00:01" in i,
188 onpass="Pass",
189 onfail="Fail" )
190
191 main.step( "Sending/Receiving Test packet - Filter matches" )
Jon Hallfc951072017-05-24 15:55:34 -0700192 main.h2.startFilter()
Jon Hall892818c2015-10-20 17:58:34 -0700193 main.h1.buildEther( dst=main.h2.hostMac )
194 main.h1.buildIP( dst=main.h2.hostIp )
Jon Hallfc951072017-05-24 15:55:34 -0700195 main.h1.sendPacket()
196 finished = main.h2.checkFilter()
Jon Hall892818c2015-10-20 17:58:34 -0700197 i = ""
198 if finished:
Jon Hallfc951072017-05-24 15:55:34 -0700199 a = main.h2.readPackets()
200 for i in a.splitlines():
Jon Hall892818c2015-10-20 17:58:34 -0700201 main.log.info( i )
202 else:
Jon Hallfc951072017-05-24 15:55:34 -0700203 kill = main.h2.killFilter()
Jon Hall892818c2015-10-20 17:58:34 -0700204 main.log.debug( kill )
205 main.h2.handle.sendline( "" )
206 main.h2.handle.expect( main.h2.scapyPrompt )
207 main.log.debug( main.h2.handle.before )
208 utilities.assert_equals( expect=True,
209 actual="dst=00:00:00:00:00:02 src=00:00:00:00:00:01" in i,
210 onpass="Pass",
211 onfail="Fail" )
212
Jon Hall892818c2015-10-20 17:58:34 -0700213 main.step( "Clean up host components" )
214 for host in hosts:
Jon Hallfc951072017-05-24 15:55:34 -0700215 host.stopScapy()
alisone14d7b02016-07-06 10:31:51 -0700216 main.Mininet1.removeHostComponent( "h1" )
217 main.Mininet1.removeHostComponent( "h2" )
Jon Hall892818c2015-10-20 17:58:34 -0700218
GlennRC68449942015-10-16 16:03:12 -0700219 def CASE1000( self, main ):
Jon Hallfc951072017-05-24 15:55:34 -0700220 """
GlennRC073e8bc2015-10-27 17:11:28 -0700221 Add flows with MAC selectors and verify the flows
Jon Hallfc951072017-05-24 15:55:34 -0700222 """
GlennRC073e8bc2015-10-27 17:11:28 -0700223 import json
224 import time
Devin Lim142b5342017-07-20 15:22:39 -0700225 ctrl = main.Cluster.active( 0 )
GlennRC073e8bc2015-10-27 17:11:28 -0700226 main.case( "Verify flow MAC selectors are correctly compiled" )
227 main.caseExplanation = "Install two flows with only MAC selectors " +\
Jon Hallfc951072017-05-24 15:55:34 -0700228 "specified, then verify flows are added in ONOS, finally " +\
GlennRC073e8bc2015-10-27 17:11:28 -0700229 "send a packet that only specifies the MAC src and dst."
GlennRC68449942015-10-16 16:03:12 -0700230
GlennRC073e8bc2015-10-27 17:11:28 -0700231 main.step( "Add flows with MAC addresses as the only selectors" )
GlennRC68449942015-10-16 16:03:12 -0700232
GlennRC073e8bc2015-10-27 17:11:28 -0700233 main.log.info( "Creating host components" )
Jon Halla510a8a2016-05-04 15:09:28 -0700234 main.Scapy.createHostComponent( "h1" )
235 main.Scapy.createHostComponent( "h2" )
alisone14d7b02016-07-06 10:31:51 -0700236 hosts = [ main.h1, main.h2 ]
GlennRC073e8bc2015-10-27 17:11:28 -0700237 for host in hosts:
Jon Hallfc951072017-05-24 15:55:34 -0700238 host.startHostCli()
239 host.startScapy()
240 host.updateSelf()
GlennRC68449942015-10-16 16:03:12 -0700241
GlennRC073e8bc2015-10-27 17:11:28 -0700242 # Add a flow that connects host1 on port1 to host2 on port2
243 # send output on port2
244 # recieve input on port1
245 egress = 2
246 ingress = 1
247
248 # Add flows that sends packets from port1 to port2 with correct
249 # MAC src and dst addresses
250 main.log.info( "Adding flow with MAC selectors" )
Devin Lim142b5342017-07-20 15:22:39 -0700251 stepResult = ctrl.REST.addFlow( deviceId=main.swDPID,
252 egressPort=egress,
253 ingressPort=ingress,
254 ethSrc=main.h1.hostMac,
255 ethDst=main.h2.hostMac,
256 debug=main.debug )
GlennRC68449942015-10-16 16:03:12 -0700257
GlennRCa5391372015-10-14 17:28:15 -0700258 utilities.assert_equals( expect=main.TRUE,
259 actual=stepResult,
GlennRC68449942015-10-16 16:03:12 -0700260 onpass="Successfully added flows",
261 onfail="Failed add flows" )
GlennRCa5391372015-10-14 17:28:15 -0700262
GlennRC073e8bc2015-10-27 17:11:28 -0700263 # Giving ONOS time to add the flows
264 time.sleep( main.addFlowSleep )
GlennRC5147a422015-10-06 17:26:17 -0700265
Devin Lim142b5342017-07-20 15:22:39 -0700266 main.checkingFlow.checkFlow()
GlennRC956ea742015-11-05 16:14:15 -0800267
GlennRC073e8bc2015-10-27 17:11:28 -0700268 main.step( "Send a packet to verify the flows are correct" )
269
270 # Specify the src and dst MAC addr
271 main.log.info( "Constructing packet" )
272 main.h1.buildEther( src=main.h1.hostMac, dst=main.h2.hostMac )
273
274 # Filter for packets with the correct host name. Otherwise,
275 # the filter we catch any packet that is sent to host2
276 # NOTE: I believe it doesn't matter which host name it is,
GlennRC956ea742015-11-05 16:14:15 -0800277 # as long as the src and dst are both specified
GlennRC073e8bc2015-10-27 17:11:28 -0700278 main.log.info( "Starting filter on host2" )
alisone14d7b02016-07-06 10:31:51 -0700279 main.h2.startFilter( pktFilter="ether host %s" % main.h1.hostMac )
GlennRC073e8bc2015-10-27 17:11:28 -0700280
281 main.log.info( "Sending packet to host2" )
282 main.h1.sendPacket()
283
284 main.log.info( "Checking filter for our packet" )
Jon Hallfc951072017-05-24 15:55:34 -0700285 stepResult = main.h2.checkFilter()
GlennRC073e8bc2015-10-27 17:11:28 -0700286 if stepResult:
Jon Hallfc951072017-05-24 15:55:34 -0700287 main.log.info( "Packet: %s" % main.h2.readPackets() )
alisone14d7b02016-07-06 10:31:51 -0700288 else:
Jon Hallfc951072017-05-24 15:55:34 -0700289 main.h2.killFilter()
GlennRC073e8bc2015-10-27 17:11:28 -0700290
291 main.log.info( "Clean up host components" )
292 for host in hosts:
Jon Hallfc951072017-05-24 15:55:34 -0700293 host.stopScapy()
alisone14d7b02016-07-06 10:31:51 -0700294 main.Mininet1.removeHostComponent( "h1" )
295 main.Mininet1.removeHostComponent( "h2" )
GlennRC073e8bc2015-10-27 17:11:28 -0700296
297 utilities.assert_equals( expect=main.TRUE,
298 actual=stepResult,
299 onpass="Successfully sent a packet",
300 onfail="Failed to send a packet" )
301
alisone14d7b02016-07-06 10:31:51 -0700302 def CASE1400( self, main ):
Jon Hallfc951072017-05-24 15:55:34 -0700303 """
GlennRC073e8bc2015-10-27 17:11:28 -0700304 Add flows with IPv4 selectors and verify the flows
Jon Hallfc951072017-05-24 15:55:34 -0700305 """
GlennRC68449942015-10-16 16:03:12 -0700306 import json
GlennRC073e8bc2015-10-27 17:11:28 -0700307 import time
Devin Lim142b5342017-07-20 15:22:39 -0700308 ctrl = main.Cluster.active( 0 )
GlennRC073e8bc2015-10-27 17:11:28 -0700309 main.case( "Verify flow IP selectors are correctly compiled" )
310 main.caseExplanation = "Install two flows with only IP selectors " +\
alisone14d7b02016-07-06 10:31:51 -0700311 "specified, then verify flows are added in ONOS, finally " +\
GlennRC073e8bc2015-10-27 17:11:28 -0700312 "send a packet that only specifies the IP src and dst."
313
314 main.step( "Add flows with IPv4 addresses as the only selectors" )
315
316 main.log.info( "Creating host components" )
Jon Halla510a8a2016-05-04 15:09:28 -0700317 main.Scapy.createHostComponent( "h1" )
318 main.Scapy.createHostComponent( "h2" )
alisone14d7b02016-07-06 10:31:51 -0700319 hosts = [ main.h1, main.h2 ]
GlennRC073e8bc2015-10-27 17:11:28 -0700320 for host in hosts:
Jon Hallfc951072017-05-24 15:55:34 -0700321 host.startHostCli()
322 host.startScapy()
323 host.updateSelf()
GlennRC073e8bc2015-10-27 17:11:28 -0700324
325 # Add a flow that connects host1 on port1 to host2 on port2
326 # send output on port2
327 # recieve input on port1
328 egress = 2
329 ingress = 1
330 # IPv4 etherType = 0x800
alisone14d7b02016-07-06 10:31:51 -0700331 ethType = main.params[ 'TEST' ][ 'ip4Type' ]
GlennRC073e8bc2015-10-27 17:11:28 -0700332
333 # Add flows that connects host1 to host2
334 main.log.info( "Add flow with port ingress 1 to port egress 2" )
Devin Lim142b5342017-07-20 15:22:39 -0700335 stepResult = ctrl.REST.addFlow( deviceId=main.swDPID,
336 egressPort=egress,
337 ingressPort=ingress,
338 ethType=ethType,
339 ipSrc=( "IPV4_SRC", main.h1.hostIp + "/32" ),
340 ipDst=( "IPV4_DST", main.h2.hostIp + "/32" ),
341 debug=main.debug )
GlennRC073e8bc2015-10-27 17:11:28 -0700342
343 utilities.assert_equals( expect=main.TRUE,
344 actual=stepResult,
345 onpass="Successfully added flows",
346 onfail="Failed add flows" )
347
348 # Giving ONOS time to add the flow
349 time.sleep( main.addFlowSleep )
350
Devin Lim58046fa2017-07-05 16:55:00 -0700351 main.checkingFlow.checkFlow()
GlennRC956ea742015-11-05 16:14:15 -0800352
GlennRC073e8bc2015-10-27 17:11:28 -0700353 main.step( "Send a packet to verify the flow is correct" )
354
355 main.log.info( "Constructing packet" )
356 # No need for the MAC src dst
357 main.h1.buildEther( dst=main.h2.hostMac )
358 main.h1.buildIP( src=main.h1.hostIp, dst=main.h2.hostIp )
359
360 main.log.info( "Starting filter on host2" )
361 # Defaults to ip
Jon Hallfc951072017-05-24 15:55:34 -0700362 main.h2.startFilter()
GlennRC073e8bc2015-10-27 17:11:28 -0700363
364 main.log.info( "Sending packet to host2" )
Jon Hallfc951072017-05-24 15:55:34 -0700365 main.h1.sendPacket()
GlennRC073e8bc2015-10-27 17:11:28 -0700366
367 main.log.info( "Checking filter for our packet" )
Jon Hallfc951072017-05-24 15:55:34 -0700368 stepResult = main.h2.checkFilter()
GlennRC073e8bc2015-10-27 17:11:28 -0700369 if stepResult:
Jon Hallfc951072017-05-24 15:55:34 -0700370 main.log.info( "Packet: %s" % main.h2.readPackets() )
371 else:
372 main.h2.killFilter()
GlennRC073e8bc2015-10-27 17:11:28 -0700373
374 main.log.info( "Clean up host components" )
375 for host in hosts:
Jon Hallfc951072017-05-24 15:55:34 -0700376 host.stopScapy()
alisone14d7b02016-07-06 10:31:51 -0700377 main.Mininet1.removeHostComponent( "h1" )
378 main.Mininet1.removeHostComponent( "h2" )
GlennRC073e8bc2015-10-27 17:11:28 -0700379
380 utilities.assert_equals( expect=main.TRUE,
381 actual=stepResult,
382 onpass="Successfully sent a packet",
383 onfail="Failed to send a packet" )
384
Jon Hallfc951072017-05-24 15:55:34 -0700385 def CASE1500( self, main ):
alisone14d7b02016-07-06 10:31:51 -0700386 """
387 Add flow with IPv6 selector and verify the flow
388 """
389 import json
390 import time
391 main.case( "Verify IPv6 selector is correctly compiled" )
392 main.caseExplanation = "Install two flows with only IP selectors " + \
393 "specified, then verify flows are added in ONOS, finally " + \
394 "send a packet that only specifies the IP src and dst."
395
396 main.step( "Add flows with IPv6 addresses as the only selectors" )
397
398 main.log.info( "Creating host components" )
Devin Lim142b5342017-07-20 15:22:39 -0700399 ctrl = main.Cluster.active( 0 )
alisone14d7b02016-07-06 10:31:51 -0700400 main.Scapy.createHostComponent( "h5" )
401 main.Scapy.createHostComponent( "h6" )
402 hosts = [ main.h5, main.h6 ]
403
404 for host in hosts:
Jon Hallfc951072017-05-24 15:55:34 -0700405 host.startHostCli()
406 host.startScapy()
alisone14d7b02016-07-06 10:31:51 -0700407 host.updateSelf( IPv6=True )
408
409 # Add a flow that connects host1 on port1 to host2 on port2
410 # send output on port2
411 # recieve input on port1
412 egress = 6
413 ingress = 5
414 # IPv6 etherType = 0x86DD
415 ethType = main.params[ 'TEST' ][ 'ip6Type' ]
416
417 # Add flows that connects host1 to host2
418 main.log.info( "Add flow with port ingress 5 to port egress 6" )
Devin Lim142b5342017-07-20 15:22:39 -0700419 stepResult = ctrl.REST.addFlow( deviceId=main.swDPID,
420 egressPort=egress,
421 ingressPort=ingress,
422 ethType=ethType,
423 ipSrc=( "IPV6_SRC", main.h5.hostIp + "/128" ),
424 ipDst=( "IPV6_DST", main.h6.hostIp + "/128" ),
425 debug=main.debug )
alisone14d7b02016-07-06 10:31:51 -0700426
427 utilities.assert_equals( expect=main.TRUE,
428 actual=stepResult,
429 onpass="Successfully added flows",
430 onfail="Failed add flows" )
431
432 # Giving ONOS time to add the flow
433 time.sleep( main.addFlowSleep )
434
Devin Lim58046fa2017-07-05 16:55:00 -0700435 main.checkingFlow.checkFlow()
alisone14d7b02016-07-06 10:31:51 -0700436
437 main.step( "Send a packet to verify the flow is correct" )
438
439 main.log.info( "Constructing packet" )
440 # No need for the MAC src dst
441 main.h5.buildEther( dst=main.h6.hostMac )
442 main.h5.buildIPv6( src=main.h5.hostIp, dst=main.h6.hostIp )
443
444 main.log.info( "Starting filter on host6" )
445 # Defaults to ip
446 main.h6.startFilter( pktFilter="ip6" )
447 main.log.info( "Sending packet to host6" )
Jon Hallfc951072017-05-24 15:55:34 -0700448 main.h5.sendPacket()
alisone14d7b02016-07-06 10:31:51 -0700449
450 main.log.info( "Checking filter for our packet" )
Jon Hallfc951072017-05-24 15:55:34 -0700451 stepResult = main.h6.checkFilter()
alisone14d7b02016-07-06 10:31:51 -0700452 if stepResult:
Jon Hallfc951072017-05-24 15:55:34 -0700453 main.log.info( "Packet: %s" % main.h6.readPackets() )
alisone14d7b02016-07-06 10:31:51 -0700454 else:
Jon Hallfc951072017-05-24 15:55:34 -0700455 main.h6.killFilter()
alisone14d7b02016-07-06 10:31:51 -0700456
457 main.log.info( "Clean up host components" )
458 for host in hosts:
Jon Hallfc951072017-05-24 15:55:34 -0700459 host.stopScapy()
alisone14d7b02016-07-06 10:31:51 -0700460 main.Mininet1.removeHostComponent( "h5" )
461 main.Mininet1.removeHostComponent( "h6" )
462
463 utilities.assert_equals( expect=main.TRUE,
464 actual=stepResult,
465 onpass="Successfully sent a packet",
466 onfail="Failed to send a packet" )
467
alisone14d7b02016-07-06 10:31:51 -0700468 def CASE1100( self, main ):
Jon Hallfc951072017-05-24 15:55:34 -0700469 """
GlennRC073e8bc2015-10-27 17:11:28 -0700470 Add flow with VLAN selector and verify the flow
Jon Hallfc951072017-05-24 15:55:34 -0700471 """
GlennRC073e8bc2015-10-27 17:11:28 -0700472 import json
473 import time
474
475 main.case( "Verify VLAN selector is correctly compiled" )
476 main.caseExplanation = "Install one flow with only the VLAN selector " +\
Jon Hallfc951072017-05-24 15:55:34 -0700477 "specified, then verify the flow is added in ONOS, and finally " +\
GlennRC073e8bc2015-10-27 17:11:28 -0700478 "broadcast a packet with the correct VLAN tag."
479
480 # We do this here to utilize the hosts information
481 main.log.info( "Creating host components" )
Devin Lim142b5342017-07-20 15:22:39 -0700482 ctrl = main.Cluster.active( 0 )
Jon Halla510a8a2016-05-04 15:09:28 -0700483 main.Scapy.createHostComponent( "h3" )
484 main.Scapy.createHostComponent( "h4" )
alisone14d7b02016-07-06 10:31:51 -0700485 hosts = [ main.h3, main.h4 ]
GlennRC073e8bc2015-10-27 17:11:28 -0700486 for host in hosts:
Jon Hallfc951072017-05-24 15:55:34 -0700487 host.startHostCli()
488 host.startScapy()
489 host.updateSelf()
GlennRC073e8bc2015-10-27 17:11:28 -0700490
491 main.step( "Add a flow with the VLAN tag as the only selector" )
492
493 # Add flows that connects the two vlan hosts h3 and h4
494 # Host 3 is on port 3 and host 4 is on port 4
495 vlan = main.params[ 'TEST' ][ 'vlan' ]
496 egress = 4
497 ingress = 3
498 # VLAN ethType = 0x8100
alisone14d7b02016-07-06 10:31:51 -0700499 ethType = main.params[ 'TEST' ][ 'vlanType' ]
GlennRC073e8bc2015-10-27 17:11:28 -0700500
501 # Add only one flow because we don't need a response
502 main.log.info( "Add flow with port ingress 1 to port egress 2" )
Devin Lim142b5342017-07-20 15:22:39 -0700503 stepResult = ctrl.REST.addFlow( deviceId=main.swDPID,
504 egressPort=egress,
505 ingressPort=ingress,
506 ethType=ethType,
507 vlan=vlan,
508 debug=main.debug )
GlennRC073e8bc2015-10-27 17:11:28 -0700509
GlennRC073e8bc2015-10-27 17:11:28 -0700510 utilities.assert_equals( expect=main.TRUE,
511 actual=stepResult,
512 onpass="Successfully added flow",
513 onfail="Failed add flows" )
514
515 # Giving ONOS time to add the flows
516 time.sleep( main.addFlowSleep )
517
Devin Lim142b5342017-07-20 15:22:39 -0700518 main.checkingFlow.checkFlow()
GlennRC956ea742015-11-05 16:14:15 -0800519
GlennRC073e8bc2015-10-27 17:11:28 -0700520 main.step( "Send a packet to verify the flow are correct" )
521
522 # The receiving interface
alisone14d7b02016-07-06 10:31:51 -0700523 recIface = "{}-eth0.{}".format( main.h4.name, vlan )
GlennRC073e8bc2015-10-27 17:11:28 -0700524 main.log.info( "Starting filter on host2" )
525 # Filter is setup to catch any packet on the vlan interface with the correct vlan tag
Jon Hallfc951072017-05-24 15:55:34 -0700526 main.h4.startFilter( ifaceName=recIface, pktFilter="" )
GlennRC073e8bc2015-10-27 17:11:28 -0700527
528 # Broadcast the packet on the vlan interface. We only care if the flow forwards
529 # the packet with the correct vlan tag, not if the mac addr is correct
alisone14d7b02016-07-06 10:31:51 -0700530 sendIface = "{}-eth0.{}".format( main.h3.name, vlan )
GlennRC073e8bc2015-10-27 17:11:28 -0700531 main.log.info( "Broadcasting the packet with a vlan tag" )
GlennRC956ea742015-11-05 16:14:15 -0800532 main.h3.sendPacket( iface=sendIface,
alisone14d7b02016-07-06 10:31:51 -0700533 packet="Ether()/Dot1Q(vlan={})".format( vlan ) )
GlennRC073e8bc2015-10-27 17:11:28 -0700534
535 main.log.info( "Checking filter for our packet" )
Jon Hallfc951072017-05-24 15:55:34 -0700536 stepResult = main.h4.checkFilter()
GlennRC073e8bc2015-10-27 17:11:28 -0700537 if stepResult:
Jon Hallfc951072017-05-24 15:55:34 -0700538 main.log.info( "Packet: %s" % main.h4.readPackets() )
539 else:
540 main.h4.killFilter()
GlennRC073e8bc2015-10-27 17:11:28 -0700541
542 main.log.info( "Clean up host components" )
543 for host in hosts:
Jon Hallfc951072017-05-24 15:55:34 -0700544 host.stopScapy()
alisone14d7b02016-07-06 10:31:51 -0700545 main.Mininet1.removeHostComponent( "h3" )
546 main.Mininet1.removeHostComponent( "h4" )
GlennRC073e8bc2015-10-27 17:11:28 -0700547
548 utilities.assert_equals( expect=main.TRUE,
549 actual=stepResult,
550 onpass="Successfully sent a packet",
551 onfail="Failed to send a packet" )
GlennRC68449942015-10-16 16:03:12 -0700552
GlennRC956ea742015-11-05 16:14:15 -0800553 def CASE1300( self, main ):
Jon Hallfc951072017-05-24 15:55:34 -0700554 """
GlennRC956ea742015-11-05 16:14:15 -0800555 Add flows with MPLS selector and verify the flows
Jon Hallfc951072017-05-24 15:55:34 -0700556 """
GlennRC956ea742015-11-05 16:14:15 -0800557 import json
558 import time
559
560 main.case( "Verify the MPLS selector is correctly compiled on the flow." )
561 main.caseExplanation = "Install one flow with an MPLS selector, " +\
alisone14d7b02016-07-06 10:31:51 -0700562 "verify the flow is added in ONOS, and finally " +\
GlennRC956ea742015-11-05 16:14:15 -0800563 "send a packet via scapy that has a MPLS label."
564
565 main.step( "Add a flow with a MPLS selector" )
566
567 main.log.info( "Creating host components" )
Devin Lim142b5342017-07-20 15:22:39 -0700568 ctrl = main.Cluster.active( 0 )
Jon Halla510a8a2016-05-04 15:09:28 -0700569 main.Scapy.createHostComponent( "h1" )
570 main.Scapy.createHostComponent( "h2" )
alisone14d7b02016-07-06 10:31:51 -0700571 hosts = [ main.h1, main.h2 ]
GlennRC956ea742015-11-05 16:14:15 -0800572 for host in hosts:
Jon Hallfc951072017-05-24 15:55:34 -0700573 host.startHostCli()
GlennRC956ea742015-11-05 16:14:15 -0800574 host.startScapy( main.dependencyPath )
Jon Hallfc951072017-05-24 15:55:34 -0700575 host.updateSelf()
GlennRC956ea742015-11-05 16:14:15 -0800576
577 # ports
578 egress = 2
579 ingress = 1
580 # MPLS etherType
581 ethType = main.params[ 'TEST' ][ 'mplsType' ]
582 # MPLS label
583 mplsLabel = main.params[ 'TEST' ][ 'mpls' ]
584
585 # Add a flow that connects host1 on port1 to host2 on port2
586 main.log.info( "Adding flow with MPLS selector" )
Devin Lim142b5342017-07-20 15:22:39 -0700587 stepResult = ctrl.REST.addFlow( deviceId=main.swDPID,
588 egressPort=egress,
589 ingressPort=ingress,
590 ethType=ethType,
591 mpls=mplsLabel,
592 debug=main.debug )
GlennRC956ea742015-11-05 16:14:15 -0800593
594 utilities.assert_equals( expect=main.TRUE,
595 actual=stepResult,
596 onpass="Successfully added flow",
597 onfail="Failed add flow" )
598
599 # Giving ONOS time to add the flow
600 time.sleep( main.addFlowSleep )
601
602 main.step( "Check flow is in the ADDED state" )
603
604 main.log.info( "Get the flows from ONOS" )
Jeremy86160992016-04-11 10:05:53 -0700605 try:
Devin Lim142b5342017-07-20 15:22:39 -0700606 flows = json.loads( ctrl.REST.flows() )
GlennRC956ea742015-11-05 16:14:15 -0800607
Jeremy86160992016-04-11 10:05:53 -0700608 stepResult = main.TRUE
609 for f in flows:
alisone14d7b02016-07-06 10:31:51 -0700610 if "rest" in f.get( "appId" ):
611 if "ADDED" not in f.get( "state" ):
Jeremy86160992016-04-11 10:05:53 -0700612 stepResult = main.FALSE
alisone14d7b02016-07-06 10:31:51 -0700613 main.log.error( "Flow: %s in state: %s" % ( f.get( "id" ), f.get( "state" ) ) )
Jeremy86160992016-04-11 10:05:53 -0700614 except TypeError:
615 main.log.error( "No Flows found by the REST API" )
616 stepResult = main.FALSE
617 except ValueError:
618 main.log.error( "Problem getting Flows state from REST API. Exiting test" )
Devin Lim44075962017-08-11 10:56:37 -0700619 main.cleanAndExit()
GlennRC956ea742015-11-05 16:14:15 -0800620
621 utilities.assert_equals( expect=main.TRUE,
622 actual=stepResult,
623 onpass="All flows are in the ADDED state",
624 onfail="All flows are NOT in the ADDED state" )
625
626 main.step( "Check flows are in Mininet's flow table" )
627
628 # get the flow IDs that were added through rest
629 main.log.info( "Getting the flow IDs from ONOS" )
alisone14d7b02016-07-06 10:31:51 -0700630 flowIds = [ f.get( "id" ) for f in flows if "rest" in f.get( "appId" ) ]
GlennRC956ea742015-11-05 16:14:15 -0800631 # convert the flowIDs to ints then hex and finally back to strings
alisone14d7b02016-07-06 10:31:51 -0700632 flowIds = [ str( hex( int( x ) ) ) for x in flowIds ]
633 main.log.info( "ONOS flow IDs: {}".format( flowIds ) )
GlennRC956ea742015-11-05 16:14:15 -0800634
635 stepResult = main.Mininet1.checkFlowId( "s1", flowIds, debug=True )
636
637 utilities.assert_equals( expect=main.TRUE,
638 actual=stepResult,
639 onpass="All flows are in mininet",
640 onfail="All flows are NOT in mininet" )
641
642 main.step( "Send a packet to verify the flow is correct" )
643
644 main.log.info( "Starting filter on host2" )
645 main.h2.startFilter( pktFilter="mpls" )
646
647 main.log.info( "Constructing packet" )
648 main.log.info( "Sending packet to host2" )
alisone14d7b02016-07-06 10:31:51 -0700649 main.h1.sendPacket( packet='Ether()/MPLS(label={})'.format( mplsLabel ) )
GlennRC956ea742015-11-05 16:14:15 -0800650
651 main.log.info( "Checking filter for our packet" )
Jon Hallfc951072017-05-24 15:55:34 -0700652 stepResult = main.h2.checkFilter()
GlennRC956ea742015-11-05 16:14:15 -0800653 if stepResult:
Jon Hallfc951072017-05-24 15:55:34 -0700654 main.log.info( "Packet: %s" % main.h2.readPackets() )
655 else:
656 main.h2.killFilter()
GlennRC956ea742015-11-05 16:14:15 -0800657
658 main.log.info( "Clean up host components" )
659 for host in hosts:
Jon Hallfc951072017-05-24 15:55:34 -0700660 host.stopScapy()
alisone14d7b02016-07-06 10:31:51 -0700661 main.Mininet1.removeHostComponent( "h1" )
662 main.Mininet1.removeHostComponent( "h2" )
GlennRC956ea742015-11-05 16:14:15 -0800663
664 utilities.assert_equals( expect=main.TRUE,
665 actual=stepResult,
666 onpass="Successfully sent a packet",
667 onfail="Failed to send a packet" )
668
alisone14d7b02016-07-06 10:31:51 -0700669 def CASE1700( self, main ):
Jon Hallfc951072017-05-24 15:55:34 -0700670 """
GlennRC956ea742015-11-05 16:14:15 -0800671 Add flows with a TCP selector and verify the flow
Jon Hallfc951072017-05-24 15:55:34 -0700672 """
GlennRC956ea742015-11-05 16:14:15 -0800673 import json
674 import time
675
676 main.case( "Verify the TCP selector is correctly compiled on the flow" )
677 main.caseExplanation = "Install a flow with only the TCP selector " +\
alisone14d7b02016-07-06 10:31:51 -0700678 "specified, verify the flow is added in ONOS, and finally " +\
GlennRC956ea742015-11-05 16:14:15 -0800679 "send a TCP packet to verify the TCP selector is compiled correctly."
680
681 main.step( "Add a flow with a TCP selector" )
Devin Lim142b5342017-07-20 15:22:39 -0700682 ctrl = main.Cluster.active( 0 )
GlennRC956ea742015-11-05 16:14:15 -0800683 main.log.info( "Creating host components" )
Jon Halla510a8a2016-05-04 15:09:28 -0700684 main.Scapy.createHostComponent( "h1" )
685 main.Scapy.createHostComponent( "h2" )
alisone14d7b02016-07-06 10:31:51 -0700686 hosts = [ main.h1, main.h2 ]
GlennRC956ea742015-11-05 16:14:15 -0800687 for host in hosts:
Jon Hallfc951072017-05-24 15:55:34 -0700688 host.startHostCli()
689 host.startScapy()
690 host.updateSelf()
GlennRC956ea742015-11-05 16:14:15 -0800691
692 # Add a flow that connects host1 on port1 to host2 on port2
693 egress = 2
694 ingress = 1
695 # IPv4 etherType
696 ethType = main.params[ 'TEST' ][ 'ip4Type' ]
697 # IP protocol
698 ipProto = main.params[ 'TEST' ][ 'tcpProto' ]
699 # TCP port destination
700 tcpDst = main.params[ 'TEST' ][ 'tcpDst' ]
701
702 main.log.info( "Add a flow that connects host1 on port1 to host2 on port2" )
Devin Lim142b5342017-07-20 15:22:39 -0700703 stepResult = ctrl.REST.addFlow( deviceId=main.swDPID,
704 egressPort=egress,
705 ingressPort=ingress,
706 ethType=ethType,
707 ipProto=ipProto,
708 tcpDst=tcpDst,
709 debug=main.debug )
GlennRC956ea742015-11-05 16:14:15 -0800710
711 utilities.assert_equals( expect=main.TRUE,
712 actual=stepResult,
713 onpass="Successfully added flows",
714 onfail="Failed add flows" )
715
716 # Giving ONOS time to add the flow
717 time.sleep( main.addFlowSleep )
718
Devin Lim58046fa2017-07-05 16:55:00 -0700719 main.checkingFlow.checkFlow()
GlennRC956ea742015-11-05 16:14:15 -0800720
721 main.step( "Send a packet to verify the flow is correct" )
722
723 main.log.info( "Constructing packet" )
724 # No need for the MAC src dst
725 main.h1.buildEther( dst=main.h2.hostMac )
726 main.h1.buildIP( dst=main.h2.hostIp )
727 main.h1.buildTCP( dport=tcpDst )
728
729 main.log.info( "Starting filter on host2" )
730 # Defaults to ip
731 main.h2.startFilter( pktFilter="tcp" )
732
733 main.log.info( "Sending packet to host2" )
Jon Hallfc951072017-05-24 15:55:34 -0700734 main.h1.sendPacket()
GlennRC956ea742015-11-05 16:14:15 -0800735
736 main.log.info( "Checking filter for our packet" )
Jon Hallfc951072017-05-24 15:55:34 -0700737 stepResult = main.h2.checkFilter()
GlennRC956ea742015-11-05 16:14:15 -0800738 if stepResult:
Jon Hallfc951072017-05-24 15:55:34 -0700739 main.log.info( "Packet: %s" % main.h2.readPackets() )
740 else:
741 main.h2.killFilter()
GlennRC956ea742015-11-05 16:14:15 -0800742
743 main.log.info( "Clean up host components" )
744 for host in hosts:
Jon Hallfc951072017-05-24 15:55:34 -0700745 host.stopScapy()
alisone14d7b02016-07-06 10:31:51 -0700746 main.Mininet1.removeHostComponent( "h1" )
747 main.Mininet1.removeHostComponent( "h2" )
GlennRC956ea742015-11-05 16:14:15 -0800748
749 utilities.assert_equals( expect=main.TRUE,
750 actual=stepResult,
751 onpass="Successfully sent a packet",
752 onfail="Failed to send a packet" )
753
alisone14d7b02016-07-06 10:31:51 -0700754 def CASE1600( self, main ):
Jon Hallfc951072017-05-24 15:55:34 -0700755 """
GlennRC956ea742015-11-05 16:14:15 -0800756 Add flows with a UDP selector and verify the flow
Jon Hallfc951072017-05-24 15:55:34 -0700757 """
GlennRC956ea742015-11-05 16:14:15 -0800758 import json
759 import time
760
761 main.case( "Verify the UDP selector is correctly compiled on the flow" )
762 main.caseExplanation = "Install a flow with only the UDP selector " +\
alisone14d7b02016-07-06 10:31:51 -0700763 "specified, verify the flow is added in ONOS, and finally " +\
GlennRC956ea742015-11-05 16:14:15 -0800764 "send a UDP packet to verify the UDP selector is compiled correctly."
765
766 main.step( "Add a flow with a UDP selector" )
Devin Lim142b5342017-07-20 15:22:39 -0700767 ctrl = main.Cluster.active( 0 )
GlennRC956ea742015-11-05 16:14:15 -0800768 main.log.info( "Creating host components" )
Jon Halla510a8a2016-05-04 15:09:28 -0700769 main.Scapy.createHostComponent( "h1" )
770 main.Scapy.createHostComponent( "h2" )
alisone14d7b02016-07-06 10:31:51 -0700771 hosts = [ main.h1, main.h2 ]
GlennRC956ea742015-11-05 16:14:15 -0800772 for host in hosts:
Jon Hallfc951072017-05-24 15:55:34 -0700773 host.startHostCli()
774 host.startScapy()
775 host.updateSelf()
GlennRC956ea742015-11-05 16:14:15 -0800776
777 # Add a flow that connects host1 on port1 to host2 on port2
778 egress = 2
779 ingress = 1
780 # IPv4 etherType
781 ethType = main.params[ 'TEST' ][ 'ip4Type' ]
782 # IP protocol
783 ipProto = main.params[ 'TEST' ][ 'udpProto' ]
784 # UDP port destination
785 udpDst = main.params[ 'TEST' ][ 'udpDst' ]
786
787 main.log.info( "Add a flow that connects host1 on port1 to host2 on port2" )
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700788 stepResult = ctrl.REST.addFlow( deviceId=main.swDPID,
GlennRC956ea742015-11-05 16:14:15 -0800789 egressPort=egress,
790 ingressPort=ingress,
791 ethType=ethType,
792 ipProto=ipProto,
793 udpDst=udpDst,
794 debug=main.debug )
795
796 utilities.assert_equals( expect=main.TRUE,
797 actual=stepResult,
798 onpass="Successfully added flows",
799 onfail="Failed add flows" )
800
801 # Giving ONOS time to add the flow
802 time.sleep( main.addFlowSleep )
803
Devin Lim58046fa2017-07-05 16:55:00 -0700804 main.checkingFlow.checkFlow()
GlennRC956ea742015-11-05 16:14:15 -0800805
806 main.step( "Send a packet to verify the flow is correct" )
807
808 main.log.info( "Constructing packet" )
809 # No need for the MAC src dst
810 main.h1.buildEther( dst=main.h2.hostMac )
811 main.h1.buildIP( dst=main.h2.hostIp )
812 main.h1.buildUDP( dport=udpDst )
813
814 main.log.info( "Starting filter on host2" )
815 # Defaults to ip
816 main.h2.startFilter( pktFilter="udp" )
817
818 main.log.info( "Sending packet to host2" )
Jon Hallfc951072017-05-24 15:55:34 -0700819 main.h1.sendPacket()
GlennRC956ea742015-11-05 16:14:15 -0800820
821 main.log.info( "Checking filter for our packet" )
Jon Hallfc951072017-05-24 15:55:34 -0700822 stepResult = main.h2.checkFilter()
GlennRC956ea742015-11-05 16:14:15 -0800823 if stepResult:
Jon Hallfc951072017-05-24 15:55:34 -0700824 main.log.info( "Packet: %s" % main.h2.readPackets() )
825 else:
826 main.h2.killFilter()
GlennRC956ea742015-11-05 16:14:15 -0800827
828 main.log.info( "Clean up host components" )
829 for host in hosts:
Jon Hallfc951072017-05-24 15:55:34 -0700830 host.stopScapy()
alisone14d7b02016-07-06 10:31:51 -0700831 main.Mininet1.removeHostComponent( "h1" )
832 main.Mininet1.removeHostComponent( "h2" )
GlennRC956ea742015-11-05 16:14:15 -0800833
834 utilities.assert_equals( expect=main.TRUE,
835 actual=stepResult,
836 onpass="Successfully sent a packet",
837 onfail="Failed to send a packet" )
838
alisone14d7b02016-07-06 10:31:51 -0700839 def CASE1900( self, main ):
Jon Hallfc951072017-05-24 15:55:34 -0700840 """
alisone14d7b02016-07-06 10:31:51 -0700841 Add flows with a ICMPv4 selector and verify the flow
Jon Hallfc951072017-05-24 15:55:34 -0700842 """
GlennRC956ea742015-11-05 16:14:15 -0800843 import json
alisone14d7b02016-07-06 10:31:51 -0700844 import time
GlennRC956ea742015-11-05 16:14:15 -0800845
alisone14d7b02016-07-06 10:31:51 -0700846 main.case( "Verify the ICMPv4 selector is correctly compiled on the flow" )
847 main.caseExplanation = "Install a flow with only the ICMPv4 selector " +\
848 "specified, verify the flow is added in ONOS, and finally " +\
849 "send a IMCPv4 packet to verify the ICMPv4 selector is compiled correctly."
GlennRC956ea742015-11-05 16:14:15 -0800850
alisone14d7b02016-07-06 10:31:51 -0700851 main.step( "Add a flow with a ICMPv4 selector" )
852
853 main.log.info( "Creating host components" )
854 main.Scapy.createHostComponent( "h1" )
855 main.Scapy.createHostComponent( "h2" )
856 hosts = [ main.h1, main.h2 ]
857 for host in hosts:
Jon Hallfc951072017-05-24 15:55:34 -0700858 host.startHostCli()
859 host.startScapy()
860 host.updateSelf()
alisone14d7b02016-07-06 10:31:51 -0700861
862 # Add a flow that connects host1 on port1 to host2 on port2
863 egress = 2
864 ingress = 1
865 # IPv4 etherType
866 ethType = main.params[ 'TEST' ][ 'ip4Type' ]
867 # IP protocol
868 ipProto = main.params[ 'TEST' ][ 'icmpProto' ]
Devin Lim142b5342017-07-20 15:22:39 -0700869 ctrl = main.Cluster.active( 0 )
alisone14d7b02016-07-06 10:31:51 -0700870 main.log.info( "Add a flow that connects host1 on port1 to host2 on port2" )
Devin Lim142b5342017-07-20 15:22:39 -0700871 stepResult = ctrl.REST.addFlow( deviceId=main.swDPID,
872 egressPort=egress,
873 ingressPort=ingress,
874 ethType=ethType,
875 ipProto=ipProto,
876 debug=main.debug )
alisone14d7b02016-07-06 10:31:51 -0700877
878 utilities.assert_equals( expect=main.TRUE,
879 actual=stepResult,
880 onpass="Successfully added flows",
881 onfail="Failed add flows" )
882
883 # Giving ONOS time to add the flow
884 time.sleep( main.addFlowSleep )
885
Devin Lim58046fa2017-07-05 16:55:00 -0700886 main.checkingFlow.checkFlow()
alisone14d7b02016-07-06 10:31:51 -0700887
888 main.step( "Send a packet to verify the flow is correct" )
889
890 main.log.info( "Constructing packet" )
891 # No need for the MAC src dst
892 main.h1.buildEther( dst=main.h2.hostMac )
893 main.h1.buildIP( dst=main.h2.hostIp )
Jon Hallfc951072017-05-24 15:55:34 -0700894 main.h1.buildICMP()
alisone14d7b02016-07-06 10:31:51 -0700895
896 main.log.info( "Starting filter on host2" )
897 # Defaults to ip
898 main.h2.startFilter( pktFilter="icmp" )
899
900 main.log.info( "Sending packet to host2" )
Jon Hallfc951072017-05-24 15:55:34 -0700901 main.h1.sendPacket()
alisone14d7b02016-07-06 10:31:51 -0700902
903 main.log.info( "Checking filter for our packet" )
Jon Hallfc951072017-05-24 15:55:34 -0700904 stepResult = main.h2.checkFilter()
alisone14d7b02016-07-06 10:31:51 -0700905 if stepResult:
Jon Hallfc951072017-05-24 15:55:34 -0700906 main.log.info( "Packet: %s" % main.h2.readPackets() )
907 else:
908 main.h2.killFilter()
alisone14d7b02016-07-06 10:31:51 -0700909
910 main.log.info( "Clean up host components" )
911 for host in hosts:
Jon Hallfc951072017-05-24 15:55:34 -0700912 host.stopScapy()
alisone14d7b02016-07-06 10:31:51 -0700913 main.Mininet1.removeHostComponent( "h1" )
914 main.Mininet1.removeHostComponent( "h2" )
915
916 utilities.assert_equals( expect=main.TRUE,
917 actual=stepResult,
918 onpass="Successfully sent a packet",
919 onfail="Failed to send a packet" )
920
921 def CASE2000( self, main ):
Jon Hallfc951072017-05-24 15:55:34 -0700922 """
alisone14d7b02016-07-06 10:31:51 -0700923 Add flows with a ICMPv6 selector and verify the flow
Jon Hallfc951072017-05-24 15:55:34 -0700924 """
alisone14d7b02016-07-06 10:31:51 -0700925 import json
926 import time
927
928 main.case( "Verify the ICMPv6 selector is correctly compiled on the flow" )
929 main.caseExplanation = "Install a flow with only the ICMPv6 selector " +\
930 "specified, verify the flow is added in ONOS, and finally " +\
931 "send a IMCPv6 packet to verify the ICMPv6 selector is compiled correctly."
932
933 main.step( "Add a flow with a ICMPv6 selector" )
934
935 main.log.info( "Creating host components" )
936 main.Scapy.createHostComponent( "h5" )
937 main.Scapy.createHostComponent( "h6" )
Jon Hallfc951072017-05-24 15:55:34 -0700938 hosts = [ main.h5, main.h6 ]
alisone14d7b02016-07-06 10:31:51 -0700939 for host in hosts:
Jon Hallfc951072017-05-24 15:55:34 -0700940 host.startHostCli()
941 host.startScapy()
alisone14d7b02016-07-06 10:31:51 -0700942 host.updateSelf( IPv6=True )
943
944 # Add a flow that connects host1 on port1 to host2 on port2
Jon Hallfc951072017-05-24 15:55:34 -0700945 egress = 6
946 ingress = 5
alisone14d7b02016-07-06 10:31:51 -0700947 # IPv6 etherType
948 ethType = main.params[ 'TEST' ][ 'ip6Type' ]
949 # IP protocol
950 ipProto = main.params[ 'TEST' ][ 'icmp6Proto' ]
Devin Lim142b5342017-07-20 15:22:39 -0700951 ctrl = main.Cluster.active( 0 )
alisone14d7b02016-07-06 10:31:51 -0700952 main.log.info( "Add a flow that connects host1 on port1 to host2 on port2" )
Devin Lim142b5342017-07-20 15:22:39 -0700953 stepResult = ctrl.REST.addFlow( deviceId=main.swDPID,
954 egressPort=egress,
955 ingressPort=ingress,
956 ethType=ethType,
957 ipProto=ipProto,
958 debug=main.debug )
alisone14d7b02016-07-06 10:31:51 -0700959
960 utilities.assert_equals( expect=main.TRUE,
961 actual=stepResult,
962 onpass="Successfully added flows",
963 onfail="Failed add flows" )
964
965 # Giving ONOS time to add the flow
966 time.sleep( main.addFlowSleep )
967
Devin Lim58046fa2017-07-05 16:55:00 -0700968 main.checkingFlow.checkFlow()
alisone14d7b02016-07-06 10:31:51 -0700969
970 main.step( "Send a packet to verify the flow is correct" )
971
972 main.log.info( "Constructing packet" )
973 # No need for the MAC src dst
974 main.h5.buildEther( dst=main.h6.hostMac )
975 main.h5.buildIPv6( dst=main.h6.hostIp )
976 main.h5.buildICMP( ipVersion=6 )
977
978 main.log.info( "Starting filter on host2" )
979 # Defaults to ip
980 main.h6.startFilter( pktFilter="icmp6" )
981
982 main.log.info( "Sending packet to host2" )
Jon Hallfc951072017-05-24 15:55:34 -0700983 main.h5.sendPacket()
alisone14d7b02016-07-06 10:31:51 -0700984
985 main.log.info( "Checking filter for our packet" )
Jon Hallfc951072017-05-24 15:55:34 -0700986 stepResult = main.h6.checkFilter()
alisone14d7b02016-07-06 10:31:51 -0700987 if stepResult:
Jon Hallfc951072017-05-24 15:55:34 -0700988 main.log.info( "Packet: %s" % main.h6.readPackets() )
989 else:
990 main.h6.killFilter()
alisone14d7b02016-07-06 10:31:51 -0700991
992 main.log.info( "Clean up host components" )
993 for host in hosts:
Jon Hallfc951072017-05-24 15:55:34 -0700994 host.stopScapy()
alisone14d7b02016-07-06 10:31:51 -0700995 main.Mininet1.removeHostComponent( "h5" )
996 main.Mininet1.removeHostComponent( "h6" )
997
998 utilities.assert_equals( expect=main.TRUE,
999 actual=stepResult,
1000 onpass="Successfully sent a packet",
1001 onfail="Failed to send a packet" )
1002
1003 def CASE3000( self, main ):
Jon Hallfc951072017-05-24 15:55:34 -07001004 """
alisone14d7b02016-07-06 10:31:51 -07001005 Delete flow
Jon Hallfc951072017-05-24 15:55:34 -07001006 """
alisone14d7b02016-07-06 10:31:51 -07001007 import json
1008
1009 main.case( "Delete flows that were added through rest" )
1010 main.step( "Deleting flows" )
Devin Lim142b5342017-07-20 15:22:39 -07001011 ctrl = main.Cluster.active( 0 )
alisone14d7b02016-07-06 10:31:51 -07001012 main.log.info( "Getting flows" )
1013 try:
Devin Lim142b5342017-07-20 15:22:39 -07001014 flows = json.loads( ctrl.REST.flows() )
alisone14d7b02016-07-06 10:31:51 -07001015
1016 stepResult = main.TRUE
1017 for f in flows:
1018 if "rest" in f.get( "appId" ):
Jon Hallfc951072017-05-24 15:55:34 -07001019 if main.debug:
Devin Lim142b5342017-07-20 15:22:39 -07001020 main.log.debug( "Flow to be deleted:\n{}".format( ctrl.REST.pprint( f ) ) )
1021 stepResult = stepResult and ctrl.REST.removeFlow( f.get( "deviceId" ), f.get( "id" ) )
alisone14d7b02016-07-06 10:31:51 -07001022 except TypeError:
1023 main.log.error( "No Flows found by the REST API" )
1024 stepResult = main.FALSE
1025 except ValueError:
1026 main.log.error( "Problem getting Flows state from REST API. Exiting test" )
Devin Lim44075962017-08-11 10:56:37 -07001027 main.cleanAndExit()
GlennRC956ea742015-11-05 16:14:15 -08001028
1029 utilities.assert_equals( expect=main.TRUE,
1030 actual=stepResult,
1031 onpass="Successfully deleting flows",
1032 onfail="Failed to delete flows" )
1033
1034 time.sleep( main.delFlowSleep )
1035
Jon Hallfc951072017-05-24 15:55:34 -07001036 def CASE1200( self, main ):
1037 """
alisone14d7b02016-07-06 10:31:51 -07001038 Add flows with a ARP selector and verify the flow
Jon Hallfc951072017-05-24 15:55:34 -07001039 """
alisone14d7b02016-07-06 10:31:51 -07001040 import json
1041 import time
1042
1043 main.case( "Verify flow IP selectors are correctly compiled" )
1044 main.caseExplanation = "Install two flows with only IP selectors " + \
1045 "specified, then verify flows are added in ONOS, finally " + \
1046 "send a packet that only specifies the IP src and dst."
1047
1048 main.step( "Add flows with ARP addresses as the only selectors" )
1049
1050 main.log.info( "Creating host components" )
1051 main.Scapy.createHostComponent( "h1" )
1052 main.Scapy.createHostComponent( "h2" )
1053 hosts = [ main.h1, main.h2 ]
1054 for host in hosts:
Jon Hallfc951072017-05-24 15:55:34 -07001055 host.startHostCli()
1056 host.startScapy()
1057 host.updateSelf()
Devin Lim142b5342017-07-20 15:22:39 -07001058 ctrl = main.Cluster.active( 0 )
alisone14d7b02016-07-06 10:31:51 -07001059 # Add a flow that connects host1 on port1 to host2 on port2
1060 # send output on port2
1061 # recieve input on port1
1062 egress = 2
1063 ingress = 1
1064 # ARP etherType = 0x0806
1065 ethType = main.params[ 'TEST' ][ 'arpType' ]
1066
1067 # Add flows that connects host1 to host2
1068 main.log.info( "Add flow with port ingress 1 to port egress 2" )
Devin Lim142b5342017-07-20 15:22:39 -07001069 stepResult = ctrl.REST.addFlow( deviceId=main.swDPID,
1070 egressPort=egress,
1071 ingressPort=ingress,
1072 ethType=ethType,
1073 priority=40001,
1074 debug=main.debug )
alisone14d7b02016-07-06 10:31:51 -07001075
1076 utilities.assert_equals( expect=main.TRUE,
1077 actual=stepResult,
1078 onpass="Successfully added flows",
1079 onfail="Failed add flows" )
1080
1081 # Giving ONOS time to add the flow
1082 time.sleep( main.addFlowSleep )
1083
Devin Lim58046fa2017-07-05 16:55:00 -07001084 main.checkingFlow.checkFlow()
alisone14d7b02016-07-06 10:31:51 -07001085
1086 main.step( "Send a packet to verify the flow is correct" )
1087
1088 main.log.info( "Constructing packet" )
1089 # No need for the MAC src dst
1090 main.h1.buildEther( src=main.h1.hostMac, dst=main.h2.hostMac )
1091 main.h1.buildARP( pdst=main.h2.hostIp )
1092
1093 main.log.info( "Starting filter on host2" )
1094 # Defaults to ip
1095 main.h2.startFilter( pktFilter="arp" )
1096
1097 main.log.info( "Sending packet to host2" )
Jon Hallfc951072017-05-24 15:55:34 -07001098 main.h1.sendPacket()
alisone14d7b02016-07-06 10:31:51 -07001099
1100 main.log.info( "Checking filter for our packet" )
Jon Hallfc951072017-05-24 15:55:34 -07001101 stepResult = main.h2.checkFilter()
alisone14d7b02016-07-06 10:31:51 -07001102 if stepResult:
Jon Hallfc951072017-05-24 15:55:34 -07001103 main.log.info( "Packet: %s" % main.h2.readPackets() )
alisone14d7b02016-07-06 10:31:51 -07001104 else:
Jon Hallfc951072017-05-24 15:55:34 -07001105 main.h2.killFilter()
alisone14d7b02016-07-06 10:31:51 -07001106
1107 main.log.info( "Clean up host components" )
1108 for host in hosts:
Jon Hallfc951072017-05-24 15:55:34 -07001109 host.stopScapy()
alisone14d7b02016-07-06 10:31:51 -07001110 main.Mininet1.removeHostComponent( "h1" )
1111 main.Mininet1.removeHostComponent( "h2" )
1112
1113 utilities.assert_equals( expect=main.TRUE,
1114 actual=stepResult,
1115 onpass="Successfully sent a packet",
1116 onfail="Failed to send a packet" )
1117
1118 def CASE1800( self, main ):
Jon Hallfc951072017-05-24 15:55:34 -07001119 """
alisone14d7b02016-07-06 10:31:51 -07001120 Add flows with a SCTP selector and verify the flow
Jon Hallfc951072017-05-24 15:55:34 -07001121 """
alisone14d7b02016-07-06 10:31:51 -07001122 import json
1123 import time
1124
1125 main.case( "Verify the UDP selector is correctly compiled on the flow" )
1126 main.caseExplanation = "Install a flow with only the UDP selector " + \
1127 "specified, verify the flow is added in ONOS, and finally " + \
1128 "send a UDP packet to verify the UDP selector is compiled correctly."
1129
1130 main.step( "Add a flow with a SCTP selector" )
1131
1132 main.log.info( "Creating host components" )
1133 main.Scapy.createHostComponent( "h1" )
1134 main.Scapy.createHostComponent( "h2" )
1135 hosts = [ main.h1, main.h2 ]
1136 for host in hosts:
Jon Hallfc951072017-05-24 15:55:34 -07001137 host.startHostCli()
1138 host.startScapy()
1139 host.updateSelf()
alisone14d7b02016-07-06 10:31:51 -07001140
1141 # Add a flow that connects host1 on port1 to host2 on port2
1142 egress = 2
1143 ingress = 1
1144 # IPv4 etherType
1145 ethType = main.params[ 'TEST' ][ 'ip4Type' ]
1146 # IP protocol
1147 ipProto = main.params[ 'TEST' ][ 'sctpProto' ]
Devin Lim142b5342017-07-20 15:22:39 -07001148 ctrl = main.Cluster.active( 0 )
Jon Hallfc951072017-05-24 15:55:34 -07001149 main.log.info( "Add a flow that connects host1 on port1 to host2 on port2" )
Devin Lim142b5342017-07-20 15:22:39 -07001150 stepResult = ctrl.REST.addFlow( deviceId=main.swDPID,
1151 egressPort=egress,
1152 ingressPort=ingress,
1153 ethType=ethType,
1154 ipProto=ipProto,
1155 debug=main.debug )
alisone14d7b02016-07-06 10:31:51 -07001156
1157 utilities.assert_equals( expect=main.TRUE,
1158 actual=stepResult,
1159 onpass="Successfully added flows",
1160 onfail="Failed add flows" )
1161
1162 # Giving ONOS time to add the flow
1163 time.sleep( main.addFlowSleep )
1164
Devin Lim58046fa2017-07-05 16:55:00 -07001165 main.checkingFlow.checkFlow()
alisone14d7b02016-07-06 10:31:51 -07001166
1167 main.step( "Send a packet to verify the flow is correct" )
1168
1169 main.log.info( "Constructing packet" )
1170 # No need for the MAC src dst
1171 main.h1.buildEther( dst=main.h2.hostMac )
1172 main.h1.buildIP( dst=main.h2.hostIp )
Jon Hallfc951072017-05-24 15:55:34 -07001173 main.h1.buildSCTP()
alisone14d7b02016-07-06 10:31:51 -07001174
1175 main.log.info( "Starting filter on host2" )
1176 # Defaults to ip
1177 main.h2.startFilter( pktFilter="sctp" )
1178
1179 main.log.info( "Sending packet to host2" )
Jon Hallfc951072017-05-24 15:55:34 -07001180 main.h1.sendPacket()
alisone14d7b02016-07-06 10:31:51 -07001181
1182 main.log.info( "Checking filter for our packet" )
Jon Hallfc951072017-05-24 15:55:34 -07001183 stepResult = main.h2.checkFilter()
alisone14d7b02016-07-06 10:31:51 -07001184 if stepResult:
Jon Hallfc951072017-05-24 15:55:34 -07001185 main.log.info( "Packet: %s" % main.h2.readPackets() )
alisone14d7b02016-07-06 10:31:51 -07001186 else:
Jon Hallfc951072017-05-24 15:55:34 -07001187 main.h2.killFilter()
alisone14d7b02016-07-06 10:31:51 -07001188
1189 main.log.info( "Clean up host components" )
1190 for host in hosts:
Jon Hallfc951072017-05-24 15:55:34 -07001191 host.stopScapy()
alisone14d7b02016-07-06 10:31:51 -07001192 main.Mininet1.removeHostComponent( "h1" )
1193 main.Mininet1.removeHostComponent( "h2" )
1194
1195 utilities.assert_equals( expect=main.TRUE,
1196 actual=stepResult,
1197 onpass="Successfully sent a packet",
1198 onfail="Failed to send a packet" )
1199
GlennRC68449942015-10-16 16:03:12 -07001200 def CASE100( self, main ):
Jon Hallfc951072017-05-24 15:55:34 -07001201 """
GlennRC5147a422015-10-06 17:26:17 -07001202 Report errors/warnings/exceptions
Jon Hallfc951072017-05-24 15:55:34 -07001203 """
alisone14d7b02016-07-06 10:31:51 -07001204 main.log.info( "Error report: \n" )
Devin Lim142b5342017-07-20 15:22:39 -07001205 main.ONOSbench.logReport( main.Cluster.active( 0 ).ipAddress,
GlennRC5147a422015-10-06 17:26:17 -07001206 [ "INFO",
1207 "FOLLOWER",
1208 "WARN",
1209 "flow",
1210 "ERROR",
1211 "Except" ],
GlennRC68449942015-10-16 16:03:12 -07001212 "s" )