blob: f3f354cceddccf427513abc24a70b7857f62614b [file] [log] [blame]
Harald Welte4e5721d2010-05-17 23:41:43 +02001/* 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 Welte7fa89c22014-10-26 20:33:09 +01008 * 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 Welte4e5721d2010-05-17 23:41:43 +020010 * (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 Welte7fa89c22014-10-26 20:33:09 +010015 * GNU General Public License for more details.
Harald Welte4e5721d2010-05-17 23:41:43 +020016 *
Harald Welte7fa89c22014-10-26 20:33:09 +010017 * You should have received a copy of the GNU General Public License
Harald Weltee4cbb3f2011-01-01 15:25:50 +010018 * along with this program. If not, see <http://www.gnu.org/licenses/>.
Harald Welte4e5721d2010-05-17 23:41:43 +020019 *
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 Ayusoff663232011-03-22 16:47:59 +010029#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 Welte73952e32012-06-16 14:59:56 +080034#include <osmocom/gprs/gprs_ns.h>
35#include <osmocom/gprs/gprs_bssgp.h>
Maxea507322016-03-31 21:40:26 +020036#include <osmocom/gprs/gprs_bssgp_bss.h>
Harald Welte4e5721d2010-05-17 23:41:43 +020037
Harald Welteac1a7152010-05-19 19:45:32 +020038#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 Ayuso167281e2011-03-28 19:35:00 +020042#include <osmocom/vty/misc.h>
Harald Welte4e5721d2010-05-17 23:41:43 +020043
Harald Welte4f5883b2012-06-16 16:54:06 +080044#include "common_vty.h"
Harald Welte73952e32012-06-16 14:59:56 +080045
Harald Weltef5430362012-06-17 12:25:53 +080046static void log_set_bvc_filter(struct log_target *target,
47 struct bssgp_bvc_ctx *bctx)
48{
49 if (bctx) {
Neels Hofmeyr8b86cd72017-02-23 18:03:28 +010050 target->filter_map |= (1 << LOG_FLT_GB_BVC);
51 target->filter_data[LOG_FLT_GB_BVC] = bctx;
52 } else if (target->filter_data[LOG_FLT_GB_BVC]) {
53 target->filter_map = ~(1 << LOG_FLT_GB_BVC);
54 target->filter_data[LOG_FLT_GB_BVC] = NULL;
Harald Weltef5430362012-06-17 12:25:53 +080055 }
56}
57
Harald Welte4e5721d2010-05-17 23:41:43 +020058static struct cmd_node bssgp_node = {
Harald Welte4f5883b2012-06-16 16:54:06 +080059 L_BSSGP_NODE,
Harald Welte4e5721d2010-05-17 23:41:43 +020060 "%s(bssgp)#",
61 1,
62};
63
64static int config_write_bssgp(struct vty *vty)
65{
66 vty_out(vty, "bssgp%s", VTY_NEWLINE);
67
68 return CMD_SUCCESS;
69}
70
71DEFUN(cfg_bssgp, cfg_bssgp_cmd,
72 "bssgp",
73 "Configure the GPRS BSS Gateway Protocol")
74{
Harald Welte4f5883b2012-06-16 16:54:06 +080075 vty->node = L_BSSGP_NODE;
Harald Welte4e5721d2010-05-17 23:41:43 +020076 return CMD_SUCCESS;
77}
78
79static void dump_bvc(struct vty *vty, struct bssgp_bvc_ctx *bvc, int stats)
80{
81 vty_out(vty, "NSEI %5u, BVCI %5u, RA-ID: %u-%u-%u-%u, CID: %u, "
Harald Weltebf03d902010-05-18 12:00:55 +020082 "STATE: %s%s", bvc->nsei, bvc->bvci, bvc->ra_id.mcc,
Harald Welte4e5721d2010-05-17 23:41:43 +020083 bvc->ra_id.mnc, bvc->ra_id.lac, bvc->ra_id.rac, bvc->cell_id,
84 bvc->state & BVC_S_BLOCKED ? "BLOCKED" : "UNBLOCKED",
85 VTY_NEWLINE);
Harald Welte0823e1e2012-09-07 12:13:09 +020086
87 if (stats) {
88 struct bssgp_flow_control *fc = bvc->fc;
89
Harald Welte4e5721d2010-05-17 23:41:43 +020090 vty_out_rate_ctr_group(vty, " ", bvc->ctrg);
Harald Welte0823e1e2012-09-07 12:13:09 +020091
92 if (fc)
93 vty_out(vty, "FC-BVC(bucket_max: %uoct, leak_rate: "
94 "%uoct/s, cur_tokens: %uoct, max_q_d: %u, "
Jacob Erlbeck1bda4422015-04-29 15:00:29 +020095 "cur_q_d: %u)%s", fc->bucket_size_max,
Harald Welte0823e1e2012-09-07 12:13:09 +020096 fc->bucket_leak_rate, fc->bucket_counter,
Jacob Erlbeck1bda4422015-04-29 15:00:29 +020097 fc->max_queue_depth, fc->queue_depth,
98 VTY_NEWLINE);
Harald Welte0823e1e2012-09-07 12:13:09 +020099 }
Harald Welte4e5721d2010-05-17 23:41:43 +0200100}
101
102static void dump_bssgp(struct vty *vty, int stats)
103{
104 struct bssgp_bvc_ctx *bvc;
105
106 llist_for_each_entry(bvc, &bssgp_bvc_ctxts, list) {
107 dump_bvc(vty, bvc, stats);
108 }
109}
110
Maxea507322016-03-31 21:40:26 +0200111DEFUN(bvc_reset, bvc_reset_cmd,
Maxb9bb0b02016-04-07 11:01:52 +0200112 "bssgp bvc nsei <0-65535> bvci <0-65535> reset",
113 "Initiate BVC RESET procedure for a given NSEI and BVCI\n"
114 "Filter based on BSSGP Virtual Connection\n"
115 "NSEI of the BVC to be filtered\n"
116 "Network Service Entity Identifier (NSEI)\n"
117 "BVCI of the BVC to be filtered\n"
118 "BSSGP Virtual Connection Identifier (BVCI)\n"
119 "Perform reset procedure\n")
Maxea507322016-03-31 21:40:26 +0200120{
121 int r;
122 uint16_t nsei = atoi(argv[0]), bvci = atoi(argv[1]);
123 struct bssgp_bvc_ctx *bvc = btsctx_by_bvci_nsei(bvci, nsei);
124 if (!bvc) {
125 vty_out(vty, "No BVC for NSEI %d BVCI %d%s", nsei, bvci,
126 VTY_NEWLINE);
127 return CMD_WARNING;
128 }
129 r = bssgp_tx_bvc_reset(bvc, bvci, BSSGP_CAUSE_OML_INTERV);
130 vty_out(vty, "Sent BVC RESET for NSEI %d BVCI %d: %d%s", nsei, bvci, r,
131 VTY_NEWLINE);
132 return CMD_SUCCESS;
133}
134
Harald Welte4e5721d2010-05-17 23:41:43 +0200135#define BSSGP_STR "Show information about the BSSGP protocol\n"
136
137DEFUN(show_bssgp, show_bssgp_cmd, "show bssgp",
138 SHOW_STR BSSGP_STR)
139{
140 dump_bssgp(vty, 0);
141 return CMD_SUCCESS;
142}
143
144DEFUN(show_bssgp_stats, show_bssgp_stats_cmd, "show bssgp stats",
145 SHOW_STR BSSGP_STR
146 "Include statistics\n")
147{
148 dump_bssgp(vty, 1);
149 return CMD_SUCCESS;
150}
151
152DEFUN(show_bvc, show_bvc_cmd, "show bssgp nsei <0-65535> [stats]",
153 SHOW_STR BSSGP_STR
Harald Welte781b3e62010-06-10 00:20:12 +0200154 "Show all BVCs on one NSE\n"
Harald Welte4e5721d2010-05-17 23:41:43 +0200155 "The NSEI\n" "Include Statistics\n")
156{
157 struct bssgp_bvc_ctx *bvc;
Jacob Erlbeck0673b702014-11-10 08:27:15 +0100158 uint16_t nsei = atoi(argv[0]);
Harald Welte4e5721d2010-05-17 23:41:43 +0200159 int show_stats = 0;
160
161 if (argc >= 2)
162 show_stats = 1;
163
164 llist_for_each_entry(bvc, &bssgp_bvc_ctxts, list) {
165 if (bvc->nsei != nsei)
166 continue;
167 dump_bvc(vty, bvc, show_stats);
168 }
169
170 return CMD_SUCCESS;
171}
172
173DEFUN(logging_fltr_bvc,
174 logging_fltr_bvc_cmd,
175 "logging filter bvc nsei <0-65535> bvci <0-65535>",
176 LOGGING_STR FILTER_STR
177 "Filter based on BSSGP Virtual Connection\n"
178 "NSEI of the BVC to be filtered\n"
179 "Network Service Entity Identifier (NSEI)\n"
180 "BVCI of the BVC to be filtered\n"
181 "BSSGP Virtual Connection Identifier (BVCI)\n")
182{
Harald Welte43ae94e2011-02-18 21:10:05 +0100183 struct log_target *tgt = osmo_log_vty2tgt(vty);
Harald Welte4e5721d2010-05-17 23:41:43 +0200184 struct bssgp_bvc_ctx *bvc;
185 uint16_t nsei = atoi(argv[0]);
186 uint16_t bvci = atoi(argv[1]);
187
Harald Welte43ae94e2011-02-18 21:10:05 +0100188 if (!tgt)
Harald Welte4e5721d2010-05-17 23:41:43 +0200189 return CMD_WARNING;
Harald Welte4e5721d2010-05-17 23:41:43 +0200190
191 bvc = btsctx_by_bvci_nsei(bvci, nsei);
192 if (!bvc) {
193 vty_out(vty, "No BVC by that identifier%s", VTY_NEWLINE);
194 return CMD_WARNING;
195 }
196
Harald Welte43ae94e2011-02-18 21:10:05 +0100197 log_set_bvc_filter(tgt, bvc);
Harald Welte4e5721d2010-05-17 23:41:43 +0200198 return CMD_SUCCESS;
199}
200
Harald Weltede4599c2012-06-17 13:04:02 +0800201int bssgp_vty_init(void)
Harald Welte4e5721d2010-05-17 23:41:43 +0200202{
203 install_element_ve(&show_bssgp_cmd);
204 install_element_ve(&show_bssgp_stats_cmd);
205 install_element_ve(&show_bvc_cmd);
206 install_element_ve(&logging_fltr_bvc_cmd);
Maxea507322016-03-31 21:40:26 +0200207 install_element_ve(&bvc_reset_cmd);
Harald Welte4e5721d2010-05-17 23:41:43 +0200208
Harald Welte43ae94e2011-02-18 21:10:05 +0100209 install_element(CFG_LOG_NODE, &logging_fltr_bvc_cmd);
210
Harald Welte4e5721d2010-05-17 23:41:43 +0200211 install_element(CONFIG_NODE, &cfg_bssgp_cmd);
212 install_node(&bssgp_node, config_write_bssgp);
Harald Welte4f5883b2012-06-16 16:54:06 +0800213 install_default(L_BSSGP_NODE);
214 install_element(L_BSSGP_NODE, &libgb_exit_cmd);
215 install_element(L_BSSGP_NODE, &libgb_end_cmd);
Harald Welte4e5721d2010-05-17 23:41:43 +0200216
217 return 0;
218}