Search in sources :

Example 1 with NetconfChunkAggregator

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());
}
Also used : NetconfChunkAggregator(org.opendaylight.netconf.nettyutil.handler.NetconfChunkAggregator)

Example 2 with 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());
}
Also used : NetconfMessage(org.opendaylight.netconf.api.NetconfMessage) NetconfChunkAggregator(org.opendaylight.netconf.nettyutil.handler.NetconfChunkAggregator) NetconfXMLToMessageDecoder(org.opendaylight.netconf.nettyutil.handler.NetconfXMLToMessageDecoder) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) ByteBuf(io.netty.buffer.ByteBuf) NetconfMessageToXMLEncoder(org.opendaylight.netconf.nettyutil.handler.NetconfMessageToXMLEncoder) Test(org.junit.Test)

Example 3 with NetconfChunkAggregator

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);
}
Also used : ChunkedFramingMechanismEncoder(org.opendaylight.netconf.nettyutil.handler.ChunkedFramingMechanismEncoder) NetconfChunkAggregator(org.opendaylight.netconf.nettyutil.handler.NetconfChunkAggregator) NetconfHelloMessage(org.opendaylight.netconf.api.messages.NetconfHelloMessage) Document(org.w3c.dom.Document)

Aggregations

NetconfChunkAggregator (org.opendaylight.netconf.nettyutil.handler.NetconfChunkAggregator)3 ByteBuf (io.netty.buffer.ByteBuf)1 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)1 Test (org.junit.Test)1 NetconfMessage (org.opendaylight.netconf.api.NetconfMessage)1 NetconfHelloMessage (org.opendaylight.netconf.api.messages.NetconfHelloMessage)1 ChunkedFramingMechanismEncoder (org.opendaylight.netconf.nettyutil.handler.ChunkedFramingMechanismEncoder)1 NetconfMessageToXMLEncoder (org.opendaylight.netconf.nettyutil.handler.NetconfMessageToXMLEncoder)1 NetconfXMLToMessageDecoder (org.opendaylight.netconf.nettyutil.handler.NetconfXMLToMessageDecoder)1 Document (org.w3c.dom.Document)1