Re: [netmod] false() vs 'false' in 'when' statements
Martin Bjorklund <mbj@tail-f.com> Wed, 08 August 2018 13:51 UTC
Return-Path: <mbj@tail-f.com>
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 EA1A8130DC0 for <netmod@ietfa.amsl.com>; Wed, 8 Aug 2018 06:51:00 -0700 (PDT)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -1.901
X-Spam-Level:
X-Spam-Status: No, score=-1.901 tagged_above=-999 required=5 tests=[BAYES_00=-1.9, SPF_PASS=-0.001] autolearn=ham autolearn_force=no
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 tVx9mM2BgyGL for <netmod@ietfa.amsl.com>; Wed, 8 Aug 2018 06:50:58 -0700 (PDT)
Received: from mail.tail-f.com (mail.tail-f.com [46.21.102.45]) by ietfa.amsl.com (Postfix) with ESMTP id A37B2130DBE for <netmod@ietf.org>; Wed, 8 Aug 2018 06:50:58 -0700 (PDT)
Received: from localhost (h-80-27.A165.priv.bahnhof.se [212.85.80.27]) by mail.tail-f.com (Postfix) with ESMTPSA id F25D01AE018A; Wed, 8 Aug 2018 15:50:56 +0200 (CEST)
Date: Wed, 08 Aug 2018 15:50:48 +0200
Message-Id: <20180808.155048.1116801606990172501.mbj@tail-f.com>
To: jason.sterne@nokia.com
Cc: william.ivory@intl.att.com, netmod@ietf.org
From: Martin Bjorklund <mbj@tail-f.com>
In-Reply-To: <VI1PR07MB39813DB16C1AF2314EBD14EE9B260@VI1PR07MB3981.eurprd07.prod.outlook.com>
References: <VI1PR07MB3981A0DC1F7069AFC5BE72AD9B270@VI1PR07MB3981.eurprd07.prod.outlook.com> <E3378E0605547F4E854DEE0CB1116AB03A8BA8@gbcdcmbx03.intl.att.com> <VI1PR07MB39813DB16C1AF2314EBD14EE9B260@VI1PR07MB3981.eurprd07.prod.outlook.com>
X-Mailer: Mew version 6.7 on Emacs 24.5 / Mule 6.0 (HANACHIRUSATO)
Mime-Version: 1.0
Content-Type: Text/Plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Archived-At: <https://mailarchive.ietf.org/arch/msg/netmod/6dKkQbbNzfJmkMxJec1s51K-H1k>
Subject: Re: [netmod] false() vs 'false' in 'when' statements
X-BeenThere: netmod@ietf.org
X-Mailman-Version: 2.1.27
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, 08 Aug 2018 13:51:01 -0000
Hi, "Sterne, Jason (Nokia - CA/Ottawa)" <jason.sterne@nokia.com> wrote: > Thanks William. > Please see below. > Regards, > Jason > > > -----Original Message----- > > From: Ivory, William <william.ivory@intl.att.com> > > Sent: Wednesday, August 8, 2018 3:27 AM > > To: Sterne, Jason (Nokia - CA/Ottawa) <jason.sterne@nokia.com>; > > netmod@ietf.org > > Subject: Re: [netmod] false() vs 'false' in 'when' statements > > > > On 07/08/18 18:37, Sterne, Jason (Nokia - CA/Ottawa) wrote: > > Hi all, > > > > When comparing the value of a boolean leaf in a 'when' statement (or a > > 'must' > > statement), is an equality comparison to 'true' or 'false' the same as > > a check > > against true() or false() ? > > > > For example: > > > > leaf a { > > type boolean; > > } > > leaf b { > > type uint32; > > when ".../a = 'true'"; > > } > > leaf c { > > type uint32; > > when ".../a = 'false'"; > > } > > (note that neither b nor c can be configured if leaf a isn't > > explicitly configured > > with a value since there is no default) > > > > If I replace the two 'when' statements above with the following > > instead, is the > > behavior the same ? > > ... > > when ".../a = true()"; > > ... > > when ".../a = false()"; > > ... > > > > Or does "../a = true()" behave as an existence check on leaf a and > > would be > > enabled whether a is configured as true or false ? > > > > Regards, > > Jason > > > > > > > > See https://www.w3.org/TR/1999/REC-xpath-19991116/#booleans > > > > (a) "../a = 'true'" > > > > Compares 'string-value' (same as value of node if a leaf, rather more > > interesting if a list / container!) of each node in nodeset generated > > by '../a' and > > if any node in the nodeset matches 'true', expression is true. > > [>>JTS: ] In my specific example, leaf a is a single Boolean leaf. In > that case, are these equivalent ? > when ".../a = 'true'"; > when ".../a = true()"; No... > and are these also equivalent ? > when ".../a = 'false'"; > when ".../a = false()"; ... and no. What you probably want is ".../a = 'true'" (or 'false'). The expression: ".../a = true()"; will first take the string value of ".../a", which e.g. is "false". This string value is then converted to a boolean, resulting in the boolean value True (b/c the string is non-empty). This means that if "a" is set at all (to true or false), the expression ".../a = true()" returns true. The expression ".../a = false()" will only return true if "a" is unset. > (sorry if I'm being dense here, but I'm not 100% positive if I'm > interpreting your explanations correctly and getting the right > conclusion. I've never seen must or when statements that use = > false() or = true()). > > [>>JTS: ] Are the strings 'true' and 'false' the "string-value" (that > you mention above) for a Boolean leaf ? Yes, according to 9.5.1 in RFC 7950. > 'a' is a single Boolean leaf so the nodeset is that single leaf and > the value is 'true' or 'false'. > > > > > (b) "../a = true()" > > > > Similar to above but after getting the string-value, this is converted > > to a > > boolean before comparing with the boolean true. > > [>>JTS: ] I'm a bit confused here. Are you saying that the > string-value of leaf a is converted to a Boolean ? > Do the string-values of a convert to something that is equal to true() > or false() ? See above. /martin > > > > > (c) '../a' > > > > True if the nodeset generated by this expression is not empty. > > > > --- > > > > Caveats alluded to above are that if '../a' matches multiple nodes, > > then only > > one of these nodes needs to pass the test for the test to be true. > > Separately, if > > any of the nodes are not leaves, the 'string-value' is a concatenated > > string of > > the values of the node's child / grandchild leaves. > > > > Hope that helps. You wouldn't believe the number of unit tests I have > > to make > > sure we get this logic right! Using '!=' when comparing a nodeset > > with >1 node > > with other values is very likely not to give the answer you expect (-: > > > > Regards, > > > > William > > > > _______________________________________________ > netmod mailing list > netmod@ietf.org > https://www.ietf.org/mailman/listinfo/netmod >
- [netmod] false() vs 'false' in 'when' statements Sterne, Jason (Nokia - CA/Ottawa)
- Re: [netmod] false() vs 'false' in 'when' stateme… Ivory, William
- Re: [netmod] false() vs 'false' in 'when' stateme… Sterne, Jason (Nokia - CA/Ottawa)
- Re: [netmod] false() vs 'false' in 'when' stateme… Sterne, Jason (Nokia - CA/Ottawa)
- Re: [netmod] false() vs 'false' in 'when' stateme… Martin Bjorklund
- Re: [netmod] false() vs 'false' in 'when' stateme… Andy Bierman
- Re: [netmod] false() vs 'false' in 'when' stateme… Martin Bjorklund
- Re: [netmod] false() vs 'false' in 'when' stateme… Andy Bierman
- Re: [netmod] false() vs 'false' in 'when' stateme… Martin Bjorklund