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

Ladislav Lhotka <lhotka@nic.cz> Wed, 10 October 2018 15:43 UTC

Return-Path: <lhotka@nic.cz>
X-Original-To: netmod@ietfa.amsl.com
Delivered-To: netmod@ietfa.amsl.com
Received: from localhost (localhost [127.0.0.1]) by ietfa.amsl.com (Postfix) with ESMTP id 7EEC8130F47 for <netmod@ietfa.amsl.com>; Wed, 10 Oct 2018 08:43:17 -0700 (PDT)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -7
X-Spam-Level:
X-Spam-Status: No, score=-7 tagged_above=-999 required=5 tests=[BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, RCVD_IN_DNSWL_HI=-5] autolearn=ham autolearn_force=no
Authentication-Results: ietfa.amsl.com (amavisd-new); dkim=pass (1024-bit key) header.d=nic.cz
Received: from mail.ietf.org ([4.31.198.44]) by localhost (ietfa.amsl.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Za-ioyLSMG0R for <netmod@ietfa.amsl.com>; Wed, 10 Oct 2018 08:43:15 -0700 (PDT)
Received: from mail.nic.cz (mail.nic.cz [217.31.204.67]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ietfa.amsl.com (Postfix) with ESMTPS id 9803F130DD9 for <netmod@ietf.org>; Wed, 10 Oct 2018 08:43:14 -0700 (PDT)
Received: from birdie (unknown [IPv6:2a01:5e0:29:ffff:ffc6:c393:cdb9:8db1]) by mail.nic.cz (Postfix) with ESMTPSA id 6A15D620AD; Wed, 10 Oct 2018 17:43:12 +0200 (CEST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=nic.cz; s=default; t=1539186192; bh=l7dYXOeW63wwhPSqDDZk/083PgCNqjG5KZQ+E9C1nmk=; h=From:To:Date; b=D5T/Bkrn5LGWy3ph+9Qicio22eNW+fwZawcLIm58f8qbQv0hn166VKkW1fKVKqhZ2 AV9Lk6AINLOzGY6Qrey2PPaOYSAdV+lG5a0fvyINPZK8YUiA5sXp+/mxH+KgfPQqzE M5KCW/Mlg+mNDazL2HMS3fUMtX6RqRhdGuF4tH/8=
Message-ID: <f336bfd896fde63dc9b0aaf62781db9bcf40106b.camel@nic.cz>
From: Ladislav Lhotka <lhotka@nic.cz>
To: Michael Rehder <Michael.Rehder@Amdocs.com>, "netmod@ietf.org" <netmod@ietf.org>
Cc: "Walker, Jason (Jason_Walker2@comcast.com)" <Jason_Walker2@comcast.com>
Date: Wed, 10 Oct 2018 17:43:12 +0200
In-Reply-To: <AM0PR06MB40833D8AED0744BB597394E7E7E00@AM0PR06MB4083.eurprd06.prod.outlook.com>
References: <AM0PR06MB4083426FA0F1D3F6515F2ECFE7E70@AM0PR06MB4083.eurprd06.prod.outlook.com> <87zhvlvpts.fsf@nic.cz> <AM0PR06MB40833D8AED0744BB597394E7E7E00@AM0PR06MB4083.eurprd06.prod.outlook.com>
Organization: CZ.NIC
Content-Type: text/plain; charset="UTF-8"
User-Agent: Evolution 3.30.1
Mime-Version: 1.0
Content-Transfer-Encoding: 8bit
X-Virus-Scanned: clamav-milter 0.99.2 at mail
X-Virus-Status: Clean
Archived-At: <https://mailarchive.ietf.org/arch/msg/netmod/qf0k1Vpzyh8WBbmKNvMhF8Zv30c>
Subject: Re: [netmod] WHEN statement within mandatory objects doesn't ensure presence of the mandatory object
X-BeenThere: netmod@ietf.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: NETMOD WG list <netmod.ietf.org>
List-Unsubscribe: <https://www.ietf.org/mailman/options/netmod>, <mailto:netmod-request@ietf.org?subject=unsubscribe>
List-Archive: <https://mailarchive.ietf.org/arch/browse/netmod/>
List-Post: <mailto:netmod@ietf.org>
List-Help: <mailto:netmod-request@ietf.org?subject=help>
List-Subscribe: <https://www.ietf.org/mailman/listinfo/netmod>, <mailto:netmod-request@ietf.org?subject=subscribe>
X-List-Received-Date: Wed, 10 Oct 2018 15:43:18 -0000

On Wed, 2018-10-10 at 15:23 +0000, Michael Rehder wrote:
> 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".


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.
> 
> 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:lhotka@nic.cz]
> > Sent: Wednesday, October 10, 2018 10:28 AM
> > To: Michael Rehder <Michael.Rehder@Amdocs.com>; netmod@ietf.org
> > Subject: Re: [netmod] WHEN statement within mandatory objects doesn't
> > ensure presence of the mandatory object
> > 
> > Michael Rehder <Michael.Rehder@Amdocs.com> writes:
> > 
> > > 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.).
> > 
> > Maybe you intended to have, e.g., a "mandatory true" leaf inside "container
> > foo"?
> > 
> > > This is considered valid XML for the above
> > >     <color>blue</color>
> > 
> > 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
> > 
> > > thanks
> > > Mike Rehder
> > 
> > --
> > Ladislav Lhotka
> > Head, CZ.NIC Labs
> > PGP Key ID: 0xB8F92B08A9F76C67
> “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”.
-- 
Ladislav Lhotka
Head, CZ.NIC Labs
PGP Key ID: 0xB8F92B08A9F76C67