blob: f1ab28731476b978b83e8be37dffb7dd47fbd46a [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/gsm_data.h>
44#include <openbsc/debug.h>
45#include <openbsc/signal.h>
46#include <openbsc/vty.h>
47
Harald Welte144e0292010-05-13 11:45:07 +020048static struct gprs_ns_inst *vty_nsi = NULL;
49
50/* FIXME: this should go to some common file as it is copied
51 * in vty_interface.c of the BSC */
52static const struct value_string gprs_ns_timer_strs[] = {
53 { 0, "tns-block" },
54 { 1, "tns-block-retries" },
55 { 2, "tns-reset" },
56 { 3, "tns-reset-retries" },
57 { 4, "tns-test" },
58 { 5, "tns-alive" },
59 { 6, "tns-alive-retries" },
60 { 0, NULL }
61};
62
63static struct cmd_node ns_node = {
64 NS_NODE,
65 "%s(ns)#",
66 1,
67};
68
69static int config_write_ns(struct vty *vty)
70{
71 struct gprs_nsvc *nsvc;
72 unsigned int i;
Harald Welte7fb05232010-05-19 15:09:09 +020073 struct in_addr ia;
Harald Welte144e0292010-05-13 11:45:07 +020074
75 vty_out(vty, "ns%s", VTY_NEWLINE);
76
77 llist_for_each_entry(nsvc, &vty_nsi->gprs_nsvcs, list) {
78 if (!nsvc->persistent)
79 continue;
80 vty_out(vty, " nse %u nsvci %u%s",
81 nsvc->nsei, nsvc->nsvci, VTY_NEWLINE);
82 vty_out(vty, " nse %u remote-role %s%s",
83 nsvc->nsei, nsvc->remote_end_is_sgsn ? "sgsn" : "bss",
84 VTY_NEWLINE);
Harald Welteb3ee2652010-05-19 14:38:50 +020085 switch (nsvc->ll) {
86 case GPRS_NS_LL_UDP:
87 vty_out(vty, " nse %u encapsulation udp%s", nsvc->nsei,
88 VTY_NEWLINE);
Harald Welte144e0292010-05-13 11:45:07 +020089 vty_out(vty, " nse %u remote-ip %s%s",
90 nsvc->nsei,
91 inet_ntoa(nsvc->ip.bts_addr.sin_addr),
92 VTY_NEWLINE);
93 vty_out(vty, " nse %u remote-port %u%s",
94 nsvc->nsei, ntohs(nsvc->ip.bts_addr.sin_port),
95 VTY_NEWLINE);
Harald Welteb3ee2652010-05-19 14:38:50 +020096 break;
97 case GPRS_NS_LL_FR_GRE:
98 vty_out(vty, " nse %u encapsulation framerelay-gre%s",
99 nsvc->nsei, VTY_NEWLINE);
100 vty_out(vty, " nse %u remote-ip %s%s",
101 nsvc->nsei,
102 inet_ntoa(nsvc->frgre.bts_addr.sin_addr),
103 VTY_NEWLINE);
104 vty_out(vty, " nse %u fr-dlci %u%s",
105 nsvc->nsei, ntohs(nsvc->frgre.bts_addr.sin_port),
106 VTY_NEWLINE);
107 default:
108 break;
Harald Welte144e0292010-05-13 11:45:07 +0200109 }
110 }
111
112 for (i = 0; i < ARRAY_SIZE(vty_nsi->timeout); i++)
113 vty_out(vty, " timer %s %u%s",
114 get_value_string(gprs_ns_timer_strs, i),
115 vty_nsi->timeout[i], VTY_NEWLINE);
116
Harald Welte7fb05232010-05-19 15:09:09 +0200117 if (vty_nsi->nsip.local_ip) {
118 ia.s_addr = htonl(vty_nsi->nsip.local_ip);
119 vty_out(vty, " encapsulation udp local-ip %s%s",
120 inet_ntoa(ia), VTY_NEWLINE);
Harald Welte7fb05232010-05-19 15:09:09 +0200121 }
Harald Weltece4ccbc2010-05-19 17:02:57 +0200122 if (vty_nsi->nsip.local_port)
123 vty_out(vty, " encapsulation udp local-port %u%s",
124 vty_nsi->nsip.local_port, VTY_NEWLINE);
125
Harald Welte7fb05232010-05-19 15:09:09 +0200126 vty_out(vty, " encapsulation framerelay-gre enabled %u%s",
127 vty_nsi->frgre.enabled ? 1 : 0, VTY_NEWLINE);
Harald Weltece4ccbc2010-05-19 17:02:57 +0200128 if (vty_nsi->frgre.local_ip) {
Harald Welte7fb05232010-05-19 15:09:09 +0200129 ia.s_addr = htonl(vty_nsi->frgre.local_ip);
130 vty_out(vty, " encapsulation framerelay-gre local-ip %s%s",
131 inet_ntoa(ia), VTY_NEWLINE);
132 }
133
Harald Welte144e0292010-05-13 11:45:07 +0200134 return CMD_SUCCESS;
135}
136
137DEFUN(cfg_ns, cfg_ns_cmd,
138 "ns",
139 "Configure the GPRS Network Service")
140{
141 vty->node = NS_NODE;
142 return CMD_SUCCESS;
143}
144
Harald Welte92883342010-05-15 23:04:03 +0200145static void dump_nse(struct vty *vty, struct gprs_nsvc *nsvc, int stats)
146{
147 vty_out(vty, "NSEI %5u, NS-VC %5u, Remote: %-4s, %5s %9s",
148 nsvc->nsei, nsvc->nsvci,
149 nsvc->remote_end_is_sgsn ? "SGSN" : "BSS",
150 nsvc->state & NSE_S_ALIVE ? "ALIVE" : "DEAD",
151 nsvc->state & NSE_S_BLOCKED ? "BLOCKED" : "UNBLOCKED");
Harald Welteb3ee2652010-05-19 14:38:50 +0200152 if (nsvc->ll == GPRS_NS_LL_UDP || nsvc->ll == GPRS_NS_LL_FR_GRE)
153 vty_out(vty, ", %s %15s:%u",
Harald Weltece4ccbc2010-05-19 17:02:57 +0200154 nsvc->ll == GPRS_NS_LL_UDP ? "UDP " : "FR-GRE",
Harald Welte92883342010-05-15 23:04:03 +0200155 inet_ntoa(nsvc->ip.bts_addr.sin_addr),
156 ntohs(nsvc->ip.bts_addr.sin_port));
157 vty_out(vty, "%s", VTY_NEWLINE);
158 if (stats)
159 vty_out_rate_ctr_group(vty, " ", nsvc->ctrg);
160}
161
Harald Welteaf1d4cb2010-05-13 12:32:30 +0200162static void dump_ns(struct vty *vty, struct gprs_ns_inst *nsi, int stats)
Harald Welte144e0292010-05-13 11:45:07 +0200163{
Harald Welte144e0292010-05-13 11:45:07 +0200164 struct gprs_nsvc *nsvc;
Harald Welte7fb05232010-05-19 15:09:09 +0200165 struct in_addr ia;
166
167 ia.s_addr = htonl(vty_nsi->nsip.local_ip);
Harald Weltece4ccbc2010-05-19 17:02:57 +0200168 vty_out(vty, "Encapsulation NS-UDP-IP Local IP: %s, UDP Port: %u%s",
Harald Welte7fb05232010-05-19 15:09:09 +0200169 inet_ntoa(ia), vty_nsi->nsip.local_port, VTY_NEWLINE);
170
171 ia.s_addr = htonl(vty_nsi->frgre.local_ip);
Harald Weltece4ccbc2010-05-19 17:02:57 +0200172 vty_out(vty, "Encapsulation NS-FR-GRE-IP Local IP: %s%s",
Harald Welte7fb05232010-05-19 15:09:09 +0200173 inet_ntoa(ia), VTY_NEWLINE);
Harald Welte144e0292010-05-13 11:45:07 +0200174
175 llist_for_each_entry(nsvc, &nsi->gprs_nsvcs, list) {
Harald Weltedd1c83c2010-05-13 13:58:08 +0200176 if (nsvc == nsi->unknown_nsvc)
177 continue;
Harald Welte92883342010-05-15 23:04:03 +0200178 dump_nse(vty, nsvc, stats);
Harald Welte144e0292010-05-13 11:45:07 +0200179 }
Harald Welteaf1d4cb2010-05-13 12:32:30 +0200180}
Harald Welte144e0292010-05-13 11:45:07 +0200181
Harald Welteaf1d4cb2010-05-13 12:32:30 +0200182DEFUN(show_ns, show_ns_cmd, "show ns",
183 SHOW_STR "Display information about the NS protocol")
184{
185 struct gprs_ns_inst *nsi = vty_nsi;
186 dump_ns(vty, nsi, 0);
Harald Welte144e0292010-05-13 11:45:07 +0200187 return CMD_SUCCESS;
188}
189
Harald Welteaf1d4cb2010-05-13 12:32:30 +0200190DEFUN(show_ns_stats, show_ns_stats_cmd, "show ns stats",
191 SHOW_STR
192 "Display information about the NS protocol\n"
193 "Include statistics\n")
194{
195 struct gprs_ns_inst *nsi = vty_nsi;
196 dump_ns(vty, nsi, 1);
197 return CMD_SUCCESS;
198}
Harald Welte144e0292010-05-13 11:45:07 +0200199
Harald Welte92883342010-05-15 23:04:03 +0200200DEFUN(show_nse, show_nse_cmd, "show ns (nsei|nsvc) <0-65535> [stats]",
201 SHOW_STR "Display information about the NS protocol\n"
202 "Select one NSE by its NSE Identifier\n"
203 "Select one NSE by its NS-VC Identifier\n"
204 "The Identifier of selected type\n"
205 "Include Statistics\n")
206{
207 struct gprs_ns_inst *nsi = vty_nsi;
208 struct gprs_nsvc *nsvc;
209 uint16_t id = atoi(argv[1]);
210 int show_stats = 0;
211
212 if (!strcmp(argv[0], "nsei"))
213 nsvc = nsvc_by_nsei(nsi, id);
214 else
215 nsvc = nsvc_by_nsvci(nsi, id);
216
217 if (!nsvc) {
218 vty_out(vty, "No such NS Entity%s", VTY_NEWLINE);
219 return CMD_WARNING;
220 }
221
222 if (argc >= 3)
223 show_stats = 1;
224
225 dump_nse(vty, nsvc, show_stats);
226 return CMD_SUCCESS;
227}
228
Harald Welte24133c32010-05-15 23:06:26 +0200229#define NSE_CMD_STR "Persistent NS Entity\n" "NS Entity ID (NSEI)\n"
Harald Welte144e0292010-05-13 11:45:07 +0200230
231DEFUN(cfg_nse_nsvc, cfg_nse_nsvci_cmd,
232 "nse <0-65535> nsvci <0-65534>",
233 NSE_CMD_STR
234 "NS Virtual Connection\n"
235 "NS Virtual Connection ID (NSVCI)\n"
236 )
237{
238 uint16_t nsei = atoi(argv[0]);
239 uint16_t nsvci = atoi(argv[1]);
240 struct gprs_nsvc *nsvc;
241
242 nsvc = nsvc_by_nsei(vty_nsi, nsei);
243 if (!nsvc) {
244 nsvc = nsvc_create(vty_nsi, nsvci);
245 nsvc->nsei = nsei;
246 }
247 nsvc->nsvci = nsvci;
248 /* All NSVCs that are explicitly configured by VTY are
249 * marked as persistent so we can write them to the config
250 * file at some later point */
251 nsvc->persistent = 1;
252
253 return CMD_SUCCESS;
254}
255
256DEFUN(cfg_nse_remoteip, cfg_nse_remoteip_cmd,
257 "nse <0-65535> remote-ip A.B.C.D",
258 NSE_CMD_STR
259 "Remote IP Address\n"
260 "Remote IP Address\n")
261{
262 uint16_t nsei = atoi(argv[0]);
263 struct gprs_nsvc *nsvc;
264
265 nsvc = nsvc_by_nsei(vty_nsi, nsei);
266 if (!nsvc) {
267 vty_out(vty, "No such NSE (%u)%s", nsei, VTY_NEWLINE);
268 return CMD_WARNING;
269 }
270 inet_aton(argv[1], &nsvc->ip.bts_addr.sin_addr);
271
272 return CMD_SUCCESS;
273
274}
275
276DEFUN(cfg_nse_remoteport, cfg_nse_remoteport_cmd,
277 "nse <0-65535> remote-port <0-65535>",
278 NSE_CMD_STR
279 "Remote UDP Port\n"
280 "Remote UDP Port Number\n")
281{
282 uint16_t nsei = atoi(argv[0]);
283 uint16_t port = atoi(argv[1]);
284 struct gprs_nsvc *nsvc;
285
286 nsvc = nsvc_by_nsei(vty_nsi, nsei);
287 if (!nsvc) {
288 vty_out(vty, "No such NSE (%u)%s", nsei, VTY_NEWLINE);
289 return CMD_WARNING;
290 }
291
Harald Welteb3ee2652010-05-19 14:38:50 +0200292 if (nsvc->ll != GPRS_NS_LL_UDP) {
293 vty_out(vty, "Cannot set UDP Port on non-UDP NSE%s",
294 VTY_NEWLINE);
295 return CMD_WARNING;
296 }
297
Harald Welte144e0292010-05-13 11:45:07 +0200298 nsvc->ip.bts_addr.sin_port = htons(port);
299
300 return CMD_SUCCESS;
301}
302
Harald Welteb3ee2652010-05-19 14:38:50 +0200303DEFUN(cfg_nse_fr_dlci, cfg_nse_fr_dlci_cmd,
Harald Welte188bda62010-05-28 14:11:49 +0200304 "nse <0-65535> fr-dlci <16-1007>",
Harald Welteb3ee2652010-05-19 14:38:50 +0200305 NSE_CMD_STR
306 "Frame Relay DLCI\n"
307 "Frame Relay DLCI Number\n")
308{
309 uint16_t nsei = atoi(argv[0]);
310 uint16_t dlci = atoi(argv[1]);
311 struct gprs_nsvc *nsvc;
312
313 nsvc = nsvc_by_nsei(vty_nsi, nsei);
314 if (!nsvc) {
315 vty_out(vty, "No such NSE (%u)%s", nsei, VTY_NEWLINE);
316 return CMD_WARNING;
317 }
318
319 if (nsvc->ll != GPRS_NS_LL_FR_GRE) {
320 vty_out(vty, "Cannot set FR DLCI on non-FR NSE%s",
321 VTY_NEWLINE);
322 return CMD_WARNING;
323 }
324
325 nsvc->frgre.bts_addr.sin_port = htons(dlci);
326
327 return CMD_SUCCESS;
328}
329
330DEFUN(cfg_nse_encaps, cfg_nse_encaps_cmd,
331 "nse <0-65535> encapsulation (udp|framerelay-gre)",
332 NSE_CMD_STR
333 "Encapsulation for NS\n"
334 "UDP/IP Encapsulation\n" "Frame-Relay/GRE/IP Encapsulation\n")
335{
336 uint16_t nsei = atoi(argv[0]);
337 struct gprs_nsvc *nsvc;
338
339 nsvc = nsvc_by_nsei(vty_nsi, nsei);
340 if (!nsvc) {
341 vty_out(vty, "No such NSE (%u)%s", nsei, VTY_NEWLINE);
342 return CMD_WARNING;
343 }
344
345 if (!strcmp(argv[1], "udp"))
346 nsvc->ll = GPRS_NS_LL_UDP;
347 else
348 nsvc->ll = GPRS_NS_LL_FR_GRE;
349
350 return CMD_SUCCESS;
351}
352
353
Harald Welte144e0292010-05-13 11:45:07 +0200354DEFUN(cfg_nse_remoterole, cfg_nse_remoterole_cmd,
355 "nse <0-65535> remote-role (sgsn|bss)",
356 NSE_CMD_STR
357 "Remote NSE Role\n"
358 "Remote Peer is SGSN\n"
359 "Remote Peer is BSS\n")
360{
361 uint16_t nsei = atoi(argv[0]);
362 struct gprs_nsvc *nsvc;
363
364 nsvc = nsvc_by_nsei(vty_nsi, nsei);
365 if (!nsvc) {
366 vty_out(vty, "No such NSE (%u)%s", nsei, VTY_NEWLINE);
367 return CMD_WARNING;
368 }
369
370 if (!strcmp(argv[1], "sgsn"))
371 nsvc->remote_end_is_sgsn = 1;
372 else
373 nsvc->remote_end_is_sgsn = 0;
374
375 return CMD_SUCCESS;
376}
377
378DEFUN(cfg_no_nse, cfg_no_nse_cmd,
379 "no nse <0-65535>",
Harald Welte24133c32010-05-15 23:06:26 +0200380 "Delete Persistent NS Entity\n"
Harald Welte144e0292010-05-13 11:45:07 +0200381 "Delete " NSE_CMD_STR)
382{
383 uint16_t nsei = atoi(argv[0]);
384 struct gprs_nsvc *nsvc;
385
386 nsvc = nsvc_by_nsei(vty_nsi, nsei);
387 if (!nsvc) {
388 vty_out(vty, "No such NSE (%u)%s", nsei, VTY_NEWLINE);
389 return CMD_WARNING;
390 }
391
Harald Welte24133c32010-05-15 23:06:26 +0200392 if (!nsvc->persistent) {
393 vty_out(vty, "NSEI %u is not a persistent NSE%s",
394 nsei, VTY_NEWLINE);
395 return CMD_WARNING;
396 }
397
398 nsvc->persistent = 0;
Harald Welte144e0292010-05-13 11:45:07 +0200399
400 return CMD_SUCCESS;
401}
402
403DEFUN(cfg_ns_timer, cfg_ns_timer_cmd,
404 "timer " NS_TIMERS " <0-65535>",
405 "Network Service Timer\n"
406 NS_TIMERS_HELP "Timer Value\n")
407{
408 int idx = get_string_value(gprs_ns_timer_strs, argv[0]);
409 int val = atoi(argv[1]);
410
411 if (idx < 0 || idx >= ARRAY_SIZE(vty_nsi->timeout))
412 return CMD_WARNING;
413
414 vty_nsi->timeout[idx] = val;
415
416 return CMD_SUCCESS;
417}
418
Harald Welte7fb05232010-05-19 15:09:09 +0200419#define ENCAPS_STR "NS encapsulation options\n"
420
421DEFUN(cfg_nsip_local_ip, cfg_nsip_local_ip_cmd,
422 "encapsulation udp local-ip A.B.C.D",
423 ENCAPS_STR "NS over UDP Encapsulation\n"
424 "Set the IP address on which we listen for NS/UDP\n"
425 "IP Address\n")
426{
427 struct in_addr ia;
428
429 inet_aton(argv[0], &ia);
430 vty_nsi->nsip.local_ip = ntohl(ia.s_addr);
431
432 return CMD_SUCCESS;
433}
434
435DEFUN(cfg_nsip_local_port, cfg_nsip_local_port_cmd,
436 "encapsulation udp local-port <0-65535>",
437 ENCAPS_STR "NS over UDP Encapsulation\n"
438 "Set the UDP port on which we listen for NS/UDP\n"
439 "UDP port number\n")
440{
441 unsigned int port = atoi(argv[0]);
442
443 vty_nsi->nsip.local_port = port;
444
445 return CMD_SUCCESS;
446}
447
448DEFUN(cfg_frgre_local_ip, cfg_frgre_local_ip_cmd,
449 "encapsulation framerelay-gre local-ip A.B.C.D",
450 ENCAPS_STR "NS over Frame Relay over GRE Encapsulation\n"
451 "Set the IP address on which we listen for NS/FR/GRE\n"
452 "IP Address\n")
453{
454 struct in_addr ia;
455
456 if (!vty_nsi->frgre.enabled) {
457 vty_out(vty, "FR/GRE is not enabled%s", VTY_NEWLINE);
458 return CMD_WARNING;
459 }
460 inet_aton(argv[0], &ia);
461 vty_nsi->frgre.local_ip = ntohl(ia.s_addr);
462
463 return CMD_SUCCESS;
464}
465
466DEFUN(cfg_frgre_enable, cfg_frgre_enable_cmd,
467 "encapsulation framerelay-gre enabled (1|0)",
468 ENCAPS_STR "NS over Frame Relay over GRE Encapsulation\n"
469 "Enable or disable Frame Relay over GRE\n"
470 "Enable\n" "Disable\n")
471{
472 int enabled = atoi(argv[0]);
473
474 vty_nsi->frgre.enabled = enabled;
475
476 return CMD_SUCCESS;
477}
478
Harald Welte43f3b692010-05-14 19:36:59 +0200479DEFUN(nsvc_nsei, nsvc_nsei_cmd,
480 "nsvc nsei <0-65535> (block|unblock|reset)",
481 "Perform an operation on a NSVC\n"
Holger Hans Peter Freyther887934e2011-11-05 15:14:59 +0100482 "NSEI to identify NS-VC Identifier (NS-VCI)\n"
483 "The NSEI\n"
Harald Welte43f3b692010-05-14 19:36:59 +0200484 "Initiate BLOCK procedure\n"
485 "Initiate UNBLOCK procedure\n"
486 "Initiate RESET procedure\n")
487{
488 uint16_t nsvci = atoi(argv[0]);
489 const char *operation = argv[1];
490 struct gprs_nsvc *nsvc;
491
492 nsvc = nsvc_by_nsei(vty_nsi, nsvci);
493 if (!nsvc) {
494 vty_out(vty, "No such NSVCI (%u)%s", nsvci, VTY_NEWLINE);
495 return CMD_WARNING;
496 }
497
498 if (!strcmp(operation, "block"))
499 gprs_ns_tx_block(nsvc, NS_CAUSE_OM_INTERVENTION);
500 else if (!strcmp(operation, "unblock"))
501 gprs_ns_tx_unblock(nsvc);
502 else if (!strcmp(operation, "reset"))
503 gprs_nsvc_reset(nsvc, NS_CAUSE_OM_INTERVENTION);
504 else
505 return CMD_WARNING;
506
507 return CMD_SUCCESS;
508}
509
Harald Welte91f7f4b2010-05-15 23:52:02 +0200510DEFUN(logging_fltr_nsvc,
511 logging_fltr_nsvc_cmd,
512 "logging filter nsvc (nsei|nsvci) <0-65535>",
Harald Welte6703bf72010-05-16 00:00:04 +0200513 LOGGING_STR FILTER_STR
Harald Welte91f7f4b2010-05-15 23:52:02 +0200514 "Filter based on NS Virtual Connection\n"
515 "Identify NS-VC by NSEI\n"
516 "Identify NS-VC by NSVCI\n"
517 "Numeric identifier\n")
518{
Harald Welte43ae94e2011-02-18 21:10:05 +0100519 struct log_target *tgt = osmo_log_vty2tgt(vty);
Harald Welte91f7f4b2010-05-15 23:52:02 +0200520 struct gprs_nsvc *nsvc;
521 uint16_t id = atoi(argv[1]);
522
Harald Welte43ae94e2011-02-18 21:10:05 +0100523 if (!tgt)
Harald Welte91f7f4b2010-05-15 23:52:02 +0200524 return CMD_WARNING;
Harald Welte91f7f4b2010-05-15 23:52:02 +0200525
526 if (!strcmp(argv[0], "nsei"))
527 nsvc = nsvc_by_nsei(vty_nsi, id);
528 else
529 nsvc = nsvc_by_nsvci(vty_nsi, id);
530
531 if (!nsvc) {
532 vty_out(vty, "No NS-VC by that identifier%s", VTY_NEWLINE);
533 return CMD_WARNING;
534 }
535
Harald Welte43ae94e2011-02-18 21:10:05 +0100536 log_set_nsvc_filter(tgt, nsvc);
Harald Welte91f7f4b2010-05-15 23:52:02 +0200537 return CMD_SUCCESS;
538}
Harald Welte43f3b692010-05-14 19:36:59 +0200539
Harald Welte144e0292010-05-13 11:45:07 +0200540int gprs_ns_vty_init(struct gprs_ns_inst *nsi)
541{
542 vty_nsi = nsi;
543
544 install_element_ve(&show_ns_cmd);
Harald Welteaf1d4cb2010-05-13 12:32:30 +0200545 install_element_ve(&show_ns_stats_cmd);
Harald Welte92883342010-05-15 23:04:03 +0200546 install_element_ve(&show_nse_cmd);
Harald Welte91f7f4b2010-05-15 23:52:02 +0200547 install_element_ve(&logging_fltr_nsvc_cmd);
Harald Welte144e0292010-05-13 11:45:07 +0200548
Harald Welte43ae94e2011-02-18 21:10:05 +0100549 install_element(CFG_LOG_NODE, &logging_fltr_nsvc_cmd);
550
Harald Welte144e0292010-05-13 11:45:07 +0200551 install_element(CONFIG_NODE, &cfg_ns_cmd);
552 install_node(&ns_node, config_write_ns);
553 install_default(NS_NODE);
Harald Welte804fc812010-05-14 18:59:17 +0200554 install_element(NS_NODE, &ournode_exit_cmd);
Harald Weltea52ff452010-05-14 19:11:04 +0200555 install_element(NS_NODE, &ournode_end_cmd);
Harald Welte144e0292010-05-13 11:45:07 +0200556 install_element(NS_NODE, &cfg_nse_nsvci_cmd);
557 install_element(NS_NODE, &cfg_nse_remoteip_cmd);
558 install_element(NS_NODE, &cfg_nse_remoteport_cmd);
Harald Welteb3ee2652010-05-19 14:38:50 +0200559 install_element(NS_NODE, &cfg_nse_fr_dlci_cmd);
560 install_element(NS_NODE, &cfg_nse_encaps_cmd);
Harald Welte144e0292010-05-13 11:45:07 +0200561 install_element(NS_NODE, &cfg_nse_remoterole_cmd);
562 install_element(NS_NODE, &cfg_no_nse_cmd);
563 install_element(NS_NODE, &cfg_ns_timer_cmd);
Harald Welte7fb05232010-05-19 15:09:09 +0200564 install_element(NS_NODE, &cfg_nsip_local_ip_cmd);
565 install_element(NS_NODE, &cfg_nsip_local_port_cmd);
566 install_element(NS_NODE, &cfg_frgre_enable_cmd);
567 install_element(NS_NODE, &cfg_frgre_local_ip_cmd);
Harald Welte144e0292010-05-13 11:45:07 +0200568
Harald Welte43f3b692010-05-14 19:36:59 +0200569 install_element(ENABLE_NODE, &nsvc_nsei_cmd);
570
Harald Welte144e0292010-05-13 11:45:07 +0200571 return 0;
572}