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);
}
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;
}
Aggregations