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

0

Yang model default value doesn't work

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

labry gravatar image

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

Hello,

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.

hello.yang

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

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

..

HelloWorldImpl.java

    Future<Optional<HelloWorld>> readFuture = 
            tx.read(LogicalDatastoreType.CONFIGURATION, HELLO_IID);

    if(readFuture.isDone()) {

        try {
            long helloCount = readFuture.get().get().getCounter();
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (ExecutionException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        LOG.info("helloCounter:" + helloCounter);
    } else {
        LOG.info("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
0

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

labry gravatar image

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

My conclusion is default in Yang is just human readable text. Even in the wiki https://wiki.opendaylight.org/view/YANGTools:YANGtoJavaMapping "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

Comments

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

grmontpetit ( 2015-07-06 03:59:25 -0800 )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 -0800 )edit

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

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

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

grmontpetit ( 2015-07-06 05:36:06 -0800 )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 -0800 )edit
0

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

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

Hello,

Try rewriting your yang this way:

default '100';

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

     type uint32 {
       range "1 .. 1000";
     }

Cheers

edit flag offensive delete publish link more

Comments

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

labry ( 2015-07-05 21:51:34 -0800 )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 -0800 )edit
Login/Signup to Answer

Question Tools

Follow
1 follower

Stats

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

Seen: 408 times

Last updated: Aug 12 '15