diff --git a/src/main/java/net/floodlightcontroller/debugcounter/DebugCounter.java b/src/main/java/net/floodlightcontroller/debugcounter/DebugCounter.java index 754323d0a734b76648ecb261bce613716f5a4184..5bb1ce16757a4faa363205c346887ad1fbbc0d3e 100644 --- a/src/main/java/net/floodlightcontroller/debugcounter/DebugCounter.java +++ b/src/main/java/net/floodlightcontroller/debugcounter/DebugCounter.java @@ -513,6 +513,29 @@ public class DebugCounter implements IFloodlightModule, IDebugCounterService { return (moduleCounters.containsKey(moduleName)) ? true : false; } + @Override + public List<String> getModuleList() { + List<String> retval = new ArrayList<String>(); + retval.addAll(moduleCounters.keySet()); + return retval; + } + + @Override + public List<String> getModuleCounterList(String moduleName) { + if (!moduleCounters.containsKey(moduleName)) + return Collections.emptyList(); + + List<String> retval = new ArrayList<String>(); + RetCtrInfo rci = new RetCtrInfo(); + rci.levels = "".split("/"); + + ArrayList<Integer> cids = getHierarchyBelow(moduleName, rci); + for (int index : cids) { + retval.add(allCounters[index].cinfo.counterHierarchy); + } + return retval; + } + //******************************* // Internal Methods //******************************* diff --git a/src/main/java/net/floodlightcontroller/debugcounter/IDebugCounterService.java b/src/main/java/net/floodlightcontroller/debugcounter/IDebugCounterService.java index b61c8449cbd12cd1544a084c0ca283b902d9fbcd..538e60dad148c600e3802b53271ed6e111d8f6b9 100644 --- a/src/main/java/net/floodlightcontroller/debugcounter/IDebugCounterService.java +++ b/src/main/java/net/floodlightcontroller/debugcounter/IDebugCounterService.java @@ -243,5 +243,17 @@ public interface IDebugCounterService extends IFloodlightService { */ public boolean containsModuleName(String moduleName); + /** + * Returns a list of moduleNames registered for debug counters or an empty + * list if no counters have been registered in the system + */ + public List<String> getModuleList(); + + /** + * Returns a list of all counters registered for a specific moduleName + * or a empty list + */ + public List<String> getModuleCounterList(String moduleName); + } diff --git a/src/main/java/net/floodlightcontroller/debugcounter/NullDebugCounter.java b/src/main/java/net/floodlightcontroller/debugcounter/NullDebugCounter.java index 9aed1951059a056d3d4d5f34c7dfc051af7c4dba..e9081a8e07bead12f847f0a4a2ffe347e9243d9b 100644 --- a/src/main/java/net/floodlightcontroller/debugcounter/NullDebugCounter.java +++ b/src/main/java/net/floodlightcontroller/debugcounter/NullDebugCounter.java @@ -122,6 +122,16 @@ public class NullDebugCounter implements IFloodlightModule, IDebugCounterService return new NullCounterImpl(); } + @Override + public List<String> getModuleList() { + return Collections.emptyList(); + } + + @Override + public List<String> getModuleCounterList(String moduleName) { + return Collections.emptyList(); + } + public class NullCounterImpl implements IDebugCounter { @Override @@ -150,6 +160,4 @@ public class NullDebugCounter implements IFloodlightModule, IDebugCounterService } - - } diff --git a/src/main/java/net/floodlightcontroller/debugcounter/web/DebugCounterResource.java b/src/main/java/net/floodlightcontroller/debugcounter/web/DebugCounterResource.java index ccddb02afe38af34f3789e0bf1ec2932c308b740..f4d00bf14d5d269e8574241e9772f961854747b0 100644 --- a/src/main/java/net/floodlightcontroller/debugcounter/web/DebugCounterResource.java +++ b/src/main/java/net/floodlightcontroller/debugcounter/web/DebugCounterResource.java @@ -28,28 +28,28 @@ public class DebugCounterResource extends DebugCounterResourceBase { public class DebugCounterInfoOutput { protected class DCInfo { private final Long counterValue; - private final CounterType cType; + private final CounterType counterType; private final String counterDesc; private final boolean enabled; private final String counterHierarchy; private final String moduleName; + private final String[] metaData; DCInfo(DebugCounterInfo dci) { this.moduleName = dci.getCounterInfo().getModuleName(); this.counterHierarchy = dci.getCounterInfo().getCounterHierarchy(); - this.counterDesc = dci.getCounterInfo().getCounterHierarchy(); - //this.metaData = dci.getCounterInfo().getMetaData(); + this.counterDesc = dci.getCounterInfo().getCounterDesc(); + this.metaData = dci.getCounterInfo().getMetaData(); this.enabled = dci.getCounterInfo().isEnabled(); - this.cType = dci.getCounterInfo().getCtype(); + this.counterType = dci.getCounterInfo().getCtype(); this.counterValue = dci.getCounterValue(); } public Long getCounterValue() { return counterValue; } - - public CounterType getcType() { - return cType; + public CounterType getCounterType() { + return counterType; } public String getCounterDesc() { @@ -68,13 +68,24 @@ public class DebugCounterResource extends DebugCounterResourceBase { return moduleName; } - } + public String[] getMetaData() { + return metaData; + } + } + // complete counter information - null if only names are requested or + // if an error occurs public Map<String, DCInfo> counterMap; + // list of names could be just moduleNames or counter hierarchical names + // for a specific module + public List<String> names; + public String error; - DebugCounterInfoOutput() { - counterMap = new HashMap<String, DCInfo>(); + DebugCounterInfoOutput(boolean getList) { + if (!getList) { + counterMap = new HashMap<String, DCInfo>(); + } error = null; } public Map<String, DCInfo> getCounterMap() { @@ -85,6 +96,10 @@ public class DebugCounterResource extends DebugCounterResourceBase { return error; } + public List<String> getNames() { + return names; + } + } public enum Option { @@ -258,7 +273,7 @@ public class DebugCounterResource extends DebugCounterResourceBase { */ @Get public DebugCounterInfoOutput handleCounterInfoQuery() { - DebugCounterInfoOutput output = new DebugCounterInfoOutput(); + DebugCounterInfoOutput output; Option choice = Option.ERROR_BAD_PARAM; String param1 = (String)getRequestAttributes().get("param1"); String param2 = (String)getRequestAttributes().get("param2"); @@ -266,14 +281,34 @@ public class DebugCounterResource extends DebugCounterResourceBase { String param4 = (String)getRequestAttributes().get("param4"); if (param1 == null) { - param1 = "all"; - choice = Option.ALL; + output = new DebugCounterInfoOutput(true); + return listCounters(output); } else if (param1.equals("all")) { - choice = Option.ALL; + output = new DebugCounterInfoOutput(false); + populateCounters(debugCounter.getAllCounterValues(), output); + return output; } + output = new DebugCounterInfoOutput(false); String counterHierarchy = ""; - if (param2 != null) { + if (param2 == null) { + // param2 is null -- return list of counternames for param1 + boolean isRegistered = debugCounter.containsModuleName(param1); + output = new DebugCounterInfoOutput(true); + if (isRegistered) { + return listCounters(param1, output); + } else { + choice = Option.ERROR_BAD_MODULE_NAME; + } + } else if (param2.equals("all")) { + // get all counter info for a single module + boolean isRegistered = debugCounter.containsModuleName(param1); + if (isRegistered) { + choice = Option.ONE_MODULE; + } else { + choice = Option.ERROR_BAD_MODULE_NAME; + } + } else { counterHierarchy += param2; if (param3 != null) { counterHierarchy += "/" + param3; @@ -288,22 +323,9 @@ public class DebugCounterResource extends DebugCounterResourceBase { } else { choice = Option.ERROR_BAD_MODULE_COUNTER_NAME; } - } else { - if (!param1.equals("all")) { - // get all counters for a single module - boolean isRegistered = debugCounter.containsModuleName(param1); - if (isRegistered) { - choice = Option.ONE_MODULE; - } else { - choice = Option.ERROR_BAD_MODULE_NAME; - } - } } switch (choice) { - case ALL: - populateCounters(debugCounter.getAllCounterValues(), output); - break; case ONE_MODULE: populateCounters(debugCounter.getModuleCounterValues(param1), output); break; @@ -312,18 +334,30 @@ public class DebugCounterResource extends DebugCounterResourceBase { output); break; case ERROR_BAD_MODULE_NAME: - output.error = "Module name has no corresponding registered counters"; + output.error = "Module name is not registered for debug-counters"; break; case ERROR_BAD_MODULE_COUNTER_NAME: output.error = "Counter not registered"; break; case ERROR_BAD_PARAM: + default: output.error = "Bad param"; } return output; } + private DebugCounterInfoOutput listCounters(String moduleName, + DebugCounterInfoOutput output) { + output.names = debugCounter.getModuleCounterList(moduleName); + return output; + } + + private DebugCounterInfoOutput listCounters(DebugCounterInfoOutput output) { + output.names = debugCounter.getModuleList(); + return output; + } + private void populateSingleCounter(DebugCounterInfo debugCounterInfo, DebugCounterInfoOutput output) { if (debugCounterInfo != null) diff --git a/src/main/java/net/floodlightcontroller/debugcounter/web/DebugCounterRoutable.java b/src/main/java/net/floodlightcontroller/debugcounter/web/DebugCounterRoutable.java index 8b7b2fa6f3bf9b68be3189cb65364dac990c33dc..55ba5bacf95b0257556bd5483a561ca40fa0a8cb 100644 --- a/src/main/java/net/floodlightcontroller/debugcounter/web/DebugCounterRoutable.java +++ b/src/main/java/net/floodlightcontroller/debugcounter/web/DebugCounterRoutable.java @@ -25,6 +25,7 @@ public class DebugCounterRoutable implements RestletRoutable { router.attach("/{param1}/", DebugCounterResource.class); router.attach("/{param1}", DebugCounterResource.class); router.attach("/", DebugCounterResource.class); + router.attach("", DebugCounterResource.class); return router; } } diff --git a/src/main/java/org/sdnplatform/sync/internal/SyncManager.java b/src/main/java/org/sdnplatform/sync/internal/SyncManager.java index 727ccd51992a530a96177246be8b2afa0f6e2931..95bae4316d83cf4963e423a2349c23f5d059c793 100644 --- a/src/main/java/org/sdnplatform/sync/internal/SyncManager.java +++ b/src/main/java/org/sdnplatform/sync/internal/SyncManager.java @@ -515,7 +515,7 @@ public class SyncManager extends AbstractSyncManager { throws FloodlightModuleException { if (context != null) { try { - counterHints = debugCounter.registerCounter(PACKAGE, " hints", + counterHints = debugCounter.registerCounter(PACKAGE, "hints", "Queued sync events processed", CounterType.ALWAYS_COUNT); counterSentValues = debugCounter.registerCounter(PACKAGE, "sent-values",