blob: 6217ca3e75aafd6864d8a679003a4356941ac85e [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
Pau Espin Pedrole2490452018-03-17 01:16:54 +010030#include <osmocom/mgcp_client/mgcp_client_fsm.h>
31
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>
48#include <osmocom/bsc/mgw_endpoint_fsm.h>
49#include <osmocom/bsc/handover_fsm.h>
50#include <osmocom/bsc/bsc_msc_data.h>
Neels Hofmeyr909e9722017-12-07 03:54:01 +010051
Neels Hofmeyre3416182018-03-05 05:31:14 +010052void *ctx;
53
Neels Hofmeyr909e9722017-12-07 03:54:01 +010054struct gsm_network *bsc_gsmnet;
55
Neels Hofmeyr31f525e2018-05-14 18:14:15 +020056/* override, requires '-Wl,--wrap=mgw_endpoint_ci_request'.
Harald Welte3561bd42018-01-28 03:04:16 +010057 * Catch modification of an MGCP connection. */
Neels Hofmeyr31f525e2018-05-14 18:14:15 +020058void __real_mgw_endpoint_ci_request(struct mgwep_ci *ci,
59 enum mgcp_verb verb, const struct mgcp_conn_peer *verb_info,
60 struct osmo_fsm_inst *notify,
61 uint32_t event_success, uint32_t event_failure,
62 void *notify_data);
63void __wrap_mgw_endpoint_ci_request(struct mgwep_ci *ci,
64 enum mgcp_verb verb, const struct mgcp_conn_peer *verb_info,
65 struct osmo_fsm_inst *notify,
66 uint32_t event_success, uint32_t event_failure,
67 void *notify_data)
Harald Welte3561bd42018-01-28 03:04:16 +010068{
Neels Hofmeyr31f525e2018-05-14 18:14:15 +020069 struct mgcp_conn_peer fake_data = {};
70 /* All MGCP shall be successful */
71 if (!notify)
72 return;
73 osmo_fsm_inst_dispatch(notify, event_success, &fake_data);
Harald Welte3561bd42018-01-28 03:04:16 +010074}
75
Neels Hofmeyr909e9722017-12-07 03:54:01 +010076/* measurement report */
77
78uint8_t meas_rep_ba = 0, meas_rep_valid = 1, meas_valid = 1, meas_multi_rep = 0;
79uint8_t meas_dl_rxlev = 0, meas_dl_rxqual = 0;
80uint8_t meas_ul_rxlev = 0, meas_ul_rxqual = 0;
81uint8_t meas_tx_power_ms = 0, meas_tx_power_bs = 0, meas_ta_ms = 0;
82uint8_t meas_dtx_ms = 0, meas_dtx_bs = 0, meas_nr = 0;
83uint8_t meas_num_nc = 0, meas_rxlev_nc[6], meas_bsic_nc[6], meas_bcch_f_nc[6];
84
85static void gen_meas_rep(struct gsm_lchan *lchan)
86{
87 struct msgb *msg = msgb_alloc_headroom(256, 64, "RSL");
88 struct abis_rsl_dchan_hdr *dh;
89 uint8_t chan_nr = gsm_lchan2chan_nr(lchan);
90 uint8_t ulm[3], l1i[2], *buf;
91 struct gsm48_hdr *gh;
92 struct gsm48_meas_res *mr;
93
94 dh = (struct abis_rsl_dchan_hdr *) msgb_put(msg, sizeof(*dh));
95 dh->c.msg_discr = ABIS_RSL_MDISC_DED_CHAN;
96 dh->c.msg_type = RSL_MT_MEAS_RES;
97 dh->ie_chan = RSL_IE_CHAN_NR;
98 dh->chan_nr = chan_nr;
99
100 msgb_tv_put(msg, RSL_IE_MEAS_RES_NR, meas_nr++);
101
102 ulm[0] = meas_ul_rxlev | (meas_dtx_bs << 7);
103 ulm[1] = meas_ul_rxlev;
104 ulm[2] = (meas_ul_rxqual << 3) | meas_ul_rxqual;
105 msgb_tlv_put(msg, RSL_IE_UPLINK_MEAS, sizeof(ulm), ulm);
106
107 msgb_tv_put(msg, RSL_IE_BS_POWER, meas_tx_power_bs);
108
109 l1i[0] = 0;
110 l1i[1] = meas_ta_ms;
111 msgb_tv_fixed_put(msg, RSL_IE_L1_INFO, sizeof(l1i), l1i);
112
113 buf = msgb_put(msg, 3);
114 buf[0] = RSL_IE_L3_INFO;
115 buf[1] = (sizeof(*gh) + sizeof(*mr)) >> 8;
116 buf[2] = (sizeof(*gh) + sizeof(*mr)) & 0xff;
117
118 gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
119 mr = (struct gsm48_meas_res *) msgb_put(msg, sizeof(*mr));
120
121 gh->proto_discr = GSM48_PDISC_RR;
122 gh->msg_type = GSM48_MT_RR_MEAS_REP;
123
124 /* measurement results */
125 mr->rxlev_full = meas_dl_rxlev;
126 mr->rxlev_sub = meas_dl_rxlev;
127 mr->rxqual_full = meas_dl_rxqual;
128 mr->rxqual_sub = meas_dl_rxqual;
129 mr->dtx_used = meas_dtx_ms;
130 mr->ba_used = meas_rep_ba;
131 mr->meas_valid = !meas_valid; /* 0 = valid */
132 if (meas_rep_valid) {
133 mr->no_nc_n_hi = meas_num_nc >> 2;
134 mr->no_nc_n_lo = meas_num_nc & 3;
135 } else {
136 /* no results for serving cells */
137 mr->no_nc_n_hi = 1;
138 mr->no_nc_n_lo = 3;
139 }
140 mr->rxlev_nc1 = meas_rxlev_nc[0];
141 mr->rxlev_nc2_hi = meas_rxlev_nc[1] >> 1;
142 mr->rxlev_nc2_lo = meas_rxlev_nc[1] & 1;
143 mr->rxlev_nc3_hi = meas_rxlev_nc[2] >> 2;
144 mr->rxlev_nc3_lo = meas_rxlev_nc[2] & 3;
145 mr->rxlev_nc4_hi = meas_rxlev_nc[3] >> 3;
146 mr->rxlev_nc4_lo = meas_rxlev_nc[3] & 7;
147 mr->rxlev_nc5_hi = meas_rxlev_nc[4] >> 4;
148 mr->rxlev_nc5_lo = meas_rxlev_nc[4] & 15;
149 mr->rxlev_nc6_hi = meas_rxlev_nc[5] >> 5;
150 mr->rxlev_nc6_lo = meas_rxlev_nc[5] & 31;
151 mr->bsic_nc1_hi = meas_bsic_nc[0] >> 3;
152 mr->bsic_nc1_lo = meas_bsic_nc[0] & 7;
153 mr->bsic_nc2_hi = meas_bsic_nc[1] >> 4;
154 mr->bsic_nc2_lo = meas_bsic_nc[1] & 15;
155 mr->bsic_nc3_hi = meas_bsic_nc[2] >> 5;
156 mr->bsic_nc3_lo = meas_bsic_nc[2] & 31;
157 mr->bsic_nc4 = meas_bsic_nc[3];
158 mr->bsic_nc5 = meas_bsic_nc[4];
159 mr->bsic_nc6 = meas_bsic_nc[5];
160 mr->bcch_f_nc1 = meas_bcch_f_nc[0];
161 mr->bcch_f_nc2 = meas_bcch_f_nc[1];
162 mr->bcch_f_nc3 = meas_bcch_f_nc[2];
163 mr->bcch_f_nc4 = meas_bcch_f_nc[3];
164 mr->bcch_f_nc5_hi = meas_bcch_f_nc[4] >> 1;
165 mr->bcch_f_nc5_lo = meas_bcch_f_nc[4] & 1;
166 mr->bcch_f_nc6_hi = meas_bcch_f_nc[5] >> 2;
167 mr->bcch_f_nc6_lo = meas_bcch_f_nc[5] & 3;
168
169 msg->dst = lchan->ts->trx->bts->c0->rsl_link;
170 msg->l2h = (unsigned char *)dh;
171 msg->l3h = (unsigned char *)gh;
172
173 abis_rsl_rcvmsg(msg);
174}
175
176static struct gsm_bts *create_bts(int arfcn)
177{
178 struct gsm_bts *bts;
179 struct e1inp_sign_link *rsl_link;
180 int i;
181
Neels Hofmeyr958f2592018-05-27 01:26:31 +0200182 bts = bsc_bts_alloc_register(bsc_gsmnet, GSM_BTS_TYPE_OSMOBTS, 0x3f);
Neels Hofmeyr909e9722017-12-07 03:54:01 +0100183 if (!bts) {
184 printf("No resource for bts1\n");
185 return NULL;
186 }
187
188 bts->location_area_code = 23;
189 bts->c0->arfcn = arfcn;
190
191 bts->codec.efr = 1;
192 bts->codec.hr = 1;
193 bts->codec.amr = 1;
194
Neels Hofmeyre3416182018-03-05 05:31:14 +0100195 rsl_link = talloc_zero(ctx, struct e1inp_sign_link);
Neels Hofmeyr909e9722017-12-07 03:54:01 +0100196 rsl_link->trx = bts->c0;
197 bts->c0->rsl_link = rsl_link;
198
199 bts->c0->mo.nm_state.operational = NM_OPSTATE_ENABLED;
200 bts->c0->mo.nm_state.availability = NM_AVSTATE_OK;
201 bts->c0->bb_transc.mo.nm_state.operational = NM_OPSTATE_ENABLED;
202 bts->c0->bb_transc.mo.nm_state.availability = NM_AVSTATE_OK;
203
204 /* 4 full rate and 4 half rate channels */
205 for (i = 1; i <= 6; i++) {
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200206 bts->c0->ts[i].pchan_from_config = (i < 5) ? GSM_PCHAN_TCH_F : GSM_PCHAN_TCH_H;
Neels Hofmeyr909e9722017-12-07 03:54:01 +0100207 bts->c0->ts[i].mo.nm_state.operational = NM_OPSTATE_ENABLED;
208 bts->c0->ts[i].mo.nm_state.availability = NM_AVSTATE_OK;
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200209 }
210
211 for (i = 0; i < ARRAY_SIZE(bts->c0->ts); i++) {
212 /* make sure ts->lchans[] get initialized */
Neels Hofmeyrbcdbfb72018-07-26 20:33:15 +0200213 osmo_fsm_inst_dispatch(bts->c0->ts[i].fi, TS_EV_RSL_READY, 0);
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200214 osmo_fsm_inst_dispatch(bts->c0->ts[i].fi, TS_EV_OML_READY, 0);
Neels Hofmeyr909e9722017-12-07 03:54:01 +0100215 }
216 return bts;
217}
218
219void create_conn(struct gsm_lchan *lchan)
220{
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200221 static struct bsc_msc_data fake_msc_data = {};
Philipp Maier0a4d2e52018-11-12 09:50:05 +0100222 fake_msc_data.network = bsc_gsmnet;
Neels Hofmeyrbb6c13b2018-05-24 18:43:58 +0200223 static unsigned int next_imsi = 0;
224 char imsi[sizeof(lchan->conn->bsub->imsi)];
225 struct gsm_network *net = lchan->ts->trx->bts->network;
Harald Welte3561bd42018-01-28 03:04:16 +0100226 struct gsm_subscriber_connection *conn;
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200227 struct mgcp_client *fake_mgcp_client = (void*)talloc_zero(net, int);
Philipp Maier9108d472018-10-23 09:33:19 +0200228 uint8_t *amr_conf;
229
230 /* HACK: lchan_fsm.c requires some AMR codec rates to be enabled,
231 * lets pretend that all AMR codec rates are allowed */
232 amr_conf = (uint8_t*) &fake_msc_data.amr_conf;
233 amr_conf[1] = 0xff;
Neels Hofmeyrbb6c13b2018-05-24 18:43:58 +0200234
235 conn = bsc_subscr_con_allocate(net);
Harald Welte3561bd42018-01-28 03:04:16 +0100236
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200237 conn->user_plane.mgw_endpoint = mgw_endpoint_alloc(conn->fi,
238 GSCON_EV_FORGET_MGW_ENDPOINT,
239 fake_mgcp_client, "test",
240 "fake endpoint");
241 conn->sccp.msc = &fake_msc_data;
Harald Welte3561bd42018-01-28 03:04:16 +0100242
243 lchan->conn = conn;
244 conn->lchan = lchan;
Neels Hofmeyrbb6c13b2018-05-24 18:43:58 +0200245
246 /* Make up a new IMSI for this test, for logging the subscriber */
247 next_imsi ++;
248 snprintf(imsi, sizeof(imsi), "%06u", next_imsi);
249 lchan->conn->bsub = bsc_subscr_find_or_create_by_imsi(net->bsc_subscribers, imsi);
250
Harald Welte3561bd42018-01-28 03:04:16 +0100251 /* kick the FSM from INIT through to the ACTIVE state */
252 osmo_fsm_inst_dispatch(conn->fi, GSCON_EV_A_CONN_REQ, NULL);
253 osmo_fsm_inst_dispatch(conn->fi, GSCON_EV_A_CONN_CFM, NULL);
Neels Hofmeyr909e9722017-12-07 03:54:01 +0100254}
255
256/* create lchan */
257struct gsm_lchan *create_lchan(struct gsm_bts *bts, int full_rate, char *codec)
258{
259 struct gsm_lchan *lchan;
260
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200261 lchan = lchan_select_by_type(bts, (full_rate) ? GSM_LCHAN_TCH_F : GSM_LCHAN_TCH_H);
Neels Hofmeyr909e9722017-12-07 03:54:01 +0100262 if (!lchan) {
263 printf("No resource for lchan\n");
264 exit(EXIT_FAILURE);
265 }
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200266
267 /* serious hack into osmo_fsm */
268 lchan->fi->state = LCHAN_ST_ESTABLISHED;
269 lchan->ts->fi->state = TS_ST_IN_USE;
270 LOG_LCHAN(lchan, LOGL_DEBUG, "activated by handover_test.c\n");
271
Neels Hofmeyr909e9722017-12-07 03:54:01 +0100272 create_conn(lchan);
273 if (!strcasecmp(codec, "FR") && full_rate)
274 lchan->tch_mode = GSM48_CMODE_SPEECH_V1;
275 else if (!strcasecmp(codec, "HR") && !full_rate)
276 lchan->tch_mode = GSM48_CMODE_SPEECH_V1;
277 else if (!strcasecmp(codec, "EFR") && full_rate)
278 lchan->tch_mode = GSM48_CMODE_SPEECH_EFR;
279 else if (!strcasecmp(codec, "AMR"))
280 lchan->tch_mode = GSM48_CMODE_SPEECH_AMR;
281 else {
282 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"
697 "ammount of improvement is greater or equal hyteresis\n",
698
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.
818 * See Performence Enhancements in a Frequency Hopping GSM Network (Nielsen Wigard 2002), Chapter
819 * 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",
952 "expect-ho", "0", "3", /* best candidate is MS 2 at BTS 1, TS 3 */
953 "ho-complete",
954 NULL
955};
956
957static char *test_case_19[] = {
958 "2",
959
960 "Congestion check: Balancing over congested cells\n\n"
961 "Two cells are congested, but the second cell is more congested.\n"
962 "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"
1143 "As soon as enough measurments available (1 in our case), perform\n"
1144 "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
1291static char **test_cases[] = {
1292 test_case_0,
1293 test_case_1,
1294 test_case_2,
1295 test_case_3,
1296 test_case_4,
1297 test_case_5,
1298 test_case_6,
1299 test_case_7,
1300 test_case_8,
1301 test_case_9,
1302 test_case_10,
1303 test_case_11,
1304 test_case_12,
1305 test_case_13,
1306 test_case_14,
1307 test_case_15,
1308 test_case_16,
1309 test_case_17,
1310 test_case_18,
1311 test_case_19,
1312 test_case_20,
1313 test_case_21,
1314 test_case_22,
1315 test_case_23,
1316 test_case_24,
1317 test_case_25,
1318 test_case_26,
1319 test_case_27,
1320 test_case_28,
Neels Hofmeyr909e9722017-12-07 03:54:01 +01001321};
1322
1323static const struct log_info_cat log_categories[] = {
1324 [DHO] = {
1325 .name = "DHO",
1326 .description = "Hand-Over Process",
1327 .color = "\033[1;38m",
1328 .enabled = 1, .loglevel = LOGL_DEBUG,
1329 },
1330 [DHODEC] = {
1331 .name = "DHODEC",
1332 .description = "Hand-Over Decision",
1333 .color = "\033[1;38m",
1334 .enabled = 1, .loglevel = LOGL_DEBUG,
1335 },
1336 [DMEAS] = {
1337 .name = "DMEAS",
1338 .description = "Radio Measurement Processing",
1339 .enabled = 1, .loglevel = LOGL_DEBUG,
1340 },
1341 [DREF] = {
1342 .name = "DREF",
1343 .description = "Reference Counting",
1344 .enabled = 1, .loglevel = LOGL_DEBUG,
1345 },
1346 [DRSL] = {
1347 .name = "DRSL",
Keithd925c7c2018-04-16 13:40:07 +02001348 .description = "A-bis Radio Signalling Link (RSL)",
Neels Hofmeyr909e9722017-12-07 03:54:01 +01001349 .color = "\033[1;35m",
1350 .enabled = 1, .loglevel = LOGL_DEBUG,
1351 },
Neels Hofmeyr31f525e2018-05-14 18:14:15 +02001352 [DRR] = {
1353 .name = "DRR",
1354 .description = "RR",
1355 .color = "\033[1;35m",
1356 .enabled = 1, .loglevel = LOGL_DEBUG,
1357 },
1358 [DRLL] = {
1359 .name = "DRLL",
1360 .description = "RLL",
1361 .color = "\033[1;35m",
1362 .enabled = 1, .loglevel = LOGL_DEBUG,
1363 },
Harald Welte3561bd42018-01-28 03:04:16 +01001364 [DMSC] = {
1365 .name = "DMSC",
1366 .description = "Mobile Switching Center",
1367 .enabled = 1, .loglevel = LOGL_DEBUG,
1368 },
Neels Hofmeyr3c5612f2018-07-11 19:53:39 +02001369 [DCHAN] = {
1370 .name = "DCHAN",
1371 .description = "lchan FSM",
1372 .color = "\033[1;32m",
1373 .enabled = 1, .loglevel = LOGL_DEBUG,
1374 },
1375 [DTS] = {
1376 .name = "DTS",
1377 .description = "timeslot FSM",
1378 .color = "\033[1;31m",
1379 .enabled = 1, .loglevel = LOGL_DEBUG,
1380 },
1381 [DAS] = {
1382 .name = "DAS",
1383 .description = "assignment FSM",
1384 .color = "\033[1;33m",
1385 .enabled = 1, .loglevel = LOGL_DEBUG,
1386 },
Neels Hofmeyr909e9722017-12-07 03:54:01 +01001387};
1388
1389const struct log_info log_info = {
1390 .cat = log_categories,
1391 .num_cat = ARRAY_SIZE(log_categories),
1392};
1393
1394int main(int argc, char **argv)
1395{
1396 char **test_case;
1397 struct gsm_bts *bts[256];
1398 int bts_num = 0;
1399 struct gsm_lchan *lchan[256];
1400 int lchan_num = 0;
Neels Hofmeyr909e9722017-12-07 03:54:01 +01001401 int i;
Neels Hofmeyr958f2592018-05-27 01:26:31 +02001402 int algorithm;
Neels Hofmeyr00727552018-02-21 14:33:15 +01001403 int test_case_i;
1404 int last_test_i;
Neels Hofmeyr909e9722017-12-07 03:54:01 +01001405
Neels Hofmeyre3416182018-03-05 05:31:14 +01001406 ctx = talloc_named_const(NULL, 0, "handover_test");
1407 msgb_talloc_ctx_init(ctx, 0);
1408
Neels Hofmeyr00727552018-02-21 14:33:15 +01001409 test_case_i = argc > 1? atoi(argv[1]) : -1;
1410 last_test_i = ARRAY_SIZE(test_cases) - 1;
Neels Hofmeyr909e9722017-12-07 03:54:01 +01001411
Neels Hofmeyr00727552018-02-21 14:33:15 +01001412 if (test_case_i < 0 || test_case_i > last_test_i) {
1413 for (i = 0; i <= last_test_i; i++) {
Neels Hofmeyr909e9722017-12-07 03:54:01 +01001414 printf("Test #%d (algorithm %s):\n%s\n", i,
1415 test_cases[i][0], test_cases[i][1]);
1416 }
Neels Hofmeyr00727552018-02-21 14:33:15 +01001417 printf("\nPlease specify test case number 0..%d\n", last_test_i);
Neels Hofmeyr909e9722017-12-07 03:54:01 +01001418 return EXIT_FAILURE;
1419 }
1420
Neels Hofmeyre3416182018-03-05 05:31:14 +01001421 osmo_init_logging2(ctx, &log_info);
Neels Hofmeyr909e9722017-12-07 03:54:01 +01001422
1423 log_set_print_category(osmo_stderr_target, 1);
1424 log_set_print_category_hex(osmo_stderr_target, 0);
1425 log_set_print_filename2(osmo_stderr_target, LOG_FILENAME_BASENAME);
Neels Hofmeyr31f525e2018-05-14 18:14:15 +02001426 osmo_fsm_log_addr(false);
Neels Hofmeyr909e9722017-12-07 03:54:01 +01001427
Neels Hofmeyr958f2592018-05-27 01:26:31 +02001428 bsc_network_alloc();
Neels Hofmeyr909e9722017-12-07 03:54:01 +01001429 if (!bsc_gsmnet)
1430 exit(1);
1431
Neels Hofmeyr31f525e2018-05-14 18:14:15 +02001432 ts_fsm_init();
1433 lchan_fsm_init();
1434 mgw_endpoint_fsm_init(bsc_gsmnet->T_defs);
1435 bsc_subscr_conn_fsm_init();
1436 handover_fsm_init();
1437
Neels Hofmeyr909e9722017-12-07 03:54:01 +01001438 ho_set_algorithm(bsc_gsmnet->ho, 2);
1439 ho_set_ho_active(bsc_gsmnet->ho, true);
1440 ho_set_hodec2_as_active(bsc_gsmnet->ho, true);
1441 ho_set_hodec2_min_rxlev(bsc_gsmnet->ho, -100);
1442 ho_set_hodec2_rxlev_avg_win(bsc_gsmnet->ho, 1);
1443 ho_set_hodec2_rxlev_neigh_avg_win(bsc_gsmnet->ho, 1);
1444 ho_set_hodec2_rxqual_avg_win(bsc_gsmnet->ho, 10);
1445 ho_set_hodec2_pwr_hysteresis(bsc_gsmnet->ho, 3);
1446 ho_set_hodec2_pwr_interval(bsc_gsmnet->ho, 1);
1447 ho_set_hodec2_afs_bias_rxlev(bsc_gsmnet->ho, 0);
1448 ho_set_hodec2_min_rxqual(bsc_gsmnet->ho, 5);
1449 ho_set_hodec2_afs_bias_rxqual(bsc_gsmnet->ho, 0);
1450 ho_set_hodec2_max_distance(bsc_gsmnet->ho, 9999);
1451 ho_set_hodec2_ho_max(bsc_gsmnet->ho, 9999);
1452 ho_set_hodec2_penalty_max_dist(bsc_gsmnet->ho, 300);
1453 ho_set_hodec2_penalty_failed_ho(bsc_gsmnet->ho, 60);
1454 ho_set_hodec2_penalty_failed_as(bsc_gsmnet->ho, 60);
1455
1456 bts_model_sysmobts_init();
1457
Neels Hofmeyr00727552018-02-21 14:33:15 +01001458 test_case = test_cases[test_case_i];
Neels Hofmeyr909e9722017-12-07 03:54:01 +01001459
1460 fprintf(stderr, "--------------------\n");
1461 fprintf(stderr, "Performing the following test %d (algorithm %s):\n%s",
Neels Hofmeyr00727552018-02-21 14:33:15 +01001462 test_case_i, test_case[0], test_case[1]);
Neels Hofmeyr909e9722017-12-07 03:54:01 +01001463 algorithm = atoi(test_case[0]);
1464 test_case += 2;
1465 fprintf(stderr, "--------------------\n");
1466
1467 /* Disable the congestion check timer, we will trigger manually. */
1468 bsc_gsmnet->hodec2.congestion_check_interval_s = 0;
1469
1470 handover_decision_1_init();
1471 hodec2_init(bsc_gsmnet);
1472
1473 while (*test_case) {
1474 if (!strcmp(*test_case, "create-bts")) {
1475 static int arfcn = 870;
1476 int n = atoi(test_case[1]);
1477 fprintf(stderr, "- Creating %d BTS (one TRX each, "
1478 "TS(1-4) are TCH/F, TS(5-6) are TCH/H)\n", n);
1479 for (i = 0; i < n; i++)
1480 bts[bts_num + i] = create_bts(arfcn++);
Neels Hofmeyr00727552018-02-21 14:33:15 +01001481 for (i = 0; i < n; i++) {
Neels Hofmeyr31f525e2018-05-14 18:14:15 +02001482 if (gsm_generate_si(bts[bts_num + i], SYSINFO_TYPE_2) <= 0)
Neels Hofmeyr00727552018-02-21 14:33:15 +01001483 fprintf(stderr, "Error generating SI2\n");
1484 }
Neels Hofmeyr909e9722017-12-07 03:54:01 +01001485 bts_num += n;
1486 test_case += 2;
1487 } else
1488 if (!strcmp(*test_case, "as-enable")) {
1489 fprintf(stderr, "- Set assignment enable state at "
1490 "BTS %s to %s\n", test_case[1], test_case[2]);
1491 ho_set_hodec2_as_active(bts[atoi(test_case[1])]->ho, atoi(test_case[2]));
1492 test_case += 3;
1493 } else
1494 if (!strcmp(*test_case, "ho-enable")) {
1495 fprintf(stderr, "- Set handover enable state at "
1496 "BTS %s to %s\n", test_case[1], test_case[2]);
1497 ho_set_ho_active(bts[atoi(test_case[1])]->ho, atoi(test_case[2]));
1498 test_case += 3;
1499 } else
1500 if (!strcmp(*test_case, "afs-rxlev-improve")) {
1501 fprintf(stderr, "- Set afs RX level improvement at "
1502 "BTS %s to %s\n", test_case[1], test_case[2]);
1503 ho_set_hodec2_afs_bias_rxlev(bts[atoi(test_case[1])]->ho, atoi(test_case[2]));
1504 test_case += 3;
1505 } else
1506 if (!strcmp(*test_case, "afs-rxqual-improve")) {
1507 fprintf(stderr, "- Set afs RX quality improvement at "
1508 "BTS %s to %s\n", test_case[1], test_case[2]);
1509 ho_set_hodec2_afs_bias_rxqual(bts[atoi(test_case[1])]->ho, atoi(test_case[2]));
1510 test_case += 3;
1511 } else
1512 if (!strcmp(*test_case, "set-min-free")) {
1513 fprintf(stderr, "- Setting minimum required free %s "
1514 "slots at BTS %s to %s\n", test_case[2],
1515 test_case[1], test_case[3]);
1516 if (!strcmp(test_case[2], "TCH/F"))
1517 ho_set_hodec2_tchf_min_slots(bts[atoi(test_case[1])]->ho, atoi(test_case[3]));
1518 else
1519 ho_set_hodec2_tchh_min_slots(bts[atoi(test_case[1])]->ho, atoi(test_case[3]));
1520 test_case += 4;
1521 } else
1522 if (!strcmp(*test_case, "set-max-ho")) {
1523 fprintf(stderr, "- Setting maximum parallel handovers "
1524 "at BTS %s to %s\n", test_case[1],
1525 test_case[2]);
1526 ho_set_hodec2_ho_max( bts[atoi(test_case[1])]->ho, atoi(test_case[2]));
1527 test_case += 3;
1528 } else
1529 if (!strcmp(*test_case, "set-max-ta")) {
1530 fprintf(stderr, "- Setting maximum timing advance "
1531 "at BTS %s to %s\n", test_case[1],
1532 test_case[2]);
1533 ho_set_hodec2_max_distance(bts[atoi(test_case[1])]->ho, atoi(test_case[2]));
1534 test_case += 3;
1535 } else
1536 if (!strcmp(*test_case, "create-ms")) {
1537 fprintf(stderr, "- Creating mobile #%d at BTS %s on "
1538 "%s with %s codec\n", lchan_num, test_case[1],
1539 test_case[2], test_case[3]);
1540 lchan[lchan_num] = create_lchan(bts[atoi(test_case[1])],
1541 !strcmp(test_case[2], "TCH/F"), test_case[3]);
1542 if (!lchan[lchan_num]) {
1543 printf("Failed to create lchan!\n");
1544 return EXIT_FAILURE;
1545 }
1546 fprintf(stderr, " * New MS is at BTS %d TS %d\n",
1547 lchan[lchan_num]->ts->trx->bts->nr,
1548 lchan[lchan_num]->ts->nr);
1549 lchan_num++;
1550 test_case += 4;
1551 } else
1552 if (!strcmp(*test_case, "set-ta")) {
1553 fprintf(stderr, "- Setting maximum timing advance "
1554 "at MS %s to %s\n", test_case[1],
1555 test_case[2]);
1556 meas_ta_ms = atoi(test_case[2]);
1557 test_case += 3;
1558 } else
1559 if (!strcmp(*test_case, "meas-rep")) {
1560 /* meas-rep <lchan-nr> <rxlev> <rxqual> <nr-of-neighbors> [<cell-idx> <rxlev> [...]] */
1561 int n = atoi(test_case[4]);
1562 struct gsm_lchan *lc = lchan[atoi(test_case[1])];
1563 fprintf(stderr, "- Sending measurement report from "
1564 "mobile #%s (rxlev=%s, rxqual=%s)\n",
1565 test_case[1], test_case[2], test_case[3]);
1566 meas_dl_rxlev = atoi(test_case[2]);
1567 meas_dl_rxqual = atoi(test_case[3]);
1568 meas_num_nc = n;
1569 test_case += 5;
1570 for (i = 0; i < n; i++) {
1571 int nr = atoi(test_case[0]);
1572 /* since our bts is not in the list of neighbor
1573 * cells, we need to shift */
1574 if (nr >= lc->ts->trx->bts->nr)
1575 nr++;
1576 fprintf(stderr, " * Neighbor cell #%s, actual "
1577 "BTS %d (rxlev=%s)\n", test_case[0], nr,
1578 test_case[1]);
1579 meas_bcch_f_nc[i] = atoi(test_case[0]);
1580 /* bts number, not counting our own */
1581 meas_rxlev_nc[i] = atoi(test_case[1]);
1582 meas_bsic_nc[i] = 0x3f;
1583 test_case += 2;
1584 }
1585 got_chan_req = 0;
1586 gen_meas_rep(lc);
1587 } else
1588 if (!strcmp(*test_case, "congestion-check")) {
1589 fprintf(stderr, "- Triggering congestion check\n");
1590 got_chan_req = 0;
1591 if (algorithm == 2)
1592 hodec2_congestion_check(bsc_gsmnet);
1593 test_case += 1;
1594 } else
1595 if (!strcmp(*test_case, "expect-chan")) {
1596 fprintf(stderr, "- Expecting channel request at BTS %s "
1597 "TS %s\n", test_case[1], test_case[2]);
1598 if (!got_chan_req) {
1599 printf("Test failed, because no channel was "
1600 "requested\n");
1601 return EXIT_FAILURE;
1602 }
1603 fprintf(stderr, " * Got channel request at BTS %d "
1604 "TS %d\n", chan_req_lchan->ts->trx->bts->nr,
1605 chan_req_lchan->ts->nr);
1606 if (chan_req_lchan->ts->trx->bts->nr
1607 != atoi(test_case[1])) {
1608 printf("Test failed, because channel was not "
1609 "requested on expected BTS\n");
1610 return EXIT_FAILURE;
1611 }
1612 if (chan_req_lchan->ts->nr != atoi(test_case[2])) {
1613 printf("Test failed, because channel was not "
1614 "requested on expected TS\n");
1615 return EXIT_FAILURE;
1616 }
1617 test_case += 3;
1618 } else
1619 if (!strcmp(*test_case, "expect-no-chan")) {
1620 fprintf(stderr, "- Expecting no channel request\n");
1621 if (got_chan_req) {
1622 fprintf(stderr, " * Got channel request at "
1623 "BTS %d TS %d\n",
1624 chan_req_lchan->ts->trx->bts->nr,
1625 chan_req_lchan->ts->nr);
1626 printf("Test failed, because channel was "
1627 "requested\n");
1628 return EXIT_FAILURE;
1629 }
1630 fprintf(stderr, " * Got no channel request\n");
1631 test_case += 1;
1632 } else
1633 if (!strcmp(*test_case, "expect-ho")) {
1634 fprintf(stderr, "- Expecting handover/assignment "
1635 "request at BTS %s TS %s\n", test_case[1],
1636 test_case[2]);
1637 if (!got_ho_req) {
1638 printf("Test failed, because no handover was "
1639 "requested\n");
1640 return EXIT_FAILURE;
1641 }
1642 fprintf(stderr, " * Got handover/assignment request at "
1643 "BTS %d TS %d\n",
1644 ho_req_lchan->ts->trx->bts->nr,
1645 ho_req_lchan->ts->nr);
1646 if (ho_req_lchan->ts->trx->bts->nr
1647 != atoi(test_case[1])) {
1648 printf("Test failed, because "
1649 "handover/assignment was not commanded "
1650 "at the expected BTS\n");
1651 return EXIT_FAILURE;
1652 }
1653 if (ho_req_lchan->ts->nr != atoi(test_case[2])) {
1654 printf("Test failed, because "
1655 "handover/assignment was not commanded "
1656 "at the expected TS\n");
1657 return EXIT_FAILURE;
1658 }
1659 test_case += 3;
1660 } else
1661 if (!strcmp(*test_case, "ack-chan")) {
1662 fprintf(stderr, "- Acknowledging channel request\n");
1663 if (!got_chan_req) {
1664 printf("Cannot ack channel, because no "
1665 "request\n");
1666 return EXIT_FAILURE;
1667 }
1668 test_case += 1;
1669 got_ho_req = 0;
1670 send_chan_act_ack(chan_req_lchan, 1);
1671 } else
1672 if (!strcmp(*test_case, "ho-complete")) {
1673 fprintf(stderr, "- Acknowledging handover/assignment "
1674 "request\n");
1675 if (!got_chan_req) {
1676 printf("Cannot ack handover/assignment, "
1677 "because no chan request\n");
1678 return EXIT_FAILURE;
1679 }
1680 if (!got_ho_req) {
1681 printf("Cannot ack handover/assignment, "
1682 "because no ho request\n");
1683 return EXIT_FAILURE;
1684 }
1685 test_case += 1;
1686 got_chan_req = 0;
1687 got_ho_req = 0;
1688 /* switch lchan */
1689 for (i = 0; i < lchan_num; i++) {
1690 if (lchan[i] == ho_req_lchan) {
1691 fprintf(stderr, " * MS %d changes from "
1692 "BTS=%d TS=%d to BTS=%d "
1693 "TS=%d\n", i,
1694 lchan[i]->ts->trx->bts->nr,
1695 lchan[i]->ts->nr,
1696 chan_req_lchan->ts->trx->bts->nr,
1697 chan_req_lchan->ts->nr);
1698 lchan[i] = chan_req_lchan;
1699 }
1700 }
1701 send_ho_complete(chan_req_lchan, true);
1702 } else
1703 if (!strcmp(*test_case, "ho-failed")) {
1704 fprintf(stderr, "- Making handover fail\n");
1705 if (!got_chan_req) {
1706 printf("Cannot fail handover, because no chan "
1707 "request\n");
1708 return EXIT_FAILURE;
1709 }
1710 test_case += 1;
1711 got_chan_req = 0;
1712 got_ho_req = 0;
1713 send_ho_complete(ho_req_lchan, false);
1714 } else
1715 if (!strcmp(*test_case, "print")) {
1716 fprintf(stderr, "\n%s\n\n", test_case[1]);
1717 test_case += 2;
1718 } else {
1719 printf("Unknown test command '%s', please fix!\n",
1720 *test_case);
1721 return EXIT_FAILURE;
1722 }
Neels Hofmeyr31f525e2018-05-14 18:14:15 +02001723
1724 {
1725 /* Help the lchan out of releasing states */
1726 struct gsm_bts *bts;
1727 llist_for_each_entry(bts, &bsc_gsmnet->bts_list, list) {
1728 struct gsm_bts_trx *trx;
1729 llist_for_each_entry(trx, &bts->trx_list, list) {
1730 int ts_nr;
1731 for (ts_nr = 0; ts_nr < TRX_NR_TS; ts_nr++) {
1732 struct gsm_lchan *lchan;
1733 ts_for_each_lchan(lchan, &trx->ts[ts_nr]) {
1734
1735 if (lchan->fi && lchan->fi->state == LCHAN_ST_WAIT_BEFORE_RF_RELEASE) {
1736 osmo_fsm_inst_state_chg(lchan->fi, LCHAN_ST_WAIT_RF_RELEASE_ACK, 0, 0);
1737 osmo_fsm_inst_dispatch(lchan->fi, LCHAN_EV_RSL_RF_CHAN_REL_ACK, 0);
1738 }
1739 }
1740 }
1741 }
1742 }
1743 }
Neels Hofmeyr909e9722017-12-07 03:54:01 +01001744 }
1745
1746 for (i = 0; i < lchan_num; i++) {
1747 struct gsm_subscriber_connection *conn = lchan[i]->conn;
1748 lchan[i]->conn = NULL;
1749 conn->lchan = NULL;
Harald Welte3561bd42018-01-28 03:04:16 +01001750 osmo_fsm_inst_term(conn->fi, OSMO_FSM_TERM_REGULAR, NULL);
Neels Hofmeyr909e9722017-12-07 03:54:01 +01001751 }
1752
1753 fprintf(stderr, "--------------------\n");
1754
1755 printf("Test OK\n");
1756
1757 fprintf(stderr, "--------------------\n");
1758
Neels Hofmeyre3416182018-03-05 05:31:14 +01001759 talloc_free(ctx);
Neels Hofmeyr909e9722017-12-07 03:54:01 +01001760 return EXIT_SUCCESS;
1761}
1762
1763void rtp_socket_free() {}
1764void rtp_send_frame() {}
1765void rtp_socket_upstream() {}
1766void rtp_socket_create() {}
1767void rtp_socket_connect() {}
1768void rtp_socket_proxy() {}
1769void trau_mux_unmap() {}
1770void trau_mux_map_lchan() {}
1771void trau_recv_lchan() {}
1772void trau_send_frame() {}
Harald Welte3561bd42018-01-28 03:04:16 +01001773int osmo_bsc_sigtran_send(struct gsm_subscriber_connection *conn, struct msgb *msg) { return 0; }
1774int osmo_bsc_sigtran_open_conn(struct gsm_subscriber_connection *conn, struct msgb *msg) { return 0; }
Neels Hofmeyrc19581f2018-05-27 03:05:18 +02001775void bsc_sapi_n_reject(struct gsm_subscriber_connection *conn, int dlci) {}
1776void bsc_cipher_mode_compl(struct gsm_subscriber_connection *conn, struct msgb *msg, uint8_t chosen_encr) {}
1777int bsc_compl_l3(struct gsm_subscriber_connection *conn, struct msgb *msg, uint16_t chosen_channel)
1778{ return 0; }
1779void bsc_dtap(struct gsm_subscriber_connection *conn, uint8_t link_id, struct msgb *msg) {}
1780void bsc_assign_compl(struct gsm_subscriber_connection *conn, uint8_t rr_cause) {}
Neels Hofmeyrc19581f2018-05-27 03:05:18 +02001781int bsc_clear_request(struct gsm_subscriber_connection *conn, uint32_t cause)
1782{ return 0; }
1783void bsc_cm_update(struct gsm_subscriber_connection *conn,
1784 const uint8_t *cm2, uint8_t cm2_len,
1785 const uint8_t *cm3, uint8_t cm3_len) {}
Neels Hofmeyr31f525e2018-05-14 18:14:15 +02001786struct gsm0808_handover_required;
1787int bsc_tx_bssmap_ho_required(struct gsm_lchan *lchan, const struct gsm0808_cell_id_list2 *target_cells)
1788{ return 0; }
1789int bsc_tx_bssmap_ho_request_ack(struct gsm_subscriber_connection *conn, struct msgb *rr_ho_command)
1790{ return 0; }
1791int bsc_tx_bssmap_ho_detect(struct gsm_subscriber_connection *conn) { return 0; }
1792enum handover_result bsc_tx_bssmap_ho_complete(struct gsm_subscriber_connection *conn,
1793 struct gsm_lchan *lchan) { return HO_RESULT_OK; }
1794void bsc_tx_bssmap_ho_failure(struct gsm_subscriber_connection *conn) {}