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:
Olof hagsand 2022-05-15 13:42:28 +02:00
parent 62a32faf9c
commit 99cd8bacc0
5 changed files with 279 additions and 105 deletions

View file

@ -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)){

View file

@ -43,11 +43,12 @@ extern "C" {
/* /*
* Prototypes * Prototypes
*/ */
int snmp_modes_str2int(char *modes_str); int snmp_access_str2int(char *modes_str);
int yang2snmp_types(yang_stmt *ys, int *asn1_type, enum cv_type *cvtype); const char *snmp_msg_int2str(int msg);
int type_yang2snmp(char *valstr, enum cv_type cvtype, int yang2snmp_types(yang_stmt *ys, int *asn1_type, enum cv_type *cvtype);
netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests, int type_yang2snmp(char *valstr, enum cv_type cvtype,
u_char **snmpval, size_t *snmplen); netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests,
u_char **snmpval, size_t *snmplen);
int yang2xpath(yang_stmt *ys, cbuf *cb); int yang2xpath(yang_stmt *ys, cbuf *cb);
#endif /* _SNMP_LIB_H_ */ #endif /* _SNMP_LIB_H_ */

View file

@ -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,
snmp_msg_int2str(reqinfo->mode));
sh = (clixon_snmp_handle*)nhreg->my_reg_void;
ys = sh->sh_ys;
h = sh->sh_h;
table = sh->sh_table;
if ((ylist = yang_find(ys, Y_LIST, NULL)) == NULL)
goto ok;
switch(reqinfo->mode){
case MODE_GETNEXT: // 160
if (xml_nsctx_yang(ys, &nsc) < 0)
goto done;
/* XXX just for yang2xpath */
if ((cb = cbuf_new()) == NULL){
clicon_err(OE_UNIX, errno, "cbuf_new");
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) {
netsnmp_ds_set_string(NETSNMP_DS_APPLICATION_ID, NETSNMP_DS_AGENT_X_SOCKET, "/var/run/snmp.sock"); 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;
table = netsnmp_create_table_data_set("netSnmpIETFWGTable"); }
ok:
netsnmp_table_dataset_add_index(table, ASN_OCTET_STR); retval = SNMP_ERR_NOERROR;
netsnmp_table_set_multi_add_default_row(table, 2, ASN_OCTET_STR, 1, NULL, 0, 3, ASN_OCTET_STR, 1, NULL, 0, 0); done:
if (xt)
handler = netsnmp_create_handler_registration("netSnmpIETFWGTable", table_handler, xml_free(xt);
my_registration_oid, if (cb)
OID_LENGTH(my_registration_oid), cbuf_free(cb);
HANDLER_CAN_RWRITE); if (nsc)
handler->my_reg_void = table; xml_nsctx_free(nsc);
return retval;
netsnmp_register_table_data_set(handler, table, NULL);
netsnmp_register_auto_data_table(table, NULL);
} }
/*! 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;

View file

@ -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"

View file

@ -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,16 +117,18 @@ 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"
new "Set new value for one cell" if false; then # NOT YET
expectpart "$($snmpset $OID_SET s newstring)" 0 "$OID_SET = STRING: \"newstring\"" new "Set new value for one cell"
expectpart "$($snmpset $OID_SET s newstring)" 0 "$OID_SET = STRING: \"newstring\""
new "Test invalid type" new "Test invalid type"
expectpart "$($snmpset $OID_SET u 1234)" 1 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