blob: 44055d30c436681f4298a76c99d261cdaf178b14 [file] [log] [blame]
Jeremy Ronquillob27ce4c2017-07-17 12:41:28 -07001"""
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -07002Copyright 2016 Open Networking Foundation ( ONF )
Jeremy Ronquillob27ce4c2017-07-17 12:41:28 -07003
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
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070011 ( at your option ) any later version.
Jeremy Ronquillob27ce4c2017-07-17 12:41:28 -070012
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"""
Jon Hall1efcb3f2016-08-23 13:42:15 -070021import os
22import imp
23import time
24import json
25import urllib
26from core import utilities
27
28
29class Testcaselib:
Pierfb719b12016-09-19 14:51:44 -070030
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070031 useSSH = True
Pierfb719b12016-09-19 14:51:44 -070032
Jon Hall1efcb3f2016-08-23 13:42:15 -070033 @staticmethod
34 def initTest( main ):
35 """
36 - Construct tests variables
37 - GIT ( optional )
38 - Checkout ONOS master branch
39 - Pull latest ONOS code
40 - Building ONOS ( optional )
41 - Install ONOS package
42 - Build ONOS package
43 """
Devin Lim58046fa2017-07-05 16:55:00 -070044 try:
45 from tests.dependencies.ONOSSetup import ONOSSetup
46 main.testSetUp = ONOSSetup()
47 except ImportError:
48 main.log.error( "ONOSSetup not found. exiting the test" )
Devin Lim44075962017-08-11 10:56:37 -070049 main.cleanAndExit()
You Wangd5873482018-01-24 12:30:00 -080050 from tests.dependencies.Network import Network
51 main.Network = Network()
Devin Lim0c972b72018-02-08 14:53:59 -080052 main.testSetUp.envSetupDescription( False )
Devin Lim58046fa2017-07-05 16:55:00 -070053 stepResult = main.FALSE
54 try:
55 main.step( "Constructing test variables" )
56 # Test variables
57 main.cellName = main.params[ 'ENV' ][ 'cellName' ]
58 main.apps = main.params[ 'ENV' ][ 'cellApps' ]
Devin Lim58046fa2017-07-05 16:55:00 -070059 main.path = os.path.dirname( main.testFile )
Devin Lim57221b02018-02-14 15:45:36 -080060 main.useCommonTopo = main.params[ 'DEPENDENCY' ][ 'useCommonTopo' ] == 'True'
61 main.topoPath = main.path + ( "/.." if main.useCommonTopo else "" ) + "/dependencies/"
62 main.useCommonConf = main.params[ 'DEPENDENCY' ][ 'useCommonConf' ] == 'True'
63 main.configPath = main.path + ( "/.." if main.useCommonConf else "" ) + "/dependencies/"
64 main.forJson = "json/"
65 main.forChart = "chart/"
66 main.forConfig = "conf/"
67 main.forHost = "host/"
You Wang27317572018-03-06 12:13:11 -080068 main.forSwitchFailure = "switchFailure/"
Andreas Pantelopoulosfab6bf32018-03-06 18:56:35 -080069 main.forLinkFailure = "linkFailure/"
You Wange24d6272018-03-27 21:18:50 -070070 main.forMulticast = "multicast/"
Devin Lim58046fa2017-07-05 16:55:00 -070071 main.topology = main.params[ 'DEPENDENCY' ][ 'topology' ]
You Wangd87b2312018-01-30 12:47:17 -080072 main.topologyLib = main.params[ 'DEPENDENCY' ][ 'lib' ] if 'lib' in main.params[ 'DEPENDENCY' ] else None
73 main.topologyConf = main.params[ 'DEPENDENCY' ][ 'conf' ] if 'conf' in main.params[ 'DEPENDENCY' ] else None
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070074 main.scale = ( main.params[ 'SCALE' ][ 'size' ] ).split( "," )
Devin Lim58046fa2017-07-05 16:55:00 -070075 main.maxNodes = int( main.params[ 'SCALE' ][ 'max' ] )
Jon Hall1efcb3f2016-08-23 13:42:15 -070076
Devin Lim0c972b72018-02-08 14:53:59 -080077 stepResult = main.testSetUp.envSetup( False )
Devin Lim58046fa2017-07-05 16:55:00 -070078 except Exception as e:
79 main.testSetUp.envSetupException( e )
Jonghwan Hyun3731d6a2017-10-19 11:59:31 -070080
Devin Lim58046fa2017-07-05 16:55:00 -070081 main.testSetUp.evnSetupConclusion( stepResult )
Jon Hall1efcb3f2016-08-23 13:42:15 -070082
Jon Hall1efcb3f2016-08-23 13:42:15 -070083 @staticmethod
Andreas Pantelopoulos90f0b102018-02-01 13:21:45 -080084 def installOnos( main, vlanCfg=True, skipPackage=False, cliSleep=10,
85 parallel=True ):
Jon Hall1efcb3f2016-08-23 13:42:15 -070086 """
87 - Set up cell
88 - Create cell file
89 - Set cell file
90 - Verify cell file
91 - Kill ONOS process
92 - Uninstall ONOS cluster
93 - Verify ONOS start up
94 - Install ONOS cluster
95 - Connect to cli
96 """
97 # main.scale[ 0 ] determines the current number of ONOS controller
You Wangd87b2312018-01-30 12:47:17 -080098 if not main.apps:
Jon Hall1efcb3f2016-08-23 13:42:15 -070099 main.log.error( "App list is empty" )
Jon Hall3c910162018-03-07 14:42:16 -0800100 main.log.info( "Cluster size: " + str( main.Cluster.numCtrls ) )
101 main.log.info( "Cluster ips: " + ', '.join( main.Cluster.getIps() ) )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700102 main.dynamicHosts = [ 'in1', 'out1' ]
You Wanga0f6ff62018-01-11 15:46:30 -0800103 main.testSetUp.ONOSSetUp( main.Cluster, newCell=True, cellName=main.cellName,
Andreas Pantelopoulos90f0b102018-02-01 13:21:45 -0800104 skipPack=skipPackage,
105 useSSH=Testcaselib.useSSH,
Devin Lim0c972b72018-02-08 14:53:59 -0800106 installParallel=parallel, includeCaseDesc=False )
Devin Lim142b5342017-07-20 15:22:39 -0700107 ready = utilities.retry( main.Cluster.active( 0 ).CLI.summary,
108 main.FALSE,
You Wang1cdc5f52017-12-19 16:47:51 -0800109 sleep=cliSleep,
Devin Lim142b5342017-07-20 15:22:39 -0700110 attempts=10 )
111 if ready:
112 ready = main.TRUE
113 utilities.assert_equals( expect=main.TRUE, actual=ready,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700114 onpass="ONOS summary command succeded",
115 onfail="ONOS summary command failed" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700116 if not ready:
117 main.log.error( "ONOS startup failed!" )
Devin Lim44075962017-08-11 10:56:37 -0700118 main.cleanAndExit()
Jon Hall1efcb3f2016-08-23 13:42:15 -0700119
Devin Lim142b5342017-07-20 15:22:39 -0700120 for ctrl in main.Cluster.active():
121 ctrl.CLI.logSet( "DEBUG", "org.onosproject.segmentrouting" )
You Wangf5f104f2018-03-30 17:09:10 -0700122 ctrl.CLI.logSet( "DEBUG", "org.onosproject.driver" )
Devin Lim142b5342017-07-20 15:22:39 -0700123 ctrl.CLI.logSet( "DEBUG", "org.onosproject.net.flowobjective.impl" )
You Wangf5f104f2018-03-30 17:09:10 -0700124 ctrl.CLI.logSet( "DEBUG", "org.onosproject.routeservice.impl" )
125 ctrl.CLI.logSet( "DEBUG", "org.onosproject.routeservice.store" )
126 ctrl.CLI.logSet( "DEBUG", "org.onosproject.routing.fpm" )
Jon Hall9677ed32018-04-24 11:16:23 -0700127 ctrl.CLI.logSet( "TRACE", "org.onosproject.events" )
128 ctrl.CLI.logSet( "DEBUG", "org.onosproject.mcast" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700129
130 @staticmethod
Andreas Pantelopoulos9173d442018-03-01 17:07:37 -0800131 def loadCount( main ):
132 with open("%s/count/%s.count" % (main.configPath, main.cfgName)) as count:
You Wang5df1c6d2018-04-06 18:02:02 -0700133 main.count = json.load(count)
Andreas Pantelopoulos9173d442018-03-01 17:07:37 -0800134
135 @staticmethod
Devin Lim57221b02018-02-14 15:45:36 -0800136 def loadJson( main ):
137 with open( "%s%s.json" % ( main.configPath + main.forJson,
138 main.cfgName ) ) as cfg:
139 main.Cluster.active( 0 ).REST.setNetCfg( json.load( cfg ) )
140
141 @staticmethod
142 def loadChart( main ):
143 try:
144 with open( "%s%s.chart" % ( main.configPath + main.forChart,
145 main.cfgName ) ) as chart:
146 main.pingChart = json.load(chart)
147 except IOError:
148 main.log.warn( "No chart file found." )
149
150 @staticmethod
151 def loadHost( main ):
152 with open( "%s%s.host" % ( main.configPath + main.forHost,
153 main.cfgName ) ) as host:
154 main.expectedHosts = json.load( host )
155
156 @staticmethod
You Wang27317572018-03-06 12:13:11 -0800157 def loadSwitchFailureChart( main ):
158 with open( "%s%s.switchFailureChart" % ( main.configPath + main.forSwitchFailure,
159 main.cfgName ) ) as sfc:
160 main.switchFailureChart = json.load( sfc )
161
162 @staticmethod
Andreas Pantelopoulosfab6bf32018-03-06 18:56:35 -0800163 def loadLinkFailureChart( main ):
164 with open( "%s%s.linkFailureChart" % ( main.configPath + main.forLinkFailure,
You Wange24d6272018-03-27 21:18:50 -0700165 main.cfgName ) ) as lfc:
166 main.linkFailureChart = json.load( lfc )
167
168 @staticmethod
169 def loadMulticastConfig( main ):
170 with open( "%s%s.multicastConfig" % ( main.configPath + main.forMulticast,
171 main.cfgName ) ) as cfg:
172 main.multicastConfig = json.load( cfg )
Andreas Pantelopoulosfab6bf32018-03-06 18:56:35 -0800173
174 @staticmethod
Jon Hall1efcb3f2016-08-23 13:42:15 -0700175 def startMininet( main, topology, args="" ):
You Wangd87b2312018-01-30 12:47:17 -0800176 copyResult = main.ONOSbench.scp( main.Mininet1,
177 main.topoPath + main.topology,
You Wang5da39c82018-04-26 22:55:08 -0700178 main.Mininet1.home + "custom",
You Wangd87b2312018-01-30 12:47:17 -0800179 direction="to" )
180 if main.topologyLib:
181 for lib in main.topologyLib.split(","):
182 copyResult = copyResult and main.ONOSbench.scp( main.Mininet1,
183 main.topoPath + lib,
You Wang5da39c82018-04-26 22:55:08 -0700184 main.Mininet1.home + "custom",
You Wangd87b2312018-01-30 12:47:17 -0800185 direction="to" )
186 if main.topologyConf:
You Wanga877ea42018-04-05 15:27:40 -0700187 import re
188 controllerIPs = [ ctrl.ipAddress for ctrl in main.Cluster.runningNodes ]
189 index = 0
You Wangd87b2312018-01-30 12:47:17 -0800190 for conf in main.topologyConf.split(","):
You Wanga877ea42018-04-05 15:27:40 -0700191 # Update zebra configurations with correct ONOS instance IP
192 if conf in [ "zebradbgp1.conf", "zebradbgp2.conf" ]:
193 ip = controllerIPs[ index ]
194 index = ( index + 1 ) % len( controllerIPs )
195 with open( main.configPath + main.forConfig + conf ) as f:
196 s = f.read()
197 s = re.sub( r"(fpm connection ip).*(port 2620)", r"\1 " + ip + r" \2", s )
198 with open( main.configPath + main.forConfig + conf, "w" ) as f:
199 f.write( s )
You Wangd87b2312018-01-30 12:47:17 -0800200 copyResult = copyResult and main.ONOSbench.scp( main.Mininet1,
Devin Lim57221b02018-02-14 15:45:36 -0800201 main.configPath + main.forConfig + conf,
You Wangd87b2312018-01-30 12:47:17 -0800202 "~/",
203 direction="to" )
204 stepResult = copyResult
205 utilities.assert_equals( expect=main.TRUE,
206 actual=stepResult,
207 onpass="Successfully copied topo files",
208 onfail="Failed to copy topo files" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700209 main.step( "Starting Mininet Topology" )
Jonghwan Hyun3731d6a2017-10-19 11:59:31 -0700210 arg = "--onos-ip=%s %s" % (",".join([ctrl.ipAddress for ctrl in main.Cluster.runningNodes]), args)
Jon Hall1efcb3f2016-08-23 13:42:15 -0700211 main.topology = topology
212 topoResult = main.Mininet1.startNet(
You Wang5da39c82018-04-26 22:55:08 -0700213 topoFile=main.Mininet1.home + "custom/" + main.topology, args=arg )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700214 stepResult = topoResult
215 utilities.assert_equals( expect=main.TRUE,
216 actual=stepResult,
217 onpass="Successfully loaded topology",
218 onfail="Failed to load topology" )
219 # Exit if topology did not load properly
220 if not topoResult:
Devin Lim44075962017-08-11 10:56:37 -0700221 main.cleanAndExit()
Jon Hall1efcb3f2016-08-23 13:42:15 -0700222
223 @staticmethod
You Wang84f981d2018-01-12 16:11:50 -0800224 def connectToPhysicalNetwork( main, switchNames ):
225 main.step( "Connecting to physical netowrk" )
226 topoResult = main.NetworkBench.connectToNet()
227 stepResult = topoResult
228 utilities.assert_equals( expect=main.TRUE,
229 actual=stepResult,
230 onpass="Successfully loaded topology",
231 onfail="Failed to load topology" )
232 # Exit if topology did not load properly
233 if not topoResult:
234 main.cleanAndExit()
235
236 main.step( "Assign switches to controllers." )
237 assignResult = main.TRUE
238 for name in switchNames:
239 assignResult = assignResult & main.NetworkBench.assignSwController( sw=name,
240 ip=main.Cluster.getIps(),
241 port='6653' )
242 utilities.assert_equals( expect=main.TRUE,
243 actual=stepResult,
244 onpass="Successfully assign switches to controllers",
245 onfail="Failed to assign switches to controllers" )
246
247 @staticmethod
You Wang5df1c6d2018-04-06 18:02:02 -0700248 def saveOnosDiagnostics( main ):
249 """
250 Get onos-diags.tar.gz and save it to the log directory.
251 suffix: suffix string of the file name. E.g. onos-diags-case1.tar.gz
252 """
253 main.log.info( "Collecting onos-diags..." )
254 main.ONOSbench.onosDiagnostics( [ctrl.ipAddress for ctrl in main.Cluster.runningNodes],
255 main.logdir,
256 "-CASE%d" % main.CurrentTestCaseNumber )
257
258 @staticmethod
Devin Lim142b5342017-07-20 15:22:39 -0700259 def config( main, cfgName ):
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700260 main.spines = []
Piera2a7e1b2016-10-04 11:51:43 -0700261
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700262 main.failures = int( main.params[ 'failures' ] )
263 main.cfgName = cfgName
Piera2a7e1b2016-10-04 11:51:43 -0700264
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700265 if main.cfgName == '2x2':
266 spine = {}
267 spine[ 'name' ] = main.params[ 'switches' ][ 'spine1' ]
268 spine[ 'dpid' ] = main.params[ 'switches' ][ 'spinedpid1' ]
269 main.spines.append( spine )
Piera2a7e1b2016-10-04 11:51:43 -0700270
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700271 spine = {}
272 spine[ 'name' ] = main.params[ 'switches' ][ 'spine2' ]
273 spine[ 'dpid' ] = main.params[ 'switches' ][ 'spinedpid2' ]
274 main.spines.append( spine )
Piera2a7e1b2016-10-04 11:51:43 -0700275
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700276 elif main.cfgName == '4x4':
277 spine = {}
278 spine[ 'name' ] = main.params[ 'switches' ][ 'spine1' ]
279 spine[ 'dpid' ] = main.params[ 'switches' ][ 'spinedpid1' ]
280 main.spines.append( spine )
Piera2a7e1b2016-10-04 11:51:43 -0700281
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700282 spine = {}
283 spine[ 'name' ] = main.params[ 'switches' ][ 'spine2' ]
284 spine[ 'dpid' ] = main.params[ 'switches' ][ 'spinedpid2' ]
285 main.spines.append( spine )
Piera2a7e1b2016-10-04 11:51:43 -0700286
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700287 spine = {}
288 spine[ 'name' ] = main.params[ 'switches' ][ 'spine3' ]
289 spine[ 'dpid' ] = main.params[ 'switches' ][ 'spinedpid3' ]
290 main.spines.append( spine )
Piera2a7e1b2016-10-04 11:51:43 -0700291
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700292 spine = {}
293 spine[ 'name' ] = main.params[ 'switches' ][ 'spine4' ]
294 spine[ 'dpid' ] = main.params[ 'switches' ][ 'spinedpid4' ]
295 main.spines.append( spine )
Piera2a7e1b2016-10-04 11:51:43 -0700296
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700297 else:
Piera2a7e1b2016-10-04 11:51:43 -0700298 main.log.error( "Configuration failed!" )
Devin Lim44075962017-08-11 10:56:37 -0700299 main.cleanAndExit()
You Wang27317572018-03-06 12:13:11 -0800300
Andreas Pantelopoulos2eae3242018-03-06 13:47:20 -0800301 @staticmethod
302 def addStaticOnosRoute( main, subnet, intf):
303 """
304 Adds an ONOS static route with the use route-add command.
305 """
306 main.step("Add static route for subnet {0} towards router interface {1}".format(subnet, intf))
307 routeResult = main.Cluster.active( 0 ).addStaticRoute(subnet, intf)
308
309 utilities.assert_equals( expect=True, actual=( not routeResult ),
310 onpass="route-add command succeeded",
311 onfail="route-add command failed")
Piera2a7e1b2016-10-04 11:51:43 -0700312
313 @staticmethod
Jonghwan Hyun76a02b72018-01-30 16:40:48 +0900314 def checkFlows( main, minFlowCount, tag="", dumpflows=True, sleep=10 ):
Jon Hall1efcb3f2016-08-23 13:42:15 -0700315 main.step(
Jon Hall3c910162018-03-07 14:42:16 -0800316 "Check whether the flow count is bigger than %s" % minFlowCount )
Jonghwan Hyun76a02b72018-01-30 16:40:48 +0900317 if tag == "":
318 tag = 'CASE%d' % main.CurrentTestCaseNumber
Devin Lim142b5342017-07-20 15:22:39 -0700319 count = utilities.retry( main.Cluster.active( 0 ).CLI.checkFlowCount,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700320 main.FALSE,
321 kwargs={ 'min': minFlowCount },
322 attempts=10,
You Wang1cdc5f52017-12-19 16:47:51 -0800323 sleep=sleep )
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700324 utilities.assertEquals(
Jon Hall1efcb3f2016-08-23 13:42:15 -0700325 expect=True,
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700326 actual=( count > 0 ),
Jon Hall1efcb3f2016-08-23 13:42:15 -0700327 onpass="Flow count looks correct: " + str( count ),
328 onfail="Flow count looks wrong: " + str( count ) )
329
330 main.step( "Check whether all flow status are ADDED" )
Devin Lim142b5342017-07-20 15:22:39 -0700331 flowCheck = utilities.retry( main.Cluster.active( 0 ).CLI.checkFlowsState,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700332 main.FALSE,
333 kwargs={ 'isPENDING': False },
Jonghwan Hyun98fb40a2018-01-04 16:16:28 -0800334 attempts=5,
You Wang1cdc5f52017-12-19 16:47:51 -0800335 sleep=sleep )
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700336 utilities.assertEquals(
Jon Hall1efcb3f2016-08-23 13:42:15 -0700337 expect=main.TRUE,
338 actual=flowCheck,
339 onpass="Flow status is correct!",
340 onfail="Flow status is wrong!" )
341 if dumpflows:
Devin Lim142b5342017-07-20 15:22:39 -0700342 main.ONOSbench.dumpONOSCmd( main.Cluster.active( 0 ).ipAddress,
Pier50f0bc62016-09-07 17:53:40 -0700343 "flows",
344 main.logdir,
Jonghwan Hyun76a02b72018-01-30 16:40:48 +0900345 tag + "_FlowsBefore" )
Devin Lim142b5342017-07-20 15:22:39 -0700346 main.ONOSbench.dumpONOSCmd( main.Cluster.active( 0 ).ipAddress,
Pier50f0bc62016-09-07 17:53:40 -0700347 "groups",
348 main.logdir,
Jonghwan Hyun76a02b72018-01-30 16:40:48 +0900349 tag + "_GroupsBefore" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700350
351 @staticmethod
Pier6a0c4de2018-03-18 16:01:30 -0700352 def checkDevices( main, switches, tag="", sleep=10 ):
353 main.step(
354 "Check whether the switches count is equal to %s" % switches )
355 if tag == "":
356 tag = 'CASE%d' % main.CurrentTestCaseNumber
357 result = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus,
358 main.FALSE,
359 kwargs={ 'numoswitch': switches},
360 attempts=10,
361 sleep=sleep )
362 utilities.assert_equals( expect=main.TRUE, actual=result,
363 onpass="Device up successful",
364 onfail="Failed to boot up devices?" )
365
366 @staticmethod
Jonghwan Hyun98fb40a2018-01-04 16:16:28 -0800367 def checkFlowsByDpid( main, dpid, minFlowCount, sleep=10 ):
368 main.step(
Jonghwan Hyuncf2345c2018-02-26 11:07:54 -0800369 " Check whether the flow count of device %s is bigger than %s" % ( dpid, minFlowCount ) )
370 count = utilities.retry( main.Cluster.active( 0 ).CLI.checkFlowAddedCount,
371 main.FALSE,
372 args=( dpid, minFlowCount ),
Jonghwan Hyun98fb40a2018-01-04 16:16:28 -0800373 attempts=5,
374 sleep=sleep )
375 utilities.assertEquals(
Jonghwan Hyuncf2345c2018-02-26 11:07:54 -0800376 expect=True,
377 actual=( count > minFlowCount ),
378 onpass="Flow count looks correct: " + str( count ),
379 onfail="Flow count looks wrong. " )
Jonghwan Hyun98fb40a2018-01-04 16:16:28 -0800380
381 @staticmethod
Jon Hall9677ed32018-04-24 11:16:23 -0700382 def checkFlowEqualityByDpid( main, dpid, flowCount, sleep=10 ):
Andreas Pantelopoulos9173d442018-03-01 17:07:37 -0800383 main.step(
384 " Check whether the flow count of device %s is equal to %s" % ( dpid, flowCount ) )
385 count = utilities.retry( main.Cluster.active( 0 ).CLI.checkFlowAddedCount,
386 main.FALSE,
Jon Hall9677ed32018-04-24 11:16:23 -0700387 args=( dpid, flowCount, False, 1 ),
Andreas Pantelopoulos9173d442018-03-01 17:07:37 -0800388 attempts=5,
389 sleep=sleep )
390
391 utilities.assertEquals(
392 expect=True,
393 actual=( int( count ) == flowCount ),
Jon Hall9677ed32018-04-24 11:16:23 -0700394 onpass="Flow count looks correct: " + str( count ) ,
395 onfail="Flow count looks wrong. found {}, should be {}.".format( count, flowCount ) )
Andreas Pantelopoulos9173d442018-03-01 17:07:37 -0800396
397 @staticmethod
398 def checkGroupEqualityByDpid( main, dpid, groupCount, sleep=10):
399 main.step(
400 " Check whether the group count of device %s is equal to %s" % ( dpid, groupCount ) )
401 count = utilities.retry( main.Cluster.active( 0 ).CLI.checkGroupAddedCount,
402 main.FALSE,
403 args=( dpid, groupCount, False, 1),
404 attempts=5,
405 sleep=sleep )
406
407 utilities.assertEquals(
408 expect=True,
409 actual=( count == groupCount ),
Jon Hall9677ed32018-04-24 11:16:23 -0700410 onpass="Group count looks correct: " + str( count ) ,
411 onfail="Group count looks wrong. found {}, should be {}.".format( count, groupCount ) )
Andreas Pantelopoulos9173d442018-03-01 17:07:37 -0800412
413 @staticmethod
Jon Hall9677ed32018-04-24 11:16:23 -0700414 def checkFlowsGroupsFromFile( main ):
Andreas Pantelopoulos9173d442018-03-01 17:07:37 -0800415
416 for dpid, values in main.count.items():
417 flowCount = values["flows"]
418 groupCount = values["groups"]
Jon Hall9677ed32018-04-24 11:16:23 -0700419 main.log.report( "Check flow count for dpid " + str( dpid ) +
420 ", should be " + str( flowCount ) )
421 Testcaselib.checkFlowEqualityByDpid( main, dpid, flowCount )
Andreas Pantelopoulos9173d442018-03-01 17:07:37 -0800422
Jon Hall9677ed32018-04-24 11:16:23 -0700423 main.log.report( "Check group count for dpid " + str( dpid ) +
424 ", should be " + str( groupCount ) )
425 Testcaselib.checkGroupEqualityByDpid( main, dpid, groupCount )
Andreas Pantelopoulos9173d442018-03-01 17:07:37 -0800426
427 return
428
429 @staticmethod
You Wang5df1c6d2018-04-06 18:02:02 -0700430 def pingAll( main, tag="", dumpflows=True, acceptableFailed=0, basedOnIp=False, sleep=10, retryAttempts=1, skipOnFail=False ):
You Wangf19d9f42018-02-23 16:34:19 -0800431 '''
You Wangba231e72018-03-01 13:18:21 -0800432 Verify connectivity between hosts according to the ping chart
433 acceptableFailed: max number of acceptable failed pings.
You Wangf19d9f42018-02-23 16:34:19 -0800434 basedOnIp: if True, run ping or ping6 based on suffix of host names
Jonghwan Hyun812c70f2018-02-16 16:33:16 -0800435 retryAttempts: the number of retry ping. Only works for IPv4 hosts.
You Wangf19d9f42018-02-23 16:34:19 -0800436 '''
You Wangba231e72018-03-01 13:18:21 -0800437 main.log.report( "Check host connectivity" )
438 main.log.debug( "Ping chart: %s" % main.pingChart )
Andreas Pantelopoulosf6ed5012018-02-08 21:26:01 -0800439 if tag == "":
440 tag = 'CASE%d' % main.CurrentTestCaseNumber
441 for entry in main.pingChart.itervalues():
You Wangba231e72018-03-01 13:18:21 -0800442 main.log.debug( "Entry in ping chart: %s" % entry )
443 expect = entry[ 'expect' ]
444 if expect == "Unidirectional":
445 # Verify ping from each src host to each dst host
446 src = entry[ 'src' ]
447 dst = entry[ 'dst' ]
448 expect = main.TRUE
449 main.step( "Verify unidirectional connectivity from %s to %s with tag %s" % ( str( src ), str( dst ), tag ) )
450 if basedOnIp:
451 if ("v4" in src[0]):
452 pa = main.Network.pingallHostsUnidirectional( src, dst, acceptableFailed=acceptableFailed )
453 utilities.assert_equals( expect=expect, actual=pa,
454 onpass="IPv4 connectivity successfully tested",
455 onfail="IPv4 connectivity failed" )
456 if ("v6" in src[0]):
457 pa = main.Network.pingallHostsUnidirectional( src, dst, ipv6=True, acceptableFailed=acceptableFailed )
458 utilities.assert_equals( expect=expect, actual=pa,
459 onpass="IPv6 connectivity successfully tested",
460 onfail="IPv6 connectivity failed" )
461 else:
462 pa = main.Network.pingallHostsUnidirectional( src, dst, acceptableFailed=acceptableFailed )
463 utilities.assert_equals( expect=expect, actual=pa,
464 onpass="IP connectivity successfully tested",
465 onfail="IP connectivity failed" )
466 else:
467 # Verify ping between each host pair
468 hosts = entry[ 'hosts' ]
469 try:
470 expect = main.TRUE if str(expect).lower() == 'true' else main.FALSE
471 except:
472 expect = main.FALSE
473 main.step( "Verify full connectivity for %s with tag %s" % ( str( hosts ), tag ) )
474 if basedOnIp:
475 if ("v4" in hosts[0]):
Jonghwan Hyun812c70f2018-02-16 16:33:16 -0800476 pa = utilities.retry( main.Network.pingallHosts,
477 main.FALSE if expect else main.TRUE,
478 args=(hosts,),
479 attempts=retryAttempts,
480 sleep=sleep )
You Wangba231e72018-03-01 13:18:21 -0800481 utilities.assert_equals( expect=expect, actual=pa,
482 onpass="IPv4 connectivity successfully tested",
483 onfail="IPv4 connectivity failed" )
484 if ("v6" in hosts[0]):
485 pa = main.Network.pingIpv6Hosts( hosts, acceptableFailed=acceptableFailed )
486 utilities.assert_equals( expect=expect, actual=pa,
487 onpass="IPv6 connectivity successfully tested",
488 onfail="IPv6 connectivity failed" )
489 else:
You Wangf19d9f42018-02-23 16:34:19 -0800490 pa = main.Network.pingallHosts( hosts )
491 utilities.assert_equals( expect=expect, actual=pa,
You Wangba231e72018-03-01 13:18:21 -0800492 onpass="IP connectivity successfully tested",
493 onfail="IP connectivity failed" )
You Wang5df1c6d2018-04-06 18:02:02 -0700494 if skipOnFail and pa != expect:
495 Testcaselib.saveOnosDiagnostics( main )
You Wang24ad2f52018-04-10 10:47:12 -0700496 Testcaselib.cleanup( main, copyKarafLog=False )
You Wang5df1c6d2018-04-06 18:02:02 -0700497 main.skipCase()
Andreas Pantelopoulosf6ed5012018-02-08 21:26:01 -0800498
499 if dumpflows:
500 main.ONOSbench.dumpONOSCmd( main.Cluster.active( 0 ).ipAddress,
501 "flows",
502 main.logdir,
503 tag + "_FlowsOn" )
504 main.ONOSbench.dumpONOSCmd( main.Cluster.active( 0 ).ipAddress,
505 "groups",
506 main.logdir,
507 tag + "_GroupsOn" )
508
509 @staticmethod
Jon Hall1efcb3f2016-08-23 13:42:15 -0700510 def killLink( main, end1, end2, switches, links ):
511 """
512 end1,end2: identify the switches, ex.: 'leaf1', 'spine1'
513 switches, links: number of expected switches and links after linkDown, ex.: '4', '6'
514 Kill a link and verify ONOS can see the proper link change
515 """
516 main.linkSleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] )
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700517 main.step( "Kill link between %s and %s" % ( end1, end2 ) )
You Wangd5873482018-01-24 12:30:00 -0800518 LinkDown = main.Network.link( END1=end1, END2=end2, OPTION="down" )
519 LinkDown = main.Network.link( END2=end1, END1=end2, OPTION="down" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700520 main.log.info(
521 "Waiting %s seconds for link down to be discovered" % main.linkSleep )
522 time.sleep( main.linkSleep )
Devin Lim142b5342017-07-20 15:22:39 -0700523 topology = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700524 main.FALSE,
525 kwargs={ 'numoswitch': switches,
526 'numolink': links },
527 attempts=10,
528 sleep=main.linkSleep )
529 result = topology & LinkDown
530 utilities.assert_equals( expect=main.TRUE, actual=result,
531 onpass="Link down successful",
532 onfail="Failed to turn off link?" )
533
534 @staticmethod
You Wangeb717bc2018-04-05 17:36:11 -0700535 def killLinkBatch( main, links, linksAfter, switches ):
Andreas Pantelopoulosfab6bf32018-03-06 18:56:35 -0800536 """
537 links = list of links (src, dst) to bring down.
538 """
539
540 main.step("Killing a batch of links {0}".format(links))
541
542 for end1, end2 in links:
543 main.Network.link( END1=end1, END2=end2, OPTION="down")
544 main.Network.link( END1=end2, END2=end1, OPTION="down")
545
546 main.linkSleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] )
547 main.log.info(
548 "Waiting %s seconds for links down to be discovered" % main.linkSleep )
549 time.sleep( main.linkSleep )
550
551 topology = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus,
552 main.FALSE,
553 kwargs={ 'numoswitch': switches,
554 'numolink': linksAfter },
555 attempts=10,
556 sleep=main.linkSleep )
557
You Wang2854bce2018-03-30 10:15:32 -0700558 utilities.assert_equals( expect=main.TRUE, actual=topology,
559 onpass="Link batch down successful",
560 onfail="Link batch down failed" )
561
Andreas Pantelopoulosfab6bf32018-03-06 18:56:35 -0800562 @staticmethod
You Wangeb717bc2018-04-05 17:36:11 -0700563 def restoreLinkBatch( main, links, linksAfter, switches ):
Andreas Pantelopoulosfab6bf32018-03-06 18:56:35 -0800564 """
565 links = list of link (src, dst) to bring up again.
566 """
567
568 main.step("Restoring a batch of links {0}".format(links))
569
570 for end1, end2 in links:
571 main.Network.link( END1=end1, END2=end2, OPTION="up")
572 main.Network.link( END1=end2, END2=end1, OPTION="up")
573
574 main.linkSleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] )
575 main.log.info(
576 "Waiting %s seconds for links down to be discovered" % main.linkSleep )
577 time.sleep( main.linkSleep )
578
579 topology = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus,
580 main.FALSE,
581 kwargs={ 'numoswitch': switches,
582 'numolink': linksAfter },
583 attempts=10,
584 sleep=main.linkSleep )
585
You Wang2854bce2018-03-30 10:15:32 -0700586 utilities.assert_equals( expect=main.TRUE, actual=topology,
587 onpass="Link batch up successful",
588 onfail="Link batch up failed" )
589
Andreas Pantelopoulosfab6bf32018-03-06 18:56:35 -0800590 @staticmethod
You Wangc02d8352018-04-17 16:42:10 -0700591 def restoreLink( main, end1, end2, switches, links,
592 portUp=False, dpid1='', dpid2='', port1='', port2='' ):
Jon Hall1efcb3f2016-08-23 13:42:15 -0700593 """
594 Params:
595 end1,end2: identify the end switches, ex.: 'leaf1', 'spine1'
You Wangc02d8352018-04-17 16:42:10 -0700596 portUp: enable portstate after restoring link
Jon Hall1efcb3f2016-08-23 13:42:15 -0700597 dpid1, dpid2: dpid of the end switches respectively, ex.: 'of:0000000000000002'
598 port1, port2: respective port of the end switches that connects to the link, ex.:'1'
599 switches, links: number of expected switches and links after linkDown, ex.: '4', '6'
600 Kill a link and verify ONOS can see the proper link change
601 """
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700602 main.step( "Restore link between %s and %s" % ( end1, end2 ) )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700603 result = False
604 count = 0
605 while True:
606 count += 1
You Wangd5873482018-01-24 12:30:00 -0800607 main.Network.link( END1=end1, END2=end2, OPTION="up" )
608 main.Network.link( END2=end1, END1=end2, OPTION="up" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700609 main.log.info(
610 "Waiting %s seconds for link up to be discovered" % main.linkSleep )
611 time.sleep( main.linkSleep )
Pierfb719b12016-09-19 14:51:44 -0700612
You Wangc02d8352018-04-17 16:42:10 -0700613 if portUp:
614 ctrl.CLI.portstate( dpid=dpid1, port=port1, state='Enable' )
615 ctrl.CLI.portstate( dpid=dpid2, port=port2, state='Enable' )
616 time.sleep( main.linkSleep )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700617
Devin Lim142b5342017-07-20 15:22:39 -0700618 result = main.Cluster.active( 0 ).CLI.checkStatus( numoswitch=switches,
619 numolink=links )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700620 if count > 5 or result:
621 break
622 utilities.assert_equals( expect=main.TRUE, actual=result,
623 onpass="Link up successful",
624 onfail="Failed to bring link up" )
625
626 @staticmethod
627 def killSwitch( main, switch, switches, links ):
628 """
629 Params: switches, links: number of expected switches and links after SwitchDown, ex.: '4', '6'
630 Completely kill a switch and verify ONOS can see the proper change
631 """
632 main.switchSleep = float( main.params[ 'timers' ][ 'SwitchDiscovery' ] )
You Wangc02d8352018-04-17 16:42:10 -0700633 switch = switch if isinstance( switch, list ) else [ switch ]
634 main.step( "Kill " + str( switch ) )
635 for s in switch:
636 main.log.info( "Stopping " + s )
637 main.Network.switch( SW=s, OPTION="stop" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700638 # todo make this repeatable
639 main.log.info( "Waiting %s seconds for switch down to be discovered" % (
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700640 main.switchSleep ) )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700641 time.sleep( main.switchSleep )
Devin Lim142b5342017-07-20 15:22:39 -0700642 topology = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700643 main.FALSE,
644 kwargs={ 'numoswitch': switches,
645 'numolink': links },
646 attempts=10,
647 sleep=main.switchSleep )
648 utilities.assert_equals( expect=main.TRUE, actual=topology,
649 onpass="Kill switch successful",
650 onfail="Failed to kill switch?" )
651
652 @staticmethod
You Wangac363b92018-05-05 00:01:07 +0000653 def recoverSwitch( main, switch, switches, links, rediscoverHosts=False ):
Jon Hall1efcb3f2016-08-23 13:42:15 -0700654 """
655 Params: switches, links: number of expected switches and links after SwitchUp, ex.: '4', '6'
656 Recover a switch and verify ONOS can see the proper change
657 """
658 # todo make this repeatable
You Wangc02d8352018-04-17 16:42:10 -0700659 switch = switch if isinstance( switch, list ) else [ switch ]
660 main.step( "Recovering " + str( switch ) )
661 for s in switch:
662 main.log.info( "Starting " + s )
663 main.Network.switch( SW=s, OPTION="start" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700664 main.log.info( "Waiting %s seconds for switch up to be discovered" % (
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700665 main.switchSleep ) )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700666 time.sleep( main.switchSleep )
Andreas Pantelopoulos74c7ff22018-05-01 15:42:02 -0700667 if rediscoverHosts:
668 main.Network.discoverIpv4Hosts( main.internalIpv4Hosts )
669 main.Network.discoverIpv6Hosts( main.internalIpv6Hosts )
670 main.log.info( "Waiting %s seconds for hosts to get re-discovered" % (
671 main.switchSleep ) )
672 time.sleep( main.switchSleep )
673
Devin Lim142b5342017-07-20 15:22:39 -0700674 topology = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700675 main.FALSE,
676 kwargs={ 'numoswitch': switches,
677 'numolink': links },
678 attempts=10,
679 sleep=main.switchSleep )
680 utilities.assert_equals( expect=main.TRUE, actual=topology,
681 onpass="Switch recovery successful",
682 onfail="Failed to recover switch?" )
683
You Wangc02d8352018-04-17 16:42:10 -0700684 def portstate( main, dpid, port, state, switches, links ):
685 """
686 Disable/enable a switch port using 'portstate' and verify ONOS can see the proper link change
687 Params:
688 dpid: dpid of the switch, ex.: 'of:0000000000000002'
689 port: port of the switch to disable/enable, ex.:'1'
690 state: disable or enable
691 switches, links: number of expected switches and links after link change, ex.: '4', '6'
692 """
693 main.step( "Port %s on %s:%s" % ( state, dpid, port ) )
694 main.Cluster.active( 0 ).CLI.portstate( dpid=dpid, port=port, state=state )
695 main.log.info( "Waiting %s seconds for port %s to be discovered" % ( main.linkSleep, state ) )
696 time.sleep( main.linkSleep )
697 result = main.Cluster.active( 0 ).CLI.checkStatus( numoswitch=switches,
698 numolink=links )
699 utilities.assert_equals( expect=main.TRUE, actual=result,
700 onpass="Port %s successful" % state,
701 onfail="Port %s failed" % state )
702
Jon Hall1efcb3f2016-08-23 13:42:15 -0700703 @staticmethod
You Wang5da39c82018-04-26 22:55:08 -0700704 def cleanup( main, copyKarafLog=True, removeHostComponent=False ):
Jon Hall1efcb3f2016-08-23 13:42:15 -0700705 """
706 Stop Onos-cluster.
707 Stops Mininet
708 Copies ONOS log
709 """
Devin Lim58046fa2017-07-05 16:55:00 -0700710 try:
711 from tests.dependencies.utils import Utils
712 except ImportError:
713 main.log.error( "Utils not found exiting the test" )
Devin Lim44075962017-08-11 10:56:37 -0700714 main.cleanAndExit()
Devin Lim58046fa2017-07-05 16:55:00 -0700715 try:
Devin Lim142b5342017-07-20 15:22:39 -0700716 main.utils
Devin Lim58046fa2017-07-05 16:55:00 -0700717 except ( NameError, AttributeError ):
Devin Lim142b5342017-07-20 15:22:39 -0700718 main.utils = Utils()
Devin Lim58046fa2017-07-05 16:55:00 -0700719
You Wange24d6272018-03-27 21:18:50 -0700720 if hasattr( main, "scapyHosts" ):
721 scapyResult = main.TRUE
722 for host in main.scapyHosts:
723 scapyResult = host.stopScapy() and scapyResult
724 main.log.info( "Stopped Scapy Host: {0}".format( host.name ) )
725 for host in main.scapyHosts:
726 scapyResult = main.Scapy.removeHostComponent( host.name ) and scapyResult
727 main.log.info( "Removed Scapy Host Component: {0}".format( host.name ) )
728 main.scapyHosts = []
729
You Wang5da39c82018-04-26 22:55:08 -0700730 if removeHostComponent:
731 for host in main.internalIpv4Hosts + main.internalIpv6Hosts + main.externalIpv4Hosts + main.externalIpv6Hosts:
732 if hasattr( main, host ):
733 main.Network.removeHostComponent( host )
734
You Wang5df1c6d2018-04-06 18:02:02 -0700735 if hasattr( main, 'Mininet1' ):
Pier6a0c4de2018-03-18 16:01:30 -0700736 main.utils.mininetCleanup( main.Mininet1 )
Devin Lim58046fa2017-07-05 16:55:00 -0700737
You Wang5df1c6d2018-04-06 18:02:02 -0700738 if copyKarafLog:
739 main.utils.copyKarafLog( "CASE%d" % main.CurrentTestCaseNumber, before=True, includeCaseDesc=False )
Devin Lim58046fa2017-07-05 16:55:00 -0700740
Devin Lim142b5342017-07-20 15:22:39 -0700741 for ctrl in main.Cluster.active():
742 main.ONOSbench.onosStop( ctrl.ipAddress )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700743
744 @staticmethod
745 def killOnos( main, nodes, switches, links, expNodes ):
746 """
747 Params: nodes, integer array with position of the ONOS nodes in the CLIs array
748 switches, links, nodes: number of expected switches, links and nodes after KillOnos, ex.: '4', '6'
749 Completely Kill an ONOS instance and verify the ONOS cluster can see the proper change
750 """
Jon Hall3c910162018-03-07 14:42:16 -0800751 main.step( "Killing ONOS instances with index(es): {}".format( nodes ) )
You Wang5df1c6d2018-04-06 18:02:02 -0700752 main.onosSleep = float( main.params[ 'timers' ][ 'OnosDiscovery' ] )
Pier3b58c652016-09-26 12:03:31 -0700753
Jon Hall1efcb3f2016-08-23 13:42:15 -0700754 for i in nodes:
Devin Lim142b5342017-07-20 15:22:39 -0700755 killResult = main.ONOSbench.onosDie( main.Cluster.runningNodes[ i ].ipAddress )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700756 utilities.assert_equals( expect=main.TRUE, actual=killResult,
757 onpass="ONOS instance Killed",
758 onfail="Error killing ONOS instance" )
Devin Lim142b5342017-07-20 15:22:39 -0700759 main.Cluster.runningNodes[ i ].active = False
You Wang5df1c6d2018-04-06 18:02:02 -0700760 time.sleep( main.onosSleep )
Pier3b58c652016-09-26 12:03:31 -0700761
Devin Lim142b5342017-07-20 15:22:39 -0700762 if len( nodes ) < main.Cluster.numCtrls:
Pier3b58c652016-09-26 12:03:31 -0700763
Jonghwan Hyun3731d6a2017-10-19 11:59:31 -0700764 nodeResults = utilities.retry( main.Cluster.nodesCheck,
Pier3b58c652016-09-26 12:03:31 -0700765 False,
Jon Hall9677ed32018-04-24 11:16:23 -0700766 attempts=10,
Pier3b58c652016-09-26 12:03:31 -0700767 sleep=10 )
768 utilities.assert_equals( expect=True, actual=nodeResults,
769 onpass="Nodes check successful",
770 onfail="Nodes check NOT successful" )
771
772 if not nodeResults:
773 for i in nodes:
Devin Lim142b5342017-07-20 15:22:39 -0700774 ctrl = main.Cluster.runningNodes[ i ]
Pier3b58c652016-09-26 12:03:31 -0700775 main.log.debug( "{} components not ACTIVE: \n{}".format(
Devin Lim142b5342017-07-20 15:22:39 -0700776 ctrl.name,
777 ctrl.CLI.sendline( "scr:list | grep -v ACTIVE" ) ) )
Pier3b58c652016-09-26 12:03:31 -0700778 main.log.error( "Failed to kill ONOS, stopping test" )
Devin Lim44075962017-08-11 10:56:37 -0700779 main.cleanAndExit()
Pier3b58c652016-09-26 12:03:31 -0700780
Jonghwan Hyun76a02b72018-01-30 16:40:48 +0900781 topology = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700782 main.FALSE,
783 kwargs={ 'numoswitch': switches,
784 'numolink': links,
785 'numoctrl': expNodes },
786 attempts=10,
787 sleep=12 )
788 utilities.assert_equals( expect=main.TRUE, actual=topology,
789 onpass="ONOS Instance down successful",
790 onfail="Failed to turn off ONOS Instance" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700791
792 @staticmethod
793 def recoverOnos( main, nodes, switches, links, expNodes ):
794 """
795 Params: nodes, integer array with position of the ONOS nodes in the CLIs array
796 switches, links, nodes: number of expected switches, links and nodes after recoverOnos, ex.: '4', '6'
797 Recover an ONOS instance and verify the ONOS cluster can see the proper change
798 """
Jon Hall3c910162018-03-07 14:42:16 -0800799 main.step( "Recovering ONOS instances with index(es): {}".format( nodes ) )
Devin Lim142b5342017-07-20 15:22:39 -0700800 [ main.ONOSbench.onosStart( main.Cluster.runningNodes[ i ].ipAddress ) for i in nodes ]
You Wang5df1c6d2018-04-06 18:02:02 -0700801 time.sleep( main.onosSleep )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700802 for i in nodes:
Devin Lim142b5342017-07-20 15:22:39 -0700803 isUp = main.ONOSbench.isup( main.Cluster.runningNodes[ i ].ipAddress )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700804 utilities.assert_equals( expect=main.TRUE, actual=isUp,
805 onpass="ONOS service is ready",
806 onfail="ONOS service did not start properly" )
807 for i in nodes:
808 main.step( "Checking if ONOS CLI is ready" )
Devin Lim142b5342017-07-20 15:22:39 -0700809 ctrl = main.Cluster.runningNodes[ i ]
Jonghwan Hyun76a02b72018-01-30 16:40:48 +0900810 # ctrl.CLI.startCellCli()
Devin Lim142b5342017-07-20 15:22:39 -0700811 cliResult = ctrl.CLI.startOnosCli( ctrl.ipAddress,
812 commandlineTimeout=60,
813 onosStartTimeout=100 )
814 ctrl.active = True
Jon Hall1efcb3f2016-08-23 13:42:15 -0700815 utilities.assert_equals( expect=main.TRUE,
816 actual=cliResult,
817 onpass="ONOS CLI is ready",
818 onfail="ONOS CLI is not ready" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700819
Pier3b58c652016-09-26 12:03:31 -0700820 main.step( "Checking ONOS nodes" )
Jonghwan Hyun3731d6a2017-10-19 11:59:31 -0700821 nodeResults = utilities.retry( main.Cluster.nodesCheck,
Pier3b58c652016-09-26 12:03:31 -0700822 False,
Pier3b58c652016-09-26 12:03:31 -0700823 attempts=5,
824 sleep=10 )
825 utilities.assert_equals( expect=True, actual=nodeResults,
826 onpass="Nodes check successful",
827 onfail="Nodes check NOT successful" )
828
829 if not nodeResults:
830 for i in nodes:
Devin Lim142b5342017-07-20 15:22:39 -0700831 ctrl = main.Cluster.runningNodes[ i ]
Pier3b58c652016-09-26 12:03:31 -0700832 main.log.debug( "{} components not ACTIVE: \n{}".format(
Devin Lim142b5342017-07-20 15:22:39 -0700833 ctrl.name,
834 ctrl.CLI.sendline( "scr:list | grep -v ACTIVE" ) ) )
Pier3b58c652016-09-26 12:03:31 -0700835 main.log.error( "Failed to start ONOS, stopping test" )
Devin Lim44075962017-08-11 10:56:37 -0700836 main.cleanAndExit()
Pier3b58c652016-09-26 12:03:31 -0700837
Devin Lim142b5342017-07-20 15:22:39 -0700838 topology = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700839 main.FALSE,
840 kwargs={ 'numoswitch': switches,
841 'numolink': links,
842 'numoctrl': expNodes },
843 attempts=10,
844 sleep=12 )
845 utilities.assert_equals( expect=main.TRUE, actual=topology,
846 onpass="ONOS Instance down successful",
847 onfail="Failed to turn off ONOS Instance" )
Devin Lim142b5342017-07-20 15:22:39 -0700848 ready = utilities.retry( main.Cluster.active( 0 ).CLI.summary,
849 main.FALSE,
850 attempts=10,
851 sleep=12 )
852 if ready:
853 ready = main.TRUE
854 utilities.assert_equals( expect=main.TRUE, actual=ready,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700855 onpass="ONOS summary command succeded",
856 onfail="ONOS summary command failed" )
857 if not ready:
858 main.log.error( "ONOS startup failed!" )
Devin Lim44075962017-08-11 10:56:37 -0700859 main.cleanAndExit()
Jon Hall1efcb3f2016-08-23 13:42:15 -0700860
861 @staticmethod
862 def addHostCfg( main ):
863 """
864 Adds Host Configuration to ONOS
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700865 Updates expected state of the network ( pingChart )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700866 """
867 import json
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700868 hostCfg = {}
Devin Lim57221b02018-02-14 15:45:36 -0800869 with open( main.configPath + main.forJson + "extra.json" ) as template:
Jon Hall1efcb3f2016-08-23 13:42:15 -0700870 hostCfg = json.load( template )
871 main.pingChart[ 'ip' ][ 'hosts' ] += [ 'in1' ]
872 main.step( "Pushing new configuration" )
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700873 mac, cfg = hostCfg[ 'hosts' ].popitem()
Devin Lim142b5342017-07-20 15:22:39 -0700874 main.Cluster.active( 0 ).REST.setNetCfg( cfg[ 'basic' ],
875 subjectClass="hosts",
876 subjectKey=urllib.quote( mac,
877 safe='' ),
878 configKey="basic" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700879 main.pingChart[ 'ip' ][ 'hosts' ] += [ 'out1' ]
880 main.step( "Pushing new configuration" )
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700881 mac, cfg = hostCfg[ 'hosts' ].popitem()
Devin Lim142b5342017-07-20 15:22:39 -0700882 main.Cluster.active( 0 ).REST.setNetCfg( cfg[ 'basic' ],
883 subjectClass="hosts",
884 subjectKey=urllib.quote( mac,
885 safe='' ),
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700886 configKey="basic" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700887 main.pingChart.update( { 'vlan1': { "expect": "True",
888 "hosts": [ "olt1", "vsg1" ] } } )
889 main.pingChart[ 'vlan5' ][ 'expect' ] = 0
890 main.pingChart[ 'vlan10' ][ 'expect' ] = 0
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700891 ports = "[%s,%s]" % ( 5, 6 )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700892 cfg = '{"of:0000000000000001":[{"vlan":1,"ports":%s,"name":"OLT 1"}]}' % ports
Devin Lim142b5342017-07-20 15:22:39 -0700893 main.Cluster.active( 0 ).REST.setNetCfg( json.loads( cfg ),
894 subjectClass="apps",
895 subjectKey="org.onosproject.segmentrouting",
896 configKey="xconnect" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700897
898 @staticmethod
899 def delHostCfg( main ):
900 """
901 Removest Host Configuration from ONOS
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700902 Updates expected state of the network ( pingChart )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700903 """
904 import json
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700905 hostCfg = {}
Devin Lim57221b02018-02-14 15:45:36 -0800906 with open( main.configPath + main.forJson + "extra.json" ) as template:
Jon Hall1efcb3f2016-08-23 13:42:15 -0700907 hostCfg = json.load( template )
908 main.step( "Removing host configuration" )
909 main.pingChart[ 'ip' ][ 'expect' ] = 0
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700910 mac, cfg = hostCfg[ 'hosts' ].popitem()
Devin Lim142b5342017-07-20 15:22:39 -0700911 main.Cluster.active( 0 ).REST.removeNetCfg( subjectClass="hosts",
912 subjectKey=urllib.quote(
913 mac,
914 safe='' ),
915 configKey="basic" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700916 main.step( "Removing configuration" )
917 main.pingChart[ 'ip' ][ 'expect' ] = 0
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700918 mac, cfg = hostCfg[ 'hosts' ].popitem()
Devin Lim142b5342017-07-20 15:22:39 -0700919 main.Cluster.active( 0 ).REST.removeNetCfg( subjectClass="hosts",
920 subjectKey=urllib.quote(
921 mac,
922 safe='' ),
923 configKey="basic" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700924 main.step( "Removing vlan configuration" )
925 main.pingChart[ 'vlan1' ][ 'expect' ] = 0
Devin Lim142b5342017-07-20 15:22:39 -0700926 main.Cluster.active( 0 ).REST.removeNetCfg( subjectClass="apps",
927 subjectKey="org.onosproject.segmentrouting",
928 configKey="xconnect" )
You Wang53dba1e2018-02-02 17:45:44 -0800929
930 @staticmethod
931 def verifyNetworkHostIp( main, attempts=10, sleep=10 ):
932 """
933 Verifies IP address assignment from the hosts
934 """
935 main.step( "Verify IP address assignment from hosts" )
936 ipResult = main.TRUE
You Wangd66de192018-04-30 17:30:12 -0700937 main.Network.update()
You Wang6acb7a42018-05-04 15:12:25 -0700938 # Find out names of disconnected hosts
939 disconnectedHosts = []
940 if hasattr( main, "disconnectedIpv4Hosts" ):
941 for host in main.disconnectedIpv4Hosts:
942 disconnectedHosts.append( host )
943 if hasattr( main, "disconnectedIpv6Hosts" ):
944 for host in main.disconnectedIpv6Hosts:
945 disconnectedHosts.append( host )
You Wang53dba1e2018-02-02 17:45:44 -0800946 for hostName, ip in main.expectedHosts[ "network" ].items():
You Wang6acb7a42018-05-04 15:12:25 -0700947 # Exclude disconnected hosts
948 if hostName in disconnectedHosts:
949 main.log.debug( "Skip verifying IP for {} as it's disconnected".format( hostName ) )
950 continue
You Wang53dba1e2018-02-02 17:45:44 -0800951 ipResult = ipResult and utilities.retry( main.Network.verifyHostIp,
952 main.FALSE,
953 kwargs={ 'hostList': [ hostName ],
You Wangd66de192018-04-30 17:30:12 -0700954 'prefix': ip,
955 'update': False },
You Wang53dba1e2018-02-02 17:45:44 -0800956 attempts=attempts,
957 sleep=sleep )
958 utilities.assert_equals( expect=main.TRUE, actual=ipResult,
959 onpass="Verify network host IP succeded",
960 onfail="Verify network host IP failed" )
961
962 @staticmethod
963 def verifyOnosHostIp( main, attempts=10, sleep=10 ):
964 """
965 Verifies host IP address assignment from ONOS
966 """
967 main.step( "Verify host IP address assignment in ONOS" )
968 ipResult = main.TRUE
You Wang6acb7a42018-05-04 15:12:25 -0700969 # Find out IPs of disconnected hosts
970 disconnectedIps = []
971 if hasattr( main, "disconnectedIpv4Hosts" ):
972 for host in main.disconnectedIpv4Hosts:
973 disconnectedIps.append( main.expectedHosts[ "network" ][ host ] )
974 if hasattr( main, "disconnectedIpv6Hosts" ):
975 for host in main.disconnectedIpv6Hosts:
976 disconnectedIps.append( main.expectedHosts[ "network" ][ host ] )
You Wang53dba1e2018-02-02 17:45:44 -0800977 for hostName, ip in main.expectedHosts[ "onos" ].items():
You Wang6acb7a42018-05-04 15:12:25 -0700978 # Exclude disconnected hosts
979 if ip in disconnectedIps:
980 main.log.debug( "Skip verifying IP for {} as it's disconnected".format( ip ) )
981 continue
You Wang53dba1e2018-02-02 17:45:44 -0800982 ipResult = ipResult and utilities.retry( main.Cluster.active( 0 ).verifyHostIp,
983 main.FALSE,
984 kwargs={ 'hostList': [ hostName ],
985 'prefix': ip },
986 attempts=attempts,
987 sleep=sleep )
988 utilities.assert_equals( expect=main.TRUE, actual=ipResult,
989 onpass="Verify ONOS host IP succeded",
990 onfail="Verify ONOS host IP failed" )
Andreas Pantelopoulos2eae3242018-03-06 13:47:20 -0800991
Jonghwan Hyun812c70f2018-02-16 16:33:16 -0800992 @staticmethod
993 def updateIntfCfg( main, connectPoint, ips=[], untagged=0, tagged=[], native=0 ):
994 """
995 Description:
996 Updates interface configuration in ONOS, with given IP and vlan parameters
997 Required:
998 * connectPoint: connect point to update configuration
999 Optional:
1000 * ips: list of IP addresses, combined with '/xx' subnet representation,
1001 corresponding to 'ips' field in the configuration
1002 * untagged: vlan ID as an integer, corresponding to 'vlan-untagged' field in the configuration
1003 * tagged: integer list of vlan IDs, corresponding to 'vlan-tagged' field in the configuration
1004 * native: vlan ID as an integer, corresponding to 'vlan-native' field in the configuration
1005 """
1006 cfg = dict()
1007 cfg[ "ports" ] = dict()
1008 cfg[ "ports" ][ connectPoint ] = dict()
1009 cfg[ "ports" ][ connectPoint ][ "interfaces" ] = [ dict() ]
1010 cfg[ "ports" ][ connectPoint ][ "interfaces" ][ 0 ][ "ips" ] = ips
1011 if untagged > 0:
1012 cfg[ "ports" ][ connectPoint ][ "interfaces" ][ 0 ][ "vlan-untagged" ] = untagged
1013 else:
1014 cfg[ "ports" ][ connectPoint ][ "interfaces" ][ 0 ][ "vlan-tagged" ] = tagged
1015 if native > 0:
1016 cfg[ "ports" ][ connectPoint ][ "interfaces" ][ 0 ][ "vlan-native" ] = native
1017
1018 main.Cluster.active( 0 ).REST.setNetCfg( json.loads( json.dumps( cfg ) ) )
You Wange24d6272018-03-27 21:18:50 -07001019
1020 @staticmethod
1021 def startScapyHosts( main ):
1022 """
1023 Create host components and start Scapy CLIs
1024 """
1025 main.step( "Start Scapy CLIs" )
1026 main.scapyHostNames = main.params[ 'SCAPY' ][ 'HOSTNAMES' ].split( ',' )
1027 main.scapyHosts = []
1028 for hostName in main.scapyHostNames:
1029 main.Scapy.createHostComponent( hostName )
1030 main.scapyHosts.append( getattr( main, hostName ) )
1031 for host in main.scapyHosts:
1032 host.startHostCli()
1033 host.startScapy()
1034 host.updateSelf()
1035 main.log.debug( host.name )
1036 main.log.debug( host.hostIp )
1037 main.log.debug( host.hostMac )
1038
1039 @staticmethod
You Wangc564c6f2018-05-01 15:24:57 -07001040 def verifyMulticastTraffic( main, routeName, expect, skipOnFail=True, maxRetry=0 ):
You Wange24d6272018-03-27 21:18:50 -07001041 """
1042 Verify multicast traffic using scapy
1043 """
You Wangc564c6f2018-05-01 15:24:57 -07001044 from tests.dependencies.topology import Topology
1045 try:
1046 main.topo
1047 except ( NameError, AttributeError ):
1048 main.topo = Topology()
You Wangc02d8352018-04-17 16:42:10 -07001049 routeData = main.multicastConfig[ routeName ]
1050 srcs = main.mcastRoutes[ routeName ][ "src" ]
1051 dsts = main.mcastRoutes[ routeName ][ "dst" ]
1052 main.log.info( "Sending multicast traffic from {} to {}".format( [ routeData[ "src" ][ i ][ "host" ] for i in srcs ],
1053 [ routeData[ "dst" ][ i ][ "host" ] for i in dsts ] ) )
1054 for src in srcs:
1055 srcEntry = routeData[ "src" ][ src ]
1056 for dst in dsts:
1057 dstEntry = routeData[ "dst" ][ dst ]
1058 sender = getattr( main, srcEntry[ "host" ] )
1059 receiver = getattr( main, dstEntry[ "host" ] )
1060 main.Network.addRoute( str( srcEntry[ "host" ] ),
1061 str( routeData[ "group" ] ),
1062 str( srcEntry[ "interface" ] ),
1063 True if routeData[ "ipVersion" ] == 6 else False )
1064 # Build the packet
1065 sender.buildEther( dst=str( srcEntry[ "Ether" ] ) )
1066 if routeData[ "ipVersion" ] == 4:
1067 sender.buildIP( dst=str( routeData[ "group" ] ) )
1068 elif routeData[ "ipVersion" ] == 6:
1069 sender.buildIPv6( dst=str( routeData[ "group" ] ) )
1070 sender.buildUDP( ipVersion=routeData[ "ipVersion" ], dport=srcEntry[ "UDP" ] )
1071 sIface = srcEntry[ "interface" ]
1072 dIface = dstEntry[ "interface" ] if "interface" in dstEntry.keys() else None
1073 pktFilter = srcEntry[ "filter" ]
1074 pkt = srcEntry[ "packet" ]
1075 # Send packet and check received packet
1076 expectedResult = expect.pop( 0 ) if isinstance( expect, list ) else expect
You Wangc564c6f2018-05-01 15:24:57 -07001077 t3Cmd = "t3-troubleshoot -vv -sp {} -et ipv{} -d {} -dm {}".format( srcEntry[ "port" ], routeData[ "ipVersion" ],
1078 routeData[ "group" ], srcEntry[ "Ether" ] )
1079 trafficResult = main.topo.sendScapyPackets( sender, receiver, pktFilter, pkt, sIface, dIface,
1080 expectedResult, maxRetry, True, t3Cmd )
You Wangc02d8352018-04-17 16:42:10 -07001081 utilities.assert_equals( expect=main.TRUE,
1082 actual=trafficResult,
1083 onpass="{} to {}: Pass".format( srcEntry[ "host" ], dstEntry[ "host" ] ),
1084 onfail="{} to {}: Fail".format( srcEntry[ "host" ], dstEntry[ "host" ] ) )
1085 if skipOnFail and trafficResult != main.TRUE:
1086 Testcaselib.saveOnosDiagnostics( main )
1087 Testcaselib.cleanup( main, copyKarafLog=False )
1088 main.skipCase()
1089
1090 @staticmethod
You Wang5da39c82018-04-26 22:55:08 -07001091 def verifyPing( main, srcList, dstList, ipv6=False, expect=True, wait=1, acceptableFailed=0, skipOnFail=True ):
1092 """
1093 Verify reachability from each host in srcList to each host in dstList
1094 """
1095 from tests.dependencies.topology import Topology
1096 try:
1097 main.topo
1098 except ( NameError, AttributeError ):
1099 main.topo = Topology()
1100 pingResult = main.topo.ping( srcList, dstList, ipv6, expect, wait, acceptableFailed, skipOnFail )
1101 if not pingResult and skipOnFail:
1102 Testcaselib.saveOnosDiagnostics( main )
1103 Testcaselib.cleanup( main, copyKarafLog=False, removeHostComponent=True )
1104 main.skipCase()
You Wangbc898b82018-05-03 16:22:34 -07001105
1106 @staticmethod
1107 def verifyHostLocation( main, hostName, locations, ipv6=False ):
1108 """
1109 Verify if the specified host is discovered by ONOS on the given locations
1110 Required:
1111 hostName: name of the host. ex. "h1"
1112 locations: expected locations of the host. ex. "of:0000000000000005/8"
1113 Could be a string or list
1114 Optional:
1115 ipv6: Use True for IPv6 only hosts
1116 Returns:
1117 main.TRUE if host is discovered on all locations provided, otherwise main.FALSE
1118 """
1119 main.step( "Verify host {} is discovered at {}".format( hostName, locations ) )
1120 hostIp = main.Network.getIPAddress( hostName, proto='IPV6' if ipv6 else 'IPV4' )
1121 result = main.Cluster.active( 0 ).CLI.verifyHostLocation( hostIp, locations )
1122 return result