public void disconnect() { if(session != null) { session.close(); } }
@Override protected void addExiHandlers(final ByteToMessageDecoder decoder, final MessageToByteEncoder<NetconfMessage> encoder) { // TODO used only in negotiator, client supports only auto start-exi replaceMessageDecoder(decoder); replaceMessageEncoder(encoder); }
@GuardedBy("this") private void dispatchRequest() { while (!requests.isEmpty()) { final RequestEntry e = requests.peek(); if (e.promise.setUncancellable()) { LOG.debug("Sending message {}", e.request); clientSession.sendMessage(e.request); break; } LOG.debug("Message {} has been cancelled, skipping it", e.request); requests.poll(); } }
public static NetconfSessionPreferences fromNetconfSession(final NetconfClientSession session) { return fromStrings(session.getServerCapabilities()); }
@Override public void channelRead(final ChannelHandlerContext ctx, final Object msg) throws Exception { ctx.pipeline().remove(ExiConfirmationInboundHandler.EXI_CONFIRMED_HANDLER); NetconfMessage netconfMessage = (NetconfMessage) msg; // Ok response to start-exi, try to add exi handlers if (NetconfMessageUtil.isOKMessage(netconfMessage)) { LOG.trace("Positive response on start-exi call received on session {}", session); try { session.startExiCommunication(startExiMessage); } catch (RuntimeException e) { // Unable to add exi, continue without exi LOG.warn("Unable to start exi communication, Communication will continue without exi on session {}", session, e); } // Error response } else if(NetconfMessageUtil.isErrorMessage(netconfMessage)) { LOG.warn( "Error response to start-exi message {}, Communication will continue without exi on session {}", netconfMessage, session); // Unexpected response to start-exi, throwing message away, continue without exi } else { LOG.warn("Unexpected response to start-exi message, should be ok, was {}, " + "Communication will continue without exi and response message will be thrown away on session {}", netconfMessage, session); } negotiationSuccessful(session); } }
@Override protected NetconfClientSession getSession(final NetconfClientSessionListener sessionListener, final Channel channel, final NetconfHelloMessage message) throws NetconfDocumentedException { long sessionId = extractSessionId(message.getDocument()); // Copy here is important: it disconnects the strings from the document Collection<String> capabilities = ImmutableList.copyOf(NetconfMessageUtil.extractCapabilitiesFromHello(message.getDocument())); // FIXME: scalability: we could instantiate a cache to share the same collections return new NetconfClientSession(sessionListener, channel, sessionId, capabilities); }
/** * Initiates exi communication by sending start-exi message and waiting for positive/negative response. * * @param startExiMessage */ void tryToInitiateExi(final NetconfClientSession session, final NetconfStartExiMessage startExiMessage) { channel.pipeline().addAfter(AbstractChannelInitializer.NETCONF_MESSAGE_DECODER, ExiConfirmationInboundHandler.EXI_CONFIRMED_HANDLER, new ExiConfirmationInboundHandler(session, startExiMessage)); session.sendMessage(startExiMessage).addListener(new ChannelFutureListener() { @Override public void operationComplete(final ChannelFuture f) { if (!f.isSuccess()) { LOG.warn("Failed to send start-exi message {} on session {}", startExiMessage, this, f.cause()); channel.pipeline().remove(ExiConfirmationInboundHandler.EXI_CONFIRMED_HANDLER); } else { LOG.trace("Start-exi message {} sent to socket on session {}", startExiMessage, this); } } }); }
@Override public Boolean call() throws Exception { executionStrategy.invoke(); netconfClientSession.close(); return true; }
requests.add(req); session.sendMessage(req.request).addListener(new FutureListener<Void>() { @Override public void operationComplete(final Future<Void> future) throws Exception {
@Override public void stopExiCommunication() { // TODO never used, Netconf client does not support stop-exi replaceMessageDecoder(new NetconfXMLToMessageDecoder()); replaceMessageEncoder(new NetconfMessageToXMLEncoder()); } }
@Override public void close() { // Cancel reconnect if in progress if(initFuture != null) { initFuture.cancel(false); } // Disconnect from device if(session != null) { session.close(); // tear down not necessary, called indirectly by above close } }