Update per-trunk global packet/byte counters in real-time
We used to update only the per-connection rx/tx packet/byte counters
on-the-fly, but not the per-trunk global counters. The latter would
only be updated at the end of a connection. As MGCP connections
can last quite long (think of a long phone call) this is maybe
not the best of ideas.
Note: The all_rtp:err_tstmp_in and all_rt:err_tstmp_out are still
only updated at the end of a connection.
Change-Id: Ib3866cb8149d3257fcf39733846c97c33881c4ee
Related: OS#4437
diff --git a/src/libosmo-mgcp/mgcp_conn.c b/src/libosmo-mgcp/mgcp_conn.c
index 60a1700..7a86274 100644
--- a/src/libosmo-mgcp/mgcp_conn.c
+++ b/src/libosmo-mgcp/mgcp_conn.c
@@ -259,7 +259,6 @@
{
struct rate_ctr_group *all_stats = trunk->all_rtp_conn_stats;
struct rate_ctr_group *conn_stats = conn_rtp->rate_ctr_group;
- int i;
if (all_stats == NULL || conn_stats == NULL)
return;
@@ -269,8 +268,11 @@
* All other counters in both counter groups correspond to each other. */
OSMO_ASSERT(conn_stats->desc->num_ctr + 1 == all_stats->desc->num_ctr);
- for (i = 0; i < conn_stats->desc->num_ctr; i++)
- rate_ctr_add(&all_stats->ctr[i], conn_stats->ctr[i].current);
+ /* 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_inc(&all_stats->ctr[RTP_NUM_CONNECTIONS]);
}
diff --git a/src/libosmo-mgcp/mgcp_network.c b/src/libosmo-mgcp/mgcp_network.c
index 53cdc06..cd60ce2 100644
--- a/src/libosmo-mgcp/mgcp_network.c
+++ b/src/libosmo-mgcp/mgcp_network.c
@@ -57,6 +57,22 @@
MGCP_PROTO_RTCP,
};
+static void rtpconn_rate_ctr_add(struct mgcp_conn_rtp *conn_rtp, struct mgcp_endpoint *endp,
+ int id, int inc)
+{
+ struct rate_ctr_group *conn_stats = conn_rtp->rate_ctr_group;
+ struct rate_ctr_group *trunk_stats = endp->tcfg->all_rtp_conn_stats;
+
+ /* add to both the per-connection and the per-trunk global stats */
+ rate_ctr_add(&conn_stats->ctr[id], inc);
+ rate_ctr_add(&trunk_stats->ctr[id], inc);
+}
+
+static void rtpconn_rate_ctr_inc(struct mgcp_conn_rtp *conn_rtp, struct mgcp_endpoint *endp, int id)
+{
+ rtpconn_rate_ctr_add(conn_rtp, endp, id, 1);
+}
+
/*! Determine the local rtp bind IP-address.
* \param[out] addr caller provided memory to store the resulting IP-Address
* \param[in] endp mgcp endpoint, that holds a copy of the VTY parameters
@@ -845,7 +861,7 @@
dest_name = conn_dst->conn->name;
if (!rtp_end->output_enabled) {
- rate_ctr_inc(&conn_dst->rate_ctr_group->ctr[RTP_DROPPED_PACKETS_CTR]);
+ rtpconn_rate_ctr_inc(conn_dst, endp, RTP_DROPPED_PACKETS_CTR);
LOGPENDP(endp, DRTP, LOGL_DEBUG,
"output disabled, drop to %s %s "
"rtp_port:%u rtcp_port:%u\n",
@@ -924,8 +940,8 @@
if (len <= 0)
return len;
- rate_ctr_inc(&conn_dst->rate_ctr_group->ctr[RTP_PACKETS_TX_CTR]);
- rate_ctr_add(&conn_dst->rate_ctr_group->ctr[RTP_OCTETS_TX_CTR], len);
+ rtpconn_rate_ctr_inc(conn_dst, endp, RTP_PACKETS_TX_CTR);
+ rtpconn_rate_ctr_add(conn_dst, endp, RTP_OCTETS_TX_CTR, len);
nbytes += len;
buflen = cont;
@@ -942,8 +958,8 @@
&rtp_end->addr,
rtp_end->rtcp_port, buf, len);
- rate_ctr_inc(&conn_dst->rate_ctr_group->ctr[RTP_PACKETS_TX_CTR]);
- rate_ctr_add(&conn_dst->rate_ctr_group->ctr[RTP_OCTETS_TX_CTR], len);
+ rtpconn_rate_ctr_inc(conn_dst, endp, RTP_PACKETS_TX_CTR);
+ rtpconn_rate_ctr_add(conn_dst, endp, RTP_OCTETS_TX_CTR, len);
return len;
}
@@ -1189,8 +1205,8 @@
}
/* Increment RX statistics */
- rate_ctr_inc(&conn->rate_ctr_group->ctr[RTP_PACKETS_RX_CTR]);
- rate_ctr_add(&conn->rate_ctr_group->ctr[RTP_OCTETS_RX_CTR], rc);
+ rtpconn_rate_ctr_inc(conn, endp, RTP_PACKETS_RX_CTR);
+ rtpconn_rate_ctr_add(conn, endp, RTP_OCTETS_RX_CTR, rc);
/* Forward a copy of the RTP data to a debug ip/port */
forward_data(fd->fd, &conn->tap_in, buf, rc);