Search in sources :

Example 1 with NetconfMessageToXMLEncoder

use of org.opendaylight.netconf.nettyutil.handler.NetconfMessageToXMLEncoder in project netconf by opendaylight.

the class NetconfServerSessionTest method testAddExiHandlers.

@Test
public void testAddExiHandlers() throws Exception {
    channel.pipeline().addLast(AbstractChannelInitializer.NETCONF_MESSAGE_DECODER, new NetconfXMLToMessageDecoder());
    channel.pipeline().addLast(AbstractChannelInitializer.NETCONF_MESSAGE_ENCODER, new NetconfMessageToXMLEncoder());
    final NetconfEXICodec codec = NetconfEXICodec.forParameters(EXIParameters.empty());
    session.addExiHandlers(NetconfEXIToMessageDecoder.create(codec), NetconfMessageToEXIEncoder.create(codec));
}
Also used : NetconfEXICodec(org.opendaylight.netconf.nettyutil.handler.NetconfEXICodec) NetconfXMLToMessageDecoder(org.opendaylight.netconf.nettyutil.handler.NetconfXMLToMessageDecoder) NetconfMessageToXMLEncoder(org.opendaylight.netconf.nettyutil.handler.NetconfMessageToXMLEncoder) Test(org.junit.Test)

Example 2 with NetconfMessageToXMLEncoder

use of org.opendaylight.netconf.nettyutil.handler.NetconfMessageToXMLEncoder in project netconf by opendaylight.

the class MessageParserTest method testEOMFramingMechanismOnPipeline.

@Test
public void testEOMFramingMechanismOnPipeline() throws Exception {
    EmbeddedChannel testChunkChannel = new EmbeddedChannel(FramingMechanismHandlerFactory.createHandler(FramingMechanism.EOM), new NetconfMessageToXMLEncoder(), new NetconfEOMAggregator(), new NetconfXMLToMessageDecoder());
    testChunkChannel.writeOutbound(this.msg);
    ByteBuf recievedOutbound = testChunkChannel.readOutbound();
    byte[] endOfMsgBytes = NetconfMessageConstants.END_OF_MESSAGE.getBytes(StandardCharsets.UTF_8);
    byte[] eom = new byte[endOfMsgBytes.length];
    recievedOutbound.getBytes(recievedOutbound.readableBytes() - endOfMsgBytes.length, eom);
    assertArrayEquals(endOfMsgBytes, eom);
    testChunkChannel.writeInbound(recievedOutbound);
    NetconfMessage receivedMessage = testChunkChannel.readInbound();
    assertNotNull(receivedMessage);
    XMLUnit.setIgnoreWhitespace(true);
    assertXMLEqual(this.msg.getDocument(), receivedMessage.getDocument());
}
Also used : NetconfMessage(org.opendaylight.netconf.api.NetconfMessage) 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) NetconfEOMAggregator(org.opendaylight.netconf.nettyutil.handler.NetconfEOMAggregator) Test(org.junit.Test)

Example 3 with NetconfMessageToXMLEncoder

use of org.opendaylight.netconf.nettyutil.handler.NetconfMessageToXMLEncoder 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 4 with NetconfMessageToXMLEncoder

use of org.opendaylight.netconf.nettyutil.handler.NetconfMessageToXMLEncoder in project netconf by opendaylight.

the class NetconfClientSession method stopExiCommunication.

@Override
public void stopExiCommunication() {
    // TODO never used, Netconf client does not support stop-exi
    replaceMessageDecoder(new NetconfXMLToMessageDecoder());
    replaceMessageEncoder(new NetconfMessageToXMLEncoder());
}
Also used : NetconfXMLToMessageDecoder(org.opendaylight.netconf.nettyutil.handler.NetconfXMLToMessageDecoder) NetconfMessageToXMLEncoder(org.opendaylight.netconf.nettyutil.handler.NetconfMessageToXMLEncoder)

Example 5 with NetconfMessageToXMLEncoder

use of org.opendaylight.netconf.nettyutil.handler.NetconfMessageToXMLEncoder in project netconf by opendaylight.

the class NetconfServerSession method stopExiCommunication.

@Override
public void stopExiCommunication() {
    replaceMessageDecoder(new NetconfXMLToMessageDecoder());
    replaceMessageEncoderAfterNextMessage(new NetconfMessageToXMLEncoder());
}
Also used : NetconfXMLToMessageDecoder(org.opendaylight.netconf.nettyutil.handler.NetconfXMLToMessageDecoder) NetconfMessageToXMLEncoder(org.opendaylight.netconf.nettyutil.handler.NetconfMessageToXMLEncoder)

Aggregations

NetconfMessageToXMLEncoder (org.opendaylight.netconf.nettyutil.handler.NetconfMessageToXMLEncoder)5 NetconfXMLToMessageDecoder (org.opendaylight.netconf.nettyutil.handler.NetconfXMLToMessageDecoder)5 Test (org.junit.Test)3 ByteBuf (io.netty.buffer.ByteBuf)2 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)2 NetconfMessage (org.opendaylight.netconf.api.NetconfMessage)2 NetconfChunkAggregator (org.opendaylight.netconf.nettyutil.handler.NetconfChunkAggregator)1 NetconfEOMAggregator (org.opendaylight.netconf.nettyutil.handler.NetconfEOMAggregator)1 NetconfEXICodec (org.opendaylight.netconf.nettyutil.handler.NetconfEXICodec)1