Search in sources :

Example 1 with Capability

use of org.opendaylight.netconf.api.capability.Capability in project netconf by opendaylight.

the class NetconfCapabilityMonitoringServiceTest method testOnCapabilitiesChanged.

@Test
public void testOnCapabilitiesChanged() throws Exception {
    final String capUri = "test";
    final Uri uri = new Uri(capUri);
    final HashSet<Capability> testCaps = new HashSet<>();
    testCaps.add(new BasicCapability(capUri));
    final ArgumentCaptor<NetconfCapabilityChange> capabilityChangeCaptor = ArgumentCaptor.forClass(NetconfCapabilityChange.class);
    final ArgumentCaptor<Capabilities> monitoringListenerCaptor = ArgumentCaptor.forClass(Capabilities.class);
    // add capability
    monitoringService.onCapabilitiesChanged(testCaps, Set.of());
    // remove capability
    monitoringService.onCapabilitiesChanged(Set.of(), testCaps);
    verify(listener, times(3)).onCapabilitiesChanged(monitoringListenerCaptor.capture());
    verify(notificationPublisher, times(2)).onCapabilityChanged(capabilityChangeCaptor.capture());
    // verify listener calls
    final List<Capabilities> listenerValues = monitoringListenerCaptor.getAllValues();
    final List<Uri> afterRegisterState = listenerValues.get(0).getCapability();
    final List<Uri> afterAddState = listenerValues.get(1).getCapability();
    final List<Uri> afterRemoveState = listenerValues.get(2).getCapability();
    assertEquals(capabilitiesSize, afterRegisterState.size());
    assertEquals(capabilitiesSize + 1, afterAddState.size());
    assertEquals(capabilitiesSize, afterRemoveState.size());
    assertFalse(afterRegisterState.contains(uri));
    assertTrue(afterAddState.contains(uri));
    assertFalse(afterRemoveState.contains(uri));
    // verify notification publication
    final List<NetconfCapabilityChange> publisherValues = capabilityChangeCaptor.getAllValues();
    final NetconfCapabilityChange afterAdd = publisherValues.get(0);
    final NetconfCapabilityChange afterRemove = publisherValues.get(1);
    assertEquals(Set.of(uri), Set.copyOf(afterAdd.getAddedCapability()));
    assertEquals(List.of(), afterAdd.getDeletedCapability());
    assertEquals(Set.of(uri), Set.copyOf(afterRemove.getDeletedCapability()));
    assertEquals(List.of(), afterRemove.getAddedCapability());
}
Also used : Capability(org.opendaylight.netconf.api.capability.Capability) BasicCapability(org.opendaylight.netconf.api.capability.BasicCapability) YangModuleCapability(org.opendaylight.netconf.api.capability.YangModuleCapability) BasicCapability(org.opendaylight.netconf.api.capability.BasicCapability) Uri(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri) Capabilities(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.netconf.state.Capabilities) NetconfCapabilityChange(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.NetconfCapabilityChange) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 2 with Capability

use of org.opendaylight.netconf.api.capability.Capability in project netconf by opendaylight.

the class NetconfDeviceSimulator method createDispatcher.

