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));
}
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);
}
}
Aggregations