public NetconfHelloMessage(Document doc, NetconfHelloMessageAdditionalHeader additionalHeader) throws NetconfDocumentedException { super(doc); checkHelloMessage(doc); this.additionalHeader = additionalHeader; }
public byte[] toBytes() { return toBytes(this.length); }
private static NetconfMessage getNetconfMessage(final String additionalHeader, final Document doc) throws NetconfDocumentedException { NetconfMessage msg = new NetconfMessage(doc); if(NetconfHelloMessage.isHelloMessage(msg)) { if (additionalHeader != null) { return new NetconfHelloMessage(doc, NetconfHelloMessageAdditionalHeader.fromString(additionalHeader)); } else { return new NetconfHelloMessage(doc); } } return msg; }
public static boolean isErrorMessage(NetconfMessage message) throws NetconfDocumentedException { return isErrorMessage(message.getDocument()); }
public static NetconfHelloMessage createClientHello(Iterable<String> capabilities, Optional<NetconfHelloMessageAdditionalHeader> additionalHeaderOptional) throws NetconfDocumentedException { Document doc = createHelloMessageDoc(capabilities); return additionalHeaderOptional.isPresent() ? new NetconfHelloMessage(doc, additionalHeaderOptional.get()) : new NetconfHelloMessage(doc); }
@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); }
public static void sendErrorMessage(final NetconfSession session, final NetconfDocumentedException sendErrorException, final NetconfMessage incommingMessage) { final Document errorDocument = createDocument(sendErrorException); if (LOG.isTraceEnabled()) { LOG.trace("Sending error {}", XmlUtil.toString(errorDocument)); } tryToCopyAttributes(incommingMessage.getDocument(), errorDocument, sendErrorException); ChannelFuture f = session.sendMessage(new NetconfMessage(errorDocument)); f.addListener(new SendErrorVerifyingListener(sendErrorException)); }
@Override @VisibleForTesting public void encode(ChannelHandlerContext ctx, NetconfMessage msg, ByteBuf out) throws IOException, TransformerException { Preconditions.checkState(msg instanceof NetconfHelloMessage, "Netconf message of type %s expected, was %s", NetconfHelloMessage.class, msg.getClass()); Optional<NetconfHelloMessageAdditionalHeader> headerOptional = ((NetconfHelloMessage) msg) .getAdditionalHeader(); // If additional header present, serialize it along with netconf hello message if (headerOptional.isPresent()) { out.writeBytes(headerOptional.get().toFormattedString().getBytes(Charsets.UTF_8)); } super.encode(ctx, msg, out); } }
public static boolean isHelloMessage(final NetconfMessage msg) { Document document = msg.getDocument(); return isHelloMessage(document); }
public static boolean isOKMessage(NetconfMessage message) throws NetconfDocumentedException { return isOKMessage(message.getDocument()); }
public static void sendErrorMessage(final Channel channel, final NetconfDocumentedException sendErrorException) { LOG.trace("Sending error {}", sendErrorException.getMessage(), sendErrorException); final Document errorDocument = createDocument(sendErrorException); ChannelFuture f = channel.writeAndFlush(new NetconfMessage(errorDocument)); f.addListener(new SendErrorVerifyingListener(sendErrorException)); }
protected final S getSessionForHelloMessage(final NetconfHelloMessage netconfMessage) throws NetconfDocumentedException { Preconditions.checkNotNull(netconfMessage, "netconfMessage"); final Document doc = netconfMessage.getDocument(); if (shouldUseChunkFraming(doc)) { insertChunkFramingToPipeline(); } changeState(State.ESTABLISHED); return getSession(sessionListener, channel, netconfMessage); }
private NetconfHelloMessage createHelloMessage(final long sessionId, final NetconfMonitoringService capabilityProvider) throws NetconfDocumentedException { return NetconfHelloMessage.createServerHello(Sets.union(DefaultCommit.transformCapabilities(capabilityProvider.getCapabilities()), baseCapabilities), sessionId); }
public static boolean isErrorMessage(Document document) throws NetconfDocumentedException { return isErrorMessage(XmlElement.fromDomDocument(document)); }
public static NetconfHelloMessage createServerHello(Set<String> capabilities, long sessionId) throws NetconfDocumentedException { Document doc = createHelloMessageDoc(capabilities); Element sessionIdElement = doc.createElementNS(XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0, XmlNetconfConstants.SESSION_ID); sessionIdElement.setTextContent(Long.toString(sessionId)); doc.getDocumentElement().appendChild(sessionIdElement); return new NetconfHelloMessage(doc); }
private static void checkHelloMessage(Document doc) { Preconditions.checkArgument(isHelloMessage(doc), "Hello message invalid format, should contain %s tag from namespace %s, but is: %s", HELLO_TAG, XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0, XmlUtil.toString(doc)); }
public static boolean isOKMessage(Document document) throws NetconfDocumentedException { return isOKMessage(XmlElement.fromDomDocument(document)); }
public static void sendErrorMessage(final NetconfSession session, final NetconfDocumentedException sendErrorException) { LOG.trace("Sending error {}", sendErrorException.getMessage(), sendErrorException); final Document errorDocument = createDocument(sendErrorException); ChannelFuture f = session.sendMessage(new NetconfMessage(errorDocument)); f.addListener(new SendErrorVerifyingListener(sendErrorException)); }
private boolean shouldUseExi(final NetconfHelloMessage helloMsg) { return containsExi10Capability(helloMsg.getDocument()) && containsExi10Capability(sessionPreferences.getHelloMessage().getDocument()); }
public static void checkSuccessReply(final NetconfMessage output) throws NetconfDocumentedException { if(NetconfMessageUtil.isErrorMessage(output)) { throw NetconfDocumentedException.fromXMLDocument(output.getDocument()); } }