SNMP frontend generic code for tables and clixon backend
Added snmp-msg translation table Changed test-table to only GET
This commit is contained in:
parent
62a32faf9c
commit
99cd8bacc0
5 changed files with 279 additions and 105 deletions
|
|
@ -104,16 +104,32 @@ static const map_str2int snmp_type_map[] = {
|
||||||
{NULL, -1}
|
{NULL, -1}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* Map between SNMP message / mode str and int form
|
||||||
|
*/
|
||||||
|
static const map_str2int snmp_msg_map[] = {
|
||||||
|
{"MODE_SET_RESERVE1", MODE_SET_RESERVE1},
|
||||||
|
{"MODE_SET_RESERVE2", MODE_SET_RESERVE2},
|
||||||
|
{"MODE_SET_ACTION", MODE_SET_ACTION},
|
||||||
|
{"MODE_SET_COMMIT", MODE_SET_COMMIT},
|
||||||
|
{"MODE_GET", MODE_GET},
|
||||||
|
{"MODE_GETNEXT", MODE_GETNEXT},
|
||||||
|
{NULL, -1}
|
||||||
|
};
|
||||||
|
|
||||||
/*! Translate from snmp string to int representation
|
/*! Translate from snmp string to int representation
|
||||||
* @note Internal snmpd, maybe find something in netsnmpd?
|
* @note Internal snmpd, maybe find something in netsnmpd?
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
snmp_modes_str2int(char *modes_str)
|
snmp_access_str2int(char *modes_str)
|
||||||
{
|
{
|
||||||
return clicon_str2int(snmp_access_map, modes_str);
|
return clicon_str2int(snmp_access_map, modes_str);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char *
|
||||||
|
snmp_msg_int2str(int msg)
|
||||||
|
{
|
||||||
|
return clicon_int2str(snmp_msg_map, msg);
|
||||||
|
}
|
||||||
/*!
|
/*!
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
|
|
@ -249,7 +265,7 @@ yang2xpath(yang_stmt *ys,
|
||||||
cprintf(cb, "/");
|
cprintf(cb, "/");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
cprintf(cb, "/%s:", yang_find_myprefix(ys));
|
cprintf(cb, "%s:", yang_find_myprefix(ys));
|
||||||
if (yang_keyword_get(ys) != Y_CHOICE && yang_keyword_get(ys) != Y_CASE)
|
if (yang_keyword_get(ys) != Y_CHOICE && yang_keyword_get(ys) != Y_CASE)
|
||||||
cprintf(cb, "%s", yang_argument_get(ys));
|
cprintf(cb, "%s", yang_argument_get(ys));
|
||||||
switch (yang_keyword_get(ys)){
|
switch (yang_keyword_get(ys)){
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,8 @@ extern "C" {
|
||||||
/*
|
/*
|
||||||
* Prototypes
|
* Prototypes
|
||||||
*/
|
*/
|
||||||
int snmp_modes_str2int(char *modes_str);
|
int snmp_access_str2int(char *modes_str);
|
||||||
|
const char *snmp_msg_int2str(int msg);
|
||||||
int yang2snmp_types(yang_stmt *ys, int *asn1_type, enum cv_type *cvtype);
|
int yang2snmp_types(yang_stmt *ys, int *asn1_type, enum cv_type *cvtype);
|
||||||
int type_yang2snmp(char *valstr, enum cv_type cvtype,
|
int type_yang2snmp(char *valstr, enum cv_type cvtype,
|
||||||
netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests,
|
netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests,
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,13 @@
|
||||||
* smiv2:alias "netSnmpExamples" {
|
* smiv2:alias "netSnmpExamples" {
|
||||||
* smiv2:oid "1.3.6.1.4.1.8072.2";
|
* smiv2:oid "1.3.6.1.4.1.8072.2";
|
||||||
*
|
*
|
||||||
|
* SNMP messages:
|
||||||
|
* 160 MODE_GETNEXT / SNMP_MSG_GET
|
||||||
|
* 161 MODE_GET / SNMP_MSG_GETNEXT
|
||||||
|
* 0 MODE_SET_RESERVE1
|
||||||
|
* 1 MODE_SET_RESERVE2
|
||||||
|
* 2 MODE_SET_ACTION
|
||||||
|
* 3 MODE_SET_COMMIT
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifdef HAVE_CONFIG_H
|
#ifdef HAVE_CONFIG_H
|
||||||
|
|
@ -56,6 +62,7 @@
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
#include <assert.h>
|
||||||
|
|
||||||
/* net-snmp */
|
/* net-snmp */
|
||||||
#include <net-snmp/net-snmp-config.h>
|
#include <net-snmp/net-snmp-config.h>
|
||||||
|
|
@ -81,70 +88,118 @@
|
||||||
struct clixon_snmp_handle {
|
struct clixon_snmp_handle {
|
||||||
clicon_handle sh_h;
|
clicon_handle sh_h;
|
||||||
yang_stmt *sh_ys;
|
yang_stmt *sh_ys;
|
||||||
char *sh_default;
|
char *sh_default; /* MIB default value leaf only */
|
||||||
|
netsnmp_table_data_set *sh_table; /* table struct, table only */
|
||||||
};
|
};
|
||||||
typedef struct clixon_snmp_handle clixon_snmp_handle;
|
typedef struct clixon_snmp_handle clixon_snmp_handle;
|
||||||
|
|
||||||
/*
|
/*! SNMP table operation handlre
|
||||||
* https://net-snmp.sourceforge.io/dev/agent/data_set_8c-example.html#_a0
|
|
||||||
|
* Callorder: 161,160,.... 0, 1,2,3, 160,161,...
|
||||||
|
* see https://net-snmp.sourceforge.io/dev/agent/data_set_8c-example.html#_a0
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
table_handler(netsnmp_mib_handler *handler,
|
snmp_table_handler(netsnmp_mib_handler *handler,
|
||||||
netsnmp_handler_registration *reginfo,
|
netsnmp_handler_registration *nhreg,
|
||||||
netsnmp_agent_request_info *reqinfo,
|
netsnmp_agent_request_info *reqinfo,
|
||||||
netsnmp_request_info *requests)
|
netsnmp_request_info *requests)
|
||||||
{
|
{
|
||||||
netsnmp_table_data_set *table = (netsnmp_table_data_set *)reginfo->my_reg_void;
|
int retval = -1;
|
||||||
netsnmp_table_row *row;
|
clixon_snmp_handle *sh;
|
||||||
|
|
||||||
row = netsnmp_create_table_data_row();
|
|
||||||
|
|
||||||
netsnmp_table_row_add_index(row, ASN_OCTET_STR, "snmpv3", strlen("snmpv3"));
|
|
||||||
|
|
||||||
netsnmp_set_row_column(row, 2, ASN_OCTET_STR, "Russ Mundy", strlen("Russ Mundy"));
|
|
||||||
netsnmp_mark_row_column_writable(row, 2, 1);
|
|
||||||
netsnmp_set_row_column(row, 3, ASN_OCTET_STR, "David Harrington", strlen("David Harrington"));
|
|
||||||
netsnmp_mark_row_column_writable(row, 3, 1);
|
|
||||||
|
|
||||||
netsnmp_table_dataset_add_row(table, row);
|
|
||||||
|
|
||||||
return SNMP_ERR_NOERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
init_testtable(void)
|
|
||||||
{
|
|
||||||
netsnmp_handler_registration *handler;
|
|
||||||
netsnmp_table_data_set *table;
|
netsnmp_table_data_set *table;
|
||||||
|
netsnmp_table_row *row;
|
||||||
|
yang_stmt *ys; /* container */
|
||||||
|
yang_stmt *ylist;
|
||||||
|
clicon_handle h;
|
||||||
|
cvec *nsc = NULL;
|
||||||
|
cxobj *xt = NULL;
|
||||||
|
cbuf *cb = NULL;
|
||||||
|
cxobj *xerr;
|
||||||
|
char *xpath;
|
||||||
|
cxobj *xtable;
|
||||||
|
cxobj *xe;
|
||||||
|
cxobj *xleaf;
|
||||||
|
int i;
|
||||||
|
char *valstr;
|
||||||
|
|
||||||
oid my_registration_oid[] = { 1, 3, 6, 1, 4, 1, 8072, 2, 2, 1 };
|
clicon_debug(1, "%s %s %s", __FUNCTION__,
|
||||||
|
handler->handler_name,
|
||||||
netsnmp_ds_set_string(NETSNMP_DS_APPLICATION_ID, NETSNMP_DS_AGENT_X_SOCKET, "/var/run/snmp.sock");
|
snmp_msg_int2str(reqinfo->mode));
|
||||||
|
sh = (clixon_snmp_handle*)nhreg->my_reg_void;
|
||||||
table = netsnmp_create_table_data_set("netSnmpIETFWGTable");
|
ys = sh->sh_ys;
|
||||||
|
h = sh->sh_h;
|
||||||
netsnmp_table_dataset_add_index(table, ASN_OCTET_STR);
|
table = sh->sh_table;
|
||||||
netsnmp_table_set_multi_add_default_row(table, 2, ASN_OCTET_STR, 1, NULL, 0, 3, ASN_OCTET_STR, 1, NULL, 0, 0);
|
if ((ylist = yang_find(ys, Y_LIST, NULL)) == NULL)
|
||||||
|
goto ok;
|
||||||
handler = netsnmp_create_handler_registration("netSnmpIETFWGTable", table_handler,
|
switch(reqinfo->mode){
|
||||||
my_registration_oid,
|
case MODE_GETNEXT: // 160
|
||||||
OID_LENGTH(my_registration_oid),
|
if (xml_nsctx_yang(ys, &nsc) < 0)
|
||||||
HANDLER_CAN_RWRITE);
|
goto done;
|
||||||
handler->my_reg_void = table;
|
/* XXX just for yang2xpath */
|
||||||
|
if ((cb = cbuf_new()) == NULL){
|
||||||
netsnmp_register_table_data_set(handler, table, NULL);
|
clicon_err(OE_UNIX, errno, "cbuf_new");
|
||||||
netsnmp_register_auto_data_table(table, NULL);
|
goto done;
|
||||||
}
|
}
|
||||||
|
if (yang2xpath(ys, cb) < 0)
|
||||||
|
goto done;
|
||||||
|
xpath = cbuf_get(cb);
|
||||||
|
if (clicon_rpc_get(h, xpath, nsc, CONTENT_ALL, -1, &xt) < 0)
|
||||||
|
goto done;
|
||||||
|
if ((xerr = xpath_first(xt, NULL, "/rpc-error")) != NULL){
|
||||||
|
clixon_netconf_error(xerr, "clicon_rpc_get", NULL);
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
|
if ((xtable = xpath_first(xt, nsc, "%s", xpath)) != NULL) {
|
||||||
|
|
||||||
|
xe = NULL; /* Loop thru entries in table */
|
||||||
|
while ((xe = xml_child_each(xtable, xe, CX_ELMNT)) != NULL) {
|
||||||
|
row = netsnmp_create_table_data_row();
|
||||||
|
xleaf = NULL; /* Loop thru leafs in entry */
|
||||||
|
i = 1; /* tableindex start at 1 */
|
||||||
|
while ((xleaf = xml_child_each(xe, xleaf, CX_ELMNT)) != NULL) {
|
||||||
|
valstr = xml_body(xleaf);
|
||||||
|
if (i == 1) // Assume first netry is key XXX should check YANG
|
||||||
|
netsnmp_table_row_add_index(row, ASN_OCTET_STR, valstr, strlen(valstr));
|
||||||
|
else{
|
||||||
|
netsnmp_set_row_column(row, i, ASN_OCTET_STR, valstr, strlen(valstr));
|
||||||
|
netsnmp_mark_row_column_writable(row, i, 1);
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
netsnmp_table_dataset_add_row(table, row);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case MODE_GET: // 160
|
||||||
|
case MODE_SET_RESERVE1:
|
||||||
|
case MODE_SET_RESERVE2:
|
||||||
|
case MODE_SET_ACTION:
|
||||||
|
case MODE_SET_COMMIT:
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
|
ok:
|
||||||
|
retval = SNMP_ERR_NOERROR;
|
||||||
|
done:
|
||||||
|
if (xt)
|
||||||
|
xml_free(xt);
|
||||||
|
if (cb)
|
||||||
|
cbuf_free(cb);
|
||||||
|
if (nsc)
|
||||||
|
xml_nsctx_free(nsc);
|
||||||
|
return retval;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*! SNMP Scalar operation handler
|
/*! SNMP Scalar operation handler
|
||||||
* Calls come: READ:160,
|
* Calls order: READ:160,
|
||||||
* WRITE: 0, 1, 2, 3,
|
* WRITE: 0, 1, 2, 3,
|
||||||
* MODE_SET_RESEVE1, MODE_SET_RESERVE2, MODE_SET_ACTION, MODE_SET_COMMIT
|
* MODE_SET_RESERVE1, MODE_SET_RESERVE2, MODE_SET_ACTION, MODE_SET_COMMIT
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
snmp_scalar_handler(netsnmp_mib_handler *handler,
|
snmp_scalar_handler(netsnmp_mib_handler *handler,
|
||||||
netsnmp_handler_registration *reginfo,
|
netsnmp_handler_registration *nhreg,
|
||||||
netsnmp_agent_request_info *reqinfo,
|
netsnmp_agent_request_info *reqinfo,
|
||||||
netsnmp_request_info *requests)
|
netsnmp_request_info *requests)
|
||||||
{
|
{
|
||||||
|
|
@ -173,12 +228,12 @@ snmp_scalar_handler(netsnmp_mib_handler *handler,
|
||||||
netsnmp_data_list *agent_data;
|
netsnmp_data_list *agent_data;
|
||||||
netsnmp_free_agent_data_set()
|
netsnmp_free_agent_data_set()
|
||||||
*/
|
*/
|
||||||
clicon_debug(1, "%s %s", __FUNCTION__, handler->handler_name);
|
clicon_debug(1, "%s %s %s", __FUNCTION__,
|
||||||
|
handler->handler_name,
|
||||||
sh = (clixon_snmp_handle*)handler->myvoid;
|
snmp_msg_int2str(reqinfo->mode));
|
||||||
|
sh = (clixon_snmp_handle*)nhreg->my_reg_void;
|
||||||
ys = sh->sh_ys;
|
ys = sh->sh_ys;
|
||||||
h = sh->sh_h;
|
h = sh->sh_h;
|
||||||
clicon_debug(1, "%s mode:%d", __FUNCTION__, reqinfo->mode);
|
|
||||||
|
|
||||||
if (yang2snmp_types(ys, &asn1_type, &cvtype) < 0)
|
if (yang2snmp_types(ys, &asn1_type, &cvtype) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
|
|
@ -197,7 +252,7 @@ snmp_scalar_handler(netsnmp_mib_handler *handler,
|
||||||
|
|
||||||
if (xml_nsctx_yang(ys, &nsc) < 0)
|
if (xml_nsctx_yang(ys, &nsc) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
|
/* XXX just for yang2xpath */
|
||||||
if ((cb = cbuf_new()) == NULL){
|
if ((cb = cbuf_new()) == NULL){
|
||||||
clicon_err(OE_UNIX, errno, "cbuf_new");
|
clicon_err(OE_UNIX, errno, "cbuf_new");
|
||||||
goto done;
|
goto done;
|
||||||
|
|
@ -298,29 +353,116 @@ snmp_scalar_handler(netsnmp_mib_handler *handler,
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*! Parse smiv2 extensions for YANG container/list
|
||||||
|
*
|
||||||
|
* Typical table:
|
||||||
|
* container x {
|
||||||
|
* smiv2:oid "1.3.6.1.4.1.8072.2.2.1";
|
||||||
|
* list y{
|
||||||
|
*
|
||||||
|
* }
|
||||||
|
* }
|
||||||
|
* @param[in] h Clixon handle
|
||||||
|
* @param[in] ys Mib-Yang node
|
||||||
|
* @retval 0 OK
|
||||||
|
* @retval -1 Error
|
||||||
|
*/
|
||||||
|
static int
|
||||||
|
mib_yang_table(clicon_handle h,
|
||||||
|
yang_stmt *ys)
|
||||||
|
{
|
||||||
|
int retval = -1;
|
||||||
|
netsnmp_handler_registration *nhreg;
|
||||||
|
netsnmp_table_data_set *table;
|
||||||
|
char *oidstr = NULL;
|
||||||
|
oid oid1[MAX_OID_LEN] = {0,};
|
||||||
|
size_t sz1 = MAX_OID_LEN;
|
||||||
|
char *name;
|
||||||
|
clixon_snmp_handle *sh;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
/* Get OID from parent container */
|
||||||
|
if (yang_extension_value(ys, "oid", IETF_YANG_SMIV2_NS, NULL, &oidstr) < 0)
|
||||||
|
goto done;
|
||||||
|
if (oidstr == NULL)
|
||||||
|
goto ok;
|
||||||
|
if (snmp_parse_oid(oidstr, oid1, &sz1) == NULL){
|
||||||
|
clicon_err(OE_SNMP, 0, "snmp_parse_oid");
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
|
name = yang_argument_get(ys);
|
||||||
|
|
||||||
|
if ((table = netsnmp_create_table_data_set(name)) == NULL){
|
||||||
|
clicon_err(OE_SNMP, errno, "netsnmp_create_table_data_set");
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
|
/* Userdata to pass around in netsmp callbacks
|
||||||
|
* XXX: not deallocated
|
||||||
|
*/
|
||||||
|
if ((sh = malloc(sizeof(*sh))) == NULL){
|
||||||
|
clicon_err(OE_UNIX, errno, "malloc");
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
|
sh->sh_h = h;
|
||||||
|
sh->sh_ys = ys;
|
||||||
|
sh->sh_table = table;
|
||||||
|
|
||||||
|
(void)netsnmp_table_dataset_add_index(table, ASN_OCTET_STR);
|
||||||
|
(void)netsnmp_table_set_multi_add_default_row(table, 2, ASN_OCTET_STR, 1, NULL, 0, 3, ASN_OCTET_STR, 1, NULL, 0, 0);
|
||||||
|
|
||||||
|
if ((nhreg = netsnmp_create_handler_registration(name,
|
||||||
|
snmp_table_handler,
|
||||||
|
oid1,
|
||||||
|
sz1,
|
||||||
|
HANDLER_CAN_RWRITE)) == NULL){
|
||||||
|
clicon_err(OE_SNMP, errno, "netsnmp_create_handler_registration");
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
|
|
||||||
|
nhreg->my_reg_void = sh;
|
||||||
|
|
||||||
|
if ((ret = netsnmp_register_table_data_set(nhreg, table, NULL)) != SNMPERR_SUCCESS){
|
||||||
|
//XXX err return? clicon_err(OE_SNMP, ret, "netsnmp_register_table_data_set");
|
||||||
|
// goto done;
|
||||||
|
|
||||||
|
}
|
||||||
|
(void)netsnmp_register_auto_data_table(table, NULL);
|
||||||
|
|
||||||
|
clicon_debug(1, "%s %s registered", __FUNCTION__, oidstr);
|
||||||
|
ok:
|
||||||
|
retval = 0;
|
||||||
|
done:
|
||||||
|
return retval;
|
||||||
|
}
|
||||||
|
|
||||||
/*! Parse smiv2 extensions for YANG leaf
|
/*! Parse smiv2 extensions for YANG leaf
|
||||||
* Typical leaf:
|
* Typical leaf:
|
||||||
* smiv2:oid "1.3.6.1.4.1.8072.2.1.1";
|
* smiv2:oid "1.3.6.1.4.1.8072.2.1.1";
|
||||||
* smiv2:max-access "read-write";
|
* smiv2:max-access "read-write";
|
||||||
* smiv2:defval "42"; (optional)
|
* smiv2:defval "42"; (optional)
|
||||||
|
* @param[in] h Clixon handle
|
||||||
|
* @param[in] ys Mib-Yang node
|
||||||
|
* @retval 0 OK
|
||||||
|
* @retval -1 Error
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
mib_yang_leaf(clicon_handle h,
|
mib_yang_leaf(clicon_handle h,
|
||||||
yang_stmt *ys)
|
yang_stmt *ys)
|
||||||
{
|
{
|
||||||
int retval = -1;
|
int retval = -1;
|
||||||
netsnmp_handler_registration *nh = NULL;
|
netsnmp_handler_registration *nhreg = NULL;
|
||||||
netsnmp_mib_handler *handler;
|
netsnmp_mib_handler *handler;
|
||||||
int ret;
|
int ret;
|
||||||
char *oidstr = NULL;
|
|
||||||
char *modes_str = NULL;
|
char *modes_str = NULL;
|
||||||
char *default_str = NULL;
|
char *default_str = NULL;
|
||||||
|
char *oidstr = NULL;
|
||||||
oid oid1[MAX_OID_LEN] = {0,};
|
oid oid1[MAX_OID_LEN] = {0,};
|
||||||
size_t sz1 = MAX_OID_LEN;
|
size_t sz1 = MAX_OID_LEN;
|
||||||
int modes;
|
int modes;
|
||||||
char *name;
|
char *name;
|
||||||
clixon_snmp_handle *sh;
|
clixon_snmp_handle *sh;
|
||||||
|
|
||||||
|
/* Get OID from leaf */
|
||||||
if (yang_extension_value(ys, "oid", IETF_YANG_SMIV2_NS, NULL, &oidstr) < 0)
|
if (yang_extension_value(ys, "oid", IETF_YANG_SMIV2_NS, NULL, &oidstr) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
if (oidstr == NULL)
|
if (oidstr == NULL)
|
||||||
|
|
@ -336,7 +478,7 @@ mib_yang_leaf(clicon_handle h,
|
||||||
*/
|
*/
|
||||||
if (modes_str == NULL)
|
if (modes_str == NULL)
|
||||||
goto ok;
|
goto ok;
|
||||||
modes = snmp_modes_str2int(modes_str);
|
modes = snmp_access_str2int(modes_str);
|
||||||
|
|
||||||
/* SMI default value, How is this different from yang defaults?
|
/* SMI default value, How is this different from yang defaults?
|
||||||
*/
|
*/
|
||||||
|
|
@ -360,8 +502,7 @@ mib_yang_leaf(clicon_handle h,
|
||||||
sh->sh_h = h;
|
sh->sh_h = h;
|
||||||
sh->sh_ys = ys;
|
sh->sh_ys = ys;
|
||||||
sh->sh_default = default_str;
|
sh->sh_default = default_str;
|
||||||
handler->myvoid =(void*)sh;
|
if ((nhreg = netsnmp_handler_registration_create(name,
|
||||||
if ((nh = netsnmp_handler_registration_create(name,
|
|
||||||
handler,
|
handler,
|
||||||
oid1,
|
oid1,
|
||||||
sz1,
|
sz1,
|
||||||
|
|
@ -370,16 +511,16 @@ mib_yang_leaf(clicon_handle h,
|
||||||
netsnmp_handler_free(handler);
|
netsnmp_handler_free(handler);
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
nhreg->my_reg_void =(void*)sh;
|
||||||
/*
|
/*
|
||||||
* XXX: nh->agent_data
|
* XXX: nhreg->agent_data
|
||||||
*/
|
*/
|
||||||
if ((ret = netsnmp_register_instance(nh)) < 0){
|
if ((ret = netsnmp_register_instance(nhreg)) < 0){
|
||||||
/* XXX Failures are MIB_REGISTRATION_FAILED and MIB_DUPLICATE_REGISTRATION. */
|
/* XXX Failures are MIB_REGISTRATION_FAILED and MIB_DUPLICATE_REGISTRATION. */
|
||||||
clicon_err(OE_SNMP, ret, "netsnmp_register_instance");
|
clicon_err(OE_SNMP, ret, "netsnmp_register_instance");
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
clicon_debug(1, "%s %s registered", __FUNCTION__, oidstr);
|
clicon_debug(1, "%s %s registered", __FUNCTION__, oidstr);
|
||||||
|
|
||||||
ok:
|
ok:
|
||||||
retval = 0;
|
retval = 0;
|
||||||
done:
|
done:
|
||||||
|
|
@ -420,13 +561,14 @@ mib_traverse(clicon_handle h,
|
||||||
if (mib_yang_leaf(h, yn) < 0)
|
if (mib_yang_leaf(h, yn) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
break;
|
break;
|
||||||
case Y_CONTAINER: // XXX
|
case Y_CONTAINER: /* See list case */
|
||||||
break;
|
break;
|
||||||
case Y_LIST: // XXX
|
case Y_LIST: /* If parent is container -> identify as table */
|
||||||
yp = yang_parent_get(yn);
|
yp = yang_parent_get(yn);
|
||||||
if (yang_keyword_get(yp) == Y_CONTAINER){
|
if (yang_keyword_get(yp) == Y_CONTAINER){
|
||||||
/* XXX ad-hoc method to find table? now skip */
|
if (mib_yang_table(h, yp) < 0)
|
||||||
goto ok;
|
goto done;
|
||||||
|
goto ok; /* Dont traverse child leafs further */
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|
@ -488,7 +630,6 @@ clixon_snmp_mib_yangs(clicon_handle h)
|
||||||
if (mib_traverse(h, ymod) < 0)
|
if (mib_traverse(h, ymod) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
init_testtable(); // XXX NOTE Must be AFTER loop ^ for unknown reason
|
|
||||||
retval = 0;
|
retval = 0;
|
||||||
done:
|
done:
|
||||||
return retval;
|
return retval;
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@
|
||||||
# Magic line must be first in script (see README.md)
|
# Magic line must be first in script (see README.md)
|
||||||
s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi
|
s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi
|
||||||
|
|
||||||
|
# Re-use main example backend state callbacks
|
||||||
APPNAME=example
|
APPNAME=example
|
||||||
|
|
||||||
if [ ${ENABLE_NETSNMP} != "yes" ]; then
|
if [ ${ENABLE_NETSNMP} != "yes" ]; then
|
||||||
|
|
@ -37,7 +38,6 @@ cat <<EOF > $cfg
|
||||||
<CLICON_XMLDB_DIR>$dir</CLICON_XMLDB_DIR>
|
<CLICON_XMLDB_DIR>$dir</CLICON_XMLDB_DIR>
|
||||||
<CLICON_SNMP_AGENT_SOCK>unix:$SOCK</CLICON_SNMP_AGENT_SOCK>
|
<CLICON_SNMP_AGENT_SOCK>unix:$SOCK</CLICON_SNMP_AGENT_SOCK>
|
||||||
<CLICON_SNMP_MIB>NET-SNMP-EXAMPLES-MIB</CLICON_SNMP_MIB>
|
<CLICON_SNMP_MIB>NET-SNMP-EXAMPLES-MIB</CLICON_SNMP_MIB>
|
||||||
|
|
||||||
</clixon-config>
|
</clixon-config>
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
|
|
@ -63,7 +63,6 @@ EOF
|
||||||
|
|
||||||
function testinit(){
|
function testinit(){
|
||||||
new "test params: -f $cfg -- -sS $fstate"
|
new "test params: -f $cfg -- -sS $fstate"
|
||||||
|
|
||||||
if [ $BE -ne 0 ]; then
|
if [ $BE -ne 0 ]; then
|
||||||
# Kill old backend and start a new one
|
# Kill old backend and start a new one
|
||||||
new "kill old backend"
|
new "kill old backend"
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,11 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
# Use NET-SNMP-EXAMPLES-MIB
|
# SNMP table snmpget / snmptable
|
||||||
# with OID: .iso.org.dod.internet.private.enterprises.netSnmp.netSnmpExamples (.1.3.6.1.4.1.8072.2)
|
|
||||||
|
|
||||||
# Magic line must be first in script (see README.md)
|
# Magic line must be first in script (see README.md)
|
||||||
s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi
|
s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi
|
||||||
|
|
||||||
APPNAME=snmp
|
# Re-use main example backend state callbacks
|
||||||
|
APPNAME=example
|
||||||
|
|
||||||
if [ ${ENABLE_NETSNMP} != "yes" ]; then
|
if [ ${ENABLE_NETSNMP} != "yes" ]; then
|
||||||
echo "Skipping test, Net-SNMP support not enabled."
|
echo "Skipping test, Net-SNMP support not enabled."
|
||||||
|
|
@ -19,6 +19,7 @@ snmptable="$(type -p snmptable) -c public -v2c localhost:161 "
|
||||||
|
|
||||||
cfg=$dir/conf_startup.xml
|
cfg=$dir/conf_startup.xml
|
||||||
fyang=$dir/clixon-example.yang
|
fyang=$dir/clixon-example.yang
|
||||||
|
fstate=$dir/state.xml
|
||||||
|
|
||||||
# AgentX unix socket
|
# AgentX unix socket
|
||||||
SOCK=/var/run/snmp.sock
|
SOCK=/var/run/snmp.sock
|
||||||
|
|
@ -38,6 +39,7 @@ cat <<EOF > $cfg
|
||||||
<CLICON_YANG_DIR>${MIB_GENERATED_YANG_DIR}</CLICON_YANG_DIR>
|
<CLICON_YANG_DIR>${MIB_GENERATED_YANG_DIR}</CLICON_YANG_DIR>
|
||||||
<CLICON_YANG_MAIN_FILE>$fyang</CLICON_YANG_MAIN_FILE>
|
<CLICON_YANG_MAIN_FILE>$fyang</CLICON_YANG_MAIN_FILE>
|
||||||
<CLICON_SOCK>$dir/$APPNAME.sock</CLICON_SOCK>
|
<CLICON_SOCK>$dir/$APPNAME.sock</CLICON_SOCK>
|
||||||
|
<CLICON_BACKEND_DIR>/usr/local/lib/$APPNAME/backend</CLICON_BACKEND_DIR>
|
||||||
<CLICON_BACKEND_PIDFILE>/var/tmp/$APPNAME.pidfile</CLICON_BACKEND_PIDFILE>
|
<CLICON_BACKEND_PIDFILE>/var/tmp/$APPNAME.pidfile</CLICON_BACKEND_PIDFILE>
|
||||||
<CLICON_XMLDB_DIR>$dir</CLICON_XMLDB_DIR>
|
<CLICON_XMLDB_DIR>$dir</CLICON_XMLDB_DIR>
|
||||||
<CLICON_SNMP_AGENT_SOCK>unix:$SOCK</CLICON_SNMP_AGENT_SOCK>
|
<CLICON_SNMP_AGENT_SOCK>unix:$SOCK</CLICON_SNMP_AGENT_SOCK>
|
||||||
|
|
@ -56,8 +58,21 @@ module clixon-example{
|
||||||
}
|
}
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
|
# This is state data written to file that backend reads from (on request)
|
||||||
|
cat <<EOF > $fstate
|
||||||
|
<NET-SNMP-EXAMPLES-MIB xmlns="urn:ietf:params:xml:ns:yang:smiv2:NET-SNMP-EXAMPLES-MIB">
|
||||||
|
<netSnmpIETFWGTable>
|
||||||
|
<netSnmpIETFWGEntry>
|
||||||
|
<nsIETFWGName>snmpv3</nsIETFWGName>
|
||||||
|
<nsIETFWGChair1>Russ Mundy</nsIETFWGChair1>
|
||||||
|
<nsIETFWGChair2>David Harrington</nsIETFWGChair2>
|
||||||
|
</netSnmpIETFWGEntry>
|
||||||
|
</netSnmpIETFWGTable>
|
||||||
|
</NET-SNMP-EXAMPLES-MIB>
|
||||||
|
EOF
|
||||||
|
|
||||||
function testinit(){
|
function testinit(){
|
||||||
new "test params: -f $cfg"
|
new "test params: -f $cfg -- -sS $fstate"
|
||||||
if [ $BE -ne 0 ]; then
|
if [ $BE -ne 0 ]; then
|
||||||
# Kill old backend and start a new one
|
# Kill old backend and start a new one
|
||||||
new "kill old backend"
|
new "kill old backend"
|
||||||
|
|
@ -69,7 +84,7 @@ function testinit(){
|
||||||
sudo pkill -f clixon_backend
|
sudo pkill -f clixon_backend
|
||||||
|
|
||||||
new "Starting backend"
|
new "Starting backend"
|
||||||
start_backend -s init -f $cfg
|
start_backend -s init -f $cfg -- -sS $fstate
|
||||||
fi
|
fi
|
||||||
|
|
||||||
new "wait backend"
|
new "wait backend"
|
||||||
|
|
@ -87,8 +102,8 @@ function testinit(){
|
||||||
new "wait snmp"
|
new "wait snmp"
|
||||||
wait_snmp
|
wait_snmp
|
||||||
|
|
||||||
# XXX: This should be remoeved!
|
# XXX: It is necessary to run twice? (should be removed!)
|
||||||
$($snmptable $OID)
|
$snmptable $OID
|
||||||
}
|
}
|
||||||
|
|
||||||
function testexit()
|
function testexit()
|
||||||
|
|
@ -102,8 +117,9 @@ new "SNMP table tests"
|
||||||
testinit
|
testinit
|
||||||
|
|
||||||
new "Test SNMP table for netSnmpIETFWGTable"
|
new "Test SNMP table for netSnmpIETFWGTable"
|
||||||
expectpart "$($snmptable $OID)" 0 "SNMP table: NET-SNMP-EXAMPLES-MIB::netSnmpIETFWGTable"
|
expectpart "$($snmptable $OID)" 0 "SNMP table: NET-SNMP-EXAMPLES-MIB::netSnmpIETFWGTable" "Russ Mundy" "David Harrington"
|
||||||
|
|
||||||
|
if false; then # NOT YET
|
||||||
new "Set new value for one cell"
|
new "Set new value for one cell"
|
||||||
expectpart "$($snmpset $OID_SET s newstring)" 0 "$OID_SET = STRING: \"newstring\""
|
expectpart "$($snmpset $OID_SET s newstring)" 0 "$OID_SET = STRING: \"newstring\""
|
||||||
|
|
||||||
|
|
@ -112,6 +128,7 @@ expectpart "$($snmpset $OID_SET u 1234)" 1
|
||||||
|
|
||||||
new "Test SNMP table for netSnmpIETFWGTable with new value"
|
new "Test SNMP table for netSnmpIETFWGTable with new value"
|
||||||
expectpart "$($snmptable $OID)" 0 "newstring"
|
expectpart "$($snmptable $OID)" 0 "newstring"
|
||||||
|
fi
|
||||||
|
|
||||||
new "Cleaning up"
|
new "Cleaning up"
|
||||||
testexit
|
testexit
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue