blob: 8fa8fe84aaffa9b8bbdcd4e69579889e9d03d229 [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
177static struct gsm_bts *create_bts(int arfcn)
178{
179 struct gsm_bts *bts;
180 struct e1inp_sign_link *rsl_link;
181 int i;
182
Vadim Yanitskiy4f3a6412020-05-31 01:56:20 +0700183 bts = bsc_bts_alloc_register(bsc_gsmnet, GSM_BTS_TYPE_UNKNOWN, 0x3f);
Neels Hofmeyr909e9722017-12-07 03:54:01 +0100184 if (!bts) {
185 printf("No resource for bts1\n");
186 return NULL;
187 }
188
189 bts->location_area_code = 23;
190 bts->c0->arfcn = arfcn;
191
192 bts->codec.efr = 1;
193 bts->codec.hr = 1;
194 bts->codec.amr = 1;
195
Neels Hofmeyre3416182018-03-05 05:31:14 +0100196 rsl_link = talloc_zero(ctx, struct e1inp_sign_link);
Neels Hofmeyr909e9722017-12-07 03:54:01 +0100197 rsl_link->trx = bts->c0;
198 bts->c0->rsl_link = rsl_link;
199
200 bts->c0->mo.nm_state.operational = NM_OPSTATE_ENABLED;
201 bts->c0->mo.nm_state.availability = NM_AVSTATE_OK;
Pau Espin Pedrolcce0ae12020-06-22 17:57:01 +0200202 bts->c0->mo.nm_state.administrative = NM_STATE_UNLOCKED;
Neels Hofmeyr909e9722017-12-07 03:54:01 +0100203 bts->c0->bb_transc.mo.nm_state.operational = NM_OPSTATE_ENABLED;
204 bts->c0->bb_transc.mo.nm_state.availability = NM_AVSTATE_OK;
Pau Espin Pedrolcce0ae12020-06-22 17:57:01 +0200205 bts->c0->bb_transc.mo.nm_state.administrative = NM_STATE_UNLOCKED;
Neels Hofmeyr909e9722017-12-07 03:54:01 +0100206
207 /* 4 full rate and 4 half rate channels */
208 for (i = 1; i <= 6; i++) {
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200209 bts->c0->ts[i].pchan_from_config = (i < 5) ? GSM_PCHAN_TCH_F : GSM_PCHAN_TCH_H;
Neels Hofmeyr909e9722017-12-07 03:54:01 +0100210 bts->c0->ts[i].mo.nm_state.operational = NM_OPSTATE_ENABLED;
211 bts->c0->ts[i].mo.nm_state.availability = NM_AVSTATE_OK;
Pau Espin Pedrolcce0ae12020-06-22 17:57:01 +0200212 bts->c0->ts[i].mo.nm_state.administrative = NM_STATE_UNLOCKED;
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200213 }
214
215 for (i = 0; i < ARRAY_SIZE(bts->c0->ts); i++) {
216 /* make sure ts->lchans[] get initialized */
Neels Hofmeyrbcdbfb72018-07-26 20:33:15 +0200217 osmo_fsm_inst_dispatch(bts->c0->ts[i].fi, TS_EV_RSL_READY, 0);
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200218 osmo_fsm_inst_dispatch(bts->c0->ts[i].fi, TS_EV_OML_READY, 0);
Neels Hofmeyr909e9722017-12-07 03:54:01 +0100219 }
220 return bts;
221}
222
223void create_conn(struct gsm_lchan *lchan)
224{
Neels Hofmeyrbb6c13b2018-05-24 18:43:58 +0200225 static unsigned int next_imsi = 0;
226 char imsi[sizeof(lchan->conn->bsub->imsi)];
227 struct gsm_network *net = lchan->ts->trx->bts->network;
Harald Welte3561bd42018-01-28 03:04:16 +0100228 struct gsm_subscriber_connection *conn;
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200229 struct mgcp_client *fake_mgcp_client = (void*)talloc_zero(net, int);
Neels Hofmeyrbb6c13b2018-05-24 18:43:58 +0200230
231 conn = bsc_subscr_con_allocate(net);
Harald Welte3561bd42018-01-28 03:04:16 +0100232
Neels Hofmeyrf14aaa42019-04-23 18:37:37 +0200233 conn->user_plane.mgw_endpoint = osmo_mgcpc_ep_alloc(conn->fi,
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200234 GSCON_EV_FORGET_MGW_ENDPOINT,
Neels Hofmeyrf14aaa42019-04-23 18:37:37 +0200235 fake_mgcp_client,
236 net->mgw.tdefs,
237 "test",
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200238 "fake endpoint");
Alexander Chemeris69ba8be2020-05-10 22:48:01 +0300239 conn->sccp.msc = osmo_msc_data_alloc(net, 0);
Harald Welte3561bd42018-01-28 03:04:16 +0100240
241 lchan->conn = conn;
242 conn->lchan = lchan;
Neels Hofmeyrbb6c13b2018-05-24 18:43:58 +0200243
244 /* Make up a new IMSI for this test, for logging the subscriber */
245 next_imsi ++;
246 snprintf(imsi, sizeof(imsi), "%06u", next_imsi);
Neels Hofmeyr86a1dca2020-09-15 01:03:58 +0000247 lchan->conn->bsub = bsc_subscr_find_or_create_by_imsi(net->bsc_subscribers, imsi, BSUB_USE_CONN);
Neels Hofmeyrbb6c13b2018-05-24 18:43:58 +0200248
Harald Welte3561bd42018-01-28 03:04:16 +0100249 /* kick the FSM from INIT through to the ACTIVE state */
250 osmo_fsm_inst_dispatch(conn->fi, GSCON_EV_A_CONN_REQ, NULL);
251 osmo_fsm_inst_dispatch(conn->fi, GSCON_EV_A_CONN_CFM, NULL);
Neels Hofmeyr909e9722017-12-07 03:54:01 +0100252}
253
254/* create lchan */
255struct gsm_lchan *create_lchan(struct gsm_bts *bts, int full_rate, char *codec)
256{
257 struct gsm_lchan *lchan;
258
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200259 lchan = lchan_select_by_type(bts, (full_rate) ? GSM_LCHAN_TCH_F : GSM_LCHAN_TCH_H);
Neels Hofmeyr909e9722017-12-07 03:54:01 +0100260 if (!lchan) {
261 printf("No resource for lchan\n");
262 exit(EXIT_FAILURE);
263 }
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200264
265 /* serious hack into osmo_fsm */
266 lchan->fi->state = LCHAN_ST_ESTABLISHED;
267 lchan->ts->fi->state = TS_ST_IN_USE;
268 LOG_LCHAN(lchan, LOGL_DEBUG, "activated by handover_test.c\n");
269
Neels Hofmeyr909e9722017-12-07 03:54:01 +0100270 create_conn(lchan);
271 if (!strcasecmp(codec, "FR") && full_rate)
272 lchan->tch_mode = GSM48_CMODE_SPEECH_V1;
273 else if (!strcasecmp(codec, "HR") && !full_rate)
274 lchan->tch_mode = GSM48_CMODE_SPEECH_V1;
275 else if (!strcasecmp(codec, "EFR") && full_rate)
276 lchan->tch_mode = GSM48_CMODE_SPEECH_EFR;
Philipp Maiereda6bfa2019-03-11 14:10:26 +0100277 else if (!strcasecmp(codec, "AMR")) {
Neels Hofmeyr909e9722017-12-07 03:54:01 +0100278 lchan->tch_mode = GSM48_CMODE_SPEECH_AMR;
Philipp Maiereda6bfa2019-03-11 14:10:26 +0100279 lchan->activate.info.s15_s0 = 0x0002;
280 } else {
Neels Hofmeyr909e9722017-12-07 03:54:01 +0100281 printf("Given codec unknown\n");
282 exit(EXIT_FAILURE);
283 }
284
285 lchan->conn->codec_list = (struct gsm0808_speech_codec_list){
286 .codec = {
287 { .fi=true, .type=GSM0808_SCT_FR1, },
288 { .fi=true, .type=GSM0808_SCT_FR2, },
289 { .fi=true, .type=GSM0808_SCT_FR3, },
290 { .fi=true, .type=GSM0808_SCT_HR1, },
291 { .fi=true, .type=GSM0808_SCT_HR3, },
292 },
293 .len = 5,
294 };
Neels Hofmeyr909e9722017-12-07 03:54:01 +0100295
296 return lchan;
297}
298
299/* parse channel request */
300
301static int got_chan_req = 0;
302static struct gsm_lchan *chan_req_lchan = NULL;
303
304static int parse_chan_act(struct gsm_lchan *lchan, uint8_t *data)
305{
306 chan_req_lchan = lchan;
307 return 0;
308}
309
310static int parse_chan_rel(struct gsm_lchan *lchan, uint8_t *data)
311{
312 chan_req_lchan = lchan;
313 return 0;
314}
315
316/* parse handover request */
317
318static int got_ho_req = 0;
319static struct gsm_lchan *ho_req_lchan = NULL;
320
321static int parse_ho_command(struct gsm_lchan *lchan, uint8_t *data, int len)
322{
323 struct gsm48_hdr *gh = (struct gsm48_hdr *) data;
324 struct gsm48_ho_cmd *ho = (struct gsm48_ho_cmd *) gh->data;
325 int arfcn;
326 struct gsm_bts *neigh;
327
328 switch (gh->msg_type) {
329 case GSM48_MT_RR_HANDO_CMD:
330 arfcn = (ho->cell_desc.arfcn_hi << 8) | ho->cell_desc.arfcn_lo;
331
332 /* look up trx. since every dummy bts uses different arfcn and
333 * only one trx, it is simple */
334 llist_for_each_entry(neigh, &bsc_gsmnet->bts_list, list) {
335 if (neigh->c0->arfcn != arfcn)
336 continue;
337 ho_req_lchan = lchan;
338 return 0;
339 }
340 break;
341 case GSM48_MT_RR_ASS_CMD:
342 ho_req_lchan = lchan;
343 return 0;
344 break;
345 default:
346 fprintf(stderr, "Error, expecting HO or AS command\n");
347 return -EINVAL;
348 }
349
350 return -1;
351}
352
353/* send channel activation ack */
354static void send_chan_act_ack(struct gsm_lchan *lchan, int act)
355{
356 struct msgb *msg = msgb_alloc_headroom(256, 64, "RSL");
357 struct abis_rsl_dchan_hdr *dh;
358
359 dh = (struct abis_rsl_dchan_hdr *) msgb_put(msg, sizeof(*dh));
360 dh->c.msg_discr = ABIS_RSL_MDISC_DED_CHAN;
361 dh->c.msg_type = (act) ? RSL_MT_CHAN_ACTIV_ACK : RSL_MT_RF_CHAN_REL_ACK;
362 dh->ie_chan = RSL_IE_CHAN_NR;
363 dh->chan_nr = gsm_lchan2chan_nr(lchan);
364
365 msg->dst = lchan->ts->trx->bts->c0->rsl_link;
366 msg->l2h = (unsigned char *)dh;
367
368 abis_rsl_rcvmsg(msg);
369}
370
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200371/* Send RLL Est Ind for SAPI[0] */
372static void send_est_ind(struct gsm_lchan *lchan)
373{
374 struct msgb *msg = msgb_alloc_headroom(256, 64, "RSL");
375 struct abis_rsl_rll_hdr *rh;
376 uint8_t chan_nr = gsm_lchan2chan_nr(lchan);
377
378 rh = (struct abis_rsl_rll_hdr *) msgb_put(msg, sizeof(*rh));
379 rh->c.msg_discr = ABIS_RSL_MDISC_RLL;
380 rh->c.msg_type = RSL_MT_EST_IND;
381 rh->ie_chan = RSL_IE_CHAN_NR;
382 rh->chan_nr = chan_nr;
383 rh->ie_link_id = RSL_IE_LINK_IDENT;
384 rh->link_id = 0x00;
385
386 msg->dst = lchan->ts->trx->bts->c0->rsl_link;
387 msg->l2h = (unsigned char *)rh;
388
389 abis_rsl_rcvmsg(msg);
390}
391
Neels Hofmeyr909e9722017-12-07 03:54:01 +0100392/* send handover complete */
393static void send_ho_complete(struct gsm_lchan *lchan, bool success)
394{
395 struct msgb *msg = msgb_alloc_headroom(256, 64, "RSL");
396 struct abis_rsl_rll_hdr *rh;
397 uint8_t chan_nr = gsm_lchan2chan_nr(lchan);
398 uint8_t *buf;
399 struct gsm48_hdr *gh;
400 struct gsm48_ho_cpl *hc;
401
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200402 send_est_ind(lchan);
Neels Hofmeyrac85b342018-07-12 21:23:26 +0200403 osmo_fsm_inst_dispatch(lchan->fi, LCHAN_EV_RTP_READY, 0);
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200404
Neels Hofmeyr909e9722017-12-07 03:54:01 +0100405 rh = (struct abis_rsl_rll_hdr *) msgb_put(msg, sizeof(*rh));
406 rh->c.msg_discr = ABIS_RSL_MDISC_RLL;
407 rh->c.msg_type = RSL_MT_DATA_IND;
408 rh->ie_chan = RSL_IE_CHAN_NR;
409 rh->chan_nr = chan_nr;
410 rh->ie_link_id = RSL_IE_LINK_IDENT;
411 rh->link_id = 0x00;
412
413 buf = msgb_put(msg, 3);
414 buf[0] = RSL_IE_L3_INFO;
415 buf[1] = (sizeof(*gh) + sizeof(*hc)) >> 8;
416 buf[2] = (sizeof(*gh) + sizeof(*hc)) & 0xff;
417
418 gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
419 hc = (struct gsm48_ho_cpl *) msgb_put(msg, sizeof(*hc));
420
421 gh->proto_discr = GSM48_PDISC_RR;
422 gh->msg_type =
423 success ? GSM48_MT_RR_HANDO_COMPL : GSM48_MT_RR_HANDO_FAIL;
424
425 msg->dst = lchan->ts->trx->bts->c0->rsl_link;
426 msg->l2h = (unsigned char *)rh;
427 msg->l3h = (unsigned char *)gh;
428
429 abis_rsl_rcvmsg(msg);
430}
431
Neels Hofmeyr1d7473c2018-03-05 21:53:18 +0100432/* override, requires '-Wl,--wrap=abis_rsl_sendmsg'.
433 * Catch RSL messages sent towards the BTS. */
434int __real_abis_rsl_sendmsg(struct msgb *msg);
435int __wrap_abis_rsl_sendmsg(struct msgb *msg)
Neels Hofmeyr909e9722017-12-07 03:54:01 +0100436{
437 struct abis_rsl_dchan_hdr *dh = (struct abis_rsl_dchan_hdr *) msg->data;
438 struct e1inp_sign_link *sign_link = msg->dst;
439 int rc;
440 struct gsm_lchan *lchan = rsl_lchan_lookup(sign_link->trx, dh->chan_nr, &rc);
441
442 if (rc) {
443 printf("rsl_lchan_lookup() failed\n");
444 exit(1);
445 }
446
447 switch (dh->c.msg_type) {
448 case RSL_MT_CHAN_ACTIV:
449 rc = parse_chan_act(lchan, dh->data);
450 if (rc == 0)
451 got_chan_req = 1;
452 break;
453 case RSL_MT_RF_CHAN_REL:
454 rc = parse_chan_rel(lchan, dh->data);
455 if (rc == 0)
456 send_chan_act_ack(chan_req_lchan, 0);
457 break;
458 case RSL_MT_DATA_REQ:
459 rc = parse_ho_command(lchan, msg->l3h, msgb_l3len(msg));
460 if (rc == 0)
461 got_ho_req = 1;
462 break;
463 case RSL_MT_IPAC_CRCX:
464 break;
Neels Hofmeyr5b1a7d12018-11-06 22:24:07 +0100465 case RSL_MT_DEACTIVATE_SACCH:
466 break;
Neels Hofmeyr909e9722017-12-07 03:54:01 +0100467 default:
468 printf("unknown rsl message=0x%x\n", dh->c.msg_type);
469 }
470 return 0;
471}
472
473/* test cases */
474
475static char *test_case_0[] = {
476 "2",
477
478 "Stay in better cell\n\n"
479 "There are many neighbor cells, but only the current cell is the best\n"
480 "cell, so no handover is performed\n",
481
482 "create-bts", "7",
483 "create-ms", "0", "TCH/F", "AMR",
484 "meas-rep", "0", "30","0",
485 "6","0","20","1","21","2","18","3","20","4","23","5","19",
486 "expect-no-chan",
487 NULL
488};
489
490static char *test_case_1[] = {
491 "2",
492
493 "Handover to best better cell\n\n"
494 "The best neighbor cell is selected\n",
495
496 "create-bts", "7",
497 "create-ms", "0", "TCH/F", "AMR",
498 "meas-rep", "0", "10","0",
499 "6","0","20","1","21","2","18","3","20","4","23","5","19",
500 "expect-chan", "5", "1",
501 "ack-chan",
502 "expect-ho", "0", "1",
503 "ho-complete",
504 NULL
505};
506
507static char *test_case_2[] = {
508 "2",
509
510 "Handover and Assignment must be enabled\n\n"
511 "This test will start with disabled assignment and handover. A\n"
512 "better neighbor cell (assignment enabled) will not be selected and \n"
513 "also no assignment from TCH/H to TCH/F to improve quality. There\n"
514 "will be no handover nor assignment. After enabling assignment on the\n"
515 "current cell, the MS will assign to TCH/F. After enabling handover\n"
516 "in the current cell, but disabling in the neighbor cell, handover\n"
517 "will not be performed, until it is enabled in the neighbor cell too.\n",
518
519 "create-bts", "2",
520 "afs-rxlev-improve", "0", "5",
521 "create-ms", "0", "TCH/H", "AMR",
522 "as-enable", "0", "0",
523 "ho-enable", "0", "0",
524 "meas-rep", "0", "0","0", "1","0","30",
525 "expect-no-chan",
526 "as-enable", "0", "1",
527 "meas-rep", "0", "0","0", "1","0","30",
528 "expect-chan", "0", "1",
529 "ack-chan",
530 "expect-ho", "0", "5",
531 "ho-complete",
532 "ho-enable", "0", "1",
533 "ho-enable", "1", "0",
534 "meas-rep", "0", "0","0", "1","0","30",
535 "expect-no-chan",
536 "ho-enable", "1", "1",
537 "meas-rep", "0", "0","0", "1","0","30",
538 "expect-chan", "1", "1",
539 "ack-chan",
540 "expect-ho", "0", "1",
541 "ho-complete",
542 NULL
543};
544
545static char *test_case_3[] = {
546 "2",
547
548 "Penalty timer must not run\n\n"
549 "The MS will try to handover to a better cell, but this will fail.\n"
550 "Even though the cell is still better, handover will not be performed\n"
551 "due to penalty timer after handover failure\n",
552
553 "create-bts", "2",
554 "create-ms", "0", "TCH/F", "AMR",
555 "meas-rep", "0", "20","0", "1","0","30",
556 "expect-chan", "1", "1",
557 "ack-chan",
558 "expect-ho", "0", "1",
559 "ho-failed",
560 "meas-rep", "0", "20","0", "1","0","30",
561 "expect-no-chan",
562 NULL
563};
564
565static char *test_case_4[] = {
566 "2",
567
568 "TCH/H keeping with HR codec\n\n"
569 "The MS is using half rate V1 codec, but the better cell is congested\n"
570 "at TCH/H slots. As the congestion is removed, the handover takes\n"
571 "place.\n",
572
573 "create-bts", "2",
574 "set-min-free", "1", "TCH/H", "4",
575 "create-ms", "0", "TCH/H", "HR",
576 "meas-rep", "0", "20","0", "1","0","30",
577 "expect-no-chan",
578 "set-min-free", "1", "TCH/H", "3",
579 "meas-rep", "0", "20","0", "1","0","30",
580 "expect-chan", "1", "5",
581 "ack-chan",
582 "expect-ho", "0", "5",
583 "ho-complete",
584 NULL
585};
586
587static char *test_case_5[] = {
588 "2",
589
590 "TCH/F keeping with FR codec\n\n"
591 "The MS is using full rate V1 codec, but the better cell is congested\n"
592 "at TCH/F slots. As the congestion is removed, the handover takes\n"
593 "place.\n",
594
595 "create-bts", "2",
596 "set-min-free", "1", "TCH/F", "4",
597 "create-ms", "0", "TCH/F", "FR",
598 "meas-rep", "0", "20","0", "1","0","30",
599 "expect-no-chan",
600 "set-min-free", "1", "TCH/F", "3",
601 "meas-rep", "0", "20","0", "1","0","30",
602 "expect-chan", "1", "1",
603 "ack-chan",
604 "expect-ho", "0", "1",
605 "ho-complete",
606 NULL
607};
608
609static char *test_case_6[] = {
610 "2",
611
612 "TCH/F keeping with EFR codec\n\n"
613 "The MS is using full rate V2 codec, but the better cell is congested\n"
614 "at TCH/F slots. As the congestion is removed, the handover takes\n"
615 "place.\n",
616
617 "create-bts", "2",
618 "set-min-free", "1", "TCH/F", "4",
619 "create-ms", "0", "TCH/F", "EFR",
620 "meas-rep", "0", "20","0", "1","0","30",
621 "expect-no-chan",
622 "set-min-free", "1", "TCH/F", "3",
623 "meas-rep", "0", "20","0", "1","0","30",
624 "expect-chan", "1", "1",
625 "ack-chan",
626 "expect-ho", "0", "1",
627 "ho-complete",
628 NULL
629};
630
631static char *test_case_7[] = {
632 "2",
633
634 "TCH/F to TCH/H changing with AMR codec\n\n"
635 "The MS is using AMR V3 codec, the better cell is congested at TCH/F\n"
636 "slots. The handover is performed to non-congested TCH/H slots.\n",
637
638 "create-bts", "2",
639 "set-min-free", "1", "TCH/F", "4",
640 "create-ms", "0", "TCH/F", "AMR",
641 "meas-rep", "0", "20","0", "1","0","30",
642 "expect-chan", "1", "5",
643 "ack-chan",
644 "expect-ho", "0", "1",
645 "ho-complete",
646 NULL
647};
648
649static char *test_case_8[] = {
650 "2",
651
652 "No handover to a cell with no slots available\n\n"
653 "If no slot is available, no handover is performed\n",
654
655 "create-bts", "2",
656 "create-ms", "0", "TCH/F", "AMR",
657 "create-ms", "1", "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/H", "AMR",
662 "create-ms", "1", "TCH/H", "AMR",
663 "create-ms", "1", "TCH/H", "AMR",
664 "create-ms", "1", "TCH/H", "AMR",
665 "meas-rep", "0", "0","0", "1","0","30",
666 "expect-no-chan",
667 NULL
668};
669
670static char *test_case_9[] = {
671 "2",
672
673 "No more parallel handovers, if max_unsync_ho is defined\n\n"
674 "There are tree mobiles that want to handover, but only two can do\n"
675 "it at a time, because the maximum number is limited to two.\n",
676
677 "create-bts", "2",
678 "set-max-ho", "1", "2",
679 "create-ms", "0", "TCH/F", "AMR",
680 "create-ms", "0", "TCH/F", "AMR",
681 "create-ms", "0", "TCH/F", "AMR",
682 "meas-rep", "0", "0","0", "1","0","30",
683 "expect-chan", "1", "1",
684 "meas-rep", "1", "0","0", "1","0","30",
685 "expect-chan", "1", "2",
686 "meas-rep", "2", "0","0", "1","0","30",
687 "expect-no-chan",
688 NULL
689};
690
691static char *test_case_10[] = {
692 "2",
693
694 "Hysteresis\n\n"
695 "If neighbor cell is better, handover is only performed if the\n"
Martin Haukea29affd2019-11-13 22:10:41 +0100696 "amount of improvement is greater or equal hyteresis\n",
Neels Hofmeyr909e9722017-12-07 03:54:01 +0100697
698 "create-bts", "2",
699 "create-ms", "0", "TCH/F", "AMR",
700 "meas-rep", "0", "27","0", "1","0","30",
701 "expect-no-chan",
702 "meas-rep", "0", "26","0", "1","0","30",
703 "expect-chan", "1", "1",
704 "ack-chan",
705 "expect-ho", "0", "1",
706 "ho-complete",
707 NULL
708};
709
710static char *test_case_11[] = {
711 "2",
712
713 "No Hysteresis and minimum RX level\n\n"
714 "If current cell's RX level is below mimium level, handover must be\n"
715 "performed, no matter of the hysteresis. First do not perform\n"
716 "handover to better neighbor cell, because the hysteresis is not\n"
717 "met. Second do not perform handover because better neighbor cell is\n"
718 "below minimum RX level. Third perform handover because current cell\n"
719 "is below minimum RX level, even if the better neighbor cell (minimum\n"
720 "RX level reached) does not meet the hysteresis.\n",
721
722 "create-bts", "2",
723 "create-ms", "0", "TCH/F", "AMR",
724 "meas-rep", "0", "10","0", "1","0","11",
725 "expect-no-chan",
726 "meas-rep", "0", "8","0", "1","0","9",
727 "expect-no-chan",
728 "meas-rep", "0", "9","0", "1","0","10",
729 "expect-chan", "1", "1",
730 "ack-chan",
731 "expect-ho", "0", "1",
732 "ho-complete",
733 NULL
734};
735
736static char *test_case_12[] = {
737 "2",
738
739 "No handover to congested cell\n\n"
740 "The better neighbor cell is congested, so no handover is performed.\n"
741 "After the congestion is over, handover will be performed.\n",
742
743 "create-bts", "2",
744 "create-ms", "0", "TCH/F", "AMR",
745 "set-min-free", "1", "TCH/F", "4",
746 "set-min-free", "1", "TCH/H", "4",
747 "meas-rep", "0", "20","0", "1","0","30",
748 "expect-no-chan",
749 "set-min-free", "1", "TCH/F", "3",
750 "set-min-free", "1", "TCH/H", "3",
751 "meas-rep", "0", "20","0", "1","0","30",
752 "expect-chan", "1", "1",
753 "ack-chan",
754 "expect-ho", "0", "1",
755 "ho-complete",
756 NULL
757};
758
759static char *test_case_13[] = {
760 "2",
761
762 "Handover to balance congestion\n\n"
763 "The current and the better cell are congested, so no handover is\n"
764 "performed. This is because handover would congest the neighbor cell\n"
765 "more. After congestion raises in the current cell, the handover is\n"
766 "performed to balance congestion\n",
767
768 "create-bts", "2",
769 "create-ms", "0", "TCH/F", "AMR",
770 "set-min-free", "0", "TCH/F", "4",
771 "set-min-free", "0", "TCH/H", "4",
772 "set-min-free", "1", "TCH/F", "4",
773 "set-min-free", "1", "TCH/H", "4",
774 "meas-rep", "0", "20","0", "1","0","30",
775 "expect-no-chan",
776 "create-ms", "0", "TCH/F", "AMR",
777 "meas-rep", "0", "20","0", "1","0","30",
778 "expect-chan", "1", "1",
779 "ack-chan",
780 "expect-ho", "0", "1",
781 "ho-complete",
782 NULL
783};
784
785static char *test_case_14[] = {
786 "2",
787
788 "Handover to congested cell, if RX level is below minimum\n\n"
789 "The better neighbor cell is congested, so no handover is performed.\n"
790 "If the RX level of the current cell drops below minimum acceptable\n"
791 "level, the handover is performed.\n",
792
793 "create-bts", "2",
794 "create-ms", "0", "TCH/F", "AMR",
795 "set-min-free", "1", "TCH/F", "4",
796 "set-min-free", "1", "TCH/H", "4",
797 "meas-rep", "0", "10","0", "1","0","30",
798 "expect-no-chan",
799 "meas-rep", "0", "9","0", "1","0","30",
800 "expect-chan", "1", "1",
801 "ack-chan",
802 "expect-ho", "0", "1",
803 "ho-complete",
804 NULL
805};
806
807static char *test_case_15[] = {
808 "2",
809
810 "Handover to cell with worse RXLEV, if RXQUAL is below minimum\n\n"
811 "The neighbor cell has worse RXLEV, so no handover is performed.\n"
812 "If the RXQUAL of the current cell drops below minimum acceptable\n"
813 "level, the handover is performed. It is also required that 10\n"
814 "reports are received, before RXQUAL is checked.\n",
815 /* (See also test 28, which tests for RXQUAL triggering HO to congested cell.) */
816 /* TODO: bad RXQUAL may want to prefer assignment within the same cell to avoid interference.
Martin Haukea29affd2019-11-13 22:10:41 +0100817 * See Performance Enhancements in a Frequency Hopping GSM Network (Nielsen Wigard 2002), Chapter
Neels Hofmeyr909e9722017-12-07 03:54:01 +0100818 * 2.1.1, "Interference" in the list of triggers on p.157. */
819
820 "create-bts", "2",
821 "create-ms", "0", "TCH/F", "AMR",
822 "meas-rep", "0", "40","6", "1","0","30",
823 "expect-no-chan",
824 "meas-rep", "0", "40","6", "1","0","30",
825 "expect-no-chan",
826 "meas-rep", "0", "40","6", "1","0","30",
827 "expect-no-chan",
828 "meas-rep", "0", "40","6", "1","0","30",
829 "expect-no-chan",
830 "meas-rep", "0", "40","6", "1","0","30",
831 "expect-no-chan",
832 "meas-rep", "0", "40","6", "1","0","30",
833 "expect-no-chan",
834 "meas-rep", "0", "40","6", "1","0","30",
835 "expect-no-chan",
836 "meas-rep", "0", "40","6", "1","0","30",
837 "expect-no-chan",
838 "meas-rep", "0", "40","6", "1","0","30",
839 "expect-no-chan",
840 "meas-rep", "0", "40","6", "1","0","30",
841 "expect-chan", "1", "1",
842 "ack-chan",
843 "expect-ho", "0", "1",
844 "ho-complete",
845 NULL
846};
847
848static char *test_case_16[] = {
849 "2",
850
851 "Handover due to maximum TA exceeded\n\n"
852 "The MS in the current (best) cell has reached maximum allowed timing\n"
853 "advance. No handover is performed until the timing advance exceeds\n"
854 "it. The originating cell is still the best, but no handover is\n"
855 "performed back to that cell, because the penalty timer (due to\n"
856 "maximum allowed timing advance) is running.\n",
857
858 "create-bts", "2",
859 "create-ms", "0", "TCH/F", "AMR",
860 "set-max-ta", "0", "5", /* of cell */
861 "set-ta", "0", "5", /* of ms */
862 "meas-rep", "0", "30","0", "1","0","20",
863 "expect-no-chan",
864 "set-ta", "0", "6", /* of ms */
865 "meas-rep", "0", "30","0", "1","0","20",
866 "expect-chan", "1", "1",
867 "ack-chan",
868 "expect-ho", "0", "1",
869 "ho-complete",
870 "meas-rep", "0", "20","0", "1","0","30",
871 "expect-no-chan",
872 NULL
873};
874
875static char *test_case_17[] = {
876 "2",
877
878 "Congestion check: No congestion\n\n"
879 "Three cells have different number of used slots, but there is no\n"
880 "congestion in any of these cells. No handover is performed.\n",
881
882 "create-bts", "3",
883 "set-min-free", "0", "TCH/F", "2",
884 "set-min-free", "0", "TCH/H", "2",
885 "set-min-free", "1", "TCH/F", "2",
886 "set-min-free", "1", "TCH/H", "2",
887 "set-min-free", "2", "TCH/F", "2",
888 "set-min-free", "2", "TCH/H", "2",
889 "create-ms", "0", "TCH/F", "AMR",
890 "create-ms", "0", "TCH/F", "AMR",
891 "create-ms", "0", "TCH/H", "AMR",
892 "create-ms", "0", "TCH/H", "AMR",
893 "create-ms", "1", "TCH/F", "AMR",
894 "create-ms", "1", "TCH/H", "AMR",
895 "meas-rep", "0", "30","0", "2","0","20","1","20",
896 "expect-no-chan",
897 "meas-rep", "1", "30","0", "2","0","20","1","20",
898 "expect-no-chan",
899 "meas-rep", "2", "30","0", "2","0","20","1","20",
900 "expect-no-chan",
901 "meas-rep", "3", "30","0", "2","0","20","1","20",
902 "expect-no-chan",
903 "meas-rep", "4", "30","0", "2","0","20","1","20",
904 "expect-no-chan",
905 "meas-rep", "5", "30","0", "2","0","20","1","20",
906 "expect-no-chan",
907 "congestion-check",
908 "expect-no-chan",
909 NULL
910};
911
912static char *test_case_18[] = {
913 "2",
914
915 "Congestion check: One out of three cells is congested\n\n"
916 "Three cells have different number of used slots, but there is\n"
917 "congestion at TCH/F in the first cell. Handover is performed with\n"
918 "the best candidate.\n",
919
920 "create-bts", "3",
921 "set-min-free", "0", "TCH/F", "2",
922 "set-min-free", "0", "TCH/H", "2",
923 "set-min-free", "1", "TCH/F", "2",
924 "set-min-free", "1", "TCH/H", "2",
925 "set-min-free", "2", "TCH/F", "2",
926 "set-min-free", "2", "TCH/H", "2",
927 "create-ms", "0", "TCH/F", "AMR",
928 "create-ms", "0", "TCH/F", "AMR",
929 "create-ms", "0", "TCH/F", "AMR",
930 "create-ms", "0", "TCH/H", "AMR",
931 "create-ms", "0", "TCH/H", "AMR",
932 "create-ms", "1", "TCH/F", "AMR",
933 "create-ms", "1", "TCH/H", "AMR",
934 "meas-rep", "0", "30","0", "2","0","20","1","20",
935 "expect-no-chan",
936 "meas-rep", "1", "30","0", "2","0","20","1","20",
937 "expect-no-chan",
938 "meas-rep", "2", "30","0", "2","0","21","1","20",
939 "expect-no-chan",
940 "meas-rep", "3", "30","0", "2","0","20","1","20",
941 "expect-no-chan",
942 "meas-rep", "4", "30","0", "2","0","20","1","20",
943 "expect-no-chan",
944 "meas-rep", "5", "30","0", "2","0","20","1","20",
945 "expect-no-chan",
946 "meas-rep", "6", "30","0", "2","0","20","1","20",
947 "expect-no-chan",
948 "congestion-check",
949 "expect-chan", "1", "2",
950 "ack-chan",
951 "expect-ho", "0", "3", /* best candidate is MS 2 at BTS 1, TS 3 */
952 "ho-complete",
953 NULL
954};
955
956static char *test_case_19[] = {
957 "2",
958
959 "Congestion check: Balancing over congested cells\n\n"
Neels Hofmeyr1336d942020-08-10 21:13:55 +0200960 "Two cells are congested, but the second cell is less congested.\n"
Neels Hofmeyr909e9722017-12-07 03:54:01 +0100961 "Handover is performed to solve the congestion.\n",
962
963 "create-bts", "2",
964 "set-min-free", "0", "TCH/F", "4",
965 "set-min-free", "1", "TCH/F", "4",
966 "create-ms", "0", "TCH/F", "FR",
967 "create-ms", "0", "TCH/F", "FR",
968 "create-ms", "0", "TCH/F", "FR",
969 "create-ms", "1", "TCH/F", "FR",
970 "meas-rep", "0", "30","0", "1","0","20",
971 "expect-no-chan",
972 "meas-rep", "1", "30","0", "1","0","21",
973 "expect-no-chan",
974 "meas-rep", "2", "30","0", "1","0","20",
975 "expect-no-chan",
976 "meas-rep", "3", "30","0", "1","0","20",
977 "expect-no-chan",
978 "congestion-check",
979 "expect-chan", "1", "2",
980 "ack-chan",
981 "expect-ho", "0", "2", /* best candidate is MS 1 at BTS 0, TS 2 */
982 "ho-complete",
983 NULL
984};
985
986static char *test_case_20[] = {
987 "2",
988
989 "Congestion check: Solving congestion by handover TCH/F -> TCH/H\n\n"
990 "Two BTS, one MS in the first congested BTS must handover to\n"
991 "non-congested TCH/H of second BTS, in order to solve congestion\n",
992 "create-bts", "2",
993 "set-min-free", "0", "TCH/F", "4",
994 "set-min-free", "0", "TCH/H", "4",
995 "set-min-free", "1", "TCH/F", "4",
996 "create-ms", "0", "TCH/F", "AMR",
997 "meas-rep", "0", "30","0", "1","0","30",
998 "expect-no-chan",
999 "congestion-check",
1000 "expect-chan", "1", "5",
1001 "ack-chan",
1002 "expect-ho", "0", "1",
1003 "ho-complete",
1004 NULL
1005};
1006
1007static char *test_case_21[] = {
1008 "2",
1009
1010 "Congestion check: Balancing congestion by handover TCH/F -> TCH/H\n\n"
1011 "Two BTS, one MS in the first congested BTS must handover to\n"
1012 "less-congested TCH/H of second BTS, in order to balance congestion\n",
1013 "create-bts", "2",
1014 "set-min-free", "0", "TCH/F", "4",
1015 "set-min-free", "0", "TCH/H", "4",
1016 "set-min-free", "1", "TCH/F", "4",
1017 "set-min-free", "1", "TCH/H", "4",
1018 "create-ms", "0", "TCH/F", "AMR",
1019 "create-ms", "0", "TCH/F", "AMR",
1020 "create-ms", "0", "TCH/H", "AMR",
1021 "meas-rep", "0", "30","0", "1","0","30",
1022 "expect-no-chan",
1023 "congestion-check",
1024 "expect-chan", "1", "1",
1025 "ack-chan",
1026 "expect-ho", "0", "1",
1027 "ho-complete",
1028 NULL
1029};
1030
1031static char *test_case_22[] = {
1032 "2",
1033
1034 "Congestion check: Upgrading worst candidate from TCH/H -> TCH/F\n\n"
1035 "There is only one BTS. The TCH/H slots are congested. Since\n"
1036 "assignment is performed to less-congested TCH/F, the candidate with\n"
1037 "the worst RX level is chosen.\n",
1038
1039 "create-bts", "1",
1040 "set-min-free", "0", "TCH/F", "4",
1041 "set-min-free", "0", "TCH/H", "4",
1042 "create-ms", "0", "TCH/H", "AMR",
1043 "create-ms", "0", "TCH/H", "AMR",
1044 "create-ms", "0", "TCH/H", "AMR",
1045 "meas-rep", "0", "30","0", "0",
1046 "meas-rep", "1", "34","0", "0",
1047 "meas-rep", "2", "20","0", "0",
1048 "expect-no-chan",
1049 "congestion-check",
1050 "expect-chan", "0", "1",
1051 "ack-chan",
1052 "expect-ho", "0", "6",
1053 "ho-complete",
1054 NULL
1055};
1056
1057static char *test_case_23[] = {
1058 "2",
1059
1060 "Story: 'A neighbor is your friend'\n",
1061
1062 "create-bts", "3",
1063
1064 "print",
1065 "Andreas is driving along the coast, on a sunny june afternoon.\n"
1066 "Suddenly he is getting a call from his friend and neighbor Axel.\n"
1067 "\n"
1068 "What happens: Two MS are created, #0 for Axel, #1 for Andreas.",
1069 /* Axel */
1070 "create-ms", "2", "TCH/F", "AMR",
1071 /* andreas */
1072 "create-ms", "0", "TCH/F", "AMR",
1073 "meas-rep", "1", "40","0", "1","0","30",
1074 "expect-no-chan",
1075
1076 "print",
1077 "Axel asks Andreas if he would like to join them for a barbecue.\n"
1078 "Axel's house is right in the neighborhood and the weather is fine.\n"
1079 "Andreas agrees, so he drives to a close store to buy some barbecue\n"
1080 "skewers.\n"
1081 "\n"
1082 "What happens: While driving, a different cell (mounted atop the\n"
1083 "store) becomes better.",
1084 /* drive to bts 1 */
1085 "meas-rep", "1", "20","0", "1","0","35",
1086 "expect-chan", "1", "1",
1087 "ack-chan",
1088 "expect-ho", "0", "1",
1089 "ho-complete",
1090
1091 "print",
1092 "While Andreas is walking into the store, Axel asks, if he could also\n"
1093 "bring some beer. Andreas has problems understanding him: \"I have a\n"
1094 "bad reception here. The cell tower is right atop the store, but poor\n"
1095 "coverage inside. Can you repeat please?\"\n"
1096 "\n"
1097 "What happens: Inside the store the close cell is so bad, that\n"
1098 "handover back to the previous cell is required.",
1099 /* bts 1 becomes bad, so bts 0 helps out */
1100 "meas-rep", "1", "5","0", "1","0","20",
1101 "expect-chan", "0", "1",
1102 "ack-chan",
1103 "expect-ho", "1", "1",
1104 "ho-complete",
1105
1106 "print",
1107 "After Andreas bought skewers and beer, he leaves the store.\n"
1108 "\n"
1109 "What happens: Outside the store the close cell is better again, so\n"
1110 "handover back to the that cell is performed.",
1111 /* bts 1 becomes better again */
1112 "meas-rep", "1", "20","0", "1","0","35",
1113 "expect-chan", "1", "1",
1114 "ack-chan",
1115 "expect-ho", "0", "1",
1116 "ho-complete",
1117
1118 "print",
1119 /* bts 2 becomes better */
1120 "Andreas drives down to the lake where Axel's house is.\n"
1121 "\n"
1122 "What happens: There is a small cell at Axel's house, which becomes\n"
1123 "better, because the current cell has no good comverage at the lake.",
1124 "meas-rep", "1", "14","0", "2","0","2","1","63",
1125 "expect-chan", "2", "2",
1126 "ack-chan",
1127 "expect-ho", "1", "1",
1128 "ho-complete",
1129
1130 "print",
1131 "Andreas wonders why he still has good radio coverage: \"Last time it\n"
1132 "was so bad\". Axel says: \"I installed a pico cell in my house,\n"
1133 "now we can use our mobile phones down here at the lake.\"",
1134
1135 NULL
1136};
1137
1138static char *test_case_24[] = {
1139 "2",
1140 "No (or not enough) measurements for handover\n\n"
1141 "Do not solve congestion in cell, because there is no measurement.\n"
Martin Haukea29affd2019-11-13 22:10:41 +01001142 "As soon as enough measurements available (1 in our case), perform\n"
Neels Hofmeyr909e9722017-12-07 03:54:01 +01001143 "handover. Afterwards the old cell becomes congested and the new\n"
1144 "cell is not. Do not perform handover until new measurements are\n"
1145 "received.\n",
1146
1147 /* two cells, first in congested, but no handover */
1148 "create-bts", "2",
1149 "set-min-free", "0", "TCH/F", "4",
1150 "set-min-free", "0", "TCH/H", "4",
1151 "create-ms", "0", "TCH/F", "AMR",
1152 "congestion-check",
1153 "expect-no-chan",
1154
1155 /* send measurement and trigger congestion check */
1156 "meas-rep", "0", "20","0", "1","0","20",
1157 "expect-no-chan",
1158 "congestion-check",
1159 "expect-chan", "1", "1",
1160 "ack-chan",
1161 "expect-ho", "0", "1",
1162 "ho-complete",
1163
1164 /* congest the first cell and remove congestion from second cell */
1165 "set-min-free", "0", "TCH/F", "0",
1166 "set-min-free", "0", "TCH/H", "0",
1167 "set-min-free", "1", "TCH/F", "4",
1168 "set-min-free", "1", "TCH/H", "4",
1169
1170 /* no handover until measurements applied */
1171 "congestion-check",
1172 "expect-no-chan",
1173 "meas-rep", "0", "20","0", "1","0","20",
1174 "expect-no-chan",
1175 "congestion-check",
1176 "expect-chan", "0", "1",
1177 "ack-chan",
1178 "expect-ho", "1", "1",
1179 "ho-complete",
1180 NULL
1181};
1182
1183static char *test_case_25[] = {
1184 "1",
1185
1186 "Stay in better cell\n\n"
1187 "There are many neighbor cells, but only the current cell is the best\n"
1188 "cell, so no handover is performed\n",
1189
1190 "create-bts", "7",
1191 "create-ms", "0", "TCH/F", "AMR",
1192 "meas-rep", "0", "30","0",
1193 "6","0","20","1","21","2","18","3","20","4","23","5","19",
1194 "expect-no-chan",
1195 NULL
1196};
1197
1198static char *test_case_26[] = {
1199 "1",
1200
1201 "Handover to best better cell\n\n"
1202 "The best neighbor cell is selected\n",
1203
1204 "create-bts", "7",
1205 "create-ms", "0", "TCH/F", "AMR",
1206 "meas-rep", "0", "10","0",
1207 "6","0","20","1","21","2","18","3","20","4","23","5","19",
1208 "expect-chan", "5", "1",
1209 "ack-chan",
1210 "expect-ho", "0", "1",
1211 "ho-complete",
1212 NULL
1213};
1214
1215static char *test_case_27[] = {
1216 "2",
1217
1218 "Congestion check: Upgrading worst candidate from TCH/H -> TCH/F\n\n"
1219 "There is only one BTS. The TCH/H slots are congested. Since\n"
1220 "assignment is performed to less-congested TCH/F, the candidate with\n"
1221 "the worst RX level is chosen. (So far like test 22.)\n"
1222 "After that, trigger more congestion checks to ensure stability.\n",
1223
1224 "create-bts", "1",
1225 "set-min-free", "0", "TCH/F", "2",
1226 "set-min-free", "0", "TCH/H", "4",
1227 "create-ms", "0", "TCH/H", "AMR",
1228 "create-ms", "0", "TCH/H", "AMR",
1229 "create-ms", "0", "TCH/H", "AMR",
1230 "meas-rep", "0", "30","0", "0",
1231 "meas-rep", "1", "34","0", "0",
1232 "meas-rep", "2", "20","0", "0",
1233 "expect-no-chan",
1234 "congestion-check",
1235 "expect-chan", "0", "1",
1236 "ack-chan",
1237 "expect-ho", "0", "6",
1238 "ho-complete",
1239 "congestion-check",
1240 "expect-chan", "0", "2",
1241 "ack-chan",
1242 "expect-ho", "0", "5",
1243 "ho-complete",
1244 "congestion-check",
1245 "expect-no-chan",
1246 "congestion-check",
1247 "expect-no-chan",
1248 NULL
1249};
1250
1251static char *test_case_28[] = {
1252 "2",
1253
1254 "Handover to congested cell, if RX quality is below minimum\n\n"
1255 "The better neighbor cell is congested, so no handover is performed.\n"
1256 "If the RX quality of the current cell drops below minimum acceptable\n"
1257 "level, the handover is performed. It is also required that 10\n"
1258 "resports are received, before RX quality is checked.\n",
1259
1260 "create-bts", "2",
1261 "create-ms", "0", "TCH/F", "AMR",
1262 "set-min-free", "1", "TCH/F", "4",
1263 "set-min-free", "1", "TCH/H", "4",
1264 "meas-rep", "0", "30","6", "1","0","40",
1265 "expect-no-chan",
1266 "meas-rep", "0", "30","6", "1","0","40",
1267 "expect-no-chan",
1268 "meas-rep", "0", "30","6", "1","0","40",
1269 "expect-no-chan",
1270 "meas-rep", "0", "30","6", "1","0","40",
1271 "expect-no-chan",
1272 "meas-rep", "0", "30","6", "1","0","40",
1273 "expect-no-chan",
1274 "meas-rep", "0", "30","6", "1","0","40",
1275 "expect-no-chan",
1276 "meas-rep", "0", "30","6", "1","0","40",
1277 "expect-no-chan",
1278 "meas-rep", "0", "30","6", "1","0","40",
1279 "expect-no-chan",
1280 "meas-rep", "0", "30","6", "1","0","40",
1281 "expect-no-chan",
1282 "meas-rep", "0", "30","6", "1","0","40",
1283 "expect-chan", "1", "1",
1284 "ack-chan",
1285 "expect-ho", "0", "1",
1286 "ho-complete",
1287 NULL
1288};
1289
Neels Hofmeyr7b2b4302020-08-02 02:50:17 +02001290static char *test_case_29[] = {
1291 "2",
1292
1293 "Congestion check: Balancing congestion by handover TCH/F -> TCH/H\n\n"
1294 "One BTS, and TCH/F are considered congested, TCH/H are not.\n"
1295 ,
1296 "create-bts", "1",
1297 "set-min-free", "0", "TCH/F", "3",
1298 "set-min-free", "0", "TCH/H", "0",
1299 "create-ms", "0", "TCH/F", "AMR",
1300 "create-ms", "0", "TCH/F", "AMR",
1301 "create-ms", "0", "TCH/H", "AMR",
1302 "meas-rep", "0", "30","0", "1","0","30",
1303 "expect-no-chan",
1304 "congestion-check",
1305 "expect-chan", "0", "5",
1306 "ack-chan",
1307 "expect-ho", "0", "1",
1308 "ho-complete",
1309 NULL
1310};
1311
1312
Neels Hofmeyr909e9722017-12-07 03:54:01 +01001313static char **test_cases[] = {
1314 test_case_0,
1315 test_case_1,
1316 test_case_2,
1317 test_case_3,
1318 test_case_4,
1319 test_case_5,
1320 test_case_6,
1321 test_case_7,
1322 test_case_8,
1323 test_case_9,
1324 test_case_10,
1325 test_case_11,
1326 test_case_12,
1327 test_case_13,
1328 test_case_14,
1329 test_case_15,
1330 test_case_16,
1331 test_case_17,
1332 test_case_18,
1333 test_case_19,
1334 test_case_20,
1335 test_case_21,
1336 test_case_22,
1337 test_case_23,
1338 test_case_24,
1339 test_case_25,
1340 test_case_26,
1341 test_case_27,
1342 test_case_28,
Neels Hofmeyr7b2b4302020-08-02 02:50:17 +02001343 test_case_29,
Neels Hofmeyr909e9722017-12-07 03:54:01 +01001344};
1345
1346static const struct log_info_cat log_categories[] = {
1347 [DHO] = {
1348 .name = "DHO",
1349 .description = "Hand-Over Process",
1350 .color = "\033[1;38m",
1351 .enabled = 1, .loglevel = LOGL_DEBUG,
1352 },
1353 [DHODEC] = {
1354 .name = "DHODEC",
1355 .description = "Hand-Over Decision",
1356 .color = "\033[1;38m",
1357 .enabled = 1, .loglevel = LOGL_DEBUG,
1358 },
1359 [DMEAS] = {
1360 .name = "DMEAS",
1361 .description = "Radio Measurement Processing",
1362 .enabled = 1, .loglevel = LOGL_DEBUG,
1363 },
1364 [DREF] = {
1365 .name = "DREF",
1366 .description = "Reference Counting",
1367 .enabled = 1, .loglevel = LOGL_DEBUG,
1368 },
1369 [DRSL] = {
1370 .name = "DRSL",
Keithd925c7c2018-04-16 13:40:07 +02001371 .description = "A-bis Radio Signalling Link (RSL)",
Neels Hofmeyr909e9722017-12-07 03:54:01 +01001372 .color = "\033[1;35m",
1373 .enabled = 1, .loglevel = LOGL_DEBUG,
1374 },
Neels Hofmeyr31f525e2018-05-14 18:14:15 +02001375 [DRR] = {
1376 .name = "DRR",
1377 .description = "RR",
1378 .color = "\033[1;35m",
1379 .enabled = 1, .loglevel = LOGL_DEBUG,
1380 },
1381 [DRLL] = {
1382 .name = "DRLL",
1383 .description = "RLL",
1384 .color = "\033[1;35m",
1385 .enabled = 1, .loglevel = LOGL_DEBUG,
1386 },
Harald Welte3561bd42018-01-28 03:04:16 +01001387 [DMSC] = {
1388 .name = "DMSC",
1389 .description = "Mobile Switching Center",
1390 .enabled = 1, .loglevel = LOGL_DEBUG,
1391 },
Neels Hofmeyr3c5612f2018-07-11 19:53:39 +02001392 [DCHAN] = {
1393 .name = "DCHAN",
1394 .description = "lchan FSM",
1395 .color = "\033[1;32m",
1396 .enabled = 1, .loglevel = LOGL_DEBUG,
1397 },
1398 [DTS] = {
1399 .name = "DTS",
1400 .description = "timeslot FSM",
1401 .color = "\033[1;31m",
1402 .enabled = 1, .loglevel = LOGL_DEBUG,
1403 },
1404 [DAS] = {
1405 .name = "DAS",
1406 .description = "assignment FSM",
1407 .color = "\033[1;33m",
1408 .enabled = 1, .loglevel = LOGL_DEBUG,
1409 },
Neels Hofmeyr909e9722017-12-07 03:54:01 +01001410};
1411
1412const struct log_info log_info = {
1413 .cat = log_categories,
1414 .num_cat = ARRAY_SIZE(log_categories),
1415};
1416
1417int main(int argc, char **argv)
1418{
1419 char **test_case;
1420 struct gsm_bts *bts[256];
1421 int bts_num = 0;
1422 struct gsm_lchan *lchan[256];
1423 int lchan_num = 0;
Neels Hofmeyr909e9722017-12-07 03:54:01 +01001424 int i;
Neels Hofmeyr958f2592018-05-27 01:26:31 +02001425 int algorithm;
Neels Hofmeyr00727552018-02-21 14:33:15 +01001426 int test_case_i;
1427 int last_test_i;
Neels Hofmeyr909e9722017-12-07 03:54:01 +01001428
Neels Hofmeyre3416182018-03-05 05:31:14 +01001429 ctx = talloc_named_const(NULL, 0, "handover_test");
1430 msgb_talloc_ctx_init(ctx, 0);
1431
Neels Hofmeyr00727552018-02-21 14:33:15 +01001432 test_case_i = argc > 1? atoi(argv[1]) : -1;
1433 last_test_i = ARRAY_SIZE(test_cases) - 1;
Neels Hofmeyr909e9722017-12-07 03:54:01 +01001434
Neels Hofmeyr00727552018-02-21 14:33:15 +01001435 if (test_case_i < 0 || test_case_i > last_test_i) {
1436 for (i = 0; i <= last_test_i; i++) {
Neels Hofmeyr909e9722017-12-07 03:54:01 +01001437 printf("Test #%d (algorithm %s):\n%s\n", i,
1438 test_cases[i][0], test_cases[i][1]);
1439 }
Neels Hofmeyr00727552018-02-21 14:33:15 +01001440 printf("\nPlease specify test case number 0..%d\n", last_test_i);
Neels Hofmeyr909e9722017-12-07 03:54:01 +01001441 return EXIT_FAILURE;
1442 }
1443
Neels Hofmeyre3416182018-03-05 05:31:14 +01001444 osmo_init_logging2(ctx, &log_info);
Neels Hofmeyr909e9722017-12-07 03:54:01 +01001445
1446 log_set_print_category(osmo_stderr_target, 1);
1447 log_set_print_category_hex(osmo_stderr_target, 0);
1448 log_set_print_filename2(osmo_stderr_target, LOG_FILENAME_BASENAME);
Neels Hofmeyr31f525e2018-05-14 18:14:15 +02001449 osmo_fsm_log_addr(false);
Neels Hofmeyr909e9722017-12-07 03:54:01 +01001450
Neels Hofmeyr958f2592018-05-27 01:26:31 +02001451 bsc_network_alloc();
Neels Hofmeyr909e9722017-12-07 03:54:01 +01001452 if (!bsc_gsmnet)
1453 exit(1);
1454
Neels Hofmeyr31f525e2018-05-14 18:14:15 +02001455 ts_fsm_init();
1456 lchan_fsm_init();
Neels Hofmeyr31f525e2018-05-14 18:14:15 +02001457 bsc_subscr_conn_fsm_init();
1458 handover_fsm_init();
1459
Neels Hofmeyr909e9722017-12-07 03:54:01 +01001460 ho_set_algorithm(bsc_gsmnet->ho, 2);
1461 ho_set_ho_active(bsc_gsmnet->ho, true);
1462 ho_set_hodec2_as_active(bsc_gsmnet->ho, true);
1463 ho_set_hodec2_min_rxlev(bsc_gsmnet->ho, -100);
1464 ho_set_hodec2_rxlev_avg_win(bsc_gsmnet->ho, 1);
1465 ho_set_hodec2_rxlev_neigh_avg_win(bsc_gsmnet->ho, 1);
1466 ho_set_hodec2_rxqual_avg_win(bsc_gsmnet->ho, 10);
1467 ho_set_hodec2_pwr_hysteresis(bsc_gsmnet->ho, 3);
1468 ho_set_hodec2_pwr_interval(bsc_gsmnet->ho, 1);
1469 ho_set_hodec2_afs_bias_rxlev(bsc_gsmnet->ho, 0);
1470 ho_set_hodec2_min_rxqual(bsc_gsmnet->ho, 5);
1471 ho_set_hodec2_afs_bias_rxqual(bsc_gsmnet->ho, 0);
1472 ho_set_hodec2_max_distance(bsc_gsmnet->ho, 9999);
1473 ho_set_hodec2_ho_max(bsc_gsmnet->ho, 9999);
1474 ho_set_hodec2_penalty_max_dist(bsc_gsmnet->ho, 300);
1475 ho_set_hodec2_penalty_failed_ho(bsc_gsmnet->ho, 60);
1476 ho_set_hodec2_penalty_failed_as(bsc_gsmnet->ho, 60);
1477
Vadim Yanitskiy4f3a6412020-05-31 01:56:20 +07001478 /* We don't really need any specific model here */
1479 bts_model_unknown_init();
Neels Hofmeyr909e9722017-12-07 03:54:01 +01001480
Neels Hofmeyr00727552018-02-21 14:33:15 +01001481 test_case = test_cases[test_case_i];
Neels Hofmeyr909e9722017-12-07 03:54:01 +01001482
1483 fprintf(stderr, "--------------------\n");
1484 fprintf(stderr, "Performing the following test %d (algorithm %s):\n%s",
Neels Hofmeyr00727552018-02-21 14:33:15 +01001485 test_case_i, test_case[0], test_case[1]);
Neels Hofmeyr909e9722017-12-07 03:54:01 +01001486 algorithm = atoi(test_case[0]);
1487 test_case += 2;
1488 fprintf(stderr, "--------------------\n");
1489
1490 /* Disable the congestion check timer, we will trigger manually. */
1491 bsc_gsmnet->hodec2.congestion_check_interval_s = 0;
1492
1493 handover_decision_1_init();
1494 hodec2_init(bsc_gsmnet);
1495
1496 while (*test_case) {
1497 if (!strcmp(*test_case, "create-bts")) {
1498 static int arfcn = 870;
1499 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++)
1503 bts[bts_num + i] = create_bts(arfcn++);
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) {}