# I want to know how to input instance-identifier

**URL:** <https://dmap-community.ductus.global/t/i-want-to-know-how-to-input-instance-identifier/1666>\
**Category:** CDB and CDB API\
**Created:** [November 29, 2017, 5:26am UTC](https://dmap-community.ductus.global/t/i-want-to-know-how-to-input-instance-identifier/1666 "2017-11-29T05:26:49Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![jeongmin.na](https://avatars.discourse-cdn.com/v4/letter/j/ce7236/32.png) [@jeongmin.na](https://dmap-community.ductus.global/u/jeongmin.na)\
**Post date:** [November 29, 2017, 5:26am UTC](https://dmap-community.ductus.global/t/i-want-to-know-how-to-input-instance-identifier/1666/1 "2017-11-29T05:26:50Z")

</div>

1. There is a yang model as below.

```auto
container managed-element {
 container enb-function {
   list active-queue-management{
       key aqm-index;   
       leaf aqm-index{
            type uint16{
                range "0..7";
            }
       }
       leaf qci{
            type uint16 {
                range "0..7";
            }
       }
   }
 }
}

```

1. Based on the above yang, I want to send a notification as below.

```xml
"<"notification xmlns="urn:ietf:params:xml:ns:netconf:notification:1.0">
  "<"eventTime>2017-11-28T12:26:14-00:00"<"/eventTime>
  "<"data-changed-notification xmlns="http://www.samsung.com">
   " <"data-change-event>
     " <"noti-path>"managed-element/enb-function/active-queue-management[aqm-index=0]""<"/noti-path>
     " <"noti-store>config"<"/noti-store>
      "<"noti-operation>updated"<"/noti-operation>
      "<"noti-data>
        "<"qci>5"<"/qci>
      "<"/noti-data>
    "<"/data-change-event>
  "<"/data-changed-notification>
"<"/notification>

```

1. I was coding as below to send it as above.

```auto
    confd_tag_value_t val[MAX_NOTI_INSERT_COUNT +1];
    confd_hkeypath_t key, *pKey = &key;
    pkey_path->len = 4;
    pKey->v[3][0].type = C_XMLTAG; 
    pKey->v[3][0].val.xmltag.tag = venb_c_managed_element;
    pKey->v[3][0].val.xmltag.ns = venb_c__ns;

    pKey->v[2][0].type = C_XMLTAG;
    pKey->v[2][0].val.xmltag.tag = venb_c_enb_function;
    pKey->v[2][0].val.xmltag.ns = venb_c__ns;

    pKey->v[1][0].type = C_XMLTAG;
    pKey->v[1][0].val.xmltag.tag = venb_c_active_queue_management;
    pKey->v[1][0].val.xmltag.ns = venb_c__ns;

    pKey->v[0][0].type = C_UINT16;
    pKey->v[0][0].val.u16 = 0;

    CONFD_SET_TAG_XMLBEGIN(&val[insert_cnt], venb_c_data_changed_notification, venb_c__ns); insert_cnt++;
    CONFD_SET_TAG_XMLBEGIN(&val[insert_cnt], venb_c_data_change_event, venb_c__ns); insert_cnt++;

    CONFD_SET_TAG_OBJECTREF(& val[insert_cnt], venb_c_noti_path, pKey); insert_cnt++;
    CONFD_SET_TAG_ENUM_VALUE(&val[insert_cnt], venb_c_noti_store, 0); insert_cnt++;
    CONFD_SET_TAG_ENUM_VALUE(&val[insert_cnt], venb_c_noti_operation, 1); insert_cnt++;
    CONFD_SET_TAG_STR(& val[insert_cnt], venb_c_noti_data, (const char *) noti_data.c_str()); insert_cnt++;

    CONFD_SET_TAG_XMLEND(&val[insert_cnt], venb_c_data_change_event, venb_c__ns); insert_cnt++;
    CONFD_SET_TAG_XMLEND(&val[insert_cnt], venb_c_data_changed_notification, venb_c__ns); insert_cnt++;

    confd_notification_send( p_nctx, p_time, val, insert_cnt);

```

1. If I code as avove, an error occurs in the following areas

```auto
 -> CONFD_SET_TAG_OBJECTREF(& val[insert_cnt], venb_c_noti_path, pKey); insert_cnt++;

```

1. When configuring the key path, if i enter only path without list, it works normally.  
However, if i add the list key, an error occurs.  
I want to know how to make it as follows.

```auto
<noti-path>"managed-element/enb-function/active-queue-management[aqm-index=0]"</noti-path>

```

---

<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 29, 2017, 9:32am UTC](https://dmap-community.ductus.global/t/i-want-to-know-how-to-input-instance-identifier/1666/2 "2017-11-29T09:32:27Z")

</div>

Hi,  
I assume you are using maapi\_xpath2kpath() or similar to convert your path to a confd\_hkeypath\_t?  
If so, you are missing a “/” in front of “managed-element” in your path.

The correct path to maapi\_xpath2kpath() should in your case be:  
`/managed-element/enb-function/active-queue-management[aqm-index=0]`

---

<div class="post-metadata">

**Author:** ![mnovak](https://yyz2.discourse-cdn.com/flex010/user_avatar/dmap-community.ductus.global/mnovak/32/183_2.png) [@mnovak](https://dmap-community.ductus.global/u/mnovak)\
**Post date:** [November 29, 2017, 10:07am UTC](https://dmap-community.ductus.global/t/i-want-to-know-how-to-input-instance-identifier/1666/3 "2017-11-29T10:07:14Z")

</div>

Can you also paste the `yang` representation of your notification and what is **the error** that you get.

---

<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 29, 2017, 10:07am UTC](https://dmap-community.ductus.global/t/i-want-to-know-how-to-input-instance-identifier/1666/4 "2017-11-29T10:07:41Z")

</div>

Quick example added to the examples.confd/netconf\_notifications example using the built in NETCONF stream instead of your proprietary one:

```auto
$ diff -u notifier_builtin_replay_store.bak notifier_builtin_replay_store.c 
--- notifier_builtin_replay_store.bak	2017-11-29 11:01:50.000000000 +0100
+++ notifier_builtin_replay_store.c	2017-11-29 11:02:30.000000000 +0100
@@ -14,14 +14,16 @@
 
 #include <confd_lib.h>
 #include <confd_dp.h>
+#include <confd_maapi.h>
 
 #include "notif.h"
+#include "ietf-netconf-notifications.h"
 
 #define OK(val) (assert((val) == CONFD_OK))
 
 static int ctlsock, workersock;
 static struct confd_daemon_ctx *dctx;
-static struct confd_notification_ctx *live_ctx;
+static struct confd_notification_ctx *live_ctx, *netconf_ctx;
 
 static int get_ctlsock(struct addrinfo *addr)
 {
@@ -73,6 +75,14 @@
     datetime->min = tm.tm_min;
 }
 
+static void send_netconf_notification(confd_tag_value_t *vals, int nvals)
+{
+ struct confd_datetime eventTime;
+
+ getdatetime(&eventTime);
+ OK(confd_notification_send(netconf_ctx, &eventTime, vals, nvals));
+}
+
 static void send_notification(confd_tag_value_t *vals, int nvals)
 {
     struct confd_datetime eventTime;
@@ -81,6 +91,41 @@
     OK(confd_notification_send(live_ctx, &eventTime, vals, nvals));
 }
 
+static void send_x(void)
+{
+ confd_tag_value_t vals[11];
+ int i = 0;
+
+ confd_hkeypath_t *kp;
+ struct sockaddr_in saddr;
+ struct in_addr an_addr = {0xa0a0a0a0};
+
+ int msock;
+
+ saddr.sin_addr.s_addr = inet_addr("127.0.0.1");
+ saddr.sin_family = AF_INET;
+ saddr.sin_port = htons(CONFD_PORT);
+
+ msock = socket(PF_INET, SOCK_STREAM, 0);
+ maapi_connect(msock, (struct sockaddr *)&saddr, sizeof(saddr));
+ maapi_xpath2kpath(msock, "/managed-element/enb-function/active-queue-management[aqm-index=0]", &kp);
+ maapi_close(msock);
+
+ CONFD_SET_TAG_XMLBEGIN(&vals[i], ncn_netconf_config_change, ncn__ns); i++;
+ CONFD_SET_TAG_XMLBEGIN(&vals[i], ncn_changed_by, ncn__ns); i++;
+ CONFD_SET_TAG_STR(&vals[i], ncn_username, "admin"); i++;
+ CONFD_SET_TAG_UINT32(&vals[i], ncn_session_id, 0); i++;
+ CONFD_SET_TAG_IPV4(&vals[i], ncn_source_host, an_addr); i++;
+ CONFD_SET_TAG_XMLEND(&vals[i], ncn_changed_by, ncn__ns); i++;
+ CONFD_SET_TAG_ENUM_VALUE(&vals[i], ncn_datastore, ncn_running); i++;
+ CONFD_SET_TAG_XMLBEGIN(&vals[i], ncn_edit, ncn__ns); i++;
+ CONFD_SET_TAG_OBJECTREF(&vals[i], ncn_target, kp); i++;
+ CONFD_SET_TAG_XMLEND(&vals[i], ncn_edit, ncn__ns); i++;
+ CONFD_SET_TAG_XMLEND(&vals[i], ncn_netconf_config_change, ncn__ns); i++;
+
+ send_netconf_notification(vals, i);
+ confd_free_hkeypath(kp);
+}
+
 static void send_notifup_1(int index, int flags1, int flags2)
 {
     confd_tag_value_t vals[9];
@@ -238,6 +283,16 @@
     if (confd_register_notification_stream(dctx, &ncb, &live_ctx) != CONFD_OK) {
         confd_fatal("Couldn't register stream %s\n", ncb.streamname);
     }
+
+ memset(&ncb, 0, sizeof(ncb));
+ ncb.fd = workersock;
+ ncb.get_log_times = NULL;
+ ncb.replay = NULL;
+ strcpy(ncb.streamname, "NETCONF");
+ ncb.cb_opaque = NULL;
+ if (confd_register_notification_stream(dctx, &ncb, &netconf_ctx) != CONFD_OK) {
+ confd_fatal("Couldn't register stream %s\n", ncb.streamname);
+ }
     if (confd_register_done(dctx) != CONFD_OK) {
         confd_fatal("Failed to complete registration \n");
     }
@@ -291,6 +346,9 @@
                     printf("sending linkDown notification\n");
                     send_notifdown(1);
                     break;
+ case 'x':
+ send_x();
+ break;
                 case 'm':
                     printf("sending 10000 random notifications\n");
                     int i;
$ diff -u Makefile.bak Makefile
--- Makefile.bak	2017-11-29 11:03:12.000000000 +0100
+++ Makefile	2017-11-29 11:10:10.000000000 +0100
@@ -43,15 +43,17 @@
 all: notifier notifier_builtin_replay_store notif.fxs $(CDB_DIR) ssh-keydir
 	@echo "Build complete"
 
+ietf-netconf-notifications.h:
+	$(CONFDC) --emit-h ietf-netconf-notifications.h $(CONFD_DIR)/etc/confd/ietf-netconf-notifications.fxs
 notifier: notifier.o
 	 $(CC) notifier.o $(LIBS) $(CFLAGS) -ansi -pedantic -o $@
 
-notifier.o: notifier.c notif.h
+notifier.o: notifier.c notif.h ietf-netconf-notifications.h
 
 notifier_builtin_replay_store: notifier_builtin_replay_store.o
 	 $(CC) notifier_builtin_replay_store.o $(LIBS) $(CFLAGS) -o $@
 
-notifier_builtin_replay_store.o: notifier_builtin_replay_store.c notif.h
+notifier_builtin_replay_store.o: notifier_builtin_replay_store.c notif.h ietf-netconf-notifications.h
 
$ diff -u notif.yang.bak notif.yang 
--- notif.yang.bak	2017-11-29 11:08:24.000000000 +0100
+++ notif.yang	2017-11-29 09:48:11.000000000 +0100
@@ -14,6 +14,24 @@
     }
   }
 
+container managed-element {
+ container enb-function {
+ list active-queue-management{
+ key aqm-index;   
+ leaf aqm-index{
+ type uint16{
+ range "0..7";
+ }
+ }
+ leaf qci{
+ type uint16 {
+ range "0..7";
+ }
+ }
+ }
+ }
+}
+
   notification linkUp {
     leaf ifIndex {
       type leafref {

```

---

<div class="post-metadata">

**Author:** ![jeongmin.na](https://avatars.discourse-cdn.com/v4/letter/j/ce7236/32.png) [@jeongmin.na](https://dmap-community.ductus.global/u/jeongmin.na)\
**Post date:** [November 29, 2017, 11:11am UTC](https://dmap-community.ductus.global/t/i-want-to-know-how-to-input-instance-identifier/1666/5 "2017-11-29T11:11:50Z")

</div>

It’s as flows.

```
notification data-changed-notification {
    description "Data change notification.";
    list data-change-event {
        key noti-path;
        leaf noti-path {
            type instance-identifier;
        }
        leaf noti-store {
            type enumeration {
                enum config {
                    tailf:code-name data-changed-config;
                }
                enum operation {
                    tailf:code-name data-changed-operation;
                }
            }
        }
        leaf noti-operation {
            type enumeration {
                enum created {
                    tailf:code-name data-changed-created;
                }
                enum updated {
                    tailf:code-name data-changed-updated;
                }
                enum deleted {
                    tailf:code-name data-changed-deleted;
                }
            }
        }
        anyxml noti-data{
            description "DataObject ";
        }
     }
}
```

---

<div class="post-metadata">

**Author:** ![jeongmin.na](https://avatars.discourse-cdn.com/v4/letter/j/ce7236/32.png) [@jeongmin.na](https://dmap-community.ductus.global/u/jeongmin.na)\
**Post date:** [November 29, 2017, 11:13am UTC](https://dmap-community.ductus.global/t/i-want-to-know-how-to-input-instance-identifier/1666/6 "2017-11-29T11:13:30Z")

</div>

error message is below.

DEBUG Invalid confd\_vtype value: 0

---

<div class="post-metadata">

**Author:** ![jeongmin.na](https://avatars.discourse-cdn.com/v4/letter/j/ce7236/32.png) [@jeongmin.na](https://dmap-community.ductus.global/u/jeongmin.na)\
**Post date:** [November 29, 2017, 12:44pm UTC](https://dmap-community.ductus.global/t/i-want-to-know-how-to-input-instance-identifier/1666/7 "2017-11-29T12:44:13Z")

</div>

Hi cohult

Thank you for your help.  
The following code is referenced by the above code.  
However, the following error occurs.  
Can you tell me what else to do?

```
int get_key_path(confd_hkeypath_t *kp)
{
 int msock;
    struct sockaddr_in saddr;
    struct in_addr an_addr = {0xa0a0a0a0};

    saddr.sin_addr.s_addr = inet_addr("127.0.0.1");
    saddr.sin_family = AF_INET;
    saddr.sin_port = htons(CONFD_PORT);

    msock = socket(PF_INET, SOCK_STREAM, 0);
    maapi_connect(msock, (struct sockaddr *)&saddr, sizeof(saddr));
    dal_load_schemas(); //confd_load_schemas((struct sockaddr*)&d_addr.addr, sizeof(struct sockaddr_in));
    maapi_xpath2kpath(msock, "/managed-element/enb-function/active-queue-management[aqm-index=0]", &kp);
    maapi_close(msock);
}

```

- 

```
                get_key_path(&key_path);

                CONFD_SET_TAG_OBJECTREF(& val[insert_count], noti_path, & key_path); insert_count++;

```

- 

=\> 29-Nov-2017::21:10:57.998 svcf-oam-1128-vlan-cmc-00 confd[5403]: devel-c Failed to send notification for stream NETCONF: /data-changed-notification/data-change-event/noti-path:  
{34,[]}: [] is not a valid value.

---

<div class="post-metadata">

**Author:** ![jeongmin.na](https://avatars.discourse-cdn.com/v4/letter/j/ce7236/32.png) [@jeongmin.na](https://dmap-community.ductus.global/u/jeongmin.na)\
**Post date:** [November 29, 2017, 1:44pm UTC](https://dmap-community.ductus.global/t/i-want-to-know-how-to-input-instance-identifier/1666/8 "2017-11-29T13:44:13Z")

</div>

I’ve fixed the issue.  
I am very grateful for your help.

1. First, I entered the wrong index value. modify -\> [aqm-index=‘0’]
2. Second, The key\_path value is lost after calling get\_key\_path (& key\_path).  
I did not know that dynamic memory was allocated.

Do I need to free memory dynamically allocated by maapi\_xpath2kpath?

---

<div class="post-metadata">

**Author:** ![mnovak](https://yyz2.discourse-cdn.com/flex010/user_avatar/dmap-community.ductus.global/mnovak/32/183_2.png) [@mnovak](https://dmap-community.ductus.global/u/mnovak)\
**Post date:** [November 29, 2017, 2:03pm UTC](https://dmap-community.ductus.global/t/i-want-to-know-how-to-input-instance-identifier/1666/9 "2017-11-29T14:03:53Z")

</div>

Hello,

I have made simple Netconf example based on your scenario (not using maapi\_xpath2keypath).

[https://cisco.box.com/s/2jw6b7gi1zjsos6dr63tsgyaghi75cna](https://cisco.box.com/s/2jw6b7gi1zjsos6dr63tsgyaghi75cna)

Steps are written in the README

```nohighlight
First shell:
make clean all start

Second shell:
netconf-console --create-subscription=data_stream

First shell:
press 'n'

Second shell:
see notification text

```

Main problem in your code was probably that you didn’t add C\_NOEXIST to mark end of keypath and keys in keypath. Also len of keypath was not filled (is commented in your code).

```auto
pKey->len = 4;
pKey->v[4][0].type = C_NOEXISTS;
...

pKey->v[0][0].type = C_UINT16;
pKey->v[0][0].val.u16 = 0;

pKey->v[0][1].type = C_NOEXISTS;

```

Please, can you check if it works in your environment.

---

<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 29, 2017, 9:48pm UTC](https://dmap-community.ductus.global/t/i-want-to-know-how-to-input-instance-identifier/1666/10 "2017-11-29T21:48:42Z")

</div>

\*.[quote=“jeongmin.na, post:8, topic:1666”]  
2) Second, The key\_path value is lost after calling get\_key\_path (& key\_path).  
I did not know that dynamic memory was allocated.  
Do I need to free memory dynamically allocated by maapi\_xpath2kpath?  
[/quote]

From the confd\_lib\_maapi man page for maapi\_xpath2kpath():

> The returned keypath is dynamically allocated, and may further contain dynamically allocated elements. The caller must free the allocated memory, easiest done by calling confd\_free\_hkeypath().

---

<div class="post-metadata">

**Author:** ![rdpravin1895](https://avatars.discourse-cdn.com/v4/letter/r/4da419/32.png) [@rdpravin1895](https://dmap-community.ductus.global/u/rdpravin1895)\
**Post date:** [April 17, 2018, 10:42am UTC](https://dmap-community.ductus.global/t/i-want-to-know-how-to-input-instance-identifier/1666/11 "2018-04-17T10:42:09Z")

</div>

I am also trying to do the similar.  
can you share me the C code for notification that you have written?
