super(sessionPreferences, promise, channel, timer, sessionListener, connectionTimeoutMillis);
}
+ @SuppressWarnings("checkstyle:IllegalCatch")
@Override
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", e);
+ negotiationFailed(e);
+ return;
+ }
+ }
final NetconfClientSession session = getSessionForHelloMessage(netconfMessage);
replaceHelloMessageInboundHandler(session);
verify(promise).setSuccess(anyObject());
}
+ @Test
+ public void testNegotiatorWhenChannelActiveHappenAfterHandleMessage() throws Exception {
+ Promise promise = mock(Promise.class);
+ doReturn(false).when(promise).isDone();
+ doReturn(promise).when(promise).setSuccess(anyObject());
+ 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(anyObject());
+ }
+
+
@Test
public void testNetconfClientSessionNegotiatorWithEXI() throws Exception {
Promise<NetconfClientSession> promise = mock(Promise.class);
@Override
protected final void startNegotiation() {
- final Optional<SslHandler> sslHandler = getSslHandler(channel);
- if (sslHandler.isPresent()) {
- Future<Channel> future = sslHandler.get().handshakeFuture();
- future.addListener(new GenericFutureListener<Future<? super Channel>>() {
- @Override
- public void operationComplete(final Future<? super Channel> future) {
- Preconditions.checkState(future.isSuccess(), "Ssl handshake was not successful");
- LOG.debug("Ssl handshake complete");
- start();
- }
- });
+ if (ifNegotiatedAlready()) {
+ LOG.debug("Negotiation on channel {} already started", channel);
} else {
- start();
+ final Optional<SslHandler> sslHandler = getSslHandler(channel);
+ if (sslHandler.isPresent()) {
+ Future<Channel> future = sslHandler.get().handshakeFuture();
+ future.addListener(new GenericFutureListener<Future<? super Channel>>() {
+ @Override
+ public void operationComplete(final Future<? super Channel> future) {
+ Preconditions.checkState(future.isSuccess(), "Ssl handshake was not successful");
+ LOG.debug("Ssl handshake complete");
+ start();
+ }
+ });
+ } else {
+ start();
+ }
}
}
+ protected final boolean ifNegotiatedAlready() {
+ // Indicates whether negotiation already started
+ return this.state != State.IDLE;
+ }
+
private static Optional<SslHandler> getSslHandler(final Channel channel) {
final SslHandler sslHandler = channel.pipeline().get(SslHandler.class);
return sslHandler == null ? Optional.<SslHandler>absent() : Optional.of(sslHandler);