fixeria has submitted this change. (
https://gerrit.osmocom.org/c/osmocom-bb/+/28678 )
Change subject: trxcon: support handling of multiple L1CTL client connections
......................................................................
trxcon: support handling of multiple L1CTL client connections
Change-Id: Id92e5b553487e4cf10ea291b487a3ef0c65d72ae
---
M src/host/trxcon/include/osmocom/bb/trxcon/l1ctl_server.h
M src/host/trxcon/include/osmocom/bb/trxcon/trxcon.h
M src/host/trxcon/src/l1ctl_server.c
M src/host/trxcon/src/trx_if.c
M src/host/trxcon/src/trxcon.c
5 files changed, 45 insertions(+), 15 deletions(-)
Approvals:
Jenkins Builder: Verified
laforge: Looks good to me, approved
pespin: Looks good to me, but someone else must approve
diff --git a/src/host/trxcon/include/osmocom/bb/trxcon/l1ctl_server.h
b/src/host/trxcon/include/osmocom/bb/trxcon/l1ctl_server.h
index f0414a1..8a7e48e 100644
--- a/src/host/trxcon/include/osmocom/bb/trxcon/l1ctl_server.h
+++ b/src/host/trxcon/include/osmocom/bb/trxcon/l1ctl_server.h
@@ -37,6 +37,8 @@
struct llist_head clients;
/* number of connected clients */
unsigned int num_clients;
+ /* used for client ID generation */
+ unsigned int next_client_id;
/* socket on which we listen for connections */
struct osmo_fd ofd;
/* server configuration */
@@ -52,6 +54,8 @@
struct osmo_wqueue wq;
/* logging context (used as prefix for messages) */
const char *log_prefix;
+ /* unique client ID */
+ unsigned int id;
/* some private data */
void *priv;
};
diff --git a/src/host/trxcon/include/osmocom/bb/trxcon/trxcon.h
b/src/host/trxcon/include/osmocom/bb/trxcon/trxcon.h
index 12ad017..da47f8b 100644
--- a/src/host/trxcon/include/osmocom/bb/trxcon/trxcon.h
+++ b/src/host/trxcon/include/osmocom/bb/trxcon/trxcon.h
@@ -21,6 +21,7 @@
struct trxcon_inst {
struct osmo_fsm_inst *fi;
+ unsigned int id;
/* Logging context for sched and l1c */
const char *log_prefix;
@@ -36,5 +37,5 @@
bool fbsb_conf_sent;
};
-struct trxcon_inst *trxcon_inst_alloc(void *ctx);
+struct trxcon_inst *trxcon_inst_alloc(void *ctx, unsigned int id);
void trxcon_inst_free(struct trxcon_inst *trxcon);
diff --git a/src/host/trxcon/src/l1ctl_server.c b/src/host/trxcon/src/l1ctl_server.c
index c5c34e9..cf98c6f 100644
--- a/src/host/trxcon/src/l1ctl_server.c
+++ b/src/host/trxcon/src/l1ctl_server.c
@@ -51,7 +51,9 @@
/* Attempt to read from socket */
rc = read(ofd->fd, &len, L1CTL_MSG_LEN_FIELD);
if (rc < L1CTL_MSG_LEN_FIELD) {
- LOGP_CLI(client, DL1D, LOGL_NOTICE, "L1CTL server has lost connection\n");
+ LOGP_CLI(client, DL1D, LOGL_NOTICE,
+ "L1CTL server has lost connection (id=%u)\n",
+ client->id);
if (rc >= 0)
rc = -EIO;
l1ctl_client_conn_close(client);
@@ -157,12 +159,13 @@
return rc;
}
- LOGP(DL1C, LOGL_NOTICE, "L1CTL server got a new connection\n");
-
llist_add_tail(&client->list, &server->clients);
+ client->id = server->next_client_id++;
client->server = server;
server->num_clients++;
+ LOGP(DL1C, LOGL_NOTICE, "L1CTL server got a new connection (id=%u)\n",
client->id);
+
if (client->server->cfg->conn_accept_cb != NULL)
client->server->cfg->conn_accept_cb(client);
@@ -194,8 +197,10 @@
void l1ctl_client_conn_close(struct l1ctl_client *client)
{
- if (client->server->cfg->conn_close_cb != NULL)
- client->server->cfg->conn_close_cb(client);
+ struct l1ctl_server *server = client->server;
+
+ if (server->cfg->conn_close_cb != NULL)
+ server->cfg->conn_close_cb(client);
/* Close connection socket */
osmo_fd_unregister(&client->wq.bfd);
@@ -208,6 +213,11 @@
client->server->num_clients--;
llist_del(&client->list);
talloc_free(client);
+
+ /* If this was the last client, reset the client IDs generator to 0.
+ * This way avoid assigning huge unreadable client IDs like 26545. */
+ if (llist_empty(&server->clients))
+ server->next_client_id = 0;
}
struct l1ctl_server *l1ctl_server_alloc(void *ctx, const struct l1ctl_server_cfg *cfg)
diff --git a/src/host/trxcon/src/trx_if.c b/src/host/trxcon/src/trx_if.c
index 46f6e7e..339173f 100644
--- a/src/host/trxcon/src/trx_if.c
+++ b/src/host/trxcon/src/trx_if.c
@@ -697,11 +697,12 @@
const char *local_host, const char *remote_host,
uint16_t base_port)
{
+ const unsigned int offset = trxcon->id * 2;
struct trx_instance *trx;
int rc;
LOGPFSML(trxcon->fi, LOGL_NOTICE, "Init transceiver interface "
- "(%s:%u)\n", remote_host, base_port);
+ "(%s:%u/%u)\n", remote_host, base_port, trxcon->id);
/* Try to allocate memory */
trx = talloc_zero(trxcon, struct trx_instance);
@@ -723,13 +724,17 @@
INIT_LLIST_HEAD(&trx->trx_ctrl_list);
/* Open sockets */
- rc = trx_udp_open(trx, &trx->trx_ofd_ctrl, local_host,
- base_port + 101, remote_host, base_port + 1, trx_ctrl_read_cb);
+ rc = trx_udp_open(trx, &trx->trx_ofd_ctrl, /* TRXC */
+ local_host, base_port + 101 + offset,
+ remote_host, base_port + 1 + offset,
+ trx_ctrl_read_cb);
if (rc < 0)
goto udp_error;
- rc = trx_udp_open(trx, &trx->trx_ofd_data, local_host,
- base_port + 102, remote_host, base_port + 2, trx_data_rx_cb);
+ rc = trx_udp_open(trx, &trx->trx_ofd_data, /* TRXD */
+ local_host, base_port + 102 + offset,
+ remote_host, base_port + 2 + offset,
+ trx_data_rx_cb);
if (rc < 0)
goto udp_error;
diff --git a/src/host/trxcon/src/trxcon.c b/src/host/trxcon/src/trxcon.c
index f0cf703..14354d1 100644
--- a/src/host/trxcon/src/trxcon.c
+++ b/src/host/trxcon/src/trxcon.c
@@ -65,6 +65,7 @@
int quit;
/* L1CTL specific */
+ unsigned int max_clients;
const char *bind_socket;
/* TRX specific */
@@ -77,6 +78,7 @@
struct gsmtap_inst *gsmtap;
const char *gsmtap_ip;
} app_data = {
+ .max_clients = 1, /* only one L1CTL client by default */
.bind_socket = "/tmp/osmocom_l2",
.trx_remote_ip = "127.0.0.1",
.trx_bind_ip = "0.0.0.0",
@@ -322,7 +324,7 @@
.event_names = trxcon_fsm_event_names,
};
-struct trxcon_inst *trxcon_inst_alloc(void *ctx)
+struct trxcon_inst *trxcon_inst_alloc(void *ctx, unsigned int id)
{
struct trxcon_inst *trxcon;
@@ -333,6 +335,9 @@
trxcon, LOGL_DEBUG, NULL);
OSMO_ASSERT(trxcon->fi != NULL);
+ osmo_fsm_inst_update_id_f(trxcon->fi, "%u", id);
+ trxcon->id = id;
+
/* Logging context to be used by both l1ctl and l1sched modules */
trxcon->log_prefix = talloc_asprintf(trxcon, "%s: ",
osmo_fsm_inst_name(trxcon->fi));
@@ -383,7 +388,7 @@
{
struct trxcon_inst *trxcon;
- trxcon = trxcon_inst_alloc(l1c);
+ trxcon = trxcon_inst_alloc(l1c, l1c->id);
if (trxcon == NULL) {
l1ctl_client_conn_close(l1c);
return;
@@ -422,6 +427,7 @@
printf(" -f --trx-advance Uplink burst scheduling advance (default 3)\n");
printf(" -s --socket Listening socket for layer23 (default
/tmp/osmocom_l2)\n");
printf(" -g --gsmtap-ip The destination IP used for GSMTAP (disabled by
default)\n");
+ printf(" -C --max-clients Maximum number of L1CTL connections (default
1)\n");
printf(" -D --daemonize Run as daemon\n");
}
@@ -441,11 +447,12 @@
{"trx-port", 1, 0, 'p'},
{"trx-advance", 1, 0, 'f'},
{"gsmtap-ip", 1, 0, 'g'},
+ {"max-clients", 1, 0, 'C'},
{"daemonize", 0, 0, 'D'},
{0, 0, 0, 0}
};
- c = getopt_long(argc, argv, "d:b:i:p:f:s:g:Dh",
+ c = getopt_long(argc, argv, "d:b:i:p:f:s:g:C:Dh",
long_options, &option_index);
if (c == -1)
break;
@@ -477,6 +484,9 @@
case 'g':
app_data.gsmtap_ip = optarg;
break;
+ case 'C':
+ app_data.max_clients = atoi(optarg);
+ break;
case 'D':
app_data.daemonize = 1;
break;
@@ -567,7 +577,7 @@
/* Start the L1CTL server */
server_cfg = (struct l1ctl_server_cfg) {
.sock_path = app_data.bind_socket,
- .num_clients_max = 1, /* only one connection for now */
+ .num_clients_max = app_data.max_clients,
.conn_read_cb = &l1ctl_rx_cb,
.conn_accept_cb = &l1ctl_conn_accept_cb,
.conn_close_cb = &l1ctl_conn_close_cb,
--
To view, visit
https://gerrit.osmocom.org/c/osmocom-bb/+/28678
To unsubscribe, or for help writing mail filters, visit
https://gerrit.osmocom.org/settings
Gerrit-Project: osmocom-bb
Gerrit-Branch: master
Gerrit-Change-Id: Id92e5b553487e4cf10ea291b487a3ef0c65d72ae
Gerrit-Change-Number: 28678
Gerrit-PatchSet: 11
Gerrit-Owner: fixeria <vyanitskiy(a)sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: dexter <pmaier(a)sysmocom.de>
Gerrit-Reviewer: fixeria <vyanitskiy(a)sysmocom.de>
Gerrit-Reviewer: laforge <laforge(a)osmocom.org>
Gerrit-Reviewer: pespin <pespin(a)sysmocom.de>
Gerrit-MessageType: merged