Search in sources :

Example 1 with NetconfReconnectingClientConfigurationBuilder

use of org.opendaylight.netconf.client.conf.NetconfReconnectingClientConfigurationBuilder in project netconf by opendaylight.

the class RemoteDeviceConnectorImpl method getClientConfig.

@VisibleForTesting
NetconfReconnectingClientConfiguration getClientConfig(final NetconfClientSessionListener listener, final NetconfNode node) {
    // setup default values since default value is not supported in mdsal
    final long clientConnectionTimeoutMillis = node.getConnectionTimeoutMillis() == null ? NetconfTopologyUtils.DEFAULT_CONNECTION_TIMEOUT_MILLIS : node.getConnectionTimeoutMillis().toJava();
    final long maxConnectionAttempts = node.getMaxConnectionAttempts() == null ? NetconfTopologyUtils.DEFAULT_MAX_CONNECTION_ATTEMPTS : node.getMaxConnectionAttempts().toJava();
    final int betweenAttemptsTimeoutMillis = node.getBetweenAttemptsTimeoutMillis() == null ? NetconfTopologyUtils.DEFAULT_BETWEEN_ATTEMPTS_TIMEOUT_MILLIS : node.getBetweenAttemptsTimeoutMillis().toJava();
    final boolean isTcpOnly = node.getTcpOnly() == null ? NetconfTopologyUtils.DEFAULT_IS_TCP_ONLY : node.getTcpOnly();
    final BigDecimal sleepFactor = node.getSleepFactor() == null ? NetconfTopologyUtils.DEFAULT_SLEEP_FACTOR : node.getSleepFactor();
    final InetSocketAddress socketAddress = getSocketAddress(node.getHost(), node.getPort().getValue().toJava());
    final ReconnectStrategyFactory sf = new TimedReconnectStrategyFactory(netconfTopologyDeviceSetup.getEventExecutor(), maxConnectionAttempts, betweenAttemptsTimeoutMillis, sleepFactor);
    final NetconfReconnectingClientConfigurationBuilder reconnectingClientConfigurationBuilder;
    final Protocol protocol = node.getProtocol();
    if (isTcpOnly) {
        reconnectingClientConfigurationBuilder = NetconfReconnectingClientConfigurationBuilder.create().withProtocol(NetconfClientConfiguration.NetconfClientProtocol.TCP).withAuthHandler(getHandlerFromCredentials(node.getCredentials()));
    } else if (protocol == null || protocol.getName() == Protocol.Name.SSH) {
        reconnectingClientConfigurationBuilder = NetconfReconnectingClientConfigurationBuilder.create().withProtocol(NetconfClientConfiguration.NetconfClientProtocol.SSH).withAuthHandler(getHandlerFromCredentials(node.getCredentials()));
    } else if (protocol.getName() == Protocol.Name.TLS) {
        reconnectingClientConfigurationBuilder = NetconfReconnectingClientConfigurationBuilder.create().withSslHandlerFactory(new SslHandlerFactoryImpl(keystoreAdapter, protocol.getSpecification())).withProtocol(NetconfClientConfiguration.NetconfClientProtocol.TLS);
    } else {
        throw new IllegalStateException("Unsupported protocol type: " + protocol.getName());
    }
    final List<Uri> odlHelloCapabilities = getOdlHelloCapabilities(node);
    if (odlHelloCapabilities != null) {
        reconnectingClientConfigurationBuilder.withOdlHelloCapabilities(odlHelloCapabilities);
    }
    return reconnectingClientConfigurationBuilder.withAddress(socketAddress).withConnectionTimeoutMillis(clientConnectionTimeoutMillis).withReconnectStrategy(sf.createReconnectStrategy()).withConnectStrategyFactory(sf).withSessionListener(listener).build();
}
Also used : InetSocketAddress(java.net.InetSocketAddress) NetconfReconnectingClientConfigurationBuilder(org.opendaylight.netconf.client.conf.NetconfReconnectingClientConfigurationBuilder) Uri(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri) BigDecimal(java.math.BigDecimal) TimedReconnectStrategyFactory(org.opendaylight.netconf.nettyutil.TimedReconnectStrategyFactory) TimedReconnectStrategyFactory(org.opendaylight.netconf.nettyutil.TimedReconnectStrategyFactory) ReconnectStrategyFactory(org.opendaylight.netconf.nettyutil.ReconnectStrategyFactory) SslHandlerFactoryImpl(org.opendaylight.netconf.sal.connect.util.SslHandlerFactoryImpl) Protocol(org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.netconf.node.connection.parameters.Protocol) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 2 with NetconfReconnectingClientConfigurationBuilder

