blob: a0d74ac94fbbf500cf87e751e9d45852ee3ee05e [file] [log] [blame]
Jonathan Santos03fd8d02011-05-25 13:54:02 -04001/* 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 Affero General Public License as published by
9 * the Free Software Foundation; either version 3 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 Affero General Public License for more details.
16 *
17 * 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/>.
19 *
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
29#include <openbsc/gsm_data.h>
Jonathan Santos5a45b152011-08-17 15:33:57 -040030#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>
Jonathan Santos03fd8d02011-05-25 13:54:02 -040035#include <openbsc/debug.h>
36#include <openbsc/signal.h>
37#include <openbsc/gprs_ns.h>
38#include <openbsc/gprs_bssgp.h>
39#include <openbsc/vty.h>
40
41#include <osmocom/vty/vty.h>
42#include <osmocom/vty/command.h>
43#include <osmocom/vty/logging.h>
44#include <osmocom/vty/telnet_interface.h>
Jonathan Santos5a45b152011-08-17 15:33:57 -040045#include <osmocom/vty/misc.h>
Jonathan Santos03fd8d02011-05-25 13:54:02 -040046
47/* FIXME: this should go to some common file as it is copied
48 * in vty_interface.c of the BSC */
49static const struct value_string gprs_bssgp_timer_strs[] = {
50 { 0, NULL }
51};
52
53static struct cmd_node bssgp_node = {
54 BSSGP_NODE,
55 "%s(bssgp)#",
56 1,
57};
58
59static int config_write_bssgp(struct vty *vty)
60{
61 vty_out(vty, "bssgp%s", VTY_NEWLINE);
62
63 return CMD_SUCCESS;
64}
65
66DEFUN(cfg_bssgp, cfg_bssgp_cmd,
67 "bssgp",
68 "Configure the GPRS BSS Gateway Protocol")
69{
70 vty->node = BSSGP_NODE;
71 return CMD_SUCCESS;
72}
73
74static void dump_bvc(struct vty *vty, struct bssgp_bvc_ctx *bvc, int stats)
75{
76 vty_out(vty, "NSEI %5u, BVCI %5u, RA-ID: %u-%u-%u-%u, CID: %u, "
77 "STATE: %s%s", bvc->nsei, bvc->bvci, bvc->ra_id.mcc,
78 bvc->ra_id.mnc, bvc->ra_id.lac, bvc->ra_id.rac, bvc->cell_id,
79 bvc->state & BVC_S_BLOCKED ? "BLOCKED" : "UNBLOCKED",
80 VTY_NEWLINE);
81 if (stats)
82 vty_out_rate_ctr_group(vty, " ", bvc->ctrg);
83}
84
85static void dump_bssgp(struct vty *vty, int stats)
86{
87 struct bssgp_bvc_ctx *bvc;
88
89 llist_for_each_entry(bvc, &bssgp_bvc_ctxts, list) {
90 dump_bvc(vty, bvc, stats);
91 }
92}
93
94#define BSSGP_STR "Show information about the BSSGP protocol\n"
95
96DEFUN(show_bssgp, show_bssgp_cmd, "show bssgp",
97 SHOW_STR BSSGP_STR)
98{
99 dump_bssgp(vty, 0);
100 return CMD_SUCCESS;
101}
102
103DEFUN(show_bssgp_stats, show_bssgp_stats_cmd, "show bssgp stats",
104 SHOW_STR BSSGP_STR
105 "Include statistics\n")
106{
107 dump_bssgp(vty, 1);
108 return CMD_SUCCESS;
109}
110
111DEFUN(show_bvc, show_bvc_cmd, "show bssgp nsei <0-65535> [stats]",
112 SHOW_STR BSSGP_STR
113 "Show all BVCs on one NSE\n"
114 "The NSEI\n" "Include Statistics\n")
115{
116 struct bssgp_bvc_ctx *bvc;
117 uint16_t nsei = atoi(argv[1]);
118 int show_stats = 0;
119
120 if (argc >= 2)
121 show_stats = 1;
122
123 llist_for_each_entry(bvc, &bssgp_bvc_ctxts, list) {
124 if (bvc->nsei != nsei)
125 continue;
126 dump_bvc(vty, bvc, show_stats);
127 }
128
129 return CMD_SUCCESS;
130}
131
132DEFUN(logging_fltr_bvc,
133 logging_fltr_bvc_cmd,
134 "logging filter bvc nsei <0-65535> bvci <0-65535>",
135 LOGGING_STR FILTER_STR
136 "Filter based on BSSGP Virtual Connection\n"
137 "NSEI of the BVC to be filtered\n"
138 "Network Service Entity Identifier (NSEI)\n"
139 "BVCI of the BVC to be filtered\n"
140 "BSSGP Virtual Connection Identifier (BVCI)\n")
141{
142 struct log_target *tgt = osmo_log_vty2tgt(vty);
143 struct bssgp_bvc_ctx *bvc;
144 uint16_t nsei = atoi(argv[0]);
145 uint16_t bvci = atoi(argv[1]);
146
147 if (!tgt)
148 return CMD_WARNING;
149
150 bvc = btsctx_by_bvci_nsei(bvci, nsei);
151 if (!bvc) {
152 vty_out(vty, "No BVC by that identifier%s", VTY_NEWLINE);
153 return CMD_WARNING;
154 }
155
156 log_set_bvc_filter(tgt, bvc);
157 return CMD_SUCCESS;
158}
159
160int gprs_bssgp_vty_init(void)
161{
162 install_element_ve(&show_bssgp_cmd);
163 install_element_ve(&show_bssgp_stats_cmd);
164 install_element_ve(&show_bvc_cmd);
165 install_element_ve(&logging_fltr_bvc_cmd);
166
167 install_element(CFG_LOG_NODE, &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}