fixeria has submitted this change. ( https://gerrit.osmocom.org/c/osmo-trx/+/43608?usp=email )
(
3 is the latest approved patch-set. No files were changed between the latest approved patch-set and the submitted one. )Change subject: proxy: make path_sim values configurable via VTY ......................................................................
proxy: make path_sim values configurable via VTY
Move the RF path loss and default reported ToA/CI for forwarded bursts ('path-loss'/'nominal-toa256'/'nominal-ci' under 'proxy'), and each endpoint's nominal Tx power ('tx-power' under 'ep'), out of path_sim.c's compile-time constants and into new VTY commands.
The global values are held in a new opaque struct path_sim_cfg, talloc-allocated by path_sim_cfg_alloc() and exposed only through path_sim_cfg_{get,set}_*() accessors, keeping struct proxy_ctx down to a single pointer instead of exposing path_sim internals. tx_power is per-endpoint and lives directly on struct proxy_trx. Both are applied when a channel's path_sim_state is (re)initialized.
Change-Id: I969e9df1ab394e631da3da9b3044fab1446db40e Related: OS#6672 --- M proxy/include/osmocom/proxy/path_sim.h M proxy/include/osmocom/proxy/proxy.h M proxy/include/osmocom/proxy/trx.h M proxy/src/burst_fwd.c M proxy/src/ctrl_cmd.c M proxy/src/path_sim.c M proxy/src/proxy.c M proxy/src/trx.c M proxy/src/vty.c 9 files changed, 194 insertions(+), 33 deletions(-)
Approvals: Jenkins Builder: Verified pespin: Looks good to me, approved laforge: Looks good to me, but someone else must approve
diff --git a/proxy/include/osmocom/proxy/path_sim.h b/proxy/include/osmocom/proxy/path_sim.h index c263eea..58bd9bb 100644 --- a/proxy/include/osmocom/proxy/path_sim.h +++ b/proxy/include/osmocom/proxy/path_sim.h @@ -5,6 +5,7 @@ struct proxy_trx_chan; struct osmo_trxd_burst_ind; struct osmo_trxd_burst_req; +struct path_sim_cfg;
#define PATH_SIM_F_FAKE_RSSI (1 << 0) /*!< use rssi instead of the path-loss formula */
@@ -25,9 +26,24 @@ unsigned int burst_drop_period; /*!< drop if (fn % period) == 0 */ };
-void path_sim_state_reset(struct path_sim_state *ps); +void path_sim_state_reset(struct path_sim_state *ps, int tx_power, int toa256, int ci); void path_sim_apply(struct osmo_trxd_burst_ind *bi, struct proxy_trx_chan *dst, const struct osmo_trxd_burst_req *br, - const struct proxy_trx_chan *src); -int path_sim_measure(uint32_t freq_hz, int rssi_noise); + const struct proxy_trx_chan *src, + const struct path_sim_cfg *cfg); +int path_sim_measure(uint32_t freq_hz, const struct path_sim_cfg *cfg); + +struct path_sim_cfg *path_sim_cfg_alloc(void *talloc_ctx); + +void path_sim_cfg_set_noise_dbm(struct path_sim_cfg *cfg, int noise_dbm); +int path_sim_cfg_get_noise_dbm(const struct path_sim_cfg *cfg); + +void path_sim_cfg_set_path_loss_db(struct path_sim_cfg *cfg, int path_loss_db); +int path_sim_cfg_get_path_loss_db(const struct path_sim_cfg *cfg); + +void path_sim_cfg_set_nom_toa256(struct path_sim_cfg *cfg, int nom_toa256); +int path_sim_cfg_get_nom_toa256(const struct path_sim_cfg *cfg); + +void path_sim_cfg_set_nom_ci_cb(struct path_sim_cfg *cfg, int nom_ci_cb); +int path_sim_cfg_get_nom_ci_cb(const struct path_sim_cfg *cfg); diff --git a/proxy/include/osmocom/proxy/proxy.h b/proxy/include/osmocom/proxy/proxy.h index 2d17ce9..30b9316 100644 --- a/proxy/include/osmocom/proxy/proxy.h +++ b/proxy/include/osmocom/proxy/proxy.h @@ -13,12 +13,11 @@ #define PROXY_DEFAULT_MS_NAME "ms" #define PROXY_DEFAULT_MS_PORT 6700
-/*! RSSI (dBm) reported by MEASURE for a frequency with no Tx found on it */ -#define PROXY_DEFAULT_PM_RSSI_NOISE -110 +struct path_sim_cfg;
struct proxy_ctx { char *bind_addr; - int path_sim_noise_dbm; /*!< dBm, MEASURE result for frequencies with no Tx found */ + struct path_sim_cfg *path_sim; /*!< RF path simulation config (path_sim.c) */ struct llist_head trx_list; /*!< struct proxy_trx::list */ };
diff --git a/proxy/include/osmocom/proxy/trx.h b/proxy/include/osmocom/proxy/trx.h index f91acbf..4f56a24 100644 --- a/proxy/include/osmocom/proxy/trx.h +++ b/proxy/include/osmocom/proxy/trx.h @@ -11,6 +11,9 @@ struct osmo_trx_ep; struct proxy_ctx;
+/*! dBm, nominal Tx power (per endpoint) */ +#define PROXY_TRX_DEFAULT_TX_POWER 50 + /*! Per-channel state: each channel is conceptually its own (child) * transceiver with an independent Rx/Tx frequency, sharing the endpoint's * power state and clock. */ @@ -27,6 +30,7 @@ char *name; struct osmo_trx_ep *ep; bool powered; /*!< POWERON/POWEROFF applies to all channels at once */ + int tx_power; /*!< dBm, nominal Tx power (path_sim_state::tx_power) */ unsigned int num_chans; /*!< mirrors osmo_trx_ep_get_num_chans(ep) */ struct proxy_trx_chan *chans; /*!< array of num_chans entries, allocated on open */ }; diff --git a/proxy/src/burst_fwd.c b/proxy/src/burst_fwd.c index 1254e02..2166714 100644 --- a/proxy/src/burst_fwd.c +++ b/proxy/src/burst_fwd.c @@ -59,7 +59,8 @@
osmo_ubit2sbit(bi.burst, br->burst, br->burst_len); path_sim_apply(&bi, &dst->chans[dst_chan], - br, &src->chans[src_chan]); + br, &src->chans[src_chan], + g_proxy_ctx->path_sim);
osmo_trx_ep_send_burst_ind(dst->ep, dst_chan, &bi); } diff --git a/proxy/src/ctrl_cmd.c b/proxy/src/ctrl_cmd.c index 9a86bb1..ceaed21 100644 --- a/proxy/src/ctrl_cmd.c +++ b/proxy/src/ctrl_cmd.c @@ -289,7 +289,7 @@ return; }
- rssi = path_sim_measure(freq_khz * 1000, g_proxy_ctx->path_sim_noise_dbm); + rssi = path_sim_measure(freq_khz * 1000, g_proxy_ctx->path_sim); snprintf(rsp->params, sizeof(rsp->params), "%d %d", freq_khz, rssi); }
diff --git a/proxy/src/path_sim.c b/proxy/src/path_sim.c index d51c20a..260cce2 100644 --- a/proxy/src/path_sim.c +++ b/proxy/src/path_sim.c @@ -25,35 +25,103 @@
#include <stdlib.h>
+#include <osmocom/core/talloc.h> + #include <osmocom/trx/trxd.h>
#include <osmocom/proxy/proxy.h> #include <osmocom/proxy/trx.h> #include <osmocom/proxy/path_sim.h>
-#define PATH_SIM_NOMINAL_TX_POWER_DEFAULT 50 /* dBm */ -#define PATH_SIM_TX_ATT_DEFAULT 0 /* dB */ -#define PATH_SIM_PATH_LOSS_DEFAULT 110 /* dB */ -#define PATH_SIM_CI_DEFAULT 90 /* cB */ +/* Defaults for struct path_sim_cfg */ +#define PATH_SIM_CFG_DEFAULT_NOISE_DBM -110 +#define PATH_SIM_CFG_DEFAULT_PATH_LOSS_DB 110 +#define PATH_SIM_CFG_DEFAULT_TOA256 0 +#define PATH_SIM_CFG_DEFAULT_CI_CB 90
/* Values reported for NOPE.ind (burst dropped / RF muted) */ #define PATH_SIM_TOA256_NOISE_DEFAULT 0 #define PATH_SIM_RSSI_NOISE_DEFAULT -110 #define PATH_SIM_CI_NOISE_DEFAULT -30
-/*! Reset a channel's RF path simulation state to nominal defaults. */ -void path_sim_state_reset(struct path_sim_state *ps) +/*! Global RF path simulation configuration (see path_sim.h). */ +struct path_sim_cfg { + int noise_dbm; /*!< dBm, MEASURE result for frequencies with no Tx found */ + int path_loss_db; /*!< dB, RF path loss used by the RSSI formula */ + int nom_toa256; /*!< default reported ToA for BURST.ind, 1/256 symbol periods */ + int nom_ci_cb; /*!< default reported C/I for BURST.ind, in cB */ +}; + +/*! Global RF path simulation configuration. Opaque; use the accessors below. */ +struct path_sim_cfg *path_sim_cfg_alloc(void *talloc_ctx) +{ + struct path_sim_cfg *cfg; + + cfg = talloc_zero(talloc_ctx, struct path_sim_cfg); + if (cfg == NULL) + return NULL; + + cfg->noise_dbm = PATH_SIM_CFG_DEFAULT_NOISE_DBM; + cfg->path_loss_db = PATH_SIM_CFG_DEFAULT_PATH_LOSS_DB; + cfg->nom_toa256 = PATH_SIM_CFG_DEFAULT_TOA256; + cfg->nom_ci_cb = PATH_SIM_CFG_DEFAULT_CI_CB; + + return cfg; +} + +void path_sim_cfg_set_noise_dbm(struct path_sim_cfg *cfg, int noise_dbm) +{ + cfg->noise_dbm = noise_dbm; +} + +int path_sim_cfg_get_noise_dbm(const struct path_sim_cfg *cfg) +{ + return cfg->noise_dbm; +} + +void path_sim_cfg_set_path_loss_db(struct path_sim_cfg *cfg, int path_loss_db) +{ + cfg->path_loss_db = path_loss_db; +} + +int path_sim_cfg_get_path_loss_db(const struct path_sim_cfg *cfg) +{ + return cfg->path_loss_db; +} + +void path_sim_cfg_set_nom_toa256(struct path_sim_cfg *cfg, int nom_toa256) +{ + cfg->nom_toa256 = nom_toa256; +} + +int path_sim_cfg_get_nom_toa256(const struct path_sim_cfg *cfg) +{ + return cfg->nom_toa256; +} + +void path_sim_cfg_set_nom_ci_cb(struct path_sim_cfg *cfg, int nom_ci_cb) +{ + cfg->nom_ci_cb = nom_ci_cb; +} + +int path_sim_cfg_get_nom_ci_cb(const struct path_sim_cfg *cfg) +{ + return cfg->nom_ci_cb; +} + +/*! Reset a channel's RF path simulation state to the given nominal Tx power, + * ToA and C/I defaults. */ +void path_sim_state_reset(struct path_sim_state *ps, int tx_power, int toa256, int ci) { ps->flags = 0; - ps->tx_power = PATH_SIM_NOMINAL_TX_POWER_DEFAULT; - ps->tx_att = PATH_SIM_TX_ATT_DEFAULT; + ps->tx_power = tx_power; + ps->tx_att = 0; ps->ta = 0; - ps->toa256 = 0; + ps->toa256 = toa256; ps->toa256_jitter = 0; - ps->rssi = PATH_SIM_NOMINAL_TX_POWER_DEFAULT - - PATH_SIM_TX_ATT_DEFAULT - PATH_SIM_PATH_LOSS_DEFAULT; + ps->rssi = 0; /* unused unless PATH_SIM_F_FAKE_RSSI is set */ ps->rssi_jitter = 0; - ps->ci = PATH_SIM_CI_DEFAULT; + ps->ci = ci; ps->ci_jitter = 0; ps->burst_drop_amount = 0; ps->burst_drop_period = 1; @@ -88,7 +156,8 @@ void path_sim_apply(struct osmo_trxd_burst_ind *bi, struct proxy_trx_chan *dst, const struct osmo_trxd_burst_req *br, - const struct proxy_trx_chan *src) + const struct proxy_trx_chan *src, + const struct path_sim_cfg *cfg) { bool nope = bi->flags & OSMO_TRXD_F_NOPE_IND;
@@ -114,26 +183,27 @@ bi->rssi = dst->path_sim.rssi + path_sim_jitter(dst->path_sim.rssi_jitter); } else { int tx_power = src->path_sim.tx_power - src->path_sim.tx_att; - bi->rssi = tx_power - (int)br->att - PATH_SIM_PATH_LOSS_DEFAULT; + bi->rssi = tx_power - (int)br->att - cfg->path_loss_db; }
bi->ci_cb = dst->path_sim.ci + path_sim_jitter(dst->path_sim.ci_jitter); bi->flags |= OSMO_TRXD_F_CI_CB; }
-static int path_sim_measure_rssi(const struct proxy_trx_chan *tx) +static int path_sim_measure_rssi(const struct proxy_trx_chan *tx, const struct path_sim_cfg *cfg) { if (tx->path_sim.flags & PATH_SIM_F_FAKE_RSSI) return tx->path_sim.rssi;
- return (tx->path_sim.tx_power - tx->path_sim.tx_att) - PATH_SIM_PATH_LOSS_DEFAULT; + return (tx->path_sim.tx_power - tx->path_sim.tx_att) - cfg->path_loss_db; }
/*! Emulate a power measurement (MEASURE CTRL command) on a given Tx * frequency: if some powered-on channel is currently transmitting on it, * return the RSSI it would be measured at (same path-loss formula, or - * FAKE_RSSI override, as path_sim_apply()); otherwise return rssi_noise. */ -int path_sim_measure(uint32_t freq_hz, int rssi_noise) + * FAKE_RSSI override, as path_sim_apply()); otherwise return the configured + * noise floor. */ +int path_sim_measure(uint32_t freq_hz, const struct path_sim_cfg *cfg) { struct proxy_trx *trx;
@@ -145,9 +215,9 @@
for (chan = 0; chan < trx->num_chans; chan++) { if (trx->chans[chan].tx_freq == freq_hz) - return path_sim_measure_rssi(&trx->chans[chan]); + return path_sim_measure_rssi(&trx->chans[chan], cfg); } }
- return rssi_noise; + return cfg->noise_dbm; } diff --git a/proxy/src/proxy.c b/proxy/src/proxy.c index 4495909..db7258b 100644 --- a/proxy/src/proxy.c +++ b/proxy/src/proxy.c @@ -32,6 +32,7 @@
#include <osmocom/proxy/proxy.h> #include <osmocom/proxy/trx.h> +#include <osmocom/proxy/path_sim.h> #include <osmocom/proxy/logging.h>
struct proxy_ctx *g_proxy_ctx = NULL; @@ -45,7 +46,11 @@ return NULL;
proxy->bind_addr = talloc_strdup(proxy, PROXY_DEFAULT_BIND_ADDR); - proxy->path_sim_noise_dbm = PROXY_DEFAULT_PM_RSSI_NOISE; + proxy->path_sim = path_sim_cfg_alloc(proxy); + if (proxy->path_sim == NULL) { + talloc_free(proxy); + return NULL; + } INIT_LLIST_HEAD(&proxy->trx_list);
return proxy; diff --git a/proxy/src/trx.c b/proxy/src/trx.c index 7087d6a..eb42ebe 100644 --- a/proxy/src/trx.c +++ b/proxy/src/trx.c @@ -48,6 +48,7 @@ return NULL;
trx->name = talloc_strdup(trx, name); + trx->tx_power = PROXY_TRX_DEFAULT_TX_POWER; trx->ep = osmo_trx_ep_alloc(trx, num_chans); if (trx->ep == NULL) { talloc_free(trx); @@ -127,8 +128,11 @@ if (rc == 0) { /* first successful open: num_chans is now fixed */ trx->chans = talloc_zero_array(trx, struct proxy_trx_chan, trx->num_chans); OSMO_ASSERT(trx->chans != NULL); - for (unsigned int i = 0; i < trx->num_chans; i++) - path_sim_state_reset(&trx->chans[i].path_sim); + for (unsigned int i = 0; i < trx->num_chans; i++) { + path_sim_state_reset(&trx->chans[i].path_sim, trx->tx_power, + path_sim_cfg_get_nom_toa256(g_proxy_ctx->path_sim), + path_sim_cfg_get_nom_ci_cb(g_proxy_ctx->path_sim)); + } }
return 0; diff --git a/proxy/src/vty.c b/proxy/src/vty.c index aa8288a..7b863c4 100644 --- a/proxy/src/vty.c +++ b/proxy/src/vty.c @@ -41,6 +41,7 @@ #include <osmocom/proxy/proxy.h> #include <osmocom/proxy/vty.h> #include <osmocom/proxy/trx.h> +#include <osmocom/proxy/path_sim.h>
extern void *g_talloc_ctx;
@@ -99,7 +100,46 @@ { struct proxy_ctx *proxy = vty->index;
- proxy->path_sim_noise_dbm = atoi(argv[0]); + path_sim_cfg_set_noise_dbm(proxy->path_sim, atoi(argv[0])); + + return CMD_SUCCESS; +} + +DEFUN(cfg_proxy_path_loss, + cfg_proxy_path_loss_cmd, + "path-loss <0-200>", + "Set the simulated RF path loss used to compute the reported RSSI\n" + "Path loss in dB\n") +{ + struct proxy_ctx *proxy = vty->index; + + path_sim_cfg_set_path_loss_db(proxy->path_sim, atoi(argv[0])); + + return CMD_SUCCESS; +} + +DEFUN(cfg_proxy_nom_toa256, + cfg_proxy_nom_toa256_cmd, + "nominal-toa256 <-32768-32767>", + "Set the default reported ToA for a forwarded burst\n" + "ToA in 1/256 of a symbol period\n") +{ + struct proxy_ctx *proxy = vty->index; + + path_sim_cfg_set_nom_toa256(proxy->path_sim, atoi(argv[0])); + + return CMD_SUCCESS; +} + +DEFUN(cfg_proxy_nom_ci, + cfg_proxy_nom_ci_cmd, + "nominal-ci <-1280-1280>", + "Set the default reported C/I for a forwarded burst\n" + "C/I in centiBels\n") +{ + struct proxy_ctx *proxy = vty->index; + + path_sim_cfg_set_nom_ci_cb(proxy->path_sim, atoi(argv[0]));
return CMD_SUCCESS; } @@ -202,6 +242,20 @@ return CMD_SUCCESS; }
+DEFUN(cfg_ep_tx_power, + cfg_ep_tx_power_cmd, + "tx-power <-100-100>", + "Set the nominal Tx power reported by NOMTXPOWER and used to compute " + "the RSSI of bursts sent from this endpoint\n" + "Tx power in dBm\n") +{ + struct proxy_trx *trx = vty->index; + + trx->tx_power = atoi(argv[0]); + + return CMD_SUCCESS; +} + DEFUN(cfg_ep_clock_socket, cfg_ep_clock_socket_cmd, "clock-socket", @@ -233,7 +287,10 @@ vty_out(vty, "proxy%s", VTY_NEWLINE); if (g_proxy_ctx->bind_addr) vty_out(vty, " bind-addr %s%s", g_proxy_ctx->bind_addr, VTY_NEWLINE); - vty_out(vty, " pm-rssi-noise %d%s", g_proxy_ctx->path_sim_noise_dbm, VTY_NEWLINE); + vty_out(vty, " pm-rssi-noise %d%s", path_sim_cfg_get_noise_dbm(g_proxy_ctx->path_sim), VTY_NEWLINE); + vty_out(vty, " path-loss %d%s", path_sim_cfg_get_path_loss_db(g_proxy_ctx->path_sim), VTY_NEWLINE); + vty_out(vty, " nominal-toa256 %d%s", path_sim_cfg_get_nom_toa256(g_proxy_ctx->path_sim), VTY_NEWLINE); + vty_out(vty, " nominal-ci %d%s", path_sim_cfg_get_nom_ci_cb(g_proxy_ctx->path_sim), VTY_NEWLINE);
llist_for_each_entry(trx, &g_proxy_ctx->trx_list, list) { const char *raddr = osmo_trx_ep_get_raddr(trx->ep); @@ -246,6 +303,7 @@ vty_out(vty, " bind-addr %s%s", laddr, VTY_NEWLINE); vty_out(vty, " base-port %u%s", osmo_trx_ep_get_base_port(trx->ep), VTY_NEWLINE); vty_out(vty, " num-chans %u%s", trx->num_chans, VTY_NEWLINE); + vty_out(vty, " tx-power %d%s", trx->tx_power, VTY_NEWLINE);
if (!osmo_trx_ep_get_clock_socket(trx->ep)) vty_out(vty, " no clock-socket%s", VTY_NEWLINE); @@ -337,6 +395,9 @@ install_node(&proxy_node, config_write_proxy); install_element(PROXY_NODE, &cfg_proxy_bind_addr_cmd); install_element(PROXY_NODE, &cfg_proxy_pm_rssi_noise_cmd); + install_element(PROXY_NODE, &cfg_proxy_path_loss_cmd); + install_element(PROXY_NODE, &cfg_proxy_nom_toa256_cmd); + install_element(PROXY_NODE, &cfg_proxy_nom_ci_cmd); install_element(PROXY_NODE, &cfg_proxy_ep_cmd); install_element(PROXY_NODE, &cfg_no_proxy_ep_cmd);
@@ -345,6 +406,7 @@ install_element(EP_NODE, &cfg_ep_bind_addr_cmd); install_element(EP_NODE, &cfg_ep_base_port_cmd); install_element(EP_NODE, &cfg_ep_num_chans_cmd); + install_element(EP_NODE, &cfg_ep_tx_power_cmd); install_element(EP_NODE, &cfg_ep_clock_socket_cmd); install_element(EP_NODE, &cfg_ep_no_clock_socket_cmd);