fixeria has submitted this change. ( https://gerrit.osmocom.org/c/osmo-trx/+/43628?usp=email )
(
2 is the latest approved patch-set. No files were changed between the latest approved patch-set and the submitted one. )Change subject: proxy: make clck_gen start Fn and period configurable ......................................................................
proxy: make clck_gen start Fn and period configurable
Change-Id: I85bc0a1e4674685c7ddcf6627d139f4b8268f7a6 Related: OS#6672 --- M proxy/include/osmocom/proxy/clck_gen.h M proxy/src/clck_gen.c M proxy/src/vty.c 3 files changed, 107 insertions(+), 5 deletions(-)
Approvals: Jenkins Builder: Verified laforge: Looks good to me, but someone else must approve pespin: Looks good to me, approved
diff --git a/proxy/include/osmocom/proxy/clck_gen.h b/proxy/include/osmocom/proxy/clck_gen.h index dae2a2d..54764a6 100644 --- a/proxy/include/osmocom/proxy/clck_gen.h +++ b/proxy/include/osmocom/proxy/clck_gen.h @@ -1,5 +1,15 @@ #pragma once
+/*! Special value for clck_gen_{get,set}_start_fn() meaning + * a random starting TDMA frame number (default). */ +#define CLCK_GEN_START_FN_RANDOM (-1) + int clck_gen_init(void);
void clck_gen_trx_list_updated(void); + +int clck_gen_set_start_fn(int fn); +int clck_gen_get_start_fn(void); + +int clck_gen_set_ind_period(unsigned int period); +unsigned int clck_gen_get_ind_period(void); diff --git a/proxy/src/clck_gen.c b/proxy/src/clck_gen.c index c485711..813530c 100644 --- a/proxy/src/clck_gen.c +++ b/proxy/src/clck_gen.c @@ -23,8 +23,10 @@ * along with this program. If not, see http://www.gnu.org/licenses/. */
+#include <errno.h> #include <unistd.h> #include <stdint.h> +#include <stdlib.h>
#include <osmocom/core/linuxlist.h> #include <osmocom/core/select.h> @@ -37,16 +39,21 @@ #include <osmocom/proxy/clck_gen.h> #include <osmocom/proxy/logging.h>
-/*! Send "IND CLOCK" every N frames (matches fake_trx.py's CLCKGen default) */ +/*! Default "IND CLOCK" period, in frames */ #define CLCK_GEN_IND_PERIOD 102
struct clck_gen { struct osmo_fd timerfd; uint32_t fn; bool running; + int start_fn; /*!< CLCK_GEN_START_FN_RANDOM, or a fixed FN */ + uint32_t ind_period; /*!< send "IND CLOCK" every N frames */ };
-static struct clck_gen g_clck_gen; +static struct clck_gen g_clck_gen = { + .start_fn = CLCK_GEN_START_FN_RANDOM, + .ind_period = CLCK_GEN_IND_PERIOD, +};
static int clck_gen_timer_cb(struct osmo_fd *ofd, unsigned int what) { @@ -59,7 +66,7 @@ while (expire_count-- > 0) { const struct proxy_trx *trx;
- if (gen->fn % CLCK_GEN_IND_PERIOD == 0) { + if (gen->fn % gen->ind_period == 0) { llist_for_each_entry(trx, &g_proxy_ctx->trx_list, list) { if (!trx->powered) continue; @@ -87,14 +94,19 @@ if (gen->running) return;
- gen->fn = 0; + if (gen->start_fn == CLCK_GEN_START_FN_RANDOM) + gen->fn = rand() % GSM_TDMA_HYPERFRAME; + else + gen->fn = (uint32_t)gen->start_fn; + if (osmo_timerfd_schedule(&gen->timerfd, &first, &interval) < 0) { LOGP(DTRXC, LOGL_ERROR, "Failed to start the TDMA clock generator\n"); return; }
gen->running = true; - LOGP(DTRXC, LOGL_NOTICE, "TDMA clock generator started\n"); + LOGP(DTRXC, LOGL_NOTICE, "TDMA clock generator started (fn=%u, period=%u)\n", + gen->fn, gen->ind_period); }
static void clck_gen_stop(struct clck_gen *gen) @@ -133,3 +145,40 @@ &clck_gen_timer_cb, &g_clck_gen); } + +/*! Set the frame number the clock generator starts counting from the next + * time it (re)starts: either a fixed FN, or CLCK_GEN_START_FN_RANDOM to + * pick a random one (default). Returns 0 on success, -EINVAL if fn is + * neither CLCK_GEN_START_FN_RANDOM nor a valid FN. */ +int clck_gen_set_start_fn(int fn) +{ + if (fn < CLCK_GEN_START_FN_RANDOM || fn >= GSM_TDMA_HYPERFRAME) + return -EINVAL; + + g_clck_gen.start_fn = fn; + return 0; +} + +/*! Get the currently configured starting frame number, or + * CLCK_GEN_START_FN_RANDOM if set to pick a random one. */ +int clck_gen_get_start_fn(void) +{ + return g_clck_gen.start_fn; +} + +/*! Set how many frames apart "IND CLOCK" is sent (default: 102). Returns 0 + * on success, -EINVAL if period is 0 or exceeds the TDMA hyperframe length. */ +int clck_gen_set_ind_period(unsigned int period) +{ + if (period == 0 || period > GSM_TDMA_HYPERFRAME) + return -EINVAL; + + g_clck_gen.ind_period = period; + return 0; +} + +/*! Get the currently configured "IND CLOCK" period, in frames. */ +unsigned int clck_gen_get_ind_period(void) +{ + return g_clck_gen.ind_period; +} diff --git a/proxy/src/vty.c b/proxy/src/vty.c index 7b863c4..ab53147 100644 --- a/proxy/src/vty.c +++ b/proxy/src/vty.c @@ -42,6 +42,7 @@ #include <osmocom/proxy/vty.h> #include <osmocom/proxy/trx.h> #include <osmocom/proxy/path_sim.h> +#include <osmocom/proxy/clck_gen.h>
extern void *g_talloc_ctx;
@@ -144,6 +145,41 @@ return CMD_SUCCESS; }
+DEFUN(cfg_proxy_clck_gen_start_fn, + cfg_proxy_clck_gen_start_fn_cmd, + "clck-gen start-fn (random|<0-2715647>)", + "Configure the shared TDMA clock generator\n" + "Set the frame number the clock generator starts counting from\n" + "Start from a random frame number every time it (re)starts (default)\n" + "Start from this fixed frame number\n") +{ + int fn = !strcmp(argv[0], "random") ? CLCK_GEN_START_FN_RANDOM : atoi(argv[0]); + + if (clck_gen_set_start_fn(fn) < 0) { + vty_out(vty, "%% Invalid starting frame number: %d%s", fn, VTY_NEWLINE); + return CMD_WARNING; + } + + return CMD_SUCCESS; +} + +DEFUN(cfg_proxy_clck_gen_ind_period, + cfg_proxy_clck_gen_ind_period_cmd, + "clck-gen ind-period <1-2715648>", + "Configure the shared TDMA clock generator\n" + "Set how many frames apart "IND CLOCK" is sent (default: 102)\n" + "Period in frames\n") +{ + unsigned int period = atoi(argv[0]); + + if (clck_gen_set_ind_period(period) < 0) { + vty_out(vty, "%% Invalid IND CLOCK period: %u%s", period, VTY_NEWLINE); + return CMD_WARNING; + } + + return CMD_SUCCESS; +} + DEFUN(cfg_proxy_ep, cfg_proxy_ep_cmd, "ep NAME", @@ -287,6 +323,11 @@ 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); + if (clck_gen_get_start_fn() == CLCK_GEN_START_FN_RANDOM) + vty_out(vty, " clck-gen start-fn random%s", VTY_NEWLINE); + else + vty_out(vty, " clck-gen start-fn %d%s", clck_gen_get_start_fn(), VTY_NEWLINE); + vty_out(vty, " clck-gen ind-period %u%s", clck_gen_get_ind_period(), 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); @@ -398,6 +439,8 @@ 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_clck_gen_start_fn_cmd); + install_element(PROXY_NODE, &cfg_proxy_clck_gen_ind_period_cmd); install_element(PROXY_NODE, &cfg_proxy_ep_cmd); install_element(PROXY_NODE, &cfg_no_proxy_ep_cmd);