- 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, nioExecutor);
- 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 {}", address);
- }
-
- devicesChannels.add(server.channel());
- openDevices.add(currentPort - 1);