blob: 35ef81b1eb70d97ad9ca1177db465da66c3293f6 [file] [log] [blame]
Pau Espin Pedrol1ddefb12019-08-30 19:48:34 +02001/* 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 Willmanna16ecc32021-03-10 09:57:12 +010031#include <osmocom/gbproxy/gb_proxy.h>
Oliver Smith29532c22021-01-29 11:13:00 +010032
33#include "debug.h"
Pau Espin Pedrol1ddefb12019-08-30 19:48:34 +020034
35extern vector ctrl_node_vec;
36
Daniel Willmann2fca2192020-11-04 17:32:11 +010037struct nsvc_cb_data {
38 struct ctrl_cmd *cmd;
39 uint16_t nsei;
40 bool is_sgsn;
41};
Alexander Couzens951e1332020-09-22 13:21:46 +020042
Daniel Willmann2fca2192020-11-04 17:32:11 +010043static 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 Couzens951e1332020-09-22 13:21:46 +020051 return 0;
52}
53
Pau Espin Pedrol1ddefb12019-08-30 19:48:34 +020054static int get_nsvc_state(struct ctrl_cmd *cmd, void *data)
55{
56 struct gbproxy_config *cfg = data;
Alexander Couzens951e1332020-09-22 13:21:46 +020057 struct gprs_ns2_inst *nsi = cfg->nsi;
58 struct gprs_ns2_nse *nse;
Daniel Willmanne50550e2020-11-26 18:19:21 +010059 struct gbproxy_nse *nse_peer;
Harald Welted2fef952020-12-05 00:31:07 +010060 int i;
Pau Espin Pedrol1ddefb12019-08-30 19:48:34 +020061
62 cmd->reply = talloc_strdup(cmd, "");
63
Alexander Couzens951e1332020-09-22 13:21:46 +020064 /* NS-VCs for SGSN */
Harald Weltee5209642020-12-05 19:59:45 +010065 hash_for_each(cfg->sgsn_nses, i, nse_peer, list) {
66 nse = gprs_ns2_nse_by_nsei(nsi, nse_peer->nsei);
67 if (nse)
68 gprs_ns2_nse_foreach_nsvc(nse, &ctrl_nsvc_state_cb, cmd);
69 }
Pau Espin Pedrol1ddefb12019-08-30 19:48:34 +020070
Alexander Couzens951e1332020-09-22 13:21:46 +020071 /* NS-VCs for BSS peers */
Harald Welted2fef952020-12-05 00:31:07 +010072 hash_for_each(cfg->bss_nses, i, nse_peer, list) {
Daniel Willmanne50550e2020-11-26 18:19:21 +010073 nse = gprs_ns2_nse_by_nsei(nsi, nse_peer->nsei);
Alexander Couzens951e1332020-09-22 13:21:46 +020074 if (nse)
75 gprs_ns2_nse_foreach_nsvc(nse, &ctrl_nsvc_state_cb, cmd);
Pau Espin Pedrol1ddefb12019-08-30 19:48:34 +020076 }
Daniel Willmann2fca2192020-11-04 17:32:11 +010077
78 return CTRL_CMD_REPLY;
Pau Espin Pedrol1ddefb12019-08-30 19:48:34 +020079}
80
81CTRL_CMD_DEFINE_RO(nsvc_state, "nsvc-state");
82
83static int get_gbproxy_state(struct ctrl_cmd *cmd, void *data)
84{
85 struct gbproxy_config *cfg = data;
Daniel Willmanne50550e2020-11-26 18:19:21 +010086 struct gbproxy_nse *nse_peer;
Harald Welte8b4c7942020-12-05 10:14:49 +010087 int i, j;
Pau Espin Pedrol1ddefb12019-08-30 19:48:34 +020088
89 cmd->reply = talloc_strdup(cmd, "");
90
Harald Welted2fef952020-12-05 00:31:07 +010091 hash_for_each(cfg->bss_nses, i, nse_peer, list) {
Harald Welte560bdb32020-12-04 22:24:47 +010092 struct gbproxy_bvc *bvc;
Harald Welte8b4c7942020-12-05 10:14:49 +010093 hash_for_each(nse_peer->bvcs, j, bvc, list) {
Philipp Maierda3af942021-02-04 21:54:09 +010094 struct gprs_ra_id *raid = &bvc->cell->id.raid;
Pau Espin Pedrol1ddefb12019-08-30 19:48:34 +020095
Philipp Maier55a22b82021-02-04 17:27:53 +010096 cmd->reply = talloc_asprintf_append(cmd->reply, "%u,%u,%u-%u-%u-%u,%s\n",
Harald Welte560bdb32020-12-04 22:24:47 +010097 nse_peer->nsei, bvc->bvci,
Philipp Maierda3af942021-02-04 21:54:09 +010098 raid->mcc, raid->mnc,
99 raid->lac, raid->rac,
Harald Weltee5209642020-12-05 19:59:45 +0100100 osmo_fsm_inst_state_name(bvc->fi));
Daniel Willmanne50550e2020-11-26 18:19:21 +0100101 }
Pau Espin Pedrol1ddefb12019-08-30 19:48:34 +0200102 }
103
104 return CTRL_CMD_REPLY;
105}
106
107CTRL_CMD_DEFINE_RO(gbproxy_state, "gbproxy-state");
108
109static int get_num_peers(struct ctrl_cmd *cmd, void *data)
110{
111 struct gbproxy_config *cfg = data;
Daniel Willmanne50550e2020-11-26 18:19:21 +0100112 struct gbproxy_nse *nse_peer;
Harald Welte8b4c7942020-12-05 10:14:49 +0100113 struct gbproxy_bvc *bvc;
Daniel Willmanne50550e2020-11-26 18:19:21 +0100114 uint32_t count = 0;
Harald Welte8b4c7942020-12-05 10:14:49 +0100115 int i, j;
Daniel Willmanne50550e2020-11-26 18:19:21 +0100116
Harald Welte8b4c7942020-12-05 10:14:49 +0100117 hash_for_each(cfg->bss_nses, i, nse_peer, list) {
118 hash_for_each(nse_peer->bvcs, j, bvc, list)
119 count++;
120 }
Pau Espin Pedrol1ddefb12019-08-30 19:48:34 +0200121
122 cmd->reply = talloc_strdup(cmd, "");
Daniel Willmanne50550e2020-11-26 18:19:21 +0100123 cmd->reply = talloc_asprintf_append(cmd->reply, "%u", count);
Pau Espin Pedrol1ddefb12019-08-30 19:48:34 +0200124
125 return CTRL_CMD_REPLY;
126}
127CTRL_CMD_DEFINE_RO(num_peers, "number-of-peers");
128
129int gb_ctrl_cmds_install(void)
130{
131 int rc = 0;
132 rc |= ctrl_cmd_install(CTRL_NODE_ROOT, &cmd_nsvc_state);
133 rc |= ctrl_cmd_install(CTRL_NODE_ROOT, &cmd_gbproxy_state);
134 rc |= ctrl_cmd_install(CTRL_NODE_ROOT, &cmd_num_peers);
135
136 return rc;
137}