*/
package org.opendaylight.netconf.topology;
-import com.google.common.base.Optional;
+import static java.util.Objects.requireNonNull;
+
+import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
import com.google.common.collect.Lists;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.Optional;
import java.util.concurrent.TimeUnit;
import org.opendaylight.aaa.encrypt.AAAEncryptionService;
import org.opendaylight.controller.config.threadpool.ScheduledThreadPool;
import org.opendaylight.netconf.topology.api.SchemaRepositoryProvider;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Host;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.optional.rev190614.NetconfNodeAugmentedOptional;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNode;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.netconf.node.connection.parameters.Protocol;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.netconf.node.connection.parameters.Protocol.Name;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.netconf.node.credentials.credentials.login.pw.unencrypted.LoginPasswordUnencrypted;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
+import org.opendaylight.yangtools.yang.model.repo.api.EffectiveModelContextFactory;
import org.opendaylight.yangtools.yang.model.repo.api.SchemaContextFactory;
+import org.opendaylight.yangtools.yang.model.repo.api.SchemaContextFactoryConfiguration;
import org.opendaylight.yangtools.yang.model.repo.api.SchemaRepository;
-import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceFilter;
import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
import org.opendaylight.yangtools.yang.model.repo.spi.PotentialSchemaSource;
/**
* The default factory for creating <code>SchemaContext</code> instances.
*/
- private static final SchemaContextFactory DEFAULT_SCHEMA_CONTEXT_FACTORY =
- DEFAULT_SCHEMA_REPOSITORY.createSchemaContextFactory(SchemaSourceFilter.ALWAYS_ACCEPT);
+ private static final EffectiveModelContextFactory DEFAULT_SCHEMA_CONTEXT_FACTORY =
+ DEFAULT_SCHEMA_REPOSITORY.createEffectiveModelContextFactory(
+ SchemaContextFactoryConfiguration.getDefault());
/**
* Keeps track of initialized Schema resources. A Map is maintained in which the key represents the name
@Override
public ListenableFuture<NetconfDeviceCapabilities> connectNode(final NodeId nodeId, final Node configNode) {
- LOG.info("Connecting RemoteDevice{{}} , with config {}", nodeId, configNode);
+ LOG.info("Connecting RemoteDevice{{}} , with config {}", nodeId, hideCredentials(configNode));
return setupConnection(nodeId, configNode);
}
+ /**
+ * Hiding of private credentials from node configuration (credentials data is replaced by asterisks).
+ *
+ * @param nodeConfiguration Node configuration container.
+ * @return String representation of node configuration with credentials replaced by asterisks.
+ */
+ @VisibleForTesting
+ public static String hideCredentials(final Node nodeConfiguration) {
+ final NetconfNode netconfNodeAugmentation = nodeConfiguration.augmentation(NetconfNode.class);
+ final String nodeCredentials = netconfNodeAugmentation.getCredentials().toString();
+ final String nodeConfigurationString = nodeConfiguration.toString();
+ return nodeConfigurationString.replace(nodeCredentials, "***");
+ }
+
@Override
public ListenableFuture<Void> disconnectNode(final NodeId nodeId) {
LOG.debug("Disconnecting RemoteDevice{{}}", nodeId.getValue());
protected ListenableFuture<NetconfDeviceCapabilities> setupConnection(final NodeId nodeId,
final Node configNode) {
final NetconfNode netconfNode = configNode.augmentation(NetconfNode.class);
+ final NetconfNodeAugmentedOptional nodeOptional = configNode.augmentation(NetconfNodeAugmentedOptional.class);
- Preconditions.checkNotNull(netconfNode.getHost());
- Preconditions.checkNotNull(netconfNode.getPort());
+ requireNonNull(netconfNode.getHost());
+ requireNonNull(netconfNode.getPort());
- final NetconfConnectorDTO deviceCommunicatorDTO = createDeviceCommunicator(nodeId, netconfNode);
+ final NetconfConnectorDTO deviceCommunicatorDTO = createDeviceCommunicator(nodeId, netconfNode, nodeOptional);
final NetconfDeviceCommunicator deviceCommunicator = deviceCommunicatorDTO.getCommunicator();
final NetconfClientSessionListener netconfClientSessionListener = deviceCommunicatorDTO.getSessionListener();
final NetconfReconnectingClientConfiguration clientConfig =
}
protected NetconfConnectorDTO createDeviceCommunicator(final NodeId nodeId, final NetconfNode node) {
+ return createDeviceCommunicator(nodeId, node, null);
+ }
+
+ protected NetconfConnectorDTO createDeviceCommunicator(final NodeId nodeId, final NetconfNode node,
+ final NetconfNodeAugmentedOptional nodeOptional) {
//setup default values since default value is not supported in mdsal
final long defaultRequestTimeoutMillis = node.getDefaultRequestTimeoutMillis() == null
- ? DEFAULT_REQUEST_TIMEOUT_MILLIS : node.getDefaultRequestTimeoutMillis();
+ ? DEFAULT_REQUEST_TIMEOUT_MILLIS : node.getDefaultRequestTimeoutMillis().toJava();
final long keepaliveDelay = node.getKeepaliveDelay() == null
- ? DEFAULT_KEEPALIVE_DELAY : node.getKeepaliveDelay();
+ ? DEFAULT_KEEPALIVE_DELAY : node.getKeepaliveDelay().toJava();
final boolean reconnectOnChangedSchema = node.isReconnectOnChangedSchema() == null
? DEFAULT_RECONNECT_ON_CHANGED_SCHEMA : node.isReconnectOnChangedSchema();
final IpAddress ipAddress = node.getHost().getIpAddress();
final InetSocketAddress address = new InetSocketAddress(ipAddress.getIpv4Address() != null
? ipAddress.getIpv4Address().getValue() : ipAddress.getIpv6Address().getValue(),
- node.getPort().getValue());
+ node.getPort().getValue().toJava());
final RemoteDeviceId remoteDeviceId = new RemoteDeviceId(nodeId.getValue(), address);
RemoteDeviceHandler<NetconfSessionPreferences> salFacade =
.setSchemaResourcesDTO(schemaResourcesDTO)
.setGlobalProcessingExecutor(this.processingExecutor)
.setId(remoteDeviceId)
- .setSalFacade(salFacade);
- if (this.deviceActionFactory != null) {
- netconfDeviceBuilder.setDeviceActionFactory(this.deviceActionFactory);
- }
+ .setSalFacade(salFacade)
+ .setNode(node)
+ .setEventExecutor(eventExecutor)
+ .setNodeOptional(nodeOptional)
+ .setDeviceActionFactory(deviceActionFactory);
device = netconfDeviceBuilder.build();
}
final Optional<UserPreferences> userCapabilities = getUserCapabilities(node);
- final int rpcMessageLimit =
- node.getConcurrentRpcLimit() == null ? DEFAULT_CONCURRENT_RPC_LIMIT : node.getConcurrentRpcLimit();
+ final int rpcMessageLimit = node.getConcurrentRpcLimit() == null ? DEFAULT_CONCURRENT_RPC_LIMIT
+ : node.getConcurrentRpcLimit().toJava();
if (rpcMessageLimit < 1) {
LOG.info("Concurrent rpc limit is smaller than 1, no limit will be enforced for device {}", remoteDeviceId);
*/
private NetconfDevice.SchemaResourcesDTO createSchemaResourcesDTO(final String moduleSchemaCacheDirectory) {
final SharedSchemaRepository repository = new SharedSchemaRepository(moduleSchemaCacheDirectory);
- final SchemaContextFactory contextFactory
- = repository.createSchemaContextFactory(SchemaSourceFilter.ALWAYS_ACCEPT);
+ final EffectiveModelContextFactory contextFactory
+ = repository.createEffectiveModelContextFactory(SchemaContextFactoryConfiguration.getDefault());
setSchemaRegistry(repository);
setSchemaContextFactory(contextFactory);
final FilesystemSchemaSourceCache<YangTextSchemaSource> deviceCache =
//setup default values since default value is not supported in mdsal
final long clientConnectionTimeoutMillis = node.getConnectionTimeoutMillis() == null
- ? DEFAULT_CONNECTION_TIMEOUT_MILLIS : node.getConnectionTimeoutMillis();
+ ? DEFAULT_CONNECTION_TIMEOUT_MILLIS : node.getConnectionTimeoutMillis().toJava();
final long maxConnectionAttempts = node.getMaxConnectionAttempts() == null
- ? DEFAULT_MAX_CONNECTION_ATTEMPTS : node.getMaxConnectionAttempts();
+ ? DEFAULT_MAX_CONNECTION_ATTEMPTS : node.getMaxConnectionAttempts().toJava();
final int betweenAttemptsTimeoutMillis = node.getBetweenAttemptsTimeoutMillis() == null
- ? DEFAULT_BETWEEN_ATTEMPTS_TIMEOUT_MILLIS : node.getBetweenAttemptsTimeoutMillis();
+ ? DEFAULT_BETWEEN_ATTEMPTS_TIMEOUT_MILLIS : node.getBetweenAttemptsTimeoutMillis().toJava();
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());
+ final InetSocketAddress socketAddress = getSocketAddress(node.getHost(), node.getPort().getValue().toJava());
final ReconnectStrategyFactory sf = new TimedReconnectStrategyFactory(eventExecutor,
maxConnectionAttempts, betweenAttemptsTimeoutMillis, sleepFactor);
// if none of yang-module-capabilities or non-module-capabilities is specified
// just return absent
if (node.getYangModuleCapabilities() == null && node.getNonModuleCapabilities() == null) {
- return Optional.absent();
+ return Optional.empty();
}
final List<String> capabilities = new ArrayList<>();