I have few parameters that have default values in my implementation. I am trying to add those parameters with respective values using maapi API.
cos-classifier is a leaf with two enum values in the yang file
However, it does not work for me… maapi_set_elem2() is returning an error all the time…
is there something that I am missing here?
I tried using “pcp” instead of “1” and even “enum<1>” as third argument to maapi_set_elem2().
maapi_set_namespace(msock, maapi_thandle, link__ns);
syslog(LOG_INFO, "setting cos-classifier to be pcp");
if (maapi_set_elem2(msock, maapi_thandle, "1", "/link/cos-classifier") != CONFD_OK) {
syslog(LOG_ERR, "cos-classifier init to pcp failed");
}
maapi_apply_trans(msock, maapi_thandle, 0);
if (maapi_finish_trans(msock, maapi_thandle) != CONFD_OK) {
syslog(LOG_ERR, "%s: failed to finish transaction", __FUNCTION__);
}
syslog(LOG_INFO, "%s: Changes applied to CDB successfully", __FUNCTION__);
maapi_close(msock);
Since you didn’t provide the YANG model for your project, I will use the intro/1-2-3 example to illustrate how maapi_set_elem2( ) works with enum values.
Following is a snippet of dhcpd.yang for the example:
You should be using the names of the enum as defined in the YANG when working with the maapi_set_elem2( ) API call. I will demonstrate using the confd_cmd tool which is a wrapper of the ConfD library functions in which the man-page for it can be found in the ConfD User Guide. The mset command translates to maapi_set_elem2( ).
Here is my yang definition.
typedef cndlp-classifier-mode {
type enumeration {
enum vid {
tailf:info “Classification based on vlan tag”;
}
enum pcp {
tailf:info “Classification based on pcp bits”;
}
}
tailf:info “classifier mode [vid|pcp]”;
}
leaf cos-classifier {
when "../mode = 'differentiated'";
type cndlp-types:cndlp-classifier-mode;
tailf:info "Mode of traffic treatment based on vlan or pcp";
}
I tried three different ways: all of them returning an error…
if (maapi_set_elem2(msock, maapi_thandle, “1”, “/link/cos-classifier”) != CONFD_OK) {
if (maapi_set_elem2(msock, maapi_thandle, “pcp”, “/link/cos-classifier”) != CONFD_OK) {
if (maapi_set_elem2(msock, maapi_thandle, “enum<1>”, “/link/cos-classifier”) != CONFD_OK) {