ConfD User Community

Default-stmt can be ambiguous


#1

These two YANG “default” statements below are both acceptable to the ConfD.

  default 123;
  default "123";

I don’t know if quotes should be forbidden in default-stmt or not.
But as the ABNF from RFC-6020 claims:

string = < an unquoted string, as returned by >
< the scanner, that matches the rule >
< yang-string >

I’ll treat unquoted string as the correct format.
Then take this typedef-stmt for example.

typedef foo-type {
    type union {
        type string;
        type int32;
    }
    default 444;
}

From YANG grammar, I couldn’t tell what’s the actual type of default value “444”, it can be string, it also can be integer.

How does ConfD handle this?


#2

Both statements are valid, and there is no semantical difference between them. Quoting is required in the cases specified by https://tools.ietf.org/html/rfc6020#section-6.1.3, otherwise optional.

This means that the actual value is 123 - the quote characters are not part of the value.[quote=“lukai, post:1, topic:1619”]
typedef foo-type {
type union {
type string;
type int32;
}
default 444;
}

From YANG grammar, I couldn’t tell what’s the actual type of default value “444”, it can be string, it also can be integer.
[/quote]

From https://tools.ietf.org/html/rfc6020#section-9.12

   When a string representing a union data type is validated, the string
   is validated against each member type, in the order they are
   specified in the "type" statement, until a match is found.

Thus with that type definition, a default value will only ever match the string member, never int32. The corresponding text in https://tools.ietf.org/html/rfc7950#section-9.12 is a little different, because it takes into consideration that in the JSON encoding, strings and integers have different representation, and it is thus possible for a value to match the int32 member, while for XML encoding, a value can only match the string member.