Subject: [netmod] anydata

From: Ladislav Lhotka <[email-masked]>
Date: Tue, 14 Apr 2015 10:37:54 +0200

Hi,

I assume that, according to Y34-05, anydata node has to play the same
role as a container. That is, if we have

anydata foo;

then

"foo": {
  "bar": 42
}

is allowed but

"foo": 42

or

"foo": [1, 2]

is not.

Is it correct?

Thanks, Lada

-- 
Ladislav Lhotka, CZ.NIC Labs
PGP Key ID: E74E8C0C

---

From: Jernej Tuljak <[email-masked]>
Date: Tue, 14 Apr 2015 11:16:14 +0200

This would be a silly requirement, IMO. Especially since with

anyxml foo;

<foo>character data</foo>

or even

<foo bar="val">character data</foo>

are considered OK.

Anydata should be able to play a role of a container or a leaf, same as 
anyxml.

Jernej

---

From: Ladislav Lhotka <[email-masked]>
Date: Tue, 14 Apr 2015 11:26:41 +0200

> On 14 Apr 2015, at 11:16, Jernej Tuljak <[email-masked]> wrote:
> 
> Anydata should be able to play a role of a container or a leaf, same as anyxml.

But then for XML encoding there would essentially be no difference between anyxml and any data, right?

Lada

---

From: Juergen Schoenwaelder <[email-masked]>
Date: Tue, 14 Apr 2015 11:31:25 +0200

> But then for XML encoding there would essentially be no difference between anyxml and any data, right?

For the XML encoding, anydata is a true subset of anyxml.

/js

-- 
Juergen Schoenwaelder           Jacobs University Bremen gGmbH
Phone: +49 421 200 3587         Campus Ring 1 | 28759 Bremen | Germany
Fax:   +49 421 200 3103         <http://www.jacobs-university.de/>

---

From: Ladislav Lhotka <[email-masked]>
Date: Tue, 14 Apr 2015 11:33:51 +0200

> On 14 Apr 2015, at 11:31, Juergen Schoenwaelder <[email-masked]> wrote:
> 

So what’s your answer to my question?

Lada

---

From: Ladislav Lhotka <[email-masked]>
Date: Tue, 14 Apr 2015 11:36:52 +0200

> On 14 Apr 2015, at 11:33, Ladislav Lhotka <[email-masked]> wrote:
> 
>> 

To be specific, will the following be allowed for “anydata foo” in XML encoding?

<foo>42</foo>

Lada

---

From: Juergen Schoenwaelder <[email-masked]>
Date: Tue, 14 Apr 2015 11:38:45 +0200

> So what’s your answer to my question?

The answer was "for the XML encoding, anydata is a true subset of
anyxml".  Or in other words, it is not correct to say "there would
essentially be no difference between anyxml and any data" since anyxml
allows things like processing instructions, mixed content, etc. that
anydata does not allow. But if you look at only the subset that
anydata allows, then your statements becomes correct (perhaps this
was implicit in your statement - hard to tell).

/js

---

From: Juergen Schoenwaelder <[email-masked]>
Date: Tue, 14 Apr 2015 11:41:54 +0200

> To be specific, will the following be allowed for “anydata foo” in XML encoding?

Well, I have not seen the edits yet, but unless there are strong
reasons to not allow this, why should it not be legal to have a leaf
there?

/js

---

From: Ladislav Lhotka <[email-masked]>
Date: Tue, 14 Apr 2015 11:54:53 +0200

> On 14 Apr 2015, at 11:38, Juergen Schoenwaelder <[email-masked]> wrote:
> 

Does RFC 6020 prevent processing instructions (or XML comments, for that matter) from appearing *anywhere* in an XML instance document? I believe it is not so.

> was implicit in your statement - hard to tell).

Then I am questioning the meaning of “unknown chunk of data that can be modeled with YANG”. An isolated number like 42 cannot be modeled with YANG (or show me a module that does it).

Lada

---

From: Martin Bjorklund <[email-masked]>
Date: Tue, 14 Apr 2015 12:01:08 +0200 (CEST)

> reasons to not allow this, why should it not be legal to have a leaf

I would say that this is not valid.  Note that the data model was:

  anydata foo;

It would be encoded as an XML element "foo" with some unknown set of
nodes in it.  Just like anyxml.

/martin

---

From: Ladislav Lhotka <[email-masked]>
Date: Tue, 14 Apr 2015 13:40:09 +0200

> On 14 Apr 2015, at 12:01, Martin Bjorklund <[email-masked]> wrote:
> 

Just to clarify: if we have

anydata foo;
anyxml bar;

then <foo>42</foo> isn't allowed but <bar>42</bar> is. Correct?

Lada

---

From: Andy Bierman <[email-masked]>
Date: Tue, 14 Apr 2015 07:56:43 -0700

> then <foo>42</foo> isn't allowed but <bar>42</bar> is. Correct?

No -- anydata can be a leaf or a container.

