net.floodlightcontroller.debugevent
Class DebugEvent

java.lang.Object
  extended by net.floodlightcontroller.debugevent.DebugEvent
All Implemented Interfaces:
IFloodlightModule, IFloodlightService, IDebugEventService

public class DebugEvent
extends java.lang.Object
implements IFloodlightModule, IDebugEventService

This class implements a central store for all events used for debugging the system. The basic idea is that given the functionality provided by this class, it should be unnecessary to resort to scraping through system DEBUG/TRACE logs to understand behavior in a running system.

Author:
Saurav

Nested Class Summary
protected  class DebugEvent.DebugEventHistory
          Event history for a particular event-id is stored in a circular buffer
 class DebugEvent.EventInfo
          Event Information
protected  class DebugEvent.EventUpdaterImpl<T>
           
protected  class DebugEvent.LocalEventHistory
          Thread local storage for events
 
Nested classes/interfaces inherited from interface net.floodlightcontroller.debugevent.IDebugEventService
IDebugEventService.DebugEventInfo, IDebugEventService.EventColumn, IDebugEventService.EventFieldType, IDebugEventService.EventType, IDebugEventService.MaxEventsRegistered
 
Field Summary
protected  DebugEvent.DebugEventHistory[] allEvents
          Global storage for all event types and their corresponding event buffers.
protected  java.util.Set<java.lang.Integer> currentEvents
          A collection of event ids that are currently enabled for logging
protected  int eventIdCounter
          Every registered event type gets an event id, the value for which is obtained while holding the lock.
protected  java.lang.Object eventIdLock
           
protected static org.slf4j.Logger log
           
protected  java.util.concurrent.ConcurrentHashMap<java.lang.String,java.util.concurrent.ConcurrentHashMap<java.lang.String,java.lang.Integer>> moduleEvents
          Global storage for all event ids registered for a module.
protected  java.lang.ThreadLocal<java.util.Set<java.lang.Integer>> threadlocalCurrentEvents
          Thread local cache for event-ids that are currently active.
protected  java.lang.ThreadLocal<DebugEvent.LocalEventHistory[]> threadlocalEvents
          Thread local event buffers used for maintaining event history local to a thread.
 
Fields inherited from interface net.floodlightcontroller.debugevent.IDebugEventService
EV_MDATA_ERROR, EV_MDATA_WARN, MAX_EVENTS
 
Constructor Summary
DebugEvent()
           
 
Method Summary
 boolean containsModuleEventName(java.lang.String moduleName, java.lang.String eventName)
          Determine if eventName is a registered event for a given moduleName
 boolean containsModuleName(java.lang.String moduleName)
          Determine if any events have been registered for module of name moduleName
 void flushEvents()
          Update the global event stores with values from the thread local stores.
 java.util.List<IDebugEventService.DebugEventInfo> getAllEventHistory()
          Get event history for all events.
 java.util.Collection<java.lang.Class<? extends IFloodlightService>> getModuleDependencies()
          Get a list of Modules that this module depends on.
 java.util.List<IDebugEventService.DebugEventInfo> getModuleEventHistory(java.lang.String moduleName)
          Get event history for all events registered for a given moduleName
 java.util.List<java.lang.String> getModuleEventList(java.lang.String moduleName)
          Returns a list of all events registered for a specific moduleName or a empty list
 java.util.List<java.lang.String> getModuleList()
          Retrieve a list of moduleNames registered for debug events or an empty list if no events have been registered in the system
 java.util.Collection<java.lang.Class<? extends IFloodlightService>> getModuleServices()
          Return the list of interfaces that this module implements.
 java.util.Map<java.lang.Class<? extends IFloodlightService>,IFloodlightService> getServiceImpls()
          Instantiate (as needed) and return objects that implement each of the services exported by this module.
 IDebugEventService.DebugEventInfo getSingleEventHistory(java.lang.String moduleName, java.lang.String eventName, int last)
          Get event history for a single event
 void init(FloodlightModuleContext context)
          This is a hook for each module to do its internal initialization, e.g., call setService(context.getService("Service")) All module dependencies are resolved when this is called, but not every module is initialized.
