Search in sources :

Example 1 with NetconfStartExiMessage

use of org.opendaylight.netconf.nettyutil.handler.exi.NetconfStartExiMessage 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 2 with NetconfStartExiMessage

use of org.opendaylight.netconf.nettyutil.handler.exi.NetconfStartExiMessage in project netconf by opendaylight.

the class NetconfClientSessionNegotiator method handleMessage.

@SuppressWarnings("checkstyle:IllegalCatch")
@Override
@SuppressFBWarnings("BC_UNCONFIRMED_CAST")
protected void handleMessage(final NetconfHelloMessage netconfMessage) throws NetconfDocumentedException {
    if (!ifNegotiatedAlready()) {
        LOG.debug("Server hello message received, starting negotiation on channel {}", channel);
        try {
            startNegotiation();
        } catch (final Exception e) {
            LOG.warn("Unexpected negotiation failure on channel {}", channel, e);
            negotiationFailed(e);
            return;
        }
    }
    final NetconfClientSession session = getSessionForHelloMessage(netconfMessage);
    replaceHelloMessageInboundHandler(session);
    // If exi should be used, try to initiate exi communication
    // Call negotiationSuccessFul after exi negotiation is finished successfully or not
    final NetconfMessage startExiMessage = sessionPreferences.getStartExiMessage();
    if (shouldUseExi(netconfMessage) && startExiMessage instanceof NetconfStartExiMessage) {
        LOG.debug("Netconf session {} should use exi.", session);
        tryToInitiateExi(session, (NetconfStartExiMessage) startExiMessage);
    } else {
        // Exi is not supported, release session immediately
        LOG.debug("Netconf session {} isn't capable of using exi.", session);
        negotiationSuccessful(session);
    }
}
Also used : NetconfStartExiMessage(org.opendaylight.netconf.nettyutil.handler.exi.NetconfStartExiMessage) NetconfMessage(org.opendaylight.netconf.api.NetconfMessage) NetconfDocumentedException(org.opendaylight.netconf.api.NetconfDocumentedException) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Aggregations

NetconfMessage (org.opendaylight.netconf.api.NetconfMessage)2 NetconfStartExiMessage (org.opendaylight.netconf.nettyutil.handler.exi.NetconfStartExiMessage)2 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)1 ChannelHandler (io.netty.channel.ChannelHandler)1 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)1 Test (org.junit.Test)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1 NetconfDocumentedException (org.opendaylight.netconf.api.NetconfDocumentedException)1 NetconfHelloMessage (org.opendaylight.netconf.api.messages.NetconfHelloMessage)1 Document (org.w3c.dom.Document)1