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