blob: 0ae3141972e43484c403433d0f2d44cdf8920255 [file] [log] [blame]
Harald Welte144e0292010-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 Weltee4cbb3f2011-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 Welte144e0292010-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 Weltee4cbb3f2011-01-01 15:25:50 +010015 * GNU Affero General Public License for more details.
Harald Welte144e0292010-05-13 11:45:07 +020016 *
Harald Weltee4cbb3f2011-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 Welte144e0292010-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 Ayusoff663232011-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 Welte73952e32012-06-16 14:59:56 +080034#include <osmocom/gprs/gprs_ns.h>
35#include <osmocom/gprs/gprs_bssgp.h>
Harald Welte144e0292010-05-13 11:45:07 +020036
Harald Welteac1a7152010-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 Ayuso167281e2011-03-28 19:35:00 +020041#include <osmocom/vty/misc.h>
Harald Welte144e0292010-05-13 11:45:07 +020042
Harald Welte73952e32012-06-16 14:59:56 +080043#include <openbsc/debug.h>
Harald Welte4f5883b2012-06-16 16:54:06 +080044
45#include "common_vty.h"
Harald Welte73952e32012-06-16 14:59:56 +080046
Harald Welte144e0292010-05-13 11:45:07 +020047static struct gprs_ns_inst *vty_nsi = NULL;
48
49/* FIXME: this should go to some common file as it is copied
50 * in vty_interface.c of the BSC */
51static const struct value_string gprs_ns_timer_strs[] = {
52 { 0, "tns-block" },
53 { 1, "tns-block-retries" },
54 { 2, "tns-reset" },
55 { 3, "tns-reset-retries" },
56 { 4, "tns-test" },
57 { 5, "tns-alive" },
58 { 6, "tns-alive-retries" },
59 { 0, NULL }
60};
61
62static struct cmd_node ns_node = {
Harald Welte4f5883b2012-06-16 16:54:06 +080063 L_NS_NODE,
Harald Welte144e0292010-05-13 11:45:07 +020064 "%s(ns)#",
65 1,
66};
67
68static int config_write_ns(struct vty *vty)
69{
70 struct gprs_nsvc *nsvc;
71 unsigned int i;
Harald Welte7fb05232010-05-19 15:09:09 +020072 struct in_addr ia;
Harald Welte144e0292010-05-13 11:45:07 +020073
74 vty_out(vty, "ns%s", VTY_NEWLINE);
75
76 llist_for_each_entry(nsvc, &vty_nsi->gprs_nsvcs, list) {
77 if (!nsvc->persistent)
78 continue;
79 vty_out(vty, " nse %u nsvci %u%s",
80 nsvc->nsei, nsvc->nsvci, VTY_NEWLINE);
81 vty_out(vty, " nse %u remote-role %s%s",
82 nsvc->nsei, nsvc->remote_end_is_sgsn ? "sgsn" : "bss",
83 VTY_NEWLINE);
Harald Welteb3ee2652010-05-19 14:38:50 +020084 switch (nsvc->ll) {
85 case GPRS_NS_LL_UDP:
86 vty_out(vty, " nse %u encapsulation udp%s", nsvc->nsei,
87 VTY_NEWLINE);
Harald Welte144e0292010-05-13 11:45:07 +020088 vty_out(vty, " nse %u remote-ip %s%s",
89 nsvc->nsei,
90 inet_ntoa(nsvc->ip.bts_addr.sin_addr),
91 VTY_NEWLINE);
92 vty_out(vty, " nse %u remote-port %u%s",
93 nsvc->nsei, ntohs(nsvc->ip.bts_addr.sin_port),
94 VTY_NEWLINE);
Harald Welteb3ee2652010-05-19 14:38:50 +020095 break;
96 case GPRS_NS_LL_FR_GRE:
97 vty_out(vty, " nse %u encapsulation framerelay-gre%s",
98 nsvc->nsei, VTY_NEWLINE);
99 vty_out(vty, " nse %u remote-ip %s%s",
100 nsvc->nsei,
101 inet_ntoa(nsvc->frgre.bts_addr.sin_addr),
102 VTY_NEWLINE);
103 vty_out(vty, " nse %u fr-dlci %u%s",
104 nsvc->nsei, ntohs(nsvc->frgre.bts_addr.sin_port),
105 VTY_NEWLINE);
106 default:
107 break;
Harald Welte144e0292010-05-13 11:45:07 +0200108 }
109 }
110
111 for (i = 0; i < ARRAY_SIZE(vty_nsi->timeout); i++)
112 vty_out(vty, " timer %s %u%s",
113 get_value_string(gprs_ns_timer_strs, i),
114 vty_nsi->timeout[i], VTY_NEWLINE);
115
Harald Welte7fb05232010-05-19 15:09:09 +0200116 if (vty_nsi->nsip.local_ip) {
117 ia.s_addr = htonl(vty_nsi->nsip.local_ip);
118 vty_out(vty, " encapsulation udp local-ip %s%s",
119 inet_ntoa(ia), VTY_NEWLINE);
Harald Welte7fb05232010-05-19 15:09:09 +0200120 }
Harald Weltece4ccbc2010-05-19 17:02:57 +0200121 if (vty_nsi->nsip.local_port)
122 vty_out(vty, " encapsulation udp local-port %u%s",
123 vty_nsi->nsip.local_port, VTY_NEWLINE);
124
Harald Welte7fb05232010-05-19 15:09:09 +0200125 vty_out(vty, " encapsulation framerelay-gre enabled %u%s",
126 vty_nsi->frgre.enabled ? 1 : 0, VTY_NEWLINE);
Harald Weltece4ccbc2010-05-19 17:02:57 +0200127 if (vty_nsi->frgre.local_ip) {
Harald Welte7fb05232010-05-19 15:09:09 +0200128 ia.s_addr = htonl(vty_nsi->frgre.local_ip);
129 vty_out(vty, " encapsulation framerelay-gre local-ip %s%s",
130 inet_ntoa(ia), VTY_NEWLINE);
131 }
132
Harald Welte144e0292010-05-13 11:45:07 +0200133 return CMD_SUCCESS;
134}
135
136DEFUN(cfg_ns, cfg_ns_cmd,
137 "ns",
138 "Configure the GPRS Network Service")
139{
Harald Welte4f5883b2012-06-16 16:54:06 +0800140 vty->node = L_NS_NODE;
Harald Welte144e0292010-05-13 11:45:07 +0200141 return CMD_SUCCESS;
142}
143
Harald Welte92883342010-05-15 23:04:03 +0200144static void dump_nse(struct vty *vty, struct gprs_nsvc *nsvc, int stats)
145{
146 vty_out(vty, "NSEI %5u, NS-VC %5u, Remote: %-4s, %5s %9s",
147 nsvc->nsei, nsvc->nsvci,
148 nsvc->remote_end_is_sgsn ? "SGSN" : "BSS",
149 nsvc->state & NSE_S_ALIVE ? "ALIVE" : "DEAD",
150 nsvc->state & NSE_S_BLOCKED ? "BLOCKED" : "UNBLOCKED");
Harald Welteb3ee2652010-05-19 14:38:50 +0200151 if (nsvc->ll == GPRS_NS_LL_UDP || nsvc->ll == GPRS_NS_LL_FR_GRE)
152 vty_out(vty, ", %s %15s:%u",
Harald Weltece4ccbc2010-05-19 17:02:57 +0200153 nsvc->ll == GPRS_NS_LL_UDP ? "UDP " : "FR-GRE",
Harald Welte92883342010-05-15 23:04:03 +0200154 inet_ntoa(nsvc->ip.bts_addr.sin_addr),
155 ntohs(nsvc->ip.bts_addr.sin_port));
156 vty_out(vty, "%s", VTY_NEWLINE);
157 if (stats)
158 vty_out_rate_ctr_group(vty, " ", nsvc->ctrg);
159}
160
Harald Welteaf1d4cb2010-05-13 12:32:30 +0200161static void dump_ns(struct vty *vty, struct gprs_ns_inst *nsi, int stats)
Harald Welte144e0292010-05-13 11:45:07 +0200162{
Harald Welte144e0292010-05-13 11:45:07 +0200163 struct gprs_nsvc *nsvc;
Harald Welte7fb05232010-05-19 15:09:09 +0200164 struct in_addr ia;
165
166 ia.s_addr = htonl(vty_nsi->nsip.local_ip);
Harald Weltece4ccbc2010-05-19 17:02:57 +0200167 vty_out(vty, "Encapsulation NS-UDP-IP Local IP: %s, UDP Port: %u%s",
Harald Welte7fb05232010-05-19 15:09:09 +0200168 inet_ntoa(ia), vty_nsi->nsip.local_port, VTY_NEWLINE);
169
170 ia.s_addr = htonl(vty_nsi->frgre.local_ip);
Harald Weltece4ccbc2010-05-19 17:02:57 +0200171 vty_out(vty, "Encapsulation NS-FR-GRE-IP Local IP: %s%s",
Harald Welte7fb05232010-05-19 15:09:09 +0200172 inet_ntoa(ia), VTY_NEWLINE);
Harald Welte144e0292010-05-13 11:45:07 +0200173
174 llist_for_each_entry(nsvc, &nsi->gprs_nsvcs, list) {
Harald Weltedd1c83c2010-05-13 13:58:08 +0200175 if (nsvc == nsi->unknown_nsvc)
176 continue;
Harald Welte92883342010-05-15 23:04:03 +0200177 dump_nse(vty, nsvc, stats);
Harald Welte144e0292010-05-13 11:45:07 +0200178 }
Harald Welteaf1d4cb2010-05-13 12:32:30 +0200179}
Harald Welte144e0292010-05-13 11:45:07 +0200180
Harald Welteaf1d4cb2010-05-13 12:32:30 +0200181DEFUN(show_ns, show_ns_cmd, "show ns",
182 SHOW_STR "Display information about the NS protocol")
183{
184 struct gprs_ns_inst *nsi = vty_nsi;
185 dump_ns(vty, nsi, 0);
Harald Welte144e0292010-05-13 11:45:07 +0200186 return CMD_SUCCESS;
187}
188
Harald Welteaf1d4cb2010-05-13 12:32:30 +0200189DEFUN(show_ns_stats, show_ns_stats_cmd, "show ns stats",
190 SHOW_STR
191 "Display information about the NS protocol\n"
192 "Include statistics\n")
193{
194 struct gprs_ns_inst *nsi = vty_nsi;
195 dump_ns(vty, nsi, 1);
196 return CMD_SUCCESS;
197}
Harald Welte144e0292010-05-13 11:45:07 +0200198
Harald Welte92883342010-05-15 23:04:03 +0200199DEFUN(show_nse, show_nse_cmd, "show ns (nsei|nsvc) <0-65535> [stats]",
200 SHOW_STR "Display information about the NS protocol\n"
201 "Select one NSE by its NSE Identifier\n"
202 "Select one NSE by its NS-VC Identifier\n"
203 "The Identifier of selected type\n"
204 "Include Statistics\n")
205{
206 struct gprs_ns_inst *nsi = vty_nsi;
207 struct gprs_nsvc *nsvc;
208 uint16_t id = atoi(argv[1]);
209 int show_stats = 0;
210
211 if (!strcmp(argv[0], "nsei"))
212 nsvc = nsvc_by_nsei(nsi, id);
213 else
214 nsvc = nsvc_by_nsvci(nsi, id);
215
216 if (!nsvc) {
217 vty_out(vty, "No such NS Entity%s", VTY_NEWLINE);
218 return CMD_WARNING;
219 }
220
221 if (argc >= 3)
222 show_stats = 1;
223
224 dump_nse(vty, nsvc, show_stats);
225 return CMD_SUCCESS;
226}
227
Harald Welte24133c32010-05-15 23:06:26 +0200228#define NSE_CMD_STR "Persistent NS Entity\n" "NS Entity ID (NSEI)\n"
Harald Welte144e0292010-05-13 11:45:07 +0200229
230DEFUN(cfg_nse_nsvc, cfg_nse_nsvci_cmd,
231 "nse <0-65535> nsvci <0-65534>",
232 NSE_CMD_STR
233 "NS Virtual Connection\n"
234 "NS Virtual Connection ID (NSVCI)\n"
235 )
236{
237 uint16_t nsei = atoi(argv[0]);
238 uint16_t nsvci = atoi(argv[1]);
239 struct gprs_nsvc *nsvc;
240
241 nsvc = nsvc_by_nsei(vty_nsi, nsei);
242 if (!nsvc) {
243 nsvc = nsvc_create(vty_nsi, nsvci);
244 nsvc->nsei = nsei;
245 }
246 nsvc->nsvci = nsvci;
247 /* All NSVCs that are explicitly configured by VTY are
248 * marked as persistent so we can write them to the config
249 * file at some later point */
250 nsvc->persistent = 1;
251
252 return CMD_SUCCESS;
253}
254
255DEFUN(cfg_nse_remoteip, cfg_nse_remoteip_cmd,
256 "nse <0-65535> remote-ip A.B.C.D",
257 NSE_CMD_STR
258 "Remote IP Address\n"
259 "Remote IP Address\n")
260{
261 uint16_t nsei = atoi(argv[0]);
262 struct gprs_nsvc *nsvc;
263
264 nsvc = nsvc_by_nsei(vty_nsi, nsei);
265 if (!nsvc) {
266 vty_out(vty, "No such NSE (%u)%s", nsei, VTY_NEWLINE);
267 return CMD_WARNING;
268 }
269 inet_aton(argv[1], &nsvc->ip.bts_addr.sin_addr);
270
271 return CMD_SUCCESS;
272
273}
274
275DEFUN(cfg_nse_remoteport, cfg_nse_remoteport_cmd,
276 "nse <0-65535> remote-port <0-65535>",
277 NSE_CMD_STR
278 "Remote UDP Port\n"
279 "Remote UDP Port Number\n")
280{
281 uint16_t nsei = atoi(argv[0]);
282 uint16_t port = atoi(argv[1]);
283 struct gprs_nsvc *nsvc;
284
285 nsvc = nsvc_by_nsei(vty_nsi, nsei);
286 if (!nsvc) {
287 vty_out(vty, "No such NSE (%u)%s", nsei, VTY_NEWLINE);
288 return CMD_WARNING;
289 }
290
Harald Welteb3ee2652010-05-19 14:38:50 +0200291 if (nsvc->ll != GPRS_NS_LL_UDP) {
292 vty_out(vty, "Cannot set UDP Port on non-UDP NSE%s",
293 VTY_NEWLINE);
294 return CMD_WARNING;
295 }
296
Harald Welte144e0292010-05-13 11:45:07 +0200297 nsvc->ip.bts_addr.sin_port = htons(port);
298
299 return CMD_SUCCESS;
300}
301
Harald Welteb3ee2652010-05-19 14:38:50 +0200302DEFUN(cfg_nse_fr_dlci, cfg_nse_fr_dlci_cmd,
Harald Welte188bda62010-05-28 14:11:49 +0200303 "nse <0-65535> fr-dlci <16-1007>",
Harald Welteb3ee2652010-05-19 14:38:50 +0200304 NSE_CMD_STR
305 "Frame Relay DLCI\n"
306 "Frame Relay DLCI Number\n")
307{
308 uint16_t nsei = atoi(argv[0]);
309 uint16_t dlci = atoi(argv[1]);
310 struct gprs_nsvc *nsvc;
311
312 nsvc = nsvc_by_nsei(vty_nsi, nsei);
313 if (!nsvc) {
314 vty_out(vty, "No such NSE (%u)%s", nsei, VTY_NEWLINE);
315 return CMD_WARNING;
316 }
317
318 if (nsvc->ll != GPRS_NS_LL_FR_GRE) {
319 vty_out(vty, "Cannot set FR DLCI on non-FR NSE%s",
320 VTY_NEWLINE);
321 return CMD_WARNING;
322 }
323
324 nsvc->frgre.bts_addr.sin_port = htons(dlci);
325
326 return CMD_SUCCESS;
327}
328
329DEFUN(cfg_nse_encaps, cfg_nse_encaps_cmd,
330 "nse <0-65535> encapsulation (udp|framerelay-gre)",
331 NSE_CMD_STR
332 "Encapsulation for NS\n"
333 "UDP/IP Encapsulation\n" "Frame-Relay/GRE/IP Encapsulation\n")
334{
335 uint16_t nsei = atoi(argv[0]);
336 struct gprs_nsvc *nsvc;
337
338 nsvc = nsvc_by_nsei(vty_nsi, nsei);
339 if (!nsvc) {
340 vty_out(vty, "No such NSE (%u)%s", nsei, VTY_NEWLINE);
341 return CMD_WARNING;
342 }
343
344 if (!strcmp(argv[1], "udp"))
345 nsvc->ll = GPRS_NS_LL_UDP;
346 else
347 nsvc->ll = GPRS_NS_LL_FR_GRE;
348
349 return CMD_SUCCESS;
350}
351
352
Harald Welte144e0292010-05-13 11:45:07 +0200353DEFUN(cfg_nse_remoterole, cfg_nse_remoterole_cmd,
354 "nse <0-65535> remote-role (sgsn|bss)",
355 NSE_CMD_STR
356 "Remote NSE Role\n"
357 "Remote Peer is SGSN\n"
358 "Remote Peer is BSS\n")
359{
360 uint16_t nsei = atoi(argv[0]);
361 struct gprs_nsvc *nsvc;
362
363 nsvc = nsvc_by_nsei(vty_nsi, nsei);
364 if (!nsvc) {
365 vty_out(vty, "No such NSE (%u)%s", nsei, VTY_NEWLINE);
366 return CMD_WARNING;
367 }
368
369 if (!strcmp(argv[1], "sgsn"))
370 nsvc->remote_end_is_sgsn = 1;
371 else
372 nsvc->remote_end_is_sgsn = 0;
373
374 return CMD_SUCCESS;
375}
376
377DEFUN(cfg_no_nse, cfg_no_nse_cmd,
378 "no nse <0-65535>",
Harald Welte24133c32010-05-15 23:06:26 +0200379 "Delete Persistent NS Entity\n"
Harald Welte144e0292010-05-13 11:45:07 +0200380 "Delete " NSE_CMD_STR)
381{
382 uint16_t nsei = atoi(argv[0]);
383 struct gprs_nsvc *nsvc;
384
385 nsvc = nsvc_by_nsei(vty_nsi, nsei);
386 if (!nsvc) {
387 vty_out(vty, "No such NSE (%u)%s", nsei, VTY_NEWLINE);
388 return CMD_WARNING;
389 }
390
Harald Welte24133c32010-05-15 23:06:26 +0200391 if (!nsvc->persistent) {
392 vty_out(vty, "NSEI %u is not a persistent NSE%s",
393 nsei, VTY_NEWLINE);
394 return CMD_WARNING;
395 }
396
397 nsvc->persistent = 0;
Harald Welte144e0292010-05-13 11:45:07 +0200398
399 return CMD_SUCCESS;
400}
401
402DEFUN(cfg_ns_timer, cfg_ns_timer_cmd,
403 "timer " NS_TIMERS " <0-65535>",
404 "Network Service Timer\n"
405 NS_TIMERS_HELP "Timer Value\n")
406{
407 int idx = get_string_value(gprs_ns_timer_strs, argv[0]);
408 int val = atoi(argv[1]);
409
410 if (idx < 0 || idx >= ARRAY_SIZE(vty_nsi->timeout))
411 return CMD_WARNING;
412
413 vty_nsi->timeout[idx] = val;
414
415 return CMD_SUCCESS;
416}
417
Harald Welte7fb05232010-05-19 15:09:09 +0200418#define ENCAPS_STR "NS encapsulation options\n"
419
420DEFUN(cfg_nsip_local_ip, cfg_nsip_local_ip_cmd,
421 "encapsulation udp local-ip A.B.C.D",
422 ENCAPS_STR "NS over UDP Encapsulation\n"
423 "Set the IP address on which we listen for NS/UDP\n"
424 "IP Address\n")
425{
426 struct in_addr ia;
427
428 inet_aton(argv[0], &ia);
429 vty_nsi->nsip.local_ip = ntohl(ia.s_addr);
430
431 return CMD_SUCCESS;
432}
433
434DEFUN(cfg_nsip_local_port, cfg_nsip_local_port_cmd,
435 "encapsulation udp local-port <0-65535>",
436 ENCAPS_STR "NS over UDP Encapsulation\n"
437 "Set the UDP port on which we listen for NS/UDP\n"
438 "UDP port number\n")
439{
440 unsigned int port = atoi(argv[0]);
441
442 vty_nsi->nsip.local_port = port;
443
444 return CMD_SUCCESS;
445}
446
447DEFUN(cfg_frgre_local_ip, cfg_frgre_local_ip_cmd,
448 "encapsulation framerelay-gre local-ip A.B.C.D",
449 ENCAPS_STR "NS over Frame Relay over GRE Encapsulation\n"
450 "Set the IP address on which we listen for NS/FR/GRE\n"
451 "IP Address\n")
452{
453 struct in_addr ia;
454
455 if (!vty_nsi->frgre.enabled) {
456 vty_out(vty, "FR/GRE is not enabled%s", VTY_NEWLINE);
457 return CMD_WARNING;
458 }
459 inet_aton(argv[0], &ia);
460 vty_nsi->frgre.local_ip = ntohl(ia.s_addr);
461
462 return CMD_SUCCESS;
463}
464
465DEFUN(cfg_frgre_enable, cfg_frgre_enable_cmd,
466 "encapsulation framerelay-gre enabled (1|0)",
467 ENCAPS_STR "NS over Frame Relay over GRE Encapsulation\n"
468 "Enable or disable Frame Relay over GRE\n"
469 "Enable\n" "Disable\n")
470{
471 int enabled = atoi(argv[0]);
472
473 vty_nsi->frgre.enabled = enabled;
474
475 return CMD_SUCCESS;
476}
477
Harald Welte43f3b692010-05-14 19:36:59 +0200478DEFUN(nsvc_nsei, nsvc_nsei_cmd,
479 "nsvc nsei <0-65535> (block|unblock|reset)",
480 "Perform an operation on a NSVC\n"
Holger Hans Peter Freyther887934e2011-11-05 15:14:59 +0100481 "NSEI to identify NS-VC Identifier (NS-VCI)\n"
482 "The NSEI\n"
Harald Welte43f3b692010-05-14 19:36:59 +0200483 "Initiate BLOCK procedure\n"
484 "Initiate UNBLOCK procedure\n"
485 "Initiate RESET procedure\n")
486{
487 uint16_t nsvci = atoi(argv[0]);
488 const char *operation = argv[1];
489 struct gprs_nsvc *nsvc;
490
491 nsvc = nsvc_by_nsei(vty_nsi, nsvci);
492 if (!nsvc) {
493 vty_out(vty, "No such NSVCI (%u)%s", nsvci, VTY_NEWLINE);
494 return CMD_WARNING;
495 }
496
497 if (!strcmp(operation, "block"))
498 gprs_ns_tx_block(nsvc, NS_CAUSE_OM_INTERVENTION);
499 else if (!strcmp(operation, "unblock"))
500 gprs_ns_tx_unblock(nsvc);
501 else if (!strcmp(operation, "reset"))
502 gprs_nsvc_reset(nsvc, NS_CAUSE_OM_INTERVENTION);
503 else
504 return CMD_WARNING;
505
506 return CMD_SUCCESS;
507}
508
Harald Welte91f7f4b2010-05-15 23:52:02 +0200509DEFUN(logging_fltr_nsvc,
510 logging_fltr_nsvc_cmd,
511 "logging filter nsvc (nsei|nsvci) <0-65535>",
Harald Welte6703bf72010-05-16 00:00:04 +0200512 LOGGING_STR FILTER_STR
Harald Welte91f7f4b2010-05-15 23:52:02 +0200513 "Filter based on NS Virtual Connection\n"
514 "Identify NS-VC by NSEI\n"
515 "Identify NS-VC by NSVCI\n"
516 "Numeric identifier\n")
517{
Harald Welte43ae94e2011-02-18 21:10:05 +0100518 struct log_target *tgt = osmo_log_vty2tgt(vty);
Harald Welte91f7f4b2010-05-15 23:52:02 +0200519 struct gprs_nsvc *nsvc;
520 uint16_t id = atoi(argv[1]);
521
Harald Welte43ae94e2011-02-18 21:10:05 +0100522 if (!tgt)
Harald Welte91f7f4b2010-05-15 23:52:02 +0200523 return CMD_WARNING;
Harald Welte91f7f4b2010-05-15 23:52:02 +0200524
525 if (!strcmp(argv[0], "nsei"))
526 nsvc = nsvc_by_nsei(vty_nsi, id);
527 else
528 nsvc = nsvc_by_nsvci(vty_nsi, id);
529
530 if (!nsvc) {
531 vty_out(vty, "No NS-VC by that identifier%s", VTY_NEWLINE);
532 return CMD_WARNING;
533 }
534
Harald Welte43ae94e2011-02-18 21:10:05 +0100535 log_set_nsvc_filter(tgt, nsvc);
Harald Welte91f7f4b2010-05-15 23:52:02 +0200536 return CMD_SUCCESS;
537}
Harald Welte43f3b692010-05-14 19:36:59 +0200538
Harald Welte144e0292010-05-13 11:45:07 +0200539int gprs_ns_vty_init(struct gprs_ns_inst *nsi)
540{
541 vty_nsi = nsi;
542
543 install_element_ve(&show_ns_cmd);
Harald Welteaf1d4cb2010-05-13 12:32:30 +0200544 install_element_ve(&show_ns_stats_cmd);
Harald Welte92883342010-05-15 23:04:03 +0200545 install_element_ve(&show_nse_cmd);
Harald Welte91f7f4b2010-05-15 23:52:02 +0200546 install_element_ve(&logging_fltr_nsvc_cmd);
Harald Welte144e0292010-05-13 11:45:07 +0200547
Harald Welte43ae94e2011-02-18 21:10:05 +0100548 install_element(CFG_LOG_NODE, &logging_fltr_nsvc_cmd);
549
Harald Welte144e0292010-05-13 11:45:07 +0200550 install_element(CONFIG_NODE, &cfg_ns_cmd);
551 install_node(&ns_node, config_write_ns);
Harald Welte4f5883b2012-06-16 16:54:06 +0800552 install_default(L_NS_NODE);
553 install_element(L_NS_NODE, &libgb_exit_cmd);
554 install_element(L_NS_NODE, &libgb_end_cmd);
555 install_element(L_NS_NODE, &cfg_nse_nsvci_cmd);
556 install_element(L_NS_NODE, &cfg_nse_remoteip_cmd);
557 install_element(L_NS_NODE, &cfg_nse_remoteport_cmd);
558 install_element(L_NS_NODE, &cfg_nse_fr_dlci_cmd);
559 install_element(L_NS_NODE, &cfg_nse_encaps_cmd);
560 install_element(L_NS_NODE, &cfg_nse_remoterole_cmd);
561 install_element(L_NS_NODE, &cfg_no_nse_cmd);
562 install_element(L_NS_NODE, &cfg_ns_timer_cmd);
563 install_element(L_NS_NODE, &cfg_nsip_local_ip_cmd);
564 install_element(L_NS_NODE, &cfg_nsip_local_port_cmd);
565 install_element(L_NS_NODE, &cfg_frgre_enable_cmd);
566 install_element(L_NS_NODE, &cfg_frgre_local_ip_cmd);
Harald Welte144e0292010-05-13 11:45:07 +0200567
Harald Welte43f3b692010-05-14 19:36:59 +0200568 install_element(ENABLE_NODE, &nsvc_nsei_cmd);
569
Harald Welte144e0292010-05-13 11:45:07 +0200570 return 0;
571}