Search in sources :

Example 1 with KeepaliveSalFacade

use of org.opendaylight.netconf.sal.connect.netconf.sal.KeepaliveSalFacade 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);
}
Also used : NetconfNodeBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNodeBuilder) NetconfNode(org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNode) Node(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node) NetconfNode(org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNode) KeepaliveSalFacade(org.opendaylight.netconf.sal.connect.netconf.sal.KeepaliveSalFacade) Host(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Host) DefaultYangParserFactory(org.opendaylight.yangtools.yang.parser.impl.DefaultYangParserFactory) NetconfNodeBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNodeBuilder) NodeBuilder(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeBuilder) NetconfSessionPreferences(org.opendaylight.netconf.sal.connect.netconf.listener.NetconfSessionPreferences) NetconfConnectorDTO(org.opendaylight.netconf.topology.spi.NetconfConnectorDTO) LoginPasswordBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.netconf.node.credentials.credentials.LoginPasswordBuilder) IpAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress) PortNumber(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber) DefaultSchemaResourceManager(org.opendaylight.netconf.sal.connect.impl.DefaultSchemaResourceManager) Credentials(org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.netconf.node.credentials.Credentials) Ipv4Address(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address) Test(org.junit.Test)

Example 2 with KeepaliveSalFacade

use of org.opendaylight.netconf.sal.connect.netconf.sal.KeepaliveSalFacade in project netconf by opendaylight.

the class AbstractNetconfTopology method createDeviceCommunicator.

protected NetconfConnectorDTO createDeviceCommunicator(final NodeId nodeId, final NetconfNode node, final NetconfNodeAugmentedOptional nodeOptional) {
    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());
    } else {
        address = new InetSocketAddress(host.getDomainName().getValue(), node.getPort().getValue().toJava());
    }
    final RemoteDeviceId remoteDeviceId = new RemoteDeviceId(nodeId.getValue(), address);
    final long keepaliveDelay = node.requireKeepaliveDelay().toJava();
    RemoteDeviceHandler<NetconfSessionPreferences> salFacade = createSalFacade(remoteDeviceId);
    if (keepaliveDelay > 0) {
        LOG.info("Adding keepalive facade, for device {}", nodeId);
        salFacade = new KeepaliveSalFacade(remoteDeviceId, salFacade, this.keepaliveExecutor.getExecutor(), keepaliveDelay, node.requireDefaultRequestTimeoutMillis().toJava());
    }
    final RemoteDevice<NetconfSessionPreferences, NetconfMessage, NetconfDeviceCommunicator> device;
    final List<SchemaSourceRegistration<?>> yanglibRegistrations;
    if (node.requireSchemaless()) {
        device = new SchemalessNetconfDevice(baseSchemas, remoteDeviceId, salFacade);
        yanglibRegistrations = List.of();
    } else {
        final boolean reconnectOnChangedSchema = node.requireReconnectOnChangedSchema();
        final SchemaResourcesDTO resources = schemaManager.getSchemaResources(node, nodeId.getValue());
        device = new NetconfDeviceBuilder().setReconnectOnSchemasChange(reconnectOnChangedSchema).setSchemaResourcesDTO(resources).setGlobalProcessingExecutor(this.processingExecutor).setId(remoteDeviceId).setSalFacade(salFacade).setNode(node).setEventExecutor(eventExecutor).setNodeOptional(nodeOptional).setDeviceActionFactory(deviceActionFactory).setBaseSchemas(baseSchemas).build();
        yanglibRegistrations = registerDeviceSchemaSources(remoteDeviceId, node, resources);
    }
    final Optional<UserPreferences> userCapabilities = getUserCapabilities(node);
    final int rpcMessageLimit = node.requireConcurrentRpcLimit().toJava();
    if (rpcMessageLimit < 1) {
        LOG.info("Concurrent rpc limit is smaller than 1, no limit will be enforced for device {}", remoteDeviceId);
    }
    final NetconfDeviceCommunicator netconfDeviceCommunicator = userCapabilities.isPresent() ? new NetconfDeviceCommunicator(remoteDeviceId, device, userCapabilities.get(), rpcMessageLimit) : new NetconfDeviceCommunicator(remoteDeviceId, device, rpcMessageLimit);
    if (salFacade instanceof KeepaliveSalFacade) {
        ((KeepaliveSalFacade) salFacade).setListener(netconfDeviceCommunicator);
    }
    return new NetconfConnectorDTO(netconfDeviceCommunicator, salFacade, yanglibRegistrations);
}
Also used : UserPreferences(org.opendaylight.netconf.sal.connect.netconf.listener.UserPreferences) NetconfDeviceCommunicator(org.opendaylight.netconf.sal.connect.netconf.listener.NetconfDeviceCommunicator) InetSocketAddress(java.net.InetSocketAddress) KeepaliveSalFacade(org.opendaylight.netconf.sal.connect.netconf.sal.KeepaliveSalFacade) Host(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Host) NetconfSessionPreferences(org.opendaylight.netconf.sal.connect.netconf.listener.NetconfSessionPreferences) SchemaResourcesDTO(org.opendaylight.netconf.sal.connect.netconf.NetconfDevice.SchemaResourcesDTO) RemoteDeviceId(org.opendaylight.netconf.sal.connect.util.RemoteDeviceId) NetconfDeviceBuilder(org.opendaylight.netconf.sal.connect.netconf.NetconfDeviceBuilder) NetconfMessage(org.opendaylight.netconf.api.NetconfMessage) SchemaSourceRegistration(org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceRegistration) IpAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress) SchemalessNetconfDevice(org.opendaylight.netconf.sal.connect.netconf.SchemalessNetconfDevice)

