blob: 578d35d7d34c0671be205f9381bdf13d5564ec41 [file] [log] [blame]
Daniel Willmann19b8d902022-01-05 09:12:34 +01001module HNBGW_Tests {
2
3/* Integration Tests for OsmoHNBGW
4 * (C) 2021 by sysmocom - s.f.m.c. GmbH <info@sysmocom.de>
5 * 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 * SPDX-License-Identifier: GPL-2.0-or-later
11 *
12 * This test suite tests OsmoHNBGW while emulating the hNodeB as well as MSC, SGSN, MGW
13 * See README for more details.
14 */
15
16import from Misc_Helpers all;
17import from General_Types all;
18import from GSM_Types all;
19import from Osmocom_Types all;
20import from IPL4asp_Types all;
Neels Hofmeyr1e311462023-01-11 01:19:12 +010021import from Native_Functions all;
Daniel Willmann19b8d902022-01-05 09:12:34 +010022
23import from Osmocom_CTRL_Functions all;
24import from Osmocom_CTRL_Types all;
25import from Osmocom_CTRL_Adapter all;
26
27import from StatsD_Types all;
28import from StatsD_CodecPort all;
29import from StatsD_CodecPort_CtrlFunct all;
30import from StatsD_Checker all;
31
32import from Osmocom_VTY_Functions all;
33import from TELNETasp_PortType all;
34
35import from HNBAP_Templates all;
Harald Welteaf3e2162024-03-27 21:54:20 +010036import from HNBAP_IEs all;
Daniel Willmann19b8d902022-01-05 09:12:34 +010037import from HNBAP_PDU_Descriptions all;
38
39import from RUA_IEs all;
40import from RUA_Templates all;
41import from RUA_Emulation all;
42
43import from Iuh_Emulation all;
44
45import from RANAP_Types all;
46import from RANAP_PDU_Descriptions all;
47import from RANAP_PDU_Contents all;
48import from RANAP_IEs all;
49import from RANAP_Templates all;
Neels Hofmeyrb1bf16d2023-06-27 02:10:04 +020050import from RANAP_CodecPort all;
Daniel Willmann19b8d902022-01-05 09:12:34 +010051
52import from RAN_Adapter all;
Daniel Willmann19b8d902022-01-05 09:12:34 +010053import from RAN_Emulation all;
54
55import from MGCP_Emulation all;
56import from MGCP_Types all;
57import from MGCP_Templates all;
58import from MGCP_CodecPort all;
59import from SDP_Types all;
Pau Espin Pedrol1158cc62024-03-21 17:21:35 +010060import from SDP_Templates all;
Daniel Willmann19b8d902022-01-05 09:12:34 +010061
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +020062import from PFCP_Types all;
63import from PFCP_Emulation all;
64import from PFCP_Templates all;
65import from PFCP_CodecPort all;
66
Neels Hofmeyr75d905b2023-04-27 00:30:25 +020067import from TCCConversion_Functions all;
Neels Hofmeyr7a48df12023-04-20 20:43:43 +020068import from MobileL3_Types all;
Neels Hofmeyr7d0e6802023-04-20 20:43:55 +020069import from MobileL3_CommonIE_Types all;
70import from MobileL3_GMM_SM_Types all;
Neels Hofmeyr7a48df12023-04-20 20:43:43 +020071import from L3_Templates all;
Neels Hofmeyr7d0e6802023-04-20 20:43:55 +020072import from L3_Common all;
Neels Hofmeyr7a48df12023-04-20 20:43:43 +020073
Neels Hofmeyrb1bf16d2023-06-27 02:10:04 +020074import from SCCPasp_Types all;
75
Neels Hofmeyr7a48df12023-04-20 20:43:43 +020076const integer NUM_MSC := 4;
77const integer NUM_SGSN := 4;
78
79const integer FIRST_MSC_IDX := 0;
80const integer FIRST_SGSN_IDX := NUM_MSC;
Neels Hofmeyr75d905b2023-04-27 00:30:25 +020081
Daniel Willmann19b8d902022-01-05 09:12:34 +010082modulepar {
83 /* IP address at which the HNodeB can be reached */
84 charstring mp_hnodeb_ip := "127.0.0.1";
85 integer mp_hnodeb_port := -1;
86
87 /* IP address at which the test binds */
88 charstring mp_hnbgw_ip := "127.0.0.1";
89 integer mp_hnbgw_iuh_port := 29169;
Neels Hofmeyrffcb8892023-06-27 01:09:57 +020090 integer mp_hnbgw_ctrl_port := 4262;
Harald Welte904b5f12024-04-04 02:47:30 +020091 integer mp_hnbgw_statsd_port := 8125;
Daniel Willmann19b8d902022-01-05 09:12:34 +010092
93 charstring mp_mgw_ip := "127.0.0.1";
94 integer mp_mgw_port := 2427;
95
Neels Hofmeyr7a48df12023-04-20 20:43:43 +020096 RAN_Configurations mp_cn_cfg := {
97 /* MSCs (NUM_MSC entries) */
98 {
99 transport := RANAP_TRANSPORT_IuCS,
100 sccp_service_type := "mtp3_itu",
101 sctp_addr := { 23905, "127.0.0.1", 2905, "127.0.0.1" },
102 own_pc := 188, /* 0.23.4 first MSC emulation */
103 own_ssn := 142,
104 peer_pc := 189, /* 0.23.5 osmo-hnbgw */
105 peer_ssn := 142,
106 sio := '83'O,
107 rctx := 1
108 },
109 {
110 transport := RANAP_TRANSPORT_IuCS,
111 sccp_service_type := "mtp3_itu",
112 sctp_addr := { 23907, "127.0.0.1", 2905, "127.0.0.1" },
113 own_pc := 2, /* 0.0.2 second MSC emulation */
114 own_ssn := 142,
115 peer_pc := 189, /* 0.23.5 osmo-hnbgw */
116 peer_ssn := 142,
117 sio := '83'O,
118 rctx := 3
119 },
120 {
121 transport := RANAP_TRANSPORT_IuCS,
122 sccp_service_type := "mtp3_itu",
123 sctp_addr := { 23909, "127.0.0.1", 2905, "127.0.0.1" },
124 own_pc := 3, /* 0.0.3 third MSC emulation */
125 own_ssn := 142,
126 peer_pc := 189, /* 0.23.5 osmo-hnbgw */
127 peer_ssn := 142,
128 sio := '83'O,
129 rctx := 5
130 },
131 {
132 transport := RANAP_TRANSPORT_IuCS,
133 sccp_service_type := "mtp3_itu",
134 sctp_addr := { 23911, "127.0.0.1", 2905, "127.0.0.1" },
135 own_pc := 4, /* 0.0.4 fourth MSC emulation */
136 own_ssn := 142,
137 peer_pc := 189, /* 0.23.5 osmo-hnbgw */
138 peer_ssn := 142,
139 sio := '83'O,
140 rctx := 7
141 },
142
143 /* SGSNs (NUM_SGSN entries) */
144 {
145 transport := RANAP_TRANSPORT_IuCS,
146 sccp_service_type := "mtp3_itu",
147 sctp_addr := { /* local */ 23906, "127.0.0.1", /* remote */ 2905, "127.0.0.1" },
148 own_pc := 185, /* 0.23.1 first SGSN emulation */
149 own_ssn := 142,
150 peer_pc := 189, /* 2237, 1.23.5 osmo-hnbgw */
151 peer_ssn := 142,
152 sio := '83'O,
153 rctx := 2
154 },
155 {
156 transport := RANAP_TRANSPORT_IuCS,
157 sccp_service_type := "mtp3_itu",
158 sctp_addr := { /* local */ 23908, "127.0.0.1", /* remote */ 2905, "127.0.0.1" },
159 own_pc := 10, /* 0.1.2 second SGSN emulation */
160 own_ssn := 142,
161 peer_pc := 189, /* 2237, 1.23.5 osmo-hnbgw */
162 peer_ssn := 142,
163 sio := '83'O,
164 rctx := 4
165 },
166 {
167 transport := RANAP_TRANSPORT_IuCS,
168 sccp_service_type := "mtp3_itu",
169 sctp_addr := { /* local */ 23910, "127.0.0.1", /* remote */ 2905, "127.0.0.1" },
170 own_pc := 11, /* 0.1.3 third SGSN emulation */
171 own_ssn := 142,
172 peer_pc := 189, /* 2237, 1.23.5 osmo-hnbgw */
173 peer_ssn := 142,
174 sio := '83'O,
175 rctx := 6
176 },
177 {
178 transport := RANAP_TRANSPORT_IuCS,
179 sccp_service_type := "mtp3_itu",
180 sctp_addr := { /* local */ 23912, "127.0.0.1", /* remote */ 2905, "127.0.0.1" },
181 own_pc := 12, /* 0.1.4 fourth SGSN emulation */
182 own_ssn := 142,
183 peer_pc := 189, /* 2237, 1.23.5 osmo-hnbgw */
184 peer_ssn := 142,
185 sio := '83'O,
186 rctx := 8
187 }
Daniel Willmann19b8d902022-01-05 09:12:34 +0100188 };
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +0200189
Neels Hofmeyrbacb74f2022-08-29 16:24:12 +0200190 boolean mp_enable_pfcp_tests := false;
191
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +0200192 /* IP address at which we listen for PFCP to emulate a UPF in ttcn3 */
193 charstring mp_pfcp_ip_local := "127.0.0.1";
194
195 /* IP address from which the SUT (osmo-hnbgw) sends PFCP requests, and to which the ttcn3 UPF emulation sends
196 * PFCP responses. */
197 charstring mp_pfcp_ip_remote := "127.0.0.2";
Pau Espin Pedrol6c87ad92023-07-18 11:24:25 +0200198
199 boolean mp_validate_talloc_asn1 := true;
Pau Espin Pedrolee4ce862023-11-02 12:23:25 +0100200
201 /* The X31 timer configured at osmo-hnbgw (seconds). This provided an idea on
202 * minimum time the test must wait to consider this timer triggered */
203 integer mp_hnbgw_timer_x31 := 5;
Daniel Willmann19b8d902022-01-05 09:12:34 +0100204}
205
206function MSC_UnitdataCallback(RANAP_PDU ranap) runs on RAN_Emulation_CT return template RANAP_PDU {
207 // TODO: Actually implement unitdata handling
Neels Hofmeyrcf6dc492023-06-27 00:51:08 +0200208 return omit;
Daniel Willmann19b8d902022-01-05 09:12:34 +0100209}
210
211const RanOps MSC_RanOps := {
212 ranap_create_cb := refers(RAN_Emulation.RanapExpectedCreateCallback),
213 ranap_unitdata_cb := refers(MSC_UnitdataCallback),
214 ps_domain := false,
215 decode_dtap := false,
216 role_ms := false,
217 protocol := RAN_PROTOCOL_RANAP,
218 transport := RANAP_TRANSPORT_IuCS,
219 use_osmux := false,
Eric Wild6e511ce2022-04-02 21:35:56 +0200220 bssap_reset_retries := 1,
Daniel Willmann19b8d902022-01-05 09:12:34 +0100221 sccp_addr_local := omit,
222 sccp_addr_peer := omit
223}
224
Pau Espin Pedrol264679f2023-11-29 15:52:00 +0100225type record MgwResponse {
Daniel Willmann19b8d902022-01-05 09:12:34 +0100226 integer resp,
227 HostName mgw_rtp_ip,
Pau Espin Pedrol0c35a632023-11-29 16:00:35 +0100228 /* if set, used after first received MDCX: */
229 HostName mgw_rtp_ip_mdcx optional,
Daniel Willmann19b8d902022-01-05 09:12:34 +0100230 PortNumber mgw_rtp_port,
231 MgcpConnectionId mgcp_connection_id
232}
233type record MgcpParameters {
234 integer got_crcx_count,
235 integer got_dlcx_count,
236 MgcpCallId mgcp_call_id optional,
237 MgcpEndpoint mgcp_ep,
Pau Espin Pedrol264679f2023-11-29 15:52:00 +0100238 MgwResponse mgw_conn_ran,
239 MgwResponse mgw_conn_cn,
Daniel Willmann19b8d902022-01-05 09:12:34 +0100240 uint7_t rtp_payload_type,
241 charstring rtp_sdp_format,
242 HostName hnb_rtp_ip,
243 PortNumber hnb_rtp_port,
244 HostName cn_rtp_ip,
245 PortNumber cn_rtp_port,
246 boolean use_osmux,
247 integer got_osmux_count
248}
249
250template (value) MgcpParameters t_MgcpParams := {
251 got_crcx_count := 0,
252 got_dlcx_count := 0,
253 mgcp_call_id := omit,
254 mgcp_ep := "rtpbridge/1@mgw",
Pau Espin Pedrolb85ac2f2023-11-29 15:48:57 +0100255 mgw_conn_ran := {
Daniel Willmann19b8d902022-01-05 09:12:34 +0100256 resp := 1,
257 mgw_rtp_ip := "127.1.2.1",
Pau Espin Pedrol0c35a632023-11-29 16:00:35 +0100258 mgw_rtp_ip_mdcx := omit,
Daniel Willmann19b8d902022-01-05 09:12:34 +0100259 mgw_rtp_port := 10000,
260 mgcp_connection_id := '11111'H
261 },
Pau Espin Pedrolb85ac2f2023-11-29 15:48:57 +0100262 mgw_conn_cn := {
Daniel Willmann19b8d902022-01-05 09:12:34 +0100263 resp := 1,
264 mgw_rtp_ip := "127.1.2.2",
Pau Espin Pedrol0c35a632023-11-29 16:00:35 +0100265 mgw_rtp_ip_mdcx := omit,
Daniel Willmann19b8d902022-01-05 09:12:34 +0100266 mgw_rtp_port := 20000,
267 mgcp_connection_id := '22222'H
268 },
Philipp Maier6c5ba0752023-07-04 16:53:40 +0200269 rtp_payload_type := 112,
270 rtp_sdp_format := "VND.3GPP.IUFP",
Daniel Willmann19b8d902022-01-05 09:12:34 +0100271 hnb_rtp_ip := "127.1.1.1",
272 hnb_rtp_port := 10001,
273 cn_rtp_ip := "127.1.3.1",
274 cn_rtp_port := 20001,
275 use_osmux := false,
276 got_osmux_count := 0
277}
278
279type record TestHdlrParams {
280 integer hnb_idx,
Neels Hofmeyr7a48df12023-04-20 20:43:43 +0200281 /* cn_idx indicates which CN link from g_cn[] to connect to the test component.
282 * See also f_cn_idx(). */
283 integer cn_idx,
Daniel Willmann19b8d902022-01-05 09:12:34 +0100284 hexstring imsi,
285 boolean ps_domain,
286 MgcpParameters mgcp_pars optional,
Neels Hofmeyrf0b9ed12022-06-07 17:46:32 +0200287 HnbConfig hnb optional,
Neels Hofmeyrf2c95022023-04-19 01:24:39 +0200288 boolean expect_separate_sccp_cr,
289 integer tx_sccp_cr_data_len,
Neels Hofmeyr7d0e6802023-04-20 20:43:55 +0200290 charstring pfcp_local_addr,
Neels Hofmeyrb1bf16d2023-06-27 02:10:04 +0200291 octetstring nas_pdu optional,
292 /* local and remote SCCP addresses, used in TC_mscpool_paging_* */
293 SCCP_PAR_Address sccp_addr_msc optional,
Harald Welte0d4a8432024-04-04 01:12:11 +0200294 SCCP_PAR_Address sccp_addr_hnbgw optional,
295 /* RAB release cause */
296 RANAP_IEs.Cause rab_rel_cause
Daniel Willmann19b8d902022-01-05 09:12:34 +0100297}
298
299/* We extend:
300 * RUA_ConnHdlr (for the Iuh side, emulating the HNB)
301 * RAN_ConnHdlr (for the Iu side, emulating the MSC)
302 * MGCP_ConnHdlr (for the MGCP side, emulating the MGW)
Harald Welte904b5f12024-04-04 02:47:30 +0200303 * StatsD_ConnHdlr (for the statsd interface, verifying counters)
Daniel Willmann19b8d902022-01-05 09:12:34 +0100304 */
Harald Welte904b5f12024-04-04 02:47:30 +0200305type component ConnHdlr extends RAN_ConnHdlr, MGCP_ConnHdlr, RUA_ConnHdlr, PFCP_ConnHdlr, StatsD_ConnHdlr {
Daniel Willmann19b8d902022-01-05 09:12:34 +0100306 var integer g_sccp_conn_id;
307 var TestHdlrParams g_pars;
308 timer g_Tguard;
Neels Hofmeyr72a8d622023-01-26 13:47:01 +0100309
310 port TELNETasp_PT HNBGWVTY;
Daniel Willmann19b8d902022-01-05 09:12:34 +0100311}
312
313
314const MGCPOps MSC_MGCPOps := {
315 create_cb := refers(MGCP_Emulation.ExpectedCreateCallback),
316 unitdata_cb := refers(MGCP_Emulation.DummyUnitdataCallback)
317}
318
319function f_create_ranap_exp(octetstring l3_enc) runs on ConnHdlr {
320 BSSAP_PROC.call(RAN_register:{l3_enc, self}) {
321 [] BSSAP_PROC.getreply(RAN_register:{?, ?}) {};
322 }
323}
324
325
Daniel Willmannc79679a2022-08-23 17:48:39 +0200326const integer NUM_HNB := 2;
Daniel Willmann19b8d902022-01-05 09:12:34 +0100327
Daniel Willmann19b8d902022-01-05 09:12:34 +0100328type record HnbConfig {
329 LocationAreaIdentification lai,
330 integer sac
331}
332
Harald Welte904b5f12024-04-04 02:47:30 +0200333type component test_CT extends CTRL_Adapter_CT, StatsD_Checker_CT {
Daniel Willmann19b8d902022-01-05 09:12:34 +0100334 var boolean g_initialized := false;
335
336 /********************* Iu side */
Neels Hofmeyr7a48df12023-04-20 20:43:43 +0200337 var RAN_Adapter g_cn[NUM_MSC + NUM_SGSN];
Daniel Willmann19b8d902022-01-05 09:12:34 +0100338
339 /********************* Iuh side */
340 var HnbConfig g_hnb_cfg[NUM_HNB];
341 var Iuh_Emulation_CT vc_Iuh[NUM_HNB];
342 var RUA_Emulation_CT vc_RUA[NUM_HNB];
343 port HNBAP_PT HNBAP[NUM_HNB];
Pau Espin Pedrol83a49612022-09-12 21:11:05 +0200344 /* Number of HNBs to be used/started by the test */
345 var integer g_num_hnbs := NUM_HNB;
Daniel Willmann19b8d902022-01-05 09:12:34 +0100346
347 var MGCP_Emulation_CT vc_MGCP;
348 port TELNETasp_PT HNBGWVTY;
Harald Welte904b5f12024-04-04 02:47:30 +0200349 var StatsD_Checker_CT vc_STATSD;
Daniel Willmann19b8d902022-01-05 09:12:34 +0100350 /* global test case guard timer (actual timeout value is set in f_init()) */
351 timer T_guard := 30.0;
Neels Hofmeyr7d0e6802023-04-20 20:43:55 +0200352
353 /* The cnlink type 'msc' or 'sgsn', to be used in CTRL commands to obtain counters */
354 var charstring g_ctr_cn_node_name;
355 /* Counter state */
356 var CounterNameValsList g_ctr_cn;
Daniel Willmann19b8d902022-01-05 09:12:34 +0100357}
358
359/* global altstep for global guard timer; */
360altstep as_Tguard() runs on test_CT {
361 [] T_guard.timeout {
362 setverdict(fail, "Timeout of T_guard");
363 mtc.stop;
364 }
365}
366
Daniel Willmann19b8d902022-01-05 09:12:34 +0100367function f_init_vty(charstring id := "foo") runs on test_CT {
368 if (HNBGWVTY.checkstate("Mapped")) {
369 /* skip initialization if already executed once */
370 return;
371 }
372 map(self:HNBGWVTY, system:HNBGWVTY);
373 f_vty_set_prompts(HNBGWVTY);
374 f_vty_transceive(HNBGWVTY, "enable");
375}
376
377function f_init_mgcp(charstring id) runs on test_CT {
378 id := id & "-MGCP";
379 var MGCPOps ops := {
380 create_cb := refers(MGCP_Emulation.ExpectedCreateCallback),
381 unitdata_cb := refers(MGCP_Emulation.DummyUnitdataCallback)
382 }
383 var MGCP_conn_parameters pars := {
384 callagent_ip := mp_hnbgw_ip,
385 callagent_udp_port := -1,
386 mgw_ip := mp_mgw_ip,
387 mgw_udp_port := mp_mgw_port,
388 multi_conn_mode := false
389 }
390
391 vc_MGCP := MGCP_Emulation_CT.create(id);
392 map(vc_MGCP:MGCP, system:MGCP_CODEC_PT);
393 vc_MGCP.start(MGCP_Emulation.main(ops, pars, id));
394}
395
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +0200396function f_init_pfcp(charstring id) runs on ConnHdlr {
397 id := id & "-PFCP";
398
399 var PFCP_Emulation_Cfg pfcp_cfg := {
400 pfcp_bind_ip := mp_pfcp_ip_local,
401 pfcp_bind_port := PFCP_PORT,
402 pfcp_remote_ip := mp_pfcp_ip_remote,
403 pfcp_remote_port := PFCP_PORT,
404 role := UPF
405 };
406
407 vc_PFCP := PFCP_Emulation_CT.create(id) alive;
408 connect(self:PFCP, vc_PFCP:CLIENT);
409 connect(self:PFCP_PROC, vc_PFCP:CLIENT_PROC);
410 vc_PFCP.start(PFCP_Emulation.main(pfcp_cfg));
411}
412
Daniel Willmann19b8d902022-01-05 09:12:34 +0100413function f_init_hnodeb(charstring id, integer hnb_idx, RuaOps rua_ops) runs on test_CT {
414 id := id & "-Iuh" & int2str(hnb_idx);
415
416 /* Iuh lower layer (RUA/HNBAP demux) */
417 var Iuh_conn_parameters iuh_pars;
418 iuh_pars.remote_ip := mp_hnbgw_ip;
419 iuh_pars.remote_sctp_port := mp_hnbgw_iuh_port;
420 iuh_pars.local_ip := mp_hnodeb_ip;
421 iuh_pars.local_sctp_port := mp_hnodeb_port + hnb_idx;
422 vc_Iuh[hnb_idx] := Iuh_Emulation_CT.create(id);
423 connect(self:HNBAP[hnb_idx], vc_Iuh[hnb_idx]:HNBAP);
424
425 vc_RUA[hnb_idx] := RUA_Emulation_CT.create(id & "-RUA");
426 connect(vc_RUA[hnb_idx]:RUA, vc_Iuh[hnb_idx]:RUA);
427
428 /* Start Iuh side components */
429 vc_Iuh[hnb_idx].start(Iuh_Emulation.main(iuh_pars, id));
430 vc_RUA[hnb_idx].start(RUA_Emulation.main(rua_ops, id & "-RUA"));
431}
432
Neels Hofmeyr3d5a0da2023-06-27 00:57:46 +0200433private type record of boolean BooleanList;
434
435private function f_vty_cnlink_allow_attach(TELNETasp_PT pt, boolean ps_domain, BooleanList allow_attach_list)
436{
437 var charstring config := f_vty_transceive_ret(pt, "show running-config");
438
439 var charstring msc_sgsn;
440 if (ps_domain) {
441 msc_sgsn := "sgsn";
442 } else {
443 msc_sgsn := "msc";
444 }
445
446 f_vty_enter_config(pt);
447 for (var integer cn_nr := 0; cn_nr < sizeof(allow_attach_list); cn_nr := cn_nr+1) {
448 if (f_strstr(config, "\n" & msc_sgsn & " " & int2str(cn_nr) & "\n") < 0) {
449 /* There is no 'msc N' for this cn_nr in the running config, so don't create an empty cn by
450 * stepping into that config node. */
451 log(msc_sgsn, cn_nr, " is not configured, skipping");
452 continue;
453 }
454 f_vty_transceive(pt, msc_sgsn & " " & int2str(cn_nr));
455
456 if (allow_attach_list[cn_nr]) {
457 /* strict := false: ignore if osmo-hnbgw does not support this config option (latest build) */
458 f_vty_transceive(pt, "allow-attach", strict := false);
459 } else {
460 f_vty_transceive(pt, "no allow-attach", strict := false);
461 }
462 f_vty_transceive(pt, "exit");
463 }
464 f_vty_transceive(pt, "exit");
465}
466
467/* Start RAN adapter for CN link N.
468 * e.g. link for 'msc 0' = (ps_domain := false, cn_nr := 0)
469 * link for 'sgsn 3' = (ps_domain := true, cn_nr := 3)
470 */
471private function f_cn_nr_init(boolean ps_domain, integer cn_nr) runs on test_CT {
472 var RanOps ranops := MSC_RanOps;
473 ranops.ps_domain := ps_domain;
474 var integer cn_idx := f_cn_idx(ps_domain, cn_nr);
475 var charstring msc_sgsn := "msc";
476 if (ps_domain) {
477 msc_sgsn := "sgsn";
478 }
479 f_ran_adapter_init(g_cn[cn_idx], mp_cn_cfg[cn_idx], "HNBGW_Test." & msc_sgsn & int2str(cn_nr), ranops);
480 f_ran_adapter_start(g_cn[cn_idx]);
481}
482
483private function f_cn_idx_disconnect(integer cn_idx) runs on test_CT {
484 f_ran_adapter_cleanup(g_cn[cn_idx]);
485}
486
Daniel Willmann19b8d902022-01-05 09:12:34 +0100487/* global initialization function */
Neels Hofmeyr333ea392023-06-27 00:58:05 +0200488function f_init(charstring id := "HNBGW", float guard_timeout := 30.0, integer nr_msc := 1, integer nr_sgsn := 1,
489 boolean start_hnb := true) runs on test_CT {
Daniel Willmann19b8d902022-01-05 09:12:34 +0100490
Daniel Willmann19b8d902022-01-05 09:12:34 +0100491 T_guard.start(guard_timeout);
492 activate(as_Tguard());
493
Harald Welte904b5f12024-04-04 02:47:30 +0200494 f_init_statsd("VirtHNBGW", vc_STATSD, mp_hnbgw_ip, mp_hnbgw_statsd_port);
495
Daniel Willmann19b8d902022-01-05 09:12:34 +0100496 /* RUA/RANAP emulation on top of lower-layer Iuh */
497 var RuaOps rua_ops := {
498 create_cb := refers(IuhRanapCreateCallback),
499 unitdata_cb := refers(IuhRanapUnitdataCallback)
500 };
Pau Espin Pedrol83a49612022-09-12 21:11:05 +0200501 for (var integer i := 0; i < g_num_hnbs; i := i+1) {
Daniel Willmannc79679a2022-08-23 17:48:39 +0200502 g_hnb_cfg[i] := {
503 lai := {
Neels Hofmeyr497216f2023-06-27 00:59:26 +0200504 mcc_mnc := '00F110'H,
Daniel Willmannc79679a2022-08-23 17:48:39 +0200505 lac := 2342 + i
506 },
507 sac := 55
508 };
Daniel Willmann19b8d902022-01-05 09:12:34 +0100509 f_init_hnodeb(testcasename(), i, rua_ops);
510 }
511
Neels Hofmeyr3d5a0da2023-06-27 00:57:46 +0200512 f_init_vty("VirtHNBGW");
Neels Hofmeyrffcb8892023-06-27 01:09:57 +0200513 f_ipa_ctrl_start_client(mp_hnbgw_ip, mp_hnbgw_ctrl_port);
514
Daniel Willmann19b8d902022-01-05 09:12:34 +0100515 /* MSC emulation */
Neels Hofmeyr3d5a0da2023-06-27 00:57:46 +0200516
517 /* Make sure each MSC's internal state is "DISCONNECTED" at first */
518 for (var integer i := 0; i < NUM_MSC; i := i + 1) {
519 f_vty_transceive(HNBGWVTY, "msc " & int2str(i) & " ranap reset", strict := false);
520 }
521
522 var BooleanList allow_attach := { false, false, false, false };
Neels Hofmeyr7a48df12023-04-20 20:43:43 +0200523 for (var integer i := 0; i < nr_msc; i := i + 1) {
524 var integer cn_idx := FIRST_MSC_IDX + i;
Neels Hofmeyr3d5a0da2023-06-27 00:57:46 +0200525 allow_attach[i] := true;
526 f_cn_nr_init(ps_domain := false, cn_nr := i);
Neels Hofmeyr7a48df12023-04-20 20:43:43 +0200527 }
Neels Hofmeyr3d5a0da2023-06-27 00:57:46 +0200528 /* start the test with exactly all enabled MSCs allowed to attach */
529 f_vty_cnlink_allow_attach(HNBGWVTY, false, allow_attach);
Daniel Willmann19b8d902022-01-05 09:12:34 +0100530
531 /* SGSN emulation */
Neels Hofmeyr3d5a0da2023-06-27 00:57:46 +0200532
533 /* Make sure each SGSN's internal state is "DISCONNECTED" at first */
534 for (var integer i := 0; i < NUM_SGSN; i := i + 1) {
535 f_vty_transceive(HNBGWVTY, "sgsn " & int2str(i) & " ranap reset", strict := false);
Neels Hofmeyr7a48df12023-04-20 20:43:43 +0200536 }
Daniel Willmann19b8d902022-01-05 09:12:34 +0100537
Neels Hofmeyr3d5a0da2023-06-27 00:57:46 +0200538 allow_attach := { false, false, false, false };
539 for (var integer i := 0; i < nr_sgsn; i := i + 1) {
540 var integer cn_idx := FIRST_SGSN_IDX + i;
541 allow_attach[i] := true;
542 f_cn_nr_init(ps_domain := true, cn_nr := i);
543 }
544 f_vty_cnlink_allow_attach(HNBGWVTY, true, allow_attach);
545
Daniel Willmann19b8d902022-01-05 09:12:34 +0100546 f_init_mgcp(id);
Neels Hofmeyr333ea392023-06-27 00:58:05 +0200547
548 if (start_hnb) {
549 f_start_hnbs();
550 }
Neels Hofmeyr467eb7e2023-08-10 03:38:07 +0200551
552 /* Sometimes, the RUA InitialUE-Message from a test happens too quickly, before the RANAP RESET from
553 * RAN_Emulation is through, after above f_cn_nr_init(). In the pcap it seems to be a matter of 50 ms. Give some
554 * grace. */
555 f_sleep(1.0);
Daniel Willmann19b8d902022-01-05 09:12:34 +0100556}
557
558friend function f_shutdown_helper() runs on test_CT {
Pau Espin Pedrol6c87ad92023-07-18 11:24:25 +0200559 if (mp_validate_talloc_asn1) {
560 f_verify_talloc_bytes(HNBGWVTY, {"asn1_context"}, 1);
561 }
Neels Hofmeyr75d905b2023-04-27 00:30:25 +0200562
Daniel Willmann19b8d902022-01-05 09:12:34 +0100563 all component.stop;
564 setverdict(pass);
565 mtc.stop;
566}
567
568/* helper function to start all of the simulated hNodeBs */
569function f_start_hnbs() runs on test_CT {
Pau Espin Pedrol83a49612022-09-12 21:11:05 +0200570 for (var integer i:= 0; i < g_num_hnbs; i := i+1) {
Harald Welted71d5962024-03-27 19:17:19 +0100571 f_hnbap_hnb_register(i, i);
Daniel Willmann19b8d902022-01-05 09:12:34 +0100572 }
573}
574
575/***********************************************************************
576 * code running in test_CT, preparing start of per-UE ConnHdlr
577 ***********************************************************************/
578
579/* inbound RUA connection establishment on Iuh side */
580function IuhRanapCreateCallback(ContextId context_id, RUA_IEs.CN_DomainIndicator domain, charstring id)
581runs on RUA_Emulation_CT return RUA_ConnHdlr {
582 log("CreateCallback");
583 return null;
584}
585
586/* inbound RUA connectionless data on Iuh side */
587function IuhRanapUnitdataCallback(RANAP_PDU ranap)
588runs on RUA_Emulation_CT return template RANAP_PDU {
589 log("UnitdataCallback");
590 return omit;
591}
592
593private function f_start_handler_create(TestHdlrParams pars) runs on test_CT return ConnHdlr {
594 var ConnHdlr vc_conn;
595 var charstring id := testcasename() & int2str(pars.hnb_idx);
596
597 vc_conn := ConnHdlr.create(id);
598
599 /* Iuh RUA part */
600 connect(vc_conn:RUA, vc_RUA[pars.hnb_idx]:CLIENT);
601
Neels Hofmeyr7a48df12023-04-20 20:43:43 +0200602 /* MSC or SGSN */
603 connect(vc_conn:BSSAP, g_cn[pars.cn_idx].vc_RAN:CLIENT);
604 connect(vc_conn:BSSAP_PROC, g_cn[pars.cn_idx].vc_RAN:PROC);
605
Daniel Willmann19b8d902022-01-05 09:12:34 +0100606 /* MGCP part */
607 connect(vc_conn:MGCP, vc_MGCP:MGCP_CLIENT);
608 connect(vc_conn:MGCP_PROC, vc_MGCP:MGCP_PROC);
609
Harald Welte904b5f12024-04-04 02:47:30 +0200610 connect(vc_conn:STATSD_PROC, vc_STATSD:STATSD_PROC);
611
Daniel Willmann19b8d902022-01-05 09:12:34 +0100612 return vc_conn;
613}
614
615private function f_start_handler_run(ConnHdlr vc_conn, void_fn fn, TestHdlrParams pars) runs on test_CT {
616 var charstring id := testcasename(); // & int2str(pars.ran_idx);
617 /* We cannot use vc_conn.start(f_init_handler(fn, id, pars)); as we cannot have
618 * a stand-alone 'derefers()' call, see https://www.eclipse.org/forums/index.php/t/1091364/ */
619 pars.hnb := g_hnb_cfg[pars.hnb_idx];
Daniel Willmann19b8d902022-01-05 09:12:34 +0100620 vc_conn.start(derefers(fn)(id, pars));
621}
622
623function f_start_handler_with_pars(void_fn fn, template (value) TestHdlrParams pars)
624runs on test_CT return ConnHdlr {
625 var ConnHdlr vc_conn;
626 vc_conn := f_start_handler_create(valueof(pars));
627 f_start_handler_run(vc_conn, fn, valueof(pars));
628 return vc_conn;
629}
630
631/***********************************************************************
632 * code running inside per-UE ConnHdlr
633 ***********************************************************************/
634
635type function void_fn(charstring id, TestHdlrParams pars) runs on ConnHdlr;
636
637function f_init_handler(TestHdlrParams pars, float t_guard := 20.0) runs on ConnHdlr {
638 /* make parameters available via component variable */
639 g_pars := pars;
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +0200640
641 f_init_pfcp(testcasename());
642
Daniel Willmann19b8d902022-01-05 09:12:34 +0100643 /* start guard timer and activate it as default */
644 g_Tguard.start(t_guard);
645 activate(as_Tguard_ConnHdlr());
646
Neels Hofmeyr72a8d622023-01-26 13:47:01 +0100647 map(self:HNBGWVTY, system:HNBGWVTY);
648 f_vty_set_prompts(HNBGWVTY);
649 f_vty_transceive(HNBGWVTY, "enable");
650
Daniel Willmann19b8d902022-01-05 09:12:34 +0100651 /* TODO: CTRL? */
Neels Hofmeyr59517222023-06-23 04:46:59 +0200652
653 f_sleep(1.0);
Daniel Willmann19b8d902022-01-05 09:12:34 +0100654}
655
656/* global altstep for global guard timer; */
657private altstep as_Tguard_ConnHdlr() runs on ConnHdlr {
658 [] g_Tguard.timeout {
659 setverdict(fail, "Timeout of T_guard");
660 mtc.stop;
661 }
662}
663
Neels Hofmeyrdc416c92023-03-09 02:47:50 +0100664private function f_bssap_expect(template (present) RANAP_PDU exp_rx) runs on ConnHdlr return RANAP_PDU
665{
666 var RANAP_PDU rx;
667 timer T := 5.0;
668 T.start;
669 alt {
670 [] BSSAP.receive(exp_rx) -> value rx {
671 setverdict(pass);
672 }
673 [] BSSAP.receive(RANAP_PDU:?) {
674 setverdict(fail, "Got an unexpected RANAP message on BSSAP port, was waiting for ", exp_rx);
675 mtc.stop;
676 }
677 [] T.timeout {
678 setverdict(fail, "Timeout waiting for RANAP on BSSAP port: ", exp_rx);
679 mtc.stop;
680 }
681 }
682 T.stop;
683 return rx;
684}
685
Daniel Willmann19b8d902022-01-05 09:12:34 +0100686/* send RANAP on Iuh and expect it to show up on Iu */
687function f_iuh2iu(template (present) RANAP_PDU tx, template RANAP_PDU exp_rx := omit)
688runs on ConnHdlr return RANAP_PDU {
689 var RANAP_PDU rx;
690 timer T := 5.0;
691
692 if (istemplatekind(exp_rx, "omit")) {
693 exp_rx := tx;
694 }
695
696 RUA.send(tx);
Daniel Willmann19b8d902022-01-05 09:12:34 +0100697
Neels Hofmeyrdc416c92023-03-09 02:47:50 +0100698 return f_bssap_expect(exp_rx);
Daniel Willmann19b8d902022-01-05 09:12:34 +0100699}
700
701/* send RANAP on Iu and expect it to show up on Iuh */
702function f_iu2iuh(template (present) RANAP_PDU tx, template RANAP_PDU exp_rx := omit)
703runs on ConnHdlr return RANAP_PDU {
Daniel Willmann19b8d902022-01-05 09:12:34 +0100704 if (istemplatekind(exp_rx, "omit")) {
705 exp_rx := tx;
706 }
707
708 BSSAP.send(tx);
Daniel Willmann19b8d902022-01-05 09:12:34 +0100709
Neels Hofmeyr735b6562023-03-09 02:51:28 +0100710 return f_rua_expect(exp_rx)
711}
712
713/* expect to receive a specific RUA message on Iuh */
714private function f_rua_expect(template (present) RANAP_PDU exp_rx) runs on ConnHdlr return RANAP_PDU
715{
716 var RANAP_PDU rx;
717 timer T := 5.0;
718 T.start;
Daniel Willmann19b8d902022-01-05 09:12:34 +0100719 alt {
720 [] RUA.receive(exp_rx) -> value rx {
721 setverdict(pass);
722 }
Neels Hofmeyr735b6562023-03-09 02:51:28 +0100723 [] RUA.receive(RANAP_PDU:?) {
724 setverdict(fail, "Got an unexpected RUA message, was waiting for ", exp_rx);
725 mtc.stop;
726 }
Daniel Willmann19b8d902022-01-05 09:12:34 +0100727 [] T.timeout {
728 setverdict(fail, "Timeout waiting for Iuh ", exp_rx);
Neels Hofmeyr735b6562023-03-09 02:51:28 +0100729 mtc.stop;
Daniel Willmann19b8d902022-01-05 09:12:34 +0100730 }
731 }
Neels Hofmeyr735b6562023-03-09 02:51:28 +0100732 T.stop;
Daniel Willmann19b8d902022-01-05 09:12:34 +0100733 return rx;
734}
735
736/* send RANAP on Iuh and expect it to show up on Iu */
737function f_iuh2iu_connect(template (present) RANAP_PDU tx, template RANAP_PDU exp_rx := omit)
738runs on ConnHdlr return RANAP_PDU {
739 var RANAP_PDU rx;
740 timer T := 5.0;
741
742 if (istemplatekind(exp_rx, "omit")) {
743 exp_rx := tx;
744 }
745
746 /* create an expect on the Iu side for the random NAS portion */
Neels Hofmeyrf2c95022023-04-19 01:24:39 +0200747 if (g_pars.expect_separate_sccp_cr) {
Neels Hofmeyrf0b9ed12022-06-07 17:46:32 +0200748 f_ran_register_sccp_cr_without_payload();
749 } else {
750 var template (omit) octetstring nas := f_ranap_extract_l3(valueof(tx));
751 f_ran_register_exp(valueof(nas));
752 }
Daniel Willmann19b8d902022-01-05 09:12:34 +0100753
754 /* send it via Iuh (creating a RUA connection) */
755 RUA.send(RUA_Conn_Req:{g_pars.ps_domain, tx});
756
Neels Hofmeyrf2c95022023-04-19 01:24:39 +0200757 if (g_pars.expect_separate_sccp_cr) {
Neels Hofmeyrf0b9ed12022-06-07 17:46:32 +0200758 /* Acknowledge the empty SCCP CR. RAN_Emulation does the confirmation, no need to respond. */
759 BSSAP.receive(tr_RANAP_Conn_Req());
760 }
761
Daniel Willmann19b8d902022-01-05 09:12:34 +0100762 /* expect to receive it on the Iu side */
Neels Hofmeyrdc416c92023-03-09 02:47:50 +0100763 return f_bssap_expect(exp_rx);
Daniel Willmann19b8d902022-01-05 09:12:34 +0100764}
765
Neels Hofmeyr99b7d402023-02-20 14:26:31 +0100766/* 3GPP TS 48.006 9.2 Connection release:
767 *
768 * The MSC sends a SCCP released message. This message shall not contain
769 * any user data field.
770 *
771 * So what we expect normally is:
772 *
773 * HNBGW MSC
774 * RUA --id-Disconnect-------> | ---Data-Form-1(!)---> | Iu-ReleaseComplete
775 * | <--Released---------- | (no data)
776 *
777 * This function tests osmo-hnbgw behavior if the CN fails to send a RLSD:
778 * after some timeout, osmo-hnbgw should send a RLSD to the CN.
779 */
Daniel Willmann19b8d902022-01-05 09:12:34 +0100780function f_iuh2iu_disconnect(template (present) RANAP_PDU tx, RUA_IEs.Cause cause,
781 template RANAP_PDU exp_rx := omit)
782runs on ConnHdlr return RANAP_PDU {
783 var RANAP_PDU rx
Pau Espin Pedrolee4ce862023-11-02 12:23:25 +0100784 timer T := int2float(mp_hnbgw_timer_x31) + 1.0;
Daniel Willmann19b8d902022-01-05 09:12:34 +0100785
786 if (istemplatekind(exp_rx, "omit")) {
787 exp_rx := tx;
788 }
789
790 /* send it via Iuh (creating a RUA connection) */
791 RUA.send(RUA_Disc_Req:{tx, cause});
792
793 /* expect to receive it on the Iu side */
Neels Hofmeyrdc416c92023-03-09 02:47:50 +0100794 rx := f_bssap_expect(exp_rx);
Daniel Willmann19b8d902022-01-05 09:12:34 +0100795
796 /* expect disconnect on the Iu side */
Neels Hofmeyrdc416c92023-03-09 02:47:50 +0100797 T.start;
Daniel Willmann19b8d902022-01-05 09:12:34 +0100798 alt {
799 [] BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_IND) {
800 setverdict(pass);
801 }
802 [] T.timeout {
803 setverdict(fail, "Timeout waiting for Iu disconnect");
804 return rx;
805 }
806
807 }
808 return rx;
809}
810
Neels Hofmeyrf2c95022023-04-19 01:24:39 +0200811private function f_build_initial_ue_with_nas(TestHdlrParams pars, octetstring nas)
812 return RANAP_PDU {
Harald Welte3f216c52024-03-27 20:40:17 +0100813 var RANAP_IEs.LAI lai := {
Daniel Willmann19b8d902022-01-05 09:12:34 +0100814 pLMNidentity := hex2oct(pars.hnb.lai.mcc_mnc),
815 lAC := int2oct(pars.hnb.lai.lac, 2),
816 iE_Extensions := omit
817 };
Harald Welte3f216c52024-03-27 20:40:17 +0100818 var RANAP_IEs.SAI sai := {
Daniel Willmann19b8d902022-01-05 09:12:34 +0100819 pLMNidentity := lai.pLMNidentity,
820 lAC := lai.lAC,
821 sAC := int2oct(pars.hnb.sac, 2),
822 iE_Extensions := omit
823 }
Daniel Willmann19b8d902022-01-05 09:12:34 +0100824 var IuSignallingConnectionIdentifier sigc_id := int2bit(f_rnd_int(1000), 24);
825 var GlobalRNC_ID grnc_id := {
826 pLMNidentity := lai.pLMNidentity,
827 rNC_ID := 2342
828 }
Neels Hofmeyrf2c95022023-04-19 01:24:39 +0200829 var template RANAP_PDU ret;
Daniel Willmann19b8d902022-01-05 09:12:34 +0100830 if (pars.ps_domain) {
Harald Welte3f216c52024-03-27 20:40:17 +0100831 var RANAP_IEs.RAC rac := '00'O;
Neels Hofmeyrf2c95022023-04-19 01:24:39 +0200832 ret := ts_RANAP_initialUE_PS(lai, rac, sai, nas, sigc_id, grnc_id);
Daniel Willmann19b8d902022-01-05 09:12:34 +0100833 } else {
Neels Hofmeyrf2c95022023-04-19 01:24:39 +0200834 ret := ts_RANAP_initialUE_CS(lai, sai, nas, sigc_id, grnc_id);
Daniel Willmann19b8d902022-01-05 09:12:34 +0100835 }
Neels Hofmeyrf2c95022023-04-19 01:24:39 +0200836 return valueof(ret);
837}
838
839/* build a RANAP InitialUE based on the TestHdlrParams */
840friend function f_build_initial_ue(TestHdlrParams pars) return RANAP_PDU {
841
842 var octetstring nas;
843
844 if (pars.tx_sccp_cr_data_len == 0) {
845 nas := f_rnd_octstring(10);
846 } else {
847 /* The test asks for an exact number of Optional Data bytes. */
848
849 /* First see what size the RANAP part of the payload data is,
850 * to adjust the NAS PDU size to the size requested by the test (pars.tx_sccp_cr_data_len). */
851 var RANAP_PDU initial_ue := f_build_initial_ue_with_nas(pars, '00'O);
852
853 var octetstring ranap_plus_one_byte_nas := enc_RANAP_PDU(initial_ue);
854 var integer ranap_length := lengthof(ranap_plus_one_byte_nas) - 1;
855
856 log("ranap_plus_one_byte_nas = ", lengthof(ranap_plus_one_byte_nas), " bytes, ", initial_ue, " = ",
857 ranap_plus_one_byte_nas);
858 log("ranap_length = ", ranap_length);
859
860 /* SCCP CR has a payload length limit of 130 bytes. To trigger this limit, the RANAP + NAS PDU has to be
861 * > 130 bytes. It doesn't need to be 131 bytes in the NAS PDU alone, but let's just make it definitely
862 * large enough. To test for this limit, pars.tx_sccp_cr_data_len asks for a specific amount of data len. */
863 nas := f_rnd_octstring(pars.tx_sccp_cr_data_len - ranap_length);
864 }
865
866 var RANAP_PDU ret := f_build_initial_ue_with_nas(pars, nas);
867
868 if (pars.tx_sccp_cr_data_len != 0) {
869 for (var integer attempts := 0; attempts < 2; attempts := attempts + 1) {
870 var octetstring check_len := enc_RANAP_PDU(ret);
871 log("final RANAP PDU length = ", lengthof(check_len));
872 if (lengthof(check_len) == pars.tx_sccp_cr_data_len) {
873 return ret;
874 }
875 nas := f_rnd_octstring(lengthof(nas) + (pars.tx_sccp_cr_data_len - lengthof(check_len)));
876 log("that was off, changed NAS length to ", lengthof(nas), " and trying again");
877 ret := f_build_initial_ue_with_nas(pars, nas);
878 }
879 setverdict(fail, "Ended up with wrong Optional Data length");
880 mtc.stop;
881 }
882 return ret;
Daniel Willmann19b8d902022-01-05 09:12:34 +0100883}
884
885/* build a RANAP RAB AssignmentResponse based on the TestHdlrParams */
886friend function f_build_rab_ass_resp(TestHdlrParams pars) return RANAP_PDU {
887 var template RAB_SetupOrModifiedList rab_sml;
888
889 rab_sml := ts_RAB_SMdL(t_RAB_id(23), f_ts_RAB_TLA("192.168.1.23"), t_RAB_binding_port(1234));
890
891 return valueof(ts_RANAP_RabAssResp(rab_sml));
892}
893
894
895/***********************************************************************
896 * HNBAP Testing
897 ***********************************************************************/
898
899
Harald Welted71d5962024-03-27 19:17:19 +0100900function f_hnbap_hnb_register(integer hnb_idx := 0, integer cell_id := 0, boolean expect_reject := false) runs on test_CT
Daniel Willmann19b8d902022-01-05 09:12:34 +0100901{
902 timer T := 2.0;
903
Neels Hofmeyrfffe79b2023-06-27 01:16:15 +0200904 HNBAP[hnb_idx].send(ts_HNBAP_HNBRegisterRequest(char2oct("TTCN3-HNB-" & int2str(hnb_idx)),
Harald Welte7a9e7962024-04-04 02:46:45 +0200905 hex2oct(g_hnb_cfg[hnb_idx].lai.mcc_mnc),
Daniel Willmannc79679a2022-08-23 17:48:39 +0200906 int2bit(1 + cell_id, 28),
Harald Welte7a9e7962024-04-04 02:46:45 +0200907 int2oct(g_hnb_cfg[hnb_idx].lai.lac, 2),
908 int2oct(0, 1),
909 int2oct(g_hnb_cfg[hnb_idx].sac, 2)));
Daniel Willmann19b8d902022-01-05 09:12:34 +0100910
911 T.start;
912 alt {
913 [] HNBAP[hnb_idx].receive(tr_HNBAP_HNBRegisterAccept(?)) {
Daniel Willmannc79679a2022-08-23 17:48:39 +0200914 if (expect_reject) {
915 setverdict(fail, "Rx HNB Register Accept while expecting reject");
916 } else {
917 setverdict(pass);
918 }
919 }
920 [] HNBAP[hnb_idx].receive(tr_HNBAP_HNBRegisterReject(?)) {
921 if (expect_reject) {
922 setverdict(pass);
923 } else {
924 setverdict(fail, "Rx HNB Register Reject while expecting accept");
925 }
Daniel Willmann19b8d902022-01-05 09:12:34 +0100926 }
927 [] HNBAP[hnb_idx].receive(IUHEM_Event:?) {
928 repeat;
929 }
930 [] T.timeout {
Daniel Willmannc79679a2022-08-23 17:48:39 +0200931 setverdict(fail, "Timeout waiting for HNB Register response");
Daniel Willmann19b8d902022-01-05 09:12:34 +0100932 }
933 }
934}
935
Harald Welteaf3e2162024-03-27 21:54:20 +0100936function f_hnbap_ue_register(integer hnb_idx := 0, template (present) UE_Identity ue_id, boolean expect_reject := false) runs on test_CT
937{
938 timer T := 2.0;
939
940 HNBAP[hnb_idx].send(ts_HNBAP_UERegisterRequest(ue_id));
941
942 T.start;
943 alt {
944 [] HNBAP[hnb_idx].receive(tr_HNBAP_UERegisterAccept(ue_id)) {
945 if (expect_reject) {
946 setverdict(fail, "Rx UE Register Accept while expecting reject");
947 } else {
948 setverdict(pass);
949 }
950 }
951 [] HNBAP[hnb_idx].receive(tr_HNBAP_UERegisterReject(ue_id, ?)) {
952 if (expect_reject) {
953 setverdict(pass);
954 } else {
955 setverdict(fail, "Rx UE Register Reject while expecting accept");
956 }
957 }
958 [] HNBAP[hnb_idx].receive(IUHEM_Event:?) {
959 repeat;
960 }
961 [] T.timeout {
962 setverdict(fail, "Timeout waiting for UE Register response");
963 }
964 }
965}
966
967
Daniel Willmann19b8d902022-01-05 09:12:34 +0100968testcase TC_hnb_register() runs on test_CT {
Pau Espin Pedrol83a49612022-09-12 21:11:05 +0200969 g_num_hnbs := 1;
Neels Hofmeyr333ea392023-06-27 00:58:05 +0200970 f_init(start_hnb := false);
Harald Welted71d5962024-03-27 19:17:19 +0100971 f_hnbap_hnb_register(0);
Daniel Willmann19b8d902022-01-05 09:12:34 +0100972 f_shutdown_helper();
973}
974
Pau Espin Pedrolacf4f222022-09-27 14:33:40 +0200975/* Try to register the same HNB from 2 different concurrent connections. Second
976 * one should be rejected. */
Daniel Willmannc79679a2022-08-23 17:48:39 +0200977testcase TC_hnb_register_duplicate() runs on test_CT {
Pau Espin Pedrol83a49612022-09-12 21:11:05 +0200978 g_num_hnbs := 2;
Neels Hofmeyr333ea392023-06-27 00:58:05 +0200979 f_init(start_hnb := false);
Harald Welted71d5962024-03-27 19:17:19 +0100980 f_hnbap_hnb_register(0);
981 f_hnbap_hnb_register(1, 0, expect_reject := true);
Daniel Willmannc79679a2022-08-23 17:48:39 +0200982 f_verify_talloc_count(HNBGWVTY, {"struct hnb_context"}, expect_count := 1);
983 f_shutdown_helper();
984}
985
Pau Espin Pedrolacf4f222022-09-27 14:33:40 +0200986/* Try to register the same HNB in the same connection already established, aka
987 * duplicate HNB Register Request. It should be accepted and new configuration
988 * applied. TS 25.469 8.2.4 */
989testcase TC_hnb_register_duplicate_reuse_sctp_assoc() runs on test_CT {
990 g_num_hnbs := 1;
Neels Hofmeyr333ea392023-06-27 00:58:05 +0200991 f_init(start_hnb := false);
Harald Welted71d5962024-03-27 19:17:19 +0100992 f_hnbap_hnb_register(0);
993 f_hnbap_hnb_register(0);
Pau Espin Pedrolacf4f222022-09-27 14:33:40 +0200994 f_verify_talloc_count(HNBGWVTY, {"struct hnb_context"}, expect_count := 1);
995 f_shutdown_helper();
996}
997
Pau Espin Pedrolf0b9fa02022-09-12 13:31:07 +0200998/* Drop HNBAP conn (HNBAP DEREG) and reconnect it (HNBAP REG) using same SCTP association.
999 * Related: OS#5676, SYS#6113 */
1000testcase TC_hnb_reregister_reuse_sctp_assoc() runs on test_CT {
1001 g_num_hnbs := 1;
Neels Hofmeyr333ea392023-06-27 00:58:05 +02001002 f_init(start_hnb := false);
Harald Welted71d5962024-03-27 19:17:19 +01001003 f_hnbap_hnb_register(0);
Pau Espin Pedrolf0b9fa02022-09-12 13:31:07 +02001004 HNBAP[0].send(ts_HNBAP_HNBDe_Register(ts_HnbapCause(unspecified)));
Harald Welted71d5962024-03-27 19:17:19 +01001005 f_hnbap_hnb_register(0);
Pau Espin Pedrolf0b9fa02022-09-12 13:31:07 +02001006 f_verify_talloc_count(HNBGWVTY, {"struct hnb_context"}, expect_count := 1);
1007 f_shutdown_helper();
1008}
1009
Harald Welteaf3e2162024-03-27 21:54:20 +01001010/* regular UE registration */
1011testcase TC_ue_register() runs on test_CT {
1012 var UE_Identity ue_id := { iMSI := imsi_hex2oct(f_gen_imsi(1)) };
1013 g_num_hnbs := 1;
1014 f_init(start_hnb := true);
1015 f_hnbap_ue_register(0, ue_id);
1016 f_shutdown_helper();
1017}
1018
Harald Weltef60044d2024-04-04 00:54:34 +02001019/* regular UE registration (UE Identity: TMSI+LAI) */
1020testcase TC_ue_register_tmsi_lai() runs on test_CT {
1021 var UE_Identity ue_id := { tMSILAI := { tMSI := oct2bit(f_gen_tmsi(0)),
1022 lAI := { pLMNID := '00F110'O, lAC := '2342'O }
1023 }
1024 };
1025 g_num_hnbs := 1;
1026 f_init(start_hnb := true);
1027 f_hnbap_ue_register(0, ue_id);
1028 f_shutdown_helper();
1029}
1030
1031
Harald Welteaf3e2162024-03-27 21:54:20 +01001032/* UE registration from unregistered HNB */
1033testcase TC_ue_register_before_hnb_register() runs on test_CT {
1034 var UE_Identity ue_id := { iMSI := imsi_hex2oct(f_gen_imsi(1)) };
1035 g_num_hnbs := 1;
1036 f_init(start_hnb := false);
1037 f_hnbap_ue_register(0, ue_id, expect_reject := true);
1038 f_shutdown_helper();
1039}
1040
Daniel Willmann19b8d902022-01-05 09:12:34 +01001041/***********************************************************************
1042 * RUA / RANAP Testing
1043 ***********************************************************************/
1044
Neels Hofmeyr7a48df12023-04-20 20:43:43 +02001045/* Translate from {msc,sgsn}x{0..n} to the proper index to use in g_cn[].
1046 * g_cn[] stores CN links, MSCs and SGSNs in the same array.
1047 * For example, for 'sgsn 23', use g_cn[ f_cn_idx(ps_domain := true, cn_nr := 23) ].
1048 *
1049 * Note the naming:
1050 * cn_nr is the number used in the cfg file, as in 'msc 0'.
1051 * cn_idx is the array index in g_cn[].
1052 */
1053private function f_cn_idx(boolean ps_domain, integer cn_nr := 0) return integer
1054{
1055 if (ps_domain) {
1056 return FIRST_SGSN_IDX + cn_nr;
1057 }
1058 return FIRST_MSC_IDX + cn_nr;
1059}
1060
Daniel Willmann19b8d902022-01-05 09:12:34 +01001061private template (value) TestHdlrParams
Neels Hofmeyrf0b9ed12022-06-07 17:46:32 +02001062t_pars(integer imsi_suffix, boolean ps_domain := false, integer hnb_idx := 0,
Neels Hofmeyr7a48df12023-04-20 20:43:43 +02001063 boolean expect_separate_sccp_cr := false, integer tx_sccp_cr_data_len := 0,
Harald Welte18188342024-04-04 01:36:56 +02001064 integer cn_nr := 0, template (value) RANAP_IEs.Cause rab_rel_cause := ts_RanapCause_nas_normal) := {
Daniel Willmann19b8d902022-01-05 09:12:34 +01001065 hnb_idx := hnb_idx,
Neels Hofmeyr7a48df12023-04-20 20:43:43 +02001066 cn_idx := f_cn_idx(ps_domain, cn_nr),
Daniel Willmann19b8d902022-01-05 09:12:34 +01001067 imsi := f_gen_imsi(imsi_suffix),
1068 ps_domain := ps_domain,
Pau Espin Pedrolaf746502023-11-29 16:18:28 +01001069 mgcp_pars := t_MgcpParams,
Neels Hofmeyrf0b9ed12022-06-07 17:46:32 +02001070 hnb := omit, /* filled in later */
Neels Hofmeyrf2c95022023-04-19 01:24:39 +02001071 expect_separate_sccp_cr := expect_separate_sccp_cr,
1072 tx_sccp_cr_data_len := tx_sccp_cr_data_len,
Neels Hofmeyr7d0e6802023-04-20 20:43:55 +02001073 pfcp_local_addr := mp_pfcp_ip_local,
Neels Hofmeyrb1bf16d2023-06-27 02:10:04 +02001074 nas_pdu := omit,
1075 sccp_addr_msc := omit,
Harald Welte0d4a8432024-04-04 01:12:11 +02001076 sccp_addr_hnbgw := omit,
1077 rab_rel_cause := rab_rel_cause
Daniel Willmann19b8d902022-01-05 09:12:34 +01001078}
1079
1080/* Create an Iuh connection; send InitialUE; expect it to appear on new SCCP conenction */
1081friend function f_tc_initial_ue(charstring id, TestHdlrParams pars) runs on ConnHdlr {
1082 f_init_handler(pars);
1083 var RANAP_PDU tx := f_build_initial_ue(g_pars);
1084 f_iuh2iu_connect(tx);
1085}
1086testcase TC_ranap_cs_initial_ue() runs on test_CT {
1087 var ConnHdlr vc_conn;
1088
Pau Espin Pedrol83a49612022-09-12 21:11:05 +02001089 g_num_hnbs := 1;
Daniel Willmann19b8d902022-01-05 09:12:34 +01001090 f_init();
Daniel Willmann19b8d902022-01-05 09:12:34 +01001091
1092 vc_conn := f_start_handler_with_pars(refers(f_tc_initial_ue), t_pars(1));
1093 vc_conn.done;
Neels Hofmeyr3a9140e2023-06-23 04:50:39 +02001094
1095 f_shutdown_helper();
Daniel Willmann19b8d902022-01-05 09:12:34 +01001096}
1097testcase TC_ranap_ps_initial_ue() runs on test_CT {
1098 var ConnHdlr vc_conn;
1099
Pau Espin Pedrol83a49612022-09-12 21:11:05 +02001100 g_num_hnbs := 1;
Daniel Willmann19b8d902022-01-05 09:12:34 +01001101 f_init();
Daniel Willmann19b8d902022-01-05 09:12:34 +01001102
1103 vc_conn := f_start_handler_with_pars(refers(f_tc_initial_ue), t_pars(2, true));
1104 vc_conn.done;
Neels Hofmeyr3a9140e2023-06-23 04:50:39 +02001105
1106 f_shutdown_helper();
Daniel Willmann19b8d902022-01-05 09:12:34 +01001107}
1108
Neels Hofmeyrf2c95022023-04-19 01:24:39 +02001109private function f_vty_set_sccp_max_optional_data(TELNETasp_PT pt, integer val := -1)
Neels Hofmeyrf0b9ed12022-06-07 17:46:32 +02001110{
Neels Hofmeyrf2c95022023-04-19 01:24:39 +02001111 var charstring valstr;
1112 if (val < 0) {
1113 valstr := "standard";
1114 } else {
1115 valstr := int2str(val);
1116 }
Neels Hofmeyrf0b9ed12022-06-07 17:46:32 +02001117 f_vty_enter_config(pt);
Neels Hofmeyrf2c95022023-04-19 01:24:39 +02001118 f_vty_transceive(pt, "cs7 instance 0");
1119 f_vty_transceive(pt, "sccp max-optional-data " & valstr);
Neels Hofmeyrf0b9ed12022-06-07 17:46:32 +02001120 f_vty_transceive(pt, "end");
1121}
1122
1123testcase TC_ranap_cs_initial_ue_empty_cr() runs on test_CT {
1124 var ConnHdlr vc_conn;
1125
Pau Espin Pedrol83a49612022-09-12 21:11:05 +02001126 g_num_hnbs := 1;
Neels Hofmeyrf0b9ed12022-06-07 17:46:32 +02001127 f_init();
Neels Hofmeyrf0b9ed12022-06-07 17:46:32 +02001128
Neels Hofmeyrf2c95022023-04-19 01:24:39 +02001129 f_vty_set_sccp_max_optional_data(HNBGWVTY, 0);
Neels Hofmeyrf0b9ed12022-06-07 17:46:32 +02001130
Neels Hofmeyrf2c95022023-04-19 01:24:39 +02001131 vc_conn := f_start_handler_with_pars(refers(f_tc_initial_ue), t_pars(1, expect_separate_sccp_cr := true));
Neels Hofmeyrf0b9ed12022-06-07 17:46:32 +02001132 vc_conn.done;
1133
1134 /* reset */
Neels Hofmeyrf2c95022023-04-19 01:24:39 +02001135 f_vty_set_sccp_max_optional_data(HNBGWVTY);
Neels Hofmeyr3a9140e2023-06-23 04:50:39 +02001136
1137 f_shutdown_helper();
Neels Hofmeyrf0b9ed12022-06-07 17:46:32 +02001138}
1139testcase TC_ranap_ps_initial_ue_empty_cr() runs on test_CT {
1140 var ConnHdlr vc_conn;
1141
Pau Espin Pedrol83a49612022-09-12 21:11:05 +02001142 g_num_hnbs := 1;
Neels Hofmeyrf0b9ed12022-06-07 17:46:32 +02001143 f_init();
Neels Hofmeyrf0b9ed12022-06-07 17:46:32 +02001144
Neels Hofmeyrf2c95022023-04-19 01:24:39 +02001145 f_vty_set_sccp_max_optional_data(HNBGWVTY, 0);
Neels Hofmeyrf0b9ed12022-06-07 17:46:32 +02001146
Neels Hofmeyrf2c95022023-04-19 01:24:39 +02001147 vc_conn := f_start_handler_with_pars(refers(f_tc_initial_ue), t_pars(2, true, expect_separate_sccp_cr := true));
Neels Hofmeyrf0b9ed12022-06-07 17:46:32 +02001148 vc_conn.done;
1149
1150 /* reset */
Neels Hofmeyrf2c95022023-04-19 01:24:39 +02001151 f_vty_set_sccp_max_optional_data(HNBGWVTY);
Neels Hofmeyr3a9140e2023-06-23 04:50:39 +02001152
1153 f_shutdown_helper();
Neels Hofmeyrf2c95022023-04-19 01:24:39 +02001154}
1155
1156type record Testdata_CR_Limit {
1157 integer data_len,
1158 integer max_optional_data,
1159 boolean expect_separate_sccp_cr
1160};
1161type record of Testdata_CR_Limit Testdata_CR_Limits;
1162
1163testcase TC_sccp_cr_limit() runs on test_CT {
1164 g_num_hnbs := 1;
1165 f_init();
Neels Hofmeyrf2c95022023-04-19 01:24:39 +02001166
1167 const Testdata_CR_Limits tests := {
1168 { data_len := 130, max_optional_data := -1, expect_separate_sccp_cr := false },
1169 { data_len := 131, max_optional_data := -1, expect_separate_sccp_cr := true },
1170
1171 { data_len := 100, max_optional_data := 100, expect_separate_sccp_cr := false },
1172 { data_len := 101, max_optional_data := 100, expect_separate_sccp_cr := true },
1173
1174 { data_len := 200, max_optional_data := 200, expect_separate_sccp_cr := false },
1175 { data_len := 201, max_optional_data := 200, expect_separate_sccp_cr := true }
1176 };
1177
1178 var integer csps;
1179 for (csps := 0; csps < 2; csps := csps + 1) {
1180 var boolean ps_domain := (csps > 0);
1181
1182 var integer i;
1183 for (i := 0; i < lengthof(tests); i := i + 1) {
1184 var Testdata_CR_Limit t := tests[i];
1185 f_logp(HNBGWVTY,
1186 "TEST PART TC_sccp_cr_limit ps_domain=" & f_bool2str(ps_domain)
1187 & " data_len=" & int2str(t.data_len)
1188 & " max_optional_data=" & int2str(t.max_optional_data)
1189 & " expect_separate_sccp_cr=" & f_bool2str(t.expect_separate_sccp_cr)
1190 );
1191
1192 f_vty_set_sccp_max_optional_data(HNBGWVTY, t.max_optional_data);
1193 var ConnHdlr vc_conn;
1194 vc_conn := f_start_handler_with_pars(refers(f_tc_initial_ue),
1195 t_pars(100 + i,
1196 ps_domain := ps_domain,
1197 expect_separate_sccp_cr := t.expect_separate_sccp_cr,
1198 tx_sccp_cr_data_len := t.data_len));
1199 vc_conn.done;
1200 }
1201 }
1202
1203 /* reset */
1204 f_vty_set_sccp_max_optional_data(HNBGWVTY);
Neels Hofmeyr3a9140e2023-06-23 04:50:39 +02001205
1206 f_shutdown_helper();
Neels Hofmeyrf0b9ed12022-06-07 17:46:32 +02001207}
1208
Daniel Willmann19b8d902022-01-05 09:12:34 +01001209/* Reply to a received CRCX with an OK (or the reply configured in cpars), using the given parameters.
1210 * Return true when an OK reply was sent, false otherwise.
1211 * Count occurrence of Osmux, include Osmux parameters in the reply if necessary. */
1212function f_handle_crcx(inout MgcpParameters pars, MgcpCommand mgcp_cmd) return template MgcpResponse {
Pau Espin Pedrol264679f2023-11-29 15:52:00 +01001213 var MgwResponse conn := pars.mgw_conn_ran;
Daniel Willmann19b8d902022-01-05 09:12:34 +01001214 if (pars.got_crcx_count > 0) {
Pau Espin Pedrolb85ac2f2023-11-29 15:48:57 +01001215 conn := pars.mgw_conn_cn;
Daniel Willmann19b8d902022-01-05 09:12:34 +01001216 }
1217 pars.got_crcx_count := pars.got_crcx_count + 1;
1218
1219 var MgcpMessage mgcp_msg := {
1220 command := mgcp_cmd
1221 }
1222 var template MgcpResponse mgcp_resp;
1223 var MgcpOsmuxCID osmux_cid;
1224 var MgcpCallId call_id := f_MgcpCmd_extract_call_id(mgcp_cmd);
1225 if (ispresent(pars.mgcp_call_id)) {
1226 if (pars.mgcp_call_id != call_id) {
1227 setverdict(fail, "CRCX contained unexpected call id. Expected:", pars.mgcp_call_id, " got:", call_id);
1228 mtc.stop;
1229 }
1230 } else {
1231 pars.mgcp_call_id := call_id;
1232 }
1233
1234 /* When the endpoint contains a wildcard we keep the endpoint
1235 * identifier we have set up in pars. Otherwise we use the
1236 * endpoint name that the call agent has supplied */
1237 if (match(mgcp_cmd.line.ep, t_MGCP_EP_wildcard) == false) {
1238 pars.mgcp_ep := mgcp_cmd.line.ep;
1239 }
1240
1241 if (conn.resp == -1) {
1242 /* Reply with rror */
1243 var MgcpResponse mgcp_rsp := {
1244 line := {
1245 code := "542",
1246 trans_id := mgcp_cmd.line.trans_id,
1247 string := "FORCED_FAIL"
1248 },
1249 sdp := omit
1250
1251 }
1252 var MgcpParameter mgcp_rsp_param := {
1253 code := "Z",
1254 val := pars.mgcp_ep
1255 };
1256 mgcp_rsp.params[0] := mgcp_rsp_param;
1257 return mgcp_rsp;
1258 }
1259
1260 if (conn.resp == 0) {
1261 /* Do not reply at all */
1262 return omit;
1263 }
1264
1265 if (conn.resp != 1) {
1266 setverdict(fail, "Unexpected value for pars.mgw_conn_*.resp, expect -1, 0 or 1");
1267 mtc.stop;
1268 }
1269
1270 var SDP_Message sdp := valueof(ts_SDP(conn.mgw_rtp_ip, conn.mgw_rtp_ip,
1271 hex2str(pars.mgcp_call_id), "42",
1272 conn.mgw_rtp_port,
1273 { int2str(pars.rtp_payload_type) },
1274 { valueof(ts_SDP_rtpmap(pars.rtp_payload_type,
1275 pars.rtp_sdp_format)),
1276 valueof(ts_SDP_ptime(20)) }));
1277
1278 if (f_mgcp_contains_par(mgcp_msg, "X-OSMUX")) {
1279 if (not pars.use_osmux) {
1280 setverdict(fail, "MSC sent X-Osmux parameter in MGCP, but not expecting any Osmux");
1281 mtc.stop;
1282 }
1283 pars.got_osmux_count := pars.got_osmux_count + 1;
1284 /* we expect MSC to use wildcard here, i.e. osmux_cid == -1 */
1285 osmux_cid := f_MgcpCmd_extract_osmux_cid(mgcp_cmd);
1286 log("f_handle_crcx(): got Osmux CID: ", osmux_cid);
1287 if (osmux_cid != -1) {
1288 setverdict(fail, "MSC using unexpected CID " & int2str(osmux_cid) & " != -1");
1289 mtc.stop;
1290 }
1291
1292 osmux_cid := 0;
1293 mgcp_resp := ts_CRCX_ACK_osmux(mgcp_cmd.line.trans_id, conn.mgcp_connection_id, osmux_cid, sdp);
1294 } else {
1295 mgcp_resp := ts_CRCX_ACK(mgcp_cmd.line.trans_id, conn.mgcp_connection_id, sdp);
1296 }
1297
1298 f_mgcp_par_append(mgcp_resp.params, ts_MgcpParSpecEP(pars.mgcp_ep));
1299
1300 return mgcp_resp;
1301}
1302
Daniel Willmann3e15b7b2022-02-21 17:07:02 +01001303friend function f_create_rab(inout MgcpParameters pars) runs on ConnHdlr {
1304 f_rab_ass_req(pars);
1305 f_rab_ass_resp(pars);
1306}
1307
1308friend function f_rab_ass_req(inout MgcpParameters pars) runs on ConnHdlr {
Daniel Willmann19b8d902022-01-05 09:12:34 +01001309 var MgcpCommand mgcp_cmd;
1310 var RANAP_PDU tx;
1311 var template RAB_SetupOrModifyList rab_sml;
Daniel Willmann19b8d902022-01-05 09:12:34 +01001312 timer T := 5.0;
1313
1314 /* Send RAB Assignment Request */
1315 rab_sml := ts_RAB_SML(t_RAB_id(23), f_ts_RAB_TLA(pars.cn_rtp_ip), t_RAB_binding_port(pars.cn_rtp_port));
1316 tx := valueof(ts_RANAP_RabAssReq(rab_sml));
1317 BSSAP.send(tx);
1318 T.start;
1319
1320 /* Handle MGCP CRCX */
1321 alt {
1322 [] MGCP.receive(tr_CRCX) -> value mgcp_cmd {
1323 log("CRCX1", mgcp_cmd);
1324 var template MgcpResponse mgcp_rsp := f_handle_crcx(pars, mgcp_cmd);
1325 MGCP.send(valueof(mgcp_rsp));
1326 }
1327 [] T.timeout {
1328 setverdict(fail, "Timeout waiting for MGCP");
1329 }
1330 }
Neels Hofmeyr735b6562023-03-09 02:51:28 +01001331 T.stop;
Daniel Willmann19b8d902022-01-05 09:12:34 +01001332
1333 /* Expect RAB Assignment Request with IP/port from CRCX ACK via Iuh */
Pau Espin Pedrolb85ac2f2023-11-29 15:48:57 +01001334 rab_sml := ts_RAB_SML(t_RAB_id(23), f_ts_RAB_TLA(pars.mgw_conn_ran.mgw_rtp_ip), t_RAB_binding_port(pars.mgw_conn_ran.mgw_rtp_port));
Daniel Willmann19b8d902022-01-05 09:12:34 +01001335 tx := valueof(ts_RANAP_RabAssReq(rab_sml));
1336
Neels Hofmeyr735b6562023-03-09 02:51:28 +01001337 f_rua_expect(tx);
Daniel Willmann3e15b7b2022-02-21 17:07:02 +01001338}
1339
1340friend function f_rab_ass_resp(inout MgcpParameters pars) runs on ConnHdlr {
1341 var MgcpCommand mgcp_cmd;
1342 var RANAP_PDU tx;
1343 var template RAB_SetupOrModifiedList rab_smdl;
Daniel Willmann19b8d902022-01-05 09:12:34 +01001344
1345 /* Send back RAB Assignment Response via Iuh */
1346 rab_smdl := ts_RAB_SMdL(t_RAB_id(23), f_ts_RAB_TLA(pars.hnb_rtp_ip), t_RAB_binding_port(pars.hnb_rtp_port));
1347 tx := valueof(ts_RANAP_RabAssResp(rab_smdl));
1348 RUA.send(tx);
Daniel Willmann19b8d902022-01-05 09:12:34 +01001349
1350 interleave {
1351 /* Expect MDCX with IP/port from RAB Assignment Response */
1352 [] MGCP.receive(tr_MDCX(tr_SDP(pars.hnb_rtp_ip, pars.hnb_rtp_port))) -> value mgcp_cmd {
Pau Espin Pedrol0c35a632023-11-29 16:00:35 +01001353 var HostName mgw_rtp_ip;
Pau Espin Pedrolaf746502023-11-29 16:18:28 +01001354 var boolean exp_rua_rab_reass := false;
Daniel Willmann19b8d902022-01-05 09:12:34 +01001355 log("MDCX1", mgcp_cmd);
Pau Espin Pedrol0c35a632023-11-29 16:00:35 +01001356 if (ispresent(pars.mgw_conn_ran.mgw_rtp_ip_mdcx)) {
1357 mgw_rtp_ip := pars.mgw_conn_ran.mgw_rtp_ip_mdcx;
Pau Espin Pedrolaf746502023-11-29 16:18:28 +01001358 if (pars.mgw_conn_ran.mgw_rtp_ip != pars.mgw_conn_ran.mgw_rtp_ip_mdcx) {
1359 exp_rua_rab_reass := true;
1360 }
Pau Espin Pedrol0c35a632023-11-29 16:00:35 +01001361 } else {
1362 mgw_rtp_ip := pars.mgw_conn_ran.mgw_rtp_ip;
1363 }
1364
Daniel Willmann19b8d902022-01-05 09:12:34 +01001365 /* Verify SDP of MDCX */
Pau Espin Pedrol0c35a632023-11-29 16:00:35 +01001366 var SDP_Message sdp := valueof(ts_SDP(mgw_rtp_ip, mgw_rtp_ip, hex2str(pars.mgcp_call_id), "42", pars.mgw_conn_ran.mgw_rtp_port,
Daniel Willmann19b8d902022-01-05 09:12:34 +01001367 { int2str(pars.rtp_payload_type) }, { valueof(ts_SDP_rtpmap(pars.rtp_payload_type, pars.rtp_sdp_format)), valueof(ts_SDP_ptime(20)) } ));
Pau Espin Pedrolb85ac2f2023-11-29 15:48:57 +01001368 var template MgcpResponse mgcp_rsp := ts_MDCX_ACK(mgcp_cmd.line.trans_id, pars.mgw_conn_ran.mgcp_connection_id, sdp);
Daniel Willmann19b8d902022-01-05 09:12:34 +01001369 MGCP.send(valueof(mgcp_rsp));
Pau Espin Pedrolaf746502023-11-29 16:18:28 +01001370
1371 /* If IP address changed, we expect HNBGW to Modify the RAB through RAB-Ass-Req: */
1372 if (exp_rua_rab_reass) {
1373 var template RAB_SetupOrModifyList rab_sml;
1374 /* Expect RAB Assignment Request with IP/port from MDCX ACK via Iuh */
1375 rab_sml := ts_RAB_SML(t_RAB_id(23), f_ts_RAB_TLA(pars.mgw_conn_ran.mgw_rtp_ip_mdcx), t_RAB_binding_port(pars.mgw_conn_ran.mgw_rtp_port));
1376 tx := valueof(ts_RANAP_RabAssReq(rab_sml));
1377
1378 f_rua_expect(tx);
1379 /* Send back RAB Assignment Response via Iuh */
1380 rab_smdl := ts_RAB_SMdL(t_RAB_id(23), f_ts_RAB_TLA(pars.hnb_rtp_ip), t_RAB_binding_port(pars.hnb_rtp_port));
1381 tx := valueof(ts_RANAP_RabAssResp(rab_smdl));
1382 RUA.send(tx);
1383 /* This shouldn't trigger any MGCP, since nothing changed on the HNB IP side. Continue below. */
1384 }
Daniel Willmann19b8d902022-01-05 09:12:34 +01001385 }
1386 /* Handle CRCX for second leg of endpoint, answer with IP/port */
1387 [] MGCP.receive(tr_CRCX(pars.mgcp_ep, tr_SDP(pars.cn_rtp_ip, pars.cn_rtp_port))) -> value mgcp_cmd {
1388 log("CRCX2", mgcp_cmd);
1389 /* Verify SDP of CRCX */
1390 var template MgcpResponse mgcp_rsp := f_handle_crcx(pars, mgcp_cmd);
1391 MGCP.send(valueof(mgcp_rsp));
1392 }
1393 }
1394
1395 /* Expect RAB Assignment Response with IP/port from second CRCX ACK */
Pau Espin Pedrolb85ac2f2023-11-29 15:48:57 +01001396 rab_smdl := ts_RAB_SMdL(t_RAB_id(23), f_ts_RAB_TLA(pars.mgw_conn_cn.mgw_rtp_ip), t_RAB_binding_port(pars.mgw_conn_cn.mgw_rtp_port));
Daniel Willmann19b8d902022-01-05 09:12:34 +01001397 tx := valueof(ts_RANAP_RabAssResp(rab_smdl));
1398
Neels Hofmeyrdc416c92023-03-09 02:47:50 +01001399 f_bssap_expect(tx);
Daniel Willmann19b8d902022-01-05 09:12:34 +01001400}
1401
1402private altstep as_mgcp_dlcx(inout TestHdlrParams pars) runs on ConnHdlr {
1403 var MgcpCommand mgcp_cmd;
1404
1405 [] MGCP.receive(tr_DLCX(pars.mgcp_pars.mgcp_ep)) -> value mgcp_cmd {
1406 log("DLCX", mgcp_cmd);
1407 MGCP.send(ts_DLCX_ACK2(mgcp_cmd.line.trans_id));
1408 pars.mgcp_pars.got_dlcx_count := pars.mgcp_pars.got_dlcx_count + 1;
Daniel Willmann3e15b7b2022-02-21 17:07:02 +01001409 if (pars.mgcp_pars.got_dlcx_count != pars.mgcp_pars.got_crcx_count) {
Daniel Willmann19b8d902022-01-05 09:12:34 +01001410 repeat;
1411 }
1412 setverdict(pass);
1413 }
1414}
1415
1416friend function f_tc_rab_assignment(charstring id, TestHdlrParams pars) runs on ConnHdlr {
Harald Welte904b5f12024-04-04 02:47:30 +02001417 const charstring hnb0_ctr_prefix := "TTCN3.hnb.001-01-L2342-R0-S55-C1.";
Daniel Willmann19b8d902022-01-05 09:12:34 +01001418 var MgcpCommand mgcp_cmd;
1419 var RANAP_PDU tx;
1420 timer T := 5.0;
1421
1422 f_init_handler(pars);
1423 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
1424
Harald Welte904b5f12024-04-04 02:47:30 +02001425 f_statsd_reset();
1426
Daniel Willmann19b8d902022-01-05 09:12:34 +01001427 tx := f_build_initial_ue(g_pars);
1428 f_iuh2iu_connect(tx);
1429
Harald Welte904b5f12024-04-04 02:47:30 +02001430 /* Expect stats to be 0 */
1431 var StatsDExpects expect := {
1432 {name := hnb0_ctr_prefix & "ranap.cs.rab_act.req", mtype := "c", min := 0, max := 0},
1433 {name := hnb0_ctr_prefix & "ranap.cs.rab_act.cnf", mtype := "c", min := 0, max := 0},
1434 {name := hnb0_ctr_prefix & "ranap.cs.rab_act.fail", mtype := "c", min := 0, max := 0}
1435 };
1436 f_statsd_expect(expect);
1437
Daniel Willmann19b8d902022-01-05 09:12:34 +01001438 f_create_rab(pars.mgcp_pars);
1439
Harald Welte904b5f12024-04-04 02:47:30 +02001440 expect := {
1441 {name := hnb0_ctr_prefix & "ranap.cs.rab_act.req", mtype := "c", min := 1, max := 1},
1442 {name := hnb0_ctr_prefix & "ranap.cs.rab_act.cnf", mtype := "c", min := 1, max := 1},
1443 {name := hnb0_ctr_prefix & "ranap.cs.rab_act.fail", mtype := "c", min := 0, max := 0}
1444 };
1445 f_statsd_expect(expect);
1446
Daniel Willmann19b8d902022-01-05 09:12:34 +01001447 /* Send Iu Release */
Harald Welte0d4a8432024-04-04 01:12:11 +02001448 tx := valueof(ts_RANAP_IuReleaseCommand(pars.rab_rel_cause));
Daniel Willmann19b8d902022-01-05 09:12:34 +01001449 f_iu2iuh(tx);
1450
1451 T.start;
1452 alt {
1453 [] as_mgcp_dlcx(pars) {}
1454 [] T.timeout {
1455 setverdict(fail, "Timeout waiting for DLCX");
1456 }
1457 }
1458
1459 tx := valueof(ts_RANAP_IuReleaseComplete());
1460 f_iuh2iu(tx);
1461}
1462
1463testcase TC_rab_assignment() runs on test_CT {
1464 var ConnHdlr vc_conn;
Pau Espin Pedrol83a49612022-09-12 21:11:05 +02001465 g_num_hnbs := 1;
Daniel Willmann19b8d902022-01-05 09:12:34 +01001466 f_init();
Daniel Willmann19b8d902022-01-05 09:12:34 +01001467
1468 vc_conn := f_start_handler_with_pars(refers(f_tc_rab_assignment), t_pars(3));
1469 vc_conn.done;
Neels Hofmeyr3a9140e2023-06-23 04:50:39 +02001470
1471 f_shutdown_helper();
Daniel Willmann19b8d902022-01-05 09:12:34 +01001472}
1473
Daniel Willmann3e15b7b2022-02-21 17:07:02 +01001474friend function f_tc_rab_assign_fail(charstring id, TestHdlrParams pars) runs on ConnHdlr {
Harald Welte904b5f12024-04-04 02:47:30 +02001475 const charstring hnb0_ctr_prefix := "TTCN3.hnb.001-01-L2342-R0-S55-C1.";
Daniel Willmann3e15b7b2022-02-21 17:07:02 +01001476 var MgcpCommand mgcp_cmd;
1477 var RANAP_PDU tx;
1478 timer T := 5.0;
1479
1480 f_init_handler(pars);
1481 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
1482
Harald Welte904b5f12024-04-04 02:47:30 +02001483 f_statsd_reset();
1484
Daniel Willmann3e15b7b2022-02-21 17:07:02 +01001485 tx := f_build_initial_ue(g_pars);
1486 f_iuh2iu_connect(tx);
1487
Harald Welte904b5f12024-04-04 02:47:30 +02001488 /* Expect stats to be 0 */
1489 var StatsDExpects expect := {
1490 {name := hnb0_ctr_prefix & "ranap.cs.rab_act.req", mtype := "c", min := 0, max := 0},
1491 {name := hnb0_ctr_prefix & "ranap.cs.rab_act.cnf", mtype := "c", min := 0, max := 0},
1492 {name := hnb0_ctr_prefix & "ranap.cs.rab_act.fail", mtype := "c", min := 0, max := 0}
1493 };
1494 f_statsd_expect(expect);
1495
Daniel Willmann3e15b7b2022-02-21 17:07:02 +01001496 f_rab_ass_req(pars.mgcp_pars);
1497
1498 /* Send RAB failed list in response */
Harald Welte0d4a8432024-04-04 01:12:11 +02001499 tx := valueof(ts_RANAP_RabAssResp(rab_fl := ts_RAB_FL(t_RAB_id(23), pars.rab_rel_cause)));
Daniel Willmann3e15b7b2022-02-21 17:07:02 +01001500 f_iuh2iu(tx);
1501
Harald Welte904b5f12024-04-04 02:47:30 +02001502 expect := {
1503 {name := hnb0_ctr_prefix & "ranap.cs.rab_act.req", mtype := "c", min := 1, max := 1},
1504 {name := hnb0_ctr_prefix & "ranap.cs.rab_act.cnf", mtype := "c", min := 0, max := 0},
1505 {name := hnb0_ctr_prefix & "ranap.cs.rab_act.fail", mtype := "c", min := 1, max := 1}
1506 };
1507 f_statsd_expect(expect);
1508
1509
Daniel Willmann3e15b7b2022-02-21 17:07:02 +01001510 T.start;
1511 alt {
1512 [] as_mgcp_dlcx(pars) {}
1513 [] T.timeout {
1514 setverdict(fail, "Timeout waiting for DLCX");
1515 }
1516 }
1517}
1518
1519testcase TC_rab_assign_fail() runs on test_CT {
1520 var ConnHdlr vc_conn;
Pau Espin Pedrol83a49612022-09-12 21:11:05 +02001521 g_num_hnbs := 1;
Daniel Willmann3e15b7b2022-02-21 17:07:02 +01001522 f_init();
Daniel Willmann3e15b7b2022-02-21 17:07:02 +01001523
Harald Welte18188342024-04-04 01:36:56 +02001524 vc_conn := f_start_handler_with_pars(refers(f_tc_rab_assign_fail), t_pars(4, rab_rel_cause := ts_RanapCause_radio_conn_lost));
Daniel Willmann3e15b7b2022-02-21 17:07:02 +01001525 vc_conn.done;
Neels Hofmeyr3a9140e2023-06-23 04:50:39 +02001526
1527 f_shutdown_helper();
Daniel Willmann3e15b7b2022-02-21 17:07:02 +01001528}
1529
Daniel Willmann19b8d902022-01-05 09:12:34 +01001530friend function f_tc_rab_release(charstring id, TestHdlrParams pars) runs on ConnHdlr {
Harald Welte904b5f12024-04-04 02:47:30 +02001531 const charstring hnb0_ctr_prefix := "TTCN3.hnb.001-01-L2342-R0-S55-C1.";
Daniel Willmann19b8d902022-01-05 09:12:34 +01001532 var MgcpCommand mgcp_cmd;
1533 var RANAP_PDU tx;
1534 timer T := 15.0;
1535
1536 f_init_handler(pars);
1537 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
1538
Harald Welte904b5f12024-04-04 02:47:30 +02001539 f_statsd_reset();
1540
Daniel Willmann19b8d902022-01-05 09:12:34 +01001541 tx := f_build_initial_ue(g_pars);
1542 f_iuh2iu_connect(tx);
1543
1544 f_create_rab(pars.mgcp_pars);
1545
Harald Welte904b5f12024-04-04 02:47:30 +02001546 var charstring ctr_name;
1547 if (pars.rab_rel_cause == valueof(ts_RanapCause_nas_normal)) {
1548 ctr_name := "ranap.cs.rab_rel.req.normal";
1549 } else {
1550 ctr_name := "ranap.cs.rab_rel.req.abnormal";
1551 }
1552
1553 /* Expect stats to be 0 */
1554 var StatsDExpects expect := {
1555 {name := hnb0_ctr_prefix & ctr_name, mtype := "c", min := 0, max := 0}
1556 };
1557 f_statsd_expect(expect);
1558
Daniel Willmann19b8d902022-01-05 09:12:34 +01001559 /* Send RAB Release */
Harald Welte0d4a8432024-04-04 01:12:11 +02001560 tx := valueof(ts_RANAP_RabAssReq(rab_rl := ts_RAB_RL(t_RAB_id(23), pars.rab_rel_cause)));
Daniel Willmann19b8d902022-01-05 09:12:34 +01001561 BSSAP.send(tx);
1562
Harald Welte904b5f12024-04-04 02:47:30 +02001563 expect := {
1564 {name := hnb0_ctr_prefix & ctr_name, mtype := "c", min := 1, max := 1}
1565 };
1566 f_statsd_expect(expect);
1567
Daniel Willmann19b8d902022-01-05 09:12:34 +01001568 T.start;
1569
1570 alt {
1571 [] as_mgcp_dlcx(pars) {}
1572 [] T.timeout {
1573 setverdict(fail, "Timeout waiting for DLCX");
1574 }
1575 }
Neels Hofmeyr735b6562023-03-09 02:51:28 +01001576 T.stop;
Daniel Willmann19b8d902022-01-05 09:12:34 +01001577
Neels Hofmeyr735b6562023-03-09 02:51:28 +01001578 f_rua_expect(tx);
Daniel Willmann19b8d902022-01-05 09:12:34 +01001579}
1580
Harald Weltef95ab2d2024-04-04 01:32:20 +02001581/* RAB release with Cause NAS/Normal (successful/orderly release) */
Daniel Willmann19b8d902022-01-05 09:12:34 +01001582testcase TC_rab_release() runs on test_CT {
1583 var ConnHdlr vc_conn;
Pau Espin Pedrol83a49612022-09-12 21:11:05 +02001584 g_num_hnbs := 1;
Daniel Willmann19b8d902022-01-05 09:12:34 +01001585 f_init();
Daniel Willmann19b8d902022-01-05 09:12:34 +01001586
1587 vc_conn := f_start_handler_with_pars(refers(f_tc_rab_release), t_pars(5));
1588 vc_conn.done;
Neels Hofmeyr3a9140e2023-06-23 04:50:39 +02001589
1590 f_shutdown_helper();
Daniel Willmann19b8d902022-01-05 09:12:34 +01001591}
1592
Harald Weltef95ab2d2024-04-04 01:32:20 +02001593/* RAB release with Cause abnormal */
1594testcase TC_rab_release_abnormal() runs on test_CT {
1595 var ConnHdlr vc_conn;
1596 g_num_hnbs := 1;
1597 f_init();
1598
Harald Welte7a9e7962024-04-04 02:46:45 +02001599 vc_conn := f_start_handler_with_pars(refers(f_tc_rab_release),
1600 t_pars(8, rab_rel_cause := ts_RanapCause_radio_conn_lost));
Harald Weltef95ab2d2024-04-04 01:32:20 +02001601 vc_conn.done;
1602
1603 f_shutdown_helper();
1604}
1605
Daniel Willmann37c877f2022-02-22 16:47:06 +01001606friend function f_tc_rab_assign_mgcp_to(charstring id, TestHdlrParams pars) runs on ConnHdlr {
1607 var MgcpCommand mgcp_cmd;
1608 var RANAP_PDU tx;
1609 var template RAB_SetupOrModifyList rab_sml;
1610 timer T := 15.0;
1611
1612 T.start;
1613 f_init_handler(pars);
1614 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
1615
1616 tx := f_build_initial_ue(g_pars);
1617 f_iuh2iu_connect(tx);
1618
1619
1620 /* Send RAB Assignment Request */
1621 rab_sml := ts_RAB_SML(t_RAB_id(23), f_ts_RAB_TLA(pars.mgcp_pars.cn_rtp_ip), t_RAB_binding_port(pars.mgcp_pars.cn_rtp_port));
1622 tx := valueof(ts_RANAP_RabAssReq(rab_sml));
1623 BSSAP.send(tx);
1624
1625 /* Ignore MGCP CRCX */
1626 alt {
1627 [] MGCP.receive(tr_CRCX) -> value mgcp_cmd {
1628 log("Ignoreing CRCX1", mgcp_cmd);
1629 repeat;
1630 }
1631 [] BSSAP.receive(tr_RANAP_IuReleaseRequest(?)) { }
1632 [] T.timeout {
1633 setverdict(fail, "Timeout waiting for IuRelease");
1634 }
1635 }
1636
1637 /* Send Iu Release */
Harald Welte0d4a8432024-04-04 01:12:11 +02001638 tx := valueof(ts_RANAP_IuReleaseCommand(pars.rab_rel_cause));
Daniel Willmann37c877f2022-02-22 16:47:06 +01001639 f_iu2iuh(tx);
1640
1641 tx := valueof(ts_RANAP_IuReleaseComplete());
1642 f_iuh2iu(tx);
1643}
1644
1645testcase TC_rab_assign_mgcp_to() runs on test_CT {
1646 var ConnHdlr vc_conn;
Pau Espin Pedrol83a49612022-09-12 21:11:05 +02001647 g_num_hnbs := 1;
Daniel Willmann37c877f2022-02-22 16:47:06 +01001648 f_init();
Daniel Willmann37c877f2022-02-22 16:47:06 +01001649
1650 vc_conn := f_start_handler_with_pars(refers(f_tc_rab_assign_mgcp_to), t_pars(6));
1651 vc_conn.done;
Neels Hofmeyr3a9140e2023-06-23 04:50:39 +02001652
1653 f_shutdown_helper();
Daniel Willmann37c877f2022-02-22 16:47:06 +01001654}
1655
Pau Espin Pedrolaf746502023-11-29 16:18:28 +01001656/* Test case where IuUP IP address announced by HNB and updated through MDCX
1657 * makes MGW select a new local IuUP address. HNBGW is expected to update the HNB
1658 * through RAB-Modify-Req. */
1659testcase TC_rab_assign_mgw_iuup_addr_chg() runs on test_CT {
1660 var ConnHdlr vc_conn;
1661 g_num_hnbs := 1;
1662 f_init();
1663 var template (value) TestHdlrParams pars := t_pars(3);
1664 /* Emulate change of local IuUP IP address after rx MDCX: */
1665 pars.mgcp_pars.mgw_conn_ran.mgw_rtp_ip_mdcx := "127.3.2.1";
1666
1667 vc_conn := f_start_handler_with_pars(refers(f_tc_rab_assignment), pars);
1668 vc_conn.done;
1669
1670 f_shutdown_helper();
1671}
1672
Daniel Willmann19b8d902022-01-05 09:12:34 +01001673/* Create an Iuh connection; send InitialUE; transceive data both directions */
1674friend function f_tc_ranap_bidir(charstring id, TestHdlrParams pars) runs on ConnHdlr {
1675 f_init_handler(pars);
1676
1677 /* HNB -> MSC: InitialUE */
1678 f_iuh2iu_connect(f_build_initial_ue(g_pars));
1679
1680 /* MSC <- HNB: DirectTransfer */
1681 f_iu2iuh(ts_RANAP_DirectTransfer(f_rnd_octstring(10)));
1682 /* MSC -> HNB: DirectTransfer */
1683 f_iuh2iu(ts_RANAP_DirectTransfer(f_rnd_octstring(10)));
1684
1685 /* HNB <- MSC: CommonID */
1686 f_iu2iuh(ts_RANAP_CommonId(hex2oct(pars.imsi)));
1687}
1688testcase TC_ranap_cs_bidir() runs on test_CT {
1689 var ConnHdlr vc_conn;
Pau Espin Pedrol83a49612022-09-12 21:11:05 +02001690 g_num_hnbs := 1;
Daniel Willmann19b8d902022-01-05 09:12:34 +01001691 f_init();
Daniel Willmann19b8d902022-01-05 09:12:34 +01001692
1693 vc_conn := f_start_handler_with_pars(refers(f_tc_ranap_bidir), t_pars(3));
1694 vc_conn.done;
Neels Hofmeyr3a9140e2023-06-23 04:50:39 +02001695
1696 f_shutdown_helper();
Daniel Willmann19b8d902022-01-05 09:12:34 +01001697}
1698testcase TC_ranap_ps_bidir() runs on test_CT {
1699 var ConnHdlr vc_conn;
Pau Espin Pedrol83a49612022-09-12 21:11:05 +02001700 g_num_hnbs := 1;
Daniel Willmann19b8d902022-01-05 09:12:34 +01001701 f_init();
Daniel Willmann19b8d902022-01-05 09:12:34 +01001702
1703 vc_conn := f_start_handler_with_pars(refers(f_tc_ranap_bidir), t_pars(4, true));
1704 vc_conn.done;
Neels Hofmeyr3a9140e2023-06-23 04:50:39 +02001705
1706 f_shutdown_helper();
Daniel Willmann19b8d902022-01-05 09:12:34 +01001707}
1708
1709
1710private function f_tc_ranap_mo_disconnect(charstring id, TestHdlrParams pars) runs on ConnHdlr {
1711 f_init_handler(pars);
1712
1713 /* HNB -> MSC: InitialUE */
1714 f_iuh2iu_connect(f_build_initial_ue(g_pars));
1715
1716 /* MSC <- HNB: DirectTransfer */
1717 f_iu2iuh(ts_RANAP_DirectTransfer(f_rnd_octstring(10)));
1718 /* MSC -> HNB: DirectTransfer */
1719 f_iuh2iu(ts_RANAP_DirectTransfer(f_rnd_octstring(10)));
1720
1721 /* MSC <- HNB: RUA disconnect */
1722 f_iuh2iu_disconnect(ts_RANAP_IuReleaseComplete, RUA_IEs.Cause:{misc:=processing_overload});
1723}
1724testcase TC_ranap_cs_mo_disconnect() runs on test_CT {
1725 var ConnHdlr vc_conn;
Pau Espin Pedrol83a49612022-09-12 21:11:05 +02001726 g_num_hnbs := 1;
Daniel Willmann19b8d902022-01-05 09:12:34 +01001727 f_init();
Daniel Willmann19b8d902022-01-05 09:12:34 +01001728
1729 vc_conn := f_start_handler_with_pars(refers(f_tc_ranap_mo_disconnect), t_pars(5));
1730 vc_conn.done;
Neels Hofmeyr3a9140e2023-06-23 04:50:39 +02001731
1732 f_shutdown_helper();
Daniel Willmann19b8d902022-01-05 09:12:34 +01001733}
1734testcase TC_ranap_ps_mo_disconnect() runs on test_CT {
1735 var ConnHdlr vc_conn;
Pau Espin Pedrol83a49612022-09-12 21:11:05 +02001736 g_num_hnbs := 1;
Daniel Willmann19b8d902022-01-05 09:12:34 +01001737 f_init();
Daniel Willmann19b8d902022-01-05 09:12:34 +01001738
1739 vc_conn := f_start_handler_with_pars(refers(f_tc_ranap_mo_disconnect), t_pars(6));
1740 vc_conn.done;
Neels Hofmeyr3a9140e2023-06-23 04:50:39 +02001741
1742 f_shutdown_helper();
Daniel Willmann19b8d902022-01-05 09:12:34 +01001743}
1744
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001745type record FTeid {
1746 HostName addr,
1747 OCT4 teid
1748}
1749
1750type record FTeids {
1751 FTeid local,
1752 FTeid remote
1753}
Daniel Willmann19b8d902022-01-05 09:12:34 +01001754
1755
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001756/* 'local' and 'remote' refer to the GTP information from the UPF's point of view:
1757 * HNB UPF CN
1758 * access.remote <---> access.local | core.local <---> core.remote
1759 */
1760type record GtpParameters {
1761 FTeids core,
1762 FTeids access
1763}
1764
1765/* HNB UPF CN
1766 * access.remote <---> access.local | core.local <---> core.remote
1767 * 127.0.0.4 127.0.0.3 127.0.0.2 127.0.0.1
1768 * 0x44004400 0x30303030 0x22002200 0x10101010
1769 */
1770template GtpParameters t_GtpParameters := {
1771 core := {
1772 local := {
1773 addr := "127.0.0.2",
1774 teid := '22002200'O
1775 },
1776 remote := {
1777 addr := "127.0.0.1",
1778 teid := '10101010'O
1779 }
1780 },
1781 access := {
1782 local := {
1783 addr := "127.0.0.3",
1784 teid := '30303030'O
1785 },
1786 remote := {
1787 addr := "127.0.0.4",
1788 teid := '44004400'O
1789 }
1790 }
1791}
1792
Neels Hofmeyr65499282023-04-25 02:31:51 +02001793private function f_pfcp_expect(template (present) PDU_PFCP exp_rx, float wait_time := 5.0) runs on ConnHdlr return PDU_PFCP
Neels Hofmeyr6bbfe052023-03-09 02:51:46 +01001794{
1795 var PDU_PFCP rx;
Neels Hofmeyr65499282023-04-25 02:31:51 +02001796 timer T := wait_time;
Neels Hofmeyr6bbfe052023-03-09 02:51:46 +01001797 T.start;
1798 alt {
1799 [] PFCP.receive(exp_rx) -> value rx {
1800 setverdict(pass);
1801 }
1802 [] PFCP.receive(PDU_PFCP:?) {
1803 setverdict(fail, "Got an unexpected PFCP message, was waiting for ", exp_rx);
1804 mtc.stop;
1805 }
1806 [] T.timeout {
1807 setverdict(fail, "Timeout waiting for PFCP ", exp_rx);
1808 mtc.stop;
1809 }
1810 }
1811 T.stop;
1812 return rx;
1813}
1814
Neels Hofmeyrbacb74f2022-08-29 16:24:12 +02001815friend function f_tc_ps_rab_assignment_with_pfcp(charstring id, TestHdlrParams pars) runs on ConnHdlr {
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001816 var RANAP_PDU tx;
1817 var RANAP_PDU rx;
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001818
1819 f_init_handler(pars);
1820
1821 f_pfcp_register();
1822
1823 var PDU_PFCP m;
1824 var Node_ID upf_node_id := valueof(ts_PFCP_Node_ID_fqdn("\07osmocom\03org"));
1825
Neels Hofmeyr65499282023-04-25 02:31:51 +02001826 m := f_pfcp_expect(tr_PFCP_Assoc_Setup_Req(), wait_time := 15.0);
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001827 PFCP.send(ts_PFCP_Assoc_Setup_Resp(m.sequence_number, upf_node_id,
1828 ts_PFCP_Cause(REQUEST_ACCEPTED), 1234));
1829
1830 tx := f_build_initial_ue(g_pars);
1831 f_iuh2iu_connect(tx);
1832
1833 var GtpParameters gtp_pars := valueof(t_GtpParameters);
1834 var template RAB_SetupOrModifyList rab_sml;
1835
1836 /* Send RAB Assignment Request */
1837 rab_sml := ts_RAB_SML_ps(t_RAB_id(23), f_ts_RAB_TLA(gtp_pars.core.remote.addr), gtp_pars.core.remote.teid);
1838 tx := valueof(ts_RANAP_RabAssReq(rab_sml));
1839 BSSAP.send(tx);
1840
1841 /* Expect PFCP Session Establishment Request. */
Neels Hofmeyr6bbfe052023-03-09 02:51:46 +01001842 m := f_pfcp_expect(tr_PFCP_Session_Est_Req());
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001843 var F_SEID hnbgw_f_seid := m.message_body.pfcp_session_establishment_request.CP_F_SEID;
1844 var PFCP_Session_Establishment_Request serq := m.message_body.pfcp_session_establishment_request;
1845
1846 /* Acting as UPF, invent a new PFCP SEID to send to HNBGW. Respond to the Session Establishment.
1847 * The PFCP response must have the same sequence_number as the request. */
Neels Hofmeyr1e311462023-01-11 01:19:12 +01001848 var F_SEID up_f_seid := valueof(ts_PFCP_F_SEID_ipv4(f_inet_addr("127.0.0.1"), '1111111111111111'O));
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001849 var template PDU_PFCP r := ts_PFCP_Session_Est_Resp(m.sequence_number, upf_node_id, hnbgw_f_seid.seid);
1850 r.message_body.pfcp_session_establishment_response := {
1851 offending_ie := omit,
1852 UP_F_SEID := up_f_seid,
1853 created_PDR_list := {
1854 ts_PFCP_Created_PDR(pdr_id := serq.create_PDR_list[0].grouped_ie.pdr_id,
1855 local_F_TEID := ts_PFCP_F_TEID_ipv4(gtp_pars.core.local.teid,
Neels Hofmeyr1e311462023-01-11 01:19:12 +01001856 f_inet_addr(gtp_pars.core.local.addr))),
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001857 ts_PFCP_Created_PDR(pdr_id := serq.create_PDR_list[1].grouped_ie.pdr_id,
1858 local_F_TEID := ts_PFCP_F_TEID_ipv4(gtp_pars.access.local.teid,
Neels Hofmeyr1e311462023-01-11 01:19:12 +01001859 f_inet_addr(gtp_pars.access.local.addr)))
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001860 },
1861 load_control_information := omit,
1862 overload_control_information := omit,
1863 node_list := omit,
1864 failed_rule_id := omit,
1865 created_traffic_endpoint_list := omit
1866 };
1867 PFCP.send(r);
1868
1869 /* Expect on Iuh: RAB Assignment Request with IP/port from PFCP Session Est Resp */
1870 rab_sml := ts_RAB_SML_ps(t_RAB_id(23), f_ts_RAB_TLA(gtp_pars.access.local.addr),
1871 gtp_pars.access.local.teid);
1872 rx := valueof(ts_RANAP_RabAssReq(rab_sml));
Neels Hofmeyr735b6562023-03-09 02:51:28 +01001873 f_rua_expect(rx);
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001874
1875 /* Send back RAB Assignment Response via Iuh */
1876 var template RAB_SetupOrModifiedList rab_smdl;
1877 rab_smdl := ts_RAB_SMdL_ps(t_RAB_id(23), f_ts_RAB_TLA(gtp_pars.access.remote.addr),
1878 gtp_pars.access.remote.teid);
1879 tx := valueof(ts_RANAP_RabAssResp(rab_smdl));
1880 RUA.send(tx);
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001881
Neels Hofmeyr6bbfe052023-03-09 02:51:46 +01001882 m := f_pfcp_expect(tr_PFCP_Session_Mod_Req(up_f_seid.seid));
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001883 r := ts_PFCP_Session_Mod_Resp(m.sequence_number, hnbgw_f_seid.seid);
1884 PFCP.send(r);
1885
1886 rab_smdl := ts_RAB_SMdL_ps(t_RAB_id(23), f_ts_RAB_TLA(gtp_pars.core.local.addr), gtp_pars.core.local.teid);
Neels Hofmeyrdc416c92023-03-09 02:47:50 +01001887 f_bssap_expect(tr_RANAP_RabAssResp(rab_smdl));
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001888
1889 f_sleep(2.0);
Harald Welte0d4a8432024-04-04 01:12:11 +02001890 tx := valueof(ts_RANAP_IuReleaseCommand(pars.rab_rel_cause));
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001891 f_iu2iuh(tx);
1892
1893 tx := valueof(ts_RANAP_IuReleaseComplete());
1894 f_iuh2iu(tx);
1895
Neels Hofmeyr6bbfe052023-03-09 02:51:46 +01001896 m := f_pfcp_expect(tr_PFCP_Session_Del_Req(up_f_seid.seid));
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001897 PFCP.send(ts_PFCP_Session_Del_Resp(m.sequence_number, hnbgw_f_seid.seid));
1898
1899 f_sleep(2.0);
1900}
1901
Neels Hofmeyrbacb74f2022-08-29 16:24:12 +02001902testcase TC_ps_rab_assignment_with_pfcp() runs on test_CT {
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001903 var ConnHdlr vc_conn;
Pau Espin Pedrol83a49612022-09-12 21:11:05 +02001904 g_num_hnbs := 1;
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001905 f_init();
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001906 f_sleep(1.0);
1907
Neels Hofmeyrbacb74f2022-08-29 16:24:12 +02001908 vc_conn := f_start_handler_with_pars(refers(f_tc_ps_rab_assignment_with_pfcp), t_pars(7, ps_domain := true));
1909 vc_conn.done;
Neels Hofmeyr3a9140e2023-06-23 04:50:39 +02001910
1911 f_shutdown_helper();
Neels Hofmeyrbacb74f2022-08-29 16:24:12 +02001912}
1913
1914altstep as_disallow_pfcp() runs on ConnHdlr {
1915 [] PFCP.receive(PDU_PFCP:?) {
1916 setverdict(fail, "Received PFCP message, but no PFCP communication expected");
1917 mtc.stop;
1918 }
1919}
1920
1921friend function f_tc_ps_rab_assignment_without_pfcp(charstring id, TestHdlrParams pars) runs on ConnHdlr {
1922 var RANAP_PDU tx;
1923 var RANAP_PDU rx;
1924 timer T := 5.0;
1925
1926 f_init_handler(pars);
1927
1928 f_pfcp_register();
1929 activate(as_disallow_pfcp());
1930
1931 tx := f_build_initial_ue(g_pars);
1932 f_iuh2iu_connect(tx);
1933
1934 var GtpParameters gtp_pars := valueof(t_GtpParameters);
1935 var template RAB_SetupOrModifyList rab_sml;
1936
1937 /* Send RAB Assignment Request */
1938 rab_sml := ts_RAB_SML_ps(t_RAB_id(23), f_ts_RAB_TLA(gtp_pars.core.remote.addr), gtp_pars.core.remote.teid);
1939 tx := valueof(ts_RANAP_RabAssReq(rab_sml));
1940 BSSAP.send(tx);
1941
1942 /* Expect on Iuh: unmodified RAB Assignment Request */
1943 rx := valueof(ts_RANAP_RabAssReq(rab_sml));
Neels Hofmeyr735b6562023-03-09 02:51:28 +01001944 f_rua_expect(rx);
Neels Hofmeyrbacb74f2022-08-29 16:24:12 +02001945
1946 /* Send back RAB Assignment Response via Iuh */
1947 var template RAB_SetupOrModifiedList rab_smdl;
1948 rab_smdl := ts_RAB_SMdL_ps(t_RAB_id(23), f_ts_RAB_TLA(gtp_pars.access.remote.addr),
1949 gtp_pars.access.remote.teid);
1950 tx := valueof(ts_RANAP_RabAssResp(rab_smdl));
1951 RUA.send(tx);
1952
1953 /* Expect on IuPS: unmodified RAB Assignment Response */
Neels Hofmeyrdc416c92023-03-09 02:47:50 +01001954 f_bssap_expect(tr_RANAP_RabAssResp(rab_smdl));
Neels Hofmeyrbacb74f2022-08-29 16:24:12 +02001955
1956 f_sleep(2.0);
Harald Welte0d4a8432024-04-04 01:12:11 +02001957 tx := valueof(ts_RANAP_IuReleaseCommand(pars.rab_rel_cause));
Neels Hofmeyrbacb74f2022-08-29 16:24:12 +02001958 f_iu2iuh(tx);
1959
1960 tx := valueof(ts_RANAP_IuReleaseComplete());
1961 f_iuh2iu(tx);
1962
1963 f_sleep(2.0);
1964}
1965
1966testcase TC_ps_rab_assignment_without_pfcp() runs on test_CT {
1967 var ConnHdlr vc_conn;
1968 f_init();
Neels Hofmeyrbacb74f2022-08-29 16:24:12 +02001969 f_sleep(1.0);
1970
1971 vc_conn := f_start_handler_with_pars(refers(f_tc_ps_rab_assignment_without_pfcp), t_pars(7, ps_domain := true));
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001972 vc_conn.done;
Neels Hofmeyr3a9140e2023-06-23 04:50:39 +02001973
1974 f_shutdown_helper();
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001975}
Daniel Willmann19b8d902022-01-05 09:12:34 +01001976
Neels Hofmeyr7d0e6802023-04-20 20:43:55 +02001977/* Default list of counters for a 'cn' entity to test the cnpool feature. */
1978const CounterNameVals counternames_cnpool := {
1979 { "cnpool:subscr:new", 0 },
1980 { "cnpool:subscr:known", 0 },
1981 { "cnpool:subscr:reattach", 0 },
1982 { "cnpool:subscr:attach_lost", 0 },
1983 { "cnpool:subscr:paged", 0 }
1984};
1985private function f_ctrs_cn_init(boolean ps_domain, integer cn_count := 0,
1986 CounterNameVals counternames := counternames_cnpool) runs on test_CT {
1987 if (ps_domain) {
1988 g_ctr_cn_node_name := "sgsn";
1989 if (cn_count == 0) {
1990 cn_count := NUM_SGSN;
1991 }
1992 } else {
1993 g_ctr_cn_node_name := "msc";
1994 if (cn_count == 0) {
1995 cn_count := NUM_MSC;
1996 }
1997 }
1998 g_ctr_cn := f_counter_name_vals_get_n(IPA_CTRL, g_ctr_cn_node_name, cn_count, counternames);
1999 log("initial " & g_ctr_cn_node_name & " rate counters: ", g_ctr_cn);
2000}
2001
2002/* f_ctrs_cn_init();
2003 * f_do_thing(on_cn := 0);
2004 * f_do_thing(on_cn := 0);
2005 * f_do_other(on_cn := 1);
2006 * f_ctrs_cn_add(0, "thing", 2);
2007 * f_ctrs_cn_add(1, "other");
2008 * f_ctrs_cn_verify();
2009 */
2010private function f_ctrs_cn_verify() runs on test_CT {
2011 log("verifying", g_ctr_cn_node_name, " rate counters: ", g_ctr_cn);
2012 f_counter_name_vals_expect_n(IPA_CTRL, g_ctr_cn_node_name, g_ctr_cn);
2013}
2014
2015/* convenience: f_ctrs_cn_add() and f_ctrs_cn_verify() in one call.
2016 * f_ctrs_cn_init();
2017 * f_do_thing(on_cn := 0);
2018 * f_do_thing(on_cn := 0);
2019 * f_do_thing(on_cn := 0);
2020 * f_ctrs_cn_expect(0, "thing", 3);
2021 */
2022private function f_ctrs_cn_expect(integer cn_nr, charstring countername, integer val := 1) runs on test_CT {
2023 f_ctrs_cn_add(cn_nr, countername, val);
2024 f_ctrs_cn_verify();
2025}
2026
2027private function f_ctrs_cn_add(integer cn_nr, charstring countername, integer val := 1) runs on test_CT {
2028 f_counter_name_vals_list_add(g_ctr_cn, cn_nr, countername, val);
2029}
2030
2031private function f_perform_compl_l3(octetstring nas, boolean do_clear := true, boolean expect_iu_l3 := true)
2032runs on ConnHdlr {
2033 timer T := 10.0;
2034
2035 /* create an expect on the Iu side for the random NAS portion */
2036 if (g_pars.expect_separate_sccp_cr) {
2037 f_ran_register_sccp_cr_without_payload();
2038 } else {
2039 f_ran_register_exp(nas);
2040 }
2041
2042 /* send Connect via Iuh (creating a RUA connection) */
2043 var RANAP_PDU tx := f_build_initial_ue_with_nas(g_pars, nas);
2044 RUA.send(RUA_Conn_Req:{g_pars.ps_domain, tx});
2045
2046 if (expect_iu_l3) {
2047 /* Expect same message to arrive at CN */
2048 f_bssap_expect(tx);
2049 }
2050}
2051
2052private function f_tc_cnpool_compl_l3(charstring id, TestHdlrParams pars) runs on ConnHdlr {
2053 f_init_handler(pars);
2054 f_perform_compl_l3(g_pars.nas_pdu);
2055}
2056
2057private function f_TC_cnpool_compl_l3(boolean ps_domain, octetstring nas_pdu, integer cn_nr,
2058 template (omit) charstring inc_countername := omit) runs on test_CT {
2059 var ConnHdlr vc_conn;
2060 var template (value) TestHdlrParams pars := t_pars(0, ps_domain := ps_domain, cn_nr := cn_nr);
2061 pars.nas_pdu := nas_pdu;
2062 log("XXX ", pars);
2063 vc_conn := f_start_handler_with_pars(refers(f_tc_cnpool_compl_l3), pars);
2064 vc_conn.done;
2065
2066 if (not istemplatekind(inc_countername, "omit")) {
2067 f_ctrs_cn_expect(cn_nr, valueof(inc_countername));
2068 }
2069}
2070
2071function f_TC_cnpool_compl_l3_list(boolean ps_domain, ro_octetstring compl3, Osmocom_Types.ro_integer cn_nrs,
2072 charstring inc_countername) runs on test_CT {
2073 var integer n := lengthof(compl3);
2074 if (n < lengthof(cn_nrs)) {
2075 n := lengthof(cn_nrs);
2076 }
2077 for (var integer i := 0; i < n; i := i + 1) {
2078 var integer cn_nr := cn_nrs[i mod lengthof(cn_nrs)];
2079 f_TC_cnpool_compl_l3(ps_domain, compl3[i mod lengthof(compl3)], cn_nr, inc_countername);
2080 }
2081}
2082
2083type enumerated Compl3Type {
2084 /* CS */
2085 LU,
2086 CMSERV,
2087 PAGRESP,
2088 IMSIDETACH,
2089
2090 /* PS */
2091 ATTACHREQ,
2092 RAUREQ,
2093 DETREQ
2094};
2095
2096private function f_gen_one_compl_l3(Compl3Type compl3type, template (value) MobileIdentityLV mi,
2097 integer ps_nri := -1
2098 ) return octetstring
2099{
2100 /* CS */
2101 if (compl3type == LU) {
2102 return enc_PDU_ML3_MS_NW(valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(mi), '00F110'O)));
2103 }
2104 if (compl3type == CMSERV) {
2105 return enc_PDU_ML3_MS_NW(valueof(ts_CM_SERV_REQ(CM_TYPE_MO_CALL, valueof(mi))));
2106 }
2107 if (compl3type == PAGRESP) {
2108 return enc_PDU_ML3_MS_NW(valueof(ts_PAG_RESP(valueof(mi))));
2109 }
2110 if (compl3type == IMSIDETACH) {
2111 return enc_PDU_ML3_MS_NW(valueof(ts_ML3_MO_MM_IMSI_DET_Ind(valueof(mi))));
2112 }
2113
2114 /* PS */
2115 var template (omit) NetworkResourceIdentifierContainerTLV nri := omit;
2116 if (ps_nri >= 0) {
2117 nri := valueof(ts_GMM_NRI(ps_nri));
2118 }
2119
2120 if (compl3type == ATTACHREQ) {
2121 return enc_PDU_L3_MS_SGSN(valueof(ts_GMM_ATTACH_REQ(valueof(mi), f_RAI('001'H, '01'H, '2a2a'O, '17'O),
2122 nri := nri)));
2123 }
2124 if (compl3type == RAUREQ) {
2125 return enc_PDU_L3_MS_SGSN(valueof(ts_GMM_RAU_REQ(valueof(mi), GPRS_UPD_T_PERIODIC,
2126 f_RAI('001'H, '01'H, '2a2a'O, '17'O),
2127 nri := nri)));
2128 }
2129 if (compl3type == DETREQ) {
2130 return enc_PDU_L3_MS_SGSN(valueof(ts_GMM_DET_REQ_MO_mi(c_GMM_DTT_MO_GPRS, power_off := false,
2131 p_tmsi := valueof(ts_MI_TLV(mi.mobileIdentityV)))));
2132 }
2133
2134 setverdict(fail, "unknown complete layer 3 type");
2135 mtc.stop;
2136}
2137
2138type record of Compl3Type ro_Compl3Type;
2139type record of MobileIdentityLV ro_MobileIdentityLV;
2140type record of octetstring ro_octetstring;
2141
2142/* Generate a list of n Complete Layer 3 NAS PDUs,
2143 * rotating through the message kinds listed in 'types' and the mobile identities in mis.
2144 */
2145private function f_gen_compl_l3(ro_Compl3Type types, ro_MobileIdentityLV mis, integer n) return ro_octetstring
2146{
2147 var ro_octetstring res := {};
2148 for (var integer i := 0; i < n; i := i + 1) {
2149 var integer ti := i mod lengthof(types);
2150 var integer mi := i mod lengthof(mis);
2151 res[i] := f_gen_one_compl_l3(types[ti], mis[mi]);
2152 }
2153 return res;
2154}
2155
2156private function f_gen_mi_imsi(integer n) return MobileIdentityLV
2157{
2158 return valueof(ts_MI_IMSI_LV(f_gen_imsi(n)));
2159}
2160
2161private function f_gen_mi_imsis(integer n) return ro_MobileIdentityLV
2162{
2163 var ro_MobileIdentityLV mis := {};
2164 for (var integer i := 0; i < n; i := i + 1) {
2165 mis[i] := f_gen_mi_imsi(n);
2166 }
2167 return mis;
2168}
2169
2170function f_vty_set_roundrobin_next(TELNETasp_PT VTY, boolean ps_domain, integer cn_nr)
2171{
2172 var charstring msc_sgsn;
2173 if (ps_domain) {
2174 msc_sgsn := "sgsn";
2175 } else {
2176 msc_sgsn := "msc";
2177 }
2178 f_vty_transceive(VTY, "cnpool roundrobin next " & msc_sgsn & " " & int2str(cn_nr));
2179}
2180
2181private function f_gen_compl3_by_domain(boolean ps_domain, integer n, template (omit) ro_MobileIdentityLV mis := omit) return ro_octetstring{
2182 var ro_Compl3Type types;
2183 if (ps_domain) {
2184 types := { ATTACHREQ, RAUREQ, DETREQ };
2185 } else {
2186 types := { LU, CMSERV, PAGRESP, IMSIDETACH };
2187 }
2188 if (istemplatekind(mis, "omit")) {
2189 mis := f_gen_mi_imsis(n);
2190 }
2191 return f_gen_compl_l3(types, valueof(mis), n);
2192}
2193
2194/* Various Complete Layer 3 by IMSI all end up with the first MSC, because the other MSCs are not connected. */
2195testcase TC_mscpool_L3Compl_on_1_cnlink() runs on test_CT {
2196 f_TC_cnpool_L3Compl_on_1_cnlink(ps_domain := false);
2197}
2198testcase TC_sgsnpool_L3Compl_on_1_cnlink() runs on test_CT {
2199 f_TC_cnpool_L3Compl_on_1_cnlink(ps_domain := true);
2200}
2201function f_TC_cnpool_L3Compl_on_1_cnlink(boolean ps_domain) runs on test_CT {
2202
2203 f_init();
2204
2205 f_ctrs_cn_init(ps_domain := ps_domain);
2206
2207 var ro_octetstring compl3 := f_gen_compl3_by_domain(ps_domain, 4);
2208 f_TC_cnpool_compl_l3_list(ps_domain, compl3, {0, 0, 0, 0}, "cnpool:subscr:new");
2209
2210 f_shutdown_helper();
2211}
2212
2213/* Three Layer 3 Complete by IMSI are round-robin'ed across two connected MSCs */
2214testcase TC_mscpool_L3Complete_by_imsi_round_robin() runs on test_CT {
2215 f_TC_cnpool_L3Complete_by_imsi_round_robin(ps_domain := false);
2216}
2217testcase TC_sgsnpool_L3Complete_no_nri_round_robin() runs on test_CT {
2218 f_TC_cnpool_L3Complete_by_imsi_round_robin(ps_domain := true);
2219}
2220function f_TC_cnpool_L3Complete_by_imsi_round_robin(boolean ps_domain) runs on test_CT {
2221
2222 f_init(nr_msc := 2, nr_sgsn := 2);
2223 f_sleep(1.0);
2224
2225 /* Control which MSC gets chosen next by the round-robin, otherwise
2226 * would be randomly affected by which other tests ran before this. */
2227 f_vty_set_roundrobin_next(HNBGWVTY, ps_domain, 0);
2228
2229 f_ctrs_cn_init(ps_domain := ps_domain);
2230
2231 var ro_octetstring compl3 := f_gen_compl3_by_domain(ps_domain, 3);
2232
2233 f_TC_cnpool_compl_l3_list(ps_domain, compl3,
2234 /* Third Complete Layer 3 wraps back to msc 0 */
2235 cn_nrs := {0, 1, 0},
2236 inc_countername := "cnpool:subscr:new");
2237
2238 f_shutdown_helper();
2239}
2240
2241/* Three LU by TMSI are round-robin'ed across two connected MSCs, because they contain a NULL-NRI (0, 1)
2242 * (configured in osmo-hnbgw.cfg). */
2243testcase TC_mscpool_LU_by_tmsi_null_nri_0_round_robin() runs on test_CT {
2244 f_TC_cnpool_LU_by_tmsi_null_nri_N_round_robin(ps_domain := false, nri_val := 0);
2245}
2246/* For NRI == 1, one of the MSC also has the NULL-NRI as part of its owned NRIs, but the NULL-NRI setting is stronger
2247 * than that. */
2248testcase TC_mscpool_LU_by_tmsi_null_nri_1_round_robin() runs on test_CT {
2249 f_TC_cnpool_LU_by_tmsi_null_nri_N_round_robin(ps_domain := false, nri_val := 1);
2250}
2251function f_TC_cnpool_LU_by_tmsi_null_nri_N_round_robin(boolean ps_domain, integer nri_val) runs on test_CT {
2252
2253 f_init(nr_msc := 2, nr_sgsn := 2);
2254 f_sleep(1.0);
2255
2256 /* Control which MSC gets chosen next by the round-robin, otherwise
2257 * would be randomly affected by which other tests ran before this. */
2258 f_vty_set_roundrobin_next(HNBGWVTY, ps_domain, 0);
2259
2260 f_ctrs_cn_init(ps_domain := ps_domain);
2261
2262 var ro_MobileIdentityLV mis := { valueof(ts_MI_TMSI_NRI_LV(nri_val)) };
2263 var ro_octetstring compl3;
2264 if (ps_domain) {
2265 compl3 := {
2266 f_gen_one_compl_l3(ATTACHREQ, mis[0], nri_val)
2267 };
2268 } else {
2269 compl3 := f_gen_compl_l3({LU}, mis, 1);
2270 }
2271
2272 f_TC_cnpool_compl_l3_list(ps_domain, compl3,
2273 /* The third Complete Layer 3 wraps back to msc 0 */
2274 {0, 1, 0},
2275 "cnpool:subscr:reattach");
2276 f_shutdown_helper();
2277}
2278
2279/* Three Layer 3 Complete by TMSI are round-robin'ed across two connected MSCs, because they contain an NRI not
2280 * assigned to any MSC (configured in osmo-hnbgw.cfg). */
2281testcase TC_mscpool_L3Complete_by_tmsi_unassigned_nri_round_robin() runs on test_CT {
2282 f_TC_cnpool_L3Complete_by_tmsi_unassigned_nri_round_robin(ps_domain := false);
2283}
2284function f_TC_cnpool_L3Complete_by_tmsi_unassigned_nri_round_robin(boolean ps_domain) runs on test_CT {
2285
2286 f_init(nr_msc := 2, nr_sgsn := 2);
2287 f_sleep(1.0);
2288
2289 /* Control which MSC gets chosen next by the round-robin, otherwise
2290 * would be randomly affected by which other tests ran before this. */
2291 f_vty_set_roundrobin_next(HNBGWVTY, ps_domain, 0);
2292
2293 f_ctrs_cn_init(ps_domain := ps_domain);
2294
2295 /* 3 NRIs that are not assigned to any MSC */
2296 var ro_MobileIdentityLV mis := {
2297 valueof(ts_MI_TMSI_NRI_LV(1000)),
2298 valueof(ts_MI_TMSI_NRI_LV(768)),
2299 valueof(ts_MI_TMSI_NRI_LV(819))
2300 };
2301
2302 var ro_octetstring compl3 := f_gen_compl3_by_domain(ps_domain, 3, mis);
2303 f_TC_cnpool_compl_l3_list(ps_domain, compl3, { 0, 1, 0 }, "cnpool:subscr:new");
2304
2305 f_shutdown_helper();
2306}
2307
2308/* Three Layer 3 Complete by TMSI are round-robin'ed across two connected MSCs, because they contain an NRI
2309 * assigned to a CN link that is currently not connected (configured in osmo-hnbgw.cfg). */
2310testcase TC_mscpool_L3Complete_by_tmsi_valid_nri_msc_not_connected_round_robin() runs on test_CT {
2311 f_TC_cnpool_L3Complete_by_tmsi_valid_nri_msc_not_connected_round_robin(ps_domain := false);
2312}
2313function f_TC_cnpool_L3Complete_by_tmsi_valid_nri_msc_not_connected_round_robin(boolean ps_domain) runs on test_CT {
2314
2315 f_init(nr_msc := 2, nr_sgsn := 2);
2316 f_sleep(1.0);
2317
2318 /* Control which MSC gets chosen next by the round-robin, otherwise
2319 * would be randomly affected by which other tests ran before this. */
2320 f_vty_set_roundrobin_next(HNBGWVTY, ps_domain, 0);
2321
2322 f_ctrs_cn_init(ps_domain := ps_domain);
2323
2324 /* 3 NRIs that are assigned to an unconnected MSC */
2325 var ro_MobileIdentityLV mis := {
2326 valueof(ts_MI_TMSI_NRI_LV(512)),
2327 valueof(ts_MI_TMSI_NRI_LV(767)),
2328 valueof(ts_MI_TMSI_NRI_LV(750))
2329 };
2330
2331 var ro_octetstring compl3 := f_gen_compl3_by_domain(ps_domain, 3, mis);
2332
2333 f_TC_cnpool_compl_l3(ps_domain, compl3[0], cn_nr := 0);
2334 f_ctrs_cn_add(2, "cnpool:subscr:attach_lost");
2335 f_ctrs_cn_add(0, "cnpool:subscr:new");
2336 f_ctrs_cn_verify();
2337
2338 f_TC_cnpool_compl_l3(ps_domain, compl3[1], cn_nr := 1);
2339 f_ctrs_cn_add(2, "cnpool:subscr:attach_lost");
2340 f_ctrs_cn_add(1, "cnpool:subscr:new");
2341 f_ctrs_cn_verify();
2342
2343 f_TC_cnpool_compl_l3(ps_domain, compl3[2], cn_nr := 0);
2344 f_ctrs_cn_add(2, "cnpool:subscr:attach_lost");
2345 f_ctrs_cn_add(0, "cnpool:subscr:new");
2346 f_ctrs_cn_verify();
2347
2348 f_shutdown_helper();
2349}
2350
2351/* Three Layer 3 Complete by TMSI with valid NRI for the second MSC are all directed to the second MSC (configured in
2352 * osmo-hnbgw.cfg). */
2353testcase TC_mscpool_L3Complete_by_tmsi_valid_nri_1() runs on test_CT {
2354 f_TC_cnpool_L3Complete_valid_nri_1(ps_domain := false);
2355}
2356testcase TC_sgsnpool_L3Complete_valid_nri_1() runs on test_CT {
2357 f_TC_cnpool_L3Complete_valid_nri_1(ps_domain := true);
2358}
2359function f_TC_cnpool_L3Complete_valid_nri_1(boolean ps_domain) runs on test_CT {
2360
2361 f_init(nr_msc := 2, nr_sgsn := 2);
2362 f_sleep(1.0);
2363
2364 /* All TMSIs in this test point at the second MSC, set the round robin to point at the first MSC to make sure
2365 * this is not using round-robin. */
2366 f_vty_set_roundrobin_next(HNBGWVTY, ps_domain, 0);
2367
2368 f_ctrs_cn_init(ps_domain := ps_domain);
2369
2370 var ro_octetstring compl3;
2371
2372 /* 3 NRIs of the second MSC's range (256-511) */
2373 var ro_MobileIdentityLV mis := {
2374 valueof(ts_MI_TMSI_NRI_LV(256)),
2375 valueof(ts_MI_TMSI_NRI_LV(260)),
2376 valueof(ts_MI_TMSI_NRI_LV(511))
2377 };
2378 if (ps_domain) {
2379 compl3 := {
2380 f_gen_one_compl_l3(RAUREQ, mis[0], 256),
2381 f_gen_one_compl_l3(RAUREQ, mis[1], 260),
2382 f_gen_one_compl_l3(RAUREQ, mis[2], 511)
2383 };
2384 } else {
2385 compl3 := f_gen_compl3_by_domain(ps_domain, 3, mis);
2386 }
2387
2388 f_TC_cnpool_compl_l3_list(ps_domain, compl3, {1, 1, 1}, "cnpool:subscr:known");
2389
2390 f_shutdown_helper();
2391}
2392
2393/* Layer 3 Complete by TMSI with valid NRI for the third MSC are directed to the third MSC (configured in osmo-hnbgw.cfg),
2394 * while a round-robin remains unaffected by that. */
2395testcase TC_mscpool_L3Complete_by_tmsi_valid_nri_2() runs on test_CT {
2396 f_TC_cnpool_L3Complete_valid_nri_2(ps_domain := false);
2397}
2398testcase TC_sgsnpool_L3Complete_valid_nri_2() runs on test_CT {
2399 f_TC_cnpool_L3Complete_valid_nri_2(ps_domain := true);
2400}
2401function f_TC_cnpool_L3Complete_valid_nri_2(boolean ps_domain) runs on test_CT {
2402
2403 f_init(nr_msc := 3, nr_sgsn := 3);
2404 f_sleep(1.0);
2405
2406 /* All TMSIs in this test point at the third MSC, set the round robin to point at the second MSC to make sure
2407 * this is not using round-robin. */
2408 f_vty_set_roundrobin_next(HNBGWVTY, ps_domain, 1);
2409
2410 f_ctrs_cn_init(ps_domain := ps_domain);
2411
2412 var ro_octetstring compl3;
2413
2414 /* 2 NRIs of the third MSC's range (512-767) */
2415 var ro_MobileIdentityLV mis := {
2416 valueof(ts_MI_TMSI_NRI_LV(512)),
2417 valueof(ts_MI_TMSI_NRI_LV(678))
2418 };
2419 if (ps_domain) {
2420 compl3 := {
2421 f_gen_one_compl_l3(ATTACHREQ, mis[0], 512),
2422 f_gen_one_compl_l3(ATTACHREQ, mis[1], 678)
2423 };
2424 } else {
2425 compl3 := f_gen_compl3_by_domain(ps_domain, 2, mis);
2426 }
2427
2428 f_TC_cnpool_compl_l3_list(ps_domain, compl3, {2, 2}, "cnpool:subscr:known");
2429
2430 /* The above forwardings to third MSC have not affected the round robin, which still points at the second MSC */
2431 f_TC_cnpool_compl_l3_list(ps_domain, f_gen_compl3_by_domain(ps_domain, 1), {1}, "cnpool:subscr:new");
2432
2433 f_shutdown_helper();
2434}
2435
2436/* LU with a TMSI but indicating a different PLMN in its previous LAI: ignore the NRI. */
2437testcase TC_mscpool_LU_by_tmsi_from_other_PLMN() runs on test_CT {
2438 f_TC_cnpool_nri_from_other_PLMN(ps_domain := false);
2439}
2440testcase TC_sgsnpool_nri_from_other_PLMN() runs on test_CT {
2441 f_TC_cnpool_nri_from_other_PLMN(ps_domain := true);
2442}
2443function f_TC_cnpool_nri_from_other_PLMN(boolean ps_domain) runs on test_CT {
2444
2445 f_init(nr_msc := 3, nr_sgsn := 3);
2446 f_sleep(1.0);
2447
2448 /* The TMSIs in this test points at the second MSC, but since it is from a different PLMN, round-robin is used
2449 * instead, and hits msc 0. */
2450 f_vty_set_roundrobin_next(HNBGWVTY, ps_domain, 0);
2451
2452 f_ctrs_cn_init(ps_domain := ps_domain);
2453
2454 var ro_octetstring compl3;
2455
2456 var ro_MobileIdentityLV mis := {
2457 valueof(ts_MI_TMSI_NRI_LV(260)),
2458 valueof(ts_MI_TMSI_NRI_LV(555))
2459 };
2460 if (ps_domain) {
2461 compl3 := {
2462 /* An NRI of the second MSC's range (256-511), but a PLMN that doesn't match with osmo-hnbgw.cfg */
2463 enc_PDU_L3_MS_SGSN(valueof(ts_GMM_ATTACH_REQ(mis[0], f_RAI('999'H, '99'H, '2a2a'O,
2464 '17'O),
2465 nri := ts_GMM_NRI(260)
2466 ))),
2467 /* An NRI of the third MSC's range (512-767) and a matching PLMN gets directed by NRI. */
2468 f_gen_one_compl_l3(ATTACHREQ, mis[1], 555)
2469 }
2470 } else {
2471 compl3 := {
2472 /* An NRI of the second MSC's range (256-511), but a PLMN that doesn't match with osmo-hnbgw.cfg */
2473 enc_PDU_ML3_MS_NW(valueof(ts_LU_REQ(LU_Type_IMSI_Attach, mis[0], '99F999'O))),
2474 /* An NRI of the third MSC's range (512-767) and a matching PLMN gets directed by NRI. */
2475 enc_PDU_ML3_MS_NW(valueof(ts_LU_REQ(LU_Type_IMSI_Attach, mis[1], '00F110'O)))
2476 };
2477 }
2478
2479 /* Foreign NRI: roundrobin */
2480 f_TC_cnpool_compl_l3(ps_domain, compl3[0], cn_nr := 0, inc_countername := "cnpool:subscr:new");
2481
2482 /* Local NRI: matching msc */
2483 f_TC_cnpool_compl_l3(ps_domain, compl3[1], cn_nr := 2, inc_countername := "cnpool:subscr:known");
2484
2485 f_shutdown_helper();
2486}
2487
Neels Hofmeyrb1bf16d2023-06-27 02:10:04 +02002488/* Make sure that whichever MSC paged a subscriber will also get the Paging Response. Page by IMSI, which would be
2489 * round-robined to another MSC, to make sure the Paging->Response relation is stronger than the NRI->MSC mapping. */
2490friend function f_tc_mscpool_paging_imsi(charstring id, TestHdlrParams pars) runs on ConnHdlr {
2491 f_init_handler(pars);
2492
2493 var hexstring imsi := '001010000000123'H;
2494 var RANAP_IEs.CN_DomainIndicator domain_ind;
2495 if (pars.ps_domain) {
2496 domain_ind := ps_domain;
2497 } else {
2498 domain_ind := cs_domain;
2499 }
2500 var template (value) RANAP_PDU paging := ts_RANAP_Paging(domain_ind, imsi_hex2oct(imsi));
2501 BSSAP.send(ts_RANAP_UNITDATA_req(pars.sccp_addr_hnbgw, pars.sccp_addr_msc, paging));
2502 /* TODO: Expect RUA ConnectionlessTransfer Paging (on all HNB).
2503 * We could verify the Paging sent from osmo-hnbgw to RUA with some effort,
2504 * but, this test does not care whether the Paging was forwarded to RUA or not, only that osmo-hnbgw *received*
2505 * the Paging. In the CN pool decisions, osmo-hnbgw should match up Paging Response to an earlier Paging.
2506 */
2507
2508 f_sleep(1.0);
2509
2510 /* Despite the round robin pointing at the second MSC ('roundrobin next msc 1'), the earlier Paging for the same IMSI
2511 * causes this Paging Response to go to the first MSC ('msc 0'). */
2512 f_perform_compl_l3(f_gen_one_compl_l3(PAGRESP, ts_MI_IMSI_LV(imsi)));
2513 f_sleep(1.0);
2514}
2515
2516testcase TC_mscpool_paging_imsi() runs on test_CT {
2517 f_init(nr_msc := 3);
2518 f_sleep(1.0);
2519
2520 var boolean ps_domain := false;
2521
2522 /* Testing a Paging on the first MSC to get a Paging Response back to the first MSC. Set round robin to the
2523 * second MSC to make sure we're getting the Paging logic, not a coincidental round robin match. */
2524 f_vty_set_roundrobin_next(HNBGWVTY, ps_domain, 0);
2525
2526 f_ctrs_cn_init(ps_domain := ps_domain);
2527
2528 var ConnHdlr vc_conn1;
2529 var template (value) TestHdlrParams pars1 := t_pars(0, ps_domain := ps_domain, cn_nr := 0);
2530 pars1.sccp_addr_hnbgw := g_cn[valueof(pars1.cn_idx)].sccp_addr_peer;
2531 pars1.sccp_addr_msc := g_cn[valueof(pars1.cn_idx)].sccp_addr_own;
2532 vc_conn1 := f_start_handler_with_pars(refers(f_tc_mscpool_paging_imsi), pars1);
2533 vc_conn1.done;
2534 f_ctrs_cn_expect(0, "cnpool:subscr:paged");
2535 f_shutdown_helper();
2536}
2537
2538/* Make sure that whichever MSC paged a subscriber will also get the Paging Response. Page by TMSI with an NRI value
2539 * that matches a different MSC, to make sure the Paging->Response relation is stronger than the NRI->MSC mapping. */
2540friend function f_tc_mscpool_paging_tmsi(charstring id, TestHdlrParams pars) runs on ConnHdlr {
2541 f_init_handler(pars);
2542
2543 var hexstring imsi := '001010000000124'H;
2544 var integer nri_v := 300; /* <-- second MSC's NRI */
2545 var octetstring tmsi := f_gen_tmsi(suffix := 0, nri_v := nri_v);
2546
2547 var RANAP_IEs.CN_DomainIndicator domain_ind;
2548 if (pars.ps_domain) {
2549 domain_ind := ps_domain;
2550 } else {
2551 domain_ind := cs_domain;
2552 }
2553 var template (value) RANAP_PDU paging := ts_RANAP_Paging_temp_id(domain_ind, imsi_hex2oct(imsi),
2554 ts_RANAP_TemporaryUE_ID_TMSI(tmsi));
2555 BSSAP.send(ts_RANAP_UNITDATA_req(pars.sccp_addr_hnbgw, pars.sccp_addr_msc, paging));
2556 /* TODO: Expect RUA ConnectionlessTransfer Paging (on all HNB).
2557 * We could verify the Paging sent from osmo-hnbgw to RUA with some effort,
2558 * but, this test does not care whether the Paging was forwarded to RUA or not, only that osmo-hnbgw *received*
2559 * the Paging. In the CN pool decisions, osmo-hnbgw should match up Paging Response to an earlier Paging.
2560 */
2561
2562 f_sleep(1.0);
2563
2564 /* Despite the round robin pointing at the third MSC ('roundrobin next msc 2'), the earlier Paging for the same
2565 * TMSI causes this Paging Response to go to the first MSC ('msc 0'). */
2566 f_perform_compl_l3(f_gen_one_compl_l3(PAGRESP, ts_MI_TMSI_NRI_LV(nri_v)));
2567 f_sleep(1.0);
2568}
2569testcase TC_mscpool_paging_tmsi() runs on test_CT {
2570 f_init(nr_msc := 3);
2571 f_sleep(1.0);
2572
2573 var boolean ps_domain := false;
2574
2575 /* Testing a Paging on the first MSC to get a Paging Response back to the first MSC. Set round robin to the
2576 * third MSC to make sure we're getting the Paging logic, not a coincidental round robin match. */
2577 f_vty_set_roundrobin_next(HNBGWVTY, ps_domain, 0);
2578
2579 f_ctrs_cn_init(ps_domain := ps_domain);
2580
2581 var ConnHdlr vc_conn1;
2582 var template (value) TestHdlrParams pars1 := t_pars(0, ps_domain := ps_domain, cn_nr := 0);
2583 pars1.sccp_addr_hnbgw := g_cn[valueof(pars1.cn_idx)].sccp_addr_peer;
2584 pars1.sccp_addr_msc := g_cn[valueof(pars1.cn_idx)].sccp_addr_own;
2585 vc_conn1 := f_start_handler_with_pars(refers(f_tc_mscpool_paging_tmsi), pars1);
2586 vc_conn1.done;
2587 f_ctrs_cn_expect(0, "cnpool:subscr:paged");
2588 f_shutdown_helper();
2589}
2590
Neels Hofmeyr7d0e6802023-04-20 20:43:55 +02002591/* For round-robin, skip a CN link that has 'no allow-attach' set. */
2592testcase TC_mscpool_no_allow_attach_round_robin() runs on test_CT {
2593
2594 f_init(nr_msc := 3);
2595 f_sleep(1.0);
2596
2597 var boolean ps_domain := false;
2598
2599 /* Mark the second MSC as offloading, round-robin should skip this MSC now. */
2600 f_vty_cnlink_allow_attach(HNBGWVTY, ps_domain, {true, false, true});
2601
2602 /* Control which MSC gets chosen next by the round-robin, otherwise
2603 * would be randomly affected by which other tests ran before this. */
2604 f_vty_set_roundrobin_next(HNBGWVTY, ps_domain, 0);
2605
2606 f_ctrs_cn_init(ps_domain := ps_domain);
2607
2608 f_TC_cnpool_compl_l3_list(ps_domain, f_gen_compl3_by_domain(ps_domain, 3),
2609 /* msc 1 is skipped */
2610 {0, 2, 0},
2611 "cnpool:subscr:new");
2612
2613 f_shutdown_helper();
2614}
2615
2616/* An MSC that has 'no allow-attach' set should still serve subscribers that are already attached according to their
2617 * TMSI NRI. */
2618testcase TC_mscpool_no_allow_attach_valid_nri() runs on test_CT {
2619
2620 f_init(nr_msc := 3);
2621 f_sleep(1.0);
2622
2623 var boolean ps_domain := false;
2624
2625 /* Mark the second MSC as offloading, round-robin should skip this MSC now. */
2626 f_vty_cnlink_allow_attach(HNBGWVTY, ps_domain, {true, false, true});
2627
2628 /* Control which MSC gets chosen next by the round-robin, otherwise
2629 * would be randomly affected by which other tests ran before this. */
2630 f_vty_set_roundrobin_next(HNBGWVTY, ps_domain, 0);
2631
2632 f_ctrs_cn_init(ps_domain := ps_domain);
2633
2634 var ro_MobileIdentityLV mis := {
2635 valueof(ts_MI_TMSI_NRI_LV(260)),
2636 valueof(ts_MI_IMSI_LV('001010000000002'H)),
2637 valueof(ts_MI_IMSI_LV('001010000000003'H))
2638 };
2639
2640 var ro_octetstring compl3 := f_gen_compl3_by_domain(ps_domain, 3, mis);
2641
2642 /* Round robin points at msc 0, but the valid NRI directs to msc 1, even though msc 1 has 'no allow-attach'. */
2643 f_TC_cnpool_compl_l3(ps_domain, compl3[0], cn_nr := 1, inc_countername := "cnpool:subscr:known");
2644
2645 /* Normal round robin skips msc 1, because it has 'no allow-attach' */
2646 f_TC_cnpool_compl_l3(ps_domain, compl3[1], cn_nr := 0, inc_countername := "cnpool:subscr:new");
2647 f_TC_cnpool_compl_l3(ps_domain, compl3[2], cn_nr := 2, inc_countername := "cnpool:subscr:new");
2648
2649 f_shutdown_helper();
2650}
2651
2652/* When a peer point-code gets an SCCP N-PCSTATE saying it is unreachable, immediately mark the CN link as unusable. */
2653testcase TC_mscpool_sccp_n_pcstate_detaches_cnlink() runs on test_CT {
2654 f_TC_cnpool_sccp_n_pcstate_detaches_cnlink(ps_domain := false);
2655}
2656testcase TC_sgsnpool_sccp_n_pcstate_detaches_cnlink() runs on test_CT {
2657 f_TC_cnpool_sccp_n_pcstate_detaches_cnlink(ps_domain := true);
2658}
2659function f_TC_cnpool_sccp_n_pcstate_detaches_cnlink(boolean ps_domain) runs on test_CT
2660{
2661
2662 f_init(nr_msc := 2, nr_sgsn := 2);
2663 f_sleep(1.0);
2664
2665 /* Control which MSC gets chosen next by the round-robin, otherwise
2666 * would be randomly affected by which other tests ran before this. */
2667 f_vty_set_roundrobin_next(HNBGWVTY, ps_domain, 0);
2668
2669 f_ctrs_cn_init(ps_domain := ps_domain);
2670
2671 var ro_octetstring compl3 := f_gen_compl3_by_domain(ps_domain, 3);
2672
2673 f_TC_cnpool_compl_l3(ps_domain, compl3[0], cn_nr := 0, inc_countername := "cnpool:subscr:new");
2674 f_TC_cnpool_compl_l3(ps_domain, compl3[1], cn_nr := 1, inc_countername := "cnpool:subscr:new");
2675
2676 f_logp(HNBGWVTY, "disconnecting msc0");
2677 f_cn_idx_disconnect(f_cn_idx(ps_domain, 0));
2678
2679 /* Now round-robin would wrap to the first MSC, but since the first MSC is disconnected, it wraps around to the
2680 * second. */
2681 f_TC_cnpool_compl_l3(ps_domain, compl3[2], cn_nr := 1, inc_countername := "cnpool:subscr:new");
2682
2683 f_shutdown_helper();
2684}
2685
2686/* When a CN link point-code gets an SCCP N-PCSTATE saying it is now reachable, immediately trigger RESET and bring up the
2687 * MSC. */
2688testcase TC_mscpool_sccp_n_pcstate_attaches_cnlink() runs on test_CT {
2689 f_TC_cnpool_sccp_n_pcstate_attaches_cnlink(ps_domain := false);
2690}
2691testcase TC_sgsnpool_sccp_n_pcstate_attaches_cnlink() runs on test_CT {
2692 f_TC_cnpool_sccp_n_pcstate_attaches_cnlink(ps_domain := true);
2693}
2694function f_TC_cnpool_sccp_n_pcstate_attaches_cnlink(boolean ps_domain) runs on test_CT
2695{
2696 f_init(nr_msc := 1, nr_sgsn := 1);
2697 f_sleep(1.0);
2698
2699 /* Control which MSC gets chosen next by the round-robin, otherwise
2700 * would be randomly affected by which other tests ran before this. */
2701 f_vty_set_roundrobin_next(HNBGWVTY, ps_domain, 0);
2702
2703 var ro_octetstring compl3 := f_gen_compl3_by_domain(ps_domain, 3);
2704
2705 f_ctrs_cn_init(ps_domain := ps_domain);
2706
2707 /* There is only one MSC, round robin stays on msc0 */
2708 f_TC_cnpool_compl_l3(ps_domain := ps_domain, nas_pdu := compl3[0], cn_nr := 0, inc_countername := "cnpool:subscr:new");
2709 f_TC_cnpool_compl_l3(ps_domain := ps_domain, nas_pdu := compl3[1], cn_nr := 0, inc_countername := "cnpool:subscr:new");
2710
2711 f_logp(HNBGWVTY, "connecting cnlink 1");
2712 f_cn_nr_init(ps_domain, 1);
2713 f_vty_cnlink_allow_attach(HNBGWVTY, ps_domain, { true, true });
2714 f_sleep(1.0);
2715
2716 /* This time round-robin wraps to the second MSC, because it is now online. */
2717 f_TC_cnpool_compl_l3(ps_domain := ps_domain, nas_pdu := compl3[2], cn_nr := 1, inc_countername := "cnpool:subscr:new");
2718
2719 f_shutdown_helper();
2720}
2721
Neels Hofmeyrd019cc02023-06-02 16:31:23 +02002722private function f_vty_add_sccp_addr(TELNETasp_PT pt, charstring addr_name, charstring pc, integer cs7_nr := 0)
2723{
2724 f_vty_enter_config(pt);
2725 f_vty_transceive(pt, "cs7 instance 0");
2726 f_vty_transceive(pt, "sccp-address " & addr_name);
2727 f_vty_transceive(pt, "point-code " & pc);
2728 f_vty_transceive(pt, "end");
2729}
2730
2731private function f_vty_set_cnlink_addr(TELNETasp_PT pt, charstring cnlink_and_nr, charstring addr_name)
2732{
2733 f_vty_enter_config(pt);
2734 f_vty_transceive(pt, cnlink_and_nr);
2735 f_vty_transceive(pt, "remote-addr " & addr_name);
2736 f_vty_transceive(pt, "end");
2737}
2738
2739private function f_vty_apply_sccp(TELNETasp_PT pt)
2740{
2741 f_vty_enter_config(pt);
2742 f_vty_transceive(pt, "apply sccp");
2743 f_vty_transceive(pt, "end");
2744}
2745
2746template (present) RUA_Disc_Req tr_RUA_Disc_Req := {
2747 ranap := ?,
2748 cause := ?
2749};
2750
2751/* With a cnlink up, change the SCCP address, and verify that it restarts upon vty 'apply sccp' */
2752private function f_tc_apply_sccp(charstring id, TestHdlrParams pars) runs on ConnHdlr
2753{
2754 f_init_handler(pars);
2755 f_perform_compl_l3(f_gen_compl3_by_domain(pars.ps_domain, 1)[0]);
2756
2757 f_sleep(1.0);
2758 f_logp(HNBGWVTY, "Changing SCCP address, don't apply yet");
2759
2760 f_vty_add_sccp_addr(HNBGWVTY, "msc-foo", "0.42.4");
2761 f_vty_set_cnlink_addr(HNBGWVTY, "msc 0", "msc-foo");
2762
2763 /* No effect yet, link still open both ways */
2764 f_sleep(1.0);
2765 f_iuh2iu(ts_RANAP_DirectTransfer(f_rnd_octstring(10)));
2766 f_iu2iuh(ts_RANAP_DirectTransfer(f_rnd_octstring(10)));
2767
2768 f_logp(HNBGWVTY, "Apply SCCP address changes");
2769 f_vty_apply_sccp(HNBGWVTY);
2770
2771 /* We modified the SCCP configuration, expect disconnect of UE that was active on the aborted link. */
2772 RUA.receive(RUA_Disc_Ind:?);
2773 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_IND);
2774
2775 /* Would be nice to test reconnection on the other point-code, too. That would require another cnlink in
2776 * osmo-stp.cfg and module parameters... */
2777
2778 f_sleep(1.0);
2779}
2780testcase TC_apply_sccp() runs on test_CT
2781{
2782 f_init();
2783 f_sleep(1.0);
2784
2785 var ConnHdlr vc_conn;
2786 var template (value) TestHdlrParams pars := t_pars(0);
2787 vc_conn := f_start_handler_with_pars(refers(f_tc_apply_sccp), pars);
2788 vc_conn.done;
2789
2790 f_shutdown_helper();
2791}
2792
Neels Hofmeyrc3c01d32023-11-07 02:19:00 +01002793/* In the field, we encountered a "normal" RAB Assignment that concludes successfully, followed by another RAB
2794 * Assignment that has different SDU subflow parameters, and does not contain RTP information. At the time of writing,
2795 * it seems that the second RAB Assignment causes a crash. Play through this scenario. */
2796friend function f_tc_second_rab_assignment(charstring id, TestHdlrParams pars) runs on ConnHdlr {
2797 var MgcpCommand mgcp_cmd;
2798 var RANAP_PDU tx;
2799 timer T := 5.0;
2800
2801 f_init_handler(pars);
2802 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
2803
2804 tx := f_build_initial_ue(g_pars);
2805 f_iuh2iu_connect(tx);
2806
2807 f_create_rab(pars.mgcp_pars);
2808
2809 /* Now send a second RAB Assignment with different subflows and omitting transportLayerInformation. (Assuming
2810 * the first RAB Assignment's transportLayerInformation remains in use unchanged.) */
2811 var template RAB_SetupOrModifyList rab_sml;
2812 rab_sml := ts_RAB_SML2(t_RAB_id(23),
2813 ts_RabParams,
2814 user_plane_info := omit,
2815 transport_layer_info := omit);
2816 tx := valueof(ts_RANAP_RabAssReq(rab_sml));
2817 BSSAP.send(tx);
2818 T.start;
2819
2820 /* Expect this secondary RAB Assignment to go through unchanged. */
2821 f_rua_expect(tx);
2822
2823 /* I'm guessing that the RAB Assignment Response also omits transportLayerInformation, so far not known because
2824 * osmo-hnbgw crashed before we could receive the response. */
2825
2826 /* Send back RAB Assignment Response via Iuh */
2827 var template RAB_SetupOrModifiedList rab_smdl;
2828 rab_smdl := ts_RAB_SMdL_no_tla(t_RAB_id(23));
2829 tx := valueof(ts_RANAP_RabAssResp(rab_smdl));
2830 RUA.send(tx);
2831 f_bssap_expect(tx);
2832
2833 /* Send Iu Release */
Harald Welte0d4a8432024-04-04 01:12:11 +02002834 tx := valueof(ts_RANAP_IuReleaseCommand(pars.rab_rel_cause));
Neels Hofmeyrc3c01d32023-11-07 02:19:00 +01002835 f_iu2iuh(tx);
2836
2837 T.start;
2838 alt {
2839 [] as_mgcp_dlcx(pars) {}
2840 [] T.timeout {
2841 setverdict(fail, "Timeout waiting for DLCX");
2842 }
2843 }
2844
2845 tx := valueof(ts_RANAP_IuReleaseComplete());
2846 f_iuh2iu(tx);
2847}
2848
2849testcase TC_second_rab_assignment() runs on test_CT {
2850 var ConnHdlr vc_conn;
2851 g_num_hnbs := 1;
2852 f_init();
2853
2854 vc_conn := f_start_handler_with_pars(refers(f_tc_second_rab_assignment), t_pars(3));
2855 vc_conn.done;
2856
2857 f_shutdown_helper();
2858}
2859
Daniel Willmann19b8d902022-01-05 09:12:34 +01002860control {
2861 execute(TC_hnb_register());
Daniel Willmannc79679a2022-08-23 17:48:39 +02002862 execute(TC_hnb_register_duplicate());
Pau Espin Pedrolacf4f222022-09-27 14:33:40 +02002863 execute(TC_hnb_register_duplicate_reuse_sctp_assoc());
Harald Welteaf3e2162024-03-27 21:54:20 +01002864 execute(TC_ue_register());
Harald Weltef60044d2024-04-04 00:54:34 +02002865 execute(TC_ue_register_tmsi_lai());
Harald Welteaf3e2162024-03-27 21:54:20 +01002866 execute(TC_ue_register_before_hnb_register());
Daniel Willmann19b8d902022-01-05 09:12:34 +01002867 execute(TC_ranap_cs_initial_ue());
2868 execute(TC_ranap_ps_initial_ue());
Neels Hofmeyrf0b9ed12022-06-07 17:46:32 +02002869 execute(TC_ranap_cs_initial_ue_empty_cr());
2870 execute(TC_ranap_ps_initial_ue_empty_cr());
Daniel Willmann19b8d902022-01-05 09:12:34 +01002871 execute(TC_ranap_cs_bidir());
2872 execute(TC_ranap_ps_bidir());
2873 execute(TC_rab_assignment());
2874 execute(TC_rab_release());
Harald Weltef95ab2d2024-04-04 01:32:20 +02002875 execute(TC_rab_release_abnormal());
Daniel Willmann3e15b7b2022-02-21 17:07:02 +01002876 execute(TC_rab_assign_fail());
Daniel Willmann37c877f2022-02-22 16:47:06 +01002877 execute(TC_rab_assign_mgcp_to());
Pau Espin Pedrolaf746502023-11-29 16:18:28 +01002878 execute(TC_rab_assign_mgw_iuup_addr_chg());
Daniel Willmann19b8d902022-01-05 09:12:34 +01002879 execute(TC_ranap_cs_mo_disconnect());
2880 execute(TC_ranap_ps_mo_disconnect());
Neels Hofmeyrbacb74f2022-08-29 16:24:12 +02002881
2882 if (mp_enable_pfcp_tests) {
2883 execute(TC_ps_rab_assignment_with_pfcp());
2884 } else {
2885 execute(TC_ps_rab_assignment_without_pfcp());
2886 }
Pau Espin Pedrolf0b9fa02022-09-12 13:31:07 +02002887
Neels Hofmeyr7d0e6802023-04-20 20:43:55 +02002888 execute( TC_mscpool_L3Compl_on_1_cnlink() );
2889 execute( TC_mscpool_L3Complete_by_imsi_round_robin() );
2890 execute( TC_mscpool_LU_by_tmsi_null_nri_0_round_robin() );
2891 execute( TC_mscpool_LU_by_tmsi_null_nri_1_round_robin() );
2892 execute( TC_mscpool_L3Complete_by_tmsi_unassigned_nri_round_robin() );
2893 execute( TC_mscpool_L3Complete_by_tmsi_valid_nri_msc_not_connected_round_robin() );
2894 execute( TC_mscpool_L3Complete_by_tmsi_valid_nri_1() );
2895 execute( TC_mscpool_L3Complete_by_tmsi_valid_nri_2() );
2896 execute( TC_mscpool_LU_by_tmsi_from_other_PLMN() );
Neels Hofmeyrb1bf16d2023-06-27 02:10:04 +02002897 execute( TC_mscpool_paging_imsi() );
2898 execute( TC_mscpool_paging_tmsi() );
Neels Hofmeyr7d0e6802023-04-20 20:43:55 +02002899 execute( TC_mscpool_no_allow_attach_round_robin() );
2900 execute( TC_mscpool_no_allow_attach_valid_nri() );
2901 execute( TC_mscpool_sccp_n_pcstate_detaches_cnlink() );
2902 execute( TC_mscpool_sccp_n_pcstate_attaches_cnlink() );
2903
2904 execute( TC_sgsnpool_L3Compl_on_1_cnlink() );
2905 execute( TC_sgsnpool_L3Complete_no_nri_round_robin() );
2906 execute( TC_sgsnpool_L3Complete_valid_nri_1() );
2907 execute( TC_sgsnpool_L3Complete_valid_nri_2() );
2908 execute( TC_sgsnpool_nri_from_other_PLMN() );
2909 execute( TC_sgsnpool_sccp_n_pcstate_detaches_cnlink() );
2910 execute( TC_sgsnpool_sccp_n_pcstate_attaches_cnlink() );
2911
Oliver Smithaa919b42023-11-14 11:30:55 +01002912 /* Run only on nightly since it makes osmo-hnbgw <= 1.5.0 crash: OS#6253 */
2913 if (f_osmo_repo_is("nightly")) {
2914 execute(TC_second_rab_assignment());
2915 }
Neels Hofmeyrc3c01d32023-11-07 02:19:00 +01002916
Pau Espin Pedrolf0b9fa02022-09-12 13:31:07 +02002917 /* Run at the end since it makes osmo-hnbgw <= 1.3.0 crash: OS#5676 */
2918 execute(TC_hnb_reregister_reuse_sctp_assoc());
Neels Hofmeyrd019cc02023-06-02 16:31:23 +02002919
2920 /* Run at the end since it messes with the SCCP config */
2921 execute( TC_apply_sccp() );
Daniel Willmann19b8d902022-01-05 09:12:34 +01002922}
2923
2924}