blob: d71d3dc4e6e42d24c5ded8172b045209bb3cf6ae [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;
33import from RSL_Types all;
Harald Welte624f9632017-12-16 19:26:04 +010034import from RSL_Emulation all;
Daniel Willmann191e0d92018-01-17 12:44:35 +010035import from MGCP_Emulation all;
Harald Welte28d943e2017-11-25 15:00:50 +010036
Harald Welte96c94412017-12-09 03:12:45 +010037import from Osmocom_CTRL_Functions all;
Harald Weltea5d2ab22017-12-09 14:21:42 +010038import from Osmocom_CTRL_Types all;
Harald Welteffe55fc2018-01-17 22:39:54 +010039import from Osmocom_CTRL_Adapter all;
Harald Welte96c94412017-12-09 03:12:45 +010040
Harald Weltebc03c762018-02-12 18:09:38 +010041import from Osmocom_VTY_Functions all;
42import from TELNETasp_PortType all;
43
Harald Welte6f521d82017-12-11 19:52:02 +010044import from MobileL3_CommonIE_Types all;
Harald Weltee3bd6582018-01-31 22:51:25 +010045import from MobileL3_Types all;
Harald Welte6f521d82017-12-11 19:52:02 +010046import from L3_Templates all;
47import from GSM_RR_Types all;
48
Neels Hofmeyr4ff93282018-03-12 04:25:35 +010049import from BSSMAP_Templates all;
50
Harald Welte5d1a2202017-12-13 19:51:29 +010051const integer NUM_BTS := 3;
Harald Welteae026692017-12-09 01:03:01 +010052const float T3101_MAX := 12.0;
Harald Welte28d943e2017-11-25 15:00:50 +010053
Harald Welte799c97b2017-12-14 17:50:30 +010054/* make sure to sync this with the osmo-bts.cfg you're using */
Philipp Maiercb6cc482018-03-26 13:08:00 +020055const integer NUM_TCHH_PER_BTS := 2;
56const integer NUM_TCHF_PER_BTS := 4;
Harald Weltedd8cbf32018-01-28 12:07:52 +010057const integer NUM_SDCCH_PER_BTS := 4;
Harald Welte799c97b2017-12-14 17:50:30 +010058
Harald Welte4003d112017-12-09 22:35:39 +010059
Harald Welte21b46bd2017-12-17 19:46:32 +010060/* per-BTS state which we keep */
Harald Welte96c94412017-12-09 03:12:45 +010061type record BTS_State {
Harald Welte21b46bd2017-12-17 19:46:32 +010062 /* component reference to the IPA_Client component used for RSL */
Harald Weltea5d2ab22017-12-09 14:21:42 +010063 IPA_Client rsl
Harald Welte96c94412017-12-09 03:12:45 +010064}
65
Harald Weltea4ca4462018-02-09 00:17:14 +010066type component test_CT extends CTRL_Adapter_CT {
Harald Welte21b46bd2017-12-17 19:46:32 +010067 /* Array of per-BTS state */
Harald Welte96c94412017-12-09 03:12:45 +010068 var BTS_State bts[NUM_BTS];
Harald Welte89ab1912018-02-23 18:56:29 +010069 /* RSL common Channel Port (for RSL_Emulation) */
70 port RSL_CCHAN_PT RSL_CCHAN[NUM_BTS];
Harald Welte21b46bd2017-12-17 19:46:32 +010071 /* array of per-BTS RSL test ports */
Harald Welteae026692017-12-09 01:03:01 +010072 port IPA_RSL_PT IPA_RSL[NUM_BTS];
Stefan Sperling830dc9d2018-02-12 21:08:28 +010073 port IPA_CODEC_PT IPA; /* Required for compilation of TC_rsl_unknown_unit_id() */
Harald Weltea5d2ab22017-12-09 14:21:42 +010074
Daniel Willmann191e0d92018-01-17 12:44:35 +010075 var MGCP_Emulation_CT vc_MGCP;
Harald Weltebc03c762018-02-12 18:09:38 +010076 port TELNETasp_PT BSCVTY;
Daniel Willmann191e0d92018-01-17 12:44:35 +010077
Harald Weltea4ca4462018-02-09 00:17:14 +010078 var BSSAP_Adapter g_bssap;
79 /* for old legacy-tests only */
80 port BSSAP_CODEC_PT BSSAP;
81
Harald Welte21b46bd2017-12-17 19:46:32 +010082 /* are we initialized yet */
Harald Welte28d943e2017-11-25 15:00:50 +010083 var boolean g_initialized := false;
Harald Welte21b46bd2017-12-17 19:46:32 +010084
85 /* global test case guard timer */
Harald Welteae026692017-12-09 01:03:01 +010086 timer T_guard := 30.0;
87
Harald Welte28d943e2017-11-25 15:00:50 +010088}
89
90modulepar {
Harald Welte21b46bd2017-12-17 19:46:32 +010091 /* IP address at which the BSC can be reached */
Harald Welte696ddb62017-12-08 14:01:43 +010092 charstring mp_bsc_ip := "127.0.0.1";
Stefan Sperling830dc9d2018-02-12 21:08:28 +010093 /* port number to which to establish the IPA OML connections */
94 integer mp_bsc_oml_port := 3002;
Harald Welte21b46bd2017-12-17 19:46:32 +010095 /* port number to which to establish the IPA RSL connections */
Harald Welte696ddb62017-12-08 14:01:43 +010096 integer mp_bsc_rsl_port := 3003;
Harald Welte21b46bd2017-12-17 19:46:32 +010097 /* port number to which to establish the IPA CTRL connection */
Harald Welte96c94412017-12-09 03:12:45 +010098 integer mp_bsc_ctrl_port := 4249;
Daniel Willmann191e0d92018-01-17 12:44:35 +010099 /* IP address at which the test binds */
100 charstring mp_test_ip := "127.0.0.1";
Harald Weltea4ca4462018-02-09 00:17:14 +0100101
102 BSSAP_Configuration mp_bssap_cfg := {
Harald Welte7ef51aa2018-04-16 19:16:01 +0200103 transport := BSSAP_TRANSPORT_AoIP,
Harald Weltea4ca4462018-02-09 00:17:14 +0100104 sccp_service_type := "mtp3_itu",
105 sctp_addr := { 23905, "127.0.0.1", 2905, "127.0.0.1" },
106 own_pc := 185,
107 own_ssn := 254,
108 peer_pc := 187,
109 peer_ssn := 254,
Philipp Maier38d68942018-03-29 15:38:09 +0200110 sio := '83'O,
111 rctx := 0
Harald Weltea4ca4462018-02-09 00:17:14 +0100112 };
113}
114
Philipp Maier282ca4b2018-02-27 17:17:00 +0100115private function f_shutdown_helper() runs on test_CT {
Philipp Maier282ca4b2018-02-27 17:17:00 +0100116 setverdict(pass);
Daniel Willmannafce8662018-07-06 23:11:32 +0200117 mtc.stop;
Philipp Maier282ca4b2018-02-27 17:17:00 +0100118}
119
Harald Weltea4ca4462018-02-09 00:17:14 +0100120private function f_legacy_bssap_reset() runs on test_CT {
121 var BSSAP_N_UNITDATA_ind ud_ind;
122 timer T := 5.0;
123 BSSAP.send(ts_BSSAP_UNITDATA_req(g_bssap.sccp_addr_peer, g_bssap.sccp_addr_own, ts_BSSMAP_Reset(0)));
124 T.start;
125 alt {
126 [] BSSAP.receive(tr_BSSAP_UNITDATA_ind(g_bssap.sccp_addr_own, g_bssap.sccp_addr_peer, tr_BSSMAP_ResetAck)) {
127 log("Received RESET-ACK in response to RESET, we're ready to go!");
128 }
129 [] BSSAP.receive(tr_BSSAP_UNITDATA_ind(?, ?, tr_BSSMAP_Reset)) -> value ud_ind {
130 log("Respoding to inbound RESET with RESET-ACK");
131 BSSAP.send(ts_BSSAP_UNITDATA_req(ud_ind.callingAddress, ud_ind.calledAddress,
132 ts_BSSMAP_ResetAck));
133 repeat;
134 }
135 [] BSSAP.receive { repeat; }
136 [] T.timeout { setverdict(fail, "Waiting for RESET-ACK after sending RESET"); }
137 }
Harald Welte28d943e2017-11-25 15:00:50 +0100138}
139
Harald Welteae026692017-12-09 01:03:01 +0100140type record IPA_Client {
Harald Welte21b46bd2017-12-17 19:46:32 +0100141 /* IPA Emulation component reference */
Harald Welteae026692017-12-09 01:03:01 +0100142 IPA_Emulation_CT vc_IPA,
Harald Welte21b46bd2017-12-17 19:46:32 +0100143 /* Unit-ID and other CCM parameters to use for IPA client emulation */
Harald Welteae026692017-12-09 01:03:01 +0100144 IPA_CCM_Parameters ccm_pars,
Harald Welte21b46bd2017-12-17 19:46:32 +0100145 /* String identifier for this IPA Client */
Harald Welte624f9632017-12-16 19:26:04 +0100146 charstring id,
Harald Welte21b46bd2017-12-17 19:46:32 +0100147 /* Associated RSL Emulation Component (if any). Only used in "Handler mode" */
Harald Welte624f9632017-12-16 19:26:04 +0100148 RSL_Emulation_CT vc_RSL optional
Harald Welte28d943e2017-11-25 15:00:50 +0100149}
150
Harald Welte21b46bd2017-12-17 19:46:32 +0100151/*! Start the IPA/RSL related bits for one IPA_Client.
152 * \param clnt IPA_Client for which to establish
153 * \param bsc_host IP address / hostname of the BSC
154 * \param bsc_port TCP port number of the BSC
155 * \param i number identifying this BTS
156 * \param handler_mode Start an RSL_Emulation_CT component (true) or not (false) */
Harald Welte624f9632017-12-16 19:26:04 +0100157function f_ipa_rsl_start(inout IPA_Client clnt, charstring bsc_host, PortNumber bsc_port, integer i,
158 boolean handler_mode := false)
Harald Welte28d943e2017-11-25 15:00:50 +0100159runs on test_CT {
Harald Welteae026692017-12-09 01:03:01 +0100160 timer T := 10.0;
161
Harald Welte96c94412017-12-09 03:12:45 +0100162 clnt.id := "IPA" & int2str(i) & "-RSL";
Harald Welteae026692017-12-09 01:03:01 +0100163 clnt.vc_IPA := IPA_Emulation_CT.create(clnt.id & "-IPA");
164 clnt.ccm_pars := c_IPA_default_ccm_pars;
165 clnt.ccm_pars.name := "Osmocom TTCN-3 BTS Simulator";
166 clnt.ccm_pars.unit_id := int2str(1234+i) & "/0/0";
Harald Welte624f9632017-12-16 19:26:04 +0100167 if (handler_mode) {
168 clnt.vc_RSL := RSL_Emulation_CT.create(clnt.id & "-RSL");
Harald Welte89ab1912018-02-23 18:56:29 +0100169 connect(clnt.vc_RSL:CCHAN_PT, self:RSL_CCHAN[i]);
Harald Welte624f9632017-12-16 19:26:04 +0100170 }
Harald Welteae026692017-12-09 01:03:01 +0100171
172 map(clnt.vc_IPA:IPA_PORT, system:IPA_CODEC_PT);
Harald Welte624f9632017-12-16 19:26:04 +0100173 if (handler_mode) {
174 connect(clnt.vc_IPA:IPA_RSL_PORT, clnt.vc_RSL:IPA_PT);
175 } else {
176 connect(clnt.vc_IPA:IPA_RSL_PORT, self:IPA_RSL[i]);
177 }
Harald Welteae026692017-12-09 01:03:01 +0100178
Harald Welte5d1a2202017-12-13 19:51:29 +0100179 clnt.vc_IPA.start(IPA_Emulation.main_client(bsc_host, bsc_port, "", 10000+i, clnt.ccm_pars));
Harald Welte624f9632017-12-16 19:26:04 +0100180 if (handler_mode) {
181 clnt.vc_RSL.start(RSL_Emulation.main());
182 return;
183 }
Harald Welteae026692017-12-09 01:03:01 +0100184
185 /* wait for IPA RSL link to connect and send ID ACK */
186 T.start;
187 alt {
188 [] IPA_RSL[i].receive(ASP_IPA_Event:{up_down := ASP_IPA_EVENT_ID_ACK}) {
189 T.stop;
190 IPA_RSL[i].send(ts_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0,ts_RSL_PAGING_LOAD_IND(23)));
191 }
Harald Welte60e823a2017-12-10 14:10:59 +0100192 [] IPA_RSL[i].receive(ASP_IPA_Event:?) { repeat }
Harald Welteae026692017-12-09 01:03:01 +0100193 [] IPA_RSL[i].receive { repeat }
194 [] T.timeout {
Harald Welte96c94412017-12-09 03:12:45 +0100195 setverdict(fail, "Timeout RSL waiting for ASP_IPA_EVENT_ID_ACK");
Daniel Willmannafce8662018-07-06 23:11:32 +0200196 mtc.stop;
Harald Welteae026692017-12-09 01:03:01 +0100197 }
198 }
199}
200
Harald Welte12055472018-03-17 20:10:08 +0100201function f_ipa_rsl_stop(inout IPA_Client clnt) runs on test_CT {
202 if (not isbound(clnt) or not isbound(clnt.vc_IPA)) {
203 return;
204 }
205 clnt.vc_IPA.stop;
206 if (isbound(clnt.vc_RSL)) {
207 clnt.vc_RSL.stop;
208 }
209}
210
Harald Welte21b46bd2017-12-17 19:46:32 +0100211/* Wait for the OML connection to be brought up by the external osmo-bts-omldummy */
Harald Weltea5d2ab22017-12-09 14:21:42 +0100212function f_wait_oml(integer bts_nr, charstring status, float secs_max) runs on test_CT {
213 timer T := secs_max;
214 T.start;
215 while (true) {
216 if (f_ctrl_get_bts(IPA_CTRL, bts_nr, "oml-connection-state") == status) {
217 T.stop;
Harald Weltebd868bd2017-12-10 18:28:40 +0100218 /* the 'degraded' state exists from OML connection time, and we have to wait
219 * until all MO's are initialized */
220 T.start(1.0);
221 T.timeout;
Harald Weltea5d2ab22017-12-09 14:21:42 +0100222 return;
223 }
Harald Weltef0d6ac62017-12-17 17:02:21 +0100224 f_sleep(0.1);
Harald Weltea5d2ab22017-12-09 14:21:42 +0100225 if (not T.running) {
226 setverdict(fail, "Timeout waiting for oml-connection-state ", status);
Daniel Willmannafce8662018-07-06 23:11:32 +0200227 mtc.stop;
Harald Weltea5d2ab22017-12-09 14:21:42 +0100228 }
229 }
230}
231
Harald Welte21b46bd2017-12-17 19:46:32 +0100232/* global altstep for global guard timer; also takes care of responding RESET witH RESET-ACK */
Harald Welteae026692017-12-09 01:03:01 +0100233altstep as_Tguard() runs on test_CT {
Harald Welte60e823a2017-12-10 14:10:59 +0100234 var BSSAP_N_UNITDATA_ind ud_ind;
Neels Hofmeyrcc3f76a2018-03-12 01:43:25 +0100235 [] T_guard.timeout {
236 setverdict(fail, "Timeout of T_guard");
Daniel Willmannafce8662018-07-06 23:11:32 +0200237 mtc.stop;
Neels Hofmeyrcc3f76a2018-03-12 01:43:25 +0100238 }
Harald Welte60e823a2017-12-10 14:10:59 +0100239 /* always respond with RESET ACK to RESET */
240 [] BSSAP.receive(tr_BSSAP_UNITDATA_ind(?, ?, tr_BSSMAP_Reset)) -> value ud_ind {
241 BSSAP.send(ts_BSSAP_UNITDATA_req(ud_ind.callingAddress, ud_ind.calledAddress,
242 ts_BSSMAP_ResetAck));
Harald Welte69c1c262017-12-13 21:02:08 +0100243 repeat;
Harald Welte60e823a2017-12-10 14:10:59 +0100244 }
Harald Welte28d943e2017-11-25 15:00:50 +0100245}
246
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +0100247altstep no_bssmap_reset() runs on test_CT {
248 [] BSSAP.receive(tr_BSSAP_UNITDATA_ind(?, ?, tr_BSSMAP_Reset)) {
249 setverdict(fail, "unexpected BSSMAP Reset");
Daniel Willmannafce8662018-07-06 23:11:32 +0200250 mtc.stop;
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +0100251 }
252}
253
Daniel Willmann191e0d92018-01-17 12:44:35 +0100254function f_init_mgcp(charstring id) runs on test_CT {
255 id := id & "-MGCP";
256
257 var MGCPOps ops := {
258 create_cb := refers(MGCP_Emulation.ExpectedCreateCallback),
259 unitdata_cb := refers(MGCP_Emulation.DummyUnitdataCallback)
260 };
261 var MGCP_conn_parameters mgcp_pars := {
262 callagent_ip := mp_bsc_ip,
Harald Welte9e4273e2018-01-29 22:01:22 +0100263 callagent_udp_port := -1,
Daniel Willmann191e0d92018-01-17 12:44:35 +0100264 mgw_ip := mp_test_ip,
265 mgw_udp_port := 2427
266 };
267
268 vc_MGCP := MGCP_Emulation_CT.create(id);
269 vc_MGCP.start(MGCP_Emulation.main(ops, mgcp_pars, id));
270}
271
Harald Welte94e0c342018-04-07 11:33:23 +0200272private function f_init_vty(charstring id := "foo") runs on test_CT {
273 if (BSCVTY.checkstate("Mapped")) {
274 /* skip initialization if already executed once */
275 return;
276 }
Harald Weltebc03c762018-02-12 18:09:38 +0100277 map(self:BSCVTY, system:BSCVTY);
278 f_vty_set_prompts(BSCVTY);
279 f_vty_transceive(BSCVTY, "enable");
280}
281
Harald Welte21b46bd2017-12-17 19:46:32 +0100282/* global initialization function
283 * \param nr_bts Number of BTSs we should start/bring up
284 * \param handler_mode Start an RSL_Emulation_CT component (true) or not (false) */
Harald Welte89d42e82017-12-17 16:42:41 +0100285function f_init(integer nr_bts := NUM_BTS, boolean handler_mode := false) runs on test_CT {
Harald Welte28d943e2017-11-25 15:00:50 +0100286 var integer i;
Harald Welte28d943e2017-11-25 15:00:50 +0100287
Harald Welteae026692017-12-09 01:03:01 +0100288 if (g_initialized) {
289 return;
Harald Welte28d943e2017-11-25 15:00:50 +0100290 }
Harald Welteae026692017-12-09 01:03:01 +0100291 g_initialized := true;
292
293 /* Call a function of our 'parent component' BSSAP_Adapter_CT to start the
294 * MSC-side BSSAP emulation */
Harald Welte67089ee2018-01-17 22:19:03 +0100295 if (handler_mode) {
Harald Weltea4ca4462018-02-09 00:17:14 +0100296 f_bssap_init(g_bssap, mp_bssap_cfg, "VirtMSC", MSC_BssmapOps);
Harald Welte4bcbd172018-05-27 19:47:44 +0200297 f_bssap_start(g_bssap);
Harald Welte67089ee2018-01-17 22:19:03 +0100298 } else {
Harald Weltea4ca4462018-02-09 00:17:14 +0100299 f_bssap_init(g_bssap, mp_bssap_cfg, "VirtMSC", omit);
300 connect(self:BSSAP, g_bssap.vc_SCCP:SCCP_SP_PORT);
Harald Welte4bcbd172018-05-27 19:47:44 +0200301 f_bssap_start(g_bssap);
Harald Weltea4ca4462018-02-09 00:17:14 +0100302 f_legacy_bssap_reset();
Harald Welte67089ee2018-01-17 22:19:03 +0100303 }
Harald Welted5833a82018-05-27 16:52:56 +0200304
Harald Welteffe55fc2018-01-17 22:39:54 +0100305 f_ipa_ctrl_start(mp_bsc_ip, mp_bsc_ctrl_port);
Harald Welte28d943e2017-11-25 15:00:50 +0100306
Daniel Willmann191e0d92018-01-17 12:44:35 +0100307 f_init_mgcp("VirtMSC");
Harald Weltebc03c762018-02-12 18:09:38 +0100308 f_init_vty("VirtMSC");
Daniel Willmann191e0d92018-01-17 12:44:35 +0100309
Harald Welte89d42e82017-12-17 16:42:41 +0100310 for (i := 0; i < nr_bts; i := i+1) {
Harald Weltea5d2ab22017-12-09 14:21:42 +0100311 /* wait until osmo-bts-omldummy has respawned */
312 f_wait_oml(i, "degraded", 5.0);
313 /* start RSL connection */
Harald Welte624f9632017-12-16 19:26:04 +0100314 f_ipa_rsl_start(bts[i].rsl, mp_bsc_ip, mp_bsc_rsl_port, i, handler_mode);
Harald Weltea5d2ab22017-12-09 14:21:42 +0100315 /* wait until BSC tells us "connected" */
316 f_wait_oml(i, "connected", 5.0);
Harald Welte696ddb62017-12-08 14:01:43 +0100317 }
318
Harald Welteae026692017-12-09 01:03:01 +0100319 T_guard.start;
320 activate(as_Tguard());
Harald Welte28d943e2017-11-25 15:00:50 +0100321}
322
Harald Welte21b46bd2017-12-17 19:46:32 +0100323/* expect to receive a RSL message matching a specified templaten on a given BTS / stream */
Harald Welteae026692017-12-09 01:03:01 +0100324function f_exp_ipa_rx(integer bts_nr, template RSL_Message t_rx, float t_secs := 2.0, IpaStreamId sid := IPAC_PROTO_RSL_TRX0)
325runs on test_CT return RSL_Message {
326 var ASP_RSL_Unitdata rx_rsl_ud;
327 timer T := t_secs;
328
329 T.start;
330 alt {
331 [] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(sid, t_rx)) -> value rx_rsl_ud {
332 T.stop;
333 }
334 [] IPA_RSL[bts_nr].receive { repeat; }
Harald Welteb2917702017-12-10 15:48:52 +0100335 [] T.timeout {
336 setverdict(fail, "Timeout expecting ", t_rx);
Daniel Willmannafce8662018-07-06 23:11:32 +0200337 mtc.stop;
Harald Welteb2917702017-12-10 15:48:52 +0100338 }
Harald Welteae026692017-12-09 01:03:01 +0100339 }
340 return rx_rsl_ud.rsl;
341}
342
Harald Welte21b46bd2017-12-17 19:46:32 +0100343/* helper function to transmit RSL on a given BTS/stream */
Harald Welteae026692017-12-09 01:03:01 +0100344function f_ipa_tx(integer bts_nr, template RSL_Message t_tx, IpaStreamId sid := IPAC_PROTO_RSL_TRX0)
345runs on test_CT {
346 IPA_RSL[bts_nr].send(ts_ASP_RSL_UD(sid, t_tx));
347}
348
349
Harald Welte4003d112017-12-09 22:35:39 +0100350/* verify we get a CHAN_ACT after CHAN RQD */
Harald Welteae026692017-12-09 01:03:01 +0100351testcase TC_chan_act_noreply() runs on test_CT {
352 var BSSAP_N_UNITDATA_ind ud_ind;
Harald Welte930d0a72018-03-22 22:08:40 +0100353 var RSL_Message rsl_unused;
Harald Welte28d943e2017-11-25 15:00:50 +0100354
Harald Welte89d42e82017-12-17 16:42:41 +0100355 f_init(1);
Harald Welte28d943e2017-11-25 15:00:50 +0100356
Harald Welteae026692017-12-09 01:03:01 +0100357 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 +0100358 rsl_unused := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
Harald Welteae026692017-12-09 01:03:01 +0100359 setverdict(pass);
Harald Welte28d943e2017-11-25 15:00:50 +0100360}
361
Harald Welte4003d112017-12-09 22:35:39 +0100362/* verify if the "chreq:total" counter increments as expected */
363testcase TC_chan_act_counter() runs on test_CT {
364 var BSSAP_N_UNITDATA_ind ud_ind;
365 var integer chreq_total;
Harald Welte930d0a72018-03-22 22:08:40 +0100366 var RSL_Message rsl_unused;
Harald Welte4003d112017-12-09 22:35:39 +0100367
Harald Welte89d42e82017-12-17 16:42:41 +0100368 f_init(1);
Harald Welte4003d112017-12-09 22:35:39 +0100369
370 chreq_total := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:total");
371 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 +0100372 rsl_unused := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
Harald Welte4003d112017-12-09 22:35:39 +0100373 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:total", chreq_total+1);
374
375 setverdict(pass);
376}
377
Harald Welteae026692017-12-09 01:03:01 +0100378/* CHAN RQD -> CHAN ACT -> CHAN ACT ACK -> RF CHAN REL */
379testcase TC_chan_act_ack_noest() runs on test_CT {
380 var RSL_Message rx_rsl;
381
Harald Welte89d42e82017-12-17 16:42:41 +0100382 f_init(1);
Harald Welteae026692017-12-09 01:03:01 +0100383
384 /* Send CHAN RQD and wait for allocation; acknowledge it */
Harald Welted6939652017-12-13 21:02:46 +0100385 var RslChannelNr chan_nr := f_chreq_act_ack();
Harald Welteae026692017-12-09 01:03:01 +0100386
387 /* expect BSC to disable the channel again if there's no RLL EST IND */
388 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL), T3101_MAX);
389
390 setverdict(pass);
391}
392
393/* Test behavior if MSC never answers to CR */
394testcase TC_chan_act_ack_est_ind_noreply() runs on test_CT {
Harald Weltef77aef62018-01-28 15:35:42 +0100395 var RslLinkId main_dcch := valueof(ts_RslLinkID_DCCH(0));
396 var IpaStreamId sid := IPAC_PROTO_RSL_TRX0;
Harald Welteae026692017-12-09 01:03:01 +0100397 var RSL_Message rx_rsl;
Harald Weltef77aef62018-01-28 15:35:42 +0100398 var ASP_RSL_Unitdata rx_rsl_ud;
Harald Welteae026692017-12-09 01:03:01 +0100399
Harald Welte89d42e82017-12-17 16:42:41 +0100400 f_init(1);
Harald Welteae026692017-12-09 01:03:01 +0100401
402 /* Send CHAN RQD and wait for allocation; acknowledge it */
Harald Welted6939652017-12-13 21:02:46 +0100403 var RslChannelNr chan_nr := f_chreq_act_ack();
Harald Welteae026692017-12-09 01:03:01 +0100404
405 var octetstring l3 := '00010203040506'O
406 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
407
408 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3)));
409
410 /* expect BSC to disable the channel again if there's no response from MSC */
Harald Weltef77aef62018-01-28 15:35:42 +0100411 /* MS waits 20s (T3210) at LU; 10s (T3230) at CM SERV REQ and 5s (T3220) AT detach */
412 IPA_RSL[0].clear;
413 alt {
414 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(sid, tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL))) -> value rx_rsl_ud { }
415 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(sid, tr_RSL_REL_REQ(chan_nr, ?))) -> value rx_rsl_ud {
416 f_ipa_tx(0, ts_RSL_REL_CONF(chan_nr, main_dcch));
417 repeat;
418 }
419 }
Harald Welteae026692017-12-09 01:03:01 +0100420
421 setverdict(pass);
422}
423
424/* Test behavior if MSC answers with CREF to CR */
425testcase TC_chan_act_ack_est_ind_refused() runs on test_CT {
426 var BSSAP_N_CONNECT_ind rx_c_ind;
427 var RSL_Message rx_rsl;
428
Harald Welte89d42e82017-12-17 16:42:41 +0100429 f_init(1);
Harald Welteae026692017-12-09 01:03:01 +0100430
431 /* Send CHAN RQD and wait for allocation; acknowledge it */
Harald Welted6939652017-12-13 21:02:46 +0100432 var RslChannelNr chan_nr := f_chreq_act_ack();
Harald Welteae026692017-12-09 01:03:01 +0100433
434 var octetstring l3 := '00010203040506'O
435 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
436
437 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) -> value rx_c_ind;
438 BSSAP.send(ts_BSSAP_DISC_req(rx_c_ind.connectionId, 0));
439
440 /* expect BSC to disable the channel */
Harald Welte725844b2018-01-28 16:18:32 +0100441 f_expect_chan_rel(0, chan_nr);
Harald Welteae026692017-12-09 01:03:01 +0100442 setverdict(pass);
443}
444
Harald Welte618ef642017-12-14 14:58:20 +0100445/* CHAN RQD -> CHAN ACT -> CHAN ACT NACK -> RF CHAN REL */
446testcase TC_chan_act_nack() runs on test_CT {
447 var RSL_Message rx_rsl;
448 var integer chact_nack;
449
Harald Welte89d42e82017-12-17 16:42:41 +0100450 f_init(1);
Harald Welte618ef642017-12-14 14:58:20 +0100451
452 chact_nack := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "chan_act:nack");
453
454 f_ipa_tx(0, ts_RSL_CHAN_RQD('33'O, 33));
455 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
456 var RslChannelNr chan_nr := rx_rsl.ies[0].body.chan_nr;
457
458 f_ipa_tx(0, ts_RSL_CHAN_ACT_NACK(chan_nr, RSL_ERR_EQUIPMENT_FAIL));
459
460 /* wait for some time to hope the NACK arrives before the CTRL GET below */
461 f_sleep(0.5);
462
463 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "chan_act:nack", chact_nack+1);
464
465 setverdict(pass);
466}
467
Harald Welte799c97b2017-12-14 17:50:30 +0100468/* Test for channel exhaustion due to RACH overload */
469testcase TC_chan_exhaustion() runs on test_CT {
470 var ASP_RSL_Unitdata rsl_ud;
471 var integer i;
472 var integer chreq_total, chreq_nochan;
473
Harald Welte89d42e82017-12-17 16:42:41 +0100474 f_init(1);
Harald Welte799c97b2017-12-14 17:50:30 +0100475
476 chreq_total := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:total");
477 chreq_nochan := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:no_channel");
478
479 /* expect 5xTCH/F to succeed */
Philipp Maiercb6cc482018-03-26 13:08:00 +0200480 for (i := 0; i < NUM_TCHF_PER_BTS + NUM_TCHH_PER_BTS + NUM_SDCCH_PER_BTS; i := i+1) {
Harald Welte930d0a72018-03-22 22:08:40 +0100481 var RslChannelNr chan_nr := f_chreq_act_ack('23'O, i);
Harald Welte799c97b2017-12-14 17:50:30 +0100482 }
483
484 IPA_RSL[0].clear;
485
Harald Weltedd8cbf32018-01-28 12:07:52 +0100486 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:total",
Philipp Maiercb6cc482018-03-26 13:08:00 +0200487 chreq_total + NUM_TCHF_PER_BTS + NUM_TCHH_PER_BTS + NUM_SDCCH_PER_BTS);
Harald Welte799c97b2017-12-14 17:50:30 +0100488
489 /* now expect additional channel activations to fail */
490 f_ipa_tx(0, ts_RSL_CHAN_RQD('42'O, 42));
491
492 alt {
493 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0,
494 tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV))) {
495 setverdict(fail, "Received CHAN ACT ACK without resources?!?");
496 }
497 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0, tr_RSL_IMM_ASSIGN(?))) -> value rsl_ud {
498 var GsmRrMessage rr;
499 /* match on IMM ASS REJ */
500 rr := dec_GsmRrMessage(rsl_ud.rsl.ies[1].body.full_imm_ass_info.payload);
501 if (rr.header.message_type == IMMEDIATE_ASSIGNMENT_REJECT) {
502 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:total",
Philipp Maiercb6cc482018-03-26 13:08:00 +0200503 chreq_total + NUM_TCHF_PER_BTS + NUM_TCHH_PER_BTS + NUM_SDCCH_PER_BTS+1);
Harald Welte799c97b2017-12-14 17:50:30 +0100504 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:no_channel",
505 chreq_nochan+1);
506 setverdict(pass);
507 } else {
508 repeat;
509 }
510 }
511 [] IPA_RSL[0].receive { repeat; }
512 }
513}
514
Harald Weltecfe2c962017-12-15 12:09:32 +0100515/***********************************************************************
516 * Assignment Testing
517 ***********************************************************************/
518
519/* Verify that the BSC refuses any BSSAP connection from the MSC (They are all BSC->MSC direction) */
520testcase TC_outbound_connect() runs on test_CT {
Harald Welte89d42e82017-12-17 16:42:41 +0100521 f_init(1);
Harald Weltecfe2c962017-12-15 12:09:32 +0100522
Harald Weltea4ca4462018-02-09 00:17:14 +0100523 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 +0100524 BSSAP.receive(tr_BSSAP_DISC_ind(2342, ?, ?));
525 setverdict(pass);
526}
527
Harald Welte16a4adf2017-12-14 18:54:01 +0100528/* Test behavior if MSC answers with CREF to CR */
529testcase TC_assignment_cic_only() runs on test_CT {
530 var BSSAP_N_CONNECT_ind rx_c_ind;
531 var RSL_Message rx_rsl;
532 var DchanTuple dt;
533
Harald Welte89d42e82017-12-17 16:42:41 +0100534 f_init(1);
Harald Welte16a4adf2017-12-14 18:54:01 +0100535
536 dt := f_est_dchan('23'O, 23, '00000000'O);
Harald Welte17b27da2018-05-25 20:33:53 +0200537 if (mp_bssap_cfg.transport == BSSAP_TRANSPORT_AoIP) {
538 /* send assignment without AoIP IEs */
539 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_AssignmentReq(ts_BSSMAP_IE_CIC(0, 1))));
540 } else {
541 /* Send assignmetn without CIC in IPA case */
542 var BSSMAP_IE_AoIP_TransportLayerAddress tla :=
543 valueof(ts_BSSMAP_IE_AoIP_TLA4('01020304'O, 2342));
544 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_AssignmentReq(omit, tla)));
545 }
Harald Welte16a4adf2017-12-14 18:54:01 +0100546 alt {
547 [] BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_AssignmentComplete)) {
548 setverdict(fail, "AoIP BSC cannot accept ASSIGNMENT without AoIP Transport IE");
549 }
Harald Welte235ebf12017-12-15 14:18:16 +0100550 /* TODO: Actually expect GSM0808_CAUSE_REQ_A_IF_TYPE_NOT_SUPP */
Harald Welte16a4adf2017-12-14 18:54:01 +0100551 [] BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_AssignmentFail)) {
552 setverdict(pass);
553 }
554 [] BSSAP.receive { repeat; }
555 }
556}
557
Harald Welteed848512018-05-24 22:27:58 +0200558/* generate an assignment request for either AoIP or SCCPlite */
Harald Weltee102eae2018-05-31 21:03:47 +0200559function f_gen_ass_req() return PDU_BSSAP {
Harald Welteed848512018-05-24 22:27:58 +0200560 var PDU_BSSAP ass_cmd;
561 if (mp_bssap_cfg.transport == BSSAP_TRANSPORT_AoIP) {
562 var BSSMAP_IE_AoIP_TransportLayerAddress tla :=
563 valueof(ts_BSSMAP_IE_AoIP_TLA4('01020304'O, 2342));
564 ass_cmd := valueof(ts_BSSMAP_AssignmentReq(omit, tla));
565 } else {
566 var BSSMAP_IE_CircuitIdentityCode cic := valueof(ts_BSSMAP_IE_CIC(0,1));
567 ass_cmd := valueof(ts_BSSMAP_AssignmentReq(cic, omit));
568 }
569 return ass_cmd;
570}
571
572/* generate an assignment complete template for either AoIP or SCCPlite */
Harald Weltee102eae2018-05-31 21:03:47 +0200573function f_gen_exp_compl() return template PDU_BSSAP {
Harald Welteed848512018-05-24 22:27:58 +0200574 var template PDU_BSSAP exp_compl;
575 if (mp_bssap_cfg.transport == BSSAP_TRANSPORT_AoIP) {
576 exp_compl := tr_BSSMAP_AssignmentComplete(omit, ?);
577 } else {
578 /* CIC is optional "*" as the MSC allocated it */
579 exp_compl := tr_BSSMAP_AssignmentComplete(*, omit);
580 }
581 return exp_compl;
582}
583
Harald Welte235ebf12017-12-15 14:18:16 +0100584/* Run everything required up to sending a caller-specified assignment command and expect response */
585function f_assignment_exp(PDU_BSSAP ass_cmd, template PDU_BSSAP exp, charstring fail_text)
586runs on test_CT {
587 var BSSAP_N_CONNECT_ind rx_c_ind;
588 var RSL_Message rx_rsl;
589 var DchanTuple dt;
590
Harald Welte89d42e82017-12-17 16:42:41 +0100591 f_init(1);
Harald Welte235ebf12017-12-15 14:18:16 +0100592
593 dt := f_est_dchan('23'O, 23, '00000000'O);
594 /* send assignment without AoIP IEs */
595 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ass_cmd));
596 alt {
597 [] BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_AssignmentComplete)) {
598 if (ischosen(exp.pdu.bssmap.assignmentComplete)) {
599 setverdict(pass);
600 } else {
601 setverdict(fail, fail_text);
602 }
603 }
604 [] BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_AssignmentFail)) {
605 if (ischosen(exp.pdu.bssmap.assignmentFailure)) {
606 setverdict(pass);
607 } else {
608 setverdict(fail, fail_text);
609 }
610 }
611 [] BSSAP.receive { repeat; }
612 }
613}
614testcase TC_assignment_csd() runs on test_CT {
615 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
Harald Welteed848512018-05-24 22:27:58 +0200616 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte235ebf12017-12-15 14:18:16 +0100617 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelTypeCSD);
618 //exp_fail.pdu.bssmap.assignmentFailure.cause.causeValue := int2bit(enum2int(GSM0808_CAUSE_REQ_CODEC_TYPE_OR_CONFIG_UNAVAIL), 7);
619 f_assignment_exp(ass_cmd, exp_fail, "BSC accepted Assignment for CSD");
620}
621
622testcase TC_assignment_ctm() runs on test_CT {
623 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
Harald Welteed848512018-05-24 22:27:58 +0200624 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte235ebf12017-12-15 14:18:16 +0100625 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelTypeCTM);
626 //exp_fail.pdu.bssmap.assignmentFailure.cause.causeValue := int2bit(enum2int(GSM0808_CAUSE_REQ_CODEC_TYPE_OR_CONFIG_UNAVAIL), 7);
627 f_assignment_exp(ass_cmd, exp_fail, "BSC accepted Assignment for Speech+CTM");
628}
629
Harald Welte4003d112017-12-09 22:35:39 +0100630type record DchanTuple {
631 integer sccp_conn_id,
632 RslChannelNr rsl_chan_nr
Harald Weltea5d2ab22017-12-09 14:21:42 +0100633}
634
Harald Welted6939652017-12-13 21:02:46 +0100635/* Send CHAN RQD and wait for allocation; acknowledge it */
636private function f_chreq_act_ack(OCT1 ra := '23'O, GsmFrameNumber fn := 23)
637runs on test_CT return RslChannelNr {
638 var RSL_Message rx_rsl;
639 f_ipa_tx(0, ts_RSL_CHAN_RQD(ra, fn));
640 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
641 var RslChannelNr chan_nr := rx_rsl.ies[0].body.chan_nr;
642 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, fn+10));
643 return chan_nr;
644}
645
Harald Welte4003d112017-12-09 22:35:39 +0100646/* helper function to establish a dedicated channel via BTS and MSC */
647function f_est_dchan(OCT1 ra, GsmFrameNumber fn, octetstring l3)
648runs on test_CT return DchanTuple {
649 var BSSAP_N_CONNECT_ind rx_c_ind;
Harald Welte4003d112017-12-09 22:35:39 +0100650 var DchanTuple dt;
Harald Weltea5d2ab22017-12-09 14:21:42 +0100651
Harald Welte4003d112017-12-09 22:35:39 +0100652 /* Send CHAN RQD and wait for allocation; acknowledge it */
Harald Welted6939652017-12-13 21:02:46 +0100653 dt.rsl_chan_nr := f_chreq_act_ack(ra, fn);
Harald Welte4003d112017-12-09 22:35:39 +0100654
655 f_ipa_tx(0, ts_RSL_EST_IND(dt.rsl_chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
656
657 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) -> value rx_c_ind;
658 dt.sccp_conn_id := rx_c_ind.connectionId;
659 BSSAP.send(ts_BSSAP_CONNECT_res(dt.sccp_conn_id));
660
661 return dt;
Harald Weltea5d2ab22017-12-09 14:21:42 +0100662}
663
Harald Welte641fcbe2018-06-14 10:58:35 +0200664/* expect RF CAN REL from BTS, acknowledge it and clear the MSC side */
665private function f_exp_chan_rel_and_clear(DchanTuple dt, integer bts_nr := 0) runs on test_CT {
666 var RSL_Message rx_rsl;
667 /* expect BSC to disable the channel */
668 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL), T3101_MAX);
669 /* respond with CHAN REL ACK */
670 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(dt.rsl_chan_nr));
671
672 /* expect Clear Complete from BSC */
673 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearComplete));
674
675 /* MSC disconnects as instructed. */
676 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
677}
678
Harald Welte4003d112017-12-09 22:35:39 +0100679/* Test behavior of channel release after unilateral RLL REL IND (DISC from MS) */
680testcase TC_chan_rel_rll_rel_ind() runs on test_CT {
Neels Hofmeyr27f64362018-03-12 01:44:00 +0100681 var BSSAP_N_DATA_ind rx_di;
Harald Welte4003d112017-12-09 22:35:39 +0100682 var DchanTuple dt;
Harald Welte96c94412017-12-09 03:12:45 +0100683
Harald Welte89d42e82017-12-17 16:42:41 +0100684 f_init(1);
Harald Welte96c94412017-12-09 03:12:45 +0100685
Harald Welte4003d112017-12-09 22:35:39 +0100686 dt := f_est_dchan('23'O, 23, '00010203040506'O);
687
688 /* simulate RLL REL IND */
689 f_ipa_tx(0, ts_RSL_REL_IND(dt.rsl_chan_nr, valueof(ts_RslLinkID_DCCH(0))));
690
Neels Hofmeyr27f64362018-03-12 01:44:00 +0100691 /* expect Clear Request on MSC side */
692 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearRequest)) -> value rx_di;
693
694 /* Instruct BSC to clear channel */
695 var BssmapCause cause := bit2int(rx_di.userData.pdu.bssmap.clearRequest.cause.causeValue);
696 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
697
Harald Welte4003d112017-12-09 22:35:39 +0100698 /* expect BSC to disable the channel */
Harald Welte641fcbe2018-06-14 10:58:35 +0200699 f_exp_chan_rel_and_clear(dt, 0);
Neels Hofmeyr27f64362018-03-12 01:44:00 +0100700
701 /* wait for SCCP emulation to do its job */
702 f_sleep(1.0);
Harald Welte4003d112017-12-09 22:35:39 +0100703
704 setverdict(pass);
705}
706
707/* Test behavior of channel release after CONN FAIL IND from BTS */
708testcase TC_chan_rel_conn_fail() runs on test_CT {
709 var BSSAP_N_DATA_ind rx_di;
Harald Welte4003d112017-12-09 22:35:39 +0100710 var DchanTuple dt;
711
Harald Welte89d42e82017-12-17 16:42:41 +0100712 f_init(1);
Harald Welte4003d112017-12-09 22:35:39 +0100713
714 dt := f_est_dchan('23'O, 23, '00010203040506'O);
715
716 /* simulate CONN FAIL IND */
Harald Weltea8ed9062017-12-14 09:46:01 +0100717 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 +0100718 /* TODO: different cause values? */
719
Harald Welte4003d112017-12-09 22:35:39 +0100720 /* expect Clear Request from BSC */
721 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearRequest)) -> value rx_di;
722
723 /* Instruct BSC to clear channel */
724 var BssmapCause cause := bit2int(rx_di.userData.pdu.bssmap.clearRequest.cause.causeValue);
725 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
726
Harald Welte6ff76ea2018-01-28 13:08:01 +0100727 /* expect BSC to disable the channel */
Harald Welte641fcbe2018-06-14 10:58:35 +0200728 f_exp_chan_rel_and_clear(dt, 0);
Harald Welte4003d112017-12-09 22:35:39 +0100729
730 /* wait for SCCP emulation to do its job */
731 f_sleep(1.0);
732
733 setverdict(pass);
734}
735
Harald Welte99f3ca02018-06-14 13:40:29 +0200736/* Test behavior of early CONN FAIL IND from BTS (before EST IND!) */
737/* See also https://www.osmocom.org/issues/3182 */
738testcase TC_early_conn_fail() runs on test_CT {
739 var RSL_Message rx_rsl;
740 var DchanTuple dt;
741
742 f_init(1);
743
744 /* BTS->BSC: Send CHAN RQD and wait for allocation; acknowledge it */
745 dt.rsl_chan_nr := f_chreq_act_ack(f_rnd_octstring(1), 23);
746
747 /* BTS->BSC: simulate CONN FAIL IND */
748 f_ipa_tx(0, ts_RSL_CONN_FAIL_IND(dt.rsl_chan_nr, RSL_ERR_RADIO_LINK_FAIL));
749
750 /* BTS->BSC: Expect RF channel release from BSC on Abis */
751 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL), 10.0);
752
753 /* BTS<-BSC: respond with CHAN REL ACK */
754 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(dt.rsl_chan_nr));
755
756 setverdict(pass);
757}
758
759/* Test behavior of late CONN FAIL IND from BTS (ater REL IND!) */
760/* See also https://www.osmocom.org/issues/3182 */
761testcase TC_late_conn_fail() runs on test_CT {
762 var RSL_Message rx_rsl;
763 var DchanTuple dt;
764
765 f_init(1);
766
767 dt := f_est_dchan('23'O, 23, '00010203040506'O);
768
769 /* BSC<-MSC: Instruct BSC to clear connection */
770 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(0)));
771
772 /* BTS->BSC: expect BSC to deactivate SACCH */
773 rx_rsl := f_exp_ipa_rx(0, tr_RSL_DEACT_SACCH(dt.rsl_chan_nr));
774
775 /* BTS->BSC: simulate a late CONN FAIL IND from BTS */
776 f_ipa_tx(0, ts_RSL_CONN_FAIL_IND(dt.rsl_chan_nr, RSL_ERR_RADIO_LINK_FAIL));
777
778 /* BTS<-BSC: Expect RF channel release from BSC on Abis */
779 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL), 10.0);
780 /* BTS->BSC: respond with CHAN REL ACK */
781 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(dt.rsl_chan_nr));
782
783 /* BSC->MSC: expect Clear Complete from BSC */
784 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearComplete));
785
786 /* BSC<-MSC: MSC disconnects as requested. */
787 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
788
789 setverdict(pass);
790}
791
Harald Welte91d54a52018-01-28 15:35:07 +0100792function f_expect_chan_rel(integer bts_nr, RslChannelNr rsl_chan_nr, boolean flush := true,
793 boolean handle_rll_rel := true) runs on test_CT {
794
795 var RslLinkId main_dcch := valueof(ts_RslLinkID_DCCH(0));
796 if (flush) {
797 /* Clear the queue, it might still contain stuff like IMMEDIATE ASSIGN */
798 IPA_RSL[bts_nr].clear;
799 }
800 alt {
801 /* ignore DEACTIVATE SACCH (if any) */
802 [] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0,
803 tr_RSL_DEACT_SACCH(rsl_chan_nr))) {
804 repeat;
805 }
806 /* acknowledge RLL release (if any)*/
807 [handle_rll_rel] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0,
808 tr_RSL_REL_REQ(rsl_chan_nr, ?))) {
809 /* FIXME: Why are we getting this for LinkID SACCH? */
810 f_ipa_tx(0, ts_RSL_REL_CONF(rsl_chan_nr, main_dcch));
811 repeat;
812 }
Neels Hofmeyr92d48422018-06-14 04:05:07 +0200813 [not handle_rll_rel] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0,
814 tr_RSL_REL_REQ(rsl_chan_nr, ?))) {
815 /* Do not reply, just continue */
816 repeat;
817 }
Harald Welte91d54a52018-01-28 15:35:07 +0100818 /* Expect RF channel release from BSC on Abis */
819 [] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0,
820 tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL))) {
821 /* respond with CHAN REL ACK */
822 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(rsl_chan_nr));
823 }
824 /* ignore any user data */
825 [] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0, tr_RSL_MsgTypeR(?))) {
826 repeat;
827 }
828 }
829}
830
Harald Welte4003d112017-12-09 22:35:39 +0100831/* Test behavior of channel release after hard Clear Command from MSC */
832testcase TC_chan_rel_hard_clear() runs on test_CT {
833 var BSSAP_N_DATA_ind rx_di;
Harald Welte4003d112017-12-09 22:35:39 +0100834 var DchanTuple dt;
Harald Welte4003d112017-12-09 22:35:39 +0100835
Harald Welte89d42e82017-12-17 16:42:41 +0100836 f_init(1);
Harald Welte4003d112017-12-09 22:35:39 +0100837
838 dt := f_est_dchan('23'O, 23, '00010203040506'O);
839
840 /* Instruct BSC to clear channel */
841 var BssmapCause cause := 0;
842 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
843
844 /* expect Clear Complete from BSC on A */
845 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearComplete)) {
846 /* release the SCCP connection */
847 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
848 }
849
Harald Welte91d54a52018-01-28 15:35:07 +0100850 f_expect_chan_rel(0, dt.rsl_chan_nr);
Harald Welte4003d112017-12-09 22:35:39 +0100851 setverdict(pass);
852}
853
Harald Welted8c36cd2017-12-09 23:05:31 +0100854/* Test behavior of channel release after hard RLSD from MSC */
855testcase TC_chan_rel_hard_rlsd() runs on test_CT {
Harald Welted8c36cd2017-12-09 23:05:31 +0100856 var DchanTuple dt;
Harald Welted8c36cd2017-12-09 23:05:31 +0100857
Harald Welte89d42e82017-12-17 16:42:41 +0100858 f_init(1);
Harald Welted8c36cd2017-12-09 23:05:31 +0100859
860 dt := f_est_dchan('23'O, 23, '00010203040506'O);
861
862 /* release the SCCP connection */
863 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
864
Harald Welte91d54a52018-01-28 15:35:07 +0100865 f_expect_chan_rel(0, dt.rsl_chan_nr);
Harald Welted8c36cd2017-12-09 23:05:31 +0100866 setverdict(pass);
867}
868
Harald Welte550daf92018-06-11 19:22:13 +0200869/* Test behavior of channel release after hard RLSD from MSC and MS is not responding to RLL REL REQ */
870testcase TC_chan_rel_hard_rlsd_ms_dead() runs on test_CT {
871 var DchanTuple dt;
872
873 f_init(1);
874
875 dt := f_est_dchan('23'O, 23, '00010203040506'O);
876
877 /* release the SCCP connection */
878 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
879
880 f_expect_chan_rel(0, dt.rsl_chan_nr, true, false);
881 setverdict(pass);
882}
883
Harald Welte85804d42017-12-10 14:11:58 +0100884/* Test behavior of channel release after BSSMAP RESET from MSC */
885testcase TC_chan_rel_a_reset() runs on test_CT {
Harald Welte85804d42017-12-10 14:11:58 +0100886 var DchanTuple dt;
Harald Welte85804d42017-12-10 14:11:58 +0100887
Harald Welte89d42e82017-12-17 16:42:41 +0100888 f_init(1);
Harald Welte85804d42017-12-10 14:11:58 +0100889
890 dt := f_est_dchan('23'O, 23, '00010203040506'O);
891
892 /* Clear the queue, it might still contain stuff like IMMEDIATE ASSIGN */
893 IPA_RSL[0].clear;
894
895 /* perform BSSAP RESET, expect RESET ACK and DISC.ind on connection */
Harald Weltea4ca4462018-02-09 00:17:14 +0100896 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 +0100897 interleave {
Harald Weltea4ca4462018-02-09 00:17:14 +0100898 [] 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 +0100899 [] BSSAP.receive(tr_BSSAP_DISC_ind(dt.sccp_conn_id, ?, ?)) { }
900 }
901
Philipp Maiere8f38ed2018-02-09 10:30:31 +0100902 f_expect_chan_rel(0, dt.rsl_chan_nr, false);
Harald Welte85804d42017-12-10 14:11:58 +0100903 setverdict(pass);
904}
905
Harald Welte5cd20ed2017-12-13 21:03:20 +0100906/* Test behavior if RSL EST IND for non-active channel */
907testcase TC_rll_est_ind_inact_lchan() runs on test_CT {
908 timer T := 2.0;
909
Harald Welte89d42e82017-12-17 16:42:41 +0100910 f_init(1);
Harald Welte5cd20ed2017-12-13 21:03:20 +0100911
912 var octetstring l3 := '00010203040506'O;
913 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(6));
914 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
915
916 T.start;
917 alt {
918 [] BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) {
919 setverdict(fail, "MSC received COMPL L3 for non-active lchan");
920 }
921 [] BSSAP.receive {}
922 [] IPA_RSL[0].receive {}
923 [] T.timeout {}
924 }
925
926 setverdict(pass);
927}
928
929/* Test behavior if RSL EST IND for invalid SAPI */
930testcase TC_rll_est_ind_inval_sapi1() runs on test_CT {
931 var RslChannelNr chan_nr;
932
Harald Welte89d42e82017-12-17 16:42:41 +0100933 f_init(1);
Harald Welte5cd20ed2017-12-13 21:03:20 +0100934
935 chan_nr := f_chreq_act_ack()
936
937 var octetstring l3 := '00010203040506'O;
938 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(1)), l3));
939
940 timer T := 2.0;
941 T.start;
942 alt {
943 [] BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) {
944 setverdict(fail, "MSC received COMPL L3 for invalid SAPI 1");
945 }
946 [] BSSAP.receive { repeat; }
947 [] IPA_RSL[0].receive { repeat; }
948 [] T.timeout {}
949 }
950
951 setverdict(pass);
952}
953
954/* Test behavior if RSL EST IND for invalid SAPI */
955testcase TC_rll_est_ind_inval_sapi3() runs on test_CT {
956 timer T := 2.0;
957
Harald Welte89d42e82017-12-17 16:42:41 +0100958 f_init(1);
Harald Welte5cd20ed2017-12-13 21:03:20 +0100959
960 var RslChannelNr chan_nr := f_chreq_act_ack();
961
962 var octetstring l3 := '00010203040506'O;
963 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(3)), l3));
964
965 T.start;
966 alt {
967 [] BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) {
968 setverdict(fail, "MSC received COMPL L3 for invalid SAPI 3");
969 }
970 [] BSSAP.receive { repeat; }
971 [] IPA_RSL[0].receive { repeat; }
972 [] T.timeout {}
973 }
974
975 setverdict(pass);
976}
977
978/* Test behavior if RSL EST IND for invalid SACCH */
979testcase TC_rll_est_ind_inval_sacch() runs on test_CT {
980 timer T := 2.0;
981
Harald Welte89d42e82017-12-17 16:42:41 +0100982 f_init(1);
Harald Welte5cd20ed2017-12-13 21:03:20 +0100983
984 var RslChannelNr chan_nr := f_chreq_act_ack();
985
986 var octetstring l3 := '00010203040506'O;
987 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_SACCH(0)), l3));
988
989 T.start;
990 alt {
991 [] BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) {
992 setverdict(fail, "MSC received COMPL L3 for invalid Link SACCH");
993 }
994 [] BSSAP.receive { repeat; }
995 [] IPA_RSL[0].receive { repeat; }
996 [] T.timeout {}
997 }
998
999 setverdict(pass);
1000}
1001
1002
1003
Harald Welte4003d112017-12-09 22:35:39 +01001004
1005testcase TC_ctrl_msc_connection_status() runs on test_CT {
1006 var charstring ctrl_resp;
1007
Harald Welte89d42e82017-12-17 16:42:41 +01001008 f_init(1);
Harald Welte4003d112017-12-09 22:35:39 +01001009
1010 /* See https://osmocom.org/issues/2729 */
1011 f_ctrl_get_exp(IPA_CTRL, "msc_connection_status", "connected");
1012 setverdict(pass);
1013}
1014
Stefan Sperlingb041b3d2018-01-03 17:14:55 +01001015testcase TC_ctrl_msc0_connection_status() runs on test_CT {
1016 var charstring ctrl_resp;
1017
1018 f_init(1);
Stefan Sperlingb041b3d2018-01-03 17:14:55 +01001019
1020 f_ctrl_get_exp(IPA_CTRL, "msc.0.connection_status", "connected");
1021 setverdict(pass);
1022}
1023
Harald Welte4003d112017-12-09 22:35:39 +01001024testcase TC_ctrl() runs on test_CT {
1025 var charstring ctrl_resp;
1026
Harald Welte89d42e82017-12-17 16:42:41 +01001027 f_init(1);
Harald Welte4003d112017-12-09 22:35:39 +01001028
1029 /* all below values must match the osmo-bsc.cfg config file used */
1030
Harald Welte6a129692018-03-17 17:30:14 +01001031 f_ctrl_get_exp(IPA_CTRL, "mcc", "001");
1032 f_ctrl_get_exp(IPA_CTRL, "mnc", "01");
Harald Welte44bdaa52017-12-17 17:01:47 +01001033 f_ctrl_get_exp(IPA_CTRL, "number-of-bts", "3");
Harald Welte4003d112017-12-09 22:35:39 +01001034
1035 var integer bts_nr := 0;
1036 f_ctrl_get_exp_bts(IPA_CTRL, bts_nr, "location-area-code", "1");
1037 f_ctrl_get_exp_bts(IPA_CTRL, bts_nr, "cell-identity", "0");
1038 f_ctrl_get_exp_bts(IPA_CTRL, bts_nr, "oml-connection-state", "connected");
1039 f_ctrl_get_exp_bts(IPA_CTRL, bts_nr, "gprs-mode", "gprs");
1040 f_ctrl_get_exp_bts(IPA_CTRL, bts_nr, "rf_state", "operational,unlocked,on");
1041 f_ctrl_get_exp_trx(IPA_CTRL, bts_nr, 0, "arfcn", "871");
1042 f_ctrl_get_exp_trx(IPA_CTRL, bts_nr, 0, "max-power-reduction", "20");
1043
1044 var integer uptime := str2int(f_ctrl_get_bts(IPA_CTRL, bts_nr, "oml-uptime"));
1045 f_sleep(2.0);
1046 if (str2int(f_ctrl_get_bts(IPA_CTRL, bts_nr, "oml-uptime")) < uptime+1) {
1047 setverdict(fail, "oml-uptime not incrementing as expected");
1048 }
1049 /* TODO: Disconnect RSL, imply that OML is disconnected and check for uptime zero? */
1050
1051 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bsc", 0, "paging:attempted", 0);
1052
1053 setverdict(pass);
Harald Welte96c94412017-12-09 03:12:45 +01001054}
1055
Harald Welte6f521d82017-12-11 19:52:02 +01001056function f_bssap_tx_ud(template PDU_BSSAP bssap) runs on test_CT {
Harald Weltea4ca4462018-02-09 00:17:14 +01001057 BSSAP.send(ts_BSSAP_UNITDATA_req(g_bssap.sccp_addr_peer, g_bssap.sccp_addr_own, bssap));
Harald Welte6f521d82017-12-11 19:52:02 +01001058}
1059
1060
1061/***********************************************************************
1062 * Paging Testing
1063 ***********************************************************************/
1064
1065type record Cell_Identity {
1066 GsmMcc mcc,
1067 GsmMnc mnc,
1068 GsmLac lac,
1069 GsmCellId ci
1070};
Harald Welte24135bd2018-03-17 19:27:53 +01001071private const Cell_Identity cid := { '001'H, '01'H, 1, 0 };
Stefan Sperling049a86e2018-03-20 15:51:00 +01001072private const Cell_Identity unknown_cid := { '678'H, 'f90'H, 1, 0 };
Harald Welte6f521d82017-12-11 19:52:02 +01001073
Harald Welte5d1a2202017-12-13 19:51:29 +01001074type set of integer BtsIdList;
1075
1076private function f_bts_in_list(integer bts_id, BtsIdList bts_ids) return boolean {
1077 for (var integer j := 0; j < sizeof(bts_ids); j := j + 1) {
1078 if (bts_id == bts_ids[j]) {
1079 return true;
1080 }
1081 }
1082 return false;
1083}
Harald Welte6f521d82017-12-11 19:52:02 +01001084
1085/* core paging test helper function; used by most paging test cases */
1086private function f_pageing_helper(hexstring imsi,
1087 template BSSMAP_FIELD_CellIdentificationList cid_list,
Harald Welte5d1a2202017-12-13 19:51:29 +01001088 BtsIdList bts_ids := { 0 },
Harald Welte6f521d82017-12-11 19:52:02 +01001089 template RSL_ChanNeeded rsl_chneed := omit,
1090 template OCT4 tmsi := omit) runs on test_CT
1091{
1092 var template BSSMAP_IE_ChannelNeeded bssmap_chneed;
1093 var MobileIdentity mi;
1094 var template octetstring id_enc; /* FIXME */
1095 var RSL_Message rx_rsl;
1096 var integer paging_group := hex2int(imsi[lengthof(imsi)-1]);
Harald Welte5d1a2202017-12-13 19:51:29 +01001097 var integer i;
Harald Welte6f521d82017-12-11 19:52:02 +01001098
1099 f_init();
Harald Welte6f521d82017-12-11 19:52:02 +01001100
1101 /* Clear the queue, it might still contain stuff like BCCH FILLING */
Harald Weltec3068592018-03-17 19:55:31 +01001102 for (i := 0; i < NUM_BTS; i := i + 1) {
1103 IPA_RSL[i].clear;
Harald Welte5d1a2202017-12-13 19:51:29 +01001104 }
Harald Welte6f521d82017-12-11 19:52:02 +01001105
1106 if (isvalue(rsl_chneed)) {
1107 /* The values of 08.08 3.2.2.36 and 08.58 9.3.40 are luckily identical */
1108 bssmap_chneed := ts_BSSMAP_IE_ChanNeeded(int2bit(enum2int(valueof(rsl_chneed)),2));
1109 } else {
1110 bssmap_chneed := omit;
1111 }
1112
1113 f_bssap_tx_ud(ts_BSSMAP_Paging(imsi, cid_list, tmsi, bssmap_chneed));
1114
1115/* FIXME: Disabled due to bugs in both GSM_RR_Types and MobileL3_CommonIE_Types IMSI encoder
1116 if (isvalue(tmsi)) {
1117 mi := valueof(t_Osmo_MI_TMSI(oct2int(valueof(tmsi))));
1118 } else {
1119 mi := valueof(ts_Osmo_MI_IMSI(imsi));
1120 }
1121 id_enc := enc_MobileIdentity(mi);
1122*/
1123 id_enc := ?;
Harald Welte5d1a2202017-12-13 19:51:29 +01001124 for (i := 0; i < sizeof(bts_ids); i := i + 1) {
1125 rx_rsl := f_exp_ipa_rx(bts_ids[i], tr_RSL_PAGING_CMD(id_enc));
1126 /* check channel type, paging group */
1127 if (rx_rsl.ies[1].body.paging_group != paging_group) {
1128 setverdict(fail, "Paging for wrong paging group");
1129 }
1130 if (ispresent(rsl_chneed) and
1131 rx_rsl.ies[3].body.chan_needed.chan_needed != valueof(rsl_chneed)) {
1132 setverdict(fail, "RSL Channel Needed != BSSMAP Channel Needed");
1133 }
Harald Welte6f521d82017-12-11 19:52:02 +01001134 }
Harald Welte2fccd982018-01-31 15:48:19 +01001135 f_sleep(2.0);
Harald Welte5d1a2202017-12-13 19:51:29 +01001136 /* do a quick check on all not-included BTSs if they received paging */
1137 for (i := 0; i < NUM_BTS; i := i + 1) {
1138 timer T := 0.1;
1139 if (f_bts_in_list(i, bts_ids)) {
1140 continue;
1141 }
1142 T.start;
1143 alt {
1144 [] IPA_RSL[i].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0, tr_RSL_PAGING_CMD(id_enc))) {
1145 setverdict(fail, "Paging on BTS ", i, " which is not part of ", bts_ids);
1146 }
1147 [] IPA_RSL[i].receive { repeat; }
1148 [] T.timeout { }
1149 }
Harald Welte6f521d82017-12-11 19:52:02 +01001150 }
1151
1152 setverdict(pass);
1153}
1154
Harald Welte5d1a2202017-12-13 19:51:29 +01001155const BtsIdList c_BtsId_all := { 0, 1, 2 };
Harald Welte751d3eb2018-01-31 15:51:06 +01001156const BtsIdList c_BtsId_none := { };
Harald Welte5d1a2202017-12-13 19:51:29 +01001157const BtsIdList c_BtsId_LAC1 := { 0, 1 };
1158const BtsIdList c_BtsId_LAC2 := { 2 };
1159
Harald Welte6f521d82017-12-11 19:52:02 +01001160/* PAGING by IMSI + TMSI */
1161testcase TC_paging_imsi_nochan() runs on test_CT {
1162 var BSSMAP_FIELD_CellIdentificationList cid_list;
1163 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Philipp Maier8c04b0a2018-02-23 13:48:48 +01001164 f_pageing_helper('001010100000001'H, cid_list, c_BtsId_all, omit, omit);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001165 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001166}
1167
1168/* PAGING by IMSI + TMSI */
1169testcase TC_paging_tmsi_nochan() runs on test_CT {
1170 var BSSMAP_FIELD_CellIdentificationList cid_list;
1171 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01001172 f_pageing_helper('001010100000001'H, cid_list, c_BtsId_all, omit, 'A1B2C301'O);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001173 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001174}
1175
1176/* Paging with different "channel needed' values */
1177testcase TC_paging_tmsi_any() runs on test_CT {
1178 var BSSMAP_FIELD_CellIdentificationList cid_list;
1179 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01001180 f_pageing_helper('001010100000002'H, cid_list, c_BtsId_all, RSL_CHANNEED_ANY, 'A1B2C302'O);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001181 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001182}
1183testcase TC_paging_tmsi_sdcch() runs on test_CT {
1184 var BSSMAP_FIELD_CellIdentificationList cid_list;
1185 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01001186 f_pageing_helper('001010100000003'H, cid_list, c_BtsId_all, RSL_CHANNEED_SDCCH, 'A1B2C303'O);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001187 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001188}
1189testcase TC_paging_tmsi_tch_f() runs on test_CT {
1190 var BSSMAP_FIELD_CellIdentificationList cid_list;
1191 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01001192 f_pageing_helper('001010000000004'H, cid_list, c_BtsId_all, RSL_CHANNEED_TCH_F, 'A1B2C304'O);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001193 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001194}
1195testcase TC_paging_tmsi_tch_hf() runs on test_CT {
1196 var BSSMAP_FIELD_CellIdentificationList cid_list;
1197 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01001198 f_pageing_helper('001010000000005'H, cid_list, c_BtsId_all, RSL_CHANNEED_TCH_ForH, 'A1B2C305'O);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001199 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001200}
1201
1202/* Paging by CGI */
1203testcase TC_paging_imsi_nochan_cgi() runs on test_CT {
1204 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1205 cid_list := { cIl_CGI := { ts_BSSMAP_CI_CGI(cid.mcc, cid.mnc, cid.lac, cid.ci) } };
Harald Welte5d1a2202017-12-13 19:51:29 +01001206 f_pageing_helper('001010000000006'H, cid_list, { 0 });
Philipp Maier282ca4b2018-02-27 17:17:00 +01001207 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001208}
1209
1210/* Paging by LAC+CI */
1211testcase TC_paging_imsi_nochan_lac_ci() runs on test_CT {
1212 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1213 cid_list := { cIl_LAC_CI := { ts_BSSMAP_CI_LAC_CI(cid.lac, cid.ci) } };
Harald Welte5d1a2202017-12-13 19:51:29 +01001214 f_pageing_helper('001010000000007'H, cid_list, { 0 });
Philipp Maier282ca4b2018-02-27 17:17:00 +01001215 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001216}
1217
1218/* Paging by CI */
1219testcase TC_paging_imsi_nochan_ci() runs on test_CT {
1220 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1221 cid_list := { cIl_CI := { ts_BSSMAP_CI_CI(cid.ci) } };
Harald Welte5d1a2202017-12-13 19:51:29 +01001222 f_pageing_helper('001010000000008'H, cid_list, { 0 });
Philipp Maier282ca4b2018-02-27 17:17:00 +01001223 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001224}
1225
1226/* Paging by LAI */
1227testcase TC_paging_imsi_nochan_lai() runs on test_CT {
1228 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1229 cid_list := { cIl_LAI := { ts_BSSMAP_CI_LAI(cid.mcc, cid.mnc, cid.lac) } };
Harald Welte5d1a2202017-12-13 19:51:29 +01001230 f_pageing_helper('001010000000009'H, cid_list, c_BtsId_LAC1);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001231 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001232}
1233
1234/* Paging by LAC */
1235testcase TC_paging_imsi_nochan_lac() runs on test_CT {
1236 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1237 cid_list := { cIl_LAC := { ts_BSSMAP_CI_LAC(cid.lac) } };
Harald Welte5d1a2202017-12-13 19:51:29 +01001238 f_pageing_helper('001010000000010'H, cid_list, c_BtsId_LAC1);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001239 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001240}
1241
1242/* Paging by "all in BSS" */
1243testcase TC_paging_imsi_nochan_all() runs on test_CT {
1244 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1245 cid_list := { cIl_allInBSS := ''O };
Harald Welte5d1a2202017-12-13 19:51:29 +01001246 f_pageing_helper('001010000000011'H, cid_list, c_BtsId_all);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001247 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001248}
1249
Stefan Sperling7b5e1782018-03-20 19:32:43 +01001250/* Paging by PLMN+LAC+RNC; We do not implement this; Verify nothing is paged */
Harald Welte751d3eb2018-01-31 15:51:06 +01001251testcase TC_paging_imsi_nochan_plmn_lac_rnc() runs on test_CT {
1252 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1253 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 +01001254 f_pageing_helper('001010000000012'H, cid_list, c_BtsId_none);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001255 f_shutdown_helper();
Harald Welte751d3eb2018-01-31 15:51:06 +01001256}
Harald Welte6f521d82017-12-11 19:52:02 +01001257
Stefan Sperling7b5e1782018-03-20 19:32:43 +01001258/* Paging by RNC; We do not implement this; Verify nothing is paged */
Harald Welte751d3eb2018-01-31 15:51:06 +01001259testcase TC_paging_imsi_nochan_rnc() runs on test_CT {
1260 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1261 cid_list := { cIl_RNC := { int2oct(13, 2) } };
Stefan Sperling7b5e1782018-03-20 19:32:43 +01001262 f_pageing_helper('001010000000013'H, cid_list, c_BtsId_none);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001263 f_shutdown_helper();
Harald Welte751d3eb2018-01-31 15:51:06 +01001264}
1265
Stefan Sperling7b5e1782018-03-20 19:32:43 +01001266/* Paging by LAC+RNC; We do not implement; Verify nothing is paged */
Harald Welte751d3eb2018-01-31 15:51:06 +01001267testcase TC_paging_imsi_nochan_lac_rnc() runs on test_CT {
1268 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1269 cid_list := { cIl_LAC_RNC := { ts_BSSMAP_CI_LAC_RNC(cid.lac, 14) } };
Stefan Sperling7b5e1782018-03-20 19:32:43 +01001270 f_pageing_helper('001010000000014'H, cid_list, c_BtsId_none);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001271 f_shutdown_helper();
Harald Welte751d3eb2018-01-31 15:51:06 +01001272}
1273
Harald Welte6f521d82017-12-11 19:52:02 +01001274/* Paging on multiple cells (multiple entries in list): Verify all of them page */
Harald Welte751d3eb2018-01-31 15:51:06 +01001275testcase TC_paging_imsi_nochan_lacs() runs on test_CT {
1276 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1277 cid_list := { cIl_LAC := { ts_BSSMAP_CI_LAC(1), ts_BSSMAP_CI_LAC(2) } };
1278 f_pageing_helper('001010000000015'H, cid_list, c_BtsId_all);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001279 f_shutdown_helper();
Harald Welte751d3eb2018-01-31 15:51:06 +01001280}
1281
1282/* Paging on empty list: Verify none of them page */
1283testcase TC_paging_imsi_nochan_lacs_empty() runs on test_CT {
1284 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1285 cid_list := { cIl_LAC := { } };
1286 f_pageing_helper('001010000000016'H, cid_list, c_BtsId_none);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001287 f_shutdown_helper();
Harald Welte751d3eb2018-01-31 15:51:06 +01001288}
1289
Stefan Sperling049a86e2018-03-20 15:51:00 +01001290/* Paging by CGI with unknown MCC/MNC: Verify nothing is paged. */
1291testcase TC_paging_imsi_nochan_cgi_unknown_cid() runs on test_CT {
1292 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1293 cid_list := { cIl_CGI := { ts_BSSMAP_CI_CGI(unknown_cid.mcc, unknown_cid.mnc, unknown_cid.lac, unknown_cid.ci) } };
1294 f_pageing_helper('001010000000006'H, cid_list, c_BtsId_none);
1295 f_shutdown_helper();
1296}
1297
Harald Welte6f521d82017-12-11 19:52:02 +01001298/* Verify paging retransmission interval + count */
1299/* Verify paging stops after channel establishment */
Harald Welte6f521d82017-12-11 19:52:02 +01001300/* Test behavior under paging overload */
Harald Welteae026692017-12-09 01:03:01 +01001301
Harald Weltee65d40e2017-12-13 00:09:06 +01001302/* Verify PCH load */
1303testcase TC_paging_imsi_load() runs on test_CT {
1304 var BSSMAP_FIELD_CellIdentificationList cid_list;
1305 timer T := 4.0;
Harald Welte2caa1062018-03-17 18:19:05 +01001306 timer T_retrans := 1.0;
Harald Weltee65d40e2017-12-13 00:09:06 +01001307 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01001308 f_pageing_helper('001010123456789'H, cid_list, c_BtsId_all);
Harald Weltee65d40e2017-12-13 00:09:06 +01001309
1310 /* tell BSC there is no paging space anymore */
1311 f_ipa_tx(0, ts_RSL_PAGING_LOAD_IND(0));
Harald Welte3b57ab52018-03-17 18:01:10 +01001312 f_sleep(0.2);
1313 IPA_RSL[0].clear;
Harald Weltee65d40e2017-12-13 00:09:06 +01001314
1315 /* Wait for 4 seconds if any more PAGING CMD are received on RSL. Normally,
1316 * there would be 8 retransmissions during 4 seconds */
1317 T.start;
Harald Welte2caa1062018-03-17 18:19:05 +01001318 T_retrans.start;
Harald Weltee65d40e2017-12-13 00:09:06 +01001319 alt {
1320 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0, tr_RSL_PAGING_CMD(?))) {
1321 setverdict(fail, "Received PAGING after LOAD_IND(0)");
Daniel Willmannafce8662018-07-06 23:11:32 +02001322 mtc.stop;
Harald Weltee65d40e2017-12-13 00:09:06 +01001323 }
Harald Welte2caa1062018-03-17 18:19:05 +01001324 [] T_retrans.timeout {
1325 /* re-trnsmit the zero-space LOAD IND to avoid BSC 'auto credit' */
1326 f_ipa_tx(0, ts_RSL_PAGING_LOAD_IND(0));
1327 T_retrans.start;
1328 repeat;
1329 }
Harald Weltee65d40e2017-12-13 00:09:06 +01001330 [] T.timeout {
1331 setverdict(pass);
1332 }
1333 }
Philipp Maier282ca4b2018-02-27 17:17:00 +01001334
1335 f_shutdown_helper();
Harald Weltee65d40e2017-12-13 00:09:06 +01001336}
1337
Harald Welte235ebf12017-12-15 14:18:16 +01001338/* Verify Paging Counter */
Harald Welte1ff69992017-12-14 12:31:17 +01001339testcase TC_paging_counter() runs on test_CT {
1340 var BSSMAP_FIELD_CellIdentificationList cid_list;
1341 timer T := 4.0;
1342 var integer i;
1343 var integer paging_attempted_bsc;
1344 var integer paging_attempted_bts[NUM_BTS];
1345 var integer paging_expired_bts[NUM_BTS];
1346 cid_list := valueof(ts_BSSMAP_CIL_noCell);
1347
1348 f_init();
1349
1350 /* read counters before paging */
1351 paging_attempted_bsc := f_ctrl_get_ratectr_abs(IPA_CTRL, "bsc", 0, "paging:attempted");
1352 for (i := 0; i < NUM_BTS; i := i+1) {
1353 paging_attempted_bts[i] := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", i, "paging:attempted");
1354 paging_expired_bts[i] := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", i, "paging:expired");
1355 }
1356
1357 f_pageing_helper('001230000000001'H, cid_list, c_BtsId_all);
1358
1359 /* expect the attempted pages on BSC and each BTSs to have incremented by one */
1360 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bsc", 0, "paging:attempted", paging_attempted_bsc+1);
1361 for (i := 0; i < NUM_BTS; i := i+1) {
1362 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", i, "paging:attempted",
1363 paging_attempted_bts[i]+1);
1364 }
1365
1366 /* assume that 12s later the paging on all BTSs have expired and hence incremented by 1 */
1367 f_sleep(12.0);
1368 for (i := 0; i < NUM_BTS; i := i+1) {
1369 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", i, "paging:expired",
1370 paging_expired_bts[i]+1);
1371 }
Harald Welte1ff69992017-12-14 12:31:17 +01001372
Philipp Maier282ca4b2018-02-27 17:17:00 +01001373 f_shutdown_helper();
Harald Welte1ff69992017-12-14 12:31:17 +01001374}
1375
1376
Harald Welte10985002017-12-12 09:29:15 +01001377/* Verify paging stops after A-RESET */
1378testcase TC_paging_imsi_a_reset() runs on test_CT {
1379 var BSSMAP_FIELD_CellIdentificationList cid_list;
1380 timer T := 3.0;
1381 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01001382 f_pageing_helper('001010123456789'H, cid_list, c_BtsId_all);
Harald Welte10985002017-12-12 09:29:15 +01001383
1384 /* Perform a BSSMAP Reset and wait for ACK */
Harald Weltea4ca4462018-02-09 00:17:14 +01001385 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 +01001386 alt {
Harald Weltea4ca4462018-02-09 00:17:14 +01001387 [] 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 +01001388 [] BSSAP.receive { repeat; }
1389 }
1390
1391 /* Clear the queue, it might still contain stuff like BCCH FILLING */
Philipp Maier1e6b4422018-02-23 14:02:13 +01001392 for (var integer i := 0; i < sizeof(IPA_RSL); i := i+1) {
1393 IPA_RSL[i].clear;
1394 }
Harald Welte10985002017-12-12 09:29:15 +01001395
1396 /* Wait for 3 seconds if any more PAGING CMD are received on RSL */
1397 T.start;
1398 alt {
1399 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0, tr_RSL_PAGING_CMD(?))) {
1400 setverdict(fail, "Received PAGING after A-RESET");
Daniel Willmannafce8662018-07-06 23:11:32 +02001401 mtc.stop;
Harald Welte10985002017-12-12 09:29:15 +01001402 }
Harald Welte5d1a2202017-12-13 19:51:29 +01001403 [] IPA_RSL[1].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0, tr_RSL_PAGING_CMD(?))) {
1404 setverdict(fail, "Received PAGING after A-RESET");
Daniel Willmannafce8662018-07-06 23:11:32 +02001405 mtc.stop;
Harald Welte5d1a2202017-12-13 19:51:29 +01001406 }
1407 [] IPA_RSL[2].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0, tr_RSL_PAGING_CMD(?))) {
1408 setverdict(fail, "Received PAGING after A-RESET");
Daniel Willmannafce8662018-07-06 23:11:32 +02001409 mtc.stop;
Harald Welte5d1a2202017-12-13 19:51:29 +01001410 }
Harald Welte10985002017-12-12 09:29:15 +01001411 [] T.timeout {
1412 setverdict(pass);
1413 }
1414 }
Philipp Maier282ca4b2018-02-27 17:17:00 +01001415
1416 f_shutdown_helper();
Harald Welte10985002017-12-12 09:29:15 +01001417}
Harald Welteae026692017-12-09 01:03:01 +01001418
Harald Welte4e9b9cc2017-12-14 18:31:02 +01001419/* Test RSL link drop causes counter increment */
1420testcase TC_rsl_drop_counter() runs on test_CT {
1421 var integer rsl_fail;
1422
Harald Welte89d42e82017-12-17 16:42:41 +01001423 f_init(1);
Harald Welte4e9b9cc2017-12-14 18:31:02 +01001424
1425 rsl_fail := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "rsl_fail");
1426
1427 bts[0].rsl.vc_IPA.stop;
1428
1429 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "rsl_fail", rsl_fail+1);
1430
1431 setverdict(pass);
1432}
1433
1434/* TODO: Test OML link drop causes counter increment */
1435
Stefan Sperling830dc9d2018-02-12 21:08:28 +01001436/* The body of TC_rsl_unknown_unit_id() and TC_oml_unknown_unit_id() tests. */
1437function f_ipa_unknown_unit_id(integer mp_bsc_ipa_port) runs on test_CT return boolean {
1438 timer T := 10.0;
1439
1440 bts[0].rsl.id := "IPA-0-RSL";
1441 bts[0].rsl.vc_IPA := IPA_Emulation_CT.create(bts[0].rsl.id & "-IPA");
1442 bts[0].rsl.ccm_pars := c_IPA_default_ccm_pars;
1443 bts[0].rsl.ccm_pars.name := "Osmocom TTCN-3 BTS Simulator";
1444 bts[0].rsl.ccm_pars.unit_id := "0/0/0"; /* value which is unknown at BTS */
1445
Stefan Sperling830dc9d2018-02-12 21:08:28 +01001446 f_ipa_ctrl_start(mp_bsc_ip, mp_bsc_ctrl_port);
1447
1448 f_init_mgcp("VirtMSC");
1449
1450 /* start RSL/OML connection (XXX re-uses RSL port/protocol definitions for OML) */
1451 map(bts[0].rsl.vc_IPA:IPA_PORT, system:IPA);
1452 connect(bts[0].rsl.vc_IPA:IPA_RSL_PORT, self:IPA_RSL[0]);
1453 bts[0].rsl.vc_IPA.start(IPA_Emulation.main_client(mp_bsc_ip, mp_bsc_ipa_port, "", 10000, bts[0].rsl.ccm_pars));
1454
1455 /* wait for IPA OML link to connect and then disconnect */
1456 T.start;
1457 alt {
1458 [] IPA_RSL[0].receive(ASP_IPA_Event:{up_down := ASP_IPA_EVENT_DOWN}) {
1459 T.stop;
1460 return true;
1461 }
1462 [] IPA_RSL[0].receive { repeat }
1463 [] T.timeout {
Daniel Willmannafce8662018-07-06 23:11:32 +02001464 return false;
Stefan Sperling830dc9d2018-02-12 21:08:28 +01001465 }
1466 }
Stefan Sperling830dc9d2018-02-12 21:08:28 +01001467 return false;
1468}
1469
1470/* BSC should close an RSL connection from a BTS with unknown unit ID (OS#2714). */
1471testcase TC_rsl_unknown_unit_id() runs on test_CT {
1472 if (f_ipa_unknown_unit_id(mp_bsc_rsl_port)) {
1473 setverdict(pass);
1474 } else {
1475 setverdict(fail, "Timeout RSL waiting for connection to close");
1476 }
1477}
1478
1479
1480/* BSC should close an RSL connection from a BTS with unknown unit ID (OS#2714). */
1481testcase TC_oml_unknown_unit_id() runs on test_CT {
1482 if (f_ipa_unknown_unit_id(mp_bsc_oml_port)) {
1483 setverdict(pass);
1484 } else {
1485 setverdict(fail, "Timeout OML waiting for connection to close");
1486 }
1487}
1488
1489
Harald Weltec1a2fff2017-12-17 11:06:19 +01001490/***********************************************************************
1491 * "New world" test cases using RSL_Emulation + BSSMAP_Emulation
1492 ***********************************************************************/
1493
1494import from BSSMAP_Emulation all;
1495import from RSL_Emulation all;
1496import from MSC_ConnectionHandler all;
1497
1498type function void_fn(charstring id) runs on MSC_ConnHdlr;
1499
Harald Welte336820c2018-05-31 20:34:52 +02001500/* helper function to create and connect a MSC_ConnHdlr component */
Harald Welteff579f92018-05-31 22:19:39 +02001501private function f_connect_handler(inout MSC_ConnHdlr vc_conn) runs on test_CT {
Harald Weltea4ca4462018-02-09 00:17:14 +01001502 connect(vc_conn:BSSMAPEM, g_bssap.vc_BSSMAP:PROC);
Daniel Willmann191e0d92018-01-17 12:44:35 +01001503 connect(vc_conn:MGCP_PROC, vc_MGCP:MGCP_PROC);
Harald Weltec1a2fff2017-12-17 11:06:19 +01001504 connect(vc_conn:RSL, bts[0].rsl.vc_RSL:CLIENT_PT);
Harald Weltef70df652018-01-29 22:00:23 +01001505 connect(vc_conn:RSL_PROC, bts[0].rsl.vc_RSL:RSL_PROC);
Philipp Maier88f4ae82018-03-01 14:00:58 +01001506 if (isvalue(bts[1])) {
Philipp Maier956a92f2018-02-16 10:58:07 +01001507 connect(vc_conn:RSL1, bts[1].rsl.vc_RSL:CLIENT_PT);
1508 connect(vc_conn:RSL1_PROC, bts[1].rsl.vc_RSL:RSL_PROC);
1509 }
Harald Weltea4ca4462018-02-09 00:17:14 +01001510 connect(vc_conn:BSSAP, g_bssap.vc_BSSMAP:CLIENT);
Daniel Willmann191e0d92018-01-17 12:44:35 +01001511 connect(vc_conn:MGCP, vc_MGCP:MGCP_CLIENT);
Harald Welte336820c2018-05-31 20:34:52 +02001512}
1513
1514function f_start_handler(void_fn fn, template (omit) TestHdlrParams pars := omit)
1515runs on test_CT return MSC_ConnHdlr {
1516 var charstring id := testcasename();
1517 var MSC_ConnHdlr vc_conn;
1518 vc_conn := MSC_ConnHdlr.create(id);
1519 f_connect_handler(vc_conn);
Harald Weltea0630032018-03-20 21:09:55 +01001520 vc_conn.start(f_handler_init(fn, id, pars));
Harald Weltec1a2fff2017-12-17 11:06:19 +01001521 return vc_conn;
1522}
1523
Harald Weltea0630032018-03-20 21:09:55 +01001524/* first function inside ConnHdlr component; sets g_pars + starts function */
1525private function f_handler_init(void_fn fn, charstring id, template (omit) TestHdlrParams pars := omit)
1526runs on MSC_ConnHdlr {
1527 if (isvalue(pars)) {
1528 g_pars := valueof(pars);
1529 }
1530 fn.apply(id);
1531}
1532
Harald Welte3c86ea02018-05-10 22:28:05 +02001533/* Establish signalling channel (non-assignment case) followed by cipher mode */
1534private function f_tc_ciph_mode_a5(charstring id) runs on MSC_ConnHdlr {
Harald Welteed848512018-05-24 22:27:58 +02001535 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
1536 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte3c86ea02018-05-10 22:28:05 +02001537 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelTypeSIGNAL);
Philipp Maier23000732018-05-18 11:25:37 +02001538 ass_cmd.pdu.bssmap.assignmentRequest.circuitIdentityCode := omit;
1539 ass_cmd.pdu.bssmap.assignmentRequest.aoIPTransportLayer := omit;
1540 exp_compl.pdu.bssmap.assignmentComplete.circuitIdentityCode := omit;
1541 exp_compl.pdu.bssmap.assignmentComplete.aoIPTransportLayer := omit;
Harald Welte3c86ea02018-05-10 22:28:05 +02001542
Philipp Maier23000732018-05-18 11:25:37 +02001543 f_establish_fully(ass_cmd, exp_compl);
Harald Welte3c86ea02018-05-10 22:28:05 +02001544}
1545testcase TC_ciph_mode_a5_0() runs on test_CT {
1546 var MSC_ConnHdlr vc_conn;
1547 var TestHdlrParams pars := valueof(t_def_TestHdlrPars);
1548 pars.encr := valueof(t_EncrParams('01'O, f_rnd_octstring(8)));
1549
1550 f_init(1, true);
1551 f_sleep(1.0);
1552 vc_conn := f_start_handler(refers(f_tc_ciph_mode_a5), pars);
1553 vc_conn.done;
1554}
1555testcase TC_ciph_mode_a5_1() runs on test_CT {
1556 var MSC_ConnHdlr vc_conn;
1557 var TestHdlrParams pars := valueof(t_def_TestHdlrPars);
1558 pars.encr := valueof(t_EncrParams('02'O, f_rnd_octstring(8)));
1559
1560 f_init(1, true);
1561 f_sleep(1.0);
1562 vc_conn := f_start_handler(refers(f_tc_ciph_mode_a5), pars);
1563 vc_conn.done;
1564}
1565testcase TC_ciph_mode_a5_3() runs on test_CT {
1566 var MSC_ConnHdlr vc_conn;
1567 var TestHdlrParams pars := valueof(t_def_TestHdlrPars);
1568 pars.encr := valueof(t_EncrParams('08'O, f_rnd_octstring(8)));
1569
1570 f_init(1, true);
1571 f_sleep(1.0);
1572 vc_conn := f_start_handler(refers(f_tc_ciph_mode_a5), pars);
1573 vc_conn.done;
1574}
1575
1576
1577/* establish initial channel, enable ciphering followed by assignment to ciphered channel */
Harald Welte651fcdc2018-05-10 20:23:16 +02001578private function f_tc_assignment_fr_a5(charstring id) runs on MSC_ConnHdlr {
Harald Welteed848512018-05-24 22:27:58 +02001579 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
1580 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Weltec1a2fff2017-12-17 11:06:19 +01001581
Harald Welte552620d2017-12-16 23:21:36 +01001582 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
1583 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
Harald Welte73cd2712017-12-17 00:44:52 +01001584
Harald Weltea0630032018-03-20 21:09:55 +01001585 f_establish_fully(ass_cmd, exp_compl);
Harald Welte552620d2017-12-16 23:21:36 +01001586}
Harald Welte552620d2017-12-16 23:21:36 +01001587testcase TC_assignment_fr_a5_0() runs on test_CT {
1588 var MSC_ConnHdlr vc_conn;
Harald Welte651fcdc2018-05-10 20:23:16 +02001589 var TestHdlrParams pars := valueof(t_def_TestHdlrPars);
1590 pars.encr := valueof(t_EncrParams('01'O, f_rnd_octstring(8)));
Harald Welte552620d2017-12-16 23:21:36 +01001591
Harald Welte89d42e82017-12-17 16:42:41 +01001592 f_init(1, true);
Harald Welte552620d2017-12-16 23:21:36 +01001593 f_sleep(1.0);
Harald Welte651fcdc2018-05-10 20:23:16 +02001594 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5), pars);
Harald Welte552620d2017-12-16 23:21:36 +01001595 vc_conn.done;
1596}
Harald Welte552620d2017-12-16 23:21:36 +01001597testcase TC_assignment_fr_a5_1() runs on test_CT {
Harald Weltec1a2fff2017-12-17 11:06:19 +01001598 var MSC_ConnHdlr vc_conn;
Harald Welte651fcdc2018-05-10 20:23:16 +02001599 var TestHdlrParams pars := valueof(t_def_TestHdlrPars);
1600 pars.encr := valueof(t_EncrParams('02'O, f_rnd_octstring(8)));
Harald Weltec1a2fff2017-12-17 11:06:19 +01001601
Harald Welte89d42e82017-12-17 16:42:41 +01001602 f_init(1, true);
Harald Weltec1a2fff2017-12-17 11:06:19 +01001603 f_sleep(1.0);
Harald Welte651fcdc2018-05-10 20:23:16 +02001604 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5), pars);
1605 vc_conn.done;
1606}
1607testcase TC_assignment_fr_a5_3() runs on test_CT {
1608 var MSC_ConnHdlr vc_conn;
1609 var TestHdlrParams pars := valueof(t_def_TestHdlrPars);
1610 pars.encr := valueof(t_EncrParams('08'O, f_rnd_octstring(8)));
Harald Weltec1a2fff2017-12-17 11:06:19 +01001611
Harald Welte651fcdc2018-05-10 20:23:16 +02001612 f_init(1, true);
1613 f_sleep(1.0);
1614 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5), pars);
Harald Weltec1a2fff2017-12-17 11:06:19 +01001615 vc_conn.done;
1616}
1617
Harald Welte552620d2017-12-16 23:21:36 +01001618/* Expect ASSIGNMENT FAIL if mandatory IE is missing */
1619private function f_tc_assignment_fr_a5_1_codec_missing(charstring id) runs on MSC_ConnHdlr {
Harald Weltea0630032018-03-20 21:09:55 +01001620 g_pars := valueof(t_def_TestHdlrPars);
Harald Welte552620d2017-12-16 23:21:36 +01001621 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
Harald Welteed848512018-05-24 22:27:58 +02001622 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte552620d2017-12-16 23:21:36 +01001623 const OCT8 kc := '0001020304050607'O;
1624
1625 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
Harald Weltea0630032018-03-20 21:09:55 +01001626 f_establish_fully(ass_cmd, exp_fail);
Harald Welte552620d2017-12-16 23:21:36 +01001627}
Harald Welte552620d2017-12-16 23:21:36 +01001628testcase TC_assignment_fr_a5_1_codec_missing() runs on test_CT {
1629 var MSC_ConnHdlr vc_conn;
1630
Harald Welte89d42e82017-12-17 16:42:41 +01001631 f_init(1, true);
Harald Welte552620d2017-12-16 23:21:36 +01001632 f_sleep(1.0);
1633
Harald Welte8863fa12018-05-10 20:15:27 +02001634 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5_1_codec_missing));
Harald Welte552620d2017-12-16 23:21:36 +01001635 vc_conn.done;
1636}
1637
Harald Welte552620d2017-12-16 23:21:36 +01001638private function f_tc_assignment_fr_a5_4(charstring id) runs on MSC_ConnHdlr {
Harald Weltea0630032018-03-20 21:09:55 +01001639 g_pars := valueof(t_def_TestHdlrPars);
Harald Welteed848512018-05-24 22:27:58 +02001640 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
1641 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte552620d2017-12-16 23:21:36 +01001642 const OCT8 kc := '0001020304050607'O;
1643 const OCT16 kc128 := kc & kc;
1644
1645 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
1646 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
Harald Weltea0630032018-03-20 21:09:55 +01001647 f_establish_fully(ass_cmd, exp_compl);
Harald Welte38b2a102017-12-23 02:42:58 +01001648 f_cipher_mode('10'O, kc, kc128, true);
Harald Welte552620d2017-12-16 23:21:36 +01001649 /* TODO: expect GSM0808_CAUSE_CIPHERING_ALGORITHM_NOT_SUPPORTED cause value */
Harald Welte552620d2017-12-16 23:21:36 +01001650}
Harald Welte552620d2017-12-16 23:21:36 +01001651testcase TC_assignment_fr_a5_4() runs on test_CT {
1652 var MSC_ConnHdlr vc_conn;
1653
Harald Welte89d42e82017-12-17 16:42:41 +01001654 f_init(1, true);
Harald Welte552620d2017-12-16 23:21:36 +01001655 f_sleep(1.0);
1656
Harald Welte8863fa12018-05-10 20:15:27 +02001657 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5_4));
Harald Welte552620d2017-12-16 23:21:36 +01001658 vc_conn.done;
1659}
1660
1661
Harald Welte4532e0a2017-12-23 02:05:44 +01001662private function f_tc_assignment_sign(charstring id) runs on MSC_ConnHdlr {
Philipp Maier6a50c7c2018-04-16 16:15:59 +02001663 g_pars := valueof(t_def_TestHdlrPars);
Harald Welte4532e0a2017-12-23 02:05:44 +01001664 var template PDU_BSSAP exp_compl := tr_BSSMAP_AssignmentComplete(omit, omit);
1665 var PDU_BSSAP ass_cmd := valueof(ts_BSSMAP_AssignmentReq(omit, omit));
1666
1667 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelTypeSIGNAL);
Harald Weltea0630032018-03-20 21:09:55 +01001668 f_establish_fully(ass_cmd, exp_compl);
Harald Welte4532e0a2017-12-23 02:05:44 +01001669}
1670
1671testcase TC_assignment_sign() runs on test_CT {
1672 var MSC_ConnHdlr vc_conn;
1673
1674 f_init(1, true);
1675 f_sleep(1.0);
1676
Harald Welte8863fa12018-05-10 20:15:27 +02001677 vc_conn := f_start_handler(refers(f_tc_assignment_sign));
Harald Welte4532e0a2017-12-23 02:05:44 +01001678 vc_conn.done;
1679}
1680
Harald Welte60aa5762018-03-21 19:33:13 +01001681/***********************************************************************
1682 * Codec (list) testing
1683 ***********************************************************************/
1684
1685/* check if the given rsl_mode is compatible with the a_elem */
1686private function f_match_codec(BSSMAP_FIELD_CodecElement a_elem, RSL_IE_ChannelMode rsl_mode)
1687return boolean {
1688 select (a_elem.codecType) {
1689 case (GSM_FR) {
1690 if (match(rsl_mode, tr_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM1))) {
1691 return true;
1692 }
1693 }
1694 case (GSM_HR) {
1695 if (match(rsl_mode, tr_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1))) {
1696 return true;
1697 }
1698 }
1699 case (GSM_EFR) {
1700 if (match(rsl_mode, tr_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM2))) {
1701 return true;
1702 }
1703 }
1704 case (FR_AMR) {
1705 if (match(rsl_mode, tr_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM3))) {
1706 return true;
1707 }
1708 }
1709 case (HR_AMR) {
1710 if (match(rsl_mode, tr_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM3))) {
1711 return true;
1712 }
1713 }
1714 case else { }
1715 }
1716 return false;
1717}
1718
1719/* check if the given rsl_mode is compatible with the a_list */
1720private function f_match_codecs(BSSMAP_IE_SpeechCodecList a_list, RSL_IE_ChannelMode rsl_mode)
1721return boolean {
1722 for (var integer i := 0; i < sizeof(a_list); i := i+1) {
1723 if (f_match_codec(a_list.codecElements[i], rsl_mode)) {
1724 return true;
1725 }
1726 }
1727 return false;
1728}
1729
1730/* determine BSSMAP_IE_ChannelType from *first* element of BSSMAP_FIELD_CodecElement */
Philipp Maier61f6b572018-07-06 14:03:38 +02001731function f_BSSMAP_chtype_from_codec(BSSMAP_FIELD_CodecElement a_elem)
Harald Welte60aa5762018-03-21 19:33:13 +01001732return BSSMAP_IE_ChannelType {
1733 /* FIXME: actually look at all elements of BSSMAP_IE_SpeechCodecList */
1734 var BSSMAP_IE_ChannelType ret := valueof(ts_BSSMAP_IE_ChannelType);
1735 select (a_elem.codecType) {
1736 case (GSM_FR) {
1737 ret.channelRateAndType := ChRate_TCHF;
1738 ret.speechId_DataIndicator := Spdi_TCHF_FR;
1739 }
1740 case (GSM_HR) {
1741 ret.channelRateAndType := ChRate_TCHH;
1742 ret.speechId_DataIndicator := Spdi_TCHH_HR;
1743 }
1744 case (GSM_EFR) {
1745 ret.channelRateAndType := ChRate_TCHF;
1746 ret.speechId_DataIndicator := Spdi_TCHF_EFR;
1747 }
1748 case (FR_AMR) {
1749 ret.channelRateAndType := ChRate_TCHF;
1750 ret.speechId_DataIndicator := Spdi_TCHF_AMR;
1751 }
1752 case (HR_AMR) {
1753 ret.channelRateAndType := ChRate_TCHH;
1754 ret.speechId_DataIndicator := Spdi_TCHH_AMR;
1755 }
1756 case else {
1757 setverdict(fail, "Unsupported codec ", a_elem);
Daniel Willmannafce8662018-07-06 23:11:32 +02001758 mtc.stop;
Harald Welte60aa5762018-03-21 19:33:13 +01001759 }
1760 }
1761 return ret;
1762}
1763
Harald Weltea63b9102018-03-22 20:36:16 +01001764private function f_rsl_chmod_tmpl_from_codec(BSSMAP_FIELD_CodecElement a_elem)
1765return template RSL_IE_Body {
1766 var template RSL_IE_Body mode_ie := {
1767 chan_mode := {
1768 len := ?,
1769 reserved := ?,
1770 dtx_d := ?,
1771 dtx_u := ?,
1772 spd_ind := RSL_SPDI_SPEECH,
1773 ch_rate_type := -,
1774 coding_alg_rate := -
1775 }
1776 }
1777
1778 select (a_elem.codecType) {
1779 case (GSM_FR) {
1780 mode_ie.chan_mode.ch_rate_type := RSL_CHRT_TCH_F;
1781 mode_ie.chan_mode.coding_alg_rate := RSL_CMOD_SP_GSM1;
1782 }
1783 case (GSM_HR) {
1784 mode_ie.chan_mode.ch_rate_type := RSL_CHRT_TCH_H;
1785 mode_ie.chan_mode.coding_alg_rate := RSL_CMOD_SP_GSM1;
1786 }
1787 case (GSM_EFR) {
1788 mode_ie.chan_mode.ch_rate_type := RSL_CHRT_TCH_F;
1789 mode_ie.chan_mode.coding_alg_rate := RSL_CMOD_SP_GSM2;
1790 }
1791 case (FR_AMR) {
1792 mode_ie.chan_mode.ch_rate_type := RSL_CHRT_TCH_F;
1793 mode_ie.chan_mode.coding_alg_rate := RSL_CMOD_SP_GSM3;
1794 }
1795 case (HR_AMR) {
1796 mode_ie.chan_mode.ch_rate_type := RSL_CHRT_TCH_H;
1797 mode_ie.chan_mode.coding_alg_rate := RSL_CMOD_SP_GSM3;
1798 }
1799 }
1800 return mode_ie;
1801}
1802
Harald Welte60aa5762018-03-21 19:33:13 +01001803type record CodecListTest {
1804 BSSMAP_IE_SpeechCodecList codec_list,
1805 charstring id
1806}
1807type record of CodecListTest CodecListTests
1808
1809private function f_TC_assignment_codec(charstring id) runs on MSC_ConnHdlr {
Harald Welteed848512018-05-24 22:27:58 +02001810 var PDU_BSSAP ass_cmd := f_gen_ass_req();
1811 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
Harald Welte60aa5762018-03-21 19:33:13 +01001812
1813 /* puzzle together the ASSIGNMENT REQ for given codec[s] */
Harald Welte79f3f542018-05-25 20:02:37 +02001814 if (mp_bssap_cfg.transport == BSSAP_TRANSPORT_AoIP) {
1815 ass_cmd.pdu.bssmap.assignmentRequest.codecList := g_pars.ass_codec_list;
1816 exp_compl.pdu.bssmap.assignmentComplete.speechCodec.codecElements[0] :=
1817 g_pars.ass_codec_list.codecElements[0];
1818 }
Harald Welte60aa5762018-03-21 19:33:13 +01001819 ass_cmd.pdu.bssmap.assignmentRequest.channelType :=
1820 f_BSSMAP_chtype_from_codec(g_pars.ass_codec_list.codecElements[0]);
Harald Welte60aa5762018-03-21 19:33:13 +01001821 log("expecting ASS COMPL like this: ", exp_compl);
1822
1823 f_establish_fully(ass_cmd, exp_compl);
Harald Weltea63b9102018-03-22 20:36:16 +01001824
1825 /* Verify that the RSL-side activation actually matches our expectations */
1826 var RSL_Message rsl := f_rslem_get_last_act(RSL_PROC, 0, g_chan_nr);
1827
1828 var RSL_IE_Body mode_ie;
1829 if (f_rsl_find_ie(rsl, RSL_IE_CHAN_MODE, mode_ie) == false) {
1830 setverdict(fail, "Couldn't find CHAN_MODE IE");
Daniel Willmannafce8662018-07-06 23:11:32 +02001831 mtc.stop;
Harald Weltea63b9102018-03-22 20:36:16 +01001832 }
1833 var template RSL_IE_Body t_mode_ie := f_rsl_chmod_tmpl_from_codec(g_pars.ass_codec_list.codecElements[0]);
1834 if (not match(mode_ie, t_mode_ie)) {
1835 setverdict(fail, "RSL Channel Mode IE doesn't match expectation");
1836 }
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02001837
1838 var RSL_IE_Body mr_conf;
1839 if (g_pars.expect_mr_conf_ie != omit) {
1840 if (f_rsl_find_ie(rsl, RSL_IE_MR_CONFIG, mr_conf) == false) {
1841 setverdict(fail, "Missing MR CONFIG IE in RSL Chan Activ");
Daniel Willmannafce8662018-07-06 23:11:32 +02001842 mtc.stop;
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02001843 }
1844 log("found RSL MR CONFIG IE: ", mr_conf);
1845
1846 if (not match(mr_conf, g_pars.expect_mr_conf_ie)) {
1847 setverdict(fail, "RSL MR CONFIG IE does not match expectation. Expected: ",
1848 g_pars.expect_mr_conf_ie);
1849 }
1850 } else {
1851 if (f_rsl_find_ie(rsl, RSL_IE_MR_CONFIG, mr_conf) == true) {
1852 log("found RSL MR CONFIG IE: ", mr_conf);
1853 setverdict(fail, "Found MR CONFIG IE in RSL Chan Activ, expecting omit");
Daniel Willmannafce8662018-07-06 23:11:32 +02001854 mtc.stop;
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02001855 }
1856 }
Harald Welte60aa5762018-03-21 19:33:13 +01001857}
1858
1859testcase TC_assignment_codec_fr() runs on test_CT {
1860 var TestHdlrParams pars := valueof(t_def_TestHdlrPars);
1861 var MSC_ConnHdlr vc_conn;
1862
1863 f_init(1, true);
1864 f_sleep(1.0);
1865
1866 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
Harald Welte8863fa12018-05-10 20:15:27 +02001867 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
Harald Welte60aa5762018-03-21 19:33:13 +01001868 vc_conn.done;
1869}
1870
1871testcase TC_assignment_codec_hr() runs on test_CT {
1872 var TestHdlrParams pars := valueof(t_def_TestHdlrPars);
1873 var MSC_ConnHdlr vc_conn;
1874
1875 f_init(1, true);
1876 f_sleep(1.0);
1877
1878 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecHR}));
Harald Welte8863fa12018-05-10 20:15:27 +02001879 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
Harald Welte60aa5762018-03-21 19:33:13 +01001880 vc_conn.done;
1881}
1882
1883testcase TC_assignment_codec_efr() runs on test_CT {
1884 var TestHdlrParams pars := valueof(t_def_TestHdlrPars);
1885 var MSC_ConnHdlr vc_conn;
1886
1887 f_init(1, true);
1888 f_sleep(1.0);
1889
1890 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecEFR}));
Harald Welte8863fa12018-05-10 20:15:27 +02001891 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
Harald Welte60aa5762018-03-21 19:33:13 +01001892 vc_conn.done;
1893}
1894
1895testcase TC_assignment_codec_amr_f() runs on test_CT {
1896 var TestHdlrParams pars := valueof(t_def_TestHdlrPars);
1897 var MSC_ConnHdlr vc_conn;
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02001898 var RSL_IE_Body mr_conf := {
1899 other := {
1900 len := 2,
1901 payload := '2804'O
1902 }
1903 };
Harald Welte60aa5762018-03-21 19:33:13 +01001904
1905 f_init(1, true);
1906 f_sleep(1.0);
1907
1908 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_F}));
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02001909 pars.expect_mr_conf_ie := mr_conf;
Harald Welte8863fa12018-05-10 20:15:27 +02001910 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
Harald Welte60aa5762018-03-21 19:33:13 +01001911 vc_conn.done;
1912}
1913
1914testcase TC_assignment_codec_amr_h() runs on test_CT {
1915 var TestHdlrParams pars := valueof(t_def_TestHdlrPars);
1916 var MSC_ConnHdlr vc_conn;
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02001917 var RSL_IE_Body mr_conf := {
1918 other := {
1919 len := 2,
1920 payload := '2804'O
1921 }
1922 };
Harald Welte60aa5762018-03-21 19:33:13 +01001923
1924 f_init(1, true);
1925 f_sleep(1.0);
1926
1927 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_H}));
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02001928 pars.expect_mr_conf_ie := mr_conf;
Harald Welte8863fa12018-05-10 20:15:27 +02001929 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
Harald Welte60aa5762018-03-21 19:33:13 +01001930 vc_conn.done;
1931}
1932
Harald Welte898113b2018-01-31 18:32:21 +01001933/* test if L3 RR CLASSMARK CHANGE is translated to BSSMAP CLASSMARK UPDATE */
1934private function f_tc_classmark(charstring id) runs on MSC_ConnHdlr {
Harald Weltea0630032018-03-20 21:09:55 +01001935 g_pars := valueof(t_def_TestHdlrPars);
1936 f_create_chan_and_exp();
Harald Welte898113b2018-01-31 18:32:21 +01001937 /* we should now have a COMPL_L3 at the MSC */
1938 BSSAP.receive(tr_BSSMAP_ComplL3);
1939
1940 f_rsl_send_l3(ts_RRM_CM_CHG(valueof(ts_CM2)));
1941 BSSAP.receive(tr_BSSMAP_ClassmarkUpd(?, omit));
1942 setverdict(pass);
1943}
1944testcase TC_classmark() runs on test_CT {
1945 var MSC_ConnHdlr vc_conn;
1946 f_init(1, true);
1947 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02001948 vc_conn := f_start_handler(refers(f_tc_classmark));
Harald Welte898113b2018-01-31 18:32:21 +01001949 vc_conn.done;
1950}
1951
Harald Weltee3bd6582018-01-31 22:51:25 +01001952private function f_est_single_l3(template PDU_ML3_MS_NW l3) runs on MSC_ConnHdlr {
Harald Weltea0630032018-03-20 21:09:55 +01001953 g_pars := valueof(t_def_TestHdlrPars);
1954 f_create_chan_and_exp();
Harald Welte898113b2018-01-31 18:32:21 +01001955 /* we should now have a COMPL_L3 at the MSC */
1956 BSSAP.receive(tr_BSSMAP_ComplL3);
1957
Harald Weltee3bd6582018-01-31 22:51:25 +01001958 /* send the single message we want to send */
1959 f_rsl_send_l3(l3);
1960}
1961
1962private function f_bssap_expect_nothing(float sec := 5.00) runs on MSC_ConnHdlr {
1963 timer T := sec;
1964 var PDU_BSSAP bssap;
Harald Welte898113b2018-01-31 18:32:21 +01001965 T.start;
1966 alt {
Harald Weltee3bd6582018-01-31 22:51:25 +01001967 [] BSSAP.receive(PDU_BSSAP:?) -> value bssap {
1968 setverdict(fail, "Unexpected BSSMAP ", bssap);
Daniel Willmannafce8662018-07-06 23:11:32 +02001969 mtc.stop;
Harald Welte898113b2018-01-31 18:32:21 +01001970 }
1971 [] T.timeout {
1972 setverdict(pass);
1973 }
1974 }
1975}
1976
Harald Weltee3bd6582018-01-31 22:51:25 +01001977/* unsolicited ASSIGNMENT FAIL (without ASSIGN) from MS shouldn't bring BSC down */
1978private function f_tc_unsol_ass_fail(charstring id) runs on MSC_ConnHdlr {
1979 f_est_single_l3(ts_RRM_AssignmentFailure('00'O));
1980 f_bssap_expect_nothing();
1981}
Harald Welte898113b2018-01-31 18:32:21 +01001982testcase TC_unsol_ass_fail() runs on test_CT {
1983 var MSC_ConnHdlr vc_conn;
1984 f_init(1, true);
1985 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02001986 vc_conn := f_start_handler(refers(f_tc_unsol_ass_fail));
Harald Welte898113b2018-01-31 18:32:21 +01001987 vc_conn.done;
1988}
Harald Welte552620d2017-12-16 23:21:36 +01001989
Harald Welteea99a002018-01-31 20:46:43 +01001990
1991/* unsolicited ASSIGNMENT COMPLETE (without ASSIGN) from MS shouldn't bring BSC down */
1992private function f_tc_unsol_ass_compl(charstring id) runs on MSC_ConnHdlr {
Harald Weltee3bd6582018-01-31 22:51:25 +01001993 f_est_single_l3(ts_RRM_AssignmentComplete('00'O));
1994 f_bssap_expect_nothing();
Harald Welteea99a002018-01-31 20:46:43 +01001995}
1996testcase TC_unsol_ass_compl() runs on test_CT {
1997 var MSC_ConnHdlr vc_conn;
1998 f_init(1, true);
1999 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02002000 vc_conn := f_start_handler(refers(f_tc_unsol_ass_compl));
Harald Welteea99a002018-01-31 20:46:43 +01002001 vc_conn.done;
2002}
2003
2004
Harald Weltefbf9b5e2018-01-31 20:41:23 +01002005/* unsolicited HANDOVER FAIL (without ASSIGN) from MS shouldn't bring BSC down */
2006private function f_tc_unsol_ho_fail(charstring id) runs on MSC_ConnHdlr {
Harald Weltee3bd6582018-01-31 22:51:25 +01002007 f_est_single_l3(ts_RRM_HandoverFailure('00'O));
2008 f_bssap_expect_nothing();
Harald Weltefbf9b5e2018-01-31 20:41:23 +01002009}
Harald Weltefbf9b5e2018-01-31 20:41:23 +01002010testcase TC_unsol_ho_fail() runs on test_CT {
2011 var MSC_ConnHdlr vc_conn;
2012 f_init(1, true);
2013 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02002014 vc_conn := f_start_handler(refers(f_tc_unsol_ho_fail));
Harald Weltefbf9b5e2018-01-31 20:41:23 +01002015 vc_conn.done;
2016}
2017
2018
Harald Weltee3bd6582018-01-31 22:51:25 +01002019/* short message from MS should be ignored */
2020private function f_tc_err_82_short_msg(charstring id) runs on MSC_ConnHdlr {
Harald Weltea0630032018-03-20 21:09:55 +01002021 g_pars := valueof(t_def_TestHdlrPars);
2022 f_create_chan_and_exp();
Harald Weltee3bd6582018-01-31 22:51:25 +01002023 /* we should now have a COMPL_L3 at the MSC */
2024 BSSAP.receive(tr_BSSMAP_ComplL3);
2025
2026 /* send short message */
2027 RSL.send(ts_RSL_DATA_IND(g_chan_nr, valueof(ts_RslLinkID_DCCH(0)), ''O));
2028 f_bssap_expect_nothing();
2029}
2030testcase TC_err_82_short_msg() runs on test_CT {
2031 var MSC_ConnHdlr vc_conn;
2032 f_init(1, true);
2033 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02002034 vc_conn := f_start_handler(refers(f_tc_err_82_short_msg));
Harald Weltee3bd6582018-01-31 22:51:25 +01002035 vc_conn.done;
2036}
2037
2038
Harald Weltee9e02e42018-01-31 23:36:25 +01002039/* 24.008 8.4 Unknown message must trigger RR STATUS */
2040private function f_tc_err_84_unknown_msg(charstring id) runs on MSC_ConnHdlr {
2041 f_est_single_l3(ts_RRM_UL_REL('00'O));
2042 timer T := 3.0
2043 alt {
2044 [] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch tr_RRM_RR_STATUS)) {
2045 setverdict(pass);
2046 }
2047 [] BSSAP.receive { setverdict(fail, "unexpected BSSAP"); }
Harald Welte458fd372018-03-21 11:26:23 +01002048 [] T.timeout { setverdict(fail, "Timeout waiting for RR STATUS"); }
Harald Weltee9e02e42018-01-31 23:36:25 +01002049 }
2050}
2051testcase TC_err_84_unknown_msg() runs on test_CT {
2052 var MSC_ConnHdlr vc_conn;
2053 f_init(1, true);
2054 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02002055 vc_conn := f_start_handler(refers(f_tc_err_84_unknown_msg));
Harald Weltee9e02e42018-01-31 23:36:25 +01002056 vc_conn.done;
2057}
2058
Harald Welte94e0c342018-04-07 11:33:23 +02002059/* execute a "bts <0-255> trx <0-255> timeslot <0-7> " command on given Dchan */
2060private function f_vty_ts_action(charstring suffix, integer bts_nr, integer trx_nr, integer ts_nr)
2061runs on test_CT {
2062 var charstring cmd := "bts "&int2str(bts_nr)&" trx "&int2str(trx_nr)&
2063 " timeslot "&int2str(ts_nr)&" ";
2064 f_vty_transceive(BSCVTY, cmd & suffix);
2065}
2066
Harald Welte261af4b2018-02-12 21:20:39 +01002067/* execute a "bts <0-255> trx <0-255> timeslot <0-7> sub-slot <0-7>" command on given Dchan */
2068private function f_vty_ss_action(charstring suffix, integer bts_nr, integer trx_nr, RslChannelNr chan_nr)
2069runs on MSC_ConnHdlr {
2070 /* FIXME: resolve those from component-global state */
2071 var integer ts_nr := chan_nr.tn;
2072 var integer ss_nr;
2073 if (ischosen(chan_nr.u.ch0)) {
2074 ss_nr := 0;
2075 } else if (ischosen(chan_nr.u.lm)) {
2076 ss_nr := chan_nr.u.lm.sub_chan;
2077 } else if (ischosen(chan_nr.u.sdcch4)) {
2078 ss_nr := chan_nr.u.sdcch4.sub_chan;
2079 } else if (ischosen(chan_nr.u.sdcch8)) {
2080 ss_nr := chan_nr.u.sdcch8.sub_chan;
2081 } else {
2082 setverdict(fail, "Invalid ChanNr ", chan_nr);
Daniel Willmannafce8662018-07-06 23:11:32 +02002083 mtc.stop;
Harald Welte261af4b2018-02-12 21:20:39 +01002084 }
2085
2086 var charstring cmd := "bts "&int2str(bts_nr)&" trx "&int2str(trx_nr)&
2087 " timeslot "&int2str(ts_nr)&" sub-slot "&int2str(ss_nr)&" ";
2088 f_vty_transceive(BSCVTY, cmd & suffix);
2089}
2090
2091private function f_vty_handover(integer bts_nr, integer trx_nr, RslChannelNr chan_nr,
2092 integer new_bts_nr)
2093runs on MSC_ConnHdlr {
2094 f_vty_ss_action("handover " & int2str(new_bts_nr), bts_nr, trx_nr, chan_nr);
2095}
2096
2097/* intra-BSC hand-over between BTS0 and BTS1 */
2098private function f_tc_ho_int(charstring id) runs on MSC_ConnHdlr {
Harald Weltea0630032018-03-20 21:09:55 +01002099 g_pars := valueof(t_def_TestHdlrPars);
Harald Welteed848512018-05-24 22:27:58 +02002100 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
2101 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte261af4b2018-02-12 21:20:39 +01002102 const OCT8 kc := '0001020304050607'O;
2103
2104 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
2105 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
2106
Harald Weltea0630032018-03-20 21:09:55 +01002107 f_establish_fully(ass_cmd, exp_compl);
Harald Welte261af4b2018-02-12 21:20:39 +01002108
2109 var HandoverState hs := {
2110 rr_ho_cmpl_seen := false,
2111 handover_done := false,
2112 old_chan_nr := -
2113 };
2114 /* issue hand-over command on VTY */
2115 f_vty_handover(0, 0, g_chan_nr, 1);
2116 /* temporarily suspend DChan processing on BTS1 to avoid race with RSLEM_register */
2117 f_rslem_suspend(RSL1_PROC);
Philipp Maier3e2af5d2018-07-11 17:01:05 +02002118
2119 /* From the MGW perspective, a handover is is characterized by
2120 * performing one MDCX operation with the MGW. So we expect to see
2121 * one more MDCX during handover. */
2122 g_media.mgcp_conn[0].mdcx_seen_exp := g_media.mgcp_conn[0].crcx_seen_exp + 1;
2123
Harald Welte261af4b2018-02-12 21:20:39 +01002124 alt {
2125 [] as_handover(hs);
Harald Welte261af4b2018-02-12 21:20:39 +01002126 }
Philipp Maier3e2af5d2018-07-11 17:01:05 +02002127
2128 /* Check the amount of MGCP transactions is still consistant with the
2129 * test expectation */
2130 f_check_mgcp_expectations()
Harald Welte261af4b2018-02-12 21:20:39 +01002131}
2132
2133testcase TC_ho_int() runs on test_CT {
2134 var MSC_ConnHdlr vc_conn;
2135 f_init(2, true);
2136 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02002137 vc_conn := f_start_handler(refers(f_tc_ho_int));
Harald Welte261af4b2018-02-12 21:20:39 +01002138 vc_conn.done;
2139}
Harald Weltee9e02e42018-01-31 23:36:25 +01002140
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +01002141/* OS#3041: Open and close N connections in a normal fashion, and expect no
2142 * BSSMAP Reset just because of that. */
2143testcase TC_bssap_rlsd_does_not_cause_bssmap_reset() runs on test_CT {
2144 var default d;
2145 var integer i;
2146 var DchanTuple dt;
2147
2148 f_init();
2149
2150 /* Wait for initial BSSMAP Reset to pass */
2151 f_sleep(4.0);
2152
2153 d := activate(no_bssmap_reset());
2154
2155 /* Setup up a number of connections and RLSD them again from the MSC
2156 * side. In the buggy behavior, the fourth one triggers BSSMAP Reset.
2157 * Let's do it some more times for good measure. */
Harald Weltec3260d92018-06-11 17:48:16 +02002158 for (i := 0; i < 4; i := i+1) {
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +01002159 /* Since we're doing a lot of runs, give each one a fresh
2160 * T_guard from the top. */
2161 T_guard.start;
2162
2163 /* Setup a BSSAP connection and clear it right away. This is
2164 * the MSC telling the BSC about a planned release, it's not an
2165 * erratic loss of a connection. */
Harald Weltea1897182018-06-11 13:53:09 +02002166 dt := f_est_dchan(int2oct(i,1), 23+i, '00010203040506'O);
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +01002167
2168 /* MSC disconnects (RLSD). */
2169 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
2170 }
2171
2172 /* In the buggy behavior, a timeout of 2 seconds happens between above
2173 * trigger (logs "SIGTRAN connection down, reconnecting...") and the
2174 * actual BSSMAP Reset. Wait a bit longer just to make sure. */
2175 f_sleep(4.0);
2176
2177 deactivate(d);
2178 f_shutdown_helper();
2179}
Harald Welte552620d2017-12-16 23:21:36 +01002180
Neels Hofmeyr4ff93282018-03-12 04:25:35 +01002181/* OS#3041: Open and close N connections in a normal fashion, and expect no
2182 * BSSMAP Reset just because of that. Invoke the release by a BSSMAP Clear from
2183 * the MSC. */
2184testcase TC_bssmap_clear_does_not_cause_bssmap_reset() runs on test_CT {
2185 var default d;
2186 var integer i;
2187 var DchanTuple dt;
2188 var BSSAP_N_DATA_ind rx_di;
Neels Hofmeyr4ff93282018-03-12 04:25:35 +01002189 var myBSSMAP_Cause cause_val := GSM0808_CAUSE_CALL_CONTROL;
2190 var BssmapCause cause := enum2int(cause_val);
2191
2192 f_init();
2193
2194 /* Wait for initial BSSMAP Reset to pass */
2195 f_sleep(4.0);
2196
2197 d := activate(no_bssmap_reset());
2198
2199 /* Setup up a number of connections and RLSD them again from the MSC
2200 * side. In the buggy behavior, the fourth one triggers BSSMAP Reset.
2201 * Let's do it some more times for good measure. */
2202 for (i := 0; i < 8; i := i+1) {
2203 /* Since we're doing a lot of runs, give each one a fresh
2204 * T_guard from the top. */
2205 T_guard.start;
2206
2207 /* Setup a BSSAP connection and clear it right away. This is
2208 * the MSC telling the BSC about a planned release, it's not an
2209 * erratic loss of a connection. */
Harald Weltea1897182018-06-11 13:53:09 +02002210 dt := f_est_dchan(int2oct(i,1), 23+i, '00010203040506'O);
Neels Hofmeyr4ff93282018-03-12 04:25:35 +01002211
2212 /* Instruct BSC to clear channel */
2213 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
2214
2215 /* expect BSC to disable the channel */
Harald Welte641fcbe2018-06-14 10:58:35 +02002216 f_exp_chan_rel_and_clear(dt, 0);
Neels Hofmeyr4ff93282018-03-12 04:25:35 +01002217 }
2218
2219 /* In the buggy behavior, a timeout of 2 seconds happens between above
2220 * trigger (logs "SIGTRAN connection down, reconnecting...") and the
2221 * actual BSSMAP Reset. Wait a bit longer just to make sure. */
2222 f_sleep(4.0);
2223
2224 deactivate(d);
2225 f_shutdown_helper();
2226}
2227
Neels Hofmeyrfd445c32018-03-09 15:39:31 +01002228/* OS#3041: Open and close N connections in a normal fashion, and expect no
2229 * BSSMAP Reset just because of that. Close connections from the MS side with a
2230 * Release Ind on RSL. */
2231testcase TC_ms_rel_ind_does_not_cause_bssmap_reset() runs on test_CT {
2232 var default d;
2233 var integer i;
2234 var DchanTuple dt;
2235 var BSSAP_N_DATA_ind rx_di;
Neels Hofmeyrfd445c32018-03-09 15:39:31 +01002236 var integer j;
2237
2238 f_init();
2239
2240 /* Wait for initial BSSMAP Reset to pass */
2241 f_sleep(4.0);
2242
2243 d := activate(no_bssmap_reset());
2244
2245 /* Setup up a number of connections and RLSD them again from the MSC
2246 * side. In the buggy behavior, the fourth one triggers BSSMAP Reset.
2247 * Let's do it some more times for good measure. */
2248 for (i := 0; i < 8; i := i+1) {
2249 /* Since we're doing a lot of runs, give each one a fresh
2250 * T_guard from the top. */
2251 T_guard.start;
2252
2253 /* Setup a BSSAP connection and clear it right away. This is
2254 * the MSC telling the BSC about a planned release, it's not an
2255 * erratic loss of a connection. */
2256 dt := f_est_dchan('23'O, 23, '00010203040506'O);
2257
2258 /* simulate RLL REL IND */
2259 f_ipa_tx(0, ts_RSL_REL_IND(dt.rsl_chan_nr, valueof(ts_RslLinkID_DCCH(0))));
2260
2261 /* expect Clear Request on MSC side */
2262 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearRequest)) -> value rx_di;
2263
2264 /* Instruct BSC to clear channel */
2265 var BssmapCause cause := bit2int(rx_di.userData.pdu.bssmap.clearRequest.cause.causeValue);
2266 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
2267
2268 /* expect BSC to disable the channel */
Harald Welte641fcbe2018-06-14 10:58:35 +02002269 f_exp_chan_rel_and_clear(dt, 0);
Neels Hofmeyrfd445c32018-03-09 15:39:31 +01002270 }
2271
2272 /* In the buggy behavior, a timeout of 2 seconds happens between above
2273 * trigger (logs "SIGTRAN connection down, reconnecting...") and the
2274 * actual BSSMAP Reset. Wait a bit longer just to make sure. */
2275 f_sleep(4.0);
2276
2277 deactivate(d);
2278 f_shutdown_helper();
2279}
2280
Harald Welte94e0c342018-04-07 11:33:23 +02002281/***********************************************************************
2282 * IPA style dynamic PDCH
2283 ***********************************************************************/
2284
2285private function f_dyn_ipa_pdch_act(integer bts_nr, integer trx_nr, integer ts_nr,
2286 template (omit) RSL_Cause nack := omit)
2287runs on test_CT {
2288 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(ts_nr));
2289 var RSL_Message rsl_unused;
2290 /* ask BSC via VTY to activate a given IPA style chan as PDCH */
2291 f_vty_ts_action("pdch activate", bts_nr, trx_nr, ts_nr);
2292 /* expect the BSC to issue the related RSL command */
2293 rsl_unused := f_exp_ipa_rx(0, tr_RSL_IPA_PDCH_ACT(chan_nr));
2294 if (istemplatekind(nack, "omit")) {
2295 /* respond with a related acknowledgement */
2296 f_ipa_tx(0, ts_RSL_IPA_PDCH_ACT_ACK(chan_nr, ts_RSL_IE_FrameNumber(2342)));
2297 } else {
2298 f_ipa_tx(0, ts_RSL_IPA_PDCH_ACT_NACK(chan_nr, valueof(nack)));
2299 }
2300}
2301
2302private function f_dyn_ipa_pdch_deact(integer bts_nr, integer trx_nr, integer ts_nr,
2303 template (omit) RSL_Cause nack := omit)
2304runs on test_CT {
2305 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(ts_nr));
2306 var RSL_Message rsl_unused;
2307 /* ask BSC via VTY to activate a given IPA style chan as PDCH */
2308 f_vty_ts_action("pdch deactivate", bts_nr, trx_nr, ts_nr);
2309 /* expect the BSC to issue the related RSL command */
2310 rsl_unused := f_exp_ipa_rx(0, tr_RSL_IPA_PDCH_DEACT(chan_nr));
2311 if (istemplatekind(nack, "omit")) {
2312 /* respond with a related acknowledgement */
2313 f_ipa_tx(0, ts_RSL_IPA_PDCH_DEACT_ACK(chan_nr));
2314 } else {
2315 f_ipa_tx(0, ts_RSL_IPA_PDCH_DEACT_NACK(chan_nr, valueof(nack)));
2316 }
2317}
2318
2319private function f_ts_dyn_mode_get(integer bts_nr, integer trx_nr, integer ts_nr)
2320runs on test_CT return charstring {
2321 var charstring cmd, resp;
2322 cmd := "show timeslot "&int2str(bts_nr)&" "&int2str(trx_nr)&" "&int2str(ts_nr);
2323 resp := f_vty_transceive_ret(BSCVTY, cmd);
2324 return regexp(resp, "*\((*)\)*", 0);
2325}
2326
2327private function f_ts_dyn_mode_assert(integer bts_nr, integer trx_nr, integer ts_nr,
2328 template charstring exp)
2329runs on test_CT {
2330 var charstring mode := f_ts_dyn_mode_get(bts_nr, trx_nr, ts_nr);
2331 if (not match(mode, exp)) {
2332 setverdict(fail, "Unexpected TS Mode: ", mode);
Daniel Willmannafce8662018-07-06 23:11:32 +02002333 mtc.stop;
Harald Welte94e0c342018-04-07 11:33:23 +02002334 }
2335}
2336
2337private function f_ts_set_chcomb(integer bts_nr, integer trx_nr, integer ts_nr, charstring chcomb)
2338runs on test_CT {
2339 f_vty_enter_cfg_ts(BSCVTY, bts_nr, trx_nr, ts_nr);
2340 f_vty_transceive(BSCVTY, "phys_chan_config " & chcomb);
2341 f_vty_transceive(BSCVTY, "end");
2342}
2343
2344private const charstring TCHF_MODE := "TCH/F mode";
2345private const charstring TCHH_MODE := "TCH/H mode";
2346private const charstring PDCH_MODE := "PDCH mode";
2347private const charstring NONE_MODE := "NONE mode";
2348
2349/* Test IPA PDCH activation / deactivation triggered by VTY */
2350testcase TC_dyn_pdch_ipa_act_deact() runs on test_CT {
2351 var RSL_Message rsl_unused;
2352
2353 /* change Timeslot 6 before f_init() starts RSL */
2354 f_init_vty();
2355 f_ts_set_chcomb(0, 0, 6, "TCH/F_PDCH");
2356 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
2357
2358 f_init(1, false);
2359 f_sleep(1.0);
2360
2361 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(6));
2362
2363 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
2364 /* The BSC will activate the dynamic PDCH by default, so confirm that */
2365 rsl_unused := f_exp_ipa_rx(0, tr_RSL_IPA_PDCH_ACT(chan_nr));
2366 f_ipa_tx(0, ts_RSL_IPA_PDCH_ACT_ACK(chan_nr, ts_RSL_IE_FrameNumber(2342)));
2367 f_sleep(1.0);
2368 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, PDCH_MODE);
2369
2370 /* De-activate it via VTY */
2371 f_dyn_ipa_pdch_deact(0, 0, chan_nr.tn);
2372 f_sleep(1.0);
2373 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
2374
2375 /* re-activate it via VTY */
2376 f_dyn_ipa_pdch_act(0, 0, chan_nr.tn);
2377 f_sleep(1.0);
2378 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, PDCH_MODE);
2379
2380 /* and finally de-activate it again */
2381 f_dyn_ipa_pdch_deact(0, 0, chan_nr.tn);
2382 f_sleep(1.0);
2383 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
2384
Neels Hofmeyr887e8f12018-06-27 01:01:55 +02002385 /* clean up config */
2386 f_ts_set_chcomb(0, 0, 6, "PDCH");
2387
Harald Welte94e0c342018-04-07 11:33:23 +02002388 setverdict(pass);
2389}
2390
2391/* Test IPA PDCH activation NACK */
2392testcase TC_dyn_pdch_ipa_act_nack() runs on test_CT {
2393 var RSL_Message rsl_unused;
2394
2395 /* change Timeslot 6 before f_init() starts RSL */
2396 f_init_vty();
2397 f_ts_set_chcomb(0, 0, 6, "TCH/F_PDCH");
2398 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
2399
2400 f_init(1, false);
2401 f_sleep(1.0);
2402
2403 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(6));
2404
2405 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
2406 /* The BSC will activate the dynamic PDCH by default, so confirm that */
2407 rsl_unused := f_exp_ipa_rx(0, tr_RSL_IPA_PDCH_ACT(chan_nr));
2408 f_ipa_tx(0, ts_RSL_IPA_PDCH_ACT_ACK(chan_nr, ts_RSL_IE_FrameNumber(2342)));
2409 f_sleep(1.0);
2410 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, PDCH_MODE);
2411
2412 /* De-activate it via VTY */
2413 f_dyn_ipa_pdch_deact(0, 0, chan_nr.tn);
2414 f_sleep(1.0);
2415 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
2416
2417 /* re-activate it via VTY, but fail that; check BSC still assumes TCH/F mode */
2418 f_dyn_ipa_pdch_act(0, 0, chan_nr.tn, RSL_ERR_EQUIPMENT_FAIL);
2419 f_sleep(1.0);
2420 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
2421
Neels Hofmeyr887e8f12018-06-27 01:01:55 +02002422 /* clean up config */
2423 f_ts_set_chcomb(0, 0, 6, "PDCH");
2424
Harald Welte94e0c342018-04-07 11:33:23 +02002425 setverdict(pass);
2426}
2427
2428
2429/***********************************************************************
2430 * Osmocom style dynamic PDCH
2431 ***********************************************************************/
2432
2433private function f_dyn_osmo_pdch_act(integer bts_nr, integer trx_nr, integer ts_nr,
2434 template (omit) RSL_Cause nack := omit)
2435runs on test_CT {
2436 var RslChannelNr chan_nr := valueof(t_RslChanNr_PDCH(ts_nr));
2437 var RSL_Message rsl_unused;
2438 /* ask BSC via VTY to activate a given IPA style chan as PDCH */
2439 /* FIXME: no VTY command to activate Osmocom PDCH !! */
2440 /* expect the BSC to issue the related RSL command */
2441 rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT(chan_nr, ?));
2442 if (istemplatekind(nack, "omit")) {
2443 /* respond with a related acknowledgement */
2444 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, 2342));
2445 } else {
2446 f_ipa_tx(0, ts_RSL_CHAN_ACT_NACK(chan_nr, valueof(nack)));
2447 }
2448}
2449
2450private function f_dyn_osmo_pdch_deact(integer bts_nr, integer trx_nr, integer ts_nr,
2451 template (omit) RSL_Cause nack := omit)
2452runs on test_CT {
2453 var RslChannelNr chan_nr := valueof(t_RslChanNr_PDCH(ts_nr));
2454 var RSL_Message rsl_unused;
2455 /* ask BSC via VTY to activate a given IPA style chan as PDCH */
2456 /* FIXME: no VTY command to activate Osmocom PDCH !! */
2457 /* expect the BSC to issue the related RSL command */
2458 rsl_unused := f_exp_ipa_rx(0, tr_RSL_RF_CHAN_REL(chan_nr));
2459 if (istemplatekind(nack, "omit")) {
2460 /* respond with a related acknowledgement */
2461 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(chan_nr));
2462 } else {
2463 //f_ipa_tx(0, ts_RSL_RF_CHAN_REL_NACK(chan_nr, valueof(nack)));
2464 }
2465}
2466
2467/* Test Osmocom dyn PDCH activation / deactivation triggered by VTY */
2468testcase TC_dyn_pdch_osmo_act_deact() runs on test_CT {
2469 var RSL_Message rsl_unused;
2470
2471 /* change Timeslot 6 before f_init() starts RSL */
2472 f_init_vty();
2473 f_ts_set_chcomb(0, 0, 6, "TCH/F_TCH/H_PDCH");
2474 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
2475
2476 f_init(1, false);
2477 f_sleep(1.0);
2478
2479 var RslChannelNr chan_nr := valueof(t_RslChanNr_PDCH(6));
2480
2481 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, NONE_MODE);
2482 /* The BSC will activate the dynamic PDCH by default, so confirm that */
2483 rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(chan_nr, ?));
2484
2485 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, 2342));
2486 f_sleep(1.0);
2487 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, PDCH_MODE);
2488
Neels Hofmeyr887e8f12018-06-27 01:01:55 +02002489 /* clean up config */
2490 f_ts_set_chcomb(0, 0, 6, "PDCH");
2491
Harald Welte94e0c342018-04-07 11:33:23 +02002492 setverdict(pass);
2493}
2494
2495/* Test Osmocom dyn PDCH activation NACK behavior */
2496testcase TC_dyn_pdch_osmo_act_nack() runs on test_CT {
2497 var RSL_Message rsl_unused;
2498
2499 /* change Timeslot 6 before f_init() starts RSL */
2500 f_init_vty();
2501 f_ts_set_chcomb(0, 0, 6, "TCH/F_TCH/H_PDCH");
2502 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
2503
2504 f_init(1, false);
2505 f_sleep(1.0);
2506
2507 var RslChannelNr chan_nr := valueof(t_RslChanNr_PDCH(6));
2508
2509 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, NONE_MODE);
2510 /* The BSC will activate the dynamic PDCH by default, so confirm that */
2511 rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(chan_nr, ?));
2512
2513 /* NACK this activation and expect the "show timeslot" mode still to be NONE */
2514 f_ipa_tx(0, ts_RSL_CHAN_ACT_NACK(chan_nr, RSL_ERR_EQUIPMENT_FAIL));
2515 f_sleep(1.0);
2516 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, NONE_MODE);
2517
Neels Hofmeyr887e8f12018-06-27 01:01:55 +02002518 /* clean up config */
2519 f_ts_set_chcomb(0, 0, 6, "PDCH");
2520
Harald Welte94e0c342018-04-07 11:33:23 +02002521 setverdict(pass);
2522}
2523
Harald Welte0ea2d5e2018-04-07 21:40:29 +02002524/* Dyn PDCH todo:
2525 * activate OSMO as TCH/F
2526 * activate OSMO as TCH/H
2527 * does the BSC-located PCU socket get the updated INFO?
2528 * what if no PCU is connected at the time?
2529 * is the info correct on delayed PCU (re)connect?
2530 */
Harald Welte94e0c342018-04-07 11:33:23 +02002531
Harald Welte28d943e2017-11-25 15:00:50 +01002532control {
Harald Welte898113b2018-01-31 18:32:21 +01002533 /* CTRL interface testing */
Harald Welte4003d112017-12-09 22:35:39 +01002534 execute( TC_ctrl_msc_connection_status() );
Stefan Sperlingb041b3d2018-01-03 17:14:55 +01002535 execute( TC_ctrl_msc0_connection_status() );
Harald Welte96c94412017-12-09 03:12:45 +01002536 execute( TC_ctrl() );
Harald Welte898113b2018-01-31 18:32:21 +01002537
2538 /* RSL DCHAN Channel ACtivation / Deactivation */
Harald Welteae026692017-12-09 01:03:01 +01002539 execute( TC_chan_act_noreply() );
Harald Welte4003d112017-12-09 22:35:39 +01002540 execute( TC_chan_act_counter() );
Harald Welteae026692017-12-09 01:03:01 +01002541 execute( TC_chan_act_ack_noest() );
2542 execute( TC_chan_act_ack_est_ind_noreply() );
2543 execute( TC_chan_act_ack_est_ind_refused() );
Harald Welte618ef642017-12-14 14:58:20 +01002544 execute( TC_chan_act_nack() );
Harald Welte799c97b2017-12-14 17:50:30 +01002545 execute( TC_chan_exhaustion() );
Harald Welte4003d112017-12-09 22:35:39 +01002546 execute( TC_chan_rel_rll_rel_ind() );
2547 execute( TC_chan_rel_conn_fail() );
2548 execute( TC_chan_rel_hard_clear() );
Harald Welted8c36cd2017-12-09 23:05:31 +01002549 execute( TC_chan_rel_hard_rlsd() );
Harald Welte550daf92018-06-11 19:22:13 +02002550 execute( TC_chan_rel_hard_rlsd_ms_dead() );
Harald Welte85804d42017-12-10 14:11:58 +01002551 execute( TC_chan_rel_a_reset() );
Harald Welte6f521d82017-12-11 19:52:02 +01002552
Harald Weltecfe2c962017-12-15 12:09:32 +01002553 execute( TC_outbound_connect() );
Harald Welte898113b2018-01-31 18:32:21 +01002554
2555 /* Assignment related */
Harald Welte16a4adf2017-12-14 18:54:01 +01002556 execute( TC_assignment_cic_only() );
Harald Welte235ebf12017-12-15 14:18:16 +01002557 execute( TC_assignment_csd() );
2558 execute( TC_assignment_ctm() );
2559 execute( TC_assignment_sign() );
2560 execute( TC_assignment_fr_a5_0() );
2561 execute( TC_assignment_fr_a5_1() );
Harald Welte8f67d1d2018-05-25 20:38:42 +02002562 if (mp_bssap_cfg.transport == BSSAP_TRANSPORT_AoIP) {
2563 execute( TC_assignment_fr_a5_1_codec_missing() );
2564 }
Harald Welte235ebf12017-12-15 14:18:16 +01002565 execute( TC_assignment_fr_a5_3() );
2566 execute( TC_assignment_fr_a5_4() );
Harald Welte3c86ea02018-05-10 22:28:05 +02002567 execute( TC_ciph_mode_a5_0() );
2568 execute( TC_ciph_mode_a5_1() );
2569 execute( TC_ciph_mode_a5_3() );
Harald Welte16a4adf2017-12-14 18:54:01 +01002570
Harald Welte60aa5762018-03-21 19:33:13 +01002571 execute( TC_assignment_codec_fr() );
2572 execute( TC_assignment_codec_hr() );
2573 execute( TC_assignment_codec_efr() );
2574 execute( TC_assignment_codec_amr_f() );
2575 execute( TC_assignment_codec_amr_h() );
2576
Harald Welte898113b2018-01-31 18:32:21 +01002577 /* RLL Establish Indication on inactive DCHAN / SAPI */
Harald Welte5cd20ed2017-12-13 21:03:20 +01002578 execute( TC_rll_est_ind_inact_lchan() );
2579 execute( TC_rll_est_ind_inval_sapi1() );
2580 execute( TC_rll_est_ind_inval_sapi3() );
2581 execute( TC_rll_est_ind_inval_sacch() );
2582
Harald Welte898113b2018-01-31 18:32:21 +01002583 /* Paging related tests */
Harald Welte6f521d82017-12-11 19:52:02 +01002584 execute( TC_paging_imsi_nochan() );
2585 execute( TC_paging_tmsi_nochan() );
2586 execute( TC_paging_tmsi_any() );
2587 execute( TC_paging_tmsi_sdcch() );
2588 execute( TC_paging_tmsi_tch_f() );
2589 execute( TC_paging_tmsi_tch_hf() );
2590 execute( TC_paging_imsi_nochan_cgi() );
2591 execute( TC_paging_imsi_nochan_lac_ci() );
2592 execute( TC_paging_imsi_nochan_ci() );
2593 execute( TC_paging_imsi_nochan_lai() );
2594 execute( TC_paging_imsi_nochan_lac() );
2595 execute( TC_paging_imsi_nochan_all() );
Harald Welte751d3eb2018-01-31 15:51:06 +01002596 execute( TC_paging_imsi_nochan_plmn_lac_rnc() );
2597 execute( TC_paging_imsi_nochan_rnc() );
2598 execute( TC_paging_imsi_nochan_lac_rnc() );
2599 execute( TC_paging_imsi_nochan_lacs() );
2600 execute( TC_paging_imsi_nochan_lacs_empty() );
Stefan Sperling049a86e2018-03-20 15:51:00 +01002601 execute( TC_paging_imsi_nochan_cgi_unknown_cid() );
Harald Welte10985002017-12-12 09:29:15 +01002602 execute( TC_paging_imsi_a_reset() );
Harald Weltee65d40e2017-12-13 00:09:06 +01002603 execute( TC_paging_imsi_load() );
Philipp Maier779a7922018-02-16 11:00:37 +01002604 execute( TC_paging_counter() );
Harald Welte4e9b9cc2017-12-14 18:31:02 +01002605
2606 execute( TC_rsl_drop_counter() );
Stefan Sperling830dc9d2018-02-12 21:08:28 +01002607 execute( TC_rsl_unknown_unit_id() );
2608
2609 execute( TC_oml_unknown_unit_id() );
Harald Welte898113b2018-01-31 18:32:21 +01002610
2611 execute( TC_classmark() );
2612 execute( TC_unsol_ass_fail() );
Harald Welteea99a002018-01-31 20:46:43 +01002613 execute( TC_unsol_ass_compl() );
Harald Weltefbf9b5e2018-01-31 20:41:23 +01002614 execute( TC_unsol_ho_fail() );
Harald Weltee3bd6582018-01-31 22:51:25 +01002615 execute( TC_err_82_short_msg() );
Harald Weltee9e02e42018-01-31 23:36:25 +01002616 execute( TC_err_84_unknown_msg() );
Harald Welte261af4b2018-02-12 21:20:39 +01002617 execute( TC_ho_int() );
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +01002618
2619 execute( TC_bssap_rlsd_does_not_cause_bssmap_reset() );
Neels Hofmeyr4ff93282018-03-12 04:25:35 +01002620 execute( TC_bssmap_clear_does_not_cause_bssmap_reset() );
Neels Hofmeyrfd445c32018-03-09 15:39:31 +01002621 execute( TC_ms_rel_ind_does_not_cause_bssmap_reset() );
Harald Welte94e0c342018-04-07 11:33:23 +02002622
2623 execute( TC_dyn_pdch_ipa_act_deact() );
2624 execute( TC_dyn_pdch_ipa_act_nack() );
2625 execute( TC_dyn_pdch_osmo_act_deact() );
2626 execute( TC_dyn_pdch_osmo_act_nack() );
Harald Welte99f3ca02018-06-14 13:40:29 +02002627
2628 /* at bottom as they might crash OsmoBSC before OS#3182 is fixed */
2629 execute( TC_early_conn_fail() );
2630 execute( TC_late_conn_fail() );
2631
Harald Welte28d943e2017-11-25 15:00:50 +01002632}
2633
2634}