From 6f6801066bb5890c628d719a864602041644ae62 Mon Sep 17 00:00:00 2001 From: Holger Hans Peter Freyther Date: Sat, 18 Sep 2010 20:40:22 +0800 Subject: mgcp: Keep the gw_fd inside the mgcp_config Move the bfd from a static var into the mgcp_config. --- openbsc/include/openbsc/mgcp.h | 3 +++ openbsc/src/mgcp/mgcp_main.c | 23 +++++++++++------------ 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/openbsc/include/openbsc/mgcp.h b/openbsc/include/openbsc/mgcp.h index 0a0032211..00c5071a3 100644 --- a/openbsc/include/openbsc/mgcp.h +++ b/openbsc/include/openbsc/mgcp.h @@ -25,6 +25,7 @@ #define OPENBSC_MGCP_H #include +#include #include "debug.h" @@ -114,6 +115,8 @@ struct mgcp_config { int audio_payload; int audio_loop; + struct write_queue gw_fd; + struct mgcp_port_range bts_ports; struct mgcp_port_range net_ports; int endp_dscp; diff --git a/openbsc/src/mgcp/mgcp_main.c b/openbsc/src/mgcp/mgcp_main.c index e331159b4..08b0230c5 100644 --- a/openbsc/src/mgcp/mgcp_main.c +++ b/openbsc/src/mgcp/mgcp_main.c @@ -55,7 +55,6 @@ void subscr_put() { abort(); } #warning "Make use of the rtp proxy code" -static struct bsc_fd bfd; static struct mgcp_config *cfg; static int reset_endpoints = 0; static int daemonize = 0; @@ -147,7 +146,7 @@ static int read_call_agent(struct bsc_fd *fd, unsigned int what) msg = (struct msgb *) fd->data; /* read one less so we can use it as a \0 */ - int rc = recvfrom(bfd.fd, msg->data, msg->data_len - 1, 0, + int rc = recvfrom(cfg->gw_fd.bfd.fd, msg->data, msg->data_len - 1, 0, (struct sockaddr *) &addr, &slen); if (rc < 0) { perror("Gateway failed to read"); @@ -164,7 +163,7 @@ static int read_call_agent(struct bsc_fd *fd, unsigned int what) msgb_reset(msg); if (resp) { - sendto(bfd.fd, resp->l2h, msgb_l2len(resp), 0, (struct sockaddr *) &addr, sizeof(addr)); + sendto(cfg->gw_fd.bfd.fd, resp->l2h, msgb_l2len(resp), 0, (struct sockaddr *) &addr, sizeof(addr)); msgb_free(resp); } @@ -228,34 +227,34 @@ int main(int argc, char **argv) /* we need to bind a socket */ if (rc == 0) { - bfd.when = BSC_FD_READ; - bfd.cb = read_call_agent; - bfd.fd = socket(AF_INET, SOCK_DGRAM, 0); - if (bfd.fd < 0) { + cfg->gw_fd.bfd.when = BSC_FD_READ; + cfg->gw_fd.bfd.cb = read_call_agent; + cfg->gw_fd.bfd.fd = socket(AF_INET, SOCK_DGRAM, 0); + if (cfg->gw_fd.bfd.fd < 0) { perror("Gateway failed to listen"); return -1; } - setsockopt(bfd.fd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)); + setsockopt(cfg->gw_fd.bfd.fd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)); memset(&addr, 0, sizeof(addr)); addr.sin_family = AF_INET; addr.sin_port = htons(cfg->source_port); inet_aton(cfg->source_addr, &addr.sin_addr); - if (bind(bfd.fd, (struct sockaddr *) &addr, sizeof(addr)) < 0) { + if (bind(cfg->gw_fd.bfd.fd, (struct sockaddr *) &addr, sizeof(addr)) < 0) { perror("Gateway failed to bind"); return -1; } - bfd.data = msgb_alloc(4096, "mgcp-msg"); - if (!bfd.data) { + cfg->gw_fd.bfd.data = msgb_alloc(4096, "mgcp-msg"); + if (!cfg->gw_fd.bfd.data) { fprintf(stderr, "Gateway memory error.\n"); return -1; } - if (bsc_register_fd(&bfd) != 0) { + if (bsc_register_fd(&cfg->gw_fd.bfd) != 0) { LOGP(DMGCP, LOGL_FATAL, "Failed to register the fd\n"); return -1; } -- cgit v1.2.3 From 249d69a26c5bfdb3adedfa1d822861a200082033 Mon Sep 17 00:00:00 2001 From: Holger Hans Peter Freyther Date: Sat, 18 Sep 2010 21:13:54 +0800 Subject: nat: Use the write_queue inside the CFG. --- openbsc/include/openbsc/bsc_nat.h | 1 - openbsc/src/nat/bsc_mgcp_utils.c | 77 ++++++++++++++++++++------------------- 2 files changed, 39 insertions(+), 39 deletions(-) diff --git a/openbsc/include/openbsc/bsc_nat.h b/openbsc/include/openbsc/bsc_nat.h index 6b2a09940..ff0ee484c 100644 --- a/openbsc/include/openbsc/bsc_nat.h +++ b/openbsc/include/openbsc/bsc_nat.h @@ -190,7 +190,6 @@ struct bsc_nat { /* MGCP config */ struct mgcp_config *mgcp_cfg; - struct write_queue mgcp_queue; uint8_t mgcp_msg[4096]; int mgcp_length; diff --git a/openbsc/src/nat/bsc_mgcp_utils.c b/openbsc/src/nat/bsc_mgcp_utils.c index db0fb743b..2543ea242 100644 --- a/openbsc/src/nat/bsc_mgcp_utils.c +++ b/openbsc/src/nat/bsc_mgcp_utils.c @@ -412,7 +412,7 @@ void bsc_mgcp_forward(struct bsc_connection *bsc, struct msgb *msg) return; } - if (write_queue_enqueue(&bsc->nat->mgcp_queue, output) != 0) { + if (write_queue_enqueue(&bsc->nat->mgcp_cfg->gw_fd, output) != 0) { LOGP(DMGCP, LOGL_ERROR, "Failed to queue MGCP msg.\n"); msgb_free(output); } @@ -562,7 +562,7 @@ static int mgcp_do_read(struct bsc_fd *fd) /* we do have a direct answer... e.g. AUEP */ if (resp) { - if (write_queue_enqueue(&nat->mgcp_queue, resp) != 0) { + if (write_queue_enqueue(&nat->mgcp_cfg->gw_fd, resp) != 0) { LOGP(DMGCP, LOGL_ERROR, "Failed to enqueue msg.\n"); msgb_free(resp); } @@ -589,81 +589,82 @@ int bsc_mgcp_nat_init(struct bsc_nat *nat) { int on; struct sockaddr_in addr; + struct mgcp_config *cfg = nat->mgcp_cfg; - if (!nat->mgcp_cfg->call_agent_addr) { + if (!cfg->call_agent_addr) { LOGP(DMGCP, LOGL_ERROR, "The BSC nat requires the call agent ip to be set.\n"); return -1; } - if (nat->mgcp_cfg->bts_ip) { + if (cfg->bts_ip) { LOGP(DMGCP, LOGL_ERROR, "Do not set the BTS ip for the nat.\n"); return -1; } - nat->mgcp_queue.bfd.fd = socket(AF_INET, SOCK_DGRAM, 0); - if (nat->mgcp_queue.bfd.fd < 0) { + cfg->gw_fd.bfd.fd = socket(AF_INET, SOCK_DGRAM, 0); + if (cfg->gw_fd.bfd.fd < 0) { LOGP(DMGCP, LOGL_ERROR, "Failed to create MGCP socket. errno: %d\n", errno); return -1; } on = 1; - setsockopt(nat->mgcp_queue.bfd.fd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)); + setsockopt(cfg->gw_fd.bfd.fd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)); addr.sin_family = AF_INET; - addr.sin_port = htons(nat->mgcp_cfg->source_port); - inet_aton(nat->mgcp_cfg->source_addr, &addr.sin_addr); + addr.sin_port = htons(cfg->source_port); + inet_aton(cfg->source_addr, &addr.sin_addr); - if (bind(nat->mgcp_queue.bfd.fd, (struct sockaddr *) &addr, sizeof(addr)) < 0) { + if (bind(cfg->gw_fd.bfd.fd, (struct sockaddr *) &addr, sizeof(addr)) < 0) { LOGP(DMGCP, LOGL_ERROR, "Failed to bind. errno: %d\n", errno); - close(nat->mgcp_queue.bfd.fd); - nat->mgcp_queue.bfd.fd = -1; + close(cfg->gw_fd.bfd.fd); + cfg->gw_fd.bfd.fd = -1; return -1; } addr.sin_port = htons(2727); - inet_aton(nat->mgcp_cfg->call_agent_addr, &addr.sin_addr); - if (connect(nat->mgcp_queue.bfd.fd, (struct sockaddr *) &addr, sizeof(addr)) < 0) { + inet_aton(cfg->call_agent_addr, &addr.sin_addr); + if (connect(cfg->gw_fd.bfd.fd, (struct sockaddr *) &addr, sizeof(addr)) < 0) { LOGP(DMGCP, LOGL_ERROR, "Failed to connect to: '%s'. errno: %d\n", - nat->mgcp_cfg->call_agent_addr, errno); - close(nat->mgcp_queue.bfd.fd); - nat->mgcp_queue.bfd.fd = -1; + cfg->call_agent_addr, errno); + close(cfg->gw_fd.bfd.fd); + cfg->gw_fd.bfd.fd = -1; return -1; } - write_queue_init(&nat->mgcp_queue, 10); - nat->mgcp_queue.bfd.when = BSC_FD_READ; - nat->mgcp_queue.bfd.data = nat; - nat->mgcp_queue.read_cb = mgcp_do_read; - nat->mgcp_queue.write_cb = mgcp_do_write; + write_queue_init(&cfg->gw_fd, 10); + cfg->gw_fd.bfd.when = BSC_FD_READ; + cfg->gw_fd.bfd.data = nat; + cfg->gw_fd.read_cb = mgcp_do_read; + cfg->gw_fd.write_cb = mgcp_do_write; - if (bsc_register_fd(&nat->mgcp_queue.bfd) != 0) { + if (bsc_register_fd(&cfg->gw_fd.bfd) != 0) { LOGP(DMGCP, LOGL_ERROR, "Failed to register MGCP fd.\n"); - close(nat->mgcp_queue.bfd.fd); - nat->mgcp_queue.bfd.fd = -1; + close(cfg->gw_fd.bfd.fd); + cfg->gw_fd.bfd.fd = -1; return -1; } /* some more MGCP config handling */ - if (nat->mgcp_cfg->audio_name) - talloc_free(nat->mgcp_cfg->audio_name); - nat->mgcp_cfg->audio_name = NULL; + if (cfg->audio_name) + talloc_free(cfg->audio_name); + cfg->audio_name = NULL; - nat->mgcp_cfg->audio_payload = -1; - nat->mgcp_cfg->data = nat; - nat->mgcp_cfg->policy_cb = bsc_mgcp_policy_cb; - nat->mgcp_cfg->force_realloc = 1; + cfg->audio_payload = -1; + cfg->data = nat; + cfg->policy_cb = bsc_mgcp_policy_cb; + cfg->force_realloc = 1; - if (nat->mgcp_cfg->bts_ip) - talloc_free(nat->mgcp_cfg->bts_ip); - nat->mgcp_cfg->bts_ip = ""; + if (cfg->bts_ip) + talloc_free(cfg->bts_ip); + cfg->bts_ip = ""; nat->bsc_endpoints = talloc_zero_array(nat, struct bsc_endpoint, - nat->mgcp_cfg->number_endpoints + 1); + cfg->number_endpoints + 1); if (!nat->bsc_endpoints) { LOGP(DMGCP, LOGL_ERROR, "Failed to allocate nat endpoints\n"); - close(nat->mgcp_queue.bfd.fd); - nat->mgcp_queue.bfd.fd = -1; + close(cfg->gw_fd.bfd.fd); + cfg->gw_fd.bfd.fd = -1; return -1; } -- cgit v1.2.3 From 985f5694c76245c0f0455f2f3197bbfe663aacde Mon Sep 17 00:00:00 2001 From: Holger Hans Peter Freyther Date: Sun, 19 Sep 2010 04:15:39 +0800 Subject: nat: Keep the audio name and default payload around For all forwarded messages this will not be used, but it is of use for the transcoding. --- openbsc/src/nat/bsc_mgcp_utils.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/openbsc/src/nat/bsc_mgcp_utils.c b/openbsc/src/nat/bsc_mgcp_utils.c index 2543ea242..765952768 100644 --- a/openbsc/src/nat/bsc_mgcp_utils.c +++ b/openbsc/src/nat/bsc_mgcp_utils.c @@ -645,11 +645,6 @@ int bsc_mgcp_nat_init(struct bsc_nat *nat) } /* some more MGCP config handling */ - if (cfg->audio_name) - talloc_free(cfg->audio_name); - cfg->audio_name = NULL; - - cfg->audio_payload = -1; cfg->data = nat; cfg->policy_cb = bsc_mgcp_policy_cb; cfg->force_realloc = 1; -- cgit v1.2.3 From a2a10ebf033e618ec9dc69d8d9089940f540a3a7 Mon Sep 17 00:00:00 2001 From: Holger Hans Peter Freyther Date: Fri, 17 Sep 2010 03:58:52 +0800 Subject: mgcp: Add a transcoder-mgw command to store the address --- openbsc/include/openbsc/mgcp.h | 2 ++ openbsc/src/mgcp/mgcp_vty.c | 17 +++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/openbsc/include/openbsc/mgcp.h b/openbsc/include/openbsc/mgcp.h index 00c5071a3..3f76f6c73 100644 --- a/openbsc/include/openbsc/mgcp.h +++ b/openbsc/include/openbsc/mgcp.h @@ -109,8 +109,10 @@ struct mgcp_config { unsigned int number_endpoints; char *bts_ip; char *call_agent_addr; + char *transcoder_ip; struct in_addr bts_in; + struct in_addr transcoder_in; char *audio_name; int audio_payload; int audio_loop; diff --git a/openbsc/src/mgcp/mgcp_vty.c b/openbsc/src/mgcp/mgcp_vty.c index e86ce7d7d..b1c006cb8 100644 --- a/openbsc/src/mgcp/mgcp_vty.c +++ b/openbsc/src/mgcp/mgcp_vty.c @@ -78,6 +78,8 @@ static int config_write_mgcp(struct vty *vty) vty_out(vty, " number endpoints %u%s", g_cfg->number_endpoints - 1, VTY_NEWLINE); if (g_cfg->call_agent_addr) vty_out(vty, " call agent ip %s%s", g_cfg->call_agent_addr, VTY_NEWLINE); + if (g_cfg->transcoder_ip) + vty_out(vty, " transcoder-mgw %s%s", g_cfg->transcoder_ip, VTY_NEWLINE); return CMD_SUCCESS; } @@ -282,6 +284,20 @@ DEFUN(cfg_mgcp_agent_addr, return CMD_SUCCESS; } +DEFUN(cfg_mgcp_transcoder, + cfg_mgcp_transcoder_cmd, + "transcoder-mgw A.B.C.D", + "Use a MGW to detranscoder RTP\n" + "The IP address of the MGW") +{ + if (g_cfg->transcoder_ip) + talloc_free(g_cfg->transcoder_ip); + g_cfg->transcoder_ip = talloc_strdup(g_cfg, argv[0]); + inet_aton(g_cfg->transcoder_ip, &g_cfg->transcoder_in); + + return CMD_SUCCESS; +} + DEFUN(loop_endp, loop_endp_cmd, "loop-endpoint NAME (0|1)", @@ -403,6 +419,7 @@ int mgcp_vty_init(void) install_element(MGCP_NODE, &cfg_mgcp_loop_cmd); 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); return 0; } -- cgit v1.2.3 From c5f9248c3f3027e7ca44ae8593e7a74da190146c Mon Sep 17 00:00:00 2001 From: Holger Hans Peter Freyther Date: Fri, 17 Sep 2010 23:34:36 +0800 Subject: mgcp: Share the range parsing code for net/bts --- openbsc/src/mgcp/mgcp_vty.c | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/openbsc/src/mgcp/mgcp_vty.c b/openbsc/src/mgcp/mgcp_vty.c index b1c006cb8..b222f65de 100644 --- a/openbsc/src/mgcp/mgcp_vty.c +++ b/openbsc/src/mgcp/mgcp_vty.c @@ -167,14 +167,28 @@ DEFUN(cfg_mgcp_bind_early, return CMD_WARNING; } +static void parse_base(struct mgcp_port_range *range, const char **argv) +{ + unsigned int port = atoi(argv[0]); + range->mode = PORT_ALLOC_STATIC; + range->base_port = port; +} + +static void parse_range(struct mgcp_port_range *range, const char **argv) +{ + range->mode = PORT_ALLOC_DYNAMIC; + range->range_start = atoi(argv[0]); + range->range_end = atoi(argv[1]); + range->last_port = g_cfg->bts_ports.range_start; +} + + DEFUN(cfg_mgcp_rtp_bts_base_port, cfg_mgcp_rtp_bts_base_port_cmd, "rtp bts-base <0-65534>", "Base port to use") { - unsigned int port = atoi(argv[0]); - g_cfg->bts_ports.mode = PORT_ALLOC_STATIC; - g_cfg->bts_ports.base_port = port; + parse_base(&g_cfg->bts_ports, argv); return CMD_SUCCESS; } @@ -184,10 +198,7 @@ DEFUN(cfg_mgcp_rtp_bts_range, "Range of ports to allocate for endpoints\n" "Start of the range of ports\n" "End of the range of ports\n") { - g_cfg->bts_ports.mode = PORT_ALLOC_DYNAMIC; - g_cfg->bts_ports.range_start = atoi(argv[0]); - g_cfg->bts_ports.range_end = atoi(argv[1]); - g_cfg->bts_ports.last_port = g_cfg->bts_ports.range_start; + parse_range(&g_cfg->bts_ports, argv); return CMD_SUCCESS; } @@ -197,10 +208,7 @@ DEFUN(cfg_mgcp_rtp_net_range, "Range of ports to allocate for endpoints\n" "Start of the range of ports\n" "End of the range of ports\n") { - g_cfg->net_ports.mode = PORT_ALLOC_DYNAMIC; - g_cfg->net_ports.range_start = atoi(argv[0]); - g_cfg->net_ports.range_end = atoi(argv[1]); - g_cfg->net_ports.last_port = g_cfg->net_ports.range_start; + parse_range(&g_cfg->net_ports, argv); return CMD_SUCCESS; } @@ -209,9 +217,7 @@ DEFUN(cfg_mgcp_rtp_net_base_port, "rtp net-base <0-65534>", "Base port to use for network port\n" "Port\n") { - unsigned int port = atoi(argv[0]); - g_cfg->net_ports.mode = PORT_ALLOC_STATIC; - g_cfg->net_ports.base_port = port; + parse_base(&g_cfg->net_ports, argv); return CMD_SUCCESS; } -- cgit v1.2.3 From 54aaa0fbedf6a966b3cabd6585c987969c4c13d4 Mon Sep 17 00:00:00 2001 From: Holger Hans Peter Freyther Date: Fri, 17 Sep 2010 23:35:53 +0800 Subject: mgcp: Add ports for the transcoder as well --- openbsc/include/openbsc/mgcp.h | 1 + openbsc/src/mgcp/mgcp_vty.c | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/openbsc/include/openbsc/mgcp.h b/openbsc/include/openbsc/mgcp.h index 3f76f6c73..0e45f521d 100644 --- a/openbsc/include/openbsc/mgcp.h +++ b/openbsc/include/openbsc/mgcp.h @@ -121,6 +121,7 @@ struct mgcp_config { struct mgcp_port_range bts_ports; struct mgcp_port_range net_ports; + struct mgcp_port_range transcoder_ports; int endp_dscp; /* spec handling */ diff --git a/openbsc/src/mgcp/mgcp_vty.c b/openbsc/src/mgcp/mgcp_vty.c index b222f65de..b60357096 100644 --- a/openbsc/src/mgcp/mgcp_vty.c +++ b/openbsc/src/mgcp/mgcp_vty.c @@ -81,6 +81,12 @@ static int config_write_mgcp(struct vty *vty) if (g_cfg->transcoder_ip) vty_out(vty, " transcoder-mgw %s%s", g_cfg->transcoder_ip, VTY_NEWLINE); + if (g_cfg->transcoder_ports.mode == PORT_ALLOC_STATIC) + vty_out(vty, " rtp transcoder-base %u%s", g_cfg->transcoder_ports.base_port, VTY_NEWLINE); + else + vty_out(vty, " rtp transcoder-range %u %u%s", + g_cfg->transcoder_ports.range_start, g_cfg->transcoder_ports.range_end, VTY_NEWLINE); + return CMD_SUCCESS; } @@ -224,6 +230,25 @@ DEFUN(cfg_mgcp_rtp_net_base_port, ALIAS_DEPRECATED(cfg_mgcp_rtp_bts_base_port, cfg_mgcp_rtp_base_port_cmd, "rtp base <0-65534>", "Base port to use") +DEFUN(cfg_mgcp_rtp_transcoder_range, + cfg_mgcp_rtp_transcoder_range_cmd, + "rtp transcoder-range <0-65534> <0-65534>", + "Range of ports to allocate for the transcoder\n" + "Start of the range of ports\n" "End of the range of ports\n") +{ + parse_range(&g_cfg->transcoder_ports, argv); + return CMD_SUCCESS; +} + +DEFUN(cfg_mgcp_rtp_transcoder_base, + cfg_mgcp_rtp_transcoder_base_cmd, + "rtp transcoder-base <0-65534>", + "Base port for the transcoder range\n" "Port\n") +{ + parse_base(&g_cfg->transcoder_ports, argv); + return CMD_SUCCESS; +} + DEFUN(cfg_mgcp_rtp_ip_dscp, cfg_mgcp_rtp_ip_dscp_cmd, "rtp ip-dscp <0-255>", @@ -418,6 +443,8 @@ int mgcp_vty_init(void) install_element(MGCP_NODE, &cfg_mgcp_rtp_net_base_port_cmd); install_element(MGCP_NODE, &cfg_mgcp_rtp_bts_range_cmd); install_element(MGCP_NODE, &cfg_mgcp_rtp_net_range_cmd); + install_element(MGCP_NODE, &cfg_mgcp_rtp_transcoder_range_cmd); + install_element(MGCP_NODE, &cfg_mgcp_rtp_transcoder_base_cmd); install_element(MGCP_NODE, &cfg_mgcp_rtp_ip_dscp_cmd); install_element(MGCP_NODE, &cfg_mgcp_rtp_ip_tos_cmd); install_element(MGCP_NODE, &cfg_mgcp_sdp_payload_number_cmd); -- cgit v1.2.3 From 218f8564e1d68c544ff453a4da67fcb24d302e40 Mon Sep 17 00:00:00 2001 From: Holger Hans Peter Freyther Date: Sat, 18 Sep 2010 02:30:02 +0800 Subject: mgcp: Forward data from the BTS-in to the transcoder Bind a new port for the transcoder, forward data from the BTS to the transcoder, and from the transcoder to the network. Leave BTS-IN where it is, BTS-OUT can now be after the transcoding took place. We send the data from the BTS RTP port. This whole route will be guarded by the transcoder_ip and if it is NULL (current default) it will not go through the transcoder. --- openbsc/include/openbsc/mgcp_internal.h | 2 + openbsc/src/mgcp/mgcp_network.c | 97 +++++++++++++++++++++++++++++++++ openbsc/src/mgcp/mgcp_protocol.c | 27 ++++++--- openbsc/src/mgcp/mgcp_vty.c | 10 ++++ 4 files changed, 128 insertions(+), 8 deletions(-) diff --git a/openbsc/include/openbsc/mgcp_internal.h b/openbsc/include/openbsc/mgcp_internal.h index 12e3ad9b1..7c5badc92 100644 --- a/openbsc/include/openbsc/mgcp_internal.h +++ b/openbsc/include/openbsc/mgcp_internal.h @@ -98,6 +98,7 @@ 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; /* sequence bits */ struct mgcp_rtp_state net_state; @@ -123,6 +124,7 @@ 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_free_rtp_port(struct mgcp_rtp_end *end); #endif diff --git a/openbsc/src/mgcp/mgcp_network.c b/openbsc/src/mgcp/mgcp_network.c index 96a186559..6ee268c4c 100644 --- a/openbsc/src/mgcp/mgcp_network.c +++ b/openbsc/src/mgcp/mgcp_network.c @@ -159,6 +159,42 @@ static int forward_data(int fd, struct mgcp_rtp_tap *tap, const char *buf, int l return sendto(fd, buf, len, 0, (struct sockaddr *)&tap->forward, sizeof(tap->forward)); } + +static int send_transcoder(struct mgcp_endpoint *endp, int is_rtp, + const char *buf, int len) +{ + int rc; + int port; + struct mgcp_config *cfg = endp->cfg; + struct sockaddr_in addr; + + if (endp->transcoder_end.rtp_port == 0) { + LOGP(DMGCP, LOGL_ERROR, "Transcoder port not known on 0x%x\n", + ENDPOINT_NUMBER(endp)); + return -1; + } + + port = rtp_calculate_port(ENDPOINT_NUMBER(endp), 4000); + if (!is_rtp) + port += 1; + + addr.sin_family = AF_INET; + addr.sin_addr = cfg->transcoder_in; + addr.sin_port = htons(port); + + rc = sendto(is_rtp ? + endp->bts_end.rtp.fd : + endp->bts_end.rtcp.fd, buf, len, 0, + (struct sockaddr *) &addr, sizeof(addr)); + + if (rc != len) + LOGP(DMGCP, LOGL_ERROR, + "Failed to send data to the transcoder: %s\n", + strerror(errno)); + + return rc; +} + static int send_to(struct mgcp_endpoint *endp, int dest, int is_rtp, struct sockaddr_in *addr, char *buf, int rc) { @@ -339,6 +375,51 @@ 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) + return send_transcoder(endp, proto == PROTO_RTP, &buf[0], rc); + else + 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) +{ + 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)); + if (rc <= 0) + return -1; + + proto = fd == &endp->transcoder_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)); + return -1; + } + + if (endp->transcoder_end.rtp_port != addr.sin_port && + endp->transcoder_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)); + 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)); + return 0; + } + return send_to(endp, DEST_NETWORK, proto == PROTO_RTP, &addr, &buf[0], rc); } @@ -453,6 +534,22 @@ 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) +{ + if (endp->transcoder_end.rtp.fd != -1 || endp->transcoder_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->transcoder_end); + } + + 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)); +} + 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 943fd0b6b..80100061d 100644 --- a/openbsc/src/mgcp/mgcp_protocol.c +++ b/openbsc/src/mgcp/mgcp_protocol.c @@ -373,7 +373,8 @@ static int parse_conn_mode(const char *msg, int *conn_mode) } static int allocate_port(struct mgcp_endpoint *endp, struct mgcp_rtp_end *end, - struct mgcp_port_range *range, int for_net) + struct mgcp_port_range *range, + int (*alloc)(struct mgcp_endpoint *endp, int port)) { int i; @@ -390,9 +391,7 @@ static int allocate_port(struct mgcp_endpoint *endp, struct mgcp_rtp_end *end, if (range->last_port >= range->range_end) range->last_port = range->range_start; - rc = for_net ? - mgcp_bind_net_rtp_port(endp, range->last_port) : - mgcp_bind_bts_rtp_port(endp, range->last_port); + rc = alloc(endp, range->last_port); range->last_port += 2; if (rc == 0) { @@ -402,21 +401,31 @@ static int allocate_port(struct mgcp_endpoint *endp, struct mgcp_rtp_end *end, } - LOGP(DMGCP, LOGL_ERROR, "Allocating a RTP/RTCP port failed 200 times 0x%x net: %d\n", - ENDPOINT_NUMBER(endp), for_net); + LOGP(DMGCP, LOGL_ERROR, "Allocating a RTP/RTCP port failed 200 times 0x%x.\n", + ENDPOINT_NUMBER(endp)); return -1; } static int allocate_ports(struct mgcp_endpoint *endp) { - if (allocate_port(endp, &endp->net_end, &endp->cfg->net_ports, 1) != 0) + if (allocate_port(endp, &endp->net_end, &endp->cfg->net_ports, + mgcp_bind_net_rtp_port) != 0) return -1; - if (allocate_port(endp, &endp->bts_end, &endp->cfg->bts_ports, 0) != 0) { + if (allocate_port(endp, &endp->bts_end, &endp->cfg->bts_ports, + mgcp_bind_bts_rtp_port) != 0) { mgcp_rtp_end_reset(&endp->net_end); 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; + } + return 0; } @@ -805,6 +814,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); } return 0; @@ -828,6 +838,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); memset(&endp->net_state, 0, sizeof(endp->net_state)); memset(&endp->bts_state, 0, sizeof(endp->bts_state)); diff --git a/openbsc/src/mgcp/mgcp_vty.c b/openbsc/src/mgcp/mgcp_vty.c index b60357096..d84c3c1d0 100644 --- a/openbsc/src/mgcp/mgcp_vty.c +++ b/openbsc/src/mgcp/mgcp_vty.c @@ -505,6 +505,16 @@ int mgcp_parse_config(const char *config_file, struct mgcp_config *cfg) } endp->net_end.local_alloc = PORT_ALLOC_STATIC; } + + if (g_cfg->transcoder_ip && g_cfg->transcoder_ports.mode == PORT_ALLOC_STATIC) { + rtp_port = rtp_calculate_port(ENDPOINT_NUMBER(endp), + g_cfg->transcoder_ports.base_port); + if (mgcp_bind_transcoder_rtp_port(endp, rtp_port) != 0) { + LOGP(DMGCP, LOGL_FATAL, "Failed to bind: %d\n", rtp_port); + return -1; + } + endp->transcoder_end.local_alloc = PORT_ALLOC_STATIC; + } } return 0; -- cgit v1.2.3 From 3b5e3c4d6ff7835b8139a0d97a78cabac737a7ff Mon Sep 17 00:00:00 2001 From: Holger Hans Peter Freyther Date: Sat, 18 Sep 2010 06:35:29 +0800 Subject: mgcp: Prepare the CRCX/MDCX/DLCX messages for the transcoder. Send CRCX/MDCX/DLCX to the transcoder, fill out transcoder_end with the interesting data and hope that it is going to work. --- openbsc/src/mgcp/mgcp_protocol.c | 102 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) diff --git a/openbsc/src/mgcp/mgcp_protocol.c b/openbsc/src/mgcp/mgcp_protocol.c index 80100061d..6d9a6b405 100644 --- a/openbsc/src/mgcp/mgcp_protocol.c +++ b/openbsc/src/mgcp/mgcp_protocol.c @@ -89,6 +89,9 @@ static struct msgb *handle_delete_con(struct mgcp_config *cfg, struct msgb *msg) static struct msgb *handle_modify_con(struct mgcp_config *cfg, struct msgb *msg); static struct msgb *handle_rsip(struct mgcp_config *cfg, struct msgb *msg); +static void create_transcoder(struct mgcp_endpoint *endp); +static void delete_transcoder(struct mgcp_endpoint *endp); + static uint32_t generate_call_id(struct mgcp_config *cfg) { int i; @@ -512,6 +515,7 @@ static struct msgb *handle_create_con(struct mgcp_config *cfg, struct msgb *msg) break; case MGCP_POLICY_DEFER: /* stop processing */ + create_transcoder(endp); return NULL; break; case MGCP_POLICY_CONT: @@ -526,6 +530,7 @@ static struct msgb *handle_create_con(struct mgcp_config *cfg, struct msgb *msg) if (cfg->change_cb) cfg->change_cb(cfg, ENDPOINT_NUMBER(endp), MGCP_ENDP_CRCX); + create_transcoder(endp); return create_response_with_sdp(endp, "CRCX", trans_id); error: LOGP(DMGCP, LOGL_ERROR, "Malformed line: %s on 0x%x with: line_start: %d %d\n", @@ -719,6 +724,7 @@ static struct msgb *handle_delete_con(struct mgcp_config *cfg, struct msgb *msg) break; case MGCP_POLICY_DEFER: /* stop processing */ + delete_transcoder(endp); return NULL; break; case MGCP_POLICY_CONT: @@ -730,6 +736,8 @@ static struct msgb *handle_delete_con(struct mgcp_config *cfg, struct msgb *msg) /* free the connection */ LOGP(DMGCP, LOGL_DEBUG, "Deleted endpoint on: 0x%x Server: %s:%u\n", ENDPOINT_NUMBER(endp), inet_ntoa(endp->net_end.addr), ntohs(endp->net_end.rtp_port)); + + delete_transcoder(endp); mgcp_free_endp(endp); if (cfg->change_cb) cfg->change_cb(cfg, ENDPOINT_NUMBER(endp), MGCP_ENDP_DLCX); @@ -848,3 +856,97 @@ 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 void send_msg(struct mgcp_endpoint *endp, int endpoint, int port, + const char *msg, const char *mode) +{ + struct sockaddr_in addr; + char buf[2096]; + int len; + + /* hardcoded to AMR right now, we do not know the real type at this point */ + len = snprintf(buf, sizeof(buf), + "%s 42 %x@mgw MGCP 1.0\r\n" + "C: 4256\r\n" + "M: %s\r\n" + "\r\n" + "c=IN IP4 %s\r\n" + "m=audio %d RTP/AVP %d\r\n" + "a=rtpmap:%d %s\r\n", + msg, endpoint, mode, endp->cfg->source_addr, + port, endp->cfg->audio_payload, + endp->cfg->audio_payload, endp->cfg->audio_name); + + if (len < 0) + return; + + buf[sizeof(buf) - 1] = '\0'; + + memset(&addr, 0, sizeof(addr)); + addr.sin_family = AF_INET; + addr.sin_addr = endp->cfg->transcoder_in; + addr.sin_port = htons(2427); + sendto(endp->cfg->gw_fd.bfd.fd, buf, len, 0, + (struct sockaddr *) &addr, sizeof(addr)); +} + +static void send_dlcx(struct mgcp_endpoint *endp, int endpoint) +{ + struct sockaddr_in addr; + char buf[2096]; + int len; + + len = snprintf(buf, sizeof(buf), + "DLCX 43 %x@mgw MGCP 1.0\r\n" + "C: 4256\r\n" + , endpoint); + + if (len < 0) + return; + + buf[sizeof(buf) - 1] = '\0'; + + memset(&addr, 0, sizeof(addr)); + addr.sin_family = AF_INET; + addr.sin_addr = endp->cfg->transcoder_in; + addr.sin_port = htons(2427); + sendto(endp->cfg->gw_fd.bfd.fd, buf, len, 0, + (struct sockaddr *) &addr, sizeof(addr)); +} + +static void create_transcoder(struct mgcp_endpoint *endp) +{ + int port; + int in_endp = ENDPOINT_NUMBER(endp); + int out_endp = back_channel(in_endp); + + if (!endp->cfg->transcoder_ip) + 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, out_endp, endp->transcoder_end.local_port, "CRCX", "sendrecv"); + send_msg(endp, out_endp, endp->transcoder_end.local_port, "MDCX", "sendrecv"); + + port = rtp_calculate_port(out_endp, 4000); + endp->transcoder_end.rtp_port = htons(port); + endp->transcoder_end.rtcp_port = htons(port + 1); +} + +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) + return; + + send_dlcx(endp, in_endp); + send_dlcx(endp, out_endp); +} -- cgit v1.2.3 From b98ba72e0a413a9d325fa8ed20cb77d28d472e2f Mon Sep 17 00:00:00 2001 From: Holger Hans Peter Freyther Date: Sun, 19 Sep 2010 04:21:39 +0800 Subject: mgcp: Make the base port of the transcoder configurable The code assumes a static mapping from endpoint to RTP port, be able to configure the start of such a mapping. --- openbsc/include/openbsc/mgcp.h | 7 +++++-- openbsc/src/mgcp/mgcp_network.c | 2 +- openbsc/src/mgcp/mgcp_protocol.c | 3 ++- openbsc/src/mgcp/mgcp_vty.c | 12 ++++++++++++ 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/openbsc/include/openbsc/mgcp.h b/openbsc/include/openbsc/mgcp.h index 0e45f521d..4adea96b8 100644 --- a/openbsc/include/openbsc/mgcp.h +++ b/openbsc/include/openbsc/mgcp.h @@ -109,14 +109,17 @@ struct mgcp_config { unsigned int number_endpoints; char *bts_ip; char *call_agent_addr; - char *transcoder_ip; struct in_addr bts_in; - struct in_addr transcoder_in; char *audio_name; int audio_payload; int audio_loop; + /* transcoder handling */ + char *transcoder_ip; + struct in_addr transcoder_in; + int transcoder_remote_base; + struct write_queue gw_fd; struct mgcp_port_range bts_ports; diff --git a/openbsc/src/mgcp/mgcp_network.c b/openbsc/src/mgcp/mgcp_network.c index 6ee268c4c..96f35df7e 100644 --- a/openbsc/src/mgcp/mgcp_network.c +++ b/openbsc/src/mgcp/mgcp_network.c @@ -174,7 +174,7 @@ static int send_transcoder(struct mgcp_endpoint *endp, int is_rtp, return -1; } - port = rtp_calculate_port(ENDPOINT_NUMBER(endp), 4000); + port = rtp_calculate_port(ENDPOINT_NUMBER(endp), cfg->transcoder_remote_base); if (!is_rtp) port += 1; diff --git a/openbsc/src/mgcp/mgcp_protocol.c b/openbsc/src/mgcp/mgcp_protocol.c index 6d9a6b405..f18431aa9 100644 --- a/openbsc/src/mgcp/mgcp_protocol.c +++ b/openbsc/src/mgcp/mgcp_protocol.c @@ -780,6 +780,7 @@ struct mgcp_config *mgcp_config_alloc(void) cfg->source_addr = talloc_strdup(cfg, "0.0.0.0"); cfg->audio_name = talloc_strdup(cfg, "AMR/8000"); cfg->audio_payload = 126; + cfg->transcoder_remote_base = 4000; cfg->bts_ports.base_port = RTP_PORT_DEFAULT; cfg->net_ports.base_port = RTP_PORT_NET_DEFAULT; @@ -934,7 +935,7 @@ static void create_transcoder(struct mgcp_endpoint *endp) send_msg(endp, out_endp, endp->transcoder_end.local_port, "CRCX", "sendrecv"); send_msg(endp, out_endp, endp->transcoder_end.local_port, "MDCX", "sendrecv"); - port = rtp_calculate_port(out_endp, 4000); + 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); } diff --git a/openbsc/src/mgcp/mgcp_vty.c b/openbsc/src/mgcp/mgcp_vty.c index d84c3c1d0..d7c649e5b 100644 --- a/openbsc/src/mgcp/mgcp_vty.c +++ b/openbsc/src/mgcp/mgcp_vty.c @@ -86,6 +86,7 @@ static int config_write_mgcp(struct vty *vty) else vty_out(vty, " rtp transcoder-range %u %u%s", g_cfg->transcoder_ports.range_start, g_cfg->transcoder_ports.range_end, VTY_NEWLINE); + vty_out(vty, " transcoder-remote-base %u%s", g_cfg->transcoder_remote_base, VTY_NEWLINE); return CMD_SUCCESS; } @@ -329,6 +330,16 @@ DEFUN(cfg_mgcp_transcoder, return CMD_SUCCESS; } +DEFUN(cfg_mgcp_transcoder_remote_base, + cfg_mgcp_transcoder_remote_base_cmd, + "transcoder-remote-base <0-65534>", + "Set the base port for the transcoder\n" "The RTP base port on the transcoder") +{ + g_cfg->transcoder_remote_base = atoi(argv[0]); + return CMD_SUCCESS; +} + + DEFUN(loop_endp, loop_endp_cmd, "loop-endpoint NAME (0|1)", @@ -453,6 +464,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_transcoder_remote_base_cmd); return 0; } -- cgit v1.2.3 From f2eedff052bd7f92655a32d5a57206018b310aec Mon Sep 17 00:00:00 2001 From: Holger Hans Peter Freyther Date: Sun, 19 Sep 2010 04:36:07 +0800 Subject: nat: Send a transcoder reset on start up. The transcoder RESET is using the same extensions to reset all endpoints on a remote site. This makes sure that all allocations can be made in a properly configured network. --- openbsc/include/openbsc/mgcp.h | 1 + openbsc/src/mgcp/mgcp_protocol.c | 19 +++++++++++++++++++ openbsc/src/nat/bsc_mgcp_utils.c | 9 +++++++++ 3 files changed, 29 insertions(+) diff --git a/openbsc/include/openbsc/mgcp.h b/openbsc/include/openbsc/mgcp.h index 4adea96b8..850396a8a 100644 --- a/openbsc/include/openbsc/mgcp.h +++ b/openbsc/include/openbsc/mgcp.h @@ -146,6 +146,7 @@ int mgcp_parse_config(const char *config_file, struct mgcp_config *cfg); int mgcp_vty_init(void); int mgcp_endpoints_allocate(struct mgcp_config *cfg); void mgcp_free_endp(struct mgcp_endpoint *endp); +int mgcp_reset_transcoder(struct mgcp_config *cfg); /* * format helper functions diff --git a/openbsc/src/mgcp/mgcp_protocol.c b/openbsc/src/mgcp/mgcp_protocol.c index f18431aa9..5abdeaeab 100644 --- a/openbsc/src/mgcp/mgcp_protocol.c +++ b/openbsc/src/mgcp/mgcp_protocol.c @@ -951,3 +951,22 @@ static void delete_transcoder(struct mgcp_endpoint *endp) send_dlcx(endp, in_endp); send_dlcx(endp, out_endp); } + +int mgcp_reset_transcoder(struct mgcp_config *cfg) +{ + struct sockaddr_in addr; + + if (!cfg->transcoder_ip) + return -1; + + static const char mgcp_reset[] = { + "RSIP 1 13@mgw MGCP 1.0\r\n" + }; + + memset(&addr, 0, sizeof(addr)); + addr.sin_family = AF_INET; + addr.sin_addr = cfg->transcoder_in; + addr.sin_port = htons(2427); + return sendto(cfg->gw_fd.bfd.fd, mgcp_reset, sizeof mgcp_reset -1, 0, + (struct sockaddr *) &addr, sizeof(addr)); +} diff --git a/openbsc/src/nat/bsc_mgcp_utils.c b/openbsc/src/nat/bsc_mgcp_utils.c index 765952768..b84a26232 100644 --- a/openbsc/src/nat/bsc_mgcp_utils.c +++ b/openbsc/src/nat/bsc_mgcp_utils.c @@ -663,6 +663,15 @@ int bsc_mgcp_nat_init(struct bsc_nat *nat) return -1; } + if (mgcp_reset_transcoder(cfg) < 0) { + LOGP(DMGCP, LOGL_ERROR, "Failed to send packet to the transcoder.\n"); + talloc_free(nat->bsc_endpoints); + nat->bsc_endpoints = NULL; + close(cfg->gw_fd.bfd.fd); + cfg->gw_fd.bfd.fd = -1; + return -1; + } + return 0; } -- cgit v1.2.3 From 557b1ab15b3a404397e4e728702eb5d0ae33c4e6 Mon Sep 17 00:00:00 2001 From: Holger Hans Peter Freyther Date: Sun, 19 Sep 2010 04:39:55 +0800 Subject: mgcp: Remove code duplication for filling out the sockaddr_in Share the send to transcoder sockaddr sending routines. --- openbsc/src/mgcp/mgcp_protocol.c | 37 +++++++++++++++---------------------- 1 file changed, 15 insertions(+), 22 deletions(-) diff --git a/openbsc/src/mgcp/mgcp_protocol.c b/openbsc/src/mgcp/mgcp_protocol.c index 5abdeaeab..d1699e17f 100644 --- a/openbsc/src/mgcp/mgcp_protocol.c +++ b/openbsc/src/mgcp/mgcp_protocol.c @@ -864,10 +864,21 @@ 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; + + memset(&addr, 0, sizeof(addr)); + addr.sin_family = AF_INET; + addr.sin_addr = cfg->transcoder_in; + addr.sin_port = htons(2427); + return sendto(cfg->gw_fd.bfd.fd, buf, len, 0, + (struct sockaddr *) &addr, sizeof(addr)); +} + static void send_msg(struct mgcp_endpoint *endp, int endpoint, int port, const char *msg, const char *mode) { - struct sockaddr_in addr; char buf[2096]; int len; @@ -889,17 +900,11 @@ static void send_msg(struct mgcp_endpoint *endp, int endpoint, int port, buf[sizeof(buf) - 1] = '\0'; - memset(&addr, 0, sizeof(addr)); - addr.sin_family = AF_INET; - addr.sin_addr = endp->cfg->transcoder_in; - addr.sin_port = htons(2427); - sendto(endp->cfg->gw_fd.bfd.fd, buf, len, 0, - (struct sockaddr *) &addr, sizeof(addr)); + send_trans(endp->cfg, buf, len); } static void send_dlcx(struct mgcp_endpoint *endp, int endpoint) { - struct sockaddr_in addr; char buf[2096]; int len; @@ -913,12 +918,7 @@ static void send_dlcx(struct mgcp_endpoint *endp, int endpoint) buf[sizeof(buf) - 1] = '\0'; - memset(&addr, 0, sizeof(addr)); - addr.sin_family = AF_INET; - addr.sin_addr = endp->cfg->transcoder_in; - addr.sin_port = htons(2427); - sendto(endp->cfg->gw_fd.bfd.fd, buf, len, 0, - (struct sockaddr *) &addr, sizeof(addr)); + send_trans(endp->cfg, buf, len); } static void create_transcoder(struct mgcp_endpoint *endp) @@ -954,8 +954,6 @@ static void delete_transcoder(struct mgcp_endpoint *endp) int mgcp_reset_transcoder(struct mgcp_config *cfg) { - struct sockaddr_in addr; - if (!cfg->transcoder_ip) return -1; @@ -963,10 +961,5 @@ int mgcp_reset_transcoder(struct mgcp_config *cfg) "RSIP 1 13@mgw MGCP 1.0\r\n" }; - memset(&addr, 0, sizeof(addr)); - addr.sin_family = AF_INET; - addr.sin_addr = cfg->transcoder_in; - addr.sin_port = htons(2427); - return sendto(cfg->gw_fd.bfd.fd, mgcp_reset, sizeof mgcp_reset -1, 0, - (struct sockaddr *) &addr, sizeof(addr)); + return send_trans(cfg, mgcp_reset, sizeof mgcp_reset -1); } -- cgit v1.2.3 From 9aa8a9c5a7f35770582bdb6d564f13caf852f91d Mon Sep 17 00:00:00 2001 From: Holger Hans Peter Freyther Date: Sun, 19 Sep 2010 13:50:52 +0200 Subject: mgcp: Count the packets that arrive on the transcoder --- openbsc/src/mgcp/mgcp_network.c | 1 + openbsc/src/mgcp/mgcp_vty.c | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/openbsc/src/mgcp/mgcp_network.c b/openbsc/src/mgcp/mgcp_network.c index 96f35df7e..5c57bf49a 100644 --- a/openbsc/src/mgcp/mgcp_network.c +++ b/openbsc/src/mgcp/mgcp_network.c @@ -420,6 +420,7 @@ static int rtp_data_transcoder(struct bsc_fd *fd, unsigned int what) return 0; } + endp->transcoder_end.packets += 1; return send_to(endp, DEST_NETWORK, proto == PROTO_RTP, &addr, &buf[0], rc); } diff --git a/openbsc/src/mgcp/mgcp_vty.c b/openbsc/src/mgcp/mgcp_vty.c index d7c649e5b..a9845a12f 100644 --- a/openbsc/src/mgcp/mgcp_vty.c +++ b/openbsc/src/mgcp/mgcp_vty.c @@ -99,13 +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%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%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->transcoder_end.packets, VTY_NEWLINE); } -- cgit v1.2.3