> Lada

Andy

> _______________________________________________
> netmod mailing list
> [email-masked]
> https://www.ietf.org/mailman/listinfo/netmod

---

From: Ladislav Lhotka <[email-masked]>
Date: Tue, 14 Apr 2015 17:18:00 +0200

> On 14 Apr 2015, at 16:56, Andy Bierman <[email-masked]> wrote:
> 

Then here doesn’t seem to be consensus about what anydata is supposed to mean.

Lada

---

From: Andy Bierman <[email-masked]>
Date: Tue, 14 Apr 2015 09:05:47 -0700

> Then here doesn’t seem to be consensus about what anydata is supposed to mean.

I think there is consensus, but you don't agree with it.
Why do you think anydata must be a container?

anydata is just a tree of data nodes.  The derivative case is
a tree consisting of 1 leaf.  It doesn't really help much to worry about
the correct schema to use for a blob that has no schema.
It doesn't matter if 1 implementation thinks nodes are leafs
and another thinks they are leaf-lists.  There is no schema,
so nobody is right (or wrong) about the proper YANG data nodes
to use.

Don't expect any interoperability out of anydata.
The only difference from anyxml is that mixed mode XML
and processing instructions are not allowed.

Andy

---

From: Ladislav Lhotka <[email-masked]>
Date: Tue, 14 Apr 2015 18:42:18 +0200

> On 14 Apr 2015, at 18:05, Andy Bierman <[email-masked]> wrote:
> 

Martin also said <foo>42</foo> is not valid for “anydata foo”.  

> Why do you think anydata must be a container?

Because I thought that it was the *content* of an anydata instance that needs to be (potentially) modellable with YANG.

So you are essentially saying that anydata == anyxml minus mixed content, but this IMO doesn’t warrant introducing a new type of data node.

Lada

---

From: Andy Bierman <[email-masked]>
Date: Tue, 14 Apr 2015 13:29:53 -0700

> Because I thought that it was the *content* of an anydata instance that needs to be (potentially) modellable with YANG.

I suppose the data model should indicate whether a leaf makes sense
for the specific object.

> So you are essentially saying that anydata == anyxml minus mixed content, but this IMO doesn’t warrant introducing a new type of data node.

I don't think anydata is warranted at all, because nobody actually
implements anyxml as it is defined.  Some people who don't
even implement YANG insist everybody else should support
anyxml with mixed mode. Now we will bloat the standard and
double-down on anyxml -- not only MUST everybody implement it,
but we MUST implement 2 versions of it.

I am curious why anydata would be wonderful
if only it was restricted to be a container instead of
a container or a leaf.  It seems just as lame and misguided
to me with or without this restriction.

Andy

---

From: Kent Watsen <[email-masked]>
Date: Tue, 14 Apr 2015 21:17:04 +0000

>> Because I thought that it was the *content* of an anydata instance that
>>needs to be (potentially) modellable with YANG.

Y34-05 says:

   Introduce a new 'anydata' statement that represents an
   unknown chunk of data that can be modeled with YANG.

So let's say I have private YANG module foo:

   module foo {
     namespace "http://example.com/foo";
     leaf bar {
       type string;
     }
   }

Now let's say there is a some other YANG module inet-widgets:

   module inet-widgets {
      namespace "urn:ietf:params:xml:ns:yang:ietf-widgets";
      anydata opaque-data ;
   }

Then the XML would be:

  <opaque-data xmlns="urn:ietf:params:xml:ns:yang:ietf-widgets">
     <bar xmlns="http://example.com/foo">42</bar>
  </opaque-data>

Or in JSON:

   {
      "inet-widgets:opaque-data" : {
         "foo:bar" : 42
      }
   }

Correct?

Thanks,
Kent

---

From: Andy Bierman <[email-masked]>
Date: Tue, 14 Apr 2015 14:34:22 -0700

