blob: 2f99bcb2c57efff4e717628c2626cf5e6f0664cb [file] [log] [blame]
Harald Welte28d943e2017-11-25 15:00:50 +01001module BSC_Tests {
2
Harald Welte21b46bd2017-12-17 19:46:32 +01003/* Integration Tests for OsmoBSC
Harald Weltea0630032018-03-20 21:09:55 +01004 * (C) 2017-2018 by Harald Welte <laforge@gnumonks.org>
Harald Welte21b46bd2017-12-17 19:46:32 +01005 * All rights reserved.
6 *
7 * Released under the terms of GNU General Public License, Version 2 or
8 * (at your option) any later version.
9 *
10 * This test suite tests OsmoBSC while emulating both multiple BTS + MS as
11 * well as the MSC. See README for more details.
12 *
13 * There are test cases that run in so-called 'handler mode' and test cases
14 * that run directly on top of the BSSAP and RSL CodecPorts. The "handler mode"
15 * tests abstract the multiplexing/demultiplexing of multiple SCCP connections
16 * and/or RSL channels and are hence suitable for higher-level test cases, while
17 * the "raw" tests directly on top of the CodecPorts are more suitable for lower-
18 * level testing.
19 */
20
Harald Welte4003d112017-12-09 22:35:39 +010021import from General_Types all;
Harald Welte28d943e2017-11-25 15:00:50 +010022import from Osmocom_Types all;
Harald Welteae026692017-12-09 01:03:01 +010023import from GSM_Types all;
Harald Welte28d943e2017-11-25 15:00:50 +010024import from IPL4asp_Types all;
25
Harald Welte6f521d82017-12-11 19:52:02 +010026import from BSSAP_Types all;
Harald Welteae026692017-12-09 01:03:01 +010027import from BSSAP_Adapter all;
28import from BSSAP_CodecPort all;
29import from BSSMAP_Templates all;
Harald Welte28d943e2017-11-25 15:00:50 +010030import from IPA_Emulation all;
Stefan Sperling830dc9d2018-02-12 21:08:28 +010031import from IPA_CodecPort all;
Harald Welteae026692017-12-09 01:03:01 +010032import from IPA_Types all;
33import from RSL_Types all;
Harald Welte624f9632017-12-16 19:26:04 +010034import from RSL_Emulation all;
Daniel Willmann191e0d92018-01-17 12:44:35 +010035import from MGCP_Emulation all;
Harald Welte28d943e2017-11-25 15:00:50 +010036
Harald Welte96c94412017-12-09 03:12:45 +010037import from Osmocom_CTRL_Functions all;
Harald Weltea5d2ab22017-12-09 14:21:42 +010038import from Osmocom_CTRL_Types all;
Harald Welteffe55fc2018-01-17 22:39:54 +010039import from Osmocom_CTRL_Adapter all;
Harald Welte96c94412017-12-09 03:12:45 +010040
Harald Weltebc03c762018-02-12 18:09:38 +010041import from Osmocom_VTY_Functions all;
42import from TELNETasp_PortType all;
43
Harald Welte6f521d82017-12-11 19:52:02 +010044import from MobileL3_CommonIE_Types all;
Harald Weltee3bd6582018-01-31 22:51:25 +010045import from MobileL3_Types all;
Harald Welte6f521d82017-12-11 19:52:02 +010046import from L3_Templates all;
47import from GSM_RR_Types all;
48
Neels Hofmeyr4ff93282018-03-12 04:25:35 +010049import from BSSMAP_Templates all;
50
Harald Welte5d1a2202017-12-13 19:51:29 +010051const integer NUM_BTS := 3;
Harald Welteae026692017-12-09 01:03:01 +010052const float T3101_MAX := 12.0;
Harald Welte28d943e2017-11-25 15:00:50 +010053
Harald Welte799c97b2017-12-14 17:50:30 +010054/* make sure to sync this with the osmo-bts.cfg you're using */
Philipp Maiercb6cc482018-03-26 13:08:00 +020055const integer NUM_TCHH_PER_BTS := 2;
56const integer NUM_TCHF_PER_BTS := 4;
Harald Weltedd8cbf32018-01-28 12:07:52 +010057const integer NUM_SDCCH_PER_BTS := 4;
Harald Welte799c97b2017-12-14 17:50:30 +010058
Harald Welte4003d112017-12-09 22:35:39 +010059
Harald Welte21b46bd2017-12-17 19:46:32 +010060/* per-BTS state which we keep */
Harald Welte96c94412017-12-09 03:12:45 +010061type record BTS_State {
Harald Welte21b46bd2017-12-17 19:46:32 +010062 /* component reference to the IPA_Client component used for RSL */
Harald Weltea5d2ab22017-12-09 14:21:42 +010063 IPA_Client rsl
Harald Welte96c94412017-12-09 03:12:45 +010064}
65
Harald Weltea4ca4462018-02-09 00:17:14 +010066type component test_CT extends CTRL_Adapter_CT {
Harald Welte21b46bd2017-12-17 19:46:32 +010067 /* Array of per-BTS state */
Harald Welte96c94412017-12-09 03:12:45 +010068 var BTS_State bts[NUM_BTS];
Harald Welte89ab1912018-02-23 18:56:29 +010069 /* RSL common Channel Port (for RSL_Emulation) */
70 port RSL_CCHAN_PT RSL_CCHAN[NUM_BTS];
Harald Welte21b46bd2017-12-17 19:46:32 +010071 /* array of per-BTS RSL test ports */
Harald Welteae026692017-12-09 01:03:01 +010072 port IPA_RSL_PT IPA_RSL[NUM_BTS];
Stefan Sperling830dc9d2018-02-12 21:08:28 +010073 port IPA_CODEC_PT IPA; /* Required for compilation of TC_rsl_unknown_unit_id() */
Harald Weltea5d2ab22017-12-09 14:21:42 +010074
Daniel Willmann191e0d92018-01-17 12:44:35 +010075 var MGCP_Emulation_CT vc_MGCP;
Harald Weltebc03c762018-02-12 18:09:38 +010076 port TELNETasp_PT BSCVTY;
Daniel Willmann191e0d92018-01-17 12:44:35 +010077
Harald Weltea4ca4462018-02-09 00:17:14 +010078 var BSSAP_Adapter g_bssap;
79 /* for old legacy-tests only */
80 port BSSAP_CODEC_PT BSSAP;
81
Harald Welte21b46bd2017-12-17 19:46:32 +010082 /* are we initialized yet */
Harald Welte28d943e2017-11-25 15:00:50 +010083 var boolean g_initialized := false;
Harald Welte21b46bd2017-12-17 19:46:32 +010084
85 /* global test case guard timer */
Harald Welteae026692017-12-09 01:03:01 +010086 timer T_guard := 30.0;
87
Harald Welte28d943e2017-11-25 15:00:50 +010088}
89
90modulepar {
Harald Welte21b46bd2017-12-17 19:46:32 +010091 /* IP address at which the BSC can be reached */
Harald Welte696ddb62017-12-08 14:01:43 +010092 charstring mp_bsc_ip := "127.0.0.1";
Stefan Sperling830dc9d2018-02-12 21:08:28 +010093 /* port number to which to establish the IPA OML connections */
94 integer mp_bsc_oml_port := 3002;
Harald Welte21b46bd2017-12-17 19:46:32 +010095 /* port number to which to establish the IPA RSL connections */
Harald Welte696ddb62017-12-08 14:01:43 +010096 integer mp_bsc_rsl_port := 3003;
Harald Welte21b46bd2017-12-17 19:46:32 +010097 /* port number to which to establish the IPA CTRL connection */
Harald Welte96c94412017-12-09 03:12:45 +010098 integer mp_bsc_ctrl_port := 4249;
Daniel Willmann191e0d92018-01-17 12:44:35 +010099 /* IP address at which the test binds */
100 charstring mp_test_ip := "127.0.0.1";
Harald Weltea4ca4462018-02-09 00:17:14 +0100101
102 BSSAP_Configuration mp_bssap_cfg := {
Harald Welte7ef51aa2018-04-16 19:16:01 +0200103 transport := BSSAP_TRANSPORT_AoIP,
Harald Weltea4ca4462018-02-09 00:17:14 +0100104 sccp_service_type := "mtp3_itu",
105 sctp_addr := { 23905, "127.0.0.1", 2905, "127.0.0.1" },
106 own_pc := 185,
107 own_ssn := 254,
108 peer_pc := 187,
109 peer_ssn := 254,
Philipp Maier38d68942018-03-29 15:38:09 +0200110 sio := '83'O,
111 rctx := 0
Harald Weltea4ca4462018-02-09 00:17:14 +0100112 };
113}
114
Philipp Maier282ca4b2018-02-27 17:17:00 +0100115private function f_shutdown_helper() runs on test_CT {
Harald Welte12055472018-03-17 20:10:08 +0100116 for (var integer i := 0; i < NUM_BTS; i := i+1) {
117 if (isbound(bts[i]) and isbound(bts[i].rsl)) {
118 f_ipa_rsl_stop(bts[i].rsl);
119 }
120 }
121 f_ipa_ctrl_stop();
Philipp Maier282ca4b2018-02-27 17:17:00 +0100122 all port.stop;
123 setverdict(pass);
124}
125
Harald Weltea4ca4462018-02-09 00:17:14 +0100126private function f_legacy_bssap_reset() runs on test_CT {
127 var BSSAP_N_UNITDATA_ind ud_ind;
128 timer T := 5.0;
129 BSSAP.send(ts_BSSAP_UNITDATA_req(g_bssap.sccp_addr_peer, g_bssap.sccp_addr_own, ts_BSSMAP_Reset(0)));
130 T.start;
131 alt {
132 [] BSSAP.receive(tr_BSSAP_UNITDATA_ind(g_bssap.sccp_addr_own, g_bssap.sccp_addr_peer, tr_BSSMAP_ResetAck)) {
133 log("Received RESET-ACK in response to RESET, we're ready to go!");
134 }
135 [] BSSAP.receive(tr_BSSAP_UNITDATA_ind(?, ?, tr_BSSMAP_Reset)) -> value ud_ind {
136 log("Respoding to inbound RESET with RESET-ACK");
137 BSSAP.send(ts_BSSAP_UNITDATA_req(ud_ind.callingAddress, ud_ind.calledAddress,
138 ts_BSSMAP_ResetAck));
139 repeat;
140 }
141 [] BSSAP.receive { repeat; }
142 [] T.timeout { setverdict(fail, "Waiting for RESET-ACK after sending RESET"); }
143 }
Harald Welte28d943e2017-11-25 15:00:50 +0100144}
145
Harald Welteae026692017-12-09 01:03:01 +0100146type record IPA_Client {
Harald Welte21b46bd2017-12-17 19:46:32 +0100147 /* IPA Emulation component reference */
Harald Welteae026692017-12-09 01:03:01 +0100148 IPA_Emulation_CT vc_IPA,
Harald Welte21b46bd2017-12-17 19:46:32 +0100149 /* Unit-ID and other CCM parameters to use for IPA client emulation */
Harald Welteae026692017-12-09 01:03:01 +0100150 IPA_CCM_Parameters ccm_pars,
Harald Welte21b46bd2017-12-17 19:46:32 +0100151 /* String identifier for this IPA Client */
Harald Welte624f9632017-12-16 19:26:04 +0100152 charstring id,
Harald Welte21b46bd2017-12-17 19:46:32 +0100153 /* Associated RSL Emulation Component (if any). Only used in "Handler mode" */
Harald Welte624f9632017-12-16 19:26:04 +0100154 RSL_Emulation_CT vc_RSL optional
Harald Welte28d943e2017-11-25 15:00:50 +0100155}
156
Harald Welte21b46bd2017-12-17 19:46:32 +0100157/*! Start the IPA/RSL related bits for one IPA_Client.
158 * \param clnt IPA_Client for which to establish
159 * \param bsc_host IP address / hostname of the BSC
160 * \param bsc_port TCP port number of the BSC
161 * \param i number identifying this BTS
162 * \param handler_mode Start an RSL_Emulation_CT component (true) or not (false) */
Harald Welte624f9632017-12-16 19:26:04 +0100163function f_ipa_rsl_start(inout IPA_Client clnt, charstring bsc_host, PortNumber bsc_port, integer i,
164 boolean handler_mode := false)
Harald Welte28d943e2017-11-25 15:00:50 +0100165runs on test_CT {
Harald Welteae026692017-12-09 01:03:01 +0100166 timer T := 10.0;
167
Harald Welte96c94412017-12-09 03:12:45 +0100168 clnt.id := "IPA" & int2str(i) & "-RSL";
Harald Welteae026692017-12-09 01:03:01 +0100169 clnt.vc_IPA := IPA_Emulation_CT.create(clnt.id & "-IPA");
170 clnt.ccm_pars := c_IPA_default_ccm_pars;
171 clnt.ccm_pars.name := "Osmocom TTCN-3 BTS Simulator";
172 clnt.ccm_pars.unit_id := int2str(1234+i) & "/0/0";
Harald Welte624f9632017-12-16 19:26:04 +0100173 if (handler_mode) {
174 clnt.vc_RSL := RSL_Emulation_CT.create(clnt.id & "-RSL");
Harald Welte89ab1912018-02-23 18:56:29 +0100175 connect(clnt.vc_RSL:CCHAN_PT, self:RSL_CCHAN[i]);
Harald Welte624f9632017-12-16 19:26:04 +0100176 }
Harald Welteae026692017-12-09 01:03:01 +0100177
178 map(clnt.vc_IPA:IPA_PORT, system:IPA_CODEC_PT);
Harald Welte624f9632017-12-16 19:26:04 +0100179 if (handler_mode) {
180 connect(clnt.vc_IPA:IPA_RSL_PORT, clnt.vc_RSL:IPA_PT);
181 } else {
182 connect(clnt.vc_IPA:IPA_RSL_PORT, self:IPA_RSL[i]);
183 }
Harald Welteae026692017-12-09 01:03:01 +0100184
Harald Welte5d1a2202017-12-13 19:51:29 +0100185 clnt.vc_IPA.start(IPA_Emulation.main_client(bsc_host, bsc_port, "", 10000+i, clnt.ccm_pars));
Harald Welte624f9632017-12-16 19:26:04 +0100186 if (handler_mode) {
187 clnt.vc_RSL.start(RSL_Emulation.main());
188 return;
189 }
Harald Welteae026692017-12-09 01:03:01 +0100190
191 /* wait for IPA RSL link to connect and send ID ACK */
192 T.start;
193 alt {
194 [] IPA_RSL[i].receive(ASP_IPA_Event:{up_down := ASP_IPA_EVENT_ID_ACK}) {
195 T.stop;
196 IPA_RSL[i].send(ts_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0,ts_RSL_PAGING_LOAD_IND(23)));
197 }
Harald Welte60e823a2017-12-10 14:10:59 +0100198 [] IPA_RSL[i].receive(ASP_IPA_Event:?) { repeat }
Harald Welteae026692017-12-09 01:03:01 +0100199 [] IPA_RSL[i].receive { repeat }
200 [] T.timeout {
Harald Welte96c94412017-12-09 03:12:45 +0100201 setverdict(fail, "Timeout RSL waiting for ASP_IPA_EVENT_ID_ACK");
Harald Welteae026692017-12-09 01:03:01 +0100202 self.stop;
203 }
204 }
205}
206
Harald Welte12055472018-03-17 20:10:08 +0100207function f_ipa_rsl_stop(inout IPA_Client clnt) runs on test_CT {
208 if (not isbound(clnt) or not isbound(clnt.vc_IPA)) {
209 return;
210 }
211 clnt.vc_IPA.stop;
212 if (isbound(clnt.vc_RSL)) {
213 clnt.vc_RSL.stop;
214 }
215}
216
Harald Welte21b46bd2017-12-17 19:46:32 +0100217/* Wait for the OML connection to be brought up by the external osmo-bts-omldummy */
Harald Weltea5d2ab22017-12-09 14:21:42 +0100218function f_wait_oml(integer bts_nr, charstring status, float secs_max) runs on test_CT {
219 timer T := secs_max;
220 T.start;
221 while (true) {
222 if (f_ctrl_get_bts(IPA_CTRL, bts_nr, "oml-connection-state") == status) {
223 T.stop;
Harald Weltebd868bd2017-12-10 18:28:40 +0100224 /* the 'degraded' state exists from OML connection time, and we have to wait
225 * until all MO's are initialized */
226 T.start(1.0);
227 T.timeout;
Harald Weltea5d2ab22017-12-09 14:21:42 +0100228 return;
229 }
Harald Weltef0d6ac62017-12-17 17:02:21 +0100230 f_sleep(0.1);
Harald Weltea5d2ab22017-12-09 14:21:42 +0100231 if (not T.running) {
232 setverdict(fail, "Timeout waiting for oml-connection-state ", status);
233 self.stop;
234 }
235 }
236}
237
Harald Welte21b46bd2017-12-17 19:46:32 +0100238/* global altstep for global guard timer; also takes care of responding RESET witH RESET-ACK */
Harald Welteae026692017-12-09 01:03:01 +0100239altstep as_Tguard() runs on test_CT {
Harald Welte60e823a2017-12-10 14:10:59 +0100240 var BSSAP_N_UNITDATA_ind ud_ind;
Neels Hofmeyrcc3f76a2018-03-12 01:43:25 +0100241 [] T_guard.timeout {
242 setverdict(fail, "Timeout of T_guard");
243 self.stop;
244 }
Harald Welte60e823a2017-12-10 14:10:59 +0100245 /* always respond with RESET ACK to RESET */
246 [] BSSAP.receive(tr_BSSAP_UNITDATA_ind(?, ?, tr_BSSMAP_Reset)) -> value ud_ind {
247 BSSAP.send(ts_BSSAP_UNITDATA_req(ud_ind.callingAddress, ud_ind.calledAddress,
248 ts_BSSMAP_ResetAck));
Harald Welte69c1c262017-12-13 21:02:08 +0100249 repeat;
Harald Welte60e823a2017-12-10 14:10:59 +0100250 }
Harald Welte28d943e2017-11-25 15:00:50 +0100251}
252
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +0100253altstep no_bssmap_reset() runs on test_CT {
254 [] BSSAP.receive(tr_BSSAP_UNITDATA_ind(?, ?, tr_BSSMAP_Reset)) {
255 setverdict(fail, "unexpected BSSMAP Reset");
256 self.stop;
257 }
258}
259
Daniel Willmann191e0d92018-01-17 12:44:35 +0100260function f_init_mgcp(charstring id) runs on test_CT {
261 id := id & "-MGCP";
262
263 var MGCPOps ops := {
264 create_cb := refers(MGCP_Emulation.ExpectedCreateCallback),
265 unitdata_cb := refers(MGCP_Emulation.DummyUnitdataCallback)
266 };
267 var MGCP_conn_parameters mgcp_pars := {
268 callagent_ip := mp_bsc_ip,
Harald Welte9e4273e2018-01-29 22:01:22 +0100269 callagent_udp_port := -1,
Daniel Willmann191e0d92018-01-17 12:44:35 +0100270 mgw_ip := mp_test_ip,
271 mgw_udp_port := 2427
272 };
273
274 vc_MGCP := MGCP_Emulation_CT.create(id);
275 vc_MGCP.start(MGCP_Emulation.main(ops, mgcp_pars, id));
276}
277
Harald Welte94e0c342018-04-07 11:33:23 +0200278private function f_init_vty(charstring id := "foo") runs on test_CT {
279 if (BSCVTY.checkstate("Mapped")) {
280 /* skip initialization if already executed once */
281 return;
282 }
Harald Weltebc03c762018-02-12 18:09:38 +0100283 map(self:BSCVTY, system:BSCVTY);
284 f_vty_set_prompts(BSCVTY);
285 f_vty_transceive(BSCVTY, "enable");
286}
287
Harald Welte21b46bd2017-12-17 19:46:32 +0100288/* global initialization function
289 * \param nr_bts Number of BTSs we should start/bring up
290 * \param handler_mode Start an RSL_Emulation_CT component (true) or not (false) */
Harald Welte89d42e82017-12-17 16:42:41 +0100291function f_init(integer nr_bts := NUM_BTS, boolean handler_mode := false) runs on test_CT {
Harald Welte28d943e2017-11-25 15:00:50 +0100292 var integer i;
Harald Welte28d943e2017-11-25 15:00:50 +0100293
Harald Welteae026692017-12-09 01:03:01 +0100294 if (g_initialized) {
295 return;
Harald Welte28d943e2017-11-25 15:00:50 +0100296 }
Harald Welteae026692017-12-09 01:03:01 +0100297 g_initialized := true;
298
299 /* Call a function of our 'parent component' BSSAP_Adapter_CT to start the
300 * MSC-side BSSAP emulation */
Harald Welte67089ee2018-01-17 22:19:03 +0100301 if (handler_mode) {
Harald Weltea4ca4462018-02-09 00:17:14 +0100302 f_bssap_init(g_bssap, mp_bssap_cfg, "VirtMSC", MSC_BssmapOps);
Harald Welte4bcbd172018-05-27 19:47:44 +0200303 f_bssap_start(g_bssap);
Harald Welte67089ee2018-01-17 22:19:03 +0100304 } else {
Harald Weltea4ca4462018-02-09 00:17:14 +0100305 f_bssap_init(g_bssap, mp_bssap_cfg, "VirtMSC", omit);
306 connect(self:BSSAP, g_bssap.vc_SCCP:SCCP_SP_PORT);
Harald Welte4bcbd172018-05-27 19:47:44 +0200307 f_bssap_start(g_bssap);
Harald Weltea4ca4462018-02-09 00:17:14 +0100308 f_legacy_bssap_reset();
Harald Welte67089ee2018-01-17 22:19:03 +0100309 }
Harald Welted5833a82018-05-27 16:52:56 +0200310
Harald Welteffe55fc2018-01-17 22:39:54 +0100311 f_ipa_ctrl_start(mp_bsc_ip, mp_bsc_ctrl_port);
Harald Welte28d943e2017-11-25 15:00:50 +0100312
Daniel Willmann191e0d92018-01-17 12:44:35 +0100313 f_init_mgcp("VirtMSC");
Harald Weltebc03c762018-02-12 18:09:38 +0100314 f_init_vty("VirtMSC");
Daniel Willmann191e0d92018-01-17 12:44:35 +0100315
Harald Welte89d42e82017-12-17 16:42:41 +0100316 for (i := 0; i < nr_bts; i := i+1) {
Harald Weltea5d2ab22017-12-09 14:21:42 +0100317 /* wait until osmo-bts-omldummy has respawned */
318 f_wait_oml(i, "degraded", 5.0);
319 /* start RSL connection */
Harald Welte624f9632017-12-16 19:26:04 +0100320 f_ipa_rsl_start(bts[i].rsl, mp_bsc_ip, mp_bsc_rsl_port, i, handler_mode);
Harald Weltea5d2ab22017-12-09 14:21:42 +0100321 /* wait until BSC tells us "connected" */
322 f_wait_oml(i, "connected", 5.0);
Harald Welte696ddb62017-12-08 14:01:43 +0100323 }
324
Harald Welteae026692017-12-09 01:03:01 +0100325 T_guard.start;
326 activate(as_Tguard());
Harald Welte28d943e2017-11-25 15:00:50 +0100327}
328
Harald Welte21b46bd2017-12-17 19:46:32 +0100329/* expect to receive a RSL message matching a specified templaten on a given BTS / stream */
Harald Welteae026692017-12-09 01:03:01 +0100330function f_exp_ipa_rx(integer bts_nr, template RSL_Message t_rx, float t_secs := 2.0, IpaStreamId sid := IPAC_PROTO_RSL_TRX0)
331runs on test_CT return RSL_Message {
332 var ASP_RSL_Unitdata rx_rsl_ud;
333 timer T := t_secs;
334
335 T.start;
336 alt {
337 [] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(sid, t_rx)) -> value rx_rsl_ud {
338 T.stop;
339 }
340 [] IPA_RSL[bts_nr].receive { repeat; }
Harald Welteb2917702017-12-10 15:48:52 +0100341 [] T.timeout {
342 setverdict(fail, "Timeout expecting ", t_rx);
343 self.stop;
344 }
Harald Welteae026692017-12-09 01:03:01 +0100345 }
346 return rx_rsl_ud.rsl;
347}
348
Harald Welte21b46bd2017-12-17 19:46:32 +0100349/* helper function to transmit RSL on a given BTS/stream */
Harald Welteae026692017-12-09 01:03:01 +0100350function f_ipa_tx(integer bts_nr, template RSL_Message t_tx, IpaStreamId sid := IPAC_PROTO_RSL_TRX0)
351runs on test_CT {
352 IPA_RSL[bts_nr].send(ts_ASP_RSL_UD(sid, t_tx));
353}
354
355
Harald Welte4003d112017-12-09 22:35:39 +0100356/* verify we get a CHAN_ACT after CHAN RQD */
Harald Welteae026692017-12-09 01:03:01 +0100357testcase TC_chan_act_noreply() runs on test_CT {
358 var BSSAP_N_UNITDATA_ind ud_ind;
Harald Welte930d0a72018-03-22 22:08:40 +0100359 var RSL_Message rsl_unused;
Harald Welte28d943e2017-11-25 15:00:50 +0100360
Harald Welte89d42e82017-12-17 16:42:41 +0100361 f_init(1);
Harald Welte28d943e2017-11-25 15:00:50 +0100362
Harald Welteae026692017-12-09 01:03:01 +0100363 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 +0100364 rsl_unused := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
Harald Welteae026692017-12-09 01:03:01 +0100365 setverdict(pass);
Harald Welte28d943e2017-11-25 15:00:50 +0100366}
367
Harald Welte4003d112017-12-09 22:35:39 +0100368/* verify if the "chreq:total" counter increments as expected */
369testcase TC_chan_act_counter() runs on test_CT {
370 var BSSAP_N_UNITDATA_ind ud_ind;
371 var integer chreq_total;
Harald Welte930d0a72018-03-22 22:08:40 +0100372 var RSL_Message rsl_unused;
Harald Welte4003d112017-12-09 22:35:39 +0100373
Harald Welte89d42e82017-12-17 16:42:41 +0100374 f_init(1);
Harald Welte4003d112017-12-09 22:35:39 +0100375
376 chreq_total := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:total");
377 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 +0100378 rsl_unused := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
Harald Welte4003d112017-12-09 22:35:39 +0100379 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:total", chreq_total+1);
380
381 setverdict(pass);
382}
383
Harald Welteae026692017-12-09 01:03:01 +0100384/* CHAN RQD -> CHAN ACT -> CHAN ACT ACK -> RF CHAN REL */
385testcase TC_chan_act_ack_noest() runs on test_CT {
386 var RSL_Message rx_rsl;
387
Harald Welte89d42e82017-12-17 16:42:41 +0100388 f_init(1);
Harald Welteae026692017-12-09 01:03:01 +0100389
390 /* Send CHAN RQD and wait for allocation; acknowledge it */
Harald Welted6939652017-12-13 21:02:46 +0100391 var RslChannelNr chan_nr := f_chreq_act_ack();
Harald Welteae026692017-12-09 01:03:01 +0100392
393 /* expect BSC to disable the channel again if there's no RLL EST IND */
394 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL), T3101_MAX);
395
396 setverdict(pass);
397}
398
399/* Test behavior if MSC never answers to CR */
400testcase TC_chan_act_ack_est_ind_noreply() runs on test_CT {
Harald Weltef77aef62018-01-28 15:35:42 +0100401 var RslLinkId main_dcch := valueof(ts_RslLinkID_DCCH(0));
402 var IpaStreamId sid := IPAC_PROTO_RSL_TRX0;
Harald Welteae026692017-12-09 01:03:01 +0100403 var RSL_Message rx_rsl;
Harald Weltef77aef62018-01-28 15:35:42 +0100404 var ASP_RSL_Unitdata rx_rsl_ud;
Harald Welteae026692017-12-09 01:03:01 +0100405
Harald Welte89d42e82017-12-17 16:42:41 +0100406 f_init(1);
Harald Welteae026692017-12-09 01:03:01 +0100407
408 /* Send CHAN RQD and wait for allocation; acknowledge it */
Harald Welted6939652017-12-13 21:02:46 +0100409 var RslChannelNr chan_nr := f_chreq_act_ack();
Harald Welteae026692017-12-09 01:03:01 +0100410
411 var octetstring l3 := '00010203040506'O
412 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
413
414 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3)));
415
416 /* expect BSC to disable the channel again if there's no response from MSC */
Harald Weltef77aef62018-01-28 15:35:42 +0100417 /* MS waits 20s (T3210) at LU; 10s (T3230) at CM SERV REQ and 5s (T3220) AT detach */
418 IPA_RSL[0].clear;
419 alt {
420 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(sid, tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL))) -> value rx_rsl_ud { }
421 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(sid, tr_RSL_REL_REQ(chan_nr, ?))) -> value rx_rsl_ud {
422 f_ipa_tx(0, ts_RSL_REL_CONF(chan_nr, main_dcch));
423 repeat;
424 }
425 }
Harald Welteae026692017-12-09 01:03:01 +0100426
427 setverdict(pass);
428}
429
430/* Test behavior if MSC answers with CREF to CR */
431testcase TC_chan_act_ack_est_ind_refused() runs on test_CT {
432 var BSSAP_N_CONNECT_ind rx_c_ind;
433 var RSL_Message rx_rsl;
434
Harald Welte89d42e82017-12-17 16:42:41 +0100435 f_init(1);
Harald Welteae026692017-12-09 01:03:01 +0100436
437 /* Send CHAN RQD and wait for allocation; acknowledge it */
Harald Welted6939652017-12-13 21:02:46 +0100438 var RslChannelNr chan_nr := f_chreq_act_ack();
Harald Welteae026692017-12-09 01:03:01 +0100439
440 var octetstring l3 := '00010203040506'O
441 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
442
443 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) -> value rx_c_ind;
444 BSSAP.send(ts_BSSAP_DISC_req(rx_c_ind.connectionId, 0));
445
446 /* expect BSC to disable the channel */
Harald Welte725844b2018-01-28 16:18:32 +0100447 f_expect_chan_rel(0, chan_nr);
Harald Welteae026692017-12-09 01:03:01 +0100448 setverdict(pass);
449}
450
Harald Welte618ef642017-12-14 14:58:20 +0100451/* CHAN RQD -> CHAN ACT -> CHAN ACT NACK -> RF CHAN REL */
452testcase TC_chan_act_nack() runs on test_CT {
453 var RSL_Message rx_rsl;
454 var integer chact_nack;
455
Harald Welte89d42e82017-12-17 16:42:41 +0100456 f_init(1);
Harald Welte618ef642017-12-14 14:58:20 +0100457
458 chact_nack := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "chan_act:nack");
459
460 f_ipa_tx(0, ts_RSL_CHAN_RQD('33'O, 33));
461 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
462 var RslChannelNr chan_nr := rx_rsl.ies[0].body.chan_nr;
463
464 f_ipa_tx(0, ts_RSL_CHAN_ACT_NACK(chan_nr, RSL_ERR_EQUIPMENT_FAIL));
465
466 /* wait for some time to hope the NACK arrives before the CTRL GET below */
467 f_sleep(0.5);
468
469 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "chan_act:nack", chact_nack+1);
470
471 setverdict(pass);
472}
473
Harald Welte799c97b2017-12-14 17:50:30 +0100474/* Test for channel exhaustion due to RACH overload */
475testcase TC_chan_exhaustion() runs on test_CT {
476 var ASP_RSL_Unitdata rsl_ud;
477 var integer i;
478 var integer chreq_total, chreq_nochan;
479
Harald Welte89d42e82017-12-17 16:42:41 +0100480 f_init(1);
Harald Welte799c97b2017-12-14 17:50:30 +0100481
482 chreq_total := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:total");
483 chreq_nochan := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:no_channel");
484
485 /* expect 5xTCH/F to succeed */
Philipp Maiercb6cc482018-03-26 13:08:00 +0200486 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 +0100487 var RslChannelNr chan_nr := f_chreq_act_ack('23'O, i);
Harald Welte799c97b2017-12-14 17:50:30 +0100488 }
489
490 IPA_RSL[0].clear;
491
Harald Weltedd8cbf32018-01-28 12:07:52 +0100492 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:total",
Philipp Maiercb6cc482018-03-26 13:08:00 +0200493 chreq_total + NUM_TCHF_PER_BTS + NUM_TCHH_PER_BTS + NUM_SDCCH_PER_BTS);
Harald Welte799c97b2017-12-14 17:50:30 +0100494
495 /* now expect additional channel activations to fail */
496 f_ipa_tx(0, ts_RSL_CHAN_RQD('42'O, 42));
497
498 alt {
499 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0,
500 tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV))) {
501 setverdict(fail, "Received CHAN ACT ACK without resources?!?");
502 }
503 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0, tr_RSL_IMM_ASSIGN(?))) -> value rsl_ud {
504 var GsmRrMessage rr;
505 /* match on IMM ASS REJ */
506 rr := dec_GsmRrMessage(rsl_ud.rsl.ies[1].body.full_imm_ass_info.payload);
507 if (rr.header.message_type == IMMEDIATE_ASSIGNMENT_REJECT) {
508 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:total",
Philipp Maiercb6cc482018-03-26 13:08:00 +0200509 chreq_total + NUM_TCHF_PER_BTS + NUM_TCHH_PER_BTS + NUM_SDCCH_PER_BTS+1);
Harald Welte799c97b2017-12-14 17:50:30 +0100510 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:no_channel",
511 chreq_nochan+1);
512 setverdict(pass);
513 } else {
514 repeat;
515 }
516 }
517 [] IPA_RSL[0].receive { repeat; }
518 }
519}
520
Harald Weltecfe2c962017-12-15 12:09:32 +0100521/***********************************************************************
522 * Assignment Testing
523 ***********************************************************************/
524
525/* Verify that the BSC refuses any BSSAP connection from the MSC (They are all BSC->MSC direction) */
526testcase TC_outbound_connect() runs on test_CT {
Harald Welte89d42e82017-12-17 16:42:41 +0100527 f_init(1);
Harald Weltecfe2c962017-12-15 12:09:32 +0100528
Harald Weltea4ca4462018-02-09 00:17:14 +0100529 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 +0100530 BSSAP.receive(tr_BSSAP_DISC_ind(2342, ?, ?));
531 setverdict(pass);
532}
533
Harald Welte16a4adf2017-12-14 18:54:01 +0100534/* Test behavior if MSC answers with CREF to CR */
535testcase TC_assignment_cic_only() runs on test_CT {
536 var BSSAP_N_CONNECT_ind rx_c_ind;
537 var RSL_Message rx_rsl;
538 var DchanTuple dt;
539
Harald Welte89d42e82017-12-17 16:42:41 +0100540 f_init(1);
Harald Welte16a4adf2017-12-14 18:54:01 +0100541
542 dt := f_est_dchan('23'O, 23, '00000000'O);
Harald Welte17b27da2018-05-25 20:33:53 +0200543 if (mp_bssap_cfg.transport == BSSAP_TRANSPORT_AoIP) {
544 /* send assignment without AoIP IEs */
545 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_AssignmentReq(ts_BSSMAP_IE_CIC(0, 1))));
546 } else {
547 /* Send assignmetn without CIC in IPA case */
548 var BSSMAP_IE_AoIP_TransportLayerAddress tla :=
549 valueof(ts_BSSMAP_IE_AoIP_TLA4('01020304'O, 2342));
550 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_AssignmentReq(omit, tla)));
551 }
Harald Welte16a4adf2017-12-14 18:54:01 +0100552 alt {
553 [] BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_AssignmentComplete)) {
554 setverdict(fail, "AoIP BSC cannot accept ASSIGNMENT without AoIP Transport IE");
555 }
Harald Welte235ebf12017-12-15 14:18:16 +0100556 /* TODO: Actually expect GSM0808_CAUSE_REQ_A_IF_TYPE_NOT_SUPP */
Harald Welte16a4adf2017-12-14 18:54:01 +0100557 [] BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_AssignmentFail)) {
558 setverdict(pass);
559 }
560 [] BSSAP.receive { repeat; }
561 }
562}
563
Harald Welteed848512018-05-24 22:27:58 +0200564/* generate an assignment request for either AoIP or SCCPlite */
Harald Weltee102eae2018-05-31 21:03:47 +0200565function f_gen_ass_req() return PDU_BSSAP {
Harald Welteed848512018-05-24 22:27:58 +0200566 var PDU_BSSAP ass_cmd;
567 if (mp_bssap_cfg.transport == BSSAP_TRANSPORT_AoIP) {
568 var BSSMAP_IE_AoIP_TransportLayerAddress tla :=
569 valueof(ts_BSSMAP_IE_AoIP_TLA4('01020304'O, 2342));
570 ass_cmd := valueof(ts_BSSMAP_AssignmentReq(omit, tla));
571 } else {
572 var BSSMAP_IE_CircuitIdentityCode cic := valueof(ts_BSSMAP_IE_CIC(0,1));
573 ass_cmd := valueof(ts_BSSMAP_AssignmentReq(cic, omit));
574 }
575 return ass_cmd;
576}
577
578/* generate an assignment complete template for either AoIP or SCCPlite */
Harald Weltee102eae2018-05-31 21:03:47 +0200579function f_gen_exp_compl() return template PDU_BSSAP {
Harald Welteed848512018-05-24 22:27:58 +0200580 var template PDU_BSSAP exp_compl;
581 if (mp_bssap_cfg.transport == BSSAP_TRANSPORT_AoIP) {
582 exp_compl := tr_BSSMAP_AssignmentComplete(omit, ?);
583 } else {
584 /* CIC is optional "*" as the MSC allocated it */
585 exp_compl := tr_BSSMAP_AssignmentComplete(*, omit);
586 }
587 return exp_compl;
588}
589
Harald Welte235ebf12017-12-15 14:18:16 +0100590/* Run everything required up to sending a caller-specified assignment command and expect response */
591function f_assignment_exp(PDU_BSSAP ass_cmd, template PDU_BSSAP exp, charstring fail_text)
592runs on test_CT {
593 var BSSAP_N_CONNECT_ind rx_c_ind;
594 var RSL_Message rx_rsl;
595 var DchanTuple dt;
596
Harald Welte89d42e82017-12-17 16:42:41 +0100597 f_init(1);
Harald Welte235ebf12017-12-15 14:18:16 +0100598
599 dt := f_est_dchan('23'O, 23, '00000000'O);
600 /* send assignment without AoIP IEs */
601 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ass_cmd));
602 alt {
603 [] BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_AssignmentComplete)) {
604 if (ischosen(exp.pdu.bssmap.assignmentComplete)) {
605 setverdict(pass);
606 } else {
607 setverdict(fail, fail_text);
608 }
609 }
610 [] BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_AssignmentFail)) {
611 if (ischosen(exp.pdu.bssmap.assignmentFailure)) {
612 setverdict(pass);
613 } else {
614 setverdict(fail, fail_text);
615 }
616 }
617 [] BSSAP.receive { repeat; }
618 }
619}
620testcase TC_assignment_csd() runs on test_CT {
621 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
Harald Welteed848512018-05-24 22:27:58 +0200622 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte235ebf12017-12-15 14:18:16 +0100623 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelTypeCSD);
624 //exp_fail.pdu.bssmap.assignmentFailure.cause.causeValue := int2bit(enum2int(GSM0808_CAUSE_REQ_CODEC_TYPE_OR_CONFIG_UNAVAIL), 7);
625 f_assignment_exp(ass_cmd, exp_fail, "BSC accepted Assignment for CSD");
626}
627
628testcase TC_assignment_ctm() runs on test_CT {
629 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
Harald Welteed848512018-05-24 22:27:58 +0200630 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte235ebf12017-12-15 14:18:16 +0100631 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelTypeCTM);
632 //exp_fail.pdu.bssmap.assignmentFailure.cause.causeValue := int2bit(enum2int(GSM0808_CAUSE_REQ_CODEC_TYPE_OR_CONFIG_UNAVAIL), 7);
633 f_assignment_exp(ass_cmd, exp_fail, "BSC accepted Assignment for Speech+CTM");
634}
635
Harald Welte4003d112017-12-09 22:35:39 +0100636type record DchanTuple {
637 integer sccp_conn_id,
638 RslChannelNr rsl_chan_nr
Harald Weltea5d2ab22017-12-09 14:21:42 +0100639}
640
Harald Welted6939652017-12-13 21:02:46 +0100641/* Send CHAN RQD and wait for allocation; acknowledge it */
642private function f_chreq_act_ack(OCT1 ra := '23'O, GsmFrameNumber fn := 23)
643runs on test_CT return RslChannelNr {
644 var RSL_Message rx_rsl;
645 f_ipa_tx(0, ts_RSL_CHAN_RQD(ra, fn));
646 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
647 var RslChannelNr chan_nr := rx_rsl.ies[0].body.chan_nr;
648 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, fn+10));
649 return chan_nr;
650}
651
Harald Welte4003d112017-12-09 22:35:39 +0100652/* helper function to establish a dedicated channel via BTS and MSC */
653function f_est_dchan(OCT1 ra, GsmFrameNumber fn, octetstring l3)
654runs on test_CT return DchanTuple {
655 var BSSAP_N_CONNECT_ind rx_c_ind;
Harald Welte4003d112017-12-09 22:35:39 +0100656 var DchanTuple dt;
Harald Weltea5d2ab22017-12-09 14:21:42 +0100657
Harald Welte4003d112017-12-09 22:35:39 +0100658 /* Send CHAN RQD and wait for allocation; acknowledge it */
Harald Welted6939652017-12-13 21:02:46 +0100659 dt.rsl_chan_nr := f_chreq_act_ack(ra, fn);
Harald Welte4003d112017-12-09 22:35:39 +0100660
661 f_ipa_tx(0, ts_RSL_EST_IND(dt.rsl_chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
662
663 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) -> value rx_c_ind;
664 dt.sccp_conn_id := rx_c_ind.connectionId;
665 BSSAP.send(ts_BSSAP_CONNECT_res(dt.sccp_conn_id));
666
667 return dt;
Harald Weltea5d2ab22017-12-09 14:21:42 +0100668}
669
Harald Welte641fcbe2018-06-14 10:58:35 +0200670/* expect RF CAN REL from BTS, acknowledge it and clear the MSC side */
671private function f_exp_chan_rel_and_clear(DchanTuple dt, integer bts_nr := 0) runs on test_CT {
672 var RSL_Message rx_rsl;
673 /* expect BSC to disable the channel */
674 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL), T3101_MAX);
675 /* respond with CHAN REL ACK */
676 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(dt.rsl_chan_nr));
677
678 /* expect Clear Complete from BSC */
679 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearComplete));
680
681 /* MSC disconnects as instructed. */
682 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
683}
684
Harald Welte4003d112017-12-09 22:35:39 +0100685/* Test behavior of channel release after unilateral RLL REL IND (DISC from MS) */
686testcase TC_chan_rel_rll_rel_ind() runs on test_CT {
Neels Hofmeyr27f64362018-03-12 01:44:00 +0100687 var BSSAP_N_DATA_ind rx_di;
Harald Welte4003d112017-12-09 22:35:39 +0100688 var DchanTuple dt;
Harald Welte96c94412017-12-09 03:12:45 +0100689
Harald Welte89d42e82017-12-17 16:42:41 +0100690 f_init(1);
Harald Welte96c94412017-12-09 03:12:45 +0100691
Harald Welte4003d112017-12-09 22:35:39 +0100692 dt := f_est_dchan('23'O, 23, '00010203040506'O);
693
694 /* simulate RLL REL IND */
695 f_ipa_tx(0, ts_RSL_REL_IND(dt.rsl_chan_nr, valueof(ts_RslLinkID_DCCH(0))));
696
Neels Hofmeyr27f64362018-03-12 01:44:00 +0100697 /* expect Clear Request on MSC side */
698 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearRequest)) -> value rx_di;
699
700 /* Instruct BSC to clear channel */
701 var BssmapCause cause := bit2int(rx_di.userData.pdu.bssmap.clearRequest.cause.causeValue);
702 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
703
Harald Welte4003d112017-12-09 22:35:39 +0100704 /* expect BSC to disable the channel */
Harald Welte641fcbe2018-06-14 10:58:35 +0200705 f_exp_chan_rel_and_clear(dt, 0);
Neels Hofmeyr27f64362018-03-12 01:44:00 +0100706
707 /* wait for SCCP emulation to do its job */
708 f_sleep(1.0);
Harald Welte4003d112017-12-09 22:35:39 +0100709
710 setverdict(pass);
711}
712
713/* Test behavior of channel release after CONN FAIL IND from BTS */
714testcase TC_chan_rel_conn_fail() runs on test_CT {
715 var BSSAP_N_DATA_ind rx_di;
Harald Welte4003d112017-12-09 22:35:39 +0100716 var DchanTuple dt;
717
Harald Welte89d42e82017-12-17 16:42:41 +0100718 f_init(1);
Harald Welte4003d112017-12-09 22:35:39 +0100719
720 dt := f_est_dchan('23'O, 23, '00010203040506'O);
721
722 /* simulate CONN FAIL IND */
Harald Weltea8ed9062017-12-14 09:46:01 +0100723 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 +0100724 /* TODO: different cause values? */
725
Harald Welte4003d112017-12-09 22:35:39 +0100726 /* expect Clear Request from BSC */
727 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearRequest)) -> value rx_di;
728
729 /* Instruct BSC to clear channel */
730 var BssmapCause cause := bit2int(rx_di.userData.pdu.bssmap.clearRequest.cause.causeValue);
731 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
732
Harald Welte6ff76ea2018-01-28 13:08:01 +0100733 /* expect BSC to disable the channel */
Harald Welte641fcbe2018-06-14 10:58:35 +0200734 f_exp_chan_rel_and_clear(dt, 0);
Harald Welte4003d112017-12-09 22:35:39 +0100735
736 /* wait for SCCP emulation to do its job */
737 f_sleep(1.0);
738
739 setverdict(pass);
740}
741
Harald Welte99f3ca02018-06-14 13:40:29 +0200742/* Test behavior of early CONN FAIL IND from BTS (before EST IND!) */
743/* See also https://www.osmocom.org/issues/3182 */
744testcase TC_early_conn_fail() runs on test_CT {
745 var RSL_Message rx_rsl;
746 var DchanTuple dt;
747
748 f_init(1);
749
750 /* BTS->BSC: Send CHAN RQD and wait for allocation; acknowledge it */
751 dt.rsl_chan_nr := f_chreq_act_ack(f_rnd_octstring(1), 23);
752
753 /* BTS->BSC: simulate CONN FAIL IND */
754 f_ipa_tx(0, ts_RSL_CONN_FAIL_IND(dt.rsl_chan_nr, RSL_ERR_RADIO_LINK_FAIL));
755
756 /* BTS->BSC: Expect RF channel release from BSC on Abis */
757 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL), 10.0);
758
759 /* BTS<-BSC: respond with CHAN REL ACK */
760 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(dt.rsl_chan_nr));
761
762 setverdict(pass);
763}
764
765/* Test behavior of late CONN FAIL IND from BTS (ater REL IND!) */
766/* See also https://www.osmocom.org/issues/3182 */
767testcase TC_late_conn_fail() runs on test_CT {
768 var RSL_Message rx_rsl;
769 var DchanTuple dt;
770
771 f_init(1);
772
773 dt := f_est_dchan('23'O, 23, '00010203040506'O);
774
775 /* BSC<-MSC: Instruct BSC to clear connection */
776 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(0)));
777
778 /* BTS->BSC: expect BSC to deactivate SACCH */
779 rx_rsl := f_exp_ipa_rx(0, tr_RSL_DEACT_SACCH(dt.rsl_chan_nr));
780
781 /* BTS->BSC: simulate a late CONN FAIL IND from BTS */
782 f_ipa_tx(0, ts_RSL_CONN_FAIL_IND(dt.rsl_chan_nr, RSL_ERR_RADIO_LINK_FAIL));
783
784 /* BTS<-BSC: Expect RF channel release from BSC on Abis */
785 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL), 10.0);
786 /* BTS->BSC: respond with CHAN REL ACK */
787 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(dt.rsl_chan_nr));
788
789 /* BSC->MSC: expect Clear Complete from BSC */
790 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearComplete));
791
792 /* BSC<-MSC: MSC disconnects as requested. */
793 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
794
795 setverdict(pass);
796}
797
Harald Welte91d54a52018-01-28 15:35:07 +0100798function f_expect_chan_rel(integer bts_nr, RslChannelNr rsl_chan_nr, boolean flush := true,
799 boolean handle_rll_rel := true) runs on test_CT {
800
801 var RslLinkId main_dcch := valueof(ts_RslLinkID_DCCH(0));
802 if (flush) {
803 /* Clear the queue, it might still contain stuff like IMMEDIATE ASSIGN */
804 IPA_RSL[bts_nr].clear;
805 }
806 alt {
807 /* ignore DEACTIVATE SACCH (if any) */
808 [] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0,
809 tr_RSL_DEACT_SACCH(rsl_chan_nr))) {
810 repeat;
811 }
812 /* acknowledge RLL release (if any)*/
813 [handle_rll_rel] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0,
814 tr_RSL_REL_REQ(rsl_chan_nr, ?))) {
815 /* FIXME: Why are we getting this for LinkID SACCH? */
816 f_ipa_tx(0, ts_RSL_REL_CONF(rsl_chan_nr, main_dcch));
817 repeat;
818 }
819 /* Expect RF channel release from BSC on Abis */
820 [] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0,
821 tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL))) {
822 /* respond with CHAN REL ACK */
823 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(rsl_chan_nr));
824 }
825 /* ignore any user data */
826 [] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0, tr_RSL_MsgTypeR(?))) {
827 repeat;
828 }
829 }
830}
831
Harald Welte4003d112017-12-09 22:35:39 +0100832/* Test behavior of channel release after hard Clear Command from MSC */
833testcase TC_chan_rel_hard_clear() runs on test_CT {
834 var BSSAP_N_DATA_ind rx_di;
Harald Welte4003d112017-12-09 22:35:39 +0100835 var DchanTuple dt;
Harald Welte4003d112017-12-09 22:35:39 +0100836
Harald Welte89d42e82017-12-17 16:42:41 +0100837 f_init(1);
Harald Welte4003d112017-12-09 22:35:39 +0100838
839 dt := f_est_dchan('23'O, 23, '00010203040506'O);
840
841 /* Instruct BSC to clear channel */
842 var BssmapCause cause := 0;
843 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
844
845 /* expect Clear Complete from BSC on A */
846 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearComplete)) {
847 /* release the SCCP connection */
848 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
849 }
850
Harald Welte91d54a52018-01-28 15:35:07 +0100851 f_expect_chan_rel(0, dt.rsl_chan_nr);
Harald Welte4003d112017-12-09 22:35:39 +0100852 setverdict(pass);
853}
854
Harald Welted8c36cd2017-12-09 23:05:31 +0100855/* Test behavior of channel release after hard RLSD from MSC */
856testcase TC_chan_rel_hard_rlsd() runs on test_CT {
Harald Welted8c36cd2017-12-09 23:05:31 +0100857 var DchanTuple dt;
Harald Welted8c36cd2017-12-09 23:05:31 +0100858
Harald Welte89d42e82017-12-17 16:42:41 +0100859 f_init(1);
Harald Welted8c36cd2017-12-09 23:05:31 +0100860
861 dt := f_est_dchan('23'O, 23, '00010203040506'O);
862
863 /* release the SCCP connection */
864 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
865
Harald Welte91d54a52018-01-28 15:35:07 +0100866 f_expect_chan_rel(0, dt.rsl_chan_nr);
Harald Welted8c36cd2017-12-09 23:05:31 +0100867 setverdict(pass);
868}
869
Harald Welte550daf92018-06-11 19:22:13 +0200870/* Test behavior of channel release after hard RLSD from MSC and MS is not responding to RLL REL REQ */
871testcase TC_chan_rel_hard_rlsd_ms_dead() runs on test_CT {
872 var DchanTuple dt;
873
874 f_init(1);
875
876 dt := f_est_dchan('23'O, 23, '00010203040506'O);
877
878 /* release the SCCP connection */
879 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
880
881 f_expect_chan_rel(0, dt.rsl_chan_nr, true, false);
882 setverdict(pass);
883}
884
Harald Welte85804d42017-12-10 14:11:58 +0100885/* Test behavior of channel release after BSSMAP RESET from MSC */
886testcase TC_chan_rel_a_reset() runs on test_CT {
Harald Welte85804d42017-12-10 14:11:58 +0100887 var DchanTuple dt;
Harald Welte85804d42017-12-10 14:11:58 +0100888
Harald Welte89d42e82017-12-17 16:42:41 +0100889 f_init(1);
Harald Welte85804d42017-12-10 14:11:58 +0100890
891 dt := f_est_dchan('23'O, 23, '00010203040506'O);
892
893 /* Clear the queue, it might still contain stuff like IMMEDIATE ASSIGN */
894 IPA_RSL[0].clear;
895
896 /* perform BSSAP RESET, expect RESET ACK and DISC.ind on connection */
Harald Weltea4ca4462018-02-09 00:17:14 +0100897 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 +0100898 interleave {
Harald Weltea4ca4462018-02-09 00:17:14 +0100899 [] 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 +0100900 [] BSSAP.receive(tr_BSSAP_DISC_ind(dt.sccp_conn_id, ?, ?)) { }
901 }
902
Philipp Maiere8f38ed2018-02-09 10:30:31 +0100903 f_expect_chan_rel(0, dt.rsl_chan_nr, false);
Harald Welte85804d42017-12-10 14:11:58 +0100904 setverdict(pass);
905}
906
Harald Welte5cd20ed2017-12-13 21:03:20 +0100907/* Test behavior if RSL EST IND for non-active channel */
908testcase TC_rll_est_ind_inact_lchan() runs on test_CT {
909 timer T := 2.0;
910
Harald Welte89d42e82017-12-17 16:42:41 +0100911 f_init(1);
Harald Welte5cd20ed2017-12-13 21:03:20 +0100912
913 var octetstring l3 := '00010203040506'O;
914 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(6));
915 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
916
917 T.start;
918 alt {
919 [] BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) {
920 setverdict(fail, "MSC received COMPL L3 for non-active lchan");
921 }
922 [] BSSAP.receive {}
923 [] IPA_RSL[0].receive {}
924 [] T.timeout {}
925 }
926
927 setverdict(pass);
928}
929
930/* Test behavior if RSL EST IND for invalid SAPI */
931testcase TC_rll_est_ind_inval_sapi1() runs on test_CT {
932 var RslChannelNr chan_nr;
933
Harald Welte89d42e82017-12-17 16:42:41 +0100934 f_init(1);
Harald Welte5cd20ed2017-12-13 21:03:20 +0100935
936 chan_nr := f_chreq_act_ack()
937
938 var octetstring l3 := '00010203040506'O;
939 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(1)), l3));
940
941 timer T := 2.0;
942 T.start;
943 alt {
944 [] BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) {
945 setverdict(fail, "MSC received COMPL L3 for invalid SAPI 1");
946 }
947 [] BSSAP.receive { repeat; }
948 [] IPA_RSL[0].receive { repeat; }
949 [] T.timeout {}
950 }
951
952 setverdict(pass);
953}
954
955/* Test behavior if RSL EST IND for invalid SAPI */
956testcase TC_rll_est_ind_inval_sapi3() runs on test_CT {
957 timer T := 2.0;
958
Harald Welte89d42e82017-12-17 16:42:41 +0100959 f_init(1);
Harald Welte5cd20ed2017-12-13 21:03:20 +0100960
961 var RslChannelNr chan_nr := f_chreq_act_ack();
962
963 var octetstring l3 := '00010203040506'O;
964 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(3)), l3));
965
966 T.start;
967 alt {
968 [] BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) {
969 setverdict(fail, "MSC received COMPL L3 for invalid SAPI 3");
970 }
971 [] BSSAP.receive { repeat; }
972 [] IPA_RSL[0].receive { repeat; }
973 [] T.timeout {}
974 }
975
976 setverdict(pass);
977}
978
979/* Test behavior if RSL EST IND for invalid SACCH */
980testcase TC_rll_est_ind_inval_sacch() runs on test_CT {
981 timer T := 2.0;
982
Harald Welte89d42e82017-12-17 16:42:41 +0100983 f_init(1);
Harald Welte5cd20ed2017-12-13 21:03:20 +0100984
985 var RslChannelNr chan_nr := f_chreq_act_ack();
986
987 var octetstring l3 := '00010203040506'O;
988 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_SACCH(0)), l3));
989
990 T.start;
991 alt {
992 [] BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) {
993 setverdict(fail, "MSC received COMPL L3 for invalid Link SACCH");
994 }
995 [] BSSAP.receive { repeat; }
996 [] IPA_RSL[0].receive { repeat; }
997 [] T.timeout {}
998 }
999
1000 setverdict(pass);
1001}
1002
1003
1004
Harald Welte4003d112017-12-09 22:35:39 +01001005
1006testcase TC_ctrl_msc_connection_status() runs on test_CT {
1007 var charstring ctrl_resp;
1008
Harald Welte89d42e82017-12-17 16:42:41 +01001009 f_init(1);
Harald Welte4003d112017-12-09 22:35:39 +01001010
1011 /* See https://osmocom.org/issues/2729 */
1012 f_ctrl_get_exp(IPA_CTRL, "msc_connection_status", "connected");
1013 setverdict(pass);
1014}
1015
Stefan Sperlingb041b3d2018-01-03 17:14:55 +01001016testcase TC_ctrl_msc0_connection_status() runs on test_CT {
1017 var charstring ctrl_resp;
1018
1019 f_init(1);
Stefan Sperlingb041b3d2018-01-03 17:14:55 +01001020
1021 f_ctrl_get_exp(IPA_CTRL, "msc.0.connection_status", "connected");
1022 setverdict(pass);
1023}
1024
Harald Welte4003d112017-12-09 22:35:39 +01001025testcase TC_ctrl() runs on test_CT {
1026 var charstring ctrl_resp;
1027
Harald Welte89d42e82017-12-17 16:42:41 +01001028 f_init(1);
Harald Welte4003d112017-12-09 22:35:39 +01001029
1030 /* all below values must match the osmo-bsc.cfg config file used */
1031
Harald Welte6a129692018-03-17 17:30:14 +01001032 f_ctrl_get_exp(IPA_CTRL, "mcc", "001");
1033 f_ctrl_get_exp(IPA_CTRL, "mnc", "01");
Harald Welte44bdaa52017-12-17 17:01:47 +01001034 f_ctrl_get_exp(IPA_CTRL, "number-of-bts", "3");
Harald Welte4003d112017-12-09 22:35:39 +01001035
1036 var integer bts_nr := 0;
1037 f_ctrl_get_exp_bts(IPA_CTRL, bts_nr, "location-area-code", "1");
1038 f_ctrl_get_exp_bts(IPA_CTRL, bts_nr, "cell-identity", "0");
1039 f_ctrl_get_exp_bts(IPA_CTRL, bts_nr, "oml-connection-state", "connected");
1040 f_ctrl_get_exp_bts(IPA_CTRL, bts_nr, "gprs-mode", "gprs");
1041 f_ctrl_get_exp_bts(IPA_CTRL, bts_nr, "rf_state", "operational,unlocked,on");
1042 f_ctrl_get_exp_trx(IPA_CTRL, bts_nr, 0, "arfcn", "871");
1043 f_ctrl_get_exp_trx(IPA_CTRL, bts_nr, 0, "max-power-reduction", "20");
1044
1045 var integer uptime := str2int(f_ctrl_get_bts(IPA_CTRL, bts_nr, "oml-uptime"));
1046 f_sleep(2.0);
1047 if (str2int(f_ctrl_get_bts(IPA_CTRL, bts_nr, "oml-uptime")) < uptime+1) {
1048 setverdict(fail, "oml-uptime not incrementing as expected");
1049 }
1050 /* TODO: Disconnect RSL, imply that OML is disconnected and check for uptime zero? */
1051
1052 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bsc", 0, "paging:attempted", 0);
1053
1054 setverdict(pass);
Harald Welte96c94412017-12-09 03:12:45 +01001055}
1056
Harald Welte6f521d82017-12-11 19:52:02 +01001057function f_bssap_tx_ud(template PDU_BSSAP bssap) runs on test_CT {
Harald Weltea4ca4462018-02-09 00:17:14 +01001058 BSSAP.send(ts_BSSAP_UNITDATA_req(g_bssap.sccp_addr_peer, g_bssap.sccp_addr_own, bssap));
Harald Welte6f521d82017-12-11 19:52:02 +01001059}
1060
1061
1062/***********************************************************************
1063 * Paging Testing
1064 ***********************************************************************/
1065
1066type record Cell_Identity {
1067 GsmMcc mcc,
1068 GsmMnc mnc,
1069 GsmLac lac,
1070 GsmCellId ci
1071};
Harald Welte24135bd2018-03-17 19:27:53 +01001072private const Cell_Identity cid := { '001'H, '01'H, 1, 0 };
Stefan Sperling049a86e2018-03-20 15:51:00 +01001073private const Cell_Identity unknown_cid := { '678'H, 'f90'H, 1, 0 };
Harald Welte6f521d82017-12-11 19:52:02 +01001074
Harald Welte5d1a2202017-12-13 19:51:29 +01001075type set of integer BtsIdList;
1076
1077private function f_bts_in_list(integer bts_id, BtsIdList bts_ids) return boolean {
1078 for (var integer j := 0; j < sizeof(bts_ids); j := j + 1) {
1079 if (bts_id == bts_ids[j]) {
1080 return true;
1081 }
1082 }
1083 return false;
1084}
Harald Welte6f521d82017-12-11 19:52:02 +01001085
1086/* core paging test helper function; used by most paging test cases */
1087private function f_pageing_helper(hexstring imsi,
1088 template BSSMAP_FIELD_CellIdentificationList cid_list,
Harald Welte5d1a2202017-12-13 19:51:29 +01001089 BtsIdList bts_ids := { 0 },
Harald Welte6f521d82017-12-11 19:52:02 +01001090 template RSL_ChanNeeded rsl_chneed := omit,
1091 template OCT4 tmsi := omit) runs on test_CT
1092{
1093 var template BSSMAP_IE_ChannelNeeded bssmap_chneed;
1094 var MobileIdentity mi;
1095 var template octetstring id_enc; /* FIXME */
1096 var RSL_Message rx_rsl;
1097 var integer paging_group := hex2int(imsi[lengthof(imsi)-1]);
Harald Welte5d1a2202017-12-13 19:51:29 +01001098 var integer i;
Harald Welte6f521d82017-12-11 19:52:02 +01001099
1100 f_init();
Harald Welte6f521d82017-12-11 19:52:02 +01001101
1102 /* Clear the queue, it might still contain stuff like BCCH FILLING */
Harald Weltec3068592018-03-17 19:55:31 +01001103 for (i := 0; i < NUM_BTS; i := i + 1) {
1104 IPA_RSL[i].clear;
Harald Welte5d1a2202017-12-13 19:51:29 +01001105 }
Harald Welte6f521d82017-12-11 19:52:02 +01001106
1107 if (isvalue(rsl_chneed)) {
1108 /* The values of 08.08 3.2.2.36 and 08.58 9.3.40 are luckily identical */
1109 bssmap_chneed := ts_BSSMAP_IE_ChanNeeded(int2bit(enum2int(valueof(rsl_chneed)),2));
1110 } else {
1111 bssmap_chneed := omit;
1112 }
1113
1114 f_bssap_tx_ud(ts_BSSMAP_Paging(imsi, cid_list, tmsi, bssmap_chneed));
1115
1116/* FIXME: Disabled due to bugs in both GSM_RR_Types and MobileL3_CommonIE_Types IMSI encoder
1117 if (isvalue(tmsi)) {
1118 mi := valueof(t_Osmo_MI_TMSI(oct2int(valueof(tmsi))));
1119 } else {
1120 mi := valueof(ts_Osmo_MI_IMSI(imsi));
1121 }
1122 id_enc := enc_MobileIdentity(mi);
1123*/
1124 id_enc := ?;
Harald Welte5d1a2202017-12-13 19:51:29 +01001125 for (i := 0; i < sizeof(bts_ids); i := i + 1) {
1126 rx_rsl := f_exp_ipa_rx(bts_ids[i], tr_RSL_PAGING_CMD(id_enc));
1127 /* check channel type, paging group */
1128 if (rx_rsl.ies[1].body.paging_group != paging_group) {
1129 setverdict(fail, "Paging for wrong paging group");
1130 }
1131 if (ispresent(rsl_chneed) and
1132 rx_rsl.ies[3].body.chan_needed.chan_needed != valueof(rsl_chneed)) {
1133 setverdict(fail, "RSL Channel Needed != BSSMAP Channel Needed");
1134 }
Harald Welte6f521d82017-12-11 19:52:02 +01001135 }
Harald Welte2fccd982018-01-31 15:48:19 +01001136 f_sleep(2.0);
Harald Welte5d1a2202017-12-13 19:51:29 +01001137 /* do a quick check on all not-included BTSs if they received paging */
1138 for (i := 0; i < NUM_BTS; i := i + 1) {
1139 timer T := 0.1;
1140 if (f_bts_in_list(i, bts_ids)) {
1141 continue;
1142 }
1143 T.start;
1144 alt {
1145 [] IPA_RSL[i].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0, tr_RSL_PAGING_CMD(id_enc))) {
1146 setverdict(fail, "Paging on BTS ", i, " which is not part of ", bts_ids);
1147 }
1148 [] IPA_RSL[i].receive { repeat; }
1149 [] T.timeout { }
1150 }
Harald Welte6f521d82017-12-11 19:52:02 +01001151 }
1152
1153 setverdict(pass);
1154}
1155
Harald Welte5d1a2202017-12-13 19:51:29 +01001156const BtsIdList c_BtsId_all := { 0, 1, 2 };
Harald Welte751d3eb2018-01-31 15:51:06 +01001157const BtsIdList c_BtsId_none := { };
Harald Welte5d1a2202017-12-13 19:51:29 +01001158const BtsIdList c_BtsId_LAC1 := { 0, 1 };
1159const BtsIdList c_BtsId_LAC2 := { 2 };
1160
Harald Welte6f521d82017-12-11 19:52:02 +01001161/* PAGING by IMSI + TMSI */
1162testcase TC_paging_imsi_nochan() runs on test_CT {
1163 var BSSMAP_FIELD_CellIdentificationList cid_list;
1164 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Philipp Maier8c04b0a2018-02-23 13:48:48 +01001165 f_pageing_helper('001010100000001'H, cid_list, c_BtsId_all, omit, omit);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001166 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001167}
1168
1169/* PAGING by IMSI + TMSI */
1170testcase TC_paging_tmsi_nochan() runs on test_CT {
1171 var BSSMAP_FIELD_CellIdentificationList cid_list;
1172 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01001173 f_pageing_helper('001010100000001'H, cid_list, c_BtsId_all, omit, 'A1B2C301'O);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001174 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001175}
1176
1177/* Paging with different "channel needed' values */
1178testcase TC_paging_tmsi_any() runs on test_CT {
1179 var BSSMAP_FIELD_CellIdentificationList cid_list;
1180 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01001181 f_pageing_helper('001010100000002'H, cid_list, c_BtsId_all, RSL_CHANNEED_ANY, 'A1B2C302'O);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001182 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001183}
1184testcase TC_paging_tmsi_sdcch() runs on test_CT {
1185 var BSSMAP_FIELD_CellIdentificationList cid_list;
1186 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01001187 f_pageing_helper('001010100000003'H, cid_list, c_BtsId_all, RSL_CHANNEED_SDCCH, 'A1B2C303'O);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001188 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001189}
1190testcase TC_paging_tmsi_tch_f() runs on test_CT {
1191 var BSSMAP_FIELD_CellIdentificationList cid_list;
1192 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01001193 f_pageing_helper('001010000000004'H, cid_list, c_BtsId_all, RSL_CHANNEED_TCH_F, 'A1B2C304'O);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001194 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001195}
1196testcase TC_paging_tmsi_tch_hf() runs on test_CT {
1197 var BSSMAP_FIELD_CellIdentificationList cid_list;
1198 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01001199 f_pageing_helper('001010000000005'H, cid_list, c_BtsId_all, RSL_CHANNEED_TCH_ForH, 'A1B2C305'O);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001200 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001201}
1202
1203/* Paging by CGI */
1204testcase TC_paging_imsi_nochan_cgi() runs on test_CT {
1205 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1206 cid_list := { cIl_CGI := { ts_BSSMAP_CI_CGI(cid.mcc, cid.mnc, cid.lac, cid.ci) } };
Harald Welte5d1a2202017-12-13 19:51:29 +01001207 f_pageing_helper('001010000000006'H, cid_list, { 0 });
Philipp Maier282ca4b2018-02-27 17:17:00 +01001208 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001209}
1210
1211/* Paging by LAC+CI */
1212testcase TC_paging_imsi_nochan_lac_ci() runs on test_CT {
1213 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1214 cid_list := { cIl_LAC_CI := { ts_BSSMAP_CI_LAC_CI(cid.lac, cid.ci) } };
Harald Welte5d1a2202017-12-13 19:51:29 +01001215 f_pageing_helper('001010000000007'H, cid_list, { 0 });
Philipp Maier282ca4b2018-02-27 17:17:00 +01001216 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001217}
1218
1219/* Paging by CI */
1220testcase TC_paging_imsi_nochan_ci() runs on test_CT {
1221 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1222 cid_list := { cIl_CI := { ts_BSSMAP_CI_CI(cid.ci) } };
Harald Welte5d1a2202017-12-13 19:51:29 +01001223 f_pageing_helper('001010000000008'H, cid_list, { 0 });
Philipp Maier282ca4b2018-02-27 17:17:00 +01001224 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001225}
1226
1227/* Paging by LAI */
1228testcase TC_paging_imsi_nochan_lai() runs on test_CT {
1229 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1230 cid_list := { cIl_LAI := { ts_BSSMAP_CI_LAI(cid.mcc, cid.mnc, cid.lac) } };
Harald Welte5d1a2202017-12-13 19:51:29 +01001231 f_pageing_helper('001010000000009'H, cid_list, c_BtsId_LAC1);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001232 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001233}
1234
1235/* Paging by LAC */
1236testcase TC_paging_imsi_nochan_lac() runs on test_CT {
1237 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1238 cid_list := { cIl_LAC := { ts_BSSMAP_CI_LAC(cid.lac) } };
Harald Welte5d1a2202017-12-13 19:51:29 +01001239 f_pageing_helper('001010000000010'H, cid_list, c_BtsId_LAC1);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001240 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001241}
1242
1243/* Paging by "all in BSS" */
1244testcase TC_paging_imsi_nochan_all() runs on test_CT {
1245 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1246 cid_list := { cIl_allInBSS := ''O };
Harald Welte5d1a2202017-12-13 19:51:29 +01001247 f_pageing_helper('001010000000011'H, cid_list, c_BtsId_all);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001248 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001249}
1250
Stefan Sperling7b5e1782018-03-20 19:32:43 +01001251/* Paging by PLMN+LAC+RNC; We do not implement this; Verify nothing is paged */
Harald Welte751d3eb2018-01-31 15:51:06 +01001252testcase TC_paging_imsi_nochan_plmn_lac_rnc() runs on test_CT {
1253 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1254 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 +01001255 f_pageing_helper('001010000000012'H, cid_list, c_BtsId_none);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001256 f_shutdown_helper();
Harald Welte751d3eb2018-01-31 15:51:06 +01001257}
Harald Welte6f521d82017-12-11 19:52:02 +01001258
Stefan Sperling7b5e1782018-03-20 19:32:43 +01001259/* Paging by RNC; We do not implement this; Verify nothing is paged */
Harald Welte751d3eb2018-01-31 15:51:06 +01001260testcase TC_paging_imsi_nochan_rnc() runs on test_CT {
1261 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1262 cid_list := { cIl_RNC := { int2oct(13, 2) } };
Stefan Sperling7b5e1782018-03-20 19:32:43 +01001263 f_pageing_helper('001010000000013'H, cid_list, c_BtsId_none);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001264 f_shutdown_helper();
Harald Welte751d3eb2018-01-31 15:51:06 +01001265}
1266
Stefan Sperling7b5e1782018-03-20 19:32:43 +01001267/* Paging by LAC+RNC; We do not implement; Verify nothing is paged */
Harald Welte751d3eb2018-01-31 15:51:06 +01001268testcase TC_paging_imsi_nochan_lac_rnc() runs on test_CT {
1269 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1270 cid_list := { cIl_LAC_RNC := { ts_BSSMAP_CI_LAC_RNC(cid.lac, 14) } };
Stefan Sperling7b5e1782018-03-20 19:32:43 +01001271 f_pageing_helper('001010000000014'H, cid_list, c_BtsId_none);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001272 f_shutdown_helper();
Harald Welte751d3eb2018-01-31 15:51:06 +01001273}
1274
Harald Welte6f521d82017-12-11 19:52:02 +01001275/* Paging on multiple cells (multiple entries in list): Verify all of them page */
Harald Welte751d3eb2018-01-31 15:51:06 +01001276testcase TC_paging_imsi_nochan_lacs() runs on test_CT {
1277 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1278 cid_list := { cIl_LAC := { ts_BSSMAP_CI_LAC(1), ts_BSSMAP_CI_LAC(2) } };
1279 f_pageing_helper('001010000000015'H, cid_list, c_BtsId_all);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001280 f_shutdown_helper();
Harald Welte751d3eb2018-01-31 15:51:06 +01001281}
1282
1283/* Paging on empty list: Verify none of them page */
1284testcase TC_paging_imsi_nochan_lacs_empty() runs on test_CT {
1285 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1286 cid_list := { cIl_LAC := { } };
1287 f_pageing_helper('001010000000016'H, cid_list, c_BtsId_none);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001288 f_shutdown_helper();
Harald Welte751d3eb2018-01-31 15:51:06 +01001289}
1290
Stefan Sperling049a86e2018-03-20 15:51:00 +01001291/* Paging by CGI with unknown MCC/MNC: Verify nothing is paged. */
1292testcase TC_paging_imsi_nochan_cgi_unknown_cid() runs on test_CT {
1293 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1294 cid_list := { cIl_CGI := { ts_BSSMAP_CI_CGI(unknown_cid.mcc, unknown_cid.mnc, unknown_cid.lac, unknown_cid.ci) } };
1295 f_pageing_helper('001010000000006'H, cid_list, c_BtsId_none);
1296 f_shutdown_helper();
1297}
1298
Harald Welte6f521d82017-12-11 19:52:02 +01001299/* Verify paging retransmission interval + count */
1300/* Verify paging stops after channel establishment */
Harald Welte6f521d82017-12-11 19:52:02 +01001301/* Test behavior under paging overload */
Harald Welteae026692017-12-09 01:03:01 +01001302
Harald Weltee65d40e2017-12-13 00:09:06 +01001303/* Verify PCH load */
1304testcase TC_paging_imsi_load() runs on test_CT {
1305 var BSSMAP_FIELD_CellIdentificationList cid_list;
1306 timer T := 4.0;
Harald Welte2caa1062018-03-17 18:19:05 +01001307 timer T_retrans := 1.0;
Harald Weltee65d40e2017-12-13 00:09:06 +01001308 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01001309 f_pageing_helper('001010123456789'H, cid_list, c_BtsId_all);
Harald Weltee65d40e2017-12-13 00:09:06 +01001310
1311 /* tell BSC there is no paging space anymore */
1312 f_ipa_tx(0, ts_RSL_PAGING_LOAD_IND(0));
Harald Welte3b57ab52018-03-17 18:01:10 +01001313 f_sleep(0.2);
1314 IPA_RSL[0].clear;
Harald Weltee65d40e2017-12-13 00:09:06 +01001315
1316 /* Wait for 4 seconds if any more PAGING CMD are received on RSL. Normally,
1317 * there would be 8 retransmissions during 4 seconds */
1318 T.start;
Harald Welte2caa1062018-03-17 18:19:05 +01001319 T_retrans.start;
Harald Weltee65d40e2017-12-13 00:09:06 +01001320 alt {
1321 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0, tr_RSL_PAGING_CMD(?))) {
1322 setverdict(fail, "Received PAGING after LOAD_IND(0)");
1323 self.stop;
1324 }
Harald Welte2caa1062018-03-17 18:19:05 +01001325 [] T_retrans.timeout {
1326 /* re-trnsmit the zero-space LOAD IND to avoid BSC 'auto credit' */
1327 f_ipa_tx(0, ts_RSL_PAGING_LOAD_IND(0));
1328 T_retrans.start;
1329 repeat;
1330 }
Harald Weltee65d40e2017-12-13 00:09:06 +01001331 [] T.timeout {
1332 setverdict(pass);
1333 }
1334 }
Philipp Maier282ca4b2018-02-27 17:17:00 +01001335
1336 f_shutdown_helper();
Harald Weltee65d40e2017-12-13 00:09:06 +01001337}
1338
Harald Welte235ebf12017-12-15 14:18:16 +01001339/* Verify Paging Counter */
Harald Welte1ff69992017-12-14 12:31:17 +01001340testcase TC_paging_counter() runs on test_CT {
1341 var BSSMAP_FIELD_CellIdentificationList cid_list;
1342 timer T := 4.0;
1343 var integer i;
1344 var integer paging_attempted_bsc;
1345 var integer paging_attempted_bts[NUM_BTS];
1346 var integer paging_expired_bts[NUM_BTS];
1347 cid_list := valueof(ts_BSSMAP_CIL_noCell);
1348
1349 f_init();
1350
1351 /* read counters before paging */
1352 paging_attempted_bsc := f_ctrl_get_ratectr_abs(IPA_CTRL, "bsc", 0, "paging:attempted");
1353 for (i := 0; i < NUM_BTS; i := i+1) {
1354 paging_attempted_bts[i] := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", i, "paging:attempted");
1355 paging_expired_bts[i] := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", i, "paging:expired");
1356 }
1357
1358 f_pageing_helper('001230000000001'H, cid_list, c_BtsId_all);
1359
1360 /* expect the attempted pages on BSC and each BTSs to have incremented by one */
1361 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bsc", 0, "paging:attempted", paging_attempted_bsc+1);
1362 for (i := 0; i < NUM_BTS; i := i+1) {
1363 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", i, "paging:attempted",
1364 paging_attempted_bts[i]+1);
1365 }
1366
1367 /* assume that 12s later the paging on all BTSs have expired and hence incremented by 1 */
1368 f_sleep(12.0);
1369 for (i := 0; i < NUM_BTS; i := i+1) {
1370 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", i, "paging:expired",
1371 paging_expired_bts[i]+1);
1372 }
Harald Welte1ff69992017-12-14 12:31:17 +01001373
Philipp Maier282ca4b2018-02-27 17:17:00 +01001374 f_shutdown_helper();
Harald Welte1ff69992017-12-14 12:31:17 +01001375}
1376
1377
Harald Welte10985002017-12-12 09:29:15 +01001378/* Verify paging stops after A-RESET */
1379testcase TC_paging_imsi_a_reset() runs on test_CT {
1380 var BSSMAP_FIELD_CellIdentificationList cid_list;
1381 timer T := 3.0;
1382 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01001383 f_pageing_helper('001010123456789'H, cid_list, c_BtsId_all);
Harald Welte10985002017-12-12 09:29:15 +01001384
1385 /* Perform a BSSMAP Reset and wait for ACK */
Harald Weltea4ca4462018-02-09 00:17:14 +01001386 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 +01001387 alt {
Harald Weltea4ca4462018-02-09 00:17:14 +01001388 [] 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 +01001389 [] BSSAP.receive { repeat; }
1390 }
1391
1392 /* Clear the queue, it might still contain stuff like BCCH FILLING */
Philipp Maier1e6b4422018-02-23 14:02:13 +01001393 for (var integer i := 0; i < sizeof(IPA_RSL); i := i+1) {
1394 IPA_RSL[i].clear;
1395 }
Harald Welte10985002017-12-12 09:29:15 +01001396
1397 /* Wait for 3 seconds if any more PAGING CMD are received on RSL */
1398 T.start;
1399 alt {
1400 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0, tr_RSL_PAGING_CMD(?))) {
1401 setverdict(fail, "Received PAGING after A-RESET");
1402 self.stop;
1403 }
Harald Welte5d1a2202017-12-13 19:51:29 +01001404 [] IPA_RSL[1].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0, tr_RSL_PAGING_CMD(?))) {
1405 setverdict(fail, "Received PAGING after A-RESET");
1406 self.stop;
1407 }
1408 [] IPA_RSL[2].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0, tr_RSL_PAGING_CMD(?))) {
1409 setverdict(fail, "Received PAGING after A-RESET");
1410 self.stop;
1411 }
Harald Welte10985002017-12-12 09:29:15 +01001412 [] T.timeout {
1413 setverdict(pass);
1414 }
1415 }
Philipp Maier282ca4b2018-02-27 17:17:00 +01001416
1417 f_shutdown_helper();
Harald Welte10985002017-12-12 09:29:15 +01001418}
Harald Welteae026692017-12-09 01:03:01 +01001419
Harald Welte4e9b9cc2017-12-14 18:31:02 +01001420/* Test RSL link drop causes counter increment */
1421testcase TC_rsl_drop_counter() runs on test_CT {
1422 var integer rsl_fail;
1423
Harald Welte89d42e82017-12-17 16:42:41 +01001424 f_init(1);
Harald Welte4e9b9cc2017-12-14 18:31:02 +01001425
1426 rsl_fail := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "rsl_fail");
1427
1428 bts[0].rsl.vc_IPA.stop;
1429
1430 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "rsl_fail", rsl_fail+1);
1431
1432 setverdict(pass);
1433}
1434
1435/* TODO: Test OML link drop causes counter increment */
1436
Stefan Sperling830dc9d2018-02-12 21:08:28 +01001437/* The body of TC_rsl_unknown_unit_id() and TC_oml_unknown_unit_id() tests. */
1438function f_ipa_unknown_unit_id(integer mp_bsc_ipa_port) runs on test_CT return boolean {
1439 timer T := 10.0;
1440
1441 bts[0].rsl.id := "IPA-0-RSL";
1442 bts[0].rsl.vc_IPA := IPA_Emulation_CT.create(bts[0].rsl.id & "-IPA");
1443 bts[0].rsl.ccm_pars := c_IPA_default_ccm_pars;
1444 bts[0].rsl.ccm_pars.name := "Osmocom TTCN-3 BTS Simulator";
1445 bts[0].rsl.ccm_pars.unit_id := "0/0/0"; /* value which is unknown at BTS */
1446
Stefan Sperling830dc9d2018-02-12 21:08:28 +01001447 f_ipa_ctrl_start(mp_bsc_ip, mp_bsc_ctrl_port);
1448
1449 f_init_mgcp("VirtMSC");
1450
1451 /* start RSL/OML connection (XXX re-uses RSL port/protocol definitions for OML) */
1452 map(bts[0].rsl.vc_IPA:IPA_PORT, system:IPA);
1453 connect(bts[0].rsl.vc_IPA:IPA_RSL_PORT, self:IPA_RSL[0]);
1454 bts[0].rsl.vc_IPA.start(IPA_Emulation.main_client(mp_bsc_ip, mp_bsc_ipa_port, "", 10000, bts[0].rsl.ccm_pars));
1455
1456 /* wait for IPA OML link to connect and then disconnect */
1457 T.start;
1458 alt {
1459 [] IPA_RSL[0].receive(ASP_IPA_Event:{up_down := ASP_IPA_EVENT_DOWN}) {
1460 T.stop;
1461 return true;
1462 }
1463 [] IPA_RSL[0].receive { repeat }
1464 [] T.timeout {
1465 self.stop;
Stefan Sperling830dc9d2018-02-12 21:08:28 +01001466 }
1467 }
1468
1469 return false;
1470}
1471
1472/* BSC should close an RSL connection from a BTS with unknown unit ID (OS#2714). */
1473testcase TC_rsl_unknown_unit_id() runs on test_CT {
1474 if (f_ipa_unknown_unit_id(mp_bsc_rsl_port)) {
1475 setverdict(pass);
1476 } else {
1477 setverdict(fail, "Timeout RSL waiting for connection to close");
1478 }
1479}
1480
1481
1482/* BSC should close an RSL connection from a BTS with unknown unit ID (OS#2714). */
1483testcase TC_oml_unknown_unit_id() runs on test_CT {
1484 if (f_ipa_unknown_unit_id(mp_bsc_oml_port)) {
1485 setverdict(pass);
1486 } else {
1487 setverdict(fail, "Timeout OML waiting for connection to close");
1488 }
1489}
1490
1491
Harald Weltec1a2fff2017-12-17 11:06:19 +01001492/***********************************************************************
1493 * "New world" test cases using RSL_Emulation + BSSMAP_Emulation
1494 ***********************************************************************/
1495
1496import from BSSMAP_Emulation all;
1497import from RSL_Emulation all;
1498import from MSC_ConnectionHandler all;
1499
1500type function void_fn(charstring id) runs on MSC_ConnHdlr;
1501
Harald Welte336820c2018-05-31 20:34:52 +02001502/* helper function to create and connect a MSC_ConnHdlr component */
Harald Welteff579f92018-05-31 22:19:39 +02001503private function f_connect_handler(inout MSC_ConnHdlr vc_conn) runs on test_CT {
Harald Weltea4ca4462018-02-09 00:17:14 +01001504 connect(vc_conn:BSSMAPEM, g_bssap.vc_BSSMAP:PROC);
Daniel Willmann191e0d92018-01-17 12:44:35 +01001505 connect(vc_conn:MGCP_PROC, vc_MGCP:MGCP_PROC);
Harald Weltec1a2fff2017-12-17 11:06:19 +01001506 connect(vc_conn:RSL, bts[0].rsl.vc_RSL:CLIENT_PT);
Harald Weltef70df652018-01-29 22:00:23 +01001507 connect(vc_conn:RSL_PROC, bts[0].rsl.vc_RSL:RSL_PROC);
Philipp Maier88f4ae82018-03-01 14:00:58 +01001508 if (isvalue(bts[1])) {
Philipp Maier956a92f2018-02-16 10:58:07 +01001509 connect(vc_conn:RSL1, bts[1].rsl.vc_RSL:CLIENT_PT);
1510 connect(vc_conn:RSL1_PROC, bts[1].rsl.vc_RSL:RSL_PROC);
1511 }
Harald Weltea4ca4462018-02-09 00:17:14 +01001512 connect(vc_conn:BSSAP, g_bssap.vc_BSSMAP:CLIENT);
Daniel Willmann191e0d92018-01-17 12:44:35 +01001513 connect(vc_conn:MGCP, vc_MGCP:MGCP_CLIENT);
Harald Welte336820c2018-05-31 20:34:52 +02001514}
1515
1516function f_start_handler(void_fn fn, template (omit) TestHdlrParams pars := omit)
1517runs on test_CT return MSC_ConnHdlr {
1518 var charstring id := testcasename();
1519 var MSC_ConnHdlr vc_conn;
1520 vc_conn := MSC_ConnHdlr.create(id);
1521 f_connect_handler(vc_conn);
Harald Weltea0630032018-03-20 21:09:55 +01001522 vc_conn.start(f_handler_init(fn, id, pars));
Harald Weltec1a2fff2017-12-17 11:06:19 +01001523 return vc_conn;
1524}
1525
Harald Weltea0630032018-03-20 21:09:55 +01001526/* first function inside ConnHdlr component; sets g_pars + starts function */
1527private function f_handler_init(void_fn fn, charstring id, template (omit) TestHdlrParams pars := omit)
1528runs on MSC_ConnHdlr {
1529 if (isvalue(pars)) {
1530 g_pars := valueof(pars);
1531 }
1532 fn.apply(id);
1533}
1534
Harald Welte3c86ea02018-05-10 22:28:05 +02001535/* Establish signalling channel (non-assignment case) followed by cipher mode */
1536private function f_tc_ciph_mode_a5(charstring id) runs on MSC_ConnHdlr {
Harald Welteed848512018-05-24 22:27:58 +02001537 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
1538 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte3c86ea02018-05-10 22:28:05 +02001539 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelTypeSIGNAL);
Philipp Maier23000732018-05-18 11:25:37 +02001540 ass_cmd.pdu.bssmap.assignmentRequest.circuitIdentityCode := omit;
1541 ass_cmd.pdu.bssmap.assignmentRequest.aoIPTransportLayer := omit;
1542 exp_compl.pdu.bssmap.assignmentComplete.circuitIdentityCode := omit;
1543 exp_compl.pdu.bssmap.assignmentComplete.aoIPTransportLayer := omit;
Harald Welte3c86ea02018-05-10 22:28:05 +02001544
Philipp Maier23000732018-05-18 11:25:37 +02001545 f_establish_fully(ass_cmd, exp_compl);
Harald Welte3c86ea02018-05-10 22:28:05 +02001546}
1547testcase TC_ciph_mode_a5_0() runs on test_CT {
1548 var MSC_ConnHdlr vc_conn;
1549 var TestHdlrParams pars := valueof(t_def_TestHdlrPars);
1550 pars.encr := valueof(t_EncrParams('01'O, f_rnd_octstring(8)));
1551
1552 f_init(1, true);
1553 f_sleep(1.0);
1554 vc_conn := f_start_handler(refers(f_tc_ciph_mode_a5), pars);
1555 vc_conn.done;
1556}
1557testcase TC_ciph_mode_a5_1() runs on test_CT {
1558 var MSC_ConnHdlr vc_conn;
1559 var TestHdlrParams pars := valueof(t_def_TestHdlrPars);
1560 pars.encr := valueof(t_EncrParams('02'O, f_rnd_octstring(8)));
1561
1562 f_init(1, true);
1563 f_sleep(1.0);
1564 vc_conn := f_start_handler(refers(f_tc_ciph_mode_a5), pars);
1565 vc_conn.done;
1566}
1567testcase TC_ciph_mode_a5_3() runs on test_CT {
1568 var MSC_ConnHdlr vc_conn;
1569 var TestHdlrParams pars := valueof(t_def_TestHdlrPars);
1570 pars.encr := valueof(t_EncrParams('08'O, f_rnd_octstring(8)));
1571
1572 f_init(1, true);
1573 f_sleep(1.0);
1574 vc_conn := f_start_handler(refers(f_tc_ciph_mode_a5), pars);
1575 vc_conn.done;
1576}
1577
1578
1579/* establish initial channel, enable ciphering followed by assignment to ciphered channel */
Harald Welte651fcdc2018-05-10 20:23:16 +02001580private function f_tc_assignment_fr_a5(charstring id) runs on MSC_ConnHdlr {
Harald Welteed848512018-05-24 22:27:58 +02001581 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
1582 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Weltec1a2fff2017-12-17 11:06:19 +01001583
Harald Welte552620d2017-12-16 23:21:36 +01001584 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
1585 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
Harald Welte73cd2712017-12-17 00:44:52 +01001586
Harald Weltea0630032018-03-20 21:09:55 +01001587 f_establish_fully(ass_cmd, exp_compl);
Harald Welte552620d2017-12-16 23:21:36 +01001588}
Harald Welte552620d2017-12-16 23:21:36 +01001589testcase TC_assignment_fr_a5_0() runs on test_CT {
1590 var MSC_ConnHdlr vc_conn;
Harald Welte651fcdc2018-05-10 20:23:16 +02001591 var TestHdlrParams pars := valueof(t_def_TestHdlrPars);
1592 pars.encr := valueof(t_EncrParams('01'O, f_rnd_octstring(8)));
Harald Welte552620d2017-12-16 23:21:36 +01001593
Harald Welte89d42e82017-12-17 16:42:41 +01001594 f_init(1, true);
Harald Welte552620d2017-12-16 23:21:36 +01001595 f_sleep(1.0);
Harald Welte651fcdc2018-05-10 20:23:16 +02001596 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5), pars);
Harald Welte552620d2017-12-16 23:21:36 +01001597 vc_conn.done;
1598}
Harald Welte552620d2017-12-16 23:21:36 +01001599testcase TC_assignment_fr_a5_1() runs on test_CT {
Harald Weltec1a2fff2017-12-17 11:06:19 +01001600 var MSC_ConnHdlr vc_conn;
Harald Welte651fcdc2018-05-10 20:23:16 +02001601 var TestHdlrParams pars := valueof(t_def_TestHdlrPars);
1602 pars.encr := valueof(t_EncrParams('02'O, f_rnd_octstring(8)));
Harald Weltec1a2fff2017-12-17 11:06:19 +01001603
Harald Welte89d42e82017-12-17 16:42:41 +01001604 f_init(1, true);
Harald Weltec1a2fff2017-12-17 11:06:19 +01001605 f_sleep(1.0);
Harald Welte651fcdc2018-05-10 20:23:16 +02001606 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5), pars);
1607 vc_conn.done;
1608}
1609testcase TC_assignment_fr_a5_3() runs on test_CT {
1610 var MSC_ConnHdlr vc_conn;
1611 var TestHdlrParams pars := valueof(t_def_TestHdlrPars);
1612 pars.encr := valueof(t_EncrParams('08'O, f_rnd_octstring(8)));
Harald Weltec1a2fff2017-12-17 11:06:19 +01001613
Harald Welte651fcdc2018-05-10 20:23:16 +02001614 f_init(1, true);
1615 f_sleep(1.0);
1616 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5), pars);
Harald Weltec1a2fff2017-12-17 11:06:19 +01001617 vc_conn.done;
1618}
1619
Harald Welte552620d2017-12-16 23:21:36 +01001620/* Expect ASSIGNMENT FAIL if mandatory IE is missing */
1621private function f_tc_assignment_fr_a5_1_codec_missing(charstring id) runs on MSC_ConnHdlr {
Harald Weltea0630032018-03-20 21:09:55 +01001622 g_pars := valueof(t_def_TestHdlrPars);
Harald Welte552620d2017-12-16 23:21:36 +01001623 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
Harald Welteed848512018-05-24 22:27:58 +02001624 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte552620d2017-12-16 23:21:36 +01001625 const OCT8 kc := '0001020304050607'O;
1626
1627 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
Harald Weltea0630032018-03-20 21:09:55 +01001628 f_establish_fully(ass_cmd, exp_fail);
Harald Welte552620d2017-12-16 23:21:36 +01001629}
Harald Welte552620d2017-12-16 23:21:36 +01001630testcase TC_assignment_fr_a5_1_codec_missing() runs on test_CT {
1631 var MSC_ConnHdlr vc_conn;
1632
Harald Welte89d42e82017-12-17 16:42:41 +01001633 f_init(1, true);
Harald Welte552620d2017-12-16 23:21:36 +01001634 f_sleep(1.0);
1635
Harald Welte8863fa12018-05-10 20:15:27 +02001636 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5_1_codec_missing));
Harald Welte552620d2017-12-16 23:21:36 +01001637 vc_conn.done;
1638}
1639
Harald Welte552620d2017-12-16 23:21:36 +01001640private function f_tc_assignment_fr_a5_4(charstring id) runs on MSC_ConnHdlr {
Harald Weltea0630032018-03-20 21:09:55 +01001641 g_pars := valueof(t_def_TestHdlrPars);
Harald Welteed848512018-05-24 22:27:58 +02001642 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
1643 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte552620d2017-12-16 23:21:36 +01001644 const OCT8 kc := '0001020304050607'O;
1645 const OCT16 kc128 := kc & kc;
1646
1647 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
1648 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
Harald Weltea0630032018-03-20 21:09:55 +01001649 f_establish_fully(ass_cmd, exp_compl);
Harald Welte38b2a102017-12-23 02:42:58 +01001650 f_cipher_mode('10'O, kc, kc128, true);
Harald Welte552620d2017-12-16 23:21:36 +01001651 /* TODO: expect GSM0808_CAUSE_CIPHERING_ALGORITHM_NOT_SUPPORTED cause value */
Harald Welte552620d2017-12-16 23:21:36 +01001652}
Harald Welte552620d2017-12-16 23:21:36 +01001653testcase TC_assignment_fr_a5_4() runs on test_CT {
1654 var MSC_ConnHdlr vc_conn;
1655
Harald Welte89d42e82017-12-17 16:42:41 +01001656 f_init(1, true);
Harald Welte552620d2017-12-16 23:21:36 +01001657 f_sleep(1.0);
1658
Harald Welte8863fa12018-05-10 20:15:27 +02001659 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5_4));
Harald Welte552620d2017-12-16 23:21:36 +01001660 vc_conn.done;
1661}
1662
1663
Harald Welte4532e0a2017-12-23 02:05:44 +01001664private function f_tc_assignment_sign(charstring id) runs on MSC_ConnHdlr {
Philipp Maier6a50c7c2018-04-16 16:15:59 +02001665 g_pars := valueof(t_def_TestHdlrPars);
Harald Welte4532e0a2017-12-23 02:05:44 +01001666 var template PDU_BSSAP exp_compl := tr_BSSMAP_AssignmentComplete(omit, omit);
1667 var PDU_BSSAP ass_cmd := valueof(ts_BSSMAP_AssignmentReq(omit, omit));
1668
1669 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelTypeSIGNAL);
Harald Weltea0630032018-03-20 21:09:55 +01001670 f_establish_fully(ass_cmd, exp_compl);
Harald Welte4532e0a2017-12-23 02:05:44 +01001671}
1672
1673testcase TC_assignment_sign() runs on test_CT {
1674 var MSC_ConnHdlr vc_conn;
1675
1676 f_init(1, true);
1677 f_sleep(1.0);
1678
Harald Welte8863fa12018-05-10 20:15:27 +02001679 vc_conn := f_start_handler(refers(f_tc_assignment_sign));
Harald Welte4532e0a2017-12-23 02:05:44 +01001680 vc_conn.done;
1681}
1682
Harald Welte60aa5762018-03-21 19:33:13 +01001683/***********************************************************************
1684 * Codec (list) testing
1685 ***********************************************************************/
1686
1687/* check if the given rsl_mode is compatible with the a_elem */
1688private function f_match_codec(BSSMAP_FIELD_CodecElement a_elem, RSL_IE_ChannelMode rsl_mode)
1689return boolean {
1690 select (a_elem.codecType) {
1691 case (GSM_FR) {
1692 if (match(rsl_mode, tr_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM1))) {
1693 return true;
1694 }
1695 }
1696 case (GSM_HR) {
1697 if (match(rsl_mode, tr_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1))) {
1698 return true;
1699 }
1700 }
1701 case (GSM_EFR) {
1702 if (match(rsl_mode, tr_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM2))) {
1703 return true;
1704 }
1705 }
1706 case (FR_AMR) {
1707 if (match(rsl_mode, tr_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM3))) {
1708 return true;
1709 }
1710 }
1711 case (HR_AMR) {
1712 if (match(rsl_mode, tr_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM3))) {
1713 return true;
1714 }
1715 }
1716 case else { }
1717 }
1718 return false;
1719}
1720
1721/* check if the given rsl_mode is compatible with the a_list */
1722private function f_match_codecs(BSSMAP_IE_SpeechCodecList a_list, RSL_IE_ChannelMode rsl_mode)
1723return boolean {
1724 for (var integer i := 0; i < sizeof(a_list); i := i+1) {
1725 if (f_match_codec(a_list.codecElements[i], rsl_mode)) {
1726 return true;
1727 }
1728 }
1729 return false;
1730}
1731
1732/* determine BSSMAP_IE_ChannelType from *first* element of BSSMAP_FIELD_CodecElement */
1733private function f_BSSMAP_chtype_from_codec(BSSMAP_FIELD_CodecElement a_elem)
1734return BSSMAP_IE_ChannelType {
1735 /* FIXME: actually look at all elements of BSSMAP_IE_SpeechCodecList */
1736 var BSSMAP_IE_ChannelType ret := valueof(ts_BSSMAP_IE_ChannelType);
1737 select (a_elem.codecType) {
1738 case (GSM_FR) {
1739 ret.channelRateAndType := ChRate_TCHF;
1740 ret.speechId_DataIndicator := Spdi_TCHF_FR;
1741 }
1742 case (GSM_HR) {
1743 ret.channelRateAndType := ChRate_TCHH;
1744 ret.speechId_DataIndicator := Spdi_TCHH_HR;
1745 }
1746 case (GSM_EFR) {
1747 ret.channelRateAndType := ChRate_TCHF;
1748 ret.speechId_DataIndicator := Spdi_TCHF_EFR;
1749 }
1750 case (FR_AMR) {
1751 ret.channelRateAndType := ChRate_TCHF;
1752 ret.speechId_DataIndicator := Spdi_TCHF_AMR;
1753 }
1754 case (HR_AMR) {
1755 ret.channelRateAndType := ChRate_TCHH;
1756 ret.speechId_DataIndicator := Spdi_TCHH_AMR;
1757 }
1758 case else {
1759 setverdict(fail, "Unsupported codec ", a_elem);
1760 self.stop;
1761 }
1762 }
1763 return ret;
1764}
1765
Harald Weltea63b9102018-03-22 20:36:16 +01001766private function f_rsl_chmod_tmpl_from_codec(BSSMAP_FIELD_CodecElement a_elem)
1767return template RSL_IE_Body {
1768 var template RSL_IE_Body mode_ie := {
1769 chan_mode := {
1770 len := ?,
1771 reserved := ?,
1772 dtx_d := ?,
1773 dtx_u := ?,
1774 spd_ind := RSL_SPDI_SPEECH,
1775 ch_rate_type := -,
1776 coding_alg_rate := -
1777 }
1778 }
1779
1780 select (a_elem.codecType) {
1781 case (GSM_FR) {
1782 mode_ie.chan_mode.ch_rate_type := RSL_CHRT_TCH_F;
1783 mode_ie.chan_mode.coding_alg_rate := RSL_CMOD_SP_GSM1;
1784 }
1785 case (GSM_HR) {
1786 mode_ie.chan_mode.ch_rate_type := RSL_CHRT_TCH_H;
1787 mode_ie.chan_mode.coding_alg_rate := RSL_CMOD_SP_GSM1;
1788 }
1789 case (GSM_EFR) {
1790 mode_ie.chan_mode.ch_rate_type := RSL_CHRT_TCH_F;
1791 mode_ie.chan_mode.coding_alg_rate := RSL_CMOD_SP_GSM2;
1792 }
1793 case (FR_AMR) {
1794 mode_ie.chan_mode.ch_rate_type := RSL_CHRT_TCH_F;
1795 mode_ie.chan_mode.coding_alg_rate := RSL_CMOD_SP_GSM3;
1796 }
1797 case (HR_AMR) {
1798 mode_ie.chan_mode.ch_rate_type := RSL_CHRT_TCH_H;
1799 mode_ie.chan_mode.coding_alg_rate := RSL_CMOD_SP_GSM3;
1800 }
1801 }
1802 return mode_ie;
1803}
1804
Harald Welte60aa5762018-03-21 19:33:13 +01001805type record CodecListTest {
1806 BSSMAP_IE_SpeechCodecList codec_list,
1807 charstring id
1808}
1809type record of CodecListTest CodecListTests
1810
1811private function f_TC_assignment_codec(charstring id) runs on MSC_ConnHdlr {
Harald Welteed848512018-05-24 22:27:58 +02001812 var PDU_BSSAP ass_cmd := f_gen_ass_req();
1813 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
Harald Welte60aa5762018-03-21 19:33:13 +01001814
1815 /* puzzle together the ASSIGNMENT REQ for given codec[s] */
Harald Welte79f3f542018-05-25 20:02:37 +02001816 if (mp_bssap_cfg.transport == BSSAP_TRANSPORT_AoIP) {
1817 ass_cmd.pdu.bssmap.assignmentRequest.codecList := g_pars.ass_codec_list;
1818 exp_compl.pdu.bssmap.assignmentComplete.speechCodec.codecElements[0] :=
1819 g_pars.ass_codec_list.codecElements[0];
1820 }
Harald Welte60aa5762018-03-21 19:33:13 +01001821 ass_cmd.pdu.bssmap.assignmentRequest.channelType :=
1822 f_BSSMAP_chtype_from_codec(g_pars.ass_codec_list.codecElements[0]);
Harald Welte60aa5762018-03-21 19:33:13 +01001823 log("expecting ASS COMPL like this: ", exp_compl);
1824
1825 f_establish_fully(ass_cmd, exp_compl);
Harald Weltea63b9102018-03-22 20:36:16 +01001826
1827 /* Verify that the RSL-side activation actually matches our expectations */
1828 var RSL_Message rsl := f_rslem_get_last_act(RSL_PROC, 0, g_chan_nr);
1829
1830 var RSL_IE_Body mode_ie;
1831 if (f_rsl_find_ie(rsl, RSL_IE_CHAN_MODE, mode_ie) == false) {
1832 setverdict(fail, "Couldn't find CHAN_MODE IE");
1833 self.stop;
1834 }
1835 var template RSL_IE_Body t_mode_ie := f_rsl_chmod_tmpl_from_codec(g_pars.ass_codec_list.codecElements[0]);
1836 if (not match(mode_ie, t_mode_ie)) {
1837 setverdict(fail, "RSL Channel Mode IE doesn't match expectation");
1838 }
Harald Welte60aa5762018-03-21 19:33:13 +01001839}
1840
1841testcase TC_assignment_codec_fr() runs on test_CT {
1842 var TestHdlrParams pars := valueof(t_def_TestHdlrPars);
1843 var MSC_ConnHdlr vc_conn;
1844
1845 f_init(1, true);
1846 f_sleep(1.0);
1847
1848 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
Harald Welte8863fa12018-05-10 20:15:27 +02001849 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
Harald Welte60aa5762018-03-21 19:33:13 +01001850 vc_conn.done;
1851}
1852
1853testcase TC_assignment_codec_hr() runs on test_CT {
1854 var TestHdlrParams pars := valueof(t_def_TestHdlrPars);
1855 var MSC_ConnHdlr vc_conn;
1856
1857 f_init(1, true);
1858 f_sleep(1.0);
1859
1860 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecHR}));
Harald Welte8863fa12018-05-10 20:15:27 +02001861 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
Harald Welte60aa5762018-03-21 19:33:13 +01001862 vc_conn.done;
1863}
1864
1865testcase TC_assignment_codec_efr() 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_CodecEFR}));
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_amr_f() 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_CodecAMR_F}));
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_amr_h() 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_CodecAMR_H}));
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
Harald Welte898113b2018-01-31 18:32:21 +01001901/* test if L3 RR CLASSMARK CHANGE is translated to BSSMAP CLASSMARK UPDATE */
1902private function f_tc_classmark(charstring id) runs on MSC_ConnHdlr {
Harald Weltea0630032018-03-20 21:09:55 +01001903 g_pars := valueof(t_def_TestHdlrPars);
1904 f_create_chan_and_exp();
Harald Welte898113b2018-01-31 18:32:21 +01001905 /* we should now have a COMPL_L3 at the MSC */
1906 BSSAP.receive(tr_BSSMAP_ComplL3);
1907
1908 f_rsl_send_l3(ts_RRM_CM_CHG(valueof(ts_CM2)));
1909 BSSAP.receive(tr_BSSMAP_ClassmarkUpd(?, omit));
1910 setverdict(pass);
1911}
1912testcase TC_classmark() runs on test_CT {
1913 var MSC_ConnHdlr vc_conn;
1914 f_init(1, true);
1915 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02001916 vc_conn := f_start_handler(refers(f_tc_classmark));
Harald Welte898113b2018-01-31 18:32:21 +01001917 vc_conn.done;
1918}
1919
Harald Weltee3bd6582018-01-31 22:51:25 +01001920private function f_est_single_l3(template PDU_ML3_MS_NW l3) runs on MSC_ConnHdlr {
Harald Weltea0630032018-03-20 21:09:55 +01001921 g_pars := valueof(t_def_TestHdlrPars);
1922 f_create_chan_and_exp();
Harald Welte898113b2018-01-31 18:32:21 +01001923 /* we should now have a COMPL_L3 at the MSC */
1924 BSSAP.receive(tr_BSSMAP_ComplL3);
1925
Harald Weltee3bd6582018-01-31 22:51:25 +01001926 /* send the single message we want to send */
1927 f_rsl_send_l3(l3);
1928}
1929
1930private function f_bssap_expect_nothing(float sec := 5.00) runs on MSC_ConnHdlr {
1931 timer T := sec;
1932 var PDU_BSSAP bssap;
Harald Welte898113b2018-01-31 18:32:21 +01001933 T.start;
1934 alt {
Harald Weltee3bd6582018-01-31 22:51:25 +01001935 [] BSSAP.receive(PDU_BSSAP:?) -> value bssap {
1936 setverdict(fail, "Unexpected BSSMAP ", bssap);
1937 self.stop;
Harald Welte898113b2018-01-31 18:32:21 +01001938 }
1939 [] T.timeout {
1940 setverdict(pass);
1941 }
1942 }
1943}
1944
Harald Weltee3bd6582018-01-31 22:51:25 +01001945/* unsolicited ASSIGNMENT FAIL (without ASSIGN) from MS shouldn't bring BSC down */
1946private function f_tc_unsol_ass_fail(charstring id) runs on MSC_ConnHdlr {
1947 f_est_single_l3(ts_RRM_AssignmentFailure('00'O));
1948 f_bssap_expect_nothing();
1949}
Harald Welte898113b2018-01-31 18:32:21 +01001950testcase TC_unsol_ass_fail() 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_unsol_ass_fail));
Harald Welte898113b2018-01-31 18:32:21 +01001955 vc_conn.done;
1956}
Harald Welte552620d2017-12-16 23:21:36 +01001957
Harald Welteea99a002018-01-31 20:46:43 +01001958
1959/* unsolicited ASSIGNMENT COMPLETE (without ASSIGN) from MS shouldn't bring BSC down */
1960private function f_tc_unsol_ass_compl(charstring id) runs on MSC_ConnHdlr {
Harald Weltee3bd6582018-01-31 22:51:25 +01001961 f_est_single_l3(ts_RRM_AssignmentComplete('00'O));
1962 f_bssap_expect_nothing();
Harald Welteea99a002018-01-31 20:46:43 +01001963}
1964testcase TC_unsol_ass_compl() runs on test_CT {
1965 var MSC_ConnHdlr vc_conn;
1966 f_init(1, true);
1967 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02001968 vc_conn := f_start_handler(refers(f_tc_unsol_ass_compl));
Harald Welteea99a002018-01-31 20:46:43 +01001969 vc_conn.done;
1970}
1971
1972
Harald Weltefbf9b5e2018-01-31 20:41:23 +01001973/* unsolicited HANDOVER FAIL (without ASSIGN) from MS shouldn't bring BSC down */
1974private function f_tc_unsol_ho_fail(charstring id) runs on MSC_ConnHdlr {
Harald Weltee3bd6582018-01-31 22:51:25 +01001975 f_est_single_l3(ts_RRM_HandoverFailure('00'O));
1976 f_bssap_expect_nothing();
Harald Weltefbf9b5e2018-01-31 20:41:23 +01001977}
Harald Weltefbf9b5e2018-01-31 20:41:23 +01001978testcase TC_unsol_ho_fail() runs on test_CT {
1979 var MSC_ConnHdlr vc_conn;
1980 f_init(1, true);
1981 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02001982 vc_conn := f_start_handler(refers(f_tc_unsol_ho_fail));
Harald Weltefbf9b5e2018-01-31 20:41:23 +01001983 vc_conn.done;
1984}
1985
1986
Harald Weltee3bd6582018-01-31 22:51:25 +01001987/* short message from MS should be ignored */
1988private function f_tc_err_82_short_msg(charstring id) runs on MSC_ConnHdlr {
Harald Weltea0630032018-03-20 21:09:55 +01001989 g_pars := valueof(t_def_TestHdlrPars);
1990 f_create_chan_and_exp();
Harald Weltee3bd6582018-01-31 22:51:25 +01001991 /* we should now have a COMPL_L3 at the MSC */
1992 BSSAP.receive(tr_BSSMAP_ComplL3);
1993
1994 /* send short message */
1995 RSL.send(ts_RSL_DATA_IND(g_chan_nr, valueof(ts_RslLinkID_DCCH(0)), ''O));
1996 f_bssap_expect_nothing();
1997}
1998testcase TC_err_82_short_msg() runs on test_CT {
1999 var MSC_ConnHdlr vc_conn;
2000 f_init(1, true);
2001 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02002002 vc_conn := f_start_handler(refers(f_tc_err_82_short_msg));
Harald Weltee3bd6582018-01-31 22:51:25 +01002003 vc_conn.done;
2004}
2005
2006
Harald Weltee9e02e42018-01-31 23:36:25 +01002007/* 24.008 8.4 Unknown message must trigger RR STATUS */
2008private function f_tc_err_84_unknown_msg(charstring id) runs on MSC_ConnHdlr {
2009 f_est_single_l3(ts_RRM_UL_REL('00'O));
2010 timer T := 3.0
2011 alt {
2012 [] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch tr_RRM_RR_STATUS)) {
2013 setverdict(pass);
2014 }
2015 [] BSSAP.receive { setverdict(fail, "unexpected BSSAP"); }
Harald Welte458fd372018-03-21 11:26:23 +01002016 [] T.timeout { setverdict(fail, "Timeout waiting for RR STATUS"); }
Harald Weltee9e02e42018-01-31 23:36:25 +01002017 }
2018}
2019testcase TC_err_84_unknown_msg() runs on test_CT {
2020 var MSC_ConnHdlr vc_conn;
2021 f_init(1, true);
2022 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02002023 vc_conn := f_start_handler(refers(f_tc_err_84_unknown_msg));
Harald Weltee9e02e42018-01-31 23:36:25 +01002024 vc_conn.done;
2025}
2026
Harald Welte94e0c342018-04-07 11:33:23 +02002027/* execute a "bts <0-255> trx <0-255> timeslot <0-7> " command on given Dchan */
2028private function f_vty_ts_action(charstring suffix, integer bts_nr, integer trx_nr, integer ts_nr)
2029runs on test_CT {
2030 var charstring cmd := "bts "&int2str(bts_nr)&" trx "&int2str(trx_nr)&
2031 " timeslot "&int2str(ts_nr)&" ";
2032 f_vty_transceive(BSCVTY, cmd & suffix);
2033}
2034
Harald Welte261af4b2018-02-12 21:20:39 +01002035/* execute a "bts <0-255> trx <0-255> timeslot <0-7> sub-slot <0-7>" command on given Dchan */
2036private function f_vty_ss_action(charstring suffix, integer bts_nr, integer trx_nr, RslChannelNr chan_nr)
2037runs on MSC_ConnHdlr {
2038 /* FIXME: resolve those from component-global state */
2039 var integer ts_nr := chan_nr.tn;
2040 var integer ss_nr;
2041 if (ischosen(chan_nr.u.ch0)) {
2042 ss_nr := 0;
2043 } else if (ischosen(chan_nr.u.lm)) {
2044 ss_nr := chan_nr.u.lm.sub_chan;
2045 } else if (ischosen(chan_nr.u.sdcch4)) {
2046 ss_nr := chan_nr.u.sdcch4.sub_chan;
2047 } else if (ischosen(chan_nr.u.sdcch8)) {
2048 ss_nr := chan_nr.u.sdcch8.sub_chan;
2049 } else {
2050 setverdict(fail, "Invalid ChanNr ", chan_nr);
2051 self.stop;
2052 }
2053
2054 var charstring cmd := "bts "&int2str(bts_nr)&" trx "&int2str(trx_nr)&
2055 " timeslot "&int2str(ts_nr)&" sub-slot "&int2str(ss_nr)&" ";
2056 f_vty_transceive(BSCVTY, cmd & suffix);
2057}
2058
2059private function f_vty_handover(integer bts_nr, integer trx_nr, RslChannelNr chan_nr,
2060 integer new_bts_nr)
2061runs on MSC_ConnHdlr {
2062 f_vty_ss_action("handover " & int2str(new_bts_nr), bts_nr, trx_nr, chan_nr);
2063}
2064
2065/* intra-BSC hand-over between BTS0 and BTS1 */
2066private function f_tc_ho_int(charstring id) runs on MSC_ConnHdlr {
Harald Weltea0630032018-03-20 21:09:55 +01002067 g_pars := valueof(t_def_TestHdlrPars);
Harald Welteed848512018-05-24 22:27:58 +02002068 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
2069 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte261af4b2018-02-12 21:20:39 +01002070 const OCT8 kc := '0001020304050607'O;
2071
2072 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
2073 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
2074
Harald Weltea0630032018-03-20 21:09:55 +01002075 f_establish_fully(ass_cmd, exp_compl);
Harald Welte261af4b2018-02-12 21:20:39 +01002076
2077 var HandoverState hs := {
2078 rr_ho_cmpl_seen := false,
2079 handover_done := false,
2080 old_chan_nr := -
2081 };
2082 /* issue hand-over command on VTY */
2083 f_vty_handover(0, 0, g_chan_nr, 1);
2084 /* temporarily suspend DChan processing on BTS1 to avoid race with RSLEM_register */
2085 f_rslem_suspend(RSL1_PROC);
2086 alt {
2087 [] as_handover(hs);
2088 /* FIXME: somehow determine that the hand-over has completed, by MGCP MDCX? */
2089 }
2090}
2091
2092testcase TC_ho_int() runs on test_CT {
2093 var MSC_ConnHdlr vc_conn;
2094 f_init(2, true);
2095 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02002096 vc_conn := f_start_handler(refers(f_tc_ho_int));
Harald Welte261af4b2018-02-12 21:20:39 +01002097 vc_conn.done;
2098}
Harald Weltee9e02e42018-01-31 23:36:25 +01002099
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +01002100/* OS#3041: Open and close N connections in a normal fashion, and expect no
2101 * BSSMAP Reset just because of that. */
2102testcase TC_bssap_rlsd_does_not_cause_bssmap_reset() runs on test_CT {
2103 var default d;
2104 var integer i;
2105 var DchanTuple dt;
2106
2107 f_init();
2108
2109 /* Wait for initial BSSMAP Reset to pass */
2110 f_sleep(4.0);
2111
2112 d := activate(no_bssmap_reset());
2113
2114 /* Setup up a number of connections and RLSD them again from the MSC
2115 * side. In the buggy behavior, the fourth one triggers BSSMAP Reset.
2116 * Let's do it some more times for good measure. */
Harald Weltec3260d92018-06-11 17:48:16 +02002117 for (i := 0; i < 4; i := i+1) {
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +01002118 /* Since we're doing a lot of runs, give each one a fresh
2119 * T_guard from the top. */
2120 T_guard.start;
2121
2122 /* Setup a BSSAP connection and clear it right away. This is
2123 * the MSC telling the BSC about a planned release, it's not an
2124 * erratic loss of a connection. */
Harald Weltea1897182018-06-11 13:53:09 +02002125 dt := f_est_dchan(int2oct(i,1), 23+i, '00010203040506'O);
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +01002126
2127 /* MSC disconnects (RLSD). */
2128 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
2129 }
2130
2131 /* In the buggy behavior, a timeout of 2 seconds happens between above
2132 * trigger (logs "SIGTRAN connection down, reconnecting...") and the
2133 * actual BSSMAP Reset. Wait a bit longer just to make sure. */
2134 f_sleep(4.0);
2135
2136 deactivate(d);
2137 f_shutdown_helper();
2138}
Harald Welte552620d2017-12-16 23:21:36 +01002139
Neels Hofmeyr4ff93282018-03-12 04:25:35 +01002140/* OS#3041: Open and close N connections in a normal fashion, and expect no
2141 * BSSMAP Reset just because of that. Invoke the release by a BSSMAP Clear from
2142 * the MSC. */
2143testcase TC_bssmap_clear_does_not_cause_bssmap_reset() runs on test_CT {
2144 var default d;
2145 var integer i;
2146 var DchanTuple dt;
2147 var BSSAP_N_DATA_ind rx_di;
Neels Hofmeyr4ff93282018-03-12 04:25:35 +01002148 var myBSSMAP_Cause cause_val := GSM0808_CAUSE_CALL_CONTROL;
2149 var BssmapCause cause := enum2int(cause_val);
2150
2151 f_init();
2152
2153 /* Wait for initial BSSMAP Reset to pass */
2154 f_sleep(4.0);
2155
2156 d := activate(no_bssmap_reset());
2157
2158 /* Setup up a number of connections and RLSD them again from the MSC
2159 * side. In the buggy behavior, the fourth one triggers BSSMAP Reset.
2160 * Let's do it some more times for good measure. */
2161 for (i := 0; i < 8; i := i+1) {
2162 /* Since we're doing a lot of runs, give each one a fresh
2163 * T_guard from the top. */
2164 T_guard.start;
2165
2166 /* Setup a BSSAP connection and clear it right away. This is
2167 * the MSC telling the BSC about a planned release, it's not an
2168 * erratic loss of a connection. */
Harald Weltea1897182018-06-11 13:53:09 +02002169 dt := f_est_dchan(int2oct(i,1), 23+i, '00010203040506'O);
Neels Hofmeyr4ff93282018-03-12 04:25:35 +01002170
2171 /* Instruct BSC to clear channel */
2172 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
2173
2174 /* expect BSC to disable the channel */
Harald Welte641fcbe2018-06-14 10:58:35 +02002175 f_exp_chan_rel_and_clear(dt, 0);
Neels Hofmeyr4ff93282018-03-12 04:25:35 +01002176 }
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}
2186
Neels Hofmeyrfd445c32018-03-09 15:39:31 +01002187/* OS#3041: Open and close N connections in a normal fashion, and expect no
2188 * BSSMAP Reset just because of that. Close connections from the MS side with a
2189 * Release Ind on RSL. */
2190testcase TC_ms_rel_ind_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 Hofmeyrfd445c32018-03-09 15:39:31 +01002195 var integer j;
2196
2197 f_init();
2198
2199 /* Wait for initial BSSMAP Reset to pass */
2200 f_sleep(4.0);
2201
2202 d := activate(no_bssmap_reset());
2203
2204 /* Setup up a number of connections and RLSD them again from the MSC
2205 * side. In the buggy behavior, the fourth one triggers BSSMAP Reset.
2206 * Let's do it some more times for good measure. */
2207 for (i := 0; i < 8; i := i+1) {
2208 /* Since we're doing a lot of runs, give each one a fresh
2209 * T_guard from the top. */
2210 T_guard.start;
2211
2212 /* Setup a BSSAP connection and clear it right away. This is
2213 * the MSC telling the BSC about a planned release, it's not an
2214 * erratic loss of a connection. */
2215 dt := f_est_dchan('23'O, 23, '00010203040506'O);
2216
2217 /* simulate RLL REL IND */
2218 f_ipa_tx(0, ts_RSL_REL_IND(dt.rsl_chan_nr, valueof(ts_RslLinkID_DCCH(0))));
2219
2220 /* expect Clear Request on MSC side */
2221 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearRequest)) -> value rx_di;
2222
2223 /* Instruct BSC to clear channel */
2224 var BssmapCause cause := bit2int(rx_di.userData.pdu.bssmap.clearRequest.cause.causeValue);
2225 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
2226
2227 /* expect BSC to disable the channel */
Harald Welte641fcbe2018-06-14 10:58:35 +02002228 f_exp_chan_rel_and_clear(dt, 0);
Neels Hofmeyrfd445c32018-03-09 15:39:31 +01002229 }
2230
2231 /* In the buggy behavior, a timeout of 2 seconds happens between above
2232 * trigger (logs "SIGTRAN connection down, reconnecting...") and the
2233 * actual BSSMAP Reset. Wait a bit longer just to make sure. */
2234 f_sleep(4.0);
2235
2236 deactivate(d);
2237 f_shutdown_helper();
2238}
2239
Harald Welte94e0c342018-04-07 11:33:23 +02002240/***********************************************************************
2241 * IPA style dynamic PDCH
2242 ***********************************************************************/
2243
2244private function f_dyn_ipa_pdch_act(integer bts_nr, integer trx_nr, integer ts_nr,
2245 template (omit) RSL_Cause nack := omit)
2246runs on test_CT {
2247 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(ts_nr));
2248 var RSL_Message rsl_unused;
2249 /* ask BSC via VTY to activate a given IPA style chan as PDCH */
2250 f_vty_ts_action("pdch activate", bts_nr, trx_nr, ts_nr);
2251 /* expect the BSC to issue the related RSL command */
2252 rsl_unused := f_exp_ipa_rx(0, tr_RSL_IPA_PDCH_ACT(chan_nr));
2253 if (istemplatekind(nack, "omit")) {
2254 /* respond with a related acknowledgement */
2255 f_ipa_tx(0, ts_RSL_IPA_PDCH_ACT_ACK(chan_nr, ts_RSL_IE_FrameNumber(2342)));
2256 } else {
2257 f_ipa_tx(0, ts_RSL_IPA_PDCH_ACT_NACK(chan_nr, valueof(nack)));
2258 }
2259}
2260
2261private function f_dyn_ipa_pdch_deact(integer bts_nr, integer trx_nr, integer ts_nr,
2262 template (omit) RSL_Cause nack := omit)
2263runs on test_CT {
2264 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(ts_nr));
2265 var RSL_Message rsl_unused;
2266 /* ask BSC via VTY to activate a given IPA style chan as PDCH */
2267 f_vty_ts_action("pdch deactivate", bts_nr, trx_nr, ts_nr);
2268 /* expect the BSC to issue the related RSL command */
2269 rsl_unused := f_exp_ipa_rx(0, tr_RSL_IPA_PDCH_DEACT(chan_nr));
2270 if (istemplatekind(nack, "omit")) {
2271 /* respond with a related acknowledgement */
2272 f_ipa_tx(0, ts_RSL_IPA_PDCH_DEACT_ACK(chan_nr));
2273 } else {
2274 f_ipa_tx(0, ts_RSL_IPA_PDCH_DEACT_NACK(chan_nr, valueof(nack)));
2275 }
2276}
2277
2278private function f_ts_dyn_mode_get(integer bts_nr, integer trx_nr, integer ts_nr)
2279runs on test_CT return charstring {
2280 var charstring cmd, resp;
2281 cmd := "show timeslot "&int2str(bts_nr)&" "&int2str(trx_nr)&" "&int2str(ts_nr);
2282 resp := f_vty_transceive_ret(BSCVTY, cmd);
2283 return regexp(resp, "*\((*)\)*", 0);
2284}
2285
2286private function f_ts_dyn_mode_assert(integer bts_nr, integer trx_nr, integer ts_nr,
2287 template charstring exp)
2288runs on test_CT {
2289 var charstring mode := f_ts_dyn_mode_get(bts_nr, trx_nr, ts_nr);
2290 if (not match(mode, exp)) {
2291 setverdict(fail, "Unexpected TS Mode: ", mode);
2292 self.stop;
2293 }
2294}
2295
2296private function f_ts_set_chcomb(integer bts_nr, integer trx_nr, integer ts_nr, charstring chcomb)
2297runs on test_CT {
2298 f_vty_enter_cfg_ts(BSCVTY, bts_nr, trx_nr, ts_nr);
2299 f_vty_transceive(BSCVTY, "phys_chan_config " & chcomb);
2300 f_vty_transceive(BSCVTY, "end");
2301}
2302
2303private const charstring TCHF_MODE := "TCH/F mode";
2304private const charstring TCHH_MODE := "TCH/H mode";
2305private const charstring PDCH_MODE := "PDCH mode";
2306private const charstring NONE_MODE := "NONE mode";
2307
2308/* Test IPA PDCH activation / deactivation triggered by VTY */
2309testcase TC_dyn_pdch_ipa_act_deact() runs on test_CT {
2310 var RSL_Message rsl_unused;
2311
2312 /* change Timeslot 6 before f_init() starts RSL */
2313 f_init_vty();
2314 f_ts_set_chcomb(0, 0, 6, "TCH/F_PDCH");
2315 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
2316
2317 f_init(1, false);
2318 f_sleep(1.0);
2319
2320 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(6));
2321
2322 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
2323 /* The BSC will activate the dynamic PDCH by default, so confirm that */
2324 rsl_unused := f_exp_ipa_rx(0, tr_RSL_IPA_PDCH_ACT(chan_nr));
2325 f_ipa_tx(0, ts_RSL_IPA_PDCH_ACT_ACK(chan_nr, ts_RSL_IE_FrameNumber(2342)));
2326 f_sleep(1.0);
2327 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, PDCH_MODE);
2328
2329 /* De-activate it via VTY */
2330 f_dyn_ipa_pdch_deact(0, 0, chan_nr.tn);
2331 f_sleep(1.0);
2332 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
2333
2334 /* re-activate it via VTY */
2335 f_dyn_ipa_pdch_act(0, 0, chan_nr.tn);
2336 f_sleep(1.0);
2337 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, PDCH_MODE);
2338
2339 /* and finally de-activate it again */
2340 f_dyn_ipa_pdch_deact(0, 0, chan_nr.tn);
2341 f_sleep(1.0);
2342 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
2343
2344 setverdict(pass);
2345}
2346
2347/* Test IPA PDCH activation NACK */
2348testcase TC_dyn_pdch_ipa_act_nack() runs on test_CT {
2349 var RSL_Message rsl_unused;
2350
2351 /* change Timeslot 6 before f_init() starts RSL */
2352 f_init_vty();
2353 f_ts_set_chcomb(0, 0, 6, "TCH/F_PDCH");
2354 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
2355
2356 f_init(1, false);
2357 f_sleep(1.0);
2358
2359 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(6));
2360
2361 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
2362 /* The BSC will activate the dynamic PDCH by default, so confirm that */
2363 rsl_unused := f_exp_ipa_rx(0, tr_RSL_IPA_PDCH_ACT(chan_nr));
2364 f_ipa_tx(0, ts_RSL_IPA_PDCH_ACT_ACK(chan_nr, ts_RSL_IE_FrameNumber(2342)));
2365 f_sleep(1.0);
2366 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, PDCH_MODE);
2367
2368 /* De-activate it via VTY */
2369 f_dyn_ipa_pdch_deact(0, 0, chan_nr.tn);
2370 f_sleep(1.0);
2371 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
2372
2373 /* re-activate it via VTY, but fail that; check BSC still assumes TCH/F mode */
2374 f_dyn_ipa_pdch_act(0, 0, chan_nr.tn, RSL_ERR_EQUIPMENT_FAIL);
2375 f_sleep(1.0);
2376 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
2377
2378 setverdict(pass);
2379}
2380
2381
2382/***********************************************************************
2383 * Osmocom style dynamic PDCH
2384 ***********************************************************************/
2385
2386private function f_dyn_osmo_pdch_act(integer bts_nr, integer trx_nr, integer ts_nr,
2387 template (omit) RSL_Cause nack := omit)
2388runs on test_CT {
2389 var RslChannelNr chan_nr := valueof(t_RslChanNr_PDCH(ts_nr));
2390 var RSL_Message rsl_unused;
2391 /* ask BSC via VTY to activate a given IPA style chan as PDCH */
2392 /* FIXME: no VTY command to activate Osmocom PDCH !! */
2393 /* expect the BSC to issue the related RSL command */
2394 rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT(chan_nr, ?));
2395 if (istemplatekind(nack, "omit")) {
2396 /* respond with a related acknowledgement */
2397 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, 2342));
2398 } else {
2399 f_ipa_tx(0, ts_RSL_CHAN_ACT_NACK(chan_nr, valueof(nack)));
2400 }
2401}
2402
2403private function f_dyn_osmo_pdch_deact(integer bts_nr, integer trx_nr, integer ts_nr,
2404 template (omit) RSL_Cause nack := omit)
2405runs on test_CT {
2406 var RslChannelNr chan_nr := valueof(t_RslChanNr_PDCH(ts_nr));
2407 var RSL_Message rsl_unused;
2408 /* ask BSC via VTY to activate a given IPA style chan as PDCH */
2409 /* FIXME: no VTY command to activate Osmocom PDCH !! */
2410 /* expect the BSC to issue the related RSL command */
2411 rsl_unused := f_exp_ipa_rx(0, tr_RSL_RF_CHAN_REL(chan_nr));
2412 if (istemplatekind(nack, "omit")) {
2413 /* respond with a related acknowledgement */
2414 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(chan_nr));
2415 } else {
2416 //f_ipa_tx(0, ts_RSL_RF_CHAN_REL_NACK(chan_nr, valueof(nack)));
2417 }
2418}
2419
2420/* Test Osmocom dyn PDCH activation / deactivation triggered by VTY */
2421testcase TC_dyn_pdch_osmo_act_deact() runs on test_CT {
2422 var RSL_Message rsl_unused;
2423
2424 /* change Timeslot 6 before f_init() starts RSL */
2425 f_init_vty();
2426 f_ts_set_chcomb(0, 0, 6, "TCH/F_TCH/H_PDCH");
2427 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
2428
2429 f_init(1, false);
2430 f_sleep(1.0);
2431
2432 var RslChannelNr chan_nr := valueof(t_RslChanNr_PDCH(6));
2433
2434 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, NONE_MODE);
2435 /* The BSC will activate the dynamic PDCH by default, so confirm that */
2436 rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(chan_nr, ?));
2437
2438 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, 2342));
2439 f_sleep(1.0);
2440 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, PDCH_MODE);
2441
2442 setverdict(pass);
2443}
2444
2445/* Test Osmocom dyn PDCH activation NACK behavior */
2446testcase TC_dyn_pdch_osmo_act_nack() runs on test_CT {
2447 var RSL_Message rsl_unused;
2448
2449 /* change Timeslot 6 before f_init() starts RSL */
2450 f_init_vty();
2451 f_ts_set_chcomb(0, 0, 6, "TCH/F_TCH/H_PDCH");
2452 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
2453
2454 f_init(1, false);
2455 f_sleep(1.0);
2456
2457 var RslChannelNr chan_nr := valueof(t_RslChanNr_PDCH(6));
2458
2459 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, NONE_MODE);
2460 /* The BSC will activate the dynamic PDCH by default, so confirm that */
2461 rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(chan_nr, ?));
2462
2463 /* NACK this activation and expect the "show timeslot" mode still to be NONE */
2464 f_ipa_tx(0, ts_RSL_CHAN_ACT_NACK(chan_nr, RSL_ERR_EQUIPMENT_FAIL));
2465 f_sleep(1.0);
2466 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, NONE_MODE);
2467
2468 setverdict(pass);
2469}
2470
Harald Welte0ea2d5e2018-04-07 21:40:29 +02002471/* Dyn PDCH todo:
2472 * activate OSMO as TCH/F
2473 * activate OSMO as TCH/H
2474 * does the BSC-located PCU socket get the updated INFO?
2475 * what if no PCU is connected at the time?
2476 * is the info correct on delayed PCU (re)connect?
2477 */
Harald Welte94e0c342018-04-07 11:33:23 +02002478
Harald Welte28d943e2017-11-25 15:00:50 +01002479control {
Harald Welte898113b2018-01-31 18:32:21 +01002480 /* CTRL interface testing */
Harald Welte4003d112017-12-09 22:35:39 +01002481 execute( TC_ctrl_msc_connection_status() );
Stefan Sperlingb041b3d2018-01-03 17:14:55 +01002482 execute( TC_ctrl_msc0_connection_status() );
Harald Welte96c94412017-12-09 03:12:45 +01002483 execute( TC_ctrl() );
Harald Welte898113b2018-01-31 18:32:21 +01002484
2485 /* RSL DCHAN Channel ACtivation / Deactivation */
Harald Welteae026692017-12-09 01:03:01 +01002486 execute( TC_chan_act_noreply() );
Harald Welte4003d112017-12-09 22:35:39 +01002487 execute( TC_chan_act_counter() );
Harald Welteae026692017-12-09 01:03:01 +01002488 execute( TC_chan_act_ack_noest() );
2489 execute( TC_chan_act_ack_est_ind_noreply() );
2490 execute( TC_chan_act_ack_est_ind_refused() );
Harald Welte618ef642017-12-14 14:58:20 +01002491 execute( TC_chan_act_nack() );
Harald Welte799c97b2017-12-14 17:50:30 +01002492 execute( TC_chan_exhaustion() );
Harald Welte4003d112017-12-09 22:35:39 +01002493 execute( TC_chan_rel_rll_rel_ind() );
2494 execute( TC_chan_rel_conn_fail() );
2495 execute( TC_chan_rel_hard_clear() );
Harald Welted8c36cd2017-12-09 23:05:31 +01002496 execute( TC_chan_rel_hard_rlsd() );
Harald Welte550daf92018-06-11 19:22:13 +02002497 execute( TC_chan_rel_hard_rlsd_ms_dead() );
Harald Welte85804d42017-12-10 14:11:58 +01002498 execute( TC_chan_rel_a_reset() );
Harald Welte6f521d82017-12-11 19:52:02 +01002499
Harald Weltecfe2c962017-12-15 12:09:32 +01002500 execute( TC_outbound_connect() );
Harald Welte898113b2018-01-31 18:32:21 +01002501
2502 /* Assignment related */
Harald Welte16a4adf2017-12-14 18:54:01 +01002503 execute( TC_assignment_cic_only() );
Harald Welte235ebf12017-12-15 14:18:16 +01002504 execute( TC_assignment_csd() );
2505 execute( TC_assignment_ctm() );
2506 execute( TC_assignment_sign() );
2507 execute( TC_assignment_fr_a5_0() );
2508 execute( TC_assignment_fr_a5_1() );
Harald Welte8f67d1d2018-05-25 20:38:42 +02002509 if (mp_bssap_cfg.transport == BSSAP_TRANSPORT_AoIP) {
2510 execute( TC_assignment_fr_a5_1_codec_missing() );
2511 }
Harald Welte235ebf12017-12-15 14:18:16 +01002512 execute( TC_assignment_fr_a5_3() );
2513 execute( TC_assignment_fr_a5_4() );
Harald Welte3c86ea02018-05-10 22:28:05 +02002514 execute( TC_ciph_mode_a5_0() );
2515 execute( TC_ciph_mode_a5_1() );
2516 execute( TC_ciph_mode_a5_3() );
Harald Welte16a4adf2017-12-14 18:54:01 +01002517
Harald Welte60aa5762018-03-21 19:33:13 +01002518 execute( TC_assignment_codec_fr() );
2519 execute( TC_assignment_codec_hr() );
2520 execute( TC_assignment_codec_efr() );
2521 execute( TC_assignment_codec_amr_f() );
2522 execute( TC_assignment_codec_amr_h() );
2523
Harald Welte898113b2018-01-31 18:32:21 +01002524 /* RLL Establish Indication on inactive DCHAN / SAPI */
Harald Welte5cd20ed2017-12-13 21:03:20 +01002525 execute( TC_rll_est_ind_inact_lchan() );
2526 execute( TC_rll_est_ind_inval_sapi1() );
2527 execute( TC_rll_est_ind_inval_sapi3() );
2528 execute( TC_rll_est_ind_inval_sacch() );
2529
Harald Welte898113b2018-01-31 18:32:21 +01002530 /* Paging related tests */
Harald Welte6f521d82017-12-11 19:52:02 +01002531 execute( TC_paging_imsi_nochan() );
2532 execute( TC_paging_tmsi_nochan() );
2533 execute( TC_paging_tmsi_any() );
2534 execute( TC_paging_tmsi_sdcch() );
2535 execute( TC_paging_tmsi_tch_f() );
2536 execute( TC_paging_tmsi_tch_hf() );
2537 execute( TC_paging_imsi_nochan_cgi() );
2538 execute( TC_paging_imsi_nochan_lac_ci() );
2539 execute( TC_paging_imsi_nochan_ci() );
2540 execute( TC_paging_imsi_nochan_lai() );
2541 execute( TC_paging_imsi_nochan_lac() );
2542 execute( TC_paging_imsi_nochan_all() );
Harald Welte751d3eb2018-01-31 15:51:06 +01002543 execute( TC_paging_imsi_nochan_plmn_lac_rnc() );
2544 execute( TC_paging_imsi_nochan_rnc() );
2545 execute( TC_paging_imsi_nochan_lac_rnc() );
2546 execute( TC_paging_imsi_nochan_lacs() );
2547 execute( TC_paging_imsi_nochan_lacs_empty() );
Stefan Sperling049a86e2018-03-20 15:51:00 +01002548 execute( TC_paging_imsi_nochan_cgi_unknown_cid() );
Harald Welte10985002017-12-12 09:29:15 +01002549 execute( TC_paging_imsi_a_reset() );
Harald Weltee65d40e2017-12-13 00:09:06 +01002550 execute( TC_paging_imsi_load() );
Philipp Maier779a7922018-02-16 11:00:37 +01002551 execute( TC_paging_counter() );
Harald Welte4e9b9cc2017-12-14 18:31:02 +01002552
2553 execute( TC_rsl_drop_counter() );
Stefan Sperling830dc9d2018-02-12 21:08:28 +01002554 execute( TC_rsl_unknown_unit_id() );
2555
2556 execute( TC_oml_unknown_unit_id() );
Harald Welte898113b2018-01-31 18:32:21 +01002557
2558 execute( TC_classmark() );
2559 execute( TC_unsol_ass_fail() );
Harald Welteea99a002018-01-31 20:46:43 +01002560 execute( TC_unsol_ass_compl() );
Harald Weltefbf9b5e2018-01-31 20:41:23 +01002561 execute( TC_unsol_ho_fail() );
Harald Weltee3bd6582018-01-31 22:51:25 +01002562 execute( TC_err_82_short_msg() );
Harald Weltee9e02e42018-01-31 23:36:25 +01002563 execute( TC_err_84_unknown_msg() );
Harald Welte261af4b2018-02-12 21:20:39 +01002564 execute( TC_ho_int() );
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +01002565
2566 execute( TC_bssap_rlsd_does_not_cause_bssmap_reset() );
Neels Hofmeyr4ff93282018-03-12 04:25:35 +01002567 execute( TC_bssmap_clear_does_not_cause_bssmap_reset() );
Neels Hofmeyrfd445c32018-03-09 15:39:31 +01002568 execute( TC_ms_rel_ind_does_not_cause_bssmap_reset() );
Harald Welte94e0c342018-04-07 11:33:23 +02002569
2570 execute( TC_dyn_pdch_ipa_act_deact() );
2571 execute( TC_dyn_pdch_ipa_act_nack() );
2572 execute( TC_dyn_pdch_osmo_act_deact() );
2573 execute( TC_dyn_pdch_osmo_act_nack() );
Harald Welte99f3ca02018-06-14 13:40:29 +02002574
2575 /* at bottom as they might crash OsmoBSC before OS#3182 is fixed */
2576 execute( TC_early_conn_fail() );
2577 execute( TC_late_conn_fail() );
2578
Harald Welte28d943e2017-11-25 15:00:50 +01002579}
2580
2581}