stats: use libosmocore rate counter for in/out_stream.err_ts_counter
The two counters: in_stream.err_ts_counter and out_stream.err_ts_counter
are still handcoded. To make them better accessible they should
be replaced with libosmocore rate counters.
- replace state.in_stream.err_ts_counter with libosmocore rate counter
- replace state.out_stream.err_ts_counter with libosmocore rate counter
Change-Id: I67aa7a8602f60366ef3ba2c5b1319b1b85719f64
Related: OS#2517
diff --git a/src/libosmo-mgcp/mgcp_conn.c b/src/libosmo-mgcp/mgcp_conn.c
index 998dbc5..0055049 100644
--- a/src/libosmo-mgcp/mgcp_conn.c
+++ b/src/libosmo-mgcp/mgcp_conn.c
@@ -26,8 +26,28 @@
#include <osmocom/mgcp/mgcp_common.h>
#include <osmocom/mgcp/mgcp_endp.h>
#include <osmocom/gsm/gsm_utils.h>
+#include <osmocom/core/rate_ctr.h>
#include <ctype.h>
+const static struct rate_ctr_desc rate_ctr_desc[] = {
+ {
+ .name = "in_stream_err_ts_ctr",
+ .description = "inbound rtp-stream timestamp errors",
+ },{
+ .name = "out_stream_err_ts_ctr",
+ .description = "outbound rtp-stream timestamp errors",
+ }
+};
+
+const static struct rate_ctr_group_desc rate_ctr_group_desc = {
+ .group_name_prefix = "conn_rtp",
+ .group_description = "rtp connection statistics",
+ .class_id = 1,
+ .num_ctr = 2,
+ .ctr_desc = rate_ctr_desc
+};
+
+
/* Allocate a new connection identifier. According to RFC3435, they must
* be unique only within the scope of the endpoint. (Caller must provide
* memory for id) */
@@ -87,6 +107,10 @@
static void mgcp_rtp_conn_init(struct mgcp_conn_rtp *conn_rtp, struct mgcp_conn *conn)
{
struct mgcp_rtp_end *end = &conn_rtp->end;
+ /* FIXME: Each new rate counter group requires an unique index. At the
+ * moment we generate this index using this counter, but perhaps there
+ * is a more concious way to assign the indexes. */
+ static unsigned int rate_ctr_index = 0;
conn_rtp->type = MGCP_RTP_DEFAULT;
conn_rtp->osmux.allocated_cid = -1;
@@ -108,6 +132,15 @@
mgcp_rtp_codec_init(&end->codec);
mgcp_rtp_codec_init(&end->alt_codec);
+
+ conn_rtp->rate_ctr_group =
+ rate_ctr_group_alloc(conn, &rate_ctr_group_desc,
+ rate_ctr_index);
+ conn_rtp->state.in_stream.err_ts_ctr =
+ &conn_rtp->rate_ctr_group->ctr[0];
+ conn_rtp->state.out_stream.err_ts_ctr =
+ &conn_rtp->rate_ctr_group->ctr[1];
+ rate_ctr_index++;
}
/* Cleanup rtp connection struct */
@@ -116,6 +149,7 @@
osmux_disable_conn(conn_rtp);
osmux_release_cid(conn_rtp);
mgcp_free_rtp_port(&conn_rtp->end);
+ rate_ctr_group_free(conn_rtp->rate_ctr_group);
}
/*! allocate a new connection list entry.
diff --git a/src/libosmo-mgcp/mgcp_network.c b/src/libosmo-mgcp/mgcp_network.c
index 6923b97..c56e433 100644
--- a/src/libosmo-mgcp/mgcp_network.c
+++ b/src/libosmo-mgcp/mgcp_network.c
@@ -222,7 +222,7 @@
if (seq == sstate->last_seq) {
if (timestamp != sstate->last_timestamp) {
- sstate->err_ts_counter += 1;
+ rate_ctr_inc(sstate->err_ts_ctr);
LOGP(DRTP, LOGL_ERROR,
"The %s timestamp delta is != 0 but the sequence "
"number %d is the same, "
@@ -272,7 +272,7 @@
ts_alignment_error(sstate, state->packet_duration, timestamp);
if (timestamp_error) {
- sstate->err_ts_counter += 1;
+ rate_ctr_inc(sstate->err_ts_ctr);
LOGP(DRTP, LOGL_NOTICE,
"The %s timestamp has an alignment error of %d "
"on 0x%x SSRC: %u "
@@ -505,13 +505,16 @@
mgcp_rtp_annex_count(endp, state, seq, transit, ssrc);
if (!state->initialized) {
+ /* FIXME: Move this initialization to mgcp.conn.c */
state->initialized = 1;
state->in_stream.last_seq = seq - 1;
state->in_stream.ssrc = state->patch.orig_ssrc = ssrc;
state->in_stream.last_tsdelta = 0;
state->packet_duration =
mgcp_rtp_packet_duration(endp, rtp_end);
- state->out_stream = state->in_stream;
+ state->out_stream.last_seq = seq - 1;
+ state->out_stream.ssrc = state->patch.orig_ssrc = ssrc;
+ state->out_stream.last_tsdelta = 0;
state->out_stream.last_timestamp = timestamp;
state->out_stream.ssrc = ssrc - 1; /* force output SSRC change */
LOGP(DRTP, LOGL_INFO,
diff --git a/src/libosmo-mgcp/mgcp_stat.c b/src/libosmo-mgcp/mgcp_stat.c
index 581130c..cc723bb 100644
--- a/src/libosmo-mgcp/mgcp_stat.c
+++ b/src/libosmo-mgcp/mgcp_stat.c
@@ -87,9 +87,9 @@
if (conn->conn->endp->cfg->osmux != OSMUX_USAGE_OFF) {
/* Error Counter */
nchars = snprintf(str, str_len,
- "\r\nX-Osmo-CP: EC TI=%u, TO=%u",
- conn->state.in_stream.err_ts_counter,
- conn->state.out_stream.err_ts_counter);
+ "\r\nX-Osmo-CP: EC TI=%lu, TO=%lu",
+ conn->state.in_stream.err_ts_ctr->current,
+ conn->state.out_stream.err_ts_ctr->current);
if (nchars < 0 || nchars >= str_len)
goto truncate;
diff --git a/src/libosmo-mgcp/mgcp_vty.c b/src/libosmo-mgcp/mgcp_vty.c
index 14ecd17..392a176 100644
--- a/src/libosmo-mgcp/mgcp_vty.c
+++ b/src/libosmo-mgcp/mgcp_vty.c
@@ -160,15 +160,16 @@
struct mgcp_rtp_codec *codec = &end->codec;
vty_out(vty,
- " Timestamp Errs: %d->%d%s"
+ " Timestamp Errs: %lu->%lu%s"
" Dropped Packets: %d%s"
" Payload Type: %d Rate: %u Channels: %d %s"
" Frame Duration: %u Frame Denominator: %u%s"
" FPP: %d Packet Duration: %u%s"
" FMTP-Extra: %s Audio-Name: %s Sub-Type: %s%s"
" Output-Enabled: %d Force-PTIME: %d%s",
- state->in_stream.err_ts_counter,
- state->out_stream.err_ts_counter, VTY_NEWLINE,
+ state->in_stream.err_ts_ctr->current,
+ state->out_stream.err_ts_ctr->current,
+ VTY_NEWLINE,
end->stats.dropped_packets, VTY_NEWLINE,
codec->payload_type, codec->rate, codec->channels, VTY_NEWLINE,
codec->frame_duration_num, codec->frame_duration_den,