Skip to content
Snippets Groups Projects
Commit 77ac6d62 authored by Saurav Das's avatar Saurav Das
Browse files

Changes after code review - typos and better error handling

parent fd98cbef
No related branches found
No related tags found
No related merge requests found
......@@ -171,8 +171,6 @@ public class DebugEvent implements IFloodlightModule, IDebugEventService {
}
};
/**
* Thread local cache for event-ids that are currently active.
*/
......@@ -192,14 +190,13 @@ public class DebugEvent implements IFloodlightModule, IDebugEventService {
public int registerEvent(String moduleName, String eventName,
boolean flushImmediately, String eventDescription,
EventType et, int bufferCapacity, String formatStr,
Object[] params) {
Object[] params) throws MaxEventsRegistered {
int eventId = -1;
synchronized (eventIdLock) {
eventId = Integer.valueOf(eventIdCounter++);
}
if (eventId > MAX_EVENTS-2) {
log.error("Cannot register any more events - max threshold reached");
eventId = MAX_EVENTS-1; // last element of array
if (eventId > MAX_EVENTS-1) {
throw new MaxEventsRegistered();
}
// register event id for moduleName
......@@ -219,7 +216,7 @@ public class DebugEvent implements IFloodlightModule, IDebugEventService {
et, formatStr, eventDescription, eventName,
moduleName, flushImmediately);
allEvents[eventId] = new DebugEventHistory(ei, bufferCapacity);
if (enabled && eventId < MAX_EVENTS-1) {
if (enabled && eventId < MAX_EVENTS) {
currentEvents.add(eventId);
}
......@@ -228,7 +225,7 @@ public class DebugEvent implements IFloodlightModule, IDebugEventService {
@Override
public void updateEvent(int eventId, Object[] params) {
if (eventId < 0 || eventId > MAX_EVENTS-2) return;
if (eventId < 0 || eventId > MAX_EVENTS-1) return;
LocalEventHistory[] thishist = this.threadlocalEvents.get();
if (thishist[eventId] == null) {
......
......@@ -38,6 +38,13 @@ public interface IDebugEventService extends IFloodlightService {
}
}
/**
* exception thrown when MAX_EVENTS have been registered
*/
public class MaxEventsRegistered extends Exception {
private static final long serialVersionUID = 2609587082227510262L;
}
/**
* Register an event for debugging.
*
......@@ -64,10 +71,12 @@ public interface IDebugEventService extends IFloodlightService {
* event. This can just be null for now.
* @return an eventId for this event. All updates to this
* event must use the returned eventId.
* @throws MaxEventsRegistered
*/
public int registerEvent(String moduleName, String eventName, boolean flushNow,
String eventDescription, EventType et,
int bufferCapacity, String formatStr, Object[] params);
int bufferCapacity, String formatStr, Object[] params)
throws MaxEventsRegistered;
/**
* updateEvent is used to log events for pre-registered events. This method
......
......@@ -22,7 +22,7 @@ import org.slf4j.LoggerFactory;
* where {param} must be one of (no quotes):
* "all" returns value/info on all active events.
* "{moduleName}" returns value/info on all active events for the specified module.
* "{moduleCounterName}" returns value/info for specific event if it is active.
* "{moduleEventName}" returns value/info for specific event if it is active.
*
* @author Saurav
*/
......
......@@ -60,6 +60,7 @@ import net.floodlightcontroller.debugcounter.IDebugCounterService;
import net.floodlightcontroller.debugcounter.IDebugCounterService.CounterType;
import net.floodlightcontroller.debugcounter.NullDebugCounter;
import net.floodlightcontroller.debugevent.IDebugEventService;
import net.floodlightcontroller.debugevent.IDebugEventService.MaxEventsRegistered;
import net.floodlightcontroller.debugevent.NullDebugEvent;
import net.floodlightcontroller.debugevent.IDebugEventService.EventType;
import net.floodlightcontroller.linkdiscovery.ILinkDiscovery;
......@@ -2073,7 +2074,7 @@ public class LinkDiscoveryManager implements IOFMessageListener,
}
registerLinkDiscoveryDebugCounters();
registerLinkDiscovertDebugEvents();
registerLinkDiscoveryDebugEvents();
ScheduledExecutorService ses = threadPool.getScheduledExecutor();
......@@ -2167,23 +2168,27 @@ public class LinkDiscoveryManager implements IOFMessageListener,
CounterType.COUNT_ON_DEMAND);
}
private void registerLinkDiscovertDebugEvents() {
private void registerLinkDiscoveryDebugEvents() {
if (debugEvents == null) {
log.error("Debug Event Service not found.");
debugEvents = new NullDebugEvent();
return;
}
SWITCH_EVENT = debugEvents.registerEvent(
getName(), "switchevent", true,
"Switch connected, disconnected or port changed",
EventType.ALWAYS_LOG, 100,
"Sw=%dpid, reason=%s", null);
LINK_EVENT = debugEvents.registerEvent(
getName(), "linkevent", false,
"Direct OpenFlow links discovered or timed-out",
EventType.ALWAYS_LOG, 100,
"srcSw=%dpid, srcPort=%d, dstSw=%dpid, dstPort=%d, reason=%s", null);
try {
SWITCH_EVENT = debugEvents.registerEvent(
getName(), "switchevent", true,
"Switch connected, disconnected or port changed",
EventType.ALWAYS_LOG, 100,
"Sw=%dpid, reason=%s", null);
LINK_EVENT = debugEvents.registerEvent(
getName(), "linkevent", false,
"Direct OpenFlow links discovered or timed-out",
EventType.ALWAYS_LOG, 100,
"srcSw=%dpid, srcPort=%d, dstSw=%dpid, dstPort=%d, reason=%s", null);
} catch (MaxEventsRegistered e) {
e.printStackTrace();
}
}
// ****************************************************
......
......@@ -7,6 +7,7 @@ import org.slf4j.LoggerFactory;
import net.floodlightcontroller.debugevent.IDebugEventService.DebugEventInfo;
import net.floodlightcontroller.debugevent.IDebugEventService.EventType;
import net.floodlightcontroller.debugevent.IDebugEventService.MaxEventsRegistered;
import net.floodlightcontroller.test.FloodlightTestCase;
public class DebugEventTest extends FloodlightTestCase {
......@@ -24,9 +25,14 @@ public class DebugEventTest extends FloodlightTestCase {
@Test
public void testRegisterAndUpdateEvent() {
assertEquals(0, debugEvent.currentEvents.size());
int eventId = debugEvent.registerEvent("dbgevtest", "switchevent", true,
int eventId = -1;
try {
eventId = debugEvent.registerEvent("dbgevtest", "switchevent", true,
"switchtest", EventType.ALWAYS_LOG,
100, "Sw=%dpid, reason=%s", null);
} catch (MaxEventsRegistered e) {
e.printStackTrace();
}
assertEquals(1, debugEvent.currentEvents.size());
assertEquals(eventId, debugEvent.moduleEvents.get("dbgevtest").
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment