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);
}
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));
}
Aggregations