blob: d101ded9b9af734a55f0d5e5753c0efa05d91e92 [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
30#include <osmocom/legacy_mgcp/vty.h>
31#include <osmocom/legacy_mgcp/mgcpgw_client.h>
32
33#define MGCPGW_STR "MGCP gateway configuration for RTP streams\n"
34
35void *global_mgcpgw_client_ctx = NULL;
36struct mgcpgw_client_conf *global_mgcpgw_client_conf = NULL;
37
38DEFUN(cfg_mgcpgw_local_ip, cfg_mgcpgw_local_ip_cmd,
39 "mgcpgw local-ip A.B.C.D",
40 MGCPGW_STR "local bind to connect to MGCP gateway with\n"
41 "local bind IP address\n")
42{
43 if (!global_mgcpgw_client_conf)
44 return CMD_ERR_NOTHING_TODO;
45 OSMO_ASSERT(global_mgcpgw_client_ctx);
46 global_mgcpgw_client_conf->local_addr =
47 talloc_strdup(global_mgcpgw_client_ctx, argv[0]);
48 return CMD_SUCCESS;
49}
50
51DEFUN(cfg_mgcpgw_local_port, cfg_mgcpgw_local_port_cmd,
52 "mgcpgw local-port <0-65535>",
53 MGCPGW_STR "local bind to connect to MGCP gateway with\n"
54 "local bind port\n")
55{
56 if (!global_mgcpgw_client_conf)
57 return CMD_ERR_NOTHING_TODO;
58 global_mgcpgw_client_conf->local_port = atoi(argv[0]);
59 return CMD_SUCCESS;
60}
61
62DEFUN(cfg_mgcpgw_remote_ip, cfg_mgcpgw_remote_ip_cmd,
63 "mgcpgw remote-ip A.B.C.D",
64 MGCPGW_STR "remote bind to connect to MGCP gateway with\n"
65 "remote bind IP address\n")
66{
67 if (!global_mgcpgw_client_conf)
68 return CMD_ERR_NOTHING_TODO;
69 OSMO_ASSERT(global_mgcpgw_client_ctx);
70 global_mgcpgw_client_conf->remote_addr =
71 talloc_strdup(global_mgcpgw_client_ctx, argv[0]);
72 return CMD_SUCCESS;
73}
74
75DEFUN(cfg_mgcpgw_remote_port, cfg_mgcpgw_remote_port_cmd,
76 "mgcpgw remote-port <0-65535>",
77 MGCPGW_STR "remote bind to connect to MGCP gateway with\n"
78 "remote bind port\n")
79{
80 if (!global_mgcpgw_client_conf)
81 return CMD_ERR_NOTHING_TODO;
82 global_mgcpgw_client_conf->remote_port = atoi(argv[0]);
83 return CMD_SUCCESS;
84}
85
86DEFUN(cfg_mgcpgw_endpoint_range, cfg_mgcpgw_endpoint_range_cmd,
87 "mgcpgw endpoint-range <1-65534> <1-65534>",
88 MGCPGW_STR "usable range of endpoint identifiers\n"
89 "set first useable endpoint identifier\n"
90 "set the last useable endpoint identifier\n")
91{
92 uint16_t first_endpoint = atoi(argv[0]);
93 uint16_t last_endpoint = atoi(argv[1]);
94
95 if (last_endpoint < first_endpoint) {
96 vty_out(vty, "last endpoint must be greater than first endpoint!%s",
97 VTY_NEWLINE);
98 return CMD_SUCCESS;
99 }
100
101 global_mgcpgw_client_conf->first_endpoint = first_endpoint;
102 global_mgcpgw_client_conf->last_endpoint = last_endpoint;
103 return CMD_SUCCESS;
104}
105
106#define BTS_START_STR "First UDP port allocated for the BTS side\n"
107#define UDP_PORT_STR "UDP Port number\n"
108DEFUN(cfg_mgcp_rtp_bts_base_port,
109 cfg_mgcp_rtp_bts_base_port_cmd,
110 "mgcpgw bts-base <0-65534>",
111 MGCPGW_STR
112 BTS_START_STR
113 UDP_PORT_STR)
114{
115 global_mgcpgw_client_conf->bts_base = atoi(argv[0]);
116 return CMD_SUCCESS;
117}
118
119int mgcpgw_client_config_write(struct vty *vty, const char *indent)
120{
121 const char *addr;
122 int port;
123 uint16_t first_endpoint;
124 uint16_t last_endpoint;
125 uint16_t bts_base;
126
127 addr = global_mgcpgw_client_conf->local_addr;
128 if (addr)
129 vty_out(vty, "%smgcpgw local-ip %s%s", indent, addr,
130 VTY_NEWLINE);
131 port = global_mgcpgw_client_conf->local_port;
132 if (port >= 0)
133 vty_out(vty, "%smgcpgw local-port %u%s", indent,
134 (uint16_t)port, VTY_NEWLINE);
135
136 addr = global_mgcpgw_client_conf->remote_addr;
137 if (addr)
138 vty_out(vty, "%smgcpgw remote-ip %s%s", indent, addr,
139 VTY_NEWLINE);
140 port = global_mgcpgw_client_conf->remote_port;
141 if (port >= 0)
142 vty_out(vty, "%smgcpgw remote-port %u%s", indent,
143 (uint16_t)port, VTY_NEWLINE);
144
145 first_endpoint = global_mgcpgw_client_conf->first_endpoint;
146 last_endpoint = global_mgcpgw_client_conf->last_endpoint;
147 if (last_endpoint != 0) {
148 vty_out(vty, "%smgcpgw endpoint-range %u %u%s", indent,
149 first_endpoint, last_endpoint, VTY_NEWLINE);
150 }
151
152 bts_base = global_mgcpgw_client_conf->bts_base;
153 if (bts_base) {
154 vty_out(vty, "%smgcpgw bts-base %u%s", indent,
155 bts_base, VTY_NEWLINE);
156 }
157
158 return CMD_SUCCESS;
159}
160
161void mgcpgw_client_vty_init(void *talloc_ctx, int node, struct mgcpgw_client_conf *conf)
162{
163 global_mgcpgw_client_ctx = talloc_ctx;
164 global_mgcpgw_client_conf = conf;
165
166 install_element(node, &cfg_mgcpgw_local_ip_cmd);
167 install_element(node, &cfg_mgcpgw_local_port_cmd);
168 install_element(node, &cfg_mgcpgw_remote_ip_cmd);
169 install_element(node, &cfg_mgcpgw_remote_port_cmd);
170 install_element(node, &cfg_mgcpgw_endpoint_range_cmd);
171 install_element(node, &cfg_mgcp_rtp_bts_base_port_cmd);
172}