private NetconfServerDispatcherImpl createDispatcher(final Set<Capability> capabilities, final SchemaSourceProvider<YangTextSchemaSource> sourceProvider) {
    final Set<Capability> transformedCapabilities = new HashSet<>(Collections2.transform(capabilities, input -> {
        if (sendFakeSchema) {
            sendFakeSchema = false;
            return new FakeCapability((YangModuleCapability) input);
        } else {
            return input;
        }
    }));
    transformedCapabilities.add(new BasicCapability("urn:ietf:params:netconf:capability:candidate:1.0"));
    final NetconfMonitoringService monitoringService1 = new DummyMonitoringService(transformedCapabilities);
    final SessionIdProvider idProvider = new SessionIdProvider();
    final NetconfOperationServiceFactory aggregatedNetconfOperationServiceFactory = createOperationServiceFactory(sourceProvider, transformedCapabilities, monitoringService1, idProvider);
    final Set<String> serverCapabilities = configuration.getCapabilities();
    final NetconfServerSessionNegotiatorFactory serverNegotiatorFactory = new TesttoolNegotiationFactory(hashedWheelTimer, aggregatedNetconfOperationServiceFactory, idProvider, configuration.getGenerateConfigsTimeout(), monitoringService1, serverCapabilities);
    final ServerChannelInitializer serverChannelInitializer = new ServerChannelInitializer(serverNegotiatorFactory);
    return new NetconfServerDispatcherImpl(serverChannelInitializer, nettyThreadgroup, nettyThreadgroup);
}
Also used : Configuration(org.opendaylight.netconf.test.tool.config.Configuration) SettableOperationProvider(org.opendaylight.netconf.test.tool.customrpc.SettableOperationProvider) KeyPairProvider(org.opendaylight.netconf.shaded.sshd.common.keyprovider.KeyPairProvider) NetconfMonitoringOperationService(org.opendaylight.netconf.test.tool.monitoring.NetconfMonitoringOperationService) LoggerFactory(org.slf4j.LoggerFactory) Collections2(com.google.common.collect.Collections2) ThreadUtils(org.opendaylight.netconf.shaded.sshd.common.util.threads.ThreadUtils) SshProxyServerConfiguration(org.opendaylight.netconf.ssh.SshProxyServerConfiguration) LocalAddress(io.netty.channel.local.LocalAddress) ServerChannelInitializer(org.opendaylight.netconf.impl.ServerChannelInitializer) NetconfMonitoringService(org.opendaylight.netconf.api.monitoring.NetconfMonitoringService) SchemaSourceCache(org.opendaylight.netconf.test.tool.schemacache.SchemaSourceCache) Capability(org.opendaylight.netconf.api.capability.Capability) Module(org.opendaylight.yangtools.yang.model.api.Module) Set(java.util.Set) NetconfServerDispatcherImpl(org.opendaylight.netconf.impl.NetconfServerDispatcherImpl) DefaultOperationsCreator(org.opendaylight.netconf.test.tool.operations.DefaultOperationsCreator) YangModuleCapability(org.opendaylight.netconf.api.capability.YangModuleCapability) InetSocketAddress(java.net.InetSocketAddress) ModuleLike(org.opendaylight.yangtools.yang.model.api.ModuleLike) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) Executors(java.util.concurrent.Executors) SchemaSourceRepresentation(org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceRepresentation) List(java.util.List) SshProxyServerConfigurationBuilder(org.opendaylight.netconf.ssh.SshProxyServerConfigurationBuilder) Revision(org.opendaylight.yangtools.yang.common.Revision) PotentialSchemaSource(org.opendaylight.yangtools.yang.model.repo.spi.PotentialSchemaSource) HashedWheelTimer(io.netty.util.HashedWheelTimer) AsynchronousChannelGroup(java.nio.channels.AsynchronousChannelGroup) Optional(java.util.Optional) NetconfMonitoringOperationServiceFactory(org.opendaylight.netconf.test.tool.monitoring.NetconfMonitoringOperationServiceFactory) SshProxyServer(org.opendaylight.netconf.ssh.SshProxyServer) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings) ThreadFactoryBuilder(com.google.common.util.concurrent.ThreadFactoryBuilder) YangTextSchemaSource(org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource) OperationsProvider(org.opendaylight.netconf.test.tool.operations.OperationsProvider) SettableOperationRpcProvider(org.opendaylight.netconf.test.tool.rpchandler.SettableOperationRpcProvider) Submodule(org.opendaylight.yangtools.yang.model.api.Submodule) SharedSchemaRepository(org.opendaylight.yangtools.yang.parser.repo.SharedSchemaRepository) BindException(java.net.BindException) NetconfServerSessionNegotiatorFactory(org.opendaylight.netconf.impl.NetconfServerSessionNegotiatorFactory) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) SessionIdProvider(org.opendaylight.netconf.impl.SessionIdProvider) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) ExecutorService(java.util.concurrent.ExecutorService) SchemaSourceProvider(org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceProvider) AggregatedNetconfOperationServiceFactory(org.opendaylight.netconf.impl.osgi.AggregatedNetconfOperationServiceFactory) Logger(org.slf4j.Logger) SourceIdentifier(org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier) TextToIRTransformer(org.opendaylight.yangtools.yang.parser.rfc7950.repo.TextToIRTransformer) IOException(java.io.IOException) EffectiveModelContext(org.opendaylight.yangtools.yang.model.api.EffectiveModelContext) BasicCapability(org.opendaylight.netconf.api.capability.BasicCapability) Inet4Address(java.net.Inet4Address) UnknownHostException(java.net.UnknownHostException) ChannelFuture(io.netty.channel.ChannelFuture) Channel(io.netty.channel.Channel) ExecutionException(java.util.concurrent.ExecutionException) Futures(com.google.common.util.concurrent.Futures) RevisionSourceIdentifier(org.opendaylight.yangtools.yang.model.repo.api.RevisionSourceIdentifier) Closeable(java.io.Closeable) NetconfOperationServiceFactory(org.opendaylight.netconf.mapping.api.NetconfOperationServiceFactory) FilesystemSchemaSourceCache(org.opendaylight.yangtools.yang.model.repo.fs.FilesystemSchemaSourceCache) SchemaSourceListener(org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceListener) Capability(org.opendaylight.netconf.api.capability.Capability) YangModuleCapability(org.opendaylight.netconf.api.capability.YangModuleCapability) BasicCapability(org.opendaylight.netconf.api.capability.BasicCapability) SessionIdProvider(org.opendaylight.netconf.impl.SessionIdProvider) BasicCapability(org.opendaylight.netconf.api.capability.BasicCapability) YangModuleCapability(org.opendaylight.netconf.api.capability.YangModuleCapability) NetconfServerDispatcherImpl(org.opendaylight.netconf.impl.NetconfServerDispatcherImpl) AggregatedNetconfOperationServiceFactory(org.opendaylight.netconf.impl.osgi.AggregatedNetconfOperationServiceFactory) NetconfOperationServiceFactory(org.opendaylight.netconf.mapping.api.NetconfOperationServiceFactory) NetconfMonitoringService(org.opendaylight.netconf.api.monitoring.NetconfMonitoringService) NetconfServerSessionNegotiatorFactory(org.opendaylight.netconf.impl.NetconfServerSessionNegotiatorFactory) ServerChannelInitializer(org.opendaylight.netconf.impl.ServerChannelInitializer) HashSet(java.util.HashSet)

