Search in sources :

Example 91 with NetconfMessage

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

the class ExiEncodeDecodeTest method encodeExi.

@Test
public void encodeExi() throws Exception {
    String startExiString = XmlFileLoader.xmlFileToString("netconfMessages/startExi.xml");
    assertNotNull(startExiString);
    NetconfMessage startExiMessage = XmlFileLoader.xmlFileToNetconfMessage(("netconfMessages/startExi.xml"));
    assertNotNull(startExiMessage);
/*
        ExiParameters exiParams = new ExiParameters();
        exiParams.setParametersFromXmlElement(XmlElement.fromDomElement(startExiMessage.getDocument()
        .getDocumentElement()));
        assertNotNull(exiParams);

        ByteBuf encodedBuf = Unpooled.buffer();
        ByteBuf sourceBuf = Unpooled.copiedBuffer(startExiString.getBytes());
        ExiUtil.encode(sourceBuf, encodedBuf, exiParams);

        List<Object> newOut = new ArrayList<Object>();
        ExiUtil.decode(encodedBuf, newOut, exiParams);

        ByteBuf decodedBuf = (ByteBuf)newOut.get(0);
        String decodedString = new String(decodedBuf.array(),"UTF-8");
        assertNotNull(decodedString);
        */
}
Also used : NetconfMessage(org.opendaylight.netconf.api.NetconfMessage) Test(org.junit.Test)

Example 92 with NetconfMessage

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

the class AbstractNetconfSessionNegotiator method replaceHelloMessageInboundHandler.

/**
 * Remove special inbound handler for hello message. Insert regular netconf xml message (en|de)coders.
 *
 * <p>
 * Inbound hello message handler should be kept until negotiation is successful
 * It caches any non-hello messages while negotiation is still in progress
 */
protected final void replaceHelloMessageInboundHandler(final S session) {
    ChannelHandler helloMessageHandler = replaceChannelHandler(channel, AbstractChannelInitializer.NETCONF_MESSAGE_DECODER, new NetconfXMLToMessageDecoder());
    checkState(helloMessageHandler instanceof NetconfXMLToHelloMessageDecoder, "Pipeline handlers misplaced on session: %s, pipeline: %s", session, channel.pipeline());
    Iterable<NetconfMessage> netconfMessagesFromNegotiation = ((NetconfXMLToHelloMessageDecoder) helloMessageHandler).getPostHelloNetconfMessages();
    // It means, we are now using the thread now
    for (NetconfMessage message : netconfMessagesFromNegotiation) {
        session.handleMessage(message);
    }
}
Also used : NetconfXMLToHelloMessageDecoder(org.opendaylight.netconf.nettyutil.handler.NetconfXMLToHelloMessageDecoder) NetconfMessage(org.opendaylight.netconf.api.NetconfMessage) NetconfXMLToMessageDecoder(org.opendaylight.netconf.nettyutil.handler.NetconfXMLToMessageDecoder) ChannelHandler(io.netty.channel.ChannelHandler)

Example 93 with NetconfMessage

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

the class NetconfEXIToMessageDecoder method decode.

@Override
protected void decode(final ChannelHandlerContext ctx, final ByteBuf in, final List<Object> out) throws IOException, SAXException, TransformerConfigurationException {
    // If empty Byte buffer is passed to r.parse, EOFException is thrown
    if (!in.isReadable()) {
        LOG.debug("No more content in incoming buffer.");
        return;
    }
    if (LOG.isTraceEnabled()) {
        LOG.trace("Received to decode: {}", ByteBufUtil.hexDump(in));
    }
    final TransformerHandler handler = FACTORY.newTransformerHandler();
    reader.setContentHandler(handler);
    final DOMResult domResult = new DOMResult(documentBuilder.newDocument());
    handler.setResult(domResult);
    try (InputStream is = new ByteBufInputStream(in)) {
        // Performs internal reset before doing anything
        reader.parse(new InputSource(is));
    }
    out.add(new NetconfMessage((Document) domResult.getNode()));
}
Also used : TransformerHandler(javax.xml.transform.sax.TransformerHandler) InputSource(org.xml.sax.InputSource) DOMResult(javax.xml.transform.dom.DOMResult) ByteBufInputStream(io.netty.buffer.ByteBufInputStream) InputStream(java.io.InputStream) NetconfMessage(org.opendaylight.netconf.api.NetconfMessage) ByteBufInputStream(io.netty.buffer.ByteBufInputStream) Document(org.w3c.dom.Document)

