From 967d712297c0160832d841688a8d50294498500f Mon Sep 17 00:00:00 2001 From: Jakub Morvay Date: Sat, 2 Feb 2019 18:40:27 +0100 Subject: [PATCH] Make netconf node tcp-only leaf have default value Netconf node tcp-only leaf defines if we should use SSH or TCP as an underlying protocol for netconf session to a netconf device. Currently it does not have any default value defined. That means if we forgot to fill in tcp-only field when configuring netconf mount point, netconf topology implementation will not know what protocol to use and will throw NPE. However, it would be more user friendly to have some default protocol defined. We should aim to use SSH by default as it is more secure protocol than just plain TCP. Make tcp-only field default to false. JIRA: NETCONF-488 Change-Id: I99d17ad54db55089b9ec3e417d69e711058c760a Signed-off-by: Jakub Morvay --- .../topology/singleton/impl/RemoteDeviceConnectorImpl.java | 5 +++-- .../topology/singleton/impl/utils/NetconfTopologyUtils.java | 1 + .../netconf/topology/AbstractNetconfTopology.java | 5 +++-- .../src/main/yang/netconf-node-topology.yang | 1 + 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/netconf/netconf-topology-singleton/src/main/java/org/opendaylight/netconf/topology/singleton/impl/RemoteDeviceConnectorImpl.java b/netconf/netconf-topology-singleton/src/main/java/org/opendaylight/netconf/topology/singleton/impl/RemoteDeviceConnectorImpl.java index 8ff961885e..6c05cf1fd5 100644 --- a/netconf/netconf-topology-singleton/src/main/java/org/opendaylight/netconf/topology/singleton/impl/RemoteDeviceConnectorImpl.java +++ b/netconf/netconf-topology-singleton/src/main/java/org/opendaylight/netconf/topology/singleton/impl/RemoteDeviceConnectorImpl.java @@ -109,7 +109,6 @@ public class RemoteDeviceConnectorImpl implements RemoteDeviceConnector { final NodeId nodeId = netconfTopologyDeviceSetup.getNode().getNodeId(); Preconditions.checkNotNull(netconfNode.getHost()); Preconditions.checkNotNull(netconfNode.getPort()); - Preconditions.checkNotNull(netconfNode.isTcpOnly()); this.deviceCommunicatorDTO = createDeviceCommunicator(nodeId, netconfNode, deviceHandler); final NetconfDeviceCommunicator deviceCommunicator = deviceCommunicatorDTO.getCommunicator(); @@ -276,6 +275,8 @@ public class RemoteDeviceConnectorImpl implements RemoteDeviceConnector { ? NetconfTopologyUtils.DEFAULT_MAX_CONNECTION_ATTEMPTS : node.getMaxConnectionAttempts(); final int betweenAttemptsTimeoutMillis = node.getBetweenAttemptsTimeoutMillis() == null ? NetconfTopologyUtils.DEFAULT_BETWEEN_ATTEMPTS_TIMEOUT_MILLIS : node.getBetweenAttemptsTimeoutMillis(); + final boolean isTcpOnly = node.isTcpOnly() == null + ? NetconfTopologyUtils.DEFAULT_IS_TCP_ONLY : node.isTcpOnly(); final BigDecimal sleepFactor = node.getSleepFactor() == null ? NetconfTopologyUtils.DEFAULT_SLEEP_FACTOR : node.getSleepFactor(); @@ -288,7 +289,7 @@ public class RemoteDeviceConnectorImpl implements RemoteDeviceConnector { final NetconfReconnectingClientConfigurationBuilder reconnectingClientConfigurationBuilder; final Protocol protocol = node.getProtocol(); - if (node.isTcpOnly()) { + if (isTcpOnly) { reconnectingClientConfigurationBuilder = NetconfReconnectingClientConfigurationBuilder.create() .withProtocol(NetconfClientConfiguration.NetconfClientProtocol.TCP) .withAuthHandler(getHandlerFromCredentials(node.getCredentials())); diff --git a/netconf/netconf-topology-singleton/src/main/java/org/opendaylight/netconf/topology/singleton/impl/utils/NetconfTopologyUtils.java b/netconf/netconf-topology-singleton/src/main/java/org/opendaylight/netconf/topology/singleton/impl/utils/NetconfTopologyUtils.java index 4f70d88a7d..1b7cd2be30 100644 --- a/netconf/netconf-topology-singleton/src/main/java/org/opendaylight/netconf/topology/singleton/impl/utils/NetconfTopologyUtils.java +++ b/netconf/netconf-topology-singleton/src/main/java/org/opendaylight/netconf/topology/singleton/impl/utils/NetconfTopologyUtils.java @@ -53,6 +53,7 @@ public final class NetconfTopologyUtils { public static final long DEFAULT_REQUEST_TIMEOUT_MILLIS = 60000L; public static final int DEFAULT_KEEPALIVE_DELAY = 0; public static final boolean DEFAULT_RECONNECT_ON_CHANGED_SCHEMA = false; + public static final boolean DEFAULT_IS_TCP_ONLY = false; public static final int DEFAULT_CONCURRENT_RPC_LIMIT = 0; public static final int DEFAULT_MAX_CONNECTION_ATTEMPTS = 0; public static final int DEFAULT_BETWEEN_ATTEMPTS_TIMEOUT_MILLIS = 2000; diff --git a/netconf/netconf-topology/src/main/java/org/opendaylight/netconf/topology/AbstractNetconfTopology.java b/netconf/netconf-topology/src/main/java/org/opendaylight/netconf/topology/AbstractNetconfTopology.java index a625dd3a49..3bb3fcf682 100644 --- a/netconf/netconf-topology/src/main/java/org/opendaylight/netconf/topology/AbstractNetconfTopology.java +++ b/netconf/netconf-topology/src/main/java/org/opendaylight/netconf/topology/AbstractNetconfTopology.java @@ -101,6 +101,7 @@ public abstract class AbstractNetconfTopology implements NetconfTopology { protected static final int DEFAULT_KEEPALIVE_DELAY = 0; protected static final boolean DEFAULT_RECONNECT_ON_CHANGED_SCHEMA = false; protected static final int DEFAULT_CONCURRENT_RPC_LIMIT = 0; + private static final boolean DEFAULT_IS_TCP_ONLY = false; private static final int DEFAULT_MAX_CONNECTION_ATTEMPTS = 0; private static final int DEFAULT_BETWEEN_ATTEMPTS_TIMEOUT_MILLIS = 2000; private static final long DEFAULT_CONNECTION_TIMEOUT_MILLIS = 20000L; @@ -263,7 +264,6 @@ public abstract class AbstractNetconfTopology implements NetconfTopology { Preconditions.checkNotNull(netconfNode.getHost()); Preconditions.checkNotNull(netconfNode.getPort()); - Preconditions.checkNotNull(netconfNode.isTcpOnly()); final NetconfConnectorDTO deviceCommunicatorDTO = createDeviceCommunicator(nodeId, netconfNode); final NetconfDeviceCommunicator deviceCommunicator = deviceCommunicatorDTO.getCommunicator(); @@ -477,6 +477,7 @@ public abstract class AbstractNetconfTopology implements NetconfTopology { ? DEFAULT_MAX_CONNECTION_ATTEMPTS : node.getMaxConnectionAttempts(); final int betweenAttemptsTimeoutMillis = node.getBetweenAttemptsTimeoutMillis() == null ? DEFAULT_BETWEEN_ATTEMPTS_TIMEOUT_MILLIS : node.getBetweenAttemptsTimeoutMillis(); + final boolean useTcp = node.isTcpOnly() == null ? DEFAULT_IS_TCP_ONLY : node.isTcpOnly(); final BigDecimal sleepFactor = node.getSleepFactor() == null ? DEFAULT_SLEEP_FACTOR : node.getSleepFactor(); final InetSocketAddress socketAddress = getSocketAddress(node.getHost(), node.getPort().getValue()); @@ -486,7 +487,7 @@ public abstract class AbstractNetconfTopology implements NetconfTopology { final NetconfReconnectingClientConfigurationBuilder reconnectingClientConfigurationBuilder; final Protocol protocol = node.getProtocol(); - if (node.isTcpOnly()) { + if (useTcp) { reconnectingClientConfigurationBuilder = NetconfReconnectingClientConfigurationBuilder.create() .withProtocol(NetconfClientConfiguration.NetconfClientProtocol.TCP) .withAuthHandler(getHandlerFromCredentials(node.getCredentials())); diff --git a/netconf/sal-netconf-connector/src/main/yang/netconf-node-topology.yang b/netconf/sal-netconf-connector/src/main/yang/netconf-node-topology.yang index 78fb0422e4..143cc2a3b2 100644 --- a/netconf/sal-netconf-connector/src/main/yang/netconf-node-topology.yang +++ b/netconf/sal-netconf-connector/src/main/yang/netconf-node-topology.yang @@ -79,6 +79,7 @@ module netconf-node-topology { leaf tcp-only { config true; type boolean; + default false; } container protocol { -- 2.36.6