Subject: [netmod] Top-level choice (and uses) with a when sub-statement

From: Jernej Tuljak <[email-masked]>
Date: Mon, 13 Jan 2014 11:44:16 +0100

Just encountered some strangeness. Can top-level choice (uses) 
statements have when sub-statements? The latter don't appear to have a 
context node and therefore an accessible tree defined for the XPath 
expression.

In RFC6020, Section 7.19.5.

    o  If the "when" statement is a child of a "uses", "choice", or
       "case" statement, then the context node is the closest ancestor
       node to the "uses", "choice", or "case" node that is also a data
       node.

and later

The accessible tree depends on the context node

When combined with definition of a data node in Section 3.

    o  data node: A node in the schema tree that can be instantiated in a
       data tree.  One of container, leaf, leaf-list, list, and anyxml.

Note that top-level statements cannot have a data node ancestor (they 
are children of module or a submodule statement). I don't think the text 
above is correct, since there's no reason why top-level choice and uses 
statements should be prevented from being optional via a when statement. 
The context node should be the root node (document root) of the 
accessible tree, which should be determined the same as if the missing 
context node would represent state data.

Jernej

---

From: Martin Bjorklund <[email-masked]>
Date: Mon, 13 Jan 2014 11:59:34 +0100 (CET)

Jernej Tuljak <[email-masked]> wrote:
> are children of module or a submodule statement). I don't think the
> text above is correct, since there's no reason why top-level choice
> and uses statements should be prevented from being optional via a when
> statement. The context node should be the root node (document root) of
> the accessible tree, which should be determined the same as if the
> missing context node would represent state data.

I agree.

/martin

---

From: Jernej Tuljak <[email-masked]>
Date: Mon, 13 Jan 2014 12:06:37 +0100

>> missing context node would represent state data.

The first two bullets in 7.19.5. should be corrected with text that 
describes what happens when no data node ancestor can be found. They are 
both affected.

Jernej

---

From: Ladislav Lhotka <[email-masked]>
Date: Mon, 13 Jan 2014 13:38:04 +0100

On 13 Jan 2014, at 12:06, Jernej Tuljak <[email-masked]> wrote:

> The first two bullets in 7.19.5. should be corrected with text that describes what happens when no data node ancestor can be found. They are both affected.

The definition of “when” context has other problems that need to be addressed:

1. The XPath expression in the argument must not refer, even indirectly, to the context node and its descendants.

2. The context node in the third bullet may not exist. Example:

container top {
  leaf foo {
    type boolean;
  }
  leaf bar {
    when “../foo = ‘true’”;
    type uint8;
    default 42;
  }
}

Now, if the instance document contains

<top>
  <foo>false</foo>
</top>

we get into a deadlock: the “when” statement has no context node, so it cannot be evaluated and the “default” statement applies, but then the context node starts to exist, so the “when” statement applies, the server removes <bar> form the conceptual tree, and so on.

Lada  

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

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

---

From: Andy Bierman <[email-masked]>
Date: Mon, 13 Jan 2014 07:20:12 -0800

On Mon, Jan 13, 2014 at 4:38 AM, Ladislav Lhotka <[email-masked]> wrote:

> we get into a deadlock: the “when” statement has no context node, so it
> cannot be evaluated and the “default” statement applies, but then the
> context node starts to exist, so the “when” statement applies, the server
> removes <bar> form the conceptual tree, and so on.
>
>

These are just implementation details.

(1) is just a boolean XPath expression that is always false

(2) is just hard to implement. The server must know the XPath
evaluation result even though the context node does not exist yet.

> >> /martin

Andy

---

From: Ladislav Lhotka <[email-masked]>
Date: Mon, 13 Jan 2014 18:01:29 +0100

> (1) is just a boolean XPath expression that is always false

No, it can lead to deadlocks or race conditions, too. The action od deleting the node with "when" expression being "false" (mandated by last bullet in sec. 8.3.2) can lead to a situation where the same expression evaluates to "true". Perhaps the simplest case is:

container top {
  when "not(foo)";
  leaf foo {
    type uint8;
    default 0;
  }
}

But there can be also various mutual dependences that would be very hard to detect:

leaf foo {
  when "not(../bar)";
  type uint8;
  default 1;
}
leaf bar {
  when "not(../foo)";
  type uint8;
  default 2;
}

> evaluation result even though the context node does not exist yet.

But it is then a non-standard XPath evaluation. In practical terms, it renders all off-the-shelf XPath processors and libraries unusable.

Lada