Subject: [netmod] WHEN statement within mandatory objects doesn't ensure presence of the mandatory object

From: Michael Rehder <[email-masked]>
Date: Tue, 9 Oct 2018 17:51:20 +0000

I have a question about “when” and mandatory objects.

It seems to me that the implemented semantics of “when” are really “optional when”, in that the enclosing object can be absent even though it is mandatory and the “when” clause holds true.
The RFC could be clearer about this.

Example

   leaf color {
     enumeration  {
        enum “blue”;
        enum “black”;
     }
     mandatory true;
   }
   container foo {
      when ../color = ‘blue’;
      etc.
   }

“foo” is optional due to the presence of the “when” statement even though the object is mandatory (same is true for mandatory leaf, min-elements=1 list etc.).
This is considered valid XML for the above
    <color>blue</color>

In my view this makes conditionally variant schemas “loose” in their enforcement (some scenarios can use choice but it doesn’t cover everything).

I think that mandatory should be respected for the enclosing objects of a “when” statement.
That is, a mandatory object must be present when its “when” clause holds true and a Schematron statement should enforce that.

What is the rationale behind the current YANG rules behavior, that the “when” Schematron mapping doesn’t check for presence of the enclosing mandatory object?

thanks
Mike Rehder

“Amdocs’ email platform is based on a third-party, worldwide, cloud-based system. Any emails sent to Amdocs will be processed and stored using such system and are accessible by third party providers of such system on a limited basis. Your sending of emails to Amdocs evidences your consent to the use of such system and such processing, storing and access”.

---

From: "Sterne, Jason (Nokia - CA/Ottawa)" <[email-masked]>
Date: Wed, 10 Oct 2018 13:49:07 +0000

Hi Mike,
Please see below.
Jason

From: netmod <[email-masked]> On Behalf Of Michael Rehder
Sent: Tuesday, October 9, 2018 1:51 PM
To: [email-masked]
Subject: [netmod] WHEN statement within mandatory objects doesn't ensure presence of the mandatory object

Example

   leaf color {
     enumeration  {
        enum “blue”;
        enum “black”;
     }
     mandatory true;
   }
   container foo {
      when ../color = ‘blue’;
      etc.
   }

“foo” is optional due to the presence of the “when” statement even though the object is mandatory (same is true for mandatory leaf, min-elements=1 list etc.).
[>>JTS: ]  What do you mean by "the object is mandatory" ?  I see that leaf color is mandatory (so it must have a value of either black or blue).  But the container foo is not mandatory.

I think that mandatory should be respected for the enclosing objects of a “when” statement.
That is, a mandatory object must be present when its “when” clause holds true and a Schematron statement should enforce that.
[>>JTS: ] We can't change that definition now. I don't know all the details of the rationale but "when" is defined such that its parent data definition statement is only valid when the condition in the "when" is true. But that doesn't mean that parent node is mandatory. In other words -> a "when" can only remove a node (from the schema), it can't enforce that a node exists (in instance data).

thanks
Mike Rehder

---

From: Ladislav Lhotka <[email-masked]>
Date: Wed, 10 Oct 2018 16:28:15 +0200

Michael Rehder <[email-masked]> writes:

> “foo” is optional due to the presence of the “when” statement even
> though the object is mandatory (same is true for mandatory leaf,
> min-elements=1 list etc.).

Maybe you intended to have, e.g., a "mandatory true" leaf inside
"container foo"?

> This is considered valid XML for the above

Yes, it is, under current YANG rules, no matter what "etc." stands
for. Note that evaluation of the XPath expression in this case (with
"foo" missing) requires the peculiar procedure of sec. 7.21.5 in RFC
7950.

>
> In my view this makes conditionally variant schemas “loose” in their
> enforcement (some scenarios can use choice but it doesn’t cover
> everything).
>
> I think that mandatory should be respected for the enclosing objects
> of a “when” statement.  That is, a mandatory object must be present
> when its “when” clause holds true and a Schematron statement should
> enforce that.

In fact, this is one case where the DSDL mapping (RFC 6110) deviates
from YANG 1.0. Nodes that mandatory aren't enclosed in the RELAX NG
<optional> pattern, and are then required no matter what any "when"
statements say (because RELAX NG validation comes before Schematron).  

>
> What is the rationale behind the current YANG rules behavior, that the
> “when” Schematron mapping doesn’t check for presence of the enclosing
> mandatory object?

FWIW, I have been repeatedly protesting against this behaviour but
without much luck. See for example

https://www.ietf.org/mail-archive/web/netmod/current/msg14012.html

As a result, "when" is the trickiest feature in YANG by far.

Lada

-- 
Ladislav Lhotka
Head, CZ.NIC Labs
PGP Key ID: 0xB8F92B08A9F76C67

---

From: Michael Rehder <[email-masked]>
Date: Wed, 10 Oct 2018 15:23:27 +0000

Container "foo" would be mandatory if not for the "when" child element.  
With the "when" child element, the logic becomes "inverted" and the constraint is a negative one of "disallowed under certain condition".

The UC is for enforcement in REST API payloads. 
For a practical example:

         leaf AssignmentMechanism {
            type enumeration {
              enum "DHCP";
              enum "Static";
            }
            mandatory true;
            description "The address assignment mechanism.";
          }
          list IPAddresses {
            when "../AssignmentMechanism = 'Static'";
            key Address;
            min-elements 1;
            
            leaf Address {
              type capit:IPv4Address;
              description "An ipv4 address.";
            }
           }

There is no way in the IPAddresses list to enforce that there is at least one IP Address when the assignment method is "Static".
One could put a "must" on "AssignmentMechanism" to ensure at least one element of the IPAddresses list when "Static", but I don't see this as a good schema design, to have the controlling attribute check controlled attributes.

I appreciate that this semantic can't be changed in YANG at this point.
Could the "when" statement have a modifying child element to state that the mandatory status of the element is to be enforced?
Like
    container foo {
      when "condition" {
          enforce-mandatory-status;
      }

There is already back-end for existential checks for mandatory choice so this seems reasonably consistent to me.
I appreciate there are existing issues for "when" but I don't see why this would make things any worse.
In fact by promoting a better dependency "direction" between schema elements,  think it could simplify things (so I naively think :) ).

