blob: 2f0b70ad4d43d56313548ae5d7e0ad7f8f989dca [file] [log] [blame]
Harald Weltef2b4cd72010-05-13 11:45:07 +02001/* VTY interface for our GPRS Networks Service (NS) implementation */
2
3/* (C) 2009-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 Weltef2b4cd72010-05-13 11:45:07 +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 Weltef2b4cd72010-05-13 11:45:07 +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 Weltef2b4cd72010-05-13 11:45:07 +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 Weltef2b4cd72010-05-13 11:45:07 +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 Weltef2b4cd72010-05-13 11:45:07 +020042
Harald Weltefdd8b3b2012-06-16 16:54:06 +080043#include "common_vty.h"
Harald Welteea34a4e2012-06-16 14:59:56 +080044
Harald Weltef2b4cd72010-05-13 11:45:07 +020045static struct gprs_ns_inst *vty_nsi = NULL;
46
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_ns_timer_strs[] = {
50 { 0, "tns-block" },
51 { 1, "tns-block-retries" },
52 { 2, "tns-reset" },
53 { 3, "tns-reset-retries" },
54 { 4, "tns-test" },
55 { 5, "tns-alive" },
56 { 6, "tns-alive-retries" },
57 { 0, NULL }
58};
59
60static struct cmd_node ns_node = {
Harald Weltefdd8b3b2012-06-16 16:54:06 +080061 L_NS_NODE,
Harald Weltef2b4cd72010-05-13 11:45:07 +020062 "%s(ns)#",
63 1,
64};
65
66static int config_write_ns(struct vty *vty)
67{
68 struct gprs_nsvc *nsvc;
69 unsigned int i;
Harald Welteff3bde82010-05-19 15:09:09 +020070 struct in_addr ia;
Harald Weltef2b4cd72010-05-13 11:45:07 +020071
72 vty_out(vty, "ns%s", VTY_NEWLINE);
73
74 llist_for_each_entry(nsvc, &vty_nsi->gprs_nsvcs, list) {
75 if (!nsvc->persistent)
76 continue;
77 vty_out(vty, " nse %u nsvci %u%s",
78 nsvc->nsei, nsvc->nsvci, VTY_NEWLINE);
79 vty_out(vty, " nse %u remote-role %s%s",
80 nsvc->nsei, nsvc->remote_end_is_sgsn ? "sgsn" : "bss",
81 VTY_NEWLINE);
Harald Welte5540c4c2010-05-19 14:38:50 +020082 switch (nsvc->ll) {
83 case GPRS_NS_LL_UDP:
84 vty_out(vty, " nse %u encapsulation udp%s", nsvc->nsei,
85 VTY_NEWLINE);
Harald Weltef2b4cd72010-05-13 11:45:07 +020086 vty_out(vty, " nse %u remote-ip %s%s",
87 nsvc->nsei,
88 inet_ntoa(nsvc->ip.bts_addr.sin_addr),
89 VTY_NEWLINE);
90 vty_out(vty, " nse %u remote-port %u%s",
91 nsvc->nsei, ntohs(nsvc->ip.bts_addr.sin_port),
92 VTY_NEWLINE);
Harald Welte5540c4c2010-05-19 14:38:50 +020093 break;
94 case GPRS_NS_LL_FR_GRE:
95 vty_out(vty, " nse %u encapsulation framerelay-gre%s",
96 nsvc->nsei, VTY_NEWLINE);
97 vty_out(vty, " nse %u remote-ip %s%s",
98 nsvc->nsei,
99 inet_ntoa(nsvc->frgre.bts_addr.sin_addr),
100 VTY_NEWLINE);
101 vty_out(vty, " nse %u fr-dlci %u%s",
102 nsvc->nsei, ntohs(nsvc->frgre.bts_addr.sin_port),
103 VTY_NEWLINE);
104 default:
105 break;
Harald Weltef2b4cd72010-05-13 11:45:07 +0200106 }
107 }
108
109 for (i = 0; i < ARRAY_SIZE(vty_nsi->timeout); i++)
110 vty_out(vty, " timer %s %u%s",
111 get_value_string(gprs_ns_timer_strs, i),
112 vty_nsi->timeout[i], VTY_NEWLINE);
113
Harald Welteff3bde82010-05-19 15:09:09 +0200114 if (vty_nsi->nsip.local_ip) {
115 ia.s_addr = htonl(vty_nsi->nsip.local_ip);
116 vty_out(vty, " encapsulation udp local-ip %s%s",
117 inet_ntoa(ia), VTY_NEWLINE);
Harald Welteff3bde82010-05-19 15:09:09 +0200118 }
Harald Welte6624cae2010-05-19 17:02:57 +0200119 if (vty_nsi->nsip.local_port)
120 vty_out(vty, " encapsulation udp local-port %u%s",
121 vty_nsi->nsip.local_port, VTY_NEWLINE);
122
Harald Welteff3bde82010-05-19 15:09:09 +0200123 vty_out(vty, " encapsulation framerelay-gre enabled %u%s",
124 vty_nsi->frgre.enabled ? 1 : 0, VTY_NEWLINE);
Harald Welte6624cae2010-05-19 17:02:57 +0200125 if (vty_nsi->frgre.local_ip) {
Harald Welteff3bde82010-05-19 15:09:09 +0200126 ia.s_addr = htonl(vty_nsi->frgre.local_ip);
127 vty_out(vty, " encapsulation framerelay-gre local-ip %s%s",
128 inet_ntoa(ia), VTY_NEWLINE);
129 }
130
Harald Weltef2b4cd72010-05-13 11:45:07 +0200131 return CMD_SUCCESS;
132}
133
134DEFUN(cfg_ns, cfg_ns_cmd,
135 "ns",
136 "Configure the GPRS Network Service")
137{
Harald Weltefdd8b3b2012-06-16 16:54:06 +0800138 vty->node = L_NS_NODE;
Harald Weltef2b4cd72010-05-13 11:45:07 +0200139 return CMD_SUCCESS;
140}
141
Harald Welte55c91e42010-05-15 23:04:03 +0200142static void dump_nse(struct vty *vty, struct gprs_nsvc *nsvc, int stats)
143{
144 vty_out(vty, "NSEI %5u, NS-VC %5u, Remote: %-4s, %5s %9s",
145 nsvc->nsei, nsvc->nsvci,
146 nsvc->remote_end_is_sgsn ? "SGSN" : "BSS",
147 nsvc->state & NSE_S_ALIVE ? "ALIVE" : "DEAD",
148 nsvc->state & NSE_S_BLOCKED ? "BLOCKED" : "UNBLOCKED");
Harald Welte5540c4c2010-05-19 14:38:50 +0200149 if (nsvc->ll == GPRS_NS_LL_UDP || nsvc->ll == GPRS_NS_LL_FR_GRE)
150 vty_out(vty, ", %s %15s:%u",
Harald Welte6624cae2010-05-19 17:02:57 +0200151 nsvc->ll == GPRS_NS_LL_UDP ? "UDP " : "FR-GRE",
Harald Welte55c91e42010-05-15 23:04:03 +0200152 inet_ntoa(nsvc->ip.bts_addr.sin_addr),
153 ntohs(nsvc->ip.bts_addr.sin_port));
154 vty_out(vty, "%s", VTY_NEWLINE);
155 if (stats)
156 vty_out_rate_ctr_group(vty, " ", nsvc->ctrg);
157}
158
Harald Welte73b23592010-05-13 12:32:30 +0200159static void dump_ns(struct vty *vty, struct gprs_ns_inst *nsi, int stats)
Harald Weltef2b4cd72010-05-13 11:45:07 +0200160{
Harald Weltef2b4cd72010-05-13 11:45:07 +0200161 struct gprs_nsvc *nsvc;
Harald Welteff3bde82010-05-19 15:09:09 +0200162 struct in_addr ia;
163
164 ia.s_addr = htonl(vty_nsi->nsip.local_ip);
Harald Welte6624cae2010-05-19 17:02:57 +0200165 vty_out(vty, "Encapsulation NS-UDP-IP Local IP: %s, UDP Port: %u%s",
Harald Welteff3bde82010-05-19 15:09:09 +0200166 inet_ntoa(ia), vty_nsi->nsip.local_port, VTY_NEWLINE);
167
168 ia.s_addr = htonl(vty_nsi->frgre.local_ip);
Harald Welte6624cae2010-05-19 17:02:57 +0200169 vty_out(vty, "Encapsulation NS-FR-GRE-IP Local IP: %s%s",
Harald Welteff3bde82010-05-19 15:09:09 +0200170 inet_ntoa(ia), VTY_NEWLINE);
Harald Weltef2b4cd72010-05-13 11:45:07 +0200171
172 llist_for_each_entry(nsvc, &nsi->gprs_nsvcs, list) {
Harald Welte9aa97fc2010-05-13 13:58:08 +0200173 if (nsvc == nsi->unknown_nsvc)
174 continue;
Harald Welte55c91e42010-05-15 23:04:03 +0200175 dump_nse(vty, nsvc, stats);
Harald Weltef2b4cd72010-05-13 11:45:07 +0200176 }
Harald Welte73b23592010-05-13 12:32:30 +0200177}
Harald Weltef2b4cd72010-05-13 11:45:07 +0200178
Harald Welte73b23592010-05-13 12:32:30 +0200179DEFUN(show_ns, show_ns_cmd, "show ns",
180 SHOW_STR "Display information about the NS protocol")
181{
182 struct gprs_ns_inst *nsi = vty_nsi;
183 dump_ns(vty, nsi, 0);
Harald Weltef2b4cd72010-05-13 11:45:07 +0200184 return CMD_SUCCESS;
185}
186
Harald Welte73b23592010-05-13 12:32:30 +0200187DEFUN(show_ns_stats, show_ns_stats_cmd, "show ns stats",
188 SHOW_STR
189 "Display information about the NS protocol\n"
190 "Include statistics\n")
191{
192 struct gprs_ns_inst *nsi = vty_nsi;
193 dump_ns(vty, nsi, 1);
194 return CMD_SUCCESS;
195}
Harald Weltef2b4cd72010-05-13 11:45:07 +0200196
Harald Welte55c91e42010-05-15 23:04:03 +0200197DEFUN(show_nse, show_nse_cmd, "show ns (nsei|nsvc) <0-65535> [stats]",
198 SHOW_STR "Display information about the NS protocol\n"
199 "Select one NSE by its NSE Identifier\n"
200 "Select one NSE by its NS-VC Identifier\n"
201 "The Identifier of selected type\n"
202 "Include Statistics\n")
203{
204 struct gprs_ns_inst *nsi = vty_nsi;
205 struct gprs_nsvc *nsvc;
206 uint16_t id = atoi(argv[1]);
207 int show_stats = 0;
208
209 if (!strcmp(argv[0], "nsei"))
210 nsvc = nsvc_by_nsei(nsi, id);
211 else
212 nsvc = nsvc_by_nsvci(nsi, id);
213
214 if (!nsvc) {
215 vty_out(vty, "No such NS Entity%s", VTY_NEWLINE);
216 return CMD_WARNING;
217 }
218
219 if (argc >= 3)
220 show_stats = 1;
221
222 dump_nse(vty, nsvc, show_stats);
223 return CMD_SUCCESS;
224}
225
Harald Welte52613a12010-05-15 23:06:26 +0200226#define NSE_CMD_STR "Persistent NS Entity\n" "NS Entity ID (NSEI)\n"
Harald Weltef2b4cd72010-05-13 11:45:07 +0200227
228DEFUN(cfg_nse_nsvc, cfg_nse_nsvci_cmd,
229 "nse <0-65535> nsvci <0-65534>",
230 NSE_CMD_STR
231 "NS Virtual Connection\n"
232 "NS Virtual Connection ID (NSVCI)\n"
233 )
234{
235 uint16_t nsei = atoi(argv[0]);
236 uint16_t nsvci = atoi(argv[1]);
237 struct gprs_nsvc *nsvc;
238
239 nsvc = nsvc_by_nsei(vty_nsi, nsei);
240 if (!nsvc) {
241 nsvc = nsvc_create(vty_nsi, nsvci);
242 nsvc->nsei = nsei;
243 }
244 nsvc->nsvci = nsvci;
245 /* All NSVCs that are explicitly configured by VTY are
246 * marked as persistent so we can write them to the config
247 * file at some later point */
248 nsvc->persistent = 1;
249
250 return CMD_SUCCESS;
251}
252
253DEFUN(cfg_nse_remoteip, cfg_nse_remoteip_cmd,
254 "nse <0-65535> remote-ip A.B.C.D",
255 NSE_CMD_STR
256 "Remote IP Address\n"
257 "Remote IP Address\n")
258{
259 uint16_t nsei = atoi(argv[0]);
260 struct gprs_nsvc *nsvc;
261
262 nsvc = nsvc_by_nsei(vty_nsi, nsei);
263 if (!nsvc) {
264 vty_out(vty, "No such NSE (%u)%s", nsei, VTY_NEWLINE);
265 return CMD_WARNING;
266 }
267 inet_aton(argv[1], &nsvc->ip.bts_addr.sin_addr);
268
269 return CMD_SUCCESS;
270
271}
272
273DEFUN(cfg_nse_remoteport, cfg_nse_remoteport_cmd,
274 "nse <0-65535> remote-port <0-65535>",
275 NSE_CMD_STR
276 "Remote UDP Port\n"
277 "Remote UDP Port Number\n")
278{
279 uint16_t nsei = atoi(argv[0]);
280 uint16_t port = atoi(argv[1]);
281 struct gprs_nsvc *nsvc;
282
283 nsvc = nsvc_by_nsei(vty_nsi, nsei);
284 if (!nsvc) {
285 vty_out(vty, "No such NSE (%u)%s", nsei, VTY_NEWLINE);
286 return CMD_WARNING;
287 }
288
Harald Welte5540c4c2010-05-19 14:38:50 +0200289 if (nsvc->ll != GPRS_NS_LL_UDP) {
290 vty_out(vty, "Cannot set UDP Port on non-UDP NSE%s",
291 VTY_NEWLINE);
292 return CMD_WARNING;
293 }
294
Harald Weltef2b4cd72010-05-13 11:45:07 +0200295 nsvc->ip.bts_addr.sin_port = htons(port);
296
297 return CMD_SUCCESS;
298}
299
Harald Welte5540c4c2010-05-19 14:38:50 +0200300DEFUN(cfg_nse_fr_dlci, cfg_nse_fr_dlci_cmd,
Harald Welteedcc3b82010-05-28 14:11:49 +0200301 "nse <0-65535> fr-dlci <16-1007>",
Harald Welte5540c4c2010-05-19 14:38:50 +0200302 NSE_CMD_STR
303 "Frame Relay DLCI\n"
304 "Frame Relay DLCI Number\n")
305{
306 uint16_t nsei = atoi(argv[0]);
307 uint16_t dlci = atoi(argv[1]);
308 struct gprs_nsvc *nsvc;
309
310 nsvc = nsvc_by_nsei(vty_nsi, nsei);
311 if (!nsvc) {
312 vty_out(vty, "No such NSE (%u)%s", nsei, VTY_NEWLINE);
313 return CMD_WARNING;
314 }
315
316 if (nsvc->ll != GPRS_NS_LL_FR_GRE) {
317 vty_out(vty, "Cannot set FR DLCI on non-FR NSE%s",
318 VTY_NEWLINE);
319 return CMD_WARNING;
320 }
321
322 nsvc->frgre.bts_addr.sin_port = htons(dlci);
323
324 return CMD_SUCCESS;
325}
326
327DEFUN(cfg_nse_encaps, cfg_nse_encaps_cmd,
328 "nse <0-65535> encapsulation (udp|framerelay-gre)",
329 NSE_CMD_STR
330 "Encapsulation for NS\n"
331 "UDP/IP Encapsulation\n" "Frame-Relay/GRE/IP Encapsulation\n")
332{
333 uint16_t nsei = atoi(argv[0]);
334 struct gprs_nsvc *nsvc;
335
336 nsvc = nsvc_by_nsei(vty_nsi, nsei);
337 if (!nsvc) {
338 vty_out(vty, "No such NSE (%u)%s", nsei, VTY_NEWLINE);
339 return CMD_WARNING;
340 }
341
342 if (!strcmp(argv[1], "udp"))
343 nsvc->ll = GPRS_NS_LL_UDP;
344 else
345 nsvc->ll = GPRS_NS_LL_FR_GRE;
346
347 return CMD_SUCCESS;
348}
349
350
Harald Weltef2b4cd72010-05-13 11:45:07 +0200351DEFUN(cfg_nse_remoterole, cfg_nse_remoterole_cmd,
352 "nse <0-65535> remote-role (sgsn|bss)",
353 NSE_CMD_STR
354 "Remote NSE Role\n"
355 "Remote Peer is SGSN\n"
356 "Remote Peer is BSS\n")
357{
358 uint16_t nsei = atoi(argv[0]);
359 struct gprs_nsvc *nsvc;
360
361 nsvc = nsvc_by_nsei(vty_nsi, nsei);
362 if (!nsvc) {
363 vty_out(vty, "No such NSE (%u)%s", nsei, VTY_NEWLINE);
364 return CMD_WARNING;
365 }
366
367 if (!strcmp(argv[1], "sgsn"))
368 nsvc->remote_end_is_sgsn = 1;
369 else
370 nsvc->remote_end_is_sgsn = 0;
371
372 return CMD_SUCCESS;
373}
374
375DEFUN(cfg_no_nse, cfg_no_nse_cmd,
376 "no nse <0-65535>",
Harald Welte52613a12010-05-15 23:06:26 +0200377 "Delete Persistent NS Entity\n"
Harald Weltef2b4cd72010-05-13 11:45:07 +0200378 "Delete " NSE_CMD_STR)
379{
380 uint16_t nsei = atoi(argv[0]);
381 struct gprs_nsvc *nsvc;
382
383 nsvc = nsvc_by_nsei(vty_nsi, nsei);
384 if (!nsvc) {
385 vty_out(vty, "No such NSE (%u)%s", nsei, VTY_NEWLINE);
386 return CMD_WARNING;
387 }
388
Harald Welte52613a12010-05-15 23:06:26 +0200389 if (!nsvc->persistent) {
390 vty_out(vty, "NSEI %u is not a persistent NSE%s",
391 nsei, VTY_NEWLINE);
392 return CMD_WARNING;
393 }
394
395 nsvc->persistent = 0;
Harald Weltef2b4cd72010-05-13 11:45:07 +0200396
397 return CMD_SUCCESS;
398}
399
400DEFUN(cfg_ns_timer, cfg_ns_timer_cmd,
401 "timer " NS_TIMERS " <0-65535>",
402 "Network Service Timer\n"
403 NS_TIMERS_HELP "Timer Value\n")
404{
405 int idx = get_string_value(gprs_ns_timer_strs, argv[0]);
406 int val = atoi(argv[1]);
407
408 if (idx < 0 || idx >= ARRAY_SIZE(vty_nsi->timeout))
409 return CMD_WARNING;
410
411 vty_nsi->timeout[idx] = val;
412
413 return CMD_SUCCESS;
414}
415
Harald Welteff3bde82010-05-19 15:09:09 +0200416#define ENCAPS_STR "NS encapsulation options\n"
417
418DEFUN(cfg_nsip_local_ip, cfg_nsip_local_ip_cmd,
419 "encapsulation udp local-ip A.B.C.D",
420 ENCAPS_STR "NS over UDP Encapsulation\n"
421 "Set the IP address on which we listen for NS/UDP\n"
422 "IP Address\n")
423{
424 struct in_addr ia;
425
426 inet_aton(argv[0], &ia);
427 vty_nsi->nsip.local_ip = ntohl(ia.s_addr);
428
429 return CMD_SUCCESS;
430}
431
432DEFUN(cfg_nsip_local_port, cfg_nsip_local_port_cmd,
433 "encapsulation udp local-port <0-65535>",
434 ENCAPS_STR "NS over UDP Encapsulation\n"
435 "Set the UDP port on which we listen for NS/UDP\n"
436 "UDP port number\n")
437{
438 unsigned int port = atoi(argv[0]);
439
440 vty_nsi->nsip.local_port = port;
441
442 return CMD_SUCCESS;
443}
444
445DEFUN(cfg_frgre_local_ip, cfg_frgre_local_ip_cmd,
446 "encapsulation framerelay-gre local-ip A.B.C.D",
447 ENCAPS_STR "NS over Frame Relay over GRE Encapsulation\n"
448 "Set the IP address on which we listen for NS/FR/GRE\n"
449 "IP Address\n")
450{
451 struct in_addr ia;
452
453 if (!vty_nsi->frgre.enabled) {
454 vty_out(vty, "FR/GRE is not enabled%s", VTY_NEWLINE);
455 return CMD_WARNING;
456 }
457 inet_aton(argv[0], &ia);
458 vty_nsi->frgre.local_ip = ntohl(ia.s_addr);
459
460 return CMD_SUCCESS;
461}
462
463DEFUN(cfg_frgre_enable, cfg_frgre_enable_cmd,
464 "encapsulation framerelay-gre enabled (1|0)",
465 ENCAPS_STR "NS over Frame Relay over GRE Encapsulation\n"
466 "Enable or disable Frame Relay over GRE\n"
467 "Enable\n" "Disable\n")
468{
469 int enabled = atoi(argv[0]);
470
471 vty_nsi->frgre.enabled = enabled;
472
473 return CMD_SUCCESS;
474}
475
Harald Welte9ef91082010-05-14 19:36:59 +0200476DEFUN(nsvc_nsei, nsvc_nsei_cmd,
477 "nsvc nsei <0-65535> (block|unblock|reset)",
478 "Perform an operation on a NSVC\n"
Holger Hans Peter Freyther2eb6e2c2011-11-05 15:14:59 +0100479 "NSEI to identify NS-VC Identifier (NS-VCI)\n"
480 "The NSEI\n"
Harald Welte9ef91082010-05-14 19:36:59 +0200481 "Initiate BLOCK procedure\n"
482 "Initiate UNBLOCK procedure\n"
483 "Initiate RESET procedure\n")
484{
485 uint16_t nsvci = atoi(argv[0]);
486 const char *operation = argv[1];
487 struct gprs_nsvc *nsvc;
488
489 nsvc = nsvc_by_nsei(vty_nsi, nsvci);
490 if (!nsvc) {
491 vty_out(vty, "No such NSVCI (%u)%s", nsvci, VTY_NEWLINE);
492 return CMD_WARNING;
493 }
494
495 if (!strcmp(operation, "block"))
496 gprs_ns_tx_block(nsvc, NS_CAUSE_OM_INTERVENTION);
497 else if (!strcmp(operation, "unblock"))
498 gprs_ns_tx_unblock(nsvc);
499 else if (!strcmp(operation, "reset"))
500 gprs_nsvc_reset(nsvc, NS_CAUSE_OM_INTERVENTION);
501 else
502 return CMD_WARNING;
503
504 return CMD_SUCCESS;
505}
506
Harald Welte8be8c8f2010-05-15 23:52:02 +0200507DEFUN(logging_fltr_nsvc,
508 logging_fltr_nsvc_cmd,
509 "logging filter nsvc (nsei|nsvci) <0-65535>",
Harald Welte95647152010-05-16 00:00:04 +0200510 LOGGING_STR FILTER_STR
Harald Welte8be8c8f2010-05-15 23:52:02 +0200511 "Filter based on NS Virtual Connection\n"
512 "Identify NS-VC by NSEI\n"
513 "Identify NS-VC by NSVCI\n"
514 "Numeric identifier\n")
515{
Harald Welte8dcebd32011-02-18 21:10:05 +0100516 struct log_target *tgt = osmo_log_vty2tgt(vty);
Harald Welte8be8c8f2010-05-15 23:52:02 +0200517 struct gprs_nsvc *nsvc;
518 uint16_t id = atoi(argv[1]);
519
Harald Welte8dcebd32011-02-18 21:10:05 +0100520 if (!tgt)
Harald Welte8be8c8f2010-05-15 23:52:02 +0200521 return CMD_WARNING;
Harald Welte8be8c8f2010-05-15 23:52:02 +0200522
523 if (!strcmp(argv[0], "nsei"))
524 nsvc = nsvc_by_nsei(vty_nsi, id);
525 else
526 nsvc = nsvc_by_nsvci(vty_nsi, id);
527
528 if (!nsvc) {
529 vty_out(vty, "No NS-VC by that identifier%s", VTY_NEWLINE);
530 return CMD_WARNING;
531 }
532
Harald Welte8dcebd32011-02-18 21:10:05 +0100533 log_set_nsvc_filter(tgt, nsvc);
Harald Welte8be8c8f2010-05-15 23:52:02 +0200534 return CMD_SUCCESS;
535}
Harald Welte9ef91082010-05-14 19:36:59 +0200536
Harald Weltef2b4cd72010-05-13 11:45:07 +0200537int gprs_ns_vty_init(struct gprs_ns_inst *nsi)
538{
539 vty_nsi = nsi;
540
541 install_element_ve(&show_ns_cmd);
Harald Welte73b23592010-05-13 12:32:30 +0200542 install_element_ve(&show_ns_stats_cmd);
Harald Welte55c91e42010-05-15 23:04:03 +0200543 install_element_ve(&show_nse_cmd);
Harald Welte8be8c8f2010-05-15 23:52:02 +0200544 install_element_ve(&logging_fltr_nsvc_cmd);
Harald Weltef2b4cd72010-05-13 11:45:07 +0200545
Harald Welte8dcebd32011-02-18 21:10:05 +0100546 install_element(CFG_LOG_NODE, &logging_fltr_nsvc_cmd);
547
Harald Weltef2b4cd72010-05-13 11:45:07 +0200548 install_element(CONFIG_NODE, &cfg_ns_cmd);
549 install_node(&ns_node, config_write_ns);
Harald Weltefdd8b3b2012-06-16 16:54:06 +0800550 install_default(L_NS_NODE);
551 install_element(L_NS_NODE, &libgb_exit_cmd);
552 install_element(L_NS_NODE, &libgb_end_cmd);
553 install_element(L_NS_NODE, &cfg_nse_nsvci_cmd);
554 install_element(L_NS_NODE, &cfg_nse_remoteip_cmd);
555 install_element(L_NS_NODE, &cfg_nse_remoteport_cmd);
556 install_element(L_NS_NODE, &cfg_nse_fr_dlci_cmd);
557 install_element(L_NS_NODE, &cfg_nse_encaps_cmd);
558 install_element(L_NS_NODE, &cfg_nse_remoterole_cmd);
559 install_element(L_NS_NODE, &cfg_no_nse_cmd);
560 install_element(L_NS_NODE, &cfg_ns_timer_cmd);
561 install_element(L_NS_NODE, &cfg_nsip_local_ip_cmd);
562 install_element(L_NS_NODE, &cfg_nsip_local_port_cmd);
563 install_element(L_NS_NODE, &cfg_frgre_enable_cmd);
564 install_element(L_NS_NODE, &cfg_frgre_local_ip_cmd);
Harald Weltef2b4cd72010-05-13 11:45:07 +0200565
Harald Welte9ef91082010-05-14 19:36:59 +0200566 install_element(ENABLE_NODE, &nsvc_nsei_cmd);
567
Harald Weltef2b4cd72010-05-13 11:45:07 +0200568 return 0;
569}