blob: 482bca013d0a98b540a8738dc1244b8190a871e9 [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>
31#include <osmocom/sgsn/gb_proxy.h>
32#include <osmocom/sgsn/debug.h>
33
34extern vector ctrl_node_vec;
35
Daniel Willmann2fca2192020-11-04 17:32:11 +010036struct nsvc_cb_data {
37 struct ctrl_cmd *cmd;
38 uint16_t nsei;
39 bool is_sgsn;
40};
Alexander Couzens951e1332020-09-22 13:21:46 +020041
Daniel Willmann2fca2192020-11-04 17:32:11 +010042static int ctrl_nsvc_state_cb(struct gprs_ns2_vc *nsvc, void *ctx) {
43 struct nsvc_cb_data *data = (struct nsvc_cb_data *)ctx;
44 struct ctrl_cmd *cmd = (struct ctrl_cmd *)data->cmd;
45
46 cmd->reply = talloc_asprintf_append(cmd->reply, "%u,%s,%s,%s\n",
47 data->nsei, gprs_ns2_ll_str(nsvc), gprs_ns2_nsvc_state_name(nsvc),
48 data->is_sgsn ? "SGSN" : "BSS" );
49
Alexander Couzens951e1332020-09-22 13:21:46 +020050 return 0;
51}
52
Pau Espin Pedrol1ddefb12019-08-30 19:48:34 +020053static int get_nsvc_state(struct ctrl_cmd *cmd, void *data)
54{
55 struct gbproxy_config *cfg = data;
Alexander Couzens951e1332020-09-22 13:21:46 +020056 struct gprs_ns2_inst *nsi = cfg->nsi;
57 struct gprs_ns2_nse *nse;
Daniel Willmanne50550e2020-11-26 18:19:21 +010058 struct gbproxy_nse *nse_peer;
Pau Espin Pedrol1ddefb12019-08-30 19:48:34 +020059
60 cmd->reply = talloc_strdup(cmd, "");
61
Alexander Couzens951e1332020-09-22 13:21:46 +020062 /* NS-VCs for SGSN */
63 nse = gprs_ns2_nse_by_nsei(nsi, cfg->nsip_sgsn_nsei);
64 if (nse)
65 gprs_ns2_nse_foreach_nsvc(nse, &ctrl_nsvc_state_cb, cmd);
66 /* NS-VCs for SGSN2 */
67 nse = gprs_ns2_nse_by_nsei(nsi, cfg->nsip_sgsn2_nsei);
68 if (nse)
69 gprs_ns2_nse_foreach_nsvc(nse, &ctrl_nsvc_state_cb, cmd);
Pau Espin Pedrol1ddefb12019-08-30 19:48:34 +020070
Alexander Couzens951e1332020-09-22 13:21:46 +020071 /* NS-VCs for BSS peers */
Daniel Willmanne50550e2020-11-26 18:19:21 +010072 llist_for_each_entry(nse_peer, &cfg->nse_peers, list) {
73 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;
Pau Espin Pedrol1ddefb12019-08-30 19:48:34 +020087
88 cmd->reply = talloc_strdup(cmd, "");
89
Daniel Willmanne50550e2020-11-26 18:19:21 +010090 llist_for_each_entry(nse_peer, &cfg->nse_peers, list) {
91 struct gbproxy_peer *peer;
92 llist_for_each_entry(peer, &nse_peer->bts_peers, list) {
93 struct gprs_ra_id raid;
94 gsm48_parse_ra(&raid, peer->ra);
Pau Espin Pedrol1ddefb12019-08-30 19:48:34 +020095
Daniel Willmanne50550e2020-11-26 18:19:21 +010096 cmd->reply = talloc_asprintf_append(cmd->reply, "%u,%u,%u,%u,%u,%u,%s\n",
97 nse_peer->nsei, peer->bvci,
98 raid.mcc, raid.mnc,
99 raid.lac, raid.rac,
100 peer->blocked ? "BLOCKED" : "UNBLOCKED");
101 }
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;
113 uint32_t count = 0;
114
115 llist_for_each_entry(nse_peer, &cfg->nse_peers, list)
116 count += llist_count(&nse_peer->bts_peers);
Pau Espin Pedrol1ddefb12019-08-30 19:48:34 +0200117
118 cmd->reply = talloc_strdup(cmd, "");
Daniel Willmanne50550e2020-11-26 18:19:21 +0100119 cmd->reply = talloc_asprintf_append(cmd->reply, "%u", count);
Pau Espin Pedrol1ddefb12019-08-30 19:48:34 +0200120
121 return CTRL_CMD_REPLY;
122}
123CTRL_CMD_DEFINE_RO(num_peers, "number-of-peers");
124
125int gb_ctrl_cmds_install(void)
126{
127 int rc = 0;
128 rc |= ctrl_cmd_install(CTRL_NODE_ROOT, &cmd_nsvc_state);
129 rc |= ctrl_cmd_install(CTRL_NODE_ROOT, &cmd_gbproxy_state);
130 rc |= ctrl_cmd_install(CTRL_NODE_ROOT, &cmd_num_peers);
131
132 return rc;
133}