Thanks
Mike
> -----Original Message-----
> From: Ladislav Lhotka [mailto:[email-masked]]
> Sent: Wednesday, October 10, 2018 10:28 AM
> To: Michael Rehder <[email-masked]>; [email-masked]
> Subject: Re: [netmod] WHEN statement within mandatory objects doesn't
> ensure presence of the mandatory object
> 
> > It seems to me that the implemented semantics of “when” are really
> “optional when”, in that the enclosing object can be absent even though it is
> mandatory and the “when” clause holds true.
> Maybe you intended to have, e.g., a "mandatory true" leaf inside "container
> foo"?
> 
> Yes, it is, under current YANG rules, no matter what "etc." stands for. Note that
> evaluation of the XPath expression in this case (with "foo" missing) requires the
> peculiar procedure of sec. 7.21.5 in RFC 7950.
> 
> >
> In fact, this is one case where the DSDL mapping (RFC 6110) deviates from
> YANG 1.0. Nodes that mandatory aren't enclosed in the RELAX NG <optional>
> pattern, and are then required no matter what any "when"
> FWIW, I have been repeatedly protesting against this behaviour but without
> much luck. See for example
>

---

From: Robert Wilton <[email-masked]>
Date: Wed, 10 Oct 2018 16:33:01 +0100

Hi Mike,

I think that the YANG below already enforces what you want, or otherwise 
I don't follow your issue.

The YANG below is valid in two cases:

(1) AssignmentMechanism = DHCP, and IPAddresses is not present in the 
config (due to the when statement).
(2) AssignmentMechanism = Static, IPAddresses exists and has at least 
one element (due to min-elements 1).

Thanks,
Rob

On 10/10/2018 16:23, Michael Rehder wrote:
> _______________________________________________
> netmod mailing list
> [email-masked]
> https://www.ietf.org/mailman/listinfo/netmod

---

From: Ladislav Lhotka <[email-masked]>
Date: Wed, 10 Oct 2018 17:43:12 +0200

On Wed, 2018-10-10 at 15:23 +0000, Michael Rehder wrote:
> With the "when" child element, the logic becomes "inverted" and the constraint
> is a negative one of "disallowed under certain condition".
> 
> There is no way in the IPAddresses list to enforce that there is at least one
> IP Address when the assignment method is "Static".

Why do you think there is no way? For example, according to sec. 10.28 of RFC
6110, then "min-elements 1" statement is mapped to the RELAX NG pattern

<oneOrMore>

which enforces the presence of at least one entry of IPAddresses.

>From the DSDL point of view, the problem is rather the opposite: at least one
entry will be required during RELAX NG validation even if AssignmentMechanism is
"DHCP".

Lada

> One could put a "must" on "AssignmentMechanism" to ensure at least one element
> of the IPAddresses list when "Static", but I don't see this as a good schema
> design, to have the controlling attribute check controlled attributes.
> 
> Could the "when" statement have a modifying child element to state that the
> mandatory status of the element is to be enforced?
> Like
>     container foo {
>       when "condition" {
> In fact by promoting a better dependency "direction" between schema
> elements,  think it could simplify things (so I naively think :) ).
> 
> Thanks
> Mike
> “Amdocs’ email platform is based on a third-party, worldwide, cloud-based
> system. Any emails sent to Amdocs will be processed and stored using such
> system and are accessible by third party providers of such system on a limited
> basis. Your sending of emails to Amdocs evidences your consent to the use of
> such system and such processing, storing and access”.

---

From: Michael Rehder <[email-masked]>
Date: Wed, 10 Oct 2018 18:17:26 +0000

If the list has a "when" clause the RNG file actually produces a "OneOrMore" which has a choice of <empty> or the list so it actually doesn't enforce the presence at least one row of the list (unless I'm mistaken in my reading).
              <oneOrMore>
                <choice>
                  <empty/>
                  <element name="IPAddresses">
                    <element name="Address">
                      <ref name="types__IPv4Address"/>
                    </element>
                    <empty/>
                  </element>
                </choice>
              </oneOrMore>

A leaf/container would be a simpler example but would result in the same lack of enforcement of the mandatory status of an element with a "when" clause.

This RNG seems consistent with the Schematron rules that "when" makes something optional.

I think a workaround would be choice with mandatory true and a when clause on the cases. This would ensure that at least one case is present since the mandatory clause implements a Schematron existence constraint.

Thanks
Mike
> From: Robert Wilton [mailto:[email-masked]]
> Sent: Wednesday, October 10, 2018 11:33 AM
> To: Michael Rehder <[email-masked]>; Ladislav Lhotka
> <[email-masked]>; [email-masked]
> Cc: Walker, Jason ([email-masked])
> <[email-masked]>
> I think that the YANG below already enforces what you want, or otherwise I
> don't follow your issue.
> 
> (1) AssignmentMechanism = DHCP, and IPAddresses is not present in the config
> (due to the when statement).
> (2) AssignmentMechanism = Static, IPAddresses exists and has at least one
> element (due to min-elements 1).
> 
> Thanks,
> Rob
> 
> 
> > With the "when" child element, the logic becomes "inverted" and the
> constraint is a negative one of "disallowed under certain condition".
> >
> > There is no way in the IPAddresses list to enforce that there is at least one IP
> Address when the assignment method is "Static".
> > One could put a "must" on "AssignmentMechanism" to ensure at least one
> element of the IPAddresses list when "Static", but I don't see this as a good
> schema design, to have the controlling attribute check controlled attributes.
> >
> >> “optional when”, in that the enclosing object can be absent even
> >> though it is mandatory and the “when” clause holds true.
> >> "foo" missing) requires the peculiar procedure of sec. 7.21.5 in RFC 7950.
> >>
> >>> What is the rationale behind the current YANG rules behavior, that
> >>> the “when” Schematron mapping doesn’t check for presence of the
> >>> enclosing mandatory object?

---

From: Juergen Schoenwaelder <[email-masked]>
Date: Wed, 10 Oct 2018 20:25:29 +0200

Michael,

