blob: dd532385f6af12b50df683349ef752a54360319e [file] [log] [blame]
You Wangdb927a52016-02-26 11:03:28 -08001"""
2This file contains the event generator class for CHOTestMonkey
3Author: you@onlab.us
4"""
5from threading import Lock, Condition
6from tests.CHOTestMonkey.dependencies.events.Event import EventType, EventStates, Event
7from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod
You Wangdb927a52016-02-26 11:03:28 -08008
9class MessageType:
10 def __init__( self ):
11 self.map = {}
12 # This message type is used for requesting an event injection from outside CHOTestMonkey
13 self.EVENT_REQUEST = 1
14 self.map[ 1 ] = 'EVENT_REQUEST'
15 # This message tyoe will force the event generator to accept the event injection request for debugging purpose
16 self.EVENT_REQUEST_DEBUG = 2
17 self.map[ 2 ] = 'EVENT_REQUEST_DEBUG'
18 # This message type implies the event generator has inserted the event
19 self.EVENT_INSERTED = 10
20 self.map[ 10 ] = 'EVENT_INSERTED'
21 # This message type implies CHOTestMonkey has refused the event injection request
22 # due to, e.g. too many pending events in the scheduler
23 self.EVENT_DENIED = 11
24 self.map[ 11 ] = 'EVENT_DENIED'
25 # The followings are error messages
26 self.UNKNOWN_MESSAGE = 20
27 self.map[ 20 ] = 'UNKNOWN_MESSAGE'
28 self.UNKNOWN_EVENT_TYPE = 21
29 self.map[ 21 ] = 'UNKNOWN_EVENT_TYPE'
30 self.UNKNOWN_SCHEDULE_METHOD = 22
31 self.map[ 22 ] = 'UNKNOWN_SCHEDULE_METHOD'
32 self.NOT_ENOUGH_ARGUMENT = 23
33 self.map[ 23 ] = 'NOT_ENOUGH_ARGUMENT'
34
35class EventGenerator:
36 def __init__( self ):
37 self.default = ''
38 self.eventGeneratorLock = Lock()
39
40 def startListener( self ):
41 """
42 Listen to event triggers
43 """
44 from multiprocessing.connection import Listener
45 import time
46
47 host = "localhost"
48 port = int( main.params[ 'GENERATOR' ][ 'listenerPort' ] )
49 address = ( host, port )
50 listener = Listener( address )
51 main.log.info( "Event Generator - Event listener start listening on %s:%s" % ( host, port ) )
52
53 while 1:
54 conn = listener.accept()
55 t = main.Thread( target=self.handleConnection,
56 threadID=main.threadID,
57 name="handleConnection",
58 args=[ conn ])
59 t.start()
60 with main.variableLock:
61 main.threadID += 1
62 listener.close()
63
64 def handleConnection( self, conn ):
65 """
66 Handle connections from event triggers
67 """
68 request = conn.recv()
69 if isinstance( request, list ) and ( request[ 0 ] == MessageType().EVENT_REQUEST or request[ 0 ] == MessageType().EVENT_REQUEST_DEBUG ):
70 if len( request ) < 3:
71 response = MessageType().NOT_ENOUGH_ARGUMENT
72 elif request[ 0 ] == MessageType().EVENT_REQUEST and not main.eventScheduler.isAvailable():
73 response = MessageType().EVENT_DENIED
74 else:
75 typeString = str( request[ 1 ] )
76 scheduleMethodString = str( request[ 2 ] )
77 if len( request ) > 3:
78 args = request[ 3: ]
79 else:
80 args = None
81 for key, value in EventType().map.items():
82 if value == typeString:
83 typeIndex = key
84 break
85 if not value == typeString:
86 response = MessageType().UNKNOWN_EVENT_TYPE
87 else:
88 for key, value in EventScheduleMethod().map.items():
89 if value == scheduleMethodString:
90 scheduleMethod = key
91 break
92 if not value == scheduleMethodString:
93 response = MessageType().UNKNOWN_SCHEDULE_METHOD
94 else:
95 self.insertEvent( typeIndex, scheduleMethod, args )
96 response = MessageType().EVENT_INSERTED
97 else:
98 response = MessageType().UNKNOWN_MESSAGE
99 conn.send( response )
100 conn.close()
101
102 def triggerEvent( self, typeIndex, scheduleMethod, *args ):
103 """
104 This function triggers an event from inside of CHOTestMonkey
105 """
106 import time
107 if not typeIndex in EventType().map.keys():
108 main.log.warn( "Event Generator - Unknown event type: " + str( typeIndex ) )
109 return
110 if not scheduleMethod in EventScheduleMethod().map.keys():
111 main.log.warn( "Event Generator - Unknown event schedule method: " + str( scheduleMethod ) )
112 return
113 while not main.eventScheduler.isAvailable():
114 time.sleep( int( main.params[ 'GENERATOR' ][ 'insertEventRetryInterval' ] ) )
115 self.insertEvent( typeIndex, scheduleMethod, list( args ) )
116
117 def insertEvent( self, typeIndex, scheduleMethod, args=None ):
118 """
119 This function inserts an event into the scheduler
120 """
121 if typeIndex > 100:
122 # Handle group events
123 if not typeIndex in main.enabledEvents.keys():
124 main.log.warn( "Event Generator - event type %s not enabled" % ( typeIndex ) )
125 return
126 function = getattr( self, main.enabledEvents[ typeIndex ] )
127 assert function != None, "Event Generator - funtion for group event " + typeIndex + " not found"
128 function( scheduleMethod, args )
129 else:
130 # Add individual events to the scheduler
131 main.eventScheduler.scheduleEvent( typeIndex, scheduleMethod, args )
132
133 def insertAllChecks( self, args=None ):
134 """
135 Acquire eventGeneratorLock before calling this funtion
136 """
137 for eventType in main.enabledEvents.keys():
138 if eventType < 100 and EventType().map[ eventType ].startswith( 'CHECK' ):
139 main.eventScheduler.scheduleEvent( eventType,
140 EventScheduleMethod().RUN_NON_BLOCK,
141 args )
142
143 def addAllChecks( self, scheduleMethod, args=None ):
144 """
145 The function adds all check events into the scheduler
146 """
147 with self.eventGeneratorLock:
148 if scheduleMethod == EventScheduleMethod().RUN_BLOCK:
149 main.eventScheduler.scheduleEvent( EventType().NULL, EventScheduleMethod().RUN_BLOCK )
150 self.insertAllChecks( args )
151 if scheduleMethod == EventScheduleMethod().RUN_BLOCK:
152 main.eventScheduler.scheduleEvent( EventType().NULL, EventScheduleMethod().RUN_BLOCK )
153
154 def randomLinkToggle( self, scheduleMethod, args=[ 5 ], blocking=True ):
155 """
156 The function randomly adds a link down-up event pair into the scheduler
157 After each individual link event, all checks are inserted into the scheduler
158 param:
159 args[0] is the average interval between link down and link up events
160 blocking means blocking other events from being scheduled between link down and link up
161 """
162 import random
163 import time
164
165 if len( args ) < 1:
166 main.log.warn( "Event Generator - Not enough arguments for randomLinkToggle: %s" % ( args ) )
167 elif len( args ) > 1:
168 main.log.warn( "Event Generator - Too many arguments for randomLinkToggle: %s" % ( args ) )
169 else:
170 downUpAvgInterval = int( args[ 0 ] )
You Wangdb927a52016-02-26 11:03:28 -0800171 self.eventGeneratorLock.acquire()
172 main.eventScheduler.scheduleEvent( EventType().NETWORK_LINK_DOWN,
173 scheduleMethod,
You Wang221db322016-06-03 15:45:52 -0700174 [ 'random', 'random' ] )
You Wangdb927a52016-02-26 11:03:28 -0800175 sleepTime = int( main.params[ 'EVENT' ][ 'randomLinkToggle' ][ 'sleepBeforeCheck' ] )
176 main.eventScheduler.scheduleEvent( EventType().TEST_SLEEP, EventScheduleMethod().RUN_BLOCK, [ sleepTime ] )
177 self.insertAllChecks( EventScheduleMethod().RUN_NON_BLOCK )
178 if scheduleMethod == EventScheduleMethod().RUN_BLOCK:
179 # Insert a NULL BLOCK event
180 main.eventScheduler.scheduleEvent( EventType().NULL, EventScheduleMethod().RUN_BLOCK )
181 downUpInterval = abs( random.gauss( downUpAvgInterval, 1 ) )
182 if not blocking:
183 self.eventGeneratorLock.release()
184 time.sleep( downUpInterval )
185 self.eventGeneratorLock.acquire()
186 else:
187 time.sleep( downUpInterval )
188 main.eventScheduler.scheduleEvent( EventType().NETWORK_LINK_UP,
189 scheduleMethod,
You Wang221db322016-06-03 15:45:52 -0700190 [ 'random', 'random' ] )
You Wangdb927a52016-02-26 11:03:28 -0800191 main.eventScheduler.scheduleEvent( EventType().TEST_SLEEP, EventScheduleMethod().RUN_BLOCK, [ sleepTime ] )
192 self.insertAllChecks( EventScheduleMethod().RUN_NON_BLOCK )
193 if scheduleMethod == EventScheduleMethod().RUN_BLOCK:
194 main.eventScheduler.scheduleEvent( EventType().NULL, EventScheduleMethod().RUN_BLOCK )
195 self.eventGeneratorLock.release()
196
197 def randomLinkGroupToggle( self, scheduleMethod, args=None, blocking=True ):
198 """
199 The function randomly adds a group of link down-up events into the scheduler
200 After each link down or up, all checks are inserted into the scheduler
201 param:
202 args[0] is the number of links that are to be brought down
203 args[1] is the average interval between link down events
204 args[2] is the average interval between link group down and group up events
205 blocking means blocking other events from being scheduled between link events
206 """
207 import random
208 import time
209
210 if len( args ) < 3:
211 main.log.warn( "Event Generator - Not enough arguments for randomLinkGroupToggle: %s" % ( args ) )
212 elif len( args ) > 3:
213 main.log.warn( "Event Generator - Too many arguments for randomLinkGroupToggle: %s" % ( args ) )
214 else:
215 linkGroupSize = int( args[ 0 ] )
216 downDownAvgInterval = int( args[ 1 ] )
217 downUpAvgInterval = int( args[ 2 ] )
You Wangdb927a52016-02-26 11:03:28 -0800218 for i in range( 0, linkGroupSize ):
You Wangdb927a52016-02-26 11:03:28 -0800219 if i == 0:
220 self.eventGeneratorLock.acquire()
221 main.eventScheduler.scheduleEvent( EventType().NETWORK_LINK_DOWN,
222 scheduleMethod,
You Wang221db322016-06-03 15:45:52 -0700223 [ 'random', 'random' ] )
You Wangdb927a52016-02-26 11:03:28 -0800224 sleepTime = int( main.params[ 'EVENT' ][ 'randomLinkGroupToggle' ][ 'sleepBeforeCheck' ] )
225 main.eventScheduler.scheduleEvent( EventType().TEST_SLEEP, EventScheduleMethod().RUN_BLOCK, [ sleepTime ] )
226 self.insertAllChecks( EventScheduleMethod().RUN_NON_BLOCK )
227 if scheduleMethod == EventScheduleMethod().RUN_BLOCK:
228 # Insert a NULL BLOCK event
229 main.eventScheduler.scheduleEvent( EventType().NULL, EventScheduleMethod().RUN_BLOCK )
230 downDownInterval = abs( random.gauss( downDownAvgInterval, 1 ) )
231 if not blocking:
232 self.eventGeneratorLock.release()
233 time.sleep( downDownInterval )
234 self.eventGeneratorLock.acquire()
235 else:
236 time.sleep( downDownInterval )
237
238 downUpInterval = abs( random.gauss( downUpAvgInterval, 1 ) )
239 if not blocking:
240 self.eventGeneratorLock.release()
241 time.sleep( downUpInterval )
242 self.eventGeneratorLock.acquire()
243 else:
244 time.sleep( downUpInterval )
245
You Wang221db322016-06-03 15:45:52 -0700246 for i in range( 0, linkGroupSize ):
You Wangdb927a52016-02-26 11:03:28 -0800247 main.eventScheduler.scheduleEvent( EventType().NETWORK_LINK_UP,
248 scheduleMethod,
You Wang221db322016-06-03 15:45:52 -0700249 [ 'random', 'random' ] )
You Wangdb927a52016-02-26 11:03:28 -0800250 main.eventScheduler.scheduleEvent( EventType().TEST_SLEEP, EventScheduleMethod().RUN_BLOCK, [ sleepTime ] )
251 self.insertAllChecks( EventScheduleMethod().RUN_NON_BLOCK )
252 if scheduleMethod == EventScheduleMethod().RUN_BLOCK:
253 main.eventScheduler.scheduleEvent( EventType().NULL, EventScheduleMethod().RUN_BLOCK )
254 upUpInterval = abs( random.gauss( downDownAvgInterval, 1 ) )
255 if not blocking:
256 self.eventGeneratorLock.release()
257 time.sleep( upUpInterval )
258 self.eventGeneratorLock.acquire()
259 else:
260 time.sleep( upUpInterval )
261 self.eventGeneratorLock.release()
262
263 def randomDeviceToggle( self, scheduleMethod, args=[ 5 ], blocking=True ):
264 """
265 The function randomly removes a device and then adds it back
266 After each individual device event, all checks are inserted into the scheduler
267 param:
268 args[0] is the average interval between device down and device up events
269 blocking means blocking other events from being scheduled between device down and device up
270 """
271 import random
272 import time
273
274 if len( args ) < 1:
275 main.log.warn( "Event Generator - Not enough arguments for randomDeviceToggle: %s" % ( args ) )
276 elif len( args ) > 1:
277 main.log.warn( "Event Generator - Too many arguments for randomDeviceToggle: %s" % ( args ) )
278 else:
279 downUpAvgInterval = int( args[ 0 ] )
You Wangdb927a52016-02-26 11:03:28 -0800280 self.eventGeneratorLock.acquire()
281 main.eventScheduler.scheduleEvent( EventType().NETWORK_DEVICE_DOWN,
282 scheduleMethod,
You Wang221db322016-06-03 15:45:52 -0700283 [ 'random' ] )
You Wangdb927a52016-02-26 11:03:28 -0800284 sleepTime = int( main.params[ 'EVENT' ][ 'randomLinkToggle' ][ 'sleepBeforeCheck' ] )
285 main.eventScheduler.scheduleEvent( EventType().TEST_SLEEP, EventScheduleMethod().RUN_BLOCK, [ sleepTime ] )
286 self.insertAllChecks( EventScheduleMethod().RUN_NON_BLOCK )
287 if scheduleMethod == EventScheduleMethod().RUN_BLOCK:
288 # Insert a NULL BLOCK event
289 main.eventScheduler.scheduleEvent( EventType().NULL, EventScheduleMethod().RUN_BLOCK )
290 downUpInterval = abs( random.gauss( downUpAvgInterval, 1 ) )
291 if not blocking:
292 self.eventGeneratorLock.release()
293 time.sleep( downUpInterval )
294 self.eventGeneratorLock.acquire()
295 else:
296 time.sleep( downUpInterval )
297 main.eventScheduler.scheduleEvent( EventType().NETWORK_DEVICE_UP,
298 scheduleMethod,
You Wang221db322016-06-03 15:45:52 -0700299 [ 'random' ] )
You Wangdb927a52016-02-26 11:03:28 -0800300 main.eventScheduler.scheduleEvent( EventType().TEST_SLEEP, EventScheduleMethod().RUN_BLOCK, [ sleepTime ] )
301 self.insertAllChecks( EventScheduleMethod().RUN_NON_BLOCK )
302 if scheduleMethod == EventScheduleMethod().RUN_BLOCK:
303 main.eventScheduler.scheduleEvent( EventType().NULL, EventScheduleMethod().RUN_BLOCK )
304 self.eventGeneratorLock.release()
305
306 def randomDeviceGroupToggle( self, scheduleMethod, args=None, blocking=True ):
307 """
308 The function randomly adds a group of device down-up events into the scheduler
309 After each device down or up, all checks are inserted into the scheduler
310 param:
311 args[0] is the number of devices that are to be brought down
312 args[1] is the average interval between device down events
313 args[2] is the average interval between device group down and group up events
314 blocking means blocking other events from being scheduled between device events
315 """
316 import random
317 import time
318
319 if len( args ) < 3:
320 main.log.warn( "Event Generator - Not enough arguments for randomDeviceGroupToggle: %s" % ( args ) )
321 elif len( args ) > 3:
322 main.log.warn( "Event Generator - Too many arguments for randomDeviceGroupToggle: %s" % ( args ) )
323 else:
324 deviceGroupSize = int( args[ 0 ] )
325 downDownAvgInterval = int( args[ 1 ] )
326 downUpAvgInterval = int( args[ 2 ] )
You Wangdb927a52016-02-26 11:03:28 -0800327 for i in range( 0, deviceGroupSize ):
You Wangdb927a52016-02-26 11:03:28 -0800328 if i == 0:
329 self.eventGeneratorLock.acquire()
330 main.eventScheduler.scheduleEvent( EventType().NETWORK_DEVICE_DOWN,
331 scheduleMethod,
You Wang221db322016-06-03 15:45:52 -0700332 [ 'random' ] )
You Wangdb927a52016-02-26 11:03:28 -0800333 sleepTime = int( main.params[ 'EVENT' ][ 'randomLinkGroupToggle' ][ 'sleepBeforeCheck' ] )
334 main.eventScheduler.scheduleEvent( EventType().TEST_SLEEP, EventScheduleMethod().RUN_BLOCK, [ sleepTime ] )
335 self.insertAllChecks( EventScheduleMethod().RUN_NON_BLOCK )
336 if scheduleMethod == EventScheduleMethod().RUN_BLOCK:
337 # Insert a NULL BLOCK event
338 main.eventScheduler.scheduleEvent( EventType().NULL, EventScheduleMethod().RUN_BLOCK )
339 downDownInterval = abs( random.gauss( downDownAvgInterval, 1 ) )
340 if not blocking:
341 self.eventGeneratorLock.release()
342 time.sleep( downDownInterval )
343 self.eventGeneratorLock.acquire()
344 else:
345 time.sleep( downDownInterval )
346
347 downUpInterval = abs( random.gauss( downUpAvgInterval, 1 ) )
348 if not blocking:
349 self.eventGeneratorLock.release()
350 time.sleep( downUpInterval )
351 self.eventGeneratorLock.acquire()
352 else:
353 time.sleep( downUpInterval )
354
You Wang221db322016-06-03 15:45:52 -0700355 for i in range( 0, deviceGroupSize ):
You Wangdb927a52016-02-26 11:03:28 -0800356 main.eventScheduler.scheduleEvent( EventType().NETWORK_DEVICE_UP,
357 scheduleMethod,
You Wang221db322016-06-03 15:45:52 -0700358 [ 'random' ] )
You Wangdb927a52016-02-26 11:03:28 -0800359 main.eventScheduler.scheduleEvent( EventType().TEST_SLEEP, EventScheduleMethod().RUN_BLOCK, [ sleepTime ] )
360 self.insertAllChecks( EventScheduleMethod().RUN_NON_BLOCK )
361 if scheduleMethod == EventScheduleMethod().RUN_BLOCK:
362 main.eventScheduler.scheduleEvent( EventType().NULL, EventScheduleMethod().RUN_BLOCK )
363 upUpInterval = abs( random.gauss( downDownAvgInterval, 1 ) )
364 if not blocking:
365 self.eventGeneratorLock.release()
366 time.sleep( upUpInterval )
367 self.eventGeneratorLock.acquire()
368 else:
369 time.sleep( upUpInterval )
370 self.eventGeneratorLock.release()
371
372 def installAllHostIntents( self, scheduleMethod, args=None ):
373 """
374 This function installs host intents for all host pairs
375 After all intent events are inserted, this funciton also insert intent and traffic checks
376 """
377 import itertools
378
379 with self.eventGeneratorLock:
380 if scheduleMethod == EventScheduleMethod().RUN_BLOCK:
381 main.eventScheduler.scheduleEvent( EventType().NULL, EventScheduleMethod().RUN_BLOCK )
382 availableControllers = []
383 for controller in main.controllers:
384 if controller.isUp():
385 availableControllers.append( controller.index )
386 if len( availableControllers ) == 0:
387 main.log.warn( "Event Generator - No available controllers" )
388 return
389 hostCombos = list( itertools.combinations( main.hosts, 2 ) )
390 for i in xrange( 0, len( hostCombos ), len( availableControllers ) ):
391 for CLIIndex in availableControllers:
392 if i >= len( hostCombos ):
393 break
394 main.eventScheduler.scheduleEvent( EventType().APP_INTENT_HOST_ADD,
395 EventScheduleMethod().RUN_NON_BLOCK,
396 [ hostCombos[ i ][ 0 ].name, hostCombos[ i ][ 1 ].name, CLIIndex ] )
397 i += 1
398 # Pending checks after installing all intents
399 if scheduleMethod == EventScheduleMethod().RUN_BLOCK:
400 main.eventScheduler.scheduleEvent( EventType().NULL, EventScheduleMethod().RUN_BLOCK )
401 sleepTime = int( main.params[ 'EVENT' ][ 'installAllHostIntents' ][ 'sleepBeforeCheck' ] )
402 main.eventScheduler.scheduleEvent( EventType().TEST_SLEEP, EventScheduleMethod().RUN_BLOCK, [ sleepTime ] )
You Wang55503a32016-06-27 15:11:40 -0700403 self.insertAllChecks( EventScheduleMethod().RUN_NON_BLOCK )
You Wangdb927a52016-02-26 11:03:28 -0800404 if scheduleMethod == EventScheduleMethod().RUN_BLOCK:
405 main.eventScheduler.scheduleEvent( EventType().NULL, EventScheduleMethod().RUN_BLOCK )
406
407 def removeAllHostIntents( self, scheduleMethod, args=None ):
408 """
409 This function removes host intents for all host pairs
410 After all intent events are inserted, this funciton also insert intent and traffic checks
411 """
412 import itertools
413
414 with self.eventGeneratorLock:
415 if scheduleMethod == EventScheduleMethod().RUN_BLOCK:
416 main.eventScheduler.scheduleEvent( EventType().NULL, EventScheduleMethod().RUN_BLOCK )
417 availableControllers = []
418 for controller in main.controllers:
419 if controller.isUp():
420 availableControllers.append( controller.index )
421 if len( availableControllers ) == 0:
422 main.log.warn( "Event Generator - No available controllers" )
423 return
424 hostCombos = list( itertools.combinations( main.hosts, 2 ) )
425 for i in xrange( 0, len( hostCombos ), len( availableControllers ) ):
426 for CLIIndex in availableControllers:
427 if i >= len( hostCombos ):
428 break
429 main.eventScheduler.scheduleEvent( EventType().APP_INTENT_HOST_DEL,
430 EventScheduleMethod().RUN_NON_BLOCK,
431 [ hostCombos[ i ][ 0 ].name, hostCombos[ i ][ 1 ].name, CLIIndex ] )
432 i += 1
433 # Pending checks after removing all intents
434 if scheduleMethod == EventScheduleMethod().RUN_BLOCK:
435 main.eventScheduler.scheduleEvent( EventType().NULL, EventScheduleMethod().RUN_BLOCK )
436 sleepTime = int( main.params[ 'EVENT' ][ 'removeAllHostIntents' ][ 'sleepBeforeCheck' ] )
437 main.eventScheduler.scheduleEvent( EventType().TEST_SLEEP, EventScheduleMethod().RUN_BLOCK, [ sleepTime ] )
You Wang55503a32016-06-27 15:11:40 -0700438 self.insertAllChecks( EventScheduleMethod().RUN_NON_BLOCK )
You Wangdb927a52016-02-26 11:03:28 -0800439 if scheduleMethod == EventScheduleMethod().RUN_BLOCK:
440 main.eventScheduler.scheduleEvent( EventType().NULL, EventScheduleMethod().RUN_BLOCK )
441
442 def installAllPointIntents( self, scheduleMethod, args=None ):
443 """
444 This function installs point intents for all device pairs
445 After all intent events are inserted, this funciton also insert intent and traffic checks
446 """
447 import itertools
448
449 with self.eventGeneratorLock:
450 if scheduleMethod == EventScheduleMethod().RUN_BLOCK:
451 main.eventScheduler.scheduleEvent( EventType().NULL, EventScheduleMethod().RUN_BLOCK )
452 availableControllers = []
453 for controller in main.controllers:
454 if controller.isUp():
455 availableControllers.append( controller.index )
456 if len( availableControllers ) == 0:
457 main.log.warn( "Event Generator - No available controllers" )
458 return
459 deviceCombos = list( itertools.permutations( main.devices, 2 ) )
460 for i in xrange( 0, len( deviceCombos ), len( availableControllers ) ):
461 for CLIIndex in availableControllers:
462 if i >= len( deviceCombos ):
463 break
464 main.eventScheduler.scheduleEvent( EventType().APP_INTENT_POINT_ADD,
465 EventScheduleMethod().RUN_NON_BLOCK,
466 [ deviceCombos[ i ][ 0 ].name, deviceCombos[ i ][ 1 ].name, CLIIndex ] )
467 i += 1
468 # Pending checks after installing all intents
469 if scheduleMethod == EventScheduleMethod().RUN_BLOCK:
470 main.eventScheduler.scheduleEvent( EventType().NULL, EventScheduleMethod().RUN_BLOCK )
471 sleepTime = int( main.params[ 'EVENT' ][ 'installAllPointIntents' ][ 'sleepBeforeCheck' ] )
472 main.eventScheduler.scheduleEvent( EventType().TEST_SLEEP, EventScheduleMethod().RUN_BLOCK, [ sleepTime ] )
You Wang55503a32016-06-27 15:11:40 -0700473 self.insertAllChecks( EventScheduleMethod().RUN_NON_BLOCK )
You Wangdb927a52016-02-26 11:03:28 -0800474 if scheduleMethod == EventScheduleMethod().RUN_BLOCK:
475 main.eventScheduler.scheduleEvent( EventType().NULL, EventScheduleMethod().RUN_BLOCK )
476
477 def removeAllPointIntents( self, scheduleMethod, args=None ):
478 """
479 This function removes point intents for all device pairs
480 After all intent events are inserted, this funciton also insert intent and traffic checks
481 """
482 import itertools
483
484 with self.eventGeneratorLock:
485 if scheduleMethod == EventScheduleMethod().RUN_BLOCK:
486 main.eventScheduler.scheduleEvent( EventType().NULL, EventScheduleMethod().RUN_BLOCK )
487 availableControllers = []
488 for controller in main.controllers:
489 if controller.isUp():
490 availableControllers.append( controller.index )
491 if len( availableControllers ) == 0:
492 main.log.warn( "Event Generator - No available controllers" )
493 return
494 deviceCombos = list( itertools.permutations( main.devices, 2 ) )
495 for i in xrange( 0, len( deviceCombos ), len( availableControllers ) ):
496 for CLIIndex in availableControllers:
497 if i >= len( deviceCombos ):
498 break
499 main.eventScheduler.scheduleEvent( EventType().APP_INTENT_POINT_DEL,
500 EventScheduleMethod().RUN_NON_BLOCK,
501 [ deviceCombos[ i ][ 0 ].name, deviceCombos[ i ][ 1 ].name, CLIIndex ] )
502 i += 1
503 # Pending checks after removing all intents
504 if scheduleMethod == EventScheduleMethod().RUN_BLOCK:
505 main.eventScheduler.scheduleEvent( EventType().NULL, EventScheduleMethod().RUN_BLOCK )
506 sleepTime = int( main.params[ 'EVENT' ][ 'removeAllPointIntents' ][ 'sleepBeforeCheck' ] )
507 main.eventScheduler.scheduleEvent( EventType().TEST_SLEEP, EventScheduleMethod().RUN_BLOCK, [ sleepTime ] )
You Wang55503a32016-06-27 15:11:40 -0700508 self.insertAllChecks( EventScheduleMethod().RUN_NON_BLOCK )
You Wangdb927a52016-02-26 11:03:28 -0800509 if scheduleMethod == EventScheduleMethod().RUN_BLOCK:
510 main.eventScheduler.scheduleEvent( EventType().NULL, EventScheduleMethod().RUN_BLOCK )