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