blob: 97c564472feb7816a465b0558f13839f0ef74230 [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;
Daniel Willmann19b8d902022-01-05 09:12:34 +010091
92 charstring mp_mgw_ip := "127.0.0.1";
93 integer mp_mgw_port := 2427;
94
Neels Hofmeyr7a48df12023-04-20 20:43:43 +020095 RAN_Configurations mp_cn_cfg := {
96 /* MSCs (NUM_MSC entries) */
97 {
98 transport := RANAP_TRANSPORT_IuCS,
99 sccp_service_type := "mtp3_itu",
100 sctp_addr := { 23905, "127.0.0.1", 2905, "127.0.0.1" },
101 own_pc := 188, /* 0.23.4 first MSC emulation */
102 own_ssn := 142,
103 peer_pc := 189, /* 0.23.5 osmo-hnbgw */
104 peer_ssn := 142,
105 sio := '83'O,
106 rctx := 1
107 },
108 {
109 transport := RANAP_TRANSPORT_IuCS,
110 sccp_service_type := "mtp3_itu",
111 sctp_addr := { 23907, "127.0.0.1", 2905, "127.0.0.1" },
112 own_pc := 2, /* 0.0.2 second MSC emulation */
113 own_ssn := 142,
114 peer_pc := 189, /* 0.23.5 osmo-hnbgw */
115 peer_ssn := 142,
116 sio := '83'O,
117 rctx := 3
118 },
119 {
120 transport := RANAP_TRANSPORT_IuCS,
121 sccp_service_type := "mtp3_itu",
122 sctp_addr := { 23909, "127.0.0.1", 2905, "127.0.0.1" },
123 own_pc := 3, /* 0.0.3 third MSC emulation */
124 own_ssn := 142,
125 peer_pc := 189, /* 0.23.5 osmo-hnbgw */
126 peer_ssn := 142,
127 sio := '83'O,
128 rctx := 5
129 },
130 {
131 transport := RANAP_TRANSPORT_IuCS,
132 sccp_service_type := "mtp3_itu",
133 sctp_addr := { 23911, "127.0.0.1", 2905, "127.0.0.1" },
134 own_pc := 4, /* 0.0.4 fourth MSC emulation */
135 own_ssn := 142,
136 peer_pc := 189, /* 0.23.5 osmo-hnbgw */
137 peer_ssn := 142,
138 sio := '83'O,
139 rctx := 7
140 },
141
142 /* SGSNs (NUM_SGSN entries) */
143 {
144 transport := RANAP_TRANSPORT_IuCS,
145 sccp_service_type := "mtp3_itu",
146 sctp_addr := { /* local */ 23906, "127.0.0.1", /* remote */ 2905, "127.0.0.1" },
147 own_pc := 185, /* 0.23.1 first SGSN emulation */
148 own_ssn := 142,
149 peer_pc := 189, /* 2237, 1.23.5 osmo-hnbgw */
150 peer_ssn := 142,
151 sio := '83'O,
152 rctx := 2
153 },
154 {
155 transport := RANAP_TRANSPORT_IuCS,
156 sccp_service_type := "mtp3_itu",
157 sctp_addr := { /* local */ 23908, "127.0.0.1", /* remote */ 2905, "127.0.0.1" },
158 own_pc := 10, /* 0.1.2 second SGSN emulation */
159 own_ssn := 142,
160 peer_pc := 189, /* 2237, 1.23.5 osmo-hnbgw */
161 peer_ssn := 142,
162 sio := '83'O,
163 rctx := 4
164 },
165 {
166 transport := RANAP_TRANSPORT_IuCS,
167 sccp_service_type := "mtp3_itu",
168 sctp_addr := { /* local */ 23910, "127.0.0.1", /* remote */ 2905, "127.0.0.1" },
169 own_pc := 11, /* 0.1.3 third SGSN emulation */
170 own_ssn := 142,
171 peer_pc := 189, /* 2237, 1.23.5 osmo-hnbgw */
172 peer_ssn := 142,
173 sio := '83'O,
174 rctx := 6
175 },
176 {
177 transport := RANAP_TRANSPORT_IuCS,
178 sccp_service_type := "mtp3_itu",
179 sctp_addr := { /* local */ 23912, "127.0.0.1", /* remote */ 2905, "127.0.0.1" },
180 own_pc := 12, /* 0.1.4 fourth SGSN emulation */
181 own_ssn := 142,
182 peer_pc := 189, /* 2237, 1.23.5 osmo-hnbgw */
183 peer_ssn := 142,
184 sio := '83'O,
185 rctx := 8
186 }
Daniel Willmann19b8d902022-01-05 09:12:34 +0100187 };
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +0200188
Neels Hofmeyrbacb74f2022-08-29 16:24:12 +0200189 boolean mp_enable_pfcp_tests := false;
190
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +0200191 /* IP address at which we listen for PFCP to emulate a UPF in ttcn3 */
192 charstring mp_pfcp_ip_local := "127.0.0.1";
193
194 /* IP address from which the SUT (osmo-hnbgw) sends PFCP requests, and to which the ttcn3 UPF emulation sends
195 * PFCP responses. */
196 charstring mp_pfcp_ip_remote := "127.0.0.2";
Pau Espin Pedrol6c87ad92023-07-18 11:24:25 +0200197
198 boolean mp_validate_talloc_asn1 := true;
Pau Espin Pedrolee4ce862023-11-02 12:23:25 +0100199
200 /* The X31 timer configured at osmo-hnbgw (seconds). This provided an idea on
201 * minimum time the test must wait to consider this timer triggered */
202 integer mp_hnbgw_timer_x31 := 5;
Daniel Willmann19b8d902022-01-05 09:12:34 +0100203}
204
205function MSC_UnitdataCallback(RANAP_PDU ranap) runs on RAN_Emulation_CT return template RANAP_PDU {
206 // TODO: Actually implement unitdata handling
Neels Hofmeyrcf6dc492023-06-27 00:51:08 +0200207 return omit;
Daniel Willmann19b8d902022-01-05 09:12:34 +0100208}
209
210const RanOps MSC_RanOps := {
211 ranap_create_cb := refers(RAN_Emulation.RanapExpectedCreateCallback),
212 ranap_unitdata_cb := refers(MSC_UnitdataCallback),
213 ps_domain := false,
214 decode_dtap := false,
215 role_ms := false,
216 protocol := RAN_PROTOCOL_RANAP,
217 transport := RANAP_TRANSPORT_IuCS,
218 use_osmux := false,
Eric Wild6e511ce2022-04-02 21:35:56 +0200219 bssap_reset_retries := 1,
Daniel Willmann19b8d902022-01-05 09:12:34 +0100220 sccp_addr_local := omit,
221 sccp_addr_peer := omit
222}
223
Pau Espin Pedrol264679f2023-11-29 15:52:00 +0100224type record MgwResponse {
Daniel Willmann19b8d902022-01-05 09:12:34 +0100225 integer resp,
226 HostName mgw_rtp_ip,
Pau Espin Pedrol0c35a632023-11-29 16:00:35 +0100227 /* if set, used after first received MDCX: */
228 HostName mgw_rtp_ip_mdcx optional,
Daniel Willmann19b8d902022-01-05 09:12:34 +0100229 PortNumber mgw_rtp_port,
230 MgcpConnectionId mgcp_connection_id
231}
232type record MgcpParameters {
233 integer got_crcx_count,
234 integer got_dlcx_count,
235 MgcpCallId mgcp_call_id optional,
236 MgcpEndpoint mgcp_ep,
Pau Espin Pedrol264679f2023-11-29 15:52:00 +0100237 MgwResponse mgw_conn_ran,
238 MgwResponse mgw_conn_cn,
Daniel Willmann19b8d902022-01-05 09:12:34 +0100239 uint7_t rtp_payload_type,
240 charstring rtp_sdp_format,
241 HostName hnb_rtp_ip,
242 PortNumber hnb_rtp_port,
243 HostName cn_rtp_ip,
244 PortNumber cn_rtp_port,
245 boolean use_osmux,
246 integer got_osmux_count
247}
248
249template (value) MgcpParameters t_MgcpParams := {
250 got_crcx_count := 0,
251 got_dlcx_count := 0,
252 mgcp_call_id := omit,
253 mgcp_ep := "rtpbridge/1@mgw",
Pau Espin Pedrolb85ac2f2023-11-29 15:48:57 +0100254 mgw_conn_ran := {
Daniel Willmann19b8d902022-01-05 09:12:34 +0100255 resp := 1,
256 mgw_rtp_ip := "127.1.2.1",
Pau Espin Pedrol0c35a632023-11-29 16:00:35 +0100257 mgw_rtp_ip_mdcx := omit,
Daniel Willmann19b8d902022-01-05 09:12:34 +0100258 mgw_rtp_port := 10000,
259 mgcp_connection_id := '11111'H
260 },
Pau Espin Pedrolb85ac2f2023-11-29 15:48:57 +0100261 mgw_conn_cn := {
Daniel Willmann19b8d902022-01-05 09:12:34 +0100262 resp := 1,
263 mgw_rtp_ip := "127.1.2.2",
Pau Espin Pedrol0c35a632023-11-29 16:00:35 +0100264 mgw_rtp_ip_mdcx := omit,
Daniel Willmann19b8d902022-01-05 09:12:34 +0100265 mgw_rtp_port := 20000,
266 mgcp_connection_id := '22222'H
267 },
Philipp Maier6c5ba0752023-07-04 16:53:40 +0200268 rtp_payload_type := 112,
269 rtp_sdp_format := "VND.3GPP.IUFP",
Daniel Willmann19b8d902022-01-05 09:12:34 +0100270 hnb_rtp_ip := "127.1.1.1",
271 hnb_rtp_port := 10001,
272 cn_rtp_ip := "127.1.3.1",
273 cn_rtp_port := 20001,
274 use_osmux := false,
275 got_osmux_count := 0
276}
277
278type record TestHdlrParams {
279 integer hnb_idx,
Neels Hofmeyr7a48df12023-04-20 20:43:43 +0200280 /* cn_idx indicates which CN link from g_cn[] to connect to the test component.
281 * See also f_cn_idx(). */
282 integer cn_idx,
Daniel Willmann19b8d902022-01-05 09:12:34 +0100283 hexstring imsi,
284 boolean ps_domain,
285 MgcpParameters mgcp_pars optional,
Neels Hofmeyrf0b9ed12022-06-07 17:46:32 +0200286 HnbConfig hnb optional,
Neels Hofmeyrf2c95022023-04-19 01:24:39 +0200287 boolean expect_separate_sccp_cr,
288 integer tx_sccp_cr_data_len,
Neels Hofmeyr7d0e6802023-04-20 20:43:55 +0200289 charstring pfcp_local_addr,
Neels Hofmeyrb1bf16d2023-06-27 02:10:04 +0200290 octetstring nas_pdu optional,
291 /* local and remote SCCP addresses, used in TC_mscpool_paging_* */
292 SCCP_PAR_Address sccp_addr_msc optional,
Harald Welte0d4a8432024-04-04 01:12:11 +0200293 SCCP_PAR_Address sccp_addr_hnbgw optional,
294 /* RAB release cause */
295 RANAP_IEs.Cause rab_rel_cause
Daniel Willmann19b8d902022-01-05 09:12:34 +0100296}
297
298/* We extend:
299 * RUA_ConnHdlr (for the Iuh side, emulating the HNB)
300 * RAN_ConnHdlr (for the Iu side, emulating the MSC)
301 * MGCP_ConnHdlr (for the MGCP side, emulating the MGW)
302 */
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +0200303type component ConnHdlr extends RAN_ConnHdlr, MGCP_ConnHdlr, RUA_ConnHdlr, PFCP_ConnHdlr {
Daniel Willmann19b8d902022-01-05 09:12:34 +0100304 var integer g_sccp_conn_id;
305 var TestHdlrParams g_pars;
306 timer g_Tguard;
Neels Hofmeyr72a8d622023-01-26 13:47:01 +0100307
308 port TELNETasp_PT HNBGWVTY;
Daniel Willmann19b8d902022-01-05 09:12:34 +0100309}
310
311
312const MGCPOps MSC_MGCPOps := {
313 create_cb := refers(MGCP_Emulation.ExpectedCreateCallback),
314 unitdata_cb := refers(MGCP_Emulation.DummyUnitdataCallback)
315}
316
317function f_create_ranap_exp(octetstring l3_enc) runs on ConnHdlr {
318 BSSAP_PROC.call(RAN_register:{l3_enc, self}) {
319 [] BSSAP_PROC.getreply(RAN_register:{?, ?}) {};
320 }
321}
322
323
Daniel Willmannc79679a2022-08-23 17:48:39 +0200324const integer NUM_HNB := 2;
Daniel Willmann19b8d902022-01-05 09:12:34 +0100325
Daniel Willmann19b8d902022-01-05 09:12:34 +0100326type record HnbConfig {
327 LocationAreaIdentification lai,
328 integer sac
329}
330
331type component test_CT extends CTRL_Adapter_CT {
332 var boolean g_initialized := false;
333
334 /********************* Iu side */
Neels Hofmeyr7a48df12023-04-20 20:43:43 +0200335 var RAN_Adapter g_cn[NUM_MSC + NUM_SGSN];
Daniel Willmann19b8d902022-01-05 09:12:34 +0100336
337 /********************* Iuh side */
338 var HnbConfig g_hnb_cfg[NUM_HNB];
339 var Iuh_Emulation_CT vc_Iuh[NUM_HNB];
340 var RUA_Emulation_CT vc_RUA[NUM_HNB];
341 port HNBAP_PT HNBAP[NUM_HNB];
Pau Espin Pedrol83a49612022-09-12 21:11:05 +0200342 /* Number of HNBs to be used/started by the test */
343 var integer g_num_hnbs := NUM_HNB;
Daniel Willmann19b8d902022-01-05 09:12:34 +0100344
345 var MGCP_Emulation_CT vc_MGCP;
346 port TELNETasp_PT HNBGWVTY;
347 /* global test case guard timer (actual timeout value is set in f_init()) */
348 timer T_guard := 30.0;
Neels Hofmeyr7d0e6802023-04-20 20:43:55 +0200349
350 /* The cnlink type 'msc' or 'sgsn', to be used in CTRL commands to obtain counters */
351 var charstring g_ctr_cn_node_name;
352 /* Counter state */
353 var CounterNameValsList g_ctr_cn;
Daniel Willmann19b8d902022-01-05 09:12:34 +0100354}
355
356/* global altstep for global guard timer; */
357altstep as_Tguard() runs on test_CT {
358 [] T_guard.timeout {
359 setverdict(fail, "Timeout of T_guard");
360 mtc.stop;
361 }
362}
363
Daniel Willmann19b8d902022-01-05 09:12:34 +0100364function f_init_vty(charstring id := "foo") runs on test_CT {
365 if (HNBGWVTY.checkstate("Mapped")) {
366 /* skip initialization if already executed once */
367 return;
368 }
369 map(self:HNBGWVTY, system:HNBGWVTY);
370 f_vty_set_prompts(HNBGWVTY);
371 f_vty_transceive(HNBGWVTY, "enable");
372}
373
374function f_init_mgcp(charstring id) runs on test_CT {
375 id := id & "-MGCP";
376 var MGCPOps ops := {
377 create_cb := refers(MGCP_Emulation.ExpectedCreateCallback),
378 unitdata_cb := refers(MGCP_Emulation.DummyUnitdataCallback)
379 }
380 var MGCP_conn_parameters pars := {
381 callagent_ip := mp_hnbgw_ip,
382 callagent_udp_port := -1,
383 mgw_ip := mp_mgw_ip,
384 mgw_udp_port := mp_mgw_port,
385 multi_conn_mode := false
386 }
387
388 vc_MGCP := MGCP_Emulation_CT.create(id);
389 map(vc_MGCP:MGCP, system:MGCP_CODEC_PT);
390 vc_MGCP.start(MGCP_Emulation.main(ops, pars, id));
391}
392
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +0200393function f_init_pfcp(charstring id) runs on ConnHdlr {
394 id := id & "-PFCP";
395
396 var PFCP_Emulation_Cfg pfcp_cfg := {
397 pfcp_bind_ip := mp_pfcp_ip_local,
398 pfcp_bind_port := PFCP_PORT,
399 pfcp_remote_ip := mp_pfcp_ip_remote,
400 pfcp_remote_port := PFCP_PORT,
401 role := UPF
402 };
403
404 vc_PFCP := PFCP_Emulation_CT.create(id) alive;
405 connect(self:PFCP, vc_PFCP:CLIENT);
406 connect(self:PFCP_PROC, vc_PFCP:CLIENT_PROC);
407 vc_PFCP.start(PFCP_Emulation.main(pfcp_cfg));
408}
409
Daniel Willmann19b8d902022-01-05 09:12:34 +0100410function f_init_hnodeb(charstring id, integer hnb_idx, RuaOps rua_ops) runs on test_CT {
411 id := id & "-Iuh" & int2str(hnb_idx);
412
413 /* Iuh lower layer (RUA/HNBAP demux) */
414 var Iuh_conn_parameters iuh_pars;
415 iuh_pars.remote_ip := mp_hnbgw_ip;
416 iuh_pars.remote_sctp_port := mp_hnbgw_iuh_port;
417 iuh_pars.local_ip := mp_hnodeb_ip;
418 iuh_pars.local_sctp_port := mp_hnodeb_port + hnb_idx;
419 vc_Iuh[hnb_idx] := Iuh_Emulation_CT.create(id);
420 connect(self:HNBAP[hnb_idx], vc_Iuh[hnb_idx]:HNBAP);
421
422 vc_RUA[hnb_idx] := RUA_Emulation_CT.create(id & "-RUA");
423 connect(vc_RUA[hnb_idx]:RUA, vc_Iuh[hnb_idx]:RUA);
424
425 /* Start Iuh side components */
426 vc_Iuh[hnb_idx].start(Iuh_Emulation.main(iuh_pars, id));
427 vc_RUA[hnb_idx].start(RUA_Emulation.main(rua_ops, id & "-RUA"));
428}
429
Neels Hofmeyr3d5a0da2023-06-27 00:57:46 +0200430private type record of boolean BooleanList;
431
432private function f_vty_cnlink_allow_attach(TELNETasp_PT pt, boolean ps_domain, BooleanList allow_attach_list)
433{
434 var charstring config := f_vty_transceive_ret(pt, "show running-config");
435
436 var charstring msc_sgsn;
437 if (ps_domain) {
438 msc_sgsn := "sgsn";
439 } else {
440 msc_sgsn := "msc";
441 }
442
443 f_vty_enter_config(pt);
444 for (var integer cn_nr := 0; cn_nr < sizeof(allow_attach_list); cn_nr := cn_nr+1) {
445 if (f_strstr(config, "\n" & msc_sgsn & " " & int2str(cn_nr) & "\n") < 0) {
446 /* There is no 'msc N' for this cn_nr in the running config, so don't create an empty cn by
447 * stepping into that config node. */
448 log(msc_sgsn, cn_nr, " is not configured, skipping");
449 continue;
450 }
451 f_vty_transceive(pt, msc_sgsn & " " & int2str(cn_nr));
452
453 if (allow_attach_list[cn_nr]) {
454 /* strict := false: ignore if osmo-hnbgw does not support this config option (latest build) */
455 f_vty_transceive(pt, "allow-attach", strict := false);
456 } else {
457 f_vty_transceive(pt, "no allow-attach", strict := false);
458 }
459 f_vty_transceive(pt, "exit");
460 }
461 f_vty_transceive(pt, "exit");
462}
463
464/* Start RAN adapter for CN link N.
465 * e.g. link for 'msc 0' = (ps_domain := false, cn_nr := 0)
466 * link for 'sgsn 3' = (ps_domain := true, cn_nr := 3)
467 */
468private function f_cn_nr_init(boolean ps_domain, integer cn_nr) runs on test_CT {
469 var RanOps ranops := MSC_RanOps;
470 ranops.ps_domain := ps_domain;
471 var integer cn_idx := f_cn_idx(ps_domain, cn_nr);
472 var charstring msc_sgsn := "msc";
473 if (ps_domain) {
474 msc_sgsn := "sgsn";
475 }
476 f_ran_adapter_init(g_cn[cn_idx], mp_cn_cfg[cn_idx], "HNBGW_Test." & msc_sgsn & int2str(cn_nr), ranops);
477 f_ran_adapter_start(g_cn[cn_idx]);
478}
479
480private function f_cn_idx_disconnect(integer cn_idx) runs on test_CT {
481 f_ran_adapter_cleanup(g_cn[cn_idx]);
482}
483
Daniel Willmann19b8d902022-01-05 09:12:34 +0100484/* global initialization function */
Neels Hofmeyr333ea392023-06-27 00:58:05 +0200485function f_init(charstring id := "HNBGW", float guard_timeout := 30.0, integer nr_msc := 1, integer nr_sgsn := 1,
486 boolean start_hnb := true) runs on test_CT {
Daniel Willmann19b8d902022-01-05 09:12:34 +0100487
Daniel Willmann19b8d902022-01-05 09:12:34 +0100488 T_guard.start(guard_timeout);
489 activate(as_Tguard());
490
491 /* RUA/RANAP emulation on top of lower-layer Iuh */
492 var RuaOps rua_ops := {
493 create_cb := refers(IuhRanapCreateCallback),
494 unitdata_cb := refers(IuhRanapUnitdataCallback)
495 };
Pau Espin Pedrol83a49612022-09-12 21:11:05 +0200496 for (var integer i := 0; i < g_num_hnbs; i := i+1) {
Daniel Willmannc79679a2022-08-23 17:48:39 +0200497 g_hnb_cfg[i] := {
498 lai := {
Neels Hofmeyr497216f2023-06-27 00:59:26 +0200499 mcc_mnc := '00F110'H,
Daniel Willmannc79679a2022-08-23 17:48:39 +0200500 lac := 2342 + i
501 },
502 sac := 55
503 };
Daniel Willmann19b8d902022-01-05 09:12:34 +0100504 f_init_hnodeb(testcasename(), i, rua_ops);
505 }
506
Neels Hofmeyr3d5a0da2023-06-27 00:57:46 +0200507 f_init_vty("VirtHNBGW");
Neels Hofmeyrffcb8892023-06-27 01:09:57 +0200508 f_ipa_ctrl_start_client(mp_hnbgw_ip, mp_hnbgw_ctrl_port);
509
Daniel Willmann19b8d902022-01-05 09:12:34 +0100510 /* MSC emulation */
Neels Hofmeyr3d5a0da2023-06-27 00:57:46 +0200511
512 /* Make sure each MSC's internal state is "DISCONNECTED" at first */
513 for (var integer i := 0; i < NUM_MSC; i := i + 1) {
514 f_vty_transceive(HNBGWVTY, "msc " & int2str(i) & " ranap reset", strict := false);
515 }
516
517 var BooleanList allow_attach := { false, false, false, false };
Neels Hofmeyr7a48df12023-04-20 20:43:43 +0200518 for (var integer i := 0; i < nr_msc; i := i + 1) {
519 var integer cn_idx := FIRST_MSC_IDX + i;
Neels Hofmeyr3d5a0da2023-06-27 00:57:46 +0200520 allow_attach[i] := true;
521 f_cn_nr_init(ps_domain := false, cn_nr := i);
Neels Hofmeyr7a48df12023-04-20 20:43:43 +0200522 }
Neels Hofmeyr3d5a0da2023-06-27 00:57:46 +0200523 /* start the test with exactly all enabled MSCs allowed to attach */
524 f_vty_cnlink_allow_attach(HNBGWVTY, false, allow_attach);
Daniel Willmann19b8d902022-01-05 09:12:34 +0100525
526 /* SGSN emulation */
Neels Hofmeyr3d5a0da2023-06-27 00:57:46 +0200527
528 /* Make sure each SGSN's internal state is "DISCONNECTED" at first */
529 for (var integer i := 0; i < NUM_SGSN; i := i + 1) {
530 f_vty_transceive(HNBGWVTY, "sgsn " & int2str(i) & " ranap reset", strict := false);
Neels Hofmeyr7a48df12023-04-20 20:43:43 +0200531 }
Daniel Willmann19b8d902022-01-05 09:12:34 +0100532
Neels Hofmeyr3d5a0da2023-06-27 00:57:46 +0200533 allow_attach := { false, false, false, false };
534 for (var integer i := 0; i < nr_sgsn; i := i + 1) {
535 var integer cn_idx := FIRST_SGSN_IDX + i;
536 allow_attach[i] := true;
537 f_cn_nr_init(ps_domain := true, cn_nr := i);
538 }
539 f_vty_cnlink_allow_attach(HNBGWVTY, true, allow_attach);
540
Daniel Willmann19b8d902022-01-05 09:12:34 +0100541 f_init_mgcp(id);
Neels Hofmeyr333ea392023-06-27 00:58:05 +0200542
543 if (start_hnb) {
544 f_start_hnbs();
545 }
Neels Hofmeyr467eb7e2023-08-10 03:38:07 +0200546
547 /* Sometimes, the RUA InitialUE-Message from a test happens too quickly, before the RANAP RESET from
548 * RAN_Emulation is through, after above f_cn_nr_init(). In the pcap it seems to be a matter of 50 ms. Give some
549 * grace. */
550 f_sleep(1.0);
Daniel Willmann19b8d902022-01-05 09:12:34 +0100551}
552
553friend function f_shutdown_helper() runs on test_CT {
Pau Espin Pedrol6c87ad92023-07-18 11:24:25 +0200554 if (mp_validate_talloc_asn1) {
555 f_verify_talloc_bytes(HNBGWVTY, {"asn1_context"}, 1);
556 }
Neels Hofmeyr75d905b2023-04-27 00:30:25 +0200557
Daniel Willmann19b8d902022-01-05 09:12:34 +0100558 all component.stop;
559 setverdict(pass);
560 mtc.stop;
561}
562
563/* helper function to start all of the simulated hNodeBs */
564function f_start_hnbs() runs on test_CT {
Pau Espin Pedrol83a49612022-09-12 21:11:05 +0200565 for (var integer i:= 0; i < g_num_hnbs; i := i+1) {
Harald Welted71d5962024-03-27 19:17:19 +0100566 f_hnbap_hnb_register(i, i);
Daniel Willmann19b8d902022-01-05 09:12:34 +0100567 }
568}
569
570/***********************************************************************
571 * code running in test_CT, preparing start of per-UE ConnHdlr
572 ***********************************************************************/
573
574/* inbound RUA connection establishment on Iuh side */
575function IuhRanapCreateCallback(ContextId context_id, RUA_IEs.CN_DomainIndicator domain, charstring id)
576runs on RUA_Emulation_CT return RUA_ConnHdlr {
577 log("CreateCallback");
578 return null;
579}
580
581/* inbound RUA connectionless data on Iuh side */
582function IuhRanapUnitdataCallback(RANAP_PDU ranap)
583runs on RUA_Emulation_CT return template RANAP_PDU {
584 log("UnitdataCallback");
585 return omit;
586}
587
588private function f_start_handler_create(TestHdlrParams pars) runs on test_CT return ConnHdlr {
589 var ConnHdlr vc_conn;
590 var charstring id := testcasename() & int2str(pars.hnb_idx);
591
592 vc_conn := ConnHdlr.create(id);
593
594 /* Iuh RUA part */
595 connect(vc_conn:RUA, vc_RUA[pars.hnb_idx]:CLIENT);
596
Neels Hofmeyr7a48df12023-04-20 20:43:43 +0200597 /* MSC or SGSN */
598 connect(vc_conn:BSSAP, g_cn[pars.cn_idx].vc_RAN:CLIENT);
599 connect(vc_conn:BSSAP_PROC, g_cn[pars.cn_idx].vc_RAN:PROC);
600
Daniel Willmann19b8d902022-01-05 09:12:34 +0100601 /* MGCP part */
602 connect(vc_conn:MGCP, vc_MGCP:MGCP_CLIENT);
603 connect(vc_conn:MGCP_PROC, vc_MGCP:MGCP_PROC);
604
605 return vc_conn;
606}
607
608private function f_start_handler_run(ConnHdlr vc_conn, void_fn fn, TestHdlrParams pars) runs on test_CT {
609 var charstring id := testcasename(); // & int2str(pars.ran_idx);
610 /* We cannot use vc_conn.start(f_init_handler(fn, id, pars)); as we cannot have
611 * a stand-alone 'derefers()' call, see https://www.eclipse.org/forums/index.php/t/1091364/ */
612 pars.hnb := g_hnb_cfg[pars.hnb_idx];
Daniel Willmann19b8d902022-01-05 09:12:34 +0100613 vc_conn.start(derefers(fn)(id, pars));
614}
615
616function f_start_handler_with_pars(void_fn fn, template (value) TestHdlrParams pars)
617runs on test_CT return ConnHdlr {
618 var ConnHdlr vc_conn;
619 vc_conn := f_start_handler_create(valueof(pars));
620 f_start_handler_run(vc_conn, fn, valueof(pars));
621 return vc_conn;
622}
623
624/***********************************************************************
625 * code running inside per-UE ConnHdlr
626 ***********************************************************************/
627
628type function void_fn(charstring id, TestHdlrParams pars) runs on ConnHdlr;
629
630function f_init_handler(TestHdlrParams pars, float t_guard := 20.0) runs on ConnHdlr {
631 /* make parameters available via component variable */
632 g_pars := pars;
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +0200633
634 f_init_pfcp(testcasename());
635
Daniel Willmann19b8d902022-01-05 09:12:34 +0100636 /* start guard timer and activate it as default */
637 g_Tguard.start(t_guard);
638 activate(as_Tguard_ConnHdlr());
639
Neels Hofmeyr72a8d622023-01-26 13:47:01 +0100640 map(self:HNBGWVTY, system:HNBGWVTY);
641 f_vty_set_prompts(HNBGWVTY);
642 f_vty_transceive(HNBGWVTY, "enable");
643
Daniel Willmann19b8d902022-01-05 09:12:34 +0100644 /* TODO: CTRL? */
Neels Hofmeyr59517222023-06-23 04:46:59 +0200645
646 f_sleep(1.0);
Daniel Willmann19b8d902022-01-05 09:12:34 +0100647}
648
649/* global altstep for global guard timer; */
650private altstep as_Tguard_ConnHdlr() runs on ConnHdlr {
651 [] g_Tguard.timeout {
652 setverdict(fail, "Timeout of T_guard");
653 mtc.stop;
654 }
655}
656
Neels Hofmeyrdc416c92023-03-09 02:47:50 +0100657private function f_bssap_expect(template (present) RANAP_PDU exp_rx) runs on ConnHdlr return RANAP_PDU
658{
659 var RANAP_PDU rx;
660 timer T := 5.0;
661 T.start;
662 alt {
663 [] BSSAP.receive(exp_rx) -> value rx {
664 setverdict(pass);
665 }
666 [] BSSAP.receive(RANAP_PDU:?) {
667 setverdict(fail, "Got an unexpected RANAP message on BSSAP port, was waiting for ", exp_rx);
668 mtc.stop;
669 }
670 [] T.timeout {
671 setverdict(fail, "Timeout waiting for RANAP on BSSAP port: ", exp_rx);
672 mtc.stop;
673 }
674 }
675 T.stop;
676 return rx;
677}
678
Daniel Willmann19b8d902022-01-05 09:12:34 +0100679/* send RANAP on Iuh and expect it to show up on Iu */
680function f_iuh2iu(template (present) RANAP_PDU tx, template RANAP_PDU exp_rx := omit)
681runs on ConnHdlr return RANAP_PDU {
682 var RANAP_PDU rx;
683 timer T := 5.0;
684
685 if (istemplatekind(exp_rx, "omit")) {
686 exp_rx := tx;
687 }
688
689 RUA.send(tx);
Daniel Willmann19b8d902022-01-05 09:12:34 +0100690
Neels Hofmeyrdc416c92023-03-09 02:47:50 +0100691 return f_bssap_expect(exp_rx);
Daniel Willmann19b8d902022-01-05 09:12:34 +0100692}
693
694/* send RANAP on Iu and expect it to show up on Iuh */
695function f_iu2iuh(template (present) RANAP_PDU tx, template RANAP_PDU exp_rx := omit)
696runs on ConnHdlr return RANAP_PDU {
Daniel Willmann19b8d902022-01-05 09:12:34 +0100697 if (istemplatekind(exp_rx, "omit")) {
698 exp_rx := tx;
699 }
700
701 BSSAP.send(tx);
Daniel Willmann19b8d902022-01-05 09:12:34 +0100702
Neels Hofmeyr735b6562023-03-09 02:51:28 +0100703 return f_rua_expect(exp_rx)
704}
705
706/* expect to receive a specific RUA message on Iuh */
707private function f_rua_expect(template (present) RANAP_PDU exp_rx) runs on ConnHdlr return RANAP_PDU
708{
709 var RANAP_PDU rx;
710 timer T := 5.0;
711 T.start;
Daniel Willmann19b8d902022-01-05 09:12:34 +0100712 alt {
713 [] RUA.receive(exp_rx) -> value rx {
714 setverdict(pass);
715 }
Neels Hofmeyr735b6562023-03-09 02:51:28 +0100716 [] RUA.receive(RANAP_PDU:?) {
717 setverdict(fail, "Got an unexpected RUA message, was waiting for ", exp_rx);
718 mtc.stop;
719 }
Daniel Willmann19b8d902022-01-05 09:12:34 +0100720 [] T.timeout {
721 setverdict(fail, "Timeout waiting for Iuh ", exp_rx);
Neels Hofmeyr735b6562023-03-09 02:51:28 +0100722 mtc.stop;
Daniel Willmann19b8d902022-01-05 09:12:34 +0100723 }
724 }
Neels Hofmeyr735b6562023-03-09 02:51:28 +0100725 T.stop;
Daniel Willmann19b8d902022-01-05 09:12:34 +0100726 return rx;
727}
728
729/* send RANAP on Iuh and expect it to show up on Iu */
730function f_iuh2iu_connect(template (present) RANAP_PDU tx, template RANAP_PDU exp_rx := omit)
731runs on ConnHdlr return RANAP_PDU {
732 var RANAP_PDU rx;
733 timer T := 5.0;
734
735 if (istemplatekind(exp_rx, "omit")) {
736 exp_rx := tx;
737 }
738
739 /* create an expect on the Iu side for the random NAS portion */
Neels Hofmeyrf2c95022023-04-19 01:24:39 +0200740 if (g_pars.expect_separate_sccp_cr) {
Neels Hofmeyrf0b9ed12022-06-07 17:46:32 +0200741 f_ran_register_sccp_cr_without_payload();
742 } else {
743 var template (omit) octetstring nas := f_ranap_extract_l3(valueof(tx));
744 f_ran_register_exp(valueof(nas));
745 }
Daniel Willmann19b8d902022-01-05 09:12:34 +0100746
747 /* send it via Iuh (creating a RUA connection) */
748 RUA.send(RUA_Conn_Req:{g_pars.ps_domain, tx});
749
Neels Hofmeyrf2c95022023-04-19 01:24:39 +0200750 if (g_pars.expect_separate_sccp_cr) {
Neels Hofmeyrf0b9ed12022-06-07 17:46:32 +0200751 /* Acknowledge the empty SCCP CR. RAN_Emulation does the confirmation, no need to respond. */
752 BSSAP.receive(tr_RANAP_Conn_Req());
753 }
754
Daniel Willmann19b8d902022-01-05 09:12:34 +0100755 /* expect to receive it on the Iu side */
Neels Hofmeyrdc416c92023-03-09 02:47:50 +0100756 return f_bssap_expect(exp_rx);
Daniel Willmann19b8d902022-01-05 09:12:34 +0100757}
758
Neels Hofmeyr99b7d402023-02-20 14:26:31 +0100759/* 3GPP TS 48.006 9.2 Connection release:
760 *
761 * The MSC sends a SCCP released message. This message shall not contain
762 * any user data field.
763 *
764 * So what we expect normally is:
765 *
766 * HNBGW MSC
767 * RUA --id-Disconnect-------> | ---Data-Form-1(!)---> | Iu-ReleaseComplete
768 * | <--Released---------- | (no data)
769 *
770 * This function tests osmo-hnbgw behavior if the CN fails to send a RLSD:
771 * after some timeout, osmo-hnbgw should send a RLSD to the CN.
772 */
Daniel Willmann19b8d902022-01-05 09:12:34 +0100773function f_iuh2iu_disconnect(template (present) RANAP_PDU tx, RUA_IEs.Cause cause,
774 template RANAP_PDU exp_rx := omit)
775runs on ConnHdlr return RANAP_PDU {
776 var RANAP_PDU rx
Pau Espin Pedrolee4ce862023-11-02 12:23:25 +0100777 timer T := int2float(mp_hnbgw_timer_x31) + 1.0;
Daniel Willmann19b8d902022-01-05 09:12:34 +0100778
779 if (istemplatekind(exp_rx, "omit")) {
780 exp_rx := tx;
781 }
782
783 /* send it via Iuh (creating a RUA connection) */
784 RUA.send(RUA_Disc_Req:{tx, cause});
785
786 /* expect to receive it on the Iu side */
Neels Hofmeyrdc416c92023-03-09 02:47:50 +0100787 rx := f_bssap_expect(exp_rx);
Daniel Willmann19b8d902022-01-05 09:12:34 +0100788
789 /* expect disconnect on the Iu side */
Neels Hofmeyrdc416c92023-03-09 02:47:50 +0100790 T.start;
Daniel Willmann19b8d902022-01-05 09:12:34 +0100791 alt {
792 [] BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_IND) {
793 setverdict(pass);
794 }
795 [] T.timeout {
796 setverdict(fail, "Timeout waiting for Iu disconnect");
797 return rx;
798 }
799
800 }
801 return rx;
802}
803
Neels Hofmeyrf2c95022023-04-19 01:24:39 +0200804private function f_build_initial_ue_with_nas(TestHdlrParams pars, octetstring nas)
805 return RANAP_PDU {
Harald Welte3f216c52024-03-27 20:40:17 +0100806 var RANAP_IEs.LAI lai := {
Daniel Willmann19b8d902022-01-05 09:12:34 +0100807 pLMNidentity := hex2oct(pars.hnb.lai.mcc_mnc),
808 lAC := int2oct(pars.hnb.lai.lac, 2),
809 iE_Extensions := omit
810 };
Harald Welte3f216c52024-03-27 20:40:17 +0100811 var RANAP_IEs.SAI sai := {
Daniel Willmann19b8d902022-01-05 09:12:34 +0100812 pLMNidentity := lai.pLMNidentity,
813 lAC := lai.lAC,
814 sAC := int2oct(pars.hnb.sac, 2),
815 iE_Extensions := omit
816 }
Daniel Willmann19b8d902022-01-05 09:12:34 +0100817 var IuSignallingConnectionIdentifier sigc_id := int2bit(f_rnd_int(1000), 24);
818 var GlobalRNC_ID grnc_id := {
819 pLMNidentity := lai.pLMNidentity,
820 rNC_ID := 2342
821 }
Neels Hofmeyrf2c95022023-04-19 01:24:39 +0200822 var template RANAP_PDU ret;
Daniel Willmann19b8d902022-01-05 09:12:34 +0100823 if (pars.ps_domain) {
Harald Welte3f216c52024-03-27 20:40:17 +0100824 var RANAP_IEs.RAC rac := '00'O;
Neels Hofmeyrf2c95022023-04-19 01:24:39 +0200825 ret := ts_RANAP_initialUE_PS(lai, rac, sai, nas, sigc_id, grnc_id);
Daniel Willmann19b8d902022-01-05 09:12:34 +0100826 } else {
Neels Hofmeyrf2c95022023-04-19 01:24:39 +0200827 ret := ts_RANAP_initialUE_CS(lai, sai, nas, sigc_id, grnc_id);
Daniel Willmann19b8d902022-01-05 09:12:34 +0100828 }
Neels Hofmeyrf2c95022023-04-19 01:24:39 +0200829 return valueof(ret);
830}
831
832/* build a RANAP InitialUE based on the TestHdlrParams */
833friend function f_build_initial_ue(TestHdlrParams pars) return RANAP_PDU {
834
835 var octetstring nas;
836
837 if (pars.tx_sccp_cr_data_len == 0) {
838 nas := f_rnd_octstring(10);
839 } else {
840 /* The test asks for an exact number of Optional Data bytes. */
841
842 /* First see what size the RANAP part of the payload data is,
843 * to adjust the NAS PDU size to the size requested by the test (pars.tx_sccp_cr_data_len). */
844 var RANAP_PDU initial_ue := f_build_initial_ue_with_nas(pars, '00'O);
845
846 var octetstring ranap_plus_one_byte_nas := enc_RANAP_PDU(initial_ue);
847 var integer ranap_length := lengthof(ranap_plus_one_byte_nas) - 1;
848
849 log("ranap_plus_one_byte_nas = ", lengthof(ranap_plus_one_byte_nas), " bytes, ", initial_ue, " = ",
850 ranap_plus_one_byte_nas);
851 log("ranap_length = ", ranap_length);
852
853 /* SCCP CR has a payload length limit of 130 bytes. To trigger this limit, the RANAP + NAS PDU has to be
854 * > 130 bytes. It doesn't need to be 131 bytes in the NAS PDU alone, but let's just make it definitely
855 * large enough. To test for this limit, pars.tx_sccp_cr_data_len asks for a specific amount of data len. */
856 nas := f_rnd_octstring(pars.tx_sccp_cr_data_len - ranap_length);
857 }
858
859 var RANAP_PDU ret := f_build_initial_ue_with_nas(pars, nas);
860
861 if (pars.tx_sccp_cr_data_len != 0) {
862 for (var integer attempts := 0; attempts < 2; attempts := attempts + 1) {
863 var octetstring check_len := enc_RANAP_PDU(ret);
864 log("final RANAP PDU length = ", lengthof(check_len));
865 if (lengthof(check_len) == pars.tx_sccp_cr_data_len) {
866 return ret;
867 }
868 nas := f_rnd_octstring(lengthof(nas) + (pars.tx_sccp_cr_data_len - lengthof(check_len)));
869 log("that was off, changed NAS length to ", lengthof(nas), " and trying again");
870 ret := f_build_initial_ue_with_nas(pars, nas);
871 }
872 setverdict(fail, "Ended up with wrong Optional Data length");
873 mtc.stop;
874 }
875 return ret;
Daniel Willmann19b8d902022-01-05 09:12:34 +0100876}
877
878/* build a RANAP RAB AssignmentResponse based on the TestHdlrParams */
879friend function f_build_rab_ass_resp(TestHdlrParams pars) return RANAP_PDU {
880 var template RAB_SetupOrModifiedList rab_sml;
881
882 rab_sml := ts_RAB_SMdL(t_RAB_id(23), f_ts_RAB_TLA("192.168.1.23"), t_RAB_binding_port(1234));
883
884 return valueof(ts_RANAP_RabAssResp(rab_sml));
885}
886
887
888/***********************************************************************
889 * HNBAP Testing
890 ***********************************************************************/
891
892
Harald Welted71d5962024-03-27 19:17:19 +0100893function 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 +0100894{
895 timer T := 2.0;
896
Neels Hofmeyrfffe79b2023-06-27 01:16:15 +0200897 HNBAP[hnb_idx].send(ts_HNBAP_HNBRegisterRequest(char2oct("TTCN3-HNB-" & int2str(hnb_idx)),
Daniel Willmann19b8d902022-01-05 09:12:34 +0100898 '00F110'O,
Daniel Willmannc79679a2022-08-23 17:48:39 +0200899 int2bit(1 + cell_id, 28),
Daniel Willmann19b8d902022-01-05 09:12:34 +0100900 int2oct(2, 2),
901 int2oct(3, 1),
902 int2oct(4, 2)));
903
904 T.start;
905 alt {
906 [] HNBAP[hnb_idx].receive(tr_HNBAP_HNBRegisterAccept(?)) {
Daniel Willmannc79679a2022-08-23 17:48:39 +0200907 if (expect_reject) {
908 setverdict(fail, "Rx HNB Register Accept while expecting reject");
909 } else {
910 setverdict(pass);
911 }
912 }
913 [] HNBAP[hnb_idx].receive(tr_HNBAP_HNBRegisterReject(?)) {
914 if (expect_reject) {
915 setverdict(pass);
916 } else {
917 setverdict(fail, "Rx HNB Register Reject while expecting accept");
918 }
Daniel Willmann19b8d902022-01-05 09:12:34 +0100919 }
920 [] HNBAP[hnb_idx].receive(IUHEM_Event:?) {
921 repeat;
922 }
923 [] T.timeout {
Daniel Willmannc79679a2022-08-23 17:48:39 +0200924 setverdict(fail, "Timeout waiting for HNB Register response");
Daniel Willmann19b8d902022-01-05 09:12:34 +0100925 }
926 }
927}
928
Harald Welteaf3e2162024-03-27 21:54:20 +0100929function f_hnbap_ue_register(integer hnb_idx := 0, template (present) UE_Identity ue_id, boolean expect_reject := false) runs on test_CT
930{
931 timer T := 2.0;
932
933 HNBAP[hnb_idx].send(ts_HNBAP_UERegisterRequest(ue_id));
934
935 T.start;
936 alt {
937 [] HNBAP[hnb_idx].receive(tr_HNBAP_UERegisterAccept(ue_id)) {
938 if (expect_reject) {
939 setverdict(fail, "Rx UE Register Accept while expecting reject");
940 } else {
941 setverdict(pass);
942 }
943 }
944 [] HNBAP[hnb_idx].receive(tr_HNBAP_UERegisterReject(ue_id, ?)) {
945 if (expect_reject) {
946 setverdict(pass);
947 } else {
948 setverdict(fail, "Rx UE Register Reject while expecting accept");
949 }
950 }
951 [] HNBAP[hnb_idx].receive(IUHEM_Event:?) {
952 repeat;
953 }
954 [] T.timeout {
955 setverdict(fail, "Timeout waiting for UE Register response");
956 }
957 }
958}
959
960
Daniel Willmann19b8d902022-01-05 09:12:34 +0100961testcase TC_hnb_register() runs on test_CT {
Pau Espin Pedrol83a49612022-09-12 21:11:05 +0200962 g_num_hnbs := 1;
Neels Hofmeyr333ea392023-06-27 00:58:05 +0200963 f_init(start_hnb := false);
Harald Welted71d5962024-03-27 19:17:19 +0100964 f_hnbap_hnb_register(0);
Daniel Willmann19b8d902022-01-05 09:12:34 +0100965 f_shutdown_helper();
966}
967
Pau Espin Pedrolacf4f222022-09-27 14:33:40 +0200968/* Try to register the same HNB from 2 different concurrent connections. Second
969 * one should be rejected. */
Daniel Willmannc79679a2022-08-23 17:48:39 +0200970testcase TC_hnb_register_duplicate() runs on test_CT {
Pau Espin Pedrol83a49612022-09-12 21:11:05 +0200971 g_num_hnbs := 2;
Neels Hofmeyr333ea392023-06-27 00:58:05 +0200972 f_init(start_hnb := false);
Harald Welted71d5962024-03-27 19:17:19 +0100973 f_hnbap_hnb_register(0);
974 f_hnbap_hnb_register(1, 0, expect_reject := true);
Daniel Willmannc79679a2022-08-23 17:48:39 +0200975 f_verify_talloc_count(HNBGWVTY, {"struct hnb_context"}, expect_count := 1);
976 f_shutdown_helper();
977}
978
Pau Espin Pedrolacf4f222022-09-27 14:33:40 +0200979/* Try to register the same HNB in the same connection already established, aka
980 * duplicate HNB Register Request. It should be accepted and new configuration
981 * applied. TS 25.469 8.2.4 */
982testcase TC_hnb_register_duplicate_reuse_sctp_assoc() runs on test_CT {
983 g_num_hnbs := 1;
Neels Hofmeyr333ea392023-06-27 00:58:05 +0200984 f_init(start_hnb := false);
Harald Welted71d5962024-03-27 19:17:19 +0100985 f_hnbap_hnb_register(0);
986 f_hnbap_hnb_register(0);
Pau Espin Pedrolacf4f222022-09-27 14:33:40 +0200987 f_verify_talloc_count(HNBGWVTY, {"struct hnb_context"}, expect_count := 1);
988 f_shutdown_helper();
989}
990
Pau Espin Pedrolf0b9fa02022-09-12 13:31:07 +0200991/* Drop HNBAP conn (HNBAP DEREG) and reconnect it (HNBAP REG) using same SCTP association.
992 * Related: OS#5676, SYS#6113 */
993testcase TC_hnb_reregister_reuse_sctp_assoc() runs on test_CT {
994 g_num_hnbs := 1;
Neels Hofmeyr333ea392023-06-27 00:58:05 +0200995 f_init(start_hnb := false);
Harald Welted71d5962024-03-27 19:17:19 +0100996 f_hnbap_hnb_register(0);
Pau Espin Pedrolf0b9fa02022-09-12 13:31:07 +0200997 HNBAP[0].send(ts_HNBAP_HNBDe_Register(ts_HnbapCause(unspecified)));
Harald Welted71d5962024-03-27 19:17:19 +0100998 f_hnbap_hnb_register(0);
Pau Espin Pedrolf0b9fa02022-09-12 13:31:07 +0200999 f_verify_talloc_count(HNBGWVTY, {"struct hnb_context"}, expect_count := 1);
1000 f_shutdown_helper();
1001}
1002
Harald Welteaf3e2162024-03-27 21:54:20 +01001003/* regular UE registration */
1004testcase TC_ue_register() runs on test_CT {
1005 var UE_Identity ue_id := { iMSI := imsi_hex2oct(f_gen_imsi(1)) };
1006 g_num_hnbs := 1;
1007 f_init(start_hnb := true);
1008 f_hnbap_ue_register(0, ue_id);
1009 f_shutdown_helper();
1010}
1011
Harald Weltef60044d2024-04-04 00:54:34 +02001012/* regular UE registration (UE Identity: TMSI+LAI) */
1013testcase TC_ue_register_tmsi_lai() runs on test_CT {
1014 var UE_Identity ue_id := { tMSILAI := { tMSI := oct2bit(f_gen_tmsi(0)),
1015 lAI := { pLMNID := '00F110'O, lAC := '2342'O }
1016 }
1017 };
1018 g_num_hnbs := 1;
1019 f_init(start_hnb := true);
1020 f_hnbap_ue_register(0, ue_id);
1021 f_shutdown_helper();
1022}
1023
1024
Harald Welteaf3e2162024-03-27 21:54:20 +01001025/* UE registration from unregistered HNB */
1026testcase TC_ue_register_before_hnb_register() runs on test_CT {
1027 var UE_Identity ue_id := { iMSI := imsi_hex2oct(f_gen_imsi(1)) };
1028 g_num_hnbs := 1;
1029 f_init(start_hnb := false);
1030 f_hnbap_ue_register(0, ue_id, expect_reject := true);
1031 f_shutdown_helper();
1032}
1033
Daniel Willmann19b8d902022-01-05 09:12:34 +01001034/***********************************************************************
1035 * RUA / RANAP Testing
1036 ***********************************************************************/
1037
Neels Hofmeyr7a48df12023-04-20 20:43:43 +02001038/* Translate from {msc,sgsn}x{0..n} to the proper index to use in g_cn[].
1039 * g_cn[] stores CN links, MSCs and SGSNs in the same array.
1040 * For example, for 'sgsn 23', use g_cn[ f_cn_idx(ps_domain := true, cn_nr := 23) ].
1041 *
1042 * Note the naming:
1043 * cn_nr is the number used in the cfg file, as in 'msc 0'.
1044 * cn_idx is the array index in g_cn[].
1045 */
1046private function f_cn_idx(boolean ps_domain, integer cn_nr := 0) return integer
1047{
1048 if (ps_domain) {
1049 return FIRST_SGSN_IDX + cn_nr;
1050 }
1051 return FIRST_MSC_IDX + cn_nr;
1052}
1053
Daniel Willmann19b8d902022-01-05 09:12:34 +01001054private template (value) TestHdlrParams
Neels Hofmeyrf0b9ed12022-06-07 17:46:32 +02001055t_pars(integer imsi_suffix, boolean ps_domain := false, integer hnb_idx := 0,
Neels Hofmeyr7a48df12023-04-20 20:43:43 +02001056 boolean expect_separate_sccp_cr := false, integer tx_sccp_cr_data_len := 0,
Harald Welte18188342024-04-04 01:36:56 +02001057 integer cn_nr := 0, template (value) RANAP_IEs.Cause rab_rel_cause := ts_RanapCause_nas_normal) := {
Daniel Willmann19b8d902022-01-05 09:12:34 +01001058 hnb_idx := hnb_idx,
Neels Hofmeyr7a48df12023-04-20 20:43:43 +02001059 cn_idx := f_cn_idx(ps_domain, cn_nr),
Daniel Willmann19b8d902022-01-05 09:12:34 +01001060 imsi := f_gen_imsi(imsi_suffix),
1061 ps_domain := ps_domain,
Pau Espin Pedrolaf746502023-11-29 16:18:28 +01001062 mgcp_pars := t_MgcpParams,
Neels Hofmeyrf0b9ed12022-06-07 17:46:32 +02001063 hnb := omit, /* filled in later */
Neels Hofmeyrf2c95022023-04-19 01:24:39 +02001064 expect_separate_sccp_cr := expect_separate_sccp_cr,
1065 tx_sccp_cr_data_len := tx_sccp_cr_data_len,
Neels Hofmeyr7d0e6802023-04-20 20:43:55 +02001066 pfcp_local_addr := mp_pfcp_ip_local,
Neels Hofmeyrb1bf16d2023-06-27 02:10:04 +02001067 nas_pdu := omit,
1068 sccp_addr_msc := omit,
Harald Welte0d4a8432024-04-04 01:12:11 +02001069 sccp_addr_hnbgw := omit,
1070 rab_rel_cause := rab_rel_cause
Daniel Willmann19b8d902022-01-05 09:12:34 +01001071}
1072
1073/* Create an Iuh connection; send InitialUE; expect it to appear on new SCCP conenction */
1074friend function f_tc_initial_ue(charstring id, TestHdlrParams pars) runs on ConnHdlr {
1075 f_init_handler(pars);
1076 var RANAP_PDU tx := f_build_initial_ue(g_pars);
1077 f_iuh2iu_connect(tx);
1078}
1079testcase TC_ranap_cs_initial_ue() runs on test_CT {
1080 var ConnHdlr vc_conn;
1081
Pau Espin Pedrol83a49612022-09-12 21:11:05 +02001082 g_num_hnbs := 1;
Daniel Willmann19b8d902022-01-05 09:12:34 +01001083 f_init();
Daniel Willmann19b8d902022-01-05 09:12:34 +01001084
1085 vc_conn := f_start_handler_with_pars(refers(f_tc_initial_ue), t_pars(1));
1086 vc_conn.done;
Neels Hofmeyr3a9140e2023-06-23 04:50:39 +02001087
1088 f_shutdown_helper();
Daniel Willmann19b8d902022-01-05 09:12:34 +01001089}
1090testcase TC_ranap_ps_initial_ue() runs on test_CT {
1091 var ConnHdlr vc_conn;
1092
Pau Espin Pedrol83a49612022-09-12 21:11:05 +02001093 g_num_hnbs := 1;
Daniel Willmann19b8d902022-01-05 09:12:34 +01001094 f_init();
Daniel Willmann19b8d902022-01-05 09:12:34 +01001095
1096 vc_conn := f_start_handler_with_pars(refers(f_tc_initial_ue), t_pars(2, true));
1097 vc_conn.done;
Neels Hofmeyr3a9140e2023-06-23 04:50:39 +02001098
1099 f_shutdown_helper();
Daniel Willmann19b8d902022-01-05 09:12:34 +01001100}
1101
Neels Hofmeyrf2c95022023-04-19 01:24:39 +02001102private function f_vty_set_sccp_max_optional_data(TELNETasp_PT pt, integer val := -1)
Neels Hofmeyrf0b9ed12022-06-07 17:46:32 +02001103{
Neels Hofmeyrf2c95022023-04-19 01:24:39 +02001104 var charstring valstr;
1105 if (val < 0) {
1106 valstr := "standard";
1107 } else {
1108 valstr := int2str(val);
1109 }
Neels Hofmeyrf0b9ed12022-06-07 17:46:32 +02001110 f_vty_enter_config(pt);
Neels Hofmeyrf2c95022023-04-19 01:24:39 +02001111 f_vty_transceive(pt, "cs7 instance 0");
1112 f_vty_transceive(pt, "sccp max-optional-data " & valstr);
Neels Hofmeyrf0b9ed12022-06-07 17:46:32 +02001113 f_vty_transceive(pt, "end");
1114}
1115
1116testcase TC_ranap_cs_initial_ue_empty_cr() runs on test_CT {
1117 var ConnHdlr vc_conn;
1118
Pau Espin Pedrol83a49612022-09-12 21:11:05 +02001119 g_num_hnbs := 1;
Neels Hofmeyrf0b9ed12022-06-07 17:46:32 +02001120 f_init();
Neels Hofmeyrf0b9ed12022-06-07 17:46:32 +02001121
Neels Hofmeyrf2c95022023-04-19 01:24:39 +02001122 f_vty_set_sccp_max_optional_data(HNBGWVTY, 0);
Neels Hofmeyrf0b9ed12022-06-07 17:46:32 +02001123
Neels Hofmeyrf2c95022023-04-19 01:24:39 +02001124 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 +02001125 vc_conn.done;
1126
1127 /* reset */
Neels Hofmeyrf2c95022023-04-19 01:24:39 +02001128 f_vty_set_sccp_max_optional_data(HNBGWVTY);
Neels Hofmeyr3a9140e2023-06-23 04:50:39 +02001129
1130 f_shutdown_helper();
Neels Hofmeyrf0b9ed12022-06-07 17:46:32 +02001131}
1132testcase TC_ranap_ps_initial_ue_empty_cr() runs on test_CT {
1133 var ConnHdlr vc_conn;
1134
Pau Espin Pedrol83a49612022-09-12 21:11:05 +02001135 g_num_hnbs := 1;
Neels Hofmeyrf0b9ed12022-06-07 17:46:32 +02001136 f_init();
Neels Hofmeyrf0b9ed12022-06-07 17:46:32 +02001137
Neels Hofmeyrf2c95022023-04-19 01:24:39 +02001138 f_vty_set_sccp_max_optional_data(HNBGWVTY, 0);
Neels Hofmeyrf0b9ed12022-06-07 17:46:32 +02001139
Neels Hofmeyrf2c95022023-04-19 01:24:39 +02001140 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 +02001141 vc_conn.done;
1142
1143 /* reset */
Neels Hofmeyrf2c95022023-04-19 01:24:39 +02001144 f_vty_set_sccp_max_optional_data(HNBGWVTY);
Neels Hofmeyr3a9140e2023-06-23 04:50:39 +02001145
1146 f_shutdown_helper();
Neels Hofmeyrf2c95022023-04-19 01:24:39 +02001147}
1148
1149type record Testdata_CR_Limit {
1150 integer data_len,
1151 integer max_optional_data,
1152 boolean expect_separate_sccp_cr
1153};
1154type record of Testdata_CR_Limit Testdata_CR_Limits;
1155
1156testcase TC_sccp_cr_limit() runs on test_CT {
1157 g_num_hnbs := 1;
1158 f_init();
Neels Hofmeyrf2c95022023-04-19 01:24:39 +02001159
1160 const Testdata_CR_Limits tests := {
1161 { data_len := 130, max_optional_data := -1, expect_separate_sccp_cr := false },
1162 { data_len := 131, max_optional_data := -1, expect_separate_sccp_cr := true },
1163
1164 { data_len := 100, max_optional_data := 100, expect_separate_sccp_cr := false },
1165 { data_len := 101, max_optional_data := 100, expect_separate_sccp_cr := true },
1166
1167 { data_len := 200, max_optional_data := 200, expect_separate_sccp_cr := false },
1168 { data_len := 201, max_optional_data := 200, expect_separate_sccp_cr := true }
1169 };
1170
1171 var integer csps;
1172 for (csps := 0; csps < 2; csps := csps + 1) {
1173 var boolean ps_domain := (csps > 0);
1174
1175 var integer i;
1176 for (i := 0; i < lengthof(tests); i := i + 1) {
1177 var Testdata_CR_Limit t := tests[i];
1178 f_logp(HNBGWVTY,
1179 "TEST PART TC_sccp_cr_limit ps_domain=" & f_bool2str(ps_domain)
1180 & " data_len=" & int2str(t.data_len)
1181 & " max_optional_data=" & int2str(t.max_optional_data)
1182 & " expect_separate_sccp_cr=" & f_bool2str(t.expect_separate_sccp_cr)
1183 );
1184
1185 f_vty_set_sccp_max_optional_data(HNBGWVTY, t.max_optional_data);
1186 var ConnHdlr vc_conn;
1187 vc_conn := f_start_handler_with_pars(refers(f_tc_initial_ue),
1188 t_pars(100 + i,
1189 ps_domain := ps_domain,
1190 expect_separate_sccp_cr := t.expect_separate_sccp_cr,
1191 tx_sccp_cr_data_len := t.data_len));
1192 vc_conn.done;
1193 }
1194 }
1195
1196 /* reset */
1197 f_vty_set_sccp_max_optional_data(HNBGWVTY);
Neels Hofmeyr3a9140e2023-06-23 04:50:39 +02001198
1199 f_shutdown_helper();
Neels Hofmeyrf0b9ed12022-06-07 17:46:32 +02001200}
1201
Daniel Willmann19b8d902022-01-05 09:12:34 +01001202/* Reply to a received CRCX with an OK (or the reply configured in cpars), using the given parameters.
1203 * Return true when an OK reply was sent, false otherwise.
1204 * Count occurrence of Osmux, include Osmux parameters in the reply if necessary. */
1205function f_handle_crcx(inout MgcpParameters pars, MgcpCommand mgcp_cmd) return template MgcpResponse {
Pau Espin Pedrol264679f2023-11-29 15:52:00 +01001206 var MgwResponse conn := pars.mgw_conn_ran;
Daniel Willmann19b8d902022-01-05 09:12:34 +01001207 if (pars.got_crcx_count > 0) {
Pau Espin Pedrolb85ac2f2023-11-29 15:48:57 +01001208 conn := pars.mgw_conn_cn;
Daniel Willmann19b8d902022-01-05 09:12:34 +01001209 }
1210 pars.got_crcx_count := pars.got_crcx_count + 1;
1211
1212 var MgcpMessage mgcp_msg := {
1213 command := mgcp_cmd
1214 }
1215 var template MgcpResponse mgcp_resp;
1216 var MgcpOsmuxCID osmux_cid;
1217 var MgcpCallId call_id := f_MgcpCmd_extract_call_id(mgcp_cmd);
1218 if (ispresent(pars.mgcp_call_id)) {
1219 if (pars.mgcp_call_id != call_id) {
1220 setverdict(fail, "CRCX contained unexpected call id. Expected:", pars.mgcp_call_id, " got:", call_id);
1221 mtc.stop;
1222 }
1223 } else {
1224 pars.mgcp_call_id := call_id;
1225 }
1226
1227 /* When the endpoint contains a wildcard we keep the endpoint
1228 * identifier we have set up in pars. Otherwise we use the
1229 * endpoint name that the call agent has supplied */
1230 if (match(mgcp_cmd.line.ep, t_MGCP_EP_wildcard) == false) {
1231 pars.mgcp_ep := mgcp_cmd.line.ep;
1232 }
1233
1234 if (conn.resp == -1) {
1235 /* Reply with rror */
1236 var MgcpResponse mgcp_rsp := {
1237 line := {
1238 code := "542",
1239 trans_id := mgcp_cmd.line.trans_id,
1240 string := "FORCED_FAIL"
1241 },
1242 sdp := omit
1243
1244 }
1245 var MgcpParameter mgcp_rsp_param := {
1246 code := "Z",
1247 val := pars.mgcp_ep
1248 };
1249 mgcp_rsp.params[0] := mgcp_rsp_param;
1250 return mgcp_rsp;
1251 }
1252
1253 if (conn.resp == 0) {
1254 /* Do not reply at all */
1255 return omit;
1256 }
1257
1258 if (conn.resp != 1) {
1259 setverdict(fail, "Unexpected value for pars.mgw_conn_*.resp, expect -1, 0 or 1");
1260 mtc.stop;
1261 }
1262
1263 var SDP_Message sdp := valueof(ts_SDP(conn.mgw_rtp_ip, conn.mgw_rtp_ip,
1264 hex2str(pars.mgcp_call_id), "42",
1265 conn.mgw_rtp_port,
1266 { int2str(pars.rtp_payload_type) },
1267 { valueof(ts_SDP_rtpmap(pars.rtp_payload_type,
1268 pars.rtp_sdp_format)),
1269 valueof(ts_SDP_ptime(20)) }));
1270
1271 if (f_mgcp_contains_par(mgcp_msg, "X-OSMUX")) {
1272 if (not pars.use_osmux) {
1273 setverdict(fail, "MSC sent X-Osmux parameter in MGCP, but not expecting any Osmux");
1274 mtc.stop;
1275 }
1276 pars.got_osmux_count := pars.got_osmux_count + 1;
1277 /* we expect MSC to use wildcard here, i.e. osmux_cid == -1 */
1278 osmux_cid := f_MgcpCmd_extract_osmux_cid(mgcp_cmd);
1279 log("f_handle_crcx(): got Osmux CID: ", osmux_cid);
1280 if (osmux_cid != -1) {
1281 setverdict(fail, "MSC using unexpected CID " & int2str(osmux_cid) & " != -1");
1282 mtc.stop;
1283 }
1284
1285 osmux_cid := 0;
1286 mgcp_resp := ts_CRCX_ACK_osmux(mgcp_cmd.line.trans_id, conn.mgcp_connection_id, osmux_cid, sdp);
1287 } else {
1288 mgcp_resp := ts_CRCX_ACK(mgcp_cmd.line.trans_id, conn.mgcp_connection_id, sdp);
1289 }
1290
1291 f_mgcp_par_append(mgcp_resp.params, ts_MgcpParSpecEP(pars.mgcp_ep));
1292
1293 return mgcp_resp;
1294}
1295
Daniel Willmann3e15b7b2022-02-21 17:07:02 +01001296friend function f_create_rab(inout MgcpParameters pars) runs on ConnHdlr {
1297 f_rab_ass_req(pars);
1298 f_rab_ass_resp(pars);
1299}
1300
1301friend function f_rab_ass_req(inout MgcpParameters pars) runs on ConnHdlr {
Daniel Willmann19b8d902022-01-05 09:12:34 +01001302 var MgcpCommand mgcp_cmd;
1303 var RANAP_PDU tx;
1304 var template RAB_SetupOrModifyList rab_sml;
Daniel Willmann19b8d902022-01-05 09:12:34 +01001305 timer T := 5.0;
1306
1307 /* Send RAB Assignment Request */
1308 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));
1309 tx := valueof(ts_RANAP_RabAssReq(rab_sml));
1310 BSSAP.send(tx);
1311 T.start;
1312
1313 /* Handle MGCP CRCX */
1314 alt {
1315 [] MGCP.receive(tr_CRCX) -> value mgcp_cmd {
1316 log("CRCX1", mgcp_cmd);
1317 var template MgcpResponse mgcp_rsp := f_handle_crcx(pars, mgcp_cmd);
1318 MGCP.send(valueof(mgcp_rsp));
1319 }
1320 [] T.timeout {
1321 setverdict(fail, "Timeout waiting for MGCP");
1322 }
1323 }
Neels Hofmeyr735b6562023-03-09 02:51:28 +01001324 T.stop;
Daniel Willmann19b8d902022-01-05 09:12:34 +01001325
1326 /* Expect RAB Assignment Request with IP/port from CRCX ACK via Iuh */
Pau Espin Pedrolb85ac2f2023-11-29 15:48:57 +01001327 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 +01001328 tx := valueof(ts_RANAP_RabAssReq(rab_sml));
1329
Neels Hofmeyr735b6562023-03-09 02:51:28 +01001330 f_rua_expect(tx);
Daniel Willmann3e15b7b2022-02-21 17:07:02 +01001331}
1332
1333friend function f_rab_ass_resp(inout MgcpParameters pars) runs on ConnHdlr {
1334 var MgcpCommand mgcp_cmd;
1335 var RANAP_PDU tx;
1336 var template RAB_SetupOrModifiedList rab_smdl;
Daniel Willmann19b8d902022-01-05 09:12:34 +01001337
1338 /* Send back RAB Assignment Response via Iuh */
1339 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));
1340 tx := valueof(ts_RANAP_RabAssResp(rab_smdl));
1341 RUA.send(tx);
Daniel Willmann19b8d902022-01-05 09:12:34 +01001342
1343 interleave {
1344 /* Expect MDCX with IP/port from RAB Assignment Response */
1345 [] 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 +01001346 var HostName mgw_rtp_ip;
Pau Espin Pedrolaf746502023-11-29 16:18:28 +01001347 var boolean exp_rua_rab_reass := false;
Daniel Willmann19b8d902022-01-05 09:12:34 +01001348 log("MDCX1", mgcp_cmd);
Pau Espin Pedrol0c35a632023-11-29 16:00:35 +01001349 if (ispresent(pars.mgw_conn_ran.mgw_rtp_ip_mdcx)) {
1350 mgw_rtp_ip := pars.mgw_conn_ran.mgw_rtp_ip_mdcx;
Pau Espin Pedrolaf746502023-11-29 16:18:28 +01001351 if (pars.mgw_conn_ran.mgw_rtp_ip != pars.mgw_conn_ran.mgw_rtp_ip_mdcx) {
1352 exp_rua_rab_reass := true;
1353 }
Pau Espin Pedrol0c35a632023-11-29 16:00:35 +01001354 } else {
1355 mgw_rtp_ip := pars.mgw_conn_ran.mgw_rtp_ip;
1356 }
1357
Daniel Willmann19b8d902022-01-05 09:12:34 +01001358 /* Verify SDP of MDCX */
Pau Espin Pedrol0c35a632023-11-29 16:00:35 +01001359 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 +01001360 { 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 +01001361 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 +01001362 MGCP.send(valueof(mgcp_rsp));
Pau Espin Pedrolaf746502023-11-29 16:18:28 +01001363
1364 /* If IP address changed, we expect HNBGW to Modify the RAB through RAB-Ass-Req: */
1365 if (exp_rua_rab_reass) {
1366 var template RAB_SetupOrModifyList rab_sml;
1367 /* Expect RAB Assignment Request with IP/port from MDCX ACK via Iuh */
1368 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));
1369 tx := valueof(ts_RANAP_RabAssReq(rab_sml));
1370
1371 f_rua_expect(tx);
1372 /* Send back RAB Assignment Response via Iuh */
1373 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));
1374 tx := valueof(ts_RANAP_RabAssResp(rab_smdl));
1375 RUA.send(tx);
1376 /* This shouldn't trigger any MGCP, since nothing changed on the HNB IP side. Continue below. */
1377 }
Daniel Willmann19b8d902022-01-05 09:12:34 +01001378 }
1379 /* Handle CRCX for second leg of endpoint, answer with IP/port */
1380 [] MGCP.receive(tr_CRCX(pars.mgcp_ep, tr_SDP(pars.cn_rtp_ip, pars.cn_rtp_port))) -> value mgcp_cmd {
1381 log("CRCX2", mgcp_cmd);
1382 /* Verify SDP of CRCX */
1383 var template MgcpResponse mgcp_rsp := f_handle_crcx(pars, mgcp_cmd);
1384 MGCP.send(valueof(mgcp_rsp));
1385 }
1386 }
1387
1388 /* Expect RAB Assignment Response with IP/port from second CRCX ACK */
Pau Espin Pedrolb85ac2f2023-11-29 15:48:57 +01001389 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 +01001390 tx := valueof(ts_RANAP_RabAssResp(rab_smdl));
1391
Neels Hofmeyrdc416c92023-03-09 02:47:50 +01001392 f_bssap_expect(tx);
Daniel Willmann19b8d902022-01-05 09:12:34 +01001393}
1394
1395private altstep as_mgcp_dlcx(inout TestHdlrParams pars) runs on ConnHdlr {
1396 var MgcpCommand mgcp_cmd;
1397
1398 [] MGCP.receive(tr_DLCX(pars.mgcp_pars.mgcp_ep)) -> value mgcp_cmd {
1399 log("DLCX", mgcp_cmd);
1400 MGCP.send(ts_DLCX_ACK2(mgcp_cmd.line.trans_id));
1401 pars.mgcp_pars.got_dlcx_count := pars.mgcp_pars.got_dlcx_count + 1;
Daniel Willmann3e15b7b2022-02-21 17:07:02 +01001402 if (pars.mgcp_pars.got_dlcx_count != pars.mgcp_pars.got_crcx_count) {
Daniel Willmann19b8d902022-01-05 09:12:34 +01001403 repeat;
1404 }
1405 setverdict(pass);
1406 }
1407}
1408
1409friend function f_tc_rab_assignment(charstring id, TestHdlrParams pars) runs on ConnHdlr {
1410 var MgcpCommand mgcp_cmd;
1411 var RANAP_PDU tx;
1412 timer T := 5.0;
1413
1414 f_init_handler(pars);
1415 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
1416
1417 tx := f_build_initial_ue(g_pars);
1418 f_iuh2iu_connect(tx);
1419
1420 f_create_rab(pars.mgcp_pars);
1421
1422 /* Send Iu Release */
Harald Welte0d4a8432024-04-04 01:12:11 +02001423 tx := valueof(ts_RANAP_IuReleaseCommand(pars.rab_rel_cause));
Daniel Willmann19b8d902022-01-05 09:12:34 +01001424 f_iu2iuh(tx);
1425
1426 T.start;
1427 alt {
1428 [] as_mgcp_dlcx(pars) {}
1429 [] T.timeout {
1430 setverdict(fail, "Timeout waiting for DLCX");
1431 }
1432 }
1433
1434 tx := valueof(ts_RANAP_IuReleaseComplete());
1435 f_iuh2iu(tx);
1436}
1437
1438testcase TC_rab_assignment() runs on test_CT {
1439 var ConnHdlr vc_conn;
Pau Espin Pedrol83a49612022-09-12 21:11:05 +02001440 g_num_hnbs := 1;
Daniel Willmann19b8d902022-01-05 09:12:34 +01001441 f_init();
Daniel Willmann19b8d902022-01-05 09:12:34 +01001442
1443 vc_conn := f_start_handler_with_pars(refers(f_tc_rab_assignment), t_pars(3));
1444 vc_conn.done;
Neels Hofmeyr3a9140e2023-06-23 04:50:39 +02001445
1446 f_shutdown_helper();
Daniel Willmann19b8d902022-01-05 09:12:34 +01001447}
1448
Daniel Willmann3e15b7b2022-02-21 17:07:02 +01001449friend function f_tc_rab_assign_fail(charstring id, TestHdlrParams pars) runs on ConnHdlr {
1450 var MgcpCommand mgcp_cmd;
1451 var RANAP_PDU tx;
1452 timer T := 5.0;
1453
1454 f_init_handler(pars);
1455 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
1456
1457 tx := f_build_initial_ue(g_pars);
1458 f_iuh2iu_connect(tx);
1459
1460 f_rab_ass_req(pars.mgcp_pars);
1461
1462 /* Send RAB failed list in response */
Harald Welte0d4a8432024-04-04 01:12:11 +02001463 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 +01001464 f_iuh2iu(tx);
1465
1466 T.start;
1467 alt {
1468 [] as_mgcp_dlcx(pars) {}
1469 [] T.timeout {
1470 setverdict(fail, "Timeout waiting for DLCX");
1471 }
1472 }
1473}
1474
1475testcase TC_rab_assign_fail() runs on test_CT {
1476 var ConnHdlr vc_conn;
Pau Espin Pedrol83a49612022-09-12 21:11:05 +02001477 g_num_hnbs := 1;
Daniel Willmann3e15b7b2022-02-21 17:07:02 +01001478 f_init();
Daniel Willmann3e15b7b2022-02-21 17:07:02 +01001479
Harald Welte18188342024-04-04 01:36:56 +02001480 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 +01001481 vc_conn.done;
Neels Hofmeyr3a9140e2023-06-23 04:50:39 +02001482
1483 f_shutdown_helper();
Daniel Willmann3e15b7b2022-02-21 17:07:02 +01001484}
1485
Daniel Willmann19b8d902022-01-05 09:12:34 +01001486friend function f_tc_rab_release(charstring id, TestHdlrParams pars) runs on ConnHdlr {
1487 var MgcpCommand mgcp_cmd;
1488 var RANAP_PDU tx;
1489 timer T := 15.0;
1490
1491 f_init_handler(pars);
1492 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
1493
1494 tx := f_build_initial_ue(g_pars);
1495 f_iuh2iu_connect(tx);
1496
1497 f_create_rab(pars.mgcp_pars);
1498
1499 /* Send RAB Release */
Harald Welte0d4a8432024-04-04 01:12:11 +02001500 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 +01001501 BSSAP.send(tx);
1502
1503 T.start;
1504
1505 alt {
1506 [] as_mgcp_dlcx(pars) {}
1507 [] T.timeout {
1508 setverdict(fail, "Timeout waiting for DLCX");
1509 }
1510 }
Neels Hofmeyr735b6562023-03-09 02:51:28 +01001511 T.stop;
Daniel Willmann19b8d902022-01-05 09:12:34 +01001512
Neels Hofmeyr735b6562023-03-09 02:51:28 +01001513 f_rua_expect(tx);
Daniel Willmann19b8d902022-01-05 09:12:34 +01001514}
1515
Harald Weltef95ab2d2024-04-04 01:32:20 +02001516/* RAB release with Cause NAS/Normal (successful/orderly release) */
Daniel Willmann19b8d902022-01-05 09:12:34 +01001517testcase TC_rab_release() runs on test_CT {
1518 var ConnHdlr vc_conn;
Pau Espin Pedrol83a49612022-09-12 21:11:05 +02001519 g_num_hnbs := 1;
Daniel Willmann19b8d902022-01-05 09:12:34 +01001520 f_init();
Daniel Willmann19b8d902022-01-05 09:12:34 +01001521
1522 vc_conn := f_start_handler_with_pars(refers(f_tc_rab_release), t_pars(5));
1523 vc_conn.done;
Neels Hofmeyr3a9140e2023-06-23 04:50:39 +02001524
1525 f_shutdown_helper();
Daniel Willmann19b8d902022-01-05 09:12:34 +01001526}
1527
Harald Weltef95ab2d2024-04-04 01:32:20 +02001528/* RAB release with Cause abnormal */
1529testcase TC_rab_release_abnormal() runs on test_CT {
1530 var ConnHdlr vc_conn;
1531 g_num_hnbs := 1;
1532 f_init();
1533
1534 vc_conn := f_start_handler_with_pars(refers(f_tc_rab_release), t_pars(8, rab_rel_cause := ts_RanapCause_radio_conn_lost));
1535 vc_conn.done;
1536
1537 f_shutdown_helper();
1538}
1539
Daniel Willmann37c877f2022-02-22 16:47:06 +01001540friend function f_tc_rab_assign_mgcp_to(charstring id, TestHdlrParams pars) runs on ConnHdlr {
1541 var MgcpCommand mgcp_cmd;
1542 var RANAP_PDU tx;
1543 var template RAB_SetupOrModifyList rab_sml;
1544 timer T := 15.0;
1545
1546 T.start;
1547 f_init_handler(pars);
1548 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
1549
1550 tx := f_build_initial_ue(g_pars);
1551 f_iuh2iu_connect(tx);
1552
1553
1554 /* Send RAB Assignment Request */
1555 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));
1556 tx := valueof(ts_RANAP_RabAssReq(rab_sml));
1557 BSSAP.send(tx);
1558
1559 /* Ignore MGCP CRCX */
1560 alt {
1561 [] MGCP.receive(tr_CRCX) -> value mgcp_cmd {
1562 log("Ignoreing CRCX1", mgcp_cmd);
1563 repeat;
1564 }
1565 [] BSSAP.receive(tr_RANAP_IuReleaseRequest(?)) { }
1566 [] T.timeout {
1567 setverdict(fail, "Timeout waiting for IuRelease");
1568 }
1569 }
1570
1571 /* Send Iu Release */
Harald Welte0d4a8432024-04-04 01:12:11 +02001572 tx := valueof(ts_RANAP_IuReleaseCommand(pars.rab_rel_cause));
Daniel Willmann37c877f2022-02-22 16:47:06 +01001573 f_iu2iuh(tx);
1574
1575 tx := valueof(ts_RANAP_IuReleaseComplete());
1576 f_iuh2iu(tx);
1577}
1578
1579testcase TC_rab_assign_mgcp_to() runs on test_CT {
1580 var ConnHdlr vc_conn;
Pau Espin Pedrol83a49612022-09-12 21:11:05 +02001581 g_num_hnbs := 1;
Daniel Willmann37c877f2022-02-22 16:47:06 +01001582 f_init();
Daniel Willmann37c877f2022-02-22 16:47:06 +01001583
1584 vc_conn := f_start_handler_with_pars(refers(f_tc_rab_assign_mgcp_to), t_pars(6));
1585 vc_conn.done;
Neels Hofmeyr3a9140e2023-06-23 04:50:39 +02001586
1587 f_shutdown_helper();
Daniel Willmann37c877f2022-02-22 16:47:06 +01001588}
1589
Pau Espin Pedrolaf746502023-11-29 16:18:28 +01001590/* Test case where IuUP IP address announced by HNB and updated through MDCX
1591 * makes MGW select a new local IuUP address. HNBGW is expected to update the HNB
1592 * through RAB-Modify-Req. */
1593testcase TC_rab_assign_mgw_iuup_addr_chg() runs on test_CT {
1594 var ConnHdlr vc_conn;
1595 g_num_hnbs := 1;
1596 f_init();
1597 var template (value) TestHdlrParams pars := t_pars(3);
1598 /* Emulate change of local IuUP IP address after rx MDCX: */
1599 pars.mgcp_pars.mgw_conn_ran.mgw_rtp_ip_mdcx := "127.3.2.1";
1600
1601 vc_conn := f_start_handler_with_pars(refers(f_tc_rab_assignment), pars);
1602 vc_conn.done;
1603
1604 f_shutdown_helper();
1605}
1606
Daniel Willmann19b8d902022-01-05 09:12:34 +01001607/* Create an Iuh connection; send InitialUE; transceive data both directions */
1608friend function f_tc_ranap_bidir(charstring id, TestHdlrParams pars) runs on ConnHdlr {
1609 f_init_handler(pars);
1610
1611 /* HNB -> MSC: InitialUE */
1612 f_iuh2iu_connect(f_build_initial_ue(g_pars));
1613
1614 /* MSC <- HNB: DirectTransfer */
1615 f_iu2iuh(ts_RANAP_DirectTransfer(f_rnd_octstring(10)));
1616 /* MSC -> HNB: DirectTransfer */
1617 f_iuh2iu(ts_RANAP_DirectTransfer(f_rnd_octstring(10)));
1618
1619 /* HNB <- MSC: CommonID */
1620 f_iu2iuh(ts_RANAP_CommonId(hex2oct(pars.imsi)));
1621}
1622testcase TC_ranap_cs_bidir() runs on test_CT {
1623 var ConnHdlr vc_conn;
Pau Espin Pedrol83a49612022-09-12 21:11:05 +02001624 g_num_hnbs := 1;
Daniel Willmann19b8d902022-01-05 09:12:34 +01001625 f_init();
Daniel Willmann19b8d902022-01-05 09:12:34 +01001626
1627 vc_conn := f_start_handler_with_pars(refers(f_tc_ranap_bidir), t_pars(3));
1628 vc_conn.done;
Neels Hofmeyr3a9140e2023-06-23 04:50:39 +02001629
1630 f_shutdown_helper();
Daniel Willmann19b8d902022-01-05 09:12:34 +01001631}
1632testcase TC_ranap_ps_bidir() runs on test_CT {
1633 var ConnHdlr vc_conn;
Pau Espin Pedrol83a49612022-09-12 21:11:05 +02001634 g_num_hnbs := 1;
Daniel Willmann19b8d902022-01-05 09:12:34 +01001635 f_init();
Daniel Willmann19b8d902022-01-05 09:12:34 +01001636
1637 vc_conn := f_start_handler_with_pars(refers(f_tc_ranap_bidir), t_pars(4, true));
1638 vc_conn.done;
Neels Hofmeyr3a9140e2023-06-23 04:50:39 +02001639
1640 f_shutdown_helper();
Daniel Willmann19b8d902022-01-05 09:12:34 +01001641}
1642
1643
1644private function f_tc_ranap_mo_disconnect(charstring id, TestHdlrParams pars) runs on ConnHdlr {
1645 f_init_handler(pars);
1646
1647 /* HNB -> MSC: InitialUE */
1648 f_iuh2iu_connect(f_build_initial_ue(g_pars));
1649
1650 /* MSC <- HNB: DirectTransfer */
1651 f_iu2iuh(ts_RANAP_DirectTransfer(f_rnd_octstring(10)));
1652 /* MSC -> HNB: DirectTransfer */
1653 f_iuh2iu(ts_RANAP_DirectTransfer(f_rnd_octstring(10)));
1654
1655 /* MSC <- HNB: RUA disconnect */
1656 f_iuh2iu_disconnect(ts_RANAP_IuReleaseComplete, RUA_IEs.Cause:{misc:=processing_overload});
1657}
1658testcase TC_ranap_cs_mo_disconnect() runs on test_CT {
1659 var ConnHdlr vc_conn;
Pau Espin Pedrol83a49612022-09-12 21:11:05 +02001660 g_num_hnbs := 1;
Daniel Willmann19b8d902022-01-05 09:12:34 +01001661 f_init();
Daniel Willmann19b8d902022-01-05 09:12:34 +01001662
1663 vc_conn := f_start_handler_with_pars(refers(f_tc_ranap_mo_disconnect), t_pars(5));
1664 vc_conn.done;
Neels Hofmeyr3a9140e2023-06-23 04:50:39 +02001665
1666 f_shutdown_helper();
Daniel Willmann19b8d902022-01-05 09:12:34 +01001667}
1668testcase TC_ranap_ps_mo_disconnect() runs on test_CT {
1669 var ConnHdlr vc_conn;
Pau Espin Pedrol83a49612022-09-12 21:11:05 +02001670 g_num_hnbs := 1;
Daniel Willmann19b8d902022-01-05 09:12:34 +01001671 f_init();
Daniel Willmann19b8d902022-01-05 09:12:34 +01001672
1673 vc_conn := f_start_handler_with_pars(refers(f_tc_ranap_mo_disconnect), t_pars(6));
1674 vc_conn.done;
Neels Hofmeyr3a9140e2023-06-23 04:50:39 +02001675
1676 f_shutdown_helper();
Daniel Willmann19b8d902022-01-05 09:12:34 +01001677}
1678
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001679type record FTeid {
1680 HostName addr,
1681 OCT4 teid
1682}
1683
1684type record FTeids {
1685 FTeid local,
1686 FTeid remote
1687}
Daniel Willmann19b8d902022-01-05 09:12:34 +01001688
1689
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001690/* 'local' and 'remote' refer to the GTP information from the UPF's point of view:
1691 * HNB UPF CN
1692 * access.remote <---> access.local | core.local <---> core.remote
1693 */
1694type record GtpParameters {
1695 FTeids core,
1696 FTeids access
1697}
1698
1699/* HNB UPF CN
1700 * access.remote <---> access.local | core.local <---> core.remote
1701 * 127.0.0.4 127.0.0.3 127.0.0.2 127.0.0.1
1702 * 0x44004400 0x30303030 0x22002200 0x10101010
1703 */
1704template GtpParameters t_GtpParameters := {
1705 core := {
1706 local := {
1707 addr := "127.0.0.2",
1708 teid := '22002200'O
1709 },
1710 remote := {
1711 addr := "127.0.0.1",
1712 teid := '10101010'O
1713 }
1714 },
1715 access := {
1716 local := {
1717 addr := "127.0.0.3",
1718 teid := '30303030'O
1719 },
1720 remote := {
1721 addr := "127.0.0.4",
1722 teid := '44004400'O
1723 }
1724 }
1725}
1726
Neels Hofmeyr65499282023-04-25 02:31:51 +02001727private 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 +01001728{
1729 var PDU_PFCP rx;
Neels Hofmeyr65499282023-04-25 02:31:51 +02001730 timer T := wait_time;
Neels Hofmeyr6bbfe052023-03-09 02:51:46 +01001731 T.start;
1732 alt {
1733 [] PFCP.receive(exp_rx) -> value rx {
1734 setverdict(pass);
1735 }
1736 [] PFCP.receive(PDU_PFCP:?) {
1737 setverdict(fail, "Got an unexpected PFCP message, was waiting for ", exp_rx);
1738 mtc.stop;
1739 }
1740 [] T.timeout {
1741 setverdict(fail, "Timeout waiting for PFCP ", exp_rx);
1742 mtc.stop;
1743 }
1744 }
1745 T.stop;
1746 return rx;
1747}
1748
Neels Hofmeyrbacb74f2022-08-29 16:24:12 +02001749friend function f_tc_ps_rab_assignment_with_pfcp(charstring id, TestHdlrParams pars) runs on ConnHdlr {
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001750 var RANAP_PDU tx;
1751 var RANAP_PDU rx;
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001752
1753 f_init_handler(pars);
1754
1755 f_pfcp_register();
1756
1757 var PDU_PFCP m;
1758 var Node_ID upf_node_id := valueof(ts_PFCP_Node_ID_fqdn("\07osmocom\03org"));
1759
Neels Hofmeyr65499282023-04-25 02:31:51 +02001760 m := f_pfcp_expect(tr_PFCP_Assoc_Setup_Req(), wait_time := 15.0);
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001761 PFCP.send(ts_PFCP_Assoc_Setup_Resp(m.sequence_number, upf_node_id,
1762 ts_PFCP_Cause(REQUEST_ACCEPTED), 1234));
1763
1764 tx := f_build_initial_ue(g_pars);
1765 f_iuh2iu_connect(tx);
1766
1767 var GtpParameters gtp_pars := valueof(t_GtpParameters);
1768 var template RAB_SetupOrModifyList rab_sml;
1769
1770 /* Send RAB Assignment Request */
1771 rab_sml := ts_RAB_SML_ps(t_RAB_id(23), f_ts_RAB_TLA(gtp_pars.core.remote.addr), gtp_pars.core.remote.teid);
1772 tx := valueof(ts_RANAP_RabAssReq(rab_sml));
1773 BSSAP.send(tx);
1774
1775 /* Expect PFCP Session Establishment Request. */
Neels Hofmeyr6bbfe052023-03-09 02:51:46 +01001776 m := f_pfcp_expect(tr_PFCP_Session_Est_Req());
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001777 var F_SEID hnbgw_f_seid := m.message_body.pfcp_session_establishment_request.CP_F_SEID;
1778 var PFCP_Session_Establishment_Request serq := m.message_body.pfcp_session_establishment_request;
1779
1780 /* Acting as UPF, invent a new PFCP SEID to send to HNBGW. Respond to the Session Establishment.
1781 * The PFCP response must have the same sequence_number as the request. */
Neels Hofmeyr1e311462023-01-11 01:19:12 +01001782 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 +02001783 var template PDU_PFCP r := ts_PFCP_Session_Est_Resp(m.sequence_number, upf_node_id, hnbgw_f_seid.seid);
1784 r.message_body.pfcp_session_establishment_response := {
1785 offending_ie := omit,
1786 UP_F_SEID := up_f_seid,
1787 created_PDR_list := {
1788 ts_PFCP_Created_PDR(pdr_id := serq.create_PDR_list[0].grouped_ie.pdr_id,
1789 local_F_TEID := ts_PFCP_F_TEID_ipv4(gtp_pars.core.local.teid,
Neels Hofmeyr1e311462023-01-11 01:19:12 +01001790 f_inet_addr(gtp_pars.core.local.addr))),
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001791 ts_PFCP_Created_PDR(pdr_id := serq.create_PDR_list[1].grouped_ie.pdr_id,
1792 local_F_TEID := ts_PFCP_F_TEID_ipv4(gtp_pars.access.local.teid,
Neels Hofmeyr1e311462023-01-11 01:19:12 +01001793 f_inet_addr(gtp_pars.access.local.addr)))
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001794 },
1795 load_control_information := omit,
1796 overload_control_information := omit,
1797 node_list := omit,
1798 failed_rule_id := omit,
1799 created_traffic_endpoint_list := omit
1800 };
1801 PFCP.send(r);
1802
1803 /* Expect on Iuh: RAB Assignment Request with IP/port from PFCP Session Est Resp */
1804 rab_sml := ts_RAB_SML_ps(t_RAB_id(23), f_ts_RAB_TLA(gtp_pars.access.local.addr),
1805 gtp_pars.access.local.teid);
1806 rx := valueof(ts_RANAP_RabAssReq(rab_sml));
Neels Hofmeyr735b6562023-03-09 02:51:28 +01001807 f_rua_expect(rx);
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001808
1809 /* Send back RAB Assignment Response via Iuh */
1810 var template RAB_SetupOrModifiedList rab_smdl;
1811 rab_smdl := ts_RAB_SMdL_ps(t_RAB_id(23), f_ts_RAB_TLA(gtp_pars.access.remote.addr),
1812 gtp_pars.access.remote.teid);
1813 tx := valueof(ts_RANAP_RabAssResp(rab_smdl));
1814 RUA.send(tx);
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001815
Neels Hofmeyr6bbfe052023-03-09 02:51:46 +01001816 m := f_pfcp_expect(tr_PFCP_Session_Mod_Req(up_f_seid.seid));
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001817 r := ts_PFCP_Session_Mod_Resp(m.sequence_number, hnbgw_f_seid.seid);
1818 PFCP.send(r);
1819
1820 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 +01001821 f_bssap_expect(tr_RANAP_RabAssResp(rab_smdl));
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001822
1823 f_sleep(2.0);
Harald Welte0d4a8432024-04-04 01:12:11 +02001824 tx := valueof(ts_RANAP_IuReleaseCommand(pars.rab_rel_cause));
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001825 f_iu2iuh(tx);
1826
1827 tx := valueof(ts_RANAP_IuReleaseComplete());
1828 f_iuh2iu(tx);
1829
Neels Hofmeyr6bbfe052023-03-09 02:51:46 +01001830 m := f_pfcp_expect(tr_PFCP_Session_Del_Req(up_f_seid.seid));
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001831 PFCP.send(ts_PFCP_Session_Del_Resp(m.sequence_number, hnbgw_f_seid.seid));
1832
1833 f_sleep(2.0);
1834}
1835
Neels Hofmeyrbacb74f2022-08-29 16:24:12 +02001836testcase TC_ps_rab_assignment_with_pfcp() runs on test_CT {
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001837 var ConnHdlr vc_conn;
Pau Espin Pedrol83a49612022-09-12 21:11:05 +02001838 g_num_hnbs := 1;
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001839 f_init();
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001840 f_sleep(1.0);
1841
Neels Hofmeyrbacb74f2022-08-29 16:24:12 +02001842 vc_conn := f_start_handler_with_pars(refers(f_tc_ps_rab_assignment_with_pfcp), t_pars(7, ps_domain := true));
1843 vc_conn.done;
Neels Hofmeyr3a9140e2023-06-23 04:50:39 +02001844
1845 f_shutdown_helper();
Neels Hofmeyrbacb74f2022-08-29 16:24:12 +02001846}
1847
1848altstep as_disallow_pfcp() runs on ConnHdlr {
1849 [] PFCP.receive(PDU_PFCP:?) {
1850 setverdict(fail, "Received PFCP message, but no PFCP communication expected");
1851 mtc.stop;
1852 }
1853}
1854
1855friend function f_tc_ps_rab_assignment_without_pfcp(charstring id, TestHdlrParams pars) runs on ConnHdlr {
1856 var RANAP_PDU tx;
1857 var RANAP_PDU rx;
1858 timer T := 5.0;
1859
1860 f_init_handler(pars);
1861
1862 f_pfcp_register();
1863 activate(as_disallow_pfcp());
1864
1865 tx := f_build_initial_ue(g_pars);
1866 f_iuh2iu_connect(tx);
1867
1868 var GtpParameters gtp_pars := valueof(t_GtpParameters);
1869 var template RAB_SetupOrModifyList rab_sml;
1870
1871 /* Send RAB Assignment Request */
1872 rab_sml := ts_RAB_SML_ps(t_RAB_id(23), f_ts_RAB_TLA(gtp_pars.core.remote.addr), gtp_pars.core.remote.teid);
1873 tx := valueof(ts_RANAP_RabAssReq(rab_sml));
1874 BSSAP.send(tx);
1875
1876 /* Expect on Iuh: unmodified RAB Assignment Request */
1877 rx := valueof(ts_RANAP_RabAssReq(rab_sml));
Neels Hofmeyr735b6562023-03-09 02:51:28 +01001878 f_rua_expect(rx);
Neels Hofmeyrbacb74f2022-08-29 16:24:12 +02001879
1880 /* Send back RAB Assignment Response via Iuh */
1881 var template RAB_SetupOrModifiedList rab_smdl;
1882 rab_smdl := ts_RAB_SMdL_ps(t_RAB_id(23), f_ts_RAB_TLA(gtp_pars.access.remote.addr),
1883 gtp_pars.access.remote.teid);
1884 tx := valueof(ts_RANAP_RabAssResp(rab_smdl));
1885 RUA.send(tx);
1886
1887 /* Expect on IuPS: unmodified RAB Assignment Response */
Neels Hofmeyrdc416c92023-03-09 02:47:50 +01001888 f_bssap_expect(tr_RANAP_RabAssResp(rab_smdl));
Neels Hofmeyrbacb74f2022-08-29 16:24:12 +02001889
1890 f_sleep(2.0);
Harald Welte0d4a8432024-04-04 01:12:11 +02001891 tx := valueof(ts_RANAP_IuReleaseCommand(pars.rab_rel_cause));
Neels Hofmeyrbacb74f2022-08-29 16:24:12 +02001892 f_iu2iuh(tx);
1893
1894 tx := valueof(ts_RANAP_IuReleaseComplete());
1895 f_iuh2iu(tx);
1896
1897 f_sleep(2.0);
1898}
1899
1900testcase TC_ps_rab_assignment_without_pfcp() runs on test_CT {
1901 var ConnHdlr vc_conn;
1902 f_init();
Neels Hofmeyrbacb74f2022-08-29 16:24:12 +02001903 f_sleep(1.0);
1904
1905 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 +02001906 vc_conn.done;
Neels Hofmeyr3a9140e2023-06-23 04:50:39 +02001907
1908 f_shutdown_helper();
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001909}
Daniel Willmann19b8d902022-01-05 09:12:34 +01001910
Neels Hofmeyr7d0e6802023-04-20 20:43:55 +02001911/* Default list of counters for a 'cn' entity to test the cnpool feature. */
1912const CounterNameVals counternames_cnpool := {
1913 { "cnpool:subscr:new", 0 },
1914 { "cnpool:subscr:known", 0 },
1915 { "cnpool:subscr:reattach", 0 },
1916 { "cnpool:subscr:attach_lost", 0 },
1917 { "cnpool:subscr:paged", 0 }
1918};
1919private function f_ctrs_cn_init(boolean ps_domain, integer cn_count := 0,
1920 CounterNameVals counternames := counternames_cnpool) runs on test_CT {
1921 if (ps_domain) {
1922 g_ctr_cn_node_name := "sgsn";
1923 if (cn_count == 0) {
1924 cn_count := NUM_SGSN;
1925 }
1926 } else {
1927 g_ctr_cn_node_name := "msc";
1928 if (cn_count == 0) {
1929 cn_count := NUM_MSC;
1930 }
1931 }
1932 g_ctr_cn := f_counter_name_vals_get_n(IPA_CTRL, g_ctr_cn_node_name, cn_count, counternames);
1933 log("initial " & g_ctr_cn_node_name & " rate counters: ", g_ctr_cn);
1934}
1935
1936/* f_ctrs_cn_init();
1937 * f_do_thing(on_cn := 0);
1938 * f_do_thing(on_cn := 0);
1939 * f_do_other(on_cn := 1);
1940 * f_ctrs_cn_add(0, "thing", 2);
1941 * f_ctrs_cn_add(1, "other");
1942 * f_ctrs_cn_verify();
1943 */
1944private function f_ctrs_cn_verify() runs on test_CT {
1945 log("verifying", g_ctr_cn_node_name, " rate counters: ", g_ctr_cn);
1946 f_counter_name_vals_expect_n(IPA_CTRL, g_ctr_cn_node_name, g_ctr_cn);
1947}
1948
1949/* convenience: f_ctrs_cn_add() and f_ctrs_cn_verify() in one call.
1950 * f_ctrs_cn_init();
1951 * f_do_thing(on_cn := 0);
1952 * f_do_thing(on_cn := 0);
1953 * f_do_thing(on_cn := 0);
1954 * f_ctrs_cn_expect(0, "thing", 3);
1955 */
1956private function f_ctrs_cn_expect(integer cn_nr, charstring countername, integer val := 1) runs on test_CT {
1957 f_ctrs_cn_add(cn_nr, countername, val);
1958 f_ctrs_cn_verify();
1959}
1960
1961private function f_ctrs_cn_add(integer cn_nr, charstring countername, integer val := 1) runs on test_CT {
1962 f_counter_name_vals_list_add(g_ctr_cn, cn_nr, countername, val);
1963}
1964
1965private function f_perform_compl_l3(octetstring nas, boolean do_clear := true, boolean expect_iu_l3 := true)
1966runs on ConnHdlr {
1967 timer T := 10.0;
1968
1969 /* create an expect on the Iu side for the random NAS portion */
1970 if (g_pars.expect_separate_sccp_cr) {
1971 f_ran_register_sccp_cr_without_payload();
1972 } else {
1973 f_ran_register_exp(nas);
1974 }
1975
1976 /* send Connect via Iuh (creating a RUA connection) */
1977 var RANAP_PDU tx := f_build_initial_ue_with_nas(g_pars, nas);
1978 RUA.send(RUA_Conn_Req:{g_pars.ps_domain, tx});
1979
1980 if (expect_iu_l3) {
1981 /* Expect same message to arrive at CN */
1982 f_bssap_expect(tx);
1983 }
1984}
1985
1986private function f_tc_cnpool_compl_l3(charstring id, TestHdlrParams pars) runs on ConnHdlr {
1987 f_init_handler(pars);
1988 f_perform_compl_l3(g_pars.nas_pdu);
1989}
1990
1991private function f_TC_cnpool_compl_l3(boolean ps_domain, octetstring nas_pdu, integer cn_nr,
1992 template (omit) charstring inc_countername := omit) runs on test_CT {
1993 var ConnHdlr vc_conn;
1994 var template (value) TestHdlrParams pars := t_pars(0, ps_domain := ps_domain, cn_nr := cn_nr);
1995 pars.nas_pdu := nas_pdu;
1996 log("XXX ", pars);
1997 vc_conn := f_start_handler_with_pars(refers(f_tc_cnpool_compl_l3), pars);
1998 vc_conn.done;
1999
2000 if (not istemplatekind(inc_countername, "omit")) {
2001 f_ctrs_cn_expect(cn_nr, valueof(inc_countername));
2002 }
2003}
2004
2005function f_TC_cnpool_compl_l3_list(boolean ps_domain, ro_octetstring compl3, Osmocom_Types.ro_integer cn_nrs,
2006 charstring inc_countername) runs on test_CT {
2007 var integer n := lengthof(compl3);
2008 if (n < lengthof(cn_nrs)) {
2009 n := lengthof(cn_nrs);
2010 }
2011 for (var integer i := 0; i < n; i := i + 1) {
2012 var integer cn_nr := cn_nrs[i mod lengthof(cn_nrs)];
2013 f_TC_cnpool_compl_l3(ps_domain, compl3[i mod lengthof(compl3)], cn_nr, inc_countername);
2014 }
2015}
2016
2017type enumerated Compl3Type {
2018 /* CS */
2019 LU,
2020 CMSERV,
2021 PAGRESP,
2022 IMSIDETACH,
2023
2024 /* PS */
2025 ATTACHREQ,
2026 RAUREQ,
2027 DETREQ
2028};
2029
2030private function f_gen_one_compl_l3(Compl3Type compl3type, template (value) MobileIdentityLV mi,
2031 integer ps_nri := -1
2032 ) return octetstring
2033{
2034 /* CS */
2035 if (compl3type == LU) {
2036 return enc_PDU_ML3_MS_NW(valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(mi), '00F110'O)));
2037 }
2038 if (compl3type == CMSERV) {
2039 return enc_PDU_ML3_MS_NW(valueof(ts_CM_SERV_REQ(CM_TYPE_MO_CALL, valueof(mi))));
2040 }
2041 if (compl3type == PAGRESP) {
2042 return enc_PDU_ML3_MS_NW(valueof(ts_PAG_RESP(valueof(mi))));
2043 }
2044 if (compl3type == IMSIDETACH) {
2045 return enc_PDU_ML3_MS_NW(valueof(ts_ML3_MO_MM_IMSI_DET_Ind(valueof(mi))));
2046 }
2047
2048 /* PS */
2049 var template (omit) NetworkResourceIdentifierContainerTLV nri := omit;
2050 if (ps_nri >= 0) {
2051 nri := valueof(ts_GMM_NRI(ps_nri));
2052 }
2053
2054 if (compl3type == ATTACHREQ) {
2055 return enc_PDU_L3_MS_SGSN(valueof(ts_GMM_ATTACH_REQ(valueof(mi), f_RAI('001'H, '01'H, '2a2a'O, '17'O),
2056 nri := nri)));
2057 }
2058 if (compl3type == RAUREQ) {
2059 return enc_PDU_L3_MS_SGSN(valueof(ts_GMM_RAU_REQ(valueof(mi), GPRS_UPD_T_PERIODIC,
2060 f_RAI('001'H, '01'H, '2a2a'O, '17'O),
2061 nri := nri)));
2062 }
2063 if (compl3type == DETREQ) {
2064 return enc_PDU_L3_MS_SGSN(valueof(ts_GMM_DET_REQ_MO_mi(c_GMM_DTT_MO_GPRS, power_off := false,
2065 p_tmsi := valueof(ts_MI_TLV(mi.mobileIdentityV)))));
2066 }
2067
2068 setverdict(fail, "unknown complete layer 3 type");
2069 mtc.stop;
2070}
2071
2072type record of Compl3Type ro_Compl3Type;
2073type record of MobileIdentityLV ro_MobileIdentityLV;
2074type record of octetstring ro_octetstring;
2075
2076/* Generate a list of n Complete Layer 3 NAS PDUs,
2077 * rotating through the message kinds listed in 'types' and the mobile identities in mis.
2078 */
2079private function f_gen_compl_l3(ro_Compl3Type types, ro_MobileIdentityLV mis, integer n) return ro_octetstring
2080{
2081 var ro_octetstring res := {};
2082 for (var integer i := 0; i < n; i := i + 1) {
2083 var integer ti := i mod lengthof(types);
2084 var integer mi := i mod lengthof(mis);
2085 res[i] := f_gen_one_compl_l3(types[ti], mis[mi]);
2086 }
2087 return res;
2088}
2089
2090private function f_gen_mi_imsi(integer n) return MobileIdentityLV
2091{
2092 return valueof(ts_MI_IMSI_LV(f_gen_imsi(n)));
2093}
2094
2095private function f_gen_mi_imsis(integer n) return ro_MobileIdentityLV
2096{
2097 var ro_MobileIdentityLV mis := {};
2098 for (var integer i := 0; i < n; i := i + 1) {
2099 mis[i] := f_gen_mi_imsi(n);
2100 }
2101 return mis;
2102}
2103
2104function f_vty_set_roundrobin_next(TELNETasp_PT VTY, boolean ps_domain, integer cn_nr)
2105{
2106 var charstring msc_sgsn;
2107 if (ps_domain) {
2108 msc_sgsn := "sgsn";
2109 } else {
2110 msc_sgsn := "msc";
2111 }
2112 f_vty_transceive(VTY, "cnpool roundrobin next " & msc_sgsn & " " & int2str(cn_nr));
2113}
2114
2115private function f_gen_compl3_by_domain(boolean ps_domain, integer n, template (omit) ro_MobileIdentityLV mis := omit) return ro_octetstring{
2116 var ro_Compl3Type types;
2117 if (ps_domain) {
2118 types := { ATTACHREQ, RAUREQ, DETREQ };
2119 } else {
2120 types := { LU, CMSERV, PAGRESP, IMSIDETACH };
2121 }
2122 if (istemplatekind(mis, "omit")) {
2123 mis := f_gen_mi_imsis(n);
2124 }
2125 return f_gen_compl_l3(types, valueof(mis), n);
2126}
2127
2128/* Various Complete Layer 3 by IMSI all end up with the first MSC, because the other MSCs are not connected. */
2129testcase TC_mscpool_L3Compl_on_1_cnlink() runs on test_CT {
2130 f_TC_cnpool_L3Compl_on_1_cnlink(ps_domain := false);
2131}
2132testcase TC_sgsnpool_L3Compl_on_1_cnlink() runs on test_CT {
2133 f_TC_cnpool_L3Compl_on_1_cnlink(ps_domain := true);
2134}
2135function f_TC_cnpool_L3Compl_on_1_cnlink(boolean ps_domain) runs on test_CT {
2136
2137 f_init();
2138
2139 f_ctrs_cn_init(ps_domain := ps_domain);
2140
2141 var ro_octetstring compl3 := f_gen_compl3_by_domain(ps_domain, 4);
2142 f_TC_cnpool_compl_l3_list(ps_domain, compl3, {0, 0, 0, 0}, "cnpool:subscr:new");
2143
2144 f_shutdown_helper();
2145}
2146
2147/* Three Layer 3 Complete by IMSI are round-robin'ed across two connected MSCs */
2148testcase TC_mscpool_L3Complete_by_imsi_round_robin() runs on test_CT {
2149 f_TC_cnpool_L3Complete_by_imsi_round_robin(ps_domain := false);
2150}
2151testcase TC_sgsnpool_L3Complete_no_nri_round_robin() runs on test_CT {
2152 f_TC_cnpool_L3Complete_by_imsi_round_robin(ps_domain := true);
2153}
2154function f_TC_cnpool_L3Complete_by_imsi_round_robin(boolean ps_domain) runs on test_CT {
2155
2156 f_init(nr_msc := 2, nr_sgsn := 2);
2157 f_sleep(1.0);
2158
2159 /* Control which MSC gets chosen next by the round-robin, otherwise
2160 * would be randomly affected by which other tests ran before this. */
2161 f_vty_set_roundrobin_next(HNBGWVTY, ps_domain, 0);
2162
2163 f_ctrs_cn_init(ps_domain := ps_domain);
2164
2165 var ro_octetstring compl3 := f_gen_compl3_by_domain(ps_domain, 3);
2166
2167 f_TC_cnpool_compl_l3_list(ps_domain, compl3,
2168 /* Third Complete Layer 3 wraps back to msc 0 */
2169 cn_nrs := {0, 1, 0},
2170 inc_countername := "cnpool:subscr:new");
2171
2172 f_shutdown_helper();
2173}
2174
2175/* Three LU by TMSI are round-robin'ed across two connected MSCs, because they contain a NULL-NRI (0, 1)
2176 * (configured in osmo-hnbgw.cfg). */
2177testcase TC_mscpool_LU_by_tmsi_null_nri_0_round_robin() runs on test_CT {
2178 f_TC_cnpool_LU_by_tmsi_null_nri_N_round_robin(ps_domain := false, nri_val := 0);
2179}
2180/* 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
2181 * than that. */
2182testcase TC_mscpool_LU_by_tmsi_null_nri_1_round_robin() runs on test_CT {
2183 f_TC_cnpool_LU_by_tmsi_null_nri_N_round_robin(ps_domain := false, nri_val := 1);
2184}
2185function f_TC_cnpool_LU_by_tmsi_null_nri_N_round_robin(boolean ps_domain, integer nri_val) runs on test_CT {
2186
2187 f_init(nr_msc := 2, nr_sgsn := 2);
2188 f_sleep(1.0);
2189
2190 /* Control which MSC gets chosen next by the round-robin, otherwise
2191 * would be randomly affected by which other tests ran before this. */
2192 f_vty_set_roundrobin_next(HNBGWVTY, ps_domain, 0);
2193
2194 f_ctrs_cn_init(ps_domain := ps_domain);
2195
2196 var ro_MobileIdentityLV mis := { valueof(ts_MI_TMSI_NRI_LV(nri_val)) };
2197 var ro_octetstring compl3;
2198 if (ps_domain) {
2199 compl3 := {
2200 f_gen_one_compl_l3(ATTACHREQ, mis[0], nri_val)
2201 };
2202 } else {
2203 compl3 := f_gen_compl_l3({LU}, mis, 1);
2204 }
2205
2206 f_TC_cnpool_compl_l3_list(ps_domain, compl3,
2207 /* The third Complete Layer 3 wraps back to msc 0 */
2208 {0, 1, 0},
2209 "cnpool:subscr:reattach");
2210 f_shutdown_helper();
2211}
2212
2213/* Three Layer 3 Complete by TMSI are round-robin'ed across two connected MSCs, because they contain an NRI not
2214 * assigned to any MSC (configured in osmo-hnbgw.cfg). */
2215testcase TC_mscpool_L3Complete_by_tmsi_unassigned_nri_round_robin() runs on test_CT {
2216 f_TC_cnpool_L3Complete_by_tmsi_unassigned_nri_round_robin(ps_domain := false);
2217}
2218function f_TC_cnpool_L3Complete_by_tmsi_unassigned_nri_round_robin(boolean ps_domain) runs on test_CT {
2219
2220 f_init(nr_msc := 2, nr_sgsn := 2);
2221 f_sleep(1.0);
2222
2223 /* Control which MSC gets chosen next by the round-robin, otherwise
2224 * would be randomly affected by which other tests ran before this. */
2225 f_vty_set_roundrobin_next(HNBGWVTY, ps_domain, 0);
2226
2227 f_ctrs_cn_init(ps_domain := ps_domain);
2228
2229 /* 3 NRIs that are not assigned to any MSC */
2230 var ro_MobileIdentityLV mis := {
2231 valueof(ts_MI_TMSI_NRI_LV(1000)),
2232 valueof(ts_MI_TMSI_NRI_LV(768)),
2233 valueof(ts_MI_TMSI_NRI_LV(819))
2234 };
2235
2236 var ro_octetstring compl3 := f_gen_compl3_by_domain(ps_domain, 3, mis);
2237 f_TC_cnpool_compl_l3_list(ps_domain, compl3, { 0, 1, 0 }, "cnpool:subscr:new");
2238
2239 f_shutdown_helper();
2240}
2241
2242/* Three Layer 3 Complete by TMSI are round-robin'ed across two connected MSCs, because they contain an NRI
2243 * assigned to a CN link that is currently not connected (configured in osmo-hnbgw.cfg). */
2244testcase TC_mscpool_L3Complete_by_tmsi_valid_nri_msc_not_connected_round_robin() runs on test_CT {
2245 f_TC_cnpool_L3Complete_by_tmsi_valid_nri_msc_not_connected_round_robin(ps_domain := false);
2246}
2247function f_TC_cnpool_L3Complete_by_tmsi_valid_nri_msc_not_connected_round_robin(boolean ps_domain) runs on test_CT {
2248
2249 f_init(nr_msc := 2, nr_sgsn := 2);
2250 f_sleep(1.0);
2251
2252 /* Control which MSC gets chosen next by the round-robin, otherwise
2253 * would be randomly affected by which other tests ran before this. */
2254 f_vty_set_roundrobin_next(HNBGWVTY, ps_domain, 0);
2255
2256 f_ctrs_cn_init(ps_domain := ps_domain);
2257
2258 /* 3 NRIs that are assigned to an unconnected MSC */
2259 var ro_MobileIdentityLV mis := {
2260 valueof(ts_MI_TMSI_NRI_LV(512)),
2261 valueof(ts_MI_TMSI_NRI_LV(767)),
2262 valueof(ts_MI_TMSI_NRI_LV(750))
2263 };
2264
2265 var ro_octetstring compl3 := f_gen_compl3_by_domain(ps_domain, 3, mis);
2266
2267 f_TC_cnpool_compl_l3(ps_domain, compl3[0], cn_nr := 0);
2268 f_ctrs_cn_add(2, "cnpool:subscr:attach_lost");
2269 f_ctrs_cn_add(0, "cnpool:subscr:new");
2270 f_ctrs_cn_verify();
2271
2272 f_TC_cnpool_compl_l3(ps_domain, compl3[1], cn_nr := 1);
2273 f_ctrs_cn_add(2, "cnpool:subscr:attach_lost");
2274 f_ctrs_cn_add(1, "cnpool:subscr:new");
2275 f_ctrs_cn_verify();
2276
2277 f_TC_cnpool_compl_l3(ps_domain, compl3[2], cn_nr := 0);
2278 f_ctrs_cn_add(2, "cnpool:subscr:attach_lost");
2279 f_ctrs_cn_add(0, "cnpool:subscr:new");
2280 f_ctrs_cn_verify();
2281
2282 f_shutdown_helper();
2283}
2284
2285/* Three Layer 3 Complete by TMSI with valid NRI for the second MSC are all directed to the second MSC (configured in
2286 * osmo-hnbgw.cfg). */
2287testcase TC_mscpool_L3Complete_by_tmsi_valid_nri_1() runs on test_CT {
2288 f_TC_cnpool_L3Complete_valid_nri_1(ps_domain := false);
2289}
2290testcase TC_sgsnpool_L3Complete_valid_nri_1() runs on test_CT {
2291 f_TC_cnpool_L3Complete_valid_nri_1(ps_domain := true);
2292}
2293function f_TC_cnpool_L3Complete_valid_nri_1(boolean ps_domain) runs on test_CT {
2294
2295 f_init(nr_msc := 2, nr_sgsn := 2);
2296 f_sleep(1.0);
2297
2298 /* All TMSIs in this test point at the second MSC, set the round robin to point at the first MSC to make sure
2299 * this is not using round-robin. */
2300 f_vty_set_roundrobin_next(HNBGWVTY, ps_domain, 0);
2301
2302 f_ctrs_cn_init(ps_domain := ps_domain);
2303
2304 var ro_octetstring compl3;
2305
2306 /* 3 NRIs of the second MSC's range (256-511) */
2307 var ro_MobileIdentityLV mis := {
2308 valueof(ts_MI_TMSI_NRI_LV(256)),
2309 valueof(ts_MI_TMSI_NRI_LV(260)),
2310 valueof(ts_MI_TMSI_NRI_LV(511))
2311 };
2312 if (ps_domain) {
2313 compl3 := {
2314 f_gen_one_compl_l3(RAUREQ, mis[0], 256),
2315 f_gen_one_compl_l3(RAUREQ, mis[1], 260),
2316 f_gen_one_compl_l3(RAUREQ, mis[2], 511)
2317 };
2318 } else {
2319 compl3 := f_gen_compl3_by_domain(ps_domain, 3, mis);
2320 }
2321
2322 f_TC_cnpool_compl_l3_list(ps_domain, compl3, {1, 1, 1}, "cnpool:subscr:known");
2323
2324 f_shutdown_helper();
2325}
2326
2327/* Layer 3 Complete by TMSI with valid NRI for the third MSC are directed to the third MSC (configured in osmo-hnbgw.cfg),
2328 * while a round-robin remains unaffected by that. */
2329testcase TC_mscpool_L3Complete_by_tmsi_valid_nri_2() runs on test_CT {
2330 f_TC_cnpool_L3Complete_valid_nri_2(ps_domain := false);
2331}
2332testcase TC_sgsnpool_L3Complete_valid_nri_2() runs on test_CT {
2333 f_TC_cnpool_L3Complete_valid_nri_2(ps_domain := true);
2334}
2335function f_TC_cnpool_L3Complete_valid_nri_2(boolean ps_domain) runs on test_CT {
2336
2337 f_init(nr_msc := 3, nr_sgsn := 3);
2338 f_sleep(1.0);
2339
2340 /* All TMSIs in this test point at the third MSC, set the round robin to point at the second MSC to make sure
2341 * this is not using round-robin. */
2342 f_vty_set_roundrobin_next(HNBGWVTY, ps_domain, 1);
2343
2344 f_ctrs_cn_init(ps_domain := ps_domain);
2345
2346 var ro_octetstring compl3;
2347
2348 /* 2 NRIs of the third MSC's range (512-767) */
2349 var ro_MobileIdentityLV mis := {
2350 valueof(ts_MI_TMSI_NRI_LV(512)),
2351 valueof(ts_MI_TMSI_NRI_LV(678))
2352 };
2353 if (ps_domain) {
2354 compl3 := {
2355 f_gen_one_compl_l3(ATTACHREQ, mis[0], 512),
2356 f_gen_one_compl_l3(ATTACHREQ, mis[1], 678)
2357 };
2358 } else {
2359 compl3 := f_gen_compl3_by_domain(ps_domain, 2, mis);
2360 }
2361
2362 f_TC_cnpool_compl_l3_list(ps_domain, compl3, {2, 2}, "cnpool:subscr:known");
2363
2364 /* The above forwardings to third MSC have not affected the round robin, which still points at the second MSC */
2365 f_TC_cnpool_compl_l3_list(ps_domain, f_gen_compl3_by_domain(ps_domain, 1), {1}, "cnpool:subscr:new");
2366
2367 f_shutdown_helper();
2368}
2369
2370/* LU with a TMSI but indicating a different PLMN in its previous LAI: ignore the NRI. */
2371testcase TC_mscpool_LU_by_tmsi_from_other_PLMN() runs on test_CT {
2372 f_TC_cnpool_nri_from_other_PLMN(ps_domain := false);
2373}
2374testcase TC_sgsnpool_nri_from_other_PLMN() runs on test_CT {
2375 f_TC_cnpool_nri_from_other_PLMN(ps_domain := true);
2376}
2377function f_TC_cnpool_nri_from_other_PLMN(boolean ps_domain) runs on test_CT {
2378
2379 f_init(nr_msc := 3, nr_sgsn := 3);
2380 f_sleep(1.0);
2381
2382 /* The TMSIs in this test points at the second MSC, but since it is from a different PLMN, round-robin is used
2383 * instead, and hits msc 0. */
2384 f_vty_set_roundrobin_next(HNBGWVTY, ps_domain, 0);
2385
2386 f_ctrs_cn_init(ps_domain := ps_domain);
2387
2388 var ro_octetstring compl3;
2389
2390 var ro_MobileIdentityLV mis := {
2391 valueof(ts_MI_TMSI_NRI_LV(260)),
2392 valueof(ts_MI_TMSI_NRI_LV(555))
2393 };
2394 if (ps_domain) {
2395 compl3 := {
2396 /* An NRI of the second MSC's range (256-511), but a PLMN that doesn't match with osmo-hnbgw.cfg */
2397 enc_PDU_L3_MS_SGSN(valueof(ts_GMM_ATTACH_REQ(mis[0], f_RAI('999'H, '99'H, '2a2a'O,
2398 '17'O),
2399 nri := ts_GMM_NRI(260)
2400 ))),
2401 /* An NRI of the third MSC's range (512-767) and a matching PLMN gets directed by NRI. */
2402 f_gen_one_compl_l3(ATTACHREQ, mis[1], 555)
2403 }
2404 } else {
2405 compl3 := {
2406 /* An NRI of the second MSC's range (256-511), but a PLMN that doesn't match with osmo-hnbgw.cfg */
2407 enc_PDU_ML3_MS_NW(valueof(ts_LU_REQ(LU_Type_IMSI_Attach, mis[0], '99F999'O))),
2408 /* An NRI of the third MSC's range (512-767) and a matching PLMN gets directed by NRI. */
2409 enc_PDU_ML3_MS_NW(valueof(ts_LU_REQ(LU_Type_IMSI_Attach, mis[1], '00F110'O)))
2410 };
2411 }
2412
2413 /* Foreign NRI: roundrobin */
2414 f_TC_cnpool_compl_l3(ps_domain, compl3[0], cn_nr := 0, inc_countername := "cnpool:subscr:new");
2415
2416 /* Local NRI: matching msc */
2417 f_TC_cnpool_compl_l3(ps_domain, compl3[1], cn_nr := 2, inc_countername := "cnpool:subscr:known");
2418
2419 f_shutdown_helper();
2420}
2421
Neels Hofmeyrb1bf16d2023-06-27 02:10:04 +02002422/* Make sure that whichever MSC paged a subscriber will also get the Paging Response. Page by IMSI, which would be
2423 * round-robined to another MSC, to make sure the Paging->Response relation is stronger than the NRI->MSC mapping. */
2424friend function f_tc_mscpool_paging_imsi(charstring id, TestHdlrParams pars) runs on ConnHdlr {
2425 f_init_handler(pars);
2426
2427 var hexstring imsi := '001010000000123'H;
2428 var RANAP_IEs.CN_DomainIndicator domain_ind;
2429 if (pars.ps_domain) {
2430 domain_ind := ps_domain;
2431 } else {
2432 domain_ind := cs_domain;
2433 }
2434 var template (value) RANAP_PDU paging := ts_RANAP_Paging(domain_ind, imsi_hex2oct(imsi));
2435 BSSAP.send(ts_RANAP_UNITDATA_req(pars.sccp_addr_hnbgw, pars.sccp_addr_msc, paging));
2436 /* TODO: Expect RUA ConnectionlessTransfer Paging (on all HNB).
2437 * We could verify the Paging sent from osmo-hnbgw to RUA with some effort,
2438 * but, this test does not care whether the Paging was forwarded to RUA or not, only that osmo-hnbgw *received*
2439 * the Paging. In the CN pool decisions, osmo-hnbgw should match up Paging Response to an earlier Paging.
2440 */
2441
2442 f_sleep(1.0);
2443
2444 /* Despite the round robin pointing at the second MSC ('roundrobin next msc 1'), the earlier Paging for the same IMSI
2445 * causes this Paging Response to go to the first MSC ('msc 0'). */
2446 f_perform_compl_l3(f_gen_one_compl_l3(PAGRESP, ts_MI_IMSI_LV(imsi)));
2447 f_sleep(1.0);
2448}
2449
2450testcase TC_mscpool_paging_imsi() runs on test_CT {
2451 f_init(nr_msc := 3);
2452 f_sleep(1.0);
2453
2454 var boolean ps_domain := false;
2455
2456 /* Testing a Paging on the first MSC to get a Paging Response back to the first MSC. Set round robin to the
2457 * second MSC to make sure we're getting the Paging logic, not a coincidental round robin match. */
2458 f_vty_set_roundrobin_next(HNBGWVTY, ps_domain, 0);
2459
2460 f_ctrs_cn_init(ps_domain := ps_domain);
2461
2462 var ConnHdlr vc_conn1;
2463 var template (value) TestHdlrParams pars1 := t_pars(0, ps_domain := ps_domain, cn_nr := 0);
2464 pars1.sccp_addr_hnbgw := g_cn[valueof(pars1.cn_idx)].sccp_addr_peer;
2465 pars1.sccp_addr_msc := g_cn[valueof(pars1.cn_idx)].sccp_addr_own;
2466 vc_conn1 := f_start_handler_with_pars(refers(f_tc_mscpool_paging_imsi), pars1);
2467 vc_conn1.done;
2468 f_ctrs_cn_expect(0, "cnpool:subscr:paged");
2469 f_shutdown_helper();
2470}
2471
2472/* Make sure that whichever MSC paged a subscriber will also get the Paging Response. Page by TMSI with an NRI value
2473 * that matches a different MSC, to make sure the Paging->Response relation is stronger than the NRI->MSC mapping. */
2474friend function f_tc_mscpool_paging_tmsi(charstring id, TestHdlrParams pars) runs on ConnHdlr {
2475 f_init_handler(pars);
2476
2477 var hexstring imsi := '001010000000124'H;
2478 var integer nri_v := 300; /* <-- second MSC's NRI */
2479 var octetstring tmsi := f_gen_tmsi(suffix := 0, nri_v := nri_v);
2480
2481 var RANAP_IEs.CN_DomainIndicator domain_ind;
2482 if (pars.ps_domain) {
2483 domain_ind := ps_domain;
2484 } else {
2485 domain_ind := cs_domain;
2486 }
2487 var template (value) RANAP_PDU paging := ts_RANAP_Paging_temp_id(domain_ind, imsi_hex2oct(imsi),
2488 ts_RANAP_TemporaryUE_ID_TMSI(tmsi));
2489 BSSAP.send(ts_RANAP_UNITDATA_req(pars.sccp_addr_hnbgw, pars.sccp_addr_msc, paging));
2490 /* TODO: Expect RUA ConnectionlessTransfer Paging (on all HNB).
2491 * We could verify the Paging sent from osmo-hnbgw to RUA with some effort,
2492 * but, this test does not care whether the Paging was forwarded to RUA or not, only that osmo-hnbgw *received*
2493 * the Paging. In the CN pool decisions, osmo-hnbgw should match up Paging Response to an earlier Paging.
2494 */
2495
2496 f_sleep(1.0);
2497
2498 /* Despite the round robin pointing at the third MSC ('roundrobin next msc 2'), the earlier Paging for the same
2499 * TMSI causes this Paging Response to go to the first MSC ('msc 0'). */
2500 f_perform_compl_l3(f_gen_one_compl_l3(PAGRESP, ts_MI_TMSI_NRI_LV(nri_v)));
2501 f_sleep(1.0);
2502}
2503testcase TC_mscpool_paging_tmsi() runs on test_CT {
2504 f_init(nr_msc := 3);
2505 f_sleep(1.0);
2506
2507 var boolean ps_domain := false;
2508
2509 /* Testing a Paging on the first MSC to get a Paging Response back to the first MSC. Set round robin to the
2510 * third MSC to make sure we're getting the Paging logic, not a coincidental round robin match. */
2511 f_vty_set_roundrobin_next(HNBGWVTY, ps_domain, 0);
2512
2513 f_ctrs_cn_init(ps_domain := ps_domain);
2514
2515 var ConnHdlr vc_conn1;
2516 var template (value) TestHdlrParams pars1 := t_pars(0, ps_domain := ps_domain, cn_nr := 0);
2517 pars1.sccp_addr_hnbgw := g_cn[valueof(pars1.cn_idx)].sccp_addr_peer;
2518 pars1.sccp_addr_msc := g_cn[valueof(pars1.cn_idx)].sccp_addr_own;
2519 vc_conn1 := f_start_handler_with_pars(refers(f_tc_mscpool_paging_tmsi), pars1);
2520 vc_conn1.done;
2521 f_ctrs_cn_expect(0, "cnpool:subscr:paged");
2522 f_shutdown_helper();
2523}
2524
Neels Hofmeyr7d0e6802023-04-20 20:43:55 +02002525/* For round-robin, skip a CN link that has 'no allow-attach' set. */
2526testcase TC_mscpool_no_allow_attach_round_robin() runs on test_CT {
2527
2528 f_init(nr_msc := 3);
2529 f_sleep(1.0);
2530
2531 var boolean ps_domain := false;
2532
2533 /* Mark the second MSC as offloading, round-robin should skip this MSC now. */
2534 f_vty_cnlink_allow_attach(HNBGWVTY, ps_domain, {true, false, true});
2535
2536 /* Control which MSC gets chosen next by the round-robin, otherwise
2537 * would be randomly affected by which other tests ran before this. */
2538 f_vty_set_roundrobin_next(HNBGWVTY, ps_domain, 0);
2539
2540 f_ctrs_cn_init(ps_domain := ps_domain);
2541
2542 f_TC_cnpool_compl_l3_list(ps_domain, f_gen_compl3_by_domain(ps_domain, 3),
2543 /* msc 1 is skipped */
2544 {0, 2, 0},
2545 "cnpool:subscr:new");
2546
2547 f_shutdown_helper();
2548}
2549
2550/* An MSC that has 'no allow-attach' set should still serve subscribers that are already attached according to their
2551 * TMSI NRI. */
2552testcase TC_mscpool_no_allow_attach_valid_nri() runs on test_CT {
2553
2554 f_init(nr_msc := 3);
2555 f_sleep(1.0);
2556
2557 var boolean ps_domain := false;
2558
2559 /* Mark the second MSC as offloading, round-robin should skip this MSC now. */
2560 f_vty_cnlink_allow_attach(HNBGWVTY, ps_domain, {true, false, true});
2561
2562 /* Control which MSC gets chosen next by the round-robin, otherwise
2563 * would be randomly affected by which other tests ran before this. */
2564 f_vty_set_roundrobin_next(HNBGWVTY, ps_domain, 0);
2565
2566 f_ctrs_cn_init(ps_domain := ps_domain);
2567
2568 var ro_MobileIdentityLV mis := {
2569 valueof(ts_MI_TMSI_NRI_LV(260)),
2570 valueof(ts_MI_IMSI_LV('001010000000002'H)),
2571 valueof(ts_MI_IMSI_LV('001010000000003'H))
2572 };
2573
2574 var ro_octetstring compl3 := f_gen_compl3_by_domain(ps_domain, 3, mis);
2575
2576 /* Round robin points at msc 0, but the valid NRI directs to msc 1, even though msc 1 has 'no allow-attach'. */
2577 f_TC_cnpool_compl_l3(ps_domain, compl3[0], cn_nr := 1, inc_countername := "cnpool:subscr:known");
2578
2579 /* Normal round robin skips msc 1, because it has 'no allow-attach' */
2580 f_TC_cnpool_compl_l3(ps_domain, compl3[1], cn_nr := 0, inc_countername := "cnpool:subscr:new");
2581 f_TC_cnpool_compl_l3(ps_domain, compl3[2], cn_nr := 2, inc_countername := "cnpool:subscr:new");
2582
2583 f_shutdown_helper();
2584}
2585
2586/* When a peer point-code gets an SCCP N-PCSTATE saying it is unreachable, immediately mark the CN link as unusable. */
2587testcase TC_mscpool_sccp_n_pcstate_detaches_cnlink() runs on test_CT {
2588 f_TC_cnpool_sccp_n_pcstate_detaches_cnlink(ps_domain := false);
2589}
2590testcase TC_sgsnpool_sccp_n_pcstate_detaches_cnlink() runs on test_CT {
2591 f_TC_cnpool_sccp_n_pcstate_detaches_cnlink(ps_domain := true);
2592}
2593function f_TC_cnpool_sccp_n_pcstate_detaches_cnlink(boolean ps_domain) runs on test_CT
2594{
2595
2596 f_init(nr_msc := 2, nr_sgsn := 2);
2597 f_sleep(1.0);
2598
2599 /* Control which MSC gets chosen next by the round-robin, otherwise
2600 * would be randomly affected by which other tests ran before this. */
2601 f_vty_set_roundrobin_next(HNBGWVTY, ps_domain, 0);
2602
2603 f_ctrs_cn_init(ps_domain := ps_domain);
2604
2605 var ro_octetstring compl3 := f_gen_compl3_by_domain(ps_domain, 3);
2606
2607 f_TC_cnpool_compl_l3(ps_domain, compl3[0], cn_nr := 0, inc_countername := "cnpool:subscr:new");
2608 f_TC_cnpool_compl_l3(ps_domain, compl3[1], cn_nr := 1, inc_countername := "cnpool:subscr:new");
2609
2610 f_logp(HNBGWVTY, "disconnecting msc0");
2611 f_cn_idx_disconnect(f_cn_idx(ps_domain, 0));
2612
2613 /* Now round-robin would wrap to the first MSC, but since the first MSC is disconnected, it wraps around to the
2614 * second. */
2615 f_TC_cnpool_compl_l3(ps_domain, compl3[2], cn_nr := 1, inc_countername := "cnpool:subscr:new");
2616
2617 f_shutdown_helper();
2618}
2619
2620/* When a CN link point-code gets an SCCP N-PCSTATE saying it is now reachable, immediately trigger RESET and bring up the
2621 * MSC. */
2622testcase TC_mscpool_sccp_n_pcstate_attaches_cnlink() runs on test_CT {
2623 f_TC_cnpool_sccp_n_pcstate_attaches_cnlink(ps_domain := false);
2624}
2625testcase TC_sgsnpool_sccp_n_pcstate_attaches_cnlink() runs on test_CT {
2626 f_TC_cnpool_sccp_n_pcstate_attaches_cnlink(ps_domain := true);
2627}
2628function f_TC_cnpool_sccp_n_pcstate_attaches_cnlink(boolean ps_domain) runs on test_CT
2629{
2630 f_init(nr_msc := 1, nr_sgsn := 1);
2631 f_sleep(1.0);
2632
2633 /* Control which MSC gets chosen next by the round-robin, otherwise
2634 * would be randomly affected by which other tests ran before this. */
2635 f_vty_set_roundrobin_next(HNBGWVTY, ps_domain, 0);
2636
2637 var ro_octetstring compl3 := f_gen_compl3_by_domain(ps_domain, 3);
2638
2639 f_ctrs_cn_init(ps_domain := ps_domain);
2640
2641 /* There is only one MSC, round robin stays on msc0 */
2642 f_TC_cnpool_compl_l3(ps_domain := ps_domain, nas_pdu := compl3[0], cn_nr := 0, inc_countername := "cnpool:subscr:new");
2643 f_TC_cnpool_compl_l3(ps_domain := ps_domain, nas_pdu := compl3[1], cn_nr := 0, inc_countername := "cnpool:subscr:new");
2644
2645 f_logp(HNBGWVTY, "connecting cnlink 1");
2646 f_cn_nr_init(ps_domain, 1);
2647 f_vty_cnlink_allow_attach(HNBGWVTY, ps_domain, { true, true });
2648 f_sleep(1.0);
2649
2650 /* This time round-robin wraps to the second MSC, because it is now online. */
2651 f_TC_cnpool_compl_l3(ps_domain := ps_domain, nas_pdu := compl3[2], cn_nr := 1, inc_countername := "cnpool:subscr:new");
2652
2653 f_shutdown_helper();
2654}
2655
Neels Hofmeyrd019cc02023-06-02 16:31:23 +02002656private function f_vty_add_sccp_addr(TELNETasp_PT pt, charstring addr_name, charstring pc, integer cs7_nr := 0)
2657{
2658 f_vty_enter_config(pt);
2659 f_vty_transceive(pt, "cs7 instance 0");
2660 f_vty_transceive(pt, "sccp-address " & addr_name);
2661 f_vty_transceive(pt, "point-code " & pc);
2662 f_vty_transceive(pt, "end");
2663}
2664
2665private function f_vty_set_cnlink_addr(TELNETasp_PT pt, charstring cnlink_and_nr, charstring addr_name)
2666{
2667 f_vty_enter_config(pt);
2668 f_vty_transceive(pt, cnlink_and_nr);
2669 f_vty_transceive(pt, "remote-addr " & addr_name);
2670 f_vty_transceive(pt, "end");
2671}
2672
2673private function f_vty_apply_sccp(TELNETasp_PT pt)
2674{
2675 f_vty_enter_config(pt);
2676 f_vty_transceive(pt, "apply sccp");
2677 f_vty_transceive(pt, "end");
2678}
2679
2680template (present) RUA_Disc_Req tr_RUA_Disc_Req := {
2681 ranap := ?,
2682 cause := ?
2683};
2684
2685/* With a cnlink up, change the SCCP address, and verify that it restarts upon vty 'apply sccp' */
2686private function f_tc_apply_sccp(charstring id, TestHdlrParams pars) runs on ConnHdlr
2687{
2688 f_init_handler(pars);
2689 f_perform_compl_l3(f_gen_compl3_by_domain(pars.ps_domain, 1)[0]);
2690
2691 f_sleep(1.0);
2692 f_logp(HNBGWVTY, "Changing SCCP address, don't apply yet");
2693
2694 f_vty_add_sccp_addr(HNBGWVTY, "msc-foo", "0.42.4");
2695 f_vty_set_cnlink_addr(HNBGWVTY, "msc 0", "msc-foo");
2696
2697 /* No effect yet, link still open both ways */
2698 f_sleep(1.0);
2699 f_iuh2iu(ts_RANAP_DirectTransfer(f_rnd_octstring(10)));
2700 f_iu2iuh(ts_RANAP_DirectTransfer(f_rnd_octstring(10)));
2701
2702 f_logp(HNBGWVTY, "Apply SCCP address changes");
2703 f_vty_apply_sccp(HNBGWVTY);
2704
2705 /* We modified the SCCP configuration, expect disconnect of UE that was active on the aborted link. */
2706 RUA.receive(RUA_Disc_Ind:?);
2707 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_IND);
2708
2709 /* Would be nice to test reconnection on the other point-code, too. That would require another cnlink in
2710 * osmo-stp.cfg and module parameters... */
2711
2712 f_sleep(1.0);
2713}
2714testcase TC_apply_sccp() runs on test_CT
2715{
2716 f_init();
2717 f_sleep(1.0);
2718
2719 var ConnHdlr vc_conn;
2720 var template (value) TestHdlrParams pars := t_pars(0);
2721 vc_conn := f_start_handler_with_pars(refers(f_tc_apply_sccp), pars);
2722 vc_conn.done;
2723
2724 f_shutdown_helper();
2725}
2726
Neels Hofmeyrc3c01d32023-11-07 02:19:00 +01002727/* In the field, we encountered a "normal" RAB Assignment that concludes successfully, followed by another RAB
2728 * Assignment that has different SDU subflow parameters, and does not contain RTP information. At the time of writing,
2729 * it seems that the second RAB Assignment causes a crash. Play through this scenario. */
2730friend function f_tc_second_rab_assignment(charstring id, TestHdlrParams pars) runs on ConnHdlr {
2731 var MgcpCommand mgcp_cmd;
2732 var RANAP_PDU tx;
2733 timer T := 5.0;
2734
2735 f_init_handler(pars);
2736 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
2737
2738 tx := f_build_initial_ue(g_pars);
2739 f_iuh2iu_connect(tx);
2740
2741 f_create_rab(pars.mgcp_pars);
2742
2743 /* Now send a second RAB Assignment with different subflows and omitting transportLayerInformation. (Assuming
2744 * the first RAB Assignment's transportLayerInformation remains in use unchanged.) */
2745 var template RAB_SetupOrModifyList rab_sml;
2746 rab_sml := ts_RAB_SML2(t_RAB_id(23),
2747 ts_RabParams,
2748 user_plane_info := omit,
2749 transport_layer_info := omit);
2750 tx := valueof(ts_RANAP_RabAssReq(rab_sml));
2751 BSSAP.send(tx);
2752 T.start;
2753
2754 /* Expect this secondary RAB Assignment to go through unchanged. */
2755 f_rua_expect(tx);
2756
2757 /* I'm guessing that the RAB Assignment Response also omits transportLayerInformation, so far not known because
2758 * osmo-hnbgw crashed before we could receive the response. */
2759
2760 /* Send back RAB Assignment Response via Iuh */
2761 var template RAB_SetupOrModifiedList rab_smdl;
2762 rab_smdl := ts_RAB_SMdL_no_tla(t_RAB_id(23));
2763 tx := valueof(ts_RANAP_RabAssResp(rab_smdl));
2764 RUA.send(tx);
2765 f_bssap_expect(tx);
2766
2767 /* Send Iu Release */
Harald Welte0d4a8432024-04-04 01:12:11 +02002768 tx := valueof(ts_RANAP_IuReleaseCommand(pars.rab_rel_cause));
Neels Hofmeyrc3c01d32023-11-07 02:19:00 +01002769 f_iu2iuh(tx);
2770
2771 T.start;
2772 alt {
2773 [] as_mgcp_dlcx(pars) {}
2774 [] T.timeout {
2775 setverdict(fail, "Timeout waiting for DLCX");
2776 }
2777 }
2778
2779 tx := valueof(ts_RANAP_IuReleaseComplete());
2780 f_iuh2iu(tx);
2781}
2782
2783testcase TC_second_rab_assignment() runs on test_CT {
2784 var ConnHdlr vc_conn;
2785 g_num_hnbs := 1;
2786 f_init();
2787
2788 vc_conn := f_start_handler_with_pars(refers(f_tc_second_rab_assignment), t_pars(3));
2789 vc_conn.done;
2790
2791 f_shutdown_helper();
2792}
2793
Daniel Willmann19b8d902022-01-05 09:12:34 +01002794control {
2795 execute(TC_hnb_register());
Daniel Willmannc79679a2022-08-23 17:48:39 +02002796 execute(TC_hnb_register_duplicate());
Pau Espin Pedrolacf4f222022-09-27 14:33:40 +02002797 execute(TC_hnb_register_duplicate_reuse_sctp_assoc());
Harald Welteaf3e2162024-03-27 21:54:20 +01002798 execute(TC_ue_register());
Harald Weltef60044d2024-04-04 00:54:34 +02002799 execute(TC_ue_register_tmsi_lai());
Harald Welteaf3e2162024-03-27 21:54:20 +01002800 execute(TC_ue_register_before_hnb_register());
Daniel Willmann19b8d902022-01-05 09:12:34 +01002801 execute(TC_ranap_cs_initial_ue());
2802 execute(TC_ranap_ps_initial_ue());
Neels Hofmeyrf0b9ed12022-06-07 17:46:32 +02002803 execute(TC_ranap_cs_initial_ue_empty_cr());
2804 execute(TC_ranap_ps_initial_ue_empty_cr());
Daniel Willmann19b8d902022-01-05 09:12:34 +01002805 execute(TC_ranap_cs_bidir());
2806 execute(TC_ranap_ps_bidir());
2807 execute(TC_rab_assignment());
2808 execute(TC_rab_release());
Harald Weltef95ab2d2024-04-04 01:32:20 +02002809 execute(TC_rab_release_abnormal());
Daniel Willmann3e15b7b2022-02-21 17:07:02 +01002810 execute(TC_rab_assign_fail());
Daniel Willmann37c877f2022-02-22 16:47:06 +01002811 execute(TC_rab_assign_mgcp_to());
Pau Espin Pedrolaf746502023-11-29 16:18:28 +01002812 execute(TC_rab_assign_mgw_iuup_addr_chg());
Daniel Willmann19b8d902022-01-05 09:12:34 +01002813 execute(TC_ranap_cs_mo_disconnect());
2814 execute(TC_ranap_ps_mo_disconnect());
Neels Hofmeyrbacb74f2022-08-29 16:24:12 +02002815
2816 if (mp_enable_pfcp_tests) {
2817 execute(TC_ps_rab_assignment_with_pfcp());
2818 } else {
2819 execute(TC_ps_rab_assignment_without_pfcp());
2820 }
Pau Espin Pedrolf0b9fa02022-09-12 13:31:07 +02002821
Neels Hofmeyr7d0e6802023-04-20 20:43:55 +02002822 execute( TC_mscpool_L3Compl_on_1_cnlink() );
2823 execute( TC_mscpool_L3Complete_by_imsi_round_robin() );
2824 execute( TC_mscpool_LU_by_tmsi_null_nri_0_round_robin() );
2825 execute( TC_mscpool_LU_by_tmsi_null_nri_1_round_robin() );
2826 execute( TC_mscpool_L3Complete_by_tmsi_unassigned_nri_round_robin() );
2827 execute( TC_mscpool_L3Complete_by_tmsi_valid_nri_msc_not_connected_round_robin() );
2828 execute( TC_mscpool_L3Complete_by_tmsi_valid_nri_1() );
2829 execute( TC_mscpool_L3Complete_by_tmsi_valid_nri_2() );
2830 execute( TC_mscpool_LU_by_tmsi_from_other_PLMN() );
Neels Hofmeyrb1bf16d2023-06-27 02:10:04 +02002831 execute( TC_mscpool_paging_imsi() );
2832 execute( TC_mscpool_paging_tmsi() );
Neels Hofmeyr7d0e6802023-04-20 20:43:55 +02002833 execute( TC_mscpool_no_allow_attach_round_robin() );
2834 execute( TC_mscpool_no_allow_attach_valid_nri() );
2835 execute( TC_mscpool_sccp_n_pcstate_detaches_cnlink() );
2836 execute( TC_mscpool_sccp_n_pcstate_attaches_cnlink() );
2837
2838 execute( TC_sgsnpool_L3Compl_on_1_cnlink() );
2839 execute( TC_sgsnpool_L3Complete_no_nri_round_robin() );
2840 execute( TC_sgsnpool_L3Complete_valid_nri_1() );
2841 execute( TC_sgsnpool_L3Complete_valid_nri_2() );
2842 execute( TC_sgsnpool_nri_from_other_PLMN() );
2843 execute( TC_sgsnpool_sccp_n_pcstate_detaches_cnlink() );
2844 execute( TC_sgsnpool_sccp_n_pcstate_attaches_cnlink() );
2845
Oliver Smithaa919b42023-11-14 11:30:55 +01002846 /* Run only on nightly since it makes osmo-hnbgw <= 1.5.0 crash: OS#6253 */
2847 if (f_osmo_repo_is("nightly")) {
2848 execute(TC_second_rab_assignment());
2849 }
Neels Hofmeyrc3c01d32023-11-07 02:19:00 +01002850
Pau Espin Pedrolf0b9fa02022-09-12 13:31:07 +02002851 /* Run at the end since it makes osmo-hnbgw <= 1.3.0 crash: OS#5676 */
2852 execute(TC_hnb_reregister_reuse_sctp_assoc());
Neels Hofmeyrd019cc02023-06-02 16:31:23 +02002853
2854 /* Run at the end since it messes with the SCCP config */
2855 execute( TC_apply_sccp() );
Daniel Willmann19b8d902022-01-05 09:12:34 +01002856}
2857
2858}