blob: c19715ebcfe04fb79def93a872fbd865770be43a [file] [log] [blame]
You Wangdb927a52016-02-26 11:03:28 -08001"""
Jeremy Ronquillob27ce4c2017-07-17 12:41:28 -07002Copyright 2016 Open Networking Foundation (ONF)
3
4Please refer questions to either the onos test mailing list at <onos-test@onosproject.org>,
5the System Testing Plans and Results wiki page at <https://wiki.onosproject.org/x/voMg>,
6or the System Testing Guide page at <https://wiki.onosproject.org/x/WYQg>
7
8 TestON is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 2 of the License, or
11 (at your option) any later version.
12
13 TestON is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with TestON. If not, see <http://www.gnu.org/licenses/>.
20"""
21
22"""
You Wangdb927a52016-02-26 11:03:28 -080023This file contains the event generator class for CHOTestMonkey
24Author: you@onlab.us
25"""
26from threading import Lock, Condition
27from tests.CHOTestMonkey.dependencies.events.Event import EventType, EventStates, Event
28from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod
You Wangdb927a52016-02-26 11:03:28 -080029
Jon Hall2bb3e212017-05-24 17:07:25 -070030
You Wangdb927a52016-02-26 11:03:28 -080031class MessageType:
Jon Hall2bb3e212017-05-24 17:07:25 -070032
You Wangdb927a52016-02-26 11:03:28 -080033 def __init__( self ):
34 self.map = {}
35 # This message type is used for requesting an event injection from outside CHOTestMonkey
36 self.EVENT_REQUEST = 1
37 self.map[ 1 ] = 'EVENT_REQUEST'
38 # This message tyoe will force the event generator to accept the event injection request for debugging purpose
39 self.EVENT_REQUEST_DEBUG = 2
40 self.map[ 2 ] = 'EVENT_REQUEST_DEBUG'
41 # This message type implies the event generator has inserted the event
42 self.EVENT_INSERTED = 10
43 self.map[ 10 ] = 'EVENT_INSERTED'
44 # This message type implies CHOTestMonkey has refused the event injection request
45 # due to, e.g. too many pending events in the scheduler
46 self.EVENT_DENIED = 11
47 self.map[ 11 ] = 'EVENT_DENIED'
48 # The followings are error messages
49 self.UNKNOWN_MESSAGE = 20
50 self.map[ 20 ] = 'UNKNOWN_MESSAGE'
51 self.UNKNOWN_EVENT_TYPE = 21
52 self.map[ 21 ] = 'UNKNOWN_EVENT_TYPE'
53 self.UNKNOWN_SCHEDULE_METHOD = 22
54 self.map[ 22 ] = 'UNKNOWN_SCHEDULE_METHOD'
55 self.NOT_ENOUGH_ARGUMENT = 23
56 self.map[ 23 ] = 'NOT_ENOUGH_ARGUMENT'
57
Jon Hall2bb3e212017-05-24 17:07:25 -070058
You Wangdb927a52016-02-26 11:03:28 -080059class EventGenerator:
Jon Hall2bb3e212017-05-24 17:07:25 -070060
You Wangdb927a52016-02-26 11:03:28 -080061 def __init__( self ):
62 self.default = ''
63 self.eventGeneratorLock = Lock()
64
65 def startListener( self ):
66 """
67 Listen to event triggers
68 """
69 from multiprocessing.connection import Listener
70 import time
71
72 host = "localhost"
73 port = int( main.params[ 'GENERATOR' ][ 'listenerPort' ] )
74 address = ( host, port )
75 listener = Listener( address )
76 main.log.info( "Event Generator - Event listener start listening on %s:%s" % ( host, port ) )
77
Jon Hall2bb3e212017-05-24 17:07:25 -070078 while True:
You Wangdb927a52016-02-26 11:03:28 -080079 conn = listener.accept()
80 t = main.Thread( target=self.handleConnection,
81 threadID=main.threadID,
82 name="handleConnection",
Jon Hall2bb3e212017-05-24 17:07:25 -070083 args=[ conn ] )
You Wangdb927a52016-02-26 11:03:28 -080084 t.start()
85 with main.variableLock:
86 main.threadID += 1
87 listener.close()
88
89 def handleConnection( self, conn ):
90 """
91 Handle connections from event triggers
92 """
93 request = conn.recv()
94 if isinstance( request, list ) and ( request[ 0 ] == MessageType().EVENT_REQUEST or request[ 0 ] == MessageType().EVENT_REQUEST_DEBUG ):
95 if len( request ) < 3:
96 response = MessageType().NOT_ENOUGH_ARGUMENT
97 elif request[ 0 ] == MessageType().EVENT_REQUEST and not main.eventScheduler.isAvailable():
98 response = MessageType().EVENT_DENIED
99 else:
100 typeString = str( request[ 1 ] )
101 scheduleMethodString = str( request[ 2 ] )
102 if len( request ) > 3:
103 args = request[ 3: ]
104 else:
105 args = None
106 for key, value in EventType().map.items():
107 if value == typeString:
108 typeIndex = key
109 break
110 if not value == typeString:
111 response = MessageType().UNKNOWN_EVENT_TYPE
112 else:
113 for key, value in EventScheduleMethod().map.items():
114 if value == scheduleMethodString:
115 scheduleMethod = key
116 break
117 if not value == scheduleMethodString:
118 response = MessageType().UNKNOWN_SCHEDULE_METHOD
119 else:
120 self.insertEvent( typeIndex, scheduleMethod, args )
121 response = MessageType().EVENT_INSERTED
122 else:
123 response = MessageType().UNKNOWN_MESSAGE
124 conn.send( response )
125 conn.close()
126
127 def triggerEvent( self, typeIndex, scheduleMethod, *args ):
128 """
129 This function triggers an event from inside of CHOTestMonkey
130 """
131 import time
132 if not typeIndex in EventType().map.keys():
133 main.log.warn( "Event Generator - Unknown event type: " + str( typeIndex ) )
134 return
135 if not scheduleMethod in EventScheduleMethod().map.keys():
136 main.log.warn( "Event Generator - Unknown event schedule method: " + str( scheduleMethod ) )
137 return
138 while not main.eventScheduler.isAvailable():
139 time.sleep( int( main.params[ 'GENERATOR' ][ 'insertEventRetryInterval' ] ) )
140 self.insertEvent( typeIndex, scheduleMethod, list( args ) )
141
142 def insertEvent( self, typeIndex, scheduleMethod, args=None ):
143 """
144 This function inserts an event into the scheduler
145 """
146 if typeIndex > 100:
147 # Handle group events
148 if not typeIndex in main.enabledEvents.keys():
149 main.log.warn( "Event Generator - event type %s not enabled" % ( typeIndex ) )
150 return
151 function = getattr( self, main.enabledEvents[ typeIndex ] )
Jon Hall2bb3e212017-05-24 17:07:25 -0700152 assert function is not None, "Event Generator - funtion for group event " + typeIndex + " not found"
You Wangdb927a52016-02-26 11:03:28 -0800153 function( scheduleMethod, args )
154 else:
155 # Add individual events to the scheduler
156 main.eventScheduler.scheduleEvent( typeIndex, scheduleMethod, args )
157
158 def insertAllChecks( self, args=None ):
159 """
160 Acquire eventGeneratorLock before calling this funtion
161 """
162 for eventType in main.enabledEvents.keys():
163 if eventType < 100 and EventType().map[ eventType ].startswith( 'CHECK' ):
164 main.eventScheduler.scheduleEvent( eventType,
165 EventScheduleMethod().RUN_NON_BLOCK,
166 args )
167
168 def addAllChecks( self, scheduleMethod, args=None ):
169 """
170 The function adds all check events into the scheduler
171 """
172 with self.eventGeneratorLock:
173 if scheduleMethod == EventScheduleMethod().RUN_BLOCK:
174 main.eventScheduler.scheduleEvent( EventType().NULL, EventScheduleMethod().RUN_BLOCK )
175 self.insertAllChecks( args )
176 if scheduleMethod == EventScheduleMethod().RUN_BLOCK:
177 main.eventScheduler.scheduleEvent( EventType().NULL, EventScheduleMethod().RUN_BLOCK )
178
179 def randomLinkToggle( self, scheduleMethod, args=[ 5 ], blocking=True ):
180 """
181 The function randomly adds a link down-up event pair into the scheduler
182 After each individual link event, all checks are inserted into the scheduler
183 param:
Jon Hall2bb3e212017-05-24 17:07:25 -0700184 args[ 0 ] is the average interval between link down and link up events
You Wangdb927a52016-02-26 11:03:28 -0800185 blocking means blocking other events from being scheduled between link down and link up
186 """
187 import random
188 import time
189
190 if len( args ) < 1:
191 main.log.warn( "Event Generator - Not enough arguments for randomLinkToggle: %s" % ( args ) )
192 elif len( args ) > 1:
193 main.log.warn( "Event Generator - Too many arguments for randomLinkToggle: %s" % ( args ) )
194 else:
195 downUpAvgInterval = int( args[ 0 ] )
You Wangdb927a52016-02-26 11:03:28 -0800196 self.eventGeneratorLock.acquire()
197 main.eventScheduler.scheduleEvent( EventType().NETWORK_LINK_DOWN,
198 scheduleMethod,
You Wang221db322016-06-03 15:45:52 -0700199 [ 'random', 'random' ] )
You Wangdb927a52016-02-26 11:03:28 -0800200 sleepTime = int( main.params[ 'EVENT' ][ 'randomLinkToggle' ][ 'sleepBeforeCheck' ] )
201 main.eventScheduler.scheduleEvent( EventType().TEST_SLEEP, EventScheduleMethod().RUN_BLOCK, [ sleepTime ] )
202 self.insertAllChecks( EventScheduleMethod().RUN_NON_BLOCK )
203 if scheduleMethod == EventScheduleMethod().RUN_BLOCK:
204 # Insert a NULL BLOCK event
205 main.eventScheduler.scheduleEvent( EventType().NULL, EventScheduleMethod().RUN_BLOCK )
206 downUpInterval = abs( random.gauss( downUpAvgInterval, 1 ) )
207 if not blocking:
208 self.eventGeneratorLock.release()
209 time.sleep( downUpInterval )
210 self.eventGeneratorLock.acquire()
211 else:
212 time.sleep( downUpInterval )
213 main.eventScheduler.scheduleEvent( EventType().NETWORK_LINK_UP,
214 scheduleMethod,
You Wang221db322016-06-03 15:45:52 -0700215 [ 'random', 'random' ] )
You Wangdb927a52016-02-26 11:03:28 -0800216 main.eventScheduler.scheduleEvent( EventType().TEST_SLEEP, EventScheduleMethod().RUN_BLOCK, [ sleepTime ] )
217 self.insertAllChecks( EventScheduleMethod().RUN_NON_BLOCK )
218 if scheduleMethod == EventScheduleMethod().RUN_BLOCK:
219 main.eventScheduler.scheduleEvent( EventType().NULL, EventScheduleMethod().RUN_BLOCK )
220 self.eventGeneratorLock.release()
221
222 def randomLinkGroupToggle( self, scheduleMethod, args=None, blocking=True ):
223 """
224 The function randomly adds a group of link down-up events into the scheduler
225 After each link down or up, all checks are inserted into the scheduler
226 param:
Jon Hall2bb3e212017-05-24 17:07:25 -0700227 args[ 0 ] is the number of links that are to be brought down
228 args[ 1 ] is the average interval between link down events
229 args[ 2 ] is the average interval between link group down and group up events
You Wangdb927a52016-02-26 11:03:28 -0800230 blocking means blocking other events from being scheduled between link events
231 """
232 import random
233 import time
234
235 if len( args ) < 3:
236 main.log.warn( "Event Generator - Not enough arguments for randomLinkGroupToggle: %s" % ( args ) )
237 elif len( args ) > 3:
238 main.log.warn( "Event Generator - Too many arguments for randomLinkGroupToggle: %s" % ( args ) )
239 else:
240 linkGroupSize = int( args[ 0 ] )
241 downDownAvgInterval = int( args[ 1 ] )
242 downUpAvgInterval = int( args[ 2 ] )
You Wangdb927a52016-02-26 11:03:28 -0800243 for i in range( 0, linkGroupSize ):
You Wangdb927a52016-02-26 11:03:28 -0800244 if i == 0:
245 self.eventGeneratorLock.acquire()
246 main.eventScheduler.scheduleEvent( EventType().NETWORK_LINK_DOWN,
247 scheduleMethod,
You Wang221db322016-06-03 15:45:52 -0700248 [ 'random', 'random' ] )
You Wangdb927a52016-02-26 11:03:28 -0800249 sleepTime = int( main.params[ 'EVENT' ][ 'randomLinkGroupToggle' ][ 'sleepBeforeCheck' ] )
250 main.eventScheduler.scheduleEvent( EventType().TEST_SLEEP, EventScheduleMethod().RUN_BLOCK, [ sleepTime ] )
251 self.insertAllChecks( EventScheduleMethod().RUN_NON_BLOCK )
252 if scheduleMethod == EventScheduleMethod().RUN_BLOCK:
253 # Insert a NULL BLOCK event
254 main.eventScheduler.scheduleEvent( EventType().NULL, EventScheduleMethod().RUN_BLOCK )
255 downDownInterval = abs( random.gauss( downDownAvgInterval, 1 ) )
256 if not blocking:
257 self.eventGeneratorLock.release()
258 time.sleep( downDownInterval )
259 self.eventGeneratorLock.acquire()
260 else:
261 time.sleep( downDownInterval )
262
263 downUpInterval = abs( random.gauss( downUpAvgInterval, 1 ) )
264 if not blocking:
265 self.eventGeneratorLock.release()
266 time.sleep( downUpInterval )
267 self.eventGeneratorLock.acquire()
268 else:
269 time.sleep( downUpInterval )
270
You Wang221db322016-06-03 15:45:52 -0700271 for i in range( 0, linkGroupSize ):
You Wangdb927a52016-02-26 11:03:28 -0800272 main.eventScheduler.scheduleEvent( EventType().NETWORK_LINK_UP,
273 scheduleMethod,
You Wang221db322016-06-03 15:45:52 -0700274 [ 'random', 'random' ] )
You Wangdb927a52016-02-26 11:03:28 -0800275 main.eventScheduler.scheduleEvent( EventType().TEST_SLEEP, EventScheduleMethod().RUN_BLOCK, [ sleepTime ] )
276 self.insertAllChecks( EventScheduleMethod().RUN_NON_BLOCK )
277 if scheduleMethod == EventScheduleMethod().RUN_BLOCK:
278 main.eventScheduler.scheduleEvent( EventType().NULL, EventScheduleMethod().RUN_BLOCK )
279 upUpInterval = abs( random.gauss( downDownAvgInterval, 1 ) )
280 if not blocking:
281 self.eventGeneratorLock.release()
282 time.sleep( upUpInterval )
283 self.eventGeneratorLock.acquire()
284 else:
285 time.sleep( upUpInterval )
286 self.eventGeneratorLock.release()
287
288 def randomDeviceToggle( self, scheduleMethod, args=[ 5 ], blocking=True ):
289 """
290 The function randomly removes a device and then adds it back
291 After each individual device event, all checks are inserted into the scheduler
292 param:
Jon Hall2bb3e212017-05-24 17:07:25 -0700293 args[ 0 ] is the average interval between device down and device up events
You Wangdb927a52016-02-26 11:03:28 -0800294 blocking means blocking other events from being scheduled between device down and device up
295 """
296 import random
297 import time
298
299 if len( args ) < 1:
300 main.log.warn( "Event Generator - Not enough arguments for randomDeviceToggle: %s" % ( args ) )
301 elif len( args ) > 1:
302 main.log.warn( "Event Generator - Too many arguments for randomDeviceToggle: %s" % ( args ) )
303 else:
304 downUpAvgInterval = int( args[ 0 ] )
You Wangdb927a52016-02-26 11:03:28 -0800305 self.eventGeneratorLock.acquire()
306 main.eventScheduler.scheduleEvent( EventType().NETWORK_DEVICE_DOWN,
307 scheduleMethod,
You Wang221db322016-06-03 15:45:52 -0700308 [ 'random' ] )
You Wangdb927a52016-02-26 11:03:28 -0800309 sleepTime = int( main.params[ 'EVENT' ][ 'randomLinkToggle' ][ 'sleepBeforeCheck' ] )
310 main.eventScheduler.scheduleEvent( EventType().TEST_SLEEP, EventScheduleMethod().RUN_BLOCK, [ sleepTime ] )
311 self.insertAllChecks( EventScheduleMethod().RUN_NON_BLOCK )
312 if scheduleMethod == EventScheduleMethod().RUN_BLOCK:
313 # Insert a NULL BLOCK event
314 main.eventScheduler.scheduleEvent( EventType().NULL, EventScheduleMethod().RUN_BLOCK )
315 downUpInterval = abs( random.gauss( downUpAvgInterval, 1 ) )
316 if not blocking:
317 self.eventGeneratorLock.release()
318 time.sleep( downUpInterval )
319 self.eventGeneratorLock.acquire()
320 else:
321 time.sleep( downUpInterval )
322 main.eventScheduler.scheduleEvent( EventType().NETWORK_DEVICE_UP,
323 scheduleMethod,
You Wang221db322016-06-03 15:45:52 -0700324 [ 'random' ] )
You Wangdb927a52016-02-26 11:03:28 -0800325 main.eventScheduler.scheduleEvent( EventType().TEST_SLEEP, EventScheduleMethod().RUN_BLOCK, [ sleepTime ] )
326 self.insertAllChecks( EventScheduleMethod().RUN_NON_BLOCK )
327 if scheduleMethod == EventScheduleMethod().RUN_BLOCK:
328 main.eventScheduler.scheduleEvent( EventType().NULL, EventScheduleMethod().RUN_BLOCK )
329 self.eventGeneratorLock.release()
330
331 def randomDeviceGroupToggle( self, scheduleMethod, args=None, blocking=True ):
332 """
333 The function randomly adds a group of device down-up events into the scheduler
334 After each device down or up, all checks are inserted into the scheduler
335 param:
Jon Hall2bb3e212017-05-24 17:07:25 -0700336 args[ 0 ] is the number of devices that are to be brought down
337 args[ 1 ] is the average interval between device down events
338 args[ 2 ] is the average interval between device group down and group up events
You Wangdb927a52016-02-26 11:03:28 -0800339 blocking means blocking other events from being scheduled between device events
340 """
341 import random
342 import time
343
344 if len( args ) < 3:
345 main.log.warn( "Event Generator - Not enough arguments for randomDeviceGroupToggle: %s" % ( args ) )
346 elif len( args ) > 3:
347 main.log.warn( "Event Generator - Too many arguments for randomDeviceGroupToggle: %s" % ( args ) )
348 else:
349 deviceGroupSize = int( args[ 0 ] )
350 downDownAvgInterval = int( args[ 1 ] )
351 downUpAvgInterval = int( args[ 2 ] )
You Wangdb927a52016-02-26 11:03:28 -0800352 for i in range( 0, deviceGroupSize ):
You Wangdb927a52016-02-26 11:03:28 -0800353 if i == 0:
354 self.eventGeneratorLock.acquire()
355 main.eventScheduler.scheduleEvent( EventType().NETWORK_DEVICE_DOWN,
356 scheduleMethod,
You Wang221db322016-06-03 15:45:52 -0700357 [ 'random' ] )
You Wangdb927a52016-02-26 11:03:28 -0800358 sleepTime = int( main.params[ 'EVENT' ][ 'randomLinkGroupToggle' ][ 'sleepBeforeCheck' ] )
359 main.eventScheduler.scheduleEvent( EventType().TEST_SLEEP, EventScheduleMethod().RUN_BLOCK, [ sleepTime ] )
360 self.insertAllChecks( EventScheduleMethod().RUN_NON_BLOCK )
361 if scheduleMethod == EventScheduleMethod().RUN_BLOCK:
362 # Insert a NULL BLOCK event
363 main.eventScheduler.scheduleEvent( EventType().NULL, EventScheduleMethod().RUN_BLOCK )
364 downDownInterval = abs( random.gauss( downDownAvgInterval, 1 ) )
365 if not blocking:
366 self.eventGeneratorLock.release()
367 time.sleep( downDownInterval )
368 self.eventGeneratorLock.acquire()
369 else:
370 time.sleep( downDownInterval )
371
372 downUpInterval = abs( random.gauss( downUpAvgInterval, 1 ) )
373 if not blocking:
374 self.eventGeneratorLock.release()
375 time.sleep( downUpInterval )
376 self.eventGeneratorLock.acquire()
377 else:
378 time.sleep( downUpInterval )
379
You Wang221db322016-06-03 15:45:52 -0700380 for i in range( 0, deviceGroupSize ):
You Wangdb927a52016-02-26 11:03:28 -0800381 main.eventScheduler.scheduleEvent( EventType().NETWORK_DEVICE_UP,
382 scheduleMethod,
You Wang221db322016-06-03 15:45:52 -0700383 [ 'random' ] )
You Wangdb927a52016-02-26 11:03:28 -0800384 main.eventScheduler.scheduleEvent( EventType().TEST_SLEEP, EventScheduleMethod().RUN_BLOCK, [ sleepTime ] )
385 self.insertAllChecks( EventScheduleMethod().RUN_NON_BLOCK )
386 if scheduleMethod == EventScheduleMethod().RUN_BLOCK:
387 main.eventScheduler.scheduleEvent( EventType().NULL, EventScheduleMethod().RUN_BLOCK )
388 upUpInterval = abs( random.gauss( downDownAvgInterval, 1 ) )
389 if not blocking:
390 self.eventGeneratorLock.release()
391 time.sleep( upUpInterval )
392 self.eventGeneratorLock.acquire()
393 else:
394 time.sleep( upUpInterval )
395 self.eventGeneratorLock.release()
396
397 def installAllHostIntents( self, scheduleMethod, args=None ):
398 """
399 This function installs host intents for all host pairs
400 After all intent events are inserted, this funciton also insert intent and traffic checks
401 """
402 import itertools
403
404 with self.eventGeneratorLock:
405 if scheduleMethod == EventScheduleMethod().RUN_BLOCK:
406 main.eventScheduler.scheduleEvent( EventType().NULL, EventScheduleMethod().RUN_BLOCK )
407 availableControllers = []
408 for controller in main.controllers:
409 if controller.isUp():
410 availableControllers.append( controller.index )
411 if len( availableControllers ) == 0:
412 main.log.warn( "Event Generator - No available controllers" )
413 return
414 hostCombos = list( itertools.combinations( main.hosts, 2 ) )
415 for i in xrange( 0, len( hostCombos ), len( availableControllers ) ):
416 for CLIIndex in availableControllers:
417 if i >= len( hostCombos ):
418 break
419 main.eventScheduler.scheduleEvent( EventType().APP_INTENT_HOST_ADD,
420 EventScheduleMethod().RUN_NON_BLOCK,
421 [ hostCombos[ i ][ 0 ].name, hostCombos[ i ][ 1 ].name, CLIIndex ] )
422 i += 1
423 # Pending checks after installing all intents
424 if scheduleMethod == EventScheduleMethod().RUN_BLOCK:
425 main.eventScheduler.scheduleEvent( EventType().NULL, EventScheduleMethod().RUN_BLOCK )
426 sleepTime = int( main.params[ 'EVENT' ][ 'installAllHostIntents' ][ 'sleepBeforeCheck' ] )
427 main.eventScheduler.scheduleEvent( EventType().TEST_SLEEP, EventScheduleMethod().RUN_BLOCK, [ sleepTime ] )
You Wang55503a32016-06-27 15:11:40 -0700428 self.insertAllChecks( EventScheduleMethod().RUN_NON_BLOCK )
You Wangdb927a52016-02-26 11:03:28 -0800429 if scheduleMethod == EventScheduleMethod().RUN_BLOCK:
430 main.eventScheduler.scheduleEvent( EventType().NULL, EventScheduleMethod().RUN_BLOCK )
431
432 def removeAllHostIntents( self, scheduleMethod, args=None ):
433 """
434 This function removes host intents for all host pairs
435 After all intent events are inserted, this funciton also insert intent and traffic checks
436 """
437 import itertools
438
439 with self.eventGeneratorLock:
440 if scheduleMethod == EventScheduleMethod().RUN_BLOCK:
441 main.eventScheduler.scheduleEvent( EventType().NULL, EventScheduleMethod().RUN_BLOCK )
442 availableControllers = []
443 for controller in main.controllers:
444 if controller.isUp():
445 availableControllers.append( controller.index )
446 if len( availableControllers ) == 0:
447 main.log.warn( "Event Generator - No available controllers" )
448 return
449 hostCombos = list( itertools.combinations( main.hosts, 2 ) )
450 for i in xrange( 0, len( hostCombos ), len( availableControllers ) ):
451 for CLIIndex in availableControllers:
452 if i >= len( hostCombos ):
453 break
454 main.eventScheduler.scheduleEvent( EventType().APP_INTENT_HOST_DEL,
455 EventScheduleMethod().RUN_NON_BLOCK,
456 [ hostCombos[ i ][ 0 ].name, hostCombos[ i ][ 1 ].name, CLIIndex ] )
457 i += 1
458 # Pending checks after removing all intents
459 if scheduleMethod == EventScheduleMethod().RUN_BLOCK:
460 main.eventScheduler.scheduleEvent( EventType().NULL, EventScheduleMethod().RUN_BLOCK )
461 sleepTime = int( main.params[ 'EVENT' ][ 'removeAllHostIntents' ][ 'sleepBeforeCheck' ] )
462 main.eventScheduler.scheduleEvent( EventType().TEST_SLEEP, EventScheduleMethod().RUN_BLOCK, [ sleepTime ] )
You Wang55503a32016-06-27 15:11:40 -0700463 self.insertAllChecks( EventScheduleMethod().RUN_NON_BLOCK )
You Wangdb927a52016-02-26 11:03:28 -0800464 if scheduleMethod == EventScheduleMethod().RUN_BLOCK:
465 main.eventScheduler.scheduleEvent( EventType().NULL, EventScheduleMethod().RUN_BLOCK )
466
467 def installAllPointIntents( self, scheduleMethod, args=None ):
468 """
469 This function installs point intents for all device pairs
470 After all intent events are inserted, this funciton also insert intent and traffic checks
471 """
472 import itertools
473
474 with self.eventGeneratorLock:
475 if scheduleMethod == EventScheduleMethod().RUN_BLOCK:
476 main.eventScheduler.scheduleEvent( EventType().NULL, EventScheduleMethod().RUN_BLOCK )
477 availableControllers = []
478 for controller in main.controllers:
479 if controller.isUp():
480 availableControllers.append( controller.index )
481 if len( availableControllers ) == 0:
482 main.log.warn( "Event Generator - No available controllers" )
483 return
484 deviceCombos = list( itertools.permutations( main.devices, 2 ) )
485 for i in xrange( 0, len( deviceCombos ), len( availableControllers ) ):
486 for CLIIndex in availableControllers:
487 if i >= len( deviceCombos ):
488 break
489 main.eventScheduler.scheduleEvent( EventType().APP_INTENT_POINT_ADD,
490 EventScheduleMethod().RUN_NON_BLOCK,
491 [ deviceCombos[ i ][ 0 ].name, deviceCombos[ i ][ 1 ].name, CLIIndex ] )
492 i += 1
493 # Pending checks after installing all intents
494 if scheduleMethod == EventScheduleMethod().RUN_BLOCK:
495 main.eventScheduler.scheduleEvent( EventType().NULL, EventScheduleMethod().RUN_BLOCK )
496 sleepTime = int( main.params[ 'EVENT' ][ 'installAllPointIntents' ][ 'sleepBeforeCheck' ] )
497 main.eventScheduler.scheduleEvent( EventType().TEST_SLEEP, EventScheduleMethod().RUN_BLOCK, [ sleepTime ] )
You Wang55503a32016-06-27 15:11:40 -0700498 self.insertAllChecks( EventScheduleMethod().RUN_NON_BLOCK )
You Wangdb927a52016-02-26 11:03:28 -0800499 if scheduleMethod == EventScheduleMethod().RUN_BLOCK:
500 main.eventScheduler.scheduleEvent( EventType().NULL, EventScheduleMethod().RUN_BLOCK )
501
502 def removeAllPointIntents( self, scheduleMethod, args=None ):
503 """
504 This function removes point intents for all device pairs
505 After all intent events are inserted, this funciton also insert intent and traffic checks
506 """
507 import itertools
508
509 with self.eventGeneratorLock:
510 if scheduleMethod == EventScheduleMethod().RUN_BLOCK:
511 main.eventScheduler.scheduleEvent( EventType().NULL, EventScheduleMethod().RUN_BLOCK )
512 availableControllers = []
513 for controller in main.controllers:
514 if controller.isUp():
515 availableControllers.append( controller.index )
516 if len( availableControllers ) == 0:
517 main.log.warn( "Event Generator - No available controllers" )
518 return
519 deviceCombos = list( itertools.permutations( main.devices, 2 ) )
520 for i in xrange( 0, len( deviceCombos ), len( availableControllers ) ):
521 for CLIIndex in availableControllers:
522 if i >= len( deviceCombos ):
523 break
524 main.eventScheduler.scheduleEvent( EventType().APP_INTENT_POINT_DEL,
525 EventScheduleMethod().RUN_NON_BLOCK,
526 [ deviceCombos[ i ][ 0 ].name, deviceCombos[ i ][ 1 ].name, CLIIndex ] )
527 i += 1
528 # Pending checks after removing all intents
529 if scheduleMethod == EventScheduleMethod().RUN_BLOCK:
530 main.eventScheduler.scheduleEvent( EventType().NULL, EventScheduleMethod().RUN_BLOCK )
531 sleepTime = int( main.params[ 'EVENT' ][ 'removeAllPointIntents' ][ 'sleepBeforeCheck' ] )
532 main.eventScheduler.scheduleEvent( EventType().TEST_SLEEP, EventScheduleMethod().RUN_BLOCK, [ sleepTime ] )
You Wang55503a32016-06-27 15:11:40 -0700533 self.insertAllChecks( EventScheduleMethod().RUN_NON_BLOCK )
You Wangdb927a52016-02-26 11:03:28 -0800534 if scheduleMethod == EventScheduleMethod().RUN_BLOCK:
535 main.eventScheduler.scheduleEvent( EventType().NULL, EventScheduleMethod().RUN_BLOCK )