Example 94 with NetconfMessage

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

the class BaseRpcSchemalessTransformerTest method toRpcResult.

@Test
public void toRpcResult() throws Exception {
    final Document doc = XmlUtil.readXmlToDocument("<rpc-reply message-id=\"101\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\"/>");
    final InputStream stream = getClass().getResourceAsStream("/schemaless/get-config/container.xml");
    final Element dataElement = XmlUtil.readXmlToElement(stream);
    final Element element = (Element) doc.importNode(dataElement, true);
    doc.getDocumentElement().appendChild(element);
    final NetconfMessage msg = new NetconfMessage(doc);
    final DOMRpcResult result = transformer.toRpcResult(msg, NetconfMessageTransformUtil.NETCONF_GET_CONFIG_QNAME);
    assertNotNull(result.getResult());
    final ContainerNode rpcReply = (ContainerNode) result.getResult();
    assertEquals(NetconfMessageTransformUtil.NETCONF_RPC_REPLY_QNAME, rpcReply.getIdentifier().getNodeType());
    final Optional<?> dataOpt = rpcReply.findChildByArg(NetconfMessageTransformUtil.NETCONF_DATA_NODEID);
    assertTrue(dataOpt.isPresent());
    final DOMSourceAnyxmlNode data = (DOMSourceAnyxmlNode) dataOpt.get();
    final Diff diff = XMLUnit.compareXML(dataElement.getOwnerDocument(), (Document) data.body().getNode());
    assertTrue(diff.toString(), diff.similar());
}
Also used : DOMRpcResult(org.opendaylight.mdsal.dom.api.DOMRpcResult) DOMSourceAnyxmlNode(org.opendaylight.yangtools.yang.data.api.schema.DOMSourceAnyxmlNode) Diff(org.custommonkey.xmlunit.Diff) InputStream(java.io.InputStream) NetconfMessage(org.opendaylight.netconf.api.NetconfMessage) Element(org.w3c.dom.Element) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) Document(org.w3c.dom.Document) AbstractBaseSchemasTest(org.opendaylight.netconf.sal.connect.netconf.AbstractBaseSchemasTest) Test(org.junit.Test)

Example 95 with NetconfMessage

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

the class NetconfMessageTransformerTest method toActionRequestContainerInContainerTest.

@Test
public void toActionRequestContainerInContainerTest() {
    List<PathArgument> nodeIdentifiers = new ArrayList<>();
    nodeIdentifiers.add(NodeIdentifier.create(BOX_OUT_QNAME));
    nodeIdentifiers.add(NodeIdentifier.create(BOX_IN_QNAME));
    DOMDataTreeIdentifier domDataTreeIdentifier = prepareDataTreeId(nodeIdentifiers);
    ContainerNode payload = initInputAction(QName.create(BOX_OUT_QNAME, "start-at"), "now");
    NetconfMessage actionRequest = actionNetconfMessageTransformer.toActionRequest(OPEN_BOXES_PATH, domDataTreeIdentifier, payload);
    Node childAction = checkBasePartOfActionRequest(actionRequest);
    Node childBoxOut = childAction.getFirstChild();
    checkNode(childBoxOut, "box-out", "box-out", URN_EXAMPLE_SERVER_FARM);
    Node childBoxIn = childBoxOut.getFirstChild();
    checkNode(childBoxIn, "box-in", "box-in", URN_EXAMPLE_SERVER_FARM);
    Node action = childBoxIn.getFirstChild();
    checkNode(action, OPEN_QNAME.getLocalName(), OPEN_QNAME.getLocalName(), OPEN_QNAME.getNamespace().toString());
}
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) ArrayList(java.util.ArrayList) 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)

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