YANG:如何在没有密钥的情况下为嵌套列表配置数据建模 [英] YANG: how to model nested lists configuration data without key

查看:148
本文介绍了YANG:如何在没有密钥的情况下为嵌套列表配置数据建模的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为该配置文件构建YANG模型,该模型具有没有键的列表.但是,由于必须使用YANG列表中的密钥,所以我无法建立精确的YANG模型. 有什么想法如何在不使用YANG的情况下表示列表的列表吗?

I am trying to build YANG model for this configuration file that has lists without keys. However, Due to the necessity of key in YANG list, I wasn't able to build exact YANG model. Is there any idea how to represents list of list without key in YANG.

文件包含ACL,其中可能有许多ACL,例如用户命名的ACL1,ACL2,并且具有如下示例中所示的规则.

The file includes acls in which there could be many acl like acl1, acl2 named by users and has rules as in the example below.

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)不存在.

And hence the corresponding valid data file has extra fields that are necessary for YANG but not exist in my original configuration file above like (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

推荐答案

RFC7950 ,7.8.2.列表的关键"声明

"key"语句,如果列表表示,则必须存在 配置,否则可以存在,将a作为参数 指定一个或多个叶子的以空格分隔的列表的字符串 此列表的标识符.叶标识符不得再出现 不止一次按键.每个这样的叶子标识符必须引用一个 列表的子叶.可以在以下位置直接定义叶子 列表的子陈述或列表中使用的分组.

The "key" statement, which MUST be present if the list represents configuration and MAY be present otherwise, takes as an argument a string that specifies a space-separated list of one or more leaf identifiers of this list. A leaf identifier MUST NOT appear more than once in the key. Each such leaf identifier MUST refer to a child leaf of the list. The leafs can be defined directly in substatements to the list or in groupings used in the list.

键中指定的所有叶子的组合值用于 唯一标识列表项.必须为所有关键叶子赋予值 创建列表条目时.因此,密钥中的任何默认值 叶子或其类型将被忽略.广告中的任何强制性"陈述 关键叶子将被忽略.

The combined values of all the leafs specified in the key are used to uniquely identify a list entry. All key leafs MUST be given values when a list entry is created. Thus, any default values in the key leafs or their types are ignored. Any "mandatory" statements in the key leafs are ignored.

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

Lists that model configuration data (whether nested or not) must have a key. There is no way around this, because each configuration list instance must be uniquely identifiable, so that constructs like instance-identifiers work as expected. You would have a hard time telling a device to modify (or even simply obtain) a specific entry in your configuration, if there were no keys. What you are proposing to do is therefore not achievable - it is not the YANG way of things.

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

Only state data (config false;) lists may exist without keys because they do not have to be modified in a standard way - their instantiation/modification/removal is governed by implementation details of a device.

此外,您已经在示例中使用了键. "acl1"和"acl2"显然是"acl"列表的实例,其键名已编码为它们的名称.

Besides, you are already using keys in your example. The "acl1" and "acl2" are clearly instances of an "acl" list, which have their key encoded into their name.

这篇关于YANG:如何在没有密钥的情况下为嵌套列表配置数据建模的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