Fix checkstyle warnings for netconf-testtool
[controller.git] / opendaylight / netconf / netconf-testtool / src / main / java / org / opendaylight / controller / netconf / test / tool / NetconfDeviceSimulator.java
index e8ba769da547f552dc3fe47aaa9a6e3f35ad0d54..adcdea6073860b5f6b660faa356baf9cf7455df4 100644 (file)
@@ -68,6 +68,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;
@@ -193,15 +195,7 @@ 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));
                     sshWrappers.add(sshServer);
                 } catch (final Exception e) {
                     LOG.warn("Cannot start simulated device on {}, skipping", address, e);
@@ -255,6 +249,21 @@ public class NetconfDeviceSimulator implements Closeable {
         return openDevices;
     }
 
+    private SshProxyServerConfiguration getSshConfiguration(final InetSocketAddress bindingAddress, final LocalAddress tcpLocalAddress) 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(new PEMGeneratorHostKeyProvider(Files.createTempFile("prefix", "suffix").toAbsolutePath().toString()))
+                .setIdleTimeout(Integer.MAX_VALUE)
+                .createSshProxyServerConfiguration();
+    }
+
     private PEMGeneratorHostKeyProvider getPemGeneratorHostKeyProvider() {
         try {
             final Path tempFile = Files.createTempFile("tempKeyNetconfTest", "suffix");
@@ -295,15 +304,15 @@ public class NetconfDeviceSimulator implements Closeable {
 
         final Map<SourceIdentifier, Map.Entry<ASTSchemaSource, YangTextSchemaSource>> asts = Maps.newHashMap();
         for (final SourceIdentifier loadedSource : loadedSources) {
-                try {
-                    final CheckedFuture<ASTSchemaSource, SchemaSourceException> ast = consumer.getSchemaSource(loadedSource, ASTSchemaSource.class);
-                    final CheckedFuture<YangTextSchemaSource, SchemaSourceException> 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<ASTSchemaSource, SchemaSourceException> ast = consumer.getSchemaSource(loadedSource, ASTSchemaSource.class);
+                final CheckedFuture<YangTextSchemaSource, SchemaSourceException> 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);
     }