what matters here is what the YANG specification (RFC 7950) says. Is
there a reason to believe the IPAddresses list in your example can be
absent or have no elements based on what RFC 7950 says? Or do we talk
about a shortcoming of RFC 6110?

/js

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

---

From: Michael Rehder <[email-masked]>
Date: Wed, 10 Oct 2018 18:44:18 +0000

Sure.

I think the RFC is unclear since it seems that the semantics are consistent in the back-end checks.
One can read the RFC and not notice by its absence that the when clause doesn't require anything to be present.

     The "when" statement makes its parent data definition statement conditional.
Should be
    The "when" statement makes its parent data definition statement conditional and optional.

I think there should be a more definite statement about this overriding any mandatory status of the parent data definition statement.
Like
     "Any mandatory status of the parent data definition statement (mandatory statement, min-element statement etc.) is overridden by this statement and made non-mandatory."

That would have made the side-effect of "when" on other declarations clearer.

Thanks
mike
> From: Juergen Schoenwaelder [mailto:[email-masked]]
> Sent: Wednesday, October 10, 2018 2:25 PM
> To: Michael Rehder <[email-masked]>
> Cc: Robert Wilton <[email-masked]>; Ladislav Lhotka <[email-masked]>;
> [email-masked]; Walker, Jason ([email-masked])
> what matters here is what the YANG specification (RFC 7950) says. Is there a
> reason to believe the IPAddresses list in your example can be absent or have no
> elements based on what RFC 7950 says? Or do we talk about a shortcoming of
> RFC 6110?
> 
> /js
> 
> > If the list has a "when" clause the RNG file actually produces a "OneOrMore"
> which has a choice of <empty> or the list so it actually doesn't enforce the
> presence at least one row of the list (unless I'm mistaken in my reading).
> >               <oneOrMore>
> >                 <choice>
> >                   <empty/>
> > A leaf/container would be a simpler example but would result in the same
> lack of enforcement of the mandatory status of an element with a "when"
> clause.
> >
> > I think a workaround would be choice with mandatory true and a when clause
> on the cases. This would ensure that at least one case is present since the
> mandatory clause implements a Schematron existence constraint.
> >
> > Thanks
> > Mike
> > > Subject: Re: [netmod] WHEN statement within mandatory objects
> > > doesn't ensure presence of the mandatory object
> > >
> > > Hi Mike,
> > >
> > > I think that the YANG below already enforces what you want, or
> > > otherwise I don't follow your issue.
> > >
> > > (1) AssignmentMechanism = DHCP, and IPAddresses is not present in
> > > the config (due to the when statement).
> > > (2) AssignmentMechanism = Static, IPAddresses exists and has at
> > > least one element (due to min-elements 1).
> > >
> > > Thanks,
> > > Rob
> > >
> > >
> > > element of the IPAddresses list when "Static", but I don't see this
> > > as a good schema design, to have the controlling attribute check controlled
> attributes.
> > > >
> > > > There is already back-end for existential checks for mandatory
> > > > choice so this
> > > seems reasonably consistent to me.
> > > > I appreciate there are existing issues for "when" but I don't see
> > > > why this
> > > would make things any worse.
> > > >> Subject: Re: [netmod] WHEN statement within mandatory objects
> > > >> doesn't ensure presence of the mandatory object
> > > >>
> > > >>> “foo” is optional due to the presence of the “when” statement
> > > >>> even though the object is mandatory (same is true for mandatory
> > > >>> leaf,
> > > >> Yes, it is, under current YANG rules, no matter what "etc."
> > > >> stands for. Note that evaluation of the XPath expression in this
> > > >> case (with "foo" missing) requires the peculiar procedure of sec. 7.21.5
> in RFC 7950.
> > > >>
> > > >>> In my view this makes conditionally variant schemas “loose” in
> > > >>> their enforcement (some scenarios can use choice but it doesn’t
> > > >>> cover everything).
> > > >>>
> > > >>> I think that mandatory should be respected for the enclosing
> > > >>> objects of a “when” statement.  That is, a mandatory object must
> > > >>> be present when its “when” clause holds true and a Schematron
> > > >>> statement should enforce that.
> > > >> In fact, this is one case where the DSDL mapping (RFC 6110)
> > > >> deviates from YANG 1.0. Nodes that mandatory aren't enclosed in
> > > >> the RELAX NG <optional> pattern, and are then required no matter what
> any "when"
> > > >>> What is the rationale behind the current YANG rules behavior,
> > > >>> that the “when” Schematron mapping doesn’t check for presence of
> > > >>> the enclosing mandatory object?
> > > >> FWIW, I have been repeatedly protesting against this behaviour
> > > >> but without much luck. See for example
> > > >>
> > > system. Any emails sent to Amdocs will be processed and stored using
> > > such system and are accessible by third party providers of such
> > > system on a limited basis. Your sending of emails to Amdocs
> > > evidences your consent to the use of such system and such processing,
> storing and access”.

---

From: Andy Bierman <[email-masked]>
Date: Wed, 10 Oct 2018 11:51:39 -0700

> conditional and optional.
This is not correct.

Step 1) if-feature makes the schema node conditional

Step 2) when-stmt makes instances of the schema-node conditional

Step 3) YANG validation applies to instances of data nodes (or the YANG
default value if applicable)

Step 2 is only relevant if Step 1 is true or non-existent
Step 3 is only relevant if Step 2 is true or non-existent

Andy

> I think there should be a more definite statement about this overriding
> any mandatory status of the parent data definition statement.
> Like
>      "Any mandatory status of the parent data definition statement
> (mandatory statement, min-element statement etc.) is overridden by this
> statement and made non-mandatory."
>
> there a
> system and are accessible by third party providers of such system on a
> limited basis. Your sending of emails to Amdocs evidences your consent to
> the use of such system and such processing, storing and access”.

---

From: Ladislav Lhotka <[email-masked]>
Date: Thu, 11 Oct 2018 07:58:46 +0200

> conditional and optional.

Data nodes in YANG are optional by default and become mandatory only in certain
cases (in RFC 6020 these cases were specified in section 3.1). In contrast,
RELAX NG <element> patterns are mandatory by default and <optional> is used to
make them optional.

Lada

