blob: d1f75ba4ed5175eaf8209aae674c17efd126d946 [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
342/* RSL messages from BSC */
343int abis_rsl_sendmsg(struct msgb *msg)
344{
345 struct abis_rsl_dchan_hdr *dh = (struct abis_rsl_dchan_hdr *) msg->data;
346 struct e1inp_sign_link *sign_link = msg->dst;
347 int rc;
348 struct gsm_lchan *lchan = rsl_lchan_lookup(sign_link->trx, dh->chan_nr, &rc);
349
350 if (rc) {
351 printf("rsl_lchan_lookup() failed\n");
352 exit(1);
353 }
354
355 switch (dh->c.msg_type) {
356 case RSL_MT_CHAN_ACTIV:
357 rc = parse_chan_act(lchan, dh->data);
358 if (rc == 0)
359 got_chan_req = 1;
360 break;
361 case RSL_MT_RF_CHAN_REL:
362 rc = parse_chan_rel(lchan, dh->data);
363 if (rc == 0)
364 send_chan_act_ack(chan_req_lchan, 0);
365 break;
366 case RSL_MT_DATA_REQ:
367 rc = parse_ho_command(lchan, msg->l3h, msgb_l3len(msg));
368 if (rc == 0)
369 got_ho_req = 1;
370 break;
371 case RSL_MT_IPAC_CRCX:
372 break;
373 default:
374 printf("unknown rsl message=0x%x\n", dh->c.msg_type);
375 }
376 return 0;
377}
378
379/* test cases */
380
381static char *test_case_0[] = {
382 "2",
383
384 "Stay in better cell\n\n"
385 "There are many neighbor cells, but only the current cell is the best\n"
386 "cell, so no handover is performed\n",
387
388 "create-bts", "7",
389 "create-ms", "0", "TCH/F", "AMR",
390 "meas-rep", "0", "30","0",
391 "6","0","20","1","21","2","18","3","20","4","23","5","19",
392 "expect-no-chan",
393 NULL
394};
395
396static char *test_case_1[] = {
397 "2",
398
399 "Handover to best better cell\n\n"
400 "The best neighbor cell is selected\n",
401
402 "create-bts", "7",
403 "create-ms", "0", "TCH/F", "AMR",
404 "meas-rep", "0", "10","0",
405 "6","0","20","1","21","2","18","3","20","4","23","5","19",
406 "expect-chan", "5", "1",
407 "ack-chan",
408 "expect-ho", "0", "1",
409 "ho-complete",
410 NULL
411};
412
413static char *test_case_2[] = {
414 "2",
415
416 "Handover and Assignment must be enabled\n\n"
417 "This test will start with disabled assignment and handover. A\n"
418 "better neighbor cell (assignment enabled) will not be selected and \n"
419 "also no assignment from TCH/H to TCH/F to improve quality. There\n"
420 "will be no handover nor assignment. After enabling assignment on the\n"
421 "current cell, the MS will assign to TCH/F. After enabling handover\n"
422 "in the current cell, but disabling in the neighbor cell, handover\n"
423 "will not be performed, until it is enabled in the neighbor cell too.\n",
424
425 "create-bts", "2",
426 "afs-rxlev-improve", "0", "5",
427 "create-ms", "0", "TCH/H", "AMR",
428 "as-enable", "0", "0",
429 "ho-enable", "0", "0",
430 "meas-rep", "0", "0","0", "1","0","30",
431 "expect-no-chan",
432 "as-enable", "0", "1",
433 "meas-rep", "0", "0","0", "1","0","30",
434 "expect-chan", "0", "1",
435 "ack-chan",
436 "expect-ho", "0", "5",
437 "ho-complete",
438 "ho-enable", "0", "1",
439 "ho-enable", "1", "0",
440 "meas-rep", "0", "0","0", "1","0","30",
441 "expect-no-chan",
442 "ho-enable", "1", "1",
443 "meas-rep", "0", "0","0", "1","0","30",
444 "expect-chan", "1", "1",
445 "ack-chan",
446 "expect-ho", "0", "1",
447 "ho-complete",
448 NULL
449};
450
451static char *test_case_3[] = {
452 "2",
453
454 "Penalty timer must not run\n\n"
455 "The MS will try to handover to a better cell, but this will fail.\n"
456 "Even though the cell is still better, handover will not be performed\n"
457 "due to penalty timer after handover failure\n",
458
459 "create-bts", "2",
460 "create-ms", "0", "TCH/F", "AMR",
461 "meas-rep", "0", "20","0", "1","0","30",
462 "expect-chan", "1", "1",
463 "ack-chan",
464 "expect-ho", "0", "1",
465 "ho-failed",
466 "meas-rep", "0", "20","0", "1","0","30",
467 "expect-no-chan",
468 NULL
469};
470
471static char *test_case_4[] = {
472 "2",
473
474 "TCH/H keeping with HR codec\n\n"
475 "The MS is using half rate V1 codec, but the better cell is congested\n"
476 "at TCH/H slots. As the congestion is removed, the handover takes\n"
477 "place.\n",
478
479 "create-bts", "2",
480 "set-min-free", "1", "TCH/H", "4",
481 "create-ms", "0", "TCH/H", "HR",
482 "meas-rep", "0", "20","0", "1","0","30",
483 "expect-no-chan",
484 "set-min-free", "1", "TCH/H", "3",
485 "meas-rep", "0", "20","0", "1","0","30",
486 "expect-chan", "1", "5",
487 "ack-chan",
488 "expect-ho", "0", "5",
489 "ho-complete",
490 NULL
491};
492
493static char *test_case_5[] = {
494 "2",
495
496 "TCH/F keeping with FR codec\n\n"
497 "The MS is using full rate V1 codec, but the better cell is congested\n"
498 "at TCH/F slots. As the congestion is removed, the handover takes\n"
499 "place.\n",
500
501 "create-bts", "2",
502 "set-min-free", "1", "TCH/F", "4",
503 "create-ms", "0", "TCH/F", "FR",
504 "meas-rep", "0", "20","0", "1","0","30",
505 "expect-no-chan",
506 "set-min-free", "1", "TCH/F", "3",
507 "meas-rep", "0", "20","0", "1","0","30",
508 "expect-chan", "1", "1",
509 "ack-chan",
510 "expect-ho", "0", "1",
511 "ho-complete",
512 NULL
513};
514
515static char *test_case_6[] = {
516 "2",
517
518 "TCH/F keeping with EFR codec\n\n"
519 "The MS is using full rate V2 codec, but the better cell is congested\n"
520 "at TCH/F slots. As the congestion is removed, the handover takes\n"
521 "place.\n",
522
523 "create-bts", "2",
524 "set-min-free", "1", "TCH/F", "4",
525 "create-ms", "0", "TCH/F", "EFR",
526 "meas-rep", "0", "20","0", "1","0","30",
527 "expect-no-chan",
528 "set-min-free", "1", "TCH/F", "3",
529 "meas-rep", "0", "20","0", "1","0","30",
530 "expect-chan", "1", "1",
531 "ack-chan",
532 "expect-ho", "0", "1",
533 "ho-complete",
534 NULL
535};
536
537static char *test_case_7[] = {
538 "2",
539
540 "TCH/F to TCH/H changing with AMR codec\n\n"
541 "The MS is using AMR V3 codec, the better cell is congested at TCH/F\n"
542 "slots. The handover is performed to non-congested TCH/H slots.\n",
543
544 "create-bts", "2",
545 "set-min-free", "1", "TCH/F", "4",
546 "create-ms", "0", "TCH/F", "AMR",
547 "meas-rep", "0", "20","0", "1","0","30",
548 "expect-chan", "1", "5",
549 "ack-chan",
550 "expect-ho", "0", "1",
551 "ho-complete",
552 NULL
553};
554
555static char *test_case_8[] = {
556 "2",
557
558 "No handover to a cell with no slots available\n\n"
559 "If no slot is available, no handover is performed\n",
560
561 "create-bts", "2",
562 "create-ms", "0", "TCH/F", "AMR",
563 "create-ms", "1", "TCH/F", "AMR",
564 "create-ms", "1", "TCH/F", "AMR",
565 "create-ms", "1", "TCH/F", "AMR",
566 "create-ms", "1", "TCH/F", "AMR",
567 "create-ms", "1", "TCH/H", "AMR",
568 "create-ms", "1", "TCH/H", "AMR",
569 "create-ms", "1", "TCH/H", "AMR",
570 "create-ms", "1", "TCH/H", "AMR",
571 "meas-rep", "0", "0","0", "1","0","30",
572 "expect-no-chan",
573 NULL
574};
575
576static char *test_case_9[] = {
577 "2",
578
579 "No more parallel handovers, if max_unsync_ho is defined\n\n"
580 "There are tree mobiles that want to handover, but only two can do\n"
581 "it at a time, because the maximum number is limited to two.\n",
582
583 "create-bts", "2",
584 "set-max-ho", "1", "2",
585 "create-ms", "0", "TCH/F", "AMR",
586 "create-ms", "0", "TCH/F", "AMR",
587 "create-ms", "0", "TCH/F", "AMR",
588 "meas-rep", "0", "0","0", "1","0","30",
589 "expect-chan", "1", "1",
590 "meas-rep", "1", "0","0", "1","0","30",
591 "expect-chan", "1", "2",
592 "meas-rep", "2", "0","0", "1","0","30",
593 "expect-no-chan",
594 NULL
595};
596
597static char *test_case_10[] = {
598 "2",
599
600 "Hysteresis\n\n"
601 "If neighbor cell is better, handover is only performed if the\n"
602 "ammount of improvement is greater or equal hyteresis\n",
603
604 "create-bts", "2",
605 "create-ms", "0", "TCH/F", "AMR",
606 "meas-rep", "0", "27","0", "1","0","30",
607 "expect-no-chan",
608 "meas-rep", "0", "26","0", "1","0","30",
609 "expect-chan", "1", "1",
610 "ack-chan",
611 "expect-ho", "0", "1",
612 "ho-complete",
613 NULL
614};
615
616static char *test_case_11[] = {
617 "2",
618
619 "No Hysteresis and minimum RX level\n\n"
620 "If current cell's RX level is below mimium level, handover must be\n"
621 "performed, no matter of the hysteresis. First do not perform\n"
622 "handover to better neighbor cell, because the hysteresis is not\n"
623 "met. Second do not perform handover because better neighbor cell is\n"
624 "below minimum RX level. Third perform handover because current cell\n"
625 "is below minimum RX level, even if the better neighbor cell (minimum\n"
626 "RX level reached) does not meet the hysteresis.\n",
627
628 "create-bts", "2",
629 "create-ms", "0", "TCH/F", "AMR",
630 "meas-rep", "0", "10","0", "1","0","11",
631 "expect-no-chan",
632 "meas-rep", "0", "8","0", "1","0","9",
633 "expect-no-chan",
634 "meas-rep", "0", "9","0", "1","0","10",
635 "expect-chan", "1", "1",
636 "ack-chan",
637 "expect-ho", "0", "1",
638 "ho-complete",
639 NULL
640};
641
642static char *test_case_12[] = {
643 "2",
644
645 "No handover to congested cell\n\n"
646 "The better neighbor cell is congested, so no handover is performed.\n"
647 "After the congestion is over, handover will be performed.\n",
648
649 "create-bts", "2",
650 "create-ms", "0", "TCH/F", "AMR",
651 "set-min-free", "1", "TCH/F", "4",
652 "set-min-free", "1", "TCH/H", "4",
653 "meas-rep", "0", "20","0", "1","0","30",
654 "expect-no-chan",
655 "set-min-free", "1", "TCH/F", "3",
656 "set-min-free", "1", "TCH/H", "3",
657 "meas-rep", "0", "20","0", "1","0","30",
658 "expect-chan", "1", "1",
659 "ack-chan",
660 "expect-ho", "0", "1",
661 "ho-complete",
662 NULL
663};
664
665static char *test_case_13[] = {
666 "2",
667
668 "Handover to balance congestion\n\n"
669 "The current and the better cell are congested, so no handover is\n"
670 "performed. This is because handover would congest the neighbor cell\n"
671 "more. After congestion raises in the current cell, the handover is\n"
672 "performed to balance congestion\n",
673
674 "create-bts", "2",
675 "create-ms", "0", "TCH/F", "AMR",
676 "set-min-free", "0", "TCH/F", "4",
677 "set-min-free", "0", "TCH/H", "4",
678 "set-min-free", "1", "TCH/F", "4",
679 "set-min-free", "1", "TCH/H", "4",
680 "meas-rep", "0", "20","0", "1","0","30",
681 "expect-no-chan",
682 "create-ms", "0", "TCH/F", "AMR",
683 "meas-rep", "0", "20","0", "1","0","30",
684 "expect-chan", "1", "1",
685 "ack-chan",
686 "expect-ho", "0", "1",
687 "ho-complete",
688 NULL
689};
690
691static char *test_case_14[] = {
692 "2",
693
694 "Handover to congested cell, if RX level is below minimum\n\n"
695 "The better neighbor cell is congested, so no handover is performed.\n"
696 "If the RX level of the current cell drops below minimum acceptable\n"
697 "level, the handover is performed.\n",
698
699 "create-bts", "2",
700 "create-ms", "0", "TCH/F", "AMR",
701 "set-min-free", "1", "TCH/F", "4",
702 "set-min-free", "1", "TCH/H", "4",
703 "meas-rep", "0", "10","0", "1","0","30",
704 "expect-no-chan",
705 "meas-rep", "0", "9","0", "1","0","30",
706 "expect-chan", "1", "1",
707 "ack-chan",
708 "expect-ho", "0", "1",
709 "ho-complete",
710 NULL
711};
712
713static char *test_case_15[] = {
714 "2",
715
716 "Handover to cell with worse RXLEV, if RXQUAL is below minimum\n\n"
717 "The neighbor cell has worse RXLEV, so no handover is performed.\n"
718 "If the RXQUAL of the current cell drops below minimum acceptable\n"
719 "level, the handover is performed. It is also required that 10\n"
720 "reports are received, before RXQUAL is checked.\n",
721 /* (See also test 28, which tests for RXQUAL triggering HO to congested cell.) */
722 /* TODO: bad RXQUAL may want to prefer assignment within the same cell to avoid interference.
723 * See Performence Enhancements in a Frequency Hopping GSM Network (Nielsen Wigard 2002), Chapter
724 * 2.1.1, "Interference" in the list of triggers on p.157. */
725
726 "create-bts", "2",
727 "create-ms", "0", "TCH/F", "AMR",
728 "meas-rep", "0", "40","6", "1","0","30",
729 "expect-no-chan",
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-chan", "1", "1",
748 "ack-chan",
749 "expect-ho", "0", "1",
750 "ho-complete",
751 NULL
752};
753
754static char *test_case_16[] = {
755 "2",
756
757 "Handover due to maximum TA exceeded\n\n"
758 "The MS in the current (best) cell has reached maximum allowed timing\n"
759 "advance. No handover is performed until the timing advance exceeds\n"
760 "it. The originating cell is still the best, but no handover is\n"
761 "performed back to that cell, because the penalty timer (due to\n"
762 "maximum allowed timing advance) is running.\n",
763
764 "create-bts", "2",
765 "create-ms", "0", "TCH/F", "AMR",
766 "set-max-ta", "0", "5", /* of cell */
767 "set-ta", "0", "5", /* of ms */
768 "meas-rep", "0", "30","0", "1","0","20",
769 "expect-no-chan",
770 "set-ta", "0", "6", /* of ms */
771 "meas-rep", "0", "30","0", "1","0","20",
772 "expect-chan", "1", "1",
773 "ack-chan",
774 "expect-ho", "0", "1",
775 "ho-complete",
776 "meas-rep", "0", "20","0", "1","0","30",
777 "expect-no-chan",
778 NULL
779};
780
781static char *test_case_17[] = {
782 "2",
783
784 "Congestion check: No congestion\n\n"
785 "Three cells have different number of used slots, but there is no\n"
786 "congestion in any of these cells. No handover is performed.\n",
787
788 "create-bts", "3",
789 "set-min-free", "0", "TCH/F", "2",
790 "set-min-free", "0", "TCH/H", "2",
791 "set-min-free", "1", "TCH/F", "2",
792 "set-min-free", "1", "TCH/H", "2",
793 "set-min-free", "2", "TCH/F", "2",
794 "set-min-free", "2", "TCH/H", "2",
795 "create-ms", "0", "TCH/F", "AMR",
796 "create-ms", "0", "TCH/F", "AMR",
797 "create-ms", "0", "TCH/H", "AMR",
798 "create-ms", "0", "TCH/H", "AMR",
799 "create-ms", "1", "TCH/F", "AMR",
800 "create-ms", "1", "TCH/H", "AMR",
801 "meas-rep", "0", "30","0", "2","0","20","1","20",
802 "expect-no-chan",
803 "meas-rep", "1", "30","0", "2","0","20","1","20",
804 "expect-no-chan",
805 "meas-rep", "2", "30","0", "2","0","20","1","20",
806 "expect-no-chan",
807 "meas-rep", "3", "30","0", "2","0","20","1","20",
808 "expect-no-chan",
809 "meas-rep", "4", "30","0", "2","0","20","1","20",
810 "expect-no-chan",
811 "meas-rep", "5", "30","0", "2","0","20","1","20",
812 "expect-no-chan",
813 "congestion-check",
814 "expect-no-chan",
815 NULL
816};
817
818static char *test_case_18[] = {
819 "2",
820
821 "Congestion check: One out of three cells is congested\n\n"
822 "Three cells have different number of used slots, but there is\n"
823 "congestion at TCH/F in the first cell. Handover is performed with\n"
824 "the best candidate.\n",
825
826 "create-bts", "3",
827 "set-min-free", "0", "TCH/F", "2",
828 "set-min-free", "0", "TCH/H", "2",
829 "set-min-free", "1", "TCH/F", "2",
830 "set-min-free", "1", "TCH/H", "2",
831 "set-min-free", "2", "TCH/F", "2",
832 "set-min-free", "2", "TCH/H", "2",
833 "create-ms", "0", "TCH/F", "AMR",
834 "create-ms", "0", "TCH/F", "AMR",
835 "create-ms", "0", "TCH/F", "AMR",
836 "create-ms", "0", "TCH/H", "AMR",
837 "create-ms", "0", "TCH/H", "AMR",
838 "create-ms", "1", "TCH/F", "AMR",
839 "create-ms", "1", "TCH/H", "AMR",
840 "meas-rep", "0", "30","0", "2","0","20","1","20",
841 "expect-no-chan",
842 "meas-rep", "1", "30","0", "2","0","20","1","20",
843 "expect-no-chan",
844 "meas-rep", "2", "30","0", "2","0","21","1","20",
845 "expect-no-chan",
846 "meas-rep", "3", "30","0", "2","0","20","1","20",
847 "expect-no-chan",
848 "meas-rep", "4", "30","0", "2","0","20","1","20",
849 "expect-no-chan",
850 "meas-rep", "5", "30","0", "2","0","20","1","20",
851 "expect-no-chan",
852 "meas-rep", "6", "30","0", "2","0","20","1","20",
853 "expect-no-chan",
854 "congestion-check",
855 "expect-chan", "1", "2",
856 "ack-chan",
857 "expect-ho", "0", "3", /* best candidate is MS 2 at BTS 1, TS 3 */
858 "ho-complete",
859 NULL
860};
861
862static char *test_case_19[] = {
863 "2",
864
865 "Congestion check: Balancing over congested cells\n\n"
866 "Two cells are congested, but the second cell is more congested.\n"
867 "Handover is performed to solve the congestion.\n",
868
869 "create-bts", "2",
870 "set-min-free", "0", "TCH/F", "4",
871 "set-min-free", "1", "TCH/F", "4",
872 "create-ms", "0", "TCH/F", "FR",
873 "create-ms", "0", "TCH/F", "FR",
874 "create-ms", "0", "TCH/F", "FR",
875 "create-ms", "1", "TCH/F", "FR",
876 "meas-rep", "0", "30","0", "1","0","20",
877 "expect-no-chan",
878 "meas-rep", "1", "30","0", "1","0","21",
879 "expect-no-chan",
880 "meas-rep", "2", "30","0", "1","0","20",
881 "expect-no-chan",
882 "meas-rep", "3", "30","0", "1","0","20",
883 "expect-no-chan",
884 "congestion-check",
885 "expect-chan", "1", "2",
886 "ack-chan",
887 "expect-ho", "0", "2", /* best candidate is MS 1 at BTS 0, TS 2 */
888 "ho-complete",
889 NULL
890};
891
892static char *test_case_20[] = {
893 "2",
894
895 "Congestion check: Solving congestion by handover TCH/F -> TCH/H\n\n"
896 "Two BTS, one MS in the first congested BTS must handover to\n"
897 "non-congested TCH/H of second BTS, in order to solve congestion\n",
898 "create-bts", "2",
899 "set-min-free", "0", "TCH/F", "4",
900 "set-min-free", "0", "TCH/H", "4",
901 "set-min-free", "1", "TCH/F", "4",
902 "create-ms", "0", "TCH/F", "AMR",
903 "meas-rep", "0", "30","0", "1","0","30",
904 "expect-no-chan",
905 "congestion-check",
906 "expect-chan", "1", "5",
907 "ack-chan",
908 "expect-ho", "0", "1",
909 "ho-complete",
910 NULL
911};
912
913static char *test_case_21[] = {
914 "2",
915
916 "Congestion check: Balancing congestion by handover TCH/F -> TCH/H\n\n"
917 "Two BTS, one MS in the first congested BTS must handover to\n"
918 "less-congested TCH/H of second BTS, in order to balance congestion\n",
919 "create-bts", "2",
920 "set-min-free", "0", "TCH/F", "4",
921 "set-min-free", "0", "TCH/H", "4",
922 "set-min-free", "1", "TCH/F", "4",
923 "set-min-free", "1", "TCH/H", "4",
924 "create-ms", "0", "TCH/F", "AMR",
925 "create-ms", "0", "TCH/F", "AMR",
926 "create-ms", "0", "TCH/H", "AMR",
927 "meas-rep", "0", "30","0", "1","0","30",
928 "expect-no-chan",
929 "congestion-check",
930 "expect-chan", "1", "1",
931 "ack-chan",
932 "expect-ho", "0", "1",
933 "ho-complete",
934 NULL
935};
936
937static char *test_case_22[] = {
938 "2",
939
940 "Congestion check: Upgrading worst candidate from TCH/H -> TCH/F\n\n"
941 "There is only one BTS. The TCH/H slots are congested. Since\n"
942 "assignment is performed to less-congested TCH/F, the candidate with\n"
943 "the worst RX level is chosen.\n",
944
945 "create-bts", "1",
946 "set-min-free", "0", "TCH/F", "4",
947 "set-min-free", "0", "TCH/H", "4",
948 "create-ms", "0", "TCH/H", "AMR",
949 "create-ms", "0", "TCH/H", "AMR",
950 "create-ms", "0", "TCH/H", "AMR",
951 "meas-rep", "0", "30","0", "0",
952 "meas-rep", "1", "34","0", "0",
953 "meas-rep", "2", "20","0", "0",
954 "expect-no-chan",
955 "congestion-check",
956 "expect-chan", "0", "1",
957 "ack-chan",
958 "expect-ho", "0", "6",
959 "ho-complete",
960 NULL
961};
962
963static char *test_case_23[] = {
964 "2",
965
966 "Story: 'A neighbor is your friend'\n",
967
968 "create-bts", "3",
969
970 "print",
971 "Andreas is driving along the coast, on a sunny june afternoon.\n"
972 "Suddenly he is getting a call from his friend and neighbor Axel.\n"
973 "\n"
974 "What happens: Two MS are created, #0 for Axel, #1 for Andreas.",
975 /* Axel */
976 "create-ms", "2", "TCH/F", "AMR",
977 /* andreas */
978 "create-ms", "0", "TCH/F", "AMR",
979 "meas-rep", "1", "40","0", "1","0","30",
980 "expect-no-chan",
981
982 "print",
983 "Axel asks Andreas if he would like to join them for a barbecue.\n"
984 "Axel's house is right in the neighborhood and the weather is fine.\n"
985 "Andreas agrees, so he drives to a close store to buy some barbecue\n"
986 "skewers.\n"
987 "\n"
988 "What happens: While driving, a different cell (mounted atop the\n"
989 "store) becomes better.",
990 /* drive to bts 1 */
991 "meas-rep", "1", "20","0", "1","0","35",
992 "expect-chan", "1", "1",
993 "ack-chan",
994 "expect-ho", "0", "1",
995 "ho-complete",
996
997 "print",
998 "While Andreas is walking into the store, Axel asks, if he could also\n"
999 "bring some beer. Andreas has problems understanding him: \"I have a\n"
1000 "bad reception here. The cell tower is right atop the store, but poor\n"
1001 "coverage inside. Can you repeat please?\"\n"
1002 "\n"
1003 "What happens: Inside the store the close cell is so bad, that\n"
1004 "handover back to the previous cell is required.",
1005 /* bts 1 becomes bad, so bts 0 helps out */
1006 "meas-rep", "1", "5","0", "1","0","20",
1007 "expect-chan", "0", "1",
1008 "ack-chan",
1009 "expect-ho", "1", "1",
1010 "ho-complete",
1011
1012 "print",
1013 "After Andreas bought skewers and beer, he leaves the store.\n"
1014 "\n"
1015 "What happens: Outside the store the close cell is better again, so\n"
1016 "handover back to the that cell is performed.",
1017 /* bts 1 becomes better again */
1018 "meas-rep", "1", "20","0", "1","0","35",
1019 "expect-chan", "1", "1",
1020 "ack-chan",
1021 "expect-ho", "0", "1",
1022 "ho-complete",
1023
1024 "print",
1025 /* bts 2 becomes better */
1026 "Andreas drives down to the lake where Axel's house is.\n"
1027 "\n"
1028 "What happens: There is a small cell at Axel's house, which becomes\n"
1029 "better, because the current cell has no good comverage at the lake.",
1030 "meas-rep", "1", "14","0", "2","0","2","1","63",
1031 "expect-chan", "2", "2",
1032 "ack-chan",
1033 "expect-ho", "1", "1",
1034 "ho-complete",
1035
1036 "print",
1037 "Andreas wonders why he still has good radio coverage: \"Last time it\n"
1038 "was so bad\". Axel says: \"I installed a pico cell in my house,\n"
1039 "now we can use our mobile phones down here at the lake.\"",
1040
1041 NULL
1042};
1043
1044static char *test_case_24[] = {
1045 "2",
1046 "No (or not enough) measurements for handover\n\n"
1047 "Do not solve congestion in cell, because there is no measurement.\n"
1048 "As soon as enough measurments available (1 in our case), perform\n"
1049 "handover. Afterwards the old cell becomes congested and the new\n"
1050 "cell is not. Do not perform handover until new measurements are\n"
1051 "received.\n",
1052
1053 /* two cells, first in congested, but no handover */
1054 "create-bts", "2",
1055 "set-min-free", "0", "TCH/F", "4",
1056 "set-min-free", "0", "TCH/H", "4",
1057 "create-ms", "0", "TCH/F", "AMR",
1058 "congestion-check",
1059 "expect-no-chan",
1060
1061 /* send measurement and trigger congestion check */
1062 "meas-rep", "0", "20","0", "1","0","20",
1063 "expect-no-chan",
1064 "congestion-check",
1065 "expect-chan", "1", "1",
1066 "ack-chan",
1067 "expect-ho", "0", "1",
1068 "ho-complete",
1069
1070 /* congest the first cell and remove congestion from second cell */
1071 "set-min-free", "0", "TCH/F", "0",
1072 "set-min-free", "0", "TCH/H", "0",
1073 "set-min-free", "1", "TCH/F", "4",
1074 "set-min-free", "1", "TCH/H", "4",
1075
1076 /* no handover until measurements applied */
1077 "congestion-check",
1078 "expect-no-chan",
1079 "meas-rep", "0", "20","0", "1","0","20",
1080 "expect-no-chan",
1081 "congestion-check",
1082 "expect-chan", "0", "1",
1083 "ack-chan",
1084 "expect-ho", "1", "1",
1085 "ho-complete",
1086 NULL
1087};
1088
1089static char *test_case_25[] = {
1090 "1",
1091
1092 "Stay in better cell\n\n"
1093 "There are many neighbor cells, but only the current cell is the best\n"
1094 "cell, so no handover is performed\n",
1095
1096 "create-bts", "7",
1097 "create-ms", "0", "TCH/F", "AMR",
1098 "meas-rep", "0", "30","0",
1099 "6","0","20","1","21","2","18","3","20","4","23","5","19",
1100 "expect-no-chan",
1101 NULL
1102};
1103
1104static char *test_case_26[] = {
1105 "1",
1106
1107 "Handover to best better cell\n\n"
1108 "The best neighbor cell is selected\n",
1109
1110 "create-bts", "7",
1111 "create-ms", "0", "TCH/F", "AMR",
1112 "meas-rep", "0", "10","0",
1113 "6","0","20","1","21","2","18","3","20","4","23","5","19",
1114 "expect-chan", "5", "1",
1115 "ack-chan",
1116 "expect-ho", "0", "1",
1117 "ho-complete",
1118 NULL
1119};
1120
1121static char *test_case_27[] = {
1122 "2",
1123
1124 "Congestion check: Upgrading worst candidate from TCH/H -> TCH/F\n\n"
1125 "There is only one BTS. The TCH/H slots are congested. Since\n"
1126 "assignment is performed to less-congested TCH/F, the candidate with\n"
1127 "the worst RX level is chosen. (So far like test 22.)\n"
1128 "After that, trigger more congestion checks to ensure stability.\n",
1129
1130 "create-bts", "1",
1131 "set-min-free", "0", "TCH/F", "2",
1132 "set-min-free", "0", "TCH/H", "4",
1133 "create-ms", "0", "TCH/H", "AMR",
1134 "create-ms", "0", "TCH/H", "AMR",
1135 "create-ms", "0", "TCH/H", "AMR",
1136 "meas-rep", "0", "30","0", "0",
1137 "meas-rep", "1", "34","0", "0",
1138 "meas-rep", "2", "20","0", "0",
1139 "expect-no-chan",
1140 "congestion-check",
1141 "expect-chan", "0", "1",
1142 "ack-chan",
1143 "expect-ho", "0", "6",
1144 "ho-complete",
1145 "congestion-check",
1146 "expect-chan", "0", "2",
1147 "ack-chan",
1148 "expect-ho", "0", "5",
1149 "ho-complete",
1150 "congestion-check",
1151 "expect-no-chan",
1152 "congestion-check",
1153 "expect-no-chan",
1154 NULL
1155};
1156
1157static char *test_case_28[] = {
1158 "2",
1159
1160 "Handover to congested cell, if RX quality is below minimum\n\n"
1161 "The better neighbor cell is congested, so no handover is performed.\n"
1162 "If the RX quality of the current cell drops below minimum acceptable\n"
1163 "level, the handover is performed. It is also required that 10\n"
1164 "resports are received, before RX quality is checked.\n",
1165
1166 "create-bts", "2",
1167 "create-ms", "0", "TCH/F", "AMR",
1168 "set-min-free", "1", "TCH/F", "4",
1169 "set-min-free", "1", "TCH/H", "4",
1170 "meas-rep", "0", "30","6", "1","0","40",
1171 "expect-no-chan",
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-chan", "1", "1",
1190 "ack-chan",
1191 "expect-ho", "0", "1",
1192 "ho-complete",
1193 NULL
1194};
1195
1196static char **test_cases[] = {
1197 test_case_0,
1198 test_case_1,
1199 test_case_2,
1200 test_case_3,
1201 test_case_4,
1202 test_case_5,
1203 test_case_6,
1204 test_case_7,
1205 test_case_8,
1206 test_case_9,
1207 test_case_10,
1208 test_case_11,
1209 test_case_12,
1210 test_case_13,
1211 test_case_14,
1212 test_case_15,
1213 test_case_16,
1214 test_case_17,
1215 test_case_18,
1216 test_case_19,
1217 test_case_20,
1218 test_case_21,
1219 test_case_22,
1220 test_case_23,
1221 test_case_24,
1222 test_case_25,
1223 test_case_26,
1224 test_case_27,
1225 test_case_28,
Neels Hofmeyr909e9722017-12-07 03:54:01 +01001226};
1227
1228static const struct log_info_cat log_categories[] = {
1229 [DHO] = {
1230 .name = "DHO",
1231 .description = "Hand-Over Process",
1232 .color = "\033[1;38m",
1233 .enabled = 1, .loglevel = LOGL_DEBUG,
1234 },
1235 [DHODEC] = {
1236 .name = "DHODEC",
1237 .description = "Hand-Over Decision",
1238 .color = "\033[1;38m",
1239 .enabled = 1, .loglevel = LOGL_DEBUG,
1240 },
1241 [DMEAS] = {
1242 .name = "DMEAS",
1243 .description = "Radio Measurement Processing",
1244 .enabled = 1, .loglevel = LOGL_DEBUG,
1245 },
1246 [DREF] = {
1247 .name = "DREF",
1248 .description = "Reference Counting",
1249 .enabled = 1, .loglevel = LOGL_DEBUG,
1250 },
1251 [DRSL] = {
1252 .name = "DRSL",
1253 .description = "A-bis Radio Siganlling Link (RSL)",
1254 .color = "\033[1;35m",
1255 .enabled = 1, .loglevel = LOGL_DEBUG,
1256 },
1257};
1258
1259const struct log_info log_info = {
1260 .cat = log_categories,
1261 .num_cat = ARRAY_SIZE(log_categories),
1262};
1263
1264int main(int argc, char **argv)
1265{
1266 char **test_case;
1267 struct gsm_bts *bts[256];
1268 int bts_num = 0;
1269 struct gsm_lchan *lchan[256];
1270 int lchan_num = 0;
Neels Hofmeyr909e9722017-12-07 03:54:01 +01001271 int i;
1272 int algorithm;
1273 struct bsc_api bsc_api = {};
Neels Hofmeyr00727552018-02-21 14:33:15 +01001274 int test_case_i;
1275 int last_test_i;
Neels Hofmeyr909e9722017-12-07 03:54:01 +01001276
Neels Hofmeyr00727552018-02-21 14:33:15 +01001277 test_case_i = argc > 1? atoi(argv[1]) : -1;
1278 last_test_i = ARRAY_SIZE(test_cases) - 1;
Neels Hofmeyr909e9722017-12-07 03:54:01 +01001279
Neels Hofmeyr00727552018-02-21 14:33:15 +01001280 if (test_case_i < 0 || test_case_i > last_test_i) {
1281 for (i = 0; i <= last_test_i; i++) {
Neels Hofmeyr909e9722017-12-07 03:54:01 +01001282 printf("Test #%d (algorithm %s):\n%s\n", i,
1283 test_cases[i][0], test_cases[i][1]);
1284 }
Neels Hofmeyr00727552018-02-21 14:33:15 +01001285 printf("\nPlease specify test case number 0..%d\n", last_test_i);
Neels Hofmeyr909e9722017-12-07 03:54:01 +01001286 return EXIT_FAILURE;
1287 }
1288
1289 osmo_init_logging(&log_info);
1290
1291 log_set_print_category(osmo_stderr_target, 1);
1292 log_set_print_category_hex(osmo_stderr_target, 0);
1293 log_set_print_filename2(osmo_stderr_target, LOG_FILENAME_BASENAME);
1294
1295 /* Create a dummy network */
1296 bsc_gsmnet = bsc_network_init(NULL, 1, 1);
1297 if (!bsc_gsmnet)
1298 exit(1);
1299
1300 bsc_api_init(bsc_gsmnet, &bsc_api);
1301
1302 ho_set_algorithm(bsc_gsmnet->ho, 2);
1303 ho_set_ho_active(bsc_gsmnet->ho, true);
1304 ho_set_hodec2_as_active(bsc_gsmnet->ho, true);
1305 ho_set_hodec2_min_rxlev(bsc_gsmnet->ho, -100);
1306 ho_set_hodec2_rxlev_avg_win(bsc_gsmnet->ho, 1);
1307 ho_set_hodec2_rxlev_neigh_avg_win(bsc_gsmnet->ho, 1);
1308 ho_set_hodec2_rxqual_avg_win(bsc_gsmnet->ho, 10);
1309 ho_set_hodec2_pwr_hysteresis(bsc_gsmnet->ho, 3);
1310 ho_set_hodec2_pwr_interval(bsc_gsmnet->ho, 1);
1311 ho_set_hodec2_afs_bias_rxlev(bsc_gsmnet->ho, 0);
1312 ho_set_hodec2_min_rxqual(bsc_gsmnet->ho, 5);
1313 ho_set_hodec2_afs_bias_rxqual(bsc_gsmnet->ho, 0);
1314 ho_set_hodec2_max_distance(bsc_gsmnet->ho, 9999);
1315 ho_set_hodec2_ho_max(bsc_gsmnet->ho, 9999);
1316 ho_set_hodec2_penalty_max_dist(bsc_gsmnet->ho, 300);
1317 ho_set_hodec2_penalty_failed_ho(bsc_gsmnet->ho, 60);
1318 ho_set_hodec2_penalty_failed_as(bsc_gsmnet->ho, 60);
1319
1320 bts_model_sysmobts_init();
1321
Neels Hofmeyr00727552018-02-21 14:33:15 +01001322 test_case = test_cases[test_case_i];
Neels Hofmeyr909e9722017-12-07 03:54:01 +01001323
1324 fprintf(stderr, "--------------------\n");
1325 fprintf(stderr, "Performing the following test %d (algorithm %s):\n%s",
Neels Hofmeyr00727552018-02-21 14:33:15 +01001326 test_case_i, test_case[0], test_case[1]);
Neels Hofmeyr909e9722017-12-07 03:54:01 +01001327 algorithm = atoi(test_case[0]);
1328 test_case += 2;
1329 fprintf(stderr, "--------------------\n");
1330
1331 /* Disable the congestion check timer, we will trigger manually. */
1332 bsc_gsmnet->hodec2.congestion_check_interval_s = 0;
1333
1334 handover_decision_1_init();
1335 hodec2_init(bsc_gsmnet);
1336
1337 while (*test_case) {
1338 if (!strcmp(*test_case, "create-bts")) {
1339 static int arfcn = 870;
1340 int n = atoi(test_case[1]);
1341 fprintf(stderr, "- Creating %d BTS (one TRX each, "
1342 "TS(1-4) are TCH/F, TS(5-6) are TCH/H)\n", n);
1343 for (i = 0; i < n; i++)
1344 bts[bts_num + i] = create_bts(arfcn++);
Neels Hofmeyr00727552018-02-21 14:33:15 +01001345 for (i = 0; i < n; i++) {
1346 if (gsm_generate_si(bts[bts_num + i], SYSINFO_TYPE_2))
1347 fprintf(stderr, "Error generating SI2\n");
1348 }
Neels Hofmeyr909e9722017-12-07 03:54:01 +01001349 bts_num += n;
1350 test_case += 2;
1351 } else
1352 if (!strcmp(*test_case, "as-enable")) {
1353 fprintf(stderr, "- Set assignment enable state at "
1354 "BTS %s to %s\n", test_case[1], test_case[2]);
1355 ho_set_hodec2_as_active(bts[atoi(test_case[1])]->ho, atoi(test_case[2]));
1356 test_case += 3;
1357 } else
1358 if (!strcmp(*test_case, "ho-enable")) {
1359 fprintf(stderr, "- Set handover enable state at "
1360 "BTS %s to %s\n", test_case[1], test_case[2]);
1361 ho_set_ho_active(bts[atoi(test_case[1])]->ho, atoi(test_case[2]));
1362 test_case += 3;
1363 } else
1364 if (!strcmp(*test_case, "afs-rxlev-improve")) {
1365 fprintf(stderr, "- Set afs RX level improvement at "
1366 "BTS %s to %s\n", test_case[1], test_case[2]);
1367 ho_set_hodec2_afs_bias_rxlev(bts[atoi(test_case[1])]->ho, atoi(test_case[2]));
1368 test_case += 3;
1369 } else
1370 if (!strcmp(*test_case, "afs-rxqual-improve")) {
1371 fprintf(stderr, "- Set afs RX quality improvement at "
1372 "BTS %s to %s\n", test_case[1], test_case[2]);
1373 ho_set_hodec2_afs_bias_rxqual(bts[atoi(test_case[1])]->ho, atoi(test_case[2]));
1374 test_case += 3;
1375 } else
1376 if (!strcmp(*test_case, "set-min-free")) {
1377 fprintf(stderr, "- Setting minimum required free %s "
1378 "slots at BTS %s to %s\n", test_case[2],
1379 test_case[1], test_case[3]);
1380 if (!strcmp(test_case[2], "TCH/F"))
1381 ho_set_hodec2_tchf_min_slots(bts[atoi(test_case[1])]->ho, atoi(test_case[3]));
1382 else
1383 ho_set_hodec2_tchh_min_slots(bts[atoi(test_case[1])]->ho, atoi(test_case[3]));
1384 test_case += 4;
1385 } else
1386 if (!strcmp(*test_case, "set-max-ho")) {
1387 fprintf(stderr, "- Setting maximum parallel handovers "
1388 "at BTS %s to %s\n", test_case[1],
1389 test_case[2]);
1390 ho_set_hodec2_ho_max( bts[atoi(test_case[1])]->ho, atoi(test_case[2]));
1391 test_case += 3;
1392 } else
1393 if (!strcmp(*test_case, "set-max-ta")) {
1394 fprintf(stderr, "- Setting maximum timing advance "
1395 "at BTS %s to %s\n", test_case[1],
1396 test_case[2]);
1397 ho_set_hodec2_max_distance(bts[atoi(test_case[1])]->ho, atoi(test_case[2]));
1398 test_case += 3;
1399 } else
1400 if (!strcmp(*test_case, "create-ms")) {
1401 fprintf(stderr, "- Creating mobile #%d at BTS %s on "
1402 "%s with %s codec\n", lchan_num, test_case[1],
1403 test_case[2], test_case[3]);
1404 lchan[lchan_num] = create_lchan(bts[atoi(test_case[1])],
1405 !strcmp(test_case[2], "TCH/F"), test_case[3]);
1406 if (!lchan[lchan_num]) {
1407 printf("Failed to create lchan!\n");
1408 return EXIT_FAILURE;
1409 }
1410 fprintf(stderr, " * New MS is at BTS %d TS %d\n",
1411 lchan[lchan_num]->ts->trx->bts->nr,
1412 lchan[lchan_num]->ts->nr);
1413 lchan_num++;
1414 test_case += 4;
1415 } else
1416 if (!strcmp(*test_case, "set-ta")) {
1417 fprintf(stderr, "- Setting maximum timing advance "
1418 "at MS %s to %s\n", test_case[1],
1419 test_case[2]);
1420 meas_ta_ms = atoi(test_case[2]);
1421 test_case += 3;
1422 } else
1423 if (!strcmp(*test_case, "meas-rep")) {
1424 /* meas-rep <lchan-nr> <rxlev> <rxqual> <nr-of-neighbors> [<cell-idx> <rxlev> [...]] */
1425 int n = atoi(test_case[4]);
1426 struct gsm_lchan *lc = lchan[atoi(test_case[1])];
1427 fprintf(stderr, "- Sending measurement report from "
1428 "mobile #%s (rxlev=%s, rxqual=%s)\n",
1429 test_case[1], test_case[2], test_case[3]);
1430 meas_dl_rxlev = atoi(test_case[2]);
1431 meas_dl_rxqual = atoi(test_case[3]);
1432 meas_num_nc = n;
1433 test_case += 5;
1434 for (i = 0; i < n; i++) {
1435 int nr = atoi(test_case[0]);
1436 /* since our bts is not in the list of neighbor
1437 * cells, we need to shift */
1438 if (nr >= lc->ts->trx->bts->nr)
1439 nr++;
1440 fprintf(stderr, " * Neighbor cell #%s, actual "
1441 "BTS %d (rxlev=%s)\n", test_case[0], nr,
1442 test_case[1]);
1443 meas_bcch_f_nc[i] = atoi(test_case[0]);
1444 /* bts number, not counting our own */
1445 meas_rxlev_nc[i] = atoi(test_case[1]);
1446 meas_bsic_nc[i] = 0x3f;
1447 test_case += 2;
1448 }
1449 got_chan_req = 0;
1450 gen_meas_rep(lc);
1451 } else
1452 if (!strcmp(*test_case, "congestion-check")) {
1453 fprintf(stderr, "- Triggering congestion check\n");
1454 got_chan_req = 0;
1455 if (algorithm == 2)
1456 hodec2_congestion_check(bsc_gsmnet);
1457 test_case += 1;
1458 } else
1459 if (!strcmp(*test_case, "expect-chan")) {
1460 fprintf(stderr, "- Expecting channel request at BTS %s "
1461 "TS %s\n", test_case[1], test_case[2]);
1462 if (!got_chan_req) {
1463 printf("Test failed, because no channel was "
1464 "requested\n");
1465 return EXIT_FAILURE;
1466 }
1467 fprintf(stderr, " * Got channel request at BTS %d "
1468 "TS %d\n", chan_req_lchan->ts->trx->bts->nr,
1469 chan_req_lchan->ts->nr);
1470 if (chan_req_lchan->ts->trx->bts->nr
1471 != atoi(test_case[1])) {
1472 printf("Test failed, because channel was not "
1473 "requested on expected BTS\n");
1474 return EXIT_FAILURE;
1475 }
1476 if (chan_req_lchan->ts->nr != atoi(test_case[2])) {
1477 printf("Test failed, because channel was not "
1478 "requested on expected TS\n");
1479 return EXIT_FAILURE;
1480 }
1481 test_case += 3;
1482 } else
1483 if (!strcmp(*test_case, "expect-no-chan")) {
1484 fprintf(stderr, "- Expecting no channel request\n");
1485 if (got_chan_req) {
1486 fprintf(stderr, " * Got channel request at "
1487 "BTS %d TS %d\n",
1488 chan_req_lchan->ts->trx->bts->nr,
1489 chan_req_lchan->ts->nr);
1490 printf("Test failed, because channel was "
1491 "requested\n");
1492 return EXIT_FAILURE;
1493 }
1494 fprintf(stderr, " * Got no channel request\n");
1495 test_case += 1;
1496 } else
1497 if (!strcmp(*test_case, "expect-ho")) {
1498 fprintf(stderr, "- Expecting handover/assignment "
1499 "request at BTS %s TS %s\n", test_case[1],
1500 test_case[2]);
1501 if (!got_ho_req) {
1502 printf("Test failed, because no handover was "
1503 "requested\n");
1504 return EXIT_FAILURE;
1505 }
1506 fprintf(stderr, " * Got handover/assignment request at "
1507 "BTS %d TS %d\n",
1508 ho_req_lchan->ts->trx->bts->nr,
1509 ho_req_lchan->ts->nr);
1510 if (ho_req_lchan->ts->trx->bts->nr
1511 != atoi(test_case[1])) {
1512 printf("Test failed, because "
1513 "handover/assignment was not commanded "
1514 "at the expected BTS\n");
1515 return EXIT_FAILURE;
1516 }
1517 if (ho_req_lchan->ts->nr != atoi(test_case[2])) {
1518 printf("Test failed, because "
1519 "handover/assignment was not commanded "
1520 "at the expected TS\n");
1521 return EXIT_FAILURE;
1522 }
1523 test_case += 3;
1524 } else
1525 if (!strcmp(*test_case, "ack-chan")) {
1526 fprintf(stderr, "- Acknowledging channel request\n");
1527 if (!got_chan_req) {
1528 printf("Cannot ack channel, because no "
1529 "request\n");
1530 return EXIT_FAILURE;
1531 }
1532 test_case += 1;
1533 got_ho_req = 0;
1534 send_chan_act_ack(chan_req_lchan, 1);
1535 } else
1536 if (!strcmp(*test_case, "ho-complete")) {
1537 fprintf(stderr, "- Acknowledging handover/assignment "
1538 "request\n");
1539 if (!got_chan_req) {
1540 printf("Cannot ack handover/assignment, "
1541 "because no chan request\n");
1542 return EXIT_FAILURE;
1543 }
1544 if (!got_ho_req) {
1545 printf("Cannot ack handover/assignment, "
1546 "because no ho request\n");
1547 return EXIT_FAILURE;
1548 }
1549 test_case += 1;
1550 got_chan_req = 0;
1551 got_ho_req = 0;
1552 /* switch lchan */
1553 for (i = 0; i < lchan_num; i++) {
1554 if (lchan[i] == ho_req_lchan) {
1555 fprintf(stderr, " * MS %d changes from "
1556 "BTS=%d TS=%d to BTS=%d "
1557 "TS=%d\n", i,
1558 lchan[i]->ts->trx->bts->nr,
1559 lchan[i]->ts->nr,
1560 chan_req_lchan->ts->trx->bts->nr,
1561 chan_req_lchan->ts->nr);
1562 lchan[i] = chan_req_lchan;
1563 }
1564 }
1565 send_ho_complete(chan_req_lchan, true);
1566 } else
1567 if (!strcmp(*test_case, "ho-failed")) {
1568 fprintf(stderr, "- Making handover fail\n");
1569 if (!got_chan_req) {
1570 printf("Cannot fail handover, because no chan "
1571 "request\n");
1572 return EXIT_FAILURE;
1573 }
1574 test_case += 1;
1575 got_chan_req = 0;
1576 got_ho_req = 0;
1577 send_ho_complete(ho_req_lchan, false);
1578 } else
1579 if (!strcmp(*test_case, "print")) {
1580 fprintf(stderr, "\n%s\n\n", test_case[1]);
1581 test_case += 2;
1582 } else {
1583 printf("Unknown test command '%s', please fix!\n",
1584 *test_case);
1585 return EXIT_FAILURE;
1586 }
1587 }
1588
1589 for (i = 0; i < lchan_num; i++) {
1590 struct gsm_subscriber_connection *conn = lchan[i]->conn;
1591 lchan[i]->conn = NULL;
1592 conn->lchan = NULL;
1593 bsc_subscr_con_free(conn);
1594 lchan_free(lchan[i]);
1595 }
1596
1597 fprintf(stderr, "--------------------\n");
1598
1599 printf("Test OK\n");
1600
1601 fprintf(stderr, "--------------------\n");
1602
1603 return EXIT_SUCCESS;
1604}
1605
1606void rtp_socket_free() {}
1607void rtp_send_frame() {}
1608void rtp_socket_upstream() {}
1609void rtp_socket_create() {}
1610void rtp_socket_connect() {}
1611void rtp_socket_proxy() {}
1612void trau_mux_unmap() {}
1613void trau_mux_map_lchan() {}
1614void trau_recv_lchan() {}
1615void trau_send_frame() {}