ConfD User Community

Leaf with when statement and default value


#1

Hi, I have a yang model with when statement and default values and I use external database and when I do a set confD fills in the default values for me.

The problem I have is that it fills in all defaults, if attrib-type is 1 I still get the default value for attrib-val-string and I get a bad-element error from confD telling me that the attrib-val-string is not valid when attrib-type is 1.

I could use the confd_set_daemon_flags( , CONFD_DAEMON_FLAG_NO_DEFAULTS); to get rid of the problem but I would like to have it anabled and get the default values for all valid leafs.

container c1 {
    leaf  attrib-type {
        type uint32;
    }
    leaf attrib-val-int {
        when "../attrib-type = 1 or ../attrib-type = 2"
        type uint32;
        default 1;
    }   

    leaf attrib-val-string {
        when "../attrib-type = 5 or ../attrib-type = 6"
        type string;
        default "one";
    }   
}

#2

Are you referring to CLI completion?
You may try to write your own completion points and see if it can solve your issue (see 16.13.1. Customizing CLI completion in ConfD user guide).


#3

Not CLI, just plain old yang.

as I tried to explain in the question the client can send

: <c1><attrib-type>2</attrib-type></c1> :

and confd will fill in the default data and our application will receive set/create/xx requests as if the client sent
: <c1> <attrib-type>2</attrib-type> <attrib-val-int>1</attrib-val-int> <attrib-val-string>one</attrib-val-string> </c1> :

this will not pass the model validation and the client will get back a bad element eller on

even if the client send the valid data
: <c1> <attrib-type>2</attrib-type> <attrib-val-int>1</attrib-val-int> </c1> :

confd still add the default data for the leaf

If I call the confd_set_daemon_flags( , CONFD_DAEMON_FLAG_NO_DEFAULTS); and instruct confd not to supply default data the

: <c1> <attrib-type>2</attrib-type> <attrib-val-int>1</attrib-val-int> </c1> :
validates fine and works but now the
: <c1><attrib-type>2</attrib-type></c1> :
will not work.

The correct behaviour should be to add default values for leafs that is currently valid according to the model.


#4

By validation, do you mean validation done by ConfD (according to the YANG) or validation done by your application?

I have tried following in CLI (just YANG validation using your model, ConfD 6.5):

config
c1 attrib-type 2
commit

show full-configuration c1 | details
c1 attrib-type 2
c1 attrib-val-int 1

c1 attrib-type 3
commit

show full-configuration c1 | details
c1 attrib-type 3

c1 attrib-type 5
commit

show full-configuration c1 | details
c1 attrib-type    5
c1 attrib-val-string one

Is it similar to your scenario? Does it work same in your case?


#5

Why not try the same thing as described in the post? Doing other stuff does not make sense.

  • external dB application written in c
  • yang model like the one in the post
  • edit config via netconf-console with <c1><attrib-type>2</attrib-type></c1>

confd rejects the setting with bad element on attrib-val-string.

if you add confd_set_daemon_flags( , CONFD_DAEMON_FLAG_NO_DEFAULTS); to the code then it will pass and the request will reach the external dB application

My problem is that confd adds the default data for the attrib-val-string which is not valid since attrib-type is 2
the external dB application does not get any calls from confd so the validation of the xml is done by confd.


#6

Yes, I just wanted to make sure everything is working as expected when you do not use external DB (disable callback temporarily) as troubleshooting with callback is more difficult. I agree the scenario is different as you have issue with set callback.

Here are also netconf-console -i commands (add <defaultHandlingMode>report-all</defaultHandlingMode> to confd.conf as described I entered a default value in my YANG module, but it doesn’t show )

netconf-console -i

<edit-config>
<target>
    <running/>
</target>
<config>
    <c1 xmlns="http://tail-f.com/ns/example/datamodel"
           xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">
        <attrib-type>2</attrib-type>
    </c1>
</config>
</edit-config>

<get>
    <filter xmlns="http://tail-f.com/ns/example/datamodel">
   <c1/>
    </filter>
</get>

the output

<?xml version="1.0" encoding="UTF-8"?>                                                                             │$
<rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="2">                                         │
  <data>                                                                                                           │
    <c1 xmlns="http://tail-f.com/ns/example/datamodel">                                                            │
      <attrib-type>2</attrib-type>                                                                                 │
      <attrib-val-int>1</attrib-val-int>                                                                           │
    </c1>                                                                                                          │
  </data>                                                                                                          │
</rpc-reply>