> 
> I think there should be a more definite statement about this overriding any
> mandatory status of the parent data definition statement.
> Like
>      "Any mandatory status of the parent data definition statement (mandatory
> statement, min-element statement etc.) is overridden by this statement and
> made non-mandatory."
> 
> > limited

---

From: Michael Rehder <[email-masked]>
Date: Thu, 11 Oct 2018 18:00:16 +0000

I think the wording is relevant - something can be conditional but still required.
It should be clarified that elements become implicitly “mandatory false” when a “when” statement is used.

I would like to see an enhancement to YANG to control this behavior, to allow the mandatory status to be enforced.
That is, support also “conditionally required” instead of only the current “conditionally optional”.

Thanks
Mike

From: Andy Bierman [mailto:[email-masked]]
Sent: Wednesday, October 10, 2018 2:52 PM
To: Michael Rehder <[email-masked]>
Cc: Juergen Schoenwaelder <[email-masked]>; Walker, Jason ([email-masked]) <[email-masked]>; [email-masked]
Subject: Re: [netmod] WHEN statement within mandatory objects doesn't ensure presence of the mandatory object

On Wed, Oct 10, 2018 at 11:44 AM, Michael Rehder <[email-masked]<mailto:[email-masked]>> wrote:
Sure.

This is not correct.

Step 3) YANG validation applies to instances of data nodes (or the YANG default value if applicable)

Andy

Thanks
mike
> From: Juergen Schoenwaelder [mailto:[email-masked]<mailto:[email-masked]>]
> To: Michael Rehder <[email-masked]<mailto:[email-masked]>>
> Cc: Robert Wilton <[email-masked]<mailto:[email-masked]>>; Ladislav Lhotka <[email-masked]<mailto:[email-masked]>>;
> [email-masked]<mailto:[email-masked]>; Walker, Jason ([email-masked]<mailto:[email-masked]>)
> <[email-masked]<mailto:[email-masked]>>
> > > From: Robert Wilton [mailto:[email-masked]<mailto:[email-masked]>]
> > > To: Michael Rehder <[email-masked]<mailto:[email-masked]>>; Ladislav Lhotka
> > > <[email-masked]<mailto:[email-masked]>>; [email-masked]<mailto:[email-masked]>
> > > Cc: Walker, Jason ([email-masked]<mailto:[email-masked]>)
> > > <[email-masked]<mailto:[email-masked]>>
> > > >> From: Ladislav Lhotka [mailto:[email-masked]<mailto:[email-masked]>]
> > > >> To: Michael Rehder <[email-masked]<mailto:[email-masked]>>; [email-masked]<mailto:[email-masked]>
> > > >> Michael Rehder <[email-masked]<mailto:[email-masked]>> writes:
> > > >>
> > > > [email-masked]<mailto:[email-masked]>
> > [email-masked]<mailto:[email-masked]>
“Amdocs’ email platform is based on a third-party, worldwide, cloud-based system. Any emails sent to Amdocs will be processed and stored using such system and are accessible by third party providers of such system on a limited basis. Your sending of emails to Amdocs evidences your consent to the use of such system and such processing, storing and access”.
_______________________________________________
netmod mailing list
[email-masked]<mailto:[email-masked]>
https://www.ietf.org/mailman/listinfo/netmod

---

From: Andy Bierman <[email-masked]>
Date: Thu, 11 Oct 2018 11:05:35 -0700

On Thu, Oct 11, 2018 at 11:00 AM, Michael Rehder <[email-masked]>
wrote:

> I would like to see an enhancement to YANG to control this behavior, to
> allow the mandatory status to be enforced.
>

  leaf foo {
     when "../some-other-node = 5";
     type int32;
     mandatory true;
 }

This leaf is mandatory if the when-expr is true.
Where is the text in 7950 that says this mandatory true is ignored if
when-stmt is present?

Thanks

Andy

>
>
> *From:* Andy Bierman [mailto:[email-masked]]
> *Sent:* Wednesday, October 10, 2018 2:52 PM
> *To:* Michael Rehder <[email-masked]>
> *Cc:* Juergen Schoenwaelder <[email-masked]>;
> Walker, Jason ([email-masked]) <[email-masked]>;
> [email-masked]
> *Subject:* Re: [netmod] WHEN statement within mandatory objects doesn't
> On Wed, Oct 10, 2018 at 11:44 AM, Michael Rehder <
> [email-masked]> wrote:
>
> Sure.
>
> <https://maps.google.com/?q=Campus+Ring+1+%7C+28759+Bremen+%7C+Germany&entry=gmail&source=g>
> *“Amdocs’ email platform is based on a third-party, worldwide, cloud-based
> the use of such system and such processing, storing and access”.*
>

---

From: Michael Rehder <[email-masked]>
Date: Thu, 11 Oct 2018 18:14:31 +0000

There is no specific text - the text just says it is “conditional”.
However the implementation forces it optional:

-          The RNG file makes it optional (I’m not actually running this for various reasons so I’m just interpreting the file generated – maybe I misunderstand RNG)

-          Schematron doesn’t check for its existence (like it does for a mandatory choice case)

Thanks
Mike

Sent: Thursday, October 11, 2018 2:06 PM

