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 | e4cbb3f | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 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 |
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 | e4cbb3f | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 15 | * GNU Affero General Public License for more details. |
Harald Welte | 4e5721d | 2010-05-17 23:41:43 +0200 | [diff] [blame] | 16 | * |
Harald Welte | e4cbb3f | 2011-01-01 15:25:50 +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/>. |
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> |
Harald Welte | 4e5721d | 2010-05-17 23:41:43 +0200 | [diff] [blame] | 36 | |
Harald Welte | ac1a715 | 2010-05-19 19:45:32 +0200 | [diff] [blame] | 37 | #include <osmocom/vty/vty.h> |
| 38 | #include <osmocom/vty/command.h> |
| 39 | #include <osmocom/vty/logging.h> |
| 40 | #include <osmocom/vty/telnet_interface.h> |
Pablo Neira Ayuso | 167281e | 2011-03-28 19:35:00 +0200 | [diff] [blame] | 41 | #include <osmocom/vty/misc.h> |
Harald Welte | 4e5721d | 2010-05-17 23:41:43 +0200 | [diff] [blame] | 42 | |
Harald Welte | 4f5883b | 2012-06-16 16:54:06 +0800 | [diff] [blame] | 43 | #include "common_vty.h" |
Harald Welte | 73952e3 | 2012-06-16 14:59:56 +0800 | [diff] [blame] | 44 | |
Harald Welte | 4e5721d | 2010-05-17 23:41:43 +0200 | [diff] [blame] | 45 | /* FIXME: this should go to some common file as it is copied |
| 46 | * in vty_interface.c of the BSC */ |
| 47 | static const struct value_string gprs_bssgp_timer_strs[] = { |
| 48 | { 0, NULL } |
| 49 | }; |
| 50 | |
Harald Welte | f543036 | 2012-06-17 12:25:53 +0800 | [diff] [blame] | 51 | static void log_set_bvc_filter(struct log_target *target, |
| 52 | struct bssgp_bvc_ctx *bctx) |
| 53 | { |
| 54 | if (bctx) { |
| 55 | target->filter_map |= (1 << FLT_BVC); |
| 56 | target->filter_data[FLT_BVC] = bctx; |
| 57 | } else if (target->filter_data[FLT_NSVC]) { |
| 58 | target->filter_map = ~(1 << FLT_BVC); |
| 59 | target->filter_data[FLT_BVC] = NULL; |
| 60 | } |
| 61 | } |
| 62 | |
Harald Welte | 4e5721d | 2010-05-17 23:41:43 +0200 | [diff] [blame] | 63 | static struct cmd_node bssgp_node = { |
Harald Welte | 4f5883b | 2012-06-16 16:54:06 +0800 | [diff] [blame] | 64 | L_BSSGP_NODE, |
Harald Welte | 4e5721d | 2010-05-17 23:41:43 +0200 | [diff] [blame] | 65 | "%s(bssgp)#", |
| 66 | 1, |
| 67 | }; |
| 68 | |
| 69 | static int config_write_bssgp(struct vty *vty) |
| 70 | { |
| 71 | vty_out(vty, "bssgp%s", VTY_NEWLINE); |
| 72 | |
| 73 | return CMD_SUCCESS; |
| 74 | } |
| 75 | |
| 76 | DEFUN(cfg_bssgp, cfg_bssgp_cmd, |
| 77 | "bssgp", |
| 78 | "Configure the GPRS BSS Gateway Protocol") |
| 79 | { |
Harald Welte | 4f5883b | 2012-06-16 16:54:06 +0800 | [diff] [blame] | 80 | vty->node = L_BSSGP_NODE; |
Harald Welte | 4e5721d | 2010-05-17 23:41:43 +0200 | [diff] [blame] | 81 | return CMD_SUCCESS; |
| 82 | } |
| 83 | |
| 84 | static void dump_bvc(struct vty *vty, struct bssgp_bvc_ctx *bvc, int stats) |
| 85 | { |
| 86 | 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] | 87 | "STATE: %s%s", bvc->nsei, bvc->bvci, bvc->ra_id.mcc, |
Harald Welte | 4e5721d | 2010-05-17 23:41:43 +0200 | [diff] [blame] | 88 | bvc->ra_id.mnc, bvc->ra_id.lac, bvc->ra_id.rac, bvc->cell_id, |
| 89 | bvc->state & BVC_S_BLOCKED ? "BLOCKED" : "UNBLOCKED", |
| 90 | VTY_NEWLINE); |
| 91 | if (stats) |
| 92 | vty_out_rate_ctr_group(vty, " ", bvc->ctrg); |
| 93 | } |
| 94 | |
| 95 | static void dump_bssgp(struct vty *vty, int stats) |
| 96 | { |
| 97 | struct bssgp_bvc_ctx *bvc; |
| 98 | |
| 99 | llist_for_each_entry(bvc, &bssgp_bvc_ctxts, list) { |
| 100 | dump_bvc(vty, bvc, stats); |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | #define BSSGP_STR "Show information about the BSSGP protocol\n" |
| 105 | |
| 106 | DEFUN(show_bssgp, show_bssgp_cmd, "show bssgp", |
| 107 | SHOW_STR BSSGP_STR) |
| 108 | { |
| 109 | dump_bssgp(vty, 0); |
| 110 | return CMD_SUCCESS; |
| 111 | } |
| 112 | |
| 113 | DEFUN(show_bssgp_stats, show_bssgp_stats_cmd, "show bssgp stats", |
| 114 | SHOW_STR BSSGP_STR |
| 115 | "Include statistics\n") |
| 116 | { |
| 117 | dump_bssgp(vty, 1); |
| 118 | return CMD_SUCCESS; |
| 119 | } |
| 120 | |
| 121 | DEFUN(show_bvc, show_bvc_cmd, "show bssgp nsei <0-65535> [stats]", |
| 122 | SHOW_STR BSSGP_STR |
Harald Welte | 781b3e6 | 2010-06-10 00:20:12 +0200 | [diff] [blame] | 123 | "Show all BVCs on one NSE\n" |
Harald Welte | 4e5721d | 2010-05-17 23:41:43 +0200 | [diff] [blame] | 124 | "The NSEI\n" "Include Statistics\n") |
| 125 | { |
| 126 | struct bssgp_bvc_ctx *bvc; |
| 127 | uint16_t nsei = atoi(argv[1]); |
| 128 | int show_stats = 0; |
| 129 | |
| 130 | if (argc >= 2) |
| 131 | show_stats = 1; |
| 132 | |
| 133 | llist_for_each_entry(bvc, &bssgp_bvc_ctxts, list) { |
| 134 | if (bvc->nsei != nsei) |
| 135 | continue; |
| 136 | dump_bvc(vty, bvc, show_stats); |
| 137 | } |
| 138 | |
| 139 | return CMD_SUCCESS; |
| 140 | } |
| 141 | |
| 142 | DEFUN(logging_fltr_bvc, |
| 143 | logging_fltr_bvc_cmd, |
| 144 | "logging filter bvc nsei <0-65535> bvci <0-65535>", |
| 145 | LOGGING_STR FILTER_STR |
| 146 | "Filter based on BSSGP Virtual Connection\n" |
| 147 | "NSEI of the BVC to be filtered\n" |
| 148 | "Network Service Entity Identifier (NSEI)\n" |
| 149 | "BVCI of the BVC to be filtered\n" |
| 150 | "BSSGP Virtual Connection Identifier (BVCI)\n") |
| 151 | { |
Harald Welte | 43ae94e | 2011-02-18 21:10:05 +0100 | [diff] [blame] | 152 | struct log_target *tgt = osmo_log_vty2tgt(vty); |
Harald Welte | 4e5721d | 2010-05-17 23:41:43 +0200 | [diff] [blame] | 153 | struct bssgp_bvc_ctx *bvc; |
| 154 | uint16_t nsei = atoi(argv[0]); |
| 155 | uint16_t bvci = atoi(argv[1]); |
| 156 | |
Harald Welte | 43ae94e | 2011-02-18 21:10:05 +0100 | [diff] [blame] | 157 | if (!tgt) |
Harald Welte | 4e5721d | 2010-05-17 23:41:43 +0200 | [diff] [blame] | 158 | return CMD_WARNING; |
Harald Welte | 4e5721d | 2010-05-17 23:41:43 +0200 | [diff] [blame] | 159 | |
| 160 | bvc = btsctx_by_bvci_nsei(bvci, nsei); |
| 161 | if (!bvc) { |
| 162 | vty_out(vty, "No BVC by that identifier%s", VTY_NEWLINE); |
| 163 | return CMD_WARNING; |
| 164 | } |
| 165 | |
Harald Welte | 43ae94e | 2011-02-18 21:10:05 +0100 | [diff] [blame] | 166 | log_set_bvc_filter(tgt, bvc); |
Harald Welte | 4e5721d | 2010-05-17 23:41:43 +0200 | [diff] [blame] | 167 | return CMD_SUCCESS; |
| 168 | } |
| 169 | |
Harald Welte | de4599c | 2012-06-17 13:04:02 +0800 | [diff] [blame] | 170 | int bssgp_vty_init(void) |
Harald Welte | 4e5721d | 2010-05-17 23:41:43 +0200 | [diff] [blame] | 171 | { |
| 172 | install_element_ve(&show_bssgp_cmd); |
| 173 | install_element_ve(&show_bssgp_stats_cmd); |
| 174 | install_element_ve(&show_bvc_cmd); |
| 175 | install_element_ve(&logging_fltr_bvc_cmd); |
| 176 | |
Harald Welte | 43ae94e | 2011-02-18 21:10:05 +0100 | [diff] [blame] | 177 | install_element(CFG_LOG_NODE, &logging_fltr_bvc_cmd); |
| 178 | |
Harald Welte | 4e5721d | 2010-05-17 23:41:43 +0200 | [diff] [blame] | 179 | install_element(CONFIG_NODE, &cfg_bssgp_cmd); |
| 180 | install_node(&bssgp_node, config_write_bssgp); |
Harald Welte | 4f5883b | 2012-06-16 16:54:06 +0800 | [diff] [blame] | 181 | install_default(L_BSSGP_NODE); |
| 182 | install_element(L_BSSGP_NODE, &libgb_exit_cmd); |
| 183 | install_element(L_BSSGP_NODE, &libgb_end_cmd); |
| 184 | //install_element(L_BSSGP_NODE, &cfg_bssgp_timer_cmd); |
Harald Welte | 4e5721d | 2010-05-17 23:41:43 +0200 | [diff] [blame] | 185 | |
| 186 | return 0; |
| 187 | } |