meas_feed: Use osmo_io instead of write queue

Related: OS#6170
Change-Id: Ib0570a3242e2846062e24c93cbbbbd31137acdee
This commit is contained in:
arehbein 2023-09-26 00:42:22 +02:00 committed by daniel
parent 9bb4b22152
commit ea388e1db1
4 changed files with 44 additions and 54 deletions

View File

@ -35,12 +35,12 @@ enum meas_feed_msgtype {
}; };
#define MEAS_FEED_VERSION 1 #define MEAS_FEED_VERSION 1
#define MEAS_FEED_WQUEUE_MAX_LEN_DEFAULT 100 #define MEAS_FEED_TXQUEUE_MAX_LEN_DEFAULT 100
int meas_feed_cfg_set(const char *dst_host, uint16_t dst_port); int meas_feed_cfg_set(const char *dst_host, uint16_t dst_port);
void meas_feed_scenario_set(const char *name); void meas_feed_scenario_set(const char *name);
void meas_feed_wqueue_max_length_set(unsigned int max_length); void meas_feed_txqueue_max_length_set(unsigned int max_length);
void meas_feed_cfg_get(char **host, uint16_t *port); void meas_feed_cfg_get(char **host, uint16_t *port);
const char *meas_feed_scenario_get(void); const char *meas_feed_scenario_get(void);
unsigned int meas_feed_wqueue_max_length_get(void); unsigned int meas_feed_txqueue_max_length_get(void);

View File

@ -385,7 +385,7 @@ static int config_write_net(struct vty *vty)
uint16_t meas_port; uint16_t meas_port;
char *meas_host; char *meas_host;
const char *meas_scenario; const char *meas_scenario;
unsigned int max_len = meas_feed_wqueue_max_length_get(); unsigned int max_len = meas_feed_txqueue_max_length_get();
meas_feed_cfg_get(&meas_host, &meas_port); meas_feed_cfg_get(&meas_host, &meas_port);
meas_scenario = meas_feed_scenario_get(); meas_scenario = meas_feed_scenario_get();
@ -396,7 +396,7 @@ static int config_write_net(struct vty *vty)
if (strlen(meas_scenario) > 0) if (strlen(meas_scenario) > 0)
vty_out(vty, " meas-feed scenario %s%s", vty_out(vty, " meas-feed scenario %s%s",
meas_scenario, VTY_NEWLINE); meas_scenario, VTY_NEWLINE);
if (max_len != MEAS_FEED_WQUEUE_MAX_LEN_DEFAULT) if (max_len != MEAS_FEED_TXQUEUE_MAX_LEN_DEFAULT)
vty_out(vty, " meas-feed write-queue-max-length %u%s", vty_out(vty, " meas-feed write-queue-max-length %u%s",
max_len, VTY_NEWLINE); max_len, VTY_NEWLINE);
} }
@ -2424,7 +2424,7 @@ DEFUN_ATTR(cfg_net_meas_feed_wqueue_max_len, cfg_net_meas_feed_wqueue_max_len_cm
"Maximum number of messages to be queued waiting for transmission\n", "Maximum number of messages to be queued waiting for transmission\n",
CMD_ATTR_IMMEDIATE) CMD_ATTR_IMMEDIATE)
{ {
meas_feed_wqueue_max_length_set(atoi(argv[0])); meas_feed_txqueue_max_length_set(atoi(argv[0]));
return CMD_SUCCESS; return CMD_SUCCESS;
} }

View File