>       "inet-widgets:opaque-data" : {

correct for this data model.
Note that the client knows nothing about 'opaque-data'
so it has no reason to expect a container or a leaf.
An empty leaf and an empty container can look the
same in XML

But it us not hard for the server to check that anydata
can only be a container.  I don't have any strong use-cases
for allowing anydata to be a leaf.  Nor do I have reason
for forbidding it from being a leaf.

Maybe it is easier to understand your way.

   anydata == container of arbitrary YANG data nodes
   anyxml == mixed mode XML (we will pretend every server
    MUST support this, yet zero so far do that)

Andy

---

From: Ladislav Lhotka <[email-masked]>
Date: Wed, 15 Apr 2015 08:20:56 +0200

> On 14 Apr 2015, at 23:17, Kent Watsen <[email-masked]> wrote:
> 
> 

Right, this is exactly how I understand the Y34-05 wording. With this approach it is also easy to map XML<->JSON - otherwise we could have problems with mapping things like

"foo": [1, 2]

which maps to

<foo>1</foo>
<foo>2</foo>

(i.e. two anydata foo instances in XML).

Lada

---

From: Jernej Tuljak <[email-masked]>
Date: Wed, 15 Apr 2015 10:09:03 +0200

> (i.e. two anydata foo instances in XML).

A container or a leaf (!). The same as anyxml.

If anydata _content_ has a requirement that it must be modeled using 
YANG, then I agree with your original example. The anydata node must be 
a container. I don't agree this is the right way to do it however.

How would one model output of an RPC such as <get-schema> in 
ietf-netconf-monitoring using anydata for the XML encoding? The payload 
may contain character data where anydata now seems to require instances 
of YANG data nodes.

"foo": "character data"

should be legal.

One could even argue that both of these "represent an unknown chunk of 
data that can be modeled with YANG", therefore anydata may represent them.

Jernej

---

From: Ladislav Lhotka <[email-masked]>
Date: Wed, 15 Apr 2015 11:26:08 +0200

> On 15 Apr 2015, at 10:09, Jernej Tuljak <[email-masked]> wrote:
> 

But in JSON it’s different: if

"foo": 42

can be modelled in YANG, then arguably

"foo": [1,2]

can be modelled as well.

> 
> If anydata _content_ has a requirement that it must be modeled using YANG, then I agree with your original example. The anydata node must be a container. I don't agree this is the right way to do it however.
> 
> How would one model output of an RPC such as <get-schema> in ietf-netconf-monitoring using anydata for the XML encoding? The payload may contain character data where anydata now seems to require

I think this really requires anyxml because neither XSD nor RELAX NG (XML syntax) can be modelled with YANG - nor converted to JSON.

>  instances of YANG data nodes.
> 
> "foo": "character data"
> One could even argue that both of these "represent an unknown chunk of data that can be modeled with YANG", therefore anydata may represent them.

In this case, I’d prefer to just introduce “anydata” as a synonym for “anyxml”, deprecate the latter, and the guidelines document to say that anydata/anyxml SHOULD NOT use mixed content. Introducing a new data node type in YANG is quite a big change, and just getting rid of mixed content (which is BTW a problem only for XML encoding) is IMO not a sufficient reason.

I think it would work just fine. In every use case of anyxml/anydata I am aware of, it is not that the instance can contain really anything - the content always has to comply to some schema although it may be different for different servers or different RPC requests. In your <get-schema> example, the client definitely expects a schema in the requested format and not just arbitrary XML.

Lada

---

From: Martin Bjorklund <[email-masked]>
Date: Wed, 15 Apr 2015 14:29:50 +0200 (CEST)

> for forbidding it from being a leaf.

The anydata node is encoded as an XML element.  So if we have:

  anydata foo;

and the XML:

  <foo>42</foo>

it means that the contents of the anydata is not a leaf, but just a
value.

If we allowed this, should we also allow:

  <foo>42</foo>
  <foo>43</foo>

?  This gets complicated.

It is certainly ok for an anydata node to contain a leaf:

  <foo>
    <bar>42</bar>
  </foo>

>     MUST support this, yet zero so far do that)

Agree.

/martin

---

From: Ladislav Lhotka <[email-masked]>
Date: Wed, 15 Apr 2015 14:33:07 +0200

> On 15 Apr 2015, at 14:29, Martin Bjorklund <[email-masked]> wrote:
> 

+1

Lada

---

From: Martin Bjorklund <[email-masked]>
Date: Wed, 15 Apr 2015 14:33:47 +0200 (CEST)

Jernej Tuljak <[email-masked]> wrote:
> ietf-netconf-monitoring using anydata for the XML encoding?

You wouldn't, since the schema is not modelled in YANG.

If we want to avoid anyxml, you could model it as a string (makes an
YIN module look ugly over the wire, not a big issue maybe) or binary
(needs a decoder on the client).

/martin

---

From: Andy Bierman <[email-masked]>
Date: Wed, 15 Apr 2015 09:34:24 -0700

> (needs a decoder on the client).

I don't think anyxml can be avoided.
Modeling XML as a string is a non-starter.
The tools will treat the content as a string.  They have no
way of knowing that <get-schema> output is special
and &gt;foo&lt; must be converted to <foo> before using it.

The <get-schema> operation would continue to use anyxml I guess.

Andy

---

From: Ladislav Lhotka <[email-masked]>
Date: Thu, 16 Apr 2015 11:55:49 +0200

>    anydata == container of arbitrary YANG data nodes

Could we then agree on the following change to the wording of Y34-05?

OLD

   - Introduce a new 'anydata' statement that represents an unknown
     chunk of data that can be modeled with YANG

NEW

   - Introduce a new 'anydata' statement that represents a container
     whose content is an unknown chunk of data that can be modeled with
     YANG.

Lada

---

From: Juergen Schoenwaelder <[email-masked]>
Date: Fri, 17 Apr 2015 10:28:41 +0200

>      whose content is an unknown chunk of data that can be modeled with

OK for me.

/js