blob: c7be38cb39477c655c0f889c7652b409b99d3d66 [file] [log] [blame]
Stefan Sperling6442e432018-02-06 14:44:54 +01001/* (C) 2018 by sysmocom s.f.m.c. GmbH <info@sysmocom.de>
2 *
3 * Author: Stefan Sperling <ssperling@sysmocom.de>
4 *
5 * All Rights Reserved
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
16 *
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 *
20 */
21
22#pragma once
23
24#include <stdbool.h>
25#include <stdint.h>
26
27#include <osmocom/core/timer.h>
28#include <osmocom/gsm/protocol/gsm_04_08.h>
29
Pau Espin Pedroldeaa6fd2020-07-16 20:53:21 +020030#define ACC_MGR_QUANTUM_DEFAULT 20 /* 20 seconds */
31
32/* Manage rotating subset of allowed Access Class as per configuration */
33struct acc_mgr {
34 struct gsm_bts *bts; /*!< backpointer to BTS using this ACC manager */
35 /* Administrative Maximum Number of ACC 0-9 to be allowed at the same time.
36 Configurable through VTY cmd "access-control-class-roundrobin",
37 defaults to all allowed (10) */
38 uint8_t len_allowed_adm;
39 /* Further limiting the number of ACC to use. It may be lower due
40 to ramping, based for instance on channel or system load. */
41 uint8_t len_allowed_ramp;
42
43 /* Time until next subset is generated */
44 uint32_t rotation_time_sec;
45 struct osmo_timer_list rotate_timer;
46
47 /* Bitmask containing subset of allowed ACC 0-9 on current rotation iteration */
48 uint16_t allowed_subset_mask;
49 /* Number of bits (ACC) set in allowed_subset_mask: 0->min(len_allowed_ramp, len_allowed_adm) */
50 uint8_t allowed_subset_mask_count;
51 /* Number of ACC 0-9 allowed as per adminsitrative (permanent) config. */
52 uint8_t allowed_permanent_count;
53};
54
55void acc_mgr_init(struct acc_mgr *acc_mgr, struct gsm_bts *bts);
56uint8_t acc_mgr_get_len_allowed_adm(struct acc_mgr *acc_mgr);
57uint8_t acc_mgr_get_len_allowed_ramp(struct acc_mgr *acc_mgr);
58void acc_mgr_set_len_allowed_adm(struct acc_mgr *acc_mgr, uint8_t len_allowed_adm);
59void acc_mgr_set_len_allowed_ramp(struct acc_mgr *acc_mgr, uint8_t len_allowed_ramp);
60void acc_mgr_set_rotation_time(struct acc_mgr *acc_mgr, uint32_t rotation_time_sec);
61void acc_mgr_perm_subset_changed(struct acc_mgr *acc_mgr, struct gsm48_rach_control *rach_control);
62void acc_mgr_apply_acc(struct acc_mgr *acc_mgr, struct gsm48_rach_control *rach_control);
63
Stefan Sperling6442e432018-02-06 14:44:54 +010064/*!
65 * Access control class (ACC) ramping is used to slowly make the cell available to
66 * an increasing number of MS. This avoids overload at startup time in cases where
67 * a lot of MS would discover the new cell and try to connect to it all at once.
68 */
69
70#define ACC_RAMP_STEP_SIZE_MIN 1 /* allow at most 1 new ACC per ramp step */
71#define ACC_RAMP_STEP_SIZE_DEFAULT ACC_RAMP_STEP_SIZE_MIN
72#define ACC_RAMP_STEP_SIZE_MAX 10 /* allow all ACC in one step (effectively disables ramping) */
73
Pau Espin Pedrol1e5e7002020-07-23 19:13:56 +020074#define ACC_RAMP_STEP_INTERVAL_MIN 5 /* 5 seconds */
Stefan Sperling6442e432018-02-06 14:44:54 +010075#define ACC_RAMP_STEP_INTERVAL_MAX 600 /* 10 minutes */
76
Pau Espin Pedrol1e5e7002020-07-23 19:13:56 +020077#define ACC_RAMP_CHAN_LOAD_THRESHOLD_LOW 71
78#define ACC_RAMP_CHAN_LOAD_THRESHOLD_UP 89
79
Stefan Sperling6442e432018-02-06 14:44:54 +010080/*!
81 * Data structure used to manage ACC ramping. Please avoid setting or reading fields
82 * in this structure directly. Use the accessor functions below instead.
83 */
84struct acc_ramp {
85 struct gsm_bts *bts; /*!< backpointer to BTS using this ACC ramp */
86
87 bool acc_ramping_enabled; /*!< whether ACC ramping is enabled */
88
89 /*!
Stefan Sperling6442e432018-02-06 14:44:54 +010090 * This controls the maximum number of ACCs to allow per ramping step (1 - 10).
91 * The compile-time default value is ACC_RAMP_STEP_SIZE_DEFAULT.
92 * This value can be changed by VTY configuration.
93 * A value of ACC_RAMP_STEP_SIZE_MAX effectively disables ramping.
94 */
95 unsigned int step_size;
96
97 /*!
98 * Ramping step interval in seconds.
99 * This value depends on the current BTS channel load average, unless
Martin Haukea29affd2019-11-13 22:10:41 +0100100 * it has been overridden by VTY configuration.
Stefan Sperling6442e432018-02-06 14:44:54 +0100101 */
102 unsigned int step_interval_sec;
Stefan Sperling6442e432018-02-06 14:44:54 +0100103 struct osmo_timer_list step_timer;
Pau Espin Pedrol1e5e7002020-07-23 19:13:56 +0200104
105 /*!
106 * Channel Load Upper/Lower Thresholds:
107 * They control how ramping subset size of allowed ACCs changes in
108 * relation to current channel load (%, 0-100): Under the lower
109 * threshold, subset size may be increased; above the upper threshold,
110 * subset size may be decreased.
111 */
112 unsigned int chan_load_lower_threshold;
113 unsigned int chan_load_upper_threshold;
Stefan Sperling6442e432018-02-06 14:44:54 +0100114};
115
116/*!
Stefan Sperlingea333412018-04-10 16:36:54 +0200117 * Enable or disable ACC ramping.
118 * When enabled, ramping begins once acc_ramp_start() is called.
119 * When disabled, an ACC ramping process in progress will continue
120 * unless acc_ramp_abort() is called as well.
121 * \param[in] acc_ramp Pointer to acc_ramp structure.
122 */
123static inline void acc_ramp_set_enabled(struct acc_ramp *acc_ramp, bool enable)
124{
125 acc_ramp->acc_ramping_enabled = enable;
126}
127
128/*!
Stefan Sperling6442e432018-02-06 14:44:54 +0100129 * Return true if ACC ramping is currently enabled, else false.
130 * \param[in] acc_ramp Pointer to acc_ramp structure.
131 */
132static inline bool acc_ramp_is_enabled(struct acc_ramp *acc_ramp)
133{
134 return acc_ramp->acc_ramping_enabled;
135}
136
137/*!
138 * Return the current ACC ramp step size.
139 * \param[in] acc_ramp Pointer to acc_ramp structure.
140 */
141static inline unsigned int acc_ramp_get_step_size(struct acc_ramp *acc_ramp)
142{
143 return acc_ramp->step_size;
144}
145
146/*!
147 * Return the current ACC ramp step interval (in seconds)
148 * \param[in] acc_ramp Pointer to acc_ramp structure.
149 */
150static inline unsigned int acc_ramp_get_step_interval(struct acc_ramp *acc_ramp)
151{
152 return acc_ramp->step_interval_sec;
153}
154
155/*!
Pau Espin Pedrol1e5e7002020-07-23 19:13:56 +0200156 * Return the current ACC ramp step interval (in seconds)
Stefan Sperling6442e432018-02-06 14:44:54 +0100157 * \param[in] acc_ramp Pointer to acc_ramp structure.
158 */
Pau Espin Pedrol1e5e7002020-07-23 19:13:56 +0200159static inline unsigned int acc_ramp_is_running(struct acc_ramp *acc_ramp)
Stefan Sperling6442e432018-02-06 14:44:54 +0100160{
Pau Espin Pedrol1e5e7002020-07-23 19:13:56 +0200161 return acc_ramp->step_interval_sec;
Stefan Sperling6442e432018-02-06 14:44:54 +0100162}
163
Stefan Sperlingea333412018-04-10 16:36:54 +0200164void acc_ramp_init(struct acc_ramp *acc_ramp, struct gsm_bts *bts);
Stefan Sperling6442e432018-02-06 14:44:54 +0100165int acc_ramp_set_step_size(struct acc_ramp *acc_ramp, unsigned int step_size);
166int acc_ramp_set_step_interval(struct acc_ramp *acc_ramp, unsigned int step_interval);
Pau Espin Pedrol1e5e7002020-07-23 19:13:56 +0200167int acc_ramp_set_chan_load_thresholds(struct acc_ramp *acc_ramp, unsigned int low_threshold, unsigned int up_threshold);
Stefan Sperlingea333412018-04-10 16:36:54 +0200168void acc_ramp_trigger(struct acc_ramp *acc_ramp);
Stefan Sperling6442e432018-02-06 14:44:54 +0100169void acc_ramp_abort(struct acc_ramp *acc_ramp);