On Thu, Oct 11, 2018 at 11:00 AM, Michael Rehder <[email-masked]<mailto:[email-masked]>> wrote:
I think the wording is relevant - something can be conditional but still required.
It should be clarified that elements become implicitly “mandatory false” when a “when” statement is used.

  leaf foo {

This leaf is mandatory if the when-expr is true.
Where is the text in 7950 that says this mandatory true is ignored if when-stmt is present?

Thanks
Mike

Andy

From: Andy Bierman [mailto:[email-masked]<mailto:[email-masked]>]
Sent: Wednesday, October 10, 2018 2:52 PM
To: Michael Rehder <[email-masked]<mailto:[email-masked]>>
Cc: Juergen Schoenwaelder <[email-masked]<mailto:[email-masked]>>; Walker, Jason ([email-masked]<mailto:[email-masked]>) <[email-masked]<mailto:[email-masked]>>; [email-masked]<mailto:[email-masked]>
Subject: Re: [netmod] WHEN statement within mandatory objects doesn't ensure presence of the mandatory object

This is not correct.

Andy

Thanks
mike
> Phone: +49 421 200 3587         Campus Ring 1 | 28759 Bremen | Germany<https://maps.google.com/?q=Campus+Ring+1+%7C+28759+Bremen+%7C+Germany&entry=gmail&source=g>

---

From: Andy Bierman <[email-masked]>
Date: Thu, 11 Oct 2018 11:48:12 -0700

On Thu, Oct 11, 2018 at 11:14 AM, Michael Rehder <[email-masked]>
wrote:

> -          The RNG file makes it optional (I’m not actually running this
> for various reasons so I’m just interpreting the file generated – maybe I
> misunderstand RNG)
>

So change the implementation so it conforms to the spec.

Andy

> *Sent:* Thursday, October 11, 2018 2:06 PM
> On Thu, Oct 11, 2018 at 11:00 AM, Michael Rehder <

---

From: Michael Rehder <[email-masked]>
Date: Fri, 12 Oct 2018 14:07:23 +0000

It depends what’s meant by “Conditional”. I think the term is distinct from “Optional”.

I don’t think the implementation can be changed (unless you meant that I change my own local implementation).

That’s why I think there should be a YANG language addition to control this behavior, since there are valid use cases for it.
Adding options to the WHEN statement seems a reasonable way to do this.

Thanks
Mike

Sent: Thursday, October 11, 2018 2:48 PM

On Thu, Oct 11, 2018 at 11:14 AM, Michael Rehder <[email-masked]<mailto:[email-masked]>> wrote:
There is no specific text - the text just says it is “conditional”.
However the implementation forces it optional:

Thanks
Mike

Andy

  leaf foo {

Thanks
Mike

Andy

This is not correct.

Andy

Thanks
mike

---

From: Robert Wilton <[email-masked]>
Date: Fri, 12 Oct 2018 17:05:36 +0100

Hi Mike,

On 11/10/2018 19:05, Andy Bierman wrote:
>
>
> On Thu, Oct 11, 2018 at 11:00 AM, Michael Rehder 
> <[email-masked] <mailto:[email-masked]>> wrote:
>
Yes, but I think that this is already expressed by a node that has both 
a when condition and mandatory statement.

container a {
   container x {
     when "some condition";
     leaf foo {
       mandatory true;
     }
     leaf bar {
       ...
     }
   }
   container y {
     leaf baz {
       mandatory true;
     }
     leaf tee {
       ...
     }
   }
}

a/x/foo is conditional (due to when) but required (if the when condition is met).
a/x/bar is conditional (due to when) but optional (if the when condition is met).
a/y/baz is unconditional but required.
a/y/tee is unconditional but optional.

>     false” when a “when” statement is used.
But they don't.

>     I would like to see an enhancement to YANG to control this
>     behavior, to allow the mandatory status to be enforced.
>
I'm trying to understand what this would even mean.

Taking your original example, but with "enforce-mandatory-status":

          leaf AssignmentMechanism {
             type enumeration {
               enum "DHCP";
               enum "Static";
             }
             mandatory true;
             description "The address assignment mechanism.";
           }
           list IPAddresses {
             when "../AssignmentMechanism = 'Static'" {
               enforce-mandatory-status;
             }  key Address;
             min-elements 1;
             
             leaf Address {
               type capit:IPv4Address;

So this means that list IPaddresses must have at least one element 
regardless of whether the when condition holds.  I.e. no matter whether 
the assignment is DHCP or Static there must always be at least one 1 
address configured.  But I don't understand what this actually means - 
it seems like a contradiction.  What am I missing? Please can you give a 
concrete example (in YANG) of what behaviour you are looking for.

Thanks,
Rob

---

From: Michael Rehder <[email-masked]>
Date: Fri, 12 Oct 2018 16:08:48 +0000

The mandatory statement in that case is ignored (I’ve pointed out the RNG and Schematron lack of enforcement).
WHEN trumps the mandatory status (via explicit mandatory or implicit mandatory via min-elements 1)

Thanks
Mike

From: Robert Wilton [mailto:[email-masked]]
Sent: Friday, October 12, 2018 12:06 PM
To: Michael Rehder <[email-masked]>
Cc: Andy Bierman <[email-masked]>; Walker, Jason ([email-masked]) <[email-masked]>; [email-masked]
Subject: Re: [netmod] WHEN statement within mandatory objects doesn't ensure presence of the mandatory object

Hi Mike,

On Thu, Oct 11, 2018 at 11:00 AM, Michael Rehder <[email-masked]<mailto:[email-masked]>> wrote:
I think the wording is relevant - something can be conditional but still required.
Yes, but I think that this is already expressed by a node that has both a when condition and mandatory statement.

container a {

  container x {

    when "some condition";

    leaf foo {

      mandatory true;

    }

    leaf bar {

      ...

    }

  }

  container y {

    leaf baz {

      mandatory true;

    }

    leaf tee {

      ...

    }

  }

}

            type enumeration {

              enum "DHCP";

              enum "Static";

            }

            mandatory true;

          }

          list IPAddresses {

            }  key Address;

            min-elements 1;

            leaf Address {

              type capit:IPv4Address;

            }

           }

So this means that list IPaddresses must have at least one element regardless of whether the when condition holds.  I.e. no matter whether the assignment is DHCP or Static there must always be at least one 1 address configured.  But I don't understand what this actually means - it seems like a contradiction.  What am I missing?  Please can you give a concrete example (in YANG) of what behaviour you are looking for.

Thanks,
Rob

---

From: Andy Bierman <[email-masked]>
Date: Fri, 12 Oct 2018 09:29:06 -0700

> mandatory via min-elements 1)

Implementation of the when-stmt is complicated, especially if the server is
expected to be fast.
RFC 7950 has many more details than RFC 6020 about implementation of this
statement,
but it is still difficult.

The schema dictates what can be in the instance documents. The when-stmt
modifies the
schema based on what is in the instance document.  Even the default value
goes away if the
when-stmt is false (as it should). I would be very surprised if static
document validation tools could handle that.

YANG validation is already heavyweight and complex to implement.
Allowing designers to pick and choose when which constraints are active,
would make much more complex.

Andy

>
>
> *From:* Robert Wilton [mailto:[email-masked]]
> *Sent:* Friday, October 12, 2018 12:06 PM
> *Cc:* Andy Bierman <[email-masked]>; Walker, Jason (
> [email-masked]) <[email-masked]>; [email-masked]
> regardless of whether the when condition holds.  I.e. no matter whether the
> assignment is DHCP or Static there must always be at least one 1 address
> configured.  But I don't understand what this actually means - it seems
> like a contradiction.  What am I missing?  Please can you give a concrete
> example (in YANG) of what behaviour you are looking for.
>
> Thanks,
> Rob
>

---

From: Robert Wilton <[email-masked]>
Date: Fri, 12 Oct 2018 17:30:05 +0100

> RNG and Schematron lack of enforcement).
OK, I'm not familiar with RNG and Schematron.

