[PATCH] osmo-bsc[master]: Add support for Access Control Class ramping.

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

Stefan Sperling gerrit-no-reply at lists.osmocom.org
Tue Feb 27 14:15:50 UTC 2018


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 (#8).

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:

  [no] access-control-class-ramping
  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 step with a 'dynamic' 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.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/gsm_data.c
M src/libbsc/system_information.c
10 files changed, 533 insertions(+), 3 deletions(-)


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

diff --git a/include/osmocom/bsc/Makefile.am b/include/osmocom/bsc/Makefile.am
index a5d7d18..17e8bd3 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..cb063bf
--- /dev/null
+++ b/include/osmocom/bsc/acc_ramp.h
@@ -0,0 +1,149 @@
+/* (C) 2018 by sysmocom s.f.m.c. GmbH <info at sysmocom.de>
+ *
+ * Author: Stefan Sperling <ssperling at 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 */
+
+/*!
+ * Data structure used to manage ACC ramping. Please avoid setting or reading fields
+ * in this structure directly. Use the accessor functions below instead.
+ */
+struct acc_ramp {
+	struct gsm_bts *bts; /*!< backpointer to BTS using this ACC ramp */
+
+	bool acc_ramping_enabled; /*!< whether ACC ramping is enabled */
+
+	/*!
+	 * Bitmask which keeps track of access control classes that are currently denied
+	 * access. The function acc_ramp_apply() uses this mask to modulate bits from
+	 * octets 2 and 3 in RACH Control Parameters (see 3GPP 44.018 10.5.2.29).
+	 * Ramping is only concerned with ACCs 0-9. While any of the bits 0-9 is set,
+	 * the corresponding ACC is barred.
+	 * ACCs 11-15 should always be allowed, and ACC 10 denies emergency calls for
+	 * all ACCs from 0-9 inclusive; these ACCs are ignored in this implementation.
+	 */
+	uint16_t barred_accs;
+
+	/*!
+	 * 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;
+};
+
+/*!
+ * Return true if ACC ramping is currently enabled, else false.
+ * \param[in] acc_ramp Pointer to acc_ramp structure.
+ */
+static inline bool acc_ramp_is_enabled(struct acc_ramp *acc_ramp)
+{
+	return acc_ramp->acc_ramping_enabled;
+}
+
+/*!
+ * Return the current ACC ramp step size.
+ * \param[in] acc_ramp Pointer to acc_ramp structure.
+ */
+static inline unsigned int acc_ramp_get_step_size(struct acc_ramp *acc_ramp)
+{
+	return acc_ramp->step_size;
+}
+
+/*!
+ * Return the current ACC ramp step interval (in seconds)
+ * \param[in] acc_ramp Pointer to acc_ramp structure.
+ */
+static inline unsigned int acc_ramp_get_step_interval(struct acc_ramp *acc_ramp)
+{
+	return acc_ramp->step_interval_sec;
+}
+
+/*!
+ * If the step interval is dynamic, return true, else return false.
+ * \param[in] acc_ramp Pointer to acc_ramp structure.
+ */
+static inline bool acc_ramp_step_interval_is_dynamic(struct acc_ramp *acc_ramp)
+{
+	return !(acc_ramp->step_interval_is_fixed);
+}
+
+/*!
+ * 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.
+ * \param[in] acc_ramp Pointer to acc_ramp structure.
+ */
+static inline uint8_t acc_ramp_get_barred_t2(struct acc_ramp *acc_ramp)
+{
+	return ((acc_ramp->barred_accs >> 8) & 0x03);
+};
+static inline uint8_t acc_ramp_get_barred_t3(struct acc_ramp *acc_ramp)
+{
+	return (acc_ramp->barred_accs & 0xff);
+}
+
+/*!
+ * Potentially mark certain Access Control Classes (ACCs) as barred in accordance to ACC ramping.
+ * \param[in] rach_control RACH control parameters in which barred ACCs will be configured.
+ * \param[in] acc_ramp Pointer to acc_ramp structure.
+ */
+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);
+}
+
+void acc_ramp_init(struct acc_ramp *acc_ramp, bool enable, struct gsm_bts *bts);
+int acc_ramp_set_step_size(struct acc_ramp *acc_ramp, unsigned int step_size);
+int acc_ramp_set_step_interval(struct acc_ramp *acc_ramp, unsigned int step_interval);
+void acc_ramp_set_step_interval_dynamic(struct acc_ramp *acc_ramp);
+void acc_ramp_start(struct acc_ramp *acc_ramp);
+void acc_ramp_abort(struct acc_ramp *acc_ramp);
diff --git a/include/osmocom/bsc/gsm_data.h b/include/osmocom/bsc/gsm_data.h
index 07e5478..3c65c9c 100644
--- a/include/osmocom/bsc/gsm_data.h
+++ b/include/osmocom/bsc/gsm_data.h
@@ -26,6 +26,7 @@
 #include <osmocom/abis/e1_input.h>
 #include <osmocom/bsc/meas_rep.h>
 #include <osmocom/bsc/bsc_msg_filter.h>
