blob: 9c87fb57bcfc8da7d3907312f84107621d5f2cbb [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 Freyther7942abc2010-09-30 00:34:46 +080024
25#include <osmocore/talloc.h>
Holger Hans Peter Freyther0e4e35f2010-09-30 03:04:28 +080026#include <osmocore/gsm48.h>
Holger Hans Peter Freyther51b9e7a2011-01-22 16:02:13 +010027#include <osmocore/rate_ctr.h>
Holger Hans Peter Freyther7942abc2010-09-30 00:34:46 +080028
29#include <osmocom/vty/command.h>
Holger Hans Peter Freytherfca7b122011-01-22 23:19:44 +010030#include <osmocom/vty/logging.h>
Holger Hans Peter Freyther7942abc2010-09-30 00:34:46 +080031#include <osmocom/vty/vty.h>
32
33#include <unistd.h>
34#include <netdb.h>
Holger Hans Peter Freyther5b2fe8d2011-01-22 21:09:53 +010035#include <sys/types.h>
36#include <sys/stat.h>
37#include <fcntl.h>
Holger Hans Peter Freyther7942abc2010-09-30 00:34:46 +080038
39#undef PACKAGE_NAME
40#undef PACKAGE_VERSION
41#undef PACKAGE_BUGREPORT
42#undef PACKAGE_TARNAME
43#undef PACKAGE_STRING
44#include <cellmgr_config.h>
45
46extern struct bsc_data bsc;
47
48static struct vty_app_info vty_info = {
49 .name = "Cellmgr-ng",
50 .version = VERSION,
51 .go_parent_cb = NULL,
52};
53
54/* vty code */
55enum cellmgr_node {
56 CELLMGR_NODE = _LAST_OSMOVTY_NODE,
57};
58
59static struct cmd_node cell_node = {
60 CELLMGR_NODE,
61 "%s(cellmgr)#",
62 1,
63};
64
Holger Hans Peter Freyther2656e8f2010-09-30 00:41:37 +080065static int config_write_cell(struct vty *vty)
Holger Hans Peter Freyther7942abc2010-09-30 00:34:46 +080066{
Holger Hans Peter Freyther2656e8f2010-09-30 00:41:37 +080067 vty_out(vty, "cellmgr%s", VTY_NEWLINE);
68 vty_out(vty, " mtp dpc %d%s", bsc.dpc, VTY_NEWLINE);
69 vty_out(vty, " mtp opc %d%s", bsc.opc, VTY_NEWLINE);
Holger Hans Peter Freyther7a725562011-01-01 13:34:58 +010070 vty_out(vty, " mtp sccp-opc %d%s", bsc.sccp_opc, VTY_NEWLINE);
Holger Hans Peter Freytherb38b33b2010-11-26 21:21:04 +010071 vty_out(vty, " mtp ni %d%s", bsc.ni_ni, VTY_NEWLINE);
72 vty_out(vty, " mtp spare %d%s", bsc.ni_spare, VTY_NEWLINE);
Holger Hans Peter Freyther3bbb58b2010-11-26 21:25:38 +010073 vty_out(vty, " mtp sltm once %d%s", bsc.once, VTY_NEWLINE);
Holger Hans Peter Freyther0e4e35f2010-09-30 03:04:28 +080074 vty_out(vty, " country-code %d%s", bsc.mcc, VTY_NEWLINE);
75 vty_out(vty, " network-code %d%s", bsc.mnc, VTY_NEWLINE);
76 vty_out(vty, " location-area-code %d%s", bsc.lac, VTY_NEWLINE);
Holger Hans Peter Freyther2656e8f2010-09-30 00:41:37 +080077 if (bsc.udp_ip)
78 vty_out(vty, " udp dest ip %s%s", bsc.udp_ip, VTY_NEWLINE);
79 vty_out(vty, " udp dest port %d%s", bsc.udp_port, VTY_NEWLINE);
80 vty_out(vty, " udp src port %d%s", bsc.src_port, VTY_NEWLINE);
Holger Hans Peter Freyther644aafb2011-01-03 23:51:07 +010081 vty_out(vty, " udp reset %d%s", bsc.udp_reset_timeout, VTY_NEWLINE);
Holger Hans Peter Freytherc6bfa272011-01-22 17:06:34 +010082 vty_out(vty, " udp number-links %d%s", bsc.udp_nr_links, VTY_NEWLINE);
Holger Hans Peter Freyther2656e8f2010-09-30 00:41:37 +080083 vty_out(vty, " msc ip %s%s", bsc.msc_address, VTY_NEWLINE);
84 vty_out(vty, " msc ip-dscp %d%s", bsc.msc_ip_dscp, VTY_NEWLINE);
85 vty_out(vty, " msc token %s%s", bsc.token, VTY_NEWLINE);
86
Holger Hans Peter Freyther7942abc2010-09-30 00:34:46 +080087 return CMD_SUCCESS;
88}
89
90DEFUN(cfg_cell, cfg_cell_cmd,
91 "cellmgr", "Configure the Cellmgr")
92{
93 vty->node = CELLMGR_NODE;
94 return CMD_SUCCESS;
95}
96
97DEFUN(cfg_net_dpc, cfg_net_dpc_cmd,
98 "mtp dpc DPC_NR",
99 "Set the DPC to be used.")
100{
101 bsc.dpc = atoi(argv[0]);
102 return CMD_SUCCESS;
103}
104
105DEFUN(cfg_net_opc, cfg_net_opc_cmd,
106 "mtp opc OPC_NR",
107 "Set the OPC to be used.")
108{
109 bsc.opc = atoi(argv[0]);
110 return CMD_SUCCESS;
111}
112
Holger Hans Peter Freyther7a725562011-01-01 13:34:58 +0100113DEFUN(cfg_net_sccp_opc, cfg_net_sccp_opc_cmd,
114 "mtp sccp-opc OPC_NR",
115 "Set the SCCP OPC to be used.")
116{
117 bsc.sccp_opc = atoi(argv[0]);
118 return CMD_SUCCESS;
119}
120
Holger Hans Peter Freytherb38b33b2010-11-26 21:21:04 +0100121DEFUN(cfg_net_mtp_ni, cfg_net_mtp_ni_cmd,
122 "mtp ni NR",
123 "Set the MTP NI to be used.\n" "NR")
124{
125 bsc.ni_ni = atoi(argv[0]);
126 return CMD_SUCCESS;
127}
128
129DEFUN(cfg_net_mtp_spare, cfg_net_mtp_spare_cmd,
130 "mtp spare NR",
131 "Set the MTP Spare to be used.\n" "NR")
132{
133 bsc.ni_spare = atoi(argv[0]);
134 return CMD_SUCCESS;
135}
136
137
Holger Hans Peter Freyther7942abc2010-09-30 00:34:46 +0800138DEFUN(cfg_udp_dst_ip, cfg_udp_dst_ip_cmd,
139 "udp dest ip IP",
140 "Set the IP when UDP mode is supposed to be used.")
141{
142 struct hostent *hosts;
143 struct in_addr *addr;
144
145 hosts = gethostbyname(argv[0]);
146 if (!hosts || hosts->h_length < 1 || hosts->h_addrtype != AF_INET) {
147 vty_out(vty, "Failed to resolve '%s'%s", argv[0], VTY_NEWLINE);
148 return CMD_WARNING;
149 }
150
151 addr = (struct in_addr *) hosts->h_addr_list[0];
152 bsc.udp_ip = talloc_strdup(NULL, inet_ntoa(*addr));
153 return CMD_SUCCESS;
154}
155
156DEFUN(cfg_udp_dst_port, cfg_udp_dst_port_cmd,
157 "udp dest port PORT_NR",
158 "If UDP mode is used specify the UDP dest port")
159{
160 bsc.udp_port = atoi(argv[0]);
161 return CMD_SUCCESS;
162}
163
164DEFUN(cfg_udp_src_port, cfg_udp_src_port_cmd,
165 "udp src port PORT_NR",
166 "Set the UDP source port to be used.")
167{
168 bsc.src_port = atoi(argv[0]);
169 return CMD_SUCCESS;
170}
171
172DEFUN(cfg_udp_reset, cfg_udp_reset_cmd,
173 "udp reset TIMEOUT",
174 "Set the timeout to take the link down")
175{
Holger Hans Peter Freyther644aafb2011-01-03 23:51:07 +0100176 bsc.udp_reset_timeout = atoi(argv[0]);
Holger Hans Peter Freyther7942abc2010-09-30 00:34:46 +0800177 return CMD_SUCCESS;
178}
179
Holger Hans Peter Freytherc6bfa272011-01-22 17:06:34 +0100180DEFUN(cfg_udp_nr_links, cfg_udp_nr_links_cmd,
181 "udp number-links <1-32>",
182 "Set the number of links to use\n")
183{
184 bsc.udp_nr_links = atoi(argv[0]);
185 return CMD_SUCCESS;
186}
187
Holger Hans Peter Freyther7942abc2010-09-30 00:34:46 +0800188DEFUN(cfg_sltm_once, cfg_sltm_once_cmd,
189 "mtp sltm once (0|1)",
190 "Send SLTMs until the link is established.")
191{
192 bsc.once = !!atoi(argv[0]);
193 return CMD_SUCCESS;
194}
195
196DEFUN(cfg_msc_ip, cfg_msc_ip_cmd,
197 "msc ip IP",
198 "Set the MSC IP")
199{
200 struct hostent *hosts;
201 struct in_addr *addr;
202
203 hosts = gethostbyname(argv[0]);
204 if (!hosts || hosts->h_length < 1 || hosts->h_addrtype != AF_INET) {
205 vty_out(vty, "Failed to resolve '%s'%s", argv[0], VTY_NEWLINE);
206 return CMD_WARNING;
207 }
208
209 addr = (struct in_addr *) hosts->h_addr_list[0];
210
211 bsc.msc_address = talloc_strdup(NULL, inet_ntoa(*addr));
212 return CMD_SUCCESS;
213}
214
215DEFUN(cfg_msc_ip_dscp, cfg_msc_ip_dscp_cmd,
216 "msc ip-dscp <0-255>",
217 "Set the IP DSCP on the A-link\n"
218 "Set the DSCP in IP packets to the MSC")
219{
220 bsc.msc_ip_dscp = atoi(argv[0]);
221 return CMD_SUCCESS;
222}
223
224ALIAS_DEPRECATED(cfg_msc_ip_dscp, cfg_msc_ip_tos_cmd,
225 "msc ip-tos <0-255>",
226 "Set the IP DSCP on the A-link\n"
227 "Set the DSCP in IP packets to the MSC")
228
229DEFUN(cfg_msc_token, cfg_msc_token_cmd,
230 "msc token TOKEN",
231 "Set the Token to be used for the MSC")
232{
233 bsc.token = talloc_strdup(NULL, argv[0]);
234 return CMD_SUCCESS;
235}
236
237DEFUN(cfg_ping_time, cfg_ping_time_cmd,
238 "timeout ping NR",
239 "Set the PING interval. Negative to disable it")
240{
241 bsc.ping_time = atoi(argv[0]);
242 return CMD_SUCCESS;
243}
244
245DEFUN(cfg_pong_time, cfg_pong_time_cmd,
246 "timeout pong NR",
247 "Set the PING interval. Negative to disable it")
248{
249 bsc.pong_time = atoi(argv[0]);
250 return CMD_SUCCESS;
251}
252
253DEFUN(cfg_msc_time, cfg_msc_time_cmd,
254 "timeout msc NR",
255 "Set the MSC connect timeout")
256{
257 bsc.msc_time = atoi(argv[0]);
258 return CMD_SUCCESS;
259}
260
Holger Hans Peter Freyther0e4e35f2010-09-30 03:04:28 +0800261static void update_lai(struct bsc_data *bsc)
262{
263 gsm48_generate_lai(&bsc->lai, bsc->mcc, bsc->mnc, bsc->lac);
264}
265
266DEFUN(cfg_mnc, cfg_mnc_cmd,
267 "network-code NR",
268 "Set the Mobile Network Code\n" "Number\n")
269{
270 bsc.mnc = atoi(argv[0]);
271 update_lai(&bsc);
272 return CMD_SUCCESS;
273}
274
275DEFUN(cfg_mcc, cfg_mcc_cmd,
276 "country-code NR",
277 "Set the Mobile Country Code\n" "Number\n")
278{
279 bsc.mcc = atoi(argv[0]);
280 update_lai(&bsc);
281 return CMD_SUCCESS;
282}
283
284DEFUN(cfg_lac, cfg_lac_cmd,
285 "location-area-code NR",
286 "Set the Location Area Code\n" "Number\n")
287{
288 bsc.lac = atoi(argv[0]);
289 update_lai(&bsc);
290 return CMD_SUCCESS;
291}
292
Holger Hans Peter Freyther1b47ce52011-01-22 21:31:24 +0100293static void dump_stats(struct vty *vty, const char *name, struct mtp_link_set *set)
Holger Hans Peter Freyther51b9e7a2011-01-22 16:02:13 +0100294{
295 struct mtp_link *link;
296
Holger Hans Peter Freyther1b47ce52011-01-22 21:31:24 +0100297 vty_out(vty, "Linkset name: %s opc: %d%s", name, set->opc, VTY_NEWLINE);
Holger Hans Peter Freyther51b9e7a2011-01-22 16:02:13 +0100298 vty_out_rate_ctr_group(vty, " ", set->ctrg);
299
300 llist_for_each_entry(link, &set->links, entry) {
301 vty_out(vty, " Link %d%s", link->link_no, VTY_NEWLINE);
302 vty_out_rate_ctr_group(vty, " ", link->ctrg);
303 }
304}
305
306DEFUN(show_stats, show_stats_cmd,
307 "show statistics",
308 SHOW_STR "Display Linkset statistics\n")
309{
310 if (bsc.link_set)
Holger Hans Peter Freyther1b47ce52011-01-22 21:31:24 +0100311 dump_stats(vty, "MTP ", bsc.link_set);
Holger Hans Peter Freythera310e532011-01-22 16:34:16 +0100312 if (bsc.m2ua_set && bsc.app == APP_STP)
Holger Hans Peter Freyther1b47ce52011-01-22 21:31:24 +0100313 dump_stats(vty, "M2UA", bsc.m2ua_set);
Holger Hans Peter Freyther51b9e7a2011-01-22 16:02:13 +0100314 return CMD_SUCCESS;
315}
316
Holger Hans Peter Freyther60af5dd2011-01-22 16:16:52 +0100317static void dump_state(struct vty *vty, const char *name, struct mtp_link_set *set)
318{
319 struct mtp_link *link;
320
321 if (!set) {
322 vty_out(vty, "LinkSet for %s is not configured.%s", name, VTY_NEWLINE);
323 return;
324 }
325
326 vty_out(vty, "LinkSet for %s is %s, remote sccp is %s.%s",
327 name,
328 set->available == 0 ? "not available" : "available",
329 set->sccp_up == 0? "not established" : "established",
330 VTY_NEWLINE);
331
332 llist_for_each_entry(link, &set->links, entry) {
333 vty_out(vty, " Link %d is %s.%s",
334 link->link_no,
335 link->available == 0 ? "not available" : "available",
336 VTY_NEWLINE);
337 }
338}
339
340DEFUN(show_linksets, show_linksets_cmd,
341 "show link-sets",
342 SHOW_STR "Display current state of linksets\n")
343{
344 dump_state(vty, "MTP ", bsc.link_set);
Holger Hans Peter Freythera310e532011-01-22 16:34:16 +0100345 if (bsc.app == APP_STP)
346 dump_state(vty, "M2UA", bsc.m2ua_set);
Holger Hans Peter Freyther60af5dd2011-01-22 16:16:52 +0100347 return CMD_SUCCESS;
348}
349
Holger Hans Peter Freyther0b316222011-01-22 16:43:14 +0100350DEFUN(show_msc, show_msc_cmd,
351 "show msc",
352 SHOW_STR "Display the status of the MSC\n")
353{
354 vty_out(vty, "MSC link is %s and had %s.%s",
355 bsc.msc_link_down == 0 ? "down" : "up",
356 bsc.first_contact == 1 ? "no contact" : "contact",
357 VTY_NEWLINE);
358 return CMD_SUCCESS;
359}
360
Holger Hans Peter Freyther5b2fe8d2011-01-22 21:09:53 +0100361DEFUN(pcap_set, pcap_set_cmd,
362 "trace-pcap set (m2ua|mtp) FILE",
363 "Trace to a PCAP file\n" "Trace a linkset\n"
364 "OPC of the linkset\n" "Filename to trace\n")
365{
366 struct mtp_link_set *set = NULL;
367
368 if (bsc.link_set && strcmp(argv[0], "mtp") == 0)
369 set = bsc.link_set;
370 else if (bsc.m2ua_set && strcmp(argv[0], "m2ua") == 0)
371 set = bsc.m2ua_set;
372
373 if (!set) {
374 vty_out(vty, "Failed to find linkset.%s", VTY_NEWLINE);
375 return CMD_WARNING;
376 }
377
378
379 if (set->pcap_fd >= 0 && bsc.pcap_fd != set->pcap_fd)
380 close(set->pcap_fd);
381 set->pcap_fd = open(argv[1], O_WRONLY | O_TRUNC | O_CREAT,
382 S_IRUSR | S_IWUSR | S_IRGRP| S_IROTH);
383 if (set->pcap_fd < 0) {
384 vty_out(vty, "Failed to open file for writing.%s", VTY_NEWLINE);
385 return CMD_WARNING;
386 }
387
388 mtp_pcap_write_header(set->pcap_fd);
389 return CMD_SUCCESS;
390}
391
392DEFUN(pcap_set_stop, pcap_set_stop_cmd,
393 "trace-pcap set <1-16383> stop",
394 "Trace to a PCAP file\n" "Trace a linkset\n"
395 "OPC for the linkset\n" "Stop the tracing\n")
396{
397 struct mtp_link_set *set = NULL;
398
399 if (bsc.link_set && strcmp(argv[0], "mtp") == 0)
400 set = bsc.link_set;
401 else if (bsc.m2ua_set && strcmp(argv[0], "m2ua") == 0)
402 set = bsc.m2ua_set;
403
404 if (!set) {
405 vty_out(vty, "Failed to find linkset.%s", VTY_NEWLINE);
406 return CMD_WARNING;
407 }
408
409 if (set->pcap_fd >= 0 && bsc.pcap_fd != set->pcap_fd)
410 close(set->pcap_fd);
411 set->pcap_fd = -1;
412 return CMD_SUCCESS;
413}
414
415
Holger Hans Peter Freyther7942abc2010-09-30 00:34:46 +0800416void cell_vty_init(void)
417{
418 cmd_init(1);
419 vty_init(&vty_info);
Holger Hans Peter Freytherfca7b122011-01-22 23:19:44 +0100420 logging_vty_add_cmds();
Holger Hans Peter Freyther7942abc2010-09-30 00:34:46 +0800421
422 install_element(CONFIG_NODE, &cfg_cell_cmd);
423 install_node(&cell_node, config_write_cell);
424
425 install_element(CELLMGR_NODE, &cfg_net_dpc_cmd);
426 install_element(CELLMGR_NODE, &cfg_net_opc_cmd);
Holger Hans Peter Freyther7a725562011-01-01 13:34:58 +0100427 install_element(CELLMGR_NODE, &cfg_net_sccp_opc_cmd);
Holger Hans Peter Freytherb38b33b2010-11-26 21:21:04 +0100428 install_element(CELLMGR_NODE, &cfg_net_mtp_ni_cmd);
429 install_element(CELLMGR_NODE, &cfg_net_mtp_spare_cmd);
Holger Hans Peter Freyther7942abc2010-09-30 00:34:46 +0800430 install_element(CELLMGR_NODE, &cfg_udp_dst_ip_cmd);
431 install_element(CELLMGR_NODE, &cfg_udp_dst_port_cmd);
432 install_element(CELLMGR_NODE, &cfg_udp_src_port_cmd);
433 install_element(CELLMGR_NODE, &cfg_udp_reset_cmd);
Holger Hans Peter Freytherc6bfa272011-01-22 17:06:34 +0100434 install_element(CELLMGR_NODE, &cfg_udp_nr_links_cmd);
Holger Hans Peter Freyther7942abc2010-09-30 00:34:46 +0800435 install_element(CELLMGR_NODE, &cfg_sltm_once_cmd);
436 install_element(CELLMGR_NODE, &cfg_msc_ip_cmd);
437 install_element(CELLMGR_NODE, &cfg_msc_token_cmd);
438 install_element(CELLMGR_NODE, &cfg_msc_ip_dscp_cmd);
439 install_element(CELLMGR_NODE, &cfg_msc_ip_tos_cmd);
440 install_element(CELLMGR_NODE, &cfg_ping_time_cmd);
441 install_element(CELLMGR_NODE, &cfg_pong_time_cmd);
442 install_element(CELLMGR_NODE, &cfg_msc_time_cmd);
Holger Hans Peter Freyther0e4e35f2010-09-30 03:04:28 +0800443 install_element(CELLMGR_NODE, &cfg_mcc_cmd);
444 install_element(CELLMGR_NODE, &cfg_mnc_cmd);
445 install_element(CELLMGR_NODE, &cfg_lac_cmd);
Holger Hans Peter Freyther51b9e7a2011-01-22 16:02:13 +0100446
Holger Hans Peter Freyther5b2fe8d2011-01-22 21:09:53 +0100447 /* special commands */
448 install_element(ENABLE_NODE, &pcap_set_cmd);
449 install_element(ENABLE_NODE, &pcap_set_stop_cmd);
Holger Hans Peter Freyther51b9e7a2011-01-22 16:02:13 +0100450
451 /* show commands */
452 install_element_ve(&show_stats_cmd);
Holger Hans Peter Freyther60af5dd2011-01-22 16:16:52 +0100453 install_element_ve(&show_linksets_cmd);
Holger Hans Peter Freyther0b316222011-01-22 16:43:14 +0100454
455 if (bsc.app != APP_STP) {
456 install_element_ve(&show_msc_cmd);
457 }
Holger Hans Peter Freyther7942abc2010-09-30 00:34:46 +0800458}
459
460const char *openbsc_copyright = "";