Stefan Sperling | 6442e43 | 2018-02-06 14:44:54 +0100 | [diff] [blame] | 1 | /* (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 Pedrol | deaa6fd | 2020-07-16 20:53:21 +0200 | [diff] [blame] | 30 | #define ACC_MGR_QUANTUM_DEFAULT 20 /* 20 seconds */ |
| 31 | |
| 32 | /* Manage rotating subset of allowed Access Class as per configuration */ |
| 33 | struct 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 | |
| 55 | void acc_mgr_init(struct acc_mgr *acc_mgr, struct gsm_bts *bts); |
| 56 | uint8_t acc_mgr_get_len_allowed_adm(struct acc_mgr *acc_mgr); |
| 57 | uint8_t acc_mgr_get_len_allowed_ramp(struct acc_mgr *acc_mgr); |
| 58 | void acc_mgr_set_len_allowed_adm(struct acc_mgr *acc_mgr, uint8_t len_allowed_adm); |
| 59 | void acc_mgr_set_len_allowed_ramp(struct acc_mgr *acc_mgr, uint8_t len_allowed_ramp); |
| 60 | void acc_mgr_set_rotation_time(struct acc_mgr *acc_mgr, uint32_t rotation_time_sec); |
| 61 | void acc_mgr_perm_subset_changed(struct acc_mgr *acc_mgr, struct gsm48_rach_control *rach_control); |
| 62 | void acc_mgr_apply_acc(struct acc_mgr *acc_mgr, struct gsm48_rach_control *rach_control); |
| 63 | |
Stefan Sperling | 6442e43 | 2018-02-06 14:44:54 +0100 | [diff] [blame] | 64 | /*! |
| 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 Pedrol | 1e5e700 | 2020-07-23 19:13:56 +0200 | [diff] [blame] | 74 | #define ACC_RAMP_STEP_INTERVAL_MIN 5 /* 5 seconds */ |
Stefan Sperling | 6442e43 | 2018-02-06 14:44:54 +0100 | [diff] [blame] | 75 | #define ACC_RAMP_STEP_INTERVAL_MAX 600 /* 10 minutes */ |
| 76 | |
Pau Espin Pedrol | 1e5e700 | 2020-07-23 19:13:56 +0200 | [diff] [blame] | 77 | #define ACC_RAMP_CHAN_LOAD_THRESHOLD_LOW 71 |
| 78 | #define ACC_RAMP_CHAN_LOAD_THRESHOLD_UP 89 |
| 79 | |
Stefan Sperling | 6442e43 | 2018-02-06 14:44:54 +0100 | [diff] [blame] | 80 | /*! |
| 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 | */ |
| 84 | struct 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 Sperling | 6442e43 | 2018-02-06 14:44:54 +0100 | [diff] [blame] | 90 | * 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 Hauke | a29affd | 2019-11-13 22:10:41 +0100 | [diff] [blame] | 100 | * it has been overridden by VTY configuration. |
Stefan Sperling | 6442e43 | 2018-02-06 14:44:54 +0100 | [diff] [blame] | 101 | */ |
| 102 | unsigned int step_interval_sec; |
Stefan Sperling | 6442e43 | 2018-02-06 14:44:54 +0100 | [diff] [blame] | 103 | struct osmo_timer_list step_timer; |
Pau Espin Pedrol | 1e5e700 | 2020-07-23 19:13:56 +0200 | [diff] [blame] | 104 | |
| 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 Sperling | 6442e43 | 2018-02-06 14:44:54 +0100 | [diff] [blame] | 114 | }; |
| 115 | |
| 116 | /*! |
Stefan Sperling | ea33341 | 2018-04-10 16:36:54 +0200 | [diff] [blame] | 117 | * 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 | */ |
| 123 | static 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 Sperling | 6442e43 | 2018-02-06 14:44:54 +0100 | [diff] [blame] | 129 | * Return true if ACC ramping is currently enabled, else false. |
| 130 | * \param[in] acc_ramp Pointer to acc_ramp structure. |
| 131 | */ |
| 132 | static 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 | */ |
| 141 | static 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 | */ |
| 150 | static 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 Pedrol | 1e5e700 | 2020-07-23 19:13:56 +0200 | [diff] [blame] | 156 | * Return the current ACC ramp step interval (in seconds) |
Stefan Sperling | 6442e43 | 2018-02-06 14:44:54 +0100 | [diff] [blame] | 157 | * \param[in] acc_ramp Pointer to acc_ramp structure. |
| 158 | */ |
Pau Espin Pedrol | 1e5e700 | 2020-07-23 19:13:56 +0200 | [diff] [blame] | 159 | static inline unsigned int acc_ramp_is_running(struct acc_ramp *acc_ramp) |
Stefan Sperling | 6442e43 | 2018-02-06 14:44:54 +0100 | [diff] [blame] | 160 | { |
Pau Espin Pedrol | 1e5e700 | 2020-07-23 19:13:56 +0200 | [diff] [blame] | 161 | return acc_ramp->step_interval_sec; |
Stefan Sperling | 6442e43 | 2018-02-06 14:44:54 +0100 | [diff] [blame] | 162 | } |
| 163 | |
Stefan Sperling | ea33341 | 2018-04-10 16:36:54 +0200 | [diff] [blame] | 164 | void acc_ramp_init(struct acc_ramp *acc_ramp, struct gsm_bts *bts); |
Stefan Sperling | 6442e43 | 2018-02-06 14:44:54 +0100 | [diff] [blame] | 165 | int acc_ramp_set_step_size(struct acc_ramp *acc_ramp, unsigned int step_size); |
| 166 | int acc_ramp_set_step_interval(struct acc_ramp *acc_ramp, unsigned int step_interval); |
Pau Espin Pedrol | 1e5e700 | 2020-07-23 19:13:56 +0200 | [diff] [blame] | 167 | int acc_ramp_set_chan_load_thresholds(struct acc_ramp *acc_ramp, unsigned int low_threshold, unsigned int up_threshold); |
Stefan Sperling | ea33341 | 2018-04-10 16:36:54 +0200 | [diff] [blame] | 168 | void acc_ramp_trigger(struct acc_ramp *acc_ramp); |
Stefan Sperling | 6442e43 | 2018-02-06 14:44:54 +0100 | [diff] [blame] | 169 | void acc_ramp_abort(struct acc_ramp *acc_ramp); |