> mandatory via min-elements 1)
So I think that you are asking for mandatory to trump a when condition.  
Can you provide a concrete example where this is required, or even useful?

A solution here, that doesn't require any changes in the YANG language, 
would be to just move the when condition, down to each of the child 
nodes that are not marked as mandatory.

But, sorry, at the moment I'm still at a loss to see how where this 
would actually be useful.

Thanks,
Rob

> Thanks
>
> Mike
>
> *From:*Robert Wilton [mailto:[email-masked]]
> *Cc:* Andy Bierman <[email-masked]>; Walker, Jason 
> ([email-masked]) <[email-masked]>; [email-masked]
> *Subject:* Re: [netmod] WHEN statement within mandatory objects 
> Yes, but I think that this is already expressed by a node that has 
> both a when condition and mandatory statement.
>
>
> container a {
>    container x {
>      when "some condition";
>      leaf foo {
>        mandatory true;
>      }
>      leaf bar {
>        ...
>      }
>    }
>    container y {
>      leaf baz {
>        mandatory true;
>      }
>      leaf tee {
>        ...
>      }
>    }
> }
>         It should be clarified that elements become implicitly
>         “mandatory false” when a “when” statement is used.
>
> But they don't.
>
>
> it seems like a contradiction.  What am I missing?  Please can you 
> give a concrete example (in YANG) of what behaviour you are looking for.
>
> Thanks,
> Rob
>
> /“Amdocs’ email platform is based on a third-party, worldwide, 
> cloud-based system. Any emails sent to Amdocs will be processed and 
> stored using such system and are accessible by third party providers 
> of such system on a limited basis. Your sending of emails to Amdocs 
> storing and access”./

---

From: Michael Rehder <[email-masked]>
Date: Fri, 12 Oct 2018 19:14:51 +0000

I provided an example.
Requiring something to be present when a condition is to me a useful capability.
How else would you enforce in an optimal way that something is present under only certain conditions (define it on the controlled section, not use a zillion if-feature)?

Thanks
Mike

Sent: Friday, October 12, 2018 12:30 PM

WHEN trumps the mandatory status (via explicit mandatory or implicit mandatory via min-elements 1)
So I think that you are asking for mandatory to trump a when condition.  Can you provide a concrete example where this is required, or even useful?

A solution here, that doesn't require any changes in the YANG language, would be to just move the when condition, down to each of the child nodes that are not marked as mandatory.

But, sorry, at the moment I'm still at a loss to see how where this would actually be useful.

Thanks,
Rob

Thanks
Mike

From: Robert Wilton [mailto:[email-masked]]
Sent: Friday, October 12, 2018 12:06 PM
To: Michael Rehder <[email-masked]><mailto:[email-masked]>
Cc: Andy Bierman <[email-masked]><mailto:[email-masked]>; Walker, Jason ([email-masked]<mailto:[email-masked]>) <[email-masked]><mailto:[email-masked]>; [email-masked]<mailto:[email-masked]>
Subject: Re: [netmod] WHEN statement within mandatory objects doesn't ensure presence of the mandatory object

Hi Mike,

container a {

  container x {

    when "some condition";

    leaf foo {

      mandatory true;

    }

    leaf bar {

      ...

    }

  }

  container y {

    leaf baz {

      mandatory true;

    }

    leaf tee {

      ...

    }

  }

}

            type enumeration {

              enum "DHCP";

              enum "Static";

            }

            mandatory true;

          }

          list IPAddresses {

            }  key Address;

            min-elements 1;

            leaf Address {

              type capit:IPv4Address;

            }

           }

Thanks,
Rob

---

From: Juergen Schoenwaelder <[email-masked]>
Date: Sat, 13 Oct 2018 23:19:43 +0200

On Fri, Oct 12, 2018 at 04:08:48PM +0000, Michael Rehder wrote:

> The mandatory statement in that case is ignored (I’ve pointed out
> the RNG and Schematron lack of enforcement).  WHEN trumps the
> mandatory status (via explicit mandatory or implicit mandatory via
> min-elements 1)

Has the RNG and Schematron been obtained following RFC 6110? If so,
this may be a problem with RFC 6110 but not with YANG itself. There
are validators that do not use RNG or Schematron.

/js

---

From: Michael Rehder <[email-masked]>
Date: Tue, 16 Oct 2018 13:26:25 +0000

