blob: efb12b08852f165bcdb71210ed30effb57f4f11f [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
30/*!
31 * Access control class (ACC) ramping is used to slowly make the cell available to
32 * an increasing number of MS. This avoids overload at startup time in cases where
33 * a lot of MS would discover the new cell and try to connect to it all at once.
34 */
35
36#define ACC_RAMP_STEP_SIZE_MIN 1 /* allow at most 1 new ACC per ramp step */
37#define ACC_RAMP_STEP_SIZE_DEFAULT ACC_RAMP_STEP_SIZE_MIN
38#define ACC_RAMP_STEP_SIZE_MAX 10 /* allow all ACC in one step (effectively disables ramping) */
39
40#define ACC_RAMP_STEP_INTERVAL_MIN 30 /* 30 seconds */
41#define ACC_RAMP_STEP_INTERVAL_MAX 600 /* 10 minutes */
42
43/*!
44 * Data structure used to manage ACC ramping. Please avoid setting or reading fields
45 * in this structure directly. Use the accessor functions below instead.
46 */
47struct acc_ramp {
48 struct gsm_bts *bts; /*!< backpointer to BTS using this ACC ramp */
49
50 bool acc_ramping_enabled; /*!< whether ACC ramping is enabled */
51
52 /*!
53 * Bitmask which keeps track of access control classes that are currently denied
54 * access. The function acc_ramp_apply() uses this mask to modulate bits from
55 * octets 2 and 3 in RACH Control Parameters (see 3GPP 44.018 10.5.2.29).
56 * Ramping is only concerned with ACCs 0-9. While any of the bits 0-9 is set,
57 * the corresponding ACC is barred.
58 * ACCs 11-15 should always be allowed, and ACC 10 denies emergency calls for
59 * all ACCs from 0-9 inclusive; these ACCs are ignored in this implementation.
60 */
61 uint16_t barred_accs;
62
63 /*!
64 * This controls the maximum number of ACCs to allow per ramping step (1 - 10).
65 * The compile-time default value is ACC_RAMP_STEP_SIZE_DEFAULT.
66 * This value can be changed by VTY configuration.
67 * A value of ACC_RAMP_STEP_SIZE_MAX effectively disables ramping.
68 */
69 unsigned int step_size;
70
71 /*!
72 * Ramping step interval in seconds.
73 * This value depends on the current BTS channel load average, unless
74 * it has been overriden by VTY configuration.
75 */
76 unsigned int step_interval_sec;
77 bool step_interval_is_fixed;
78 struct osmo_timer_list step_timer;
79};
80
81/*!
Stefan Sperlingea333412018-04-10 16:36:54 +020082 * Enable or disable ACC ramping.
83 * When enabled, ramping begins once acc_ramp_start() is called.
84 * When disabled, an ACC ramping process in progress will continue
85 * unless acc_ramp_abort() is called as well.
86 * \param[in] acc_ramp Pointer to acc_ramp structure.
87 */
88static inline void acc_ramp_set_enabled(struct acc_ramp *acc_ramp, bool enable)
89{
90 acc_ramp->acc_ramping_enabled = enable;
91}
92
93/*!
Stefan Sperling6442e432018-02-06 14:44:54 +010094 * Return true if ACC ramping is currently enabled, else false.
95 * \param[in] acc_ramp Pointer to acc_ramp structure.
96 */
97static inline bool acc_ramp_is_enabled(struct acc_ramp *acc_ramp)
98{
99 return acc_ramp->acc_ramping_enabled;
100}
101
102/*!
103 * Return the current ACC ramp step size.
104 * \param[in] acc_ramp Pointer to acc_ramp structure.
105 */
106static inline unsigned int acc_ramp_get_step_size(struct acc_ramp *acc_ramp)
107{
108 return acc_ramp->step_size;
109}
110
111/*!
112 * Return the current ACC ramp step interval (in seconds)
113 * \param[in] acc_ramp Pointer to acc_ramp structure.
114 */
115static inline unsigned int acc_ramp_get_step_interval(struct acc_ramp *acc_ramp)
116{
117 return acc_ramp->step_interval_sec;
118}
119
120/*!
121 * If the step interval is dynamic, return true, else return false.
122 * \param[in] acc_ramp Pointer to acc_ramp structure.
123 */
124static inline bool acc_ramp_step_interval_is_dynamic(struct acc_ramp *acc_ramp)
125{
126 return !(acc_ramp->step_interval_is_fixed);
127}
128
129/*!
130 * Return bitmasks which correspond to access control classes that are currently
131 * denied access. Ramping is only concerned with those bits which control access
132 * for ACCs 0-9, and any of the other bits will always be set to zero in these masks, i.e.
133 * it is safe to OR these bitmasks with the corresponding fields in struct gsm48_rach_control.
134 * \param[in] acc_ramp Pointer to acc_ramp structure.
135 */
136static inline uint8_t acc_ramp_get_barred_t2(struct acc_ramp *acc_ramp)
137{
138 return ((acc_ramp->barred_accs >> 8) & 0x03);
139};
140static inline uint8_t acc_ramp_get_barred_t3(struct acc_ramp *acc_ramp)
141{
142 return (acc_ramp->barred_accs & 0xff);
143}
144
145/*!
146 * Potentially mark certain Access Control Classes (ACCs) as barred in accordance to ACC ramping.
147 * \param[in] rach_control RACH control parameters in which barred ACCs will be configured.
148 * \param[in] acc_ramp Pointer to acc_ramp structure.
149 */
150static inline void acc_ramp_apply(struct gsm48_rach_control *rach_control, struct acc_ramp *acc_ramp)
151{
152 rach_control->t2 |= acc_ramp_get_barred_t2(acc_ramp);
153 rach_control->t3 |= acc_ramp_get_barred_t3(acc_ramp);
154}
155
Stefan Sperlingea333412018-04-10 16:36:54 +0200156void acc_ramp_init(struct acc_ramp *acc_ramp, struct gsm_bts *bts);
Stefan Sperling6442e432018-02-06 14:44:54 +0100157int acc_ramp_set_step_size(struct acc_ramp *acc_ramp, unsigned int step_size);
158int acc_ramp_set_step_interval(struct acc_ramp *acc_ramp, unsigned int step_interval);
159void acc_ramp_set_step_interval_dynamic(struct acc_ramp *acc_ramp);
Stefan Sperlingea333412018-04-10 16:36:54 +0200160void acc_ramp_trigger(struct acc_ramp *acc_ramp);
Stefan Sperling6442e432018-02-06 14:44:54 +0100161void acc_ramp_abort(struct acc_ramp *acc_ramp);