blob: a9a24bb9901950937b381273a97a41f788cf0ba3 [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
22from tests.USECASE.SegmentRouting.dependencies.Testcaselib import Testcaselib as run
Andreas Pantelopoulosf6ed5012018-02-08 21:26:01 -080023import time
Jon Hall3c910162018-03-07 14:42:16 -080024import json
Andreas Pantelopoulos90f0b102018-02-01 13:21:45 -080025
26class SRRoutingTest ():
27
28 topo = {}
29
30 def __init__( self ):
31 self.default = ''
32
33 @staticmethod
Andreas Pantelopoulos2eae3242018-03-06 13:47:20 -080034 def runTest( main, test_idx, onosNodes, dhcp, routers, ipv4, ipv6,
35 description, countFlowsGroups=False, checkExternalHost=False,
Jon Hall3c910162018-03-07 14:42:16 -080036 staticRouteConfigure=False, switchFailure=False, linkFailure=False,
37 nodeFailure=False ):
Andreas Pantelopoulos90f0b102018-02-01 13:21:45 -080038
39 skipPackage = False
40 init = False
41 if not hasattr( main, 'apps' ):
42 init = True
43 run.initTest( main )
44
45 # Skip onos packaging if the cluster size stays the same
46 if not init and onosNodes == main.Cluster.numCtrls:
47 skipPackage = True
48
Jon Hall098c0bf2018-03-23 14:15:04 -070049 main.case( '%s, ONOS cluster size: %s' % ( description, onosNodes ) )
Andreas Pantelopoulos90f0b102018-02-01 13:21:45 -080050
Andreas Pantelopoulosd5d470f2018-03-23 18:02:47 -070051 main.cfgName = 'TEST_CONFIG_ipv4=%d_ipv6=%d_dhcp=%d_routers=%d' % \
Devin Lim57221b02018-02-14 15:45:36 -080052 ( ipv4, ipv6, dhcp, routers )
You Wangba231e72018-03-01 13:18:21 -080053 if checkExternalHost:
54 main.cfgName += '_external=1'
Andreas Pantelopoulos2eae3242018-03-06 13:47:20 -080055 if staticRouteConfigure:
56 main.cfgName += '_static=1'
57
Jon Hall3c910162018-03-07 14:42:16 -080058 main.resultFileName = 'CASE%03d' % test_idx
Devin Lim57221b02018-02-14 15:45:36 -080059 main.Cluster.setRunningNode( onosNodes )
Andreas Pantelopoulos90f0b102018-02-01 13:21:45 -080060
Devin Lim57221b02018-02-14 15:45:36 -080061 run.installOnos( main, skipPackage=skipPackage, cliSleep=5,
62 parallel=False )
You Wang27317572018-03-06 12:13:11 -080063
64 # Load configuration files
Devin Lim57221b02018-02-14 15:45:36 -080065 run.loadJson( main )
66 run.loadChart( main )
You Wang86abda12018-03-09 18:10:54 -080067 run.loadHost( main )
Andreas Pantelopoulos90f0b102018-02-01 13:21:45 -080068
Andreas Pantelopoulos2eae3242018-03-06 13:47:20 -080069 # if static route flag add routes
70 # these routes are topology specific
71 if (staticRouteConfigure):
72 if (ipv4):
73 run.addStaticOnosRoute( main, "10.0.88.0/24", "10.0.1.1")
74 if (ipv6):
75 run.addStaticOnosRoute( main, "2000::8700/120", "2000::101")
76
You Wang27317572018-03-06 12:13:11 -080077 if countFlowsGroups:
Andreas Pantelopoulos9173d442018-03-01 17:07:37 -080078 run.loadCount( main )
You Wang27317572018-03-06 12:13:11 -080079 if switchFailure:
80 run.loadSwitchFailureChart( main )
Andreas Pantelopoulosfab6bf32018-03-06 18:56:35 -080081 if linkFailure:
82 run.loadLinkFailureChart( main )
Andreas Pantelopoulos9173d442018-03-01 17:07:37 -080083
You Wang27317572018-03-06 12:13:11 -080084 # wait some time
You Wang5df1c6d2018-04-06 18:02:02 -070085 time.sleep( float( main.params[ 'timers' ][ 'loadNetcfgSleep' ] ) )
Andreas Pantelopoulosf6ed5012018-02-08 21:26:01 -080086
Devin Lim57221b02018-02-14 15:45:36 -080087 if hasattr( main, 'Mininet1' ):
Andreas Pantelopoulos90f0b102018-02-01 13:21:45 -080088 # Run the test with Mininet
Devin Lim57221b02018-02-14 15:45:36 -080089 mininet_args = ' --dhcp=%s --routers=%s --ipv6=%s --ipv4=%s' % ( dhcp, routers, ipv6, ipv4 )
You Wangeb717bc2018-04-05 17:36:11 -070090 run.startMininet( main, main.params['DEPENDENCY']['topology'], args=mininet_args )
Andreas Pantelopoulos90f0b102018-02-01 13:21:45 -080091 else:
92 # Run the test with physical devices
93 # TODO: connect TestON to the physical network
94 pass
95
Andreas Pantelopoulosf6ed5012018-02-08 21:26:01 -080096 # wait some time for onos to install the rules!
You Wang5df1c6d2018-04-06 18:02:02 -070097 time.sleep( float( main.params[ 'timers' ][ 'startMininetSleep' ] ) )
Devin Lim57221b02018-02-14 15:45:36 -080098 if ( dhcp ):
You Wang5df1c6d2018-04-06 18:02:02 -070099 time.sleep( float( main.params[ 'timers' ][ 'dhcpSleep' ] ) )
Andreas Pantelopoulosf6ed5012018-02-08 21:26:01 -0800100
You Wang86abda12018-03-09 18:10:54 -0800101 SRRoutingTest.runChecks( main, test_idx, countFlowsGroups )
Andreas Pantelopoulos90f0b102018-02-01 13:21:45 -0800102
You Wang27317572018-03-06 12:13:11 -0800103 # Test switch failures
104 if switchFailure:
105 for switch, expected in main.switchFailureChart.items():
106 run.killSwitch( main, switch, expected['switches_after_failure'], expected['links_after_failure'] )
You Wang86abda12018-03-09 18:10:54 -0800107 SRRoutingTest.runChecks( main, test_idx, countFlowsGroups )
108
You Wang27317572018-03-06 12:13:11 -0800109 run.recoverSwitch( main, switch, expected['switches_before_failure'], expected['links_before_failure'] )
You Wang86abda12018-03-09 18:10:54 -0800110 SRRoutingTest.runChecks( main, test_idx, countFlowsGroups )
You Wang27317572018-03-06 12:13:11 -0800111
Andreas Pantelopoulosfab6bf32018-03-06 18:56:35 -0800112 # Test link failures
113 if linkFailure:
114 for link_batch_name, info in main.linkFailureChart.items():
115
116 linksToRemove = info['links'].values()
117 linksBefore = info['links_before']
118 linksAfter = info['links_after']
119
You Wangeb717bc2018-04-05 17:36:11 -0700120 run.killLinkBatch( main, linksToRemove, linksAfter, 10 )
You Wang86abda12018-03-09 18:10:54 -0800121 SRRoutingTest.runChecks( main, test_idx, countFlowsGroups )
Andreas Pantelopoulosfab6bf32018-03-06 18:56:35 -0800122
You Wangeb717bc2018-04-05 17:36:11 -0700123 run.restoreLinkBatch( main, linksToRemove, linksBefore, 10 )
You Wang86abda12018-03-09 18:10:54 -0800124 SRRoutingTest.runChecks( main, test_idx, countFlowsGroups )
Andreas Pantelopoulosfab6bf32018-03-06 18:56:35 -0800125
Jon Hall3c910162018-03-07 14:42:16 -0800126 # Test node failures
127 if nodeFailure:
128 numCtrls = len( main.Cluster.runningNodes )
129 links = len( json.loads( main.Cluster.next().links() ) )
130 switches = len( json.loads( main.Cluster.next().devices() ) )
131 for ctrl in xrange( numCtrls ):
Jon Halldd246642018-03-08 15:02:59 -0800132 # Kill node
Jon Hall3c910162018-03-07 14:42:16 -0800133 run.killOnos( main, [ ctrl ], switches, links, ( numCtrls - 1 ) )
134 main.Cluster.active(0).CLI.balanceMasters()
You Wang5df1c6d2018-04-06 18:02:02 -0700135 time.sleep( float( main.params[ 'timers' ][ 'balanceMasterSleep' ] ) )
You Wang86abda12018-03-09 18:10:54 -0800136 SRRoutingTest.runChecks( main, test_idx, countFlowsGroups )
Jon Hall3c910162018-03-07 14:42:16 -0800137
Jon Halldd246642018-03-08 15:02:59 -0800138 # Recover node
Jon Hall3c910162018-03-07 14:42:16 -0800139 run.recoverOnos( main, [ ctrl ], switches, links, numCtrls )
140 main.Cluster.active(0).CLI.balanceMasters()
You Wang5df1c6d2018-04-06 18:02:02 -0700141 time.sleep( float( main.params[ 'timers' ][ 'balanceMasterSleep' ] ) )
You Wang86abda12018-03-09 18:10:54 -0800142 SRRoutingTest.runChecks( main, test_idx, countFlowsGroups )
Jon Hall3c910162018-03-07 14:42:16 -0800143
144 # Cleanup
You Wang5df1c6d2018-04-06 18:02:02 -0700145 run.cleanup( main, copyKarafLog=False )
You Wang86abda12018-03-09 18:10:54 -0800146
147 @staticmethod
148 def runChecks( main, test_idx, countFlowsGroups ):
149 # Verify host IP assignment
150 run.verifyOnosHostIp( main )
151 run.verifyNetworkHostIp( main )
152 # check flows / groups numbers
153 if countFlowsGroups:
154 run.checkFlowsGroupsFromFile( main )
155 # ping hosts
You Wang5df1c6d2018-04-06 18:02:02 -0700156 run.pingAll( main, 'CASE%03d' % test_idx, False, acceptableFailed=5, basedOnIp=True, skipOnFail=True )
You Wang5da39c82018-04-26 22:55:08 -0700157
158
159def setupTest( main, test_idx, onosNodes ):
160 """
161 SRRouting test setup
162 """
163 from tests.USECASE.SegmentRouting.dependencies.Testcaselib import Testcaselib as lib
164 skipPackage = False
165 init = False
166 if not hasattr( main, 'apps' ):
167 init = True
168 run.initTest( main )
169 # Skip onos packaging if the cluster size stays the same
170 if not init and onosNodes == main.Cluster.numCtrls:
171 skipPackage = True
172
173 main.internalIpv4Hosts = main.params[ 'TOPO' ][ 'internalIpv4Hosts' ].split( ',' )
174 main.internalIpv6Hosts = main.params[ 'TOPO' ][ 'internalIpv6Hosts' ].split( ',' )
175 main.externalIpv4Hosts = main.params[ 'TOPO' ][ 'externalIpv4Hosts' ].split( ',' )
176 main.externalIpv6Hosts = main.params[ 'TOPO' ][ 'externalIpv6Hosts' ].split( ',' )
177 main.resultFileName = "CASE%03d" % test_idx
178 main.Cluster.setRunningNode( onosNodes )
179 lib.installOnos( main, skipPackage=skipPackage, cliSleep=5 )
180 # Load configuration files
181 main.step( "Load configurations" )
182 main.cfgName = "TEST_CONFIG_ipv4=1_ipv6=1_dhcp=1_routers=1_external=1"
183 lib.loadJson( main )
184 time.sleep( float( main.params[ "timers" ][ "loadNetcfgSleep" ] ) )
185
186 if hasattr( main, "Mininet1" ):
187 # Run the test with Mininet
188 mininet_args = " --dhcp=1 --routers=1 --ipv6=1 --ipv4=1"
189 lib.startMininet( main, main.params[ "DEPENDENCY" ][ "topology" ], args=mininet_args )
190 time.sleep( float( main.params[ "timers" ][ "startMininetSleep" ] ) )
191 else:
192 # Run the test with physical devices
193 lib.connectToPhysicalNetwork( main, self.switchNames )
194 # Check if the devices are up
195 lib.checkDevices( main, switches=len( self.switchNames ) )
196
197 # wait some time for onos to install the rules!
198 time.sleep( float( main.params[ "timers" ][ "startMininetSleep" ] ) )
199 time.sleep( float( main.params[ "timers" ][ "dhcpSleep" ] ) )
200
201def verifyPingInternal( main, verifyDisconnected=True ):
202 """
203 Verify all connected internal hosts are able to reach each other,
204 and disconnected internal hosts cannot reach any other internal host
205 """
206 from tests.USECASE.SegmentRouting.dependencies.Testcaselib import Testcaselib as lib
207 # Verify connected hosts
208 main.step("Verify reachability of connected internal hosts")
209 lib.verifyPing( main,
210 [ h for h in main.internalIpv4Hosts if h not in main.disconnectedIpv4Hosts ],
211 [ h for h in main.internalIpv4Hosts if h not in main.disconnectedIpv4Hosts ] )
212 lib.verifyPing( main,
213 [ h for h in main.internalIpv6Hosts if h not in main.disconnectedIpv6Hosts ],
214 [ h for h in main.internalIpv6Hosts if h not in main.disconnectedIpv6Hosts ],
215 ipv6=True, acceptableFailed=7 )
216 # Verify disconnected hosts
217 if verifyDisconnected and ( main.disconnectedIpv4Hosts or main.disconnectedIpv6Hosts ):
218 main.step("Verify unreachability of disconnected internal hosts")
219 lib.verifyPing( main, main.internalIpv4Hosts, main.disconnectedIpv4Hosts, expect=False )
220 lib.verifyPing( main, main.internalIpv6Hosts, main.disconnectedIpv6Hosts, ipv6=True, expect=False )
221
222def verifyPingExternal( main, verifyDisconnected=True ):
223 """
224 Verify all connected internal hosts are able to reach external hosts,
225 and disconnected internal hosts cannot reach any external host
226 """
227 from tests.USECASE.SegmentRouting.dependencies.Testcaselib import Testcaselib as lib
228 # Verify connected hosts
229 main.step("Verify reachability of from connected internal hosts to external hosts")
230 lib.verifyPing( main,
231 [ h for h in main.internalIpv4Hosts if h not in main.disconnectedIpv4Hosts ],
232 main.externalIpv4Hosts )
233 lib.verifyPing( main,
234 [ h for h in main.internalIpv6Hosts if h not in main.disconnectedIpv6Hosts ],
235 main.externalIpv6Hosts,
236 ipv6=True, acceptableFailed=7 )
237 # Verify disconnected hosts
238 '''
239 if verifyDisconnected and ( main.disconnectedIpv4Hosts or main.disconnectedIpv6Hosts ):
240 main.step("Verify unreachability of disconnected internal hosts to external hosts")
241 lib.verifyPing( main, main.disconnectedIpv4Hosts, main.externalIpv4Hosts, expect=False )
242 lib.verifyPing( main, main.disconnectedIpv6Hosts, main.externalIpv6Hosts, ipv6=True, expect=False )
243 '''
244
245def verifyPing( main ):
246 """
247 Verify reachability and unreachability of connected/disconnected hosts
248 """
249 verifyPingInternal( main )
250 verifyPingExternal( main )