blob: df64bb4f969781974b5cc5c132d6a212dfa3bcd8 [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
9
10 """
11 - Construct tests variables
12 - GIT ( optional )
13 - Checkout ONOS master branch
14 - Pull latest ONOS code
15 - Building ONOS ( optional )
16 - Install ONOS package
17 - Build ONOS package
18 """
19
20 main.case( "Constructing test variables and building ONOS package" )
21 main.step( "Constructing test variables" )
GlennRC5147a422015-10-06 17:26:17 -070022
23 # Test variables
24 main.testOnDirectory = os.path.dirname( os.getcwd ( ) )
25 main.cellName = main.params[ 'ENV' ][ 'cellName' ]
26 main.apps = main.params[ 'ENV' ][ 'cellApps' ]
27 gitBranch = main.params[ 'GIT' ][ 'branch' ]
GlennRC073e8bc2015-10-27 17:11:28 -070028 gitPull = main.params[ 'GIT' ][ 'pull' ]
29 main.ONOSport = main.params[ 'CTRL' ][ 'port' ]
GlennRC5147a422015-10-06 17:26:17 -070030 main.dependencyPath = main.testOnDirectory + \
31 main.params[ 'DEPENDENCY' ][ 'path' ]
GlennRC5147a422015-10-06 17:26:17 -070032 wrapperFile1 = main.params[ 'DEPENDENCY' ][ 'wrapper1' ]
GlennRC1704d072015-10-07 18:40:45 -070033 wrapperFile2 = main.params[ 'DEPENDENCY' ][ 'wrapper2' ]
GlennRC073e8bc2015-10-27 17:11:28 -070034 main.topology = main.params[ 'DEPENDENCY' ][ 'topology' ]
35 main.maxNodes = int( main.params[ 'SCALE' ][ 'max' ] )
GlennRC5147a422015-10-06 17:26:17 -070036 main.startUpSleep = int( main.params[ 'SLEEP' ][ 'startup' ] )
GlennRC073e8bc2015-10-27 17:11:28 -070037 main.startMNSleep = int( main.params[ 'SLEEP' ][ 'startMN' ] )
38 main.addFlowSleep = int( main.params[ 'SLEEP' ][ 'addFlow' ] )
39 main.delFlowSleep = int( main.params[ 'SLEEP' ][ 'delFlow' ] )
alisone14d7b02016-07-06 10:31:51 -070040 main.debug = main.params[ 'DEBUG' ]
GlennRC073e8bc2015-10-27 17:11:28 -070041 main.swDPID = main.params[ 'TEST' ][ 'swDPID' ]
alisone14d7b02016-07-06 10:31:51 -070042 main.cellData = { } # for creating cell file
43 main.CLIs = [ ]
44 main.ONOSip = [ ]
GlennRC5147a422015-10-06 17:26:17 -070045
GlennRC956ea742015-11-05 16:14:15 -080046 main.debug = True if "on" in main.debug else False
47
alisone14d7b02016-07-06 10:31:51 -070048 main.ONOSip = main.ONOSbench.getOnosIps( )
GlennRC5147a422015-10-06 17:26:17 -070049
50 # Assigning ONOS cli handles to a list
51 for i in range( 1, main.maxNodes + 1 ):
52 main.CLIs.append( getattr( main, 'ONOScli' + str( i ) ) )
53
54 # -- INIT SECTION, ONLY RUNS ONCE -- #
55 main.startUp = imp.load_source( wrapperFile1,
56 main.dependencyPath +
57 wrapperFile1 +
58 ".py" )
59
GlennRC1704d072015-10-07 18:40:45 -070060 main.topo = imp.load_source( wrapperFile2,
61 main.dependencyPath +
62 wrapperFile2 +
63 ".py" )
64
GlennRC956ea742015-11-05 16:14:15 -080065
GlennRC94ed2232015-10-07 15:08:57 -070066 copyResult = main.ONOSbench.scp( main.Mininet1,
alisone14d7b02016-07-06 10:31:51 -070067 main.dependencyPath + main.topology,
68 main.Mininet1.home + '/custom/',
GlennRC94ed2232015-10-07 15:08:57 -070069 direction="to" )
70
alisone14d7b02016-07-06 10:31:51 -070071 utilities.assert_equals( expect=main.TRUE,
Jeremy Songstere7f3b342016-08-17 14:56:49 -070072 actual=copyResult,
73 onpass="Successfully copy " + "test variables ",
74 onfail="Failed to copy test variables" )
alisone14d7b02016-07-06 10:31:51 -070075
76
GlennRC5147a422015-10-06 17:26:17 -070077 if main.CLIs:
78 stepResult = main.TRUE
79 else:
80 main.log.error( "Did not properly created list of ONOS CLI handle" )
81 stepResult = main.FALSE
82
83 utilities.assert_equals( expect=main.TRUE,
84 actual=stepResult,
alisone14d7b02016-07-06 10:31:51 -070085 onpass="Successfully construct " + "test variables ",
GlennRC5147a422015-10-06 17:26:17 -070086 onfail="Failed to construct test variables" )
87
88 if gitPull == 'True':
89 main.step( "Building ONOS in " + gitBranch + " branch" )
90 onosBuildResult = main.startUp.onosBuild( main, gitBranch )
91 stepResult = onosBuildResult
92 utilities.assert_equals( expect=main.TRUE,
93 actual=stepResult,
alisone14d7b02016-07-06 10:31:51 -070094 onpass="Successfully compiled " + "latest ONOS",
95 onfail="Failed to compile " + "latest ONOS" )
GlennRC5147a422015-10-06 17:26:17 -070096 else:
97 main.log.warn( "Did not pull new code so skipping mvn " +
98 "clean install" )
99
100 def CASE2( self, main ):
101 """
102 - Set up cell
103 - Create cell file
104 - Set cell file
105 - Verify cell file
106 - Kill ONOS process
107 - Uninstall ONOS cluster
108 - Verify ONOS start up
109 - Install ONOS cluster
110 - Connect to cli
111 """
alisone14d7b02016-07-06 10:31:51 -0700112 import time
GlennRC5147a422015-10-06 17:26:17 -0700113
114 main.numCtrls = int( main.maxNodes )
115
116 main.case( "Starting up " + str( main.numCtrls ) +
117 " node(s) ONOS cluster" )
118
119 #kill off all onos processes
120 main.log.info( "Safety check, killing all ONOS processes" +
Jon Hall70b2ff42015-11-17 15:49:44 -0800121 " before initiating environment setup" )
GlennRC5147a422015-10-06 17:26:17 -0700122
123 for i in range( main.maxNodes ):
124 main.ONOSbench.onosDie( main.ONOSip[ i ] )
125
Jon Hall53c5e662016-04-13 16:06:56 -0700126 main.log.info( "NODE COUNT = " + str( main.numCtrls ) )
GlennRC5147a422015-10-06 17:26:17 -0700127
alisone14d7b02016-07-06 10:31:51 -0700128 tempOnosIp = [ ]
GlennRC5147a422015-10-06 17:26:17 -0700129 for i in range( main.numCtrls ):
alisone14d7b02016-07-06 10:31:51 -0700130 tempOnosIp.append( main.ONOSip[ i ] )
GlennRC5147a422015-10-06 17:26:17 -0700131
Jon Hall53c5e662016-04-13 16:06:56 -0700132 main.ONOSbench.createCellFile( main.ONOSbench.ip_address,
133 "temp",
134 main.Mininet1.ip_address,
135 main.apps,
136 tempOnosIp )
GlennRC5147a422015-10-06 17:26:17 -0700137
138 main.step( "Apply cell to environment" )
139 cellResult = main.ONOSbench.setCell( "temp" )
alisone14d7b02016-07-06 10:31:51 -0700140 verifyResult = main.ONOSbench.verifyCell( )
GlennRC5147a422015-10-06 17:26:17 -0700141 stepResult = cellResult and verifyResult
142 utilities.assert_equals( expect=main.TRUE,
143 actual=stepResult,
alisone14d7b02016-07-06 10:31:51 -0700144 onpass="Successfully applied cell to " + "environment",
GlennRC5147a422015-10-06 17:26:17 -0700145 onfail="Failed to apply cell to environment " )
146
147 main.step( "Creating ONOS package" )
Jon Hallbd60ea02016-08-23 10:03:59 -0700148 packageResult = main.ONOSbench.buckBuild()
GlennRC5147a422015-10-06 17:26:17 -0700149 stepResult = packageResult
150 utilities.assert_equals( expect=main.TRUE,
151 actual=stepResult,
152 onpass="Successfully created ONOS package",
153 onfail="Failed to create ONOS package" )
154
155 time.sleep( main.startUpSleep )
156 main.step( "Uninstalling ONOS package" )
157 onosUninstallResult = main.TRUE
Jeremy86160992016-04-11 10:05:53 -0700158 for ip in main.ONOSip:
GlennRC5147a422015-10-06 17:26:17 -0700159 onosUninstallResult = onosUninstallResult and \
Jeremy Songstere7f3b342016-08-17 14:56:49 -0700160 main.ONOSbench.onosUninstall( nodeIp=ip )
GlennRC5147a422015-10-06 17:26:17 -0700161 stepResult = onosUninstallResult
162 utilities.assert_equals( expect=main.TRUE,
163 actual=stepResult,
164 onpass="Successfully uninstalled ONOS package",
165 onfail="Failed to uninstall ONOS package" )
GlennRC5147a422015-10-06 17:26:17 -0700166 time.sleep( main.startUpSleep )
167 main.step( "Installing ONOS package" )
168 onosInstallResult = main.TRUE
169 for i in range( main.numCtrls ):
170 onosInstallResult = onosInstallResult and \
Jeremy Songstere7f3b342016-08-17 14:56:49 -0700171 main.ONOSbench.onosInstall( node=main.ONOSip[ i ] )
GlennRC5147a422015-10-06 17:26:17 -0700172 stepResult = onosInstallResult
173 utilities.assert_equals( expect=main.TRUE,
174 actual=stepResult,
175 onpass="Successfully installed ONOS package",
176 onfail="Failed to install ONOS package" )
177
You Wangf5de25b2017-01-06 15:13:01 -0800178 main.step( "Set up ONOS secure SSH" )
179 secureSshResult = main.TRUE
180 for i in range( int( main.numCtrls ) ):
181 secureSshResult = secureSshResult and main.ONOSbench.onosSecureSSH( node=main.ONOSip[i] )
182 utilities.assert_equals( expect=main.TRUE, actual=secureSshResult,
183 onpass="Test step PASS",
184 onfail="Test step FAIL" )
185
GlennRC5147a422015-10-06 17:26:17 -0700186 time.sleep( main.startUpSleep )
187 main.step( "Starting ONOS service" )
188 stopResult = main.TRUE
189 startResult = main.TRUE
190 onosIsUp = main.TRUE
191
192 for i in range( main.numCtrls ):
193 onosIsUp = onosIsUp and main.ONOSbench.isup( main.ONOSip[ i ] )
194 if onosIsUp == main.TRUE:
195 main.log.report( "ONOS instance is up and ready" )
196 else:
197 main.log.report( "ONOS instance may not be up, stop and " +
198 "start ONOS again " )
199 for i in range( main.numCtrls ):
200 stopResult = stopResult and \
201 main.ONOSbench.onosStop( main.ONOSip[ i ] )
202 for i in range( main.numCtrls ):
203 startResult = startResult and \
204 main.ONOSbench.onosStart( main.ONOSip[ i ] )
205 stepResult = onosIsUp and stopResult and startResult
206 utilities.assert_equals( expect=main.TRUE,
207 actual=stepResult,
208 onpass="ONOS service is ready",
209 onfail="ONOS service did not start properly" )
210
211 main.step( "Start ONOS cli" )
212 cliResult = main.TRUE
213 for i in range( main.numCtrls ):
214 cliResult = cliResult and \
215 main.CLIs[ i ].startOnosCli( main.ONOSip[ i ] )
216 stepResult = cliResult
217 utilities.assert_equals( expect=main.TRUE,
218 actual=stepResult,
219 onpass="Successfully start ONOS cli",
220 onfail="Failed to start ONOS cli" )
221
GlennRC68449942015-10-16 16:03:12 -0700222 def CASE10( self, main ):
223 '''
224 Start Mininet
225 '''
GlennRC073e8bc2015-10-27 17:11:28 -0700226 import json
227
228 main.case( "Setup mininet and compare ONOS topology view to Mininet topology" )
229 main.caseExplanation = "Start mininet with custom topology and compare topology " +\
230 "elements between Mininet and ONOS"
231
GlennRC68449942015-10-16 16:03:12 -0700232 main.step( "Setup Mininet Topology" )
233 topology = main.Mininet1.home + '/custom/' + main.topology
alisone14d7b02016-07-06 10:31:51 -0700234 stepResult = main.Mininet1.startNet( topoFile = topology )
GlennRC68449942015-10-16 16:03:12 -0700235
236 utilities.assert_equals( expect=main.TRUE,
GlennRC073e8bc2015-10-27 17:11:28 -0700237 actual=stepResult,
GlennRC68449942015-10-16 16:03:12 -0700238 onpass="Successfully loaded topology",
239 onfail="Failed to load topology" )
240
GlennRC073e8bc2015-10-27 17:11:28 -0700241 main.step( "Assign switch to controller" )
242 stepResult = main.Mininet1.assignSwController( "s1", main.ONOSip[0] )
GlennRC68449942015-10-16 16:03:12 -0700243
244 utilities.assert_equals( expect=main.TRUE,
GlennRC073e8bc2015-10-27 17:11:28 -0700245 actual=stepResult,
246 onpass="Successfully assigned switch to controller",
247 onfail="Failed to assign switch to controller" )
GlennRC68449942015-10-16 16:03:12 -0700248
GlennRC073e8bc2015-10-27 17:11:28 -0700249 time.sleep( main.startMNSleep )
GlennRC68449942015-10-16 16:03:12 -0700250
Jon Hall70b2ff42015-11-17 15:49:44 -0800251 main.step( "Comparing MN topology to ONOS topology" )
GlennRC073e8bc2015-10-27 17:11:28 -0700252 main.log.info( "Gathering topology information" )
GlennRC1704d072015-10-07 18:40:45 -0700253 devices = main.topo.getAllDevices( main )
254 hosts = main.topo.getAllHosts( main )
255 ports = main.topo.getAllPorts( main )
256 links = main.topo.getAllLinks( main )
GlennRC1704d072015-10-07 18:40:45 -0700257
alisone14d7b02016-07-06 10:31:51 -0700258 mnSwitches = main.Mininet1.getSwitches( )
259 mnLinks = main.Mininet1.getLinks( )
260 mnHosts = main.Mininet1.getHosts( )
GlennRC1704d072015-10-07 18:40:45 -0700261
GlennRC1704d072015-10-07 18:40:45 -0700262 for controller in range( main.numCtrls ):
263 controllerStr = str( controller + 1 )
264 if devices[ controller ] and ports[ controller ] and\
265 "Error" not in devices[ controller ] and\
266 "Error" not in ports[ controller ]:
267
268 currentDevicesResult = main.Mininet1.compareSwitches(
269 mnSwitches,
270 json.loads( devices[ controller ] ),
271 json.loads( ports[ controller ] ) )
272 else:
273 currentDevicesResult = main.FALSE
274 utilities.assert_equals( expect=main.TRUE,
275 actual=currentDevicesResult,
276 onpass="ONOS" + controllerStr +
GlennRC68449942015-10-16 16:03:12 -0700277 " Switches view is correct",
GlennRC1704d072015-10-07 18:40:45 -0700278 onfail="ONOS" + controllerStr +
GlennRC68449942015-10-16 16:03:12 -0700279 " Switches view is incorrect" )
GlennRC1704d072015-10-07 18:40:45 -0700280 if links[ controller ] and "Error" not in links[ controller ]:
281 currentLinksResult = main.Mininet1.compareLinks(
282 mnSwitches, mnLinks,
283 json.loads( links[ controller ] ) )
284 else:
285 currentLinksResult = main.FALSE
286 utilities.assert_equals( expect=main.TRUE,
287 actual=currentLinksResult,
288 onpass="ONOS" + controllerStr +
GlennRC68449942015-10-16 16:03:12 -0700289 " links view is correct",
GlennRC1704d072015-10-07 18:40:45 -0700290 onfail="ONOS" + controllerStr +
GlennRC68449942015-10-16 16:03:12 -0700291 " links view is incorrect" )
GlennRC1704d072015-10-07 18:40:45 -0700292
293 if hosts[ controller ] or "Error" not in hosts[ controller ]:
294 currentHostsResult = main.Mininet1.compareHosts(
295 mnHosts,
296 json.loads( hosts[ controller ] ) )
297 else:
298 currentHostsResult = main.FALSE
299 utilities.assert_equals( expect=main.TRUE,
300 actual=currentHostsResult,
301 onpass="ONOS" + controllerStr +
GlennRC68449942015-10-16 16:03:12 -0700302 " hosts exist in Mininet",
GlennRC1704d072015-10-07 18:40:45 -0700303 onfail="ONOS" + controllerStr +
GlennRC68449942015-10-16 16:03:12 -0700304 " hosts don't match Mininet")
GlennRCa5391372015-10-14 17:28:15 -0700305
GlennRC68449942015-10-16 16:03:12 -0700306
Jon Hall892818c2015-10-20 17:58:34 -0700307 def CASE66( self, main ):
308 '''
309 Testing scapy
310 '''
311 main.case( "Testing scapy" )
312 main.step( "Creating Host1 component" )
Jon Halla510a8a2016-05-04 15:09:28 -0700313 main.Scapy.createHostComponent( "h1" )
314 main.Scapy.createHostComponent( "h2" )
alisone14d7b02016-07-06 10:31:51 -0700315 hosts = [ main.h1, main.h2 ]
Jon Hall892818c2015-10-20 17:58:34 -0700316 for host in hosts:
alisone14d7b02016-07-06 10:31:51 -0700317 host.startHostCli( )
318 host.startScapy( )
319 host.updateSelf( )
Jon Hall892818c2015-10-20 17:58:34 -0700320 main.log.debug( host.name )
321 main.log.debug( host.hostIp )
322 main.log.debug( host.hostMac )
323
324 main.step( "Sending/Receiving Test packet - Filter doesn't match" )
Jon Halla510a8a2016-05-04 15:09:28 -0700325 main.log.info( "Starting Filter..." )
alisone14d7b02016-07-06 10:31:51 -0700326 main.h2.startFilter( )
Jon Halla510a8a2016-05-04 15:09:28 -0700327 main.log.info( "Building Ether frame..." )
Jon Hall892818c2015-10-20 17:58:34 -0700328 main.h1.buildEther( dst=main.h2.hostMac )
Jon Halla510a8a2016-05-04 15:09:28 -0700329 main.log.info( "Sending Packet..." )
Jon Hall892818c2015-10-20 17:58:34 -0700330 main.h1.sendPacket( )
Jon Halla510a8a2016-05-04 15:09:28 -0700331 main.log.info( "Checking Filter..." )
alisone14d7b02016-07-06 10:31:51 -0700332 finished = main.h2.checkFilter( )
Jon Halla510a8a2016-05-04 15:09:28 -0700333 main.log.debug( finished )
Jon Hall892818c2015-10-20 17:58:34 -0700334 i = ""
335 if finished:
alisone14d7b02016-07-06 10:31:51 -0700336 a = main.h2.readPackets( )
337 for i in a.splitlines( ):
Jon Hall892818c2015-10-20 17:58:34 -0700338 main.log.info( i )
339 else:
alisone14d7b02016-07-06 10:31:51 -0700340 kill = main.h2.killFilter( )
Jon Hall892818c2015-10-20 17:58:34 -0700341 main.log.debug( kill )
342 main.h2.handle.sendline( "" )
343 main.h2.handle.expect( main.h2.scapyPrompt )
344 main.log.debug( main.h2.handle.before )
345 utilities.assert_equals( expect=True,
346 actual="dst=00:00:00:00:00:02 src=00:00:00:00:00:01" in i,
347 onpass="Pass",
348 onfail="Fail" )
349
350 main.step( "Sending/Receiving Test packet - Filter matches" )
alisone14d7b02016-07-06 10:31:51 -0700351 main.h2.startFilter( )
Jon Hall892818c2015-10-20 17:58:34 -0700352 main.h1.buildEther( dst=main.h2.hostMac )
353 main.h1.buildIP( dst=main.h2.hostIp )
354 main.h1.sendPacket( )
alisone14d7b02016-07-06 10:31:51 -0700355 finished = main.h2.checkFilter( )
Jon Hall892818c2015-10-20 17:58:34 -0700356 i = ""
357 if finished:
alisone14d7b02016-07-06 10:31:51 -0700358 a = main.h2.readPackets( )
359 for i in a.splitlines( ):
Jon Hall892818c2015-10-20 17:58:34 -0700360 main.log.info( i )
361 else:
alisone14d7b02016-07-06 10:31:51 -0700362 kill = main.h2.killFilter( )
Jon Hall892818c2015-10-20 17:58:34 -0700363 main.log.debug( kill )
364 main.h2.handle.sendline( "" )
365 main.h2.handle.expect( main.h2.scapyPrompt )
366 main.log.debug( main.h2.handle.before )
367 utilities.assert_equals( expect=True,
368 actual="dst=00:00:00:00:00:02 src=00:00:00:00:00:01" in i,
369 onpass="Pass",
370 onfail="Fail" )
371
372
373
374 main.step( "Clean up host components" )
375 for host in hosts:
alisone14d7b02016-07-06 10:31:51 -0700376 host.stopScapy( )
377 main.Mininet1.removeHostComponent( "h1" )
378 main.Mininet1.removeHostComponent( "h2" )
Jon Hall892818c2015-10-20 17:58:34 -0700379
GlennRC68449942015-10-16 16:03:12 -0700380 def CASE1000( self, main ):
381 '''
GlennRC073e8bc2015-10-27 17:11:28 -0700382 Add flows with MAC selectors and verify the flows
GlennRC68449942015-10-16 16:03:12 -0700383 '''
GlennRC073e8bc2015-10-27 17:11:28 -0700384 import json
385 import time
GlennRC68449942015-10-16 16:03:12 -0700386
GlennRC073e8bc2015-10-27 17:11:28 -0700387 main.case( "Verify flow MAC selectors are correctly compiled" )
388 main.caseExplanation = "Install two flows with only MAC selectors " +\
389 "specified, then verify flows are added in ONOS, finally "+\
390 "send a packet that only specifies the MAC src and dst."
GlennRC68449942015-10-16 16:03:12 -0700391
GlennRC073e8bc2015-10-27 17:11:28 -0700392 main.step( "Add flows with MAC addresses as the only selectors" )
GlennRC68449942015-10-16 16:03:12 -0700393
GlennRC073e8bc2015-10-27 17:11:28 -0700394 main.log.info( "Creating host components" )
Jon Halla510a8a2016-05-04 15:09:28 -0700395 main.Scapy.createHostComponent( "h1" )
396 main.Scapy.createHostComponent( "h2" )
alisone14d7b02016-07-06 10:31:51 -0700397 hosts = [ main.h1, main.h2 ]
GlennRC073e8bc2015-10-27 17:11:28 -0700398 for host in hosts:
alisone14d7b02016-07-06 10:31:51 -0700399 host.startHostCli( )
400 host.startScapy( )
401 host.updateSelf( )
GlennRC68449942015-10-16 16:03:12 -0700402
GlennRC073e8bc2015-10-27 17:11:28 -0700403 # Add a flow that connects host1 on port1 to host2 on port2
404 # send output on port2
405 # recieve input on port1
406 egress = 2
407 ingress = 1
408
409 # Add flows that sends packets from port1 to port2 with correct
410 # MAC src and dst addresses
411 main.log.info( "Adding flow with MAC selectors" )
412 stepResult = main.ONOSrest.addFlow( deviceId=main.swDPID,
413 egressPort=egress,
414 ingressPort=ingress,
415 ethSrc=main.h1.hostMac,
416 ethDst=main.h2.hostMac,
GlennRC956ea742015-11-05 16:14:15 -0800417 debug=main.debug )
GlennRC68449942015-10-16 16:03:12 -0700418
GlennRCa5391372015-10-14 17:28:15 -0700419 utilities.assert_equals( expect=main.TRUE,
420 actual=stepResult,
GlennRC68449942015-10-16 16:03:12 -0700421 onpass="Successfully added flows",
422 onfail="Failed add flows" )
GlennRCa5391372015-10-14 17:28:15 -0700423
GlennRC073e8bc2015-10-27 17:11:28 -0700424 # Giving ONOS time to add the flows
425 time.sleep( main.addFlowSleep )
GlennRC5147a422015-10-06 17:26:17 -0700426
GlennRC073e8bc2015-10-27 17:11:28 -0700427 main.step( "Check flows are in the ADDED state" )
428
GlennRC073e8bc2015-10-27 17:11:28 -0700429 main.log.info( "Get the flows from ONOS" )
Jeremy86160992016-04-11 10:05:53 -0700430 try:
alisone14d7b02016-07-06 10:31:51 -0700431 flows = json.loads( main.ONOSrest.flows( ) )
GlennRC68449942015-10-16 16:03:12 -0700432
Jeremy86160992016-04-11 10:05:53 -0700433 stepResult = main.TRUE
434 for f in flows:
alisone14d7b02016-07-06 10:31:51 -0700435 if "rest" in f.get( "appId" ):
436 if "ADDED" not in f.get( "state" ):
Jeremy86160992016-04-11 10:05:53 -0700437 stepResult = main.FALSE
alisone14d7b02016-07-06 10:31:51 -0700438 main.log.error( "Flow: %s in state: %s" % ( f.get( "id" ), f.get( "state" ) ) )
Jeremy86160992016-04-11 10:05:53 -0700439 except TypeError:
440 main.log.error( "No Flows found by the REST API" )
441 stepResult = main.FALSE
442 except ValueError:
443 main.log.error( "Problem getting Flows state from REST API. Exiting test" )
alisone14d7b02016-07-06 10:31:51 -0700444 main.cleanup( )
445 main.exit( )
GlennRC68449942015-10-16 16:03:12 -0700446
447 utilities.assert_equals( expect=main.TRUE,
448 actual=stepResult,
449 onpass="All flows are in the ADDED state",
GlennRC073e8bc2015-10-27 17:11:28 -0700450 onfail="All flows are NOT in the ADDED state" )
GlennRC68449942015-10-16 16:03:12 -0700451
GlennRC956ea742015-11-05 16:14:15 -0800452 main.step( "Check flows are in Mininet's flow table" )
453
454 # get the flow IDs that were added through rest
455 main.log.info( "Getting the flow IDs from ONOS" )
alisone14d7b02016-07-06 10:31:51 -0700456 flowIds = [ f.get( "id" ) for f in flows if "rest" in f.get( "appId" ) ]
GlennRC956ea742015-11-05 16:14:15 -0800457 # convert the flowIDs to ints then hex and finally back to strings
alisone14d7b02016-07-06 10:31:51 -0700458 flowIds = [ str( hex( int( x ) ) ) for x in flowIds ]
459 main.log.info( "ONOS flow IDs: {}".format( flowIds ) )
GlennRC956ea742015-11-05 16:14:15 -0800460
461 stepResult = main.Mininet1.checkFlowId( "s1", flowIds, debug=False )
462
463 utilities.assert_equals( expect=main.TRUE,
464 actual=stepResult,
465 onpass="All flows are in mininet",
466 onfail="All flows are NOT in mininet" )
467
GlennRC073e8bc2015-10-27 17:11:28 -0700468 main.step( "Send a packet to verify the flows are correct" )
469
470 # Specify the src and dst MAC addr
471 main.log.info( "Constructing packet" )
472 main.h1.buildEther( src=main.h1.hostMac, dst=main.h2.hostMac )
473
474 # Filter for packets with the correct host name. Otherwise,
475 # the filter we catch any packet that is sent to host2
476 # NOTE: I believe it doesn't matter which host name it is,
GlennRC956ea742015-11-05 16:14:15 -0800477 # as long as the src and dst are both specified
GlennRC073e8bc2015-10-27 17:11:28 -0700478 main.log.info( "Starting filter on host2" )
alisone14d7b02016-07-06 10:31:51 -0700479 main.h2.startFilter( pktFilter="ether host %s" % main.h1.hostMac )
GlennRC073e8bc2015-10-27 17:11:28 -0700480
481 main.log.info( "Sending packet to host2" )
482 main.h1.sendPacket()
483
484 main.log.info( "Checking filter for our packet" )
alisone14d7b02016-07-06 10:31:51 -0700485 stepResult = main.h2.checkFilter( )
GlennRC073e8bc2015-10-27 17:11:28 -0700486 if stepResult:
alisone14d7b02016-07-06 10:31:51 -0700487 main.log.info( "Packet: %s" % main.h2.readPackets( ) )
488 else:
489 main.h2.killFilter( )
GlennRC073e8bc2015-10-27 17:11:28 -0700490
491 main.log.info( "Clean up host components" )
492 for host in hosts:
alisone14d7b02016-07-06 10:31:51 -0700493 host.stopScapy( )
494 main.Mininet1.removeHostComponent( "h1" )
495 main.Mininet1.removeHostComponent( "h2" )
GlennRC073e8bc2015-10-27 17:11:28 -0700496
497 utilities.assert_equals( expect=main.TRUE,
498 actual=stepResult,
499 onpass="Successfully sent a packet",
500 onfail="Failed to send a packet" )
501
alisone14d7b02016-07-06 10:31:51 -0700502 def CASE1400( self, main ):
GlennRC68449942015-10-16 16:03:12 -0700503 '''
GlennRC073e8bc2015-10-27 17:11:28 -0700504 Add flows with IPv4 selectors and verify the flows
GlennRC68449942015-10-16 16:03:12 -0700505 '''
506 import json
GlennRC073e8bc2015-10-27 17:11:28 -0700507 import time
GlennRC68449942015-10-16 16:03:12 -0700508
GlennRC073e8bc2015-10-27 17:11:28 -0700509 main.case( "Verify flow IP selectors are correctly compiled" )
510 main.caseExplanation = "Install two flows with only IP selectors " +\
alisone14d7b02016-07-06 10:31:51 -0700511 "specified, then verify flows are added in ONOS, finally " +\
GlennRC073e8bc2015-10-27 17:11:28 -0700512 "send a packet that only specifies the IP src and dst."
513
514 main.step( "Add flows with IPv4 addresses as the only selectors" )
515
516 main.log.info( "Creating host components" )
Jon Halla510a8a2016-05-04 15:09:28 -0700517 main.Scapy.createHostComponent( "h1" )
518 main.Scapy.createHostComponent( "h2" )
alisone14d7b02016-07-06 10:31:51 -0700519 hosts = [ main.h1, main.h2 ]
GlennRC073e8bc2015-10-27 17:11:28 -0700520 for host in hosts:
alisone14d7b02016-07-06 10:31:51 -0700521 host.startHostCli( )
522 host.startScapy( )
523 host.updateSelf( )
GlennRC073e8bc2015-10-27 17:11:28 -0700524
525 # Add a flow that connects host1 on port1 to host2 on port2
526 # send output on port2
527 # recieve input on port1
528 egress = 2
529 ingress = 1
530 # IPv4 etherType = 0x800
alisone14d7b02016-07-06 10:31:51 -0700531 ethType = main.params[ 'TEST' ][ 'ip4Type' ]
GlennRC073e8bc2015-10-27 17:11:28 -0700532
533 # Add flows that connects host1 to host2
534 main.log.info( "Add flow with port ingress 1 to port egress 2" )
535 stepResult = main.ONOSrest.addFlow( deviceId=main.swDPID,
536 egressPort=egress,
537 ingressPort=ingress,
alisone14d7b02016-07-06 10:31:51 -0700538 ethType=ethType,
539 ipSrc=( "IPV4_SRC", main.h1.hostIp+"/32" ),
540 ipDst=( "IPV4_DST", main.h2.hostIp+"/32" ),
GlennRC956ea742015-11-05 16:14:15 -0800541 debug=main.debug )
GlennRC073e8bc2015-10-27 17:11:28 -0700542
543 utilities.assert_equals( expect=main.TRUE,
544 actual=stepResult,
545 onpass="Successfully added flows",
546 onfail="Failed add flows" )
547
548 # Giving ONOS time to add the flow
549 time.sleep( main.addFlowSleep )
550
551 main.step( "Check flow is in the ADDED state" )
552
553 main.log.info( "Get the flows from ONOS" )
Jeremy86160992016-04-11 10:05:53 -0700554 try:
alisone14d7b02016-07-06 10:31:51 -0700555 flows = json.loads( main.ONOSrest.flows( ) )
GlennRC68449942015-10-16 16:03:12 -0700556
Jeremy86160992016-04-11 10:05:53 -0700557 stepResult = main.TRUE
558 for f in flows:
alisone14d7b02016-07-06 10:31:51 -0700559 if "rest" in f.get( "appId" ):
560 if "ADDED" not in f.get( "state" ):
Jeremy86160992016-04-11 10:05:53 -0700561 stepResult = main.FALSE
alisone14d7b02016-07-06 10:31:51 -0700562 main.log.error( "Flow: %s in state: %s" % ( f.get( "id" ), f.get( "state" ) ) )
Jeremy86160992016-04-11 10:05:53 -0700563 except TypeError:
564 main.log.error( "No Flows found by the REST API" )
565 stepResult = main.FALSE
566 except ValueError:
567 main.log.error( "Problem getting Flows state from REST API. Exiting test" )
alisone14d7b02016-07-06 10:31:51 -0700568 main.cleanup( )
569 main.exit( )
GlennRC68449942015-10-16 16:03:12 -0700570
571 utilities.assert_equals( expect=main.TRUE,
572 actual=stepResult,
GlennRC073e8bc2015-10-27 17:11:28 -0700573 onpass="All flows are in the ADDED state",
574 onfail="All flows are NOT in the ADDED state" )
575
GlennRC956ea742015-11-05 16:14:15 -0800576 main.step( "Check flows are in Mininet's flow table" )
577
578 # get the flow IDs that were added through rest
579 main.log.info( "Getting the flow IDs from ONOS" )
alisone14d7b02016-07-06 10:31:51 -0700580 flowIds = [ f.get( "id" ) for f in flows if "rest" in f.get( "appId" ) ]
GlennRC956ea742015-11-05 16:14:15 -0800581 # convert the flowIDs to ints then hex and finally back to strings
alisone14d7b02016-07-06 10:31:51 -0700582 flowIds = [ str( hex( int( x ) ) ) for x in flowIds ]
583 main.log.info( "ONOS flow IDs: {}".format( flowIds ) )
GlennRC956ea742015-11-05 16:14:15 -0800584
585 stepResult = main.Mininet1.checkFlowId( "s1", flowIds, debug=False )
586
587 utilities.assert_equals( expect=main.TRUE,
588 actual=stepResult,
589 onpass="All flows are in mininet",
590 onfail="All flows are NOT in mininet" )
591
GlennRC073e8bc2015-10-27 17:11:28 -0700592 main.step( "Send a packet to verify the flow is correct" )
593
594 main.log.info( "Constructing packet" )
595 # No need for the MAC src dst
596 main.h1.buildEther( dst=main.h2.hostMac )
597 main.h1.buildIP( src=main.h1.hostIp, dst=main.h2.hostIp )
598
599 main.log.info( "Starting filter on host2" )
600 # Defaults to ip
alisone14d7b02016-07-06 10:31:51 -0700601 main.h2.startFilter( )
GlennRC073e8bc2015-10-27 17:11:28 -0700602
603 main.log.info( "Sending packet to host2" )
alisone14d7b02016-07-06 10:31:51 -0700604 main.h1.sendPacket( )
GlennRC073e8bc2015-10-27 17:11:28 -0700605
606 main.log.info( "Checking filter for our packet" )
alisone14d7b02016-07-06 10:31:51 -0700607 stepResult = main.h2.checkFilter( )
GlennRC073e8bc2015-10-27 17:11:28 -0700608 if stepResult:
alisone14d7b02016-07-06 10:31:51 -0700609 main.log.info( "Packet: %s" % main.h2.readPackets( ) )
610 else: main.h2.killFilter( )
GlennRC073e8bc2015-10-27 17:11:28 -0700611
612 main.log.info( "Clean up host components" )
613 for host in hosts:
alisone14d7b02016-07-06 10:31:51 -0700614 host.stopScapy( )
615 main.Mininet1.removeHostComponent( "h1" )
616 main.Mininet1.removeHostComponent( "h2" )
GlennRC073e8bc2015-10-27 17:11:28 -0700617
618 utilities.assert_equals( expect=main.TRUE,
619 actual=stepResult,
620 onpass="Successfully sent a packet",
621 onfail="Failed to send a packet" )
622
alisone14d7b02016-07-06 10:31:51 -0700623 def CASE1500 (self, main ):
624 """
625 Add flow with IPv6 selector and verify the flow
626 """
627 import json
628 import time
629 main.case( "Verify IPv6 selector is correctly compiled" )
630 main.caseExplanation = "Install two flows with only IP selectors " + \
631 "specified, then verify flows are added in ONOS, finally " + \
632 "send a packet that only specifies the IP src and dst."
633
634 main.step( "Add flows with IPv6 addresses as the only selectors" )
635
636 main.log.info( "Creating host components" )
637 main.Scapy.createHostComponent( "h5" )
638 main.Scapy.createHostComponent( "h6" )
639 hosts = [ main.h5, main.h6 ]
640
641 for host in hosts:
642 host.startHostCli( )
643 host.startScapy( )
644 host.updateSelf( IPv6=True )
645
646 # Add a flow that connects host1 on port1 to host2 on port2
647 # send output on port2
648 # recieve input on port1
649 egress = 6
650 ingress = 5
651 # IPv6 etherType = 0x86DD
652 ethType = main.params[ 'TEST' ][ 'ip6Type' ]
653
654 # Add flows that connects host1 to host2
655 main.log.info( "Add flow with port ingress 5 to port egress 6" )
656 stepResult = main.ONOSrest.addFlow( deviceId=main.swDPID,
657 egressPort=egress,
658 ingressPort=ingress,
659 ethType=ethType,
660 ipSrc=( "IPV6_SRC", main.h5.hostIp + "/128" ),
661 ipDst=( "IPV6_DST", main.h6.hostIp + "/128" ),
662 debug=main.debug )
663
664 utilities.assert_equals( expect=main.TRUE,
665 actual=stepResult,
666 onpass="Successfully added flows",
667 onfail="Failed add flows" )
668
669 # Giving ONOS time to add the flow
670 time.sleep( main.addFlowSleep )
671
672 main.step( "Check flow is in the ADDED state" )
673
674 main.log.info( "Get the flows from ONOS" )
675 try:
676 flows = json.loads( main.ONOSrest.flows( ) )
677
678 stepResult = main.TRUE
679 for f in flows:
680 if "rest" in f.get( "appId" ):
681 if "ADDED" not in f.get( "state" ):
682 stepResult = main.FALSE
683 main.log.error( "Flow: %s in state: %s" % ( f.get( "id" ), f.get( "state" ) ) )
684 except TypeError:
685 main.log.error( "No Flows found by the REST API" )
686 stepResult = main.FALSE
687 except ValueError:
688 main.log.error( "Problem getting Flows state from REST API. Exiting test" )
689 main.cleanup( )
690 main.exit( )
691
692 utilities.assert_equals( expect=main.TRUE,
693 actual=stepResult,
694 onpass="All flows are in the ADDED state",
695 onfail="All flows are NOT in the ADDED state" )
696
697 main.step( "Check flows are in Mininet's flow table" )
698
699 # get the flow IDs that were added through rest
700 main.log.info( "Getting the flow IDs from ONOS" )
701 flowIds = [ f.get( "id" ) for f in flows if "rest" in f.get( "appId" ) ]
702 # convert the flowIDs to ints then hex and finally back to strings
703 flowIds = [ str( hex( int( x ) ) ) for x in flowIds ]
704 main.log.info( "ONOS flow IDs: {}".format( flowIds ) )
705
706 stepResult = main.Mininet1.checkFlowId( "s1", flowIds, debug=False )
707
708 utilities.assert_equals( expect=main.TRUE,
709 actual=stepResult,
710 onpass="All flows are in mininet",
711 onfail="All flows are NOT in mininet" )
712
713 main.step( "Send a packet to verify the flow is correct" )
714
715 main.log.info( "Constructing packet" )
716 # No need for the MAC src dst
717 main.h5.buildEther( dst=main.h6.hostMac )
718 main.h5.buildIPv6( src=main.h5.hostIp, dst=main.h6.hostIp )
719
720 main.log.info( "Starting filter on host6" )
721 # Defaults to ip
722 main.h6.startFilter( pktFilter="ip6" )
723 main.log.info( "Sending packet to host6" )
724 main.h5.sendPacket( )
725
726 main.log.info( "Checking filter for our packet" )
727 stepResult = main.h6.checkFilter( )
728 if stepResult:
729 main.log.info( "Packet: %s" % main.h6.readPackets( ) )
730 else:
731 main.h6.killFilter( )
732
733 main.log.info( "Clean up host components" )
734 for host in hosts:
735 host.stopScapy( )
736 main.Mininet1.removeHostComponent( "h5" )
737 main.Mininet1.removeHostComponent( "h6" )
738
739 utilities.assert_equals( expect=main.TRUE,
740 actual=stepResult,
741 onpass="Successfully sent a packet",
742 onfail="Failed to send a packet" )
743
744
745 def CASE1100( self, main ):
GlennRC073e8bc2015-10-27 17:11:28 -0700746 '''
747 Add flow with VLAN selector and verify the flow
748 '''
749 import json
750 import time
751
752 main.case( "Verify VLAN selector is correctly compiled" )
753 main.caseExplanation = "Install one flow with only the VLAN selector " +\
754 "specified, then verify the flow is added in ONOS, and finally "+\
755 "broadcast a packet with the correct VLAN tag."
756
757 # We do this here to utilize the hosts information
758 main.log.info( "Creating host components" )
Jon Halla510a8a2016-05-04 15:09:28 -0700759 main.Scapy.createHostComponent( "h3" )
760 main.Scapy.createHostComponent( "h4" )
alisone14d7b02016-07-06 10:31:51 -0700761 hosts = [ main.h3, main.h4 ]
GlennRC073e8bc2015-10-27 17:11:28 -0700762 for host in hosts:
alisone14d7b02016-07-06 10:31:51 -0700763 host.startHostCli( )
764 host.startScapy( )
765 host.updateSelf( )
GlennRC073e8bc2015-10-27 17:11:28 -0700766
767
768 main.step( "Add a flow with the VLAN tag as the only selector" )
769
770 # Add flows that connects the two vlan hosts h3 and h4
771 # Host 3 is on port 3 and host 4 is on port 4
772 vlan = main.params[ 'TEST' ][ 'vlan' ]
773 egress = 4
774 ingress = 3
775 # VLAN ethType = 0x8100
alisone14d7b02016-07-06 10:31:51 -0700776 ethType = main.params[ 'TEST' ][ 'vlanType' ]
GlennRC073e8bc2015-10-27 17:11:28 -0700777
778 # Add only one flow because we don't need a response
779 main.log.info( "Add flow with port ingress 1 to port egress 2" )
780 stepResult = main.ONOSrest.addFlow( deviceId=main.swDPID,
781 egressPort=egress,
782 ingressPort=ingress,
783 ethType=ethType,
784 vlan=vlan,
GlennRC956ea742015-11-05 16:14:15 -0800785 debug=main.debug )
GlennRC073e8bc2015-10-27 17:11:28 -0700786
787
788 utilities.assert_equals( expect=main.TRUE,
789 actual=stepResult,
790 onpass="Successfully added flow",
791 onfail="Failed add flows" )
792
793 # Giving ONOS time to add the flows
794 time.sleep( main.addFlowSleep )
795
796 main.step( "Check flows are in the ADDED state" )
797
798 main.log.info( "Get the flows from ONOS" )
Jeremy86160992016-04-11 10:05:53 -0700799 try:
alisone14d7b02016-07-06 10:31:51 -0700800 flows = json.loads( main.ONOSrest.flows( ) )
GlennRC073e8bc2015-10-27 17:11:28 -0700801
Jeremy86160992016-04-11 10:05:53 -0700802 stepResult = main.TRUE
803 for f in flows:
alisone14d7b02016-07-06 10:31:51 -0700804 if "rest" in f.get( "appId" ):
805 if "ADDED" not in f.get( "state" ):
Jeremy86160992016-04-11 10:05:53 -0700806 stepResult = main.FALSE
alisone14d7b02016-07-06 10:31:51 -0700807 main.log.error( "Flow: %s in state: %s" % ( f.get( "id" ), f.get( "state" ) ) )
Jeremy86160992016-04-11 10:05:53 -0700808 except TypeError:
809 main.log.error( "No Flows found by the REST API" )
810 stepResult = main.FALSE
811 except ValueError:
812 main.log.error( "Problem getting Flows state from REST API. Exiting test" )
alisone14d7b02016-07-06 10:31:51 -0700813 main.cleanup( )
814 main.exit( )
GlennRC073e8bc2015-10-27 17:11:28 -0700815
816 utilities.assert_equals( expect=main.TRUE,
817 actual=stepResult,
818 onpass="All flows are in the ADDED state",
819 onfail="All flows are NOT in the ADDED state" )
820
GlennRC956ea742015-11-05 16:14:15 -0800821 main.step( "Check flows are in Mininet's flow table" )
822
823 # get the flow IDs that were added through rest
824 main.log.info( "Getting the flow IDs from ONOS" )
alisone14d7b02016-07-06 10:31:51 -0700825 flowIds = [ f.get( "id" ) for f in flows if "rest" in f.get( "appId" ) ]
GlennRC956ea742015-11-05 16:14:15 -0800826 # convert the flowIDs to ints then hex and finally back to strings
alisone14d7b02016-07-06 10:31:51 -0700827 flowIds = [ str( hex( int( x ) ) ) for x in flowIds ]
828 main.log.info( "ONOS flow IDs: {}".format( flowIds ) )
GlennRC956ea742015-11-05 16:14:15 -0800829
830 stepResult = main.Mininet1.checkFlowId( "s1", flowIds, debug=False )
831
832 utilities.assert_equals( expect=main.TRUE,
833 actual=stepResult,
834 onpass="All flows are in mininet",
835 onfail="All flows are NOT in mininet" )
836
GlennRC073e8bc2015-10-27 17:11:28 -0700837 main.step( "Send a packet to verify the flow are correct" )
838
839 # The receiving interface
alisone14d7b02016-07-06 10:31:51 -0700840 recIface = "{}-eth0.{}".format( main.h4.name, vlan )
GlennRC073e8bc2015-10-27 17:11:28 -0700841 main.log.info( "Starting filter on host2" )
842 # Filter is setup to catch any packet on the vlan interface with the correct vlan tag
alisone14d7b02016-07-06 10:31:51 -0700843 main.h4.startFilter( ifaceName=recIface, pktFilter = "" )
GlennRC073e8bc2015-10-27 17:11:28 -0700844
845 # Broadcast the packet on the vlan interface. We only care if the flow forwards
846 # the packet with the correct vlan tag, not if the mac addr is correct
alisone14d7b02016-07-06 10:31:51 -0700847 sendIface = "{}-eth0.{}".format( main.h3.name, vlan )
GlennRC073e8bc2015-10-27 17:11:28 -0700848 main.log.info( "Broadcasting the packet with a vlan tag" )
GlennRC956ea742015-11-05 16:14:15 -0800849 main.h3.sendPacket( iface=sendIface,
alisone14d7b02016-07-06 10:31:51 -0700850 packet="Ether()/Dot1Q(vlan={})".format( vlan ) )
GlennRC073e8bc2015-10-27 17:11:28 -0700851
852 main.log.info( "Checking filter for our packet" )
alisone14d7b02016-07-06 10:31:51 -0700853 stepResult = main.h4.checkFilter( )
GlennRC073e8bc2015-10-27 17:11:28 -0700854 if stepResult:
alisone14d7b02016-07-06 10:31:51 -0700855 main.log.info( "Packet: %s" % main.h4.readPackets( ) )
856 else: main.h4.killFilter( )
GlennRC073e8bc2015-10-27 17:11:28 -0700857
858 main.log.info( "Clean up host components" )
859 for host in hosts:
alisone14d7b02016-07-06 10:31:51 -0700860 host.stopScapy( )
861 main.Mininet1.removeHostComponent( "h3" )
862 main.Mininet1.removeHostComponent( "h4" )
GlennRC073e8bc2015-10-27 17:11:28 -0700863
864 utilities.assert_equals( expect=main.TRUE,
865 actual=stepResult,
866 onpass="Successfully sent a packet",
867 onfail="Failed to send a packet" )
GlennRC68449942015-10-16 16:03:12 -0700868
GlennRC956ea742015-11-05 16:14:15 -0800869 def CASE1300( self, main ):
870 '''
871 Add flows with MPLS selector and verify the flows
872 '''
873 import json
874 import time
875
876 main.case( "Verify the MPLS selector is correctly compiled on the flow." )
877 main.caseExplanation = "Install one flow with an MPLS selector, " +\
alisone14d7b02016-07-06 10:31:51 -0700878 "verify the flow is added in ONOS, and finally " +\
GlennRC956ea742015-11-05 16:14:15 -0800879 "send a packet via scapy that has a MPLS label."
880
881 main.step( "Add a flow with a MPLS selector" )
882
883 main.log.info( "Creating host components" )
Jon Halla510a8a2016-05-04 15:09:28 -0700884 main.Scapy.createHostComponent( "h1" )
885 main.Scapy.createHostComponent( "h2" )
alisone14d7b02016-07-06 10:31:51 -0700886 hosts = [ main.h1, main.h2 ]
GlennRC956ea742015-11-05 16:14:15 -0800887 for host in hosts:
alisone14d7b02016-07-06 10:31:51 -0700888 host.startHostCli( )
GlennRC956ea742015-11-05 16:14:15 -0800889 host.startScapy( main.dependencyPath )
alisone14d7b02016-07-06 10:31:51 -0700890 host.updateSelf( )
GlennRC956ea742015-11-05 16:14:15 -0800891
892 # ports
893 egress = 2
894 ingress = 1
895 # MPLS etherType
896 ethType = main.params[ 'TEST' ][ 'mplsType' ]
897 # MPLS label
898 mplsLabel = main.params[ 'TEST' ][ 'mpls' ]
899
900 # Add a flow that connects host1 on port1 to host2 on port2
901 main.log.info( "Adding flow with MPLS selector" )
902 stepResult = main.ONOSrest.addFlow( deviceId=main.swDPID,
903 egressPort=egress,
904 ingressPort=ingress,
905 ethType=ethType,
906 mpls=mplsLabel,
907 debug=main.debug )
908
909 utilities.assert_equals( expect=main.TRUE,
910 actual=stepResult,
911 onpass="Successfully added flow",
912 onfail="Failed add flow" )
913
914 # Giving ONOS time to add the flow
915 time.sleep( main.addFlowSleep )
916
917 main.step( "Check flow is in the ADDED state" )
918
919 main.log.info( "Get the flows from ONOS" )
Jeremy86160992016-04-11 10:05:53 -0700920 try:
alisone14d7b02016-07-06 10:31:51 -0700921 flows = json.loads( main.ONOSrest.flows( ) )
GlennRC956ea742015-11-05 16:14:15 -0800922
Jeremy86160992016-04-11 10:05:53 -0700923 stepResult = main.TRUE
924 for f in flows:
alisone14d7b02016-07-06 10:31:51 -0700925 if "rest" in f.get( "appId" ):
926 if "ADDED" not in f.get( "state" ):
Jeremy86160992016-04-11 10:05:53 -0700927 stepResult = main.FALSE
alisone14d7b02016-07-06 10:31:51 -0700928 main.log.error( "Flow: %s in state: %s" % ( f.get( "id" ), f.get( "state" ) ) )
Jeremy86160992016-04-11 10:05:53 -0700929 except TypeError:
930 main.log.error( "No Flows found by the REST API" )
931 stepResult = main.FALSE
932 except ValueError:
933 main.log.error( "Problem getting Flows state from REST API. Exiting test" )
alisone14d7b02016-07-06 10:31:51 -0700934 main.cleanup( )
935 main.exit( )
GlennRC956ea742015-11-05 16:14:15 -0800936
937 utilities.assert_equals( expect=main.TRUE,
938 actual=stepResult,
939 onpass="All flows are in the ADDED state",
940 onfail="All flows are NOT in the ADDED state" )
941
942 main.step( "Check flows are in Mininet's flow table" )
943
944 # get the flow IDs that were added through rest
945 main.log.info( "Getting the flow IDs from ONOS" )
alisone14d7b02016-07-06 10:31:51 -0700946 flowIds = [ f.get( "id" ) for f in flows if "rest" in f.get( "appId" ) ]
GlennRC956ea742015-11-05 16:14:15 -0800947 # convert the flowIDs to ints then hex and finally back to strings
alisone14d7b02016-07-06 10:31:51 -0700948 flowIds = [ str( hex( int( x ) ) ) for x in flowIds ]
949 main.log.info( "ONOS flow IDs: {}".format( flowIds ) )
GlennRC956ea742015-11-05 16:14:15 -0800950
951 stepResult = main.Mininet1.checkFlowId( "s1", flowIds, debug=True )
952
953 utilities.assert_equals( expect=main.TRUE,
954 actual=stepResult,
955 onpass="All flows are in mininet",
956 onfail="All flows are NOT in mininet" )
957
958 main.step( "Send a packet to verify the flow is correct" )
959
960 main.log.info( "Starting filter on host2" )
961 main.h2.startFilter( pktFilter="mpls" )
962
963 main.log.info( "Constructing packet" )
964 main.log.info( "Sending packet to host2" )
alisone14d7b02016-07-06 10:31:51 -0700965 main.h1.sendPacket( packet='Ether()/MPLS(label={})'.format( mplsLabel ) )
GlennRC956ea742015-11-05 16:14:15 -0800966
967 main.log.info( "Checking filter for our packet" )
alisone14d7b02016-07-06 10:31:51 -0700968 stepResult = main.h2.checkFilter( )
GlennRC956ea742015-11-05 16:14:15 -0800969 if stepResult:
alisone14d7b02016-07-06 10:31:51 -0700970 main.log.info( "Packet: %s" % main.h2.readPackets( ) )
971 else: main.h2.killFilter( )
GlennRC956ea742015-11-05 16:14:15 -0800972
973 main.log.info( "Clean up host components" )
974 for host in hosts:
alisone14d7b02016-07-06 10:31:51 -0700975 host.stopScapy( )
976 main.Mininet1.removeHostComponent( "h1" )
977 main.Mininet1.removeHostComponent( "h2" )
GlennRC956ea742015-11-05 16:14:15 -0800978
979 utilities.assert_equals( expect=main.TRUE,
980 actual=stepResult,
981 onpass="Successfully sent a packet",
982 onfail="Failed to send a packet" )
983
alisone14d7b02016-07-06 10:31:51 -0700984 def CASE1700( self, main ):
GlennRC956ea742015-11-05 16:14:15 -0800985 '''
986 Add flows with a TCP selector and verify the flow
987 '''
988 import json
989 import time
990
991 main.case( "Verify the TCP selector is correctly compiled on the flow" )
992 main.caseExplanation = "Install a flow with only the TCP selector " +\
alisone14d7b02016-07-06 10:31:51 -0700993 "specified, verify the flow is added in ONOS, and finally " +\
GlennRC956ea742015-11-05 16:14:15 -0800994 "send a TCP packet to verify the TCP selector is compiled correctly."
995
996 main.step( "Add a flow with a TCP selector" )
997
998 main.log.info( "Creating host components" )
Jon Halla510a8a2016-05-04 15:09:28 -0700999 main.Scapy.createHostComponent( "h1" )
1000 main.Scapy.createHostComponent( "h2" )
alisone14d7b02016-07-06 10:31:51 -07001001 hosts = [ main.h1, main.h2 ]
GlennRC956ea742015-11-05 16:14:15 -08001002 for host in hosts:
alisone14d7b02016-07-06 10:31:51 -07001003 host.startHostCli( )
1004 host.startScapy( )
1005 host.updateSelf( )
GlennRC956ea742015-11-05 16:14:15 -08001006
1007 # Add a flow that connects host1 on port1 to host2 on port2
1008 egress = 2
1009 ingress = 1
1010 # IPv4 etherType
1011 ethType = main.params[ 'TEST' ][ 'ip4Type' ]
1012 # IP protocol
1013 ipProto = main.params[ 'TEST' ][ 'tcpProto' ]
1014 # TCP port destination
1015 tcpDst = main.params[ 'TEST' ][ 'tcpDst' ]
1016
1017 main.log.info( "Add a flow that connects host1 on port1 to host2 on port2" )
1018 stepResult = main.ONOSrest.addFlow( deviceId=main.swDPID,
1019 egressPort=egress,
1020 ingressPort=ingress,
1021 ethType=ethType,
1022 ipProto=ipProto,
1023 tcpDst=tcpDst,
1024 debug=main.debug )
1025
1026 utilities.assert_equals( expect=main.TRUE,
1027 actual=stepResult,
1028 onpass="Successfully added flows",
1029 onfail="Failed add flows" )
1030
1031 # Giving ONOS time to add the flow
1032 time.sleep( main.addFlowSleep )
1033
1034 main.step( "Check flow is in the ADDED state" )
1035
1036 main.log.info( "Get the flows from ONOS" )
Jeremy86160992016-04-11 10:05:53 -07001037 try:
alisone14d7b02016-07-06 10:31:51 -07001038 flows = json.loads( main.ONOSrest.flows( ) )
GlennRC956ea742015-11-05 16:14:15 -08001039
Jeremy86160992016-04-11 10:05:53 -07001040 stepResult = main.TRUE
1041 for f in flows:
alisone14d7b02016-07-06 10:31:51 -07001042 if "rest" in f.get( "appId" ):
1043 if "ADDED" not in f.get( "state" ):
Jeremy86160992016-04-11 10:05:53 -07001044 stepResult = main.FALSE
alisone14d7b02016-07-06 10:31:51 -07001045 main.log.error( "Flow: %s in state: %s" % ( f.get( "id" ), f.get( "state" ) ) )
Jeremy86160992016-04-11 10:05:53 -07001046 except TypeError:
1047 main.log.error( "No Flows found by the REST API" )
1048 stepResult = main.FALSE
1049 except ValueError:
1050 main.log.error( "Problem getting Flows state from REST API. Exiting test" )
alisone14d7b02016-07-06 10:31:51 -07001051 main.cleanup( )
1052 main.exit( )
GlennRC956ea742015-11-05 16:14:15 -08001053
1054 utilities.assert_equals( expect=main.TRUE,
1055 actual=stepResult,
1056 onpass="All flows are in the ADDED state",
1057 onfail="All flows are NOT in the ADDED state" )
1058
1059 main.step( "Check flows are in Mininet's flow table" )
1060
1061 # get the flow IDs that were added through rest
1062 main.log.info( "Getting the flow IDs from ONOS" )
alisone14d7b02016-07-06 10:31:51 -07001063 flowIds = [ f.get( "id" ) for f in flows if "rest" in f.get( "appId" ) ]
GlennRC956ea742015-11-05 16:14:15 -08001064 # convert the flowIDs to ints then hex and finally back to strings
alisone14d7b02016-07-06 10:31:51 -07001065 flowIds = [ str( hex( int( x ) ) ) for x in flowIds ]
1066 main.log.info( "ONOS flow IDs: {}".format( flowIds ) )
GlennRC956ea742015-11-05 16:14:15 -08001067
1068 stepResult = main.Mininet1.checkFlowId( "s1", flowIds, debug=False )
1069
1070 utilities.assert_equals( expect=main.TRUE,
1071 actual=stepResult,
1072 onpass="All flows are in mininet",
1073 onfail="All flows are NOT in mininet" )
1074
1075 main.step( "Send a packet to verify the flow is correct" )
1076
1077 main.log.info( "Constructing packet" )
1078 # No need for the MAC src dst
1079 main.h1.buildEther( dst=main.h2.hostMac )
1080 main.h1.buildIP( dst=main.h2.hostIp )
1081 main.h1.buildTCP( dport=tcpDst )
1082
1083 main.log.info( "Starting filter on host2" )
1084 # Defaults to ip
1085 main.h2.startFilter( pktFilter="tcp" )
1086
1087 main.log.info( "Sending packet to host2" )
alisone14d7b02016-07-06 10:31:51 -07001088 main.h1.sendPacket( )
GlennRC956ea742015-11-05 16:14:15 -08001089
1090 main.log.info( "Checking filter for our packet" )
alisone14d7b02016-07-06 10:31:51 -07001091 stepResult = main.h2.checkFilter( )
GlennRC956ea742015-11-05 16:14:15 -08001092 if stepResult:
alisone14d7b02016-07-06 10:31:51 -07001093 main.log.info( "Packet: %s" % main.h2.readPackets( ) )
1094 else: main.h2.killFilter( )
GlennRC956ea742015-11-05 16:14:15 -08001095
1096 main.log.info( "Clean up host components" )
1097 for host in hosts:
alisone14d7b02016-07-06 10:31:51 -07001098 host.stopScapy( )
1099 main.Mininet1.removeHostComponent( "h1" )
1100 main.Mininet1.removeHostComponent( "h2" )
GlennRC956ea742015-11-05 16:14:15 -08001101
1102 utilities.assert_equals( expect=main.TRUE,
1103 actual=stepResult,
1104 onpass="Successfully sent a packet",
1105 onfail="Failed to send a packet" )
1106
alisone14d7b02016-07-06 10:31:51 -07001107 def CASE1600( self, main ):
GlennRC956ea742015-11-05 16:14:15 -08001108 '''
1109 Add flows with a UDP selector and verify the flow
1110 '''
1111 import json
1112 import time
1113
1114 main.case( "Verify the UDP selector is correctly compiled on the flow" )
1115 main.caseExplanation = "Install a flow with only the UDP selector " +\
alisone14d7b02016-07-06 10:31:51 -07001116 "specified, verify the flow is added in ONOS, and finally " +\
GlennRC956ea742015-11-05 16:14:15 -08001117 "send a UDP packet to verify the UDP selector is compiled correctly."
1118
1119 main.step( "Add a flow with a UDP selector" )
1120
1121 main.log.info( "Creating host components" )
Jon Halla510a8a2016-05-04 15:09:28 -07001122 main.Scapy.createHostComponent( "h1" )
1123 main.Scapy.createHostComponent( "h2" )
alisone14d7b02016-07-06 10:31:51 -07001124 hosts = [ main.h1, main.h2 ]
GlennRC956ea742015-11-05 16:14:15 -08001125 for host in hosts:
alisone14d7b02016-07-06 10:31:51 -07001126 host.startHostCli( )
1127 host.startScapy( )
1128 host.updateSelf( )
GlennRC956ea742015-11-05 16:14:15 -08001129
1130 # Add a flow that connects host1 on port1 to host2 on port2
1131 egress = 2
1132 ingress = 1
1133 # IPv4 etherType
1134 ethType = main.params[ 'TEST' ][ 'ip4Type' ]
1135 # IP protocol
1136 ipProto = main.params[ 'TEST' ][ 'udpProto' ]
1137 # UDP port destination
1138 udpDst = main.params[ 'TEST' ][ 'udpDst' ]
1139
1140 main.log.info( "Add a flow that connects host1 on port1 to host2 on port2" )
1141 stepResult = main.ONOSrest.addFlow( deviceId=main.swDPID,
1142 egressPort=egress,
1143 ingressPort=ingress,
1144 ethType=ethType,
1145 ipProto=ipProto,
1146 udpDst=udpDst,
1147 debug=main.debug )
1148
1149 utilities.assert_equals( expect=main.TRUE,
1150 actual=stepResult,
1151 onpass="Successfully added flows",
1152 onfail="Failed add flows" )
1153
1154 # Giving ONOS time to add the flow
1155 time.sleep( main.addFlowSleep )
1156
1157 main.step( "Check flow is in the ADDED state" )
1158
1159 main.log.info( "Get the flows from ONOS" )
Jeremy86160992016-04-11 10:05:53 -07001160 try:
alisone14d7b02016-07-06 10:31:51 -07001161 flows = json.loads( main.ONOSrest.flows( ) )
GlennRC956ea742015-11-05 16:14:15 -08001162
Jeremy86160992016-04-11 10:05:53 -07001163 stepResult = main.TRUE
1164 for f in flows:
alisone14d7b02016-07-06 10:31:51 -07001165 if "rest" in f.get( "appId" ):
1166 if "ADDED" not in f.get( "state" ):
Jeremy86160992016-04-11 10:05:53 -07001167 stepResult = main.FALSE
alisone14d7b02016-07-06 10:31:51 -07001168 main.log.error( "Flow: %s in state: %s" % ( f.get( "id" ), f.get( "state" ) ) )
Jeremy86160992016-04-11 10:05:53 -07001169 except TypeError:
1170 main.log.error( "No Flows found by the REST API" )
1171 stepResult = main.FALSE
1172 except ValueError:
1173 main.log.error( "Problem getting Flows state from REST API. Exiting test" )
alisone14d7b02016-07-06 10:31:51 -07001174 main.cleanup( )
1175 main.exit( )
GlennRC956ea742015-11-05 16:14:15 -08001176
1177 utilities.assert_equals( expect=main.TRUE,
1178 actual=stepResult,
1179 onpass="All flows are in the ADDED state",
1180 onfail="All flows are NOT in the ADDED state" )
1181
1182 main.step( "Check flows are in Mininet's flow table" )
1183
1184 # get the flow IDs that were added through rest
1185 main.log.info( "Getting the flow IDs from ONOS" )
alisone14d7b02016-07-06 10:31:51 -07001186 flowIds = [ f.get( "id" ) for f in flows if "rest" in f.get( "appId" ) ]
GlennRC956ea742015-11-05 16:14:15 -08001187 # convert the flowIDs to ints then hex and finally back to strings
alisone14d7b02016-07-06 10:31:51 -07001188 flowIds = [ str( hex( int( x ) ) ) for x in flowIds ]
1189 main.log.info( "ONOS flow IDs: {}".format( flowIds ) )
GlennRC956ea742015-11-05 16:14:15 -08001190
1191 stepResult = main.Mininet1.checkFlowId( "s1", flowIds, debug=False )
1192
1193 utilities.assert_equals( expect=main.TRUE,
1194 actual=stepResult,
1195 onpass="All flows are in mininet",
1196 onfail="All flows are NOT in mininet" )
1197
1198 main.step( "Send a packet to verify the flow is correct" )
1199
1200 main.log.info( "Constructing packet" )
1201 # No need for the MAC src dst
1202 main.h1.buildEther( dst=main.h2.hostMac )
1203 main.h1.buildIP( dst=main.h2.hostIp )
1204 main.h1.buildUDP( dport=udpDst )
1205
1206 main.log.info( "Starting filter on host2" )
1207 # Defaults to ip
1208 main.h2.startFilter( pktFilter="udp" )
1209
1210 main.log.info( "Sending packet to host2" )
alisone14d7b02016-07-06 10:31:51 -07001211 main.h1.sendPacket( )
GlennRC956ea742015-11-05 16:14:15 -08001212
1213 main.log.info( "Checking filter for our packet" )
alisone14d7b02016-07-06 10:31:51 -07001214 stepResult = main.h2.checkFilter( )
GlennRC956ea742015-11-05 16:14:15 -08001215 if stepResult:
alisone14d7b02016-07-06 10:31:51 -07001216 main.log.info( "Packet: %s" % main.h2.readPackets( ) )
1217 else: main.h2.killFilter( )
GlennRC956ea742015-11-05 16:14:15 -08001218
1219 main.log.info( "Clean up host components" )
1220 for host in hosts:
alisone14d7b02016-07-06 10:31:51 -07001221 host.stopScapy( )
1222 main.Mininet1.removeHostComponent( "h1" )
1223 main.Mininet1.removeHostComponent( "h2" )
GlennRC956ea742015-11-05 16:14:15 -08001224
1225 utilities.assert_equals( expect=main.TRUE,
1226 actual=stepResult,
1227 onpass="Successfully sent a packet",
1228 onfail="Failed to send a packet" )
1229
alisone14d7b02016-07-06 10:31:51 -07001230 def CASE1900( self, main ):
1231 '''
1232 Add flows with a ICMPv4 selector and verify the flow
1233 '''
GlennRC956ea742015-11-05 16:14:15 -08001234 import json
alisone14d7b02016-07-06 10:31:51 -07001235 import time
GlennRC956ea742015-11-05 16:14:15 -08001236
alisone14d7b02016-07-06 10:31:51 -07001237 main.case( "Verify the ICMPv4 selector is correctly compiled on the flow" )
1238 main.caseExplanation = "Install a flow with only the ICMPv4 selector " +\
1239 "specified, verify the flow is added in ONOS, and finally " +\
1240 "send a IMCPv4 packet to verify the ICMPv4 selector is compiled correctly."
GlennRC956ea742015-11-05 16:14:15 -08001241
alisone14d7b02016-07-06 10:31:51 -07001242 main.step( "Add a flow with a ICMPv4 selector" )
1243
1244 main.log.info( "Creating host components" )
1245 main.Scapy.createHostComponent( "h1" )
1246 main.Scapy.createHostComponent( "h2" )
1247 hosts = [ main.h1, main.h2 ]
1248 for host in hosts:
1249 host.startHostCli( )
1250 host.startScapy( )
1251 host.updateSelf( )
1252
1253 # Add a flow that connects host1 on port1 to host2 on port2
1254 egress = 2
1255 ingress = 1
1256 # IPv4 etherType
1257 ethType = main.params[ 'TEST' ][ 'ip4Type' ]
1258 # IP protocol
1259 ipProto = main.params[ 'TEST' ][ 'icmpProto' ]
1260
1261 main.log.info( "Add a flow that connects host1 on port1 to host2 on port2" )
1262 stepResult = main.ONOSrest.addFlow( deviceId=main.swDPID,
1263 egressPort=egress,
1264 ingressPort=ingress,
1265 ethType=ethType,
1266 ipProto=ipProto,
1267 debug=main.debug )
1268
1269 utilities.assert_equals( expect=main.TRUE,
1270 actual=stepResult,
1271 onpass="Successfully added flows",
1272 onfail="Failed add flows" )
1273
1274 # Giving ONOS time to add the flow
1275 time.sleep( main.addFlowSleep )
1276
1277 main.step( "Check flow is in the ADDED state" )
1278
1279 main.log.info( "Get the flows from ONOS" )
Jeremy86160992016-04-11 10:05:53 -07001280 try:
alisone14d7b02016-07-06 10:31:51 -07001281 flows = json.loads( main.ONOSrest.flows( ) )
GlennRC956ea742015-11-05 16:14:15 -08001282
Jeremy86160992016-04-11 10:05:53 -07001283 stepResult = main.TRUE
1284 for f in flows:
alisone14d7b02016-07-06 10:31:51 -07001285 if "rest" in f.get( "appId" ):
1286 if "ADDED" not in f.get( "state" ):
1287 stepResult = main.FALSE
1288 main.log.error( "Flow: %s in state: %s" % ( f.get( "id" ), f.get( "state" ) ) )
Jeremy86160992016-04-11 10:05:53 -07001289 except TypeError:
1290 main.log.error( "No Flows found by the REST API" )
1291 stepResult = main.FALSE
1292 except ValueError:
1293 main.log.error( "Problem getting Flows state from REST API. Exiting test" )
alisone14d7b02016-07-06 10:31:51 -07001294 main.cleanup( )
1295 main.exit( )
1296
1297 utilities.assert_equals( expect=main.TRUE,
1298 actual=stepResult,
1299 onpass="All flows are in the ADDED state",
1300 onfail="All flows are NOT in the ADDED state" )
1301
1302 main.step( "Check flows are in Mininet's flow table" )
1303
1304 # get the flow IDs that were added through rest
1305 main.log.info( "Getting the flow IDs from ONOS" )
1306 flowIds = [ f.get( "id" ) for f in flows if "rest" in f.get( "appId" ) ]
1307 # convert the flowIDs to ints then hex and finally back to strings
1308 flowIds = [ str( hex( int( x ) ) ) for x in flowIds ]
1309 main.log.info( "ONOS flow IDs: {}".format( flowIds ) )
1310
1311 stepResult = main.Mininet1.checkFlowId( "s1", flowIds, debug=False )
1312
1313 utilities.assert_equals( expect=main.TRUE,
1314 actual=stepResult,
1315 onpass="All flows are in mininet",
1316 onfail="All flows are NOT in mininet" )
1317
1318 main.step( "Send a packet to verify the flow is correct" )
1319
1320 main.log.info( "Constructing packet" )
1321 # No need for the MAC src dst
1322 main.h1.buildEther( dst=main.h2.hostMac )
1323 main.h1.buildIP( dst=main.h2.hostIp )
1324 main.h1.buildICMP( )
1325
1326 main.log.info( "Starting filter on host2" )
1327 # Defaults to ip
1328 main.h2.startFilter( pktFilter="icmp" )
1329
1330 main.log.info( "Sending packet to host2" )
1331 main.h1.sendPacket( )
1332
1333 main.log.info( "Checking filter for our packet" )
1334 stepResult = main.h2.checkFilter( )
1335 if stepResult:
1336 main.log.info( "Packet: %s" % main.h2.readPackets( ) )
1337 else: main.h2.killFilter( )
1338
1339 main.log.info( "Clean up host components" )
1340 for host in hosts:
1341 host.stopScapy( )
1342 main.Mininet1.removeHostComponent( "h1" )
1343 main.Mininet1.removeHostComponent( "h2" )
1344
1345 utilities.assert_equals( expect=main.TRUE,
1346 actual=stepResult,
1347 onpass="Successfully sent a packet",
1348 onfail="Failed to send a packet" )
1349
1350 def CASE2000( self, main ):
1351 '''
1352 Add flows with a ICMPv6 selector and verify the flow
1353 '''
1354 import json
1355 import time
1356
1357 main.case( "Verify the ICMPv6 selector is correctly compiled on the flow" )
1358 main.caseExplanation = "Install a flow with only the ICMPv6 selector " +\
1359 "specified, verify the flow is added in ONOS, and finally " +\
1360 "send a IMCPv6 packet to verify the ICMPv6 selector is compiled correctly."
1361
1362 main.step( "Add a flow with a ICMPv6 selector" )
1363
1364 main.log.info( "Creating host components" )
1365 main.Scapy.createHostComponent( "h5" )
1366 main.Scapy.createHostComponent( "h6" )
1367 hosts =[ main.h5, main.h6 ]
1368 for host in hosts:
1369 host.startHostCli( )
1370 host.startScapy( )
1371 host.updateSelf( IPv6=True )
1372
1373 # Add a flow that connects host1 on port1 to host2 on port2
1374 egress =6
1375 ingress =5
1376 # IPv6 etherType
1377 ethType = main.params[ 'TEST' ][ 'ip6Type' ]
1378 # IP protocol
1379 ipProto = main.params[ 'TEST' ][ 'icmp6Proto' ]
1380
1381 main.log.info( "Add a flow that connects host1 on port1 to host2 on port2" )
1382 stepResult = main.ONOSrest.addFlow( deviceId=main.swDPID,
1383 egressPort=egress,
1384 ingressPort=ingress,
1385 ethType=ethType,
1386 ipProto=ipProto,
1387 debug=main.debug )
1388
1389 utilities.assert_equals( expect=main.TRUE,
1390 actual=stepResult,
1391 onpass="Successfully added flows",
1392 onfail="Failed add flows" )
1393
1394 # Giving ONOS time to add the flow
1395 time.sleep( main.addFlowSleep )
1396
1397 main.step( "Check flow is in the ADDED state" )
1398
1399 main.log.info( "Get the flows from ONOS" )
1400 try:
1401 flows = json.loads( main.ONOSrest.flows( ) )
1402
1403 stepResult = main.TRUE
1404 for f in flows:
1405 if "rest" in f.get( "appId" ):
1406 if "ADDED" not in f.get( "state" ):
1407 stepResult = main.FALSE
1408 main.log.error( "Flow: %s in state: %s" % ( f.get( "id" ), f.get( "state" ) ) )
1409 except TypeError:
1410 main.log.error( "No Flows found by the REST API" )
1411 stepResult = main.FALSE
1412 except ValueError:
1413 main.log.error( "Problem getting Flows state from REST API. Exiting test" )
1414 main.cleanup( )
1415 main.exit( )
1416
1417 utilities.assert_equals( expect=main.TRUE,
1418 actual=stepResult,
1419 onpass="All flows are in the ADDED state",
1420 onfail="All flows are NOT in the ADDED state" )
1421
1422 main.step( "Check flows are in Mininet's flow table" )
1423
1424 # get the flow IDs that were added through rest
1425 main.log.info( "Getting the flow IDs from ONOS" )
1426 flowIds = [ f.get( "id" ) for f in flows if "rest" in f.get( "appId" ) ]
1427 # convert the flowIDs to ints then hex and finally back to strings
1428 flowIds = [ str( hex( int( x ) ) ) for x in flowIds ]
1429 main.log.info( "ONOS flow IDs: {}".format( flowIds ) )
1430
1431 stepResult = main.Mininet1.checkFlowId( "s1", flowIds, debug=False )
1432
1433 utilities.assert_equals( expect=main.TRUE,
1434 actual=stepResult,
1435 onpass="All flows are in mininet",
1436 onfail="All flows are NOT in mininet" )
1437
1438 main.step( "Send a packet to verify the flow is correct" )
1439
1440 main.log.info( "Constructing packet" )
1441 # No need for the MAC src dst
1442 main.h5.buildEther( dst=main.h6.hostMac )
1443 main.h5.buildIPv6( dst=main.h6.hostIp )
1444 main.h5.buildICMP( ipVersion=6 )
1445
1446 main.log.info( "Starting filter on host2" )
1447 # Defaults to ip
1448 main.h6.startFilter( pktFilter="icmp6" )
1449
1450 main.log.info( "Sending packet to host2" )
1451 main.h5.sendPacket( )
1452
1453 main.log.info( "Checking filter for our packet" )
1454 stepResult = main.h6.checkFilter( )
1455 if stepResult:
1456 main.log.info( "Packet: %s" % main.h6.readPackets( ) )
1457 else: main.h6.killFilter( )
1458
1459 main.log.info( "Clean up host components" )
1460 for host in hosts:
1461 host.stopScapy( )
1462 main.Mininet1.removeHostComponent( "h5" )
1463 main.Mininet1.removeHostComponent( "h6" )
1464
1465 utilities.assert_equals( expect=main.TRUE,
1466 actual=stepResult,
1467 onpass="Successfully sent a packet",
1468 onfail="Failed to send a packet" )
1469
1470 def CASE3000( self, main ):
1471 '''
1472 Delete flow
1473 '''
1474 import json
1475
1476 main.case( "Delete flows that were added through rest" )
1477 main.step( "Deleting flows" )
1478
1479 main.log.info( "Getting flows" )
1480 try:
1481 flows = json.loads( main.ONOSrest.flows( ) )
1482
1483 stepResult = main.TRUE
1484 for f in flows:
1485 if "rest" in f.get( "appId" ):
1486 if main.debug: main.log.debug( "Flow to be deleted:\n{}".format( main.ONOSrest.pprint( f ) ) )
1487 stepResult = stepResult and main.ONOSrest.removeFlow( f.get( "deviceId" ), f.get( "id" ) )
1488 except TypeError:
1489 main.log.error( "No Flows found by the REST API" )
1490 stepResult = main.FALSE
1491 except ValueError:
1492 main.log.error( "Problem getting Flows state from REST API. Exiting test" )
1493 main.cleanup( )
1494 main.exit( )
GlennRC956ea742015-11-05 16:14:15 -08001495
1496 utilities.assert_equals( expect=main.TRUE,
1497 actual=stepResult,
1498 onpass="Successfully deleting flows",
1499 onfail="Failed to delete flows" )
1500
1501 time.sleep( main.delFlowSleep )
1502
alisone14d7b02016-07-06 10:31:51 -07001503
1504 def CASE1200(self, main ):
1505 '''
1506 Add flows with a ARP selector and verify the flow
1507 '''
1508 import json
1509 import time
1510
1511 main.case( "Verify flow IP selectors are correctly compiled" )
1512 main.caseExplanation = "Install two flows with only IP selectors " + \
1513 "specified, then verify flows are added in ONOS, finally " + \
1514 "send a packet that only specifies the IP src and dst."
1515
1516 main.step( "Add flows with ARP addresses as the only selectors" )
1517
1518 main.log.info( "Creating host components" )
1519 main.Scapy.createHostComponent( "h1" )
1520 main.Scapy.createHostComponent( "h2" )
1521 hosts = [ main.h1, main.h2 ]
1522 for host in hosts:
1523 host.startHostCli( )
1524 host.startScapy( )
1525 host.updateSelf( )
1526
1527 # Add a flow that connects host1 on port1 to host2 on port2
1528 # send output on port2
1529 # recieve input on port1
1530 egress = 2
1531 ingress = 1
1532 # ARP etherType = 0x0806
1533 ethType = main.params[ 'TEST' ][ 'arpType' ]
1534
1535 # Add flows that connects host1 to host2
1536 main.log.info( "Add flow with port ingress 1 to port egress 2" )
1537 stepResult = main.ONOSrest.addFlow(deviceId=main.swDPID,
1538 egressPort=egress,
1539 ingressPort=ingress,
1540 ethType=ethType,
1541 priority=40001,
1542 debug=main.debug )
1543
1544 utilities.assert_equals( expect=main.TRUE,
1545 actual=stepResult,
1546 onpass="Successfully added flows",
1547 onfail="Failed add flows" )
1548
1549 # Giving ONOS time to add the flow
1550 time.sleep( main.addFlowSleep )
1551
1552 main.step( "Check flow is in the ADDED state" )
1553
1554 main.log.info( "Get the flows from ONOS" )
1555 try:
1556 flows = json.loads( main.ONOSrest.flows( ) )
1557
1558 stepResult = main.TRUE
1559 for f in flows:
1560 if "rest" in f.get( "appId" ):
1561 if "ADDED" not in f.get( "state" ):
1562 stepResult = main.FALSE
1563 main.log.error("Flow: %s in state: %s" % ( f.get("id"), f.get( "state" ) ) )
1564 except TypeError:
1565 main.log.error( "No Flows found by the REST API" )
1566 stepResult = main.FALSE
1567 except ValueError:
1568 main.log.error( "Problem getting Flows state from REST API. Exiting test" )
1569 main.cleanup( )
1570 main.exit( )
1571
1572 utilities.assert_equals( expect=main.TRUE,
1573 actual=stepResult,
1574 onpass="All flows are in the ADDED state",
1575 onfail="All flows are NOT in the ADDED state" )
1576
1577 main.step( "Check flows are in Mininet's flow table" )
1578
1579 # get the flow IDs that were added through rest
1580 main.log.info( "Getting the flow IDs from ONOS" )
1581 flowIds = [f.get( "id" ) for f in flows if "rest" in f.get( "appId" ) ]
1582 # convert the flowIDs to ints then hex and finally back to strings
1583 flowIds = [ str( hex( int( x ) ) ) for x in flowIds ]
1584 main.log.info("ONOS flow IDs: {}".format( flowIds ) )
1585
1586 stepResult = main.Mininet1.checkFlowId( "s1", flowIds, debug=False )
1587
1588 utilities.assert_equals( expect=main.TRUE,
1589 actual=stepResult,
1590 onpass="All flows are in mininet",
1591 onfail="All flows are NOT in mininet" )
1592
1593 main.step( "Send a packet to verify the flow is correct" )
1594
1595 main.log.info( "Constructing packet" )
1596 # No need for the MAC src dst
1597 main.h1.buildEther( src=main.h1.hostMac, dst=main.h2.hostMac )
1598 main.h1.buildARP( pdst=main.h2.hostIp )
1599
1600 main.log.info( "Starting filter on host2" )
1601 # Defaults to ip
1602 main.h2.startFilter( pktFilter="arp" )
1603
1604 main.log.info( "Sending packet to host2" )
1605 main.h1.sendPacket( )
1606
1607 main.log.info( "Checking filter for our packet" )
1608 stepResult = main.h2.checkFilter( )
1609 if stepResult:
1610 main.log.info( "Packet: %s" % main.h2.readPackets( ) )
1611 else:
1612 main.h2.killFilter( )
1613
1614 main.log.info( "Clean up host components" )
1615 for host in hosts:
1616 host.stopScapy( )
1617 main.Mininet1.removeHostComponent( "h1" )
1618 main.Mininet1.removeHostComponent( "h2" )
1619
1620 utilities.assert_equals( expect=main.TRUE,
1621 actual=stepResult,
1622 onpass="Successfully sent a packet",
1623 onfail="Failed to send a packet" )
1624
1625 def CASE1800( self, main ):
1626 '''
1627 Add flows with a SCTP selector and verify the flow
1628 '''
1629 import json
1630 import time
1631
1632 main.case( "Verify the UDP selector is correctly compiled on the flow" )
1633 main.caseExplanation = "Install a flow with only the UDP selector " + \
1634 "specified, verify the flow is added in ONOS, and finally " + \
1635 "send a UDP packet to verify the UDP selector is compiled correctly."
1636
1637 main.step( "Add a flow with a SCTP selector" )
1638
1639 main.log.info( "Creating host components" )
1640 main.Scapy.createHostComponent( "h1" )
1641 main.Scapy.createHostComponent( "h2" )
1642 hosts = [ main.h1, main.h2 ]
1643 for host in hosts:
1644 host.startHostCli( )
1645 host.startScapy( )
1646 host.updateSelf( )
1647
1648 # Add a flow that connects host1 on port1 to host2 on port2
1649 egress = 2
1650 ingress = 1
1651 # IPv4 etherType
1652 ethType = main.params[ 'TEST' ][ 'ip4Type' ]
1653 # IP protocol
1654 ipProto = main.params[ 'TEST' ][ 'sctpProto' ]
1655
1656 main.log.info("Add a flow that connects host1 on port1 to host2 on port2")
1657 stepResult = main.ONOSrest.addFlow( deviceId=main.swDPID,
1658 egressPort=egress,
1659 ingressPort=ingress,
1660 ethType=ethType,
1661 ipProto=ipProto,
1662 debug=main.debug )
1663
1664 utilities.assert_equals( expect=main.TRUE,
1665 actual=stepResult,
1666 onpass="Successfully added flows",
1667 onfail="Failed add flows" )
1668
1669 # Giving ONOS time to add the flow
1670 time.sleep( main.addFlowSleep )
1671
1672 main.step( "Check flow is in the ADDED state" )
1673
1674 main.log.info( "Get the flows from ONOS" )
1675 try:
1676 flows = json.loads( main.ONOSrest.flows( ) )
1677
1678 stepResult = main.TRUE
1679 for f in flows:
1680 if "rest" in f.get( "appId" ):
1681 if "ADDED" not in f.get( "state" ):
1682 stepResult = main.FALSE
1683 main.log.error("Flow: %s in state: %s" % ( f.get( "id" ), f.get( "state" ) ) )
1684 except TypeError:
1685 main.log.error( "No Flows found by the REST API" )
1686 stepResult = main.FALSE
1687 except ValueError:
1688 main.log.error( "Problem getting Flows state from REST API. Exiting test" )
1689 main.cleanup( )
1690 main.exit( )
1691
1692 utilities.assert_equals( expect=main.TRUE,
1693 actual=stepResult,
1694 onpass="All flows are in the ADDED state",
1695 onfail="All flows are NOT in the ADDED state" )
1696
1697 main.step( "Check flows are in Mininet's flow table" )
1698
1699 # get the flow IDs that were added through rest
1700 main.log.info( "Getting the flow IDs from ONOS" )
1701 flowIds = [ f.get( "id" ) for f in flows if "rest" in f.get( "appId" ) ]
1702 # convert the flowIDs to ints then hex and finally back to strings
1703 flowIds = [ str( hex( int( x ) ) ) for x in flowIds ]
1704 main.log.info( "ONOS flow IDs: {}".format( flowIds ) )
1705
1706 stepResult = main.Mininet1.checkFlowId( "s1", flowIds, debug=False )
1707
1708 utilities.assert_equals( expect=main.TRUE,
1709 actual=stepResult,
1710 onpass="All flows are in mininet",
1711 onfail="All flows are NOT in mininet" )
1712
1713 main.step( "Send a packet to verify the flow is correct" )
1714
1715 main.log.info( "Constructing packet" )
1716 # No need for the MAC src dst
1717 main.h1.buildEther( dst=main.h2.hostMac )
1718 main.h1.buildIP( dst=main.h2.hostIp )
1719 main.h1.buildSCTP( )
1720
1721 main.log.info( "Starting filter on host2" )
1722 # Defaults to ip
1723 main.h2.startFilter( pktFilter="sctp" )
1724
1725 main.log.info( "Sending packet to host2" )
1726 main.h1.sendPacket( )
1727
1728 main.log.info( "Checking filter for our packet" )
1729 stepResult = main.h2.checkFilter( )
1730 if stepResult:
1731 main.log.info( "Packet: %s" % main.h2.readPackets( ) )
1732 else:
1733 main.h2.killFilter( )
1734
1735 main.log.info( "Clean up host components" )
1736 for host in hosts:
1737 host.stopScapy( )
1738 main.Mininet1.removeHostComponent( "h1" )
1739 main.Mininet1.removeHostComponent( "h2" )
1740
1741 utilities.assert_equals( expect=main.TRUE,
1742 actual=stepResult,
1743 onpass="Successfully sent a packet",
1744 onfail="Failed to send a packet" )
1745
GlennRC68449942015-10-16 16:03:12 -07001746 def CASE100( self, main ):
GlennRC5147a422015-10-06 17:26:17 -07001747 '''
1748 Report errors/warnings/exceptions
1749 '''
alisone14d7b02016-07-06 10:31:51 -07001750 main.log.info( "Error report: \n" )
GlennRC5147a422015-10-06 17:26:17 -07001751 main.ONOSbench.logReport( main.ONOSip[ 0 ],
1752 [ "INFO",
1753 "FOLLOWER",
1754 "WARN",
1755 "flow",
1756 "ERROR",
1757 "Except" ],
GlennRC68449942015-10-16 16:03:12 -07001758 "s" )