Change in libosmocore[master]: Aggregate NSVC stats inside the NSE

daniel gerrit-no-reply at lists.osmocom.org
Mon Jul 12 16:37:59 UTC 2021


daniel has submitted this change. ( https://gerrit.osmocom.org/c/libosmocore/+/24907 )

Change subject: Aggregate NSVC stats inside the NSE
......................................................................

Aggregate NSVC stats inside the NSE

Change-Id: Ifa3c85ec52bda14596e9d7a8705baa1fd4ee2010
Related: OS#4998
---
M src/gb/gprs_ns2.c
M src/gb/gprs_ns2_internal.h
M src/gb/gprs_ns2_message.c
M src/gb/gprs_ns2_vc_fsm.c
4 files changed, 45 insertions(+), 13 deletions(-)

Approvals:
  Jenkins Builder: Verified
  laforge: Looks good to me, but someone else must approve
  pespin: Looks good to me, but someone else must approve
  lynxis lazus: Looks good to me, approved



diff --git a/src/gb/gprs_ns2.c b/src/gb/gprs_ns2.c
index 3eb59e5..fb2965a 100644
--- a/src/gb/gprs_ns2.c
+++ b/src/gb/gprs_ns2.c
@@ -159,7 +159,7 @@
 	{ 0, NULL }
 };
 
-static const struct rate_ctr_desc nsvc_ctr_description[] = {
+static const struct rate_ctr_desc ns_ctr_description[] = {
 	[NS_CTR_PKTS_IN]	= { "packets:in", 	"Packets at NS Level  ( In)" },
 	[NS_CTR_PKTS_OUT] 	= { "packets:out",	"Packets at NS Level  (Out)" },
 	[NS_CTR_PKTS_OUT_DROP] 	= { "packets:out:drop",	"Dropped Packets      (Out)" },
@@ -177,11 +177,19 @@
 	[NS_CTR_LOST_RESET]	= { "lost:reset",	"RESET ACK missing count   " },
 };
 
+static const struct rate_ctr_group_desc nse_ctrg_desc = {
+	.group_name_prefix = "ns:nse",
+	.group_description = "NSE Peer Statistics",
+	.num_ctr = ARRAY_SIZE(ns_ctr_description),
+	.ctr_desc = ns_ctr_description,
+	.class_id = OSMO_STATS_CLASS_PEER,
+};
+
 static const struct rate_ctr_group_desc nsvc_ctrg_desc = {
 	.group_name_prefix = "ns:nsvc",
 	.group_description = "NSVC Peer Statistics",
-	.num_ctr = ARRAY_SIZE(nsvc_ctr_description),
-	.ctr_desc = nsvc_ctr_description,
+	.num_ctr = ARRAY_SIZE(ns_ctr_description),
+	.ctr_desc = ns_ctr_description,
 	.class_id = OSMO_STATS_CLASS_PEER,
 };
 
@@ -806,6 +814,12 @@
 		return NULL;
 	}
 
+	nse->ctrg = rate_ctr_group_alloc(nse, &nse_ctrg_desc, nsei);
+	if (!nse->ctrg) {
+		talloc_free(nse);
+		return NULL;
+	}
+
 	nse->ll = linklayer;
 	nse->nsei = nsei;
 	nse->nsi = nsi;
@@ -886,6 +900,7 @@
 
 	gprs_ns2_free_nsvcs(nse);
 	ns2_prim_status_ind(nse, NULL, 0, GPRS_NS2_AFF_CAUSE_FAILURE);
+	rate_ctr_group_free(nse->ctrg);
 
 	llist_del(&nse->list);
 	talloc_free(nse);
@@ -1265,8 +1280,8 @@
 	log_set_context(LOG_CTX_GB_NSE, nsvc->nse);
 	log_set_context(LOG_CTX_GB_NSVC, nsvc);
 
-	rate_ctr_inc(rate_ctr_group_get_ctr(nsvc->ctrg, NS_CTR_PKTS_IN));
-	rate_ctr_add(rate_ctr_group_get_ctr(nsvc->ctrg, NS_CTR_BYTES_IN), msg->len);
+	RATE_CTR_INC_NS(nsvc, NS_CTR_PKTS_IN);
+	RATE_CTR_ADD_NS(nsvc, NS_CTR_BYTES_IN, msg->len);
 
 	if (msg->len < sizeof(struct gprs_ns_hdr)) {
 		rc = -EINVAL;
diff --git a/src/gb/gprs_ns2_internal.h b/src/gb/gprs_ns2_internal.h
index 70e212a..db01c2e 100644
--- a/src/gb/gprs_ns2_internal.h
+++ b/src/gb/gprs_ns2_internal.h
@@ -38,6 +38,20 @@
 #define LOG_NS_RX_SIGNAL(nsvc, pdu_type) LOG_NS_SIGNAL(nsvc, "Rx", pdu_type, LOGL_INFO, "\n")
 #define LOG_NS_TX_SIGNAL(nsvc, pdu_type) LOG_NS_SIGNAL(nsvc, "Tx", pdu_type, LOGL_INFO, "\n")
 
+#define RATE_CTR_INC_NS(nsvc, ctr) \
+	do { \
+		struct gprs_ns2_vc *_nsvc = (nsvc); \
+		rate_ctr_inc(rate_ctr_group_get_ctr(_nsvc->ctrg, ctr)); \
+		rate_ctr_inc(rate_ctr_group_get_ctr(_nsvc->nse->ctrg, ctr)); \
+	} while (0)
+
+#define RATE_CTR_ADD_NS(nsvc, ctr, val) \
+	do { \
+		struct gprs_ns2_vc *_nsvc = (nsvc); \
+		rate_ctr_add(rate_ctr_group_get_ctr(_nsvc->ctrg, ctr), val); \
+		rate_ctr_add(rate_ctr_group_get_ctr(_nsvc->nse->ctrg, ctr), val); \
+	} while (0)
+
 
 struct osmo_fsm_inst;
 struct tlv_parsed;
@@ -198,6 +212,9 @@
 
 	/*! are we implementing the SGSN role? */
 	bool ip_sns_role_sgsn;
+
+	/*! NSE-wide statistics */
+	struct rate_ctr_group *ctrg;
 };
 
 /*! Structure representing a single NS-VC */
