Subject: [netmod] Question about must statement in grouping

From: "Bogaert, Bart (Nokia - BE/Antwerp)" <[email-masked]>
Date: Wed, 29 Mar 2017 10:47:16 +0000

Hi,

We have a question on the usage of a must statement within a grouping.

Assume the following grouping

grouping a-group {

  list a-list {

    must "count(.) != 1" {

      description

        "This list must either be empty or have at least 2 elements";

    }

    key "entry";

    leaf entry {

      type uint16;

    }

    leaf another-entry {

      type uint32;

    }

  }

}

And used in another module

container a-container {

  uses a-group;

}

The uses actually results in a data-tree like below

  +--rw a-container

      +--rw a-list* [entry]

           +--rw entry           uint16

           +--rw another-entry   uint32

Does the usage of the grouping usage also result in the expected behavior
for the must statement when configuring /a-container/a-list?  The '.' in the
must statement in the grouping refers to 'a-list' so will that return 2 in
case we have configured 2 elements in /a-container/a-list or should we write
the must statement at the level of 'a-container' stating that "count(a-list)
!= 1" (as below)?

grouping a-group {

  list a-list {

    key "entry";

    leaf entry {

      type uint16;

    }

  }

}

And used in another module

container a-container {

  uses a-group;

  must "count(a-list) != 1" {

    description

      "This list must either be empty or have at least 2 elements";

  }

}

Best regards - Vriendelijke groeten,

Bart Bogaert

---

From: "Bogaert, Bart (Nokia - BE/Antwerp)" <[email-masked]>
Date: Wed, 29 Mar 2017 12:02:05 +0000

Changing "count(.) != 1" into "count(../a-list) != 1" in the grouping does
the job as expected.  So it seems that count(.) within the context of the
a-list applies to each element in the list and rather than to the list
itself?

Regards, Bart

From: netmod [mailto:[email-masked]] On Behalf Of Bogaert, Bart
(Nokia - BE/Antwerp)
Sent: 29 March 2017 12:47
To: [email-masked]
Subject: [netmod] Question about must statement in grouping

Hi,

grouping a-group {

  list a-list {

    must "count(.) != 1" {

      description

    }

    key "entry";

    leaf entry {

      type uint16;

    }

    leaf another-entry {

      type uint32;

    }

  }

}

container a-container {

  uses a-group;

}

  +--rw a-container

      +--rw a-list* [entry]

           +--rw entry           uint16

grouping a-group {

  list a-list {

    key "entry";

    leaf entry {

      type uint16;

    }

  }

}

container a-container {

  uses a-group;

    description

  }

}

Bart Bogaert

---

From: Ladislav Lhotka <[email-masked]>
Date: Wed, 29 Mar 2017 07:37:03 -0500

> a-list applies to each element in the list and rather than to the list

Both versions of the XPath expression are evaluated once for each entry
of the list, and the entry's 'a-list' node is the context node. By
definition, '.'  selects the context node, so 'count(.)' is always
1. After the change, '..' selects the parent node and 'a-list' then
selects all nodes of that name, which are the entries of the list.

Note that it would be more efficient to verify the constraint on the
parent container, with 'count(a-list) != 1'.

Lada

> _______________________________________________
> netmod mailing list
> [email-masked]
> https://www.ietf.org/mailman/listinfo/netmod

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

---

From: "Bogaert, Bart (Nokia - BE/Antwerp)" <[email-masked]>
Date: Wed, 29 Mar 2017 12:43:31 +0000

Lada, thanks for the feedback.

Any specific reason why you say that this would be more efficient when used
in the context of the parent container and not in the grouping?

Regards, Bart

-----Original Message-----
From: Ladislav Lhotka [mailto:[email-masked]] 
Sent: 29 March 2017 14:37
To: Bogaert, Bart (Nokia - BE/Antwerp) <[email-masked]>; Bogaert,
Bart (Nokia - BE/Antwerp) <[email-masked]>; [email-masked]
Subject: Re: [netmod] Question about must statement in grouping

"Bogaert, Bart (Nokia - BE/Antwerp)" <[email-masked]> writes:

> Changing "count(.) != 1" into "count(../a-list) != 1" in the grouping 
> does the job as expected.  So it seems that count(.) within the 
> context of the a-list applies to each element in the list and rather 
> than to the list itself?

Both versions of the XPath expression are evaluated once for each entry of
the list, and the entry's 'a-list' node is the context node. By definition,
'.'  selects the context node, so 'count(.)' is always 1. After the change,
'..' selects the parent node and 'a-list' then selects all nodes of that
name, which are the entries of the list.

Note that it would be more efficient to verify the constraint on the parent
container, with 'count(a-list) != 1'.

Lada

>
>  
>
> Regards, Bart
>
>  
>
> From: netmod [mailto:[email-masked]] On Behalf Of Bogaert, 
> Bart (Nokia - BE/Antwerp)
> Does the usage of the grouping usage also result in the expected 
> behavior for the must statement when configuring /a-container/a-list?  
> The '.' in the must statement in the grouping refers to 'a-list' so 
> will that return 2 in case we have configured 2 elements in 
> /a-container/a-list or should we write the must statement at the level 
> of 'a-container' stating that "count(a-list) != 1" (as below)?
>
>  
>
> grouping a-group {
>
>   list a-list {
>
>     key "entry";
>
>     leaf entry {
>
>       type uint16;
>
>     }
>
>   }
>
> }
>
>  
>

---

From: Ladislav Lhotka <[email-masked]>
Date: Wed, 29 Mar 2017 09:11:21 -0500

> On 29 Mar 2017, at 07:43, Bogaert, Bart (Nokia - BE/Antwerp) <[email-masked]> wrote:
> 

As I wrote, the expression is evaluated once for each entry, always with the same result. It may or may not be a problem depending on the number of entries.

Lada