Search in sources :

Example 16 with NetconfClientSession

use of org.opendaylight.netconf.client.NetconfClientSession in project netconf by opendaylight.

the class CallHomeTlsSessionContext method doActivate.

private Promise<NetconfClientSession> doActivate(final Channel ch, final NetconfClientSessionListener listener) {
    final Promise<NetconfClientSession> activationPromise = newSessionPromise();
    if (activated.compareAndExchange(false, true)) {
        return activationPromise.setFailure(new IllegalStateException("Session (channel) already activated."));
    }
    LOG.info("Activating Netconf channel for {} with {}", getRemoteAddress(), listener);
    final NetconfClientSessionNegotiatorFactory negotiatorFactory = new NetconfClientSessionNegotiatorFactory(new HashedWheelTimer(), Optional.empty(), TimeUnit.SECONDS.toMillis(5));
    final TlsClientChannelInitializer tlsClientChannelInitializer = new TlsClientChannelInitializer(sslHandlerFactory, negotiatorFactory, listener);
    tlsClientChannelInitializer.initialize(ch, activationPromise);
    return activationPromise;
}
Also used : TlsClientChannelInitializer(org.opendaylight.netconf.client.TlsClientChannelInitializer) HashedWheelTimer(io.netty.util.HashedWheelTimer) NetconfClientSession(org.opendaylight.netconf.client.NetconfClientSession) NetconfClientSessionNegotiatorFactory(org.opendaylight.netconf.client.NetconfClientSessionNegotiatorFactory)

Example 17 with NetconfClientSession

use of org.opendaylight.netconf.client.NetconfClientSession in project netconf by opendaylight.

the class CallHomeMountDispatcherTest method noSessionIsCreatedWithoutAContextAvailableForAGivenAddress.

@Test
public void noSessionIsCreatedWithoutAContextAvailableForAGivenAddress() {
    // given
    final InetSocketAddress someAddress = InetSocketAddress.createUnresolved("1.2.3.4", 123);
    final NetconfClientConfiguration someCfg = someConfiguration(someAddress);
    // when
    final Future<NetconfClientSession> future = instance.createClient(someCfg);
    // then
    assertFalse(future.isSuccess());
}
Also used : NetconfClientConfiguration(org.opendaylight.netconf.client.conf.NetconfClientConfiguration) InetSocketAddress(java.net.InetSocketAddress) NetconfClientSession(org.opendaylight.netconf.client.NetconfClientSession) Test(org.junit.Test)

Example 18 with NetconfClientSession

use of org.opendaylight.netconf.client.NetconfClientSession in project netconf by opendaylight.

the class CallHomeMountSessionContextTest method activationOfListenerSupportsSessionDown.

@Test
public void activationOfListenerSupportsSessionDown() {
    // given
    when(mockActivator.activate(any(NetconfClientSessionListener.class))).thenAnswer(invocationOnMock -> {
        NetconfClientSession mockSession = mock(NetconfClientSession.class);
        Exception mockException = mock(Exception.class);
        Object arg = invocationOnMock.getArguments()[0];
        ((NetconfClientSessionListener) arg).onSessionDown(mockSession, mockException);
        return null;
    });
    // given
    NetconfClientSessionListener mockListener = mock(NetconfClientSessionListener.class);
    // when
    mockActivator.activate(mockListener);
    // then
    verify(mockListener, times(1)).onSessionDown(any(NetconfClientSession.class), any(Exception.class));
}
Also used : NetconfClientSessionListener(org.opendaylight.netconf.client.NetconfClientSessionListener) NetconfClientSession(org.opendaylight.netconf.client.NetconfClientSession) Test(org.junit.Test)

Aggregations

NetconfClientSession (org.opendaylight.netconf.client.NetconfClientSession)18 NetconfMessage (org.opendaylight.netconf.api.NetconfMessage)12 SimpleNetconfClientSessionListener (org.opendaylight.netconf.client.SimpleNetconfClientSessionListener)11 Test (org.junit.jupiter.api.Test)10 Test (org.junit.Test)5 NodeList (org.w3c.dom.NodeList)5 NetconfClientSessionListener (org.opendaylight.netconf.client.NetconfClientSessionListener)4 Element (org.w3c.dom.Element)4 HashedWheelTimer (io.netty.util.HashedWheelTimer)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 NetconfClientConfiguration (org.opendaylight.netconf.client.conf.NetconfClientConfiguration)2 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)1 DefaultThreadFactory (io.netty.util.concurrent.DefaultThreadFactory)1 InetSocketAddress (java.net.InetSocketAddress)1 BeforeAll (org.junit.jupiter.api.BeforeAll)1 NetconfTerminationReason (org.opendaylight.netconf.api.NetconfTerminationReason)1 NetconfClientDispatcherImpl (org.opendaylight.netconf.client.NetconfClientDispatcherImpl)1 NetconfClientSessionNegotiatorFactory (org.opendaylight.netconf.client.NetconfClientSessionNegotiatorFactory)1 TlsClientChannelInitializer (org.opendaylight.netconf.client.TlsClientChannelInitializer)1 Document (org.w3c.dom.Document)1