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