Pau Espin Pedrol | 1ddefb1 | 2019-08-30 19:48:34 +0200 | [diff] [blame] | 1 | /* Control Interface Implementation for the Gb-proxy */ |
| 2 | /* |
| 3 | * (C) 2018 by sysmocom s.f.m.c. GmbH <info@sysmocom.de> |
| 4 | * All Rights Reserved |
| 5 | * |
| 6 | * Author: Daniel Willmann |
| 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 <osmocom/core/talloc.h> |
| 24 | |
| 25 | |
| 26 | #include <osmocom/gprs/gprs_bssgp.h> |
| 27 | #include <osmocom/gprs/gprs_ns.h> |
| 28 | |
| 29 | #include <osmocom/ctrl/control_if.h> |
| 30 | #include <osmocom/ctrl/control_cmd.h> |
Daniel Willmann | a16ecc3 | 2021-03-10 09:57:12 +0100 | [diff] [blame] | 31 | #include <osmocom/gbproxy/gb_proxy.h> |
Oliver Smith | 29532c2 | 2021-01-29 11:13:00 +0100 | [diff] [blame] | 32 | |
| 33 | #include "debug.h" |
Pau Espin Pedrol | 1ddefb1 | 2019-08-30 19:48:34 +0200 | [diff] [blame] | 34 | |
| 35 | extern vector ctrl_node_vec; |
| 36 | |
Daniel Willmann | 2fca219 | 2020-11-04 17:32:11 +0100 | [diff] [blame] | 37 | struct nsvc_cb_data { |
| 38 | struct ctrl_cmd *cmd; |
| 39 | uint16_t nsei; |
| 40 | bool is_sgsn; |
| 41 | }; |
Alexander Couzens | 951e133 | 2020-09-22 13:21:46 +0200 | [diff] [blame] | 42 | |
Daniel Willmann | 2fca219 | 2020-11-04 17:32:11 +0100 | [diff] [blame] | 43 | static int ctrl_nsvc_state_cb(struct gprs_ns2_vc *nsvc, void *ctx) { |
| 44 | struct nsvc_cb_data *data = (struct nsvc_cb_data *)ctx; |
| 45 | struct ctrl_cmd *cmd = (struct ctrl_cmd *)data->cmd; |
| 46 | |
| 47 | cmd->reply = talloc_asprintf_append(cmd->reply, "%u,%s,%s,%s\n", |
| 48 | data->nsei, gprs_ns2_ll_str(nsvc), gprs_ns2_nsvc_state_name(nsvc), |
| 49 | data->is_sgsn ? "SGSN" : "BSS" ); |
| 50 | |
Alexander Couzens | 951e133 | 2020-09-22 13:21:46 +0200 | [diff] [blame] | 51 | return 0; |
| 52 | } |
| 53 | |
Pau Espin Pedrol | 1ddefb1 | 2019-08-30 19:48:34 +0200 | [diff] [blame] | 54 | static int get_nsvc_state(struct ctrl_cmd *cmd, void *data) |
| 55 | { |
| 56 | struct gbproxy_config *cfg = data; |
Alexander Couzens | 951e133 | 2020-09-22 13:21:46 +0200 | [diff] [blame] | 57 | struct gprs_ns2_inst *nsi = cfg->nsi; |
| 58 | struct gprs_ns2_nse *nse; |
Daniel Willmann | e50550e | 2020-11-26 18:19:21 +0100 | [diff] [blame] | 59 | struct gbproxy_nse *nse_peer; |
Harald Welte | d2fef95 | 2020-12-05 00:31:07 +0100 | [diff] [blame] | 60 | int i; |
Pau Espin Pedrol | 1ddefb1 | 2019-08-30 19:48:34 +0200 | [diff] [blame] | 61 | |
| 62 | cmd->reply = talloc_strdup(cmd, ""); |
| 63 | |
Alexander Couzens | 951e133 | 2020-09-22 13:21:46 +0200 | [diff] [blame] | 64 | /* NS-VCs for SGSN */ |
Harald Welte | e520964 | 2020-12-05 19:59:45 +0100 | [diff] [blame] | 65 | hash_for_each(cfg->sgsn_nses, i, nse_peer, list) { |
| 66 | nse = gprs_ns2_nse_by_nsei(nsi, nse_peer->nsei); |
Daniel Willmann | 5e8c0e8 | 2021-07-19 16:05:59 +0200 | [diff] [blame] | 67 | if (nse) { |
| 68 | struct nsvc_cb_data cb_data = { |
| 69 | .cmd = cmd, |
| 70 | .nsei = nse_peer->nsei, |
| 71 | .is_sgsn = true, |
| 72 | }; |
| 73 | gprs_ns2_nse_foreach_nsvc(nse, &ctrl_nsvc_state_cb, &cb_data); |
| 74 | } |
Harald Welte | e520964 | 2020-12-05 19:59:45 +0100 | [diff] [blame] | 75 | } |
Pau Espin Pedrol | 1ddefb1 | 2019-08-30 19:48:34 +0200 | [diff] [blame] | 76 | |
Alexander Couzens | 951e133 | 2020-09-22 13:21:46 +0200 | [diff] [blame] | 77 | /* NS-VCs for BSS peers */ |
Harald Welte | d2fef95 | 2020-12-05 00:31:07 +0100 | [diff] [blame] | 78 | hash_for_each(cfg->bss_nses, i, nse_peer, list) { |
Daniel Willmann | e50550e | 2020-11-26 18:19:21 +0100 | [diff] [blame] | 79 | nse = gprs_ns2_nse_by_nsei(nsi, nse_peer->nsei); |
Daniel Willmann | 5e8c0e8 | 2021-07-19 16:05:59 +0200 | [diff] [blame] | 80 | if (nse) { |
| 81 | struct nsvc_cb_data cb_data = { |
| 82 | .cmd = cmd, |
| 83 | .nsei = nse_peer->nsei, |
| 84 | .is_sgsn = true, |
| 85 | }; |
| 86 | gprs_ns2_nse_foreach_nsvc(nse, &ctrl_nsvc_state_cb, &cb_data); |
| 87 | } |
Pau Espin Pedrol | 1ddefb1 | 2019-08-30 19:48:34 +0200 | [diff] [blame] | 88 | } |
Daniel Willmann | 2fca219 | 2020-11-04 17:32:11 +0100 | [diff] [blame] | 89 | |
| 90 | return CTRL_CMD_REPLY; |
Pau Espin Pedrol | 1ddefb1 | 2019-08-30 19:48:34 +0200 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | CTRL_CMD_DEFINE_RO(nsvc_state, "nsvc-state"); |
| 94 | |
| 95 | static int get_gbproxy_state(struct ctrl_cmd *cmd, void *data) |
| 96 | { |
| 97 | struct gbproxy_config *cfg = data; |
Daniel Willmann | e50550e | 2020-11-26 18:19:21 +0100 | [diff] [blame] | 98 | struct gbproxy_nse *nse_peer; |
Harald Welte | 8b4c794 | 2020-12-05 10:14:49 +0100 | [diff] [blame] | 99 | int i, j; |
Pau Espin Pedrol | 1ddefb1 | 2019-08-30 19:48:34 +0200 | [diff] [blame] | 100 | |
| 101 | cmd->reply = talloc_strdup(cmd, ""); |
| 102 | |
Harald Welte | d2fef95 | 2020-12-05 00:31:07 +0100 | [diff] [blame] | 103 | hash_for_each(cfg->bss_nses, i, nse_peer, list) { |
Harald Welte | 560bdb3 | 2020-12-04 22:24:47 +0100 | [diff] [blame] | 104 | struct gbproxy_bvc *bvc; |
Harald Welte | 8b4c794 | 2020-12-05 10:14:49 +0100 | [diff] [blame] | 105 | hash_for_each(nse_peer->bvcs, j, bvc, list) { |
Daniel Willmann | 5f76259 | 2021-07-19 16:08:20 +0200 | [diff] [blame] | 106 | if (bvc->bvci == 0) |
| 107 | continue; |
| 108 | |
Philipp Maier | da3af94 | 2021-02-04 21:54:09 +0100 | [diff] [blame] | 109 | struct gprs_ra_id *raid = &bvc->cell->id.raid; |
Pau Espin Pedrol | 1ddefb1 | 2019-08-30 19:48:34 +0200 | [diff] [blame] | 110 | |
Philipp Maier | 55a22b8 | 2021-02-04 17:27:53 +0100 | [diff] [blame] | 111 | cmd->reply = talloc_asprintf_append(cmd->reply, "%u,%u,%u-%u-%u-%u,%s\n", |
Harald Welte | 560bdb3 | 2020-12-04 22:24:47 +0100 | [diff] [blame] | 112 | nse_peer->nsei, bvc->bvci, |
Philipp Maier | da3af94 | 2021-02-04 21:54:09 +0100 | [diff] [blame] | 113 | raid->mcc, raid->mnc, |
| 114 | raid->lac, raid->rac, |
Harald Welte | e520964 | 2020-12-05 19:59:45 +0100 | [diff] [blame] | 115 | osmo_fsm_inst_state_name(bvc->fi)); |
Daniel Willmann | e50550e | 2020-11-26 18:19:21 +0100 | [diff] [blame] | 116 | } |
Pau Espin Pedrol | 1ddefb1 | 2019-08-30 19:48:34 +0200 | [diff] [blame] | 117 | } |
| 118 | |
| 119 | return CTRL_CMD_REPLY; |
| 120 | } |
| 121 | |
| 122 | CTRL_CMD_DEFINE_RO(gbproxy_state, "gbproxy-state"); |
| 123 | |
| 124 | static int get_num_peers(struct ctrl_cmd *cmd, void *data) |
| 125 | { |
| 126 | struct gbproxy_config *cfg = data; |
Daniel Willmann | e50550e | 2020-11-26 18:19:21 +0100 | [diff] [blame] | 127 | struct gbproxy_nse *nse_peer; |
Harald Welte | 8b4c794 | 2020-12-05 10:14:49 +0100 | [diff] [blame] | 128 | struct gbproxy_bvc *bvc; |
Daniel Willmann | e50550e | 2020-11-26 18:19:21 +0100 | [diff] [blame] | 129 | uint32_t count = 0; |
Harald Welte | 8b4c794 | 2020-12-05 10:14:49 +0100 | [diff] [blame] | 130 | int i, j; |
Daniel Willmann | e50550e | 2020-11-26 18:19:21 +0100 | [diff] [blame] | 131 | |
Harald Welte | 8b4c794 | 2020-12-05 10:14:49 +0100 | [diff] [blame] | 132 | hash_for_each(cfg->bss_nses, i, nse_peer, list) { |
Daniel Willmann | 5f76259 | 2021-07-19 16:08:20 +0200 | [diff] [blame] | 133 | hash_for_each(nse_peer->bvcs, j, bvc, list) { |
| 134 | if (bvc->bvci == 0) |
| 135 | continue; |
Harald Welte | 8b4c794 | 2020-12-05 10:14:49 +0100 | [diff] [blame] | 136 | count++; |
Daniel Willmann | 5f76259 | 2021-07-19 16:08:20 +0200 | [diff] [blame] | 137 | } |
Harald Welte | 8b4c794 | 2020-12-05 10:14:49 +0100 | [diff] [blame] | 138 | } |
Pau Espin Pedrol | 1ddefb1 | 2019-08-30 19:48:34 +0200 | [diff] [blame] | 139 | |
| 140 | cmd->reply = talloc_strdup(cmd, ""); |
Daniel Willmann | e50550e | 2020-11-26 18:19:21 +0100 | [diff] [blame] | 141 | cmd->reply = talloc_asprintf_append(cmd->reply, "%u", count); |
Pau Espin Pedrol | 1ddefb1 | 2019-08-30 19:48:34 +0200 | [diff] [blame] | 142 | |
| 143 | return CTRL_CMD_REPLY; |
| 144 | } |
| 145 | CTRL_CMD_DEFINE_RO(num_peers, "number-of-peers"); |
| 146 | |
| 147 | int gb_ctrl_cmds_install(void) |
| 148 | { |
| 149 | int rc = 0; |
| 150 | rc |= ctrl_cmd_install(CTRL_NODE_ROOT, &cmd_nsvc_state); |
| 151 | rc |= ctrl_cmd_install(CTRL_NODE_ROOT, &cmd_gbproxy_state); |
| 152 | rc |= ctrl_cmd_install(CTRL_NODE_ROOT, &cmd_num_peers); |
| 153 | |
| 154 | return rc; |
| 155 | } |