ConfD User Community

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


#1

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?


#2

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.


#3

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


#4

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?


#5

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


#6

Yes @cohult. I have done the commit.

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


#7

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


#8

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 dummy_leaf

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

target-node-container my_container one-way dummy_leaf
!

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 dummy_leaf

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

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

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.