<T> IEventUpdater<T>
registerEvent(java.lang.String moduleName, java.lang.String eventName, java.lang.String eventDescription, IDebugEventService.EventType et, java.lang.Class<T> eventClass, int bufferCapacity, java.lang.String... metaData)
          Register an event for debugging.
 void resetAllEvents()
          Wipe out all event history for all registered events
 void resetAllModuleEvents(java.lang.String moduleName)
          Wipe out all event history for all events registered for a specific module
 void resetSingleEvent(java.lang.String moduleName, java.lang.String eventName)
          Wipe out event history for a single event
 void startUp(FloodlightModuleContext context)
          This is a hook for each module to do its external initializations, e.g., register for callbacks or query for state in other modules It is expected that this function will not block and that modules that want non-event driven CPU will spawn their own threads.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

protected static org.slf4j.Logger log

eventIdCounter

protected int eventIdCounter
Every registered event type gets an event id, the value for which is obtained while holding the lock.


eventIdLock

protected java.lang.Object eventIdLock

allEvents

protected DebugEvent.DebugEventHistory[] allEvents
Global storage for all event types and their corresponding event buffers. A particular event type is accessed by directly indexing into the array with the corresponding event-id.


moduleEvents

protected java.util.concurrent.ConcurrentHashMap<java.lang.String,java.util.concurrent.ConcurrentHashMap<java.lang.String,java.lang.Integer>> moduleEvents
Global storage for all event ids registered for a module. The map is indexed by the module name and event name and returns the event-ids that correspond to the event types registered by that module (for example module 'linkdiscovery' may register events that have ids 0 and 1 that correspond to link up/down events, and receiving malformed LLDP packets, respectively).


currentEvents

protected java.util.Set<java.lang.Integer> currentEvents
A collection of event ids that are currently enabled for logging


threadlocalEvents

protected final java.lang.ThreadLocal<DebugEvent.LocalEventHistory[]> threadlocalEvents
Thread local event buffers used for maintaining event history local to a thread. Eventually this locally maintained information is flushed into the global event buffers.


threadlocalCurrentEvents

protected final java.lang.ThreadLocal<java.util.Set<java.lang.Integer>> threadlocalCurrentEvents
Thread local cache for event-ids that are currently active.

Constructor Detail

DebugEvent

public DebugEvent()
Method Detail

registerEvent

public <T> IEventUpdater<T> registerEvent(java.lang.String moduleName,
                                          java.lang.String eventName,
                                          java.lang.String eventDescription,
                                          IDebugEventService.EventType et,
                                          java.lang.Class<T> eventClass,
                                          int bufferCapacity,
                                          java.lang.String... metaData)
                               throws IDebugEventService.MaxEventsRegistered
Description copied from interface: IDebugEventService
Register an event for debugging.

Specified by:
registerEvent in interface IDebugEventService
Parameters:
moduleName - module registering event eg. linkdiscovery, virtualrouting.
eventName - name given to event.
eventDescription - A descriptive string describing the event.
et - EventType for this event. On-demand events have to be explicitly enabled using other methods in this API
eventClass - A user defined class that annotates the fields with @EventColumn. This class specifies the fields/columns for this event.
bufferCapacity - Number of events to store for this event in a circular buffer. Older events will be discarded once the buffer is full.
metaData - variable arguments that qualify an event eg. EV_MDATA_WARN, EV_MDATA_ERROR etc. See Debug Event Qualifiers
Returns:
IEventUpdater with update methods that can be used to update an event of the given eventClass
Throws:
IDebugEventService.MaxEventsRegistered

flushEvents

public void flushEvents()
Description copied from interface: IDebugEventService
Update the global event stores with values from the thread local stores. This method is not typically intended for use by any module. It's typical usage is from floodlight core for events that happen in the packet processing pipeline. For other rare events, flushEvents should be called.

Specified by:
flushEvents in interface IDebugEventService

containsModuleEventName

public boolean containsModuleEventName(java.lang.String moduleName,
                                       java.lang.String eventName)
Description copied from interface: IDebugEventService
Determine if eventName is a registered event for a given moduleName

Specified by:
containsModuleEventName in interface IDebugEventService

containsModuleName

public boolean containsModuleName(java.lang.String moduleName)
Description copied from interface: IDebugEventService
Determine if any events have been registered for module of name moduleName

Specified by:
containsModuleName in interface IDebugEventService

getAllEventHistory

