Search in sources :

Example 1 with NetconfServerDispatcherImpl

use of org.opendaylight.netconf.impl.NetconfServerDispatcherImpl 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 2 with NetconfServerDispatcherImpl

use of org.opendaylight.netconf.impl.NetconfServerDispatcherImpl 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)

Aggregations

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 ArrayList (java.util.ArrayList)2 ExecutionException (java.util.concurrent.ExecutionException)2 BasicCapability (org.opendaylight.netconf.api.capability.BasicCapability)2 Capability (org.opendaylight.netconf.api.capability.Capability)2 YangModuleCapability (org.opendaylight.netconf.api.capability.YangModuleCapability)2 NetconfServerDispatcherImpl (org.opendaylight.netconf.impl.NetconfServerDispatcherImpl)2 KeyPairProvider (org.opendaylight.netconf.shaded.sshd.common.keyprovider.KeyPairProvider)2 SshProxyServer (org.opendaylight.netconf.ssh.SshProxyServer)2 Collections2 (com.google.common.collect.Collections2)1 Futures (com.google.common.util.concurrent.Futures)1 ThreadFactoryBuilder (com.google.common.util.concurrent.ThreadFactoryBuilder)1 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)1 Channel (io.netty.channel.Channel)1 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)1