Re: [yang-doctors] A compact way to compare a type in YANG

Martin Björklund <mbj+ietf@4668.se> Mon, 16 March 2020 11:12 UTC

Return-Path: <mbj+ietf@4668.se>
X-Original-To: yang-doctors@ietfa.amsl.com
Delivered-To: yang-doctors@ietfa.amsl.com
Received: from localhost (localhost [127.0.0.1]) by ietfa.amsl.com (Postfix) with ESMTP id 4A6EF3A2281 for <yang-doctors@ietfa.amsl.com>; Mon, 16 Mar 2020 04:12:16 -0700 (PDT)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -0.101
X-Spam-Level:
X-Spam-Status: No, score=-0.101 tagged_above=-999 required=5 tests=[BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, PDS_NAKED_TO_NUMERO=1.999, SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=no autolearn_force=no
Authentication-Results: ietfa.amsl.com (amavisd-new); dkim=pass (2048-bit key) header.d=4668.se header.b=onMeCWDp; dkim=pass (2048-bit key) header.d=messagingengine.com header.b=Yc/Pv45q
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 tQ_uvD457vho for <yang-doctors@ietfa.amsl.com>; Mon, 16 Mar 2020 04:12:14 -0700 (PDT)
Received: from wnew4-smtp.messagingengine.com (wnew4-smtp.messagingengine.com [64.147.123.18]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ietfa.amsl.com (Postfix) with ESMTPS id E3DF73A22E2 for <yang-doctors@ietf.org>; Mon, 16 Mar 2020 04:12:14 -0700 (PDT)
Received: from compute2.internal (compute2.nyi.internal [10.202.2.42]) by mailnew.west.internal (Postfix) with ESMTP id 0BF2E775; Mon, 16 Mar 2020 07:12:13 -0400 (EDT)
Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Mon, 16 Mar 2020 07:12:14 -0400
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=4668.se; h=date :message-id:to:cc:subject:from:in-reply-to:references :mime-version:content-type:content-transfer-encoding; s=fm1; bh= sQzH3rl+HB0iBvcgRfSzfZBkZsbsRbE5b/dxFDWsARE=; b=onMeCWDpbCQyNd54 7UWE9PDKPZhN/O2bfVh36BmFlw6KEDvlDAaAXN1O5R4WYgSs7fpqC8v7U649rBnW XPrEK0RdyDAzffms1zk9xYzY2ZT55t3J7CiuEE/CXJF8/BpfOj3X5bXrknCOwxcA m+TgKLTNy/MLG3jCYlJ5A/7wlE1GzMESkwptOBXFBsJ7JKKhwD5FNqrrXvlM8gDx 6WBCljkHBcBXcO0+pXjwOvSn8RXRDi5Qev/b26BBoJS2BxF82ZEkqHFATsj9L5Bj rjawO0uEzDLhwIbXvjRSqrGQ8EuWZ9t4ofsEkMsr3pqoUor+i8KfC3GPv6xnjppe ib68zg==
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm2; bh=sQzH3rl+HB0iBvcgRfSzfZBkZsbsRbE5b/dxFDWsA RE=; b=Yc/Pv45qmEDtuGWh7gN3O5NBgEzvHlCiuDohdjMNqE9Rto2Y7yXWZRgO/ fAGaJb8R8aOLxLIynzrwdOhhHDZLFXaw9S0sg4KJA7ymWrWt+tckN9UI2AC2w1aT 1Q0iMmPmhG//i0WjEV07JFtwWs24YiPk/tgLN+Tr7f6CtK3Y44st6USLQjm52JkP e86vynXjptX97TnmBbT7foRoTdoEBh9V/uMhOwM28P3voMLY6KZlhwjo8hTe0qXO W1qFlGLUvtUN1Ow3qOfg9hpdWtMCVQocP6S5PijzzZZAWlMPcgSbtWlVIVoIbw2F CkXuErh8YgEDyyRUNmzC3VxnGZV4w==
X-ME-Sender: <xms:DF9vXoVouifdLcDtXZKDmVVUOO5zrNEQN-ztz3wFY4LYQ_SnxEMwAQ>
X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedugedrudeffedgvdegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpeffkffvuffhjghfofggtgfgsehtje ertdertddvnecuhfhrohhmpeforghrthhinhcuuehjnphrkhhluhhnugcuoehmsghjodhi vghtfhesgeeiieekrdhsvgeqnecukfhppedvuddvrddvudegrdduuddriedtnecuvehluh hsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepmhgsjhdoihgvthhf seegieeikedrshgv
X-ME-Proxy: <xmx:DF9vXlD2qrPQebFU5Fy2EjROmBJqOgc8GQPiIL8ojWxXOELj5rs3wg> <xmx:DF9vXiDqaxiFHVFzDqVbN3ADczRkK7Z8Xk2jKtt2YP7X5fKKbqsXWQ> <xmx:DF9vXraWO_N6Jr1gLzz_6PcjdjqOJcz9fHKIz8jUN9vIZYXwTpExBA> <xmx:DV9vXk8hfaxwz9VLwHPVP9jrC6634antdIjYI4e3B9MQTtsltM7yQ__Z1DA>
Received: from localhost (212-214-11-60-static.se.customer.tele2.net [212.214.11.60]) by mail.messagingengine.com (Postfix) with ESMTPA id BE775328005D; Mon, 16 Mar 2020 07:12:11 -0400 (EDT)
Date: Mon, 16 Mar 2020 12:12:09 +0100
Message-Id: <20200316.121209.2148431500798425289.id@4668.se>
To: scott.mansfield=40ericsson.com@dmarc.ietf.org
Cc: yang-doctors@ietf.org
From: Martin Björklund <mbj+ietf@4668.se>
In-Reply-To: <DM5PR15MB1772345A25C69265D681A5258BF90@DM5PR15MB1772.namprd15.prod.outlook.com>
References: <DM5PR15MB1772345A25C69265D681A5258BF90@DM5PR15MB1772.namprd15.prod.outlook.com>
X-Mailer: Mew version 6.8 on Emacs 26.3
Mime-Version: 1.0
Content-Type: Text/Plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Archived-At: <https://mailarchive.ietf.org/arch/msg/yang-doctors/z1_YUEzuyi7jfU2TYA3t_WHa4Cg>
Subject: Re: [yang-doctors] A compact way to compare a type in YANG
X-BeenThere: yang-doctors@ietf.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Email list of the yang-doctors directorate <yang-doctors.ietf.org>
List-Unsubscribe: <https://www.ietf.org/mailman/options/yang-doctors>, <mailto:yang-doctors-request@ietf.org?subject=unsubscribe>
List-Archive: <https://mailarchive.ietf.org/arch/browse/yang-doctors/>
List-Post: <mailto:yang-doctors@ietf.org>
List-Help: <mailto:yang-doctors-request@ietf.org?subject=help>
List-Subscribe: <https://www.ietf.org/mailman/listinfo/yang-doctors>, <mailto:yang-doctors-request@ietf.org?subject=subscribe>
X-List-Received-Date: Mon, 16 Mar 2020 11:12:16 -0000

Hi,

Scott Mansfield <scott.mansfield=40ericsson.com@dmarc.ietf.org> wrote:
> Yang Doctors,
> 
>  
> 
> The IEEE has been working on the IEEE 802.1 bridge model and while updating
> some when statements in  YANG models ieee802-dot1q-bridge and
> ieee802-dot1q-pb to select conditions for certain types of bridge components
> we had a question. 
> 
>  
> 
> The pertinent part of the bridge tree is this:
> 
>  
> 
> module: ieee802-dot1q-bridge
> 
>   +--rw bridges
> 
>      +--rw bridge* [name]
> 
>         +--rw name           dot1qtypes:name-type
> 
>         +--rw address        ieee:mac-address
> 
>         +--rw bridge-type    identityref
> 
>         +--ro ports?         uint16
> 
>         +--ro up-time?       yang:zero-based-counter32
> 
>         +--ro components?    uint32
> 
>         +--rw component* [name]
> 
>            +--rw name                     string
> 
>            +--rw id?                      uint32
> 
>            +--rw type                     identityref <- This is the type we
> want to test.
> 
>            +--rw address?                 ieee:mac-address
> 
>  
> 
>  
> 
>  
> 
> And later in the same file an augmented interface tree looks like  this:
> 
>  
> 
>  
> 
> augment /if:interfaces/if:interface:
> 
>     +--rw bridge-port
> 
>        +--rw bridge-name?                           -> /bridges/bridge/name
> 
>        +--rw component-name?                        ->
> /bridges/bridge[dot1q:name=current()/../bridge-name]/component/name
> 
>  
> 
>  
> 
> In several places we are using a when statement with an xpath condition
> while in the interface tree context: (This is what it looks like in the
> ieee802-dot1q-pb module)
> 
> when
> 
>  
> "/dot1q:bridges/dot1q:bridge[dot1q:name=current()/../dot1q:bridge-name]/dot1
> q:component[dot1q:name=current()/../dot1q:component-name]/dot1q:type =
> 'dot1q:c-vlan-component'
> 
>  
> 
> We had a discussion on our Yangsters meeting this seem rather cumbersome and
> whether the component type value could be locally instantiated with the
> value of the respective component type to reduce the when statement to: 
> 
>  
> 
> when " ../dot1q:component-type = 'dot1q:c-vlan-component' "
> 
>  
> 
> The suggestion was adding this:
> 
>  
> 
>       leaf component-type {
> 
>         type leafref {
> 
>           path
> "/dot1q:bridges/dot1q:bridge[dot1q:name=current()/../bridge-name]/dot1q:comp
> onent[dot1q:name=current()/../component-name]/dot1q:type";  
> 
>         }
> 
>         description
> 
>           "Used to reference the Component type.";
> 
>       }
> 
>  
> 
> However I don't think this works it seems to only make the leafref type of
> component-type the same as the dot1q type of ../component/type which is an
> identityref. (type-of-component) . Other attempts to make this work failed
> too.

This works, but it requires the operator to explicitly set this leaf,
which probably is not what you want.



> Does YANG offer another mechanism for a more compact form to do what we
> want? 

Not that I can think of.


/martin


> 
>  
> 
> Thanks for your consideration!
> 
>  
> 
> Regards,
> 
> -scott.
> 
>  
>