libosmocore/src/gb/gprs_bssgp_vty.c

221 lines
5.7 KiB
C
Raw Normal View History

/*! \file gprs_bssgp_vty.c
* VTY interface for our GPRS BSS Gateway Protocol (BSSGP) implementation. */
/*
* (C) 2010 by Harald Welte <laforge@gnumonks.org>
*
* All Rights Reserved
*
* SPDX-License-Identifier: GPL-2.0+
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <stdint.h>
#include <arpa/inet.h>
#include <osmocom/core/msgb.h>
#include <osmocom/gsm/tlv.h>
#include <osmocom/core/talloc.h>
#include <osmocom/core/select.h>
#include <osmocom/core/rate_ctr.h>
#include <osmocom/gprs/gprs_ns.h>
#include <osmocom/gprs/gprs_bssgp.h>
#include <osmocom/gprs/gprs_bssgp_bss.h>
2010-05-19 17:45:32 +00:00
#include <osmocom/vty/vty.h>
#include <osmocom/vty/command.h>
#include <osmocom/vty/logging.h>
#include <osmocom/vty/telnet_interface.h>
#include <osmocom/vty/misc.h>
static void log_set_bvc_filter(struct log_target *target,
struct bssgp_bvc_ctx *bctx)
{
if (bctx) {
target->filter_map |= (1 << LOG_FLT_GB_BVC);
target->filter_data[LOG_FLT_GB_BVC] = bctx;
} else if (target->filter_data[LOG_FLT_GB_BVC]) {
target->filter_map = ~(1 << LOG_FLT_GB_BVC);
target->filter_data[LOG_FLT_GB_BVC] = NULL;
}
}
static struct cmd_node bssgp_node = {
L_BSSGP_NODE,
"%s(config-bssgp)# ",
1,
};
static int config_write_bssgp(struct vty *vty)
{
vty_out(vty, "bssgp%s", VTY_NEWLINE);
return CMD_SUCCESS;
}
DEFUN(cfg_bssgp, cfg_bssgp_cmd,
"bssgp",
"Configure the GPRS BSS Gateway Protocol")
{
vty->node = L_BSSGP_NODE;
return CMD_SUCCESS;
}
static void dump_bvc(struct vty *vty, struct bssgp_bvc_ctx *bvc, int stats)
{
implement support for 3-digit MNC with leading zeros Enable representing three-digit MNC with leading zeros. The MNCs 23 and 023 are actually different; so far we treated both as 23. Re-encode an incoming BCD or string of 023 as it were, i.e. not dropping the leading zero as 23. Break ABI compatibility by changing the size and ordering of structs gprs_ra_id, osmo_plmn_id, osmo_cell_global_id, ... by adding an mnc_3_digits flag. Change ordering in gprs_ra_id because the canonical oder is {Mobile Country Code, Mobile Network Code}, so have the mcc member first. ABI compatibility cannot be maintained for struct gprs_ra_id, since it is a direct member of structs bssgp_bvc_ctx and bssgp_paging_info, and even just adding a flag to the end would cause ABI changes of those structs. Similarly, osmo_plmn_id is a direct member of osmo_location_area_id, and so forth. Add new API to set and read this additional flag to preserve leading zeros: - osmo_plmn_to_bcd(), osmo_plmn_from_bcd() after gsm48_mcc_mnc_to_bcd() and gsm48_mcc_mnc_from_bcd(). - gsm48_decode_lai2(), gsm48_generate_lai2() after gsm48_decode_lai(), gsm48_generate_lai(). - gsm0808_create_layer3_2() after gsm0808_create_layer3() and gsm0808_create_layer3_aoip(). - various osmo_*_name() functions in gsm23003.h (osmo_rai_name() still in gsm48.h close to struct gprs_ra_id definition). The amount and duplication of these may seem a bit overboard, but IMO they do make sense in this way. Though most code will soon see patches unifying the data structures used, in some cases (vty, ctrl) they are required singled out. Without these functions, the formatting ("%0*u", mnc_3_digits ? 3 : 2, mnc) would be duplicated all over our diverse repositories. In various log output, include the leading MNC zeros. Mark one TODO in card_fs_sim.c, I am not sure how to communicate a leading zero to/from a SIM card FS. The focus here is on the core network / BSS. To indicate ABI incompatibility, bump libosmogsm and libosmogb LIBVERSIONs; adjust debian files accordingly. Implementation choices: - The default behavior upon zero-initialization will be the mnc_3_digits flag set to false, which yields exactly the previous behavior. - I decided against packing the mnc with the mnc_3_digits field into a sub-struct because it would immediately break all builds of dependent projects: it would require immediate merging of numerous patches in other repositories, and it would make compiling older code against a newer libosmocore unneccessarily hard. Change-Id: Id2240f7f518494c9df6c8bda52c0d5092f90f221
2018-02-20 12:47:08 +00:00
vty_out(vty, "NSEI %5u, BVCI %5u, RA-ID: %s, CID: %u, "
"STATE: %s%s", bvc->nsei, bvc->bvci, osmo_rai_name(&bvc->ra_id),
bvc->cell_id, bvc->state & BVC_S_BLOCKED ? "BLOCKED" : "UNBLOCKED", VTY_NEWLINE);
if (stats) {
struct bssgp_flow_control *fc = bvc->fc;
vty_out_rate_ctr_group(vty, " ", bvc->ctrg);
if (fc)
vty_out(vty, "FC-BVC(bucket_max: %uoct, leak_rate: "
"%uoct/s, cur_tokens: %uoct, max_q_d: %u, "
"cur_q_d: %u)%s", fc->bucket_size_max,
fc->bucket_leak_rate, fc->bucket_counter,
fc->max_queue_depth, fc->queue_depth,
VTY_NEWLINE);
}
}
static void dump_bssgp(struct vty *vty, int stats)
{
struct bssgp_bvc_ctx *bvc;
llist_for_each_entry(bvc, &bssgp_bvc_ctxts, list) {
dump_bvc(vty, bvc, stats);
}
}
DEFUN(bvc_reset, bvc_reset_cmd,
"bssgp bvc nsei <0-65535> bvci <0-65535> reset",
"Initiate BVC RESET procedure for a given NSEI and BVCI\n"
"Filter based on BSSGP Virtual Connection\n"
"NSEI of the BVC to be filtered\n"
"Network Service Entity Identifier (NSEI)\n"
"BVCI of the BVC to be filtered\n"
"BSSGP Virtual Connection Identifier (BVCI)\n"
"Perform reset procedure\n")
{
int r;
uint16_t nsei = atoi(argv[0]), bvci = atoi(argv[1]);
struct bssgp_bvc_ctx *bvc = btsctx_by_bvci_nsei(bvci, nsei);
if (!bvc) {
vty_out(vty, "No BVC for NSEI %d BVCI %d%s", nsei, bvci,
VTY_NEWLINE);
return CMD_WARNING;
}
r = bssgp_tx_bvc_reset(bvc, bvci, BSSGP_CAUSE_OML_INTERV);
vty_out(vty, "Sent BVC RESET for NSEI %d BVCI %d: %d%s", nsei, bvci, r,
VTY_NEWLINE);
return CMD_SUCCESS;
}
#define BSSGP_STR "Show information about the BSSGP protocol\n"
DEFUN(show_bssgp, show_bssgp_cmd, "show bssgp",
SHOW_STR BSSGP_STR)
{
dump_bssgp(vty, 0);
return CMD_SUCCESS;
}
DEFUN(show_bssgp_stats, show_bssgp_stats_cmd, "show bssgp stats",
SHOW_STR BSSGP_STR
"Include statistics\n")
{
dump_bssgp(vty, 1);
return CMD_SUCCESS;
}
DEFUN(show_bvc, show_bvc_cmd, "show bssgp nsei <0-65535> [stats]",
SHOW_STR BSSGP_STR
"Show all BVCs on one NSE\n"
"The NSEI\n" "Include Statistics\n")
{
struct bssgp_bvc_ctx *bvc;
uint16_t nsei = atoi(argv[0]);
int show_stats = 0;
if (argc >= 2)
show_stats = 1;
llist_for_each_entry(bvc, &bssgp_bvc_ctxts, list) {
if (bvc->nsei != nsei)
continue;
dump_bvc(vty, bvc, show_stats);
}
return CMD_SUCCESS;
}
DEFUN(logging_fltr_bvc,
logging_fltr_bvc_cmd,
"logging filter bvc nsei <0-65535> bvci <0-65535>",
LOGGING_STR FILTER_STR
"Filter based on BSSGP Virtual Connection\n"
"NSEI of the BVC to be filtered\n"
"Network Service Entity Identifier (NSEI)\n"
"BVCI of the BVC to be filtered\n"
"BSSGP Virtual Connection Identifier (BVCI)\n")
{
struct log_target *tgt;
struct bssgp_bvc_ctx *bvc;
uint16_t nsei = atoi(argv[0]);
uint16_t bvci = atoi(argv[1]);
log_tgt_mutex_lock();
tgt = osmo_log_vty2tgt(vty);
if (!tgt) {
log_tgt_mutex_unlock();
return CMD_WARNING;
}
bvc = btsctx_by_bvci_nsei(bvci, nsei);
if (!bvc) {
vty_out(vty, "No BVC by that identifier%s", VTY_NEWLINE);
log_tgt_mutex_unlock();
return CMD_WARNING;
}
log_set_bvc_filter(tgt, bvc);
log_tgt_mutex_unlock();
return CMD_SUCCESS;
}
int bssgp_vty_init(void)
{
install_lib_element_ve(&show_bssgp_cmd);
install_lib_element_ve(&show_bssgp_stats_cmd);
install_lib_element_ve(&show_bvc_cmd);
install_lib_element_ve(&logging_fltr_bvc_cmd);
install_lib_element_ve(&bvc_reset_cmd);
install_lib_element(CFG_LOG_NODE, &logging_fltr_bvc_cmd);
install_lib_element(CONFIG_NODE, &cfg_bssgp_cmd);
install_node(&bssgp_node, config_write_bssgp);
return 0;
}