Yang Modeling 以另一个领域为基础设置一个领域

Yang Modeling Set a Field Based on Another Field

我在写一个杨模型。是否可以使用基于另一个字段的值来设置叶(字符串或枚举)。因此,例如,我想说如果 x 则字段 a 的值为 b,如果 z 则字段 a 的值为 c。

编辑:我是 yang 的新手,仍在努力学习,如果有任何其他想法或运算符可以用来解决这个问题,请不要犹豫分享。 :D 非常感谢。

您可以使用 whenmust 结构:YANG 1.1, Section 7.5.3 说:

The must statement, which is optional, takes as an argument a string that contains an XPath expression (see Section 6.4). It is used to formally declare a constraint on valid data. The constraintis enforced according to the rules in Section 8.

Section 7.5.4.3 布局:

 container interface {
   leaf ifType {
     type enumeration {
       enum ethernet;
       enum atm;
     }
   }
   leaf ifMTU {
     type uint32;
   }
   must 'ifType != "ethernet" or ifMTU = 1500' {
     error-message "An Ethernet MTU must be 1500";
   }
   must 'ifType != "atm" or'
      + ' (ifMTU <= 17966 and ifMTU >= 64)' {
     error-message "An ATM MTU must be 64 .. 17966";
   }
 }

whenSection 7.21.5 阅读,

The when statement makes its parent data definition statement conditional. The node defined by the parent data definition statement is only valid when the condition specified by the when statement is satisfied. The statement's argument is an XPath expression (see Section 6.4), which is used to formally specify this condition.

ConfD 提供了关于 XPath in NETCONF and YANG 的教程;这个例子来自它:

augment /system/login/user {
  when “class != ’wheel’”;
  leaf uid {
    type uint16 {
    range “1000 .. 30000”;
    }
  }
}