In YANG, how can we achieve something similar to a pointer like concept of C?

Hi Folks,

I am having a structure like below-

container root
{
  container outerBody
  {
        leaf frequency
        {
           units seconds;
           type uint32 {
              range "1..604800";
           }
         }
     ...
     ...
     ..._some more leaves_
     ...
     ...
     ...   
  }

  leaf frequency
  {
   ...
  }
}

I want to place the frequency at 2 different hierarchical levels.
One under /root/outerbody/frequency and another under - /root/frequency. And any changes made to either of these item should get reflected in the other one. Thats why i said like a C pointer kind of behavior.
What yang syntax i can use inside /root/frequency to bring in this behavior? Does instance-identifier helps in anyway here?

You can use the tailf:link extension where one of the leafs point to the other leaf. E.g. from the leaf in the outerBody container you can point to the one in the root container using something like
tailf:link "/root/frequency"
See tailf:link in the tailf_yang_extensions man page for details.

Thanks a lot @cohult for the pointer. After little bit research on the usage and i am able to use it for my purpose.

Hi @cohult,

With this tailf annotation, I am facing one issue.

I have a construct as below-

                                    container my_container {
                                        tailf:cli-sequence-commands;
                                        tailf:cli-compact-syntax;
                                        choice way {
                                          case one-way-case {
                                            leaf one-way {
                                              tailf:cli-incomplete-command;
                                              tailf:link "some-path/one-way";
                                              type uint8 {
                                                range "1..10";
                                              }
                                            }//end of onw-way
                                          }//end of one-way-case
                                          case two-way-case {
                                            leaf two-way {
                                              tailf:cli-incomplete-command;
                                              tailf:link "some-path/two-way";
                                              type uint8 {
                                                range "1..10";
                                              }
                                            }//end of two-way
                                          }//end of two-way-case
                                        }//end of choice-way
                                        leaf dummy_leaf {
                                          tailf:cli-drop-node-name;
                                          type string;
                                        }
                                      }
                                    }

So if i make change to one of the leaf (one-way or two-way) under the choice statement, in the target data node, then that don’t get reflected in the linked node.
However, i could see the reflection of the change made to the leaf outside the choice statement - dummy_leaf.

So how is the tailf:link statement related to the choice statement?

Did you commit the configuration before checking if the change got reflected in the linked node?

Yes @cohult. I have done the commit.

[By commit, you mean to say, commit command on the confd CLI prompt, after configuring the command?]

Yes. If that does not work for you, please provide details, e.g. step by step commands.

My linked model looks like -

                           container linked_items {
                               container my_container {
                                    tailf:cli-sequence-commands;
                                    tailf:cli-compact-syntax;
                                    choice way {
                                      case one-way-case {
                                        leaf one-way {
                                          tailf:cli-incomplete-command;
                                          tailf:link "some-path/one-way";
                                          type uint8 {
                                            range "1..10";
                                          }
                                        }//end of onw-way
                                      }//end of one-way-case
                                      case two-way-case {
                                        leaf two-way {
                                          tailf:cli-incomplete-command;
                                          tailf:link "some-path/two-way";
                                          type uint8 {
                                            range "1..10";
                                          }
                                        }//end of two-way
                                      }//end of two-way-case
                                    }//end of choice-way
                                    leaf dummy_leaf {
                                      tailf:cli-drop-node-name;
                                      type string;
                                    }
                                  }
                                }
                              }

My target node structure looks like -

                            container target-node-container {
                                container my_container {
                                    tailf:cli-sequence-commands;
                                    tailf:cli-compact-syntax;
                                    choice way {
                                      case one-way-case {
                                        leaf one-way {
                                          tailf:cli-incomplete-command;
                                          type uint8 {
                                            range "1..10";
                                          }
                                        }//end of onw-way
                                      }//end of one-way-case
                                      case two-way-case {
                                        leaf two-way {
                                          tailf:cli-incomplete-command;
                                          type uint8 {
                                            range "1..10";
                                          }
                                        }//end of two-way
                                      }//end of two-way-case
                                    }//end of choice-way
                                    leaf dummy_leaf {
                                      tailf:cli-drop-node-name;
                                      type string;
                                    }
                                  }
                                }
                             }

So on the CLI prompt if i type -
(config)# target-node-container my_container one-way 1 dummy_leaf abc

So basically, I am trying to set value on the target node, so the output looks like -

target-node-container my_container one-way 1 dummy_leaf abc
!

Here it is not setting the linked node! It has set only the target node.

However, on the CLI prompt, if i type the cmd -
(config)# linked_items my_container one-way 1 dummy_leaf abc

Here, I am setting the linked node. Output looks like-

linked_items my_container one-way 1 dummy_leaf abc
!
target-node-container my_container one-way 1 dummy_leaf abc
!

In this case, it is indirectly setting the target node as well along with the linked node.

And this behavior (not setting the linked node) is observed only when choice statement is used. So please help with this.
Instead if we hadn’t used choice statement, then setting either the linked node or the target node, would have set both the nodes.

I believe you forgot to include an integer between 1…10 for the one-way leaf in your example commands.

Ok, so the output you are looking at is from the cdb_get_modifications_cli() API call, and you have a leaf within one choice tailf:link:ed to a leaf within another choice statement.

So when you set the tailf:link leaf the target leaf will get set as well as you have a tailf:link instructing ConfD to do that for you.
However, when you set the leaf that is targeted by the tailf:link leaf inside the other choice, the leaf with the tailf:link is not set.

This makes sense, as the choice statement above the leaf with the tailf:link has not been made yet. Hence there is no leaf actively pointing to the target leaf yet.

Then if you set the leaf with the tailf:link the target leaf will also be updated if the values differ.

However, if you then set the target leaf again, you would expect that the tailf:link leaf that is now active would be updated, and it is in the configuration, but this is not reflected by the cdb_get_modifications_cli() output. And so this is something I believe you want to create a ticket for with Tail-f support.

yes, you are right. I had missed it. I corrected it now in the post.

Correct, you are right. Even if we directly update the target node, first (even before accessing the linked node), still we want the linked node to be reflected with the value being set through target node.

Is this request taken up?
Or, is there any action item for me?

@cohult: How do I create a ticket for this with Tail-f?
Could you please help in knowing the procedure for this?

In your case there is a ticket system for ConfD that the platform team for the product you are working on have access to. I suggest you go through them.