mbj4668 / pyang

An extensible YANG validator and converter in python
ISC License
530 stars 343 forks source link

Grouping converted to Interleave #795

Closed siarheul closed 2 years ago

siarheul commented 2 years ago

I try to convert my Yang model to Relax NG model. The issue is my 'grouping' statement is converted to 'interleave' when I run command yang2dsdl -t data file.yang Instead of 'interleave' I want to have 'group' element. Is it possible?

My yang look like this

grouping links-top {
        container links {
            config false;
            list active {
                uses active-link-state;
                key remote-assigned-name;
            }
        }
    }
grouping active-link-state {

        leaf remote-assigned-name {
            type rb-tg-types:node-assigned-name;

        }
        leaf actual-remote-sector-index {
            type rb-tg-types:radio-sector-index;

        }
        leaf actual-local-sector-index {
            type rb-tg-types:radio-sector-index;

        }
        leaf remote-mac-addr {
            type yang:mac-address;

        }
        leaf local-role {
            type link-role;

        }
        leaf link-uptime {
            type uint64;
            units "seconds";

        }
        uses active-link-health-state;
    }

It results in the following Relax NG code

<element name="links">
            <zeroOrMore>
               <element name="active">
                  <element name="remote-assigned-name">
                     <ref name="radio-bridge-tg-types__node-assigned-name" />
                  </element>
                  <interleave>
                     <optional>
                        <element name="actual-remote-sector-index">
                           <ref name="radio-bridge-tg-types__radio-sector-index" />
                        </element>
                     </optional>
                     <optional>
                        <element name="actual-local-sector-index">
                           <ref name="radio-bridge-tg-types__radio-sector-index" />
                        </element>
                     </optional>
                     <optional>
                        <element name="remote-mac-addr">
                           <ref name="ietf-yang-types__mac-address" />
                        </element>
                     </optional>
                     <optional>
                        <element name="local-role">
                           <ref name="radio-bridge-tg-radio-common__link-role" />
                        </element>
                     </optional>
                     <optional>
                        <element name="link-uptime">
                           <data type="unsignedLong" />
                        </element>
                     </optional>
                     <ref name="radio-bridge-tg-radio-common___active-link-health-state" />
                  </interleave>
               </element>
            </zeroOrMore>
         </element>

I can change 'interleave' to 'group' manually - it is still valid Relax NG file, but I want to know if the problem with my YANG or with pyang tool

Thank you!

llhotka commented 2 years ago

According to YANG rules (Section 7.5.7 in RFC 7950), the instances of the leaves contained in your grouping may appear in any order – except the key remote-assigned-name, which is therefore put first. So <interleave> is really appropriate here, with <group> validation could fail on instance documents that are valid according to YANG rules.

siarheul commented 2 years ago

@llhotka Thank you for your response! What if I want to have leaf ordered? Does YANG support that?

llhotka commented 2 years ago

Only in specific cases, see the cited sec. 7.5.7.