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