blob: 7c634c0ac2673cf6aa614064901b86eeea6bbbeb [file] [log] [blame]
Holger Hans Peter Freyther29176442011-02-22 16:00:36 +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>
Holger Hans Peter Freytherab79b9b2011-08-10 06:11:39 +020025#include <sctp_m2ua.h>
Holger Hans Peter Freyther29176442011-02-22 16:00:36 +010026
Harald Welteff397ed2011-05-08 10:29:23 +020027#include <osmocom/core/rate_ctr.h>
Holger Hans Peter Freyther29176442011-02-22 16:00:36 +010028
29#include <osmocom/vty/command.h>
30#include <osmocom/vty/logging.h>
31#include <osmocom/vty/vty.h>
Harald Welteff397ed2011-05-08 10:29:23 +020032#include <osmocom/vty/misc.h>
Holger Hans Peter Freyther29176442011-02-22 16:00:36 +010033
34#include <sys/types.h>
35#include <sys/stat.h>
36#include <fcntl.h>
37#include <unistd.h>
38
39extern struct bsc_data *bsc;
40
41static void dump_stats(struct vty *vty, struct mtp_link_set *set)
42{
43 struct mtp_link *link;
44
45 vty_out(vty, "Linkset name: %s opc: %d%s", set->name, set->opc, VTY_NEWLINE);
46 vty_out_rate_ctr_group(vty, " ", set->ctrg);
47
48 llist_for_each_entry(link, &set->links, entry) {
49 vty_out(vty, " Link %d%s", link->nr, VTY_NEWLINE);
50 vty_out_rate_ctr_group(vty, " ", link->ctrg);
51 }
52}
53
54DEFUN(show_stats, show_stats_cmd,
55 "show statistics",
56 SHOW_STR "Display Linkset statistics\n")
57{
58 struct mtp_link_set *set;
59
60 llist_for_each_entry(set, &bsc->linksets, entry)
61 dump_stats(vty, set);
62
63 return CMD_SUCCESS;
64}
65
66static void dump_state(struct vty *vty, struct mtp_link_set *set)
67{
68 struct mtp_link *link;
69
Holger Hans Peter Freyther71760302011-02-22 20:57:08 +010070 if (!set->app) {
71 vty_out(vty, "LinkSet %d not assigned to an application.%s",
72 set->nr, VTY_NEWLINE);
Holger Hans Peter Freyther29176442011-02-22 16:00:36 +010073 return;
74 }
75
Holger Hans Peter Freyther71760302011-02-22 20:57:08 +010076 vty_out(vty, "LinkSet for %d/%s is %s, remote sccp is %s.%s",
77 set->nr, set->name,
Holger Hans Peter Freyther29176442011-02-22 16:00:36 +010078 set->available == 0 ? "not available" : "available",
79 set->sccp_up == 0? "not established" : "established",
80 VTY_NEWLINE);
81
82 llist_for_each_entry(link, &set->links, entry) {
83 if (link->blocked)
84 vty_out(vty, " Link %d is blocked.%s",
85 link->nr, VTY_NEWLINE);
86 else
87 vty_out(vty, " Link %d is %s.%s",
88 link->nr,
89 link->available == 0 ? "not available" : "available",
90 VTY_NEWLINE);
91 }
92}
93
94DEFUN(show_linksets, show_linksets_cmd,
95 "show link-sets",
96 SHOW_STR "Display current state of linksets\n")
97{
98 struct mtp_link_set *set;
99
100 llist_for_each_entry(set, &bsc->linksets, entry)
101 dump_state(vty, set);
102 return CMD_SUCCESS;
103}
104
105DEFUN(show_msc, show_msc_cmd,
Holger Hans Peter Freytherd87ef3b2011-11-28 10:16:38 +0100106 "show msc [NR]",
107 SHOW_STR "Display the status of the MSC\n" "Number of the MSC\n")
Holger Hans Peter Freyther29176442011-02-22 16:00:36 +0100108{
Holger Hans Peter Freytherd87ef3b2011-11-28 10:16:38 +0100109 struct msc_connection *msc;
110
111 if (argc == 1)
112 msc = msc_connection_num(bsc, atoi(argv[0]));
113 else
114 msc = msc_connection_num(bsc, 0);
Holger Hans Peter Freyther29176442011-02-22 16:00:36 +0100115
Holger Hans Peter Freytherc5e8f082011-11-25 17:26:44 +0100116 if (!msc) {
117 vty_out(vty, "%%No MSC Connection defined in this app.%s", VTY_NEWLINE);
118 return CMD_WARNING;
Holger Hans Peter Freyther29176442011-02-22 16:00:36 +0100119 }
120
Holger Hans Peter Freytherc5e8f082011-11-25 17:26:44 +0100121
122 vty_out(vty, "MSC link is %s and had %s.%s",
123 msc->msc_link_down == 0 ? "up" : "down",
124 msc->first_contact == 1 ? "no contact" : "contact",
125 VTY_NEWLINE);
126
Holger Hans Peter Freyther29176442011-02-22 16:00:36 +0100127 return CMD_SUCCESS;
128}
129
Holger Hans Peter Freyther31d65972011-11-25 16:23:43 +0100130DEFUN(show_mscs, show_mscs_cmd,
131 "show mscs",
132 SHOW_STR "Display the status of all MSCs\n")
133{
134 struct msc_connection *msc;
135
136 llist_for_each_entry(msc, &bsc->mscs, entry) {
137 vty_out(vty, "MSC link nr %d name '%s' is %s and had %s.%s",
138 msc->nr, msc->name,
139 msc->msc_link_down == 0 ? "up" : "down",
140 msc->first_contact == 1 ? "no contact" : "contact",
141 VTY_NEWLINE);
142 }
143
144 return CMD_SUCCESS;
145}
146
147
Holger Hans Peter Freyther29176442011-02-22 16:00:36 +0100148DEFUN(show_slc, show_slc_cmd,
149 "show link-set <0-100> slc",
150 SHOW_STR "LinkSet\n" "Linkset nr\n" "SLS to SLC\n")
151{
152 struct mtp_link_set *set = NULL;
153 int i;
154
155 set = mtp_link_set_num(bsc, atoi(argv[0]));
156
157 if (!set) {
158 vty_out(vty, "Failed to find linkset.%s", VTY_NEWLINE);
159 return CMD_WARNING;
160 }
161
162 vty_out(vty, "LinkSet for %s.%s", argv[0], VTY_NEWLINE);
163 for (i = 0; i < ARRAY_SIZE(set->slc); ++i) {
164 if (set->slc[i])
165 vty_out(vty, " SLC[%.2d] is on link %d.%s",
166 i, set->slc[i]->nr, VTY_NEWLINE);
167 else
168 vty_out(vty, " SLC[%d] is down.%s",
169 i, VTY_NEWLINE);
170 }
171
172 return CMD_SUCCESS;
173}
174
175DEFUN(pcap_set, pcap_set_cmd,
176 "trace-pcap <0-100> NAME FILE",
177 "Trace to a PCAP file\n" "Linkset nr.\n"
178 "Trace Linkset\n" "Filename to trace\n")
179{
180 struct mtp_link_set *set = NULL;
181
182 set = mtp_link_set_num(bsc, atoi(argv[0]));
183
184 if (!set) {
185 vty_out(vty, "Failed to find linkset.%s", VTY_NEWLINE);
186 return CMD_WARNING;
187 }
188
189
190 if (set->pcap_fd >= 0 && bsc->pcap_fd != set->pcap_fd)
191 close(set->pcap_fd);
192 set->pcap_fd = open(argv[1], O_WRONLY | O_TRUNC | O_CREAT,
193 S_IRUSR | S_IWUSR | S_IRGRP| S_IROTH);
194 if (set->pcap_fd < 0) {
195 vty_out(vty, "Failed to open file for writing.%s", VTY_NEWLINE);
196 return CMD_WARNING;
197 }
198
199 mtp_pcap_write_header(set->pcap_fd);
200 return CMD_SUCCESS;
201}
202
203DEFUN(pcap_set_stop, pcap_set_stop_cmd,
204 "trace-pcap <0-100> NAME stop",
205 "Trace to a PCAP file\n" "Linkset nr\n"
206 "Trace Linkset\n" "Stop the tracing\n")
207{
208 struct mtp_link_set *set = NULL;
209
210 set = mtp_link_set_num(bsc, atoi(argv[0]));
211
212 if (!set) {
213 vty_out(vty, "Failed to find linkset.%s", VTY_NEWLINE);
214 return CMD_WARNING;
215 }
216
217 if (set->pcap_fd >= 0 && bsc->pcap_fd != set->pcap_fd)
218 close(set->pcap_fd);
219 set->pcap_fd = -1;
220 return CMD_SUCCESS;
221}
222
223#define FIND_LINK(vty, set_no, nr) ({ \
224 struct mtp_link_set *set = NULL; \
225 struct mtp_link *link = NULL; \
226 set = mtp_link_set_num(bsc, set_no); \
227 if (!set) { \
228 vty_out(vty, "Unknown Linkset nr %d.%s", set_no, VTY_NEWLINE); \
229 return CMD_WARNING; \
230 } \
Holger Hans Peter Freyther71760302011-02-22 20:57:08 +0100231 if (!set->app) { \
232 vty_out(vty, "Linkset nr %d has no application.%s", \
233 set_no, VTY_NEWLINE); \
234 } \
Holger Hans Peter Freyther29176442011-02-22 16:00:36 +0100235 link = mtp_link_num(set, nr); \
236 if (!link) { \
237 vty_out(vty, "Can not find link %d.%s", nr, VTY_NEWLINE); \
238 return CMD_WARNING; \
239 } \
240 link; })
241
242#define LINK_STR "Operations on the link\n" \
243 "Linkset number\n" \
244 "Link number\n"
245
246DEFUN(lnk_block, lnk_block_cmd,
247 "link <0-100> <0-15> block",
248 LINK_STR "Block it\n")
249{
250 struct mtp_link *link = FIND_LINK(vty, atoi(argv[0]), atoi(argv[1]));
251 mtp_link_block(link);
252 return CMD_SUCCESS;
253}
254
255DEFUN(lnk_unblock, lnk_unblock_cmd,
256 "link <0-100> <0-15> unblock",
257 LINK_STR "Unblock it\n")
258{
259 struct mtp_link *link = FIND_LINK(vty, atoi(argv[0]), atoi(argv[1]));
260 mtp_link_unblock(link);
261 return CMD_SUCCESS;
262}
263
264DEFUN(lnk_reset, lnk_reset_cmd,
265 "link <0-100> <0-15> reset",
266 LINK_STR "Reset it\n")
267{
268 struct mtp_link *link = FIND_LINK(vty, atoi(argv[0]), atoi(argv[1]));
269 mtp_link_failure(link);
270 return CMD_SUCCESS;
271}
272
273DEFUN(allow_inject, allow_inject_cmd,
274 "allow-inject (0|1)",
275 "Allow to inject messages\n" "Disable\n" "Enable\n")
276{
277 bsc->allow_inject = atoi(argv[0]);
278 return CMD_SUCCESS;
279}
280
Holger Hans Peter Freythercf60a012011-08-10 06:26:44 +0200281DEFUN(show_sctp_count, show_sctp_count_cmd,
282 "show sctp-connections count",
Holger Hans Peter Freyther368e5492016-08-15 11:54:24 +0200283 SHOW_STR "SCTP connections\n" "Number of connections\n")
Holger Hans Peter Freytherab79b9b2011-08-10 06:11:39 +0200284{
285 int count = sctp_m2ua_conn_count(bsc->m2ua_trans);
286 vty_out(vty, "Active SCTP connections are: %d.%s", count, VTY_NEWLINE);
287 return CMD_SUCCESS;
288}
289
Holger Hans Peter Freythercf60a012011-08-10 06:26:44 +0200290DEFUN(show_sctp_details, show_sctp_details_cmd,
291 "show sctp-connections details",
Holger Hans Peter Freyther368e5492016-08-15 11:54:24 +0200292 SHOW_STR "SCTP connections\n" "Details\n")
Holger Hans Peter Freythercf60a012011-08-10 06:26:44 +0200293{
294 struct sctp_m2ua_conn *conn;
295
296 llist_for_each_entry(conn, &bsc->m2ua_trans->conns, entry) {
297 vty_out(vty,
298 "SCTP Conn ASP UP: %d, ident: %d,%d,%d,%d fd: %d ptr: %p.%s",
299 conn->asp_up, conn->asp_ident[0], conn->asp_ident[1],
300 conn->asp_ident[2], conn->asp_ident[3],
301 conn->queue.bfd.fd, conn, VTY_NEWLINE);
302 }
303
304 return CMD_WARNING;
305}
306
Holger Hans Peter Freyther29176442011-02-22 16:00:36 +0100307void cell_vty_init_cmds(void)
308{
309 /* special commands */
310 install_element(ENABLE_NODE, &pcap_set_cmd);
311 install_element(ENABLE_NODE, &pcap_set_stop_cmd);
312 install_element(ENABLE_NODE, &lnk_block_cmd);
313 install_element(ENABLE_NODE, &lnk_unblock_cmd);
314 install_element(ENABLE_NODE, &lnk_reset_cmd);
315 install_element(ENABLE_NODE, &allow_inject_cmd);
316
317 /* show commands */
318 install_element_ve(&show_stats_cmd);
319 install_element_ve(&show_linksets_cmd);
320 install_element_ve(&show_slc_cmd);
321
322 install_element_ve(&show_msc_cmd);
Holger Hans Peter Freyther31d65972011-11-25 16:23:43 +0100323 install_element_ve(&show_mscs_cmd);
Holger Hans Peter Freythercf60a012011-08-10 06:26:44 +0200324 install_element_ve(&show_sctp_count_cmd);
325 install_element_ve(&show_sctp_details_cmd);
Holger Hans Peter Freyther29176442011-02-22 16:00:36 +0100326}