I want to know how to input instance-identifier

  1. There is a yang model as below.
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.
"<"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.
    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
 -> 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.
<noti-path>"managed-element/enb-function/active-queue-management[aqm-index=0]"</noti-path>

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]

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

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

$ 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 {

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 ";
        }
     }
}

error message is below.

DEBUG Invalid confd_vtype value: 0

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.

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?

Hello,

I have made simple Netconf example based on your scenario (not using maapi_xpath2keypath).

https://cisco.box.com/s/2jw6b7gi1zjsos6dr63tsgyaghi75cna

Steps are written in the README

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).

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.

*.[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().

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