Search in sources :

Example 1 with SshProxyServerConfigurationBuilder

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();
    }
}
Also used : SshProxyServer(org.opendaylight.netconf.ssh.SshProxyServer) SshProxyServerConfigurationBuilder(org.opendaylight.netconf.ssh.SshProxyServerConfigurationBuilder) InetSocketAddress(java.net.InetSocketAddress) Stopwatch(com.google.common.base.Stopwatch) File(java.io.File) Test(org.junit.Test)

Example 2 with SshProxyServerConfigurationBuilder

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);
}
Also used : SshProxyServer(org.opendaylight.netconf.ssh.SshProxyServer) SshProxyServerConfigurationBuilder(org.opendaylight.netconf.ssh.SshProxyServerConfigurationBuilder) InetSocketAddress(java.net.InetSocketAddress) Before(org.junit.Before)

Aggregations

InetSocketAddress (java.net.InetSocketAddress)2 SshProxyServer (org.opendaylight.netconf.ssh.SshProxyServer)2 SshProxyServerConfigurationBuilder (org.opendaylight.netconf.ssh.SshProxyServerConfigurationBuilder)2 Stopwatch (com.google.common.base.Stopwatch)1 File (java.io.File)1 Before (org.junit.Before)1 Test (org.junit.Test)1