blob: e7193f4a3a1700e20706a9f6f46546beaada8535 [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 Freyther7942abc2010-09-30 00:34:46 +080025
26#include <osmocore/talloc.h>
Holger Hans Peter Freyther0e4e35f2010-09-30 03:04:28 +080027#include <osmocore/gsm48.h>
Holger Hans Peter Freyther51b9e7a2011-01-22 16:02:13 +010028#include <osmocore/rate_ctr.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>
Holger Hans Peter Freyther5b2fe8d2011-01-22 21:09:53 +010036#include <sys/types.h>
37#include <sys/stat.h>
38#include <fcntl.h>
Holger Hans Peter Freyther7942abc2010-09-30 00:34:46 +080039
40#undef PACKAGE_NAME
41#undef PACKAGE_VERSION
42#undef PACKAGE_BUGREPORT
43#undef PACKAGE_TARNAME
44#undef PACKAGE_STRING
45#include <cellmgr_config.h>
46
Holger Hans Peter Freyther2ff47b82011-02-15 20:25:10 +010047extern struct bsc_data *bsc;
Holger Hans Peter Freyther7942abc2010-09-30 00:34:46 +080048
49static struct vty_app_info vty_info = {
50 .name = "Cellmgr-ng",
51 .version = VERSION,
52 .go_parent_cb = NULL,
53};
54
55/* vty code */
56enum cellmgr_node {
57 CELLMGR_NODE = _LAST_OSMOVTY_NODE,
58};
59
60static struct cmd_node cell_node = {
61 CELLMGR_NODE,
62 "%s(cellmgr)#",
63 1,
64};
65
Holger Hans Peter Freyther2656e8f2010-09-30 00:41:37 +080066static int config_write_cell(struct vty *vty)
Holger Hans Peter Freyther7942abc2010-09-30 00:34:46 +080067{
Holger Hans Peter Freyther84ec8712011-02-15 20:01:47 +010068 struct msc_connection *msc = msc_connection_num(bsc, 0);
69
Holger Hans Peter Freyther2656e8f2010-09-30 00:41:37 +080070 vty_out(vty, "cellmgr%s", VTY_NEWLINE);
Holger Hans Peter Freyther2ff47b82011-02-15 20:25:10 +010071 vty_out(vty, " mtp dpc %d%s", bsc->dpc, VTY_NEWLINE);
72 vty_out(vty, " mtp opc %d%s", bsc->opc, VTY_NEWLINE);
73 vty_out(vty, " mtp sccp-opc %d%s", bsc->sccp_opc, VTY_NEWLINE);
74 vty_out(vty, " mtp ni %d%s", bsc->ni_ni, VTY_NEWLINE);
75 vty_out(vty, " mtp spare %d%s", bsc->ni_spare, VTY_NEWLINE);
76 vty_out(vty, " mtp sltm once %d%s", bsc->once, VTY_NEWLINE);
77 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);
81 vty_out(vty, " udp reset %d%s", bsc->udp_reset_timeout, VTY_NEWLINE);
82 vty_out(vty, " udp number-links %d%s", bsc->udp_nr_links, VTY_NEWLINE);
Holger Hans Peter Freyther2ff47b82011-02-15 20:25:10 +010083 vty_out(vty, " isup pass-through %d%s", bsc->isup_pass, VTY_NEWLINE);
Holger Hans Peter Freyther2656e8f2010-09-30 00:41:37 +080084
Holger Hans Peter Freyther84ec8712011-02-15 20:01:47 +010085 if (msc) {
86 vty_out(vty, " msc ip %s%s", msc->ip, VTY_NEWLINE);
87 vty_out(vty, " msc ip-dscp %d%s", msc->dscp, VTY_NEWLINE);
88 vty_out(vty, " msc token %s%s", msc->token, VTY_NEWLINE);
89 }
90
91
Holger Hans Peter Freyther7942abc2010-09-30 00:34:46 +080092 return CMD_SUCCESS;
93}
94
95DEFUN(cfg_cell, cfg_cell_cmd,
96 "cellmgr", "Configure the Cellmgr")
97{
98 vty->node = CELLMGR_NODE;
99 return CMD_SUCCESS;
100}
101
102DEFUN(cfg_net_dpc, cfg_net_dpc_cmd,
103 "mtp dpc DPC_NR",
104 "Set the DPC to be used.")
105{
Holger Hans Peter Freyther2ff47b82011-02-15 20:25:10 +0100106 bsc->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 Freyther2ff47b82011-02-15 20:25:10 +0100114 bsc->opc = atoi(argv[0]);
Holger Hans Peter Freyther7942abc2010-09-30 00:34:46 +0800115 return CMD_SUCCESS;
116}
117
Holger Hans Peter Freyther7a725562011-01-01 13:34:58 +0100118DEFUN(cfg_net_sccp_opc, cfg_net_sccp_opc_cmd,
119 "mtp sccp-opc OPC_NR",
120 "Set the SCCP OPC to be used.")
121{
Holger Hans Peter Freyther2ff47b82011-02-15 20:25:10 +0100122 bsc->sccp_opc = atoi(argv[0]);
Holger Hans Peter Freyther7a725562011-01-01 13:34:58 +0100123 return CMD_SUCCESS;
124}
125
Holger Hans Peter Freytherb38b33b2010-11-26 21:21:04 +0100126DEFUN(cfg_net_mtp_ni, cfg_net_mtp_ni_cmd,
127 "mtp ni NR",
128 "Set the MTP NI to be used.\n" "NR")
129{
Holger Hans Peter Freyther2ff47b82011-02-15 20:25:10 +0100130 bsc->ni_ni = atoi(argv[0]);
Holger Hans Peter Freytherb38b33b2010-11-26 21:21:04 +0100131 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{
Holger Hans Peter Freyther2ff47b82011-02-15 20:25:10 +0100138 bsc->ni_spare = atoi(argv[0]);
Holger Hans Peter Freytherb38b33b2010-11-26 21:21:04 +0100139 return CMD_SUCCESS;
140}
141
142
Holger Hans Peter Freyther7942abc2010-09-30 00:34:46 +0800143DEFUN(cfg_udp_dst_ip, cfg_udp_dst_ip_cmd,
144 "udp dest ip IP",
145 "Set the IP when UDP mode is supposed to be used.")
146{
147 struct hostent *hosts;
148 struct in_addr *addr;
149
150 hosts = gethostbyname(argv[0]);
151 if (!hosts || hosts->h_length < 1 || hosts->h_addrtype != AF_INET) {
152 vty_out(vty, "Failed to resolve '%s'%s", argv[0], VTY_NEWLINE);
153 return CMD_WARNING;
154 }
155
156 addr = (struct in_addr *) hosts->h_addr_list[0];
Holger Hans Peter Freyther2ff47b82011-02-15 20:25:10 +0100157 bsc->udp_ip = talloc_strdup(NULL, inet_ntoa(*addr));
Holger Hans Peter Freyther7942abc2010-09-30 00:34:46 +0800158 return CMD_SUCCESS;
159}
160
161DEFUN(cfg_udp_dst_port, cfg_udp_dst_port_cmd,
162 "udp dest port PORT_NR",
163 "If UDP mode is used specify the UDP dest port")
164{
Holger Hans Peter Freyther2ff47b82011-02-15 20:25:10 +0100165 bsc->udp_port = atoi(argv[0]);
Holger Hans Peter Freyther7942abc2010-09-30 00:34:46 +0800166 return CMD_SUCCESS;
167}
168
169DEFUN(cfg_udp_src_port, cfg_udp_src_port_cmd,
170 "udp src port PORT_NR",
171 "Set the UDP source port to be used.")
172{
Holger Hans Peter Freyther2ff47b82011-02-15 20:25:10 +0100173 bsc->src_port = atoi(argv[0]);
Holger Hans Peter Freyther7942abc2010-09-30 00:34:46 +0800174 return CMD_SUCCESS;
175}
176
177DEFUN(cfg_udp_reset, cfg_udp_reset_cmd,
178 "udp reset TIMEOUT",
179 "Set the timeout to take the link down")
180{
Holger Hans Peter Freyther2ff47b82011-02-15 20:25:10 +0100181 bsc->udp_reset_timeout = atoi(argv[0]);
Holger Hans Peter Freyther7942abc2010-09-30 00:34:46 +0800182 return CMD_SUCCESS;
183}
184
Holger Hans Peter Freytherc6bfa272011-01-22 17:06:34 +0100185DEFUN(cfg_udp_nr_links, cfg_udp_nr_links_cmd,
186 "udp number-links <1-32>",
187 "Set the number of links to use\n")
188{
Holger Hans Peter Freyther2ff47b82011-02-15 20:25:10 +0100189 bsc->udp_nr_links = atoi(argv[0]);
Holger Hans Peter Freytherc6bfa272011-01-22 17:06:34 +0100190 return CMD_SUCCESS;
191}
192
Holger Hans Peter Freyther7942abc2010-09-30 00:34:46 +0800193DEFUN(cfg_sltm_once, cfg_sltm_once_cmd,
194 "mtp sltm once (0|1)",
195 "Send SLTMs until the link is established.")
196{
Holger Hans Peter Freyther2ff47b82011-02-15 20:25:10 +0100197 bsc->once = !!atoi(argv[0]);
Holger Hans Peter Freyther7942abc2010-09-30 00:34:46 +0800198 return CMD_SUCCESS;
199}
200
201DEFUN(cfg_msc_ip, cfg_msc_ip_cmd,
202 "msc ip IP",
203 "Set the MSC IP")
204{
205 struct hostent *hosts;
206 struct in_addr *addr;
Holger Hans Peter Freyther84ec8712011-02-15 20:01:47 +0100207 struct msc_connection *msc = msc_connection_num(bsc, 0);
208
209 if (!msc) {
210 vty_out(vty, "%%No MSC Connection defined in this app.%s", VTY_NEWLINE);
211 return CMD_WARNING;
212 }
Holger Hans Peter Freyther7942abc2010-09-30 00:34:46 +0800213
214 hosts = gethostbyname(argv[0]);
215 if (!hosts || hosts->h_length < 1 || hosts->h_addrtype != AF_INET) {
216 vty_out(vty, "Failed to resolve '%s'%s", argv[0], VTY_NEWLINE);
217 return CMD_WARNING;
218 }
219
220 addr = (struct in_addr *) hosts->h_addr_list[0];
221
Holger Hans Peter Freyther84ec8712011-02-15 20:01:47 +0100222 if (msc->ip)
223 talloc_free(msc->ip);
224 msc->ip = talloc_strdup(msc, inet_ntoa(*addr));
Holger Hans Peter Freyther7942abc2010-09-30 00:34:46 +0800225 return CMD_SUCCESS;
226}
227
228DEFUN(cfg_msc_ip_dscp, cfg_msc_ip_dscp_cmd,
229 "msc ip-dscp <0-255>",
230 "Set the IP DSCP on the A-link\n"
231 "Set the DSCP in IP packets to the MSC")
232{
Holger Hans Peter Freyther84ec8712011-02-15 20:01:47 +0100233 struct msc_connection *msc = msc_connection_num(bsc, 0);
234
235 if (!msc) {
236 vty_out(vty, "%%No MSC Connection defined in this app.%s", VTY_NEWLINE);
237 return CMD_WARNING;
238 }
239
240 msc->dscp = atoi(argv[0]);
Holger Hans Peter Freyther7942abc2010-09-30 00:34:46 +0800241 return CMD_SUCCESS;
242}
243
244ALIAS_DEPRECATED(cfg_msc_ip_dscp, cfg_msc_ip_tos_cmd,
245 "msc ip-tos <0-255>",
246 "Set the IP DSCP on the A-link\n"
247 "Set the DSCP in IP packets to the MSC")
248
249DEFUN(cfg_msc_token, cfg_msc_token_cmd,
250 "msc token TOKEN",
251 "Set the Token to be used for the MSC")
252{
Holger Hans Peter Freyther84ec8712011-02-15 20:01:47 +0100253 struct msc_connection *msc = msc_connection_num(bsc, 0);
254
255 if (!msc) {
256 vty_out(vty, "%%No MSC Connection defined in this app.%s", VTY_NEWLINE);
257 return CMD_WARNING;
258 }
259
260 if (msc->token)
261 talloc_free(msc->token);
262 msc->token = talloc_strdup(msc, argv[0]);
Holger Hans Peter Freyther7942abc2010-09-30 00:34:46 +0800263 return CMD_SUCCESS;
264}
265
266DEFUN(cfg_ping_time, cfg_ping_time_cmd,
267 "timeout ping NR",
268 "Set the PING interval. Negative to disable it")
269{
Holger Hans Peter Freyther84ec8712011-02-15 20:01:47 +0100270 struct msc_connection *msc = msc_connection_num(bsc, 0);
271
272 if (!msc) {
273 vty_out(vty, "%%No MSC Connection defined in this app.%s", VTY_NEWLINE);
274 return CMD_WARNING;
275 }
276
277 msc->ping_time = atoi(argv[0]);
Holger Hans Peter Freyther7942abc2010-09-30 00:34:46 +0800278 return CMD_SUCCESS;
279}
280
281DEFUN(cfg_pong_time, cfg_pong_time_cmd,
282 "timeout pong NR",
283 "Set the PING interval. Negative to disable it")
284{
Holger Hans Peter Freyther84ec8712011-02-15 20:01:47 +0100285 struct msc_connection *msc = msc_connection_num(bsc, 0);
286
287 if (!msc) {
288 vty_out(vty, "%%No MSC Connection defined in this app.%s", VTY_NEWLINE);
289 return CMD_WARNING;
290 }
291
292 msc->pong_time = atoi(argv[0]);
Holger Hans Peter Freyther7942abc2010-09-30 00:34:46 +0800293 return CMD_SUCCESS;
294}
295
296DEFUN(cfg_msc_time, cfg_msc_time_cmd,
297 "timeout msc NR",
298 "Set the MSC connect timeout")
299{
Holger Hans Peter Freyther84ec8712011-02-15 20:01:47 +0100300 struct msc_connection *msc = msc_connection_num(bsc, 0);
301
302 if (!msc) {
303 vty_out(vty, "%%No MSC Connection defined in this app.%s", VTY_NEWLINE);
304 return CMD_WARNING;
305 }
306
307 msc->msc_time = atoi(argv[0]);
Holger Hans Peter Freyther7942abc2010-09-30 00:34:46 +0800308 return CMD_SUCCESS;
309}
310
Holger Hans Peter Freytherf603f282011-01-30 00:24:15 +0100311DEFUN(cfg_isup_pass, cfg_isup_pass_cmd,
312 "isup pass-through (0|1)",
313 "ISUP related functionality\n"
314 "Pass through all ISUP messages directly\n"
315 "Handle some messages locally\n" "Pass through everything\n")
316{
Holger Hans Peter Freyther89fa11a2011-02-10 18:26:07 +0100317 struct mtp_link_set *set;
318
Holger Hans Peter Freyther2ff47b82011-02-15 20:25:10 +0100319 bsc->isup_pass = atoi(argv[0]);
Holger Hans Peter Freyther89fa11a2011-02-10 18:26:07 +0100320
Holger Hans Peter Freyther599c9a42011-02-15 11:18:38 +0100321 llist_for_each_entry(set, &bsc->linksets, entry)
Holger Hans Peter Freyther2ff47b82011-02-15 20:25:10 +0100322 set->pass_all_isup = bsc->isup_pass;
Holger Hans Peter Freytherf603f282011-01-30 00:24:15 +0100323
324 return CMD_SUCCESS;
325}
326
Holger Hans Peter Freyther89fa11a2011-02-10 18:26:07 +0100327static void dump_stats(struct vty *vty, struct mtp_link_set *set)
Holger Hans Peter Freyther51b9e7a2011-01-22 16:02:13 +0100328{
329 struct mtp_link *link;
330
Holger Hans Peter Freyther89fa11a2011-02-10 18:26:07 +0100331 vty_out(vty, "Linkset name: %s opc: %d%s", set->name, set->opc, VTY_NEWLINE);
Holger Hans Peter Freyther51b9e7a2011-01-22 16:02:13 +0100332 vty_out_rate_ctr_group(vty, " ", set->ctrg);
333
334 llist_for_each_entry(link, &set->links, entry) {
335 vty_out(vty, " Link %d%s", link->link_no, VTY_NEWLINE);
336 vty_out_rate_ctr_group(vty, " ", link->ctrg);
337 }
338}
339
340DEFUN(show_stats, show_stats_cmd,
341 "show statistics",
342 SHOW_STR "Display Linkset statistics\n")
343{
Holger Hans Peter Freyther89fa11a2011-02-10 18:26:07 +0100344 struct mtp_link_set *set;
345
Holger Hans Peter Freyther599c9a42011-02-15 11:18:38 +0100346 llist_for_each_entry(set, &bsc->linksets, entry)
Holger Hans Peter Freyther89fa11a2011-02-10 18:26:07 +0100347 dump_stats(vty, set);
348
Holger Hans Peter Freyther51b9e7a2011-01-22 16:02:13 +0100349 return CMD_SUCCESS;
350}
351
Holger Hans Peter Freyther89fa11a2011-02-10 18:26:07 +0100352static void dump_state(struct vty *vty, struct mtp_link_set *set)
Holger Hans Peter Freyther60af5dd2011-01-22 16:16:52 +0100353{
354 struct mtp_link *link;
355
356 if (!set) {
Holger Hans Peter Freyther89fa11a2011-02-10 18:26:07 +0100357 vty_out(vty, "LinkSet for %s is not configured.%s", set->name, VTY_NEWLINE);
Holger Hans Peter Freyther60af5dd2011-01-22 16:16:52 +0100358 return;
359 }
360
361 vty_out(vty, "LinkSet for %s is %s, remote sccp is %s.%s",
Holger Hans Peter Freyther89fa11a2011-02-10 18:26:07 +0100362 set->name,
Holger Hans Peter Freyther60af5dd2011-01-22 16:16:52 +0100363 set->available == 0 ? "not available" : "available",
364 set->sccp_up == 0? "not established" : "established",
365 VTY_NEWLINE);
366
367 llist_for_each_entry(link, &set->links, entry) {
Holger Hans Peter Freyther4e2e2422011-01-24 15:40:30 +0100368 if (link->blocked)
369 vty_out(vty, " Link %d is blocked.%s",
370 link->link_no, VTY_NEWLINE);
371 else
372 vty_out(vty, " Link %d is %s.%s",
373 link->link_no,
374 link->available == 0 ? "not available" : "available",
375 VTY_NEWLINE);
Holger Hans Peter Freyther60af5dd2011-01-22 16:16:52 +0100376 }
377}
378
379DEFUN(show_linksets, show_linksets_cmd,
380 "show link-sets",
381 SHOW_STR "Display current state of linksets\n")
382{
Holger Hans Peter Freyther89fa11a2011-02-10 18:26:07 +0100383 struct mtp_link_set *set;
384
Holger Hans Peter Freyther599c9a42011-02-15 11:18:38 +0100385 llist_for_each_entry(set, &bsc->linksets, entry)
Holger Hans Peter Freyther89fa11a2011-02-10 18:26:07 +0100386 dump_state(vty, set);
Holger Hans Peter Freyther60af5dd2011-01-22 16:16:52 +0100387 return CMD_SUCCESS;
388}
389
Holger Hans Peter Freyther0b316222011-01-22 16:43:14 +0100390DEFUN(show_msc, show_msc_cmd,
391 "show msc",
392 SHOW_STR "Display the status of the MSC\n")
393{
Holger Hans Peter Freyther84ec8712011-02-15 20:01:47 +0100394 struct msc_connection *msc = msc_connection_num(bsc, 0);
395
396 if (!msc) {
397 vty_out(vty, "%%No MSC Connection defined in this app.%s", VTY_NEWLINE);
398 return CMD_WARNING;
399 }
400
Holger Hans Peter Freyther0b316222011-01-22 16:43:14 +0100401 vty_out(vty, "MSC link is %s and had %s.%s",
Holger Hans Peter Freyther84ec8712011-02-15 20:01:47 +0100402 msc->msc_link_down == 0 ? "up" : "down",
403 msc->first_contact == 1 ? "no contact" : "contact",
Holger Hans Peter Freyther0b316222011-01-22 16:43:14 +0100404 VTY_NEWLINE);
405 return CMD_SUCCESS;
406}
407
Holger Hans Peter Freyther89fa11a2011-02-10 18:26:07 +0100408static struct mtp_link_set *find_link_set(struct llist_head *head,
409 const char *name)
410{
411 struct mtp_link_set *set;
412
413 llist_for_each_entry(set, head, entry)
414 if (strcmp(name, set->name) == 0)
415 return set;
416
417 return NULL;
418}
419
Holger Hans Peter Freyther3c2b84c2011-01-24 21:13:56 +0100420DEFUN(show_slc, show_slc_cmd,
Holger Hans Peter Freyther89fa11a2011-02-10 18:26:07 +0100421 "show link-set NAME slc",
422 SHOW_STR "LinkSet\n" "Linkset name\n" "SLS to SLC\n")
Holger Hans Peter Freyther3c2b84c2011-01-24 21:13:56 +0100423{
424 struct mtp_link_set *set = NULL;
425 int i;
426
Holger Hans Peter Freyther599c9a42011-02-15 11:18:38 +0100427 set = find_link_set(&bsc->linksets, argv[0]);
Holger Hans Peter Freyther3c2b84c2011-01-24 21:13:56 +0100428
429 if (!set) {
430 vty_out(vty, "Failed to find linkset.%s", VTY_NEWLINE);
431 return CMD_WARNING;
432 }
433
434 vty_out(vty, "LinkSet for %s.%s", argv[0], VTY_NEWLINE);
435 for (i = 0; i < ARRAY_SIZE(set->slc); ++i) {
436 if (set->slc[i])
437 vty_out(vty, " SLC[%.2d] is on link %d.%s",
438 i, set->slc[i]->link_no, VTY_NEWLINE);
439 else
440 vty_out(vty, " SLC[%d] is down.%s",
441 i, VTY_NEWLINE);
442 }
443
444 return CMD_SUCCESS;
445}
446
Holger Hans Peter Freyther5b2fe8d2011-01-22 21:09:53 +0100447DEFUN(pcap_set, pcap_set_cmd,
Holger Hans Peter Freyther89fa11a2011-02-10 18:26:07 +0100448 "trace-pcap set NAME FILE",
Holger Hans Peter Freyther5b2fe8d2011-01-22 21:09:53 +0100449 "Trace to a PCAP file\n" "Trace a linkset\n"
Holger Hans Peter Freyther89fa11a2011-02-10 18:26:07 +0100450 "Trace Linkset\n" "Filename to trace\n")
Holger Hans Peter Freyther5b2fe8d2011-01-22 21:09:53 +0100451{
452 struct mtp_link_set *set = NULL;
453
Holger Hans Peter Freyther599c9a42011-02-15 11:18:38 +0100454 set = find_link_set(&bsc->linksets, argv[0]);
Holger Hans Peter Freyther5b2fe8d2011-01-22 21:09:53 +0100455
456 if (!set) {
457 vty_out(vty, "Failed to find linkset.%s", VTY_NEWLINE);
458 return CMD_WARNING;
459 }
460
461
Holger Hans Peter Freyther2ff47b82011-02-15 20:25:10 +0100462 if (set->pcap_fd >= 0 && bsc->pcap_fd != set->pcap_fd)
Holger Hans Peter Freyther5b2fe8d2011-01-22 21:09:53 +0100463 close(set->pcap_fd);
464 set->pcap_fd = open(argv[1], O_WRONLY | O_TRUNC | O_CREAT,
465 S_IRUSR | S_IWUSR | S_IRGRP| S_IROTH);
466 if (set->pcap_fd < 0) {
467 vty_out(vty, "Failed to open file for writing.%s", VTY_NEWLINE);
468 return CMD_WARNING;
469 }
470
471 mtp_pcap_write_header(set->pcap_fd);
472 return CMD_SUCCESS;
473}
474
475DEFUN(pcap_set_stop, pcap_set_stop_cmd,
Holger Hans Peter Freyther89fa11a2011-02-10 18:26:07 +0100476 "trace-pcap set NAME stop",
Holger Hans Peter Freyther5b2fe8d2011-01-22 21:09:53 +0100477 "Trace to a PCAP file\n" "Trace a linkset\n"
Holger Hans Peter Freyther89fa11a2011-02-10 18:26:07 +0100478 "Trace Linkset\n" "Stop the tracing\n")
Holger Hans Peter Freyther5b2fe8d2011-01-22 21:09:53 +0100479{
480 struct mtp_link_set *set = NULL;
481
Holger Hans Peter Freyther599c9a42011-02-15 11:18:38 +0100482 set = find_link_set(&bsc->linksets, argv[0]);
Holger Hans Peter Freyther5b2fe8d2011-01-22 21:09:53 +0100483
484 if (!set) {
485 vty_out(vty, "Failed to find linkset.%s", VTY_NEWLINE);
486 return CMD_WARNING;
487 }
488
Holger Hans Peter Freyther2ff47b82011-02-15 20:25:10 +0100489 if (set->pcap_fd >= 0 && bsc->pcap_fd != set->pcap_fd)
Holger Hans Peter Freyther5b2fe8d2011-01-22 21:09:53 +0100490 close(set->pcap_fd);
491 set->pcap_fd = -1;
492 return CMD_SUCCESS;
493}
494
Holger Hans Peter Freyther315ec672011-01-24 15:35:56 +0100495#define FIND_LINK(vty, type, nr) ({ \
496 struct mtp_link_set *set = NULL; \
497 struct mtp_link *link = NULL, *tmp; \
Holger Hans Peter Freyther599c9a42011-02-15 11:18:38 +0100498 set = find_link_set(&bsc->linksets, type); \
Holger Hans Peter Freyther89fa11a2011-02-10 18:26:07 +0100499 if (!set) { \
Holger Hans Peter Freyther315ec672011-01-24 15:35:56 +0100500 vty_out(vty, "Unknown linkset %s.%s", type, VTY_NEWLINE); \
501 return CMD_WARNING; \
502 } \
503 llist_for_each_entry(tmp, &set->links, entry) { \
504 if (tmp->link_no == nr) { \
505 link = tmp; \
506 break; \
507 } \
508 } \
509 if (!link) { \
510 vty_out(vty, "Can not find link %d.%s", nr, VTY_NEWLINE); \
511 return CMD_WARNING; \
512 } \
513 link; })
514
515#define LINK_STR "Operations on the link\n" \
Holger Hans Peter Freyther89fa11a2011-02-10 18:26:07 +0100516 "Linkset name\n" \
Holger Hans Peter Freyther315ec672011-01-24 15:35:56 +0100517 "Link number\n"
518
519DEFUN(lnk_block, lnk_block_cmd,
Holger Hans Peter Freyther89fa11a2011-02-10 18:26:07 +0100520 "link NAME <0-15> block",
Holger Hans Peter Freyther315ec672011-01-24 15:35:56 +0100521 LINK_STR "Block it\n")
522{
523 struct mtp_link *link = FIND_LINK(vty, argv[0], atoi(argv[1]));
524 mtp_link_block(link);
525 return CMD_SUCCESS;
526}
527
528DEFUN(lnk_unblock, lnk_unblock_cmd,
Holger Hans Peter Freyther89fa11a2011-02-10 18:26:07 +0100529 "link NAME <0-15> unblock",
Holger Hans Peter Freyther315ec672011-01-24 15:35:56 +0100530 LINK_STR "Unblock it\n")
531{
532 struct mtp_link *link = FIND_LINK(vty, argv[0], atoi(argv[1]));
533 mtp_link_unblock(link);
534 return CMD_SUCCESS;
535}
536
537DEFUN(lnk_reset, lnk_reset_cmd,
Holger Hans Peter Freyther89fa11a2011-02-10 18:26:07 +0100538 "link NAME <0-15> reset",
Holger Hans Peter Freyther315ec672011-01-24 15:35:56 +0100539 LINK_STR "Reset it\n")
540{
541 struct mtp_link *link = FIND_LINK(vty, argv[0], atoi(argv[1]));
542 mtp_link_failure(link);
543 return CMD_SUCCESS;
544}
545
Holger Hans Peter Freytheree63d7d2011-02-10 12:39:05 +0100546DEFUN(allow_inject, allow_inject_cmd,
547 "allow-inject (0|1)",
548 "Allow to inject messages\n" "Disable\n" "Enable\n")
549{
Holger Hans Peter Freyther2ff47b82011-02-15 20:25:10 +0100550 bsc->allow_inject = atoi(argv[0]);
Holger Hans Peter Freytheree63d7d2011-02-10 12:39:05 +0100551 return CMD_SUCCESS;
552}
Holger Hans Peter Freyther5b2fe8d2011-01-22 21:09:53 +0100553
Holger Hans Peter Freyther7942abc2010-09-30 00:34:46 +0800554void cell_vty_init(void)
555{
556 cmd_init(1);
557 vty_init(&vty_info);
Holger Hans Peter Freytherfca7b122011-01-22 23:19:44 +0100558 logging_vty_add_cmds();
Holger Hans Peter Freyther7942abc2010-09-30 00:34:46 +0800559
560 install_element(CONFIG_NODE, &cfg_cell_cmd);
561 install_node(&cell_node, config_write_cell);
562
563 install_element(CELLMGR_NODE, &cfg_net_dpc_cmd);
564 install_element(CELLMGR_NODE, &cfg_net_opc_cmd);
Holger Hans Peter Freyther7a725562011-01-01 13:34:58 +0100565 install_element(CELLMGR_NODE, &cfg_net_sccp_opc_cmd);
Holger Hans Peter Freytherb38b33b2010-11-26 21:21:04 +0100566 install_element(CELLMGR_NODE, &cfg_net_mtp_ni_cmd);
567 install_element(CELLMGR_NODE, &cfg_net_mtp_spare_cmd);
Holger Hans Peter Freyther7942abc2010-09-30 00:34:46 +0800568 install_element(CELLMGR_NODE, &cfg_udp_dst_ip_cmd);
569 install_element(CELLMGR_NODE, &cfg_udp_dst_port_cmd);
570 install_element(CELLMGR_NODE, &cfg_udp_src_port_cmd);
571 install_element(CELLMGR_NODE, &cfg_udp_reset_cmd);
Holger Hans Peter Freytherc6bfa272011-01-22 17:06:34 +0100572 install_element(CELLMGR_NODE, &cfg_udp_nr_links_cmd);
Holger Hans Peter Freyther7942abc2010-09-30 00:34:46 +0800573 install_element(CELLMGR_NODE, &cfg_sltm_once_cmd);
574 install_element(CELLMGR_NODE, &cfg_msc_ip_cmd);
575 install_element(CELLMGR_NODE, &cfg_msc_token_cmd);
576 install_element(CELLMGR_NODE, &cfg_msc_ip_dscp_cmd);
577 install_element(CELLMGR_NODE, &cfg_msc_ip_tos_cmd);
578 install_element(CELLMGR_NODE, &cfg_ping_time_cmd);
579 install_element(CELLMGR_NODE, &cfg_pong_time_cmd);
580 install_element(CELLMGR_NODE, &cfg_msc_time_cmd);
Holger Hans Peter Freytherf603f282011-01-30 00:24:15 +0100581 install_element(CELLMGR_NODE, &cfg_isup_pass_cmd);
Holger Hans Peter Freyther51b9e7a2011-01-22 16:02:13 +0100582
Holger Hans Peter Freyther5b2fe8d2011-01-22 21:09:53 +0100583 /* special commands */
584 install_element(ENABLE_NODE, &pcap_set_cmd);
585 install_element(ENABLE_NODE, &pcap_set_stop_cmd);
Holger Hans Peter Freyther315ec672011-01-24 15:35:56 +0100586 install_element(ENABLE_NODE, &lnk_block_cmd);
587 install_element(ENABLE_NODE, &lnk_unblock_cmd);
588 install_element(ENABLE_NODE, &lnk_reset_cmd);
Holger Hans Peter Freytheree63d7d2011-02-10 12:39:05 +0100589 install_element(ENABLE_NODE, &allow_inject_cmd);
Holger Hans Peter Freyther51b9e7a2011-01-22 16:02:13 +0100590
591 /* show commands */
592 install_element_ve(&show_stats_cmd);
Holger Hans Peter Freyther60af5dd2011-01-22 16:16:52 +0100593 install_element_ve(&show_linksets_cmd);
Holger Hans Peter Freyther3c2b84c2011-01-24 21:13:56 +0100594 install_element_ve(&show_slc_cmd);
Holger Hans Peter Freyther0b316222011-01-22 16:43:14 +0100595
Holger Hans Peter Freyther2ff47b82011-02-15 20:25:10 +0100596 if (bsc->app != APP_STP) {
Holger Hans Peter Freyther0b316222011-01-22 16:43:14 +0100597 install_element_ve(&show_msc_cmd);
598 }
Holger Hans Peter Freyther7942abc2010-09-30 00:34:46 +0800599}
600
601const char *openbsc_copyright = "";