Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +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 | |
| 29 | #include <openbsc/vty.h> |
| 30 | #include <openbsc/mgcpgw_client.h> |
| 31 | |
| 32 | #define MGCPGW_STR "MGCP gateway configuration for RTP streams\n" |
| 33 | |
| 34 | struct mgcpgw_client_conf *global_mgcpgw_client_conf = NULL; |
| 35 | |
| 36 | DEFUN(cfg_mgcpgw_local_ip, cfg_mgcpgw_local_ip_cmd, |
| 37 | "mgcpgw local-ip A.B.C.D", |
| 38 | MGCPGW_STR "local bind to connect to MGCP gateway with\n" |
| 39 | "local bind IP address\n") |
| 40 | { |
| 41 | if (!global_mgcpgw_client_conf) |
| 42 | return CMD_ERR_NOTHING_TODO; |
| 43 | global_mgcpgw_client_conf->local_addr = |
| 44 | talloc_strdup(gsmnet_from_vty(vty), argv[0]); |
| 45 | return CMD_SUCCESS; |
| 46 | } |
| 47 | |
| 48 | DEFUN(cfg_mgcpgw_local_port, cfg_mgcpgw_local_port_cmd, |
| 49 | "mgcpgw local-port <0-65535>", |
| 50 | MGCPGW_STR "local bind to connect to MGCP gateway with\n" |
| 51 | "local bind port\n") |
| 52 | { |
| 53 | if (!global_mgcpgw_client_conf) |
| 54 | return CMD_ERR_NOTHING_TODO; |
| 55 | global_mgcpgw_client_conf->local_port = atoi(argv[0]); |
| 56 | return CMD_SUCCESS; |
| 57 | } |
| 58 | |
| 59 | DEFUN(cfg_mgcpgw_remote_ip, cfg_mgcpgw_remote_ip_cmd, |
| 60 | "mgcpgw remote-ip A.B.C.D", |
| 61 | MGCPGW_STR "remote bind to connect to MGCP gateway with\n" |
| 62 | "remote bind IP address\n") |
| 63 | { |
| 64 | if (!global_mgcpgw_client_conf) |
| 65 | return CMD_ERR_NOTHING_TODO; |
| 66 | global_mgcpgw_client_conf->remote_addr = |
| 67 | talloc_strdup(gsmnet_from_vty(vty), argv[0]); |
| 68 | return CMD_SUCCESS; |
| 69 | } |
| 70 | |
| 71 | DEFUN(cfg_mgcpgw_remote_port, cfg_mgcpgw_remote_port_cmd, |
| 72 | "mgcpgw remote-port <0-65535>", |
| 73 | MGCPGW_STR "remote bind to connect to MGCP gateway with\n" |
| 74 | "remote bind port\n") |
| 75 | { |
| 76 | if (!global_mgcpgw_client_conf) |
| 77 | return CMD_ERR_NOTHING_TODO; |
| 78 | global_mgcpgw_client_conf->remote_port = atoi(argv[0]); |
| 79 | return CMD_SUCCESS; |
| 80 | } |
| 81 | |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 82 | DEFUN(cfg_mgcpgw_endpoint_range, cfg_mgcpgw_endpoint_range_cmd, |
| 83 | "mgcpgw endpoint-range <1-65534> <1-65534>", |
| 84 | MGCPGW_STR "usable range of endpoint identifiers\n" |
| 85 | "set first useable endpoint identifier\n" |
| 86 | "set the last useable endpoint identifier\n") |
| 87 | { |
| 88 | uint16_t first_endpoint = atoi(argv[0]); |
| 89 | uint16_t last_endpoint = atoi(argv[1]); |
| 90 | |
| 91 | if (last_endpoint < first_endpoint) { |
| 92 | vty_out(vty, "last endpoint must be greater than first endpoint!%s", |
| 93 | VTY_NEWLINE); |
| 94 | return CMD_SUCCESS; |
| 95 | } |
| 96 | |
| 97 | global_mgcpgw_client_conf->first_endpoint = first_endpoint; |
| 98 | global_mgcpgw_client_conf->last_endpoint = last_endpoint; |
| 99 | return CMD_SUCCESS; |
| 100 | } |
| 101 | |
| 102 | #define BTS_START_STR "First UDP port allocated for the BTS side\n" |
| 103 | #define UDP_PORT_STR "UDP Port number\n" |
| 104 | DEFUN(cfg_mgcp_rtp_bts_base_port, |
| 105 | cfg_mgcp_rtp_bts_base_port_cmd, |
| 106 | "mgcpgw bts-base <0-65534>", |
| 107 | MGCPGW_STR |
| 108 | BTS_START_STR |
| 109 | UDP_PORT_STR) |
| 110 | { |
| 111 | global_mgcpgw_client_conf->bts_base = atoi(argv[0]); |
| 112 | return CMD_SUCCESS; |
| 113 | } |
| 114 | |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 115 | int mgcpgw_client_config_write(struct vty *vty, const char *indent) |
| 116 | { |
| 117 | const char *addr; |
| 118 | int port; |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 119 | uint16_t first_endpoint; |
| 120 | uint16_t last_endpoint; |
| 121 | uint16_t bts_base; |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 122 | |
| 123 | addr = global_mgcpgw_client_conf->local_addr; |
| 124 | if (addr) |
| 125 | vty_out(vty, "%smgcpgw local-ip %s%s", indent, addr, |
| 126 | VTY_NEWLINE); |
| 127 | port = global_mgcpgw_client_conf->local_port; |
| 128 | if (port >= 0) |
| 129 | vty_out(vty, "%smgcpgw local-port %u%s", indent, |
| 130 | (uint16_t)port, VTY_NEWLINE); |
| 131 | |
| 132 | addr = global_mgcpgw_client_conf->remote_addr; |
| 133 | if (addr) |
| 134 | vty_out(vty, "%smgcpgw remote-ip %s%s", indent, addr, |
| 135 | VTY_NEWLINE); |
| 136 | port = global_mgcpgw_client_conf->remote_port; |
| 137 | if (port >= 0) |
| 138 | vty_out(vty, "%smgcpgw remote-port %u%s", indent, |
| 139 | (uint16_t)port, VTY_NEWLINE); |
| 140 | |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 141 | first_endpoint = global_mgcpgw_client_conf->first_endpoint; |
| 142 | last_endpoint = global_mgcpgw_client_conf->last_endpoint; |
| 143 | if (last_endpoint != 0) { |
| 144 | vty_out(vty, "%smgcpgw endpoint-range %u %u%s", indent, |
| 145 | first_endpoint, last_endpoint, VTY_NEWLINE); |
| 146 | } |
| 147 | |
| 148 | bts_base = global_mgcpgw_client_conf->bts_base; |
| 149 | if (bts_base) { |
| 150 | vty_out(vty, "%smgcpgw bts-base %u%s", indent, |
| 151 | bts_base, VTY_NEWLINE); |
| 152 | } |
| 153 | |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 154 | return CMD_SUCCESS; |
| 155 | } |
| 156 | |
| 157 | void mgcpgw_client_vty_init(int node, struct mgcpgw_client_conf *conf) |
| 158 | { |
| 159 | global_mgcpgw_client_conf = conf; |
| 160 | |
| 161 | install_element(node, &cfg_mgcpgw_local_ip_cmd); |
| 162 | install_element(node, &cfg_mgcpgw_local_port_cmd); |
| 163 | install_element(node, &cfg_mgcpgw_remote_ip_cmd); |
| 164 | install_element(node, &cfg_mgcpgw_remote_port_cmd); |
Philipp Maier | fbf6610 | 2017-04-09 12:32:51 +0200 | [diff] [blame] | 165 | install_element(node, &cfg_mgcpgw_endpoint_range_cmd); |
| 166 | install_element(node, &cfg_mgcp_rtp_bts_base_port_cmd); |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 167 | } |