1

In 'leaf remote-port' I need to get value from 'leaf base-port' and add number 100. The code below is incorrect because.

the value "base-port + 100" does not match its base type - not an integer

module internet-module {
    yang-version 1.1;
    namespace "elements:space";
    prefix im;
    
    container elements {
        list net-parameters {
            key base-port;
            
            leaf base-port {
                type uint16;
                mandatory true;
                description "Base Port number";
            }
            
            leaf remote-port {
                type uint16;
                mandatory true;
                description "Remote port number";
                
                default "base-port + 100";
            }
        }
    }
}

How can I do it correctly?

  • Is your requirement for "remote-port" to *always* have a value of "base-port" + 100, or *only* when the "remote-port" is not present in configuration (has the default value in effect)? My answer may change based on that. – predi Sep 01 '23 at 08:07

1 Answers1

0

Unfortunately, defaults are meant to be "static final" constants. You can't really make them depend on another value in a way you are attempting.

Note: you also cannot have a leaf with both default and mandatory properties set. When you set a default value for a leaf, you are actually implying that the leaf is mandatory. Same goes for leafs that represent list keys - it is implied that they are mandatory.

predi
  • 5,528
  • 32
  • 60