blob: 0d7c6f82628f9cd5fcb9d7ab48100fa20e6abf86 [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
91 main.step("Verify reachability of connected internal hosts")
You Wangd66de192018-04-30 17:30:12 -070092 if ipv4:
93 lib.verifyPing( main,
94 [ h for h in main.internalIpv4Hosts if h not in main.disconnectedIpv4Hosts ],
95 [ h for h in main.internalIpv4Hosts if h not in main.disconnectedIpv4Hosts ] )
96 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 ],
100 ipv6=True, acceptableFailed=7 )
You Wang5da39c82018-04-26 22:55:08 -0700101 # Verify disconnected hosts
You Wangd66de192018-04-30 17:30:12 -0700102 if disconnected:
You Wang5da39c82018-04-26 22:55:08 -0700103 main.step("Verify unreachability of disconnected internal hosts")
You Wangd66de192018-04-30 17:30:12 -0700104 if main.disconnectedIpv4Hosts:
105 lib.verifyPing( main, main.internalIpv4Hosts, main.disconnectedIpv4Hosts, expect=False )
106 if main.disconnectedIpv6Hosts:
107 lib.verifyPing( main, main.internalIpv6Hosts, main.disconnectedIpv6Hosts, ipv6=True, expect=False )
You Wang5da39c82018-04-26 22:55:08 -0700108
You Wangd66de192018-04-30 17:30:12 -0700109def verifyPingExternal( main, ipv4=True, ipv6=True, disconnected=True ):
You Wang5da39c82018-04-26 22:55:08 -0700110 """
111 Verify all connected internal hosts are able to reach external hosts,
112 and disconnected internal hosts cannot reach any external host
113 """
114 from tests.USECASE.SegmentRouting.dependencies.Testcaselib import Testcaselib as lib
115 # Verify connected hosts
You Wang6d2d6312018-05-08 12:02:02 -0700116 main.step("Verify reachability from connected internal hosts to external hosts")
You Wangd66de192018-04-30 17:30:12 -0700117 if ipv4:
118 lib.verifyPing( main,
119 [ h for h in main.internalIpv4Hosts if h not in main.disconnectedIpv4Hosts ],
Jonghwan Hyun3759e472018-05-01 15:40:08 -0700120 [ h for h in main.externalIpv4Hosts if h not in main.disconnectedExternalIpv4Hosts ] )
You Wangd66de192018-04-30 17:30:12 -0700121 if ipv6:
122 lib.verifyPing( main,
123 [ h for h in main.internalIpv6Hosts if h not in main.disconnectedIpv6Hosts ],
Jonghwan Hyun3759e472018-05-01 15:40:08 -0700124 [ h for h in main.externalIpv6Hosts if h not in main.disconnectedExternalIpv6Hosts ],
You Wangd66de192018-04-30 17:30:12 -0700125 ipv6=True, acceptableFailed=7 )
You Wang5da39c82018-04-26 22:55:08 -0700126 # Verify disconnected hosts
You Wangd66de192018-04-30 17:30:12 -0700127 if disconnected:
You Wang5da39c82018-04-26 22:55:08 -0700128 main.step("Verify unreachability of disconnected internal hosts to external hosts")
Jonghwan Hyun3759e472018-05-01 15:40:08 -0700129 # Disconnected internal to connected external
You Wangd66de192018-04-30 17:30:12 -0700130 if main.disconnectedIpv4Hosts:
Jonghwan Hyun3759e472018-05-01 15:40:08 -0700131 lib.verifyPing( main, main.disconnectedIpv4Hosts,
132 [ h for h in main.externalIpv4Hosts if h not in main.disconnectedExternalIpv4Hosts ],
133 expect=False )
You Wangd66de192018-04-30 17:30:12 -0700134 if main.disconnectedIpv6Hosts:
Jonghwan Hyun3759e472018-05-01 15:40:08 -0700135 lib.verifyPing( main, main.disconnectedIpv6Hosts,
136 [ h for h in main.externalIpv6Hosts if h not in main.disconnectedExternalIpv6Hosts ],
137 ipv6=True, expect=False )
138 # Connected internal to disconnected external
139 if main.disconnectedExternalIpv4Hosts:
140 lib.verifyPing( main,
141 [ h for h in main.internalIpv4Hosts if h not in main.disconnectedIpv4Hosts ],
142 main.disconnectedExternalIpv4Hosts,
143 expect=False )
144 if main.disconnectedExternalIpv6Hosts:
145 lib.verifyPing( main,
146 [ h for h in main.internalIpv6Hosts if h not in main.disconnectedIpv6Hosts ],
147 main.disconnectedExternalIpv6Hosts,
148 ipv6=True, expect=False )
You Wang5da39c82018-04-26 22:55:08 -0700149
You Wangd66de192018-04-30 17:30:12 -0700150def verifyPing( main, ipv4=True, ipv6=True, disconnected=False, internal=True, external=True ):
You Wang5da39c82018-04-26 22:55:08 -0700151 """
152 Verify reachability and unreachability of connected/disconnected hosts
153 """
You Wangd66de192018-04-30 17:30:12 -0700154 if internal:
155 verifyPingInternal( main, ipv4, ipv6, disconnected )
156 if external:
157 verifyPingExternal( main, ipv4, ipv6, disconnected )
158
159def verifyLinkFailure( main, ipv4=True, ipv6=True, disconnected=False, internal=True, external=True, countFlowsGroups=False ):
160 """
161 Kill and recover all links to spine101 and 102 sequencially and run verifications
162 """
163 from tests.USECASE.SegmentRouting.dependencies.Testcaselib import Testcaselib as lib
164 linksToRemove = [ ["spine103", "spine101"],
165 ["leaf2", "spine101"],
166 ["leaf3", "spine101"],
167 ["leaf4", "spine101"],
168 ["leaf5", "spine101"] ]
169 lib.killLinkBatch( main, linksToRemove, 30, 10 )
170 verify( main, ipv4, ipv6, disconnected, internal, external, countFlowsGroups )
171 lib.restoreLinkBatch( main, linksToRemove, 48, 10 )
172 verify( main, ipv4, ipv6, disconnected, internal, external, countFlowsGroups )
173 linksToRemove = [ ["spine104", "spine102"],
174 ["leaf2", "spine102"],
175 ["leaf3", "spine102"],
176 ["leaf4", "spine102"],
177 ["leaf5", "spine102"] ]
178 lib.killLinkBatch( main, linksToRemove, 30, 10 )
179 verify( main, ipv4, ipv6, disconnected, internal, external, countFlowsGroups )
180 lib.restoreLinkBatch( main, linksToRemove, 48, 10 )
181 verify( main, ipv4, ipv6, disconnected, internal, external, countFlowsGroups )
182
183def verifySwitchFailure( main, ipv4=True, ipv6=True, disconnected=False, internal=True, external=True, countFlowsGroups=False ):
184 """
185 Kill and recover spine101 and 102 sequencially and run verifications
186 """
187 from tests.USECASE.SegmentRouting.dependencies.Testcaselib import Testcaselib as lib
188 for switchToKill in [ "spine101", "spine102" ]:
189 lib.killSwitch( main, switchToKill, 9, 30 )
190 verify( main, ipv4, ipv6, disconnected, internal, external, countFlowsGroups )
191 lib.recoverSwitch( main, switchToKill, 10, 48 )
192 verify( main, ipv4, ipv6, disconnected, internal, external, countFlowsGroups )
193
194def verifyOnosFailure( main, ipv4=True, ipv6=True, disconnected=False, internal=True, external=True, countFlowsGroups=False ):
195 """
196 Kill and recover onos nodes sequencially and run verifications
197 """
198 from tests.USECASE.SegmentRouting.dependencies.Testcaselib import Testcaselib as lib
199 import json
200 import time
201
202 numCtrls = len( main.Cluster.runningNodes )
203 links = len( json.loads( main.Cluster.next().links() ) )
204 switches = len( json.loads( main.Cluster.next().devices() ) )
205 for ctrl in xrange( numCtrls ):
206 # Kill node
207 lib.killOnos( main, [ ctrl ], switches, links, ( numCtrls - 1 ) )
208 main.Cluster.active(0).CLI.balanceMasters()
209 time.sleep( float( main.params[ 'timers' ][ 'balanceMasterSleep' ] ) )
210 verify( main, ipv4, ipv6, disconnected, internal, external, countFlowsGroups )
211 # Recover node
212 lib.recoverOnos( main, [ ctrl ], switches, links, numCtrls )
213 main.Cluster.active(0).CLI.balanceMasters()
214 time.sleep( float( main.params[ 'timers' ][ 'balanceMasterSleep' ] ) )
215 verify( main, ipv4, ipv6, disconnected, internal, external, countFlowsGroups )
216
217def verify( main, ipv4=True, ipv6=True, disconnected=True, internal=True, external=True, countFlowsGroups=False ):
218 """
219 Verify host IP assignment, flow/group number and pings
220 """
221 from tests.USECASE.SegmentRouting.dependencies.Testcaselib import Testcaselib as lib
222 # Verify host IP assignment
223 lib.verifyOnosHostIp( main )
224 lib.verifyNetworkHostIp( main )
225 # check flows / groups numbers
226 if countFlowsGroups:
227 run.checkFlowsGroupsFromFile( main )
228 # ping hosts
229 verifyPing( main, ipv4, ipv6, disconnected, internal, external )