blob: f4b54810d0c7ccd81d5f84a483ce5be080a9ac79 [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
You Wangd66de192018-04-30 17:30:12 -070022def setupTest( main, test_idx, onosNodes, ipv4=True, ipv6=True, external=True, static=False, countFlowsGroups=False ):
You Wang5da39c82018-04-26 22:55:08 -070023 """
24 SRRouting test setup
25 """
26 from tests.USECASE.SegmentRouting.dependencies.Testcaselib import Testcaselib as lib
You Wangd66de192018-04-30 17:30:12 -070027 import time
28
You Wang5da39c82018-04-26 22:55:08 -070029 skipPackage = False
30 init = False
31 if not hasattr( main, 'apps' ):
32 init = True
You Wangd66de192018-04-30 17:30:12 -070033 lib.initTest( main )
You Wang5da39c82018-04-26 22:55:08 -070034 # Skip onos packaging if the cluster size stays the same
35 if not init and onosNodes == main.Cluster.numCtrls:
36 skipPackage = True
37
38 main.internalIpv4Hosts = main.params[ 'TOPO' ][ 'internalIpv4Hosts' ].split( ',' )
39 main.internalIpv6Hosts = main.params[ 'TOPO' ][ 'internalIpv6Hosts' ].split( ',' )
40 main.externalIpv4Hosts = main.params[ 'TOPO' ][ 'externalIpv4Hosts' ].split( ',' )
41 main.externalIpv6Hosts = main.params[ 'TOPO' ][ 'externalIpv6Hosts' ].split( ',' )
You Wangd66de192018-04-30 17:30:12 -070042 main.disconnectedIpv4Hosts = []
43 main.disconnectedIpv6Hosts = []
Jonghwan Hyun3759e472018-05-01 15:40:08 -070044 main.disconnectedExternalIpv4Hosts = [ ]
45 main.disconnectedExternalIpv6Hosts = [ ]
You Wangd66de192018-04-30 17:30:12 -070046 main.resultFileName = 'CASE%03d' % test_idx
You Wang5da39c82018-04-26 22:55:08 -070047 main.Cluster.setRunningNode( onosNodes )
You Wang5da39c82018-04-26 22:55:08 -070048
You Wangd66de192018-04-30 17:30:12 -070049 lib.installOnos( main, skipPackage=skipPackage, cliSleep=5, parallel=False )
50
51 # Load configuration files
52 main.cfgName = 'TEST_CONFIG_ipv4={}_ipv6={}_dhcp=1_routers=1{}{}'.format( 1 if ipv4 else 0,
53 1 if ipv6 else 0,
54 "_external=1" if external else "",
55 "_static=1" if static else "" )
56 lib.loadJson( main )
57 time.sleep( float( main.params[ 'timers' ][ 'loadNetcfgSleep' ] ) )
58 lib.loadHost( main )
59
60 # if static route flag add routes
61 # these routes are topology specific
62 if static:
63 if ipv4:
64 lib.addStaticOnosRoute( main, "10.0.88.0/24", "10.0.1.1")
65 if ipv6:
66 lib.addStaticOnosRoute( main, "2000::8700/120", "2000::101")
67 if countFlowsGroups:
68 lib.loadCount( main )
69
70 if hasattr( main, 'Mininet1' ):
You Wang5da39c82018-04-26 22:55:08 -070071 # Run the test with Mininet
You Wangd66de192018-04-30 17:30:12 -070072 mininet_args = ' --dhcp=1 --routers=1 --ipv6={} --ipv4={}'.format( 1 if ipv6 else 0,
73 1 if ipv4 else 0 )
74 lib.startMininet( main, main.params[ 'DEPENDENCY' ][ 'topology' ], args=mininet_args )
You Wang5da39c82018-04-26 22:55:08 -070075 time.sleep( float( main.params[ "timers" ][ "startMininetSleep" ] ) )
76 else:
77 # Run the test with physical devices
78 lib.connectToPhysicalNetwork( main, self.switchNames )
79 # Check if the devices are up
80 lib.checkDevices( main, switches=len( self.switchNames ) )
You Wang5da39c82018-04-26 22:55:08 -070081 # wait some time for onos to install the rules!
You Wangd66de192018-04-30 17:30:12 -070082 time.sleep( float( main.params[ 'timers' ][ 'dhcpSleep' ] ) )
You Wang5da39c82018-04-26 22:55:08 -070083
You Wangd66de192018-04-30 17:30:12 -070084def verifyPingInternal( main, ipv4=True, ipv6=True, disconnected=True ):
You Wang5da39c82018-04-26 22:55:08 -070085 """
86 Verify all connected internal hosts are able to reach each other,
87 and disconnected internal hosts cannot reach any other internal host
88 """
89 from tests.USECASE.SegmentRouting.dependencies.Testcaselib import Testcaselib as lib
90 # Verify connected hosts
You Wangd66de192018-04-30 17:30:12 -070091 if ipv4:
92 lib.verifyPing( main,
93 [ h for h in main.internalIpv4Hosts if h not in main.disconnectedIpv4Hosts ],
You Wang85747762018-05-11 15:51:50 -070094 [ h for h in main.internalIpv4Hosts if h not in main.disconnectedIpv4Hosts ],
95 stepMsg="Verify reachability of connected internal IPv4 hosts" )
You Wangd66de192018-04-30 17:30:12 -070096 if ipv6:
97 lib.verifyPing( main,
98 [ h for h in main.internalIpv6Hosts if h not in main.disconnectedIpv6Hosts ],
99 [ h for h in main.internalIpv6Hosts if h not in main.disconnectedIpv6Hosts ],
You Wang85747762018-05-11 15:51:50 -0700100 ipv6=True, acceptableFailed=7,
101 stepMsg="Verify reachability of connected internal IPv6 hosts" )
You Wang5da39c82018-04-26 22:55:08 -0700102 # Verify disconnected hosts
You Wangd66de192018-04-30 17:30:12 -0700103 if disconnected:
You Wangd66de192018-04-30 17:30:12 -0700104 if main.disconnectedIpv4Hosts:
You Wang85747762018-05-11 15:51:50 -0700105 lib.verifyPing( main, main.internalIpv4Hosts, main.disconnectedIpv4Hosts, expect=False,
106 stepMsg="Verify unreachability of disconnected internal IPv4 hosts" )
You Wangd66de192018-04-30 17:30:12 -0700107 if main.disconnectedIpv6Hosts:
You Wang85747762018-05-11 15:51:50 -0700108 lib.verifyPing( main, main.internalIpv6Hosts, main.disconnectedIpv6Hosts, ipv6=True, expect=False,
109 stepMsg="Verify unreachability of disconnected internal IPv6 hosts" )
You Wang5da39c82018-04-26 22:55:08 -0700110
You Wangd66de192018-04-30 17:30:12 -0700111def verifyPingExternal( main, ipv4=True, ipv6=True, disconnected=True ):
You Wang5da39c82018-04-26 22:55:08 -0700112 """
113 Verify all connected internal hosts are able to reach external hosts,
114 and disconnected internal hosts cannot reach any external host
115 """
116 from tests.USECASE.SegmentRouting.dependencies.Testcaselib import Testcaselib as lib
117 # Verify connected hosts
You Wangd66de192018-04-30 17:30:12 -0700118 if ipv4:
119 lib.verifyPing( main,
120 [ h for h in main.internalIpv4Hosts if h not in main.disconnectedIpv4Hosts ],
You Wang85747762018-05-11 15:51:50 -0700121 [ h for h in main.externalIpv4Hosts if h not in main.disconnectedExternalIpv4Hosts ],
122 stepMsg="Verify reachability from connected internal IPv4 hosts to external IPv4 hosts" )
You Wangd66de192018-04-30 17:30:12 -0700123 if ipv6:
124 lib.verifyPing( main,
125 [ h for h in main.internalIpv6Hosts if h not in main.disconnectedIpv6Hosts ],
Jonghwan Hyun3759e472018-05-01 15:40:08 -0700126 [ h for h in main.externalIpv6Hosts if h not in main.disconnectedExternalIpv6Hosts ],
You Wang85747762018-05-11 15:51:50 -0700127 ipv6=True, acceptableFailed=7,
128 stepMsg="Verify reachability from connected internal IPv6 hosts to external IPv6 hosts" )
You Wang5da39c82018-04-26 22:55:08 -0700129 # Verify disconnected hosts
You Wangd66de192018-04-30 17:30:12 -0700130 if disconnected:
Jonghwan Hyun3759e472018-05-01 15:40:08 -0700131 # Disconnected internal to connected external
You Wangd66de192018-04-30 17:30:12 -0700132 if main.disconnectedIpv4Hosts:
Jonghwan Hyun3759e472018-05-01 15:40:08 -0700133 lib.verifyPing( main, main.disconnectedIpv4Hosts,
134 [ h for h in main.externalIpv4Hosts if h not in main.disconnectedExternalIpv4Hosts ],
You Wang85747762018-05-11 15:51:50 -0700135 expect=False,
136 stepMsg="Verify unreachability of disconnected internal IPv4 hosts to connected external IPv4 hosts" )
You Wangd66de192018-04-30 17:30:12 -0700137 if main.disconnectedIpv6Hosts:
Jonghwan Hyun3759e472018-05-01 15:40:08 -0700138 lib.verifyPing( main, main.disconnectedIpv6Hosts,
139 [ h for h in main.externalIpv6Hosts if h not in main.disconnectedExternalIpv6Hosts ],
You Wang85747762018-05-11 15:51:50 -0700140 ipv6=True, expect=False,
141 stepMsg="Verify unreachability of disconnected internal IPv6 hosts to connected external IPv6 hosts" )
Jonghwan Hyun3759e472018-05-01 15:40:08 -0700142 # Connected internal to disconnected external
143 if main.disconnectedExternalIpv4Hosts:
144 lib.verifyPing( main,
145 [ h for h in main.internalIpv4Hosts if h not in main.disconnectedIpv4Hosts ],
146 main.disconnectedExternalIpv4Hosts,
You Wang85747762018-05-11 15:51:50 -0700147 expect=False,
148 stepMsg="Verify unreachability of connected internal IPv4 hosts to disconnected external IPv4 hosts" )
Jonghwan Hyun3759e472018-05-01 15:40:08 -0700149 if main.disconnectedExternalIpv6Hosts:
150 lib.verifyPing( main,
151 [ h for h in main.internalIpv6Hosts if h not in main.disconnectedIpv6Hosts ],
152 main.disconnectedExternalIpv6Hosts,
You Wang85747762018-05-11 15:51:50 -0700153 ipv6=True, expect=False,
154 stepMsg="Verify unreachability of connected internal IPv6 hosts to disconnected external IPv6 hosts" )
You Wang5da39c82018-04-26 22:55:08 -0700155
You Wangd66de192018-04-30 17:30:12 -0700156def verifyPing( main, ipv4=True, ipv6=True, disconnected=False, internal=True, external=True ):
You Wang5da39c82018-04-26 22:55:08 -0700157 """
158 Verify reachability and unreachability of connected/disconnected hosts
159 """
You Wangd66de192018-04-30 17:30:12 -0700160 if internal:
161 verifyPingInternal( main, ipv4, ipv6, disconnected )
162 if external:
163 verifyPingExternal( main, ipv4, ipv6, disconnected )
164
165def verifyLinkFailure( main, ipv4=True, ipv6=True, disconnected=False, internal=True, external=True, countFlowsGroups=False ):
166 """
167 Kill and recover all links to spine101 and 102 sequencially and run verifications
168 """
169 from tests.USECASE.SegmentRouting.dependencies.Testcaselib import Testcaselib as lib
170 linksToRemove = [ ["spine103", "spine101"],
171 ["leaf2", "spine101"],
172 ["leaf3", "spine101"],
173 ["leaf4", "spine101"],
174 ["leaf5", "spine101"] ]
175 lib.killLinkBatch( main, linksToRemove, 30, 10 )
176 verify( main, ipv4, ipv6, disconnected, internal, external, countFlowsGroups )
177 lib.restoreLinkBatch( main, linksToRemove, 48, 10 )
178 verify( main, ipv4, ipv6, disconnected, internal, external, countFlowsGroups )
179 linksToRemove = [ ["spine104", "spine102"],
180 ["leaf2", "spine102"],
181 ["leaf3", "spine102"],
182 ["leaf4", "spine102"],
183 ["leaf5", "spine102"] ]
184 lib.killLinkBatch( main, linksToRemove, 30, 10 )
185 verify( main, ipv4, ipv6, disconnected, internal, external, countFlowsGroups )
186 lib.restoreLinkBatch( main, linksToRemove, 48, 10 )
187 verify( main, ipv4, ipv6, disconnected, internal, external, countFlowsGroups )
188
189def verifySwitchFailure( main, ipv4=True, ipv6=True, disconnected=False, internal=True, external=True, countFlowsGroups=False ):
190 """
191 Kill and recover spine101 and 102 sequencially and run verifications
192 """
193 from tests.USECASE.SegmentRouting.dependencies.Testcaselib import Testcaselib as lib
194 for switchToKill in [ "spine101", "spine102" ]:
195 lib.killSwitch( main, switchToKill, 9, 30 )
196 verify( main, ipv4, ipv6, disconnected, internal, external, countFlowsGroups )
197 lib.recoverSwitch( main, switchToKill, 10, 48 )
198 verify( main, ipv4, ipv6, disconnected, internal, external, countFlowsGroups )
199
200def verifyOnosFailure( main, ipv4=True, ipv6=True, disconnected=False, internal=True, external=True, countFlowsGroups=False ):
201 """
202 Kill and recover onos nodes sequencially and run verifications
203 """
204 from tests.USECASE.SegmentRouting.dependencies.Testcaselib import Testcaselib as lib
205 import json
206 import time
207
208 numCtrls = len( main.Cluster.runningNodes )
209 links = len( json.loads( main.Cluster.next().links() ) )
210 switches = len( json.loads( main.Cluster.next().devices() ) )
211 for ctrl in xrange( numCtrls ):
212 # Kill node
213 lib.killOnos( main, [ ctrl ], switches, links, ( numCtrls - 1 ) )
214 main.Cluster.active(0).CLI.balanceMasters()
215 time.sleep( float( main.params[ 'timers' ][ 'balanceMasterSleep' ] ) )
216 verify( main, ipv4, ipv6, disconnected, internal, external, countFlowsGroups )
217 # Recover node
218 lib.recoverOnos( main, [ ctrl ], switches, links, numCtrls )
219 main.Cluster.active(0).CLI.balanceMasters()
220 time.sleep( float( main.params[ 'timers' ][ 'balanceMasterSleep' ] ) )
221 verify( main, ipv4, ipv6, disconnected, internal, external, countFlowsGroups )
222
223def verify( main, ipv4=True, ipv6=True, disconnected=True, internal=True, external=True, countFlowsGroups=False ):
224 """
225 Verify host IP assignment, flow/group number and pings
226 """
227 from tests.USECASE.SegmentRouting.dependencies.Testcaselib import Testcaselib as lib
228 # Verify host IP assignment
229 lib.verifyOnosHostIp( main )
230 lib.verifyNetworkHostIp( main )
231 # check flows / groups numbers
232 if countFlowsGroups:
233 run.checkFlowsGroupsFromFile( main )
234 # ping hosts
235 verifyPing( main, ipv4, ipv6, disconnected, internal, external )