Hello Harald Welte, Jenkins Builder,

I'd like you to reexamine a change.  Please visit

    https://gerrit.osmocom.org/6324

to look at the new patch set (#4).

Add support for Access Control Class ramping.

Access Control Class (ACC) ramping is used to slowly make the cell
available to an increasing number of MS. This avoids overload at
startup time in cases where a lot of MS would discover the new
cell and try to connect to it all at once.

Ramping behaviour can be configured with new VTY commands:

  access-control-class-ramping enabled (0|1)
  access-control-class-ramping step-interval (<30,600>|dynamic)
  access-control-class-ramping step-size (<1,10>

(The minimum and maximum values for these parameters are hard-coded,
but could be changed if they are found to be inadequate.)

The VTY command 'show bts' has been extended to display the
current ACC ramping configuration.

By default, ACC ramping is disabled.

When enabled, the default behaviour is to enable one ACC per
ramping stepm with a 'dyanmic' step interval. This means the
ramping interval (time between steps) is scaled to the channel
load average of the BTS, i.e. the number of used vs. available
channels measured over a certain amount of time.

Below is an example of debug log output with ACC ramping enabled,
while many 'mobile' programs are concurrently trying to connect
to the network via an osmo-bts-virtual BTS. Initially, all ACCs
are barred, and then only one class is allowed. Then the current
BTS channel load average is consulted for scheduling the next
ramping step. While the channel load average is low, ramping
proceeds faster, and while it is is high, ramping proceeds slower:

(bts=0) ACC RAMP: barring Access Control Class 0
(bts=0) ACC RAMP: barring Access Control Class 1
(bts=0) ACC RAMP: barring Access Control Class 2
(bts=0) ACC RAMP: barring Access Control Class 3
(bts=0) ACC RAMP: barring Access Control Class 4
(bts=0) ACC RAMP: barring Access Control Class 5
(bts=0) ACC RAMP: barring Access Control Class 6
(bts=0) ACC RAMP: barring Access Control Class 7
(bts=0) ACC RAMP: barring Access Control Class 8
(bts=0) ACC RAMP: barring Access Control Class 9
(bts=0) ACC RAMP: allowing Access Control Class 0
(bts=0) ACC RAMP: step interval set to 30 seconds based on 0% channel load 
average
(bts=0) ACC RAMP: allowing Access Control Class 1
(bts=0) ACC RAMP: step interval set to 354 seconds based on 59% channel load 
average
(bts=0) ACC RAMP: allowing Access Control Class 2
(bts=0) ACC RAMP: step interval set to 30 seconds based on 0% channel load 
average
(bts=0) ACC RAMP: allowing Access Control Class 3
(bts=0) ACC RAMP: step interval set to 30 seconds based on 0% channel load 
average

Change-Id: I0a5ac3a08f992f326435944f17e0a9171911afb0
Related: OS#2591
---
M include/osmocom/bsc/Makefile.am
A include/osmocom/bsc/acc_ramp.h
M include/osmocom/bsc/gsm_data_shared.h
M src/libbsc/Makefile.am
A src/libbsc/acc_ramp.c
M src/libbsc/bsc_init.c
M src/libbsc/bsc_vty.c
M src/libbsc/chan_alloc.c
M src/libbsc/system_information.c
M src/libcommon/gsm_data_shared.c
10 files changed, 488 insertions(+), 3 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/osmo-bsc refs/changes/24/6324/4

diff --git a/include/osmocom/bsc/Makefile.am b/include/osmocom/bsc/Makefile.am
index 699aeb3..7919e8d 100644
--- a/include/osmocom/bsc/Makefile.am
+++ b/include/osmocom/bsc/Makefile.am
@@ -3,6 +3,7 @@
        abis_nm.h \
        abis_om2000.h \
        abis_rsl.h \
+       acc_ramp.h \
        arfcn_range_encode.h \
        bsc_msc.h \
        bsc_msg_filter.h \
diff --git a/include/osmocom/bsc/acc_ramp.h b/include/osmocom/bsc/acc_ramp.h
new file mode 100644
index 0000000..003f6cd
--- /dev/null
+++ b/include/osmocom/bsc/acc_ramp.h
@@ -0,0 +1,138 @@
+/* (C) 2018 by sysmocom s.f.m.c. GmbH <i...@sysmocom.de>
+ *
+ * Author: Stefan Sperling <ssperl...@sysmocom.de>
+ *
+ * All Rights Reserved
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#pragma once
+
+#include <stdbool.h>
+#include <stdint.h>
+
+#include <osmocom/core/timer.h>
+#include <osmocom/gsm/protocol/gsm_04_08.h>
+
+/*
+ * Access control class (ACC) ramping is used to slowly make the cell 
available to
+ * an increasing number of MS. This avoids overload at startup time in cases 
where
+ * a lot of MS would discover the new cell and try to connect to it all at 
once.
+ */
+
+#define ACC_RAMP_STEP_SIZE_MIN 1 /* allow at most 1 new ACC per ramp step */
+#define ACC_RAMP_STEP_SIZE_DEFAULT ACC_RAMP_STEP_SIZE_MIN
+#define ACC_RAMP_STEP_SIZE_MAX 10 /* allow all ACC in one step (effectively 
disables ramping) */
+
+#define ACC_RAMP_STEP_INTERVAL_MIN 30  /* 30 seconds */
+#define ACC_RAMP_STEP_INTERVAL_MAX 600 /* 10 minutes */
+
+struct acc_ramp {
+       struct gsm_bts *bts; /* backpointer to BTS using this ACC ramp */
+
+       /*
+        * Bitmasks which keep track of access control classes that are 
currently denied
+        * access. These masks should be used to modulate bits from octets 2 
and 3 of
+        * the RACH Control Parameters (see 3GPP 44.018 10.5.2.29).
+        * While a bit in these masks is set, the corresponding ACC is barred.
+        * Note that t2 contains bits for classes 11-15 which should always be 
allowed,
+        * and a bit which denies emergency calls for all ACCs from 0-9 
inclusive.
+        * Ramping is only concerned with those bits which control access for 
ACCs 0-9.
+        */
+       uint8_t barred_t2;
+       uint8_t barred_t3;
+
+       /*
+        * This controls the maximum number of ACCs to allow per ramping step 
(1 - 10).
+        * The compile-time default value is ACC_RAMP_STEP_SIZE_DEFAULT.
+        * This value can be changed by VTY configuration.
+        * A value of ACC_RAMP_STEP_SIZE_MAX effectively disables ramping.
+        */
+       unsigned int step_size;
+
+       /*
+        * Ramping step interval in seconds.
+        * This value depends on the current BTS channel load average, unless
+        * it has been overriden by VTY configuration.
+        */
+       unsigned int step_interval_sec;
+       bool step_interval_is_fixed;
+       struct osmo_timer_list step_timer;
+};
+
+/*
+ * Initialize an acc_ramp data structure.
+ * Storage for this structure must be provided by the caller.
+ *
+ * The BTS which uses this ACC ramp data structure must be provided as well.
+ *
+ * If 'bts->acc_ramping_enabled' is true, all ACCs are denied by default.
+ * A subsequent call to acc_ramp_start() will begin the ramping process.
+ *
+ * If 'bts->acc_ramping_enabled' is false, all ACCs will be allowed by default,
+ * and there is no need to do anything else.
+ */
+void acc_ramp_init(struct acc_ramp *acc_ramp, struct gsm_bts *bts);
+
+/* Change the ramping step size. Returns negative on error (step_size out of 
range), else zero. */
+int acc_ramp_set_step_size(struct acc_ramp *acc_ramp, unsigned int step_size);
+
+/*
+ * Change the ramping step interval to a fixed value. Unless this function is 
called,
+ * the interval is automatically scaled to the BTS channel load average.
+ */
+int acc_ramp_set_step_interval(struct acc_ramp *acc_ramp, unsigned int 
step_interval);
+
+/*
+ * Clear a previously set fixed ramping step interval, so that the interval
+ * is again automatically scaled to the BTS channel load average.
+ */
+void acc_ramp_set_step_interval_dynamic(struct acc_ramp *acc_ramp);
+
+/*
+ * Begin the ramping process. Perform at least one ramping step to allow 
'step_size' ACCs.
+ * If 'step_size' is ACC_RAMP_STEP_SIZE_MAX, all ACCs will be allowed 
immediately.
+ */
+void acc_ramp_start(struct acc_ramp *acc_ramp);
+
+/*
+ * Abort the ramping process. If ramping is disabled or has already finished,
+ * then this function has no effect.
+ */
+void acc_ramp_abort(struct acc_ramp *acc_ramp);
+
+/*
+ * Return bitmasks which correspond to access control classes that are 
currently
+ * denied access. Ramping is only concerned with those bits which control 
access
+ * for ACCs 0-9, and any of the other bits will always be set to zero in these 
masks, i.e.
+ * it is safe to OR these bitmasks with the corresponding fields in struct 
gsm48_rach_control.
+ */
+static inline uint8_t acc_ramp_get_barred_t2(struct acc_ramp *acc_ramp)
+{
+       return (acc_ramp->barred_t2 & 0x03);
+};
+
+static inline uint8_t acc_ramp_get_barred_t3(struct acc_ramp *acc_ramp)
+{
+       return acc_ramp->barred_t3;
+}
+
+/* Potentially mark certain Access Control Classes (ACCs) as barred in 
accordance to ACC ramping. */
+static inline void acc_ramp_apply(struct gsm48_rach_control *rach_control, 
struct acc_ramp *acc_ramp)
+{
+       rach_control->t2 |= acc_ramp_get_barred_t2(acc_ramp);
+       rach_control->t3 |= acc_ramp_get_barred_t3(acc_ramp);
+}
diff --git a/include/osmocom/bsc/gsm_data_shared.h 
b/include/osmocom/bsc/gsm_data_shared.h
index e3e1389..6af397d 100644
--- a/include/osmocom/bsc/gsm_data_shared.h
+++ b/include/osmocom/bsc/gsm_data_shared.h
@@ -22,6 +22,7 @@
 #include <osmocom/bsc/common_cs.h>
 #include <osmocom/bsc/meas_rep.h>
 #include <osmocom/bsc/rest_octets.h>
+#include <osmocom/bsc/acc_ramp.h>
 
 /* 16 is the max. number of SI2quater messages according to 3GPP TS 44.018 
Table 10.5.2.33b.1:
    4-bit index is used (2#1111 = 10#15) */
@@ -787,6 +788,10 @@
        /* do we use static (user-defined) system information messages? 
(bitmask) */
        uint32_t si_mode_static;
 
+       /* access control class ramping */
+       struct acc_ramp acc_ramp;
+       bool acc_ramping_enabled;
+
        /* exclude the BTS from the global RF Lock handling */
        int excl_from_rf_lock;
 
@@ -815,6 +820,7 @@
        /* Periodic channel load measurements are used to maintain T3122. */
        struct load_counter chan_load_samples[7];
        int chan_load_samples_idx;
+       uint8_t chan_load_avg; /* current channel load average in percent (0 - 
100). */
 };
 
 
