blob: e3c82cb1d3e59ca4b400e3f350535c85a7f309b6 [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
68 if (!set) {
69 vty_out(vty, "LinkSet for %s is not configured.%s", set->name, VTY_NEWLINE);
70 return;
71 }
72
73 vty_out(vty, "LinkSet for %s is %s, remote sccp is %s.%s",
74 set->name,
75 set->available == 0 ? "not available" : "available",
76 set->sccp_up == 0? "not established" : "established",
77 VTY_NEWLINE);
78
79 llist_for_each_entry(link, &set->links, entry) {
80 if (link->blocked)
81 vty_out(vty, " Link %d is blocked.%s",
82 link->nr, VTY_NEWLINE);
83 else
84 vty_out(vty, " Link %d is %s.%s",
85 link->nr,
86 link->available == 0 ? "not available" : "available",
87 VTY_NEWLINE);
88 }
89}
90
91DEFUN(show_linksets, show_linksets_cmd,
92 "show link-sets",
93 SHOW_STR "Display current state of linksets\n")
94{
95 struct mtp_link_set *set;
96
97 llist_for_each_entry(set, &bsc->linksets, entry)
98 dump_state(vty, set);
99 return CMD_SUCCESS;
100}
101
102DEFUN(show_msc, show_msc_cmd,
103 "show msc",
104 SHOW_STR "Display the status of the MSC\n")
105{
106 struct msc_connection *msc = msc_connection_num(bsc, 0);
107
108 if (!msc) {
109 vty_out(vty, "%%No MSC Connection defined in this app.%s", VTY_NEWLINE);
110 return CMD_WARNING;
111 }
112
113 vty_out(vty, "MSC link is %s and had %s.%s",
114 msc->msc_link_down == 0 ? "up" : "down",
115 msc->first_contact == 1 ? "no contact" : "contact",
116 VTY_NEWLINE);
117 return CMD_SUCCESS;
118}
119
120DEFUN(show_slc, show_slc_cmd,
121 "show link-set <0-100> slc",
122 SHOW_STR "LinkSet\n" "Linkset nr\n" "SLS to SLC\n")
123{
124 struct mtp_link_set *set = NULL;
125 int i;
126
127 set = mtp_link_set_num(bsc, atoi(argv[0]));
128
129 if (!set) {
130 vty_out(vty, "Failed to find linkset.%s", VTY_NEWLINE);
131 return CMD_WARNING;
132 }
133
134 vty_out(vty, "LinkSet for %s.%s", argv[0], VTY_NEWLINE);
135 for (i = 0; i < ARRAY_SIZE(set->slc); ++i) {
136 if (set->slc[i])
137 vty_out(vty, " SLC[%.2d] is on link %d.%s",
138 i, set->slc[i]->nr, VTY_NEWLINE);
139 else
140 vty_out(vty, " SLC[%d] is down.%s",
141 i, VTY_NEWLINE);
142 }
143
144 return CMD_SUCCESS;
145}
146
147DEFUN(pcap_set, pcap_set_cmd,
148 "trace-pcap <0-100> NAME FILE",
149 "Trace to a PCAP file\n" "Linkset nr.\n"
150 "Trace Linkset\n" "Filename to trace\n")
151{
152 struct mtp_link_set *set = NULL;
153
154 set = mtp_link_set_num(bsc, atoi(argv[0]));
155
156 if (!set) {
157 vty_out(vty, "Failed to find linkset.%s", VTY_NEWLINE);
158 return CMD_WARNING;
159 }
160
161
162 if (set->pcap_fd >= 0 && bsc->pcap_fd != set->pcap_fd)
163 close(set->pcap_fd);
164 set->pcap_fd = open(argv[1], O_WRONLY | O_TRUNC | O_CREAT,
165 S_IRUSR | S_IWUSR | S_IRGRP| S_IROTH);
166 if (set->pcap_fd < 0) {
167 vty_out(vty, "Failed to open file for writing.%s", VTY_NEWLINE);
168 return CMD_WARNING;
169 }
170
171 mtp_pcap_write_header(set->pcap_fd);
172 return CMD_SUCCESS;
173}
174
175DEFUN(pcap_set_stop, pcap_set_stop_cmd,
176 "trace-pcap <0-100> NAME stop",
177 "Trace to a PCAP file\n" "Linkset nr\n"
178 "Trace Linkset\n" "Stop the tracing\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 if (set->pcap_fd >= 0 && bsc->pcap_fd != set->pcap_fd)
190 close(set->pcap_fd);
191 set->pcap_fd = -1;
192 return CMD_SUCCESS;
193}
194
195#define FIND_LINK(vty, set_no, nr) ({ \
196 struct mtp_link_set *set = NULL; \
197 struct mtp_link *link = NULL; \
198 set = mtp_link_set_num(bsc, set_no); \
199 if (!set) { \
200 vty_out(vty, "Unknown Linkset nr %d.%s", set_no, VTY_NEWLINE); \
201 return CMD_WARNING; \
202 } \
203 link = mtp_link_num(set, nr); \
204 if (!link) { \
205 vty_out(vty, "Can not find link %d.%s", nr, VTY_NEWLINE); \
206 return CMD_WARNING; \
207 } \
208 link; })
209
210#define LINK_STR "Operations on the link\n" \
211 "Linkset number\n" \
212 "Link number\n"
213
214DEFUN(lnk_block, lnk_block_cmd,
215 "link <0-100> <0-15> block",
216 LINK_STR "Block it\n")
217{
218 struct mtp_link *link = FIND_LINK(vty, atoi(argv[0]), atoi(argv[1]));
219 mtp_link_block(link);
220 return CMD_SUCCESS;
221}
222
223DEFUN(lnk_unblock, lnk_unblock_cmd,
224 "link <0-100> <0-15> unblock",
225 LINK_STR "Unblock it\n")
226{
227 struct mtp_link *link = FIND_LINK(vty, atoi(argv[0]), atoi(argv[1]));
228 mtp_link_unblock(link);
229 return CMD_SUCCESS;
230}
231
232DEFUN(lnk_reset, lnk_reset_cmd,
233 "link <0-100> <0-15> reset",
234 LINK_STR "Reset it\n")
235{
236 struct mtp_link *link = FIND_LINK(vty, atoi(argv[0]), atoi(argv[1]));
237 mtp_link_failure(link);
238 return CMD_SUCCESS;
239}
240
241DEFUN(allow_inject, allow_inject_cmd,
242 "allow-inject (0|1)",
243 "Allow to inject messages\n" "Disable\n" "Enable\n")
244{
245 bsc->allow_inject = atoi(argv[0]);
246 return CMD_SUCCESS;
247}
248
249void cell_vty_init_cmds(void)
250{
251 /* special commands */
252 install_element(ENABLE_NODE, &pcap_set_cmd);
253 install_element(ENABLE_NODE, &pcap_set_stop_cmd);
254 install_element(ENABLE_NODE, &lnk_block_cmd);
255 install_element(ENABLE_NODE, &lnk_unblock_cmd);
256 install_element(ENABLE_NODE, &lnk_reset_cmd);
257 install_element(ENABLE_NODE, &allow_inject_cmd);
258
259 /* show commands */
260 install_element_ve(&show_stats_cmd);
261 install_element_ve(&show_linksets_cmd);
262 install_element_ve(&show_slc_cmd);
263
264 install_element_ve(&show_msc_cmd);
265}