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

**URL:** https://dmap-community.ductus.global/t/in-yang-how-can-we-achieve-something-similar-to-a-pointer-like-concept-of-c/2165
**Category:** YANG
**Created:** [November 22, 2018, 12:18pm UTC](https://dmap-community.ductus.global/t/in-yang-how-can-we-achieve-something-similar-to-a-pointer-like-concept-of-c/2165 "2018-11-22T12:18:06Z")
**Posts on this page:** 13
**Page:** 1

<div class="post-metadata">

### Author: ![dalakshm](https://avatars.discourse-cdn.com/v4/letter/d/d2c977/32.png) [@dalakshm](https://dmap-community.ductus.global/u/dalakshm)
#### Post date: [November 22, 2018, 12:18pm UTC](https://dmap-community.ductus.global/t/in-yang-how-can-we-achieve-something-similar-to-a-pointer-like-concept-of-c/2165/1 "2018-11-22T12:18:06Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![cohult](https://yyz2.discourse-cdn.com/flex010/user_avatar/dmap-community.ductus.global/cohult/32/221_2.png) [@cohult](https://dmap-community.ductus.global/u/cohult)
#### Post date: [November 22, 2018, 1:28pm UTC](https://dmap-community.ductus.global/t/in-yang-how-can-we-achieve-something-similar-to-a-pointer-like-concept-of-c/2165/2 "2018-11-22T13:28:59Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![dalakshm](https://avatars.discourse-cdn.com/v4/letter/d/d2c977/32.png) [@dalakshm](https://dmap-community.ductus.global/u/dalakshm)
#### Post date: [November 23, 2018, 2:25pm UTC](https://dmap-community.ductus.global/t/in-yang-how-can-we-achieve-something-similar-to-a-pointer-like-concept-of-c/2165/3 "2018-11-23T14:25:18Z")

</div>

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

---

<div class="post-metadata">

### Author: ![dalakshm](https://avatars.discourse-cdn.com/v4/letter/d/d2c977/32.png) [@dalakshm](https://dmap-community.ductus.global/u/dalakshm)
#### Post date: [January 20, 2019, 2:24pm UTC](https://dmap-community.ductus.global/t/in-yang-how-can-we-achieve-something-similar-to-a-pointer-like-concept-of-c/2165/4 "2019-01-20T14:24:25Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![cohult](https://yyz2.discourse-cdn.com/flex010/user_avatar/dmap-community.ductus.global/cohult/32/221_2.png) [@cohult](https://dmap-community.ductus.global/u/cohult)
#### Post date: [January 22, 2019, 8:11am UTC](https://dmap-community.ductus.global/t/in-yang-how-can-we-achieve-something-similar-to-a-pointer-like-concept-of-c/2165/5 "2019-01-22T08:11:16Z")

</div>

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

---

<div class="post-metadata">

### Author: ![dalakshm](https://avatars.discourse-cdn.com/v4/letter/d/d2c977/32.png) [@dalakshm](https://dmap-community.ductus.global/u/dalakshm)
#### Post date: [January 22, 2019, 8:23am UTC](https://dmap-community.ductus.global/t/in-yang-how-can-we-achieve-something-similar-to-a-pointer-like-concept-of-c/2165/6 "2019-01-22T08:23:10Z")

</div>

Yes @cohult. I have done the commit.

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

---

<div class="post-metadata">

### Author: ![cohult](https://yyz2.discourse-cdn.com/flex010/user_avatar/dmap-community.ductus.global/cohult/32/221_2.png) [@cohult](https://dmap-community.ductus.global/u/cohult)
#### Post date: [January 22, 2019, 8:26am UTC](https://dmap-community.ductus.global/t/in-yang-how-can-we-achieve-something-similar-to-a-pointer-like-concept-of-c/2165/7 "2019-01-22T08:26:24Z")

</div>

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

---

<div class="post-metadata">

### Author: ![dalakshm](https://avatars.discourse-cdn.com/v4/letter/d/d2c977/32.png) [@dalakshm](https://dmap-community.ductus.global/u/dalakshm)
#### Post date: [January 22, 2019, 6:08pm UTC](https://dmap-community.ductus.global/t/in-yang-how-can-we-achieve-something-similar-to-a-pointer-like-concept-of-c/2165/8 "2019-01-22T18:08:59Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![cohult](https://yyz2.discourse-cdn.com/flex010/user_avatar/dmap-community.ductus.global/cohult/32/221_2.png) [@cohult](https://dmap-community.ductus.global/u/cohult)
#### Post date: [January 23, 2019, 9:04am UTC](https://dmap-community.ductus.global/t/in-yang-how-can-we-achieve-something-similar-to-a-pointer-like-concept-of-c/2165/9 "2019-01-23T09:04:11Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![dalakshm](https://avatars.discourse-cdn.com/v4/letter/d/d2c977/32.png) [@dalakshm](https://dmap-community.ductus.global/u/dalakshm)
#### Post date: [January 23, 2019, 9:41am UTC](https://dmap-community.ductus.global/t/in-yang-how-can-we-achieve-something-similar-to-a-pointer-like-concept-of-c/2165/10 "2019-01-23T09:41:11Z")

</div>

> [@cohult](#):
>
> I believe you forgot to include an integer between 1…10 for the one-way leaf in your example commands.

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

> [@cohult](#):
>
> 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.

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.

---

<div class="post-metadata">

### Author: ![dalakshm](https://avatars.discourse-cdn.com/v4/letter/d/d2c977/32.png) [@dalakshm](https://dmap-community.ductus.global/u/dalakshm)
#### Post date: [February 7, 2019, 5:29pm UTC](https://dmap-community.ductus.global/t/in-yang-how-can-we-achieve-something-similar-to-a-pointer-like-concept-of-c/2165/11 "2019-02-07T17:29:28Z")

</div>

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

---

<div class="post-metadata">

### Author: ![dalakshm](https://avatars.discourse-cdn.com/v4/letter/d/d2c977/32.png) [@dalakshm](https://dmap-community.ductus.global/u/dalakshm)
#### Post date: [February 12, 2019, 1:25am UTC](https://dmap-community.ductus.global/t/in-yang-how-can-we-achieve-something-similar-to-a-pointer-like-concept-of-c/2165/12 "2019-02-12T01:25:51Z")

</div>

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

---

<div class="post-metadata">

### Author: ![cohult](https://yyz2.discourse-cdn.com/flex010/user_avatar/dmap-community.ductus.global/cohult/32/221_2.png) [@cohult](https://dmap-community.ductus.global/u/cohult)
#### Post date: [February 12, 2019, 1:50am UTC](https://dmap-community.ductus.global/t/in-yang-how-can-we-achieve-something-similar-to-a-pointer-like-concept-of-c/2165/13 "2019-02-12T01:50:42Z")

</div>

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.
