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