Search in sources :

Example 6 with NetconfClientDispatcherImpl

use of org.opendaylight.netconf.client.NetconfClientDispatcherImpl 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 7 with NetconfClientDispatcherImpl

use of org.opendaylight.netconf.client.NetconfClientDispatcherImpl in project lighty-netconf-simulator by PANTHEONtech.

the class ToasterDeviceTest method setUpClass.

@BeforeAll
public static void setUpClass() {
    deviceSimulator = new Main();
    deviceSimulator.start(new String[] { DEVICE_SIMULATOR_PORT + "" }, false, false);
    nettyGroup = new NioEventLoopGroup(1, new DefaultThreadFactory(NetconfClientDispatcher.class));
    dispatcher = new NetconfClientDispatcherImpl(nettyGroup, nettyGroup, new HashedWheelTimer());
}
Also used : DefaultThreadFactory(io.netty.util.concurrent.DefaultThreadFactory) HashedWheelTimer(io.netty.util.HashedWheelTimer) NetconfClientDispatcherImpl(org.opendaylight.netconf.client.NetconfClientDispatcherImpl) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 8 with NetconfClientDispatcherImpl

use of org.opendaylight.netconf.client.NetconfClientDispatcherImpl in project lighty-netconf-simulator by PANTHEONtech.

the class DeviceTest method setUpClass.

@BeforeAll
public static void setUpClass() throws InterruptedException, ExecutionException, TimeoutException {
    deviceSimulator = new Main();
    deviceSimulator.start(new String[] { "--starting-port", String.valueOf(DEVICE_STARTING_PORT), "--thread-pool-size", String.valueOf(THREAD_POOL_SIZE), "--device-count", String.valueOf(DEVICE_COUNT) }, true, false);
    nettyGroup = new NioEventLoopGroup(THREAD_POOL_SIZE, new DefaultThreadFactory(NetconfClientDispatcher.class));
    NetconfClientDispatcherImpl dispatcher = new NetconfClientDispatcherImpl(nettyGroup, nettyGroup, new HashedWheelTimer());
    for (int port = DEVICE_STARTING_PORT; port < DEVICE_STARTING_PORT + DEVICE_COUNT; port++) {
        final SimpleNetconfClientSessionListener sessionListener = new SimpleNetconfClientSessionListener();
        NetconfClientSession session = dispatcher.createClient(createSHHConfig(sessionListener, port)).get(TimeoutUtil.TIMEOUT_MILLIS, TimeUnit.MILLISECONDS);
        NETCONF_CLIENT_SESSIONS.add(session);
        SESSION_LISTENERS.add(sessionListener);
    }
}
Also used : DefaultThreadFactory(io.netty.util.concurrent.DefaultThreadFactory) SimpleNetconfClientSessionListener(org.opendaylight.netconf.client.SimpleNetconfClientSessionListener) HashedWheelTimer(io.netty.util.HashedWheelTimer) NetconfClientDispatcherImpl(org.opendaylight.netconf.client.NetconfClientDispatcherImpl) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) NetconfClientSession(org.opendaylight.netconf.client.NetconfClientSession) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 9 with NetconfClientDispatcherImpl

use of org.opendaylight.netconf.client.NetconfClientDispatcherImpl in project lighty-netconf-simulator by PANTHEONtech.

the class DeviceTest method setUpClass.

@BeforeAll
public static void setUpClass() {
    deviceSimulator = new Main();
    deviceSimulator.start(new String[] { DEVICE_SIMULATOR_PORT + "" }, false, false);
    nettyGroup = new NioEventLoopGroup(1, new DefaultThreadFactory(NetconfClientDispatcher.class));
    dispatcher = new NetconfClientDispatcherImpl(nettyGroup, nettyGroup, new HashedWheelTimer());
}
Also used : DefaultThreadFactory(io.netty.util.concurrent.DefaultThreadFactory) HashedWheelTimer(io.netty.util.HashedWheelTimer) NetconfClientDispatcherImpl(org.opendaylight.netconf.client.NetconfClientDispatcherImpl) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) BeforeAll(org.junit.jupiter.api.BeforeAll)

Aggregations

NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)9 HashedWheelTimer (io.netty.util.HashedWheelTimer)9 NetconfClientDispatcherImpl (org.opendaylight.netconf.client.NetconfClientDispatcherImpl)9 DefaultThreadFactory (io.netty.util.concurrent.DefaultThreadFactory)6 BeforeAll (org.junit.jupiter.api.BeforeAll)5 ChannelFuture (io.netty.channel.ChannelFuture)2 Timer (io.netty.util.Timer)2 TimeoutException (java.util.concurrent.TimeoutException)2 NetconfMessage (org.opendaylight.netconf.api.NetconfMessage)2 Stopwatch (com.google.common.base.Stopwatch)1 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1 Main (io.lighty.netconf.device.notification.Main)1 EventLoopGroup (io.netty.channel.EventLoopGroup)1 Future (io.netty.util.concurrent.Future)1 IOException (java.io.IOException)1 InetSocketAddress (java.net.InetSocketAddress)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 ExecutionException (java.util.concurrent.ExecutionException)1 ExecutorService (java.util.concurrent.ExecutorService)1