@ -6,7 +6,7 @@
#include <osmocom/core/msgb.h> #include <osmocom/core/msgb.h>
#include <osmocom/core/socket.h> #include <osmocom/core/socket.h>
#include <osmocom/core/write_queue.h> #include <osmocom/core/osmo_io.h>
#include <osmocom/core/talloc.h> #include <osmocom/core/talloc.h>
#include <osmocom/core/utils.h> #include <osmocom/core/utils.h>
@ -23,17 +23,14 @@
#include <osmocom/bsc/lchan.h> #include <osmocom/bsc/lchan.h>
struct meas_feed_state { struct meas_feed_state {
struct osmo_wqueue wqueue; struct osmo_io_fd *io_fd;
unsigned int wqueue_max_len;
char scenario[31+1]; char scenario[31+1];
char *dst_host; char *dst_host;
uint16_t dst_port; uint16_t dst_port;
size_t txqueue_max;
}; };
static struct meas_feed_state g_mfs = { static struct meas_feed_state g_mfs = { .txqueue_max = MEAS_FEED_TXQUEUE_MAX_LEN_DEFAULT };
.wqueue.bfd.fd = -1,
.wqueue_max_len = MEAS_FEED_WQUEUE_MAX_LEN_DEFAULT,
};
static int process_meas_rep(struct gsm_meas_rep *mr) static int process_meas_rep(struct gsm_meas_rep *mr)
{ {
@ -41,7 +38,7 @@ static int process_meas_rep(struct gsm_meas_rep *mr)
struct meas_feed_meas *mfm; struct meas_feed_meas *mfm;
struct bsc_subscr *bsub; struct bsc_subscr *bsub;
OSMO_ASSERT(g_mfs.wqueue.bfd.fd != -1); OSMO_ASSERT(g_mfs.io_fd != NULL);
/* ignore measurements as long as we don't know who it is */ /* ignore measurements as long as we don't know who it is */
if (!mr->lchan) { if (!mr->lchan) {
@ -90,7 +87,7 @@ static int process_meas_rep(struct gsm_meas_rep *mr)
mfm->ss_nr = mr->lchan->nr; mfm->ss_nr = mr->lchan->nr;
/* and send it to the socket */ /* and send it to the socket */
if (osmo_wqueue_enqueue(&g_mfs.wqueue, msg) != 0) { if (osmo_iofd_write_msgb(g_mfs.io_fd, msg)) {
LOGP(DMEAS, LOGL_ERROR, "meas_feed %s: sending measurement report failed\n", LOGP(DMEAS, LOGL_ERROR, "meas_feed %s: sending measurement report failed\n",
gsm_lchan_name(mr->lchan)); gsm_lchan_name(mr->lchan));
msgb_free(msg); msgb_free(msg);
@ -115,63 +112,54 @@ static int meas_feed_sig_cb(unsigned int subsys, unsigned int signal,
return 0; return 0;
} }
static int feed_write_cb(struct osmo_fd *ofd, struct msgb *msg)
{
return write(ofd->fd, msgb_data(msg), msgb_length(msg));
}
static int feed_read_cb(struct osmo_fd *ofd)
{
int rc;
char buf[256];
rc = read(ofd->fd, buf, sizeof(buf));
osmo_fd_read_disable(ofd);
return rc;
}
static void meas_feed_close(void) static void meas_feed_close(void)
{ {
if (g_mfs.wqueue.bfd.fd == -1) if (g_mfs.io_fd == NULL)
return; return;
osmo_signal_unregister_handler(SS_LCHAN, meas_feed_sig_cb, NULL); osmo_signal_unregister_handler(SS_LCHAN, meas_feed_sig_cb, NULL);
osmo_wqueue_clear(&g_mfs.wqueue); osmo_iofd_close(g_mfs.io_fd);
osmo_fd_unregister(&g_mfs.wqueue.bfd); osmo_iofd_free(g_mfs.io_fd);
close(g_mfs.wqueue.bfd.fd); g_mfs.io_fd = NULL;
g_mfs.wqueue.bfd.fd = -1; }
static void meas_feed_noop_cb(struct osmo_io_fd *iofd, int res, struct msgb *msg)
{
} }
int meas_feed_cfg_set(const char *dst_host, uint16_t dst_port) int meas_feed_cfg_set(const char *dst_host, uint16_t dst_port)
{ {
int rc; int rc;
/* osmo_io code throws an error if 'write_cb' is NULL, so we set a no-op */
struct osmo_io_ops meas_feed_oio = {
.read_cb = NULL,
.write_cb = meas_feed_noop_cb,
.segmentation_cb = NULL
};
/* Already initialized */ /* Already initialized */
if (g_mfs.wqueue.bfd.fd > 0) { if (g_mfs.io_fd != NULL) {
/* No change needed, do nothing */ /* No change needed, do nothing */
if (!strcmp(dst_host, g_mfs.dst_host) && dst_port == g_mfs.dst_port) if (!strcmp(dst_host, g_mfs.dst_host) && dst_port == g_mfs.dst_port)
return 0; return 0;
meas_feed_close(); meas_feed_close();
} }
osmo_wqueue_init(&g_mfs.wqueue, g_mfs.wqueue_max_len); rc = osmo_sock_init(AF_UNSPEC, SOCK_DGRAM, IPPROTO_UDP, dst_host, dst_port, OSMO_SOCK_F_CONNECT);
g_mfs.wqueue.write_cb = feed_write_cb;
g_mfs.wqueue.read_cb = feed_read_cb;
rc = osmo_sock_init_ofd(&g_mfs.wqueue.bfd, AF_UNSPEC, SOCK_DGRAM,
IPPROTO_UDP, dst_host, dst_port,
OSMO_SOCK_F_CONNECT);
if (rc < 0) { if (rc < 0) {
g_mfs.wqueue.bfd.fd = -1; osmo_signal_unregister_handler(SS_LCHAN, meas_feed_sig_cb, NULL);
return rc; return rc;
} }
g_mfs.io_fd = osmo_iofd_setup(NULL, rc, "meas_iofd", OSMO_IO_FD_MODE_READ_WRITE, &meas_feed_oio, NULL);
if (!g_mfs.io_fd)
return -1;
osmo_iofd_set_txqueue_max_length(g_mfs.io_fd, g_mfs.txqueue_max);
if ((rc = osmo_iofd_register(g_mfs.io_fd, rc)))
return rc;
osmo_fd_read_disable(&g_mfs.wqueue.bfd);
osmo_talloc_replace_string(NULL, &g_mfs.dst_host, dst_host); osmo_talloc_replace_string(NULL, &g_mfs.dst_host, dst_host);
g_mfs.dst_port = dst_port; g_mfs.dst_port = dst_port;
osmo_signal_register_handler(SS_LCHAN, meas_feed_sig_cb, NULL); osmo_signal_register_handler(SS_LCHAN, meas_feed_sig_cb, NULL);
LOGP(DMEAS, LOGL_DEBUG, "meas_feed: started %s\n", LOGP(DMEAS, LOGL_DEBUG, "meas_feed: started %s\n",
osmo_sock_get_name2(g_mfs.wqueue.bfd.fd)); osmo_sock_get_name2(osmo_iofd_get_fd(g_mfs.io_fd)));
return 0; return 0;
} }
@ -181,16 +169,16 @@ void meas_feed_cfg_get(char **host, uint16_t *port)
*host = g_mfs.dst_host; *host = g_mfs.dst_host;
} }
void meas_feed_wqueue_max_length_set(unsigned int max_length) void meas_feed_txqueue_max_length_set(unsigned int max_length)
{ {
g_mfs.wqueue_max_len = max_length; g_mfs.txqueue_max = max_length;
if (g_mfs.wqueue.bfd.fd) if (g_mfs.io_fd)
g_mfs.wqueue.max_length = max_length; osmo_iofd_set_txqueue_max_length(g_mfs.io_fd, max_length);
} }
unsigned int meas_feed_wqueue_max_length_get(void) unsigned int meas_feed_txqueue_max_length_get(void)
{ {
return g_mfs.wqueue_max_len; return g_mfs.txqueue_max;
} }
void meas_feed_scenario_set(const char *name) void meas_feed_scenario_set(const char *name)

View File

@ -39,6 +39,7 @@
#include <osmocom/bsc/handover_fsm.h> #include <osmocom/bsc/handover_fsm.h>
#include <osmocom/bsc/smscb.h> #include <osmocom/bsc/smscb.h>
#include <osmocom/bsc/lb.h> #include <osmocom/bsc/lb.h>
#include <osmocom/bsc/meas_feed.h>
#include <osmocom/ctrl/control_cmd.h> #include <osmocom/ctrl/control_cmd.h>
#include <osmocom/ctrl/control_if.h> #include <osmocom/ctrl/control_if.h>
@ -971,6 +972,7 @@ int main(int argc, char **argv)
acc_ramp_global_init(); acc_ramp_global_init();
paging_global_init(); paging_global_init();
smscb_global_init(); smscb_global_init();
meas_feed_txqueue_max_length_set(MEAS_FEED_TXQUEUE_MAX_LEN_DEFAULT);
/* Read the config */ /* Read the config */
rc = bsc_network_configure(config_file); rc = bsc_network_configure(config_file);