I've read rfc6110 and I didn't see any mention of "WHEN" on the mandatory status (section 9.1.1 Optional and Mandatory Nodes doesn't list it which seems a bit odd to me).
The section on "WHEN" just mentions the xpath mapping, not anything about changing the mandatory status of the enclosing node.

I still think that the YANG RFC wording of "conditional" needs to indicate if the node is mandatory status is affected or not.
Note that rfc6060 "3.1 Mandatory Nodes" doesn't mention "WHEN" (it does mention presence).

Thanks
Mike
> Sent: Saturday, October 13, 2018 5:20 PM
> Cc: [email-masked]
> > The mandatory statement in that case is ignored (I’ve pointed out the
> > RNG and Schematron lack of enforcement).  WHEN trumps the mandatory
> > status (via explicit mandatory or implicit mandatory via min-elements
> > 1)
> 
> Has the RNG and Schematron been obtained following RFC 6110? If so, this may
> be a problem with RFC 6110 but not with YANG itself. There are validators that
> do not use RNG or Schematron.
> 
> /js
> 
> --

---

From: Robert Wilton <[email-masked]>
Date: Tue, 16 Oct 2018 14:41:31 +0100

Hi Mike,

> Note that rfc6060 "3.1 Mandatory Nodes" doesn't mention "WHEN" (it does mention presence).
By YANG RFC do you mean RFC 6020/7950?

Section 8.1 of RFC 7950 states the following constraints apply on valid 
data trees:

    o  There MUST be no nodes tagged with "when" present if the "when"
       condition evaluates to "false" in the data tree.

    o  The "mandatory" constraint is enforced for leafs and choices,
       unless the node or any of its ancestors has a "when" condition or
       "if-feature" expression that evaluates to "false".

    o  The "min-elements" and "max-elements" constraints are enforced for
       lists and leaf-lists, unless the node or any of its ancestors has
       a "when" condition or "if-feature" expression that evaluates to
       "false".

These rules indicate that "when" trumps "mandatory", "min-elements" and "max-elements".

Thanks,
Rob

---

From: Michael Rehder <[email-masked]>
Date: Tue, 16 Oct 2018 15:34:50 +0000

Ok, so it is there in the RFC, just somewhat separated (in my view) from the definition of “when”.

I still am somewhat surprised by this implementation.
Far more often the I see a need to enforce the presence of a variant.

Thanks
Mike

From: Robert Wilton [mailto:[email-masked]]
Sent: Tuesday, October 16, 2018 9:42 AM
To: Michael Rehder <[email-masked]>; Juergen Schoenwaelder <[email-masked]>
Cc: [email-masked]
Subject: Re: [netmod] WHEN statement within mandatory objects doesn't ensure presence of the mandatory object

Hi Mike,

Section 8.1 of RFC 7950 states the following constraints apply on valid data trees:

      "false".

Thanks,

Rob

Thanks

Mike

-----Original Message-----

Cc: [email-masked]<mailto:[email-masked]>

1)

/js

--

Fax:   +49 421 200 3103         <https://www.jacobs-university.de/><https://www.jacobs-university.de/>

netmod mailing list

---

From: Robert Wilton <[email-masked]>
Date: Tue, 16 Oct 2018 17:06:19 +0100

Hi Mike,

> Far more often the I see a need to enforce the presence of a variant.
I'm sorry, but I still haven't seen you provide any concrete example in 
YANG where this is useful.

Early in the thread you provided an example with static/dynamic IP 
addresses, and wrote 'There is no way in the IPAddresses list to enforce 
that there is at least one IP Address when the assignment method is 
"Static".'.  But as I replied previously, for YANG at least, this 
statement is wrong since your YANG achieves exactly that constraint!

Specifically, if you have a server that implements the YANG module that 
you provided and a client attempted to configure it via NETCONF or 
RESTCONF then the server would enforce that either the assignment is 
DHCP or at least one static IP address is provided, otherwise the config 
change would be rejected.

I think that your issue may be more with how the YANG is translated via 
the methods in RFC 6110 (which I am not familiar with), but that doesn't 
mean that there is a problem with the YANG definition itself.  Allowing 
mandatory/min-elements/max-elements to have precedence over 'when' 
doesn't make much sense to me, I'm missing a concrete example where it 
seems that this would be useful, certainly your IP address example does 
not require it.

Thanks,
Rob

> *Sent:* Tuesday, October 16, 2018 9:42 AM
> *To:* Michael Rehder <[email-masked]>; Juergen 
> Schoenwaelder <[email-masked]>
> *Cc:* [email-masked]
>         To: Michael Rehder<[email-masked]> <mailto:[email-masked]>
>
>         Cc:[email-masked] <mailto:[email-masked]>
>
>         Fax:   +49 421 200 3103<https://www.jacobs-university.de/>
>         <https://www.jacobs-university.de/>
>
>     [email-masked] <mailto:[email-masked]>
>

---

From: Ladislav Lhotka <[email-masked]>
Date: Wed, 17 Oct 2018 10:43:23 +0200

Michael Rehder <[email-masked]> writes:

> I've read rfc6110 and I didn't see any mention of "WHEN" on the
> mandatory status (section 9.1.1 Optional and Mandatory Nodes doesn't
> list it which seems a bit odd to me).

RFC 6110 was being prepared along with RFC 6020, and section 9.1.1 is
closely related to sec. 3.1 in 6020.

> The section on "WHEN" just mentions the xpath mapping, not anything
> about changing the mandatory status of the enclosing node.

If you take into account the DSDL validation procedure (Figure 2 in RFC
6110) then everything is IMO clear:

- Mandatory nodes (as defined in sec. 9.1.1) are not wrapped in
  <rng:optional> and thus are required during RELAX NG schema
  validation, no matter what any "when" expression says.

- Section 12.17 explains how when expressions are mapped to Schematron
  asserts. This means that if an instance node exists in the data and a
  when expression attached to the corresponding data node in YANG
  evaluates to false, Schematron will report a failed assert.

- Note that Schematron cannot by definition report absence of an
  instance based on the when expression attached to its data
  node: Schematron rules are only fired for elements that are present in
  the instance document. 

> Note that rfc6060 "3.1 Mandatory Nodes" doesn't mention "WHEN" (it

Perhaps this thread is just about misunderstanding of what "when" really
means, which is: Instances for which the "when" expression evaluates to
false must not be present.

It does NOT mean that instances for which the "when" expression
evaluates to true must be present.

Lada

---

From: Michael Rehder <[email-masked]>
Date: Wed, 17 Oct 2018 17:56:37 +0000

That's exactly my point - I think that the wording is unclear in the RFC, that "conditional" doesn't necessarily mean the mandatory status is ignored.

BTW a Schematron rule is emitted to ensure a "mandatory true" CHOICE has at least one CASE present, so there already is an "existential" check built.

I'll suggest a YANG enhancement on "yang-next" for the ability to respect mandatory status or not by a when statement.

