Subject: [yang-doctors] value statement in enum

From: Mahesh Jethanandani <[email-masked]>
Date: Fri, 22 Jun 2018 12:53:45 -0700

RFC 7950 states in Section 9.6.4.2 that

   The "value" statement, which is optional, is used to associate an
   integer value with the assigned name for the enum.  This integer
   value MUST be in the range -2147483648 to 2147483647, and it MUST be
   unique within the enumeration type.

Does that mean enum can only be a signed integer value? What if the type we are trying to define is a unsigned int, as in this case? Note, 0 already has a special meaning in this case, so I cannot assign that value.

          leaf repeat {
            type union {
              type uint32 {
                range 0..4294967294;
              }
              type enumeration {
                enum forever {
                  value 4294967295;
                  description
                    "Indicates that the test session SHALL be
                     repeated *forever* using the information in
                     repeat-interval parameter, and SHALL NOT
                     decrement the value.";
                }
              }
            }
            default 0;
            description
              "This value determines if the TWAMP-Test session must
               be repeated. When a test session has completed, the
               repeat parameter is checked.

               The default value of 0 indicates that the session
               MUST NOT be repeated.

               If the repeat value is 1 through 4,294,967,294
               then the test session SHALL be repeated using the
               information in repeat-interval parameter, and the
               parent TWAMP-Control connection for this test
               session is restarted to negotiate a new instance
               of this TWAMP-Test session.";
          }

Currently, pyang spits out the following error:

yang/[email-masked]:830: error: the enumeration value "4294967295" is not an 32 bit integer

Thanks.

Mahesh Jethanandani
[email-masked]

---

From: Juergen Schoenwaelder <[email-masked]>
Date: Sat, 23 Jun 2018 12:39:46 +0200

On Fri, Jun 22, 2018 at 12:53:45PM -0700, Mahesh Jethanandani wrote:
> Does that mean enum can only be a signed integer value?

Yes.

> What if the type we are trying to define is a unsigned int, as in this case? Note, 0 already has a special meaning in this case, so I cannot assign that value.
> 
>           leaf repeat {
>             type union {
>               type uint32 {
>                 range 0..4294967294;
>               }
>               type enumeration {
>                 enum forever {
>                   value 4294967295;
>                   description

You are defining a union of an uint32 and an enum, which has a numeric
value space of int32, but the encoding is the enum name in XML and
JSON. One option to avoid a clash in the numeric spaces is this:

           leaf repeat {
             type union {
               type uint32 {
                 range 0..4294967294;
               }
               type enumeration {
                 enum forever {
                   value -1;
  	         }
	       }
	     }
	  }

/js

-- 
Juergen Schoenwaelder           Jacobs University Bremen gGmbH
Phone: +49 421 200 3587         Campus Ring 1 | 28759 Bremen | Germany
Fax:   +49 421 200 3103         <https://www.jacobs-university.de/>

---

From: Robert Wilton <[email-masked]>
Date: Wed, 27 Jun 2018 09:55:23 +0100

I quite like Juegen's suggestion below.

Another couple of choices:
  (1) don't use a union, instead, just define in the leaf description 
that the value 4294967295 means that it repeats forever.
  (2) will users of the model really want repeats in the 2-4 billion 
range?  If not, the union could use int32 instead, and use either 
2,147,483,647 or -1 as the enum value to represent "forever".

Thanks,
Rob

---

From: "Reshad Rahman (rrahman)" <[email-masked]>
Date: Wed, 27 Jun 2018 12:33:54 +0000

A similar option we discussed offline is to have a choice with 2 cases: a) repeat-count type uint32 b) forever type empty

Regards,
Reshad.

On 2018-06-27, 4:55 AM, "yang-doctors on behalf of Robert Wilton" <[email-masked] on behalf of rwilton=[email-masked]> wrote:

    
    Thanks,
    Rob

    > JSON. One option to avoid a clash in the numeric spaces is this:
    
    _______________________________________________
    yang-doctors mailing list
    [email-masked]
    https://www.ietf.org/mailman/listinfo/yang-doctors