Search in sources :

Example 1 with LoginPasswordHandler

use of org.opendaylight.netconf.nettyutil.handler.ssh.authentication.LoginPasswordHandler in project netconf by opendaylight.

the class TestingNetconfClient method main.

public static void main(final String[] args) throws Exception {
    HashedWheelTimer hashedWheelTimer = new HashedWheelTimer();
    NioEventLoopGroup nettyGroup = new NioEventLoopGroup();
    NetconfClientDispatcherImpl netconfClientDispatcher = new NetconfClientDispatcherImpl(nettyGroup, nettyGroup, hashedWheelTimer);
    LoginPasswordHandler authHandler = new LoginPasswordHandler("admin", "admin");
    TestingNetconfClient client = new TestingNetconfClient("client", netconfClientDispatcher, getClientConfig("127.0.0.1", 1830, true, Optional.of(authHandler)));
    System.console().writer().println(client.getCapabilities());
}
Also used : LoginPasswordHandler(org.opendaylight.netconf.nettyutil.handler.ssh.authentication.LoginPasswordHandler) HashedWheelTimer(io.netty.util.HashedWheelTimer) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup)

Example 2 with LoginPasswordHandler

use of org.opendaylight.netconf.nettyutil.handler.ssh.authentication.LoginPasswordHandler in project netconf by opendaylight.

the class NetconfDeviceCommunicatorTest method testNetconfDeviceReconnectInCommunicator.

/**
 * Test whether reconnect is scheduled properly.
 */
@Test
public void testNetconfDeviceReconnectInCommunicator() {
    final RemoteDevice<NetconfSessionPreferences, NetconfMessage, NetconfDeviceCommunicator> device = mock(RemoteDevice.class);
    final TimedReconnectStrategy timedReconnectStrategy = new TimedReconnectStrategy(GlobalEventExecutor.INSTANCE, 10000, 0, 1.0, null, 100L, null);
    final ReconnectStrategy reconnectStrategy = spy(new ReconnectStrategy() {

        @Override
        @Deprecated
        public int getConnectTimeout() throws Exception {
            return timedReconnectStrategy.getConnectTimeout();
        }

        @Override
        @Deprecated
        public Future<Void> scheduleReconnect(final Throwable cause) {
            return timedReconnectStrategy.scheduleReconnect(cause);
        }

        @Override
        @Deprecated
        public void reconnectSuccessful() {
            timedReconnectStrategy.reconnectSuccessful();
        }
    });
    final EventLoopGroup group = new NioEventLoopGroup();
    final Timer time = new HashedWheelTimer();
    try {
        final NetconfDeviceCommunicator listener = new NetconfDeviceCommunicator(new RemoteDeviceId("test", InetSocketAddress.createUnresolved("localhost", 22)), device, 10);
        final NetconfReconnectingClientConfiguration cfg = NetconfReconnectingClientConfigurationBuilder.create().withAddress(new InetSocketAddress("localhost", 65000)).withReconnectStrategy(reconnectStrategy).withConnectStrategyFactory(() -> reconnectStrategy).withAuthHandler(new LoginPasswordHandler("admin", "admin")).withConnectionTimeoutMillis(10000).withProtocol(NetconfClientConfiguration.NetconfClientProtocol.SSH).withSessionListener(listener).build();
        listener.initializeRemoteConnection(new NetconfClientDispatcherImpl(group, group, time), cfg);
        verify(reconnectStrategy, timeout(TimeUnit.MINUTES.toMillis(4)).times(101)).scheduleReconnect(any(Throwable.class));
    } finally {
        time.stop();
        group.shutdownGracefully();
    }
}
Also used : TimedReconnectStrategy(org.opendaylight.netconf.nettyutil.TimedReconnectStrategy) ReconnectStrategy(org.opendaylight.netconf.nettyutil.ReconnectStrategy) InetSocketAddress(java.net.InetSocketAddress) HashedWheelTimer(io.netty.util.HashedWheelTimer) NetconfClientDispatcherImpl(org.opendaylight.netconf.client.NetconfClientDispatcherImpl) TimeoutException(java.util.concurrent.TimeoutException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) RemoteDeviceId(org.opendaylight.netconf.sal.connect.util.RemoteDeviceId) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) EventLoopGroup(io.netty.channel.EventLoopGroup) LoginPasswordHandler(org.opendaylight.netconf.nettyutil.handler.ssh.authentication.LoginPasswordHandler) HashedWheelTimer(io.netty.util.HashedWheelTimer) Timer(io.netty.util.Timer) NetconfMessage(org.opendaylight.netconf.api.NetconfMessage) TimedReconnectStrategy(org.opendaylight.netconf.nettyutil.TimedReconnectStrategy) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) ChannelFuture(io.netty.channel.ChannelFuture) Future(io.netty.util.concurrent.Future) NetconfReconnectingClientConfiguration(org.opendaylight.netconf.client.conf.NetconfReconnectingClientConfiguration) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) Test(org.junit.Test)

