Merge "Bug:3026 - Echo response timeout needs be exported to configuration"
authorKamal Rameshan <kramesha@cisco.com>
Wed, 9 Mar 2016 17:33:00 +0000 (17:33 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Wed, 9 Mar 2016 17:33:00 +0000 (17:33 +0000)
openflowplugin-api/src/main/java/org/opendaylight/openflowplugin/api/openflow/OpenFlowPluginProvider.java
openflowplugin-controller-config/src/main/resources/initial/42-openflowplugin-new.xml
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/OpenFlowPluginProviderImpl.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/connection/ConnectionManagerImpl.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/connection/listener/SystemNotificationsListenerImpl.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/device/DeviceManagerImpl.java
openflowplugin-impl/src/main/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/config/openflow/plugin/impl/rev150327/OpenFlowProviderModule.java
openflowplugin-impl/src/main/yang/openflow-plugin-impl.yang
openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/connection/ConnectionManagerImplTest.java
openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/connection/listener/SystemNotificationsListenerImplTest.java
openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/device/DeviceManagerImplTest.java

index 82a69c5847a1a45a147a78ef86b93834f10ec928..6173fb536f8e5285c827099106cb3d5dc1b9e4a9 100644 (file)
@@ -67,4 +67,10 @@ public interface OpenFlowPluginProvider extends AutoCloseable, BindingService {
      * @param isStatisticsRpcEnabled
      */
     void setIsStatisticsRpcEnabled(boolean isStatisticsRpcEnabled);
+
+    void setBarrierCountLimit(int barrierCountLimit);
+
+    void setBarrierInterval(long barrierTimeoutLimit);
+
+    void setEchoReplyTimeout(long echoReplyTimeout);
 }
index d81a392ded5a8d5161340acb63b3b4ec6636092c..7a282c09dc0b9c53b21cdc95064bb181b91f8f20 100644 (file)
@@ -90,6 +90,9 @@ and is available at http://www.eclipse.org/legal/epl-v10.html
                     <switch-features-mandatory>false</switch-features-mandatory>
                     <global-notification-quota>64000</global-notification-quota>
                     <is-statistics-polling-off>false</is-statistics-polling-off>
+                    <barrier-interval-timeout-limit>500</barrier-interval-timeout-limit>
+                    <barrier-count-limit>25600</barrier-count-limit>
+                    <echo-reply-timeout>2000</echo-reply-timeout>
                 </module>
             </modules>
 
index a7c74d618c5981d8fffe2e977cc9e8d2c675b81c..7f2a3b700fce6c2122dd0c61d0f374b1b9e4fab1 100644 (file)
@@ -63,6 +63,9 @@ public class OpenFlowPluginProviderImpl implements OpenFlowPluginProvider, OpenF
 
     private final int rpcRequestsQuota;
     private final long globalNotificationQuota;
+    private long barrierInterval;
+    private int barrierCountLimit;
+    private long echoReplyTimeout;
     private DeviceManager deviceManager;
     private RoleManager roleManager;
     private RpcManager rpcManager;
@@ -130,6 +133,22 @@ public class OpenFlowPluginProviderImpl implements OpenFlowPluginProvider, OpenF
         this.entityOwnershipService = entityOwnershipService;
     }
 