diff --git a/src/gb/gprs_ns2_message.c b/src/gb/gprs_ns2_message.c
index 03e26bd..dccf51d 100644
--- a/src/gb/gprs_ns2_message.c
+++ b/src/gb/gprs_ns2_message.c
@@ -174,11 +174,11 @@
 
 	rc = nsvc->bind->send_vc(nsvc, msg);
 	if (rc < 0) {
-		rate_ctr_inc(rate_ctr_group_get_ctr(nsvc->ctrg, NS_CTR_PKTS_OUT_DROP));
-		rate_ctr_add(rate_ctr_group_get_ctr(nsvc->ctrg, NS_CTR_BYTES_OUT_DROP), bytes);
+		RATE_CTR_INC_NS(nsvc, NS_CTR_PKTS_OUT_DROP);
+		RATE_CTR_ADD_NS(nsvc, NS_CTR_BYTES_OUT_DROP, bytes);
 	} else {
-		rate_ctr_inc(rate_ctr_group_get_ctr(nsvc->ctrg, NS_CTR_PKTS_OUT));
-		rate_ctr_add(rate_ctr_group_get_ctr(nsvc->ctrg, NS_CTR_BYTES_OUT), bytes);
+		RATE_CTR_INC_NS(nsvc, NS_CTR_PKTS_OUT);
+		RATE_CTR_ADD_NS(nsvc, NS_CTR_BYTES_OUT, bytes);
 	}
 
 	return rc;
diff --git a/src/gb/gprs_ns2_vc_fsm.c b/src/gb/gprs_ns2_vc_fsm.c
index 05118b2..4dc0536 100644
--- a/src/gb/gprs_ns2_vc_fsm.c
+++ b/src/gb/gprs_ns2_vc_fsm.c
@@ -230,7 +230,7 @@
 		osmo_timer_schedule(&priv->alive.timer, nsi->timeout[NS_TOUT_TNS_ALIVE], 0);
 		break;
 	case NS_TOUT_TNS_ALIVE:
-		rate_ctr_inc(rate_ctr_group_get_ctr(priv->nsvc->ctrg, NS_CTR_LOST_ALIVE));
+		RATE_CTR_INC_NS(priv->nsvc, NS_CTR_LOST_ALIVE);
 		priv->alive.N++;
 
 		if (priv->alive.N <= nsi->timeout[NS_TOUT_TNS_ALIVE_RETRIES]) {
@@ -336,7 +336,7 @@
 
 	if (old_state != GPRS_NS2_ST_BLOCKED) {
 		priv->N = 0;
-		rate_ctr_inc(rate_ctr_group_get_ctr(priv->nsvc->ctrg, NS_CTR_BLOCKED));
+		RATE_CTR_INC_NS(priv->nsvc, NS_CTR_BLOCKED);
 	}
 
 	ns2_nse_notify_unblocked(priv->nsvc, false);
@@ -412,7 +412,7 @@
 	struct gprs_ns2_nse *nse = nsvc->nse;
 
 	if (old_state != GPRS_NS2_ST_UNBLOCKED)
-		rate_ctr_inc(rate_ctr_group_get_ctr(nsvc->ctrg, NS_CTR_UNBLOCKED));
+		RATE_CTR_INC_NS(nsvc, NS_CTR_UNBLOCKED);
 
 	priv->accept_unitdata = true;
 	ns2_nse_notify_unblocked(nsvc, true);
@@ -527,7 +527,7 @@
 	switch (fi->state) {
 	case GPRS_NS2_ST_RESET:
 		if (priv->initiate_reset) {
-			rate_ctr_inc(rate_ctr_group_get_ctr(priv->nsvc->ctrg, NS_CTR_LOST_RESET));
+			RATE_CTR_INC_NS(priv->nsvc, NS_CTR_LOST_RESET);
 			priv->N++;
 			if (priv->N <= nsi->timeout[NS_TOUT_TNS_RESET_RETRIES]) {
 				osmo_fsm_inst_state_chg(fi, GPRS_NS2_ST_RESET, nsi->timeout[NS_TOUT_TNS_RESET], 0);

-- 
To view, visit https://gerrit.osmocom.org/c/libosmocore/+/24907
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: Ifa3c85ec52bda14596e9d7a8705baa1fd4ee2010
Gerrit-Change-Number: 24907
Gerrit-PatchSet: 1
Gerrit-Owner: daniel <dwillmann at sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: daniel <dwillmann at sysmocom.de>
Gerrit-Reviewer: laforge <laforge at osmocom.org>
Gerrit-Reviewer: lynxis lazus <lynxis at fe80.eu>
Gerrit-Reviewer: pespin <pespin at sysmocom.de>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20210712/7060fd0f/attachment.htm>


More information about the gerrit-log mailing list