blob: 90e8129b598014056c0701d604107e6861a47533 [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 Wangd66de192018-04-30 17:30:12 -070045 main.disconnectedIpv4Hosts = []
46 main.disconnectedIpv6Hosts = []
Jonghwan Hyun3759e472018-05-01 15:40:08 -070047 main.disconnectedExternalIpv4Hosts = [ ]
48 main.disconnectedExternalIpv6Hosts = [ ]
You Wangd66de192018-04-30 17:30:12 -070049 main.resultFileName = 'CASE%03d' % test_idx
You Wang5da39c82018-04-26 22:55:08 -070050 main.Cluster.setRunningNode( onosNodes )
You Wang5da39c82018-04-26 22:55:08 -070051
You Wangd66de192018-04-30 17:30:12 -070052 lib.installOnos( main, skipPackage=skipPackage, cliSleep=5, parallel=False )
53
54 # Load configuration files
55 main.cfgName = 'TEST_CONFIG_ipv4={}_ipv6={}_dhcp=1_routers=1{}{}'.format( 1 if ipv4 else 0,
56 1 if ipv6 else 0,
57 "_external=1" if external else "",
58 "_static=1" if static else "" )
59 lib.loadJson( main )
60 time.sleep( float( main.params[ 'timers' ][ 'loadNetcfgSleep' ] ) )
61 lib.loadHost( main )
62
63 # if static route flag add routes
64 # these routes are topology specific
65 if static:
66 if ipv4:
67 lib.addStaticOnosRoute( main, "10.0.88.0/24", "10.0.1.1")
68 if ipv6:
69 lib.addStaticOnosRoute( main, "2000::8700/120", "2000::101")
70 if countFlowsGroups:
71 lib.loadCount( main )
72
73 if hasattr( main, 'Mininet1' ):
You Wang5da39c82018-04-26 22:55:08 -070074 # Run the test with Mininet
You Wangd66de192018-04-30 17:30:12 -070075 mininet_args = ' --dhcp=1 --routers=1 --ipv6={} --ipv4={}'.format( 1 if ipv6 else 0,
76 1 if ipv4 else 0 )
77 lib.startMininet( main, main.params[ 'DEPENDENCY' ][ 'topology' ], args=mininet_args )
You Wang5da39c82018-04-26 22:55:08 -070078 time.sleep( float( main.params[ "timers" ][ "startMininetSleep" ] ) )
79 else:
80 # Run the test with physical devices
81 lib.connectToPhysicalNetwork( main, self.switchNames )
82 # Check if the devices are up
83 lib.checkDevices( main, switches=len( self.switchNames ) )
You Wang5da39c82018-04-26 22:55:08 -070084 # wait some time for onos to install the rules!
You Wangd66de192018-04-30 17:30:12 -070085 time.sleep( float( main.params[ 'timers' ][ 'dhcpSleep' ] ) )
You Wang5da39c82018-04-26 22:55:08 -070086
You Wangd66de192018-04-30 17:30:12 -070087def verifyPingInternal( main, ipv4=True, ipv6=True, disconnected=True ):
You Wang5da39c82018-04-26 22:55:08 -070088 """
89 Verify all connected internal hosts are able to reach each other,
90 and disconnected internal hosts cannot reach any other internal host
91 """
92 from tests.USECASE.SegmentRouting.dependencies.Testcaselib import Testcaselib as lib
93 # Verify connected hosts
You Wangd66de192018-04-30 17:30:12 -070094 if ipv4:
95 lib.verifyPing( main,
96 [ h for h in main.internalIpv4Hosts if h not in main.disconnectedIpv4Hosts ],
You Wang85747762018-05-11 15:51:50 -070097 [ h for h in main.internalIpv4Hosts if h not in main.disconnectedIpv4Hosts ],
98 stepMsg="Verify reachability of connected internal IPv4 hosts" )
You Wangd66de192018-04-30 17:30:12 -070099 if ipv6:
100 lib.verifyPing( main,
101 [ h for h in main.internalIpv6Hosts if h not in main.disconnectedIpv6Hosts ],
102 [ h for h in main.internalIpv6Hosts if h not in main.disconnectedIpv6Hosts ],
You Wang85747762018-05-11 15:51:50 -0700103 ipv6=True, acceptableFailed=7,
104 stepMsg="Verify reachability of connected internal IPv6 hosts" )
You Wang5da39c82018-04-26 22:55:08 -0700105 # Verify disconnected hosts
You Wangd66de192018-04-30 17:30:12 -0700106 if disconnected:
You Wangd66de192018-04-30 17:30:12 -0700107 if main.disconnectedIpv4Hosts:
You Wang85747762018-05-11 15:51:50 -0700108 lib.verifyPing( main, main.internalIpv4Hosts, main.disconnectedIpv4Hosts, expect=False,
109 stepMsg="Verify unreachability of disconnected internal IPv4 hosts" )
You Wangd66de192018-04-30 17:30:12 -0700110 if main.disconnectedIpv6Hosts:
You Wang85747762018-05-11 15:51:50 -0700111 lib.verifyPing( main, main.internalIpv6Hosts, main.disconnectedIpv6Hosts, ipv6=True, expect=False,
112 stepMsg="Verify unreachability of disconnected internal IPv6 hosts" )
You Wang5da39c82018-04-26 22:55:08 -0700113
You Wangd66de192018-04-30 17:30:12 -0700114def verifyPingExternal( main, ipv4=True, ipv6=True, disconnected=True ):
You Wang5da39c82018-04-26 22:55:08 -0700115 """
116 Verify all connected internal hosts are able to reach external hosts,
117 and disconnected internal hosts cannot reach any external host
118 """
119 from tests.USECASE.SegmentRouting.dependencies.Testcaselib import Testcaselib as lib
120 # Verify connected hosts
You Wangd66de192018-04-30 17:30:12 -0700121 if ipv4:
122 lib.verifyPing( main,
123 [ h for h in main.internalIpv4Hosts if h not in main.disconnectedIpv4Hosts ],
You Wang85747762018-05-11 15:51:50 -0700124 [ h for h in main.externalIpv4Hosts if h not in main.disconnectedExternalIpv4Hosts ],
125 stepMsg="Verify reachability from connected internal IPv4 hosts to external IPv4 hosts" )
You Wangd66de192018-04-30 17:30:12 -0700126 if ipv6:
127 lib.verifyPing( main,
128 [ h for h in main.internalIpv6Hosts if h not in main.disconnectedIpv6Hosts ],
Jonghwan Hyun3759e472018-05-01 15:40:08 -0700129 [ h for h in main.externalIpv6Hosts if h not in main.disconnectedExternalIpv6Hosts ],
You Wang85747762018-05-11 15:51:50 -0700130 ipv6=True, acceptableFailed=7,
131 stepMsg="Verify reachability from connected internal IPv6 hosts to external IPv6 hosts" )
You Wang5da39c82018-04-26 22:55:08 -0700132 # Verify disconnected hosts
You Wangd66de192018-04-30 17:30:12 -0700133 if disconnected:
Jonghwan Hyun3759e472018-05-01 15:40:08 -0700134 # Disconnected internal to connected external
You Wangd66de192018-04-30 17:30:12 -0700135 if main.disconnectedIpv4Hosts:
Jonghwan Hyun3759e472018-05-01 15:40:08 -0700136 lib.verifyPing( main, main.disconnectedIpv4Hosts,
137 [ h for h in main.externalIpv4Hosts if h not in main.disconnectedExternalIpv4Hosts ],
You Wang85747762018-05-11 15:51:50 -0700138 expect=False,
139 stepMsg="Verify unreachability of disconnected internal IPv4 hosts to connected external IPv4 hosts" )
You Wangd66de192018-04-30 17:30:12 -0700140 if main.disconnectedIpv6Hosts:
Jonghwan Hyun3759e472018-05-01 15:40:08 -0700141 lib.verifyPing( main, main.disconnectedIpv6Hosts,
142 [ h for h in main.externalIpv6Hosts if h not in main.disconnectedExternalIpv6Hosts ],
You Wang85747762018-05-11 15:51:50 -0700143 ipv6=True, expect=False,
144 stepMsg="Verify unreachability of disconnected internal IPv6 hosts to connected external IPv6 hosts" )
Jonghwan Hyun3759e472018-05-01 15:40:08 -0700145 # Connected internal to disconnected external
146 if main.disconnectedExternalIpv4Hosts:
147 lib.verifyPing( main,
148 [ h for h in main.internalIpv4Hosts if h not in main.disconnectedIpv4Hosts ],
149 main.disconnectedExternalIpv4Hosts,
You Wang85747762018-05-11 15:51:50 -0700150 expect=False,
151 stepMsg="Verify unreachability of connected internal IPv4 hosts to disconnected external IPv4 hosts" )
Jonghwan Hyun3759e472018-05-01 15:40:08 -0700152 if main.disconnectedExternalIpv6Hosts:
153 lib.verifyPing( main,
154 [ h for h in main.internalIpv6Hosts if h not in main.disconnectedIpv6Hosts ],
155 main.disconnectedExternalIpv6Hosts,
You Wang85747762018-05-11 15:51:50 -0700156 ipv6=True, expect=False,
157 stepMsg="Verify unreachability of connected internal IPv6 hosts to disconnected external IPv6 hosts" )
You Wang5da39c82018-04-26 22:55:08 -0700158
You Wangd66de192018-04-30 17:30:12 -0700159def verifyPing( main, ipv4=True, ipv6=True, disconnected=False, internal=True, external=True ):
You Wang5da39c82018-04-26 22:55:08 -0700160 """
161 Verify reachability and unreachability of connected/disconnected hosts
162 """
You Wangd66de192018-04-30 17:30:12 -0700163 if internal:
164 verifyPingInternal( main, ipv4, ipv6, disconnected )
165 if external:
166 verifyPingExternal( main, ipv4, ipv6, disconnected )
167
Jon Halla604fd42018-05-04 14:27:27 -0700168def verifyLinkFailure( main, ipv4=True, ipv6=True, disconnected=False,
169 internal=True, external=True, countFlowsGroups=False ):
You Wangd66de192018-04-30 17:30:12 -0700170 """
171 Kill and recover all links to spine101 and 102 sequencially and run verifications
172 """
173 from tests.USECASE.SegmentRouting.dependencies.Testcaselib import Testcaselib as lib
174 linksToRemove = [ ["spine103", "spine101"],
175 ["leaf2", "spine101"],
176 ["leaf3", "spine101"],
177 ["leaf4", "spine101"],
178 ["leaf5", "spine101"] ]
179 lib.killLinkBatch( main, linksToRemove, 30, 10 )
180 verify( main, ipv4, ipv6, disconnected, internal, external, countFlowsGroups )
181 lib.restoreLinkBatch( main, linksToRemove, 48, 10 )
182 verify( main, ipv4, ipv6, disconnected, internal, external, countFlowsGroups )
183 linksToRemove = [ ["spine104", "spine102"],
184 ["leaf2", "spine102"],
185 ["leaf3", "spine102"],
186 ["leaf4", "spine102"],
187 ["leaf5", "spine102"] ]
188 lib.killLinkBatch( main, linksToRemove, 30, 10 )
189 verify( main, ipv4, ipv6, disconnected, internal, external, countFlowsGroups )
190 lib.restoreLinkBatch( main, linksToRemove, 48, 10 )
191 verify( main, ipv4, ipv6, disconnected, internal, external, countFlowsGroups )
192
Jon Halla604fd42018-05-04 14:27:27 -0700193def verifySwitchFailure( main, ipv4=True, ipv6=True, disconnected=False,
194 internal=True, external=True, countFlowsGroups=False ):
You Wangd66de192018-04-30 17:30:12 -0700195 """
196 Kill and recover spine101 and 102 sequencially and run verifications
197 """
198 from tests.USECASE.SegmentRouting.dependencies.Testcaselib import Testcaselib as lib
199 for switchToKill in [ "spine101", "spine102" ]:
200 lib.killSwitch( main, switchToKill, 9, 30 )
201 verify( main, ipv4, ipv6, disconnected, internal, external, countFlowsGroups )
202 lib.recoverSwitch( main, switchToKill, 10, 48 )
203 verify( main, ipv4, ipv6, disconnected, internal, external, countFlowsGroups )
204
Jon Halla604fd42018-05-04 14:27:27 -0700205def verifyOnosFailure( main, ipv4=True, ipv6=True, disconnected=False,
206 internal=True, external=True, countFlowsGroups=False ):
You Wangd66de192018-04-30 17:30:12 -0700207 """
208 Kill and recover onos nodes sequencially and run verifications
209 """
210 from tests.USECASE.SegmentRouting.dependencies.Testcaselib import Testcaselib as lib
211 import json
212 import time
213
214 numCtrls = len( main.Cluster.runningNodes )
215 links = len( json.loads( main.Cluster.next().links() ) )
216 switches = len( json.loads( main.Cluster.next().devices() ) )
Jon Halla604fd42018-05-04 14:27:27 -0700217 mastershipSleep = float( main.params[ 'timers' ][ 'balanceMasterSleep' ] )
You Wangd66de192018-04-30 17:30:12 -0700218 for ctrl in xrange( numCtrls ):
219 # Kill node
220 lib.killOnos( main, [ ctrl ], switches, links, ( numCtrls - 1 ) )
221 main.Cluster.active(0).CLI.balanceMasters()
Jon Halla604fd42018-05-04 14:27:27 -0700222 time.sleep( mastershipSleep )
You Wangd66de192018-04-30 17:30:12 -0700223 verify( main, ipv4, ipv6, disconnected, internal, external, countFlowsGroups )
224 # Recover node
225 lib.recoverOnos( main, [ ctrl ], switches, links, numCtrls )
226 main.Cluster.active(0).CLI.balanceMasters()
Jon Halla604fd42018-05-04 14:27:27 -0700227 time.sleep( mastershipSleep )
You Wangd66de192018-04-30 17:30:12 -0700228 verify( main, ipv4, ipv6, disconnected, internal, external, countFlowsGroups )
229
230def verify( main, ipv4=True, ipv6=True, disconnected=True, internal=True, external=True, countFlowsGroups=False ):
231 """
232 Verify host IP assignment, flow/group number and pings
233 """
234 from tests.USECASE.SegmentRouting.dependencies.Testcaselib import Testcaselib as lib
235 # Verify host IP assignment
236 lib.verifyOnosHostIp( main )
237 lib.verifyNetworkHostIp( main )
238 # check flows / groups numbers
239 if countFlowsGroups:
Jon Halla604fd42018-05-04 14:27:27 -0700240 lib.checkFlowsGroupsFromFile( main )
You Wangd66de192018-04-30 17:30:12 -0700241 # ping hosts
242 verifyPing( main, ipv4, ipv6, disconnected, internal, external )