+    @Override
+    public void setBarrierCountLimit(int barrierCountLimit) {
+        this.barrierCountLimit = barrierCountLimit;
+    }
+
+    @Override
+    public void setBarrierInterval(long barrierTimeoutLimit) {
+        this.barrierInterval = barrierTimeoutLimit;
+    }
+
+    @Override
+    public void setEchoReplyTimeout(long echoReplyTimeout) {
+        this.echoReplyTimeout = echoReplyTimeout;
+    }
+
+
     @Override
     public void setSwitchFeaturesMandatory(final boolean switchFeaturesMandatory) {
         this.switchFeaturesMandatory = switchFeaturesMandatory;
@@ -166,11 +185,12 @@ public class OpenFlowPluginProviderImpl implements OpenFlowPluginProvider, OpenF
         // TODO: rewrite later!
         OFSessionUtil.getSessionManager().setExtensionConverterProvider(extensionConverterManager);
 
-        connectionManager = new ConnectionManagerImpl();
+        connectionManager = new ConnectionManagerImpl(echoReplyTimeout);
 
         registerMXBean(messageIntelligenceAgency);
 
-        deviceManager = new DeviceManagerImpl(dataBroker, messageIntelligenceAgency, globalNotificationQuota, switchFeaturesMandatory);
+        deviceManager = new DeviceManagerImpl(dataBroker, messageIntelligenceAgency, globalNotificationQuota,
+                switchFeaturesMandatory, barrierInterval, barrierCountLimit);
         ((ExtensionConverterProviderKeeper) deviceManager).setExtensionConverterProvider(extensionConverterManager);
         roleManager = new RoleManagerImpl(entityOwnershipService, dataBroker, switchFeaturesMandatory);
         statisticsManager = new StatisticsManagerImpl(rpcProviderRegistry, isStatisticsPollingOff);
index 9901b7162cbcb2fa6eabad5f6d44dbcc3873fc87..544e7124ba44bb6627efc050820b2803a5715545 100644 (file)
@@ -41,6 +41,12 @@ public class ConnectionManagerImpl implements ConnectionManager {
     private static final int HELLO_LIMIT = 20;
     private final boolean bitmapNegotiationEnabled = true;
     private DeviceConnectedHandler deviceConnectedHandler;
+    private final long echoReplyTimeout;
+
+    public ConnectionManagerImpl(long echoReplyTimeout) {
+        this.echoReplyTimeout = echoReplyTimeout;
+    }
+
 
     @Override
     public void onSwitchConnected(final ConnectionAdapter connectionAdapter) {
@@ -71,7 +77,7 @@ public class ConnectionManagerImpl implements ConnectionManager {
                 new OpenflowProtocolListenerInitialImpl(connectionContext, handshakeContext);
         connectionAdapter.setMessageListener(ofMessageListener);
 
-        final SystemNotificationsListener systemListener = new SystemNotificationsListenerImpl(connectionContext);
+        final SystemNotificationsListener systemListener = new SystemNotificationsListenerImpl(connectionContext, echoReplyTimeout);
         connectionAdapter.setSystemListener(systemListener);
 
         LOG.trace("connection ballet finished");
index de1619895ef44294731546f57ef42ce6d2aca66b..ebb03b889fbad2b1879a7d527d5117adbfcedfcc 100644 (file)
@@ -35,9 +35,11 @@ public class SystemNotificationsListenerImpl implements SystemNotificationsListe
     private static final Logger LOG = LoggerFactory.getLogger(SystemNotificationsListenerImpl.class);
     @VisibleForTesting
     static final long MAX_ECHO_REPLY_TIMEOUT = 2000;
+    private final long echoReplyTimeout;
 
-    public SystemNotificationsListenerImpl(@Nonnull final ConnectionContext connectionContext) {
+    public SystemNotificationsListenerImpl(@Nonnull final ConnectionContext connectionContext, long echoReplyTimeout) {
         this.connectionContext = Preconditions.checkNotNull(connectionContext);
+        this.echoReplyTimeout = echoReplyTimeout;
     }
 
     @Override
@@ -56,36 +58,42 @@ public class SystemNotificationsListenerImpl implements SystemNotificationsListe
 
                 if (ConnectionContext.CONNECTION_STATE.WORKING.equals(connectionContext.getConnectionState())) {
                     FeaturesReply features = connectionContext.getFeatures();
-                    LOG.debug(
-                            "first idle state occured, node={}|auxId={}",
-                            remoteAddress, features.getAuxiliaryId());
+                    LOG.debug("Switch Idle state occured, node={}|auxId={}", remoteAddress, features.getAuxiliaryId());
                     connectionContext.changeStateToTimeouting();
                     EchoInputBuilder builder = new EchoInputBuilder();
                     builder.setVersion(features.getVersion());
                     Xid xid = new Xid(0L);
                     builder.setXid(xid.getValue());
 
-                    Future<RpcResult<EchoOutput>> echoReplyFuture = connectionContext.getConnectionAdapter()
-                            .echo(builder.build());
+                    Future<RpcResult<EchoOutput>> echoReplyFuture = connectionContext.getConnectionAdapter().echo(builder.build());
 
                     try {
-                        RpcResult<EchoOutput> echoReplyValue = echoReplyFuture.get(MAX_ECHO_REPLY_TIMEOUT, TimeUnit.MILLISECONDS);
+                        RpcResult<EchoOutput> echoReplyValue = echoReplyFuture.get(echoReplyTimeout, TimeUnit.MILLISECONDS);
                         if (echoReplyValue.isSuccessful()) {
                             connectionContext.changeStateToWorking();
                             shouldBeDisconnected = false;
                         } else {
-                            for (RpcError replyError : echoReplyValue
-                                    .getErrors()) {
+                            for (RpcError replyError : echoReplyValue.getErrors()) {
                                 Throwable cause = replyError.getCause();
-                                LOG.warn("while receiving echoReply [{}] in TIMEOUTING state {} ",
-                                        remoteAddress,
-                                        cause.getMessage());
-                                LOG.trace("while receiving echoReply [{}] in TIMEOUTING state ..", remoteAddress, cause);
+                                if (LOG.isWarnEnabled()) {
+                                    LOG.warn("Received EchoReply from [{}] in TIMEOUTING state, Error:{}", remoteAddress, cause.getMessage());
+                                }
+
+                                if (LOG.isTraceEnabled()) {
+                                    LOG.trace("Received EchoReply from [{}] in TIMEOUTING state, Error:{}", remoteAddress, cause);
+                                }
+
                             }
                         }
                     } catch (Exception e) {
-                        LOG.warn("while waiting for echoReply in TIMEOUTING state: {}", e.getMessage());
-                        LOG.trace("while waiting for echoReply in TIMEOUTING state ..", remoteAddress, e);
+                        if (LOG.isWarnEnabled()) {
+                            LOG.warn("Exception while  waiting for echoReply from [{}] in TIMEOUTING state: {}", remoteAddress, e.getMessage());
+                        }
+
+                        if (LOG.isTraceEnabled()) {
+                            LOG.trace("Exception while  waiting for echoReply from [{}] in TIMEOUTING state: {}", remoteAddress, e);
+                        }
+
                     }
                 }
                 if (shouldBeDisconnected) {
index 903137d55d2c3af7385609426f605163a15f050c..5742453758ac93079dda72473db0d0f62dc10323 100644 (file)
@@ -58,6 +58,7 @@ public class DeviceManagerImpl implements DeviceManager, ExtensionConverterProvi
     private static final long TICK_DURATION = 10; // 0.5 sec.
     private final long globalNotificationQuota;
     private final boolean switchFeaturesMandatory;
+
     private ScheduledThreadPoolExecutor spyPool;
     private final int spyRate = 10;
 
@@ -71,13 +72,14 @@ public class DeviceManagerImpl implements DeviceManager, ExtensionConverterProvi
     private final ConcurrentMap<NodeId, DeviceContext> deviceContexts = new ConcurrentHashMap<>();
     private final MessageIntelligenceAgency messageIntelligenceAgency;
 
-    private final long barrierNanos = TimeUnit.MILLISECONDS.toNanos(500);
-    private final int maxQueueDepth = 25600;
+    private final long barrierIntervalNanos;
+    private final int barrierCountLimit;
     private ExtensionConverterProvider extensionConverterProvider;
 
     public DeviceManagerImpl(@Nonnull final DataBroker dataBroker,
                              @Nonnull final MessageIntelligenceAgency messageIntelligenceAgency,
-                             final long globalNotificationQuota, final boolean switchFeaturesMandatory) {
+                             final long globalNotificationQuota, final boolean switchFeaturesMandatory,
+                             final long barrierInterval, final int barrierCountLimit) {
         this.switchFeaturesMandatory = switchFeaturesMandatory;
         this.globalNotificationQuota = globalNotificationQuota;
         this.dataBroker = Preconditions.checkNotNull(dataBroker);
@@ -96,6 +98,8 @@ public class DeviceManagerImpl implements DeviceManager, ExtensionConverterProvi
         }
 
         this.messageIntelligenceAgency = messageIntelligenceAgency;
+        this.barrierIntervalNanos = TimeUnit.MILLISECONDS.toNanos(barrierInterval);
+        this.barrierCountLimit = barrierCountLimit;
     }
 
 
@@ -133,7 +137,7 @@ public class DeviceManagerImpl implements DeviceManager, ExtensionConverterProvi
 
         connectionContext.setOutboundQueueProvider(outboundQueueProvider);
         final OutboundQueueHandlerRegistration<OutboundQueueProvider> outboundQueueHandlerRegistration =
-                connectionAdapter.registerOutboundQueueHandler(outboundQueueProvider, maxQueueDepth, barrierNanos);
+                connectionAdapter.registerOutboundQueueHandler(outboundQueueProvider, barrierCountLimit, barrierIntervalNanos);
         connectionContext.setOutboundQueueHandleRegistration(outboundQueueHandlerRegistration);
 
         final DeviceState deviceState = createDeviceState(connectionContext);
index cc7d179466349a2f704a077555ae9808166d61e1..4717561f7de4d8af3d5837bc0e87466bde33ff7c 100644 (file)
@@ -10,11 +10,11 @@ public class OpenFlowProviderModule extends org.opendaylight.yang.gen.v1.urn.ope
 
     private static final Logger LOG = LoggerFactory.getLogger(OpenFlowProviderModule.class);
 
-    public OpenFlowProviderModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
+    public OpenFlowProviderModule(final org.opendaylight.controller.config.api.ModuleIdentifier identifier, final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
         super(identifier, dependencyResolver);
     }
 
-    public OpenFlowProviderModule(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.config.openflow.plugin.impl.rev150327.OpenFlowProviderModule oldModule, java.lang.AutoCloseable oldInstance) {
+    public OpenFlowProviderModule(final org.opendaylight.controller.config.api.ModuleIdentifier identifier, final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver, final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.config.openflow.plugin.impl.rev150327.OpenFlowProviderModule oldModule, final java.lang.AutoCloseable oldInstance) {
         super(identifier, dependencyResolver, oldModule, oldInstance);
     }
 
@@ -27,7 +27,7 @@ public class OpenFlowProviderModule extends org.opendaylight.yang.gen.v1.urn.ope
     public java.lang.AutoCloseable createInstance() {
         LOG.info("Initializing new OFP southbound.");
         OpenflowPortsUtil.init();
-        OpenFlowPluginProvider openflowPluginProvider = new OpenFlowPluginProviderImpl(getRpcRequestsQuota(), getGlobalNotificationQuota());
+        final OpenFlowPluginProvider openflowPluginProvider = new OpenFlowPluginProviderImpl(getRpcRequestsQuota(), getGlobalNotificationQuota());
 
         openflowPluginProvider.setSwitchConnectionProviders(getOpenflowSwitchConnectionProviderDependency());
         openflowPluginProvider.setDataBroker(getDataBrokerDependency());
@@ -38,9 +38,17 @@ public class OpenFlowProviderModule extends org.opendaylight.yang.gen.v1.urn.ope
         openflowPluginProvider.setIsStatisticsPollingOff(getIsStatisticsPollingOff());
         openflowPluginProvider.setEntityOwnershipService(getEntityOwnershipServiceDependency());
         openflowPluginProvider.setIsStatisticsRpcEnabled(getIsStatisticsRpcEnabled());
+        openflowPluginProvider.setBarrierCountLimit(getBarrierCountLimit().getValue());
+        openflowPluginProvider.setBarrierInterval(getBarrierIntervalTimeoutLimit().getValue());
+        openflowPluginProvider.setEchoReplyTimeout(getEchoReplyTimeout().getValue());
 
         openflowPluginProvider.initialize();
 
+        LOG.info("Configured values, StatisticsPollingOff:{}, SwitchFeaturesMandatory:{}, BarrierCountLimit:{}, BarrierTimeoutLimit:{}, EchoReplyTimeout:{}",
+                getIsStatisticsPollingOff(), getSwitchFeaturesMandatory(), getBarrierCountLimit().getValue(),
+                getBarrierIntervalTimeoutLimit().getValue(), getEchoReplyTimeout().getValue());
+
+
         return openflowPluginProvider;
     }
 
index aee2d6ccd1d1c776f6a84cf3737094bc152f511e..e86ae12ba251fefd5f093801c7401ea573bb3bc1 100644 (file)
@@ -20,6 +20,18 @@ module openflow-plugin-provider-impl {
             "Second openflow plugin implementation.";
     }
 
+    typedef non-zero-uint32-type {
+        type uint32 {
+            range "1..max";
+        }
+    }
+
+    typedef non-zero-uint16-type {
+        type uint16 {
+            range "1..max";
+        }
+     }
+
     identity openflow-plugin-provider-impl {
         base config:module-type;
         config:provided-service openflow-provider:openflow-provider;
@@ -101,6 +113,18 @@ module openflow-plugin-provider-impl {
                 type boolean;
                 default "false";
             }
+            leaf barrier-interval-timeout-limit {
+                type non-zero-uint32-type;
+                default 500;
+            }
+            leaf barrier-count-limit {
+                type non-zero-uint16-type;
+                default 25600;
+            }
+            leaf echo-reply-timeout {
+                type non-zero-uint32-type;
+                default 2000;
+            }
         }
 
     }
index 3c3f5c1bde3fbda6015ac6cd43c7a392dca9d701..813c1bd372a04084d63bc47ff05d8e098847a437 100644 (file)
@@ -55,12 +55,14 @@ public class ConnectionManagerImplTest {
     @Captor
     private ArgumentCaptor<OpenflowProtocolListener> ofpListenerAC;
 
+    private final static int ECHO_REPLY_TIMEOUT = 500;
+
     /**
      * before each test method
      */
     @Before
     public void setUp() {
-        connectionManagerImpl = new ConnectionManagerImpl();
+        connectionManagerImpl = new ConnectionManagerImpl(ECHO_REPLY_TIMEOUT);
         connectionManagerImpl.setDeviceConnectedHandler(deviceConnectedHandler);
         final InetSocketAddress deviceAddress = InetSocketAddress.createUnresolved("yahoo", 42);
         Mockito.when(connection.getRemoteAddress()).thenReturn(deviceAddress);
index e2cb7224d3ce0fdffd39fefdddb013de88166399..84fbd22b60b9848ffccafa64f7b985805311a36d 100644 (file)
@@ -40,6 +40,7 @@ import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
 public class SystemNotificationsListenerImplTest {
 
     public static final int SAFE_TIMEOUT = 1000;
+    private final static int ECHO_REPLY_TIMEOUT = 2000;
     @Mock
     private org.opendaylight.openflowjava.protocol.api.connection.ConnectionAdapter connectionAdapter;
     @Mock
@@ -64,7 +65,7 @@ public class SystemNotificationsListenerImplTest {
         Mockito.when(connectionContext.getConnectionAdapter()).thenReturn(connectionAdapter);
         Mockito.when(connectionContext.getFeatures()).thenReturn(features);
 
-        systemNotificationsListener = new SystemNotificationsListenerImpl(connectionContext);
+        systemNotificationsListener = new SystemNotificationsListenerImpl(connectionContext, ECHO_REPLY_TIMEOUT);
     }
 
     @After
index 8ec6befe162ce80efb255d3213d30781dc66b50d..fbde5c46bc91411f6a4d61b1b0324b84a837d6ac 100644 (file)
@@ -79,6 +79,8 @@ public class DeviceManagerImplTest {
     private static final Long DUMMY_MAX_METER = 544L;
     private static final String DUMMY_DATAPATH_ID = "44";
     private static final Long DUMMY_PORT_NUMBER = 21L;
+    private static final int barrierCountLimit = 25600;
+    private static final int barrierIntervalNanos = 500;
 
     @Mock
     CheckedFuture<Void, TransactionCommitFailedException> mockedFuture;
@@ -144,7 +146,8 @@ public class DeviceManagerImplTest {
 
         final MessageIntelligenceAgency mockedMessageIntelligenceAgency = mock(MessageIntelligenceAgency.class);
         final DeviceManagerImpl deviceManager = new DeviceManagerImpl(mockedDataBroker, mockedMessageIntelligenceAgency,
-                TEST_VALUE_GLOBAL_NOTIFICATION_QUOTA, false);
+                TEST_VALUE_GLOBAL_NOTIFICATION_QUOTA, false, barrierIntervalNanos, barrierCountLimit);
+
         deviceManager.setDeviceInitializationPhaseHandler(deviceInitPhaseHandler);
 
         return deviceManager;