aboutsummaryrefslogtreecommitdiffstats
path: root/src/common/l1sap.c
diff options
context:
space:
mode:
authorHarald Welte <laforge@gnumonks.org>2019-06-02 17:36:21 +0200
committerlaforge <laforge@gnumonks.org>2019-06-13 15:37:13 +0000
commitb24ef2357032c1ed25c2f95f8ca2e7b4cd013e82 (patch)
tree1b0f8a5eda17b1636e027e60db4b771c12684f22 /src/common/l1sap.c
parent01c539284e85c5d907300e45548d497cca27217b (diff)
l1sap: Compute statistics on FN advance in PH-RTS.ind
Let's keep some statistics about the min/max/average frame number advance that we're observing above L1SAP when comparing the time in the PH-RTS.ind and the frame number we observe in PH-DATA.ind of data that was received on the uplink. The statistics are currently only shown in the VTY, but this is a precursor to using them to correctly advance the LAPDm timers in a follow-up patch. Change-Id: I8f739fdb808a614f080afbc4654641ec3df19eb2 Related: OS#2294 Related: OS#3906
Diffstat (limited to 'src/common/l1sap.c')
-rw-r--r--src/common/l1sap.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/common/l1sap.c b/src/common/l1sap.c
index 59d5b931..b730b853 100644
--- a/src/common/l1sap.c
+++ b/src/common/l1sap.c
@@ -719,6 +719,33 @@ int is_ccch_for_agch(struct gsm_bts_trx *trx, uint32_t fn) {
return l1sap_fn2ccch_block(fn) < num_agch(trx, "PH-RTS-IND");
}
+/* return the measured average of frame numbers that the RTS clock is running in advance */
+int32_t bts_get_avg_fn_advance(struct gsm_bts *bts)
+{
+ if (bts->fn_stats.avg_count == 0)
+ return 0;
+ return bts->fn_stats.avg256 / bts->fn_stats.avg_count;
+}
+
+static void l1sap_update_fnstats(struct gsm_bts *bts, uint32_t rts_fn)
+{
+ int32_t delta = (rts_fn + GSM_HYPERFRAME - bts->gsm_time.fn) % GSM_HYPERFRAME;
+
+ if (delta < bts->fn_stats.min)
+ bts->fn_stats.min = delta;
+ if (delta > bts->fn_stats.max)
+ bts->fn_stats.max = delta;
+
+ if (bts->fn_stats.avg_count > bts->fn_stats.avg_window) {
+ /* reset and start old average and new sample */
+ bts->fn_stats.avg256 = (bts->fn_stats.avg256 / bts->fn_stats.avg_count) + delta;
+ bts->fn_stats.avg_count = 2;
+ } else {
+ bts->fn_stats.avg256 += delta;
+ bts->fn_stats.avg_count++;
+ }
+}
+
/* PH-RTS-IND prim received from bts model */
static int l1sap_ph_rts_ind(struct gsm_bts_trx *trx,
struct osmo_phsap_prim *l1sap, struct ph_data_param *rts_ind)
@@ -745,6 +772,8 @@ static int l1sap_ph_rts_ind(struct gsm_bts_trx *trx,
DEBUGPGT(DL1P, &g_time, "Rx PH-RTS.ind chan_nr=%s link_id=0x%02xd\n", rsl_chan_nr_str(chan_nr), link_id);
+ l1sap_update_fnstats(trx->bts, fn);
+
/* reuse PH-RTS.ind for PH-DATA.req */
if (!msg) {
LOGPGT(DL1P, LOGL_FATAL, &g_time, "RTS without msg to be reused. Please fix!\n");