X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fnetconf%2Fnetconf-testtool%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fnetconf%2Ftest%2Ftool%2FNetconfDeviceSimulator.java;h=287ff2dca77a60a4a8f3cac0569c96fad233aac4;hp=e8ba769da547f552dc3fe47aaa9a6e3f35ad0d54;hb=26d2f331053e05d830c74196fb46b90379e47492;hpb=720b039093db2268d6dfeed364e685d34d6c62bf diff --git a/opendaylight/netconf/netconf-testtool/src/main/java/org/opendaylight/controller/netconf/test/tool/NetconfDeviceSimulator.java b/opendaylight/netconf/netconf-testtool/src/main/java/org/opendaylight/controller/netconf/test/tool/NetconfDeviceSimulator.java index e8ba769da5..287ff2dca7 100644 --- a/opendaylight/netconf/netconf-testtool/src/main/java/org/opendaylight/controller/netconf/test/tool/NetconfDeviceSimulator.java +++ b/opendaylight/netconf/netconf-testtool/src/main/java/org/opendaylight/controller/netconf/test/tool/NetconfDeviceSimulator.java @@ -30,6 +30,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.lang.management.ManagementFactory; +import java.net.BindException; import java.net.Inet4Address; import java.net.InetSocketAddress; import java.net.URI; @@ -68,6 +69,8 @@ import org.opendaylight.controller.netconf.mapping.api.NetconfOperationService; import org.opendaylight.controller.netconf.mapping.api.NetconfOperationServiceSnapshot; import org.opendaylight.controller.netconf.monitoring.osgi.NetconfMonitoringOperationService; import org.opendaylight.controller.netconf.ssh.SshProxyServer; +import org.opendaylight.controller.netconf.ssh.SshProxyServerConfiguration; +import org.opendaylight.controller.netconf.ssh.SshProxyServerConfigurationBuilder; import org.opendaylight.yangtools.yang.model.api.SchemaContext; import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceException; import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceRepresentation; @@ -183,6 +186,10 @@ public class NetconfDeviceSimulator implements Closeable { final PEMGeneratorHostKeyProvider keyPairProvider = getPemGeneratorHostKeyProvider(); for (int i = 0; i < params.deviceCount; i++) { + if (currentPort > 65535) { + LOG.warn("Port cannot be greater than 65535, stopping further attempts."); + break; + } final InetSocketAddress address = getAddress(currentPort); final ChannelFuture server; @@ -193,24 +200,19 @@ public class NetconfDeviceSimulator implements Closeable { server = dispatcher.createLocalServer(tcpLocalAddress); try { final SshProxyServer sshServer = new SshProxyServer(minaTimerExecutor, nettyThreadgroup, nioExecutor); - sshServer.bind(bindingAddress, tcpLocalAddress, - new PasswordAuthenticator() { - @Override - public boolean authenticate(final String username, final String password, final ServerSession session) { - // All connections are accepted - return true; - } - }, keyPairProvider); - + sshServer.bind(getSshConfiguration(bindingAddress, tcpLocalAddress, keyPairProvider)); sshWrappers.add(sshServer); - } catch (final Exception e) { - LOG.warn("Cannot start simulated device on {}, skipping", address, e); + } 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++; } @@ -248,6 +250,8 @@ public class NetconfDeviceSimulator implements Closeable { if(openDevices.size() == params.deviceCount) { LOG.info("All simulated devices started successfully from port {} to {}", params.startingPort, 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); } @@ -255,6 +259,21 @@ public class NetconfDeviceSimulator implements Closeable { return openDevices; } + private SshProxyServerConfiguration getSshConfiguration(final InetSocketAddress bindingAddress, final LocalAddress tcpLocalAddress, final PEMGeneratorHostKeyProvider keyPairProvider) throws IOException { + return new SshProxyServerConfigurationBuilder() + .setBindingAddress(bindingAddress) + .setLocalAddress(tcpLocalAddress) + .setAuthenticator(new PasswordAuthenticator() { + @Override + public boolean authenticate(final String username, final String password, final ServerSession session) { + return true; + } + }) + .setKeyPairProvider(keyPairProvider) + .setIdleTimeout(Integer.MAX_VALUE) + .createSshProxyServerConfiguration(); + } + private PEMGeneratorHostKeyProvider getPemGeneratorHostKeyProvider() { try { final Path tempFile = Files.createTempFile("tempKeyNetconfTest", "suffix"); @@ -295,15 +314,15 @@ public class NetconfDeviceSimulator implements Closeable { final Map> asts = Maps.newHashMap(); for (final SourceIdentifier loadedSource : loadedSources) { - try { - final CheckedFuture ast = consumer.getSchemaSource(loadedSource, ASTSchemaSource.class); - final CheckedFuture text = consumer.getSchemaSource(loadedSource, YangTextSchemaSource.class); - asts.put(loadedSource, new AbstractMap.SimpleEntry<>(ast.get(), text.get())); - } catch (final InterruptedException e) { - throw new RuntimeException(e); - } catch (final ExecutionException e) { - throw new RuntimeException("Cannot parse schema context", e); - } + try { + final CheckedFuture ast = consumer.getSchemaSource(loadedSource, ASTSchemaSource.class); + final CheckedFuture text = consumer.getSchemaSource(loadedSource, YangTextSchemaSource.class); + asts.put(loadedSource, new AbstractMap.SimpleEntry<>(ast.get(), text.get())); + } catch (final InterruptedException e) { + throw new RuntimeException(e); + } catch (final ExecutionException e) { + throw new RuntimeException("Cannot parse schema context", e); + } } return toModuleBuilders(asts); }