How to define different default value for different product

As you know, the default value could be defined in Yang file for each leaf.

But how to define different default values for different product? As these products use the same Yang file and they should have different default value for one same leaf.

One way is to have a YANG annotation file per product that annotate the shared YANG model with different default values depending on product.
See ConfD 6.3-4 UG Chapter 3.7.1. ā€œUsing a YANG annotation fileā€ and tailf_yang_extensions(5) man page under ā€œtailf:annotateā€ and ā€œtailf:annotate-moduleā€.

I am still not very clear for the annotate to implement the case. Could you help to explain more detail?

Which part is not clear?
How to implement an annotation file that add an application specific default value to a base YANG model used by all applications that does not have a default statement?

How to define the annotation file? Then how to use in the Yang module for the annotation file?

Thanks for the clarification, A good starting point is the examples.confd/validate/c/mtest.annot.yang model that annotate the mtest.yang model.
See also the Makefile in that example for how the annotation model, mtest.annot.yang is compiled with confdc to annotate the mtest.yang model.
You can search for ā€œtailf:annotateā€ in the YANG models provided in the ConfD example set for more variants.

Yang RFC also describes a way to set default value with deviate statement (for different product one can use different deviation file, see confdc --deviation).
https://tools.ietf.org/html/rfc6020#section-7.18.3.3

When I tried something like this.

tailf:annotate ā€œ/if:interfaces/if:interface/if:portā€ {
when ā€œcurrent()/ā€¦/if:protocol = ā€˜sshā€™ā€{
default 22;
}
}

But I am receving an error as
ā€œerror: unexpected keyword ā€œdefaultā€.ā€

another way is to use deviation for different product.

deviation /base:system/base:user/base:type {
deviate add {
default ā€œadminā€; // new users are ā€™adminā€™ by default
}
}

I do not think you can add deault value conditionally, as deviation or deviate cannot have when substatement.

Yes, deviation without condition would work.

My requirement is more of having a different default values for a leaf ā€œportā€ based on the leaf ā€œprotocolā€.

Any other options available to achieve this ?

You can use tailf:set-hook callpoint, that would be called on every modification of the protocol leaf.
It can modify/update port leaf accordingly.

leaf protocol {
      tailf:callpoint protocol_hook {
           tailf:set-hook node;
        }
        type string;
}

Unfortunately, you need to write (simple) hook callback handler.
More description is in the ConfD User Guilde, section 10.6 (Hooks)

1 Like

Thanks for your inputs :slight_smile:

I will try this oneā€¦