blob: f728c5bd8aa40b06740531c875e5931c73ace627 [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 = {};
Neels Hofmeyrbb6c13b2018-05-24 18:43:58 +0200222 static unsigned int next_imsi = 0;
223 char imsi[sizeof(lchan->conn->bsub->imsi)];
224 struct gsm_network *net = lchan->ts->trx->bts->network;
Harald Welte3561bd42018-01-28 03:04:16 +0100225 struct gsm_subscriber_connection *conn;
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200226 struct mgcp_client *fake_mgcp_client = (void*)talloc_zero(net, int);
Philipp Maier9108d472018-10-23 09:33:19 +0200227 uint8_t *amr_conf;
228
229 /* HACK: lchan_fsm.c requires some AMR codec rates to be enabled,
230 * lets pretend that all AMR codec rates are allowed */
231 amr_conf = (uint8_t*) &fake_msc_data.amr_conf;
232 amr_conf[1] = 0xff;
Neels Hofmeyrbb6c13b2018-05-24 18:43:58 +0200233
234 conn = bsc_subscr_con_allocate(net);
Harald Welte3561bd42018-01-28 03:04:16 +0100235
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200236 conn->user_plane.mgw_endpoint = mgw_endpoint_alloc(conn->fi,
237 GSCON_EV_FORGET_MGW_ENDPOINT,
238 fake_mgcp_client, "test",
239 "fake endpoint");
240 conn->sccp.msc = &fake_msc_data;
Harald Welte3561bd42018-01-28 03:04:16 +0100241
242 lchan->conn = conn;
243 conn->lchan = lchan;
Neels Hofmeyrbb6c13b2018-05-24 18:43:58 +0200244
245 /* Make up a new IMSI for this test, for logging the subscriber */
246 next_imsi ++;
247 snprintf(imsi, sizeof(imsi), "%06u", next_imsi);
248 lchan->conn->bsub = bsc_subscr_find_or_create_by_imsi(net->bsc_subscribers, imsi);
249
Harald Welte3561bd42018-01-28 03:04:16 +0100250 /* kick the FSM from INIT through to the ACTIVE state */
251 osmo_fsm_inst_dispatch(conn->fi, GSCON_EV_A_CONN_REQ, NULL);
252 osmo_fsm_inst_dispatch(conn->fi, GSCON_EV_A_CONN_CFM, NULL);
Neels Hofmeyr909e9722017-12-07 03:54:01 +0100253}
254
255/* create lchan */
256struct gsm_lchan *create_lchan(struct gsm_bts *bts, int full_rate, char *codec)
257{
258 struct gsm_lchan *lchan;
259
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200260 lchan = lchan_select_by_type(bts, (full_rate) ? GSM_LCHAN_TCH_F : GSM_LCHAN_TCH_H);
Neels Hofmeyr909e9722017-12-07 03:54:01 +0100261 if (!lchan) {
262 printf("No resource for lchan\n");
263 exit(EXIT_FAILURE);
264 }
Neels Hofmeyr31f525e2018-05-14 18:14:15 +0200265
266 /* serious hack into osmo_fsm */
267 lchan->fi->state = LCHAN_ST_ESTABLISHED;
268 lchan->ts->fi->state = TS_ST_IN_USE;
269 LOG_LCHAN(lchan, LOGL_DEBUG, "activated by handover_test.c\n");
270
Neels Hofmeyr909e9722017-12-07 03:54:01 +0100271 create_conn(lchan);
272 if (!strcasecmp(codec, "FR") && full_rate)
273 lchan->tch_mode = GSM48_CMODE_SPEECH_V1;
274 else if (!strcasecmp(codec, "HR") && !full_rate)
275 lchan->tch_mode = GSM48_CMODE_SPEECH_V1;
276 else if (!strcasecmp(codec, "EFR") && full_rate)
277 lchan->tch_mode = GSM48_CMODE_SPEECH_EFR;
278 else if (!strcasecmp(codec, "AMR"))
279 lchan->tch_mode = GSM48_CMODE_SPEECH_AMR;
280 else {
281 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"
696 "ammount of improvement is greater or equal hyteresis\n",
697
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.
817 * See Performence Enhancements in a Frequency Hopping GSM Network (Nielsen Wigard 2002), Chapter
818 * 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"
960 "Two cells are congested, but the second cell is more congested.\n"
961 "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"
1142 "As soon as enough measurments available (1 in our case), perform\n"
1143 "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
1290static char **test_cases[] = {
1291 test_case_0,
1292 test_case_1,
1293 test_case_2,
1294 test_case_3,
1295 test_case_4,
1296 test_case_5,
1297 test_case_6,
1298 test_case_7,
1299 test_case_8,
1300 test_case_9,
1301 test_case_10,
1302 test_case_11,
1303 test_case_12,
1304 test_case_13,
1305 test_case_14,
1306 test_case_15,
1307 test_case_16,
1308 test_case_17,
1309 test_case_18,
1310 test_case_19,
1311 test_case_20,
1312 test_case_21,
1313 test_case_22,
1314 test_case_23,
1315 test_case_24,
1316 test_case_25,
1317 test_case_26,
1318 test_case_27,
1319 test_case_28,
Neels Hofmeyr909e9722017-12-07 03:54:01 +01001320};
1321
1322static const struct log_info_cat log_categories[] = {
1323 [DHO] = {
1324 .name = "DHO",
1325 .description = "Hand-Over Process",
1326 .color = "\033[1;38m",
1327 .enabled = 1, .loglevel = LOGL_DEBUG,
1328 },
1329 [DHODEC] = {
1330 .name = "DHODEC",
1331 .description = "Hand-Over Decision",
1332 .color = "\033[1;38m",
1333 .enabled = 1, .loglevel = LOGL_DEBUG,
1334 },
1335 [DMEAS] = {
1336 .name = "DMEAS",
1337 .description = "Radio Measurement Processing",
1338 .enabled = 1, .loglevel = LOGL_DEBUG,
1339 },
1340 [DREF] = {
1341 .name = "DREF",
1342 .description = "Reference Counting",
1343 .enabled = 1, .loglevel = LOGL_DEBUG,
1344 },
1345 [DRSL] = {
1346 .name = "DRSL",
Keithd925c7c2018-04-16 13:40:07 +02001347 .description = "A-bis Radio Signalling Link (RSL)",
Neels Hofmeyr909e9722017-12-07 03:54:01 +01001348 .color = "\033[1;35m",
1349 .enabled = 1, .loglevel = LOGL_DEBUG,
1350 },
Neels Hofmeyr31f525e2018-05-14 18:14:15 +02001351 [DRR] = {
1352 .name = "DRR",
1353 .description = "RR",
1354 .color = "\033[1;35m",
1355 .enabled = 1, .loglevel = LOGL_DEBUG,
1356 },
1357 [DRLL] = {
1358 .name = "DRLL",
1359 .description = "RLL",
1360 .color = "\033[1;35m",
1361 .enabled = 1, .loglevel = LOGL_DEBUG,
1362 },
Harald Welte3561bd42018-01-28 03:04:16 +01001363 [DMSC] = {
1364 .name = "DMSC",
1365 .description = "Mobile Switching Center",
1366 .enabled = 1, .loglevel = LOGL_DEBUG,
1367 },
Neels Hofmeyr3c5612f2018-07-11 19:53:39 +02001368 [DCHAN] = {
1369 .name = "DCHAN",
1370 .description = "lchan FSM",
1371 .color = "\033[1;32m",
1372 .enabled = 1, .loglevel = LOGL_DEBUG,
1373 },
1374 [DTS] = {
1375 .name = "DTS",
1376 .description = "timeslot FSM",
1377 .color = "\033[1;31m",
1378 .enabled = 1, .loglevel = LOGL_DEBUG,
1379 },
1380 [DAS] = {
1381 .name = "DAS",
1382 .description = "assignment FSM",
1383 .color = "\033[1;33m",
1384 .enabled = 1, .loglevel = LOGL_DEBUG,
1385 },
Neels Hofmeyr909e9722017-12-07 03:54:01 +01001386};
1387
1388const struct log_info log_info = {
1389 .cat = log_categories,
1390 .num_cat = ARRAY_SIZE(log_categories),
1391};
1392
1393int main(int argc, char **argv)
1394{
1395 char **test_case;
1396 struct gsm_bts *bts[256];
1397 int bts_num = 0;
1398 struct gsm_lchan *lchan[256];
1399 int lchan_num = 0;
Neels Hofmeyr909e9722017-12-07 03:54:01 +01001400 int i;
Neels Hofmeyr958f2592018-05-27 01:26:31 +02001401 int algorithm;
Neels Hofmeyr00727552018-02-21 14:33:15 +01001402 int test_case_i;
1403 int last_test_i;
Neels Hofmeyr909e9722017-12-07 03:54:01 +01001404
Neels Hofmeyre3416182018-03-05 05:31:14 +01001405 ctx = talloc_named_const(NULL, 0, "handover_test");
1406 msgb_talloc_ctx_init(ctx, 0);
1407
Neels Hofmeyr00727552018-02-21 14:33:15 +01001408 test_case_i = argc > 1? atoi(argv[1]) : -1;
1409 last_test_i = ARRAY_SIZE(test_cases) - 1;
Neels Hofmeyr909e9722017-12-07 03:54:01 +01001410
Neels Hofmeyr00727552018-02-21 14:33:15 +01001411 if (test_case_i < 0 || test_case_i > last_test_i) {
1412 for (i = 0; i <= last_test_i; i++) {
Neels Hofmeyr909e9722017-12-07 03:54:01 +01001413 printf("Test #%d (algorithm %s):\n%s\n", i,
1414 test_cases[i][0], test_cases[i][1]);
1415 }
Neels Hofmeyr00727552018-02-21 14:33:15 +01001416 printf("\nPlease specify test case number 0..%d\n", last_test_i);
Neels Hofmeyr909e9722017-12-07 03:54:01 +01001417 return EXIT_FAILURE;
1418 }
1419
Neels Hofmeyre3416182018-03-05 05:31:14 +01001420 osmo_init_logging2(ctx, &log_info);
Neels Hofmeyr909e9722017-12-07 03:54:01 +01001421
1422 log_set_print_category(osmo_stderr_target, 1);
1423 log_set_print_category_hex(osmo_stderr_target, 0);
1424 log_set_print_filename2(osmo_stderr_target, LOG_FILENAME_BASENAME);
Neels Hofmeyr31f525e2018-05-14 18:14:15 +02001425 osmo_fsm_log_addr(false);
Neels Hofmeyr909e9722017-12-07 03:54:01 +01001426
Neels Hofmeyr958f2592018-05-27 01:26:31 +02001427 bsc_network_alloc();
Neels Hofmeyr909e9722017-12-07 03:54:01 +01001428 if (!bsc_gsmnet)
1429 exit(1);
1430
Neels Hofmeyr31f525e2018-05-14 18:14:15 +02001431 ts_fsm_init();
1432 lchan_fsm_init();
1433 mgw_endpoint_fsm_init(bsc_gsmnet->T_defs);
1434 bsc_subscr_conn_fsm_init();
1435 handover_fsm_init();
1436
Neels Hofmeyr909e9722017-12-07 03:54:01 +01001437 ho_set_algorithm(bsc_gsmnet->ho, 2);
1438 ho_set_ho_active(bsc_gsmnet->ho, true);
1439 ho_set_hodec2_as_active(bsc_gsmnet->ho, true);
1440 ho_set_hodec2_min_rxlev(bsc_gsmnet->ho, -100);
1441 ho_set_hodec2_rxlev_avg_win(bsc_gsmnet->ho, 1);
1442 ho_set_hodec2_rxlev_neigh_avg_win(bsc_gsmnet->ho, 1);
1443 ho_set_hodec2_rxqual_avg_win(bsc_gsmnet->ho, 10);
1444 ho_set_hodec2_pwr_hysteresis(bsc_gsmnet->ho, 3);
1445 ho_set_hodec2_pwr_interval(bsc_gsmnet->ho, 1);
1446 ho_set_hodec2_afs_bias_rxlev(bsc_gsmnet->ho, 0);
1447 ho_set_hodec2_min_rxqual(bsc_gsmnet->ho, 5);
1448 ho_set_hodec2_afs_bias_rxqual(bsc_gsmnet->ho, 0);
1449 ho_set_hodec2_max_distance(bsc_gsmnet->ho, 9999);
1450 ho_set_hodec2_ho_max(bsc_gsmnet->ho, 9999);
1451 ho_set_hodec2_penalty_max_dist(bsc_gsmnet->ho, 300);
1452 ho_set_hodec2_penalty_failed_ho(bsc_gsmnet->ho, 60);
1453 ho_set_hodec2_penalty_failed_as(bsc_gsmnet->ho, 60);
1454
1455 bts_model_sysmobts_init();
1456
Neels Hofmeyr00727552018-02-21 14:33:15 +01001457 test_case = test_cases[test_case_i];
Neels Hofmeyr909e9722017-12-07 03:54:01 +01001458
1459 fprintf(stderr, "--------------------\n");
1460 fprintf(stderr, "Performing the following test %d (algorithm %s):\n%s",
Neels Hofmeyr00727552018-02-21 14:33:15 +01001461 test_case_i, test_case[0], test_case[1]);
Neels Hofmeyr909e9722017-12-07 03:54:01 +01001462 algorithm = atoi(test_case[0]);
1463 test_case += 2;
1464 fprintf(stderr, "--------------------\n");
1465
1466 /* Disable the congestion check timer, we will trigger manually. */
1467 bsc_gsmnet->hodec2.congestion_check_interval_s = 0;
1468
1469 handover_decision_1_init();
1470 hodec2_init(bsc_gsmnet);
1471
1472 while (*test_case) {
1473 if (!strcmp(*test_case, "create-bts")) {
1474 static int arfcn = 870;
1475 int n = atoi(test_case[1]);
1476 fprintf(stderr, "- Creating %d BTS (one TRX each, "
1477 "TS(1-4) are TCH/F, TS(5-6) are TCH/H)\n", n);
1478 for (i = 0; i < n; i++)
1479 bts[bts_num + i] = create_bts(arfcn++);
Neels Hofmeyr00727552018-02-21 14:33:15 +01001480 for (i = 0; i < n; i++) {
Neels Hofmeyr31f525e2018-05-14 18:14:15 +02001481 if (gsm_generate_si(bts[bts_num + i], SYSINFO_TYPE_2) <= 0)
Neels Hofmeyr00727552018-02-21 14:33:15 +01001482 fprintf(stderr, "Error generating SI2\n");
1483 }
Neels Hofmeyr909e9722017-12-07 03:54:01 +01001484 bts_num += n;
1485 test_case += 2;
1486 } else
1487 if (!strcmp(*test_case, "as-enable")) {
1488 fprintf(stderr, "- Set assignment enable state at "
1489 "BTS %s to %s\n", test_case[1], test_case[2]);
1490 ho_set_hodec2_as_active(bts[atoi(test_case[1])]->ho, atoi(test_case[2]));
1491 test_case += 3;
1492 } else
1493 if (!strcmp(*test_case, "ho-enable")) {
1494 fprintf(stderr, "- Set handover enable state at "
1495 "BTS %s to %s\n", test_case[1], test_case[2]);
1496 ho_set_ho_active(bts[atoi(test_case[1])]->ho, atoi(test_case[2]));
1497 test_case += 3;
1498 } else
1499 if (!strcmp(*test_case, "afs-rxlev-improve")) {
1500 fprintf(stderr, "- Set afs RX level improvement at "
1501 "BTS %s to %s\n", test_case[1], test_case[2]);
1502 ho_set_hodec2_afs_bias_rxlev(bts[atoi(test_case[1])]->ho, atoi(test_case[2]));
1503 test_case += 3;
1504 } else
1505 if (!strcmp(*test_case, "afs-rxqual-improve")) {
1506 fprintf(stderr, "- Set afs RX quality improvement at "
1507 "BTS %s to %s\n", test_case[1], test_case[2]);
1508 ho_set_hodec2_afs_bias_rxqual(bts[atoi(test_case[1])]->ho, atoi(test_case[2]));
1509 test_case += 3;
1510 } else
1511 if (!strcmp(*test_case, "set-min-free")) {
1512 fprintf(stderr, "- Setting minimum required free %s "
1513 "slots at BTS %s to %s\n", test_case[2],
1514 test_case[1], test_case[3]);
1515 if (!strcmp(test_case[2], "TCH/F"))
1516 ho_set_hodec2_tchf_min_slots(bts[atoi(test_case[1])]->ho, atoi(test_case[3]));
1517 else
1518 ho_set_hodec2_tchh_min_slots(bts[atoi(test_case[1])]->ho, atoi(test_case[3]));
1519 test_case += 4;
1520 } else
1521 if (!strcmp(*test_case, "set-max-ho")) {
1522 fprintf(stderr, "- Setting maximum parallel handovers "
1523 "at BTS %s to %s\n", test_case[1],
1524 test_case[2]);
1525 ho_set_hodec2_ho_max( bts[atoi(test_case[1])]->ho, atoi(test_case[2]));
1526 test_case += 3;
1527 } else
1528 if (!strcmp(*test_case, "set-max-ta")) {
1529 fprintf(stderr, "- Setting maximum timing advance "
1530 "at BTS %s to %s\n", test_case[1],
1531 test_case[2]);
1532 ho_set_hodec2_max_distance(bts[atoi(test_case[1])]->ho, atoi(test_case[2]));
1533 test_case += 3;
1534 } else
1535 if (!strcmp(*test_case, "create-ms")) {
1536 fprintf(stderr, "- Creating mobile #%d at BTS %s on "
1537 "%s with %s codec\n", lchan_num, test_case[1],
1538 test_case[2], test_case[3]);
1539 lchan[lchan_num] = create_lchan(bts[atoi(test_case[1])],
1540 !strcmp(test_case[2], "TCH/F"), test_case[3]);
1541 if (!lchan[lchan_num]) {
1542 printf("Failed to create lchan!\n");
1543 return EXIT_FAILURE;
1544 }
1545 fprintf(stderr, " * New MS is at BTS %d TS %d\n",
1546 lchan[lchan_num]->ts->trx->bts->nr,
1547 lchan[lchan_num]->ts->nr);
1548 lchan_num++;
1549 test_case += 4;
1550 } else
1551 if (!strcmp(*test_case, "set-ta")) {
1552 fprintf(stderr, "- Setting maximum timing advance "
1553 "at MS %s to %s\n", test_case[1],
1554 test_case[2]);
1555 meas_ta_ms = atoi(test_case[2]);
1556 test_case += 3;
1557 } else
1558 if (!strcmp(*test_case, "meas-rep")) {
1559 /* meas-rep <lchan-nr> <rxlev> <rxqual> <nr-of-neighbors> [<cell-idx> <rxlev> [...]] */
1560 int n = atoi(test_case[4]);
1561 struct gsm_lchan *lc = lchan[atoi(test_case[1])];
1562 fprintf(stderr, "- Sending measurement report from "
1563 "mobile #%s (rxlev=%s, rxqual=%s)\n",
1564 test_case[1], test_case[2], test_case[3]);
1565 meas_dl_rxlev = atoi(test_case[2]);
1566 meas_dl_rxqual = atoi(test_case[3]);
1567 meas_num_nc = n;
1568 test_case += 5;
1569 for (i = 0; i < n; i++) {
1570 int nr = atoi(test_case[0]);
1571 /* since our bts is not in the list of neighbor
1572 * cells, we need to shift */
1573 if (nr >= lc->ts->trx->bts->nr)
1574 nr++;
1575 fprintf(stderr, " * Neighbor cell #%s, actual "
1576 "BTS %d (rxlev=%s)\n", test_case[0], nr,
1577 test_case[1]);
1578 meas_bcch_f_nc[i] = atoi(test_case[0]);
1579 /* bts number, not counting our own */
1580 meas_rxlev_nc[i] = atoi(test_case[1]);
1581 meas_bsic_nc[i] = 0x3f;
1582 test_case += 2;
1583 }
1584 got_chan_req = 0;
1585 gen_meas_rep(lc);
1586 } else
1587 if (!strcmp(*test_case, "congestion-check")) {
1588 fprintf(stderr, "- Triggering congestion check\n");
1589 got_chan_req = 0;
1590 if (algorithm == 2)
1591 hodec2_congestion_check(bsc_gsmnet);
1592 test_case += 1;
1593 } else
1594 if (!strcmp(*test_case, "expect-chan")) {
1595 fprintf(stderr, "- Expecting channel request at BTS %s "
1596 "TS %s\n", test_case[1], test_case[2]);
1597 if (!got_chan_req) {
1598 printf("Test failed, because no channel was "
1599 "requested\n");
1600 return EXIT_FAILURE;
1601 }
1602 fprintf(stderr, " * Got channel request at BTS %d "
1603 "TS %d\n", chan_req_lchan->ts->trx->bts->nr,
1604 chan_req_lchan->ts->nr);
1605 if (chan_req_lchan->ts->trx->bts->nr
1606 != atoi(test_case[1])) {
1607 printf("Test failed, because channel was not "
1608 "requested on expected BTS\n");
1609 return EXIT_FAILURE;
1610 }
1611 if (chan_req_lchan->ts->nr != atoi(test_case[2])) {
1612 printf("Test failed, because channel was not "
1613 "requested on expected TS\n");
1614 return EXIT_FAILURE;
1615 }
1616 test_case += 3;
1617 } else
1618 if (!strcmp(*test_case, "expect-no-chan")) {
1619 fprintf(stderr, "- Expecting no channel request\n");
1620 if (got_chan_req) {
1621 fprintf(stderr, " * Got channel request at "
1622 "BTS %d TS %d\n",
1623 chan_req_lchan->ts->trx->bts->nr,
1624 chan_req_lchan->ts->nr);
1625 printf("Test failed, because channel was "
1626 "requested\n");
1627 return EXIT_FAILURE;
1628 }
1629 fprintf(stderr, " * Got no channel request\n");
1630 test_case += 1;
1631 } else
1632 if (!strcmp(*test_case, "expect-ho")) {
1633 fprintf(stderr, "- Expecting handover/assignment "
1634 "request at BTS %s TS %s\n", test_case[1],
1635 test_case[2]);
1636 if (!got_ho_req) {
1637 printf("Test failed, because no handover was "
1638 "requested\n");
1639 return EXIT_FAILURE;
1640 }
1641 fprintf(stderr, " * Got handover/assignment request at "
1642 "BTS %d TS %d\n",
1643 ho_req_lchan->ts->trx->bts->nr,
1644 ho_req_lchan->ts->nr);
1645 if (ho_req_lchan->ts->trx->bts->nr
1646 != atoi(test_case[1])) {
1647 printf("Test failed, because "
1648 "handover/assignment was not commanded "
1649 "at the expected BTS\n");
1650 return EXIT_FAILURE;
1651 }
1652 if (ho_req_lchan->ts->nr != atoi(test_case[2])) {
1653 printf("Test failed, because "
1654 "handover/assignment was not commanded "
1655 "at the expected TS\n");
1656 return EXIT_FAILURE;
1657 }
1658 test_case += 3;
1659 } else
1660 if (!strcmp(*test_case, "ack-chan")) {
1661 fprintf(stderr, "- Acknowledging channel request\n");
1662 if (!got_chan_req) {
1663 printf("Cannot ack channel, because no "
1664 "request\n");
1665 return EXIT_FAILURE;
1666 }
1667 test_case += 1;
1668 got_ho_req = 0;
1669 send_chan_act_ack(chan_req_lchan, 1);
1670 } else
1671 if (!strcmp(*test_case, "ho-complete")) {
1672 fprintf(stderr, "- Acknowledging handover/assignment "
1673 "request\n");
1674 if (!got_chan_req) {
1675 printf("Cannot ack handover/assignment, "
1676 "because no chan request\n");
1677 return EXIT_FAILURE;
1678 }
1679 if (!got_ho_req) {
1680 printf("Cannot ack handover/assignment, "
1681 "because no ho request\n");
1682 return EXIT_FAILURE;
1683 }
1684 test_case += 1;
1685 got_chan_req = 0;
1686 got_ho_req = 0;
1687 /* switch lchan */
1688 for (i = 0; i < lchan_num; i++) {
1689 if (lchan[i] == ho_req_lchan) {
1690 fprintf(stderr, " * MS %d changes from "
1691 "BTS=%d TS=%d to BTS=%d "
1692 "TS=%d\n", i,
1693 lchan[i]->ts->trx->bts->nr,
1694 lchan[i]->ts->nr,
1695 chan_req_lchan->ts->trx->bts->nr,
1696 chan_req_lchan->ts->nr);
1697 lchan[i] = chan_req_lchan;
1698 }
1699 }
1700 send_ho_complete(chan_req_lchan, true);
1701 } else
1702 if (!strcmp(*test_case, "ho-failed")) {
1703 fprintf(stderr, "- Making handover fail\n");
1704 if (!got_chan_req) {
1705 printf("Cannot fail handover, because no chan "
1706 "request\n");
1707 return EXIT_FAILURE;
1708 }
1709 test_case += 1;
1710 got_chan_req = 0;
1711 got_ho_req = 0;
1712 send_ho_complete(ho_req_lchan, false);
1713 } else
1714 if (!strcmp(*test_case, "print")) {
1715 fprintf(stderr, "\n%s\n\n", test_case[1]);
1716 test_case += 2;
1717 } else {
1718 printf("Unknown test command '%s', please fix!\n",
1719 *test_case);
1720 return EXIT_FAILURE;
1721 }
Neels Hofmeyr31f525e2018-05-14 18:14:15 +02001722
1723 {
1724 /* Help the lchan out of releasing states */
1725 struct gsm_bts *bts;
1726 llist_for_each_entry(bts, &bsc_gsmnet->bts_list, list) {
1727 struct gsm_bts_trx *trx;
1728 llist_for_each_entry(trx, &bts->trx_list, list) {
1729 int ts_nr;
1730 for (ts_nr = 0; ts_nr < TRX_NR_TS; ts_nr++) {
1731 struct gsm_lchan *lchan;
1732 ts_for_each_lchan(lchan, &trx->ts[ts_nr]) {
1733
1734 if (lchan->fi && lchan->fi->state == LCHAN_ST_WAIT_BEFORE_RF_RELEASE) {
1735 osmo_fsm_inst_state_chg(lchan->fi, LCHAN_ST_WAIT_RF_RELEASE_ACK, 0, 0);
1736 osmo_fsm_inst_dispatch(lchan->fi, LCHAN_EV_RSL_RF_CHAN_REL_ACK, 0);
1737 }
1738 }
1739 }
1740 }
1741 }
1742 }
Neels Hofmeyr909e9722017-12-07 03:54:01 +01001743 }
1744
1745 for (i = 0; i < lchan_num; i++) {
1746 struct gsm_subscriber_connection *conn = lchan[i]->conn;
1747 lchan[i]->conn = NULL;
1748 conn->lchan = NULL;
Harald Welte3561bd42018-01-28 03:04:16 +01001749 osmo_fsm_inst_term(conn->fi, OSMO_FSM_TERM_REGULAR, NULL);
Neels Hofmeyr909e9722017-12-07 03:54:01 +01001750 }
1751
1752 fprintf(stderr, "--------------------\n");
1753
1754 printf("Test OK\n");
1755
1756 fprintf(stderr, "--------------------\n");
1757
Neels Hofmeyre3416182018-03-05 05:31:14 +01001758 talloc_free(ctx);
Neels Hofmeyr909e9722017-12-07 03:54:01 +01001759 return EXIT_SUCCESS;
1760}
1761
1762void rtp_socket_free() {}
1763void rtp_send_frame() {}
1764void rtp_socket_upstream() {}
1765void rtp_socket_create() {}
1766void rtp_socket_connect() {}
1767void rtp_socket_proxy() {}
1768void trau_mux_unmap() {}
1769void trau_mux_map_lchan() {}
1770void trau_recv_lchan() {}
1771void trau_send_frame() {}
Harald Welte3561bd42018-01-28 03:04:16 +01001772int osmo_bsc_sigtran_send(struct gsm_subscriber_connection *conn, struct msgb *msg) { return 0; }
1773int osmo_bsc_sigtran_open_conn(struct gsm_subscriber_connection *conn, struct msgb *msg) { return 0; }
Neels Hofmeyrc19581f2018-05-27 03:05:18 +02001774void bsc_sapi_n_reject(struct gsm_subscriber_connection *conn, int dlci) {}
1775void bsc_cipher_mode_compl(struct gsm_subscriber_connection *conn, struct msgb *msg, uint8_t chosen_encr) {}
1776int bsc_compl_l3(struct gsm_subscriber_connection *conn, struct msgb *msg, uint16_t chosen_channel)
1777{ return 0; }
1778void bsc_dtap(struct gsm_subscriber_connection *conn, uint8_t link_id, struct msgb *msg) {}
1779void bsc_assign_compl(struct gsm_subscriber_connection *conn, uint8_t rr_cause) {}
Neels Hofmeyrc19581f2018-05-27 03:05:18 +02001780int bsc_clear_request(struct gsm_subscriber_connection *conn, uint32_t cause)
1781{ return 0; }
1782void bsc_cm_update(struct gsm_subscriber_connection *conn,
1783 const uint8_t *cm2, uint8_t cm2_len,
1784 const uint8_t *cm3, uint8_t cm3_len) {}
Neels Hofmeyr31f525e2018-05-14 18:14:15 +02001785struct gsm0808_handover_required;
1786int bsc_tx_bssmap_ho_required(struct gsm_lchan *lchan, const struct gsm0808_cell_id_list2 *target_cells)
1787{ return 0; }
1788int bsc_tx_bssmap_ho_request_ack(struct gsm_subscriber_connection *conn, struct msgb *rr_ho_command)
1789{ return 0; }
1790int bsc_tx_bssmap_ho_detect(struct gsm_subscriber_connection *conn) { return 0; }
1791enum handover_result bsc_tx_bssmap_ho_complete(struct gsm_subscriber_connection *conn,
1792 struct gsm_lchan *lchan) { return HO_RESULT_OK; }
1793void bsc_tx_bssmap_ho_failure(struct gsm_subscriber_connection *conn) {}