This article describes how to get ancestor and local keys in the EDIT callbacks. However, this is only when you made your SIL-SA code with out --split parameter. If the SIL-SA code is made with --split parameter the auto generated code will be provided with these keys already, so you won't have to deal with them manually.


For example, assume we have the following simplified but functional YANG module and we are making a SIL-SA code for this module as follow:


> make_sil_sa_dir test-hardware --sil-get2


module test-hardware {
  yang-version 1.1;
  namespace "urn:ietf:params:xml:ns:yang:test-hardware";
  prefix test-hw;

  revision 2020-08-19 {
    description
      "Initial revision.";
  }

  container hardware {

    list component {
      key name;

      leaf name {
        type string;
      }

      leaf description {
        type string;
        config false;
      }

      leaf parent {
        type leafref {
          path "../../component/name";
          require-instance false;
        }
      }

      leaf alias {
        type string;
      }
    }
  }
}


In this case without --split parameter during make_sil_sa_dir  there will not be any handling for "name" key inside EDIT callbacks for "component" list and all of its children callbacks.


EXAMPLE


Assume there are multiple "component" list entries exist with key values "name1" and "name2".

In order to retrieve key value for the component list, for example, when you edit "alias" children of the list the following handling can be used:


    /* key test-hardware:name */
    const xmlChar *key_name = NULL;

    /* Get the key value node for the specified key
     * where 1 is a key index to get -- 1 to N
     */
    val_value_t *keyval = sil_sa_get_key(msg, 1);
    if (keyval) {
        key_name = VAL_STR(keyval);
        if (key_name) {
            log_info("\n\n key value is:%s",
                     key_name);
        }
    }


Note, that for config FALSE nodes, such as "description" node there will be different handling, as follows:


    val_value_t *keyval = NULL;

    /* key test-hardware:name */
    const xmlChar *k_hardware_component_name = NULL;
    keyval =
        getcb_find_key_lvl(get2cb,
                           y_test_hardware_M_test_hardware,
                           y_test_hardware_N_name,
                           (uint32)3);
    if (keyval) {
        k_hardware_component_name = VAL_STR(keyval);

        if (k_hardware_component_name) {
            log_info("\n\n key value is:%s",
                     k_hardware_component_name);
        }
    }


Refer to val.h header file or Developer Manual for more VAL_ macros that allows to retrieve the value of the val value node.

In the above example since the node type is a string, the VAL_STR macro was used.

If the type of the string would be uint32, then the VAL_UINT32 would be used. As a result, if you build this code manually pay attention on what type your desired key node is.


For complete example SIL-SA code, refer to the attachments.