blob: 555aac8048ced5ea3ce4f358f39f5d058ca6c77e [file] [log] [blame]
Harald Welte28d943e2017-11-25 15:00:50 +01001module BSC_Tests {
2
Harald Welte21b46bd2017-12-17 19:46:32 +01003/* Integration Tests for OsmoBSC
Harald Weltea0630032018-03-20 21:09:55 +01004 * (C) 2017-2018 by Harald Welte <laforge@gnumonks.org>
Harald Welte21b46bd2017-12-17 19:46:32 +01005 * All rights reserved.
6 *
7 * Released under the terms of GNU General Public License, Version 2 or
8 * (at your option) any later version.
9 *
10 * This test suite tests OsmoBSC while emulating both multiple BTS + MS as
11 * well as the MSC. See README for more details.
12 *
13 * There are test cases that run in so-called 'handler mode' and test cases
14 * that run directly on top of the BSSAP and RSL CodecPorts. The "handler mode"
15 * tests abstract the multiplexing/demultiplexing of multiple SCCP connections
16 * and/or RSL channels and are hence suitable for higher-level test cases, while
17 * the "raw" tests directly on top of the CodecPorts are more suitable for lower-
18 * level testing.
19 */
20
Harald Welte4003d112017-12-09 22:35:39 +010021import from General_Types all;
Harald Welte28d943e2017-11-25 15:00:50 +010022import from Osmocom_Types all;
Harald Welteae026692017-12-09 01:03:01 +010023import from GSM_Types all;
Harald Welte28d943e2017-11-25 15:00:50 +010024import from IPL4asp_Types all;
25
Harald Welte6f521d82017-12-11 19:52:02 +010026import from BSSAP_Types all;
Harald Welteae026692017-12-09 01:03:01 +010027import from BSSAP_Adapter all;
28import from BSSAP_CodecPort all;
29import from BSSMAP_Templates all;
Harald Welte28d943e2017-11-25 15:00:50 +010030import from IPA_Emulation all;
Stefan Sperling830dc9d2018-02-12 21:08:28 +010031import from IPA_CodecPort all;
Harald Welteae026692017-12-09 01:03:01 +010032import from IPA_Types all;
Stefan Sperling0796a822018-10-05 13:01:39 +020033import from IPA_Testing all;
Harald Welteae026692017-12-09 01:03:01 +010034import from RSL_Types all;
Harald Welte624f9632017-12-16 19:26:04 +010035import from RSL_Emulation all;
Daniel Willmann191e0d92018-01-17 12:44:35 +010036import from MGCP_Emulation all;
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +010037import from MGCP_Templates all;
38import from MGCP_Types all;
Harald Welte28d943e2017-11-25 15:00:50 +010039
Harald Welte96c94412017-12-09 03:12:45 +010040import from Osmocom_CTRL_Functions all;
Harald Weltea5d2ab22017-12-09 14:21:42 +010041import from Osmocom_CTRL_Types all;
Harald Welteffe55fc2018-01-17 22:39:54 +010042import from Osmocom_CTRL_Adapter all;
Harald Welte96c94412017-12-09 03:12:45 +010043
Harald Weltebc03c762018-02-12 18:09:38 +010044import from Osmocom_VTY_Functions all;
45import from TELNETasp_PortType all;
46
Harald Welte6f521d82017-12-11 19:52:02 +010047import from MobileL3_CommonIE_Types all;
Harald Weltee3bd6582018-01-31 22:51:25 +010048import from MobileL3_Types all;
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +010049import from MobileL3_RRM_Types all;
Harald Welte6f521d82017-12-11 19:52:02 +010050import from L3_Templates all;
51import from GSM_RR_Types all;
52
Stefan Sperlingc307e682018-06-14 15:15:46 +020053import from SCCP_Templates all;
Neels Hofmeyr4ff93282018-03-12 04:25:35 +010054import from BSSMAP_Templates all;
55
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +010056import from SCCPasp_Types all;
57
Harald Welte5d1a2202017-12-13 19:51:29 +010058const integer NUM_BTS := 3;
Harald Welteae026692017-12-09 01:03:01 +010059const float T3101_MAX := 12.0;
Harald Welte28d943e2017-11-25 15:00:50 +010060
Harald Welte799c97b2017-12-14 17:50:30 +010061/* make sure to sync this with the osmo-bts.cfg you're using */
Philipp Maiercb6cc482018-03-26 13:08:00 +020062const integer NUM_TCHH_PER_BTS := 2;
63const integer NUM_TCHF_PER_BTS := 4;
Harald Weltedd8cbf32018-01-28 12:07:52 +010064const integer NUM_SDCCH_PER_BTS := 4;
Harald Welte799c97b2017-12-14 17:50:30 +010065
Harald Welte4003d112017-12-09 22:35:39 +010066
Harald Welte21b46bd2017-12-17 19:46:32 +010067/* per-BTS state which we keep */
Harald Welte96c94412017-12-09 03:12:45 +010068type record BTS_State {
Harald Welte21b46bd2017-12-17 19:46:32 +010069 /* component reference to the IPA_Client component used for RSL */
Harald Weltea5d2ab22017-12-09 14:21:42 +010070 IPA_Client rsl
Harald Welte96c94412017-12-09 03:12:45 +010071}
72
Harald Weltea4ca4462018-02-09 00:17:14 +010073type component test_CT extends CTRL_Adapter_CT {
Harald Welte21b46bd2017-12-17 19:46:32 +010074 /* Array of per-BTS state */
Harald Welte96c94412017-12-09 03:12:45 +010075 var BTS_State bts[NUM_BTS];
Harald Welte89ab1912018-02-23 18:56:29 +010076 /* RSL common Channel Port (for RSL_Emulation) */
77 port RSL_CCHAN_PT RSL_CCHAN[NUM_BTS];
Harald Welte21b46bd2017-12-17 19:46:32 +010078 /* array of per-BTS RSL test ports */
Harald Welteae026692017-12-09 01:03:01 +010079 port IPA_RSL_PT IPA_RSL[NUM_BTS];
Stefan Sperling830dc9d2018-02-12 21:08:28 +010080 port IPA_CODEC_PT IPA; /* Required for compilation of TC_rsl_unknown_unit_id() */
Harald Weltea5d2ab22017-12-09 14:21:42 +010081
Daniel Willmann191e0d92018-01-17 12:44:35 +010082 var MGCP_Emulation_CT vc_MGCP;
Harald Weltebc03c762018-02-12 18:09:38 +010083 port TELNETasp_PT BSCVTY;
Daniel Willmann191e0d92018-01-17 12:44:35 +010084
Harald Weltea4ca4462018-02-09 00:17:14 +010085 var BSSAP_Adapter g_bssap;
86 /* for old legacy-tests only */
87 port BSSAP_CODEC_PT BSSAP;
88
Harald Welte21b46bd2017-12-17 19:46:32 +010089 /* are we initialized yet */
Harald Welte28d943e2017-11-25 15:00:50 +010090 var boolean g_initialized := false;
Harald Welte21b46bd2017-12-17 19:46:32 +010091
92 /* global test case guard timer */
Harald Welteae026692017-12-09 01:03:01 +010093 timer T_guard := 30.0;
94
Harald Welte28d943e2017-11-25 15:00:50 +010095}
96
97modulepar {
Harald Welte21b46bd2017-12-17 19:46:32 +010098 /* IP address at which the BSC can be reached */
Harald Welte696ddb62017-12-08 14:01:43 +010099 charstring mp_bsc_ip := "127.0.0.1";
Stefan Sperling830dc9d2018-02-12 21:08:28 +0100100 /* port number to which to establish the IPA OML connections */
101 integer mp_bsc_oml_port := 3002;
Harald Welte21b46bd2017-12-17 19:46:32 +0100102 /* port number to which to establish the IPA RSL connections */
Harald Welte696ddb62017-12-08 14:01:43 +0100103 integer mp_bsc_rsl_port := 3003;
Harald Welte21b46bd2017-12-17 19:46:32 +0100104 /* port number to which to establish the IPA CTRL connection */
Harald Welte96c94412017-12-09 03:12:45 +0100105 integer mp_bsc_ctrl_port := 4249;
Daniel Willmann191e0d92018-01-17 12:44:35 +0100106 /* IP address at which the test binds */
107 charstring mp_test_ip := "127.0.0.1";
Harald Weltea4ca4462018-02-09 00:17:14 +0100108
109 BSSAP_Configuration mp_bssap_cfg := {
Harald Welte7ef51aa2018-04-16 19:16:01 +0200110 transport := BSSAP_TRANSPORT_AoIP,
Harald Weltea4ca4462018-02-09 00:17:14 +0100111 sccp_service_type := "mtp3_itu",
112 sctp_addr := { 23905, "127.0.0.1", 2905, "127.0.0.1" },
113 own_pc := 185,
114 own_ssn := 254,
115 peer_pc := 187,
116 peer_ssn := 254,
Philipp Maier38d68942018-03-29 15:38:09 +0200117 sio := '83'O,
118 rctx := 0
Harald Weltea4ca4462018-02-09 00:17:14 +0100119 };
120}
121
Philipp Maier48604732018-10-09 15:00:37 +0200122private function f_gen_test_hdlr_pars() return TestHdlrParams {
123
124 var TestHdlrParams pars := valueof(t_def_TestHdlrPars);
125 if (mp_bssap_cfg.transport == BSSAP_TRANSPORT_AoIP) {
126 pars.aoip := true;
127 } else {
128 pars.aoip := false;
129 }
130
131 return pars;
132}
133
Philipp Maier282ca4b2018-02-27 17:17:00 +0100134private function f_shutdown_helper() runs on test_CT {
Daniel Willmann637ef6c2018-07-25 10:49:09 +0200135 all component.stop;
Philipp Maier282ca4b2018-02-27 17:17:00 +0100136 setverdict(pass);
Daniel Willmannafce8662018-07-06 23:11:32 +0200137 mtc.stop;
Philipp Maier282ca4b2018-02-27 17:17:00 +0100138}
139
Harald Weltea4ca4462018-02-09 00:17:14 +0100140private function f_legacy_bssap_reset() runs on test_CT {
141 var BSSAP_N_UNITDATA_ind ud_ind;
142 timer T := 5.0;
143 BSSAP.send(ts_BSSAP_UNITDATA_req(g_bssap.sccp_addr_peer, g_bssap.sccp_addr_own, ts_BSSMAP_Reset(0)));
144 T.start;
145 alt {
146 [] BSSAP.receive(tr_BSSAP_UNITDATA_ind(g_bssap.sccp_addr_own, g_bssap.sccp_addr_peer, tr_BSSMAP_ResetAck)) {
147 log("Received RESET-ACK in response to RESET, we're ready to go!");
148 }
149 [] BSSAP.receive(tr_BSSAP_UNITDATA_ind(?, ?, tr_BSSMAP_Reset)) -> value ud_ind {
150 log("Respoding to inbound RESET with RESET-ACK");
151 BSSAP.send(ts_BSSAP_UNITDATA_req(ud_ind.callingAddress, ud_ind.calledAddress,
152 ts_BSSMAP_ResetAck));
153 repeat;
154 }
155 [] BSSAP.receive { repeat; }
156 [] T.timeout { setverdict(fail, "Waiting for RESET-ACK after sending RESET"); }
157 }
Harald Welte28d943e2017-11-25 15:00:50 +0100158}
159
Harald Welteae026692017-12-09 01:03:01 +0100160type record IPA_Client {
Harald Welte21b46bd2017-12-17 19:46:32 +0100161 /* IPA Emulation component reference */
Harald Welteae026692017-12-09 01:03:01 +0100162 IPA_Emulation_CT vc_IPA,
Harald Welte21b46bd2017-12-17 19:46:32 +0100163 /* Unit-ID and other CCM parameters to use for IPA client emulation */
Harald Welteae026692017-12-09 01:03:01 +0100164 IPA_CCM_Parameters ccm_pars,
Harald Welte21b46bd2017-12-17 19:46:32 +0100165 /* String identifier for this IPA Client */
Harald Welte624f9632017-12-16 19:26:04 +0100166 charstring id,
Harald Welte21b46bd2017-12-17 19:46:32 +0100167 /* Associated RSL Emulation Component (if any). Only used in "Handler mode" */
Harald Welte624f9632017-12-16 19:26:04 +0100168 RSL_Emulation_CT vc_RSL optional
Harald Welte28d943e2017-11-25 15:00:50 +0100169}
170
Harald Welte21b46bd2017-12-17 19:46:32 +0100171/*! Start the IPA/RSL related bits for one IPA_Client.
172 * \param clnt IPA_Client for which to establish
173 * \param bsc_host IP address / hostname of the BSC
174 * \param bsc_port TCP port number of the BSC
175 * \param i number identifying this BTS
176 * \param handler_mode Start an RSL_Emulation_CT component (true) or not (false) */
Harald Welte624f9632017-12-16 19:26:04 +0100177function f_ipa_rsl_start(inout IPA_Client clnt, charstring bsc_host, PortNumber bsc_port, integer i,
178 boolean handler_mode := false)
Harald Welte28d943e2017-11-25 15:00:50 +0100179runs on test_CT {
Harald Welteae026692017-12-09 01:03:01 +0100180 timer T := 10.0;
181
Harald Welte96c94412017-12-09 03:12:45 +0100182 clnt.id := "IPA" & int2str(i) & "-RSL";
Harald Welteae026692017-12-09 01:03:01 +0100183 clnt.vc_IPA := IPA_Emulation_CT.create(clnt.id & "-IPA");
184 clnt.ccm_pars := c_IPA_default_ccm_pars;
185 clnt.ccm_pars.name := "Osmocom TTCN-3 BTS Simulator";
186 clnt.ccm_pars.unit_id := int2str(1234+i) & "/0/0";
Harald Welte624f9632017-12-16 19:26:04 +0100187 if (handler_mode) {
188 clnt.vc_RSL := RSL_Emulation_CT.create(clnt.id & "-RSL");
Harald Welte89ab1912018-02-23 18:56:29 +0100189 connect(clnt.vc_RSL:CCHAN_PT, self:RSL_CCHAN[i]);
Harald Welte624f9632017-12-16 19:26:04 +0100190 }
Harald Welteae026692017-12-09 01:03:01 +0100191
192 map(clnt.vc_IPA:IPA_PORT, system:IPA_CODEC_PT);
Harald Welte624f9632017-12-16 19:26:04 +0100193 if (handler_mode) {
194 connect(clnt.vc_IPA:IPA_RSL_PORT, clnt.vc_RSL:IPA_PT);
195 } else {
196 connect(clnt.vc_IPA:IPA_RSL_PORT, self:IPA_RSL[i]);
197 }
Harald Welteae026692017-12-09 01:03:01 +0100198
Harald Welte5d1a2202017-12-13 19:51:29 +0100199 clnt.vc_IPA.start(IPA_Emulation.main_client(bsc_host, bsc_port, "", 10000+i, clnt.ccm_pars));
Harald Welte624f9632017-12-16 19:26:04 +0100200 if (handler_mode) {
201 clnt.vc_RSL.start(RSL_Emulation.main());
202 return;
203 }
Harald Welteae026692017-12-09 01:03:01 +0100204
205 /* wait for IPA RSL link to connect and send ID ACK */
206 T.start;
207 alt {
208 [] IPA_RSL[i].receive(ASP_IPA_Event:{up_down := ASP_IPA_EVENT_ID_ACK}) {
209 T.stop;
210 IPA_RSL[i].send(ts_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0,ts_RSL_PAGING_LOAD_IND(23)));
211 }
Harald Welte60e823a2017-12-10 14:10:59 +0100212 [] IPA_RSL[i].receive(ASP_IPA_Event:?) { repeat }
Harald Welteae026692017-12-09 01:03:01 +0100213 [] IPA_RSL[i].receive { repeat }
214 [] T.timeout {
Harald Welte96c94412017-12-09 03:12:45 +0100215 setverdict(fail, "Timeout RSL waiting for ASP_IPA_EVENT_ID_ACK");
Daniel Willmannafce8662018-07-06 23:11:32 +0200216 mtc.stop;
Harald Welteae026692017-12-09 01:03:01 +0100217 }
218 }
219}
220
Harald Welte12055472018-03-17 20:10:08 +0100221function f_ipa_rsl_stop(inout IPA_Client clnt) runs on test_CT {
222 if (not isbound(clnt) or not isbound(clnt.vc_IPA)) {
223 return;
224 }
225 clnt.vc_IPA.stop;
226 if (isbound(clnt.vc_RSL)) {
227 clnt.vc_RSL.stop;
228 }
229}
230
Harald Welte21b46bd2017-12-17 19:46:32 +0100231/* Wait for the OML connection to be brought up by the external osmo-bts-omldummy */
Harald Weltea5d2ab22017-12-09 14:21:42 +0100232function f_wait_oml(integer bts_nr, charstring status, float secs_max) runs on test_CT {
233 timer T := secs_max;
234 T.start;
235 while (true) {
236 if (f_ctrl_get_bts(IPA_CTRL, bts_nr, "oml-connection-state") == status) {
237 T.stop;
Harald Weltebd868bd2017-12-10 18:28:40 +0100238 /* the 'degraded' state exists from OML connection time, and we have to wait
239 * until all MO's are initialized */
240 T.start(1.0);
241 T.timeout;
Harald Weltea5d2ab22017-12-09 14:21:42 +0100242 return;
243 }
Harald Weltef0d6ac62017-12-17 17:02:21 +0100244 f_sleep(0.1);
Harald Weltea5d2ab22017-12-09 14:21:42 +0100245 if (not T.running) {
Max99253902018-11-16 17:57:39 +0100246 setverdict(fail, "Timeout waiting for BTS" & int2str(bts_nr) & " oml-connection-state ", status);
Daniel Willmannafce8662018-07-06 23:11:32 +0200247 mtc.stop;
Harald Weltea5d2ab22017-12-09 14:21:42 +0100248 }
249 }
250}
251
Harald Welte21b46bd2017-12-17 19:46:32 +0100252/* global altstep for global guard timer; also takes care of responding RESET witH RESET-ACK */
Harald Welteae026692017-12-09 01:03:01 +0100253altstep as_Tguard() runs on test_CT {
Harald Welte60e823a2017-12-10 14:10:59 +0100254 var BSSAP_N_UNITDATA_ind ud_ind;
Neels Hofmeyrcc3f76a2018-03-12 01:43:25 +0100255 [] T_guard.timeout {
256 setverdict(fail, "Timeout of T_guard");
Daniel Willmannafce8662018-07-06 23:11:32 +0200257 mtc.stop;
Neels Hofmeyrcc3f76a2018-03-12 01:43:25 +0100258 }
Harald Welte60e823a2017-12-10 14:10:59 +0100259 /* always respond with RESET ACK to RESET */
260 [] BSSAP.receive(tr_BSSAP_UNITDATA_ind(?, ?, tr_BSSMAP_Reset)) -> value ud_ind {
261 BSSAP.send(ts_BSSAP_UNITDATA_req(ud_ind.callingAddress, ud_ind.calledAddress,
262 ts_BSSMAP_ResetAck));
Harald Welte69c1c262017-12-13 21:02:08 +0100263 repeat;
Harald Welte60e823a2017-12-10 14:10:59 +0100264 }
Harald Welte28d943e2017-11-25 15:00:50 +0100265}
266
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +0100267altstep no_bssmap_reset() runs on test_CT {
268 [] BSSAP.receive(tr_BSSAP_UNITDATA_ind(?, ?, tr_BSSMAP_Reset)) {
269 setverdict(fail, "unexpected BSSMAP Reset");
Daniel Willmannafce8662018-07-06 23:11:32 +0200270 mtc.stop;
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +0100271 }
272}
273
Daniel Willmann191e0d92018-01-17 12:44:35 +0100274function f_init_mgcp(charstring id) runs on test_CT {
275 id := id & "-MGCP";
276
277 var MGCPOps ops := {
278 create_cb := refers(MGCP_Emulation.ExpectedCreateCallback),
279 unitdata_cb := refers(MGCP_Emulation.DummyUnitdataCallback)
280 };
281 var MGCP_conn_parameters mgcp_pars := {
282 callagent_ip := mp_bsc_ip,
Harald Welte9e4273e2018-01-29 22:01:22 +0100283 callagent_udp_port := -1,
Daniel Willmann191e0d92018-01-17 12:44:35 +0100284 mgw_ip := mp_test_ip,
285 mgw_udp_port := 2427
286 };
287
288 vc_MGCP := MGCP_Emulation_CT.create(id);
289 vc_MGCP.start(MGCP_Emulation.main(ops, mgcp_pars, id));
290}
291
Max2253c0b2018-11-06 19:28:05 +0100292function f_init_vty(charstring id := "foo") runs on test_CT {
Harald Welte94e0c342018-04-07 11:33:23 +0200293 if (BSCVTY.checkstate("Mapped")) {
294 /* skip initialization if already executed once */
295 return;
296 }
Harald Weltebc03c762018-02-12 18:09:38 +0100297 map(self:BSCVTY, system:BSCVTY);
298 f_vty_set_prompts(BSCVTY);
299 f_vty_transceive(BSCVTY, "enable");
300}
301
Harald Welte21b46bd2017-12-17 19:46:32 +0100302/* global initialization function
303 * \param nr_bts Number of BTSs we should start/bring up
304 * \param handler_mode Start an RSL_Emulation_CT component (true) or not (false) */
Harald Welte89d42e82017-12-17 16:42:41 +0100305function f_init(integer nr_bts := NUM_BTS, boolean handler_mode := false) runs on test_CT {
Harald Welte28d943e2017-11-25 15:00:50 +0100306 var integer i;
Harald Welte28d943e2017-11-25 15:00:50 +0100307
Harald Welteae026692017-12-09 01:03:01 +0100308 if (g_initialized) {
309 return;
Harald Welte28d943e2017-11-25 15:00:50 +0100310 }
Harald Welteae026692017-12-09 01:03:01 +0100311 g_initialized := true;
312
Daniel Willmanne68f9272018-11-27 15:15:28 +0100313 T_guard.start;
314 activate(as_Tguard());
315
Harald Welteae026692017-12-09 01:03:01 +0100316 /* Call a function of our 'parent component' BSSAP_Adapter_CT to start the
317 * MSC-side BSSAP emulation */
Harald Welte67089ee2018-01-17 22:19:03 +0100318 if (handler_mode) {
Harald Weltea4ca4462018-02-09 00:17:14 +0100319 f_bssap_init(g_bssap, mp_bssap_cfg, "VirtMSC", MSC_BssmapOps);
Harald Welte4bcbd172018-05-27 19:47:44 +0200320 f_bssap_start(g_bssap);
Harald Welte67089ee2018-01-17 22:19:03 +0100321 } else {
Harald Weltea4ca4462018-02-09 00:17:14 +0100322 f_bssap_init(g_bssap, mp_bssap_cfg, "VirtMSC", omit);
323 connect(self:BSSAP, g_bssap.vc_SCCP:SCCP_SP_PORT);
Harald Welte4bcbd172018-05-27 19:47:44 +0200324 f_bssap_start(g_bssap);
Harald Weltea4ca4462018-02-09 00:17:14 +0100325 f_legacy_bssap_reset();
Harald Welte67089ee2018-01-17 22:19:03 +0100326 }
Harald Welted5833a82018-05-27 16:52:56 +0200327
Harald Welteffe55fc2018-01-17 22:39:54 +0100328 f_ipa_ctrl_start(mp_bsc_ip, mp_bsc_ctrl_port);
Harald Welte28d943e2017-11-25 15:00:50 +0100329
Daniel Willmann191e0d92018-01-17 12:44:35 +0100330 f_init_mgcp("VirtMSC");
Harald Weltebc03c762018-02-12 18:09:38 +0100331 f_init_vty("VirtMSC");
Daniel Willmann191e0d92018-01-17 12:44:35 +0100332
Harald Welte89d42e82017-12-17 16:42:41 +0100333 for (i := 0; i < nr_bts; i := i+1) {
Harald Weltea5d2ab22017-12-09 14:21:42 +0100334 /* wait until osmo-bts-omldummy has respawned */
335 f_wait_oml(i, "degraded", 5.0);
336 /* start RSL connection */
Harald Welte624f9632017-12-16 19:26:04 +0100337 f_ipa_rsl_start(bts[i].rsl, mp_bsc_ip, mp_bsc_rsl_port, i, handler_mode);
Harald Weltea5d2ab22017-12-09 14:21:42 +0100338 /* wait until BSC tells us "connected" */
339 f_wait_oml(i, "connected", 5.0);
Harald Welte696ddb62017-12-08 14:01:43 +0100340 }
341
Harald Welte28d943e2017-11-25 15:00:50 +0100342}
343
Maxd4e56962018-10-31 19:08:25 +0100344/* expect to receive a RSL message matching a specified template on a given BTS / stream */
Harald Welteae026692017-12-09 01:03:01 +0100345function f_exp_ipa_rx(integer bts_nr, template RSL_Message t_rx, float t_secs := 2.0, IpaStreamId sid := IPAC_PROTO_RSL_TRX0)
346runs on test_CT return RSL_Message {
347 var ASP_RSL_Unitdata rx_rsl_ud;
348 timer T := t_secs;
349
350 T.start;
351 alt {
352 [] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(sid, t_rx)) -> value rx_rsl_ud {
353 T.stop;
354 }
355 [] IPA_RSL[bts_nr].receive { repeat; }
Harald Welteb2917702017-12-10 15:48:52 +0100356 [] T.timeout {
357 setverdict(fail, "Timeout expecting ", t_rx);
Daniel Willmannafce8662018-07-06 23:11:32 +0200358 mtc.stop;
Harald Welteb2917702017-12-10 15:48:52 +0100359 }
Harald Welteae026692017-12-09 01:03:01 +0100360 }
361 return rx_rsl_ud.rsl;
362}
363
Harald Welte21b46bd2017-12-17 19:46:32 +0100364/* helper function to transmit RSL on a given BTS/stream */
Harald Welteae026692017-12-09 01:03:01 +0100365function f_ipa_tx(integer bts_nr, template RSL_Message t_tx, IpaStreamId sid := IPAC_PROTO_RSL_TRX0)
366runs on test_CT {
367 IPA_RSL[bts_nr].send(ts_ASP_RSL_UD(sid, t_tx));
368}
369
370
Harald Welte4003d112017-12-09 22:35:39 +0100371/* verify we get a CHAN_ACT after CHAN RQD */
Harald Welteae026692017-12-09 01:03:01 +0100372testcase TC_chan_act_noreply() runs on test_CT {
373 var BSSAP_N_UNITDATA_ind ud_ind;
Harald Welte930d0a72018-03-22 22:08:40 +0100374 var RSL_Message rsl_unused;
Harald Welte28d943e2017-11-25 15:00:50 +0100375
Harald Welte89d42e82017-12-17 16:42:41 +0100376 f_init(1);
Harald Welte28d943e2017-11-25 15:00:50 +0100377
Harald Welteae026692017-12-09 01:03:01 +0100378 IPA_RSL[0].send(ts_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0,ts_RSL_CHAN_RQD('23'O, 23)));
Harald Welte930d0a72018-03-22 22:08:40 +0100379 rsl_unused := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
Harald Welteae026692017-12-09 01:03:01 +0100380 setverdict(pass);
Harald Welte28d943e2017-11-25 15:00:50 +0100381}
382
Harald Welte4003d112017-12-09 22:35:39 +0100383/* verify if the "chreq:total" counter increments as expected */
384testcase TC_chan_act_counter() runs on test_CT {
385 var BSSAP_N_UNITDATA_ind ud_ind;
386 var integer chreq_total;
Harald Welte930d0a72018-03-22 22:08:40 +0100387 var RSL_Message rsl_unused;
Harald Welte4003d112017-12-09 22:35:39 +0100388
Harald Welte89d42e82017-12-17 16:42:41 +0100389 f_init(1);
Harald Welte4003d112017-12-09 22:35:39 +0100390
391 chreq_total := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:total");
392 IPA_RSL[0].send(ts_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0,ts_RSL_CHAN_RQD('23'O, 23)));
Harald Welte930d0a72018-03-22 22:08:40 +0100393 rsl_unused := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
Harald Welte4003d112017-12-09 22:35:39 +0100394 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:total", chreq_total+1);
395
396 setverdict(pass);
397}
398
Harald Welteae026692017-12-09 01:03:01 +0100399/* CHAN RQD -> CHAN ACT -> CHAN ACT ACK -> RF CHAN REL */
400testcase TC_chan_act_ack_noest() runs on test_CT {
401 var RSL_Message rx_rsl;
402
Harald Welte89d42e82017-12-17 16:42:41 +0100403 f_init(1);
Harald Welteae026692017-12-09 01:03:01 +0100404
405 /* Send CHAN RQD and wait for allocation; acknowledge it */
Harald Welted6939652017-12-13 21:02:46 +0100406 var RslChannelNr chan_nr := f_chreq_act_ack();
Harald Welteae026692017-12-09 01:03:01 +0100407
408 /* expect BSC to disable the channel again if there's no RLL EST IND */
409 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL), T3101_MAX);
410
411 setverdict(pass);
412}
413
414/* Test behavior if MSC never answers to CR */
415testcase TC_chan_act_ack_est_ind_noreply() runs on test_CT {
Harald Weltef77aef62018-01-28 15:35:42 +0100416 var RslLinkId main_dcch := valueof(ts_RslLinkID_DCCH(0));
417 var IpaStreamId sid := IPAC_PROTO_RSL_TRX0;
Harald Welteae026692017-12-09 01:03:01 +0100418 var RSL_Message rx_rsl;
Harald Weltef77aef62018-01-28 15:35:42 +0100419 var ASP_RSL_Unitdata rx_rsl_ud;
Harald Welteae026692017-12-09 01:03:01 +0100420
Harald Welte89d42e82017-12-17 16:42:41 +0100421 f_init(1);
Harald Welteae026692017-12-09 01:03:01 +0100422
423 /* Send CHAN RQD and wait for allocation; acknowledge it */
Harald Welted6939652017-12-13 21:02:46 +0100424 var RslChannelNr chan_nr := f_chreq_act_ack();
Harald Welteae026692017-12-09 01:03:01 +0100425
426 var octetstring l3 := '00010203040506'O
427 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
428
429 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3)));
430
431 /* expect BSC to disable the channel again if there's no response from MSC */
Harald Weltef77aef62018-01-28 15:35:42 +0100432 /* MS waits 20s (T3210) at LU; 10s (T3230) at CM SERV REQ and 5s (T3220) AT detach */
Neels Hofmeyra5302c82018-11-04 23:09:58 +0100433 f_expect_chan_rel(0, chan_nr, expect_rll_rel_req := false);
Harald Welteae026692017-12-09 01:03:01 +0100434 setverdict(pass);
435}
436
437/* Test behavior if MSC answers with CREF to CR */
438testcase TC_chan_act_ack_est_ind_refused() runs on test_CT {
439 var BSSAP_N_CONNECT_ind rx_c_ind;
440 var RSL_Message rx_rsl;
441
Harald Welte89d42e82017-12-17 16:42:41 +0100442 f_init(1);
Harald Welteae026692017-12-09 01:03:01 +0100443
444 /* Send CHAN RQD and wait for allocation; acknowledge it */
Harald Welted6939652017-12-13 21:02:46 +0100445 var RslChannelNr chan_nr := f_chreq_act_ack();
Harald Welteae026692017-12-09 01:03:01 +0100446
447 var octetstring l3 := '00010203040506'O
448 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
449
450 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) -> value rx_c_ind;
451 BSSAP.send(ts_BSSAP_DISC_req(rx_c_ind.connectionId, 0));
452
453 /* expect BSC to disable the channel */
Neels Hofmeyra5302c82018-11-04 23:09:58 +0100454 f_expect_chan_rel(0, chan_nr, expect_rll_rel_req := false);
Harald Welteae026692017-12-09 01:03:01 +0100455 setverdict(pass);
456}
457
Harald Welte618ef642017-12-14 14:58:20 +0100458/* CHAN RQD -> CHAN ACT -> CHAN ACT NACK -> RF CHAN REL */
459testcase TC_chan_act_nack() runs on test_CT {
460 var RSL_Message rx_rsl;
461 var integer chact_nack;
462
Harald Welte89d42e82017-12-17 16:42:41 +0100463 f_init(1);
Harald Welte618ef642017-12-14 14:58:20 +0100464
465 chact_nack := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "chan_act:nack");
466
467 f_ipa_tx(0, ts_RSL_CHAN_RQD('33'O, 33));
468 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
469 var RslChannelNr chan_nr := rx_rsl.ies[0].body.chan_nr;
470
471 f_ipa_tx(0, ts_RSL_CHAN_ACT_NACK(chan_nr, RSL_ERR_EQUIPMENT_FAIL));
472
473 /* wait for some time to hope the NACK arrives before the CTRL GET below */
474 f_sleep(0.5);
475
476 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "chan_act:nack", chact_nack+1);
477
478 setverdict(pass);
479}
480
Harald Welte799c97b2017-12-14 17:50:30 +0100481/* Test for channel exhaustion due to RACH overload */
482testcase TC_chan_exhaustion() runs on test_CT {
483 var ASP_RSL_Unitdata rsl_ud;
484 var integer i;
485 var integer chreq_total, chreq_nochan;
486
Harald Welte89d42e82017-12-17 16:42:41 +0100487 f_init(1);
Harald Welte799c97b2017-12-14 17:50:30 +0100488
489 chreq_total := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:total");
490 chreq_nochan := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:no_channel");
491
Pau Espin Pedrolfe200d72018-12-10 12:41:04 +0100492 /* GSM 04.08 Table 9.9a:
493 * RA = '33'O -> Establishment cause = 0011xxxx (MS dual rate capable and asks for "TCH/H or TCH/F").
494 * With current setup, expect 4xSDCCH + 4xTCH/F + 1xTCH/H to succeed */
Philipp Maiercb6cc482018-03-26 13:08:00 +0200495 for (i := 0; i < NUM_TCHF_PER_BTS + NUM_TCHH_PER_BTS + NUM_SDCCH_PER_BTS; i := i+1) {
Pau Espin Pedrolfe200d72018-12-10 12:41:04 +0100496 var RslChannelNr chan_nr := f_chreq_act_ack('33'O, i);
Harald Welte799c97b2017-12-14 17:50:30 +0100497 }
498
499 IPA_RSL[0].clear;
500
Harald Weltedd8cbf32018-01-28 12:07:52 +0100501 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:total",
Philipp Maiercb6cc482018-03-26 13:08:00 +0200502 chreq_total + NUM_TCHF_PER_BTS + NUM_TCHH_PER_BTS + NUM_SDCCH_PER_BTS);
Harald Welte799c97b2017-12-14 17:50:30 +0100503
504 /* now expect additional channel activations to fail */
505 f_ipa_tx(0, ts_RSL_CHAN_RQD('42'O, 42));
506
507 alt {
508 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0,
509 tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV))) {
510 setverdict(fail, "Received CHAN ACT ACK without resources?!?");
511 }
512 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0, tr_RSL_IMM_ASSIGN(?))) -> value rsl_ud {
513 var GsmRrMessage rr;
514 /* match on IMM ASS REJ */
515 rr := dec_GsmRrMessage(rsl_ud.rsl.ies[1].body.full_imm_ass_info.payload);
516 if (rr.header.message_type == IMMEDIATE_ASSIGNMENT_REJECT) {
517 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:total",
Philipp Maiercb6cc482018-03-26 13:08:00 +0200518 chreq_total + NUM_TCHF_PER_BTS + NUM_TCHH_PER_BTS + NUM_SDCCH_PER_BTS+1);
Harald Welte799c97b2017-12-14 17:50:30 +0100519 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:no_channel",
520 chreq_nochan+1);
521 setverdict(pass);
522 } else {
523 repeat;
524 }
525 }
526 [] IPA_RSL[0].receive { repeat; }
527 }
528}
529
Vadim Yanitskiy1ff1fdf2018-11-27 01:32:57 +0700530/* Test channel deactivation due to silence from MS */
531testcase TC_chan_deact_silence() runs on test_CT {
532 var RslChannelNr chan_nr;
533
534 f_init(1);
535
536 /* Request for a dedicated channel */
537 chan_nr := f_chreq_act_ack('23'O);
538
539 /* Wait some time until the channel is released */
540 f_sleep(2.0);
541
542 /* Expect CHANnel RELease */
543 alt {
544 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0,
545 tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL))) {
546 log("Received CHANnel RELease");
547 setverdict(pass);
548 }
549 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0,
550 tr_RSL_IMM_ASSIGN(?))) {
551 /* See OS#3709, OsmoBSC should not send Immediate
552 * Assignment Reject since a dedicated channel was
553 * already allocated, and Immediate Assignment was
554 * already sent. */
555 setverdict(fail, "Unexpected Immediate Assignment!");
556 }
557 [] IPA_RSL[0].receive {
558 setverdict(fail, "Unexpected RSL message!");
559 }
560 }
561}
562
Harald Weltecfe2c962017-12-15 12:09:32 +0100563/***********************************************************************
564 * Assignment Testing
565 ***********************************************************************/
566
Neels Hofmeyrda4a6952018-06-14 04:02:49 +0200567/* Verify that the BSC refuses any BSSAP connection from the MSC (They are all BSC->MSC direction,
568 * except for the inter-BSC handover, MT side) */
Harald Weltecfe2c962017-12-15 12:09:32 +0100569testcase TC_outbound_connect() runs on test_CT {
Harald Welte89d42e82017-12-17 16:42:41 +0100570 f_init(1);
Harald Weltecfe2c962017-12-15 12:09:32 +0100571
Harald Weltea4ca4462018-02-09 00:17:14 +0100572 BSSAP.send(ts_BSSAP_CONNECT_req(g_bssap.sccp_addr_peer, g_bssap.sccp_addr_own, 2342, ts_BSSMAP_AssignmentReq));
Harald Weltecfe2c962017-12-15 12:09:32 +0100573 BSSAP.receive(tr_BSSAP_DISC_ind(2342, ?, ?));
574 setverdict(pass);
575}
576
Harald Welte16a4adf2017-12-14 18:54:01 +0100577/* Test behavior if MSC answers with CREF to CR */
578testcase TC_assignment_cic_only() runs on test_CT {
579 var BSSAP_N_CONNECT_ind rx_c_ind;
580 var RSL_Message rx_rsl;
581 var DchanTuple dt;
582
Harald Welte89d42e82017-12-17 16:42:41 +0100583 f_init(1);
Harald Welte16a4adf2017-12-14 18:54:01 +0100584
585 dt := f_est_dchan('23'O, 23, '00000000'O);
Harald Welte17b27da2018-05-25 20:33:53 +0200586 if (mp_bssap_cfg.transport == BSSAP_TRANSPORT_AoIP) {
587 /* send assignment without AoIP IEs */
588 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_AssignmentReq(ts_BSSMAP_IE_CIC(0, 1))));
589 } else {
590 /* Send assignmetn without CIC in IPA case */
591 var BSSMAP_IE_AoIP_TransportLayerAddress tla :=
592 valueof(ts_BSSMAP_IE_AoIP_TLA4('01020304'O, 2342));
593 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_AssignmentReq(omit, tla)));
594 }
Harald Welte16a4adf2017-12-14 18:54:01 +0100595 alt {
596 [] BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_AssignmentComplete)) {
597 setverdict(fail, "AoIP BSC cannot accept ASSIGNMENT without AoIP Transport IE");
598 }
Harald Welte235ebf12017-12-15 14:18:16 +0100599 /* TODO: Actually expect GSM0808_CAUSE_REQ_A_IF_TYPE_NOT_SUPP */
Harald Welte16a4adf2017-12-14 18:54:01 +0100600 [] BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_AssignmentFail)) {
601 setverdict(pass);
602 }
603 [] BSSAP.receive { repeat; }
604 }
605}
606
Harald Welteed848512018-05-24 22:27:58 +0200607/* generate an assignment request for either AoIP or SCCPlite */
Harald Weltee102eae2018-05-31 21:03:47 +0200608function f_gen_ass_req() return PDU_BSSAP {
Harald Welteed848512018-05-24 22:27:58 +0200609 var PDU_BSSAP ass_cmd;
610 if (mp_bssap_cfg.transport == BSSAP_TRANSPORT_AoIP) {
611 var BSSMAP_IE_AoIP_TransportLayerAddress tla :=
612 valueof(ts_BSSMAP_IE_AoIP_TLA4('01020304'O, 2342));
613 ass_cmd := valueof(ts_BSSMAP_AssignmentReq(omit, tla));
614 } else {
615 var BSSMAP_IE_CircuitIdentityCode cic := valueof(ts_BSSMAP_IE_CIC(0,1));
616 ass_cmd := valueof(ts_BSSMAP_AssignmentReq(cic, omit));
617 }
618 return ass_cmd;
619}
620
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +0100621function f_gen_handover_req() return PDU_BSSAP {
622 var PDU_BSSAP ho_req;
623 if (mp_bssap_cfg.transport == BSSAP_TRANSPORT_AoIP) {
624 var BSSMAP_IE_AoIP_TransportLayerAddress tla :=
625 valueof(ts_BSSMAP_IE_AoIP_TLA4('01020304'O, 2342));
626 ho_req := valueof(ts_BSSMAP_HandoverRequest(omit, tla));
627 } else {
628 var BSSMAP_IE_CircuitIdentityCode cic := valueof(ts_BSSMAP_IE_CIC(0,1));
629 ho_req := valueof(ts_BSSMAP_HandoverRequest(cic, omit));
630 }
631 return ho_req;
632}
633
Harald Welteed848512018-05-24 22:27:58 +0200634/* generate an assignment complete template for either AoIP or SCCPlite */
Harald Weltee102eae2018-05-31 21:03:47 +0200635function f_gen_exp_compl() return template PDU_BSSAP {
Harald Welteed848512018-05-24 22:27:58 +0200636 var template PDU_BSSAP exp_compl;
637 if (mp_bssap_cfg.transport == BSSAP_TRANSPORT_AoIP) {
638 exp_compl := tr_BSSMAP_AssignmentComplete(omit, ?);
639 } else {
640 /* CIC is optional "*" as the MSC allocated it */
641 exp_compl := tr_BSSMAP_AssignmentComplete(*, omit);
642 }
643 return exp_compl;
644}
645
Harald Welte235ebf12017-12-15 14:18:16 +0100646/* Run everything required up to sending a caller-specified assignment command and expect response */
647function f_assignment_exp(PDU_BSSAP ass_cmd, template PDU_BSSAP exp, charstring fail_text)
648runs on test_CT {
649 var BSSAP_N_CONNECT_ind rx_c_ind;
650 var RSL_Message rx_rsl;
651 var DchanTuple dt;
652
Harald Welte89d42e82017-12-17 16:42:41 +0100653 f_init(1);
Harald Welte235ebf12017-12-15 14:18:16 +0100654
655 dt := f_est_dchan('23'O, 23, '00000000'O);
656 /* send assignment without AoIP IEs */
657 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ass_cmd));
658 alt {
659 [] BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_AssignmentComplete)) {
660 if (ischosen(exp.pdu.bssmap.assignmentComplete)) {
661 setverdict(pass);
662 } else {
663 setverdict(fail, fail_text);
664 }
665 }
666 [] BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_AssignmentFail)) {
667 if (ischosen(exp.pdu.bssmap.assignmentFailure)) {
668 setverdict(pass);
669 } else {
670 setverdict(fail, fail_text);
671 }
672 }
673 [] BSSAP.receive { repeat; }
674 }
675}
676testcase TC_assignment_csd() runs on test_CT {
677 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
Harald Welteed848512018-05-24 22:27:58 +0200678 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte235ebf12017-12-15 14:18:16 +0100679 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelTypeCSD);
680 //exp_fail.pdu.bssmap.assignmentFailure.cause.causeValue := int2bit(enum2int(GSM0808_CAUSE_REQ_CODEC_TYPE_OR_CONFIG_UNAVAIL), 7);
681 f_assignment_exp(ass_cmd, exp_fail, "BSC accepted Assignment for CSD");
682}
683
684testcase TC_assignment_ctm() runs on test_CT {
685 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
Harald Welteed848512018-05-24 22:27:58 +0200686 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte235ebf12017-12-15 14:18:16 +0100687 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelTypeCTM);
688 //exp_fail.pdu.bssmap.assignmentFailure.cause.causeValue := int2bit(enum2int(GSM0808_CAUSE_REQ_CODEC_TYPE_OR_CONFIG_UNAVAIL), 7);
689 f_assignment_exp(ass_cmd, exp_fail, "BSC accepted Assignment for Speech+CTM");
690}
691
Harald Welte4003d112017-12-09 22:35:39 +0100692type record DchanTuple {
693 integer sccp_conn_id,
694 RslChannelNr rsl_chan_nr
Harald Weltea5d2ab22017-12-09 14:21:42 +0100695}
696
Harald Welted6939652017-12-13 21:02:46 +0100697/* Send CHAN RQD and wait for allocation; acknowledge it */
698private function f_chreq_act_ack(OCT1 ra := '23'O, GsmFrameNumber fn := 23)
699runs on test_CT return RslChannelNr {
700 var RSL_Message rx_rsl;
701 f_ipa_tx(0, ts_RSL_CHAN_RQD(ra, fn));
702 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
703 var RslChannelNr chan_nr := rx_rsl.ies[0].body.chan_nr;
704 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, fn+10));
Daniel Willmannf4ac4ce2018-08-02 14:06:30 +0200705 rx_rsl := f_exp_ipa_rx(0, tr_RSL_IMM_ASSIGN(0));
Harald Welted6939652017-12-13 21:02:46 +0100706 return chan_nr;
707}
708
Harald Welte4003d112017-12-09 22:35:39 +0100709/* helper function to establish a dedicated channel via BTS and MSC */
710function f_est_dchan(OCT1 ra, GsmFrameNumber fn, octetstring l3)
711runs on test_CT return DchanTuple {
712 var BSSAP_N_CONNECT_ind rx_c_ind;
Harald Welte4003d112017-12-09 22:35:39 +0100713 var DchanTuple dt;
Harald Weltea5d2ab22017-12-09 14:21:42 +0100714
Harald Welte4003d112017-12-09 22:35:39 +0100715 /* Send CHAN RQD and wait for allocation; acknowledge it */
Harald Welted6939652017-12-13 21:02:46 +0100716 dt.rsl_chan_nr := f_chreq_act_ack(ra, fn);
Harald Welte4003d112017-12-09 22:35:39 +0100717
718 f_ipa_tx(0, ts_RSL_EST_IND(dt.rsl_chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
719
720 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) -> value rx_c_ind;
721 dt.sccp_conn_id := rx_c_ind.connectionId;
722 BSSAP.send(ts_BSSAP_CONNECT_res(dt.sccp_conn_id));
723
724 return dt;
Harald Weltea5d2ab22017-12-09 14:21:42 +0100725}
726
Harald Welte641fcbe2018-06-14 10:58:35 +0200727/* expect RF CAN REL from BTS, acknowledge it and clear the MSC side */
728private function f_exp_chan_rel_and_clear(DchanTuple dt, integer bts_nr := 0) runs on test_CT {
729 var RSL_Message rx_rsl;
730 /* expect BSC to disable the channel */
731 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL), T3101_MAX);
732 /* respond with CHAN REL ACK */
733 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(dt.rsl_chan_nr));
734
735 /* expect Clear Complete from BSC */
736 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearComplete));
737
738 /* MSC disconnects as instructed. */
739 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
740}
741
Harald Welte4003d112017-12-09 22:35:39 +0100742/* Test behavior of channel release after unilateral RLL REL IND (DISC from MS) */
743testcase TC_chan_rel_rll_rel_ind() runs on test_CT {
Neels Hofmeyr27f64362018-03-12 01:44:00 +0100744 var BSSAP_N_DATA_ind rx_di;
Harald Welte4003d112017-12-09 22:35:39 +0100745 var DchanTuple dt;
Harald Welte96c94412017-12-09 03:12:45 +0100746
Harald Welte89d42e82017-12-17 16:42:41 +0100747 f_init(1);
Harald Welte96c94412017-12-09 03:12:45 +0100748
Harald Welte4003d112017-12-09 22:35:39 +0100749 dt := f_est_dchan('23'O, 23, '00010203040506'O);
750
751 /* simulate RLL REL IND */
752 f_ipa_tx(0, ts_RSL_REL_IND(dt.rsl_chan_nr, valueof(ts_RslLinkID_DCCH(0))));
753
Neels Hofmeyr27f64362018-03-12 01:44:00 +0100754 /* expect Clear Request on MSC side */
755 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearRequest)) -> value rx_di;
756
757 /* Instruct BSC to clear channel */
758 var BssmapCause cause := bit2int(rx_di.userData.pdu.bssmap.clearRequest.cause.causeValue);
759 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
760
Harald Welte4003d112017-12-09 22:35:39 +0100761 /* expect BSC to disable the channel */
Harald Welte641fcbe2018-06-14 10:58:35 +0200762 f_exp_chan_rel_and_clear(dt, 0);
Neels Hofmeyr27f64362018-03-12 01:44:00 +0100763
764 /* wait for SCCP emulation to do its job */
765 f_sleep(1.0);
Harald Welte4003d112017-12-09 22:35:39 +0100766
767 setverdict(pass);
768}
769
770/* Test behavior of channel release after CONN FAIL IND from BTS */
771testcase TC_chan_rel_conn_fail() runs on test_CT {
772 var BSSAP_N_DATA_ind rx_di;
Harald Welte4003d112017-12-09 22:35:39 +0100773 var DchanTuple dt;
774
Harald Welte89d42e82017-12-17 16:42:41 +0100775 f_init(1);
Harald Welte4003d112017-12-09 22:35:39 +0100776
777 dt := f_est_dchan('23'O, 23, '00010203040506'O);
778
779 /* simulate CONN FAIL IND */
Harald Weltea8ed9062017-12-14 09:46:01 +0100780 f_ipa_tx(0, ts_RSL_CONN_FAIL_IND(dt.rsl_chan_nr, RSL_ERR_RADIO_LINK_FAIL));
Harald Welte4003d112017-12-09 22:35:39 +0100781 /* TODO: different cause values? */
782
Harald Welte4003d112017-12-09 22:35:39 +0100783 /* expect Clear Request from BSC */
784 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearRequest)) -> value rx_di;
785
786 /* Instruct BSC to clear channel */
787 var BssmapCause cause := bit2int(rx_di.userData.pdu.bssmap.clearRequest.cause.causeValue);
788 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
789
Harald Welte6ff76ea2018-01-28 13:08:01 +0100790 /* expect BSC to disable the channel */
Harald Welte641fcbe2018-06-14 10:58:35 +0200791 f_exp_chan_rel_and_clear(dt, 0);
Harald Welte4003d112017-12-09 22:35:39 +0100792
793 /* wait for SCCP emulation to do its job */
794 f_sleep(1.0);
795
796 setverdict(pass);
797}
798
Harald Welte99f3ca02018-06-14 13:40:29 +0200799/* Test behavior of early CONN FAIL IND from BTS (before EST IND!) */
800/* See also https://www.osmocom.org/issues/3182 */
801testcase TC_early_conn_fail() runs on test_CT {
802 var RSL_Message rx_rsl;
803 var DchanTuple dt;
804
805 f_init(1);
806
807 /* BTS->BSC: Send CHAN RQD and wait for allocation; acknowledge it */
808 dt.rsl_chan_nr := f_chreq_act_ack(f_rnd_octstring(1), 23);
809
810 /* BTS->BSC: simulate CONN FAIL IND */
811 f_ipa_tx(0, ts_RSL_CONN_FAIL_IND(dt.rsl_chan_nr, RSL_ERR_RADIO_LINK_FAIL));
812
813 /* BTS->BSC: Expect RF channel release from BSC on Abis */
814 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL), 10.0);
815
816 /* BTS<-BSC: respond with CHAN REL ACK */
817 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(dt.rsl_chan_nr));
818
819 setverdict(pass);
820}
821
822/* Test behavior of late CONN FAIL IND from BTS (ater REL IND!) */
823/* See also https://www.osmocom.org/issues/3182 */
824testcase TC_late_conn_fail() runs on test_CT {
825 var RSL_Message rx_rsl;
826 var DchanTuple dt;
827
828 f_init(1);
829
830 dt := f_est_dchan('23'O, 23, '00010203040506'O);
831
832 /* BSC<-MSC: Instruct BSC to clear connection */
833 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(0)));
834
835 /* BTS->BSC: expect BSC to deactivate SACCH */
836 rx_rsl := f_exp_ipa_rx(0, tr_RSL_DEACT_SACCH(dt.rsl_chan_nr));
837
838 /* BTS->BSC: simulate a late CONN FAIL IND from BTS */
839 f_ipa_tx(0, ts_RSL_CONN_FAIL_IND(dt.rsl_chan_nr, RSL_ERR_RADIO_LINK_FAIL));
840
841 /* BTS<-BSC: Expect RF channel release from BSC on Abis */
842 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL), 10.0);
843 /* BTS->BSC: respond with CHAN REL ACK */
844 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(dt.rsl_chan_nr));
845
846 /* BSC->MSC: expect Clear Complete from BSC */
847 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearComplete));
848
849 /* BSC<-MSC: MSC disconnects as requested. */
850 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
851
852 setverdict(pass);
853}
854
Neels Hofmeyrf44ccd12018-11-05 19:15:23 +0100855function f_expect_chan_rel(integer bts_nr, RslChannelNr rsl_chan_nr,
Neels Hofmeyra5302c82018-11-04 23:09:58 +0100856 boolean expect_deact_sacch := true,
857 boolean expect_rr_chan_rel := true,
858 boolean expect_rll_rel_req := true,
859 boolean handle_rll_rel := true
860 ) runs on test_CT {
Harald Welte91d54a52018-01-28 15:35:07 +0100861
862 var RslLinkId main_dcch := valueof(ts_RslLinkID_DCCH(0));
Neels Hofmeyra5302c82018-11-04 23:09:58 +0100863 var boolean got_deact_sacch := false;
864 var boolean got_rr_chan_rel := false;
865 var boolean got_rll_rel_req := false;
866 log("f_expect_chan_rel() expecting: expect_deact_sacch=", expect_deact_sacch, " expect_rr_chan_rel=", expect_rr_chan_rel,
867 " expect_rll_rel_req=", expect_rll_rel_req);
Harald Welte91d54a52018-01-28 15:35:07 +0100868 alt {
Harald Welte91d54a52018-01-28 15:35:07 +0100869 [] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0,
870 tr_RSL_DEACT_SACCH(rsl_chan_nr))) {
Neels Hofmeyra5302c82018-11-04 23:09:58 +0100871 got_deact_sacch := true;
Harald Welte91d54a52018-01-28 15:35:07 +0100872 repeat;
873 }
Harald Welte924b6ea2019-02-04 01:05:34 +0100874 [] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0, tr_RSL_DATA_REQ(rsl_chan_nr, ?, decmatch tr_RRM_RR_RELEASE))) {
Neels Hofmeyra5302c82018-11-04 23:09:58 +0100875 got_rr_chan_rel := true;
Neels Hofmeyr211169d2018-11-07 00:37:29 +0100876 repeat;
877 }
Neels Hofmeyra5302c82018-11-04 23:09:58 +0100878 [] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0,
Harald Welte91d54a52018-01-28 15:35:07 +0100879 tr_RSL_REL_REQ(rsl_chan_nr, ?))) {
Neels Hofmeyra5302c82018-11-04 23:09:58 +0100880 got_rll_rel_req := true;
Harald Welte91d54a52018-01-28 15:35:07 +0100881 /* FIXME: Why are we getting this for LinkID SACCH? */
Neels Hofmeyra5302c82018-11-04 23:09:58 +0100882 if (handle_rll_rel) {
883 f_ipa_tx(0, ts_RSL_REL_CONF(rsl_chan_nr, main_dcch));
884 }
Harald Welte91d54a52018-01-28 15:35:07 +0100885 repeat;
886 }
Harald Welte91d54a52018-01-28 15:35:07 +0100887 [] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0,
888 tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL))) {
889 /* respond with CHAN REL ACK */
890 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(rsl_chan_nr));
891 }
892 /* ignore any user data */
893 [] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0, tr_RSL_MsgTypeR(?))) {
894 repeat;
895 }
896 }
Neels Hofmeyra5302c82018-11-04 23:09:58 +0100897
898 log("f_expect_chan_rel() summary: got_deact_sacch=", got_deact_sacch, " got_rr_chan_rel=", got_rr_chan_rel,
899 " got_rll_rel_req=", got_rll_rel_req);
900
901 if (expect_deact_sacch != got_deact_sacch) {
902 setverdict(fail, "f_expect_chan_rel(): expect_deact_sacch=", expect_deact_sacch, " got_deact_sacch=", got_deact_sacch);
903 }
904 if (expect_rr_chan_rel != got_rr_chan_rel) {
905 setverdict(fail, "f_expect_chan_rel(): expect_rr_chan_rel=", expect_rr_chan_rel, " got_rr_chan_rel=", got_rr_chan_rel);
906 }
907 if (expect_rll_rel_req != got_rll_rel_req) {
908 setverdict(fail, "f_expect_chan_rel(): expect_rll_rel_req=", expect_rll_rel_req, " got_rll_rel_req=", got_rll_rel_req);
909 }
Harald Welte91d54a52018-01-28 15:35:07 +0100910}
911
Harald Welte4003d112017-12-09 22:35:39 +0100912/* Test behavior of channel release after hard Clear Command from MSC */
913testcase TC_chan_rel_hard_clear() runs on test_CT {
914 var BSSAP_N_DATA_ind rx_di;
Harald Welte4003d112017-12-09 22:35:39 +0100915 var DchanTuple dt;
Harald Welte4003d112017-12-09 22:35:39 +0100916
Harald Welte89d42e82017-12-17 16:42:41 +0100917 f_init(1);
Harald Welte4003d112017-12-09 22:35:39 +0100918
919 dt := f_est_dchan('23'O, 23, '00010203040506'O);
920
921 /* Instruct BSC to clear channel */
922 var BssmapCause cause := 0;
923 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
924
925 /* expect Clear Complete from BSC on A */
926 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearComplete)) {
927 /* release the SCCP connection */
928 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
929 }
930
Neels Hofmeyra5302c82018-11-04 23:09:58 +0100931 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
Harald Welte4003d112017-12-09 22:35:39 +0100932 setverdict(pass);
933}
934
Harald Welted8c36cd2017-12-09 23:05:31 +0100935/* Test behavior of channel release after hard RLSD from MSC */
936testcase TC_chan_rel_hard_rlsd() runs on test_CT {
Harald Welted8c36cd2017-12-09 23:05:31 +0100937 var DchanTuple dt;
Harald Welted8c36cd2017-12-09 23:05:31 +0100938
Harald Welte89d42e82017-12-17 16:42:41 +0100939 f_init(1);
Harald Welted8c36cd2017-12-09 23:05:31 +0100940
941 dt := f_est_dchan('23'O, 23, '00010203040506'O);
942
943 /* release the SCCP connection */
944 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
945
Neels Hofmeyra5302c82018-11-04 23:09:58 +0100946 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
Harald Welted8c36cd2017-12-09 23:05:31 +0100947 setverdict(pass);
948}
949
Harald Welte550daf92018-06-11 19:22:13 +0200950/* Test behavior of channel release after hard RLSD from MSC and MS is not responding to RLL REL REQ */
951testcase TC_chan_rel_hard_rlsd_ms_dead() runs on test_CT {
952 var DchanTuple dt;
953
954 f_init(1);
955
956 dt := f_est_dchan('23'O, 23, '00010203040506'O);
957
958 /* release the SCCP connection */
959 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
960
Neels Hofmeyra5302c82018-11-04 23:09:58 +0100961 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
Harald Welte550daf92018-06-11 19:22:13 +0200962 setverdict(pass);
963}
964
Harald Welte85804d42017-12-10 14:11:58 +0100965/* Test behavior of channel release after BSSMAP RESET from MSC */
966testcase TC_chan_rel_a_reset() runs on test_CT {
Harald Welte85804d42017-12-10 14:11:58 +0100967 var DchanTuple dt;
Harald Welte85804d42017-12-10 14:11:58 +0100968
Harald Welte89d42e82017-12-17 16:42:41 +0100969 f_init(1);
Harald Welte85804d42017-12-10 14:11:58 +0100970
971 dt := f_est_dchan('23'O, 23, '00010203040506'O);
972
973 /* Clear the queue, it might still contain stuff like IMMEDIATE ASSIGN */
974 IPA_RSL[0].clear;
975
976 /* perform BSSAP RESET, expect RESET ACK and DISC.ind on connection */
Harald Weltea4ca4462018-02-09 00:17:14 +0100977 BSSAP.send(ts_BSSAP_UNITDATA_req(g_bssap.sccp_addr_peer, g_bssap.sccp_addr_own, ts_BSSMAP_Reset(0)));
Harald Welte85804d42017-12-10 14:11:58 +0100978 interleave {
Harald Weltea4ca4462018-02-09 00:17:14 +0100979 [] BSSAP.receive(tr_BSSAP_UNITDATA_ind(g_bssap.sccp_addr_own, g_bssap.sccp_addr_peer, tr_BSSMAP_ResetAck)) { }
Harald Welte85804d42017-12-10 14:11:58 +0100980 [] BSSAP.receive(tr_BSSAP_DISC_ind(dt.sccp_conn_id, ?, ?)) { }
981 }
982
Neels Hofmeyra5302c82018-11-04 23:09:58 +0100983 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
Harald Welte85804d42017-12-10 14:11:58 +0100984 setverdict(pass);
985}
986
Harald Welte5cd20ed2017-12-13 21:03:20 +0100987/* Test behavior if RSL EST IND for non-active channel */
988testcase TC_rll_est_ind_inact_lchan() runs on test_CT {
989 timer T := 2.0;
990
Harald Welte89d42e82017-12-17 16:42:41 +0100991 f_init(1);
Harald Welte5cd20ed2017-12-13 21:03:20 +0100992
993 var octetstring l3 := '00010203040506'O;
994 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(6));
995 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
996
997 T.start;
998 alt {
999 [] BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) {
1000 setverdict(fail, "MSC received COMPL L3 for non-active lchan");
1001 }
1002 [] BSSAP.receive {}
1003 [] IPA_RSL[0].receive {}
1004 [] T.timeout {}
1005 }
1006
1007 setverdict(pass);
1008}
1009
1010/* Test behavior if RSL EST IND for invalid SAPI */
1011testcase TC_rll_est_ind_inval_sapi1() runs on test_CT {
1012 var RslChannelNr chan_nr;
1013
Harald Welte89d42e82017-12-17 16:42:41 +01001014 f_init(1);
Harald Welte5cd20ed2017-12-13 21:03:20 +01001015
1016 chan_nr := f_chreq_act_ack()
1017
1018 var octetstring l3 := '00010203040506'O;
1019 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(1)), l3));
1020
1021 timer T := 2.0;
1022 T.start;
1023 alt {
1024 [] BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) {
1025 setverdict(fail, "MSC received COMPL L3 for invalid SAPI 1");
1026 }
1027 [] BSSAP.receive { repeat; }
1028 [] IPA_RSL[0].receive { repeat; }
1029 [] T.timeout {}
1030 }
1031
1032 setverdict(pass);
1033}
1034
1035/* Test behavior if RSL EST IND for invalid SAPI */
1036testcase TC_rll_est_ind_inval_sapi3() runs on test_CT {
1037 timer T := 2.0;
1038
Harald Welte89d42e82017-12-17 16:42:41 +01001039 f_init(1);
Harald Welte5cd20ed2017-12-13 21:03:20 +01001040
1041 var RslChannelNr chan_nr := f_chreq_act_ack();
1042
1043 var octetstring l3 := '00010203040506'O;
1044 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(3)), l3));
1045
1046 T.start;
1047 alt {
1048 [] BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) {
1049 setverdict(fail, "MSC received COMPL L3 for invalid SAPI 3");
1050 }
1051 [] BSSAP.receive { repeat; }
1052 [] IPA_RSL[0].receive { repeat; }
1053 [] T.timeout {}
1054 }
1055
1056 setverdict(pass);
1057}
1058
1059/* Test behavior if RSL EST IND for invalid SACCH */
1060testcase TC_rll_est_ind_inval_sacch() runs on test_CT {
1061 timer T := 2.0;
1062
Harald Welte89d42e82017-12-17 16:42:41 +01001063 f_init(1);
Harald Welte5cd20ed2017-12-13 21:03:20 +01001064
1065 var RslChannelNr chan_nr := f_chreq_act_ack();
1066
1067 var octetstring l3 := '00010203040506'O;
1068 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_SACCH(0)), l3));
1069
1070 T.start;
1071 alt {
1072 [] BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) {
1073 setverdict(fail, "MSC received COMPL L3 for invalid Link SACCH");
1074 }
1075 [] BSSAP.receive { repeat; }
1076 [] IPA_RSL[0].receive { repeat; }
1077 [] T.timeout {}
1078 }
1079
1080 setverdict(pass);
1081}
1082
1083
1084
Harald Welte4003d112017-12-09 22:35:39 +01001085
1086testcase TC_ctrl_msc_connection_status() runs on test_CT {
1087 var charstring ctrl_resp;
1088
Harald Welte89d42e82017-12-17 16:42:41 +01001089 f_init(1);
Harald Welte4003d112017-12-09 22:35:39 +01001090
1091 /* See https://osmocom.org/issues/2729 */
1092 f_ctrl_get_exp(IPA_CTRL, "msc_connection_status", "connected");
1093 setverdict(pass);
1094}
1095
Stefan Sperlingb041b3d2018-01-03 17:14:55 +01001096testcase TC_ctrl_msc0_connection_status() runs on test_CT {
1097 var charstring ctrl_resp;
1098
1099 f_init(1);
Stefan Sperlingb041b3d2018-01-03 17:14:55 +01001100
1101 f_ctrl_get_exp(IPA_CTRL, "msc.0.connection_status", "connected");
1102 setverdict(pass);
1103}
1104
Harald Welte4003d112017-12-09 22:35:39 +01001105testcase TC_ctrl() runs on test_CT {
1106 var charstring ctrl_resp;
1107
Harald Welte89d42e82017-12-17 16:42:41 +01001108 f_init(1);
Harald Welte4003d112017-12-09 22:35:39 +01001109
1110 /* all below values must match the osmo-bsc.cfg config file used */
1111
Harald Welte6a129692018-03-17 17:30:14 +01001112 f_ctrl_get_exp(IPA_CTRL, "mcc", "001");
1113 f_ctrl_get_exp(IPA_CTRL, "mnc", "01");
Harald Welte44bdaa52017-12-17 17:01:47 +01001114 f_ctrl_get_exp(IPA_CTRL, "number-of-bts", "3");
Harald Welte4003d112017-12-09 22:35:39 +01001115
1116 var integer bts_nr := 0;
1117 f_ctrl_get_exp_bts(IPA_CTRL, bts_nr, "location-area-code", "1");
1118 f_ctrl_get_exp_bts(IPA_CTRL, bts_nr, "cell-identity", "0");
1119 f_ctrl_get_exp_bts(IPA_CTRL, bts_nr, "oml-connection-state", "connected");
1120 f_ctrl_get_exp_bts(IPA_CTRL, bts_nr, "gprs-mode", "gprs");
1121 f_ctrl_get_exp_bts(IPA_CTRL, bts_nr, "rf_state", "operational,unlocked,on");
1122 f_ctrl_get_exp_trx(IPA_CTRL, bts_nr, 0, "arfcn", "871");
1123 f_ctrl_get_exp_trx(IPA_CTRL, bts_nr, 0, "max-power-reduction", "20");
1124
1125 var integer uptime := str2int(f_ctrl_get_bts(IPA_CTRL, bts_nr, "oml-uptime"));
1126 f_sleep(2.0);
1127 if (str2int(f_ctrl_get_bts(IPA_CTRL, bts_nr, "oml-uptime")) < uptime+1) {
1128 setverdict(fail, "oml-uptime not incrementing as expected");
1129 }
1130 /* TODO: Disconnect RSL, imply that OML is disconnected and check for uptime zero? */
1131
1132 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bsc", 0, "paging:attempted", 0);
1133
1134 setverdict(pass);
Harald Welte96c94412017-12-09 03:12:45 +01001135}
1136
Harald Welte6f521d82017-12-11 19:52:02 +01001137function f_bssap_tx_ud(template PDU_BSSAP bssap) runs on test_CT {
Harald Weltea4ca4462018-02-09 00:17:14 +01001138 BSSAP.send(ts_BSSAP_UNITDATA_req(g_bssap.sccp_addr_peer, g_bssap.sccp_addr_own, bssap));
Harald Welte6f521d82017-12-11 19:52:02 +01001139}
1140
1141
1142/***********************************************************************
1143 * Paging Testing
1144 ***********************************************************************/
1145
1146type record Cell_Identity {
1147 GsmMcc mcc,
1148 GsmMnc mnc,
1149 GsmLac lac,
1150 GsmCellId ci
1151};
Harald Welte24135bd2018-03-17 19:27:53 +01001152private const Cell_Identity cid := { '001'H, '01'H, 1, 0 };
Stefan Sperling049a86e2018-03-20 15:51:00 +01001153private const Cell_Identity unknown_cid := { '678'H, 'f90'H, 1, 0 };
Harald Welte6f521d82017-12-11 19:52:02 +01001154
Harald Welte5d1a2202017-12-13 19:51:29 +01001155type set of integer BtsIdList;
1156
1157private function f_bts_in_list(integer bts_id, BtsIdList bts_ids) return boolean {
1158 for (var integer j := 0; j < sizeof(bts_ids); j := j + 1) {
1159 if (bts_id == bts_ids[j]) {
1160 return true;
1161 }
1162 }
1163 return false;
1164}
Harald Welte6f521d82017-12-11 19:52:02 +01001165
1166/* core paging test helper function; used by most paging test cases */
1167private function f_pageing_helper(hexstring imsi,
1168 template BSSMAP_FIELD_CellIdentificationList cid_list,
Harald Welte5d1a2202017-12-13 19:51:29 +01001169 BtsIdList bts_ids := { 0 },
Harald Welte6f521d82017-12-11 19:52:02 +01001170 template RSL_ChanNeeded rsl_chneed := omit,
1171 template OCT4 tmsi := omit) runs on test_CT
1172{
1173 var template BSSMAP_IE_ChannelNeeded bssmap_chneed;
1174 var MobileIdentity mi;
1175 var template octetstring id_enc; /* FIXME */
1176 var RSL_Message rx_rsl;
1177 var integer paging_group := hex2int(imsi[lengthof(imsi)-1]);
Harald Welte5d1a2202017-12-13 19:51:29 +01001178 var integer i;
Harald Welte6f521d82017-12-11 19:52:02 +01001179
1180 f_init();
Harald Welte6f521d82017-12-11 19:52:02 +01001181
1182 /* Clear the queue, it might still contain stuff like BCCH FILLING */
Harald Weltec3068592018-03-17 19:55:31 +01001183 for (i := 0; i < NUM_BTS; i := i + 1) {
1184 IPA_RSL[i].clear;
Harald Welte5d1a2202017-12-13 19:51:29 +01001185 }
Harald Welte6f521d82017-12-11 19:52:02 +01001186
1187 if (isvalue(rsl_chneed)) {
1188 /* The values of 08.08 3.2.2.36 and 08.58 9.3.40 are luckily identical */
1189 bssmap_chneed := ts_BSSMAP_IE_ChanNeeded(int2bit(enum2int(valueof(rsl_chneed)),2));
1190 } else {
1191 bssmap_chneed := omit;
1192 }
1193
1194 f_bssap_tx_ud(ts_BSSMAP_Paging(imsi, cid_list, tmsi, bssmap_chneed));
1195
1196/* FIXME: Disabled due to bugs in both GSM_RR_Types and MobileL3_CommonIE_Types IMSI encoder
1197 if (isvalue(tmsi)) {
1198 mi := valueof(t_Osmo_MI_TMSI(oct2int(valueof(tmsi))));
1199 } else {
1200 mi := valueof(ts_Osmo_MI_IMSI(imsi));
1201 }
1202 id_enc := enc_MobileIdentity(mi);
1203*/
1204 id_enc := ?;
Harald Welte5d1a2202017-12-13 19:51:29 +01001205 for (i := 0; i < sizeof(bts_ids); i := i + 1) {
1206 rx_rsl := f_exp_ipa_rx(bts_ids[i], tr_RSL_PAGING_CMD(id_enc));
1207 /* check channel type, paging group */
1208 if (rx_rsl.ies[1].body.paging_group != paging_group) {
1209 setverdict(fail, "Paging for wrong paging group");
1210 }
1211 if (ispresent(rsl_chneed) and
1212 rx_rsl.ies[3].body.chan_needed.chan_needed != valueof(rsl_chneed)) {
1213 setverdict(fail, "RSL Channel Needed != BSSMAP Channel Needed");
1214 }
Harald Welte6f521d82017-12-11 19:52:02 +01001215 }
Harald Welte2fccd982018-01-31 15:48:19 +01001216 f_sleep(2.0);
Harald Welte5d1a2202017-12-13 19:51:29 +01001217 /* do a quick check on all not-included BTSs if they received paging */
1218 for (i := 0; i < NUM_BTS; i := i + 1) {
1219 timer T := 0.1;
1220 if (f_bts_in_list(i, bts_ids)) {
1221 continue;
1222 }
1223 T.start;
1224 alt {
1225 [] IPA_RSL[i].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0, tr_RSL_PAGING_CMD(id_enc))) {
1226 setverdict(fail, "Paging on BTS ", i, " which is not part of ", bts_ids);
1227 }
1228 [] IPA_RSL[i].receive { repeat; }
1229 [] T.timeout { }
1230 }
Harald Welte6f521d82017-12-11 19:52:02 +01001231 }
1232
1233 setverdict(pass);
1234}
1235
Harald Welte5d1a2202017-12-13 19:51:29 +01001236const BtsIdList c_BtsId_all := { 0, 1, 2 };
Harald Welte751d3eb2018-01-31 15:51:06 +01001237const BtsIdList c_BtsId_none := { };
Harald Welte5d1a2202017-12-13 19:51:29 +01001238const BtsIdList c_BtsId_LAC1 := { 0, 1 };
1239const BtsIdList c_BtsId_LAC2 := { 2 };
1240
Harald Welte6f521d82017-12-11 19:52:02 +01001241/* PAGING by IMSI + TMSI */
1242testcase TC_paging_imsi_nochan() runs on test_CT {
1243 var BSSMAP_FIELD_CellIdentificationList cid_list;
1244 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Philipp Maier8c04b0a2018-02-23 13:48:48 +01001245 f_pageing_helper('001010100000001'H, cid_list, c_BtsId_all, omit, omit);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001246 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001247}
1248
1249/* PAGING by IMSI + TMSI */
1250testcase TC_paging_tmsi_nochan() runs on test_CT {
1251 var BSSMAP_FIELD_CellIdentificationList cid_list;
1252 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01001253 f_pageing_helper('001010100000001'H, cid_list, c_BtsId_all, omit, 'A1B2C301'O);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001254 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001255}
1256
1257/* Paging with different "channel needed' values */
1258testcase TC_paging_tmsi_any() runs on test_CT {
1259 var BSSMAP_FIELD_CellIdentificationList cid_list;
1260 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01001261 f_pageing_helper('001010100000002'H, cid_list, c_BtsId_all, RSL_CHANNEED_ANY, 'A1B2C302'O);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001262 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001263}
1264testcase TC_paging_tmsi_sdcch() runs on test_CT {
1265 var BSSMAP_FIELD_CellIdentificationList cid_list;
1266 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01001267 f_pageing_helper('001010100000003'H, cid_list, c_BtsId_all, RSL_CHANNEED_SDCCH, 'A1B2C303'O);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001268 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001269}
1270testcase TC_paging_tmsi_tch_f() runs on test_CT {
1271 var BSSMAP_FIELD_CellIdentificationList cid_list;
1272 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01001273 f_pageing_helper('001010000000004'H, cid_list, c_BtsId_all, RSL_CHANNEED_TCH_F, 'A1B2C304'O);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001274 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001275}
1276testcase TC_paging_tmsi_tch_hf() runs on test_CT {
1277 var BSSMAP_FIELD_CellIdentificationList cid_list;
1278 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01001279 f_pageing_helper('001010000000005'H, cid_list, c_BtsId_all, RSL_CHANNEED_TCH_ForH, 'A1B2C305'O);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001280 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001281}
1282
1283/* Paging by CGI */
1284testcase TC_paging_imsi_nochan_cgi() runs on test_CT {
1285 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1286 cid_list := { cIl_CGI := { ts_BSSMAP_CI_CGI(cid.mcc, cid.mnc, cid.lac, cid.ci) } };
Harald Welte5d1a2202017-12-13 19:51:29 +01001287 f_pageing_helper('001010000000006'H, cid_list, { 0 });
Philipp Maier282ca4b2018-02-27 17:17:00 +01001288 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001289}
1290
1291/* Paging by LAC+CI */
1292testcase TC_paging_imsi_nochan_lac_ci() runs on test_CT {
1293 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1294 cid_list := { cIl_LAC_CI := { ts_BSSMAP_CI_LAC_CI(cid.lac, cid.ci) } };
Harald Welte5d1a2202017-12-13 19:51:29 +01001295 f_pageing_helper('001010000000007'H, cid_list, { 0 });
Philipp Maier282ca4b2018-02-27 17:17:00 +01001296 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001297}
1298
1299/* Paging by CI */
1300testcase TC_paging_imsi_nochan_ci() runs on test_CT {
1301 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1302 cid_list := { cIl_CI := { ts_BSSMAP_CI_CI(cid.ci) } };
Harald Welte5d1a2202017-12-13 19:51:29 +01001303 f_pageing_helper('001010000000008'H, cid_list, { 0 });
Philipp Maier282ca4b2018-02-27 17:17:00 +01001304 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001305}
1306
1307/* Paging by LAI */
1308testcase TC_paging_imsi_nochan_lai() runs on test_CT {
1309 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1310 cid_list := { cIl_LAI := { ts_BSSMAP_CI_LAI(cid.mcc, cid.mnc, cid.lac) } };
Harald Welte5d1a2202017-12-13 19:51:29 +01001311 f_pageing_helper('001010000000009'H, cid_list, c_BtsId_LAC1);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001312 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001313}
1314
1315/* Paging by LAC */
1316testcase TC_paging_imsi_nochan_lac() runs on test_CT {
1317 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1318 cid_list := { cIl_LAC := { ts_BSSMAP_CI_LAC(cid.lac) } };
Harald Welte5d1a2202017-12-13 19:51:29 +01001319 f_pageing_helper('001010000000010'H, cid_list, c_BtsId_LAC1);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001320 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001321}
1322
1323/* Paging by "all in BSS" */
1324testcase TC_paging_imsi_nochan_all() runs on test_CT {
1325 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1326 cid_list := { cIl_allInBSS := ''O };
Harald Welte5d1a2202017-12-13 19:51:29 +01001327 f_pageing_helper('001010000000011'H, cid_list, c_BtsId_all);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001328 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001329}
1330
Stefan Sperling7b5e1782018-03-20 19:32:43 +01001331/* Paging by PLMN+LAC+RNC; We do not implement this; Verify nothing is paged */
Harald Welte751d3eb2018-01-31 15:51:06 +01001332testcase TC_paging_imsi_nochan_plmn_lac_rnc() runs on test_CT {
1333 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1334 cid_list := { cIl_PLMN_LAC_RNC := { ts_BSSMAP_CI_PLMN_LAC_RNC(cid.mcc, cid.mnc, cid.lac, 12) } };
Stefan Sperling7b5e1782018-03-20 19:32:43 +01001335 f_pageing_helper('001010000000012'H, cid_list, c_BtsId_none);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001336 f_shutdown_helper();
Harald Welte751d3eb2018-01-31 15:51:06 +01001337}
Harald Welte6f521d82017-12-11 19:52:02 +01001338
Stefan Sperling7b5e1782018-03-20 19:32:43 +01001339/* Paging by RNC; We do not implement this; Verify nothing is paged */
Harald Welte751d3eb2018-01-31 15:51:06 +01001340testcase TC_paging_imsi_nochan_rnc() runs on test_CT {
1341 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1342 cid_list := { cIl_RNC := { int2oct(13, 2) } };
Stefan Sperling7b5e1782018-03-20 19:32:43 +01001343 f_pageing_helper('001010000000013'H, cid_list, c_BtsId_none);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001344 f_shutdown_helper();
Harald Welte751d3eb2018-01-31 15:51:06 +01001345}
1346
Stefan Sperling7b5e1782018-03-20 19:32:43 +01001347/* Paging by LAC+RNC; We do not implement; Verify nothing is paged */
Harald Welte751d3eb2018-01-31 15:51:06 +01001348testcase TC_paging_imsi_nochan_lac_rnc() runs on test_CT {
1349 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1350 cid_list := { cIl_LAC_RNC := { ts_BSSMAP_CI_LAC_RNC(cid.lac, 14) } };
Stefan Sperling7b5e1782018-03-20 19:32:43 +01001351 f_pageing_helper('001010000000014'H, cid_list, c_BtsId_none);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001352 f_shutdown_helper();
Harald Welte751d3eb2018-01-31 15:51:06 +01001353}
1354
Harald Welte6f521d82017-12-11 19:52:02 +01001355/* Paging on multiple cells (multiple entries in list): Verify all of them page */
Harald Welte751d3eb2018-01-31 15:51:06 +01001356testcase TC_paging_imsi_nochan_lacs() runs on test_CT {
1357 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1358 cid_list := { cIl_LAC := { ts_BSSMAP_CI_LAC(1), ts_BSSMAP_CI_LAC(2) } };
1359 f_pageing_helper('001010000000015'H, cid_list, c_BtsId_all);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001360 f_shutdown_helper();
Harald Welte751d3eb2018-01-31 15:51:06 +01001361}
1362
1363/* Paging on empty list: Verify none of them page */
1364testcase TC_paging_imsi_nochan_lacs_empty() runs on test_CT {
1365 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1366 cid_list := { cIl_LAC := { } };
1367 f_pageing_helper('001010000000016'H, cid_list, c_BtsId_none);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001368 f_shutdown_helper();
Harald Welte751d3eb2018-01-31 15:51:06 +01001369}
1370
Stefan Sperling049a86e2018-03-20 15:51:00 +01001371/* Paging by CGI with unknown MCC/MNC: Verify nothing is paged. */
1372testcase TC_paging_imsi_nochan_cgi_unknown_cid() runs on test_CT {
1373 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1374 cid_list := { cIl_CGI := { ts_BSSMAP_CI_CGI(unknown_cid.mcc, unknown_cid.mnc, unknown_cid.lac, unknown_cid.ci) } };
1375 f_pageing_helper('001010000000006'H, cid_list, c_BtsId_none);
1376 f_shutdown_helper();
1377}
1378
Harald Welte6f521d82017-12-11 19:52:02 +01001379/* Verify paging retransmission interval + count */
1380/* Verify paging stops after channel establishment */
Harald Welte6f521d82017-12-11 19:52:02 +01001381/* Test behavior under paging overload */
Harald Welteae026692017-12-09 01:03:01 +01001382
Harald Weltee65d40e2017-12-13 00:09:06 +01001383/* Verify PCH load */
1384testcase TC_paging_imsi_load() runs on test_CT {
1385 var BSSMAP_FIELD_CellIdentificationList cid_list;
1386 timer T := 4.0;
Harald Welte2caa1062018-03-17 18:19:05 +01001387 timer T_retrans := 1.0;
Harald Weltee65d40e2017-12-13 00:09:06 +01001388 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01001389 f_pageing_helper('001010123456789'H, cid_list, c_BtsId_all);
Harald Weltee65d40e2017-12-13 00:09:06 +01001390
1391 /* tell BSC there is no paging space anymore */
1392 f_ipa_tx(0, ts_RSL_PAGING_LOAD_IND(0));
Harald Welte3b57ab52018-03-17 18:01:10 +01001393 f_sleep(0.2);
1394 IPA_RSL[0].clear;
Harald Weltee65d40e2017-12-13 00:09:06 +01001395
1396 /* Wait for 4 seconds if any more PAGING CMD are received on RSL. Normally,
1397 * there would be 8 retransmissions during 4 seconds */
1398 T.start;
Harald Welte2caa1062018-03-17 18:19:05 +01001399 T_retrans.start;
Harald Weltee65d40e2017-12-13 00:09:06 +01001400 alt {
1401 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0, tr_RSL_PAGING_CMD(?))) {
1402 setverdict(fail, "Received PAGING after LOAD_IND(0)");
Daniel Willmannafce8662018-07-06 23:11:32 +02001403 mtc.stop;
Harald Weltee65d40e2017-12-13 00:09:06 +01001404 }
Harald Welte2caa1062018-03-17 18:19:05 +01001405 [] T_retrans.timeout {
1406 /* re-trnsmit the zero-space LOAD IND to avoid BSC 'auto credit' */
1407 f_ipa_tx(0, ts_RSL_PAGING_LOAD_IND(0));
1408 T_retrans.start;
1409 repeat;
1410 }
Harald Weltee65d40e2017-12-13 00:09:06 +01001411 [] T.timeout {
1412 setverdict(pass);
1413 }
1414 }
Philipp Maier282ca4b2018-02-27 17:17:00 +01001415
1416 f_shutdown_helper();
Harald Weltee65d40e2017-12-13 00:09:06 +01001417}
1418
Harald Welte235ebf12017-12-15 14:18:16 +01001419/* Verify Paging Counter */
Harald Welte1ff69992017-12-14 12:31:17 +01001420testcase TC_paging_counter() runs on test_CT {
1421 var BSSMAP_FIELD_CellIdentificationList cid_list;
1422 timer T := 4.0;
1423 var integer i;
1424 var integer paging_attempted_bsc;
1425 var integer paging_attempted_bts[NUM_BTS];
1426 var integer paging_expired_bts[NUM_BTS];
1427 cid_list := valueof(ts_BSSMAP_CIL_noCell);
1428
1429 f_init();
1430
1431 /* read counters before paging */
1432 paging_attempted_bsc := f_ctrl_get_ratectr_abs(IPA_CTRL, "bsc", 0, "paging:attempted");
1433 for (i := 0; i < NUM_BTS; i := i+1) {
1434 paging_attempted_bts[i] := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", i, "paging:attempted");
1435 paging_expired_bts[i] := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", i, "paging:expired");
1436 }
1437
1438 f_pageing_helper('001230000000001'H, cid_list, c_BtsId_all);
1439
1440 /* expect the attempted pages on BSC and each BTSs to have incremented by one */
1441 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bsc", 0, "paging:attempted", paging_attempted_bsc+1);
1442 for (i := 0; i < NUM_BTS; i := i+1) {
1443 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", i, "paging:attempted",
1444 paging_attempted_bts[i]+1);
1445 }
1446
1447 /* assume that 12s later the paging on all BTSs have expired and hence incremented by 1 */
1448 f_sleep(12.0);
1449 for (i := 0; i < NUM_BTS; i := i+1) {
1450 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", i, "paging:expired",
1451 paging_expired_bts[i]+1);
1452 }
Harald Welte1ff69992017-12-14 12:31:17 +01001453
Philipp Maier282ca4b2018-02-27 17:17:00 +01001454 f_shutdown_helper();
Harald Welte1ff69992017-12-14 12:31:17 +01001455}
1456
1457
Harald Welte10985002017-12-12 09:29:15 +01001458/* Verify paging stops after A-RESET */
1459testcase TC_paging_imsi_a_reset() runs on test_CT {
1460 var BSSMAP_FIELD_CellIdentificationList cid_list;
1461 timer T := 3.0;
1462 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01001463 f_pageing_helper('001010123456789'H, cid_list, c_BtsId_all);
Harald Welte10985002017-12-12 09:29:15 +01001464
1465 /* Perform a BSSMAP Reset and wait for ACK */
Harald Weltea4ca4462018-02-09 00:17:14 +01001466 BSSAP.send(ts_BSSAP_UNITDATA_req(g_bssap.sccp_addr_peer, g_bssap.sccp_addr_own, ts_BSSMAP_Reset(0)));
Harald Welte10985002017-12-12 09:29:15 +01001467 alt {
Harald Weltea4ca4462018-02-09 00:17:14 +01001468 [] BSSAP.receive(tr_BSSAP_UNITDATA_ind(g_bssap.sccp_addr_own, g_bssap.sccp_addr_peer, tr_BSSMAP_ResetAck)) { }
Harald Welte10985002017-12-12 09:29:15 +01001469 [] BSSAP.receive { repeat; }
1470 }
1471
Daniel Willmanncbef3982018-07-30 09:22:40 +02001472 /* Wait to avoid a possible race condition if a paging message is
1473 * received right before the reset ACK. */
1474 f_sleep(0.2);
1475
Harald Welte10985002017-12-12 09:29:15 +01001476 /* Clear the queue, it might still contain stuff like BCCH FILLING */
Philipp Maier1e6b4422018-02-23 14:02:13 +01001477 for (var integer i := 0; i < sizeof(IPA_RSL); i := i+1) {
1478 IPA_RSL[i].clear;
1479 }
Harald Welte10985002017-12-12 09:29:15 +01001480
1481 /* Wait for 3 seconds if any more PAGING CMD are received on RSL */
1482 T.start;
1483 alt {
1484 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0, tr_RSL_PAGING_CMD(?))) {
1485 setverdict(fail, "Received PAGING after A-RESET");
Daniel Willmannafce8662018-07-06 23:11:32 +02001486 mtc.stop;
Harald Welte10985002017-12-12 09:29:15 +01001487 }
Harald Welte5d1a2202017-12-13 19:51:29 +01001488 [] IPA_RSL[1].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0, tr_RSL_PAGING_CMD(?))) {
1489 setverdict(fail, "Received PAGING after A-RESET");
Daniel Willmannafce8662018-07-06 23:11:32 +02001490 mtc.stop;
Harald Welte5d1a2202017-12-13 19:51:29 +01001491 }
1492 [] IPA_RSL[2].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0, tr_RSL_PAGING_CMD(?))) {
1493 setverdict(fail, "Received PAGING after A-RESET");
Daniel Willmannafce8662018-07-06 23:11:32 +02001494 mtc.stop;
Harald Welte5d1a2202017-12-13 19:51:29 +01001495 }
Harald Welte10985002017-12-12 09:29:15 +01001496 [] T.timeout {
1497 setverdict(pass);
1498 }
1499 }
Philipp Maier282ca4b2018-02-27 17:17:00 +01001500
1501 f_shutdown_helper();
Harald Welte10985002017-12-12 09:29:15 +01001502}
Harald Welteae026692017-12-09 01:03:01 +01001503
Pau Espin Pedrol3466cc52018-11-05 12:41:05 +01001504/* Verify how we handle unsolicited Paging Response, for instance because we
1505 * receive a Paging Response after T3113 expired (and subscriber information was
1506 * dropped). See OS#3680.
1507 */
1508testcase TC_paging_resp_unsol() runs on test_CT {
1509
1510 f_init(1);
1511
1512 var BSSAP_N_CONNECT_ind rx_c_ind;
1513 var DchanTuple dt;
1514 var PDU_ML3_MS_NW l3 := valueof(ts_PAG_RESP(valueof(ts_MI_IMSI_LV('001010008880018'H))));
1515
1516 /* Send CHAN RQD and wait for allocation; acknowledge it */
1517 dt.rsl_chan_nr := f_chreq_act_ack();
1518
1519 /* Send unsolicited Paging response (no matching Paging CMD stored in BSC) */
1520 f_ipa_tx(0, ts_RSL_EST_IND(dt.rsl_chan_nr, valueof(ts_RslLinkID_DCCH(0)), enc_PDU_ML3_MS_NW(l3)));
1521
1522 /* expect BSC to disable the channel */
Pau Espin Pedrol5ee6f6c2018-12-07 12:07:43 +01001523 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
Pau Espin Pedrol3466cc52018-11-05 12:41:05 +01001524 setverdict(pass);
1525
1526}
1527
Harald Welte4e9b9cc2017-12-14 18:31:02 +01001528/* Test RSL link drop causes counter increment */
1529testcase TC_rsl_drop_counter() runs on test_CT {
1530 var integer rsl_fail;
1531
Harald Welte89d42e82017-12-17 16:42:41 +01001532 f_init(1);
Harald Welte4e9b9cc2017-12-14 18:31:02 +01001533
1534 rsl_fail := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "rsl_fail");
1535
1536 bts[0].rsl.vc_IPA.stop;
1537
1538 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "rsl_fail", rsl_fail+1);
1539
1540 setverdict(pass);
1541}
1542
1543/* TODO: Test OML link drop causes counter increment */
1544
Stefan Sperling830dc9d2018-02-12 21:08:28 +01001545/* The body of TC_rsl_unknown_unit_id() and TC_oml_unknown_unit_id() tests. */
1546function f_ipa_unknown_unit_id(integer mp_bsc_ipa_port) runs on test_CT return boolean {
1547 timer T := 10.0;
1548
1549 bts[0].rsl.id := "IPA-0-RSL";
1550 bts[0].rsl.vc_IPA := IPA_Emulation_CT.create(bts[0].rsl.id & "-IPA");
1551 bts[0].rsl.ccm_pars := c_IPA_default_ccm_pars;
1552 bts[0].rsl.ccm_pars.name := "Osmocom TTCN-3 BTS Simulator";
1553 bts[0].rsl.ccm_pars.unit_id := "0/0/0"; /* value which is unknown at BTS */
1554
Stefan Sperling830dc9d2018-02-12 21:08:28 +01001555 f_ipa_ctrl_start(mp_bsc_ip, mp_bsc_ctrl_port);
1556
1557 f_init_mgcp("VirtMSC");
1558
1559 /* start RSL/OML connection (XXX re-uses RSL port/protocol definitions for OML) */
1560 map(bts[0].rsl.vc_IPA:IPA_PORT, system:IPA);
1561 connect(bts[0].rsl.vc_IPA:IPA_RSL_PORT, self:IPA_RSL[0]);
1562 bts[0].rsl.vc_IPA.start(IPA_Emulation.main_client(mp_bsc_ip, mp_bsc_ipa_port, "", 10000, bts[0].rsl.ccm_pars));
1563
1564 /* wait for IPA OML link to connect and then disconnect */
1565 T.start;
1566 alt {
1567 [] IPA_RSL[0].receive(ASP_IPA_Event:{up_down := ASP_IPA_EVENT_DOWN}) {
1568 T.stop;
1569 return true;
1570 }
1571 [] IPA_RSL[0].receive { repeat }
1572 [] T.timeout {
Daniel Willmannafce8662018-07-06 23:11:32 +02001573 return false;
Stefan Sperling830dc9d2018-02-12 21:08:28 +01001574 }
1575 }
Stefan Sperling830dc9d2018-02-12 21:08:28 +01001576 return false;
1577}
1578
1579/* BSC should close an RSL connection from a BTS with unknown unit ID (OS#2714). */
1580testcase TC_rsl_unknown_unit_id() runs on test_CT {
1581 if (f_ipa_unknown_unit_id(mp_bsc_rsl_port)) {
1582 setverdict(pass);
1583 } else {
1584 setverdict(fail, "Timeout RSL waiting for connection to close");
1585 }
1586}
1587
1588
1589/* BSC should close an RSL connection from a BTS with unknown unit ID (OS#2714). */
1590testcase TC_oml_unknown_unit_id() runs on test_CT {
1591 if (f_ipa_unknown_unit_id(mp_bsc_oml_port)) {
1592 setverdict(pass);
1593 } else {
1594 setverdict(fail, "Timeout OML waiting for connection to close");
1595 }
1596}
1597
1598
Harald Weltec1a2fff2017-12-17 11:06:19 +01001599/***********************************************************************
1600 * "New world" test cases using RSL_Emulation + BSSMAP_Emulation
1601 ***********************************************************************/
1602
1603import from BSSMAP_Emulation all;
1604import from RSL_Emulation all;
1605import from MSC_ConnectionHandler all;
1606
1607type function void_fn(charstring id) runs on MSC_ConnHdlr;
1608
Harald Welte336820c2018-05-31 20:34:52 +02001609/* helper function to create and connect a MSC_ConnHdlr component */
Harald Welteff579f92018-05-31 22:19:39 +02001610private function f_connect_handler(inout MSC_ConnHdlr vc_conn) runs on test_CT {
Harald Weltea4ca4462018-02-09 00:17:14 +01001611 connect(vc_conn:BSSMAPEM, g_bssap.vc_BSSMAP:PROC);
Daniel Willmann191e0d92018-01-17 12:44:35 +01001612 connect(vc_conn:MGCP_PROC, vc_MGCP:MGCP_PROC);
Harald Weltec1a2fff2017-12-17 11:06:19 +01001613 connect(vc_conn:RSL, bts[0].rsl.vc_RSL:CLIENT_PT);
Harald Weltef70df652018-01-29 22:00:23 +01001614 connect(vc_conn:RSL_PROC, bts[0].rsl.vc_RSL:RSL_PROC);
Philipp Maier88f4ae82018-03-01 14:00:58 +01001615 if (isvalue(bts[1])) {
Philipp Maier956a92f2018-02-16 10:58:07 +01001616 connect(vc_conn:RSL1, bts[1].rsl.vc_RSL:CLIENT_PT);
1617 connect(vc_conn:RSL1_PROC, bts[1].rsl.vc_RSL:RSL_PROC);
1618 }
Harald Weltea4ca4462018-02-09 00:17:14 +01001619 connect(vc_conn:BSSAP, g_bssap.vc_BSSMAP:CLIENT);
Daniel Willmann191e0d92018-01-17 12:44:35 +01001620 connect(vc_conn:MGCP, vc_MGCP:MGCP_CLIENT);
Harald Welte336820c2018-05-31 20:34:52 +02001621}
1622
1623function f_start_handler(void_fn fn, template (omit) TestHdlrParams pars := omit)
1624runs on test_CT return MSC_ConnHdlr {
1625 var charstring id := testcasename();
1626 var MSC_ConnHdlr vc_conn;
1627 vc_conn := MSC_ConnHdlr.create(id);
1628 f_connect_handler(vc_conn);
Harald Weltea0630032018-03-20 21:09:55 +01001629 vc_conn.start(f_handler_init(fn, id, pars));
Harald Weltec1a2fff2017-12-17 11:06:19 +01001630 return vc_conn;
1631}
1632
Harald Weltea0630032018-03-20 21:09:55 +01001633/* first function inside ConnHdlr component; sets g_pars + starts function */
1634private function f_handler_init(void_fn fn, charstring id, template (omit) TestHdlrParams pars := omit)
1635runs on MSC_ConnHdlr {
1636 if (isvalue(pars)) {
1637 g_pars := valueof(pars);
1638 }
1639 fn.apply(id);
1640}
1641
Harald Welte3c86ea02018-05-10 22:28:05 +02001642/* Establish signalling channel (non-assignment case) followed by cipher mode */
1643private function f_tc_ciph_mode_a5(charstring id) runs on MSC_ConnHdlr {
Harald Welteed848512018-05-24 22:27:58 +02001644 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
1645 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte3c86ea02018-05-10 22:28:05 +02001646 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelTypeSIGNAL);
Philipp Maier23000732018-05-18 11:25:37 +02001647 ass_cmd.pdu.bssmap.assignmentRequest.circuitIdentityCode := omit;
1648 ass_cmd.pdu.bssmap.assignmentRequest.aoIPTransportLayer := omit;
1649 exp_compl.pdu.bssmap.assignmentComplete.circuitIdentityCode := omit;
1650 exp_compl.pdu.bssmap.assignmentComplete.aoIPTransportLayer := omit;
Harald Welte3c86ea02018-05-10 22:28:05 +02001651
Philipp Maier23000732018-05-18 11:25:37 +02001652 f_establish_fully(ass_cmd, exp_compl);
Harald Welte3c86ea02018-05-10 22:28:05 +02001653}
1654testcase TC_ciph_mode_a5_0() runs on test_CT {
1655 var MSC_ConnHdlr vc_conn;
Philipp Maier48604732018-10-09 15:00:37 +02001656 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte3c86ea02018-05-10 22:28:05 +02001657 pars.encr := valueof(t_EncrParams('01'O, f_rnd_octstring(8)));
1658
1659 f_init(1, true);
1660 f_sleep(1.0);
1661 vc_conn := f_start_handler(refers(f_tc_ciph_mode_a5), pars);
1662 vc_conn.done;
1663}
1664testcase TC_ciph_mode_a5_1() runs on test_CT {
1665 var MSC_ConnHdlr vc_conn;
Philipp Maier48604732018-10-09 15:00:37 +02001666 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte3c86ea02018-05-10 22:28:05 +02001667 pars.encr := valueof(t_EncrParams('02'O, f_rnd_octstring(8)));
1668
1669 f_init(1, true);
1670 f_sleep(1.0);
1671 vc_conn := f_start_handler(refers(f_tc_ciph_mode_a5), pars);
1672 vc_conn.done;
1673}
1674testcase TC_ciph_mode_a5_3() runs on test_CT {
1675 var MSC_ConnHdlr vc_conn;
Philipp Maier48604732018-10-09 15:00:37 +02001676 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte3c86ea02018-05-10 22:28:05 +02001677 pars.encr := valueof(t_EncrParams('08'O, f_rnd_octstring(8)));
1678
1679 f_init(1, true);
1680 f_sleep(1.0);
1681 vc_conn := f_start_handler(refers(f_tc_ciph_mode_a5), pars);
1682 vc_conn.done;
1683}
1684
1685
1686/* establish initial channel, enable ciphering followed by assignment to ciphered channel */
Harald Welte651fcdc2018-05-10 20:23:16 +02001687private function f_tc_assignment_fr_a5(charstring id) runs on MSC_ConnHdlr {
Harald Welteed848512018-05-24 22:27:58 +02001688 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
1689 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Weltec1a2fff2017-12-17 11:06:19 +01001690
Harald Welte552620d2017-12-16 23:21:36 +01001691 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
1692 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
Harald Welte73cd2712017-12-17 00:44:52 +01001693
Harald Weltea0630032018-03-20 21:09:55 +01001694 f_establish_fully(ass_cmd, exp_compl);
Harald Welte552620d2017-12-16 23:21:36 +01001695}
Harald Welte552620d2017-12-16 23:21:36 +01001696testcase TC_assignment_fr_a5_0() runs on test_CT {
1697 var MSC_ConnHdlr vc_conn;
Philipp Maier48604732018-10-09 15:00:37 +02001698 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte651fcdc2018-05-10 20:23:16 +02001699 pars.encr := valueof(t_EncrParams('01'O, f_rnd_octstring(8)));
Harald Welte552620d2017-12-16 23:21:36 +01001700
Harald Welte89d42e82017-12-17 16:42:41 +01001701 f_init(1, true);
Harald Welte552620d2017-12-16 23:21:36 +01001702 f_sleep(1.0);
Harald Welte651fcdc2018-05-10 20:23:16 +02001703 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5), pars);
Harald Welte552620d2017-12-16 23:21:36 +01001704 vc_conn.done;
1705}
Harald Welte552620d2017-12-16 23:21:36 +01001706testcase TC_assignment_fr_a5_1() runs on test_CT {
Harald Weltec1a2fff2017-12-17 11:06:19 +01001707 var MSC_ConnHdlr vc_conn;
Philipp Maier48604732018-10-09 15:00:37 +02001708 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte651fcdc2018-05-10 20:23:16 +02001709 pars.encr := valueof(t_EncrParams('02'O, f_rnd_octstring(8)));
Harald Weltec1a2fff2017-12-17 11:06:19 +01001710
Harald Welte89d42e82017-12-17 16:42:41 +01001711 f_init(1, true);
Harald Weltec1a2fff2017-12-17 11:06:19 +01001712 f_sleep(1.0);
Harald Welte651fcdc2018-05-10 20:23:16 +02001713 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5), pars);
1714 vc_conn.done;
1715}
1716testcase TC_assignment_fr_a5_3() runs on test_CT {
1717 var MSC_ConnHdlr vc_conn;
Philipp Maier48604732018-10-09 15:00:37 +02001718 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte651fcdc2018-05-10 20:23:16 +02001719 pars.encr := valueof(t_EncrParams('08'O, f_rnd_octstring(8)));
Harald Weltec1a2fff2017-12-17 11:06:19 +01001720
Harald Welte651fcdc2018-05-10 20:23:16 +02001721 f_init(1, true);
1722 f_sleep(1.0);
1723 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5), pars);
Harald Weltec1a2fff2017-12-17 11:06:19 +01001724 vc_conn.done;
1725}
1726
Harald Welte552620d2017-12-16 23:21:36 +01001727/* Expect ASSIGNMENT FAIL if mandatory IE is missing */
1728private function f_tc_assignment_fr_a5_1_codec_missing(charstring id) runs on MSC_ConnHdlr {
Philipp Maier48604732018-10-09 15:00:37 +02001729 g_pars := f_gen_test_hdlr_pars();
Harald Welte552620d2017-12-16 23:21:36 +01001730 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
Harald Welteed848512018-05-24 22:27:58 +02001731 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte552620d2017-12-16 23:21:36 +01001732 const OCT8 kc := '0001020304050607'O;
1733
1734 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02001735 /* Omit: ass_cmd.pdu.bssmap.assignmentRequest.codecList */
1736
Harald Weltea0630032018-03-20 21:09:55 +01001737 f_establish_fully(ass_cmd, exp_fail);
Harald Welte552620d2017-12-16 23:21:36 +01001738}
Harald Welte552620d2017-12-16 23:21:36 +01001739testcase TC_assignment_fr_a5_1_codec_missing() runs on test_CT {
1740 var MSC_ConnHdlr vc_conn;
1741
Harald Welte89d42e82017-12-17 16:42:41 +01001742 f_init(1, true);
Harald Welte552620d2017-12-16 23:21:36 +01001743 f_sleep(1.0);
1744
Harald Welte8863fa12018-05-10 20:15:27 +02001745 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5_1_codec_missing));
Harald Welte552620d2017-12-16 23:21:36 +01001746 vc_conn.done;
1747}
1748
Harald Welte552620d2017-12-16 23:21:36 +01001749private function f_tc_assignment_fr_a5_4(charstring id) runs on MSC_ConnHdlr {
Philipp Maier48604732018-10-09 15:00:37 +02001750 g_pars := f_gen_test_hdlr_pars();
Harald Welteed848512018-05-24 22:27:58 +02001751 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
1752 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte552620d2017-12-16 23:21:36 +01001753 const OCT8 kc := '0001020304050607'O;
1754 const OCT16 kc128 := kc & kc;
1755
1756 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
1757 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
Harald Weltea0630032018-03-20 21:09:55 +01001758 f_establish_fully(ass_cmd, exp_compl);
Harald Welte38b2a102017-12-23 02:42:58 +01001759 f_cipher_mode('10'O, kc, kc128, true);
Harald Welte552620d2017-12-16 23:21:36 +01001760 /* TODO: expect GSM0808_CAUSE_CIPHERING_ALGORITHM_NOT_SUPPORTED cause value */
Harald Welte552620d2017-12-16 23:21:36 +01001761}
Harald Welte552620d2017-12-16 23:21:36 +01001762testcase TC_assignment_fr_a5_4() runs on test_CT {
1763 var MSC_ConnHdlr vc_conn;
1764
Harald Welte89d42e82017-12-17 16:42:41 +01001765 f_init(1, true);
Harald Welte552620d2017-12-16 23:21:36 +01001766 f_sleep(1.0);
1767
Harald Welte8863fa12018-05-10 20:15:27 +02001768 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5_4));
Harald Welte552620d2017-12-16 23:21:36 +01001769 vc_conn.done;
1770}
1771
1772
Harald Welte4532e0a2017-12-23 02:05:44 +01001773private function f_tc_assignment_sign(charstring id) runs on MSC_ConnHdlr {
Philipp Maier48604732018-10-09 15:00:37 +02001774 g_pars := f_gen_test_hdlr_pars();
Harald Welte4532e0a2017-12-23 02:05:44 +01001775 var template PDU_BSSAP exp_compl := tr_BSSMAP_AssignmentComplete(omit, omit);
Philipp Maier48604732018-10-09 15:00:37 +02001776 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte4532e0a2017-12-23 02:05:44 +01001777 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelTypeSIGNAL);
Harald Weltea0630032018-03-20 21:09:55 +01001778 f_establish_fully(ass_cmd, exp_compl);
Harald Welte4532e0a2017-12-23 02:05:44 +01001779}
1780
1781testcase TC_assignment_sign() runs on test_CT {
1782 var MSC_ConnHdlr vc_conn;
1783
1784 f_init(1, true);
1785 f_sleep(1.0);
1786
Harald Welte8863fa12018-05-10 20:15:27 +02001787 vc_conn := f_start_handler(refers(f_tc_assignment_sign));
Harald Welte4532e0a2017-12-23 02:05:44 +01001788 vc_conn.done;
1789}
1790
Harald Welte60aa5762018-03-21 19:33:13 +01001791/***********************************************************************
1792 * Codec (list) testing
1793 ***********************************************************************/
1794
1795/* check if the given rsl_mode is compatible with the a_elem */
1796private function f_match_codec(BSSMAP_FIELD_CodecElement a_elem, RSL_IE_ChannelMode rsl_mode)
1797return boolean {
1798 select (a_elem.codecType) {
1799 case (GSM_FR) {
1800 if (match(rsl_mode, tr_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM1))) {
1801 return true;
1802 }
1803 }
1804 case (GSM_HR) {
1805 if (match(rsl_mode, tr_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1))) {
1806 return true;
1807 }
1808 }
1809 case (GSM_EFR) {
1810 if (match(rsl_mode, tr_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM2))) {
1811 return true;
1812 }
1813 }
1814 case (FR_AMR) {
1815 if (match(rsl_mode, tr_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM3))) {
1816 return true;
1817 }
1818 }
1819 case (HR_AMR) {
1820 if (match(rsl_mode, tr_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM3))) {
1821 return true;
1822 }
1823 }
1824 case else { }
1825 }
1826 return false;
1827}
1828
1829/* check if the given rsl_mode is compatible with the a_list */
1830private function f_match_codecs(BSSMAP_IE_SpeechCodecList a_list, RSL_IE_ChannelMode rsl_mode)
1831return boolean {
1832 for (var integer i := 0; i < sizeof(a_list); i := i+1) {
1833 if (f_match_codec(a_list.codecElements[i], rsl_mode)) {
1834 return true;
1835 }
1836 }
1837 return false;
1838}
1839
1840/* determine BSSMAP_IE_ChannelType from *first* element of BSSMAP_FIELD_CodecElement */
Philipp Maier61f6b572018-07-06 14:03:38 +02001841function f_BSSMAP_chtype_from_codec(BSSMAP_FIELD_CodecElement a_elem)
Harald Welte60aa5762018-03-21 19:33:13 +01001842return BSSMAP_IE_ChannelType {
1843 /* FIXME: actually look at all elements of BSSMAP_IE_SpeechCodecList */
1844 var BSSMAP_IE_ChannelType ret := valueof(ts_BSSMAP_IE_ChannelType);
1845 select (a_elem.codecType) {
1846 case (GSM_FR) {
1847 ret.channelRateAndType := ChRate_TCHF;
1848 ret.speechId_DataIndicator := Spdi_TCHF_FR;
1849 }
1850 case (GSM_HR) {
1851 ret.channelRateAndType := ChRate_TCHH;
1852 ret.speechId_DataIndicator := Spdi_TCHH_HR;
1853 }
1854 case (GSM_EFR) {
1855 ret.channelRateAndType := ChRate_TCHF;
1856 ret.speechId_DataIndicator := Spdi_TCHF_EFR;
1857 }
1858 case (FR_AMR) {
1859 ret.channelRateAndType := ChRate_TCHF;
1860 ret.speechId_DataIndicator := Spdi_TCHF_AMR;
1861 }
1862 case (HR_AMR) {
1863 ret.channelRateAndType := ChRate_TCHH;
1864 ret.speechId_DataIndicator := Spdi_TCHH_AMR;
1865 }
1866 case else {
1867 setverdict(fail, "Unsupported codec ", a_elem);
Daniel Willmannafce8662018-07-06 23:11:32 +02001868 mtc.stop;
Harald Welte60aa5762018-03-21 19:33:13 +01001869 }
1870 }
1871 return ret;
1872}
1873
Harald Weltea63b9102018-03-22 20:36:16 +01001874private function f_rsl_chmod_tmpl_from_codec(BSSMAP_FIELD_CodecElement a_elem)
1875return template RSL_IE_Body {
1876 var template RSL_IE_Body mode_ie := {
1877 chan_mode := {
1878 len := ?,
1879 reserved := ?,
1880 dtx_d := ?,
1881 dtx_u := ?,
1882 spd_ind := RSL_SPDI_SPEECH,
1883 ch_rate_type := -,
1884 coding_alg_rate := -
1885 }
1886 }
1887
1888 select (a_elem.codecType) {
1889 case (GSM_FR) {
1890 mode_ie.chan_mode.ch_rate_type := RSL_CHRT_TCH_F;
1891 mode_ie.chan_mode.coding_alg_rate := RSL_CMOD_SP_GSM1;
1892 }
1893 case (GSM_HR) {
1894 mode_ie.chan_mode.ch_rate_type := RSL_CHRT_TCH_H;
1895 mode_ie.chan_mode.coding_alg_rate := RSL_CMOD_SP_GSM1;
1896 }
1897 case (GSM_EFR) {
1898 mode_ie.chan_mode.ch_rate_type := RSL_CHRT_TCH_F;
1899 mode_ie.chan_mode.coding_alg_rate := RSL_CMOD_SP_GSM2;
1900 }
1901 case (FR_AMR) {
1902 mode_ie.chan_mode.ch_rate_type := RSL_CHRT_TCH_F;
1903 mode_ie.chan_mode.coding_alg_rate := RSL_CMOD_SP_GSM3;
1904 }
1905 case (HR_AMR) {
1906 mode_ie.chan_mode.ch_rate_type := RSL_CHRT_TCH_H;
1907 mode_ie.chan_mode.coding_alg_rate := RSL_CMOD_SP_GSM3;
1908 }
1909 }
1910 return mode_ie;
1911}
1912
Harald Welte60aa5762018-03-21 19:33:13 +01001913type record CodecListTest {
1914 BSSMAP_IE_SpeechCodecList codec_list,
1915 charstring id
1916}
1917type record of CodecListTest CodecListTests
1918
1919private function f_TC_assignment_codec(charstring id) runs on MSC_ConnHdlr {
Harald Welteed848512018-05-24 22:27:58 +02001920 var PDU_BSSAP ass_cmd := f_gen_ass_req();
1921 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
Harald Welte60aa5762018-03-21 19:33:13 +01001922
1923 /* puzzle together the ASSIGNMENT REQ for given codec[s] */
Harald Welte79f3f542018-05-25 20:02:37 +02001924 if (mp_bssap_cfg.transport == BSSAP_TRANSPORT_AoIP) {
1925 ass_cmd.pdu.bssmap.assignmentRequest.codecList := g_pars.ass_codec_list;
1926 exp_compl.pdu.bssmap.assignmentComplete.speechCodec.codecElements[0] :=
1927 g_pars.ass_codec_list.codecElements[0];
1928 }
Harald Welte60aa5762018-03-21 19:33:13 +01001929 ass_cmd.pdu.bssmap.assignmentRequest.channelType :=
1930 f_BSSMAP_chtype_from_codec(g_pars.ass_codec_list.codecElements[0]);
Harald Welte60aa5762018-03-21 19:33:13 +01001931 log("expecting ASS COMPL like this: ", exp_compl);
1932
1933 f_establish_fully(ass_cmd, exp_compl);
Harald Weltea63b9102018-03-22 20:36:16 +01001934
1935 /* Verify that the RSL-side activation actually matches our expectations */
1936 var RSL_Message rsl := f_rslem_get_last_act(RSL_PROC, 0, g_chan_nr);
1937
1938 var RSL_IE_Body mode_ie;
1939 if (f_rsl_find_ie(rsl, RSL_IE_CHAN_MODE, mode_ie) == false) {
1940 setverdict(fail, "Couldn't find CHAN_MODE IE");
Daniel Willmannafce8662018-07-06 23:11:32 +02001941 mtc.stop;
Harald Weltea63b9102018-03-22 20:36:16 +01001942 }
1943 var template RSL_IE_Body t_mode_ie := f_rsl_chmod_tmpl_from_codec(g_pars.ass_codec_list.codecElements[0]);
1944 if (not match(mode_ie, t_mode_ie)) {
1945 setverdict(fail, "RSL Channel Mode IE doesn't match expectation");
1946 }
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02001947
1948 var RSL_IE_Body mr_conf;
1949 if (g_pars.expect_mr_conf_ie != omit) {
1950 if (f_rsl_find_ie(rsl, RSL_IE_MR_CONFIG, mr_conf) == false) {
1951 setverdict(fail, "Missing MR CONFIG IE in RSL Chan Activ");
Daniel Willmannafce8662018-07-06 23:11:32 +02001952 mtc.stop;
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02001953 }
1954 log("found RSL MR CONFIG IE: ", mr_conf);
1955
1956 if (not match(mr_conf, g_pars.expect_mr_conf_ie)) {
1957 setverdict(fail, "RSL MR CONFIG IE does not match expectation. Expected: ",
1958 g_pars.expect_mr_conf_ie);
1959 }
1960 } else {
1961 if (f_rsl_find_ie(rsl, RSL_IE_MR_CONFIG, mr_conf) == true) {
1962 log("found RSL MR CONFIG IE: ", mr_conf);
1963 setverdict(fail, "Found MR CONFIG IE in RSL Chan Activ, expecting omit");
Daniel Willmannafce8662018-07-06 23:11:32 +02001964 mtc.stop;
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02001965 }
1966 }
Harald Welte60aa5762018-03-21 19:33:13 +01001967}
1968
1969testcase TC_assignment_codec_fr() runs on test_CT {
Philipp Maier48604732018-10-09 15:00:37 +02001970 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte60aa5762018-03-21 19:33:13 +01001971 var MSC_ConnHdlr vc_conn;
1972
1973 f_init(1, true);
1974 f_sleep(1.0);
1975
1976 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
Harald Welte8863fa12018-05-10 20:15:27 +02001977 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
Harald Welte60aa5762018-03-21 19:33:13 +01001978 vc_conn.done;
1979}
1980
1981testcase TC_assignment_codec_hr() runs on test_CT {
Philipp Maier48604732018-10-09 15:00:37 +02001982 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte60aa5762018-03-21 19:33:13 +01001983 var MSC_ConnHdlr vc_conn;
1984
1985 f_init(1, true);
1986 f_sleep(1.0);
1987
1988 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecHR}));
Harald Welte8863fa12018-05-10 20:15:27 +02001989 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
Harald Welte60aa5762018-03-21 19:33:13 +01001990 vc_conn.done;
1991}
1992
1993testcase TC_assignment_codec_efr() runs on test_CT {
Philipp Maier48604732018-10-09 15:00:37 +02001994 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte60aa5762018-03-21 19:33:13 +01001995 var MSC_ConnHdlr vc_conn;
1996
1997 f_init(1, true);
1998 f_sleep(1.0);
1999
2000 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecEFR}));
Harald Welte8863fa12018-05-10 20:15:27 +02002001 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
Harald Welte60aa5762018-03-21 19:33:13 +01002002 vc_conn.done;
2003}
2004
2005testcase TC_assignment_codec_amr_f() runs on test_CT {
Philipp Maier48604732018-10-09 15:00:37 +02002006 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte60aa5762018-03-21 19:33:13 +01002007 var MSC_ConnHdlr vc_conn;
Philipp Maier7695a0d2018-09-27 17:52:14 +02002008
2009 /* Note: This setups the codec configuration. The parameter payload in
2010 * mr_conf must be consistant with the parameter codecElements in pars
2011 * and also must match the amr-config in osmo-bsc.cfg! */
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02002012 var RSL_IE_Body mr_conf := {
2013 other := {
2014 len := 2,
2015 payload := '2804'O
2016 }
2017 };
Harald Welte60aa5762018-03-21 19:33:13 +01002018
Philipp Maier7695a0d2018-09-27 17:52:14 +02002019 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_F}));
2020 pars.ass_codec_list.codecElements[0].s0_7 := '00000110'B;
2021 pars.ass_codec_list.codecElements[0].s8_15 := '01010111'B;
2022 pars.expect_mr_conf_ie := mr_conf;
2023
Harald Welte60aa5762018-03-21 19:33:13 +01002024 f_init(1, true);
2025 f_sleep(1.0);
2026
Harald Welte8863fa12018-05-10 20:15:27 +02002027 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
Harald Welte60aa5762018-03-21 19:33:13 +01002028 vc_conn.done;
2029}
2030
2031testcase TC_assignment_codec_amr_h() runs on test_CT {
Philipp Maier48604732018-10-09 15:00:37 +02002032 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte60aa5762018-03-21 19:33:13 +01002033 var MSC_ConnHdlr vc_conn;
Philipp Maier7695a0d2018-09-27 17:52:14 +02002034
2035 /* See note above */
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02002036 var RSL_IE_Body mr_conf := {
2037 other := {
2038 len := 2,
2039 payload := '2804'O
2040 }
2041 };
Harald Welte60aa5762018-03-21 19:33:13 +01002042
Philipp Maier7695a0d2018-09-27 17:52:14 +02002043 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_H}));
2044 pars.ass_codec_list.codecElements[0].s0_7 := '00000110'B;
2045 pars.ass_codec_list.codecElements[0].s8_15 := '00000111'B;
2046 pars.expect_mr_conf_ie := mr_conf;
2047
Harald Welte60aa5762018-03-21 19:33:13 +01002048 f_init(1, true);
2049 f_sleep(1.0);
2050
Harald Welte8863fa12018-05-10 20:15:27 +02002051 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
Harald Welte60aa5762018-03-21 19:33:13 +01002052 vc_conn.done;
2053}
2054
Philipp Maierac09bfc2019-01-08 13:41:39 +01002055private function f_disable_all_tch_f() runs on test_CT {
Philipp Maierc704a882019-01-29 15:58:52 +01002056 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 1 sub-slot 0 borken");
2057 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 2 sub-slot 0 borken");
2058 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 3 sub-slot 0 borken");
2059 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 4 sub-slot 0 borken");
Philipp Maierac09bfc2019-01-08 13:41:39 +01002060}
2061
2062private function f_disable_all_tch_h() runs on test_CT {
Philipp Maierc704a882019-01-29 15:58:52 +01002063 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 5 sub-slot 0 borken");
2064 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 5 sub-slot 1 borken");
Philipp Maierac09bfc2019-01-08 13:41:39 +01002065}
2066
2067private function f_enable_all_tch() runs on test_CT {
Philipp Maierc704a882019-01-29 15:58:52 +01002068 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 1 sub-slot 0 unused");
2069 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 2 sub-slot 0 unused");
2070 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 3 sub-slot 0 unused");
2071 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 4 sub-slot 0 unused");
2072 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 5 sub-slot 0 unused");
2073 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 5 sub-slot 1 unused");
Philipp Maierac09bfc2019-01-08 13:41:39 +01002074}
2075
2076/* Allow HR only */
2077private function f_TC_assignment_codec_xr_exhausted_req_hr(charstring id) runs on MSC_ConnHdlr {
2078 g_pars := f_gen_test_hdlr_pars();
2079 var PDU_BSSAP ass_cmd := f_gen_ass_req();
2080 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
2081 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
2082 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '09'O;
2083 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '05'O;
2084 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecHR}));
2085 f_establish_fully(ass_cmd, exp_compl);
2086}
2087
2088/* Allow FR only */
2089private function f_TC_assignment_codec_xr_exhausted_req_fr(charstring id) runs on MSC_ConnHdlr {
2090 g_pars := f_gen_test_hdlr_pars();
2091 var PDU_BSSAP ass_cmd := f_gen_ass_req();
2092 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
2093 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
2094 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '08'O;
2095 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '01'O;
2096 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
2097 f_establish_fully(ass_cmd, exp_compl);
2098}
2099
2100/* Allow HR only (expect assignment failure) */
2101private function f_TC_assignment_codec_xr_exhausted_req_hr_fail(charstring id) runs on MSC_ConnHdlr {
2102 g_pars := f_gen_test_hdlr_pars();
2103 var PDU_BSSAP ass_cmd := f_gen_ass_req();
2104 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
2105 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
2106 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '09'O;
2107 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '05'O;
2108 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecHR}));
2109 f_establish_fully(ass_cmd, exp_fail);
2110}
2111
2112/* Allow FR only (expect assignment failure) */
2113private function f_TC_assignment_codec_xr_exhausted_req_fr_fail(charstring id) runs on MSC_ConnHdlr {
2114 g_pars := f_gen_test_hdlr_pars();
2115 var PDU_BSSAP ass_cmd := f_gen_ass_req();
2116 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
2117 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
2118 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '08'O;
2119 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '01'O;
2120 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
2121 f_establish_fully(ass_cmd, exp_fail);
2122}
2123
2124/* Allow FR and HR, but prefer FR */
2125private function f_TC_assignment_codec_fr_exhausted_req_fr_hr(charstring id) runs on MSC_ConnHdlr {
2126 g_pars := f_gen_test_hdlr_pars();
2127 var PDU_BSSAP ass_cmd := f_gen_ass_req();
2128 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
2129 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
2130 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '0A'O; /* Prefer FR */
2131 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '8105'O;
2132 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR, ts_CodecHR}));
2133 exp_compl.pdu.bssmap.assignmentComplete.speechVersion.speechVersionIdentifier := '0000101'B; /* Expect HR */
2134 f_establish_fully(ass_cmd, exp_compl);
2135}
2136
2137/* Allow FR and HR, but prefer HR */
2138private function f_TC_assignment_codec_fr_exhausted_req_hr_fr(charstring id) runs on MSC_ConnHdlr {
2139 g_pars := f_gen_test_hdlr_pars();
2140 var PDU_BSSAP ass_cmd := f_gen_ass_req();
2141 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
2142 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
2143 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '0B'O; /* Prefer HR */
2144 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '8501'O;
2145 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecHR, ts_CodecFR}));
2146 exp_compl.pdu.bssmap.assignmentComplete.speechVersion.speechVersionIdentifier := '0000101'B; /* Expect HR */
2147 f_establish_fully(ass_cmd, exp_compl);
2148}
2149
2150/* Allow FR and HR, but prefer FR */
2151private function f_TC_assignment_codec_hr_exhausted_req_fr_hr(charstring id) runs on MSC_ConnHdlr {
2152 g_pars := f_gen_test_hdlr_pars();
2153 var PDU_BSSAP ass_cmd := f_gen_ass_req();
2154 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
2155 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
2156 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '0A'O; /* Prefer FR */
2157 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '8105'O;
2158 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR, ts_CodecHR}));
2159 exp_compl.pdu.bssmap.assignmentComplete.speechVersion.speechVersionIdentifier := '0000001'B; /* Expect FR */
2160 f_establish_fully(ass_cmd, exp_compl);
2161}
2162
2163/* Allow FR and HR, but prefer HR */
2164private function f_TC_assignment_codec_hr_exhausted_req_hr_fr(charstring id) runs on MSC_ConnHdlr {
2165 g_pars := f_gen_test_hdlr_pars();
2166 var PDU_BSSAP ass_cmd := f_gen_ass_req();
2167 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
2168 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
2169 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '0B'O; /* Prefer HR */
2170 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '8501'O;
2171 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecHR, ts_CodecFR}));
2172 exp_compl.pdu.bssmap.assignmentComplete.speechVersion.speechVersionIdentifier := '0000001'B; /* Expect FR */
2173 f_establish_fully(ass_cmd, exp_compl);
2174}
2175
2176/* Request a HR channel while all FR channels are exhausted, this is expected
2177 * to work without conflicts */
2178testcase TC_assignment_codec_fr_exhausted_req_hr() runs on test_CT {
2179 var MSC_ConnHdlr vc_conn;
2180 f_init(1, true);
2181 f_sleep(1.0);
2182 f_enable_all_tch();
2183 f_disable_all_tch_f();
2184 vc_conn := f_start_handler(refers(f_TC_assignment_codec_xr_exhausted_req_hr));
2185 vc_conn.done;
2186 f_enable_all_tch();
2187 setverdict(pass);
2188}
2189
2190/* Request a FR channel while all FR channels are exhausted, this is expected
2191 * to fail. */
2192testcase TC_assignment_codec_fr_exhausted_req_fr() runs on test_CT {
2193 var MSC_ConnHdlr vc_conn;
2194 f_init(1, true);
2195 f_sleep(1.0);
2196 f_enable_all_tch();
2197 f_disable_all_tch_f();
2198 vc_conn := f_start_handler(refers(f_TC_assignment_codec_xr_exhausted_req_fr_fail));
2199 vc_conn.done;
2200 f_enable_all_tch();
2201 setverdict(pass);
2202}
2203
2204/* Request a FR (prefered) or alternatively a HR channel while all FR channels
2205 * are exhausted, this is expected to be resolved by selecting a HR channel. */
2206testcase TC_assignment_codec_fr_exhausted_req_fr_hr() runs on test_CT {
2207 var MSC_ConnHdlr vc_conn;
2208 f_init(1, true);
2209 f_sleep(1.0);
2210 f_enable_all_tch();
2211 f_disable_all_tch_f();
2212 vc_conn := f_start_handler(refers(f_TC_assignment_codec_fr_exhausted_req_fr_hr));
2213 vc_conn.done;
2214 f_enable_all_tch();
2215 setverdict(pass);
2216}
2217
2218/* Request a HR (prefered) or alternatively a FR channel while all FR channels
2219 * are exhausted, this is expected to work without conflicts. */
2220testcase TC_assignment_codec_fr_exhausted_req_hr_fr() runs on test_CT {
2221 var MSC_ConnHdlr vc_conn;
2222 f_init(1, true);
2223 f_sleep(1.0);
2224 f_enable_all_tch();
2225 f_disable_all_tch_f();
2226 vc_conn := f_start_handler(refers(f_TC_assignment_codec_fr_exhausted_req_hr_fr));
2227 vc_conn.done;
2228 f_enable_all_tch();
2229 setverdict(pass);
2230}
2231
2232/* Request a FR channel while all HR channels are exhausted, this is expected
2233 * to work without conflicts */
2234testcase TC_assignment_codec_hr_exhausted_req_fr() runs on test_CT {
2235 var MSC_ConnHdlr vc_conn;
2236 f_init(1, true);
2237 f_sleep(1.0);
2238 f_enable_all_tch();
2239 f_disable_all_tch_h();
2240 vc_conn := f_start_handler(refers(f_TC_assignment_codec_xr_exhausted_req_fr));
2241 vc_conn.done;
2242 f_enable_all_tch();
2243 setverdict(pass);
2244}
2245
2246/* Request a HR channel while all HR channels are exhausted, this is expected
2247 * to fail. */
2248testcase TC_assignment_codec_hr_exhausted_req_hr() runs on test_CT {
2249 var MSC_ConnHdlr vc_conn;
2250 f_init(1, true);
2251 f_sleep(1.0);
2252 f_enable_all_tch();
2253 f_disable_all_tch_h();
2254 vc_conn := f_start_handler(refers(f_TC_assignment_codec_xr_exhausted_req_hr_fail));
2255 vc_conn.done;
2256 f_enable_all_tch();
2257 setverdict(pass);
2258}
2259
2260/* Request a HR (prefered) or alternatively a FR channel while all HR channels
2261 * are exhausted, this is expected to be resolved by selecting a FR channel. */
2262testcase TC_assignment_codec_hr_exhausted_req_hr_fr() runs on test_CT {
2263 var MSC_ConnHdlr vc_conn;
2264 f_init(1, true);
2265 f_sleep(1.0);
2266 f_enable_all_tch();
2267 f_disable_all_tch_h();
2268 vc_conn := f_start_handler(refers(f_TC_assignment_codec_hr_exhausted_req_hr_fr));
2269 vc_conn.done;
2270 f_enable_all_tch();
2271 setverdict(pass);
2272}
2273
2274/* Request a FR (prefered) or alternatively a HR channel while all HR channels
2275 * are exhausted, this is expected to work without conflicts. */
2276testcase TC_assignment_codec_hr_exhausted_req_fr_hr() runs on test_CT {
2277 var MSC_ConnHdlr vc_conn;
2278 f_init(1, true);
2279 f_sleep(1.0);
2280 f_enable_all_tch();
2281 f_disable_all_tch_h();
2282 vc_conn := f_start_handler(refers(f_TC_assignment_codec_hr_exhausted_req_fr_hr));
2283 vc_conn.done;
2284 f_enable_all_tch();
2285 setverdict(pass);
2286}
2287
2288/* Allow FR and HR, but prefer HR */
2289private function f_TC_assignment_codec_req_hr_fr(charstring id) runs on MSC_ConnHdlr {
2290 g_pars := f_gen_test_hdlr_pars();
2291 var PDU_BSSAP ass_cmd := f_gen_ass_req();
2292 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
2293 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
2294 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '0B'O; /* Prefer HR */
2295 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '8501'O;
2296 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecHR, ts_CodecFR}));
2297 exp_compl.pdu.bssmap.assignmentComplete.speechVersion.speechVersionIdentifier := '0000101'B; /* Expect HR */
2298 f_establish_fully(ass_cmd, exp_compl);
2299}
2300
2301/* Allow FR and HR, but prefer FR */
2302private function f_TC_assignment_codec_req_fr_hr(charstring id) runs on MSC_ConnHdlr {
2303 g_pars := f_gen_test_hdlr_pars();
2304 var PDU_BSSAP ass_cmd := f_gen_ass_req();
2305 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
2306 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
2307 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '0A'O; /* Prefer FR */
2308 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '8105'O;
2309 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR, ts_CodecHR}));
2310 exp_compl.pdu.bssmap.assignmentComplete.speechVersion.speechVersionIdentifier := '0000001'B; /* Expect FR */
2311 f_establish_fully(ass_cmd, exp_compl);
2312}
2313
2314/* Request a HR (prefered) or alternatively a FR channel, it is expected that
2315 * HR, which is the prefered type, is selected. */
2316testcase TC_assignment_codec_req_hr_fr() runs on test_CT {
2317 var MSC_ConnHdlr vc_conn;
2318 f_init(1, true);
2319 f_sleep(1.0);
2320 f_enable_all_tch();
2321 vc_conn := f_start_handler(refers(f_TC_assignment_codec_req_hr_fr));
2322 vc_conn.done;
2323 setverdict(pass);
2324}
2325
2326/* Request a FR (prefered) or alternatively a HR channel, it is expected that
2327 * FR, which is the prefered type, is selected. */
2328testcase TC_assignment_codec_req_fr_hr() runs on test_CT {
2329 var MSC_ConnHdlr vc_conn;
2330 f_init(1, true);
2331 f_sleep(1.0);
2332 f_enable_all_tch();
2333 vc_conn := f_start_handler(refers(f_TC_assignment_codec_req_fr_hr));
2334 vc_conn.done;
2335 setverdict(pass);
2336}
2337
Neels Hofmeyr92b12b72018-09-18 14:30:23 +02002338/* test the procedure of the MSC requesting a Classmark Update:
2339 * a) BSSMAP Classmark Request should result in RR CLASSMARK ENQUIRY,
2340 * b) L3 RR CLASSMARK CHANGE should result in BSSMAP CLASSMARK UPDATE */
Harald Welte898113b2018-01-31 18:32:21 +01002341private function f_tc_classmark(charstring id) runs on MSC_ConnHdlr {
Philipp Maier48604732018-10-09 15:00:37 +02002342 g_pars := f_gen_test_hdlr_pars();
2343
Harald Weltea0630032018-03-20 21:09:55 +01002344 f_create_chan_and_exp();
Harald Welte898113b2018-01-31 18:32:21 +01002345 /* we should now have a COMPL_L3 at the MSC */
2346 BSSAP.receive(tr_BSSMAP_ComplL3);
2347
Neels Hofmeyr92b12b72018-09-18 14:30:23 +02002348 BSSAP.send(ts_BSSMAP_ClassmarkRequest);
2349 RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch tr_RRM_CM_ENQUIRY));
2350
Harald Welte898113b2018-01-31 18:32:21 +01002351 f_rsl_send_l3(ts_RRM_CM_CHG(valueof(ts_CM2)));
2352 BSSAP.receive(tr_BSSMAP_ClassmarkUpd(?, omit));
2353 setverdict(pass);
2354}
2355testcase TC_classmark() runs on test_CT {
2356 var MSC_ConnHdlr vc_conn;
2357 f_init(1, true);
2358 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02002359 vc_conn := f_start_handler(refers(f_tc_classmark));
Harald Welte898113b2018-01-31 18:32:21 +01002360 vc_conn.done;
2361}
2362
Harald Weltee3bd6582018-01-31 22:51:25 +01002363private function f_est_single_l3(template PDU_ML3_MS_NW l3) runs on MSC_ConnHdlr {
Philipp Maier48604732018-10-09 15:00:37 +02002364 g_pars := f_gen_test_hdlr_pars();
Harald Weltea0630032018-03-20 21:09:55 +01002365 f_create_chan_and_exp();
Harald Welte898113b2018-01-31 18:32:21 +01002366 /* we should now have a COMPL_L3 at the MSC */
2367 BSSAP.receive(tr_BSSMAP_ComplL3);
2368
Harald Weltee3bd6582018-01-31 22:51:25 +01002369 /* send the single message we want to send */
2370 f_rsl_send_l3(l3);
2371}
2372
2373private function f_bssap_expect_nothing(float sec := 5.00) runs on MSC_ConnHdlr {
2374 timer T := sec;
2375 var PDU_BSSAP bssap;
Harald Welte898113b2018-01-31 18:32:21 +01002376 T.start;
2377 alt {
Harald Weltee3bd6582018-01-31 22:51:25 +01002378 [] BSSAP.receive(PDU_BSSAP:?) -> value bssap {
2379 setverdict(fail, "Unexpected BSSMAP ", bssap);
Daniel Willmannafce8662018-07-06 23:11:32 +02002380 mtc.stop;
Harald Welte898113b2018-01-31 18:32:21 +01002381 }
2382 [] T.timeout {
2383 setverdict(pass);
2384 }
2385 }
2386}
2387
Harald Weltee3bd6582018-01-31 22:51:25 +01002388/* unsolicited ASSIGNMENT FAIL (without ASSIGN) from MS shouldn't bring BSC down */
2389private function f_tc_unsol_ass_fail(charstring id) runs on MSC_ConnHdlr {
2390 f_est_single_l3(ts_RRM_AssignmentFailure('00'O));
2391 f_bssap_expect_nothing();
2392}
Harald Welte898113b2018-01-31 18:32:21 +01002393testcase TC_unsol_ass_fail() runs on test_CT {
2394 var MSC_ConnHdlr vc_conn;
2395 f_init(1, true);
2396 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02002397 vc_conn := f_start_handler(refers(f_tc_unsol_ass_fail));
Harald Welte898113b2018-01-31 18:32:21 +01002398 vc_conn.done;
2399}
Harald Welte552620d2017-12-16 23:21:36 +01002400
Harald Welteea99a002018-01-31 20:46:43 +01002401
2402/* unsolicited ASSIGNMENT COMPLETE (without ASSIGN) from MS shouldn't bring BSC down */
2403private function f_tc_unsol_ass_compl(charstring id) runs on MSC_ConnHdlr {
Harald Weltee3bd6582018-01-31 22:51:25 +01002404 f_est_single_l3(ts_RRM_AssignmentComplete('00'O));
2405 f_bssap_expect_nothing();
Harald Welteea99a002018-01-31 20:46:43 +01002406}
2407testcase TC_unsol_ass_compl() runs on test_CT {
2408 var MSC_ConnHdlr vc_conn;
2409 f_init(1, true);
2410 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02002411 vc_conn := f_start_handler(refers(f_tc_unsol_ass_compl));
Harald Welteea99a002018-01-31 20:46:43 +01002412 vc_conn.done;
2413}
2414
2415
Harald Weltefbf9b5e2018-01-31 20:41:23 +01002416/* unsolicited HANDOVER FAIL (without ASSIGN) from MS shouldn't bring BSC down */
2417private function f_tc_unsol_ho_fail(charstring id) runs on MSC_ConnHdlr {
Harald Weltee3bd6582018-01-31 22:51:25 +01002418 f_est_single_l3(ts_RRM_HandoverFailure('00'O));
2419 f_bssap_expect_nothing();
Harald Weltefbf9b5e2018-01-31 20:41:23 +01002420}
Harald Weltefbf9b5e2018-01-31 20:41:23 +01002421testcase TC_unsol_ho_fail() runs on test_CT {
2422 var MSC_ConnHdlr vc_conn;
2423 f_init(1, true);
2424 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02002425 vc_conn := f_start_handler(refers(f_tc_unsol_ho_fail));
Harald Weltefbf9b5e2018-01-31 20:41:23 +01002426 vc_conn.done;
2427}
2428
2429
Harald Weltee3bd6582018-01-31 22:51:25 +01002430/* short message from MS should be ignored */
2431private function f_tc_err_82_short_msg(charstring id) runs on MSC_ConnHdlr {
Philipp Maier48604732018-10-09 15:00:37 +02002432 g_pars := f_gen_test_hdlr_pars();
Harald Weltea0630032018-03-20 21:09:55 +01002433 f_create_chan_and_exp();
Harald Weltee3bd6582018-01-31 22:51:25 +01002434 /* we should now have a COMPL_L3 at the MSC */
2435 BSSAP.receive(tr_BSSMAP_ComplL3);
2436
2437 /* send short message */
2438 RSL.send(ts_RSL_DATA_IND(g_chan_nr, valueof(ts_RslLinkID_DCCH(0)), ''O));
2439 f_bssap_expect_nothing();
2440}
2441testcase TC_err_82_short_msg() runs on test_CT {
2442 var MSC_ConnHdlr vc_conn;
2443 f_init(1, true);
2444 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02002445 vc_conn := f_start_handler(refers(f_tc_err_82_short_msg));
Harald Weltee3bd6582018-01-31 22:51:25 +01002446 vc_conn.done;
2447}
2448
2449
Harald Weltee9e02e42018-01-31 23:36:25 +01002450/* 24.008 8.4 Unknown message must trigger RR STATUS */
2451private function f_tc_err_84_unknown_msg(charstring id) runs on MSC_ConnHdlr {
2452 f_est_single_l3(ts_RRM_UL_REL('00'O));
2453 timer T := 3.0
2454 alt {
2455 [] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch tr_RRM_RR_STATUS)) {
2456 setverdict(pass);
2457 }
2458 [] BSSAP.receive { setverdict(fail, "unexpected BSSAP"); }
Harald Welte458fd372018-03-21 11:26:23 +01002459 [] T.timeout { setverdict(fail, "Timeout waiting for RR STATUS"); }
Harald Weltee9e02e42018-01-31 23:36:25 +01002460 }
2461}
2462testcase TC_err_84_unknown_msg() runs on test_CT {
2463 var MSC_ConnHdlr vc_conn;
2464 f_init(1, true);
2465 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02002466 vc_conn := f_start_handler(refers(f_tc_err_84_unknown_msg));
Harald Weltee9e02e42018-01-31 23:36:25 +01002467 vc_conn.done;
2468}
2469
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01002470/***********************************************************************
2471 * Handover
2472 ***********************************************************************/
2473
Harald Welte94e0c342018-04-07 11:33:23 +02002474/* execute a "bts <0-255> trx <0-255> timeslot <0-7> " command on given Dchan */
2475private function f_vty_ts_action(charstring suffix, integer bts_nr, integer trx_nr, integer ts_nr)
2476runs on test_CT {
2477 var charstring cmd := "bts "&int2str(bts_nr)&" trx "&int2str(trx_nr)&
2478 " timeslot "&int2str(ts_nr)&" ";
2479 f_vty_transceive(BSCVTY, cmd & suffix);
2480}
2481
Harald Welte261af4b2018-02-12 21:20:39 +01002482/* execute a "bts <0-255> trx <0-255> timeslot <0-7> sub-slot <0-7>" command on given Dchan */
2483private function f_vty_ss_action(charstring suffix, integer bts_nr, integer trx_nr, RslChannelNr chan_nr)
2484runs on MSC_ConnHdlr {
2485 /* FIXME: resolve those from component-global state */
2486 var integer ts_nr := chan_nr.tn;
2487 var integer ss_nr;
2488 if (ischosen(chan_nr.u.ch0)) {
2489 ss_nr := 0;
2490 } else if (ischosen(chan_nr.u.lm)) {
2491 ss_nr := chan_nr.u.lm.sub_chan;
2492 } else if (ischosen(chan_nr.u.sdcch4)) {
2493 ss_nr := chan_nr.u.sdcch4.sub_chan;
2494 } else if (ischosen(chan_nr.u.sdcch8)) {
2495 ss_nr := chan_nr.u.sdcch8.sub_chan;
2496 } else {
2497 setverdict(fail, "Invalid ChanNr ", chan_nr);
Daniel Willmannafce8662018-07-06 23:11:32 +02002498 mtc.stop;
Harald Welte261af4b2018-02-12 21:20:39 +01002499 }
2500
2501 var charstring cmd := "bts "&int2str(bts_nr)&" trx "&int2str(trx_nr)&
2502 " timeslot "&int2str(ts_nr)&" sub-slot "&int2str(ss_nr)&" ";
2503 f_vty_transceive(BSCVTY, cmd & suffix);
2504}
2505
2506private function f_vty_handover(integer bts_nr, integer trx_nr, RslChannelNr chan_nr,
2507 integer new_bts_nr)
2508runs on MSC_ConnHdlr {
2509 f_vty_ss_action("handover " & int2str(new_bts_nr), bts_nr, trx_nr, chan_nr);
2510}
2511
2512/* intra-BSC hand-over between BTS0 and BTS1 */
2513private function f_tc_ho_int(charstring id) runs on MSC_ConnHdlr {
Philipp Maier48604732018-10-09 15:00:37 +02002514 g_pars := f_gen_test_hdlr_pars();
Harald Welteed848512018-05-24 22:27:58 +02002515 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
2516 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte261af4b2018-02-12 21:20:39 +01002517 const OCT8 kc := '0001020304050607'O;
2518
2519 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
2520 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
2521
Harald Weltea0630032018-03-20 21:09:55 +01002522 f_establish_fully(ass_cmd, exp_compl);
Harald Welte261af4b2018-02-12 21:20:39 +01002523
2524 var HandoverState hs := {
2525 rr_ho_cmpl_seen := false,
2526 handover_done := false,
2527 old_chan_nr := -
2528 };
2529 /* issue hand-over command on VTY */
2530 f_vty_handover(0, 0, g_chan_nr, 1);
2531 /* temporarily suspend DChan processing on BTS1 to avoid race with RSLEM_register */
2532 f_rslem_suspend(RSL1_PROC);
Philipp Maier3e2af5d2018-07-11 17:01:05 +02002533
2534 /* From the MGW perspective, a handover is is characterized by
2535 * performing one MDCX operation with the MGW. So we expect to see
2536 * one more MDCX during handover. */
2537 g_media.mgcp_conn[0].mdcx_seen_exp := g_media.mgcp_conn[0].crcx_seen_exp + 1;
2538
Harald Welte261af4b2018-02-12 21:20:39 +01002539 alt {
2540 [] as_handover(hs);
Harald Welte261af4b2018-02-12 21:20:39 +01002541 }
Philipp Maier3e2af5d2018-07-11 17:01:05 +02002542
Philipp Maier4dae0652018-11-12 12:03:26 +01002543 /* Since this is an internal handover we expect the BSC to inform the
2544 * MSC about the event */
2545 BSSAP.receive(tr_BSSMAP_HandoverPerformed);
2546
Philipp Maier3e2af5d2018-07-11 17:01:05 +02002547 /* Check the amount of MGCP transactions is still consistant with the
2548 * test expectation */
2549 f_check_mgcp_expectations()
Neels Hofmeyr861a4c12018-11-07 01:23:17 +01002550 f_sleep(0.5);
Harald Welte261af4b2018-02-12 21:20:39 +01002551}
2552
2553testcase TC_ho_int() runs on test_CT {
2554 var MSC_ConnHdlr vc_conn;
2555 f_init(2, true);
2556 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02002557 vc_conn := f_start_handler(refers(f_tc_ho_int));
Harald Welte261af4b2018-02-12 21:20:39 +01002558 vc_conn.done;
2559}
Harald Weltee9e02e42018-01-31 23:36:25 +01002560
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01002561private function f_tc_ho_out_of_this_bsc(charstring id) runs on MSC_ConnHdlr {
Philipp Maier48604732018-10-09 15:00:37 +02002562 g_pars := f_gen_test_hdlr_pars();
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01002563
2564 var PDU_BSSAP ass_req := f_gen_ass_req();
2565 ass_req.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
2566 ass_req.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
2567 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
2568 f_establish_fully(ass_req, exp_compl);
2569
2570 f_vty_transceive(BSCVTY, "handover any to arfcn 123 bsic any");
2571
2572 BSSAP.receive(tr_BSSMAP_HandoverRequired);
2573
2574 f_sleep(0.5);
2575 /* The MSC negotiates Handover Request and Handover Request Ack with
2576 * the other BSS and comes back with a BSSMAP Handover Command
2577 * containing an RR Handover Command coming from the target BSS... */
2578
2579 var PDU_ML3_NW_MS rr_ho_cmd := valueof(ts_RR_HandoverCommand);
2580 log("Remote cell's RR Handover Command passed through as L3 Info: ", rr_ho_cmd);
2581 var octetstring rr_ho_cmd_enc := enc_PDU_ML3_NW_MS(rr_ho_cmd);
2582 log("Remote cell's RR Handover Command passed through as L3 Info, encoded: ", rr_ho_cmd_enc);
2583 BSSAP.send(ts_BSSMAP_HandoverCommand(rr_ho_cmd_enc));
2584
2585 /* expect the Handover Command to go out on RR */
2586 var RSL_Message rsl_ho_cmd
2587 RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, ?)) -> value rsl_ho_cmd;
2588 log("RSL Data Req went out to first BTS: ", rsl_ho_cmd);
2589 var RSL_IE_Body rsl_ho_cmd_l3;
2590 if (not f_rsl_find_ie(rsl_ho_cmd, RSL_IE_L3_INFO, rsl_ho_cmd_l3)) {
2591 log("RSL message contains no L3 Info IE, expected RR Handover Command");
2592 setverdict(fail);
2593 } else {
2594 log("Found L3 Info: ", rsl_ho_cmd_l3);
2595 if (rsl_ho_cmd_l3.l3_info.payload != rr_ho_cmd_enc) {
2596 log("FAIL: the BSC sent out a different L3 Info, not matching the RR Handover Command the other BSS forwarded.");
2597 setverdict(fail);
2598 } else {
2599 log("Success: the BSC sent out the same RR Handover Command the other BSS forwarded.");
2600 setverdict(pass);
2601 }
2602 }
2603
2604 /* When the other BSS has reported a completed handover, this side is
2605 * torn down. */
2606
2607 var myBSSMAP_Cause cause_val := GSM0808_CAUSE_HANDOVER_SUCCESSFUL;
2608 var BssmapCause cause := enum2int(cause_val);
2609 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
2610
2611 /* Expecting MGCP to DLCX the endpoint's two connections: towards BTS and towards MSC */
2612 var MgcpCommand mgcp;
2613 interleave {
2614 [] BSSAP.receive(tr_BSSMAP_ClearComplete);
2615 [] MGCP.receive(tr_DLCX()) -> value mgcp {
2616 log("Got first DLCX: ", mgcp);
2617 }
2618 [] MGCP.receive(tr_DLCX()) -> value mgcp {
2619 log("Got second DLCX: ", mgcp);
2620 }
2621 }
2622 setverdict(pass);
2623 f_sleep(1.0);
2624}
2625testcase TC_ho_out_of_this_bsc() runs on test_CT {
2626 var MSC_ConnHdlr vc_conn;
2627
2628 f_init(1, true);
2629 f_sleep(1.0);
2630
2631 vc_conn := f_start_handler(refers(f_tc_ho_out_of_this_bsc));
2632 vc_conn.done;
2633}
2634
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02002635/* BSC asks for inter-BSC HO, but the MSC decides that it won't happen and
2636 * simply never sends a BSSMAP Handover Command. */
2637private function f_tc_ho_out_fail_no_msc_response(charstring id) runs on MSC_ConnHdlr {
Daniel Willmann3b59eb52018-10-29 15:40:55 +01002638 g_pars := f_gen_test_hdlr_pars();
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02002639
2640 var PDU_BSSAP ass_req := f_gen_ass_req();
2641 ass_req.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
2642 ass_req.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
2643 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
2644 f_establish_fully(ass_req, exp_compl);
2645
2646 f_vty_transceive(BSCVTY, "handover any to arfcn 123 bsic any");
2647
2648 BSSAP.receive(tr_BSSMAP_HandoverRequired);
2649
2650 /* osmo-bsc should time out 10 seconds after the handover started.
2651 * Let's give it a bit extra. */
2652 f_sleep(15.0);
2653
2654 /* The old lchan and conn should still be active. See that arbitrary L3
2655 * is still going through. */
2656 var octetstring l3 := '0123456789'O;
2657 RSL.send(ts_RSL_DATA_IND(g_chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
2658 var template PDU_BSSAP exp_data := {
2659 discriminator := '1'B,
2660 spare := '0000000'B,
2661 dlci := '00'O,
2662 lengthIndicator := 5,
2663 pdu := {
2664 dtap := l3
2665 }
2666 };
2667 BSSAP.receive(exp_data);
2668 setverdict(pass);
2669 f_sleep(1.0);
2670}
2671testcase TC_ho_out_fail_no_msc_response() runs on test_CT {
2672 var MSC_ConnHdlr vc_conn;
2673
2674 f_init(1, true);
2675 f_sleep(1.0);
2676
2677 vc_conn := f_start_handler(refers(f_tc_ho_out_fail_no_msc_response));
2678 vc_conn.done;
2679}
2680
2681/* BSC asks for inter-BSC HO, receives BSSMAP Handover Command, but MS reports
2682 * RR Handover Failure. */
2683private function f_tc_ho_out_fail_rr_ho_failure(charstring id) runs on MSC_ConnHdlr {
Daniel Willmann3b59eb52018-10-29 15:40:55 +01002684 g_pars := f_gen_test_hdlr_pars();
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02002685
2686 var PDU_BSSAP ass_req := f_gen_ass_req();
2687 ass_req.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
2688 ass_req.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
2689 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
2690 f_establish_fully(ass_req, exp_compl);
2691
2692 f_vty_transceive(BSCVTY, "handover any to arfcn 123 bsic any");
2693
2694 BSSAP.receive(tr_BSSMAP_HandoverRequired);
2695
2696 f_sleep(0.5);
2697 /* The MSC negotiates Handover Request and Handover Request Ack with
2698 * the other BSS and comes back with a BSSMAP Handover Command
2699 * containing an RR Handover Command coming from the target BSS... */
2700
2701 var PDU_ML3_NW_MS rr_ho_cmd := valueof(ts_RR_HandoverCommand);
2702 log("Remote cell's RR Handover Command passed through as L3 Info: ", rr_ho_cmd);
2703 var octetstring rr_ho_cmd_enc := enc_PDU_ML3_NW_MS(rr_ho_cmd);
2704 log("Remote cell's RR Handover Command passed through as L3 Info, encoded: ", rr_ho_cmd_enc);
2705 BSSAP.send(ts_BSSMAP_HandoverCommand(rr_ho_cmd_enc));
2706
2707 /* expect the Handover Command to go out on RR */
2708 var RSL_Message rsl_ho_cmd
2709 RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, ?)) -> value rsl_ho_cmd;
2710 log("RSL Data Req went out to first BTS: ", rsl_ho_cmd);
2711 var RSL_IE_Body rsl_ho_cmd_l3;
2712 if (not f_rsl_find_ie(rsl_ho_cmd, RSL_IE_L3_INFO, rsl_ho_cmd_l3)) {
2713 log("RSL message contains no L3 Info IE, expected RR Handover Command");
2714 setverdict(fail);
2715 } else {
2716 log("Found L3 Info: ", rsl_ho_cmd_l3);
2717 if (rsl_ho_cmd_l3.l3_info.payload != rr_ho_cmd_enc) {
2718 log("FAIL: the BSC sent out a different L3 Info, not matching the RR Handover Command the other BSS forwarded.");
2719 setverdict(fail);
2720 } else {
2721 log("Success: the BSC sent out the same RR Handover Command the other BSS forwarded.");
2722 setverdict(pass);
2723 }
2724 }
2725
2726 f_sleep(0.2);
2727 f_rsl_send_l3(ts_RRM_HandoverFailure('00'O));
2728
2729 /* Should tell the MSC about the failure */
2730 BSSAP.receive(tr_BSSMAP_HandoverFailure);
2731
2732 f_sleep(1.0);
2733
2734 /* The old lchan and conn should still be active. See that arbitrary L3
2735 * is still going through. */
2736 var octetstring l3 := '0123456789'O;
2737 RSL.send(ts_RSL_DATA_IND(g_chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
2738 var template PDU_BSSAP exp_data := {
2739 discriminator := '1'B,
2740 spare := '0000000'B,
2741 dlci := '00'O,
2742 lengthIndicator := 5,
2743 pdu := {
2744 dtap := l3
2745 }
2746 };
2747 BSSAP.receive(exp_data);
2748 setverdict(pass);
2749 f_sleep(1.0);
2750
2751 setverdict(pass);
2752 f_sleep(1.0);
2753}
2754testcase TC_ho_out_fail_rr_ho_failure() runs on test_CT {
2755 var MSC_ConnHdlr vc_conn;
2756
2757 f_init(1, true);
2758 f_sleep(1.0);
2759
2760 vc_conn := f_start_handler(refers(f_tc_ho_out_fail_rr_ho_failure));
2761 vc_conn.done;
2762}
2763
2764/* BSC asks for inter-BSC HO, receives BSSMAP Handover Command, but MS reports
2765 * RR Handover Failure. */
2766private function f_tc_ho_out_fail_no_ho_detect(charstring id) runs on MSC_ConnHdlr {
Daniel Willmann3b59eb52018-10-29 15:40:55 +01002767 g_pars := f_gen_test_hdlr_pars();
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02002768
2769 var PDU_BSSAP ass_req := f_gen_ass_req();
2770 ass_req.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
2771 ass_req.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
2772 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
2773 f_establish_fully(ass_req, exp_compl);
2774
2775 f_vty_transceive(BSCVTY, "handover any to arfcn 123 bsic any");
2776
2777 BSSAP.receive(tr_BSSMAP_HandoverRequired);
2778
2779 f_sleep(0.5);
2780 /* The MSC negotiates Handover Request and Handover Request Ack with
2781 * the other BSS and comes back with a BSSMAP Handover Command
2782 * containing an RR Handover Command coming from the target BSS... */
2783
2784 var PDU_ML3_NW_MS rr_ho_cmd := valueof(ts_RR_HandoverCommand);
2785 log("Remote cell's RR Handover Command passed through as L3 Info: ", rr_ho_cmd);
2786 var octetstring rr_ho_cmd_enc := enc_PDU_ML3_NW_MS(rr_ho_cmd);
2787 log("Remote cell's RR Handover Command passed through as L3 Info, encoded: ", rr_ho_cmd_enc);
2788 BSSAP.send(ts_BSSMAP_HandoverCommand(rr_ho_cmd_enc));
2789
2790 /* expect the Handover Command to go out on RR */
2791 var RSL_Message rsl_ho_cmd
2792 RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, ?)) -> value rsl_ho_cmd;
2793 log("RSL Data Req went out to first BTS: ", rsl_ho_cmd);
2794 var RSL_IE_Body rsl_ho_cmd_l3;
2795 if (not f_rsl_find_ie(rsl_ho_cmd, RSL_IE_L3_INFO, rsl_ho_cmd_l3)) {
2796 log("RSL message contains no L3 Info IE, expected RR Handover Command");
2797 setverdict(fail);
2798 } else {
2799 log("Found L3 Info: ", rsl_ho_cmd_l3);
2800 if (rsl_ho_cmd_l3.l3_info.payload != rr_ho_cmd_enc) {
2801 log("FAIL: the BSC sent out a different L3 Info, not matching the RR Handover Command the other BSS forwarded.");
2802 setverdict(fail);
2803 } else {
2804 log("Success: the BSC sent out the same RR Handover Command the other BSS forwarded.");
2805 setverdict(pass);
2806 }
2807 }
2808
2809 /* The MS never shows up on the remote BSS. Eventually the BSC times
2810 * out and we run into 3GPP TS 48.008 3.1.5.3.3 "Abnormal Conditions":
2811 * RR should be released and Clear Request should go to the MSC. */
2812
2813 var MgcpCommand mgcp;
2814 interleave {
Neels Hofmeyr861a4c12018-11-07 01:23:17 +01002815 [] RSL.receive(tr_RSL_DEACT_SACCH(g_chan_nr)) {
2816 log("Got Deact SACCH");
2817 }
Harald Welte924b6ea2019-02-04 01:05:34 +01002818 [] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch tr_RRM_RR_RELEASE)) {
Neels Hofmeyr211169d2018-11-07 00:37:29 +01002819 log("Got RR Release");
2820 }
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02002821 [] RSL.receive(tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL)) {
2822 log("Got RF Chan Rel");
2823 RSL.send(ts_RSL_RF_CHAN_REL_ACK(g_chan_nr));
2824 }
2825 [] BSSAP.receive(tr_BSSMAP_ClearRequest) {
2826 log("Got BSSMAP Clear Request");
2827 }
2828 [] MGCP.receive(tr_DLCX()) -> value mgcp {
2829 log("Got first DLCX: ", mgcp);
2830 }
2831 [] MGCP.receive(tr_DLCX()) -> value mgcp {
2832 log("Got second DLCX: ", mgcp);
2833 }
2834 }
2835
2836 setverdict(pass);
2837 f_sleep(1.0);
2838}
2839testcase TC_ho_out_fail_no_ho_detect() runs on test_CT {
2840 var MSC_ConnHdlr vc_conn;
2841
2842 f_init(1, true);
2843 f_sleep(1.0);
2844
2845 vc_conn := f_start_handler(refers(f_tc_ho_out_fail_no_ho_detect));
2846 vc_conn.done;
2847}
2848
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01002849private function f_tc_ho_into_this_bsc(charstring id) runs on MSC_ConnHdlr {
2850 /* Hack: the proper way would be to wait for the BSSMAP Handover Request ACK and extract the
2851 * actual assigned chan_nr from its L3 (RR Handover Command) message. But osmo-bsc starts acting
2852 * on the lchan even before we get a chance to evaluate the BSSMAP Handover Request ACK. So we
2853 * need to assume that osmo-bsc will activate TS 1 and already set up this lchan's RSL emulation
2854 * before we get started. */
2855 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(1, RSL_CHAN_NR_Bm_ACCH));
2856 f_rslem_register(0, new_chan_nr);
2857 g_chan_nr := new_chan_nr;
2858 f_sleep(1.0);
2859
2860 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
2861 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
2862 activate(as_Media());
2863
2864 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.handover.sccp_addr_bsc, g_pars.handover.sccp_addr_msc,
2865 f_gen_handover_req()));
2866 BSSAP.receive(BSSAP_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
2867
2868 /* The RSL Emulation magically accepts the Chan Activ behind the scenes. */
2869
2870 var PDU_BSSAP rx_bssap;
2871 var octetstring ho_command_str;
2872
2873 BSSAP.receive(tr_BSSMAP_HandoverRequestAcknowledge(?)) -> value rx_bssap;
2874
2875 ho_command_str := rx_bssap.pdu.bssmap.handoverRequestAck.layer3Information.layer3info;
2876 log("Received L3 Info in HO Request Ack: ", ho_command_str);
2877 var PDU_ML3_NW_MS ho_command := dec_PDU_ML3_NW_MS(ho_command_str);
2878 log("L3 Info in HO Request Ack is ", ho_command);
2879
2880 var GsmArfcn arfcn;
2881 var RslChannelNr actual_new_chan_nr;
2882 f_ChDesc2RslChanNr(ho_command.msgs.rrm.handoverCommand.channelDescription2,
2883 actual_new_chan_nr, arfcn);
2884
2885 if (actual_new_chan_nr != new_chan_nr) {
2886 log("ERROR: osmo-bsc assigned a different lchan than we assumed above -- this test will fail now.",
2887 " Assumed: ", new_chan_nr, " Assigned: ", actual_new_chan_nr);
2888 setverdict(fail);
2889 return;
2890 }
2891 log("Handover Command chan_nr is", actual_new_chan_nr);
2892
2893 /* Now the MSC forwards the RR Handover Command to the other BSC, which
2894 * tells the MS to handover to the new lchan. Here comes the new MS on
2895 * the new lchan with a Handover RACH: */
2896
2897 /* send handover detect */
2898
2899 RSL.send(ts_RSL_HANDO_DET(new_chan_nr));
2900
2901 BSSAP.receive(tr_BSSMAP_HandoverDetect);
2902
2903 /* send handover complete over the new channel */
2904
2905 var PDU_ML3_MS_NW l3_tx := valueof(ts_RRM_HandoverComplete('00'O));
2906 RSL.send(ts_RSL_EST_IND(new_chan_nr, valueof(ts_RslLinkID_DCCH(0)),
2907 enc_PDU_ML3_MS_NW(l3_tx)));
2908
2909 BSSAP.receive(tr_BSSMAP_HandoverComplete);
2910 setverdict(pass);
2911}
2912testcase TC_ho_into_this_bsc() runs on test_CT {
2913 var MSC_ConnHdlr vc_conn;
Philipp Maier48604732018-10-09 15:00:37 +02002914 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01002915
2916 f_init(1, true);
2917 f_sleep(1.0);
2918
2919 pars.handover.sccp_addr_msc := g_bssap.sccp_addr_own;
2920 pars.handover.sccp_addr_bsc := g_bssap.sccp_addr_peer;
2921
2922 vc_conn := f_start_handler(refers(f_tc_ho_into_this_bsc), pars);
2923 vc_conn.done;
2924}
2925
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01002926private function f_tc_ho_in_fail_msc_clears(charstring id) runs on MSC_ConnHdlr {
2927 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(1, RSL_CHAN_NR_Bm_ACCH));
2928 f_rslem_register(0, new_chan_nr);
2929 g_chan_nr := new_chan_nr;
2930 f_sleep(1.0);
2931
2932 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
2933 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
2934 activate(as_Media());
2935
2936 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.handover.sccp_addr_bsc, g_pars.handover.sccp_addr_msc,
2937 f_gen_handover_req()));
2938 BSSAP.receive(BSSAP_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
2939
2940 /* The RSL Emulation magically accepts the Chan Activ behind the scenes. */
2941
2942 var PDU_BSSAP rx_bssap;
2943 var octetstring ho_command_str;
2944
2945 BSSAP.receive(tr_BSSMAP_HandoverRequestAcknowledge(?)) -> value rx_bssap;
2946
2947 ho_command_str := rx_bssap.pdu.bssmap.handoverRequestAck.layer3Information.layer3info;
2948 log("Received L3 Info in HO Request Ack: ", ho_command_str);
2949 var PDU_ML3_NW_MS ho_command := dec_PDU_ML3_NW_MS(ho_command_str);
2950 log("L3 Info in HO Request Ack is ", ho_command);
2951
2952 var GsmArfcn arfcn;
2953 var RslChannelNr actual_new_chan_nr;
2954 f_ChDesc2RslChanNr(ho_command.msgs.rrm.handoverCommand.channelDescription2,
2955 actual_new_chan_nr, arfcn);
2956
2957 if (actual_new_chan_nr != new_chan_nr) {
2958 log("ERROR: osmo-bsc assigned a different lchan than we assumed above -- this test will fail now.",
2959 " Assumed: ", new_chan_nr, " Assigned: ", actual_new_chan_nr);
2960 setverdict(fail);
2961 return;
2962 }
2963 log("Handover Command chan_nr is", actual_new_chan_nr);
2964
2965 /* Now the MSC forwards the RR Handover Command to the other BSC, which
2966 * tells the MS to handover to the new lchan. In this case, the MS
2967 * reports a Handover Failure to the old BSS, which forwards a BSSMAP
2968 * Handover Failure to the MSC. The procedure according to 3GPP TS
2969 * 48.008 3.1.5.3.2 "Handover Failure" is then that the MSC sends a
2970 * BSSMAP Clear Command: */
2971
2972 var myBSSMAP_Cause cause_val := GSM0808_CAUSE_RADIO_INTERFACE_FAILURE_REVERSION;
2973 var BssmapCause cause := enum2int(cause_val);
2974 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
2975
2976 /* Expecting MGCP to DLCX the endpoint's two connections: towards BTS and towards MSC */
2977 var MgcpCommand mgcp;
2978 interleave {
2979 [] BSSAP.receive(tr_BSSMAP_ClearComplete);
2980 [] MGCP.receive(tr_DLCX()) -> value mgcp {
2981 log("Got first DLCX: ", mgcp);
2982 }
2983 [] MGCP.receive(tr_DLCX()) -> value mgcp {
2984 log("Got second DLCX: ", mgcp);
2985 }
2986 }
2987 setverdict(pass);
2988 f_sleep(1.0);
2989
2990 setverdict(pass);
2991}
2992testcase TC_ho_in_fail_msc_clears() runs on test_CT {
2993 var MSC_ConnHdlr vc_conn;
2994 var TestHdlrParams pars := f_gen_test_hdlr_pars();
2995
2996 f_init(1, true);
2997 f_sleep(1.0);
2998
2999 pars.handover.sccp_addr_msc := g_bssap.sccp_addr_own;
3000 pars.handover.sccp_addr_bsc := g_bssap.sccp_addr_peer;
3001
3002 vc_conn := f_start_handler(refers(f_tc_ho_in_fail_msc_clears), pars);
3003 vc_conn.done;
3004}
3005
3006private function f_tc_ho_in_fail_msc_clears_after_ho_detect(charstring id) runs on MSC_ConnHdlr {
3007 /* Hack: the proper way would be to wait for the BSSMAP Handover Request ACK and extract the
3008 * actual assigned chan_nr from its L3 (RR Handover Command) message. But osmo-bsc starts acting
3009 * on the lchan even before we get a chance to evaluate the BSSMAP Handover Request ACK. So we
3010 * need to assume that osmo-bsc will activate TS 1 and already set up this lchan's RSL emulation
3011 * before we get started. */
3012 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(1, RSL_CHAN_NR_Bm_ACCH));
3013 f_rslem_register(0, new_chan_nr);
3014 g_chan_nr := new_chan_nr;
3015 f_sleep(1.0);
3016
3017 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
3018 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
3019 activate(as_Media());
3020
3021 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.handover.sccp_addr_bsc, g_pars.handover.sccp_addr_msc,
3022 f_gen_handover_req()));
3023 BSSAP.receive(BSSAP_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
3024
3025 /* The RSL Emulation magically accepts the Chan Activ behind the scenes. */
3026
3027 var PDU_BSSAP rx_bssap;
3028 var octetstring ho_command_str;
3029
3030 BSSAP.receive(tr_BSSMAP_HandoverRequestAcknowledge(?)) -> value rx_bssap;
3031
3032 ho_command_str := rx_bssap.pdu.bssmap.handoverRequestAck.layer3Information.layer3info;
3033 log("Received L3 Info in HO Request Ack: ", ho_command_str);
3034 var PDU_ML3_NW_MS ho_command := dec_PDU_ML3_NW_MS(ho_command_str);
3035 log("L3 Info in HO Request Ack is ", ho_command);
3036
3037 var GsmArfcn arfcn;
3038 var RslChannelNr actual_new_chan_nr;
3039 f_ChDesc2RslChanNr(ho_command.msgs.rrm.handoverCommand.channelDescription2,
3040 actual_new_chan_nr, arfcn);
3041
3042 if (actual_new_chan_nr != new_chan_nr) {
3043 log("ERROR: osmo-bsc assigned a different lchan than we assumed above -- this test will fail now.",
3044 " Assumed: ", new_chan_nr, " Assigned: ", actual_new_chan_nr);
3045 setverdict(fail);
3046 return;
3047 }
3048 log("Handover Command chan_nr is", actual_new_chan_nr);
3049
3050 /* Now the MSC forwards the RR Handover Command to the other BSC, which
3051 * tells the MS to handover to the new lchan. Here comes the new MS on
3052 * the new lchan with a Handover RACH: */
3053
3054 /* send handover detect */
3055
3056 RSL.send(ts_RSL_HANDO_DET(new_chan_nr));
3057
3058 BSSAP.receive(tr_BSSMAP_HandoverDetect);
3059
3060 /* The MSC chooses to clear the connection now, maybe we got the
3061 * Handover RACH on the new cell but the MS still signaled Handover
3062 * Failure to the old BSS? */
3063
3064 var myBSSMAP_Cause cause_val := GSM0808_CAUSE_RADIO_INTERFACE_FAILURE_REVERSION;
3065 var BssmapCause cause := enum2int(cause_val);
3066 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
3067
3068 /* Expecting MGCP to DLCX the endpoint's two connections: towards BTS and towards MSC */
3069 var MgcpCommand mgcp;
3070 interleave {
3071 [] BSSAP.receive(tr_BSSMAP_ClearComplete);
3072 [] MGCP.receive(tr_DLCX()) -> value mgcp {
3073 log("Got first DLCX: ", mgcp);
3074 }
3075 [] MGCP.receive(tr_DLCX()) -> value mgcp {
3076 log("Got second DLCX: ", mgcp);
3077 }
3078 }
3079 setverdict(pass);
3080 f_sleep(1.0);
3081}
3082testcase TC_ho_in_fail_msc_clears_after_ho_detect() runs on test_CT {
3083 var MSC_ConnHdlr vc_conn;
3084 var TestHdlrParams pars := f_gen_test_hdlr_pars();
3085
3086 f_init(1, true);
3087 f_sleep(1.0);
3088
3089 pars.handover.sccp_addr_msc := g_bssap.sccp_addr_own;
3090 pars.handover.sccp_addr_bsc := g_bssap.sccp_addr_peer;
3091
3092 vc_conn := f_start_handler(refers(f_tc_ho_in_fail_msc_clears_after_ho_detect), pars);
3093 vc_conn.done;
3094}
3095
3096/* The new BSS's lchan times out before the MSC decides that handover failed. */
3097private function f_tc_ho_in_fail_no_detect(charstring id) runs on MSC_ConnHdlr {
3098 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(1, RSL_CHAN_NR_Bm_ACCH));
3099 f_rslem_register(0, new_chan_nr);
3100 g_chan_nr := new_chan_nr;
3101 f_sleep(1.0);
3102
3103 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
3104 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
3105 activate(as_Media());
3106
3107 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.handover.sccp_addr_bsc, g_pars.handover.sccp_addr_msc,
3108 f_gen_handover_req()));
3109 BSSAP.receive(BSSAP_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
3110
3111 /* The RSL Emulation magically accepts the Chan Activ behind the scenes. */
3112
3113 var PDU_BSSAP rx_bssap;
3114 var octetstring ho_command_str;
3115
3116 BSSAP.receive(tr_BSSMAP_HandoverRequestAcknowledge(?)) -> value rx_bssap;
3117
3118 ho_command_str := rx_bssap.pdu.bssmap.handoverRequestAck.layer3Information.layer3info;
3119 log("Received L3 Info in HO Request Ack: ", ho_command_str);
3120 var PDU_ML3_NW_MS ho_command := dec_PDU_ML3_NW_MS(ho_command_str);
3121 log("L3 Info in HO Request Ack is ", ho_command);
3122
3123 var GsmArfcn arfcn;
3124 var RslChannelNr actual_new_chan_nr;
3125 f_ChDesc2RslChanNr(ho_command.msgs.rrm.handoverCommand.channelDescription2,
3126 actual_new_chan_nr, arfcn);
3127
3128 if (actual_new_chan_nr != new_chan_nr) {
3129 log("ERROR: osmo-bsc assigned a different lchan than we assumed above -- this test will fail now.",
3130 " Assumed: ", new_chan_nr, " Assigned: ", actual_new_chan_nr);
3131 setverdict(fail);
3132 return;
3133 }
3134 log("Handover Command chan_nr is", actual_new_chan_nr);
3135
3136 /* Now the MSC forwards the RR Handover Command to the other BSC, which
3137 * tells the MS to handover to the new lchan. But the MS never shows up
3138 * on the new lchan. */
3139
3140 BSSAP.receive(tr_BSSMAP_HandoverFailure);
3141
3142 /* Did osmo-bsc also send a Clear Request? */
3143 timer T := 0.5;
3144 T.start;
3145 alt {
3146 [] BSSAP.receive(tr_BSSMAP_ClearRequest);
3147 [] T.timeout { }
3148 }
3149
3150 /* MSC plays along with a Clear Command (no matter whether osmo-bsc
3151 * asked for it, this is a Handover Failure after all). */
3152
3153 var myBSSMAP_Cause cause_val := GSM0808_CAUSE_RADIO_INTERFACE_FAILURE_REVERSION;
3154 var BssmapCause cause := enum2int(cause_val);
3155 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
3156
3157 /* Expecting MGCP to DLCX the endpoint's two connections: towards BTS and towards MSC */
3158 var MgcpCommand mgcp;
3159 interleave {
3160 [] BSSAP.receive(tr_BSSMAP_ClearComplete);
3161 [] MGCP.receive(tr_DLCX()) -> value mgcp {
3162 log("Got first DLCX: ", mgcp);
3163 }
3164 [] MGCP.receive(tr_DLCX()) -> value mgcp {
3165 log("Got second DLCX: ", mgcp);
3166 }
3167 }
3168 setverdict(pass);
3169 f_sleep(1.0);
3170
3171 setverdict(pass);
3172}
3173testcase TC_ho_in_fail_no_detect() runs on test_CT {
3174 var MSC_ConnHdlr vc_conn;
3175 var TestHdlrParams pars := f_gen_test_hdlr_pars();
3176
3177 f_init(1, true);
3178 f_sleep(1.0);
3179
3180 pars.handover.sccp_addr_msc := g_bssap.sccp_addr_own;
3181 pars.handover.sccp_addr_bsc := g_bssap.sccp_addr_peer;
3182
3183 vc_conn := f_start_handler(refers(f_tc_ho_in_fail_no_detect), pars);
3184 vc_conn.done;
3185}
3186
3187/* Same as f_tc_ho_in_fail_no_detect, but MSC fails to send a Clear Command */
3188private function f_tc_ho_in_fail_no_detect2(charstring id) runs on MSC_ConnHdlr {
3189 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(1, RSL_CHAN_NR_Bm_ACCH));
3190 f_rslem_register(0, new_chan_nr);
3191 g_chan_nr := new_chan_nr;
3192 f_sleep(1.0);
3193
3194 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
3195 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
3196 activate(as_Media());
3197
3198 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.handover.sccp_addr_bsc, g_pars.handover.sccp_addr_msc,
3199 f_gen_handover_req()));
3200 BSSAP.receive(BSSAP_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
3201
3202 /* The RSL Emulation magically accepts the Chan Activ behind the scenes. */
3203
3204 var PDU_BSSAP rx_bssap;
3205 var octetstring ho_command_str;
3206
3207 BSSAP.receive(tr_BSSMAP_HandoverRequestAcknowledge(?)) -> value rx_bssap;
3208
3209 ho_command_str := rx_bssap.pdu.bssmap.handoverRequestAck.layer3Information.layer3info;
3210 log("Received L3 Info in HO Request Ack: ", ho_command_str);
3211 var PDU_ML3_NW_MS ho_command := dec_PDU_ML3_NW_MS(ho_command_str);
3212 log("L3 Info in HO Request Ack is ", ho_command);
3213
3214 var GsmArfcn arfcn;
3215 var RslChannelNr actual_new_chan_nr;
3216 f_ChDesc2RslChanNr(ho_command.msgs.rrm.handoverCommand.channelDescription2,
3217 actual_new_chan_nr, arfcn);
3218
3219 if (actual_new_chan_nr != new_chan_nr) {
3220 log("ERROR: osmo-bsc assigned a different lchan than we assumed above -- this test will fail now.",
3221 " Assumed: ", new_chan_nr, " Assigned: ", actual_new_chan_nr);
3222 setverdict(fail);
3223 return;
3224 }
3225 log("Handover Command chan_nr is", actual_new_chan_nr);
3226
3227 /* Now the MSC forwards the RR Handover Command to the other BSC, which
3228 * tells the MS to handover to the new lchan. But the MS never shows up
3229 * on the new lchan. */
3230
3231 BSSAP.receive(tr_BSSMAP_HandoverFailure);
3232
3233 /* MSC plays dumb and sends no Clear Command */
3234
3235 /* Expecting MGCP to DLCX the endpoint's two connections: towards BTS and towards MSC */
3236 var PDU_BSSAP rx_clear_request;
3237 var MgcpCommand mgcp;
3238 interleave {
3239 [] BSSAP.receive(tr_BSSMAP_ClearRequest) -> value rx_clear_request {
3240 var BssmapCause cause := bit2int(rx_clear_request.pdu.bssmap.clearRequest.cause.causeValue);
3241 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
3242 };
3243 [] BSSAP.receive(tr_BSSMAP_ClearComplete);
3244
3245 [] MGCP.receive(tr_DLCX()) -> value mgcp {
3246 log("Got first DLCX: ", mgcp);
3247 }
3248 [] MGCP.receive(tr_DLCX()) -> value mgcp {
3249 log("Got second DLCX: ", mgcp);
3250 }
3251 }
3252 setverdict(pass);
3253 f_sleep(1.0);
3254}
3255testcase TC_ho_in_fail_no_detect2() runs on test_CT {
3256 var MSC_ConnHdlr vc_conn;
3257 var TestHdlrParams pars := f_gen_test_hdlr_pars();
3258
3259 f_init(1, true);
3260 f_sleep(1.0);
3261
3262 pars.handover.sccp_addr_msc := g_bssap.sccp_addr_own;
3263 pars.handover.sccp_addr_bsc := g_bssap.sccp_addr_peer;
3264
3265 vc_conn := f_start_handler(refers(f_tc_ho_in_fail_no_detect2), pars);
3266 vc_conn.done;
3267}
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01003268
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +01003269/* OS#3041: Open and close N connections in a normal fashion, and expect no
3270 * BSSMAP Reset just because of that. */
3271testcase TC_bssap_rlsd_does_not_cause_bssmap_reset() runs on test_CT {
3272 var default d;
3273 var integer i;
3274 var DchanTuple dt;
3275
3276 f_init();
3277
3278 /* Wait for initial BSSMAP Reset to pass */
3279 f_sleep(4.0);
3280
3281 d := activate(no_bssmap_reset());
3282
3283 /* Setup up a number of connections and RLSD them again from the MSC
3284 * side. In the buggy behavior, the fourth one triggers BSSMAP Reset.
3285 * Let's do it some more times for good measure. */
Harald Weltec3260d92018-06-11 17:48:16 +02003286 for (i := 0; i < 4; i := i+1) {
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +01003287 /* Since we're doing a lot of runs, give each one a fresh
3288 * T_guard from the top. */
3289 T_guard.start;
3290
3291 /* Setup a BSSAP connection and clear it right away. This is
3292 * the MSC telling the BSC about a planned release, it's not an
3293 * erratic loss of a connection. */
Harald Weltea1897182018-06-11 13:53:09 +02003294 dt := f_est_dchan(int2oct(i,1), 23+i, '00010203040506'O);
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +01003295
3296 /* MSC disconnects (RLSD). */
3297 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
3298 }
3299
3300 /* In the buggy behavior, a timeout of 2 seconds happens between above
3301 * trigger (logs "SIGTRAN connection down, reconnecting...") and the
3302 * actual BSSMAP Reset. Wait a bit longer just to make sure. */
3303 f_sleep(4.0);
3304
3305 deactivate(d);
3306 f_shutdown_helper();
3307}
Harald Welte552620d2017-12-16 23:21:36 +01003308
Neels Hofmeyr4ff93282018-03-12 04:25:35 +01003309/* OS#3041: Open and close N connections in a normal fashion, and expect no
3310 * BSSMAP Reset just because of that. Invoke the release by a BSSMAP Clear from
3311 * the MSC. */
3312testcase TC_bssmap_clear_does_not_cause_bssmap_reset() runs on test_CT {
3313 var default d;
3314 var integer i;
3315 var DchanTuple dt;
3316 var BSSAP_N_DATA_ind rx_di;
Neels Hofmeyr4ff93282018-03-12 04:25:35 +01003317 var myBSSMAP_Cause cause_val := GSM0808_CAUSE_CALL_CONTROL;
3318 var BssmapCause cause := enum2int(cause_val);
3319
3320 f_init();
3321
3322 /* Wait for initial BSSMAP Reset to pass */
3323 f_sleep(4.0);
3324
3325 d := activate(no_bssmap_reset());
3326
3327 /* Setup up a number of connections and RLSD them again from the MSC
3328 * side. In the buggy behavior, the fourth one triggers BSSMAP Reset.
3329 * Let's do it some more times for good measure. */
3330 for (i := 0; i < 8; i := i+1) {
3331 /* Since we're doing a lot of runs, give each one a fresh
3332 * T_guard from the top. */
3333 T_guard.start;
3334
3335 /* Setup a BSSAP connection and clear it right away. This is
3336 * the MSC telling the BSC about a planned release, it's not an
3337 * erratic loss of a connection. */
Harald Weltea1897182018-06-11 13:53:09 +02003338 dt := f_est_dchan(int2oct(i,1), 23+i, '00010203040506'O);
Neels Hofmeyr4ff93282018-03-12 04:25:35 +01003339
3340 /* Instruct BSC to clear channel */
3341 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
3342
3343 /* expect BSC to disable the channel */
Harald Welte641fcbe2018-06-14 10:58:35 +02003344 f_exp_chan_rel_and_clear(dt, 0);
Neels Hofmeyr4ff93282018-03-12 04:25:35 +01003345 }
3346
3347 /* In the buggy behavior, a timeout of 2 seconds happens between above
3348 * trigger (logs "SIGTRAN connection down, reconnecting...") and the
3349 * actual BSSMAP Reset. Wait a bit longer just to make sure. */
3350 f_sleep(4.0);
3351
3352 deactivate(d);
3353 f_shutdown_helper();
3354}
3355
Neels Hofmeyrfd445c32018-03-09 15:39:31 +01003356/* OS#3041: Open and close N connections in a normal fashion, and expect no
3357 * BSSMAP Reset just because of that. Close connections from the MS side with a
3358 * Release Ind on RSL. */
3359testcase TC_ms_rel_ind_does_not_cause_bssmap_reset() runs on test_CT {
3360 var default d;
3361 var integer i;
3362 var DchanTuple dt;
3363 var BSSAP_N_DATA_ind rx_di;
Neels Hofmeyrfd445c32018-03-09 15:39:31 +01003364 var integer j;
3365
3366 f_init();
3367
3368 /* Wait for initial BSSMAP Reset to pass */
3369 f_sleep(4.0);
3370
3371 d := activate(no_bssmap_reset());
3372
3373 /* Setup up a number of connections and RLSD them again from the MSC
3374 * side. In the buggy behavior, the fourth one triggers BSSMAP Reset.
3375 * Let's do it some more times for good measure. */
3376 for (i := 0; i < 8; i := i+1) {
3377 /* Since we're doing a lot of runs, give each one a fresh
3378 * T_guard from the top. */
3379 T_guard.start;
3380
3381 /* Setup a BSSAP connection and clear it right away. This is
3382 * the MSC telling the BSC about a planned release, it's not an
3383 * erratic loss of a connection. */
3384 dt := f_est_dchan('23'O, 23, '00010203040506'O);
3385
3386 /* simulate RLL REL IND */
3387 f_ipa_tx(0, ts_RSL_REL_IND(dt.rsl_chan_nr, valueof(ts_RslLinkID_DCCH(0))));
3388
3389 /* expect Clear Request on MSC side */
3390 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearRequest)) -> value rx_di;
3391
3392 /* Instruct BSC to clear channel */
3393 var BssmapCause cause := bit2int(rx_di.userData.pdu.bssmap.clearRequest.cause.causeValue);
3394 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
3395
3396 /* expect BSC to disable the channel */
Harald Welte641fcbe2018-06-14 10:58:35 +02003397 f_exp_chan_rel_and_clear(dt, 0);
Neels Hofmeyrfd445c32018-03-09 15:39:31 +01003398 }
3399
3400 /* In the buggy behavior, a timeout of 2 seconds happens between above
3401 * trigger (logs "SIGTRAN connection down, reconnecting...") and the
3402 * actual BSSMAP Reset. Wait a bit longer just to make sure. */
3403 f_sleep(4.0);
3404
3405 deactivate(d);
3406 f_shutdown_helper();
3407}
3408
Harald Welte94e0c342018-04-07 11:33:23 +02003409/***********************************************************************
3410 * IPA style dynamic PDCH
3411 ***********************************************************************/
3412
3413private function f_dyn_ipa_pdch_act(integer bts_nr, integer trx_nr, integer ts_nr,
3414 template (omit) RSL_Cause nack := omit)
3415runs on test_CT {
3416 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(ts_nr));
3417 var RSL_Message rsl_unused;
3418 /* ask BSC via VTY to activate a given IPA style chan as PDCH */
3419 f_vty_ts_action("pdch activate", bts_nr, trx_nr, ts_nr);
3420 /* expect the BSC to issue the related RSL command */
3421 rsl_unused := f_exp_ipa_rx(0, tr_RSL_IPA_PDCH_ACT(chan_nr));
3422 if (istemplatekind(nack, "omit")) {
3423 /* respond with a related acknowledgement */
3424 f_ipa_tx(0, ts_RSL_IPA_PDCH_ACT_ACK(chan_nr, ts_RSL_IE_FrameNumber(2342)));
3425 } else {
3426 f_ipa_tx(0, ts_RSL_IPA_PDCH_ACT_NACK(chan_nr, valueof(nack)));
3427 }
3428}
3429
3430private function f_dyn_ipa_pdch_deact(integer bts_nr, integer trx_nr, integer ts_nr,
3431 template (omit) RSL_Cause nack := omit)
3432runs on test_CT {
3433 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(ts_nr));
3434 var RSL_Message rsl_unused;
3435 /* ask BSC via VTY to activate a given IPA style chan as PDCH */
3436 f_vty_ts_action("pdch deactivate", bts_nr, trx_nr, ts_nr);
3437 /* expect the BSC to issue the related RSL command */
3438 rsl_unused := f_exp_ipa_rx(0, tr_RSL_IPA_PDCH_DEACT(chan_nr));
3439 if (istemplatekind(nack, "omit")) {
3440 /* respond with a related acknowledgement */
3441 f_ipa_tx(0, ts_RSL_IPA_PDCH_DEACT_ACK(chan_nr));
3442 } else {
3443 f_ipa_tx(0, ts_RSL_IPA_PDCH_DEACT_NACK(chan_nr, valueof(nack)));
3444 }
3445}
3446
3447private function f_ts_dyn_mode_get(integer bts_nr, integer trx_nr, integer ts_nr)
3448runs on test_CT return charstring {
3449 var charstring cmd, resp;
3450 cmd := "show timeslot "&int2str(bts_nr)&" "&int2str(trx_nr)&" "&int2str(ts_nr);
Stefan Sperlingcff13562018-11-13 15:24:06 +01003451 return f_vty_transceive_match_regexp_retry(BSCVTY, cmd, "*\((*)\)*", 0, 4, 1.0);
Harald Welte94e0c342018-04-07 11:33:23 +02003452}
3453
3454private function f_ts_dyn_mode_assert(integer bts_nr, integer trx_nr, integer ts_nr,
3455 template charstring exp)
3456runs on test_CT {
3457 var charstring mode := f_ts_dyn_mode_get(bts_nr, trx_nr, ts_nr);
3458 if (not match(mode, exp)) {
3459 setverdict(fail, "Unexpected TS Mode: ", mode);
Daniel Willmannafce8662018-07-06 23:11:32 +02003460 mtc.stop;
Harald Welte94e0c342018-04-07 11:33:23 +02003461 }
3462}
3463
3464private function f_ts_set_chcomb(integer bts_nr, integer trx_nr, integer ts_nr, charstring chcomb)
3465runs on test_CT {
3466 f_vty_enter_cfg_ts(BSCVTY, bts_nr, trx_nr, ts_nr);
3467 f_vty_transceive(BSCVTY, "phys_chan_config " & chcomb);
3468 f_vty_transceive(BSCVTY, "end");
3469}
3470
3471private const charstring TCHF_MODE := "TCH/F mode";
3472private const charstring TCHH_MODE := "TCH/H mode";
3473private const charstring PDCH_MODE := "PDCH mode";
3474private const charstring NONE_MODE := "NONE mode";
3475
3476/* Test IPA PDCH activation / deactivation triggered by VTY */
3477testcase TC_dyn_pdch_ipa_act_deact() runs on test_CT {
3478 var RSL_Message rsl_unused;
3479
3480 /* change Timeslot 6 before f_init() starts RSL */
3481 f_init_vty();
3482 f_ts_set_chcomb(0, 0, 6, "TCH/F_PDCH");
3483 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
3484
3485 f_init(1, false);
3486 f_sleep(1.0);
3487
3488 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(6));
3489
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02003490 log("TCH/F_PDCH pchan starts out in TCH/F mode:");
Harald Welte94e0c342018-04-07 11:33:23 +02003491 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
3492 /* The BSC will activate the dynamic PDCH by default, so confirm that */
3493 rsl_unused := f_exp_ipa_rx(0, tr_RSL_IPA_PDCH_ACT(chan_nr));
3494 f_ipa_tx(0, ts_RSL_IPA_PDCH_ACT_ACK(chan_nr, ts_RSL_IE_FrameNumber(2342)));
3495 f_sleep(1.0);
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02003496 log("TCH/F_PDCH pchan, PDCH ACT was ACKed, so now in PDCH mode:");
Harald Welte94e0c342018-04-07 11:33:23 +02003497 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, PDCH_MODE);
3498
3499 /* De-activate it via VTY */
3500 f_dyn_ipa_pdch_deact(0, 0, chan_nr.tn);
3501 f_sleep(1.0);
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02003502 log("TCH/F_PDCH pchan, PDCH DEACT via VTY, so now back in TCH/F mode:");
Harald Welte94e0c342018-04-07 11:33:23 +02003503 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
3504
3505 /* re-activate it via VTY */
3506 f_dyn_ipa_pdch_act(0, 0, chan_nr.tn);
3507 f_sleep(1.0);
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02003508 log("TCH/F_PDCH pchan, PDCH ACT via VTY, so now in PDCH mode:");
Harald Welte94e0c342018-04-07 11:33:23 +02003509 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, PDCH_MODE);
3510
3511 /* and finally de-activate it again */
3512 f_dyn_ipa_pdch_deact(0, 0, chan_nr.tn);
3513 f_sleep(1.0);
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02003514 log("TCH/F_PDCH pchan, PDCH DEACT via VTY, so now back in TCH/F mode:");
Harald Welte94e0c342018-04-07 11:33:23 +02003515 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
3516
Neels Hofmeyr887e8f12018-06-27 01:01:55 +02003517 /* clean up config */
3518 f_ts_set_chcomb(0, 0, 6, "PDCH");
3519
Harald Welte94e0c342018-04-07 11:33:23 +02003520 setverdict(pass);
3521}
3522
3523/* Test IPA PDCH activation NACK */
3524testcase TC_dyn_pdch_ipa_act_nack() runs on test_CT {
3525 var RSL_Message rsl_unused;
3526
3527 /* change Timeslot 6 before f_init() starts RSL */
3528 f_init_vty();
3529 f_ts_set_chcomb(0, 0, 6, "TCH/F_PDCH");
3530 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
3531
3532 f_init(1, false);
3533 f_sleep(1.0);
3534
3535 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(6));
3536
3537 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
3538 /* The BSC will activate the dynamic PDCH by default, so confirm that */
3539 rsl_unused := f_exp_ipa_rx(0, tr_RSL_IPA_PDCH_ACT(chan_nr));
3540 f_ipa_tx(0, ts_RSL_IPA_PDCH_ACT_ACK(chan_nr, ts_RSL_IE_FrameNumber(2342)));
3541 f_sleep(1.0);
3542 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, PDCH_MODE);
3543
3544 /* De-activate it via VTY */
3545 f_dyn_ipa_pdch_deact(0, 0, chan_nr.tn);
3546 f_sleep(1.0);
3547 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
3548
3549 /* re-activate it via VTY, but fail that; check BSC still assumes TCH/F mode */
3550 f_dyn_ipa_pdch_act(0, 0, chan_nr.tn, RSL_ERR_EQUIPMENT_FAIL);
3551 f_sleep(1.0);
3552 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
3553
Neels Hofmeyr887e8f12018-06-27 01:01:55 +02003554 /* clean up config */
3555 f_ts_set_chcomb(0, 0, 6, "PDCH");
3556
Harald Welte94e0c342018-04-07 11:33:23 +02003557 setverdict(pass);
3558}
3559
3560
3561/***********************************************************************
3562 * Osmocom style dynamic PDCH
3563 ***********************************************************************/
3564
3565private function f_dyn_osmo_pdch_act(integer bts_nr, integer trx_nr, integer ts_nr,
3566 template (omit) RSL_Cause nack := omit)
3567runs on test_CT {
3568 var RslChannelNr chan_nr := valueof(t_RslChanNr_PDCH(ts_nr));
3569 var RSL_Message rsl_unused;
3570 /* ask BSC via VTY to activate a given IPA style chan as PDCH */
3571 /* FIXME: no VTY command to activate Osmocom PDCH !! */
3572 /* expect the BSC to issue the related RSL command */
3573 rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT(chan_nr, ?));
3574 if (istemplatekind(nack, "omit")) {
3575 /* respond with a related acknowledgement */
3576 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, 2342));
3577 } else {
3578 f_ipa_tx(0, ts_RSL_CHAN_ACT_NACK(chan_nr, valueof(nack)));
3579 }
3580}
3581
3582private function f_dyn_osmo_pdch_deact(integer bts_nr, integer trx_nr, integer ts_nr,
3583 template (omit) RSL_Cause nack := omit)
3584runs on test_CT {
3585 var RslChannelNr chan_nr := valueof(t_RslChanNr_PDCH(ts_nr));
3586 var RSL_Message rsl_unused;
3587 /* ask BSC via VTY to activate a given IPA style chan as PDCH */
3588 /* FIXME: no VTY command to activate Osmocom PDCH !! */
3589 /* expect the BSC to issue the related RSL command */
3590 rsl_unused := f_exp_ipa_rx(0, tr_RSL_RF_CHAN_REL(chan_nr));
3591 if (istemplatekind(nack, "omit")) {
3592 /* respond with a related acknowledgement */
3593 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(chan_nr));
3594 } else {
3595 //f_ipa_tx(0, ts_RSL_RF_CHAN_REL_NACK(chan_nr, valueof(nack)));
3596 }
3597}
3598
3599/* Test Osmocom dyn PDCH activation / deactivation triggered by VTY */
3600testcase TC_dyn_pdch_osmo_act_deact() runs on test_CT {
3601 var RSL_Message rsl_unused;
3602
3603 /* change Timeslot 6 before f_init() starts RSL */
3604 f_init_vty();
3605 f_ts_set_chcomb(0, 0, 6, "TCH/F_TCH/H_PDCH");
3606 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
3607
3608 f_init(1, false);
3609 f_sleep(1.0);
3610
3611 var RslChannelNr chan_nr := valueof(t_RslChanNr_PDCH(6));
3612
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02003613 log("TCH/F_TCH/H_PDCH pchan starts out in disabled mode:");
Harald Welte94e0c342018-04-07 11:33:23 +02003614 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, NONE_MODE);
3615 /* The BSC will activate the dynamic PDCH by default, so confirm that */
3616 rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(chan_nr, ?));
3617
3618 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, 2342));
3619 f_sleep(1.0);
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02003620 log("TCH/F_TCH/H_PDCH requested to PDCH ACT on startup, which was ACKed, so now in PDCH:");
Harald Welte94e0c342018-04-07 11:33:23 +02003621 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, PDCH_MODE);
3622
Neels Hofmeyr887e8f12018-06-27 01:01:55 +02003623 /* clean up config */
3624 f_ts_set_chcomb(0, 0, 6, "PDCH");
3625
Harald Welte94e0c342018-04-07 11:33:23 +02003626 setverdict(pass);
3627}
3628
3629/* Test Osmocom dyn PDCH activation NACK behavior */
3630testcase TC_dyn_pdch_osmo_act_nack() runs on test_CT {
3631 var RSL_Message rsl_unused;
3632
3633 /* change Timeslot 6 before f_init() starts RSL */
3634 f_init_vty();
3635 f_ts_set_chcomb(0, 0, 6, "TCH/F_TCH/H_PDCH");
3636 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
3637
3638 f_init(1, false);
3639 f_sleep(1.0);
3640
3641 var RslChannelNr chan_nr := valueof(t_RslChanNr_PDCH(6));
3642
3643 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, NONE_MODE);
3644 /* The BSC will activate the dynamic PDCH by default, so confirm that */
3645 rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(chan_nr, ?));
3646
3647 /* NACK this activation and expect the "show timeslot" mode still to be NONE */
3648 f_ipa_tx(0, ts_RSL_CHAN_ACT_NACK(chan_nr, RSL_ERR_EQUIPMENT_FAIL));
3649 f_sleep(1.0);
3650 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, NONE_MODE);
3651
Neels Hofmeyr887e8f12018-06-27 01:01:55 +02003652 /* clean up config */
3653 f_ts_set_chcomb(0, 0, 6, "PDCH");
3654
Harald Welte94e0c342018-04-07 11:33:23 +02003655 setverdict(pass);
3656}
3657
Stefan Sperling0796a822018-10-05 13:01:39 +02003658testcase TC_chopped_ipa_ping() runs on test_CT {
Stefan Sperling554123f2018-10-09 14:12:30 +02003659 const Integers bsc_ipa_ports := {mp_bsc_rsl_port, mp_bsc_oml_port, mp_bsc_ctrl_port};
Stefan Sperling0796a822018-10-05 13:01:39 +02003660 for (var integer i := 0; i < lengthof(bsc_ipa_ports); i := i + 1) {
3661 IPA_Testing.f_run_TC_chopped_ipa_ping(mp_bsc_ip, bsc_ipa_ports[i], CONNECT_TO_SERVER);
3662 }
3663}
3664
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02003665testcase TC_chopped_ipa_payload() runs on test_CT {
3666 const Integers bsc_ipa_ports := {mp_bsc_rsl_port, mp_bsc_oml_port
3667 /* TODO: mp_bsc_ctrl_port does not work yet */};
3668 for (var integer i := 0; i < lengthof(bsc_ipa_ports); i := i + 1) {
3669 IPA_Testing.f_run_TC_chopped_ipa_payload(mp_bsc_ip, bsc_ipa_ports[i], CONNECT_TO_SERVER);
3670 }
3671}
3672
3673
Harald Welte0ea2d5e2018-04-07 21:40:29 +02003674/* Dyn PDCH todo:
3675 * activate OSMO as TCH/F
3676 * activate OSMO as TCH/H
3677 * does the BSC-located PCU socket get the updated INFO?
3678 * what if no PCU is connected at the time?
3679 * is the info correct on delayed PCU (re)connect?
3680 */
Harald Welte94e0c342018-04-07 11:33:23 +02003681
Harald Welte28d943e2017-11-25 15:00:50 +01003682control {
Harald Welte898113b2018-01-31 18:32:21 +01003683 /* CTRL interface testing */
Harald Welte4003d112017-12-09 22:35:39 +01003684 execute( TC_ctrl_msc_connection_status() );
Stefan Sperlingb041b3d2018-01-03 17:14:55 +01003685 execute( TC_ctrl_msc0_connection_status() );
Harald Welte96c94412017-12-09 03:12:45 +01003686 execute( TC_ctrl() );
Harald Welte898113b2018-01-31 18:32:21 +01003687
3688 /* RSL DCHAN Channel ACtivation / Deactivation */
Harald Welteae026692017-12-09 01:03:01 +01003689 execute( TC_chan_act_noreply() );
Harald Welte4003d112017-12-09 22:35:39 +01003690 execute( TC_chan_act_counter() );
Harald Welteae026692017-12-09 01:03:01 +01003691 execute( TC_chan_act_ack_noest() );
3692 execute( TC_chan_act_ack_est_ind_noreply() );
3693 execute( TC_chan_act_ack_est_ind_refused() );
Harald Welte618ef642017-12-14 14:58:20 +01003694 execute( TC_chan_act_nack() );
Harald Welte799c97b2017-12-14 17:50:30 +01003695 execute( TC_chan_exhaustion() );
Vadim Yanitskiy1ff1fdf2018-11-27 01:32:57 +07003696 execute( TC_chan_deact_silence() );
Harald Welte4003d112017-12-09 22:35:39 +01003697 execute( TC_chan_rel_rll_rel_ind() );
3698 execute( TC_chan_rel_conn_fail() );
3699 execute( TC_chan_rel_hard_clear() );
Harald Welted8c36cd2017-12-09 23:05:31 +01003700 execute( TC_chan_rel_hard_rlsd() );
Harald Welte550daf92018-06-11 19:22:13 +02003701 execute( TC_chan_rel_hard_rlsd_ms_dead() );
Harald Welte85804d42017-12-10 14:11:58 +01003702 execute( TC_chan_rel_a_reset() );
Harald Welte6f521d82017-12-11 19:52:02 +01003703
Harald Weltecfe2c962017-12-15 12:09:32 +01003704 execute( TC_outbound_connect() );
Harald Welte898113b2018-01-31 18:32:21 +01003705
3706 /* Assignment related */
Harald Welte16a4adf2017-12-14 18:54:01 +01003707 execute( TC_assignment_cic_only() );
Harald Welte235ebf12017-12-15 14:18:16 +01003708 execute( TC_assignment_csd() );
3709 execute( TC_assignment_ctm() );
3710 execute( TC_assignment_sign() );
3711 execute( TC_assignment_fr_a5_0() );
3712 execute( TC_assignment_fr_a5_1() );
Harald Welte8f67d1d2018-05-25 20:38:42 +02003713 if (mp_bssap_cfg.transport == BSSAP_TRANSPORT_AoIP) {
3714 execute( TC_assignment_fr_a5_1_codec_missing() );
3715 }
Harald Welte235ebf12017-12-15 14:18:16 +01003716 execute( TC_assignment_fr_a5_3() );
3717 execute( TC_assignment_fr_a5_4() );
Harald Welte3c86ea02018-05-10 22:28:05 +02003718 execute( TC_ciph_mode_a5_0() );
3719 execute( TC_ciph_mode_a5_1() );
3720 execute( TC_ciph_mode_a5_3() );
Harald Welte16a4adf2017-12-14 18:54:01 +01003721
Harald Welte60aa5762018-03-21 19:33:13 +01003722 execute( TC_assignment_codec_fr() );
3723 execute( TC_assignment_codec_hr() );
3724 execute( TC_assignment_codec_efr() );
3725 execute( TC_assignment_codec_amr_f() );
3726 execute( TC_assignment_codec_amr_h() );
3727
Philipp Maierac09bfc2019-01-08 13:41:39 +01003728 execute( TC_assignment_codec_fr_exhausted_req_hr() );
3729 execute( TC_assignment_codec_fr_exhausted_req_fr() );
3730 execute( TC_assignment_codec_fr_exhausted_req_fr_hr() );
3731 execute( TC_assignment_codec_fr_exhausted_req_hr_fr() );
3732 execute( TC_assignment_codec_hr_exhausted_req_fr() );
3733 execute( TC_assignment_codec_hr_exhausted_req_hr() );
3734 execute( TC_assignment_codec_hr_exhausted_req_hr_fr() );
3735 execute( TC_assignment_codec_hr_exhausted_req_fr_hr() );
3736 execute( TC_assignment_codec_req_hr_fr() );
3737 execute( TC_assignment_codec_req_fr_hr() );
3738
Harald Welte898113b2018-01-31 18:32:21 +01003739 /* RLL Establish Indication on inactive DCHAN / SAPI */
Harald Welte5cd20ed2017-12-13 21:03:20 +01003740 execute( TC_rll_est_ind_inact_lchan() );
3741 execute( TC_rll_est_ind_inval_sapi1() );
3742 execute( TC_rll_est_ind_inval_sapi3() );
3743 execute( TC_rll_est_ind_inval_sacch() );
3744
Harald Welte898113b2018-01-31 18:32:21 +01003745 /* Paging related tests */
Harald Welte6f521d82017-12-11 19:52:02 +01003746 execute( TC_paging_imsi_nochan() );
3747 execute( TC_paging_tmsi_nochan() );
3748 execute( TC_paging_tmsi_any() );
3749 execute( TC_paging_tmsi_sdcch() );
3750 execute( TC_paging_tmsi_tch_f() );
3751 execute( TC_paging_tmsi_tch_hf() );
3752 execute( TC_paging_imsi_nochan_cgi() );
3753 execute( TC_paging_imsi_nochan_lac_ci() );
3754 execute( TC_paging_imsi_nochan_ci() );
3755 execute( TC_paging_imsi_nochan_lai() );
3756 execute( TC_paging_imsi_nochan_lac() );
3757 execute( TC_paging_imsi_nochan_all() );
Harald Welte751d3eb2018-01-31 15:51:06 +01003758 execute( TC_paging_imsi_nochan_plmn_lac_rnc() );
3759 execute( TC_paging_imsi_nochan_rnc() );
3760 execute( TC_paging_imsi_nochan_lac_rnc() );
3761 execute( TC_paging_imsi_nochan_lacs() );
3762 execute( TC_paging_imsi_nochan_lacs_empty() );
Stefan Sperling049a86e2018-03-20 15:51:00 +01003763 execute( TC_paging_imsi_nochan_cgi_unknown_cid() );
Harald Welte10985002017-12-12 09:29:15 +01003764 execute( TC_paging_imsi_a_reset() );
Harald Weltee65d40e2017-12-13 00:09:06 +01003765 execute( TC_paging_imsi_load() );
Philipp Maier779a7922018-02-16 11:00:37 +01003766 execute( TC_paging_counter() );
Pau Espin Pedrol3466cc52018-11-05 12:41:05 +01003767 execute( TC_paging_resp_unsol() );
Harald Welte4e9b9cc2017-12-14 18:31:02 +01003768
3769 execute( TC_rsl_drop_counter() );
Stefan Sperling830dc9d2018-02-12 21:08:28 +01003770 execute( TC_rsl_unknown_unit_id() );
3771
3772 execute( TC_oml_unknown_unit_id() );
Harald Welte898113b2018-01-31 18:32:21 +01003773
3774 execute( TC_classmark() );
3775 execute( TC_unsol_ass_fail() );
Harald Welteea99a002018-01-31 20:46:43 +01003776 execute( TC_unsol_ass_compl() );
Harald Weltefbf9b5e2018-01-31 20:41:23 +01003777 execute( TC_unsol_ho_fail() );
Harald Weltee3bd6582018-01-31 22:51:25 +01003778 execute( TC_err_82_short_msg() );
Harald Weltee9e02e42018-01-31 23:36:25 +01003779 execute( TC_err_84_unknown_msg() );
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01003780
Harald Welte261af4b2018-02-12 21:20:39 +01003781 execute( TC_ho_int() );
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01003782
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01003783 execute( TC_ho_out_of_this_bsc() );
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02003784 execute( TC_ho_out_fail_no_msc_response() );
3785 execute( TC_ho_out_fail_rr_ho_failure() );
3786 execute( TC_ho_out_fail_no_ho_detect() );
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01003787
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01003788 execute( TC_ho_into_this_bsc() );
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01003789 execute( TC_ho_in_fail_msc_clears() );
3790 execute( TC_ho_in_fail_msc_clears_after_ho_detect() );
3791 execute( TC_ho_in_fail_no_detect() );
3792 execute( TC_ho_in_fail_no_detect2() );
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +01003793
3794 execute( TC_bssap_rlsd_does_not_cause_bssmap_reset() );
Neels Hofmeyr4ff93282018-03-12 04:25:35 +01003795 execute( TC_bssmap_clear_does_not_cause_bssmap_reset() );
Neels Hofmeyrfd445c32018-03-09 15:39:31 +01003796 execute( TC_ms_rel_ind_does_not_cause_bssmap_reset() );
Harald Welte94e0c342018-04-07 11:33:23 +02003797
3798 execute( TC_dyn_pdch_ipa_act_deact() );
3799 execute( TC_dyn_pdch_ipa_act_nack() );
3800 execute( TC_dyn_pdch_osmo_act_deact() );
3801 execute( TC_dyn_pdch_osmo_act_nack() );
Harald Welte99f3ca02018-06-14 13:40:29 +02003802
Stefan Sperling0796a822018-10-05 13:01:39 +02003803 execute( TC_chopped_ipa_ping() );
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02003804 execute( TC_chopped_ipa_payload() );
Stefan Sperling0796a822018-10-05 13:01:39 +02003805
Harald Welte99f3ca02018-06-14 13:40:29 +02003806 /* at bottom as they might crash OsmoBSC before OS#3182 is fixed */
3807 execute( TC_early_conn_fail() );
3808 execute( TC_late_conn_fail() );
3809
Harald Welte28d943e2017-11-25 15:00:50 +01003810}
3811
3812}