public java.util.List<IDebugEventService.DebugEventInfo> getAllEventHistory()
Description copied from interface: IDebugEventService
Get event history for all events. This call can be expensive as it formats the event histories for all events.

Specified by:
getAllEventHistory in interface IDebugEventService
Returns:
a list of all event histories or an empty list if no events have been registered

getModuleEventHistory

public java.util.List<IDebugEventService.DebugEventInfo> getModuleEventHistory(java.lang.String moduleName)
Description copied from interface: IDebugEventService
Get event history for all events registered for a given moduleName

Specified by:
getModuleEventHistory in interface IDebugEventService
Returns:
a list of all event histories for all events registered for the the module or an empty list if there are no events for this module

getSingleEventHistory

public IDebugEventService.DebugEventInfo getSingleEventHistory(java.lang.String moduleName,
                                                               java.lang.String eventName,
                                                               int last)
Description copied from interface: IDebugEventService
Get event history for a single event

Specified by:
getSingleEventHistory in interface IDebugEventService
Parameters:
moduleName - registered module name
eventName - registered event name for moduleName
last - last X events
Returns:
DebugEventInfo for that event, or null if the moduleEventName does not correspond to a registered event.

resetAllEvents

public void resetAllEvents()
Description copied from interface: IDebugEventService
Wipe out all event history for all registered events

Specified by:
resetAllEvents in interface IDebugEventService

resetAllModuleEvents

public void resetAllModuleEvents(java.lang.String moduleName)
Description copied from interface: IDebugEventService
Wipe out all event history for all events registered for a specific module

Specified by:
resetAllModuleEvents in interface IDebugEventService
Parameters:
moduleName - registered module name

resetSingleEvent

public void resetSingleEvent(java.lang.String moduleName,
                             java.lang.String eventName)
Description copied from interface: IDebugEventService
Wipe out event history for a single event

Specified by:
resetSingleEvent in interface IDebugEventService
Parameters:
moduleName - registered module name
eventName - registered event name for moduleName

getModuleList

public java.util.List<java.lang.String> getModuleList()
Description copied from interface: IDebugEventService
Retrieve a list of moduleNames registered for debug events or an empty list if no events have been registered in the system

Specified by:
getModuleList in interface IDebugEventService

getModuleEventList

public java.util.List<java.lang.String> getModuleEventList(java.lang.String moduleName)
Description copied from interface: IDebugEventService
Returns a list of all events registered for a specific moduleName or a empty list

Specified by:
getModuleEventList in interface IDebugEventService

getModuleServices

public java.util.Collection<java.lang.Class<? extends IFloodlightService>> getModuleServices()
Description copied from interface: IFloodlightModule
Return the list of interfaces that this module implements. All interfaces must inherit IFloodlightService

Specified by:
getModuleServices in interface IFloodlightModule
Returns:

getServiceImpls

public java.util.Map<java.lang.Class<? extends IFloodlightService>,IFloodlightService> getServiceImpls()
Description copied from interface: IFloodlightModule
Instantiate (as needed) and return objects that implement each of the services exported by this module. The map returned maps the implemented service to the object. The object could be the same object or different objects for different exported services.

Specified by:
getServiceImpls in interface IFloodlightModule
Returns:
The map from service interface class to service implementation

getModuleDependencies

public java.util.Collection<java.lang.Class<? extends IFloodlightService>> getModuleDependencies()
Description copied from interface: IFloodlightModule
Get a list of Modules that this module depends on. The module system will ensure that each these dependencies is resolved before the subsequent calls to init().

Specified by:
getModuleDependencies in interface IFloodlightModule
Returns:
The Collection of IFloodlightServices that this module depends on.

init

public void init(FloodlightModuleContext context)
          throws FloodlightModuleException
Description copied from interface: IFloodlightModule
This is a hook for each module to do its internal initialization, e.g., call setService(context.getService("Service")) All module dependencies are resolved when this is called, but not every module is initialized.

Specified by:
init in interface IFloodlightModule
Throws:
FloodlightModuleException

startUp

public void startUp(FloodlightModuleContext context)
             throws FloodlightModuleException
Description copied from interface: IFloodlightModule
This is a hook for each module to do its external initializations, e.g., register for callbacks or query for state in other modules It is expected that this function will not block and that modules that want non-event driven CPU will spawn their own threads.

Specified by:
startUp in interface IFloodlightModule
Throws:
FloodlightModuleException