Search in sources :

Example 1 with NetconfEXICodec

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

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

the class AbstractNetconfSession method startExiCommunication.

@Override
public final void startExiCommunication(final NetconfMessage startExiMessage) {
    final EXIParameters exiParams;
    try {
        exiParams = EXIParameters.fromXmlElement(XmlElement.fromDomDocument(startExiMessage.getDocument()));
    } catch (final UnsupportedOption e) {
        LOG.warn("Unable to parse EXI parameters from {} on session {}", startExiMessage, this, e);
        throw new IllegalArgumentException("Cannot parse options", e);
    }
    final NetconfEXICodec exiCodec = NetconfEXICodec.forParameters(exiParams);
    final NetconfMessageToEXIEncoder exiEncoder = NetconfMessageToEXIEncoder.create(exiCodec);
    final NetconfEXIToMessageDecoder exiDecoder;
    try {
        exiDecoder = NetconfEXIToMessageDecoder.create(exiCodec);
    } catch (EXIException e) {
        LOG.warn("Failed to instantiate EXI decodeer for {} on session {}", exiCodec, this, e);
        throw new IllegalStateException("Cannot instantiate encoder for options", e);
    }
    addExiHandlers(exiDecoder, exiEncoder);
    LOG.debug("Session {} EXI handlers added to pipeline", this);
}
Also used : EXIParameters(org.opendaylight.netconf.nettyutil.handler.exi.EXIParameters) NetconfEXICodec(org.opendaylight.netconf.nettyutil.handler.NetconfEXICodec) NetconfMessageToEXIEncoder(org.opendaylight.netconf.nettyutil.handler.NetconfMessageToEXIEncoder) NetconfEXIToMessageDecoder(org.opendaylight.netconf.nettyutil.handler.NetconfEXIToMessageDecoder) UnsupportedOption(org.opendaylight.netconf.shaded.exificient.core.exceptions.UnsupportedOption) EXIException(org.opendaylight.netconf.shaded.exificient.core.exceptions.EXIException)

Example 3 with NetconfEXICodec

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

the class NetconfClientSessionTest method testNetconfClientSession.

@Test
public void testNetconfClientSession() throws Exception {
    final NetconfClientSessionListener sessionListener = mock(NetconfClientSessionListener.class);
    final long sessId = 20L;
    final Collection<String> caps = Lists.newArrayList("cap1", "cap2");
    final NetconfEXICodec codec = NetconfEXICodec.forParameters(EXIParameters.empty());
    final ChannelPipeline pipeline = mock(ChannelPipeline.class);
    Mockito.doReturn(pipeline).when(channel).pipeline();
    Mockito.doReturn(channelHandler).when(pipeline).replace(anyString(), anyString(), any(ChannelHandler.class));
    final NetconfClientSession session = new NetconfClientSession(sessionListener, channel, sessId, caps);
    final NetconfMessageToEXIEncoder exiEncoder = NetconfMessageToEXIEncoder.create(codec);
    final NetconfEXIToMessageDecoder exiDecoder = NetconfEXIToMessageDecoder.create(codec);
    session.addExiHandlers(exiDecoder, exiEncoder);
    session.stopExiCommunication();
    assertEquals(caps, session.getServerCapabilities());
    assertEquals(session, session.thisInstance());
    Mockito.verify(pipeline, Mockito.times(4)).replace(anyString(), anyString(), Mockito.any(ChannelHandler.class));
}
Also used : NetconfEXICodec(org.opendaylight.netconf.nettyutil.handler.NetconfEXICodec) NetconfMessageToEXIEncoder(org.opendaylight.netconf.nettyutil.handler.NetconfMessageToEXIEncoder) NetconfEXIToMessageDecoder(org.opendaylight.netconf.nettyutil.handler.NetconfEXIToMessageDecoder) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ChannelHandler(io.netty.channel.ChannelHandler) ChannelPipeline(io.netty.channel.ChannelPipeline) Test(org.junit.Test)

Aggregations

NetconfEXICodec (org.opendaylight.netconf.nettyutil.handler.NetconfEXICodec)3 Test (org.junit.Test)2 NetconfEXIToMessageDecoder (org.opendaylight.netconf.nettyutil.handler.NetconfEXIToMessageDecoder)2 NetconfMessageToEXIEncoder (org.opendaylight.netconf.nettyutil.handler.NetconfMessageToEXIEncoder)2 ChannelHandler (io.netty.channel.ChannelHandler)1 ChannelPipeline (io.netty.channel.ChannelPipeline)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1 NetconfMessageToXMLEncoder (org.opendaylight.netconf.nettyutil.handler.NetconfMessageToXMLEncoder)1 NetconfXMLToMessageDecoder (org.opendaylight.netconf.nettyutil.handler.NetconfXMLToMessageDecoder)1 EXIParameters (org.opendaylight.netconf.nettyutil.handler.exi.EXIParameters)1 EXIException (org.opendaylight.netconf.shaded.exificient.core.exceptions.EXIException)1 UnsupportedOption (org.opendaylight.netconf.shaded.exificient.core.exceptions.UnsupportedOption)1