Subject: [netmod] 7.19.5. The when Statement

From: Andy Bierman <[email-masked]>
Date: Tue, 25 Nov 2008 09:40:28 -0800

Hi,

The context node definition for XPath evaluation of when statements
is not clear to me, and certainly not intuitive.  These are defined
in para 2, bullets 1-3.

It is clear that the schema nodes defined in an augment
which have XPath clauses (keyref, must, when) need to
be evaluated in the context of the augment target,
not within the body of the augment statement.

It is not intuitive that a when sub-statement of an augment
is evaluated in the context of the target as well.
The when-stmt for the augment itself says "Add the augment
payload only if this XPath expr is true".

There should be examples of when expressions in data nodes
and each type of non-data node, showing how the context node
moves from the current node.

(bullet 3, line 2 has a typo: s/teh/the)

Why is 'anyxml' considered a data node, which can be confusing,
since it cannot be the target of an augment?  Can must/when/leafref
expressions refer to anyxml nodes?  What about unnamed child nodes
of anyxml?  They are not present in a schema, so that should
not be allowed.

Is a key leaf allowed to be conditional at all (any ancestor-or-self
node with a when or if-feature clause)?  What about a mandatory node?

Do all nodes have to compile as if no conditionals are present?
This seems right, since the revision rules allow if-feature
and when to be removed but not added.

What happens if must or when XPath expressions refer to nodes
which are not present because they are part of an 'if-feature'
block which happens to be false for a given implementation?
If it happens in a must-stmt, then the config cannot ever
be committed.  Oh well.

All this conditional schema plus conditional runtime can get
complicated, and be a source of errors, maybe even automated
errors, which are the worst kind.  Just use the chainsaw
carefully....read the owners manual...practice on 2x4s
before attempting to fell a tree...

Andy

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

---

From: Martin Bjorklund <[email-masked]>
Date: Tue, 25 Nov 2008 21:29:26 +0100 (CET)

> is evaluated in the context of the target as well.

[...]

> moves from the current node.

I hope that an example will help.  I will add one or two examples.

> (bullet 3, line 2 has a typo: s/teh/the)

Fixed.

> expressions refer to anyxml nodes?

must and when, yes.  leafreaf no, since anyxml is not a leaf.

> What about unnamed child nodes

Agreed.  Since the anyxml is an unknown chunk of XML, how could it be
possible to name an unknown node...?

> node with a when or if-feature clause)?

No, and it needs to be clarified.

> What about a mandatory node?

Yes it can be conditional.  If the condition is true, then the node is
mandatory.

> Do all nodes have to compile as if no conditionals are present?

I don't know what "have to compile" means.  They have to be valid YANG
if that's what you meant.

> If it happens in a must-stmt, then the config cannot ever

We could say that it should be handled just as a must ref to
non-config from config, i.e. that any reference in the must/when MUST
NOT refer to a node which has a if-feature, unless the node with the
must also has the same if-feature.

But I don't think it's worth it.  A clever compiler can warn about
this.

/martin

---

From: Andy Bierman <[email-masked]>
Date: Tue, 25 Nov 2008 13:22:42 -0800

> I hope that an example will help.  I will add one or two examples.

good -- there is no text that specifies the context node
for when evaluation if the when-stmt is a child of a uses-stmt.
Since I'm trying to code this at the moment, some guidance
would help.  I still think this is all too complicated,
but the DM designer has to be careful, and never make
any XPath errors.

It seems that each cooked node (what I call a final-position
data node after all augment and uses have been expanded)
will have up to 3 when statements, each evaluated in
its own context:
     1) from the object itself
     2) from a uses-stmt that causes the grouping expansion
     3) from an augment-stmt that causes the augment expansion

Perhaps an example with an augment inside a uses, showing
when-stmts in the augment, uses, original grouping objects,
and target schema node tree, showing how the XPath
evaluation is done, and the evaluation order as well.

Andy

---

From: Andy Bierman <[email-masked]>
Date: Tue, 25 Nov 2008 18:12:17 -0800

> if that's what you meant.

So this is never allowed:

container dummy {
   uses G {
     when "some-expr";
   }
   uses G {
     when "not(some-expr)";
     refine x {...}
   }
}

OR

container dummy {
   leaf x {
     when "some-expr";
     type string;
   }
   leaf x {
     when "not(some-expr)";
     type float32;
   }
}

There are more scenarios like this, and I want to make
sure this sort of thing is invalid YANG.  We really should
avoid YANG modules that magically become invalid because
runtime values on the agent change.  That would be really
bad design.

> But I don't think it's worth it.  A clever compiler can warn about

Clever compilers are going to be mandatory, because YANG
is way too complicated now for even clever humans to
debug by inspection.

Andy