Subject: [netmod] xpath for must statements

From: "Acee Lindem (acee)" <[email-masked]>
Date: Tue, 7 Aug 2018 22:00:24 +0000

Is it possible to indicate that choice statement must be specified in a YANG 1.1 “must” clause w/o specifying every case? Similarly, it is there a way specify that a container cannot be empty in “must” clause?
Thanks,
Acee

---

From: "Ivory, William" <[email-masked]>
Date: Wed, 8 Aug 2018 07:13:50 +0000

On 07/08/18 23:01, Acee Lindem (acee) wrote:
Is it possible to indicate that choice statement must be specified in a YANG 1.1 “must” clause w/o specifying every case? Similarly, it is there a way specify that a container cannot be empty in “must” clause?
Thanks,
Acee

For the second, just check the container has children:

    must "<path_to_container>/*";

Regards,

William

---

From: Martin Bjorklund <[email-masked]>
Date: Wed, 08 Aug 2018 09:41:24 +0200 (CEST)

Hi,

>     must "<path_to_container>/*";

Note that if the container has an NP-container as a child, this
expression will always return true (even if that NP-container is
empty), since NP-containers exists in XPath evaluations (see 6.4.1 in
RFC 7950).

If there are no NP-containers the expression works -- except that it
doesn't work if someone augments an NP-container into this container.

/martin

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

---

From: Martin Bjorklund <[email-masked]>
Date: Wed, 08 Aug 2018 09:42:49 +0200 (CEST)

Hi,

"Acee Lindem \(acee\)" <acee=[email-masked]> wrote:
> Is it possible to indicate that choice statement must be specified
> in a YANG 1.1 “must” clause w/o specifying every case?

Do you mean that you to ensure that a case is always configured?  If
so, mark the choice as "mandatory true".  It can't be done with an
XPath expression.

/martin

> Similarly, it is there a way specify that a container cannot be empty in “must” clause?
> Thanks,
> Acee

---

From: "Ivory, William" <[email-masked]>
Date: Wed, 8 Aug 2018 07:14:35 +0000

[to list this time ...]

Regards,

William

---

From: "Acee Lindem (acee)" <[email-masked]>
Date: Wed, 8 Aug 2018 11:28:19 +0000

Thanks Martin - see inline. 

On 8/8/18, 3:43 AM, "Martin Bjorklund" <[email-masked]> wrote:

    Hi,

It's not that easy since at the least the choice or another leaf must be specified. I found that the choice and case identifiers are not part of the Xpath. Even after rereading some sections of RFC7950, this wasn't intuitive.

Thanks,
Acee 

    /martin

---

From: "Acee Lindem (acee)" <[email-masked]>
Date: Wed, 8 Aug 2018 11:30:00 +0000

Hi William, 

On 8/8/18, 4:41 AM, "netmod on behalf of Ivory, William" <[email-masked] on behalf of [email-masked]> wrote:

    [to list this time ...]

I'll try this. 

Thanks - it seems it should work as long as the container only contain leaves and presence containers. 
Acee

    Regards,
    
    William

---

From: Martin Bjorklund <[email-masked]>
Date: Wed, 08 Aug 2018 13:31:45 +0200 (CEST)

"Acee Lindem (acee)" <[email-masked]> wrote:
> It's not that easy since at the least the choice or another leaf
> must be specified.

Maybe you can share the model (or a simplified version) in order to
illustrate the problem?

/martin

> I found that the choice and case identifiers are
> not part of the Xpath. Even after rereading some sections of
> RFC7950, this wasn't intuitive.
> 
> Thanks,
> Acee 
>     
>     
>     /martin
>     
>     
>

---

From: "Acee Lindem (acee)" <[email-masked]>
Date: Wed, 8 Aug 2018 13:34:55 +0000

Hi Martin, 

On 8/8/18, 7:31 AM, "Martin Bjorklund" <[email-masked]> wrote:

This is from one of the Cisco IOS-XE native models available on GitHub - https://github.com/YangModels/yang/tree/master/vendor/cisco/xe/1691

+--rw service* [name]
       +--rw name                     string
       +--rw description?             string
       +--rw group-object?            string
       +--rw (protocol-choice)?
          +--:(protocol-number-case)
          |  +--rw protocol-number?   uint8
          +--:(protocol-name-case)
             +--rw ahp?               empty
             +--rw eigrp?             empty
             +--rw esp?               empty
             +--rw gre?               empty
             +--rw icmp!
             |  +--rw port-number?            uint8
             |  +--rw alternate-address?      empty
             |  +--rw conversion-error?       empty
             |  +--rw echo?                   empty
             |  +--rw echo-reply?             empty
             |  +--rw information-reply?      empty
             |  +--rw information-request?    empty
             |  +--rw mask-reply?             empty
             |  +--rw mask-request?           empty
             |  +--rw mobile-redirect?        empty
             |  +--rw parameter-problem?      empty
             |  +--rw redirect?               empty
             |  +--rw router-advertisement?   empty
             |  +--rw router-solicitation?    empty
             |  +--rw source-quench?          empty
             |  +--rw time-exceeded?          empty
             |  +--rw timestamp-reply?        empty
             |  +--rw timestamp-request?      empty
             |  +--rw traceroute?             empty
             |  +--rw unreachable?            empty
             +--rw igmp?              empty
             +--rw ip?                empty
             +--rw ipinip?            empty
             +--rw nos?               empty
             +--rw ospf?              empty
             +--rw pcp?               empty
             +--rw pim?               empty
             +--rw tcp!
             |  +--rw tcp-port-list* [tcp-port]
             |     +--rw tcp-port        ios-types:acl-tcp-port-type
             |     +--rw operator?       enumeration
             |     +--rw max-tcp-port?   ios-types:acl-tcp-port-type
             +--rw tcp-udp!
             |  +--rw udp-port-list* [udp-port]
             |     +--rw udp-port        ios-types:acl-udp-port-type
             |     +--rw operator?       enumeration
             |     +--rw max-udp-port?   ios-types:acl-udp-port-type
             +--rw udp!
                +--rw udp-port-list* [udp-port]
                   +--rw udp-port        ios-types:acl-udp-port-type
                   +--rw operator?       enumeration
                   +--rw max-udp-port?   ios-types:acl-udp-port-type

Prior to YANG I certainly didn't have a lot of experience with Xpath. However, I had to learn thru trial and error that protocol-choice, protocol-number-case, and protocol-name-case are not part of the Xpath. I guess RFC 7950 section 7.9 does indicate that these two statements are not present in the data tree but it wasn't obvious to me that this also means it isn't in the Xpath.

Thanks,
Acee 

    
    /martin