use of org.opendaylight.netconf.client.conf.NetconfReconnectingClientConfigurationBuilder in project netconf by opendaylight.

the class AbstractNetconfTopology method getClientConfig.

public NetconfReconnectingClientConfiguration getClientConfig(final NetconfClientSessionListener listener, final NetconfNode node) {
    final ReconnectStrategyFactory sf = new TimedReconnectStrategyFactory(eventExecutor, node.requireMaxConnectionAttempts().toJava(), node.requireBetweenAttemptsTimeoutMillis().toJava(), node.requireSleepFactor());
    final NetconfReconnectingClientConfigurationBuilder reconnectingClientConfigurationBuilder;
    final Protocol protocol = node.getProtocol();
    if (node.requireTcpOnly()) {
        reconnectingClientConfigurationBuilder = NetconfReconnectingClientConfigurationBuilder.create().withProtocol(NetconfClientConfiguration.NetconfClientProtocol.TCP).withAuthHandler(getHandlerFromCredentials(node.getCredentials()));
    } else if (protocol == null || protocol.getName() == Name.SSH) {
        reconnectingClientConfigurationBuilder = NetconfReconnectingClientConfigurationBuilder.create().withProtocol(NetconfClientConfiguration.NetconfClientProtocol.SSH).withAuthHandler(getHandlerFromCredentials(node.getCredentials()));
    } else if (protocol.getName() == Name.TLS) {
        reconnectingClientConfigurationBuilder = NetconfReconnectingClientConfigurationBuilder.create().withSslHandlerFactory(new SslHandlerFactoryImpl(keystoreAdapter, protocol.getSpecification())).withProtocol(NetconfClientConfiguration.NetconfClientProtocol.TLS);
    } else {
        throw new IllegalStateException("Unsupported protocol type: " + protocol.getName());
    }
    if (node.getOdlHelloMessageCapabilities() != null) {
        reconnectingClientConfigurationBuilder.withOdlHelloCapabilities(node.getOdlHelloMessageCapabilities().getCapability());
    }
    return reconnectingClientConfigurationBuilder.withAddress(getSocketAddress(node.getHost(), node.getPort().getValue().toJava())).withConnectionTimeoutMillis(node.requireConnectionTimeoutMillis().toJava()).withReconnectStrategy(sf.createReconnectStrategy()).withConnectStrategyFactory(sf).withSessionListener(listener).build();
}
Also used : TimedReconnectStrategyFactory(org.opendaylight.netconf.nettyutil.TimedReconnectStrategyFactory) TimedReconnectStrategyFactory(org.opendaylight.netconf.nettyutil.TimedReconnectStrategyFactory) ReconnectStrategyFactory(org.opendaylight.netconf.nettyutil.ReconnectStrategyFactory) SslHandlerFactoryImpl(org.opendaylight.netconf.sal.connect.util.SslHandlerFactoryImpl) Protocol(org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.netconf.node.connection.parameters.Protocol) NetconfReconnectingClientConfigurationBuilder(org.opendaylight.netconf.client.conf.NetconfReconnectingClientConfigurationBuilder)

Aggregations

NetconfReconnectingClientConfigurationBuilder (org.opendaylight.netconf.client.conf.NetconfReconnectingClientConfigurationBuilder)2 ReconnectStrategyFactory (org.opendaylight.netconf.nettyutil.ReconnectStrategyFactory)2 TimedReconnectStrategyFactory (org.opendaylight.netconf.nettyutil.TimedReconnectStrategyFactory)2 SslHandlerFactoryImpl (org.opendaylight.netconf.sal.connect.util.SslHandlerFactoryImpl)2 Protocol (org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.netconf.node.connection.parameters.Protocol)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 BigDecimal (java.math.BigDecimal)1 InetSocketAddress (java.net.InetSocketAddress)1 Uri (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri)1