简体   繁体   English

YANG 和 Choice - XML 是什么样子的?

[英]YANG and Choice - what does the XML look like?

I am trying to figure out the proper syntax for implementing the choice field from a yang model into its corresponding configuration xml. Unfortunately, the documentation in RFC 6020 and other Yang related web pages don't seem to show how to use a choice field in the actual XML which speaks to the Yang model.我试图找出将choice字段从 yang model 实现到其相应配置 xml 的正确语法。不幸的是,RFC 6020 和其他与 Yang 相关的 web 页面中的文档似乎没有显示如何在与 Yang model 通话的实际 XML。

For example, here is my YANG model:例如,这是我的 YANG model:

container MYMODEL {
    container PacketOperationConf {
        list RuleID {
            key id;
            leaf id {
                type int32;
            }
            leaf priority { 
                type int32; 
            }
            leaf name { 
                type string; 
            }
            choice type {
                case flow {
                    list action {
                        key order;
                        uses mymodel:action;
                    }
                    container match {
                        uses mymodel:match;
                    }
                }
                case function {
                    container function {
                        
                    }
                }
            }
        }
        ...

And there is the corresponding XML for this container:这个容器有对应的 XML:

<?xml version="1.0" encoding="UTF-8" ?>
<rpc message-id="101"
    xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
    <edit-config>
        <target>
            <running />
        </target>
        <config>
            <MYMODEL xmlns="urn:com:tug:mymodel">
                <PacketOperationConf>
                    <RuleID>
                        <id>101</id>
                        <type>
                            <flow>
                                <action>
                                    <order>1</order>
                                    <set-dl-src-action>
                                        <address>01:02:03:04:05:06</address>
                                    </set-dl-src-action>
                                </action>
                            </flow>
                        </type>
                    </RuleID>
                </PacketOperationConf>
            </MYMODEL>
        </config>
    </edit-config>
</rpc>

But when I run this through yang2dsdl I get the following error:但是当我通过yang2dsdl运行它时,出现以下错误:

$ yang2dsdl -t edit-config -v rmbn-full-test-1.xml -d /tmp rmbn-full.yang
== Generating RELAX NG schema '/tmp/rmbn-full-edit-config.rng'
Done.

== Validating grammar and datatypes ...
rmbn-full-test-1.xml:13: element type: Relax-NG validity error : Element RuleID has extra content: type
Relax-NG validity error : Extra element RuleID in interleave
rmbn-full-test-1.xml:11: element RuleID: Relax-NG validity error : Element PacketOperationConf failed to validate content
rmbn-full-test-1.xml fails to validate

So the error happens because it doesn't know what to do with the type element.所以错误发生是因为它不知道如何处理type元素。 The type element is the name of my choice section in the yang model. type元素是我在yang model中选择的部分的名称。

I have tried a variety of arrangements of this, however none have worked.我已经尝试过各种安排,但没有一个奏效。 I'm also unable to find anything on SOF or Google on examples of choices as implemented in XML.我也无法在 SOF 或 Google 上找到任何关于 XML 中实施的选择示例的信息。

Both case and choice are what the RFC refers to as schema nodes, but they are not also data nodes - schema nodes that may be instantiated. case 和 choice 都是 RFC 所指的模式节点,但它们也不是数据节点——可以实例化的模式节点。 Therefore choice and case nodes never appear in a valid instance document, they only impose restrictions on what a valid instance document is.因此,选择和案例节点永远不会出现在有效实例文档中,它们仅对有效实例文档是什么施加限制。

In your case, that would mean an optional choice (XOR) between:在您的情况下,这意味着在以下之间进行可选选择(XOR):

  • the (logical) group of elements containing <action> (list) and/or <match> (container),包含<action> (列表)和/或<match> (容器)的(逻辑)元素组,
  • <function> container. <function>容器。

To put it another way, if <action> appears in the instance document, <match> may also appear (and vice versa), but <function> may not appear.换句话说,如果<action>出现在实例文档中, <match>也可能出现(反之亦然),但<function>可能不会出现。

Here's a valid document (did not actually test).这是一个有效的文件(没有实际测试)。

<?xml version="1.0" encoding="UTF-8" ?>
<rpc message-id="101"
    xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
    <edit-config>
        <target>
            <running />
        </target>
        <config>
            <RMBN xmlns="urn:com:tug:rmbn-full">
                <PacketOperationConf>
                    <RuleID>
                        <id>101</id>
                        <action>
                            <order>1</order>
                            <set-dl-src-action>
                                <address>01:02:03:04:05:06</address>
                            </set-dl-src-action>
                        </action>
                    </RuleID>
                </PacketOperationConf>
            </RMBN>
        </config>
    </edit-config>
</rpc>

Below is some text from RFC6020 (YANG version 1.0), since you specifically asked about that version ( Section 7.9 ).以下是 RFC6020(YANG 版本 1.0)中的一些文本,因为您专门询问了该版本(第 7.9 节)。

The "choice" statement defines a set of alternatives, only one of which may exist at any one time. “选择”语句定义了一组备选方案,在任何时候只能存在其中一个。 The argument is an identifier, followed by a block of substatements that holds detailed choice information.参数是一个标识符,后跟一个包含详细选择信息的子语句块。 The identifier is used to identify the choice node in the schema tree.标识符用于标识模式树中的选择节点。 A choice node does not exist in the data tree.数据树中不存在选择节点。

A choice consists of a number of branches, defined with the "case" substatement.选择由多个分支组成,用“case”子语句定义。 Each branch contains a number of child nodes.每个分支包含多个子节点。 The nodes from at most one of the choice's branches exist at the same time.来自至多一个选择分支的节点同时存在。

The "case" statement is used to define branches of the choice. “case”语句用于定义选择的分支。 It takes as an argument an identifier, followed by a block of substatements that holds detailed case information.它以标识符作为参数,后跟包含详细案例信息的子语句块。

The identifier is used to identify the case node in the schema tree.标识符用于标识模式树中的案例节点。 A case node does not exist in the data tree.数据树中不存在案例节点。

Within a "case" statement, the "anyxml", "choice", "container", "leaf", "list", "leaf-list", and "uses" statements can be used to define child nodes to the case node.在“case”语句中,“anyxml”、“choice”、“container”、“leaf”、“list”、“leaf-list”和“uses”语句可用于定义 case 节点的子节点. The identifiers of all these child nodes MUST be unique within all cases in a choice.所有这些子节点的标识符在一个选择的所有情况下必须是唯一的。

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

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