blob: 2868b5724eaa3ee2b82d9e386fc1c9174bbb652b [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
You Wang5da39c82018-04-26 22:55:08 -070031 skipPackage = False
32 init = False
33 if not hasattr( main, 'apps' ):
34 init = True
You Wangd66de192018-04-30 17:30:12 -070035 lib.initTest( main )
Jon Halla604fd42018-05-04 14:27:27 -070036 if onosNodes < 0:
37 onosNodes = main.Cluster.numCtrls
You Wang5da39c82018-04-26 22:55:08 -070038 # Skip onos packaging if the cluster size stays the same
39 if not init and onosNodes == main.Cluster.numCtrls:
40 skipPackage = True
41
42 main.internalIpv4Hosts = main.params[ 'TOPO' ][ 'internalIpv4Hosts' ].split( ',' )
43 main.internalIpv6Hosts = main.params[ 'TOPO' ][ 'internalIpv6Hosts' ].split( ',' )
You Wang0fc21702018-11-02 17:49:18 -070044 main.externalIpv4Hosts = main.params[ 'TOPO' ][ 'externalIpv4Hosts' ].split( ',' ) if main.params[ 'TOPO' ].get('externalIpv4Hosts') else []
45 main.externalIpv6Hosts = main.params[ 'TOPO' ][ 'externalIpv6Hosts' ].split( ',' ) if main.params[ 'TOPO' ].get('externalIpv6Hosts') else []
46 main.staticIpv4Hosts = main.params[ 'TOPO' ][ 'staticIpv4Hosts' ].split( ',' ) if main.params[ 'TOPO' ].get('staticIpv4Hosts') else []
47 main.staticIpv6Hosts = main.params[ 'TOPO' ][ 'staticIpv6Hosts' ].split( ',' ) if main.params[ 'TOPO' ].get('staticIpv6Hosts') else []
You Wangd66de192018-04-30 17:30:12 -070048 main.disconnectedIpv4Hosts = []
49 main.disconnectedIpv6Hosts = []
You Wang4efd66b2018-06-12 14:47:26 -070050 main.disconnectedExternalIpv4Hosts = []
51 main.disconnectedExternalIpv6Hosts = []
52 main.disconnectedStaticIpv4Hosts = []
53 main.disconnectedStaticIpv6Hosts = []
You Wangd66de192018-04-30 17:30:12 -070054 main.resultFileName = 'CASE%03d' % test_idx
You Wang5da39c82018-04-26 22:55:08 -070055 main.Cluster.setRunningNode( onosNodes )
You Wang5da39c82018-04-26 22:55:08 -070056
You Wang2a1a3352018-07-31 14:35:01 -070057 lib.installOnos( main, skipPackage=skipPackage, cliSleep=5 )
You Wangd66de192018-04-30 17:30:12 -070058
59 # Load configuration files
You Wang0fc21702018-11-02 17:49:18 -070060 if hasattr( main, "Mininet1" ):
61 main.cfgName = 'TEST_CONFIG_ipv4={}_ipv6={}'.format( 1 if ipv4 else 0,
62 1 if ipv6 else 0)
63 else:
64 main.cfgName = main.params[ "DEPENDENCY" ][ "confName" ]
You Wang68568b12019-03-04 11:49:57 -080065 if main.useBmv2:
66 # Translate configuration file from OVS-OFDPA to BMv2 driver
Jon Hall43060f62020-06-23 13:13:33 -070067 translator.bmv2ToOfdpa( main ) # Try to cleanup if switching between switch types
68 switchPrefix = main.params[ 'DEPENDENCY' ].get( 'switchPrefix', "bmv2" )
69 translator.ofdpaToBmv2( main, switchPrefix=switchPrefix )
You Wang68568b12019-03-04 11:49:57 -080070 else:
71 translator.bmv2ToOfdpa( main )
You Wangd66de192018-04-30 17:30:12 -070072 lib.loadJson( main )
Jon Hall43060f62020-06-23 13:13:33 -070073 main.log.debug( "sleeping %i seconds" % float( main.params[ 'timers' ][ 'loadNetcfgSleep' ] ) )
You Wangd66de192018-04-30 17:30:12 -070074 time.sleep( float( main.params[ 'timers' ][ 'loadNetcfgSleep' ] ) )
75 lib.loadHost( main )
76
77 # if static route flag add routes
78 # these routes are topology specific
79 if static:
80 if ipv4:
81 lib.addStaticOnosRoute( main, "10.0.88.0/24", "10.0.1.1")
You Wang0f745de2018-07-27 15:49:22 -070082 lib.addStaticOnosRoute( main, "10.0.88.0/24", "10.0.5.1")
You Wangd66de192018-04-30 17:30:12 -070083 if ipv6:
84 lib.addStaticOnosRoute( main, "2000::8700/120", "2000::101")
You Wang0f745de2018-07-27 15:49:22 -070085 lib.addStaticOnosRoute( main, "2000::8700/120", "2000::501")
You Wangd66de192018-04-30 17:30:12 -070086 if countFlowsGroups:
87 lib.loadCount( main )
88
89 if hasattr( main, 'Mininet1' ):
Jon Hall43060f62020-06-23 13:13:33 -070090 lib.mnDockerSetup( main )
You Wang5da39c82018-04-26 22:55:08 -070091 # Run the test with Mininet
You Wangd66de192018-04-30 17:30:12 -070092 mininet_args = ' --dhcp=1 --routers=1 --ipv6={} --ipv4={}'.format( 1 if ipv6 else 0,
93 1 if ipv4 else 0 )
You Wang68568b12019-03-04 11:49:57 -080094 if main.useBmv2:
Jon Hall43060f62020-06-23 13:13:33 -070095 mininet_args += ' --switch %s' % main.switchType
96 main.log.info( "Using %s switch" % main.switchType )
You Wangd66de192018-04-30 17:30:12 -070097 lib.startMininet( main, main.params[ 'DEPENDENCY' ][ 'topology' ], args=mininet_args )
Jon Hall43060f62020-06-23 13:13:33 -070098 main.log.debug( "Waiting %i seconds for ONOS to discover dataplane" % float( main.params[ "timers" ][ "startMininetSleep" ] ))
You Wang5da39c82018-04-26 22:55:08 -070099 time.sleep( float( main.params[ "timers" ][ "startMininetSleep" ] ) )
100 else:
101 # Run the test with physical devices
You Wang0fc21702018-11-02 17:49:18 -0700102 lib.connectToPhysicalNetwork( main )
103
You Wang5da39c82018-04-26 22:55:08 -0700104 # wait some time for onos to install the rules!
Jon Hall43060f62020-06-23 13:13:33 -0700105 main.log.info( "Waiting %i seconds for ONOS to program the dataplane" % float( main.params[ "timers" ][ "dhcpSleep" ] ))
You Wangd66de192018-04-30 17:30:12 -0700106 time.sleep( float( main.params[ 'timers' ][ 'dhcpSleep' ] ) )
You Wang5da39c82018-04-26 22:55:08 -0700107
You Wangd66de192018-04-30 17:30:12 -0700108def verifyPingInternal( main, ipv4=True, ipv6=True, disconnected=True ):
You Wang5da39c82018-04-26 22:55:08 -0700109 """
110 Verify all connected internal hosts are able to reach each other,
111 and disconnected internal hosts cannot reach any other internal host
112 """
113 from tests.USECASE.SegmentRouting.dependencies.Testcaselib import Testcaselib as lib
114 # Verify connected hosts
You Wangd66de192018-04-30 17:30:12 -0700115 if ipv4:
116 lib.verifyPing( main,
117 [ h for h in main.internalIpv4Hosts if h not in main.disconnectedIpv4Hosts ],
You Wang85747762018-05-11 15:51:50 -0700118 [ h for h in main.internalIpv4Hosts if h not in main.disconnectedIpv4Hosts ],
119 stepMsg="Verify reachability of connected internal IPv4 hosts" )
You Wangd66de192018-04-30 17:30:12 -0700120 if ipv6:
121 lib.verifyPing( main,
122 [ h for h in main.internalIpv6Hosts if h not in main.disconnectedIpv6Hosts ],
123 [ h for h in main.internalIpv6Hosts if h not in main.disconnectedIpv6Hosts ],
You Wang42f9e8a2018-07-11 13:25:11 -0700124 ipv6=True,
You Wang85747762018-05-11 15:51:50 -0700125 stepMsg="Verify reachability of connected internal IPv6 hosts" )
You Wang5da39c82018-04-26 22:55:08 -0700126 # Verify disconnected hosts
You Wangd66de192018-04-30 17:30:12 -0700127 if disconnected:
You Wangd66de192018-04-30 17:30:12 -0700128 if main.disconnectedIpv4Hosts:
You Wang85747762018-05-11 15:51:50 -0700129 lib.verifyPing( main, main.internalIpv4Hosts, main.disconnectedIpv4Hosts, expect=False,
130 stepMsg="Verify unreachability of disconnected internal IPv4 hosts" )
You Wangd66de192018-04-30 17:30:12 -0700131 if main.disconnectedIpv6Hosts:
You Wang85747762018-05-11 15:51:50 -0700132 lib.verifyPing( main, main.internalIpv6Hosts, main.disconnectedIpv6Hosts, ipv6=True, expect=False,
133 stepMsg="Verify unreachability of disconnected internal IPv6 hosts" )
You Wang5da39c82018-04-26 22:55:08 -0700134
You Wangd66de192018-04-30 17:30:12 -0700135def verifyPingExternal( main, ipv4=True, ipv6=True, disconnected=True ):
You Wang5da39c82018-04-26 22:55:08 -0700136 """
137 Verify all connected internal hosts are able to reach external hosts,
138 and disconnected internal hosts cannot reach any external host
139 """
140 from tests.USECASE.SegmentRouting.dependencies.Testcaselib import Testcaselib as lib
141 # Verify connected hosts
You Wangd66de192018-04-30 17:30:12 -0700142 if ipv4:
143 lib.verifyPing( main,
144 [ h for h in main.internalIpv4Hosts if h not in main.disconnectedIpv4Hosts ],
You Wang85747762018-05-11 15:51:50 -0700145 [ h for h in main.externalIpv4Hosts if h not in main.disconnectedExternalIpv4Hosts ],
You Wang54b1d672018-06-11 16:44:13 -0700146 stepMsg="Verify reachability from connected internal IPv4 hosts to external IPv4 hosts",
147 t3Simple=False )
You Wangd66de192018-04-30 17:30:12 -0700148 if ipv6:
149 lib.verifyPing( main,
150 [ h for h in main.internalIpv6Hosts if h not in main.disconnectedIpv6Hosts ],
Jonghwan Hyun3759e472018-05-01 15:40:08 -0700151 [ h for h in main.externalIpv6Hosts if h not in main.disconnectedExternalIpv6Hosts ],
You Wang42f9e8a2018-07-11 13:25:11 -0700152 ipv6=True,
You Wang54b1d672018-06-11 16:44:13 -0700153 stepMsg="Verify reachability from connected internal IPv6 hosts to external IPv6 hosts",
154 t3Simple=False )
You Wang5da39c82018-04-26 22:55:08 -0700155 # Verify disconnected hosts
You Wangd66de192018-04-30 17:30:12 -0700156 if disconnected:
Jonghwan Hyun3759e472018-05-01 15:40:08 -0700157 # Disconnected internal to connected external
You Wangd66de192018-04-30 17:30:12 -0700158 if main.disconnectedIpv4Hosts:
Jonghwan Hyun3759e472018-05-01 15:40:08 -0700159 lib.verifyPing( main, main.disconnectedIpv4Hosts,
160 [ h for h in main.externalIpv4Hosts if h not in main.disconnectedExternalIpv4Hosts ],
You Wang85747762018-05-11 15:51:50 -0700161 expect=False,
You Wang54b1d672018-06-11 16:44:13 -0700162 stepMsg="Verify unreachability of disconnected internal IPv4 hosts to connected external IPv4 hosts",
163 t3Simple=False )
You Wangd66de192018-04-30 17:30:12 -0700164 if main.disconnectedIpv6Hosts:
Jonghwan Hyun3759e472018-05-01 15:40:08 -0700165 lib.verifyPing( main, main.disconnectedIpv6Hosts,
166 [ h for h in main.externalIpv6Hosts if h not in main.disconnectedExternalIpv6Hosts ],
You Wang85747762018-05-11 15:51:50 -0700167 ipv6=True, expect=False,
You Wang54b1d672018-06-11 16:44:13 -0700168 stepMsg="Verify unreachability of disconnected internal IPv6 hosts to connected external IPv6 hosts",
169 t3Simple=False )
Jonghwan Hyun3759e472018-05-01 15:40:08 -0700170 # Connected internal to disconnected external
171 if main.disconnectedExternalIpv4Hosts:
172 lib.verifyPing( main,
173 [ h for h in main.internalIpv4Hosts if h not in main.disconnectedIpv4Hosts ],
174 main.disconnectedExternalIpv4Hosts,
You Wang85747762018-05-11 15:51:50 -0700175 expect=False,
You Wang54b1d672018-06-11 16:44:13 -0700176 stepMsg="Verify unreachability of connected internal IPv4 hosts to disconnected external IPv4 hosts",
177 t3Simple=False )
Jonghwan Hyun3759e472018-05-01 15:40:08 -0700178 if main.disconnectedExternalIpv6Hosts:
179 lib.verifyPing( main,
180 [ h for h in main.internalIpv6Hosts if h not in main.disconnectedIpv6Hosts ],
181 main.disconnectedExternalIpv6Hosts,
You Wang85747762018-05-11 15:51:50 -0700182 ipv6=True, expect=False,
You Wang54b1d672018-06-11 16:44:13 -0700183 stepMsg="Verify unreachability of connected internal IPv6 hosts to disconnected external IPv6 hosts",
184 t3Simple=False )
You Wang5da39c82018-04-26 22:55:08 -0700185
You Wangd66de192018-04-30 17:30:12 -0700186def verifyPing( main, ipv4=True, ipv6=True, disconnected=False, internal=True, external=True ):
You Wang5da39c82018-04-26 22:55:08 -0700187 """
188 Verify reachability and unreachability of connected/disconnected hosts
189 """
You Wangd66de192018-04-30 17:30:12 -0700190 if internal:
191 verifyPingInternal( main, ipv4, ipv6, disconnected )
192 if external:
193 verifyPingExternal( main, ipv4, ipv6, disconnected )
194
Jon Halla604fd42018-05-04 14:27:27 -0700195def verifyLinkFailure( main, ipv4=True, ipv6=True, disconnected=False,
196 internal=True, external=True, countFlowsGroups=False ):
You Wangd66de192018-04-30 17:30:12 -0700197 """
198 Kill and recover all links to spine101 and 102 sequencially and run verifications
199 """
200 from tests.USECASE.SegmentRouting.dependencies.Testcaselib import Testcaselib as lib
201 linksToRemove = [ ["spine103", "spine101"],
202 ["leaf2", "spine101"],
203 ["leaf3", "spine101"],
204 ["leaf4", "spine101"],
205 ["leaf5", "spine101"] ]
206 lib.killLinkBatch( main, linksToRemove, 30, 10 )
207 verify( main, ipv4, ipv6, disconnected, internal, external, countFlowsGroups )
208 lib.restoreLinkBatch( main, linksToRemove, 48, 10 )
209 verify( main, ipv4, ipv6, disconnected, internal, external, countFlowsGroups )
210 linksToRemove = [ ["spine104", "spine102"],
211 ["leaf2", "spine102"],
212 ["leaf3", "spine102"],
213 ["leaf4", "spine102"],
214 ["leaf5", "spine102"] ]
215 lib.killLinkBatch( main, linksToRemove, 30, 10 )
216 verify( main, ipv4, ipv6, disconnected, internal, external, countFlowsGroups )
217 lib.restoreLinkBatch( main, linksToRemove, 48, 10 )
218 verify( main, ipv4, ipv6, disconnected, internal, external, countFlowsGroups )
219
Jon Halla604fd42018-05-04 14:27:27 -0700220def verifySwitchFailure( main, ipv4=True, ipv6=True, disconnected=False,
221 internal=True, external=True, countFlowsGroups=False ):
You Wangd66de192018-04-30 17:30:12 -0700222 """
223 Kill and recover spine101 and 102 sequencially and run verifications
224 """
225 from tests.USECASE.SegmentRouting.dependencies.Testcaselib import Testcaselib as lib
226 for switchToKill in [ "spine101", "spine102" ]:
227 lib.killSwitch( main, switchToKill, 9, 30 )
228 verify( main, ipv4, ipv6, disconnected, internal, external, countFlowsGroups )
229 lib.recoverSwitch( main, switchToKill, 10, 48 )
230 verify( main, ipv4, ipv6, disconnected, internal, external, countFlowsGroups )
231
Jon Halla604fd42018-05-04 14:27:27 -0700232def verifyOnosFailure( main, ipv4=True, ipv6=True, disconnected=False,
233 internal=True, external=True, countFlowsGroups=False ):
You Wangd66de192018-04-30 17:30:12 -0700234 """
235 Kill and recover onos nodes sequencially and run verifications
236 """
237 from tests.USECASE.SegmentRouting.dependencies.Testcaselib import Testcaselib as lib
238 import json
239 import time
240
241 numCtrls = len( main.Cluster.runningNodes )
242 links = len( json.loads( main.Cluster.next().links() ) )
243 switches = len( json.loads( main.Cluster.next().devices() ) )
Jon Halla604fd42018-05-04 14:27:27 -0700244 mastershipSleep = float( main.params[ 'timers' ][ 'balanceMasterSleep' ] )
You Wangd66de192018-04-30 17:30:12 -0700245 for ctrl in xrange( numCtrls ):
246 # Kill node
247 lib.killOnos( main, [ ctrl ], switches, links, ( numCtrls - 1 ) )
248 main.Cluster.active(0).CLI.balanceMasters()
Jon Hall43060f62020-06-23 13:13:33 -0700249 main.log.debug( "sleeping %i seconds" % mastershipSleep )
Jon Halla604fd42018-05-04 14:27:27 -0700250 time.sleep( mastershipSleep )
You Wangd66de192018-04-30 17:30:12 -0700251 verify( main, ipv4, ipv6, disconnected, internal, external, countFlowsGroups )
252 # Recover node
253 lib.recoverOnos( main, [ ctrl ], switches, links, numCtrls )
254 main.Cluster.active(0).CLI.balanceMasters()
Jon Hall43060f62020-06-23 13:13:33 -0700255 main.log.debug( "sleeping %i seconds" % mastershipSleep )
Jon Halla604fd42018-05-04 14:27:27 -0700256 time.sleep( mastershipSleep )
You Wangd66de192018-04-30 17:30:12 -0700257 verify( main, ipv4, ipv6, disconnected, internal, external, countFlowsGroups )
258
259def verify( main, ipv4=True, ipv6=True, disconnected=True, internal=True, external=True, countFlowsGroups=False ):
260 """
261 Verify host IP assignment, flow/group number and pings
262 """
263 from tests.USECASE.SegmentRouting.dependencies.Testcaselib import Testcaselib as lib
264 # Verify host IP assignment
265 lib.verifyOnosHostIp( main )
266 lib.verifyNetworkHostIp( main )
267 # check flows / groups numbers
268 if countFlowsGroups:
Jon Halla604fd42018-05-04 14:27:27 -0700269 lib.checkFlowsGroupsFromFile( main )
You Wangd66de192018-04-30 17:30:12 -0700270 # ping hosts
271 verifyPing( main, ipv4, ipv6, disconnected, internal, external )
You Wang0f745de2018-07-27 15:49:22 -0700272
273def verifyRouterFailure( main, routerToKill, affectedIpv4Hosts=[], affectedIpv6Hosts=[],
274 ipv4=True, ipv6=True, countFlowsGroups=False ):
275 """
276 Kill and recover a quagga router and verify connectivities to external hosts
277 """
278 from tests.USECASE.SegmentRouting.dependencies.Testcaselib import Testcaselib as lib
279 lib.killRouter( main, routerToKill, 5 )
280 main.disconnectedExternalIpv4Hosts = affectedIpv4Hosts
281 main.disconnectedExternalIpv6Hosts = affectedIpv6Hosts
282 verify( main, ipv4, ipv6, True if (affectedIpv4Hosts or affectedIpv6Hosts) else False, False, True, countFlowsGroups )
283 lib.recoverRouter( main, routerToKill, 5 )
284 main.disconnectedExternalIpv4Hosts = []
285 main.disconnectedExternalIpv6Hosts = []
286 verify( main, ipv4, ipv6, False, False, True, countFlowsGroups )