use of org.opendaylight.netconf.ssh.SshProxyServerConfigurationBuilder in project netconf by opendaylight.
the class SSHTest method test.
@Test
public void test() throws Exception {
File sshKeyPair = Files.createTempFile("sshKeyPair", ".pem").toFile();
sshKeyPair.deleteOnExit();
new Thread(new EchoServer(), "EchoServer").start();
final InetSocketAddress addr = new InetSocketAddress("127.0.0.1", 10831);
final SshProxyServer sshProxyServer = new SshProxyServer(minaTimerEx, nettyGroup, nioExec);
sshProxyServer.bind(new SshProxyServerConfigurationBuilder().setBindingAddress(addr).setLocalAddress(NetconfConfiguration.NETCONF_LOCAL_ADDRESS).setAuthenticator((username, password) -> true).setKeyPairProvider(SecurityUtils.createGeneratorHostKeyProvider(sshKeyPair.toPath())).setIdleTimeout(Integer.MAX_VALUE).createSshProxyServerConfiguration());
final EchoClientHandler echoClientHandler = connectClient(addr);
Stopwatch stopwatch = Stopwatch.createStarted();
while (echoClientHandler.isConnected() == false && stopwatch.elapsed(TimeUnit.SECONDS) < 30) {
Thread.sleep(500);
}
assertTrue(echoClientHandler.isConnected());
LOG.info("connected, writing to client");
echoClientHandler.write(AHOJ);
// check that server sent back the same string
stopwatch = stopwatch.reset().start();
while (echoClientHandler.read().endsWith(AHOJ) == false && stopwatch.elapsed(TimeUnit.SECONDS) < 30) {
Thread.sleep(500);
}
try {
final String read = echoClientHandler.read();
assertTrue(read + " should end with " + AHOJ, read.endsWith(AHOJ));
} finally {
LOG.info("Closing socket");
sshProxyServer.close();
}
}
use of org.opendaylight.netconf.ssh.SshProxyServerConfigurationBuilder in project netconf by opendaylight.
the class SSHServerTest method setUp.
@Before
public void setUp() throws Exception {
sshKeyPair = Files.createTempFile("sshKeyPair", ".pem").toFile();
sshKeyPair.deleteOnExit();
LOG.info("Creating SSH server");
final InetSocketAddress addr = InetSocketAddress.createUnresolved(HOST, PORT);
server = new SshProxyServer(minaTimerEx, clientGroup, nioExec);
server.bind(new SshProxyServerConfigurationBuilder().setBindingAddress(addr).setLocalAddress(NetconfConfiguration.NETCONF_LOCAL_ADDRESS).setAuthenticator((username, password) -> true).setKeyPairProvider(SecurityUtils.createGeneratorHostKeyProvider(sshKeyPair.toPath())).setIdleTimeout(Integer.MAX_VALUE).createSshProxyServerConfiguration());
LOG.info("SSH server started on {}", PORT);
}
Aggregations