Ask is moving to Stack Overflow and! Please use the "opendaylight" tag on either of these sites. This site is now in Read-Only mode


Yang model default value doesn't work

asked 2015-07-04 11:31:49 -0700

labry gravatar image

updated 2015-07-04 11:32:46 -0700


I have set my counter to have default 100, but when I retrieve it from the data broker the default value is 0. It seems like default value doesn't work. Could you tell me how I can fix this problem.


container helloWorld {
    leaf counter {
        type uint32;
        config true;
        default 100;

    leaf value {
        type string;
        config false;
        mandatory false;


    Future<Optional<HelloWorld>> readFuture = 

    if(readFuture.isDone()) {

        try {
            long helloCount = readFuture.get().get().getCounter();
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
        } catch (ExecutionException e) {
            // TODO Auto-generated catch block
        }"helloCounter:" + helloCounter);
    } else {"helloCounter is not ready.");

it gives 0 instead of 100

Thank you!

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted

answered 2015-07-05 21:53:46 -0700

labry gravatar image

updated 2015-08-12 20:59:31 -0700

My conclusion is default in Yang is just human readable text. Even in the wiki "default" doesn't have any mapping relationships to JAVA like description and units. Please correct me if I am wrong.

================================================================== I got this from ODLsummit 2015. There is no doubt that ODL currently does not support default statment. :-D

image description

edit flag offensive delete publish link more


No, I know it is possible to add a default value. Have you tried default '100'; ?

grmontpetit ( 2015-07-06 03:59:25 -0700 )edit

Yes, I have tried default 100; default '100', and default "100"; All three of them failed to set the default value. Even if I look at the generated Java file (HelloWorld and HelloWorldBuilder), I don't see any of the code that can perform initialization for the values.

labry ( 2015-07-06 05:03:05 -0700 )edit

However, the range "1 .. 1000" works for me, but not default.

labry ( 2015-07-06 05:03:38 -0700 )edit

I could have sworn I used default value via RESTConf (didn't have specify a value).

grmontpetit ( 2015-07-06 05:36:06 -0700 )edit

Then there must be some configuration that maps default values to DTOs. I wonder where that is. :-(

labry ( 2015-07-07 22:43:20 -0700 )edit

answered 2015-07-05 19:31:29 -0700

updated 2015-07-06 04:01:01 -0700


Try rewriting your yang this way:

default '100';

Also, you might have to specify a range, like so:

     type uint32 {
       range "1 .. 1000";


edit flag offensive delete publish link more


You know what.. I try that but it doesn't work either. Thanks anyway.

labry ( 2015-07-05 21:51:34 -0700 )edit

Hello grmontpetit.. Can you please share which version of ODL you are using? and How do you post data for the leaf having default value in yang model. I am also trying to get default value populated but it is not working

sdvac15 ( 2015-11-16 14:14:33 -0700 )edit
Login/Signup to Answer

Question Tools

1 follower


Asked: 2015-07-04 11:31:49 -0700

Seen: 545 times

Last updated: Aug 12 '15