Search in sources :

Example 1 with NetconfEXIToMessageDecoder

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

use of org.opendaylight.netconf.nettyutil.handler.NetconfEXIToMessageDecoder 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)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 Test (org.junit.Test)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)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