blob: 358ce47c28744395ffeeb3d37651cac8a45f8956 [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,
178 main.Mininet1.home,
179 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,
184 main.Mininet1.home,
185 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(
213 topoFile=main.Mininet1.home + main.topology, args=arg )
214 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
Jon Hall1efcb3f2016-08-23 13:42:15 -0700591 def restoreLink( main, end1, end2, dpid1, dpid2, port1, port2, switches,
592 links ):
593 """
594 Params:
595 end1,end2: identify the end switches, ex.: 'leaf1', 'spine1'
596 dpid1, dpid2: dpid of the end switches respectively, ex.: 'of:0000000000000002'
597 port1, port2: respective port of the end switches that connects to the link, ex.:'1'
598 switches, links: number of expected switches and links after linkDown, ex.: '4', '6'
599 Kill a link and verify ONOS can see the proper link change
600 """
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700601 main.step( "Restore link between %s and %s" % ( end1, end2 ) )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700602 result = False
603 count = 0
604 while True:
605 count += 1
You Wangd5873482018-01-24 12:30:00 -0800606 main.Network.link( END1=end1, END2=end2, OPTION="up" )
607 main.Network.link( END2=end1, END1=end2, OPTION="up" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700608 main.log.info(
609 "Waiting %s seconds for link up to be discovered" % main.linkSleep )
610 time.sleep( main.linkSleep )
Pierfb719b12016-09-19 14:51:44 -0700611
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700612 for i in range( 0, main.Cluster.numCtrls ):
Devin Lim142b5342017-07-20 15:22:39 -0700613 ctrl = main.Cluster.runningNodes[ i ]
614 onosIsUp = main.ONOSbench.isup( ctrl.ipAddress )
Pierfb719b12016-09-19 14:51:44 -0700615 if onosIsUp == main.TRUE:
Jonghwan Hyun76a02b72018-01-30 16:40:48 +0900616 ctrl.CLI.portstate( dpid=dpid1, port=port1, state='Enable' )
617 ctrl.CLI.portstate( dpid=dpid2, port=port2, state='Enable' )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700618 time.sleep( main.linkSleep )
619
Devin Lim142b5342017-07-20 15:22:39 -0700620 result = main.Cluster.active( 0 ).CLI.checkStatus( numoswitch=switches,
621 numolink=links )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700622 if count > 5 or result:
623 break
624 utilities.assert_equals( expect=main.TRUE, actual=result,
625 onpass="Link up successful",
626 onfail="Failed to bring link up" )
627
628 @staticmethod
629 def killSwitch( main, switch, switches, links ):
630 """
631 Params: switches, links: number of expected switches and links after SwitchDown, ex.: '4', '6'
632 Completely kill a switch and verify ONOS can see the proper change
633 """
634 main.switchSleep = float( main.params[ 'timers' ][ 'SwitchDiscovery' ] )
635 main.step( "Kill " + switch )
636 main.log.info( "Stopping" + switch )
You Wangd5873482018-01-24 12:30:00 -0800637 main.Network.switch( SW=switch, 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
653 def recoverSwitch( main, switch, switches, links ):
654 """
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
659 main.step( "Recovering " + switch )
660 main.log.info( "Starting" + switch )
You Wangd5873482018-01-24 12:30:00 -0800661 main.Network.switch( SW=switch, OPTION="start" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700662 main.log.info( "Waiting %s seconds for switch up to be discovered" % (
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700663 main.switchSleep ) )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700664 time.sleep( main.switchSleep )
Devin Lim142b5342017-07-20 15:22:39 -0700665 topology = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700666 main.FALSE,
667 kwargs={ 'numoswitch': switches,
668 'numolink': links },
669 attempts=10,
670 sleep=main.switchSleep )
671 utilities.assert_equals( expect=main.TRUE, actual=topology,
672 onpass="Switch recovery successful",
673 onfail="Failed to recover switch?" )
674
675 @staticmethod
You Wang5df1c6d2018-04-06 18:02:02 -0700676 def cleanup( main, copyKarafLog=True ):
Jon Hall1efcb3f2016-08-23 13:42:15 -0700677 """
678 Stop Onos-cluster.
679 Stops Mininet
680 Copies ONOS log
681 """
Devin Lim58046fa2017-07-05 16:55:00 -0700682 try:
683 from tests.dependencies.utils import Utils
684 except ImportError:
685 main.log.error( "Utils not found exiting the test" )
Devin Lim44075962017-08-11 10:56:37 -0700686 main.cleanAndExit()
Devin Lim58046fa2017-07-05 16:55:00 -0700687 try:
Devin Lim142b5342017-07-20 15:22:39 -0700688 main.utils
Devin Lim58046fa2017-07-05 16:55:00 -0700689 except ( NameError, AttributeError ):
Devin Lim142b5342017-07-20 15:22:39 -0700690 main.utils = Utils()
Devin Lim58046fa2017-07-05 16:55:00 -0700691
You Wange24d6272018-03-27 21:18:50 -0700692 if hasattr( main, "scapyHosts" ):
693 scapyResult = main.TRUE
694 for host in main.scapyHosts:
695 scapyResult = host.stopScapy() and scapyResult
696 main.log.info( "Stopped Scapy Host: {0}".format( host.name ) )
697 for host in main.scapyHosts:
698 scapyResult = main.Scapy.removeHostComponent( host.name ) and scapyResult
699 main.log.info( "Removed Scapy Host Component: {0}".format( host.name ) )
700 main.scapyHosts = []
701
You Wang5df1c6d2018-04-06 18:02:02 -0700702 if hasattr( main, 'Mininet1' ):
Pier6a0c4de2018-03-18 16:01:30 -0700703 main.utils.mininetCleanup( main.Mininet1 )
Devin Lim58046fa2017-07-05 16:55:00 -0700704
You Wang5df1c6d2018-04-06 18:02:02 -0700705 if copyKarafLog:
706 main.utils.copyKarafLog( "CASE%d" % main.CurrentTestCaseNumber, before=True, includeCaseDesc=False )
Devin Lim58046fa2017-07-05 16:55:00 -0700707
Devin Lim142b5342017-07-20 15:22:39 -0700708 for ctrl in main.Cluster.active():
709 main.ONOSbench.onosStop( ctrl.ipAddress )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700710
711 @staticmethod
712 def killOnos( main, nodes, switches, links, expNodes ):
713 """
714 Params: nodes, integer array with position of the ONOS nodes in the CLIs array
715 switches, links, nodes: number of expected switches, links and nodes after KillOnos, ex.: '4', '6'
716 Completely Kill an ONOS instance and verify the ONOS cluster can see the proper change
717 """
Jon Hall3c910162018-03-07 14:42:16 -0800718 main.step( "Killing ONOS instances with index(es): {}".format( nodes ) )
You Wang5df1c6d2018-04-06 18:02:02 -0700719 main.onosSleep = float( main.params[ 'timers' ][ 'OnosDiscovery' ] )
Pier3b58c652016-09-26 12:03:31 -0700720
Jon Hall1efcb3f2016-08-23 13:42:15 -0700721 for i in nodes:
Devin Lim142b5342017-07-20 15:22:39 -0700722 killResult = main.ONOSbench.onosDie( main.Cluster.runningNodes[ i ].ipAddress )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700723 utilities.assert_equals( expect=main.TRUE, actual=killResult,
724 onpass="ONOS instance Killed",
725 onfail="Error killing ONOS instance" )
Devin Lim142b5342017-07-20 15:22:39 -0700726 main.Cluster.runningNodes[ i ].active = False
You Wang5df1c6d2018-04-06 18:02:02 -0700727 time.sleep( main.onosSleep )
Pier3b58c652016-09-26 12:03:31 -0700728
Devin Lim142b5342017-07-20 15:22:39 -0700729 if len( nodes ) < main.Cluster.numCtrls:
Pier3b58c652016-09-26 12:03:31 -0700730
Jonghwan Hyun3731d6a2017-10-19 11:59:31 -0700731 nodeResults = utilities.retry( main.Cluster.nodesCheck,
Pier3b58c652016-09-26 12:03:31 -0700732 False,
Jon Hall9677ed32018-04-24 11:16:23 -0700733 attempts=10,
Pier3b58c652016-09-26 12:03:31 -0700734 sleep=10 )
735 utilities.assert_equals( expect=True, actual=nodeResults,
736 onpass="Nodes check successful",
737 onfail="Nodes check NOT successful" )
738
739 if not nodeResults:
740 for i in nodes:
Devin Lim142b5342017-07-20 15:22:39 -0700741 ctrl = main.Cluster.runningNodes[ i ]
Pier3b58c652016-09-26 12:03:31 -0700742 main.log.debug( "{} components not ACTIVE: \n{}".format(
Devin Lim142b5342017-07-20 15:22:39 -0700743 ctrl.name,
744 ctrl.CLI.sendline( "scr:list | grep -v ACTIVE" ) ) )
Pier3b58c652016-09-26 12:03:31 -0700745 main.log.error( "Failed to kill ONOS, stopping test" )
Devin Lim44075962017-08-11 10:56:37 -0700746 main.cleanAndExit()
Pier3b58c652016-09-26 12:03:31 -0700747
Jonghwan Hyun76a02b72018-01-30 16:40:48 +0900748 topology = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700749 main.FALSE,
750 kwargs={ 'numoswitch': switches,
751 'numolink': links,
752 'numoctrl': expNodes },
753 attempts=10,
754 sleep=12 )
755 utilities.assert_equals( expect=main.TRUE, actual=topology,
756 onpass="ONOS Instance down successful",
757 onfail="Failed to turn off ONOS Instance" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700758
759 @staticmethod
760 def recoverOnos( main, nodes, switches, links, expNodes ):
761 """
762 Params: nodes, integer array with position of the ONOS nodes in the CLIs array
763 switches, links, nodes: number of expected switches, links and nodes after recoverOnos, ex.: '4', '6'
764 Recover an ONOS instance and verify the ONOS cluster can see the proper change
765 """
Jon Hall3c910162018-03-07 14:42:16 -0800766 main.step( "Recovering ONOS instances with index(es): {}".format( nodes ) )
Devin Lim142b5342017-07-20 15:22:39 -0700767 [ main.ONOSbench.onosStart( main.Cluster.runningNodes[ i ].ipAddress ) for i in nodes ]
You Wang5df1c6d2018-04-06 18:02:02 -0700768 time.sleep( main.onosSleep )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700769 for i in nodes:
Devin Lim142b5342017-07-20 15:22:39 -0700770 isUp = main.ONOSbench.isup( main.Cluster.runningNodes[ i ].ipAddress )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700771 utilities.assert_equals( expect=main.TRUE, actual=isUp,
772 onpass="ONOS service is ready",
773 onfail="ONOS service did not start properly" )
774 for i in nodes:
775 main.step( "Checking if ONOS CLI is ready" )
Devin Lim142b5342017-07-20 15:22:39 -0700776 ctrl = main.Cluster.runningNodes[ i ]
Jonghwan Hyun76a02b72018-01-30 16:40:48 +0900777 # ctrl.CLI.startCellCli()
Devin Lim142b5342017-07-20 15:22:39 -0700778 cliResult = ctrl.CLI.startOnosCli( ctrl.ipAddress,
779 commandlineTimeout=60,
780 onosStartTimeout=100 )
781 ctrl.active = True
Jon Hall1efcb3f2016-08-23 13:42:15 -0700782 utilities.assert_equals( expect=main.TRUE,
783 actual=cliResult,
784 onpass="ONOS CLI is ready",
785 onfail="ONOS CLI is not ready" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700786
Pier3b58c652016-09-26 12:03:31 -0700787 main.step( "Checking ONOS nodes" )
Jonghwan Hyun3731d6a2017-10-19 11:59:31 -0700788 nodeResults = utilities.retry( main.Cluster.nodesCheck,
Pier3b58c652016-09-26 12:03:31 -0700789 False,
Pier3b58c652016-09-26 12:03:31 -0700790 attempts=5,
791 sleep=10 )
792 utilities.assert_equals( expect=True, actual=nodeResults,
793 onpass="Nodes check successful",
794 onfail="Nodes check NOT successful" )
795
796 if not nodeResults:
797 for i in nodes:
Devin Lim142b5342017-07-20 15:22:39 -0700798 ctrl = main.Cluster.runningNodes[ i ]
Pier3b58c652016-09-26 12:03:31 -0700799 main.log.debug( "{} components not ACTIVE: \n{}".format(
Devin Lim142b5342017-07-20 15:22:39 -0700800 ctrl.name,
801 ctrl.CLI.sendline( "scr:list | grep -v ACTIVE" ) ) )
Pier3b58c652016-09-26 12:03:31 -0700802 main.log.error( "Failed to start ONOS, stopping test" )
Devin Lim44075962017-08-11 10:56:37 -0700803 main.cleanAndExit()
Pier3b58c652016-09-26 12:03:31 -0700804
Devin Lim142b5342017-07-20 15:22:39 -0700805 topology = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700806 main.FALSE,
807 kwargs={ 'numoswitch': switches,
808 'numolink': links,
809 'numoctrl': expNodes },
810 attempts=10,
811 sleep=12 )
812 utilities.assert_equals( expect=main.TRUE, actual=topology,
813 onpass="ONOS Instance down successful",
814 onfail="Failed to turn off ONOS Instance" )
Devin Lim142b5342017-07-20 15:22:39 -0700815 ready = utilities.retry( main.Cluster.active( 0 ).CLI.summary,
816 main.FALSE,
817 attempts=10,
818 sleep=12 )
819 if ready:
820 ready = main.TRUE
821 utilities.assert_equals( expect=main.TRUE, actual=ready,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700822 onpass="ONOS summary command succeded",
823 onfail="ONOS summary command failed" )
824 if not ready:
825 main.log.error( "ONOS startup failed!" )
Devin Lim44075962017-08-11 10:56:37 -0700826 main.cleanAndExit()
Jon Hall1efcb3f2016-08-23 13:42:15 -0700827
828 @staticmethod
829 def addHostCfg( main ):
830 """
831 Adds Host Configuration to ONOS
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700832 Updates expected state of the network ( pingChart )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700833 """
834 import json
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700835 hostCfg = {}
Devin Lim57221b02018-02-14 15:45:36 -0800836 with open( main.configPath + main.forJson + "extra.json" ) as template:
Jon Hall1efcb3f2016-08-23 13:42:15 -0700837 hostCfg = json.load( template )
838 main.pingChart[ 'ip' ][ 'hosts' ] += [ 'in1' ]
839 main.step( "Pushing new configuration" )
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700840 mac, cfg = hostCfg[ 'hosts' ].popitem()
Devin Lim142b5342017-07-20 15:22:39 -0700841 main.Cluster.active( 0 ).REST.setNetCfg( cfg[ 'basic' ],
842 subjectClass="hosts",
843 subjectKey=urllib.quote( mac,
844 safe='' ),
845 configKey="basic" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700846 main.pingChart[ 'ip' ][ 'hosts' ] += [ 'out1' ]
847 main.step( "Pushing new configuration" )
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700848 mac, cfg = hostCfg[ 'hosts' ].popitem()
Devin Lim142b5342017-07-20 15:22:39 -0700849 main.Cluster.active( 0 ).REST.setNetCfg( cfg[ 'basic' ],
850 subjectClass="hosts",
851 subjectKey=urllib.quote( mac,
852 safe='' ),
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700853 configKey="basic" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700854 main.pingChart.update( { 'vlan1': { "expect": "True",
855 "hosts": [ "olt1", "vsg1" ] } } )
856 main.pingChart[ 'vlan5' ][ 'expect' ] = 0
857 main.pingChart[ 'vlan10' ][ 'expect' ] = 0
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700858 ports = "[%s,%s]" % ( 5, 6 )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700859 cfg = '{"of:0000000000000001":[{"vlan":1,"ports":%s,"name":"OLT 1"}]}' % ports
Devin Lim142b5342017-07-20 15:22:39 -0700860 main.Cluster.active( 0 ).REST.setNetCfg( json.loads( cfg ),
861 subjectClass="apps",
862 subjectKey="org.onosproject.segmentrouting",
863 configKey="xconnect" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700864
865 @staticmethod
866 def delHostCfg( main ):
867 """
868 Removest Host Configuration from ONOS
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700869 Updates expected state of the network ( pingChart )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700870 """
871 import json
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700872 hostCfg = {}
Devin Lim57221b02018-02-14 15:45:36 -0800873 with open( main.configPath + main.forJson + "extra.json" ) as template:
Jon Hall1efcb3f2016-08-23 13:42:15 -0700874 hostCfg = json.load( template )
875 main.step( "Removing host configuration" )
876 main.pingChart[ 'ip' ][ 'expect' ] = 0
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700877 mac, cfg = hostCfg[ 'hosts' ].popitem()
Devin Lim142b5342017-07-20 15:22:39 -0700878 main.Cluster.active( 0 ).REST.removeNetCfg( subjectClass="hosts",
879 subjectKey=urllib.quote(
880 mac,
881 safe='' ),
882 configKey="basic" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700883 main.step( "Removing configuration" )
884 main.pingChart[ 'ip' ][ 'expect' ] = 0
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700885 mac, cfg = hostCfg[ 'hosts' ].popitem()
Devin Lim142b5342017-07-20 15:22:39 -0700886 main.Cluster.active( 0 ).REST.removeNetCfg( subjectClass="hosts",
887 subjectKey=urllib.quote(
888 mac,
889 safe='' ),
890 configKey="basic" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700891 main.step( "Removing vlan configuration" )
892 main.pingChart[ 'vlan1' ][ 'expect' ] = 0
Devin Lim142b5342017-07-20 15:22:39 -0700893 main.Cluster.active( 0 ).REST.removeNetCfg( subjectClass="apps",
894 subjectKey="org.onosproject.segmentrouting",
895 configKey="xconnect" )
You Wang53dba1e2018-02-02 17:45:44 -0800896
897 @staticmethod
898 def verifyNetworkHostIp( main, attempts=10, sleep=10 ):
899 """
900 Verifies IP address assignment from the hosts
901 """
902 main.step( "Verify IP address assignment from hosts" )
903 ipResult = main.TRUE
904 for hostName, ip in main.expectedHosts[ "network" ].items():
905 ipResult = ipResult and utilities.retry( main.Network.verifyHostIp,
906 main.FALSE,
907 kwargs={ 'hostList': [ hostName ],
908 'prefix': ip },
909 attempts=attempts,
910 sleep=sleep )
911 utilities.assert_equals( expect=main.TRUE, actual=ipResult,
912 onpass="Verify network host IP succeded",
913 onfail="Verify network host IP failed" )
914
915 @staticmethod
916 def verifyOnosHostIp( main, attempts=10, sleep=10 ):
917 """
918 Verifies host IP address assignment from ONOS
919 """
920 main.step( "Verify host IP address assignment in ONOS" )
921 ipResult = main.TRUE
922 for hostName, ip in main.expectedHosts[ "onos" ].items():
923 ipResult = ipResult and utilities.retry( main.Cluster.active( 0 ).verifyHostIp,
924 main.FALSE,
925 kwargs={ 'hostList': [ hostName ],
926 'prefix': ip },
927 attempts=attempts,
928 sleep=sleep )
929 utilities.assert_equals( expect=main.TRUE, actual=ipResult,
930 onpass="Verify ONOS host IP succeded",
931 onfail="Verify ONOS host IP failed" )
Andreas Pantelopoulos2eae3242018-03-06 13:47:20 -0800932
Jonghwan Hyun812c70f2018-02-16 16:33:16 -0800933 @staticmethod
934 def updateIntfCfg( main, connectPoint, ips=[], untagged=0, tagged=[], native=0 ):
935 """
936 Description:
937 Updates interface configuration in ONOS, with given IP and vlan parameters
938 Required:
939 * connectPoint: connect point to update configuration
940 Optional:
941 * ips: list of IP addresses, combined with '/xx' subnet representation,
942 corresponding to 'ips' field in the configuration
943 * untagged: vlan ID as an integer, corresponding to 'vlan-untagged' field in the configuration
944 * tagged: integer list of vlan IDs, corresponding to 'vlan-tagged' field in the configuration
945 * native: vlan ID as an integer, corresponding to 'vlan-native' field in the configuration
946 """
947 cfg = dict()
948 cfg[ "ports" ] = dict()
949 cfg[ "ports" ][ connectPoint ] = dict()
950 cfg[ "ports" ][ connectPoint ][ "interfaces" ] = [ dict() ]
951 cfg[ "ports" ][ connectPoint ][ "interfaces" ][ 0 ][ "ips" ] = ips
952 if untagged > 0:
953 cfg[ "ports" ][ connectPoint ][ "interfaces" ][ 0 ][ "vlan-untagged" ] = untagged
954 else:
955 cfg[ "ports" ][ connectPoint ][ "interfaces" ][ 0 ][ "vlan-tagged" ] = tagged
956 if native > 0:
957 cfg[ "ports" ][ connectPoint ][ "interfaces" ][ 0 ][ "vlan-native" ] = native
958
959 main.Cluster.active( 0 ).REST.setNetCfg( json.loads( json.dumps( cfg ) ) )
You Wange24d6272018-03-27 21:18:50 -0700960
961 @staticmethod
962 def startScapyHosts( main ):
963 """
964 Create host components and start Scapy CLIs
965 """
966 main.step( "Start Scapy CLIs" )
967 main.scapyHostNames = main.params[ 'SCAPY' ][ 'HOSTNAMES' ].split( ',' )
968 main.scapyHosts = []
969 for hostName in main.scapyHostNames:
970 main.Scapy.createHostComponent( hostName )
971 main.scapyHosts.append( getattr( main, hostName ) )
972 for host in main.scapyHosts:
973 host.startHostCli()
974 host.startScapy()
975 host.updateSelf()
976 main.log.debug( host.name )
977 main.log.debug( host.hostIp )
978 main.log.debug( host.hostMac )
979
980 @staticmethod
981 def verifyMulticastTraffic( main, entry, expect, skipOnFail=False ):
982 """
983 Verify multicast traffic using scapy
984 """
985 srcEntry = entry["scapy"]["src"]
986 for dstEntry in entry["scapy"]["dst"]:
987 # Set up scapy receiver
988 receiver = getattr( main, dstEntry["host"] )
You Wangece951a2018-04-16 13:34:43 -0700989 if "interface" in dstEntry.keys():
990 receiver.startFilter( ifaceName=dstEntry["interface"], pktFilter=srcEntry["filter"] )
991 else:
992 receiver.startFilter( pktFilter=srcEntry["filter"] )
You Wange24d6272018-03-27 21:18:50 -0700993 # Set up scapy sender
994 main.Network.addRoute( str( srcEntry["host"] ),
995 str( entry["group"] ),
996 str( srcEntry["interface"] ),
997 True if entry["ipVersion"] == 6 else False )
998 sender = getattr( main, srcEntry["host"] )
999 sender.buildEther( dst=str( srcEntry["Ether"] ) )
1000 if entry["ipVersion"] == 4:
1001 sender.buildIP( dst=str( entry["group"] ) )
1002 elif entry["ipVersion"] == 6:
1003 sender.buildIPv6( dst=str( entry["group"] ) )
1004 sender.buildUDP( ipVersion=entry["ipVersion"], dport=srcEntry["UDP"] )
1005 # Send packet and check received packet
1006 sender.sendPacket( iface=srcEntry["interface"] )
1007 finished = receiver.checkFilter()
1008 packet = ""
1009 if finished:
1010 packets = receiver.readPackets()
1011 for packet in packets.splitlines():
1012 main.log.debug( packet )
1013 else:
1014 kill = receiver.killFilter()
1015 main.log.debug( kill )
1016 sender.handle.sendline( "" )
1017 sender.handle.expect( sender.scapyPrompt )
1018 main.log.debug( sender.handle.before )
You Wangece951a2018-04-16 13:34:43 -07001019 packetCaptured = True if srcEntry["packet"] in packet else False
You Wange24d6272018-03-27 21:18:50 -07001020 utilities.assert_equals( expect=expect,
You Wangece951a2018-04-16 13:34:43 -07001021 actual=packetCaptured,
You Wange24d6272018-03-27 21:18:50 -07001022 onpass="Pass",
1023 onfail="Fail" )
You Wang0a283bf2018-04-16 17:34:40 -07001024 if skipOnFail and packetCaptured != expect:
1025 Testcaselib.saveOnosDiagnostics( main )
1026 Testcaselib.cleanup( main, copyKarafLog=False )
1027 main.skipCase()