Holger Hans Peter Freyther | 2917644 | 2011-02-22 16:00:36 +0100 | [diff] [blame] | 1 | /* 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 Freyther | ab79b9b | 2011-08-10 06:11:39 +0200 | [diff] [blame] | 25 | #include <sctp_m2ua.h> |
Holger Hans Peter Freyther | 2917644 | 2011-02-22 16:00:36 +0100 | [diff] [blame] | 26 | |
Harald Welte | ff397ed | 2011-05-08 10:29:23 +0200 | [diff] [blame] | 27 | #include <osmocom/core/rate_ctr.h> |
Holger Hans Peter Freyther | 2917644 | 2011-02-22 16:00:36 +0100 | [diff] [blame] | 28 | |
| 29 | #include <osmocom/vty/command.h> |
| 30 | #include <osmocom/vty/logging.h> |
| 31 | #include <osmocom/vty/vty.h> |
Harald Welte | ff397ed | 2011-05-08 10:29:23 +0200 | [diff] [blame] | 32 | #include <osmocom/vty/misc.h> |
Holger Hans Peter Freyther | 2917644 | 2011-02-22 16:00:36 +0100 | [diff] [blame] | 33 | |
| 34 | #include <sys/types.h> |
| 35 | #include <sys/stat.h> |
| 36 | #include <fcntl.h> |
| 37 | #include <unistd.h> |
| 38 | |
| 39 | extern struct bsc_data *bsc; |
| 40 | |
| 41 | static 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 | |
| 54 | DEFUN(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 | |
| 66 | static void dump_state(struct vty *vty, struct mtp_link_set *set) |
| 67 | { |
| 68 | struct mtp_link *link; |
| 69 | |
Holger Hans Peter Freyther | 7176030 | 2011-02-22 20:57:08 +0100 | [diff] [blame] | 70 | if (!set->app) { |
| 71 | vty_out(vty, "LinkSet %d not assigned to an application.%s", |
| 72 | set->nr, VTY_NEWLINE); |
Holger Hans Peter Freyther | 2917644 | 2011-02-22 16:00:36 +0100 | [diff] [blame] | 73 | return; |
| 74 | } |
| 75 | |
Holger Hans Peter Freyther | 7176030 | 2011-02-22 20:57:08 +0100 | [diff] [blame] | 76 | vty_out(vty, "LinkSet for %d/%s is %s, remote sccp is %s.%s", |
| 77 | set->nr, set->name, |
Holger Hans Peter Freyther | 2917644 | 2011-02-22 16:00:36 +0100 | [diff] [blame] | 78 | 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 | |
| 94 | DEFUN(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 | |
| 105 | DEFUN(show_msc, show_msc_cmd, |
| 106 | "show msc", |
| 107 | SHOW_STR "Display the status of the MSC\n") |
| 108 | { |
Holger Hans Peter Freyther | 31d6597 | 2011-11-25 16:23:43 +0100 | [diff] [blame^] | 109 | struct msc_connection *msc; |
Holger Hans Peter Freyther | 2917644 | 2011-02-22 16:00:36 +0100 | [diff] [blame] | 110 | |
Holger Hans Peter Freyther | 31d6597 | 2011-11-25 16:23:43 +0100 | [diff] [blame^] | 111 | llist_for_each_entry(msc, &bsc->mscs, entry) { |
| 112 | vty_out(vty, "MSC link is %s and had %s.%s", |
| 113 | msc->msc_link_down == 0 ? "up" : "down", |
| 114 | msc->first_contact == 1 ? "no contact" : "contact", |
| 115 | VTY_NEWLINE); |
Holger Hans Peter Freyther | 2917644 | 2011-02-22 16:00:36 +0100 | [diff] [blame] | 116 | } |
| 117 | |
Holger Hans Peter Freyther | 2917644 | 2011-02-22 16:00:36 +0100 | [diff] [blame] | 118 | return CMD_SUCCESS; |
| 119 | } |
| 120 | |
Holger Hans Peter Freyther | 31d6597 | 2011-11-25 16:23:43 +0100 | [diff] [blame^] | 121 | DEFUN(show_mscs, show_mscs_cmd, |
| 122 | "show mscs", |
| 123 | SHOW_STR "Display the status of all MSCs\n") |
| 124 | { |
| 125 | struct msc_connection *msc; |
| 126 | |
| 127 | llist_for_each_entry(msc, &bsc->mscs, entry) { |
| 128 | vty_out(vty, "MSC link nr %d name '%s' is %s and had %s.%s", |
| 129 | msc->nr, msc->name, |
| 130 | msc->msc_link_down == 0 ? "up" : "down", |
| 131 | msc->first_contact == 1 ? "no contact" : "contact", |
| 132 | VTY_NEWLINE); |
| 133 | } |
| 134 | |
| 135 | return CMD_SUCCESS; |
| 136 | } |
| 137 | |
| 138 | |
Holger Hans Peter Freyther | 2917644 | 2011-02-22 16:00:36 +0100 | [diff] [blame] | 139 | DEFUN(show_slc, show_slc_cmd, |
| 140 | "show link-set <0-100> slc", |
| 141 | SHOW_STR "LinkSet\n" "Linkset nr\n" "SLS to SLC\n") |
| 142 | { |
| 143 | struct mtp_link_set *set = NULL; |
| 144 | int i; |
| 145 | |
| 146 | set = mtp_link_set_num(bsc, atoi(argv[0])); |
| 147 | |
| 148 | if (!set) { |
| 149 | vty_out(vty, "Failed to find linkset.%s", VTY_NEWLINE); |
| 150 | return CMD_WARNING; |
| 151 | } |
| 152 | |
| 153 | vty_out(vty, "LinkSet for %s.%s", argv[0], VTY_NEWLINE); |
| 154 | for (i = 0; i < ARRAY_SIZE(set->slc); ++i) { |
| 155 | if (set->slc[i]) |
| 156 | vty_out(vty, " SLC[%.2d] is on link %d.%s", |
| 157 | i, set->slc[i]->nr, VTY_NEWLINE); |
| 158 | else |
| 159 | vty_out(vty, " SLC[%d] is down.%s", |
| 160 | i, VTY_NEWLINE); |
| 161 | } |
| 162 | |
| 163 | return CMD_SUCCESS; |
| 164 | } |
| 165 | |
| 166 | DEFUN(pcap_set, pcap_set_cmd, |
| 167 | "trace-pcap <0-100> NAME FILE", |
| 168 | "Trace to a PCAP file\n" "Linkset nr.\n" |
| 169 | "Trace Linkset\n" "Filename to trace\n") |
| 170 | { |
| 171 | struct mtp_link_set *set = NULL; |
| 172 | |
| 173 | set = mtp_link_set_num(bsc, atoi(argv[0])); |
| 174 | |
| 175 | if (!set) { |
| 176 | vty_out(vty, "Failed to find linkset.%s", VTY_NEWLINE); |
| 177 | return CMD_WARNING; |
| 178 | } |
| 179 | |
| 180 | |
| 181 | if (set->pcap_fd >= 0 && bsc->pcap_fd != set->pcap_fd) |
| 182 | close(set->pcap_fd); |
| 183 | set->pcap_fd = open(argv[1], O_WRONLY | O_TRUNC | O_CREAT, |
| 184 | S_IRUSR | S_IWUSR | S_IRGRP| S_IROTH); |
| 185 | if (set->pcap_fd < 0) { |
| 186 | vty_out(vty, "Failed to open file for writing.%s", VTY_NEWLINE); |
| 187 | return CMD_WARNING; |
| 188 | } |
| 189 | |
| 190 | mtp_pcap_write_header(set->pcap_fd); |
| 191 | return CMD_SUCCESS; |
| 192 | } |
| 193 | |
| 194 | DEFUN(pcap_set_stop, pcap_set_stop_cmd, |
| 195 | "trace-pcap <0-100> NAME stop", |
| 196 | "Trace to a PCAP file\n" "Linkset nr\n" |
| 197 | "Trace Linkset\n" "Stop the tracing\n") |
| 198 | { |
| 199 | struct mtp_link_set *set = NULL; |
| 200 | |
| 201 | set = mtp_link_set_num(bsc, atoi(argv[0])); |
| 202 | |
| 203 | if (!set) { |
| 204 | vty_out(vty, "Failed to find linkset.%s", VTY_NEWLINE); |
| 205 | return CMD_WARNING; |
| 206 | } |
| 207 | |
| 208 | if (set->pcap_fd >= 0 && bsc->pcap_fd != set->pcap_fd) |
| 209 | close(set->pcap_fd); |
| 210 | set->pcap_fd = -1; |
| 211 | return CMD_SUCCESS; |
| 212 | } |
| 213 | |
| 214 | #define FIND_LINK(vty, set_no, nr) ({ \ |
| 215 | struct mtp_link_set *set = NULL; \ |
| 216 | struct mtp_link *link = NULL; \ |
| 217 | set = mtp_link_set_num(bsc, set_no); \ |
| 218 | if (!set) { \ |
| 219 | vty_out(vty, "Unknown Linkset nr %d.%s", set_no, VTY_NEWLINE); \ |
| 220 | return CMD_WARNING; \ |
| 221 | } \ |
Holger Hans Peter Freyther | 7176030 | 2011-02-22 20:57:08 +0100 | [diff] [blame] | 222 | if (!set->app) { \ |
| 223 | vty_out(vty, "Linkset nr %d has no application.%s", \ |
| 224 | set_no, VTY_NEWLINE); \ |
| 225 | } \ |
Holger Hans Peter Freyther | 2917644 | 2011-02-22 16:00:36 +0100 | [diff] [blame] | 226 | link = mtp_link_num(set, nr); \ |
| 227 | if (!link) { \ |
| 228 | vty_out(vty, "Can not find link %d.%s", nr, VTY_NEWLINE); \ |
| 229 | return CMD_WARNING; \ |
| 230 | } \ |
| 231 | link; }) |
| 232 | |
| 233 | #define LINK_STR "Operations on the link\n" \ |
| 234 | "Linkset number\n" \ |
| 235 | "Link number\n" |
| 236 | |
| 237 | DEFUN(lnk_block, lnk_block_cmd, |
| 238 | "link <0-100> <0-15> block", |
| 239 | LINK_STR "Block it\n") |
| 240 | { |
| 241 | struct mtp_link *link = FIND_LINK(vty, atoi(argv[0]), atoi(argv[1])); |
| 242 | mtp_link_block(link); |
| 243 | return CMD_SUCCESS; |
| 244 | } |
| 245 | |
| 246 | DEFUN(lnk_unblock, lnk_unblock_cmd, |
| 247 | "link <0-100> <0-15> unblock", |
| 248 | LINK_STR "Unblock it\n") |
| 249 | { |
| 250 | struct mtp_link *link = FIND_LINK(vty, atoi(argv[0]), atoi(argv[1])); |
| 251 | mtp_link_unblock(link); |
| 252 | return CMD_SUCCESS; |
| 253 | } |
| 254 | |
| 255 | DEFUN(lnk_reset, lnk_reset_cmd, |
| 256 | "link <0-100> <0-15> reset", |
| 257 | LINK_STR "Reset it\n") |
| 258 | { |
| 259 | struct mtp_link *link = FIND_LINK(vty, atoi(argv[0]), atoi(argv[1])); |
| 260 | mtp_link_failure(link); |
| 261 | return CMD_SUCCESS; |
| 262 | } |
| 263 | |
| 264 | DEFUN(allow_inject, allow_inject_cmd, |
| 265 | "allow-inject (0|1)", |
| 266 | "Allow to inject messages\n" "Disable\n" "Enable\n") |
| 267 | { |
| 268 | bsc->allow_inject = atoi(argv[0]); |
| 269 | return CMD_SUCCESS; |
| 270 | } |
| 271 | |
Holger Hans Peter Freyther | cf60a01 | 2011-08-10 06:26:44 +0200 | [diff] [blame] | 272 | DEFUN(show_sctp_count, show_sctp_count_cmd, |
| 273 | "show sctp-connections count", |
| 274 | SHOW_STR "Number of SCTP connections\n") |
Holger Hans Peter Freyther | ab79b9b | 2011-08-10 06:11:39 +0200 | [diff] [blame] | 275 | { |
| 276 | int count = sctp_m2ua_conn_count(bsc->m2ua_trans); |
| 277 | vty_out(vty, "Active SCTP connections are: %d.%s", count, VTY_NEWLINE); |
| 278 | return CMD_SUCCESS; |
| 279 | } |
| 280 | |
Holger Hans Peter Freyther | cf60a01 | 2011-08-10 06:26:44 +0200 | [diff] [blame] | 281 | DEFUN(show_sctp_details, show_sctp_details_cmd, |
| 282 | "show sctp-connections details", |
| 283 | SHOW_STR "Details of SCTP connections\n") |
| 284 | { |
| 285 | struct sctp_m2ua_conn *conn; |
| 286 | |
| 287 | llist_for_each_entry(conn, &bsc->m2ua_trans->conns, entry) { |
| 288 | vty_out(vty, |
| 289 | "SCTP Conn ASP UP: %d, ident: %d,%d,%d,%d fd: %d ptr: %p.%s", |
| 290 | conn->asp_up, conn->asp_ident[0], conn->asp_ident[1], |
| 291 | conn->asp_ident[2], conn->asp_ident[3], |
| 292 | conn->queue.bfd.fd, conn, VTY_NEWLINE); |
| 293 | } |
| 294 | |
| 295 | return CMD_WARNING; |
| 296 | } |
| 297 | |
Holger Hans Peter Freyther | 2917644 | 2011-02-22 16:00:36 +0100 | [diff] [blame] | 298 | void cell_vty_init_cmds(void) |
| 299 | { |
| 300 | /* special commands */ |
| 301 | install_element(ENABLE_NODE, &pcap_set_cmd); |
| 302 | install_element(ENABLE_NODE, &pcap_set_stop_cmd); |
| 303 | install_element(ENABLE_NODE, &lnk_block_cmd); |
| 304 | install_element(ENABLE_NODE, &lnk_unblock_cmd); |
| 305 | install_element(ENABLE_NODE, &lnk_reset_cmd); |
| 306 | install_element(ENABLE_NODE, &allow_inject_cmd); |
| 307 | |
| 308 | /* show commands */ |
| 309 | install_element_ve(&show_stats_cmd); |
| 310 | install_element_ve(&show_linksets_cmd); |
| 311 | install_element_ve(&show_slc_cmd); |
| 312 | |
| 313 | install_element_ve(&show_msc_cmd); |
Holger Hans Peter Freyther | 31d6597 | 2011-11-25 16:23:43 +0100 | [diff] [blame^] | 314 | install_element_ve(&show_mscs_cmd); |
Holger Hans Peter Freyther | cf60a01 | 2011-08-10 06:26:44 +0200 | [diff] [blame] | 315 | install_element_ve(&show_sctp_count_cmd); |
| 316 | install_element_ve(&show_sctp_details_cmd); |
Holger Hans Peter Freyther | 2917644 | 2011-02-22 16:00:36 +0100 | [diff] [blame] | 317 | } |