BUG-372 Add reconnecting to netconf-connector for unexpected session drop 34/6934/1
authorMaros Marsalek <mmarsale@cisco.com>
Tue, 13 May 2014 14:10:59 +0000 (16:10 +0200)
committerMaros Marsalek <mmarsale@cisco.com>
Tue, 13 May 2014 14:19:35 +0000 (16:19 +0200)
Netconf connector will reattempt connection if the session to remote device is dropped.
Increase sleep factor in netconf connector from 1.0 to 1.5.
This prevents connection attempt every second in case remote device is not comming back for longer time.
Connection attempts span increases gradually.

Change-Id: Icc4b993942e9cc6897c0da858eb867afa4c8aa87
Signed-off-by: Maros Marsalek <mmarsale@cisco.com>
opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/config/yang/md/sal/connector/netconf/NetconfConnectorModule.java
opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/sal/connect/netconf/NetconfDevice.java

index 7bf8ee8..de3c18d 100644 (file)
@@ -23,11 +23,14 @@ import org.opendaylight.controller.netconf.client.NetconfClientDispatcher;
 import org.opendaylight.controller.netconf.client.NetconfClientDispatcherImpl;
 import org.opendaylight.controller.netconf.client.conf.NetconfClientConfiguration;
 import org.opendaylight.controller.netconf.client.conf.NetconfClientConfigurationBuilder;
+import org.opendaylight.controller.netconf.client.conf.NetconfReconnectingClientConfiguration;
+import org.opendaylight.controller.netconf.client.conf.NetconfReconnectingClientConfigurationBuilder;
 import org.opendaylight.controller.netconf.util.handler.ssh.authentication.LoginPassword;
 import org.opendaylight.controller.sal.binding.api.data.DataProviderService;
 import org.opendaylight.controller.sal.connect.netconf.NetconfDevice;
 import org.opendaylight.controller.sal.connect.netconf.NetconfDeviceListener;
 import org.opendaylight.protocol.framework.ReconnectStrategy;
+import org.opendaylight.protocol.framework.ReconnectStrategyFactory;
 import org.opendaylight.protocol.framework.TimedReconnectStrategy;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
@@ -141,12 +144,12 @@ public final class NetconfConnectorModule extends org.opendaylight.controller.co
         this.bundleContext = bundleContext;
     }
 
-    public NetconfClientConfiguration getClientConfig(final NetconfDevice device) {
+    public NetconfReconnectingClientConfiguration getClientConfig(final NetconfDevice device) {
         InetSocketAddress socketAddress = getSocketAddress();
         ReconnectStrategy strategy = getReconnectStrategy();
         long clientConnectionTimeoutMillis = getConnectionTimeoutMillis();
 
-        return NetconfClientConfigurationBuilder.create()
+        return NetconfReconnectingClientConfigurationBuilder.create()
         .withAddress(socketAddress)
         .withConnectionTimeoutMillis(clientConnectionTimeoutMillis)
         .withReconnectStrategy(strategy)
@@ -155,6 +158,12 @@ public final class NetconfConnectorModule extends org.opendaylight.controller.co
         .withProtocol(getTcpOnly() ?
                 NetconfClientConfiguration.NetconfClientProtocol.TCP :
                 NetconfClientConfiguration.NetconfClientProtocol.SSH)
+        .withConnectStrategyFactory(new ReconnectStrategyFactory() {
+            @Override
+            public ReconnectStrategy createReconnectStrategy() {
+                return getReconnectStrategy();
+            }
+        })
         .build();
     }
 
@@ -166,7 +175,7 @@ public final class NetconfConnectorModule extends org.opendaylight.controller.co
             logger.trace("Setting {} on {} to infinity", maxConnectionAttemptsJmxAttribute, this);
             connectionAttempts = null;
         }
-        double sleepFactor = 1.0;
+        double sleepFactor = 1.5;
         int minSleep = 1000;
         Long maxSleep = null;
         Long deadline = null;
index 54242cf..94beaed 100644 (file)
@@ -40,6 +40,7 @@ import org.opendaylight.controller.md.sal.common.api.data.DataModification;
 import org.opendaylight.controller.md.sal.common.api.data.DataReader;
 import org.opendaylight.controller.netconf.client.NetconfClientDispatcher;
 import org.opendaylight.controller.netconf.client.conf.NetconfClientConfiguration;
+import org.opendaylight.controller.netconf.client.conf.NetconfReconnectingClientConfiguration;
 import org.opendaylight.controller.sal.binding.api.data.DataProviderService;
 import org.opendaylight.controller.sal.core.api.Broker.ProviderSession;
 import org.opendaylight.controller.sal.core.api.Broker.RpcRegistration;
@@ -126,7 +127,7 @@ public class NetconfDevice implements Provider, //
 
     private boolean rollbackSupported;
 
-    private NetconfClientConfiguration clientConfig;
+    private NetconfReconnectingClientConfiguration clientConfig;
     private volatile DataProviderService dataProviderService;
 
     public NetconfDevice(String name) {
@@ -146,7 +147,7 @@ public class NetconfDevice implements Provider, //
 
         logger.info("Starting NETCONF Client {} for address {}", name, socketAddress);
 
-        dispatcher.createClient(clientConfig);
+        dispatcher.createReconnectingClient(clientConfig);
     }
 
     Optional<SchemaContext> getSchemaContext() {
@@ -491,7 +492,7 @@ public class NetconfDevice implements Provider, //
         this.dispatcher = dispatcher;
     }
 
-    public void setClientConfig(final NetconfClientConfiguration clientConfig) {
+    public void setClientConfig(final NetconfReconnectingClientConfiguration clientConfig) {
         this.clientConfig = clientConfig;
     }