yang 中默认值的条件赋值

use*_*937 3 ietf-netmod-yang

我的模型有两个属性:

  • 叶协议,
  • 叶端口。

我想具体说明的是:

  • 如果协议 = 'ssh' 那么默认端口值为 22,
  • 如果协议 = 'http' 那么默认端口值为 80,
  • ETC。

我该如何用 yang 来表达这个意思?

pre*_*edi 5

YANG 中没有条件default值 -default对于两个defaults具有不同值的语句,您需要两个语句,并且单个语句leaf可能只有一个子default语句。不过,您可以解决这个问题。也许通过使用 apresence container而不是您的协议leaf

module conditional-default {
  namespace "http://example.com/conditional-default";
  prefix "excd";

  grouping common {
    leaf port {
      type int32;
    }
  }

  container config {

    container ssh {
      presence "If this container is present, ssh is configured.";
      uses common {
        refine port {
          default 22;
        }
      }
    }
    container http {
      presence "If this container is present, http is configured.";
      uses common {
        refine port {
          default 80;
        }
      }
    }

  }

}
Run Code Online (Sandbox Code Playgroud)

来自 RFC6020,7.5.5:

“存在”语句为数据树中容器的存在赋予含义。它采用一个字符串作为参数,其中包含节点存在含义的文本描述。