Search in sources :

Example 6 with NetconfHelloMessage

use of org.opendaylight.netconf.api.messages.NetconfHelloMessage in project netconf by opendaylight.

the class NetconfClientSessionNegotiatorTest method testNetconfClientSessionNegotiatorWithEXI.

@Test
public void testNetconfClientSessionNegotiatorWithEXI() throws Exception {
    Promise<NetconfClientSession> promise = mock(Promise.class);
    NetconfStartExiMessage exiMessage = NetconfStartExiMessage.create(EXIParameters.empty(), "msg-id");
    doReturn(promise).when(promise).setSuccess(any());
    NetconfClientSessionNegotiator negotiator = createNetconfClientSessionNegotiator(promise, exiMessage);
    negotiator.channelActive(null);
    Set<String> caps = Sets.newSet("exi:1.0");
    NetconfHelloMessage message = NetconfHelloMessage.createServerHello(caps, 10);
    doAnswer(invocationOnMock -> {
        channelInboundHandlerAdapter = invocationOnMock.getArgument(2);
        return null;
    }).when(pipeline).addAfter(anyString(), anyString(), any(ChannelHandler.class));
    ChannelHandlerContext handlerContext = mock(ChannelHandlerContext.class);
    doReturn(pipeline).when(handlerContext).pipeline();
    negotiator.handleMessage(message);
    Document expectedResult = XmlFileLoader.xmlFileToDocument("netconfMessages/rpc-reply_ok.xml");
    channelInboundHandlerAdapter.channelRead(handlerContext, new NetconfMessage(expectedResult));
    verify(promise).setSuccess(any());
    // two calls for exiMessage, 2 for hello message
    verify(pipeline, times(4)).replace(anyString(), anyString(), any(ChannelHandler.class));
}
Also used : NetconfStartExiMessage(org.opendaylight.netconf.nettyutil.handler.exi.NetconfStartExiMessage) NetconfMessage(org.opendaylight.netconf.api.NetconfMessage) NetconfHelloMessage(org.opendaylight.netconf.api.messages.NetconfHelloMessage) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ChannelHandler(io.netty.channel.ChannelHandler) Document(org.w3c.dom.Document) Test(org.junit.Test)

Example 7 with NetconfHelloMessage

use of org.opendaylight.netconf.api.messages.NetconfHelloMessage in project netconf by opendaylight.

the class NetconfClientSessionNegotiatorTest method testNetconfClientSessionNegotiator.

@Test
public void testNetconfClientSessionNegotiator() throws NetconfDocumentedException {
    Promise<NetconfClientSession> promise = mock(Promise.class);
    doReturn(promise).when(promise).setSuccess(any());
    NetconfClientSessionNegotiator negotiator = createNetconfClientSessionNegotiator(promise, null);
    negotiator.channelActive(null);
    Set<String> caps = Sets.newSet("a", "b");
    NetconfHelloMessage helloServerMessage = NetconfHelloMessage.createServerHello(caps, 10);
    negotiator.handleMessage(helloServerMessage);
    verify(promise).setSuccess(any());
}
Also used : NetconfHelloMessage(org.opendaylight.netconf.api.messages.NetconfHelloMessage) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 8 with NetconfHelloMessage

use of org.opendaylight.netconf.api.messages.NetconfHelloMessage in project netconf by opendaylight.

the class NetconfClientSessionNegotiatorTest method testNegotiatorWhenChannelActiveHappenAfterHandleMessage.

@Test
public void testNegotiatorWhenChannelActiveHappenAfterHandleMessage() throws Exception {
    Promise promise = mock(Promise.class);
    doReturn(false).when(promise).isDone();
    doReturn(promise).when(promise).setSuccess(any());
    NetconfClientSessionNegotiator negotiator = createNetconfClientSessionNegotiator(promise, null);
    Set<String> caps = Sets.newSet("a", "b");
    NetconfHelloMessage helloServerMessage = NetconfHelloMessage.createServerHello(caps, 10);
    negotiator.handleMessage(helloServerMessage);
    negotiator.channelActive(null);
    verify(promise).setSuccess(any());
}
Also used : ChannelPromise(io.netty.channel.ChannelPromise) ChannelProgressivePromise(io.netty.channel.ChannelProgressivePromise) Promise(io.netty.util.concurrent.Promise) NetconfHelloMessage(org.opendaylight.netconf.api.messages.NetconfHelloMessage) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 9 with NetconfHelloMessage

use of org.opendaylight.netconf.api.messages.NetconfHelloMessage in project netconf by opendaylight.

the class NetconfClientSessionNegotiatorFactory method getSessionNegotiator.

@Override
public NetconfClientSessionNegotiator getSessionNegotiator(final NetconfSessionListenerFactory<NetconfClientSessionListener> sessionListenerFactory, final Channel channel, final Promise<NetconfClientSession> promise) {
    NetconfMessage startExiMessage = NetconfStartExiMessage.create(options, START_EXI_MESSAGE_ID);
    NetconfHelloMessage helloMessage = NetconfHelloMessage.createClientHello(clientCapabilities, additionalHeader);
    NetconfClientSessionPreferences proposal = new NetconfClientSessionPreferences(helloMessage, startExiMessage);
    return new NetconfClientSessionNegotiator(proposal, promise, channel, timer, sessionListenerFactory.getSessionListener(), connectionTimeoutMillis);
}
Also used : NetconfClientSessionPreferences(org.opendaylight.netconf.api.NetconfClientSessionPreferences) NetconfMessage(org.opendaylight.netconf.api.NetconfMessage) NetconfHelloMessage(org.opendaylight.netconf.api.messages.NetconfHelloMessage)

Example 10 with NetconfHelloMessage

use of org.opendaylight.netconf.api.messages.NetconfHelloMessage in project netconf by opendaylight.

the class AbstractNetconfSessionNegotiator method start.

private void start() {
    final NetconfHelloMessage helloMessage = this.sessionPreferences.getHelloMessage();
    LOG.debug("Session negotiation started with hello message {} on channel {}", helloMessage, channel);
    channel.pipeline().addLast(NAME_OF_EXCEPTION_HANDLER, new ExceptionHandlingInboundChannelHandler());
    sendMessage(helloMessage);
    replaceHelloMessageOutboundHandler();
    changeState(State.OPEN_WAIT);
    timeoutTask = this.timer.newTimeout(this::timeoutExpired, connectionTimeoutMillis, TimeUnit.MILLISECONDS);
}
Also used : NetconfHelloMessage(org.opendaylight.netconf.api.messages.NetconfHelloMessage)

Aggregations

NetconfHelloMessage (org.opendaylight.netconf.api.messages.NetconfHelloMessage)14 Test (org.junit.Test)8 NetconfMessage (org.opendaylight.netconf.api.NetconfMessage)5 ByteBuf (io.netty.buffer.ByteBuf)4 Document (org.w3c.dom.Document)4 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)3 ArrayList (java.util.ArrayList)2 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 ChannelHandler (io.netty.channel.ChannelHandler)1 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)1 ChannelInboundHandlerAdapter (io.netty.channel.ChannelInboundHandlerAdapter)1 ChannelProgressivePromise (io.netty.channel.ChannelProgressivePromise)1 ChannelPromise (io.netty.channel.ChannelPromise)1 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)1 HashedWheelTimer (io.netty.util.HashedWheelTimer)1 Promise (io.netty.util.concurrent.Promise)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 Before (org.junit.Before)1