Holger Hans Peter Freyther | 7942abc | 2010-09-30 00:34:46 +0800 | [diff] [blame] | 1 | /* VTY code for the Cellmgr */ |
| 2 | /* |
Holger Hans Peter Freyther | a310e53 | 2011-01-22 16:34:16 +0100 | [diff] [blame] | 3 | * (C) 2010-2011 by Holger Hans Peter Freyther <zecke@selfish.org> |
| 4 | * (C) 2010-2011 by On-Waves |
Holger Hans Peter Freyther | 7942abc | 2010-09-30 00:34:46 +0800 | [diff] [blame] | 5 | * All Rights Reserved |
| 6 | * |
Holger Hans Peter Freyther | de56c22 | 2011-01-16 17:45:14 +0100 | [diff] [blame] | 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 |
Holger Hans Peter Freyther | 7942abc | 2010-09-30 00:34:46 +0800 | [diff] [blame] | 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 |
Holger Hans Peter Freyther | de56c22 | 2011-01-16 17:45:14 +0100 | [diff] [blame] | 15 | * GNU Affero General Public License for more details. |
Holger Hans Peter Freyther | 7942abc | 2010-09-30 00:34:46 +0800 | [diff] [blame] | 16 | * |
Holger Hans Peter Freyther | de56c22 | 2011-01-16 17:45:14 +0100 | [diff] [blame] | 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/>. |
Holger Hans Peter Freyther | 7942abc | 2010-09-30 00:34:46 +0800 | [diff] [blame] | 19 | * |
| 20 | */ |
| 21 | |
| 22 | #include <bsc_data.h> |
Holger Hans Peter Freyther | 5b2fe8d | 2011-01-22 21:09:53 +0100 | [diff] [blame] | 23 | #include <mtp_pcap.h> |
Holger Hans Peter Freyther | 7942abc | 2010-09-30 00:34:46 +0800 | [diff] [blame] | 24 | |
| 25 | #include <osmocore/talloc.h> |
Holger Hans Peter Freyther | 0e4e35f | 2010-09-30 03:04:28 +0800 | [diff] [blame] | 26 | #include <osmocore/gsm48.h> |
Holger Hans Peter Freyther | 51b9e7a | 2011-01-22 16:02:13 +0100 | [diff] [blame] | 27 | #include <osmocore/rate_ctr.h> |
Holger Hans Peter Freyther | 7942abc | 2010-09-30 00:34:46 +0800 | [diff] [blame] | 28 | |
| 29 | #include <osmocom/vty/command.h> |
Holger Hans Peter Freyther | fca7b12 | 2011-01-22 23:19:44 +0100 | [diff] [blame] | 30 | #include <osmocom/vty/logging.h> |
Holger Hans Peter Freyther | 7942abc | 2010-09-30 00:34:46 +0800 | [diff] [blame] | 31 | #include <osmocom/vty/vty.h> |
| 32 | |
| 33 | #include <unistd.h> |
| 34 | #include <netdb.h> |
Holger Hans Peter Freyther | 5b2fe8d | 2011-01-22 21:09:53 +0100 | [diff] [blame] | 35 | #include <sys/types.h> |
| 36 | #include <sys/stat.h> |
| 37 | #include <fcntl.h> |
Holger Hans Peter Freyther | 7942abc | 2010-09-30 00:34:46 +0800 | [diff] [blame] | 38 | |
| 39 | #undef PACKAGE_NAME |
| 40 | #undef PACKAGE_VERSION |
| 41 | #undef PACKAGE_BUGREPORT |
| 42 | #undef PACKAGE_TARNAME |
| 43 | #undef PACKAGE_STRING |
| 44 | #include <cellmgr_config.h> |
| 45 | |
| 46 | extern struct bsc_data bsc; |
| 47 | |
| 48 | static struct vty_app_info vty_info = { |
| 49 | .name = "Cellmgr-ng", |
| 50 | .version = VERSION, |
| 51 | .go_parent_cb = NULL, |
| 52 | }; |
| 53 | |
| 54 | /* vty code */ |
| 55 | enum cellmgr_node { |
| 56 | CELLMGR_NODE = _LAST_OSMOVTY_NODE, |
| 57 | }; |
| 58 | |
| 59 | static struct cmd_node cell_node = { |
| 60 | CELLMGR_NODE, |
| 61 | "%s(cellmgr)#", |
| 62 | 1, |
| 63 | }; |
| 64 | |
Holger Hans Peter Freyther | 2656e8f | 2010-09-30 00:41:37 +0800 | [diff] [blame] | 65 | static int config_write_cell(struct vty *vty) |
Holger Hans Peter Freyther | 7942abc | 2010-09-30 00:34:46 +0800 | [diff] [blame] | 66 | { |
Holger Hans Peter Freyther | 2656e8f | 2010-09-30 00:41:37 +0800 | [diff] [blame] | 67 | vty_out(vty, "cellmgr%s", VTY_NEWLINE); |
| 68 | vty_out(vty, " mtp dpc %d%s", bsc.dpc, VTY_NEWLINE); |
| 69 | vty_out(vty, " mtp opc %d%s", bsc.opc, VTY_NEWLINE); |
Holger Hans Peter Freyther | 7a72556 | 2011-01-01 13:34:58 +0100 | [diff] [blame] | 70 | vty_out(vty, " mtp sccp-opc %d%s", bsc.sccp_opc, VTY_NEWLINE); |
Holger Hans Peter Freyther | b38b33b | 2010-11-26 21:21:04 +0100 | [diff] [blame] | 71 | vty_out(vty, " mtp ni %d%s", bsc.ni_ni, VTY_NEWLINE); |
| 72 | vty_out(vty, " mtp spare %d%s", bsc.ni_spare, VTY_NEWLINE); |
Holger Hans Peter Freyther | 3bbb58b | 2010-11-26 21:25:38 +0100 | [diff] [blame] | 73 | vty_out(vty, " mtp sltm once %d%s", bsc.once, VTY_NEWLINE); |
Holger Hans Peter Freyther | 0e4e35f | 2010-09-30 03:04:28 +0800 | [diff] [blame] | 74 | vty_out(vty, " country-code %d%s", bsc.mcc, VTY_NEWLINE); |
| 75 | vty_out(vty, " network-code %d%s", bsc.mnc, VTY_NEWLINE); |
| 76 | vty_out(vty, " location-area-code %d%s", bsc.lac, VTY_NEWLINE); |
Holger Hans Peter Freyther | 2656e8f | 2010-09-30 00:41:37 +0800 | [diff] [blame] | 77 | if (bsc.udp_ip) |
| 78 | vty_out(vty, " udp dest ip %s%s", bsc.udp_ip, VTY_NEWLINE); |
| 79 | vty_out(vty, " udp dest port %d%s", bsc.udp_port, VTY_NEWLINE); |
| 80 | vty_out(vty, " udp src port %d%s", bsc.src_port, VTY_NEWLINE); |
Holger Hans Peter Freyther | 644aafb | 2011-01-03 23:51:07 +0100 | [diff] [blame] | 81 | vty_out(vty, " udp reset %d%s", bsc.udp_reset_timeout, VTY_NEWLINE); |
Holger Hans Peter Freyther | c6bfa27 | 2011-01-22 17:06:34 +0100 | [diff] [blame] | 82 | vty_out(vty, " udp number-links %d%s", bsc.udp_nr_links, VTY_NEWLINE); |
Holger Hans Peter Freyther | 2656e8f | 2010-09-30 00:41:37 +0800 | [diff] [blame] | 83 | vty_out(vty, " msc ip %s%s", bsc.msc_address, VTY_NEWLINE); |
| 84 | vty_out(vty, " msc ip-dscp %d%s", bsc.msc_ip_dscp, VTY_NEWLINE); |
| 85 | vty_out(vty, " msc token %s%s", bsc.token, VTY_NEWLINE); |
| 86 | |
Holger Hans Peter Freyther | 7942abc | 2010-09-30 00:34:46 +0800 | [diff] [blame] | 87 | return CMD_SUCCESS; |
| 88 | } |
| 89 | |
| 90 | DEFUN(cfg_cell, cfg_cell_cmd, |
| 91 | "cellmgr", "Configure the Cellmgr") |
| 92 | { |
| 93 | vty->node = CELLMGR_NODE; |
| 94 | return CMD_SUCCESS; |
| 95 | } |
| 96 | |
| 97 | DEFUN(cfg_net_dpc, cfg_net_dpc_cmd, |
| 98 | "mtp dpc DPC_NR", |
| 99 | "Set the DPC to be used.") |
| 100 | { |
| 101 | bsc.dpc = atoi(argv[0]); |
| 102 | return CMD_SUCCESS; |
| 103 | } |
| 104 | |
| 105 | DEFUN(cfg_net_opc, cfg_net_opc_cmd, |
| 106 | "mtp opc OPC_NR", |
| 107 | "Set the OPC to be used.") |
| 108 | { |
| 109 | bsc.opc = atoi(argv[0]); |
| 110 | return CMD_SUCCESS; |
| 111 | } |
| 112 | |
Holger Hans Peter Freyther | 7a72556 | 2011-01-01 13:34:58 +0100 | [diff] [blame] | 113 | DEFUN(cfg_net_sccp_opc, cfg_net_sccp_opc_cmd, |
| 114 | "mtp sccp-opc OPC_NR", |
| 115 | "Set the SCCP OPC to be used.") |
| 116 | { |
| 117 | bsc.sccp_opc = atoi(argv[0]); |
| 118 | return CMD_SUCCESS; |
| 119 | } |
| 120 | |
Holger Hans Peter Freyther | b38b33b | 2010-11-26 21:21:04 +0100 | [diff] [blame] | 121 | DEFUN(cfg_net_mtp_ni, cfg_net_mtp_ni_cmd, |
| 122 | "mtp ni NR", |
| 123 | "Set the MTP NI to be used.\n" "NR") |
| 124 | { |
| 125 | bsc.ni_ni = atoi(argv[0]); |
| 126 | return CMD_SUCCESS; |
| 127 | } |
| 128 | |
| 129 | DEFUN(cfg_net_mtp_spare, cfg_net_mtp_spare_cmd, |
| 130 | "mtp spare NR", |
| 131 | "Set the MTP Spare to be used.\n" "NR") |
| 132 | { |
| 133 | bsc.ni_spare = atoi(argv[0]); |
| 134 | return CMD_SUCCESS; |
| 135 | } |
| 136 | |
| 137 | |
Holger Hans Peter Freyther | 7942abc | 2010-09-30 00:34:46 +0800 | [diff] [blame] | 138 | DEFUN(cfg_udp_dst_ip, cfg_udp_dst_ip_cmd, |
| 139 | "udp dest ip IP", |
| 140 | "Set the IP when UDP mode is supposed to be used.") |
| 141 | { |
| 142 | struct hostent *hosts; |
| 143 | struct in_addr *addr; |
| 144 | |
| 145 | hosts = gethostbyname(argv[0]); |
| 146 | if (!hosts || hosts->h_length < 1 || hosts->h_addrtype != AF_INET) { |
| 147 | vty_out(vty, "Failed to resolve '%s'%s", argv[0], VTY_NEWLINE); |
| 148 | return CMD_WARNING; |
| 149 | } |
| 150 | |
| 151 | addr = (struct in_addr *) hosts->h_addr_list[0]; |
| 152 | bsc.udp_ip = talloc_strdup(NULL, inet_ntoa(*addr)); |
| 153 | return CMD_SUCCESS; |
| 154 | } |
| 155 | |
| 156 | DEFUN(cfg_udp_dst_port, cfg_udp_dst_port_cmd, |
| 157 | "udp dest port PORT_NR", |
| 158 | "If UDP mode is used specify the UDP dest port") |
| 159 | { |
| 160 | bsc.udp_port = atoi(argv[0]); |
| 161 | return CMD_SUCCESS; |
| 162 | } |
| 163 | |
| 164 | DEFUN(cfg_udp_src_port, cfg_udp_src_port_cmd, |
| 165 | "udp src port PORT_NR", |
| 166 | "Set the UDP source port to be used.") |
| 167 | { |
| 168 | bsc.src_port = atoi(argv[0]); |
| 169 | return CMD_SUCCESS; |
| 170 | } |
| 171 | |
| 172 | DEFUN(cfg_udp_reset, cfg_udp_reset_cmd, |
| 173 | "udp reset TIMEOUT", |
| 174 | "Set the timeout to take the link down") |
| 175 | { |
Holger Hans Peter Freyther | 644aafb | 2011-01-03 23:51:07 +0100 | [diff] [blame] | 176 | bsc.udp_reset_timeout = atoi(argv[0]); |
Holger Hans Peter Freyther | 7942abc | 2010-09-30 00:34:46 +0800 | [diff] [blame] | 177 | return CMD_SUCCESS; |
| 178 | } |
| 179 | |
Holger Hans Peter Freyther | c6bfa27 | 2011-01-22 17:06:34 +0100 | [diff] [blame] | 180 | DEFUN(cfg_udp_nr_links, cfg_udp_nr_links_cmd, |
| 181 | "udp number-links <1-32>", |
| 182 | "Set the number of links to use\n") |
| 183 | { |
| 184 | bsc.udp_nr_links = atoi(argv[0]); |
| 185 | return CMD_SUCCESS; |
| 186 | } |
| 187 | |
Holger Hans Peter Freyther | 7942abc | 2010-09-30 00:34:46 +0800 | [diff] [blame] | 188 | DEFUN(cfg_sltm_once, cfg_sltm_once_cmd, |
| 189 | "mtp sltm once (0|1)", |
| 190 | "Send SLTMs until the link is established.") |
| 191 | { |
| 192 | bsc.once = !!atoi(argv[0]); |
| 193 | return CMD_SUCCESS; |
| 194 | } |
| 195 | |
| 196 | DEFUN(cfg_msc_ip, cfg_msc_ip_cmd, |
| 197 | "msc ip IP", |
| 198 | "Set the MSC IP") |
| 199 | { |
| 200 | struct hostent *hosts; |
| 201 | struct in_addr *addr; |
| 202 | |
| 203 | hosts = gethostbyname(argv[0]); |
| 204 | if (!hosts || hosts->h_length < 1 || hosts->h_addrtype != AF_INET) { |
| 205 | vty_out(vty, "Failed to resolve '%s'%s", argv[0], VTY_NEWLINE); |
| 206 | return CMD_WARNING; |
| 207 | } |
| 208 | |
| 209 | addr = (struct in_addr *) hosts->h_addr_list[0]; |
| 210 | |
| 211 | bsc.msc_address = talloc_strdup(NULL, inet_ntoa(*addr)); |
| 212 | return CMD_SUCCESS; |
| 213 | } |
| 214 | |
| 215 | DEFUN(cfg_msc_ip_dscp, cfg_msc_ip_dscp_cmd, |
| 216 | "msc ip-dscp <0-255>", |
| 217 | "Set the IP DSCP on the A-link\n" |
| 218 | "Set the DSCP in IP packets to the MSC") |
| 219 | { |
| 220 | bsc.msc_ip_dscp = atoi(argv[0]); |
| 221 | return CMD_SUCCESS; |
| 222 | } |
| 223 | |
| 224 | ALIAS_DEPRECATED(cfg_msc_ip_dscp, cfg_msc_ip_tos_cmd, |
| 225 | "msc ip-tos <0-255>", |
| 226 | "Set the IP DSCP on the A-link\n" |
| 227 | "Set the DSCP in IP packets to the MSC") |
| 228 | |
| 229 | DEFUN(cfg_msc_token, cfg_msc_token_cmd, |
| 230 | "msc token TOKEN", |
| 231 | "Set the Token to be used for the MSC") |
| 232 | { |
| 233 | bsc.token = talloc_strdup(NULL, argv[0]); |
| 234 | return CMD_SUCCESS; |
| 235 | } |
| 236 | |
| 237 | DEFUN(cfg_ping_time, cfg_ping_time_cmd, |
| 238 | "timeout ping NR", |
| 239 | "Set the PING interval. Negative to disable it") |
| 240 | { |
| 241 | bsc.ping_time = atoi(argv[0]); |
| 242 | return CMD_SUCCESS; |
| 243 | } |
| 244 | |
| 245 | DEFUN(cfg_pong_time, cfg_pong_time_cmd, |
| 246 | "timeout pong NR", |
| 247 | "Set the PING interval. Negative to disable it") |
| 248 | { |
| 249 | bsc.pong_time = atoi(argv[0]); |
| 250 | return CMD_SUCCESS; |
| 251 | } |
| 252 | |
| 253 | DEFUN(cfg_msc_time, cfg_msc_time_cmd, |
| 254 | "timeout msc NR", |
| 255 | "Set the MSC connect timeout") |
| 256 | { |
| 257 | bsc.msc_time = atoi(argv[0]); |
| 258 | return CMD_SUCCESS; |
| 259 | } |
| 260 | |
Holger Hans Peter Freyther | 0e4e35f | 2010-09-30 03:04:28 +0800 | [diff] [blame] | 261 | static void update_lai(struct bsc_data *bsc) |
| 262 | { |
| 263 | gsm48_generate_lai(&bsc->lai, bsc->mcc, bsc->mnc, bsc->lac); |
| 264 | } |
| 265 | |
| 266 | DEFUN(cfg_mnc, cfg_mnc_cmd, |
| 267 | "network-code NR", |
| 268 | "Set the Mobile Network Code\n" "Number\n") |
| 269 | { |
| 270 | bsc.mnc = atoi(argv[0]); |
| 271 | update_lai(&bsc); |
| 272 | return CMD_SUCCESS; |
| 273 | } |
| 274 | |
| 275 | DEFUN(cfg_mcc, cfg_mcc_cmd, |
| 276 | "country-code NR", |
| 277 | "Set the Mobile Country Code\n" "Number\n") |
| 278 | { |
| 279 | bsc.mcc = atoi(argv[0]); |
| 280 | update_lai(&bsc); |
| 281 | return CMD_SUCCESS; |
| 282 | } |
| 283 | |
| 284 | DEFUN(cfg_lac, cfg_lac_cmd, |
| 285 | "location-area-code NR", |
| 286 | "Set the Location Area Code\n" "Number\n") |
| 287 | { |
| 288 | bsc.lac = atoi(argv[0]); |
| 289 | update_lai(&bsc); |
| 290 | return CMD_SUCCESS; |
| 291 | } |
| 292 | |
Holger Hans Peter Freyther | 1b47ce5 | 2011-01-22 21:31:24 +0100 | [diff] [blame] | 293 | static void dump_stats(struct vty *vty, const char *name, struct mtp_link_set *set) |
Holger Hans Peter Freyther | 51b9e7a | 2011-01-22 16:02:13 +0100 | [diff] [blame] | 294 | { |
| 295 | struct mtp_link *link; |
| 296 | |
Holger Hans Peter Freyther | 1b47ce5 | 2011-01-22 21:31:24 +0100 | [diff] [blame] | 297 | vty_out(vty, "Linkset name: %s opc: %d%s", name, set->opc, VTY_NEWLINE); |
Holger Hans Peter Freyther | 51b9e7a | 2011-01-22 16:02:13 +0100 | [diff] [blame] | 298 | vty_out_rate_ctr_group(vty, " ", set->ctrg); |
| 299 | |
| 300 | llist_for_each_entry(link, &set->links, entry) { |
| 301 | vty_out(vty, " Link %d%s", link->link_no, VTY_NEWLINE); |
| 302 | vty_out_rate_ctr_group(vty, " ", link->ctrg); |
| 303 | } |
| 304 | } |
| 305 | |
| 306 | DEFUN(show_stats, show_stats_cmd, |
| 307 | "show statistics", |
| 308 | SHOW_STR "Display Linkset statistics\n") |
| 309 | { |
| 310 | if (bsc.link_set) |
Holger Hans Peter Freyther | 1b47ce5 | 2011-01-22 21:31:24 +0100 | [diff] [blame] | 311 | dump_stats(vty, "MTP ", bsc.link_set); |
Holger Hans Peter Freyther | a310e53 | 2011-01-22 16:34:16 +0100 | [diff] [blame] | 312 | if (bsc.m2ua_set && bsc.app == APP_STP) |
Holger Hans Peter Freyther | 1b47ce5 | 2011-01-22 21:31:24 +0100 | [diff] [blame] | 313 | dump_stats(vty, "M2UA", bsc.m2ua_set); |
Holger Hans Peter Freyther | 51b9e7a | 2011-01-22 16:02:13 +0100 | [diff] [blame] | 314 | return CMD_SUCCESS; |
| 315 | } |
| 316 | |
Holger Hans Peter Freyther | 60af5dd | 2011-01-22 16:16:52 +0100 | [diff] [blame] | 317 | static void dump_state(struct vty *vty, const char *name, struct mtp_link_set *set) |
| 318 | { |
| 319 | struct mtp_link *link; |
| 320 | |
| 321 | if (!set) { |
| 322 | vty_out(vty, "LinkSet for %s is not configured.%s", name, VTY_NEWLINE); |
| 323 | return; |
| 324 | } |
| 325 | |
| 326 | vty_out(vty, "LinkSet for %s is %s, remote sccp is %s.%s", |
| 327 | name, |
| 328 | set->available == 0 ? "not available" : "available", |
| 329 | set->sccp_up == 0? "not established" : "established", |
| 330 | VTY_NEWLINE); |
| 331 | |
| 332 | llist_for_each_entry(link, &set->links, entry) { |
Holger Hans Peter Freyther | 4e2e242 | 2011-01-24 15:40:30 +0100 | [diff] [blame] | 333 | if (link->blocked) |
| 334 | vty_out(vty, " Link %d is blocked.%s", |
| 335 | link->link_no, VTY_NEWLINE); |
| 336 | else |
| 337 | vty_out(vty, " Link %d is %s.%s", |
| 338 | link->link_no, |
| 339 | link->available == 0 ? "not available" : "available", |
| 340 | VTY_NEWLINE); |
Holger Hans Peter Freyther | 60af5dd | 2011-01-22 16:16:52 +0100 | [diff] [blame] | 341 | } |
| 342 | } |
| 343 | |
| 344 | DEFUN(show_linksets, show_linksets_cmd, |
| 345 | "show link-sets", |
| 346 | SHOW_STR "Display current state of linksets\n") |
| 347 | { |
| 348 | dump_state(vty, "MTP ", bsc.link_set); |
Holger Hans Peter Freyther | a310e53 | 2011-01-22 16:34:16 +0100 | [diff] [blame] | 349 | if (bsc.app == APP_STP) |
| 350 | dump_state(vty, "M2UA", bsc.m2ua_set); |
Holger Hans Peter Freyther | 60af5dd | 2011-01-22 16:16:52 +0100 | [diff] [blame] | 351 | return CMD_SUCCESS; |
| 352 | } |
| 353 | |
Holger Hans Peter Freyther | 0b31622 | 2011-01-22 16:43:14 +0100 | [diff] [blame] | 354 | DEFUN(show_msc, show_msc_cmd, |
| 355 | "show msc", |
| 356 | SHOW_STR "Display the status of the MSC\n") |
| 357 | { |
| 358 | vty_out(vty, "MSC link is %s and had %s.%s", |
| 359 | bsc.msc_link_down == 0 ? "down" : "up", |
| 360 | bsc.first_contact == 1 ? "no contact" : "contact", |
| 361 | VTY_NEWLINE); |
| 362 | return CMD_SUCCESS; |
| 363 | } |
| 364 | |
Holger Hans Peter Freyther | 3c2b84c | 2011-01-24 21:13:56 +0100 | [diff] [blame^] | 365 | DEFUN(show_slc, show_slc_cmd, |
| 366 | "show link-set (mtp|m2ua) slc", |
| 367 | SHOW_STR "LinkSet\n" "MTP Linkset\n" "M2UA LinkSet\n" "SLS to SLC\n") |
| 368 | { |
| 369 | struct mtp_link_set *set = NULL; |
| 370 | int i; |
| 371 | |
| 372 | if (bsc.link_set && strcmp(argv[0], "mtp") == 0) |
| 373 | set = bsc.link_set; |
| 374 | else if (bsc.m2ua_set && strcmp(argv[0], "m2ua") == 0) |
| 375 | set = bsc.m2ua_set; |
| 376 | |
| 377 | if (!set) { |
| 378 | vty_out(vty, "Failed to find linkset.%s", VTY_NEWLINE); |
| 379 | return CMD_WARNING; |
| 380 | } |
| 381 | |
| 382 | vty_out(vty, "LinkSet for %s.%s", argv[0], VTY_NEWLINE); |
| 383 | for (i = 0; i < ARRAY_SIZE(set->slc); ++i) { |
| 384 | if (set->slc[i]) |
| 385 | vty_out(vty, " SLC[%.2d] is on link %d.%s", |
| 386 | i, set->slc[i]->link_no, VTY_NEWLINE); |
| 387 | else |
| 388 | vty_out(vty, " SLC[%d] is down.%s", |
| 389 | i, VTY_NEWLINE); |
| 390 | } |
| 391 | |
| 392 | return CMD_SUCCESS; |
| 393 | } |
| 394 | |
Holger Hans Peter Freyther | 5b2fe8d | 2011-01-22 21:09:53 +0100 | [diff] [blame] | 395 | DEFUN(pcap_set, pcap_set_cmd, |
| 396 | "trace-pcap set (m2ua|mtp) FILE", |
| 397 | "Trace to a PCAP file\n" "Trace a linkset\n" |
| 398 | "OPC of the linkset\n" "Filename to trace\n") |
| 399 | { |
| 400 | struct mtp_link_set *set = NULL; |
| 401 | |
| 402 | if (bsc.link_set && strcmp(argv[0], "mtp") == 0) |
| 403 | set = bsc.link_set; |
| 404 | else if (bsc.m2ua_set && strcmp(argv[0], "m2ua") == 0) |
| 405 | set = bsc.m2ua_set; |
| 406 | |
| 407 | if (!set) { |
| 408 | vty_out(vty, "Failed to find linkset.%s", VTY_NEWLINE); |
| 409 | return CMD_WARNING; |
| 410 | } |
| 411 | |
| 412 | |
| 413 | if (set->pcap_fd >= 0 && bsc.pcap_fd != set->pcap_fd) |
| 414 | close(set->pcap_fd); |
| 415 | set->pcap_fd = open(argv[1], O_WRONLY | O_TRUNC | O_CREAT, |
| 416 | S_IRUSR | S_IWUSR | S_IRGRP| S_IROTH); |
| 417 | if (set->pcap_fd < 0) { |
| 418 | vty_out(vty, "Failed to open file for writing.%s", VTY_NEWLINE); |
| 419 | return CMD_WARNING; |
| 420 | } |
| 421 | |
| 422 | mtp_pcap_write_header(set->pcap_fd); |
| 423 | return CMD_SUCCESS; |
| 424 | } |
| 425 | |
| 426 | DEFUN(pcap_set_stop, pcap_set_stop_cmd, |
| 427 | "trace-pcap set <1-16383> stop", |
| 428 | "Trace to a PCAP file\n" "Trace a linkset\n" |
| 429 | "OPC for the linkset\n" "Stop the tracing\n") |
| 430 | { |
| 431 | struct mtp_link_set *set = NULL; |
| 432 | |
| 433 | if (bsc.link_set && strcmp(argv[0], "mtp") == 0) |
| 434 | set = bsc.link_set; |
| 435 | else if (bsc.m2ua_set && strcmp(argv[0], "m2ua") == 0) |
| 436 | set = bsc.m2ua_set; |
| 437 | |
| 438 | if (!set) { |
| 439 | vty_out(vty, "Failed to find linkset.%s", VTY_NEWLINE); |
| 440 | return CMD_WARNING; |
| 441 | } |
| 442 | |
| 443 | if (set->pcap_fd >= 0 && bsc.pcap_fd != set->pcap_fd) |
| 444 | close(set->pcap_fd); |
| 445 | set->pcap_fd = -1; |
| 446 | return CMD_SUCCESS; |
| 447 | } |
| 448 | |
Holger Hans Peter Freyther | 315ec67 | 2011-01-24 15:35:56 +0100 | [diff] [blame] | 449 | #define FIND_LINK(vty, type, nr) ({ \ |
| 450 | struct mtp_link_set *set = NULL; \ |
| 451 | struct mtp_link *link = NULL, *tmp; \ |
| 452 | if (strcmp(type, "mtp") == 0) \ |
| 453 | set = bsc.link_set; \ |
| 454 | else if (strcmp(type, "m2ua") == 0) \ |
| 455 | set = bsc.m2ua_set; \ |
| 456 | else { \ |
| 457 | vty_out(vty, "Unknown linkset %s.%s", type, VTY_NEWLINE); \ |
| 458 | return CMD_WARNING; \ |
| 459 | } \ |
| 460 | llist_for_each_entry(tmp, &set->links, entry) { \ |
| 461 | if (tmp->link_no == nr) { \ |
| 462 | link = tmp; \ |
| 463 | break; \ |
| 464 | } \ |
| 465 | } \ |
| 466 | if (!link) { \ |
| 467 | vty_out(vty, "Can not find link %d.%s", nr, VTY_NEWLINE); \ |
| 468 | return CMD_WARNING; \ |
| 469 | } \ |
| 470 | link; }) |
| 471 | |
| 472 | #define LINK_STR "Operations on the link\n" \ |
| 473 | "MTP Linkset\n" "M2UA Linkset\n" \ |
| 474 | "Link number\n" |
| 475 | |
| 476 | DEFUN(lnk_block, lnk_block_cmd, |
| 477 | "link (mtp|m2ua) <0-15> block", |
| 478 | LINK_STR "Block it\n") |
| 479 | { |
| 480 | struct mtp_link *link = FIND_LINK(vty, argv[0], atoi(argv[1])); |
| 481 | mtp_link_block(link); |
| 482 | return CMD_SUCCESS; |
| 483 | } |
| 484 | |
| 485 | DEFUN(lnk_unblock, lnk_unblock_cmd, |
| 486 | "link (mtp|m2ua) <0-15> unblock", |
| 487 | LINK_STR "Unblock it\n") |
| 488 | { |
| 489 | struct mtp_link *link = FIND_LINK(vty, argv[0], atoi(argv[1])); |
| 490 | mtp_link_unblock(link); |
| 491 | return CMD_SUCCESS; |
| 492 | } |
| 493 | |
| 494 | DEFUN(lnk_reset, lnk_reset_cmd, |
| 495 | "link (mtp|m2ua) <0-15> reset", |
| 496 | LINK_STR "Reset it\n") |
| 497 | { |
| 498 | struct mtp_link *link = FIND_LINK(vty, argv[0], atoi(argv[1])); |
| 499 | mtp_link_failure(link); |
| 500 | return CMD_SUCCESS; |
| 501 | } |
| 502 | |
| 503 | |
Holger Hans Peter Freyther | 5b2fe8d | 2011-01-22 21:09:53 +0100 | [diff] [blame] | 504 | |
Holger Hans Peter Freyther | 7942abc | 2010-09-30 00:34:46 +0800 | [diff] [blame] | 505 | void cell_vty_init(void) |
| 506 | { |
| 507 | cmd_init(1); |
| 508 | vty_init(&vty_info); |
Holger Hans Peter Freyther | fca7b12 | 2011-01-22 23:19:44 +0100 | [diff] [blame] | 509 | logging_vty_add_cmds(); |
Holger Hans Peter Freyther | 7942abc | 2010-09-30 00:34:46 +0800 | [diff] [blame] | 510 | |
| 511 | install_element(CONFIG_NODE, &cfg_cell_cmd); |
| 512 | install_node(&cell_node, config_write_cell); |
| 513 | |
| 514 | install_element(CELLMGR_NODE, &cfg_net_dpc_cmd); |
| 515 | install_element(CELLMGR_NODE, &cfg_net_opc_cmd); |
Holger Hans Peter Freyther | 7a72556 | 2011-01-01 13:34:58 +0100 | [diff] [blame] | 516 | install_element(CELLMGR_NODE, &cfg_net_sccp_opc_cmd); |
Holger Hans Peter Freyther | b38b33b | 2010-11-26 21:21:04 +0100 | [diff] [blame] | 517 | install_element(CELLMGR_NODE, &cfg_net_mtp_ni_cmd); |
| 518 | install_element(CELLMGR_NODE, &cfg_net_mtp_spare_cmd); |
Holger Hans Peter Freyther | 7942abc | 2010-09-30 00:34:46 +0800 | [diff] [blame] | 519 | install_element(CELLMGR_NODE, &cfg_udp_dst_ip_cmd); |
| 520 | install_element(CELLMGR_NODE, &cfg_udp_dst_port_cmd); |
| 521 | install_element(CELLMGR_NODE, &cfg_udp_src_port_cmd); |
| 522 | install_element(CELLMGR_NODE, &cfg_udp_reset_cmd); |
Holger Hans Peter Freyther | c6bfa27 | 2011-01-22 17:06:34 +0100 | [diff] [blame] | 523 | install_element(CELLMGR_NODE, &cfg_udp_nr_links_cmd); |
Holger Hans Peter Freyther | 7942abc | 2010-09-30 00:34:46 +0800 | [diff] [blame] | 524 | install_element(CELLMGR_NODE, &cfg_sltm_once_cmd); |
| 525 | install_element(CELLMGR_NODE, &cfg_msc_ip_cmd); |
| 526 | install_element(CELLMGR_NODE, &cfg_msc_token_cmd); |
| 527 | install_element(CELLMGR_NODE, &cfg_msc_ip_dscp_cmd); |
| 528 | install_element(CELLMGR_NODE, &cfg_msc_ip_tos_cmd); |
| 529 | install_element(CELLMGR_NODE, &cfg_ping_time_cmd); |
| 530 | install_element(CELLMGR_NODE, &cfg_pong_time_cmd); |
| 531 | install_element(CELLMGR_NODE, &cfg_msc_time_cmd); |
Holger Hans Peter Freyther | 0e4e35f | 2010-09-30 03:04:28 +0800 | [diff] [blame] | 532 | install_element(CELLMGR_NODE, &cfg_mcc_cmd); |
| 533 | install_element(CELLMGR_NODE, &cfg_mnc_cmd); |
| 534 | install_element(CELLMGR_NODE, &cfg_lac_cmd); |
Holger Hans Peter Freyther | 51b9e7a | 2011-01-22 16:02:13 +0100 | [diff] [blame] | 535 | |
Holger Hans Peter Freyther | 5b2fe8d | 2011-01-22 21:09:53 +0100 | [diff] [blame] | 536 | /* special commands */ |
| 537 | install_element(ENABLE_NODE, &pcap_set_cmd); |
| 538 | install_element(ENABLE_NODE, &pcap_set_stop_cmd); |
Holger Hans Peter Freyther | 315ec67 | 2011-01-24 15:35:56 +0100 | [diff] [blame] | 539 | install_element(ENABLE_NODE, &lnk_block_cmd); |
| 540 | install_element(ENABLE_NODE, &lnk_unblock_cmd); |
| 541 | install_element(ENABLE_NODE, &lnk_reset_cmd); |
Holger Hans Peter Freyther | 51b9e7a | 2011-01-22 16:02:13 +0100 | [diff] [blame] | 542 | |
| 543 | /* show commands */ |
| 544 | install_element_ve(&show_stats_cmd); |
Holger Hans Peter Freyther | 60af5dd | 2011-01-22 16:16:52 +0100 | [diff] [blame] | 545 | install_element_ve(&show_linksets_cmd); |
Holger Hans Peter Freyther | 3c2b84c | 2011-01-24 21:13:56 +0100 | [diff] [blame^] | 546 | install_element_ve(&show_slc_cmd); |
Holger Hans Peter Freyther | 0b31622 | 2011-01-22 16:43:14 +0100 | [diff] [blame] | 547 | |
| 548 | if (bsc.app != APP_STP) { |
| 549 | install_element_ve(&show_msc_cmd); |
| 550 | } |
Holger Hans Peter Freyther | 7942abc | 2010-09-30 00:34:46 +0800 | [diff] [blame] | 551 | } |
| 552 | |
| 553 | const char *openbsc_copyright = ""; |