0

I use pyang's yang2dsl for validating input xml instances against yang data model. But, it throws error when the order of the parameters in the xml instances is not the same as in yang model. Is there an option to make it ignore the order of parameters? Here's my xml code(example.xml):

<rpc xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="100">
<action>
<param1>aaa</param1>
<param2>bbb</param2>
</action>
</rpc>

Here's my YANG model, example.yang(I've pasted only the part it's compared against for brevity):

module example {
    rpc action {
       input {
           leaf param2 {
               type string
           }
           leaf param1 {
               type string
           }
    }
}

yang2dsdl -t rpc example.yang The schemas are generated successfully.

yang2dsdl -s -j -b example -t rpc -v example.xml

error: element "param1" not allowed yet; missing required element "param2"

Though param1 and param2 are in the input xml file, as they are not in the same order as in YANG model, it throws errors.

Can someone tell me how to solve this problem?

predi
  • 5,528
  • 32
  • 60
linuxfreak
  • 2,068
  • 3
  • 20
  • 29

1 Answers1

2

It seems that the YANG RFC treats order of child elements differently for rpcs and other data. In rpcs the order has to be exactly how it was defined in the model. In case of other data the order of child elements is not important.

So in your case the rpc input was not prepared according to YANG standard and it should be fixed. The yang2dsdl tool works just fine and you should not expect to have there any "ignore order for rpcs" option.

rpc XML Mapping Rules

Input parameters are encoded as child XML elements to the rpc node's XML element, in the same order as they are defined within the "input" statement.

If the RPC operation invocation succeeded, and no output parameters are returned, the <rpc-reply> contains a single <ok/> element defined in [RFC4741]. If output parameters are returned, they are encoded as child elements to the <rpc-reply> element defined in [RFC4741], in the same order as they are defined within the "output" statement.

container XML Mapping Rules

The container's child nodes are encoded as subelements to the container element. If the container defines RPC input or output parameters, these subelements are encoded in the same order as they are defined within the "container" statement. Otherwise, the subelements are encoded in any order.

Community
  • 1
  • 1
Piotr Babij
  • 837
  • 5
  • 12
  • Note that this is apparently different than what is specified in [JSON encoding for YANG data (draft)](https://tools.ietf.org/html/draft-ietf-netmod-yang-json-06) which claims to be compliant with [I-JSON](https://tools.ietf.org/html/rfc7493#section-2.3). And I-JSON specifically says: "The order of object members in an I-JSON message does not change the meaning of an I-JSON message." – Piotr Babij Dec 31 '15 at 12:49