From fbca4ea1171abb65fd8e1f121469adaeb57104df Mon Sep 17 00:00:00 2001 From: Holger Hans Peter Freyther Date: Mon, 1 Nov 2010 19:49:48 +0100 Subject: mgcp: Fix the indetion of this code. it should use tabs --- openbsc/src/mgcp/mgcp_protocol.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openbsc/src/mgcp/mgcp_protocol.c b/openbsc/src/mgcp/mgcp_protocol.c index 840bc14c2..c73031c08 100644 --- a/openbsc/src/mgcp/mgcp_protocol.c +++ b/openbsc/src/mgcp/mgcp_protocol.c @@ -422,7 +422,7 @@ static int allocate_ports(struct mgcp_endpoint *endp) } if (endp->cfg->transcoder_ip && - allocate_port(endp, &endp->transcoder_end, &endp->cfg->transcoder_ports, + allocate_port(endp, &endp->transcoder_end, &endp->cfg->transcoder_ports, mgcp_bind_transcoder_rtp_port) != 0) { mgcp_rtp_end_reset(&endp->net_end); mgcp_rtp_end_reset(&endp->bts_end); -- cgit v1.2.3 From b54048fe25a28c47149f916ae293654b5330ff78 Mon Sep 17 00:00:00 2001 From: Holger Hans Peter Freyther Date: Mon, 1 Nov 2010 19:57:50 +0100 Subject: mgcp: Make transcoding a per Endpoint configuration This allows to switch off transcoding on the fly, or only enable it for certain vessels with known problems. --- openbsc/include/openbsc/mgcp_internal.h | 1 + openbsc/src/mgcp/mgcp_network.c | 2 +- openbsc/src/mgcp/mgcp_protocol.c | 22 ++++++++++++++-------- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/openbsc/include/openbsc/mgcp_internal.h b/openbsc/include/openbsc/mgcp_internal.h index 7c5badc92..473ee31c0 100644 --- a/openbsc/include/openbsc/mgcp_internal.h +++ b/openbsc/include/openbsc/mgcp_internal.h @@ -99,6 +99,7 @@ struct mgcp_endpoint { struct mgcp_rtp_end bts_end; struct mgcp_rtp_end net_end; struct mgcp_rtp_end transcoder_end; + int is_transcoded; /* sequence bits */ struct mgcp_rtp_state net_state; diff --git a/openbsc/src/mgcp/mgcp_network.c b/openbsc/src/mgcp/mgcp_network.c index 28a27ca55..6c6c33646 100644 --- a/openbsc/src/mgcp/mgcp_network.c +++ b/openbsc/src/mgcp/mgcp_network.c @@ -383,7 +383,7 @@ static int rtp_data_bts(struct bsc_fd *fd, unsigned int what) endp->bts_end.packets += 1; forward_data(fd->fd, &endp->taps[MGCP_TAP_BTS_IN], buf, rc); - if (cfg->transcoder_ip) + if (endp->is_transcoded) return send_transcoder(endp, proto == PROTO_RTP, &buf[0], rc); else return send_to(endp, DEST_NETWORK, proto == PROTO_RTP, &addr, &buf[0], rc); diff --git a/openbsc/src/mgcp/mgcp_protocol.c b/openbsc/src/mgcp/mgcp_protocol.c index c73031c08..4e7ebf8bb 100644 --- a/openbsc/src/mgcp/mgcp_protocol.c +++ b/openbsc/src/mgcp/mgcp_protocol.c @@ -421,12 +421,17 @@ static int allocate_ports(struct mgcp_endpoint *endp) return -1; } - if (endp->cfg->transcoder_ip && - allocate_port(endp, &endp->transcoder_end, &endp->cfg->transcoder_ports, - mgcp_bind_transcoder_rtp_port) != 0) { - mgcp_rtp_end_reset(&endp->net_end); - mgcp_rtp_end_reset(&endp->bts_end); - return -1; + if (endp->cfg->transcoder_ip) { + if (allocate_port(endp, &endp->transcoder_end, + &endp->cfg->transcoder_ports, + mgcp_bind_transcoder_rtp_port) != 0) { + mgcp_rtp_end_reset(&endp->net_end); + mgcp_rtp_end_reset(&endp->bts_end); + return -1; + } + + /* remember that we have set up transcoding */ + endp->is_transcoded = 1; } return 0; @@ -848,6 +853,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->transcoder_end); + endp->is_transcoded = 0; memset(&endp->net_state, 0, sizeof(endp->net_state)); memset(&endp->bts_state, 0, sizeof(endp->bts_state)); @@ -927,7 +933,7 @@ static void create_transcoder(struct mgcp_endpoint *endp) int in_endp = ENDPOINT_NUMBER(endp); int out_endp = back_channel(in_endp); - if (!endp->cfg->transcoder_ip) + if (!endp->is_transcoded) return; send_msg(endp, in_endp, endp->bts_end.local_port, "CRCX", "recvonly"); @@ -945,7 +951,7 @@ static void delete_transcoder(struct mgcp_endpoint *endp) int in_endp = ENDPOINT_NUMBER(endp); int out_endp = back_channel(in_endp); - if (!endp->cfg->transcoder_ip) + if (!endp->is_transcoded) return; send_dlcx(endp, in_endp); -- cgit v1.2.3 From 88b597e21c2e3292eb615572545e1fd3a48f1714 Mon Sep 17 00:00:00 2001 From: Holger Hans Peter Freyther Date: Mon, 1 Nov 2010 20:06:45 +0100 Subject: mgcp: Allow to disable the transcoder in a running system. --- openbsc/src/mgcp/mgcp_vty.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/openbsc/src/mgcp/mgcp_vty.c b/openbsc/src/mgcp/mgcp_vty.c index d78b8c78a..d284abff9 100644 --- a/openbsc/src/mgcp/mgcp_vty.c +++ b/openbsc/src/mgcp/mgcp_vty.c @@ -319,6 +319,20 @@ DEFUN(cfg_mgcp_transcoder, return CMD_SUCCESS; } +DEFUN(cfg_mgcp_no_transcoder, + cfg_mgcp_no_transcoder_cmd, + NO_STR "transcoder-mgw", + "Disable the transcoding\n") +{ + if (g_cfg->transcoder_ip) { + LOGP(DMGCP, LOGL_NOTICE, "Disabling transcoding on future calls.\n"); + talloc_free(g_cfg->transcoder_ip); + g_cfg->transcoder_ip = NULL; + } + + return CMD_SUCCESS; +} + DEFUN(cfg_mgcp_transcoder_remote_base, cfg_mgcp_transcoder_remote_base_cmd, "transcoder-remote-base <0-65534>", @@ -453,6 +467,7 @@ int mgcp_vty_init(void) install_element(MGCP_NODE, &cfg_mgcp_number_endp_cmd); install_element(MGCP_NODE, &cfg_mgcp_agent_addr_cmd); install_element(MGCP_NODE, &cfg_mgcp_transcoder_cmd); + install_element(MGCP_NODE, &cfg_mgcp_no_transcoder_cmd); install_element(MGCP_NODE, &cfg_mgcp_transcoder_remote_base_cmd); return 0; } -- cgit v1.2.3 From 21262335907f2aa621742e87d596e4278b0f3d86 Mon Sep 17 00:00:00 2001 From: Holger Hans Peter Freyther Date: Mon, 1 Nov 2010 20:53:31 +0100 Subject: mgcp: Rename transcoder_end to trans_net Packets arriving for trans_net will be send out to the networking. We will introduce a trans_bts in a second. --- openbsc/include/openbsc/mgcp_internal.h | 3 ++- openbsc/src/mgcp/mgcp_network.c | 26 +++++++++++++------------- openbsc/src/mgcp/mgcp_protocol.c | 14 +++++++------- openbsc/src/mgcp/mgcp_vty.c | 4 ++-- 4 files changed, 24 insertions(+), 23 deletions(-) diff --git a/openbsc/include/openbsc/mgcp_internal.h b/openbsc/include/openbsc/mgcp_internal.h index 473ee31c0..68c8235d8 100644 --- a/openbsc/include/openbsc/mgcp_internal.h +++ b/openbsc/include/openbsc/mgcp_internal.h @@ -98,7 +98,8 @@ struct mgcp_endpoint { /* port status for bts/net */ struct mgcp_rtp_end bts_end; struct mgcp_rtp_end net_end; - struct mgcp_rtp_end transcoder_end; + + struct mgcp_rtp_end trans_net; int is_transcoded; /* sequence bits */ diff --git a/openbsc/src/mgcp/mgcp_network.c b/openbsc/src/mgcp/mgcp_network.c index 6c6c33646..f78e42abb 100644 --- a/openbsc/src/mgcp/mgcp_network.c +++ b/openbsc/src/mgcp/mgcp_network.c @@ -176,7 +176,7 @@ static int send_transcoder(struct mgcp_endpoint *endp, int is_rtp, struct mgcp_config *cfg = endp->cfg; struct sockaddr_in addr; - if (endp->transcoder_end.rtp_port == 0) { + if (endp->trans_net.rtp_port == 0) { LOGP(DMGCP, LOGL_ERROR, "Transcoder port not known on 0x%x\n", ENDPOINT_NUMBER(endp)); return -1; @@ -404,7 +404,7 @@ static int rtp_data_transcoder(struct bsc_fd *fd, unsigned int what) if (rc <= 0) return -1; - proto = fd == &endp->transcoder_end.rtp ? PROTO_RTP : PROTO_RTCP; + proto = fd == &endp->trans_net.rtp ? PROTO_RTP : PROTO_RTCP; if (memcmp(&addr.sin_addr, &cfg->transcoder_in, sizeof(addr.sin_addr)) != 0) { LOGP(DMGCP, LOGL_ERROR, @@ -413,8 +413,8 @@ static int rtp_data_transcoder(struct bsc_fd *fd, unsigned int what) return -1; } - if (endp->transcoder_end.rtp_port != addr.sin_port && - endp->transcoder_end.rtcp_port != addr.sin_port) { + if (endp->trans_net.rtp_port != addr.sin_port && + endp->trans_net.rtcp_port != addr.sin_port) { LOGP(DMGCP, LOGL_ERROR, "Data from wrong transcoder source port %d on 0x%x\n", ntohs(addr.sin_port), ENDPOINT_NUMBER(endp)); @@ -428,7 +428,7 @@ static int rtp_data_transcoder(struct bsc_fd *fd, unsigned int what) return 0; } - endp->transcoder_end.packets += 1; + endp->trans_net.packets += 1; return send_to(endp, DEST_NETWORK, proto == PROTO_RTP, &addr, &buf[0], rc); } @@ -545,18 +545,18 @@ int mgcp_bind_net_rtp_port(struct mgcp_endpoint *endp, int rtp_port) int mgcp_bind_transcoder_rtp_port(struct mgcp_endpoint *endp, int rtp_port) { - if (endp->transcoder_end.rtp.fd != -1 || endp->transcoder_end.rtcp.fd != -1) { + 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", ENDPOINT_NUMBER(endp)); - mgcp_free_rtp_port(&endp->transcoder_end); + mgcp_free_rtp_port(&endp->trans_net); } - endp->transcoder_end.local_port = rtp_port; - endp->transcoder_end.rtp.cb = rtp_data_transcoder; - endp->transcoder_end.rtp.data = endp; - endp->transcoder_end.rtcp.data = endp; - endp->transcoder_end.rtcp.cb = rtp_data_transcoder; - return bind_rtp(endp->cfg, &endp->transcoder_end, ENDPOINT_NUMBER(endp)); + endp->trans_net.local_port = rtp_port; + endp->trans_net.rtp.cb = rtp_data_transcoder; + endp->trans_net.rtp.data = endp; + endp->trans_net.rtcp.data = endp; + endp->trans_net.rtcp.cb = rtp_data_transcoder; + return bind_rtp(endp->cfg, &endp->trans_net, ENDPOINT_NUMBER(endp)); } int mgcp_free_rtp_port(struct mgcp_rtp_end *end) diff --git a/openbsc/src/mgcp/mgcp_protocol.c b/openbsc/src/mgcp/mgcp_protocol.c index 4e7ebf8bb..435ceeee2 100644 --- a/openbsc/src/mgcp/mgcp_protocol.c +++ b/openbsc/src/mgcp/mgcp_protocol.c @@ -422,7 +422,7 @@ static int allocate_ports(struct mgcp_endpoint *endp) } if (endp->cfg->transcoder_ip) { - if (allocate_port(endp, &endp->transcoder_end, + if (allocate_port(endp, &endp->trans_net, &endp->cfg->transcoder_ports, mgcp_bind_transcoder_rtp_port) != 0) { mgcp_rtp_end_reset(&endp->net_end); @@ -828,7 +828,7 @@ int mgcp_endpoints_allocate(struct mgcp_config *cfg) cfg->endpoints[i].cfg = 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].transcoder_end); + mgcp_rtp_end_init(&cfg->endpoints[i].trans_net); } return 0; @@ -852,7 +852,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->transcoder_end); + mgcp_rtp_end_reset(&endp->trans_net); endp->is_transcoded = 0; memset(&endp->net_state, 0, sizeof(endp->net_state)); @@ -938,12 +938,12 @@ static void create_transcoder(struct mgcp_endpoint *endp) 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, out_endp, endp->transcoder_end.local_port, "CRCX", "sendrecv"); - send_msg(endp, out_endp, endp->transcoder_end.local_port, "MDCX", "sendrecv"); + 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(out_endp, endp->cfg->transcoder_remote_base); - endp->transcoder_end.rtp_port = htons(port); - endp->transcoder_end.rtcp_port = htons(port + 1); + endp->trans_net.rtp_port = htons(port); + endp->trans_net.rtcp_port = htons(port + 1); } static void delete_transcoder(struct mgcp_endpoint *endp) diff --git a/openbsc/src/mgcp/mgcp_vty.c b/openbsc/src/mgcp/mgcp_vty.c index d284abff9..f1738824d 100644 --- a/openbsc/src/mgcp/mgcp_vty.c +++ b/openbsc/src/mgcp/mgcp_vty.c @@ -106,7 +106,7 @@ DEFUN(show_mcgp, show_mgcp_cmd, "show mgcp", 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->transcoder_end.packets, + endp->trans_net.packets, VTY_NEWLINE); } @@ -529,7 +529,7 @@ int mgcp_parse_config(const char *config_file, struct mgcp_config *cfg) LOGP(DMGCP, LOGL_FATAL, "Failed to bind: %d\n", rtp_port); return -1; } - endp->transcoder_end.local_alloc = PORT_ALLOC_STATIC; + endp->trans_net.local_alloc = PORT_ALLOC_STATIC; } } -- cgit v1.2.3 From e97155a2af793aa709f897e8766cccd20e86964c Mon Sep 17 00:00:00 2001 From: Holger Hans Peter Freyther Date: Tue, 2 Nov 2010 19:06:13 +0100 Subject: mgcp: Keep the local_port like it was set on allocation Do not reset statically allocated local_port. The port might be different to the calculation of endpoint number and base port. This might be the case for the coming remote transcoding. --- openbsc/src/mgcp/mgcp_protocol.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/openbsc/src/mgcp/mgcp_protocol.c b/openbsc/src/mgcp/mgcp_protocol.c index 435ceeee2..ddcbfafcb 100644 --- a/openbsc/src/mgcp/mgcp_protocol.c +++ b/openbsc/src/mgcp/mgcp_protocol.c @@ -382,7 +382,6 @@ static int allocate_port(struct mgcp_endpoint *endp, struct mgcp_rtp_end *end, int i; if (range->mode == PORT_ALLOC_STATIC) { - end->local_port = rtp_calculate_port(ENDPOINT_NUMBER(endp), range->base_port); end->local_alloc = PORT_ALLOC_STATIC; return 0; } @@ -795,12 +794,14 @@ struct mgcp_config *mgcp_config_alloc(void) static void mgcp_rtp_end_reset(struct mgcp_rtp_end *end) { - if (end->local_alloc == PORT_ALLOC_DYNAMIC) + if (end->local_alloc == PORT_ALLOC_DYNAMIC) { mgcp_free_rtp_port(end); + end->local_port = 0; + } end->packets = 0; memset(&end->addr, 0, sizeof(end->addr)); - end->rtp_port = end->rtcp_port = end->local_port = 0; + end->rtp_port = end->rtcp_port = 0; end->payload_type = -1; end->local_alloc = -1; } -- cgit v1.2.3 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 From 386a940736d5f8c65ba5d5409c4858f5c829a338 Mon Sep 17 00:00:00 2001 From: Holger Hans Peter Freyther Date: Mon, 1 Nov 2010 21:15:22 +0100 Subject: mgcp: Refactor the network binding routines Create another wrapper function that takes most of the arguments from the caller. --- openbsc/src/mgcp/mgcp_network.c | 73 +++++++++++++++-------------------------- 1 file changed, 26 insertions(+), 47 deletions(-) diff --git a/openbsc/src/mgcp/mgcp_network.c b/openbsc/src/mgcp/mgcp_network.c index ae0504ff9..c90219774 100644 --- a/openbsc/src/mgcp/mgcp_network.c +++ b/openbsc/src/mgcp/mgcp_network.c @@ -511,68 +511,47 @@ cleanup0: return -1; } -int mgcp_bind_bts_rtp_port(struct mgcp_endpoint *endp, int rtp_port) +static int int_bind(const char *port, + struct mgcp_rtp_end *end, int (*cb)(struct bsc_fd *, unsigned), + struct mgcp_endpoint *_endp, int rtp_port) { - if (endp->bts_end.rtp.fd != -1 || endp->bts_end.rtcp.fd != -1) { - LOGP(DMGCP, LOGL_ERROR, "Previous bts-port was still bound on %d\n", - ENDPOINT_NUMBER(endp)); - mgcp_free_rtp_port(&endp->bts_end); + if (end->rtp.fd != -1 || end->rtcp.fd != -1) { + LOGP(DMGCP, LOGL_ERROR, "Previous %s was still bound on %d\n", + port, ENDPOINT_NUMBER(_endp)); + mgcp_free_rtp_port(end); } - endp->bts_end.local_port = rtp_port; - endp->bts_end.rtp.cb = rtp_data_bts; - endp->bts_end.rtp.data = endp; - endp->bts_end.rtcp.data = endp; - endp->bts_end.rtcp.cb = rtp_data_bts; - return bind_rtp(endp->cfg, &endp->bts_end, ENDPOINT_NUMBER(endp)); + end->local_port = rtp_port; + end->rtp.cb = cb; + end->rtp.data = _endp; + end->rtcp.data = _endp; + end->rtcp.cb = cb; + return bind_rtp(_endp->cfg, end, ENDPOINT_NUMBER(_endp)); } -int mgcp_bind_net_rtp_port(struct mgcp_endpoint *endp, int rtp_port) + +int mgcp_bind_bts_rtp_port(struct mgcp_endpoint *endp, int rtp_port) { - if (endp->net_end.rtp.fd != -1 || endp->net_end.rtcp.fd != -1) { - LOGP(DMGCP, LOGL_ERROR, "Previous net-port was still bound on %d\n", - ENDPOINT_NUMBER(endp)); - mgcp_free_rtp_port(&endp->net_end); - } + return int_bind("bts-port", &endp->bts_end, + rtp_data_bts, endp, rtp_port); +} - endp->net_end.local_port = rtp_port; - endp->net_end.rtp.cb = rtp_data_net; - endp->net_end.rtp.data = endp; - endp->net_end.rtcp.data = endp; - endp->net_end.rtcp.cb = rtp_data_net; - return bind_rtp(endp->cfg, &endp->net_end, ENDPOINT_NUMBER(endp)); +int mgcp_bind_net_rtp_port(struct mgcp_endpoint *endp, int rtp_port) +{ + return int_bind("net-port", &endp->net_end, + rtp_data_net, endp, 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", - ENDPOINT_NUMBER(endp)); - mgcp_free_rtp_port(&endp->trans_net); - } - - endp->trans_net.local_port = rtp_port; - endp->trans_net.rtp.cb = rtp_data_transcoder; - endp->trans_net.rtp.data = endp; - endp->trans_net.rtcp.data = endp; - endp->trans_net.rtcp.cb = rtp_data_transcoder; - return bind_rtp(endp->cfg, &endp->trans_net, ENDPOINT_NUMBER(endp)); + return int_bind("trans-net", &endp->trans_net, + rtp_data_transcoder, endp, rtp_port); } 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)); + return int_bind("trans-bts", &endp->trans_bts, + rtp_data_transcoder, endp, rtp_port); } int mgcp_free_rtp_port(struct mgcp_rtp_end *end) -- cgit v1.2.3 From 3f29cc8303ecca6ba9f814abd9d5241f51d25533 Mon Sep 17 00:00:00 2001 From: Holger Hans Peter Freyther Date: Mon, 1 Nov 2010 21:25:33 +0100 Subject: mgcp: Make the transcoding forwarding work for BTS/NET Share the implementation for the transcoded packets and forward them to the network and the bts. --- openbsc/src/mgcp/mgcp_network.c | 52 ++++++++++++++++++++++++++--------------- 1 file changed, 33 insertions(+), 19 deletions(-) diff --git a/openbsc/src/mgcp/mgcp_network.c b/openbsc/src/mgcp/mgcp_network.c index c90219774..aeaafc8af 100644 --- a/openbsc/src/mgcp/mgcp_network.c +++ b/openbsc/src/mgcp/mgcp_network.c @@ -389,47 +389,61 @@ static int rtp_data_bts(struct bsc_fd *fd, unsigned int what) return send_to(endp, DEST_NETWORK, proto == PROTO_RTP, &addr, &buf[0], rc); } -static int rtp_data_transcoder(struct bsc_fd *fd, unsigned int what) +static int rtp_data_transcoder(struct mgcp_rtp_end *end, struct mgcp_endpoint *_endp, + int dest, struct bsc_fd *fd) { char buf[4096]; struct sockaddr_in addr; - struct mgcp_endpoint *endp; struct mgcp_config *cfg; int rc, proto; - endp = (struct mgcp_endpoint *) fd->data; - cfg = endp->cfg; - - rc = recevice_from(endp, fd->fd, &addr, buf, sizeof(buf)); + cfg = _endp->cfg; + rc = recevice_from(_endp, fd->fd, &addr, buf, sizeof(buf)); if (rc <= 0) return -1; - proto = fd == &endp->trans_net.rtp ? PROTO_RTP : PROTO_RTCP; + proto = fd == &end->rtp ? PROTO_RTP : PROTO_RTCP; if (memcmp(&addr.sin_addr, &cfg->transcoder_in, sizeof(addr.sin_addr)) != 0) { LOGP(DMGCP, LOGL_ERROR, - "Data not coming from transcoder: %s on 0x%x\n", - inet_ntoa(addr.sin_addr), ENDPOINT_NUMBER(endp)); + "Data not coming from transcoder dest: %d %s on 0x%x\n", + dest, inet_ntoa(addr.sin_addr), ENDPOINT_NUMBER(_endp)); return -1; } - if (endp->trans_net.rtp_port != addr.sin_port && - endp->trans_net.rtcp_port != addr.sin_port) { + if (end->rtp_port != addr.sin_port && + end->rtcp_port != addr.sin_port) { LOGP(DMGCP, LOGL_ERROR, - "Data from wrong transcoder source port %d on 0x%x\n", - ntohs(addr.sin_port), ENDPOINT_NUMBER(endp)); + "Data from wrong transcoder dest %d source port %d on 0x%x\n", + dest, ntohs(addr.sin_port), ENDPOINT_NUMBER(_endp)); return -1; } /* throw away the dummy message */ if (rc == 1 && buf[0] == DUMMY_LOAD) { - LOGP(DMGCP, LOGL_NOTICE, "Filtered dummy from transcoder on 0x%x\n", - ENDPOINT_NUMBER(endp)); + LOGP(DMGCP, LOGL_NOTICE, "Filtered dummy from transcoder dest %d on 0x%x\n", + dest, ENDPOINT_NUMBER(_endp)); return 0; } - endp->trans_net.packets += 1; - return send_to(endp, DEST_NETWORK, proto == PROTO_RTP, &addr, &buf[0], rc); + end->packets += 1; + return send_to(_endp, dest, proto == PROTO_RTP, &addr, &buf[0], rc); +} + +static int rtp_data_trans_net(struct bsc_fd *fd, unsigned int what) +{ + struct mgcp_endpoint *endp; + endp = (struct mgcp_endpoint *) fd->data; + + return rtp_data_transcoder(&endp->trans_net, endp, DEST_NETWORK, fd); +} + +static int rtp_data_trans_bts(struct bsc_fd *fd, unsigned int what) +{ + struct mgcp_endpoint *endp; + endp = (struct mgcp_endpoint *) fd->data; + + return rtp_data_transcoder(&endp->trans_bts, endp, DEST_BTS, fd); } static int create_bind(const char *source_addr, struct bsc_fd *fd, int port) @@ -545,13 +559,13 @@ int mgcp_bind_net_rtp_port(struct mgcp_endpoint *endp, int rtp_port) int mgcp_bind_trans_net_rtp_port(struct mgcp_endpoint *endp, int rtp_port) { return int_bind("trans-net", &endp->trans_net, - rtp_data_transcoder, endp, rtp_port); + rtp_data_trans_net, endp, rtp_port); } int mgcp_bind_trans_bts_rtp_port(struct mgcp_endpoint *endp, int rtp_port) { return int_bind("trans-bts", &endp->trans_bts, - rtp_data_transcoder, endp, rtp_port); + rtp_data_trans_bts, endp, rtp_port); } int mgcp_free_rtp_port(struct mgcp_rtp_end *end) -- cgit v1.2.3 From 5f2cd842818a8809865d1caacc78bdf92c823e40 Mon Sep 17 00:00:00 2001 From: Holger Hans Peter Freyther Date: Mon, 1 Nov 2010 21:53:39 +0100 Subject: mgcp: Use the calculated remote port from the mgcp_rtp_end --- openbsc/src/mgcp/mgcp_network.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/openbsc/src/mgcp/mgcp_network.c b/openbsc/src/mgcp/mgcp_network.c index aeaafc8af..f8c552c8f 100644 --- a/openbsc/src/mgcp/mgcp_network.c +++ b/openbsc/src/mgcp/mgcp_network.c @@ -182,13 +182,11 @@ static int send_transcoder(struct mgcp_endpoint *endp, int is_rtp, return -1; } - port = rtp_calculate_port(ENDPOINT_NUMBER(endp), cfg->transcoder_remote_base); - if (!is_rtp) - port += 1; + port = is_rtp ? endp->trans_bts.rtp_port : endp->trans_bts.rtcp_port; addr.sin_family = AF_INET; addr.sin_addr = cfg->transcoder_in; - addr.sin_port = htons(port); + addr.sin_port = port; rc = sendto(is_rtp ? endp->trans_bts.rtp.fd : -- cgit v1.2.3 From 8b19dee437cdd73f75413d5f936e768939e3db71 Mon Sep 17 00:00:00 2001 From: Holger Hans Peter Freyther Date: Mon, 1 Nov 2010 22:38:25 +0100 Subject: mgcp: Send data from the network to the transcoder too We now should be able to transcode in both directions. --- openbsc/src/mgcp/mgcp_network.c | 24 ++++++++++-------------- openbsc/src/mgcp/mgcp_protocol.c | 4 ++-- 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/openbsc/src/mgcp/mgcp_network.c b/openbsc/src/mgcp/mgcp_network.c index f8c552c8f..8a73e376e 100644 --- a/openbsc/src/mgcp/mgcp_network.c +++ b/openbsc/src/mgcp/mgcp_network.c @@ -168,29 +168,22 @@ static int forward_data(int fd, struct mgcp_rtp_tap *tap, const char *buf, int l (struct sockaddr *)&tap->forward, sizeof(tap->forward)); } -static int send_transcoder(struct mgcp_endpoint *endp, int is_rtp, - const char *buf, int len) +static int send_transcoder(struct mgcp_rtp_end *end, struct mgcp_config *cfg, + int is_rtp, const char *buf, int len) { int rc; int port; - struct mgcp_config *cfg = endp->cfg; struct sockaddr_in addr; - if (endp->trans_net.rtp_port == 0) { - LOGP(DMGCP, LOGL_ERROR, "Transcoder port not known on 0x%x\n", - ENDPOINT_NUMBER(endp)); - return -1; - } - - port = is_rtp ? endp->trans_bts.rtp_port : endp->trans_bts.rtcp_port; + port = is_rtp ? end->rtp_port : end->rtcp_port; addr.sin_family = AF_INET; addr.sin_addr = cfg->transcoder_in; addr.sin_port = port; rc = sendto(is_rtp ? - endp->trans_bts.rtp.fd : - endp->trans_bts.rtcp.fd, buf, len, 0, + end->rtp.fd : + end->rtcp.fd, buf, len, 0, (struct sockaddr *) &addr, sizeof(addr)); if (rc != len) @@ -304,7 +297,10 @@ static int rtp_data_net(struct bsc_fd *fd, unsigned int what) endp->net_end.packets += 1; forward_data(fd->fd, &endp->taps[MGCP_TAP_NET_IN], buf, rc); - return send_to(endp, DEST_BTS, proto == PROTO_RTP, &addr, &buf[0], rc); + if (endp->is_transcoded) + return send_transcoder(&endp->trans_net, endp->cfg, proto == PROTO_RTP, &buf[0], rc); + else + return send_to(endp, DEST_BTS, proto == PROTO_RTP, &addr, &buf[0], rc); } static void discover_bts(struct mgcp_endpoint *endp, int proto, struct sockaddr_in *addr) @@ -382,7 +378,7 @@ static int rtp_data_bts(struct bsc_fd *fd, unsigned int what) forward_data(fd->fd, &endp->taps[MGCP_TAP_BTS_IN], buf, rc); if (endp->is_transcoded) - return send_transcoder(endp, proto == PROTO_RTP, &buf[0], rc); + return send_transcoder(&endp->trans_bts, endp->cfg, proto == PROTO_RTP, &buf[0], rc); else return send_to(endp, DEST_NETWORK, proto == PROTO_RTP, &addr, &buf[0], rc); } diff --git a/openbsc/src/mgcp/mgcp_protocol.c b/openbsc/src/mgcp/mgcp_protocol.c index 84fd1551e..f8f70679e 100644 --- a/openbsc/src/mgcp/mgcp_protocol.c +++ b/openbsc/src/mgcp/mgcp_protocol.c @@ -942,8 +942,8 @@ static void create_transcoder(struct mgcp_endpoint *endp) if (!endp->is_transcoded) return; - 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, in_endp, endp->trans_bts.local_port, "CRCX", "sendrecv"); + send_msg(endp, in_endp, endp->trans_bts.local_port, "MDCX", "sendrecv"); send_msg(endp, out_endp, endp->trans_net.local_port, "CRCX", "sendrecv"); send_msg(endp, out_endp, endp->trans_net.local_port, "MDCX", "sendrecv"); -- cgit v1.2.3