Example 3 with Capability

use of org.opendaylight.netconf.api.capability.Capability in project netconf by opendaylight.

the class NetconfDeviceSimulator method parseSchemasToModuleCapabilities.

private Set<Capability> parseSchemasToModuleCapabilities(final SharedSchemaRepository consumer) {
    final Set<SourceIdentifier> loadedSources = new HashSet<>();
    consumer.registerSchemaSourceListener(TextToIRTransformer.create(consumer, consumer));
    consumer.registerSchemaSourceListener(new SchemaSourceListener() {

        @Override
        public void schemaSourceEncountered(final SchemaSourceRepresentation schemaSourceRepresentation) {
        }

        @Override
        public void schemaSourceRegistered(final Iterable<PotentialSchemaSource<?>> potentialSchemaSources) {
            for (final PotentialSchemaSource<?> potentialSchemaSource : potentialSchemaSources) {
                loadedSources.add(potentialSchemaSource.getSourceIdentifier());
            }
        }

        @Override
        public void schemaSourceUnregistered(final PotentialSchemaSource<?> potentialSchemaSource) {
        }
    });
    if (configuration.getSchemasDir() != null) {
        LOG.info("Loading models from directory.");
        final FilesystemSchemaSourceCache<YangTextSchemaSource> cache = new FilesystemSchemaSourceCache<>(consumer, YangTextSchemaSource.class, configuration.getSchemasDir());
        consumer.registerSchemaSourceListener(cache);
    } else if (configuration.getModels() != null) {
        LOG.info("Loading models from classpath.");
        final SchemaSourceCache<YangTextSchemaSource> cache = new SchemaSourceCache<>(consumer, YangTextSchemaSource.class, configuration.getModels());
        consumer.registerSchemaSourceListener(cache);
    } else {
        LOG.info("Custom module loading skipped.");
    }
    configuration.getDefaultYangResources().forEach(r -> {
        final SourceIdentifier sourceIdentifier = RevisionSourceIdentifier.create(r.getModuleName(), Revision.ofNullable(r.getRevision()));
        registerSource(consumer, r.getResourcePath(), sourceIdentifier);
    });
    try {
        // necessary for creating mdsal data stores and operations
        this.schemaContext = consumer.createEffectiveModelContextFactory().createEffectiveModelContext(loadedSources).get();
    } catch (final InterruptedException | ExecutionException e) {
        throw new RuntimeException("Cannot parse schema context. " + "Please read stack trace and check YANG files in schema directory.", e);
    }
    final Set<Capability> capabilities = new HashSet<>();
    for (final Module module : schemaContext.getModules()) {
        for (final Submodule subModule : module.getSubmodules()) {
            addModuleCapability(consumer, capabilities, subModule);
        }
        addModuleCapability(consumer, capabilities, module);
    }
    return capabilities;
}
Also used : YangTextSchemaSource(org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource) Capability(org.opendaylight.netconf.api.capability.Capability) YangModuleCapability(org.opendaylight.netconf.api.capability.YangModuleCapability) BasicCapability(org.opendaylight.netconf.api.capability.BasicCapability) SchemaSourceCache(org.opendaylight.netconf.test.tool.schemacache.SchemaSourceCache) FilesystemSchemaSourceCache(org.opendaylight.yangtools.yang.model.repo.fs.FilesystemSchemaSourceCache) SourceIdentifier(org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier) RevisionSourceIdentifier(org.opendaylight.yangtools.yang.model.repo.api.RevisionSourceIdentifier) PotentialSchemaSource(org.opendaylight.yangtools.yang.model.repo.spi.PotentialSchemaSource) Submodule(org.opendaylight.yangtools.yang.model.api.Submodule) SchemaSourceRepresentation(org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceRepresentation) SchemaSourceListener(org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceListener) FilesystemSchemaSourceCache(org.opendaylight.yangtools.yang.model.repo.fs.FilesystemSchemaSourceCache) ExecutionException(java.util.concurrent.ExecutionException) Module(org.opendaylight.yangtools.yang.model.api.Module) HashSet(java.util.HashSet)

