Harald Welte | f2b4cd7 | 2010-05-13 11:45:07 +0200 | [diff] [blame] | 1 | /* 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 |
| 8 | * 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 |
| 10 | * (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 |
| 15 | * GNU General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License along |
| 18 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 19 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 20 | * |
| 21 | */ |
| 22 | |
| 23 | #include <stdlib.h> |
| 24 | #include <unistd.h> |
| 25 | #include <errno.h> |
| 26 | #include <stdint.h> |
| 27 | |
| 28 | #include <arpa/inet.h> |
| 29 | |
| 30 | #include <openbsc/gsm_data.h> |
| 31 | #include <osmocore/msgb.h> |
| 32 | #include <osmocore/tlv.h> |
| 33 | #include <osmocore/talloc.h> |
| 34 | #include <osmocore/select.h> |
| 35 | #include <osmocore/rate_ctr.h> |
| 36 | #include <openbsc/debug.h> |
| 37 | #include <openbsc/signal.h> |
| 38 | #include <openbsc/gprs_ns.h> |
| 39 | #include <openbsc/gprs_bssgp.h> |
Harald Welte | 8be8c8f | 2010-05-15 23:52:02 +0200 | [diff] [blame] | 40 | #include <openbsc/telnet_interface.h> |
Harald Welte | 62ab20c | 2010-05-14 18:59:17 +0200 | [diff] [blame] | 41 | #include <openbsc/vty.h> |
Harald Welte | f2b4cd7 | 2010-05-13 11:45:07 +0200 | [diff] [blame] | 42 | |
| 43 | #include <vty/vty.h> |
| 44 | #include <vty/command.h> |
| 45 | |
| 46 | static struct gprs_ns_inst *vty_nsi = NULL; |
| 47 | |
| 48 | /* FIXME: this should go to some common file as it is copied |
| 49 | * in vty_interface.c of the BSC */ |
| 50 | static const struct value_string gprs_ns_timer_strs[] = { |
| 51 | { 0, "tns-block" }, |
| 52 | { 1, "tns-block-retries" }, |
| 53 | { 2, "tns-reset" }, |
| 54 | { 3, "tns-reset-retries" }, |
| 55 | { 4, "tns-test" }, |
| 56 | { 5, "tns-alive" }, |
| 57 | { 6, "tns-alive-retries" }, |
| 58 | { 0, NULL } |
| 59 | }; |
| 60 | |
| 61 | static struct cmd_node ns_node = { |
| 62 | NS_NODE, |
| 63 | "%s(ns)#", |
| 64 | 1, |
| 65 | }; |
| 66 | |
| 67 | static int config_write_ns(struct vty *vty) |
| 68 | { |
| 69 | struct gprs_nsvc *nsvc; |
| 70 | unsigned int i; |
Harald Welte | ff3bde8 | 2010-05-19 15:09:09 +0200 | [diff] [blame] | 71 | struct in_addr ia; |
Harald Welte | f2b4cd7 | 2010-05-13 11:45:07 +0200 | [diff] [blame] | 72 | |
| 73 | vty_out(vty, "ns%s", VTY_NEWLINE); |
| 74 | |
| 75 | llist_for_each_entry(nsvc, &vty_nsi->gprs_nsvcs, list) { |
| 76 | if (!nsvc->persistent) |
| 77 | continue; |
| 78 | vty_out(vty, " nse %u nsvci %u%s", |
| 79 | nsvc->nsei, nsvc->nsvci, VTY_NEWLINE); |
| 80 | vty_out(vty, " nse %u remote-role %s%s", |
| 81 | nsvc->nsei, nsvc->remote_end_is_sgsn ? "sgsn" : "bss", |
| 82 | VTY_NEWLINE); |
Harald Welte | 5540c4c | 2010-05-19 14:38:50 +0200 | [diff] [blame] | 83 | switch (nsvc->ll) { |
| 84 | case GPRS_NS_LL_UDP: |
| 85 | vty_out(vty, " nse %u encapsulation udp%s", nsvc->nsei, |
| 86 | VTY_NEWLINE); |
Harald Welte | f2b4cd7 | 2010-05-13 11:45:07 +0200 | [diff] [blame] | 87 | vty_out(vty, " nse %u remote-ip %s%s", |
| 88 | nsvc->nsei, |
| 89 | inet_ntoa(nsvc->ip.bts_addr.sin_addr), |
| 90 | VTY_NEWLINE); |
| 91 | vty_out(vty, " nse %u remote-port %u%s", |
| 92 | nsvc->nsei, ntohs(nsvc->ip.bts_addr.sin_port), |
| 93 | VTY_NEWLINE); |
Harald Welte | 5540c4c | 2010-05-19 14:38:50 +0200 | [diff] [blame] | 94 | break; |
| 95 | case GPRS_NS_LL_FR_GRE: |
| 96 | vty_out(vty, " nse %u encapsulation framerelay-gre%s", |
| 97 | nsvc->nsei, VTY_NEWLINE); |
| 98 | vty_out(vty, " nse %u remote-ip %s%s", |
| 99 | nsvc->nsei, |
| 100 | inet_ntoa(nsvc->frgre.bts_addr.sin_addr), |
| 101 | VTY_NEWLINE); |
| 102 | vty_out(vty, " nse %u fr-dlci %u%s", |
| 103 | nsvc->nsei, ntohs(nsvc->frgre.bts_addr.sin_port), |
| 104 | VTY_NEWLINE); |
| 105 | default: |
| 106 | break; |
Harald Welte | f2b4cd7 | 2010-05-13 11:45:07 +0200 | [diff] [blame] | 107 | } |
| 108 | } |
| 109 | |
| 110 | for (i = 0; i < ARRAY_SIZE(vty_nsi->timeout); i++) |
| 111 | vty_out(vty, " timer %s %u%s", |
| 112 | get_value_string(gprs_ns_timer_strs, i), |
| 113 | vty_nsi->timeout[i], VTY_NEWLINE); |
| 114 | |
Harald Welte | ff3bde8 | 2010-05-19 15:09:09 +0200 | [diff] [blame] | 115 | if (vty_nsi->nsip.local_ip) { |
| 116 | ia.s_addr = htonl(vty_nsi->nsip.local_ip); |
| 117 | vty_out(vty, " encapsulation udp local-ip %s%s", |
| 118 | inet_ntoa(ia), VTY_NEWLINE); |
| 119 | vty_out(vty, " encapsulation udp local-port %u%s", |
| 120 | vty_nsi->nsip.local_port); |
| 121 | } |
| 122 | vty_out(vty, " encapsulation framerelay-gre enabled %u%s", |
| 123 | vty_nsi->frgre.enabled ? 1 : 0, VTY_NEWLINE); |
| 124 | if (vty_nsi->frgre.enabled) { |
| 125 | ia.s_addr = htonl(vty_nsi->frgre.local_ip); |
| 126 | vty_out(vty, " encapsulation framerelay-gre local-ip %s%s", |
| 127 | inet_ntoa(ia), VTY_NEWLINE); |
| 128 | } |
| 129 | |
Harald Welte | f2b4cd7 | 2010-05-13 11:45:07 +0200 | [diff] [blame] | 130 | return CMD_SUCCESS; |
| 131 | } |
| 132 | |
| 133 | DEFUN(cfg_ns, cfg_ns_cmd, |
| 134 | "ns", |
| 135 | "Configure the GPRS Network Service") |
| 136 | { |
| 137 | vty->node = NS_NODE; |
| 138 | return CMD_SUCCESS; |
| 139 | } |
| 140 | |
Harald Welte | 55c91e4 | 2010-05-15 23:04:03 +0200 | [diff] [blame] | 141 | static void dump_nse(struct vty *vty, struct gprs_nsvc *nsvc, int stats) |
| 142 | { |
| 143 | vty_out(vty, "NSEI %5u, NS-VC %5u, Remote: %-4s, %5s %9s", |
| 144 | nsvc->nsei, nsvc->nsvci, |
| 145 | nsvc->remote_end_is_sgsn ? "SGSN" : "BSS", |
| 146 | nsvc->state & NSE_S_ALIVE ? "ALIVE" : "DEAD", |
| 147 | nsvc->state & NSE_S_BLOCKED ? "BLOCKED" : "UNBLOCKED"); |
Harald Welte | 5540c4c | 2010-05-19 14:38:50 +0200 | [diff] [blame] | 148 | if (nsvc->ll == GPRS_NS_LL_UDP || nsvc->ll == GPRS_NS_LL_FR_GRE) |
| 149 | vty_out(vty, ", %s %15s:%u", |
| 150 | nsvc->ll == GPRS_NS_LL_UDP ? "UDP" : "FR-GRE", |
Harald Welte | 55c91e4 | 2010-05-15 23:04:03 +0200 | [diff] [blame] | 151 | inet_ntoa(nsvc->ip.bts_addr.sin_addr), |
| 152 | ntohs(nsvc->ip.bts_addr.sin_port)); |
| 153 | vty_out(vty, "%s", VTY_NEWLINE); |
| 154 | if (stats) |
| 155 | vty_out_rate_ctr_group(vty, " ", nsvc->ctrg); |
| 156 | } |
| 157 | |
Harald Welte | 73b2359 | 2010-05-13 12:32:30 +0200 | [diff] [blame] | 158 | static void dump_ns(struct vty *vty, struct gprs_ns_inst *nsi, int stats) |
Harald Welte | f2b4cd7 | 2010-05-13 11:45:07 +0200 | [diff] [blame] | 159 | { |
Harald Welte | f2b4cd7 | 2010-05-13 11:45:07 +0200 | [diff] [blame] | 160 | struct gprs_nsvc *nsvc; |
Harald Welte | ff3bde8 | 2010-05-19 15:09:09 +0200 | [diff] [blame] | 161 | struct in_addr ia; |
| 162 | |
| 163 | ia.s_addr = htonl(vty_nsi->nsip.local_ip); |
| 164 | vty_out(vty, "NS-UDP-IP Encapsulation: Local IP: %s, UDP Port: %u%s", |
| 165 | inet_ntoa(ia), vty_nsi->nsip.local_port, VTY_NEWLINE); |
| 166 | |
| 167 | ia.s_addr = htonl(vty_nsi->frgre.local_ip); |
| 168 | vty_out(vty, "NS-FR-GRE-IP Encapsulation: Local IP: %s%s", |
| 169 | inet_ntoa(ia), VTY_NEWLINE); |
Harald Welte | f2b4cd7 | 2010-05-13 11:45:07 +0200 | [diff] [blame] | 170 | |
| 171 | llist_for_each_entry(nsvc, &nsi->gprs_nsvcs, list) { |
Harald Welte | 9aa97fc | 2010-05-13 13:58:08 +0200 | [diff] [blame] | 172 | if (nsvc == nsi->unknown_nsvc) |
| 173 | continue; |
Harald Welte | 55c91e4 | 2010-05-15 23:04:03 +0200 | [diff] [blame] | 174 | dump_nse(vty, nsvc, stats); |
Harald Welte | f2b4cd7 | 2010-05-13 11:45:07 +0200 | [diff] [blame] | 175 | } |
Harald Welte | 73b2359 | 2010-05-13 12:32:30 +0200 | [diff] [blame] | 176 | } |
Harald Welte | f2b4cd7 | 2010-05-13 11:45:07 +0200 | [diff] [blame] | 177 | |
Harald Welte | 73b2359 | 2010-05-13 12:32:30 +0200 | [diff] [blame] | 178 | DEFUN(show_ns, show_ns_cmd, "show ns", |
| 179 | SHOW_STR "Display information about the NS protocol") |
| 180 | { |
| 181 | struct gprs_ns_inst *nsi = vty_nsi; |
| 182 | dump_ns(vty, nsi, 0); |
Harald Welte | f2b4cd7 | 2010-05-13 11:45:07 +0200 | [diff] [blame] | 183 | return CMD_SUCCESS; |
| 184 | } |
| 185 | |
Harald Welte | 73b2359 | 2010-05-13 12:32:30 +0200 | [diff] [blame] | 186 | DEFUN(show_ns_stats, show_ns_stats_cmd, "show ns stats", |
| 187 | SHOW_STR |
| 188 | "Display information about the NS protocol\n" |
| 189 | "Include statistics\n") |
| 190 | { |
| 191 | struct gprs_ns_inst *nsi = vty_nsi; |
| 192 | dump_ns(vty, nsi, 1); |
| 193 | return CMD_SUCCESS; |
| 194 | } |
Harald Welte | f2b4cd7 | 2010-05-13 11:45:07 +0200 | [diff] [blame] | 195 | |
Harald Welte | 55c91e4 | 2010-05-15 23:04:03 +0200 | [diff] [blame] | 196 | DEFUN(show_nse, show_nse_cmd, "show ns (nsei|nsvc) <0-65535> [stats]", |
| 197 | SHOW_STR "Display information about the NS protocol\n" |
| 198 | "Select one NSE by its NSE Identifier\n" |
| 199 | "Select one NSE by its NS-VC Identifier\n" |
| 200 | "The Identifier of selected type\n" |
| 201 | "Include Statistics\n") |
| 202 | { |
| 203 | struct gprs_ns_inst *nsi = vty_nsi; |
| 204 | struct gprs_nsvc *nsvc; |
| 205 | uint16_t id = atoi(argv[1]); |
| 206 | int show_stats = 0; |
| 207 | |
| 208 | if (!strcmp(argv[0], "nsei")) |
| 209 | nsvc = nsvc_by_nsei(nsi, id); |
| 210 | else |
| 211 | nsvc = nsvc_by_nsvci(nsi, id); |
| 212 | |
| 213 | if (!nsvc) { |
| 214 | vty_out(vty, "No such NS Entity%s", VTY_NEWLINE); |
| 215 | return CMD_WARNING; |
| 216 | } |
| 217 | |
| 218 | if (argc >= 3) |
| 219 | show_stats = 1; |
| 220 | |
| 221 | dump_nse(vty, nsvc, show_stats); |
| 222 | return CMD_SUCCESS; |
| 223 | } |
| 224 | |
Harald Welte | 52613a1 | 2010-05-15 23:06:26 +0200 | [diff] [blame] | 225 | #define NSE_CMD_STR "Persistent NS Entity\n" "NS Entity ID (NSEI)\n" |
Harald Welte | f2b4cd7 | 2010-05-13 11:45:07 +0200 | [diff] [blame] | 226 | |
| 227 | DEFUN(cfg_nse_nsvc, cfg_nse_nsvci_cmd, |
| 228 | "nse <0-65535> nsvci <0-65534>", |
| 229 | NSE_CMD_STR |
| 230 | "NS Virtual Connection\n" |
| 231 | "NS Virtual Connection ID (NSVCI)\n" |
| 232 | ) |
| 233 | { |
| 234 | uint16_t nsei = atoi(argv[0]); |
| 235 | uint16_t nsvci = atoi(argv[1]); |
| 236 | struct gprs_nsvc *nsvc; |
| 237 | |
| 238 | nsvc = nsvc_by_nsei(vty_nsi, nsei); |
| 239 | if (!nsvc) { |
| 240 | nsvc = nsvc_create(vty_nsi, nsvci); |
| 241 | nsvc->nsei = nsei; |
| 242 | } |
| 243 | nsvc->nsvci = nsvci; |
| 244 | /* All NSVCs that are explicitly configured by VTY are |
| 245 | * marked as persistent so we can write them to the config |
| 246 | * file at some later point */ |
| 247 | nsvc->persistent = 1; |
| 248 | |
| 249 | return CMD_SUCCESS; |
| 250 | } |
| 251 | |
| 252 | DEFUN(cfg_nse_remoteip, cfg_nse_remoteip_cmd, |
| 253 | "nse <0-65535> remote-ip A.B.C.D", |
| 254 | NSE_CMD_STR |
| 255 | "Remote IP Address\n" |
| 256 | "Remote IP Address\n") |
| 257 | { |
| 258 | uint16_t nsei = atoi(argv[0]); |
| 259 | struct gprs_nsvc *nsvc; |
| 260 | |
| 261 | nsvc = nsvc_by_nsei(vty_nsi, nsei); |
| 262 | if (!nsvc) { |
| 263 | vty_out(vty, "No such NSE (%u)%s", nsei, VTY_NEWLINE); |
| 264 | return CMD_WARNING; |
| 265 | } |
| 266 | inet_aton(argv[1], &nsvc->ip.bts_addr.sin_addr); |
| 267 | |
| 268 | return CMD_SUCCESS; |
| 269 | |
| 270 | } |
| 271 | |
| 272 | DEFUN(cfg_nse_remoteport, cfg_nse_remoteport_cmd, |
| 273 | "nse <0-65535> remote-port <0-65535>", |
| 274 | NSE_CMD_STR |
| 275 | "Remote UDP Port\n" |
| 276 | "Remote UDP Port Number\n") |
| 277 | { |
| 278 | uint16_t nsei = atoi(argv[0]); |
| 279 | uint16_t port = atoi(argv[1]); |
| 280 | struct gprs_nsvc *nsvc; |
| 281 | |
| 282 | nsvc = nsvc_by_nsei(vty_nsi, nsei); |
| 283 | if (!nsvc) { |
| 284 | vty_out(vty, "No such NSE (%u)%s", nsei, VTY_NEWLINE); |
| 285 | return CMD_WARNING; |
| 286 | } |
| 287 | |
Harald Welte | 5540c4c | 2010-05-19 14:38:50 +0200 | [diff] [blame] | 288 | if (nsvc->ll != GPRS_NS_LL_UDP) { |
| 289 | vty_out(vty, "Cannot set UDP Port on non-UDP NSE%s", |
| 290 | VTY_NEWLINE); |
| 291 | return CMD_WARNING; |
| 292 | } |
| 293 | |
Harald Welte | f2b4cd7 | 2010-05-13 11:45:07 +0200 | [diff] [blame] | 294 | nsvc->ip.bts_addr.sin_port = htons(port); |
| 295 | |
| 296 | return CMD_SUCCESS; |
| 297 | } |
| 298 | |
Harald Welte | 5540c4c | 2010-05-19 14:38:50 +0200 | [diff] [blame] | 299 | DEFUN(cfg_nse_fr_dlci, cfg_nse_fr_dlci_cmd, |
| 300 | "nse <0-65535> fr-dlci <0-1023>", |
| 301 | NSE_CMD_STR |
| 302 | "Frame Relay DLCI\n" |
| 303 | "Frame Relay DLCI Number\n") |
| 304 | { |
| 305 | uint16_t nsei = atoi(argv[0]); |
| 306 | uint16_t dlci = atoi(argv[1]); |
| 307 | struct gprs_nsvc *nsvc; |
| 308 | |
| 309 | nsvc = nsvc_by_nsei(vty_nsi, nsei); |
| 310 | if (!nsvc) { |
| 311 | vty_out(vty, "No such NSE (%u)%s", nsei, VTY_NEWLINE); |
| 312 | return CMD_WARNING; |
| 313 | } |
| 314 | |
| 315 | if (nsvc->ll != GPRS_NS_LL_FR_GRE) { |
| 316 | vty_out(vty, "Cannot set FR DLCI on non-FR NSE%s", |
| 317 | VTY_NEWLINE); |
| 318 | return CMD_WARNING; |
| 319 | } |
| 320 | |
| 321 | nsvc->frgre.bts_addr.sin_port = htons(dlci); |
| 322 | |
| 323 | return CMD_SUCCESS; |
| 324 | } |
| 325 | |
| 326 | DEFUN(cfg_nse_encaps, cfg_nse_encaps_cmd, |
| 327 | "nse <0-65535> encapsulation (udp|framerelay-gre)", |
| 328 | NSE_CMD_STR |
| 329 | "Encapsulation for NS\n" |
| 330 | "UDP/IP Encapsulation\n" "Frame-Relay/GRE/IP Encapsulation\n") |
| 331 | { |
| 332 | uint16_t nsei = atoi(argv[0]); |
| 333 | struct gprs_nsvc *nsvc; |
| 334 | |
| 335 | nsvc = nsvc_by_nsei(vty_nsi, nsei); |
| 336 | if (!nsvc) { |
| 337 | vty_out(vty, "No such NSE (%u)%s", nsei, VTY_NEWLINE); |
| 338 | return CMD_WARNING; |
| 339 | } |
| 340 | |
| 341 | if (!strcmp(argv[1], "udp")) |
| 342 | nsvc->ll = GPRS_NS_LL_UDP; |
| 343 | else |
| 344 | nsvc->ll = GPRS_NS_LL_FR_GRE; |
| 345 | |
| 346 | return CMD_SUCCESS; |
| 347 | } |
| 348 | |
| 349 | |
Harald Welte | f2b4cd7 | 2010-05-13 11:45:07 +0200 | [diff] [blame] | 350 | DEFUN(cfg_nse_remoterole, cfg_nse_remoterole_cmd, |
| 351 | "nse <0-65535> remote-role (sgsn|bss)", |
| 352 | NSE_CMD_STR |
| 353 | "Remote NSE Role\n" |
| 354 | "Remote Peer is SGSN\n" |
| 355 | "Remote Peer is BSS\n") |
| 356 | { |
| 357 | uint16_t nsei = atoi(argv[0]); |
| 358 | struct gprs_nsvc *nsvc; |
| 359 | |
| 360 | nsvc = nsvc_by_nsei(vty_nsi, nsei); |
| 361 | if (!nsvc) { |
| 362 | vty_out(vty, "No such NSE (%u)%s", nsei, VTY_NEWLINE); |
| 363 | return CMD_WARNING; |
| 364 | } |
| 365 | |
| 366 | if (!strcmp(argv[1], "sgsn")) |
| 367 | nsvc->remote_end_is_sgsn = 1; |
| 368 | else |
| 369 | nsvc->remote_end_is_sgsn = 0; |
| 370 | |
| 371 | return CMD_SUCCESS; |
| 372 | } |
| 373 | |
| 374 | DEFUN(cfg_no_nse, cfg_no_nse_cmd, |
| 375 | "no nse <0-65535>", |
Harald Welte | 52613a1 | 2010-05-15 23:06:26 +0200 | [diff] [blame] | 376 | "Delete Persistent NS Entity\n" |
Harald Welte | f2b4cd7 | 2010-05-13 11:45:07 +0200 | [diff] [blame] | 377 | "Delete " NSE_CMD_STR) |
| 378 | { |
| 379 | uint16_t nsei = atoi(argv[0]); |
| 380 | struct gprs_nsvc *nsvc; |
| 381 | |
| 382 | nsvc = nsvc_by_nsei(vty_nsi, nsei); |
| 383 | if (!nsvc) { |
| 384 | vty_out(vty, "No such NSE (%u)%s", nsei, VTY_NEWLINE); |
| 385 | return CMD_WARNING; |
| 386 | } |
| 387 | |
Harald Welte | 52613a1 | 2010-05-15 23:06:26 +0200 | [diff] [blame] | 388 | if (!nsvc->persistent) { |
| 389 | vty_out(vty, "NSEI %u is not a persistent NSE%s", |
| 390 | nsei, VTY_NEWLINE); |
| 391 | return CMD_WARNING; |
| 392 | } |
| 393 | |
| 394 | nsvc->persistent = 0; |
Harald Welte | f2b4cd7 | 2010-05-13 11:45:07 +0200 | [diff] [blame] | 395 | |
| 396 | return CMD_SUCCESS; |
| 397 | } |
| 398 | |
| 399 | DEFUN(cfg_ns_timer, cfg_ns_timer_cmd, |
| 400 | "timer " NS_TIMERS " <0-65535>", |
| 401 | "Network Service Timer\n" |
| 402 | NS_TIMERS_HELP "Timer Value\n") |
| 403 | { |
| 404 | int idx = get_string_value(gprs_ns_timer_strs, argv[0]); |
| 405 | int val = atoi(argv[1]); |
| 406 | |
| 407 | if (idx < 0 || idx >= ARRAY_SIZE(vty_nsi->timeout)) |
| 408 | return CMD_WARNING; |
| 409 | |
| 410 | vty_nsi->timeout[idx] = val; |
| 411 | |
| 412 | return CMD_SUCCESS; |
| 413 | } |
| 414 | |
Harald Welte | ff3bde8 | 2010-05-19 15:09:09 +0200 | [diff] [blame] | 415 | #define ENCAPS_STR "NS encapsulation options\n" |
| 416 | |
| 417 | DEFUN(cfg_nsip_local_ip, cfg_nsip_local_ip_cmd, |
| 418 | "encapsulation udp local-ip A.B.C.D", |
| 419 | ENCAPS_STR "NS over UDP Encapsulation\n" |
| 420 | "Set the IP address on which we listen for NS/UDP\n" |
| 421 | "IP Address\n") |
| 422 | { |
| 423 | struct in_addr ia; |
| 424 | |
| 425 | inet_aton(argv[0], &ia); |
| 426 | vty_nsi->nsip.local_ip = ntohl(ia.s_addr); |
| 427 | |
| 428 | return CMD_SUCCESS; |
| 429 | } |
| 430 | |
| 431 | DEFUN(cfg_nsip_local_port, cfg_nsip_local_port_cmd, |
| 432 | "encapsulation udp local-port <0-65535>", |
| 433 | ENCAPS_STR "NS over UDP Encapsulation\n" |
| 434 | "Set the UDP port on which we listen for NS/UDP\n" |
| 435 | "UDP port number\n") |
| 436 | { |
| 437 | unsigned int port = atoi(argv[0]); |
| 438 | |
| 439 | vty_nsi->nsip.local_port = port; |
| 440 | |
| 441 | return CMD_SUCCESS; |
| 442 | } |
| 443 | |
| 444 | DEFUN(cfg_frgre_local_ip, cfg_frgre_local_ip_cmd, |
| 445 | "encapsulation framerelay-gre local-ip A.B.C.D", |
| 446 | ENCAPS_STR "NS over Frame Relay over GRE Encapsulation\n" |
| 447 | "Set the IP address on which we listen for NS/FR/GRE\n" |
| 448 | "IP Address\n") |
| 449 | { |
| 450 | struct in_addr ia; |
| 451 | |
| 452 | if (!vty_nsi->frgre.enabled) { |
| 453 | vty_out(vty, "FR/GRE is not enabled%s", VTY_NEWLINE); |
| 454 | return CMD_WARNING; |
| 455 | } |
| 456 | inet_aton(argv[0], &ia); |
| 457 | vty_nsi->frgre.local_ip = ntohl(ia.s_addr); |
| 458 | |
| 459 | return CMD_SUCCESS; |
| 460 | } |
| 461 | |
| 462 | DEFUN(cfg_frgre_enable, cfg_frgre_enable_cmd, |
| 463 | "encapsulation framerelay-gre enabled (1|0)", |
| 464 | ENCAPS_STR "NS over Frame Relay over GRE Encapsulation\n" |
| 465 | "Enable or disable Frame Relay over GRE\n" |
| 466 | "Enable\n" "Disable\n") |
| 467 | { |
| 468 | int enabled = atoi(argv[0]); |
| 469 | |
| 470 | vty_nsi->frgre.enabled = enabled; |
| 471 | |
| 472 | return CMD_SUCCESS; |
| 473 | } |
| 474 | |
Harald Welte | 9ef9108 | 2010-05-14 19:36:59 +0200 | [diff] [blame] | 475 | DEFUN(nsvc_nsei, nsvc_nsei_cmd, |
| 476 | "nsvc nsei <0-65535> (block|unblock|reset)", |
| 477 | "Perform an operation on a NSVC\n" |
| 478 | "NS-VC Identifier (NS-VCI)\n" |
| 479 | "Initiate BLOCK procedure\n" |
| 480 | "Initiate UNBLOCK procedure\n" |
| 481 | "Initiate RESET procedure\n") |
| 482 | { |
| 483 | uint16_t nsvci = atoi(argv[0]); |
| 484 | const char *operation = argv[1]; |
| 485 | struct gprs_nsvc *nsvc; |
| 486 | |
| 487 | nsvc = nsvc_by_nsei(vty_nsi, nsvci); |
| 488 | if (!nsvc) { |
| 489 | vty_out(vty, "No such NSVCI (%u)%s", nsvci, VTY_NEWLINE); |
| 490 | return CMD_WARNING; |
| 491 | } |
| 492 | |
| 493 | if (!strcmp(operation, "block")) |
| 494 | gprs_ns_tx_block(nsvc, NS_CAUSE_OM_INTERVENTION); |
| 495 | else if (!strcmp(operation, "unblock")) |
| 496 | gprs_ns_tx_unblock(nsvc); |
| 497 | else if (!strcmp(operation, "reset")) |
| 498 | gprs_nsvc_reset(nsvc, NS_CAUSE_OM_INTERVENTION); |
| 499 | else |
| 500 | return CMD_WARNING; |
| 501 | |
| 502 | return CMD_SUCCESS; |
| 503 | } |
| 504 | |
Harald Welte | 8be8c8f | 2010-05-15 23:52:02 +0200 | [diff] [blame] | 505 | DEFUN(logging_fltr_nsvc, |
| 506 | logging_fltr_nsvc_cmd, |
| 507 | "logging filter nsvc (nsei|nsvci) <0-65535>", |
Harald Welte | 9564715 | 2010-05-16 00:00:04 +0200 | [diff] [blame] | 508 | LOGGING_STR FILTER_STR |
Harald Welte | 8be8c8f | 2010-05-15 23:52:02 +0200 | [diff] [blame] | 509 | "Filter based on NS Virtual Connection\n" |
| 510 | "Identify NS-VC by NSEI\n" |
| 511 | "Identify NS-VC by NSVCI\n" |
| 512 | "Numeric identifier\n") |
| 513 | { |
| 514 | struct telnet_connection *conn; |
| 515 | struct gprs_nsvc *nsvc; |
| 516 | uint16_t id = atoi(argv[1]); |
| 517 | |
| 518 | conn = (struct telnet_connection *) vty->priv; |
| 519 | if (!conn->dbg) { |
| 520 | vty_out(vty, "Logging was not enabled.%s", VTY_NEWLINE); |
| 521 | return CMD_WARNING; |
| 522 | } |
| 523 | |
| 524 | if (!strcmp(argv[0], "nsei")) |
| 525 | nsvc = nsvc_by_nsei(vty_nsi, id); |
| 526 | else |
| 527 | nsvc = nsvc_by_nsvci(vty_nsi, id); |
| 528 | |
| 529 | if (!nsvc) { |
| 530 | vty_out(vty, "No NS-VC by that identifier%s", VTY_NEWLINE); |
| 531 | return CMD_WARNING; |
| 532 | } |
| 533 | |
| 534 | log_set_nsvc_filter(conn->dbg, nsvc); |
| 535 | return CMD_SUCCESS; |
| 536 | } |
Harald Welte | 9ef9108 | 2010-05-14 19:36:59 +0200 | [diff] [blame] | 537 | |
Harald Welte | f2b4cd7 | 2010-05-13 11:45:07 +0200 | [diff] [blame] | 538 | int gprs_ns_vty_init(struct gprs_ns_inst *nsi) |
| 539 | { |
| 540 | vty_nsi = nsi; |
| 541 | |
| 542 | install_element_ve(&show_ns_cmd); |
Harald Welte | 73b2359 | 2010-05-13 12:32:30 +0200 | [diff] [blame] | 543 | install_element_ve(&show_ns_stats_cmd); |
Harald Welte | 55c91e4 | 2010-05-15 23:04:03 +0200 | [diff] [blame] | 544 | install_element_ve(&show_nse_cmd); |
Harald Welte | 8be8c8f | 2010-05-15 23:52:02 +0200 | [diff] [blame] | 545 | install_element_ve(&logging_fltr_nsvc_cmd); |
Harald Welte | f2b4cd7 | 2010-05-13 11:45:07 +0200 | [diff] [blame] | 546 | |
| 547 | install_element(CONFIG_NODE, &cfg_ns_cmd); |
| 548 | install_node(&ns_node, config_write_ns); |
| 549 | install_default(NS_NODE); |
Harald Welte | 62ab20c | 2010-05-14 18:59:17 +0200 | [diff] [blame] | 550 | install_element(NS_NODE, &ournode_exit_cmd); |
Harald Welte | 54f7424 | 2010-05-14 19:11:04 +0200 | [diff] [blame] | 551 | install_element(NS_NODE, &ournode_end_cmd); |
Harald Welte | f2b4cd7 | 2010-05-13 11:45:07 +0200 | [diff] [blame] | 552 | install_element(NS_NODE, &cfg_nse_nsvci_cmd); |
| 553 | install_element(NS_NODE, &cfg_nse_remoteip_cmd); |
| 554 | install_element(NS_NODE, &cfg_nse_remoteport_cmd); |
Harald Welte | 5540c4c | 2010-05-19 14:38:50 +0200 | [diff] [blame] | 555 | install_element(NS_NODE, &cfg_nse_fr_dlci_cmd); |
| 556 | install_element(NS_NODE, &cfg_nse_encaps_cmd); |
Harald Welte | f2b4cd7 | 2010-05-13 11:45:07 +0200 | [diff] [blame] | 557 | install_element(NS_NODE, &cfg_nse_remoterole_cmd); |
| 558 | install_element(NS_NODE, &cfg_no_nse_cmd); |
| 559 | install_element(NS_NODE, &cfg_ns_timer_cmd); |
Harald Welte | ff3bde8 | 2010-05-19 15:09:09 +0200 | [diff] [blame] | 560 | install_element(NS_NODE, &cfg_nsip_local_ip_cmd); |
| 561 | install_element(NS_NODE, &cfg_nsip_local_port_cmd); |
| 562 | install_element(NS_NODE, &cfg_frgre_enable_cmd); |
| 563 | install_element(NS_NODE, &cfg_frgre_local_ip_cmd); |
Harald Welte | f2b4cd7 | 2010-05-13 11:45:07 +0200 | [diff] [blame] | 564 | |
Harald Welte | 9ef9108 | 2010-05-14 19:36:59 +0200 | [diff] [blame] | 565 | install_element(ENABLE_NODE, &nsvc_nsei_cmd); |
| 566 | |
Harald Welte | f2b4cd7 | 2010-05-13 11:45:07 +0200 | [diff] [blame] | 567 | return 0; |
| 568 | } |