blob: 4e1703e98465e2e5d43c6d23f5f5abc4ee2170ec [file] [log] [blame]
Jonghwan Hyun812c70f2018-02-16 16:33:16 -08001"""
2Copyright 2017 Open Networking Foundation ( ONF )
3
4Please refer questions to either the onos test mailing list at <onos-test@onosproject.org>,
5the System Testing Plans and Results wiki page at <https://wiki.onosproject.org/x/voMg>,
6or the System Testing Guide page at <https://wiki.onosproject.org/x/WYQg>
7
8 TestON is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 2 of the License, or
11 ( at your option ) any later version.
12
13 TestON is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with TestON. If not, see <http://www.gnu.org/licenses/>.
20"""
21
You Wang68568b12019-03-04 11:49:57 -080022import tests.USECASE.SegmentRouting.dependencies.cfgtranslator as translator
23
Jonghwan Hyun812c70f2018-02-16 16:33:16 -080024class SRDynamicConfTest:
25 def __init__( self ):
26 self.default = ''
27
28 @staticmethod
29 def runTest( main, testIndex, topology, onosNodes, description, vlan=( 0, 0, 0, 0 ) ):
30 '''
31 Tests connectivity for each test case.
32 Configuration files:
33 - (0x1, 0x2, 2x2, 2x4).json: device configuration, fed to ONOS before configuration change
34 - CASE*.json: interface configuration, fed to ONOS before configuration change
35 - CASE*0.chart: ping chart, used to check connectivity before configuration change.
36 Shared among same test scenario with different topology.
37 - CASE*0_after.chart: ping chart, used to check connectivity after configuration change.
38 Shared among same test scenario with different topology.
39 Only used when ping chart is updated.
40 '''
41 topo = dict()
42 # (number of spine switch, number of leaf switch, dual-homed, description, port number of h1)
43 topo[ '0x1' ] = ( 0, 1, False, 'single ToR', 1 )
44 topo[ '0x2' ] = ( 0, 2, True, 'dual-homed ToR', 2 )
45 topo[ '2x2' ] = ( 2, 2, False, '2x2 leaf-spine topology', 3 )
46 topo[ '2x4' ] = ( 2, 4, True, '2x4 dual-homed leaf-spine topology', 6 )
47 fanout = 4
48 switchNames = {}
49 switchNames[ '2x2' ] = [ "leaf1", "leaf2", "spine101", "spine102" ]
50
51 TAG = 'CASE%d' % testIndex
52 skipPackage = False
53 init = False
54 dualHomed = topo[ topology ][ 2 ]
55 portNum = topo[ topology ][ 4 ]
56 defaultIntf = 'bond0' if dualHomed else 'eth0'
57
58 from tests.USECASE.SegmentRouting.dependencies.Testcaselib import Testcaselib as run
59 if not hasattr( main, 'apps' ):
60 init = True
61 run.initTest( main )
62 # Skip onos packaging if the clusrer size stays the same
63 if not init and onosNodes == main.Cluster.numCtrls:
64 skipPackage = True
65
66 main.case( '%s, with %s and %d ONOS instance%s' %
67 ( description, topo[ topology ][ 3 ], onosNodes, 's' if onosNodes > 1 else '' ) )
68 main.cfgName = topology
69 main.Cluster.setRunningNode( onosNodes )
70 run.installOnos( main, skipPackage=skipPackage, cliSleep=5 )
71
72 # Provide common configuration
73 # TODO: Generate json and chart dynamically, according to topologies and scenarios
You Wang68568b12019-03-04 11:49:57 -080074 if main.useBmv2:
75 # Translate configuration file from OVS-OFDPA to BMv2 driver
76 translator.ofdpaToBmv2( main )
77 else:
78 translator.bmv2ToOfdpa( main )
Jonghwan Hyun812c70f2018-02-16 16:33:16 -080079 run.loadJson( main )
80 run.loadChart( main )
81
82 # Provide topology-specific interface configuration
83 import json
84 try:
You Wang68568b12019-03-04 11:49:57 -080085 intfCfg = "%s%s%s.json" % ( main.configPath, main.forJson, TAG )
86 if main.useBmv2:
87 # Translate configuration file from OVS-OFDPA to BMv2 driver
88 translator.ofdpaToBmv2( main, intfCfg )
89 else:
90 translator.bmv2ToOfdpa( main, intfCfg )
91 with open( intfCfg ) as cfg:
Jonghwan Hyun812c70f2018-02-16 16:33:16 -080092 main.Cluster.active( 0 ).REST.setNetCfg( json.load( cfg ) )
93 except IOError:
94 # Load default interface configuration
You Wang68568b12019-03-04 11:49:57 -080095 defaultIntfCfg = "%s%s%s_ports.json" % ( main.configPath, main.forJson, topology )
96 if main.useBmv2:
97 # Translate configuration file from OVS-OFDPA to BMv2 driver
98 translator.ofdpaToBmv2( main, defaultIntfCfg )
99 else:
100 translator.bmv2ToOfdpa( main, defaultIntfCfg )
101 with open( defaultIntfCfg ) as cfg:
Jonghwan Hyun812c70f2018-02-16 16:33:16 -0800102 main.Cluster.active( 0 ).REST.setNetCfg( json.load( cfg ) )
103
104 try:
105 with open( "%s%sCASE%d.chart" % (main.configPath, main.forChart, testIndex / 10 * 10) ) as chart:
106 main.pingChart = json.load( chart )
107 except IOError:
108 # Load default chart
109 with open( "%s%sdefault.chart" % (main.configPath, main.forChart) ) as chart:
110 main.pingChart = json.load( chart )
111
112 # Set up topology
113 if hasattr( main, 'Mininet1' ):
114 # Run the test with mininet topology
115 mininet_args = ' --spine=%d --leaf=%d --fanout=%d' \
116 % ( topo[ topology ][ 0 ], topo[ topology ][ 1 ], fanout )
117 if len( vlan ) > 0 :
118 mininet_args += ' --vlan=%s' % ( ','.join( [ '%d' % vlanId for vlanId in vlan ] ) )
119 if topo[ topology ][ 0 ] > 0:
120 mininet_args += ',0,0,0,0'
121 if dualHomed:
122 mininet_args += ' --dual-homed'
You Wang68568b12019-03-04 11:49:57 -0800123 if main.useBmv2:
124 mininet_args += ' --switch bmv2'
125 main.log.info( "Using BMv2 switch" )
Jonghwan Hyun812c70f2018-02-16 16:33:16 -0800126
127 run.startMininet( main, 'trellis_fabric.py', args=mininet_args )
128 else:
129 # Run the test with physical devices
130 run.connectToPhysicalNetwork( main, switchNames[ topology ] )
131
132 # minFlowCountPerLeaf = 13 + [# of ports] * 5 + [# of hosts] * 2 + [# of vlan ids]
133 minFlowCountPerLeaf = 13 + ( fanout + topo[ topology ][ 0 ]) * 5 + fanout * 2 + len( set( vlan ) )
134 run.checkFlows( main, minFlowCount=minFlowCountPerLeaf * topo[ topology ][ 1 ], sleep=5, dumpflows=False )
135 # Check connectivity before changing interface configuration
136 run.pingAll( main, '%s_Before' % TAG, retryAttempts=2 )
137
You Wang68568b12019-03-04 11:49:57 -0800138 if main.useBmv2:
139 leaf_dpid = [ "device:bmv2:leaf%d" % ( ls + 1 ) for ls in range( topo[ topology ][ 1 ] ) ]
140 else:
141 leaf_dpid = [ "of:%016d" % ( ls + 1 ) for ls in range( topo[ topology ][ 1 ] ) ]
Jonghwan Hyun812c70f2018-02-16 16:33:16 -0800142 for dpid in leaf_dpid:
143 run.checkFlowsByDpid( main, dpid, minFlowCountPerLeaf, sleep=5 )
144
145 # Testcase-specific interface configuration change
146 if testIndex / 10 == 1:
147 # CASE11-14
148 if hasattr( main, 'Mininet1' ):
149 # Assign vlan tag 10 to host h1
150 main.Mininet1.assignVLAN( 'h1', 'h1-%s' % defaultIntf, '10' )
151 # Update port configuration of port 1
152 SRDynamicConfTest.updateIntfCfg( main, portNum, dualHomed,
153 [ '10.0.2.254/24', ], tagged=[ 10, ] )
154 else:
155 # TODO: update physical device configuration, same for all test cases
156 pass
157 elif testIndex / 10 == 2:
158 # CASE21-24
159 if hasattr( main, 'Mininet1' ):
160 # Update port configuration of port 1
161 SRDynamicConfTest.updateIntfCfg( main, portNum, dualHomed,
162 [ '10.0.2.254/24', ], untagged=20 )
163 elif testIndex / 10 == 3:
164 # CASE31-34
165 if hasattr( main, 'Mininet1' ):
166 # Update port configuration of port 1
167 SRDynamicConfTest.updateIntfCfg( main, portNum, dualHomed,
168 [ '10.0.2.254/24', ], untagged=110 )
169 # Update port configuration of port 2
170 SRDynamicConfTest.updateIntfCfg( main, portNum + 1, dualHomed,
171 [ '10.0.2.254/24', ], untagged=110 )
172 elif testIndex / 10 == 4:
173 # CASE41-44
174 if hasattr( main, 'Mininet1' ):
175 # Assign vlan tag 20 to host h1
176 main.Mininet1.assignVLAN( 'h1', 'h1-%s' % defaultIntf, '20')
177 # Update port configuration of port 1
178 SRDynamicConfTest.updateIntfCfg( main, portNum, dualHomed,
179 [ '10.0.2.254/24', ], tagged=[ 20, ] )
180 elif testIndex / 10 == 5:
181 # CASE51-54
182 if hasattr( main, 'Mininet1' ):
183 # Update port configuration of port 1
184 SRDynamicConfTest.updateIntfCfg( main, portNum, dualHomed,
185 [ '10.0.2.254/24', ], tagged=[ 20, ], native=10 )
186 elif testIndex / 10 == 6:
187 # CASE61-64
188 if hasattr( main, 'Mininet1' ):
189 # Update port configuration of port 1
190 SRDynamicConfTest.updateIntfCfg( main, portNum, dualHomed,
191 [ '10.0.2.254/24', ], tagged=[ 120, ], native=110 )
192 # Update port configuration of port 2
193 SRDynamicConfTest.updateIntfCfg( main, portNum + 1, dualHomed,
194 [ '10.0.2.254/24', ], tagged=[ 120, ], native=110 )
195 elif testIndex / 10 == 7:
196 # CASE71-74
197 if hasattr( main, 'Mininet1' ):
198 # Update host configuration of h1
199 main.Mininet1.removeVLAN( 'h1', 'h1-%s.10' % defaultIntf )
200 # Update port configuration of port 1
201 SRDynamicConfTest.updateIntfCfg( main, portNum, dualHomed,
202 [ '10.0.2.254/24', ], untagged=10 )
203 elif testIndex / 10 == 8:
204 # CASE81-84
205 if hasattr( main, 'Mininet1' ):
206 # Update port configuration of port 1
207 SRDynamicConfTest.updateIntfCfg( main, portNum, dualHomed,
208 [ '10.0.2.254/24', ], tagged=[ 20, ], native=10 )
209 elif testIndex / 10 == 9:
210 # CASE91-94
211 if hasattr( main, 'Mininet1' ):
212 # Update host configuration
213 main.Mininet1.removeVLAN( 'h1', 'h1-%s.10' % defaultIntf )
214 main.Mininet1.removeVLAN( 'h2', 'h2-%s.10' % defaultIntf )
215
216 # Update port configuration
217 SRDynamicConfTest.updateIntfCfg( main, portNum, dualHomed,
218 [ '10.0.2.254/24', ], tagged=[ 120, ], native=110 )
219 SRDynamicConfTest.updateIntfCfg( main, portNum + 1, dualHomed,
220 [ '10.0.2.254/24', ], tagged=[ 120, ], native=110 )
221 elif testIndex / 10 == 10:
222 # CASE101-104
223 if hasattr( main, 'Mininet1' ):
224 # Update port configuration
225 SRDynamicConfTest.updateIntfCfg( main, portNum, dualHomed,
226 [ '10.0.2.254/24', ], untagged=20 )
227 elif testIndex / 10 == 11:
228 # CASE111-114
229 if hasattr( main, 'Mininet1' ):
230 # Update port configuration
231 SRDynamicConfTest.updateIntfCfg( main, portNum, dualHomed,
232 [ '10.0.2.254/24', ], tagged=[ 20, ] )
233 elif testIndex / 10 == 12:
234 # CASE121-124
235 if hasattr( main, 'Mininet1' ):
236 # Update port configuration
237 SRDynamicConfTest.updateIntfCfg( main, portNum, dualHomed,
238 [ '10.0.2.254/24', ], tagged=[ 20, ], native=110 )
239 SRDynamicConfTest.updateIntfCfg( main, portNum + 1, dualHomed,
240 [ '10.0.2.254/24', ], tagged=[ 20, ], native=110 )
241 elif testIndex / 10 == 13:
242 # CASE131-134
243 if hasattr( main, 'Mininet1' ):
244 # Update port configuration
245 SRDynamicConfTest.updateIntfCfg( main, portNum, dualHomed,
246 [ '10.0.2.254/24', ], tagged=[ 120, ], native=10 )
247 elif testIndex / 10 == 14:
248 # CASE141-144
249 if hasattr( main, 'Mininet1' ):
250 # Update port configuration
251 SRDynamicConfTest.updateIntfCfg( main, portNum, dualHomed,
252 [ '10.0.2.254/24', ], tagged=[ 20, ] )
253 elif testIndex / 10 == 15:
254 # CASE151-154
255 if hasattr( main, 'Mininet1' ):
256 # Update port configuration
257 SRDynamicConfTest.updateIntfCfg( main, portNum, dualHomed,
258 [ '10.0.2.254/24', ], tagged=[ 120, ] )
259 elif testIndex / 10 == 16:
260 # CASE161-164
261 if hasattr( main, 'Mininet1' ):
262 # Update port configuration
263 SRDynamicConfTest.updateIntfCfg( main, portNum, dualHomed,
264 [ '10.0.2.254/24', ], tagged=[ 20, ], native=10 )
265 elif testIndex / 10 == 17:
266 # CASE171-174
267 if hasattr( main, 'Mininet1' ):
268 # Update port configuration
269 SRDynamicConfTest.updateIntfCfg( main, portNum, dualHomed,
270 [ '10.0.2.254/24', ], tagged=[ 120, ] )
271 elif testIndex / 10 == 18:
272 # CASE181-184
273 if hasattr( main, 'Mininet1' ):
274 # Update port configuration
275 SRDynamicConfTest.updateIntfCfg( main, portNum, dualHomed,
276 [ '10.0.2.254/24', ], tagged=[ 20, ], native=10 )
277 elif testIndex / 10 == 19:
278 # CASE191-194
279 if hasattr( main, 'Mininet1' ):
280 # Update port configuration
281 SRDynamicConfTest.updateIntfCfg( main, portNum, dualHomed,
282 [ '10.0.2.254/24', ], untagged=20 )
283 elif testIndex / 10 == 20:
284 # CASE201-204
285 if hasattr( main, 'Mininet1' ):
286 # Update port configuration
287 SRDynamicConfTest.updateIntfCfg( main, portNum, dualHomed,
288 [ '10.0.2.254/24', ], tagged=[ 20 ] )
289 elif testIndex / 10 == 21:
290 # CASE211-214
291 if hasattr( main, 'Mininet1' ):
292 # Update port configuration
293 SRDynamicConfTest.updateIntfCfg( main, portNum, dualHomed,
294 [ '10.0.2.254/24', ], tagged=[ 20 ], native=110 )
295 elif testIndex / 10 == 22:
296 # CASE221-224
297 if hasattr( main, 'Mininet1' ):
298 # Update port configuration
299 SRDynamicConfTest.updateIntfCfg( main, portNum, dualHomed,
300 [ '10.0.2.254/24', ], tagged=[ 120 ], native=10 )
301 elif testIndex / 10 == 23:
302 # CASE231-234
303 if hasattr( main, "Mininet1" ):
304 SRDynamicConfTest.updateIntfCfg( main, portNum, dualHomed,
305 [ '10.0.2.254/24', ], tagged=[ 10, ] )
306 for dpid in leaf_dpid:
307 run.checkFlowsByDpid( main, dpid, minFlowCountPerLeaf, sleep=5 )
308 main.pingChart[ 'leaf1' ][ 'expect' ] = False
309 run.pingAll( main, '%s_1' % TAG, retryAttempts=2 )
310
311 SRDynamicConfTest.updateIntfCfg( main, portNum, dualHomed,
312 [ '10.0.2.254/24', ], untagged=50 )
313 for dpid in leaf_dpid:
314 run.checkFlowsByDpid( main, dpid, minFlowCountPerLeaf, sleep=5 )
315 run.pingAll( main, '%s_2' % TAG, retryAttempts=2 )
316
317 SRDynamicConfTest.updateIntfCfg( main, portNum, dualHomed,
318 [ '10.0.2.254/24', ], tagged=[ 20, ] )
319 for dpid in leaf_dpid:
320 run.checkFlowsByDpid( main, dpid, minFlowCountPerLeaf, sleep=5 )
321 run.pingAll( main, '%s_3' % TAG, retryAttempts=2 )
322
323 SRDynamicConfTest.updateIntfCfg( main, portNum, dualHomed,
324 [ '10.0.2.254/24', ], tagged=[ 40, ], native=10 )
325 for dpid in leaf_dpid:
326 run.checkFlowsByDpid( main, dpid, minFlowCountPerLeaf, sleep=5 )
327 main.pingChart[ 'leaf1' ][ 'expect' ] = True
328 run.pingAll( main, '%s_4' % TAG, retryAttempts=2 )
329
330 SRDynamicConfTest.updateIntfCfg( main, portNum, dualHomed,
331 [ '10.0.2.254/24', ], tagged=[ 20, ] )
332 for dpid in leaf_dpid:
333 run.checkFlowsByDpid( main, dpid, minFlowCountPerLeaf, sleep=5 )
334 main.pingChart[ 'leaf1' ][ 'expect' ] = False
335 run.pingAll( main, '%s_5' % TAG, retryAttempts=2 )
336
337 SRDynamicConfTest.updateIntfCfg( main, portNum, dualHomed,
338 [ '10.0.2.254/24', ], untagged= 20 )
339 for dpid in leaf_dpid:
340 run.checkFlowsByDpid( main, dpid, minFlowCountPerLeaf, sleep=5 )
341 run.pingAll( main, '%s_6' % TAG, retryAttempts=2 )
342
343 SRDynamicConfTest.updateIntfCfg( main, portNum, dualHomed,
344 [ '10.0.2.254/24', ], untagged= 10 )
345 for dpid in leaf_dpid:
346 run.checkFlowsByDpid( main, dpid, minFlowCountPerLeaf, sleep=5 )
347 main.pingChart[ 'leaf1' ][ 'expect' ] = True
348 elif testIndex / 10 == 24:
349 # CASE243-244
350 # Only for 2x2 and 2x4 topology, to test reachability from other leaf
351 if hasattr( main, "Mininet1" ):
352 # Update host IP and default GW
353 main.Mininet1.changeIP( 'h1', 'h1-%s' % defaultIntf, '10.0.6.1', '255.255.255.0' )
354 main.Mininet1.changeDefaultGateway( 'h1', '10.0.6.254' )
355 # Update port configuration
356 SRDynamicConfTest.updateIntfCfg( main, portNum, dualHomed,
357 [ '10.0.6.254/24', ], untagged=60 )
358
359 # Update ping chart in case it is changed
360 try:
361 with open( "%s%sCASE%d_after.chart" % (main.configPath, main.forChart, testIndex / 10 * 10 ) ) as chart:
362 main.pingChart = json.load(chart)
363 except IOError:
364 main.log.debug( "Ping chart is not changed" )
365
366 # Check connectivity after changing interface configuration
367 run.checkFlows( main, minFlowCount=minFlowCountPerLeaf * topo[ topology ][ 1 ], sleep=5, dumpflows=False )
368 run.pingAll( main, '%s_After' % TAG, retryAttempts=2 )
369
You Wang5df1c6d2018-04-06 18:02:02 -0700370 run.cleanup( main )
Jonghwan Hyun812c70f2018-02-16 16:33:16 -0800371
372 @staticmethod
373 def updateIntfCfg( main, portNum, dualHomed, ips=[], untagged=0, tagged=[], native=0 ):
374 from tests.USECASE.SegmentRouting.dependencies.Testcaselib import Testcaselib as run
You Wang68568b12019-03-04 11:49:57 -0800375 if main.useBmv2:
376 run.updateIntfCfg( main, "device:bmv2:leaf1/%d" % portNum,
Jonghwan Hyun812c70f2018-02-16 16:33:16 -0800377 ips=ips, untagged=untagged, tagged=tagged, native=native )
You Wang68568b12019-03-04 11:49:57 -0800378 else:
379 run.updateIntfCfg( main, "of:0000000000000001/%d" % portNum,
380 ips=ips, untagged=untagged, tagged=tagged, native=native )
381 if dualHomed:
382 if main.useBmv2:
383 run.updateIntfCfg( main, "device:bmv2:leaf2/%d" % portNum,
384 ips=ips, untagged=untagged, tagged=tagged, native=native )
385 else:
386 run.updateIntfCfg( main, "of:0000000000000002/%d" % portNum,
387 ips=ips, untagged=untagged, tagged=tagged, native=native )