blob: c52803fec5abf4f8190a7e45242462dbf3aceb27 [file] [log] [blame]
Neels Hofmeyre9920f22017-07-10 15:07:22 +02001/* MGCPGW client interface to quagga VTY */
2/* (C) 2016 by sysmocom s.m.f.c. GmbH <info@sysmocom.de>
3 * Based on OpenBSC interface to quagga VTY (libmsc/vty_interface_layer3.c)
4 * (C) 2009 by Harald Welte <laforge@gnumonks.org>
5 * (C) 2009-2011 by Holger Hans Peter Freyther
6 * All Rights Reserved
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU Affero General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Affero General Public License for more details.
17 *
18 * You should have received a copy of the GNU Affero General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 *
21 */
22
23#include <inttypes.h>
24#include <stdlib.h>
25#include <talloc.h>
26
27#include <osmocom/vty/command.h>
28#include <osmocom/core/utils.h>
29
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +020030#include <osmocom/mgcp_client/mgcp_client.h>
Neels Hofmeyre9920f22017-07-10 15:07:22 +020031
32#define MGCPGW_STR "MGCP gateway configuration for RTP streams\n"
33
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +020034void *global_mgcp_client_ctx = NULL;
35struct mgcp_client_conf *global_mgcp_client_conf = NULL;
Neels Hofmeyre9920f22017-07-10 15:07:22 +020036
37DEFUN(cfg_mgcpgw_local_ip, cfg_mgcpgw_local_ip_cmd,
38 "mgcpgw local-ip A.B.C.D",
39 MGCPGW_STR "local bind to connect to MGCP gateway with\n"
40 "local bind IP address\n")
41{
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +020042 if (!global_mgcp_client_conf)
Neels Hofmeyre9920f22017-07-10 15:07:22 +020043 return CMD_ERR_NOTHING_TODO;
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +020044 OSMO_ASSERT(global_mgcp_client_ctx);
45 global_mgcp_client_conf->local_addr =
46 talloc_strdup(global_mgcp_client_ctx, argv[0]);
Neels Hofmeyre9920f22017-07-10 15:07:22 +020047 return CMD_SUCCESS;
48}
49
50DEFUN(cfg_mgcpgw_local_port, cfg_mgcpgw_local_port_cmd,
51 "mgcpgw local-port <0-65535>",
52 MGCPGW_STR "local bind to connect to MGCP gateway with\n"
53 "local bind port\n")
54{
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +020055 if (!global_mgcp_client_conf)
Neels Hofmeyre9920f22017-07-10 15:07:22 +020056 return CMD_ERR_NOTHING_TODO;
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +020057 global_mgcp_client_conf->local_port = atoi(argv[0]);
Neels Hofmeyre9920f22017-07-10 15:07:22 +020058 return CMD_SUCCESS;
59}
60
61DEFUN(cfg_mgcpgw_remote_ip, cfg_mgcpgw_remote_ip_cmd,
62 "mgcpgw remote-ip A.B.C.D",
63 MGCPGW_STR "remote bind to connect to MGCP gateway with\n"
64 "remote bind IP address\n")
65{
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +020066 if (!global_mgcp_client_conf)
Neels Hofmeyre9920f22017-07-10 15:07:22 +020067 return CMD_ERR_NOTHING_TODO;
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +020068 OSMO_ASSERT(global_mgcp_client_ctx);
69 global_mgcp_client_conf->remote_addr =
70 talloc_strdup(global_mgcp_client_ctx, argv[0]);
Neels Hofmeyre9920f22017-07-10 15:07:22 +020071 return CMD_SUCCESS;
72}
73
74DEFUN(cfg_mgcpgw_remote_port, cfg_mgcpgw_remote_port_cmd,
75 "mgcpgw remote-port <0-65535>",
76 MGCPGW_STR "remote bind to connect to MGCP gateway with\n"
77 "remote bind port\n")
78{
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +020079 if (!global_mgcp_client_conf)
Neels Hofmeyre9920f22017-07-10 15:07:22 +020080 return CMD_ERR_NOTHING_TODO;
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +020081 global_mgcp_client_conf->remote_port = atoi(argv[0]);
Neels Hofmeyre9920f22017-07-10 15:07:22 +020082 return CMD_SUCCESS;
83}
84
85DEFUN(cfg_mgcpgw_endpoint_range, cfg_mgcpgw_endpoint_range_cmd,
86 "mgcpgw endpoint-range <1-65534> <1-65534>",
87 MGCPGW_STR "usable range of endpoint identifiers\n"
88 "set first useable endpoint identifier\n"
89 "set the last useable endpoint identifier\n")
90{
91 uint16_t first_endpoint = atoi(argv[0]);
92 uint16_t last_endpoint = atoi(argv[1]);
93
94 if (last_endpoint < first_endpoint) {
95 vty_out(vty, "last endpoint must be greater than first endpoint!%s",
96 VTY_NEWLINE);
97 return CMD_SUCCESS;
98 }
99
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +0200100 global_mgcp_client_conf->first_endpoint = first_endpoint;
101 global_mgcp_client_conf->last_endpoint = last_endpoint;
Neels Hofmeyre9920f22017-07-10 15:07:22 +0200102 return CMD_SUCCESS;
103}
104
105#define BTS_START_STR "First UDP port allocated for the BTS side\n"
106#define UDP_PORT_STR "UDP Port number\n"
107DEFUN(cfg_mgcp_rtp_bts_base_port,
108 cfg_mgcp_rtp_bts_base_port_cmd,
109 "mgcpgw bts-base <0-65534>",
110 MGCPGW_STR
111 BTS_START_STR
112 UDP_PORT_STR)
113{
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +0200114 global_mgcp_client_conf->bts_base = atoi(argv[0]);
Neels Hofmeyre9920f22017-07-10 15:07:22 +0200115 return CMD_SUCCESS;
116}
117
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +0200118int mgcp_client_config_write(struct vty *vty, const char *indent)
Neels Hofmeyre9920f22017-07-10 15:07:22 +0200119{
120 const char *addr;
121 int port;
122 uint16_t first_endpoint;
123 uint16_t last_endpoint;
124 uint16_t bts_base;
125
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +0200126 addr = global_mgcp_client_conf->local_addr;
Neels Hofmeyre9920f22017-07-10 15:07:22 +0200127 if (addr)
128 vty_out(vty, "%smgcpgw local-ip %s%s", indent, addr,
129 VTY_NEWLINE);
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +0200130 port = global_mgcp_client_conf->local_port;
Neels Hofmeyre9920f22017-07-10 15:07:22 +0200131 if (port >= 0)
132 vty_out(vty, "%smgcpgw local-port %u%s", indent,
133 (uint16_t)port, VTY_NEWLINE);
134
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +0200135 addr = global_mgcp_client_conf->remote_addr;
Neels Hofmeyre9920f22017-07-10 15:07:22 +0200136 if (addr)
137 vty_out(vty, "%smgcpgw remote-ip %s%s", indent, addr,
138 VTY_NEWLINE);
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +0200139 port = global_mgcp_client_conf->remote_port;
Neels Hofmeyre9920f22017-07-10 15:07:22 +0200140 if (port >= 0)
141 vty_out(vty, "%smgcpgw remote-port %u%s", indent,
142 (uint16_t)port, VTY_NEWLINE);
143
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +0200144 first_endpoint = global_mgcp_client_conf->first_endpoint;
145 last_endpoint = global_mgcp_client_conf->last_endpoint;
Neels Hofmeyre9920f22017-07-10 15:07:22 +0200146 if (last_endpoint != 0) {
147 vty_out(vty, "%smgcpgw endpoint-range %u %u%s", indent,
148 first_endpoint, last_endpoint, VTY_NEWLINE);
149 }
150
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +0200151 bts_base = global_mgcp_client_conf->bts_base;
Neels Hofmeyre9920f22017-07-10 15:07:22 +0200152 if (bts_base) {
153 vty_out(vty, "%smgcpgw bts-base %u%s", indent,
154 bts_base, VTY_NEWLINE);
155 }
156
157 return CMD_SUCCESS;
158}
159
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +0200160void mgcp_client_vty_init(void *talloc_ctx, int node, struct mgcp_client_conf *conf)
Neels Hofmeyre9920f22017-07-10 15:07:22 +0200161{
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +0200162 global_mgcp_client_ctx = talloc_ctx;
163 global_mgcp_client_conf = conf;
Neels Hofmeyre9920f22017-07-10 15:07:22 +0200164
165 install_element(node, &cfg_mgcpgw_local_ip_cmd);
166 install_element(node, &cfg_mgcpgw_local_port_cmd);
167 install_element(node, &cfg_mgcpgw_remote_ip_cmd);
168 install_element(node, &cfg_mgcpgw_remote_port_cmd);
169 install_element(node, &cfg_mgcpgw_endpoint_range_cmd);
170 install_element(node, &cfg_mgcp_rtp_bts_base_port_cmd);
171}