Re: [yang-doctors] Question about absolute and relative paths in YANG

Ladislav Lhotka <ladislav.lhotka@nic.cz> Tue, 16 November 2021 06:27 UTC

Return-Path: <ladislav.lhotka@nic.cz>
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 4F1B33A08E6 for <yang-doctors@ietfa.amsl.com>; Mon, 15 Nov 2021 22:27:38 -0800 (PST)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -3.751
X-Spam-Level:
X-Spam-Status: No, score=-3.751 tagged_above=-999 required=5 tests=[BAYES_00=-1.9, NICE_REPLY_A=-1.852, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=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 CiRvHmGowC3O for <yang-doctors@ietfa.amsl.com>; Mon, 15 Nov 2021 22:27:30 -0800 (PST)
Received: from mail.nic.cz (mail.nic.cz [IPv6:2001:1488:800:400::400]) (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 1DF043A08D0 for <yang-doctors@ietf.org>; Mon, 15 Nov 2021 22:27:29 -0800 (PST)
Received: from [IPV6:2a01:5e0:29:ffff:fc73:fa64:57e6:2115] (unknown [IPv6:2a01:5e0:29:ffff:fc73:fa64:57e6:2115]) by mail.nic.cz (Postfix) with ESMTPSA id 8C0BA13FDD4; Tue, 16 Nov 2021 07:27:25 +0100 (CET)
Message-ID: <38d78f2a-8497-2a93-2b06-7be85e1b974b@nic.cz>
Date: Tue, 16 Nov 2021 07:27:24 +0100
MIME-Version: 1.0
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.3.0
Content-Language: en-US
To: =?UTF-8?Q?Martin_Bj=c3=b6rklund?= <mbj+ietf@4668.se>, Italo.Busi@huawei.com
Cc: yang-doctors@ietf.org, zhenghaomian@huawei.com, aihuaguo@futurewei.com
References: <72a905a18a334460864bfc95be778150@huawei.com> <9ed9adedd20543eeaf4d6f5f6d1e3d7c@huawei.com> <20211115.175537.1719961127066875828.id@4668.se>
From: Ladislav Lhotka <ladislav.lhotka@nic.cz>
Organization: CZ.NIC
In-Reply-To: <20211115.175537.1719961127066875828.id@4668.se>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Virus-Scanned: clamav-milter 0.102.4 at mail
X-Virus-Status: Clean
Archived-At: <https://mailarchive.ietf.org/arch/msg/yang-doctors/eTgHJbJMf9wYCUuYidsL1NIoDEw>
Subject: Re: [yang-doctors] Question about absolute and relative paths 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: Tue, 16 Nov 2021 06:27:38 -0000

On 15. 11. 21 17:55, Martin Björklund wrote:
> Hi,
> 
> Italo Busi <Italo.Busi@huawei.com> wrote:
>> Any feedbacks/comments about this question?
>>
>> Thanks, Italo
>>
>> From: Italo Busi
>> Sent: giovedì 23 settembre 2021 18:56
>> To: yang-doctors@ietf.org
>> Cc: Zhenghaomian <zhenghaomian@huawei.com>om>; 'Aihua Guo'
>> <aihuaguo@futurewei.com>
>> Subject: Question about absolute and relative paths in YANG
>>
>> Hi YANG doctors,
>>
>> I am quite active within the IETF CCAMP and TEAS WGs on YANG models
>> for optical transport networks
>>
>> We are having some discussions about the use of absolute and relative
>> paths in some of the drafts we are developing for IETF
>>
>> I have been told that YANG doctors prefer absolute paths to relative
>> paths
> 
> I don't recognize this preference.  Also I don't know if you refer to
> XPath paths in must/when or something else.  I assume you mean XPath
> paths.

It's a mystery to me how such myths can ever arise. :-)

> 
> IMO, a short relative path is often easier to read and understand, and
> easier to get right.  In some cases it truly doesn't matter, and in
> some other cases you must use one and not the other.
> 
> In the examples below, I'd use a relative path.

+1

Lada

> 
> 
> /martin
> 
> 
> 
>> We think it makes a lot of sense to use absolute paths whenever
>> possible but there are some cases where we are not sure whether and
>> how we could use absolute paths
>>
>> We would appreciate your opinions and suggestions about how to address
>> these cases
>>
>> One case could be one of the augment statements defined in RFC8795 (TE
>> Topology model):
>>
>>    augment "/nw:networks/nw:network/nw:node/tet:te/"
>>          + "tet:te-node-attributes/tet:connectivity-matrices/"
>>          + "tet:label-restrictions/tet:label-restriction" {
>>      when "../../../../../../nw:network-types/tet:te-topology/"
>>         + "example-topology" {
>>
>> The intention is to say that this augmentation applies only to a
>> specific network-types of this network instance. Using an absolute
>> path the code could become:
>>
>>    augment "/nw:networks/nw:network/nw:node/tet:te/"
>>          + "tet:te-node-attributes/tet:connectivity-matrices/"
>>          + "tet:label-restrictions/tet:label-restriction" {
>> when
>> "/nw:networks/nw:network[nw:network-id=current()../../../../../../nw:network-id]/"
>>     + "nw:network-types/tet:te-topology/"
>>         + "example-topology" {
>>
>> It seems that using the absolute path is moving the issue on requiring
>> a relative path to get the value of the network-id of this network
>>
>> Is there an alternative solution to avoid using relative path in this
>> case?
>>
>> Another case we have considered is the definition of a grouping with a
>> leaf that references another node within the same network. In this
>> case, using a relative path or an absolution path embedding a relative
>> path required to get the network-id of this network, would make quite
>> difficult to re-use this grouping in multiple places within the YANG
>> tree
>>
>> One work-around could be to use the refine statement, such as:
>>
>> grouping node-reference {
>>    leaf network-ref {
>>      type leafref {
>>        path "/nw:networks/nw:network/nw:network-id"
>>      }
>>    }
>>
>>    leaf node-ref {
>>      type leafref {
>>        path "deref(../network-ref)/../nw:node/nw:nw:node-id"
>>      }
>>    }
>> }
>>
>> augment "/nw:networks/nw:network/nw:node/tet:te/"
>>        + "tet:te-node-attributes/tet:connectivity-matrices/"
>>        + "tet:label-restrictions/tet:label-restriction" {
>>    uses node-reference {
>>      refine network-ref {
>>        default current()/../../../../../../network-id;
>>        must current() = current()/../../../../../../network-id;
>>     }
>>    }
>>
>> This work-around seems a bit weird but at least it should the need to
>> use relative paths within the grouping but keep the requirement to use
>> the relative paths in the refine statements
>>
>> Is there a better solution to avoid using relative path within the
>> grouping?
>>
>> Thanks in advance for your help
>>
>> Italo
>>
> _______________________________________________
> yang-doctors mailing list
> yang-doctors@ietf.org
> https://www.ietf.org/mailman/listinfo/yang-doctors
> 

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