blob: 6131e6b19a0e296e6528dc848812ea85c624ea22 [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 *
Harald Weltee08da972017-11-13 01:00:26 +09008 * SPDX-License-Identifier: GPL-2.0+
9 *
Harald Welte4e5721d2010-05-17 23:41:43 +020010 * This program is free software; you can redistribute it and/or modify
Harald Welte7fa89c22014-10-26 20:33:09 +010011 * 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 Welte4e5721d2010-05-17 23:41:43 +020013 * (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 Welte7fa89c22014-10-26 20:33:09 +010018 * GNU General Public License for more details.
Harald Welte4e5721d2010-05-17 23:41:43 +020019 *
Harald Welte7fa89c22014-10-26 20:33:09 +010020 * You should have received a copy of the GNU General Public License
Harald Weltee4cbb3f2011-01-01 15:25:50 +010021 * along with this program. If not, see <http://www.gnu.org/licenses/>.
Harald Welte4e5721d2010-05-17 23:41:43 +020022 *
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 Ayusoff663232011-03-22 16:47:59 +010032#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 Welte73952e32012-06-16 14:59:56 +080037#include <osmocom/gprs/gprs_ns.h>
38#include <osmocom/gprs/gprs_bssgp.h>
Maxea507322016-03-31 21:40:26 +020039#include <osmocom/gprs/gprs_bssgp_bss.h>
Harald Welte4e5721d2010-05-17 23:41:43 +020040
Harald Welteac1a7152010-05-19 19:45:32 +020041#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 Ayuso167281e2011-03-28 19:35:00 +020045#include <osmocom/vty/misc.h>
Harald Welte4e5721d2010-05-17 23:41:43 +020046
Harald Welte4f5883b2012-06-16 16:54:06 +080047#include "common_vty.h"
Harald Welte73952e32012-06-16 14:59:56 +080048
Harald Weltef5430362012-06-17 12:25:53 +080049static void log_set_bvc_filter(struct log_target *target,
50 struct bssgp_bvc_ctx *bctx)
51{
52 if (bctx) {
Neels Hofmeyr8b86cd72017-02-23 18:03:28 +010053 target->filter_map |= (1 << LOG_FLT_GB_BVC);
54 target->filter_data[LOG_FLT_GB_BVC] = bctx;
55 } else if (target->filter_data[LOG_FLT_GB_BVC]) {
56 target->filter_map = ~(1 << LOG_FLT_GB_BVC);
57 target->filter_data[LOG_FLT_GB_BVC] = NULL;
Harald Weltef5430362012-06-17 12:25:53 +080058 }
59}
60
Harald Welte4e5721d2010-05-17 23:41:43 +020061static struct cmd_node bssgp_node = {
Harald Welte4f5883b2012-06-16 16:54:06 +080062 L_BSSGP_NODE,
Neels Hofmeyr6f417672017-09-25 00:57:00 +020063 "%s(config-bssgp)# ",
Harald Welte4e5721d2010-05-17 23:41:43 +020064 1,
65};
66
67static int config_write_bssgp(struct vty *vty)
68{
69 vty_out(vty, "bssgp%s", VTY_NEWLINE);
70
71 return CMD_SUCCESS;
72}
73
74DEFUN(cfg_bssgp, cfg_bssgp_cmd,
75 "bssgp",
76 "Configure the GPRS BSS Gateway Protocol")
77{
Harald Welte4f5883b2012-06-16 16:54:06 +080078 vty->node = L_BSSGP_NODE;
Harald Welte4e5721d2010-05-17 23:41:43 +020079 return CMD_SUCCESS;
80}
81
82static void dump_bvc(struct vty *vty, struct bssgp_bvc_ctx *bvc, int stats)
83{
84 vty_out(vty, "NSEI %5u, BVCI %5u, RA-ID: %u-%u-%u-%u, CID: %u, "
Harald Weltebf03d902010-05-18 12:00:55 +020085 "STATE: %s%s", bvc->nsei, bvc->bvci, bvc->ra_id.mcc,
Harald Welte4e5721d2010-05-17 23:41:43 +020086 bvc->ra_id.mnc, bvc->ra_id.lac, bvc->ra_id.rac, bvc->cell_id,
87 bvc->state & BVC_S_BLOCKED ? "BLOCKED" : "UNBLOCKED",
88 VTY_NEWLINE);
Harald Welte0823e1e2012-09-07 12:13:09 +020089
90 if (stats) {
91 struct bssgp_flow_control *fc = bvc->fc;
92
Harald Welte4e5721d2010-05-17 23:41:43 +020093 vty_out_rate_ctr_group(vty, " ", bvc->ctrg);
Harald Welte0823e1e2012-09-07 12:13:09 +020094
95 if (fc)
96 vty_out(vty, "FC-BVC(bucket_max: %uoct, leak_rate: "
97 "%uoct/s, cur_tokens: %uoct, max_q_d: %u, "
Jacob Erlbeck1bda4422015-04-29 15:00:29 +020098 "cur_q_d: %u)%s", fc->bucket_size_max,
Harald Welte0823e1e2012-09-07 12:13:09 +020099 fc->bucket_leak_rate, fc->bucket_counter,
Jacob Erlbeck1bda4422015-04-29 15:00:29 +0200100 fc->max_queue_depth, fc->queue_depth,
101 VTY_NEWLINE);
Harald Welte0823e1e2012-09-07 12:13:09 +0200102 }
Harald Welte4e5721d2010-05-17 23:41:43 +0200103}
104
105static void dump_bssgp(struct vty *vty, int stats)
106{
107 struct bssgp_bvc_ctx *bvc;
108
109 llist_for_each_entry(bvc, &bssgp_bvc_ctxts, list) {
110 dump_bvc(vty, bvc, stats);
111 }
112}
113
Maxea507322016-03-31 21:40:26 +0200114DEFUN(bvc_reset, bvc_reset_cmd,
Maxb9bb0b02016-04-07 11:01:52 +0200115 "bssgp bvc nsei <0-65535> bvci <0-65535> reset",
116 "Initiate BVC RESET procedure for a given NSEI and BVCI\n"
117 "Filter based on BSSGP Virtual Connection\n"
118 "NSEI of the BVC to be filtered\n"
119 "Network Service Entity Identifier (NSEI)\n"
120 "BVCI of the BVC to be filtered\n"
121 "BSSGP Virtual Connection Identifier (BVCI)\n"
122 "Perform reset procedure\n")
Maxea507322016-03-31 21:40:26 +0200123{
124 int r;
125 uint16_t nsei = atoi(argv[0]), bvci = atoi(argv[1]);
126 struct bssgp_bvc_ctx *bvc = btsctx_by_bvci_nsei(bvci, nsei);
127 if (!bvc) {
128 vty_out(vty, "No BVC for NSEI %d BVCI %d%s", nsei, bvci,
129 VTY_NEWLINE);
130 return CMD_WARNING;
131 }
132 r = bssgp_tx_bvc_reset(bvc, bvci, BSSGP_CAUSE_OML_INTERV);
133 vty_out(vty, "Sent BVC RESET for NSEI %d BVCI %d: %d%s", nsei, bvci, r,
134 VTY_NEWLINE);
135 return CMD_SUCCESS;
136}
137
Harald Welte4e5721d2010-05-17 23:41:43 +0200138#define BSSGP_STR "Show information about the BSSGP protocol\n"
139
140DEFUN(show_bssgp, show_bssgp_cmd, "show bssgp",
141 SHOW_STR BSSGP_STR)
142{
143 dump_bssgp(vty, 0);
144 return CMD_SUCCESS;
145}
146
147DEFUN(show_bssgp_stats, show_bssgp_stats_cmd, "show bssgp stats",
148 SHOW_STR BSSGP_STR
149 "Include statistics\n")
150{
151 dump_bssgp(vty, 1);
152 return CMD_SUCCESS;
153}
154
155DEFUN(show_bvc, show_bvc_cmd, "show bssgp nsei <0-65535> [stats]",
156 SHOW_STR BSSGP_STR
Harald Welte781b3e62010-06-10 00:20:12 +0200157 "Show all BVCs on one NSE\n"
Harald Welte4e5721d2010-05-17 23:41:43 +0200158 "The NSEI\n" "Include Statistics\n")
159{
160 struct bssgp_bvc_ctx *bvc;
Jacob Erlbeck0673b702014-11-10 08:27:15 +0100161 uint16_t nsei = atoi(argv[0]);
Harald Welte4e5721d2010-05-17 23:41:43 +0200162 int show_stats = 0;
163
164 if (argc >= 2)
165 show_stats = 1;
166
167 llist_for_each_entry(bvc, &bssgp_bvc_ctxts, list) {
168 if (bvc->nsei != nsei)
169 continue;
170 dump_bvc(vty, bvc, show_stats);
171 }
172
173 return CMD_SUCCESS;
174}
175
176DEFUN(logging_fltr_bvc,
177 logging_fltr_bvc_cmd,
178 "logging filter bvc nsei <0-65535> bvci <0-65535>",
179 LOGGING_STR FILTER_STR
180 "Filter based on BSSGP Virtual Connection\n"
181 "NSEI of the BVC to be filtered\n"
182 "Network Service Entity Identifier (NSEI)\n"
183 "BVCI of the BVC to be filtered\n"
184 "BSSGP Virtual Connection Identifier (BVCI)\n")
185{
Harald Welte43ae94e2011-02-18 21:10:05 +0100186 struct log_target *tgt = osmo_log_vty2tgt(vty);
Harald Welte4e5721d2010-05-17 23:41:43 +0200187 struct bssgp_bvc_ctx *bvc;
188 uint16_t nsei = atoi(argv[0]);
189 uint16_t bvci = atoi(argv[1]);
190
Harald Welte43ae94e2011-02-18 21:10:05 +0100191 if (!tgt)
Harald Welte4e5721d2010-05-17 23:41:43 +0200192 return CMD_WARNING;
Harald Welte4e5721d2010-05-17 23:41:43 +0200193
194 bvc = btsctx_by_bvci_nsei(bvci, nsei);
195 if (!bvc) {
196 vty_out(vty, "No BVC by that identifier%s", VTY_NEWLINE);
197 return CMD_WARNING;
198 }
199
Harald Welte43ae94e2011-02-18 21:10:05 +0100200 log_set_bvc_filter(tgt, bvc);
Harald Welte4e5721d2010-05-17 23:41:43 +0200201 return CMD_SUCCESS;
202}
203
Harald Weltede4599c2012-06-17 13:04:02 +0800204int bssgp_vty_init(void)
Harald Welte4e5721d2010-05-17 23:41:43 +0200205{
206 install_element_ve(&show_bssgp_cmd);
207 install_element_ve(&show_bssgp_stats_cmd);
208 install_element_ve(&show_bvc_cmd);
209 install_element_ve(&logging_fltr_bvc_cmd);
Maxea507322016-03-31 21:40:26 +0200210 install_element_ve(&bvc_reset_cmd);
Harald Welte4e5721d2010-05-17 23:41:43 +0200211
Harald Welte43ae94e2011-02-18 21:10:05 +0100212 install_element(CFG_LOG_NODE, &logging_fltr_bvc_cmd);
213
Harald Welte4e5721d2010-05-17 23:41:43 +0200214 install_element(CONFIG_NODE, &cfg_bssgp_cmd);
215 install_node(&bssgp_node, config_write_bssgp);
Harald Welte4e5721d2010-05-17 23:41:43 +0200216
217 return 0;
218}