【问题标题】:Yang Model recursive search for must condition杨模型递归搜索必须条件
【发布时间】:2019-01-25 16:00:34
【问题描述】:

我的 CLI 限制存在问题。我一直在调查 yang RFC7950 (https://www.rfc-editor.org/rfc/rfc7950),但什么也没找到。

这是一个例子。

grouping httpGroup {
  list http-list{
    key "value";
    leaf value {
      status current { yexte:preliminary; }
      description "value to match";
      must "(not(../protocol)) and (not(../network-port)))" {
        error-message "Not compatible with protocol or non-TCP ports";
      }
      type string { length "1..255"; }
    }
  }
}

该组将包含在具有以下结构的多个组中:

list and {
  leaf-list protocol { ..... }
  uses A;
  list or { 
    leaf-list protocol { ..... }
    uses A;
  }
}
grouping A {
  status{}
  leaf-list protocol { ..... }
  leaf-list X { ..... }
  uses httpGroup;
}

我需要在 httpGroup 中包含这个必须条件来验证协议值是否在层次结构的任何级别中配置。

我已经添加了更多的亲戚路径来搜索这个节点:

// same level
not(../protocol)

// next level
not(../and/protocol)
not(../or/protocol)

// previous level
not(../../protocol)
not(../../protocol)

//recursively down previous level
not(../../and/protocol)
not(../../or/protocol)

// third level
not(../and/or/protocol)
not(../and/and/protocol)

如您所见,这根本不是一个干净的解决方案。

有什么方法可以为整个层次结构完成,例如:

if protocol node exists and http-list exists then error.

提前谢谢你。

【问题讨论】:

  • 您的结构示例没有意义。您不能在列表and 中使用分组A,因为它试图定义重复的protocol 叶列表子级。请澄清这一点。

标签: ietf-netmod-yang


【解决方案1】:

分组意味着可重复使用。尝试创建只能在特定上下文中使用的分组是一种不好的做法。如果您在一个分组中定义一个 XPath 表达式并且该表达式引用了该分组“外部”的节点(例如,一个未知的祖先数据节点,或者更糟糕的是一个具有特定名称的祖先),这正是发生的情况。

处理这种情况的正确方法是在使用此分组的每个不同上下文中使用细化语句。你用它定位value 叶,然后通过添加一个必须语句来改进它,它的表达式当然取决于使用上下文。您确实在分组 http-list 中定义 must 语句。

分组内A

grouping A {
  status{}
  leaf-list protocol { ..... }
  leaf-list X { ..... }
  uses httpGroup {refine "http-list/value" {must "not(../../protocol)";}}
}

如您所见,分组 A 现在完全自给自足,可以在任何情况下使用 - 肯定不会有任何问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-11
    • 2015-09-19
    • 2010-12-24
    • 2012-06-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多