Search in sources :

Example 31 with NetconfMessage

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

the class NetconfHelloMessageToXMLEncoderTest method testEncodeNotHello.

@Test(expected = IllegalStateException.class)
public void testEncodeNotHello() throws Exception {
    final NetconfMessage msg = new NetconfMessage(XmlUtil.readXmlToDocument("<hello xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\"/>"));
    new NetconfHelloMessageToXMLEncoder().encode(ctx, msg, null);
}
Also used : NetconfMessage(org.opendaylight.netconf.api.NetconfMessage) Test(org.junit.Test)

Example 32 with NetconfMessage

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

the class SchemalessNetconfDeviceRpcTest method testInvokeRpc.

@Test
public void testInvokeRpc() throws Exception {
    final QName qName = QName.create("urn:ietf:params:xml:ns:netconf:base:1.0", "2011-06-01", "get-config");
    DOMSource src = new DOMSource(XmlUtil.readXmlToDocument("<get-config xmlns=\"dd\">\n" + "    <source>\n" + "      <running/>\n" + "    </source>\n" + "    <filter type=\"subtree\">\n" + "      <mainroot xmlns=\"urn:dummy:mod-0\">\n" + "        <maincontent/>\n" + "<choiceList></choiceList>\n" + "      </mainroot>\n" + "    </filter>\n" + "  </get-config>"));
    AnyxmlNode<?> input = Builders.anyXmlBuilder().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(qName)).withValue(src).build();
    deviceRpc.invokeRpc(qName, input);
    ArgumentCaptor<NetconfMessage> msgCaptor = ArgumentCaptor.forClass(NetconfMessage.class);
    ArgumentCaptor<QName> qnameCaptor = ArgumentCaptor.forClass(QName.class);
    verify(listener).sendRequest(msgCaptor.capture(), qnameCaptor.capture());
    LOG.info(XmlUtil.toString(msgCaptor.getValue().getDocument()));
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) QName(org.opendaylight.yangtools.yang.common.QName) NetconfMessage(org.opendaylight.netconf.api.NetconfMessage) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) AbstractBaseSchemasTest(org.opendaylight.netconf.sal.connect.netconf.AbstractBaseSchemasTest) Test(org.junit.Test)

Example 33 with NetconfMessage

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

the class NetconfBaseOpsTest method setUp.

@Before
public void setUp() throws Exception {
    final InputStream okStream = getClass().getResourceAsStream("/netconfMessages/rpc-reply_ok.xml");
    final InputStream dataStream = getClass().getResourceAsStream("/netconfMessages/rpc-reply_get.xml");
    final NetconfMessage ok = new NetconfMessage(XmlUtil.readXmlToDocument(okStream));
    final NetconfMessage data = new NetconfMessage(XmlUtil.readXmlToDocument(dataStream));
    when(listener.sendRequest(any(), eq(NetconfMessageTransformUtil.NETCONF_GET_CONFIG_QNAME))).thenReturn(RpcResultBuilder.success(data).buildFuture());
    when(listener.sendRequest(any(), eq(NetconfMessageTransformUtil.NETCONF_GET_QNAME))).thenReturn(RpcResultBuilder.success(data).buildFuture());
    when(listener.sendRequest(any(), eq(NetconfMessageTransformUtil.NETCONF_EDIT_CONFIG_QNAME))).thenReturn(RpcResultBuilder.success(ok).buildFuture());
    when(listener.sendRequest(any(), eq(NetconfMessageTransformUtil.NETCONF_COPY_CONFIG_QNAME))).thenReturn(RpcResultBuilder.success(ok).buildFuture());
    when(listener.sendRequest(any(), eq(NetconfMessageTransformUtil.NETCONF_DISCARD_CHANGES_QNAME))).thenReturn(RpcResultBuilder.success(ok).buildFuture());
    when(listener.sendRequest(any(), eq(NetconfMessageTransformUtil.NETCONF_VALIDATE_QNAME))).thenReturn(RpcResultBuilder.success(ok).buildFuture());
    when(listener.sendRequest(any(), eq(NetconfMessageTransformUtil.NETCONF_LOCK_QNAME))).thenReturn(RpcResultBuilder.success(ok).buildFuture());
    when(listener.sendRequest(any(), eq(NetconfMessageTransformUtil.NETCONF_UNLOCK_QNAME))).thenReturn(RpcResultBuilder.success(ok).buildFuture());
    when(listener.sendRequest(any(), eq(NetconfMessageTransformUtil.NETCONF_COMMIT_QNAME))).thenReturn(RpcResultBuilder.success(ok).buildFuture());
    final MessageTransformer<NetconfMessage> transformer = new NetconfMessageTransformer(new EmptyMountPointContext(SCHEMA_CONTEXT), true, BASE_SCHEMAS.getBaseSchema());
    final DOMRpcService rpc = new NetconfDeviceRpc(SCHEMA_CONTEXT, listener, transformer);
    final RemoteDeviceId id = new RemoteDeviceId("device-1", InetSocketAddress.createUnresolved("localhost", 17830));
    callback = new NetconfRpcFutureCallback("prefix", id);
    baseOps = new NetconfBaseOps(rpc, new EmptyMountPointContext(SCHEMA_CONTEXT));
}
Also used : NetconfDeviceRpc(org.opendaylight.netconf.sal.connect.netconf.sal.NetconfDeviceRpc) RemoteDeviceId(org.opendaylight.netconf.sal.connect.util.RemoteDeviceId) EmptyMountPointContext(org.opendaylight.yangtools.rfc8528.data.util.EmptyMountPointContext) DOMRpcService(org.opendaylight.mdsal.dom.api.DOMRpcService) InputStream(java.io.InputStream) NetconfMessage(org.opendaylight.netconf.api.NetconfMessage) NetconfMessageTransformer(org.opendaylight.netconf.sal.connect.netconf.schema.mapping.NetconfMessageTransformer) Before(org.junit.Before)

