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

completing the REST-API for debug counters and fixing a bug

parent 4e83faca
No related branches found
No related tags found
No related merge requests found
......@@ -164,6 +164,7 @@ public class DebugCounter implements IFloodlightModule, IDebugCounterService {
@Override
public void flushCounters() {
Map<String, MutableLong> thismap = this.threadlocalCounters.get();
ArrayList<String> deleteKeys = new ArrayList<String>();
for (String key : thismap.keySet()) {
MutableLong curval = thismap.get(key);
long delta = curval.get();
......@@ -177,13 +178,16 @@ public class DebugCounter implements IFloodlightModule, IDebugCounterService {
// recreated (see updateCounter)
Set<String> thisset = this.threadlocalCurrentCounters.get();
thisset.remove(key);
thismap.remove(key);
deleteKeys.add(key);
} else {
ctr.addAndGet(delta);
curval.set(0);
}
}
}
for (String dkey : deleteKeys)
thismap.remove(dkey);
// At this point it is also possible that the threadlocal map/set does not
// include a counter that has been enabled and is present in the global
// current counter store. If so we need to sync such state so that the
......@@ -192,7 +196,6 @@ public class DebugCounter implements IFloodlightModule, IDebugCounterService {
if (thisset.size() != currentCounters.size()) {
thisset.addAll(currentCounters);
}
//printAllCounters();
}
@Override
......
......@@ -14,12 +14,12 @@ import org.slf4j.LoggerFactory;
* Return the debug counter data for the get rest-api call
*
* URI must be in one of the following forms:
* "http://<controller-hostname>:8080/wm/core/debugcounter/<param>/json
* "http://{controller-hostname}:8080/wm/core/debugcounter/{param}/json
*
* where <param> must be one of (no quotes)
* all returns value/info on all active counters
* <moduleName> returns value/info on all active counters for the specified module
* <moduleCounterName> returns value/info for specific counter if it is enabled
* where {param} must be one of (no quotes):
* "all" returns value/info on all active counters.
* "{moduleName}" returns value/info on all active counters for the specified module.
* "{moduleCounterName}" returns value/info for specific counter if it is enabled.
*
* @author Saurav
*/
......
......@@ -7,13 +7,13 @@ import org.slf4j.LoggerFactory;
/**
* Reset debug counter values
*
* URI must be in one of the following forms: " +
* "http://<controller-hostname>:8080/wm/core/debugcounter/reset/<param>/json
* URI must be in one of the following forms:
* "http://{controller-hostname}:8080/wm/core/debugcounter/reset/{param}/json
*
* where <param> must be one of (no quotes)
* all resets all active counters
* <moduleName> resets all active counters for the specified module
* <moduleCounterName> resets specific counter if it is enabled
* where {param} must be one of (no quotes):
* "all" resets all active counters.
* "{moduleName}" resets all active counters for the specified module.
* "{moduleCounterName}" resets specific counter if it is enabled.
*
* @author Saurav
*/
......
package net.floodlightcontroller.debugcounter;
import org.restlet.resource.Get;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Enable/disable on-demand counters
*
* URI must be in one of the following forms: " +
* "http://<controller-hostname>:8080/wm/core/debugcounter/<moduleCounterName>/<state>/json
* URI must be in one of the following forms:
* "http://{controller-hostname}:8080/wm/core/debugcounter/{moduleCounterName}/{state}/json
*
* where <state> must be one of (no quotes)
* enable enables counter <moduleCounterName> if it is an on-demand counter
* disable disables counter <moduleCounterName> if it is an on-demand counter
* where {state} must be one of (no quotes):
* "enable" enables counter {moduleCounterName} if it is an on-demand counter.
* "disable" disables counter {moduleCounterName} if it is an on-demand counter.
*
* @author Saurav
*/
public class DebugCounterStateResource extends DebugCounterResourceBase {
protected static Logger logger =
LoggerFactory.getLogger(DebugCounterStateResource.class);
public static class StateOutput {
String error;
public StateOutput() {
error = null;
}
public String getError() {
return error;
}
}
@Get("json")
public StateOutput handleCounterStateCmd() {
StateOutput output = new StateOutput();
String state = (String)getRequestAttributes().get("state");
String moduleCounterName = (String)getRequestAttributes().get("moduleCounterName");
if (!moduleCounterName.contains("-")) {
output.error = "Specified moduleCounterName is not of type " +
"<moduleName>-<counterName>.";
return output;
}
if ( !(state.equals("enable") || state.equals("disable")) ) {
output.error = "State must be either enable or disable";
return output;
}
if (state.equals("enable")) {
debugCounter.enableCtrOnDemand(moduleCounterName);
} else {
debugCounter.disableCtrOnDemand(moduleCounterName);
}
output.error = "None";
return output;
}
}
......@@ -770,6 +770,7 @@ public class LinkDiscoveryManager implements IOFMessageListener,
removeFromMaintenanceQueue(nptDst);
// Consume this message
debugCounters.updateCounter("linkdiscovery-lldpeol");
return Command.STOP;
}
......@@ -2267,6 +2268,8 @@ public class LinkDiscoveryManager implements IOFMessageListener,
}
debugCounters.registerCounter(getName() + "-" + "incoming",
"All incoming packets seen by this module", CounterType.ALWAYS_COUNT);
debugCounters.registerCounter(getName() + "-" + "lldpeol",
"End of Life for LLDP packets", CounterType.COUNT_ON_DEMAND);
}
// ****************************************************
......
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