From f7f6622d4de5ea6c70a24c583d42020301b69cf3 Mon Sep 17 00:00:00 2001 From: Michal Polkorab Date: Thu, 13 Nov 2014 16:20:44 +0100 Subject: [PATCH] JConsole support for statistics collection - sevice identity moved to spi - removed unnecessary methods - toString() renamed to getStat() Change-Id: I84d8c2f333f11c202b3cbb82f55578ea3f7961f9 Signed-off-by: Michal Polkorab --- .../connection/ConnectionConfiguration.java | 4 - .../connection/StatisticsConfiguration.java | 18 ++- .../openflowjava/statistics/Counter.java | 6 +- .../statistics/StatisticsCounters.java | 92 +++++-------- .../rev140328/StatisticsCollectionModule.java | 121 ++++++++++++++++++ .../StatisticsCollectionModuleFactory.java | 13 ++ .../SwitchConnectionProviderModule.java | 64 +-------- ...nflow-switch-connection-provider-impl.yang | 76 ++++++++++- .../impl/core/OFDecoderStatisticsTest.java | 2 +- .../impl/core/OFEncoderStatisticsTest.java | 2 +- .../ConnectionAdapterImplStatisticsTest.java | 2 +- .../ConnectionConfigurationImpl.java | 10 -- .../statistics/StatisticsCountersTest.java | 7 +- openflow-protocol-spi/pom.xml | 2 +- .../spi/statistics/StatisticsHandler.java | 28 ++++ .../openflow-switch-connection-provider.yang | 7 + 16 files changed, 302 insertions(+), 152 deletions(-) create mode 100644 openflow-protocol-impl/src/main/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/openflow/_switch/connection/provider/impl/rev140328/StatisticsCollectionModule.java create mode 100644 openflow-protocol-impl/src/main/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/openflow/_switch/connection/provider/impl/rev140328/StatisticsCollectionModuleFactory.java create mode 100644 openflow-protocol-spi/src/main/java/org/opendaylight/openflowjava/protocol/spi/statistics/StatisticsHandler.java diff --git a/openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/connection/ConnectionConfiguration.java b/openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/connection/ConnectionConfiguration.java index 0ba121cc..243f2d93 100644 --- a/openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/connection/ConnectionConfiguration.java +++ b/openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/connection/ConnectionConfiguration.java @@ -53,8 +53,4 @@ public interface ConnectionConfiguration { * @return thread numbers for TcpHandler's eventloopGroups */ ThreadConfiguration getThreadConfiguration(); - /** - * @return Statistics configuration - */ - StatisticsConfiguration getStatisticsConfiguration(); } \ No newline at end of file diff --git a/openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/connection/StatisticsConfiguration.java b/openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/connection/StatisticsConfiguration.java index 68cfa433..e5b25d40 100644 --- a/openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/connection/StatisticsConfiguration.java +++ b/openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/connection/StatisticsConfiguration.java @@ -5,13 +5,23 @@ * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ + package org.opendaylight.openflowjava.protocol.api.connection; /** + * Used for StatisticsCounter configuration + * * @author madamjak - * */ public interface StatisticsConfiguration { - Boolean getStatisticsCollect(); - Integer getLogReportDelay(); -} + + /** + * @return true if statistics are / will be collected, false otherwise + */ + boolean getStatisticsCollect(); + + /** + * @return delay between two statistics logs (in milliseconds) + */ + int getLogReportDelay(); +} \ No newline at end of file diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/statistics/Counter.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/statistics/Counter.java index 9d7ddc77..c5f18729 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/statistics/Counter.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/statistics/Counter.java @@ -73,8 +73,10 @@ public class Counter { counterLastReadValue.set(0l); } - @Override - public String toString() { + /** + * @return last and current count for specified statistic + */ + public String getStat() { long cntPrevVal = getCounterLastReadValue(); long cntCurValue = getCounterValue(); return String.format("+%d | %d",cntCurValue-cntPrevVal,cntCurValue); diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/statistics/StatisticsCounters.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/statistics/StatisticsCounters.java index 34f072b0..951969ab 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/statistics/StatisticsCounters.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/statistics/StatisticsCounters.java @@ -12,6 +12,7 @@ import java.util.Timer; import java.util.TimerTask; import java.util.concurrent.ConcurrentHashMap; +import org.opendaylight.openflowjava.protocol.spi.statistics.StatisticsHandler; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -20,7 +21,7 @@ import org.slf4j.LoggerFactory; * @author madamjak * */ -public final class StatisticsCounters { +public final class StatisticsCounters implements StatisticsHandler { /** * Default delay between two writings into log (milliseconds) @@ -67,43 +68,28 @@ public final class StatisticsCounters { countersMap.put(cet, new Counter()); } runCounting = false; - this.logReportPeriod = -1; + this.logReportPeriod = 0; this.runLogReport = false; LOGGER.debug("StaticsCounters has been created"); } /** - * Start counting - * @param resetCounters - true = statistics counters will be reset before start counting - * @param reportToLogs - true = statistics counters will periodically write to log - * @param logReportDelay - delay between two writings into logs in milliseconds (for details see startLogReport(int logReportDelay)) + * Start counting (counters are set to 0 before counting starts) + * @param reportToLogs - true = statistic counters will periodically log + * @param logReportDelay - delay between two logs (in milliseconds) */ - public void startCounting(boolean resetCounters, boolean reportToLogs, int logReportDelay){ + public void startCounting(boolean reportToLogs, int logReportDelay){ if (runCounting) { return; } - LOGGER.debug("Start counting..."); + resetCounters(); + LOGGER.debug("Counting started..."); if(reportToLogs){ startLogReport(logReportDelay); } - if(resetCounters){ - resetCounters(); - } runCounting = true; } - /** - * Start counting (counters are set to 0 before start counting) - * @param reportToLogs - true = statistics counters will periodically write to log - * @param logReportDelay - delay between two writings into logs in milliseconds (for details see startLogReport(int logReportDelay)) - */ - public void startCounting(boolean reportToLogs, int logReportDelay){ - if (runCounting) { - return; - } - startCounting(true,reportToLogs,logReportDelay); - } - /** * Stop counting, values in counters are untouched, log reporter is stopped */ @@ -122,49 +108,30 @@ public final class StatisticsCounters { } /** - * Start write statistics into logs, if writing is run calling has no effect. - * If method is called without previous setting of report delay than DEFAULT_LOG_REPORT_PERIOD will be used. - */ - public void startLogReport(){ - if(runLogReport){ - return; - } - if(this.logReportPeriod <= 0){ - this.logReportPeriod = DEFAULT_LOG_REPORT_PERIOD; - } - if(this.logReportPeriod <= MINIMAL_LOG_REPORT_PERIOD){ - this.logReportPeriod = MINIMAL_LOG_REPORT_PERIOD; - } - logReporter = new Timer("SC_Timer"); - logReporter.schedule(new LogReporterTask(this), this.logReportPeriod,this.logReportPeriod); - runLogReport = true; - LOGGER.debug("Statistics log reporter has been scheduled with period {} ms", this.logReportPeriod); - } - - /** - * Start write statistics into logs with given delay between writings, if writing is run calling has no effect. - * @param logReportDelay - delay between two writings into logs (milliseconds). - * It is mandatory if reportToLogs is true, value have to be greater than 0 (zero) - * If value is smaller than MINIMAL_LOG_REPORT_PERIOD, the value MINIMAL_LOG_REPORT_PERIOD will be used. - * @exception IllegalArgumentException if logReportDelay is not greater than 0 (zero) + * Prints statistics with given delay between logs + * @param logReportDelay - delay between two logs (in milliseconds) + * @exception IllegalArgumentException if logReportDelay is less than 0 */ public void startLogReport(int logReportDelay){ if(runLogReport){ return; } if(logReportDelay <= 0){ - throw new IllegalArgumentException("logReportPeriod have to bee greater than 0 zero"); + throw new IllegalArgumentException("logReportDelay has to be greater than 0"); } if(logReportDelay < MINIMAL_LOG_REPORT_PERIOD){ this.logReportPeriod = MINIMAL_LOG_REPORT_PERIOD; } else { this.logReportPeriod = logReportDelay; } - startLogReport(); + logReporter = new Timer("SC_Timer"); + logReporter.schedule(new LogReporterTask(this), this.logReportPeriod, this.logReportPeriod); + runLogReport = true; + LOGGER.debug("Statistics log reporter has been scheduled with period {} ms", this.logReportPeriod); } /** - * Stop write statistics into logs, counting does not stop + * Stops logging, counting continues */ public void stopLogReport(){ if(runLogReport){ @@ -217,7 +184,7 @@ public final class StatisticsCounters { } /** - * Get counter by counter event type + * Get counter by CounterEventType * @param counterEventKey key to identify counter (can not be null) * @return - Counter object or null if counter has not been enabled * @exception - IllegalArgumentException if counterEventKey is null @@ -241,9 +208,7 @@ public final class StatisticsCounters { } } - /** - * Set values of all counter to 0 (zero) - */ + @Override public void resetCounters() { for(CounterEventTypes cet : enabledCounters){ countersMap.get(cet).reset(); @@ -251,6 +216,15 @@ public final class StatisticsCounters { LOGGER.debug("StaticsCounters has been reset"); } + @Override + public String printStatistics() { + StringBuilder strBuilder = new StringBuilder(); + for(CounterEventTypes cet : getEnabledCounters()){ + strBuilder.append(cet.name() + ": " + getCountersMap().get(cet).getStat() + "\n"); + } + return strBuilder.toString(); + } + /** * internal class to process logReporter * @author madamjak @@ -266,9 +240,9 @@ public final class StatisticsCounters { @Override public void run() { - for(CounterEventTypes cet : sc.getEnabledCounters()){ - LOG.debug(cet.toString() + ": " + sc.getCountersMap().get(cet).toString()); - } + for(CounterEventTypes cet : sc.getEnabledCounters()){ + LOG.debug(cet.name() + ": " + sc.getCountersMap().get(cet).getStat()); + } } } -} +} \ No newline at end of file diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/openflow/_switch/connection/provider/impl/rev140328/StatisticsCollectionModule.java b/openflow-protocol-impl/src/main/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/openflow/_switch/connection/provider/impl/rev140328/StatisticsCollectionModule.java new file mode 100644 index 00000000..ff686c16 --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/openflow/_switch/connection/provider/impl/rev140328/StatisticsCollectionModule.java @@ -0,0 +1,121 @@ +package org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflow._switch.connection.provider.impl.rev140328; + +import org.opendaylight.openflowjava.protocol.api.connection.StatisticsConfiguration; +import org.opendaylight.openflowjava.protocol.spi.statistics.StatisticsHandler; +import org.opendaylight.openflowjava.statistics.StatisticsCounters; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** +* This is the definition of statistics collection module identity. +*/ +public class StatisticsCollectionModule extends org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflow._switch.connection.provider.impl.rev140328.AbstractStatisticsCollectionModule { + + private static final Logger LOGGER = LoggerFactory.getLogger(StatisticsCollectionModule.class); + + public StatisticsCollectionModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) { + super(identifier, dependencyResolver); + } + + public StatisticsCollectionModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver, org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflow._switch.connection.provider.impl.rev140328.StatisticsCollectionModule oldModule, java.lang.AutoCloseable oldInstance) { + super(identifier, dependencyResolver, oldModule, oldInstance); + } + + @Override + public void customValidation() { + // add custom validation form module attributes here. + } + + @Override + public java.lang.AutoCloseable createInstance() { + final Statistics statistics = getStatistics(); + final StatisticsCounters statsCounter = StatisticsCounters.getInstance(); + StatisticsConfiguration statsConfig = null; + if (statistics != null) { + statsConfig = new StatisticsConfiguration() { + + @Override + public boolean getStatisticsCollect() { + if (statistics.getStatisticsCollect() != null) { + return statistics.getStatisticsCollect().booleanValue(); + } + return false; + } + + @Override + public int getLogReportDelay() { + if (statistics.getLogReportDelay() != null) { + return statistics.getLogReportDelay().intValue(); + } + return 0; + } + }; + } else { + LOGGER.error("STATISTICS ARE NULL"); + } + LOGGER.error("config " + statsConfig); + if (statsConfig != null) { + statsCounter.startCounting(statsConfig.getStatisticsCollect(), statsConfig.getLogReportDelay()); + } else { + LOGGER.debug("Unable to start StatisticCounter - wrong configuration"); + } + + /* Internal MXBean implementation */ + final StatisticsCollectionRuntimeMXBean collectionBean = new StatisticsCollectionRuntimeMXBean() { + + @Override + public String printOfjavaStatistics() { + if (statsCounter != null) { + return statsCounter.printStatistics(); + } + return "Statistics collection is not avaliable."; + } + @Override + public String getMsgStatistics() { + return printOfjavaStatistics(); + } + @Override + public String resetOfjavaStatistics() { + statsCounter.resetCounters(); + return "Statistics have been reset"; + } + }; + + /* MXBean registration */ + final StatisticsCollectionRuntimeRegistration runtimeReg = + getRootRuntimeBeanRegistratorWrapper().register(collectionBean); + + /* Internal StatisticsCollectionService implementation */ + final class AutoClosableStatisticsCollection implements StatisticsHandler, AutoCloseable { + + @Override + public void close() { + if (runtimeReg != null) { + try { + runtimeReg.close(); + } + catch (Exception e) { + String errMsg = "Error by stoping StatisticsCollectionService."; + LOGGER.error(errMsg, e); + throw new IllegalStateException(errMsg, e); + } + } + LOGGER.info("StatisticsCollection Service consumer (instance {} turn down.)", this); + } + + @Override + public void resetCounters() { + statsCounter.resetCounters(); + } + + @Override + public String printStatistics() { + return statsCounter.printStatistics(); + } + } + + AutoCloseable ret = new AutoClosableStatisticsCollection(); + LOGGER.info("StatisticsCollection service (instance {}) initialized.", ret); + return ret; + } +} \ No newline at end of file diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/openflow/_switch/connection/provider/impl/rev140328/StatisticsCollectionModuleFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/openflow/_switch/connection/provider/impl/rev140328/StatisticsCollectionModuleFactory.java new file mode 100644 index 00000000..04db2fa8 --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/openflow/_switch/connection/provider/impl/rev140328/StatisticsCollectionModuleFactory.java @@ -0,0 +1,13 @@ +/* +* Generated file +* +* Generated from: yang module name: openflow-switch-connection-provider-impl yang module local name: statistics-collection-service-impl +* Generated by: org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator +* Generated at: Thu Nov 13 12:52:26 CET 2014 +* +* Do not modify this file unless it is present under src/main directory +*/ +package org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflow._switch.connection.provider.impl.rev140328; +public class StatisticsCollectionModuleFactory extends org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflow._switch.connection.provider.impl.rev140328.AbstractStatisticsCollectionModuleFactory { + +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/openflow/_switch/connection/provider/impl/rev140328/SwitchConnectionProviderModule.java b/openflow-protocol-impl/src/main/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/openflow/_switch/connection/provider/impl/rev140328/SwitchConnectionProviderModule.java index d6494108..fd5cf8aa 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/openflow/_switch/connection/provider/impl/rev140328/SwitchConnectionProviderModule.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/openflow/_switch/connection/provider/impl/rev140328/SwitchConnectionProviderModule.java @@ -13,11 +13,9 @@ import java.net.InetAddress; import java.net.UnknownHostException; import org.opendaylight.openflowjava.protocol.api.connection.ConnectionConfiguration; -import org.opendaylight.openflowjava.protocol.api.connection.StatisticsConfiguration; import org.opendaylight.openflowjava.protocol.api.connection.ThreadConfiguration; import org.opendaylight.openflowjava.protocol.api.connection.TlsConfiguration; import org.opendaylight.openflowjava.protocol.impl.core.SwitchConnectionProviderImpl; -import org.opendaylight.openflowjava.statistics.StatisticsCounters; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.config.rev140630.KeystoreType; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.config.rev140630.TransportProtocol; @@ -63,18 +61,15 @@ public final class SwitchConnectionProviderModule extends org.opendaylight.yang. public java.lang.AutoCloseable createInstance() { LOG.info("SwitchConnectionProvider started."); SwitchConnectionProviderImpl switchConnectionProviderImpl = new SwitchConnectionProviderImpl(); - StatisticsCounters sc = StatisticsCounters.getInstance(); try { ConnectionConfiguration connConfiguration = createConnectionConfiguration(); switchConnectionProviderImpl.setConfiguration(connConfiguration); - startStatistics(sc, connConfiguration.getStatisticsConfiguration()); } catch (UnknownHostException e) { throw new IllegalArgumentException(e.getMessage(), e); } return switchConnectionProviderImpl; } - /** * @return instance configuration object * @throws UnknownHostException @@ -86,8 +81,7 @@ public final class SwitchConnectionProviderModule extends org.opendaylight.yang. final Tls tlsConfig = getTls(); final Threads threads = getThreads(); final TransportProtocol transportProtocol = getTransportProtocol(); - final Statistics statistics = getStatistics(); - + return new ConnectionConfiguration() { @Override public InetAddress getAddress() { @@ -172,31 +166,6 @@ public final class SwitchConnectionProviderModule extends org.opendaylight.yang. } }; } - @Override - public StatisticsConfiguration getStatisticsConfiguration(){ - return new StatisticsConfiguration() { - @Override - public Boolean getStatisticsCollect() { - if(statistics == null){ - return false; - } - if (statistics.getStatisticsCollect() == null){ - return false; - } - return statistics.getStatisticsCollect(); - } - @Override - public Integer getLogReportDelay() { - if(statistics == null){ - return -1; - } - if(statistics.getLogReportDelay() == null){ - return -1; - }; - return statistics.getLogReportDelay(); - } - }; - } }; } @@ -222,37 +191,6 @@ public final class SwitchConnectionProviderModule extends org.opendaylight.yang. } } - /** - * Configure and start Statistics Counters by configuration parameters. - * No operations is performed if: - * - statisticsConfig is null - * - sc is null - * - sc is not null and if counting is running - * @param sc - statistic counter to configure and start - * @param statisticsConfig - configuration parameters - */ - private static void startStatistics(StatisticsCounters sc, StatisticsConfiguration statisticsConfig){ - if(statisticsConfig == null){ - return; - } - if(sc == null || sc.isRunCounting()){ - return; - } - Boolean toCollectStats = statisticsConfig.getStatisticsCollect(); - Integer logDelay = statisticsConfig.getLogReportDelay(); - if(toCollectStats != null && toCollectStats.booleanValue()){ - int logPeriod = -1; - if(logDelay != null){ - logPeriod = logDelay.intValue(); - } - if(logPeriod >0){ - sc.startCounting(true, logPeriod); - } else { - sc.startCounting(false, 0); - } - } - } - /** * @param value * @return diff --git a/openflow-protocol-impl/src/main/yang/openflow-switch-connection-provider-impl.yang b/openflow-protocol-impl/src/main/yang/openflow-switch-connection-provider-impl.yang index 4ca31886..cb714d6b 100644 --- a/openflow-protocol-impl/src/main/yang/openflow-switch-connection-provider-impl.yang +++ b/openflow-protocol-impl/src/main/yang/openflow-switch-connection-provider-impl.yang @@ -7,6 +7,7 @@ module openflow-switch-connection-provider-impl { import openflow-switch-connection-provider {prefix openflow-switch-connection-provider; revision-date 2014-03-28; } import ietf-inet-types {prefix ietf-inet; revision-date 2010-09-24; } import openflow-configuration {prefix of-config; revision-date 2014-06-30; } + import rpc-context { prefix rpcx; revision-date 2013-06-17; } description "openflow-switch-connection-provider"; @@ -22,6 +23,13 @@ module openflow-switch-connection-provider-impl { config:java-name-prefix SwitchConnectionProvider; } + identity statistics-collection-service-impl { + description + "This is the definition of statistics collection module identity."; + base config:module-type; + config:provided-service openflow-switch-connection-provider:statistics-collection-service; + config:java-name-prefix StatisticsCollection; + } augment "/config:modules/config:module/config:configuration" { case openflow-switch-connection-provider-impl { @@ -92,9 +100,14 @@ module openflow-switch-connection-provider-impl { type uint16; } } + } + + case statistics-collection-service-impl { + when "/config:modules/config:module/config:type = 'statistics-collection-service-impl'"; + container statistics { leaf statistics-collect { - description "Toggle of collecting statistics"; + description "Toggle statistics collecting"; type boolean; } leaf log-report-delay { @@ -102,6 +115,67 @@ module openflow-switch-connection-provider-impl { type uint16; } } + list openflow-switch-connection-provider { + uses config:service-ref { + refine type { + mandatory true; + config:required-identity openflow-switch-connection-provider:openflow-switch-connection-provider; + } + } + } + } + } + + augment "/config:modules/config:module/config:state" { + case statistics-collection-service-impl { + when "/config:modules/config:module/config:type = 'statistics-collection-service-impl'"; + + description + "MXBean designed for Message Statistic providing to JConsole."; + + leaf msgStatistics { + type string; + } + + rpcx:rpc-context-instance "print-ofjava-statistics-rpc"; + rpcx:rpc-context-instance "reset-ofjava-statistics-rpc"; + } + } + + identity print-ofjava-statistics-rpc; + identity reset-ofjava-statistics-rpc; + + rpc print-ofjava-statistics { + description + "Shortcut JMX call to printOfjavaStatistics."; + input { + uses rpcx:rpc-context-ref { + refine context-instance { + rpcx:rpc-context-instance print-ofjava-statistics-rpc; + } + } + } + output { + leaf result { + type string; + } + } + } + + rpc reset-ofjava-statistics { + description + "Shortcut JMX call to resetOfjavaStatistics."; + input { + uses rpcx:rpc-context-ref { + refine context-instance { + rpcx:rpc-context-instance reset-ofjava-statistics-rpc; + } + } + } + output { + leaf result { + type string; + } } } } \ No newline at end of file diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/core/OFDecoderStatisticsTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/core/OFDecoderStatisticsTest.java index 4dd3f53b..2b30d846 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/core/OFDecoderStatisticsTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/core/OFDecoderStatisticsTest.java @@ -58,7 +58,7 @@ public class OFDecoderStatisticsTest { ofDecoder.setDeserializationFactory(mockDeserializationFactory); outList = new ArrayList<>(); statCounters = StatisticsCounters.getInstance(); - statCounters.startCounting(true, false, 0); + statCounters.startCounting(false, 0); } /** diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/core/OFEncoderStatisticsTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/core/OFEncoderStatisticsTest.java index 46aa2f45..cfafe994 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/core/OFEncoderStatisticsTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/core/OFEncoderStatisticsTest.java @@ -59,7 +59,7 @@ public class OFEncoderStatisticsTest { ofEncoder = new OFEncoder() ; ofEncoder.setSerializationFactory(mockSerializationFactory) ; statCounters = StatisticsCounters.getInstance(); - statCounters.startCounting(true,false, 0); + statCounters.startCounting(false, 0); } /** diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/core/connection/ConnectionAdapterImplStatisticsTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/core/connection/ConnectionAdapterImplStatisticsTest.java index 8429afde..a770e853 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/core/connection/ConnectionAdapterImplStatisticsTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/core/connection/ConnectionAdapterImplStatisticsTest.java @@ -117,7 +117,7 @@ public class ConnectionAdapterImplStatisticsTest { public void setUp() { MockitoAnnotations.initMocks(this); statCounters = StatisticsCounters.getInstance(); - statCounters.startCounting(true,false, 0); + statCounters.startCounting(false, 0); } /** diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/core/connection/ConnectionConfigurationImpl.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/core/connection/ConnectionConfigurationImpl.java index ec947e9a..6f199328 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/core/connection/ConnectionConfigurationImpl.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/core/connection/ConnectionConfigurationImpl.java @@ -11,11 +11,9 @@ package org.opendaylight.openflowjava.protocol.impl.core.connection; import java.net.InetAddress; import org.opendaylight.openflowjava.protocol.api.connection.ConnectionConfiguration; -import org.opendaylight.openflowjava.protocol.api.connection.StatisticsConfiguration; import org.opendaylight.openflowjava.protocol.api.connection.ThreadConfiguration; import org.opendaylight.openflowjava.protocol.api.connection.TlsConfiguration; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.config.rev140630.TransportProtocol; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflow._switch.connection.provider.impl.rev140328.modules.module.configuration.openflow._switch.connection.provider.impl.Statistics; /** * @author michal.polkorab @@ -29,8 +27,6 @@ public class ConnectionConfigurationImpl implements ConnectionConfiguration { private TlsConfiguration tlsConfig; private long switchIdleTimeout; private ThreadConfiguration threadConfig; - private TransportProtocol protocol; - private Statistics statistics; /** * Creates {@link ConnectionConfigurationImpl} @@ -96,10 +92,4 @@ public class ConnectionConfigurationImpl implements ConnectionConfiguration { public void setThreadConfiguration(ThreadConfiguration threadConfig) { this.threadConfig = threadConfig; } - - @Override - public StatisticsConfiguration getStatisticsConfiguration() { - // TODO Auto-generated method stub - return null; - } } \ No newline at end of file diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/statistics/StatisticsCountersTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/statistics/StatisticsCountersTest.java index 1bb549b6..d586a24d 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/statistics/StatisticsCountersTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/statistics/StatisticsCountersTest.java @@ -30,7 +30,7 @@ public class StatisticsCountersTest { @Before public void initTest(){ statCounters = StatisticsCounters.getInstance(); - statCounters.startCounting(true,false, 0); + statCounters.startCounting(false, 0); } /** @@ -101,9 +101,6 @@ public class StatisticsCountersTest { statCounters.startLogReport(testDelay); Assert.assertTrue("Wrong - logRepoter is not running", statCounters.isRunLogReport()); Assert.assertEquals("Wrong - bad logReportPeriod", testDelay, statCounters.getLogReportPeriod()); - statCounters.startLogReport(); - Assert.assertTrue("Wrong - logRepoter is not running", statCounters.isRunLogReport()); - Assert.assertEquals("Wrong - bad logReportPeriod", testDelay, statCounters.getLogReportPeriod()); statCounters.stopLogReport(); Assert.assertFalse("Wrong - logRepoter is running", statCounters.isRunLogReport()); statCounters.startLogReport(statCounters.MINIMAL_LOG_REPORT_PERIOD / 2); @@ -118,7 +115,7 @@ public class StatisticsCountersTest { */ @Test(expected = IllegalArgumentException.class) public void testLogReportBadPeriod(){ - statCounters.startLogReport(-1); + statCounters.startLogReport(0); } /** diff --git a/openflow-protocol-spi/pom.xml b/openflow-protocol-spi/pom.xml index f6ea1ffd..6cef4f39 100644 --- a/openflow-protocol-spi/pom.xml +++ b/openflow-protocol-spi/pom.xml @@ -23,7 +23,7 @@ - org.opendaylight.openflowjava.protocol.spi.connection*, + org.opendaylight.openflowjava.protocol.spi*, org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflow._switch.connection.provider.* diff --git a/openflow-protocol-spi/src/main/java/org/opendaylight/openflowjava/protocol/spi/statistics/StatisticsHandler.java b/openflow-protocol-spi/src/main/java/org/opendaylight/openflowjava/protocol/spi/statistics/StatisticsHandler.java new file mode 100644 index 00000000..c5d7a6aa --- /dev/null +++ b/openflow-protocol-spi/src/main/java/org/opendaylight/openflowjava/protocol/spi/statistics/StatisticsHandler.java @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2014 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowjava.protocol.spi.statistics; + +/** + * Used for JConsole service + * + * @author michal.polkorab + */ +public interface StatisticsHandler { + + /** + * Resets all counters + */ + public void resetCounters(); + + /** + * Prints statistics + * @return statistics + */ + public String printStatistics(); +} \ No newline at end of file diff --git a/openflow-protocol-spi/src/main/yang/openflow-switch-connection-provider.yang b/openflow-protocol-spi/src/main/yang/openflow-switch-connection-provider.yang index 88d2427f..3ed7c20b 100644 --- a/openflow-protocol-spi/src/main/yang/openflow-switch-connection-provider.yang +++ b/openflow-protocol-spi/src/main/yang/openflow-switch-connection-provider.yang @@ -17,4 +17,11 @@ module openflow-switch-connection-provider { base "config:service-type"; config:java-class "org.opendaylight.openflowjava.protocol.spi.connection.SwitchConnectionProvider"; } + + identity statistics-collection-service { + description + "StatisticsHandlerService interface as a StatisticsCollection interface identity"; + base config:service-type; + config:java-class "org.opendaylight.openflowjava.protocol.spi.statistics.StatisticsHandler"; + } } \ No newline at end of file -- 2.36.6