blob: ca590e6d31d413bdea2b0c0628327bab36e82f92 [file] [log] [blame]
GlennRC5147a422015-10-06 17:26:17 -07001class FUNCflow:
2
3 def __init__( self ):
4 self.default = ''
5
6 def CASE1( self, main ):
GlennRC5147a422015-10-06 17:26:17 -07007 import os
8 import imp
Devin Lim58046fa2017-07-05 16:55:00 -07009 try:
10 from tests.dependencies.ONOSSetup import ONOSSetup
11 except ImportError:
12 main.log.error( "SetUp not found exiting the test" )
13 main.exit()
14 try:
15 main.testSetUp
16 except ( NameError, AttributeError ):
17 main.testSetUp = ONOSSetup()
GlennRC5147a422015-10-06 17:26:17 -070018 """
19 - Construct tests variables
20 - GIT ( optional )
21 - Checkout ONOS master branch
22 - Pull latest ONOS code
GlennRC5147a422015-10-06 17:26:17 -070023 """
GlennRC5147a422015-10-06 17:26:17 -070024
Devin Lim58046fa2017-07-05 16:55:00 -070025 main.testSetUp.envSetupDescription()
26 stepResult = main.FALSE
27 try:
28 # Test variables
29 main.cellName = main.params[ 'ENV' ][ 'cellName' ]
30 main.apps = main.params[ 'ENV' ][ 'cellApps' ]
31 main.ONOSport = main.params[ 'CTRL' ][ 'port' ]
32 main.dependencyPath = main.testOnDirectory + \
33 main.params[ 'DEPENDENCY' ][ 'path' ]
34 wrapperFile1 = main.params[ 'DEPENDENCY' ][ 'wrapper1' ]
35 wrapperFile2 = main.params[ 'DEPENDENCY' ][ 'wrapper2' ]
36 main.topology = main.params[ 'DEPENDENCY' ][ 'topology' ]
37 main.maxNodes = int( main.params[ 'SCALE' ][ 'max' ] )
38 main.startUpSleep = int( main.params[ 'SLEEP' ][ 'startup' ] )
39 main.startMNSleep = int( main.params[ 'SLEEP' ][ 'startMN' ] )
40 main.addFlowSleep = int( main.params[ 'SLEEP' ][ 'addFlow' ] )
41 main.delFlowSleep = int( main.params[ 'SLEEP' ][ 'delFlow' ] )
42 main.debug = main.params[ 'DEBUG' ]
43 main.swDPID = main.params[ 'TEST' ][ 'swDPID' ]
GlennRC5147a422015-10-06 17:26:17 -070044
Devin Lim58046fa2017-07-05 16:55:00 -070045 main.debug = True if "on" in main.debug else False
GlennRC956ea742015-11-05 16:14:15 -080046
Devin Lim58046fa2017-07-05 16:55:00 -070047 # -- INIT SECTION, ONLY RUNS ONCE -- #
GlennRC5147a422015-10-06 17:26:17 -070048
Devin Lim58046fa2017-07-05 16:55:00 -070049 try:
50 from tests.FUNC.FUNCflow.dependencies.checkingFlow import CheckingFlow
51 main.checkingFlow = CheckingFlow()
52 except ImportError as e:
53 print e
54 main.log.error("CheckingFlow not found exiting the test")
55 main.exit()
56 copyResult = main.ONOSbench.scp( main.Mininet1,
57 main.dependencyPath + main.topology,
58 main.Mininet1.home + '/custom/',
59 direction="to" )
GlennRC5147a422015-10-06 17:26:17 -070060
Devin Lim58046fa2017-07-05 16:55:00 -070061 utilities.assert_equals( expect=main.TRUE,
62 actual=copyResult,
63 onpass="Successfully copy " + "test variables ",
64 onfail="Failed to copy test variables" )
GlennRC5147a422015-10-06 17:26:17 -070065
Devin Lim58046fa2017-07-05 16:55:00 -070066 stepResult = main.testSetUp.envSetup()
GlennRC1704d072015-10-07 18:40:45 -070067
Devin Lim58046fa2017-07-05 16:55:00 -070068 except Exception as e:
69 main.testSetUp.envSetupException( e )
70 main.testSetUp.evnSetupConclusion( stepResult )
Devin Lim8d7c7782017-06-07 16:21:20 -070071
GlennRC5147a422015-10-06 17:26:17 -070072
73 def CASE2( self, main ):
74 """
75 - Set up cell
76 - Create cell file
77 - Set cell file
78 - Verify cell file
Devin Lim58046fa2017-07-05 16:55:00 -070079 - Building ONOS
80 - Install ONOS package
81 - Build ONOS package
GlennRC5147a422015-10-06 17:26:17 -070082 - Kill ONOS process
83 - Uninstall ONOS cluster
84 - Verify ONOS start up
85 - Install ONOS cluster
86 - Connect to cli
87 """
Devin Lim58046fa2017-07-05 16:55:00 -070088 main.testSetUp.ONOSSetUp( main.Mininet1 )
GlennRC5147a422015-10-06 17:26:17 -070089
GlennRC68449942015-10-16 16:03:12 -070090 def CASE10( self, main ):
Jon Hallfc951072017-05-24 15:55:34 -070091 """
GlennRC68449942015-10-16 16:03:12 -070092 Start Mininet
Jon Hallfc951072017-05-24 15:55:34 -070093 """
GlennRC073e8bc2015-10-27 17:11:28 -070094 import json
Devin Lim58046fa2017-07-05 16:55:00 -070095 import time
96 try:
97 from tests.dependencies.topology import Topology
98 except ImportError:
99 main.log.error( "Topology not found exiting the test" )
100 main.exit()
101 try:
102 main.topoRelated
103 except ( NameError, AttributeError ):
104 main.topoRelated = Topology()
GlennRC073e8bc2015-10-27 17:11:28 -0700105
106 main.case( "Setup mininet and compare ONOS topology view to Mininet topology" )
107 main.caseExplanation = "Start mininet with custom topology and compare topology " +\
108 "elements between Mininet and ONOS"
109
GlennRC68449942015-10-16 16:03:12 -0700110 main.step( "Setup Mininet Topology" )
111 topology = main.Mininet1.home + '/custom/' + main.topology
Jon Hallfc951072017-05-24 15:55:34 -0700112 stepResult = main.Mininet1.startNet( topoFile=topology )
GlennRC68449942015-10-16 16:03:12 -0700113
114 utilities.assert_equals( expect=main.TRUE,
GlennRC073e8bc2015-10-27 17:11:28 -0700115 actual=stepResult,
GlennRC68449942015-10-16 16:03:12 -0700116 onpass="Successfully loaded topology",
117 onfail="Failed to load topology" )
118
GlennRC073e8bc2015-10-27 17:11:28 -0700119 main.step( "Assign switch to controller" )
Jon Hallfc951072017-05-24 15:55:34 -0700120 stepResult = main.Mininet1.assignSwController( "s1", main.ONOSip[ 0 ] )
GlennRC68449942015-10-16 16:03:12 -0700121
122 utilities.assert_equals( expect=main.TRUE,
GlennRC073e8bc2015-10-27 17:11:28 -0700123 actual=stepResult,
124 onpass="Successfully assigned switch to controller",
125 onfail="Failed to assign switch to controller" )
GlennRC68449942015-10-16 16:03:12 -0700126
GlennRC073e8bc2015-10-27 17:11:28 -0700127 time.sleep( main.startMNSleep )
GlennRC68449942015-10-16 16:03:12 -0700128
Devin Lim58046fa2017-07-05 16:55:00 -0700129 main.topoRelated.compareTopos( main.Mininet1 )
GlennRC68449942015-10-16 16:03:12 -0700130
Jon Hall892818c2015-10-20 17:58:34 -0700131 def CASE66( self, main ):
Jon Hallfc951072017-05-24 15:55:34 -0700132 """
Jon Hall892818c2015-10-20 17:58:34 -0700133 Testing scapy
Jon Hallfc951072017-05-24 15:55:34 -0700134 """
Jon Hall892818c2015-10-20 17:58:34 -0700135 main.case( "Testing scapy" )
136 main.step( "Creating Host1 component" )
Jon Halla510a8a2016-05-04 15:09:28 -0700137 main.Scapy.createHostComponent( "h1" )
138 main.Scapy.createHostComponent( "h2" )
alisone14d7b02016-07-06 10:31:51 -0700139 hosts = [ main.h1, main.h2 ]
Jon Hall892818c2015-10-20 17:58:34 -0700140 for host in hosts:
Jon Hallfc951072017-05-24 15:55:34 -0700141 host.startHostCli()
142 host.startScapy()
143 host.updateSelf()
Jon Hall892818c2015-10-20 17:58:34 -0700144 main.log.debug( host.name )
145 main.log.debug( host.hostIp )
146 main.log.debug( host.hostMac )
147
148 main.step( "Sending/Receiving Test packet - Filter doesn't match" )
Jon Halla510a8a2016-05-04 15:09:28 -0700149 main.log.info( "Starting Filter..." )
Jon Hallfc951072017-05-24 15:55:34 -0700150 main.h2.startFilter()
Jon Halla510a8a2016-05-04 15:09:28 -0700151 main.log.info( "Building Ether frame..." )
Jon Hall892818c2015-10-20 17:58:34 -0700152 main.h1.buildEther( dst=main.h2.hostMac )
Jon Halla510a8a2016-05-04 15:09:28 -0700153 main.log.info( "Sending Packet..." )
Jon Hallfc951072017-05-24 15:55:34 -0700154 main.h1.sendPacket()
Jon Halla510a8a2016-05-04 15:09:28 -0700155 main.log.info( "Checking Filter..." )
Jon Hallfc951072017-05-24 15:55:34 -0700156 finished = main.h2.checkFilter()
Jon Halla510a8a2016-05-04 15:09:28 -0700157 main.log.debug( finished )
Jon Hall892818c2015-10-20 17:58:34 -0700158 i = ""
159 if finished:
Jon Hallfc951072017-05-24 15:55:34 -0700160 a = main.h2.readPackets()
161 for i in a.splitlines():
Jon Hall892818c2015-10-20 17:58:34 -0700162 main.log.info( i )
163 else:
Jon Hallfc951072017-05-24 15:55:34 -0700164 kill = main.h2.killFilter()
Jon Hall892818c2015-10-20 17:58:34 -0700165 main.log.debug( kill )
166 main.h2.handle.sendline( "" )
167 main.h2.handle.expect( main.h2.scapyPrompt )
168 main.log.debug( main.h2.handle.before )
169 utilities.assert_equals( expect=True,
170 actual="dst=00:00:00:00:00:02 src=00:00:00:00:00:01" in i,
171 onpass="Pass",
172 onfail="Fail" )
173
174 main.step( "Sending/Receiving Test packet - Filter matches" )
Jon Hallfc951072017-05-24 15:55:34 -0700175 main.h2.startFilter()
Jon Hall892818c2015-10-20 17:58:34 -0700176 main.h1.buildEther( dst=main.h2.hostMac )
177 main.h1.buildIP( dst=main.h2.hostIp )
Jon Hallfc951072017-05-24 15:55:34 -0700178 main.h1.sendPacket()
179 finished = main.h2.checkFilter()
Jon Hall892818c2015-10-20 17:58:34 -0700180 i = ""
181 if finished:
Jon Hallfc951072017-05-24 15:55:34 -0700182 a = main.h2.readPackets()
183 for i in a.splitlines():
Jon Hall892818c2015-10-20 17:58:34 -0700184 main.log.info( i )
185 else:
Jon Hallfc951072017-05-24 15:55:34 -0700186 kill = main.h2.killFilter()
Jon Hall892818c2015-10-20 17:58:34 -0700187 main.log.debug( kill )
188 main.h2.handle.sendline( "" )
189 main.h2.handle.expect( main.h2.scapyPrompt )
190 main.log.debug( main.h2.handle.before )
191 utilities.assert_equals( expect=True,
192 actual="dst=00:00:00:00:00:02 src=00:00:00:00:00:01" in i,
193 onpass="Pass",
194 onfail="Fail" )
195
Jon Hall892818c2015-10-20 17:58:34 -0700196 main.step( "Clean up host components" )
197 for host in hosts:
Jon Hallfc951072017-05-24 15:55:34 -0700198 host.stopScapy()
alisone14d7b02016-07-06 10:31:51 -0700199 main.Mininet1.removeHostComponent( "h1" )
200 main.Mininet1.removeHostComponent( "h2" )
Jon Hall892818c2015-10-20 17:58:34 -0700201
GlennRC68449942015-10-16 16:03:12 -0700202 def CASE1000( self, main ):
Jon Hallfc951072017-05-24 15:55:34 -0700203 """
GlennRC073e8bc2015-10-27 17:11:28 -0700204 Add flows with MAC selectors and verify the flows
Jon Hallfc951072017-05-24 15:55:34 -0700205 """
GlennRC073e8bc2015-10-27 17:11:28 -0700206 import json
207 import time
GlennRC68449942015-10-16 16:03:12 -0700208
GlennRC073e8bc2015-10-27 17:11:28 -0700209 main.case( "Verify flow MAC selectors are correctly compiled" )
210 main.caseExplanation = "Install two flows with only MAC selectors " +\
Jon Hallfc951072017-05-24 15:55:34 -0700211 "specified, then verify flows are added in ONOS, finally " +\
GlennRC073e8bc2015-10-27 17:11:28 -0700212 "send a packet that only specifies the MAC src and dst."
GlennRC68449942015-10-16 16:03:12 -0700213
GlennRC073e8bc2015-10-27 17:11:28 -0700214 main.step( "Add flows with MAC addresses as the only selectors" )
GlennRC68449942015-10-16 16:03:12 -0700215
GlennRC073e8bc2015-10-27 17:11:28 -0700216 main.log.info( "Creating host components" )
Jon Halla510a8a2016-05-04 15:09:28 -0700217 main.Scapy.createHostComponent( "h1" )
218 main.Scapy.createHostComponent( "h2" )
alisone14d7b02016-07-06 10:31:51 -0700219 hosts = [ main.h1, main.h2 ]
GlennRC073e8bc2015-10-27 17:11:28 -0700220 for host in hosts:
Jon Hallfc951072017-05-24 15:55:34 -0700221 host.startHostCli()
222 host.startScapy()
223 host.updateSelf()
GlennRC68449942015-10-16 16:03:12 -0700224
GlennRC073e8bc2015-10-27 17:11:28 -0700225 # Add a flow that connects host1 on port1 to host2 on port2
226 # send output on port2
227 # recieve input on port1
228 egress = 2
229 ingress = 1
230
231 # Add flows that sends packets from port1 to port2 with correct
232 # MAC src and dst addresses
233 main.log.info( "Adding flow with MAC selectors" )
234 stepResult = main.ONOSrest.addFlow( deviceId=main.swDPID,
235 egressPort=egress,
236 ingressPort=ingress,
237 ethSrc=main.h1.hostMac,
238 ethDst=main.h2.hostMac,
GlennRC956ea742015-11-05 16:14:15 -0800239 debug=main.debug )
GlennRC68449942015-10-16 16:03:12 -0700240
GlennRCa5391372015-10-14 17:28:15 -0700241 utilities.assert_equals( expect=main.TRUE,
242 actual=stepResult,
GlennRC68449942015-10-16 16:03:12 -0700243 onpass="Successfully added flows",
244 onfail="Failed add flows" )
GlennRCa5391372015-10-14 17:28:15 -0700245
GlennRC073e8bc2015-10-27 17:11:28 -0700246 # Giving ONOS time to add the flows
247 time.sleep( main.addFlowSleep )
GlennRC5147a422015-10-06 17:26:17 -0700248
GlennRC073e8bc2015-10-27 17:11:28 -0700249 main.step( "Check flows are in the ADDED state" )
250
GlennRC073e8bc2015-10-27 17:11:28 -0700251 main.log.info( "Get the flows from ONOS" )
Jeremy86160992016-04-11 10:05:53 -0700252 try:
Jon Hallfc951072017-05-24 15:55:34 -0700253 flows = json.loads( main.ONOSrest.flows() )
GlennRC68449942015-10-16 16:03:12 -0700254
Jeremy86160992016-04-11 10:05:53 -0700255 stepResult = main.TRUE
256 for f in flows:
alisone14d7b02016-07-06 10:31:51 -0700257 if "rest" in f.get( "appId" ):
258 if "ADDED" not in f.get( "state" ):
Jeremy86160992016-04-11 10:05:53 -0700259 stepResult = main.FALSE
alisone14d7b02016-07-06 10:31:51 -0700260 main.log.error( "Flow: %s in state: %s" % ( f.get( "id" ), f.get( "state" ) ) )
Jeremy86160992016-04-11 10:05:53 -0700261 except TypeError:
262 main.log.error( "No Flows found by the REST API" )
263 stepResult = main.FALSE
264 except ValueError:
265 main.log.error( "Problem getting Flows state from REST API. Exiting test" )
Jon Hallfc951072017-05-24 15:55:34 -0700266 main.cleanup()
267 main.exit()
GlennRC68449942015-10-16 16:03:12 -0700268
269 utilities.assert_equals( expect=main.TRUE,
270 actual=stepResult,
271 onpass="All flows are in the ADDED state",
GlennRC073e8bc2015-10-27 17:11:28 -0700272 onfail="All flows are NOT in the ADDED state" )
GlennRC68449942015-10-16 16:03:12 -0700273
GlennRC956ea742015-11-05 16:14:15 -0800274 main.step( "Check flows are in Mininet's flow table" )
275
276 # get the flow IDs that were added through rest
277 main.log.info( "Getting the flow IDs from ONOS" )
alisone14d7b02016-07-06 10:31:51 -0700278 flowIds = [ f.get( "id" ) for f in flows if "rest" in f.get( "appId" ) ]
GlennRC956ea742015-11-05 16:14:15 -0800279 # convert the flowIDs to ints then hex and finally back to strings
alisone14d7b02016-07-06 10:31:51 -0700280 flowIds = [ str( hex( int( x ) ) ) for x in flowIds ]
281 main.log.info( "ONOS flow IDs: {}".format( flowIds ) )
GlennRC956ea742015-11-05 16:14:15 -0800282
283 stepResult = main.Mininet1.checkFlowId( "s1", flowIds, debug=False )
284
285 utilities.assert_equals( expect=main.TRUE,
286 actual=stepResult,
287 onpass="All flows are in mininet",
288 onfail="All flows are NOT in mininet" )
289
GlennRC073e8bc2015-10-27 17:11:28 -0700290 main.step( "Send a packet to verify the flows are correct" )
291
292 # Specify the src and dst MAC addr
293 main.log.info( "Constructing packet" )
294 main.h1.buildEther( src=main.h1.hostMac, dst=main.h2.hostMac )
295
296 # Filter for packets with the correct host name. Otherwise,
297 # the filter we catch any packet that is sent to host2
298 # NOTE: I believe it doesn't matter which host name it is,
GlennRC956ea742015-11-05 16:14:15 -0800299 # as long as the src and dst are both specified
GlennRC073e8bc2015-10-27 17:11:28 -0700300 main.log.info( "Starting filter on host2" )
alisone14d7b02016-07-06 10:31:51 -0700301 main.h2.startFilter( pktFilter="ether host %s" % main.h1.hostMac )
GlennRC073e8bc2015-10-27 17:11:28 -0700302
303 main.log.info( "Sending packet to host2" )
304 main.h1.sendPacket()
305
306 main.log.info( "Checking filter for our packet" )
Jon Hallfc951072017-05-24 15:55:34 -0700307 stepResult = main.h2.checkFilter()
GlennRC073e8bc2015-10-27 17:11:28 -0700308 if stepResult:
Jon Hallfc951072017-05-24 15:55:34 -0700309 main.log.info( "Packet: %s" % main.h2.readPackets() )
alisone14d7b02016-07-06 10:31:51 -0700310 else:
Jon Hallfc951072017-05-24 15:55:34 -0700311 main.h2.killFilter()
GlennRC073e8bc2015-10-27 17:11:28 -0700312
313 main.log.info( "Clean up host components" )
314 for host in hosts:
Jon Hallfc951072017-05-24 15:55:34 -0700315 host.stopScapy()
alisone14d7b02016-07-06 10:31:51 -0700316 main.Mininet1.removeHostComponent( "h1" )
317 main.Mininet1.removeHostComponent( "h2" )
GlennRC073e8bc2015-10-27 17:11:28 -0700318
319 utilities.assert_equals( expect=main.TRUE,
320 actual=stepResult,
321 onpass="Successfully sent a packet",
322 onfail="Failed to send a packet" )
323
alisone14d7b02016-07-06 10:31:51 -0700324 def CASE1400( self, main ):
Jon Hallfc951072017-05-24 15:55:34 -0700325 """
GlennRC073e8bc2015-10-27 17:11:28 -0700326 Add flows with IPv4 selectors and verify the flows
Jon Hallfc951072017-05-24 15:55:34 -0700327 """
GlennRC68449942015-10-16 16:03:12 -0700328 import json
GlennRC073e8bc2015-10-27 17:11:28 -0700329 import time
GlennRC68449942015-10-16 16:03:12 -0700330
GlennRC073e8bc2015-10-27 17:11:28 -0700331 main.case( "Verify flow IP selectors are correctly compiled" )
332 main.caseExplanation = "Install two flows with only IP selectors " +\
alisone14d7b02016-07-06 10:31:51 -0700333 "specified, then verify flows are added in ONOS, finally " +\
GlennRC073e8bc2015-10-27 17:11:28 -0700334 "send a packet that only specifies the IP src and dst."
335
336 main.step( "Add flows with IPv4 addresses as the only selectors" )
337
338 main.log.info( "Creating host components" )
Jon Halla510a8a2016-05-04 15:09:28 -0700339 main.Scapy.createHostComponent( "h1" )
340 main.Scapy.createHostComponent( "h2" )
alisone14d7b02016-07-06 10:31:51 -0700341 hosts = [ main.h1, main.h2 ]
GlennRC073e8bc2015-10-27 17:11:28 -0700342 for host in hosts:
Jon Hallfc951072017-05-24 15:55:34 -0700343 host.startHostCli()
344 host.startScapy()
345 host.updateSelf()
GlennRC073e8bc2015-10-27 17:11:28 -0700346
347 # Add a flow that connects host1 on port1 to host2 on port2
348 # send output on port2
349 # recieve input on port1
350 egress = 2
351 ingress = 1
352 # IPv4 etherType = 0x800
alisone14d7b02016-07-06 10:31:51 -0700353 ethType = main.params[ 'TEST' ][ 'ip4Type' ]
GlennRC073e8bc2015-10-27 17:11:28 -0700354
355 # Add flows that connects host1 to host2
356 main.log.info( "Add flow with port ingress 1 to port egress 2" )
357 stepResult = main.ONOSrest.addFlow( deviceId=main.swDPID,
358 egressPort=egress,
359 ingressPort=ingress,
alisone14d7b02016-07-06 10:31:51 -0700360 ethType=ethType,
Jon Hallfc951072017-05-24 15:55:34 -0700361 ipSrc=( "IPV4_SRC", main.h1.hostIp + "/32" ),
362 ipDst=( "IPV4_DST", main.h2.hostIp + "/32" ),
GlennRC956ea742015-11-05 16:14:15 -0800363 debug=main.debug )
GlennRC073e8bc2015-10-27 17:11:28 -0700364
365 utilities.assert_equals( expect=main.TRUE,
366 actual=stepResult,
367 onpass="Successfully added flows",
368 onfail="Failed add flows" )
369
370 # Giving ONOS time to add the flow
371 time.sleep( main.addFlowSleep )
372
Devin Lim58046fa2017-07-05 16:55:00 -0700373 main.checkingFlow.checkFlow()
GlennRC956ea742015-11-05 16:14:15 -0800374
GlennRC073e8bc2015-10-27 17:11:28 -0700375 main.step( "Send a packet to verify the flow is correct" )
376
377 main.log.info( "Constructing packet" )
378 # No need for the MAC src dst
379 main.h1.buildEther( dst=main.h2.hostMac )
380 main.h1.buildIP( src=main.h1.hostIp, dst=main.h2.hostIp )
381
382 main.log.info( "Starting filter on host2" )
383 # Defaults to ip
Jon Hallfc951072017-05-24 15:55:34 -0700384 main.h2.startFilter()
GlennRC073e8bc2015-10-27 17:11:28 -0700385
386 main.log.info( "Sending packet to host2" )
Jon Hallfc951072017-05-24 15:55:34 -0700387 main.h1.sendPacket()
GlennRC073e8bc2015-10-27 17:11:28 -0700388
389 main.log.info( "Checking filter for our packet" )
Jon Hallfc951072017-05-24 15:55:34 -0700390 stepResult = main.h2.checkFilter()
GlennRC073e8bc2015-10-27 17:11:28 -0700391 if stepResult:
Jon Hallfc951072017-05-24 15:55:34 -0700392 main.log.info( "Packet: %s" % main.h2.readPackets() )
393 else:
394 main.h2.killFilter()
GlennRC073e8bc2015-10-27 17:11:28 -0700395
396 main.log.info( "Clean up host components" )
397 for host in hosts:
Jon Hallfc951072017-05-24 15:55:34 -0700398 host.stopScapy()
alisone14d7b02016-07-06 10:31:51 -0700399 main.Mininet1.removeHostComponent( "h1" )
400 main.Mininet1.removeHostComponent( "h2" )
GlennRC073e8bc2015-10-27 17:11:28 -0700401
402 utilities.assert_equals( expect=main.TRUE,
403 actual=stepResult,
404 onpass="Successfully sent a packet",
405 onfail="Failed to send a packet" )
406
Jon Hallfc951072017-05-24 15:55:34 -0700407 def CASE1500( self, main ):
alisone14d7b02016-07-06 10:31:51 -0700408 """
409 Add flow with IPv6 selector and verify the flow
410 """
411 import json
412 import time
413 main.case( "Verify IPv6 selector is correctly compiled" )
414 main.caseExplanation = "Install two flows with only IP selectors " + \
415 "specified, then verify flows are added in ONOS, finally " + \
416 "send a packet that only specifies the IP src and dst."
417
418 main.step( "Add flows with IPv6 addresses as the only selectors" )
419
420 main.log.info( "Creating host components" )
421 main.Scapy.createHostComponent( "h5" )
422 main.Scapy.createHostComponent( "h6" )
423 hosts = [ main.h5, main.h6 ]
424
425 for host in hosts:
Jon Hallfc951072017-05-24 15:55:34 -0700426 host.startHostCli()
427 host.startScapy()
alisone14d7b02016-07-06 10:31:51 -0700428 host.updateSelf( IPv6=True )
429
430 # Add a flow that connects host1 on port1 to host2 on port2
431 # send output on port2
432 # recieve input on port1
433 egress = 6
434 ingress = 5
435 # IPv6 etherType = 0x86DD
436 ethType = main.params[ 'TEST' ][ 'ip6Type' ]
437
438 # Add flows that connects host1 to host2
439 main.log.info( "Add flow with port ingress 5 to port egress 6" )
440 stepResult = main.ONOSrest.addFlow( deviceId=main.swDPID,
441 egressPort=egress,
442 ingressPort=ingress,
443 ethType=ethType,
444 ipSrc=( "IPV6_SRC", main.h5.hostIp + "/128" ),
445 ipDst=( "IPV6_DST", main.h6.hostIp + "/128" ),
446 debug=main.debug )
447
448 utilities.assert_equals( expect=main.TRUE,
449 actual=stepResult,
450 onpass="Successfully added flows",
451 onfail="Failed add flows" )
452
453 # Giving ONOS time to add the flow
454 time.sleep( main.addFlowSleep )
455
Devin Lim58046fa2017-07-05 16:55:00 -0700456 main.checkingFlow.checkFlow()
alisone14d7b02016-07-06 10:31:51 -0700457
458 main.step( "Send a packet to verify the flow is correct" )
459
460 main.log.info( "Constructing packet" )
461 # No need for the MAC src dst
462 main.h5.buildEther( dst=main.h6.hostMac )
463 main.h5.buildIPv6( src=main.h5.hostIp, dst=main.h6.hostIp )
464
465 main.log.info( "Starting filter on host6" )
466 # Defaults to ip
467 main.h6.startFilter( pktFilter="ip6" )
468 main.log.info( "Sending packet to host6" )
Jon Hallfc951072017-05-24 15:55:34 -0700469 main.h5.sendPacket()
alisone14d7b02016-07-06 10:31:51 -0700470
471 main.log.info( "Checking filter for our packet" )
Jon Hallfc951072017-05-24 15:55:34 -0700472 stepResult = main.h6.checkFilter()
alisone14d7b02016-07-06 10:31:51 -0700473 if stepResult:
Jon Hallfc951072017-05-24 15:55:34 -0700474 main.log.info( "Packet: %s" % main.h6.readPackets() )
alisone14d7b02016-07-06 10:31:51 -0700475 else:
Jon Hallfc951072017-05-24 15:55:34 -0700476 main.h6.killFilter()
alisone14d7b02016-07-06 10:31:51 -0700477
478 main.log.info( "Clean up host components" )
479 for host in hosts:
Jon Hallfc951072017-05-24 15:55:34 -0700480 host.stopScapy()
alisone14d7b02016-07-06 10:31:51 -0700481 main.Mininet1.removeHostComponent( "h5" )
482 main.Mininet1.removeHostComponent( "h6" )
483
484 utilities.assert_equals( expect=main.TRUE,
485 actual=stepResult,
486 onpass="Successfully sent a packet",
487 onfail="Failed to send a packet" )
488
alisone14d7b02016-07-06 10:31:51 -0700489 def CASE1100( self, main ):
Jon Hallfc951072017-05-24 15:55:34 -0700490 """
GlennRC073e8bc2015-10-27 17:11:28 -0700491 Add flow with VLAN selector and verify the flow
Jon Hallfc951072017-05-24 15:55:34 -0700492 """
GlennRC073e8bc2015-10-27 17:11:28 -0700493 import json
494 import time
495
496 main.case( "Verify VLAN selector is correctly compiled" )
497 main.caseExplanation = "Install one flow with only the VLAN selector " +\
Jon Hallfc951072017-05-24 15:55:34 -0700498 "specified, then verify the flow is added in ONOS, and finally " +\
GlennRC073e8bc2015-10-27 17:11:28 -0700499 "broadcast a packet with the correct VLAN tag."
500
501 # We do this here to utilize the hosts information
502 main.log.info( "Creating host components" )
Jon Halla510a8a2016-05-04 15:09:28 -0700503 main.Scapy.createHostComponent( "h3" )
504 main.Scapy.createHostComponent( "h4" )
alisone14d7b02016-07-06 10:31:51 -0700505 hosts = [ main.h3, main.h4 ]
GlennRC073e8bc2015-10-27 17:11:28 -0700506 for host in hosts:
Jon Hallfc951072017-05-24 15:55:34 -0700507 host.startHostCli()
508 host.startScapy()
509 host.updateSelf()
GlennRC073e8bc2015-10-27 17:11:28 -0700510
511 main.step( "Add a flow with the VLAN tag as the only selector" )
512
513 # Add flows that connects the two vlan hosts h3 and h4
514 # Host 3 is on port 3 and host 4 is on port 4
515 vlan = main.params[ 'TEST' ][ 'vlan' ]
516 egress = 4
517 ingress = 3
518 # VLAN ethType = 0x8100
alisone14d7b02016-07-06 10:31:51 -0700519 ethType = main.params[ 'TEST' ][ 'vlanType' ]
GlennRC073e8bc2015-10-27 17:11:28 -0700520
521 # Add only one flow because we don't need a response
522 main.log.info( "Add flow with port ingress 1 to port egress 2" )
523 stepResult = main.ONOSrest.addFlow( deviceId=main.swDPID,
524 egressPort=egress,
525 ingressPort=ingress,
526 ethType=ethType,
527 vlan=vlan,
GlennRC956ea742015-11-05 16:14:15 -0800528 debug=main.debug )
GlennRC073e8bc2015-10-27 17:11:28 -0700529
GlennRC073e8bc2015-10-27 17:11:28 -0700530 utilities.assert_equals( expect=main.TRUE,
531 actual=stepResult,
532 onpass="Successfully added flow",
533 onfail="Failed add flows" )
534
535 # Giving ONOS time to add the flows
536 time.sleep( main.addFlowSleep )
537
538 main.step( "Check flows are in the ADDED state" )
539
540 main.log.info( "Get the flows from ONOS" )
Jeremy86160992016-04-11 10:05:53 -0700541 try:
Jon Hallfc951072017-05-24 15:55:34 -0700542 flows = json.loads( main.ONOSrest.flows() )
GlennRC073e8bc2015-10-27 17:11:28 -0700543
Jeremy86160992016-04-11 10:05:53 -0700544 stepResult = main.TRUE
545 for f in flows:
alisone14d7b02016-07-06 10:31:51 -0700546 if "rest" in f.get( "appId" ):
547 if "ADDED" not in f.get( "state" ):
Jeremy86160992016-04-11 10:05:53 -0700548 stepResult = main.FALSE
alisone14d7b02016-07-06 10:31:51 -0700549 main.log.error( "Flow: %s in state: %s" % ( f.get( "id" ), f.get( "state" ) ) )
Jeremy86160992016-04-11 10:05:53 -0700550 except TypeError:
551 main.log.error( "No Flows found by the REST API" )
552 stepResult = main.FALSE
553 except ValueError:
554 main.log.error( "Problem getting Flows state from REST API. Exiting test" )
Jon Hallfc951072017-05-24 15:55:34 -0700555 main.cleanup()
556 main.exit()
GlennRC073e8bc2015-10-27 17:11:28 -0700557
558 utilities.assert_equals( expect=main.TRUE,
559 actual=stepResult,
560 onpass="All flows are in the ADDED state",
561 onfail="All flows are NOT in the ADDED state" )
562
GlennRC956ea742015-11-05 16:14:15 -0800563 main.step( "Check flows are in Mininet's flow table" )
564
565 # get the flow IDs that were added through rest
566 main.log.info( "Getting the flow IDs from ONOS" )
alisone14d7b02016-07-06 10:31:51 -0700567 flowIds = [ f.get( "id" ) for f in flows if "rest" in f.get( "appId" ) ]
GlennRC956ea742015-11-05 16:14:15 -0800568 # convert the flowIDs to ints then hex and finally back to strings
alisone14d7b02016-07-06 10:31:51 -0700569 flowIds = [ str( hex( int( x ) ) ) for x in flowIds ]
570 main.log.info( "ONOS flow IDs: {}".format( flowIds ) )
GlennRC956ea742015-11-05 16:14:15 -0800571
572 stepResult = main.Mininet1.checkFlowId( "s1", flowIds, debug=False )
573
574 utilities.assert_equals( expect=main.TRUE,
575 actual=stepResult,
576 onpass="All flows are in mininet",
577 onfail="All flows are NOT in mininet" )
578
GlennRC073e8bc2015-10-27 17:11:28 -0700579 main.step( "Send a packet to verify the flow are correct" )
580
581 # The receiving interface
alisone14d7b02016-07-06 10:31:51 -0700582 recIface = "{}-eth0.{}".format( main.h4.name, vlan )
GlennRC073e8bc2015-10-27 17:11:28 -0700583 main.log.info( "Starting filter on host2" )
584 # Filter is setup to catch any packet on the vlan interface with the correct vlan tag
Jon Hallfc951072017-05-24 15:55:34 -0700585 main.h4.startFilter( ifaceName=recIface, pktFilter="" )
GlennRC073e8bc2015-10-27 17:11:28 -0700586
587 # Broadcast the packet on the vlan interface. We only care if the flow forwards
588 # the packet with the correct vlan tag, not if the mac addr is correct
alisone14d7b02016-07-06 10:31:51 -0700589 sendIface = "{}-eth0.{}".format( main.h3.name, vlan )
GlennRC073e8bc2015-10-27 17:11:28 -0700590 main.log.info( "Broadcasting the packet with a vlan tag" )
GlennRC956ea742015-11-05 16:14:15 -0800591 main.h3.sendPacket( iface=sendIface,
alisone14d7b02016-07-06 10:31:51 -0700592 packet="Ether()/Dot1Q(vlan={})".format( vlan ) )
GlennRC073e8bc2015-10-27 17:11:28 -0700593
594 main.log.info( "Checking filter for our packet" )
Jon Hallfc951072017-05-24 15:55:34 -0700595 stepResult = main.h4.checkFilter()
GlennRC073e8bc2015-10-27 17:11:28 -0700596 if stepResult:
Jon Hallfc951072017-05-24 15:55:34 -0700597 main.log.info( "Packet: %s" % main.h4.readPackets() )
598 else:
599 main.h4.killFilter()
GlennRC073e8bc2015-10-27 17:11:28 -0700600
601 main.log.info( "Clean up host components" )
602 for host in hosts:
Jon Hallfc951072017-05-24 15:55:34 -0700603 host.stopScapy()
alisone14d7b02016-07-06 10:31:51 -0700604 main.Mininet1.removeHostComponent( "h3" )
605 main.Mininet1.removeHostComponent( "h4" )
GlennRC073e8bc2015-10-27 17:11:28 -0700606
607 utilities.assert_equals( expect=main.TRUE,
608 actual=stepResult,
609 onpass="Successfully sent a packet",
610 onfail="Failed to send a packet" )
GlennRC68449942015-10-16 16:03:12 -0700611
GlennRC956ea742015-11-05 16:14:15 -0800612 def CASE1300( self, main ):
Jon Hallfc951072017-05-24 15:55:34 -0700613 """
GlennRC956ea742015-11-05 16:14:15 -0800614 Add flows with MPLS selector and verify the flows
Jon Hallfc951072017-05-24 15:55:34 -0700615 """
GlennRC956ea742015-11-05 16:14:15 -0800616 import json
617 import time
618
619 main.case( "Verify the MPLS selector is correctly compiled on the flow." )
620 main.caseExplanation = "Install one flow with an MPLS selector, " +\
alisone14d7b02016-07-06 10:31:51 -0700621 "verify the flow is added in ONOS, and finally " +\
GlennRC956ea742015-11-05 16:14:15 -0800622 "send a packet via scapy that has a MPLS label."
623
624 main.step( "Add a flow with a MPLS selector" )
625
626 main.log.info( "Creating host components" )
Jon Halla510a8a2016-05-04 15:09:28 -0700627 main.Scapy.createHostComponent( "h1" )
628 main.Scapy.createHostComponent( "h2" )
alisone14d7b02016-07-06 10:31:51 -0700629 hosts = [ main.h1, main.h2 ]
GlennRC956ea742015-11-05 16:14:15 -0800630 for host in hosts:
Jon Hallfc951072017-05-24 15:55:34 -0700631 host.startHostCli()
GlennRC956ea742015-11-05 16:14:15 -0800632 host.startScapy( main.dependencyPath )
Jon Hallfc951072017-05-24 15:55:34 -0700633 host.updateSelf()
GlennRC956ea742015-11-05 16:14:15 -0800634
635 # ports
636 egress = 2
637 ingress = 1
638 # MPLS etherType
639 ethType = main.params[ 'TEST' ][ 'mplsType' ]
640 # MPLS label
641 mplsLabel = main.params[ 'TEST' ][ 'mpls' ]
642
643 # Add a flow that connects host1 on port1 to host2 on port2
644 main.log.info( "Adding flow with MPLS selector" )
645 stepResult = main.ONOSrest.addFlow( deviceId=main.swDPID,
646 egressPort=egress,
647 ingressPort=ingress,
648 ethType=ethType,
649 mpls=mplsLabel,
650 debug=main.debug )
651
652 utilities.assert_equals( expect=main.TRUE,
653 actual=stepResult,
654 onpass="Successfully added flow",
655 onfail="Failed add flow" )
656
657 # Giving ONOS time to add the flow
658 time.sleep( main.addFlowSleep )
659
660 main.step( "Check flow is in the ADDED state" )
661
662 main.log.info( "Get the flows from ONOS" )
Jeremy86160992016-04-11 10:05:53 -0700663 try:
Jon Hallfc951072017-05-24 15:55:34 -0700664 flows = json.loads( main.ONOSrest.flows() )
GlennRC956ea742015-11-05 16:14:15 -0800665
Jeremy86160992016-04-11 10:05:53 -0700666 stepResult = main.TRUE
667 for f in flows:
alisone14d7b02016-07-06 10:31:51 -0700668 if "rest" in f.get( "appId" ):
669 if "ADDED" not in f.get( "state" ):
Jeremy86160992016-04-11 10:05:53 -0700670 stepResult = main.FALSE
alisone14d7b02016-07-06 10:31:51 -0700671 main.log.error( "Flow: %s in state: %s" % ( f.get( "id" ), f.get( "state" ) ) )
Jeremy86160992016-04-11 10:05:53 -0700672 except TypeError:
673 main.log.error( "No Flows found by the REST API" )
674 stepResult = main.FALSE
675 except ValueError:
676 main.log.error( "Problem getting Flows state from REST API. Exiting test" )
Jon Hallfc951072017-05-24 15:55:34 -0700677 main.cleanup()
678 main.exit()
GlennRC956ea742015-11-05 16:14:15 -0800679
680 utilities.assert_equals( expect=main.TRUE,
681 actual=stepResult,
682 onpass="All flows are in the ADDED state",
683 onfail="All flows are NOT in the ADDED state" )
684
685 main.step( "Check flows are in Mininet's flow table" )
686
687 # get the flow IDs that were added through rest
688 main.log.info( "Getting the flow IDs from ONOS" )
alisone14d7b02016-07-06 10:31:51 -0700689 flowIds = [ f.get( "id" ) for f in flows if "rest" in f.get( "appId" ) ]
GlennRC956ea742015-11-05 16:14:15 -0800690 # convert the flowIDs to ints then hex and finally back to strings
alisone14d7b02016-07-06 10:31:51 -0700691 flowIds = [ str( hex( int( x ) ) ) for x in flowIds ]
692 main.log.info( "ONOS flow IDs: {}".format( flowIds ) )
GlennRC956ea742015-11-05 16:14:15 -0800693
694 stepResult = main.Mininet1.checkFlowId( "s1", flowIds, debug=True )
695
696 utilities.assert_equals( expect=main.TRUE,
697 actual=stepResult,
698 onpass="All flows are in mininet",
699 onfail="All flows are NOT in mininet" )
700
701 main.step( "Send a packet to verify the flow is correct" )
702
703 main.log.info( "Starting filter on host2" )
704 main.h2.startFilter( pktFilter="mpls" )
705
706 main.log.info( "Constructing packet" )
707 main.log.info( "Sending packet to host2" )
alisone14d7b02016-07-06 10:31:51 -0700708 main.h1.sendPacket( packet='Ether()/MPLS(label={})'.format( mplsLabel ) )
GlennRC956ea742015-11-05 16:14:15 -0800709
710 main.log.info( "Checking filter for our packet" )
Jon Hallfc951072017-05-24 15:55:34 -0700711 stepResult = main.h2.checkFilter()
GlennRC956ea742015-11-05 16:14:15 -0800712 if stepResult:
Jon Hallfc951072017-05-24 15:55:34 -0700713 main.log.info( "Packet: %s" % main.h2.readPackets() )
714 else:
715 main.h2.killFilter()
GlennRC956ea742015-11-05 16:14:15 -0800716
717 main.log.info( "Clean up host components" )
718 for host in hosts:
Jon Hallfc951072017-05-24 15:55:34 -0700719 host.stopScapy()
alisone14d7b02016-07-06 10:31:51 -0700720 main.Mininet1.removeHostComponent( "h1" )
721 main.Mininet1.removeHostComponent( "h2" )
GlennRC956ea742015-11-05 16:14:15 -0800722
723 utilities.assert_equals( expect=main.TRUE,
724 actual=stepResult,
725 onpass="Successfully sent a packet",
726 onfail="Failed to send a packet" )
727
alisone14d7b02016-07-06 10:31:51 -0700728 def CASE1700( self, main ):
Jon Hallfc951072017-05-24 15:55:34 -0700729 """
GlennRC956ea742015-11-05 16:14:15 -0800730 Add flows with a TCP selector and verify the flow
Jon Hallfc951072017-05-24 15:55:34 -0700731 """
GlennRC956ea742015-11-05 16:14:15 -0800732 import json
733 import time
734
735 main.case( "Verify the TCP selector is correctly compiled on the flow" )
736 main.caseExplanation = "Install a flow with only the TCP selector " +\
alisone14d7b02016-07-06 10:31:51 -0700737 "specified, verify the flow is added in ONOS, and finally " +\
GlennRC956ea742015-11-05 16:14:15 -0800738 "send a TCP packet to verify the TCP selector is compiled correctly."
739
740 main.step( "Add a flow with a TCP selector" )
741
742 main.log.info( "Creating host components" )
Jon Halla510a8a2016-05-04 15:09:28 -0700743 main.Scapy.createHostComponent( "h1" )
744 main.Scapy.createHostComponent( "h2" )
alisone14d7b02016-07-06 10:31:51 -0700745 hosts = [ main.h1, main.h2 ]
GlennRC956ea742015-11-05 16:14:15 -0800746 for host in hosts:
Jon Hallfc951072017-05-24 15:55:34 -0700747 host.startHostCli()
748 host.startScapy()
749 host.updateSelf()
GlennRC956ea742015-11-05 16:14:15 -0800750
751 # Add a flow that connects host1 on port1 to host2 on port2
752 egress = 2
753 ingress = 1
754 # IPv4 etherType
755 ethType = main.params[ 'TEST' ][ 'ip4Type' ]
756 # IP protocol
757 ipProto = main.params[ 'TEST' ][ 'tcpProto' ]
758 # TCP port destination
759 tcpDst = main.params[ 'TEST' ][ 'tcpDst' ]
760
761 main.log.info( "Add a flow that connects host1 on port1 to host2 on port2" )
762 stepResult = main.ONOSrest.addFlow( deviceId=main.swDPID,
763 egressPort=egress,
764 ingressPort=ingress,
765 ethType=ethType,
766 ipProto=ipProto,
767 tcpDst=tcpDst,
768 debug=main.debug )
769
770 utilities.assert_equals( expect=main.TRUE,
771 actual=stepResult,
772 onpass="Successfully added flows",
773 onfail="Failed add flows" )
774
775 # Giving ONOS time to add the flow
776 time.sleep( main.addFlowSleep )
777
Devin Lim58046fa2017-07-05 16:55:00 -0700778 main.checkingFlow.checkFlow()
GlennRC956ea742015-11-05 16:14:15 -0800779
780 main.step( "Send a packet to verify the flow is correct" )
781
782 main.log.info( "Constructing packet" )
783 # No need for the MAC src dst
784 main.h1.buildEther( dst=main.h2.hostMac )
785 main.h1.buildIP( dst=main.h2.hostIp )
786 main.h1.buildTCP( dport=tcpDst )
787
788 main.log.info( "Starting filter on host2" )
789 # Defaults to ip
790 main.h2.startFilter( pktFilter="tcp" )
791
792 main.log.info( "Sending packet to host2" )
Jon Hallfc951072017-05-24 15:55:34 -0700793 main.h1.sendPacket()
GlennRC956ea742015-11-05 16:14:15 -0800794
795 main.log.info( "Checking filter for our packet" )
Jon Hallfc951072017-05-24 15:55:34 -0700796 stepResult = main.h2.checkFilter()
GlennRC956ea742015-11-05 16:14:15 -0800797 if stepResult:
Jon Hallfc951072017-05-24 15:55:34 -0700798 main.log.info( "Packet: %s" % main.h2.readPackets() )
799 else:
800 main.h2.killFilter()
GlennRC956ea742015-11-05 16:14:15 -0800801
802 main.log.info( "Clean up host components" )
803 for host in hosts:
Jon Hallfc951072017-05-24 15:55:34 -0700804 host.stopScapy()
alisone14d7b02016-07-06 10:31:51 -0700805 main.Mininet1.removeHostComponent( "h1" )
806 main.Mininet1.removeHostComponent( "h2" )
GlennRC956ea742015-11-05 16:14:15 -0800807
808 utilities.assert_equals( expect=main.TRUE,
809 actual=stepResult,
810 onpass="Successfully sent a packet",
811 onfail="Failed to send a packet" )
812
alisone14d7b02016-07-06 10:31:51 -0700813 def CASE1600( self, main ):
Jon Hallfc951072017-05-24 15:55:34 -0700814 """
GlennRC956ea742015-11-05 16:14:15 -0800815 Add flows with a UDP selector and verify the flow
Jon Hallfc951072017-05-24 15:55:34 -0700816 """
GlennRC956ea742015-11-05 16:14:15 -0800817 import json
818 import time
819
820 main.case( "Verify the UDP selector is correctly compiled on the flow" )
821 main.caseExplanation = "Install a flow with only the UDP selector " +\
alisone14d7b02016-07-06 10:31:51 -0700822 "specified, verify the flow is added in ONOS, and finally " +\
GlennRC956ea742015-11-05 16:14:15 -0800823 "send a UDP packet to verify the UDP selector is compiled correctly."
824
825 main.step( "Add a flow with a UDP selector" )
826
827 main.log.info( "Creating host components" )
Jon Halla510a8a2016-05-04 15:09:28 -0700828 main.Scapy.createHostComponent( "h1" )
829 main.Scapy.createHostComponent( "h2" )
alisone14d7b02016-07-06 10:31:51 -0700830 hosts = [ main.h1, main.h2 ]
GlennRC956ea742015-11-05 16:14:15 -0800831 for host in hosts:
Jon Hallfc951072017-05-24 15:55:34 -0700832 host.startHostCli()
833 host.startScapy()
834 host.updateSelf()
GlennRC956ea742015-11-05 16:14:15 -0800835
836 # Add a flow that connects host1 on port1 to host2 on port2
837 egress = 2
838 ingress = 1
839 # IPv4 etherType
840 ethType = main.params[ 'TEST' ][ 'ip4Type' ]
841 # IP protocol
842 ipProto = main.params[ 'TEST' ][ 'udpProto' ]
843 # UDP port destination
844 udpDst = main.params[ 'TEST' ][ 'udpDst' ]
845
846 main.log.info( "Add a flow that connects host1 on port1 to host2 on port2" )
847 stepResult = main.ONOSrest.addFlow( deviceId=main.swDPID,
848 egressPort=egress,
849 ingressPort=ingress,
850 ethType=ethType,
851 ipProto=ipProto,
852 udpDst=udpDst,
853 debug=main.debug )
854
855 utilities.assert_equals( expect=main.TRUE,
856 actual=stepResult,
857 onpass="Successfully added flows",
858 onfail="Failed add flows" )
859
860 # Giving ONOS time to add the flow
861 time.sleep( main.addFlowSleep )
862
Devin Lim58046fa2017-07-05 16:55:00 -0700863 main.checkingFlow.checkFlow()
GlennRC956ea742015-11-05 16:14:15 -0800864
865 main.step( "Send a packet to verify the flow is correct" )
866
867 main.log.info( "Constructing packet" )
868 # No need for the MAC src dst
869 main.h1.buildEther( dst=main.h2.hostMac )
870 main.h1.buildIP( dst=main.h2.hostIp )
871 main.h1.buildUDP( dport=udpDst )
872
873 main.log.info( "Starting filter on host2" )
874 # Defaults to ip
875 main.h2.startFilter( pktFilter="udp" )
876
877 main.log.info( "Sending packet to host2" )
Jon Hallfc951072017-05-24 15:55:34 -0700878 main.h1.sendPacket()
GlennRC956ea742015-11-05 16:14:15 -0800879
880 main.log.info( "Checking filter for our packet" )
Jon Hallfc951072017-05-24 15:55:34 -0700881 stepResult = main.h2.checkFilter()
GlennRC956ea742015-11-05 16:14:15 -0800882 if stepResult:
Jon Hallfc951072017-05-24 15:55:34 -0700883 main.log.info( "Packet: %s" % main.h2.readPackets() )
884 else:
885 main.h2.killFilter()
GlennRC956ea742015-11-05 16:14:15 -0800886
887 main.log.info( "Clean up host components" )
888 for host in hosts:
Jon Hallfc951072017-05-24 15:55:34 -0700889 host.stopScapy()
alisone14d7b02016-07-06 10:31:51 -0700890 main.Mininet1.removeHostComponent( "h1" )
891 main.Mininet1.removeHostComponent( "h2" )
GlennRC956ea742015-11-05 16:14:15 -0800892
893 utilities.assert_equals( expect=main.TRUE,
894 actual=stepResult,
895 onpass="Successfully sent a packet",
896 onfail="Failed to send a packet" )
897
alisone14d7b02016-07-06 10:31:51 -0700898 def CASE1900( self, main ):
Jon Hallfc951072017-05-24 15:55:34 -0700899 """
alisone14d7b02016-07-06 10:31:51 -0700900 Add flows with a ICMPv4 selector and verify the flow
Jon Hallfc951072017-05-24 15:55:34 -0700901 """
GlennRC956ea742015-11-05 16:14:15 -0800902 import json
alisone14d7b02016-07-06 10:31:51 -0700903 import time
GlennRC956ea742015-11-05 16:14:15 -0800904
alisone14d7b02016-07-06 10:31:51 -0700905 main.case( "Verify the ICMPv4 selector is correctly compiled on the flow" )
906 main.caseExplanation = "Install a flow with only the ICMPv4 selector " +\
907 "specified, verify the flow is added in ONOS, and finally " +\
908 "send a IMCPv4 packet to verify the ICMPv4 selector is compiled correctly."
GlennRC956ea742015-11-05 16:14:15 -0800909
alisone14d7b02016-07-06 10:31:51 -0700910 main.step( "Add a flow with a ICMPv4 selector" )
911
912 main.log.info( "Creating host components" )
913 main.Scapy.createHostComponent( "h1" )
914 main.Scapy.createHostComponent( "h2" )
915 hosts = [ main.h1, main.h2 ]
916 for host in hosts:
Jon Hallfc951072017-05-24 15:55:34 -0700917 host.startHostCli()
918 host.startScapy()
919 host.updateSelf()
alisone14d7b02016-07-06 10:31:51 -0700920
921 # Add a flow that connects host1 on port1 to host2 on port2
922 egress = 2
923 ingress = 1
924 # IPv4 etherType
925 ethType = main.params[ 'TEST' ][ 'ip4Type' ]
926 # IP protocol
927 ipProto = main.params[ 'TEST' ][ 'icmpProto' ]
928
929 main.log.info( "Add a flow that connects host1 on port1 to host2 on port2" )
930 stepResult = main.ONOSrest.addFlow( deviceId=main.swDPID,
931 egressPort=egress,
932 ingressPort=ingress,
933 ethType=ethType,
934 ipProto=ipProto,
935 debug=main.debug )
936
937 utilities.assert_equals( expect=main.TRUE,
938 actual=stepResult,
939 onpass="Successfully added flows",
940 onfail="Failed add flows" )
941
942 # Giving ONOS time to add the flow
943 time.sleep( main.addFlowSleep )
944
Devin Lim58046fa2017-07-05 16:55:00 -0700945 main.checkingFlow.checkFlow()
alisone14d7b02016-07-06 10:31:51 -0700946
947 main.step( "Send a packet to verify the flow is correct" )
948
949 main.log.info( "Constructing packet" )
950 # No need for the MAC src dst
951 main.h1.buildEther( dst=main.h2.hostMac )
952 main.h1.buildIP( dst=main.h2.hostIp )
Jon Hallfc951072017-05-24 15:55:34 -0700953 main.h1.buildICMP()
alisone14d7b02016-07-06 10:31:51 -0700954
955 main.log.info( "Starting filter on host2" )
956 # Defaults to ip
957 main.h2.startFilter( pktFilter="icmp" )
958
959 main.log.info( "Sending packet to host2" )
Jon Hallfc951072017-05-24 15:55:34 -0700960 main.h1.sendPacket()
alisone14d7b02016-07-06 10:31:51 -0700961
962 main.log.info( "Checking filter for our packet" )
Jon Hallfc951072017-05-24 15:55:34 -0700963 stepResult = main.h2.checkFilter()
alisone14d7b02016-07-06 10:31:51 -0700964 if stepResult:
Jon Hallfc951072017-05-24 15:55:34 -0700965 main.log.info( "Packet: %s" % main.h2.readPackets() )
966 else:
967 main.h2.killFilter()
alisone14d7b02016-07-06 10:31:51 -0700968
969 main.log.info( "Clean up host components" )
970 for host in hosts:
Jon Hallfc951072017-05-24 15:55:34 -0700971 host.stopScapy()
alisone14d7b02016-07-06 10:31:51 -0700972 main.Mininet1.removeHostComponent( "h1" )
973 main.Mininet1.removeHostComponent( "h2" )
974
975 utilities.assert_equals( expect=main.TRUE,
976 actual=stepResult,
977 onpass="Successfully sent a packet",
978 onfail="Failed to send a packet" )
979
980 def CASE2000( self, main ):
Jon Hallfc951072017-05-24 15:55:34 -0700981 """
alisone14d7b02016-07-06 10:31:51 -0700982 Add flows with a ICMPv6 selector and verify the flow
Jon Hallfc951072017-05-24 15:55:34 -0700983 """
alisone14d7b02016-07-06 10:31:51 -0700984 import json
985 import time
986
987 main.case( "Verify the ICMPv6 selector is correctly compiled on the flow" )
988 main.caseExplanation = "Install a flow with only the ICMPv6 selector " +\
989 "specified, verify the flow is added in ONOS, and finally " +\
990 "send a IMCPv6 packet to verify the ICMPv6 selector is compiled correctly."
991
992 main.step( "Add a flow with a ICMPv6 selector" )
993
994 main.log.info( "Creating host components" )
995 main.Scapy.createHostComponent( "h5" )
996 main.Scapy.createHostComponent( "h6" )
Jon Hallfc951072017-05-24 15:55:34 -0700997 hosts = [ main.h5, main.h6 ]
alisone14d7b02016-07-06 10:31:51 -0700998 for host in hosts:
Jon Hallfc951072017-05-24 15:55:34 -0700999 host.startHostCli()
1000 host.startScapy()
alisone14d7b02016-07-06 10:31:51 -07001001 host.updateSelf( IPv6=True )
1002
1003 # Add a flow that connects host1 on port1 to host2 on port2
Jon Hallfc951072017-05-24 15:55:34 -07001004 egress = 6
1005 ingress = 5
alisone14d7b02016-07-06 10:31:51 -07001006 # IPv6 etherType
1007 ethType = main.params[ 'TEST' ][ 'ip6Type' ]
1008 # IP protocol
1009 ipProto = main.params[ 'TEST' ][ 'icmp6Proto' ]
1010
1011 main.log.info( "Add a flow that connects host1 on port1 to host2 on port2" )
1012 stepResult = main.ONOSrest.addFlow( deviceId=main.swDPID,
1013 egressPort=egress,
1014 ingressPort=ingress,
1015 ethType=ethType,
1016 ipProto=ipProto,
1017 debug=main.debug )
1018
1019 utilities.assert_equals( expect=main.TRUE,
1020 actual=stepResult,
1021 onpass="Successfully added flows",
1022 onfail="Failed add flows" )
1023
1024 # Giving ONOS time to add the flow
1025 time.sleep( main.addFlowSleep )
1026
Devin Lim58046fa2017-07-05 16:55:00 -07001027 main.checkingFlow.checkFlow()
alisone14d7b02016-07-06 10:31:51 -07001028
1029 main.step( "Send a packet to verify the flow is correct" )
1030
1031 main.log.info( "Constructing packet" )
1032 # No need for the MAC src dst
1033 main.h5.buildEther( dst=main.h6.hostMac )
1034 main.h5.buildIPv6( dst=main.h6.hostIp )
1035 main.h5.buildICMP( ipVersion=6 )
1036
1037 main.log.info( "Starting filter on host2" )
1038 # Defaults to ip
1039 main.h6.startFilter( pktFilter="icmp6" )
1040
1041 main.log.info( "Sending packet to host2" )
Jon Hallfc951072017-05-24 15:55:34 -07001042 main.h5.sendPacket()
alisone14d7b02016-07-06 10:31:51 -07001043
1044 main.log.info( "Checking filter for our packet" )
Jon Hallfc951072017-05-24 15:55:34 -07001045 stepResult = main.h6.checkFilter()
alisone14d7b02016-07-06 10:31:51 -07001046 if stepResult:
Jon Hallfc951072017-05-24 15:55:34 -07001047 main.log.info( "Packet: %s" % main.h6.readPackets() )
1048 else:
1049 main.h6.killFilter()
alisone14d7b02016-07-06 10:31:51 -07001050
1051 main.log.info( "Clean up host components" )
1052 for host in hosts:
Jon Hallfc951072017-05-24 15:55:34 -07001053 host.stopScapy()
alisone14d7b02016-07-06 10:31:51 -07001054 main.Mininet1.removeHostComponent( "h5" )
1055 main.Mininet1.removeHostComponent( "h6" )
1056
1057 utilities.assert_equals( expect=main.TRUE,
1058 actual=stepResult,
1059 onpass="Successfully sent a packet",
1060 onfail="Failed to send a packet" )
1061
1062 def CASE3000( self, main ):
Jon Hallfc951072017-05-24 15:55:34 -07001063 """
alisone14d7b02016-07-06 10:31:51 -07001064 Delete flow
Jon Hallfc951072017-05-24 15:55:34 -07001065 """
alisone14d7b02016-07-06 10:31:51 -07001066 import json
1067
1068 main.case( "Delete flows that were added through rest" )
1069 main.step( "Deleting flows" )
1070
1071 main.log.info( "Getting flows" )
1072 try:
Jon Hallfc951072017-05-24 15:55:34 -07001073 flows = json.loads( main.ONOSrest.flows() )
alisone14d7b02016-07-06 10:31:51 -07001074
1075 stepResult = main.TRUE
1076 for f in flows:
1077 if "rest" in f.get( "appId" ):
Jon Hallfc951072017-05-24 15:55:34 -07001078 if main.debug:
1079 main.log.debug( "Flow to be deleted:\n{}".format( main.ONOSrest.pprint( f ) ) )
alisone14d7b02016-07-06 10:31:51 -07001080 stepResult = stepResult and main.ONOSrest.removeFlow( f.get( "deviceId" ), f.get( "id" ) )
1081 except TypeError:
1082 main.log.error( "No Flows found by the REST API" )
1083 stepResult = main.FALSE
1084 except ValueError:
1085 main.log.error( "Problem getting Flows state from REST API. Exiting test" )
Jon Hallfc951072017-05-24 15:55:34 -07001086 main.cleanup()
1087 main.exit()
GlennRC956ea742015-11-05 16:14:15 -08001088
1089 utilities.assert_equals( expect=main.TRUE,
1090 actual=stepResult,
1091 onpass="Successfully deleting flows",
1092 onfail="Failed to delete flows" )
1093
1094 time.sleep( main.delFlowSleep )
1095
Jon Hallfc951072017-05-24 15:55:34 -07001096 def CASE1200( self, main ):
1097 """
alisone14d7b02016-07-06 10:31:51 -07001098 Add flows with a ARP selector and verify the flow
Jon Hallfc951072017-05-24 15:55:34 -07001099 """
alisone14d7b02016-07-06 10:31:51 -07001100 import json
1101 import time
1102
1103 main.case( "Verify flow IP selectors are correctly compiled" )
1104 main.caseExplanation = "Install two flows with only IP selectors " + \
1105 "specified, then verify flows are added in ONOS, finally " + \
1106 "send a packet that only specifies the IP src and dst."
1107
1108 main.step( "Add flows with ARP addresses as the only selectors" )
1109
1110 main.log.info( "Creating host components" )
1111 main.Scapy.createHostComponent( "h1" )
1112 main.Scapy.createHostComponent( "h2" )
1113 hosts = [ main.h1, main.h2 ]
1114 for host in hosts:
Jon Hallfc951072017-05-24 15:55:34 -07001115 host.startHostCli()
1116 host.startScapy()
1117 host.updateSelf()
alisone14d7b02016-07-06 10:31:51 -07001118
1119 # Add a flow that connects host1 on port1 to host2 on port2
1120 # send output on port2
1121 # recieve input on port1
1122 egress = 2
1123 ingress = 1
1124 # ARP etherType = 0x0806
1125 ethType = main.params[ 'TEST' ][ 'arpType' ]
1126
1127 # Add flows that connects host1 to host2
1128 main.log.info( "Add flow with port ingress 1 to port egress 2" )
Jon Hallfc951072017-05-24 15:55:34 -07001129 stepResult = main.ONOSrest.addFlow( deviceId=main.swDPID,
1130 egressPort=egress,
1131 ingressPort=ingress,
1132 ethType=ethType,
1133 priority=40001,
1134 debug=main.debug )
alisone14d7b02016-07-06 10:31:51 -07001135
1136 utilities.assert_equals( expect=main.TRUE,
1137 actual=stepResult,
1138 onpass="Successfully added flows",
1139 onfail="Failed add flows" )
1140
1141 # Giving ONOS time to add the flow
1142 time.sleep( main.addFlowSleep )
1143
Devin Lim58046fa2017-07-05 16:55:00 -07001144 main.checkingFlow.checkFlow()
alisone14d7b02016-07-06 10:31:51 -07001145
1146 main.step( "Send a packet to verify the flow is correct" )
1147
1148 main.log.info( "Constructing packet" )
1149 # No need for the MAC src dst
1150 main.h1.buildEther( src=main.h1.hostMac, dst=main.h2.hostMac )
1151 main.h1.buildARP( pdst=main.h2.hostIp )
1152
1153 main.log.info( "Starting filter on host2" )
1154 # Defaults to ip
1155 main.h2.startFilter( pktFilter="arp" )
1156
1157 main.log.info( "Sending packet to host2" )
Jon Hallfc951072017-05-24 15:55:34 -07001158 main.h1.sendPacket()
alisone14d7b02016-07-06 10:31:51 -07001159
1160 main.log.info( "Checking filter for our packet" )
Jon Hallfc951072017-05-24 15:55:34 -07001161 stepResult = main.h2.checkFilter()
alisone14d7b02016-07-06 10:31:51 -07001162 if stepResult:
Jon Hallfc951072017-05-24 15:55:34 -07001163 main.log.info( "Packet: %s" % main.h2.readPackets() )
alisone14d7b02016-07-06 10:31:51 -07001164 else:
Jon Hallfc951072017-05-24 15:55:34 -07001165 main.h2.killFilter()
alisone14d7b02016-07-06 10:31:51 -07001166
1167 main.log.info( "Clean up host components" )
1168 for host in hosts:
Jon Hallfc951072017-05-24 15:55:34 -07001169 host.stopScapy()
alisone14d7b02016-07-06 10:31:51 -07001170 main.Mininet1.removeHostComponent( "h1" )
1171 main.Mininet1.removeHostComponent( "h2" )
1172
1173 utilities.assert_equals( expect=main.TRUE,
1174 actual=stepResult,
1175 onpass="Successfully sent a packet",
1176 onfail="Failed to send a packet" )
1177
1178 def CASE1800( self, main ):
Jon Hallfc951072017-05-24 15:55:34 -07001179 """
alisone14d7b02016-07-06 10:31:51 -07001180 Add flows with a SCTP selector and verify the flow
Jon Hallfc951072017-05-24 15:55:34 -07001181 """
alisone14d7b02016-07-06 10:31:51 -07001182 import json
1183 import time
1184
1185 main.case( "Verify the UDP selector is correctly compiled on the flow" )
1186 main.caseExplanation = "Install a flow with only the UDP selector " + \
1187 "specified, verify the flow is added in ONOS, and finally " + \
1188 "send a UDP packet to verify the UDP selector is compiled correctly."
1189
1190 main.step( "Add a flow with a SCTP selector" )
1191
1192 main.log.info( "Creating host components" )
1193 main.Scapy.createHostComponent( "h1" )
1194 main.Scapy.createHostComponent( "h2" )
1195 hosts = [ main.h1, main.h2 ]
1196 for host in hosts:
Jon Hallfc951072017-05-24 15:55:34 -07001197 host.startHostCli()
1198 host.startScapy()
1199 host.updateSelf()
alisone14d7b02016-07-06 10:31:51 -07001200
1201 # Add a flow that connects host1 on port1 to host2 on port2
1202 egress = 2
1203 ingress = 1
1204 # IPv4 etherType
1205 ethType = main.params[ 'TEST' ][ 'ip4Type' ]
1206 # IP protocol
1207 ipProto = main.params[ 'TEST' ][ 'sctpProto' ]
1208
Jon Hallfc951072017-05-24 15:55:34 -07001209 main.log.info( "Add a flow that connects host1 on port1 to host2 on port2" )
alisone14d7b02016-07-06 10:31:51 -07001210 stepResult = main.ONOSrest.addFlow( deviceId=main.swDPID,
1211 egressPort=egress,
1212 ingressPort=ingress,
1213 ethType=ethType,
1214 ipProto=ipProto,
1215 debug=main.debug )
1216
1217 utilities.assert_equals( expect=main.TRUE,
1218 actual=stepResult,
1219 onpass="Successfully added flows",
1220 onfail="Failed add flows" )
1221
1222 # Giving ONOS time to add the flow
1223 time.sleep( main.addFlowSleep )
1224
Devin Lim58046fa2017-07-05 16:55:00 -07001225 main.checkingFlow.checkFlow()
alisone14d7b02016-07-06 10:31:51 -07001226
1227 main.step( "Send a packet to verify the flow is correct" )
1228
1229 main.log.info( "Constructing packet" )
1230 # No need for the MAC src dst
1231 main.h1.buildEther( dst=main.h2.hostMac )
1232 main.h1.buildIP( dst=main.h2.hostIp )
Jon Hallfc951072017-05-24 15:55:34 -07001233 main.h1.buildSCTP()
alisone14d7b02016-07-06 10:31:51 -07001234
1235 main.log.info( "Starting filter on host2" )
1236 # Defaults to ip
1237 main.h2.startFilter( pktFilter="sctp" )
1238
1239 main.log.info( "Sending packet to host2" )
Jon Hallfc951072017-05-24 15:55:34 -07001240 main.h1.sendPacket()
alisone14d7b02016-07-06 10:31:51 -07001241
1242 main.log.info( "Checking filter for our packet" )
Jon Hallfc951072017-05-24 15:55:34 -07001243 stepResult = main.h2.checkFilter()
alisone14d7b02016-07-06 10:31:51 -07001244 if stepResult:
Jon Hallfc951072017-05-24 15:55:34 -07001245 main.log.info( "Packet: %s" % main.h2.readPackets() )
alisone14d7b02016-07-06 10:31:51 -07001246 else:
Jon Hallfc951072017-05-24 15:55:34 -07001247 main.h2.killFilter()
alisone14d7b02016-07-06 10:31:51 -07001248
1249 main.log.info( "Clean up host components" )
1250 for host in hosts:
Jon Hallfc951072017-05-24 15:55:34 -07001251 host.stopScapy()
alisone14d7b02016-07-06 10:31:51 -07001252 main.Mininet1.removeHostComponent( "h1" )
1253 main.Mininet1.removeHostComponent( "h2" )
1254
1255 utilities.assert_equals( expect=main.TRUE,
1256 actual=stepResult,
1257 onpass="Successfully sent a packet",
1258 onfail="Failed to send a packet" )
1259
GlennRC68449942015-10-16 16:03:12 -07001260 def CASE100( self, main ):
Jon Hallfc951072017-05-24 15:55:34 -07001261 """
GlennRC5147a422015-10-06 17:26:17 -07001262 Report errors/warnings/exceptions
Jon Hallfc951072017-05-24 15:55:34 -07001263 """
alisone14d7b02016-07-06 10:31:51 -07001264 main.log.info( "Error report: \n" )
GlennRC5147a422015-10-06 17:26:17 -07001265 main.ONOSbench.logReport( main.ONOSip[ 0 ],
1266 [ "INFO",
1267 "FOLLOWER",
1268 "WARN",
1269 "flow",
1270 "ERROR",
1271 "Except" ],
GlennRC68449942015-10-16 16:03:12 -07001272 "s" )