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);
*/
}
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);
}
}
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()));
}
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());
}
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());
}
Aggregations