【问题标题】:YANG: how to model nested lists configuration data without keyYANG:如何为没有键的嵌套列表配置数据建模
【发布时间】:2018-08-11 12:20:23
【问题描述】:

我正在尝试为该配置文件构建 YANG 模型,该配置文件包含没有键的列表。但是,由于 YANG 列表中 key 的必要性,我无法建立精确的 YANG 模型。 是否知道如何在 YANG 中表示没有键的列表列表。

该文件包含 acl,其中可能有许多 acl,如用户命名的 acl1、acl2,并具有如下示例所示的规则。

acls:
  acl1:
  - rule:
      nw_src: 192.168.1.1/24  
      actions:
        allow: 1
  - rule:
      actions:
        allow: 0
  acl2:
  - rule:
      nw_src: 192.168.1.1/24  
      actions:
        allow: 0
  - rule:
      actions:
        allow: 1

我的 YANG 模型是

list acls{
     description "list of acls ";
      key "acl-name";
      ordered-by user;
      leaf acl-name {
        type string {
          length "1..64";
        }
      }
 list acle {
      description "This is a list of users in the system.";
      key "acle-name";
      ordered-by user;
      leaf acle-name {
        type string {
          length "1..64";
        }
        description
          "The name of access-list. A device MAY restrict the length
           and value of this name, possibly space and special
           characters are not allowed.";
      }

      container actions {
        description "actions for this acl entry ";    
        leaf allow {
          type uint8;
         }              
      } // end actions container       
   container match{
        description "match fields for this acl entry ";
    leaf nw_src{
         type inet:ipv4-address;
         }
    }
 }//match cont
 }//acle
} //acls

因此,相应的有效数据文件具有 YANG 所需的额外字段,但在我上面的原始配置文件中不存在,例如 (aclname, acle, aclename)。

acls:
  acl1:
    aclname: acl1
    acle:
      rule11:
        aclename: rule11
        nw_src: 192.168.1.1/24
        actions:
          allow: 1
      rule12:
        aclename: rule12
        actions:
          allow: 0
  acl2:
    aclname: acl2
    acle:
      rule21:
        nw_src: 192.168.1.1/24    
        aclename: rule21
        actions:
          allow: 0
      rule22:
        aclename: rule22
        actions:
          allow: 1

【问题讨论】:

    标签: validation data-modeling ietf-netmod-yang ietf-netconf


    【解决方案1】:

    RFC7950, 7.8.2. The list's "key" Statement

    “key”语句,如果列表表示,则必须存在 配置,否则可能存在,作为参数 指定一个或多个叶子的空格分隔列表的字符串 此列表的标识符。叶标识符不得出现更多 不止一次在关键。每个这样的叶子标识符必须引用一个 列表的子叶。叶子可以直接定义在 列表的子语句或列表中使用的分组。

    键中指定的所有叶子的组合值用于 唯一标识一个列表条目。必须为所有关键叶赋予值 创建列表条目时。因此,键中的任何默认值 叶子或其类型被忽略。任何“强制性”声明 忽略关键叶子。

    列出模型配置数据(无论是否嵌套)必须有一个键。没有办法解决这个问题,因为每个配置列表实例都必须是唯一可识别的,这样instance-identifiers 这样的结构才能按预期工作。如果没有密钥,您将很难告诉设备修改(甚至简单地获取)配置中的特定条目。因此,您打算做的事情是无法实现的——这不是 YANG 的方式。

    只有状态数据 (config false;) 列表可能没有键存在,因为它们不必以标准方式修改 - 它们的实例化/修改/删除由设备的实现细节控制。

    此外,您已经在示例中使用了键。 “acl1”和“acl2”显然是“acl”列表的实例,它们的键被编码到它们的名称中。

    【讨论】:

      猜你喜欢
      • 2020-02-17
      • 2016-11-09
      • 2013-02-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-16
      • 1970-01-01
      相关资源
      最近更新 更多