Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 1 | /* MGCPGW client interface to quagga VTY */ |
| 2 | /* (C) 2016 by sysmocom s.m.f.c. GmbH <info@sysmocom.de> |
| 3 | * Based on OpenBSC interface to quagga VTY (libmsc/vty_interface_layer3.c) |
| 4 | * (C) 2009 by Harald Welte <laforge@gnumonks.org> |
| 5 | * (C) 2009-2011 by Holger Hans Peter Freyther |
| 6 | * All Rights Reserved |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU Affero General Public License as published by |
| 10 | * the Free Software Foundation; either version 3 of the License, or |
| 11 | * (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU Affero General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU Affero General Public License |
| 19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 20 | * |
| 21 | */ |
| 22 | |
| 23 | #include <inttypes.h> |
| 24 | #include <stdlib.h> |
| 25 | #include <talloc.h> |
| 26 | |
| 27 | #include <osmocom/vty/command.h> |
| 28 | #include <osmocom/core/utils.h> |
| 29 | |
Neels Hofmeyr | 3a8e723 | 2017-09-04 01:02:56 +0200 | [diff] [blame] | 30 | #include <osmocom/mgcp_client/mgcp_client.h> |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 31 | |
| 32 | #define MGCPGW_STR "MGCP gateway configuration for RTP streams\n" |
| 33 | |
Neels Hofmeyr | 3a8e723 | 2017-09-04 01:02:56 +0200 | [diff] [blame] | 34 | void *global_mgcp_client_ctx = NULL; |
| 35 | struct mgcp_client_conf *global_mgcp_client_conf = NULL; |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 36 | |
| 37 | DEFUN(cfg_mgcpgw_local_ip, cfg_mgcpgw_local_ip_cmd, |
| 38 | "mgcpgw local-ip A.B.C.D", |
| 39 | MGCPGW_STR "local bind to connect to MGCP gateway with\n" |
| 40 | "local bind IP address\n") |
| 41 | { |
Neels Hofmeyr | 3a8e723 | 2017-09-04 01:02:56 +0200 | [diff] [blame] | 42 | if (!global_mgcp_client_conf) |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 43 | return CMD_ERR_NOTHING_TODO; |
Neels Hofmeyr | 3a8e723 | 2017-09-04 01:02:56 +0200 | [diff] [blame] | 44 | OSMO_ASSERT(global_mgcp_client_ctx); |
| 45 | global_mgcp_client_conf->local_addr = |
| 46 | talloc_strdup(global_mgcp_client_ctx, argv[0]); |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 47 | return CMD_SUCCESS; |
| 48 | } |
| 49 | |
| 50 | DEFUN(cfg_mgcpgw_local_port, cfg_mgcpgw_local_port_cmd, |
| 51 | "mgcpgw local-port <0-65535>", |
| 52 | MGCPGW_STR "local bind to connect to MGCP gateway with\n" |
| 53 | "local bind port\n") |
| 54 | { |
Neels Hofmeyr | 3a8e723 | 2017-09-04 01:02:56 +0200 | [diff] [blame] | 55 | if (!global_mgcp_client_conf) |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 56 | return CMD_ERR_NOTHING_TODO; |
Neels Hofmeyr | 3a8e723 | 2017-09-04 01:02:56 +0200 | [diff] [blame] | 57 | global_mgcp_client_conf->local_port = atoi(argv[0]); |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 58 | return CMD_SUCCESS; |
| 59 | } |
| 60 | |
| 61 | DEFUN(cfg_mgcpgw_remote_ip, cfg_mgcpgw_remote_ip_cmd, |
| 62 | "mgcpgw remote-ip A.B.C.D", |
| 63 | MGCPGW_STR "remote bind to connect to MGCP gateway with\n" |
| 64 | "remote bind IP address\n") |
| 65 | { |
Neels Hofmeyr | 3a8e723 | 2017-09-04 01:02:56 +0200 | [diff] [blame] | 66 | if (!global_mgcp_client_conf) |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 67 | return CMD_ERR_NOTHING_TODO; |
Neels Hofmeyr | 3a8e723 | 2017-09-04 01:02:56 +0200 | [diff] [blame] | 68 | OSMO_ASSERT(global_mgcp_client_ctx); |
| 69 | global_mgcp_client_conf->remote_addr = |
| 70 | talloc_strdup(global_mgcp_client_ctx, argv[0]); |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 71 | return CMD_SUCCESS; |
| 72 | } |
| 73 | |
| 74 | DEFUN(cfg_mgcpgw_remote_port, cfg_mgcpgw_remote_port_cmd, |
| 75 | "mgcpgw remote-port <0-65535>", |
| 76 | MGCPGW_STR "remote bind to connect to MGCP gateway with\n" |
| 77 | "remote bind port\n") |
| 78 | { |
Neels Hofmeyr | 3a8e723 | 2017-09-04 01:02:56 +0200 | [diff] [blame] | 79 | if (!global_mgcp_client_conf) |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 80 | return CMD_ERR_NOTHING_TODO; |
Neels Hofmeyr | 3a8e723 | 2017-09-04 01:02:56 +0200 | [diff] [blame] | 81 | global_mgcp_client_conf->remote_port = atoi(argv[0]); |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 82 | return CMD_SUCCESS; |
| 83 | } |
| 84 | |
| 85 | DEFUN(cfg_mgcpgw_endpoint_range, cfg_mgcpgw_endpoint_range_cmd, |
| 86 | "mgcpgw endpoint-range <1-65534> <1-65534>", |
| 87 | MGCPGW_STR "usable range of endpoint identifiers\n" |
| 88 | "set first useable endpoint identifier\n" |
| 89 | "set the last useable endpoint identifier\n") |
| 90 | { |
| 91 | uint16_t first_endpoint = atoi(argv[0]); |
| 92 | uint16_t last_endpoint = atoi(argv[1]); |
| 93 | |
| 94 | if (last_endpoint < first_endpoint) { |
| 95 | vty_out(vty, "last endpoint must be greater than first endpoint!%s", |
| 96 | VTY_NEWLINE); |
| 97 | return CMD_SUCCESS; |
| 98 | } |
| 99 | |
Neels Hofmeyr | 3a8e723 | 2017-09-04 01:02:56 +0200 | [diff] [blame] | 100 | global_mgcp_client_conf->first_endpoint = first_endpoint; |
| 101 | global_mgcp_client_conf->last_endpoint = last_endpoint; |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 102 | return CMD_SUCCESS; |
| 103 | } |
| 104 | |
| 105 | #define BTS_START_STR "First UDP port allocated for the BTS side\n" |
| 106 | #define UDP_PORT_STR "UDP Port number\n" |
| 107 | DEFUN(cfg_mgcp_rtp_bts_base_port, |
| 108 | cfg_mgcp_rtp_bts_base_port_cmd, |
| 109 | "mgcpgw bts-base <0-65534>", |
| 110 | MGCPGW_STR |
| 111 | BTS_START_STR |
| 112 | UDP_PORT_STR) |
| 113 | { |
Neels Hofmeyr | 3a8e723 | 2017-09-04 01:02:56 +0200 | [diff] [blame] | 114 | global_mgcp_client_conf->bts_base = atoi(argv[0]); |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 115 | return CMD_SUCCESS; |
| 116 | } |
| 117 | |
Neels Hofmeyr | 3a8e723 | 2017-09-04 01:02:56 +0200 | [diff] [blame] | 118 | int mgcp_client_config_write(struct vty *vty, const char *indent) |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 119 | { |
| 120 | const char *addr; |
| 121 | int port; |
| 122 | uint16_t first_endpoint; |
| 123 | uint16_t last_endpoint; |
| 124 | uint16_t bts_base; |
| 125 | |
Neels Hofmeyr | 3a8e723 | 2017-09-04 01:02:56 +0200 | [diff] [blame] | 126 | addr = global_mgcp_client_conf->local_addr; |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 127 | if (addr) |
| 128 | vty_out(vty, "%smgcpgw local-ip %s%s", indent, addr, |
| 129 | VTY_NEWLINE); |
Neels Hofmeyr | 3a8e723 | 2017-09-04 01:02:56 +0200 | [diff] [blame] | 130 | port = global_mgcp_client_conf->local_port; |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 131 | if (port >= 0) |
| 132 | vty_out(vty, "%smgcpgw local-port %u%s", indent, |
| 133 | (uint16_t)port, VTY_NEWLINE); |
| 134 | |
Neels Hofmeyr | 3a8e723 | 2017-09-04 01:02:56 +0200 | [diff] [blame] | 135 | addr = global_mgcp_client_conf->remote_addr; |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 136 | if (addr) |
| 137 | vty_out(vty, "%smgcpgw remote-ip %s%s", indent, addr, |
| 138 | VTY_NEWLINE); |
Neels Hofmeyr | 3a8e723 | 2017-09-04 01:02:56 +0200 | [diff] [blame] | 139 | port = global_mgcp_client_conf->remote_port; |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 140 | if (port >= 0) |
| 141 | vty_out(vty, "%smgcpgw remote-port %u%s", indent, |
| 142 | (uint16_t)port, VTY_NEWLINE); |
| 143 | |
Neels Hofmeyr | 3a8e723 | 2017-09-04 01:02:56 +0200 | [diff] [blame] | 144 | first_endpoint = global_mgcp_client_conf->first_endpoint; |
| 145 | last_endpoint = global_mgcp_client_conf->last_endpoint; |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 146 | if (last_endpoint != 0) { |
| 147 | vty_out(vty, "%smgcpgw endpoint-range %u %u%s", indent, |
| 148 | first_endpoint, last_endpoint, VTY_NEWLINE); |
| 149 | } |
| 150 | |
Neels Hofmeyr | 3a8e723 | 2017-09-04 01:02:56 +0200 | [diff] [blame] | 151 | bts_base = global_mgcp_client_conf->bts_base; |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 152 | if (bts_base) { |
| 153 | vty_out(vty, "%smgcpgw bts-base %u%s", indent, |
| 154 | bts_base, VTY_NEWLINE); |
| 155 | } |
| 156 | |
| 157 | return CMD_SUCCESS; |
| 158 | } |
| 159 | |
Neels Hofmeyr | 3a8e723 | 2017-09-04 01:02:56 +0200 | [diff] [blame] | 160 | void mgcp_client_vty_init(void *talloc_ctx, int node, struct mgcp_client_conf *conf) |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 161 | { |
Neels Hofmeyr | 3a8e723 | 2017-09-04 01:02:56 +0200 | [diff] [blame] | 162 | global_mgcp_client_ctx = talloc_ctx; |
| 163 | global_mgcp_client_conf = conf; |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 164 | |
| 165 | install_element(node, &cfg_mgcpgw_local_ip_cmd); |
| 166 | install_element(node, &cfg_mgcpgw_local_port_cmd); |
| 167 | install_element(node, &cfg_mgcpgw_remote_ip_cmd); |
| 168 | install_element(node, &cfg_mgcpgw_remote_port_cmd); |
| 169 | install_element(node, &cfg_mgcpgw_endpoint_range_cmd); |
| 170 | install_element(node, &cfg_mgcp_rtp_bts_base_port_cmd); |
| 171 | } |