blob: 6528417a85f5fa72593cd2c24da5aa49c210b01a [file] [log] [blame]
Holger Hans Peter Freyther7942abc2010-09-30 00:34:46 +08001/* VTY code for the Cellmgr */
2/*
Holger Hans Peter Freythera310e532011-01-22 16:34:16 +01003 * (C) 2010-2011 by Holger Hans Peter Freyther <zecke@selfish.org>
4 * (C) 2010-2011 by On-Waves
Holger Hans Peter Freyther7942abc2010-09-30 00:34:46 +08005 * All Rights Reserved
6 *
Holger Hans Peter Freytherde56c222011-01-16 17:45:14 +01007 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
Holger Hans Peter Freyther7942abc2010-09-30 00:34:46 +080010 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Holger Hans Peter Freytherde56c222011-01-16 17:45:14 +010015 * GNU Affero General Public License for more details.
Holger Hans Peter Freyther7942abc2010-09-30 00:34:46 +080016 *
Holger Hans Peter Freytherde56c222011-01-16 17:45:14 +010017 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
Holger Hans Peter Freyther7942abc2010-09-30 00:34:46 +080019 *
20 */
21
22#include <bsc_data.h>
Holger Hans Peter Freyther5b2fe8d2011-01-22 21:09:53 +010023#include <mtp_pcap.h>
Holger Hans Peter Freyther84ec8712011-02-15 20:01:47 +010024#include <msc_connection.h>
Holger Hans Peter Freythercfe9d712011-02-17 20:32:09 +010025#include <ss7_application.h>
Holger Hans Peter Freyther7942abc2010-09-30 00:34:46 +080026
27#include <osmocore/talloc.h>
Holger Hans Peter Freyther0e4e35f2010-09-30 03:04:28 +080028#include <osmocore/gsm48.h>
Holger Hans Peter Freyther7942abc2010-09-30 00:34:46 +080029
30#include <osmocom/vty/command.h>
Holger Hans Peter Freytherfca7b122011-01-22 23:19:44 +010031#include <osmocom/vty/logging.h>
Holger Hans Peter Freyther7942abc2010-09-30 00:34:46 +080032#include <osmocom/vty/vty.h>
33
34#include <unistd.h>
35#include <netdb.h>
36
37#undef PACKAGE_NAME
38#undef PACKAGE_VERSION
39#undef PACKAGE_BUGREPORT
40#undef PACKAGE_TARNAME
41#undef PACKAGE_STRING
42#include <cellmgr_config.h>
43
Holger Hans Peter Freyther2ff47b82011-02-15 20:25:10 +010044extern struct bsc_data *bsc;
Holger Hans Peter Freyther7942abc2010-09-30 00:34:46 +080045
46static struct vty_app_info vty_info = {
47 .name = "Cellmgr-ng",
48 .version = VERSION,
49 .go_parent_cb = NULL,
50};
51
52/* vty code */
53enum cellmgr_node {
54 CELLMGR_NODE = _LAST_OSMOVTY_NODE,
55};
56
57static struct cmd_node cell_node = {
58 CELLMGR_NODE,
59 "%s(cellmgr)#",
60 1,
61};
62
Holger Hans Peter Freyther2656e8f2010-09-30 00:41:37 +080063static int config_write_cell(struct vty *vty)
Holger Hans Peter Freyther7942abc2010-09-30 00:34:46 +080064{
Holger Hans Peter Freythercfe9d712011-02-17 20:32:09 +010065 struct mtp_link_set *set = mtp_link_set_num(bsc, 0);
Holger Hans Peter Freyther84ec8712011-02-15 20:01:47 +010066 struct msc_connection *msc = msc_connection_num(bsc, 0);
Holger Hans Peter Freythercfe9d712011-02-17 20:32:09 +010067 struct ss7_application *app = ss7_application_num(bsc, 0);
Holger Hans Peter Freyther84ec8712011-02-15 20:01:47 +010068
Holger Hans Peter Freyther2656e8f2010-09-30 00:41:37 +080069 vty_out(vty, "cellmgr%s", VTY_NEWLINE);
Holger Hans Peter Freythercfe9d712011-02-17 20:32:09 +010070 vty_out(vty, " mtp dpc %d%s", set->dpc, VTY_NEWLINE);
71 vty_out(vty, " mtp opc %d%s", set->opc, VTY_NEWLINE);
72 vty_out(vty, " mtp sccp-opc %d%s", set->sccp_opc, VTY_NEWLINE);
73 vty_out(vty, " mtp ni %d%s", set->ni, VTY_NEWLINE);
74 vty_out(vty, " mtp spare %d%s", set->spare, VTY_NEWLINE);
75 vty_out(vty, " mtp sltm once %d%s", set->sltm_once, VTY_NEWLINE);
Holger Hans Peter Freyther2ff47b82011-02-15 20:25:10 +010076 if (bsc->udp_ip)
77 vty_out(vty, " udp dest ip %s%s", bsc->udp_ip, VTY_NEWLINE);
78 vty_out(vty, " udp dest port %d%s", bsc->udp_port, VTY_NEWLINE);
79 vty_out(vty, " udp src port %d%s", bsc->src_port, VTY_NEWLINE);
80 vty_out(vty, " udp reset %d%s", bsc->udp_reset_timeout, VTY_NEWLINE);
81 vty_out(vty, " udp number-links %d%s", bsc->udp_nr_links, VTY_NEWLINE);
Holger Hans Peter Freythercfe9d712011-02-17 20:32:09 +010082 vty_out(vty, " isup pass-through %d%s", app->isup_pass, VTY_NEWLINE);
Holger Hans Peter Freyther2656e8f2010-09-30 00:41:37 +080083
Holger Hans Peter Freyther84ec8712011-02-15 20:01:47 +010084 if (msc) {
85 vty_out(vty, " msc ip %s%s", msc->ip, VTY_NEWLINE);
86 vty_out(vty, " msc ip-dscp %d%s", msc->dscp, VTY_NEWLINE);
87 vty_out(vty, " msc token %s%s", msc->token, VTY_NEWLINE);
88 }
89
90
Holger Hans Peter Freyther7942abc2010-09-30 00:34:46 +080091 return CMD_SUCCESS;
92}
93
94DEFUN(cfg_cell, cfg_cell_cmd,
95 "cellmgr", "Configure the Cellmgr")
96{
97 vty->node = CELLMGR_NODE;
98 return CMD_SUCCESS;
99}
100
101DEFUN(cfg_net_dpc, cfg_net_dpc_cmd,
102 "mtp dpc DPC_NR",
103 "Set the DPC to be used.")
104{
Holger Hans Peter Freythercfe9d712011-02-17 20:32:09 +0100105 struct mtp_link_set *set = mtp_link_set_num(bsc, 0);
106 set->dpc = atoi(argv[0]);
Holger Hans Peter Freyther7942abc2010-09-30 00:34:46 +0800107 return CMD_SUCCESS;
108}
109
110DEFUN(cfg_net_opc, cfg_net_opc_cmd,
111 "mtp opc OPC_NR",
112 "Set the OPC to be used.")
113{
Holger Hans Peter Freythercfe9d712011-02-17 20:32:09 +0100114 struct mtp_link_set *set = mtp_link_set_num(bsc, 0);
115 set->opc = atoi(argv[0]);
Holger Hans Peter Freyther7942abc2010-09-30 00:34:46 +0800116 return CMD_SUCCESS;
117}
118
Holger Hans Peter Freyther7a725562011-01-01 13:34:58 +0100119DEFUN(cfg_net_sccp_opc, cfg_net_sccp_opc_cmd,
120 "mtp sccp-opc OPC_NR",
121 "Set the SCCP OPC to be used.")
122{
Holger Hans Peter Freythercfe9d712011-02-17 20:32:09 +0100123 struct mtp_link_set *set = mtp_link_set_num(bsc, 0);
124 set->sccp_opc = atoi(argv[0]);
Holger Hans Peter Freyther7a725562011-01-01 13:34:58 +0100125 return CMD_SUCCESS;
126}
127
Holger Hans Peter Freytherb38b33b2010-11-26 21:21:04 +0100128DEFUN(cfg_net_mtp_ni, cfg_net_mtp_ni_cmd,
129 "mtp ni NR",
130 "Set the MTP NI to be used.\n" "NR")
131{
Holger Hans Peter Freythercfe9d712011-02-17 20:32:09 +0100132 struct mtp_link_set *set = mtp_link_set_num(bsc, 0);
133 set->ni = atoi(argv[0]);
Holger Hans Peter Freytherb38b33b2010-11-26 21:21:04 +0100134 return CMD_SUCCESS;
135}
136
137DEFUN(cfg_net_mtp_spare, cfg_net_mtp_spare_cmd,
138 "mtp spare NR",
139 "Set the MTP Spare to be used.\n" "NR")
140{
Holger Hans Peter Freythercfe9d712011-02-17 20:32:09 +0100141 struct mtp_link_set *set = mtp_link_set_num(bsc, 0);
142 set->spare = atoi(argv[0]);
Holger Hans Peter Freytherb38b33b2010-11-26 21:21:04 +0100143 return CMD_SUCCESS;
144}
145
146
Holger Hans Peter Freyther7942abc2010-09-30 00:34:46 +0800147DEFUN(cfg_udp_dst_ip, cfg_udp_dst_ip_cmd,
148 "udp dest ip IP",
149 "Set the IP when UDP mode is supposed to be used.")
150{
151 struct hostent *hosts;
152 struct in_addr *addr;
153
154 hosts = gethostbyname(argv[0]);
155 if (!hosts || hosts->h_length < 1 || hosts->h_addrtype != AF_INET) {
156 vty_out(vty, "Failed to resolve '%s'%s", argv[0], VTY_NEWLINE);
157 return CMD_WARNING;
158 }
159
160 addr = (struct in_addr *) hosts->h_addr_list[0];
Holger Hans Peter Freyther2ff47b82011-02-15 20:25:10 +0100161 bsc->udp_ip = talloc_strdup(NULL, inet_ntoa(*addr));
Holger Hans Peter Freyther7942abc2010-09-30 00:34:46 +0800162 return CMD_SUCCESS;
163}
164
165DEFUN(cfg_udp_dst_port, cfg_udp_dst_port_cmd,
166 "udp dest port PORT_NR",
167 "If UDP mode is used specify the UDP dest port")
168{
Holger Hans Peter Freyther2ff47b82011-02-15 20:25:10 +0100169 bsc->udp_port = atoi(argv[0]);
Holger Hans Peter Freyther7942abc2010-09-30 00:34:46 +0800170 return CMD_SUCCESS;
171}
172
173DEFUN(cfg_udp_src_port, cfg_udp_src_port_cmd,
174 "udp src port PORT_NR",
175 "Set the UDP source port to be used.")
176{
Holger Hans Peter Freyther2ff47b82011-02-15 20:25:10 +0100177 bsc->src_port = atoi(argv[0]);
Holger Hans Peter Freyther7942abc2010-09-30 00:34:46 +0800178 return CMD_SUCCESS;
179}
180
181DEFUN(cfg_udp_reset, cfg_udp_reset_cmd,
182 "udp reset TIMEOUT",
183 "Set the timeout to take the link down")
184{
Holger Hans Peter Freyther2ff47b82011-02-15 20:25:10 +0100185 bsc->udp_reset_timeout = atoi(argv[0]);
Holger Hans Peter Freyther7942abc2010-09-30 00:34:46 +0800186 return CMD_SUCCESS;
187}
188
Holger Hans Peter Freytherc6bfa272011-01-22 17:06:34 +0100189DEFUN(cfg_udp_nr_links, cfg_udp_nr_links_cmd,
190 "udp number-links <1-32>",
191 "Set the number of links to use\n")
192{
Holger Hans Peter Freyther2ff47b82011-02-15 20:25:10 +0100193 bsc->udp_nr_links = atoi(argv[0]);
Holger Hans Peter Freytherc6bfa272011-01-22 17:06:34 +0100194 return CMD_SUCCESS;
195}
196
Holger Hans Peter Freyther7942abc2010-09-30 00:34:46 +0800197DEFUN(cfg_sltm_once, cfg_sltm_once_cmd,
198 "mtp sltm once (0|1)",
199 "Send SLTMs until the link is established.")
200{
Holger Hans Peter Freythercfe9d712011-02-17 20:32:09 +0100201 struct mtp_link_set *set = mtp_link_set_num(bsc, 0);
202 set->sltm_once = !!atoi(argv[0]);
Holger Hans Peter Freyther7942abc2010-09-30 00:34:46 +0800203 return CMD_SUCCESS;
204}
205
206DEFUN(cfg_msc_ip, cfg_msc_ip_cmd,
207 "msc ip IP",
208 "Set the MSC IP")
209{
210 struct hostent *hosts;
211 struct in_addr *addr;
Holger Hans Peter Freyther84ec8712011-02-15 20:01:47 +0100212 struct msc_connection *msc = msc_connection_num(bsc, 0);
213
214 if (!msc) {
215 vty_out(vty, "%%No MSC Connection defined in this app.%s", VTY_NEWLINE);
216 return CMD_WARNING;
217 }
Holger Hans Peter Freyther7942abc2010-09-30 00:34:46 +0800218
219 hosts = gethostbyname(argv[0]);
220 if (!hosts || hosts->h_length < 1 || hosts->h_addrtype != AF_INET) {
221 vty_out(vty, "Failed to resolve '%s'%s", argv[0], VTY_NEWLINE);
222 return CMD_WARNING;
223 }
224
225 addr = (struct in_addr *) hosts->h_addr_list[0];
226
Holger Hans Peter Freyther84ec8712011-02-15 20:01:47 +0100227 if (msc->ip)
228 talloc_free(msc->ip);
229 msc->ip = talloc_strdup(msc, inet_ntoa(*addr));
Holger Hans Peter Freyther7942abc2010-09-30 00:34:46 +0800230 return CMD_SUCCESS;
231}
232
233DEFUN(cfg_msc_ip_dscp, cfg_msc_ip_dscp_cmd,
234 "msc ip-dscp <0-255>",
235 "Set the IP DSCP on the A-link\n"
236 "Set the DSCP in IP packets to the MSC")
237{
Holger Hans Peter Freyther84ec8712011-02-15 20:01:47 +0100238 struct msc_connection *msc = msc_connection_num(bsc, 0);
239
240 if (!msc) {
241 vty_out(vty, "%%No MSC Connection defined in this app.%s", VTY_NEWLINE);
242 return CMD_WARNING;
243 }
244
245 msc->dscp = atoi(argv[0]);
Holger Hans Peter Freyther7942abc2010-09-30 00:34:46 +0800246 return CMD_SUCCESS;
247}
248
249ALIAS_DEPRECATED(cfg_msc_ip_dscp, cfg_msc_ip_tos_cmd,
250 "msc ip-tos <0-255>",
251 "Set the IP DSCP on the A-link\n"
252 "Set the DSCP in IP packets to the MSC")
253
254DEFUN(cfg_msc_token, cfg_msc_token_cmd,
255 "msc token TOKEN",
256 "Set the Token to be used for the MSC")
257{
Holger Hans Peter Freyther84ec8712011-02-15 20:01:47 +0100258 struct msc_connection *msc = msc_connection_num(bsc, 0);
259
260 if (!msc) {
261 vty_out(vty, "%%No MSC Connection defined in this app.%s", VTY_NEWLINE);
262 return CMD_WARNING;
263 }
264
265 if (msc->token)
266 talloc_free(msc->token);
267 msc->token = talloc_strdup(msc, argv[0]);
Holger Hans Peter Freyther7942abc2010-09-30 00:34:46 +0800268 return CMD_SUCCESS;
269}
270
271DEFUN(cfg_ping_time, cfg_ping_time_cmd,
272 "timeout ping NR",
273 "Set the PING interval. Negative to disable it")
274{
Holger Hans Peter Freyther84ec8712011-02-15 20:01:47 +0100275 struct msc_connection *msc = msc_connection_num(bsc, 0);
276
277 if (!msc) {
278 vty_out(vty, "%%No MSC Connection defined in this app.%s", VTY_NEWLINE);
279 return CMD_WARNING;
280 }
281
282 msc->ping_time = atoi(argv[0]);
Holger Hans Peter Freyther7942abc2010-09-30 00:34:46 +0800283 return CMD_SUCCESS;
284}
285
286DEFUN(cfg_pong_time, cfg_pong_time_cmd,
287 "timeout pong NR",
288 "Set the PING interval. Negative to disable it")
289{
Holger Hans Peter Freyther84ec8712011-02-15 20:01:47 +0100290 struct msc_connection *msc = msc_connection_num(bsc, 0);
291
292 if (!msc) {
293 vty_out(vty, "%%No MSC Connection defined in this app.%s", VTY_NEWLINE);
294 return CMD_WARNING;
295 }
296
297 msc->pong_time = atoi(argv[0]);
Holger Hans Peter Freyther7942abc2010-09-30 00:34:46 +0800298 return CMD_SUCCESS;
299}
300
301DEFUN(cfg_msc_time, cfg_msc_time_cmd,
302 "timeout msc NR",
303 "Set the MSC connect timeout")
304{
Holger Hans Peter Freyther84ec8712011-02-15 20:01:47 +0100305 struct msc_connection *msc = msc_connection_num(bsc, 0);
306
307 if (!msc) {
308 vty_out(vty, "%%No MSC Connection defined in this app.%s", VTY_NEWLINE);
309 return CMD_WARNING;
310 }
311
312 msc->msc_time = atoi(argv[0]);
Holger Hans Peter Freyther7942abc2010-09-30 00:34:46 +0800313 return CMD_SUCCESS;
314}
315
Holger Hans Peter Freytherf603f282011-01-30 00:24:15 +0100316DEFUN(cfg_isup_pass, cfg_isup_pass_cmd,
317 "isup pass-through (0|1)",
318 "ISUP related functionality\n"
319 "Pass through all ISUP messages directly\n"
320 "Handle some messages locally\n" "Pass through everything\n")
321{
Holger Hans Peter Freythercfe9d712011-02-17 20:32:09 +0100322 struct ss7_application *app = ss7_application_num(bsc, 0);
323 ss7_application_pass_isup(app, atoi(argv[0]));
Holger Hans Peter Freytherf603f282011-01-30 00:24:15 +0100324
325 return CMD_SUCCESS;
326}
327
Holger Hans Peter Freyther29176442011-02-22 16:00:36 +0100328extern void cell_vty_init_cmds(void);
Holger Hans Peter Freyther7942abc2010-09-30 00:34:46 +0800329void cell_vty_init(void)
330{
331 cmd_init(1);
332 vty_init(&vty_info);
Holger Hans Peter Freytherfca7b122011-01-22 23:19:44 +0100333 logging_vty_add_cmds();
Holger Hans Peter Freyther7942abc2010-09-30 00:34:46 +0800334
335 install_element(CONFIG_NODE, &cfg_cell_cmd);
336 install_node(&cell_node, config_write_cell);
337
338 install_element(CELLMGR_NODE, &cfg_net_dpc_cmd);
339 install_element(CELLMGR_NODE, &cfg_net_opc_cmd);
Holger Hans Peter Freyther7a725562011-01-01 13:34:58 +0100340 install_element(CELLMGR_NODE, &cfg_net_sccp_opc_cmd);
Holger Hans Peter Freytherb38b33b2010-11-26 21:21:04 +0100341 install_element(CELLMGR_NODE, &cfg_net_mtp_ni_cmd);
342 install_element(CELLMGR_NODE, &cfg_net_mtp_spare_cmd);
Holger Hans Peter Freyther7942abc2010-09-30 00:34:46 +0800343 install_element(CELLMGR_NODE, &cfg_udp_dst_ip_cmd);
344 install_element(CELLMGR_NODE, &cfg_udp_dst_port_cmd);
345 install_element(CELLMGR_NODE, &cfg_udp_src_port_cmd);
346 install_element(CELLMGR_NODE, &cfg_udp_reset_cmd);
Holger Hans Peter Freytherc6bfa272011-01-22 17:06:34 +0100347 install_element(CELLMGR_NODE, &cfg_udp_nr_links_cmd);
Holger Hans Peter Freyther7942abc2010-09-30 00:34:46 +0800348 install_element(CELLMGR_NODE, &cfg_sltm_once_cmd);
349 install_element(CELLMGR_NODE, &cfg_msc_ip_cmd);
350 install_element(CELLMGR_NODE, &cfg_msc_token_cmd);
351 install_element(CELLMGR_NODE, &cfg_msc_ip_dscp_cmd);
352 install_element(CELLMGR_NODE, &cfg_msc_ip_tos_cmd);
353 install_element(CELLMGR_NODE, &cfg_ping_time_cmd);
354 install_element(CELLMGR_NODE, &cfg_pong_time_cmd);
355 install_element(CELLMGR_NODE, &cfg_msc_time_cmd);
Holger Hans Peter Freytherf603f282011-01-30 00:24:15 +0100356 install_element(CELLMGR_NODE, &cfg_isup_pass_cmd);
Holger Hans Peter Freyther51b9e7a2011-01-22 16:02:13 +0100357
Holger Hans Peter Freyther29176442011-02-22 16:00:36 +0100358 cell_vty_init_cmds();
Holger Hans Peter Freyther7942abc2010-09-30 00:34:46 +0800359}
360
361const char *openbsc_copyright = "";