blob: 30ba6037afad796231433c66b53c007656308ca4 [file] [log] [blame]
Neels Hofmeyr17518fe2017-06-20 04:35:06 +02001/*! \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 Welte4e5721d2010-05-17 23:41:43 +02005 *
6 * All Rights Reserved
7 *
8 * This program is free software; you can redistribute it and/or modify
Harald Welte7fa89c22014-10-26 20:33:09 +01009 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
Harald Welte4e5721d2010-05-17 23:41:43 +020011 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Harald Welte7fa89c22014-10-26 20:33:09 +010016 * GNU General Public License for more details.
Harald Welte4e5721d2010-05-17 23:41:43 +020017 *
Harald Welte7fa89c22014-10-26 20:33:09 +010018 * You should have received a copy of the GNU General Public License
Harald Weltee4cbb3f2011-01-01 15:25:50 +010019 * along with this program. If not, see <http://www.gnu.org/licenses/>.
Harald Welte4e5721d2010-05-17 23:41:43 +020020 *
21 */
22
23#include <stdlib.h>
24#include <unistd.h>
25#include <errno.h>
26#include <stdint.h>
27
28#include <arpa/inet.h>
29
Pablo Neira Ayusoff663232011-03-22 16:47:59 +010030#include <osmocom/core/msgb.h>
31#include <osmocom/gsm/tlv.h>
32#include <osmocom/core/talloc.h>
33#include <osmocom/core/select.h>
34#include <osmocom/core/rate_ctr.h>
Harald Welte73952e32012-06-16 14:59:56 +080035#include <osmocom/gprs/gprs_ns.h>
36#include <osmocom/gprs/gprs_bssgp.h>
Maxea507322016-03-31 21:40:26 +020037#include <osmocom/gprs/gprs_bssgp_bss.h>
Harald Welte4e5721d2010-05-17 23:41:43 +020038
Harald Welteac1a7152010-05-19 19:45:32 +020039#include <osmocom/vty/vty.h>
40#include <osmocom/vty/command.h>
41#include <osmocom/vty/logging.h>
42#include <osmocom/vty/telnet_interface.h>
Pablo Neira Ayuso167281e2011-03-28 19:35:00 +020043#include <osmocom/vty/misc.h>
Harald Welte4e5721d2010-05-17 23:41:43 +020044
Harald Welte4f5883b2012-06-16 16:54:06 +080045#include "common_vty.h"
Harald Welte73952e32012-06-16 14:59:56 +080046
Harald Weltef5430362012-06-17 12:25:53 +080047static void log_set_bvc_filter(struct log_target *target,
48 struct bssgp_bvc_ctx *bctx)
49{
50 if (bctx) {
Neels Hofmeyr8b86cd72017-02-23 18:03:28 +010051 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 Weltef5430362012-06-17 12:25:53 +080056 }
57}
58
Harald Welte4e5721d2010-05-17 23:41:43 +020059static struct cmd_node bssgp_node = {
Harald Welte4f5883b2012-06-16 16:54:06 +080060 L_BSSGP_NODE,
Neels Hofmeyr6f417672017-09-25 00:57:00 +020061 "%s(config-bssgp)# ",
Harald Welte4e5721d2010-05-17 23:41:43 +020062 1,
63};
64
65static int config_write_bssgp(struct vty *vty)
66{
67 vty_out(vty, "bssgp%s", VTY_NEWLINE);
68
69 return CMD_SUCCESS;
70}
71
72DEFUN(cfg_bssgp, cfg_bssgp_cmd,
73 "bssgp",
74 "Configure the GPRS BSS Gateway Protocol")
75{
Harald Welte4f5883b2012-06-16 16:54:06 +080076 vty->node = L_BSSGP_NODE;
Harald Welte4e5721d2010-05-17 23:41:43 +020077 return CMD_SUCCESS;
78}
79
80static void dump_bvc(struct vty *vty, struct bssgp_bvc_ctx *bvc, int stats)
81{
82 vty_out(vty, "NSEI %5u, BVCI %5u, RA-ID: %u-%u-%u-%u, CID: %u, "
Harald Weltebf03d902010-05-18 12:00:55 +020083 "STATE: %s%s", bvc->nsei, bvc->bvci, bvc->ra_id.mcc,
Harald Welte4e5721d2010-05-17 23:41:43 +020084 bvc->ra_id.mnc, bvc->ra_id.lac, bvc->ra_id.rac, bvc->cell_id,
85 bvc->state & BVC_S_BLOCKED ? "BLOCKED" : "UNBLOCKED",
86 VTY_NEWLINE);
Harald Welte0823e1e2012-09-07 12:13:09 +020087
88 if (stats) {
89 struct bssgp_flow_control *fc = bvc->fc;
90
Harald Welte4e5721d2010-05-17 23:41:43 +020091 vty_out_rate_ctr_group(vty, " ", bvc->ctrg);
Harald Welte0823e1e2012-09-07 12:13:09 +020092
93 if (fc)
94 vty_out(vty, "FC-BVC(bucket_max: %uoct, leak_rate: "
95 "%uoct/s, cur_tokens: %uoct, max_q_d: %u, "
Jacob Erlbeck1bda4422015-04-29 15:00:29 +020096 "cur_q_d: %u)%s", fc->bucket_size_max,
Harald Welte0823e1e2012-09-07 12:13:09 +020097 fc->bucket_leak_rate, fc->bucket_counter,
Jacob Erlbeck1bda4422015-04-29 15:00:29 +020098 fc->max_queue_depth, fc->queue_depth,
99 VTY_NEWLINE);
Harald Welte0823e1e2012-09-07 12:13:09 +0200100 }
Harald Welte4e5721d2010-05-17 23:41:43 +0200101}
102
103static void dump_bssgp(struct vty *vty, int stats)
104{
105 struct bssgp_bvc_ctx *bvc;
106
107 llist_for_each_entry(bvc, &bssgp_bvc_ctxts, list) {
108 dump_bvc(vty, bvc, stats);
109 }
110}
111
Maxea507322016-03-31 21:40:26 +0200112DEFUN(bvc_reset, bvc_reset_cmd,
Maxb9bb0b02016-04-07 11:01:52 +0200113 "bssgp bvc nsei <0-65535> bvci <0-65535> reset",
114 "Initiate BVC RESET procedure for a given NSEI and BVCI\n"
115 "Filter based on BSSGP Virtual Connection\n"
116 "NSEI of the BVC to be filtered\n"
117 "Network Service Entity Identifier (NSEI)\n"
118 "BVCI of the BVC to be filtered\n"
119 "BSSGP Virtual Connection Identifier (BVCI)\n"
120 "Perform reset procedure\n")
Maxea507322016-03-31 21:40:26 +0200121{
122 int r;
123 uint16_t nsei = atoi(argv[0]), bvci = atoi(argv[1]);
124 struct bssgp_bvc_ctx *bvc = btsctx_by_bvci_nsei(bvci, nsei);
125 if (!bvc) {
126 vty_out(vty, "No BVC for NSEI %d BVCI %d%s", nsei, bvci,
127 VTY_NEWLINE);
128 return CMD_WARNING;
129 }
130 r = bssgp_tx_bvc_reset(bvc, bvci, BSSGP_CAUSE_OML_INTERV);
131 vty_out(vty, "Sent BVC RESET for NSEI %d BVCI %d: %d%s", nsei, bvci, r,
132 VTY_NEWLINE);
133 return CMD_SUCCESS;
134}
135
Harald Welte4e5721d2010-05-17 23:41:43 +0200136#define BSSGP_STR "Show information about the BSSGP protocol\n"
137
138DEFUN(show_bssgp, show_bssgp_cmd, "show bssgp",
139 SHOW_STR BSSGP_STR)
140{
141 dump_bssgp(vty, 0);
142 return CMD_SUCCESS;
143}
144
145DEFUN(show_bssgp_stats, show_bssgp_stats_cmd, "show bssgp stats",
146 SHOW_STR BSSGP_STR
147 "Include statistics\n")
148{
149 dump_bssgp(vty, 1);
150 return CMD_SUCCESS;
151}
152
153DEFUN(show_bvc, show_bvc_cmd, "show bssgp nsei <0-65535> [stats]",
154 SHOW_STR BSSGP_STR
Harald Welte781b3e62010-06-10 00:20:12 +0200155 "Show all BVCs on one NSE\n"
Harald Welte4e5721d2010-05-17 23:41:43 +0200156 "The NSEI\n" "Include Statistics\n")
157{
158 struct bssgp_bvc_ctx *bvc;
Jacob Erlbeck0673b702014-11-10 08:27:15 +0100159 uint16_t nsei = atoi(argv[0]);
Harald Welte4e5721d2010-05-17 23:41:43 +0200160 int show_stats = 0;
161
162 if (argc >= 2)
163 show_stats = 1;
164
165 llist_for_each_entry(bvc, &bssgp_bvc_ctxts, list) {
166 if (bvc->nsei != nsei)
167 continue;
168 dump_bvc(vty, bvc, show_stats);
169 }
170
171 return CMD_SUCCESS;
172}
173
174DEFUN(logging_fltr_bvc,
175 logging_fltr_bvc_cmd,
176 "logging filter bvc nsei <0-65535> bvci <0-65535>",
177 LOGGING_STR FILTER_STR
178 "Filter based on BSSGP Virtual Connection\n"
179 "NSEI of the BVC to be filtered\n"
180 "Network Service Entity Identifier (NSEI)\n"
181 "BVCI of the BVC to be filtered\n"
182 "BSSGP Virtual Connection Identifier (BVCI)\n")
183{
Harald Welte43ae94e2011-02-18 21:10:05 +0100184 struct log_target *tgt = osmo_log_vty2tgt(vty);
Harald Welte4e5721d2010-05-17 23:41:43 +0200185 struct bssgp_bvc_ctx *bvc;
186 uint16_t nsei = atoi(argv[0]);
187 uint16_t bvci = atoi(argv[1]);
188
Harald Welte43ae94e2011-02-18 21:10:05 +0100189 if (!tgt)
Harald Welte4e5721d2010-05-17 23:41:43 +0200190 return CMD_WARNING;
Harald Welte4e5721d2010-05-17 23:41:43 +0200191
192 bvc = btsctx_by_bvci_nsei(bvci, nsei);
193 if (!bvc) {
194 vty_out(vty, "No BVC by that identifier%s", VTY_NEWLINE);
195 return CMD_WARNING;
196 }
197
Harald Welte43ae94e2011-02-18 21:10:05 +0100198 log_set_bvc_filter(tgt, bvc);
Harald Welte4e5721d2010-05-17 23:41:43 +0200199 return CMD_SUCCESS;
200}
201
Harald Weltede4599c2012-06-17 13:04:02 +0800202int bssgp_vty_init(void)
Harald Welte4e5721d2010-05-17 23:41:43 +0200203{
204 install_element_ve(&show_bssgp_cmd);
205 install_element_ve(&show_bssgp_stats_cmd);
206 install_element_ve(&show_bvc_cmd);
207 install_element_ve(&logging_fltr_bvc_cmd);
Maxea507322016-03-31 21:40:26 +0200208 install_element_ve(&bvc_reset_cmd);
Harald Welte4e5721d2010-05-17 23:41:43 +0200209
Harald Welte43ae94e2011-02-18 21:10:05 +0100210 install_element(CFG_LOG_NODE, &logging_fltr_bvc_cmd);
211
Harald Welte4e5721d2010-05-17 23:41:43 +0200212 install_element(CONFIG_NODE, &cfg_bssgp_cmd);
213 install_node(&bssgp_node, config_write_bssgp);
Harald Welte4f5883b2012-06-16 16:54:06 +0800214 install_default(L_BSSGP_NODE);
215 install_element(L_BSSGP_NODE, &libgb_exit_cmd);
216 install_element(L_BSSGP_NODE, &libgb_end_cmd);
Harald Welte4e5721d2010-05-17 23:41:43 +0200217
218 return 0;
219}