blob: 000dfe385dddc9f6480fde1656bc2b932540b7c2 [file] [log] [blame]
You Wangdb927a52016-02-26 11:03:28 -08001"""
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"""
Jeremy Ronquillob27ce4c2017-07-17 12:41:28 -070021"""
You Wangdb927a52016-02-26 11:03:28 -080022CHOTestMonkey class
23Author: you@onlab.us
24"""
You Wangdb927a52016-02-26 11:03:28 -080025import sys
26import os
27import re
28import time
29import json
30import itertools
31
Jon Hall2bb3e212017-05-24 17:07:25 -070032
You Wangdb927a52016-02-26 11:03:28 -080033class CHOTestMonkey:
34
35 def __init__( self ):
36 self.default = ''
37
38 def CASE0( self, main ):
39 """
40 Startup sequence:
41 apply cell <name>
42 git pull
You Wangdb927a52016-02-26 11:03:28 -080043 onos-package
44 onos-verify-cell
45 onos-uninstall
46 onos-install
47 onos-start-cli
48 Set IPv6 cfg parameters for Neighbor Discovery
49 start event scheduler
50 start event listener
51 """
52 import time
53 from threading import Lock, Condition
You Wang221db322016-06-03 15:45:52 -070054 from core.graph import Graph
You Wangdb927a52016-02-26 11:03:28 -080055 from tests.CHOTestMonkey.dependencies.elements.ONOSElement import Controller
56 from tests.CHOTestMonkey.dependencies.EventGenerator import EventGenerator
57 from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduler
58
Devin Lim58046fa2017-07-05 16:55:00 -070059 try:
60 from tests.dependencies.ONOSSetup import ONOSSetup
61 main.testSetUp = ONOSSetup()
62 except ImportError:
63 main.log.error( "ONOSSetup not found exiting the test" )
Devin Lim44075962017-08-11 10:56:37 -070064 main.cleanAndExit()
Devin Lim58046fa2017-07-05 16:55:00 -070065 main.testSetUp.envSetupDescription()
66
67 try:
68 onosPackage = main.params[ 'TEST' ][ 'package' ]
69 karafTimeout = main.params[ 'TEST' ][ 'karafCliTimeout' ]
You Wang7d14d642019-01-23 15:10:08 -080070 main.enableIPv6 = main.params[ 'TEST' ][ 'IPv6' ].lower() == "on"
Devin Lim58046fa2017-07-05 16:55:00 -070071 main.caseSleep = int( main.params[ 'TEST' ][ 'caseSleep' ] )
Devin Limc5c9e112017-08-17 15:16:05 -070072 main.onosCell = main.params[ 'ENV' ][ 'cellName' ]
73 main.apps = main.params[ 'ENV' ][ 'cellApps' ]
Devin Lim58046fa2017-07-05 16:55:00 -070074 main.controllers = []
75
76 main.devices = []
77 main.links = []
78 main.hosts = []
79 main.intents = []
80 main.enabledEvents = {}
81 for eventName in main.params[ 'EVENT' ].keys():
82 if main.params[ 'EVENT' ][ eventName ][ 'status' ] == 'on':
83 main.enabledEvents[ int( main.params[ 'EVENT' ][ eventName ][ 'typeIndex' ] ) ] = eventName
Devin Lim58046fa2017-07-05 16:55:00 -070084 main.graph = Graph()
85 main.eventScheduler = EventScheduler()
86 main.eventGenerator = EventGenerator()
87 main.variableLock = Lock()
88 main.mininetLock = Lock()
89 main.ONOSbenchLock = Lock()
90 main.threadID = 0
91 main.eventID = 0
92 main.caseResult = main.TRUE
93 stepResult = main.testSetUp.envSetup()
94 except Exception as e:
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070095 main.testSetUp.envSetupException( e )
Devin Lim58046fa2017-07-05 16:55:00 -070096
97 main.testSetUp.evnSetupConclusion( stepResult )
98
You Wanga0f6ff62018-01-11 15:46:30 -080099 setupResult = main.testSetUp.ONOSSetUp( main.Cluster,
Devin Limc5c9e112017-08-17 15:16:05 -0700100 cellName=main.onosCell )
Devin Lim142b5342017-07-20 15:22:39 -0700101 for i in range( 1, main.Cluster.numCtrls + 1 ):
102 newController = Controller( i )
You Wang7d14d642019-01-23 15:10:08 -0800103 newController.setCLI( main.Cluster.runningNodes[ i - 1 ].CLI )
Devin Lim142b5342017-07-20 15:22:39 -0700104 main.controllers.append( newController )
You Wangdb927a52016-02-26 11:03:28 -0800105
You Wangdb927a52016-02-26 11:03:28 -0800106 main.step( "Start a thread for the scheduler" )
107 t = main.Thread( target=main.eventScheduler.startScheduler,
108 threadID=main.threadID,
109 name="startScheduler",
110 args=[] )
111 t.start()
112 stepResult = main.TRUE
113 with main.variableLock:
114 main.threadID = main.threadID + 1
115
116 utilities.assert_equals( expect=main.TRUE,
117 actual=stepResult,
118 onpass="Test step PASS",
119 onfail="Test step FAIL" )
120
121 main.step( "Start a thread to listen to and handle network, ONOS and application events" )
122 t = main.Thread( target=main.eventGenerator.startListener,
123 threadID=main.threadID,
124 name="startListener",
125 args=[] )
126 t.start()
127 with main.variableLock:
128 main.threadID = main.threadID + 1
129
You Wang7d14d642019-01-23 15:10:08 -0800130 caseResult = setupResult
You Wangdb927a52016-02-26 11:03:28 -0800131 utilities.assert_equals( expect=main.TRUE,
132 actual=caseResult,
133 onpass="Set up test environment PASS",
134 onfail="Set up test environment FAIL" )
135
136 def CASE1( self, main ):
137 """
You Wang7d14d642019-01-23 15:10:08 -0800138 Set IPv6 cfg parameters for Neighbor Discovery
139 """
140 main.step( "Set IPv6 cfg parameters for Neighbor Discovery" )
141 setIPv6CfgSleep = int( main.params[ 'CASE1' ][ 'setIPv6CfgSleep' ] )
142 if main.enableIPv6:
143 time.sleep( setIPv6CfgSleep )
144 cfgResult1 = main.Cluster.active( 0 ).CLI.setCfg( "org.onosproject.net.neighbour.impl.NeighbourResolutionManager",
145 "ndpEnabled",
146 "true" )
147 time.sleep( setIPv6CfgSleep )
148 cfgResult2 = main.Cluster.active( 0 ).CLI.setCfg( "org.onosproject.provider.host.impl.HostLocationProvider",
149 "requestIpv6ND",
150 "true" )
151 else:
152 main.log.info( "Skipped setting IPv6 cfg parameters as it is disabled in params file" )
153 cfgResult1 = main.TRUE
154 cfgResult2 = main.TRUE
155 cfgResult = cfgResult1 and cfgResult2
156 utilities.assert_equals( expect=main.TRUE,
157 actual=cfgResult,
158 onpass="ipv6NeighborDiscovery cfg is set to true",
159 onfail="Failed to cfg set ipv6NeighborDiscovery" )
160
161 def CASE2( self, main ):
162 """
163 Load network configuration files
164 """
165 import json
166 main.case( "Load json files for configuring the network" )
167
168 main.step( "Load json files for configuring the network" )
169 cfgResult = main.TRUE
170 jsonFileName = main.params[ 'CASE2' ][ 'fileName' ]
171 jsonFile = main.testDir + "/dependencies/topologies/json/" + jsonFileName
172 with open( jsonFile ) as cfg:
173 main.Cluster.active( 0 ).REST.setNetCfg( json.load( cfg ) )
174
175 main.step( "Load host files" )
176 hostFileName = main.params[ 'CASE2' ][ 'hostFileName' ]
177 hostFile = main.testDir + "/dependencies/topologies/host/" + hostFileName
178 with open( hostFile ) as cfg:
179 main.expectedHosts = json.load( cfg )
180
181 utilities.assert_equals( expect=main.TRUE,
182 actual=cfgResult,
183 onpass="Correctly loaded network configurations",
184 onfail="Failed to load network configurations" )
185
186 def CASE4( self, main ):
187 """
188 Copy topology lib and config files to Mininet node
You Wangdb927a52016-02-26 11:03:28 -0800189 """
190 import re
You Wang7d14d642019-01-23 15:10:08 -0800191 main.case( "Copy topology lib and config files to Mininet node" )
192
193 copyResult = main.TRUE
194 main.step( "Copy topology lib files to Mininet node" )
195 for libFileName in main.params[ 'CASE4' ][ 'lib' ].split(","):
196 libFile = main.testDir + "/dependencies/topologies/lib/" + libFileName
197 copyResult = copyResult and main.ONOSbench.scp( main.Mininet1,
198 libFile,
199 main.Mininet1.home + "/custom",
200 direction="to" )
201
202 main.step( "Copy topology config files to Mininet node" )
203 controllerIPs = [ ctrl.ipAddress for ctrl in main.Cluster.runningNodes ]
204 index = 0
205 for confFileName in main.params[ 'CASE4' ][ 'conf' ].split(","):
206 confFile = main.testDir + "/dependencies/topologies/conf/" + confFileName
207 # Update zebra configurations with correct ONOS instance IP
208 if confFileName in [ "zebradbgp1.conf", "zebradbgp2.conf" ]:
209 ip = controllerIPs[ index ]
210 index = ( index + 1 ) % len( controllerIPs )
211 with open( confFile ) as f:
212 s = f.read()
213 s = re.sub( r"(fpm connection ip).*(port 2620)", r"\1 " + ip + r" \2", s )
214 with open( confFile, "w" ) as f:
215 f.write( s )
216 copyResult = copyResult and main.ONOSbench.scp( main.Mininet1,
217 confFile,
218 "~/",
219 direction="to" )
220
221 utilities.assert_equals( expect=main.TRUE,
222 actual=copyResult,
223 onpass="Successfully copied topo lib/conf files",
224 onfail="Failed to copy topo lib/conf files" )
225
226 def CASE5( self, main ):
227 """
228 Load Mininet topology and balances all switches
229 """
You Wangdb927a52016-02-26 11:03:28 -0800230 import time
You Wang7d14d642019-01-23 15:10:08 -0800231 import re
You Wangdb927a52016-02-26 11:03:28 -0800232 main.log.report( "Load Mininet topology and Balance all Mininet switches across controllers" )
233 main.log.report( "________________________________________________________________________" )
234 main.case( "Assign and Balance all Mininet switches across controllers" )
235
You Wang7d14d642019-01-23 15:10:08 -0800236 main.step( "Copy Mininet topology files" )
237 main.topoIndex = "topo" + str( main.params[ 'TEST' ][ 'topo' ] )
238 topoFileName = main.params[ 'TOPO' ][ main.topoIndex ][ 'fileName' ]
239 topoFile = main.testDir + "/dependencies/topologies/" + topoFileName
240 copyResult = main.ONOSbench.scp( main.Mininet1, topoFile, main.Mininet1.home + "/custom", direction="to" )
241 utilities.assert_equals( expect=main.TRUE,
242 actual=copyResult,
243 onpass="Successfully copied topo files",
244 onfail="Failed to copy topo files" )
245
You Wangdb927a52016-02-26 11:03:28 -0800246 main.step( "Start Mininet topology" )
You Wang7d14d642019-01-23 15:10:08 -0800247 startStatus = main.Mininet1.startNet( topoFile=main.Mininet1.home + "/custom/" + topoFileName,
248 args=main.params[ 'TOPO' ][ 'mininetArgs' ] )
249 main.mininetSwitches = main.Mininet1.getSwitches( switchClasses=r"(OVSSwitch)" )
You Wangdb927a52016-02-26 11:03:28 -0800250 utilities.assert_equals( expect=main.TRUE,
251 actual=startStatus,
252 onpass="Start Mininet topology test PASS",
253 onfail="Start Mininet topology test FAIL" )
254
255 main.step( "Assign switches to controllers" )
256 switchMastership = main.TRUE
257 for switchName in main.mininetSwitches.keys():
Devin Lim142b5342017-07-20 15:22:39 -0700258 ips = main.Cluster.getIps()
259 main.Mininet1.assignSwController( sw=switchName, ip=ips )
You Wangdb927a52016-02-26 11:03:28 -0800260 response = main.Mininet1.getSwController( switchName )
You Wang7d14d642019-01-23 15:10:08 -0800261 main.log.debug( "Response is " + str( response ) )
Devin Lim142b5342017-07-20 15:22:39 -0700262 if re.search( "tcp:" + main.Cluster.active( 0 ).ipAddress, response ):
You Wangdb927a52016-02-26 11:03:28 -0800263 switchMastership = switchMastership and main.TRUE
264 else:
265 switchMastership = main.FALSE
266 utilities.assert_equals( expect=main.TRUE,
267 actual=switchMastership,
268 onpass="Assign switches to controllers test PASS",
269 onfail="Assign switches to controllers test FAIL" )
270 # Waiting here to make sure topology converges across all nodes
You Wang7d14d642019-01-23 15:10:08 -0800271 sleep = int( main.params[ 'TOPO' ][ 'loadTopoSleep' ] )
You Wangdb927a52016-02-26 11:03:28 -0800272 time.sleep( sleep )
273
274 main.step( "Balance devices across controllers" )
Devin Lim142b5342017-07-20 15:22:39 -0700275 balanceResult = main.Cluster.active( 0 ).CLI.balanceMasters()
You Wangdb927a52016-02-26 11:03:28 -0800276 # giving some breathing time for ONOS to complete re-balance
You Wang7d14d642019-01-23 15:10:08 -0800277 time.sleep( 5 )
278
279 # Get mininet hosts and links
280 main.mininetHosts = main.Mininet1.getHosts()
281 if hasattr( main, "expectedHosts" ):
282 main.mininetHosts = { key: value for key, value in main.mininetHosts.items() if key in main.expectedHosts[ "network" ].keys() }
283 main.mininetLinks = main.Mininet1.getLinks( timeout=60 )
284 main.mininetLinks = [ link for link in main.mininetLinks if
285 link[ 'node1' ] in main.mininetHosts.keys() + main.mininetSwitches.keys() and
286 link[ 'node2' ] in main.mininetHosts.keys() + main.mininetSwitches.keys() ]
You Wangdb927a52016-02-26 11:03:28 -0800287
288 caseResult = ( startStatus and switchMastership and balanceResult )
289 utilities.assert_equals( expect=main.TRUE,
290 actual=caseResult,
291 onpass="Starting new Att topology test PASS",
292 onfail="Starting new Att topology test FAIL" )
293
You Wang7d14d642019-01-23 15:10:08 -0800294 def CASE6( self, main ):
You Wangdb927a52016-02-26 11:03:28 -0800295 """
296 Collect and store device and link data from ONOS
297 """
298 import json
299 from tests.CHOTestMonkey.dependencies.elements.NetworkElement import Device, Link
300
301 main.log.report( "Collect and Store topology details from ONOS" )
302 main.log.report( "____________________________________________________________________" )
303 main.case( "Collect and Store Topology Details from ONOS" )
You Wang7d14d642019-01-23 15:10:08 -0800304
You Wangdb927a52016-02-26 11:03:28 -0800305 topoResult = main.TRUE
Devin Lim142b5342017-07-20 15:22:39 -0700306 topologyOutput = main.Cluster.active( 0 ).CLI.topology()
307 topologyResult = main.Cluster.active( 0 ).CLI.getTopology( topologyOutput )
You Wangdb927a52016-02-26 11:03:28 -0800308 ONOSDeviceNum = int( topologyResult[ 'devices' ] )
309 ONOSLinkNum = int( topologyResult[ 'links' ] )
310 mininetSwitchNum = len( main.mininetSwitches )
311 mininetLinkNum = ( len( main.mininetLinks ) - len( main.mininetHosts ) ) * 2
312 if mininetSwitchNum == ONOSDeviceNum and mininetLinkNum == ONOSLinkNum:
313 main.step( "Collect and store device data" )
314 stepResult = main.TRUE
315 dpidToName = {}
316 for key, value in main.mininetSwitches.items():
317 dpidToName[ 'of:' + str( value[ 'dpid' ] ) ] = key
You Wang7d14d642019-01-23 15:10:08 -0800318 main.devicesRaw = main.Cluster.active( 0 ).CLI.devices()
319 devices = json.loads( main.devicesRaw )
You Wangdb927a52016-02-26 11:03:28 -0800320 deviceInitIndex = 0
321 for device in devices:
322 name = dpidToName[ device[ 'id' ] ]
323 newDevice = Device( deviceInitIndex, name, device[ 'id' ] )
You Wang7d14d642019-01-23 15:10:08 -0800324 main.log.info( 'New device: {}'.format( newDevice ) )
You Wangdb927a52016-02-26 11:03:28 -0800325 main.devices.append( newDevice )
326 deviceInitIndex += 1
327 utilities.assert_equals( expect=main.TRUE,
328 actual=stepResult,
329 onpass="Successfully collected and stored device data",
330 onfail="Failed to collect and store device data" )
331
332 main.step( "Collect and store link data" )
333 stepResult = main.TRUE
You Wang7d14d642019-01-23 15:10:08 -0800334 main.linksRaw = main.Cluster.active( 0 ).CLI.links()
335 links = json.loads( main.linksRaw )
You Wangdb927a52016-02-26 11:03:28 -0800336 linkInitIndex = 0
337 for link in links:
338 for device in main.devices:
339 if device.dpid == link[ 'src' ][ 'device' ]:
340 deviceA = device
341 elif device.dpid == link[ 'dst' ][ 'device' ]:
342 deviceB = device
Jon Hall2bb3e212017-05-24 17:07:25 -0700343 assert deviceA is not None and deviceB is not None
You Wangdb927a52016-02-26 11:03:28 -0800344 newLink = Link( linkInitIndex, deviceA, link[ 'src' ][ 'port' ], deviceB, link[ 'dst' ][ 'port' ] )
You Wang7d14d642019-01-23 15:10:08 -0800345 main.log.info( 'New link: {}'.format( newLink ) )
You Wangdb927a52016-02-26 11:03:28 -0800346 main.links.append( newLink )
347 linkInitIndex += 1
348 # Set backward links and outgoing links of devices
349 for linkA in main.links:
350 linkA.deviceA.outgoingLinks.append( linkA )
Jon Hall2bb3e212017-05-24 17:07:25 -0700351 if linkA.backwardLink is not None:
You Wangdb927a52016-02-26 11:03:28 -0800352 continue
353 for linkB in main.links:
Jon Hall2bb3e212017-05-24 17:07:25 -0700354 if linkB.backwardLink is not None:
You Wangdb927a52016-02-26 11:03:28 -0800355 continue
356 if linkA.deviceA == linkB.deviceB and\
Jon Hall2bb3e212017-05-24 17:07:25 -0700357 linkA.deviceB == linkB.deviceA and\
358 linkA.portA == linkB.portB and\
359 linkA.portB == linkB.portA:
You Wangdb927a52016-02-26 11:03:28 -0800360 linkA.setBackwardLink( linkB )
361 linkB.setBackwardLink( linkA )
362 utilities.assert_equals( expect=main.TRUE,
363 actual=stepResult,
364 onpass="Successfully collected and stored link data",
365 onfail="Failed to collect and store link data" )
366 else:
367 main.log.info( "Devices (expected): %s, Links (expected): %s" % ( mininetSwitchNum, mininetLinkNum ) )
368 main.log.info( "Devices (actual): %s, Links (actual): %s" % ( ONOSDeviceNum, ONOSLinkNum ) )
369 topoResult = main.FALSE
370
371 caseResult = topoResult
372 utilities.assert_equals( expect=main.TRUE,
373 actual=caseResult,
374 onpass="Saving ONOS topology data test PASS",
375 onfail="Saving ONOS topology data test FAIL" )
376
377 if not caseResult:
Jon Hall2bb3e212017-05-24 17:07:25 -0700378 main.log.info( "Topology does not match, exiting test..." )
Devin Lim44075962017-08-11 10:56:37 -0700379 main.cleanAndExit()
You Wangdb927a52016-02-26 11:03:28 -0800380
You Wang7d14d642019-01-23 15:10:08 -0800381 def CASE7( self, main ):
You Wangdb927a52016-02-26 11:03:28 -0800382 """
383 Collect and store host data from ONOS
384 """
385 import json
386 from tests.CHOTestMonkey.dependencies.elements.NetworkElement import Host
387
388 main.log.report( "Collect and store host adta from ONOS" )
389 main.log.report( "______________________________________________" )
You Wang7d14d642019-01-23 15:10:08 -0800390 main.case( "Use fwd app and pingall to discover all the hosts if necessary, then collect and store host data" )
You Wangdb927a52016-02-26 11:03:28 -0800391
You Wang7d14d642019-01-23 15:10:08 -0800392 if main.params[ 'TEST' ][ 'dataPlaneConnectivity' ] == 'False':
393 main.step( "Enable Reactive forwarding" )
394 appResult = main.Cluster.active( 0 ).CLI.activateApp( "org.onosproject.fwd" )
395 cfgResult1 = main.TRUE
396 cfgResult2 = main.TRUE
397 if main.enableIPv6:
398 cfgResult1 = main.Cluster.active( 0 ).CLI.setCfg( "org.onosproject.fwd.ReactiveForwarding", "ipv6Forwarding", "true" )
399 cfgResult2 = main.Cluster.active( 0 ).CLI.setCfg( "org.onosproject.fwd.ReactiveForwarding", "matchIpv6Address", "true" )
400 stepResult = appResult and cfgResult1 and cfgResult2
401 utilities.assert_equals( expect=main.TRUE,
402 actual=stepResult,
403 onpass="Successfully enabled reactive forwarding",
404 onfail="Failed to enable reactive forwarding" )
You Wangdb927a52016-02-26 11:03:28 -0800405
You Wang7d14d642019-01-23 15:10:08 -0800406 main.step( "Discover hosts using pingall" )
407 main.Mininet1.pingall()
408 if main.enableIPv6:
409 ping6Result = main.Mininet1.pingall( protocol="IPv6" )
410
411 main.step( "Disable Reactive forwarding" )
412 appResult = main.Cluster.active( 0 ).CLI.deactivateApp( "org.onosproject.fwd" )
413 stepResult = appResult
414 utilities.assert_equals( expect=main.TRUE,
415 actual=stepResult,
416 onpass="Successfully deactivated fwd app",
417 onfail="Failed to deactivate fwd app" )
418
419 main.step( "Verify host discovery" )
You Wangdb927a52016-02-26 11:03:28 -0800420 stepResult = main.TRUE
You Wang7d14d642019-01-23 15:10:08 -0800421 main.hostsRaw = main.Cluster.active( 0 ).CLI.hosts()
422 hosts = json.loads( main.hostsRaw )
423 if hasattr( main, "expectedHosts" ):
424 hosts = [ host for host in hosts if host[ 'id' ] in main.expectedHosts[ 'onos' ].keys() ]
You Wangdb927a52016-02-26 11:03:28 -0800425 if not len( hosts ) == len( main.mininetHosts ):
426 stepResult = main.FALSE
427 utilities.assert_equals( expect=main.TRUE,
428 actual=stepResult,
429 onpass="Host discovery PASS",
430 onfail="Host discovery FAIL" )
431 if not stepResult:
432 main.log.debug( hosts )
Devin Lim44075962017-08-11 10:56:37 -0700433 main.cleanAndExit()
You Wangdb927a52016-02-26 11:03:28 -0800434
You Wangdb927a52016-02-26 11:03:28 -0800435 main.step( "Collect and store host data" )
436 stepResult = main.TRUE
437 macToName = {}
438 for key, value in main.mininetHosts.items():
439 macToName[ value[ 'interfaces' ][ 0 ][ 'mac' ].upper() ] = key
440 dpidToDevice = {}
441 for device in main.devices:
442 dpidToDevice[ device.dpid ] = device
443 hostInitIndex = 0
444 for host in hosts:
445 name = macToName[ host[ 'mac' ] ]
You Wang7d14d642019-01-23 15:10:08 -0800446 devices = {}
447 for location in host[ 'locations' ]:
448 device = dpidToDevice[ location[ 'elementId' ] ]
449 devices[ device ] = location[ 'port' ]
You Wangdb927a52016-02-26 11:03:28 -0800450 newHost = Host( hostInitIndex,
451 name, host[ 'id' ], host[ 'mac' ],
You Wang7d14d642019-01-23 15:10:08 -0800452 devices,
You Wangdb927a52016-02-26 11:03:28 -0800453 host[ 'vlan' ], host[ 'ipAddresses' ] )
You Wang7d14d642019-01-23 15:10:08 -0800454 main.log.info( 'New host: {}'.format( newHost ) )
You Wangdb927a52016-02-26 11:03:28 -0800455 main.hosts.append( newHost )
You Wangdb927a52016-02-26 11:03:28 -0800456 hostInitIndex += 1
You Wang7d14d642019-01-23 15:10:08 -0800457 for location in host[ 'locations' ]:
458 device = dpidToDevice[ location[ 'elementId' ] ]
459 main.devices[ device.index ].hosts[ newHost ] = location[ 'port' ]
460
461 # Collect IPv4 and IPv6 hosts
462 main.ipv4Hosts = []
463 main.ipv6Hosts = []
464 for host in main.hosts:
465 if any( re.match( str( main.params[ 'TEST' ][ 'ipv6Regex' ] ), ipAddress ) for ipAddress in host.ipAddresses ):
466 main.ipv6Hosts.append( host )
467 if any( re.match( str( main.params[ 'TEST' ][ 'ipv4Regex' ] ), ipAddress ) for ipAddress in host.ipAddresses ):
468 main.ipv4Hosts.append( host )
You Wangdb927a52016-02-26 11:03:28 -0800469 utilities.assert_equals( expect=main.TRUE,
470 actual=stepResult,
471 onpass="Successfully collected and stored host data",
472 onfail="Failed to collect and store host data" )
473
474 main.step( "Create one host component for each host and then start host cli" )
You Wang7d14d642019-01-23 15:10:08 -0800475 startCLIResult = main.TRUE
You Wangdb927a52016-02-26 11:03:28 -0800476 for host in main.hosts:
477 main.Mininet1.createHostComponent( host.name )
478 hostHandle = getattr( main, host.name )
479 main.log.info( "Starting CLI on host " + str( host.name ) )
You Wang7d14d642019-01-23 15:10:08 -0800480 startCLIResult = startCLIResult and hostHandle.startHostCli()
You Wangdb927a52016-02-26 11:03:28 -0800481 host.setHandle( hostHandle )
You Wang7d14d642019-01-23 15:10:08 -0800482 if main.params[ 'TEST' ][ 'dataPlaneConnectivity' ] == 'True':
483 # Hosts should already be able to ping each other
484 if host in main.ipv4Hosts:
485 host.correspondents += main.ipv4Hosts
486 if host in main.ipv6Hosts:
487 host.correspondents += main.ipv6Hosts
488 utilities.assert_equals( expect=main.TRUE,
489 actual=startCLIResult,
490 onpass="Host CLI started",
491 onfail="Failed to start host CLI" )
You Wangdb927a52016-02-26 11:03:28 -0800492
493 def CASE10( self, main ):
494 """
495 Run all enabled checks
496 """
497 import time
498 from tests.CHOTestMonkey.dependencies.events.Event import EventType
499 from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod
500
501 main.log.report( "Run all enabled checks" )
502 main.log.report( "__________________________________________________" )
503 main.case( "Run all enabled checks" )
504 main.step( "Run all enabled checks" )
505 main.caseResult = main.TRUE
506 main.eventGenerator.triggerEvent( EventType().CHECK_ALL, EventScheduleMethod().RUN_BLOCK )
507 # Wait for the scheduler to become idle before going to the next testcase
508 with main.eventScheduler.idleCondition:
509 while not main.eventScheduler.isIdle():
510 main.eventScheduler.idleCondition.wait()
511 utilities.assert_equals( expect=main.TRUE,
512 actual=main.caseResult,
513 onpass="All enabled checks passed",
514 onfail="Not all enabled checks passed" )
515 time.sleep( main.caseSleep )
516
517 def CASE20( self, main ):
518 """
519 Bring down/up links and check topology and ping
520 """
521 import time
522 from tests.CHOTestMonkey.dependencies.events.Event import EventType
523 from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod
524
525 main.log.report( "Bring down/up links and check topology and ping" )
526 main.log.report( "__________________________________________________" )
527 main.case( "Bring down/up links and check topology and ping" )
528 main.step( "Bring down/up links and check topology and ping" )
529 main.caseResult = main.TRUE
530 linkToggleNum = int( main.params[ 'CASE20' ][ 'linkToggleNum' ] )
531 linkDownUpInterval = int( main.params[ 'CASE20' ][ 'linkDownUpInterval' ] )
532 for i in range( 0, linkToggleNum ):
533 main.eventGenerator.triggerEvent( EventType().NETWORK_LINK_RANDOM_TOGGLE, EventScheduleMethod().RUN_BLOCK, linkDownUpInterval )
534 with main.eventScheduler.idleCondition:
535 while not main.eventScheduler.isIdle():
536 main.eventScheduler.idleCondition.wait()
537 utilities.assert_equals( expect=main.TRUE,
538 actual=main.caseResult,
539 onpass="Toggle network links test passed",
540 onfail="Toggle network links test failed" )
541 time.sleep( main.caseSleep )
542
543 def CASE21( self, main ):
544 """
545 Bring down/up a group of links and check topology and ping
546 """
547 import time
548 from tests.CHOTestMonkey.dependencies.events.Event import EventType
549 from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod
550
551 main.log.report( "Bring down/up a group of links and check topology and ping" )
552 main.log.report( "__________________________________________________" )
553 main.case( "Bring down/up a group of links and check topology and ping" )
554 main.step( "Bring down/up a group of links and check topology and ping" )
555 main.caseResult = main.TRUE
556 linkGroupSize = int( main.params[ 'CASE21' ][ 'linkGroupSize' ] )
557 linkDownDownInterval = int( main.params[ 'CASE21' ][ 'linkDownDownInterval' ] )
558 linkDownUpInterval = int( main.params[ 'CASE21' ][ 'linkDownUpInterval' ] )
559 main.eventGenerator.triggerEvent( EventType().NETWORK_LINK_GROUP_RANDOM_TOGGLE, EventScheduleMethod().RUN_BLOCK, linkGroupSize, linkDownDownInterval, linkDownUpInterval )
560 with main.eventScheduler.idleCondition:
561 while not main.eventScheduler.isIdle():
562 main.eventScheduler.idleCondition.wait()
563 utilities.assert_equals( expect=main.TRUE,
564 actual=main.caseResult,
565 onpass="Toggle network link group test passed",
566 onfail="Toggle network link group test failed" )
567 time.sleep( main.caseSleep )
568
569 def CASE30( self, main ):
570 """
571 Install host intents and check intent states and ping
572 """
573 import time
574 from tests.CHOTestMonkey.dependencies.events.Event import EventType
575 from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod
576
577 main.log.report( "Install host intents and check intent states and ping" )
578 main.log.report( "__________________________________________________" )
579 main.case( "Install host intents and check intent states and ping" )
580 main.step( "Install host intents and check intent states and ping" )
581 main.caseResult = main.TRUE
582 main.eventGenerator.triggerEvent( EventType().APP_INTENT_HOST_ADD_ALL, EventScheduleMethod().RUN_BLOCK )
583 with main.eventScheduler.idleCondition:
584 while not main.eventScheduler.isIdle():
585 main.eventScheduler.idleCondition.wait()
586 utilities.assert_equals( expect=main.TRUE,
587 actual=main.caseResult,
588 onpass="Install host intents test passed",
589 onfail="Install host intents test failed" )
590 time.sleep( main.caseSleep )
591
592 def CASE31( self, main ):
593 """
594 Uninstall host intents and check intent states and ping
595 """
596 import time
597 from tests.CHOTestMonkey.dependencies.events.Event import EventType
598 from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod
599
600 main.log.report( "Uninstall host intents and check intent states and ping" )
601 main.log.report( "__________________________________________________" )
602 main.case( "Uninstall host intents and check intent states and ping" )
603 main.step( "Uninstall host intents and check intent states and ping" )
604 main.caseResult = main.TRUE
605 main.eventGenerator.triggerEvent( EventType().APP_INTENT_HOST_DEL_ALL, EventScheduleMethod().RUN_BLOCK )
606 with main.eventScheduler.idleCondition:
607 while not main.eventScheduler.isIdle():
608 main.eventScheduler.idleCondition.wait()
609 utilities.assert_equals( expect=main.TRUE,
610 actual=main.caseResult,
611 onpass="Uninstall host intents test passed",
612 onfail="Uninstall host intents test failed" )
613 time.sleep( main.caseSleep )
614
615 def CASE32( self, main ):
616 """
617 Install point intents and check intent states and ping
618 """
619 import time
620 from tests.CHOTestMonkey.dependencies.events.Event import EventType
621 from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod
622
623 main.log.report( "Install point intents and check intent states and ping" )
624 main.log.report( "__________________________________________________" )
625 main.case( "Install point intents and check intent states and ping" )
626 main.step( "Install point intents and check intent states and ping" )
627 main.caseResult = main.TRUE
628 main.eventGenerator.triggerEvent( EventType().APP_INTENT_POINT_ADD_ALL, EventScheduleMethod().RUN_BLOCK )
629 with main.eventScheduler.idleCondition:
630 while not main.eventScheduler.isIdle():
631 main.eventScheduler.idleCondition.wait()
632 utilities.assert_equals( expect=main.TRUE,
633 actual=main.caseResult,
634 onpass="Install point intents test passed",
635 onfail="Install point intents test failed" )
636 time.sleep( main.caseSleep )
637
638 def CASE33( self, main ):
639 """
640 Uninstall point intents and check intent states and ping
641 """
642 import time
643 from tests.CHOTestMonkey.dependencies.events.Event import EventType
644 from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod
645
646 main.log.report( "Uninstall point intents and check intent states and ping" )
647 main.log.report( "__________________________________________________" )
648 main.case( "Uninstall point intents and check intent states and ping" )
649 main.step( "Uninstall point intents and check intent states and ping" )
650 main.caseResult = main.TRUE
651 main.eventGenerator.triggerEvent( EventType().APP_INTENT_POINT_DEL_ALL, EventScheduleMethod().RUN_BLOCK )
652 with main.eventScheduler.idleCondition:
653 while not main.eventScheduler.isIdle():
654 main.eventScheduler.idleCondition.wait()
655 utilities.assert_equals( expect=main.TRUE,
656 actual=main.caseResult,
657 onpass="Uninstall point intents test passed",
658 onfail="Uninstall point intents test failed" )
659 time.sleep( main.caseSleep )
660
661 def CASE40( self, main ):
662 """
663 Randomly bring down one ONOS node
664 """
665 import time
666 import random
667 from tests.CHOTestMonkey.dependencies.events.Event import EventType
668 from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod
669
670 main.log.report( "Randomly bring down one ONOS node" )
671 main.log.report( "__________________________________________________" )
672 main.case( "Randomly bring down one ONOS node" )
673 main.step( "Randomly bring down one ONOS node" )
674 main.caseResult = main.TRUE
675 availableControllers = []
676 for controller in main.controllers:
677 if controller.isUp():
678 availableControllers.append( controller.index )
679 if len( availableControllers ) == 0:
680 main.log.warn( "No available controllers" )
681 main.caseResult = main.FALSE
682 else:
683 index = random.sample( availableControllers, 1 )
684 main.eventGenerator.triggerEvent( EventType().ONOS_ONOS_DOWN, EventScheduleMethod().RUN_BLOCK, index[ 0 ] )
685 with main.eventScheduler.idleCondition:
686 while not main.eventScheduler.isIdle():
687 main.eventScheduler.idleCondition.wait()
688 utilities.assert_equals( expect=main.TRUE,
689 actual=main.caseResult,
690 onpass="Randomly bring down ONOS test passed",
691 onfail="Randomly bring down ONOS test failed" )
You Wange8c2b042019-01-22 15:07:25 -0800692 time.sleep( int( main.params[ 'CASE40' ][ 'sleepSec' ] ) )
You Wangdb927a52016-02-26 11:03:28 -0800693
694 def CASE41( self, main ):
695 """
696 Randomly bring up one ONOS node that is down
697 """
698 import time
699 import random
700 from tests.CHOTestMonkey.dependencies.events.Event import EventType
701 from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod
702
703 main.log.report( "Randomly bring up one ONOS node that is down" )
704 main.log.report( "__________________________________________________" )
705 main.case( "Randomly bring up one ONOS node that is down" )
706 main.step( "Randomly bring up one ONOS node that is down" )
707 main.caseResult = main.TRUE
708 targetControllers = []
709 for controller in main.controllers:
710 if not controller.isUp():
711 targetControllers.append( controller.index )
712 if len( targetControllers ) == 0:
713 main.log.warn( "All controllers are up" )
714 main.caseResult = main.FALSE
715 else:
716 index = random.sample( targetControllers, 1 )
717 main.eventGenerator.triggerEvent( EventType().ONOS_ONOS_UP, EventScheduleMethod().RUN_BLOCK, index[ 0 ] )
718 with main.eventScheduler.idleCondition:
719 while not main.eventScheduler.isIdle():
720 main.eventScheduler.idleCondition.wait()
721 utilities.assert_equals( expect=main.TRUE,
722 actual=main.caseResult,
723 onpass="Randomly bring up ONOS test passed",
724 onfail="Randomly bring up ONOS test failed" )
You Wange8c2b042019-01-22 15:07:25 -0800725 time.sleep( int( main.params[ 'CASE41' ][ 'sleepSec' ] ) )
You Wangdb927a52016-02-26 11:03:28 -0800726
727 def CASE50( self, main ):
728 """
729 Set FlowObjective to True
730 """
731 import time
732 from tests.CHOTestMonkey.dependencies.events.Event import EventType
733 from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod
734
735 main.log.report( "Set FlowObjective to True" )
736 main.log.report( "__________________________________________________" )
737 main.case( "Set FlowObjective to True" )
738 main.step( "Set FlowObjective to True" )
739 main.caseResult = main.TRUE
740 main.eventGenerator.triggerEvent( EventType().ONOS_SET_FLOWOBJ, EventScheduleMethod().RUN_BLOCK, 'true' )
741 with main.eventScheduler.idleCondition:
742 while not main.eventScheduler.isIdle():
743 main.eventScheduler.idleCondition.wait()
744 utilities.assert_equals( expect=main.TRUE,
745 actual=main.caseResult,
746 onpass="Set FlowObjective test passed",
747 onfail="Set FlowObjective test failed" )
748 time.sleep( main.caseSleep )
749
750 def CASE51( self, main ):
751 """
752 Set FlowObjective to False
753 """
754 import time
755 from tests.CHOTestMonkey.dependencies.events.Event import EventType
756 from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod
757
758 main.log.report( "Set FlowObjective to False" )
759 main.log.report( "__________________________________________________" )
760 main.case( "Set FlowObjective to False" )
761 main.step( "Set FlowObjective to False" )
762 main.caseResult = main.TRUE
763 main.eventGenerator.triggerEvent( EventType().ONOS_SET_FLOWOBJ, EventScheduleMethod().RUN_BLOCK, 'false' )
764 with main.eventScheduler.idleCondition:
765 while not main.eventScheduler.isIdle():
766 main.eventScheduler.idleCondition.wait()
767 utilities.assert_equals( expect=main.TRUE,
768 actual=main.caseResult,
769 onpass="Set FlowObjective test passed",
770 onfail="Set FlowObjective test failed" )
771 time.sleep( main.caseSleep )
772
773 def CASE60( self, main ):
774 """
775 Balance device masters
776 """
777 import time
778 from tests.CHOTestMonkey.dependencies.events.Event import EventType
779 from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod
780
781 main.log.report( "Balance device masters" )
782 main.log.report( "__________________________________________________" )
783 main.case( "Balance device masters" )
784 main.step( "Balance device masters" )
785 main.caseResult = main.TRUE
786 main.eventGenerator.triggerEvent( EventType().ONOS_BALANCE_MASTERS, EventScheduleMethod().RUN_BLOCK )
787 with main.eventScheduler.idleCondition:
788 while not main.eventScheduler.isIdle():
789 main.eventScheduler.idleCondition.wait()
790 utilities.assert_equals( expect=main.TRUE,
791 actual=main.caseResult,
792 onpass="Balance masters test passed",
793 onfail="Balance masters test failed" )
794 time.sleep( main.caseSleep )
795
You Wang7a27f3a2016-07-05 10:12:27 -0700796 def CASE70( self, main ):
797 """
798 Randomly generate events
799 """
800 import time
801 import random
802 from tests.CHOTestMonkey.dependencies.events.Event import EventType
803 from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod
804
805 main.log.report( "Randomly generate events" )
806 main.log.report( "__________________________________________________" )
807 main.case( "Randomly generate events" )
808 main.step( "Randomly generate events" )
809 main.caseResult = main.TRUE
810 sleepSec = int( main.params[ 'CASE70' ][ 'sleepSec' ] )
811 hostIntentNum = 0
812 pointIntentNum = 0
813 downDeviceNum = 0
814 downLinkNum = 0
You Wang7d14d642019-01-23 15:10:08 -0800815 downPortNum = 0
816 downOnosNum = 0
You Wangf6e98a82016-11-14 14:46:49 -0800817 flowObj = False
You Wang7d14d642019-01-23 15:10:08 -0800818 upControllers = range( 1, int( main.params[ 'TEST' ][ 'numCtrl' ] ) + 1 )
You Wang7a27f3a2016-07-05 10:12:27 -0700819 while True:
820 events = []
You Wangf6e98a82016-11-14 14:46:49 -0800821 for i in range( int( main.params[ 'CASE70' ][ 'toggleFlowObj' ] ) ):
822 events.append( 'toggle-flowobj' )
You Wang7a27f3a2016-07-05 10:12:27 -0700823 for i in range( int( main.params[ 'CASE70' ][ 'addHostIntentWeight' ] ) ):
824 events.append( 'add-host-intent' )
825 for i in range( int( main.params[ 'CASE70' ][ 'addPointIntentWeight' ] ) ):
826 events.append( 'add-point-intent' )
827 for i in range( int( main.params[ 'CASE70' ][ 'linkDownWeight' ] ) ):
828 events.append( 'link-down' )
829 for i in range( int( main.params[ 'CASE70' ][ 'deviceDownWeight' ] ) ):
830 events.append( 'device-down' )
You Wang7d14d642019-01-23 15:10:08 -0800831 for i in range( int( main.params[ 'CASE70' ][ 'portDownWeight' ] ) ):
832 events.append( 'port-down' )
833 if downOnosNum == 0:
834 for i in range( int( main.params[ 'CASE70' ][ 'onosDownWeight' ] ) ):
835 events.append( 'onos-down' )
You Wang7a27f3a2016-07-05 10:12:27 -0700836 for i in range( int( pow( hostIntentNum, 1.5 ) / 100 ) ):
837 events.append( 'del-host-intent' )
You Wang52163202016-07-14 16:37:15 -0700838 for i in range( int( pow( pointIntentNum, 1.5 ) / 100 ) ):
You Wang7a27f3a2016-07-05 10:12:27 -0700839 events.append( 'del-point-intent' )
You Wang7d14d642019-01-23 15:10:08 -0800840 for i in range( pow( 4, downLinkNum ) - 1 ):
You Wang7a27f3a2016-07-05 10:12:27 -0700841 events.append( 'link-up' )
You Wang7d14d642019-01-23 15:10:08 -0800842 for i in range( pow( 4, downDeviceNum ) - 1 ):
You Wang7a27f3a2016-07-05 10:12:27 -0700843 events.append( 'device-up' )
You Wang7d14d642019-01-23 15:10:08 -0800844 for i in range( pow( 4, downPortNum ) - 1 ):
845 events.append( 'port-up' )
846 for i in range( pow( 4, downOnosNum ) - 1 ):
847 events.append( 'onos-up' )
You Wang7a27f3a2016-07-05 10:12:27 -0700848 main.log.debug( events )
849 event = random.sample( events, 1 )[ 0 ]
850 if event == 'add-host-intent':
851 n = random.randint( 5, 50 )
852 for i in range( n ):
853 cliIndex = random.sample( upControllers, 1 )[ 0 ]
You Wangc848af12016-07-14 09:53:58 -0700854 main.eventGenerator.triggerEvent( EventType().APP_INTENT_HOST_ADD, EventScheduleMethod().RUN_BLOCK, 'random', 'random', cliIndex )
You Wang7a27f3a2016-07-05 10:12:27 -0700855 hostIntentNum += 1
You Wang7a27f3a2016-07-05 10:12:27 -0700856 elif event == 'del-host-intent':
857 n = random.randint( 5, hostIntentNum )
858 for i in range( n ):
859 cliIndex = random.sample( upControllers, 1 )[ 0 ]
You Wangc848af12016-07-14 09:53:58 -0700860 main.eventGenerator.triggerEvent( EventType().APP_INTENT_HOST_DEL, EventScheduleMethod().RUN_BLOCK, 'random', 'random', cliIndex )
You Wang7a27f3a2016-07-05 10:12:27 -0700861 hostIntentNum -= 1
You Wang7a27f3a2016-07-05 10:12:27 -0700862 elif event == 'add-point-intent':
863 n = random.randint( 5, 50 )
864 for i in range( n ):
865 cliIndex = random.sample( upControllers, 1 )[ 0 ]
You Wangc848af12016-07-14 09:53:58 -0700866 main.eventGenerator.triggerEvent( EventType().APP_INTENT_POINT_ADD, EventScheduleMethod().RUN_BLOCK, 'random', 'random', cliIndex, 'bidirectional' )
You Wang52163202016-07-14 16:37:15 -0700867 pointIntentNum += 2
You Wang7a27f3a2016-07-05 10:12:27 -0700868 elif event == 'del-point-intent':
You Wang52163202016-07-14 16:37:15 -0700869 n = random.randint( 5, pointIntentNum / 2 )
You Wang7a27f3a2016-07-05 10:12:27 -0700870 for i in range( n ):
871 cliIndex = random.sample( upControllers, 1 )[ 0 ]
You Wangc848af12016-07-14 09:53:58 -0700872 main.eventGenerator.triggerEvent( EventType().APP_INTENT_POINT_DEL, EventScheduleMethod().RUN_BLOCK, 'random', 'random', cliIndex, 'bidirectional' )
You Wang52163202016-07-14 16:37:15 -0700873 pointIntentNum -= 2
You Wang7a27f3a2016-07-05 10:12:27 -0700874 elif event == 'link-down':
875 main.eventGenerator.triggerEvent( EventType().NETWORK_LINK_DOWN, EventScheduleMethod().RUN_BLOCK, 'random', 'random' )
876 downLinkNum += 1
877 elif event == 'link-up':
878 main.eventGenerator.triggerEvent( EventType().NETWORK_LINK_UP, EventScheduleMethod().RUN_BLOCK, 'random', 'random' )
879 downLinkNum -= 1
880 elif event == 'device-down':
881 main.eventGenerator.triggerEvent( EventType().NETWORK_DEVICE_DOWN, EventScheduleMethod().RUN_BLOCK, 'random' )
882 downDeviceNum += 1
883 elif event == 'device-up':
884 main.eventGenerator.triggerEvent( EventType().NETWORK_DEVICE_UP, EventScheduleMethod().RUN_BLOCK, 'random' )
885 downDeviceNum -= 1
You Wang7d14d642019-01-23 15:10:08 -0800886 elif event == 'port-down':
887 main.eventGenerator.triggerEvent( EventType().NETWORK_PORT_DOWN, EventScheduleMethod().RUN_BLOCK, 'random', 'random' )
888 downPortNum += 1
889 elif event == 'port-up':
890 main.eventGenerator.triggerEvent( EventType().NETWORK_PORT_UP, EventScheduleMethod().RUN_BLOCK, 'random', 'random' )
891 downPortNum -= 1
892 elif event == 'onos-down':
893 main.eventGenerator.triggerEvent( EventType().ONOS_ONOS_DOWN, EventScheduleMethod().RUN_BLOCK, 1 )
894 downOnosNum += 1
895 elif event == 'onos-up':
896 main.eventGenerator.triggerEvent( EventType().ONOS_ONOS_UP, EventScheduleMethod().RUN_BLOCK, 1 )
897 downOnosNum -= 1
898 main.eventGenerator.triggerEvent( EventType().ONOS_BALANCE_MASTERS, EventScheduleMethod().RUN_BLOCK )
You Wangf6e98a82016-11-14 14:46:49 -0800899 elif event == 'toggle-flowobj':
Jon Hall2bb3e212017-05-24 17:07:25 -0700900 if not flowObj:
You Wangf6e98a82016-11-14 14:46:49 -0800901 main.eventGenerator.triggerEvent( EventType().ONOS_SET_FLOWOBJ, EventScheduleMethod().RUN_BLOCK, 'true' )
902 else:
903 main.eventGenerator.triggerEvent( EventType().ONOS_SET_FLOWOBJ, EventScheduleMethod().RUN_BLOCK, 'false' )
904 flowObj = not flowObj
You Wang7a27f3a2016-07-05 10:12:27 -0700905 else:
906 pass
907 main.eventGenerator.triggerEvent( EventType().CHECK_TOPO, EventScheduleMethod().RUN_NON_BLOCK )
908 main.eventGenerator.triggerEvent( EventType().CHECK_ONOS, EventScheduleMethod().RUN_NON_BLOCK )
909 main.eventGenerator.triggerEvent( EventType().CHECK_TRAFFIC, EventScheduleMethod().RUN_NON_BLOCK )
910 main.eventGenerator.triggerEvent( EventType().CHECK_FLOW, EventScheduleMethod().RUN_NON_BLOCK )
911 main.eventGenerator.triggerEvent( EventType().CHECK_INTENT, EventScheduleMethod().RUN_NON_BLOCK )
Devin Limf0822182017-09-12 14:52:57 -0700912 main.eventGenerator.triggerEvent( EventType().CHECK_RAFT_LOG_SIZE, EventScheduleMethod().RUN_NON_BLOCK )
You Wang7a27f3a2016-07-05 10:12:27 -0700913 with main.eventScheduler.idleCondition:
914 while not main.eventScheduler.isIdle():
915 main.eventScheduler.idleCondition.wait()
You Wang5f4f36e2016-09-21 15:30:30 -0700916 time.sleep( sleepSec )
You Wang7a27f3a2016-07-05 10:12:27 -0700917 utilities.assert_equals( expect=main.TRUE,
918 actual=main.caseResult,
919 onpass="Randomly generate events test passed",
920 onfail="Randomly generate events test failed" )
921 time.sleep( main.caseSleep )
922
You Wang52163202016-07-14 16:37:15 -0700923 def CASE80( self, main ):
924 """
925 Replay events from log file
926 """
927 import time
928 from tests.CHOTestMonkey.dependencies.events.Event import EventType
929 from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod
930
931 main.log.report( "Replay events from log file" )
932 main.log.report( "__________________________________________________" )
933 main.case( "Replay events from log file" )
934 main.step( "Replay events from log file" )
935 main.caseResult = main.TRUE
936 try:
937 f = open( main.params[ 'CASE80' ][ 'filePath' ], 'r' )
938 for line in f.readlines():
939 if 'CHOTestMonkey' in line and 'Event recorded' in line:
940 line = line.split()
941 eventIndex = int( line[ 9 ] )
942 eventName = line[ 10 ]
943 args = line[ 11: ]
944 assert eventName.startswith( 'CHECK' )\
Jon Hall2bb3e212017-05-24 17:07:25 -0700945 or eventName.startswith( 'NETWORK' )\
946 or eventName.startswith( 'APP' )\
947 or eventName.startswith( 'ONOS' )
You Wang52163202016-07-14 16:37:15 -0700948 if main.params[ 'CASE80' ][ 'skipChecks' ] == 'on' and eventName.startswith( 'CHECK' ):
949 continue
950 with main.eventScheduler.idleCondition:
951 while not main.eventScheduler.isIdle():
952 main.eventScheduler.idleCondition.wait()
953 main.eventGenerator.triggerEvent( eventIndex, EventScheduleMethod().RUN_BLOCK, *args )
954 time.sleep( float( main.params[ 'CASE80' ][ 'sleepTime' ] ) )
955 except Exception as e:
You Wang7d14d642019-01-23 15:10:08 -0800956 main.log.error( "Uncaught exception: {}".format( e ) )
You Wang52163202016-07-14 16:37:15 -0700957 utilities.assert_equals( expect=main.TRUE,
958 actual=main.caseResult,
959 onpass="Replay from log file passed",
960 onfail="Replay from log file failed" )
961
You Wangdb927a52016-02-26 11:03:28 -0800962 def CASE90( self, main ):
963 """
964 Sleep for some time
965 """
966 import time
967 from tests.CHOTestMonkey.dependencies.events.Event import EventType
968 from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod
969
970 main.log.report( "Sleep for some time" )
971 main.log.report( "__________________________________________________" )
972 main.case( "Sleep for some time" )
973 main.step( "Sleep for some time" )
974 main.caseResult = main.TRUE
975 sleepSec = int( main.params[ 'CASE90' ][ 'sleepSec' ] )
976 main.eventGenerator.triggerEvent( EventType().TEST_SLEEP, EventScheduleMethod().RUN_BLOCK, sleepSec )
977 with main.eventScheduler.idleCondition:
978 while not main.eventScheduler.isIdle():
979 main.eventScheduler.idleCondition.wait()
980 utilities.assert_equals( expect=main.TRUE,
981 actual=main.caseResult,
982 onpass="Sleep test passed",
983 onfail="Sleep test failed" )
984 time.sleep( main.caseSleep )
985
986 def CASE100( self, main ):
987 """
988 Do something else?
989 """
990 import time
991
992 main.log.report( "Do something else?" )
993 main.log.report( "__________________________________________________" )
994 main.case( "..." )
995
996 main.step( "Wait until the test stops" )
997
998 main.caseResult = main.TRUE
999 utilities.assert_equals( expect=main.TRUE,
1000 actual=main.caseResult,
1001 onpass="Test PASS",
1002 onfail="Test FAIL" )
1003
1004 testDuration = int( main.params[ 'TEST' ][ 'testDuration' ] )
1005 time.sleep( testDuration )