import com.google.common.util.concurrent.ListeningExecutorService;
import com.google.common.util.concurrent.MoreExecutors;
import io.netty.util.concurrent.EventExecutor;
-import java.math.BigDecimal;
import java.net.InetSocketAddress;
import java.net.URL;
import java.util.ArrayList;
public abstract class AbstractNetconfTopology implements NetconfTopology {
private static final Logger LOG = LoggerFactory.getLogger(AbstractNetconfTopology.class);
- protected static final long DEFAULT_REQUEST_TIMEOUT_MILLIS = 60000L;
- 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;
- private static final BigDecimal DEFAULT_SLEEP_FACTOR = new BigDecimal(1.5);
-
private final NetconfClientDispatcher clientDispatcher;
private final EventExecutor eventExecutor;
private final DeviceActionFactory deviceActionFactory;
protected final AAAEncryptionService encryptionService;
protected final HashMap<NodeId, NetconfConnectorDTO> activeConnectors = new HashMap<>();
-
protected AbstractNetconfTopology(final String topologyId, final NetconfClientDispatcher clientDispatcher,
final EventExecutor eventExecutor, final ScheduledThreadPool keepaliveExecutor,
final ThreadPool processingExecutor, final SchemaResourceManager schemaManager,
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().toJava();
- final long keepaliveDelay = node.getKeepaliveDelay() == null
- ? DEFAULT_KEEPALIVE_DELAY : node.getKeepaliveDelay().toJava();
-
- final InetSocketAddress address;
final Host host = node.getHost();
final IpAddress ipAddress = host.getIpAddress();
+ final InetSocketAddress address;
if (ipAddress != null) {
address = new InetSocketAddress(IetfInetUtil.INSTANCE.inetAddressFor(ipAddress),
node.getPort().getValue().toJava());
}
final RemoteDeviceId remoteDeviceId = new RemoteDeviceId(nodeId.getValue(), address);
+ final long keepaliveDelay = node.getKeepaliveDelay().toJava();
RemoteDeviceHandler<NetconfSessionPreferences> salFacade = createSalFacade(remoteDeviceId);
-
if (keepaliveDelay > 0) {
- LOG.warn("Adding keepalive facade, for device {}", nodeId);
+ LOG.info("Adding keepalive facade, for device {}", nodeId);
salFacade = new KeepaliveSalFacade(remoteDeviceId, salFacade, this.keepaliveExecutor.getExecutor(),
- keepaliveDelay, defaultRequestTimeoutMillis);
+ keepaliveDelay, node.getDefaultRequestTimeoutMillis().toJava());
}
final RemoteDevice<NetconfSessionPreferences, NetconfMessage, NetconfDeviceCommunicator> device;
device = new SchemalessNetconfDevice(baseSchemas, remoteDeviceId, salFacade);
yanglibRegistrations = List.of();
} else {
- final boolean reconnectOnChangedSchema = node.getReconnectOnChangedSchema() == null
- ? DEFAULT_RECONNECT_ON_CHANGED_SCHEMA : node.getReconnectOnChangedSchema();
-
+ final boolean reconnectOnChangedSchema = node.getReconnectOnChangedSchema();
final SchemaResourcesDTO resources = schemaManager.getSchemaResources(node, nodeId.getValue());
device = new NetconfDeviceBuilder()
.setReconnectOnSchemasChange(reconnectOnChangedSchema)
.setDeviceActionFactory(deviceActionFactory)
.setBaseSchemas(baseSchemas)
.build();
- yanglibRegistrations = registerDeviceSchemaSources(remoteDeviceId, nodeId, node, resources);
+ yanglibRegistrations = registerDeviceSchemaSources(remoteDeviceId, node, resources);
}
final Optional<UserPreferences> userCapabilities = getUserCapabilities(node);
- final int rpcMessageLimit = node.getConcurrentRpcLimit() == null ? DEFAULT_CONCURRENT_RPC_LIMIT
- : node.getConcurrentRpcLimit().toJava();
-
+ final int rpcMessageLimit = node.getConcurrentRpcLimit().toJava();
if (rpcMessageLimit < 1) {
LOG.info("Concurrent rpc limit is smaller than 1, no limit will be enforced for device {}", remoteDeviceId);
}
- NetconfDeviceCommunicator netconfDeviceCommunicator =
+ final NetconfDeviceCommunicator netconfDeviceCommunicator =
userCapabilities.isPresent() ? new NetconfDeviceCommunicator(remoteDeviceId, device,
userCapabilities.get(), rpcMessageLimit)
: new NetconfDeviceCommunicator(remoteDeviceId, device, rpcMessageLimit);
}
private List<SchemaSourceRegistration<?>> registerDeviceSchemaSources(final RemoteDeviceId remoteDeviceId,
- final NodeId nodeId, final NetconfNode node, final SchemaResourcesDTO resources) {
+ final NetconfNode node, final SchemaResourcesDTO resources) {
final YangLibrary yangLibrary = node.getYangLibrary();
if (yangLibrary != null) {
final Uri uri = yangLibrary.getYangLibraryUrl();
public 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
- ? DEFAULT_CONNECTION_TIMEOUT_MILLIS : node.getConnectionTimeoutMillis().toJava();
- final long maxConnectionAttempts = node.getMaxConnectionAttempts() == null
- ? DEFAULT_MAX_CONNECTION_ATTEMPTS : node.getMaxConnectionAttempts().toJava();
- final int betweenAttemptsTimeoutMillis = node.getBetweenAttemptsTimeoutMillis() == null
- ? DEFAULT_BETWEEN_ATTEMPTS_TIMEOUT_MILLIS : node.getBetweenAttemptsTimeoutMillis().toJava();
- final boolean useTcp = node.getTcpOnly() == null ? DEFAULT_IS_TCP_ONLY : node.getTcpOnly();
- final BigDecimal sleepFactor = node.getSleepFactor() == null ? DEFAULT_SLEEP_FACTOR : node.getSleepFactor();
-
- final InetSocketAddress socketAddress = getSocketAddress(node.getHost(), node.getPort().getValue().toJava());
-
final ReconnectStrategyFactory sf = new TimedReconnectStrategyFactory(eventExecutor,
- maxConnectionAttempts, betweenAttemptsTimeoutMillis, sleepFactor);
-
+ node.getMaxConnectionAttempts().toJava(), node.getBetweenAttemptsTimeoutMillis().toJava(),
+ node.getSleepFactor());
final NetconfReconnectingClientConfigurationBuilder reconnectingClientConfigurationBuilder;
final Protocol protocol = node.getProtocol();
- if (useTcp) {
+ if (node.getTcpOnly()) {
reconnectingClientConfigurationBuilder = NetconfReconnectingClientConfigurationBuilder.create()
.withProtocol(NetconfClientConfiguration.NetconfClientProtocol.TCP)
.withAuthHandler(getHandlerFromCredentials(node.getCredentials()));
}
return reconnectingClientConfigurationBuilder
- .withAddress(socketAddress)
- .withConnectionTimeoutMillis(clientConnectionTimeoutMillis)
+ .withAddress(getSocketAddress(node.getHost(), node.getPort().getValue().toJava()))
+ .withConnectionTimeoutMillis(node.getConnectionTimeoutMillis().toJava())
.withReconnectStrategy(sf.createReconnectStrategy())
.withConnectStrategyFactory(sf)
.withSessionListener(listener)