diff --git a/src/libbsc/Makefile.am b/src/libbsc/Makefile.am
index d118f44..8efe9d1 100644
--- a/src/libbsc/Makefile.am
+++ b/src/libbsc/Makefile.am
@@ -27,6 +27,7 @@
        abis_om2000.c \
        abis_om2000_vty.c \
        abis_rsl.c \
+       acc_ramp.c \
        bsc_rll.c \
        bsc_subscriber.c \
        paging.c \
diff --git a/src/libbsc/acc_ramp.c b/src/libbsc/acc_ramp.c
new file mode 100644
index 0000000..3d544f6
--- /dev/null
+++ b/src/libbsc/acc_ramp.c
@@ -0,0 +1,199 @@
+/* (C) 2018 by sysmocom s.f.m.c. GmbH <i...@sysmocom.de>
+ *
+ * Author: Stefan Sperling <ssperl...@sysmocom.de>
+ *
+ * All Rights Reserved
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#include <strings.h>
+#include <errno.h>
+
+#include <osmocom/bsc/debug.h>
+#include <osmocom/bsc/acc_ramp.h>
+#include <osmocom/bsc/gsm_data.h>
+
+/*
+ * Check if an ACC has been permanently barred for a BTS,
+ * e.g. with the 'rach access-control-class' VTY command.
+ */
+static bool acc_is_enabled(struct gsm_bts *bts, unsigned int acc)
+{
+       OSMO_ASSERT(acc >= 0 && acc <= 9);
+       if (acc == 8 || acc == 9)
+               return (bts->si_common.rach_control.t2 & (1 << (acc - 8))) == 0;
+       return (bts->si_common.rach_control.t3 & (1 << (acc))) == 0;
+}
+
+static void allow_one_acc(struct acc_ramp *acc_ramp, unsigned int acc)
+{
+       OSMO_ASSERT(acc >= 0 && acc <= 9);
+       LOGP(DRSL, LOGL_DEBUG, "(bts=%d) ACC RAMP: allowing Access Control 
Class %u\n", acc_ramp->bts->nr, acc);
+       if (acc == 8 || acc == 9)
+               acc_ramp->barred_t2 &= ~(1 << (acc - 8));
+       else
+               acc_ramp->barred_t3 &= ~(1 << acc);
+}
+
+static void barr_one_acc(struct acc_ramp *acc_ramp, unsigned int acc)
+{
+       OSMO_ASSERT(acc >= 0 && acc <= 9);
+       LOGP(DRSL, LOGL_DEBUG, "(bts=%d) ACC RAMP: barring Access Control Class 
%u\n", acc_ramp->bts->nr, acc);
+       if (acc == 8 || acc == 9)
+               acc_ramp->barred_t2 |= (1 << (acc - 8));
+       else
+               acc_ramp->barred_t3 |= (1 << acc);
+}
+
+static void barr_all_enabled_accs(struct acc_ramp *acc_ramp)
+{
+       unsigned int acc;
+       for (acc = 0; acc < 10; acc++) {
+               if (acc_is_enabled(acc_ramp->bts, acc))
+                       barr_one_acc(acc_ramp, acc);
+       }
+}
+
+static void allow_all_enabled_accs(struct acc_ramp *acc_ramp)
+{
+       unsigned int acc;
+       for (acc = 0; acc < 10; acc++) {
+               if (acc_is_enabled(acc_ramp->bts, acc))
+                       allow_one_acc(acc_ramp, acc);
+       }
+}
+
+static unsigned int get_next_step_interval(struct acc_ramp *acc_ramp)
+{
+       struct gsm_bts *bts = acc_ramp->bts;
+       uint64_t load;
+
+       if (acc_ramp->step_interval_is_fixed)
+               return acc_ramp->step_interval_sec;
+
+       /* Scale the step interval to current channel load average. */
+       load = (bts->chan_load_avg << 8); /* convert to fixed-point */
+       acc_ramp->step_interval_sec = ((load * ACC_RAMP_STEP_INTERVAL_MAX) / 
100) >> 8;
+       if (acc_ramp->step_interval_sec < ACC_RAMP_STEP_SIZE_MIN)
+               acc_ramp->step_interval_sec = ACC_RAMP_STEP_INTERVAL_MIN;
+       else if (acc_ramp->step_interval_sec > ACC_RAMP_STEP_INTERVAL_MAX)
+               acc_ramp->step_interval_sec = ACC_RAMP_STEP_INTERVAL_MAX;
+
+       LOGP(DRSL, LOGL_DEBUG, "(bts=%d) ACC RAMP: step interval set to %u 
seconds based on %u%% channel load average\n",
+            bts->nr, acc_ramp->step_interval_sec, bts->chan_load_avg);
+       return acc_ramp->step_interval_sec;
+}
+
+static void do_acc_ramping_step(void *data)
+{
+       struct acc_ramp *acc_ramp = data;
+       int i;
+
+       /* Shortcut in case we only do one ramping step. */
+       if (acc_ramp->step_size == ACC_RAMP_STEP_SIZE_MAX) {
+               allow_all_enabled_accs(acc_ramp);
+               gsm_bts_set_system_infos(acc_ramp->bts);
+               return;
+       }
+
+       /* Allow 'step_size' ACCs, starting from ACC0. ACC9 will be allowed 
last. */
+       for (i = 0; i < acc_ramp->step_size; i++) {
+               int idx = ffs(acc_ramp_get_barred_t3(acc_ramp));
+               if (idx > 0) {
+                       /* One of ACC0-ACC7 is still bared. */
+                       unsigned int acc = idx - 1;
+                       if (acc_is_enabled(acc_ramp->bts, acc))
+                               allow_one_acc(acc_ramp, acc);
+               } else {
+                       idx = ffs(acc_ramp_get_barred_t2(acc_ramp));
+                       if (idx == 1 || idx == 2) {
+                               /* ACC8 or ACC9 is still barred. */
+                               unsigned int acc = idx - 1 + 8;
+                               if (acc_is_enabled(acc_ramp->bts, acc))
+                                       allow_one_acc(acc_ramp, acc);
+                       } else {
+                               /* All ACCs are now allowed. */
+                               break;
+                       }
+               }
+       }
+
+       gsm_bts_set_system_infos(acc_ramp->bts);
+
+       /* If we have not allowed all ACCs yet, schedule another ramping step. 
*/
+       if (acc_ramp_get_barred_t2(acc_ramp) != 0x00 ||
+           acc_ramp_get_barred_t3(acc_ramp) != 0x00)
+               osmo_timer_schedule(&acc_ramp->step_timer, 
get_next_step_interval(acc_ramp), 0);
+}
+
+void acc_ramp_init(struct acc_ramp *acc_ramp, struct gsm_bts *bts)
+{
+       acc_ramp->bts = bts;
+       acc_ramp->step_size = ACC_RAMP_STEP_SIZE_DEFAULT;
+       acc_ramp->step_interval_sec = ACC_RAMP_STEP_INTERVAL_MIN;
+       acc_ramp->step_interval_is_fixed = false;
+       osmo_timer_setup(&acc_ramp->step_timer, do_acc_ramping_step, acc_ramp);
+
+       if (bts->acc_ramping_enabled)
+               barr_all_enabled_accs(acc_ramp);
+       else
+               allow_all_enabled_accs(acc_ramp);
+}
+
+int acc_ramp_set_step_size(struct acc_ramp *acc_ramp, unsigned int step_size)
+{
+       if (step_size < ACC_RAMP_STEP_SIZE_MIN || step_size > 
ACC_RAMP_STEP_SIZE_MAX)
+               return -ERANGE;
+
+       acc_ramp->step_size = step_size;
+       LOGP(DRSL, LOGL_DEBUG, "(bts=%d) ACC RAMP: ramping step size set to 
%u\n", acc_ramp->bts->nr, step_size);
+       return 0;
+}
+
+int acc_ramp_set_step_interval(struct acc_ramp *acc_ramp, unsigned int 
step_interval)
+{
+       if (step_interval < ACC_RAMP_STEP_INTERVAL_MIN || step_interval > 
ACC_RAMP_STEP_INTERVAL_MAX)
+               return -ERANGE;
+
+       acc_ramp->step_interval_sec = step_interval;
+       acc_ramp->step_interval_is_fixed = true;
+       LOGP(DRSL, LOGL_DEBUG, "(bts=%d) ACC RAMP: ramping step interval set to 
%u seconds\n",
+            acc_ramp->bts->nr, step_interval);
+       return 0;
+}
+
+void acc_ramp_set_step_interval_dynamic(struct acc_ramp *acc_ramp)
+{
+       acc_ramp->step_interval_is_fixed = false;
+       LOGP(DRSL, LOGL_DEBUG, "(bts=%d) ACC RAMP: ramping step interval set to 
'dynamic'\n",
+            acc_ramp->bts->nr);
+}
+
+void acc_ramp_start(struct acc_ramp *acc_ramp)
+{
+       /* Abort any previously running ramping process. */
+       acc_ramp_abort(acc_ramp);
+
+       /* Set all availble ACCs to barred and start ramping up. */
+       barr_all_enabled_accs(acc_ramp);
+       do_acc_ramping_step(acc_ramp);
+}
+
+void acc_ramp_abort(struct acc_ramp *acc_ramp)
+{
+       if (osmo_timer_pending(&acc_ramp->step_timer))
+               osmo_timer_del(&acc_ramp->step_timer);
+}
diff --git a/src/libbsc/bsc_init.c b/src/libbsc/bsc_init.c
index 2b1d53b..20f4b87 100644
--- a/src/libbsc/bsc_init.c
+++ b/src/libbsc/bsc_init.c
@@ -331,6 +331,12 @@
                bsc_gsmnet->network_code, trx->bts->location_area_code,
                trx->bts->cell_identity, trx->bts->bsic);
 
+       /*
+        * Re-initialize ACC ramping to ensure ACCs are barred/allowed
+        * according to our current VTY configuration.
+        */
+       acc_ramp_init(&trx->bts->acc_ramp, trx->bts);
+
        if (trx->bts->type == GSM_BTS_TYPE_NOKIA_SITE) {
                rsl_nokia_si_begin(trx);
        }
@@ -345,6 +351,9 @@
 
        for (i = 0; i < ARRAY_SIZE(trx->ts); i++)
                generate_ma_for_ts(&trx->ts[i]);
+
+       if (trx->bts->acc_ramping_enabled)
+               acc_ramp_start(&trx->bts->acc_ramp);
 }
 
 /* Callback function to be called every time we receive a signal from INPUT */
@@ -400,8 +409,10 @@
 
                if (isd->link_type == E1INP_SIGN_OML)
                        
rate_ctr_inc(&trx->bts->bts_ctrs->ctr[BTS_CTR_BTS_OML_FAIL]);
-               else if (isd->link_type == E1INP_SIGN_RSL)
+               else if (isd->link_type == E1INP_SIGN_RSL) {
                        
rate_ctr_inc(&trx->bts->bts_ctrs->ctr[BTS_CTR_BTS_RSL_FAIL]);
+                       acc_ramp_abort(&trx->bts->acc_ramp);
+               }
 
                /*
                 * free all allocated channels. change the nm_state so the
@@ -525,6 +536,8 @@
 
        bts->chan_load_samples_idx = 0;
 
+       acc_ramp_init(&bts->acc_ramp, bts);
+
        /* Initialize the BTS state */
        gsm_bts_mo_reset(bts);
 
diff --git a/src/libbsc/bsc_vty.c b/src/libbsc/bsc_vty.c
index 3da4745..b11d074 100644
--- a/src/libbsc/bsc_vty.c
+++ b/src/libbsc/bsc_vty.c
@@ -61,6 +61,7 @@
 #include <osmocom/bsc/handover_cfg.h>
 #include <osmocom/bsc/handover_vty.h>
 #include <osmocom/bsc/gsm_04_08_utils.h>
+#include <osmocom/bsc/acc_ramp.h>
 
 #include <inttypes.h>
 
@@ -266,6 +267,17 @@
                VTY_NEWLINE);
        vty_out(vty, "Cell Reselection Hysteresis: %u dBm%s",
                bts->si_common.cell_sel_par.cell_resel_hyst*2, VTY_NEWLINE);
