blob: 9c1b8c1efc23dc2daed4e1025ee0180735239ff8 [file] [log] [blame]
Andreas Pantelopoulos90f0b102018-02-01 13:21:45 -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
Jon Halla604fd42018-05-04 14:27:27 -070022def setupTest( main, test_idx, onosNodes=-1, ipv4=True, ipv6=True,
23 external=True, static=False, countFlowsGroups=False ):
You Wang5da39c82018-04-26 22:55:08 -070024 """
25 SRRouting test setup
26 """
27 from tests.USECASE.SegmentRouting.dependencies.Testcaselib import Testcaselib as lib
You Wang68568b12019-03-04 11:49:57 -080028 import tests.USECASE.SegmentRouting.dependencies.cfgtranslator as translator
You Wangd66de192018-04-30 17:30:12 -070029 import time
30
Jon Hall9b0de1f2020-08-24 15:38:04 -070031 try:
32 skipPackage = False
33 init = False
34 if not hasattr( main, 'apps' ):
35 init = True
36 lib.initTest( main )
37 if onosNodes < 0:
38 onosNodes = main.Cluster.numCtrls
39 # Skip onos packaging if the cluster size stays the same
40 if not init and onosNodes == main.Cluster.numCtrls:
41 skipPackage = True
You Wang5da39c82018-04-26 22:55:08 -070042
Jon Hall9b0de1f2020-08-24 15:38:04 -070043 main.internalIpv4Hosts = main.params[ 'TOPO' ][ 'internalIpv4Hosts' ].split( ',' )
44 main.internalIpv6Hosts = main.params[ 'TOPO' ][ 'internalIpv6Hosts' ].split( ',' )
45 main.externalIpv4Hosts = main.params[ 'TOPO' ][ 'externalIpv4Hosts' ].split( ',' ) if main.params[ 'TOPO' ].get('externalIpv4Hosts') else []
46 main.externalIpv6Hosts = main.params[ 'TOPO' ][ 'externalIpv6Hosts' ].split( ',' ) if main.params[ 'TOPO' ].get('externalIpv6Hosts') else []
47 main.staticIpv4Hosts = main.params[ 'TOPO' ][ 'staticIpv4Hosts' ].split( ',' ) if main.params[ 'TOPO' ].get('staticIpv4Hosts') else []
48 main.staticIpv6Hosts = main.params[ 'TOPO' ][ 'staticIpv6Hosts' ].split( ',' ) if main.params[ 'TOPO' ].get('staticIpv6Hosts') else []
49 main.disconnectedIpv4Hosts = []
50 main.disconnectedIpv6Hosts = []
51 main.disconnectedExternalIpv4Hosts = []
52 main.disconnectedExternalIpv6Hosts = []
53 main.disconnectedStaticIpv4Hosts = []
54 main.disconnectedStaticIpv6Hosts = []
55 main.resultFileName = 'CASE%03d' % test_idx
56 main.Cluster.setRunningNode( onosNodes )
You Wang5da39c82018-04-26 22:55:08 -070057
Jon Hall9b0de1f2020-08-24 15:38:04 -070058 lib.installOnos( main, skipPackage=skipPackage, cliSleep=5 )
You Wangd66de192018-04-30 17:30:12 -070059
Jon Hall9b0de1f2020-08-24 15:38:04 -070060 # Load configuration files
61 if hasattr( main, "Mininet1" ):
62 main.cfgName = 'TEST_CONFIG_ipv4={}_ipv6={}'.format( 1 if ipv4 else 0,
63 1 if ipv6 else 0)
64 else:
65 main.cfgName = main.params[ "DEPENDENCY" ][ "confName" ]
You Wang68568b12019-03-04 11:49:57 -080066 if main.useBmv2:
Jon Hall9b0de1f2020-08-24 15:38:04 -070067 # Translate configuration file from OVS-OFDPA to BMv2 driver
68 translator.bmv2ToOfdpa( main ) # Try to cleanup if switching between switch types
69 switchPrefix = main.params[ 'DEPENDENCY' ].get( 'switchPrefix', "bmv2" )
70 translator.ofdpaToBmv2( main, switchPrefix=switchPrefix )
71 else:
72 translator.bmv2ToOfdpa( main )
73 lib.loadJson( main )
74 main.log.debug( "sleeping %i seconds" % float( main.params[ 'timers' ][ 'loadNetcfgSleep' ] ) )
75 time.sleep( float( main.params[ 'timers' ][ 'loadNetcfgSleep' ] ) )
76 lib.loadHost( main )
You Wang0fc21702018-11-02 17:49:18 -070077
Jon Hall9b0de1f2020-08-24 15:38:04 -070078 # if static route flag add routes
79 # these routes are topology specific
80 if static:
81 if ipv4:
82 lib.addStaticOnosRoute( main, "10.0.88.0/24", "10.0.1.1")
83 lib.addStaticOnosRoute( main, "10.0.88.0/24", "10.0.5.1")
84 if ipv6:
85 lib.addStaticOnosRoute( main, "2000::8700/120", "2000::101")
86 lib.addStaticOnosRoute( main, "2000::8700/120", "2000::501")
87 if countFlowsGroups:
88 lib.loadCount( main )
89
90 if hasattr( main, 'Mininet1' ):
91 lib.mnDockerSetup( main )
92 # Run the test with Mininet
93 mininet_args = ' --dhcp=1 --routers=1 --ipv6={} --ipv4={}'.format( 1 if ipv6 else 0,
94 1 if ipv4 else 0 )
95 if main.useBmv2:
96 mininet_args += ' --switch %s' % main.switchType
97 main.log.info( "Using %s switch" % main.switchType )
98 lib.startMininet( main, main.params[ 'DEPENDENCY' ][ 'topology' ], args=mininet_args )
99 main.log.debug( "Waiting %i seconds for ONOS to discover dataplane" % float( main.params[ "timers" ][ "startMininetSleep" ] ))
100 time.sleep( float( main.params[ "timers" ][ "startMininetSleep" ] ) )
101 else:
102 # Run the test with physical devices
103 lib.connectToPhysicalNetwork( main )
104
105 lib.saveOnosDiagnostics( main )
106 # wait some time for onos to install the rules!
107 main.log.info( "Waiting %i seconds for ONOS to program the dataplane" % float( main.params[ "timers" ][ "dhcpSleep" ] ))
108 time.sleep( float( main.params[ 'timers' ][ 'dhcpSleep' ] ) )
109 except Exception as e:
110 main.log.exception( "Error in setupTest" )
111 main.skipCase( result="FAIL", msg=e )
You Wang5da39c82018-04-26 22:55:08 -0700112
You Wangd66de192018-04-30 17:30:12 -0700113def verifyPingInternal( main, ipv4=True, ipv6=True, disconnected=True ):
You Wang5da39c82018-04-26 22:55:08 -0700114 """
115 Verify all connected internal hosts are able to reach each other,
116 and disconnected internal hosts cannot reach any other internal host
117 """
118 from tests.USECASE.SegmentRouting.dependencies.Testcaselib import Testcaselib as lib
119 # Verify connected hosts
You Wangd66de192018-04-30 17:30:12 -0700120 if ipv4:
121 lib.verifyPing( main,
122 [ h for h in main.internalIpv4Hosts if h not in main.disconnectedIpv4Hosts ],
You Wang85747762018-05-11 15:51:50 -0700123 [ h for h in main.internalIpv4Hosts if h not in main.disconnectedIpv4Hosts ],
124 stepMsg="Verify reachability of connected internal IPv4 hosts" )
You Wangd66de192018-04-30 17:30:12 -0700125 if ipv6:
126 lib.verifyPing( main,
127 [ h for h in main.internalIpv6Hosts if h not in main.disconnectedIpv6Hosts ],
128 [ h for h in main.internalIpv6Hosts if h not in main.disconnectedIpv6Hosts ],
You Wang42f9e8a2018-07-11 13:25:11 -0700129 ipv6=True,
You Wang85747762018-05-11 15:51:50 -0700130 stepMsg="Verify reachability of connected internal IPv6 hosts" )
You Wang5da39c82018-04-26 22:55:08 -0700131 # Verify disconnected hosts
You Wangd66de192018-04-30 17:30:12 -0700132 if disconnected:
You Wangd66de192018-04-30 17:30:12 -0700133 if main.disconnectedIpv4Hosts:
You Wang85747762018-05-11 15:51:50 -0700134 lib.verifyPing( main, main.internalIpv4Hosts, main.disconnectedIpv4Hosts, expect=False,
135 stepMsg="Verify unreachability of disconnected internal IPv4 hosts" )
You Wangd66de192018-04-30 17:30:12 -0700136 if main.disconnectedIpv6Hosts:
You Wang85747762018-05-11 15:51:50 -0700137 lib.verifyPing( main, main.internalIpv6Hosts, main.disconnectedIpv6Hosts, ipv6=True, expect=False,
138 stepMsg="Verify unreachability of disconnected internal IPv6 hosts" )
You Wang5da39c82018-04-26 22:55:08 -0700139
You Wangd66de192018-04-30 17:30:12 -0700140def verifyPingExternal( main, ipv4=True, ipv6=True, disconnected=True ):
You Wang5da39c82018-04-26 22:55:08 -0700141 """
142 Verify all connected internal hosts are able to reach external hosts,
143 and disconnected internal hosts cannot reach any external host
144 """
145 from tests.USECASE.SegmentRouting.dependencies.Testcaselib import Testcaselib as lib
146 # Verify connected hosts
You Wangd66de192018-04-30 17:30:12 -0700147 if ipv4:
148 lib.verifyPing( main,
149 [ h for h in main.internalIpv4Hosts if h not in main.disconnectedIpv4Hosts ],
You Wang85747762018-05-11 15:51:50 -0700150 [ h for h in main.externalIpv4Hosts if h not in main.disconnectedExternalIpv4Hosts ],
You Wang54b1d672018-06-11 16:44:13 -0700151 stepMsg="Verify reachability from connected internal IPv4 hosts to external IPv4 hosts",
152 t3Simple=False )
You Wangd66de192018-04-30 17:30:12 -0700153 if ipv6:
154 lib.verifyPing( main,
155 [ h for h in main.internalIpv6Hosts if h not in main.disconnectedIpv6Hosts ],
Jonghwan Hyun3759e472018-05-01 15:40:08 -0700156 [ h for h in main.externalIpv6Hosts if h not in main.disconnectedExternalIpv6Hosts ],
You Wang42f9e8a2018-07-11 13:25:11 -0700157 ipv6=True,
You Wang54b1d672018-06-11 16:44:13 -0700158 stepMsg="Verify reachability from connected internal IPv6 hosts to external IPv6 hosts",
159 t3Simple=False )
You Wang5da39c82018-04-26 22:55:08 -0700160 # Verify disconnected hosts
You Wangd66de192018-04-30 17:30:12 -0700161 if disconnected:
Jonghwan Hyun3759e472018-05-01 15:40:08 -0700162 # Disconnected internal to connected external
You Wangd66de192018-04-30 17:30:12 -0700163 if main.disconnectedIpv4Hosts:
Jonghwan Hyun3759e472018-05-01 15:40:08 -0700164 lib.verifyPing( main, main.disconnectedIpv4Hosts,
165 [ h for h in main.externalIpv4Hosts if h not in main.disconnectedExternalIpv4Hosts ],
You Wang85747762018-05-11 15:51:50 -0700166 expect=False,
You Wang54b1d672018-06-11 16:44:13 -0700167 stepMsg="Verify unreachability of disconnected internal IPv4 hosts to connected external IPv4 hosts",
168 t3Simple=False )
You Wangd66de192018-04-30 17:30:12 -0700169 if main.disconnectedIpv6Hosts:
Jonghwan Hyun3759e472018-05-01 15:40:08 -0700170 lib.verifyPing( main, main.disconnectedIpv6Hosts,
171 [ h for h in main.externalIpv6Hosts if h not in main.disconnectedExternalIpv6Hosts ],
You Wang85747762018-05-11 15:51:50 -0700172 ipv6=True, expect=False,
You Wang54b1d672018-06-11 16:44:13 -0700173 stepMsg="Verify unreachability of disconnected internal IPv6 hosts to connected external IPv6 hosts",
174 t3Simple=False )
Jonghwan Hyun3759e472018-05-01 15:40:08 -0700175 # Connected internal to disconnected external
176 if main.disconnectedExternalIpv4Hosts:
177 lib.verifyPing( main,
178 [ h for h in main.internalIpv4Hosts if h not in main.disconnectedIpv4Hosts ],
179 main.disconnectedExternalIpv4Hosts,
You Wang85747762018-05-11 15:51:50 -0700180 expect=False,
You Wang54b1d672018-06-11 16:44:13 -0700181 stepMsg="Verify unreachability of connected internal IPv4 hosts to disconnected external IPv4 hosts",
182 t3Simple=False )
Jonghwan Hyun3759e472018-05-01 15:40:08 -0700183 if main.disconnectedExternalIpv6Hosts:
184 lib.verifyPing( main,
185 [ h for h in main.internalIpv6Hosts if h not in main.disconnectedIpv6Hosts ],
186 main.disconnectedExternalIpv6Hosts,
You Wang85747762018-05-11 15:51:50 -0700187 ipv6=True, expect=False,
You Wang54b1d672018-06-11 16:44:13 -0700188 stepMsg="Verify unreachability of connected internal IPv6 hosts to disconnected external IPv6 hosts",
189 t3Simple=False )
You Wang5da39c82018-04-26 22:55:08 -0700190
You Wangd66de192018-04-30 17:30:12 -0700191def verifyPing( main, ipv4=True, ipv6=True, disconnected=False, internal=True, external=True ):
You Wang5da39c82018-04-26 22:55:08 -0700192 """
193 Verify reachability and unreachability of connected/disconnected hosts
194 """
You Wangd66de192018-04-30 17:30:12 -0700195 if internal:
196 verifyPingInternal( main, ipv4, ipv6, disconnected )
197 if external:
198 verifyPingExternal( main, ipv4, ipv6, disconnected )
199
Jon Halla604fd42018-05-04 14:27:27 -0700200def verifyLinkFailure( main, ipv4=True, ipv6=True, disconnected=False,
201 internal=True, external=True, countFlowsGroups=False ):
You Wangd66de192018-04-30 17:30:12 -0700202 """
203 Kill and recover all links to spine101 and 102 sequencially and run verifications
204 """
205 from tests.USECASE.SegmentRouting.dependencies.Testcaselib import Testcaselib as lib
206 linksToRemove = [ ["spine103", "spine101"],
207 ["leaf2", "spine101"],
208 ["leaf3", "spine101"],
209 ["leaf4", "spine101"],
210 ["leaf5", "spine101"] ]
211 lib.killLinkBatch( main, linksToRemove, 30, 10 )
212 verify( main, ipv4, ipv6, disconnected, internal, external, countFlowsGroups )
213 lib.restoreLinkBatch( main, linksToRemove, 48, 10 )
214 verify( main, ipv4, ipv6, disconnected, internal, external, countFlowsGroups )
215 linksToRemove = [ ["spine104", "spine102"],
216 ["leaf2", "spine102"],
217 ["leaf3", "spine102"],
218 ["leaf4", "spine102"],
219 ["leaf5", "spine102"] ]
220 lib.killLinkBatch( main, linksToRemove, 30, 10 )
221 verify( main, ipv4, ipv6, disconnected, internal, external, countFlowsGroups )
222 lib.restoreLinkBatch( main, linksToRemove, 48, 10 )
223 verify( main, ipv4, ipv6, disconnected, internal, external, countFlowsGroups )
224
Jon Halla604fd42018-05-04 14:27:27 -0700225def verifySwitchFailure( main, ipv4=True, ipv6=True, disconnected=False,
226 internal=True, external=True, countFlowsGroups=False ):
You Wangd66de192018-04-30 17:30:12 -0700227 """
228 Kill and recover spine101 and 102 sequencially and run verifications
229 """
230 from tests.USECASE.SegmentRouting.dependencies.Testcaselib import Testcaselib as lib
231 for switchToKill in [ "spine101", "spine102" ]:
232 lib.killSwitch( main, switchToKill, 9, 30 )
233 verify( main, ipv4, ipv6, disconnected, internal, external, countFlowsGroups )
234 lib.recoverSwitch( main, switchToKill, 10, 48 )
235 verify( main, ipv4, ipv6, disconnected, internal, external, countFlowsGroups )
236
Jon Halla604fd42018-05-04 14:27:27 -0700237def verifyOnosFailure( main, ipv4=True, ipv6=True, disconnected=False,
238 internal=True, external=True, countFlowsGroups=False ):
You Wangd66de192018-04-30 17:30:12 -0700239 """
240 Kill and recover onos nodes sequencially and run verifications
241 """
242 from tests.USECASE.SegmentRouting.dependencies.Testcaselib import Testcaselib as lib
243 import json
244 import time
245
246 numCtrls = len( main.Cluster.runningNodes )
247 links = len( json.loads( main.Cluster.next().links() ) )
248 switches = len( json.loads( main.Cluster.next().devices() ) )
Jon Halla604fd42018-05-04 14:27:27 -0700249 mastershipSleep = float( main.params[ 'timers' ][ 'balanceMasterSleep' ] )
You Wangd66de192018-04-30 17:30:12 -0700250 for ctrl in xrange( numCtrls ):
251 # Kill node
252 lib.killOnos( main, [ ctrl ], switches, links, ( numCtrls - 1 ) )
253 main.Cluster.active(0).CLI.balanceMasters()
Jon Hall43060f62020-06-23 13:13:33 -0700254 main.log.debug( "sleeping %i seconds" % mastershipSleep )
Jon Halla604fd42018-05-04 14:27:27 -0700255 time.sleep( mastershipSleep )
You Wangd66de192018-04-30 17:30:12 -0700256 verify( main, ipv4, ipv6, disconnected, internal, external, countFlowsGroups )
257 # Recover node
258 lib.recoverOnos( main, [ ctrl ], switches, links, numCtrls )
259 main.Cluster.active(0).CLI.balanceMasters()
Jon Hall43060f62020-06-23 13:13:33 -0700260 main.log.debug( "sleeping %i seconds" % mastershipSleep )
Jon Halla604fd42018-05-04 14:27:27 -0700261 time.sleep( mastershipSleep )
You Wangd66de192018-04-30 17:30:12 -0700262 verify( main, ipv4, ipv6, disconnected, internal, external, countFlowsGroups )
263
264def verify( main, ipv4=True, ipv6=True, disconnected=True, internal=True, external=True, countFlowsGroups=False ):
265 """
266 Verify host IP assignment, flow/group number and pings
267 """
268 from tests.USECASE.SegmentRouting.dependencies.Testcaselib import Testcaselib as lib
Jon Hall39570262020-11-17 12:18:19 -0800269
270 spines = 4
271 leaves = 6
272 switches = spines + leaves
273 links = 0
274 #links = ( spines * leaves ) * 2
275 # Some double links, spines 101 and 102 to leaves 2-5
276 links += ( 2 * 4 * 2 ) * 2
277 # Some paired leaves
278 links += ( ( leaves - 2 ) / 2 ) * 2
279 # Paired spines
280 links += ( spines / 2 ) * 2
281 # single homed leaf to spines
282 links += ( 2 * 2 ) * 2
283
284 lib.verifyTopology( main, switches, links, len( main.Cluster.runningNodes ) )
You Wangd66de192018-04-30 17:30:12 -0700285 # check flows / groups numbers
286 if countFlowsGroups:
Jon Halla604fd42018-05-04 14:27:27 -0700287 lib.checkFlowsGroupsFromFile( main )
You Wangd66de192018-04-30 17:30:12 -0700288 # ping hosts
289 verifyPing( main, ipv4, ipv6, disconnected, internal, external )
Jon Hall39570262020-11-17 12:18:19 -0800290 # Verify host IP assignment
291 lib.verifyOnosHostIp( main )
292 lib.verifyNetworkHostIp( main )
293 # ping hosts
294 verifyPing( main, ipv4, ipv6, disconnected, internal, external )
You Wang0f745de2018-07-27 15:49:22 -0700295
296def verifyRouterFailure( main, routerToKill, affectedIpv4Hosts=[], affectedIpv6Hosts=[],
297 ipv4=True, ipv6=True, countFlowsGroups=False ):
298 """
299 Kill and recover a quagga router and verify connectivities to external hosts
300 """
301 from tests.USECASE.SegmentRouting.dependencies.Testcaselib import Testcaselib as lib
302 lib.killRouter( main, routerToKill, 5 )
303 main.disconnectedExternalIpv4Hosts = affectedIpv4Hosts
304 main.disconnectedExternalIpv6Hosts = affectedIpv6Hosts
305 verify( main, ipv4, ipv6, True if (affectedIpv4Hosts or affectedIpv6Hosts) else False, False, True, countFlowsGroups )
306 lib.recoverRouter( main, routerToKill, 5 )
307 main.disconnectedExternalIpv4Hosts = []
308 main.disconnectedExternalIpv6Hosts = []
309 verify( main, ipv4, ipv6, False, False, True, countFlowsGroups )