简体   繁体   English

如何在 YANG 中增加枚举

[英]How to augment an enumeration in YANG

Is there a way to augment an enumeration in another module in YANG?有没有办法在 YANG 的另一个模块中增加枚举? There is no way, in my case, to put all the values in the first module where the enumeration was defined.就我而言,没有办法将所有值放在定义枚举的第一个模块中。

Knowing that the enumeration is inside a grouping as follows:知道枚举在分组内,如下所示:

grouping mygrouping {
    ...
    container mycontainer {
        ...
        list mylist {
            leaf type {
                type enumeration {
                    enum type1
                    enum type2
                    ...
                    enum typen
                }
            }
        }
    }
}

The grouping is used in the new module, but I couldn't augment the leaf type to add new types in the enumeration.新模块中使用了分组,但我无法增加叶子类型以在枚举中添加新类型。

In YANG, enumerations are for well-known static set of options.在 YANG 中,枚举用于著名的 static 选项集。 For extensible options, you can use identityrefs.对于可扩展的选项,您可以使用 identityrefs。 This allows identities to be used in multiple files, and to define a leaf with a identityref type, which can then take any of the values of the defined identities.这允许在多个文件中使用身份,并定义一个具有 identityref 类型的叶子,然后它可以采用已定义身份的任何值。

Think of it as a decentralized enumeration.将其视为分散的枚举。 It's not really 'augmenting' but it does allow to introduce new options to a value without changing the original module.它并不是真正的“增强”,但它确实允许在不更改原始模块的情况下为值引入新选项。 Of course, this does assume that you can actually change the original leaf with the enumeration.当然,这确实假设您实际上可以使用枚举更改原始叶子。

Definition of identities in YANG RFC: https://tools.ietf.org/html/rfc6020#section-7.16 Some reference on enumeration versus identities: https://tools.ietf.org/html/rfc8407#section-4.11.1 YANG RFC 中的身份定义: https://tools.ietf.org/html/rfc6020#section-7.16关于枚举与身份的一些参考: https://tools.ietf.org/4.html/rf.1#1


Update: one option that is 'sort of' augmenting enums is to define the original enum in a typedef, and then extend it via a union:更新:“某种”增强枚举的一个选项是在 typedef 中定义原始枚举,然后通过联合扩展它:

typedef myenum {
    enum val1 { value 1; }
    enum val2 { value 2; }
    enum val3 { value 3; }
}

...

leaf myleaf {
    type union {
        type myenum;
        type enumeration {
            enum val4 { value 4; }
            enum val5 { value 5; }
        }
    }
}

So in this case, the myleaf can have values val1, val2, val3, val4, val5, which means the original enum was indeed 'augmented'.所以在这种情况下, myleaf可以具有值 val1、val2、val3、val4、val5,这意味着原始枚举确实是“增强的”。

Of course this means it is not really an enum, but a union between two enums, which are arranged so that their values don't intersect (something that unions do allow).当然,这意味着它不是真正的枚举,而是两个枚举之间的联合,它们的排列方式使它们的值不会相交(联合确实允许这样做)。 This may or may not be a simplification, on both client and server side - depending on the implementation.在客户端和服务器端,这可能是也可能不是简化 - 取决于实现。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM