CESNET / libyang

YANG data modeling language library
BSD 3-Clause "New" or "Revised" License
364 stars 291 forks source link

lyd_parse_data_mem behavior #2099

Open rabhat31 opened 1 year ago

rabhat31 commented 1 year ago

Hi, I'm running into a weird issue with parsing XMLs under certain conditions.

  1. Create a context and load the models "Cisco-IOS-XE-native" and "Cisco-IOS-XE-mdt-cfg".
  2. Parse an XML into the context using lyd_parse_data_mem with only the LYD_PARSE_STRICT flag.
  3. When parsing an XML tree under the <native> tree , lyd_parse_data_mem returns a NULL lyd_node.
  4. When parsing an XML tree under the <mdt-cfg-data> tree , lyd_parse_data_mem returns a properly populated lyd_node.
  5. When I use the flags LYD_PARSE_STRICT and LYD_PARSE_ONLY, then both and XMLs get parsed. Also when I explicitly validate these nodes, nothing gets deleted.
  6. When I parse an XML which is a combination of both mdt-cfg-data and native tags, only the mdt config gets parsed whereas native does not.

Example XMLs: MDT XML:

<mdt-config-data xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-mdt-cfg">
    <mdt-subscription>
      <subscription-id>12345</subscription-id>
      <base>
        <stream>ABC</stream>
        <encoding>XYZ</encoding>
      </base>
    </mdt-subscription>
    <mdt-named-protocol-rcvrs>
      <mdt-named-protocol-rcvr>
        <name>DEF</name>
        <protocol>native</protocol>
      </mdt-named-protocol-rcvr>
    </mdt-named-protocol-rcvrs>
    <proto-grpc-profile>
      <name>GHI</name>
    </proto-grpc-profile>
    <mdt-xfrm>
      <name>JKL</name>
    </mdt-xfrm>
  </mdt-config-data>

NATIVE XML:

<native xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-native" xmlns:yang="urn:ietf:params:xml:ns:yang:1" yang:operation="none">
    <ip>
      <routing-conf>
        <routing yang:operation="replace" yang:orig-default="false" yang:orig-value="true">false</routing>
      </routing-conf>
    </ip>
    <interface>
      <Vlan>
        <name>23</name>
        <mac-address yang:operation="replace" yang:orig-default="false" yang:orig-value="2C:3F:0B:00:45:11">2C:3F:0B:00:45:C0</mac-address>
      </Vlan>
      <Vlan yang:operation="delete">
        <name>24</name>
        <mac-address>2C:3F:0B:00:45:22</mac-address>
      </Vlan>
      <Vlan yang:operation="none">
        <name>25</name>
        <mac-address yang:operation="create">2C:3F:0B:00:45:25</mac-address>
      </Vlan>
    </interface>
  </native>
michalvasko commented 1 year ago

You should check return values and look at any errors. The behavior you described may be correct so mention what is the behavior you expect and include any error messages.

rabhat31 commented 1 year ago

There are no error messages. Could you explain why the behavior may be correct? Why does the native tree in 3 show up as empty even though we've loaded the correct schema. And why does 5 work when I add the LYD_PARSE_ONLY flag and then validate explicitly?

michalvasko commented 1 year ago

Please attach the exact YANG modules with all their imports that you are using. I have tried it with some arbitrary revision and there were unknown nodes in both data trees.

rabhat31 commented 1 year ago

We're using the models from https://github.com/YangModels/yang/tree/main/vendor/cisco/xe/17121

michalvasko commented 1 year ago

Fine, please modify my test to reproduce the exact problem you have. It all behaved as expected for me except using only LYD_PARSE_STRICT does not work, you must use at least LYD_VALIDATE_PRESENT so that the data succeed validation and are parsed.