cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
752
Views
1
Helpful
1
Replies

Understand leafref in YDK-Gen and YANG

binh.q.nguyen
Level 1
Level 1

Hi,

I am trying to understand the leafref statement in YANG and how it is realized in YDK-gen.

I am using Cisco IOS XR 632 openconfig-interfaces.yang and try to create an interface configuration like this:

    def config_openconfig_interfaces_ipv4(self,

                                          enabled="false",

                                          interface_name="GigabitEthernet0/0/0/0",

                                          ipv4_address="10.0.0.1",

                                          ipv4_prefix_length=24):

        oc_interfaces = importlib.import_module("ydk.models.openconfig.openconfig_interfaces")

        interfaces = oc_interfaces.Interfaces()

        interface = interfaces.Interface()

        interface.config.enabled = enabled

        interface.config.name = interface_name        #<== interface.name should have the same value as interface.config.name

        interface.ethernet.config.auto_negotiate="false"

        (...more)

        return self.codec.encode(self.provider, interfaces)

In the openconfig-interfaces.yang, the openconfig-interfaces:interfaces/interface/name is a "leafref" referring to openconfig-interfaces:interfaces/interface/config/name (bolded line). If I understand correctly, because "leafref" was used in the YANG model, the openconfig-interfaces:interfaces/interface/name will take whatever value the openconfig-interfaces:interfaces/interface/config/name has. However, the above code doesn't pass the value of openconfig-interfaces:interfaces/interface/config/name to openconfig-interfaces:interfaces/interface/name. So the returned config data looks like:

{

  "openconfig-interfaces:interfaces": {

    "interface": [

      {

        "name": "None",

        "config": {

          "name": "GigabitEthernet0/0/0/0",

          "enabled": false

        },

        "openconfig-if-ethernet:ethernet": {

          "config": {

            "auto-negotiate": false

          }

        }

      }

    ]

  }

}

As we see here, the openconfig-interfaces:interfaces/interface/name got a "None" value instead of "GigabitEthernet0/0/0/0".

Is this an expected behavior in YDK-gen? or am I missing something to make the leafref statement works (as I expected, maybe this YANG leafref is enforced on the device but not in YDK-gen?)?

Thanks,

Binh

1 Reply 1

abhirame
Cisco Employee
Cisco Employee

YDK is not designed to automatically populate the leafref references. User is expected to fill in the valid values for the leafrefs