blob: 280861ca20cda73afc84e8d4d94ee1952ab57a64 [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>
35#include <osmocom/bsc/chan_alloc.h>
36#include <osmocom/bsc/handover_decision.h>
37#include <osmocom/bsc/system_information.h>
38#include <osmocom/bsc/handover_cfg.h>
39#include <osmocom/bsc/handover_decision_2.h>
40#include <osmocom/bsc/common_bsc.h>
41#include <osmocom/bsc/bss.h>
42#include <osmocom/bsc/bsc_api.h>
43#include <osmocom/bsc/osmo_bsc.h>
Harald Welte3561bd42018-01-28 03:04:16 +010044#include <osmocom/bsc/bsc_subscr_conn_fsm.h>
Neels Hofmeyr909e9722017-12-07 03:54:01 +010045
46struct gsm_network *bsc_gsmnet;
47
Harald Welte3561bd42018-01-28 03:04:16 +010048/* override, requires '-Wl,--wrap=mgcp_conn_modify'.
49 * Catch modification of an MGCP connection. */
50int __real_mgcp_conn_modify(struct osmo_fsm_inst *fi, uint32_t parent_evt, struct mgcp_conn_peer *conn_peer);
51int __wrap_mgcp_conn_modify(struct osmo_fsm_inst *fi, uint32_t parent_evt, struct mgcp_conn_peer *conn_peer)
52{
53 /* CAUTION HACK:
54 *
55 * The pointer fi is misused to pass a reference to GSCON FSM !
56 *
57 * This function is called from gscon_fsm_wait_ho_compl() from
58 * bsc_subscr_conn_fsm.c when GSCON_EV_HO_COMPL is dispatched to the
59 * GSCON FSM. By then, the GSCON FSM has already changed to the state
60 * ST_WAIT_MDCX_BTS_HO (see gscon_fsm_wait_mdcx_bts_ho()) and waits for
61 * GSCON_EV_MGW_MDCX_RESP_BTS. The signal GSCON_EV_MGW_MDCX_RESP_BTS
62 * is sent to this function using the parameter parent_evt. So we
63 * implicitly know the event that is needed to simulate a successful
64 * MGW negotiation to the GSCON FSM. All we need to do is to dispatch
65 * parent_evt back to the GSCON FSM in order to make it think that the
66 * MGW negotiation is done.
67 *
68 * Unfortunately, there is a problem with this test implementation.
69 * in order to simplfy the test we do not allocate any MGCP Client
70 * FSM but the GSCON FSM will call this function with the fi pointer
71 * pointing to the MGCP Client FSM. This means we get a nullpointer
72 * here and there is no way to distinguish which GSCON FSM called
73 * the function at all (normally we would know through the parent
74 * pointer).
75 *
76 * To get around this problem we populate the fi pointer with the
77 * reference to the GSCON FSM itsself, so we can know who called the
78 * function. This is a misuse of the pointer since it normally would
79 * hold an MGCP Client FSM instead of a GSCON FSM.
80 *
81 * See also note in function create_conn() */
82
83 osmo_fsm_inst_dispatch(fi, parent_evt, NULL);
84 return 0;
85}
86
87/* override, requires '-Wl,--wrap=mgcp_conn_delete'.
88 * Catch deletion of an MGCP connection. */
89int __real_mgcp_conn_delete(struct osmo_fsm_inst *fi);
90int __wrap_mgcp_conn_delete(struct osmo_fsm_inst *fi)
91{
92 /* Just do nothing and pretend that everything went well.
93 * We never have allocatec any MGCP connections. */
94 return 0;
95}
96
Neels Hofmeyr909e9722017-12-07 03:54:01 +010097/* measurement report */
98
99uint8_t meas_rep_ba = 0, meas_rep_valid = 1, meas_valid = 1, meas_multi_rep = 0;
100uint8_t meas_dl_rxlev = 0, meas_dl_rxqual = 0;
101uint8_t meas_ul_rxlev = 0, meas_ul_rxqual = 0;
102uint8_t meas_tx_power_ms = 0, meas_tx_power_bs = 0, meas_ta_ms = 0;
103uint8_t meas_dtx_ms = 0, meas_dtx_bs = 0, meas_nr = 0;
104uint8_t meas_num_nc = 0, meas_rxlev_nc[6], meas_bsic_nc[6], meas_bcch_f_nc[6];
105
106static void gen_meas_rep(struct gsm_lchan *lchan)
107{
108 struct msgb *msg = msgb_alloc_headroom(256, 64, "RSL");
109 struct abis_rsl_dchan_hdr *dh;
110 uint8_t chan_nr = gsm_lchan2chan_nr(lchan);
111 uint8_t ulm[3], l1i[2], *buf;
112 struct gsm48_hdr *gh;
113 struct gsm48_meas_res *mr;
114
115 dh = (struct abis_rsl_dchan_hdr *) msgb_put(msg, sizeof(*dh));
116 dh->c.msg_discr = ABIS_RSL_MDISC_DED_CHAN;
117 dh->c.msg_type = RSL_MT_MEAS_RES;
118 dh->ie_chan = RSL_IE_CHAN_NR;
119 dh->chan_nr = chan_nr;
120
121 msgb_tv_put(msg, RSL_IE_MEAS_RES_NR, meas_nr++);
122
123 ulm[0] = meas_ul_rxlev | (meas_dtx_bs << 7);
124 ulm[1] = meas_ul_rxlev;
125 ulm[2] = (meas_ul_rxqual << 3) | meas_ul_rxqual;
126 msgb_tlv_put(msg, RSL_IE_UPLINK_MEAS, sizeof(ulm), ulm);
127
128 msgb_tv_put(msg, RSL_IE_BS_POWER, meas_tx_power_bs);
129
130 l1i[0] = 0;
131 l1i[1] = meas_ta_ms;
132 msgb_tv_fixed_put(msg, RSL_IE_L1_INFO, sizeof(l1i), l1i);
133
134 buf = msgb_put(msg, 3);
135 buf[0] = RSL_IE_L3_INFO;
136 buf[1] = (sizeof(*gh) + sizeof(*mr)) >> 8;
137 buf[2] = (sizeof(*gh) + sizeof(*mr)) & 0xff;
138
139 gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
140 mr = (struct gsm48_meas_res *) msgb_put(msg, sizeof(*mr));
141
142 gh->proto_discr = GSM48_PDISC_RR;
143 gh->msg_type = GSM48_MT_RR_MEAS_REP;
144
145 /* measurement results */
146 mr->rxlev_full = meas_dl_rxlev;
147 mr->rxlev_sub = meas_dl_rxlev;
148 mr->rxqual_full = meas_dl_rxqual;
149 mr->rxqual_sub = meas_dl_rxqual;
150 mr->dtx_used = meas_dtx_ms;
151 mr->ba_used = meas_rep_ba;
152 mr->meas_valid = !meas_valid; /* 0 = valid */
153 if (meas_rep_valid) {
154 mr->no_nc_n_hi = meas_num_nc >> 2;
155 mr->no_nc_n_lo = meas_num_nc & 3;
156 } else {
157 /* no results for serving cells */
158 mr->no_nc_n_hi = 1;
159 mr->no_nc_n_lo = 3;
160 }
161 mr->rxlev_nc1 = meas_rxlev_nc[0];
162 mr->rxlev_nc2_hi = meas_rxlev_nc[1] >> 1;
163 mr->rxlev_nc2_lo = meas_rxlev_nc[1] & 1;
164 mr->rxlev_nc3_hi = meas_rxlev_nc[2] >> 2;
165 mr->rxlev_nc3_lo = meas_rxlev_nc[2] & 3;
166 mr->rxlev_nc4_hi = meas_rxlev_nc[3] >> 3;
167 mr->rxlev_nc4_lo = meas_rxlev_nc[3] & 7;
168 mr->rxlev_nc5_hi = meas_rxlev_nc[4] >> 4;
169 mr->rxlev_nc5_lo = meas_rxlev_nc[4] & 15;
170 mr->rxlev_nc6_hi = meas_rxlev_nc[5] >> 5;
171 mr->rxlev_nc6_lo = meas_rxlev_nc[5] & 31;
172 mr->bsic_nc1_hi = meas_bsic_nc[0] >> 3;
173 mr->bsic_nc1_lo = meas_bsic_nc[0] & 7;
174 mr->bsic_nc2_hi = meas_bsic_nc[1] >> 4;
175 mr->bsic_nc2_lo = meas_bsic_nc[1] & 15;
176 mr->bsic_nc3_hi = meas_bsic_nc[2] >> 5;
177 mr->bsic_nc3_lo = meas_bsic_nc[2] & 31;
178 mr->bsic_nc4 = meas_bsic_nc[3];
179 mr->bsic_nc5 = meas_bsic_nc[4];
180 mr->bsic_nc6 = meas_bsic_nc[5];
181 mr->bcch_f_nc1 = meas_bcch_f_nc[0];
182 mr->bcch_f_nc2 = meas_bcch_f_nc[1];
183 mr->bcch_f_nc3 = meas_bcch_f_nc[2];
184 mr->bcch_f_nc4 = meas_bcch_f_nc[3];
185 mr->bcch_f_nc5_hi = meas_bcch_f_nc[4] >> 1;
186 mr->bcch_f_nc5_lo = meas_bcch_f_nc[4] & 1;
187 mr->bcch_f_nc6_hi = meas_bcch_f_nc[5] >> 2;
188 mr->bcch_f_nc6_lo = meas_bcch_f_nc[5] & 3;
189
190 msg->dst = lchan->ts->trx->bts->c0->rsl_link;
191 msg->l2h = (unsigned char *)dh;
192 msg->l3h = (unsigned char *)gh;
193
194 abis_rsl_rcvmsg(msg);
195}
196
197static struct gsm_bts *create_bts(int arfcn)
198{
199 struct gsm_bts *bts;
200 struct e1inp_sign_link *rsl_link;
201 int i;
202
203 bts = gsm_bts_alloc_register(bsc_gsmnet, GSM_BTS_TYPE_OSMOBTS, 0x3f);
204 if (!bts) {
205 printf("No resource for bts1\n");
206 return NULL;
207 }
208
209 bts->location_area_code = 23;
210 bts->c0->arfcn = arfcn;
211
212 bts->codec.efr = 1;
213 bts->codec.hr = 1;
214 bts->codec.amr = 1;
215
216 rsl_link = talloc_zero(0, struct e1inp_sign_link);
217 rsl_link->trx = bts->c0;
218 bts->c0->rsl_link = rsl_link;
219
220 bts->c0->mo.nm_state.operational = NM_OPSTATE_ENABLED;
221 bts->c0->mo.nm_state.availability = NM_AVSTATE_OK;
222 bts->c0->bb_transc.mo.nm_state.operational = NM_OPSTATE_ENABLED;
223 bts->c0->bb_transc.mo.nm_state.availability = NM_AVSTATE_OK;
224
225 /* 4 full rate and 4 half rate channels */
226 for (i = 1; i <= 6; i++) {
227 bts->c0->ts[i].pchan =
228 (i < 5) ? GSM_PCHAN_TCH_F : GSM_PCHAN_TCH_H;
229 bts->c0->ts[i].mo.nm_state.operational = NM_OPSTATE_ENABLED;
230 bts->c0->ts[i].mo.nm_state.availability = NM_AVSTATE_OK;
231 bts->c0->ts[i].lchan[0].type = GSM_LCHAN_NONE;
232 bts->c0->ts[i].lchan[0].state = LCHAN_S_NONE;
233 bts->c0->ts[i].lchan[1].type = GSM_LCHAN_NONE;
234 bts->c0->ts[i].lchan[1].state = LCHAN_S_NONE;
235 }
236 return bts;
237}
238
239void create_conn(struct gsm_lchan *lchan)
240{
Harald Welte3561bd42018-01-28 03:04:16 +0100241 struct gsm_subscriber_connection *conn;
242 conn = bsc_subscr_con_allocate(lchan->ts->trx->bts->network);
243
244 /* CAUTION HACK: When __real_mgcp_conn_modify() is called by the GSCON
245 * FSM, then we need to know the reference to caller FSM (GSCON FSM).
246 * Unfortunately the function __real_mgcp_conn_modify() is called with
247 * fi_bts, which is unpopulated in this setup. The real function would
248 * perform the communication with the MGW and then dispatch a signal
249 * back to the parent FSM. Since we do not have all that in this setup
250 * we populate the fi_bts pointer with a reference to the GSCON FSM in
251 * order to have it available later in __real_mgcp_conn_modify(). */
252 conn->user_plane.fi_bts = conn->fi;
253
254 lchan->conn = conn;
255 conn->lchan = lchan;
256 /* kick the FSM from INIT through to the ACTIVE state */
257 osmo_fsm_inst_dispatch(conn->fi, GSCON_EV_A_CONN_REQ, NULL);
258 osmo_fsm_inst_dispatch(conn->fi, GSCON_EV_A_CONN_CFM, NULL);
Neels Hofmeyr909e9722017-12-07 03:54:01 +0100259}
260
261/* create lchan */
262struct gsm_lchan *create_lchan(struct gsm_bts *bts, int full_rate, char *codec)
263{
264 struct gsm_lchan *lchan;
265
266 lchan = lchan_alloc(bts,
267 (full_rate) ? GSM_LCHAN_TCH_F : GSM_LCHAN_TCH_H, 0);
268 if (!lchan) {
269 printf("No resource for lchan\n");
270 exit(EXIT_FAILURE);
271 }
272 lchan->state = LCHAN_S_ACTIVE;
273 create_conn(lchan);
274 if (!strcasecmp(codec, "FR") && full_rate)
275 lchan->tch_mode = GSM48_CMODE_SPEECH_V1;
276 else if (!strcasecmp(codec, "HR") && !full_rate)
277 lchan->tch_mode = GSM48_CMODE_SPEECH_V1;
278 else if (!strcasecmp(codec, "EFR") && full_rate)
279 lchan->tch_mode = GSM48_CMODE_SPEECH_EFR;
280 else if (!strcasecmp(codec, "AMR"))
281 lchan->tch_mode = GSM48_CMODE_SPEECH_AMR;
282 else {
283 printf("Given codec unknown\n");
284 exit(EXIT_FAILURE);
285 }
286
287 lchan->conn->codec_list = (struct gsm0808_speech_codec_list){
288 .codec = {
289 { .fi=true, .type=GSM0808_SCT_FR1, },
290 { .fi=true, .type=GSM0808_SCT_FR2, },
291 { .fi=true, .type=GSM0808_SCT_FR3, },
292 { .fi=true, .type=GSM0808_SCT_HR1, },
293 { .fi=true, .type=GSM0808_SCT_HR3, },
294 },
295 .len = 5,
296 };
297 lchan->conn->codec_list_present = true;
298
299 return lchan;
300}
301
302/* parse channel request */
303
304static int got_chan_req = 0;
305static struct gsm_lchan *chan_req_lchan = NULL;
306
307static int parse_chan_act(struct gsm_lchan *lchan, uint8_t *data)
308{
309 chan_req_lchan = lchan;
310 return 0;
311}
312
313static int parse_chan_rel(struct gsm_lchan *lchan, uint8_t *data)
314{
315 chan_req_lchan = lchan;
316 return 0;
317}
318
319/* parse handover request */
320
321static int got_ho_req = 0;
322static struct gsm_lchan *ho_req_lchan = NULL;
323
324static int parse_ho_command(struct gsm_lchan *lchan, uint8_t *data, int len)
325{
326 struct gsm48_hdr *gh = (struct gsm48_hdr *) data;
327 struct gsm48_ho_cmd *ho = (struct gsm48_ho_cmd *) gh->data;
328 int arfcn;
329 struct gsm_bts *neigh;
330
331 switch (gh->msg_type) {
332 case GSM48_MT_RR_HANDO_CMD:
333 arfcn = (ho->cell_desc.arfcn_hi << 8) | ho->cell_desc.arfcn_lo;
334
335 /* look up trx. since every dummy bts uses different arfcn and
336 * only one trx, it is simple */
337 llist_for_each_entry(neigh, &bsc_gsmnet->bts_list, list) {
338 if (neigh->c0->arfcn != arfcn)
339 continue;
340 ho_req_lchan = lchan;
341 return 0;
342 }
343 break;
344 case GSM48_MT_RR_ASS_CMD:
345 ho_req_lchan = lchan;
346 return 0;
347 break;
348 default:
349 fprintf(stderr, "Error, expecting HO or AS command\n");
350 return -EINVAL;
351 }
352
353 return -1;
354}
355
356/* send channel activation ack */
357static void send_chan_act_ack(struct gsm_lchan *lchan, int act)
358{
359 struct msgb *msg = msgb_alloc_headroom(256, 64, "RSL");
360 struct abis_rsl_dchan_hdr *dh;
361
362 dh = (struct abis_rsl_dchan_hdr *) msgb_put(msg, sizeof(*dh));
363 dh->c.msg_discr = ABIS_RSL_MDISC_DED_CHAN;
364 dh->c.msg_type = (act) ? RSL_MT_CHAN_ACTIV_ACK : RSL_MT_RF_CHAN_REL_ACK;
365 dh->ie_chan = RSL_IE_CHAN_NR;
366 dh->chan_nr = gsm_lchan2chan_nr(lchan);
367
368 msg->dst = lchan->ts->trx->bts->c0->rsl_link;
369 msg->l2h = (unsigned char *)dh;
370
371 abis_rsl_rcvmsg(msg);
372}
373
374/* send handover complete */
375static void send_ho_complete(struct gsm_lchan *lchan, bool success)
376{
377 struct msgb *msg = msgb_alloc_headroom(256, 64, "RSL");
378 struct abis_rsl_rll_hdr *rh;
379 uint8_t chan_nr = gsm_lchan2chan_nr(lchan);
380 uint8_t *buf;
381 struct gsm48_hdr *gh;
382 struct gsm48_ho_cpl *hc;
383
384 rh = (struct abis_rsl_rll_hdr *) msgb_put(msg, sizeof(*rh));
385 rh->c.msg_discr = ABIS_RSL_MDISC_RLL;
386 rh->c.msg_type = RSL_MT_DATA_IND;
387 rh->ie_chan = RSL_IE_CHAN_NR;
388 rh->chan_nr = chan_nr;
389 rh->ie_link_id = RSL_IE_LINK_IDENT;
390 rh->link_id = 0x00;
391
392 buf = msgb_put(msg, 3);
393 buf[0] = RSL_IE_L3_INFO;
394 buf[1] = (sizeof(*gh) + sizeof(*hc)) >> 8;
395 buf[2] = (sizeof(*gh) + sizeof(*hc)) & 0xff;
396
397 gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh));
398 hc = (struct gsm48_ho_cpl *) msgb_put(msg, sizeof(*hc));
399
400 gh->proto_discr = GSM48_PDISC_RR;
401 gh->msg_type =
402 success ? GSM48_MT_RR_HANDO_COMPL : GSM48_MT_RR_HANDO_FAIL;
403
404 msg->dst = lchan->ts->trx->bts->c0->rsl_link;
405 msg->l2h = (unsigned char *)rh;
406 msg->l3h = (unsigned char *)gh;
407
408 abis_rsl_rcvmsg(msg);
409}
410
Neels Hofmeyr1d7473c2018-03-05 21:53:18 +0100411/* override, requires '-Wl,--wrap=abis_rsl_sendmsg'.
412 * Catch RSL messages sent towards the BTS. */
413int __real_abis_rsl_sendmsg(struct msgb *msg);
414int __wrap_abis_rsl_sendmsg(struct msgb *msg)
Neels Hofmeyr909e9722017-12-07 03:54:01 +0100415{
416 struct abis_rsl_dchan_hdr *dh = (struct abis_rsl_dchan_hdr *) msg->data;
417 struct e1inp_sign_link *sign_link = msg->dst;
418 int rc;
419 struct gsm_lchan *lchan = rsl_lchan_lookup(sign_link->trx, dh->chan_nr, &rc);
420
421 if (rc) {
422 printf("rsl_lchan_lookup() failed\n");
423 exit(1);
424 }
425
426 switch (dh->c.msg_type) {
427 case RSL_MT_CHAN_ACTIV:
428 rc = parse_chan_act(lchan, dh->data);
429 if (rc == 0)
430 got_chan_req = 1;
431 break;
432 case RSL_MT_RF_CHAN_REL:
433 rc = parse_chan_rel(lchan, dh->data);
434 if (rc == 0)
435 send_chan_act_ack(chan_req_lchan, 0);
436 break;
437 case RSL_MT_DATA_REQ:
438 rc = parse_ho_command(lchan, msg->l3h, msgb_l3len(msg));
439 if (rc == 0)
440 got_ho_req = 1;
441 break;
442 case RSL_MT_IPAC_CRCX:
443 break;
444 default:
445 printf("unknown rsl message=0x%x\n", dh->c.msg_type);
446 }
447 return 0;
448}
449
450/* test cases */
451
452static char *test_case_0[] = {
453 "2",
454
455 "Stay in better cell\n\n"
456 "There are many neighbor cells, but only the current cell is the best\n"
457 "cell, so no handover is performed\n",
458
459 "create-bts", "7",
460 "create-ms", "0", "TCH/F", "AMR",
461 "meas-rep", "0", "30","0",
462 "6","0","20","1","21","2","18","3","20","4","23","5","19",
463 "expect-no-chan",
464 NULL
465};
466
467static char *test_case_1[] = {
468 "2",
469
470 "Handover to best better cell\n\n"
471 "The best neighbor cell is selected\n",
472
473 "create-bts", "7",
474 "create-ms", "0", "TCH/F", "AMR",
475 "meas-rep", "0", "10","0",
476 "6","0","20","1","21","2","18","3","20","4","23","5","19",
477 "expect-chan", "5", "1",
478 "ack-chan",
479 "expect-ho", "0", "1",
480 "ho-complete",
481 NULL
482};
483
484static char *test_case_2[] = {
485 "2",
486
487 "Handover and Assignment must be enabled\n\n"
488 "This test will start with disabled assignment and handover. A\n"
489 "better neighbor cell (assignment enabled) will not be selected and \n"
490 "also no assignment from TCH/H to TCH/F to improve quality. There\n"
491 "will be no handover nor assignment. After enabling assignment on the\n"
492 "current cell, the MS will assign to TCH/F. After enabling handover\n"
493 "in the current cell, but disabling in the neighbor cell, handover\n"
494 "will not be performed, until it is enabled in the neighbor cell too.\n",
495
496 "create-bts", "2",
497 "afs-rxlev-improve", "0", "5",
498 "create-ms", "0", "TCH/H", "AMR",
499 "as-enable", "0", "0",
500 "ho-enable", "0", "0",
501 "meas-rep", "0", "0","0", "1","0","30",
502 "expect-no-chan",
503 "as-enable", "0", "1",
504 "meas-rep", "0", "0","0", "1","0","30",
505 "expect-chan", "0", "1",
506 "ack-chan",
507 "expect-ho", "0", "5",
508 "ho-complete",
509 "ho-enable", "0", "1",
510 "ho-enable", "1", "0",
511 "meas-rep", "0", "0","0", "1","0","30",
512 "expect-no-chan",
513 "ho-enable", "1", "1",
514 "meas-rep", "0", "0","0", "1","0","30",
515 "expect-chan", "1", "1",
516 "ack-chan",
517 "expect-ho", "0", "1",
518 "ho-complete",
519 NULL
520};
521
522static char *test_case_3[] = {
523 "2",
524
525 "Penalty timer must not run\n\n"
526 "The MS will try to handover to a better cell, but this will fail.\n"
527 "Even though the cell is still better, handover will not be performed\n"
528 "due to penalty timer after handover failure\n",
529
530 "create-bts", "2",
531 "create-ms", "0", "TCH/F", "AMR",
532 "meas-rep", "0", "20","0", "1","0","30",
533 "expect-chan", "1", "1",
534 "ack-chan",
535 "expect-ho", "0", "1",
536 "ho-failed",
537 "meas-rep", "0", "20","0", "1","0","30",
538 "expect-no-chan",
539 NULL
540};
541
542static char *test_case_4[] = {
543 "2",
544
545 "TCH/H keeping with HR codec\n\n"
546 "The MS is using half rate V1 codec, but the better cell is congested\n"
547 "at TCH/H slots. As the congestion is removed, the handover takes\n"
548 "place.\n",
549
550 "create-bts", "2",
551 "set-min-free", "1", "TCH/H", "4",
552 "create-ms", "0", "TCH/H", "HR",
553 "meas-rep", "0", "20","0", "1","0","30",
554 "expect-no-chan",
555 "set-min-free", "1", "TCH/H", "3",
556 "meas-rep", "0", "20","0", "1","0","30",
557 "expect-chan", "1", "5",
558 "ack-chan",
559 "expect-ho", "0", "5",
560 "ho-complete",
561 NULL
562};
563
564static char *test_case_5[] = {
565 "2",
566
567 "TCH/F keeping with FR codec\n\n"
568 "The MS is using full rate V1 codec, but the better cell is congested\n"
569 "at TCH/F slots. As the congestion is removed, the handover takes\n"
570 "place.\n",
571
572 "create-bts", "2",
573 "set-min-free", "1", "TCH/F", "4",
574 "create-ms", "0", "TCH/F", "FR",
575 "meas-rep", "0", "20","0", "1","0","30",
576 "expect-no-chan",
577 "set-min-free", "1", "TCH/F", "3",
578 "meas-rep", "0", "20","0", "1","0","30",
579 "expect-chan", "1", "1",
580 "ack-chan",
581 "expect-ho", "0", "1",
582 "ho-complete",
583 NULL
584};
585
586static char *test_case_6[] = {
587 "2",
588
589 "TCH/F keeping with EFR codec\n\n"
590 "The MS is using full rate V2 codec, but the better cell is congested\n"
591 "at TCH/F slots. As the congestion is removed, the handover takes\n"
592 "place.\n",
593
594 "create-bts", "2",
595 "set-min-free", "1", "TCH/F", "4",
596 "create-ms", "0", "TCH/F", "EFR",
597 "meas-rep", "0", "20","0", "1","0","30",
598 "expect-no-chan",
599 "set-min-free", "1", "TCH/F", "3",
600 "meas-rep", "0", "20","0", "1","0","30",
601 "expect-chan", "1", "1",
602 "ack-chan",
603 "expect-ho", "0", "1",
604 "ho-complete",
605 NULL
606};
607
608static char *test_case_7[] = {
609 "2",
610
611 "TCH/F to TCH/H changing with AMR codec\n\n"
612 "The MS is using AMR V3 codec, the better cell is congested at TCH/F\n"
613 "slots. The handover is performed to non-congested TCH/H slots.\n",
614
615 "create-bts", "2",
616 "set-min-free", "1", "TCH/F", "4",
617 "create-ms", "0", "TCH/F", "AMR",
618 "meas-rep", "0", "20","0", "1","0","30",
619 "expect-chan", "1", "5",
620 "ack-chan",
621 "expect-ho", "0", "1",
622 "ho-complete",
623 NULL
624};
625
626static char *test_case_8[] = {
627 "2",
628
629 "No handover to a cell with no slots available\n\n"
630 "If no slot is available, no handover is performed\n",
631
632 "create-bts", "2",
633 "create-ms", "0", "TCH/F", "AMR",
634 "create-ms", "1", "TCH/F", "AMR",
635 "create-ms", "1", "TCH/F", "AMR",
636 "create-ms", "1", "TCH/F", "AMR",
637 "create-ms", "1", "TCH/F", "AMR",
638 "create-ms", "1", "TCH/H", "AMR",
639 "create-ms", "1", "TCH/H", "AMR",
640 "create-ms", "1", "TCH/H", "AMR",
641 "create-ms", "1", "TCH/H", "AMR",
642 "meas-rep", "0", "0","0", "1","0","30",
643 "expect-no-chan",
644 NULL
645};
646
647static char *test_case_9[] = {
648 "2",
649
650 "No more parallel handovers, if max_unsync_ho is defined\n\n"
651 "There are tree mobiles that want to handover, but only two can do\n"
652 "it at a time, because the maximum number is limited to two.\n",
653
654 "create-bts", "2",
655 "set-max-ho", "1", "2",
656 "create-ms", "0", "TCH/F", "AMR",
657 "create-ms", "0", "TCH/F", "AMR",
658 "create-ms", "0", "TCH/F", "AMR",
659 "meas-rep", "0", "0","0", "1","0","30",
660 "expect-chan", "1", "1",
661 "meas-rep", "1", "0","0", "1","0","30",
662 "expect-chan", "1", "2",
663 "meas-rep", "2", "0","0", "1","0","30",
664 "expect-no-chan",
665 NULL
666};
667
668static char *test_case_10[] = {
669 "2",
670
671 "Hysteresis\n\n"
672 "If neighbor cell is better, handover is only performed if the\n"
673 "ammount of improvement is greater or equal hyteresis\n",
674
675 "create-bts", "2",
676 "create-ms", "0", "TCH/F", "AMR",
677 "meas-rep", "0", "27","0", "1","0","30",
678 "expect-no-chan",
679 "meas-rep", "0", "26","0", "1","0","30",
680 "expect-chan", "1", "1",
681 "ack-chan",
682 "expect-ho", "0", "1",
683 "ho-complete",
684 NULL
685};
686
687static char *test_case_11[] = {
688 "2",
689
690 "No Hysteresis and minimum RX level\n\n"
691 "If current cell's RX level is below mimium level, handover must be\n"
692 "performed, no matter of the hysteresis. First do not perform\n"
693 "handover to better neighbor cell, because the hysteresis is not\n"
694 "met. Second do not perform handover because better neighbor cell is\n"
695 "below minimum RX level. Third perform handover because current cell\n"
696 "is below minimum RX level, even if the better neighbor cell (minimum\n"
697 "RX level reached) does not meet the hysteresis.\n",
698
699 "create-bts", "2",
700 "create-ms", "0", "TCH/F", "AMR",
701 "meas-rep", "0", "10","0", "1","0","11",
702 "expect-no-chan",
703 "meas-rep", "0", "8","0", "1","0","9",
704 "expect-no-chan",
705 "meas-rep", "0", "9","0", "1","0","10",
706 "expect-chan", "1", "1",
707 "ack-chan",
708 "expect-ho", "0", "1",
709 "ho-complete",
710 NULL
711};
712
713static char *test_case_12[] = {
714 "2",
715
716 "No handover to congested cell\n\n"
717 "The better neighbor cell is congested, so no handover is performed.\n"
718 "After the congestion is over, handover will be performed.\n",
719
720 "create-bts", "2",
721 "create-ms", "0", "TCH/F", "AMR",
722 "set-min-free", "1", "TCH/F", "4",
723 "set-min-free", "1", "TCH/H", "4",
724 "meas-rep", "0", "20","0", "1","0","30",
725 "expect-no-chan",
726 "set-min-free", "1", "TCH/F", "3",
727 "set-min-free", "1", "TCH/H", "3",
728 "meas-rep", "0", "20","0", "1","0","30",
729 "expect-chan", "1", "1",
730 "ack-chan",
731 "expect-ho", "0", "1",
732 "ho-complete",
733 NULL
734};
735
736static char *test_case_13[] = {
737 "2",
738
739 "Handover to balance congestion\n\n"
740 "The current and the better cell are congested, so no handover is\n"
741 "performed. This is because handover would congest the neighbor cell\n"
742 "more. After congestion raises in the current cell, the handover is\n"
743 "performed to balance congestion\n",
744
745 "create-bts", "2",
746 "create-ms", "0", "TCH/F", "AMR",
747 "set-min-free", "0", "TCH/F", "4",
748 "set-min-free", "0", "TCH/H", "4",
749 "set-min-free", "1", "TCH/F", "4",
750 "set-min-free", "1", "TCH/H", "4",
751 "meas-rep", "0", "20","0", "1","0","30",
752 "expect-no-chan",
753 "create-ms", "0", "TCH/F", "AMR",
754 "meas-rep", "0", "20","0", "1","0","30",
755 "expect-chan", "1", "1",
756 "ack-chan",
757 "expect-ho", "0", "1",
758 "ho-complete",
759 NULL
760};
761
762static char *test_case_14[] = {
763 "2",
764
765 "Handover to congested cell, if RX level is below minimum\n\n"
766 "The better neighbor cell is congested, so no handover is performed.\n"
767 "If the RX level of the current cell drops below minimum acceptable\n"
768 "level, the handover is performed.\n",
769
770 "create-bts", "2",
771 "create-ms", "0", "TCH/F", "AMR",
772 "set-min-free", "1", "TCH/F", "4",
773 "set-min-free", "1", "TCH/H", "4",
774 "meas-rep", "0", "10","0", "1","0","30",
775 "expect-no-chan",
776 "meas-rep", "0", "9","0", "1","0","30",
777 "expect-chan", "1", "1",
778 "ack-chan",
779 "expect-ho", "0", "1",
780 "ho-complete",
781 NULL
782};
783
784static char *test_case_15[] = {
785 "2",
786
787 "Handover to cell with worse RXLEV, if RXQUAL is below minimum\n\n"
788 "The neighbor cell has worse RXLEV, so no handover is performed.\n"
789 "If the RXQUAL of the current cell drops below minimum acceptable\n"
790 "level, the handover is performed. It is also required that 10\n"
791 "reports are received, before RXQUAL is checked.\n",
792 /* (See also test 28, which tests for RXQUAL triggering HO to congested cell.) */
793 /* TODO: bad RXQUAL may want to prefer assignment within the same cell to avoid interference.
794 * See Performence Enhancements in a Frequency Hopping GSM Network (Nielsen Wigard 2002), Chapter
795 * 2.1.1, "Interference" in the list of triggers on p.157. */
796
797 "create-bts", "2",
798 "create-ms", "0", "TCH/F", "AMR",
799 "meas-rep", "0", "40","6", "1","0","30",
800 "expect-no-chan",
801 "meas-rep", "0", "40","6", "1","0","30",
802 "expect-no-chan",
803 "meas-rep", "0", "40","6", "1","0","30",
804 "expect-no-chan",
805 "meas-rep", "0", "40","6", "1","0","30",
806 "expect-no-chan",
807 "meas-rep", "0", "40","6", "1","0","30",
808 "expect-no-chan",
809 "meas-rep", "0", "40","6", "1","0","30",
810 "expect-no-chan",
811 "meas-rep", "0", "40","6", "1","0","30",
812 "expect-no-chan",
813 "meas-rep", "0", "40","6", "1","0","30",
814 "expect-no-chan",
815 "meas-rep", "0", "40","6", "1","0","30",
816 "expect-no-chan",
817 "meas-rep", "0", "40","6", "1","0","30",
818 "expect-chan", "1", "1",
819 "ack-chan",
820 "expect-ho", "0", "1",
821 "ho-complete",
822 NULL
823};
824
825static char *test_case_16[] = {
826 "2",
827
828 "Handover due to maximum TA exceeded\n\n"
829 "The MS in the current (best) cell has reached maximum allowed timing\n"
830 "advance. No handover is performed until the timing advance exceeds\n"
831 "it. The originating cell is still the best, but no handover is\n"
832 "performed back to that cell, because the penalty timer (due to\n"
833 "maximum allowed timing advance) is running.\n",
834
835 "create-bts", "2",
836 "create-ms", "0", "TCH/F", "AMR",
837 "set-max-ta", "0", "5", /* of cell */
838 "set-ta", "0", "5", /* of ms */
839 "meas-rep", "0", "30","0", "1","0","20",
840 "expect-no-chan",
841 "set-ta", "0", "6", /* of ms */
842 "meas-rep", "0", "30","0", "1","0","20",
843 "expect-chan", "1", "1",
844 "ack-chan",
845 "expect-ho", "0", "1",
846 "ho-complete",
847 "meas-rep", "0", "20","0", "1","0","30",
848 "expect-no-chan",
849 NULL
850};
851
852static char *test_case_17[] = {
853 "2",
854
855 "Congestion check: No congestion\n\n"
856 "Three cells have different number of used slots, but there is no\n"
857 "congestion in any of these cells. No handover is performed.\n",
858
859 "create-bts", "3",
860 "set-min-free", "0", "TCH/F", "2",
861 "set-min-free", "0", "TCH/H", "2",
862 "set-min-free", "1", "TCH/F", "2",
863 "set-min-free", "1", "TCH/H", "2",
864 "set-min-free", "2", "TCH/F", "2",
865 "set-min-free", "2", "TCH/H", "2",
866 "create-ms", "0", "TCH/F", "AMR",
867 "create-ms", "0", "TCH/F", "AMR",
868 "create-ms", "0", "TCH/H", "AMR",
869 "create-ms", "0", "TCH/H", "AMR",
870 "create-ms", "1", "TCH/F", "AMR",
871 "create-ms", "1", "TCH/H", "AMR",
872 "meas-rep", "0", "30","0", "2","0","20","1","20",
873 "expect-no-chan",
874 "meas-rep", "1", "30","0", "2","0","20","1","20",
875 "expect-no-chan",
876 "meas-rep", "2", "30","0", "2","0","20","1","20",
877 "expect-no-chan",
878 "meas-rep", "3", "30","0", "2","0","20","1","20",
879 "expect-no-chan",
880 "meas-rep", "4", "30","0", "2","0","20","1","20",
881 "expect-no-chan",
882 "meas-rep", "5", "30","0", "2","0","20","1","20",
883 "expect-no-chan",
884 "congestion-check",
885 "expect-no-chan",
886 NULL
887};
888
889static char *test_case_18[] = {
890 "2",
891
892 "Congestion check: One out of three cells is congested\n\n"
893 "Three cells have different number of used slots, but there is\n"
894 "congestion at TCH/F in the first cell. Handover is performed with\n"
895 "the best candidate.\n",
896
897 "create-bts", "3",
898 "set-min-free", "0", "TCH/F", "2",
899 "set-min-free", "0", "TCH/H", "2",
900 "set-min-free", "1", "TCH/F", "2",
901 "set-min-free", "1", "TCH/H", "2",
902 "set-min-free", "2", "TCH/F", "2",
903 "set-min-free", "2", "TCH/H", "2",
904 "create-ms", "0", "TCH/F", "AMR",
905 "create-ms", "0", "TCH/F", "AMR",
906 "create-ms", "0", "TCH/F", "AMR",
907 "create-ms", "0", "TCH/H", "AMR",
908 "create-ms", "0", "TCH/H", "AMR",
909 "create-ms", "1", "TCH/F", "AMR",
910 "create-ms", "1", "TCH/H", "AMR",
911 "meas-rep", "0", "30","0", "2","0","20","1","20",
912 "expect-no-chan",
913 "meas-rep", "1", "30","0", "2","0","20","1","20",
914 "expect-no-chan",
915 "meas-rep", "2", "30","0", "2","0","21","1","20",
916 "expect-no-chan",
917 "meas-rep", "3", "30","0", "2","0","20","1","20",
918 "expect-no-chan",
919 "meas-rep", "4", "30","0", "2","0","20","1","20",
920 "expect-no-chan",
921 "meas-rep", "5", "30","0", "2","0","20","1","20",
922 "expect-no-chan",
923 "meas-rep", "6", "30","0", "2","0","20","1","20",
924 "expect-no-chan",
925 "congestion-check",
926 "expect-chan", "1", "2",
927 "ack-chan",
928 "expect-ho", "0", "3", /* best candidate is MS 2 at BTS 1, TS 3 */
929 "ho-complete",
930 NULL
931};
932
933static char *test_case_19[] = {
934 "2",
935
936 "Congestion check: Balancing over congested cells\n\n"
937 "Two cells are congested, but the second cell is more congested.\n"
938 "Handover is performed to solve the congestion.\n",
939
940 "create-bts", "2",
941 "set-min-free", "0", "TCH/F", "4",
942 "set-min-free", "1", "TCH/F", "4",
943 "create-ms", "0", "TCH/F", "FR",
944 "create-ms", "0", "TCH/F", "FR",
945 "create-ms", "0", "TCH/F", "FR",
946 "create-ms", "1", "TCH/F", "FR",
947 "meas-rep", "0", "30","0", "1","0","20",
948 "expect-no-chan",
949 "meas-rep", "1", "30","0", "1","0","21",
950 "expect-no-chan",
951 "meas-rep", "2", "30","0", "1","0","20",
952 "expect-no-chan",
953 "meas-rep", "3", "30","0", "1","0","20",
954 "expect-no-chan",
955 "congestion-check",
956 "expect-chan", "1", "2",
957 "ack-chan",
958 "expect-ho", "0", "2", /* best candidate is MS 1 at BTS 0, TS 2 */
959 "ho-complete",
960 NULL
961};
962
963static char *test_case_20[] = {
964 "2",
965
966 "Congestion check: Solving congestion by handover TCH/F -> TCH/H\n\n"
967 "Two BTS, one MS in the first congested BTS must handover to\n"
968 "non-congested TCH/H of second BTS, in order to solve congestion\n",
969 "create-bts", "2",
970 "set-min-free", "0", "TCH/F", "4",
971 "set-min-free", "0", "TCH/H", "4",
972 "set-min-free", "1", "TCH/F", "4",
973 "create-ms", "0", "TCH/F", "AMR",
974 "meas-rep", "0", "30","0", "1","0","30",
975 "expect-no-chan",
976 "congestion-check",
977 "expect-chan", "1", "5",
978 "ack-chan",
979 "expect-ho", "0", "1",
980 "ho-complete",
981 NULL
982};
983
984static char *test_case_21[] = {
985 "2",
986
987 "Congestion check: Balancing congestion by handover TCH/F -> TCH/H\n\n"
988 "Two BTS, one MS in the first congested BTS must handover to\n"
989 "less-congested TCH/H of second BTS, in order to balance congestion\n",
990 "create-bts", "2",
991 "set-min-free", "0", "TCH/F", "4",
992 "set-min-free", "0", "TCH/H", "4",
993 "set-min-free", "1", "TCH/F", "4",
994 "set-min-free", "1", "TCH/H", "4",
995 "create-ms", "0", "TCH/F", "AMR",
996 "create-ms", "0", "TCH/F", "AMR",
997 "create-ms", "0", "TCH/H", "AMR",
998 "meas-rep", "0", "30","0", "1","0","30",
999 "expect-no-chan",
1000 "congestion-check",
1001 "expect-chan", "1", "1",
1002 "ack-chan",
1003 "expect-ho", "0", "1",
1004 "ho-complete",
1005 NULL
1006};
1007
1008static char *test_case_22[] = {
1009 "2",
1010
1011 "Congestion check: Upgrading worst candidate from TCH/H -> TCH/F\n\n"
1012 "There is only one BTS. The TCH/H slots are congested. Since\n"
1013 "assignment is performed to less-congested TCH/F, the candidate with\n"
1014 "the worst RX level is chosen.\n",
1015
1016 "create-bts", "1",
1017 "set-min-free", "0", "TCH/F", "4",
1018 "set-min-free", "0", "TCH/H", "4",
1019 "create-ms", "0", "TCH/H", "AMR",
1020 "create-ms", "0", "TCH/H", "AMR",
1021 "create-ms", "0", "TCH/H", "AMR",
1022 "meas-rep", "0", "30","0", "0",
1023 "meas-rep", "1", "34","0", "0",
1024 "meas-rep", "2", "20","0", "0",
1025 "expect-no-chan",
1026 "congestion-check",
1027 "expect-chan", "0", "1",
1028 "ack-chan",
1029 "expect-ho", "0", "6",
1030 "ho-complete",
1031 NULL
1032};
1033
1034static char *test_case_23[] = {
1035 "2",
1036
1037 "Story: 'A neighbor is your friend'\n",
1038
1039 "create-bts", "3",
1040
1041 "print",
1042 "Andreas is driving along the coast, on a sunny june afternoon.\n"
1043 "Suddenly he is getting a call from his friend and neighbor Axel.\n"
1044 "\n"
1045 "What happens: Two MS are created, #0 for Axel, #1 for Andreas.",
1046 /* Axel */
1047 "create-ms", "2", "TCH/F", "AMR",
1048 /* andreas */
1049 "create-ms", "0", "TCH/F", "AMR",
1050 "meas-rep", "1", "40","0", "1","0","30",
1051 "expect-no-chan",
1052
1053 "print",
1054 "Axel asks Andreas if he would like to join them for a barbecue.\n"
1055 "Axel's house is right in the neighborhood and the weather is fine.\n"
1056 "Andreas agrees, so he drives to a close store to buy some barbecue\n"
1057 "skewers.\n"
1058 "\n"
1059 "What happens: While driving, a different cell (mounted atop the\n"
1060 "store) becomes better.",
1061 /* drive to bts 1 */
1062 "meas-rep", "1", "20","0", "1","0","35",
1063 "expect-chan", "1", "1",
1064 "ack-chan",
1065 "expect-ho", "0", "1",
1066 "ho-complete",
1067
1068 "print",
1069 "While Andreas is walking into the store, Axel asks, if he could also\n"
1070 "bring some beer. Andreas has problems understanding him: \"I have a\n"
1071 "bad reception here. The cell tower is right atop the store, but poor\n"
1072 "coverage inside. Can you repeat please?\"\n"
1073 "\n"
1074 "What happens: Inside the store the close cell is so bad, that\n"
1075 "handover back to the previous cell is required.",
1076 /* bts 1 becomes bad, so bts 0 helps out */
1077 "meas-rep", "1", "5","0", "1","0","20",
1078 "expect-chan", "0", "1",
1079 "ack-chan",
1080 "expect-ho", "1", "1",
1081 "ho-complete",
1082
1083 "print",
1084 "After Andreas bought skewers and beer, he leaves the store.\n"
1085 "\n"
1086 "What happens: Outside the store the close cell is better again, so\n"
1087 "handover back to the that cell is performed.",
1088 /* bts 1 becomes better again */
1089 "meas-rep", "1", "20","0", "1","0","35",
1090 "expect-chan", "1", "1",
1091 "ack-chan",
1092 "expect-ho", "0", "1",
1093 "ho-complete",
1094
1095 "print",
1096 /* bts 2 becomes better */
1097 "Andreas drives down to the lake where Axel's house is.\n"
1098 "\n"
1099 "What happens: There is a small cell at Axel's house, which becomes\n"
1100 "better, because the current cell has no good comverage at the lake.",
1101 "meas-rep", "1", "14","0", "2","0","2","1","63",
1102 "expect-chan", "2", "2",
1103 "ack-chan",
1104 "expect-ho", "1", "1",
1105 "ho-complete",
1106
1107 "print",
1108 "Andreas wonders why he still has good radio coverage: \"Last time it\n"
1109 "was so bad\". Axel says: \"I installed a pico cell in my house,\n"
1110 "now we can use our mobile phones down here at the lake.\"",
1111
1112 NULL
1113};
1114
1115static char *test_case_24[] = {
1116 "2",
1117 "No (or not enough) measurements for handover\n\n"
1118 "Do not solve congestion in cell, because there is no measurement.\n"
1119 "As soon as enough measurments available (1 in our case), perform\n"
1120 "handover. Afterwards the old cell becomes congested and the new\n"
1121 "cell is not. Do not perform handover until new measurements are\n"
1122 "received.\n",
1123
1124 /* two cells, first in congested, but no handover */
1125 "create-bts", "2",
1126 "set-min-free", "0", "TCH/F", "4",
1127 "set-min-free", "0", "TCH/H", "4",
1128 "create-ms", "0", "TCH/F", "AMR",
1129 "congestion-check",
1130 "expect-no-chan",
1131
1132 /* send measurement and trigger congestion check */
1133 "meas-rep", "0", "20","0", "1","0","20",
1134 "expect-no-chan",
1135 "congestion-check",
1136 "expect-chan", "1", "1",
1137 "ack-chan",
1138 "expect-ho", "0", "1",
1139 "ho-complete",
1140
1141 /* congest the first cell and remove congestion from second cell */
1142 "set-min-free", "0", "TCH/F", "0",
1143 "set-min-free", "0", "TCH/H", "0",
1144 "set-min-free", "1", "TCH/F", "4",
1145 "set-min-free", "1", "TCH/H", "4",
1146
1147 /* no handover until measurements applied */
1148 "congestion-check",
1149 "expect-no-chan",
1150 "meas-rep", "0", "20","0", "1","0","20",
1151 "expect-no-chan",
1152 "congestion-check",
1153 "expect-chan", "0", "1",
1154 "ack-chan",
1155 "expect-ho", "1", "1",
1156 "ho-complete",
1157 NULL
1158};
1159
1160static char *test_case_25[] = {
1161 "1",
1162
1163 "Stay in better cell\n\n"
1164 "There are many neighbor cells, but only the current cell is the best\n"
1165 "cell, so no handover is performed\n",
1166
1167 "create-bts", "7",
1168 "create-ms", "0", "TCH/F", "AMR",
1169 "meas-rep", "0", "30","0",
1170 "6","0","20","1","21","2","18","3","20","4","23","5","19",
1171 "expect-no-chan",
1172 NULL
1173};
1174
1175static char *test_case_26[] = {
1176 "1",
1177
1178 "Handover to best better cell\n\n"
1179 "The best neighbor cell is selected\n",
1180
1181 "create-bts", "7",
1182 "create-ms", "0", "TCH/F", "AMR",
1183 "meas-rep", "0", "10","0",
1184 "6","0","20","1","21","2","18","3","20","4","23","5","19",
1185 "expect-chan", "5", "1",
1186 "ack-chan",
1187 "expect-ho", "0", "1",
1188 "ho-complete",
1189 NULL
1190};
1191
1192static char *test_case_27[] = {
1193 "2",
1194
1195 "Congestion check: Upgrading worst candidate from TCH/H -> TCH/F\n\n"
1196 "There is only one BTS. The TCH/H slots are congested. Since\n"
1197 "assignment is performed to less-congested TCH/F, the candidate with\n"
1198 "the worst RX level is chosen. (So far like test 22.)\n"
1199 "After that, trigger more congestion checks to ensure stability.\n",
1200
1201 "create-bts", "1",
1202 "set-min-free", "0", "TCH/F", "2",
1203 "set-min-free", "0", "TCH/H", "4",
1204 "create-ms", "0", "TCH/H", "AMR",
1205 "create-ms", "0", "TCH/H", "AMR",
1206 "create-ms", "0", "TCH/H", "AMR",
1207 "meas-rep", "0", "30","0", "0",
1208 "meas-rep", "1", "34","0", "0",
1209 "meas-rep", "2", "20","0", "0",
1210 "expect-no-chan",
1211 "congestion-check",
1212 "expect-chan", "0", "1",
1213 "ack-chan",
1214 "expect-ho", "0", "6",
1215 "ho-complete",
1216 "congestion-check",
1217 "expect-chan", "0", "2",
1218 "ack-chan",
1219 "expect-ho", "0", "5",
1220 "ho-complete",
1221 "congestion-check",
1222 "expect-no-chan",
1223 "congestion-check",
1224 "expect-no-chan",
1225 NULL
1226};
1227
1228static char *test_case_28[] = {
1229 "2",
1230
1231 "Handover to congested cell, if RX quality is below minimum\n\n"
1232 "The better neighbor cell is congested, so no handover is performed.\n"
1233 "If the RX quality of the current cell drops below minimum acceptable\n"
1234 "level, the handover is performed. It is also required that 10\n"
1235 "resports are received, before RX quality is checked.\n",
1236
1237 "create-bts", "2",
1238 "create-ms", "0", "TCH/F", "AMR",
1239 "set-min-free", "1", "TCH/F", "4",
1240 "set-min-free", "1", "TCH/H", "4",
1241 "meas-rep", "0", "30","6", "1","0","40",
1242 "expect-no-chan",
1243 "meas-rep", "0", "30","6", "1","0","40",
1244 "expect-no-chan",
1245 "meas-rep", "0", "30","6", "1","0","40",
1246 "expect-no-chan",
1247 "meas-rep", "0", "30","6", "1","0","40",
1248 "expect-no-chan",
1249 "meas-rep", "0", "30","6", "1","0","40",
1250 "expect-no-chan",
1251 "meas-rep", "0", "30","6", "1","0","40",
1252 "expect-no-chan",
1253 "meas-rep", "0", "30","6", "1","0","40",
1254 "expect-no-chan",
1255 "meas-rep", "0", "30","6", "1","0","40",
1256 "expect-no-chan",
1257 "meas-rep", "0", "30","6", "1","0","40",
1258 "expect-no-chan",
1259 "meas-rep", "0", "30","6", "1","0","40",
1260 "expect-chan", "1", "1",
1261 "ack-chan",
1262 "expect-ho", "0", "1",
1263 "ho-complete",
1264 NULL
1265};
1266
1267static char **test_cases[] = {
1268 test_case_0,
1269 test_case_1,
1270 test_case_2,
1271 test_case_3,
1272 test_case_4,
1273 test_case_5,
1274 test_case_6,
1275 test_case_7,
1276 test_case_8,
1277 test_case_9,
1278 test_case_10,
1279 test_case_11,
1280 test_case_12,
1281 test_case_13,
1282 test_case_14,
1283 test_case_15,
1284 test_case_16,
1285 test_case_17,
1286 test_case_18,
1287 test_case_19,
1288 test_case_20,
1289 test_case_21,
1290 test_case_22,
1291 test_case_23,
1292 test_case_24,
1293 test_case_25,
1294 test_case_26,
1295 test_case_27,
1296 test_case_28,
Neels Hofmeyr909e9722017-12-07 03:54:01 +01001297};
1298
1299static const struct log_info_cat log_categories[] = {
1300 [DHO] = {
1301 .name = "DHO",
1302 .description = "Hand-Over Process",
1303 .color = "\033[1;38m",
1304 .enabled = 1, .loglevel = LOGL_DEBUG,
1305 },
1306 [DHODEC] = {
1307 .name = "DHODEC",
1308 .description = "Hand-Over Decision",
1309 .color = "\033[1;38m",
1310 .enabled = 1, .loglevel = LOGL_DEBUG,
1311 },
1312 [DMEAS] = {
1313 .name = "DMEAS",
1314 .description = "Radio Measurement Processing",
1315 .enabled = 1, .loglevel = LOGL_DEBUG,
1316 },
1317 [DREF] = {
1318 .name = "DREF",
1319 .description = "Reference Counting",
1320 .enabled = 1, .loglevel = LOGL_DEBUG,
1321 },
1322 [DRSL] = {
1323 .name = "DRSL",
1324 .description = "A-bis Radio Siganlling Link (RSL)",
1325 .color = "\033[1;35m",
1326 .enabled = 1, .loglevel = LOGL_DEBUG,
1327 },
Harald Welte3561bd42018-01-28 03:04:16 +01001328 [DMSC] = {
1329 .name = "DMSC",
1330 .description = "Mobile Switching Center",
1331 .enabled = 1, .loglevel = LOGL_DEBUG,
1332 },
Neels Hofmeyr909e9722017-12-07 03:54:01 +01001333};
1334
1335const struct log_info log_info = {
1336 .cat = log_categories,
1337 .num_cat = ARRAY_SIZE(log_categories),
1338};
1339
1340int main(int argc, char **argv)
1341{
1342 char **test_case;
1343 struct gsm_bts *bts[256];
1344 int bts_num = 0;
1345 struct gsm_lchan *lchan[256];
1346 int lchan_num = 0;
Neels Hofmeyr909e9722017-12-07 03:54:01 +01001347 int i;
1348 int algorithm;
1349 struct bsc_api bsc_api = {};
Neels Hofmeyr00727552018-02-21 14:33:15 +01001350 int test_case_i;
1351 int last_test_i;
Neels Hofmeyr909e9722017-12-07 03:54:01 +01001352
Neels Hofmeyr00727552018-02-21 14:33:15 +01001353 test_case_i = argc > 1? atoi(argv[1]) : -1;
1354 last_test_i = ARRAY_SIZE(test_cases) - 1;
Neels Hofmeyr909e9722017-12-07 03:54:01 +01001355
Neels Hofmeyr00727552018-02-21 14:33:15 +01001356 if (test_case_i < 0 || test_case_i > last_test_i) {
1357 for (i = 0; i <= last_test_i; i++) {
Neels Hofmeyr909e9722017-12-07 03:54:01 +01001358 printf("Test #%d (algorithm %s):\n%s\n", i,
1359 test_cases[i][0], test_cases[i][1]);
1360 }
Neels Hofmeyr00727552018-02-21 14:33:15 +01001361 printf("\nPlease specify test case number 0..%d\n", last_test_i);
Neels Hofmeyr909e9722017-12-07 03:54:01 +01001362 return EXIT_FAILURE;
1363 }
1364
1365 osmo_init_logging(&log_info);
1366
1367 log_set_print_category(osmo_stderr_target, 1);
1368 log_set_print_category_hex(osmo_stderr_target, 0);
1369 log_set_print_filename2(osmo_stderr_target, LOG_FILENAME_BASENAME);
1370
1371 /* Create a dummy network */
Neels Hofmeyrf7a63292018-02-27 12:37:26 +01001372 bsc_gsmnet = bsc_network_init(NULL);
Neels Hofmeyr909e9722017-12-07 03:54:01 +01001373 if (!bsc_gsmnet)
1374 exit(1);
1375
1376 bsc_api_init(bsc_gsmnet, &bsc_api);
1377
1378 ho_set_algorithm(bsc_gsmnet->ho, 2);
1379 ho_set_ho_active(bsc_gsmnet->ho, true);
1380 ho_set_hodec2_as_active(bsc_gsmnet->ho, true);
1381 ho_set_hodec2_min_rxlev(bsc_gsmnet->ho, -100);
1382 ho_set_hodec2_rxlev_avg_win(bsc_gsmnet->ho, 1);
1383 ho_set_hodec2_rxlev_neigh_avg_win(bsc_gsmnet->ho, 1);
1384 ho_set_hodec2_rxqual_avg_win(bsc_gsmnet->ho, 10);
1385 ho_set_hodec2_pwr_hysteresis(bsc_gsmnet->ho, 3);
1386 ho_set_hodec2_pwr_interval(bsc_gsmnet->ho, 1);
1387 ho_set_hodec2_afs_bias_rxlev(bsc_gsmnet->ho, 0);
1388 ho_set_hodec2_min_rxqual(bsc_gsmnet->ho, 5);
1389 ho_set_hodec2_afs_bias_rxqual(bsc_gsmnet->ho, 0);
1390 ho_set_hodec2_max_distance(bsc_gsmnet->ho, 9999);
1391 ho_set_hodec2_ho_max(bsc_gsmnet->ho, 9999);
1392 ho_set_hodec2_penalty_max_dist(bsc_gsmnet->ho, 300);
1393 ho_set_hodec2_penalty_failed_ho(bsc_gsmnet->ho, 60);
1394 ho_set_hodec2_penalty_failed_as(bsc_gsmnet->ho, 60);
1395
1396 bts_model_sysmobts_init();
1397
Neels Hofmeyr00727552018-02-21 14:33:15 +01001398 test_case = test_cases[test_case_i];
Neels Hofmeyr909e9722017-12-07 03:54:01 +01001399
1400 fprintf(stderr, "--------------------\n");
1401 fprintf(stderr, "Performing the following test %d (algorithm %s):\n%s",
Neels Hofmeyr00727552018-02-21 14:33:15 +01001402 test_case_i, test_case[0], test_case[1]);
Neels Hofmeyr909e9722017-12-07 03:54:01 +01001403 algorithm = atoi(test_case[0]);
1404 test_case += 2;
1405 fprintf(stderr, "--------------------\n");
1406
1407 /* Disable the congestion check timer, we will trigger manually. */
1408 bsc_gsmnet->hodec2.congestion_check_interval_s = 0;
1409
1410 handover_decision_1_init();
1411 hodec2_init(bsc_gsmnet);
1412
1413 while (*test_case) {
1414 if (!strcmp(*test_case, "create-bts")) {
1415 static int arfcn = 870;
1416 int n = atoi(test_case[1]);
1417 fprintf(stderr, "- Creating %d BTS (one TRX each, "
1418 "TS(1-4) are TCH/F, TS(5-6) are TCH/H)\n", n);
1419 for (i = 0; i < n; i++)
1420 bts[bts_num + i] = create_bts(arfcn++);
Neels Hofmeyr00727552018-02-21 14:33:15 +01001421 for (i = 0; i < n; i++) {
1422 if (gsm_generate_si(bts[bts_num + i], SYSINFO_TYPE_2))
1423 fprintf(stderr, "Error generating SI2\n");
1424 }
Neels Hofmeyr909e9722017-12-07 03:54:01 +01001425 bts_num += n;
1426 test_case += 2;
1427 } else
1428 if (!strcmp(*test_case, "as-enable")) {
1429 fprintf(stderr, "- Set assignment enable state at "
1430 "BTS %s to %s\n", test_case[1], test_case[2]);
1431 ho_set_hodec2_as_active(bts[atoi(test_case[1])]->ho, atoi(test_case[2]));
1432 test_case += 3;
1433 } else
1434 if (!strcmp(*test_case, "ho-enable")) {
1435 fprintf(stderr, "- Set handover enable state at "
1436 "BTS %s to %s\n", test_case[1], test_case[2]);
1437 ho_set_ho_active(bts[atoi(test_case[1])]->ho, atoi(test_case[2]));
1438 test_case += 3;
1439 } else
1440 if (!strcmp(*test_case, "afs-rxlev-improve")) {
1441 fprintf(stderr, "- Set afs RX level improvement at "
1442 "BTS %s to %s\n", test_case[1], test_case[2]);
1443 ho_set_hodec2_afs_bias_rxlev(bts[atoi(test_case[1])]->ho, atoi(test_case[2]));
1444 test_case += 3;
1445 } else
1446 if (!strcmp(*test_case, "afs-rxqual-improve")) {
1447 fprintf(stderr, "- Set afs RX quality improvement at "
1448 "BTS %s to %s\n", test_case[1], test_case[2]);
1449 ho_set_hodec2_afs_bias_rxqual(bts[atoi(test_case[1])]->ho, atoi(test_case[2]));
1450 test_case += 3;
1451 } else
1452 if (!strcmp(*test_case, "set-min-free")) {
1453 fprintf(stderr, "- Setting minimum required free %s "
1454 "slots at BTS %s to %s\n", test_case[2],
1455 test_case[1], test_case[3]);
1456 if (!strcmp(test_case[2], "TCH/F"))
1457 ho_set_hodec2_tchf_min_slots(bts[atoi(test_case[1])]->ho, atoi(test_case[3]));
1458 else
1459 ho_set_hodec2_tchh_min_slots(bts[atoi(test_case[1])]->ho, atoi(test_case[3]));
1460 test_case += 4;
1461 } else
1462 if (!strcmp(*test_case, "set-max-ho")) {
1463 fprintf(stderr, "- Setting maximum parallel handovers "
1464 "at BTS %s to %s\n", test_case[1],
1465 test_case[2]);
1466 ho_set_hodec2_ho_max( bts[atoi(test_case[1])]->ho, atoi(test_case[2]));
1467 test_case += 3;
1468 } else
1469 if (!strcmp(*test_case, "set-max-ta")) {
1470 fprintf(stderr, "- Setting maximum timing advance "
1471 "at BTS %s to %s\n", test_case[1],
1472 test_case[2]);
1473 ho_set_hodec2_max_distance(bts[atoi(test_case[1])]->ho, atoi(test_case[2]));
1474 test_case += 3;
1475 } else
1476 if (!strcmp(*test_case, "create-ms")) {
1477 fprintf(stderr, "- Creating mobile #%d at BTS %s on "
1478 "%s with %s codec\n", lchan_num, test_case[1],
1479 test_case[2], test_case[3]);
1480 lchan[lchan_num] = create_lchan(bts[atoi(test_case[1])],
1481 !strcmp(test_case[2], "TCH/F"), test_case[3]);
1482 if (!lchan[lchan_num]) {
1483 printf("Failed to create lchan!\n");
1484 return EXIT_FAILURE;
1485 }
1486 fprintf(stderr, " * New MS is at BTS %d TS %d\n",
1487 lchan[lchan_num]->ts->trx->bts->nr,
1488 lchan[lchan_num]->ts->nr);
1489 lchan_num++;
1490 test_case += 4;
1491 } else
1492 if (!strcmp(*test_case, "set-ta")) {
1493 fprintf(stderr, "- Setting maximum timing advance "
1494 "at MS %s to %s\n", test_case[1],
1495 test_case[2]);
1496 meas_ta_ms = atoi(test_case[2]);
1497 test_case += 3;
1498 } else
1499 if (!strcmp(*test_case, "meas-rep")) {
1500 /* meas-rep <lchan-nr> <rxlev> <rxqual> <nr-of-neighbors> [<cell-idx> <rxlev> [...]] */
1501 int n = atoi(test_case[4]);
1502 struct gsm_lchan *lc = lchan[atoi(test_case[1])];
1503 fprintf(stderr, "- Sending measurement report from "
1504 "mobile #%s (rxlev=%s, rxqual=%s)\n",
1505 test_case[1], test_case[2], test_case[3]);
1506 meas_dl_rxlev = atoi(test_case[2]);
1507 meas_dl_rxqual = atoi(test_case[3]);
1508 meas_num_nc = n;
1509 test_case += 5;
1510 for (i = 0; i < n; i++) {
1511 int nr = atoi(test_case[0]);
1512 /* since our bts is not in the list of neighbor
1513 * cells, we need to shift */
1514 if (nr >= lc->ts->trx->bts->nr)
1515 nr++;
1516 fprintf(stderr, " * Neighbor cell #%s, actual "
1517 "BTS %d (rxlev=%s)\n", test_case[0], nr,
1518 test_case[1]);
1519 meas_bcch_f_nc[i] = atoi(test_case[0]);
1520 /* bts number, not counting our own */
1521 meas_rxlev_nc[i] = atoi(test_case[1]);
1522 meas_bsic_nc[i] = 0x3f;
1523 test_case += 2;
1524 }
1525 got_chan_req = 0;
1526 gen_meas_rep(lc);
1527 } else
1528 if (!strcmp(*test_case, "congestion-check")) {
1529 fprintf(stderr, "- Triggering congestion check\n");
1530 got_chan_req = 0;
1531 if (algorithm == 2)
1532 hodec2_congestion_check(bsc_gsmnet);
1533 test_case += 1;
1534 } else
1535 if (!strcmp(*test_case, "expect-chan")) {
1536 fprintf(stderr, "- Expecting channel request at BTS %s "
1537 "TS %s\n", test_case[1], test_case[2]);
1538 if (!got_chan_req) {
1539 printf("Test failed, because no channel was "
1540 "requested\n");
1541 return EXIT_FAILURE;
1542 }
1543 fprintf(stderr, " * Got channel request at BTS %d "
1544 "TS %d\n", chan_req_lchan->ts->trx->bts->nr,
1545 chan_req_lchan->ts->nr);
1546 if (chan_req_lchan->ts->trx->bts->nr
1547 != atoi(test_case[1])) {
1548 printf("Test failed, because channel was not "
1549 "requested on expected BTS\n");
1550 return EXIT_FAILURE;
1551 }
1552 if (chan_req_lchan->ts->nr != atoi(test_case[2])) {
1553 printf("Test failed, because channel was not "
1554 "requested on expected TS\n");
1555 return EXIT_FAILURE;
1556 }
1557 test_case += 3;
1558 } else
1559 if (!strcmp(*test_case, "expect-no-chan")) {
1560 fprintf(stderr, "- Expecting no channel request\n");
1561 if (got_chan_req) {
1562 fprintf(stderr, " * Got channel request at "
1563 "BTS %d TS %d\n",
1564 chan_req_lchan->ts->trx->bts->nr,
1565 chan_req_lchan->ts->nr);
1566 printf("Test failed, because channel was "
1567 "requested\n");
1568 return EXIT_FAILURE;
1569 }
1570 fprintf(stderr, " * Got no channel request\n");
1571 test_case += 1;
1572 } else
1573 if (!strcmp(*test_case, "expect-ho")) {
1574 fprintf(stderr, "- Expecting handover/assignment "
1575 "request at BTS %s TS %s\n", test_case[1],
1576 test_case[2]);
1577 if (!got_ho_req) {
1578 printf("Test failed, because no handover was "
1579 "requested\n");
1580 return EXIT_FAILURE;
1581 }
1582 fprintf(stderr, " * Got handover/assignment request at "
1583 "BTS %d TS %d\n",
1584 ho_req_lchan->ts->trx->bts->nr,
1585 ho_req_lchan->ts->nr);
1586 if (ho_req_lchan->ts->trx->bts->nr
1587 != atoi(test_case[1])) {
1588 printf("Test failed, because "
1589 "handover/assignment was not commanded "
1590 "at the expected BTS\n");
1591 return EXIT_FAILURE;
1592 }
1593 if (ho_req_lchan->ts->nr != atoi(test_case[2])) {
1594 printf("Test failed, because "
1595 "handover/assignment was not commanded "
1596 "at the expected TS\n");
1597 return EXIT_FAILURE;
1598 }
1599 test_case += 3;
1600 } else
1601 if (!strcmp(*test_case, "ack-chan")) {
1602 fprintf(stderr, "- Acknowledging channel request\n");
1603 if (!got_chan_req) {
1604 printf("Cannot ack channel, because no "
1605 "request\n");
1606 return EXIT_FAILURE;
1607 }
1608 test_case += 1;
1609 got_ho_req = 0;
1610 send_chan_act_ack(chan_req_lchan, 1);
1611 } else
1612 if (!strcmp(*test_case, "ho-complete")) {
1613 fprintf(stderr, "- Acknowledging handover/assignment "
1614 "request\n");
1615 if (!got_chan_req) {
1616 printf("Cannot ack handover/assignment, "
1617 "because no chan request\n");
1618 return EXIT_FAILURE;
1619 }
1620 if (!got_ho_req) {
1621 printf("Cannot ack handover/assignment, "
1622 "because no ho request\n");
1623 return EXIT_FAILURE;
1624 }
1625 test_case += 1;
1626 got_chan_req = 0;
1627 got_ho_req = 0;
1628 /* switch lchan */
1629 for (i = 0; i < lchan_num; i++) {
1630 if (lchan[i] == ho_req_lchan) {
1631 fprintf(stderr, " * MS %d changes from "
1632 "BTS=%d TS=%d to BTS=%d "
1633 "TS=%d\n", i,
1634 lchan[i]->ts->trx->bts->nr,
1635 lchan[i]->ts->nr,
1636 chan_req_lchan->ts->trx->bts->nr,
1637 chan_req_lchan->ts->nr);
1638 lchan[i] = chan_req_lchan;
1639 }
1640 }
1641 send_ho_complete(chan_req_lchan, true);
1642 } else
1643 if (!strcmp(*test_case, "ho-failed")) {
1644 fprintf(stderr, "- Making handover fail\n");
1645 if (!got_chan_req) {
1646 printf("Cannot fail handover, because no chan "
1647 "request\n");
1648 return EXIT_FAILURE;
1649 }
1650 test_case += 1;
1651 got_chan_req = 0;
1652 got_ho_req = 0;
1653 send_ho_complete(ho_req_lchan, false);
1654 } else
1655 if (!strcmp(*test_case, "print")) {
1656 fprintf(stderr, "\n%s\n\n", test_case[1]);
1657 test_case += 2;
1658 } else {
1659 printf("Unknown test command '%s', please fix!\n",
1660 *test_case);
1661 return EXIT_FAILURE;
1662 }
1663 }
1664
1665 for (i = 0; i < lchan_num; i++) {
1666 struct gsm_subscriber_connection *conn = lchan[i]->conn;
1667 lchan[i]->conn = NULL;
1668 conn->lchan = NULL;
Harald Welte3561bd42018-01-28 03:04:16 +01001669 osmo_fsm_inst_term(conn->fi, OSMO_FSM_TERM_REGULAR, NULL);
Neels Hofmeyr909e9722017-12-07 03:54:01 +01001670 lchan_free(lchan[i]);
1671 }
1672
1673 fprintf(stderr, "--------------------\n");
1674
1675 printf("Test OK\n");
1676
1677 fprintf(stderr, "--------------------\n");
1678
1679 return EXIT_SUCCESS;
1680}
1681
1682void rtp_socket_free() {}
1683void rtp_send_frame() {}
1684void rtp_socket_upstream() {}
1685void rtp_socket_create() {}
1686void rtp_socket_connect() {}
1687void rtp_socket_proxy() {}
1688void trau_mux_unmap() {}
1689void trau_mux_map_lchan() {}
1690void trau_recv_lchan() {}
1691void trau_send_frame() {}
Harald Welte3561bd42018-01-28 03:04:16 +01001692int osmo_bsc_sigtran_send(struct gsm_subscriber_connection *conn, struct msgb *msg) { return 0; }
1693int osmo_bsc_sigtran_open_conn(struct gsm_subscriber_connection *conn, struct msgb *msg) { return 0; }