Example 3 with KeepaliveSalFacade

use of org.opendaylight.netconf.sal.connect.netconf.sal.KeepaliveSalFacade 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);
}
Also used : UserPreferences(org.opendaylight.netconf.sal.connect.netconf.listener.UserPreferences) ArrayList(java.util.ArrayList) KeepaliveSalFacade(org.opendaylight.netconf.sal.connect.netconf.sal.KeepaliveSalFacade) NetconfSessionPreferences(org.opendaylight.netconf.sal.connect.netconf.listener.NetconfSessionPreferences) URL(java.net.URL) NetconfDevice(org.opendaylight.netconf.sal.connect.netconf.NetconfDevice) SchemalessNetconfDevice(org.opendaylight.netconf.sal.connect.netconf.SchemalessNetconfDevice) NetconfDeviceCommunicator(org.opendaylight.netconf.sal.connect.netconf.listener.NetconfDeviceCommunicator) YangLibrarySchemaYangSourceProvider(org.opendaylight.netconf.sal.connect.netconf.schema.YangLibrarySchemaYangSourceProvider) SourceIdentifier(org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier) NetconfConnectorDTO(org.opendaylight.netconf.topology.spi.NetconfConnectorDTO) NetconfDeviceBuilder(org.opendaylight.netconf.sal.connect.netconf.NetconfDeviceBuilder) NetconfMessage(org.opendaylight.netconf.api.NetconfMessage) LibraryModulesSchemas(org.opendaylight.netconf.sal.connect.netconf.LibraryModulesSchemas) SchemaSourceRegistration(org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceRegistration) SchemalessNetconfDevice(org.opendaylight.netconf.sal.connect.netconf.SchemalessNetconfDevice) Map(java.util.Map) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

NetconfSessionPreferences (org.opendaylight.netconf.sal.connect.netconf.listener.NetconfSessionPreferences)3 KeepaliveSalFacade (org.opendaylight.netconf.sal.connect.netconf.sal.KeepaliveSalFacade)3 NetconfMessage (org.opendaylight.netconf.api.NetconfMessage)2 NetconfDeviceBuilder (org.opendaylight.netconf.sal.connect.netconf.NetconfDeviceBuilder)2 SchemalessNetconfDevice (org.opendaylight.netconf.sal.connect.netconf.SchemalessNetconfDevice)2 NetconfDeviceCommunicator (org.opendaylight.netconf.sal.connect.netconf.listener.NetconfDeviceCommunicator)2 UserPreferences (org.opendaylight.netconf.sal.connect.netconf.listener.UserPreferences)2 NetconfConnectorDTO (org.opendaylight.netconf.topology.spi.NetconfConnectorDTO)2 Host (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Host)2 IpAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress)2 SchemaSourceRegistration (org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceRegistration)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 InetSocketAddress (java.net.InetSocketAddress)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 Test (org.junit.Test)1 DefaultSchemaResourceManager (org.opendaylight.netconf.sal.connect.impl.DefaultSchemaResourceManager)1 LibraryModulesSchemas (org.opendaylight.netconf.sal.connect.netconf.LibraryModulesSchemas)1 NetconfDevice (org.opendaylight.netconf.sal.connect.netconf.NetconfDevice)1