blob: 76dd5be9c3b6d4e29e56c46b867d364d1aa2caf2 [file] [log] [blame]
Pau Espin Pedrolac3fd122021-01-13 18:54:38 +01001/*
2 * Copyright (C) 2013 by Holger Hans Peter Freyther
3 * Copyright (C) 2021 by sysmocom - s.f.m.c. GmbH <info@sysmocom.de>
4 * Author: Pau Espin Pedrol <pespin@sysmocom.de>
5 *
6 * All Rights Reserved
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU Affero General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU Affero General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 *
21 */
22
23#include <osmocom/core/utils.h>
Pau Espin Pedrold1049dc2021-01-18 17:14:14 +010024#include <osmocom/core/linuxlist.h>
Pau Espin Pedrolc0a250d2021-01-21 18:46:13 +010025#include <osmocom/ctrl/ports.h>
Pau Espin Pedrolac3fd122021-01-13 18:54:38 +010026
27#include "gprs_pcu.h"
28#include "bts.h"
29
30struct gprs_pcu *the_pcu;
31
Pau Espin Pedrol924aaad2021-01-14 12:01:42 +010032static struct osmo_tdef T_defs_pcu[] = {
Oliver Smithd3c75912021-07-09 16:37:16 +020033 { .T=3113, .default_val=7, .unit=OSMO_TDEF_S, .desc="Timeout for paging", .val=0 },
Pau Espin Pedrol924aaad2021-01-14 12:01:42 +010034 { .T=3190, .default_val=5, .unit=OSMO_TDEF_S, .desc="Return to packet idle mode after Packet DL Assignment on CCCH (s)", .val=0},
Pau Espin Pedrol4b6f0bf2021-05-10 18:54:52 +020035 { .T=3141, .default_val=10, .unit=OSMO_TDEF_S, .desc="Timeout for contention resolution procedure (s)", .val=0 },
Pau Espin Pedrol41a22a72021-01-26 19:00:37 +010036 { .T=PCU_TDEF_NEIGH_RESOLVE_TO, .default_val=1000, .unit=OSMO_TDEF_MS, .desc="[ARFCN+BSIC]->[RAC+CI] resolution timeout (ms)", .val=0 },
37 { .T=PCU_TDEF_SI_RESOLVE_TO, .default_val=1000, .unit=OSMO_TDEF_MS, .desc="RIM RAN-INFO response timeout (ms)", .val=0 },
Pau Espin Pedrolab7159f2021-01-26 17:51:44 +010038 { .T=PCU_TDEF_NEIGH_CACHE_ALIVE, .default_val=5, .unit=OSMO_TDEF_S, .desc="[ARFCN+BSIC]->[RAC+CI] resolution cache entry storage timeout (s)", .val=0 },
39 { .T=PCU_TDEF_SI_CACHE_ALIVE, .default_val=5, .unit=OSMO_TDEF_S, .desc="[RAC+CI]->[SI] resolution cache entry storage timeout (s)", .val=0 },
Pau Espin Pedrol14339f62021-04-26 14:14:37 +020040 { .T=-101, .default_val=30, .unit=OSMO_TDEF_S, .desc="BSSGP (un)blocking procedures timer (s)", .val=0 },
41 { .T=-102, .default_val=30, .unit=OSMO_TDEF_S, .desc="BSSGP reset procedure timer (s)", .val=0 },
Pau Espin Pedrol683ce642021-11-15 14:49:08 +010042 { .T=-2000, .default_val=0, .unit=OSMO_TDEF_MS, .desc="Delay release of UL TBF after tx Packet Access Reject (PACCH) (ms)", .val=0 },
Pau Espin Pedrol039ee822021-04-26 18:49:33 +020043 { .T=-2001, .default_val=2, .unit=OSMO_TDEF_S, .desc="PACCH assignment timeout (s)", .val=0 },
Pau Espin Pedrol924aaad2021-01-14 12:01:42 +010044 { .T=-2002, .default_val=200, .unit=OSMO_TDEF_MS, .desc="Waiting after IMM.ASS confirm timer (ms)", .val=0 },
45 { .T=-2030, .default_val=60, .unit=OSMO_TDEF_S, .desc="Time to keep an idle MS object alive (s)", .val=0 }, /* slightly above T3314 (default 44s, 24.008, 11.2.2) */
46 { .T=-2031, .default_val=2000, .unit=OSMO_TDEF_MS, .desc="Time to keep an idle DL TBF alive (ms)", .val=0 },
47 { .T=0, .default_val=0, .unit=OSMO_TDEF_S, .desc=NULL, .val=0 } /* empty item at the end */
48};
49
Pau Espin Pedrol0dcbc072021-11-10 19:09:10 +010050static void _update_stats_timer_cb(void *data)
51{
52 struct gprs_pcu *pcu = (struct gprs_pcu *)data;
53 struct gprs_rlcmac_bts *bts;
54
55 llist_for_each_entry(bts, &pcu->bts_list, list)
56 osmo_time_cc_set_flag(&bts->all_allocated_pdch, bts_all_pdch_allocated(bts));
57
58 osmo_timer_schedule(&pcu->update_stats_timer, 1, 0);
59}
60
Pau Espin Pedrolc0a250d2021-01-21 18:46:13 +010061static int gprs_pcu_talloc_destructor(struct gprs_pcu *pcu)
62{
Pau Espin Pedrol0dcbc072021-11-10 19:09:10 +010063 if (osmo_timer_pending(&pcu->update_stats_timer))
64 osmo_timer_del(&pcu->update_stats_timer);
Pau Espin Pedrolc0a250d2021-01-21 18:46:13 +010065 neigh_cache_free(pcu->neigh_cache);
66 si_cache_free(pcu->si_cache);
67 return 0;
68}
69
Pau Espin Pedrolac3fd122021-01-13 18:54:38 +010070struct gprs_pcu *gprs_pcu_alloc(void *ctx)
71{
72 struct gprs_pcu *pcu;
73
74 pcu = (struct gprs_pcu *)talloc_zero(ctx, struct gprs_pcu);
75 OSMO_ASSERT(pcu);
Pau Espin Pedrolc0a250d2021-01-21 18:46:13 +010076 talloc_set_destructor(pcu, gprs_pcu_talloc_destructor);
Pau Espin Pedrolac3fd122021-01-13 18:54:38 +010077
Pau Espin Pedrole8912222021-01-14 14:03:17 +010078 pcu->vty.fc_interval = 1;
Pau Espin Pedrolac3fd122021-01-13 18:54:38 +010079 pcu->vty.max_cs_ul = MAX_GPRS_CS;
80 pcu->vty.max_cs_dl = MAX_GPRS_CS;
81 pcu->vty.max_mcs_ul = MAX_EDGE_MCS;
82 pcu->vty.max_mcs_dl = MAX_EDGE_MCS;
Pau Espin Pedrolfe8de452021-02-09 18:47:34 +010083 pcu->vty.force_alpha = (uint8_t)-1; /* don't force by default, use BTS SI13 provided value */
Pau Espin Pedrol05f9f592021-01-14 12:56:58 +010084 pcu->vty.dl_tbf_preemptive_retransmission = true;
Pau Espin Pedrol97296b22021-01-14 13:08:02 +010085 /* By default resegmentation is supported in DL can also be configured
86 * through VTY */
87 pcu->vty.dl_arq_type = EGPRS_ARQ1;
Pau Espin Pedrole8dcf642021-01-14 13:17:01 +010088 pcu->vty.cs_adj_enabled = true;
89 pcu->vty.cs_adj_upper_limit = 33; /* Decrease CS if the error rate is above */
90 pcu->vty.cs_adj_lower_limit = 10; /* Increase CS if the error rate is below */
Pau Espin Pedrolad79b852021-01-14 13:20:55 +010091 pcu->vty.cs_downgrade_threshold = 200;
Pau Espin Pedrol54b159a2021-01-14 13:30:04 +010092 /* CS-1 to CS-4 */
93 pcu->vty.cs_lqual_ranges[0].low = -256;
94 pcu->vty.cs_lqual_ranges[0].high = 6;
95 pcu->vty.cs_lqual_ranges[1].low = 5;
96 pcu->vty.cs_lqual_ranges[1].high = 8;
97 pcu->vty.cs_lqual_ranges[2].low = 7;
98 pcu->vty.cs_lqual_ranges[2].high = 13;
99 pcu->vty.cs_lqual_ranges[3].low = 12;
100 pcu->vty.cs_lqual_ranges[3].high = 256;
101 /* MCS-1 to MCS-9 */
102 /* Default thresholds are referenced from literature */
103 /* Fig. 2.3, Chapter 2, Optimizing Wireless Communication Systems, Springer (2009) */
104 pcu->vty.mcs_lqual_ranges[0].low = -256;
105 pcu->vty.mcs_lqual_ranges[0].high = 6;
106 pcu->vty.mcs_lqual_ranges[1].low = 5;
107 pcu->vty.mcs_lqual_ranges[1].high = 8;
108 pcu->vty.mcs_lqual_ranges[2].low = 7;
109 pcu->vty.mcs_lqual_ranges[2].high = 13;
110 pcu->vty.mcs_lqual_ranges[3].low = 12;
111 pcu->vty.mcs_lqual_ranges[3].high = 15;
112 pcu->vty.mcs_lqual_ranges[4].low = 14;
113 pcu->vty.mcs_lqual_ranges[4].high = 17;
114 pcu->vty.mcs_lqual_ranges[5].low = 16;
115 pcu->vty.mcs_lqual_ranges[5].high = 18;
116 pcu->vty.mcs_lqual_ranges[6].low = 17;
117 pcu->vty.mcs_lqual_ranges[6].high = 20;
118 pcu->vty.mcs_lqual_ranges[7].low = 19;
119 pcu->vty.mcs_lqual_ranges[7].high = 24;
120 pcu->vty.mcs_lqual_ranges[8].low = 23;
121 pcu->vty.mcs_lqual_ranges[8].high = 256;
Alexander Couzensf7ec5252021-01-25 20:28:38 +0100122 pcu->vty.ns_dialect = GPRS_NS2_DIALECT_IPACCESS;
Harald Welted9367e32021-04-29 22:02:47 +0200123 pcu->vty.ns_ip_dscp = -1;
124 pcu->vty.ns_priority = -1;
Pau Espin Pedrol519d0712021-01-14 14:30:03 +0100125 /* TODO: increase them when CRBB decoding is implemented */
126 pcu->vty.ws_base = 64;
127 pcu->vty.ws_pdch = 0;
Pau Espin Pedrolf473ec92021-01-14 14:45:14 +0100128 pcu->vty.llc_codel_interval_msec = LLC_CODEL_USE_DEFAULT;
129 pcu->vty.llc_idle_ack_csec = 10;
Pau Espin Pedrol5557c0a2021-09-07 14:09:50 +0200130 pcu->vty.neigh_ctrl_addr = NULL; /* don't use CTRL iface for Neigh Addr Resolution */
Pau Espin Pedrolc0a250d2021-01-21 18:46:13 +0100131 pcu->vty.neigh_ctrl_port = OSMO_CTRL_PORT_BSC_NEIGH;
Pau Espin Pedrolac3fd122021-01-13 18:54:38 +0100132
Pau Espin Pedrol924aaad2021-01-14 12:01:42 +0100133 pcu->T_defs = T_defs_pcu;
134 osmo_tdefs_reset(pcu->T_defs);
135
Pau Espin Pedrold1049dc2021-01-18 17:14:14 +0100136 INIT_LLIST_HEAD(&pcu->bts_list);
137
Pau Espin Pedrolab7159f2021-01-26 17:51:44 +0100138 pcu->neigh_cache = neigh_cache_alloc(pcu, osmo_tdef_get(pcu->T_defs, PCU_TDEF_NEIGH_CACHE_ALIVE, OSMO_TDEF_S, -1));
139 pcu->si_cache = si_cache_alloc(pcu, osmo_tdef_get(pcu->T_defs, PCU_TDEF_SI_CACHE_ALIVE, OSMO_TDEF_S, -1));
Pau Espin Pedrolc0a250d2021-01-21 18:46:13 +0100140
Pau Espin Pedrol0dcbc072021-11-10 19:09:10 +0100141 osmo_timer_setup(&pcu->update_stats_timer, _update_stats_timer_cb, pcu);
142 osmo_timer_schedule(&pcu->update_stats_timer, 1, 0);
143
Pau Espin Pedrolac3fd122021-01-13 18:54:38 +0100144 return pcu;
145}
146
Pau Espin Pedrold1049dc2021-01-18 17:14:14 +0100147struct gprs_rlcmac_bts *gprs_pcu_get_bts_by_nr(struct gprs_pcu *pcu, uint8_t bts_nr)
148{
149 struct gprs_rlcmac_bts *pos;
150 llist_for_each_entry(pos, &pcu->bts_list, list) {
151 if (pos->nr == bts_nr)
152 return pos;
153 }
154 return NULL;
155}
156
Pau Espin Pedrol3a271022021-01-21 18:44:23 +0100157struct gprs_rlcmac_bts *gprs_pcu_get_bts_by_cgi_ps(struct gprs_pcu *pcu, struct osmo_cell_global_id_ps *cgi_ps)
158{
159 struct gprs_rlcmac_bts *pos;
160 llist_for_each_entry(pos, &pcu->bts_list, list) {
Pau Espin Pedrola100a6b2021-01-22 17:45:50 +0100161 if (osmo_cgi_ps_cmp(&pos->cgi_ps, cgi_ps) == 0)
Pau Espin Pedrol3a271022021-01-21 18:44:23 +0100162 return pos;
163 }
164 return NULL;
165}
166
Pau Espin Pedrol793583e2021-01-14 16:20:57 +0100167void gprs_pcu_set_initial_cs(struct gprs_pcu *pcu, uint8_t cs_dl, uint8_t cs_ul)
168{
Pau Espin Pedrold1049dc2021-01-18 17:14:14 +0100169 struct gprs_rlcmac_bts *bts;
170
Pau Espin Pedrol793583e2021-01-14 16:20:57 +0100171 the_pcu->vty.initial_cs_dl = cs_dl;
172 the_pcu->vty.initial_cs_ul = cs_ul;
173
Pau Espin Pedrold1049dc2021-01-18 17:14:14 +0100174 llist_for_each_entry(bts, &pcu->bts_list, list) {
175 bts_recalc_initial_cs(bts);
176 }
Pau Espin Pedrol793583e2021-01-14 16:20:57 +0100177}
178void gprs_pcu_set_initial_mcs(struct gprs_pcu *pcu, uint8_t mcs_dl, uint8_t mcs_ul)
179{
Pau Espin Pedrold1049dc2021-01-18 17:14:14 +0100180 struct gprs_rlcmac_bts *bts;
181
Pau Espin Pedrol793583e2021-01-14 16:20:57 +0100182 the_pcu->vty.initial_mcs_dl = mcs_dl;
183 the_pcu->vty.initial_mcs_ul = mcs_ul;
184
Pau Espin Pedrold1049dc2021-01-18 17:14:14 +0100185 llist_for_each_entry(bts, &pcu->bts_list, list) {
186 bts_recalc_initial_mcs(bts);
187 }
Pau Espin Pedrol793583e2021-01-14 16:20:57 +0100188}
Pau Espin Pedrolac3fd122021-01-13 18:54:38 +0100189
190void gprs_pcu_set_max_cs(struct gprs_pcu *pcu, uint8_t cs_dl, uint8_t cs_ul)
191{
Pau Espin Pedrold1049dc2021-01-18 17:14:14 +0100192 struct gprs_rlcmac_bts *bts;
193
Pau Espin Pedrolac3fd122021-01-13 18:54:38 +0100194 the_pcu->vty.max_cs_dl = cs_dl;
195 the_pcu->vty.max_cs_ul = cs_ul;
Pau Espin Pedrold1049dc2021-01-18 17:14:14 +0100196
197 llist_for_each_entry(bts, &pcu->bts_list, list) {
198 bts_recalc_max_cs(bts);
199 }
Pau Espin Pedrolac3fd122021-01-13 18:54:38 +0100200}
201void gprs_pcu_set_max_mcs(struct gprs_pcu *pcu, uint8_t mcs_dl, uint8_t mcs_ul)
202{
Pau Espin Pedrold1049dc2021-01-18 17:14:14 +0100203 struct gprs_rlcmac_bts *bts;
204
Pau Espin Pedrolac3fd122021-01-13 18:54:38 +0100205 the_pcu->vty.max_mcs_dl = mcs_dl;
206 the_pcu->vty.max_mcs_ul = mcs_ul;
Pau Espin Pedrold1049dc2021-01-18 17:14:14 +0100207
208 llist_for_each_entry(bts, &pcu->bts_list, list) {
209 bts_recalc_max_mcs(bts);
210 }
Pau Espin Pedrolac3fd122021-01-13 18:54:38 +0100211}