Example 4 with Capability

use of org.opendaylight.netconf.api.capability.Capability in project netconf by opendaylight.

the class NetconfCapabilityMonitoringServiceTest method testListeners.

@Test
public void testListeners() throws Exception {
    HashSet<Capability> added = new HashSet<>();
    added.add(new BasicCapability("toAdd"));
    monitoringService.onCapabilitiesChanged(added, Set.of());
    // onCapabilitiesChanged and onSchemasChanged are invoked also after listener registration
    verify(listener, times(2)).onCapabilitiesChanged(any());
    verify(listener, times(2)).onSchemasChanged(any());
}
Also used : Capability(org.opendaylight.netconf.api.capability.Capability) BasicCapability(org.opendaylight.netconf.api.capability.BasicCapability) YangModuleCapability(org.opendaylight.netconf.api.capability.YangModuleCapability) BasicCapability(org.opendaylight.netconf.api.capability.BasicCapability) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 5 with Capability

use of org.opendaylight.netconf.api.capability.Capability in project netconf by opendaylight.

the class NetconfCapabilityMonitoringServiceTest method testGetCapabilities.

@Test
public void testGetCapabilities() throws Exception {
    List<Uri> exp = new ArrayList<>();
    for (Capability capability : capabilities) {
        exp.add(new Uri(capability.getCapabilityUri()));
    }
    // candidate and url capabilities are added by monitoring service automatically
    exp.add(new Uri(URN_IETF_PARAMS_NETCONF_CAPABILITY_CANDIDATE_1_0));
    exp.add(new Uri(URN_IETF_PARAMS_NETCONF_CAPABILITY_URL_1_0));
    Capabilities expected = new CapabilitiesBuilder().setCapability(exp).build();
    Capabilities actual = monitoringService.getCapabilities();
    assertEquals(new HashSet<>(expected.getCapability()), new HashSet<>(actual.getCapability()));
}
Also used : Capability(org.opendaylight.netconf.api.capability.Capability) BasicCapability(org.opendaylight.netconf.api.capability.BasicCapability) YangModuleCapability(org.opendaylight.netconf.api.capability.YangModuleCapability) Capabilities(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.netconf.state.Capabilities) CapabilitiesBuilder(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.netconf.state.CapabilitiesBuilder) ArrayList(java.util.ArrayList) Uri(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri) Test(org.junit.Test)

Aggregations

Capability (org.opendaylight.netconf.api.capability.Capability)9 BasicCapability (org.opendaylight.netconf.api.capability.BasicCapability)8 YangModuleCapability (org.opendaylight.netconf.api.capability.YangModuleCapability)6 HashSet (java.util.HashSet)5 Test (org.junit.Test)4 ArrayList (java.util.ArrayList)3 ExecutionException (java.util.concurrent.ExecutionException)3 YangTextSchemaSource (org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource)3 ChannelFuture (io.netty.channel.ChannelFuture)2 LocalAddress (io.netty.channel.local.LocalAddress)2 IOException (java.io.IOException)2 BindException (java.net.BindException)2 InetSocketAddress (java.net.InetSocketAddress)2 AsynchronousChannelGroup (java.nio.channels.AsynchronousChannelGroup)2 SchemaSourceCache (org.opendaylight.netconf.test.tool.schemacache.SchemaSourceCache)2 Uri (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri)2 Module (org.opendaylight.yangtools.yang.model.api.Module)2 Submodule (org.opendaylight.yangtools.yang.model.api.Submodule)2 RevisionSourceIdentifier (org.opendaylight.yangtools.yang.model.repo.api.RevisionSourceIdentifier)2 SchemaSourceRepresentation (org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceRepresentation)2