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