ns2: Introduce a per-bind stat_item group with backlog length
The backlog length indicates the instantaneous length of the backlog.
Change-Id: I1c55b4619b1221d7e607ace58649323407faf86b
diff --git a/src/gb/gprs_ns2.c b/src/gb/gprs_ns2.c
index 9c9da79..1f7525e 100644
--- a/src/gb/gprs_ns2.c
+++ b/src/gb/gprs_ns2.c
@@ -198,6 +198,18 @@
.class_id = OSMO_STATS_CLASS_PEER,
};
+const struct osmo_stat_item_desc nsbind_stat_description[] = {
+ [NS2_BIND_STAT_BACKLOG_LEN] = { "tx_backlog_length", "Transmit backlog length", "packets", 16, 0 },
+};
+
+static const struct osmo_stat_item_group_desc nsbind_statg_desc = {
+ .group_name_prefix = "ns.bind",
+ .group_description = "NS Bind Statistics",
+ .num_items = ARRAY_SIZE(nsbind_stat_description),
+ .item_desc = nsbind_stat_description,
+ .class_id = OSMO_STATS_CLASS_PEER,
+};
+
const struct value_string gprs_ns2_aff_cause_prim_strs[] = {
{ GPRS_NS2_AFF_CAUSE_VC_FAILURE, "NSVC failure" },
{ GPRS_NS2_AFF_CAUSE_VC_RECOVERY, "NSVC recovery" },
@@ -1245,6 +1257,7 @@
bind->driver->free_bind(bind);
llist_del(&bind->list);
+ osmo_stat_item_group_free(bind->statg);
talloc_free((char *)bind->name);
talloc_free(bind);
}
@@ -1375,10 +1388,18 @@
return -ENOMEM;
}
+ bind->statg = osmo_stat_item_group_alloc(bind, &nsbind_statg_desc, nsi->bind_rate_ctr_idx);
+ if (!bind->statg) {
+ talloc_free(bind);
+ return -ENOMEM;
+ }
+
bind->nsi = nsi;
INIT_LLIST_HEAD(&bind->nsvc);
llist_add(&bind->list, &nsi->binding);
+ nsi->bind_rate_ctr_idx++;
+
if (result)
*result = bind;
diff --git a/src/gb/gprs_ns2_fr.c b/src/gb/gprs_ns2_fr.c
index c32bce8..49e92ae 100644
--- a/src/gb/gprs_ns2_fr.c
+++ b/src/gb/gprs_ns2_fr.c
@@ -47,6 +47,7 @@
#include <osmocom/gprs/frame_relay.h>
#include <osmocom/core/byteswap.h>
+#include <osmocom/core/stat_item.h>
#include <osmocom/core/logging.h>
#include <osmocom/core/msgb.h>
#include <osmocom/core/select.h>
@@ -327,6 +328,7 @@
{
struct priv_bind *priv = bind->priv;
llist_add(&msg->list, &priv->backlog.list);
+ osmo_stat_item_inc(bind->statg->items[NS2_BIND_STAT_BACKLOG_LEN], 1);
osmo_timer_schedule(&priv->backlog.timer, 0, priv->backlog.retry_us);
}
@@ -334,6 +336,7 @@
{
struct priv_bind *priv = bind->priv;
llist_add_tail(&msg->list, &priv->backlog.list);
+ osmo_stat_item_inc(bind->statg->items[NS2_BIND_STAT_BACKLOG_LEN], 1);
osmo_timer_schedule(&priv->backlog.timer, 0, priv->backlog.retry_us);
}
@@ -402,6 +405,7 @@
llist_add(&msg->list, &priv->backlog.list);
break;
}
+ osmo_stat_item_dec(bind->statg->items[NS2_BIND_STAT_BACKLOG_LEN], 1);
}
/* re-start timer if we still have data in the queue */
diff --git a/src/gb/gprs_ns2_internal.h b/src/gb/gprs_ns2_internal.h
index f3c68f5..6462907 100644
--- a/src/gb/gprs_ns2_internal.h
+++ b/src/gb/gprs_ns2_internal.h
@@ -72,10 +72,14 @@
_NSVC_TIMER_NR,
};
-enum ns_stat {
+enum ns2_vc_stat {
NS_STAT_ALIVE_DELAY,
};
+enum ns2_bind_stat {
+ NS2_BIND_STAT_BACKLOG_LEN,
+};
+
/*! Osmocom NS2 VC create status */
enum ns2_cs {
NS2_CS_CREATED, /*!< A NSVC object has been created */
@@ -129,6 +133,7 @@
/*! workaround for rate counter until rate counter accepts char str as index */
uint32_t nsvc_rate_ctr_idx;
+ uint32_t bind_rate_ctr_idx;
/*! libmnl netlink socket for link state monitoring */
struct osmo_mnl *linkmon_mnl;
@@ -251,6 +256,8 @@
/*! allow to show information for the vty */
void (*dump_vty)(const struct gprs_ns2_vc_bind *bind,
struct vty *vty, bool stats);
+
+ struct osmo_stat_item_group *statg;
};
struct gprs_ns2_vc_driver {
diff --git a/src/gb/gprs_ns2_vty.c b/src/gb/gprs_ns2_vty.c
index c2b9bd9..5d0f5c0 100644
--- a/src/gb/gprs_ns2_vty.c
+++ b/src/gb/gprs_ns2_vty.c
@@ -1374,6 +1374,10 @@
{
if (bind->dump_vty)
bind->dump_vty(bind, vty, stats);
+
+ if (stats) {
+ vty_out_stat_item_group(vty, " ", bind->statg);
+ }
}
static void dump_ns_bind(struct vty *vty, const struct gprs_ns2_inst *nsi, bool stats)