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