Bug7485 Make statistics poller parameters configurable.
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / OpenFlowPluginProviderImpl.java
index a1799ac79108b3791d32d5b18b81d4d12f35c911..08ccb34e2399e42eb3d6044dd6dae7cee41ed52d 100644 (file)
@@ -13,7 +13,6 @@ import com.google.common.base.Preconditions;
 import com.google.common.util.concurrent.FutureCallback;
 import com.google.common.util.concurrent.Futures;
 import com.google.common.util.concurrent.ListenableFuture;
-import io.netty.util.HashedWheelTimer;
 import java.lang.management.ManagementFactory;
 import java.util.ArrayList;
 import java.util.Collection;
@@ -59,6 +58,7 @@ import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorM
 import org.opendaylight.openflowplugin.openflow.md.core.session.OFSessionUtil;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import io.netty.util.HashedWheelTimer;
 
 public class OpenFlowPluginProviderImpl implements OpenFlowPluginProvider, OpenFlowPluginExtensionRegistratorProvider {
 
@@ -67,6 +67,9 @@ public class OpenFlowPluginProviderImpl implements OpenFlowPluginProvider, OpenF
     private static final int TICKS_PER_WHEEL = 500;
     // 0.5 sec.
     private static final long TICK_DURATION = 10;
+    private static final Integer DEFAULT_BARRIER_COUNT = 25600;
+    private static final Long DEFAULT_ECHO_TIMEOUT = 2000L;
+    private static final Long DEFAULT_BARRIER_TIMEOUT = 500L;
 
     private final HashedWheelTimer hashedWheelTimer = new HashedWheelTimer(TICK_DURATION, TimeUnit.MILLISECONDS, TICKS_PER_WHEEL);
 
@@ -87,10 +90,12 @@ public class OpenFlowPluginProviderImpl implements OpenFlowPluginProvider, OpenF
     private DataBroker dataBroker;
     private Collection<SwitchConnectionProvider> switchConnectionProviders;
     private boolean switchFeaturesMandatory = false;
-    private boolean isStatisticsPollingOff = false;
+    private boolean isStatisticsPollingOn = true;
     private boolean isStatisticsRpcEnabled;
-    private boolean isNotificationFlowRemovedOff = false;
+    private boolean isFlowRemovedNotificationOn = true;
     private boolean skipTableFeatures = true;
+    private long basicTimerDelay;
+    private long maximumTimerDelay;
 
     private final ThreadPoolExecutor threadPool;
     private ClusterSingletonServiceProvider singletonServicesProvider;
@@ -116,13 +121,13 @@ public class OpenFlowPluginProviderImpl implements OpenFlowPluginProvider, OpenF
     }
 
     @Override
