Neels Hofmeyr | 17518fe | 2017-06-20 04:35:06 +0200 | [diff] [blame] | 1 | /*! \file gprs_bssgp_vty.c |
| 2 | * VTY interface for our GPRS BSS Gateway Protocol (BSSGP) implementation. */ |
| 3 | /* |
| 4 | * (C) 2010 by Harald Welte <laforge@gnumonks.org> |
Harald Welte | 4e5721d | 2010-05-17 23:41:43 +0200 | [diff] [blame] | 5 | * |
| 6 | * All Rights Reserved |
| 7 | * |
Harald Welte | e08da97 | 2017-11-13 01:00:26 +0900 | [diff] [blame] | 8 | * SPDX-License-Identifier: GPL-2.0+ |
| 9 | * |
Harald Welte | 4e5721d | 2010-05-17 23:41:43 +0200 | [diff] [blame] | 10 | * This program is free software; you can redistribute it and/or modify |
Harald Welte | 7fa89c2 | 2014-10-26 20:33:09 +0100 | [diff] [blame] | 11 | * it under the terms of the GNU General Public License as published by |
| 12 | * the Free Software Foundation; either version 2 of the License, or |
Harald Welte | 4e5721d | 2010-05-17 23:41:43 +0200 | [diff] [blame] | 13 | * (at your option) any later version. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
Harald Welte | 7fa89c2 | 2014-10-26 20:33:09 +0100 | [diff] [blame] | 18 | * GNU General Public License for more details. |
Harald Welte | 4e5721d | 2010-05-17 23:41:43 +0200 | [diff] [blame] | 19 | * |
Harald Welte | 7fa89c2 | 2014-10-26 20:33:09 +0100 | [diff] [blame] | 20 | * You should have received a copy of the GNU General Public License |
Harald Welte | e4cbb3f | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 21 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
Harald Welte | 4e5721d | 2010-05-17 23:41:43 +0200 | [diff] [blame] | 22 | * |
| 23 | */ |
| 24 | |
| 25 | #include <stdlib.h> |
| 26 | #include <unistd.h> |
| 27 | #include <errno.h> |
| 28 | #include <stdint.h> |
| 29 | |
| 30 | #include <arpa/inet.h> |
| 31 | |
Pablo Neira Ayuso | ff66323 | 2011-03-22 16:47:59 +0100 | [diff] [blame] | 32 | #include <osmocom/core/msgb.h> |
| 33 | #include <osmocom/gsm/tlv.h> |
| 34 | #include <osmocom/core/talloc.h> |
| 35 | #include <osmocom/core/select.h> |
| 36 | #include <osmocom/core/rate_ctr.h> |
Harald Welte | 73952e3 | 2012-06-16 14:59:56 +0800 | [diff] [blame] | 37 | #include <osmocom/gprs/gprs_ns.h> |
| 38 | #include <osmocom/gprs/gprs_bssgp.h> |
Max | ea50732 | 2016-03-31 21:40:26 +0200 | [diff] [blame] | 39 | #include <osmocom/gprs/gprs_bssgp_bss.h> |
Harald Welte | 4e5721d | 2010-05-17 23:41:43 +0200 | [diff] [blame] | 40 | |
Harald Welte | ac1a715 | 2010-05-19 19:45:32 +0200 | [diff] [blame] | 41 | #include <osmocom/vty/vty.h> |
| 42 | #include <osmocom/vty/command.h> |
| 43 | #include <osmocom/vty/logging.h> |
| 44 | #include <osmocom/vty/telnet_interface.h> |
Pablo Neira Ayuso | 167281e | 2011-03-28 19:35:00 +0200 | [diff] [blame] | 45 | #include <osmocom/vty/misc.h> |
Harald Welte | 4e5721d | 2010-05-17 23:41:43 +0200 | [diff] [blame] | 46 | |
Harald Welte | f543036 | 2012-06-17 12:25:53 +0800 | [diff] [blame] | 47 | static void log_set_bvc_filter(struct log_target *target, |
| 48 | struct bssgp_bvc_ctx *bctx) |
| 49 | { |
| 50 | if (bctx) { |
Neels Hofmeyr | 8b86cd7 | 2017-02-23 18:03:28 +0100 | [diff] [blame] | 51 | target->filter_map |= (1 << LOG_FLT_GB_BVC); |
| 52 | target->filter_data[LOG_FLT_GB_BVC] = bctx; |
| 53 | } else if (target->filter_data[LOG_FLT_GB_BVC]) { |
| 54 | target->filter_map = ~(1 << LOG_FLT_GB_BVC); |
| 55 | target->filter_data[LOG_FLT_GB_BVC] = NULL; |
Harald Welte | f543036 | 2012-06-17 12:25:53 +0800 | [diff] [blame] | 56 | } |
| 57 | } |
| 58 | |
Harald Welte | 4e5721d | 2010-05-17 23:41:43 +0200 | [diff] [blame] | 59 | static struct cmd_node bssgp_node = { |
Harald Welte | 4f5883b | 2012-06-16 16:54:06 +0800 | [diff] [blame] | 60 | L_BSSGP_NODE, |
Neels Hofmeyr | 6f41767 | 2017-09-25 00:57:00 +0200 | [diff] [blame] | 61 | "%s(config-bssgp)# ", |
Harald Welte | 4e5721d | 2010-05-17 23:41:43 +0200 | [diff] [blame] | 62 | 1, |
| 63 | }; |
| 64 | |
| 65 | static int config_write_bssgp(struct vty *vty) |
| 66 | { |
| 67 | vty_out(vty, "bssgp%s", VTY_NEWLINE); |
| 68 | |
| 69 | return CMD_SUCCESS; |
| 70 | } |
| 71 | |
| 72 | DEFUN(cfg_bssgp, cfg_bssgp_cmd, |
| 73 | "bssgp", |
| 74 | "Configure the GPRS BSS Gateway Protocol") |
| 75 | { |
Harald Welte | 4f5883b | 2012-06-16 16:54:06 +0800 | [diff] [blame] | 76 | vty->node = L_BSSGP_NODE; |
Harald Welte | 4e5721d | 2010-05-17 23:41:43 +0200 | [diff] [blame] | 77 | return CMD_SUCCESS; |
| 78 | } |
| 79 | |
| 80 | static void dump_bvc(struct vty *vty, struct bssgp_bvc_ctx *bvc, int stats) |
| 81 | { |
Neels Hofmeyr | c4fce14 | 2018-02-20 13:47:08 +0100 | [diff] [blame] | 82 | vty_out(vty, "NSEI %5u, BVCI %5u, RA-ID: %s, CID: %u, " |
| 83 | "STATE: %s%s", bvc->nsei, bvc->bvci, osmo_rai_name(&bvc->ra_id), |
| 84 | bvc->cell_id, bvc->state & BVC_S_BLOCKED ? "BLOCKED" : "UNBLOCKED", VTY_NEWLINE); |
Harald Welte | 0823e1e | 2012-09-07 12:13:09 +0200 | [diff] [blame] | 85 | |
| 86 | if (stats) { |
| 87 | struct bssgp_flow_control *fc = bvc->fc; |
| 88 | |
Harald Welte | 4e5721d | 2010-05-17 23:41:43 +0200 | [diff] [blame] | 89 | vty_out_rate_ctr_group(vty, " ", bvc->ctrg); |
Harald Welte | 0823e1e | 2012-09-07 12:13:09 +0200 | [diff] [blame] | 90 | |
| 91 | if (fc) |
| 92 | vty_out(vty, "FC-BVC(bucket_max: %uoct, leak_rate: " |
| 93 | "%uoct/s, cur_tokens: %uoct, max_q_d: %u, " |
Jacob Erlbeck | 1bda442 | 2015-04-29 15:00:29 +0200 | [diff] [blame] | 94 | "cur_q_d: %u)%s", fc->bucket_size_max, |
Harald Welte | 0823e1e | 2012-09-07 12:13:09 +0200 | [diff] [blame] | 95 | fc->bucket_leak_rate, fc->bucket_counter, |
Jacob Erlbeck | 1bda442 | 2015-04-29 15:00:29 +0200 | [diff] [blame] | 96 | fc->max_queue_depth, fc->queue_depth, |
| 97 | VTY_NEWLINE); |
Harald Welte | 0823e1e | 2012-09-07 12:13:09 +0200 | [diff] [blame] | 98 | } |
Harald Welte | 4e5721d | 2010-05-17 23:41:43 +0200 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | static void dump_bssgp(struct vty *vty, int stats) |
| 102 | { |
| 103 | struct bssgp_bvc_ctx *bvc; |
| 104 | |
| 105 | llist_for_each_entry(bvc, &bssgp_bvc_ctxts, list) { |
| 106 | dump_bvc(vty, bvc, stats); |
| 107 | } |
| 108 | } |
| 109 | |
Max | ea50732 | 2016-03-31 21:40:26 +0200 | [diff] [blame] | 110 | DEFUN(bvc_reset, bvc_reset_cmd, |
Max | b9bb0b0 | 2016-04-07 11:01:52 +0200 | [diff] [blame] | 111 | "bssgp bvc nsei <0-65535> bvci <0-65535> reset", |
| 112 | "Initiate BVC RESET procedure for a given NSEI and BVCI\n" |
| 113 | "Filter based on BSSGP Virtual Connection\n" |
| 114 | "NSEI of the BVC to be filtered\n" |
| 115 | "Network Service Entity Identifier (NSEI)\n" |
| 116 | "BVCI of the BVC to be filtered\n" |
| 117 | "BSSGP Virtual Connection Identifier (BVCI)\n" |
| 118 | "Perform reset procedure\n") |
Max | ea50732 | 2016-03-31 21:40:26 +0200 | [diff] [blame] | 119 | { |
| 120 | int r; |
| 121 | uint16_t nsei = atoi(argv[0]), bvci = atoi(argv[1]); |
| 122 | struct bssgp_bvc_ctx *bvc = btsctx_by_bvci_nsei(bvci, nsei); |
| 123 | if (!bvc) { |
| 124 | vty_out(vty, "No BVC for NSEI %d BVCI %d%s", nsei, bvci, |
| 125 | VTY_NEWLINE); |
| 126 | return CMD_WARNING; |
| 127 | } |
| 128 | r = bssgp_tx_bvc_reset(bvc, bvci, BSSGP_CAUSE_OML_INTERV); |
| 129 | vty_out(vty, "Sent BVC RESET for NSEI %d BVCI %d: %d%s", nsei, bvci, r, |
| 130 | VTY_NEWLINE); |
| 131 | return CMD_SUCCESS; |
| 132 | } |
| 133 | |
Harald Welte | 4e5721d | 2010-05-17 23:41:43 +0200 | [diff] [blame] | 134 | #define BSSGP_STR "Show information about the BSSGP protocol\n" |
| 135 | |
| 136 | DEFUN(show_bssgp, show_bssgp_cmd, "show bssgp", |
| 137 | SHOW_STR BSSGP_STR) |
| 138 | { |
| 139 | dump_bssgp(vty, 0); |
| 140 | return CMD_SUCCESS; |
| 141 | } |
| 142 | |
| 143 | DEFUN(show_bssgp_stats, show_bssgp_stats_cmd, "show bssgp stats", |
| 144 | SHOW_STR BSSGP_STR |
| 145 | "Include statistics\n") |
| 146 | { |
| 147 | dump_bssgp(vty, 1); |
| 148 | return CMD_SUCCESS; |
| 149 | } |
| 150 | |
| 151 | DEFUN(show_bvc, show_bvc_cmd, "show bssgp nsei <0-65535> [stats]", |
| 152 | SHOW_STR BSSGP_STR |
Harald Welte | 781b3e6 | 2010-06-10 00:20:12 +0200 | [diff] [blame] | 153 | "Show all BVCs on one NSE\n" |
Harald Welte | 4e5721d | 2010-05-17 23:41:43 +0200 | [diff] [blame] | 154 | "The NSEI\n" "Include Statistics\n") |
| 155 | { |
| 156 | struct bssgp_bvc_ctx *bvc; |
Jacob Erlbeck | 0673b70 | 2014-11-10 08:27:15 +0100 | [diff] [blame] | 157 | uint16_t nsei = atoi(argv[0]); |
Harald Welte | 4e5721d | 2010-05-17 23:41:43 +0200 | [diff] [blame] | 158 | int show_stats = 0; |
| 159 | |
| 160 | if (argc >= 2) |
| 161 | show_stats = 1; |
| 162 | |
| 163 | llist_for_each_entry(bvc, &bssgp_bvc_ctxts, list) { |
| 164 | if (bvc->nsei != nsei) |
| 165 | continue; |
| 166 | dump_bvc(vty, bvc, show_stats); |
| 167 | } |
| 168 | |
| 169 | return CMD_SUCCESS; |
| 170 | } |
| 171 | |
| 172 | DEFUN(logging_fltr_bvc, |
| 173 | logging_fltr_bvc_cmd, |
| 174 | "logging filter bvc nsei <0-65535> bvci <0-65535>", |
| 175 | LOGGING_STR FILTER_STR |
| 176 | "Filter based on BSSGP Virtual Connection\n" |
| 177 | "NSEI of the BVC to be filtered\n" |
| 178 | "Network Service Entity Identifier (NSEI)\n" |
| 179 | "BVCI of the BVC to be filtered\n" |
| 180 | "BSSGP Virtual Connection Identifier (BVCI)\n") |
| 181 | { |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 182 | struct log_target *tgt; |
Harald Welte | 4e5721d | 2010-05-17 23:41:43 +0200 | [diff] [blame] | 183 | struct bssgp_bvc_ctx *bvc; |
| 184 | uint16_t nsei = atoi(argv[0]); |
| 185 | uint16_t bvci = atoi(argv[1]); |
| 186 | |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 187 | log_tgt_mutex_lock(); |
| 188 | tgt = osmo_log_vty2tgt(vty); |
| 189 | if (!tgt) { |
| 190 | log_tgt_mutex_unlock(); |
Harald Welte | 4e5721d | 2010-05-17 23:41:43 +0200 | [diff] [blame] | 191 | return CMD_WARNING; |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 192 | } |
Harald Welte | 4e5721d | 2010-05-17 23:41:43 +0200 | [diff] [blame] | 193 | |
| 194 | bvc = btsctx_by_bvci_nsei(bvci, nsei); |
| 195 | if (!bvc) { |
| 196 | vty_out(vty, "No BVC by that identifier%s", VTY_NEWLINE); |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 197 | log_tgt_mutex_unlock(); |
Harald Welte | 4e5721d | 2010-05-17 23:41:43 +0200 | [diff] [blame] | 198 | return CMD_WARNING; |
| 199 | } |
| 200 | |
Harald Welte | 43ae94e | 2011-02-18 21:10:05 +0100 | [diff] [blame] | 201 | log_set_bvc_filter(tgt, bvc); |
Pau Espin Pedrol | d12f698 | 2019-09-17 18:38:58 +0200 | [diff] [blame] | 202 | log_tgt_mutex_unlock(); |
Harald Welte | 4e5721d | 2010-05-17 23:41:43 +0200 | [diff] [blame] | 203 | return CMD_SUCCESS; |
| 204 | } |
| 205 | |
Harald Welte | de4599c | 2012-06-17 13:04:02 +0800 | [diff] [blame] | 206 | int bssgp_vty_init(void) |
Harald Welte | 4e5721d | 2010-05-17 23:41:43 +0200 | [diff] [blame] | 207 | { |
Vadim Yanitskiy | 8e7c496 | 2020-10-04 15:37:31 +0700 | [diff] [blame] | 208 | install_lib_element_ve(&show_bssgp_cmd); |
| 209 | install_lib_element_ve(&show_bssgp_stats_cmd); |
| 210 | install_lib_element_ve(&show_bvc_cmd); |
| 211 | install_lib_element_ve(&logging_fltr_bvc_cmd); |
| 212 | install_lib_element_ve(&bvc_reset_cmd); |
Harald Welte | 4e5721d | 2010-05-17 23:41:43 +0200 | [diff] [blame] | 213 | |
Vadim Yanitskiy | 8e7c496 | 2020-10-04 15:37:31 +0700 | [diff] [blame] | 214 | install_lib_element(CFG_LOG_NODE, &logging_fltr_bvc_cmd); |
Harald Welte | 43ae94e | 2011-02-18 21:10:05 +0100 | [diff] [blame] | 215 | |
Vadim Yanitskiy | 8e7c496 | 2020-10-04 15:37:31 +0700 | [diff] [blame] | 216 | install_lib_element(CONFIG_NODE, &cfg_bssgp_cmd); |
Harald Welte | 4e5721d | 2010-05-17 23:41:43 +0200 | [diff] [blame] | 217 | install_node(&bssgp_node, config_write_bssgp); |
Harald Welte | 4e5721d | 2010-05-17 23:41:43 +0200 | [diff] [blame] | 218 | |
| 219 | return 0; |
| 220 | } |