blob: fac431cb44ef16c2d22a878a1e2cc2ef6e971403 [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 Welte4f5883b2012-06-16 16:54:06 +080043#include "common_vty.h"
Harald Welte73952e32012-06-16 14:59:56 +080044
Harald Welte144e0292010-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
Harald Weltef5430362012-06-17 12:25:53 +080060static void log_set_nsvc_filter(struct log_target *target,
61 struct gprs_nsvc *nsvc)
62{
63 if (nsvc) {
64 target->filter_map |= (1 << FLT_NSVC);
65 target->filter_data[FLT_NSVC] = nsvc;
66 } else if (target->filter_data[FLT_NSVC]) {
67 target->filter_map = ~(1 << FLT_NSVC);
68 target->filter_data[FLT_NSVC] = NULL;
69 }
70}
71
Harald Welte144e0292010-05-13 11:45:07 +020072static struct cmd_node ns_node = {
Harald Welte4f5883b2012-06-16 16:54:06 +080073 L_NS_NODE,
Harald Welte144e0292010-05-13 11:45:07 +020074 "%s(ns)#",
75 1,
76};
77
78static int config_write_ns(struct vty *vty)
79{
80 struct gprs_nsvc *nsvc;
81 unsigned int i;
Harald Welte7fb05232010-05-19 15:09:09 +020082 struct in_addr ia;
Harald Welte144e0292010-05-13 11:45:07 +020083
84 vty_out(vty, "ns%s", VTY_NEWLINE);
85
86 llist_for_each_entry(nsvc, &vty_nsi->gprs_nsvcs, list) {
87 if (!nsvc->persistent)
88 continue;
89 vty_out(vty, " nse %u nsvci %u%s",
90 nsvc->nsei, nsvc->nsvci, VTY_NEWLINE);
91 vty_out(vty, " nse %u remote-role %s%s",
92 nsvc->nsei, nsvc->remote_end_is_sgsn ? "sgsn" : "bss",
93 VTY_NEWLINE);
Harald Welteb3ee2652010-05-19 14:38:50 +020094 switch (nsvc->ll) {
95 case GPRS_NS_LL_UDP:
96 vty_out(vty, " nse %u encapsulation udp%s", nsvc->nsei,
97 VTY_NEWLINE);
Harald Welte144e0292010-05-13 11:45:07 +020098 vty_out(vty, " nse %u remote-ip %s%s",
99 nsvc->nsei,
100 inet_ntoa(nsvc->ip.bts_addr.sin_addr),
101 VTY_NEWLINE);
102 vty_out(vty, " nse %u remote-port %u%s",
103 nsvc->nsei, ntohs(nsvc->ip.bts_addr.sin_port),
104 VTY_NEWLINE);
Harald Welteb3ee2652010-05-19 14:38:50 +0200105 break;
106 case GPRS_NS_LL_FR_GRE:
107 vty_out(vty, " nse %u encapsulation framerelay-gre%s",
108 nsvc->nsei, VTY_NEWLINE);
109 vty_out(vty, " nse %u remote-ip %s%s",
110 nsvc->nsei,
111 inet_ntoa(nsvc->frgre.bts_addr.sin_addr),
112 VTY_NEWLINE);
113 vty_out(vty, " nse %u fr-dlci %u%s",
114 nsvc->nsei, ntohs(nsvc->frgre.bts_addr.sin_port),
115 VTY_NEWLINE);
116 default:
117 break;
Harald Welte144e0292010-05-13 11:45:07 +0200118 }
119 }
120
121 for (i = 0; i < ARRAY_SIZE(vty_nsi->timeout); i++)
122 vty_out(vty, " timer %s %u%s",
123 get_value_string(gprs_ns_timer_strs, i),
124 vty_nsi->timeout[i], VTY_NEWLINE);
125
Harald Welte7fb05232010-05-19 15:09:09 +0200126 if (vty_nsi->nsip.local_ip) {
127 ia.s_addr = htonl(vty_nsi->nsip.local_ip);
128 vty_out(vty, " encapsulation udp local-ip %s%s",
129 inet_ntoa(ia), VTY_NEWLINE);
Harald Welte7fb05232010-05-19 15:09:09 +0200130 }
Harald Weltece4ccbc2010-05-19 17:02:57 +0200131 if (vty_nsi->nsip.local_port)
132 vty_out(vty, " encapsulation udp local-port %u%s",
133 vty_nsi->nsip.local_port, VTY_NEWLINE);
134
Harald Welte7fb05232010-05-19 15:09:09 +0200135 vty_out(vty, " encapsulation framerelay-gre enabled %u%s",
136 vty_nsi->frgre.enabled ? 1 : 0, VTY_NEWLINE);
Harald Weltece4ccbc2010-05-19 17:02:57 +0200137 if (vty_nsi->frgre.local_ip) {
Harald Welte7fb05232010-05-19 15:09:09 +0200138 ia.s_addr = htonl(vty_nsi->frgre.local_ip);
139 vty_out(vty, " encapsulation framerelay-gre local-ip %s%s",
140 inet_ntoa(ia), VTY_NEWLINE);
141 }
142
Harald Welte144e0292010-05-13 11:45:07 +0200143 return CMD_SUCCESS;
144}
145
146DEFUN(cfg_ns, cfg_ns_cmd,
147 "ns",
148 "Configure the GPRS Network Service")
149{
Harald Welte4f5883b2012-06-16 16:54:06 +0800150 vty->node = L_NS_NODE;
Harald Welte144e0292010-05-13 11:45:07 +0200151 return CMD_SUCCESS;
152}
153
Harald Welte92883342010-05-15 23:04:03 +0200154static void dump_nse(struct vty *vty, struct gprs_nsvc *nsvc, int stats)
155{
156 vty_out(vty, "NSEI %5u, NS-VC %5u, Remote: %-4s, %5s %9s",
157 nsvc->nsei, nsvc->nsvci,
158 nsvc->remote_end_is_sgsn ? "SGSN" : "BSS",
159 nsvc->state & NSE_S_ALIVE ? "ALIVE" : "DEAD",
160 nsvc->state & NSE_S_BLOCKED ? "BLOCKED" : "UNBLOCKED");
Harald Welteb3ee2652010-05-19 14:38:50 +0200161 if (nsvc->ll == GPRS_NS_LL_UDP || nsvc->ll == GPRS_NS_LL_FR_GRE)
162 vty_out(vty, ", %s %15s:%u",
Harald Weltece4ccbc2010-05-19 17:02:57 +0200163 nsvc->ll == GPRS_NS_LL_UDP ? "UDP " : "FR-GRE",
Harald Welte92883342010-05-15 23:04:03 +0200164 inet_ntoa(nsvc->ip.bts_addr.sin_addr),
165 ntohs(nsvc->ip.bts_addr.sin_port));
166 vty_out(vty, "%s", VTY_NEWLINE);
167 if (stats)
168 vty_out_rate_ctr_group(vty, " ", nsvc->ctrg);
169}
170
Harald Welteaf1d4cb2010-05-13 12:32:30 +0200171static void dump_ns(struct vty *vty, struct gprs_ns_inst *nsi, int stats)
Harald Welte144e0292010-05-13 11:45:07 +0200172{
Harald Welte144e0292010-05-13 11:45:07 +0200173 struct gprs_nsvc *nsvc;
Harald Welte7fb05232010-05-19 15:09:09 +0200174 struct in_addr ia;
175
176 ia.s_addr = htonl(vty_nsi->nsip.local_ip);
Harald Weltece4ccbc2010-05-19 17:02:57 +0200177 vty_out(vty, "Encapsulation NS-UDP-IP Local IP: %s, UDP Port: %u%s",
Harald Welte7fb05232010-05-19 15:09:09 +0200178 inet_ntoa(ia), vty_nsi->nsip.local_port, VTY_NEWLINE);
179
180 ia.s_addr = htonl(vty_nsi->frgre.local_ip);
Harald Weltece4ccbc2010-05-19 17:02:57 +0200181 vty_out(vty, "Encapsulation NS-FR-GRE-IP Local IP: %s%s",
Harald Welte7fb05232010-05-19 15:09:09 +0200182 inet_ntoa(ia), VTY_NEWLINE);
Harald Welte144e0292010-05-13 11:45:07 +0200183
184 llist_for_each_entry(nsvc, &nsi->gprs_nsvcs, list) {
Harald Weltedd1c83c2010-05-13 13:58:08 +0200185 if (nsvc == nsi->unknown_nsvc)
186 continue;
Harald Welte92883342010-05-15 23:04:03 +0200187 dump_nse(vty, nsvc, stats);
Harald Welte144e0292010-05-13 11:45:07 +0200188 }
Harald Welteaf1d4cb2010-05-13 12:32:30 +0200189}
Harald Welte144e0292010-05-13 11:45:07 +0200190
Harald Welteaf1d4cb2010-05-13 12:32:30 +0200191DEFUN(show_ns, show_ns_cmd, "show ns",
192 SHOW_STR "Display information about the NS protocol")
193{
194 struct gprs_ns_inst *nsi = vty_nsi;
195 dump_ns(vty, nsi, 0);
Harald Welte144e0292010-05-13 11:45:07 +0200196 return CMD_SUCCESS;
197}
198
Harald Welteaf1d4cb2010-05-13 12:32:30 +0200199DEFUN(show_ns_stats, show_ns_stats_cmd, "show ns stats",
200 SHOW_STR
201 "Display information about the NS protocol\n"
202 "Include statistics\n")
203{
204 struct gprs_ns_inst *nsi = vty_nsi;
205 dump_ns(vty, nsi, 1);
206 return CMD_SUCCESS;
207}
Harald Welte144e0292010-05-13 11:45:07 +0200208
Harald Welte92883342010-05-15 23:04:03 +0200209DEFUN(show_nse, show_nse_cmd, "show ns (nsei|nsvc) <0-65535> [stats]",
210 SHOW_STR "Display information about the NS protocol\n"
211 "Select one NSE by its NSE Identifier\n"
212 "Select one NSE by its NS-VC Identifier\n"
213 "The Identifier of selected type\n"
214 "Include Statistics\n")
215{
216 struct gprs_ns_inst *nsi = vty_nsi;
217 struct gprs_nsvc *nsvc;
218 uint16_t id = atoi(argv[1]);
219 int show_stats = 0;
220
221 if (!strcmp(argv[0], "nsei"))
Harald Weltef5430362012-06-17 12:25:53 +0800222 nsvc = gprs_nsvc_by_nsei(nsi, id);
Harald Welte92883342010-05-15 23:04:03 +0200223 else
Harald Weltef5430362012-06-17 12:25:53 +0800224 nsvc = gprs_nsvc_by_nsvci(nsi, id);
Harald Welte92883342010-05-15 23:04:03 +0200225
226 if (!nsvc) {
227 vty_out(vty, "No such NS Entity%s", VTY_NEWLINE);
228 return CMD_WARNING;
229 }
230
231 if (argc >= 3)
232 show_stats = 1;
233
234 dump_nse(vty, nsvc, show_stats);
235 return CMD_SUCCESS;
236}
237
Harald Welte24133c32010-05-15 23:06:26 +0200238#define NSE_CMD_STR "Persistent NS Entity\n" "NS Entity ID (NSEI)\n"
Harald Welte144e0292010-05-13 11:45:07 +0200239
240DEFUN(cfg_nse_nsvc, cfg_nse_nsvci_cmd,
241 "nse <0-65535> nsvci <0-65534>",
242 NSE_CMD_STR
243 "NS Virtual Connection\n"
244 "NS Virtual Connection ID (NSVCI)\n"
245 )
246{
247 uint16_t nsei = atoi(argv[0]);
248 uint16_t nsvci = atoi(argv[1]);
249 struct gprs_nsvc *nsvc;
250
Harald Weltef5430362012-06-17 12:25:53 +0800251 nsvc = gprs_nsvc_by_nsei(vty_nsi, nsei);
Harald Welte144e0292010-05-13 11:45:07 +0200252 if (!nsvc) {
Harald Weltef5430362012-06-17 12:25:53 +0800253 nsvc = gprs_nsvc_create(vty_nsi, nsvci);
Harald Welte144e0292010-05-13 11:45:07 +0200254 nsvc->nsei = nsei;
255 }
256 nsvc->nsvci = nsvci;
257 /* All NSVCs that are explicitly configured by VTY are
258 * marked as persistent so we can write them to the config
259 * file at some later point */
260 nsvc->persistent = 1;
261
262 return CMD_SUCCESS;
263}
264
265DEFUN(cfg_nse_remoteip, cfg_nse_remoteip_cmd,
266 "nse <0-65535> remote-ip A.B.C.D",
267 NSE_CMD_STR
268 "Remote IP Address\n"
269 "Remote IP Address\n")
270{
271 uint16_t nsei = atoi(argv[0]);
272 struct gprs_nsvc *nsvc;
273
Harald Weltef5430362012-06-17 12:25:53 +0800274 nsvc = gprs_nsvc_by_nsei(vty_nsi, nsei);
Harald Welte144e0292010-05-13 11:45:07 +0200275 if (!nsvc) {
276 vty_out(vty, "No such NSE (%u)%s", nsei, VTY_NEWLINE);
277 return CMD_WARNING;
278 }
279 inet_aton(argv[1], &nsvc->ip.bts_addr.sin_addr);
280
281 return CMD_SUCCESS;
282
283}
284
285DEFUN(cfg_nse_remoteport, cfg_nse_remoteport_cmd,
286 "nse <0-65535> remote-port <0-65535>",
287 NSE_CMD_STR
288 "Remote UDP Port\n"
289 "Remote UDP Port Number\n")
290{
291 uint16_t nsei = atoi(argv[0]);
292 uint16_t port = atoi(argv[1]);
293 struct gprs_nsvc *nsvc;
294
Harald Weltef5430362012-06-17 12:25:53 +0800295 nsvc = gprs_nsvc_by_nsei(vty_nsi, nsei);
Harald Welte144e0292010-05-13 11:45:07 +0200296 if (!nsvc) {
297 vty_out(vty, "No such NSE (%u)%s", nsei, VTY_NEWLINE);
298 return CMD_WARNING;
299 }
300
Harald Welteb3ee2652010-05-19 14:38:50 +0200301 if (nsvc->ll != GPRS_NS_LL_UDP) {
302 vty_out(vty, "Cannot set UDP Port on non-UDP NSE%s",
303 VTY_NEWLINE);
304 return CMD_WARNING;
305 }
306
Harald Welte144e0292010-05-13 11:45:07 +0200307 nsvc->ip.bts_addr.sin_port = htons(port);
308
309 return CMD_SUCCESS;
310}
311
Harald Welteb3ee2652010-05-19 14:38:50 +0200312DEFUN(cfg_nse_fr_dlci, cfg_nse_fr_dlci_cmd,
Harald Welte188bda62010-05-28 14:11:49 +0200313 "nse <0-65535> fr-dlci <16-1007>",
Harald Welteb3ee2652010-05-19 14:38:50 +0200314 NSE_CMD_STR
315 "Frame Relay DLCI\n"
316 "Frame Relay DLCI Number\n")
317{
318 uint16_t nsei = atoi(argv[0]);
319 uint16_t dlci = atoi(argv[1]);
320 struct gprs_nsvc *nsvc;
321
Harald Weltef5430362012-06-17 12:25:53 +0800322 nsvc = gprs_nsvc_by_nsei(vty_nsi, nsei);
Harald Welteb3ee2652010-05-19 14:38:50 +0200323 if (!nsvc) {
324 vty_out(vty, "No such NSE (%u)%s", nsei, VTY_NEWLINE);
325 return CMD_WARNING;
326 }
327
328 if (nsvc->ll != GPRS_NS_LL_FR_GRE) {
329 vty_out(vty, "Cannot set FR DLCI on non-FR NSE%s",
330 VTY_NEWLINE);
331 return CMD_WARNING;
332 }
333
334 nsvc->frgre.bts_addr.sin_port = htons(dlci);
335
336 return CMD_SUCCESS;
337}
338
339DEFUN(cfg_nse_encaps, cfg_nse_encaps_cmd,
340 "nse <0-65535> encapsulation (udp|framerelay-gre)",
341 NSE_CMD_STR
342 "Encapsulation for NS\n"
343 "UDP/IP Encapsulation\n" "Frame-Relay/GRE/IP Encapsulation\n")
344{
345 uint16_t nsei = atoi(argv[0]);
346 struct gprs_nsvc *nsvc;
347
Harald Weltef5430362012-06-17 12:25:53 +0800348 nsvc = gprs_nsvc_by_nsei(vty_nsi, nsei);
Harald Welteb3ee2652010-05-19 14:38:50 +0200349 if (!nsvc) {
350 vty_out(vty, "No such NSE (%u)%s", nsei, VTY_NEWLINE);
351 return CMD_WARNING;
352 }
353
354 if (!strcmp(argv[1], "udp"))
355 nsvc->ll = GPRS_NS_LL_UDP;
356 else
357 nsvc->ll = GPRS_NS_LL_FR_GRE;
358
359 return CMD_SUCCESS;
360}
361
362
Harald Welte144e0292010-05-13 11:45:07 +0200363DEFUN(cfg_nse_remoterole, cfg_nse_remoterole_cmd,
364 "nse <0-65535> remote-role (sgsn|bss)",
365 NSE_CMD_STR
366 "Remote NSE Role\n"
367 "Remote Peer is SGSN\n"
368 "Remote Peer is BSS\n")
369{
370 uint16_t nsei = atoi(argv[0]);
371 struct gprs_nsvc *nsvc;
372
Harald Weltef5430362012-06-17 12:25:53 +0800373 nsvc = gprs_nsvc_by_nsei(vty_nsi, nsei);
Harald Welte144e0292010-05-13 11:45:07 +0200374 if (!nsvc) {
375 vty_out(vty, "No such NSE (%u)%s", nsei, VTY_NEWLINE);
376 return CMD_WARNING;
377 }
378
379 if (!strcmp(argv[1], "sgsn"))
380 nsvc->remote_end_is_sgsn = 1;
381 else
382 nsvc->remote_end_is_sgsn = 0;
383
384 return CMD_SUCCESS;
385}
386
387DEFUN(cfg_no_nse, cfg_no_nse_cmd,
388 "no nse <0-65535>",
Harald Welte24133c32010-05-15 23:06:26 +0200389 "Delete Persistent NS Entity\n"
Harald Welte144e0292010-05-13 11:45:07 +0200390 "Delete " NSE_CMD_STR)
391{
392 uint16_t nsei = atoi(argv[0]);
393 struct gprs_nsvc *nsvc;
394
Harald Weltef5430362012-06-17 12:25:53 +0800395 nsvc = gprs_nsvc_by_nsei(vty_nsi, nsei);
Harald Welte144e0292010-05-13 11:45:07 +0200396 if (!nsvc) {
397 vty_out(vty, "No such NSE (%u)%s", nsei, VTY_NEWLINE);
398 return CMD_WARNING;
399 }
400
Harald Welte24133c32010-05-15 23:06:26 +0200401 if (!nsvc->persistent) {
402 vty_out(vty, "NSEI %u is not a persistent NSE%s",
403 nsei, VTY_NEWLINE);
404 return CMD_WARNING;
405 }
406
407 nsvc->persistent = 0;
Harald Welte144e0292010-05-13 11:45:07 +0200408
409 return CMD_SUCCESS;
410}
411
412DEFUN(cfg_ns_timer, cfg_ns_timer_cmd,
413 "timer " NS_TIMERS " <0-65535>",
414 "Network Service Timer\n"
415 NS_TIMERS_HELP "Timer Value\n")
416{
417 int idx = get_string_value(gprs_ns_timer_strs, argv[0]);
418 int val = atoi(argv[1]);
419
420 if (idx < 0 || idx >= ARRAY_SIZE(vty_nsi->timeout))
421 return CMD_WARNING;
422
423 vty_nsi->timeout[idx] = val;
424
425 return CMD_SUCCESS;
426}
427
Harald Welte7fb05232010-05-19 15:09:09 +0200428#define ENCAPS_STR "NS encapsulation options\n"
429
430DEFUN(cfg_nsip_local_ip, cfg_nsip_local_ip_cmd,
431 "encapsulation udp local-ip A.B.C.D",
432 ENCAPS_STR "NS over UDP Encapsulation\n"
433 "Set the IP address on which we listen for NS/UDP\n"
434 "IP Address\n")
435{
436 struct in_addr ia;
437
438 inet_aton(argv[0], &ia);
439 vty_nsi->nsip.local_ip = ntohl(ia.s_addr);
440
441 return CMD_SUCCESS;
442}
443
444DEFUN(cfg_nsip_local_port, cfg_nsip_local_port_cmd,
445 "encapsulation udp local-port <0-65535>",
446 ENCAPS_STR "NS over UDP Encapsulation\n"
447 "Set the UDP port on which we listen for NS/UDP\n"
448 "UDP port number\n")
449{
450 unsigned int port = atoi(argv[0]);
451
452 vty_nsi->nsip.local_port = port;
453
454 return CMD_SUCCESS;
455}
456
457DEFUN(cfg_frgre_local_ip, cfg_frgre_local_ip_cmd,
458 "encapsulation framerelay-gre local-ip A.B.C.D",
459 ENCAPS_STR "NS over Frame Relay over GRE Encapsulation\n"
460 "Set the IP address on which we listen for NS/FR/GRE\n"
461 "IP Address\n")
462{
463 struct in_addr ia;
464
465 if (!vty_nsi->frgre.enabled) {
466 vty_out(vty, "FR/GRE is not enabled%s", VTY_NEWLINE);
467 return CMD_WARNING;
468 }
469 inet_aton(argv[0], &ia);
470 vty_nsi->frgre.local_ip = ntohl(ia.s_addr);
471
472 return CMD_SUCCESS;
473}
474
475DEFUN(cfg_frgre_enable, cfg_frgre_enable_cmd,
476 "encapsulation framerelay-gre enabled (1|0)",
477 ENCAPS_STR "NS over Frame Relay over GRE Encapsulation\n"
478 "Enable or disable Frame Relay over GRE\n"
479 "Enable\n" "Disable\n")
480{
481 int enabled = atoi(argv[0]);
482
483 vty_nsi->frgre.enabled = enabled;
484
485 return CMD_SUCCESS;
486}
487
Harald Welte43f3b692010-05-14 19:36:59 +0200488DEFUN(nsvc_nsei, nsvc_nsei_cmd,
489 "nsvc nsei <0-65535> (block|unblock|reset)",
490 "Perform an operation on a NSVC\n"
Holger Hans Peter Freyther887934e2011-11-05 15:14:59 +0100491 "NSEI to identify NS-VC Identifier (NS-VCI)\n"
492 "The NSEI\n"
Harald Welte43f3b692010-05-14 19:36:59 +0200493 "Initiate BLOCK procedure\n"
494 "Initiate UNBLOCK procedure\n"
495 "Initiate RESET procedure\n")
496{
497 uint16_t nsvci = atoi(argv[0]);
498 const char *operation = argv[1];
499 struct gprs_nsvc *nsvc;
500
Harald Weltef5430362012-06-17 12:25:53 +0800501 nsvc = gprs_nsvc_by_nsei(vty_nsi, nsvci);
Harald Welte43f3b692010-05-14 19:36:59 +0200502 if (!nsvc) {
503 vty_out(vty, "No such NSVCI (%u)%s", nsvci, VTY_NEWLINE);
504 return CMD_WARNING;
505 }
506
507 if (!strcmp(operation, "block"))
508 gprs_ns_tx_block(nsvc, NS_CAUSE_OM_INTERVENTION);
509 else if (!strcmp(operation, "unblock"))
510 gprs_ns_tx_unblock(nsvc);
511 else if (!strcmp(operation, "reset"))
512 gprs_nsvc_reset(nsvc, NS_CAUSE_OM_INTERVENTION);
513 else
514 return CMD_WARNING;
515
516 return CMD_SUCCESS;
517}
518
Harald Welte91f7f4b2010-05-15 23:52:02 +0200519DEFUN(logging_fltr_nsvc,
520 logging_fltr_nsvc_cmd,
521 "logging filter nsvc (nsei|nsvci) <0-65535>",
Harald Welte6703bf72010-05-16 00:00:04 +0200522 LOGGING_STR FILTER_STR
Harald Welte91f7f4b2010-05-15 23:52:02 +0200523 "Filter based on NS Virtual Connection\n"
524 "Identify NS-VC by NSEI\n"
525 "Identify NS-VC by NSVCI\n"
526 "Numeric identifier\n")
527{
Harald Welte43ae94e2011-02-18 21:10:05 +0100528 struct log_target *tgt = osmo_log_vty2tgt(vty);
Harald Welte91f7f4b2010-05-15 23:52:02 +0200529 struct gprs_nsvc *nsvc;
530 uint16_t id = atoi(argv[1]);
531
Harald Welte43ae94e2011-02-18 21:10:05 +0100532 if (!tgt)
Harald Welte91f7f4b2010-05-15 23:52:02 +0200533 return CMD_WARNING;
Harald Welte91f7f4b2010-05-15 23:52:02 +0200534
535 if (!strcmp(argv[0], "nsei"))
Harald Weltef5430362012-06-17 12:25:53 +0800536 nsvc = gprs_nsvc_by_nsei(vty_nsi, id);
Harald Welte91f7f4b2010-05-15 23:52:02 +0200537 else
Harald Weltef5430362012-06-17 12:25:53 +0800538 nsvc = gprs_nsvc_by_nsvci(vty_nsi, id);
Harald Welte91f7f4b2010-05-15 23:52:02 +0200539
540 if (!nsvc) {
541 vty_out(vty, "No NS-VC by that identifier%s", VTY_NEWLINE);
542 return CMD_WARNING;
543 }
544
Harald Welte43ae94e2011-02-18 21:10:05 +0100545 log_set_nsvc_filter(tgt, nsvc);
Harald Welte91f7f4b2010-05-15 23:52:02 +0200546 return CMD_SUCCESS;
547}
Harald Welte43f3b692010-05-14 19:36:59 +0200548
Harald Welte144e0292010-05-13 11:45:07 +0200549int gprs_ns_vty_init(struct gprs_ns_inst *nsi)
550{
551 vty_nsi = nsi;
552
553 install_element_ve(&show_ns_cmd);
Harald Welteaf1d4cb2010-05-13 12:32:30 +0200554 install_element_ve(&show_ns_stats_cmd);
Harald Welte92883342010-05-15 23:04:03 +0200555 install_element_ve(&show_nse_cmd);
Harald Welte91f7f4b2010-05-15 23:52:02 +0200556 install_element_ve(&logging_fltr_nsvc_cmd);
Harald Welte144e0292010-05-13 11:45:07 +0200557
Harald Welte43ae94e2011-02-18 21:10:05 +0100558 install_element(CFG_LOG_NODE, &logging_fltr_nsvc_cmd);
559
Harald Welte144e0292010-05-13 11:45:07 +0200560 install_element(CONFIG_NODE, &cfg_ns_cmd);
561 install_node(&ns_node, config_write_ns);
Harald Welte4f5883b2012-06-16 16:54:06 +0800562 install_default(L_NS_NODE);
563 install_element(L_NS_NODE, &libgb_exit_cmd);
564 install_element(L_NS_NODE, &libgb_end_cmd);
565 install_element(L_NS_NODE, &cfg_nse_nsvci_cmd);
566 install_element(L_NS_NODE, &cfg_nse_remoteip_cmd);
567 install_element(L_NS_NODE, &cfg_nse_remoteport_cmd);
568 install_element(L_NS_NODE, &cfg_nse_fr_dlci_cmd);
569 install_element(L_NS_NODE, &cfg_nse_encaps_cmd);
570 install_element(L_NS_NODE, &cfg_nse_remoterole_cmd);
571 install_element(L_NS_NODE, &cfg_no_nse_cmd);
572 install_element(L_NS_NODE, &cfg_ns_timer_cmd);
573 install_element(L_NS_NODE, &cfg_nsip_local_ip_cmd);
574 install_element(L_NS_NODE, &cfg_nsip_local_port_cmd);
575 install_element(L_NS_NODE, &cfg_frgre_enable_cmd);
576 install_element(L_NS_NODE, &cfg_frgre_local_ip_cmd);
Harald Welte144e0292010-05-13 11:45:07 +0200577
Harald Welte43f3b692010-05-14 19:36:59 +0200578 install_element(ENABLE_NODE, &nsvc_nsei_cmd);
579
Harald Welte144e0292010-05-13 11:45:07 +0200580 return 0;
581}