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?
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.