Open wkz opened 1 year ago
Good observations.
The state API is somewhat problematic for several reasons, and is the reason that the docs is unclear.
(1) The first reason is that xpath filtering sometimes cannot be done transitively. In particular if an xpath is applied twice such as first in a callback and later in the generic get code. For example, an xpath such as: x[y='a']/z
where "y" is not a key. If applied twice on a structure such as <x><z>42</z><y>a</y><x>
will return NULL since the first xpath will remove the
Best examples are in existing system state functions, such as in https://github.com/clicon/clixon/blob/585823a6099783809f03a7c40652d9c6ea3acffd/apps/backend/backend_get.c#L202 and https://github.com/clicon/clixon/blob/585823a6099783809f03a7c40652d9c6ea3acffd/lib/src/clixon_netconf_monitoring.c#L246
Thanks for the detailed response. I'm new to all this, so I'll try to rephrase what you said in my own words, and hopefully you can let me know if I've understood:
Fundamentally, it's very hard to know, based only on the requested XPath, whether a particular leaf in the model needs to be included in a response or not. Presumably, this has to do with the fact that references may exist in other parts of the model, that either point directly at the leaf in question or any node above it.
Thus, state collection and inclusion can only be skipped in cases where:
- No such references can ever exist
- All such references are known by the plugin and can be matched using the requested XPath
If that is correct, let's say that I am implementing support for /ietf-system:system-state
in my plugin, let's also assume that no external references exist into that branch of the model. What would be the proper procedure to use xpath
and nsc
to check if something below /ietf-system:system-state
is requested or not?
yes that is correct. I need to come back with such an example. it is quite straightforward but may be some cornercases with the namespace prefixes, especially if you dont use canonical namespaces (= the prefixes as defined by the YANG prefix statements).
I am in the process of writing my first backend plugin for clixon (great project, btw!). Existing examples cover configuration data handling pretty thoroughly, but I'm having some trouble understanding how to know whether a
ca_statedata
callback is applicable to a particular plugin.From the documentation, it is clear that...
...but from what I can tell, all examples always generate their state data, and rely on the clixon core to filter out the superfluous data.
Are there any examples of how a plugin should perform this filtering?
It seems to me like the procedure should be something like:
xpath
andnsc
arguments, find the set of matching nodes in the model (fromclicon_dbspec_yang()
)xtop
Step 3 is obviously specific to each plugin, and 4 is well described in existing examples - but I have not found any examples of steps 1 and 2. Or maybe I've just completely misunderstood the proper way of doing this :smile:
Any hints on how to proceed would be much appreciated!