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=a5f49474742748f3bd3556a9689e9031f270d25f;hp=adcdea6073860b5f6b660faa356baf9cf7455df4;hb=4b207b5356775c4b4d231ae979f9f2134f617dd1;hpb=e773a75ec0a88fb88c3314f89ce92d951401e585 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 adcdea6073..a5f4947474 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; @@ -99,6 +100,8 @@ public class NetconfDeviceSimulator implements Closeable { private final ScheduledExecutorService minaTimerExecutor; private final ExecutorService nioExecutor; + private boolean sendFakeSchema = false; + public NetconfDeviceSimulator() { // TODO make pool size configurable this(new NioEventLoopGroup(), new HashedWheelTimer(), @@ -118,7 +121,12 @@ public class NetconfDeviceSimulator implements Closeable { final Set capabilities = Sets.newHashSet(Collections2.transform(moduleBuilders.keySet(), new Function() { @Override public Capability apply(final ModuleBuilder input) { - return new ModuleBuilderCapability(input, moduleBuilders.get(input)); + if (sendFakeSchema) { + sendFakeSchema = false; + return new FakeModuleBuilderCapability(input, moduleBuilders.get(input)); + } else { + return new ModuleBuilderCapability(input, moduleBuilders.get(input)); + } } })); @@ -185,6 +193,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; @@ -195,16 +207,19 @@ public class NetconfDeviceSimulator implements Closeable { server = dispatcher.createLocalServer(tcpLocalAddress); try { final SshProxyServer sshServer = new SshProxyServer(minaTimerExecutor, nettyThreadgroup, nioExecutor); - sshServer.bind(getSshConfiguration(bindingAddress, tcpLocalAddress)); + 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++; } @@ -242,6 +257,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); } @@ -249,7 +266,7 @@ public class NetconfDeviceSimulator implements Closeable { return openDevices; } - private SshProxyServerConfiguration getSshConfiguration(final InetSocketAddress bindingAddress, final LocalAddress tcpLocalAddress) throws IOException { + private SshProxyServerConfiguration getSshConfiguration(final InetSocketAddress bindingAddress, final LocalAddress tcpLocalAddress, final PEMGeneratorHostKeyProvider keyPairProvider) throws IOException { return new SshProxyServerConfigurationBuilder() .setBindingAddress(bindingAddress) .setLocalAddress(tcpLocalAddress) @@ -259,7 +276,7 @@ public class NetconfDeviceSimulator implements Closeable { return true; } }) - .setKeyPairProvider(new PEMGeneratorHostKeyProvider(Files.createTempFile("prefix", "suffix").toAbsolutePath().toString())) + .setKeyPairProvider(keyPairProvider) .setIdleTimeout(Integer.MAX_VALUE) .createSshProxyServerConfiguration(); } @@ -434,7 +451,9 @@ public class NetconfDeviceSimulator implements Closeable { final SimulatedEditConfig sEditConfig = new SimulatedEditConfig(String.valueOf(currentSessionId), storage); final SimulatedGetConfig sGetConfig = new SimulatedGetConfig(String.valueOf(currentSessionId), storage); final SimulatedCommit sCommit = new SimulatedCommit(String.valueOf(currentSessionId)); - return Sets.newHashSet(sGet, sGetConfig, sEditConfig, sCommit); + final SimulatedLock sLock = new SimulatedLock(String.valueOf(currentSessionId)); + final SimulatedUnLock sUnlock = new SimulatedUnLock(String.valueOf(currentSessionId)); + return Sets.newHashSet(sGet, sGetConfig, sEditConfig, sCommit, sLock, sUnlock); } @Override