blob: 155e1e9782a96219fcb285325befac88ff519826 [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 Welte7fa89c22014-10-26 20:33:09 +01008 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 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 Welte7fa89c22014-10-26 20:33:09 +010015 * GNU General Public License for more details.
Harald Welte144e0292010-05-13 11:45:07 +020016 *
Harald Welte7fa89c22014-10-26 20:33:09 +010017 * You should have received a copy of the GNU General Public License
Harald Weltee4cbb3f2011-01-01 15:25:50 +010018 * 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,
Jacob Erlbeck35fe87c2013-10-24 01:33:20 +020074 "%s(config-ns)# ",
Harald Welte144e0292010-05-13 11:45:07 +020075 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);
Holger Hans Peter Freyther2c3393d2013-03-25 11:59:58 +0100134 if (vty_nsi->nsip.dscp)
135 vty_out(vty, " encapsulation udp dscp %d%s",
136 vty_nsi->nsip.dscp, VTY_NEWLINE);
Harald Weltece4ccbc2010-05-19 17:02:57 +0200137
Harald Welte7fb05232010-05-19 15:09:09 +0200138 vty_out(vty, " encapsulation framerelay-gre enabled %u%s",
139 vty_nsi->frgre.enabled ? 1 : 0, VTY_NEWLINE);
Harald Weltece4ccbc2010-05-19 17:02:57 +0200140 if (vty_nsi->frgre.local_ip) {
Harald Welte7fb05232010-05-19 15:09:09 +0200141 ia.s_addr = htonl(vty_nsi->frgre.local_ip);
142 vty_out(vty, " encapsulation framerelay-gre local-ip %s%s",
143 inet_ntoa(ia), VTY_NEWLINE);
144 }
145
Harald Welte144e0292010-05-13 11:45:07 +0200146 return CMD_SUCCESS;
147}
148
149DEFUN(cfg_ns, cfg_ns_cmd,
150 "ns",
151 "Configure the GPRS Network Service")
152{
Harald Welte4f5883b2012-06-16 16:54:06 +0800153 vty->node = L_NS_NODE;
Harald Welte144e0292010-05-13 11:45:07 +0200154 return CMD_SUCCESS;
155}
156
Harald Welte92883342010-05-15 23:04:03 +0200157static void dump_nse(struct vty *vty, struct gprs_nsvc *nsvc, int stats)
158{
159 vty_out(vty, "NSEI %5u, NS-VC %5u, Remote: %-4s, %5s %9s",
160 nsvc->nsei, nsvc->nsvci,
161 nsvc->remote_end_is_sgsn ? "SGSN" : "BSS",
162 nsvc->state & NSE_S_ALIVE ? "ALIVE" : "DEAD",
163 nsvc->state & NSE_S_BLOCKED ? "BLOCKED" : "UNBLOCKED");
Harald Welteb3ee2652010-05-19 14:38:50 +0200164 if (nsvc->ll == GPRS_NS_LL_UDP || nsvc->ll == GPRS_NS_LL_FR_GRE)
165 vty_out(vty, ", %s %15s:%u",
Harald Weltece4ccbc2010-05-19 17:02:57 +0200166 nsvc->ll == GPRS_NS_LL_UDP ? "UDP " : "FR-GRE",
Harald Welte92883342010-05-15 23:04:03 +0200167 inet_ntoa(nsvc->ip.bts_addr.sin_addr),
168 ntohs(nsvc->ip.bts_addr.sin_port));
169 vty_out(vty, "%s", VTY_NEWLINE);
170 if (stats)
171 vty_out_rate_ctr_group(vty, " ", nsvc->ctrg);
172}
173
Harald Welteaf1d4cb2010-05-13 12:32:30 +0200174static void dump_ns(struct vty *vty, struct gprs_ns_inst *nsi, int stats)
Harald Welte144e0292010-05-13 11:45:07 +0200175{
Harald Welte144e0292010-05-13 11:45:07 +0200176 struct gprs_nsvc *nsvc;
Harald Welte7fb05232010-05-19 15:09:09 +0200177 struct in_addr ia;
178
179 ia.s_addr = htonl(vty_nsi->nsip.local_ip);
Harald Weltece4ccbc2010-05-19 17:02:57 +0200180 vty_out(vty, "Encapsulation NS-UDP-IP Local IP: %s, UDP Port: %u%s",
Harald Welte7fb05232010-05-19 15:09:09 +0200181 inet_ntoa(ia), vty_nsi->nsip.local_port, VTY_NEWLINE);
182
183 ia.s_addr = htonl(vty_nsi->frgre.local_ip);
Harald Weltece4ccbc2010-05-19 17:02:57 +0200184 vty_out(vty, "Encapsulation NS-FR-GRE-IP Local IP: %s%s",
Harald Welte7fb05232010-05-19 15:09:09 +0200185 inet_ntoa(ia), VTY_NEWLINE);
Harald Welte144e0292010-05-13 11:45:07 +0200186
187 llist_for_each_entry(nsvc, &nsi->gprs_nsvcs, list) {
Harald Weltedd1c83c2010-05-13 13:58:08 +0200188 if (nsvc == nsi->unknown_nsvc)
189 continue;
Harald Welte92883342010-05-15 23:04:03 +0200190 dump_nse(vty, nsvc, stats);
Harald Welte144e0292010-05-13 11:45:07 +0200191 }
Harald Welteaf1d4cb2010-05-13 12:32:30 +0200192}
Harald Welte144e0292010-05-13 11:45:07 +0200193
Harald Welteaf1d4cb2010-05-13 12:32:30 +0200194DEFUN(show_ns, show_ns_cmd, "show ns",
195 SHOW_STR "Display information about the NS protocol")
196{
197 struct gprs_ns_inst *nsi = vty_nsi;
198 dump_ns(vty, nsi, 0);
Harald Welte144e0292010-05-13 11:45:07 +0200199 return CMD_SUCCESS;
200}
201
Harald Welteaf1d4cb2010-05-13 12:32:30 +0200202DEFUN(show_ns_stats, show_ns_stats_cmd, "show ns stats",
203 SHOW_STR
204 "Display information about the NS protocol\n"
205 "Include statistics\n")
206{
207 struct gprs_ns_inst *nsi = vty_nsi;
208 dump_ns(vty, nsi, 1);
209 return CMD_SUCCESS;
210}
Harald Welte144e0292010-05-13 11:45:07 +0200211
Harald Welte92883342010-05-15 23:04:03 +0200212DEFUN(show_nse, show_nse_cmd, "show ns (nsei|nsvc) <0-65535> [stats]",
213 SHOW_STR "Display information about the NS protocol\n"
214 "Select one NSE by its NSE Identifier\n"
215 "Select one NSE by its NS-VC Identifier\n"
216 "The Identifier of selected type\n"
217 "Include Statistics\n")
218{
219 struct gprs_ns_inst *nsi = vty_nsi;
220 struct gprs_nsvc *nsvc;
221 uint16_t id = atoi(argv[1]);
222 int show_stats = 0;
223
224 if (!strcmp(argv[0], "nsei"))
Harald Weltef5430362012-06-17 12:25:53 +0800225 nsvc = gprs_nsvc_by_nsei(nsi, id);
Harald Welte92883342010-05-15 23:04:03 +0200226 else
Harald Weltef5430362012-06-17 12:25:53 +0800227 nsvc = gprs_nsvc_by_nsvci(nsi, id);
Harald Welte92883342010-05-15 23:04:03 +0200228
229 if (!nsvc) {
230 vty_out(vty, "No such NS Entity%s", VTY_NEWLINE);
231 return CMD_WARNING;
232 }
233
234 if (argc >= 3)
235 show_stats = 1;
236
237 dump_nse(vty, nsvc, show_stats);
238 return CMD_SUCCESS;
239}
240
Harald Welte24133c32010-05-15 23:06:26 +0200241#define NSE_CMD_STR "Persistent NS Entity\n" "NS Entity ID (NSEI)\n"
Harald Welte144e0292010-05-13 11:45:07 +0200242
243DEFUN(cfg_nse_nsvc, cfg_nse_nsvci_cmd,
244 "nse <0-65535> nsvci <0-65534>",
245 NSE_CMD_STR
246 "NS Virtual Connection\n"
247 "NS Virtual Connection ID (NSVCI)\n"
248 )
249{
250 uint16_t nsei = atoi(argv[0]);
251 uint16_t nsvci = atoi(argv[1]);
252 struct gprs_nsvc *nsvc;
253
Harald Weltef5430362012-06-17 12:25:53 +0800254 nsvc = gprs_nsvc_by_nsei(vty_nsi, nsei);
Harald Welte144e0292010-05-13 11:45:07 +0200255 if (!nsvc) {
Harald Weltef5430362012-06-17 12:25:53 +0800256 nsvc = gprs_nsvc_create(vty_nsi, nsvci);
Harald Welte144e0292010-05-13 11:45:07 +0200257 nsvc->nsei = nsei;
258 }
259 nsvc->nsvci = nsvci;
260 /* All NSVCs that are explicitly configured by VTY are
261 * marked as persistent so we can write them to the config
262 * file at some later point */
263 nsvc->persistent = 1;
264
265 return CMD_SUCCESS;
266}
267
268DEFUN(cfg_nse_remoteip, cfg_nse_remoteip_cmd,
269 "nse <0-65535> remote-ip A.B.C.D",
270 NSE_CMD_STR
271 "Remote IP Address\n"
272 "Remote IP Address\n")
273{
274 uint16_t nsei = atoi(argv[0]);
275 struct gprs_nsvc *nsvc;
276
Harald Weltef5430362012-06-17 12:25:53 +0800277 nsvc = gprs_nsvc_by_nsei(vty_nsi, nsei);
Harald Welte144e0292010-05-13 11:45:07 +0200278 if (!nsvc) {
279 vty_out(vty, "No such NSE (%u)%s", nsei, VTY_NEWLINE);
280 return CMD_WARNING;
281 }
282 inet_aton(argv[1], &nsvc->ip.bts_addr.sin_addr);
283
284 return CMD_SUCCESS;
285
286}
287
288DEFUN(cfg_nse_remoteport, cfg_nse_remoteport_cmd,
289 "nse <0-65535> remote-port <0-65535>",
290 NSE_CMD_STR
291 "Remote UDP Port\n"
292 "Remote UDP Port Number\n")
293{
294 uint16_t nsei = atoi(argv[0]);
295 uint16_t port = atoi(argv[1]);
296 struct gprs_nsvc *nsvc;
297
Harald Weltef5430362012-06-17 12:25:53 +0800298 nsvc = gprs_nsvc_by_nsei(vty_nsi, nsei);
Harald Welte144e0292010-05-13 11:45:07 +0200299 if (!nsvc) {
300 vty_out(vty, "No such NSE (%u)%s", nsei, VTY_NEWLINE);
301 return CMD_WARNING;
302 }
303
Harald Welteb3ee2652010-05-19 14:38:50 +0200304 if (nsvc->ll != GPRS_NS_LL_UDP) {
305 vty_out(vty, "Cannot set UDP Port on non-UDP NSE%s",
306 VTY_NEWLINE);
307 return CMD_WARNING;
308 }
309
Harald Welte144e0292010-05-13 11:45:07 +0200310 nsvc->ip.bts_addr.sin_port = htons(port);
311
312 return CMD_SUCCESS;
313}
314
Harald Welteb3ee2652010-05-19 14:38:50 +0200315DEFUN(cfg_nse_fr_dlci, cfg_nse_fr_dlci_cmd,
Harald Welte188bda62010-05-28 14:11:49 +0200316 "nse <0-65535> fr-dlci <16-1007>",
Harald Welteb3ee2652010-05-19 14:38:50 +0200317 NSE_CMD_STR
318 "Frame Relay DLCI\n"
319 "Frame Relay DLCI Number\n")
320{
321 uint16_t nsei = atoi(argv[0]);
322 uint16_t dlci = atoi(argv[1]);
323 struct gprs_nsvc *nsvc;
324
Harald Weltef5430362012-06-17 12:25:53 +0800325 nsvc = gprs_nsvc_by_nsei(vty_nsi, nsei);
Harald Welteb3ee2652010-05-19 14:38:50 +0200326 if (!nsvc) {
327 vty_out(vty, "No such NSE (%u)%s", nsei, VTY_NEWLINE);
328 return CMD_WARNING;
329 }
330
331 if (nsvc->ll != GPRS_NS_LL_FR_GRE) {
332 vty_out(vty, "Cannot set FR DLCI on non-FR NSE%s",
333 VTY_NEWLINE);
334 return CMD_WARNING;
335 }
336
337 nsvc->frgre.bts_addr.sin_port = htons(dlci);
338
339 return CMD_SUCCESS;
340}
341
342DEFUN(cfg_nse_encaps, cfg_nse_encaps_cmd,
343 "nse <0-65535> encapsulation (udp|framerelay-gre)",
344 NSE_CMD_STR
345 "Encapsulation for NS\n"
346 "UDP/IP Encapsulation\n" "Frame-Relay/GRE/IP Encapsulation\n")
347{
348 uint16_t nsei = atoi(argv[0]);
349 struct gprs_nsvc *nsvc;
350
Harald Weltef5430362012-06-17 12:25:53 +0800351 nsvc = gprs_nsvc_by_nsei(vty_nsi, nsei);
Harald Welteb3ee2652010-05-19 14:38:50 +0200352 if (!nsvc) {
353 vty_out(vty, "No such NSE (%u)%s", nsei, VTY_NEWLINE);
354 return CMD_WARNING;
355 }
356
357 if (!strcmp(argv[1], "udp"))
358 nsvc->ll = GPRS_NS_LL_UDP;
359 else
360 nsvc->ll = GPRS_NS_LL_FR_GRE;
361
362 return CMD_SUCCESS;
363}
364
365
Harald Welte144e0292010-05-13 11:45:07 +0200366DEFUN(cfg_nse_remoterole, cfg_nse_remoterole_cmd,
367 "nse <0-65535> remote-role (sgsn|bss)",
368 NSE_CMD_STR
369 "Remote NSE Role\n"
370 "Remote Peer is SGSN\n"
371 "Remote Peer is BSS\n")
372{
373 uint16_t nsei = atoi(argv[0]);
374 struct gprs_nsvc *nsvc;
375
Harald Weltef5430362012-06-17 12:25:53 +0800376 nsvc = gprs_nsvc_by_nsei(vty_nsi, nsei);
Harald Welte144e0292010-05-13 11:45:07 +0200377 if (!nsvc) {
378 vty_out(vty, "No such NSE (%u)%s", nsei, VTY_NEWLINE);
379 return CMD_WARNING;
380 }
381
382 if (!strcmp(argv[1], "sgsn"))
383 nsvc->remote_end_is_sgsn = 1;
384 else
385 nsvc->remote_end_is_sgsn = 0;
386
387 return CMD_SUCCESS;
388}
389
390DEFUN(cfg_no_nse, cfg_no_nse_cmd,
391 "no nse <0-65535>",
Harald Welte24133c32010-05-15 23:06:26 +0200392 "Delete Persistent NS Entity\n"
Harald Welte144e0292010-05-13 11:45:07 +0200393 "Delete " NSE_CMD_STR)
394{
395 uint16_t nsei = atoi(argv[0]);
396 struct gprs_nsvc *nsvc;
397
Harald Weltef5430362012-06-17 12:25:53 +0800398 nsvc = gprs_nsvc_by_nsei(vty_nsi, nsei);
Harald Welte144e0292010-05-13 11:45:07 +0200399 if (!nsvc) {
400 vty_out(vty, "No such NSE (%u)%s", nsei, VTY_NEWLINE);
401 return CMD_WARNING;
402 }
403
Harald Welte24133c32010-05-15 23:06:26 +0200404 if (!nsvc->persistent) {
405 vty_out(vty, "NSEI %u is not a persistent NSE%s",
406 nsei, VTY_NEWLINE);
407 return CMD_WARNING;
408 }
409
410 nsvc->persistent = 0;
Harald Welte144e0292010-05-13 11:45:07 +0200411
412 return CMD_SUCCESS;
413}
414
415DEFUN(cfg_ns_timer, cfg_ns_timer_cmd,
416 "timer " NS_TIMERS " <0-65535>",
417 "Network Service Timer\n"
418 NS_TIMERS_HELP "Timer Value\n")
419{
420 int idx = get_string_value(gprs_ns_timer_strs, argv[0]);
421 int val = atoi(argv[1]);
422
423 if (idx < 0 || idx >= ARRAY_SIZE(vty_nsi->timeout))
424 return CMD_WARNING;
425
426 vty_nsi->timeout[idx] = val;
427
428 return CMD_SUCCESS;
429}
430
Harald Welte7fb05232010-05-19 15:09:09 +0200431#define ENCAPS_STR "NS encapsulation options\n"
432
433DEFUN(cfg_nsip_local_ip, cfg_nsip_local_ip_cmd,
434 "encapsulation udp local-ip A.B.C.D",
435 ENCAPS_STR "NS over UDP Encapsulation\n"
436 "Set the IP address on which we listen for NS/UDP\n"
437 "IP Address\n")
438{
439 struct in_addr ia;
440
441 inet_aton(argv[0], &ia);
442 vty_nsi->nsip.local_ip = ntohl(ia.s_addr);
443
444 return CMD_SUCCESS;
445}
446
447DEFUN(cfg_nsip_local_port, cfg_nsip_local_port_cmd,
448 "encapsulation udp local-port <0-65535>",
449 ENCAPS_STR "NS over UDP Encapsulation\n"
450 "Set the UDP port on which we listen for NS/UDP\n"
451 "UDP port number\n")
452{
453 unsigned int port = atoi(argv[0]);
454
455 vty_nsi->nsip.local_port = port;
456
457 return CMD_SUCCESS;
458}
459
Holger Hans Peter Freyther2c3393d2013-03-25 11:59:58 +0100460DEFUN(cfg_nsip_dscp, cfg_nsip_dscp_cmd,
461 "encapsulation udp dscp <0-255>",
462 ENCAPS_STR "NS over UDP Encapsulation\n"
463 "Set DSCP/TOS on the UDP socket\n" "DSCP Value\n")
464{
465 int dscp = atoi(argv[0]);
466 vty_nsi->nsip.dscp = dscp;
467 return CMD_SUCCESS;
468}
469
Harald Welte7fb05232010-05-19 15:09:09 +0200470DEFUN(cfg_frgre_local_ip, cfg_frgre_local_ip_cmd,
471 "encapsulation framerelay-gre local-ip A.B.C.D",
472 ENCAPS_STR "NS over Frame Relay over GRE Encapsulation\n"
473 "Set the IP address on which we listen for NS/FR/GRE\n"
474 "IP Address\n")
475{
476 struct in_addr ia;
477
478 if (!vty_nsi->frgre.enabled) {
479 vty_out(vty, "FR/GRE is not enabled%s", VTY_NEWLINE);
480 return CMD_WARNING;
481 }
482 inet_aton(argv[0], &ia);
483 vty_nsi->frgre.local_ip = ntohl(ia.s_addr);
484
485 return CMD_SUCCESS;
486}
487
488DEFUN(cfg_frgre_enable, cfg_frgre_enable_cmd,
489 "encapsulation framerelay-gre enabled (1|0)",
490 ENCAPS_STR "NS over Frame Relay over GRE Encapsulation\n"
491 "Enable or disable Frame Relay over GRE\n"
492 "Enable\n" "Disable\n")
493{
494 int enabled = atoi(argv[0]);
495
496 vty_nsi->frgre.enabled = enabled;
497
498 return CMD_SUCCESS;
499}
500
Harald Welte43f3b692010-05-14 19:36:59 +0200501DEFUN(nsvc_nsei, nsvc_nsei_cmd,
Jacob Erlbeck687b6902013-10-24 01:33:19 +0200502 "nsvc (nsei|nsvci) <0-65535> (block|unblock|reset)",
Harald Welte43f3b692010-05-14 19:36:59 +0200503 "Perform an operation on a NSVC\n"
Holger Hans Peter Freyther887934e2011-11-05 15:14:59 +0100504 "NSEI to identify NS-VC Identifier (NS-VCI)\n"
Jacob Erlbeck687b6902013-10-24 01:33:19 +0200505 "NS-VC Identifier (NS-VCI)\n"
Holger Hans Peter Freyther887934e2011-11-05 15:14:59 +0100506 "The NSEI\n"
Harald Welte43f3b692010-05-14 19:36:59 +0200507 "Initiate BLOCK procedure\n"
508 "Initiate UNBLOCK procedure\n"
509 "Initiate RESET procedure\n")
510{
Jacob Erlbeck687b6902013-10-24 01:33:19 +0200511 const char *id_type = argv[0];
512 uint16_t id = atoi(argv[1]);
513 const char *operation = argv[2];
Harald Welte43f3b692010-05-14 19:36:59 +0200514 struct gprs_nsvc *nsvc;
515
Jacob Erlbeck687b6902013-10-24 01:33:19 +0200516 if (!strcmp(id_type, "nsei"))
517 nsvc = gprs_nsvc_by_nsei(vty_nsi, id);
518 else if (!strcmp(id_type, "nsvci"))
519 nsvc = gprs_nsvc_by_nsvci(vty_nsi, id);
520 else {
521 vty_out(vty, "%%No such id_type '%s'%s", id_type, VTY_NEWLINE);
522 return CMD_WARNING;
523 }
524
Harald Welte43f3b692010-05-14 19:36:59 +0200525 if (!nsvc) {
Jacob Erlbeck687b6902013-10-24 01:33:19 +0200526 vty_out(vty, "No such %s (%u)%s", id_type, id, VTY_NEWLINE);
Harald Welte43f3b692010-05-14 19:36:59 +0200527 return CMD_WARNING;
528 }
529
530 if (!strcmp(operation, "block"))
531 gprs_ns_tx_block(nsvc, NS_CAUSE_OM_INTERVENTION);
532 else if (!strcmp(operation, "unblock"))
533 gprs_ns_tx_unblock(nsvc);
534 else if (!strcmp(operation, "reset"))
535 gprs_nsvc_reset(nsvc, NS_CAUSE_OM_INTERVENTION);
536 else
537 return CMD_WARNING;
538
539 return CMD_SUCCESS;
540}
541
Harald Welte91f7f4b2010-05-15 23:52:02 +0200542DEFUN(logging_fltr_nsvc,
543 logging_fltr_nsvc_cmd,
544 "logging filter nsvc (nsei|nsvci) <0-65535>",
Harald Welte6703bf72010-05-16 00:00:04 +0200545 LOGGING_STR FILTER_STR
Harald Welte91f7f4b2010-05-15 23:52:02 +0200546 "Filter based on NS Virtual Connection\n"
547 "Identify NS-VC by NSEI\n"
548 "Identify NS-VC by NSVCI\n"
549 "Numeric identifier\n")
550{
Harald Welte43ae94e2011-02-18 21:10:05 +0100551 struct log_target *tgt = osmo_log_vty2tgt(vty);
Harald Welte91f7f4b2010-05-15 23:52:02 +0200552 struct gprs_nsvc *nsvc;
553 uint16_t id = atoi(argv[1]);
554
Harald Welte43ae94e2011-02-18 21:10:05 +0100555 if (!tgt)
Harald Welte91f7f4b2010-05-15 23:52:02 +0200556 return CMD_WARNING;
Harald Welte91f7f4b2010-05-15 23:52:02 +0200557
558 if (!strcmp(argv[0], "nsei"))
Harald Weltef5430362012-06-17 12:25:53 +0800559 nsvc = gprs_nsvc_by_nsei(vty_nsi, id);
Harald Welte91f7f4b2010-05-15 23:52:02 +0200560 else
Harald Weltef5430362012-06-17 12:25:53 +0800561 nsvc = gprs_nsvc_by_nsvci(vty_nsi, id);
Harald Welte91f7f4b2010-05-15 23:52:02 +0200562
563 if (!nsvc) {
564 vty_out(vty, "No NS-VC by that identifier%s", VTY_NEWLINE);
565 return CMD_WARNING;
566 }
567
Harald Welte43ae94e2011-02-18 21:10:05 +0100568 log_set_nsvc_filter(tgt, nsvc);
Harald Welte91f7f4b2010-05-15 23:52:02 +0200569 return CMD_SUCCESS;
570}
Harald Welte43f3b692010-05-14 19:36:59 +0200571
Harald Welte144e0292010-05-13 11:45:07 +0200572int gprs_ns_vty_init(struct gprs_ns_inst *nsi)
573{
574 vty_nsi = nsi;
575
576 install_element_ve(&show_ns_cmd);
Harald Welteaf1d4cb2010-05-13 12:32:30 +0200577 install_element_ve(&show_ns_stats_cmd);
Harald Welte92883342010-05-15 23:04:03 +0200578 install_element_ve(&show_nse_cmd);
Harald Welte91f7f4b2010-05-15 23:52:02 +0200579 install_element_ve(&logging_fltr_nsvc_cmd);
Harald Welte144e0292010-05-13 11:45:07 +0200580
Harald Welte43ae94e2011-02-18 21:10:05 +0100581 install_element(CFG_LOG_NODE, &logging_fltr_nsvc_cmd);
582
Harald Welte144e0292010-05-13 11:45:07 +0200583 install_element(CONFIG_NODE, &cfg_ns_cmd);
584 install_node(&ns_node, config_write_ns);
Harald Welte4f5883b2012-06-16 16:54:06 +0800585 install_default(L_NS_NODE);
586 install_element(L_NS_NODE, &libgb_exit_cmd);
587 install_element(L_NS_NODE, &libgb_end_cmd);
588 install_element(L_NS_NODE, &cfg_nse_nsvci_cmd);
589 install_element(L_NS_NODE, &cfg_nse_remoteip_cmd);
590 install_element(L_NS_NODE, &cfg_nse_remoteport_cmd);
591 install_element(L_NS_NODE, &cfg_nse_fr_dlci_cmd);
592 install_element(L_NS_NODE, &cfg_nse_encaps_cmd);
593 install_element(L_NS_NODE, &cfg_nse_remoterole_cmd);
594 install_element(L_NS_NODE, &cfg_no_nse_cmd);
595 install_element(L_NS_NODE, &cfg_ns_timer_cmd);
596 install_element(L_NS_NODE, &cfg_nsip_local_ip_cmd);
597 install_element(L_NS_NODE, &cfg_nsip_local_port_cmd);
Holger Hans Peter Freyther2c3393d2013-03-25 11:59:58 +0100598 install_element(L_NS_NODE, &cfg_nsip_dscp_cmd);
Harald Welte4f5883b2012-06-16 16:54:06 +0800599 install_element(L_NS_NODE, &cfg_frgre_enable_cmd);
600 install_element(L_NS_NODE, &cfg_frgre_local_ip_cmd);
Harald Welte144e0292010-05-13 11:45:07 +0200601
Harald Welte43f3b692010-05-14 19:36:59 +0200602 install_element(ENABLE_NODE, &nsvc_nsei_cmd);
603
Harald Welte144e0292010-05-13 11:45:07 +0200604 return 0;
605}