SNMP frontend
Fixed table/scalar collision issue Made the CS variable change said to be in previous commit
This commit is contained in:
parent
214b7cc0c7
commit
4e0d9dd987
4 changed files with 111 additions and 58 deletions
|
|
@ -394,11 +394,6 @@ main(int argc,
|
||||||
if (clicon_nsctx_global_set(h, nsctx_global) < 0)
|
if (clicon_nsctx_global_set(h, nsctx_global) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
|
|
||||||
#if 0
|
|
||||||
/* Call start function is all plugins before we go interactive */
|
|
||||||
if (clixon_plugin_start_all(h) < 0)
|
|
||||||
goto done;
|
|
||||||
#endif
|
|
||||||
/* Get session id from backend hello */
|
/* Get session id from backend hello */
|
||||||
clicon_session_id_set(h, getpid());
|
clicon_session_id_set(h, getpid());
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -292,6 +292,7 @@ my_test_instance_handler(netsnmp_mib_handler *handler,
|
||||||
|
|
||||||
return SNMP_ERR_NOERROR;
|
return SNMP_ERR_NOERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*! Parse smiv2 extensions for YANG leaf
|
/*! Parse smiv2 extensions for YANG leaf
|
||||||
|
|
@ -318,8 +319,6 @@ mib_yang_leaf(clicon_handle h,
|
||||||
char *origtype=NULL; /* original type */
|
char *origtype=NULL; /* original type */
|
||||||
char *name;
|
char *name;
|
||||||
|
|
||||||
|
|
||||||
clicon_debug(1, "%s %s", __FUNCTION__, oidstr);
|
|
||||||
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)
|
||||||
|
|
@ -347,10 +346,12 @@ mib_yang_leaf(clicon_handle h,
|
||||||
goto done;
|
goto done;
|
||||||
// restype = yrestype?yang_argument_get(yrestype):NULL;
|
// restype = yrestype?yang_argument_get(yrestype):NULL;
|
||||||
name = yang_argument_get(ys);
|
name = yang_argument_get(ys);
|
||||||
|
|
||||||
if ((handler = netsnmp_create_handler(name, my_test_instance_handler)) == NULL){
|
if ((handler = netsnmp_create_handler(name, my_test_instance_handler)) == NULL){
|
||||||
clicon_err(OE_SNMP, errno, "netsnmp_create_handler");
|
clicon_err(OE_SNMP, errno, "netsnmp_create_handler");
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
// handler->myvoid = h;
|
// handler->myvoid = h;
|
||||||
handler->myvoid =(void*)99;
|
handler->myvoid =(void*)99;
|
||||||
if ((nh = netsnmp_handler_registration_create(name,
|
if ((nh = netsnmp_handler_registration_create(name,
|
||||||
|
|
@ -362,12 +363,13 @@ mib_yang_leaf(clicon_handle h,
|
||||||
netsnmp_handler_free(handler);
|
netsnmp_handler_free(handler);
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
clicon_debug(1, "%s %p", __FUNCTION__, nh);
|
|
||||||
if ((ret = netsnmp_register_instance(nh)) < 0){
|
if ((ret = netsnmp_register_instance(nh)) < 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);
|
||||||
|
|
||||||
ok:
|
ok:
|
||||||
retval = 0;
|
retval = 0;
|
||||||
done:
|
done:
|
||||||
|
|
@ -386,29 +388,67 @@ mib_yang_leaf(clicon_handle h,
|
||||||
* @see yang_extension_value
|
* @see yang_extension_value
|
||||||
* @see ys_populate_unknown
|
* @see ys_populate_unknown
|
||||||
*/
|
*/
|
||||||
static int
|
|
||||||
mib_yang_extension(yang_stmt *ys,
|
|
||||||
void *arg)
|
|
||||||
{
|
|
||||||
int retval = -1;
|
|
||||||
clicon_handle h = (clicon_handle)arg;
|
|
||||||
|
|
||||||
switch(yang_keyword_get(ys)){
|
/*! Traverse mib-yang tree, identify scalars and tables, register OID and callbacks
|
||||||
|
*
|
||||||
|
* The tree is traversed depth-first, which at least guarantees that a parent is
|
||||||
|
* traversed before a child.
|
||||||
|
* Extensions are grouped in some categories, the one I have seen are, example:
|
||||||
|
* 1. leaf
|
||||||
|
* smiv2:max-access "read-write";
|
||||||
|
* smiv2:oid "1.3.6.1.4.1.8072.2.1.1";
|
||||||
|
* smiv2:defval "42"; (not always)
|
||||||
|
* 2. container, list
|
||||||
|
* smiv2:oid "1.3.6.1.4.1.8072.2.1";
|
||||||
|
* 3. module level
|
||||||
|
* smiv2:alias "netSnmpExamples" {
|
||||||
|
* smiv2:oid "1.3.6.1.4.1.8072.2";
|
||||||
|
|
||||||
|
* @param[in] h Clixon handle
|
||||||
|
* @param[in] yn yang node
|
||||||
|
* @retval -1 Error, aborted at first error encounter
|
||||||
|
* @retval 0 OK, all nodes traversed
|
||||||
|
*/
|
||||||
|
static int
|
||||||
|
mib_traverse(clicon_handle h,
|
||||||
|
yang_stmt *yn)
|
||||||
|
{
|
||||||
|
int retval = -1;
|
||||||
|
yang_stmt *ys = NULL;
|
||||||
|
yang_stmt *yp;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
switch(yang_keyword_get(yn)){
|
||||||
case Y_LEAF:
|
case Y_LEAF:
|
||||||
if (mib_yang_leaf(h, ys) < 0)
|
if (mib_yang_leaf(h, yn) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
break;
|
break;
|
||||||
case Y_CONTAINER: // XXX
|
case Y_CONTAINER: // XXX
|
||||||
break;
|
break;
|
||||||
case Y_LIST: // XXX
|
case Y_LIST: // XXX
|
||||||
|
yp = yang_parent_get(yn);
|
||||||
|
if (yang_keyword_get(yp) == Y_CONTAINER){
|
||||||
|
/* XXX ad-hoc method to find table? now skip */
|
||||||
|
goto ok;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
ys = NULL;
|
||||||
|
while ((ys = yn_each(yn, ys)) != NULL) {
|
||||||
|
if ((ret = mib_traverse(h, ys)) < 0)
|
||||||
|
goto done;
|
||||||
|
if (ret > 0){
|
||||||
|
retval = ret;
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ok:
|
||||||
retval = 0;
|
retval = 0;
|
||||||
done:
|
done:
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
clixon_snmp_mib_yangs(clicon_handle h)
|
clixon_snmp_mib_yangs(clicon_handle h)
|
||||||
|
|
@ -420,8 +460,6 @@ clixon_snmp_mib_yangs(clicon_handle h)
|
||||||
yang_stmt *ymod;
|
yang_stmt *ymod;
|
||||||
|
|
||||||
/* XXX Hardcoded, replace this with generic MIB */
|
/* XXX Hardcoded, replace this with generic MIB */
|
||||||
init_testtable(); // XXX
|
|
||||||
|
|
||||||
if ((yspec = clicon_dbspec_yang(h)) == NULL){
|
if ((yspec = clicon_dbspec_yang(h)) == NULL){
|
||||||
clicon_err(OE_FATAL, 0, "No DB_SPEC");
|
clicon_err(OE_FATAL, 0, "No DB_SPEC");
|
||||||
goto done;
|
goto done;
|
||||||
|
|
@ -444,9 +482,10 @@ clixon_snmp_mib_yangs(clicon_handle h)
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
/* Recursively traverse the mib-yang to find extensions */
|
/* Recursively traverse the mib-yang to find extensions */
|
||||||
if (yang_apply(ymod, -1, mib_yang_extension, 1, h) < 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;
|
||||||
|
|
|
||||||
|
|
@ -48,27 +48,35 @@ EOF
|
||||||
|
|
||||||
function testinit(){
|
function testinit(){
|
||||||
new "test params: -f $cfg"
|
new "test params: -f $cfg"
|
||||||
# Kill old backend and start a new one
|
|
||||||
new "kill old backend"
|
if [ $BE -ne 0 ]; then
|
||||||
sudo clixon_backend -zf $cfg
|
# Kill old backend and start a new one
|
||||||
if [ $? -ne 0 ]; then
|
new "kill old backend"
|
||||||
|
sudo clixon_backend -zf $cfg
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
err "Failed to start backend"
|
err "Failed to start backend"
|
||||||
|
fi
|
||||||
|
|
||||||
|
sudo pkill -f clixon_backend
|
||||||
|
|
||||||
|
new "Starting backend"
|
||||||
|
start_backend -s init -f $cfg
|
||||||
fi
|
fi
|
||||||
|
|
||||||
sudo pkill -f clixon_backend
|
new "wait backend"
|
||||||
|
wait_backend
|
||||||
|
|
||||||
|
if [ $CS -ne 0 ]; then
|
||||||
|
# Kill old clixon_snmp, if any
|
||||||
|
new "Terminating any old clixon_snmp processes"
|
||||||
|
sudo killall -q clixon_snmp
|
||||||
|
|
||||||
new "Starting backend"
|
new "Starting clixon_snmp"
|
||||||
start_backend -s init -f $cfg
|
start_snmp $cfg &
|
||||||
|
fi
|
||||||
|
|
||||||
# Kill old clixon_snmp, if any
|
new "wait snmp"
|
||||||
new "Terminating any old clixon_snmp processes"
|
wait_snmp
|
||||||
sudo killall -q clixon_snmp
|
|
||||||
|
|
||||||
new "Starting clixon_snmp"
|
|
||||||
start_snmp $cfg &
|
|
||||||
|
|
||||||
# Wait for things to settle
|
|
||||||
sleep 3
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function testexit(){
|
function testexit(){
|
||||||
|
|
|
||||||
|
|
@ -41,6 +41,7 @@ cat <<EOF > $cfg
|
||||||
<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>
|
||||||
|
<CLICON_SNMP_MIB>NET-SNMP-EXAMPLES-MIB</CLICON_SNMP_MIB>
|
||||||
</clixon-config>
|
</clixon-config>
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
|
|
@ -57,31 +58,41 @@ EOF
|
||||||
|
|
||||||
function testinit(){
|
function testinit(){
|
||||||
new "test params: -f $cfg"
|
new "test params: -f $cfg"
|
||||||
# Kill old backend and start a new one
|
if [ $BE -ne 0 ]; then
|
||||||
new "kill old backend"
|
# Kill old backend and start a new one
|
||||||
sudo clixon_backend -zf $cfg
|
new "kill old backend"
|
||||||
if [ $? -ne 0 ]; then
|
sudo clixon_backend -zf $cfg
|
||||||
err "Failed to start backend"
|
if [ $? -ne 0 ]; then
|
||||||
|
err "Failed to start backend"
|
||||||
|
fi
|
||||||
|
|
||||||
|
sudo pkill -f clixon_backend
|
||||||
|
|
||||||
|
new "Starting backend"
|
||||||
|
start_backend -s init -f $cfg
|
||||||
|
fi
|
||||||
|
|
||||||
|
new "wait backend"
|
||||||
|
wait_backend
|
||||||
|
|
||||||
|
if [ $CS -ne 0 ]; then
|
||||||
|
# Kill old clixon_snmp, if any
|
||||||
|
new "Terminating any old clixon_snmp processes"
|
||||||
|
sudo killall -q clixon_snmp
|
||||||
|
|
||||||
|
new "Starting clixon_snmp"
|
||||||
|
start_snmp $cfg &
|
||||||
fi
|
fi
|
||||||
|
|
||||||
sudo pkill -f clixon_backend
|
new "wait snmp"
|
||||||
|
wait_snmp
|
||||||
new "Starting backend"
|
|
||||||
start_backend -s init -f $cfg
|
|
||||||
|
|
||||||
# Kill old clixon_snmp, if any
|
|
||||||
new "Terminating any old clixon_snmp processes"
|
|
||||||
sudo killall -q clixon_snmp
|
|
||||||
|
|
||||||
new "Starting clixon_snmp"
|
|
||||||
start_snmp $cfg &
|
|
||||||
|
|
||||||
# Wait for things to settle
|
|
||||||
sleep 3
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function testexit(){
|
function testexit()
|
||||||
stop_snmp
|
{
|
||||||
|
if [ $CS -ne 0 ]; then
|
||||||
|
stop_snmp
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
new "SNMP table tests"
|
new "SNMP table tests"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue