blob: bcf97283f84391182470d2dda4eac11aaadf26f9 [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( ',' )
Siddesha2938fe2021-04-06 02:46:06 +000044 main.internalIpv6Hosts = main.params[ 'TOPO' ][ 'internalIpv6Hosts' ].split( ',' ) if main.params[ 'TOPO' ].get( 'internalIpv6Hosts' ) else []
Jon Hall9b0de1f2020-08-24 15:38:04 -070045 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" ]
Jon Hall06fd0df2021-01-25 15:50:06 -080066 if not main.persistentSetup:
Siddesha2938fe2021-04-06 02:46:06 +000067 if main.useBmv2:
68 # Translate configuration file from OVS-OFDPA to BMv2 driver
69 translator.bmv2ToOfdpa( main ) # Try to cleanup if switching between switch types
70 switchPrefix = main.params[ 'DEPENDENCY' ].get( 'switchPrefix', '' )
71 if switchPrefix is None:
72 switchPrefix = ''
73 translator.ofdpaToBmv2( main, switchPrefix=switchPrefix )
74 else:
75 translator.bmv2ToOfdpa( main )
Jon Hall06fd0df2021-01-25 15:50:06 -080076 lib.loadJson( main )
Jon Hall9b0de1f2020-08-24 15:38:04 -070077 main.log.debug( "sleeping %i seconds" % float( main.params[ 'timers' ][ 'loadNetcfgSleep' ] ) )
78 time.sleep( float( main.params[ 'timers' ][ 'loadNetcfgSleep' ] ) )
79 lib.loadHost( main )
You Wang0fc21702018-11-02 17:49:18 -070080
Jon Hall9b0de1f2020-08-24 15:38:04 -070081 # if static route flag add routes
82 # these routes are topology specific
Siddesh715a9192021-11-03 19:51:20 +000083 # these should be in the params file
Jon Hall9b0de1f2020-08-24 15:38:04 -070084 if static:
85 if ipv4:
86 lib.addStaticOnosRoute( main, "10.0.88.0/24", "10.0.1.1")
87 lib.addStaticOnosRoute( main, "10.0.88.0/24", "10.0.5.1")
88 if ipv6:
89 lib.addStaticOnosRoute( main, "2000::8700/120", "2000::101")
90 lib.addStaticOnosRoute( main, "2000::8700/120", "2000::501")
91 if countFlowsGroups:
92 lib.loadCount( main )
93
94 if hasattr( main, 'Mininet1' ):
95 lib.mnDockerSetup( main )
96 # Run the test with Mininet
97 mininet_args = ' --dhcp=1 --routers=1 --ipv6={} --ipv4={}'.format( 1 if ipv6 else 0,
98 1 if ipv4 else 0 )
99 if main.useBmv2:
100 mininet_args += ' --switch %s' % main.switchType
101 main.log.info( "Using %s switch" % main.switchType )
102 lib.startMininet( main, main.params[ 'DEPENDENCY' ][ 'topology' ], args=mininet_args )
103 main.log.debug( "Waiting %i seconds for ONOS to discover dataplane" % float( main.params[ "timers" ][ "startMininetSleep" ] ))
104 time.sleep( float( main.params[ "timers" ][ "startMininetSleep" ] ) )
105 else:
106 # Run the test with physical devices
107 lib.connectToPhysicalNetwork( main )
108
Siddesh715a9192021-11-03 19:51:20 +0000109 # lib.saveOnosDiagnostics( main )
Jon Hall9b0de1f2020-08-24 15:38:04 -0700110 # wait some time for onos to install the rules!
111 main.log.info( "Waiting %i seconds for ONOS to program the dataplane" % float( main.params[ "timers" ][ "dhcpSleep" ] ))
112 time.sleep( float( main.params[ 'timers' ][ 'dhcpSleep' ] ) )
113 except Exception as e:
114 main.log.exception( "Error in setupTest" )
115 main.skipCase( result="FAIL", msg=e )
You Wang5da39c82018-04-26 22:55:08 -0700116
You Wangd66de192018-04-30 17:30:12 -0700117def verifyPingInternal( main, ipv4=True, ipv6=True, disconnected=True ):
You Wang5da39c82018-04-26 22:55:08 -0700118 """
119 Verify all connected internal hosts are able to reach each other,
120 and disconnected internal hosts cannot reach any other internal host
121 """
122 from tests.USECASE.SegmentRouting.dependencies.Testcaselib import Testcaselib as lib
123 # Verify connected hosts
You Wangd66de192018-04-30 17:30:12 -0700124 if ipv4:
125 lib.verifyPing( main,
126 [ h for h in main.internalIpv4Hosts if h not in main.disconnectedIpv4Hosts ],
You Wang85747762018-05-11 15:51:50 -0700127 [ h for h in main.internalIpv4Hosts if h not in main.disconnectedIpv4Hosts ],
128 stepMsg="Verify reachability of connected internal IPv4 hosts" )
You Wangd66de192018-04-30 17:30:12 -0700129 if ipv6:
130 lib.verifyPing( main,
131 [ h for h in main.internalIpv6Hosts if h not in main.disconnectedIpv6Hosts ],
132 [ h for h in main.internalIpv6Hosts if h not in main.disconnectedIpv6Hosts ],
You Wang42f9e8a2018-07-11 13:25:11 -0700133 ipv6=True,
You Wang85747762018-05-11 15:51:50 -0700134 stepMsg="Verify reachability of connected internal IPv6 hosts" )
You Wang5da39c82018-04-26 22:55:08 -0700135 # Verify disconnected hosts
You Wangd66de192018-04-30 17:30:12 -0700136 if disconnected:
You Wangd66de192018-04-30 17:30:12 -0700137 if main.disconnectedIpv4Hosts:
You Wang85747762018-05-11 15:51:50 -0700138 lib.verifyPing( main, main.internalIpv4Hosts, main.disconnectedIpv4Hosts, expect=False,
139 stepMsg="Verify unreachability of disconnected internal IPv4 hosts" )
You Wangd66de192018-04-30 17:30:12 -0700140 if main.disconnectedIpv6Hosts:
You Wang85747762018-05-11 15:51:50 -0700141 lib.verifyPing( main, main.internalIpv6Hosts, main.disconnectedIpv6Hosts, ipv6=True, expect=False,
142 stepMsg="Verify unreachability of disconnected internal IPv6 hosts" )
You Wang5da39c82018-04-26 22:55:08 -0700143
You Wangd66de192018-04-30 17:30:12 -0700144def verifyPingExternal( main, ipv4=True, ipv6=True, disconnected=True ):
You Wang5da39c82018-04-26 22:55:08 -0700145 """
146 Verify all connected internal hosts are able to reach external hosts,
147 and disconnected internal hosts cannot reach any external host
148 """
149 from tests.USECASE.SegmentRouting.dependencies.Testcaselib import Testcaselib as lib
150 # Verify connected hosts
You Wangd66de192018-04-30 17:30:12 -0700151 if ipv4:
152 lib.verifyPing( main,
153 [ h for h in main.internalIpv4Hosts if h not in main.disconnectedIpv4Hosts ],
You Wang85747762018-05-11 15:51:50 -0700154 [ h for h in main.externalIpv4Hosts if h not in main.disconnectedExternalIpv4Hosts ],
You Wang54b1d672018-06-11 16:44:13 -0700155 stepMsg="Verify reachability from connected internal IPv4 hosts to external IPv4 hosts",
156 t3Simple=False )
You Wangd66de192018-04-30 17:30:12 -0700157 if ipv6:
158 lib.verifyPing( main,
159 [ h for h in main.internalIpv6Hosts if h not in main.disconnectedIpv6Hosts ],
Jonghwan Hyun3759e472018-05-01 15:40:08 -0700160 [ h for h in main.externalIpv6Hosts if h not in main.disconnectedExternalIpv6Hosts ],
You Wang42f9e8a2018-07-11 13:25:11 -0700161 ipv6=True,
You Wang54b1d672018-06-11 16:44:13 -0700162 stepMsg="Verify reachability from connected internal IPv6 hosts to external IPv6 hosts",
163 t3Simple=False )
You Wang5da39c82018-04-26 22:55:08 -0700164 # Verify disconnected hosts
You Wangd66de192018-04-30 17:30:12 -0700165 if disconnected:
Jonghwan Hyun3759e472018-05-01 15:40:08 -0700166 # Disconnected internal to connected external
You Wangd66de192018-04-30 17:30:12 -0700167 if main.disconnectedIpv4Hosts:
Jonghwan Hyun3759e472018-05-01 15:40:08 -0700168 lib.verifyPing( main, main.disconnectedIpv4Hosts,
169 [ h for h in main.externalIpv4Hosts if h not in main.disconnectedExternalIpv4Hosts ],
You Wang85747762018-05-11 15:51:50 -0700170 expect=False,
You Wang54b1d672018-06-11 16:44:13 -0700171 stepMsg="Verify unreachability of disconnected internal IPv4 hosts to connected external IPv4 hosts",
172 t3Simple=False )
You Wangd66de192018-04-30 17:30:12 -0700173 if main.disconnectedIpv6Hosts:
Jonghwan Hyun3759e472018-05-01 15:40:08 -0700174 lib.verifyPing( main, main.disconnectedIpv6Hosts,
175 [ h for h in main.externalIpv6Hosts if h not in main.disconnectedExternalIpv6Hosts ],
You Wang85747762018-05-11 15:51:50 -0700176 ipv6=True, expect=False,
You Wang54b1d672018-06-11 16:44:13 -0700177 stepMsg="Verify unreachability of disconnected internal IPv6 hosts to connected external IPv6 hosts",
178 t3Simple=False )
Jonghwan Hyun3759e472018-05-01 15:40:08 -0700179 # Connected internal to disconnected external
180 if main.disconnectedExternalIpv4Hosts:
181 lib.verifyPing( main,
182 [ h for h in main.internalIpv4Hosts if h not in main.disconnectedIpv4Hosts ],
183 main.disconnectedExternalIpv4Hosts,
You Wang85747762018-05-11 15:51:50 -0700184 expect=False,
You Wang54b1d672018-06-11 16:44:13 -0700185 stepMsg="Verify unreachability of connected internal IPv4 hosts to disconnected external IPv4 hosts",
186 t3Simple=False )
Jonghwan Hyun3759e472018-05-01 15:40:08 -0700187 if main.disconnectedExternalIpv6Hosts:
188 lib.verifyPing( main,
189 [ h for h in main.internalIpv6Hosts if h not in main.disconnectedIpv6Hosts ],
190 main.disconnectedExternalIpv6Hosts,
You Wang85747762018-05-11 15:51:50 -0700191 ipv6=True, expect=False,
You Wang54b1d672018-06-11 16:44:13 -0700192 stepMsg="Verify unreachability of connected internal IPv6 hosts to disconnected external IPv6 hosts",
193 t3Simple=False )
You Wang5da39c82018-04-26 22:55:08 -0700194
You Wangd66de192018-04-30 17:30:12 -0700195def verifyPing( main, ipv4=True, ipv6=True, disconnected=False, internal=True, external=True ):
You Wang5da39c82018-04-26 22:55:08 -0700196 """
197 Verify reachability and unreachability of connected/disconnected hosts
198 """
You Wangd66de192018-04-30 17:30:12 -0700199 if internal:
200 verifyPingInternal( main, ipv4, ipv6, disconnected )
201 if external:
202 verifyPingExternal( main, ipv4, ipv6, disconnected )
203
Jon Halla604fd42018-05-04 14:27:27 -0700204def verifyLinkFailure( main, ipv4=True, ipv6=True, disconnected=False,
205 internal=True, external=True, countFlowsGroups=False ):
You Wangd66de192018-04-30 17:30:12 -0700206 """
207 Kill and recover all links to spine101 and 102 sequencially and run verifications
208 """
209 from tests.USECASE.SegmentRouting.dependencies.Testcaselib import Testcaselib as lib
210 linksToRemove = [ ["spine103", "spine101"],
211 ["leaf2", "spine101"],
212 ["leaf3", "spine101"],
213 ["leaf4", "spine101"],
214 ["leaf5", "spine101"] ]
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 linksToRemove = [ ["spine104", "spine102"],
220 ["leaf2", "spine102"],
221 ["leaf3", "spine102"],
222 ["leaf4", "spine102"],
223 ["leaf5", "spine102"] ]
224 lib.killLinkBatch( main, linksToRemove, 30, 10 )
225 verify( main, ipv4, ipv6, disconnected, internal, external, countFlowsGroups )
226 lib.restoreLinkBatch( main, linksToRemove, 48, 10 )
227 verify( main, ipv4, ipv6, disconnected, internal, external, countFlowsGroups )
228
Jon Halla604fd42018-05-04 14:27:27 -0700229def verifySwitchFailure( main, ipv4=True, ipv6=True, disconnected=False,
230 internal=True, external=True, countFlowsGroups=False ):
You Wangd66de192018-04-30 17:30:12 -0700231 """
232 Kill and recover spine101 and 102 sequencially and run verifications
233 """
234 from tests.USECASE.SegmentRouting.dependencies.Testcaselib import Testcaselib as lib
235 for switchToKill in [ "spine101", "spine102" ]:
236 lib.killSwitch( main, switchToKill, 9, 30 )
237 verify( main, ipv4, ipv6, disconnected, internal, external, countFlowsGroups )
238 lib.recoverSwitch( main, switchToKill, 10, 48 )
239 verify( main, ipv4, ipv6, disconnected, internal, external, countFlowsGroups )
240
Jon Halla604fd42018-05-04 14:27:27 -0700241def verifyOnosFailure( main, ipv4=True, ipv6=True, disconnected=False,
242 internal=True, external=True, countFlowsGroups=False ):
You Wangd66de192018-04-30 17:30:12 -0700243 """
244 Kill and recover onos nodes sequencially and run verifications
245 """
246 from tests.USECASE.SegmentRouting.dependencies.Testcaselib import Testcaselib as lib
247 import json
248 import time
249
250 numCtrls = len( main.Cluster.runningNodes )
251 links = len( json.loads( main.Cluster.next().links() ) )
252 switches = len( json.loads( main.Cluster.next().devices() ) )
Jon Halla604fd42018-05-04 14:27:27 -0700253 mastershipSleep = float( main.params[ 'timers' ][ 'balanceMasterSleep' ] )
You Wangd66de192018-04-30 17:30:12 -0700254 for ctrl in xrange( numCtrls ):
255 # Kill node
256 lib.killOnos( main, [ ctrl ], switches, links, ( numCtrls - 1 ) )
257 main.Cluster.active(0).CLI.balanceMasters()
Jon Hall43060f62020-06-23 13:13:33 -0700258 main.log.debug( "sleeping %i seconds" % mastershipSleep )
Jon Halla604fd42018-05-04 14:27:27 -0700259 time.sleep( mastershipSleep )
You Wangd66de192018-04-30 17:30:12 -0700260 verify( main, ipv4, ipv6, disconnected, internal, external, countFlowsGroups )
261 # Recover node
262 lib.recoverOnos( main, [ ctrl ], switches, links, numCtrls )
263 main.Cluster.active(0).CLI.balanceMasters()
Jon Hall43060f62020-06-23 13:13:33 -0700264 main.log.debug( "sleeping %i seconds" % mastershipSleep )
Jon Halla604fd42018-05-04 14:27:27 -0700265 time.sleep( mastershipSleep )
You Wangd66de192018-04-30 17:30:12 -0700266 verify( main, ipv4, ipv6, disconnected, internal, external, countFlowsGroups )
267
268def verify( main, ipv4=True, ipv6=True, disconnected=True, internal=True, external=True, countFlowsGroups=False ):
269 """
270 Verify host IP assignment, flow/group number and pings
271 """
272 from tests.USECASE.SegmentRouting.dependencies.Testcaselib import Testcaselib as lib
Jon Hall39570262020-11-17 12:18:19 -0800273
Siddesha2938fe2021-04-06 02:46:06 +0000274 switches = int(main.params["TOPO"][ "switchNum" ])
275 links = int( main.params["TOPO"][ "linkNum" ])
Jon Hall39570262020-11-17 12:18:19 -0800276 lib.verifyTopology( main, switches, links, len( main.Cluster.runningNodes ) )
You Wangd66de192018-04-30 17:30:12 -0700277 # check flows / groups numbers
278 if countFlowsGroups:
Jon Halla604fd42018-05-04 14:27:27 -0700279 lib.checkFlowsGroupsFromFile( main )
You Wangd66de192018-04-30 17:30:12 -0700280 # ping hosts
281 verifyPing( main, ipv4, ipv6, disconnected, internal, external )
Jon Hall39570262020-11-17 12:18:19 -0800282 # Verify host IP assignment
283 lib.verifyOnosHostIp( main )
284 lib.verifyNetworkHostIp( main )
285 # ping hosts
286 verifyPing( main, ipv4, ipv6, disconnected, internal, external )
You Wang0f745de2018-07-27 15:49:22 -0700287
288def verifyRouterFailure( main, routerToKill, affectedIpv4Hosts=[], affectedIpv6Hosts=[],
289 ipv4=True, ipv6=True, countFlowsGroups=False ):
290 """
291 Kill and recover a quagga router and verify connectivities to external hosts
292 """
293 from tests.USECASE.SegmentRouting.dependencies.Testcaselib import Testcaselib as lib
294 lib.killRouter( main, routerToKill, 5 )
295 main.disconnectedExternalIpv4Hosts = affectedIpv4Hosts
296 main.disconnectedExternalIpv6Hosts = affectedIpv6Hosts
297 verify( main, ipv4, ipv6, True if (affectedIpv4Hosts or affectedIpv6Hosts) else False, False, True, countFlowsGroups )
298 lib.recoverRouter( main, routerToKill, 5 )
299 main.disconnectedExternalIpv4Hosts = []
300 main.disconnectedExternalIpv6Hosts = []
301 verify( main, ipv4, ipv6, False, False, True, countFlowsGroups )