osmo-mgw: refactor endpoint and trunk handling
The trunk and endpoint handling in osmo-mgw is still very complex and
implemented in various places (mostly mgcp_protocol.c). Also we use
still integers for endpoint identification, which is not flexible enough
to address timeslots/subslots on an E1 trunk. Some refactoring is needed.
- get rid of integers as endpoint identifiers, use strings instead and
find the endpoint based on its string name on the trunk.
- identify the trunk based on the trunk prefix given in the endpoint
name.
- refactor trunk and endpoint allocation. Aggregate functionality in
in mgcp_endp.c and mgcp_trunk.c. Also remove non-reusable code that
relates to the still exisiting, but unfinished E1 trunk support.
- refactor rate counters, put them into a separate module and do no
longer allocate them per trunk. Allocate them globally instead.
Change-Id: Ia8cf4d6caf05a4e13f1f507dc68cbabb7e6239aa
Related: OS#2659
diff --git a/src/libosmo-mgcp/mgcp_network.c b/src/libosmo-mgcp/mgcp_network.c
index 2d3fdc3..8efc6b7 100644
--- a/src/libosmo-mgcp/mgcp_network.c
+++ b/src/libosmo-mgcp/mgcp_network.c
@@ -42,6 +42,7 @@
#include <osmocom/mgcp/osmux.h>
#include <osmocom/mgcp/mgcp_conn.h>
#include <osmocom/mgcp/mgcp_endp.h>
+#include <osmocom/mgcp/mgcp_trunk.h>
#include <osmocom/mgcp/mgcp_codec.h>
#include <osmocom/mgcp/debug.h>
#include <osmocom/codec/codec.h>
@@ -61,11 +62,11 @@
int id, int inc)
{
struct rate_ctr_group *conn_stats = conn_rtp->rate_ctr_group;
- struct rate_ctr_group *trunk_stats = endp->trunk->all_rtp_conn_stats;
+ struct rate_ctr_group *mgw_stats = endp->trunk->ratectr.all_rtp_conn_stats;
- /* add to both the per-connection and the per-trunk global stats */
+ /* add to both the per-connection and the global stats */
rate_ctr_add(&conn_stats->ctr[id], inc);
- rate_ctr_add(&trunk_stats->ctr[id], inc);
+ rate_ctr_add(&mgw_stats->ctr[id], inc);
}
static void rtpconn_rate_ctr_inc(struct mgcp_conn_rtp *conn_rtp, struct mgcp_endpoint *endp, int id)
@@ -648,9 +649,8 @@
return;
#if 0
- DEBUGP(DRTP,
- "endpoint:0x%x payload hdr payload %u -> endp payload %u\n",
- ENDPOINT_NUMBER(endp), rtp_hdr->payload_type, payload);
+ LOGPENDP(endp, DRTP, LOGL_DEBUG, "payload hdr payload %u -> endp payload %u\n",
+ rtp_hdr->payload_type, payload);
rtp_hdr->payload_type = payload;
#endif
}
@@ -1436,11 +1436,10 @@
/* Bind RTP and RTCP port (helper function for mgcp_bind_net_rtp_port()) */
static int bind_rtp(struct mgcp_config *cfg, const char *source_addr,
- struct mgcp_rtp_end *rtp_end, int endpno)
+ struct mgcp_rtp_end *rtp_end, struct mgcp_endpoint *endp)
{
/* NOTE: The port that is used for RTCP is the RTP port incremented by one
* (e.g. RTP-Port = 16000 ==> RTCP-Port = 16001) */
- struct mgcp_endpoint *endp = &cfg->virt_trunk->endpoints[endpno];
if (mgcp_create_bind(source_addr, &rtp_end->rtp,
rtp_end->local_port) != 0) {
@@ -1527,8 +1526,7 @@
mgcp_get_local_addr(local_ip_addr, conn);
- return bind_rtp(endp->cfg, local_ip_addr, end,
- ENDPOINT_NUMBER(endp));
+ return bind_rtp(endp->cfg, local_ip_addr, end, endp);
}
/*! free allocated RTP and RTCP ports.