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