Thanks
mike
> Sent: Wednesday, October 17, 2018 4:43 AM
> RFC 6110 was being prepared along with RFC 6020, and section 9.1.1 is closely
> related to sec. 3.1 in 6020.
> 
> > I still think that the YANG RFC wording of "conditional" needs to indicate if the
> node is mandatory status is affected or not.
> means, which is: Instances for which the "when" expression evaluates to false
> must not be present.
> 
> It does NOT mean that instances for which the "when" expression evaluates to
> true must be present.
> 
> Lada
> 
> >
> > Thanks
> > Mike
> >> From: Juergen Schoenwaelder
> >> [mailto:[email-masked]]
> >> > min-elements

---

From: Andy Bierman <[email-masked]>
Date: Wed, 17 Oct 2018 11:21:50 -0700

On Wed, Oct 17, 2018 at 10:56 AM, Michael Rehder <[email-masked]>
wrote:

> That's exactly my point - I think that the wording is unclear in the RFC,
> that "conditional" doesn't necessarily mean the mandatory status is ignored.
>
> BTW a Schematron rule is emitted to ensure a "mandatory true" CHOICE has
> at least one CASE present, so there already is an "existential" check built.
>
> I'll suggest a YANG enhancement on "yang-next" for the ability to respect
> mandatory status or not by a when statement.
>
>

The when statement works as intended. The entire subtree is on or off if
when-stmt is present.
There is a lot of relevant text in 7950 and it cannot be grouped into 1
section, so that may make
it more complicated.

The whole point of "augment when" and "uses when" is to allow the designer
to
say "this part of the model is only relevant for a subset of all possible
values
in another part of the model".  In SNMP we called this SPARSE AUGMENTS
but it was just DESCRIPTION clause text, not machine-reaable.

At the abstract level I do not understand how when-stmt would work
differently.
IMO deviation-stmt already allows enough flexibility to rewrite the model to
fit the implementation.

Andy

---

From: Alex Campbell <[email-masked]>
Date: Wed, 17 Oct 2018 21:43:20 +0000

> At the abstract level I do not understand how when-stmt would work differently.

> IMO deviation-stmt already allows enough flexibility to rewrite the model to

FWIW: deviation statements cannot be used to modify when statements - "when" is missing from the list of statements that can be added/removed/replaced.
I'm wondering if this should be considered errata.

________________________________
From: netmod <[email-masked]> on behalf of Andy Bierman <[email-masked]>
Sent: Thursday, 18 October 2018 7:21 a.m.
To: Michael Rehder
Cc: [email-masked]
Subject: Re: [netmod] WHEN statement within mandatory objects doesn't ensure presence of the mandatory object

On Wed, Oct 17, 2018 at 10:56 AM, Michael Rehder <[email-masked]<mailto:[email-masked]>> wrote:
That's exactly my point - I think that the wording is unclear in the RFC, that "conditional" doesn't necessarily mean the mandatory status is ignored.

The when statement works as intended. The entire subtree is on or off if when-stmt is present.
There is a lot of relevant text in 7950 and it cannot be grouped into 1 section, so that may make
it more complicated.

The whole point of "augment when" and "uses when" is to allow the designer to
say "this part of the model is only relevant for a subset of all possible values
in another part of the model".  In SNMP we called this SPARSE AUGMENTS
but it was just DESCRIPTION clause text, not machine-reaable.

At the abstract level I do not understand how when-stmt would work differently.
IMO deviation-stmt already allows enough flexibility to rewrite the model to
fit the implementation.

Thanks
mike

Andy

> To: Michael Rehder <[email-masked]>; Juergen Schoenwaelder
> <[email-masked]<mailto:[email-masked]>>
>   evaluates to false, Schematron will report a failed assert..
>
> >> [mailto:[email-masked]<mailto:[email-masked]>]
> >> > The mandatory statement in that case is ignored (I've pointed out
> > "Amdocs' email platform is based on a third-party, worldwide, cloud-based
> such system and such processing, storing and access".
"Amdocs' email platform is based on a third-party, worldwide, cloud-based system. Any emails sent to Amdocs will be processed and stored using such system and are accessible by third party providers of such system on a limited basis. Your sending of emails to Amdocs evidences your consent to the use of such system and such processing, storing and access".
_______________________________________________
netmod mailing list
[email-masked]<mailto:[email-masked]>
https://www.ietf.org/mailman/listinfo/netmod

---

From: Andy Bierman <[email-masked]>
Date: Wed, 17 Oct 2018 14:54:42 -0700

On Wed, Oct 17, 2018 at 2:43 PM, Alex Campbell <[email-masked]>
wrote:

> FWIW: deviation statements cannot be used to modify when statements -
> "when" is missing from the list of statements that can be
> added/removed/replaced.

This was intentional.
I meant that deviations can already be used to add/replace/remove
constraints within data nodes.
It is true that there is no way to say certain constraints only apply based
on external data.
As Robert said, I don't understand why we need that.

Andy

------------------------------
> *From:* netmod <[email-masked]> on behalf of Andy Bierman <
> [email-masked]>
> *Sent:* Thursday, 18 October 2018 7:21 a.m.
> *To:* Michael Rehder
> *Cc:* [email-masked]
> On Wed, Oct 17, 2018 at 10:56 AM, Michael Rehder <
>> > <[email-masked]>
>> > Cc: [email-masked]
>> such

---

From: Alex Campbell <[email-masked]>
Date: Thu, 18 Oct 2018 00:40:08 +0000

It means if the model has a node such as:

    leaf some-feature {

        when "../type = 'ipv4' or ../type = 'ipv6'";

        type int32;

    }

and a certain device doesn't supports this on IPv6, it is not possible for a deviation to change the condition to "../type = 'ipv4'"

Is that intentional? It seems more like an omission to me.

________________________________
From: Andy Bierman <[email-masked]>
Sent: Thursday, 18 October 2018 10:54 a.m.
To: Alex Campbell
Cc: Michael Rehder; [email-masked]
Subject: Re: [netmod] WHEN statement within mandatory objects doesn't ensure presence of the mandatory object

This was intentional.
I meant that deviations can already be used to add/replace/remove constraints within data nodes.
It is true that there is no way to say certain constraints only apply based on external data.
As Robert said, I don't understand why we need that.

Andy

From: netmod <[email-masked]<mailto:[email-masked]>> on behalf of Andy Bierman <[email-masked]<mailto:[email-masked]>>

Thanks
mike

Andy