blob: a424038d9ece211692bbd483dc4e1cc3a60dba07 [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
8 * 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
10 * (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
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
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
30#include <openbsc/gsm_data.h>
31#include <osmocore/msgb.h>
32#include <osmocore/tlv.h>
33#include <osmocore/talloc.h>
34#include <osmocore/select.h>
35#include <osmocore/rate_ctr.h>
36#include <openbsc/debug.h>
37#include <openbsc/signal.h>
38#include <openbsc/gprs_ns.h>
39#include <openbsc/gprs_bssgp.h>
40#include <openbsc/telnet_interface.h>
41#include <openbsc/vty.h>
42
43#include <vty/vty.h>
44#include <vty/command.h>
45
46/* FIXME: this should go to some common file as it is copied
47 * in vty_interface.c of the BSC */
48static const struct value_string gprs_bssgp_timer_strs[] = {
49 { 0, NULL }
50};
51
52static struct cmd_node bssgp_node = {
53 BSSGP_NODE,
54 "%s(bssgp)#",
55 1,
56};
57
58static int config_write_bssgp(struct vty *vty)
59{
60 vty_out(vty, "bssgp%s", VTY_NEWLINE);
61
62 return CMD_SUCCESS;
63}
64
65DEFUN(cfg_bssgp, cfg_bssgp_cmd,
66 "bssgp",
67 "Configure the GPRS BSS Gateway Protocol")
68{
69 vty->node = BSSGP_NODE;
70 return CMD_SUCCESS;
71}
72
73static void dump_bvc(struct vty *vty, struct bssgp_bvc_ctx *bvc, int stats)
74{
75 vty_out(vty, "NSEI %5u, BVCI %5u, RA-ID: %u-%u-%u-%u, CID: %u, "
76 "STATE: %s%s", bvc->bvci, bvc->nsei, bvc->bvci, bvc->ra_id.mcc,
77 bvc->ra_id.mnc, bvc->ra_id.lac, bvc->ra_id.rac, bvc->cell_id,
78 bvc->state & BVC_S_BLOCKED ? "BLOCKED" : "UNBLOCKED",
79 VTY_NEWLINE);
80 if (stats)
81 vty_out_rate_ctr_group(vty, " ", bvc->ctrg);
82}
83
84static void dump_bssgp(struct vty *vty, int stats)
85{
86 struct bssgp_bvc_ctx *bvc;
87
88 llist_for_each_entry(bvc, &bssgp_bvc_ctxts, list) {
89 dump_bvc(vty, bvc, stats);
90 }
91}
92
93#define BSSGP_STR "Show information about the BSSGP protocol\n"
94
95DEFUN(show_bssgp, show_bssgp_cmd, "show bssgp",
96 SHOW_STR BSSGP_STR)
97{
98 dump_bssgp(vty, 0);
99 return CMD_SUCCESS;
100}
101
102DEFUN(show_bssgp_stats, show_bssgp_stats_cmd, "show bssgp stats",
103 SHOW_STR BSSGP_STR
104 "Include statistics\n")
105{
106 dump_bssgp(vty, 1);
107 return CMD_SUCCESS;
108}
109
110DEFUN(show_bvc, show_bvc_cmd, "show bssgp nsei <0-65535> [stats]",
111 SHOW_STR BSSGP_STR
112 "Show all BVCSE by its NSE Identifier\n"
113 "The NSEI\n" "Include Statistics\n")
114{
115 struct bssgp_bvc_ctx *bvc;
116 uint16_t nsei = atoi(argv[1]);
117 int show_stats = 0;
118
119 if (argc >= 2)
120 show_stats = 1;
121
122 llist_for_each_entry(bvc, &bssgp_bvc_ctxts, list) {
123 if (bvc->nsei != nsei)
124 continue;
125 dump_bvc(vty, bvc, show_stats);
126 }
127
128 return CMD_SUCCESS;
129}
130
131DEFUN(logging_fltr_bvc,
132 logging_fltr_bvc_cmd,
133 "logging filter bvc nsei <0-65535> bvci <0-65535>",
134 LOGGING_STR FILTER_STR
135 "Filter based on BSSGP Virtual Connection\n"
136 "NSEI of the BVC to be filtered\n"
137 "Network Service Entity Identifier (NSEI)\n"
138 "BVCI of the BVC to be filtered\n"
139 "BSSGP Virtual Connection Identifier (BVCI)\n")
140{
141 struct telnet_connection *conn;
142 struct bssgp_bvc_ctx *bvc;
143 uint16_t nsei = atoi(argv[0]);
144 uint16_t bvci = atoi(argv[1]);
145
146 conn = (struct telnet_connection *) vty->priv;
147 if (!conn->dbg) {
148 vty_out(vty, "Logging was not enabled.%s", VTY_NEWLINE);
149 return CMD_WARNING;
150 }
151
152 bvc = btsctx_by_bvci_nsei(bvci, nsei);
153 if (!bvc) {
154 vty_out(vty, "No BVC by that identifier%s", VTY_NEWLINE);
155 return CMD_WARNING;
156 }
157
158 log_set_bvc_filter(conn->dbg, bvc);
159 return CMD_SUCCESS;
160}
161
162int gprs_bssgp_vty_init(void)
163{
164 install_element_ve(&show_bssgp_cmd);
165 install_element_ve(&show_bssgp_stats_cmd);
166 install_element_ve(&show_bvc_cmd);
167 install_element_ve(&logging_fltr_bvc_cmd);
168
169 install_element(CONFIG_NODE, &cfg_bssgp_cmd);
170 install_node(&bssgp_node, config_write_bssgp);
171 install_default(BSSGP_NODE);
172 install_element(BSSGP_NODE, &ournode_exit_cmd);
173 install_element(BSSGP_NODE, &ournode_end_cmd);
174 //install_element(BSSGP_NODE, &cfg_bssgp_timer_cmd);
175
176 return 0;
177}