Search in sources :

Example 51 with NetconfMessage

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);
}
Also used : NetconfMessage(org.opendaylight.netconf.api.NetconfMessage) Channel(io.netty.channel.Channel) ChannelPromise(io.netty.channel.ChannelPromise) GenericFutureListener(io.netty.util.concurrent.GenericFutureListener) Before(org.junit.Before)

Example 52 with NetconfMessage

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);
    }
}
Also used : NetconfStartExiMessage(org.opendaylight.netconf.nettyutil.handler.exi.NetconfStartExiMessage) NetconfMessage(org.opendaylight.netconf.api.NetconfMessage) NetconfDocumentedException(org.opendaylight.netconf.api.NetconfDocumentedException) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 53 with NetconfMessage

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);
}
Also used : DOMResult(javax.xml.transform.dom.DOMResult) RpcDefinition(org.opendaylight.yangtools.yang.model.api.RpcDefinition) XMLStreamException(javax.xml.stream.XMLStreamException) NetconfMessage(org.opendaylight.netconf.api.NetconfMessage) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) IOException(java.io.IOException) Document(org.w3c.dom.Document)

Example 54 with NetconfMessage

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);
}
Also used : InputStream(java.io.InputStream) NetconfMessage(org.opendaylight.netconf.api.NetconfMessage) Document(org.w3c.dom.Document)

Example 55 with NetconfMessage

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;
}
Also used : DefaultDOMRpcResult(org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult) DefaultDOMRpcResult(org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult) DOMRpcResult(org.opendaylight.mdsal.dom.api.DOMRpcResult) NetconfMessage(org.opendaylight.netconf.api.NetconfMessage) DOMRpcImplementationNotAvailableException(org.opendaylight.mdsal.dom.api.DOMRpcImplementationNotAvailableException) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) DefaultDOMRpcResult(org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult) DOMRpcResult(org.opendaylight.mdsal.dom.api.DOMRpcResult)

Aggregations

NetconfMessage (org.opendaylight.netconf.api.NetconfMessage)125 Test (org.junit.Test)72 AbstractBaseSchemasTest (org.opendaylight.netconf.sal.connect.netconf.AbstractBaseSchemasTest)40 Document (org.w3c.dom.Document)28 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)23 QName (org.opendaylight.yangtools.yang.common.QName)17 DOMSourceAnyxmlNode (org.opendaylight.yangtools.yang.data.api.schema.DOMSourceAnyxmlNode)15 Test (org.junit.jupiter.api.Test)13 SimpleNetconfClientSessionListener (org.opendaylight.netconf.client.SimpleNetconfClientSessionListener)13 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)13 Node (org.w3c.dom.Node)13 NetconfClientSession (org.opendaylight.netconf.client.NetconfClientSession)12 ArrayList (java.util.ArrayList)11 Element (org.w3c.dom.Element)11 DOMRpcResult (org.opendaylight.mdsal.dom.api.DOMRpcResult)10 UnkeyedListNode (org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListNode)10 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)9 MapEntryNode (org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode)9 ChannelFuture (io.netty.channel.ChannelFuture)8 MapNode (org.opendaylight.yangtools.yang.data.api.schema.MapNode)8