stats: replace packet statistic counters with libosmocore rate counters

In struct mgcp_rtp_end one finds unsigned int counters. Those should
be replaced with libosmocore rate counters

- replace packets_rx, octets_rx, packets_tx, octets_tx and
  dropped_packets with libosmocore rate counters.

Change-Id: I47c5c9006df5044e59ddebb895e62adb849d72d5
Related: OS#2517
diff --git a/tests/mgcp/mgcp_test.c b/tests/mgcp/mgcp_test.c
index 1d2cf4a..56d0cee 100644
--- a/tests/mgcp/mgcp_test.c
+++ b/tests/mgcp/mgcp_test.c
@@ -937,23 +937,43 @@
 static void test_packet_loss_calc(void)
 {
 	int i;
+	struct mgcp_endpoint endp;
+	struct mgcp_trunk_config trunk;
+
 	printf("Testing packet loss calculation.\n");
 
+	memset(&endp, 0, sizeof(endp));
+	memset(&trunk, 0, sizeof(trunk));
+
+	endp.type = &ep_typeset.rtp;
+	trunk.vty_number_endpoints = 1;
+	trunk.endpoints = &endp;
+	endp.tcfg = &trunk;
+	INIT_LLIST_HEAD(&endp.conns);
+
 	for (i = 0; i < ARRAY_SIZE(pl_test_dat); ++i) {
 		uint32_t expected;
 		int loss;
-		struct mgcp_rtp_state state;
-		struct mgcp_rtp_end rtp;
-		memset(&state, 0, sizeof(state));
-		memset(&rtp, 0, sizeof(rtp));
 
-		state.stats.initialized = 1;
-		state.stats.base_seq = pl_test_dat[i].base_seq;
-		state.stats.max_seq = pl_test_dat[i].max_seq;
-		state.stats.cycles = pl_test_dat[i].cycles;
+		struct mgcp_conn_rtp *conn = NULL;
+		struct mgcp_conn *_conn = NULL;
+		struct mgcp_rtp_state *state;
+		struct rate_ctr *packets_rx;
 
-		rtp.stats.packets_rx = pl_test_dat[i].packets;
-		calc_loss(&state, &rtp, &expected, &loss);
+		_conn =
+		    mgcp_conn_alloc(NULL, &endp, MGCP_CONN_TYPE_RTP,
+				    "test-connection");
+		conn = mgcp_conn_get_rtp(&endp, _conn->id);
+		state = &conn->state;
+		packets_rx = &conn->rate_ctr_group->ctr[RTP_PACKETS_RX_CTR];
+
+		state->stats.initialized = 1;
+		state->stats.base_seq = pl_test_dat[i].base_seq;
+		state->stats.max_seq = pl_test_dat[i].max_seq;
+		state->stats.cycles = pl_test_dat[i].cycles;
+
+		packets_rx->current = pl_test_dat[i].packets;
+		calc_loss(conn, &expected, &loss);
 
 		if (loss != pl_test_dat[i].loss
 		    || expected != pl_test_dat[i].expected) {
@@ -962,7 +982,10 @@
 			     i, loss, pl_test_dat[i].loss, expected,
 			     pl_test_dat[i].expected);
 		}
+
+		mgcp_conn_free_all(&endp);
 	}
+
 }
 
 int mgcp_parse_stats(struct msgb *msg, uint32_t *ps, uint32_t *os,