Brian O'Connor | c67f9fa | 2014-08-07 18:17:46 -0700 | [diff] [blame] | 1 | package net.floodlightcontroller.debugevent; |
| 2 | |
| 3 | import java.lang.annotation.ElementType; |
| 4 | import java.lang.annotation.Retention; |
| 5 | import java.lang.annotation.RetentionPolicy; |
| 6 | import java.lang.annotation.Target; |
| 7 | import java.util.List; |
| 8 | import java.util.Map; |
| 9 | |
| 10 | import net.floodlightcontroller.core.module.IFloodlightService; |
| 11 | import net.floodlightcontroller.debugevent.DebugEvent.EventInfo; |
| 12 | |
| 13 | public interface IDebugEventService extends IFloodlightService { |
| 14 | |
| 15 | /** |
| 16 | * Different event types. Events that are meant to be logged on demand |
| 17 | * need to be separately enabled/disabled. |
| 18 | */ |
| 19 | public enum EventType { |
| 20 | ALWAYS_LOG, |
| 21 | LOG_ON_DEMAND |
| 22 | } |
| 23 | |
| 24 | /** |
| 25 | * Describes the type of field obtained from reflection |
| 26 | */ |
| 27 | enum EventFieldType { |
| 28 | DPID, IPv4, MAC, STRING, OBJECT, PRIMITIVE, LIST_IPV4, |
| 29 | LIST_ATTACHMENT_POINT, LIST_OBJECT, SREF_LIST_OBJECT, SREF_OBJECT, |
| 30 | FLOW_MOD_FLAGS |
| 31 | } |
| 32 | |
| 33 | /** |
| 34 | * EventColumn is the only annotation given to the fields of the event |
| 35 | * when updating an event. |
| 36 | */ |
| 37 | @Target(ElementType.FIELD) |
| 38 | @Retention(RetentionPolicy.RUNTIME) |
| 39 | public @interface EventColumn { |
| 40 | String name() default "param"; |
| 41 | EventFieldType description() default EventFieldType.PRIMITIVE; |
| 42 | } |
| 43 | |
| 44 | /** |
| 45 | * Debug Event Qualifiers |
| 46 | */ |
| 47 | public static final String EV_MDATA_WARN = "warn"; |
| 48 | public static final String EV_MDATA_ERROR = "error"; |
| 49 | |
| 50 | /** |
| 51 | * A limit on the maximum number of events that can be created |
| 52 | */ |
| 53 | public static final int MAX_EVENTS = 2000; |
| 54 | |
| 55 | /** |
| 56 | * Public class for information returned in response to rest API calls. |
| 57 | */ |
| 58 | public class DebugEventInfo { |
| 59 | EventInfo eventInfo; |
| 60 | List<Map<String,String>> events; |
| 61 | |
| 62 | public DebugEventInfo(EventInfo eventInfo, |
| 63 | List<Map<String, String>> eventHistory) { |
| 64 | this.eventInfo = eventInfo; |
| 65 | this.events = eventHistory; |
| 66 | } |
| 67 | |
| 68 | public EventInfo getEventInfo() { |
| 69 | return eventInfo; |
| 70 | } |
| 71 | |
| 72 | public List<Map<String,String>> getEvents() { |
| 73 | return events; |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | /** |
| 78 | * exception thrown when MAX_EVENTS have been registered |
| 79 | */ |
| 80 | public class MaxEventsRegistered extends Exception { |
| 81 | private static final long serialVersionUID = 2609587082227510262L; |
| 82 | } |
| 83 | |
| 84 | /** |
| 85 | * Register an event for debugging. |
| 86 | * |
| 87 | * @param moduleName module registering event eg. linkdiscovery, virtualrouting. |
| 88 | * @param eventName name given to event. |
| 89 | * @param eventDescription A descriptive string describing the event. |
| 90 | * @param eventType EventType for this event. On-demand events have to |
| 91 | * be explicitly enabled using other methods in this API |
| 92 | * @param eventClass A user defined class that annotates the fields |
| 93 | * with @EventColumn. This class specifies the |
| 94 | * fields/columns for this event. |
| 95 | * @param bufferCapacity Number of events to store for this event in a circular |
| 96 | * buffer. Older events will be discarded once the |
| 97 | * buffer is full. |
| 98 | * @param metaData variable arguments that qualify an event |
| 99 | * eg. EV_MDATA_WARN, EV_MDATA_ERROR etc. See Debug Event Qualifiers |
| 100 | * @return IEventUpdater with update methods that can be used to |
| 101 | * update an event of the given eventClass |
| 102 | * @throws MaxEventsRegistered |
| 103 | */ |
| 104 | public <T> IEventUpdater<T> registerEvent(String moduleName, String eventName, |
| 105 | String eventDescription, |
| 106 | EventType eventType, |
| 107 | Class<T> eventClass, |
| 108 | int bufferCapacity, |
| 109 | String... metaData) |
| 110 | throws MaxEventsRegistered; |
| 111 | |
| 112 | /** |
| 113 | * Update the global event stores with values from the thread local stores. This |
| 114 | * method is not typically intended for use by any module. It's typical usage is from |
| 115 | * floodlight core for events that happen in the packet processing pipeline. |
| 116 | * For other rare events, flushEvents should be called. |
| 117 | */ |
| 118 | public void flushEvents(); |
| 119 | |
| 120 | /** |
| 121 | * Determine if eventName is a registered event for a given moduleName |
| 122 | */ |
| 123 | public boolean containsModuleEventName(String moduleName, String eventName); |
| 124 | |
| 125 | /** |
| 126 | * Determine if any events have been registered for module of name moduleName |
| 127 | */ |
| 128 | public boolean containsModuleName(String moduleName); |
| 129 | |
| 130 | /** |
| 131 | * Get event history for all events. This call can be expensive as it |
| 132 | * formats the event histories for all events. |
| 133 | * |
| 134 | * @return a list of all event histories or an empty list if no events have |
| 135 | * been registered |
| 136 | */ |
| 137 | public List<DebugEventInfo> getAllEventHistory(); |
| 138 | |
| 139 | /** |
| 140 | * Get event history for all events registered for a given moduleName |
| 141 | * |
| 142 | * @return a list of all event histories for all events registered for the |
| 143 | * the module or an empty list if there are no events for this module |
| 144 | */ |
| 145 | public List<DebugEventInfo> getModuleEventHistory(String moduleName); |
| 146 | |
| 147 | /** |
| 148 | * Get event history for a single event |
| 149 | * |
| 150 | * @param moduleName registered module name |
| 151 | * @param eventName registered event name for moduleName |
| 152 | * @param last last X events |
| 153 | * @return DebugEventInfo for that event, or null if the moduleEventName |
| 154 | * does not correspond to a registered event. |
| 155 | */ |
| 156 | public DebugEventInfo getSingleEventHistory(String moduleName, String eventName, int last); |
| 157 | |
| 158 | /** |
| 159 | * Wipe out all event history for all registered events |
| 160 | */ |
| 161 | public void resetAllEvents(); |
| 162 | |
| 163 | /** |
| 164 | * Wipe out all event history for all events registered for a specific module |
| 165 | * |
| 166 | * @param moduleName registered module name |
| 167 | */ |
| 168 | public void resetAllModuleEvents(String moduleName); |
| 169 | |
| 170 | /** |
| 171 | * Wipe out event history for a single event |
| 172 | * @param moduleName registered module name |
| 173 | * @param eventName registered event name for moduleName |
| 174 | */ |
| 175 | public void resetSingleEvent(String moduleName, String eventName); |
| 176 | |
| 177 | /** |
| 178 | * Retrieve a list of moduleNames registered for debug events or an empty |
| 179 | * list if no events have been registered in the system |
| 180 | */ |
| 181 | public List<String> getModuleList(); |
| 182 | |
| 183 | /** |
| 184 | * Returns a list of all events registered for a specific moduleName |
| 185 | * or a empty list |
| 186 | */ |
| 187 | public List<String> getModuleEventList(String moduleName); |
| 188 | |
| 189 | } |