【问题标题】:unique constraint in yang models杨模型中的唯一约束
【发布时间】:2019-04-16 00:37:37
【问题描述】:

如果我有以下型号

devices {
  device {
     key id;
     interfaces {
        interface {
            key id;
            unique name;        
        }
     }
  }
}

which data is valid or invalid according to yang's key and unique    specification ?
1. devices/device=1/interfaces/interface=1; name = a 
2. devices/device=1/interfaces/interface=1; name = b  // key violation 
3. devices/device=1/interfaces/interface=2; name = a  // unique violation
4. devices/device=2/interfaces/interface=1; name = a  // unique violation ?

假设我将“接口”对象存储在关系表中并将名称标记为唯一列,我不能同时拥有数据行 3 和 4。这就是规范的含义吗?

或者, 我可以将唯一性或键约束解释为唯一资源路径吗? 如果我这样做了,下面几行数据不会冲突,因为它们是两个不同的资源url,因为它们属于不同的设备。

devices/device=1/interfaces/interface=2; name = a  
devices/device=2/interfaces/interface=2; name = a  

什么是正确的解释?全局唯一与列表父级中的唯一?

【问题讨论】:

    标签: ietf-netmod-yang


    【解决方案1】:

    正确的答案可能是:it is unclear 用于嵌套列表。

    “唯一”约束指定所有 参数字符串中指定的叶子实例,包括带有 默认值,在所有列表条目实例中必须是唯一的 所有引用的叶子都存在或具有默认值。

    RFC7950, Section 7.8.3.

    “list”语句用于定义内部数据节点 架构树。一个列表节点可能存在于数据中的多个实例中 树。每个这样的实例都称为一个列表条目。

    RFC7950, Section 7.8.

    RFC6020(YANG 版本 1)中出现相同的文本。

    如果你严格解释它,你别无选择:你必须让所有列表条目在全局上都有一个唯一的name 才能满足约束。请注意,由于措辞相似,这同样适用于列表的键。

    目前尚不清楚这是否是意图。

    RFC6110,它使用现有的 XML 技术处理基于 YANG 的实例验证,将其解释为 unique within parent,并且它是由同一个 WG 创建的:它使用 preceding-sibling:: XPath 轴来强制执行约束,这不会在device/id=1 中提取device/id=2 接口条目,因为device/id=1/interfaces/interface 实例和device/id=2/interfaces/interface 实例不是XML 文档中的兄弟。

    请注意,RFC 不能免于错误。

    【讨论】:

      【解决方案2】:

      unique 的作用域与key 的作用域相同。也就是说,在您的示例中,不同的设备具有单独的接口列表。同样,设备“1”和“2”都有接口“1”,设备“1”和“2”可以有名称为“a”的接口。

      请注意,与key 不同,unique 可以引用后代节点。如果想使名称在设备之间保持唯一,则可以在设备列表中使用unique

      list device {
          key 'id';
          unique 'interfaces/interface/name';
          ...
      }
      

      【讨论】:

        猜你喜欢
        • 2022-07-05
        • 1970-01-01
        • 2015-06-15
        • 2018-08-16
        • 1970-01-01
        • 2022-01-22
        • 2015-05-22
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多