blob: 5af45732d6789dd8170c9a31c7b19cadebb03d0b [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
Daniel Willmanncbef3982018-07-30 09:22:40 +02001393 /* Wait to avoid a possible race condition if a paging message is
1394 * received right before the reset ACK. */
1395 f_sleep(0.2);
1396
Harald Welte10985002017-12-12 09:29:15 +01001397 /* Clear the queue, it might still contain stuff like BCCH FILLING */
Philipp Maier1e6b4422018-02-23 14:02:13 +01001398 for (var integer i := 0; i < sizeof(IPA_RSL); i := i+1) {
1399 IPA_RSL[i].clear;
1400 }
Harald Welte10985002017-12-12 09:29:15 +01001401
1402 /* Wait for 3 seconds if any more PAGING CMD are received on RSL */
1403 T.start;
1404 alt {
1405 [] IPA_RSL[0].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 Welte10985002017-12-12 09:29:15 +01001408 }
Harald Welte5d1a2202017-12-13 19:51:29 +01001409 [] IPA_RSL[1].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 }
1413 [] IPA_RSL[2].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0, tr_RSL_PAGING_CMD(?))) {
1414 setverdict(fail, "Received PAGING after A-RESET");
Daniel Willmannafce8662018-07-06 23:11:32 +02001415 mtc.stop;
Harald Welte5d1a2202017-12-13 19:51:29 +01001416 }
Harald Welte10985002017-12-12 09:29:15 +01001417 [] T.timeout {
1418 setverdict(pass);
1419 }
1420 }
Philipp Maier282ca4b2018-02-27 17:17:00 +01001421
1422 f_shutdown_helper();
Harald Welte10985002017-12-12 09:29:15 +01001423}
Harald Welteae026692017-12-09 01:03:01 +01001424
Harald Welte4e9b9cc2017-12-14 18:31:02 +01001425/* Test RSL link drop causes counter increment */
1426testcase TC_rsl_drop_counter() runs on test_CT {
1427 var integer rsl_fail;
1428
Harald Welte89d42e82017-12-17 16:42:41 +01001429 f_init(1);
Harald Welte4e9b9cc2017-12-14 18:31:02 +01001430
1431 rsl_fail := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "rsl_fail");
1432
1433 bts[0].rsl.vc_IPA.stop;
1434
1435 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "rsl_fail", rsl_fail+1);
1436
1437 setverdict(pass);
1438}
1439
1440/* TODO: Test OML link drop causes counter increment */
1441
Stefan Sperling830dc9d2018-02-12 21:08:28 +01001442/* The body of TC_rsl_unknown_unit_id() and TC_oml_unknown_unit_id() tests. */
1443function f_ipa_unknown_unit_id(integer mp_bsc_ipa_port) runs on test_CT return boolean {
1444 timer T := 10.0;
1445
1446 bts[0].rsl.id := "IPA-0-RSL";
1447 bts[0].rsl.vc_IPA := IPA_Emulation_CT.create(bts[0].rsl.id & "-IPA");
1448 bts[0].rsl.ccm_pars := c_IPA_default_ccm_pars;
1449 bts[0].rsl.ccm_pars.name := "Osmocom TTCN-3 BTS Simulator";
1450 bts[0].rsl.ccm_pars.unit_id := "0/0/0"; /* value which is unknown at BTS */
1451
Stefan Sperling830dc9d2018-02-12 21:08:28 +01001452 f_ipa_ctrl_start(mp_bsc_ip, mp_bsc_ctrl_port);
1453
1454 f_init_mgcp("VirtMSC");
1455
1456 /* start RSL/OML connection (XXX re-uses RSL port/protocol definitions for OML) */
1457 map(bts[0].rsl.vc_IPA:IPA_PORT, system:IPA);
1458 connect(bts[0].rsl.vc_IPA:IPA_RSL_PORT, self:IPA_RSL[0]);
1459 bts[0].rsl.vc_IPA.start(IPA_Emulation.main_client(mp_bsc_ip, mp_bsc_ipa_port, "", 10000, bts[0].rsl.ccm_pars));
1460
1461 /* wait for IPA OML link to connect and then disconnect */
1462 T.start;
1463 alt {
1464 [] IPA_RSL[0].receive(ASP_IPA_Event:{up_down := ASP_IPA_EVENT_DOWN}) {
1465 T.stop;
1466 return true;
1467 }
1468 [] IPA_RSL[0].receive { repeat }
1469 [] T.timeout {
Daniel Willmannafce8662018-07-06 23:11:32 +02001470 return false;
Stefan Sperling830dc9d2018-02-12 21:08:28 +01001471 }
1472 }
Stefan Sperling830dc9d2018-02-12 21:08:28 +01001473 return false;
1474}
1475
1476/* BSC should close an RSL connection from a BTS with unknown unit ID (OS#2714). */
1477testcase TC_rsl_unknown_unit_id() runs on test_CT {
1478 if (f_ipa_unknown_unit_id(mp_bsc_rsl_port)) {
1479 setverdict(pass);
1480 } else {
1481 setverdict(fail, "Timeout RSL waiting for connection to close");
1482 }
1483}
1484
1485
1486/* BSC should close an RSL connection from a BTS with unknown unit ID (OS#2714). */
1487testcase TC_oml_unknown_unit_id() runs on test_CT {
1488 if (f_ipa_unknown_unit_id(mp_bsc_oml_port)) {
1489 setverdict(pass);
1490 } else {
1491 setverdict(fail, "Timeout OML waiting for connection to close");
1492 }
1493}
1494
1495
Harald Weltec1a2fff2017-12-17 11:06:19 +01001496/***********************************************************************
1497 * "New world" test cases using RSL_Emulation + BSSMAP_Emulation
1498 ***********************************************************************/
1499
1500import from BSSMAP_Emulation all;
1501import from RSL_Emulation all;
1502import from MSC_ConnectionHandler all;
1503
1504type function void_fn(charstring id) runs on MSC_ConnHdlr;
1505
Harald Welte336820c2018-05-31 20:34:52 +02001506/* helper function to create and connect a MSC_ConnHdlr component */
Harald Welteff579f92018-05-31 22:19:39 +02001507private function f_connect_handler(inout MSC_ConnHdlr vc_conn) runs on test_CT {
Harald Weltea4ca4462018-02-09 00:17:14 +01001508 connect(vc_conn:BSSMAPEM, g_bssap.vc_BSSMAP:PROC);
Daniel Willmann191e0d92018-01-17 12:44:35 +01001509 connect(vc_conn:MGCP_PROC, vc_MGCP:MGCP_PROC);
Harald Weltec1a2fff2017-12-17 11:06:19 +01001510 connect(vc_conn:RSL, bts[0].rsl.vc_RSL:CLIENT_PT);
Harald Weltef70df652018-01-29 22:00:23 +01001511 connect(vc_conn:RSL_PROC, bts[0].rsl.vc_RSL:RSL_PROC);
Philipp Maier88f4ae82018-03-01 14:00:58 +01001512 if (isvalue(bts[1])) {
Philipp Maier956a92f2018-02-16 10:58:07 +01001513 connect(vc_conn:RSL1, bts[1].rsl.vc_RSL:CLIENT_PT);
1514 connect(vc_conn:RSL1_PROC, bts[1].rsl.vc_RSL:RSL_PROC);
1515 }
Harald Weltea4ca4462018-02-09 00:17:14 +01001516 connect(vc_conn:BSSAP, g_bssap.vc_BSSMAP:CLIENT);
Daniel Willmann191e0d92018-01-17 12:44:35 +01001517 connect(vc_conn:MGCP, vc_MGCP:MGCP_CLIENT);
Harald Welte336820c2018-05-31 20:34:52 +02001518}
1519
1520function f_start_handler(void_fn fn, template (omit) TestHdlrParams pars := omit)
1521runs on test_CT return MSC_ConnHdlr {
1522 var charstring id := testcasename();
1523 var MSC_ConnHdlr vc_conn;
1524 vc_conn := MSC_ConnHdlr.create(id);
1525 f_connect_handler(vc_conn);
Harald Weltea0630032018-03-20 21:09:55 +01001526 vc_conn.start(f_handler_init(fn, id, pars));
Harald Weltec1a2fff2017-12-17 11:06:19 +01001527 return vc_conn;
1528}
1529
Harald Weltea0630032018-03-20 21:09:55 +01001530/* first function inside ConnHdlr component; sets g_pars + starts function */
1531private function f_handler_init(void_fn fn, charstring id, template (omit) TestHdlrParams pars := omit)
1532runs on MSC_ConnHdlr {
1533 if (isvalue(pars)) {
1534 g_pars := valueof(pars);
1535 }
1536 fn.apply(id);
1537}
1538
Harald Welte3c86ea02018-05-10 22:28:05 +02001539/* Establish signalling channel (non-assignment case) followed by cipher mode */
1540private function f_tc_ciph_mode_a5(charstring id) runs on MSC_ConnHdlr {
Harald Welteed848512018-05-24 22:27:58 +02001541 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
1542 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte3c86ea02018-05-10 22:28:05 +02001543 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelTypeSIGNAL);
Philipp Maier23000732018-05-18 11:25:37 +02001544 ass_cmd.pdu.bssmap.assignmentRequest.circuitIdentityCode := omit;
1545 ass_cmd.pdu.bssmap.assignmentRequest.aoIPTransportLayer := omit;
1546 exp_compl.pdu.bssmap.assignmentComplete.circuitIdentityCode := omit;
1547 exp_compl.pdu.bssmap.assignmentComplete.aoIPTransportLayer := omit;
Harald Welte3c86ea02018-05-10 22:28:05 +02001548
Philipp Maier23000732018-05-18 11:25:37 +02001549 f_establish_fully(ass_cmd, exp_compl);
Harald Welte3c86ea02018-05-10 22:28:05 +02001550}
1551testcase TC_ciph_mode_a5_0() runs on test_CT {
1552 var MSC_ConnHdlr vc_conn;
1553 var TestHdlrParams pars := valueof(t_def_TestHdlrPars);
1554 pars.encr := valueof(t_EncrParams('01'O, f_rnd_octstring(8)));
1555
1556 f_init(1, true);
1557 f_sleep(1.0);
1558 vc_conn := f_start_handler(refers(f_tc_ciph_mode_a5), pars);
1559 vc_conn.done;
1560}
1561testcase TC_ciph_mode_a5_1() runs on test_CT {
1562 var MSC_ConnHdlr vc_conn;
1563 var TestHdlrParams pars := valueof(t_def_TestHdlrPars);
1564 pars.encr := valueof(t_EncrParams('02'O, f_rnd_octstring(8)));
1565
1566 f_init(1, true);
1567 f_sleep(1.0);
1568 vc_conn := f_start_handler(refers(f_tc_ciph_mode_a5), pars);
1569 vc_conn.done;
1570}
1571testcase TC_ciph_mode_a5_3() runs on test_CT {
1572 var MSC_ConnHdlr vc_conn;
1573 var TestHdlrParams pars := valueof(t_def_TestHdlrPars);
1574 pars.encr := valueof(t_EncrParams('08'O, f_rnd_octstring(8)));
1575
1576 f_init(1, true);
1577 f_sleep(1.0);
1578 vc_conn := f_start_handler(refers(f_tc_ciph_mode_a5), pars);
1579 vc_conn.done;
1580}
1581
1582
1583/* establish initial channel, enable ciphering followed by assignment to ciphered channel */
Harald Welte651fcdc2018-05-10 20:23:16 +02001584private function f_tc_assignment_fr_a5(charstring id) runs on MSC_ConnHdlr {
Harald Welteed848512018-05-24 22:27:58 +02001585 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
1586 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Weltec1a2fff2017-12-17 11:06:19 +01001587
Harald Welte552620d2017-12-16 23:21:36 +01001588 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
1589 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
Harald Welte73cd2712017-12-17 00:44:52 +01001590
Harald Weltea0630032018-03-20 21:09:55 +01001591 f_establish_fully(ass_cmd, exp_compl);
Harald Welte552620d2017-12-16 23:21:36 +01001592}
Harald Welte552620d2017-12-16 23:21:36 +01001593testcase TC_assignment_fr_a5_0() runs on test_CT {
1594 var MSC_ConnHdlr vc_conn;
Harald Welte651fcdc2018-05-10 20:23:16 +02001595 var TestHdlrParams pars := valueof(t_def_TestHdlrPars);
1596 pars.encr := valueof(t_EncrParams('01'O, f_rnd_octstring(8)));
Harald Welte552620d2017-12-16 23:21:36 +01001597
Harald Welte89d42e82017-12-17 16:42:41 +01001598 f_init(1, true);
Harald Welte552620d2017-12-16 23:21:36 +01001599 f_sleep(1.0);
Harald Welte651fcdc2018-05-10 20:23:16 +02001600 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5), pars);
Harald Welte552620d2017-12-16 23:21:36 +01001601 vc_conn.done;
1602}
Harald Welte552620d2017-12-16 23:21:36 +01001603testcase TC_assignment_fr_a5_1() runs on test_CT {
Harald Weltec1a2fff2017-12-17 11:06:19 +01001604 var MSC_ConnHdlr vc_conn;
Harald Welte651fcdc2018-05-10 20:23:16 +02001605 var TestHdlrParams pars := valueof(t_def_TestHdlrPars);
1606 pars.encr := valueof(t_EncrParams('02'O, f_rnd_octstring(8)));
Harald Weltec1a2fff2017-12-17 11:06:19 +01001607
Harald Welte89d42e82017-12-17 16:42:41 +01001608 f_init(1, true);
Harald Weltec1a2fff2017-12-17 11:06:19 +01001609 f_sleep(1.0);
Harald Welte651fcdc2018-05-10 20:23:16 +02001610 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5), pars);
1611 vc_conn.done;
1612}
1613testcase TC_assignment_fr_a5_3() runs on test_CT {
1614 var MSC_ConnHdlr vc_conn;
1615 var TestHdlrParams pars := valueof(t_def_TestHdlrPars);
1616 pars.encr := valueof(t_EncrParams('08'O, f_rnd_octstring(8)));
Harald Weltec1a2fff2017-12-17 11:06:19 +01001617
Harald Welte651fcdc2018-05-10 20:23:16 +02001618 f_init(1, true);
1619 f_sleep(1.0);
1620 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5), pars);
Harald Weltec1a2fff2017-12-17 11:06:19 +01001621 vc_conn.done;
1622}
1623
Harald Welte552620d2017-12-16 23:21:36 +01001624/* Expect ASSIGNMENT FAIL if mandatory IE is missing */
1625private function f_tc_assignment_fr_a5_1_codec_missing(charstring id) runs on MSC_ConnHdlr {
Harald Weltea0630032018-03-20 21:09:55 +01001626 g_pars := valueof(t_def_TestHdlrPars);
Harald Welte552620d2017-12-16 23:21:36 +01001627 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
Harald Welteed848512018-05-24 22:27:58 +02001628 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte552620d2017-12-16 23:21:36 +01001629 const OCT8 kc := '0001020304050607'O;
1630
1631 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
Harald Weltea0630032018-03-20 21:09:55 +01001632 f_establish_fully(ass_cmd, exp_fail);
Harald Welte552620d2017-12-16 23:21:36 +01001633}
Harald Welte552620d2017-12-16 23:21:36 +01001634testcase TC_assignment_fr_a5_1_codec_missing() runs on test_CT {
1635 var MSC_ConnHdlr vc_conn;
1636
Harald Welte89d42e82017-12-17 16:42:41 +01001637 f_init(1, true);
Harald Welte552620d2017-12-16 23:21:36 +01001638 f_sleep(1.0);
1639
Harald Welte8863fa12018-05-10 20:15:27 +02001640 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5_1_codec_missing));
Harald Welte552620d2017-12-16 23:21:36 +01001641 vc_conn.done;
1642}
1643
Harald Welte552620d2017-12-16 23:21:36 +01001644private function f_tc_assignment_fr_a5_4(charstring id) runs on MSC_ConnHdlr {
Harald Weltea0630032018-03-20 21:09:55 +01001645 g_pars := valueof(t_def_TestHdlrPars);
Harald Welteed848512018-05-24 22:27:58 +02001646 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
1647 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte552620d2017-12-16 23:21:36 +01001648 const OCT8 kc := '0001020304050607'O;
1649 const OCT16 kc128 := kc & kc;
1650
1651 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
1652 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
Harald Weltea0630032018-03-20 21:09:55 +01001653 f_establish_fully(ass_cmd, exp_compl);
Harald Welte38b2a102017-12-23 02:42:58 +01001654 f_cipher_mode('10'O, kc, kc128, true);
Harald Welte552620d2017-12-16 23:21:36 +01001655 /* TODO: expect GSM0808_CAUSE_CIPHERING_ALGORITHM_NOT_SUPPORTED cause value */
Harald Welte552620d2017-12-16 23:21:36 +01001656}
Harald Welte552620d2017-12-16 23:21:36 +01001657testcase TC_assignment_fr_a5_4() runs on test_CT {
1658 var MSC_ConnHdlr vc_conn;
1659
Harald Welte89d42e82017-12-17 16:42:41 +01001660 f_init(1, true);
Harald Welte552620d2017-12-16 23:21:36 +01001661 f_sleep(1.0);
1662
Harald Welte8863fa12018-05-10 20:15:27 +02001663 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5_4));
Harald Welte552620d2017-12-16 23:21:36 +01001664 vc_conn.done;
1665}
1666
1667
Harald Welte4532e0a2017-12-23 02:05:44 +01001668private function f_tc_assignment_sign(charstring id) runs on MSC_ConnHdlr {
Philipp Maier6a50c7c2018-04-16 16:15:59 +02001669 g_pars := valueof(t_def_TestHdlrPars);
Harald Welte4532e0a2017-12-23 02:05:44 +01001670 var template PDU_BSSAP exp_compl := tr_BSSMAP_AssignmentComplete(omit, omit);
1671 var PDU_BSSAP ass_cmd := valueof(ts_BSSMAP_AssignmentReq(omit, omit));
1672
1673 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelTypeSIGNAL);
Harald Weltea0630032018-03-20 21:09:55 +01001674 f_establish_fully(ass_cmd, exp_compl);
Harald Welte4532e0a2017-12-23 02:05:44 +01001675}
1676
1677testcase TC_assignment_sign() runs on test_CT {
1678 var MSC_ConnHdlr vc_conn;
1679
1680 f_init(1, true);
1681 f_sleep(1.0);
1682
Harald Welte8863fa12018-05-10 20:15:27 +02001683 vc_conn := f_start_handler(refers(f_tc_assignment_sign));
Harald Welte4532e0a2017-12-23 02:05:44 +01001684 vc_conn.done;
1685}
1686
Harald Welte60aa5762018-03-21 19:33:13 +01001687/***********************************************************************
1688 * Codec (list) testing
1689 ***********************************************************************/
1690
1691/* check if the given rsl_mode is compatible with the a_elem */
1692private function f_match_codec(BSSMAP_FIELD_CodecElement a_elem, RSL_IE_ChannelMode rsl_mode)
1693return boolean {
1694 select (a_elem.codecType) {
1695 case (GSM_FR) {
1696 if (match(rsl_mode, tr_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM1))) {
1697 return true;
1698 }
1699 }
1700 case (GSM_HR) {
1701 if (match(rsl_mode, tr_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1))) {
1702 return true;
1703 }
1704 }
1705 case (GSM_EFR) {
1706 if (match(rsl_mode, tr_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM2))) {
1707 return true;
1708 }
1709 }
1710 case (FR_AMR) {
1711 if (match(rsl_mode, tr_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM3))) {
1712 return true;
1713 }
1714 }
1715 case (HR_AMR) {
1716 if (match(rsl_mode, tr_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM3))) {
1717 return true;
1718 }
1719 }
1720 case else { }
1721 }
1722 return false;
1723}
1724
1725/* check if the given rsl_mode is compatible with the a_list */
1726private function f_match_codecs(BSSMAP_IE_SpeechCodecList a_list, RSL_IE_ChannelMode rsl_mode)
1727return boolean {
1728 for (var integer i := 0; i < sizeof(a_list); i := i+1) {
1729 if (f_match_codec(a_list.codecElements[i], rsl_mode)) {
1730 return true;
1731 }
1732 }
1733 return false;
1734}
1735
1736/* determine BSSMAP_IE_ChannelType from *first* element of BSSMAP_FIELD_CodecElement */
Philipp Maier61f6b572018-07-06 14:03:38 +02001737function f_BSSMAP_chtype_from_codec(BSSMAP_FIELD_CodecElement a_elem)
Harald Welte60aa5762018-03-21 19:33:13 +01001738return BSSMAP_IE_ChannelType {
1739 /* FIXME: actually look at all elements of BSSMAP_IE_SpeechCodecList */
1740 var BSSMAP_IE_ChannelType ret := valueof(ts_BSSMAP_IE_ChannelType);
1741 select (a_elem.codecType) {
1742 case (GSM_FR) {
1743 ret.channelRateAndType := ChRate_TCHF;
1744 ret.speechId_DataIndicator := Spdi_TCHF_FR;
1745 }
1746 case (GSM_HR) {
1747 ret.channelRateAndType := ChRate_TCHH;
1748 ret.speechId_DataIndicator := Spdi_TCHH_HR;
1749 }
1750 case (GSM_EFR) {
1751 ret.channelRateAndType := ChRate_TCHF;
1752 ret.speechId_DataIndicator := Spdi_TCHF_EFR;
1753 }
1754 case (FR_AMR) {
1755 ret.channelRateAndType := ChRate_TCHF;
1756 ret.speechId_DataIndicator := Spdi_TCHF_AMR;
1757 }
1758 case (HR_AMR) {
1759 ret.channelRateAndType := ChRate_TCHH;
1760 ret.speechId_DataIndicator := Spdi_TCHH_AMR;
1761 }
1762 case else {
1763 setverdict(fail, "Unsupported codec ", a_elem);
Daniel Willmannafce8662018-07-06 23:11:32 +02001764 mtc.stop;
Harald Welte60aa5762018-03-21 19:33:13 +01001765 }
1766 }
1767 return ret;
1768}
1769
Harald Weltea63b9102018-03-22 20:36:16 +01001770private function f_rsl_chmod_tmpl_from_codec(BSSMAP_FIELD_CodecElement a_elem)
1771return template RSL_IE_Body {
1772 var template RSL_IE_Body mode_ie := {
1773 chan_mode := {
1774 len := ?,
1775 reserved := ?,
1776 dtx_d := ?,
1777 dtx_u := ?,
1778 spd_ind := RSL_SPDI_SPEECH,
1779 ch_rate_type := -,
1780 coding_alg_rate := -
1781 }
1782 }
1783
1784 select (a_elem.codecType) {
1785 case (GSM_FR) {
1786 mode_ie.chan_mode.ch_rate_type := RSL_CHRT_TCH_F;
1787 mode_ie.chan_mode.coding_alg_rate := RSL_CMOD_SP_GSM1;
1788 }
1789 case (GSM_HR) {
1790 mode_ie.chan_mode.ch_rate_type := RSL_CHRT_TCH_H;
1791 mode_ie.chan_mode.coding_alg_rate := RSL_CMOD_SP_GSM1;
1792 }
1793 case (GSM_EFR) {
1794 mode_ie.chan_mode.ch_rate_type := RSL_CHRT_TCH_F;
1795 mode_ie.chan_mode.coding_alg_rate := RSL_CMOD_SP_GSM2;
1796 }
1797 case (FR_AMR) {
1798 mode_ie.chan_mode.ch_rate_type := RSL_CHRT_TCH_F;
1799 mode_ie.chan_mode.coding_alg_rate := RSL_CMOD_SP_GSM3;
1800 }
1801 case (HR_AMR) {
1802 mode_ie.chan_mode.ch_rate_type := RSL_CHRT_TCH_H;
1803 mode_ie.chan_mode.coding_alg_rate := RSL_CMOD_SP_GSM3;
1804 }
1805 }
1806 return mode_ie;
1807}
1808
Harald Welte60aa5762018-03-21 19:33:13 +01001809type record CodecListTest {
1810 BSSMAP_IE_SpeechCodecList codec_list,
1811 charstring id
1812}
1813type record of CodecListTest CodecListTests
1814
1815private function f_TC_assignment_codec(charstring id) runs on MSC_ConnHdlr {
Harald Welteed848512018-05-24 22:27:58 +02001816 var PDU_BSSAP ass_cmd := f_gen_ass_req();
1817 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
Harald Welte60aa5762018-03-21 19:33:13 +01001818
1819 /* puzzle together the ASSIGNMENT REQ for given codec[s] */
Harald Welte79f3f542018-05-25 20:02:37 +02001820 if (mp_bssap_cfg.transport == BSSAP_TRANSPORT_AoIP) {
1821 ass_cmd.pdu.bssmap.assignmentRequest.codecList := g_pars.ass_codec_list;
1822 exp_compl.pdu.bssmap.assignmentComplete.speechCodec.codecElements[0] :=
1823 g_pars.ass_codec_list.codecElements[0];
1824 }
Harald Welte60aa5762018-03-21 19:33:13 +01001825 ass_cmd.pdu.bssmap.assignmentRequest.channelType :=
1826 f_BSSMAP_chtype_from_codec(g_pars.ass_codec_list.codecElements[0]);
Harald Welte60aa5762018-03-21 19:33:13 +01001827 log("expecting ASS COMPL like this: ", exp_compl);
1828
1829 f_establish_fully(ass_cmd, exp_compl);
Harald Weltea63b9102018-03-22 20:36:16 +01001830
1831 /* Verify that the RSL-side activation actually matches our expectations */
1832 var RSL_Message rsl := f_rslem_get_last_act(RSL_PROC, 0, g_chan_nr);
1833
1834 var RSL_IE_Body mode_ie;
1835 if (f_rsl_find_ie(rsl, RSL_IE_CHAN_MODE, mode_ie) == false) {
1836 setverdict(fail, "Couldn't find CHAN_MODE IE");
Daniel Willmannafce8662018-07-06 23:11:32 +02001837 mtc.stop;
Harald Weltea63b9102018-03-22 20:36:16 +01001838 }
1839 var template RSL_IE_Body t_mode_ie := f_rsl_chmod_tmpl_from_codec(g_pars.ass_codec_list.codecElements[0]);
1840 if (not match(mode_ie, t_mode_ie)) {
1841 setverdict(fail, "RSL Channel Mode IE doesn't match expectation");
1842 }
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02001843
1844 var RSL_IE_Body mr_conf;
1845 if (g_pars.expect_mr_conf_ie != omit) {
1846 if (f_rsl_find_ie(rsl, RSL_IE_MR_CONFIG, mr_conf) == false) {
1847 setverdict(fail, "Missing MR CONFIG IE in RSL Chan Activ");
Daniel Willmannafce8662018-07-06 23:11:32 +02001848 mtc.stop;
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02001849 }
1850 log("found RSL MR CONFIG IE: ", mr_conf);
1851
1852 if (not match(mr_conf, g_pars.expect_mr_conf_ie)) {
1853 setverdict(fail, "RSL MR CONFIG IE does not match expectation. Expected: ",
1854 g_pars.expect_mr_conf_ie);
1855 }
1856 } else {
1857 if (f_rsl_find_ie(rsl, RSL_IE_MR_CONFIG, mr_conf) == true) {
1858 log("found RSL MR CONFIG IE: ", mr_conf);
1859 setverdict(fail, "Found MR CONFIG IE in RSL Chan Activ, expecting omit");
Daniel Willmannafce8662018-07-06 23:11:32 +02001860 mtc.stop;
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02001861 }
1862 }
Harald Welte60aa5762018-03-21 19:33:13 +01001863}
1864
1865testcase TC_assignment_codec_fr() runs on test_CT {
1866 var TestHdlrParams pars := valueof(t_def_TestHdlrPars);
1867 var MSC_ConnHdlr vc_conn;
1868
1869 f_init(1, true);
1870 f_sleep(1.0);
1871
1872 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
Harald Welte8863fa12018-05-10 20:15:27 +02001873 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
Harald Welte60aa5762018-03-21 19:33:13 +01001874 vc_conn.done;
1875}
1876
1877testcase TC_assignment_codec_hr() runs on test_CT {
1878 var TestHdlrParams pars := valueof(t_def_TestHdlrPars);
1879 var MSC_ConnHdlr vc_conn;
1880
1881 f_init(1, true);
1882 f_sleep(1.0);
1883
1884 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecHR}));
Harald Welte8863fa12018-05-10 20:15:27 +02001885 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
Harald Welte60aa5762018-03-21 19:33:13 +01001886 vc_conn.done;
1887}
1888
1889testcase TC_assignment_codec_efr() runs on test_CT {
1890 var TestHdlrParams pars := valueof(t_def_TestHdlrPars);
1891 var MSC_ConnHdlr vc_conn;
1892
1893 f_init(1, true);
1894 f_sleep(1.0);
1895
1896 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecEFR}));
Harald Welte8863fa12018-05-10 20:15:27 +02001897 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
Harald Welte60aa5762018-03-21 19:33:13 +01001898 vc_conn.done;
1899}
1900
1901testcase TC_assignment_codec_amr_f() runs on test_CT {
1902 var TestHdlrParams pars := valueof(t_def_TestHdlrPars);
1903 var MSC_ConnHdlr vc_conn;
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02001904 var RSL_IE_Body mr_conf := {
1905 other := {
1906 len := 2,
1907 payload := '2804'O
1908 }
1909 };
Harald Welte60aa5762018-03-21 19:33:13 +01001910
1911 f_init(1, true);
1912 f_sleep(1.0);
1913
1914 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_F}));
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02001915 pars.expect_mr_conf_ie := mr_conf;
Harald Welte8863fa12018-05-10 20:15:27 +02001916 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
Harald Welte60aa5762018-03-21 19:33:13 +01001917 vc_conn.done;
1918}
1919
1920testcase TC_assignment_codec_amr_h() runs on test_CT {
1921 var TestHdlrParams pars := valueof(t_def_TestHdlrPars);
1922 var MSC_ConnHdlr vc_conn;
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02001923 var RSL_IE_Body mr_conf := {
1924 other := {
1925 len := 2,
1926 payload := '2804'O
1927 }
1928 };
Harald Welte60aa5762018-03-21 19:33:13 +01001929
1930 f_init(1, true);
1931 f_sleep(1.0);
1932
1933 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_H}));
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02001934 pars.expect_mr_conf_ie := mr_conf;
Harald Welte8863fa12018-05-10 20:15:27 +02001935 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
Harald Welte60aa5762018-03-21 19:33:13 +01001936 vc_conn.done;
1937}
1938
Harald Welte898113b2018-01-31 18:32:21 +01001939/* test if L3 RR CLASSMARK CHANGE is translated to BSSMAP CLASSMARK UPDATE */
1940private function f_tc_classmark(charstring id) runs on MSC_ConnHdlr {
Harald Weltea0630032018-03-20 21:09:55 +01001941 g_pars := valueof(t_def_TestHdlrPars);
1942 f_create_chan_and_exp();
Harald Welte898113b2018-01-31 18:32:21 +01001943 /* we should now have a COMPL_L3 at the MSC */
1944 BSSAP.receive(tr_BSSMAP_ComplL3);
1945
1946 f_rsl_send_l3(ts_RRM_CM_CHG(valueof(ts_CM2)));
1947 BSSAP.receive(tr_BSSMAP_ClassmarkUpd(?, omit));
1948 setverdict(pass);
1949}
1950testcase TC_classmark() runs on test_CT {
1951 var MSC_ConnHdlr vc_conn;
1952 f_init(1, true);
1953 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02001954 vc_conn := f_start_handler(refers(f_tc_classmark));
Harald Welte898113b2018-01-31 18:32:21 +01001955 vc_conn.done;
1956}
1957
Harald Weltee3bd6582018-01-31 22:51:25 +01001958private function f_est_single_l3(template PDU_ML3_MS_NW l3) runs on MSC_ConnHdlr {
Harald Weltea0630032018-03-20 21:09:55 +01001959 g_pars := valueof(t_def_TestHdlrPars);
1960 f_create_chan_and_exp();
Harald Welte898113b2018-01-31 18:32:21 +01001961 /* we should now have a COMPL_L3 at the MSC */
1962 BSSAP.receive(tr_BSSMAP_ComplL3);
1963
Harald Weltee3bd6582018-01-31 22:51:25 +01001964 /* send the single message we want to send */
1965 f_rsl_send_l3(l3);
1966}
1967
1968private function f_bssap_expect_nothing(float sec := 5.00) runs on MSC_ConnHdlr {
1969 timer T := sec;
1970 var PDU_BSSAP bssap;
Harald Welte898113b2018-01-31 18:32:21 +01001971 T.start;
1972 alt {
Harald Weltee3bd6582018-01-31 22:51:25 +01001973 [] BSSAP.receive(PDU_BSSAP:?) -> value bssap {
1974 setverdict(fail, "Unexpected BSSMAP ", bssap);
Daniel Willmannafce8662018-07-06 23:11:32 +02001975 mtc.stop;
Harald Welte898113b2018-01-31 18:32:21 +01001976 }
1977 [] T.timeout {
1978 setverdict(pass);
1979 }
1980 }
1981}
1982
Harald Weltee3bd6582018-01-31 22:51:25 +01001983/* unsolicited ASSIGNMENT FAIL (without ASSIGN) from MS shouldn't bring BSC down */
1984private function f_tc_unsol_ass_fail(charstring id) runs on MSC_ConnHdlr {
1985 f_est_single_l3(ts_RRM_AssignmentFailure('00'O));
1986 f_bssap_expect_nothing();
1987}
Harald Welte898113b2018-01-31 18:32:21 +01001988testcase TC_unsol_ass_fail() runs on test_CT {
1989 var MSC_ConnHdlr vc_conn;
1990 f_init(1, true);
1991 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02001992 vc_conn := f_start_handler(refers(f_tc_unsol_ass_fail));
Harald Welte898113b2018-01-31 18:32:21 +01001993 vc_conn.done;
1994}
Harald Welte552620d2017-12-16 23:21:36 +01001995
Harald Welteea99a002018-01-31 20:46:43 +01001996
1997/* unsolicited ASSIGNMENT COMPLETE (without ASSIGN) from MS shouldn't bring BSC down */
1998private function f_tc_unsol_ass_compl(charstring id) runs on MSC_ConnHdlr {
Harald Weltee3bd6582018-01-31 22:51:25 +01001999 f_est_single_l3(ts_RRM_AssignmentComplete('00'O));
2000 f_bssap_expect_nothing();
Harald Welteea99a002018-01-31 20:46:43 +01002001}
2002testcase TC_unsol_ass_compl() runs on test_CT {
2003 var MSC_ConnHdlr vc_conn;
2004 f_init(1, true);
2005 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02002006 vc_conn := f_start_handler(refers(f_tc_unsol_ass_compl));
Harald Welteea99a002018-01-31 20:46:43 +01002007 vc_conn.done;
2008}
2009
2010
Harald Weltefbf9b5e2018-01-31 20:41:23 +01002011/* unsolicited HANDOVER FAIL (without ASSIGN) from MS shouldn't bring BSC down */
2012private function f_tc_unsol_ho_fail(charstring id) runs on MSC_ConnHdlr {
Harald Weltee3bd6582018-01-31 22:51:25 +01002013 f_est_single_l3(ts_RRM_HandoverFailure('00'O));
2014 f_bssap_expect_nothing();
Harald Weltefbf9b5e2018-01-31 20:41:23 +01002015}
Harald Weltefbf9b5e2018-01-31 20:41:23 +01002016testcase TC_unsol_ho_fail() runs on test_CT {
2017 var MSC_ConnHdlr vc_conn;
2018 f_init(1, true);
2019 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02002020 vc_conn := f_start_handler(refers(f_tc_unsol_ho_fail));
Harald Weltefbf9b5e2018-01-31 20:41:23 +01002021 vc_conn.done;
2022}
2023
2024
Harald Weltee3bd6582018-01-31 22:51:25 +01002025/* short message from MS should be ignored */
2026private function f_tc_err_82_short_msg(charstring id) runs on MSC_ConnHdlr {
Harald Weltea0630032018-03-20 21:09:55 +01002027 g_pars := valueof(t_def_TestHdlrPars);
2028 f_create_chan_and_exp();
Harald Weltee3bd6582018-01-31 22:51:25 +01002029 /* we should now have a COMPL_L3 at the MSC */
2030 BSSAP.receive(tr_BSSMAP_ComplL3);
2031
2032 /* send short message */
2033 RSL.send(ts_RSL_DATA_IND(g_chan_nr, valueof(ts_RslLinkID_DCCH(0)), ''O));
2034 f_bssap_expect_nothing();
2035}
2036testcase TC_err_82_short_msg() runs on test_CT {
2037 var MSC_ConnHdlr vc_conn;
2038 f_init(1, true);
2039 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02002040 vc_conn := f_start_handler(refers(f_tc_err_82_short_msg));
Harald Weltee3bd6582018-01-31 22:51:25 +01002041 vc_conn.done;
2042}
2043
2044
Harald Weltee9e02e42018-01-31 23:36:25 +01002045/* 24.008 8.4 Unknown message must trigger RR STATUS */
2046private function f_tc_err_84_unknown_msg(charstring id) runs on MSC_ConnHdlr {
2047 f_est_single_l3(ts_RRM_UL_REL('00'O));
2048 timer T := 3.0
2049 alt {
2050 [] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch tr_RRM_RR_STATUS)) {
2051 setverdict(pass);
2052 }
2053 [] BSSAP.receive { setverdict(fail, "unexpected BSSAP"); }
Harald Welte458fd372018-03-21 11:26:23 +01002054 [] T.timeout { setverdict(fail, "Timeout waiting for RR STATUS"); }
Harald Weltee9e02e42018-01-31 23:36:25 +01002055 }
2056}
2057testcase TC_err_84_unknown_msg() runs on test_CT {
2058 var MSC_ConnHdlr vc_conn;
2059 f_init(1, true);
2060 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02002061 vc_conn := f_start_handler(refers(f_tc_err_84_unknown_msg));
Harald Weltee9e02e42018-01-31 23:36:25 +01002062 vc_conn.done;
2063}
2064
Harald Welte94e0c342018-04-07 11:33:23 +02002065/* execute a "bts <0-255> trx <0-255> timeslot <0-7> " command on given Dchan */
2066private function f_vty_ts_action(charstring suffix, integer bts_nr, integer trx_nr, integer ts_nr)
2067runs on test_CT {
2068 var charstring cmd := "bts "&int2str(bts_nr)&" trx "&int2str(trx_nr)&
2069 " timeslot "&int2str(ts_nr)&" ";
2070 f_vty_transceive(BSCVTY, cmd & suffix);
2071}
2072
Harald Welte261af4b2018-02-12 21:20:39 +01002073/* execute a "bts <0-255> trx <0-255> timeslot <0-7> sub-slot <0-7>" command on given Dchan */
2074private function f_vty_ss_action(charstring suffix, integer bts_nr, integer trx_nr, RslChannelNr chan_nr)
2075runs on MSC_ConnHdlr {
2076 /* FIXME: resolve those from component-global state */
2077 var integer ts_nr := chan_nr.tn;
2078 var integer ss_nr;
2079 if (ischosen(chan_nr.u.ch0)) {
2080 ss_nr := 0;
2081 } else if (ischosen(chan_nr.u.lm)) {
2082 ss_nr := chan_nr.u.lm.sub_chan;
2083 } else if (ischosen(chan_nr.u.sdcch4)) {
2084 ss_nr := chan_nr.u.sdcch4.sub_chan;
2085 } else if (ischosen(chan_nr.u.sdcch8)) {
2086 ss_nr := chan_nr.u.sdcch8.sub_chan;
2087 } else {
2088 setverdict(fail, "Invalid ChanNr ", chan_nr);
Daniel Willmannafce8662018-07-06 23:11:32 +02002089 mtc.stop;
Harald Welte261af4b2018-02-12 21:20:39 +01002090 }
2091
2092 var charstring cmd := "bts "&int2str(bts_nr)&" trx "&int2str(trx_nr)&
2093 " timeslot "&int2str(ts_nr)&" sub-slot "&int2str(ss_nr)&" ";
2094 f_vty_transceive(BSCVTY, cmd & suffix);
2095}
2096
2097private function f_vty_handover(integer bts_nr, integer trx_nr, RslChannelNr chan_nr,
2098 integer new_bts_nr)
2099runs on MSC_ConnHdlr {
2100 f_vty_ss_action("handover " & int2str(new_bts_nr), bts_nr, trx_nr, chan_nr);
2101}
2102
2103/* intra-BSC hand-over between BTS0 and BTS1 */
2104private function f_tc_ho_int(charstring id) runs on MSC_ConnHdlr {
Harald Weltea0630032018-03-20 21:09:55 +01002105 g_pars := valueof(t_def_TestHdlrPars);
Harald Welteed848512018-05-24 22:27:58 +02002106 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
2107 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte261af4b2018-02-12 21:20:39 +01002108 const OCT8 kc := '0001020304050607'O;
2109
2110 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
2111 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
2112
Harald Weltea0630032018-03-20 21:09:55 +01002113 f_establish_fully(ass_cmd, exp_compl);
Harald Welte261af4b2018-02-12 21:20:39 +01002114
2115 var HandoverState hs := {
2116 rr_ho_cmpl_seen := false,
2117 handover_done := false,
2118 old_chan_nr := -
2119 };
2120 /* issue hand-over command on VTY */
2121 f_vty_handover(0, 0, g_chan_nr, 1);
2122 /* temporarily suspend DChan processing on BTS1 to avoid race with RSLEM_register */
2123 f_rslem_suspend(RSL1_PROC);
Philipp Maier3e2af5d2018-07-11 17:01:05 +02002124
2125 /* From the MGW perspective, a handover is is characterized by
2126 * performing one MDCX operation with the MGW. So we expect to see
2127 * one more MDCX during handover. */
2128 g_media.mgcp_conn[0].mdcx_seen_exp := g_media.mgcp_conn[0].crcx_seen_exp + 1;
2129
Harald Welte261af4b2018-02-12 21:20:39 +01002130 alt {
2131 [] as_handover(hs);
Harald Welte261af4b2018-02-12 21:20:39 +01002132 }
Philipp Maier3e2af5d2018-07-11 17:01:05 +02002133
2134 /* Check the amount of MGCP transactions is still consistant with the
2135 * test expectation */
2136 f_check_mgcp_expectations()
Harald Welte261af4b2018-02-12 21:20:39 +01002137}
2138
2139testcase TC_ho_int() runs on test_CT {
2140 var MSC_ConnHdlr vc_conn;
2141 f_init(2, true);
2142 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02002143 vc_conn := f_start_handler(refers(f_tc_ho_int));
Harald Welte261af4b2018-02-12 21:20:39 +01002144 vc_conn.done;
2145}
Harald Weltee9e02e42018-01-31 23:36:25 +01002146
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +01002147/* OS#3041: Open and close N connections in a normal fashion, and expect no
2148 * BSSMAP Reset just because of that. */
2149testcase TC_bssap_rlsd_does_not_cause_bssmap_reset() runs on test_CT {
2150 var default d;
2151 var integer i;
2152 var DchanTuple dt;
2153
2154 f_init();
2155
2156 /* Wait for initial BSSMAP Reset to pass */
2157 f_sleep(4.0);
2158
2159 d := activate(no_bssmap_reset());
2160
2161 /* Setup up a number of connections and RLSD them again from the MSC
2162 * side. In the buggy behavior, the fourth one triggers BSSMAP Reset.
2163 * Let's do it some more times for good measure. */
Harald Weltec3260d92018-06-11 17:48:16 +02002164 for (i := 0; i < 4; i := i+1) {
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +01002165 /* Since we're doing a lot of runs, give each one a fresh
2166 * T_guard from the top. */
2167 T_guard.start;
2168
2169 /* Setup a BSSAP connection and clear it right away. This is
2170 * the MSC telling the BSC about a planned release, it's not an
2171 * erratic loss of a connection. */
Harald Weltea1897182018-06-11 13:53:09 +02002172 dt := f_est_dchan(int2oct(i,1), 23+i, '00010203040506'O);
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +01002173
2174 /* MSC disconnects (RLSD). */
2175 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
2176 }
2177
2178 /* In the buggy behavior, a timeout of 2 seconds happens between above
2179 * trigger (logs "SIGTRAN connection down, reconnecting...") and the
2180 * actual BSSMAP Reset. Wait a bit longer just to make sure. */
2181 f_sleep(4.0);
2182
2183 deactivate(d);
2184 f_shutdown_helper();
2185}
Harald Welte552620d2017-12-16 23:21:36 +01002186
Neels Hofmeyr4ff93282018-03-12 04:25:35 +01002187/* OS#3041: Open and close N connections in a normal fashion, and expect no
2188 * BSSMAP Reset just because of that. Invoke the release by a BSSMAP Clear from
2189 * the MSC. */
2190testcase TC_bssmap_clear_does_not_cause_bssmap_reset() runs on test_CT {
2191 var default d;
2192 var integer i;
2193 var DchanTuple dt;
2194 var BSSAP_N_DATA_ind rx_di;
Neels Hofmeyr4ff93282018-03-12 04:25:35 +01002195 var myBSSMAP_Cause cause_val := GSM0808_CAUSE_CALL_CONTROL;
2196 var BssmapCause cause := enum2int(cause_val);
2197
2198 f_init();
2199
2200 /* Wait for initial BSSMAP Reset to pass */
2201 f_sleep(4.0);
2202
2203 d := activate(no_bssmap_reset());
2204
2205 /* Setup up a number of connections and RLSD them again from the MSC
2206 * side. In the buggy behavior, the fourth one triggers BSSMAP Reset.
2207 * Let's do it some more times for good measure. */
2208 for (i := 0; i < 8; i := i+1) {
2209 /* Since we're doing a lot of runs, give each one a fresh
2210 * T_guard from the top. */
2211 T_guard.start;
2212
2213 /* Setup a BSSAP connection and clear it right away. This is
2214 * the MSC telling the BSC about a planned release, it's not an
2215 * erratic loss of a connection. */
Harald Weltea1897182018-06-11 13:53:09 +02002216 dt := f_est_dchan(int2oct(i,1), 23+i, '00010203040506'O);
Neels Hofmeyr4ff93282018-03-12 04:25:35 +01002217
2218 /* Instruct BSC to clear channel */
2219 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
2220
2221 /* expect BSC to disable the channel */
Harald Welte641fcbe2018-06-14 10:58:35 +02002222 f_exp_chan_rel_and_clear(dt, 0);
Neels Hofmeyr4ff93282018-03-12 04:25:35 +01002223 }
2224
2225 /* In the buggy behavior, a timeout of 2 seconds happens between above
2226 * trigger (logs "SIGTRAN connection down, reconnecting...") and the
2227 * actual BSSMAP Reset. Wait a bit longer just to make sure. */
2228 f_sleep(4.0);
2229
2230 deactivate(d);
2231 f_shutdown_helper();
2232}
2233
Neels Hofmeyrfd445c32018-03-09 15:39:31 +01002234/* OS#3041: Open and close N connections in a normal fashion, and expect no
2235 * BSSMAP Reset just because of that. Close connections from the MS side with a
2236 * Release Ind on RSL. */
2237testcase TC_ms_rel_ind_does_not_cause_bssmap_reset() runs on test_CT {
2238 var default d;
2239 var integer i;
2240 var DchanTuple dt;
2241 var BSSAP_N_DATA_ind rx_di;
Neels Hofmeyrfd445c32018-03-09 15:39:31 +01002242 var integer j;
2243
2244 f_init();
2245
2246 /* Wait for initial BSSMAP Reset to pass */
2247 f_sleep(4.0);
2248
2249 d := activate(no_bssmap_reset());
2250
2251 /* Setup up a number of connections and RLSD them again from the MSC
2252 * side. In the buggy behavior, the fourth one triggers BSSMAP Reset.
2253 * Let's do it some more times for good measure. */
2254 for (i := 0; i < 8; i := i+1) {
2255 /* Since we're doing a lot of runs, give each one a fresh
2256 * T_guard from the top. */
2257 T_guard.start;
2258
2259 /* Setup a BSSAP connection and clear it right away. This is
2260 * the MSC telling the BSC about a planned release, it's not an
2261 * erratic loss of a connection. */
2262 dt := f_est_dchan('23'O, 23, '00010203040506'O);
2263
2264 /* simulate RLL REL IND */
2265 f_ipa_tx(0, ts_RSL_REL_IND(dt.rsl_chan_nr, valueof(ts_RslLinkID_DCCH(0))));
2266
2267 /* expect Clear Request on MSC side */
2268 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearRequest)) -> value rx_di;
2269
2270 /* Instruct BSC to clear channel */
2271 var BssmapCause cause := bit2int(rx_di.userData.pdu.bssmap.clearRequest.cause.causeValue);
2272 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
2273
2274 /* expect BSC to disable the channel */
Harald Welte641fcbe2018-06-14 10:58:35 +02002275 f_exp_chan_rel_and_clear(dt, 0);
Neels Hofmeyrfd445c32018-03-09 15:39:31 +01002276 }
2277
2278 /* In the buggy behavior, a timeout of 2 seconds happens between above
2279 * trigger (logs "SIGTRAN connection down, reconnecting...") and the
2280 * actual BSSMAP Reset. Wait a bit longer just to make sure. */
2281 f_sleep(4.0);
2282
2283 deactivate(d);
2284 f_shutdown_helper();
2285}
2286
Harald Welte94e0c342018-04-07 11:33:23 +02002287/***********************************************************************
2288 * IPA style dynamic PDCH
2289 ***********************************************************************/
2290
2291private function f_dyn_ipa_pdch_act(integer bts_nr, integer trx_nr, integer ts_nr,
2292 template (omit) RSL_Cause nack := omit)
2293runs on test_CT {
2294 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(ts_nr));
2295 var RSL_Message rsl_unused;
2296 /* ask BSC via VTY to activate a given IPA style chan as PDCH */
2297 f_vty_ts_action("pdch activate", bts_nr, trx_nr, ts_nr);
2298 /* expect the BSC to issue the related RSL command */
2299 rsl_unused := f_exp_ipa_rx(0, tr_RSL_IPA_PDCH_ACT(chan_nr));
2300 if (istemplatekind(nack, "omit")) {
2301 /* respond with a related acknowledgement */
2302 f_ipa_tx(0, ts_RSL_IPA_PDCH_ACT_ACK(chan_nr, ts_RSL_IE_FrameNumber(2342)));
2303 } else {
2304 f_ipa_tx(0, ts_RSL_IPA_PDCH_ACT_NACK(chan_nr, valueof(nack)));
2305 }
2306}
2307
2308private function f_dyn_ipa_pdch_deact(integer bts_nr, integer trx_nr, integer ts_nr,
2309 template (omit) RSL_Cause nack := omit)
2310runs on test_CT {
2311 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(ts_nr));
2312 var RSL_Message rsl_unused;
2313 /* ask BSC via VTY to activate a given IPA style chan as PDCH */
2314 f_vty_ts_action("pdch deactivate", bts_nr, trx_nr, ts_nr);
2315 /* expect the BSC to issue the related RSL command */
2316 rsl_unused := f_exp_ipa_rx(0, tr_RSL_IPA_PDCH_DEACT(chan_nr));
2317 if (istemplatekind(nack, "omit")) {
2318 /* respond with a related acknowledgement */
2319 f_ipa_tx(0, ts_RSL_IPA_PDCH_DEACT_ACK(chan_nr));
2320 } else {
2321 f_ipa_tx(0, ts_RSL_IPA_PDCH_DEACT_NACK(chan_nr, valueof(nack)));
2322 }
2323}
2324
2325private function f_ts_dyn_mode_get(integer bts_nr, integer trx_nr, integer ts_nr)
2326runs on test_CT return charstring {
2327 var charstring cmd, resp;
2328 cmd := "show timeslot "&int2str(bts_nr)&" "&int2str(trx_nr)&" "&int2str(ts_nr);
2329 resp := f_vty_transceive_ret(BSCVTY, cmd);
2330 return regexp(resp, "*\((*)\)*", 0);
2331}
2332
2333private function f_ts_dyn_mode_assert(integer bts_nr, integer trx_nr, integer ts_nr,
2334 template charstring exp)
2335runs on test_CT {
2336 var charstring mode := f_ts_dyn_mode_get(bts_nr, trx_nr, ts_nr);
2337 if (not match(mode, exp)) {
2338 setverdict(fail, "Unexpected TS Mode: ", mode);
Daniel Willmannafce8662018-07-06 23:11:32 +02002339 mtc.stop;
Harald Welte94e0c342018-04-07 11:33:23 +02002340 }
2341}
2342
2343private function f_ts_set_chcomb(integer bts_nr, integer trx_nr, integer ts_nr, charstring chcomb)
2344runs on test_CT {
2345 f_vty_enter_cfg_ts(BSCVTY, bts_nr, trx_nr, ts_nr);
2346 f_vty_transceive(BSCVTY, "phys_chan_config " & chcomb);
2347 f_vty_transceive(BSCVTY, "end");
2348}
2349
2350private const charstring TCHF_MODE := "TCH/F mode";
2351private const charstring TCHH_MODE := "TCH/H mode";
2352private const charstring PDCH_MODE := "PDCH mode";
2353private const charstring NONE_MODE := "NONE mode";
2354
2355/* Test IPA PDCH activation / deactivation triggered by VTY */
2356testcase TC_dyn_pdch_ipa_act_deact() runs on test_CT {
2357 var RSL_Message rsl_unused;
2358
2359 /* change Timeslot 6 before f_init() starts RSL */
2360 f_init_vty();
2361 f_ts_set_chcomb(0, 0, 6, "TCH/F_PDCH");
2362 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
2363
2364 f_init(1, false);
2365 f_sleep(1.0);
2366
2367 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(6));
2368
2369 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
2370 /* The BSC will activate the dynamic PDCH by default, so confirm that */
2371 rsl_unused := f_exp_ipa_rx(0, tr_RSL_IPA_PDCH_ACT(chan_nr));
2372 f_ipa_tx(0, ts_RSL_IPA_PDCH_ACT_ACK(chan_nr, ts_RSL_IE_FrameNumber(2342)));
2373 f_sleep(1.0);
2374 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, PDCH_MODE);
2375
2376 /* De-activate it via VTY */
2377 f_dyn_ipa_pdch_deact(0, 0, chan_nr.tn);
2378 f_sleep(1.0);
2379 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
2380
2381 /* re-activate it via VTY */
2382 f_dyn_ipa_pdch_act(0, 0, chan_nr.tn);
2383 f_sleep(1.0);
2384 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, PDCH_MODE);
2385
2386 /* and finally de-activate it again */
2387 f_dyn_ipa_pdch_deact(0, 0, chan_nr.tn);
2388 f_sleep(1.0);
2389 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
2390
Neels Hofmeyr887e8f12018-06-27 01:01:55 +02002391 /* clean up config */
2392 f_ts_set_chcomb(0, 0, 6, "PDCH");
2393
Harald Welte94e0c342018-04-07 11:33:23 +02002394 setverdict(pass);
2395}
2396
2397/* Test IPA PDCH activation NACK */
2398testcase TC_dyn_pdch_ipa_act_nack() runs on test_CT {
2399 var RSL_Message rsl_unused;
2400
2401 /* change Timeslot 6 before f_init() starts RSL */
2402 f_init_vty();
2403 f_ts_set_chcomb(0, 0, 6, "TCH/F_PDCH");
2404 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
2405
2406 f_init(1, false);
2407 f_sleep(1.0);
2408
2409 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(6));
2410
2411 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
2412 /* The BSC will activate the dynamic PDCH by default, so confirm that */
2413 rsl_unused := f_exp_ipa_rx(0, tr_RSL_IPA_PDCH_ACT(chan_nr));
2414 f_ipa_tx(0, ts_RSL_IPA_PDCH_ACT_ACK(chan_nr, ts_RSL_IE_FrameNumber(2342)));
2415 f_sleep(1.0);
2416 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, PDCH_MODE);
2417
2418 /* De-activate it via VTY */
2419 f_dyn_ipa_pdch_deact(0, 0, chan_nr.tn);
2420 f_sleep(1.0);
2421 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
2422
2423 /* re-activate it via VTY, but fail that; check BSC still assumes TCH/F mode */
2424 f_dyn_ipa_pdch_act(0, 0, chan_nr.tn, RSL_ERR_EQUIPMENT_FAIL);
2425 f_sleep(1.0);
2426 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
2427
Neels Hofmeyr887e8f12018-06-27 01:01:55 +02002428 /* clean up config */
2429 f_ts_set_chcomb(0, 0, 6, "PDCH");
2430
Harald Welte94e0c342018-04-07 11:33:23 +02002431 setverdict(pass);
2432}
2433
2434
2435/***********************************************************************
2436 * Osmocom style dynamic PDCH
2437 ***********************************************************************/
2438
2439private function f_dyn_osmo_pdch_act(integer bts_nr, integer trx_nr, integer ts_nr,
2440 template (omit) RSL_Cause nack := omit)
2441runs on test_CT {
2442 var RslChannelNr chan_nr := valueof(t_RslChanNr_PDCH(ts_nr));
2443 var RSL_Message rsl_unused;
2444 /* ask BSC via VTY to activate a given IPA style chan as PDCH */
2445 /* FIXME: no VTY command to activate Osmocom PDCH !! */
2446 /* expect the BSC to issue the related RSL command */
2447 rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT(chan_nr, ?));
2448 if (istemplatekind(nack, "omit")) {
2449 /* respond with a related acknowledgement */
2450 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, 2342));
2451 } else {
2452 f_ipa_tx(0, ts_RSL_CHAN_ACT_NACK(chan_nr, valueof(nack)));
2453 }
2454}
2455
2456private function f_dyn_osmo_pdch_deact(integer bts_nr, integer trx_nr, integer ts_nr,
2457 template (omit) RSL_Cause nack := omit)
2458runs on test_CT {
2459 var RslChannelNr chan_nr := valueof(t_RslChanNr_PDCH(ts_nr));
2460 var RSL_Message rsl_unused;
2461 /* ask BSC via VTY to activate a given IPA style chan as PDCH */
2462 /* FIXME: no VTY command to activate Osmocom PDCH !! */
2463 /* expect the BSC to issue the related RSL command */
2464 rsl_unused := f_exp_ipa_rx(0, tr_RSL_RF_CHAN_REL(chan_nr));
2465 if (istemplatekind(nack, "omit")) {
2466 /* respond with a related acknowledgement */
2467 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(chan_nr));
2468 } else {
2469 //f_ipa_tx(0, ts_RSL_RF_CHAN_REL_NACK(chan_nr, valueof(nack)));
2470 }
2471}
2472
2473/* Test Osmocom dyn PDCH activation / deactivation triggered by VTY */
2474testcase TC_dyn_pdch_osmo_act_deact() runs on test_CT {
2475 var RSL_Message rsl_unused;
2476
2477 /* change Timeslot 6 before f_init() starts RSL */
2478 f_init_vty();
2479 f_ts_set_chcomb(0, 0, 6, "TCH/F_TCH/H_PDCH");
2480 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
2481
2482 f_init(1, false);
2483 f_sleep(1.0);
2484
2485 var RslChannelNr chan_nr := valueof(t_RslChanNr_PDCH(6));
2486
2487 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, NONE_MODE);
2488 /* The BSC will activate the dynamic PDCH by default, so confirm that */
2489 rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(chan_nr, ?));
2490
2491 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, 2342));
2492 f_sleep(1.0);
2493 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, PDCH_MODE);
2494
Neels Hofmeyr887e8f12018-06-27 01:01:55 +02002495 /* clean up config */
2496 f_ts_set_chcomb(0, 0, 6, "PDCH");
2497
Harald Welte94e0c342018-04-07 11:33:23 +02002498 setverdict(pass);
2499}
2500
2501/* Test Osmocom dyn PDCH activation NACK behavior */
2502testcase TC_dyn_pdch_osmo_act_nack() runs on test_CT {
2503 var RSL_Message rsl_unused;
2504
2505 /* change Timeslot 6 before f_init() starts RSL */
2506 f_init_vty();
2507 f_ts_set_chcomb(0, 0, 6, "TCH/F_TCH/H_PDCH");
2508 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
2509
2510 f_init(1, false);
2511 f_sleep(1.0);
2512
2513 var RslChannelNr chan_nr := valueof(t_RslChanNr_PDCH(6));
2514
2515 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, NONE_MODE);
2516 /* The BSC will activate the dynamic PDCH by default, so confirm that */
2517 rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(chan_nr, ?));
2518
2519 /* NACK this activation and expect the "show timeslot" mode still to be NONE */
2520 f_ipa_tx(0, ts_RSL_CHAN_ACT_NACK(chan_nr, RSL_ERR_EQUIPMENT_FAIL));
2521 f_sleep(1.0);
2522 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, NONE_MODE);
2523
Neels Hofmeyr887e8f12018-06-27 01:01:55 +02002524 /* clean up config */
2525 f_ts_set_chcomb(0, 0, 6, "PDCH");
2526
Harald Welte94e0c342018-04-07 11:33:23 +02002527 setverdict(pass);
2528}
2529
Harald Welte0ea2d5e2018-04-07 21:40:29 +02002530/* Dyn PDCH todo:
2531 * activate OSMO as TCH/F
2532 * activate OSMO as TCH/H
2533 * does the BSC-located PCU socket get the updated INFO?
2534 * what if no PCU is connected at the time?
2535 * is the info correct on delayed PCU (re)connect?
2536 */
Harald Welte94e0c342018-04-07 11:33:23 +02002537
Harald Welte28d943e2017-11-25 15:00:50 +01002538control {
Harald Welte898113b2018-01-31 18:32:21 +01002539 /* CTRL interface testing */
Harald Welte4003d112017-12-09 22:35:39 +01002540 execute( TC_ctrl_msc_connection_status() );
Stefan Sperlingb041b3d2018-01-03 17:14:55 +01002541 execute( TC_ctrl_msc0_connection_status() );
Harald Welte96c94412017-12-09 03:12:45 +01002542 execute( TC_ctrl() );
Harald Welte898113b2018-01-31 18:32:21 +01002543
2544 /* RSL DCHAN Channel ACtivation / Deactivation */
Harald Welteae026692017-12-09 01:03:01 +01002545 execute( TC_chan_act_noreply() );
Harald Welte4003d112017-12-09 22:35:39 +01002546 execute( TC_chan_act_counter() );
Harald Welteae026692017-12-09 01:03:01 +01002547 execute( TC_chan_act_ack_noest() );
2548 execute( TC_chan_act_ack_est_ind_noreply() );
2549 execute( TC_chan_act_ack_est_ind_refused() );
Harald Welte618ef642017-12-14 14:58:20 +01002550 execute( TC_chan_act_nack() );
Harald Welte799c97b2017-12-14 17:50:30 +01002551 execute( TC_chan_exhaustion() );
Harald Welte4003d112017-12-09 22:35:39 +01002552 execute( TC_chan_rel_rll_rel_ind() );
2553 execute( TC_chan_rel_conn_fail() );
2554 execute( TC_chan_rel_hard_clear() );
Harald Welted8c36cd2017-12-09 23:05:31 +01002555 execute( TC_chan_rel_hard_rlsd() );
Harald Welte550daf92018-06-11 19:22:13 +02002556 execute( TC_chan_rel_hard_rlsd_ms_dead() );
Harald Welte85804d42017-12-10 14:11:58 +01002557 execute( TC_chan_rel_a_reset() );
Harald Welte6f521d82017-12-11 19:52:02 +01002558
Harald Weltecfe2c962017-12-15 12:09:32 +01002559 execute( TC_outbound_connect() );
Harald Welte898113b2018-01-31 18:32:21 +01002560
2561 /* Assignment related */
Harald Welte16a4adf2017-12-14 18:54:01 +01002562 execute( TC_assignment_cic_only() );
Harald Welte235ebf12017-12-15 14:18:16 +01002563 execute( TC_assignment_csd() );
2564 execute( TC_assignment_ctm() );
2565 execute( TC_assignment_sign() );
2566 execute( TC_assignment_fr_a5_0() );
2567 execute( TC_assignment_fr_a5_1() );
Harald Welte8f67d1d2018-05-25 20:38:42 +02002568 if (mp_bssap_cfg.transport == BSSAP_TRANSPORT_AoIP) {
2569 execute( TC_assignment_fr_a5_1_codec_missing() );
2570 }
Harald Welte235ebf12017-12-15 14:18:16 +01002571 execute( TC_assignment_fr_a5_3() );
2572 execute( TC_assignment_fr_a5_4() );
Harald Welte3c86ea02018-05-10 22:28:05 +02002573 execute( TC_ciph_mode_a5_0() );
2574 execute( TC_ciph_mode_a5_1() );
2575 execute( TC_ciph_mode_a5_3() );
Harald Welte16a4adf2017-12-14 18:54:01 +01002576
Harald Welte60aa5762018-03-21 19:33:13 +01002577 execute( TC_assignment_codec_fr() );
2578 execute( TC_assignment_codec_hr() );
2579 execute( TC_assignment_codec_efr() );
2580 execute( TC_assignment_codec_amr_f() );
2581 execute( TC_assignment_codec_amr_h() );
2582
Harald Welte898113b2018-01-31 18:32:21 +01002583 /* RLL Establish Indication on inactive DCHAN / SAPI */
Harald Welte5cd20ed2017-12-13 21:03:20 +01002584 execute( TC_rll_est_ind_inact_lchan() );
2585 execute( TC_rll_est_ind_inval_sapi1() );
2586 execute( TC_rll_est_ind_inval_sapi3() );
2587 execute( TC_rll_est_ind_inval_sacch() );
2588
Harald Welte898113b2018-01-31 18:32:21 +01002589 /* Paging related tests */
Harald Welte6f521d82017-12-11 19:52:02 +01002590 execute( TC_paging_imsi_nochan() );
2591 execute( TC_paging_tmsi_nochan() );
2592 execute( TC_paging_tmsi_any() );
2593 execute( TC_paging_tmsi_sdcch() );
2594 execute( TC_paging_tmsi_tch_f() );
2595 execute( TC_paging_tmsi_tch_hf() );
2596 execute( TC_paging_imsi_nochan_cgi() );
2597 execute( TC_paging_imsi_nochan_lac_ci() );
2598 execute( TC_paging_imsi_nochan_ci() );
2599 execute( TC_paging_imsi_nochan_lai() );
2600 execute( TC_paging_imsi_nochan_lac() );
2601 execute( TC_paging_imsi_nochan_all() );
Harald Welte751d3eb2018-01-31 15:51:06 +01002602 execute( TC_paging_imsi_nochan_plmn_lac_rnc() );
2603 execute( TC_paging_imsi_nochan_rnc() );
2604 execute( TC_paging_imsi_nochan_lac_rnc() );
2605 execute( TC_paging_imsi_nochan_lacs() );
2606 execute( TC_paging_imsi_nochan_lacs_empty() );
Stefan Sperling049a86e2018-03-20 15:51:00 +01002607 execute( TC_paging_imsi_nochan_cgi_unknown_cid() );
Harald Welte10985002017-12-12 09:29:15 +01002608 execute( TC_paging_imsi_a_reset() );
Harald Weltee65d40e2017-12-13 00:09:06 +01002609 execute( TC_paging_imsi_load() );
Philipp Maier779a7922018-02-16 11:00:37 +01002610 execute( TC_paging_counter() );
Harald Welte4e9b9cc2017-12-14 18:31:02 +01002611
2612 execute( TC_rsl_drop_counter() );
Stefan Sperling830dc9d2018-02-12 21:08:28 +01002613 execute( TC_rsl_unknown_unit_id() );
2614
2615 execute( TC_oml_unknown_unit_id() );
Harald Welte898113b2018-01-31 18:32:21 +01002616
2617 execute( TC_classmark() );
2618 execute( TC_unsol_ass_fail() );
Harald Welteea99a002018-01-31 20:46:43 +01002619 execute( TC_unsol_ass_compl() );
Harald Weltefbf9b5e2018-01-31 20:41:23 +01002620 execute( TC_unsol_ho_fail() );
Harald Weltee3bd6582018-01-31 22:51:25 +01002621 execute( TC_err_82_short_msg() );
Harald Weltee9e02e42018-01-31 23:36:25 +01002622 execute( TC_err_84_unknown_msg() );
Harald Welte261af4b2018-02-12 21:20:39 +01002623 execute( TC_ho_int() );
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +01002624
2625 execute( TC_bssap_rlsd_does_not_cause_bssmap_reset() );
Neels Hofmeyr4ff93282018-03-12 04:25:35 +01002626 execute( TC_bssmap_clear_does_not_cause_bssmap_reset() );
Neels Hofmeyrfd445c32018-03-09 15:39:31 +01002627 execute( TC_ms_rel_ind_does_not_cause_bssmap_reset() );
Harald Welte94e0c342018-04-07 11:33:23 +02002628
2629 execute( TC_dyn_pdch_ipa_act_deact() );
2630 execute( TC_dyn_pdch_ipa_act_nack() );
2631 execute( TC_dyn_pdch_osmo_act_deact() );
2632 execute( TC_dyn_pdch_osmo_act_nack() );
Harald Welte99f3ca02018-06-14 13:40:29 +02002633
2634 /* at bottom as they might crash OsmoBSC before OS#3182 is fixed */
2635 execute( TC_early_conn_fail() );
2636 execute( TC_late_conn_fail() );
2637
Harald Welte28d943e2017-11-25 15:00:50 +01002638}
2639
2640}