Example 34 with NetconfMessage

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

the class NetconfMessageTransformerTest method toActionRequestContainerTopLevelTest.

@Test
public void toActionRequestContainerTopLevelTest() {
    List<PathArgument> nodeIdentifiers = List.of(NodeIdentifier.create(DEVICE_QNAME));
    DOMDataTreeIdentifier domDataTreeIdentifier = prepareDataTreeId(nodeIdentifiers);
    ContainerNode payload = initInputAction(QName.create(DEVICE_QNAME, "start-at"), "now");
    NetconfMessage actionRequest = actionNetconfMessageTransformer.toActionRequest(START_DEVICE_PATH, domDataTreeIdentifier, payload);
    Node childAction = checkBasePartOfActionRequest(actionRequest);
    Node childDevice = childAction.getFirstChild();
    checkNode(childDevice, "device", "device", URN_EXAMPLE_SERVER_FARM);
    checkAction(START_QNAME, childDevice.getFirstChild(), "start-at", "start-at", "now");
}
Also used : DOMDataTreeIdentifier(org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier) NetconfMessage(org.opendaylight.netconf.api.NetconfMessage) MapNode(org.opendaylight.yangtools.yang.data.api.schema.MapNode) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) MapEntryNode(org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode) Node(org.w3c.dom.Node) UnkeyedListNode(org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListNode) AnyxmlNode(org.opendaylight.yangtools.yang.data.api.schema.AnyxmlNode) DOMSourceAnyxmlNode(org.opendaylight.yangtools.yang.data.api.schema.DOMSourceAnyxmlNode) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) PathArgument(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument) AbstractBaseSchemasTest(org.opendaylight.netconf.sal.connect.netconf.AbstractBaseSchemasTest) Test(org.junit.Test)

Example 35 with NetconfMessage

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

the class NetconfMessageTransformerTest method testGetConfigLeafRequest.

@Test
public void testGetConfigLeafRequest() throws Exception {
    final AnyxmlNode<?> filter = toFilterStructure(YangInstanceIdentifier.create(toId(NetconfState.QNAME), toId(Schemas.QNAME), toId(Schema.QNAME), NodeIdentifierWithPredicates.of(Schema.QNAME), toId(QName.create(Schemas.QNAME, "version"))), SCHEMA);
    final ContainerNode source = NetconfBaseOps.getSourceNode(NETCONF_RUNNING_QNAME);
    final NetconfMessage netconfMessage = netconfMessageTransformer.toRpcRequest(NETCONF_GET_CONFIG_QNAME, NetconfMessageTransformUtil.wrap(NETCONF_GET_CONFIG_QNAME, source, filter));
    assertSimilarXml(netconfMessage, "<rpc message-id=\"m-0\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n" + "<get-config xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n" + "<filter xmlns:ns0=\"urn:ietf:params:xml:ns:netconf:base:1.0\" ns0:type=\"subtree\">\n" + "<netconf-state xmlns=\"urn:ietf:params:xml:ns:yang:ietf-netconf-monitoring\">\n" + "<schemas>\n" + "<schema>\n" + "<version/>\n" + "</schema>\n" + "</schemas>\n" + "</netconf-state>\n" + "</filter>\n" + "<source>\n" + "<running/>\n" + "</source>\n" + "</get-config>\n" + "</rpc>");
}
Also used : NetconfMessage(org.opendaylight.netconf.api.NetconfMessage) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) AbstractBaseSchemasTest(org.opendaylight.netconf.sal.connect.netconf.AbstractBaseSchemasTest) 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