blob: 59f38522e901714422a1345966633f684f8fcec4 [file] [log] [blame]
Holger Hans Peter Freyther71760302011-02-22 20:57:08 +01001/* VTY code for the Cellmgr */
2/*
3 * (C) 2010-2011 by Holger Hans Peter Freyther <zecke@selfish.org>
4 * (C) 2010-2011 by On-Waves
5 * All Rights Reserved
6 *
7 * 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
10 * (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
15 * GNU Affero General Public License for more details.
16 *
17 * 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/>.
19 *
20 */
21
22#include <bsc_data.h>
23#include <mtp_pcap.h>
24#include <msc_connection.h>
25#include <ss7_application.h>
26#include <ss7_vty.h>
27
28#include <osmocore/talloc.h>
29#include <osmocore/gsm48.h>
30
31#include <osmocom/vty/command.h>
32#include <osmocom/vty/logging.h>
33#include <osmocom/vty/vty.h>
34
35#include <unistd.h>
36#include <netdb.h>
37
38#undef PACKAGE_NAME
39#undef PACKAGE_VERSION
40#undef PACKAGE_BUGREPORT
41#undef PACKAGE_TARNAME
42#undef PACKAGE_STRING
43#include <cellmgr_config.h>
44
45extern struct bsc_data *bsc;
46
47static struct vty_app_info vty_info = {
48 .name = "Cellmgr-ng",
49 .version = VERSION,
50 .go_parent_cb = NULL,
51};
52
53/* vty code */
54static struct cmd_node cell_node = {
55 CELLMGR_NODE,
56 "%s(cellmgr)#",
57 1,
58};
59
60static int config_write_cell(struct vty *vty)
61{
62 struct mtp_link_set *set = mtp_link_set_num(bsc, 0);
63 struct msc_connection *msc = msc_connection_num(bsc, 0);
64 struct ss7_application *app = ss7_application_num(bsc, 0);
65
66 vty_out(vty, "cellmgr%s", VTY_NEWLINE);
67 vty_out(vty, " mtp dpc %d%s", set->dpc, VTY_NEWLINE);
68 vty_out(vty, " mtp opc %d%s", set->opc, VTY_NEWLINE);
69 vty_out(vty, " mtp sccp-opc %d%s", set->sccp_opc, VTY_NEWLINE);
70 vty_out(vty, " mtp ni %d%s", set->ni, VTY_NEWLINE);
71 vty_out(vty, " mtp spare %d%s", set->spare, VTY_NEWLINE);
72 vty_out(vty, " mtp sltm once %d%s", set->sltm_once, VTY_NEWLINE);
73 if (bsc->udp_ip)
74 vty_out(vty, " udp dest ip %s%s", bsc->udp_ip, VTY_NEWLINE);
75 vty_out(vty, " udp dest port %d%s", bsc->udp_port, VTY_NEWLINE);
76 vty_out(vty, " udp src port %d%s", bsc->udp_src_port, VTY_NEWLINE);
77 vty_out(vty, " udp reset %d%s", bsc->udp_reset_timeout, VTY_NEWLINE);
78 vty_out(vty, " udp number-links %d%s", bsc->udp_nr_links, VTY_NEWLINE);
79 vty_out(vty, " isup pass-through %d%s", app->isup_pass, VTY_NEWLINE);
80
81 if (msc) {
82 vty_out(vty, " msc ip %s%s", msc->ip, VTY_NEWLINE);
83 vty_out(vty, " msc ip-dscp %d%s", msc->dscp, VTY_NEWLINE);
84 vty_out(vty, " msc token %s%s", msc->token, VTY_NEWLINE);
85 }
86
87
88 return CMD_SUCCESS;
89}
90
91DEFUN(cfg_cell, cfg_cell_cmd,
92 "cellmgr", "Configure the Cellmgr")
93{
94 vty->node = CELLMGR_NODE;
95 return CMD_SUCCESS;
96}
97
98DEFUN(cfg_net_dpc, cfg_net_dpc_cmd,
99 "mtp dpc DPC_NR",
100 "Set the DPC to be used.")
101{
102 struct mtp_link_set *set = mtp_link_set_num(bsc, 0);
103 set->dpc = atoi(argv[0]);
104 return CMD_SUCCESS;
105}
106
107DEFUN(cfg_net_opc, cfg_net_opc_cmd,
108 "mtp opc OPC_NR",
109 "Set the OPC to be used.")
110{
111 struct mtp_link_set *set = mtp_link_set_num(bsc, 0);
112 set->opc = atoi(argv[0]);
113 return CMD_SUCCESS;
114}
115
116DEFUN(cfg_net_sccp_opc, cfg_net_sccp_opc_cmd,
117 "mtp sccp-opc OPC_NR",
118 "Set the SCCP OPC to be used.")
119{
120 struct mtp_link_set *set = mtp_link_set_num(bsc, 0);
121 set->sccp_opc = atoi(argv[0]);
122 return CMD_SUCCESS;
123}
124
125DEFUN(cfg_net_mtp_ni, cfg_net_mtp_ni_cmd,
126 "mtp ni NR",
127 "Set the MTP NI to be used.\n" "NR")
128{
129 struct mtp_link_set *set = mtp_link_set_num(bsc, 0);
130 set->ni = atoi(argv[0]);
131 return CMD_SUCCESS;
132}
133
134DEFUN(cfg_net_mtp_spare, cfg_net_mtp_spare_cmd,
135 "mtp spare NR",
136 "Set the MTP Spare to be used.\n" "NR")
137{
138 struct mtp_link_set *set = mtp_link_set_num(bsc, 0);
139 set->spare = atoi(argv[0]);
140 return CMD_SUCCESS;
141}
142
143
144DEFUN(cfg_udp_dst_ip, cfg_udp_dst_ip_cmd,
145 "udp dest ip IP",
146 "Set the IP when UDP mode is supposed to be used.")
147{
148 struct hostent *hosts;
149 struct in_addr *addr;
150
151 hosts = gethostbyname(argv[0]);
152 if (!hosts || hosts->h_length < 1 || hosts->h_addrtype != AF_INET) {
153 vty_out(vty, "Failed to resolve '%s'%s", argv[0], VTY_NEWLINE);
154 return CMD_WARNING;
155 }
156
157 addr = (struct in_addr *) hosts->h_addr_list[0];
158 bsc->udp_ip = talloc_strdup(NULL, inet_ntoa(*addr));
159 return CMD_SUCCESS;
160}
161
162DEFUN(cfg_udp_dst_port, cfg_udp_dst_port_cmd,
163 "udp dest port PORT_NR",
164 "If UDP mode is used specify the UDP dest port")
165{
166 bsc->udp_port = atoi(argv[0]);
167 return CMD_SUCCESS;
168}
169
170DEFUN(cfg_udp_src_port, cfg_udp_src_port_cmd,
171 "udp src port PORT_NR",
172 "Set the UDP source port to be used.")
173{
174 bsc->udp_src_port = atoi(argv[0]);
175 return CMD_SUCCESS;
176}
177
178DEFUN(cfg_udp_reset, cfg_udp_reset_cmd,
179 "udp reset TIMEOUT",
180 "Set the timeout to take the link down")
181{
182 bsc->udp_reset_timeout = atoi(argv[0]);
183 return CMD_SUCCESS;
184}
185
186DEFUN(cfg_udp_nr_links, cfg_udp_nr_links_cmd,
187 "udp number-links <1-32>",
188 "Set the number of links to use\n")
189{
190 bsc->udp_nr_links = atoi(argv[0]);
191 return CMD_SUCCESS;
192}
193
194DEFUN(cfg_sltm_once, cfg_sltm_once_cmd,
195 "mtp sltm once (0|1)",
196 "Send SLTMs until the link is established.")
197{
198 struct mtp_link_set *set = mtp_link_set_num(bsc, 0);
199 set->sltm_once = !!atoi(argv[0]);
200 return CMD_SUCCESS;
201}
202
203DEFUN(cfg_msc_ip, cfg_msc_ip_cmd,
204 "msc ip IP",
205 "Set the MSC IP")
206{
207 struct hostent *hosts;
208 struct in_addr *addr;
209 struct msc_connection *msc = msc_connection_num(bsc, 0);
210
211 if (!msc) {
212 vty_out(vty, "%%No MSC Connection defined in this app.%s", VTY_NEWLINE);
213 return CMD_WARNING;
214 }
215
216 hosts = gethostbyname(argv[0]);
217 if (!hosts || hosts->h_length < 1 || hosts->h_addrtype != AF_INET) {
218 vty_out(vty, "Failed to resolve '%s'%s", argv[0], VTY_NEWLINE);
219 return CMD_WARNING;
220 }
221
222 addr = (struct in_addr *) hosts->h_addr_list[0];
223
224 if (msc->ip)
225 talloc_free(msc->ip);
226 msc->ip = talloc_strdup(msc, inet_ntoa(*addr));
227 return CMD_SUCCESS;
228}
229
230DEFUN(cfg_msc_ip_dscp, cfg_msc_ip_dscp_cmd,
231 "msc ip-dscp <0-255>",
232 "Set the IP DSCP on the A-link\n"
233 "Set the DSCP in IP packets to the MSC")
234{
235 struct msc_connection *msc = msc_connection_num(bsc, 0);
236
237 if (!msc) {
238 vty_out(vty, "%%No MSC Connection defined in this app.%s", VTY_NEWLINE);
239 return CMD_WARNING;
240 }
241
242 msc->dscp = atoi(argv[0]);
243 return CMD_SUCCESS;
244}
245
246ALIAS_DEPRECATED(cfg_msc_ip_dscp, cfg_msc_ip_tos_cmd,
247 "msc ip-tos <0-255>",
248 "Set the IP DSCP on the A-link\n"
249 "Set the DSCP in IP packets to the MSC")
250
251DEFUN(cfg_msc_token, cfg_msc_token_cmd,
252 "msc token TOKEN",
253 "Set the Token to be used for the MSC")
254{
255 struct msc_connection *msc = msc_connection_num(bsc, 0);
256
257 if (!msc) {
258 vty_out(vty, "%%No MSC Connection defined in this app.%s", VTY_NEWLINE);
259 return CMD_WARNING;
260 }
261
262 if (msc->token)
263 talloc_free(msc->token);
264 msc->token = talloc_strdup(msc, argv[0]);
265 return CMD_SUCCESS;
266}
267
268DEFUN(cfg_ping_time, cfg_ping_time_cmd,
269 "timeout ping NR",
270 "Set the PING interval. Negative to disable it")
271{
272 struct msc_connection *msc = msc_connection_num(bsc, 0);
273
274 if (!msc) {
275 vty_out(vty, "%%No MSC Connection defined in this app.%s", VTY_NEWLINE);
276 return CMD_WARNING;
277 }
278
279 msc->ping_time = atoi(argv[0]);
280 return CMD_SUCCESS;
281}
282
283DEFUN(cfg_pong_time, cfg_pong_time_cmd,
284 "timeout pong NR",
285 "Set the PING interval. Negative to disable it")
286{
287 struct msc_connection *msc = msc_connection_num(bsc, 0);
288
289 if (!msc) {
290 vty_out(vty, "%%No MSC Connection defined in this app.%s", VTY_NEWLINE);
291 return CMD_WARNING;
292 }
293
294 msc->pong_time = atoi(argv[0]);
295 return CMD_SUCCESS;
296}
297
298DEFUN(cfg_msc_time, cfg_msc_time_cmd,
299 "timeout msc NR",
300 "Set the MSC connect timeout")
301{
302 struct msc_connection *msc = msc_connection_num(bsc, 0);
303
304 if (!msc) {
305 vty_out(vty, "%%No MSC Connection defined in this app.%s", VTY_NEWLINE);
306 return CMD_WARNING;
307 }
308
309 msc->msc_time = atoi(argv[0]);
310 return CMD_SUCCESS;
311}
312
313DEFUN(cfg_isup_pass, cfg_isup_pass_cmd,
314 "isup pass-through (0|1)",
315 "ISUP related functionality\n"
316 "Pass through all ISUP messages directly\n"
317 "Handle some messages locally\n" "Pass through everything\n")
318{
319 struct ss7_application *app = ss7_application_num(bsc, 0);
320 ss7_application_pass_isup(app, atoi(argv[0]));
321
322 return CMD_SUCCESS;
323}
324
325extern void cell_vty_init_cmds(void);
326void cell_vty_init(void)
327{
328 cmd_init(1);
329 vty_init(&vty_info);
330 logging_vty_add_cmds();
331
332 install_element(CONFIG_NODE, &cfg_cell_cmd);
333 install_node(&cell_node, config_write_cell);
334
335 install_element(CELLMGR_NODE, &cfg_net_dpc_cmd);
336 install_element(CELLMGR_NODE, &cfg_net_opc_cmd);
337 install_element(CELLMGR_NODE, &cfg_net_sccp_opc_cmd);
338 install_element(CELLMGR_NODE, &cfg_net_mtp_ni_cmd);
339 install_element(CELLMGR_NODE, &cfg_net_mtp_spare_cmd);
340 install_element(CELLMGR_NODE, &cfg_udp_dst_ip_cmd);
341 install_element(CELLMGR_NODE, &cfg_udp_dst_port_cmd);
342 install_element(CELLMGR_NODE, &cfg_udp_src_port_cmd);
343 install_element(CELLMGR_NODE, &cfg_udp_reset_cmd);
344 install_element(CELLMGR_NODE, &cfg_udp_nr_links_cmd);
345 install_element(CELLMGR_NODE, &cfg_sltm_once_cmd);
346 install_element(CELLMGR_NODE, &cfg_msc_ip_cmd);
347 install_element(CELLMGR_NODE, &cfg_msc_token_cmd);
348 install_element(CELLMGR_NODE, &cfg_msc_ip_dscp_cmd);
349 install_element(CELLMGR_NODE, &cfg_msc_ip_tos_cmd);
350 install_element(CELLMGR_NODE, &cfg_ping_time_cmd);
351 install_element(CELLMGR_NODE, &cfg_pong_time_cmd);
352 install_element(CELLMGR_NODE, &cfg_msc_time_cmd);
353 install_element(CELLMGR_NODE, &cfg_isup_pass_cmd);
354
355 cell_vty_init_cmds();
356}
357
358const char *openbsc_copyright = "";