Search in sources :

Example 1 with NetconfXMLToHelloMessageDecoder

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

the class Netconf539Test method setUp.

@Before
public void setUp() throws Exception {
    channel = new EmbeddedChannel();
    channel.pipeline().addLast(AbstractChannelInitializer.NETCONF_MESSAGE_ENCODER, new ChannelInboundHandlerAdapter());
    channel.pipeline().addLast(AbstractChannelInitializer.NETCONF_MESSAGE_DECODER, new NetconfXMLToHelloMessageDecoder());
    channel.pipeline().addLast(NETCONF_MESSAGE_FRAME_ENCODER, FramingMechanismHandlerFactory.createHandler(FramingMechanism.EOM));
    channel.pipeline().addLast(NETCONF_MESSAGE_AGGREGATOR, new NetconfEOMAggregator());
    final NetconfHelloMessage serverHello = NetconfHelloMessage.createClientHello(Collections.singleton(XmlNetconfConstants.URN_IETF_PARAMS_NETCONF_BASE_1_1), Optional.empty());
    negotiator = new TestSessionNegotiator(new NetconfSessionPreferences(serverHello), promise, channel, new HashedWheelTimer(), listener, 100L);
}
Also used : NetconfXMLToHelloMessageDecoder(org.opendaylight.netconf.nettyutil.handler.NetconfXMLToHelloMessageDecoder) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) NetconfHelloMessage(org.opendaylight.netconf.api.messages.NetconfHelloMessage) HashedWheelTimer(io.netty.util.HashedWheelTimer) NetconfSessionPreferences(org.opendaylight.netconf.api.NetconfSessionPreferences) NetconfEOMAggregator(org.opendaylight.netconf.nettyutil.handler.NetconfEOMAggregator) ChannelInboundHandlerAdapter(io.netty.channel.ChannelInboundHandlerAdapter) Before(org.junit.Before)

Example 2 with NetconfXMLToHelloMessageDecoder

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

the class NetconfClientSessionNegotiatorTest method mockChannelPipeline.

private static ChannelPipeline mockChannelPipeline() {
    ChannelPipeline pipeline = mock(ChannelPipeline.class);
    ChannelHandler handler = mock(ChannelHandler.class);
    doReturn(pipeline).when(pipeline).addAfter(anyString(), anyString(), any(ChannelHandler.class));
    doReturn(null).when(pipeline).get(SslHandler.class);
    doReturn(pipeline).when(pipeline).addLast(anyString(), any(ChannelHandler.class));
    doReturn(handler).when(pipeline).replace(anyString(), anyString(), any(ChunkedFramingMechanismEncoder.class));
    NetconfXMLToHelloMessageDecoder messageDecoder = new NetconfXMLToHelloMessageDecoder();
    doReturn(messageDecoder).when(pipeline).replace(anyString(), anyString(), any(NetconfXMLToMessageDecoder.class));
    doReturn(pipeline).when(pipeline).replace(any(ChannelHandler.class), anyString(), any(NetconfClientSession.class));
    doReturn(null).when(pipeline).replace(anyString(), anyString(), any(MessageToByteEncoder.class));
    doReturn(null).when(pipeline).replace(anyString(), anyString(), any(NetconfEXIToMessageDecoder.class));
    return pipeline;
}
Also used : ChunkedFramingMechanismEncoder(org.opendaylight.netconf.nettyutil.handler.ChunkedFramingMechanismEncoder) NetconfXMLToHelloMessageDecoder(org.opendaylight.netconf.nettyutil.handler.NetconfXMLToHelloMessageDecoder) NetconfEXIToMessageDecoder(org.opendaylight.netconf.nettyutil.handler.NetconfEXIToMessageDecoder) NetconfXMLToMessageDecoder(org.opendaylight.netconf.nettyutil.handler.NetconfXMLToMessageDecoder) ChannelHandler(io.netty.channel.ChannelHandler) MessageToByteEncoder(io.netty.handler.codec.MessageToByteEncoder) ChannelPipeline(io.netty.channel.ChannelPipeline)

Example 3 with NetconfXMLToHelloMessageDecoder

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

the class AbstractNetconfSessionNegotiator method replaceHelloMessageInboundHandler.

/**
 * Remove special inbound handler for hello message. Insert regular netconf xml message (en|de)coders.
 *
 * <p>
 * Inbound hello message handler should be kept until negotiation is successful
 * It caches any non-hello messages while negotiation is still in progress
 */