+#include <osmocom/bsc/acc_ramp.h>
 
 struct mgcp_client_conf;
 struct mgcp_client;
@@ -948,6 +949,9 @@
 	/* do we use static (user-defined) system information messages? (bitmask) */
 	uint32_t si_mode_static;
 
+	/* access control class ramping */
+	struct acc_ramp acc_ramp;
+
 	/* exclude the BTS from the global RF Lock handling */
 	int excl_from_rf_lock;
 
@@ -976,6 +980,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 bb14227..805a7ee 100644
--- a/src/libbsc/Makefile.am
+++ b/src/libbsc/Makefile.am
@@ -26,6 +26,7 @@
 	abis_om2000_vty.c \
 	abis_rsl.c \
 	a_reset.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..7cace4b
--- /dev/null
+++ b/src/libbsc/acc_ramp.c
@@ -0,0 +1,235 @@
+/* (C) 2018 by sysmocom s.f.m.c. GmbH <info at sysmocom.de>
+ *
+ * Author: Stefan Sperling <ssperling at 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 <stdbool.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);
+	acc_ramp->barred_accs &= ~(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);
+	acc_ramp->barred_accs |= (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);
+}
+
+/*!
+ * Initialize an acc_ramp data structure.
+ * Storage for this structure must be provided by the caller.
+ *
+ * If ACC ramping is enabled, all ACCs are denied by default.
+ * A subsequent call to acc_ramp_start() will begin the ramping process.
+ * If ACC ramping is disabled, all ACCs will be allowed by default,
+ * and there is no need to do anything else.
+ *
+ * \param[in] acc_ramp Pointer to acc_ramp structure to be initialized.
+ * \param[in] enable Indicates whether ACC ramping should be enabled or disabled.
+ * \param[in] bts BTS which uses this ACC ramp data structure.
+ */
+void acc_ramp_init(struct acc_ramp *acc_ramp, bool enable, struct gsm_bts *bts)
+{
+	acc_ramp->bts = bts;
+	acc_ramp->acc_ramping_enabled = enable;
+	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 (acc_ramp->acc_ramping_enabled)
+		barr_all_enabled_accs(acc_ramp);
+	else
+		allow_all_enabled_accs(acc_ramp);
+}
+
+/*!
+ * Change the ramping step size which controls how many ACCs will be allowed per ramping step.
+ * Returns negative on error (step_size out of range), else zero.
+ * \param[in] acc_ramp Pointer to acc_ramp structure.
+ * \param[in] step_size The new step size value.
+ */
+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;
+}
+
+/*!
+ * 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.
+ * \param[in] acc_ramp Pointer to acc_ramp structure.
+ * \param[in] step_interval The new fixed step interval in seconds.
+ */
+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;
+}
+
+/*!
+ * Clear a previously set fixed ramping step interval, so that the interval
+ * is again automatically scaled to the BTS channel load average.
+ * \param[in] acc_ramp Pointer to acc_ramp structure.
+ */
+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);
+}
+
+/*!
+ * 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.
+ * \param[in] acc_ramp Pointer to acc_ramp structure.
+ */
+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);
+}
+
+/*!
+ * Abort the ramping process. If ramping is disabled or has already finished,
+ * then this function has no effect.
+ * \param[in] acc_ramp Pointer to acc_ramp structure.
+ */
+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..2fddc80 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, acc_ramp_is_enabled(&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 (acc_ramp_is_enabled(&trx->bts->acc_ramp))
+		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, false, 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 36c849d..5ff9cb2 100644
--- a/src/libbsc/bsc_vty.c
+++ b/src/libbsc/bsc_vty.c
@@ -60,6 +60,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>
 
@@ -343,6 +344,18 @@
 		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",
+		acc_ramp_is_enabled(&bts->acc_ramp) ? "" : "not ", VTY_NEWLINE);
+	if (acc_ramp_is_enabled(&bts->acc_ramp)) {
+		if (!acc_ramp_step_interval_is_dynamic(&bts->acc_ramp))
+			vty_out(vty, "  Access Control Class ramping step interval: %u seconds%s",
+				acc_ramp_get_step_interval(&bts->acc_ramp), 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",
+			acc_ramp_get_step_size(&bts->acc_ramp),
+			acc_ramp_get_step_size(&bts->acc_ramp) > 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",
@@ -767,6 +780,15 @@
 		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", acc_ramp_is_enabled(&bts->acc_ramp) ? "" : "no ", VTY_NEWLINE);
+	if (!acc_ramp_step_interval_is_dynamic(&bts->acc_ramp)) {
+		vty_out(vty, "  access-control-class-ramping-step-interval %u%s",
+			acc_ramp_get_step_interval(&bts->acc_ramp), 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", acc_ramp_get_step_size(&bts->acc_ramp),
+		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",
@@ -1858,6 +1880,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, false, bts);
 	} else
 		bts = gsm_bts_num(gsmnet, bts_nr);
 
@@ -3204,6 +3231,88 @@
 	if (rc < 0) {
 		vty_out(vty, "%% Error creating PCU socket `%s' for BTS %u%s",
 			bts->pcu_sock_path, bts->nr, VTY_NEWLINE);
+		return CMD_WARNING;
+	}
+
+	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;
+
+	acc_ramp_init(&bts->acc_ramp, true, bts);
+
+	/* 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;
+
+	if (acc_ramp_is_enabled(&bts->acc_ramp)) {
+		acc_ramp_abort(&bts->acc_ramp);
+		acc_ramp_init(&bts->acc_ramp, false, 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;
 	}
 
@@ -4723,6 +4832,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 21d5090..284cb21 100644
--- a/src/libbsc/chan_alloc.c
+++ b/src/libbsc/chan_alloc.c
@@ -662,8 +662,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/gsm_data.c b/src/libbsc/gsm_data.c
index a504252..e1d422e 100644
--- a/src/libbsc/gsm_data.c
+++ b/src/libbsc/gsm_data.c
@@ -771,6 +771,7 @@
 
 	/* si handling */
 	bts->bcch_change_mark = 1;
+	bts->chan_load_avg = 0;
 
 	bts->ho = ho_cfg_init(bts, net->ho);
 
diff --git a/src/libbsc/system_information.c b/src/libbsc/system_information.c
index a04959d..750bba4 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 (acc_ramp_is_enabled(&bts->acc_ramp))
+		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 (acc_ramp_is_enabled(&bts->acc_ramp))
+		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 (acc_ramp_is_enabled(&bts->acc_ramp))
+		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 (acc_ramp_is_enabled(&bts->acc_ramp))
+		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 (acc_ramp_is_enabled(&bts->acc_ramp))
+		acc_ramp_apply(&si4->rach_control, &bts->acc_ramp);
 
 	/* Optional: CBCH Channel Description + CBCH Mobile Allocation */
 	cbch_lchan = gsm_bts_get_cbch(bts);

-- 
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: 8
Gerrit-Project: osmo-bsc
Gerrit-Branch: master
Gerrit-Owner: Stefan Sperling <ssperling at sysmocom.de>
Gerrit-Reviewer: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: Stefan Sperling <ssperling at sysmocom.de>
Gerrit-Reviewer: Vadim Yanitskiy <axilirator at gmail.com>



More information about the gerrit-log mailing list