blob: 7a9c157e896fa22503ca4d0f18c1833a11f135a0 [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>
23
24#include <osmocore/talloc.h>
Holger Hans Peter Freyther0e4e35f2010-09-30 03:04:28 +080025#include <osmocore/gsm48.h>
Holger Hans Peter Freyther51b9e7a2011-01-22 16:02:13 +010026#include <osmocore/rate_ctr.h>
Holger Hans Peter Freyther7942abc2010-09-30 00:34:46 +080027
28#include <osmocom/vty/command.h>
29#include <osmocom/vty/vty.h>
30
31#include <unistd.h>
32#include <netdb.h>
33
34#undef PACKAGE_NAME
35#undef PACKAGE_VERSION
36#undef PACKAGE_BUGREPORT
37#undef PACKAGE_TARNAME
38#undef PACKAGE_STRING
39#include <cellmgr_config.h>
40
41extern struct bsc_data bsc;
42
43static struct vty_app_info vty_info = {
44 .name = "Cellmgr-ng",
45 .version = VERSION,
46 .go_parent_cb = NULL,
47};
48
49/* vty code */
50enum cellmgr_node {
51 CELLMGR_NODE = _LAST_OSMOVTY_NODE,
52};
53
54static struct cmd_node cell_node = {
55 CELLMGR_NODE,
56 "%s(cellmgr)#",
57 1,
58};
59
Holger Hans Peter Freyther2656e8f2010-09-30 00:41:37 +080060static int config_write_cell(struct vty *vty)
Holger Hans Peter Freyther7942abc2010-09-30 00:34:46 +080061{
Holger Hans Peter Freyther2656e8f2010-09-30 00:41:37 +080062 vty_out(vty, "cellmgr%s", VTY_NEWLINE);
63 vty_out(vty, " mtp dpc %d%s", bsc.dpc, VTY_NEWLINE);
64 vty_out(vty, " mtp opc %d%s", bsc.opc, VTY_NEWLINE);
Holger Hans Peter Freyther7a725562011-01-01 13:34:58 +010065 vty_out(vty, " mtp sccp-opc %d%s", bsc.sccp_opc, VTY_NEWLINE);
Holger Hans Peter Freytherb38b33b2010-11-26 21:21:04 +010066 vty_out(vty, " mtp ni %d%s", bsc.ni_ni, VTY_NEWLINE);
67 vty_out(vty, " mtp spare %d%s", bsc.ni_spare, VTY_NEWLINE);
Holger Hans Peter Freyther3bbb58b2010-11-26 21:25:38 +010068 vty_out(vty, " mtp sltm once %d%s", bsc.once, VTY_NEWLINE);
Holger Hans Peter Freyther0e4e35f2010-09-30 03:04:28 +080069 vty_out(vty, " country-code %d%s", bsc.mcc, VTY_NEWLINE);
70 vty_out(vty, " network-code %d%s", bsc.mnc, VTY_NEWLINE);
71 vty_out(vty, " location-area-code %d%s", bsc.lac, VTY_NEWLINE);
Holger Hans Peter Freyther2656e8f2010-09-30 00:41:37 +080072 if (bsc.udp_ip)
73 vty_out(vty, " udp dest ip %s%s", bsc.udp_ip, VTY_NEWLINE);
74 vty_out(vty, " udp dest port %d%s", bsc.udp_port, VTY_NEWLINE);
75 vty_out(vty, " udp src port %d%s", bsc.src_port, VTY_NEWLINE);
Holger Hans Peter Freyther644aafb2011-01-03 23:51:07 +010076 vty_out(vty, " udp reset %d%s", bsc.udp_reset_timeout, VTY_NEWLINE);
Holger Hans Peter Freytherc6bfa272011-01-22 17:06:34 +010077 vty_out(vty, " udp number-links %d%s", bsc.udp_nr_links, VTY_NEWLINE);
Holger Hans Peter Freyther2656e8f2010-09-30 00:41:37 +080078 vty_out(vty, " msc ip %s%s", bsc.msc_address, VTY_NEWLINE);
79 vty_out(vty, " msc ip-dscp %d%s", bsc.msc_ip_dscp, VTY_NEWLINE);
80 vty_out(vty, " msc token %s%s", bsc.token, VTY_NEWLINE);
81
Holger Hans Peter Freyther7942abc2010-09-30 00:34:46 +080082 return CMD_SUCCESS;
83}
84
85DEFUN(cfg_cell, cfg_cell_cmd,
86 "cellmgr", "Configure the Cellmgr")
87{
88 vty->node = CELLMGR_NODE;
89 return CMD_SUCCESS;
90}
91
92DEFUN(cfg_net_dpc, cfg_net_dpc_cmd,
93 "mtp dpc DPC_NR",
94 "Set the DPC to be used.")
95{
96 bsc.dpc = atoi(argv[0]);
97 return CMD_SUCCESS;
98}
99
100DEFUN(cfg_net_opc, cfg_net_opc_cmd,
101 "mtp opc OPC_NR",
102 "Set the OPC to be used.")
103{
104 bsc.opc = atoi(argv[0]);
105 return CMD_SUCCESS;
106}
107
Holger Hans Peter Freyther7a725562011-01-01 13:34:58 +0100108DEFUN(cfg_net_sccp_opc, cfg_net_sccp_opc_cmd,
109 "mtp sccp-opc OPC_NR",
110 "Set the SCCP OPC to be used.")
111{
112 bsc.sccp_opc = atoi(argv[0]);
113 return CMD_SUCCESS;
114}
115
Holger Hans Peter Freytherb38b33b2010-11-26 21:21:04 +0100116DEFUN(cfg_net_mtp_ni, cfg_net_mtp_ni_cmd,
117 "mtp ni NR",
118 "Set the MTP NI to be used.\n" "NR")
119{
120 bsc.ni_ni = atoi(argv[0]);
121 return CMD_SUCCESS;
122}
123
124DEFUN(cfg_net_mtp_spare, cfg_net_mtp_spare_cmd,
125 "mtp spare NR",
126 "Set the MTP Spare to be used.\n" "NR")
127{
128 bsc.ni_spare = atoi(argv[0]);
129 return CMD_SUCCESS;
130}
131
132
Holger Hans Peter Freyther7942abc2010-09-30 00:34:46 +0800133DEFUN(cfg_udp_dst_ip, cfg_udp_dst_ip_cmd,
134 "udp dest ip IP",
135 "Set the IP when UDP mode is supposed to be used.")
136{
137 struct hostent *hosts;
138 struct in_addr *addr;
139
140 hosts = gethostbyname(argv[0]);
141 if (!hosts || hosts->h_length < 1 || hosts->h_addrtype != AF_INET) {
142 vty_out(vty, "Failed to resolve '%s'%s", argv[0], VTY_NEWLINE);
143 return CMD_WARNING;
144 }
145
146 addr = (struct in_addr *) hosts->h_addr_list[0];
147 bsc.udp_ip = talloc_strdup(NULL, inet_ntoa(*addr));
148 return CMD_SUCCESS;
149}
150
151DEFUN(cfg_udp_dst_port, cfg_udp_dst_port_cmd,
152 "udp dest port PORT_NR",
153 "If UDP mode is used specify the UDP dest port")
154{
155 bsc.udp_port = atoi(argv[0]);
156 return CMD_SUCCESS;
157}
158
159DEFUN(cfg_udp_src_port, cfg_udp_src_port_cmd,
160 "udp src port PORT_NR",
161 "Set the UDP source port to be used.")
162{
163 bsc.src_port = atoi(argv[0]);
164 return CMD_SUCCESS;
165}
166
167DEFUN(cfg_udp_reset, cfg_udp_reset_cmd,
168 "udp reset TIMEOUT",
169 "Set the timeout to take the link down")
170{
Holger Hans Peter Freyther644aafb2011-01-03 23:51:07 +0100171 bsc.udp_reset_timeout = atoi(argv[0]);
Holger Hans Peter Freyther7942abc2010-09-30 00:34:46 +0800172 return CMD_SUCCESS;
173}
174
Holger Hans Peter Freytherc6bfa272011-01-22 17:06:34 +0100175DEFUN(cfg_udp_nr_links, cfg_udp_nr_links_cmd,
176 "udp number-links <1-32>",
177 "Set the number of links to use\n")
178{
179 bsc.udp_nr_links = atoi(argv[0]);
180 return CMD_SUCCESS;
181}
182
Holger Hans Peter Freyther7942abc2010-09-30 00:34:46 +0800183DEFUN(cfg_sltm_once, cfg_sltm_once_cmd,
184 "mtp sltm once (0|1)",
185 "Send SLTMs until the link is established.")
186{
187 bsc.once = !!atoi(argv[0]);
188 return CMD_SUCCESS;
189}
190
191DEFUN(cfg_msc_ip, cfg_msc_ip_cmd,
192 "msc ip IP",
193 "Set the MSC IP")
194{
195 struct hostent *hosts;
196 struct in_addr *addr;
197
198 hosts = gethostbyname(argv[0]);
199 if (!hosts || hosts->h_length < 1 || hosts->h_addrtype != AF_INET) {
200 vty_out(vty, "Failed to resolve '%s'%s", argv[0], VTY_NEWLINE);
201 return CMD_WARNING;
202 }
203
204 addr = (struct in_addr *) hosts->h_addr_list[0];
205
206 bsc.msc_address = talloc_strdup(NULL, inet_ntoa(*addr));
207 return CMD_SUCCESS;
208}
209
210DEFUN(cfg_msc_ip_dscp, cfg_msc_ip_dscp_cmd,
211 "msc ip-dscp <0-255>",
212 "Set the IP DSCP on the A-link\n"
213 "Set the DSCP in IP packets to the MSC")
214{
215 bsc.msc_ip_dscp = atoi(argv[0]);
216 return CMD_SUCCESS;
217}
218
219ALIAS_DEPRECATED(cfg_msc_ip_dscp, cfg_msc_ip_tos_cmd,
220 "msc ip-tos <0-255>",
221 "Set the IP DSCP on the A-link\n"
222 "Set the DSCP in IP packets to the MSC")
223
224DEFUN(cfg_msc_token, cfg_msc_token_cmd,
225 "msc token TOKEN",
226 "Set the Token to be used for the MSC")
227{
228 bsc.token = talloc_strdup(NULL, argv[0]);
229 return CMD_SUCCESS;
230}
231
232DEFUN(cfg_ping_time, cfg_ping_time_cmd,
233 "timeout ping NR",
234 "Set the PING interval. Negative to disable it")
235{
236 bsc.ping_time = atoi(argv[0]);
237 return CMD_SUCCESS;
238}
239
240DEFUN(cfg_pong_time, cfg_pong_time_cmd,
241 "timeout pong NR",
242 "Set the PING interval. Negative to disable it")
243{
244 bsc.pong_time = atoi(argv[0]);
245 return CMD_SUCCESS;
246}
247
248DEFUN(cfg_msc_time, cfg_msc_time_cmd,
249 "timeout msc NR",
250 "Set the MSC connect timeout")
251{
252 bsc.msc_time = atoi(argv[0]);
253 return CMD_SUCCESS;
254}
255
Holger Hans Peter Freyther0e4e35f2010-09-30 03:04:28 +0800256static void update_lai(struct bsc_data *bsc)
257{
258 gsm48_generate_lai(&bsc->lai, bsc->mcc, bsc->mnc, bsc->lac);
259}
260
261DEFUN(cfg_mnc, cfg_mnc_cmd,
262 "network-code NR",
263 "Set the Mobile Network Code\n" "Number\n")
264{
265 bsc.mnc = atoi(argv[0]);
266 update_lai(&bsc);
267 return CMD_SUCCESS;
268}
269
270DEFUN(cfg_mcc, cfg_mcc_cmd,
271 "country-code NR",
272 "Set the Mobile Country Code\n" "Number\n")
273{
274 bsc.mcc = atoi(argv[0]);
275 update_lai(&bsc);
276 return CMD_SUCCESS;
277}
278
279DEFUN(cfg_lac, cfg_lac_cmd,
280 "location-area-code NR",
281 "Set the Location Area Code\n" "Number\n")
282{
283 bsc.lac = atoi(argv[0]);
284 update_lai(&bsc);
285 return CMD_SUCCESS;
286}
287
Holger Hans Peter Freyther51b9e7a2011-01-22 16:02:13 +0100288static void dump_stats(struct vty *vty, struct mtp_link_set *set)
289{
290 struct mtp_link *link;
291
292 vty_out(vty, "Linkset opc: %d%s", set->opc, VTY_NEWLINE);
293 vty_out_rate_ctr_group(vty, " ", set->ctrg);
294
295 llist_for_each_entry(link, &set->links, entry) {
296 vty_out(vty, " Link %d%s", link->link_no, VTY_NEWLINE);
297 vty_out_rate_ctr_group(vty, " ", link->ctrg);
298 }
299}
300
301DEFUN(show_stats, show_stats_cmd,
302 "show statistics",
303 SHOW_STR "Display Linkset statistics\n")
304{
305 if (bsc.link_set)
306 dump_stats(vty, bsc.link_set);
Holger Hans Peter Freythera310e532011-01-22 16:34:16 +0100307 if (bsc.m2ua_set && bsc.app == APP_STP)
Holger Hans Peter Freyther51b9e7a2011-01-22 16:02:13 +0100308 dump_stats(vty, bsc.m2ua_set);
309 return CMD_SUCCESS;
310}
311
Holger Hans Peter Freyther60af5dd2011-01-22 16:16:52 +0100312static void dump_state(struct vty *vty, const char *name, struct mtp_link_set *set)
313{
314 struct mtp_link *link;
315
316 if (!set) {
317 vty_out(vty, "LinkSet for %s is not configured.%s", name, VTY_NEWLINE);
318 return;
319 }
320
321 vty_out(vty, "LinkSet for %s is %s, remote sccp is %s.%s",
322 name,
323 set->available == 0 ? "not available" : "available",
324 set->sccp_up == 0? "not established" : "established",
325 VTY_NEWLINE);
326
327 llist_for_each_entry(link, &set->links, entry) {
328 vty_out(vty, " Link %d is %s.%s",
329 link->link_no,
330 link->available == 0 ? "not available" : "available",
331 VTY_NEWLINE);
332 }
333}
334
335DEFUN(show_linksets, show_linksets_cmd,
336 "show link-sets",
337 SHOW_STR "Display current state of linksets\n")
338{
339 dump_state(vty, "MTP ", bsc.link_set);
Holger Hans Peter Freythera310e532011-01-22 16:34:16 +0100340 if (bsc.app == APP_STP)
341 dump_state(vty, "M2UA", bsc.m2ua_set);
Holger Hans Peter Freyther60af5dd2011-01-22 16:16:52 +0100342 return CMD_SUCCESS;
343}
344
Holger Hans Peter Freyther0b316222011-01-22 16:43:14 +0100345DEFUN(show_msc, show_msc_cmd,
346 "show msc",
347 SHOW_STR "Display the status of the MSC\n")
348{
349 vty_out(vty, "MSC link is %s and had %s.%s",
350 bsc.msc_link_down == 0 ? "down" : "up",
351 bsc.first_contact == 1 ? "no contact" : "contact",
352 VTY_NEWLINE);
353 return CMD_SUCCESS;
354}
355
Holger Hans Peter Freyther7942abc2010-09-30 00:34:46 +0800356void cell_vty_init(void)
357{
358 cmd_init(1);
359 vty_init(&vty_info);
360
361 install_element(CONFIG_NODE, &cfg_cell_cmd);
362 install_node(&cell_node, config_write_cell);
363
364 install_element(CELLMGR_NODE, &cfg_net_dpc_cmd);
365 install_element(CELLMGR_NODE, &cfg_net_opc_cmd);
Holger Hans Peter Freyther7a725562011-01-01 13:34:58 +0100366 install_element(CELLMGR_NODE, &cfg_net_sccp_opc_cmd);
Holger Hans Peter Freytherb38b33b2010-11-26 21:21:04 +0100367 install_element(CELLMGR_NODE, &cfg_net_mtp_ni_cmd);
368 install_element(CELLMGR_NODE, &cfg_net_mtp_spare_cmd);
Holger Hans Peter Freyther7942abc2010-09-30 00:34:46 +0800369 install_element(CELLMGR_NODE, &cfg_udp_dst_ip_cmd);
370 install_element(CELLMGR_NODE, &cfg_udp_dst_port_cmd);
371 install_element(CELLMGR_NODE, &cfg_udp_src_port_cmd);
372 install_element(CELLMGR_NODE, &cfg_udp_reset_cmd);
Holger Hans Peter Freytherc6bfa272011-01-22 17:06:34 +0100373 install_element(CELLMGR_NODE, &cfg_udp_nr_links_cmd);
Holger Hans Peter Freyther7942abc2010-09-30 00:34:46 +0800374 install_element(CELLMGR_NODE, &cfg_sltm_once_cmd);
375 install_element(CELLMGR_NODE, &cfg_msc_ip_cmd);
376 install_element(CELLMGR_NODE, &cfg_msc_token_cmd);
377 install_element(CELLMGR_NODE, &cfg_msc_ip_dscp_cmd);
378 install_element(CELLMGR_NODE, &cfg_msc_ip_tos_cmd);
379 install_element(CELLMGR_NODE, &cfg_ping_time_cmd);
380 install_element(CELLMGR_NODE, &cfg_pong_time_cmd);
381 install_element(CELLMGR_NODE, &cfg_msc_time_cmd);
Holger Hans Peter Freyther0e4e35f2010-09-30 03:04:28 +0800382 install_element(CELLMGR_NODE, &cfg_mcc_cmd);
383 install_element(CELLMGR_NODE, &cfg_mnc_cmd);
384 install_element(CELLMGR_NODE, &cfg_lac_cmd);
Holger Hans Peter Freyther51b9e7a2011-01-22 16:02:13 +0100385
386
387 /* show commands */
388 install_element_ve(&show_stats_cmd);
Holger Hans Peter Freyther60af5dd2011-01-22 16:16:52 +0100389 install_element_ve(&show_linksets_cmd);
Holger Hans Peter Freyther0b316222011-01-22 16:43:14 +0100390
391 if (bsc.app != APP_STP) {
392 install_element_ve(&show_msc_cmd);
393 }
Holger Hans Peter Freyther7942abc2010-09-30 00:34:46 +0800394}
395
396const char *openbsc_copyright = "";