blob: 6de74dd1dc96045bb59422f893af767fbfe42f33 [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) {
Neels Hofmeyr8b86cd72017-02-23 18:03:28 +010064 target->filter_map |= (1 << LOG_FLT_GB_NSVC);
65 target->filter_data[LOG_FLT_GB_NSVC] = nsvc;
66 } else if (target->filter_data[LOG_FLT_GB_NSVC]) {
67 target->filter_map = ~(1 << LOG_FLT_GB_NSVC);
68 target->filter_data[LOG_FLT_GB_NSVC] = NULL;
Harald Weltef5430362012-06-17 12:25:53 +080069 }
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);
Jacob Erlbeck0a1400f2015-10-06 15:23:25 +0200170 if (stats) {
Harald Welte92883342010-05-15 23:04:03 +0200171 vty_out_rate_ctr_group(vty, " ", nsvc->ctrg);
Jacob Erlbeck0a1400f2015-10-06 15:23:25 +0200172 vty_out_stat_item_group(vty, " ", nsvc->statg);
173 }
Harald Welte92883342010-05-15 23:04:03 +0200174}
175
Harald Welteaf1d4cb2010-05-13 12:32:30 +0200176static void dump_ns(struct vty *vty, struct gprs_ns_inst *nsi, int stats)
Harald Welte144e0292010-05-13 11:45:07 +0200177{
Harald Welte144e0292010-05-13 11:45:07 +0200178 struct gprs_nsvc *nsvc;
Harald Welte7fb05232010-05-19 15:09:09 +0200179 struct in_addr ia;
180
181 ia.s_addr = htonl(vty_nsi->nsip.local_ip);
Harald Weltece4ccbc2010-05-19 17:02:57 +0200182 vty_out(vty, "Encapsulation NS-UDP-IP Local IP: %s, UDP Port: %u%s",
Harald Welte7fb05232010-05-19 15:09:09 +0200183 inet_ntoa(ia), vty_nsi->nsip.local_port, VTY_NEWLINE);
184
185 ia.s_addr = htonl(vty_nsi->frgre.local_ip);
Harald Weltece4ccbc2010-05-19 17:02:57 +0200186 vty_out(vty, "Encapsulation NS-FR-GRE-IP Local IP: %s%s",
Harald Welte7fb05232010-05-19 15:09:09 +0200187 inet_ntoa(ia), VTY_NEWLINE);
Harald Welte144e0292010-05-13 11:45:07 +0200188
189 llist_for_each_entry(nsvc, &nsi->gprs_nsvcs, list) {
Harald Weltedd1c83c2010-05-13 13:58:08 +0200190 if (nsvc == nsi->unknown_nsvc)
191 continue;
Harald Welte92883342010-05-15 23:04:03 +0200192 dump_nse(vty, nsvc, stats);
Harald Welte144e0292010-05-13 11:45:07 +0200193 }
Harald Welteaf1d4cb2010-05-13 12:32:30 +0200194}
Harald Welte144e0292010-05-13 11:45:07 +0200195
Harald Welteaf1d4cb2010-05-13 12:32:30 +0200196DEFUN(show_ns, show_ns_cmd, "show ns",
197 SHOW_STR "Display information about the NS protocol")
198{
199 struct gprs_ns_inst *nsi = vty_nsi;
200 dump_ns(vty, nsi, 0);
Harald Welte144e0292010-05-13 11:45:07 +0200201 return CMD_SUCCESS;
202}
203
Harald Welteaf1d4cb2010-05-13 12:32:30 +0200204DEFUN(show_ns_stats, show_ns_stats_cmd, "show ns stats",
205 SHOW_STR
206 "Display information about the NS protocol\n"
207 "Include statistics\n")
208{
209 struct gprs_ns_inst *nsi = vty_nsi;
210 dump_ns(vty, nsi, 1);
211 return CMD_SUCCESS;
212}
Harald Welte144e0292010-05-13 11:45:07 +0200213
Harald Welte92883342010-05-15 23:04:03 +0200214DEFUN(show_nse, show_nse_cmd, "show ns (nsei|nsvc) <0-65535> [stats]",
215 SHOW_STR "Display information about the NS protocol\n"
216 "Select one NSE by its NSE Identifier\n"
217 "Select one NSE by its NS-VC Identifier\n"
218 "The Identifier of selected type\n"
219 "Include Statistics\n")
220{
221 struct gprs_ns_inst *nsi = vty_nsi;
222 struct gprs_nsvc *nsvc;
223 uint16_t id = atoi(argv[1]);
224 int show_stats = 0;
225
226 if (!strcmp(argv[0], "nsei"))
Harald Weltef5430362012-06-17 12:25:53 +0800227 nsvc = gprs_nsvc_by_nsei(nsi, id);
Harald Welte92883342010-05-15 23:04:03 +0200228 else
Harald Weltef5430362012-06-17 12:25:53 +0800229 nsvc = gprs_nsvc_by_nsvci(nsi, id);
Harald Welte92883342010-05-15 23:04:03 +0200230
231 if (!nsvc) {
232 vty_out(vty, "No such NS Entity%s", VTY_NEWLINE);
233 return CMD_WARNING;
234 }
235
236 if (argc >= 3)
237 show_stats = 1;
238
239 dump_nse(vty, nsvc, show_stats);
240 return CMD_SUCCESS;
241}
242
Harald Welte24133c32010-05-15 23:06:26 +0200243#define NSE_CMD_STR "Persistent NS Entity\n" "NS Entity ID (NSEI)\n"
Harald Welte144e0292010-05-13 11:45:07 +0200244
245DEFUN(cfg_nse_nsvc, cfg_nse_nsvci_cmd,
246 "nse <0-65535> nsvci <0-65534>",
247 NSE_CMD_STR
248 "NS Virtual Connection\n"
249 "NS Virtual Connection ID (NSVCI)\n"
250 )
251{
252 uint16_t nsei = atoi(argv[0]);
253 uint16_t nsvci = atoi(argv[1]);
254 struct gprs_nsvc *nsvc;
255
Harald Weltef5430362012-06-17 12:25:53 +0800256 nsvc = gprs_nsvc_by_nsei(vty_nsi, nsei);
Harald Welte144e0292010-05-13 11:45:07 +0200257 if (!nsvc) {
Harald Weltef5430362012-06-17 12:25:53 +0800258 nsvc = gprs_nsvc_create(vty_nsi, nsvci);
Harald Welte144e0292010-05-13 11:45:07 +0200259 nsvc->nsei = nsei;
260 }
261 nsvc->nsvci = nsvci;
262 /* All NSVCs that are explicitly configured by VTY are
263 * marked as persistent so we can write them to the config
264 * file at some later point */
265 nsvc->persistent = 1;
266
267 return CMD_SUCCESS;
268}
269
270DEFUN(cfg_nse_remoteip, cfg_nse_remoteip_cmd,
271 "nse <0-65535> remote-ip A.B.C.D",
272 NSE_CMD_STR
273 "Remote IP Address\n"
274 "Remote IP Address\n")
275{
276 uint16_t nsei = atoi(argv[0]);
277 struct gprs_nsvc *nsvc;
278
Harald Weltef5430362012-06-17 12:25:53 +0800279 nsvc = gprs_nsvc_by_nsei(vty_nsi, nsei);
Harald Welte144e0292010-05-13 11:45:07 +0200280 if (!nsvc) {
281 vty_out(vty, "No such NSE (%u)%s", nsei, VTY_NEWLINE);
282 return CMD_WARNING;
283 }
284 inet_aton(argv[1], &nsvc->ip.bts_addr.sin_addr);
285
286 return CMD_SUCCESS;
287
288}
289
290DEFUN(cfg_nse_remoteport, cfg_nse_remoteport_cmd,
291 "nse <0-65535> remote-port <0-65535>",
292 NSE_CMD_STR
293 "Remote UDP Port\n"
294 "Remote UDP Port Number\n")
295{
296 uint16_t nsei = atoi(argv[0]);
297 uint16_t port = atoi(argv[1]);
298 struct gprs_nsvc *nsvc;
299
Harald Weltef5430362012-06-17 12:25:53 +0800300 nsvc = gprs_nsvc_by_nsei(vty_nsi, nsei);
Harald Welte144e0292010-05-13 11:45:07 +0200301 if (!nsvc) {
302 vty_out(vty, "No such NSE (%u)%s", nsei, VTY_NEWLINE);
303 return CMD_WARNING;
304 }
305
Harald Welteb3ee2652010-05-19 14:38:50 +0200306 if (nsvc->ll != GPRS_NS_LL_UDP) {
307 vty_out(vty, "Cannot set UDP Port on non-UDP NSE%s",
308 VTY_NEWLINE);
309 return CMD_WARNING;
310 }
311
Harald Welte144e0292010-05-13 11:45:07 +0200312 nsvc->ip.bts_addr.sin_port = htons(port);
313
314 return CMD_SUCCESS;
315}
316
Harald Welteb3ee2652010-05-19 14:38:50 +0200317DEFUN(cfg_nse_fr_dlci, cfg_nse_fr_dlci_cmd,
Harald Welte188bda62010-05-28 14:11:49 +0200318 "nse <0-65535> fr-dlci <16-1007>",
Harald Welteb3ee2652010-05-19 14:38:50 +0200319 NSE_CMD_STR
320 "Frame Relay DLCI\n"
321 "Frame Relay DLCI Number\n")
322{
323 uint16_t nsei = atoi(argv[0]);
324 uint16_t dlci = atoi(argv[1]);
325 struct gprs_nsvc *nsvc;
326
Harald Weltef5430362012-06-17 12:25:53 +0800327 nsvc = gprs_nsvc_by_nsei(vty_nsi, nsei);
Harald Welteb3ee2652010-05-19 14:38:50 +0200328 if (!nsvc) {
329 vty_out(vty, "No such NSE (%u)%s", nsei, VTY_NEWLINE);
330 return CMD_WARNING;
331 }
332
333 if (nsvc->ll != GPRS_NS_LL_FR_GRE) {
334 vty_out(vty, "Cannot set FR DLCI on non-FR NSE%s",
335 VTY_NEWLINE);
336 return CMD_WARNING;
337 }
338
339 nsvc->frgre.bts_addr.sin_port = htons(dlci);
340
341 return CMD_SUCCESS;
342}
343
344DEFUN(cfg_nse_encaps, cfg_nse_encaps_cmd,
345 "nse <0-65535> encapsulation (udp|framerelay-gre)",
346 NSE_CMD_STR
347 "Encapsulation for NS\n"
348 "UDP/IP Encapsulation\n" "Frame-Relay/GRE/IP Encapsulation\n")
349{
350 uint16_t nsei = atoi(argv[0]);
351 struct gprs_nsvc *nsvc;
352
Harald Weltef5430362012-06-17 12:25:53 +0800353 nsvc = gprs_nsvc_by_nsei(vty_nsi, nsei);
Harald Welteb3ee2652010-05-19 14:38:50 +0200354 if (!nsvc) {
355 vty_out(vty, "No such NSE (%u)%s", nsei, VTY_NEWLINE);
356 return CMD_WARNING;
357 }
358
359 if (!strcmp(argv[1], "udp"))
360 nsvc->ll = GPRS_NS_LL_UDP;
361 else
362 nsvc->ll = GPRS_NS_LL_FR_GRE;
363
364 return CMD_SUCCESS;
365}
366
367
Harald Welte144e0292010-05-13 11:45:07 +0200368DEFUN(cfg_nse_remoterole, cfg_nse_remoterole_cmd,
369 "nse <0-65535> remote-role (sgsn|bss)",
370 NSE_CMD_STR
371 "Remote NSE Role\n"
372 "Remote Peer is SGSN\n"
373 "Remote Peer is BSS\n")
374{
375 uint16_t nsei = atoi(argv[0]);
376 struct gprs_nsvc *nsvc;
377
Harald Weltef5430362012-06-17 12:25:53 +0800378 nsvc = gprs_nsvc_by_nsei(vty_nsi, nsei);
Harald Welte144e0292010-05-13 11:45:07 +0200379 if (!nsvc) {
380 vty_out(vty, "No such NSE (%u)%s", nsei, VTY_NEWLINE);
381 return CMD_WARNING;
382 }
383
384 if (!strcmp(argv[1], "sgsn"))
385 nsvc->remote_end_is_sgsn = 1;
386 else
387 nsvc->remote_end_is_sgsn = 0;
388
389 return CMD_SUCCESS;
390}
391
392DEFUN(cfg_no_nse, cfg_no_nse_cmd,
393 "no nse <0-65535>",
Harald Welte24133c32010-05-15 23:06:26 +0200394 "Delete Persistent NS Entity\n"
Harald Welte144e0292010-05-13 11:45:07 +0200395 "Delete " NSE_CMD_STR)
396{
397 uint16_t nsei = atoi(argv[0]);
398 struct gprs_nsvc *nsvc;
399
Harald Weltef5430362012-06-17 12:25:53 +0800400 nsvc = gprs_nsvc_by_nsei(vty_nsi, nsei);
Harald Welte144e0292010-05-13 11:45:07 +0200401 if (!nsvc) {
402 vty_out(vty, "No such NSE (%u)%s", nsei, VTY_NEWLINE);
403 return CMD_WARNING;
404 }
405
Harald Welte24133c32010-05-15 23:06:26 +0200406 if (!nsvc->persistent) {
407 vty_out(vty, "NSEI %u is not a persistent NSE%s",
408 nsei, VTY_NEWLINE);
409 return CMD_WARNING;
410 }
411
412 nsvc->persistent = 0;
Harald Welte144e0292010-05-13 11:45:07 +0200413
414 return CMD_SUCCESS;
415}
416
417DEFUN(cfg_ns_timer, cfg_ns_timer_cmd,
418 "timer " NS_TIMERS " <0-65535>",
419 "Network Service Timer\n"
420 NS_TIMERS_HELP "Timer Value\n")
421{
422 int idx = get_string_value(gprs_ns_timer_strs, argv[0]);
423 int val = atoi(argv[1]);
424
425 if (idx < 0 || idx >= ARRAY_SIZE(vty_nsi->timeout))
426 return CMD_WARNING;
427
428 vty_nsi->timeout[idx] = val;
429
430 return CMD_SUCCESS;
431}
432
Harald Welte7fb05232010-05-19 15:09:09 +0200433#define ENCAPS_STR "NS encapsulation options\n"
434
435DEFUN(cfg_nsip_local_ip, cfg_nsip_local_ip_cmd,
436 "encapsulation udp local-ip A.B.C.D",
437 ENCAPS_STR "NS over UDP Encapsulation\n"
438 "Set the IP address on which we listen for NS/UDP\n"
439 "IP Address\n")
440{
441 struct in_addr ia;
442
443 inet_aton(argv[0], &ia);
444 vty_nsi->nsip.local_ip = ntohl(ia.s_addr);
445
446 return CMD_SUCCESS;
447}
448
449DEFUN(cfg_nsip_local_port, cfg_nsip_local_port_cmd,
450 "encapsulation udp local-port <0-65535>",
451 ENCAPS_STR "NS over UDP Encapsulation\n"
452 "Set the UDP port on which we listen for NS/UDP\n"
453 "UDP port number\n")
454{
455 unsigned int port = atoi(argv[0]);
456
457 vty_nsi->nsip.local_port = port;
458
459 return CMD_SUCCESS;
460}
461
Holger Hans Peter Freyther2c3393d2013-03-25 11:59:58 +0100462DEFUN(cfg_nsip_dscp, cfg_nsip_dscp_cmd,
463 "encapsulation udp dscp <0-255>",
464 ENCAPS_STR "NS over UDP Encapsulation\n"
465 "Set DSCP/TOS on the UDP socket\n" "DSCP Value\n")
466{
467 int dscp = atoi(argv[0]);
468 vty_nsi->nsip.dscp = dscp;
469 return CMD_SUCCESS;
470}
471
Harald Welte7fb05232010-05-19 15:09:09 +0200472DEFUN(cfg_frgre_local_ip, cfg_frgre_local_ip_cmd,
473 "encapsulation framerelay-gre local-ip A.B.C.D",
474 ENCAPS_STR "NS over Frame Relay over GRE Encapsulation\n"
475 "Set the IP address on which we listen for NS/FR/GRE\n"
476 "IP Address\n")
477{
478 struct in_addr ia;
479
480 if (!vty_nsi->frgre.enabled) {
481 vty_out(vty, "FR/GRE is not enabled%s", VTY_NEWLINE);
482 return CMD_WARNING;
483 }
484 inet_aton(argv[0], &ia);
485 vty_nsi->frgre.local_ip = ntohl(ia.s_addr);
486
487 return CMD_SUCCESS;
488}
489
490DEFUN(cfg_frgre_enable, cfg_frgre_enable_cmd,
491 "encapsulation framerelay-gre enabled (1|0)",
492 ENCAPS_STR "NS over Frame Relay over GRE Encapsulation\n"
493 "Enable or disable Frame Relay over GRE\n"
494 "Enable\n" "Disable\n")
495{
496 int enabled = atoi(argv[0]);
497
498 vty_nsi->frgre.enabled = enabled;
499
500 return CMD_SUCCESS;
501}
502
Harald Welte43f3b692010-05-14 19:36:59 +0200503DEFUN(nsvc_nsei, nsvc_nsei_cmd,
Jacob Erlbeck687b6902013-10-24 01:33:19 +0200504 "nsvc (nsei|nsvci) <0-65535> (block|unblock|reset)",
Harald Welte43f3b692010-05-14 19:36:59 +0200505 "Perform an operation on a NSVC\n"
Holger Hans Peter Freyther887934e2011-11-05 15:14:59 +0100506 "NSEI to identify NS-VC Identifier (NS-VCI)\n"
Jacob Erlbeck687b6902013-10-24 01:33:19 +0200507 "NS-VC Identifier (NS-VCI)\n"
Holger Hans Peter Freyther887934e2011-11-05 15:14:59 +0100508 "The NSEI\n"
Harald Welte43f3b692010-05-14 19:36:59 +0200509 "Initiate BLOCK procedure\n"
510 "Initiate UNBLOCK procedure\n"
511 "Initiate RESET procedure\n")
512{
Jacob Erlbeck687b6902013-10-24 01:33:19 +0200513 const char *id_type = argv[0];
514 uint16_t id = atoi(argv[1]);
515 const char *operation = argv[2];
Harald Welte43f3b692010-05-14 19:36:59 +0200516 struct gprs_nsvc *nsvc;
517
Jacob Erlbeck687b6902013-10-24 01:33:19 +0200518 if (!strcmp(id_type, "nsei"))
519 nsvc = gprs_nsvc_by_nsei(vty_nsi, id);
520 else if (!strcmp(id_type, "nsvci"))
521 nsvc = gprs_nsvc_by_nsvci(vty_nsi, id);
522 else {
523 vty_out(vty, "%%No such id_type '%s'%s", id_type, VTY_NEWLINE);
524 return CMD_WARNING;
525 }
526
Harald Welte43f3b692010-05-14 19:36:59 +0200527 if (!nsvc) {
Jacob Erlbeck687b6902013-10-24 01:33:19 +0200528 vty_out(vty, "No such %s (%u)%s", id_type, id, VTY_NEWLINE);
Harald Welte43f3b692010-05-14 19:36:59 +0200529 return CMD_WARNING;
530 }
531
532 if (!strcmp(operation, "block"))
533 gprs_ns_tx_block(nsvc, NS_CAUSE_OM_INTERVENTION);
534 else if (!strcmp(operation, "unblock"))
535 gprs_ns_tx_unblock(nsvc);
536 else if (!strcmp(operation, "reset"))
537 gprs_nsvc_reset(nsvc, NS_CAUSE_OM_INTERVENTION);
538 else
539 return CMD_WARNING;
540
541 return CMD_SUCCESS;
542}
543
Harald Welte91f7f4b2010-05-15 23:52:02 +0200544DEFUN(logging_fltr_nsvc,
545 logging_fltr_nsvc_cmd,
546 "logging filter nsvc (nsei|nsvci) <0-65535>",
Harald Welte6703bf72010-05-16 00:00:04 +0200547 LOGGING_STR FILTER_STR
Harald Welte91f7f4b2010-05-15 23:52:02 +0200548 "Filter based on NS Virtual Connection\n"
549 "Identify NS-VC by NSEI\n"
550 "Identify NS-VC by NSVCI\n"
551 "Numeric identifier\n")
552{
Harald Welte43ae94e2011-02-18 21:10:05 +0100553 struct log_target *tgt = osmo_log_vty2tgt(vty);
Harald Welte91f7f4b2010-05-15 23:52:02 +0200554 struct gprs_nsvc *nsvc;
555 uint16_t id = atoi(argv[1]);
556
Harald Welte43ae94e2011-02-18 21:10:05 +0100557 if (!tgt)
Harald Welte91f7f4b2010-05-15 23:52:02 +0200558 return CMD_WARNING;
Harald Welte91f7f4b2010-05-15 23:52:02 +0200559
560 if (!strcmp(argv[0], "nsei"))
Harald Weltef5430362012-06-17 12:25:53 +0800561 nsvc = gprs_nsvc_by_nsei(vty_nsi, id);
Harald Welte91f7f4b2010-05-15 23:52:02 +0200562 else
Harald Weltef5430362012-06-17 12:25:53 +0800563 nsvc = gprs_nsvc_by_nsvci(vty_nsi, id);
Harald Welte91f7f4b2010-05-15 23:52:02 +0200564
565 if (!nsvc) {
566 vty_out(vty, "No NS-VC by that identifier%s", VTY_NEWLINE);
567 return CMD_WARNING;
568 }
569
Harald Welte43ae94e2011-02-18 21:10:05 +0100570 log_set_nsvc_filter(tgt, nsvc);
Harald Welte91f7f4b2010-05-15 23:52:02 +0200571 return CMD_SUCCESS;
572}
Harald Welte43f3b692010-05-14 19:36:59 +0200573
Harald Welte144e0292010-05-13 11:45:07 +0200574int gprs_ns_vty_init(struct gprs_ns_inst *nsi)
575{
Neels Hofmeyrc32bfd52017-01-12 22:32:19 +0100576 static bool vty_elements_installed = false;
577
Harald Welte144e0292010-05-13 11:45:07 +0200578 vty_nsi = nsi;
579
Neels Hofmeyrc32bfd52017-01-12 22:32:19 +0100580 /* Regression test code may call this function repeatedly, so make sure
581 * that VTY elements are not duplicated, which would assert. */
582 if (vty_elements_installed)
583 return 0;
584 vty_elements_installed = true;
585
Harald Welte144e0292010-05-13 11:45:07 +0200586 install_element_ve(&show_ns_cmd);
Harald Welteaf1d4cb2010-05-13 12:32:30 +0200587 install_element_ve(&show_ns_stats_cmd);
Harald Welte92883342010-05-15 23:04:03 +0200588 install_element_ve(&show_nse_cmd);
Harald Welte91f7f4b2010-05-15 23:52:02 +0200589 install_element_ve(&logging_fltr_nsvc_cmd);
Harald Welte144e0292010-05-13 11:45:07 +0200590
Harald Welte43ae94e2011-02-18 21:10:05 +0100591 install_element(CFG_LOG_NODE, &logging_fltr_nsvc_cmd);
592
Harald Welte144e0292010-05-13 11:45:07 +0200593 install_element(CONFIG_NODE, &cfg_ns_cmd);
594 install_node(&ns_node, config_write_ns);
Harald Welte4f5883b2012-06-16 16:54:06 +0800595 install_default(L_NS_NODE);
596 install_element(L_NS_NODE, &libgb_exit_cmd);
597 install_element(L_NS_NODE, &libgb_end_cmd);
598 install_element(L_NS_NODE, &cfg_nse_nsvci_cmd);
599 install_element(L_NS_NODE, &cfg_nse_remoteip_cmd);
600 install_element(L_NS_NODE, &cfg_nse_remoteport_cmd);
601 install_element(L_NS_NODE, &cfg_nse_fr_dlci_cmd);
602 install_element(L_NS_NODE, &cfg_nse_encaps_cmd);
603 install_element(L_NS_NODE, &cfg_nse_remoterole_cmd);
604 install_element(L_NS_NODE, &cfg_no_nse_cmd);
605 install_element(L_NS_NODE, &cfg_ns_timer_cmd);
606 install_element(L_NS_NODE, &cfg_nsip_local_ip_cmd);
607 install_element(L_NS_NODE, &cfg_nsip_local_port_cmd);
Holger Hans Peter Freyther2c3393d2013-03-25 11:59:58 +0100608 install_element(L_NS_NODE, &cfg_nsip_dscp_cmd);
Harald Welte4f5883b2012-06-16 16:54:06 +0800609 install_element(L_NS_NODE, &cfg_frgre_enable_cmd);
610 install_element(L_NS_NODE, &cfg_frgre_local_ip_cmd);
Harald Welte144e0292010-05-13 11:45:07 +0200611
Harald Welte43f3b692010-05-14 19:36:59 +0200612 install_element(ENABLE_NODE, &nsvc_nsei_cmd);
613
Harald Welte144e0292010-05-13 11:45:07 +0200614 return 0;
615}