Hi Joseph,
I have already enabled developer log. But there is no message seen on devel.log & confd.log.
The edit-config is failing as i am not able to set the node data in confd provided in rpc.
#netconf-console set.xml
<?xml version="1.0" encoding="UTF-8"?>
<rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="32">
<rpc-error>
<error-type>application</error-type>
<error-tag>unknown-element</error-tag>
<error-severity>error</error-severity>
<error-path xmlns:o-ran-int="urn:o-ran:interfaces:1.0"
xmlns:if="urn:ietf:params:xml:ns:yang:ietf-interfaces">
/rpc/edit-config/config/if:interfaces/if:interface[if:name='cuplane1']/o-ran-int:vlan-tagging
</error-path>
<error-message xml:lang="en">/interfaces/interface[name='cuplane1']/o-ran-int:vlan-tagging: the 'when' expression "if:type = 'ianaift:ethernetCsmacd'" failed</error-message>
<error-info>
<bad-element>vlan-tagging</bad-element>
</error-info>
</rpc-error>
</rpc-reply>
set.xml content:
<rpc xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="32">
<edit-config xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
<target><running/></target>
<config>
<interfaces xmlns="urn:ietf:params:xml:ns:yang:ietf-interfaces">
<interface>
<name>cuplane</name>
<type xmlns:ianaift="urn:ietf:params:xml:ns:yang:iana-if-type">ianaift:l2vlan</type>
<vlan-id xmlns="urn:o-ran:interfaces:1.0">408</vlan-id>
<mac-address xmlns="urn:o-ran:interfaces:1.0">00:1e:3e:0f:fc:1b</mac-address>
</interface>
</interfaces>
</config>
</edit-config>
</rpc>
sample Code:
struct interface {
char name[256];
struct in_addr ip;
unsigned int port;
u_int8_t mac[6];
u_int16_t vlan;
char baseName[256];
};
static struct interface running_db[256];
static int num_interface = 0;
static struct confd_daemon_ctx *dctx;
static int ctlsock;
static int workersock;
static int s_init(struct confd_trans_ctx *tctx)
{
confd_trans_set_fd(tctx, workersock);
return CONFD_OK;
}
static struct interface *find_interface(confd_value_t *v)
{
int i;
for (i=0; i< num_interface; i++) {
if (confd_svcmp(running_db[i].name, v) == 0){
printf("#########Find:%d\n",i);
return &running_db[i];
}
}
return NULL;
}
static struct interface *add_interface(char *name)
{
int i, j;
for (i=0; i < num_interface; i++) {
if (strcmp(running_db[i].name, name) > 0) {
/* found the position to add at, now shuffle the */
/* remaining elems in the array one step */
for (j = num_interface; j > i; j--) {
running_db[j] = running_db[j-1];
}
break;
}
}
num_interface++;
memset(&running_db[i], 0, sizeof(struct interface));
strcpy(running_db[i].name, name);
return &running_db[i];
}
#if 1
static int hw_get_optional(struct confd_trans_ctx *tctx, confd_hkeypath_t * kp)
{
int tag=CONFD_GET_XMLTAG(&kp->v[0][0]);
if (tag == ip_ipv4) {
printf("INSIDE IPV4******8\n");
confd_data_reply_not_found(tctx);
// tag = GET_NEXT_TAG;
}
else if (tag == ip_ipv6) {
printf("INSIDE IPV6******8\n");
confd_data_reply_not_found(tctx);
}
return CONFD_OK;
}
#endif
static int hw_get_elem(struct confd_trans_ctx *tctx, confd_hkeypath_t * kp)
{
confd_value_t v;
confd_value_t *key,*key1;
key = &kp->v[1][0];
struct interface* s = find_interface(&(kp->v[1][0]));
if (s == NULL) {
printf("NO Interface\n");
confd_data_reply_not_found(tctx);
return CONFD_OK;
}
struct confd_identityref idref;
int tag = CONFD_GET_XMLTAG(&kp->v[0][0]);
// printf("*******ELEM TAG:%d\n",tag);
int idx;
char * ifname;
idx = kp->len;
idx = idx - 1;
if(tag==o_ran_int_mac_address)
{
// printf("MAC ADDRESS******************");
CONFD_SET_BINARY(&v,s->mac,6);
}
else if(tag==if_type)
{
// printf("IINTERFACE TYPE\n");
idref.ns = ianaift__ns;
idref.id = ianaift_l2vlan;
CONFD_SET_IDENTITYREF(&v,idref);
}
else if(tag==if_name)
{
//ifname = (char *) CONFD_GET_BUFPTR(&kp->v[1][0]);
if (s== NULL)
{
// key = &kp->v[0][0];
// printf("****Adding Interface*******\n");
add_interface((char *)CONFD_GET_BUFPTR(key));
}
//printf("$$$KEY Name:%s\n",s->name);
//printf("*******TAG:%d\n",tag);
s = find_interface(&(kp->v[1][0]));
CONFD_SET_STR(&v,s->name);
}
else if(tag==o_ran_int_vlan_id)
{
if(s->vlan!=0)
{
printf("vlan accepted");
CONFD_SET_UINT16(&v,s->vlan);
}
else{
printf("vlan not accepted");
CONFD_SET_NOEXISTS(&v);
}
}
else if(tag == o_ran_int_vlan_tagging)
{
CONFD_SET_BOOL(&v,1);
printf("VLAN TAGGING");
}
#if 1
else if( tag == o_ran_int_base_interface)
{
if (tctx->mode == 1)
{
if(strlen(s->baseName)==0)
CONFD_SET_NOEXISTS(&v);
}
else
{
//CONFD_SET_STR(&v,"cuplane");
CONFD_SET_STR(&v,(char *)CONFD_GET_BUFPTR(key));
//strcpy(s->baseName,(char *)CONFD_GET_BUFPTR(key));
}
}
#endif
else if (tag == if_discontinuity_time)
{
time_t t;
struct confd_datetime dt;
time(&t);
time_to_dt(t, &dt);
//getdatetime(&eventTime);
CONFD_SET_DATETIME(&v, dt);
}
else
CONFD_SET_NOEXISTS(&v);
confd_data_reply_value(tctx, &v);
return CONFD_OK;
}
int hw_get_next(struct confd_trans_ctx *tctx,
confd_hkeypath_t * kp, long next)
{
confd_value_t v;
static int pos =0;
printf("*****Get NEXT\n");
switch (CONFD_GET_XMLTAG(&kp->v[0][0])) {
case if_interface:
if (next == -1) { /* first call */
pos = 0;
} else {
pos++;// = (int)next;
}
if (pos == num_interface ) { /* We have reached the end of the list*/
confd_data_reply_next_key(tctx, NULL, -1, -1);
return CONFD_OK;
}
CONFD_SET_STR(&v, running_db[pos].name);
confd_data_reply_next_key(tctx, &v, 1,(long)(pos+1));
break;
case if_higher_layer_if:
confd_data_reply_next_key(tctx, NULL, -1, -1);
break;
case if_lower_layer_if:
confd_data_reply_next_key(tctx, NULL, -1, -1);
break;
case ip_ipv4:
printf("**********IPV4********");
confd_data_reply_next_key(tctx, NULL, -1, -1);
break;
case ip_ipv6:
confd_data_reply_next_key(tctx, NULL, -1, -1);
break;
default:
return CONFD_ERR;
}
return CONFD_OK;
}
static int hw_set_elem(struct confd_trans_ctx *tctx,
confd_hkeypath_t *keypath,
confd_value_t *newval)
{
printf("*************SET ELEMENT");
unsigned char *bin;
int len;
confd_value_t *tag = &(keypath->v[0][0]);
switch (CONFD_GET_XMLTAG(tag)){
case o_ran_int_mac_address:
bin=CONFD_GET_BINARY_PTR(newval);
len=CONFD_GET_BINARY_SIZE(newval);
printf("MAC:%x:%x:%x:%x\n",bin[0],bin[1],bin[2],bin[3],bin[4]);
memcpy(s->mac,bin,len);
break;
#if 1
case o_ran_int_vlan_id:
s->vlan=CONFD_GET_UINT16(newval);
printf("&&&&&&\nSET ELEM VLAN:%d\n",s->vlan);
break;
#if 0
case o_ran_int_base_interface:
printf("****8BASE INTERFACE********\n");
CONFD_SET_STR(&v,"MAC0");
break;
#endif
default:
confd_data_reply_not_found(tctx);
// return CONFD_ERR;
#endif
// case if_name:
}
return CONFD_OK;
}
static int hw_create(struct confd_trans_ctx *tctx,
confd_hkeypath_t *keypath)
{
confd_value_t *key = &keypath->v[0][0];
add_interface((char *)CONFD_GET_BUFPTR(key));
return CONFD_OK;
}
static struct interface *new_interface(char *name, u_int8_t *mac, u_int16_t vlan)
{
struct interface *sp = add_interface(name);
strcpy(sp->mac,mac);//inet_addr(ip);
if(vlan!=0)
{
sp->vlan =vlan;// atoi(port);
}
return sp;
}
init_db()
{
num_interface = 0;
u_int8_t addr[6];
u_int16_t vlan=0;//405;
// u_int16_t vlan=0;//408;
addr[0] = 0x11;
addr[1] = 0x22;
addr[2] = 0x33;
addr[3] = 0x44;
addr[4] = 0x55;
addr[5] = 0x66;
new_interface("cuplane",addr,vlan);
}
int main(int argc, char *argv[])
{
struct sockaddr_in addr;
//int debuglevel = CONFD_PROTO_TRACE;
int debuglevel = CONFD_TRACE;
struct confd_trans_cbs trans;
struct confd_data_cbs data;
/* Initialize confd library */
confd_init("dataprovider", stderr, debuglevel);
addr.sin_addr.s_addr = inet_addr("127.0.0.1");
addr.sin_family = AF_INET;
addr.sin_port = htons(CONFD_PORT);
if (confd_load_schemas((struct sockaddr*)&addr,
sizeof (struct sockaddr_in)) != CONFD_OK)
confd_fatal("Failed to load schemas from confd\n");
if ((dctx = confd_init_daemon("portstatus")) == NULL)
confd_fatal("Failed to initialize daemon\n");
/* Create and connect the control and worker sockets */
if ((ctlsock = socket(PF_INET, SOCK_STREAM, 0)) < 0 )
confd_fatal("Failed to open ctlsocket\n");
if (confd_connect(dctx, ctlsock, CONTROL_SOCKET, (struct sockaddr*)&addr,
sizeof (struct sockaddr_in)) < 0)
confd_fatal("Failed to confd_connect() to confd \n");
if ((workersock = socket(PF_INET, SOCK_STREAM, 0)) < 0 )
confd_fatal("Failed to open workersocket\n");
if (confd_connect(dctx, workersock, WORKER_SOCKET,(struct sockaddr*)&addr,
sizeof (struct sockaddr_in)) < 0)
confd_fatal("Failed to confd_connect() to confd \n");
init_db();
/* Register callbacks */
#if 1
memset(&trans, 0, sizeof(trans));
trans.init = s_init;
if (confd_register_trans_cb(dctx, &trans) == CONFD_ERR)
confd_fatal("Failed to register trans cb\n");
memset(&data, 0, sizeof (struct confd_data_cbs));
data.get_elem = hw_get_elem;
data.get_next = hw_get_next;
data.exists_optional=hw_get_optional;
data.set_elem = hw_set_elem;
data.create = hw_create;
//data.remove = doremove;
//strcpy(data.callpoint, o_ran_hw__callpointid_cb_op_component);
strcpy(data.callpoint,if__callpointid_cb_op_if_interface);
if (confd_register_data_cb(dctx, &data) == CONFD_ERR)
confd_fatal("Failed to register data cb\n");
#endif
if (confd_register_done(dctx) != CONFD_OK)
confd_fatal("Failed to complete registration \n");
while(1) {
struct pollfd set[2];
int ret;
set[0].fd = ctlsock;
set[0].events = POLLIN;
set[0].revents = 0;
set[1].fd = workersock;
set[1].events = POLLIN;
set[1].revents = 0;
if (poll(set, sizeof(set)/sizeof(set[0]), -1) < 0) {
perror("Poll failed:");
continue;
}
/* Check for I/O */
if (set[0].revents & POLLIN) {
if ((ret = confd_fd_ready(dctx, ctlsock)) == CONFD_EOF) {
confd_fatal("Control socket closed\n");
} else if (ret == CONFD_ERR && confd_errno != CONFD_ERR_EXTERNAL) {
confd_fatal("Error on control socket request: %s (%d): %s\n",
confd_strerror(confd_errno), confd_errno, confd_lasterr());
}
}
if (set[1].revents & POLLIN) {
if ((ret = confd_fd_ready(dctx, workersock)) == CONFD_EOF) {
confd_fatal("Worker socket closed\n");
} else if (ret == CONFD_ERR && confd_errno != CONFD_ERR_EXTERNAL) {
confd_fatal("Error on worker socket request: %s (%d): %s\n",
confd_strerror(confd_errno), confd_errno, confd_lasterr());
}
}
}
}