protected final void replaceHelloMessageInboundHandler(final S session) {
    ChannelHandler helloMessageHandler = replaceChannelHandler(channel, AbstractChannelInitializer.NETCONF_MESSAGE_DECODER, new NetconfXMLToMessageDecoder());
    checkState(helloMessageHandler instanceof NetconfXMLToHelloMessageDecoder, "Pipeline handlers misplaced on session: %s, pipeline: %s", session, channel.pipeline());
    Iterable<NetconfMessage> netconfMessagesFromNegotiation = ((NetconfXMLToHelloMessageDecoder) helloMessageHandler).getPostHelloNetconfMessages();
    // It means, we are now using the thread now
    for (NetconfMessage message : netconfMessagesFromNegotiation) {
        session.handleMessage(message);
    }
}
Also used : NetconfXMLToHelloMessageDecoder(org.opendaylight.netconf.nettyutil.handler.NetconfXMLToHelloMessageDecoder) NetconfMessage(org.opendaylight.netconf.api.NetconfMessage) NetconfXMLToMessageDecoder(org.opendaylight.netconf.nettyutil.handler.NetconfXMLToMessageDecoder) ChannelHandler(io.netty.channel.ChannelHandler)

Example 4 with NetconfXMLToHelloMessageDecoder

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

the class AbstractNetconfSessionNegotiatorTest method setUp.

@Before
public void setUp() {
    channel = new EmbeddedChannel();
    xmlToHello = new NetconfXMLToHelloMessageDecoder();
    channel.pipeline().addLast(AbstractChannelInitializer.NETCONF_MESSAGE_ENCODER, new ChannelInboundHandlerAdapter());
    channel.pipeline().addLast(AbstractChannelInitializer.NETCONF_MESSAGE_DECODER, xmlToHello);
    channel.pipeline().addLast(NETCONF_MESSAGE_FRAME_ENCODER, FramingMechanismHandlerFactory.createHandler(FramingMechanism.EOM));
    channel.pipeline().addLast(NETCONF_MESSAGE_AGGREGATOR, new NetconfEOMAggregator());
    hello = NetconfHelloMessage.createClientHello(Set.of(), Optional.empty());
    helloBase11 = NetconfHelloMessage.createClientHello(Set.of(XmlNetconfConstants.URN_IETF_PARAMS_NETCONF_BASE_1_1), Optional.empty());
    prefs = new NetconfSessionPreferences(helloBase11);
    doReturn(promise).when(promise).setFailure(any());
    negotiator = new TestSessionNegotiator(prefs, promise, channel, timer, listener, 100L);
}
Also used : NetconfXMLToHelloMessageDecoder(org.opendaylight.netconf.nettyutil.handler.NetconfXMLToHelloMessageDecoder) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) NetconfSessionPreferences(org.opendaylight.netconf.api.NetconfSessionPreferences) NetconfEOMAggregator(org.opendaylight.netconf.nettyutil.handler.NetconfEOMAggregator) ChannelInboundHandlerAdapter(io.netty.channel.ChannelInboundHandlerAdapter) Before(org.junit.Before)

Aggregations

NetconfXMLToHelloMessageDecoder (org.opendaylight.netconf.nettyutil.handler.NetconfXMLToHelloMessageDecoder)4 ChannelHandler (io.netty.channel.ChannelHandler)2 ChannelInboundHandlerAdapter (io.netty.channel.ChannelInboundHandlerAdapter)2 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)2 Before (org.junit.Before)2 NetconfSessionPreferences (org.opendaylight.netconf.api.NetconfSessionPreferences)2 NetconfEOMAggregator (org.opendaylight.netconf.nettyutil.handler.NetconfEOMAggregator)2 NetconfXMLToMessageDecoder (org.opendaylight.netconf.nettyutil.handler.NetconfXMLToMessageDecoder)2 ChannelPipeline (io.netty.channel.ChannelPipeline)1 MessageToByteEncoder (io.netty.handler.codec.MessageToByteEncoder)1 HashedWheelTimer (io.netty.util.HashedWheelTimer)1 NetconfMessage (org.opendaylight.netconf.api.NetconfMessage)1 NetconfHelloMessage (org.opendaylight.netconf.api.messages.NetconfHelloMessage)1 ChunkedFramingMechanismEncoder (org.opendaylight.netconf.nettyutil.handler.ChunkedFramingMechanismEncoder)1 NetconfEXIToMessageDecoder (org.opendaylight.netconf.nettyutil.handler.NetconfEXIToMessageDecoder)1