import org.opendaylight.netconf.nettyutil.handler.NetconfMessageToXMLEncoder;
import org.opendaylight.netconf.nettyutil.handler.NetconfXMLToMessageDecoder;
import org.opendaylight.netconf.util.messages.FramingMechanism;
-import org.opendaylight.netconf.util.messages.NetconfMessageConstants;
import org.opendaylight.netconf.util.test.XmlFileLoader;
public class MessageParserTest {
@Before
public void setUp() throws Exception {
- this.msg = XmlFileLoader.xmlFileToNetconfMessage("netconfMessages/getConfig.xml");
+ msg = XmlFileLoader.xmlFileToNetconfMessage("netconfMessages/getConfig.xml");
}
@Test
new NetconfChunkAggregator(),
new NetconfXMLToMessageDecoder());
- testChunkChannel.writeOutbound(this.msg);
+ testChunkChannel.writeOutbound(msg);
Queue<Object> messages = testChunkChannel.outboundMessages();
assertFalse(messages.isEmpty());
chunkCount++;
}
- byte[] endOfChunkBytes = NetconfMessageConstants.END_OF_CHUNK.getBytes(StandardCharsets.UTF_8);
+ byte[] endOfChunkBytes = FramingMechanism.CHUNK_END_STR.getBytes(StandardCharsets.US_ASCII);
for (int i = 1; i <= chunkCount; i++) {
ByteBuf recievedOutbound = (ByteBuf) messages.poll();
int exptHeaderLength = ChunkedFramingMechanismEncoder.DEFAULT_CHUNK_SIZE;
assertArrayEquals(endOfChunkBytes, eom);
}
- byte[] header = new byte[String.valueOf(exptHeaderLength).length()
- + NetconfMessageConstants.MIN_HEADER_LENGTH - 1];
+ byte[] header = new byte[String.valueOf(exptHeaderLength).length() + 3];
recievedOutbound.getBytes(0, header);
assertEquals(exptHeaderLength, getHeaderLength(header));
NetconfMessage receivedMessage = testChunkChannel.readInbound();
assertNotNull(receivedMessage);
XMLUnit.setIgnoreWhitespace(true);
- assertXMLEqual(this.msg.getDocument(), receivedMessage.getDocument());
+ assertXMLEqual(msg.getDocument(), receivedMessage.getDocument());
}
@Test
FramingMechanismHandlerFactory.createHandler(FramingMechanism.EOM),
new NetconfMessageToXMLEncoder(), new NetconfEOMAggregator(), new NetconfXMLToMessageDecoder());
- testChunkChannel.writeOutbound(this.msg);
+ testChunkChannel.writeOutbound(msg);
ByteBuf recievedOutbound = testChunkChannel.readOutbound();
- byte[] endOfMsgBytes = NetconfMessageConstants.END_OF_MESSAGE.getBytes(StandardCharsets.UTF_8);
+ byte[] endOfMsgBytes = FramingMechanism.EOM_STR.getBytes(StandardCharsets.US_ASCII);
byte[] eom = new byte[endOfMsgBytes.length];
recievedOutbound.getBytes(recievedOutbound.readableBytes() - endOfMsgBytes.length, eom);
assertArrayEquals(endOfMsgBytes, eom);
NetconfMessage receivedMessage = testChunkChannel.readInbound();
assertNotNull(receivedMessage);
XMLUnit.setIgnoreWhitespace(true);
- assertXMLEqual(this.msg.getDocument(), receivedMessage.getDocument());
+ assertXMLEqual(msg.getDocument(), receivedMessage.getDocument());
}
private static long getHeaderLength(final byte[] bytes) {
import java.nio.charset.CharacterCodingException;
import java.nio.charset.CodingErrorAction;
import java.nio.charset.StandardCharsets;
-import org.opendaylight.netconf.util.messages.NetconfMessageConstants;
+import org.opendaylight.netconf.util.messages.FramingMechanism;
/**
* netconf message part constants as bytes.
* @author Thomas Pantelis
*/
final class MessageParts {
- static final byte[] END_OF_MESSAGE = asciiBytes(NetconfMessageConstants.END_OF_MESSAGE);
- static final byte[] START_OF_CHUNK = asciiBytes(NetconfMessageConstants.START_OF_CHUNK);
- static final byte[] END_OF_CHUNK = asciiBytes(NetconfMessageConstants.END_OF_CHUNK);
+ static final byte[] END_OF_MESSAGE = asciiBytes(FramingMechanism.EOM_STR);
+ static final byte[] START_OF_CHUNK = asciiBytes(FramingMechanism.CHUNK_START_STR);
+ static final byte[] END_OF_CHUNK = asciiBytes(FramingMechanism.CHUNK_END_STR);
private MessageParts() {
// Hidden on purpose
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-
package org.opendaylight.netconf.util.messages;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+
/**
* Known NETCONF framing mechanisms.
*/
+@NonNullByDefault
public enum FramingMechanism {
/**
- * Chunked framing mechanism.
- *
- * @see <a href="http://tools.ietf.org/html/rfc6242#section-4.2">Chunked
- * framing mechanism</a>
+ * Chunk framing mechanism, as defined in
+ * <a href="https://tools.ietf.org/html/rfc6242#section-4.2">RFC6242 Section 4.2</a>.
*/
CHUNK,
/**
- * End-of-Message framing mechanism.
- *
- * @see <a
- * href="http://tools.ietf.org/html/rfc6242#section-4.3">End-of-message
- * framing mechanism</a>
+ * End-of-Message framing mechanism, as defined in
+ * <a href="https://tools.ietf.org/html/rfc6242#section-4.3">RFC6242 Section 4.3</a>.
+ */
+ EOM;
+
+ /**
+ * String literal for a start of chunk, i.e. {@code LF HASH} part of {@code chunk} ABNF.
+ */
+ public static final String CHUNK_START_STR = "\n#";
+ /**
+ * String representing the end of a chunk, i.e. the {@code LF HASH HASH LF} production {@code end-of-chunks} ABNF.
+ */
+ public static final String CHUNK_END_STR = "\n##\n";
+ /**
+ * String representing the End-Of-Message delimiter.
*/
- EOM
+ public static final String EOM_STR = "]]>]]>";
}
+++ /dev/null
-/*
- * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.netconf.util.messages;
-
-import org.eclipse.jdt.annotation.NonNullByDefault;
-
-@NonNullByDefault
-public final class NetconfMessageConstants {
- /**
- * The NETCONF 1.0 old-style message separator. This is framing mechanism is used by default.
- */
- public static final String END_OF_MESSAGE = "]]>]]>";
-
- // bytes
- @Deprecated(since = "3.0.6", forRemoval = true)
- public static final int MIN_HEADER_LENGTH = 4;
-
- // bytes
- @Deprecated(since = "3.0.6", forRemoval = true)
- public static final int MAX_HEADER_LENGTH = 13;
-
- public static final String START_OF_CHUNK = "\n#";
- public static final String END_OF_CHUNK = "\n##\n";
-
- private NetconfMessageConstants() {
- // Hidden on purpose
- }
-}