blob: b8ad87fdac562182e8318e97e6eacd1b9e45c116 [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 Wang48381752018-05-07 13:50:57 -0700653 def recoverSwitch( main, switch, switches, links, rediscoverHosts=False, hostsToDiscover=[] ):
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:
You Wang48381752018-05-07 13:50:57 -0700668 main.Network.discoverHosts( hostList=hostsToDiscover )
Andreas Pantelopoulos74c7ff22018-05-01 15:42:02 -0700669 main.log.info( "Waiting %s seconds for hosts to get re-discovered" % (
670 main.switchSleep ) )
671 time.sleep( main.switchSleep )
672
Devin Lim142b5342017-07-20 15:22:39 -0700673 topology = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700674 main.FALSE,
675 kwargs={ 'numoswitch': switches,
676 'numolink': links },
677 attempts=10,
678 sleep=main.switchSleep )
679 utilities.assert_equals( expect=main.TRUE, actual=topology,
680 onpass="Switch recovery successful",
681 onfail="Failed to recover switch?" )
682
You Wangc02d8352018-04-17 16:42:10 -0700683 def portstate( main, dpid, port, state, switches, links ):
684 """
685 Disable/enable a switch port using 'portstate' and verify ONOS can see the proper link change
686 Params:
687 dpid: dpid of the switch, ex.: 'of:0000000000000002'
688 port: port of the switch to disable/enable, ex.:'1'
689 state: disable or enable
690 switches, links: number of expected switches and links after link change, ex.: '4', '6'
691 """
692 main.step( "Port %s on %s:%s" % ( state, dpid, port ) )
693 main.Cluster.active( 0 ).CLI.portstate( dpid=dpid, port=port, state=state )
694 main.log.info( "Waiting %s seconds for port %s to be discovered" % ( main.linkSleep, state ) )
695 time.sleep( main.linkSleep )
696 result = main.Cluster.active( 0 ).CLI.checkStatus( numoswitch=switches,
697 numolink=links )
698 utilities.assert_equals( expect=main.TRUE, actual=result,
699 onpass="Port %s successful" % state,
700 onfail="Port %s failed" % state )
701
Jon Hall1efcb3f2016-08-23 13:42:15 -0700702 @staticmethod
You Wang5da39c82018-04-26 22:55:08 -0700703 def cleanup( main, copyKarafLog=True, removeHostComponent=False ):
Jon Hall1efcb3f2016-08-23 13:42:15 -0700704 """
705 Stop Onos-cluster.
706 Stops Mininet
707 Copies ONOS log
708 """
Devin Lim58046fa2017-07-05 16:55:00 -0700709 try:
710 from tests.dependencies.utils import Utils
711 except ImportError:
712 main.log.error( "Utils not found exiting the test" )
Devin Lim44075962017-08-11 10:56:37 -0700713 main.cleanAndExit()
Devin Lim58046fa2017-07-05 16:55:00 -0700714 try:
Devin Lim142b5342017-07-20 15:22:39 -0700715 main.utils
Devin Lim58046fa2017-07-05 16:55:00 -0700716 except ( NameError, AttributeError ):
Devin Lim142b5342017-07-20 15:22:39 -0700717 main.utils = Utils()
Devin Lim58046fa2017-07-05 16:55:00 -0700718
You Wange24d6272018-03-27 21:18:50 -0700719 if hasattr( main, "scapyHosts" ):
720 scapyResult = main.TRUE
721 for host in main.scapyHosts:
722 scapyResult = host.stopScapy() and scapyResult
723 main.log.info( "Stopped Scapy Host: {0}".format( host.name ) )
724 for host in main.scapyHosts:
725 scapyResult = main.Scapy.removeHostComponent( host.name ) and scapyResult
726 main.log.info( "Removed Scapy Host Component: {0}".format( host.name ) )
727 main.scapyHosts = []
728
You Wang5da39c82018-04-26 22:55:08 -0700729 if removeHostComponent:
730 for host in main.internalIpv4Hosts + main.internalIpv6Hosts + main.externalIpv4Hosts + main.externalIpv6Hosts:
731 if hasattr( main, host ):
732 main.Network.removeHostComponent( host )
733
You Wang5df1c6d2018-04-06 18:02:02 -0700734 if hasattr( main, 'Mininet1' ):
Pier6a0c4de2018-03-18 16:01:30 -0700735 main.utils.mininetCleanup( main.Mininet1 )
Devin Lim58046fa2017-07-05 16:55:00 -0700736
You Wang5df1c6d2018-04-06 18:02:02 -0700737 if copyKarafLog:
738 main.utils.copyKarafLog( "CASE%d" % main.CurrentTestCaseNumber, before=True, includeCaseDesc=False )
Devin Lim58046fa2017-07-05 16:55:00 -0700739
Devin Lim142b5342017-07-20 15:22:39 -0700740 for ctrl in main.Cluster.active():
741 main.ONOSbench.onosStop( ctrl.ipAddress )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700742
743 @staticmethod
744 def killOnos( main, nodes, switches, links, expNodes ):
745 """
746 Params: nodes, integer array with position of the ONOS nodes in the CLIs array
747 switches, links, nodes: number of expected switches, links and nodes after KillOnos, ex.: '4', '6'
748 Completely Kill an ONOS instance and verify the ONOS cluster can see the proper change
749 """
Jon Hall3c910162018-03-07 14:42:16 -0800750 main.step( "Killing ONOS instances with index(es): {}".format( nodes ) )
You Wang5df1c6d2018-04-06 18:02:02 -0700751 main.onosSleep = float( main.params[ 'timers' ][ 'OnosDiscovery' ] )
Pier3b58c652016-09-26 12:03:31 -0700752
Jon Hall1efcb3f2016-08-23 13:42:15 -0700753 for i in nodes:
Devin Lim142b5342017-07-20 15:22:39 -0700754 killResult = main.ONOSbench.onosDie( main.Cluster.runningNodes[ i ].ipAddress )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700755 utilities.assert_equals( expect=main.TRUE, actual=killResult,
756 onpass="ONOS instance Killed",
757 onfail="Error killing ONOS instance" )
Devin Lim142b5342017-07-20 15:22:39 -0700758 main.Cluster.runningNodes[ i ].active = False
You Wang5df1c6d2018-04-06 18:02:02 -0700759 time.sleep( main.onosSleep )
Pier3b58c652016-09-26 12:03:31 -0700760
Devin Lim142b5342017-07-20 15:22:39 -0700761 if len( nodes ) < main.Cluster.numCtrls:
Pier3b58c652016-09-26 12:03:31 -0700762
Jonghwan Hyun3731d6a2017-10-19 11:59:31 -0700763 nodeResults = utilities.retry( main.Cluster.nodesCheck,
Pier3b58c652016-09-26 12:03:31 -0700764 False,
Jon Hall9677ed32018-04-24 11:16:23 -0700765 attempts=10,
Pier3b58c652016-09-26 12:03:31 -0700766 sleep=10 )
767 utilities.assert_equals( expect=True, actual=nodeResults,
768 onpass="Nodes check successful",
769 onfail="Nodes check NOT successful" )
770
771 if not nodeResults:
772 for i in nodes:
Devin Lim142b5342017-07-20 15:22:39 -0700773 ctrl = main.Cluster.runningNodes[ i ]
Pier3b58c652016-09-26 12:03:31 -0700774 main.log.debug( "{} components not ACTIVE: \n{}".format(
Devin Lim142b5342017-07-20 15:22:39 -0700775 ctrl.name,
776 ctrl.CLI.sendline( "scr:list | grep -v ACTIVE" ) ) )
Pier3b58c652016-09-26 12:03:31 -0700777 main.log.error( "Failed to kill ONOS, stopping test" )
Devin Lim44075962017-08-11 10:56:37 -0700778 main.cleanAndExit()
Pier3b58c652016-09-26 12:03:31 -0700779
Jonghwan Hyun76a02b72018-01-30 16:40:48 +0900780 topology = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700781 main.FALSE,
782 kwargs={ 'numoswitch': switches,
783 'numolink': links,
784 'numoctrl': expNodes },
785 attempts=10,
786 sleep=12 )
787 utilities.assert_equals( expect=main.TRUE, actual=topology,
788 onpass="ONOS Instance down successful",
789 onfail="Failed to turn off ONOS Instance" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700790
791 @staticmethod
792 def recoverOnos( main, nodes, switches, links, expNodes ):
793 """
794 Params: nodes, integer array with position of the ONOS nodes in the CLIs array
795 switches, links, nodes: number of expected switches, links and nodes after recoverOnos, ex.: '4', '6'
796 Recover an ONOS instance and verify the ONOS cluster can see the proper change
797 """
Jon Hall3c910162018-03-07 14:42:16 -0800798 main.step( "Recovering ONOS instances with index(es): {}".format( nodes ) )
Devin Lim142b5342017-07-20 15:22:39 -0700799 [ main.ONOSbench.onosStart( main.Cluster.runningNodes[ i ].ipAddress ) for i in nodes ]
You Wang5df1c6d2018-04-06 18:02:02 -0700800 time.sleep( main.onosSleep )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700801 for i in nodes:
Devin Lim142b5342017-07-20 15:22:39 -0700802 isUp = main.ONOSbench.isup( main.Cluster.runningNodes[ i ].ipAddress )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700803 utilities.assert_equals( expect=main.TRUE, actual=isUp,
804 onpass="ONOS service is ready",
805 onfail="ONOS service did not start properly" )
806 for i in nodes:
807 main.step( "Checking if ONOS CLI is ready" )
Devin Lim142b5342017-07-20 15:22:39 -0700808 ctrl = main.Cluster.runningNodes[ i ]
Jonghwan Hyun76a02b72018-01-30 16:40:48 +0900809 # ctrl.CLI.startCellCli()
Devin Lim142b5342017-07-20 15:22:39 -0700810 cliResult = ctrl.CLI.startOnosCli( ctrl.ipAddress,
811 commandlineTimeout=60,
812 onosStartTimeout=100 )
813 ctrl.active = True
Jon Hall1efcb3f2016-08-23 13:42:15 -0700814 utilities.assert_equals( expect=main.TRUE,
815 actual=cliResult,
816 onpass="ONOS CLI is ready",
817 onfail="ONOS CLI is not ready" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700818
Pier3b58c652016-09-26 12:03:31 -0700819 main.step( "Checking ONOS nodes" )
Jonghwan Hyun3731d6a2017-10-19 11:59:31 -0700820 nodeResults = utilities.retry( main.Cluster.nodesCheck,
Pier3b58c652016-09-26 12:03:31 -0700821 False,
Pier3b58c652016-09-26 12:03:31 -0700822 attempts=5,
823 sleep=10 )
824 utilities.assert_equals( expect=True, actual=nodeResults,
825 onpass="Nodes check successful",
826 onfail="Nodes check NOT successful" )
827
828 if not nodeResults:
829 for i in nodes:
Devin Lim142b5342017-07-20 15:22:39 -0700830 ctrl = main.Cluster.runningNodes[ i ]
Pier3b58c652016-09-26 12:03:31 -0700831 main.log.debug( "{} components not ACTIVE: \n{}".format(
Devin Lim142b5342017-07-20 15:22:39 -0700832 ctrl.name,
833 ctrl.CLI.sendline( "scr:list | grep -v ACTIVE" ) ) )
Pier3b58c652016-09-26 12:03:31 -0700834 main.log.error( "Failed to start ONOS, stopping test" )
Devin Lim44075962017-08-11 10:56:37 -0700835 main.cleanAndExit()
Pier3b58c652016-09-26 12:03:31 -0700836
Devin Lim142b5342017-07-20 15:22:39 -0700837 topology = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700838 main.FALSE,
839 kwargs={ 'numoswitch': switches,
840 'numolink': links,
841 'numoctrl': expNodes },
842 attempts=10,
843 sleep=12 )
844 utilities.assert_equals( expect=main.TRUE, actual=topology,
845 onpass="ONOS Instance down successful",
846 onfail="Failed to turn off ONOS Instance" )
Devin Lim142b5342017-07-20 15:22:39 -0700847 ready = utilities.retry( main.Cluster.active( 0 ).CLI.summary,
848 main.FALSE,
849 attempts=10,
850 sleep=12 )
851 if ready:
852 ready = main.TRUE
853 utilities.assert_equals( expect=main.TRUE, actual=ready,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700854 onpass="ONOS summary command succeded",
855 onfail="ONOS summary command failed" )
856 if not ready:
857 main.log.error( "ONOS startup failed!" )
Devin Lim44075962017-08-11 10:56:37 -0700858 main.cleanAndExit()
Jon Hall1efcb3f2016-08-23 13:42:15 -0700859
860 @staticmethod
861 def addHostCfg( main ):
862 """
863 Adds Host Configuration to ONOS
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700864 Updates expected state of the network ( pingChart )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700865 """
866 import json
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700867 hostCfg = {}
Devin Lim57221b02018-02-14 15:45:36 -0800868 with open( main.configPath + main.forJson + "extra.json" ) as template:
Jon Hall1efcb3f2016-08-23 13:42:15 -0700869 hostCfg = json.load( template )
870 main.pingChart[ 'ip' ][ 'hosts' ] += [ 'in1' ]
871 main.step( "Pushing new configuration" )
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700872 mac, cfg = hostCfg[ 'hosts' ].popitem()
Devin Lim142b5342017-07-20 15:22:39 -0700873 main.Cluster.active( 0 ).REST.setNetCfg( cfg[ 'basic' ],
874 subjectClass="hosts",
875 subjectKey=urllib.quote( mac,
876 safe='' ),
877 configKey="basic" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700878 main.pingChart[ 'ip' ][ 'hosts' ] += [ 'out1' ]
879 main.step( "Pushing new configuration" )
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700880 mac, cfg = hostCfg[ 'hosts' ].popitem()
Devin Lim142b5342017-07-20 15:22:39 -0700881 main.Cluster.active( 0 ).REST.setNetCfg( cfg[ 'basic' ],
882 subjectClass="hosts",
883 subjectKey=urllib.quote( mac,
884 safe='' ),
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700885 configKey="basic" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700886 main.pingChart.update( { 'vlan1': { "expect": "True",
887 "hosts": [ "olt1", "vsg1" ] } } )
888 main.pingChart[ 'vlan5' ][ 'expect' ] = 0
889 main.pingChart[ 'vlan10' ][ 'expect' ] = 0
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700890 ports = "[%s,%s]" % ( 5, 6 )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700891 cfg = '{"of:0000000000000001":[{"vlan":1,"ports":%s,"name":"OLT 1"}]}' % ports
Devin Lim142b5342017-07-20 15:22:39 -0700892 main.Cluster.active( 0 ).REST.setNetCfg( json.loads( cfg ),
893 subjectClass="apps",
894 subjectKey="org.onosproject.segmentrouting",
895 configKey="xconnect" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700896
897 @staticmethod
898 def delHostCfg( main ):
899 """
900 Removest Host Configuration from ONOS
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700901 Updates expected state of the network ( pingChart )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700902 """
903 import json
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700904 hostCfg = {}
Devin Lim57221b02018-02-14 15:45:36 -0800905 with open( main.configPath + main.forJson + "extra.json" ) as template:
Jon Hall1efcb3f2016-08-23 13:42:15 -0700906 hostCfg = json.load( template )
907 main.step( "Removing host configuration" )
908 main.pingChart[ 'ip' ][ 'expect' ] = 0
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700909 mac, cfg = hostCfg[ 'hosts' ].popitem()
Devin Lim142b5342017-07-20 15:22:39 -0700910 main.Cluster.active( 0 ).REST.removeNetCfg( subjectClass="hosts",
911 subjectKey=urllib.quote(
912 mac,
913 safe='' ),
914 configKey="basic" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700915 main.step( "Removing configuration" )
916 main.pingChart[ 'ip' ][ 'expect' ] = 0
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700917 mac, cfg = hostCfg[ 'hosts' ].popitem()
Devin Lim142b5342017-07-20 15:22:39 -0700918 main.Cluster.active( 0 ).REST.removeNetCfg( subjectClass="hosts",
919 subjectKey=urllib.quote(
920 mac,
921 safe='' ),
922 configKey="basic" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700923 main.step( "Removing vlan configuration" )
924 main.pingChart[ 'vlan1' ][ 'expect' ] = 0
Devin Lim142b5342017-07-20 15:22:39 -0700925 main.Cluster.active( 0 ).REST.removeNetCfg( subjectClass="apps",
926 subjectKey="org.onosproject.segmentrouting",
927 configKey="xconnect" )
You Wang53dba1e2018-02-02 17:45:44 -0800928
929 @staticmethod
930 def verifyNetworkHostIp( main, attempts=10, sleep=10 ):
931 """
932 Verifies IP address assignment from the hosts
933 """
934 main.step( "Verify IP address assignment from hosts" )
935 ipResult = main.TRUE
You Wangd66de192018-04-30 17:30:12 -0700936 main.Network.update()
You Wang6acb7a42018-05-04 15:12:25 -0700937 # Find out names of disconnected hosts
938 disconnectedHosts = []
939 if hasattr( main, "disconnectedIpv4Hosts" ):
940 for host in main.disconnectedIpv4Hosts:
941 disconnectedHosts.append( host )
942 if hasattr( main, "disconnectedIpv6Hosts" ):
943 for host in main.disconnectedIpv6Hosts:
944 disconnectedHosts.append( host )
You Wang53dba1e2018-02-02 17:45:44 -0800945 for hostName, ip in main.expectedHosts[ "network" ].items():
You Wang6acb7a42018-05-04 15:12:25 -0700946 # Exclude disconnected hosts
947 if hostName in disconnectedHosts:
948 main.log.debug( "Skip verifying IP for {} as it's disconnected".format( hostName ) )
949 continue
You Wang53dba1e2018-02-02 17:45:44 -0800950 ipResult = ipResult and utilities.retry( main.Network.verifyHostIp,
951 main.FALSE,
952 kwargs={ 'hostList': [ hostName ],
You Wangd66de192018-04-30 17:30:12 -0700953 'prefix': ip,
954 'update': False },
You Wang53dba1e2018-02-02 17:45:44 -0800955 attempts=attempts,
956 sleep=sleep )
957 utilities.assert_equals( expect=main.TRUE, actual=ipResult,
958 onpass="Verify network host IP succeded",
959 onfail="Verify network host IP failed" )
960
961 @staticmethod
962 def verifyOnosHostIp( main, attempts=10, sleep=10 ):
963 """
964 Verifies host IP address assignment from ONOS
965 """
966 main.step( "Verify host IP address assignment in ONOS" )
967 ipResult = main.TRUE
You Wang6acb7a42018-05-04 15:12:25 -0700968 # Find out IPs of disconnected hosts
969 disconnectedIps = []
970 if hasattr( main, "disconnectedIpv4Hosts" ):
971 for host in main.disconnectedIpv4Hosts:
972 disconnectedIps.append( main.expectedHosts[ "network" ][ host ] )
973 if hasattr( main, "disconnectedIpv6Hosts" ):
974 for host in main.disconnectedIpv6Hosts:
975 disconnectedIps.append( main.expectedHosts[ "network" ][ host ] )
You Wang53dba1e2018-02-02 17:45:44 -0800976 for hostName, ip in main.expectedHosts[ "onos" ].items():
You Wang6acb7a42018-05-04 15:12:25 -0700977 # Exclude disconnected hosts
978 if ip in disconnectedIps:
979 main.log.debug( "Skip verifying IP for {} as it's disconnected".format( ip ) )
980 continue
You Wang53dba1e2018-02-02 17:45:44 -0800981 ipResult = ipResult and utilities.retry( main.Cluster.active( 0 ).verifyHostIp,
982 main.FALSE,
983 kwargs={ 'hostList': [ hostName ],
984 'prefix': ip },
985 attempts=attempts,
986 sleep=sleep )
987 utilities.assert_equals( expect=main.TRUE, actual=ipResult,
988 onpass="Verify ONOS host IP succeded",
989 onfail="Verify ONOS host IP failed" )
Andreas Pantelopoulos2eae3242018-03-06 13:47:20 -0800990
Jonghwan Hyun812c70f2018-02-16 16:33:16 -0800991 @staticmethod
992 def updateIntfCfg( main, connectPoint, ips=[], untagged=0, tagged=[], native=0 ):
993 """
994 Description:
995 Updates interface configuration in ONOS, with given IP and vlan parameters
996 Required:
997 * connectPoint: connect point to update configuration
998 Optional:
999 * ips: list of IP addresses, combined with '/xx' subnet representation,
1000 corresponding to 'ips' field in the configuration
1001 * untagged: vlan ID as an integer, corresponding to 'vlan-untagged' field in the configuration
1002 * tagged: integer list of vlan IDs, corresponding to 'vlan-tagged' field in the configuration
1003 * native: vlan ID as an integer, corresponding to 'vlan-native' field in the configuration
1004 """
1005 cfg = dict()
1006 cfg[ "ports" ] = dict()
1007 cfg[ "ports" ][ connectPoint ] = dict()
1008 cfg[ "ports" ][ connectPoint ][ "interfaces" ] = [ dict() ]
1009 cfg[ "ports" ][ connectPoint ][ "interfaces" ][ 0 ][ "ips" ] = ips
1010 if untagged > 0:
1011 cfg[ "ports" ][ connectPoint ][ "interfaces" ][ 0 ][ "vlan-untagged" ] = untagged
1012 else:
1013 cfg[ "ports" ][ connectPoint ][ "interfaces" ][ 0 ][ "vlan-tagged" ] = tagged
1014 if native > 0:
1015 cfg[ "ports" ][ connectPoint ][ "interfaces" ][ 0 ][ "vlan-native" ] = native
1016
1017 main.Cluster.active( 0 ).REST.setNetCfg( json.loads( json.dumps( cfg ) ) )
You Wange24d6272018-03-27 21:18:50 -07001018
1019 @staticmethod
1020 def startScapyHosts( main ):
1021 """
1022 Create host components and start Scapy CLIs
1023 """
1024 main.step( "Start Scapy CLIs" )
1025 main.scapyHostNames = main.params[ 'SCAPY' ][ 'HOSTNAMES' ].split( ',' )
1026 main.scapyHosts = []
1027 for hostName in main.scapyHostNames:
1028 main.Scapy.createHostComponent( hostName )
1029 main.scapyHosts.append( getattr( main, hostName ) )
1030 for host in main.scapyHosts:
1031 host.startHostCli()
1032 host.startScapy()
1033 host.updateSelf()
1034 main.log.debug( host.name )
1035 main.log.debug( host.hostIp )
1036 main.log.debug( host.hostMac )
1037
1038 @staticmethod
You Wangc564c6f2018-05-01 15:24:57 -07001039 def verifyMulticastTraffic( main, routeName, expect, skipOnFail=True, maxRetry=0 ):
You Wange24d6272018-03-27 21:18:50 -07001040 """
1041 Verify multicast traffic using scapy
1042 """
You Wangc564c6f2018-05-01 15:24:57 -07001043 from tests.dependencies.topology import Topology
1044 try:
1045 main.topo
1046 except ( NameError, AttributeError ):
1047 main.topo = Topology()
You Wangc02d8352018-04-17 16:42:10 -07001048 routeData = main.multicastConfig[ routeName ]
1049 srcs = main.mcastRoutes[ routeName ][ "src" ]
1050 dsts = main.mcastRoutes[ routeName ][ "dst" ]
1051 main.log.info( "Sending multicast traffic from {} to {}".format( [ routeData[ "src" ][ i ][ "host" ] for i in srcs ],
1052 [ routeData[ "dst" ][ i ][ "host" ] for i in dsts ] ) )
1053 for src in srcs:
1054 srcEntry = routeData[ "src" ][ src ]
1055 for dst in dsts:
1056 dstEntry = routeData[ "dst" ][ dst ]
1057 sender = getattr( main, srcEntry[ "host" ] )
1058 receiver = getattr( main, dstEntry[ "host" ] )
1059 main.Network.addRoute( str( srcEntry[ "host" ] ),
1060 str( routeData[ "group" ] ),
1061 str( srcEntry[ "interface" ] ),
1062 True if routeData[ "ipVersion" ] == 6 else False )
1063 # Build the packet
1064 sender.buildEther( dst=str( srcEntry[ "Ether" ] ) )
1065 if routeData[ "ipVersion" ] == 4:
1066 sender.buildIP( dst=str( routeData[ "group" ] ) )
1067 elif routeData[ "ipVersion" ] == 6:
1068 sender.buildIPv6( dst=str( routeData[ "group" ] ) )
1069 sender.buildUDP( ipVersion=routeData[ "ipVersion" ], dport=srcEntry[ "UDP" ] )
1070 sIface = srcEntry[ "interface" ]
1071 dIface = dstEntry[ "interface" ] if "interface" in dstEntry.keys() else None
1072 pktFilter = srcEntry[ "filter" ]
1073 pkt = srcEntry[ "packet" ]
1074 # Send packet and check received packet
1075 expectedResult = expect.pop( 0 ) if isinstance( expect, list ) else expect
You Wangc564c6f2018-05-01 15:24:57 -07001076 t3Cmd = "t3-troubleshoot -vv -sp {} -et ipv{} -d {} -dm {}".format( srcEntry[ "port" ], routeData[ "ipVersion" ],
1077 routeData[ "group" ], srcEntry[ "Ether" ] )
1078 trafficResult = main.topo.sendScapyPackets( sender, receiver, pktFilter, pkt, sIface, dIface,
1079 expectedResult, maxRetry, True, t3Cmd )
You Wangc02d8352018-04-17 16:42:10 -07001080 utilities.assert_equals( expect=main.TRUE,
1081 actual=trafficResult,
1082 onpass="{} to {}: Pass".format( srcEntry[ "host" ], dstEntry[ "host" ] ),
1083 onfail="{} to {}: Fail".format( srcEntry[ "host" ], dstEntry[ "host" ] ) )
1084 if skipOnFail and trafficResult != main.TRUE:
1085 Testcaselib.saveOnosDiagnostics( main )
1086 Testcaselib.cleanup( main, copyKarafLog=False )
1087 main.skipCase()
1088
1089 @staticmethod
You Wang5da39c82018-04-26 22:55:08 -07001090 def verifyPing( main, srcList, dstList, ipv6=False, expect=True, wait=1, acceptableFailed=0, skipOnFail=True ):
1091 """
1092 Verify reachability from each host in srcList to each host in dstList
1093 """
1094 from tests.dependencies.topology import Topology
1095 try:
1096 main.topo
1097 except ( NameError, AttributeError ):
1098 main.topo = Topology()
1099 pingResult = main.topo.ping( srcList, dstList, ipv6, expect, wait, acceptableFailed, skipOnFail )
1100 if not pingResult and skipOnFail:
1101 Testcaselib.saveOnosDiagnostics( main )
1102 Testcaselib.cleanup( main, copyKarafLog=False, removeHostComponent=True )
1103 main.skipCase()
You Wangbc898b82018-05-03 16:22:34 -07001104
1105 @staticmethod
1106 def verifyHostLocation( main, hostName, locations, ipv6=False ):
1107 """
1108 Verify if the specified host is discovered by ONOS on the given locations
1109 Required:
1110 hostName: name of the host. ex. "h1"
1111 locations: expected locations of the host. ex. "of:0000000000000005/8"
1112 Could be a string or list
1113 Optional:
1114 ipv6: Use True for IPv6 only hosts
1115 Returns:
1116 main.TRUE if host is discovered on all locations provided, otherwise main.FALSE
1117 """
1118 main.step( "Verify host {} is discovered at {}".format( hostName, locations ) )
1119 hostIp = main.Network.getIPAddress( hostName, proto='IPV6' if ipv6 else 'IPV4' )
1120 result = main.Cluster.active( 0 ).CLI.verifyHostLocation( hostIp, locations )
1121 return result