Change in osmo-mgw[master]: Use new stat item/ctr getter APIs

pespin gerrit-no-reply at lists.osmocom.org
Fri Jun 4 15:58:08 UTC 2021


pespin has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmo-mgw/+/24554 )


Change subject: Use new stat item/ctr getter APIs
......................................................................

Use new stat item/ctr getter APIs

Generated with spatch with this and similat snippets:
"""
@@
expression E1, E2;
@@
- &E2->ctr[E1]
+ rate_c

Change-Id: I53b75ea8a88bc1ae4ceb479ed272865054de9665
---
M src/libosmo-mgcp/mgcp_conn.c
M src/libosmo-mgcp/mgcp_e1.c
M src/libosmo-mgcp/mgcp_network.c
M src/libosmo-mgcp/mgcp_protocol.c
M src/libosmo-mgcp/mgcp_stat.c
M src/libosmo-mgcp/mgcp_vty.c
M tests/mgcp/mgcp_test.c
7 files changed, 79 insertions(+), 79 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/osmo-mgw refs/changes/54/24554/1

diff --git a/src/libosmo-mgcp/mgcp_conn.c b/src/libosmo-mgcp/mgcp_conn.c
index 6424dcb..7988c48 100644
--- a/src/libosmo-mgcp/mgcp_conn.c
+++ b/src/libosmo-mgcp/mgcp_conn.c
@@ -114,8 +114,8 @@
 	if (!conn_rtp->rate_ctr_group)
 		return -1;
 
-	conn_rtp->state.in_stream.err_ts_ctr = &conn_rtp->rate_ctr_group->ctr[IN_STREAM_ERR_TSTMP_CTR];
-	conn_rtp->state.out_stream.err_ts_ctr = &conn_rtp->rate_ctr_group->ctr[OUT_STREAM_ERR_TSTMP_CTR];
+	conn_rtp->state.in_stream.err_ts_ctr = rate_ctr_group_get_ctr(conn_rtp->rate_ctr_group, IN_STREAM_ERR_TSTMP_CTR);
+	conn_rtp->state.out_stream.err_ts_ctr = rate_ctr_group_get_ctr(conn_rtp->rate_ctr_group, OUT_STREAM_ERR_TSTMP_CTR);
 	rate_ctr_index++;
 
 	/* Make sure codec table is reset */
@@ -270,12 +270,12 @@
 	OSMO_ASSERT(conn_stats->desc->num_ctr + 1 == all_stats->desc->num_ctr);
 
 	/* all other counters are [now] updated in real-time */
-	rate_ctr_add(&all_stats->ctr[IN_STREAM_ERR_TSTMP_CTR],
-		     conn_stats->ctr[IN_STREAM_ERR_TSTMP_CTR].current);
-	rate_ctr_add(&all_stats->ctr[OUT_STREAM_ERR_TSTMP_CTR],
-		     conn_stats->ctr[OUT_STREAM_ERR_TSTMP_CTR].current);
+	rate_ctr_add(rate_ctr_group_get_ctr(all_stats, IN_STREAM_ERR_TSTMP_CTR),
+		     rate_ctr_group_get_ctr(conn_stats, IN_STREAM_ERR_TSTMP_CTR)->current);
+	rate_ctr_add(rate_ctr_group_get_ctr(all_stats, OUT_STREAM_ERR_TSTMP_CTR),
+		     rate_ctr_group_get_ctr(conn_stats, OUT_STREAM_ERR_TSTMP_CTR)->current);
 
-	rate_ctr_inc(&all_stats->ctr[RTP_NUM_CONNECTIONS]);
+	rate_ctr_inc(rate_ctr_group_get_ctr(all_stats, RTP_NUM_CONNECTIONS));
 }
 
 /*! free a connection by its ID.
diff --git a/src/libosmo-mgcp/mgcp_e1.c b/src/libosmo-mgcp/mgcp_e1.c
index 7e810bc..effbe77 100644
--- a/src/libosmo-mgcp/mgcp_e1.c
+++ b/src/libosmo-mgcp/mgcp_e1.c
@@ -197,7 +197,7 @@
 	const uint8_t *ptr_ft;
 	enum osmo_trau_frame_type ft;
 
-	rate_ctr_inc(&rate_ctrs->ctr[E1_I460_TRAU_MUX_EMPTY_CTR]);
+	rate_ctr_inc(rate_ctr_group_get_ctr(rate_ctrs, E1_I460_TRAU_MUX_EMPTY_CTR));
 
 	/* Choose an appropiate idle frame type */
 	ft = endp->e1.trau_rtp_st->type;
@@ -304,7 +304,7 @@
 	msgb_free(msg);
 	return;
 skip:
-	rate_ctr_inc(&rate_ctrs->ctr[E1_I460_TRAU_RX_FAIL_CTR]);
+	rate_ctr_inc(rate_ctr_group_get_ctr(rate_ctrs, E1_I460_TRAU_RX_FAIL_CTR));
 	msgb_free(msg);
 	return;
 }
@@ -679,7 +679,7 @@
 
 	return 0;
 skip:
-	rate_ctr_inc(&rate_ctrs->ctr[E1_I460_TRAU_TX_FAIL_CTR]);
+	rate_ctr_inc(rate_ctr_group_get_ctr(rate_ctrs, E1_I460_TRAU_TX_FAIL_CTR));
 	msgb_free(msg_tf);
 	return -1;
 }
diff --git a/src/libosmo-mgcp/mgcp_network.c b/src/libosmo-mgcp/mgcp_network.c
index e03c100..79ddf8a 100644
--- a/src/libosmo-mgcp/mgcp_network.c
+++ b/src/libosmo-mgcp/mgcp_network.c
@@ -66,8 +66,8 @@
 	struct rate_ctr_group *mgw_stats = endp->trunk->ratectr.all_rtp_conn_stats;
 
 	/* add to both the per-connection and the global stats */
-	rate_ctr_add(&conn_stats->ctr[id], inc);
-	rate_ctr_add(&mgw_stats->ctr[id], inc);
+	rate_ctr_add(rate_ctr_group_get_ctr(conn_stats, id), inc);
+	rate_ctr_add(rate_ctr_group_get_ctr(mgw_stats, id), inc);
 }
 
 static void rtpconn_rate_ctr_inc(struct mgcp_conn_rtp *conn_rtp, struct mgcp_endpoint *endp, int id)
@@ -1475,8 +1475,8 @@
 					sizeof(struct sockaddr_in)));
 
 	/* Increment RX statistics */
-	rate_ctr_inc(&conn_src->rate_ctr_group->ctr[RTP_PACKETS_RX_CTR]);
-	rate_ctr_add(&conn_src->rate_ctr_group->ctr[RTP_OCTETS_RX_CTR], msgb_length(msg));
+	rate_ctr_inc(rate_ctr_group_get_ctr(conn_src->rate_ctr_group, RTP_PACKETS_RX_CTR));
+	rate_ctr_add(rate_ctr_group_get_ctr(conn_src->rate_ctr_group, RTP_OCTETS_RX_CTR), msgb_length(msg));
 	/* FIXME: count RTP and RTCP separately, also count IuUP payload-less separately */
 
 	/* Forward a copy of the RTP data to a debug ip/port */
diff --git a/src/libosmo-mgcp/mgcp_protocol.c b/src/libosmo-mgcp/mgcp_protocol.c
index 902c079..3014048 100644
--- a/src/libosmo-mgcp/mgcp_protocol.c
+++ b/src/libosmo-mgcp/mgcp_protocol.c
@@ -289,16 +289,16 @@
 	char *data;
 
 	/* Count all messages, even incorect ones */
-	rate_ctr_inc(&rate_ctrs->ctr[MGCP_GENERAL_RX_MSGS_TOTAL]);
+	rate_ctr_inc(rate_ctr_group_get_ctr(rate_ctrs, MGCP_GENERAL_RX_MSGS_TOTAL));
 
 	if (msgb_l2len(msg) < 4) {
 		LOGP(DLMGCP, LOGL_ERROR, "msg too short: %d\n", msg->len);
-		rate_ctr_inc(&rate_ctrs->ctr[MGCP_GENERAL_RX_FAIL_MSG_PARSE]);
+		rate_ctr_inc(rate_ctr_group_get_ctr(rate_ctrs, MGCP_GENERAL_RX_FAIL_MSG_PARSE));
 		return NULL;
 	}
 
 	if (mgcp_msg_terminate_nul(msg)) {
-		rate_ctr_inc(&rate_ctrs->ctr[MGCP_GENERAL_RX_FAIL_MSG_PARSE]);
+		rate_ctr_inc(rate_ctr_group_get_ctr(rate_ctrs, MGCP_GENERAL_RX_FAIL_MSG_PARSE));
 		return NULL;
 	}
 
@@ -307,7 +307,7 @@
 	/* attempt to treat it as a response */
 	if (sscanf((const char *)&msg->l2h[0], "%3d %*s", &code) == 1) {
 		LOGP(DLMGCP, LOGL_DEBUG, "Response: Code: %d\n", code);
-		rate_ctr_inc(&rate_ctrs->ctr[MGCP_GENERAL_RX_FAIL_MSG_PARSE]);
+		rate_ctr_inc(rate_ctr_group_get_ctr(rate_ctrs, MGCP_GENERAL_RX_FAIL_MSG_PARSE));
 		return NULL;
 	}
 
@@ -323,14 +323,14 @@
 	if (pdata.endp && pdata.trans
 	    && pdata.endp->last_trans
 	    && strcmp(pdata.endp->last_trans, pdata.trans) == 0) {
-		rate_ctr_inc(&rate_ctrs->ctr[MGCP_GENERAL_RX_MSGS_RETRANSMITTED]);
+		rate_ctr_inc(rate_ctr_group_get_ctr(rate_ctrs, MGCP_GENERAL_RX_MSGS_RETRANSMITTED));
 		return do_retransmission(pdata.endp);
 	}
 
 	/* check for general parser failure */
 	if (rc < 0) {
 		LOGP(DLMGCP, LOGL_NOTICE, "%s: failed to find the endpoint\n", msg->l2h);
-		rate_ctr_inc(&rate_ctrs->ctr[MGCP_GENERAL_RX_FAIL_NO_ENDPOINT]);
+		rate_ctr_inc(rate_ctr_group_get_ctr(rate_ctrs, MGCP_GENERAL_RX_FAIL_NO_ENDPOINT));
 		return create_err_response(NULL, -rc, (const char *) msg->l2h, pdata.trans);
 	}
 
@@ -345,9 +345,9 @@
 	}
 
 	if (handled) {
-		rate_ctr_inc(&rate_ctrs->ctr[MGCP_GENERAL_RX_MSGS_HANDLED]);
+		rate_ctr_inc(rate_ctr_group_get_ctr(rate_ctrs, MGCP_GENERAL_RX_MSGS_HANDLED));
 	} else {
-		rate_ctr_inc(&rate_ctrs->ctr[MGCP_GENERAL_RX_MSGS_UNHANDLED]);
+		rate_ctr_inc(rate_ctr_group_get_ctr(rate_ctrs, MGCP_GENERAL_RX_MSGS_UNHANDLED));
 		LOGP(DLMGCP, LOGL_NOTICE, "MSG with type: '%.4s' not handled\n",
 		     &msg->l2h[0]);
 	}
@@ -751,7 +751,7 @@
 	LOGPENDP(endp, DLMGCP, LOGL_NOTICE, "CRCX: creating new connection ...\n");
 
 	if (!mgcp_endp_avail(endp)) {
-		rate_ctr_inc(&rate_ctrs->ctr[MGCP_CRCX_FAIL_AVAIL]);
+		rate_ctr_inc(rate_ctr_group_get_ctr(rate_ctrs, MGCP_CRCX_FAIL_AVAIL));
 		LOGPENDP(endp, DLMGCP, LOGL_ERROR,
 			 "CRCX: selected endpoint not available!\n");
 		return create_err_response(NULL, 501, "CRCX", p->trans);
@@ -773,7 +773,7 @@
 			/* It is illegal to send a connection identifier
 			 * together with a CRCX, the MGW will assign the
 			 * connection identifier by itself on CRCX */
-			rate_ctr_inc(&rate_ctrs->ctr[MGCP_CRCX_FAIL_BAD_ACTION]);
+			rate_ctr_inc(rate_ctr_group_get_ctr(rate_ctrs, MGCP_CRCX_FAIL_BAD_ACTION));
 			return create_err_response(NULL, 523, "CRCX", p->trans);
 			break;
 		case 'M':
@@ -799,7 +799,7 @@
 		default:
 			LOGPENDP(endp, DLMGCP, LOGL_NOTICE,
 				 "CRCX: unhandled option: '%c'/%d\n", *line, *line);
-			rate_ctr_inc(&rate_ctrs->ctr[MGCP_CRCX_FAIL_UNHANDLED_PARAM]);
+			rate_ctr_inc(rate_ctr_group_get_ctr(rate_ctrs, MGCP_CRCX_FAIL_UNHANDLED_PARAM));
 			return create_err_response(NULL, 539, "CRCX", p->trans);
 			break;
 		}
@@ -810,14 +810,14 @@
 	if (!callid) {
 		LOGPENDP(endp, DLMGCP, LOGL_ERROR,
 			 "CRCX: insufficient parameters, missing callid\n");
-		rate_ctr_inc(&rate_ctrs->ctr[MGCP_CRCX_FAIL_MISSING_CALLID]);
+		rate_ctr_inc(rate_ctr_group_get_ctr(rate_ctrs, MGCP_CRCX_FAIL_MISSING_CALLID));
 		return create_err_response(endp, 516, "CRCX", p->trans);
 	}
 
 	if (!mode) {
 		LOGPENDP(endp, DLMGCP, LOGL_ERROR,
 			 "CRCX: insufficient parameters, missing mode\n");
-		rate_ctr_inc(&rate_ctrs->ctr[MGCP_CRCX_FAIL_INVALID_MODE]);
+		rate_ctr_inc(rate_ctr_group_get_ctr(rate_ctrs, MGCP_CRCX_FAIL_INVALID_MODE));
 		return create_err_response(endp, 517, "CRCX", p->trans);
 	}
 
@@ -834,7 +834,7 @@
 		} else {
 			/* There is no more room for a connection, leave
 			 * everything as it is and return with an error */
-			rate_ctr_inc(&rate_ctrs->ctr[MGCP_CRCX_FAIL_LIMIT_EXCEEDED]);
+			rate_ctr_inc(rate_ctr_group_get_ctr(rate_ctrs, MGCP_CRCX_FAIL_LIMIT_EXCEEDED));
 			return create_err_response(endp, 540, "CRCX", p->trans);
 		}
 	}
@@ -852,7 +852,7 @@
 		else {
 			/* This is not our call, leave everything as it is and
 			 * return with an error. */
-			rate_ctr_inc(&rate_ctrs->ctr[MGCP_CRCX_FAIL_UNKNOWN_CALLID]);
+			rate_ctr_inc(rate_ctr_group_get_ctr(rate_ctrs, MGCP_CRCX_FAIL_UNKNOWN_CALLID));
 			return create_err_response(endp, 400, "CRCX", p->trans);
 		}
 	}
@@ -863,7 +863,7 @@
 		 * the callid matches up (see above). */
 		rc = mgcp_endp_claim(endp, callid);
 		if (rc != 0) {
-			rate_ctr_inc(&rate_ctrs->ctr[MGCP_CRCX_FAIL_CLAIM]);
+			rate_ctr_inc(rate_ctr_group_get_ctr(rate_ctrs, MGCP_CRCX_FAIL_CLAIM));
 			return create_err_response(endp, 502, "CRCX", p->trans);
 		}
 	}
@@ -873,7 +873,7 @@
 	if (!_conn) {
 		LOGPENDP(endp, DLMGCP, LOGL_ERROR,
 			 "CRCX: unable to allocate RTP connection\n");
-		rate_ctr_inc(&rate_ctrs->ctr[MGCP_CRCX_FAIL_ALLOC_CONN]);
+		rate_ctr_inc(rate_ctr_group_get_ctr(rate_ctrs, MGCP_CRCX_FAIL_ALLOC_CONN));
 		goto error2;
 
 	}
@@ -883,7 +883,7 @@
 
 	if (mgcp_parse_conn_mode(mode, endp, conn->conn) != 0) {
 		error_code = 517;
-		rate_ctr_inc(&rate_ctrs->ctr[MGCP_CRCX_FAIL_INVALID_MODE]);
+		rate_ctr_inc(rate_ctr_group_get_ctr(rate_ctrs, MGCP_CRCX_FAIL_INVALID_MODE));
 		goto error2;
 	}
 
@@ -893,13 +893,13 @@
 	if (osmux_cid >= -1) { /* -1 is wilcard, alloc next avail CID */
 		conn->osmux.state = OSMUX_STATE_ACTIVATING;
 		if (conn_osmux_allocate_cid(conn, osmux_cid) == -1) {
-			rate_ctr_inc(&rate_ctrs->ctr[MGCP_CRCX_FAIL_NO_OSMUX]);
+			rate_ctr_inc(rate_ctr_group_get_ctr(rate_ctrs, MGCP_CRCX_FAIL_NO_OSMUX));
 			goto error2;
 		}
 	} else if (endp->cfg->osmux == OSMUX_USAGE_ONLY) {
 		LOGPCONN(_conn, DLMGCP, LOGL_ERROR,
 			 "CRCX: osmux only and no osmux offered\n");
-		rate_ctr_inc(&rate_ctrs->ctr[MGCP_CRCX_FAIL_NO_OSMUX]);
+		rate_ctr_inc(rate_ctr_group_get_ctr(rate_ctrs, MGCP_CRCX_FAIL_NO_OSMUX));
 		goto error2;
 	}
 
@@ -911,7 +911,7 @@
 			LOGPCONN(_conn, DLMGCP, LOGL_ERROR,
 				 "CRCX: inavlid local connection options!\n");
 			error_code = rc;
-			rate_ctr_inc(&rate_ctrs->ctr[MGCP_CRCX_FAIL_INVALID_CONN_OPTIONS]);
+			rate_ctr_inc(rate_ctr_group_get_ctr(rate_ctrs, MGCP_CRCX_FAIL_INVALID_CONN_OPTIONS));
 			goto error2;
 		}
 	}
@@ -921,7 +921,7 @@
 	mgcp_codec_summary(conn);
 	if (rc) {
 		error_code = rc;
-		rate_ctr_inc(&rate_ctrs->ctr[MGCP_CRCX_FAIL_CODEC_NEGOTIATION]);
+		rate_ctr_inc(rate_ctr_group_get_ctr(rate_ctrs, MGCP_CRCX_FAIL_CODEC_NEGOTIATION));
 		goto error2;
 	}
 
@@ -942,7 +942,7 @@
 		LOGPCONN(_conn, DLMGCP, LOGL_ERROR,
 			 "CRCX: selected connection mode type requires an opposite end!\n");
 		error_code = 527;
-		rate_ctr_inc(&rate_ctrs->ctr[MGCP_CRCX_FAIL_NO_REMOTE_CONN_DESC]);
+		rate_ctr_inc(rate_ctr_group_get_ctr(rate_ctrs, MGCP_CRCX_FAIL_NO_REMOTE_CONN_DESC));
 		goto error2;
 	}
 
@@ -950,14 +950,14 @@
 	   information, then find a free port for it */
 	mgcp_get_local_addr(conn->end.local_addr, conn);
 	if (allocate_port(endp, conn) != 0) {
-		rate_ctr_inc(&rate_ctrs->ctr[MGCP_CRCX_FAIL_BIND_PORT]);
+		rate_ctr_inc(rate_ctr_group_get_ctr(rate_ctrs, MGCP_CRCX_FAIL_BIND_PORT));
 		goto error2;
 	}
 
 	if (setup_rtp_processing(endp, conn) != 0) {
 		LOGPCONN(_conn, DLMGCP, LOGL_ERROR,
 			 "CRCX: could not start RTP processing!\n");
-		rate_ctr_inc(&rate_ctrs->ctr[MGCP_CRCX_FAIL_START_RTP]);
+		rate_ctr_inc(rate_ctr_group_get_ctr(rate_ctrs, MGCP_CRCX_FAIL_START_RTP));
 		goto error2;
 	}
 
@@ -970,7 +970,7 @@
 			LOGPCONN(_conn, DLMGCP, LOGL_NOTICE,
 				 "CRCX: CRCX rejected by policy\n");
 			mgcp_endp_release(endp);
-			rate_ctr_inc(&rate_ctrs->ctr[MGCP_CRCX_FAIL_REJECTED_BY_POLICY]);
+			rate_ctr_inc(rate_ctr_group_get_ctr(rate_ctrs, MGCP_CRCX_FAIL_REJECTED_BY_POLICY));
 			return create_err_response(endp, 400, "CRCX", p->trans);
 			break;
 		case MGCP_POLICY_DEFER:
@@ -996,7 +996,7 @@
 
 	LOGPCONN(_conn, DLMGCP, LOGL_NOTICE,
 		 "CRCX: connection successfully created\n");
-	rate_ctr_inc(&rate_ctrs->ctr[MGCP_CRCX_SUCCESS]);
+	rate_ctr_inc(rate_ctr_group_get_ctr(rate_ctrs, MGCP_CRCX_SUCCESS));
 	mgcp_endp_update(endp);
 	return create_response_with_sdp(endp, conn, "CRCX", p->trans, true);
 error2:
@@ -1026,7 +1026,7 @@
 	LOGPENDP(endp, DLMGCP, LOGL_NOTICE, "MDCX: modifying existing connection ...\n");
 
 	if (!mgcp_endp_avail(endp)) {
-		rate_ctr_inc(&rate_ctrs->ctr[MGCP_MDCX_FAIL_AVAIL]);
+		rate_ctr_inc(rate_ctr_group_get_ctr(rate_ctrs, MGCP_MDCX_FAIL_AVAIL));
 		LOGPENDP(endp, DLMGCP, LOGL_ERROR,
 			 "MDCX: selected endpoint not available!\n");
 		return create_err_response(NULL, 501, "MDCX", p->trans);
@@ -1036,14 +1036,14 @@
 	if (endp->wildcarded_req) {
 		LOGPENDP(endp, DLMGCP, LOGL_ERROR,
 			 "MDCX: wildcarded endpoint names not supported.\n");
-		rate_ctr_inc(&rate_ctrs->ctr[MGCP_MDCX_FAIL_WILDCARD]);
+		rate_ctr_inc(rate_ctr_group_get_ctr(rate_ctrs, MGCP_MDCX_FAIL_WILDCARD));
 		return create_err_response(endp, 507, "MDCX", p->trans);
 	}
 
 	if (llist_count(&endp->conns) <= 0) {
 		LOGPENDP(endp, DLMGCP, LOGL_ERROR,
 			 "MDCX: endpoint is not holding a connection.\n");
-		rate_ctr_inc(&rate_ctrs->ctr[MGCP_MDCX_FAIL_NO_CONN]);
+		rate_ctr_inc(rate_ctr_group_get_ctr(rate_ctrs, MGCP_MDCX_FAIL_NO_CONN));
 		return create_err_response(endp, 400, "MDCX", p->trans);
 	}
 
@@ -1054,7 +1054,7 @@
 		switch (toupper(line[0])) {
 		case 'C':
 			if (mgcp_verify_call_id(endp, line + 3) != 0) {
-				rate_ctr_inc(&rate_ctrs->ctr[MGCP_MDCX_FAIL_INVALID_CALLID]);
+				rate_ctr_inc(rate_ctr_group_get_ctr(rate_ctrs, MGCP_MDCX_FAIL_INVALID_CALLID));
 				error_code = 516;
 				goto error3;
 			}
@@ -1062,7 +1062,7 @@
 		case 'I':
 			conn_id = (const char *)line + 3;
 			if ((error_code = mgcp_verify_ci(endp, conn_id))) {
-				rate_ctr_inc(&rate_ctrs->ctr[MGCP_MDCX_FAIL_INVALID_CONNID]);
+				rate_ctr_inc(rate_ctr_group_get_ctr(rate_ctrs, MGCP_MDCX_FAIL_INVALID_CONNID));
 				goto error3;
 			}
 			break;
@@ -1093,7 +1093,7 @@
 			LOGPENDP(endp, DLMGCP, LOGL_NOTICE,
 				 "MDCX: Unhandled MGCP option: '%c'/%d\n",
 				 line[0], line[0]);
-			rate_ctr_inc(&rate_ctrs->ctr[MGCP_MDCX_FAIL_UNHANDLED_PARAM]);
+			rate_ctr_inc(rate_ctr_group_get_ctr(rate_ctrs, MGCP_MDCX_FAIL_UNHANDLED_PARAM));
 			return create_err_response(NULL, 539, "MDCX", p->trans);
 			break;
 		}
@@ -1103,13 +1103,13 @@
 	if (!conn_id) {
 		LOGPENDP(endp, DLMGCP, LOGL_ERROR,
 			 "MDCX: insufficient parameters, missing ci (connectionIdentifier)\n");
-		rate_ctr_inc(&rate_ctrs->ctr[MGCP_MDCX_FAIL_NO_CONNID]);
+		rate_ctr_inc(rate_ctr_group_get_ctr(rate_ctrs, MGCP_MDCX_FAIL_NO_CONNID));
 		return create_err_response(endp, 515, "MDCX", p->trans);
 	}
 
 	conn = mgcp_conn_get_rtp(endp, conn_id);
 	if (!conn) {
-		rate_ctr_inc(&rate_ctrs->ctr[MGCP_MDCX_FAIL_CONN_NOT_FOUND]);
+		rate_ctr_inc(rate_ctr_group_get_ctr(rate_ctrs, MGCP_MDCX_FAIL_CONN_NOT_FOUND));
 		return create_err_response(endp, 400, "MDCX", p->trans);
 	}
 
@@ -1117,7 +1117,7 @@
 
 	if (mode) {
 		if (mgcp_parse_conn_mode(mode, endp, conn->conn) != 0) {
-			rate_ctr_inc(&rate_ctrs->ctr[MGCP_MDCX_FAIL_INVALID_MODE]);
+			rate_ctr_inc(rate_ctr_group_get_ctr(rate_ctrs, MGCP_MDCX_FAIL_INVALID_MODE));
 			error_code = 517;
 			goto error3;
 		}
@@ -1132,7 +1132,7 @@
 			LOGPCONN(conn->conn, DLMGCP, LOGL_ERROR,
 				 "MDCX: invalid local connection options!\n");
 			error_code = rc;
-			rate_ctr_inc(&rate_ctrs->ctr[MGCP_MDCX_FAIL_INVALID_CONN_OPTIONS]);
+			rate_ctr_inc(rate_ctr_group_get_ctr(rate_ctrs, MGCP_MDCX_FAIL_INVALID_CONN_OPTIONS));
 			goto error3;
 		}
 	}
@@ -1152,7 +1152,7 @@
 		LOGPCONN(conn->conn, DLMGCP, LOGL_ERROR,
 			 "MDCX: selected connection mode type requires an opposite end!\n");
 		error_code = 527;
-		rate_ctr_inc(&rate_ctrs->ctr[MGCP_MDCX_FAIL_NO_REMOTE_CONN_DESC]);
+		rate_ctr_inc(rate_ctr_group_get_ctr(rate_ctrs, MGCP_MDCX_FAIL_NO_REMOTE_CONN_DESC));
 		goto error3;
 	}
 
@@ -1185,13 +1185,13 @@
 		osmo_strlcpy(conn->end.local_addr, new_local_addr, sizeof(conn->end.local_addr));
 		mgcp_free_rtp_port(&conn->end);
 		if (allocate_port(endp, conn) != 0) {
-			rate_ctr_inc(&rate_ctrs->ctr[MGCP_CRCX_FAIL_BIND_PORT]);
+			rate_ctr_inc(rate_ctr_group_get_ctr(rate_ctrs, MGCP_CRCX_FAIL_BIND_PORT));
 			goto error3;
 		}
 	}
 
 	if (setup_rtp_processing(endp, conn) != 0) {
-		rate_ctr_inc(&rate_ctrs->ctr[MGCP_MDCX_FAIL_START_RTP]);
+		rate_ctr_inc(rate_ctr_group_get_ctr(rate_ctrs, MGCP_MDCX_FAIL_START_RTP));
 		goto error3;
 	}
 
@@ -1204,7 +1204,7 @@
 		case MGCP_POLICY_REJECT:
 			LOGPCONN(conn->conn, DLMGCP, LOGL_NOTICE,
 				 "MDCX: rejected by policy\n");
-			rate_ctr_inc(&rate_ctrs->ctr[MGCP_MDCX_FAIL_REJECTED_BY_POLICY]);
+			rate_ctr_inc(rate_ctr_group_get_ctr(rate_ctrs, MGCP_MDCX_FAIL_REJECTED_BY_POLICY));
 			if (silent)
 				goto out_silent;
 			return create_err_response(endp, 400, "MDCX", p->trans);
@@ -1213,7 +1213,7 @@
 			/* stop processing */
 			LOGPCONN(conn->conn, DLMGCP, LOGL_DEBUG,
 				 "MDCX: deferred by policy\n");
-			rate_ctr_inc(&rate_ctrs->ctr[MGCP_MDCX_DEFERRED_BY_POLICY]);
+			rate_ctr_inc(rate_ctr_group_get_ctr(rate_ctrs, MGCP_MDCX_DEFERRED_BY_POLICY));
 			return NULL;
 			break;
 		case MGCP_POLICY_CONT:
@@ -1236,7 +1236,7 @@
 	    && endp->trunk->keepalive_interval != MGCP_KEEPALIVE_NEVER)
 		send_dummy(endp, conn);
 
-	rate_ctr_inc(&rate_ctrs->ctr[MGCP_MDCX_SUCCESS]);
+	rate_ctr_inc(rate_ctr_group_get_ctr(rate_ctrs, MGCP_MDCX_SUCCESS));
 	if (silent)
 		goto out_silent;
 
@@ -1268,7 +1268,7 @@
 		 "DLCX: deleting connection ...\n");
 
 	if (!mgcp_endp_avail(endp)) {
-		rate_ctr_inc(&rate_ctrs->ctr[MGCP_DLCX_FAIL_AVAIL]);
+		rate_ctr_inc(rate_ctr_group_get_ctr(rate_ctrs, MGCP_DLCX_FAIL_AVAIL));
 		LOGPENDP(endp, DLMGCP, LOGL_ERROR,
 			 "DLCX: selected endpoint not available!\n");
 		return create_err_response(NULL, 501, "DLCX", p->trans);
@@ -1278,14 +1278,14 @@
 	if (endp->wildcarded_req) {
 		LOGPENDP(endp, DLMGCP, LOGL_ERROR,
 			 "DLCX: wildcarded endpoint names not supported.\n");
-		rate_ctr_inc(&rate_ctrs->ctr[MGCP_DLCX_FAIL_WILDCARD]);
+		rate_ctr_inc(rate_ctr_group_get_ctr(rate_ctrs, MGCP_DLCX_FAIL_WILDCARD));
 		return create_err_response(endp, 507, "DLCX", p->trans);
 	}
 
 	if (llist_count(&endp->conns) <= 0) {
 		LOGPENDP(endp, DLMGCP, LOGL_ERROR,
 			 "DLCX: endpoint is not holding a connection.\n");
-		rate_ctr_inc(&rate_ctrs->ctr[MGCP_DLCX_FAIL_NO_CONN]);
+		rate_ctr_inc(rate_ctr_group_get_ctr(rate_ctrs, MGCP_DLCX_FAIL_NO_CONN));
 		return create_err_response(endp, 515, "DLCX", p->trans);
 	}
 
@@ -1297,14 +1297,14 @@
 		case 'C':
 			if (mgcp_verify_call_id(endp, line + 3) != 0) {
 				error_code = 516;
-				rate_ctr_inc(&rate_ctrs->ctr[MGCP_DLCX_FAIL_INVALID_CALLID]);
+				rate_ctr_inc(rate_ctr_group_get_ctr(rate_ctrs, MGCP_DLCX_FAIL_INVALID_CALLID));
 				goto error3;
 			}
 			break;
 		case 'I':
 			conn_id = (const char *)line + 3;
 			if ((error_code = mgcp_verify_ci(endp, conn_id))) {
-				rate_ctr_inc(&rate_ctrs->ctr[MGCP_DLCX_FAIL_INVALID_CONNID]);
+				rate_ctr_inc(rate_ctr_group_get_ctr(rate_ctrs, MGCP_DLCX_FAIL_INVALID_CONNID));
 				goto error3;
 			}
 			break;
@@ -1315,7 +1315,7 @@
 			LOGPENDP(endp, DLMGCP, LOGL_NOTICE,
 				 "DLCX: Unhandled MGCP option: '%c'/%d\n",
 				 line[0], line[0]);
-			rate_ctr_inc(&rate_ctrs->ctr[MGCP_DLCX_FAIL_UNHANDLED_PARAM]);
+			rate_ctr_inc(rate_ctr_group_get_ctr(rate_ctrs, MGCP_DLCX_FAIL_UNHANDLED_PARAM));
 			return create_err_response(NULL, 539, "DLCX", p->trans);
 			break;
 		}
@@ -1328,14 +1328,14 @@
 		switch (rc) {
 		case MGCP_POLICY_REJECT:
 			LOGPENDP(endp, DLMGCP, LOGL_NOTICE, "DLCX: rejected by policy\n");
-			rate_ctr_inc(&rate_ctrs->ctr[MGCP_DLCX_FAIL_REJECTED_BY_POLICY]);
+			rate_ctr_inc(rate_ctr_group_get_ctr(rate_ctrs, MGCP_DLCX_FAIL_REJECTED_BY_POLICY));
 			if (silent)
 				goto out_silent;
 			return create_err_response(endp, 400, "DLCX", p->trans);
 			break;
 		case MGCP_POLICY_DEFER:
 			/* stop processing */
-			rate_ctr_inc(&rate_ctrs->ctr[MGCP_DLCX_DEFERRED_BY_POLICY]);
+			rate_ctr_inc(rate_ctr_group_get_ctr(rate_ctrs, MGCP_DLCX_DEFERRED_BY_POLICY));
 			return NULL;
 			break;
 		case MGCP_POLICY_CONT:
@@ -1354,7 +1354,7 @@
 			 num_conns);
 
 		if (num_conns > 0)
-			rate_ctr_add(&rate_ctrs->ctr[MGCP_DLCX_SUCCESS], num_conns);
+			rate_ctr_add(rate_ctr_group_get_ctr(rate_ctrs, MGCP_DLCX_SUCCESS), num_conns);
 
 		mgcp_endp_release(endp);
 
@@ -1367,7 +1367,7 @@
 	/* Find the connection */
 	conn = mgcp_conn_get_rtp(endp, conn_id);
 	if (!conn) {
-		rate_ctr_inc(&rate_ctrs->ctr[MGCP_DLCX_FAIL_INVALID_CONNID]);
+		rate_ctr_inc(rate_ctr_group_get_ctr(rate_ctrs, MGCP_DLCX_FAIL_INVALID_CONNID));
 		goto error3;
 	}
 	/* save the statistics of the current connection */
@@ -1390,7 +1390,7 @@
 	if (p->cfg->change_cb)
 		p->cfg->change_cb(endp, MGCP_ENDP_DLCX);
 
-	rate_ctr_inc(&rate_ctrs->ctr[MGCP_DLCX_SUCCESS]);
+	rate_ctr_inc(rate_ctr_group_get_ctr(rate_ctrs, MGCP_DLCX_SUCCESS));
 	if (silent)
 		goto out_silent;
 	return create_ok_resp_with_param(endp, 250, "DLCX", p->trans, stats);
diff --git a/src/libosmo-mgcp/mgcp_stat.c b/src/libosmo-mgcp/mgcp_stat.c
index 2e74238..89891b5 100644
--- a/src/libosmo-mgcp/mgcp_stat.c
+++ b/src/libosmo-mgcp/mgcp_stat.c
@@ -33,7 +33,7 @@
 void calc_loss(struct mgcp_conn_rtp *conn, uint32_t *expected, int *loss)
 {
 	struct mgcp_rtp_state *state = &conn->state;
-	struct rate_ctr *packets_rx = &conn->rate_ctr_group->ctr[RTP_PACKETS_RX_CTR];
+	struct rate_ctr *packets_rx = rate_ctr_group_get_ctr(conn->rate_ctr_group, RTP_PACKETS_RX_CTR);
 
 	*expected = state->stats.cycles + state->stats.max_seq;
 	*expected = *expected - state->stats.base_seq + 1;
@@ -74,10 +74,10 @@
 	int ploss;
 	int nchars;
 
-	struct rate_ctr *packets_rx = &conn->rate_ctr_group->ctr[RTP_PACKETS_RX_CTR];
-	struct rate_ctr *octets_rx = &conn->rate_ctr_group->ctr[RTP_OCTETS_RX_CTR];
-	struct rate_ctr *packets_tx = &conn->rate_ctr_group->ctr[RTP_PACKETS_TX_CTR];
-	struct rate_ctr *octets_tx = &conn->rate_ctr_group->ctr[RTP_OCTETS_TX_CTR];
+	struct rate_ctr *packets_rx = rate_ctr_group_get_ctr(conn->rate_ctr_group, RTP_PACKETS_RX_CTR);
+	struct rate_ctr *octets_rx = rate_ctr_group_get_ctr(conn->rate_ctr_group, RTP_OCTETS_RX_CTR);
+	struct rate_ctr *packets_tx = rate_ctr_group_get_ctr(conn->rate_ctr_group, RTP_PACKETS_TX_CTR);
+	struct rate_ctr *octets_tx = rate_ctr_group_get_ctr(conn->rate_ctr_group, RTP_OCTETS_TX_CTR);
 
 	calc_loss(conn, &expected, &ploss);
 	jitter = calc_jitter(&conn->state);
diff --git a/src/libosmo-mgcp/mgcp_vty.c b/src/libosmo-mgcp/mgcp_vty.c
index 5892df1..369c1c1 100644
--- a/src/libosmo-mgcp/mgcp_vty.c
+++ b/src/libosmo-mgcp/mgcp_vty.c
@@ -169,11 +169,11 @@
 	struct rate_ctr *rx_packets, *rx_bytes;
 	struct rate_ctr *dropped_packets;
 
-	tx_packets = &conn->rate_ctr_group->ctr[RTP_PACKETS_TX_CTR];
-	tx_bytes = &conn->rate_ctr_group->ctr[RTP_OCTETS_TX_CTR];
-	rx_packets = &conn->rate_ctr_group->ctr[RTP_PACKETS_RX_CTR];
-	rx_bytes = &conn->rate_ctr_group->ctr[RTP_OCTETS_RX_CTR];
-	dropped_packets = &conn->rate_ctr_group->ctr[RTP_DROPPED_PACKETS_CTR];
+	tx_packets = rate_ctr_group_get_ctr(conn->rate_ctr_group, RTP_PACKETS_TX_CTR);
+	tx_bytes = rate_ctr_group_get_ctr(conn->rate_ctr_group, RTP_OCTETS_TX_CTR);
+	rx_packets = rate_ctr_group_get_ctr(conn->rate_ctr_group, RTP_PACKETS_RX_CTR);
+	rx_bytes = rate_ctr_group_get_ctr(conn->rate_ctr_group, RTP_OCTETS_RX_CTR);
+	dropped_packets = rate_ctr_group_get_ctr(conn->rate_ctr_group, RTP_DROPPED_PACKETS_CTR);
 
 	vty_out(vty,
 		"   Packets Sent: %" PRIu64 " (%" PRIu64 " bytes total)%s"
diff --git a/tests/mgcp/mgcp_test.c b/tests/mgcp/mgcp_test.c
index 620b0d1..74ecfe8 100644
--- a/tests/mgcp/mgcp_test.c
+++ b/tests/mgcp/mgcp_test.c
@@ -1071,7 +1071,7 @@
 				    "test-connection");
 		conn = mgcp_conn_get_rtp(&endp, _conn->id);
 		state = &conn->state;
-		packets_rx = &conn->rate_ctr_group->ctr[RTP_PACKETS_RX_CTR];
+		packets_rx = rate_ctr_group_get_ctr(conn->rate_ctr_group, RTP_PACKETS_RX_CTR);
 
 		state->stats.initialized = 1;
 		state->stats.base_seq = pl_test_dat[i].base_seq;

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

Gerrit-Project: osmo-mgw
Gerrit-Branch: master
Gerrit-Change-Id: I53b75ea8a88bc1ae4ceb479ed272865054de9665
Gerrit-Change-Number: 24554
Gerrit-PatchSet: 1
Gerrit-Owner: pespin <pespin at sysmocom.de>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20210604/fa259618/attachment.htm>


More information about the gerrit-log mailing list