blob: ff1b8f5c8bd57e510743a1bdbec9b24a88aa0467 [file] [log] [blame]
Harald Welted9a55f62010-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 Welte9af6ddf2011-01-01 15:25:50 +01008 * 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 Welted9a55f62010-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 Welte9af6ddf2011-01-01 15:25:50 +010015 * GNU Affero General Public License for more details.
Harald Welted9a55f62010-05-17 23:41:43 +020016 *
Harald Welte9af6ddf2011-01-01 15:25:50 +010017 * 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 Welted9a55f62010-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 Ayuso136f4532011-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 Welteea34a4e2012-06-16 14:59:56 +080034#include <osmocom/gprs/gprs_ns.h>
35#include <osmocom/gprs/gprs_bssgp.h>
Harald Welted9a55f62010-05-17 23:41:43 +020036
Harald Welte4b037e42010-05-19 19:45:32 +020037#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 Ayuso6110a3f2011-03-28 19:35:00 +020041#include <osmocom/vty/misc.h>
Harald Welted9a55f62010-05-17 23:41:43 +020042
Harald Weltefdd8b3b2012-06-16 16:54:06 +080043#include "common_vty.h"
Harald Welteea34a4e2012-06-16 14:59:56 +080044
Harald Welted9a55f62010-05-17 23:41:43 +020045/* FIXME: this should go to some common file as it is copied
46 * in vty_interface.c of the BSC */
47static const struct value_string gprs_bssgp_timer_strs[] = {
48 { 0, NULL }
49};
50
51static struct cmd_node bssgp_node = {
Harald Weltefdd8b3b2012-06-16 16:54:06 +080052 L_BSSGP_NODE,
Harald Welted9a55f62010-05-17 23:41:43 +020053 "%s(bssgp)#",
54 1,
55};
56
57static int config_write_bssgp(struct vty *vty)
58{
59 vty_out(vty, "bssgp%s", VTY_NEWLINE);
60
61 return CMD_SUCCESS;
62}
63
64DEFUN(cfg_bssgp, cfg_bssgp_cmd,
65 "bssgp",
66 "Configure the GPRS BSS Gateway Protocol")
67{
Harald Weltefdd8b3b2012-06-16 16:54:06 +080068 vty->node = L_BSSGP_NODE;
Harald Welted9a55f62010-05-17 23:41:43 +020069 return CMD_SUCCESS;
70}
71
72static void dump_bvc(struct vty *vty, struct bssgp_bvc_ctx *bvc, int stats)
73{
74 vty_out(vty, "NSEI %5u, BVCI %5u, RA-ID: %u-%u-%u-%u, CID: %u, "
Harald Welte803bd5c2010-05-18 12:00:55 +020075 "STATE: %s%s", bvc->nsei, bvc->bvci, bvc->ra_id.mcc,
Harald Welted9a55f62010-05-17 23:41:43 +020076 bvc->ra_id.mnc, bvc->ra_id.lac, bvc->ra_id.rac, bvc->cell_id,
77 bvc->state & BVC_S_BLOCKED ? "BLOCKED" : "UNBLOCKED",
78 VTY_NEWLINE);
79 if (stats)
80 vty_out_rate_ctr_group(vty, " ", bvc->ctrg);
81}
82
83static void dump_bssgp(struct vty *vty, int stats)
84{
85 struct bssgp_bvc_ctx *bvc;
86
87 llist_for_each_entry(bvc, &bssgp_bvc_ctxts, list) {
88 dump_bvc(vty, bvc, stats);
89 }
90}
91
92#define BSSGP_STR "Show information about the BSSGP protocol\n"
93
94DEFUN(show_bssgp, show_bssgp_cmd, "show bssgp",
95 SHOW_STR BSSGP_STR)
96{
97 dump_bssgp(vty, 0);
98 return CMD_SUCCESS;
99}
100
101DEFUN(show_bssgp_stats, show_bssgp_stats_cmd, "show bssgp stats",
102 SHOW_STR BSSGP_STR
103 "Include statistics\n")
104{
105 dump_bssgp(vty, 1);
106 return CMD_SUCCESS;
107}
108
109DEFUN(show_bvc, show_bvc_cmd, "show bssgp nsei <0-65535> [stats]",
110 SHOW_STR BSSGP_STR
Harald Welteefbdee92010-06-10 00:20:12 +0200111 "Show all BVCs on one NSE\n"
Harald Welted9a55f62010-05-17 23:41:43 +0200112 "The NSEI\n" "Include Statistics\n")
113{
114 struct bssgp_bvc_ctx *bvc;
115 uint16_t nsei = atoi(argv[1]);
116 int show_stats = 0;
117
118 if (argc >= 2)
119 show_stats = 1;
120
121 llist_for_each_entry(bvc, &bssgp_bvc_ctxts, list) {
122 if (bvc->nsei != nsei)
123 continue;
124 dump_bvc(vty, bvc, show_stats);
125 }
126
127 return CMD_SUCCESS;
128}
129
130DEFUN(logging_fltr_bvc,
131 logging_fltr_bvc_cmd,
132 "logging filter bvc nsei <0-65535> bvci <0-65535>",
133 LOGGING_STR FILTER_STR
134 "Filter based on BSSGP Virtual Connection\n"
135 "NSEI of the BVC to be filtered\n"
136 "Network Service Entity Identifier (NSEI)\n"
137 "BVCI of the BVC to be filtered\n"
138 "BSSGP Virtual Connection Identifier (BVCI)\n")
139{
Harald Welte8dcebd32011-02-18 21:10:05 +0100140 struct log_target *tgt = osmo_log_vty2tgt(vty);
Harald Welted9a55f62010-05-17 23:41:43 +0200141 struct bssgp_bvc_ctx *bvc;
142 uint16_t nsei = atoi(argv[0]);
143 uint16_t bvci = atoi(argv[1]);
144
Harald Welte8dcebd32011-02-18 21:10:05 +0100145 if (!tgt)
Harald Welted9a55f62010-05-17 23:41:43 +0200146 return CMD_WARNING;
Harald Welted9a55f62010-05-17 23:41:43 +0200147
148 bvc = btsctx_by_bvci_nsei(bvci, nsei);
149 if (!bvc) {
150 vty_out(vty, "No BVC by that identifier%s", VTY_NEWLINE);
151 return CMD_WARNING;
152 }
153
Harald Welte8dcebd32011-02-18 21:10:05 +0100154 log_set_bvc_filter(tgt, bvc);
Harald Welted9a55f62010-05-17 23:41:43 +0200155 return CMD_SUCCESS;
156}
157
158int gprs_bssgp_vty_init(void)
159{
160 install_element_ve(&show_bssgp_cmd);
161 install_element_ve(&show_bssgp_stats_cmd);
162 install_element_ve(&show_bvc_cmd);
163 install_element_ve(&logging_fltr_bvc_cmd);
164
Harald Welte8dcebd32011-02-18 21:10:05 +0100165 install_element(CFG_LOG_NODE, &logging_fltr_bvc_cmd);
166
Harald Welted9a55f62010-05-17 23:41:43 +0200167 install_element(CONFIG_NODE, &cfg_bssgp_cmd);
168 install_node(&bssgp_node, config_write_bssgp);
Harald Weltefdd8b3b2012-06-16 16:54:06 +0800169 install_default(L_BSSGP_NODE);
170 install_element(L_BSSGP_NODE, &libgb_exit_cmd);
171 install_element(L_BSSGP_NODE, &libgb_end_cmd);
172 //install_element(L_BSSGP_NODE, &cfg_bssgp_timer_cmd);
Harald Welted9a55f62010-05-17 23:41:43 +0200173
174 return 0;
175}