blob: 808db75a96f84c25339de56e0b00865c8af095ee [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
1516testcase TC_rab_release() runs on test_CT {
1517 var ConnHdlr vc_conn;
Pau Espin Pedrol83a49612022-09-12 21:11:05 +02001518 g_num_hnbs := 1;
Daniel Willmann19b8d902022-01-05 09:12:34 +01001519 f_init();
Daniel Willmann19b8d902022-01-05 09:12:34 +01001520
1521 vc_conn := f_start_handler_with_pars(refers(f_tc_rab_release), t_pars(5));
1522 vc_conn.done;
Neels Hofmeyr3a9140e2023-06-23 04:50:39 +02001523
1524 f_shutdown_helper();
Daniel Willmann19b8d902022-01-05 09:12:34 +01001525}
1526
Daniel Willmann37c877f2022-02-22 16:47:06 +01001527friend function f_tc_rab_assign_mgcp_to(charstring id, TestHdlrParams pars) runs on ConnHdlr {
1528 var MgcpCommand mgcp_cmd;
1529 var RANAP_PDU tx;
1530 var template RAB_SetupOrModifyList rab_sml;
1531 timer T := 15.0;
1532
1533 T.start;
1534 f_init_handler(pars);
1535 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
1536
1537 tx := f_build_initial_ue(g_pars);
1538 f_iuh2iu_connect(tx);
1539
1540
1541 /* Send RAB Assignment Request */
1542 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));
1543 tx := valueof(ts_RANAP_RabAssReq(rab_sml));
1544 BSSAP.send(tx);
1545
1546 /* Ignore MGCP CRCX */
1547 alt {
1548 [] MGCP.receive(tr_CRCX) -> value mgcp_cmd {
1549 log("Ignoreing CRCX1", mgcp_cmd);
1550 repeat;
1551 }
1552 [] BSSAP.receive(tr_RANAP_IuReleaseRequest(?)) { }
1553 [] T.timeout {
1554 setverdict(fail, "Timeout waiting for IuRelease");
1555 }
1556 }
1557
1558 /* Send Iu Release */
Harald Welte0d4a8432024-04-04 01:12:11 +02001559 tx := valueof(ts_RANAP_IuReleaseCommand(pars.rab_rel_cause));
Daniel Willmann37c877f2022-02-22 16:47:06 +01001560 f_iu2iuh(tx);
1561
1562 tx := valueof(ts_RANAP_IuReleaseComplete());
1563 f_iuh2iu(tx);
1564}
1565
1566testcase TC_rab_assign_mgcp_to() runs on test_CT {
1567 var ConnHdlr vc_conn;
Pau Espin Pedrol83a49612022-09-12 21:11:05 +02001568 g_num_hnbs := 1;
Daniel Willmann37c877f2022-02-22 16:47:06 +01001569 f_init();
Daniel Willmann37c877f2022-02-22 16:47:06 +01001570
1571 vc_conn := f_start_handler_with_pars(refers(f_tc_rab_assign_mgcp_to), t_pars(6));
1572 vc_conn.done;
Neels Hofmeyr3a9140e2023-06-23 04:50:39 +02001573
1574 f_shutdown_helper();
Daniel Willmann37c877f2022-02-22 16:47:06 +01001575}
1576
Pau Espin Pedrolaf746502023-11-29 16:18:28 +01001577/* Test case where IuUP IP address announced by HNB and updated through MDCX
1578 * makes MGW select a new local IuUP address. HNBGW is expected to update the HNB
1579 * through RAB-Modify-Req. */
1580testcase TC_rab_assign_mgw_iuup_addr_chg() runs on test_CT {
1581 var ConnHdlr vc_conn;
1582 g_num_hnbs := 1;
1583 f_init();
1584 var template (value) TestHdlrParams pars := t_pars(3);
1585 /* Emulate change of local IuUP IP address after rx MDCX: */
1586 pars.mgcp_pars.mgw_conn_ran.mgw_rtp_ip_mdcx := "127.3.2.1";
1587
1588 vc_conn := f_start_handler_with_pars(refers(f_tc_rab_assignment), pars);
1589 vc_conn.done;
1590
1591 f_shutdown_helper();
1592}
1593
Daniel Willmann19b8d902022-01-05 09:12:34 +01001594/* Create an Iuh connection; send InitialUE; transceive data both directions */
1595friend function f_tc_ranap_bidir(charstring id, TestHdlrParams pars) runs on ConnHdlr {
1596 f_init_handler(pars);
1597
1598 /* HNB -> MSC: InitialUE */
1599 f_iuh2iu_connect(f_build_initial_ue(g_pars));
1600
1601 /* MSC <- HNB: DirectTransfer */
1602 f_iu2iuh(ts_RANAP_DirectTransfer(f_rnd_octstring(10)));
1603 /* MSC -> HNB: DirectTransfer */
1604 f_iuh2iu(ts_RANAP_DirectTransfer(f_rnd_octstring(10)));
1605
1606 /* HNB <- MSC: CommonID */
1607 f_iu2iuh(ts_RANAP_CommonId(hex2oct(pars.imsi)));
1608}
1609testcase TC_ranap_cs_bidir() runs on test_CT {
1610 var ConnHdlr vc_conn;
Pau Espin Pedrol83a49612022-09-12 21:11:05 +02001611 g_num_hnbs := 1;
Daniel Willmann19b8d902022-01-05 09:12:34 +01001612 f_init();
Daniel Willmann19b8d902022-01-05 09:12:34 +01001613
1614 vc_conn := f_start_handler_with_pars(refers(f_tc_ranap_bidir), t_pars(3));
1615 vc_conn.done;
Neels Hofmeyr3a9140e2023-06-23 04:50:39 +02001616
1617 f_shutdown_helper();
Daniel Willmann19b8d902022-01-05 09:12:34 +01001618}
1619testcase TC_ranap_ps_bidir() runs on test_CT {
1620 var ConnHdlr vc_conn;
Pau Espin Pedrol83a49612022-09-12 21:11:05 +02001621 g_num_hnbs := 1;
Daniel Willmann19b8d902022-01-05 09:12:34 +01001622 f_init();
Daniel Willmann19b8d902022-01-05 09:12:34 +01001623
1624 vc_conn := f_start_handler_with_pars(refers(f_tc_ranap_bidir), t_pars(4, true));
1625 vc_conn.done;
Neels Hofmeyr3a9140e2023-06-23 04:50:39 +02001626
1627 f_shutdown_helper();
Daniel Willmann19b8d902022-01-05 09:12:34 +01001628}
1629
1630
1631private function f_tc_ranap_mo_disconnect(charstring id, TestHdlrParams pars) runs on ConnHdlr {
1632 f_init_handler(pars);
1633
1634 /* HNB -> MSC: InitialUE */
1635 f_iuh2iu_connect(f_build_initial_ue(g_pars));
1636
1637 /* MSC <- HNB: DirectTransfer */
1638 f_iu2iuh(ts_RANAP_DirectTransfer(f_rnd_octstring(10)));
1639 /* MSC -> HNB: DirectTransfer */
1640 f_iuh2iu(ts_RANAP_DirectTransfer(f_rnd_octstring(10)));
1641
1642 /* MSC <- HNB: RUA disconnect */
1643 f_iuh2iu_disconnect(ts_RANAP_IuReleaseComplete, RUA_IEs.Cause:{misc:=processing_overload});
1644}
1645testcase TC_ranap_cs_mo_disconnect() runs on test_CT {
1646 var ConnHdlr vc_conn;
Pau Espin Pedrol83a49612022-09-12 21:11:05 +02001647 g_num_hnbs := 1;
Daniel Willmann19b8d902022-01-05 09:12:34 +01001648 f_init();
Daniel Willmann19b8d902022-01-05 09:12:34 +01001649
1650 vc_conn := f_start_handler_with_pars(refers(f_tc_ranap_mo_disconnect), t_pars(5));
1651 vc_conn.done;
Neels Hofmeyr3a9140e2023-06-23 04:50:39 +02001652
1653 f_shutdown_helper();
Daniel Willmann19b8d902022-01-05 09:12:34 +01001654}
1655testcase TC_ranap_ps_mo_disconnect() runs on test_CT {
1656 var ConnHdlr vc_conn;
Pau Espin Pedrol83a49612022-09-12 21:11:05 +02001657 g_num_hnbs := 1;
Daniel Willmann19b8d902022-01-05 09:12:34 +01001658 f_init();
Daniel Willmann19b8d902022-01-05 09:12:34 +01001659
1660 vc_conn := f_start_handler_with_pars(refers(f_tc_ranap_mo_disconnect), t_pars(6));
1661 vc_conn.done;
Neels Hofmeyr3a9140e2023-06-23 04:50:39 +02001662
1663 f_shutdown_helper();
Daniel Willmann19b8d902022-01-05 09:12:34 +01001664}
1665
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001666type record FTeid {
1667 HostName addr,
1668 OCT4 teid
1669}
1670
1671type record FTeids {
1672 FTeid local,
1673 FTeid remote
1674}
Daniel Willmann19b8d902022-01-05 09:12:34 +01001675
1676
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001677/* 'local' and 'remote' refer to the GTP information from the UPF's point of view:
1678 * HNB UPF CN
1679 * access.remote <---> access.local | core.local <---> core.remote
1680 */
1681type record GtpParameters {
1682 FTeids core,
1683 FTeids access
1684}
1685
1686/* HNB UPF CN
1687 * access.remote <---> access.local | core.local <---> core.remote
1688 * 127.0.0.4 127.0.0.3 127.0.0.2 127.0.0.1
1689 * 0x44004400 0x30303030 0x22002200 0x10101010
1690 */
1691template GtpParameters t_GtpParameters := {
1692 core := {
1693 local := {
1694 addr := "127.0.0.2",
1695 teid := '22002200'O
1696 },
1697 remote := {
1698 addr := "127.0.0.1",
1699 teid := '10101010'O
1700 }
1701 },
1702 access := {
1703 local := {
1704 addr := "127.0.0.3",
1705 teid := '30303030'O
1706 },
1707 remote := {
1708 addr := "127.0.0.4",
1709 teid := '44004400'O
1710 }
1711 }
1712}
1713
Neels Hofmeyr65499282023-04-25 02:31:51 +02001714private 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 +01001715{
1716 var PDU_PFCP rx;
Neels Hofmeyr65499282023-04-25 02:31:51 +02001717 timer T := wait_time;
Neels Hofmeyr6bbfe052023-03-09 02:51:46 +01001718 T.start;
1719 alt {
1720 [] PFCP.receive(exp_rx) -> value rx {
1721 setverdict(pass);
1722 }
1723 [] PFCP.receive(PDU_PFCP:?) {
1724 setverdict(fail, "Got an unexpected PFCP message, was waiting for ", exp_rx);
1725 mtc.stop;
1726 }
1727 [] T.timeout {
1728 setverdict(fail, "Timeout waiting for PFCP ", exp_rx);
1729 mtc.stop;
1730 }
1731 }
1732 T.stop;
1733 return rx;
1734}
1735
Neels Hofmeyrbacb74f2022-08-29 16:24:12 +02001736friend function f_tc_ps_rab_assignment_with_pfcp(charstring id, TestHdlrParams pars) runs on ConnHdlr {
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001737 var RANAP_PDU tx;
1738 var RANAP_PDU rx;
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001739
1740 f_init_handler(pars);
1741
1742 f_pfcp_register();
1743
1744 var PDU_PFCP m;
1745 var Node_ID upf_node_id := valueof(ts_PFCP_Node_ID_fqdn("\07osmocom\03org"));
1746
Neels Hofmeyr65499282023-04-25 02:31:51 +02001747 m := f_pfcp_expect(tr_PFCP_Assoc_Setup_Req(), wait_time := 15.0);
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001748 PFCP.send(ts_PFCP_Assoc_Setup_Resp(m.sequence_number, upf_node_id,
1749 ts_PFCP_Cause(REQUEST_ACCEPTED), 1234));
1750
1751 tx := f_build_initial_ue(g_pars);
1752 f_iuh2iu_connect(tx);
1753
1754 var GtpParameters gtp_pars := valueof(t_GtpParameters);
1755 var template RAB_SetupOrModifyList rab_sml;
1756
1757 /* Send RAB Assignment Request */
1758 rab_sml := ts_RAB_SML_ps(t_RAB_id(23), f_ts_RAB_TLA(gtp_pars.core.remote.addr), gtp_pars.core.remote.teid);
1759 tx := valueof(ts_RANAP_RabAssReq(rab_sml));
1760 BSSAP.send(tx);
1761
1762 /* Expect PFCP Session Establishment Request. */
Neels Hofmeyr6bbfe052023-03-09 02:51:46 +01001763 m := f_pfcp_expect(tr_PFCP_Session_Est_Req());
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001764 var F_SEID hnbgw_f_seid := m.message_body.pfcp_session_establishment_request.CP_F_SEID;
1765 var PFCP_Session_Establishment_Request serq := m.message_body.pfcp_session_establishment_request;
1766
1767 /* Acting as UPF, invent a new PFCP SEID to send to HNBGW. Respond to the Session Establishment.
1768 * The PFCP response must have the same sequence_number as the request. */
Neels Hofmeyr1e311462023-01-11 01:19:12 +01001769 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 +02001770 var template PDU_PFCP r := ts_PFCP_Session_Est_Resp(m.sequence_number, upf_node_id, hnbgw_f_seid.seid);
1771 r.message_body.pfcp_session_establishment_response := {
1772 offending_ie := omit,
1773 UP_F_SEID := up_f_seid,
1774 created_PDR_list := {
1775 ts_PFCP_Created_PDR(pdr_id := serq.create_PDR_list[0].grouped_ie.pdr_id,
1776 local_F_TEID := ts_PFCP_F_TEID_ipv4(gtp_pars.core.local.teid,
Neels Hofmeyr1e311462023-01-11 01:19:12 +01001777 f_inet_addr(gtp_pars.core.local.addr))),
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001778 ts_PFCP_Created_PDR(pdr_id := serq.create_PDR_list[1].grouped_ie.pdr_id,
1779 local_F_TEID := ts_PFCP_F_TEID_ipv4(gtp_pars.access.local.teid,
Neels Hofmeyr1e311462023-01-11 01:19:12 +01001780 f_inet_addr(gtp_pars.access.local.addr)))
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001781 },
1782 load_control_information := omit,
1783 overload_control_information := omit,
1784 node_list := omit,
1785 failed_rule_id := omit,
1786 created_traffic_endpoint_list := omit
1787 };
1788 PFCP.send(r);
1789
1790 /* Expect on Iuh: RAB Assignment Request with IP/port from PFCP Session Est Resp */
1791 rab_sml := ts_RAB_SML_ps(t_RAB_id(23), f_ts_RAB_TLA(gtp_pars.access.local.addr),
1792 gtp_pars.access.local.teid);
1793 rx := valueof(ts_RANAP_RabAssReq(rab_sml));
Neels Hofmeyr735b6562023-03-09 02:51:28 +01001794 f_rua_expect(rx);
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001795
1796 /* Send back RAB Assignment Response via Iuh */
1797 var template RAB_SetupOrModifiedList rab_smdl;
1798 rab_smdl := ts_RAB_SMdL_ps(t_RAB_id(23), f_ts_RAB_TLA(gtp_pars.access.remote.addr),
1799 gtp_pars.access.remote.teid);
1800 tx := valueof(ts_RANAP_RabAssResp(rab_smdl));
1801 RUA.send(tx);
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001802
Neels Hofmeyr6bbfe052023-03-09 02:51:46 +01001803 m := f_pfcp_expect(tr_PFCP_Session_Mod_Req(up_f_seid.seid));
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001804 r := ts_PFCP_Session_Mod_Resp(m.sequence_number, hnbgw_f_seid.seid);
1805 PFCP.send(r);
1806
1807 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 +01001808 f_bssap_expect(tr_RANAP_RabAssResp(rab_smdl));
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001809
1810 f_sleep(2.0);
Harald Welte0d4a8432024-04-04 01:12:11 +02001811 tx := valueof(ts_RANAP_IuReleaseCommand(pars.rab_rel_cause));
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001812 f_iu2iuh(tx);
1813
1814 tx := valueof(ts_RANAP_IuReleaseComplete());
1815 f_iuh2iu(tx);
1816
Neels Hofmeyr6bbfe052023-03-09 02:51:46 +01001817 m := f_pfcp_expect(tr_PFCP_Session_Del_Req(up_f_seid.seid));
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001818 PFCP.send(ts_PFCP_Session_Del_Resp(m.sequence_number, hnbgw_f_seid.seid));
1819
1820 f_sleep(2.0);
1821}
1822
Neels Hofmeyrbacb74f2022-08-29 16:24:12 +02001823testcase TC_ps_rab_assignment_with_pfcp() runs on test_CT {
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001824 var ConnHdlr vc_conn;
Pau Espin Pedrol83a49612022-09-12 21:11:05 +02001825 g_num_hnbs := 1;
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001826 f_init();
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001827 f_sleep(1.0);
1828
Neels Hofmeyrbacb74f2022-08-29 16:24:12 +02001829 vc_conn := f_start_handler_with_pars(refers(f_tc_ps_rab_assignment_with_pfcp), t_pars(7, ps_domain := true));
1830 vc_conn.done;
Neels Hofmeyr3a9140e2023-06-23 04:50:39 +02001831
1832 f_shutdown_helper();
Neels Hofmeyrbacb74f2022-08-29 16:24:12 +02001833}
1834
1835altstep as_disallow_pfcp() runs on ConnHdlr {
1836 [] PFCP.receive(PDU_PFCP:?) {
1837 setverdict(fail, "Received PFCP message, but no PFCP communication expected");
1838 mtc.stop;
1839 }
1840}
1841
1842friend function f_tc_ps_rab_assignment_without_pfcp(charstring id, TestHdlrParams pars) runs on ConnHdlr {
1843 var RANAP_PDU tx;
1844 var RANAP_PDU rx;
1845 timer T := 5.0;
1846
1847 f_init_handler(pars);
1848
1849 f_pfcp_register();
1850 activate(as_disallow_pfcp());
1851
1852 tx := f_build_initial_ue(g_pars);
1853 f_iuh2iu_connect(tx);
1854
1855 var GtpParameters gtp_pars := valueof(t_GtpParameters);
1856 var template RAB_SetupOrModifyList rab_sml;
1857
1858 /* Send RAB Assignment Request */
1859 rab_sml := ts_RAB_SML_ps(t_RAB_id(23), f_ts_RAB_TLA(gtp_pars.core.remote.addr), gtp_pars.core.remote.teid);
1860 tx := valueof(ts_RANAP_RabAssReq(rab_sml));
1861 BSSAP.send(tx);
1862
1863 /* Expect on Iuh: unmodified RAB Assignment Request */
1864 rx := valueof(ts_RANAP_RabAssReq(rab_sml));
Neels Hofmeyr735b6562023-03-09 02:51:28 +01001865 f_rua_expect(rx);
Neels Hofmeyrbacb74f2022-08-29 16:24:12 +02001866
1867 /* Send back RAB Assignment Response via Iuh */
1868 var template RAB_SetupOrModifiedList rab_smdl;
1869 rab_smdl := ts_RAB_SMdL_ps(t_RAB_id(23), f_ts_RAB_TLA(gtp_pars.access.remote.addr),
1870 gtp_pars.access.remote.teid);
1871 tx := valueof(ts_RANAP_RabAssResp(rab_smdl));
1872 RUA.send(tx);
1873
1874 /* Expect on IuPS: unmodified RAB Assignment Response */
Neels Hofmeyrdc416c92023-03-09 02:47:50 +01001875 f_bssap_expect(tr_RANAP_RabAssResp(rab_smdl));
Neels Hofmeyrbacb74f2022-08-29 16:24:12 +02001876
1877 f_sleep(2.0);
Harald Welte0d4a8432024-04-04 01:12:11 +02001878 tx := valueof(ts_RANAP_IuReleaseCommand(pars.rab_rel_cause));
Neels Hofmeyrbacb74f2022-08-29 16:24:12 +02001879 f_iu2iuh(tx);
1880
1881 tx := valueof(ts_RANAP_IuReleaseComplete());
1882 f_iuh2iu(tx);
1883
1884 f_sleep(2.0);
1885}
1886
1887testcase TC_ps_rab_assignment_without_pfcp() runs on test_CT {
1888 var ConnHdlr vc_conn;
1889 f_init();
Neels Hofmeyrbacb74f2022-08-29 16:24:12 +02001890 f_sleep(1.0);
1891
1892 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 +02001893 vc_conn.done;
Neels Hofmeyr3a9140e2023-06-23 04:50:39 +02001894
1895 f_shutdown_helper();
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001896}
Daniel Willmann19b8d902022-01-05 09:12:34 +01001897
Neels Hofmeyr7d0e6802023-04-20 20:43:55 +02001898/* Default list of counters for a 'cn' entity to test the cnpool feature. */
1899const CounterNameVals counternames_cnpool := {
1900 { "cnpool:subscr:new", 0 },
1901 { "cnpool:subscr:known", 0 },
1902 { "cnpool:subscr:reattach", 0 },
1903 { "cnpool:subscr:attach_lost", 0 },
1904 { "cnpool:subscr:paged", 0 }
1905};
1906private function f_ctrs_cn_init(boolean ps_domain, integer cn_count := 0,
1907 CounterNameVals counternames := counternames_cnpool) runs on test_CT {
1908 if (ps_domain) {
1909 g_ctr_cn_node_name := "sgsn";
1910 if (cn_count == 0) {
1911 cn_count := NUM_SGSN;
1912 }
1913 } else {
1914 g_ctr_cn_node_name := "msc";
1915 if (cn_count == 0) {
1916 cn_count := NUM_MSC;
1917 }
1918 }
1919 g_ctr_cn := f_counter_name_vals_get_n(IPA_CTRL, g_ctr_cn_node_name, cn_count, counternames);
1920 log("initial " & g_ctr_cn_node_name & " rate counters: ", g_ctr_cn);
1921}
1922
1923/* f_ctrs_cn_init();
1924 * f_do_thing(on_cn := 0);
1925 * f_do_thing(on_cn := 0);
1926 * f_do_other(on_cn := 1);
1927 * f_ctrs_cn_add(0, "thing", 2);
1928 * f_ctrs_cn_add(1, "other");
1929 * f_ctrs_cn_verify();
1930 */
1931private function f_ctrs_cn_verify() runs on test_CT {
1932 log("verifying", g_ctr_cn_node_name, " rate counters: ", g_ctr_cn);
1933 f_counter_name_vals_expect_n(IPA_CTRL, g_ctr_cn_node_name, g_ctr_cn);
1934}
1935
1936/* convenience: f_ctrs_cn_add() and f_ctrs_cn_verify() in one call.
1937 * f_ctrs_cn_init();
1938 * f_do_thing(on_cn := 0);
1939 * f_do_thing(on_cn := 0);
1940 * f_do_thing(on_cn := 0);
1941 * f_ctrs_cn_expect(0, "thing", 3);
1942 */
1943private function f_ctrs_cn_expect(integer cn_nr, charstring countername, integer val := 1) runs on test_CT {
1944 f_ctrs_cn_add(cn_nr, countername, val);
1945 f_ctrs_cn_verify();
1946}
1947
1948private function f_ctrs_cn_add(integer cn_nr, charstring countername, integer val := 1) runs on test_CT {
1949 f_counter_name_vals_list_add(g_ctr_cn, cn_nr, countername, val);
1950}
1951
1952private function f_perform_compl_l3(octetstring nas, boolean do_clear := true, boolean expect_iu_l3 := true)
1953runs on ConnHdlr {
1954 timer T := 10.0;
1955
1956 /* create an expect on the Iu side for the random NAS portion */
1957 if (g_pars.expect_separate_sccp_cr) {
1958 f_ran_register_sccp_cr_without_payload();
1959 } else {
1960 f_ran_register_exp(nas);
1961 }
1962
1963 /* send Connect via Iuh (creating a RUA connection) */
1964 var RANAP_PDU tx := f_build_initial_ue_with_nas(g_pars, nas);
1965 RUA.send(RUA_Conn_Req:{g_pars.ps_domain, tx});
1966
1967 if (expect_iu_l3) {
1968 /* Expect same message to arrive at CN */
1969 f_bssap_expect(tx);
1970 }
1971}
1972
1973private function f_tc_cnpool_compl_l3(charstring id, TestHdlrParams pars) runs on ConnHdlr {
1974 f_init_handler(pars);
1975 f_perform_compl_l3(g_pars.nas_pdu);
1976}
1977
1978private function f_TC_cnpool_compl_l3(boolean ps_domain, octetstring nas_pdu, integer cn_nr,
1979 template (omit) charstring inc_countername := omit) runs on test_CT {
1980 var ConnHdlr vc_conn;
1981 var template (value) TestHdlrParams pars := t_pars(0, ps_domain := ps_domain, cn_nr := cn_nr);
1982 pars.nas_pdu := nas_pdu;
1983 log("XXX ", pars);
1984 vc_conn := f_start_handler_with_pars(refers(f_tc_cnpool_compl_l3), pars);
1985 vc_conn.done;
1986
1987 if (not istemplatekind(inc_countername, "omit")) {
1988 f_ctrs_cn_expect(cn_nr, valueof(inc_countername));
1989 }
1990}
1991
1992function f_TC_cnpool_compl_l3_list(boolean ps_domain, ro_octetstring compl3, Osmocom_Types.ro_integer cn_nrs,
1993 charstring inc_countername) runs on test_CT {
1994 var integer n := lengthof(compl3);
1995 if (n < lengthof(cn_nrs)) {
1996 n := lengthof(cn_nrs);
1997 }
1998 for (var integer i := 0; i < n; i := i + 1) {
1999 var integer cn_nr := cn_nrs[i mod lengthof(cn_nrs)];
2000 f_TC_cnpool_compl_l3(ps_domain, compl3[i mod lengthof(compl3)], cn_nr, inc_countername);
2001 }
2002}
2003
2004type enumerated Compl3Type {
2005 /* CS */
2006 LU,
2007 CMSERV,
2008 PAGRESP,
2009 IMSIDETACH,
2010
2011 /* PS */
2012 ATTACHREQ,
2013 RAUREQ,
2014 DETREQ
2015};
2016
2017private function f_gen_one_compl_l3(Compl3Type compl3type, template (value) MobileIdentityLV mi,
2018 integer ps_nri := -1
2019 ) return octetstring
2020{
2021 /* CS */
2022 if (compl3type == LU) {
2023 return enc_PDU_ML3_MS_NW(valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(mi), '00F110'O)));
2024 }
2025 if (compl3type == CMSERV) {
2026 return enc_PDU_ML3_MS_NW(valueof(ts_CM_SERV_REQ(CM_TYPE_MO_CALL, valueof(mi))));
2027 }
2028 if (compl3type == PAGRESP) {
2029 return enc_PDU_ML3_MS_NW(valueof(ts_PAG_RESP(valueof(mi))));
2030 }
2031 if (compl3type == IMSIDETACH) {
2032 return enc_PDU_ML3_MS_NW(valueof(ts_ML3_MO_MM_IMSI_DET_Ind(valueof(mi))));
2033 }
2034
2035 /* PS */
2036 var template (omit) NetworkResourceIdentifierContainerTLV nri := omit;
2037 if (ps_nri >= 0) {
2038 nri := valueof(ts_GMM_NRI(ps_nri));
2039 }
2040
2041 if (compl3type == ATTACHREQ) {
2042 return enc_PDU_L3_MS_SGSN(valueof(ts_GMM_ATTACH_REQ(valueof(mi), f_RAI('001'H, '01'H, '2a2a'O, '17'O),
2043 nri := nri)));
2044 }
2045 if (compl3type == RAUREQ) {
2046 return enc_PDU_L3_MS_SGSN(valueof(ts_GMM_RAU_REQ(valueof(mi), GPRS_UPD_T_PERIODIC,
2047 f_RAI('001'H, '01'H, '2a2a'O, '17'O),
2048 nri := nri)));
2049 }
2050 if (compl3type == DETREQ) {
2051 return enc_PDU_L3_MS_SGSN(valueof(ts_GMM_DET_REQ_MO_mi(c_GMM_DTT_MO_GPRS, power_off := false,
2052 p_tmsi := valueof(ts_MI_TLV(mi.mobileIdentityV)))));
2053 }
2054
2055 setverdict(fail, "unknown complete layer 3 type");
2056 mtc.stop;
2057}
2058
2059type record of Compl3Type ro_Compl3Type;
2060type record of MobileIdentityLV ro_MobileIdentityLV;
2061type record of octetstring ro_octetstring;
2062
2063/* Generate a list of n Complete Layer 3 NAS PDUs,
2064 * rotating through the message kinds listed in 'types' and the mobile identities in mis.
2065 */
2066private function f_gen_compl_l3(ro_Compl3Type types, ro_MobileIdentityLV mis, integer n) return ro_octetstring
2067{
2068 var ro_octetstring res := {};
2069 for (var integer i := 0; i < n; i := i + 1) {
2070 var integer ti := i mod lengthof(types);
2071 var integer mi := i mod lengthof(mis);
2072 res[i] := f_gen_one_compl_l3(types[ti], mis[mi]);
2073 }
2074 return res;
2075}
2076
2077private function f_gen_mi_imsi(integer n) return MobileIdentityLV
2078{
2079 return valueof(ts_MI_IMSI_LV(f_gen_imsi(n)));
2080}
2081
2082private function f_gen_mi_imsis(integer n) return ro_MobileIdentityLV
2083{
2084 var ro_MobileIdentityLV mis := {};
2085 for (var integer i := 0; i < n; i := i + 1) {
2086 mis[i] := f_gen_mi_imsi(n);
2087 }
2088 return mis;
2089}
2090
2091function f_vty_set_roundrobin_next(TELNETasp_PT VTY, boolean ps_domain, integer cn_nr)
2092{
2093 var charstring msc_sgsn;
2094 if (ps_domain) {
2095 msc_sgsn := "sgsn";
2096 } else {
2097 msc_sgsn := "msc";
2098 }
2099 f_vty_transceive(VTY, "cnpool roundrobin next " & msc_sgsn & " " & int2str(cn_nr));
2100}
2101
2102private function f_gen_compl3_by_domain(boolean ps_domain, integer n, template (omit) ro_MobileIdentityLV mis := omit) return ro_octetstring{
2103 var ro_Compl3Type types;
2104 if (ps_domain) {
2105 types := { ATTACHREQ, RAUREQ, DETREQ };
2106 } else {
2107 types := { LU, CMSERV, PAGRESP, IMSIDETACH };
2108 }
2109 if (istemplatekind(mis, "omit")) {
2110 mis := f_gen_mi_imsis(n);
2111 }
2112 return f_gen_compl_l3(types, valueof(mis), n);
2113}
2114
2115/* Various Complete Layer 3 by IMSI all end up with the first MSC, because the other MSCs are not connected. */
2116testcase TC_mscpool_L3Compl_on_1_cnlink() runs on test_CT {
2117 f_TC_cnpool_L3Compl_on_1_cnlink(ps_domain := false);
2118}
2119testcase TC_sgsnpool_L3Compl_on_1_cnlink() runs on test_CT {
2120 f_TC_cnpool_L3Compl_on_1_cnlink(ps_domain := true);
2121}
2122function f_TC_cnpool_L3Compl_on_1_cnlink(boolean ps_domain) runs on test_CT {
2123
2124 f_init();
2125
2126 f_ctrs_cn_init(ps_domain := ps_domain);
2127
2128 var ro_octetstring compl3 := f_gen_compl3_by_domain(ps_domain, 4);
2129 f_TC_cnpool_compl_l3_list(ps_domain, compl3, {0, 0, 0, 0}, "cnpool:subscr:new");
2130
2131 f_shutdown_helper();
2132}
2133
2134/* Three Layer 3 Complete by IMSI are round-robin'ed across two connected MSCs */
2135testcase TC_mscpool_L3Complete_by_imsi_round_robin() runs on test_CT {
2136 f_TC_cnpool_L3Complete_by_imsi_round_robin(ps_domain := false);
2137}
2138testcase TC_sgsnpool_L3Complete_no_nri_round_robin() runs on test_CT {
2139 f_TC_cnpool_L3Complete_by_imsi_round_robin(ps_domain := true);
2140}
2141function f_TC_cnpool_L3Complete_by_imsi_round_robin(boolean ps_domain) runs on test_CT {
2142
2143 f_init(nr_msc := 2, nr_sgsn := 2);
2144 f_sleep(1.0);
2145
2146 /* Control which MSC gets chosen next by the round-robin, otherwise
2147 * would be randomly affected by which other tests ran before this. */
2148 f_vty_set_roundrobin_next(HNBGWVTY, ps_domain, 0);
2149
2150 f_ctrs_cn_init(ps_domain := ps_domain);
2151
2152 var ro_octetstring compl3 := f_gen_compl3_by_domain(ps_domain, 3);
2153
2154 f_TC_cnpool_compl_l3_list(ps_domain, compl3,
2155 /* Third Complete Layer 3 wraps back to msc 0 */
2156 cn_nrs := {0, 1, 0},
2157 inc_countername := "cnpool:subscr:new");
2158
2159 f_shutdown_helper();
2160}
2161
2162/* Three LU by TMSI are round-robin'ed across two connected MSCs, because they contain a NULL-NRI (0, 1)
2163 * (configured in osmo-hnbgw.cfg). */
2164testcase TC_mscpool_LU_by_tmsi_null_nri_0_round_robin() runs on test_CT {
2165 f_TC_cnpool_LU_by_tmsi_null_nri_N_round_robin(ps_domain := false, nri_val := 0);
2166}
2167/* 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
2168 * than that. */
2169testcase TC_mscpool_LU_by_tmsi_null_nri_1_round_robin() runs on test_CT {
2170 f_TC_cnpool_LU_by_tmsi_null_nri_N_round_robin(ps_domain := false, nri_val := 1);
2171}
2172function f_TC_cnpool_LU_by_tmsi_null_nri_N_round_robin(boolean ps_domain, integer nri_val) runs on test_CT {
2173
2174 f_init(nr_msc := 2, nr_sgsn := 2);
2175 f_sleep(1.0);
2176
2177 /* Control which MSC gets chosen next by the round-robin, otherwise
2178 * would be randomly affected by which other tests ran before this. */
2179 f_vty_set_roundrobin_next(HNBGWVTY, ps_domain, 0);
2180
2181 f_ctrs_cn_init(ps_domain := ps_domain);
2182
2183 var ro_MobileIdentityLV mis := { valueof(ts_MI_TMSI_NRI_LV(nri_val)) };
2184 var ro_octetstring compl3;
2185 if (ps_domain) {
2186 compl3 := {
2187 f_gen_one_compl_l3(ATTACHREQ, mis[0], nri_val)
2188 };
2189 } else {
2190 compl3 := f_gen_compl_l3({LU}, mis, 1);
2191 }
2192
2193 f_TC_cnpool_compl_l3_list(ps_domain, compl3,
2194 /* The third Complete Layer 3 wraps back to msc 0 */
2195 {0, 1, 0},
2196 "cnpool:subscr:reattach");
2197 f_shutdown_helper();
2198}
2199
2200/* Three Layer 3 Complete by TMSI are round-robin'ed across two connected MSCs, because they contain an NRI not
2201 * assigned to any MSC (configured in osmo-hnbgw.cfg). */
2202testcase TC_mscpool_L3Complete_by_tmsi_unassigned_nri_round_robin() runs on test_CT {
2203 f_TC_cnpool_L3Complete_by_tmsi_unassigned_nri_round_robin(ps_domain := false);
2204}
2205function f_TC_cnpool_L3Complete_by_tmsi_unassigned_nri_round_robin(boolean ps_domain) runs on test_CT {
2206
2207 f_init(nr_msc := 2, nr_sgsn := 2);
2208 f_sleep(1.0);
2209
2210 /* Control which MSC gets chosen next by the round-robin, otherwise
2211 * would be randomly affected by which other tests ran before this. */
2212 f_vty_set_roundrobin_next(HNBGWVTY, ps_domain, 0);
2213
2214 f_ctrs_cn_init(ps_domain := ps_domain);
2215
2216 /* 3 NRIs that are not assigned to any MSC */
2217 var ro_MobileIdentityLV mis := {
2218 valueof(ts_MI_TMSI_NRI_LV(1000)),
2219 valueof(ts_MI_TMSI_NRI_LV(768)),
2220 valueof(ts_MI_TMSI_NRI_LV(819))
2221 };
2222
2223 var ro_octetstring compl3 := f_gen_compl3_by_domain(ps_domain, 3, mis);
2224 f_TC_cnpool_compl_l3_list(ps_domain, compl3, { 0, 1, 0 }, "cnpool:subscr:new");
2225
2226 f_shutdown_helper();
2227}
2228
2229/* Three Layer 3 Complete by TMSI are round-robin'ed across two connected MSCs, because they contain an NRI
2230 * assigned to a CN link that is currently not connected (configured in osmo-hnbgw.cfg). */
2231testcase TC_mscpool_L3Complete_by_tmsi_valid_nri_msc_not_connected_round_robin() runs on test_CT {
2232 f_TC_cnpool_L3Complete_by_tmsi_valid_nri_msc_not_connected_round_robin(ps_domain := false);
2233}
2234function f_TC_cnpool_L3Complete_by_tmsi_valid_nri_msc_not_connected_round_robin(boolean ps_domain) runs on test_CT {
2235
2236 f_init(nr_msc := 2, nr_sgsn := 2);
2237 f_sleep(1.0);
2238
2239 /* Control which MSC gets chosen next by the round-robin, otherwise
2240 * would be randomly affected by which other tests ran before this. */
2241 f_vty_set_roundrobin_next(HNBGWVTY, ps_domain, 0);
2242
2243 f_ctrs_cn_init(ps_domain := ps_domain);
2244
2245 /* 3 NRIs that are assigned to an unconnected MSC */
2246 var ro_MobileIdentityLV mis := {
2247 valueof(ts_MI_TMSI_NRI_LV(512)),
2248 valueof(ts_MI_TMSI_NRI_LV(767)),
2249 valueof(ts_MI_TMSI_NRI_LV(750))
2250 };
2251
2252 var ro_octetstring compl3 := f_gen_compl3_by_domain(ps_domain, 3, mis);
2253
2254 f_TC_cnpool_compl_l3(ps_domain, compl3[0], cn_nr := 0);
2255 f_ctrs_cn_add(2, "cnpool:subscr:attach_lost");
2256 f_ctrs_cn_add(0, "cnpool:subscr:new");
2257 f_ctrs_cn_verify();
2258
2259 f_TC_cnpool_compl_l3(ps_domain, compl3[1], cn_nr := 1);
2260 f_ctrs_cn_add(2, "cnpool:subscr:attach_lost");
2261 f_ctrs_cn_add(1, "cnpool:subscr:new");
2262 f_ctrs_cn_verify();
2263
2264 f_TC_cnpool_compl_l3(ps_domain, compl3[2], cn_nr := 0);
2265 f_ctrs_cn_add(2, "cnpool:subscr:attach_lost");
2266 f_ctrs_cn_add(0, "cnpool:subscr:new");
2267 f_ctrs_cn_verify();
2268
2269 f_shutdown_helper();
2270}
2271
2272/* Three Layer 3 Complete by TMSI with valid NRI for the second MSC are all directed to the second MSC (configured in
2273 * osmo-hnbgw.cfg). */
2274testcase TC_mscpool_L3Complete_by_tmsi_valid_nri_1() runs on test_CT {
2275 f_TC_cnpool_L3Complete_valid_nri_1(ps_domain := false);
2276}
2277testcase TC_sgsnpool_L3Complete_valid_nri_1() runs on test_CT {
2278 f_TC_cnpool_L3Complete_valid_nri_1(ps_domain := true);
2279}
2280function f_TC_cnpool_L3Complete_valid_nri_1(boolean ps_domain) runs on test_CT {
2281
2282 f_init(nr_msc := 2, nr_sgsn := 2);
2283 f_sleep(1.0);
2284
2285 /* All TMSIs in this test point at the second MSC, set the round robin to point at the first MSC to make sure
2286 * this is not using round-robin. */
2287 f_vty_set_roundrobin_next(HNBGWVTY, ps_domain, 0);
2288
2289 f_ctrs_cn_init(ps_domain := ps_domain);
2290
2291 var ro_octetstring compl3;
2292
2293 /* 3 NRIs of the second MSC's range (256-511) */
2294 var ro_MobileIdentityLV mis := {
2295 valueof(ts_MI_TMSI_NRI_LV(256)),
2296 valueof(ts_MI_TMSI_NRI_LV(260)),
2297 valueof(ts_MI_TMSI_NRI_LV(511))
2298 };
2299 if (ps_domain) {
2300 compl3 := {
2301 f_gen_one_compl_l3(RAUREQ, mis[0], 256),
2302 f_gen_one_compl_l3(RAUREQ, mis[1], 260),
2303 f_gen_one_compl_l3(RAUREQ, mis[2], 511)
2304 };
2305 } else {
2306 compl3 := f_gen_compl3_by_domain(ps_domain, 3, mis);
2307 }
2308
2309 f_TC_cnpool_compl_l3_list(ps_domain, compl3, {1, 1, 1}, "cnpool:subscr:known");
2310
2311 f_shutdown_helper();
2312}
2313
2314/* Layer 3 Complete by TMSI with valid NRI for the third MSC are directed to the third MSC (configured in osmo-hnbgw.cfg),
2315 * while a round-robin remains unaffected by that. */
2316testcase TC_mscpool_L3Complete_by_tmsi_valid_nri_2() runs on test_CT {
2317 f_TC_cnpool_L3Complete_valid_nri_2(ps_domain := false);
2318}
2319testcase TC_sgsnpool_L3Complete_valid_nri_2() runs on test_CT {
2320 f_TC_cnpool_L3Complete_valid_nri_2(ps_domain := true);
2321}
2322function f_TC_cnpool_L3Complete_valid_nri_2(boolean ps_domain) runs on test_CT {
2323
2324 f_init(nr_msc := 3, nr_sgsn := 3);
2325 f_sleep(1.0);
2326
2327 /* All TMSIs in this test point at the third MSC, set the round robin to point at the second MSC to make sure
2328 * this is not using round-robin. */
2329 f_vty_set_roundrobin_next(HNBGWVTY, ps_domain, 1);
2330
2331 f_ctrs_cn_init(ps_domain := ps_domain);
2332
2333 var ro_octetstring compl3;
2334
2335 /* 2 NRIs of the third MSC's range (512-767) */
2336 var ro_MobileIdentityLV mis := {
2337 valueof(ts_MI_TMSI_NRI_LV(512)),
2338 valueof(ts_MI_TMSI_NRI_LV(678))
2339 };
2340 if (ps_domain) {
2341 compl3 := {
2342 f_gen_one_compl_l3(ATTACHREQ, mis[0], 512),
2343 f_gen_one_compl_l3(ATTACHREQ, mis[1], 678)
2344 };
2345 } else {
2346 compl3 := f_gen_compl3_by_domain(ps_domain, 2, mis);
2347 }
2348
2349 f_TC_cnpool_compl_l3_list(ps_domain, compl3, {2, 2}, "cnpool:subscr:known");
2350
2351 /* The above forwardings to third MSC have not affected the round robin, which still points at the second MSC */
2352 f_TC_cnpool_compl_l3_list(ps_domain, f_gen_compl3_by_domain(ps_domain, 1), {1}, "cnpool:subscr:new");
2353
2354 f_shutdown_helper();
2355}
2356
2357/* LU with a TMSI but indicating a different PLMN in its previous LAI: ignore the NRI. */
2358testcase TC_mscpool_LU_by_tmsi_from_other_PLMN() runs on test_CT {
2359 f_TC_cnpool_nri_from_other_PLMN(ps_domain := false);
2360}
2361testcase TC_sgsnpool_nri_from_other_PLMN() runs on test_CT {
2362 f_TC_cnpool_nri_from_other_PLMN(ps_domain := true);
2363}
2364function f_TC_cnpool_nri_from_other_PLMN(boolean ps_domain) runs on test_CT {
2365
2366 f_init(nr_msc := 3, nr_sgsn := 3);
2367 f_sleep(1.0);
2368
2369 /* The TMSIs in this test points at the second MSC, but since it is from a different PLMN, round-robin is used
2370 * instead, and hits msc 0. */
2371 f_vty_set_roundrobin_next(HNBGWVTY, ps_domain, 0);
2372
2373 f_ctrs_cn_init(ps_domain := ps_domain);
2374
2375 var ro_octetstring compl3;
2376
2377 var ro_MobileIdentityLV mis := {
2378 valueof(ts_MI_TMSI_NRI_LV(260)),
2379 valueof(ts_MI_TMSI_NRI_LV(555))
2380 };
2381 if (ps_domain) {
2382 compl3 := {
2383 /* An NRI of the second MSC's range (256-511), but a PLMN that doesn't match with osmo-hnbgw.cfg */
2384 enc_PDU_L3_MS_SGSN(valueof(ts_GMM_ATTACH_REQ(mis[0], f_RAI('999'H, '99'H, '2a2a'O,
2385 '17'O),
2386 nri := ts_GMM_NRI(260)
2387 ))),
2388 /* An NRI of the third MSC's range (512-767) and a matching PLMN gets directed by NRI. */
2389 f_gen_one_compl_l3(ATTACHREQ, mis[1], 555)
2390 }
2391 } else {
2392 compl3 := {
2393 /* An NRI of the second MSC's range (256-511), but a PLMN that doesn't match with osmo-hnbgw.cfg */
2394 enc_PDU_ML3_MS_NW(valueof(ts_LU_REQ(LU_Type_IMSI_Attach, mis[0], '99F999'O))),
2395 /* An NRI of the third MSC's range (512-767) and a matching PLMN gets directed by NRI. */
2396 enc_PDU_ML3_MS_NW(valueof(ts_LU_REQ(LU_Type_IMSI_Attach, mis[1], '00F110'O)))
2397 };
2398 }
2399
2400 /* Foreign NRI: roundrobin */
2401 f_TC_cnpool_compl_l3(ps_domain, compl3[0], cn_nr := 0, inc_countername := "cnpool:subscr:new");
2402
2403 /* Local NRI: matching msc */
2404 f_TC_cnpool_compl_l3(ps_domain, compl3[1], cn_nr := 2, inc_countername := "cnpool:subscr:known");
2405
2406 f_shutdown_helper();
2407}
2408
Neels Hofmeyrb1bf16d2023-06-27 02:10:04 +02002409/* Make sure that whichever MSC paged a subscriber will also get the Paging Response. Page by IMSI, which would be
2410 * round-robined to another MSC, to make sure the Paging->Response relation is stronger than the NRI->MSC mapping. */
2411friend function f_tc_mscpool_paging_imsi(charstring id, TestHdlrParams pars) runs on ConnHdlr {
2412 f_init_handler(pars);
2413
2414 var hexstring imsi := '001010000000123'H;
2415 var RANAP_IEs.CN_DomainIndicator domain_ind;
2416 if (pars.ps_domain) {
2417 domain_ind := ps_domain;
2418 } else {
2419 domain_ind := cs_domain;
2420 }
2421 var template (value) RANAP_PDU paging := ts_RANAP_Paging(domain_ind, imsi_hex2oct(imsi));
2422 BSSAP.send(ts_RANAP_UNITDATA_req(pars.sccp_addr_hnbgw, pars.sccp_addr_msc, paging));
2423 /* TODO: Expect RUA ConnectionlessTransfer Paging (on all HNB).
2424 * We could verify the Paging sent from osmo-hnbgw to RUA with some effort,
2425 * but, this test does not care whether the Paging was forwarded to RUA or not, only that osmo-hnbgw *received*
2426 * the Paging. In the CN pool decisions, osmo-hnbgw should match up Paging Response to an earlier Paging.
2427 */
2428
2429 f_sleep(1.0);
2430
2431 /* Despite the round robin pointing at the second MSC ('roundrobin next msc 1'), the earlier Paging for the same IMSI
2432 * causes this Paging Response to go to the first MSC ('msc 0'). */
2433 f_perform_compl_l3(f_gen_one_compl_l3(PAGRESP, ts_MI_IMSI_LV(imsi)));
2434 f_sleep(1.0);
2435}
2436
2437testcase TC_mscpool_paging_imsi() runs on test_CT {
2438 f_init(nr_msc := 3);
2439 f_sleep(1.0);
2440
2441 var boolean ps_domain := false;
2442
2443 /* Testing a Paging on the first MSC to get a Paging Response back to the first MSC. Set round robin to the
2444 * second MSC to make sure we're getting the Paging logic, not a coincidental round robin match. */
2445 f_vty_set_roundrobin_next(HNBGWVTY, ps_domain, 0);
2446
2447 f_ctrs_cn_init(ps_domain := ps_domain);
2448
2449 var ConnHdlr vc_conn1;
2450 var template (value) TestHdlrParams pars1 := t_pars(0, ps_domain := ps_domain, cn_nr := 0);
2451 pars1.sccp_addr_hnbgw := g_cn[valueof(pars1.cn_idx)].sccp_addr_peer;
2452 pars1.sccp_addr_msc := g_cn[valueof(pars1.cn_idx)].sccp_addr_own;
2453 vc_conn1 := f_start_handler_with_pars(refers(f_tc_mscpool_paging_imsi), pars1);
2454 vc_conn1.done;
2455 f_ctrs_cn_expect(0, "cnpool:subscr:paged");
2456 f_shutdown_helper();
2457}
2458
2459/* Make sure that whichever MSC paged a subscriber will also get the Paging Response. Page by TMSI with an NRI value
2460 * that matches a different MSC, to make sure the Paging->Response relation is stronger than the NRI->MSC mapping. */
2461friend function f_tc_mscpool_paging_tmsi(charstring id, TestHdlrParams pars) runs on ConnHdlr {
2462 f_init_handler(pars);
2463
2464 var hexstring imsi := '001010000000124'H;
2465 var integer nri_v := 300; /* <-- second MSC's NRI */
2466 var octetstring tmsi := f_gen_tmsi(suffix := 0, nri_v := nri_v);
2467
2468 var RANAP_IEs.CN_DomainIndicator domain_ind;
2469 if (pars.ps_domain) {
2470 domain_ind := ps_domain;
2471 } else {
2472 domain_ind := cs_domain;
2473 }
2474 var template (value) RANAP_PDU paging := ts_RANAP_Paging_temp_id(domain_ind, imsi_hex2oct(imsi),
2475 ts_RANAP_TemporaryUE_ID_TMSI(tmsi));
2476 BSSAP.send(ts_RANAP_UNITDATA_req(pars.sccp_addr_hnbgw, pars.sccp_addr_msc, paging));
2477 /* TODO: Expect RUA ConnectionlessTransfer Paging (on all HNB).
2478 * We could verify the Paging sent from osmo-hnbgw to RUA with some effort,
2479 * but, this test does not care whether the Paging was forwarded to RUA or not, only that osmo-hnbgw *received*
2480 * the Paging. In the CN pool decisions, osmo-hnbgw should match up Paging Response to an earlier Paging.
2481 */
2482
2483 f_sleep(1.0);
2484
2485 /* Despite the round robin pointing at the third MSC ('roundrobin next msc 2'), the earlier Paging for the same
2486 * TMSI causes this Paging Response to go to the first MSC ('msc 0'). */
2487 f_perform_compl_l3(f_gen_one_compl_l3(PAGRESP, ts_MI_TMSI_NRI_LV(nri_v)));
2488 f_sleep(1.0);
2489}
2490testcase TC_mscpool_paging_tmsi() runs on test_CT {
2491 f_init(nr_msc := 3);
2492 f_sleep(1.0);
2493
2494 var boolean ps_domain := false;
2495
2496 /* Testing a Paging on the first MSC to get a Paging Response back to the first MSC. Set round robin to the
2497 * third MSC to make sure we're getting the Paging logic, not a coincidental round robin match. */
2498 f_vty_set_roundrobin_next(HNBGWVTY, ps_domain, 0);
2499
2500 f_ctrs_cn_init(ps_domain := ps_domain);
2501
2502 var ConnHdlr vc_conn1;
2503 var template (value) TestHdlrParams pars1 := t_pars(0, ps_domain := ps_domain, cn_nr := 0);
2504 pars1.sccp_addr_hnbgw := g_cn[valueof(pars1.cn_idx)].sccp_addr_peer;
2505 pars1.sccp_addr_msc := g_cn[valueof(pars1.cn_idx)].sccp_addr_own;
2506 vc_conn1 := f_start_handler_with_pars(refers(f_tc_mscpool_paging_tmsi), pars1);
2507 vc_conn1.done;
2508 f_ctrs_cn_expect(0, "cnpool:subscr:paged");
2509 f_shutdown_helper();
2510}
2511
Neels Hofmeyr7d0e6802023-04-20 20:43:55 +02002512/* For round-robin, skip a CN link that has 'no allow-attach' set. */
2513testcase TC_mscpool_no_allow_attach_round_robin() runs on test_CT {
2514
2515 f_init(nr_msc := 3);
2516 f_sleep(1.0);
2517
2518 var boolean ps_domain := false;
2519
2520 /* Mark the second MSC as offloading, round-robin should skip this MSC now. */
2521 f_vty_cnlink_allow_attach(HNBGWVTY, ps_domain, {true, false, true});
2522
2523 /* Control which MSC gets chosen next by the round-robin, otherwise
2524 * would be randomly affected by which other tests ran before this. */
2525 f_vty_set_roundrobin_next(HNBGWVTY, ps_domain, 0);
2526
2527 f_ctrs_cn_init(ps_domain := ps_domain);
2528
2529 f_TC_cnpool_compl_l3_list(ps_domain, f_gen_compl3_by_domain(ps_domain, 3),
2530 /* msc 1 is skipped */
2531 {0, 2, 0},
2532 "cnpool:subscr:new");
2533
2534 f_shutdown_helper();
2535}
2536
2537/* An MSC that has 'no allow-attach' set should still serve subscribers that are already attached according to their
2538 * TMSI NRI. */
2539testcase TC_mscpool_no_allow_attach_valid_nri() runs on test_CT {
2540
2541 f_init(nr_msc := 3);
2542 f_sleep(1.0);
2543
2544 var boolean ps_domain := false;
2545
2546 /* Mark the second MSC as offloading, round-robin should skip this MSC now. */
2547 f_vty_cnlink_allow_attach(HNBGWVTY, ps_domain, {true, false, true});
2548
2549 /* Control which MSC gets chosen next by the round-robin, otherwise
2550 * would be randomly affected by which other tests ran before this. */
2551 f_vty_set_roundrobin_next(HNBGWVTY, ps_domain, 0);
2552
2553 f_ctrs_cn_init(ps_domain := ps_domain);
2554
2555 var ro_MobileIdentityLV mis := {
2556 valueof(ts_MI_TMSI_NRI_LV(260)),
2557 valueof(ts_MI_IMSI_LV('001010000000002'H)),
2558 valueof(ts_MI_IMSI_LV('001010000000003'H))
2559 };
2560
2561 var ro_octetstring compl3 := f_gen_compl3_by_domain(ps_domain, 3, mis);
2562
2563 /* Round robin points at msc 0, but the valid NRI directs to msc 1, even though msc 1 has 'no allow-attach'. */
2564 f_TC_cnpool_compl_l3(ps_domain, compl3[0], cn_nr := 1, inc_countername := "cnpool:subscr:known");
2565
2566 /* Normal round robin skips msc 1, because it has 'no allow-attach' */
2567 f_TC_cnpool_compl_l3(ps_domain, compl3[1], cn_nr := 0, inc_countername := "cnpool:subscr:new");
2568 f_TC_cnpool_compl_l3(ps_domain, compl3[2], cn_nr := 2, inc_countername := "cnpool:subscr:new");
2569
2570 f_shutdown_helper();
2571}
2572
2573/* When a peer point-code gets an SCCP N-PCSTATE saying it is unreachable, immediately mark the CN link as unusable. */
2574testcase TC_mscpool_sccp_n_pcstate_detaches_cnlink() runs on test_CT {
2575 f_TC_cnpool_sccp_n_pcstate_detaches_cnlink(ps_domain := false);
2576}
2577testcase TC_sgsnpool_sccp_n_pcstate_detaches_cnlink() runs on test_CT {
2578 f_TC_cnpool_sccp_n_pcstate_detaches_cnlink(ps_domain := true);
2579}
2580function f_TC_cnpool_sccp_n_pcstate_detaches_cnlink(boolean ps_domain) runs on test_CT
2581{
2582
2583 f_init(nr_msc := 2, nr_sgsn := 2);
2584 f_sleep(1.0);
2585
2586 /* Control which MSC gets chosen next by the round-robin, otherwise
2587 * would be randomly affected by which other tests ran before this. */
2588 f_vty_set_roundrobin_next(HNBGWVTY, ps_domain, 0);
2589
2590 f_ctrs_cn_init(ps_domain := ps_domain);
2591
2592 var ro_octetstring compl3 := f_gen_compl3_by_domain(ps_domain, 3);
2593
2594 f_TC_cnpool_compl_l3(ps_domain, compl3[0], cn_nr := 0, inc_countername := "cnpool:subscr:new");
2595 f_TC_cnpool_compl_l3(ps_domain, compl3[1], cn_nr := 1, inc_countername := "cnpool:subscr:new");
2596
2597 f_logp(HNBGWVTY, "disconnecting msc0");
2598 f_cn_idx_disconnect(f_cn_idx(ps_domain, 0));
2599
2600 /* Now round-robin would wrap to the first MSC, but since the first MSC is disconnected, it wraps around to the
2601 * second. */
2602 f_TC_cnpool_compl_l3(ps_domain, compl3[2], cn_nr := 1, inc_countername := "cnpool:subscr:new");
2603
2604 f_shutdown_helper();
2605}
2606
2607/* When a CN link point-code gets an SCCP N-PCSTATE saying it is now reachable, immediately trigger RESET and bring up the
2608 * MSC. */
2609testcase TC_mscpool_sccp_n_pcstate_attaches_cnlink() runs on test_CT {
2610 f_TC_cnpool_sccp_n_pcstate_attaches_cnlink(ps_domain := false);
2611}
2612testcase TC_sgsnpool_sccp_n_pcstate_attaches_cnlink() runs on test_CT {
2613 f_TC_cnpool_sccp_n_pcstate_attaches_cnlink(ps_domain := true);
2614}
2615function f_TC_cnpool_sccp_n_pcstate_attaches_cnlink(boolean ps_domain) runs on test_CT
2616{
2617 f_init(nr_msc := 1, nr_sgsn := 1);
2618 f_sleep(1.0);
2619
2620 /* Control which MSC gets chosen next by the round-robin, otherwise
2621 * would be randomly affected by which other tests ran before this. */
2622 f_vty_set_roundrobin_next(HNBGWVTY, ps_domain, 0);
2623
2624 var ro_octetstring compl3 := f_gen_compl3_by_domain(ps_domain, 3);
2625
2626 f_ctrs_cn_init(ps_domain := ps_domain);
2627
2628 /* There is only one MSC, round robin stays on msc0 */
2629 f_TC_cnpool_compl_l3(ps_domain := ps_domain, nas_pdu := compl3[0], cn_nr := 0, inc_countername := "cnpool:subscr:new");
2630 f_TC_cnpool_compl_l3(ps_domain := ps_domain, nas_pdu := compl3[1], cn_nr := 0, inc_countername := "cnpool:subscr:new");
2631
2632 f_logp(HNBGWVTY, "connecting cnlink 1");
2633 f_cn_nr_init(ps_domain, 1);
2634 f_vty_cnlink_allow_attach(HNBGWVTY, ps_domain, { true, true });
2635 f_sleep(1.0);
2636
2637 /* This time round-robin wraps to the second MSC, because it is now online. */
2638 f_TC_cnpool_compl_l3(ps_domain := ps_domain, nas_pdu := compl3[2], cn_nr := 1, inc_countername := "cnpool:subscr:new");
2639
2640 f_shutdown_helper();
2641}
2642
Neels Hofmeyrd019cc02023-06-02 16:31:23 +02002643private function f_vty_add_sccp_addr(TELNETasp_PT pt, charstring addr_name, charstring pc, integer cs7_nr := 0)
2644{
2645 f_vty_enter_config(pt);
2646 f_vty_transceive(pt, "cs7 instance 0");
2647 f_vty_transceive(pt, "sccp-address " & addr_name);
2648 f_vty_transceive(pt, "point-code " & pc);
2649 f_vty_transceive(pt, "end");
2650}
2651
2652private function f_vty_set_cnlink_addr(TELNETasp_PT pt, charstring cnlink_and_nr, charstring addr_name)
2653{
2654 f_vty_enter_config(pt);
2655 f_vty_transceive(pt, cnlink_and_nr);
2656 f_vty_transceive(pt, "remote-addr " & addr_name);
2657 f_vty_transceive(pt, "end");
2658}
2659
2660private function f_vty_apply_sccp(TELNETasp_PT pt)
2661{
2662 f_vty_enter_config(pt);
2663 f_vty_transceive(pt, "apply sccp");
2664 f_vty_transceive(pt, "end");
2665}
2666
2667template (present) RUA_Disc_Req tr_RUA_Disc_Req := {
2668 ranap := ?,
2669 cause := ?
2670};
2671
2672/* With a cnlink up, change the SCCP address, and verify that it restarts upon vty 'apply sccp' */
2673private function f_tc_apply_sccp(charstring id, TestHdlrParams pars) runs on ConnHdlr
2674{
2675 f_init_handler(pars);
2676 f_perform_compl_l3(f_gen_compl3_by_domain(pars.ps_domain, 1)[0]);
2677
2678 f_sleep(1.0);
2679 f_logp(HNBGWVTY, "Changing SCCP address, don't apply yet");
2680
2681 f_vty_add_sccp_addr(HNBGWVTY, "msc-foo", "0.42.4");
2682 f_vty_set_cnlink_addr(HNBGWVTY, "msc 0", "msc-foo");
2683
2684 /* No effect yet, link still open both ways */
2685 f_sleep(1.0);
2686 f_iuh2iu(ts_RANAP_DirectTransfer(f_rnd_octstring(10)));
2687 f_iu2iuh(ts_RANAP_DirectTransfer(f_rnd_octstring(10)));
2688
2689 f_logp(HNBGWVTY, "Apply SCCP address changes");
2690 f_vty_apply_sccp(HNBGWVTY);
2691
2692 /* We modified the SCCP configuration, expect disconnect of UE that was active on the aborted link. */
2693 RUA.receive(RUA_Disc_Ind:?);
2694 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_IND);
2695
2696 /* Would be nice to test reconnection on the other point-code, too. That would require another cnlink in
2697 * osmo-stp.cfg and module parameters... */
2698
2699 f_sleep(1.0);
2700}
2701testcase TC_apply_sccp() runs on test_CT
2702{
2703 f_init();
2704 f_sleep(1.0);
2705
2706 var ConnHdlr vc_conn;
2707 var template (value) TestHdlrParams pars := t_pars(0);
2708 vc_conn := f_start_handler_with_pars(refers(f_tc_apply_sccp), pars);
2709 vc_conn.done;
2710
2711 f_shutdown_helper();
2712}
2713
Neels Hofmeyrc3c01d32023-11-07 02:19:00 +01002714/* In the field, we encountered a "normal" RAB Assignment that concludes successfully, followed by another RAB
2715 * Assignment that has different SDU subflow parameters, and does not contain RTP information. At the time of writing,
2716 * it seems that the second RAB Assignment causes a crash. Play through this scenario. */
2717friend function f_tc_second_rab_assignment(charstring id, TestHdlrParams pars) runs on ConnHdlr {
2718 var MgcpCommand mgcp_cmd;
2719 var RANAP_PDU tx;
2720 timer T := 5.0;
2721
2722 f_init_handler(pars);
2723 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
2724
2725 tx := f_build_initial_ue(g_pars);
2726 f_iuh2iu_connect(tx);
2727
2728 f_create_rab(pars.mgcp_pars);
2729
2730 /* Now send a second RAB Assignment with different subflows and omitting transportLayerInformation. (Assuming
2731 * the first RAB Assignment's transportLayerInformation remains in use unchanged.) */
2732 var template RAB_SetupOrModifyList rab_sml;
2733 rab_sml := ts_RAB_SML2(t_RAB_id(23),
2734 ts_RabParams,
2735 user_plane_info := omit,
2736 transport_layer_info := omit);
2737 tx := valueof(ts_RANAP_RabAssReq(rab_sml));
2738 BSSAP.send(tx);
2739 T.start;
2740
2741 /* Expect this secondary RAB Assignment to go through unchanged. */
2742 f_rua_expect(tx);
2743
2744 /* I'm guessing that the RAB Assignment Response also omits transportLayerInformation, so far not known because
2745 * osmo-hnbgw crashed before we could receive the response. */
2746
2747 /* Send back RAB Assignment Response via Iuh */
2748 var template RAB_SetupOrModifiedList rab_smdl;
2749 rab_smdl := ts_RAB_SMdL_no_tla(t_RAB_id(23));
2750 tx := valueof(ts_RANAP_RabAssResp(rab_smdl));
2751 RUA.send(tx);
2752 f_bssap_expect(tx);
2753
2754 /* Send Iu Release */
Harald Welte0d4a8432024-04-04 01:12:11 +02002755 tx := valueof(ts_RANAP_IuReleaseCommand(pars.rab_rel_cause));
Neels Hofmeyrc3c01d32023-11-07 02:19:00 +01002756 f_iu2iuh(tx);
2757
2758 T.start;
2759 alt {
2760 [] as_mgcp_dlcx(pars) {}
2761 [] T.timeout {
2762 setverdict(fail, "Timeout waiting for DLCX");
2763 }
2764 }
2765
2766 tx := valueof(ts_RANAP_IuReleaseComplete());
2767 f_iuh2iu(tx);
2768}
2769
2770testcase TC_second_rab_assignment() runs on test_CT {
2771 var ConnHdlr vc_conn;
2772 g_num_hnbs := 1;
2773 f_init();
2774
2775 vc_conn := f_start_handler_with_pars(refers(f_tc_second_rab_assignment), t_pars(3));
2776 vc_conn.done;
2777
2778 f_shutdown_helper();
2779}
2780
Daniel Willmann19b8d902022-01-05 09:12:34 +01002781control {
2782 execute(TC_hnb_register());
Daniel Willmannc79679a2022-08-23 17:48:39 +02002783 execute(TC_hnb_register_duplicate());
Pau Espin Pedrolacf4f222022-09-27 14:33:40 +02002784 execute(TC_hnb_register_duplicate_reuse_sctp_assoc());
Harald Welteaf3e2162024-03-27 21:54:20 +01002785 execute(TC_ue_register());
Harald Weltef60044d2024-04-04 00:54:34 +02002786 execute(TC_ue_register_tmsi_lai());
Harald Welteaf3e2162024-03-27 21:54:20 +01002787 execute(TC_ue_register_before_hnb_register());
Daniel Willmann19b8d902022-01-05 09:12:34 +01002788 execute(TC_ranap_cs_initial_ue());
2789 execute(TC_ranap_ps_initial_ue());
Neels Hofmeyrf0b9ed12022-06-07 17:46:32 +02002790 execute(TC_ranap_cs_initial_ue_empty_cr());
2791 execute(TC_ranap_ps_initial_ue_empty_cr());
Daniel Willmann19b8d902022-01-05 09:12:34 +01002792 execute(TC_ranap_cs_bidir());
2793 execute(TC_ranap_ps_bidir());
2794 execute(TC_rab_assignment());
2795 execute(TC_rab_release());
Daniel Willmann3e15b7b2022-02-21 17:07:02 +01002796 execute(TC_rab_assign_fail());
Daniel Willmann37c877f2022-02-22 16:47:06 +01002797 execute(TC_rab_assign_mgcp_to());
Pau Espin Pedrolaf746502023-11-29 16:18:28 +01002798 execute(TC_rab_assign_mgw_iuup_addr_chg());
Daniel Willmann19b8d902022-01-05 09:12:34 +01002799 execute(TC_ranap_cs_mo_disconnect());
2800 execute(TC_ranap_ps_mo_disconnect());
Neels Hofmeyrbacb74f2022-08-29 16:24:12 +02002801
2802 if (mp_enable_pfcp_tests) {
2803 execute(TC_ps_rab_assignment_with_pfcp());
2804 } else {
2805 execute(TC_ps_rab_assignment_without_pfcp());
2806 }
Pau Espin Pedrolf0b9fa02022-09-12 13:31:07 +02002807
Neels Hofmeyr7d0e6802023-04-20 20:43:55 +02002808 execute( TC_mscpool_L3Compl_on_1_cnlink() );
2809 execute( TC_mscpool_L3Complete_by_imsi_round_robin() );
2810 execute( TC_mscpool_LU_by_tmsi_null_nri_0_round_robin() );
2811 execute( TC_mscpool_LU_by_tmsi_null_nri_1_round_robin() );
2812 execute( TC_mscpool_L3Complete_by_tmsi_unassigned_nri_round_robin() );
2813 execute( TC_mscpool_L3Complete_by_tmsi_valid_nri_msc_not_connected_round_robin() );
2814 execute( TC_mscpool_L3Complete_by_tmsi_valid_nri_1() );
2815 execute( TC_mscpool_L3Complete_by_tmsi_valid_nri_2() );
2816 execute( TC_mscpool_LU_by_tmsi_from_other_PLMN() );
Neels Hofmeyrb1bf16d2023-06-27 02:10:04 +02002817 execute( TC_mscpool_paging_imsi() );
2818 execute( TC_mscpool_paging_tmsi() );
Neels Hofmeyr7d0e6802023-04-20 20:43:55 +02002819 execute( TC_mscpool_no_allow_attach_round_robin() );
2820 execute( TC_mscpool_no_allow_attach_valid_nri() );
2821 execute( TC_mscpool_sccp_n_pcstate_detaches_cnlink() );
2822 execute( TC_mscpool_sccp_n_pcstate_attaches_cnlink() );
2823
2824 execute( TC_sgsnpool_L3Compl_on_1_cnlink() );
2825 execute( TC_sgsnpool_L3Complete_no_nri_round_robin() );
2826 execute( TC_sgsnpool_L3Complete_valid_nri_1() );
2827 execute( TC_sgsnpool_L3Complete_valid_nri_2() );
2828 execute( TC_sgsnpool_nri_from_other_PLMN() );
2829 execute( TC_sgsnpool_sccp_n_pcstate_detaches_cnlink() );
2830 execute( TC_sgsnpool_sccp_n_pcstate_attaches_cnlink() );
2831
Oliver Smithaa919b42023-11-14 11:30:55 +01002832 /* Run only on nightly since it makes osmo-hnbgw <= 1.5.0 crash: OS#6253 */
2833 if (f_osmo_repo_is("nightly")) {
2834 execute(TC_second_rab_assignment());
2835 }
Neels Hofmeyrc3c01d32023-11-07 02:19:00 +01002836
Pau Espin Pedrolf0b9fa02022-09-12 13:31:07 +02002837 /* Run at the end since it makes osmo-hnbgw <= 1.3.0 crash: OS#5676 */
2838 execute(TC_hnb_reregister_reuse_sctp_assoc());
Neels Hofmeyrd019cc02023-06-02 16:31:23 +02002839
2840 /* Run at the end since it messes with the SCCP config */
2841 execute( TC_apply_sccp() );
Daniel Willmann19b8d902022-01-05 09:12:34 +01002842}
2843
2844}