blob: c802a6b2d880184fd7b12843c786deb6d56c07db [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
Stefan Sperlingc307e682018-06-14 15:15:46 +020049import from SCCP_Templates all;
Neels Hofmeyr4ff93282018-03-12 04:25:35 +010050import from BSSMAP_Templates all;
51
Harald Welte5d1a2202017-12-13 19:51:29 +010052const integer NUM_BTS := 3;
Harald Welteae026692017-12-09 01:03:01 +010053const float T3101_MAX := 12.0;
Harald Welte28d943e2017-11-25 15:00:50 +010054
Harald Welte799c97b2017-12-14 17:50:30 +010055/* make sure to sync this with the osmo-bts.cfg you're using */
Philipp Maiercb6cc482018-03-26 13:08:00 +020056const integer NUM_TCHH_PER_BTS := 2;
57const integer NUM_TCHF_PER_BTS := 4;
Harald Weltedd8cbf32018-01-28 12:07:52 +010058const integer NUM_SDCCH_PER_BTS := 4;
Harald Welte799c97b2017-12-14 17:50:30 +010059
Harald Welte4003d112017-12-09 22:35:39 +010060
Harald Welte21b46bd2017-12-17 19:46:32 +010061/* per-BTS state which we keep */
Harald Welte96c94412017-12-09 03:12:45 +010062type record BTS_State {
Harald Welte21b46bd2017-12-17 19:46:32 +010063 /* component reference to the IPA_Client component used for RSL */
Harald Weltea5d2ab22017-12-09 14:21:42 +010064 IPA_Client rsl
Harald Welte96c94412017-12-09 03:12:45 +010065}
66
Harald Weltea4ca4462018-02-09 00:17:14 +010067type component test_CT extends CTRL_Adapter_CT {
Harald Welte21b46bd2017-12-17 19:46:32 +010068 /* Array of per-BTS state */
Harald Welte96c94412017-12-09 03:12:45 +010069 var BTS_State bts[NUM_BTS];
Harald Welte89ab1912018-02-23 18:56:29 +010070 /* RSL common Channel Port (for RSL_Emulation) */
71 port RSL_CCHAN_PT RSL_CCHAN[NUM_BTS];
Harald Welte21b46bd2017-12-17 19:46:32 +010072 /* array of per-BTS RSL test ports */
Harald Welteae026692017-12-09 01:03:01 +010073 port IPA_RSL_PT IPA_RSL[NUM_BTS];
Stefan Sperling830dc9d2018-02-12 21:08:28 +010074 port IPA_CODEC_PT IPA; /* Required for compilation of TC_rsl_unknown_unit_id() */
Harald Weltea5d2ab22017-12-09 14:21:42 +010075
Daniel Willmann191e0d92018-01-17 12:44:35 +010076 var MGCP_Emulation_CT vc_MGCP;
Harald Weltebc03c762018-02-12 18:09:38 +010077 port TELNETasp_PT BSCVTY;
Daniel Willmann191e0d92018-01-17 12:44:35 +010078
Harald Weltea4ca4462018-02-09 00:17:14 +010079 var BSSAP_Adapter g_bssap;
80 /* for old legacy-tests only */
81 port BSSAP_CODEC_PT BSSAP;
82
Harald Welte21b46bd2017-12-17 19:46:32 +010083 /* are we initialized yet */
Harald Welte28d943e2017-11-25 15:00:50 +010084 var boolean g_initialized := false;
Harald Welte21b46bd2017-12-17 19:46:32 +010085
86 /* global test case guard timer */
Harald Welteae026692017-12-09 01:03:01 +010087 timer T_guard := 30.0;
88
Harald Welte28d943e2017-11-25 15:00:50 +010089}
90
91modulepar {
Harald Welte21b46bd2017-12-17 19:46:32 +010092 /* IP address at which the BSC can be reached */
Harald Welte696ddb62017-12-08 14:01:43 +010093 charstring mp_bsc_ip := "127.0.0.1";
Stefan Sperling830dc9d2018-02-12 21:08:28 +010094 /* port number to which to establish the IPA OML connections */
95 integer mp_bsc_oml_port := 3002;
Harald Welte21b46bd2017-12-17 19:46:32 +010096 /* port number to which to establish the IPA RSL connections */
Harald Welte696ddb62017-12-08 14:01:43 +010097 integer mp_bsc_rsl_port := 3003;
Harald Welte21b46bd2017-12-17 19:46:32 +010098 /* port number to which to establish the IPA CTRL connection */
Harald Welte96c94412017-12-09 03:12:45 +010099 integer mp_bsc_ctrl_port := 4249;
Daniel Willmann191e0d92018-01-17 12:44:35 +0100100 /* IP address at which the test binds */
101 charstring mp_test_ip := "127.0.0.1";
Harald Weltea4ca4462018-02-09 00:17:14 +0100102
103 BSSAP_Configuration mp_bssap_cfg := {
Harald Welte7ef51aa2018-04-16 19:16:01 +0200104 transport := BSSAP_TRANSPORT_AoIP,
Harald Weltea4ca4462018-02-09 00:17:14 +0100105 sccp_service_type := "mtp3_itu",
106 sctp_addr := { 23905, "127.0.0.1", 2905, "127.0.0.1" },
107 own_pc := 185,
108 own_ssn := 254,
109 peer_pc := 187,
110 peer_ssn := 254,
Philipp Maier38d68942018-03-29 15:38:09 +0200111 sio := '83'O,
112 rctx := 0
Harald Weltea4ca4462018-02-09 00:17:14 +0100113 };
114}
115
Philipp Maier282ca4b2018-02-27 17:17:00 +0100116private function f_shutdown_helper() runs on test_CT {
Daniel Willmann637ef6c2018-07-25 10:49:09 +0200117 all component.stop;
Philipp Maier282ca4b2018-02-27 17:17:00 +0100118 setverdict(pass);
Daniel Willmannafce8662018-07-06 23:11:32 +0200119 mtc.stop;
Philipp Maier282ca4b2018-02-27 17:17:00 +0100120}
121
Harald Weltea4ca4462018-02-09 00:17:14 +0100122private function f_legacy_bssap_reset() runs on test_CT {
123 var BSSAP_N_UNITDATA_ind ud_ind;
124 timer T := 5.0;
125 BSSAP.send(ts_BSSAP_UNITDATA_req(g_bssap.sccp_addr_peer, g_bssap.sccp_addr_own, ts_BSSMAP_Reset(0)));
126 T.start;
127 alt {
128 [] BSSAP.receive(tr_BSSAP_UNITDATA_ind(g_bssap.sccp_addr_own, g_bssap.sccp_addr_peer, tr_BSSMAP_ResetAck)) {
129 log("Received RESET-ACK in response to RESET, we're ready to go!");
130 }
131 [] BSSAP.receive(tr_BSSAP_UNITDATA_ind(?, ?, tr_BSSMAP_Reset)) -> value ud_ind {
132 log("Respoding to inbound RESET with RESET-ACK");
133 BSSAP.send(ts_BSSAP_UNITDATA_req(ud_ind.callingAddress, ud_ind.calledAddress,
134 ts_BSSMAP_ResetAck));
135 repeat;
136 }
137 [] BSSAP.receive { repeat; }
138 [] T.timeout { setverdict(fail, "Waiting for RESET-ACK after sending RESET"); }
139 }
Harald Welte28d943e2017-11-25 15:00:50 +0100140}
141
Harald Welteae026692017-12-09 01:03:01 +0100142type record IPA_Client {
Harald Welte21b46bd2017-12-17 19:46:32 +0100143 /* IPA Emulation component reference */
Harald Welteae026692017-12-09 01:03:01 +0100144 IPA_Emulation_CT vc_IPA,
Harald Welte21b46bd2017-12-17 19:46:32 +0100145 /* Unit-ID and other CCM parameters to use for IPA client emulation */
Harald Welteae026692017-12-09 01:03:01 +0100146 IPA_CCM_Parameters ccm_pars,
Harald Welte21b46bd2017-12-17 19:46:32 +0100147 /* String identifier for this IPA Client */
Harald Welte624f9632017-12-16 19:26:04 +0100148 charstring id,
Harald Welte21b46bd2017-12-17 19:46:32 +0100149 /* Associated RSL Emulation Component (if any). Only used in "Handler mode" */
Harald Welte624f9632017-12-16 19:26:04 +0100150 RSL_Emulation_CT vc_RSL optional
Harald Welte28d943e2017-11-25 15:00:50 +0100151}
152
Harald Welte21b46bd2017-12-17 19:46:32 +0100153/*! Start the IPA/RSL related bits for one IPA_Client.
154 * \param clnt IPA_Client for which to establish
155 * \param bsc_host IP address / hostname of the BSC
156 * \param bsc_port TCP port number of the BSC
157 * \param i number identifying this BTS
158 * \param handler_mode Start an RSL_Emulation_CT component (true) or not (false) */
Harald Welte624f9632017-12-16 19:26:04 +0100159function f_ipa_rsl_start(inout IPA_Client clnt, charstring bsc_host, PortNumber bsc_port, integer i,
160 boolean handler_mode := false)
Harald Welte28d943e2017-11-25 15:00:50 +0100161runs on test_CT {
Harald Welteae026692017-12-09 01:03:01 +0100162 timer T := 10.0;
163
Harald Welte96c94412017-12-09 03:12:45 +0100164 clnt.id := "IPA" & int2str(i) & "-RSL";
Harald Welteae026692017-12-09 01:03:01 +0100165 clnt.vc_IPA := IPA_Emulation_CT.create(clnt.id & "-IPA");
166 clnt.ccm_pars := c_IPA_default_ccm_pars;
167 clnt.ccm_pars.name := "Osmocom TTCN-3 BTS Simulator";
168 clnt.ccm_pars.unit_id := int2str(1234+i) & "/0/0";
Harald Welte624f9632017-12-16 19:26:04 +0100169 if (handler_mode) {
170 clnt.vc_RSL := RSL_Emulation_CT.create(clnt.id & "-RSL");
Harald Welte89ab1912018-02-23 18:56:29 +0100171 connect(clnt.vc_RSL:CCHAN_PT, self:RSL_CCHAN[i]);
Harald Welte624f9632017-12-16 19:26:04 +0100172 }
Harald Welteae026692017-12-09 01:03:01 +0100173
174 map(clnt.vc_IPA:IPA_PORT, system:IPA_CODEC_PT);
Harald Welte624f9632017-12-16 19:26:04 +0100175 if (handler_mode) {
176 connect(clnt.vc_IPA:IPA_RSL_PORT, clnt.vc_RSL:IPA_PT);
177 } else {
178 connect(clnt.vc_IPA:IPA_RSL_PORT, self:IPA_RSL[i]);
179 }
Harald Welteae026692017-12-09 01:03:01 +0100180
Harald Welte5d1a2202017-12-13 19:51:29 +0100181 clnt.vc_IPA.start(IPA_Emulation.main_client(bsc_host, bsc_port, "", 10000+i, clnt.ccm_pars));
Harald Welte624f9632017-12-16 19:26:04 +0100182 if (handler_mode) {
183 clnt.vc_RSL.start(RSL_Emulation.main());
184 return;
185 }
Harald Welteae026692017-12-09 01:03:01 +0100186
187 /* wait for IPA RSL link to connect and send ID ACK */
188 T.start;
189 alt {
190 [] IPA_RSL[i].receive(ASP_IPA_Event:{up_down := ASP_IPA_EVENT_ID_ACK}) {
191 T.stop;
192 IPA_RSL[i].send(ts_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0,ts_RSL_PAGING_LOAD_IND(23)));
193 }
Harald Welte60e823a2017-12-10 14:10:59 +0100194 [] IPA_RSL[i].receive(ASP_IPA_Event:?) { repeat }
Harald Welteae026692017-12-09 01:03:01 +0100195 [] IPA_RSL[i].receive { repeat }
196 [] T.timeout {
Harald Welte96c94412017-12-09 03:12:45 +0100197 setverdict(fail, "Timeout RSL waiting for ASP_IPA_EVENT_ID_ACK");
Daniel Willmannafce8662018-07-06 23:11:32 +0200198 mtc.stop;
Harald Welteae026692017-12-09 01:03:01 +0100199 }
200 }
201}
202
Harald Welte12055472018-03-17 20:10:08 +0100203function f_ipa_rsl_stop(inout IPA_Client clnt) runs on test_CT {
204 if (not isbound(clnt) or not isbound(clnt.vc_IPA)) {
205 return;
206 }
207 clnt.vc_IPA.stop;
208 if (isbound(clnt.vc_RSL)) {
209 clnt.vc_RSL.stop;
210 }
211}
212
Harald Welte21b46bd2017-12-17 19:46:32 +0100213/* Wait for the OML connection to be brought up by the external osmo-bts-omldummy */
Harald Weltea5d2ab22017-12-09 14:21:42 +0100214function f_wait_oml(integer bts_nr, charstring status, float secs_max) runs on test_CT {
215 timer T := secs_max;
216 T.start;
217 while (true) {
218 if (f_ctrl_get_bts(IPA_CTRL, bts_nr, "oml-connection-state") == status) {
219 T.stop;
Harald Weltebd868bd2017-12-10 18:28:40 +0100220 /* the 'degraded' state exists from OML connection time, and we have to wait
221 * until all MO's are initialized */
222 T.start(1.0);
223 T.timeout;
Harald Weltea5d2ab22017-12-09 14:21:42 +0100224 return;
225 }
Harald Weltef0d6ac62017-12-17 17:02:21 +0100226 f_sleep(0.1);
Harald Weltea5d2ab22017-12-09 14:21:42 +0100227 if (not T.running) {
228 setverdict(fail, "Timeout waiting for oml-connection-state ", status);
Daniel Willmannafce8662018-07-06 23:11:32 +0200229 mtc.stop;
Harald Weltea5d2ab22017-12-09 14:21:42 +0100230 }
231 }
232}
233
Harald Welte21b46bd2017-12-17 19:46:32 +0100234/* global altstep for global guard timer; also takes care of responding RESET witH RESET-ACK */
Harald Welteae026692017-12-09 01:03:01 +0100235altstep as_Tguard() runs on test_CT {
Harald Welte60e823a2017-12-10 14:10:59 +0100236 var BSSAP_N_UNITDATA_ind ud_ind;
Neels Hofmeyrcc3f76a2018-03-12 01:43:25 +0100237 [] T_guard.timeout {
238 setverdict(fail, "Timeout of T_guard");
Daniel Willmannafce8662018-07-06 23:11:32 +0200239 mtc.stop;
Neels Hofmeyrcc3f76a2018-03-12 01:43:25 +0100240 }
Harald Welte60e823a2017-12-10 14:10:59 +0100241 /* always respond with RESET ACK to RESET */
242 [] BSSAP.receive(tr_BSSAP_UNITDATA_ind(?, ?, tr_BSSMAP_Reset)) -> value ud_ind {
243 BSSAP.send(ts_BSSAP_UNITDATA_req(ud_ind.callingAddress, ud_ind.calledAddress,
244 ts_BSSMAP_ResetAck));
Harald Welte69c1c262017-12-13 21:02:08 +0100245 repeat;
Harald Welte60e823a2017-12-10 14:10:59 +0100246 }
Harald Welte28d943e2017-11-25 15:00:50 +0100247}
248
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +0100249altstep no_bssmap_reset() runs on test_CT {
250 [] BSSAP.receive(tr_BSSAP_UNITDATA_ind(?, ?, tr_BSSMAP_Reset)) {
251 setverdict(fail, "unexpected BSSMAP Reset");
Daniel Willmannafce8662018-07-06 23:11:32 +0200252 mtc.stop;
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +0100253 }
254}
255
Daniel Willmann191e0d92018-01-17 12:44:35 +0100256function f_init_mgcp(charstring id) runs on test_CT {
257 id := id & "-MGCP";
258
259 var MGCPOps ops := {
260 create_cb := refers(MGCP_Emulation.ExpectedCreateCallback),
261 unitdata_cb := refers(MGCP_Emulation.DummyUnitdataCallback)
262 };
263 var MGCP_conn_parameters mgcp_pars := {
264 callagent_ip := mp_bsc_ip,
Harald Welte9e4273e2018-01-29 22:01:22 +0100265 callagent_udp_port := -1,
Daniel Willmann191e0d92018-01-17 12:44:35 +0100266 mgw_ip := mp_test_ip,
267 mgw_udp_port := 2427
268 };
269
270 vc_MGCP := MGCP_Emulation_CT.create(id);
271 vc_MGCP.start(MGCP_Emulation.main(ops, mgcp_pars, id));
272}
273
Harald Welte94e0c342018-04-07 11:33:23 +0200274private function f_init_vty(charstring id := "foo") runs on test_CT {
275 if (BSCVTY.checkstate("Mapped")) {
276 /* skip initialization if already executed once */
277 return;
278 }
Harald Weltebc03c762018-02-12 18:09:38 +0100279 map(self:BSCVTY, system:BSCVTY);
280 f_vty_set_prompts(BSCVTY);
281 f_vty_transceive(BSCVTY, "enable");
282}
283
Harald Welte21b46bd2017-12-17 19:46:32 +0100284/* global initialization function
285 * \param nr_bts Number of BTSs we should start/bring up
286 * \param handler_mode Start an RSL_Emulation_CT component (true) or not (false) */
Harald Welte89d42e82017-12-17 16:42:41 +0100287function f_init(integer nr_bts := NUM_BTS, boolean handler_mode := false) runs on test_CT {
Harald Welte28d943e2017-11-25 15:00:50 +0100288 var integer i;
Harald Welte28d943e2017-11-25 15:00:50 +0100289
Harald Welteae026692017-12-09 01:03:01 +0100290 if (g_initialized) {
291 return;
Harald Welte28d943e2017-11-25 15:00:50 +0100292 }
Harald Welteae026692017-12-09 01:03:01 +0100293 g_initialized := true;
294
295 /* Call a function of our 'parent component' BSSAP_Adapter_CT to start the
296 * MSC-side BSSAP emulation */
Harald Welte67089ee2018-01-17 22:19:03 +0100297 if (handler_mode) {
Harald Weltea4ca4462018-02-09 00:17:14 +0100298 f_bssap_init(g_bssap, mp_bssap_cfg, "VirtMSC", MSC_BssmapOps);
Harald Welte4bcbd172018-05-27 19:47:44 +0200299 f_bssap_start(g_bssap);
Harald Welte67089ee2018-01-17 22:19:03 +0100300 } else {
Harald Weltea4ca4462018-02-09 00:17:14 +0100301 f_bssap_init(g_bssap, mp_bssap_cfg, "VirtMSC", omit);
302 connect(self:BSSAP, g_bssap.vc_SCCP:SCCP_SP_PORT);
Harald Welte4bcbd172018-05-27 19:47:44 +0200303 f_bssap_start(g_bssap);
Harald Weltea4ca4462018-02-09 00:17:14 +0100304 f_legacy_bssap_reset();
Harald Welte67089ee2018-01-17 22:19:03 +0100305 }
Harald Welted5833a82018-05-27 16:52:56 +0200306
Harald Welteffe55fc2018-01-17 22:39:54 +0100307 f_ipa_ctrl_start(mp_bsc_ip, mp_bsc_ctrl_port);
Harald Welte28d943e2017-11-25 15:00:50 +0100308
Daniel Willmann191e0d92018-01-17 12:44:35 +0100309 f_init_mgcp("VirtMSC");
Harald Weltebc03c762018-02-12 18:09:38 +0100310 f_init_vty("VirtMSC");
Daniel Willmann191e0d92018-01-17 12:44:35 +0100311
Harald Welte89d42e82017-12-17 16:42:41 +0100312 for (i := 0; i < nr_bts; i := i+1) {
Harald Weltea5d2ab22017-12-09 14:21:42 +0100313 /* wait until osmo-bts-omldummy has respawned */
314 f_wait_oml(i, "degraded", 5.0);
315 /* start RSL connection */
Harald Welte624f9632017-12-16 19:26:04 +0100316 f_ipa_rsl_start(bts[i].rsl, mp_bsc_ip, mp_bsc_rsl_port, i, handler_mode);
Harald Weltea5d2ab22017-12-09 14:21:42 +0100317 /* wait until BSC tells us "connected" */
318 f_wait_oml(i, "connected", 5.0);
Harald Welte696ddb62017-12-08 14:01:43 +0100319 }
320
Harald Welteae026692017-12-09 01:03:01 +0100321 T_guard.start;
322 activate(as_Tguard());
Harald Welte28d943e2017-11-25 15:00:50 +0100323}
324
Harald Welte21b46bd2017-12-17 19:46:32 +0100325/* expect to receive a RSL message matching a specified templaten on a given BTS / stream */
Harald Welteae026692017-12-09 01:03:01 +0100326function f_exp_ipa_rx(integer bts_nr, template RSL_Message t_rx, float t_secs := 2.0, IpaStreamId sid := IPAC_PROTO_RSL_TRX0)
327runs on test_CT return RSL_Message {
328 var ASP_RSL_Unitdata rx_rsl_ud;
329 timer T := t_secs;
330
331 T.start;
332 alt {
333 [] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(sid, t_rx)) -> value rx_rsl_ud {
334 T.stop;
335 }
336 [] IPA_RSL[bts_nr].receive { repeat; }
Harald Welteb2917702017-12-10 15:48:52 +0100337 [] T.timeout {
338 setverdict(fail, "Timeout expecting ", t_rx);
Daniel Willmannafce8662018-07-06 23:11:32 +0200339 mtc.stop;
Harald Welteb2917702017-12-10 15:48:52 +0100340 }
Harald Welteae026692017-12-09 01:03:01 +0100341 }
342 return rx_rsl_ud.rsl;
343}
344
Harald Welte21b46bd2017-12-17 19:46:32 +0100345/* helper function to transmit RSL on a given BTS/stream */
Harald Welteae026692017-12-09 01:03:01 +0100346function f_ipa_tx(integer bts_nr, template RSL_Message t_tx, IpaStreamId sid := IPAC_PROTO_RSL_TRX0)
347runs on test_CT {
348 IPA_RSL[bts_nr].send(ts_ASP_RSL_UD(sid, t_tx));
349}
350
351
Harald Welte4003d112017-12-09 22:35:39 +0100352/* verify we get a CHAN_ACT after CHAN RQD */
Harald Welteae026692017-12-09 01:03:01 +0100353testcase TC_chan_act_noreply() runs on test_CT {
354 var BSSAP_N_UNITDATA_ind ud_ind;
Harald Welte930d0a72018-03-22 22:08:40 +0100355 var RSL_Message rsl_unused;
Harald Welte28d943e2017-11-25 15:00:50 +0100356
Harald Welte89d42e82017-12-17 16:42:41 +0100357 f_init(1);
Harald Welte28d943e2017-11-25 15:00:50 +0100358
Harald Welteae026692017-12-09 01:03:01 +0100359 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 +0100360 rsl_unused := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
Harald Welteae026692017-12-09 01:03:01 +0100361 setverdict(pass);
Harald Welte28d943e2017-11-25 15:00:50 +0100362}
363
Harald Welte4003d112017-12-09 22:35:39 +0100364/* verify if the "chreq:total" counter increments as expected */
365testcase TC_chan_act_counter() runs on test_CT {
366 var BSSAP_N_UNITDATA_ind ud_ind;
367 var integer chreq_total;
Harald Welte930d0a72018-03-22 22:08:40 +0100368 var RSL_Message rsl_unused;
Harald Welte4003d112017-12-09 22:35:39 +0100369
Harald Welte89d42e82017-12-17 16:42:41 +0100370 f_init(1);
Harald Welte4003d112017-12-09 22:35:39 +0100371
372 chreq_total := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:total");
373 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 +0100374 rsl_unused := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
Harald Welte4003d112017-12-09 22:35:39 +0100375 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:total", chreq_total+1);
376
377 setverdict(pass);
378}
379
Harald Welteae026692017-12-09 01:03:01 +0100380/* CHAN RQD -> CHAN ACT -> CHAN ACT ACK -> RF CHAN REL */
381testcase TC_chan_act_ack_noest() runs on test_CT {
382 var RSL_Message rx_rsl;
383
Harald Welte89d42e82017-12-17 16:42:41 +0100384 f_init(1);
Harald Welteae026692017-12-09 01:03:01 +0100385
386 /* Send CHAN RQD and wait for allocation; acknowledge it */
Harald Welted6939652017-12-13 21:02:46 +0100387 var RslChannelNr chan_nr := f_chreq_act_ack();
Harald Welteae026692017-12-09 01:03:01 +0100388
389 /* expect BSC to disable the channel again if there's no RLL EST IND */
390 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL), T3101_MAX);
391
392 setverdict(pass);
393}
394
395/* Test behavior if MSC never answers to CR */
396testcase TC_chan_act_ack_est_ind_noreply() runs on test_CT {
Harald Weltef77aef62018-01-28 15:35:42 +0100397 var RslLinkId main_dcch := valueof(ts_RslLinkID_DCCH(0));
398 var IpaStreamId sid := IPAC_PROTO_RSL_TRX0;
Harald Welteae026692017-12-09 01:03:01 +0100399 var RSL_Message rx_rsl;
Harald Weltef77aef62018-01-28 15:35:42 +0100400 var ASP_RSL_Unitdata rx_rsl_ud;
Harald Welteae026692017-12-09 01:03:01 +0100401
Harald Welte89d42e82017-12-17 16:42:41 +0100402 f_init(1);
Harald Welteae026692017-12-09 01:03:01 +0100403
404 /* Send CHAN RQD and wait for allocation; acknowledge it */
Harald Welted6939652017-12-13 21:02:46 +0100405 var RslChannelNr chan_nr := f_chreq_act_ack();
Harald Welteae026692017-12-09 01:03:01 +0100406
407 var octetstring l3 := '00010203040506'O
408 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
409
410 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3)));
411
412 /* expect BSC to disable the channel again if there's no response from MSC */
Harald Weltef77aef62018-01-28 15:35:42 +0100413 /* MS waits 20s (T3210) at LU; 10s (T3230) at CM SERV REQ and 5s (T3220) AT detach */
414 IPA_RSL[0].clear;
415 alt {
416 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(sid, tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL))) -> value rx_rsl_ud { }
417 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(sid, tr_RSL_REL_REQ(chan_nr, ?))) -> value rx_rsl_ud {
418 f_ipa_tx(0, ts_RSL_REL_CONF(chan_nr, main_dcch));
419 repeat;
420 }
421 }
Harald Welteae026692017-12-09 01:03:01 +0100422
423 setverdict(pass);
424}
425
426/* Test behavior if MSC answers with CREF to CR */
427testcase TC_chan_act_ack_est_ind_refused() runs on test_CT {
428 var BSSAP_N_CONNECT_ind rx_c_ind;
429 var RSL_Message rx_rsl;
430
Harald Welte89d42e82017-12-17 16:42:41 +0100431 f_init(1);
Harald Welteae026692017-12-09 01:03:01 +0100432
433 /* Send CHAN RQD and wait for allocation; acknowledge it */
Harald Welted6939652017-12-13 21:02:46 +0100434 var RslChannelNr chan_nr := f_chreq_act_ack();
Harald Welteae026692017-12-09 01:03:01 +0100435
436 var octetstring l3 := '00010203040506'O
437 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
438
439 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) -> value rx_c_ind;
440 BSSAP.send(ts_BSSAP_DISC_req(rx_c_ind.connectionId, 0));
441
442 /* expect BSC to disable the channel */
Harald Welte725844b2018-01-28 16:18:32 +0100443 f_expect_chan_rel(0, chan_nr);
Harald Welteae026692017-12-09 01:03:01 +0100444 setverdict(pass);
445}
446
Harald Welte618ef642017-12-14 14:58:20 +0100447/* CHAN RQD -> CHAN ACT -> CHAN ACT NACK -> RF CHAN REL */
448testcase TC_chan_act_nack() runs on test_CT {
449 var RSL_Message rx_rsl;
450 var integer chact_nack;
451
Harald Welte89d42e82017-12-17 16:42:41 +0100452 f_init(1);
Harald Welte618ef642017-12-14 14:58:20 +0100453
454 chact_nack := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "chan_act:nack");
455
456 f_ipa_tx(0, ts_RSL_CHAN_RQD('33'O, 33));
457 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
458 var RslChannelNr chan_nr := rx_rsl.ies[0].body.chan_nr;
459
460 f_ipa_tx(0, ts_RSL_CHAN_ACT_NACK(chan_nr, RSL_ERR_EQUIPMENT_FAIL));
461
462 /* wait for some time to hope the NACK arrives before the CTRL GET below */
463 f_sleep(0.5);
464
465 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "chan_act:nack", chact_nack+1);
466
467 setverdict(pass);
468}
469
Harald Welte799c97b2017-12-14 17:50:30 +0100470/* Test for channel exhaustion due to RACH overload */
471testcase TC_chan_exhaustion() runs on test_CT {
472 var ASP_RSL_Unitdata rsl_ud;
473 var integer i;
474 var integer chreq_total, chreq_nochan;
475
Harald Welte89d42e82017-12-17 16:42:41 +0100476 f_init(1);
Harald Welte799c97b2017-12-14 17:50:30 +0100477
478 chreq_total := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:total");
479 chreq_nochan := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:no_channel");
480
481 /* expect 5xTCH/F to succeed */
Philipp Maiercb6cc482018-03-26 13:08:00 +0200482 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 +0100483 var RslChannelNr chan_nr := f_chreq_act_ack('23'O, i);
Harald Welte799c97b2017-12-14 17:50:30 +0100484 }
485
486 IPA_RSL[0].clear;
487
Harald Weltedd8cbf32018-01-28 12:07:52 +0100488 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:total",
Philipp Maiercb6cc482018-03-26 13:08:00 +0200489 chreq_total + NUM_TCHF_PER_BTS + NUM_TCHH_PER_BTS + NUM_SDCCH_PER_BTS);
Harald Welte799c97b2017-12-14 17:50:30 +0100490
491 /* now expect additional channel activations to fail */
492 f_ipa_tx(0, ts_RSL_CHAN_RQD('42'O, 42));
493
494 alt {
495 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0,
496 tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV))) {
497 setverdict(fail, "Received CHAN ACT ACK without resources?!?");
498 }
499 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0, tr_RSL_IMM_ASSIGN(?))) -> value rsl_ud {
500 var GsmRrMessage rr;
501 /* match on IMM ASS REJ */
502 rr := dec_GsmRrMessage(rsl_ud.rsl.ies[1].body.full_imm_ass_info.payload);
503 if (rr.header.message_type == IMMEDIATE_ASSIGNMENT_REJECT) {
504 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:total",
Philipp Maiercb6cc482018-03-26 13:08:00 +0200505 chreq_total + NUM_TCHF_PER_BTS + NUM_TCHH_PER_BTS + NUM_SDCCH_PER_BTS+1);
Harald Welte799c97b2017-12-14 17:50:30 +0100506 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:no_channel",
507 chreq_nochan+1);
508 setverdict(pass);
509 } else {
510 repeat;
511 }
512 }
513 [] IPA_RSL[0].receive { repeat; }
514 }
515}
516
Harald Weltecfe2c962017-12-15 12:09:32 +0100517/***********************************************************************
518 * Assignment Testing
519 ***********************************************************************/
520
521/* Verify that the BSC refuses any BSSAP connection from the MSC (They are all BSC->MSC direction) */
522testcase TC_outbound_connect() runs on test_CT {
Harald Welte89d42e82017-12-17 16:42:41 +0100523 f_init(1);
Harald Weltecfe2c962017-12-15 12:09:32 +0100524
Harald Weltea4ca4462018-02-09 00:17:14 +0100525 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 +0100526 BSSAP.receive(tr_BSSAP_DISC_ind(2342, ?, ?));
527 setverdict(pass);
528}
529
Harald Welte16a4adf2017-12-14 18:54:01 +0100530/* Test behavior if MSC answers with CREF to CR */
531testcase TC_assignment_cic_only() runs on test_CT {
532 var BSSAP_N_CONNECT_ind rx_c_ind;
533 var RSL_Message rx_rsl;
534 var DchanTuple dt;
535
Harald Welte89d42e82017-12-17 16:42:41 +0100536 f_init(1);
Harald Welte16a4adf2017-12-14 18:54:01 +0100537
538 dt := f_est_dchan('23'O, 23, '00000000'O);
Harald Welte17b27da2018-05-25 20:33:53 +0200539 if (mp_bssap_cfg.transport == BSSAP_TRANSPORT_AoIP) {
540 /* send assignment without AoIP IEs */
541 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_AssignmentReq(ts_BSSMAP_IE_CIC(0, 1))));
542 } else {
543 /* Send assignmetn without CIC in IPA case */
544 var BSSMAP_IE_AoIP_TransportLayerAddress tla :=
545 valueof(ts_BSSMAP_IE_AoIP_TLA4('01020304'O, 2342));
546 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_AssignmentReq(omit, tla)));
547 }
Harald Welte16a4adf2017-12-14 18:54:01 +0100548 alt {
549 [] BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_AssignmentComplete)) {
550 setverdict(fail, "AoIP BSC cannot accept ASSIGNMENT without AoIP Transport IE");
551 }
Harald Welte235ebf12017-12-15 14:18:16 +0100552 /* TODO: Actually expect GSM0808_CAUSE_REQ_A_IF_TYPE_NOT_SUPP */
Harald Welte16a4adf2017-12-14 18:54:01 +0100553 [] BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_AssignmentFail)) {
554 setverdict(pass);
555 }
556 [] BSSAP.receive { repeat; }
557 }
558}
559
Harald Welteed848512018-05-24 22:27:58 +0200560/* generate an assignment request for either AoIP or SCCPlite */
Harald Weltee102eae2018-05-31 21:03:47 +0200561function f_gen_ass_req() return PDU_BSSAP {
Harald Welteed848512018-05-24 22:27:58 +0200562 var PDU_BSSAP ass_cmd;
563 if (mp_bssap_cfg.transport == BSSAP_TRANSPORT_AoIP) {
564 var BSSMAP_IE_AoIP_TransportLayerAddress tla :=
565 valueof(ts_BSSMAP_IE_AoIP_TLA4('01020304'O, 2342));
566 ass_cmd := valueof(ts_BSSMAP_AssignmentReq(omit, tla));
567 } else {
568 var BSSMAP_IE_CircuitIdentityCode cic := valueof(ts_BSSMAP_IE_CIC(0,1));
569 ass_cmd := valueof(ts_BSSMAP_AssignmentReq(cic, omit));
570 }
571 return ass_cmd;
572}
573
574/* generate an assignment complete template for either AoIP or SCCPlite */
Harald Weltee102eae2018-05-31 21:03:47 +0200575function f_gen_exp_compl() return template PDU_BSSAP {
Harald Welteed848512018-05-24 22:27:58 +0200576 var template PDU_BSSAP exp_compl;
577 if (mp_bssap_cfg.transport == BSSAP_TRANSPORT_AoIP) {
578 exp_compl := tr_BSSMAP_AssignmentComplete(omit, ?);
579 } else {
580 /* CIC is optional "*" as the MSC allocated it */
581 exp_compl := tr_BSSMAP_AssignmentComplete(*, omit);
582 }
583 return exp_compl;
584}
585
Harald Welte235ebf12017-12-15 14:18:16 +0100586/* Run everything required up to sending a caller-specified assignment command and expect response */
587function f_assignment_exp(PDU_BSSAP ass_cmd, template PDU_BSSAP exp, charstring fail_text)
588runs on test_CT {
589 var BSSAP_N_CONNECT_ind rx_c_ind;
590 var RSL_Message rx_rsl;
591 var DchanTuple dt;
592
Harald Welte89d42e82017-12-17 16:42:41 +0100593 f_init(1);
Harald Welte235ebf12017-12-15 14:18:16 +0100594
595 dt := f_est_dchan('23'O, 23, '00000000'O);
596 /* send assignment without AoIP IEs */
597 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ass_cmd));
598 alt {
599 [] BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_AssignmentComplete)) {
600 if (ischosen(exp.pdu.bssmap.assignmentComplete)) {
601 setverdict(pass);
602 } else {
603 setverdict(fail, fail_text);
604 }
605 }
606 [] BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_AssignmentFail)) {
607 if (ischosen(exp.pdu.bssmap.assignmentFailure)) {
608 setverdict(pass);
609 } else {
610 setverdict(fail, fail_text);
611 }
612 }
613 [] BSSAP.receive { repeat; }
614 }
615}
616testcase TC_assignment_csd() runs on test_CT {
617 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
Harald Welteed848512018-05-24 22:27:58 +0200618 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte235ebf12017-12-15 14:18:16 +0100619 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelTypeCSD);
620 //exp_fail.pdu.bssmap.assignmentFailure.cause.causeValue := int2bit(enum2int(GSM0808_CAUSE_REQ_CODEC_TYPE_OR_CONFIG_UNAVAIL), 7);
621 f_assignment_exp(ass_cmd, exp_fail, "BSC accepted Assignment for CSD");
622}
623
624testcase TC_assignment_ctm() runs on test_CT {
625 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
Harald Welteed848512018-05-24 22:27:58 +0200626 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte235ebf12017-12-15 14:18:16 +0100627 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelTypeCTM);
628 //exp_fail.pdu.bssmap.assignmentFailure.cause.causeValue := int2bit(enum2int(GSM0808_CAUSE_REQ_CODEC_TYPE_OR_CONFIG_UNAVAIL), 7);
629 f_assignment_exp(ass_cmd, exp_fail, "BSC accepted Assignment for Speech+CTM");
630}
631
Harald Welte4003d112017-12-09 22:35:39 +0100632type record DchanTuple {
633 integer sccp_conn_id,
634 RslChannelNr rsl_chan_nr
Harald Weltea5d2ab22017-12-09 14:21:42 +0100635}
636
Harald Welted6939652017-12-13 21:02:46 +0100637/* Send CHAN RQD and wait for allocation; acknowledge it */
638private function f_chreq_act_ack(OCT1 ra := '23'O, GsmFrameNumber fn := 23)
639runs on test_CT return RslChannelNr {
640 var RSL_Message rx_rsl;
641 f_ipa_tx(0, ts_RSL_CHAN_RQD(ra, fn));
642 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
643 var RslChannelNr chan_nr := rx_rsl.ies[0].body.chan_nr;
644 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, fn+10));
645 return chan_nr;
646}
647
Harald Welte4003d112017-12-09 22:35:39 +0100648/* helper function to establish a dedicated channel via BTS and MSC */
649function f_est_dchan(OCT1 ra, GsmFrameNumber fn, octetstring l3)
650runs on test_CT return DchanTuple {
651 var BSSAP_N_CONNECT_ind rx_c_ind;
Harald Welte4003d112017-12-09 22:35:39 +0100652 var DchanTuple dt;
Harald Weltea5d2ab22017-12-09 14:21:42 +0100653
Harald Welte4003d112017-12-09 22:35:39 +0100654 /* Send CHAN RQD and wait for allocation; acknowledge it */
Harald Welted6939652017-12-13 21:02:46 +0100655 dt.rsl_chan_nr := f_chreq_act_ack(ra, fn);
Harald Welte4003d112017-12-09 22:35:39 +0100656
657 f_ipa_tx(0, ts_RSL_EST_IND(dt.rsl_chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
658
659 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) -> value rx_c_ind;
660 dt.sccp_conn_id := rx_c_ind.connectionId;
661 BSSAP.send(ts_BSSAP_CONNECT_res(dt.sccp_conn_id));
662
663 return dt;
Harald Weltea5d2ab22017-12-09 14:21:42 +0100664}
665
Harald Welte641fcbe2018-06-14 10:58:35 +0200666/* expect RF CAN REL from BTS, acknowledge it and clear the MSC side */
667private function f_exp_chan_rel_and_clear(DchanTuple dt, integer bts_nr := 0) runs on test_CT {
668 var RSL_Message rx_rsl;
669 /* expect BSC to disable the channel */
670 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL), T3101_MAX);
671 /* respond with CHAN REL ACK */
672 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(dt.rsl_chan_nr));
673
674 /* expect Clear Complete from BSC */
675 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearComplete));
676
677 /* MSC disconnects as instructed. */
678 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
679}
680
Harald Welte4003d112017-12-09 22:35:39 +0100681/* Test behavior of channel release after unilateral RLL REL IND (DISC from MS) */
682testcase TC_chan_rel_rll_rel_ind() runs on test_CT {
Neels Hofmeyr27f64362018-03-12 01:44:00 +0100683 var BSSAP_N_DATA_ind rx_di;
Harald Welte4003d112017-12-09 22:35:39 +0100684 var DchanTuple dt;
Harald Welte96c94412017-12-09 03:12:45 +0100685
Harald Welte89d42e82017-12-17 16:42:41 +0100686 f_init(1);
Harald Welte96c94412017-12-09 03:12:45 +0100687
Harald Welte4003d112017-12-09 22:35:39 +0100688 dt := f_est_dchan('23'O, 23, '00010203040506'O);
689
690 /* simulate RLL REL IND */
691 f_ipa_tx(0, ts_RSL_REL_IND(dt.rsl_chan_nr, valueof(ts_RslLinkID_DCCH(0))));
692
Neels Hofmeyr27f64362018-03-12 01:44:00 +0100693 /* expect Clear Request on MSC side */
694 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearRequest)) -> value rx_di;
695
696 /* Instruct BSC to clear channel */
697 var BssmapCause cause := bit2int(rx_di.userData.pdu.bssmap.clearRequest.cause.causeValue);
698 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
699
Harald Welte4003d112017-12-09 22:35:39 +0100700 /* expect BSC to disable the channel */
Harald Welte641fcbe2018-06-14 10:58:35 +0200701 f_exp_chan_rel_and_clear(dt, 0);
Neels Hofmeyr27f64362018-03-12 01:44:00 +0100702
703 /* wait for SCCP emulation to do its job */
704 f_sleep(1.0);
Harald Welte4003d112017-12-09 22:35:39 +0100705
706 setverdict(pass);
707}
708
709/* Test behavior of channel release after CONN FAIL IND from BTS */
710testcase TC_chan_rel_conn_fail() runs on test_CT {
711 var BSSAP_N_DATA_ind rx_di;
Harald Welte4003d112017-12-09 22:35:39 +0100712 var DchanTuple dt;
713
Harald Welte89d42e82017-12-17 16:42:41 +0100714 f_init(1);
Harald Welte4003d112017-12-09 22:35:39 +0100715
716 dt := f_est_dchan('23'O, 23, '00010203040506'O);
717
718 /* simulate CONN FAIL IND */
Harald Weltea8ed9062017-12-14 09:46:01 +0100719 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 +0100720 /* TODO: different cause values? */
721
Harald Welte4003d112017-12-09 22:35:39 +0100722 /* expect Clear Request from BSC */
723 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearRequest)) -> value rx_di;
724
725 /* Instruct BSC to clear channel */
726 var BssmapCause cause := bit2int(rx_di.userData.pdu.bssmap.clearRequest.cause.causeValue);
727 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
728
Harald Welte6ff76ea2018-01-28 13:08:01 +0100729 /* expect BSC to disable the channel */
Harald Welte641fcbe2018-06-14 10:58:35 +0200730 f_exp_chan_rel_and_clear(dt, 0);
Harald Welte4003d112017-12-09 22:35:39 +0100731
732 /* wait for SCCP emulation to do its job */
733 f_sleep(1.0);
734
735 setverdict(pass);
736}
737
Harald Welte99f3ca02018-06-14 13:40:29 +0200738/* Test behavior of early CONN FAIL IND from BTS (before EST IND!) */
739/* See also https://www.osmocom.org/issues/3182 */
740testcase TC_early_conn_fail() runs on test_CT {
741 var RSL_Message rx_rsl;
742 var DchanTuple dt;
743
744 f_init(1);
745
746 /* BTS->BSC: Send CHAN RQD and wait for allocation; acknowledge it */
747 dt.rsl_chan_nr := f_chreq_act_ack(f_rnd_octstring(1), 23);
748
749 /* BTS->BSC: simulate CONN FAIL IND */
750 f_ipa_tx(0, ts_RSL_CONN_FAIL_IND(dt.rsl_chan_nr, RSL_ERR_RADIO_LINK_FAIL));
751
752 /* BTS->BSC: Expect RF channel release from BSC on Abis */
753 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL), 10.0);
754
755 /* BTS<-BSC: respond with CHAN REL ACK */
756 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(dt.rsl_chan_nr));
757
758 setverdict(pass);
759}
760
761/* Test behavior of late CONN FAIL IND from BTS (ater REL IND!) */
762/* See also https://www.osmocom.org/issues/3182 */
763testcase TC_late_conn_fail() runs on test_CT {
764 var RSL_Message rx_rsl;
765 var DchanTuple dt;
766
767 f_init(1);
768
769 dt := f_est_dchan('23'O, 23, '00010203040506'O);
770
771 /* BSC<-MSC: Instruct BSC to clear connection */
772 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(0)));
773
774 /* BTS->BSC: expect BSC to deactivate SACCH */
775 rx_rsl := f_exp_ipa_rx(0, tr_RSL_DEACT_SACCH(dt.rsl_chan_nr));
776
777 /* BTS->BSC: simulate a late CONN FAIL IND from BTS */
778 f_ipa_tx(0, ts_RSL_CONN_FAIL_IND(dt.rsl_chan_nr, RSL_ERR_RADIO_LINK_FAIL));
779
780 /* BTS<-BSC: Expect RF channel release from BSC on Abis */
781 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL), 10.0);
782 /* BTS->BSC: respond with CHAN REL ACK */
783 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(dt.rsl_chan_nr));
784
785 /* BSC->MSC: expect Clear Complete from BSC */
786 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearComplete));
787
788 /* BSC<-MSC: MSC disconnects as requested. */
789 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
790
791 setverdict(pass);
792}
793
Harald Welte91d54a52018-01-28 15:35:07 +0100794function f_expect_chan_rel(integer bts_nr, RslChannelNr rsl_chan_nr, boolean flush := true,
795 boolean handle_rll_rel := true) runs on test_CT {
796
797 var RslLinkId main_dcch := valueof(ts_RslLinkID_DCCH(0));
798 if (flush) {
799 /* Clear the queue, it might still contain stuff like IMMEDIATE ASSIGN */
800 IPA_RSL[bts_nr].clear;
801 }
802 alt {
803 /* ignore DEACTIVATE SACCH (if any) */
804 [] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0,
805 tr_RSL_DEACT_SACCH(rsl_chan_nr))) {
806 repeat;
807 }
808 /* acknowledge RLL release (if any)*/
809 [handle_rll_rel] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0,
810 tr_RSL_REL_REQ(rsl_chan_nr, ?))) {
811 /* FIXME: Why are we getting this for LinkID SACCH? */
812 f_ipa_tx(0, ts_RSL_REL_CONF(rsl_chan_nr, main_dcch));
813 repeat;
814 }
Neels Hofmeyr92d48422018-06-14 04:05:07 +0200815 [not handle_rll_rel] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0,
816 tr_RSL_REL_REQ(rsl_chan_nr, ?))) {
817 /* Do not reply, just continue */
818 repeat;
819 }
Harald Welte91d54a52018-01-28 15:35:07 +0100820 /* Expect RF channel release from BSC on Abis */
821 [] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0,
822 tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL))) {
823 /* respond with CHAN REL ACK */
824 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(rsl_chan_nr));
825 }
826 /* ignore any user data */
827 [] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0, tr_RSL_MsgTypeR(?))) {
828 repeat;
829 }
830 }
831}
832
Harald Welte4003d112017-12-09 22:35:39 +0100833/* Test behavior of channel release after hard Clear Command from MSC */
834testcase TC_chan_rel_hard_clear() runs on test_CT {
835 var BSSAP_N_DATA_ind rx_di;
Harald Welte4003d112017-12-09 22:35:39 +0100836 var DchanTuple dt;
Harald Welte4003d112017-12-09 22:35:39 +0100837
Harald Welte89d42e82017-12-17 16:42:41 +0100838 f_init(1);
Harald Welte4003d112017-12-09 22:35:39 +0100839
840 dt := f_est_dchan('23'O, 23, '00010203040506'O);
841
842 /* Instruct BSC to clear channel */
843 var BssmapCause cause := 0;
844 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
845
846 /* expect Clear Complete from BSC on A */
847 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearComplete)) {
848 /* release the SCCP connection */
849 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
850 }
851
Harald Welte91d54a52018-01-28 15:35:07 +0100852 f_expect_chan_rel(0, dt.rsl_chan_nr);
Harald Welte4003d112017-12-09 22:35:39 +0100853 setverdict(pass);
854}
855
Harald Welted8c36cd2017-12-09 23:05:31 +0100856/* Test behavior of channel release after hard RLSD from MSC */
857testcase TC_chan_rel_hard_rlsd() runs on test_CT {
Harald Welted8c36cd2017-12-09 23:05:31 +0100858 var DchanTuple dt;
Harald Welted8c36cd2017-12-09 23:05:31 +0100859
Harald Welte89d42e82017-12-17 16:42:41 +0100860 f_init(1);
Harald Welted8c36cd2017-12-09 23:05:31 +0100861
862 dt := f_est_dchan('23'O, 23, '00010203040506'O);
863
864 /* release the SCCP connection */
865 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
866
Harald Welte91d54a52018-01-28 15:35:07 +0100867 f_expect_chan_rel(0, dt.rsl_chan_nr);
Harald Welted8c36cd2017-12-09 23:05:31 +0100868 setverdict(pass);
869}
870
Harald Welte550daf92018-06-11 19:22:13 +0200871/* Test behavior of channel release after hard RLSD from MSC and MS is not responding to RLL REL REQ */
872testcase TC_chan_rel_hard_rlsd_ms_dead() runs on test_CT {
873 var DchanTuple dt;
874
875 f_init(1);
876
877 dt := f_est_dchan('23'O, 23, '00010203040506'O);
878
879 /* release the SCCP connection */
880 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
881
882 f_expect_chan_rel(0, dt.rsl_chan_nr, true, false);
883 setverdict(pass);
884}
885
Harald Welte85804d42017-12-10 14:11:58 +0100886/* Test behavior of channel release after BSSMAP RESET from MSC */
887testcase TC_chan_rel_a_reset() runs on test_CT {
Harald Welte85804d42017-12-10 14:11:58 +0100888 var DchanTuple dt;
Harald Welte85804d42017-12-10 14:11:58 +0100889
Harald Welte89d42e82017-12-17 16:42:41 +0100890 f_init(1);
Harald Welte85804d42017-12-10 14:11:58 +0100891
892 dt := f_est_dchan('23'O, 23, '00010203040506'O);
893
894 /* Clear the queue, it might still contain stuff like IMMEDIATE ASSIGN */
895 IPA_RSL[0].clear;
896
897 /* perform BSSAP RESET, expect RESET ACK and DISC.ind on connection */
Harald Weltea4ca4462018-02-09 00:17:14 +0100898 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 +0100899 interleave {
Harald Weltea4ca4462018-02-09 00:17:14 +0100900 [] 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 +0100901 [] BSSAP.receive(tr_BSSAP_DISC_ind(dt.sccp_conn_id, ?, ?)) { }
902 }
903
Philipp Maiere8f38ed2018-02-09 10:30:31 +0100904 f_expect_chan_rel(0, dt.rsl_chan_nr, false);
Harald Welte85804d42017-12-10 14:11:58 +0100905 setverdict(pass);
906}
907
Harald Welte5cd20ed2017-12-13 21:03:20 +0100908/* Test behavior if RSL EST IND for non-active channel */
909testcase TC_rll_est_ind_inact_lchan() runs on test_CT {
910 timer T := 2.0;
911
Harald Welte89d42e82017-12-17 16:42:41 +0100912 f_init(1);
Harald Welte5cd20ed2017-12-13 21:03:20 +0100913
914 var octetstring l3 := '00010203040506'O;
915 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(6));
916 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
917
918 T.start;
919 alt {
920 [] BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) {
921 setverdict(fail, "MSC received COMPL L3 for non-active lchan");
922 }
923 [] BSSAP.receive {}
924 [] IPA_RSL[0].receive {}
925 [] T.timeout {}
926 }
927
928 setverdict(pass);
929}
930
931/* Test behavior if RSL EST IND for invalid SAPI */
932testcase TC_rll_est_ind_inval_sapi1() runs on test_CT {
933 var RslChannelNr chan_nr;
934
Harald Welte89d42e82017-12-17 16:42:41 +0100935 f_init(1);
Harald Welte5cd20ed2017-12-13 21:03:20 +0100936
937 chan_nr := f_chreq_act_ack()
938
939 var octetstring l3 := '00010203040506'O;
940 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(1)), l3));
941
942 timer T := 2.0;
943 T.start;
944 alt {
945 [] BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) {
946 setverdict(fail, "MSC received COMPL L3 for invalid SAPI 1");
947 }
948 [] BSSAP.receive { repeat; }
949 [] IPA_RSL[0].receive { repeat; }
950 [] T.timeout {}
951 }
952
953 setverdict(pass);
954}
955
956/* Test behavior if RSL EST IND for invalid SAPI */
957testcase TC_rll_est_ind_inval_sapi3() runs on test_CT {
958 timer T := 2.0;
959
Harald Welte89d42e82017-12-17 16:42:41 +0100960 f_init(1);
Harald Welte5cd20ed2017-12-13 21:03:20 +0100961
962 var RslChannelNr chan_nr := f_chreq_act_ack();
963
964 var octetstring l3 := '00010203040506'O;
965 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(3)), l3));
966
967 T.start;
968 alt {
969 [] BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) {
970 setverdict(fail, "MSC received COMPL L3 for invalid SAPI 3");
971 }
972 [] BSSAP.receive { repeat; }
973 [] IPA_RSL[0].receive { repeat; }
974 [] T.timeout {}
975 }
976
977 setverdict(pass);
978}
979
980/* Test behavior if RSL EST IND for invalid SACCH */
981testcase TC_rll_est_ind_inval_sacch() runs on test_CT {
982 timer T := 2.0;
983
Harald Welte89d42e82017-12-17 16:42:41 +0100984 f_init(1);
Harald Welte5cd20ed2017-12-13 21:03:20 +0100985
986 var RslChannelNr chan_nr := f_chreq_act_ack();
987
988 var octetstring l3 := '00010203040506'O;
989 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_SACCH(0)), l3));
990
991 T.start;
992 alt {
993 [] BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) {
994 setverdict(fail, "MSC received COMPL L3 for invalid Link SACCH");
995 }
996 [] BSSAP.receive { repeat; }
997 [] IPA_RSL[0].receive { repeat; }
998 [] T.timeout {}
999 }
1000
1001 setverdict(pass);
1002}
1003
1004
1005
Harald Welte4003d112017-12-09 22:35:39 +01001006
1007testcase TC_ctrl_msc_connection_status() runs on test_CT {
1008 var charstring ctrl_resp;
1009
Harald Welte89d42e82017-12-17 16:42:41 +01001010 f_init(1);
Harald Welte4003d112017-12-09 22:35:39 +01001011
1012 /* See https://osmocom.org/issues/2729 */
1013 f_ctrl_get_exp(IPA_CTRL, "msc_connection_status", "connected");
1014 setverdict(pass);
1015}
1016
Stefan Sperlingb041b3d2018-01-03 17:14:55 +01001017testcase TC_ctrl_msc0_connection_status() runs on test_CT {
1018 var charstring ctrl_resp;
1019
1020 f_init(1);
Stefan Sperlingb041b3d2018-01-03 17:14:55 +01001021
1022 f_ctrl_get_exp(IPA_CTRL, "msc.0.connection_status", "connected");
1023 setverdict(pass);
1024}
1025
Harald Welte4003d112017-12-09 22:35:39 +01001026testcase TC_ctrl() runs on test_CT {
1027 var charstring ctrl_resp;
1028
Harald Welte89d42e82017-12-17 16:42:41 +01001029 f_init(1);
Harald Welte4003d112017-12-09 22:35:39 +01001030
1031 /* all below values must match the osmo-bsc.cfg config file used */
1032
Harald Welte6a129692018-03-17 17:30:14 +01001033 f_ctrl_get_exp(IPA_CTRL, "mcc", "001");
1034 f_ctrl_get_exp(IPA_CTRL, "mnc", "01");
Harald Welte44bdaa52017-12-17 17:01:47 +01001035 f_ctrl_get_exp(IPA_CTRL, "number-of-bts", "3");
Harald Welte4003d112017-12-09 22:35:39 +01001036
1037 var integer bts_nr := 0;
1038 f_ctrl_get_exp_bts(IPA_CTRL, bts_nr, "location-area-code", "1");
1039 f_ctrl_get_exp_bts(IPA_CTRL, bts_nr, "cell-identity", "0");
1040 f_ctrl_get_exp_bts(IPA_CTRL, bts_nr, "oml-connection-state", "connected");
1041 f_ctrl_get_exp_bts(IPA_CTRL, bts_nr, "gprs-mode", "gprs");
1042 f_ctrl_get_exp_bts(IPA_CTRL, bts_nr, "rf_state", "operational,unlocked,on");
1043 f_ctrl_get_exp_trx(IPA_CTRL, bts_nr, 0, "arfcn", "871");
1044 f_ctrl_get_exp_trx(IPA_CTRL, bts_nr, 0, "max-power-reduction", "20");
1045
1046 var integer uptime := str2int(f_ctrl_get_bts(IPA_CTRL, bts_nr, "oml-uptime"));
1047 f_sleep(2.0);
1048 if (str2int(f_ctrl_get_bts(IPA_CTRL, bts_nr, "oml-uptime")) < uptime+1) {
1049 setverdict(fail, "oml-uptime not incrementing as expected");
1050 }
1051 /* TODO: Disconnect RSL, imply that OML is disconnected and check for uptime zero? */
1052
1053 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bsc", 0, "paging:attempted", 0);
1054
1055 setverdict(pass);
Harald Welte96c94412017-12-09 03:12:45 +01001056}
1057
Harald Welte6f521d82017-12-11 19:52:02 +01001058function f_bssap_tx_ud(template PDU_BSSAP bssap) runs on test_CT {
Harald Weltea4ca4462018-02-09 00:17:14 +01001059 BSSAP.send(ts_BSSAP_UNITDATA_req(g_bssap.sccp_addr_peer, g_bssap.sccp_addr_own, bssap));
Harald Welte6f521d82017-12-11 19:52:02 +01001060}
1061
1062
1063/***********************************************************************
1064 * Paging Testing
1065 ***********************************************************************/
1066
1067type record Cell_Identity {
1068 GsmMcc mcc,
1069 GsmMnc mnc,
1070 GsmLac lac,
1071 GsmCellId ci
1072};
Harald Welte24135bd2018-03-17 19:27:53 +01001073private const Cell_Identity cid := { '001'H, '01'H, 1, 0 };
Stefan Sperling049a86e2018-03-20 15:51:00 +01001074private const Cell_Identity unknown_cid := { '678'H, 'f90'H, 1, 0 };
Harald Welte6f521d82017-12-11 19:52:02 +01001075
Harald Welte5d1a2202017-12-13 19:51:29 +01001076type set of integer BtsIdList;
1077
1078private function f_bts_in_list(integer bts_id, BtsIdList bts_ids) return boolean {
1079 for (var integer j := 0; j < sizeof(bts_ids); j := j + 1) {
1080 if (bts_id == bts_ids[j]) {
1081 return true;
1082 }
1083 }
1084 return false;
1085}
Harald Welte6f521d82017-12-11 19:52:02 +01001086
1087/* core paging test helper function; used by most paging test cases */
1088private function f_pageing_helper(hexstring imsi,
1089 template BSSMAP_FIELD_CellIdentificationList cid_list,
Harald Welte5d1a2202017-12-13 19:51:29 +01001090 BtsIdList bts_ids := { 0 },
Harald Welte6f521d82017-12-11 19:52:02 +01001091 template RSL_ChanNeeded rsl_chneed := omit,
1092 template OCT4 tmsi := omit) runs on test_CT
1093{
1094 var template BSSMAP_IE_ChannelNeeded bssmap_chneed;
1095 var MobileIdentity mi;
1096 var template octetstring id_enc; /* FIXME */
1097 var RSL_Message rx_rsl;
1098 var integer paging_group := hex2int(imsi[lengthof(imsi)-1]);
Harald Welte5d1a2202017-12-13 19:51:29 +01001099 var integer i;
Harald Welte6f521d82017-12-11 19:52:02 +01001100
1101 f_init();
Harald Welte6f521d82017-12-11 19:52:02 +01001102
1103 /* Clear the queue, it might still contain stuff like BCCH FILLING */
Harald Weltec3068592018-03-17 19:55:31 +01001104 for (i := 0; i < NUM_BTS; i := i + 1) {
1105 IPA_RSL[i].clear;
Harald Welte5d1a2202017-12-13 19:51:29 +01001106 }
Harald Welte6f521d82017-12-11 19:52:02 +01001107
1108 if (isvalue(rsl_chneed)) {
1109 /* The values of 08.08 3.2.2.36 and 08.58 9.3.40 are luckily identical */
1110 bssmap_chneed := ts_BSSMAP_IE_ChanNeeded(int2bit(enum2int(valueof(rsl_chneed)),2));
1111 } else {
1112 bssmap_chneed := omit;
1113 }
1114
1115 f_bssap_tx_ud(ts_BSSMAP_Paging(imsi, cid_list, tmsi, bssmap_chneed));
1116
1117/* FIXME: Disabled due to bugs in both GSM_RR_Types and MobileL3_CommonIE_Types IMSI encoder
1118 if (isvalue(tmsi)) {
1119 mi := valueof(t_Osmo_MI_TMSI(oct2int(valueof(tmsi))));
1120 } else {
1121 mi := valueof(ts_Osmo_MI_IMSI(imsi));
1122 }
1123 id_enc := enc_MobileIdentity(mi);
1124*/
1125 id_enc := ?;
Harald Welte5d1a2202017-12-13 19:51:29 +01001126 for (i := 0; i < sizeof(bts_ids); i := i + 1) {
1127 rx_rsl := f_exp_ipa_rx(bts_ids[i], tr_RSL_PAGING_CMD(id_enc));
1128 /* check channel type, paging group */
1129 if (rx_rsl.ies[1].body.paging_group != paging_group) {
1130 setverdict(fail, "Paging for wrong paging group");
1131 }
1132 if (ispresent(rsl_chneed) and
1133 rx_rsl.ies[3].body.chan_needed.chan_needed != valueof(rsl_chneed)) {
1134 setverdict(fail, "RSL Channel Needed != BSSMAP Channel Needed");
1135 }
Harald Welte6f521d82017-12-11 19:52:02 +01001136 }
Harald Welte2fccd982018-01-31 15:48:19 +01001137 f_sleep(2.0);
Harald Welte5d1a2202017-12-13 19:51:29 +01001138 /* do a quick check on all not-included BTSs if they received paging */
1139 for (i := 0; i < NUM_BTS; i := i + 1) {
1140 timer T := 0.1;
1141 if (f_bts_in_list(i, bts_ids)) {
1142 continue;
1143 }
1144 T.start;
1145 alt {
1146 [] IPA_RSL[i].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0, tr_RSL_PAGING_CMD(id_enc))) {
1147 setverdict(fail, "Paging on BTS ", i, " which is not part of ", bts_ids);
1148 }
1149 [] IPA_RSL[i].receive { repeat; }
1150 [] T.timeout { }
1151 }
Harald Welte6f521d82017-12-11 19:52:02 +01001152 }
1153
1154 setverdict(pass);
1155}
1156
Harald Welte5d1a2202017-12-13 19:51:29 +01001157const BtsIdList c_BtsId_all := { 0, 1, 2 };
Harald Welte751d3eb2018-01-31 15:51:06 +01001158const BtsIdList c_BtsId_none := { };
Harald Welte5d1a2202017-12-13 19:51:29 +01001159const BtsIdList c_BtsId_LAC1 := { 0, 1 };
1160const BtsIdList c_BtsId_LAC2 := { 2 };
1161
Harald Welte6f521d82017-12-11 19:52:02 +01001162/* PAGING by IMSI + TMSI */
1163testcase TC_paging_imsi_nochan() runs on test_CT {
1164 var BSSMAP_FIELD_CellIdentificationList cid_list;
1165 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Philipp Maier8c04b0a2018-02-23 13:48:48 +01001166 f_pageing_helper('001010100000001'H, cid_list, c_BtsId_all, omit, omit);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001167 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001168}
1169
1170/* PAGING by IMSI + TMSI */
1171testcase TC_paging_tmsi_nochan() runs on test_CT {
1172 var BSSMAP_FIELD_CellIdentificationList cid_list;
1173 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01001174 f_pageing_helper('001010100000001'H, cid_list, c_BtsId_all, omit, 'A1B2C301'O);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001175 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001176}
1177
1178/* Paging with different "channel needed' values */
1179testcase TC_paging_tmsi_any() runs on test_CT {
1180 var BSSMAP_FIELD_CellIdentificationList cid_list;
1181 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01001182 f_pageing_helper('001010100000002'H, cid_list, c_BtsId_all, RSL_CHANNEED_ANY, 'A1B2C302'O);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001183 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001184}
1185testcase TC_paging_tmsi_sdcch() runs on test_CT {
1186 var BSSMAP_FIELD_CellIdentificationList cid_list;
1187 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01001188 f_pageing_helper('001010100000003'H, cid_list, c_BtsId_all, RSL_CHANNEED_SDCCH, 'A1B2C303'O);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001189 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001190}
1191testcase TC_paging_tmsi_tch_f() runs on test_CT {
1192 var BSSMAP_FIELD_CellIdentificationList cid_list;
1193 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01001194 f_pageing_helper('001010000000004'H, cid_list, c_BtsId_all, RSL_CHANNEED_TCH_F, 'A1B2C304'O);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001195 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001196}
1197testcase TC_paging_tmsi_tch_hf() runs on test_CT {
1198 var BSSMAP_FIELD_CellIdentificationList cid_list;
1199 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01001200 f_pageing_helper('001010000000005'H, cid_list, c_BtsId_all, RSL_CHANNEED_TCH_ForH, 'A1B2C305'O);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001201 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001202}
1203
1204/* Paging by CGI */
1205testcase TC_paging_imsi_nochan_cgi() runs on test_CT {
1206 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1207 cid_list := { cIl_CGI := { ts_BSSMAP_CI_CGI(cid.mcc, cid.mnc, cid.lac, cid.ci) } };
Harald Welte5d1a2202017-12-13 19:51:29 +01001208 f_pageing_helper('001010000000006'H, cid_list, { 0 });
Philipp Maier282ca4b2018-02-27 17:17:00 +01001209 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001210}
1211
1212/* Paging by LAC+CI */
1213testcase TC_paging_imsi_nochan_lac_ci() runs on test_CT {
1214 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1215 cid_list := { cIl_LAC_CI := { ts_BSSMAP_CI_LAC_CI(cid.lac, cid.ci) } };
Harald Welte5d1a2202017-12-13 19:51:29 +01001216 f_pageing_helper('001010000000007'H, cid_list, { 0 });
Philipp Maier282ca4b2018-02-27 17:17:00 +01001217 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001218}
1219
1220/* Paging by CI */
1221testcase TC_paging_imsi_nochan_ci() runs on test_CT {
1222 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1223 cid_list := { cIl_CI := { ts_BSSMAP_CI_CI(cid.ci) } };
Harald Welte5d1a2202017-12-13 19:51:29 +01001224 f_pageing_helper('001010000000008'H, cid_list, { 0 });
Philipp Maier282ca4b2018-02-27 17:17:00 +01001225 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001226}
1227
1228/* Paging by LAI */
1229testcase TC_paging_imsi_nochan_lai() runs on test_CT {
1230 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1231 cid_list := { cIl_LAI := { ts_BSSMAP_CI_LAI(cid.mcc, cid.mnc, cid.lac) } };
Harald Welte5d1a2202017-12-13 19:51:29 +01001232 f_pageing_helper('001010000000009'H, cid_list, c_BtsId_LAC1);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001233 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001234}
1235
1236/* Paging by LAC */
1237testcase TC_paging_imsi_nochan_lac() runs on test_CT {
1238 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1239 cid_list := { cIl_LAC := { ts_BSSMAP_CI_LAC(cid.lac) } };
Harald Welte5d1a2202017-12-13 19:51:29 +01001240 f_pageing_helper('001010000000010'H, cid_list, c_BtsId_LAC1);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001241 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001242}
1243
1244/* Paging by "all in BSS" */
1245testcase TC_paging_imsi_nochan_all() runs on test_CT {
1246 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1247 cid_list := { cIl_allInBSS := ''O };
Harald Welte5d1a2202017-12-13 19:51:29 +01001248 f_pageing_helper('001010000000011'H, cid_list, c_BtsId_all);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001249 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001250}
1251
Stefan Sperling7b5e1782018-03-20 19:32:43 +01001252/* Paging by PLMN+LAC+RNC; We do not implement this; Verify nothing is paged */
Harald Welte751d3eb2018-01-31 15:51:06 +01001253testcase TC_paging_imsi_nochan_plmn_lac_rnc() runs on test_CT {
1254 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1255 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 +01001256 f_pageing_helper('001010000000012'H, cid_list, c_BtsId_none);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001257 f_shutdown_helper();
Harald Welte751d3eb2018-01-31 15:51:06 +01001258}
Harald Welte6f521d82017-12-11 19:52:02 +01001259
Stefan Sperling7b5e1782018-03-20 19:32:43 +01001260/* Paging by RNC; We do not implement this; Verify nothing is paged */
Harald Welte751d3eb2018-01-31 15:51:06 +01001261testcase TC_paging_imsi_nochan_rnc() runs on test_CT {
1262 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1263 cid_list := { cIl_RNC := { int2oct(13, 2) } };
Stefan Sperling7b5e1782018-03-20 19:32:43 +01001264 f_pageing_helper('001010000000013'H, cid_list, c_BtsId_none);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001265 f_shutdown_helper();
Harald Welte751d3eb2018-01-31 15:51:06 +01001266}
1267
Stefan Sperling7b5e1782018-03-20 19:32:43 +01001268/* Paging by LAC+RNC; We do not implement; Verify nothing is paged */
Harald Welte751d3eb2018-01-31 15:51:06 +01001269testcase TC_paging_imsi_nochan_lac_rnc() runs on test_CT {
1270 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1271 cid_list := { cIl_LAC_RNC := { ts_BSSMAP_CI_LAC_RNC(cid.lac, 14) } };
Stefan Sperling7b5e1782018-03-20 19:32:43 +01001272 f_pageing_helper('001010000000014'H, cid_list, c_BtsId_none);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001273 f_shutdown_helper();
Harald Welte751d3eb2018-01-31 15:51:06 +01001274}
1275
Harald Welte6f521d82017-12-11 19:52:02 +01001276/* Paging on multiple cells (multiple entries in list): Verify all of them page */
Harald Welte751d3eb2018-01-31 15:51:06 +01001277testcase TC_paging_imsi_nochan_lacs() runs on test_CT {
1278 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1279 cid_list := { cIl_LAC := { ts_BSSMAP_CI_LAC(1), ts_BSSMAP_CI_LAC(2) } };
1280 f_pageing_helper('001010000000015'H, cid_list, c_BtsId_all);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001281 f_shutdown_helper();
Harald Welte751d3eb2018-01-31 15:51:06 +01001282}
1283
1284/* Paging on empty list: Verify none of them page */
1285testcase TC_paging_imsi_nochan_lacs_empty() runs on test_CT {
1286 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1287 cid_list := { cIl_LAC := { } };
1288 f_pageing_helper('001010000000016'H, cid_list, c_BtsId_none);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001289 f_shutdown_helper();
Harald Welte751d3eb2018-01-31 15:51:06 +01001290}
1291
Stefan Sperling049a86e2018-03-20 15:51:00 +01001292/* Paging by CGI with unknown MCC/MNC: Verify nothing is paged. */
1293testcase TC_paging_imsi_nochan_cgi_unknown_cid() runs on test_CT {
1294 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1295 cid_list := { cIl_CGI := { ts_BSSMAP_CI_CGI(unknown_cid.mcc, unknown_cid.mnc, unknown_cid.lac, unknown_cid.ci) } };
1296 f_pageing_helper('001010000000006'H, cid_list, c_BtsId_none);
1297 f_shutdown_helper();
1298}
1299
Harald Welte6f521d82017-12-11 19:52:02 +01001300/* Verify paging retransmission interval + count */
1301/* Verify paging stops after channel establishment */
Harald Welte6f521d82017-12-11 19:52:02 +01001302/* Test behavior under paging overload */
Harald Welteae026692017-12-09 01:03:01 +01001303
Harald Weltee65d40e2017-12-13 00:09:06 +01001304/* Verify PCH load */
1305testcase TC_paging_imsi_load() runs on test_CT {
1306 var BSSMAP_FIELD_CellIdentificationList cid_list;
1307 timer T := 4.0;
Harald Welte2caa1062018-03-17 18:19:05 +01001308 timer T_retrans := 1.0;
Harald Weltee65d40e2017-12-13 00:09:06 +01001309 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01001310 f_pageing_helper('001010123456789'H, cid_list, c_BtsId_all);
Harald Weltee65d40e2017-12-13 00:09:06 +01001311
1312 /* tell BSC there is no paging space anymore */
1313 f_ipa_tx(0, ts_RSL_PAGING_LOAD_IND(0));
Harald Welte3b57ab52018-03-17 18:01:10 +01001314 f_sleep(0.2);
1315 IPA_RSL[0].clear;
Harald Weltee65d40e2017-12-13 00:09:06 +01001316
1317 /* Wait for 4 seconds if any more PAGING CMD are received on RSL. Normally,
1318 * there would be 8 retransmissions during 4 seconds */
1319 T.start;
Harald Welte2caa1062018-03-17 18:19:05 +01001320 T_retrans.start;
Harald Weltee65d40e2017-12-13 00:09:06 +01001321 alt {
1322 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0, tr_RSL_PAGING_CMD(?))) {
1323 setverdict(fail, "Received PAGING after LOAD_IND(0)");
Daniel Willmannafce8662018-07-06 23:11:32 +02001324 mtc.stop;
Harald Weltee65d40e2017-12-13 00:09:06 +01001325 }
Harald Welte2caa1062018-03-17 18:19:05 +01001326 [] T_retrans.timeout {
1327 /* re-trnsmit the zero-space LOAD IND to avoid BSC 'auto credit' */
1328 f_ipa_tx(0, ts_RSL_PAGING_LOAD_IND(0));
1329 T_retrans.start;
1330 repeat;
1331 }
Harald Weltee65d40e2017-12-13 00:09:06 +01001332 [] T.timeout {
1333 setverdict(pass);
1334 }
1335 }
Philipp Maier282ca4b2018-02-27 17:17:00 +01001336
1337 f_shutdown_helper();
Harald Weltee65d40e2017-12-13 00:09:06 +01001338}
1339
Harald Welte235ebf12017-12-15 14:18:16 +01001340/* Verify Paging Counter */
Harald Welte1ff69992017-12-14 12:31:17 +01001341testcase TC_paging_counter() runs on test_CT {
1342 var BSSMAP_FIELD_CellIdentificationList cid_list;
1343 timer T := 4.0;
1344 var integer i;
1345 var integer paging_attempted_bsc;
1346 var integer paging_attempted_bts[NUM_BTS];
1347 var integer paging_expired_bts[NUM_BTS];
1348 cid_list := valueof(ts_BSSMAP_CIL_noCell);
1349
1350 f_init();
1351
1352 /* read counters before paging */
1353 paging_attempted_bsc := f_ctrl_get_ratectr_abs(IPA_CTRL, "bsc", 0, "paging:attempted");
1354 for (i := 0; i < NUM_BTS; i := i+1) {
1355 paging_attempted_bts[i] := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", i, "paging:attempted");
1356 paging_expired_bts[i] := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", i, "paging:expired");
1357 }
1358
1359 f_pageing_helper('001230000000001'H, cid_list, c_BtsId_all);
1360
1361 /* expect the attempted pages on BSC and each BTSs to have incremented by one */
1362 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bsc", 0, "paging:attempted", paging_attempted_bsc+1);
1363 for (i := 0; i < NUM_BTS; i := i+1) {
1364 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", i, "paging:attempted",
1365 paging_attempted_bts[i]+1);
1366 }
1367
1368 /* assume that 12s later the paging on all BTSs have expired and hence incremented by 1 */
1369 f_sleep(12.0);
1370 for (i := 0; i < NUM_BTS; i := i+1) {
1371 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", i, "paging:expired",
1372 paging_expired_bts[i]+1);
1373 }
Harald Welte1ff69992017-12-14 12:31:17 +01001374
Philipp Maier282ca4b2018-02-27 17:17:00 +01001375 f_shutdown_helper();
Harald Welte1ff69992017-12-14 12:31:17 +01001376}
1377
1378
Harald Welte10985002017-12-12 09:29:15 +01001379/* Verify paging stops after A-RESET */
1380testcase TC_paging_imsi_a_reset() runs on test_CT {
1381 var BSSMAP_FIELD_CellIdentificationList cid_list;
1382 timer T := 3.0;
1383 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01001384 f_pageing_helper('001010123456789'H, cid_list, c_BtsId_all);
Harald Welte10985002017-12-12 09:29:15 +01001385
1386 /* Perform a BSSMAP Reset and wait for ACK */
Harald Weltea4ca4462018-02-09 00:17:14 +01001387 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 +01001388 alt {
Harald Weltea4ca4462018-02-09 00:17:14 +01001389 [] 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 +01001390 [] BSSAP.receive { repeat; }
1391 }
1392
1393 /* Clear the queue, it might still contain stuff like BCCH FILLING */
Philipp Maier1e6b4422018-02-23 14:02:13 +01001394 for (var integer i := 0; i < sizeof(IPA_RSL); i := i+1) {
1395 IPA_RSL[i].clear;
1396 }
Harald Welte10985002017-12-12 09:29:15 +01001397
1398 /* Wait for 3 seconds if any more PAGING CMD are received on RSL */
1399 T.start;
1400 alt {
1401 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0, tr_RSL_PAGING_CMD(?))) {
1402 setverdict(fail, "Received PAGING after A-RESET");
Daniel Willmannafce8662018-07-06 23:11:32 +02001403 mtc.stop;
Harald Welte10985002017-12-12 09:29:15 +01001404 }
Harald Welte5d1a2202017-12-13 19:51:29 +01001405 [] IPA_RSL[1].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0, tr_RSL_PAGING_CMD(?))) {
1406 setverdict(fail, "Received PAGING after A-RESET");
Daniel Willmannafce8662018-07-06 23:11:32 +02001407 mtc.stop;
Harald Welte5d1a2202017-12-13 19:51:29 +01001408 }
1409 [] IPA_RSL[2].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0, tr_RSL_PAGING_CMD(?))) {
1410 setverdict(fail, "Received PAGING after A-RESET");
Daniel Willmannafce8662018-07-06 23:11:32 +02001411 mtc.stop;
Harald Welte5d1a2202017-12-13 19:51:29 +01001412 }
Harald Welte10985002017-12-12 09:29:15 +01001413 [] T.timeout {
1414 setverdict(pass);
1415 }
1416 }
Philipp Maier282ca4b2018-02-27 17:17:00 +01001417
1418 f_shutdown_helper();
Harald Welte10985002017-12-12 09:29:15 +01001419}
Harald Welteae026692017-12-09 01:03:01 +01001420
Harald Welte4e9b9cc2017-12-14 18:31:02 +01001421/* Test RSL link drop causes counter increment */
1422testcase TC_rsl_drop_counter() runs on test_CT {
1423 var integer rsl_fail;
1424
Harald Welte89d42e82017-12-17 16:42:41 +01001425 f_init(1);
Harald Welte4e9b9cc2017-12-14 18:31:02 +01001426
1427 rsl_fail := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "rsl_fail");
1428
1429 bts[0].rsl.vc_IPA.stop;
1430
1431 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "rsl_fail", rsl_fail+1);
1432
1433 setverdict(pass);
1434}
1435
1436/* TODO: Test OML link drop causes counter increment */
1437
Stefan Sperling830dc9d2018-02-12 21:08:28 +01001438/* The body of TC_rsl_unknown_unit_id() and TC_oml_unknown_unit_id() tests. */
1439function f_ipa_unknown_unit_id(integer mp_bsc_ipa_port) runs on test_CT return boolean {
1440 timer T := 10.0;
1441
1442 bts[0].rsl.id := "IPA-0-RSL";
1443 bts[0].rsl.vc_IPA := IPA_Emulation_CT.create(bts[0].rsl.id & "-IPA");
1444 bts[0].rsl.ccm_pars := c_IPA_default_ccm_pars;
1445 bts[0].rsl.ccm_pars.name := "Osmocom TTCN-3 BTS Simulator";
1446 bts[0].rsl.ccm_pars.unit_id := "0/0/0"; /* value which is unknown at BTS */
1447
Stefan Sperling830dc9d2018-02-12 21:08:28 +01001448 f_ipa_ctrl_start(mp_bsc_ip, mp_bsc_ctrl_port);
1449
1450 f_init_mgcp("VirtMSC");
1451
1452 /* start RSL/OML connection (XXX re-uses RSL port/protocol definitions for OML) */
1453 map(bts[0].rsl.vc_IPA:IPA_PORT, system:IPA);
1454 connect(bts[0].rsl.vc_IPA:IPA_RSL_PORT, self:IPA_RSL[0]);
1455 bts[0].rsl.vc_IPA.start(IPA_Emulation.main_client(mp_bsc_ip, mp_bsc_ipa_port, "", 10000, bts[0].rsl.ccm_pars));
1456
1457 /* wait for IPA OML link to connect and then disconnect */
1458 T.start;
1459 alt {
1460 [] IPA_RSL[0].receive(ASP_IPA_Event:{up_down := ASP_IPA_EVENT_DOWN}) {
1461 T.stop;
1462 return true;
1463 }
1464 [] IPA_RSL[0].receive { repeat }
1465 [] T.timeout {
Daniel Willmannafce8662018-07-06 23:11:32 +02001466 return false;
Stefan Sperling830dc9d2018-02-12 21:08:28 +01001467 }
1468 }
Stefan Sperling830dc9d2018-02-12 21:08:28 +01001469 return false;
1470}
1471
1472/* BSC should close an RSL connection from a BTS with unknown unit ID (OS#2714). */
1473testcase TC_rsl_unknown_unit_id() runs on test_CT {
1474 if (f_ipa_unknown_unit_id(mp_bsc_rsl_port)) {
1475 setverdict(pass);
1476 } else {
1477 setverdict(fail, "Timeout RSL waiting for connection to close");
1478 }
1479}
1480
1481
1482/* BSC should close an RSL connection from a BTS with unknown unit ID (OS#2714). */
1483testcase TC_oml_unknown_unit_id() runs on test_CT {
1484 if (f_ipa_unknown_unit_id(mp_bsc_oml_port)) {
1485 setverdict(pass);
1486 } else {
1487 setverdict(fail, "Timeout OML waiting for connection to close");
1488 }
1489}
1490
1491
Harald Weltec1a2fff2017-12-17 11:06:19 +01001492/***********************************************************************
1493 * "New world" test cases using RSL_Emulation + BSSMAP_Emulation
1494 ***********************************************************************/
1495
1496import from BSSMAP_Emulation all;
1497import from RSL_Emulation all;
1498import from MSC_ConnectionHandler all;
1499
1500type function void_fn(charstring id) runs on MSC_ConnHdlr;
1501
Harald Welte336820c2018-05-31 20:34:52 +02001502/* helper function to create and connect a MSC_ConnHdlr component */
Harald Welteff579f92018-05-31 22:19:39 +02001503private function f_connect_handler(inout MSC_ConnHdlr vc_conn) runs on test_CT {
Harald Weltea4ca4462018-02-09 00:17:14 +01001504 connect(vc_conn:BSSMAPEM, g_bssap.vc_BSSMAP:PROC);
Daniel Willmann191e0d92018-01-17 12:44:35 +01001505 connect(vc_conn:MGCP_PROC, vc_MGCP:MGCP_PROC);
Harald Weltec1a2fff2017-12-17 11:06:19 +01001506 connect(vc_conn:RSL, bts[0].rsl.vc_RSL:CLIENT_PT);
Harald Weltef70df652018-01-29 22:00:23 +01001507 connect(vc_conn:RSL_PROC, bts[0].rsl.vc_RSL:RSL_PROC);
Philipp Maier88f4ae82018-03-01 14:00:58 +01001508 if (isvalue(bts[1])) {
Philipp Maier956a92f2018-02-16 10:58:07 +01001509 connect(vc_conn:RSL1, bts[1].rsl.vc_RSL:CLIENT_PT);
1510 connect(vc_conn:RSL1_PROC, bts[1].rsl.vc_RSL:RSL_PROC);
1511 }
Harald Weltea4ca4462018-02-09 00:17:14 +01001512 connect(vc_conn:BSSAP, g_bssap.vc_BSSMAP:CLIENT);
Daniel Willmann191e0d92018-01-17 12:44:35 +01001513 connect(vc_conn:MGCP, vc_MGCP:MGCP_CLIENT);
Harald Welte336820c2018-05-31 20:34:52 +02001514}
1515
1516function f_start_handler(void_fn fn, template (omit) TestHdlrParams pars := omit)
1517runs on test_CT return MSC_ConnHdlr {
1518 var charstring id := testcasename();
1519 var MSC_ConnHdlr vc_conn;
1520 vc_conn := MSC_ConnHdlr.create(id);
1521 f_connect_handler(vc_conn);
Harald Weltea0630032018-03-20 21:09:55 +01001522 vc_conn.start(f_handler_init(fn, id, pars));
Harald Weltec1a2fff2017-12-17 11:06:19 +01001523 return vc_conn;
1524}
1525
Harald Weltea0630032018-03-20 21:09:55 +01001526/* first function inside ConnHdlr component; sets g_pars + starts function */
1527private function f_handler_init(void_fn fn, charstring id, template (omit) TestHdlrParams pars := omit)
1528runs on MSC_ConnHdlr {
1529 if (isvalue(pars)) {
1530 g_pars := valueof(pars);
1531 }
1532 fn.apply(id);
1533}
1534
Harald Welte3c86ea02018-05-10 22:28:05 +02001535/* Establish signalling channel (non-assignment case) followed by cipher mode */
1536private function f_tc_ciph_mode_a5(charstring id) runs on MSC_ConnHdlr {
Harald Welteed848512018-05-24 22:27:58 +02001537 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
1538 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte3c86ea02018-05-10 22:28:05 +02001539 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelTypeSIGNAL);
Philipp Maier23000732018-05-18 11:25:37 +02001540 ass_cmd.pdu.bssmap.assignmentRequest.circuitIdentityCode := omit;
1541 ass_cmd.pdu.bssmap.assignmentRequest.aoIPTransportLayer := omit;
1542 exp_compl.pdu.bssmap.assignmentComplete.circuitIdentityCode := omit;
1543 exp_compl.pdu.bssmap.assignmentComplete.aoIPTransportLayer := omit;
Harald Welte3c86ea02018-05-10 22:28:05 +02001544
Philipp Maier23000732018-05-18 11:25:37 +02001545 f_establish_fully(ass_cmd, exp_compl);
Harald Welte3c86ea02018-05-10 22:28:05 +02001546}
1547testcase TC_ciph_mode_a5_0() runs on test_CT {
1548 var MSC_ConnHdlr vc_conn;
1549 var TestHdlrParams pars := valueof(t_def_TestHdlrPars);
1550 pars.encr := valueof(t_EncrParams('01'O, f_rnd_octstring(8)));
1551
1552 f_init(1, true);
1553 f_sleep(1.0);
1554 vc_conn := f_start_handler(refers(f_tc_ciph_mode_a5), pars);
1555 vc_conn.done;
1556}
1557testcase TC_ciph_mode_a5_1() runs on test_CT {
1558 var MSC_ConnHdlr vc_conn;
1559 var TestHdlrParams pars := valueof(t_def_TestHdlrPars);
1560 pars.encr := valueof(t_EncrParams('02'O, f_rnd_octstring(8)));
1561
1562 f_init(1, true);
1563 f_sleep(1.0);
1564 vc_conn := f_start_handler(refers(f_tc_ciph_mode_a5), pars);
1565 vc_conn.done;
1566}
1567testcase TC_ciph_mode_a5_3() runs on test_CT {
1568 var MSC_ConnHdlr vc_conn;
1569 var TestHdlrParams pars := valueof(t_def_TestHdlrPars);
1570 pars.encr := valueof(t_EncrParams('08'O, f_rnd_octstring(8)));
1571
1572 f_init(1, true);
1573 f_sleep(1.0);
1574 vc_conn := f_start_handler(refers(f_tc_ciph_mode_a5), pars);
1575 vc_conn.done;
1576}
1577
1578
1579/* establish initial channel, enable ciphering followed by assignment to ciphered channel */
Harald Welte651fcdc2018-05-10 20:23:16 +02001580private function f_tc_assignment_fr_a5(charstring id) runs on MSC_ConnHdlr {
Harald Welteed848512018-05-24 22:27:58 +02001581 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
1582 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Weltec1a2fff2017-12-17 11:06:19 +01001583
Harald Welte552620d2017-12-16 23:21:36 +01001584 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
1585 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
Harald Welte73cd2712017-12-17 00:44:52 +01001586
Harald Weltea0630032018-03-20 21:09:55 +01001587 f_establish_fully(ass_cmd, exp_compl);
Harald Welte552620d2017-12-16 23:21:36 +01001588}
Harald Welte552620d2017-12-16 23:21:36 +01001589testcase TC_assignment_fr_a5_0() runs on test_CT {
1590 var MSC_ConnHdlr vc_conn;
Harald Welte651fcdc2018-05-10 20:23:16 +02001591 var TestHdlrParams pars := valueof(t_def_TestHdlrPars);
1592 pars.encr := valueof(t_EncrParams('01'O, f_rnd_octstring(8)));
Harald Welte552620d2017-12-16 23:21:36 +01001593
Harald Welte89d42e82017-12-17 16:42:41 +01001594 f_init(1, true);
Harald Welte552620d2017-12-16 23:21:36 +01001595 f_sleep(1.0);
Harald Welte651fcdc2018-05-10 20:23:16 +02001596 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5), pars);
Harald Welte552620d2017-12-16 23:21:36 +01001597 vc_conn.done;
1598}
Harald Welte552620d2017-12-16 23:21:36 +01001599testcase TC_assignment_fr_a5_1() runs on test_CT {
Harald Weltec1a2fff2017-12-17 11:06:19 +01001600 var MSC_ConnHdlr vc_conn;
Harald Welte651fcdc2018-05-10 20:23:16 +02001601 var TestHdlrParams pars := valueof(t_def_TestHdlrPars);
1602 pars.encr := valueof(t_EncrParams('02'O, f_rnd_octstring(8)));
Harald Weltec1a2fff2017-12-17 11:06:19 +01001603
Harald Welte89d42e82017-12-17 16:42:41 +01001604 f_init(1, true);
Harald Weltec1a2fff2017-12-17 11:06:19 +01001605 f_sleep(1.0);
Harald Welte651fcdc2018-05-10 20:23:16 +02001606 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5), pars);
1607 vc_conn.done;
1608}
1609testcase TC_assignment_fr_a5_3() runs on test_CT {
1610 var MSC_ConnHdlr vc_conn;
1611 var TestHdlrParams pars := valueof(t_def_TestHdlrPars);
1612 pars.encr := valueof(t_EncrParams('08'O, f_rnd_octstring(8)));
Harald Weltec1a2fff2017-12-17 11:06:19 +01001613
Harald Welte651fcdc2018-05-10 20:23:16 +02001614 f_init(1, true);
1615 f_sleep(1.0);
1616 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5), pars);
Harald Weltec1a2fff2017-12-17 11:06:19 +01001617 vc_conn.done;
1618}
1619
Harald Welte552620d2017-12-16 23:21:36 +01001620/* Expect ASSIGNMENT FAIL if mandatory IE is missing */
1621private function f_tc_assignment_fr_a5_1_codec_missing(charstring id) runs on MSC_ConnHdlr {
Harald Weltea0630032018-03-20 21:09:55 +01001622 g_pars := valueof(t_def_TestHdlrPars);
Harald Welte552620d2017-12-16 23:21:36 +01001623 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
Harald Welteed848512018-05-24 22:27:58 +02001624 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte552620d2017-12-16 23:21:36 +01001625 const OCT8 kc := '0001020304050607'O;
1626
1627 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
Harald Weltea0630032018-03-20 21:09:55 +01001628 f_establish_fully(ass_cmd, exp_fail);
Harald Welte552620d2017-12-16 23:21:36 +01001629}
Harald Welte552620d2017-12-16 23:21:36 +01001630testcase TC_assignment_fr_a5_1_codec_missing() runs on test_CT {
1631 var MSC_ConnHdlr vc_conn;
1632
Harald Welte89d42e82017-12-17 16:42:41 +01001633 f_init(1, true);
Harald Welte552620d2017-12-16 23:21:36 +01001634 f_sleep(1.0);
1635
Harald Welte8863fa12018-05-10 20:15:27 +02001636 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5_1_codec_missing));
Harald Welte552620d2017-12-16 23:21:36 +01001637 vc_conn.done;
1638}
1639
Harald Welte552620d2017-12-16 23:21:36 +01001640private function f_tc_assignment_fr_a5_4(charstring id) runs on MSC_ConnHdlr {
Harald Weltea0630032018-03-20 21:09:55 +01001641 g_pars := valueof(t_def_TestHdlrPars);
Harald Welteed848512018-05-24 22:27:58 +02001642 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
1643 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte552620d2017-12-16 23:21:36 +01001644 const OCT8 kc := '0001020304050607'O;
1645 const OCT16 kc128 := kc & kc;
1646
1647 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
1648 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
Harald Weltea0630032018-03-20 21:09:55 +01001649 f_establish_fully(ass_cmd, exp_compl);
Harald Welte38b2a102017-12-23 02:42:58 +01001650 f_cipher_mode('10'O, kc, kc128, true);
Harald Welte552620d2017-12-16 23:21:36 +01001651 /* TODO: expect GSM0808_CAUSE_CIPHERING_ALGORITHM_NOT_SUPPORTED cause value */
Harald Welte552620d2017-12-16 23:21:36 +01001652}
Harald Welte552620d2017-12-16 23:21:36 +01001653testcase TC_assignment_fr_a5_4() runs on test_CT {
1654 var MSC_ConnHdlr vc_conn;
1655
Harald Welte89d42e82017-12-17 16:42:41 +01001656 f_init(1, true);
Harald Welte552620d2017-12-16 23:21:36 +01001657 f_sleep(1.0);
1658
Harald Welte8863fa12018-05-10 20:15:27 +02001659 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5_4));
Harald Welte552620d2017-12-16 23:21:36 +01001660 vc_conn.done;
1661}
1662
1663
Harald Welte4532e0a2017-12-23 02:05:44 +01001664private function f_tc_assignment_sign(charstring id) runs on MSC_ConnHdlr {
Philipp Maier6a50c7c2018-04-16 16:15:59 +02001665 g_pars := valueof(t_def_TestHdlrPars);
Harald Welte4532e0a2017-12-23 02:05:44 +01001666 var template PDU_BSSAP exp_compl := tr_BSSMAP_AssignmentComplete(omit, omit);
1667 var PDU_BSSAP ass_cmd := valueof(ts_BSSMAP_AssignmentReq(omit, omit));
1668
1669 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelTypeSIGNAL);
Harald Weltea0630032018-03-20 21:09:55 +01001670 f_establish_fully(ass_cmd, exp_compl);
Harald Welte4532e0a2017-12-23 02:05:44 +01001671}
1672
1673testcase TC_assignment_sign() runs on test_CT {
1674 var MSC_ConnHdlr vc_conn;
1675
1676 f_init(1, true);
1677 f_sleep(1.0);
1678
Harald Welte8863fa12018-05-10 20:15:27 +02001679 vc_conn := f_start_handler(refers(f_tc_assignment_sign));
Harald Welte4532e0a2017-12-23 02:05:44 +01001680 vc_conn.done;
1681}
1682
Harald Welte60aa5762018-03-21 19:33:13 +01001683/***********************************************************************
1684 * Codec (list) testing
1685 ***********************************************************************/
1686
1687/* check if the given rsl_mode is compatible with the a_elem */
1688private function f_match_codec(BSSMAP_FIELD_CodecElement a_elem, RSL_IE_ChannelMode rsl_mode)
1689return boolean {
1690 select (a_elem.codecType) {
1691 case (GSM_FR) {
1692 if (match(rsl_mode, tr_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM1))) {
1693 return true;
1694 }
1695 }
1696 case (GSM_HR) {
1697 if (match(rsl_mode, tr_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1))) {
1698 return true;
1699 }
1700 }
1701 case (GSM_EFR) {
1702 if (match(rsl_mode, tr_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM2))) {
1703 return true;
1704 }
1705 }
1706 case (FR_AMR) {
1707 if (match(rsl_mode, tr_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM3))) {
1708 return true;
1709 }
1710 }
1711 case (HR_AMR) {
1712 if (match(rsl_mode, tr_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM3))) {
1713 return true;
1714 }
1715 }
1716 case else { }
1717 }
1718 return false;
1719}
1720
1721/* check if the given rsl_mode is compatible with the a_list */
1722private function f_match_codecs(BSSMAP_IE_SpeechCodecList a_list, RSL_IE_ChannelMode rsl_mode)
1723return boolean {
1724 for (var integer i := 0; i < sizeof(a_list); i := i+1) {
1725 if (f_match_codec(a_list.codecElements[i], rsl_mode)) {
1726 return true;
1727 }
1728 }
1729 return false;
1730}
1731
1732/* determine BSSMAP_IE_ChannelType from *first* element of BSSMAP_FIELD_CodecElement */
Philipp Maier61f6b572018-07-06 14:03:38 +02001733function f_BSSMAP_chtype_from_codec(BSSMAP_FIELD_CodecElement a_elem)
Harald Welte60aa5762018-03-21 19:33:13 +01001734return BSSMAP_IE_ChannelType {
1735 /* FIXME: actually look at all elements of BSSMAP_IE_SpeechCodecList */
1736 var BSSMAP_IE_ChannelType ret := valueof(ts_BSSMAP_IE_ChannelType);
1737 select (a_elem.codecType) {
1738 case (GSM_FR) {
1739 ret.channelRateAndType := ChRate_TCHF;
1740 ret.speechId_DataIndicator := Spdi_TCHF_FR;
1741 }
1742 case (GSM_HR) {
1743 ret.channelRateAndType := ChRate_TCHH;
1744 ret.speechId_DataIndicator := Spdi_TCHH_HR;
1745 }
1746 case (GSM_EFR) {
1747 ret.channelRateAndType := ChRate_TCHF;
1748 ret.speechId_DataIndicator := Spdi_TCHF_EFR;
1749 }
1750 case (FR_AMR) {
1751 ret.channelRateAndType := ChRate_TCHF;
1752 ret.speechId_DataIndicator := Spdi_TCHF_AMR;
1753 }
1754 case (HR_AMR) {
1755 ret.channelRateAndType := ChRate_TCHH;
1756 ret.speechId_DataIndicator := Spdi_TCHH_AMR;
1757 }
1758 case else {
1759 setverdict(fail, "Unsupported codec ", a_elem);
Daniel Willmannafce8662018-07-06 23:11:32 +02001760 mtc.stop;
Harald Welte60aa5762018-03-21 19:33:13 +01001761 }
1762 }
1763 return ret;
1764}
1765
Harald Weltea63b9102018-03-22 20:36:16 +01001766private function f_rsl_chmod_tmpl_from_codec(BSSMAP_FIELD_CodecElement a_elem)
1767return template RSL_IE_Body {
1768 var template RSL_IE_Body mode_ie := {
1769 chan_mode := {
1770 len := ?,
1771 reserved := ?,
1772 dtx_d := ?,
1773 dtx_u := ?,
1774 spd_ind := RSL_SPDI_SPEECH,
1775 ch_rate_type := -,
1776 coding_alg_rate := -
1777 }
1778 }
1779
1780 select (a_elem.codecType) {
1781 case (GSM_FR) {
1782 mode_ie.chan_mode.ch_rate_type := RSL_CHRT_TCH_F;
1783 mode_ie.chan_mode.coding_alg_rate := RSL_CMOD_SP_GSM1;
1784 }
1785 case (GSM_HR) {
1786 mode_ie.chan_mode.ch_rate_type := RSL_CHRT_TCH_H;
1787 mode_ie.chan_mode.coding_alg_rate := RSL_CMOD_SP_GSM1;
1788 }
1789 case (GSM_EFR) {
1790 mode_ie.chan_mode.ch_rate_type := RSL_CHRT_TCH_F;
1791 mode_ie.chan_mode.coding_alg_rate := RSL_CMOD_SP_GSM2;
1792 }
1793 case (FR_AMR) {
1794 mode_ie.chan_mode.ch_rate_type := RSL_CHRT_TCH_F;
1795 mode_ie.chan_mode.coding_alg_rate := RSL_CMOD_SP_GSM3;
1796 }
1797 case (HR_AMR) {
1798 mode_ie.chan_mode.ch_rate_type := RSL_CHRT_TCH_H;
1799 mode_ie.chan_mode.coding_alg_rate := RSL_CMOD_SP_GSM3;
1800 }
1801 }
1802 return mode_ie;
1803}
1804
Harald Welte60aa5762018-03-21 19:33:13 +01001805type record CodecListTest {
1806 BSSMAP_IE_SpeechCodecList codec_list,
1807 charstring id
1808}
1809type record of CodecListTest CodecListTests
1810
1811private function f_TC_assignment_codec(charstring id) runs on MSC_ConnHdlr {
Harald Welteed848512018-05-24 22:27:58 +02001812 var PDU_BSSAP ass_cmd := f_gen_ass_req();
1813 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
Harald Welte60aa5762018-03-21 19:33:13 +01001814
1815 /* puzzle together the ASSIGNMENT REQ for given codec[s] */
Harald Welte79f3f542018-05-25 20:02:37 +02001816 if (mp_bssap_cfg.transport == BSSAP_TRANSPORT_AoIP) {
1817 ass_cmd.pdu.bssmap.assignmentRequest.codecList := g_pars.ass_codec_list;
1818 exp_compl.pdu.bssmap.assignmentComplete.speechCodec.codecElements[0] :=
1819 g_pars.ass_codec_list.codecElements[0];
1820 }
Harald Welte60aa5762018-03-21 19:33:13 +01001821 ass_cmd.pdu.bssmap.assignmentRequest.channelType :=
1822 f_BSSMAP_chtype_from_codec(g_pars.ass_codec_list.codecElements[0]);
Harald Welte60aa5762018-03-21 19:33:13 +01001823 log("expecting ASS COMPL like this: ", exp_compl);
1824
1825 f_establish_fully(ass_cmd, exp_compl);
Harald Weltea63b9102018-03-22 20:36:16 +01001826
1827 /* Verify that the RSL-side activation actually matches our expectations */
1828 var RSL_Message rsl := f_rslem_get_last_act(RSL_PROC, 0, g_chan_nr);
1829
1830 var RSL_IE_Body mode_ie;
1831 if (f_rsl_find_ie(rsl, RSL_IE_CHAN_MODE, mode_ie) == false) {
1832 setverdict(fail, "Couldn't find CHAN_MODE IE");
Daniel Willmannafce8662018-07-06 23:11:32 +02001833 mtc.stop;
Harald Weltea63b9102018-03-22 20:36:16 +01001834 }
1835 var template RSL_IE_Body t_mode_ie := f_rsl_chmod_tmpl_from_codec(g_pars.ass_codec_list.codecElements[0]);
1836 if (not match(mode_ie, t_mode_ie)) {
1837 setverdict(fail, "RSL Channel Mode IE doesn't match expectation");
1838 }
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02001839
1840 var RSL_IE_Body mr_conf;
1841 if (g_pars.expect_mr_conf_ie != omit) {
1842 if (f_rsl_find_ie(rsl, RSL_IE_MR_CONFIG, mr_conf) == false) {
1843 setverdict(fail, "Missing MR CONFIG IE in RSL Chan Activ");
Daniel Willmannafce8662018-07-06 23:11:32 +02001844 mtc.stop;
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02001845 }
1846 log("found RSL MR CONFIG IE: ", mr_conf);
1847
1848 if (not match(mr_conf, g_pars.expect_mr_conf_ie)) {
1849 setverdict(fail, "RSL MR CONFIG IE does not match expectation. Expected: ",
1850 g_pars.expect_mr_conf_ie);
1851 }
1852 } else {
1853 if (f_rsl_find_ie(rsl, RSL_IE_MR_CONFIG, mr_conf) == true) {
1854 log("found RSL MR CONFIG IE: ", mr_conf);
1855 setverdict(fail, "Found MR CONFIG IE in RSL Chan Activ, expecting omit");
Daniel Willmannafce8662018-07-06 23:11:32 +02001856 mtc.stop;
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02001857 }
1858 }
Harald Welte60aa5762018-03-21 19:33:13 +01001859}
1860
1861testcase TC_assignment_codec_fr() runs on test_CT {
1862 var TestHdlrParams pars := valueof(t_def_TestHdlrPars);
1863 var MSC_ConnHdlr vc_conn;
1864
1865 f_init(1, true);
1866 f_sleep(1.0);
1867
1868 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
Harald Welte8863fa12018-05-10 20:15:27 +02001869 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
Harald Welte60aa5762018-03-21 19:33:13 +01001870 vc_conn.done;
1871}
1872
1873testcase TC_assignment_codec_hr() runs on test_CT {
1874 var TestHdlrParams pars := valueof(t_def_TestHdlrPars);
1875 var MSC_ConnHdlr vc_conn;
1876
1877 f_init(1, true);
1878 f_sleep(1.0);
1879
1880 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecHR}));
Harald Welte8863fa12018-05-10 20:15:27 +02001881 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
Harald Welte60aa5762018-03-21 19:33:13 +01001882 vc_conn.done;
1883}
1884
1885testcase TC_assignment_codec_efr() runs on test_CT {
1886 var TestHdlrParams pars := valueof(t_def_TestHdlrPars);
1887 var MSC_ConnHdlr vc_conn;
1888
1889 f_init(1, true);
1890 f_sleep(1.0);
1891
1892 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecEFR}));
Harald Welte8863fa12018-05-10 20:15:27 +02001893 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
Harald Welte60aa5762018-03-21 19:33:13 +01001894 vc_conn.done;
1895}
1896
1897testcase TC_assignment_codec_amr_f() runs on test_CT {
1898 var TestHdlrParams pars := valueof(t_def_TestHdlrPars);
1899 var MSC_ConnHdlr vc_conn;
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02001900 var RSL_IE_Body mr_conf := {
1901 other := {
1902 len := 2,
1903 payload := '2804'O
1904 }
1905 };
Harald Welte60aa5762018-03-21 19:33:13 +01001906
1907 f_init(1, true);
1908 f_sleep(1.0);
1909
1910 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_F}));
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02001911 pars.expect_mr_conf_ie := mr_conf;
Harald Welte8863fa12018-05-10 20:15:27 +02001912 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
Harald Welte60aa5762018-03-21 19:33:13 +01001913 vc_conn.done;
1914}
1915
1916testcase TC_assignment_codec_amr_h() runs on test_CT {
1917 var TestHdlrParams pars := valueof(t_def_TestHdlrPars);
1918 var MSC_ConnHdlr vc_conn;
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02001919 var RSL_IE_Body mr_conf := {
1920 other := {
1921 len := 2,
1922 payload := '2804'O
1923 }
1924 };
Harald Welte60aa5762018-03-21 19:33:13 +01001925
1926 f_init(1, true);
1927 f_sleep(1.0);
1928
1929 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_H}));
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02001930 pars.expect_mr_conf_ie := mr_conf;
Harald Welte8863fa12018-05-10 20:15:27 +02001931 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
Harald Welte60aa5762018-03-21 19:33:13 +01001932 vc_conn.done;
1933}
1934
Harald Welte898113b2018-01-31 18:32:21 +01001935/* test if L3 RR CLASSMARK CHANGE is translated to BSSMAP CLASSMARK UPDATE */
1936private function f_tc_classmark(charstring id) runs on MSC_ConnHdlr {
Harald Weltea0630032018-03-20 21:09:55 +01001937 g_pars := valueof(t_def_TestHdlrPars);
1938 f_create_chan_and_exp();
Harald Welte898113b2018-01-31 18:32:21 +01001939 /* we should now have a COMPL_L3 at the MSC */
1940 BSSAP.receive(tr_BSSMAP_ComplL3);
1941
1942 f_rsl_send_l3(ts_RRM_CM_CHG(valueof(ts_CM2)));
1943 BSSAP.receive(tr_BSSMAP_ClassmarkUpd(?, omit));
1944 setverdict(pass);
1945}
1946testcase TC_classmark() runs on test_CT {
1947 var MSC_ConnHdlr vc_conn;
1948 f_init(1, true);
1949 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02001950 vc_conn := f_start_handler(refers(f_tc_classmark));
Harald Welte898113b2018-01-31 18:32:21 +01001951 vc_conn.done;
1952}
1953
Harald Weltee3bd6582018-01-31 22:51:25 +01001954private function f_est_single_l3(template PDU_ML3_MS_NW l3) runs on MSC_ConnHdlr {
Harald Weltea0630032018-03-20 21:09:55 +01001955 g_pars := valueof(t_def_TestHdlrPars);
1956 f_create_chan_and_exp();
Harald Welte898113b2018-01-31 18:32:21 +01001957 /* we should now have a COMPL_L3 at the MSC */
1958 BSSAP.receive(tr_BSSMAP_ComplL3);
1959
Harald Weltee3bd6582018-01-31 22:51:25 +01001960 /* send the single message we want to send */
1961 f_rsl_send_l3(l3);
1962}
1963
1964private function f_bssap_expect_nothing(float sec := 5.00) runs on MSC_ConnHdlr {
1965 timer T := sec;
1966 var PDU_BSSAP bssap;
Harald Welte898113b2018-01-31 18:32:21 +01001967 T.start;
1968 alt {
Harald Weltee3bd6582018-01-31 22:51:25 +01001969 [] BSSAP.receive(PDU_BSSAP:?) -> value bssap {
1970 setverdict(fail, "Unexpected BSSMAP ", bssap);
Daniel Willmannafce8662018-07-06 23:11:32 +02001971 mtc.stop;
Harald Welte898113b2018-01-31 18:32:21 +01001972 }
1973 [] T.timeout {
1974 setverdict(pass);
1975 }
1976 }
1977}
1978
Harald Weltee3bd6582018-01-31 22:51:25 +01001979/* unsolicited ASSIGNMENT FAIL (without ASSIGN) from MS shouldn't bring BSC down */
1980private function f_tc_unsol_ass_fail(charstring id) runs on MSC_ConnHdlr {
1981 f_est_single_l3(ts_RRM_AssignmentFailure('00'O));
1982 f_bssap_expect_nothing();
1983}
Harald Welte898113b2018-01-31 18:32:21 +01001984testcase TC_unsol_ass_fail() runs on test_CT {
1985 var MSC_ConnHdlr vc_conn;
1986 f_init(1, true);
1987 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02001988 vc_conn := f_start_handler(refers(f_tc_unsol_ass_fail));
Harald Welte898113b2018-01-31 18:32:21 +01001989 vc_conn.done;
1990}
Harald Welte552620d2017-12-16 23:21:36 +01001991
Harald Welteea99a002018-01-31 20:46:43 +01001992
1993/* unsolicited ASSIGNMENT COMPLETE (without ASSIGN) from MS shouldn't bring BSC down */
1994private function f_tc_unsol_ass_compl(charstring id) runs on MSC_ConnHdlr {
Harald Weltee3bd6582018-01-31 22:51:25 +01001995 f_est_single_l3(ts_RRM_AssignmentComplete('00'O));
1996 f_bssap_expect_nothing();
Harald Welteea99a002018-01-31 20:46:43 +01001997}
1998testcase TC_unsol_ass_compl() runs on test_CT {
1999 var MSC_ConnHdlr vc_conn;
2000 f_init(1, true);
2001 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02002002 vc_conn := f_start_handler(refers(f_tc_unsol_ass_compl));
Harald Welteea99a002018-01-31 20:46:43 +01002003 vc_conn.done;
2004}
2005
2006
Harald Weltefbf9b5e2018-01-31 20:41:23 +01002007/* unsolicited HANDOVER FAIL (without ASSIGN) from MS shouldn't bring BSC down */
2008private function f_tc_unsol_ho_fail(charstring id) runs on MSC_ConnHdlr {
Harald Weltee3bd6582018-01-31 22:51:25 +01002009 f_est_single_l3(ts_RRM_HandoverFailure('00'O));
2010 f_bssap_expect_nothing();
Harald Weltefbf9b5e2018-01-31 20:41:23 +01002011}
Harald Weltefbf9b5e2018-01-31 20:41:23 +01002012testcase TC_unsol_ho_fail() runs on test_CT {
2013 var MSC_ConnHdlr vc_conn;
2014 f_init(1, true);
2015 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02002016 vc_conn := f_start_handler(refers(f_tc_unsol_ho_fail));
Harald Weltefbf9b5e2018-01-31 20:41:23 +01002017 vc_conn.done;
2018}
2019
2020
Harald Weltee3bd6582018-01-31 22:51:25 +01002021/* short message from MS should be ignored */
2022private function f_tc_err_82_short_msg(charstring id) runs on MSC_ConnHdlr {
Harald Weltea0630032018-03-20 21:09:55 +01002023 g_pars := valueof(t_def_TestHdlrPars);
2024 f_create_chan_and_exp();
Harald Weltee3bd6582018-01-31 22:51:25 +01002025 /* we should now have a COMPL_L3 at the MSC */
2026 BSSAP.receive(tr_BSSMAP_ComplL3);
2027
2028 /* send short message */
2029 RSL.send(ts_RSL_DATA_IND(g_chan_nr, valueof(ts_RslLinkID_DCCH(0)), ''O));
2030 f_bssap_expect_nothing();
2031}
2032testcase TC_err_82_short_msg() runs on test_CT {
2033 var MSC_ConnHdlr vc_conn;
2034 f_init(1, true);
2035 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02002036 vc_conn := f_start_handler(refers(f_tc_err_82_short_msg));
Harald Weltee3bd6582018-01-31 22:51:25 +01002037 vc_conn.done;
2038}
2039
2040
Harald Weltee9e02e42018-01-31 23:36:25 +01002041/* 24.008 8.4 Unknown message must trigger RR STATUS */
2042private function f_tc_err_84_unknown_msg(charstring id) runs on MSC_ConnHdlr {
2043 f_est_single_l3(ts_RRM_UL_REL('00'O));
2044 timer T := 3.0
2045 alt {
2046 [] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch tr_RRM_RR_STATUS)) {
2047 setverdict(pass);
2048 }
2049 [] BSSAP.receive { setverdict(fail, "unexpected BSSAP"); }
Harald Welte458fd372018-03-21 11:26:23 +01002050 [] T.timeout { setverdict(fail, "Timeout waiting for RR STATUS"); }
Harald Weltee9e02e42018-01-31 23:36:25 +01002051 }
2052}
2053testcase TC_err_84_unknown_msg() runs on test_CT {
2054 var MSC_ConnHdlr vc_conn;
2055 f_init(1, true);
2056 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02002057 vc_conn := f_start_handler(refers(f_tc_err_84_unknown_msg));
Harald Weltee9e02e42018-01-31 23:36:25 +01002058 vc_conn.done;
2059}
2060
Harald Welte94e0c342018-04-07 11:33:23 +02002061/* execute a "bts <0-255> trx <0-255> timeslot <0-7> " command on given Dchan */
2062private function f_vty_ts_action(charstring suffix, integer bts_nr, integer trx_nr, integer ts_nr)
2063runs on test_CT {
2064 var charstring cmd := "bts "&int2str(bts_nr)&" trx "&int2str(trx_nr)&
2065 " timeslot "&int2str(ts_nr)&" ";
2066 f_vty_transceive(BSCVTY, cmd & suffix);
2067}
2068
Harald Welte261af4b2018-02-12 21:20:39 +01002069/* execute a "bts <0-255> trx <0-255> timeslot <0-7> sub-slot <0-7>" command on given Dchan */
2070private function f_vty_ss_action(charstring suffix, integer bts_nr, integer trx_nr, RslChannelNr chan_nr)
2071runs on MSC_ConnHdlr {
2072 /* FIXME: resolve those from component-global state */
2073 var integer ts_nr := chan_nr.tn;
2074 var integer ss_nr;
2075 if (ischosen(chan_nr.u.ch0)) {
2076 ss_nr := 0;
2077 } else if (ischosen(chan_nr.u.lm)) {
2078 ss_nr := chan_nr.u.lm.sub_chan;
2079 } else if (ischosen(chan_nr.u.sdcch4)) {
2080 ss_nr := chan_nr.u.sdcch4.sub_chan;
2081 } else if (ischosen(chan_nr.u.sdcch8)) {
2082 ss_nr := chan_nr.u.sdcch8.sub_chan;
2083 } else {
2084 setverdict(fail, "Invalid ChanNr ", chan_nr);
Daniel Willmannafce8662018-07-06 23:11:32 +02002085 mtc.stop;
Harald Welte261af4b2018-02-12 21:20:39 +01002086 }
2087
2088 var charstring cmd := "bts "&int2str(bts_nr)&" trx "&int2str(trx_nr)&
2089 " timeslot "&int2str(ts_nr)&" sub-slot "&int2str(ss_nr)&" ";
2090 f_vty_transceive(BSCVTY, cmd & suffix);
2091}
2092
2093private function f_vty_handover(integer bts_nr, integer trx_nr, RslChannelNr chan_nr,
2094 integer new_bts_nr)
2095runs on MSC_ConnHdlr {
2096 f_vty_ss_action("handover " & int2str(new_bts_nr), bts_nr, trx_nr, chan_nr);
2097}
2098
2099/* intra-BSC hand-over between BTS0 and BTS1 */
2100private function f_tc_ho_int(charstring id) runs on MSC_ConnHdlr {
Harald Weltea0630032018-03-20 21:09:55 +01002101 g_pars := valueof(t_def_TestHdlrPars);
Harald Welteed848512018-05-24 22:27:58 +02002102 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
2103 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte261af4b2018-02-12 21:20:39 +01002104 const OCT8 kc := '0001020304050607'O;
2105
2106 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
2107 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
2108
Harald Weltea0630032018-03-20 21:09:55 +01002109 f_establish_fully(ass_cmd, exp_compl);
Harald Welte261af4b2018-02-12 21:20:39 +01002110
2111 var HandoverState hs := {
2112 rr_ho_cmpl_seen := false,
2113 handover_done := false,
2114 old_chan_nr := -
2115 };
2116 /* issue hand-over command on VTY */
2117 f_vty_handover(0, 0, g_chan_nr, 1);
2118 /* temporarily suspend DChan processing on BTS1 to avoid race with RSLEM_register */
2119 f_rslem_suspend(RSL1_PROC);
Philipp Maier3e2af5d2018-07-11 17:01:05 +02002120
2121 /* From the MGW perspective, a handover is is characterized by
2122 * performing one MDCX operation with the MGW. So we expect to see
2123 * one more MDCX during handover. */
2124 g_media.mgcp_conn[0].mdcx_seen_exp := g_media.mgcp_conn[0].crcx_seen_exp + 1;
2125
Harald Welte261af4b2018-02-12 21:20:39 +01002126 alt {
2127 [] as_handover(hs);
Harald Welte261af4b2018-02-12 21:20:39 +01002128 }
Philipp Maier3e2af5d2018-07-11 17:01:05 +02002129
2130 /* Check the amount of MGCP transactions is still consistant with the
2131 * test expectation */
2132 f_check_mgcp_expectations()
Harald Welte261af4b2018-02-12 21:20:39 +01002133}
2134
2135testcase TC_ho_int() runs on test_CT {
2136 var MSC_ConnHdlr vc_conn;
2137 f_init(2, true);
2138 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02002139 vc_conn := f_start_handler(refers(f_tc_ho_int));
Harald Welte261af4b2018-02-12 21:20:39 +01002140 vc_conn.done;
2141}
Harald Weltee9e02e42018-01-31 23:36:25 +01002142
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +01002143/* OS#3041: Open and close N connections in a normal fashion, and expect no
2144 * BSSMAP Reset just because of that. */
2145testcase TC_bssap_rlsd_does_not_cause_bssmap_reset() runs on test_CT {
2146 var default d;
2147 var integer i;
2148 var DchanTuple dt;
2149
2150 f_init();
2151
2152 /* Wait for initial BSSMAP Reset to pass */
2153 f_sleep(4.0);
2154
2155 d := activate(no_bssmap_reset());
2156
2157 /* Setup up a number of connections and RLSD them again from the MSC
2158 * side. In the buggy behavior, the fourth one triggers BSSMAP Reset.
2159 * Let's do it some more times for good measure. */
Harald Weltec3260d92018-06-11 17:48:16 +02002160 for (i := 0; i < 4; i := i+1) {
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +01002161 /* Since we're doing a lot of runs, give each one a fresh
2162 * T_guard from the top. */
2163 T_guard.start;
2164
2165 /* Setup a BSSAP connection and clear it right away. This is
2166 * the MSC telling the BSC about a planned release, it's not an
2167 * erratic loss of a connection. */
Harald Weltea1897182018-06-11 13:53:09 +02002168 dt := f_est_dchan(int2oct(i,1), 23+i, '00010203040506'O);
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +01002169
2170 /* MSC disconnects (RLSD). */
2171 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
2172 }
2173
2174 /* In the buggy behavior, a timeout of 2 seconds happens between above
2175 * trigger (logs "SIGTRAN connection down, reconnecting...") and the
2176 * actual BSSMAP Reset. Wait a bit longer just to make sure. */
2177 f_sleep(4.0);
2178
2179 deactivate(d);
2180 f_shutdown_helper();
2181}
Harald Welte552620d2017-12-16 23:21:36 +01002182
Neels Hofmeyr4ff93282018-03-12 04:25:35 +01002183/* OS#3041: Open and close N connections in a normal fashion, and expect no
2184 * BSSMAP Reset just because of that. Invoke the release by a BSSMAP Clear from
2185 * the MSC. */
2186testcase TC_bssmap_clear_does_not_cause_bssmap_reset() runs on test_CT {
2187 var default d;
2188 var integer i;
2189 var DchanTuple dt;
2190 var BSSAP_N_DATA_ind rx_di;
Neels Hofmeyr4ff93282018-03-12 04:25:35 +01002191 var myBSSMAP_Cause cause_val := GSM0808_CAUSE_CALL_CONTROL;
2192 var BssmapCause cause := enum2int(cause_val);
2193
2194 f_init();
2195
2196 /* Wait for initial BSSMAP Reset to pass */
2197 f_sleep(4.0);
2198
2199 d := activate(no_bssmap_reset());
2200
2201 /* Setup up a number of connections and RLSD them again from the MSC
2202 * side. In the buggy behavior, the fourth one triggers BSSMAP Reset.
2203 * Let's do it some more times for good measure. */
2204 for (i := 0; i < 8; i := i+1) {
2205 /* Since we're doing a lot of runs, give each one a fresh
2206 * T_guard from the top. */
2207 T_guard.start;
2208
2209 /* Setup a BSSAP connection and clear it right away. This is
2210 * the MSC telling the BSC about a planned release, it's not an
2211 * erratic loss of a connection. */
Harald Weltea1897182018-06-11 13:53:09 +02002212 dt := f_est_dchan(int2oct(i,1), 23+i, '00010203040506'O);
Neels Hofmeyr4ff93282018-03-12 04:25:35 +01002213
2214 /* Instruct BSC to clear channel */
2215 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
2216
2217 /* expect BSC to disable the channel */
Harald Welte641fcbe2018-06-14 10:58:35 +02002218 f_exp_chan_rel_and_clear(dt, 0);
Neels Hofmeyr4ff93282018-03-12 04:25:35 +01002219 }
2220
2221 /* In the buggy behavior, a timeout of 2 seconds happens between above
2222 * trigger (logs "SIGTRAN connection down, reconnecting...") and the
2223 * actual BSSMAP Reset. Wait a bit longer just to make sure. */
2224 f_sleep(4.0);
2225
2226 deactivate(d);
2227 f_shutdown_helper();
2228}
2229
Neels Hofmeyrfd445c32018-03-09 15:39:31 +01002230/* OS#3041: Open and close N connections in a normal fashion, and expect no
2231 * BSSMAP Reset just because of that. Close connections from the MS side with a
2232 * Release Ind on RSL. */
2233testcase TC_ms_rel_ind_does_not_cause_bssmap_reset() runs on test_CT {
2234 var default d;
2235 var integer i;
2236 var DchanTuple dt;
2237 var BSSAP_N_DATA_ind rx_di;
Neels Hofmeyrfd445c32018-03-09 15:39:31 +01002238 var integer j;
2239
2240 f_init();
2241
2242 /* Wait for initial BSSMAP Reset to pass */
2243 f_sleep(4.0);
2244
2245 d := activate(no_bssmap_reset());
2246
2247 /* Setup up a number of connections and RLSD them again from the MSC
2248 * side. In the buggy behavior, the fourth one triggers BSSMAP Reset.
2249 * Let's do it some more times for good measure. */
2250 for (i := 0; i < 8; i := i+1) {
2251 /* Since we're doing a lot of runs, give each one a fresh
2252 * T_guard from the top. */
2253 T_guard.start;
2254
2255 /* Setup a BSSAP connection and clear it right away. This is
2256 * the MSC telling the BSC about a planned release, it's not an
2257 * erratic loss of a connection. */
2258 dt := f_est_dchan('23'O, 23, '00010203040506'O);
2259
2260 /* simulate RLL REL IND */
2261 f_ipa_tx(0, ts_RSL_REL_IND(dt.rsl_chan_nr, valueof(ts_RslLinkID_DCCH(0))));
2262
2263 /* expect Clear Request on MSC side */
2264 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearRequest)) -> value rx_di;
2265
2266 /* Instruct BSC to clear channel */
2267 var BssmapCause cause := bit2int(rx_di.userData.pdu.bssmap.clearRequest.cause.causeValue);
2268 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
2269
2270 /* expect BSC to disable the channel */
Harald Welte641fcbe2018-06-14 10:58:35 +02002271 f_exp_chan_rel_and_clear(dt, 0);
Neels Hofmeyrfd445c32018-03-09 15:39:31 +01002272 }
2273
2274 /* In the buggy behavior, a timeout of 2 seconds happens between above
2275 * trigger (logs "SIGTRAN connection down, reconnecting...") and the
2276 * actual BSSMAP Reset. Wait a bit longer just to make sure. */
2277 f_sleep(4.0);
2278
2279 deactivate(d);
2280 f_shutdown_helper();
2281}
2282
Harald Welte94e0c342018-04-07 11:33:23 +02002283/***********************************************************************
2284 * IPA style dynamic PDCH
2285 ***********************************************************************/
2286
2287private function f_dyn_ipa_pdch_act(integer bts_nr, integer trx_nr, integer ts_nr,
2288 template (omit) RSL_Cause nack := omit)
2289runs on test_CT {
2290 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(ts_nr));
2291 var RSL_Message rsl_unused;
2292 /* ask BSC via VTY to activate a given IPA style chan as PDCH */
2293 f_vty_ts_action("pdch activate", bts_nr, trx_nr, ts_nr);
2294 /* expect the BSC to issue the related RSL command */
2295 rsl_unused := f_exp_ipa_rx(0, tr_RSL_IPA_PDCH_ACT(chan_nr));
2296 if (istemplatekind(nack, "omit")) {
2297 /* respond with a related acknowledgement */
2298 f_ipa_tx(0, ts_RSL_IPA_PDCH_ACT_ACK(chan_nr, ts_RSL_IE_FrameNumber(2342)));
2299 } else {
2300 f_ipa_tx(0, ts_RSL_IPA_PDCH_ACT_NACK(chan_nr, valueof(nack)));
2301 }
2302}
2303
2304private function f_dyn_ipa_pdch_deact(integer bts_nr, integer trx_nr, integer ts_nr,
2305 template (omit) RSL_Cause nack := omit)
2306runs on test_CT {
2307 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(ts_nr));
2308 var RSL_Message rsl_unused;
2309 /* ask BSC via VTY to activate a given IPA style chan as PDCH */
2310 f_vty_ts_action("pdch deactivate", bts_nr, trx_nr, ts_nr);
2311 /* expect the BSC to issue the related RSL command */
2312 rsl_unused := f_exp_ipa_rx(0, tr_RSL_IPA_PDCH_DEACT(chan_nr));
2313 if (istemplatekind(nack, "omit")) {
2314 /* respond with a related acknowledgement */
2315 f_ipa_tx(0, ts_RSL_IPA_PDCH_DEACT_ACK(chan_nr));
2316 } else {
2317 f_ipa_tx(0, ts_RSL_IPA_PDCH_DEACT_NACK(chan_nr, valueof(nack)));
2318 }
2319}
2320
2321private function f_ts_dyn_mode_get(integer bts_nr, integer trx_nr, integer ts_nr)
2322runs on test_CT return charstring {
2323 var charstring cmd, resp;
2324 cmd := "show timeslot "&int2str(bts_nr)&" "&int2str(trx_nr)&" "&int2str(ts_nr);
2325 resp := f_vty_transceive_ret(BSCVTY, cmd);
2326 return regexp(resp, "*\((*)\)*", 0);
2327}
2328
2329private function f_ts_dyn_mode_assert(integer bts_nr, integer trx_nr, integer ts_nr,
2330 template charstring exp)
2331runs on test_CT {
2332 var charstring mode := f_ts_dyn_mode_get(bts_nr, trx_nr, ts_nr);
2333 if (not match(mode, exp)) {
2334 setverdict(fail, "Unexpected TS Mode: ", mode);
Daniel Willmannafce8662018-07-06 23:11:32 +02002335 mtc.stop;
Harald Welte94e0c342018-04-07 11:33:23 +02002336 }
2337}
2338
2339private function f_ts_set_chcomb(integer bts_nr, integer trx_nr, integer ts_nr, charstring chcomb)
2340runs on test_CT {
2341 f_vty_enter_cfg_ts(BSCVTY, bts_nr, trx_nr, ts_nr);
2342 f_vty_transceive(BSCVTY, "phys_chan_config " & chcomb);
2343 f_vty_transceive(BSCVTY, "end");
2344}
2345
2346private const charstring TCHF_MODE := "TCH/F mode";
2347private const charstring TCHH_MODE := "TCH/H mode";
2348private const charstring PDCH_MODE := "PDCH mode";
2349private const charstring NONE_MODE := "NONE mode";
2350
2351/* Test IPA PDCH activation / deactivation triggered by VTY */
2352testcase TC_dyn_pdch_ipa_act_deact() runs on test_CT {
2353 var RSL_Message rsl_unused;
2354
2355 /* change Timeslot 6 before f_init() starts RSL */
2356 f_init_vty();
2357 f_ts_set_chcomb(0, 0, 6, "TCH/F_PDCH");
2358 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
2359
2360 f_init(1, false);
2361 f_sleep(1.0);
2362
2363 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(6));
2364
2365 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
2366 /* The BSC will activate the dynamic PDCH by default, so confirm that */
2367 rsl_unused := f_exp_ipa_rx(0, tr_RSL_IPA_PDCH_ACT(chan_nr));
2368 f_ipa_tx(0, ts_RSL_IPA_PDCH_ACT_ACK(chan_nr, ts_RSL_IE_FrameNumber(2342)));
2369 f_sleep(1.0);
2370 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, PDCH_MODE);
2371
2372 /* De-activate it via VTY */
2373 f_dyn_ipa_pdch_deact(0, 0, chan_nr.tn);
2374 f_sleep(1.0);
2375 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
2376
2377 /* re-activate it via VTY */
2378 f_dyn_ipa_pdch_act(0, 0, chan_nr.tn);
2379 f_sleep(1.0);
2380 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, PDCH_MODE);
2381
2382 /* and finally de-activate it again */
2383 f_dyn_ipa_pdch_deact(0, 0, chan_nr.tn);
2384 f_sleep(1.0);
2385 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
2386
Neels Hofmeyr887e8f12018-06-27 01:01:55 +02002387 /* clean up config */
2388 f_ts_set_chcomb(0, 0, 6, "PDCH");
2389
Harald Welte94e0c342018-04-07 11:33:23 +02002390 setverdict(pass);
2391}
2392
2393/* Test IPA PDCH activation NACK */
2394testcase TC_dyn_pdch_ipa_act_nack() runs on test_CT {
2395 var RSL_Message rsl_unused;
2396
2397 /* change Timeslot 6 before f_init() starts RSL */
2398 f_init_vty();
2399 f_ts_set_chcomb(0, 0, 6, "TCH/F_PDCH");
2400 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
2401
2402 f_init(1, false);
2403 f_sleep(1.0);
2404
2405 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(6));
2406
2407 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
2408 /* The BSC will activate the dynamic PDCH by default, so confirm that */
2409 rsl_unused := f_exp_ipa_rx(0, tr_RSL_IPA_PDCH_ACT(chan_nr));
2410 f_ipa_tx(0, ts_RSL_IPA_PDCH_ACT_ACK(chan_nr, ts_RSL_IE_FrameNumber(2342)));
2411 f_sleep(1.0);
2412 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, PDCH_MODE);
2413
2414 /* De-activate it via VTY */
2415 f_dyn_ipa_pdch_deact(0, 0, chan_nr.tn);
2416 f_sleep(1.0);
2417 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
2418
2419 /* re-activate it via VTY, but fail that; check BSC still assumes TCH/F mode */
2420 f_dyn_ipa_pdch_act(0, 0, chan_nr.tn, RSL_ERR_EQUIPMENT_FAIL);
2421 f_sleep(1.0);
2422 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
2423
Neels Hofmeyr887e8f12018-06-27 01:01:55 +02002424 /* clean up config */
2425 f_ts_set_chcomb(0, 0, 6, "PDCH");
2426
Harald Welte94e0c342018-04-07 11:33:23 +02002427 setverdict(pass);
2428}
2429
2430
2431/***********************************************************************
2432 * Osmocom style dynamic PDCH
2433 ***********************************************************************/
2434
2435private function f_dyn_osmo_pdch_act(integer bts_nr, integer trx_nr, integer ts_nr,
2436 template (omit) RSL_Cause nack := omit)
2437runs on test_CT {
2438 var RslChannelNr chan_nr := valueof(t_RslChanNr_PDCH(ts_nr));
2439 var RSL_Message rsl_unused;
2440 /* ask BSC via VTY to activate a given IPA style chan as PDCH */
2441 /* FIXME: no VTY command to activate Osmocom PDCH !! */
2442 /* expect the BSC to issue the related RSL command */
2443 rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT(chan_nr, ?));
2444 if (istemplatekind(nack, "omit")) {
2445 /* respond with a related acknowledgement */
2446 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, 2342));
2447 } else {
2448 f_ipa_tx(0, ts_RSL_CHAN_ACT_NACK(chan_nr, valueof(nack)));
2449 }
2450}
2451
2452private function f_dyn_osmo_pdch_deact(integer bts_nr, integer trx_nr, integer ts_nr,
2453 template (omit) RSL_Cause nack := omit)
2454runs on test_CT {
2455 var RslChannelNr chan_nr := valueof(t_RslChanNr_PDCH(ts_nr));
2456 var RSL_Message rsl_unused;
2457 /* ask BSC via VTY to activate a given IPA style chan as PDCH */
2458 /* FIXME: no VTY command to activate Osmocom PDCH !! */
2459 /* expect the BSC to issue the related RSL command */
2460 rsl_unused := f_exp_ipa_rx(0, tr_RSL_RF_CHAN_REL(chan_nr));
2461 if (istemplatekind(nack, "omit")) {
2462 /* respond with a related acknowledgement */
2463 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(chan_nr));
2464 } else {
2465 //f_ipa_tx(0, ts_RSL_RF_CHAN_REL_NACK(chan_nr, valueof(nack)));
2466 }
2467}
2468
2469/* Test Osmocom dyn PDCH activation / deactivation triggered by VTY */
2470testcase TC_dyn_pdch_osmo_act_deact() runs on test_CT {
2471 var RSL_Message rsl_unused;
2472
2473 /* change Timeslot 6 before f_init() starts RSL */
2474 f_init_vty();
2475 f_ts_set_chcomb(0, 0, 6, "TCH/F_TCH/H_PDCH");
2476 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
2477
2478 f_init(1, false);
2479 f_sleep(1.0);
2480
2481 var RslChannelNr chan_nr := valueof(t_RslChanNr_PDCH(6));
2482
2483 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, NONE_MODE);
2484 /* The BSC will activate the dynamic PDCH by default, so confirm that */
2485 rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(chan_nr, ?));
2486
2487 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, 2342));
2488 f_sleep(1.0);
2489 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, PDCH_MODE);
2490
Neels Hofmeyr887e8f12018-06-27 01:01:55 +02002491 /* clean up config */
2492 f_ts_set_chcomb(0, 0, 6, "PDCH");
2493
Harald Welte94e0c342018-04-07 11:33:23 +02002494 setverdict(pass);
2495}
2496
2497/* Test Osmocom dyn PDCH activation NACK behavior */
2498testcase TC_dyn_pdch_osmo_act_nack() runs on test_CT {
2499 var RSL_Message rsl_unused;
2500
2501 /* change Timeslot 6 before f_init() starts RSL */
2502 f_init_vty();
2503 f_ts_set_chcomb(0, 0, 6, "TCH/F_TCH/H_PDCH");
2504 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
2505
2506 f_init(1, false);
2507 f_sleep(1.0);
2508
2509 var RslChannelNr chan_nr := valueof(t_RslChanNr_PDCH(6));
2510
2511 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, NONE_MODE);
2512 /* The BSC will activate the dynamic PDCH by default, so confirm that */
2513 rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(chan_nr, ?));
2514
2515 /* NACK this activation and expect the "show timeslot" mode still to be NONE */
2516 f_ipa_tx(0, ts_RSL_CHAN_ACT_NACK(chan_nr, RSL_ERR_EQUIPMENT_FAIL));
2517 f_sleep(1.0);
2518 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, NONE_MODE);
2519
Neels Hofmeyr887e8f12018-06-27 01:01:55 +02002520 /* clean up config */
2521 f_ts_set_chcomb(0, 0, 6, "PDCH");
2522
Harald Welte94e0c342018-04-07 11:33:23 +02002523 setverdict(pass);
2524}
2525
Harald Welte0ea2d5e2018-04-07 21:40:29 +02002526/* Dyn PDCH todo:
2527 * activate OSMO as TCH/F
2528 * activate OSMO as TCH/H
2529 * does the BSC-located PCU socket get the updated INFO?
2530 * what if no PCU is connected at the time?
2531 * is the info correct on delayed PCU (re)connect?
2532 */
Harald Welte94e0c342018-04-07 11:33:23 +02002533
Harald Welte28d943e2017-11-25 15:00:50 +01002534control {
Harald Welte898113b2018-01-31 18:32:21 +01002535 /* CTRL interface testing */
Harald Welte4003d112017-12-09 22:35:39 +01002536 execute( TC_ctrl_msc_connection_status() );
Stefan Sperlingb041b3d2018-01-03 17:14:55 +01002537 execute( TC_ctrl_msc0_connection_status() );
Harald Welte96c94412017-12-09 03:12:45 +01002538 execute( TC_ctrl() );
Harald Welte898113b2018-01-31 18:32:21 +01002539
2540 /* RSL DCHAN Channel ACtivation / Deactivation */
Harald Welteae026692017-12-09 01:03:01 +01002541 execute( TC_chan_act_noreply() );
Harald Welte4003d112017-12-09 22:35:39 +01002542 execute( TC_chan_act_counter() );
Harald Welteae026692017-12-09 01:03:01 +01002543 execute( TC_chan_act_ack_noest() );
2544 execute( TC_chan_act_ack_est_ind_noreply() );
2545 execute( TC_chan_act_ack_est_ind_refused() );
Harald Welte618ef642017-12-14 14:58:20 +01002546 execute( TC_chan_act_nack() );
Harald Welte799c97b2017-12-14 17:50:30 +01002547 execute( TC_chan_exhaustion() );
Harald Welte4003d112017-12-09 22:35:39 +01002548 execute( TC_chan_rel_rll_rel_ind() );
2549 execute( TC_chan_rel_conn_fail() );
2550 execute( TC_chan_rel_hard_clear() );
Harald Welted8c36cd2017-12-09 23:05:31 +01002551 execute( TC_chan_rel_hard_rlsd() );
Harald Welte550daf92018-06-11 19:22:13 +02002552 execute( TC_chan_rel_hard_rlsd_ms_dead() );
Harald Welte85804d42017-12-10 14:11:58 +01002553 execute( TC_chan_rel_a_reset() );
Harald Welte6f521d82017-12-11 19:52:02 +01002554
Harald Weltecfe2c962017-12-15 12:09:32 +01002555 execute( TC_outbound_connect() );
Harald Welte898113b2018-01-31 18:32:21 +01002556
2557 /* Assignment related */
Harald Welte16a4adf2017-12-14 18:54:01 +01002558 execute( TC_assignment_cic_only() );
Harald Welte235ebf12017-12-15 14:18:16 +01002559 execute( TC_assignment_csd() );
2560 execute( TC_assignment_ctm() );
2561 execute( TC_assignment_sign() );
2562 execute( TC_assignment_fr_a5_0() );
2563 execute( TC_assignment_fr_a5_1() );
Harald Welte8f67d1d2018-05-25 20:38:42 +02002564 if (mp_bssap_cfg.transport == BSSAP_TRANSPORT_AoIP) {
2565 execute( TC_assignment_fr_a5_1_codec_missing() );
2566 }
Harald Welte235ebf12017-12-15 14:18:16 +01002567 execute( TC_assignment_fr_a5_3() );
2568 execute( TC_assignment_fr_a5_4() );
Harald Welte3c86ea02018-05-10 22:28:05 +02002569 execute( TC_ciph_mode_a5_0() );
2570 execute( TC_ciph_mode_a5_1() );
2571 execute( TC_ciph_mode_a5_3() );
Harald Welte16a4adf2017-12-14 18:54:01 +01002572
Harald Welte60aa5762018-03-21 19:33:13 +01002573 execute( TC_assignment_codec_fr() );
2574 execute( TC_assignment_codec_hr() );
2575 execute( TC_assignment_codec_efr() );
2576 execute( TC_assignment_codec_amr_f() );
2577 execute( TC_assignment_codec_amr_h() );
2578
Harald Welte898113b2018-01-31 18:32:21 +01002579 /* RLL Establish Indication on inactive DCHAN / SAPI */
Harald Welte5cd20ed2017-12-13 21:03:20 +01002580 execute( TC_rll_est_ind_inact_lchan() );
2581 execute( TC_rll_est_ind_inval_sapi1() );
2582 execute( TC_rll_est_ind_inval_sapi3() );
2583 execute( TC_rll_est_ind_inval_sacch() );
2584
Harald Welte898113b2018-01-31 18:32:21 +01002585 /* Paging related tests */
Harald Welte6f521d82017-12-11 19:52:02 +01002586 execute( TC_paging_imsi_nochan() );
2587 execute( TC_paging_tmsi_nochan() );
2588 execute( TC_paging_tmsi_any() );
2589 execute( TC_paging_tmsi_sdcch() );
2590 execute( TC_paging_tmsi_tch_f() );
2591 execute( TC_paging_tmsi_tch_hf() );
2592 execute( TC_paging_imsi_nochan_cgi() );
2593 execute( TC_paging_imsi_nochan_lac_ci() );
2594 execute( TC_paging_imsi_nochan_ci() );
2595 execute( TC_paging_imsi_nochan_lai() );
2596 execute( TC_paging_imsi_nochan_lac() );
2597 execute( TC_paging_imsi_nochan_all() );
Harald Welte751d3eb2018-01-31 15:51:06 +01002598 execute( TC_paging_imsi_nochan_plmn_lac_rnc() );
2599 execute( TC_paging_imsi_nochan_rnc() );
2600 execute( TC_paging_imsi_nochan_lac_rnc() );
2601 execute( TC_paging_imsi_nochan_lacs() );
2602 execute( TC_paging_imsi_nochan_lacs_empty() );
Stefan Sperling049a86e2018-03-20 15:51:00 +01002603 execute( TC_paging_imsi_nochan_cgi_unknown_cid() );
Harald Welte10985002017-12-12 09:29:15 +01002604 execute( TC_paging_imsi_a_reset() );
Harald Weltee65d40e2017-12-13 00:09:06 +01002605 execute( TC_paging_imsi_load() );
Philipp Maier779a7922018-02-16 11:00:37 +01002606 execute( TC_paging_counter() );
Harald Welte4e9b9cc2017-12-14 18:31:02 +01002607
2608 execute( TC_rsl_drop_counter() );
Stefan Sperling830dc9d2018-02-12 21:08:28 +01002609 execute( TC_rsl_unknown_unit_id() );
2610
2611 execute( TC_oml_unknown_unit_id() );
Harald Welte898113b2018-01-31 18:32:21 +01002612
2613 execute( TC_classmark() );
2614 execute( TC_unsol_ass_fail() );
Harald Welteea99a002018-01-31 20:46:43 +01002615 execute( TC_unsol_ass_compl() );
Harald Weltefbf9b5e2018-01-31 20:41:23 +01002616 execute( TC_unsol_ho_fail() );
Harald Weltee3bd6582018-01-31 22:51:25 +01002617 execute( TC_err_82_short_msg() );
Harald Weltee9e02e42018-01-31 23:36:25 +01002618 execute( TC_err_84_unknown_msg() );
Harald Welte261af4b2018-02-12 21:20:39 +01002619 execute( TC_ho_int() );
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +01002620
2621 execute( TC_bssap_rlsd_does_not_cause_bssmap_reset() );
Neels Hofmeyr4ff93282018-03-12 04:25:35 +01002622 execute( TC_bssmap_clear_does_not_cause_bssmap_reset() );
Neels Hofmeyrfd445c32018-03-09 15:39:31 +01002623 execute( TC_ms_rel_ind_does_not_cause_bssmap_reset() );
Harald Welte94e0c342018-04-07 11:33:23 +02002624
2625 execute( TC_dyn_pdch_ipa_act_deact() );
2626 execute( TC_dyn_pdch_ipa_act_nack() );
2627 execute( TC_dyn_pdch_osmo_act_deact() );
2628 execute( TC_dyn_pdch_osmo_act_nack() );
Harald Welte99f3ca02018-06-14 13:40:29 +02002629
2630 /* at bottom as they might crash OsmoBSC before OS#3182 is fixed */
2631 execute( TC_early_conn_fail() );
2632 execute( TC_late_conn_fail() );
2633
Harald Welte28d943e2017-11-25 15:00:50 +01002634}
2635
2636}