use of org.opendaylight.netconf.nettyutil.handler.NetconfChunkAggregator in project netconf by opendaylight.
the class AbstractNetconfSessionNegotiator method insertChunkFramingToPipeline.
/**
* Insert chunk framing handlers into the pipeline.
*/
private void insertChunkFramingToPipeline() {
replaceChannelHandler(channel, AbstractChannelInitializer.NETCONF_MESSAGE_FRAME_ENCODER, FramingMechanismHandlerFactory.createHandler(FramingMechanism.CHUNK));
replaceChannelHandler(channel, AbstractChannelInitializer.NETCONF_MESSAGE_AGGREGATOR, new NetconfChunkAggregator());
}
use of org.opendaylight.netconf.nettyutil.handler.NetconfChunkAggregator in project netconf by opendaylight.
the class MessageParserTest method testChunkedFramingMechanismOnPipeline.
@Test
public void testChunkedFramingMechanismOnPipeline() throws Exception {
EmbeddedChannel testChunkChannel = new EmbeddedChannel(FramingMechanismHandlerFactory.createHandler(FramingMechanism.CHUNK), new NetconfMessageToXMLEncoder(), new NetconfChunkAggregator(), new NetconfXMLToMessageDecoder());
testChunkChannel.writeOutbound(this.msg);
Queue<Object> messages = testChunkChannel.outboundMessages();
assertFalse(messages.isEmpty());
final NetconfMessageToXMLEncoder enc = new NetconfMessageToXMLEncoder();
final ByteBuf out = Unpooled.buffer();
enc.encode(null, msg, out);
int msgLength = out.readableBytes();
int chunkCount = msgLength / ChunkedFramingMechanismEncoder.DEFAULT_CHUNK_SIZE;
if (msgLength % ChunkedFramingMechanismEncoder.DEFAULT_CHUNK_SIZE != 0) {
chunkCount++;
}
byte[] endOfChunkBytes = NetconfMessageConstants.END_OF_CHUNK.getBytes(StandardCharsets.UTF_8);
for (int i = 1; i <= chunkCount; i++) {
ByteBuf recievedOutbound = (ByteBuf) messages.poll();
int exptHeaderLength = ChunkedFramingMechanismEncoder.DEFAULT_CHUNK_SIZE;
if (i == chunkCount) {
exptHeaderLength = msgLength - ChunkedFramingMechanismEncoder.DEFAULT_CHUNK_SIZE * (i - 1);
byte[] eom = new byte[endOfChunkBytes.length];
recievedOutbound.getBytes(recievedOutbound.readableBytes() - endOfChunkBytes.length, eom);
assertArrayEquals(endOfChunkBytes, eom);
}
byte[] header = new byte[String.valueOf(exptHeaderLength).length() + NetconfMessageConstants.MIN_HEADER_LENGTH - 1];
recievedOutbound.getBytes(0, header);
assertEquals(exptHeaderLength, getHeaderLength(header));
testChunkChannel.writeInbound(recievedOutbound);
}
assertTrue(messages.isEmpty());
NetconfMessage receivedMessage = testChunkChannel.readInbound();
assertNotNull(receivedMessage);
XMLUnit.setIgnoreWhitespace(true);
assertXMLEqual(this.msg.getDocument(), receivedMessage.getDocument());
}
use of org.opendaylight.netconf.nettyutil.handler.NetconfChunkAggregator in project netconf by opendaylight.
the class Netconf539Test method testGetSessionForHelloMessage.
private void testGetSessionForHelloMessage(final String fileName) throws Exception {
final Document helloDocument = XmlFileLoader.xmlFileToDocument(fileName);
negotiator.startNegotiation();
final NetconfHelloMessage helloMessage = new NetconfHelloMessage(helloDocument);
final AbstractNetconfSession session = negotiator.getSessionForHelloMessage(helloMessage);
Assert.assertNotNull(session);
Assert.assertTrue("NetconfChunkAggregator was not installed in the Netconf pipeline", channel.pipeline().get(NETCONF_MESSAGE_AGGREGATOR) instanceof NetconfChunkAggregator);
Assert.assertTrue("ChunkedFramingMechanismEncoder was not installed in the Netconf pipeline", channel.pipeline().get(NETCONF_MESSAGE_FRAME_ENCODER) instanceof ChunkedFramingMechanismEncoder);
}
Aggregations