use of org.opendaylight.netconf.api.NetconfMessage in project netconf by opendaylight.
the class SimpleNetconfClientSessionListenerTest method setUp.
@Before
public void setUp() throws NetconfDocumentedException {
channel = mock(Channel.class);
channelFuture = mock(ChannelPromise.class);
mockEventLoop();
doReturn(channelFuture).when(channel).newPromise();
doReturn(channelFuture).when(channel).writeAndFlush(any());
doReturn(channelFuture).when(channel).writeAndFlush(any(), any(ChannelPromise.class));
doReturn(channelFuture).when(channelFuture).addListener(any(GenericFutureListener.class));
caps = Sets.newSet("a", "b");
helloMessage = NetconfHelloMessage.createServerHello(caps, 10);
message = new NetconfMessage(helloMessage.getDocument());
sessionListener = mock(NetconfClientSessionListener.class);
clientSession = new NetconfClientSession(sessionListener, channel, 20L, caps);
}
use of org.opendaylight.netconf.api.NetconfMessage in project netconf by opendaylight.
the class NetconfClientSessionNegotiator method handleMessage.
@SuppressWarnings("checkstyle:IllegalCatch")
@Override
@SuppressFBWarnings("BC_UNCONFIRMED_CAST")
protected void handleMessage(final NetconfHelloMessage netconfMessage) throws NetconfDocumentedException {
if (!ifNegotiatedAlready()) {
LOG.debug("Server hello message received, starting negotiation on channel {}", channel);
try {
startNegotiation();
} catch (final Exception e) {
LOG.warn("Unexpected negotiation failure on channel {}", channel, e);
negotiationFailed(e);
return;
}
}
final NetconfClientSession session = getSessionForHelloMessage(netconfMessage);
replaceHelloMessageInboundHandler(session);
// If exi should be used, try to initiate exi communication
// Call negotiationSuccessFul after exi negotiation is finished successfully or not
final NetconfMessage startExiMessage = sessionPreferences.getStartExiMessage();
if (shouldUseExi(netconfMessage) && startExiMessage instanceof NetconfStartExiMessage) {
LOG.debug("Netconf session {} should use exi.", session);
tryToInitiateExi(session, (NetconfStartExiMessage) startExiMessage);
} else {
// Exi is not supported, release session immediately
LOG.debug("Netconf session {} isn't capable of using exi.", session);
negotiationSuccessful(session);
}
}
use of org.opendaylight.netconf.api.NetconfMessage in project netconf by opendaylight.
the class BaseRpcSchemalessTransformer method toRpcRequest.
@Override
public NetconfMessage toRpcRequest(final QName rpc, final NormalizedNode payload) {
// In case no input for rpc is defined, we can simply construct the payload here
final RpcDefinition mappedRpc = Preconditions.checkNotNull(mappedRpcs.get(rpc), "Unknown rpc %s, available rpcs: %s", rpc, mappedRpcs.keySet());
final DOMResult domResult = NetconfMessageTransformUtil.prepareDomResultForRpcRequest(rpc, counter);
if (mappedRpc.getInput().getChildNodes().isEmpty()) {
return new NetconfMessage(domResult.getNode().getOwnerDocument());
}
Preconditions.checkNotNull(payload, "Transforming an rpc with input: %s, payload cannot be null", rpc);
Preconditions.checkArgument(payload instanceof ContainerNode, "Transforming an rpc with input: %s, payload has to be a container, but was: %s", rpc, payload);
final DOMResult result = domResult;
try {
NetconfMessageTransformUtil.writeNormalizedOperationInput((ContainerNode) payload, result, Absolute.of(rpc), modelContext);
} catch (final XMLStreamException | IOException | IllegalStateException e) {
throw new IllegalStateException("Unable to serialize input of " + rpc, e);
}
final Document node = result.getNode().getOwnerDocument();
return new NetconfMessage(node);
}
use of org.opendaylight.netconf.api.NetconfMessage in project netconf by opendaylight.
the class NetconfNestedNotificationTest method prepareNotification.
private NetconfMessage prepareNotification(final String notificationPayloadPath) throws IOException, SAXException {
InputStream notifyPayloadStream = getClass().getResourceAsStream(notificationPayloadPath);
assertNotNull(notifyPayloadStream);
final Document doc = XmlUtil.readXmlToDocument(notifyPayloadStream);
assertNotNull(doc);
return new NetconfMessage(doc);
}
use of org.opendaylight.netconf.api.NetconfMessage in project netconf by opendaylight.
the class SchemalessNetconfDeviceRpc method handleRpc.
private ListenableFuture<DOMRpcResult> handleRpc(@NonNull final QName type, @NonNull final NormalizedNode input, final MessageTransformer<NetconfMessage> transformer) {
final ListenableFuture<RpcResult<NetconfMessage>> delegateFuture = listener.sendRequest(transformer.toRpcRequest(type, input), type);
final SettableFuture<DOMRpcResult> ret = SettableFuture.create();
Futures.addCallback(delegateFuture, new FutureCallback<RpcResult<NetconfMessage>>() {
@Override
public void onSuccess(final RpcResult<NetconfMessage> result) {
ret.set(result.isSuccessful() ? transformer.toRpcResult(result.getResult(), type) : new DefaultDOMRpcResult(result.getErrors()));
}
@Override
public void onFailure(final Throwable cause) {
ret.setException(new DOMRpcImplementationNotAvailableException(cause, "Unable to invoke rpc %s on device %s", type, deviceId));
}
}, MoreExecutors.directExecutor());
return ret;
}
Aggregations