blob: fbf02003fb1423a9fbdecd9d5a530771ef977191 [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
Holger Hans Peter Freyther2ff47b82011-02-15 20:25:10 +010046extern struct bsc_data *bsc;
Holger Hans Peter Freyther7942abc2010-09-30 00:34:46 +080047
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);
Holger Hans Peter Freyther2ff47b82011-02-15 20:25:10 +010068 vty_out(vty, " mtp dpc %d%s", bsc->dpc, VTY_NEWLINE);
69 vty_out(vty, " mtp opc %d%s", bsc->opc, VTY_NEWLINE);
70 vty_out(vty, " mtp sccp-opc %d%s", bsc->sccp_opc, VTY_NEWLINE);
71 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);
73 vty_out(vty, " mtp sltm once %d%s", bsc->once, VTY_NEWLINE);
74 if (bsc->udp_ip)
75 vty_out(vty, " udp dest ip %s%s", bsc->udp_ip, VTY_NEWLINE);
76 vty_out(vty, " udp dest port %d%s", bsc->udp_port, VTY_NEWLINE);
77 vty_out(vty, " udp src port %d%s", bsc->src_port, VTY_NEWLINE);
78 vty_out(vty, " udp reset %d%s", bsc->udp_reset_timeout, VTY_NEWLINE);
79 vty_out(vty, " udp number-links %d%s", bsc->udp_nr_links, VTY_NEWLINE);
80 vty_out(vty, " msc ip %s%s", bsc->msc_forward.msc_address, VTY_NEWLINE);
81 vty_out(vty, " msc ip-dscp %d%s", bsc->msc_forward.msc_ip_dscp, VTY_NEWLINE);
82 vty_out(vty, " msc token %s%s", bsc->msc_forward.token, VTY_NEWLINE);
83 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 Freyther7942abc2010-09-30 00:34:46 +080085 return CMD_SUCCESS;
86}
87
88DEFUN(cfg_cell, cfg_cell_cmd,
89 "cellmgr", "Configure the Cellmgr")
90{
91 vty->node = CELLMGR_NODE;
92 return CMD_SUCCESS;
93}
94
95DEFUN(cfg_net_dpc, cfg_net_dpc_cmd,
96 "mtp dpc DPC_NR",
97 "Set the DPC to be used.")
98{
Holger Hans Peter Freyther2ff47b82011-02-15 20:25:10 +010099 bsc->dpc = atoi(argv[0]);
Holger Hans Peter Freyther7942abc2010-09-30 00:34:46 +0800100 return CMD_SUCCESS;
101}
102
103DEFUN(cfg_net_opc, cfg_net_opc_cmd,
104 "mtp opc OPC_NR",
105 "Set the OPC to be used.")
106{
Holger Hans Peter Freyther2ff47b82011-02-15 20:25:10 +0100107 bsc->opc = atoi(argv[0]);
Holger Hans Peter Freyther7942abc2010-09-30 00:34:46 +0800108 return CMD_SUCCESS;
109}
110
Holger Hans Peter Freyther7a725562011-01-01 13:34:58 +0100111DEFUN(cfg_net_sccp_opc, cfg_net_sccp_opc_cmd,
112 "mtp sccp-opc OPC_NR",
113 "Set the SCCP OPC to be used.")
114{
Holger Hans Peter Freyther2ff47b82011-02-15 20:25:10 +0100115 bsc->sccp_opc = atoi(argv[0]);
Holger Hans Peter Freyther7a725562011-01-01 13:34:58 +0100116 return CMD_SUCCESS;
117}
118
Holger Hans Peter Freytherb38b33b2010-11-26 21:21:04 +0100119DEFUN(cfg_net_mtp_ni, cfg_net_mtp_ni_cmd,
120 "mtp ni NR",
121 "Set the MTP NI to be used.\n" "NR")
122{
Holger Hans Peter Freyther2ff47b82011-02-15 20:25:10 +0100123 bsc->ni_ni = atoi(argv[0]);
Holger Hans Peter Freytherb38b33b2010-11-26 21:21:04 +0100124 return CMD_SUCCESS;
125}
126
127DEFUN(cfg_net_mtp_spare, cfg_net_mtp_spare_cmd,
128 "mtp spare NR",
129 "Set the MTP Spare to be used.\n" "NR")
130{
Holger Hans Peter Freyther2ff47b82011-02-15 20:25:10 +0100131 bsc->ni_spare = atoi(argv[0]);
Holger Hans Peter Freytherb38b33b2010-11-26 21:21:04 +0100132 return CMD_SUCCESS;
133}
134
135
Holger Hans Peter Freyther7942abc2010-09-30 00:34:46 +0800136DEFUN(cfg_udp_dst_ip, cfg_udp_dst_ip_cmd,
137 "udp dest ip IP",
138 "Set the IP when UDP mode is supposed to be used.")
139{
140 struct hostent *hosts;
141 struct in_addr *addr;
142
143 hosts = gethostbyname(argv[0]);
144 if (!hosts || hosts->h_length < 1 || hosts->h_addrtype != AF_INET) {
145 vty_out(vty, "Failed to resolve '%s'%s", argv[0], VTY_NEWLINE);
146 return CMD_WARNING;
147 }
148
149 addr = (struct in_addr *) hosts->h_addr_list[0];
Holger Hans Peter Freyther2ff47b82011-02-15 20:25:10 +0100150 bsc->udp_ip = talloc_strdup(NULL, inet_ntoa(*addr));
Holger Hans Peter Freyther7942abc2010-09-30 00:34:46 +0800151 return CMD_SUCCESS;
152}
153
154DEFUN(cfg_udp_dst_port, cfg_udp_dst_port_cmd,
155 "udp dest port PORT_NR",
156 "If UDP mode is used specify the UDP dest port")
157{
Holger Hans Peter Freyther2ff47b82011-02-15 20:25:10 +0100158 bsc->udp_port = atoi(argv[0]);
Holger Hans Peter Freyther7942abc2010-09-30 00:34:46 +0800159 return CMD_SUCCESS;
160}
161
162DEFUN(cfg_udp_src_port, cfg_udp_src_port_cmd,
163 "udp src port PORT_NR",
164 "Set the UDP source port to be used.")
165{
Holger Hans Peter Freyther2ff47b82011-02-15 20:25:10 +0100166 bsc->src_port = atoi(argv[0]);
Holger Hans Peter Freyther7942abc2010-09-30 00:34:46 +0800167 return CMD_SUCCESS;
168}
169
170DEFUN(cfg_udp_reset, cfg_udp_reset_cmd,
171 "udp reset TIMEOUT",
172 "Set the timeout to take the link down")
173{
Holger Hans Peter Freyther2ff47b82011-02-15 20:25:10 +0100174 bsc->udp_reset_timeout = atoi(argv[0]);
Holger Hans Peter Freyther7942abc2010-09-30 00:34:46 +0800175 return CMD_SUCCESS;
176}
177
Holger Hans Peter Freytherc6bfa272011-01-22 17:06:34 +0100178DEFUN(cfg_udp_nr_links, cfg_udp_nr_links_cmd,
179 "udp number-links <1-32>",
180 "Set the number of links to use\n")
181{
Holger Hans Peter Freyther2ff47b82011-02-15 20:25:10 +0100182 bsc->udp_nr_links = atoi(argv[0]);
Holger Hans Peter Freytherc6bfa272011-01-22 17:06:34 +0100183 return CMD_SUCCESS;
184}
185
Holger Hans Peter Freyther7942abc2010-09-30 00:34:46 +0800186DEFUN(cfg_sltm_once, cfg_sltm_once_cmd,
187 "mtp sltm once (0|1)",
188 "Send SLTMs until the link is established.")
189{
Holger Hans Peter Freyther2ff47b82011-02-15 20:25:10 +0100190 bsc->once = !!atoi(argv[0]);
Holger Hans Peter Freyther7942abc2010-09-30 00:34:46 +0800191 return CMD_SUCCESS;
192}
193
194DEFUN(cfg_msc_ip, cfg_msc_ip_cmd,
195 "msc ip IP",
196 "Set the MSC IP")
197{
198 struct hostent *hosts;
199 struct in_addr *addr;
200
201 hosts = gethostbyname(argv[0]);
202 if (!hosts || hosts->h_length < 1 || hosts->h_addrtype != AF_INET) {
203 vty_out(vty, "Failed to resolve '%s'%s", argv[0], VTY_NEWLINE);
204 return CMD_WARNING;
205 }
206
207 addr = (struct in_addr *) hosts->h_addr_list[0];
208
Holger Hans Peter Freyther2ff47b82011-02-15 20:25:10 +0100209 bsc->msc_forward.msc_address = talloc_strdup(NULL, inet_ntoa(*addr));
Holger Hans Peter Freyther7942abc2010-09-30 00:34:46 +0800210 return CMD_SUCCESS;
211}
212
213DEFUN(cfg_msc_ip_dscp, cfg_msc_ip_dscp_cmd,
214 "msc ip-dscp <0-255>",
215 "Set the IP DSCP on the A-link\n"
216 "Set the DSCP in IP packets to the MSC")
217{
Holger Hans Peter Freyther2ff47b82011-02-15 20:25:10 +0100218 bsc->msc_forward.msc_ip_dscp = atoi(argv[0]);
Holger Hans Peter Freyther7942abc2010-09-30 00:34:46 +0800219 return CMD_SUCCESS;
220}
221
222ALIAS_DEPRECATED(cfg_msc_ip_dscp, cfg_msc_ip_tos_cmd,
223 "msc ip-tos <0-255>",
224 "Set the IP DSCP on the A-link\n"
225 "Set the DSCP in IP packets to the MSC")
226
227DEFUN(cfg_msc_token, cfg_msc_token_cmd,
228 "msc token TOKEN",
229 "Set the Token to be used for the MSC")
230{
Holger Hans Peter Freyther2ff47b82011-02-15 20:25:10 +0100231 bsc->msc_forward.token = talloc_strdup(NULL, argv[0]);
Holger Hans Peter Freyther7942abc2010-09-30 00:34:46 +0800232 return CMD_SUCCESS;
233}
234
235DEFUN(cfg_ping_time, cfg_ping_time_cmd,
236 "timeout ping NR",
237 "Set the PING interval. Negative to disable it")
238{
Holger Hans Peter Freyther2ff47b82011-02-15 20:25:10 +0100239 bsc->msc_forward.ping_time = atoi(argv[0]);
Holger Hans Peter Freyther7942abc2010-09-30 00:34:46 +0800240 return CMD_SUCCESS;
241}
242
243DEFUN(cfg_pong_time, cfg_pong_time_cmd,
244 "timeout pong NR",
245 "Set the PING interval. Negative to disable it")
246{
Holger Hans Peter Freyther2ff47b82011-02-15 20:25:10 +0100247 bsc->msc_forward.pong_time = atoi(argv[0]);
Holger Hans Peter Freyther7942abc2010-09-30 00:34:46 +0800248 return CMD_SUCCESS;
249}
250
251DEFUN(cfg_msc_time, cfg_msc_time_cmd,
252 "timeout msc NR",
253 "Set the MSC connect timeout")
254{
Holger Hans Peter Freyther2ff47b82011-02-15 20:25:10 +0100255 bsc->msc_forward.msc_time = atoi(argv[0]);
Holger Hans Peter Freyther7942abc2010-09-30 00:34:46 +0800256 return CMD_SUCCESS;
257}
258
Holger Hans Peter Freytherf603f282011-01-30 00:24:15 +0100259DEFUN(cfg_isup_pass, cfg_isup_pass_cmd,
260 "isup pass-through (0|1)",
261 "ISUP related functionality\n"
262 "Pass through all ISUP messages directly\n"
263 "Handle some messages locally\n" "Pass through everything\n")
264{
Holger Hans Peter Freyther89fa11a2011-02-10 18:26:07 +0100265 struct mtp_link_set *set;
266
Holger Hans Peter Freyther2ff47b82011-02-15 20:25:10 +0100267 bsc->isup_pass = atoi(argv[0]);
Holger Hans Peter Freyther89fa11a2011-02-10 18:26:07 +0100268
Holger Hans Peter Freyther599c9a42011-02-15 11:18:38 +0100269 llist_for_each_entry(set, &bsc->linksets, entry)
Holger Hans Peter Freyther2ff47b82011-02-15 20:25:10 +0100270 set->pass_all_isup = bsc->isup_pass;
Holger Hans Peter Freytherf603f282011-01-30 00:24:15 +0100271
272 return CMD_SUCCESS;
273}
274
Holger Hans Peter Freyther89fa11a2011-02-10 18:26:07 +0100275static void dump_stats(struct vty *vty, struct mtp_link_set *set)
Holger Hans Peter Freyther51b9e7a2011-01-22 16:02:13 +0100276{
277 struct mtp_link *link;
278
Holger Hans Peter Freyther89fa11a2011-02-10 18:26:07 +0100279 vty_out(vty, "Linkset name: %s opc: %d%s", set->name, set->opc, VTY_NEWLINE);
Holger Hans Peter Freyther51b9e7a2011-01-22 16:02:13 +0100280 vty_out_rate_ctr_group(vty, " ", set->ctrg);
281
282 llist_for_each_entry(link, &set->links, entry) {
283 vty_out(vty, " Link %d%s", link->link_no, VTY_NEWLINE);
284 vty_out_rate_ctr_group(vty, " ", link->ctrg);
285 }
286}
287
288DEFUN(show_stats, show_stats_cmd,
289 "show statistics",
290 SHOW_STR "Display Linkset statistics\n")
291{
Holger Hans Peter Freyther89fa11a2011-02-10 18:26:07 +0100292 struct mtp_link_set *set;
293
Holger Hans Peter Freyther599c9a42011-02-15 11:18:38 +0100294 llist_for_each_entry(set, &bsc->linksets, entry)
Holger Hans Peter Freyther89fa11a2011-02-10 18:26:07 +0100295 dump_stats(vty, set);
296
Holger Hans Peter Freyther51b9e7a2011-01-22 16:02:13 +0100297 return CMD_SUCCESS;
298}
299
Holger Hans Peter Freyther89fa11a2011-02-10 18:26:07 +0100300static void dump_state(struct vty *vty, struct mtp_link_set *set)
Holger Hans Peter Freyther60af5dd2011-01-22 16:16:52 +0100301{
302 struct mtp_link *link;
303
304 if (!set) {
Holger Hans Peter Freyther89fa11a2011-02-10 18:26:07 +0100305 vty_out(vty, "LinkSet for %s is not configured.%s", set->name, VTY_NEWLINE);
Holger Hans Peter Freyther60af5dd2011-01-22 16:16:52 +0100306 return;
307 }
308
309 vty_out(vty, "LinkSet for %s is %s, remote sccp is %s.%s",
Holger Hans Peter Freyther89fa11a2011-02-10 18:26:07 +0100310 set->name,
Holger Hans Peter Freyther60af5dd2011-01-22 16:16:52 +0100311 set->available == 0 ? "not available" : "available",
312 set->sccp_up == 0? "not established" : "established",
313 VTY_NEWLINE);
314
315 llist_for_each_entry(link, &set->links, entry) {
Holger Hans Peter Freyther4e2e2422011-01-24 15:40:30 +0100316 if (link->blocked)
317 vty_out(vty, " Link %d is blocked.%s",
318 link->link_no, VTY_NEWLINE);
319 else
320 vty_out(vty, " Link %d is %s.%s",
321 link->link_no,
322 link->available == 0 ? "not available" : "available",
323 VTY_NEWLINE);
Holger Hans Peter Freyther60af5dd2011-01-22 16:16:52 +0100324 }
325}
326
327DEFUN(show_linksets, show_linksets_cmd,
328 "show link-sets",
329 SHOW_STR "Display current state of linksets\n")
330{
Holger Hans Peter Freyther89fa11a2011-02-10 18:26:07 +0100331 struct mtp_link_set *set;
332
Holger Hans Peter Freyther599c9a42011-02-15 11:18:38 +0100333 llist_for_each_entry(set, &bsc->linksets, entry)
Holger Hans Peter Freyther89fa11a2011-02-10 18:26:07 +0100334 dump_state(vty, set);
Holger Hans Peter Freyther60af5dd2011-01-22 16:16:52 +0100335 return CMD_SUCCESS;
336}
337
Holger Hans Peter Freyther0b316222011-01-22 16:43:14 +0100338DEFUN(show_msc, show_msc_cmd,
339 "show msc",
340 SHOW_STR "Display the status of the MSC\n")
341{
342 vty_out(vty, "MSC link is %s and had %s.%s",
Holger Hans Peter Freyther2ff47b82011-02-15 20:25:10 +0100343 bsc->msc_forward.msc_link_down == 0 ? "up" : "down",
344 bsc->msc_forward.first_contact == 1 ? "no contact" : "contact",
Holger Hans Peter Freyther0b316222011-01-22 16:43:14 +0100345 VTY_NEWLINE);
346 return CMD_SUCCESS;
347}
348
Holger Hans Peter Freyther89fa11a2011-02-10 18:26:07 +0100349static struct mtp_link_set *find_link_set(struct llist_head *head,
350 const char *name)
351{
352 struct mtp_link_set *set;
353
354 llist_for_each_entry(set, head, entry)
355 if (strcmp(name, set->name) == 0)
356 return set;
357
358 return NULL;
359}
360
Holger Hans Peter Freyther3c2b84c2011-01-24 21:13:56 +0100361DEFUN(show_slc, show_slc_cmd,
Holger Hans Peter Freyther89fa11a2011-02-10 18:26:07 +0100362 "show link-set NAME slc",
363 SHOW_STR "LinkSet\n" "Linkset name\n" "SLS to SLC\n")
Holger Hans Peter Freyther3c2b84c2011-01-24 21:13:56 +0100364{
365 struct mtp_link_set *set = NULL;
366 int i;
367
Holger Hans Peter Freyther599c9a42011-02-15 11:18:38 +0100368 set = find_link_set(&bsc->linksets, argv[0]);
Holger Hans Peter Freyther3c2b84c2011-01-24 21:13:56 +0100369
370 if (!set) {
371 vty_out(vty, "Failed to find linkset.%s", VTY_NEWLINE);
372 return CMD_WARNING;
373 }
374
375 vty_out(vty, "LinkSet for %s.%s", argv[0], VTY_NEWLINE);
376 for (i = 0; i < ARRAY_SIZE(set->slc); ++i) {
377 if (set->slc[i])
378 vty_out(vty, " SLC[%.2d] is on link %d.%s",
379 i, set->slc[i]->link_no, VTY_NEWLINE);
380 else
381 vty_out(vty, " SLC[%d] is down.%s",
382 i, VTY_NEWLINE);
383 }
384
385 return CMD_SUCCESS;
386}
387
Holger Hans Peter Freyther5b2fe8d2011-01-22 21:09:53 +0100388DEFUN(pcap_set, pcap_set_cmd,
Holger Hans Peter Freyther89fa11a2011-02-10 18:26:07 +0100389 "trace-pcap set NAME FILE",
Holger Hans Peter Freyther5b2fe8d2011-01-22 21:09:53 +0100390 "Trace to a PCAP file\n" "Trace a linkset\n"
Holger Hans Peter Freyther89fa11a2011-02-10 18:26:07 +0100391 "Trace Linkset\n" "Filename to trace\n")
Holger Hans Peter Freyther5b2fe8d2011-01-22 21:09:53 +0100392{
393 struct mtp_link_set *set = NULL;
394
Holger Hans Peter Freyther599c9a42011-02-15 11:18:38 +0100395 set = find_link_set(&bsc->linksets, argv[0]);
Holger Hans Peter Freyther5b2fe8d2011-01-22 21:09:53 +0100396
397 if (!set) {
398 vty_out(vty, "Failed to find linkset.%s", VTY_NEWLINE);
399 return CMD_WARNING;
400 }
401
402
Holger Hans Peter Freyther2ff47b82011-02-15 20:25:10 +0100403 if (set->pcap_fd >= 0 && bsc->pcap_fd != set->pcap_fd)
Holger Hans Peter Freyther5b2fe8d2011-01-22 21:09:53 +0100404 close(set->pcap_fd);
405 set->pcap_fd = open(argv[1], O_WRONLY | O_TRUNC | O_CREAT,
406 S_IRUSR | S_IWUSR | S_IRGRP| S_IROTH);
407 if (set->pcap_fd < 0) {
408 vty_out(vty, "Failed to open file for writing.%s", VTY_NEWLINE);
409 return CMD_WARNING;
410 }
411
412 mtp_pcap_write_header(set->pcap_fd);
413 return CMD_SUCCESS;
414}
415
416DEFUN(pcap_set_stop, pcap_set_stop_cmd,
Holger Hans Peter Freyther89fa11a2011-02-10 18:26:07 +0100417 "trace-pcap set NAME stop",
Holger Hans Peter Freyther5b2fe8d2011-01-22 21:09:53 +0100418 "Trace to a PCAP file\n" "Trace a linkset\n"
Holger Hans Peter Freyther89fa11a2011-02-10 18:26:07 +0100419 "Trace Linkset\n" "Stop the tracing\n")
Holger Hans Peter Freyther5b2fe8d2011-01-22 21:09:53 +0100420{
421 struct mtp_link_set *set = NULL;
422
Holger Hans Peter Freyther599c9a42011-02-15 11:18:38 +0100423 set = find_link_set(&bsc->linksets, argv[0]);
Holger Hans Peter Freyther5b2fe8d2011-01-22 21:09:53 +0100424
425 if (!set) {
426 vty_out(vty, "Failed to find linkset.%s", VTY_NEWLINE);
427 return CMD_WARNING;
428 }
429
Holger Hans Peter Freyther2ff47b82011-02-15 20:25:10 +0100430 if (set->pcap_fd >= 0 && bsc->pcap_fd != set->pcap_fd)
Holger Hans Peter Freyther5b2fe8d2011-01-22 21:09:53 +0100431 close(set->pcap_fd);
432 set->pcap_fd = -1;
433 return CMD_SUCCESS;
434}
435
Holger Hans Peter Freyther315ec672011-01-24 15:35:56 +0100436#define FIND_LINK(vty, type, nr) ({ \
437 struct mtp_link_set *set = NULL; \
438 struct mtp_link *link = NULL, *tmp; \
Holger Hans Peter Freyther599c9a42011-02-15 11:18:38 +0100439 set = find_link_set(&bsc->linksets, type); \
Holger Hans Peter Freyther89fa11a2011-02-10 18:26:07 +0100440 if (!set) { \
Holger Hans Peter Freyther315ec672011-01-24 15:35:56 +0100441 vty_out(vty, "Unknown linkset %s.%s", type, VTY_NEWLINE); \
442 return CMD_WARNING; \
443 } \
444 llist_for_each_entry(tmp, &set->links, entry) { \
445 if (tmp->link_no == nr) { \
446 link = tmp; \
447 break; \
448 } \
449 } \
450 if (!link) { \
451 vty_out(vty, "Can not find link %d.%s", nr, VTY_NEWLINE); \
452 return CMD_WARNING; \
453 } \
454 link; })
455
456#define LINK_STR "Operations on the link\n" \
Holger Hans Peter Freyther89fa11a2011-02-10 18:26:07 +0100457 "Linkset name\n" \
Holger Hans Peter Freyther315ec672011-01-24 15:35:56 +0100458 "Link number\n"
459
460DEFUN(lnk_block, lnk_block_cmd,
Holger Hans Peter Freyther89fa11a2011-02-10 18:26:07 +0100461 "link NAME <0-15> block",
Holger Hans Peter Freyther315ec672011-01-24 15:35:56 +0100462 LINK_STR "Block it\n")
463{
464 struct mtp_link *link = FIND_LINK(vty, argv[0], atoi(argv[1]));
465 mtp_link_block(link);
466 return CMD_SUCCESS;
467}
468
469DEFUN(lnk_unblock, lnk_unblock_cmd,
Holger Hans Peter Freyther89fa11a2011-02-10 18:26:07 +0100470 "link NAME <0-15> unblock",
Holger Hans Peter Freyther315ec672011-01-24 15:35:56 +0100471 LINK_STR "Unblock it\n")
472{
473 struct mtp_link *link = FIND_LINK(vty, argv[0], atoi(argv[1]));
474 mtp_link_unblock(link);
475 return CMD_SUCCESS;
476}
477
478DEFUN(lnk_reset, lnk_reset_cmd,
Holger Hans Peter Freyther89fa11a2011-02-10 18:26:07 +0100479 "link NAME <0-15> reset",
Holger Hans Peter Freyther315ec672011-01-24 15:35:56 +0100480 LINK_STR "Reset it\n")
481{
482 struct mtp_link *link = FIND_LINK(vty, argv[0], atoi(argv[1]));
483 mtp_link_failure(link);
484 return CMD_SUCCESS;
485}
486
Holger Hans Peter Freytheree63d7d2011-02-10 12:39:05 +0100487DEFUN(allow_inject, allow_inject_cmd,
488 "allow-inject (0|1)",
489 "Allow to inject messages\n" "Disable\n" "Enable\n")
490{
Holger Hans Peter Freyther2ff47b82011-02-15 20:25:10 +0100491 bsc->allow_inject = atoi(argv[0]);
Holger Hans Peter Freytheree63d7d2011-02-10 12:39:05 +0100492 return CMD_SUCCESS;
493}
Holger Hans Peter Freyther5b2fe8d2011-01-22 21:09:53 +0100494
Holger Hans Peter Freyther7942abc2010-09-30 00:34:46 +0800495void cell_vty_init(void)
496{
497 cmd_init(1);
498 vty_init(&vty_info);
Holger Hans Peter Freytherfca7b122011-01-22 23:19:44 +0100499 logging_vty_add_cmds();
Holger Hans Peter Freyther7942abc2010-09-30 00:34:46 +0800500
501 install_element(CONFIG_NODE, &cfg_cell_cmd);
502 install_node(&cell_node, config_write_cell);
503
504 install_element(CELLMGR_NODE, &cfg_net_dpc_cmd);
505 install_element(CELLMGR_NODE, &cfg_net_opc_cmd);
Holger Hans Peter Freyther7a725562011-01-01 13:34:58 +0100506 install_element(CELLMGR_NODE, &cfg_net_sccp_opc_cmd);
Holger Hans Peter Freytherb38b33b2010-11-26 21:21:04 +0100507 install_element(CELLMGR_NODE, &cfg_net_mtp_ni_cmd);
508 install_element(CELLMGR_NODE, &cfg_net_mtp_spare_cmd);
Holger Hans Peter Freyther7942abc2010-09-30 00:34:46 +0800509 install_element(CELLMGR_NODE, &cfg_udp_dst_ip_cmd);
510 install_element(CELLMGR_NODE, &cfg_udp_dst_port_cmd);
511 install_element(CELLMGR_NODE, &cfg_udp_src_port_cmd);
512 install_element(CELLMGR_NODE, &cfg_udp_reset_cmd);
Holger Hans Peter Freytherc6bfa272011-01-22 17:06:34 +0100513 install_element(CELLMGR_NODE, &cfg_udp_nr_links_cmd);
Holger Hans Peter Freyther7942abc2010-09-30 00:34:46 +0800514 install_element(CELLMGR_NODE, &cfg_sltm_once_cmd);
515 install_element(CELLMGR_NODE, &cfg_msc_ip_cmd);
516 install_element(CELLMGR_NODE, &cfg_msc_token_cmd);
517 install_element(CELLMGR_NODE, &cfg_msc_ip_dscp_cmd);
518 install_element(CELLMGR_NODE, &cfg_msc_ip_tos_cmd);
519 install_element(CELLMGR_NODE, &cfg_ping_time_cmd);
520 install_element(CELLMGR_NODE, &cfg_pong_time_cmd);
521 install_element(CELLMGR_NODE, &cfg_msc_time_cmd);
Holger Hans Peter Freytherf603f282011-01-30 00:24:15 +0100522 install_element(CELLMGR_NODE, &cfg_isup_pass_cmd);
Holger Hans Peter Freyther51b9e7a2011-01-22 16:02:13 +0100523
Holger Hans Peter Freyther5b2fe8d2011-01-22 21:09:53 +0100524 /* special commands */
525 install_element(ENABLE_NODE, &pcap_set_cmd);
526 install_element(ENABLE_NODE, &pcap_set_stop_cmd);
Holger Hans Peter Freyther315ec672011-01-24 15:35:56 +0100527 install_element(ENABLE_NODE, &lnk_block_cmd);
528 install_element(ENABLE_NODE, &lnk_unblock_cmd);
529 install_element(ENABLE_NODE, &lnk_reset_cmd);
Holger Hans Peter Freytheree63d7d2011-02-10 12:39:05 +0100530 install_element(ENABLE_NODE, &allow_inject_cmd);
Holger Hans Peter Freyther51b9e7a2011-01-22 16:02:13 +0100531
532 /* show commands */
533 install_element_ve(&show_stats_cmd);
Holger Hans Peter Freyther60af5dd2011-01-22 16:16:52 +0100534 install_element_ve(&show_linksets_cmd);
Holger Hans Peter Freyther3c2b84c2011-01-24 21:13:56 +0100535 install_element_ve(&show_slc_cmd);
Holger Hans Peter Freyther0b316222011-01-22 16:43:14 +0100536
Holger Hans Peter Freyther2ff47b82011-02-15 20:25:10 +0100537 if (bsc->app != APP_STP) {
Holger Hans Peter Freyther0b316222011-01-22 16:43:14 +0100538 install_element_ve(&show_msc_cmd);
539 }
Holger Hans Peter Freyther7942abc2010-09-30 00:34:46 +0800540}
541
542const char *openbsc_copyright = "";