Search in sources :

Example 6 with Capability

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

the class NetconfSessionMonitoringServiceTest method testListeners.

@Test
public void testListeners() {
    monitoringService.onSessionUp(sessionMock1);
    HashSet<Capability> added = new HashSet<>();
    added.add(new BasicCapability("toAdd"));
    monitoringService.onSessionDown(sessionMock1);
    verify(listener).onSessionStarted(any());
    verify(listener).onSessionEnded(any());
}
Also used : Capability(org.opendaylight.netconf.api.capability.Capability) BasicCapability(org.opendaylight.netconf.api.capability.BasicCapability) BasicCapability(org.opendaylight.netconf.api.capability.BasicCapability) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 7 with Capability

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

the class NetconfCapabilityMonitoringService method transformSchemas.

private static Schemas transformSchemas(final Set<Capability> caps) {
    final Map<SchemaKey, Schema> schemas = Maps.newHashMapWithExpectedSize(caps.size());
    for (final Capability cap : caps) {
        if (isValidModuleCapability(cap)) {
            final SchemaKey key = new SchemaKey(Yang.class, cap.getModuleName().get(), cap.getRevision().orElse(""));
            schemas.put(key, new SchemaBuilder().withKey(key).setNamespace(new Uri(cap.getModuleNamespace().get())).setLocation(transformLocations(cap.getLocation())).build());
        }
    }
    return new SchemasBuilder().setSchema(schemas).build();
}
Also used : Capability(org.opendaylight.netconf.api.capability.Capability) BasicCapability(org.opendaylight.netconf.api.capability.BasicCapability) Schema(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.netconf.state.schemas.Schema) SchemaBuilder(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.netconf.state.schemas.SchemaBuilder) SchemasBuilder(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.netconf.state.SchemasBuilder) SchemaKey(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.netconf.state.schemas.SchemaKey) Uri(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri)

Example 8 with Capability

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

the class NetconfDeviceSimulator method start.

public List<Integer> start() {
    LOG.info("Starting {}, {} simulated devices starting on port {}", configuration.getDeviceCount(), configuration.isSsh() ? "SSH" : "TCP", configuration.getStartingPort());
    final SharedSchemaRepository schemaRepo = new SharedSchemaRepository("netconf-simulator");
    final Set<Capability> capabilities = parseSchemasToModuleCapabilities(schemaRepo);
    final NetconfServerDispatcherImpl dispatcher = createDispatcher(capabilities, sourceIdentifier -> schemaRepo.getSchemaSource(sourceIdentifier, YangTextSchemaSource.class));
    int currentPort = configuration.getStartingPort();
    final List<Integer> openDevices = new ArrayList<>();
    // Generate key to temp folder
    final KeyPairProvider keyPairProvider = new VirtualKeyPairProvider();
    final AsynchronousChannelGroup group;
    try {
        group = AsynchronousChannelGroup.withThreadPool(nioExecutor);
    } catch (final IOException e) {
        throw new IllegalStateException("Failed to create group", e);
    }
    for (int i = 0; i < configuration.getDeviceCount(); i++) {
        if (currentPort > 65535) {
            LOG.warn("Port cannot be greater than 65535, stopping further attempts.");
            break;
        }
        final InetSocketAddress address = getAddress(configuration.getIp(), currentPort);
        final ChannelFuture server;
        if (configuration.isSsh()) {
            final InetSocketAddress bindingAddress = InetSocketAddress.createUnresolved("0.0.0.0", currentPort);
            final LocalAddress tcpLocalAddress = new LocalAddress(address.toString());
            server = dispatcher.createLocalServer(tcpLocalAddress);
            try {
                final SshProxyServer sshServer = new SshProxyServer(minaTimerExecutor, nettyThreadgroup, group);
                sshServer.bind(getSshConfiguration(bindingAddress, tcpLocalAddress, keyPairProvider));
                sshWrappers.add(sshServer);
            } catch (final BindException e) {
                LOG.warn("Cannot start simulated device on {}, port already in use. Skipping.", address);
                // Close local server and continue
                server.cancel(true);
                if (server.isDone()) {
                    server.channel().close();
                }
                continue;
            } catch (final IOException e) {
                LOG.warn("Cannot start simulated device on {} due to IOException.", address, e);
                break;
            } finally {
                currentPort++;
            }
            try {
                server.get();
            } catch (final InterruptedException e) {
                throw new RuntimeException(e);
            } catch (final ExecutionException e) {
                LOG.warn("Cannot start ssh simulated device on {}, skipping", address, e);
                continue;
            }
            LOG.debug("Simulated SSH device started on {}", address);
        } else {
            server = dispatcher.createServer(address);
            currentPort++;
            try {
                server.get();
            } catch (final InterruptedException e) {
                throw new RuntimeException(e);
            } catch (final ExecutionException e) {
                LOG.warn("Cannot start tcp simulated device on {}, skipping", address, e);
                continue;
            }
            LOG.debug("Simulated TCP device started on {}", server.channel().localAddress());
        }
        devicesChannels.add(server.channel());
        openDevices.add(currentPort - 1);
    }
    if (openDevices.size() == configuration.getDeviceCount()) {
        LOG.info("All simulated devices started successfully from port {} to {}", configuration.getStartingPort(), currentPort - 1);
    } else if (openDevices.size() == 0) {
        LOG.warn("No simulated devices started.");
    } else {
        LOG.warn("Not all simulated devices started successfully. Started devices ar on ports {}", openDevices);
    }
    return openDevices;
}
Also used : ChannelFuture(io.netty.channel.ChannelFuture) LocalAddress(io.netty.channel.local.LocalAddress) Capability(org.opendaylight.netconf.api.capability.Capability) YangModuleCapability(org.opendaylight.netconf.api.capability.YangModuleCapability) BasicCapability(org.opendaylight.netconf.api.capability.BasicCapability) YangTextSchemaSource(org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource) SshProxyServer(org.opendaylight.netconf.ssh.SshProxyServer) InetSocketAddress(java.net.InetSocketAddress) ArrayList(java.util.ArrayList) BindException(java.net.BindException) IOException(java.io.IOException) NetconfServerDispatcherImpl(org.opendaylight.netconf.impl.NetconfServerDispatcherImpl) KeyPairProvider(org.opendaylight.netconf.shaded.sshd.common.keyprovider.KeyPairProvider) AsynchronousChannelGroup(java.nio.channels.AsynchronousChannelGroup) ExecutionException(java.util.concurrent.ExecutionException) SharedSchemaRepository(org.opendaylight.yangtools.yang.parser.repo.SharedSchemaRepository)

Example 9 with Capability

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

the class CurrentSchemaContext method onModelContextUpdated.

@Override
public void onModelContextUpdated(final EffectiveModelContext schemaContext) {
    currentContext.set(schemaContext);
    // FIXME is notifying all the listeners from this callback wise ?
    final Set<Capability> addedCaps = MdsalNetconfOperationServiceFactory.transformCapabilities(currentContext.get(), rootSchemaSourceProvider);
    for (final CapabilityListener listener : listeners1) {
        listener.onCapabilitiesChanged(addedCaps, Collections.emptySet());
    }
}
Also used : Capability(org.opendaylight.netconf.api.capability.Capability) CapabilityListener(org.opendaylight.netconf.api.monitoring.CapabilityListener)

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