blob: 0611abc29bee80ecec218e889476fc232441d478 [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 Wangd66de192018-04-30 17:30:12 -070028 import time
29
You Wang5da39c82018-04-26 22:55:08 -070030 skipPackage = False
31 init = False
32 if not hasattr( main, 'apps' ):
33 init = True
You Wangd66de192018-04-30 17:30:12 -070034 lib.initTest( main )
Jon Halla604fd42018-05-04 14:27:27 -070035 if onosNodes < 0:
36 onosNodes = main.Cluster.numCtrls
You Wang5da39c82018-04-26 22:55:08 -070037 # Skip onos packaging if the cluster size stays the same
38 if not init and onosNodes == main.Cluster.numCtrls:
39 skipPackage = True
40
41 main.internalIpv4Hosts = main.params[ 'TOPO' ][ 'internalIpv4Hosts' ].split( ',' )
42 main.internalIpv6Hosts = main.params[ 'TOPO' ][ 'internalIpv6Hosts' ].split( ',' )
43 main.externalIpv4Hosts = main.params[ 'TOPO' ][ 'externalIpv4Hosts' ].split( ',' )
44 main.externalIpv6Hosts = main.params[ 'TOPO' ][ 'externalIpv6Hosts' ].split( ',' )
You Wang4efd66b2018-06-12 14:47:26 -070045 main.staticIpv4Hosts = main.params[ 'TOPO' ][ 'staticIpv4Hosts' ].split( ',' )
46 main.staticIpv6Hosts = main.params[ 'TOPO' ][ 'staticIpv6Hosts' ].split( ',' )
You Wangd66de192018-04-30 17:30:12 -070047 main.disconnectedIpv4Hosts = []
48 main.disconnectedIpv6Hosts = []
You Wang4efd66b2018-06-12 14:47:26 -070049 main.disconnectedExternalIpv4Hosts = []
50 main.disconnectedExternalIpv6Hosts = []
51 main.disconnectedStaticIpv4Hosts = []
52 main.disconnectedStaticIpv6Hosts = []
You Wangd66de192018-04-30 17:30:12 -070053 main.resultFileName = 'CASE%03d' % test_idx
You Wang5da39c82018-04-26 22:55:08 -070054 main.Cluster.setRunningNode( onosNodes )
You Wang5da39c82018-04-26 22:55:08 -070055
You Wangd66de192018-04-30 17:30:12 -070056 lib.installOnos( main, skipPackage=skipPackage, cliSleep=5, parallel=False )
57
58 # Load configuration files
Andreas Pantelopoulos1e0665a2018-06-05 13:34:59 -070059 main.cfgName = 'TEST_CONFIG_ipv4={}_ipv6={}'.format( 1 if ipv4 else 0,
60 1 if ipv6 else 0)
You Wangd66de192018-04-30 17:30:12 -070061 lib.loadJson( main )
62 time.sleep( float( main.params[ 'timers' ][ 'loadNetcfgSleep' ] ) )
63 lib.loadHost( main )
64
65 # if static route flag add routes
66 # these routes are topology specific
67 if static:
68 if ipv4:
69 lib.addStaticOnosRoute( main, "10.0.88.0/24", "10.0.1.1")
70 if ipv6:
71 lib.addStaticOnosRoute( main, "2000::8700/120", "2000::101")
72 if countFlowsGroups:
73 lib.loadCount( main )
74
75 if hasattr( main, 'Mininet1' ):
You Wang5da39c82018-04-26 22:55:08 -070076 # Run the test with Mininet
You Wangd66de192018-04-30 17:30:12 -070077 mininet_args = ' --dhcp=1 --routers=1 --ipv6={} --ipv4={}'.format( 1 if ipv6 else 0,
78 1 if ipv4 else 0 )
79 lib.startMininet( main, main.params[ 'DEPENDENCY' ][ 'topology' ], args=mininet_args )
You Wang5da39c82018-04-26 22:55:08 -070080 time.sleep( float( main.params[ "timers" ][ "startMininetSleep" ] ) )
81 else:
82 # Run the test with physical devices
83 lib.connectToPhysicalNetwork( main, self.switchNames )
84 # Check if the devices are up
85 lib.checkDevices( main, switches=len( self.switchNames ) )
You Wang5da39c82018-04-26 22:55:08 -070086 # wait some time for onos to install the rules!
You Wangd66de192018-04-30 17:30:12 -070087 time.sleep( float( main.params[ 'timers' ][ 'dhcpSleep' ] ) )
You Wang5da39c82018-04-26 22:55:08 -070088
You Wangd66de192018-04-30 17:30:12 -070089def verifyPingInternal( main, ipv4=True, ipv6=True, disconnected=True ):
You Wang5da39c82018-04-26 22:55:08 -070090 """
91 Verify all connected internal hosts are able to reach each other,
92 and disconnected internal hosts cannot reach any other internal host
93 """
94 from tests.USECASE.SegmentRouting.dependencies.Testcaselib import Testcaselib as lib
95 # Verify connected hosts
You Wangd66de192018-04-30 17:30:12 -070096 if ipv4:
97 lib.verifyPing( main,
98 [ h for h in main.internalIpv4Hosts if h not in main.disconnectedIpv4Hosts ],
You Wang85747762018-05-11 15:51:50 -070099 [ h for h in main.internalIpv4Hosts if h not in main.disconnectedIpv4Hosts ],
100 stepMsg="Verify reachability of connected internal IPv4 hosts" )
You Wangd66de192018-04-30 17:30:12 -0700101 if ipv6:
102 lib.verifyPing( main,
103 [ h for h in main.internalIpv6Hosts if h not in main.disconnectedIpv6Hosts ],
104 [ h for h in main.internalIpv6Hosts if h not in main.disconnectedIpv6Hosts ],
You Wang42f9e8a2018-07-11 13:25:11 -0700105 ipv6=True,
You Wang85747762018-05-11 15:51:50 -0700106 stepMsg="Verify reachability of connected internal IPv6 hosts" )
You Wang5da39c82018-04-26 22:55:08 -0700107 # Verify disconnected hosts
You Wangd66de192018-04-30 17:30:12 -0700108 if disconnected:
You Wangd66de192018-04-30 17:30:12 -0700109 if main.disconnectedIpv4Hosts:
You Wang85747762018-05-11 15:51:50 -0700110 lib.verifyPing( main, main.internalIpv4Hosts, main.disconnectedIpv4Hosts, expect=False,
111 stepMsg="Verify unreachability of disconnected internal IPv4 hosts" )
You Wangd66de192018-04-30 17:30:12 -0700112 if main.disconnectedIpv6Hosts:
You Wang85747762018-05-11 15:51:50 -0700113 lib.verifyPing( main, main.internalIpv6Hosts, main.disconnectedIpv6Hosts, ipv6=True, expect=False,
114 stepMsg="Verify unreachability of disconnected internal IPv6 hosts" )
You Wang5da39c82018-04-26 22:55:08 -0700115
You Wangd66de192018-04-30 17:30:12 -0700116def verifyPingExternal( main, ipv4=True, ipv6=True, disconnected=True ):
You Wang5da39c82018-04-26 22:55:08 -0700117 """
118 Verify all connected internal hosts are able to reach external hosts,
119 and disconnected internal hosts cannot reach any external host
120 """
121 from tests.USECASE.SegmentRouting.dependencies.Testcaselib import Testcaselib as lib
122 # Verify connected hosts
You Wangd66de192018-04-30 17:30:12 -0700123 if ipv4:
124 lib.verifyPing( main,
125 [ h for h in main.internalIpv4Hosts if h not in main.disconnectedIpv4Hosts ],
You Wang85747762018-05-11 15:51:50 -0700126 [ h for h in main.externalIpv4Hosts if h not in main.disconnectedExternalIpv4Hosts ],
You Wang54b1d672018-06-11 16:44:13 -0700127 stepMsg="Verify reachability from connected internal IPv4 hosts to external IPv4 hosts",
128 t3Simple=False )
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 ],
Jonghwan Hyun3759e472018-05-01 15:40:08 -0700132 [ h for h in main.externalIpv6Hosts if h not in main.disconnectedExternalIpv6Hosts ],
You Wang42f9e8a2018-07-11 13:25:11 -0700133 ipv6=True,
You Wang54b1d672018-06-11 16:44:13 -0700134 stepMsg="Verify reachability from connected internal IPv6 hosts to external IPv6 hosts",
135 t3Simple=False )
You Wang5da39c82018-04-26 22:55:08 -0700136 # Verify disconnected hosts
You Wangd66de192018-04-30 17:30:12 -0700137 if disconnected:
Jonghwan Hyun3759e472018-05-01 15:40:08 -0700138 # Disconnected internal to connected external
You Wangd66de192018-04-30 17:30:12 -0700139 if main.disconnectedIpv4Hosts:
Jonghwan Hyun3759e472018-05-01 15:40:08 -0700140 lib.verifyPing( main, main.disconnectedIpv4Hosts,
141 [ h for h in main.externalIpv4Hosts if h not in main.disconnectedExternalIpv4Hosts ],
You Wang85747762018-05-11 15:51:50 -0700142 expect=False,
You Wang54b1d672018-06-11 16:44:13 -0700143 stepMsg="Verify unreachability of disconnected internal IPv4 hosts to connected external IPv4 hosts",
144 t3Simple=False )
You Wangd66de192018-04-30 17:30:12 -0700145 if main.disconnectedIpv6Hosts:
Jonghwan Hyun3759e472018-05-01 15:40:08 -0700146 lib.verifyPing( main, main.disconnectedIpv6Hosts,
147 [ h for h in main.externalIpv6Hosts if h not in main.disconnectedExternalIpv6Hosts ],
You Wang85747762018-05-11 15:51:50 -0700148 ipv6=True, expect=False,
You Wang54b1d672018-06-11 16:44:13 -0700149 stepMsg="Verify unreachability of disconnected internal IPv6 hosts to connected external IPv6 hosts",
150 t3Simple=False )
Jonghwan Hyun3759e472018-05-01 15:40:08 -0700151 # Connected internal to disconnected external
152 if main.disconnectedExternalIpv4Hosts:
153 lib.verifyPing( main,
154 [ h for h in main.internalIpv4Hosts if h not in main.disconnectedIpv4Hosts ],
155 main.disconnectedExternalIpv4Hosts,
You Wang85747762018-05-11 15:51:50 -0700156 expect=False,
You Wang54b1d672018-06-11 16:44:13 -0700157 stepMsg="Verify unreachability of connected internal IPv4 hosts to disconnected external IPv4 hosts",
158 t3Simple=False )
Jonghwan Hyun3759e472018-05-01 15:40:08 -0700159 if main.disconnectedExternalIpv6Hosts:
160 lib.verifyPing( main,
161 [ h for h in main.internalIpv6Hosts if h not in main.disconnectedIpv6Hosts ],
162 main.disconnectedExternalIpv6Hosts,
You Wang85747762018-05-11 15:51:50 -0700163 ipv6=True, expect=False,
You Wang54b1d672018-06-11 16:44:13 -0700164 stepMsg="Verify unreachability of connected internal IPv6 hosts to disconnected external IPv6 hosts",
165 t3Simple=False )
You Wang5da39c82018-04-26 22:55:08 -0700166
You Wangd66de192018-04-30 17:30:12 -0700167def verifyPing( main, ipv4=True, ipv6=True, disconnected=False, internal=True, external=True ):
You Wang5da39c82018-04-26 22:55:08 -0700168 """
169 Verify reachability and unreachability of connected/disconnected hosts
170 """
You Wangd66de192018-04-30 17:30:12 -0700171 if internal:
172 verifyPingInternal( main, ipv4, ipv6, disconnected )
173 if external:
174 verifyPingExternal( main, ipv4, ipv6, disconnected )
175
Jon Halla604fd42018-05-04 14:27:27 -0700176def verifyLinkFailure( main, ipv4=True, ipv6=True, disconnected=False,
177 internal=True, external=True, countFlowsGroups=False ):
You Wangd66de192018-04-30 17:30:12 -0700178 """
179 Kill and recover all links to spine101 and 102 sequencially and run verifications
180 """
181 from tests.USECASE.SegmentRouting.dependencies.Testcaselib import Testcaselib as lib
182 linksToRemove = [ ["spine103", "spine101"],
183 ["leaf2", "spine101"],
184 ["leaf3", "spine101"],
185 ["leaf4", "spine101"],
186 ["leaf5", "spine101"] ]
187 lib.killLinkBatch( main, linksToRemove, 30, 10 )
188 verify( main, ipv4, ipv6, disconnected, internal, external, countFlowsGroups )
189 lib.restoreLinkBatch( main, linksToRemove, 48, 10 )
190 verify( main, ipv4, ipv6, disconnected, internal, external, countFlowsGroups )
191 linksToRemove = [ ["spine104", "spine102"],
192 ["leaf2", "spine102"],
193 ["leaf3", "spine102"],
194 ["leaf4", "spine102"],
195 ["leaf5", "spine102"] ]
196 lib.killLinkBatch( main, linksToRemove, 30, 10 )
197 verify( main, ipv4, ipv6, disconnected, internal, external, countFlowsGroups )
198 lib.restoreLinkBatch( main, linksToRemove, 48, 10 )
199 verify( main, ipv4, ipv6, disconnected, internal, external, countFlowsGroups )
200
Jon Halla604fd42018-05-04 14:27:27 -0700201def verifySwitchFailure( main, ipv4=True, ipv6=True, disconnected=False,
202 internal=True, external=True, countFlowsGroups=False ):
You Wangd66de192018-04-30 17:30:12 -0700203 """
204 Kill and recover spine101 and 102 sequencially and run verifications
205 """
206 from tests.USECASE.SegmentRouting.dependencies.Testcaselib import Testcaselib as lib
207 for switchToKill in [ "spine101", "spine102" ]:
208 lib.killSwitch( main, switchToKill, 9, 30 )
209 verify( main, ipv4, ipv6, disconnected, internal, external, countFlowsGroups )
210 lib.recoverSwitch( main, switchToKill, 10, 48 )
211 verify( main, ipv4, ipv6, disconnected, internal, external, countFlowsGroups )
212
Jon Halla604fd42018-05-04 14:27:27 -0700213def verifyOnosFailure( main, ipv4=True, ipv6=True, disconnected=False,
214 internal=True, external=True, countFlowsGroups=False ):
You Wangd66de192018-04-30 17:30:12 -0700215 """
216 Kill and recover onos nodes sequencially and run verifications
217 """
218 from tests.USECASE.SegmentRouting.dependencies.Testcaselib import Testcaselib as lib
219 import json
220 import time
221
222 numCtrls = len( main.Cluster.runningNodes )
223 links = len( json.loads( main.Cluster.next().links() ) )
224 switches = len( json.loads( main.Cluster.next().devices() ) )
Jon Halla604fd42018-05-04 14:27:27 -0700225 mastershipSleep = float( main.params[ 'timers' ][ 'balanceMasterSleep' ] )
You Wangd66de192018-04-30 17:30:12 -0700226 for ctrl in xrange( numCtrls ):
227 # Kill node
228 lib.killOnos( main, [ ctrl ], switches, links, ( numCtrls - 1 ) )
229 main.Cluster.active(0).CLI.balanceMasters()
Jon Halla604fd42018-05-04 14:27:27 -0700230 time.sleep( mastershipSleep )
You Wangd66de192018-04-30 17:30:12 -0700231 verify( main, ipv4, ipv6, disconnected, internal, external, countFlowsGroups )
232 # Recover node
233 lib.recoverOnos( main, [ ctrl ], switches, links, numCtrls )
234 main.Cluster.active(0).CLI.balanceMasters()
Jon Halla604fd42018-05-04 14:27:27 -0700235 time.sleep( mastershipSleep )
You Wangd66de192018-04-30 17:30:12 -0700236 verify( main, ipv4, ipv6, disconnected, internal, external, countFlowsGroups )
237
238def verify( main, ipv4=True, ipv6=True, disconnected=True, internal=True, external=True, countFlowsGroups=False ):
239 """
240 Verify host IP assignment, flow/group number and pings
241 """
242 from tests.USECASE.SegmentRouting.dependencies.Testcaselib import Testcaselib as lib
243 # Verify host IP assignment
244 lib.verifyOnosHostIp( main )
245 lib.verifyNetworkHostIp( main )
246 # check flows / groups numbers
247 if countFlowsGroups:
Jon Halla604fd42018-05-04 14:27:27 -0700248 lib.checkFlowsGroupsFromFile( main )
You Wangd66de192018-04-30 17:30:12 -0700249 # ping hosts
250 verifyPing( main, ipv4, ipv6, disconnected, internal, external )