Search in sources :

Example 1 with YangLibrarySchemaYangSourceProvider

use of org.opendaylight.netconf.sal.connect.netconf.schema.YangLibrarySchemaYangSourceProvider in project netconf by opendaylight.

the class AbstractNetconfTopology method registerDeviceSchemaSources.

private List<SchemaSourceRegistration<?>> registerDeviceSchemaSources(final RemoteDeviceId remoteDeviceId, final NetconfNode node, final SchemaResourcesDTO resources) {
    final YangLibrary yangLibrary = node.getYangLibrary();
    if (yangLibrary != null) {
        final Uri uri = yangLibrary.getYangLibraryUrl();
        if (uri != null) {
            final List<SchemaSourceRegistration<?>> registrations = new ArrayList<>();
            final String yangLibURL = uri.getValue();
            final SchemaSourceRegistry schemaRegistry = resources.getSchemaRegistry();
            // pre register yang library sources as fallback schemas to schema registry
            final LibraryModulesSchemas schemas;
            final String yangLibUsername = yangLibrary.getUsername();
            final String yangLigPassword = yangLibrary.getPassword();
            if (yangLibUsername != null && yangLigPassword != null) {
                schemas = LibraryModulesSchemas.create(yangLibURL, yangLibUsername, yangLigPassword);
            } else {
                schemas = LibraryModulesSchemas.create(yangLibURL);
            }
            for (final Map.Entry<SourceIdentifier, URL> entry : schemas.getAvailableModels().entrySet()) {
                registrations.add(schemaRegistry.registerSchemaSource(new YangLibrarySchemaYangSourceProvider(remoteDeviceId, schemas.getAvailableModels()), PotentialSchemaSource.create(entry.getKey(), YangTextSchemaSource.class, PotentialSchemaSource.Costs.REMOTE_IO.getValue())));
            }
            return List.copyOf(registrations);
        }
    }
    return List.of();
}
Also used : YangLibrarySchemaYangSourceProvider(org.opendaylight.netconf.sal.connect.netconf.schema.YangLibrarySchemaYangSourceProvider) ArrayList(java.util.ArrayList) SourceIdentifier(org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier) YangLibrary(org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.netconf.schema.storage.YangLibrary) Uri(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri) URL(java.net.URL) LibraryModulesSchemas(org.opendaylight.netconf.sal.connect.netconf.LibraryModulesSchemas) SchemaSourceRegistration(org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceRegistration) SchemaSourceRegistry(org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceRegistry) Map(java.util.Map) HashMap(java.util.HashMap)

Example 2 with YangLibrarySchemaYangSourceProvider

use of org.opendaylight.netconf.sal.connect.netconf.schema.YangLibrarySchemaYangSourceProvider 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)

Example 3 with YangLibrarySchemaYangSourceProvider

use of org.opendaylight.netconf.sal.connect.netconf.schema.YangLibrarySchemaYangSourceProvider in project netconf by opendaylight.

the class DeviceSourcesResolver method call.

@Override
public DeviceSources call() {
    final NetconfDeviceSchemas availableSchemas = stateSchemasResolver.resolve(deviceRpc, remoteSessionCapabilities, id, baseSchema.getEffectiveModelContext());
    LOG.debug("{}: Schemas exposed by ietf-netconf-monitoring: {}", id, availableSchemas.getAvailableYangSchemasQNames());
    final Set<QName> requiredSources = Sets.newHashSet(remoteSessionCapabilities.getModuleBasedCaps());
    final Set<QName> providedSources = availableSchemas.getAvailableYangSchemasQNames();
    final Set<QName> requiredSourcesNotProvided = Sets.difference(requiredSources, providedSources);
    if (!requiredSourcesNotProvided.isEmpty()) {
        LOG.warn("{}: Netconf device does not provide all yang models reported in hello message capabilities," + " required but not provided: {}", id, requiredSourcesNotProvided);
        LOG.warn("{}: Attempting to build schema context from required sources", id);
    }
    // Here all the sources reported in netconf monitoring are merged with those reported in hello.
    // It is necessary to perform this since submodules are not mentioned in hello but still required.
    // This clashes with the option of a user to specify supported yang models manually in configuration
    // for netconf-connector and as a result one is not able to fully override yang models of a device.
    // It is only possible to add additional models.
    final Set<QName> providedSourcesNotRequired = Sets.difference(providedSources, requiredSources);
    if (!providedSourcesNotRequired.isEmpty()) {
        LOG.warn("{}: Netconf device provides additional yang models not reported in " + "hello message capabilities: {}", id, providedSourcesNotRequired);
        LOG.warn("{}: Adding provided but not required sources as required to prevent failures", id);
        LOG.debug("{}: Netconf device reported in hello: {}", id, requiredSources);
        requiredSources.addAll(providedSourcesNotRequired);
    }
    final SchemaSourceProvider<YangTextSchemaSource> sourceProvider;
    if (availableSchemas instanceof LibraryModulesSchemas) {
        sourceProvider = new YangLibrarySchemaYangSourceProvider(id, ((LibraryModulesSchemas) availableSchemas).getAvailableModels());
    } else {
        sourceProvider = new NetconfRemoteSchemaYangSourceProvider(id, deviceRpc);
    }
    return new DeviceSources(requiredSources, providedSources, sourceProvider);
}
Also used : YangTextSchemaSource(org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource) QName(org.opendaylight.yangtools.yang.common.QName) YangLibrarySchemaYangSourceProvider(org.opendaylight.netconf.sal.connect.netconf.schema.YangLibrarySchemaYangSourceProvider) NetconfDeviceSchemas(org.opendaylight.netconf.sal.connect.api.NetconfDeviceSchemas) NetconfRemoteSchemaYangSourceProvider(org.opendaylight.netconf.sal.connect.netconf.schema.NetconfRemoteSchemaYangSourceProvider)

Aggregations

YangLibrarySchemaYangSourceProvider (org.opendaylight.netconf.sal.connect.netconf.schema.YangLibrarySchemaYangSourceProvider)3 URL (java.net.URL)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 LibraryModulesSchemas (org.opendaylight.netconf.sal.connect.netconf.LibraryModulesSchemas)2 SourceIdentifier (org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier)2 SchemaSourceRegistration (org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceRegistration)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 HashMap (java.util.HashMap)1 NetconfMessage (org.opendaylight.netconf.api.NetconfMessage)1 NetconfDeviceSchemas (org.opendaylight.netconf.sal.connect.api.NetconfDeviceSchemas)1 NetconfDevice (org.opendaylight.netconf.sal.connect.netconf.NetconfDevice)1 NetconfDeviceBuilder (org.opendaylight.netconf.sal.connect.netconf.NetconfDeviceBuilder)1 SchemalessNetconfDevice (org.opendaylight.netconf.sal.connect.netconf.SchemalessNetconfDevice)1 NetconfDeviceCommunicator (org.opendaylight.netconf.sal.connect.netconf.listener.NetconfDeviceCommunicator)1 NetconfSessionPreferences (org.opendaylight.netconf.sal.connect.netconf.listener.NetconfSessionPreferences)1 UserPreferences (org.opendaylight.netconf.sal.connect.netconf.listener.UserPreferences)1 KeepaliveSalFacade (org.opendaylight.netconf.sal.connect.netconf.sal.KeepaliveSalFacade)1 NetconfRemoteSchemaYangSourceProvider (org.opendaylight.netconf.sal.connect.netconf.schema.NetconfRemoteSchemaYangSourceProvider)1 NetconfConnectorDTO (org.opendaylight.netconf.topology.spi.NetconfConnectorDTO)1