blob: 988444b5243a7fa208479428b62f614e9444d02d [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>
25
26#include <osmocore/rate_ctr.h>
27
28#include <osmocom/vty/command.h>
29#include <osmocom/vty/logging.h>
30#include <osmocom/vty/vty.h>
31
32#include <sys/types.h>
33#include <sys/stat.h>
34#include <fcntl.h>
35#include <unistd.h>
36
37extern struct bsc_data *bsc;
38
39static void dump_stats(struct vty *vty, struct mtp_link_set *set)
40{
41 struct mtp_link *link;
42
43 vty_out(vty, "Linkset name: %s opc: %d%s", set->name, set->opc, VTY_NEWLINE);
44 vty_out_rate_ctr_group(vty, " ", set->ctrg);
45
46 llist_for_each_entry(link, &set->links, entry) {
47 vty_out(vty, " Link %d%s", link->nr, VTY_NEWLINE);
48 vty_out_rate_ctr_group(vty, " ", link->ctrg);
49 }
50}
51
52DEFUN(show_stats, show_stats_cmd,
53 "show statistics",
54 SHOW_STR "Display Linkset statistics\n")
55{
56 struct mtp_link_set *set;
57
58 llist_for_each_entry(set, &bsc->linksets, entry)
59 dump_stats(vty, set);
60
61 return CMD_SUCCESS;
62}
63
64static void dump_state(struct vty *vty, struct mtp_link_set *set)
65{
66 struct mtp_link *link;
67
Holger Hans Peter Freyther71760302011-02-22 20:57:08 +010068 if (!set->app) {
69 vty_out(vty, "LinkSet %d not assigned to an application.%s",
70 set->nr, VTY_NEWLINE);
Holger Hans Peter Freyther29176442011-02-22 16:00:36 +010071 return;
72 }
73
Holger Hans Peter Freyther71760302011-02-22 20:57:08 +010074 vty_out(vty, "LinkSet for %d/%s is %s, remote sccp is %s.%s",
75 set->nr, set->name,
Holger Hans Peter Freyther29176442011-02-22 16:00:36 +010076 set->available == 0 ? "not available" : "available",
77 set->sccp_up == 0? "not established" : "established",
78 VTY_NEWLINE);
79
80 llist_for_each_entry(link, &set->links, entry) {
81 if (link->blocked)
82 vty_out(vty, " Link %d is blocked.%s",
83 link->nr, VTY_NEWLINE);
84 else
85 vty_out(vty, " Link %d is %s.%s",
86 link->nr,
87 link->available == 0 ? "not available" : "available",
88 VTY_NEWLINE);
89 }
90}
91
92DEFUN(show_linksets, show_linksets_cmd,
93 "show link-sets",
94 SHOW_STR "Display current state of linksets\n")
95{
96 struct mtp_link_set *set;
97
98 llist_for_each_entry(set, &bsc->linksets, entry)
99 dump_state(vty, set);
100 return CMD_SUCCESS;
101}
102
103DEFUN(show_msc, show_msc_cmd,
104 "show msc",
105 SHOW_STR "Display the status of the MSC\n")
106{
107 struct msc_connection *msc = msc_connection_num(bsc, 0);
108
109 if (!msc) {
110 vty_out(vty, "%%No MSC Connection defined in this app.%s", VTY_NEWLINE);
111 return CMD_WARNING;
112 }
113
114 vty_out(vty, "MSC link is %s and had %s.%s",
115 msc->msc_link_down == 0 ? "up" : "down",
116 msc->first_contact == 1 ? "no contact" : "contact",
117 VTY_NEWLINE);
118 return CMD_SUCCESS;
119}
120
121DEFUN(show_slc, show_slc_cmd,
122 "show link-set <0-100> slc",
123 SHOW_STR "LinkSet\n" "Linkset nr\n" "SLS to SLC\n")
124{
125 struct mtp_link_set *set = NULL;
126 int i;
127
128 set = mtp_link_set_num(bsc, atoi(argv[0]));
129
130 if (!set) {
131 vty_out(vty, "Failed to find linkset.%s", VTY_NEWLINE);
132 return CMD_WARNING;
133 }
134
135 vty_out(vty, "LinkSet for %s.%s", argv[0], VTY_NEWLINE);
136 for (i = 0; i < ARRAY_SIZE(set->slc); ++i) {
137 if (set->slc[i])
138 vty_out(vty, " SLC[%.2d] is on link %d.%s",
139 i, set->slc[i]->nr, VTY_NEWLINE);
140 else
141 vty_out(vty, " SLC[%d] is down.%s",
142 i, VTY_NEWLINE);
143 }
144
145 return CMD_SUCCESS;
146}
147
148DEFUN(pcap_set, pcap_set_cmd,
149 "trace-pcap <0-100> NAME FILE",
150 "Trace to a PCAP file\n" "Linkset nr.\n"
151 "Trace Linkset\n" "Filename to trace\n")
152{
153 struct mtp_link_set *set = NULL;
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
163 if (set->pcap_fd >= 0 && bsc->pcap_fd != set->pcap_fd)
164 close(set->pcap_fd);
165 set->pcap_fd = open(argv[1], O_WRONLY | O_TRUNC | O_CREAT,
166 S_IRUSR | S_IWUSR | S_IRGRP| S_IROTH);
167 if (set->pcap_fd < 0) {
168 vty_out(vty, "Failed to open file for writing.%s", VTY_NEWLINE);
169 return CMD_WARNING;
170 }
171
172 mtp_pcap_write_header(set->pcap_fd);
173 return CMD_SUCCESS;
174}
175
176DEFUN(pcap_set_stop, pcap_set_stop_cmd,
177 "trace-pcap <0-100> NAME stop",
178 "Trace to a PCAP file\n" "Linkset nr\n"
179 "Trace Linkset\n" "Stop the tracing\n")
180{
181 struct mtp_link_set *set = NULL;
182
183 set = mtp_link_set_num(bsc, atoi(argv[0]));
184
185 if (!set) {
186 vty_out(vty, "Failed to find linkset.%s", VTY_NEWLINE);
187 return CMD_WARNING;
188 }
189
190 if (set->pcap_fd >= 0 && bsc->pcap_fd != set->pcap_fd)
191 close(set->pcap_fd);
192 set->pcap_fd = -1;
193 return CMD_SUCCESS;
194}
195
196#define FIND_LINK(vty, set_no, nr) ({ \
197 struct mtp_link_set *set = NULL; \
198 struct mtp_link *link = NULL; \
199 set = mtp_link_set_num(bsc, set_no); \
200 if (!set) { \
201 vty_out(vty, "Unknown Linkset nr %d.%s", set_no, VTY_NEWLINE); \
202 return CMD_WARNING; \
203 } \
Holger Hans Peter Freyther71760302011-02-22 20:57:08 +0100204 if (!set->app) { \
205 vty_out(vty, "Linkset nr %d has no application.%s", \
206 set_no, VTY_NEWLINE); \
207 } \
Holger Hans Peter Freyther29176442011-02-22 16:00:36 +0100208 link = mtp_link_num(set, nr); \
209 if (!link) { \
210 vty_out(vty, "Can not find link %d.%s", nr, VTY_NEWLINE); \
211 return CMD_WARNING; \
212 } \
213 link; })
214
215#define LINK_STR "Operations on the link\n" \
216 "Linkset number\n" \
217 "Link number\n"
218
219DEFUN(lnk_block, lnk_block_cmd,
220 "link <0-100> <0-15> block",
221 LINK_STR "Block it\n")
222{
223 struct mtp_link *link = FIND_LINK(vty, atoi(argv[0]), atoi(argv[1]));
224 mtp_link_block(link);
225 return CMD_SUCCESS;
226}
227
228DEFUN(lnk_unblock, lnk_unblock_cmd,
229 "link <0-100> <0-15> unblock",
230 LINK_STR "Unblock it\n")
231{
232 struct mtp_link *link = FIND_LINK(vty, atoi(argv[0]), atoi(argv[1]));
233 mtp_link_unblock(link);
234 return CMD_SUCCESS;
235}
236
237DEFUN(lnk_reset, lnk_reset_cmd,
238 "link <0-100> <0-15> reset",
239 LINK_STR "Reset it\n")
240{
241 struct mtp_link *link = FIND_LINK(vty, atoi(argv[0]), atoi(argv[1]));
242 mtp_link_failure(link);
243 return CMD_SUCCESS;
244}
245
246DEFUN(allow_inject, allow_inject_cmd,
247 "allow-inject (0|1)",
248 "Allow to inject messages\n" "Disable\n" "Enable\n")
249{
250 bsc->allow_inject = atoi(argv[0]);
251 return CMD_SUCCESS;
252}
253
254void cell_vty_init_cmds(void)
255{
256 /* special commands */
257 install_element(ENABLE_NODE, &pcap_set_cmd);
258 install_element(ENABLE_NODE, &pcap_set_stop_cmd);
259 install_element(ENABLE_NODE, &lnk_block_cmd);
260 install_element(ENABLE_NODE, &lnk_unblock_cmd);
261 install_element(ENABLE_NODE, &lnk_reset_cmd);
262 install_element(ENABLE_NODE, &allow_inject_cmd);
263
264 /* show commands */
265 install_element_ve(&show_stats_cmd);
266 install_element_ve(&show_linksets_cmd);
267 install_element_ve(&show_slc_cmd);
268
269 install_element_ve(&show_msc_cmd);
270}