blob: b911b98b92aa5b11dd76f577f3965a2db7347819 [file] [log] [blame]
Neels Hofmeyr909e9722017-12-07 03:54:01 +01001/*
2 * (C) 2013 by Andreas Eversberg <jolly@eversberg.eu>
3 * All Rights Reserved
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU Affero General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU Affero General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 */
19
20#include <stdio.h>
21#include <stdlib.h>
22#include <errno.h>
23
24#include <assert.h>
25
26#include <osmocom/core/application.h>
27#include <osmocom/core/select.h>
28#include <osmocom/core/talloc.h>
29
Neels Hofmeyrf14aaa42019-04-23 18:37:37 +020030#include <osmocom/mgcp_client/mgcp_client_endpoint_fsm.h>
Pau Espin Pedrole2490452018-03-17 01:16:54 +010031
Neels Hofmeyr909e9722017-12-07 03:54:01 +010032#include <osmocom/bsc/abis_rsl.h>
33#include <osmocom/bsc/debug.h>
34#include <osmocom/bsc/bsc_subscriber.h>
Neels Hofmeyr31f525e2018-05-14 18:14:15 +020035#include <osmocom/bsc/lchan_select.h>
36#include <osmocom/bsc/lchan_fsm.h>
Neels Hofmeyr909e9722017-12-07 03:54:01 +010037#include <osmocom/bsc/handover_decision.h>
38#include <osmocom/bsc/system_information.h>
Neels Hofmeyr31f525e2018-05-14 18:14:15 +020039#include <osmocom/bsc/handover.h>
Neels Hofmeyr909e9722017-12-07 03:54:01 +010040#include <osmocom/bsc/handover_cfg.h>
41#include <osmocom/bsc/handover_decision_2.h>
Neels Hofmeyr909e9722017-12-07 03:54:01 +010042#include <osmocom/bsc/bss.h>
Neels Hofmeyr81a49632018-07-24 18:10:05 +020043#include <osmocom/bsc/gsm_08_08.h>
Neels Hofmeyr909e9722017-12-07 03:54:01 +010044#include <osmocom/bsc/osmo_bsc.h>
Harald Welte3561bd42018-01-28 03:04:16 +010045#include <osmocom/bsc/bsc_subscr_conn_fsm.h>
Neels Hofmeyr31f525e2018-05-14 18:14:15 +020046#include <osmocom/bsc/timeslot_fsm.h>
47#include <osmocom/bsc/lchan_fsm.h>
Neels Hofmeyr31f525e2018-05-14 18:14:15 +020048#include <osmocom/bsc/handover_fsm.h>
49#include <osmocom/bsc/bsc_msc_data.h>
Pau Espin Pedrol388ed582020-07-15 20:53:16 +020050#include <osmocom/bsc/bts.h>
Neels Hofmeyr86ce1052020-09-18 02:49:32 +020051#include <osmocom/bsc/paging.h>
Neels Hofmeyr909e9722017-12-07 03:54:01 +010052
Neels Hofmeyre3416182018-03-05 05:31:14 +010053void *ctx;
54
Neels Hofmeyr909e9722017-12-07 03:54:01 +010055struct gsm_network *bsc_gsmnet;
56
Neels Hofmeyrf14aaa42019-04-23 18:37:37 +020057/* override, requires '-Wl,--wrap=osmo_mgcpc_ep_ci_request'.
Harald Welte3561bd42018-01-28 03:04:16 +010058 * Catch modification of an MGCP connection. */
Neels Hofmeyrf14aaa42019-04-23 18:37:37 +020059void __real_osmo_mgcpc_ep_ci_request(struct osmo_mgcpc_ep_ci *ci,
Neels Hofmeyr31f525e2018-05-14 18:14:15 +020060 enum mgcp_verb verb, const struct mgcp_conn_peer *verb_info,
61 struct osmo_fsm_inst *notify,
62 uint32_t event_success, uint32_t event_failure,
63 void *notify_data);
Neels Hofmeyrf14aaa42019-04-23 18:37:37 +020064void __wrap_osmo_mgcpc_ep_ci_request(struct osmo_mgcpc_ep_ci *ci,
Neels Hofmeyr31f525e2018-05-14 18:14:15 +020065 enum mgcp_verb verb, const struct mgcp_conn_peer *verb_info,
66 struct osmo_fsm_inst *notify,
67 uint32_t event_success, uint32_t event_failure,
68 void *notify_data)
Harald Welte3561bd42018-01-28 03:04:16 +010069{
Neels Hofmeyr31f525e2018-05-14 18:14:15 +020070 struct mgcp_conn_peer fake_data = {};
71 /* All MGCP shall be successful */
72 if (!notify)
73 return;
74 osmo_fsm_inst_dispatch(notify, event_success, &fake_data);
Harald Welte3561bd42018-01-28 03:04:16 +010075}
76
Neels Hofmeyr909e9722017-12-07 03:54:01 +010077/* measurement report */
78
79uint8_t meas_rep_ba = 0, meas_rep_valid = 1, meas_valid = 1, meas_multi_rep = 0;
80uint8_t meas_dl_rxlev = 0, meas_dl_rxqual = 0;
81uint8_t meas_ul_rxlev = 0, meas_ul_rxqual = 0;
82uint8_t meas_tx_power_ms = 0, meas_tx_power_bs = 0, meas_ta_ms = 0;
83uint8_t meas_dtx_ms = 0, meas_dtx_bs = 0, meas_nr = 0;
84uint8_t meas_num_nc = 0, meas_rxlev_nc[6], meas_bsic_nc[6], meas_bcch_f_nc[6];
85
86static void gen_meas_rep(struct gsm_lchan *lchan)
87{
88 struct msgb *msg = msgb_alloc_headroom(256, 64, "RSL");
89 struct abis_rsl_dchan_hdr *dh;
90 uint8_t chan_nr = gsm_lchan2chan_nr(lchan);
91 uint8_t ulm[3], l1i[2], *buf;
92 struct gsm48_hdr *gh;
93 struct gsm48_meas_res *mr;
94
95 dh = (struct abis_rsl_dchan_hdr *) msgb_put(msg, sizeof(*dh));
96 dh->c.msg_discr = ABIS_RSL_MDISC_DED_CHAN;
97 dh->c.msg_type = RSL_MT_MEAS_RES;
98 dh->ie_chan = RSL_IE_CHAN_NR;
99 dh->chan_nr = chan_nr;
100
101 msgb_tv_put(msg, RSL_IE_MEAS_RES_NR, meas_nr++);
102
103 ulm[0] = meas_ul_rxlev | (meas_dtx_bs << 7);
104 ulm[1] = meas_ul_rxlev;
105 ulm[2] = (meas_ul_rxqual << 3) | meas_ul_rxqual;
106 msgb_tlv_put(msg, RSL_IE_UPLINK_MEAS, sizeof(ulm), ulm);
107
108 msgb_tv_put(msg, RSL_IE_BS_POWER, meas_tx_power_bs);
109
110 l1i[0] = 0;
111 l1i[1] = meas_ta_ms;
112 msgb_tv_fixed_put(msg, RSL_IE_L1_INFO, sizeof(l1i), l1i);
113
114 buf = msgb_put(msg, 3);
115 buf[0] = RSL_IE_L3_INFO;
116 buf[1] = (sizeof(*gh) + sizeof(*mr)) >> 8;
117 buf[2] = (sizeof(*gh) + sizeof(*mr)) & 0xff;
118
119 gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
120 mr = (struct gsm48_meas_res *) msgb_put(msg, sizeof(*mr));
121
122 gh->proto_discr = GSM48_PDISC_RR;
123 gh->msg_type = GSM48_MT_RR_MEAS_REP;
124
125 /* measurement results */
126 mr->rxlev_full = meas_dl_rxlev;
127 mr->rxlev_sub = meas_dl_rxlev;
128 mr->rxqual_full = meas_dl_rxqual;
129 mr->rxqual_sub = meas_dl_rxqual;
130 mr->dtx_used = meas_dtx_ms;
131 mr->ba_used = meas_rep_ba;
132 mr->meas_valid = !meas_valid; /* 0 = valid */
133 if (meas_rep_valid) {
134 mr->no_nc_n_hi = meas_num_nc >> 2;
135 mr->no_nc_n_lo = meas_num_nc & 3;
136 } else {
137 /* no results for serving cells */
138 mr->no_nc_n_hi = 1;
139 mr->no_nc_n_lo = 3;
140 }
141 mr->rxlev_nc1 = meas_rxlev_nc[0];
142 mr->rxlev_nc2_hi = meas_rxlev_nc[1] >> 1;
143 mr->rxlev_nc2_lo = meas_rxlev_nc[1] & 1;
144 mr->rxlev_nc3_hi = meas_rxlev_nc[2] >> 2;
145 mr->rxlev_nc3_lo = meas_rxlev_nc[2] & 3;
146 mr->rxlev_nc4_hi = meas_rxlev_nc[3] >> 3;
147 mr->rxlev_nc4_lo = meas_rxlev_nc[3] & 7;
148 mr->rxlev_nc5_hi = meas_rxlev_nc[4] >> 4;
149 mr->rxlev_nc5_lo = meas_rxlev_nc[4] & 15;
150 mr->rxlev_nc6_hi = meas_rxlev_nc[5] >> 5;
151 mr->rxlev_nc6_lo = meas_rxlev_nc[5] & 31;
152 mr->bsic_nc1_hi = meas_bsic_nc[0] >> 3;
153 mr->bsic_nc1_lo = meas_bsic_nc[0] & 7;
154 mr->bsic_nc2_hi = meas_bsic_nc[1] >> 4;
155 mr->bsic_nc2_lo = meas_bsic_nc[1] & 15;
156 mr->bsic_nc3_hi = meas_bsic_nc[2] >> 5;
157 mr->bsic_nc3_lo = meas_bsic_nc[2] & 31;
158 mr->bsic_nc4 = meas_bsic_nc[3];
159 mr->bsic_nc5 = meas_bsic_nc[4];
160 mr->bsic_nc6 = meas_bsic_nc[5];
161 mr->bcch_f_nc1 = meas_bcch_f_nc[0];
162 mr->bcch_f_nc2 = meas_bcch_f_nc[1];
163 mr->bcch_f_nc3 = meas_bcch_f_nc[2];
164 mr->bcch_f_nc4 = meas_bcch_f_nc[3];
165 mr->bcch_f_nc5_hi = meas_bcch_f_nc[4] >> 1;
166 mr->bcch_f_nc5_lo = meas_bcch_f_nc[4] & 1;
167 mr->bcch_f_nc6_hi = meas_bcch_f_nc[5] >> 2;
168 mr->bcch_f_nc6_lo = meas_bcch_f_nc[5] & 3;
169
170 msg->dst = lchan->ts->trx->bts->c0->rsl_link;
171 msg->l2h = (unsigned char *)dh;
172 msg->l3h = (unsigned char *)gh;
173
174 abis_rsl_rcvmsg(msg);
175}
176
Neels Hofmeyr2f58de52020-11-12 22:51:11 +0100177static struct gsm_bts *create_bts()
Neels Hofmeyr909e9722017-12-07 03:54:01 +0100178{
Neels Hofmeyr2f58de52020-11-12 22:51:11 +0100179 static int arfcn = 870;
Neels Hofmeyr909e9722017-12-07 03:54:01 +0100180 struct gsm_bts *bts;
181 struct e1inp_sign_link *rsl_link;
182 int i;
183
Vadim Yanitskiy4f3a6412020-05-31 01:56:20 +0700184 bts = bsc_bts_alloc_register(bsc_gsmnet, GSM_BTS_TYPE_UNKNOWN, 0x3f);
Neels Hofmeyr909e9722017-12-07 03:54:01 +0100185 if (!bts) {
186 printf("No resource for bts1\n");
187 return NULL;
188 }
189
190 bts->location_area_code = 23;
Neels Hofmeyr2f58de52020-11-12 22:51:11 +0100191 bts->c0->arfcn = arfcn++;
Neels Hofmeyr909e9722017-12-07 03:54:01 +0100192
193 bts->codec.efr = 1;
194 bts->codec.hr = 1;
195 bts->codec.amr = 1;
196
Neels Hofmeyre3416182018-03-05 05:31:14 +0100197 rsl_link = talloc_zero(ctx, struct e1inp_sign_link);
Neels Hofmeyr909e9722017-12-07 03:54:01 +0100198 rsl_link->trx = bts->c0;
199 bts->c0->rsl_link = rsl_link;
200
201 bts->c0->mo.nm_state.operational = NM_OPSTATE_ENABLED;
202 bts->c0->mo.nm_state.availability = NM_AVSTATE_OK;
Pau Espin Pedrolcce0ae12020-06-22 17:57:01 +0200203 bts->c0->mo.nm_state.administrative = NM_STATE_UNLOCKED;
Neels Hofmeyr909e9722017-12-07 03:54:01 +0100204 bts->c0->bb_transc.mo.nm_state.operational = NM_OPSTATE_ENABLED;
205 bts->c0->bb_transc.mo.nm_state.availability = NM_AVSTATE_OK;
Pau Espin Pedrolcce0ae12020-06-22 17:57:01 +0200206 bts->c0->bb_transc.mo.nm_state.administrative = NM_STATE_UNLOCKED;
Neels Hofmeyr909e9722017-12-07 03:54:01 +0100207
208 /* 4 full rate and 4 half rate channels */
209 for (i = 1; i <= 6; i++) {
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200210 bts->c0->ts[i].pchan_from_config = (i < 5) ? GSM_PCHAN_TCH_F : GSM_PCHAN_TCH_H;
Neels Hofmeyr909e9722017-12-07 03:54:01 +0100211 bts->c0->ts[i].mo.nm_state.operational = NM_OPSTATE_ENABLED;
212 bts->c0->ts[i].mo.nm_state.availability = NM_AVSTATE_OK;
Pau Espin Pedrolcce0ae12020-06-22 17:57:01 +0200213 bts->c0->ts[i].mo.nm_state.administrative = NM_STATE_UNLOCKED;
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200214 }
215
216 for (i = 0; i < ARRAY_SIZE(bts->c0->ts); i++) {
217 /* make sure ts->lchans[] get initialized */
Neels Hofmeyrbcdbfb72018-07-26 20:33:15 +0200218 osmo_fsm_inst_dispatch(bts->c0->ts[i].fi, TS_EV_RSL_READY, 0);
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200219 osmo_fsm_inst_dispatch(bts->c0->ts[i].fi, TS_EV_OML_READY, 0);
Neels Hofmeyr909e9722017-12-07 03:54:01 +0100220 }
221 return bts;
222}
223
224void create_conn(struct gsm_lchan *lchan)
225{
Neels Hofmeyrbb6c13b2018-05-24 18:43:58 +0200226 static unsigned int next_imsi = 0;
227 char imsi[sizeof(lchan->conn->bsub->imsi)];
228 struct gsm_network *net = lchan->ts->trx->bts->network;
Harald Welte3561bd42018-01-28 03:04:16 +0100229 struct gsm_subscriber_connection *conn;
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200230 struct mgcp_client *fake_mgcp_client = (void*)talloc_zero(net, int);
Neels Hofmeyrbb6c13b2018-05-24 18:43:58 +0200231
232 conn = bsc_subscr_con_allocate(net);
Harald Welte3561bd42018-01-28 03:04:16 +0100233
Neels Hofmeyrf14aaa42019-04-23 18:37:37 +0200234 conn->user_plane.mgw_endpoint = osmo_mgcpc_ep_alloc(conn->fi,
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200235 GSCON_EV_FORGET_MGW_ENDPOINT,
Neels Hofmeyrf14aaa42019-04-23 18:37:37 +0200236 fake_mgcp_client,
237 net->mgw.tdefs,
238 "test",
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200239 "fake endpoint");
Alexander Chemeris69ba8be2020-05-10 22:48:01 +0300240 conn->sccp.msc = osmo_msc_data_alloc(net, 0);
Harald Welte3561bd42018-01-28 03:04:16 +0100241
242 lchan->conn = conn;
243 conn->lchan = lchan;
Neels Hofmeyrbb6c13b2018-05-24 18:43:58 +0200244
245 /* Make up a new IMSI for this test, for logging the subscriber */
246 next_imsi ++;
247 snprintf(imsi, sizeof(imsi), "%06u", next_imsi);
Neels Hofmeyr86a1dca2020-09-15 01:03:58 +0000248 lchan->conn->bsub = bsc_subscr_find_or_create_by_imsi(net->bsc_subscribers, imsi, BSUB_USE_CONN);
Neels Hofmeyrbb6c13b2018-05-24 18:43:58 +0200249
Harald Welte3561bd42018-01-28 03:04:16 +0100250 /* kick the FSM from INIT through to the ACTIVE state */
Neels Hofmeyrd1e7d392020-09-27 23:34:57 +0200251 osmo_fsm_inst_dispatch(conn->fi, GSCON_EV_MO_COMPL_L3, NULL);
Harald Welte3561bd42018-01-28 03:04:16 +0100252 osmo_fsm_inst_dispatch(conn->fi, GSCON_EV_A_CONN_CFM, NULL);
Neels Hofmeyr909e9722017-12-07 03:54:01 +0100253}
254
255/* create lchan */
256struct gsm_lchan *create_lchan(struct gsm_bts *bts, int full_rate, char *codec)
257{
258 struct gsm_lchan *lchan;
259
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200260 lchan = lchan_select_by_type(bts, (full_rate) ? GSM_LCHAN_TCH_F : GSM_LCHAN_TCH_H);
Neels Hofmeyr909e9722017-12-07 03:54:01 +0100261 if (!lchan) {
262 printf("No resource for lchan\n");
263 exit(EXIT_FAILURE);
264 }
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200265
266 /* serious hack into osmo_fsm */
267 lchan->fi->state = LCHAN_ST_ESTABLISHED;
268 lchan->ts->fi->state = TS_ST_IN_USE;
269 LOG_LCHAN(lchan, LOGL_DEBUG, "activated by handover_test.c\n");
270
Neels Hofmeyr909e9722017-12-07 03:54:01 +0100271 create_conn(lchan);
272 if (!strcasecmp(codec, "FR") && full_rate)
273 lchan->tch_mode = GSM48_CMODE_SPEECH_V1;
274 else if (!strcasecmp(codec, "HR") && !full_rate)
275 lchan->tch_mode = GSM48_CMODE_SPEECH_V1;
276 else if (!strcasecmp(codec, "EFR") && full_rate)
277 lchan->tch_mode = GSM48_CMODE_SPEECH_EFR;
Philipp Maiereda6bfa2019-03-11 14:10:26 +0100278 else if (!strcasecmp(codec, "AMR")) {
Neels Hofmeyr909e9722017-12-07 03:54:01 +0100279 lchan->tch_mode = GSM48_CMODE_SPEECH_AMR;
Philipp Maiereda6bfa2019-03-11 14:10:26 +0100280 lchan->activate.info.s15_s0 = 0x0002;
281 } else {
Neels Hofmeyr909e9722017-12-07 03:54:01 +0100282 printf("Given codec unknown\n");
283 exit(EXIT_FAILURE);
284 }
285
286 lchan->conn->codec_list = (struct gsm0808_speech_codec_list){
287 .codec = {
288 { .fi=true, .type=GSM0808_SCT_FR1, },
289 { .fi=true, .type=GSM0808_SCT_FR2, },
290 { .fi=true, .type=GSM0808_SCT_FR3, },
291 { .fi=true, .type=GSM0808_SCT_HR1, },
292 { .fi=true, .type=GSM0808_SCT_HR3, },
293 },
294 .len = 5,
295 };
Neels Hofmeyr909e9722017-12-07 03:54:01 +0100296
297 return lchan;
298}
299
300/* parse channel request */
301
302static int got_chan_req = 0;
303static struct gsm_lchan *chan_req_lchan = NULL;
304
305static int parse_chan_act(struct gsm_lchan *lchan, uint8_t *data)
306{
307 chan_req_lchan = lchan;
308 return 0;
309}
310
311static int parse_chan_rel(struct gsm_lchan *lchan, uint8_t *data)
312{
313 chan_req_lchan = lchan;
314 return 0;
315}
316
317/* parse handover request */
318
319static int got_ho_req = 0;
320static struct gsm_lchan *ho_req_lchan = NULL;
321
322static int parse_ho_command(struct gsm_lchan *lchan, uint8_t *data, int len)
323{
324 struct gsm48_hdr *gh = (struct gsm48_hdr *) data;
325 struct gsm48_ho_cmd *ho = (struct gsm48_ho_cmd *) gh->data;
326 int arfcn;
327 struct gsm_bts *neigh;
328
329 switch (gh->msg_type) {
330 case GSM48_MT_RR_HANDO_CMD:
331 arfcn = (ho->cell_desc.arfcn_hi << 8) | ho->cell_desc.arfcn_lo;
332
333 /* look up trx. since every dummy bts uses different arfcn and
334 * only one trx, it is simple */
335 llist_for_each_entry(neigh, &bsc_gsmnet->bts_list, list) {
336 if (neigh->c0->arfcn != arfcn)
337 continue;
338 ho_req_lchan = lchan;
339 return 0;
340 }
341 break;
342 case GSM48_MT_RR_ASS_CMD:
343 ho_req_lchan = lchan;
344 return 0;
345 break;
346 default:
347 fprintf(stderr, "Error, expecting HO or AS command\n");
348 return -EINVAL;
349 }
350
351 return -1;
352}
353
354/* send channel activation ack */
355static void send_chan_act_ack(struct gsm_lchan *lchan, int act)
356{
357 struct msgb *msg = msgb_alloc_headroom(256, 64, "RSL");
358 struct abis_rsl_dchan_hdr *dh;
359
360 dh = (struct abis_rsl_dchan_hdr *) msgb_put(msg, sizeof(*dh));
361 dh->c.msg_discr = ABIS_RSL_MDISC_DED_CHAN;
362 dh->c.msg_type = (act) ? RSL_MT_CHAN_ACTIV_ACK : RSL_MT_RF_CHAN_REL_ACK;
363 dh->ie_chan = RSL_IE_CHAN_NR;
364 dh->chan_nr = gsm_lchan2chan_nr(lchan);
365
366 msg->dst = lchan->ts->trx->bts->c0->rsl_link;
367 msg->l2h = (unsigned char *)dh;
368
369 abis_rsl_rcvmsg(msg);
370}
371
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200372/* Send RLL Est Ind for SAPI[0] */
373static void send_est_ind(struct gsm_lchan *lchan)
374{
375 struct msgb *msg = msgb_alloc_headroom(256, 64, "RSL");
376 struct abis_rsl_rll_hdr *rh;
377 uint8_t chan_nr = gsm_lchan2chan_nr(lchan);
378
379 rh = (struct abis_rsl_rll_hdr *) msgb_put(msg, sizeof(*rh));
380 rh->c.msg_discr = ABIS_RSL_MDISC_RLL;
381 rh->c.msg_type = RSL_MT_EST_IND;
382 rh->ie_chan = RSL_IE_CHAN_NR;
383 rh->chan_nr = chan_nr;
384 rh->ie_link_id = RSL_IE_LINK_IDENT;
385 rh->link_id = 0x00;
386
387 msg->dst = lchan->ts->trx->bts->c0->rsl_link;
388 msg->l2h = (unsigned char *)rh;
389
390 abis_rsl_rcvmsg(msg);
391}
392
Neels Hofmeyr909e9722017-12-07 03:54:01 +0100393/* send handover complete */
394static void send_ho_complete(struct gsm_lchan *lchan, bool success)
395{
396 struct msgb *msg = msgb_alloc_headroom(256, 64, "RSL");
397 struct abis_rsl_rll_hdr *rh;
398 uint8_t chan_nr = gsm_lchan2chan_nr(lchan);
399 uint8_t *buf;
400 struct gsm48_hdr *gh;
401 struct gsm48_ho_cpl *hc;
402
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200403 send_est_ind(lchan);
Neels Hofmeyrac85b342018-07-12 21:23:26 +0200404 osmo_fsm_inst_dispatch(lchan->fi, LCHAN_EV_RTP_READY, 0);
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200405
Neels Hofmeyr909e9722017-12-07 03:54:01 +0100406 rh = (struct abis_rsl_rll_hdr *) msgb_put(msg, sizeof(*rh));
407 rh->c.msg_discr = ABIS_RSL_MDISC_RLL;
408 rh->c.msg_type = RSL_MT_DATA_IND;
409 rh->ie_chan = RSL_IE_CHAN_NR;
410 rh->chan_nr = chan_nr;
411 rh->ie_link_id = RSL_IE_LINK_IDENT;
412 rh->link_id = 0x00;
413
414 buf = msgb_put(msg, 3);
415 buf[0] = RSL_IE_L3_INFO;
416 buf[1] = (sizeof(*gh) + sizeof(*hc)) >> 8;
417 buf[2] = (sizeof(*gh) + sizeof(*hc)) & 0xff;
418
419 gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
420 hc = (struct gsm48_ho_cpl *) msgb_put(msg, sizeof(*hc));
421
422 gh->proto_discr = GSM48_PDISC_RR;
423 gh->msg_type =
424 success ? GSM48_MT_RR_HANDO_COMPL : GSM48_MT_RR_HANDO_FAIL;
425
426 msg->dst = lchan->ts->trx->bts->c0->rsl_link;
427 msg->l2h = (unsigned char *)rh;
428 msg->l3h = (unsigned char *)gh;
429
430 abis_rsl_rcvmsg(msg);
431}
432
Neels Hofmeyr1d7473c2018-03-05 21:53:18 +0100433/* override, requires '-Wl,--wrap=abis_rsl_sendmsg'.
434 * Catch RSL messages sent towards the BTS. */
435int __real_abis_rsl_sendmsg(struct msgb *msg);
436int __wrap_abis_rsl_sendmsg(struct msgb *msg)
Neels Hofmeyr909e9722017-12-07 03:54:01 +0100437{
438 struct abis_rsl_dchan_hdr *dh = (struct abis_rsl_dchan_hdr *) msg->data;
439 struct e1inp_sign_link *sign_link = msg->dst;
440 int rc;
441 struct gsm_lchan *lchan = rsl_lchan_lookup(sign_link->trx, dh->chan_nr, &rc);
442
443 if (rc) {
444 printf("rsl_lchan_lookup() failed\n");
445 exit(1);
446 }
447
448 switch (dh->c.msg_type) {
449 case RSL_MT_CHAN_ACTIV:
450 rc = parse_chan_act(lchan, dh->data);
451 if (rc == 0)
452 got_chan_req = 1;
453 break;
454 case RSL_MT_RF_CHAN_REL:
455 rc = parse_chan_rel(lchan, dh->data);
456 if (rc == 0)
457 send_chan_act_ack(chan_req_lchan, 0);
458 break;
459 case RSL_MT_DATA_REQ:
460 rc = parse_ho_command(lchan, msg->l3h, msgb_l3len(msg));
461 if (rc == 0)
462 got_ho_req = 1;
463 break;
464 case RSL_MT_IPAC_CRCX:
465 break;
Neels Hofmeyr5b1a7d12018-11-06 22:24:07 +0100466 case RSL_MT_DEACTIVATE_SACCH:
467 break;
Neels Hofmeyr909e9722017-12-07 03:54:01 +0100468 default:
469 printf("unknown rsl message=0x%x\n", dh->c.msg_type);
470 }
471 return 0;
472}
473
474/* test cases */
475
476static char *test_case_0[] = {
477 "2",
478
479 "Stay in better cell\n\n"
480 "There are many neighbor cells, but only the current cell is the best\n"
481 "cell, so no handover is performed\n",
482
483 "create-bts", "7",
484 "create-ms", "0", "TCH/F", "AMR",
485 "meas-rep", "0", "30","0",
486 "6","0","20","1","21","2","18","3","20","4","23","5","19",
487 "expect-no-chan",
488 NULL
489};
490
491static char *test_case_1[] = {
492 "2",
493
494 "Handover to best better cell\n\n"
495 "The best neighbor cell is selected\n",
496
497 "create-bts", "7",
498 "create-ms", "0", "TCH/F", "AMR",
499 "meas-rep", "0", "10","0",
500 "6","0","20","1","21","2","18","3","20","4","23","5","19",
501 "expect-chan", "5", "1",
502 "ack-chan",
503 "expect-ho", "0", "1",
504 "ho-complete",
505 NULL
506};
507
508static char *test_case_2[] = {
509 "2",
510
511 "Handover and Assignment must be enabled\n\n"
512 "This test will start with disabled assignment and handover. A\n"
513 "better neighbor cell (assignment enabled) will not be selected and \n"
514 "also no assignment from TCH/H to TCH/F to improve quality. There\n"
515 "will be no handover nor assignment. After enabling assignment on the\n"
516 "current cell, the MS will assign to TCH/F. After enabling handover\n"
517 "in the current cell, but disabling in the neighbor cell, handover\n"
518 "will not be performed, until it is enabled in the neighbor cell too.\n",
519
520 "create-bts", "2",
521 "afs-rxlev-improve", "0", "5",
522 "create-ms", "0", "TCH/H", "AMR",
523 "as-enable", "0", "0",
524 "ho-enable", "0", "0",
525 "meas-rep", "0", "0","0", "1","0","30",
526 "expect-no-chan",
527 "as-enable", "0", "1",
528 "meas-rep", "0", "0","0", "1","0","30",
529 "expect-chan", "0", "1",
530 "ack-chan",
531 "expect-ho", "0", "5",
532 "ho-complete",
533 "ho-enable", "0", "1",
534 "ho-enable", "1", "0",
535 "meas-rep", "0", "0","0", "1","0","30",
536 "expect-no-chan",
537 "ho-enable", "1", "1",
538 "meas-rep", "0", "0","0", "1","0","30",
539 "expect-chan", "1", "1",
540 "ack-chan",
541 "expect-ho", "0", "1",
542 "ho-complete",
543 NULL
544};
545
546static char *test_case_3[] = {
547 "2",
548
549 "Penalty timer must not run\n\n"
550 "The MS will try to handover to a better cell, but this will fail.\n"
551 "Even though the cell is still better, handover will not be performed\n"
552 "due to penalty timer after handover failure\n",
553
554 "create-bts", "2",
555 "create-ms", "0", "TCH/F", "AMR",
556 "meas-rep", "0", "20","0", "1","0","30",
557 "expect-chan", "1", "1",
558 "ack-chan",
559 "expect-ho", "0", "1",
560 "ho-failed",
561 "meas-rep", "0", "20","0", "1","0","30",
562 "expect-no-chan",
563 NULL
564};
565
566static char *test_case_4[] = {
567 "2",
568
569 "TCH/H keeping with HR codec\n\n"
570 "The MS is using half rate V1 codec, but the better cell is congested\n"
571 "at TCH/H slots. As the congestion is removed, the handover takes\n"
572 "place.\n",
573
574 "create-bts", "2",
575 "set-min-free", "1", "TCH/H", "4",
576 "create-ms", "0", "TCH/H", "HR",
577 "meas-rep", "0", "20","0", "1","0","30",
578 "expect-no-chan",
579 "set-min-free", "1", "TCH/H", "3",
580 "meas-rep", "0", "20","0", "1","0","30",
581 "expect-chan", "1", "5",
582 "ack-chan",
583 "expect-ho", "0", "5",
584 "ho-complete",
585 NULL
586};
587
588static char *test_case_5[] = {
589 "2",
590
591 "TCH/F keeping with FR codec\n\n"
592 "The MS is using full rate V1 codec, but the better cell is congested\n"
593 "at TCH/F slots. As the congestion is removed, the handover takes\n"
594 "place.\n",
595
596 "create-bts", "2",
597 "set-min-free", "1", "TCH/F", "4",
598 "create-ms", "0", "TCH/F", "FR",
599 "meas-rep", "0", "20","0", "1","0","30",
600 "expect-no-chan",
601 "set-min-free", "1", "TCH/F", "3",
602 "meas-rep", "0", "20","0", "1","0","30",
603 "expect-chan", "1", "1",
604 "ack-chan",
605 "expect-ho", "0", "1",
606 "ho-complete",
607 NULL
608};
609
610static char *test_case_6[] = {
611 "2",
612
613 "TCH/F keeping with EFR codec\n\n"
614 "The MS is using full rate V2 codec, but the better cell is congested\n"
615 "at TCH/F slots. As the congestion is removed, the handover takes\n"
616 "place.\n",
617
618 "create-bts", "2",
619 "set-min-free", "1", "TCH/F", "4",
620 "create-ms", "0", "TCH/F", "EFR",
621 "meas-rep", "0", "20","0", "1","0","30",
622 "expect-no-chan",
623 "set-min-free", "1", "TCH/F", "3",
624 "meas-rep", "0", "20","0", "1","0","30",
625 "expect-chan", "1", "1",
626 "ack-chan",
627 "expect-ho", "0", "1",
628 "ho-complete",
629 NULL
630};
631
632static char *test_case_7[] = {
633 "2",
634
635 "TCH/F to TCH/H changing with AMR codec\n\n"
636 "The MS is using AMR V3 codec, the better cell is congested at TCH/F\n"
637 "slots. The handover is performed to non-congested TCH/H slots.\n",
638
639 "create-bts", "2",
640 "set-min-free", "1", "TCH/F", "4",
641 "create-ms", "0", "TCH/F", "AMR",
642 "meas-rep", "0", "20","0", "1","0","30",
643 "expect-chan", "1", "5",
644 "ack-chan",
645 "expect-ho", "0", "1",
646 "ho-complete",
647 NULL
648};
649
650static char *test_case_8[] = {
651 "2",
652
653 "No handover to a cell with no slots available\n\n"
654 "If no slot is available, no handover is performed\n",
655
656 "create-bts", "2",
657 "create-ms", "0", "TCH/F", "AMR",
658 "create-ms", "1", "TCH/F", "AMR",
659 "create-ms", "1", "TCH/F", "AMR",
660 "create-ms", "1", "TCH/F", "AMR",
661 "create-ms", "1", "TCH/F", "AMR",
662 "create-ms", "1", "TCH/H", "AMR",
663 "create-ms", "1", "TCH/H", "AMR",
664 "create-ms", "1", "TCH/H", "AMR",
665 "create-ms", "1", "TCH/H", "AMR",
666 "meas-rep", "0", "0","0", "1","0","30",
667 "expect-no-chan",
668 NULL
669};
670
671static char *test_case_9[] = {
672 "2",
673
674 "No more parallel handovers, if max_unsync_ho is defined\n\n"
675 "There are tree mobiles that want to handover, but only two can do\n"
676 "it at a time, because the maximum number is limited to two.\n",
677
678 "create-bts", "2",
679 "set-max-ho", "1", "2",
680 "create-ms", "0", "TCH/F", "AMR",
681 "create-ms", "0", "TCH/F", "AMR",
682 "create-ms", "0", "TCH/F", "AMR",
683 "meas-rep", "0", "0","0", "1","0","30",
684 "expect-chan", "1", "1",
685 "meas-rep", "1", "0","0", "1","0","30",
686 "expect-chan", "1", "2",
687 "meas-rep", "2", "0","0", "1","0","30",
688 "expect-no-chan",
689 NULL
690};
691
692static char *test_case_10[] = {
693 "2",
694
695 "Hysteresis\n\n"
696 "If neighbor cell is better, handover is only performed if the\n"
Martin Haukea29affd2019-11-13 22:10:41 +0100697 "amount of improvement is greater or equal hyteresis\n",
Neels Hofmeyr909e9722017-12-07 03:54:01 +0100698
699 "create-bts", "2",
700 "create-ms", "0", "TCH/F", "AMR",
701 "meas-rep", "0", "27","0", "1","0","30",
702 "expect-no-chan",
703 "meas-rep", "0", "26","0", "1","0","30",
704 "expect-chan", "1", "1",
705 "ack-chan",
706 "expect-ho", "0", "1",
707 "ho-complete",
708 NULL
709};
710
711static char *test_case_11[] = {
712 "2",
713
714 "No Hysteresis and minimum RX level\n\n"
715 "If current cell's RX level is below mimium level, handover must be\n"
716 "performed, no matter of the hysteresis. First do not perform\n"
717 "handover to better neighbor cell, because the hysteresis is not\n"
718 "met. Second do not perform handover because better neighbor cell is\n"
719 "below minimum RX level. Third perform handover because current cell\n"
720 "is below minimum RX level, even if the better neighbor cell (minimum\n"
721 "RX level reached) does not meet the hysteresis.\n",
722
723 "create-bts", "2",
724 "create-ms", "0", "TCH/F", "AMR",
725 "meas-rep", "0", "10","0", "1","0","11",
726 "expect-no-chan",
727 "meas-rep", "0", "8","0", "1","0","9",
728 "expect-no-chan",
729 "meas-rep", "0", "9","0", "1","0","10",
730 "expect-chan", "1", "1",
731 "ack-chan",
732 "expect-ho", "0", "1",
733 "ho-complete",
734 NULL
735};
736
737static char *test_case_12[] = {
738 "2",
739
740 "No handover to congested cell\n\n"
741 "The better neighbor cell is congested, so no handover is performed.\n"
742 "After the congestion is over, handover will be performed.\n",
743
744 "create-bts", "2",
745 "create-ms", "0", "TCH/F", "AMR",
746 "set-min-free", "1", "TCH/F", "4",
747 "set-min-free", "1", "TCH/H", "4",
748 "meas-rep", "0", "20","0", "1","0","30",
749 "expect-no-chan",
750 "set-min-free", "1", "TCH/F", "3",
751 "set-min-free", "1", "TCH/H", "3",
752 "meas-rep", "0", "20","0", "1","0","30",
753 "expect-chan", "1", "1",
754 "ack-chan",
755 "expect-ho", "0", "1",
756 "ho-complete",
757 NULL
758};
759
760static char *test_case_13[] = {
761 "2",
762
763 "Handover to balance congestion\n\n"
764 "The current and the better cell are congested, so no handover is\n"
765 "performed. This is because handover would congest the neighbor cell\n"
766 "more. After congestion raises in the current cell, the handover is\n"
767 "performed to balance congestion\n",
768
769 "create-bts", "2",
770 "create-ms", "0", "TCH/F", "AMR",
771 "set-min-free", "0", "TCH/F", "4",
772 "set-min-free", "0", "TCH/H", "4",
773 "set-min-free", "1", "TCH/F", "4",
774 "set-min-free", "1", "TCH/H", "4",
775 "meas-rep", "0", "20","0", "1","0","30",
776 "expect-no-chan",
777 "create-ms", "0", "TCH/F", "AMR",
778 "meas-rep", "0", "20","0", "1","0","30",
779 "expect-chan", "1", "1",
780 "ack-chan",
781 "expect-ho", "0", "1",
782 "ho-complete",
783 NULL
784};
785
786static char *test_case_14[] = {
787 "2",
788
789 "Handover to congested cell, if RX level is below minimum\n\n"
790 "The better neighbor cell is congested, so no handover is performed.\n"
791 "If the RX level of the current cell drops below minimum acceptable\n"
792 "level, the handover is performed.\n",
793
794 "create-bts", "2",
795 "create-ms", "0", "TCH/F", "AMR",
796 "set-min-free", "1", "TCH/F", "4",
797 "set-min-free", "1", "TCH/H", "4",
798 "meas-rep", "0", "10","0", "1","0","30",
799 "expect-no-chan",
800 "meas-rep", "0", "9","0", "1","0","30",
801 "expect-chan", "1", "1",
802 "ack-chan",
803 "expect-ho", "0", "1",
804 "ho-complete",
805 NULL
806};
807
808static char *test_case_15[] = {
809 "2",
810
811 "Handover to cell with worse RXLEV, if RXQUAL is below minimum\n\n"
812 "The neighbor cell has worse RXLEV, so no handover is performed.\n"
813 "If the RXQUAL of the current cell drops below minimum acceptable\n"
814 "level, the handover is performed. It is also required that 10\n"
815 "reports are received, before RXQUAL is checked.\n",
816 /* (See also test 28, which tests for RXQUAL triggering HO to congested cell.) */
817 /* TODO: bad RXQUAL may want to prefer assignment within the same cell to avoid interference.
Martin Haukea29affd2019-11-13 22:10:41 +0100818 * See Performance Enhancements in a Frequency Hopping GSM Network (Nielsen Wigard 2002), Chapter
Neels Hofmeyr909e9722017-12-07 03:54:01 +0100819 * 2.1.1, "Interference" in the list of triggers on p.157. */
820
821 "create-bts", "2",
822 "create-ms", "0", "TCH/F", "AMR",
823 "meas-rep", "0", "40","6", "1","0","30",
824 "expect-no-chan",
825 "meas-rep", "0", "40","6", "1","0","30",
826 "expect-no-chan",
827 "meas-rep", "0", "40","6", "1","0","30",
828 "expect-no-chan",
829 "meas-rep", "0", "40","6", "1","0","30",
830 "expect-no-chan",
831 "meas-rep", "0", "40","6", "1","0","30",
832 "expect-no-chan",
833 "meas-rep", "0", "40","6", "1","0","30",
834 "expect-no-chan",
835 "meas-rep", "0", "40","6", "1","0","30",
836 "expect-no-chan",
837 "meas-rep", "0", "40","6", "1","0","30",
838 "expect-no-chan",
839 "meas-rep", "0", "40","6", "1","0","30",
840 "expect-no-chan",
841 "meas-rep", "0", "40","6", "1","0","30",
842 "expect-chan", "1", "1",
843 "ack-chan",
844 "expect-ho", "0", "1",
845 "ho-complete",
846 NULL
847};
848
849static char *test_case_16[] = {
850 "2",
851
852 "Handover due to maximum TA exceeded\n\n"
853 "The MS in the current (best) cell has reached maximum allowed timing\n"
854 "advance. No handover is performed until the timing advance exceeds\n"
855 "it. The originating cell is still the best, but no handover is\n"
856 "performed back to that cell, because the penalty timer (due to\n"
857 "maximum allowed timing advance) is running.\n",
858
859 "create-bts", "2",
860 "create-ms", "0", "TCH/F", "AMR",
861 "set-max-ta", "0", "5", /* of cell */
862 "set-ta", "0", "5", /* of ms */
863 "meas-rep", "0", "30","0", "1","0","20",
864 "expect-no-chan",
865 "set-ta", "0", "6", /* of ms */
866 "meas-rep", "0", "30","0", "1","0","20",
867 "expect-chan", "1", "1",
868 "ack-chan",
869 "expect-ho", "0", "1",
870 "ho-complete",
871 "meas-rep", "0", "20","0", "1","0","30",
872 "expect-no-chan",
873 NULL
874};
875
876static char *test_case_17[] = {
877 "2",
878
879 "Congestion check: No congestion\n\n"
880 "Three cells have different number of used slots, but there is no\n"
881 "congestion in any of these cells. No handover is performed.\n",
882
883 "create-bts", "3",
884 "set-min-free", "0", "TCH/F", "2",
885 "set-min-free", "0", "TCH/H", "2",
886 "set-min-free", "1", "TCH/F", "2",
887 "set-min-free", "1", "TCH/H", "2",
888 "set-min-free", "2", "TCH/F", "2",
889 "set-min-free", "2", "TCH/H", "2",
890 "create-ms", "0", "TCH/F", "AMR",
891 "create-ms", "0", "TCH/F", "AMR",
892 "create-ms", "0", "TCH/H", "AMR",
893 "create-ms", "0", "TCH/H", "AMR",
894 "create-ms", "1", "TCH/F", "AMR",
895 "create-ms", "1", "TCH/H", "AMR",
896 "meas-rep", "0", "30","0", "2","0","20","1","20",
897 "expect-no-chan",
898 "meas-rep", "1", "30","0", "2","0","20","1","20",
899 "expect-no-chan",
900 "meas-rep", "2", "30","0", "2","0","20","1","20",
901 "expect-no-chan",
902 "meas-rep", "3", "30","0", "2","0","20","1","20",
903 "expect-no-chan",
904 "meas-rep", "4", "30","0", "2","0","20","1","20",
905 "expect-no-chan",
906 "meas-rep", "5", "30","0", "2","0","20","1","20",
907 "expect-no-chan",
908 "congestion-check",
909 "expect-no-chan",
910 NULL
911};
912
913static char *test_case_18[] = {
914 "2",
915
916 "Congestion check: One out of three cells is congested\n\n"
917 "Three cells have different number of used slots, but there is\n"
918 "congestion at TCH/F in the first cell. Handover is performed with\n"
919 "the best candidate.\n",
920
921 "create-bts", "3",
922 "set-min-free", "0", "TCH/F", "2",
923 "set-min-free", "0", "TCH/H", "2",
924 "set-min-free", "1", "TCH/F", "2",
925 "set-min-free", "1", "TCH/H", "2",
926 "set-min-free", "2", "TCH/F", "2",
927 "set-min-free", "2", "TCH/H", "2",
928 "create-ms", "0", "TCH/F", "AMR",
929 "create-ms", "0", "TCH/F", "AMR",
930 "create-ms", "0", "TCH/F", "AMR",
931 "create-ms", "0", "TCH/H", "AMR",
932 "create-ms", "0", "TCH/H", "AMR",
933 "create-ms", "1", "TCH/F", "AMR",
934 "create-ms", "1", "TCH/H", "AMR",
935 "meas-rep", "0", "30","0", "2","0","20","1","20",
936 "expect-no-chan",
937 "meas-rep", "1", "30","0", "2","0","20","1","20",
938 "expect-no-chan",
939 "meas-rep", "2", "30","0", "2","0","21","1","20",
940 "expect-no-chan",
941 "meas-rep", "3", "30","0", "2","0","20","1","20",
942 "expect-no-chan",
943 "meas-rep", "4", "30","0", "2","0","20","1","20",
944 "expect-no-chan",
945 "meas-rep", "5", "30","0", "2","0","20","1","20",
946 "expect-no-chan",
947 "meas-rep", "6", "30","0", "2","0","20","1","20",
948 "expect-no-chan",
949 "congestion-check",
950 "expect-chan", "1", "2",
951 "ack-chan",
Neels Hofmeyr72d64e72020-11-16 18:07:31 +0100952 "expect-ho", "0", "3", /* best candidate is MS 2 at BTS 0, TS 3 */
Neels Hofmeyr909e9722017-12-07 03:54:01 +0100953 "ho-complete",
954 NULL
955};
956
957static char *test_case_19[] = {
958 "2",
959
960 "Congestion check: Balancing over congested cells\n\n"
Neels Hofmeyr1336d942020-08-10 21:13:55 +0200961 "Two cells are congested, but the second cell is less congested.\n"
Neels Hofmeyr909e9722017-12-07 03:54:01 +0100962 "Handover is performed to solve the congestion.\n",
963
964 "create-bts", "2",
965 "set-min-free", "0", "TCH/F", "4",
966 "set-min-free", "1", "TCH/F", "4",
967 "create-ms", "0", "TCH/F", "FR",
968 "create-ms", "0", "TCH/F", "FR",
969 "create-ms", "0", "TCH/F", "FR",
970 "create-ms", "1", "TCH/F", "FR",
971 "meas-rep", "0", "30","0", "1","0","20",
972 "expect-no-chan",
973 "meas-rep", "1", "30","0", "1","0","21",
974 "expect-no-chan",
975 "meas-rep", "2", "30","0", "1","0","20",
976 "expect-no-chan",
977 "meas-rep", "3", "30","0", "1","0","20",
978 "expect-no-chan",
979 "congestion-check",
980 "expect-chan", "1", "2",
981 "ack-chan",
982 "expect-ho", "0", "2", /* best candidate is MS 1 at BTS 0, TS 2 */
983 "ho-complete",
984 NULL
985};
986
987static char *test_case_20[] = {
988 "2",
989
990 "Congestion check: Solving congestion by handover TCH/F -> TCH/H\n\n"
991 "Two BTS, one MS in the first congested BTS must handover to\n"
992 "non-congested TCH/H of second BTS, in order to solve congestion\n",
993 "create-bts", "2",
994 "set-min-free", "0", "TCH/F", "4",
995 "set-min-free", "0", "TCH/H", "4",
996 "set-min-free", "1", "TCH/F", "4",
997 "create-ms", "0", "TCH/F", "AMR",
998 "meas-rep", "0", "30","0", "1","0","30",
999 "expect-no-chan",
1000 "congestion-check",
1001 "expect-chan", "1", "5",
1002 "ack-chan",
1003 "expect-ho", "0", "1",
1004 "ho-complete",
1005 NULL
1006};
1007
1008static char *test_case_21[] = {
1009 "2",
1010
1011 "Congestion check: Balancing congestion by handover TCH/F -> TCH/H\n\n"
1012 "Two BTS, one MS in the first congested BTS must handover to\n"
1013 "less-congested TCH/H of second BTS, in order to balance congestion\n",
1014 "create-bts", "2",
1015 "set-min-free", "0", "TCH/F", "4",
1016 "set-min-free", "0", "TCH/H", "4",
1017 "set-min-free", "1", "TCH/F", "4",
1018 "set-min-free", "1", "TCH/H", "4",
1019 "create-ms", "0", "TCH/F", "AMR",
1020 "create-ms", "0", "TCH/F", "AMR",
1021 "create-ms", "0", "TCH/H", "AMR",
1022 "meas-rep", "0", "30","0", "1","0","30",
1023 "expect-no-chan",
1024 "congestion-check",
1025 "expect-chan", "1", "1",
1026 "ack-chan",
1027 "expect-ho", "0", "1",
1028 "ho-complete",
1029 NULL
1030};
1031
1032static char *test_case_22[] = {
1033 "2",
1034
1035 "Congestion check: Upgrading worst candidate from TCH/H -> TCH/F\n\n"
1036 "There is only one BTS. The TCH/H slots are congested. Since\n"
1037 "assignment is performed to less-congested TCH/F, the candidate with\n"
1038 "the worst RX level is chosen.\n",
1039
1040 "create-bts", "1",
1041 "set-min-free", "0", "TCH/F", "4",
1042 "set-min-free", "0", "TCH/H", "4",
1043 "create-ms", "0", "TCH/H", "AMR",
1044 "create-ms", "0", "TCH/H", "AMR",
1045 "create-ms", "0", "TCH/H", "AMR",
1046 "meas-rep", "0", "30","0", "0",
1047 "meas-rep", "1", "34","0", "0",
1048 "meas-rep", "2", "20","0", "0",
1049 "expect-no-chan",
1050 "congestion-check",
1051 "expect-chan", "0", "1",
1052 "ack-chan",
1053 "expect-ho", "0", "6",
1054 "ho-complete",
1055 NULL
1056};
1057
1058static char *test_case_23[] = {
1059 "2",
1060
1061 "Story: 'A neighbor is your friend'\n",
1062
1063 "create-bts", "3",
1064
1065 "print",
1066 "Andreas is driving along the coast, on a sunny june afternoon.\n"
1067 "Suddenly he is getting a call from his friend and neighbor Axel.\n"
1068 "\n"
1069 "What happens: Two MS are created, #0 for Axel, #1 for Andreas.",
1070 /* Axel */
1071 "create-ms", "2", "TCH/F", "AMR",
1072 /* andreas */
1073 "create-ms", "0", "TCH/F", "AMR",
1074 "meas-rep", "1", "40","0", "1","0","30",
1075 "expect-no-chan",
1076
1077 "print",
1078 "Axel asks Andreas if he would like to join them for a barbecue.\n"
1079 "Axel's house is right in the neighborhood and the weather is fine.\n"
1080 "Andreas agrees, so he drives to a close store to buy some barbecue\n"
1081 "skewers.\n"
1082 "\n"
1083 "What happens: While driving, a different cell (mounted atop the\n"
1084 "store) becomes better.",
1085 /* drive to bts 1 */
1086 "meas-rep", "1", "20","0", "1","0","35",
1087 "expect-chan", "1", "1",
1088 "ack-chan",
1089 "expect-ho", "0", "1",
1090 "ho-complete",
1091
1092 "print",
1093 "While Andreas is walking into the store, Axel asks, if he could also\n"
1094 "bring some beer. Andreas has problems understanding him: \"I have a\n"
1095 "bad reception here. The cell tower is right atop the store, but poor\n"
1096 "coverage inside. Can you repeat please?\"\n"
1097 "\n"
1098 "What happens: Inside the store the close cell is so bad, that\n"
1099 "handover back to the previous cell is required.",
1100 /* bts 1 becomes bad, so bts 0 helps out */
1101 "meas-rep", "1", "5","0", "1","0","20",
1102 "expect-chan", "0", "1",
1103 "ack-chan",
1104 "expect-ho", "1", "1",
1105 "ho-complete",
1106
1107 "print",
1108 "After Andreas bought skewers and beer, he leaves the store.\n"
1109 "\n"
1110 "What happens: Outside the store the close cell is better again, so\n"
1111 "handover back to the that cell is performed.",
1112 /* bts 1 becomes better again */
1113 "meas-rep", "1", "20","0", "1","0","35",
1114 "expect-chan", "1", "1",
1115 "ack-chan",
1116 "expect-ho", "0", "1",
1117 "ho-complete",
1118
1119 "print",
1120 /* bts 2 becomes better */
1121 "Andreas drives down to the lake where Axel's house is.\n"
1122 "\n"
1123 "What happens: There is a small cell at Axel's house, which becomes\n"
1124 "better, because the current cell has no good comverage at the lake.",
1125 "meas-rep", "1", "14","0", "2","0","2","1","63",
1126 "expect-chan", "2", "2",
1127 "ack-chan",
1128 "expect-ho", "1", "1",
1129 "ho-complete",
1130
1131 "print",
1132 "Andreas wonders why he still has good radio coverage: \"Last time it\n"
1133 "was so bad\". Axel says: \"I installed a pico cell in my house,\n"
1134 "now we can use our mobile phones down here at the lake.\"",
1135
1136 NULL
1137};
1138
1139static char *test_case_24[] = {
1140 "2",
1141 "No (or not enough) measurements for handover\n\n"
1142 "Do not solve congestion in cell, because there is no measurement.\n"
Martin Haukea29affd2019-11-13 22:10:41 +01001143 "As soon as enough measurements available (1 in our case), perform\n"
Neels Hofmeyr909e9722017-12-07 03:54:01 +01001144 "handover. Afterwards the old cell becomes congested and the new\n"
1145 "cell is not. Do not perform handover until new measurements are\n"
1146 "received.\n",
1147
1148 /* two cells, first in congested, but no handover */
1149 "create-bts", "2",
1150 "set-min-free", "0", "TCH/F", "4",
1151 "set-min-free", "0", "TCH/H", "4",
1152 "create-ms", "0", "TCH/F", "AMR",
1153 "congestion-check",
1154 "expect-no-chan",
1155
1156 /* send measurement and trigger congestion check */
1157 "meas-rep", "0", "20","0", "1","0","20",
1158 "expect-no-chan",
1159 "congestion-check",
1160 "expect-chan", "1", "1",
1161 "ack-chan",
1162 "expect-ho", "0", "1",
1163 "ho-complete",
1164
1165 /* congest the first cell and remove congestion from second cell */
1166 "set-min-free", "0", "TCH/F", "0",
1167 "set-min-free", "0", "TCH/H", "0",
1168 "set-min-free", "1", "TCH/F", "4",
1169 "set-min-free", "1", "TCH/H", "4",
1170
1171 /* no handover until measurements applied */
1172 "congestion-check",
1173 "expect-no-chan",
1174 "meas-rep", "0", "20","0", "1","0","20",
1175 "expect-no-chan",
1176 "congestion-check",
1177 "expect-chan", "0", "1",
1178 "ack-chan",
1179 "expect-ho", "1", "1",
1180 "ho-complete",
1181 NULL
1182};
1183
1184static char *test_case_25[] = {
1185 "1",
1186
1187 "Stay in better cell\n\n"
1188 "There are many neighbor cells, but only the current cell is the best\n"
1189 "cell, so no handover is performed\n",
1190
1191 "create-bts", "7",
1192 "create-ms", "0", "TCH/F", "AMR",
1193 "meas-rep", "0", "30","0",
1194 "6","0","20","1","21","2","18","3","20","4","23","5","19",
1195 "expect-no-chan",
1196 NULL
1197};
1198
1199static char *test_case_26[] = {
1200 "1",
1201
1202 "Handover to best better cell\n\n"
1203 "The best neighbor cell is selected\n",
1204
1205 "create-bts", "7",
1206 "create-ms", "0", "TCH/F", "AMR",
1207 "meas-rep", "0", "10","0",
1208 "6","0","20","1","21","2","18","3","20","4","23","5","19",
1209 "expect-chan", "5", "1",
1210 "ack-chan",
1211 "expect-ho", "0", "1",
1212 "ho-complete",
1213 NULL
1214};
1215
1216static char *test_case_27[] = {
1217 "2",
1218
1219 "Congestion check: Upgrading worst candidate from TCH/H -> TCH/F\n\n"
1220 "There is only one BTS. The TCH/H slots are congested. Since\n"
1221 "assignment is performed to less-congested TCH/F, the candidate with\n"
1222 "the worst RX level is chosen. (So far like test 22.)\n"
1223 "After that, trigger more congestion checks to ensure stability.\n",
1224
1225 "create-bts", "1",
1226 "set-min-free", "0", "TCH/F", "2",
1227 "set-min-free", "0", "TCH/H", "4",
1228 "create-ms", "0", "TCH/H", "AMR",
1229 "create-ms", "0", "TCH/H", "AMR",
1230 "create-ms", "0", "TCH/H", "AMR",
1231 "meas-rep", "0", "30","0", "0",
1232 "meas-rep", "1", "34","0", "0",
1233 "meas-rep", "2", "20","0", "0",
1234 "expect-no-chan",
1235 "congestion-check",
1236 "expect-chan", "0", "1",
1237 "ack-chan",
1238 "expect-ho", "0", "6",
1239 "ho-complete",
1240 "congestion-check",
1241 "expect-chan", "0", "2",
1242 "ack-chan",
1243 "expect-ho", "0", "5",
1244 "ho-complete",
1245 "congestion-check",
1246 "expect-no-chan",
1247 "congestion-check",
1248 "expect-no-chan",
1249 NULL
1250};
1251
1252static char *test_case_28[] = {
1253 "2",
1254
1255 "Handover to congested cell, if RX quality is below minimum\n\n"
1256 "The better neighbor cell is congested, so no handover is performed.\n"
1257 "If the RX quality of the current cell drops below minimum acceptable\n"
1258 "level, the handover is performed. It is also required that 10\n"
1259 "resports are received, before RX quality is checked.\n",
1260
1261 "create-bts", "2",
1262 "create-ms", "0", "TCH/F", "AMR",
1263 "set-min-free", "1", "TCH/F", "4",
1264 "set-min-free", "1", "TCH/H", "4",
1265 "meas-rep", "0", "30","6", "1","0","40",
1266 "expect-no-chan",
1267 "meas-rep", "0", "30","6", "1","0","40",
1268 "expect-no-chan",
1269 "meas-rep", "0", "30","6", "1","0","40",
1270 "expect-no-chan",
1271 "meas-rep", "0", "30","6", "1","0","40",
1272 "expect-no-chan",
1273 "meas-rep", "0", "30","6", "1","0","40",
1274 "expect-no-chan",
1275 "meas-rep", "0", "30","6", "1","0","40",
1276 "expect-no-chan",
1277 "meas-rep", "0", "30","6", "1","0","40",
1278 "expect-no-chan",
1279 "meas-rep", "0", "30","6", "1","0","40",
1280 "expect-no-chan",
1281 "meas-rep", "0", "30","6", "1","0","40",
1282 "expect-no-chan",
1283 "meas-rep", "0", "30","6", "1","0","40",
1284 "expect-chan", "1", "1",
1285 "ack-chan",
1286 "expect-ho", "0", "1",
1287 "ho-complete",
1288 NULL
1289};
1290
Neels Hofmeyr7b2b4302020-08-02 02:50:17 +02001291static char *test_case_29[] = {
1292 "2",
1293
1294 "Congestion check: Balancing congestion by handover TCH/F -> TCH/H\n\n"
1295 "One BTS, and TCH/F are considered congested, TCH/H are not.\n"
1296 ,
1297 "create-bts", "1",
1298 "set-min-free", "0", "TCH/F", "3",
1299 "set-min-free", "0", "TCH/H", "0",
1300 "create-ms", "0", "TCH/F", "AMR",
1301 "create-ms", "0", "TCH/F", "AMR",
1302 "create-ms", "0", "TCH/H", "AMR",
1303 "meas-rep", "0", "30","0", "1","0","30",
1304 "expect-no-chan",
1305 "congestion-check",
1306 "expect-chan", "0", "5",
1307 "ack-chan",
1308 "expect-ho", "0", "1",
1309 "ho-complete",
1310 NULL
1311};
1312
1313
Neels Hofmeyr909e9722017-12-07 03:54:01 +01001314static char **test_cases[] = {
1315 test_case_0,
1316 test_case_1,
1317 test_case_2,
1318 test_case_3,
1319 test_case_4,
1320 test_case_5,
1321 test_case_6,
1322 test_case_7,
1323 test_case_8,
1324 test_case_9,
1325 test_case_10,
1326 test_case_11,
1327 test_case_12,
1328 test_case_13,
1329 test_case_14,
1330 test_case_15,
1331 test_case_16,
1332 test_case_17,
1333 test_case_18,
1334 test_case_19,
1335 test_case_20,
1336 test_case_21,
1337 test_case_22,
1338 test_case_23,
1339 test_case_24,
1340 test_case_25,
1341 test_case_26,
1342 test_case_27,
1343 test_case_28,
Neels Hofmeyr7b2b4302020-08-02 02:50:17 +02001344 test_case_29,
Neels Hofmeyr909e9722017-12-07 03:54:01 +01001345};
1346
1347static const struct log_info_cat log_categories[] = {
1348 [DHO] = {
1349 .name = "DHO",
1350 .description = "Hand-Over Process",
1351 .color = "\033[1;38m",
1352 .enabled = 1, .loglevel = LOGL_DEBUG,
1353 },
1354 [DHODEC] = {
1355 .name = "DHODEC",
1356 .description = "Hand-Over Decision",
1357 .color = "\033[1;38m",
1358 .enabled = 1, .loglevel = LOGL_DEBUG,
1359 },
1360 [DMEAS] = {
1361 .name = "DMEAS",
1362 .description = "Radio Measurement Processing",
1363 .enabled = 1, .loglevel = LOGL_DEBUG,
1364 },
1365 [DREF] = {
1366 .name = "DREF",
1367 .description = "Reference Counting",
1368 .enabled = 1, .loglevel = LOGL_DEBUG,
1369 },
1370 [DRSL] = {
1371 .name = "DRSL",
Keithd925c7c2018-04-16 13:40:07 +02001372 .description = "A-bis Radio Signalling Link (RSL)",
Neels Hofmeyr909e9722017-12-07 03:54:01 +01001373 .color = "\033[1;35m",
1374 .enabled = 1, .loglevel = LOGL_DEBUG,
1375 },
Neels Hofmeyr31f525e2018-05-14 18:14:15 +02001376 [DRR] = {
1377 .name = "DRR",
1378 .description = "RR",
1379 .color = "\033[1;35m",
1380 .enabled = 1, .loglevel = LOGL_DEBUG,
1381 },
1382 [DRLL] = {
1383 .name = "DRLL",
1384 .description = "RLL",
1385 .color = "\033[1;35m",
1386 .enabled = 1, .loglevel = LOGL_DEBUG,
1387 },
Harald Welte3561bd42018-01-28 03:04:16 +01001388 [DMSC] = {
1389 .name = "DMSC",
1390 .description = "Mobile Switching Center",
1391 .enabled = 1, .loglevel = LOGL_DEBUG,
1392 },
Neels Hofmeyr3c5612f2018-07-11 19:53:39 +02001393 [DCHAN] = {
1394 .name = "DCHAN",
1395 .description = "lchan FSM",
1396 .color = "\033[1;32m",
1397 .enabled = 1, .loglevel = LOGL_DEBUG,
1398 },
1399 [DTS] = {
1400 .name = "DTS",
1401 .description = "timeslot FSM",
1402 .color = "\033[1;31m",
1403 .enabled = 1, .loglevel = LOGL_DEBUG,
1404 },
1405 [DAS] = {
1406 .name = "DAS",
1407 .description = "assignment FSM",
1408 .color = "\033[1;33m",
1409 .enabled = 1, .loglevel = LOGL_DEBUG,
1410 },
Neels Hofmeyr909e9722017-12-07 03:54:01 +01001411};
1412
1413const struct log_info log_info = {
1414 .cat = log_categories,
1415 .num_cat = ARRAY_SIZE(log_categories),
1416};
1417
1418int main(int argc, char **argv)
1419{
1420 char **test_case;
1421 struct gsm_bts *bts[256];
1422 int bts_num = 0;
1423 struct gsm_lchan *lchan[256];
1424 int lchan_num = 0;
Neels Hofmeyr909e9722017-12-07 03:54:01 +01001425 int i;
Neels Hofmeyr958f2592018-05-27 01:26:31 +02001426 int algorithm;
Neels Hofmeyr00727552018-02-21 14:33:15 +01001427 int test_case_i;
1428 int last_test_i;
Neels Hofmeyr909e9722017-12-07 03:54:01 +01001429
Neels Hofmeyre3416182018-03-05 05:31:14 +01001430 ctx = talloc_named_const(NULL, 0, "handover_test");
1431 msgb_talloc_ctx_init(ctx, 0);
1432
Neels Hofmeyr00727552018-02-21 14:33:15 +01001433 test_case_i = argc > 1? atoi(argv[1]) : -1;
1434 last_test_i = ARRAY_SIZE(test_cases) - 1;
Neels Hofmeyr909e9722017-12-07 03:54:01 +01001435
Neels Hofmeyr00727552018-02-21 14:33:15 +01001436 if (test_case_i < 0 || test_case_i > last_test_i) {
1437 for (i = 0; i <= last_test_i; i++) {
Neels Hofmeyr909e9722017-12-07 03:54:01 +01001438 printf("Test #%d (algorithm %s):\n%s\n", i,
1439 test_cases[i][0], test_cases[i][1]);
1440 }
Neels Hofmeyr00727552018-02-21 14:33:15 +01001441 printf("\nPlease specify test case number 0..%d\n", last_test_i);
Neels Hofmeyr909e9722017-12-07 03:54:01 +01001442 return EXIT_FAILURE;
1443 }
1444
Neels Hofmeyre3416182018-03-05 05:31:14 +01001445 osmo_init_logging2(ctx, &log_info);
Neels Hofmeyr909e9722017-12-07 03:54:01 +01001446
1447 log_set_print_category(osmo_stderr_target, 1);
1448 log_set_print_category_hex(osmo_stderr_target, 0);
1449 log_set_print_filename2(osmo_stderr_target, LOG_FILENAME_BASENAME);
Neels Hofmeyr31f525e2018-05-14 18:14:15 +02001450 osmo_fsm_log_addr(false);
Neels Hofmeyr909e9722017-12-07 03:54:01 +01001451
Neels Hofmeyr958f2592018-05-27 01:26:31 +02001452 bsc_network_alloc();
Neels Hofmeyr909e9722017-12-07 03:54:01 +01001453 if (!bsc_gsmnet)
1454 exit(1);
1455
Neels Hofmeyr31f525e2018-05-14 18:14:15 +02001456 ts_fsm_init();
1457 lchan_fsm_init();
Neels Hofmeyr31f525e2018-05-14 18:14:15 +02001458 bsc_subscr_conn_fsm_init();
1459 handover_fsm_init();
1460
Neels Hofmeyr909e9722017-12-07 03:54:01 +01001461 ho_set_algorithm(bsc_gsmnet->ho, 2);
1462 ho_set_ho_active(bsc_gsmnet->ho, true);
1463 ho_set_hodec2_as_active(bsc_gsmnet->ho, true);
1464 ho_set_hodec2_min_rxlev(bsc_gsmnet->ho, -100);
1465 ho_set_hodec2_rxlev_avg_win(bsc_gsmnet->ho, 1);
1466 ho_set_hodec2_rxlev_neigh_avg_win(bsc_gsmnet->ho, 1);
1467 ho_set_hodec2_rxqual_avg_win(bsc_gsmnet->ho, 10);
1468 ho_set_hodec2_pwr_hysteresis(bsc_gsmnet->ho, 3);
1469 ho_set_hodec2_pwr_interval(bsc_gsmnet->ho, 1);
1470 ho_set_hodec2_afs_bias_rxlev(bsc_gsmnet->ho, 0);
1471 ho_set_hodec2_min_rxqual(bsc_gsmnet->ho, 5);
1472 ho_set_hodec2_afs_bias_rxqual(bsc_gsmnet->ho, 0);
1473 ho_set_hodec2_max_distance(bsc_gsmnet->ho, 9999);
1474 ho_set_hodec2_ho_max(bsc_gsmnet->ho, 9999);
1475 ho_set_hodec2_penalty_max_dist(bsc_gsmnet->ho, 300);
1476 ho_set_hodec2_penalty_failed_ho(bsc_gsmnet->ho, 60);
1477 ho_set_hodec2_penalty_failed_as(bsc_gsmnet->ho, 60);
1478
Vadim Yanitskiy4f3a6412020-05-31 01:56:20 +07001479 /* We don't really need any specific model here */
1480 bts_model_unknown_init();
Neels Hofmeyr909e9722017-12-07 03:54:01 +01001481
Neels Hofmeyr00727552018-02-21 14:33:15 +01001482 test_case = test_cases[test_case_i];
Neels Hofmeyr909e9722017-12-07 03:54:01 +01001483
1484 fprintf(stderr, "--------------------\n");
1485 fprintf(stderr, "Performing the following test %d (algorithm %s):\n%s",
Neels Hofmeyr00727552018-02-21 14:33:15 +01001486 test_case_i, test_case[0], test_case[1]);
Neels Hofmeyr909e9722017-12-07 03:54:01 +01001487 algorithm = atoi(test_case[0]);
1488 test_case += 2;
1489 fprintf(stderr, "--------------------\n");
1490
1491 /* Disable the congestion check timer, we will trigger manually. */
1492 bsc_gsmnet->hodec2.congestion_check_interval_s = 0;
1493
1494 handover_decision_1_init();
1495 hodec2_init(bsc_gsmnet);
1496
1497 while (*test_case) {
1498 if (!strcmp(*test_case, "create-bts")) {
Neels Hofmeyr909e9722017-12-07 03:54:01 +01001499 int n = atoi(test_case[1]);
1500 fprintf(stderr, "- Creating %d BTS (one TRX each, "
1501 "TS(1-4) are TCH/F, TS(5-6) are TCH/H)\n", n);
1502 for (i = 0; i < n; i++)
Neels Hofmeyr2f58de52020-11-12 22:51:11 +01001503 bts[bts_num + i] = create_bts();
Neels Hofmeyr00727552018-02-21 14:33:15 +01001504 for (i = 0; i < n; i++) {
Neels Hofmeyr31f525e2018-05-14 18:14:15 +02001505 if (gsm_generate_si(bts[bts_num + i], SYSINFO_TYPE_2) <= 0)
Neels Hofmeyr00727552018-02-21 14:33:15 +01001506 fprintf(stderr, "Error generating SI2\n");
1507 }
Neels Hofmeyr909e9722017-12-07 03:54:01 +01001508 bts_num += n;
1509 test_case += 2;
1510 } else
1511 if (!strcmp(*test_case, "as-enable")) {
1512 fprintf(stderr, "- Set assignment enable state at "
1513 "BTS %s to %s\n", test_case[1], test_case[2]);
1514 ho_set_hodec2_as_active(bts[atoi(test_case[1])]->ho, atoi(test_case[2]));
1515 test_case += 3;
1516 } else
1517 if (!strcmp(*test_case, "ho-enable")) {
1518 fprintf(stderr, "- Set handover enable state at "
1519 "BTS %s to %s\n", test_case[1], test_case[2]);
1520 ho_set_ho_active(bts[atoi(test_case[1])]->ho, atoi(test_case[2]));
1521 test_case += 3;
1522 } else
1523 if (!strcmp(*test_case, "afs-rxlev-improve")) {
1524 fprintf(stderr, "- Set afs RX level improvement at "
1525 "BTS %s to %s\n", test_case[1], test_case[2]);
1526 ho_set_hodec2_afs_bias_rxlev(bts[atoi(test_case[1])]->ho, atoi(test_case[2]));
1527 test_case += 3;
1528 } else
1529 if (!strcmp(*test_case, "afs-rxqual-improve")) {
1530 fprintf(stderr, "- Set afs RX quality improvement at "
1531 "BTS %s to %s\n", test_case[1], test_case[2]);
1532 ho_set_hodec2_afs_bias_rxqual(bts[atoi(test_case[1])]->ho, atoi(test_case[2]));
1533 test_case += 3;
1534 } else
1535 if (!strcmp(*test_case, "set-min-free")) {
1536 fprintf(stderr, "- Setting minimum required free %s "
1537 "slots at BTS %s to %s\n", test_case[2],
1538 test_case[1], test_case[3]);
1539 if (!strcmp(test_case[2], "TCH/F"))
1540 ho_set_hodec2_tchf_min_slots(bts[atoi(test_case[1])]->ho, atoi(test_case[3]));
1541 else
1542 ho_set_hodec2_tchh_min_slots(bts[atoi(test_case[1])]->ho, atoi(test_case[3]));
1543 test_case += 4;
1544 } else
1545 if (!strcmp(*test_case, "set-max-ho")) {
1546 fprintf(stderr, "- Setting maximum parallel handovers "
1547 "at BTS %s to %s\n", test_case[1],
1548 test_case[2]);
1549 ho_set_hodec2_ho_max( bts[atoi(test_case[1])]->ho, atoi(test_case[2]));
1550 test_case += 3;
1551 } else
1552 if (!strcmp(*test_case, "set-max-ta")) {
1553 fprintf(stderr, "- Setting maximum timing advance "
1554 "at BTS %s to %s\n", test_case[1],
1555 test_case[2]);
1556 ho_set_hodec2_max_distance(bts[atoi(test_case[1])]->ho, atoi(test_case[2]));
1557 test_case += 3;
1558 } else
1559 if (!strcmp(*test_case, "create-ms")) {
1560 fprintf(stderr, "- Creating mobile #%d at BTS %s on "
1561 "%s with %s codec\n", lchan_num, test_case[1],
1562 test_case[2], test_case[3]);
1563 lchan[lchan_num] = create_lchan(bts[atoi(test_case[1])],
1564 !strcmp(test_case[2], "TCH/F"), test_case[3]);
1565 if (!lchan[lchan_num]) {
1566 printf("Failed to create lchan!\n");
1567 return EXIT_FAILURE;
1568 }
1569 fprintf(stderr, " * New MS is at BTS %d TS %d\n",
1570 lchan[lchan_num]->ts->trx->bts->nr,
1571 lchan[lchan_num]->ts->nr);
1572 lchan_num++;
1573 test_case += 4;
1574 } else
1575 if (!strcmp(*test_case, "set-ta")) {
1576 fprintf(stderr, "- Setting maximum timing advance "
1577 "at MS %s to %s\n", test_case[1],
1578 test_case[2]);
1579 meas_ta_ms = atoi(test_case[2]);
1580 test_case += 3;
1581 } else
1582 if (!strcmp(*test_case, "meas-rep")) {
1583 /* meas-rep <lchan-nr> <rxlev> <rxqual> <nr-of-neighbors> [<cell-idx> <rxlev> [...]] */
1584 int n = atoi(test_case[4]);
1585 struct gsm_lchan *lc = lchan[atoi(test_case[1])];
1586 fprintf(stderr, "- Sending measurement report from "
1587 "mobile #%s (rxlev=%s, rxqual=%s)\n",
1588 test_case[1], test_case[2], test_case[3]);
1589 meas_dl_rxlev = atoi(test_case[2]);
1590 meas_dl_rxqual = atoi(test_case[3]);
1591 meas_num_nc = n;
1592 test_case += 5;
1593 for (i = 0; i < n; i++) {
1594 int nr = atoi(test_case[0]);
1595 /* since our bts is not in the list of neighbor
1596 * cells, we need to shift */
1597 if (nr >= lc->ts->trx->bts->nr)
1598 nr++;
1599 fprintf(stderr, " * Neighbor cell #%s, actual "
1600 "BTS %d (rxlev=%s)\n", test_case[0], nr,
1601 test_case[1]);
1602 meas_bcch_f_nc[i] = atoi(test_case[0]);
1603 /* bts number, not counting our own */
1604 meas_rxlev_nc[i] = atoi(test_case[1]);
1605 meas_bsic_nc[i] = 0x3f;
1606 test_case += 2;
1607 }
1608 got_chan_req = 0;
1609 gen_meas_rep(lc);
1610 } else
1611 if (!strcmp(*test_case, "congestion-check")) {
1612 fprintf(stderr, "- Triggering congestion check\n");
1613 got_chan_req = 0;
1614 if (algorithm == 2)
1615 hodec2_congestion_check(bsc_gsmnet);
1616 test_case += 1;
1617 } else
1618 if (!strcmp(*test_case, "expect-chan")) {
1619 fprintf(stderr, "- Expecting channel request at BTS %s "
1620 "TS %s\n", test_case[1], test_case[2]);
1621 if (!got_chan_req) {
1622 printf("Test failed, because no channel was "
1623 "requested\n");
1624 return EXIT_FAILURE;
1625 }
1626 fprintf(stderr, " * Got channel request at BTS %d "
1627 "TS %d\n", chan_req_lchan->ts->trx->bts->nr,
1628 chan_req_lchan->ts->nr);
1629 if (chan_req_lchan->ts->trx->bts->nr
1630 != atoi(test_case[1])) {
1631 printf("Test failed, because channel was not "
1632 "requested on expected BTS\n");
1633 return EXIT_FAILURE;
1634 }
1635 if (chan_req_lchan->ts->nr != atoi(test_case[2])) {
1636 printf("Test failed, because channel was not "
1637 "requested on expected TS\n");
1638 return EXIT_FAILURE;
1639 }
1640 test_case += 3;
1641 } else
1642 if (!strcmp(*test_case, "expect-no-chan")) {
1643 fprintf(stderr, "- Expecting no channel request\n");
1644 if (got_chan_req) {
1645 fprintf(stderr, " * Got channel request at "
1646 "BTS %d TS %d\n",
1647 chan_req_lchan->ts->trx->bts->nr,
1648 chan_req_lchan->ts->nr);
1649 printf("Test failed, because channel was "
1650 "requested\n");
1651 return EXIT_FAILURE;
1652 }
1653 fprintf(stderr, " * Got no channel request\n");
1654 test_case += 1;
1655 } else
1656 if (!strcmp(*test_case, "expect-ho")) {
1657 fprintf(stderr, "- Expecting handover/assignment "
1658 "request at BTS %s TS %s\n", test_case[1],
1659 test_case[2]);
1660 if (!got_ho_req) {
1661 printf("Test failed, because no handover was "
1662 "requested\n");
1663 return EXIT_FAILURE;
1664 }
1665 fprintf(stderr, " * Got handover/assignment request at "
1666 "BTS %d TS %d\n",
1667 ho_req_lchan->ts->trx->bts->nr,
1668 ho_req_lchan->ts->nr);
1669 if (ho_req_lchan->ts->trx->bts->nr
1670 != atoi(test_case[1])) {
1671 printf("Test failed, because "
1672 "handover/assignment was not commanded "
1673 "at the expected BTS\n");
1674 return EXIT_FAILURE;
1675 }
1676 if (ho_req_lchan->ts->nr != atoi(test_case[2])) {
1677 printf("Test failed, because "
1678 "handover/assignment was not commanded "
1679 "at the expected TS\n");
1680 return EXIT_FAILURE;
1681 }
1682 test_case += 3;
1683 } else
1684 if (!strcmp(*test_case, "ack-chan")) {
1685 fprintf(stderr, "- Acknowledging channel request\n");
1686 if (!got_chan_req) {
1687 printf("Cannot ack channel, because no "
1688 "request\n");
1689 return EXIT_FAILURE;
1690 }
1691 test_case += 1;
1692 got_ho_req = 0;
1693 send_chan_act_ack(chan_req_lchan, 1);
1694 } else
1695 if (!strcmp(*test_case, "ho-complete")) {
1696 fprintf(stderr, "- Acknowledging handover/assignment "
1697 "request\n");
1698 if (!got_chan_req) {
1699 printf("Cannot ack handover/assignment, "
1700 "because no chan request\n");
1701 return EXIT_FAILURE;
1702 }
1703 if (!got_ho_req) {
1704 printf("Cannot ack handover/assignment, "
1705 "because no ho request\n");
1706 return EXIT_FAILURE;
1707 }
1708 test_case += 1;
1709 got_chan_req = 0;
1710 got_ho_req = 0;
1711 /* switch lchan */
1712 for (i = 0; i < lchan_num; i++) {
1713 if (lchan[i] == ho_req_lchan) {
1714 fprintf(stderr, " * MS %d changes from "
1715 "BTS=%d TS=%d to BTS=%d "
1716 "TS=%d\n", i,
1717 lchan[i]->ts->trx->bts->nr,
1718 lchan[i]->ts->nr,
1719 chan_req_lchan->ts->trx->bts->nr,
1720 chan_req_lchan->ts->nr);
1721 lchan[i] = chan_req_lchan;
1722 }
1723 }
1724 send_ho_complete(chan_req_lchan, true);
1725 } else
1726 if (!strcmp(*test_case, "ho-failed")) {
1727 fprintf(stderr, "- Making handover fail\n");
1728 if (!got_chan_req) {
1729 printf("Cannot fail handover, because no chan "
1730 "request\n");
1731 return EXIT_FAILURE;
1732 }
1733 test_case += 1;
1734 got_chan_req = 0;
1735 got_ho_req = 0;
1736 send_ho_complete(ho_req_lchan, false);
1737 } else
1738 if (!strcmp(*test_case, "print")) {
1739 fprintf(stderr, "\n%s\n\n", test_case[1]);
1740 test_case += 2;
1741 } else {
1742 printf("Unknown test command '%s', please fix!\n",
1743 *test_case);
1744 return EXIT_FAILURE;
1745 }
Neels Hofmeyr31f525e2018-05-14 18:14:15 +02001746
1747 {
1748 /* Help the lchan out of releasing states */
1749 struct gsm_bts *bts;
1750 llist_for_each_entry(bts, &bsc_gsmnet->bts_list, list) {
1751 struct gsm_bts_trx *trx;
1752 llist_for_each_entry(trx, &bts->trx_list, list) {
1753 int ts_nr;
1754 for (ts_nr = 0; ts_nr < TRX_NR_TS; ts_nr++) {
1755 struct gsm_lchan *lchan;
1756 ts_for_each_lchan(lchan, &trx->ts[ts_nr]) {
1757
1758 if (lchan->fi && lchan->fi->state == LCHAN_ST_WAIT_BEFORE_RF_RELEASE) {
1759 osmo_fsm_inst_state_chg(lchan->fi, LCHAN_ST_WAIT_RF_RELEASE_ACK, 0, 0);
1760 osmo_fsm_inst_dispatch(lchan->fi, LCHAN_EV_RSL_RF_CHAN_REL_ACK, 0);
1761 }
1762 }
1763 }
1764 }
1765 }
1766 }
Neels Hofmeyr909e9722017-12-07 03:54:01 +01001767 }
1768
1769 for (i = 0; i < lchan_num; i++) {
1770 struct gsm_subscriber_connection *conn = lchan[i]->conn;
1771 lchan[i]->conn = NULL;
1772 conn->lchan = NULL;
Harald Welte3561bd42018-01-28 03:04:16 +01001773 osmo_fsm_inst_term(conn->fi, OSMO_FSM_TERM_REGULAR, NULL);
Neels Hofmeyr909e9722017-12-07 03:54:01 +01001774 }
1775
1776 fprintf(stderr, "--------------------\n");
1777
1778 printf("Test OK\n");
1779
1780 fprintf(stderr, "--------------------\n");
1781
Neels Hofmeyre3416182018-03-05 05:31:14 +01001782 talloc_free(ctx);
Neels Hofmeyr909e9722017-12-07 03:54:01 +01001783 return EXIT_SUCCESS;
1784}
1785
1786void rtp_socket_free() {}
1787void rtp_send_frame() {}
1788void rtp_socket_upstream() {}
1789void rtp_socket_create() {}
1790void rtp_socket_connect() {}
1791void rtp_socket_proxy() {}
1792void trau_mux_unmap() {}
1793void trau_mux_map_lchan() {}
1794void trau_recv_lchan() {}
1795void trau_send_frame() {}
Harald Welte3561bd42018-01-28 03:04:16 +01001796int osmo_bsc_sigtran_send(struct gsm_subscriber_connection *conn, struct msgb *msg) { return 0; }
1797int osmo_bsc_sigtran_open_conn(struct gsm_subscriber_connection *conn, struct msgb *msg) { return 0; }
Vadim Yanitskiy6a26e2c2020-08-26 18:49:08 +07001798void bsc_sapi_n_reject(struct gsm_subscriber_connection *conn, uint8_t dlci, enum gsm0808_cause cause) {}
Neels Hofmeyrc19581f2018-05-27 03:05:18 +02001799void bsc_cipher_mode_compl(struct gsm_subscriber_connection *conn, struct msgb *msg, uint8_t chosen_encr) {}
Neels Hofmeyr2001dd62020-09-11 23:35:28 +00001800int bsc_compl_l3(struct gsm_lchan *lchan, struct msgb *msg, uint16_t chosen_channel)
Neels Hofmeyrc19581f2018-05-27 03:05:18 +02001801{ return 0; }
Neels Hofmeyr86ce1052020-09-18 02:49:32 +02001802int bsc_paging_start(struct bsc_paging_params *params)
1803{ return 0; }
Neels Hofmeyrc19581f2018-05-27 03:05:18 +02001804void bsc_dtap(struct gsm_subscriber_connection *conn, uint8_t link_id, struct msgb *msg) {}
1805void bsc_assign_compl(struct gsm_subscriber_connection *conn, uint8_t rr_cause) {}
Neels Hofmeyrc19581f2018-05-27 03:05:18 +02001806void bsc_cm_update(struct gsm_subscriber_connection *conn,
1807 const uint8_t *cm2, uint8_t cm2_len,
1808 const uint8_t *cm3, uint8_t cm3_len) {}
Neels Hofmeyr31f525e2018-05-14 18:14:15 +02001809struct gsm0808_handover_required;
1810int bsc_tx_bssmap_ho_required(struct gsm_lchan *lchan, const struct gsm0808_cell_id_list2 *target_cells)
1811{ return 0; }
1812int bsc_tx_bssmap_ho_request_ack(struct gsm_subscriber_connection *conn, struct msgb *rr_ho_command)
1813{ return 0; }
1814int bsc_tx_bssmap_ho_detect(struct gsm_subscriber_connection *conn) { return 0; }
1815enum handover_result bsc_tx_bssmap_ho_complete(struct gsm_subscriber_connection *conn,
1816 struct gsm_lchan *lchan) { return HO_RESULT_OK; }
1817void bsc_tx_bssmap_ho_failure(struct gsm_subscriber_connection *conn) {}
Neels Hofmeyrc27ae2d2020-10-04 21:32:52 +02001818void osmo_bsc_sigtran_tx_reset(void) {}
Neels Hofmeyre95b92b2020-10-09 17:18:29 +02001819void osmo_bsc_sigtran_tx_reset_ack(void) {}
Neels Hofmeyrc27ae2d2020-10-04 21:32:52 +02001820void osmo_bsc_sigtran_reset(void) {}
1821void bssmap_reset_alloc(void) {}
1822void bssmap_reset_is_conn_ready(void) {}