-    public boolean isStatisticsPollingOff() {
-        return isStatisticsPollingOff;
+    public boolean isStatisticsPollingOn() {
+        return isStatisticsPollingOn;
     }
 
     @Override
-    public void setIsStatisticsPollingOff(final boolean isStatisticsPollingOff) {
-        this.isStatisticsPollingOff = isStatisticsPollingOff;
+    public void setStatisticsPollingOn(final boolean isStatisticsPollingOn) {
+        this.isStatisticsPollingOn = isStatisticsPollingOn;
     }
 
     private void startSwitchConnections() {
@@ -169,8 +174,8 @@ public class OpenFlowPluginProviderImpl implements OpenFlowPluginProvider, OpenF
     }
 
     @Override
-    public void setNotificationFlowRemovedOff(boolean isNotificationFlowRemovedOff) {
-        this.isNotificationFlowRemovedOff = isNotificationFlowRemovedOff;
+    public void setFlowRemovedNotification(boolean isFlowRemovedNotificationOn) {
+        this.isFlowRemovedNotificationOn = this.isFlowRemovedNotificationOn;
     }
 
     @Override
@@ -183,6 +188,16 @@ public class OpenFlowPluginProviderImpl implements OpenFlowPluginProvider, OpenF
             this.skipTableFeatures = skipTableFeatures;
     }
 
+    @Override
+    public void setBasicTimerDelay(long basicTimerDelay) {
+        this.basicTimerDelay = basicTimerDelay;
+    }
+
+    @Override
+    public void setMaximumTimerDelay(long maximumTimerDelay) {
+        this.maximumTimerDelay = maximumTimerDelay;
+    }
+
     @Override
     public void setSwitchFeaturesMandatory(final boolean switchFeaturesMandatory) {
         this.switchFeaturesMandatory = switchFeaturesMandatory;
@@ -229,7 +244,7 @@ public class OpenFlowPluginProviderImpl implements OpenFlowPluginProvider, OpenF
                 barrierInterval,
                 barrierCountLimit,
                 getMessageIntelligenceAgency(),
-                isNotificationFlowRemovedOff,
+                isFlowRemovedNotificationOn,
                 singletonServicesProvider,
                 notificationPublishService,
                 hashedWheelTimer,
@@ -239,7 +254,8 @@ public class OpenFlowPluginProviderImpl implements OpenFlowPluginProvider, OpenF
         ((ExtensionConverterProviderKeeper) deviceManager).setExtensionConverterProvider(extensionConverterManager);
 
         rpcManager = new RpcManagerImpl(rpcProviderRegistry, rpcRequestsQuota, extensionConverterManager, convertorManager, notificationPublishService);
-        statisticsManager = new StatisticsManagerImpl(rpcProviderRegistry, isStatisticsPollingOff, hashedWheelTimer, convertorManager);
+        statisticsManager = new StatisticsManagerImpl(rpcProviderRegistry, isStatisticsPollingOn, hashedWheelTimer,
+                convertorManager,basicTimerDelay,maximumTimerDelay);
 
         /* Initialization Phase ordering - OFP Device Context suite */
         // CM -> DM -> SM -> RPC -> Role -> DM
@@ -264,30 +280,56 @@ public class OpenFlowPluginProviderImpl implements OpenFlowPluginProvider, OpenF
     @Override
     public void update(Map<String,Object> props) {
         LOG.debug("Update managed properties = {}", props.toString());
-        if(deviceManager != null && props.containsKey("notification-flow-removed-off")) {
-            deviceManager.setIsNotificationFlowRemovedOff(Boolean.valueOf(props.get("notification-flow-removed-off").toString()));
-        }
-        if(deviceManager != null && props.containsKey("skip-table-features")) {
-            deviceManager.setSkipTableFeatures(Boolean.valueOf(props.get("skip-table-features").toString()));
+
+        if(deviceManager != null) {
+            if (props.containsKey("notification-flow-removed-off")) {
+                deviceManager.setFlowRemovedNotificationOn(Boolean.valueOf(props.get("enable-flow-removed-notification").toString()));
+            }
+            if (props.containsKey("skip-table-features")) {
+                deviceManager.setSkipTableFeatures(Boolean.valueOf(props.get("skip-table-features").toString()));
+            }
+            if (props.containsKey("barrier-count-limit")) {
+                try {
+                    deviceManager.setBarrierCountLimit(Integer.valueOf(props.get("barrier-count-limit").toString()));
+                } catch (NumberFormatException ex) {
+                    deviceManager.setBarrierCountLimit(DEFAULT_BARRIER_COUNT);
+                }
+            }
+            if (props.containsKey("barrier-interval-timeout-limit")){
+                try {
+                    deviceManager.setBarrierInterval(Long.valueOf(props.get("barrier-interval-timeout-limit").toString()));
+                } catch (NumberFormatException ex) {
+                    deviceManager.setBarrierInterval(DEFAULT_BARRIER_TIMEOUT);
+                }
+            }
         }
+
         if(rpcManager != null && props.containsKey("is-statistics-rpc-enabled")){
             rpcManager.setStatisticsRpcEnabled(Boolean.valueOf((props.get("is-statistics-rpc-enabled").toString())));
         }
-        if(deviceManager != null && props.containsKey("barrier-count-limit")){
-            deviceManager.setBarrierCountLimit(Integer.valueOf(props.get("barrier-count-limit").toString()));
+
+        if (connectionManager != null && props.containsKey("echo-reply-timeout") ){
+            try {
+                connectionManager.setEchoReplyTimeout(Long.valueOf(props.get("echo-reply-timeout").toString()));
+            }catch (NumberFormatException ex){
+                connectionManager.setEchoReplyTimeout(DEFAULT_ECHO_TIMEOUT);
+            }
         }
-        if(deviceManager != null && props.containsKey("barrier-interval-timeout-limit")){
-            deviceManager.setBarrierInterval(Long.valueOf(props.get("barrier-interval-timeout-limit").toString()));
+
+        if(statisticsManager != null && props.containsKey("is-statistics-polling-on")){
+            statisticsManager.setIsStatisticsPollingOn(Boolean.valueOf(props.get("is-statistics-polling-on").toString()));
         }
-        if (connectionManager != null && props.containsKey("echo-reply-timeout") ){
-            connectionManager.setEchoReplyTimeout(Long.valueOf(props.get("echo-reply-timeout").toString()));
+
+        if(statisticsManager != null && props.containsKey("basic-timer-delay")){
+            statisticsManager.setBasicTimerDelay(Long.valueOf(props.get("basic-timer-delay").toString()));
         }
 
-        if(statisticsManager != null && props.containsKey("is-statistics-polling-off")){
-            statisticsManager.setIsStatisticsPollingOff(Boolean.valueOf(props.get("is-statistics-polling-off").toString()));
+        if(statisticsManager != null && props.containsKey("maximum-timer-delay")){
+            statisticsManager.setMaximumTimerDelay(Long.valueOf(props.get("maximum-timer-delay").toString()));
         }
     }
 
+
     private static void registerMXBean(final MessageIntelligenceAgency messageIntelligenceAgency) {
         final MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
         try {
@@ -334,4 +376,4 @@ public class OpenFlowPluginProviderImpl implements OpenFlowPluginProvider, OpenF
         // Manually shutdown all remaining running threads in pool
         threadPool.shutdown();
     }
-}
+}
\ No newline at end of file