blob: 6f8ca056d1e6b2c52c4198723f86dc02372300d8 [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,
106 "show msc",
107 SHOW_STR "Display the status of the MSC\n")
108{
Holger Hans Peter Freytherc5e8f082011-11-25 17:26:44 +0100109 struct msc_connection *msc = msc_connection_num(bsc, 0);
Holger Hans Peter Freyther29176442011-02-22 16:00:36 +0100110
Holger Hans Peter Freytherc5e8f082011-11-25 17:26:44 +0100111 if (!msc) {
112 vty_out(vty, "%%No MSC Connection defined in this app.%s", VTY_NEWLINE);
113 return CMD_WARNING;
Holger Hans Peter Freyther29176442011-02-22 16:00:36 +0100114 }
115
Holger Hans Peter Freytherc5e8f082011-11-25 17:26:44 +0100116
117 vty_out(vty, "MSC link is %s and had %s.%s",
118 msc->msc_link_down == 0 ? "up" : "down",
119 msc->first_contact == 1 ? "no contact" : "contact",
120 VTY_NEWLINE);
121
Holger Hans Peter Freyther29176442011-02-22 16:00:36 +0100122 return CMD_SUCCESS;
123}
124
Holger Hans Peter Freyther31d65972011-11-25 16:23:43 +0100125DEFUN(show_mscs, show_mscs_cmd,
126 "show mscs",
127 SHOW_STR "Display the status of all MSCs\n")
128{
129 struct msc_connection *msc;
130
131 llist_for_each_entry(msc, &bsc->mscs, entry) {
132 vty_out(vty, "MSC link nr %d name '%s' is %s and had %s.%s",
133 msc->nr, msc->name,
134 msc->msc_link_down == 0 ? "up" : "down",
135 msc->first_contact == 1 ? "no contact" : "contact",
136 VTY_NEWLINE);
137 }
138
139 return CMD_SUCCESS;
140}
141
142
Holger Hans Peter Freyther29176442011-02-22 16:00:36 +0100143DEFUN(show_slc, show_slc_cmd,
144 "show link-set <0-100> slc",
145 SHOW_STR "LinkSet\n" "Linkset nr\n" "SLS to SLC\n")
146{
147 struct mtp_link_set *set = NULL;
148 int i;
149
150 set = mtp_link_set_num(bsc, atoi(argv[0]));
151
152 if (!set) {
153 vty_out(vty, "Failed to find linkset.%s", VTY_NEWLINE);
154 return CMD_WARNING;
155 }
156
157 vty_out(vty, "LinkSet for %s.%s", argv[0], VTY_NEWLINE);
158 for (i = 0; i < ARRAY_SIZE(set->slc); ++i) {
159 if (set->slc[i])
160 vty_out(vty, " SLC[%.2d] is on link %d.%s",
161 i, set->slc[i]->nr, VTY_NEWLINE);
162 else
163 vty_out(vty, " SLC[%d] is down.%s",
164 i, VTY_NEWLINE);
165 }
166
167 return CMD_SUCCESS;
168}
169
170DEFUN(pcap_set, pcap_set_cmd,
171 "trace-pcap <0-100> NAME FILE",
172 "Trace to a PCAP file\n" "Linkset nr.\n"
173 "Trace Linkset\n" "Filename to trace\n")
174{
175 struct mtp_link_set *set = NULL;
176
177 set = mtp_link_set_num(bsc, atoi(argv[0]));
178
179 if (!set) {
180 vty_out(vty, "Failed to find linkset.%s", VTY_NEWLINE);
181 return CMD_WARNING;
182 }
183
184
185 if (set->pcap_fd >= 0 && bsc->pcap_fd != set->pcap_fd)
186 close(set->pcap_fd);
187 set->pcap_fd = open(argv[1], O_WRONLY | O_TRUNC | O_CREAT,
188 S_IRUSR | S_IWUSR | S_IRGRP| S_IROTH);
189 if (set->pcap_fd < 0) {
190 vty_out(vty, "Failed to open file for writing.%s", VTY_NEWLINE);
191 return CMD_WARNING;
192 }
193
194 mtp_pcap_write_header(set->pcap_fd);
195 return CMD_SUCCESS;
196}
197
198DEFUN(pcap_set_stop, pcap_set_stop_cmd,
199 "trace-pcap <0-100> NAME stop",
200 "Trace to a PCAP file\n" "Linkset nr\n"
201 "Trace Linkset\n" "Stop the tracing\n")
202{
203 struct mtp_link_set *set = NULL;
204
205 set = mtp_link_set_num(bsc, atoi(argv[0]));
206
207 if (!set) {
208 vty_out(vty, "Failed to find linkset.%s", VTY_NEWLINE);
209 return CMD_WARNING;
210 }
211
212 if (set->pcap_fd >= 0 && bsc->pcap_fd != set->pcap_fd)
213 close(set->pcap_fd);
214 set->pcap_fd = -1;
215 return CMD_SUCCESS;
216}
217
218#define FIND_LINK(vty, set_no, nr) ({ \
219 struct mtp_link_set *set = NULL; \
220 struct mtp_link *link = NULL; \
221 set = mtp_link_set_num(bsc, set_no); \
222 if (!set) { \
223 vty_out(vty, "Unknown Linkset nr %d.%s", set_no, VTY_NEWLINE); \
224 return CMD_WARNING; \
225 } \
Holger Hans Peter Freyther71760302011-02-22 20:57:08 +0100226 if (!set->app) { \
227 vty_out(vty, "Linkset nr %d has no application.%s", \
228 set_no, VTY_NEWLINE); \
229 } \
Holger Hans Peter Freyther29176442011-02-22 16:00:36 +0100230 link = mtp_link_num(set, nr); \
231 if (!link) { \
232 vty_out(vty, "Can not find link %d.%s", nr, VTY_NEWLINE); \
233 return CMD_WARNING; \
234 } \
235 link; })
236
237#define LINK_STR "Operations on the link\n" \
238 "Linkset number\n" \
239 "Link number\n"
240
241DEFUN(lnk_block, lnk_block_cmd,
242 "link <0-100> <0-15> block",
243 LINK_STR "Block it\n")
244{
245 struct mtp_link *link = FIND_LINK(vty, atoi(argv[0]), atoi(argv[1]));
246 mtp_link_block(link);
247 return CMD_SUCCESS;
248}
249
250DEFUN(lnk_unblock, lnk_unblock_cmd,
251 "link <0-100> <0-15> unblock",
252 LINK_STR "Unblock it\n")
253{
254 struct mtp_link *link = FIND_LINK(vty, atoi(argv[0]), atoi(argv[1]));
255 mtp_link_unblock(link);
256 return CMD_SUCCESS;
257}
258
259DEFUN(lnk_reset, lnk_reset_cmd,
260 "link <0-100> <0-15> reset",
261 LINK_STR "Reset it\n")
262{
263 struct mtp_link *link = FIND_LINK(vty, atoi(argv[0]), atoi(argv[1]));
264 mtp_link_failure(link);
265 return CMD_SUCCESS;
266}
267
268DEFUN(allow_inject, allow_inject_cmd,
269 "allow-inject (0|1)",
270 "Allow to inject messages\n" "Disable\n" "Enable\n")
271{
272 bsc->allow_inject = atoi(argv[0]);
273 return CMD_SUCCESS;
274}
275
Holger Hans Peter Freythercf60a012011-08-10 06:26:44 +0200276DEFUN(show_sctp_count, show_sctp_count_cmd,
277 "show sctp-connections count",
278 SHOW_STR "Number of SCTP connections\n")
Holger Hans Peter Freytherab79b9b2011-08-10 06:11:39 +0200279{
280 int count = sctp_m2ua_conn_count(bsc->m2ua_trans);
281 vty_out(vty, "Active SCTP connections are: %d.%s", count, VTY_NEWLINE);
282 return CMD_SUCCESS;
283}
284
Holger Hans Peter Freythercf60a012011-08-10 06:26:44 +0200285DEFUN(show_sctp_details, show_sctp_details_cmd,
286 "show sctp-connections details",
287 SHOW_STR "Details of SCTP connections\n")
288{
289 struct sctp_m2ua_conn *conn;
290
291 llist_for_each_entry(conn, &bsc->m2ua_trans->conns, entry) {
292 vty_out(vty,
293 "SCTP Conn ASP UP: %d, ident: %d,%d,%d,%d fd: %d ptr: %p.%s",
294 conn->asp_up, conn->asp_ident[0], conn->asp_ident[1],
295 conn->asp_ident[2], conn->asp_ident[3],
296 conn->queue.bfd.fd, conn, VTY_NEWLINE);
297 }
298
299 return CMD_WARNING;
300}
301
Holger Hans Peter Freyther29176442011-02-22 16:00:36 +0100302void cell_vty_init_cmds(void)
303{
304 /* special commands */
305 install_element(ENABLE_NODE, &pcap_set_cmd);
306 install_element(ENABLE_NODE, &pcap_set_stop_cmd);
307 install_element(ENABLE_NODE, &lnk_block_cmd);
308 install_element(ENABLE_NODE, &lnk_unblock_cmd);
309 install_element(ENABLE_NODE, &lnk_reset_cmd);
310 install_element(ENABLE_NODE, &allow_inject_cmd);
311
312 /* show commands */
313 install_element_ve(&show_stats_cmd);
314 install_element_ve(&show_linksets_cmd);
315 install_element_ve(&show_slc_cmd);
316
317 install_element_ve(&show_msc_cmd);
Holger Hans Peter Freyther31d65972011-11-25 16:23:43 +0100318 install_element_ve(&show_mscs_cmd);
Holger Hans Peter Freythercf60a012011-08-10 06:26:44 +0200319 install_element_ve(&show_sctp_count_cmd);
320 install_element_ve(&show_sctp_details_cmd);
Holger Hans Peter Freyther29176442011-02-22 16:00:36 +0100321}