Example 3 with LoginPasswordHandler

use of org.opendaylight.netconf.nettyutil.handler.ssh.authentication.LoginPasswordHandler in project netconf by opendaylight.

the class StressClientCallable method getNetconfClientConfiguration.

private static NetconfClientConfiguration getNetconfClientConfiguration(final Parameters params, final NetconfDeviceCommunicator sessionListener) {
    final NetconfClientConfigurationBuilder netconfClientConfigurationBuilder = NetconfClientConfigurationBuilder.create();
    netconfClientConfigurationBuilder.withSessionListener(sessionListener);
    netconfClientConfigurationBuilder.withAddress(params.getInetAddress());
    if (params.tcpHeader != null) {
        final String header = params.tcpHeader.replaceAll("\"", "").trim() + "\n";
        netconfClientConfigurationBuilder.withAdditionalHeader(new NetconfHelloMessageAdditionalHeader(null, null, null, null, null) {

            @Override
            public String toFormattedString() {
                LOG.debug("Sending TCP header {}", header);
                return header;
            }
        });
    }
    netconfClientConfigurationBuilder.withProtocol(params.ssh ? NetconfClientConfiguration.NetconfClientProtocol.SSH : NetconfClientConfiguration.NetconfClientProtocol.TCP);
    netconfClientConfigurationBuilder.withAuthHandler(new LoginPasswordHandler(params.username, params.password));
    netconfClientConfigurationBuilder.withConnectionTimeoutMillis(20000L);
    netconfClientConfigurationBuilder.withReconnectStrategy(new NeverReconnectStrategy(GlobalEventExecutor.INSTANCE, 5000));
    return netconfClientConfigurationBuilder.build();
}
Also used : NetconfHelloMessageAdditionalHeader(org.opendaylight.netconf.api.messages.NetconfHelloMessageAdditionalHeader) LoginPasswordHandler(org.opendaylight.netconf.nettyutil.handler.ssh.authentication.LoginPasswordHandler) NeverReconnectStrategy(org.opendaylight.netconf.nettyutil.NeverReconnectStrategy) NetconfClientConfigurationBuilder(org.opendaylight.netconf.client.conf.NetconfClientConfigurationBuilder)

Example 4 with LoginPasswordHandler

use of org.opendaylight.netconf.nettyutil.handler.ssh.authentication.LoginPasswordHandler in project netconf by opendaylight.

the class SSHTest method connectClient.

public EchoClientHandler connectClient(final InetSocketAddress address) {
    final EchoClientHandler echoClientHandler = new EchoClientHandler();
    final ChannelInitializer<NioSocketChannel> channelInitializer = new ChannelInitializer<>() {

        @Override
        public void initChannel(final NioSocketChannel ch) throws Exception {
            ch.pipeline().addFirst(AsyncSshHandler.createForNetconfSubsystem(new LoginPasswordHandler("a", "a")));
            ch.pipeline().addLast(echoClientHandler);
        }
    };
    final Bootstrap b = new Bootstrap();
    b.group(nettyGroup).channel(NioSocketChannel.class).handler(channelInitializer);
    // Start the client.
    b.connect(address).addListener(echoClientHandler);
    return echoClientHandler;
}
Also used : NioSocketChannel(io.netty.channel.socket.nio.NioSocketChannel) LoginPasswordHandler(org.opendaylight.netconf.nettyutil.handler.ssh.authentication.LoginPasswordHandler) Bootstrap(io.netty.bootstrap.Bootstrap) ChannelInitializer(io.netty.channel.ChannelInitializer)

Aggregations

LoginPasswordHandler (org.opendaylight.netconf.nettyutil.handler.ssh.authentication.LoginPasswordHandler)4 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)2 HashedWheelTimer (io.netty.util.HashedWheelTimer)2 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1 Bootstrap (io.netty.bootstrap.Bootstrap)1 ChannelFuture (io.netty.channel.ChannelFuture)1 ChannelInitializer (io.netty.channel.ChannelInitializer)1 EventLoopGroup (io.netty.channel.EventLoopGroup)1 NioSocketChannel (io.netty.channel.socket.nio.NioSocketChannel)1 Timer (io.netty.util.Timer)1 Future (io.netty.util.concurrent.Future)1 InetSocketAddress (java.net.InetSocketAddress)1 TimeoutException (java.util.concurrent.TimeoutException)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 Test (org.junit.Test)1 NetconfMessage (org.opendaylight.netconf.api.NetconfMessage)1 NetconfHelloMessageAdditionalHeader (org.opendaylight.netconf.api.messages.NetconfHelloMessageAdditionalHeader)1 NetconfClientDispatcherImpl (org.opendaylight.netconf.client.NetconfClientDispatcherImpl)1 NetconfClientConfigurationBuilder (org.opendaylight.netconf.client.conf.NetconfClientConfigurationBuilder)1 NetconfReconnectingClientConfiguration (org.opendaylight.netconf.client.conf.NetconfReconnectingClientConfiguration)1