From bd7b3c5e45426efc79b4dd685d1e818de3550d0a Mon Sep 17 00:00:00 2001 From: Holger Hans Peter Freyther Date: Mon, 1 Nov 2010 21:04:54 +0100 Subject: mgcp: Introduce trans_bts and send BTS packets from this port Introduce the trans_bts. Right now only a port is allocated and the packets from the BTS are sent from this socket. --- openbsc/include/openbsc/mgcp_internal.h | 16 +++++++++++++++- openbsc/src/mgcp/mgcp_network.c | 22 +++++++++++++++++++--- openbsc/src/mgcp/mgcp_protocol.c | 31 ++++++++++++++++++++----------- openbsc/src/mgcp/mgcp_vty.c | 16 +++++++++++++--- 4 files changed, 67 insertions(+), 18 deletions(-) diff --git a/openbsc/include/openbsc/mgcp_internal.h b/openbsc/include/openbsc/mgcp_internal.h index 68c8235d8..c0a1fb165 100644 --- a/openbsc/include/openbsc/mgcp_internal.h +++ b/openbsc/include/openbsc/mgcp_internal.h @@ -99,6 +99,12 @@ struct mgcp_endpoint { struct mgcp_rtp_end bts_end; struct mgcp_rtp_end net_end; + /* + * For transcoding we will send from the local_port + * of trans_bts and it will arrive at trans_net from + * where we will forward it to the network. + */ + struct mgcp_rtp_end trans_bts; struct mgcp_rtp_end trans_net; int is_transcoded; @@ -126,7 +132,15 @@ int mgcp_analyze_header(struct mgcp_config *cfg, struct msgb *msg, int mgcp_send_dummy(struct mgcp_endpoint *endp); int mgcp_bind_bts_rtp_port(struct mgcp_endpoint *endp, int rtp_port); int mgcp_bind_net_rtp_port(struct mgcp_endpoint *endp, int rtp_port); -int mgcp_bind_transcoder_rtp_port(struct mgcp_endpoint *enp, int rtp_port); +int mgcp_bind_trans_bts_rtp_port(struct mgcp_endpoint *enp, int rtp_port); +int mgcp_bind_trans_net_rtp_port(struct mgcp_endpoint *enp, int rtp_port); int mgcp_free_rtp_port(struct mgcp_rtp_end *end); +/* For transcoding we need to manage an in and an output that are connected */ +static inline int endp_back_channel(int endpoint) +{ + return endpoint + 60; +} + + #endif diff --git a/openbsc/src/mgcp/mgcp_network.c b/openbsc/src/mgcp/mgcp_network.c index f78e42abb..ae0504ff9 100644 --- a/openbsc/src/mgcp/mgcp_network.c +++ b/openbsc/src/mgcp/mgcp_network.c @@ -191,8 +191,8 @@ static int send_transcoder(struct mgcp_endpoint *endp, int is_rtp, addr.sin_port = htons(port); rc = sendto(is_rtp ? - endp->bts_end.rtp.fd : - endp->bts_end.rtcp.fd, buf, len, 0, + endp->trans_bts.rtp.fd : + endp->trans_bts.rtcp.fd, buf, len, 0, (struct sockaddr *) &addr, sizeof(addr)); if (rc != len) @@ -543,7 +543,7 @@ int mgcp_bind_net_rtp_port(struct mgcp_endpoint *endp, int rtp_port) return bind_rtp(endp->cfg, &endp->net_end, ENDPOINT_NUMBER(endp)); } -int mgcp_bind_transcoder_rtp_port(struct mgcp_endpoint *endp, int rtp_port) +int mgcp_bind_trans_net_rtp_port(struct mgcp_endpoint *endp, int rtp_port) { if (endp->trans_net.rtp.fd != -1 || endp->trans_net.rtcp.fd != -1) { LOGP(DMGCP, LOGL_ERROR, "Previous net-port was still bound on %d\n", @@ -559,6 +559,22 @@ int mgcp_bind_transcoder_rtp_port(struct mgcp_endpoint *endp, int rtp_port) return bind_rtp(endp->cfg, &endp->trans_net, ENDPOINT_NUMBER(endp)); } +int mgcp_bind_trans_bts_rtp_port(struct mgcp_endpoint *endp, int rtp_port) +{ + if (endp->trans_bts.rtp.fd != -1 || endp->trans_bts.rtcp.fd != -1) { + LOGP(DMGCP, LOGL_ERROR, "Previous net-port was still bound on %d\n", + ENDPOINT_NUMBER(endp)); + mgcp_free_rtp_port(&endp->trans_bts); + } + + endp->trans_bts.local_port = rtp_port; + endp->trans_bts.rtp.cb = rtp_data_transcoder; + endp->trans_bts.rtp.data = endp; + endp->trans_bts.rtcp.data = endp; + endp->trans_bts.rtcp.cb = rtp_data_transcoder; + return bind_rtp(endp->cfg, &endp->trans_bts, ENDPOINT_NUMBER(endp)); +} + int mgcp_free_rtp_port(struct mgcp_rtp_end *end) { if (end->rtp.fd != -1) { diff --git a/openbsc/src/mgcp/mgcp_protocol.c b/openbsc/src/mgcp/mgcp_protocol.c index ddcbfafcb..84fd1551e 100644 --- a/openbsc/src/mgcp/mgcp_protocol.c +++ b/openbsc/src/mgcp/mgcp_protocol.c @@ -423,12 +423,21 @@ static int allocate_ports(struct mgcp_endpoint *endp) if (endp->cfg->transcoder_ip) { if (allocate_port(endp, &endp->trans_net, &endp->cfg->transcoder_ports, - mgcp_bind_transcoder_rtp_port) != 0) { + mgcp_bind_trans_net_rtp_port) != 0) { mgcp_rtp_end_reset(&endp->net_end); mgcp_rtp_end_reset(&endp->bts_end); return -1; } + if (allocate_port(endp, &endp->trans_bts, + &endp->cfg->transcoder_ports, + mgcp_bind_trans_bts_rtp_port) != 0) { + mgcp_rtp_end_reset(&endp->net_end); + mgcp_rtp_end_reset(&endp->bts_end); + mgcp_rtp_end_reset(&endp->trans_net); + return -1; + } + /* remember that we have set up transcoding */ endp->is_transcoded = 1; } @@ -830,6 +839,7 @@ int mgcp_endpoints_allocate(struct mgcp_config *cfg) mgcp_rtp_end_init(&cfg->endpoints[i].net_end); mgcp_rtp_end_init(&cfg->endpoints[i].bts_end); mgcp_rtp_end_init(&cfg->endpoints[i].trans_net); + mgcp_rtp_end_init(&cfg->endpoints[i].trans_bts); } return 0; @@ -854,6 +864,7 @@ void mgcp_free_endp(struct mgcp_endpoint *endp) mgcp_rtp_end_reset(&endp->bts_end); mgcp_rtp_end_reset(&endp->net_end); mgcp_rtp_end_reset(&endp->trans_net); + mgcp_rtp_end_reset(&endp->trans_bts); endp->is_transcoded = 0; memset(&endp->net_state, 0, sizeof(endp->net_state)); @@ -865,12 +876,6 @@ void mgcp_free_endp(struct mgcp_endpoint *endp) memset(&endp->taps, 0, sizeof(endp->taps)); } -/* For transcoding we need to manage an in and an output that are connected */ -static int back_channel(int endpoint) -{ - return endpoint + 60; -} - static int send_trans(struct mgcp_config *cfg, const char *buf, int len) { struct sockaddr_in addr; @@ -932,16 +937,20 @@ static void create_transcoder(struct mgcp_endpoint *endp) { int port; int in_endp = ENDPOINT_NUMBER(endp); - int out_endp = back_channel(in_endp); + int out_endp = endp_back_channel(in_endp); if (!endp->is_transcoded) return; - send_msg(endp, in_endp, endp->bts_end.local_port, "CRCX", "recvonly"); - send_msg(endp, in_endp, endp->bts_end.local_port, "MDCX", "recvonly"); + send_msg(endp, in_endp, endp->trans_bts.local_port, "CRCX", "recvonly"); + send_msg(endp, in_endp, endp->trans_bts.local_port, "MDCX", "recvonly"); send_msg(endp, out_endp, endp->trans_net.local_port, "CRCX", "sendrecv"); send_msg(endp, out_endp, endp->trans_net.local_port, "MDCX", "sendrecv"); + port = rtp_calculate_port(in_endp, endp->cfg->transcoder_remote_base); + endp->trans_bts.rtp_port = htons(port); + endp->trans_bts.rtcp_port = htons(port + 1); + port = rtp_calculate_port(out_endp, endp->cfg->transcoder_remote_base); endp->trans_net.rtp_port = htons(port); endp->trans_net.rtcp_port = htons(port + 1); @@ -950,7 +959,7 @@ static void create_transcoder(struct mgcp_endpoint *endp) static void delete_transcoder(struct mgcp_endpoint *endp) { int in_endp = ENDPOINT_NUMBER(endp); - int out_endp = back_channel(in_endp); + int out_endp = endp_back_channel(in_endp); if (!endp->is_transcoded) return; diff --git a/openbsc/src/mgcp/mgcp_vty.c b/openbsc/src/mgcp/mgcp_vty.c index f1738824d..b47470dd0 100644 --- a/openbsc/src/mgcp/mgcp_vty.c +++ b/openbsc/src/mgcp/mgcp_vty.c @@ -99,14 +99,14 @@ DEFUN(show_mcgp, show_mgcp_cmd, "show mgcp", vty_out(vty, "MGCP is up and running with %u endpoints:%s", g_cfg->number_endpoints - 1, VTY_NEWLINE); for (i = 1; i < g_cfg->number_endpoints; ++i) { struct mgcp_endpoint *endp = &g_cfg->endpoints[i]; - vty_out(vty, " Endpoint 0x%.2x: CI: %d net: %u/%u bts: %u/%u on %s traffic received bts: %u/%u remote: %u/%u transcoder: %u%s", + vty_out(vty, " Endpoint 0x%.2x: CI: %d net: %u/%u bts: %u/%u on %s traffic received bts: %u/%u remote: %u/%u transcoder: %u/%u%s", i, endp->ci, ntohs(endp->net_end.rtp_port), ntohs(endp->net_end.rtcp_port), ntohs(endp->bts_end.rtp_port), ntohs(endp->bts_end.rtcp_port), inet_ntoa(endp->bts_end.addr), endp->bts_end.packets, endp->bts_state.lost_no, endp->net_end.packets, endp->net_state.lost_no, - endp->trans_net.packets, + endp->trans_net.packets, endp->trans_bts.packets, VTY_NEWLINE); } @@ -523,13 +523,23 @@ int mgcp_parse_config(const char *config_file, struct mgcp_config *cfg) } if (g_cfg->transcoder_ip && g_cfg->transcoder_ports.mode == PORT_ALLOC_STATIC) { + /* network side */ rtp_port = rtp_calculate_port(ENDPOINT_NUMBER(endp), g_cfg->transcoder_ports.base_port); - if (mgcp_bind_transcoder_rtp_port(endp, rtp_port) != 0) { + if (mgcp_bind_trans_net_rtp_port(endp, rtp_port) != 0) { LOGP(DMGCP, LOGL_FATAL, "Failed to bind: %d\n", rtp_port); return -1; } endp->trans_net.local_alloc = PORT_ALLOC_STATIC; + + /* bts side */ + rtp_port = rtp_calculate_port(endp_back_channel(ENDPOINT_NUMBER(endp)), + g_cfg->transcoder_ports.base_port); + if (mgcp_bind_trans_bts_rtp_port(endp, rtp_port) != 0) { + LOGP(DMGCP, LOGL_FATAL, "Failed to bind: %d\n", rtp_port); + return -1; + } + endp->trans_bts.local_alloc = PORT_ALLOC_STATIC; } } -- cgit v1.2.3