@Override protected void handleMessage(final NetconfHelloMessage netconfMessage) throws NetconfDocumentedException { 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 if (shouldUseExi(netconfMessage)) { LOG.debug("Netconf session {} should use exi.", session); NetconfStartExiMessage startExiMessage = (NetconfStartExiMessage) sessionPreferences.getStartExiMessage(); tryToInitiateExi(session, startExiMessage); } else { // Exi is not supported, release session immediately LOG.debug("Netconf session {} isn't capable of using exi.", session); negotiationSuccessful(session); } }
private static long extractSessionId(final Document doc) { String textContent = getSessionIdWithXPath(doc, sessionIdXPath); if (Strings.isNullOrEmpty(textContent)) { textContent = getSessionIdWithXPath(doc, sessionIdXPathNoNamespace); if (Strings.isNullOrEmpty(textContent)) { throw new IllegalStateException("Session id not received from server, hello message: " + XmlUtil.toString(doc)); } } return Long.valueOf(textContent); }
private boolean shouldUseExi(final NetconfHelloMessage helloMsg) { return containsExi10Capability(helloMsg.getDocument()) && containsExi10Capability(sessionPreferences.getHelloMessage().getDocument()); }
@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); }
@Override public SessionNegotiator<NetconfClientSession> getSessionNegotiator(final SessionListenerFactory<NetconfClientSessionListener> sessionListenerFactory, final Channel channel, final Promise<NetconfClientSession> promise) { NetconfMessage startExiMessage = NetconfStartExiMessage.create(options, START_EXI_MESSAGE_ID); NetconfHelloMessage helloMessage = null; try { helloMessage = NetconfHelloMessage.createClientHello(clientCapabilities, additionalHeader); } catch (NetconfDocumentedException e) { LOG.error("Unable to create client hello message with capabilities {} and additional handler {}", clientCapabilities,additionalHeader); throw new IllegalStateException(e); } NetconfClientSessionPreferences proposal = new NetconfClientSessionPreferences(helloMessage, startExiMessage); return new NetconfClientSessionNegotiator(proposal, promise, channel, timer, sessionListenerFactory.getSessionListener(),connectionTimeoutMillis); } }