Netconf monitoring statistics frm RFC 6022

This commit is contained in:
Olof hagsand 2023-02-02 16:42:00 +01:00
parent 5da8ce211a
commit 6681eb99d3
13 changed files with 186 additions and 39 deletions

View file

@ -41,6 +41,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <limits.h>
#include <ctype.h>
@ -62,6 +63,7 @@
#include "clixon_netconf_lib.h"
#include "clixon_options.h"
#include "clixon_err.h"
#include "clixon_data.h"
#include "clixon_datastore.h"
#include "clixon_netconf_monitoring.h"
@ -100,8 +102,8 @@ per_datastore(clicon_handle h,
* @param[in] h Clicon handle
* @param[in] yspec Yang spec
* @param[in,out] cb CLIgen buffer
* @retval -1 Error (fatal)
* @retval 0 OK
* @retval -1 Error (fatal)
* @see RFC 6022 Section 2.1.2
*/
static int
@ -131,8 +133,8 @@ netconf_monitoring_datastores(clicon_handle h,
* @param[in] h Clicon handle
* @param[in] yspec Yang spec
* @param[in,out] cb CLIgen buffer
* @retval -1 Error (fatal)
* @retval 0 OK
* @retval -1 Error (fatal)
* @see RFC 6022 Section 2.1.3
*/
static int
@ -182,20 +184,45 @@ netconf_monitoring_schemas(clicon_handle h,
* @param[in] h Clicon handle
* @param[in] yspec Yang spec
* @param[in,out] cb CLIgen buffer
* @retval -1 Error (fatal)
* @retval 0 OK
* @retval -1 Error (fatal)
* @see RFC 6022 Section 2.1.5
* XXX: NYI
*/
static int
netconf_monitoring_statistics(clicon_handle h,
yang_stmt *yspec,
cbuf *cb)
{
int retval = -1;
int retval = -1;
char *str;
cvec *cvv = NULL;
cg_var *cv;
cprintf(cb, "<statistics>");
if (clicon_data_get(h, "netconf-start-time", &str) == 0 &&
str != NULL){
cprintf(cb, "<netconf-start-time>%s</netconf-start-time>", str);
}
if ((cvv = clicon_data_cvec_get(h, "netconf-statistics")) == NULL)
goto ok;
if ((cv = cvec_find(cvv, "in-bad-hellos")) != NULL)
cprintf(cb, "<in-bad-hellos>%u</in-bad-hellos>", cv_uint32_get(cv));
if ((cv = cvec_find(cvv, "in-sessions")) != NULL)
cprintf(cb, "<in-sessions>%u</in-sessions>", cv_uint32_get(cv));
if ((cv = cvec_find(cvv, "dropped-sessions")) != NULL)
cprintf(cb, "<dropped-sessions>%u</dropped-sessions>", cv_uint32_get(cv));
if ((cv = cvec_find(cvv, "in-rpcs")) != NULL)
cprintf(cb, "<in-rpcs>%u</in-rpcs>", cv_uint32_get(cv));
if ((cv = cvec_find(cvv, "in-bad-rpcs")) != NULL)
cprintf(cb, "<in-bad-rpcs>%u</in-bad-rpcs>", cv_uint32_get(cv));
if ((cv = cvec_find(cvv, "out-rpc-errors")) != NULL)
cprintf(cb, "<out-rpc-errors>%u</out-rpc-errors>", cv_uint32_get(cv));
if ((cv = cvec_find(cvv, "out-notifications")) != NULL)
cprintf(cb, "<out-notifications>%u</out-notifications>", cv_uint32_get(cv));
cprintf(cb, "</statistics>");
ok:
retval = 0;
//done:
// done:
return retval;
}
@ -209,9 +236,9 @@ netconf_monitoring_statistics(clicon_handle h,
* @param[in] nsc XML Namespace context for xpath
* @param[in,out] xret Existing XML tree, merge x into this
* @param[out] xerr XML error tree, if retval = 0
* @retval -1 Error (fatal)
* @retval 0 Statedata callback failed, error in xret
* @retval 1 OK
* @retval 0 Statedata callback failed, error in xret
* @retval -1 Error (fatal)
* @see backend_monitoring_state_get
* @see RFC 6022
*/
@ -257,3 +284,92 @@ netconf_monitoring_state_get(clicon_handle h,
retval = 0;
goto done;
}
/*! Add RFC6022 empty counter32 with zero
*
* @param[in] cvv Cligen vector
* @param[in] name Name of new counter
*/
static int
stat_counter_add(cvec *cvv,
char *name)
{
int retval = -1;
cg_var *cv;
if ((cv = cvec_add(cvv, CGV_UINT32)) == NULL){
clicon_err(OE_UNIX, errno, "cvec_add");
goto done;
}
cv_name_set(cv, name);
cv_uint32_set(cv, 0);
retval = 0;
done:
return retval;
}
/*! Init RFC6022 stats
*
* @param[in] h Clicon handle
*/
int
netconf_monitoring_statistics_init(clicon_handle h)
{
int retval = -1;
struct timeval tv;
char timestr[28];
cvec *cvv = NULL;
gettimeofday(&tv, NULL);
if (time2str(tv, timestr, sizeof(timestr)) < 0)
goto done;
clicon_data_set(h, "netconf-start-time", timestr); /* RFC 6022 */
if ((cvv = cvec_new(0)) == NULL){
clicon_err(OE_UNIX, errno, "cvec_new");
goto done;
}
if (clicon_data_cvec_set(h, "netconf-statistics", cvv) < 0)
goto done;
if (stat_counter_add(cvv, "in-bad-hellos") < 0)
goto done;
if (stat_counter_add(cvv, "in-sessions") < 0)
goto done;
if (stat_counter_add(cvv, "dropped-sessions") < 0)
goto done;
if (stat_counter_add(cvv, "in-rpcs") < 0)
goto done;
if (stat_counter_add(cvv, "in-bad-rpcs") < 0)
goto done;
if (stat_counter_add(cvv, "out-rpc-errors") < 0)
goto done;
if (stat_counter_add(cvv, "out-notifications") < 0)
goto done;
retval = 0;
done:
return retval;
}
/*! Increment RFC6022 statistics counter
*
* @param[in] h Clixon handle
* @param[in] name Name of counter
*/
int
netconf_monitoring_counter_inc(clicon_handle h,
char *name)
{
int retval = -1;
cvec *cvv = NULL;
cg_var *cv;
uint32_t u32;
if ((cvv = clicon_data_cvec_get(h, "netconf-statistics")) != NULL){
if ((cv = cvec_find(cvv, name)) != NULL){
u32 = cv_uint32_get(cv);
u32++;
cv_uint32_set(cv, u32);
}
}
retval = 0;
return retval;
}