Search in sources :

Example 76 with NetconfMessage

use of org.opendaylight.netconf.api.NetconfMessage in project netconf by opendaylight.

the class SendErrorExceptionUtil method sendErrorMessage.

public static void sendErrorMessage(final NetconfSession session, final DocumentedException sendErrorException) {
    LOG.trace("Sending error", sendErrorException);
    final Document errorDocument = createDocument(sendErrorException);
    ChannelFuture channelFuture = session.sendMessage(new NetconfMessage(errorDocument));
    channelFuture.addListener(new SendErrorVerifyingListener(sendErrorException));
}
Also used : ChannelFuture(io.netty.channel.ChannelFuture) NetconfMessage(org.opendaylight.netconf.api.NetconfMessage) Document(org.w3c.dom.Document)

Example 77 with NetconfMessage

use of org.opendaylight.netconf.api.NetconfMessage in project netconf by opendaylight.

the class NetconfNestedNotificationTest method testNestedNotificationToNotificationFunction.

@Test
public void testNestedNotificationToNotificationFunction() throws Exception {
    final EffectiveModelContext schemaContext = getNotificationSchemaContext(Collections.singleton("/schemas/nested-notification.yang"));
    final NetconfMessage notificationMessage = prepareNotification("/nested-notification-payload.xml");
    NetconfMessageTransformer messageTransformer = new NetconfMessageTransformer(new EmptyMountPointContext(schemaContext), true, BASE_SCHEMAS.getBaseSchema());
    final DOMNotification domNotification = messageTransformer.toNotification(notificationMessage);
    final ContainerNode root = domNotification.getBody();
    assertNotNull(root);
    assertEquals(1, root.body().size());
    assertEquals("interface-enabled", root.getIdentifier().getNodeType().getLocalName());
    assertEquals(NetconfNotification.RFC3339_DATE_PARSER.apply("2008-07-08T00:01:00Z").toInstant(), ((DOMEvent) domNotification).getEventInstant());
    assertEquals(Absolute.of(INTERFACES_QNAME, INTERFACE_QNAME, INTERFACE_ENABLED_NOTIFICATION_QNAME), domNotification.getType());
}
Also used : EmptyMountPointContext(org.opendaylight.yangtools.rfc8528.data.util.EmptyMountPointContext) DOMNotification(org.opendaylight.mdsal.dom.api.DOMNotification) NetconfMessage(org.opendaylight.netconf.api.NetconfMessage) NetconfMessageTransformer(org.opendaylight.netconf.sal.connect.netconf.schema.mapping.NetconfMessageTransformer) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) EffectiveModelContext(org.opendaylight.yangtools.yang.model.api.EffectiveModelContext) Test(org.junit.Test)

Example 78 with NetconfMessage

use of org.opendaylight.netconf.api.NetconfMessage in project netconf by opendaylight.

the class SchemalessMessageTransformer method toRpcRequest.

@Override
public NetconfMessage toRpcRequest(final QName rpc, final NormalizedNode input) {
    final DOMSource payload = (DOMSource) input.body();
    wrapPayload((Document) payload.getNode());
    return new NetconfMessage((Document) ((DOMSourceAnyxmlNode) input).body().getNode());
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) NetconfMessage(org.opendaylight.netconf.api.NetconfMessage)

Example 79 with NetconfMessage

use of org.opendaylight.netconf.api.NetconfMessage in project netconf by opendaylight.

the class NetconfToNotificationTest method setup.

@Before
public void setup() throws Exception {
    InputStream notifyPayloadStream = getClass().getResourceAsStream("/notification-payload.xml");
    assertNotNull(notifyPayloadStream);
    final Document doc = XmlUtil.readXmlToDocument(notifyPayloadStream);
    assertNotNull(doc);
    userNotification = new NetconfMessage(doc);
}
Also used : InputStream(java.io.InputStream) NetconfMessage(org.opendaylight.netconf.api.NetconfMessage) Document(org.w3c.dom.Document) Before(org.junit.Before)

Example 80 with NetconfMessage

use of org.opendaylight.netconf.api.NetconfMessage in project netconf by opendaylight.

the class NetconfToRpcRequestTest method testUserDefinedRpcCall.

@Test
public void testUserDefinedRpcCall() throws Exception {
    final ContainerNode root = Builders.containerBuilder().withNodeIdentifier(toId(SUBSCRIBE_RPC_NAME)).withChild(ImmutableNodes.leafNode(STREAM_NAME, "NETCONF")).build();
    final NetconfMessage message = messageTransformer.toRpcRequest(SUBSCRIBE_RPC_NAME, root);
    assertNotNull(message);
    final Document xmlDoc = message.getDocument();
    final org.w3c.dom.Node rpcChild = xmlDoc.getFirstChild();
    assertEquals(rpcChild.getLocalName(), "rpc");
    final org.w3c.dom.Node subscribeName = rpcChild.getFirstChild();
    assertEquals(subscribeName.getLocalName(), "subscribe");
    final org.w3c.dom.Node streamName = subscribeName.getFirstChild();
    assertEquals(streamName.getLocalName(), "stream-name");
}
Also used : NetconfMessage(org.opendaylight.netconf.api.NetconfMessage) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) Document(org.w3c.dom.Document) Test(org.junit.Test)

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