use of org.opendaylight.netconf.topology.spi.NetconfConnectorDTO in project netconf by opendaylight.
the class RemoteDeviceConnectorImplTest method testKeapAliveFacade.
@SuppressWarnings("unchecked")
@Test
public void testKeapAliveFacade() {
final Credentials credentials = new LoginPasswordBuilder().setPassword("admin").setUsername("admin").build();
final NetconfNode netconfNode = new NetconfNodeBuilder().setHost(new Host(new IpAddress(new Ipv4Address("127.0.0.1")))).setPort(new PortNumber(Uint16.valueOf(9999))).setReconnectOnChangedSchema(true).setDefaultRequestTimeoutMillis(Uint32.valueOf(1000)).setBetweenAttemptsTimeoutMillis(Uint16.valueOf(100)).setSchemaless(false).setTcpOnly(false).setCredentials(credentials).setKeepaliveDelay(Uint32.ONE).build();
final Node node = new NodeBuilder().setNodeId(NODE_ID).addAugmentation(netconfNode).build();
builder.setSchemaResourceDTO(new DefaultSchemaResourceManager(new DefaultYangParserFactory()).getSchemaResources(netconfNode, "foo"));
final RemoteDeviceConnectorImpl remoteDeviceConnection = new RemoteDeviceConnectorImpl(builder.build(), remoteDeviceId, deviceActionFactory);
final RemoteDeviceHandler<NetconfSessionPreferences> salFacade = mock(RemoteDeviceHandler.class);
final NetconfConnectorDTO connectorDTO = remoteDeviceConnection.createDeviceCommunicator(NODE_ID, netconfNode, salFacade);
assertTrue(connectorDTO.getFacade() instanceof KeepaliveSalFacade);
}
use of org.opendaylight.netconf.topology.spi.NetconfConnectorDTO in project netconf by opendaylight.
the class TestingRemoteDeviceConnectorImpl method createDeviceCommunicator.
@Override
public NetconfConnectorDTO createDeviceCommunicator(final NodeId nodeId, final NetconfNode node, final RemoteDeviceHandler<NetconfSessionPreferences> salFacade) {
final NetconfConnectorDTO connectorDTO = new NetconfConnectorDTO(communicator, salFacade, List.of());
doReturn(FluentFutures.immediateNullFluentFuture()).when(communicator).initializeRemoteConnection(any(), any());
return connectorDTO;
}
use of org.opendaylight.netconf.topology.spi.NetconfConnectorDTO in project netconf by opendaylight.
the class NetconfTopologyImpl method close.
@Override
public void close() {
if (rpcReg != null) {
rpcReg.close();
rpcReg = null;
}
// close all existing connectors, delete whole topology in datastore?
for (final NetconfConnectorDTO connectorDTO : activeConnectors.values()) {
connectorDTO.close();
}
activeConnectors.clear();
if (datastoreListenerRegistration != null) {
datastoreListenerRegistration.close();
datastoreListenerRegistration = null;
}
}
use of org.opendaylight.netconf.topology.spi.NetconfConnectorDTO in project netconf by opendaylight.
the class RemoteDeviceConnectorImpl method createDeviceCommunicator.
@VisibleForTesting
NetconfConnectorDTO createDeviceCommunicator(final NodeId nodeId, final NetconfNode node, final RemoteDeviceHandler<NetconfSessionPreferences> deviceHandler) {
// setup default values since default value is not supported in mdsal
final long defaultRequestTimeoutMillis = node.getDefaultRequestTimeoutMillis() == null ? NetconfTopologyUtils.DEFAULT_REQUEST_TIMEOUT_MILLIS : node.getDefaultRequestTimeoutMillis().toJava();
final long keepaliveDelay = node.getKeepaliveDelay() == null ? NetconfTopologyUtils.DEFAULT_KEEPALIVE_DELAY : node.getKeepaliveDelay().toJava();
final boolean reconnectOnChangedSchema = node.getReconnectOnChangedSchema() == null ? NetconfTopologyUtils.DEFAULT_RECONNECT_ON_CHANGED_SCHEMA : node.getReconnectOnChangedSchema();
RemoteDeviceHandler<NetconfSessionPreferences> salFacade = requireNonNull(deviceHandler);
if (keepaliveDelay > 0) {
LOG.info("{}: Adding keepalive facade.", remoteDeviceId);
salFacade = new KeepaliveSalFacade(remoteDeviceId, salFacade, netconfTopologyDeviceSetup.getKeepaliveExecutor(), keepaliveDelay, defaultRequestTimeoutMillis);
}
final NetconfDevice.SchemaResourcesDTO schemaResourcesDTO = netconfTopologyDeviceSetup.getSchemaResourcesDTO();
// pre register yang library sources as fallback schemas to schema registry
final List<SchemaSourceRegistration<?>> registeredYangLibSources = new ArrayList<>();
if (node.getYangLibrary() != null) {
final String yangLibURL = node.getYangLibrary().getYangLibraryUrl().getValue();
final String yangLibUsername = node.getYangLibrary().getUsername();
final String yangLigPassword = node.getYangLibrary().getPassword();
final LibraryModulesSchemas libraryModulesSchemas;
if (yangLibURL != null) {
if (yangLibUsername != null && yangLigPassword != null) {
libraryModulesSchemas = LibraryModulesSchemas.create(yangLibURL, yangLibUsername, yangLigPassword);
} else {
libraryModulesSchemas = LibraryModulesSchemas.create(yangLibURL);
}
for (final Map.Entry<SourceIdentifier, URL> sourceIdentifierURLEntry : libraryModulesSchemas.getAvailableModels().entrySet()) {
registeredYangLibSources.add(schemaResourcesDTO.getSchemaRegistry().registerSchemaSource(new YangLibrarySchemaYangSourceProvider(remoteDeviceId, libraryModulesSchemas.getAvailableModels()), PotentialSchemaSource.create(sourceIdentifierURLEntry.getKey(), YangTextSchemaSource.class, PotentialSchemaSource.Costs.REMOTE_IO.getValue())));
}
}
}
final RemoteDevice<NetconfSessionPreferences, NetconfMessage, NetconfDeviceCommunicator> device;
if (node.getSchemaless()) {
device = new SchemalessNetconfDevice(netconfTopologyDeviceSetup.getBaseSchemas(), remoteDeviceId, salFacade);
} else {
device = new NetconfDeviceBuilder().setReconnectOnSchemasChange(reconnectOnChangedSchema).setSchemaResourcesDTO(schemaResourcesDTO).setGlobalProcessingExecutor(netconfTopologyDeviceSetup.getProcessingExecutor()).setBaseSchemas(netconfTopologyDeviceSetup.getBaseSchemas()).setId(remoteDeviceId).setDeviceActionFactory(deviceActionFactory).setSalFacade(salFacade).build();
}
final Optional<NetconfSessionPreferences> userCapabilities = getUserCapabilities(node);
final int rpcMessageLimit = node.getConcurrentRpcLimit() == null ? NetconfTopologyUtils.DEFAULT_CONCURRENT_RPC_LIMIT : node.getConcurrentRpcLimit().toJava();
if (rpcMessageLimit < 1) {
LOG.info("{}: Concurrent rpc limit is smaller than 1, no limit will be enforced.", remoteDeviceId);
}
NetconfDeviceCommunicator netconfDeviceCommunicator = userCapabilities.isPresent() ? new NetconfDeviceCommunicator(remoteDeviceId, device, new UserPreferences(userCapabilities.get(), node.getYangModuleCapabilities() == null ? false : node.getYangModuleCapabilities().getOverride(), node.getNonModuleCapabilities() == null ? false : node.getNonModuleCapabilities().getOverride()), rpcMessageLimit) : new NetconfDeviceCommunicator(remoteDeviceId, device, rpcMessageLimit);
if (salFacade instanceof KeepaliveSalFacade) {
((KeepaliveSalFacade) salFacade).setListener(netconfDeviceCommunicator);
}
return new NetconfConnectorDTO(netconfDeviceCommunicator, salFacade, registeredYangLibSources);
}
Aggregations