blob: bd75f95998a9ca5d28c15394ce00fd8ce08c9055 [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
74#define ACC_RAMP_STEP_INTERVAL_MIN 30 /* 30 seconds */
75#define ACC_RAMP_STEP_INTERVAL_MAX 600 /* 10 minutes */
76
77/*!
78 * Data structure used to manage ACC ramping. Please avoid setting or reading fields
79 * in this structure directly. Use the accessor functions below instead.
80 */
81struct acc_ramp {
82 struct gsm_bts *bts; /*!< backpointer to BTS using this ACC ramp */
83
84 bool acc_ramping_enabled; /*!< whether ACC ramping is enabled */
85
86 /*!
Stefan Sperling6442e432018-02-06 14:44:54 +010087 * This controls the maximum number of ACCs to allow per ramping step (1 - 10).
88 * The compile-time default value is ACC_RAMP_STEP_SIZE_DEFAULT.
89 * This value can be changed by VTY configuration.
90 * A value of ACC_RAMP_STEP_SIZE_MAX effectively disables ramping.
91 */
92 unsigned int step_size;
93
94 /*!
95 * Ramping step interval in seconds.
96 * This value depends on the current BTS channel load average, unless
Martin Haukea29affd2019-11-13 22:10:41 +010097 * it has been overridden by VTY configuration.
Stefan Sperling6442e432018-02-06 14:44:54 +010098 */
99 unsigned int step_interval_sec;
100 bool step_interval_is_fixed;
101 struct osmo_timer_list step_timer;
102};
103
104/*!
Stefan Sperlingea333412018-04-10 16:36:54 +0200105 * Enable or disable ACC ramping.
106 * When enabled, ramping begins once acc_ramp_start() is called.
107 * When disabled, an ACC ramping process in progress will continue
108 * unless acc_ramp_abort() is called as well.
109 * \param[in] acc_ramp Pointer to acc_ramp structure.
110 */
111static inline void acc_ramp_set_enabled(struct acc_ramp *acc_ramp, bool enable)
112{
113 acc_ramp->acc_ramping_enabled = enable;
114}
115
116/*!
Stefan Sperling6442e432018-02-06 14:44:54 +0100117 * Return true if ACC ramping is currently enabled, else false.
118 * \param[in] acc_ramp Pointer to acc_ramp structure.
119 */
120static inline bool acc_ramp_is_enabled(struct acc_ramp *acc_ramp)
121{
122 return acc_ramp->acc_ramping_enabled;
123}
124
125/*!
126 * Return the current ACC ramp step size.
127 * \param[in] acc_ramp Pointer to acc_ramp structure.
128 */
129static inline unsigned int acc_ramp_get_step_size(struct acc_ramp *acc_ramp)
130{
131 return acc_ramp->step_size;
132}
133
134/*!
135 * Return the current ACC ramp step interval (in seconds)
136 * \param[in] acc_ramp Pointer to acc_ramp structure.
137 */
138static inline unsigned int acc_ramp_get_step_interval(struct acc_ramp *acc_ramp)
139{
140 return acc_ramp->step_interval_sec;
141}
142
143/*!
144 * If the step interval is dynamic, return true, else return false.
145 * \param[in] acc_ramp Pointer to acc_ramp structure.
146 */
147static inline bool acc_ramp_step_interval_is_dynamic(struct acc_ramp *acc_ramp)
148{
149 return !(acc_ramp->step_interval_is_fixed);
150}
151
Stefan Sperlingea333412018-04-10 16:36:54 +0200152void acc_ramp_init(struct acc_ramp *acc_ramp, struct gsm_bts *bts);
Stefan Sperling6442e432018-02-06 14:44:54 +0100153int acc_ramp_set_step_size(struct acc_ramp *acc_ramp, unsigned int step_size);
154int acc_ramp_set_step_interval(struct acc_ramp *acc_ramp, unsigned int step_interval);
155void acc_ramp_set_step_interval_dynamic(struct acc_ramp *acc_ramp);
Stefan Sperlingea333412018-04-10 16:36:54 +0200156void acc_ramp_trigger(struct acc_ramp *acc_ramp);
Stefan Sperling6442e432018-02-06 14:44:54 +0100157void acc_ramp_abort(struct acc_ramp *acc_ramp);