+       vty_out(vty, "Access Control Class ramping: %senabled%s",
+               bts->acc_ramping_enabled ? "" : "not ", VTY_NEWLINE);
+       if (bts->acc_ramping_enabled) {
+               if (bts->acc_ramp.step_interval_is_fixed)
+                       vty_out(vty, "  Access Control Class ramping step 
interval: %u seconds%s",
+                               bts->acc_ramp.step_interval_sec, VTY_NEWLINE);
+               else
+                       vty_out(vty, "  Access Control Class ramping step 
interval: dynamic%s", VTY_NEWLINE);
+               vty_out(vty, "  enabling %u Access Control Class%s per ramping 
step%s",
+                       bts->acc_ramp.step_size, bts->acc_ramp.step_size > 1 ? 
"es" : "", VTY_NEWLINE);
+       }
        vty_out(vty, "RACH TX-Integer: %u%s", 
bts->si_common.rach_control.tx_integer,
                VTY_NEWLINE);
        vty_out(vty, "RACH Max transmissions: %u%s",
@@ -668,6 +680,14 @@
                for (i = 0; i < 8; i++)
                        if ((i != 2) && (bts->si_common.rach_control.t2 & (0x1 
<< i)))
                                vty_out(vty, "  rach access-control-class %d 
barred%s", i+8, VTY_NEWLINE);
+       vty_out(vty, "  %saccess-control-class-ramping%s", 
bts->acc_ramping_enabled ? "" : "no ", VTY_NEWLINE);
+       if (bts->acc_ramp.step_interval_is_fixed) {
+               vty_out(vty, "  access-control-class-ramping-step-interval 
%u%s",
+                       bts->acc_ramp.step_interval_sec, VTY_NEWLINE);
+       } else {
+               vty_out(vty, "  access-control-class-ramping-step-interval 
dynamic%s", VTY_NEWLINE);
+       }
+       vty_out(vty, "  access-control-class-ramping-step-size %u%s", 
bts->acc_ramp.step_size, VTY_NEWLINE);
        for (i = SYSINFO_TYPE_1; i < _MAX_SYSINFO_TYPE; i++) {
                if (bts->si_mode_static & (1 << i)) {
                        vty_out(vty, "  system-information %s mode static%s",
@@ -1753,6 +1773,11 @@
                /* allocate a new one */
                bts = gsm_bts_alloc_register(gsmnet, GSM_BTS_TYPE_UNKNOWN,
                                             HARDCODED_BSIC);
+               /*
+                * Initalize bts->acc_ramp here. Else we could segfault while
+                * processing a configuration file with ACC ramping settings.
+                */
+               acc_ramp_init(&bts->acc_ramp, bts);
        } else
                bts = gsm_bts_num(gsmnet, bts_nr);
 
@@ -3105,6 +3130,90 @@
        return CMD_SUCCESS;
 }
 
+DEFUN(cfg_bts_acc_ramping,
+      cfg_bts_acc_ramping_cmd,
+      "access-control-class-ramping",
+      "Enable Access Control Class ramping\n")
+{
+       struct gsm_bts *bts = vty->index;
+
+       bts->acc_ramping_enabled = true;
+
+       /* ACC ramping takes effect when the BTS reconnects. */
+       return CMD_SUCCESS;
+}
+
+DEFUN(cfg_bts_no_acc_ramping, cfg_bts_no_acc_ramping_cmd,
+      "no access-control-class-ramping",
+      NO_STR
+      "Disable Access Control Class ramping\n")
+{
+       struct gsm_bts *bts = vty->index;
+       bool was_enabled = bts->acc_ramping_enabled;
+
+       bts->acc_ramping_enabled = false;
+       if (was_enabled) {
+               acc_ramp_abort(&bts->acc_ramp);
+               acc_ramp_init(&bts->acc_ramp, bts);
+               gsm_bts_set_system_infos(bts);
+       }
+
+       return CMD_SUCCESS;
+}
+
+DEFUN(cfg_bts_acc_ramping_step_interval,
+      cfg_bts_acc_ramping_step_interval_cmd,
+      "access-control-class-ramping-step-interval (<"
+      OSMO_STRINGIFY_VAL(ACC_RAMP_STEP_INTERVAL_MIN) "-"
+      OSMO_STRINGIFY_VAL(ACC_RAMP_STEP_INTERVAL_MAX) ">|dynamic)",
+      "Configure Access Control Class ramping step interval\n"
+      "Set a fixed step interval (in seconds)\n"
+      "Use dynamic step interval based on BTS channel load\n")
+{
+       struct gsm_bts *bts = vty->index;
+       bool dynamic = (strcmp(argv[0], "dynamic") == 0);
+       int error;
+
+       if (dynamic) {
+               acc_ramp_set_step_interval_dynamic(&bts->acc_ramp);
+               return CMD_SUCCESS;
+       }
+
+       error = acc_ramp_set_step_interval(&bts->acc_ramp, atoi(argv[0]));
+       if (error != 0) {
+               if (error == -ERANGE)
+                       vty_out(vty, "Unable to set ACC ramp step interval: 
value out of range%s", VTY_NEWLINE);
+               else
+                       vty_out(vty, "Unable to set ACC ramp step interval: 
unknown error%s", VTY_NEWLINE);
+               return CMD_WARNING;
+       }
+
+       return CMD_SUCCESS;
+}
+
+DEFUN(cfg_bts_acc_ramping_step_size,
+      cfg_bts_acc_ramping_step_size_cmd,
+      "access-control-class-ramping-step-size (<"
+      OSMO_STRINGIFY_VAL(ACC_RAMP_STEP_SIZE_MIN) "-"
+      OSMO_STRINGIFY_VAL(ACC_RAMP_STEP_SIZE_MAX) ">)",
+      "Configure Access Control Class ramping step size\n"
+      "Set the number of Access Control Classes to enable per ramping step\n")
+{
+       struct gsm_bts *bts = vty->index;
+       int error;
+
+       error = acc_ramp_set_step_size(&bts->acc_ramp, atoi(argv[0]));
+       if (error != 0) {
+               if (error == -ERANGE)
+                       vty_out(vty, "Unable to set ACC ramp step size: value 
out of range%s", VTY_NEWLINE);
+               else
+                       vty_out(vty, "Unable to set ACC ramp step size: unknown 
error%s", VTY_NEWLINE);
+               return CMD_WARNING;
+       }
+
+       return CMD_SUCCESS;
+}
+
 #define EXCL_RFLOCK_STR "Exclude this BTS from the global RF Lock\n"
 
 DEFUN(cfg_bts_excl_rf_lock,
@@ -4436,6 +4545,10 @@
        install_element(BTS_NODE, &cfg_bts_amr_hr_hyst3_cmd);
        install_element(BTS_NODE, &cfg_bts_amr_hr_start_mode_cmd);
        install_element(BTS_NODE, &cfg_bts_pcu_sock_cmd);
+       install_element(BTS_NODE, &cfg_bts_acc_ramping_cmd);
+       install_element(BTS_NODE, &cfg_bts_no_acc_ramping_cmd);
+       install_element(BTS_NODE, &cfg_bts_acc_ramping_step_interval_cmd);
+       install_element(BTS_NODE, &cfg_bts_acc_ramping_step_size_cmd);
        /* See also handover commands added on bts level from handover_vty.c */
 
        install_element(BTS_NODE, &cfg_trx_cmd);
diff --git a/src/libbsc/chan_alloc.c b/src/libbsc/chan_alloc.c
index 500ad59..b3d415d 100644
--- a/src/libbsc/chan_alloc.c
+++ b/src/libbsc/chan_alloc.c
@@ -656,8 +656,9 @@
        load = ((used / total) * 100);
        LOGP(DRLL, LOGL_DEBUG, "(bts=%d) channel load average is %lu.%.2lu%%\n",
             bts->nr, (load & 0xffffff00) >> 8, (load & 0xff) / 10);
-       osmo_stat_item_set(bts->bts_statg->items[BTS_STAT_CHAN_LOAD_AVERAGE],
-                          (load & 0xffffff00) >> 8);
+       bts->chan_load_avg = ((load & 0xffffff00) >> 8);
+       OSMO_ASSERT(bts->chan_load_avg <= 100);
+       osmo_stat_item_set(bts->bts_statg->items[BTS_STAT_CHAN_LOAD_AVERAGE], 
bts->chan_load_avg);
 
        /* Calculate new T3122 wait indicator. */
        wait_ind = ((used / total) * max_wait_ind);
diff --git a/src/libbsc/system_information.c b/src/libbsc/system_information.c
index a04959d..221af0b 100644
--- a/src/libbsc/system_information.c
+++ b/src/libbsc/system_information.c
@@ -39,6 +39,7 @@
 #include <osmocom/bsc/rest_octets.h>
 #include <osmocom/bsc/arfcn_range_encode.h>
 #include <osmocom/bsc/gsm_04_08_utils.h>
+#include <osmocom/bsc/acc_ramp.h>
 
 /*
  * DCS1800 and PCS1900 have overlapping ARFCNs. We would need to set the
@@ -675,6 +676,8 @@
        list_arfcn(si1->cell_channel_description, 0xce, "Serving cell:");
 
        si1->rach_control = bts->si_common.rach_control;
+       if (bts->acc_ramping_enabled)
+               acc_ramp_apply(&si1->rach_control, &bts->acc_ramp);
 
        /*
         * SI1 Rest Octets (10.5.2.32), contains NCH position and band
@@ -705,6 +708,8 @@
 
        si2->ncc_permitted = bts->si_common.ncc_permitted;
        si2->rach_control = bts->si_common.rach_control;
+       if (bts->acc_ramping_enabled)
+               acc_ramp_apply(&si2->rach_control, &bts->acc_ramp);
 
        return sizeof(*si2);
 }
@@ -738,6 +743,8 @@
                bts->si_valid &= ~(1 << SYSINFO_TYPE_2bis);
 
        si2b->rach_control = bts->si_common.rach_control;
+       if (bts->acc_ramping_enabled)
+               acc_ramp_apply(&si2b->rach_control, &bts->acc_ramp);
 
        /* SI2bis Rest Octets as per 3GPP TS 44.018 ยง10.5.2.33 */
        rc = rest_octets_si2bis(si2b->rest_octets);
@@ -860,6 +867,8 @@
        si3->cell_options = bts->si_common.cell_options;
        si3->cell_sel_par = bts->si_common.cell_sel_par;
        si3->rach_control = bts->si_common.rach_control;
+       if (bts->acc_ramping_enabled)
+               acc_ramp_apply(&si3->rach_control, &bts->acc_ramp);
 
        /* allow/disallow DTXu */
        gsm48_set_dtx(&si3->cell_options, bts->dtxu, bts->dtxu, true);
@@ -910,6 +919,8 @@
                           bts->location_area_code);
        si4->cell_sel_par = bts->si_common.cell_sel_par;
        si4->rach_control = bts->si_common.rach_control;
+       if (bts->acc_ramping_enabled)
+               acc_ramp_apply(&si4->rach_control, &bts->acc_ramp);
 
        /* Optional: CBCH Channel Description + CBCH Mobile Allocation */
        cbch_lchan = gsm_bts_get_cbch(bts);
diff --git a/src/libcommon/gsm_data_shared.c b/src/libcommon/gsm_data_shared.c
index 57bf77d..54f97cb 100644
--- a/src/libcommon/gsm_data_shared.c
+++ b/src/libcommon/gsm_data_shared.c
@@ -390,6 +390,8 @@
 
        /* si handling */
        bts->bcch_change_mark = 1;
+       bts->acc_ramping_enabled = false;
+       bts->chan_load_avg = 0;
 
        bts->ho = ho_cfg_init(bts, net->ho);
 

-- 
To view, visit https://gerrit.osmocom.org/6324
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: newpatchset
Gerrit-Change-Id: I0a5ac3a08f992f326435944f17e0a9171911afb0
Gerrit-PatchSet: 4
Gerrit-Project: osmo-bsc
Gerrit-Branch: master
Gerrit-Owner: Stefan Sperling <ssperl...@sysmocom.de>
Gerrit-Reviewer: Harald Welte <lafo...@gnumonks.org>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: Stefan Sperling <ssperl...@sysmocom.de>
Gerrit-Reviewer: Vadim Yanitskiy <axilira...@gmail.com>

Reply via email to