blob: cc46021a6852b936c55a8e43a72a9cd0ae3ae963 [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,
293 SCCP_PAR_Address sccp_addr_hnbgw optional
Daniel Willmann19b8d902022-01-05 09:12:34 +0100294}
295
296/* We extend:
297 * RUA_ConnHdlr (for the Iuh side, emulating the HNB)
298 * RAN_ConnHdlr (for the Iu side, emulating the MSC)
299 * MGCP_ConnHdlr (for the MGCP side, emulating the MGW)
300 */
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +0200301type component ConnHdlr extends RAN_ConnHdlr, MGCP_ConnHdlr, RUA_ConnHdlr, PFCP_ConnHdlr {
Daniel Willmann19b8d902022-01-05 09:12:34 +0100302 var integer g_sccp_conn_id;
303 var TestHdlrParams g_pars;
304 timer g_Tguard;
Neels Hofmeyr72a8d622023-01-26 13:47:01 +0100305
306 port TELNETasp_PT HNBGWVTY;
Daniel Willmann19b8d902022-01-05 09:12:34 +0100307}
308
309
310const MGCPOps MSC_MGCPOps := {
311 create_cb := refers(MGCP_Emulation.ExpectedCreateCallback),
312 unitdata_cb := refers(MGCP_Emulation.DummyUnitdataCallback)
313}
314
315function f_create_ranap_exp(octetstring l3_enc) runs on ConnHdlr {
316 BSSAP_PROC.call(RAN_register:{l3_enc, self}) {
317 [] BSSAP_PROC.getreply(RAN_register:{?, ?}) {};
318 }
319}
320
321
Daniel Willmannc79679a2022-08-23 17:48:39 +0200322const integer NUM_HNB := 2;
Daniel Willmann19b8d902022-01-05 09:12:34 +0100323
Daniel Willmann19b8d902022-01-05 09:12:34 +0100324type record HnbConfig {
325 LocationAreaIdentification lai,
326 integer sac
327}
328
329type component test_CT extends CTRL_Adapter_CT {
330 var boolean g_initialized := false;
331
332 /********************* Iu side */
Neels Hofmeyr7a48df12023-04-20 20:43:43 +0200333 var RAN_Adapter g_cn[NUM_MSC + NUM_SGSN];
Daniel Willmann19b8d902022-01-05 09:12:34 +0100334
335 /********************* Iuh side */
336 var HnbConfig g_hnb_cfg[NUM_HNB];
337 var Iuh_Emulation_CT vc_Iuh[NUM_HNB];
338 var RUA_Emulation_CT vc_RUA[NUM_HNB];
339 port HNBAP_PT HNBAP[NUM_HNB];
Pau Espin Pedrol83a49612022-09-12 21:11:05 +0200340 /* Number of HNBs to be used/started by the test */
341 var integer g_num_hnbs := NUM_HNB;
Daniel Willmann19b8d902022-01-05 09:12:34 +0100342
343 var MGCP_Emulation_CT vc_MGCP;
344 port TELNETasp_PT HNBGWVTY;
345 /* global test case guard timer (actual timeout value is set in f_init()) */
346 timer T_guard := 30.0;
Neels Hofmeyr7d0e6802023-04-20 20:43:55 +0200347
348 /* The cnlink type 'msc' or 'sgsn', to be used in CTRL commands to obtain counters */
349 var charstring g_ctr_cn_node_name;
350 /* Counter state */
351 var CounterNameValsList g_ctr_cn;
Daniel Willmann19b8d902022-01-05 09:12:34 +0100352}
353
354/* global altstep for global guard timer; */
355altstep as_Tguard() runs on test_CT {
356 [] T_guard.timeout {
357 setverdict(fail, "Timeout of T_guard");
358 mtc.stop;
359 }
360}
361
Daniel Willmann19b8d902022-01-05 09:12:34 +0100362function f_init_vty(charstring id := "foo") runs on test_CT {
363 if (HNBGWVTY.checkstate("Mapped")) {
364 /* skip initialization if already executed once */
365 return;
366 }
367 map(self:HNBGWVTY, system:HNBGWVTY);
368 f_vty_set_prompts(HNBGWVTY);
369 f_vty_transceive(HNBGWVTY, "enable");
370}
371
372function f_init_mgcp(charstring id) runs on test_CT {
373 id := id & "-MGCP";
374 var MGCPOps ops := {
375 create_cb := refers(MGCP_Emulation.ExpectedCreateCallback),
376 unitdata_cb := refers(MGCP_Emulation.DummyUnitdataCallback)
377 }
378 var MGCP_conn_parameters pars := {
379 callagent_ip := mp_hnbgw_ip,
380 callagent_udp_port := -1,
381 mgw_ip := mp_mgw_ip,
382 mgw_udp_port := mp_mgw_port,
383 multi_conn_mode := false
384 }
385
386 vc_MGCP := MGCP_Emulation_CT.create(id);
387 map(vc_MGCP:MGCP, system:MGCP_CODEC_PT);
388 vc_MGCP.start(MGCP_Emulation.main(ops, pars, id));
389}
390
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +0200391function f_init_pfcp(charstring id) runs on ConnHdlr {
392 id := id & "-PFCP";
393
394 var PFCP_Emulation_Cfg pfcp_cfg := {
395 pfcp_bind_ip := mp_pfcp_ip_local,
396 pfcp_bind_port := PFCP_PORT,
397 pfcp_remote_ip := mp_pfcp_ip_remote,
398 pfcp_remote_port := PFCP_PORT,
399 role := UPF
400 };
401
402 vc_PFCP := PFCP_Emulation_CT.create(id) alive;
403 connect(self:PFCP, vc_PFCP:CLIENT);
404 connect(self:PFCP_PROC, vc_PFCP:CLIENT_PROC);
405 vc_PFCP.start(PFCP_Emulation.main(pfcp_cfg));
406}
407
Daniel Willmann19b8d902022-01-05 09:12:34 +0100408function f_init_hnodeb(charstring id, integer hnb_idx, RuaOps rua_ops) runs on test_CT {
409 id := id & "-Iuh" & int2str(hnb_idx);
410
411 /* Iuh lower layer (RUA/HNBAP demux) */
412 var Iuh_conn_parameters iuh_pars;
413 iuh_pars.remote_ip := mp_hnbgw_ip;
414 iuh_pars.remote_sctp_port := mp_hnbgw_iuh_port;
415 iuh_pars.local_ip := mp_hnodeb_ip;
416 iuh_pars.local_sctp_port := mp_hnodeb_port + hnb_idx;
417 vc_Iuh[hnb_idx] := Iuh_Emulation_CT.create(id);
418 connect(self:HNBAP[hnb_idx], vc_Iuh[hnb_idx]:HNBAP);
419
420 vc_RUA[hnb_idx] := RUA_Emulation_CT.create(id & "-RUA");
421 connect(vc_RUA[hnb_idx]:RUA, vc_Iuh[hnb_idx]:RUA);
422
423 /* Start Iuh side components */
424 vc_Iuh[hnb_idx].start(Iuh_Emulation.main(iuh_pars, id));
425 vc_RUA[hnb_idx].start(RUA_Emulation.main(rua_ops, id & "-RUA"));
426}
427
Neels Hofmeyr3d5a0da2023-06-27 00:57:46 +0200428private type record of boolean BooleanList;
429
430private function f_vty_cnlink_allow_attach(TELNETasp_PT pt, boolean ps_domain, BooleanList allow_attach_list)
431{
432 var charstring config := f_vty_transceive_ret(pt, "show running-config");
433
434 var charstring msc_sgsn;
435 if (ps_domain) {
436 msc_sgsn := "sgsn";
437 } else {
438 msc_sgsn := "msc";
439 }
440
441 f_vty_enter_config(pt);
442 for (var integer cn_nr := 0; cn_nr < sizeof(allow_attach_list); cn_nr := cn_nr+1) {
443 if (f_strstr(config, "\n" & msc_sgsn & " " & int2str(cn_nr) & "\n") < 0) {
444 /* There is no 'msc N' for this cn_nr in the running config, so don't create an empty cn by
445 * stepping into that config node. */
446 log(msc_sgsn, cn_nr, " is not configured, skipping");
447 continue;
448 }
449 f_vty_transceive(pt, msc_sgsn & " " & int2str(cn_nr));
450
451 if (allow_attach_list[cn_nr]) {
452 /* strict := false: ignore if osmo-hnbgw does not support this config option (latest build) */
453 f_vty_transceive(pt, "allow-attach", strict := false);
454 } else {
455 f_vty_transceive(pt, "no allow-attach", strict := false);
456 }
457 f_vty_transceive(pt, "exit");
458 }
459 f_vty_transceive(pt, "exit");
460}
461
462/* Start RAN adapter for CN link N.
463 * e.g. link for 'msc 0' = (ps_domain := false, cn_nr := 0)
464 * link for 'sgsn 3' = (ps_domain := true, cn_nr := 3)
465 */
466private function f_cn_nr_init(boolean ps_domain, integer cn_nr) runs on test_CT {
467 var RanOps ranops := MSC_RanOps;
468 ranops.ps_domain := ps_domain;
469 var integer cn_idx := f_cn_idx(ps_domain, cn_nr);
470 var charstring msc_sgsn := "msc";
471 if (ps_domain) {
472 msc_sgsn := "sgsn";
473 }
474 f_ran_adapter_init(g_cn[cn_idx], mp_cn_cfg[cn_idx], "HNBGW_Test." & msc_sgsn & int2str(cn_nr), ranops);
475 f_ran_adapter_start(g_cn[cn_idx]);
476}
477
478private function f_cn_idx_disconnect(integer cn_idx) runs on test_CT {
479 f_ran_adapter_cleanup(g_cn[cn_idx]);
480}
481
Daniel Willmann19b8d902022-01-05 09:12:34 +0100482/* global initialization function */
Neels Hofmeyr333ea392023-06-27 00:58:05 +0200483function f_init(charstring id := "HNBGW", float guard_timeout := 30.0, integer nr_msc := 1, integer nr_sgsn := 1,
484 boolean start_hnb := true) runs on test_CT {
Daniel Willmann19b8d902022-01-05 09:12:34 +0100485
Daniel Willmann19b8d902022-01-05 09:12:34 +0100486 T_guard.start(guard_timeout);
487 activate(as_Tguard());
488
489 /* RUA/RANAP emulation on top of lower-layer Iuh */
490 var RuaOps rua_ops := {
491 create_cb := refers(IuhRanapCreateCallback),
492 unitdata_cb := refers(IuhRanapUnitdataCallback)
493 };
Pau Espin Pedrol83a49612022-09-12 21:11:05 +0200494 for (var integer i := 0; i < g_num_hnbs; i := i+1) {
Daniel Willmannc79679a2022-08-23 17:48:39 +0200495 g_hnb_cfg[i] := {
496 lai := {
Neels Hofmeyr497216f2023-06-27 00:59:26 +0200497 mcc_mnc := '00F110'H,
Daniel Willmannc79679a2022-08-23 17:48:39 +0200498 lac := 2342 + i
499 },
500 sac := 55
501 };
Daniel Willmann19b8d902022-01-05 09:12:34 +0100502 f_init_hnodeb(testcasename(), i, rua_ops);
503 }
504
Neels Hofmeyr3d5a0da2023-06-27 00:57:46 +0200505 f_init_vty("VirtHNBGW");
Neels Hofmeyrffcb8892023-06-27 01:09:57 +0200506 f_ipa_ctrl_start_client(mp_hnbgw_ip, mp_hnbgw_ctrl_port);
507
Daniel Willmann19b8d902022-01-05 09:12:34 +0100508 /* MSC emulation */
Neels Hofmeyr3d5a0da2023-06-27 00:57:46 +0200509
510 /* Make sure each MSC's internal state is "DISCONNECTED" at first */
511 for (var integer i := 0; i < NUM_MSC; i := i + 1) {
512 f_vty_transceive(HNBGWVTY, "msc " & int2str(i) & " ranap reset", strict := false);
513 }
514
515 var BooleanList allow_attach := { false, false, false, false };
Neels Hofmeyr7a48df12023-04-20 20:43:43 +0200516 for (var integer i := 0; i < nr_msc; i := i + 1) {
517 var integer cn_idx := FIRST_MSC_IDX + i;
Neels Hofmeyr3d5a0da2023-06-27 00:57:46 +0200518 allow_attach[i] := true;
519 f_cn_nr_init(ps_domain := false, cn_nr := i);
Neels Hofmeyr7a48df12023-04-20 20:43:43 +0200520 }
Neels Hofmeyr3d5a0da2023-06-27 00:57:46 +0200521 /* start the test with exactly all enabled MSCs allowed to attach */
522 f_vty_cnlink_allow_attach(HNBGWVTY, false, allow_attach);
Daniel Willmann19b8d902022-01-05 09:12:34 +0100523
524 /* SGSN emulation */
Neels Hofmeyr3d5a0da2023-06-27 00:57:46 +0200525
526 /* Make sure each SGSN's internal state is "DISCONNECTED" at first */
527 for (var integer i := 0; i < NUM_SGSN; i := i + 1) {
528 f_vty_transceive(HNBGWVTY, "sgsn " & int2str(i) & " ranap reset", strict := false);
Neels Hofmeyr7a48df12023-04-20 20:43:43 +0200529 }
Daniel Willmann19b8d902022-01-05 09:12:34 +0100530
Neels Hofmeyr3d5a0da2023-06-27 00:57:46 +0200531 allow_attach := { false, false, false, false };
532 for (var integer i := 0; i < nr_sgsn; i := i + 1) {
533 var integer cn_idx := FIRST_SGSN_IDX + i;
534 allow_attach[i] := true;
535 f_cn_nr_init(ps_domain := true, cn_nr := i);
536 }
537 f_vty_cnlink_allow_attach(HNBGWVTY, true, allow_attach);
538
Daniel Willmann19b8d902022-01-05 09:12:34 +0100539 f_init_mgcp(id);
Neels Hofmeyr333ea392023-06-27 00:58:05 +0200540
541 if (start_hnb) {
542 f_start_hnbs();
543 }
Neels Hofmeyr467eb7e2023-08-10 03:38:07 +0200544
545 /* Sometimes, the RUA InitialUE-Message from a test happens too quickly, before the RANAP RESET from
546 * RAN_Emulation is through, after above f_cn_nr_init(). In the pcap it seems to be a matter of 50 ms. Give some
547 * grace. */
548 f_sleep(1.0);
Daniel Willmann19b8d902022-01-05 09:12:34 +0100549}
550
551friend function f_shutdown_helper() runs on test_CT {
Pau Espin Pedrol6c87ad92023-07-18 11:24:25 +0200552 if (mp_validate_talloc_asn1) {
553 f_verify_talloc_bytes(HNBGWVTY, {"asn1_context"}, 1);
554 }
Neels Hofmeyr75d905b2023-04-27 00:30:25 +0200555
Daniel Willmann19b8d902022-01-05 09:12:34 +0100556 all component.stop;
557 setverdict(pass);
558 mtc.stop;
559}
560
561/* helper function to start all of the simulated hNodeBs */
562function f_start_hnbs() runs on test_CT {
Pau Espin Pedrol83a49612022-09-12 21:11:05 +0200563 for (var integer i:= 0; i < g_num_hnbs; i := i+1) {
Harald Welted71d5962024-03-27 19:17:19 +0100564 f_hnbap_hnb_register(i, i);
Daniel Willmann19b8d902022-01-05 09:12:34 +0100565 }
566}
567
568/***********************************************************************
569 * code running in test_CT, preparing start of per-UE ConnHdlr
570 ***********************************************************************/
571
572/* inbound RUA connection establishment on Iuh side */
573function IuhRanapCreateCallback(ContextId context_id, RUA_IEs.CN_DomainIndicator domain, charstring id)
574runs on RUA_Emulation_CT return RUA_ConnHdlr {
575 log("CreateCallback");
576 return null;
577}
578
579/* inbound RUA connectionless data on Iuh side */
580function IuhRanapUnitdataCallback(RANAP_PDU ranap)
581runs on RUA_Emulation_CT return template RANAP_PDU {
582 log("UnitdataCallback");
583 return omit;
584}
585
586private function f_start_handler_create(TestHdlrParams pars) runs on test_CT return ConnHdlr {
587 var ConnHdlr vc_conn;
588 var charstring id := testcasename() & int2str(pars.hnb_idx);
589
590 vc_conn := ConnHdlr.create(id);
591
592 /* Iuh RUA part */
593 connect(vc_conn:RUA, vc_RUA[pars.hnb_idx]:CLIENT);
594
Neels Hofmeyr7a48df12023-04-20 20:43:43 +0200595 /* MSC or SGSN */
596 connect(vc_conn:BSSAP, g_cn[pars.cn_idx].vc_RAN:CLIENT);
597 connect(vc_conn:BSSAP_PROC, g_cn[pars.cn_idx].vc_RAN:PROC);
598
Daniel Willmann19b8d902022-01-05 09:12:34 +0100599 /* MGCP part */
600 connect(vc_conn:MGCP, vc_MGCP:MGCP_CLIENT);
601 connect(vc_conn:MGCP_PROC, vc_MGCP:MGCP_PROC);
602
603 return vc_conn;
604}
605
606private function f_start_handler_run(ConnHdlr vc_conn, void_fn fn, TestHdlrParams pars) runs on test_CT {
607 var charstring id := testcasename(); // & int2str(pars.ran_idx);
608 /* We cannot use vc_conn.start(f_init_handler(fn, id, pars)); as we cannot have
609 * a stand-alone 'derefers()' call, see https://www.eclipse.org/forums/index.php/t/1091364/ */
610 pars.hnb := g_hnb_cfg[pars.hnb_idx];
Daniel Willmann19b8d902022-01-05 09:12:34 +0100611 vc_conn.start(derefers(fn)(id, pars));
612}
613
614function f_start_handler_with_pars(void_fn fn, template (value) TestHdlrParams pars)
615runs on test_CT return ConnHdlr {
616 var ConnHdlr vc_conn;
617 vc_conn := f_start_handler_create(valueof(pars));
618 f_start_handler_run(vc_conn, fn, valueof(pars));
619 return vc_conn;
620}
621
622/***********************************************************************
623 * code running inside per-UE ConnHdlr
624 ***********************************************************************/
625
626type function void_fn(charstring id, TestHdlrParams pars) runs on ConnHdlr;
627
628function f_init_handler(TestHdlrParams pars, float t_guard := 20.0) runs on ConnHdlr {
629 /* make parameters available via component variable */
630 g_pars := pars;
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +0200631
632 f_init_pfcp(testcasename());
633
Daniel Willmann19b8d902022-01-05 09:12:34 +0100634 /* start guard timer and activate it as default */
635 g_Tguard.start(t_guard);
636 activate(as_Tguard_ConnHdlr());
637
Neels Hofmeyr72a8d622023-01-26 13:47:01 +0100638 map(self:HNBGWVTY, system:HNBGWVTY);
639 f_vty_set_prompts(HNBGWVTY);
640 f_vty_transceive(HNBGWVTY, "enable");
641
Daniel Willmann19b8d902022-01-05 09:12:34 +0100642 /* TODO: CTRL? */
Neels Hofmeyr59517222023-06-23 04:46:59 +0200643
644 f_sleep(1.0);
Daniel Willmann19b8d902022-01-05 09:12:34 +0100645}
646
647/* global altstep for global guard timer; */
648private altstep as_Tguard_ConnHdlr() runs on ConnHdlr {
649 [] g_Tguard.timeout {
650 setverdict(fail, "Timeout of T_guard");
651 mtc.stop;
652 }
653}
654
Neels Hofmeyrdc416c92023-03-09 02:47:50 +0100655private function f_bssap_expect(template (present) RANAP_PDU exp_rx) runs on ConnHdlr return RANAP_PDU
656{
657 var RANAP_PDU rx;
658 timer T := 5.0;
659 T.start;
660 alt {
661 [] BSSAP.receive(exp_rx) -> value rx {
662 setverdict(pass);
663 }
664 [] BSSAP.receive(RANAP_PDU:?) {
665 setverdict(fail, "Got an unexpected RANAP message on BSSAP port, was waiting for ", exp_rx);
666 mtc.stop;
667 }
668 [] T.timeout {
669 setverdict(fail, "Timeout waiting for RANAP on BSSAP port: ", exp_rx);
670 mtc.stop;
671 }
672 }
673 T.stop;
674 return rx;
675}
676
Daniel Willmann19b8d902022-01-05 09:12:34 +0100677/* send RANAP on Iuh and expect it to show up on Iu */
678function f_iuh2iu(template (present) RANAP_PDU tx, template RANAP_PDU exp_rx := omit)
679runs on ConnHdlr return RANAP_PDU {
680 var RANAP_PDU rx;
681 timer T := 5.0;
682
683 if (istemplatekind(exp_rx, "omit")) {
684 exp_rx := tx;
685 }
686
687 RUA.send(tx);
Daniel Willmann19b8d902022-01-05 09:12:34 +0100688
Neels Hofmeyrdc416c92023-03-09 02:47:50 +0100689 return f_bssap_expect(exp_rx);
Daniel Willmann19b8d902022-01-05 09:12:34 +0100690}
691
692/* send RANAP on Iu and expect it to show up on Iuh */
693function f_iu2iuh(template (present) RANAP_PDU tx, template RANAP_PDU exp_rx := omit)
694runs on ConnHdlr return RANAP_PDU {
Daniel Willmann19b8d902022-01-05 09:12:34 +0100695 if (istemplatekind(exp_rx, "omit")) {
696 exp_rx := tx;
697 }
698
699 BSSAP.send(tx);
Daniel Willmann19b8d902022-01-05 09:12:34 +0100700
Neels Hofmeyr735b6562023-03-09 02:51:28 +0100701 return f_rua_expect(exp_rx)
702}
703
704/* expect to receive a specific RUA message on Iuh */
705private function f_rua_expect(template (present) RANAP_PDU exp_rx) runs on ConnHdlr return RANAP_PDU
706{
707 var RANAP_PDU rx;
708 timer T := 5.0;
709 T.start;
Daniel Willmann19b8d902022-01-05 09:12:34 +0100710 alt {
711 [] RUA.receive(exp_rx) -> value rx {
712 setverdict(pass);
713 }
Neels Hofmeyr735b6562023-03-09 02:51:28 +0100714 [] RUA.receive(RANAP_PDU:?) {
715 setverdict(fail, "Got an unexpected RUA message, was waiting for ", exp_rx);
716 mtc.stop;
717 }
Daniel Willmann19b8d902022-01-05 09:12:34 +0100718 [] T.timeout {
719 setverdict(fail, "Timeout waiting for Iuh ", exp_rx);
Neels Hofmeyr735b6562023-03-09 02:51:28 +0100720 mtc.stop;
Daniel Willmann19b8d902022-01-05 09:12:34 +0100721 }
722 }
Neels Hofmeyr735b6562023-03-09 02:51:28 +0100723 T.stop;
Daniel Willmann19b8d902022-01-05 09:12:34 +0100724 return rx;
725}
726
727/* send RANAP on Iuh and expect it to show up on Iu */
728function f_iuh2iu_connect(template (present) RANAP_PDU tx, template RANAP_PDU exp_rx := omit)
729runs on ConnHdlr return RANAP_PDU {
730 var RANAP_PDU rx;
731 timer T := 5.0;
732
733 if (istemplatekind(exp_rx, "omit")) {
734 exp_rx := tx;
735 }
736
737 /* create an expect on the Iu side for the random NAS portion */
Neels Hofmeyrf2c95022023-04-19 01:24:39 +0200738 if (g_pars.expect_separate_sccp_cr) {
Neels Hofmeyrf0b9ed12022-06-07 17:46:32 +0200739 f_ran_register_sccp_cr_without_payload();
740 } else {
741 var template (omit) octetstring nas := f_ranap_extract_l3(valueof(tx));
742 f_ran_register_exp(valueof(nas));
743 }
Daniel Willmann19b8d902022-01-05 09:12:34 +0100744
745 /* send it via Iuh (creating a RUA connection) */
746 RUA.send(RUA_Conn_Req:{g_pars.ps_domain, tx});
747
Neels Hofmeyrf2c95022023-04-19 01:24:39 +0200748 if (g_pars.expect_separate_sccp_cr) {
Neels Hofmeyrf0b9ed12022-06-07 17:46:32 +0200749 /* Acknowledge the empty SCCP CR. RAN_Emulation does the confirmation, no need to respond. */
750 BSSAP.receive(tr_RANAP_Conn_Req());
751 }
752
Daniel Willmann19b8d902022-01-05 09:12:34 +0100753 /* expect to receive it on the Iu side */
Neels Hofmeyrdc416c92023-03-09 02:47:50 +0100754 return f_bssap_expect(exp_rx);
Daniel Willmann19b8d902022-01-05 09:12:34 +0100755}
756
Neels Hofmeyr99b7d402023-02-20 14:26:31 +0100757/* 3GPP TS 48.006 9.2 Connection release:
758 *
759 * The MSC sends a SCCP released message. This message shall not contain
760 * any user data field.
761 *
762 * So what we expect normally is:
763 *
764 * HNBGW MSC
765 * RUA --id-Disconnect-------> | ---Data-Form-1(!)---> | Iu-ReleaseComplete
766 * | <--Released---------- | (no data)
767 *
768 * This function tests osmo-hnbgw behavior if the CN fails to send a RLSD:
769 * after some timeout, osmo-hnbgw should send a RLSD to the CN.
770 */
Daniel Willmann19b8d902022-01-05 09:12:34 +0100771function f_iuh2iu_disconnect(template (present) RANAP_PDU tx, RUA_IEs.Cause cause,
772 template RANAP_PDU exp_rx := omit)
773runs on ConnHdlr return RANAP_PDU {
774 var RANAP_PDU rx
Pau Espin Pedrolee4ce862023-11-02 12:23:25 +0100775 timer T := int2float(mp_hnbgw_timer_x31) + 1.0;
Daniel Willmann19b8d902022-01-05 09:12:34 +0100776
777 if (istemplatekind(exp_rx, "omit")) {
778 exp_rx := tx;
779 }
780
781 /* send it via Iuh (creating a RUA connection) */
782 RUA.send(RUA_Disc_Req:{tx, cause});
783
784 /* expect to receive it on the Iu side */
Neels Hofmeyrdc416c92023-03-09 02:47:50 +0100785 rx := f_bssap_expect(exp_rx);
Daniel Willmann19b8d902022-01-05 09:12:34 +0100786
787 /* expect disconnect on the Iu side */
Neels Hofmeyrdc416c92023-03-09 02:47:50 +0100788 T.start;
Daniel Willmann19b8d902022-01-05 09:12:34 +0100789 alt {
790 [] BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_IND) {
791 setverdict(pass);
792 }
793 [] T.timeout {
794 setverdict(fail, "Timeout waiting for Iu disconnect");
795 return rx;
796 }
797
798 }
799 return rx;
800}
801
Neels Hofmeyrf2c95022023-04-19 01:24:39 +0200802private function f_build_initial_ue_with_nas(TestHdlrParams pars, octetstring nas)
803 return RANAP_PDU {
Harald Welte3f216c52024-03-27 20:40:17 +0100804 var RANAP_IEs.LAI lai := {
Daniel Willmann19b8d902022-01-05 09:12:34 +0100805 pLMNidentity := hex2oct(pars.hnb.lai.mcc_mnc),
806 lAC := int2oct(pars.hnb.lai.lac, 2),
807 iE_Extensions := omit
808 };
Harald Welte3f216c52024-03-27 20:40:17 +0100809 var RANAP_IEs.SAI sai := {
Daniel Willmann19b8d902022-01-05 09:12:34 +0100810 pLMNidentity := lai.pLMNidentity,
811 lAC := lai.lAC,
812 sAC := int2oct(pars.hnb.sac, 2),
813 iE_Extensions := omit
814 }
Daniel Willmann19b8d902022-01-05 09:12:34 +0100815 var IuSignallingConnectionIdentifier sigc_id := int2bit(f_rnd_int(1000), 24);
816 var GlobalRNC_ID grnc_id := {
817 pLMNidentity := lai.pLMNidentity,
818 rNC_ID := 2342
819 }
Neels Hofmeyrf2c95022023-04-19 01:24:39 +0200820 var template RANAP_PDU ret;
Daniel Willmann19b8d902022-01-05 09:12:34 +0100821 if (pars.ps_domain) {
Harald Welte3f216c52024-03-27 20:40:17 +0100822 var RANAP_IEs.RAC rac := '00'O;
Neels Hofmeyrf2c95022023-04-19 01:24:39 +0200823 ret := ts_RANAP_initialUE_PS(lai, rac, sai, nas, sigc_id, grnc_id);
Daniel Willmann19b8d902022-01-05 09:12:34 +0100824 } else {
Neels Hofmeyrf2c95022023-04-19 01:24:39 +0200825 ret := ts_RANAP_initialUE_CS(lai, sai, nas, sigc_id, grnc_id);
Daniel Willmann19b8d902022-01-05 09:12:34 +0100826 }
Neels Hofmeyrf2c95022023-04-19 01:24:39 +0200827 return valueof(ret);
828}
829
830/* build a RANAP InitialUE based on the TestHdlrParams */
831friend function f_build_initial_ue(TestHdlrParams pars) return RANAP_PDU {
832
833 var octetstring nas;
834
835 if (pars.tx_sccp_cr_data_len == 0) {
836 nas := f_rnd_octstring(10);
837 } else {
838 /* The test asks for an exact number of Optional Data bytes. */
839
840 /* First see what size the RANAP part of the payload data is,
841 * to adjust the NAS PDU size to the size requested by the test (pars.tx_sccp_cr_data_len). */
842 var RANAP_PDU initial_ue := f_build_initial_ue_with_nas(pars, '00'O);
843
844 var octetstring ranap_plus_one_byte_nas := enc_RANAP_PDU(initial_ue);
845 var integer ranap_length := lengthof(ranap_plus_one_byte_nas) - 1;
846
847 log("ranap_plus_one_byte_nas = ", lengthof(ranap_plus_one_byte_nas), " bytes, ", initial_ue, " = ",
848 ranap_plus_one_byte_nas);
849 log("ranap_length = ", ranap_length);
850
851 /* SCCP CR has a payload length limit of 130 bytes. To trigger this limit, the RANAP + NAS PDU has to be
852 * > 130 bytes. It doesn't need to be 131 bytes in the NAS PDU alone, but let's just make it definitely
853 * large enough. To test for this limit, pars.tx_sccp_cr_data_len asks for a specific amount of data len. */
854 nas := f_rnd_octstring(pars.tx_sccp_cr_data_len - ranap_length);
855 }
856
857 var RANAP_PDU ret := f_build_initial_ue_with_nas(pars, nas);
858
859 if (pars.tx_sccp_cr_data_len != 0) {
860 for (var integer attempts := 0; attempts < 2; attempts := attempts + 1) {
861 var octetstring check_len := enc_RANAP_PDU(ret);
862 log("final RANAP PDU length = ", lengthof(check_len));
863 if (lengthof(check_len) == pars.tx_sccp_cr_data_len) {
864 return ret;
865 }
866 nas := f_rnd_octstring(lengthof(nas) + (pars.tx_sccp_cr_data_len - lengthof(check_len)));
867 log("that was off, changed NAS length to ", lengthof(nas), " and trying again");
868 ret := f_build_initial_ue_with_nas(pars, nas);
869 }
870 setverdict(fail, "Ended up with wrong Optional Data length");
871 mtc.stop;
872 }
873 return ret;
Daniel Willmann19b8d902022-01-05 09:12:34 +0100874}
875
876/* build a RANAP RAB AssignmentResponse based on the TestHdlrParams */
877friend function f_build_rab_ass_resp(TestHdlrParams pars) return RANAP_PDU {
878 var template RAB_SetupOrModifiedList rab_sml;
879
880 rab_sml := ts_RAB_SMdL(t_RAB_id(23), f_ts_RAB_TLA("192.168.1.23"), t_RAB_binding_port(1234));
881
882 return valueof(ts_RANAP_RabAssResp(rab_sml));
883}
884
885
886/***********************************************************************
887 * HNBAP Testing
888 ***********************************************************************/
889
890
Harald Welted71d5962024-03-27 19:17:19 +0100891function 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 +0100892{
893 timer T := 2.0;
894
Neels Hofmeyrfffe79b2023-06-27 01:16:15 +0200895 HNBAP[hnb_idx].send(ts_HNBAP_HNBRegisterRequest(char2oct("TTCN3-HNB-" & int2str(hnb_idx)),
Daniel Willmann19b8d902022-01-05 09:12:34 +0100896 '00F110'O,
Daniel Willmannc79679a2022-08-23 17:48:39 +0200897 int2bit(1 + cell_id, 28),
Daniel Willmann19b8d902022-01-05 09:12:34 +0100898 int2oct(2, 2),
899 int2oct(3, 1),
900 int2oct(4, 2)));
901
902 T.start;
903 alt {
904 [] HNBAP[hnb_idx].receive(tr_HNBAP_HNBRegisterAccept(?)) {
Daniel Willmannc79679a2022-08-23 17:48:39 +0200905 if (expect_reject) {
906 setverdict(fail, "Rx HNB Register Accept while expecting reject");
907 } else {
908 setverdict(pass);
909 }
910 }
911 [] HNBAP[hnb_idx].receive(tr_HNBAP_HNBRegisterReject(?)) {
912 if (expect_reject) {
913 setverdict(pass);
914 } else {
915 setverdict(fail, "Rx HNB Register Reject while expecting accept");
916 }
Daniel Willmann19b8d902022-01-05 09:12:34 +0100917 }
918 [] HNBAP[hnb_idx].receive(IUHEM_Event:?) {
919 repeat;
920 }
921 [] T.timeout {
Daniel Willmannc79679a2022-08-23 17:48:39 +0200922 setverdict(fail, "Timeout waiting for HNB Register response");
Daniel Willmann19b8d902022-01-05 09:12:34 +0100923 }
924 }
925}
926
Harald Welteaf3e2162024-03-27 21:54:20 +0100927function f_hnbap_ue_register(integer hnb_idx := 0, template (present) UE_Identity ue_id, boolean expect_reject := false) runs on test_CT
928{
929 timer T := 2.0;
930
931 HNBAP[hnb_idx].send(ts_HNBAP_UERegisterRequest(ue_id));
932
933 T.start;
934 alt {
935 [] HNBAP[hnb_idx].receive(tr_HNBAP_UERegisterAccept(ue_id)) {
936 if (expect_reject) {
937 setverdict(fail, "Rx UE Register Accept while expecting reject");
938 } else {
939 setverdict(pass);
940 }
941 }
942 [] HNBAP[hnb_idx].receive(tr_HNBAP_UERegisterReject(ue_id, ?)) {
943 if (expect_reject) {
944 setverdict(pass);
945 } else {
946 setverdict(fail, "Rx UE Register Reject while expecting accept");
947 }
948 }
949 [] HNBAP[hnb_idx].receive(IUHEM_Event:?) {
950 repeat;
951 }
952 [] T.timeout {
953 setverdict(fail, "Timeout waiting for UE Register response");
954 }
955 }
956}
957
958
Daniel Willmann19b8d902022-01-05 09:12:34 +0100959testcase TC_hnb_register() runs on test_CT {
Pau Espin Pedrol83a49612022-09-12 21:11:05 +0200960 g_num_hnbs := 1;
Neels Hofmeyr333ea392023-06-27 00:58:05 +0200961 f_init(start_hnb := false);
Harald Welted71d5962024-03-27 19:17:19 +0100962 f_hnbap_hnb_register(0);
Daniel Willmann19b8d902022-01-05 09:12:34 +0100963 f_shutdown_helper();
964}
965
Pau Espin Pedrolacf4f222022-09-27 14:33:40 +0200966/* Try to register the same HNB from 2 different concurrent connections. Second
967 * one should be rejected. */
Daniel Willmannc79679a2022-08-23 17:48:39 +0200968testcase TC_hnb_register_duplicate() runs on test_CT {
Pau Espin Pedrol83a49612022-09-12 21:11:05 +0200969 g_num_hnbs := 2;
Neels Hofmeyr333ea392023-06-27 00:58:05 +0200970 f_init(start_hnb := false);
Harald Welted71d5962024-03-27 19:17:19 +0100971 f_hnbap_hnb_register(0);
972 f_hnbap_hnb_register(1, 0, expect_reject := true);
Daniel Willmannc79679a2022-08-23 17:48:39 +0200973 f_verify_talloc_count(HNBGWVTY, {"struct hnb_context"}, expect_count := 1);
974 f_shutdown_helper();
975}
976
Pau Espin Pedrolacf4f222022-09-27 14:33:40 +0200977/* Try to register the same HNB in the same connection already established, aka
978 * duplicate HNB Register Request. It should be accepted and new configuration
979 * applied. TS 25.469 8.2.4 */
980testcase TC_hnb_register_duplicate_reuse_sctp_assoc() runs on test_CT {
981 g_num_hnbs := 1;
Neels Hofmeyr333ea392023-06-27 00:58:05 +0200982 f_init(start_hnb := false);
Harald Welted71d5962024-03-27 19:17:19 +0100983 f_hnbap_hnb_register(0);
984 f_hnbap_hnb_register(0);
Pau Espin Pedrolacf4f222022-09-27 14:33:40 +0200985 f_verify_talloc_count(HNBGWVTY, {"struct hnb_context"}, expect_count := 1);
986 f_shutdown_helper();
987}
988
Pau Espin Pedrolf0b9fa02022-09-12 13:31:07 +0200989/* Drop HNBAP conn (HNBAP DEREG) and reconnect it (HNBAP REG) using same SCTP association.
990 * Related: OS#5676, SYS#6113 */
991testcase TC_hnb_reregister_reuse_sctp_assoc() runs on test_CT {
992 g_num_hnbs := 1;
Neels Hofmeyr333ea392023-06-27 00:58:05 +0200993 f_init(start_hnb := false);
Harald Welted71d5962024-03-27 19:17:19 +0100994 f_hnbap_hnb_register(0);
Pau Espin Pedrolf0b9fa02022-09-12 13:31:07 +0200995 HNBAP[0].send(ts_HNBAP_HNBDe_Register(ts_HnbapCause(unspecified)));
Harald Welted71d5962024-03-27 19:17:19 +0100996 f_hnbap_hnb_register(0);
Pau Espin Pedrolf0b9fa02022-09-12 13:31:07 +0200997 f_verify_talloc_count(HNBGWVTY, {"struct hnb_context"}, expect_count := 1);
998 f_shutdown_helper();
999}
1000
Harald Welteaf3e2162024-03-27 21:54:20 +01001001/* regular UE registration */
1002testcase TC_ue_register() runs on test_CT {
1003 var UE_Identity ue_id := { iMSI := imsi_hex2oct(f_gen_imsi(1)) };
1004 g_num_hnbs := 1;
1005 f_init(start_hnb := true);
1006 f_hnbap_ue_register(0, ue_id);
1007 f_shutdown_helper();
1008}
1009
Harald Weltef60044d2024-04-04 00:54:34 +02001010/* regular UE registration (UE Identity: TMSI+LAI) */
1011testcase TC_ue_register_tmsi_lai() runs on test_CT {
1012 var UE_Identity ue_id := { tMSILAI := { tMSI := oct2bit(f_gen_tmsi(0)),
1013 lAI := { pLMNID := '00F110'O, lAC := '2342'O }
1014 }
1015 };
1016 g_num_hnbs := 1;
1017 f_init(start_hnb := true);
1018 f_hnbap_ue_register(0, ue_id);
1019 f_shutdown_helper();
1020}
1021
1022
Harald Welteaf3e2162024-03-27 21:54:20 +01001023/* UE registration from unregistered HNB */
1024testcase TC_ue_register_before_hnb_register() runs on test_CT {
1025 var UE_Identity ue_id := { iMSI := imsi_hex2oct(f_gen_imsi(1)) };
1026 g_num_hnbs := 1;
1027 f_init(start_hnb := false);
1028 f_hnbap_ue_register(0, ue_id, expect_reject := true);
1029 f_shutdown_helper();
1030}
1031
Daniel Willmann19b8d902022-01-05 09:12:34 +01001032/***********************************************************************
1033 * RUA / RANAP Testing
1034 ***********************************************************************/
1035
Neels Hofmeyr7a48df12023-04-20 20:43:43 +02001036/* Translate from {msc,sgsn}x{0..n} to the proper index to use in g_cn[].
1037 * g_cn[] stores CN links, MSCs and SGSNs in the same array.
1038 * For example, for 'sgsn 23', use g_cn[ f_cn_idx(ps_domain := true, cn_nr := 23) ].
1039 *
1040 * Note the naming:
1041 * cn_nr is the number used in the cfg file, as in 'msc 0'.
1042 * cn_idx is the array index in g_cn[].
1043 */
1044private function f_cn_idx(boolean ps_domain, integer cn_nr := 0) return integer
1045{
1046 if (ps_domain) {
1047 return FIRST_SGSN_IDX + cn_nr;
1048 }
1049 return FIRST_MSC_IDX + cn_nr;
1050}
1051
Daniel Willmann19b8d902022-01-05 09:12:34 +01001052private template (value) TestHdlrParams
Neels Hofmeyrf0b9ed12022-06-07 17:46:32 +02001053t_pars(integer imsi_suffix, boolean ps_domain := false, integer hnb_idx := 0,
Neels Hofmeyr7a48df12023-04-20 20:43:43 +02001054 boolean expect_separate_sccp_cr := false, integer tx_sccp_cr_data_len := 0,
1055 integer cn_nr := 0) := {
Daniel Willmann19b8d902022-01-05 09:12:34 +01001056 hnb_idx := hnb_idx,
Neels Hofmeyr7a48df12023-04-20 20:43:43 +02001057 cn_idx := f_cn_idx(ps_domain, cn_nr),
Daniel Willmann19b8d902022-01-05 09:12:34 +01001058 imsi := f_gen_imsi(imsi_suffix),
1059 ps_domain := ps_domain,
Pau Espin Pedrolaf746502023-11-29 16:18:28 +01001060 mgcp_pars := t_MgcpParams,
Neels Hofmeyrf0b9ed12022-06-07 17:46:32 +02001061 hnb := omit, /* filled in later */
Neels Hofmeyrf2c95022023-04-19 01:24:39 +02001062 expect_separate_sccp_cr := expect_separate_sccp_cr,
1063 tx_sccp_cr_data_len := tx_sccp_cr_data_len,
Neels Hofmeyr7d0e6802023-04-20 20:43:55 +02001064 pfcp_local_addr := mp_pfcp_ip_local,
Neels Hofmeyrb1bf16d2023-06-27 02:10:04 +02001065 nas_pdu := omit,
1066 sccp_addr_msc := omit,
1067 sccp_addr_hnbgw := omit
Daniel Willmann19b8d902022-01-05 09:12:34 +01001068}
1069
1070/* Create an Iuh connection; send InitialUE; expect it to appear on new SCCP conenction */
1071friend function f_tc_initial_ue(charstring id, TestHdlrParams pars) runs on ConnHdlr {
1072 f_init_handler(pars);
1073 var RANAP_PDU tx := f_build_initial_ue(g_pars);
1074 f_iuh2iu_connect(tx);
1075}
1076testcase TC_ranap_cs_initial_ue() runs on test_CT {
1077 var ConnHdlr vc_conn;
1078
Pau Espin Pedrol83a49612022-09-12 21:11:05 +02001079 g_num_hnbs := 1;
Daniel Willmann19b8d902022-01-05 09:12:34 +01001080 f_init();
Daniel Willmann19b8d902022-01-05 09:12:34 +01001081
1082 vc_conn := f_start_handler_with_pars(refers(f_tc_initial_ue), t_pars(1));
1083 vc_conn.done;
Neels Hofmeyr3a9140e2023-06-23 04:50:39 +02001084
1085 f_shutdown_helper();
Daniel Willmann19b8d902022-01-05 09:12:34 +01001086}
1087testcase TC_ranap_ps_initial_ue() runs on test_CT {
1088 var ConnHdlr vc_conn;
1089
Pau Espin Pedrol83a49612022-09-12 21:11:05 +02001090 g_num_hnbs := 1;
Daniel Willmann19b8d902022-01-05 09:12:34 +01001091 f_init();
Daniel Willmann19b8d902022-01-05 09:12:34 +01001092
1093 vc_conn := f_start_handler_with_pars(refers(f_tc_initial_ue), t_pars(2, true));
1094 vc_conn.done;
Neels Hofmeyr3a9140e2023-06-23 04:50:39 +02001095
1096 f_shutdown_helper();
Daniel Willmann19b8d902022-01-05 09:12:34 +01001097}
1098
Neels Hofmeyrf2c95022023-04-19 01:24:39 +02001099private function f_vty_set_sccp_max_optional_data(TELNETasp_PT pt, integer val := -1)
Neels Hofmeyrf0b9ed12022-06-07 17:46:32 +02001100{
Neels Hofmeyrf2c95022023-04-19 01:24:39 +02001101 var charstring valstr;
1102 if (val < 0) {
1103 valstr := "standard";
1104 } else {
1105 valstr := int2str(val);
1106 }
Neels Hofmeyrf0b9ed12022-06-07 17:46:32 +02001107 f_vty_enter_config(pt);
Neels Hofmeyrf2c95022023-04-19 01:24:39 +02001108 f_vty_transceive(pt, "cs7 instance 0");
1109 f_vty_transceive(pt, "sccp max-optional-data " & valstr);
Neels Hofmeyrf0b9ed12022-06-07 17:46:32 +02001110 f_vty_transceive(pt, "end");
1111}
1112
1113testcase TC_ranap_cs_initial_ue_empty_cr() runs on test_CT {
1114 var ConnHdlr vc_conn;
1115
Pau Espin Pedrol83a49612022-09-12 21:11:05 +02001116 g_num_hnbs := 1;
Neels Hofmeyrf0b9ed12022-06-07 17:46:32 +02001117 f_init();
Neels Hofmeyrf0b9ed12022-06-07 17:46:32 +02001118
Neels Hofmeyrf2c95022023-04-19 01:24:39 +02001119 f_vty_set_sccp_max_optional_data(HNBGWVTY, 0);
Neels Hofmeyrf0b9ed12022-06-07 17:46:32 +02001120
Neels Hofmeyrf2c95022023-04-19 01:24:39 +02001121 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 +02001122 vc_conn.done;
1123
1124 /* reset */
Neels Hofmeyrf2c95022023-04-19 01:24:39 +02001125 f_vty_set_sccp_max_optional_data(HNBGWVTY);
Neels Hofmeyr3a9140e2023-06-23 04:50:39 +02001126
1127 f_shutdown_helper();
Neels Hofmeyrf0b9ed12022-06-07 17:46:32 +02001128}
1129testcase TC_ranap_ps_initial_ue_empty_cr() runs on test_CT {
1130 var ConnHdlr vc_conn;
1131
Pau Espin Pedrol83a49612022-09-12 21:11:05 +02001132 g_num_hnbs := 1;
Neels Hofmeyrf0b9ed12022-06-07 17:46:32 +02001133 f_init();
Neels Hofmeyrf0b9ed12022-06-07 17:46:32 +02001134
Neels Hofmeyrf2c95022023-04-19 01:24:39 +02001135 f_vty_set_sccp_max_optional_data(HNBGWVTY, 0);
Neels Hofmeyrf0b9ed12022-06-07 17:46:32 +02001136
Neels Hofmeyrf2c95022023-04-19 01:24:39 +02001137 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 +02001138 vc_conn.done;
1139
1140 /* reset */
Neels Hofmeyrf2c95022023-04-19 01:24:39 +02001141 f_vty_set_sccp_max_optional_data(HNBGWVTY);
Neels Hofmeyr3a9140e2023-06-23 04:50:39 +02001142
1143 f_shutdown_helper();
Neels Hofmeyrf2c95022023-04-19 01:24:39 +02001144}
1145
1146type record Testdata_CR_Limit {
1147 integer data_len,
1148 integer max_optional_data,
1149 boolean expect_separate_sccp_cr
1150};
1151type record of Testdata_CR_Limit Testdata_CR_Limits;
1152
1153testcase TC_sccp_cr_limit() runs on test_CT {
1154 g_num_hnbs := 1;
1155 f_init();
Neels Hofmeyrf2c95022023-04-19 01:24:39 +02001156
1157 const Testdata_CR_Limits tests := {
1158 { data_len := 130, max_optional_data := -1, expect_separate_sccp_cr := false },
1159 { data_len := 131, max_optional_data := -1, expect_separate_sccp_cr := true },
1160
1161 { data_len := 100, max_optional_data := 100, expect_separate_sccp_cr := false },
1162 { data_len := 101, max_optional_data := 100, expect_separate_sccp_cr := true },
1163
1164 { data_len := 200, max_optional_data := 200, expect_separate_sccp_cr := false },
1165 { data_len := 201, max_optional_data := 200, expect_separate_sccp_cr := true }
1166 };
1167
1168 var integer csps;
1169 for (csps := 0; csps < 2; csps := csps + 1) {
1170 var boolean ps_domain := (csps > 0);
1171
1172 var integer i;
1173 for (i := 0; i < lengthof(tests); i := i + 1) {
1174 var Testdata_CR_Limit t := tests[i];
1175 f_logp(HNBGWVTY,
1176 "TEST PART TC_sccp_cr_limit ps_domain=" & f_bool2str(ps_domain)
1177 & " data_len=" & int2str(t.data_len)
1178 & " max_optional_data=" & int2str(t.max_optional_data)
1179 & " expect_separate_sccp_cr=" & f_bool2str(t.expect_separate_sccp_cr)
1180 );
1181
1182 f_vty_set_sccp_max_optional_data(HNBGWVTY, t.max_optional_data);
1183 var ConnHdlr vc_conn;
1184 vc_conn := f_start_handler_with_pars(refers(f_tc_initial_ue),
1185 t_pars(100 + i,
1186 ps_domain := ps_domain,
1187 expect_separate_sccp_cr := t.expect_separate_sccp_cr,
1188 tx_sccp_cr_data_len := t.data_len));
1189 vc_conn.done;
1190 }
1191 }
1192
1193 /* reset */
1194 f_vty_set_sccp_max_optional_data(HNBGWVTY);
Neels Hofmeyr3a9140e2023-06-23 04:50:39 +02001195
1196 f_shutdown_helper();
Neels Hofmeyrf0b9ed12022-06-07 17:46:32 +02001197}
1198
Daniel Willmann19b8d902022-01-05 09:12:34 +01001199/* Reply to a received CRCX with an OK (or the reply configured in cpars), using the given parameters.
1200 * Return true when an OK reply was sent, false otherwise.
1201 * Count occurrence of Osmux, include Osmux parameters in the reply if necessary. */
1202function f_handle_crcx(inout MgcpParameters pars, MgcpCommand mgcp_cmd) return template MgcpResponse {
Pau Espin Pedrol264679f2023-11-29 15:52:00 +01001203 var MgwResponse conn := pars.mgw_conn_ran;
Daniel Willmann19b8d902022-01-05 09:12:34 +01001204 if (pars.got_crcx_count > 0) {
Pau Espin Pedrolb85ac2f2023-11-29 15:48:57 +01001205 conn := pars.mgw_conn_cn;
Daniel Willmann19b8d902022-01-05 09:12:34 +01001206 }
1207 pars.got_crcx_count := pars.got_crcx_count + 1;
1208
1209 var MgcpMessage mgcp_msg := {
1210 command := mgcp_cmd
1211 }
1212 var template MgcpResponse mgcp_resp;
1213 var MgcpOsmuxCID osmux_cid;
1214 var MgcpCallId call_id := f_MgcpCmd_extract_call_id(mgcp_cmd);
1215 if (ispresent(pars.mgcp_call_id)) {
1216 if (pars.mgcp_call_id != call_id) {
1217 setverdict(fail, "CRCX contained unexpected call id. Expected:", pars.mgcp_call_id, " got:", call_id);
1218 mtc.stop;
1219 }
1220 } else {
1221 pars.mgcp_call_id := call_id;
1222 }
1223
1224 /* When the endpoint contains a wildcard we keep the endpoint
1225 * identifier we have set up in pars. Otherwise we use the
1226 * endpoint name that the call agent has supplied */
1227 if (match(mgcp_cmd.line.ep, t_MGCP_EP_wildcard) == false) {
1228 pars.mgcp_ep := mgcp_cmd.line.ep;
1229 }
1230
1231 if (conn.resp == -1) {
1232 /* Reply with rror */
1233 var MgcpResponse mgcp_rsp := {
1234 line := {
1235 code := "542",
1236 trans_id := mgcp_cmd.line.trans_id,
1237 string := "FORCED_FAIL"
1238 },
1239 sdp := omit
1240
1241 }
1242 var MgcpParameter mgcp_rsp_param := {
1243 code := "Z",
1244 val := pars.mgcp_ep
1245 };
1246 mgcp_rsp.params[0] := mgcp_rsp_param;
1247 return mgcp_rsp;
1248 }
1249
1250 if (conn.resp == 0) {
1251 /* Do not reply at all */
1252 return omit;
1253 }
1254
1255 if (conn.resp != 1) {
1256 setverdict(fail, "Unexpected value for pars.mgw_conn_*.resp, expect -1, 0 or 1");
1257 mtc.stop;
1258 }
1259
1260 var SDP_Message sdp := valueof(ts_SDP(conn.mgw_rtp_ip, conn.mgw_rtp_ip,
1261 hex2str(pars.mgcp_call_id), "42",
1262 conn.mgw_rtp_port,
1263 { int2str(pars.rtp_payload_type) },
1264 { valueof(ts_SDP_rtpmap(pars.rtp_payload_type,
1265 pars.rtp_sdp_format)),
1266 valueof(ts_SDP_ptime(20)) }));
1267
1268 if (f_mgcp_contains_par(mgcp_msg, "X-OSMUX")) {
1269 if (not pars.use_osmux) {
1270 setverdict(fail, "MSC sent X-Osmux parameter in MGCP, but not expecting any Osmux");
1271 mtc.stop;
1272 }
1273 pars.got_osmux_count := pars.got_osmux_count + 1;
1274 /* we expect MSC to use wildcard here, i.e. osmux_cid == -1 */
1275 osmux_cid := f_MgcpCmd_extract_osmux_cid(mgcp_cmd);
1276 log("f_handle_crcx(): got Osmux CID: ", osmux_cid);
1277 if (osmux_cid != -1) {
1278 setverdict(fail, "MSC using unexpected CID " & int2str(osmux_cid) & " != -1");
1279 mtc.stop;
1280 }
1281
1282 osmux_cid := 0;
1283 mgcp_resp := ts_CRCX_ACK_osmux(mgcp_cmd.line.trans_id, conn.mgcp_connection_id, osmux_cid, sdp);
1284 } else {
1285 mgcp_resp := ts_CRCX_ACK(mgcp_cmd.line.trans_id, conn.mgcp_connection_id, sdp);
1286 }
1287
1288 f_mgcp_par_append(mgcp_resp.params, ts_MgcpParSpecEP(pars.mgcp_ep));
1289
1290 return mgcp_resp;
1291}
1292
Daniel Willmann3e15b7b2022-02-21 17:07:02 +01001293friend function f_create_rab(inout MgcpParameters pars) runs on ConnHdlr {
1294 f_rab_ass_req(pars);
1295 f_rab_ass_resp(pars);
1296}
1297
1298friend function f_rab_ass_req(inout MgcpParameters pars) runs on ConnHdlr {
Daniel Willmann19b8d902022-01-05 09:12:34 +01001299 var MgcpCommand mgcp_cmd;
1300 var RANAP_PDU tx;
1301 var template RAB_SetupOrModifyList rab_sml;
Daniel Willmann19b8d902022-01-05 09:12:34 +01001302 timer T := 5.0;
1303
1304 /* Send RAB Assignment Request */
1305 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));
1306 tx := valueof(ts_RANAP_RabAssReq(rab_sml));
1307 BSSAP.send(tx);
1308 T.start;
1309
1310 /* Handle MGCP CRCX */
1311 alt {
1312 [] MGCP.receive(tr_CRCX) -> value mgcp_cmd {
1313 log("CRCX1", mgcp_cmd);
1314 var template MgcpResponse mgcp_rsp := f_handle_crcx(pars, mgcp_cmd);
1315 MGCP.send(valueof(mgcp_rsp));
1316 }
1317 [] T.timeout {
1318 setverdict(fail, "Timeout waiting for MGCP");
1319 }
1320 }
Neels Hofmeyr735b6562023-03-09 02:51:28 +01001321 T.stop;
Daniel Willmann19b8d902022-01-05 09:12:34 +01001322
1323 /* Expect RAB Assignment Request with IP/port from CRCX ACK via Iuh */
Pau Espin Pedrolb85ac2f2023-11-29 15:48:57 +01001324 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 +01001325 tx := valueof(ts_RANAP_RabAssReq(rab_sml));
1326
Neels Hofmeyr735b6562023-03-09 02:51:28 +01001327 f_rua_expect(tx);
Daniel Willmann3e15b7b2022-02-21 17:07:02 +01001328}
1329
1330friend function f_rab_ass_resp(inout MgcpParameters pars) runs on ConnHdlr {
1331 var MgcpCommand mgcp_cmd;
1332 var RANAP_PDU tx;
1333 var template RAB_SetupOrModifiedList rab_smdl;
Daniel Willmann19b8d902022-01-05 09:12:34 +01001334
1335 /* Send back RAB Assignment Response via Iuh */
1336 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));
1337 tx := valueof(ts_RANAP_RabAssResp(rab_smdl));
1338 RUA.send(tx);
Daniel Willmann19b8d902022-01-05 09:12:34 +01001339
1340 interleave {
1341 /* Expect MDCX with IP/port from RAB Assignment Response */
1342 [] 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 +01001343 var HostName mgw_rtp_ip;
Pau Espin Pedrolaf746502023-11-29 16:18:28 +01001344 var boolean exp_rua_rab_reass := false;
Daniel Willmann19b8d902022-01-05 09:12:34 +01001345 log("MDCX1", mgcp_cmd);
Pau Espin Pedrol0c35a632023-11-29 16:00:35 +01001346 if (ispresent(pars.mgw_conn_ran.mgw_rtp_ip_mdcx)) {
1347 mgw_rtp_ip := pars.mgw_conn_ran.mgw_rtp_ip_mdcx;
Pau Espin Pedrolaf746502023-11-29 16:18:28 +01001348 if (pars.mgw_conn_ran.mgw_rtp_ip != pars.mgw_conn_ran.mgw_rtp_ip_mdcx) {
1349 exp_rua_rab_reass := true;
1350 }
Pau Espin Pedrol0c35a632023-11-29 16:00:35 +01001351 } else {
1352 mgw_rtp_ip := pars.mgw_conn_ran.mgw_rtp_ip;
1353 }
1354
Daniel Willmann19b8d902022-01-05 09:12:34 +01001355 /* Verify SDP of MDCX */
Pau Espin Pedrol0c35a632023-11-29 16:00:35 +01001356 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 +01001357 { 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 +01001358 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 +01001359 MGCP.send(valueof(mgcp_rsp));
Pau Espin Pedrolaf746502023-11-29 16:18:28 +01001360
1361 /* If IP address changed, we expect HNBGW to Modify the RAB through RAB-Ass-Req: */
1362 if (exp_rua_rab_reass) {
1363 var template RAB_SetupOrModifyList rab_sml;
1364 /* Expect RAB Assignment Request with IP/port from MDCX ACK via Iuh */
1365 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));
1366 tx := valueof(ts_RANAP_RabAssReq(rab_sml));
1367
1368 f_rua_expect(tx);
1369 /* Send back RAB Assignment Response via Iuh */
1370 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));
1371 tx := valueof(ts_RANAP_RabAssResp(rab_smdl));
1372 RUA.send(tx);
1373 /* This shouldn't trigger any MGCP, since nothing changed on the HNB IP side. Continue below. */
1374 }
Daniel Willmann19b8d902022-01-05 09:12:34 +01001375 }
1376 /* Handle CRCX for second leg of endpoint, answer with IP/port */
1377 [] MGCP.receive(tr_CRCX(pars.mgcp_ep, tr_SDP(pars.cn_rtp_ip, pars.cn_rtp_port))) -> value mgcp_cmd {
1378 log("CRCX2", mgcp_cmd);
1379 /* Verify SDP of CRCX */
1380 var template MgcpResponse mgcp_rsp := f_handle_crcx(pars, mgcp_cmd);
1381 MGCP.send(valueof(mgcp_rsp));
1382 }
1383 }
1384
1385 /* Expect RAB Assignment Response with IP/port from second CRCX ACK */
Pau Espin Pedrolb85ac2f2023-11-29 15:48:57 +01001386 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 +01001387 tx := valueof(ts_RANAP_RabAssResp(rab_smdl));
1388
Neels Hofmeyrdc416c92023-03-09 02:47:50 +01001389 f_bssap_expect(tx);
Daniel Willmann19b8d902022-01-05 09:12:34 +01001390}
1391
1392private altstep as_mgcp_dlcx(inout TestHdlrParams pars) runs on ConnHdlr {
1393 var MgcpCommand mgcp_cmd;
1394
1395 [] MGCP.receive(tr_DLCX(pars.mgcp_pars.mgcp_ep)) -> value mgcp_cmd {
1396 log("DLCX", mgcp_cmd);
1397 MGCP.send(ts_DLCX_ACK2(mgcp_cmd.line.trans_id));
1398 pars.mgcp_pars.got_dlcx_count := pars.mgcp_pars.got_dlcx_count + 1;
Daniel Willmann3e15b7b2022-02-21 17:07:02 +01001399 if (pars.mgcp_pars.got_dlcx_count != pars.mgcp_pars.got_crcx_count) {
Daniel Willmann19b8d902022-01-05 09:12:34 +01001400 repeat;
1401 }
1402 setverdict(pass);
1403 }
1404}
1405
1406friend function f_tc_rab_assignment(charstring id, TestHdlrParams pars) runs on ConnHdlr {
1407 var MgcpCommand mgcp_cmd;
1408 var RANAP_PDU tx;
1409 timer T := 5.0;
1410
1411 f_init_handler(pars);
1412 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
1413
1414 tx := f_build_initial_ue(g_pars);
1415 f_iuh2iu_connect(tx);
1416
1417 f_create_rab(pars.mgcp_pars);
1418
1419 /* Send Iu Release */
1420 tx := valueof(ts_RANAP_IuReleaseCommand(ts_RanapCause_om_intervention));
1421 f_iu2iuh(tx);
1422
1423 T.start;
1424 alt {
1425 [] as_mgcp_dlcx(pars) {}
1426 [] T.timeout {
1427 setverdict(fail, "Timeout waiting for DLCX");
1428 }
1429 }
1430
1431 tx := valueof(ts_RANAP_IuReleaseComplete());
1432 f_iuh2iu(tx);
1433}
1434
1435testcase TC_rab_assignment() runs on test_CT {
1436 var ConnHdlr vc_conn;
Pau Espin Pedrol83a49612022-09-12 21:11:05 +02001437 g_num_hnbs := 1;
Daniel Willmann19b8d902022-01-05 09:12:34 +01001438 f_init();
Daniel Willmann19b8d902022-01-05 09:12:34 +01001439
1440 vc_conn := f_start_handler_with_pars(refers(f_tc_rab_assignment), t_pars(3));
1441 vc_conn.done;
Neels Hofmeyr3a9140e2023-06-23 04:50:39 +02001442
1443 f_shutdown_helper();
Daniel Willmann19b8d902022-01-05 09:12:34 +01001444}
1445
Daniel Willmann3e15b7b2022-02-21 17:07:02 +01001446friend function f_tc_rab_assign_fail(charstring id, TestHdlrParams pars) runs on ConnHdlr {
1447 var MgcpCommand mgcp_cmd;
1448 var RANAP_PDU tx;
1449 timer T := 5.0;
1450
1451 f_init_handler(pars);
1452 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
1453
1454 tx := f_build_initial_ue(g_pars);
1455 f_iuh2iu_connect(tx);
1456
1457 f_rab_ass_req(pars.mgcp_pars);
1458
1459 /* Send RAB failed list in response */
1460 tx := valueof(ts_RANAP_RabAssResp(rab_fl := ts_RAB_FL(t_RAB_id(23), ts_RanapCause_om_intervention)));
1461 f_iuh2iu(tx);
1462
1463 T.start;
1464 alt {
1465 [] as_mgcp_dlcx(pars) {}
1466 [] T.timeout {
1467 setverdict(fail, "Timeout waiting for DLCX");
1468 }
1469 }
1470}
1471
1472testcase TC_rab_assign_fail() runs on test_CT {
1473 var ConnHdlr vc_conn;
Pau Espin Pedrol83a49612022-09-12 21:11:05 +02001474 g_num_hnbs := 1;
Daniel Willmann3e15b7b2022-02-21 17:07:02 +01001475 f_init();
Daniel Willmann3e15b7b2022-02-21 17:07:02 +01001476
1477 vc_conn := f_start_handler_with_pars(refers(f_tc_rab_assign_fail), t_pars(4));
1478 vc_conn.done;
Neels Hofmeyr3a9140e2023-06-23 04:50:39 +02001479
1480 f_shutdown_helper();
Daniel Willmann3e15b7b2022-02-21 17:07:02 +01001481}
1482
Daniel Willmann19b8d902022-01-05 09:12:34 +01001483friend function f_tc_rab_release(charstring id, TestHdlrParams pars) runs on ConnHdlr {
1484 var MgcpCommand mgcp_cmd;
1485 var RANAP_PDU tx;
1486 timer T := 15.0;
1487
1488 f_init_handler(pars);
1489 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
1490
1491 tx := f_build_initial_ue(g_pars);
1492 f_iuh2iu_connect(tx);
1493
1494 f_create_rab(pars.mgcp_pars);
1495
1496 /* Send RAB Release */
Daniel Willmann9e789be2022-02-22 13:30:51 +01001497 tx := valueof(ts_RANAP_RabAssReq(rab_rl := ts_RAB_RL(t_RAB_id(23), ts_RanapCause_om_intervention)));
Daniel Willmann19b8d902022-01-05 09:12:34 +01001498 BSSAP.send(tx);
1499
1500 T.start;
1501
1502 alt {
1503 [] as_mgcp_dlcx(pars) {}
1504 [] T.timeout {
1505 setverdict(fail, "Timeout waiting for DLCX");
1506 }
1507 }
Neels Hofmeyr735b6562023-03-09 02:51:28 +01001508 T.stop;
Daniel Willmann19b8d902022-01-05 09:12:34 +01001509
Neels Hofmeyr735b6562023-03-09 02:51:28 +01001510 f_rua_expect(tx);
Daniel Willmann19b8d902022-01-05 09:12:34 +01001511}
1512
1513testcase TC_rab_release() runs on test_CT {
1514 var ConnHdlr vc_conn;
Pau Espin Pedrol83a49612022-09-12 21:11:05 +02001515 g_num_hnbs := 1;
Daniel Willmann19b8d902022-01-05 09:12:34 +01001516 f_init();
Daniel Willmann19b8d902022-01-05 09:12:34 +01001517
1518 vc_conn := f_start_handler_with_pars(refers(f_tc_rab_release), t_pars(5));
1519 vc_conn.done;
Neels Hofmeyr3a9140e2023-06-23 04:50:39 +02001520
1521 f_shutdown_helper();
Daniel Willmann19b8d902022-01-05 09:12:34 +01001522}
1523
Daniel Willmann37c877f2022-02-22 16:47:06 +01001524friend function f_tc_rab_assign_mgcp_to(charstring id, TestHdlrParams pars) runs on ConnHdlr {
1525 var MgcpCommand mgcp_cmd;
1526 var RANAP_PDU tx;
1527 var template RAB_SetupOrModifyList rab_sml;
1528 timer T := 15.0;
1529
1530 T.start;
1531 f_init_handler(pars);
1532 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
1533
1534 tx := f_build_initial_ue(g_pars);
1535 f_iuh2iu_connect(tx);
1536
1537
1538 /* Send RAB Assignment Request */
1539 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));
1540 tx := valueof(ts_RANAP_RabAssReq(rab_sml));
1541 BSSAP.send(tx);
1542
1543 /* Ignore MGCP CRCX */
1544 alt {
1545 [] MGCP.receive(tr_CRCX) -> value mgcp_cmd {
1546 log("Ignoreing CRCX1", mgcp_cmd);
1547 repeat;
1548 }
1549 [] BSSAP.receive(tr_RANAP_IuReleaseRequest(?)) { }
1550 [] T.timeout {
1551 setverdict(fail, "Timeout waiting for IuRelease");
1552 }
1553 }
1554
1555 /* Send Iu Release */
1556 tx := valueof(ts_RANAP_IuReleaseCommand(ts_RanapCause_om_intervention));
1557 f_iu2iuh(tx);
1558
1559 tx := valueof(ts_RANAP_IuReleaseComplete());
1560 f_iuh2iu(tx);
1561}
1562
1563testcase TC_rab_assign_mgcp_to() runs on test_CT {
1564 var ConnHdlr vc_conn;
Pau Espin Pedrol83a49612022-09-12 21:11:05 +02001565 g_num_hnbs := 1;
Daniel Willmann37c877f2022-02-22 16:47:06 +01001566 f_init();
Daniel Willmann37c877f2022-02-22 16:47:06 +01001567
1568 vc_conn := f_start_handler_with_pars(refers(f_tc_rab_assign_mgcp_to), t_pars(6));
1569 vc_conn.done;
Neels Hofmeyr3a9140e2023-06-23 04:50:39 +02001570
1571 f_shutdown_helper();
Daniel Willmann37c877f2022-02-22 16:47:06 +01001572}
1573
Pau Espin Pedrolaf746502023-11-29 16:18:28 +01001574/* Test case where IuUP IP address announced by HNB and updated through MDCX
1575 * makes MGW select a new local IuUP address. HNBGW is expected to update the HNB
1576 * through RAB-Modify-Req. */
1577testcase TC_rab_assign_mgw_iuup_addr_chg() runs on test_CT {
1578 var ConnHdlr vc_conn;
1579 g_num_hnbs := 1;
1580 f_init();
1581 var template (value) TestHdlrParams pars := t_pars(3);
1582 /* Emulate change of local IuUP IP address after rx MDCX: */
1583 pars.mgcp_pars.mgw_conn_ran.mgw_rtp_ip_mdcx := "127.3.2.1";
1584
1585 vc_conn := f_start_handler_with_pars(refers(f_tc_rab_assignment), pars);
1586 vc_conn.done;
1587
1588 f_shutdown_helper();
1589}
1590
Daniel Willmann19b8d902022-01-05 09:12:34 +01001591/* Create an Iuh connection; send InitialUE; transceive data both directions */
1592friend function f_tc_ranap_bidir(charstring id, TestHdlrParams pars) runs on ConnHdlr {
1593 f_init_handler(pars);
1594
1595 /* HNB -> MSC: InitialUE */
1596 f_iuh2iu_connect(f_build_initial_ue(g_pars));
1597
1598 /* MSC <- HNB: DirectTransfer */
1599 f_iu2iuh(ts_RANAP_DirectTransfer(f_rnd_octstring(10)));
1600 /* MSC -> HNB: DirectTransfer */
1601 f_iuh2iu(ts_RANAP_DirectTransfer(f_rnd_octstring(10)));
1602
1603 /* HNB <- MSC: CommonID */
1604 f_iu2iuh(ts_RANAP_CommonId(hex2oct(pars.imsi)));
1605}
1606testcase TC_ranap_cs_bidir() runs on test_CT {
1607 var ConnHdlr vc_conn;
Pau Espin Pedrol83a49612022-09-12 21:11:05 +02001608 g_num_hnbs := 1;
Daniel Willmann19b8d902022-01-05 09:12:34 +01001609 f_init();
Daniel Willmann19b8d902022-01-05 09:12:34 +01001610
1611 vc_conn := f_start_handler_with_pars(refers(f_tc_ranap_bidir), t_pars(3));
1612 vc_conn.done;
Neels Hofmeyr3a9140e2023-06-23 04:50:39 +02001613
1614 f_shutdown_helper();
Daniel Willmann19b8d902022-01-05 09:12:34 +01001615}
1616testcase TC_ranap_ps_bidir() runs on test_CT {
1617 var ConnHdlr vc_conn;
Pau Espin Pedrol83a49612022-09-12 21:11:05 +02001618 g_num_hnbs := 1;
Daniel Willmann19b8d902022-01-05 09:12:34 +01001619 f_init();
Daniel Willmann19b8d902022-01-05 09:12:34 +01001620
1621 vc_conn := f_start_handler_with_pars(refers(f_tc_ranap_bidir), t_pars(4, true));
1622 vc_conn.done;
Neels Hofmeyr3a9140e2023-06-23 04:50:39 +02001623
1624 f_shutdown_helper();
Daniel Willmann19b8d902022-01-05 09:12:34 +01001625}
1626
1627
1628private function f_tc_ranap_mo_disconnect(charstring id, TestHdlrParams pars) runs on ConnHdlr {
1629 f_init_handler(pars);
1630
1631 /* HNB -> MSC: InitialUE */
1632 f_iuh2iu_connect(f_build_initial_ue(g_pars));
1633
1634 /* MSC <- HNB: DirectTransfer */
1635 f_iu2iuh(ts_RANAP_DirectTransfer(f_rnd_octstring(10)));
1636 /* MSC -> HNB: DirectTransfer */
1637 f_iuh2iu(ts_RANAP_DirectTransfer(f_rnd_octstring(10)));
1638
1639 /* MSC <- HNB: RUA disconnect */
1640 f_iuh2iu_disconnect(ts_RANAP_IuReleaseComplete, RUA_IEs.Cause:{misc:=processing_overload});
1641}
1642testcase TC_ranap_cs_mo_disconnect() runs on test_CT {
1643 var ConnHdlr vc_conn;
Pau Espin Pedrol83a49612022-09-12 21:11:05 +02001644 g_num_hnbs := 1;
Daniel Willmann19b8d902022-01-05 09:12:34 +01001645 f_init();
Daniel Willmann19b8d902022-01-05 09:12:34 +01001646
1647 vc_conn := f_start_handler_with_pars(refers(f_tc_ranap_mo_disconnect), t_pars(5));
1648 vc_conn.done;
Neels Hofmeyr3a9140e2023-06-23 04:50:39 +02001649
1650 f_shutdown_helper();
Daniel Willmann19b8d902022-01-05 09:12:34 +01001651}
1652testcase TC_ranap_ps_mo_disconnect() runs on test_CT {
1653 var ConnHdlr vc_conn;
Pau Espin Pedrol83a49612022-09-12 21:11:05 +02001654 g_num_hnbs := 1;
Daniel Willmann19b8d902022-01-05 09:12:34 +01001655 f_init();
Daniel Willmann19b8d902022-01-05 09:12:34 +01001656
1657 vc_conn := f_start_handler_with_pars(refers(f_tc_ranap_mo_disconnect), t_pars(6));
1658 vc_conn.done;
Neels Hofmeyr3a9140e2023-06-23 04:50:39 +02001659
1660 f_shutdown_helper();
Daniel Willmann19b8d902022-01-05 09:12:34 +01001661}
1662
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001663type record FTeid {
1664 HostName addr,
1665 OCT4 teid
1666}
1667
1668type record FTeids {
1669 FTeid local,
1670 FTeid remote
1671}
Daniel Willmann19b8d902022-01-05 09:12:34 +01001672
1673
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001674/* 'local' and 'remote' refer to the GTP information from the UPF's point of view:
1675 * HNB UPF CN
1676 * access.remote <---> access.local | core.local <---> core.remote
1677 */
1678type record GtpParameters {
1679 FTeids core,
1680 FTeids access
1681}
1682
1683/* HNB UPF CN
1684 * access.remote <---> access.local | core.local <---> core.remote
1685 * 127.0.0.4 127.0.0.3 127.0.0.2 127.0.0.1
1686 * 0x44004400 0x30303030 0x22002200 0x10101010
1687 */
1688template GtpParameters t_GtpParameters := {
1689 core := {
1690 local := {
1691 addr := "127.0.0.2",
1692 teid := '22002200'O
1693 },
1694 remote := {
1695 addr := "127.0.0.1",
1696 teid := '10101010'O
1697 }
1698 },
1699 access := {
1700 local := {
1701 addr := "127.0.0.3",
1702 teid := '30303030'O
1703 },
1704 remote := {
1705 addr := "127.0.0.4",
1706 teid := '44004400'O
1707 }
1708 }
1709}
1710
Neels Hofmeyr65499282023-04-25 02:31:51 +02001711private 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 +01001712{
1713 var PDU_PFCP rx;
Neels Hofmeyr65499282023-04-25 02:31:51 +02001714 timer T := wait_time;
Neels Hofmeyr6bbfe052023-03-09 02:51:46 +01001715 T.start;
1716 alt {
1717 [] PFCP.receive(exp_rx) -> value rx {
1718 setverdict(pass);
1719 }
1720 [] PFCP.receive(PDU_PFCP:?) {
1721 setverdict(fail, "Got an unexpected PFCP message, was waiting for ", exp_rx);
1722 mtc.stop;
1723 }
1724 [] T.timeout {
1725 setverdict(fail, "Timeout waiting for PFCP ", exp_rx);
1726 mtc.stop;
1727 }
1728 }
1729 T.stop;
1730 return rx;
1731}
1732
Neels Hofmeyrbacb74f2022-08-29 16:24:12 +02001733friend function f_tc_ps_rab_assignment_with_pfcp(charstring id, TestHdlrParams pars) runs on ConnHdlr {
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001734 var RANAP_PDU tx;
1735 var RANAP_PDU rx;
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001736
1737 f_init_handler(pars);
1738
1739 f_pfcp_register();
1740
1741 var PDU_PFCP m;
1742 var Node_ID upf_node_id := valueof(ts_PFCP_Node_ID_fqdn("\07osmocom\03org"));
1743
Neels Hofmeyr65499282023-04-25 02:31:51 +02001744 m := f_pfcp_expect(tr_PFCP_Assoc_Setup_Req(), wait_time := 15.0);
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001745 PFCP.send(ts_PFCP_Assoc_Setup_Resp(m.sequence_number, upf_node_id,
1746 ts_PFCP_Cause(REQUEST_ACCEPTED), 1234));
1747
1748 tx := f_build_initial_ue(g_pars);
1749 f_iuh2iu_connect(tx);
1750
1751 var GtpParameters gtp_pars := valueof(t_GtpParameters);
1752 var template RAB_SetupOrModifyList rab_sml;
1753
1754 /* Send RAB Assignment Request */
1755 rab_sml := ts_RAB_SML_ps(t_RAB_id(23), f_ts_RAB_TLA(gtp_pars.core.remote.addr), gtp_pars.core.remote.teid);
1756 tx := valueof(ts_RANAP_RabAssReq(rab_sml));
1757 BSSAP.send(tx);
1758
1759 /* Expect PFCP Session Establishment Request. */
Neels Hofmeyr6bbfe052023-03-09 02:51:46 +01001760 m := f_pfcp_expect(tr_PFCP_Session_Est_Req());
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001761 var F_SEID hnbgw_f_seid := m.message_body.pfcp_session_establishment_request.CP_F_SEID;
1762 var PFCP_Session_Establishment_Request serq := m.message_body.pfcp_session_establishment_request;
1763
1764 /* Acting as UPF, invent a new PFCP SEID to send to HNBGW. Respond to the Session Establishment.
1765 * The PFCP response must have the same sequence_number as the request. */
Neels Hofmeyr1e311462023-01-11 01:19:12 +01001766 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 +02001767 var template PDU_PFCP r := ts_PFCP_Session_Est_Resp(m.sequence_number, upf_node_id, hnbgw_f_seid.seid);
1768 r.message_body.pfcp_session_establishment_response := {
1769 offending_ie := omit,
1770 UP_F_SEID := up_f_seid,
1771 created_PDR_list := {
1772 ts_PFCP_Created_PDR(pdr_id := serq.create_PDR_list[0].grouped_ie.pdr_id,
1773 local_F_TEID := ts_PFCP_F_TEID_ipv4(gtp_pars.core.local.teid,
Neels Hofmeyr1e311462023-01-11 01:19:12 +01001774 f_inet_addr(gtp_pars.core.local.addr))),
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001775 ts_PFCP_Created_PDR(pdr_id := serq.create_PDR_list[1].grouped_ie.pdr_id,
1776 local_F_TEID := ts_PFCP_F_TEID_ipv4(gtp_pars.access.local.teid,
Neels Hofmeyr1e311462023-01-11 01:19:12 +01001777 f_inet_addr(gtp_pars.access.local.addr)))
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001778 },
1779 load_control_information := omit,
1780 overload_control_information := omit,
1781 node_list := omit,
1782 failed_rule_id := omit,
1783 created_traffic_endpoint_list := omit
1784 };
1785 PFCP.send(r);
1786
1787 /* Expect on Iuh: RAB Assignment Request with IP/port from PFCP Session Est Resp */
1788 rab_sml := ts_RAB_SML_ps(t_RAB_id(23), f_ts_RAB_TLA(gtp_pars.access.local.addr),
1789 gtp_pars.access.local.teid);
1790 rx := valueof(ts_RANAP_RabAssReq(rab_sml));
Neels Hofmeyr735b6562023-03-09 02:51:28 +01001791 f_rua_expect(rx);
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001792
1793 /* Send back RAB Assignment Response via Iuh */
1794 var template RAB_SetupOrModifiedList rab_smdl;
1795 rab_smdl := ts_RAB_SMdL_ps(t_RAB_id(23), f_ts_RAB_TLA(gtp_pars.access.remote.addr),
1796 gtp_pars.access.remote.teid);
1797 tx := valueof(ts_RANAP_RabAssResp(rab_smdl));
1798 RUA.send(tx);
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001799
Neels Hofmeyr6bbfe052023-03-09 02:51:46 +01001800 m := f_pfcp_expect(tr_PFCP_Session_Mod_Req(up_f_seid.seid));
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001801 r := ts_PFCP_Session_Mod_Resp(m.sequence_number, hnbgw_f_seid.seid);
1802 PFCP.send(r);
1803
1804 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 +01001805 f_bssap_expect(tr_RANAP_RabAssResp(rab_smdl));
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001806
1807 f_sleep(2.0);
1808 tx := valueof(ts_RANAP_IuReleaseCommand(ts_RanapCause_om_intervention));
1809 f_iu2iuh(tx);
1810
1811 tx := valueof(ts_RANAP_IuReleaseComplete());
1812 f_iuh2iu(tx);
1813
Neels Hofmeyr6bbfe052023-03-09 02:51:46 +01001814 m := f_pfcp_expect(tr_PFCP_Session_Del_Req(up_f_seid.seid));
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001815 PFCP.send(ts_PFCP_Session_Del_Resp(m.sequence_number, hnbgw_f_seid.seid));
1816
1817 f_sleep(2.0);
1818}
1819
Neels Hofmeyrbacb74f2022-08-29 16:24:12 +02001820testcase TC_ps_rab_assignment_with_pfcp() runs on test_CT {
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001821 var ConnHdlr vc_conn;
Pau Espin Pedrol83a49612022-09-12 21:11:05 +02001822 g_num_hnbs := 1;
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001823 f_init();
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001824 f_sleep(1.0);
1825
Neels Hofmeyrbacb74f2022-08-29 16:24:12 +02001826 vc_conn := f_start_handler_with_pars(refers(f_tc_ps_rab_assignment_with_pfcp), t_pars(7, ps_domain := true));
1827 vc_conn.done;
Neels Hofmeyr3a9140e2023-06-23 04:50:39 +02001828
1829 f_shutdown_helper();
Neels Hofmeyrbacb74f2022-08-29 16:24:12 +02001830}
1831
1832altstep as_disallow_pfcp() runs on ConnHdlr {
1833 [] PFCP.receive(PDU_PFCP:?) {
1834 setverdict(fail, "Received PFCP message, but no PFCP communication expected");
1835 mtc.stop;
1836 }
1837}
1838
1839friend function f_tc_ps_rab_assignment_without_pfcp(charstring id, TestHdlrParams pars) runs on ConnHdlr {
1840 var RANAP_PDU tx;
1841 var RANAP_PDU rx;
1842 timer T := 5.0;
1843
1844 f_init_handler(pars);
1845
1846 f_pfcp_register();
1847 activate(as_disallow_pfcp());
1848
1849 tx := f_build_initial_ue(g_pars);
1850 f_iuh2iu_connect(tx);
1851
1852 var GtpParameters gtp_pars := valueof(t_GtpParameters);
1853 var template RAB_SetupOrModifyList rab_sml;
1854
1855 /* Send RAB Assignment Request */
1856 rab_sml := ts_RAB_SML_ps(t_RAB_id(23), f_ts_RAB_TLA(gtp_pars.core.remote.addr), gtp_pars.core.remote.teid);
1857 tx := valueof(ts_RANAP_RabAssReq(rab_sml));
1858 BSSAP.send(tx);
1859
1860 /* Expect on Iuh: unmodified RAB Assignment Request */
1861 rx := valueof(ts_RANAP_RabAssReq(rab_sml));
Neels Hofmeyr735b6562023-03-09 02:51:28 +01001862 f_rua_expect(rx);
Neels Hofmeyrbacb74f2022-08-29 16:24:12 +02001863
1864 /* Send back RAB Assignment Response via Iuh */
1865 var template RAB_SetupOrModifiedList rab_smdl;
1866 rab_smdl := ts_RAB_SMdL_ps(t_RAB_id(23), f_ts_RAB_TLA(gtp_pars.access.remote.addr),
1867 gtp_pars.access.remote.teid);
1868 tx := valueof(ts_RANAP_RabAssResp(rab_smdl));
1869 RUA.send(tx);
1870
1871 /* Expect on IuPS: unmodified RAB Assignment Response */
Neels Hofmeyrdc416c92023-03-09 02:47:50 +01001872 f_bssap_expect(tr_RANAP_RabAssResp(rab_smdl));
Neels Hofmeyrbacb74f2022-08-29 16:24:12 +02001873
1874 f_sleep(2.0);
1875 tx := valueof(ts_RANAP_IuReleaseCommand(ts_RanapCause_om_intervention));
1876 f_iu2iuh(tx);
1877
1878 tx := valueof(ts_RANAP_IuReleaseComplete());
1879 f_iuh2iu(tx);
1880
1881 f_sleep(2.0);
1882}
1883
1884testcase TC_ps_rab_assignment_without_pfcp() runs on test_CT {
1885 var ConnHdlr vc_conn;
1886 f_init();
Neels Hofmeyrbacb74f2022-08-29 16:24:12 +02001887 f_sleep(1.0);
1888
1889 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 +02001890 vc_conn.done;
Neels Hofmeyr3a9140e2023-06-23 04:50:39 +02001891
1892 f_shutdown_helper();
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001893}
Daniel Willmann19b8d902022-01-05 09:12:34 +01001894
Neels Hofmeyr7d0e6802023-04-20 20:43:55 +02001895/* Default list of counters for a 'cn' entity to test the cnpool feature. */
1896const CounterNameVals counternames_cnpool := {
1897 { "cnpool:subscr:new", 0 },
1898 { "cnpool:subscr:known", 0 },
1899 { "cnpool:subscr:reattach", 0 },
1900 { "cnpool:subscr:attach_lost", 0 },
1901 { "cnpool:subscr:paged", 0 }
1902};
1903private function f_ctrs_cn_init(boolean ps_domain, integer cn_count := 0,
1904 CounterNameVals counternames := counternames_cnpool) runs on test_CT {
1905 if (ps_domain) {
1906 g_ctr_cn_node_name := "sgsn";
1907 if (cn_count == 0) {
1908 cn_count := NUM_SGSN;
1909 }
1910 } else {
1911 g_ctr_cn_node_name := "msc";
1912 if (cn_count == 0) {
1913 cn_count := NUM_MSC;
1914 }
1915 }
1916 g_ctr_cn := f_counter_name_vals_get_n(IPA_CTRL, g_ctr_cn_node_name, cn_count, counternames);
1917 log("initial " & g_ctr_cn_node_name & " rate counters: ", g_ctr_cn);
1918}
1919
1920/* f_ctrs_cn_init();
1921 * f_do_thing(on_cn := 0);
1922 * f_do_thing(on_cn := 0);
1923 * f_do_other(on_cn := 1);
1924 * f_ctrs_cn_add(0, "thing", 2);
1925 * f_ctrs_cn_add(1, "other");
1926 * f_ctrs_cn_verify();
1927 */
1928private function f_ctrs_cn_verify() runs on test_CT {
1929 log("verifying", g_ctr_cn_node_name, " rate counters: ", g_ctr_cn);
1930 f_counter_name_vals_expect_n(IPA_CTRL, g_ctr_cn_node_name, g_ctr_cn);
1931}
1932
1933/* convenience: f_ctrs_cn_add() and f_ctrs_cn_verify() in one call.
1934 * f_ctrs_cn_init();
1935 * f_do_thing(on_cn := 0);
1936 * f_do_thing(on_cn := 0);
1937 * f_do_thing(on_cn := 0);
1938 * f_ctrs_cn_expect(0, "thing", 3);
1939 */
1940private function f_ctrs_cn_expect(integer cn_nr, charstring countername, integer val := 1) runs on test_CT {
1941 f_ctrs_cn_add(cn_nr, countername, val);
1942 f_ctrs_cn_verify();
1943}
1944
1945private function f_ctrs_cn_add(integer cn_nr, charstring countername, integer val := 1) runs on test_CT {
1946 f_counter_name_vals_list_add(g_ctr_cn, cn_nr, countername, val);
1947}
1948
1949private function f_perform_compl_l3(octetstring nas, boolean do_clear := true, boolean expect_iu_l3 := true)
1950runs on ConnHdlr {
1951 timer T := 10.0;
1952
1953 /* create an expect on the Iu side for the random NAS portion */
1954 if (g_pars.expect_separate_sccp_cr) {
1955 f_ran_register_sccp_cr_without_payload();
1956 } else {
1957 f_ran_register_exp(nas);
1958 }
1959
1960 /* send Connect via Iuh (creating a RUA connection) */
1961 var RANAP_PDU tx := f_build_initial_ue_with_nas(g_pars, nas);
1962 RUA.send(RUA_Conn_Req:{g_pars.ps_domain, tx});
1963
1964 if (expect_iu_l3) {
1965 /* Expect same message to arrive at CN */
1966 f_bssap_expect(tx);
1967 }
1968}
1969
1970private function f_tc_cnpool_compl_l3(charstring id, TestHdlrParams pars) runs on ConnHdlr {
1971 f_init_handler(pars);
1972 f_perform_compl_l3(g_pars.nas_pdu);
1973}
1974
1975private function f_TC_cnpool_compl_l3(boolean ps_domain, octetstring nas_pdu, integer cn_nr,
1976 template (omit) charstring inc_countername := omit) runs on test_CT {
1977 var ConnHdlr vc_conn;
1978 var template (value) TestHdlrParams pars := t_pars(0, ps_domain := ps_domain, cn_nr := cn_nr);
1979 pars.nas_pdu := nas_pdu;
1980 log("XXX ", pars);
1981 vc_conn := f_start_handler_with_pars(refers(f_tc_cnpool_compl_l3), pars);
1982 vc_conn.done;
1983
1984 if (not istemplatekind(inc_countername, "omit")) {
1985 f_ctrs_cn_expect(cn_nr, valueof(inc_countername));
1986 }
1987}
1988
1989function f_TC_cnpool_compl_l3_list(boolean ps_domain, ro_octetstring compl3, Osmocom_Types.ro_integer cn_nrs,
1990 charstring inc_countername) runs on test_CT {
1991 var integer n := lengthof(compl3);
1992 if (n < lengthof(cn_nrs)) {
1993 n := lengthof(cn_nrs);
1994 }
1995 for (var integer i := 0; i < n; i := i + 1) {
1996 var integer cn_nr := cn_nrs[i mod lengthof(cn_nrs)];
1997 f_TC_cnpool_compl_l3(ps_domain, compl3[i mod lengthof(compl3)], cn_nr, inc_countername);
1998 }
1999}
2000
2001type enumerated Compl3Type {
2002 /* CS */
2003 LU,
2004 CMSERV,
2005 PAGRESP,
2006 IMSIDETACH,
2007
2008 /* PS */
2009 ATTACHREQ,
2010 RAUREQ,
2011 DETREQ
2012};
2013
2014private function f_gen_one_compl_l3(Compl3Type compl3type, template (value) MobileIdentityLV mi,
2015 integer ps_nri := -1
2016 ) return octetstring
2017{
2018 /* CS */
2019 if (compl3type == LU) {
2020 return enc_PDU_ML3_MS_NW(valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(mi), '00F110'O)));
2021 }
2022 if (compl3type == CMSERV) {
2023 return enc_PDU_ML3_MS_NW(valueof(ts_CM_SERV_REQ(CM_TYPE_MO_CALL, valueof(mi))));
2024 }
2025 if (compl3type == PAGRESP) {
2026 return enc_PDU_ML3_MS_NW(valueof(ts_PAG_RESP(valueof(mi))));
2027 }
2028 if (compl3type == IMSIDETACH) {
2029 return enc_PDU_ML3_MS_NW(valueof(ts_ML3_MO_MM_IMSI_DET_Ind(valueof(mi))));
2030 }
2031
2032 /* PS */
2033 var template (omit) NetworkResourceIdentifierContainerTLV nri := omit;
2034 if (ps_nri >= 0) {
2035 nri := valueof(ts_GMM_NRI(ps_nri));
2036 }
2037
2038 if (compl3type == ATTACHREQ) {
2039 return enc_PDU_L3_MS_SGSN(valueof(ts_GMM_ATTACH_REQ(valueof(mi), f_RAI('001'H, '01'H, '2a2a'O, '17'O),
2040 nri := nri)));
2041 }
2042 if (compl3type == RAUREQ) {
2043 return enc_PDU_L3_MS_SGSN(valueof(ts_GMM_RAU_REQ(valueof(mi), GPRS_UPD_T_PERIODIC,
2044 f_RAI('001'H, '01'H, '2a2a'O, '17'O),
2045 nri := nri)));
2046 }
2047 if (compl3type == DETREQ) {
2048 return enc_PDU_L3_MS_SGSN(valueof(ts_GMM_DET_REQ_MO_mi(c_GMM_DTT_MO_GPRS, power_off := false,
2049 p_tmsi := valueof(ts_MI_TLV(mi.mobileIdentityV)))));
2050 }
2051
2052 setverdict(fail, "unknown complete layer 3 type");
2053 mtc.stop;
2054}
2055
2056type record of Compl3Type ro_Compl3Type;
2057type record of MobileIdentityLV ro_MobileIdentityLV;
2058type record of octetstring ro_octetstring;
2059
2060/* Generate a list of n Complete Layer 3 NAS PDUs,
2061 * rotating through the message kinds listed in 'types' and the mobile identities in mis.
2062 */
2063private function f_gen_compl_l3(ro_Compl3Type types, ro_MobileIdentityLV mis, integer n) return ro_octetstring
2064{
2065 var ro_octetstring res := {};
2066 for (var integer i := 0; i < n; i := i + 1) {
2067 var integer ti := i mod lengthof(types);
2068 var integer mi := i mod lengthof(mis);
2069 res[i] := f_gen_one_compl_l3(types[ti], mis[mi]);
2070 }
2071 return res;
2072}
2073
2074private function f_gen_mi_imsi(integer n) return MobileIdentityLV
2075{
2076 return valueof(ts_MI_IMSI_LV(f_gen_imsi(n)));
2077}
2078
2079private function f_gen_mi_imsis(integer n) return ro_MobileIdentityLV
2080{
2081 var ro_MobileIdentityLV mis := {};
2082 for (var integer i := 0; i < n; i := i + 1) {
2083 mis[i] := f_gen_mi_imsi(n);
2084 }
2085 return mis;
2086}
2087
2088function f_vty_set_roundrobin_next(TELNETasp_PT VTY, boolean ps_domain, integer cn_nr)
2089{
2090 var charstring msc_sgsn;
2091 if (ps_domain) {
2092 msc_sgsn := "sgsn";
2093 } else {
2094 msc_sgsn := "msc";
2095 }
2096 f_vty_transceive(VTY, "cnpool roundrobin next " & msc_sgsn & " " & int2str(cn_nr));
2097}
2098
2099private function f_gen_compl3_by_domain(boolean ps_domain, integer n, template (omit) ro_MobileIdentityLV mis := omit) return ro_octetstring{
2100 var ro_Compl3Type types;
2101 if (ps_domain) {
2102 types := { ATTACHREQ, RAUREQ, DETREQ };
2103 } else {
2104 types := { LU, CMSERV, PAGRESP, IMSIDETACH };
2105 }
2106 if (istemplatekind(mis, "omit")) {
2107 mis := f_gen_mi_imsis(n);
2108 }
2109 return f_gen_compl_l3(types, valueof(mis), n);
2110}
2111
2112/* Various Complete Layer 3 by IMSI all end up with the first MSC, because the other MSCs are not connected. */
2113testcase TC_mscpool_L3Compl_on_1_cnlink() runs on test_CT {
2114 f_TC_cnpool_L3Compl_on_1_cnlink(ps_domain := false);
2115}
2116testcase TC_sgsnpool_L3Compl_on_1_cnlink() runs on test_CT {
2117 f_TC_cnpool_L3Compl_on_1_cnlink(ps_domain := true);
2118}
2119function f_TC_cnpool_L3Compl_on_1_cnlink(boolean ps_domain) runs on test_CT {
2120
2121 f_init();
2122
2123 f_ctrs_cn_init(ps_domain := ps_domain);
2124
2125 var ro_octetstring compl3 := f_gen_compl3_by_domain(ps_domain, 4);
2126 f_TC_cnpool_compl_l3_list(ps_domain, compl3, {0, 0, 0, 0}, "cnpool:subscr:new");
2127
2128 f_shutdown_helper();
2129}
2130
2131/* Three Layer 3 Complete by IMSI are round-robin'ed across two connected MSCs */
2132testcase TC_mscpool_L3Complete_by_imsi_round_robin() runs on test_CT {
2133 f_TC_cnpool_L3Complete_by_imsi_round_robin(ps_domain := false);
2134}
2135testcase TC_sgsnpool_L3Complete_no_nri_round_robin() runs on test_CT {
2136 f_TC_cnpool_L3Complete_by_imsi_round_robin(ps_domain := true);
2137}
2138function f_TC_cnpool_L3Complete_by_imsi_round_robin(boolean ps_domain) runs on test_CT {
2139
2140 f_init(nr_msc := 2, nr_sgsn := 2);
2141 f_sleep(1.0);
2142
2143 /* Control which MSC gets chosen next by the round-robin, otherwise
2144 * would be randomly affected by which other tests ran before this. */
2145 f_vty_set_roundrobin_next(HNBGWVTY, ps_domain, 0);
2146
2147 f_ctrs_cn_init(ps_domain := ps_domain);
2148
2149 var ro_octetstring compl3 := f_gen_compl3_by_domain(ps_domain, 3);
2150
2151 f_TC_cnpool_compl_l3_list(ps_domain, compl3,
2152 /* Third Complete Layer 3 wraps back to msc 0 */
2153 cn_nrs := {0, 1, 0},
2154 inc_countername := "cnpool:subscr:new");
2155
2156 f_shutdown_helper();
2157}
2158
2159/* Three LU by TMSI are round-robin'ed across two connected MSCs, because they contain a NULL-NRI (0, 1)
2160 * (configured in osmo-hnbgw.cfg). */
2161testcase TC_mscpool_LU_by_tmsi_null_nri_0_round_robin() runs on test_CT {
2162 f_TC_cnpool_LU_by_tmsi_null_nri_N_round_robin(ps_domain := false, nri_val := 0);
2163}
2164/* 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
2165 * than that. */
2166testcase TC_mscpool_LU_by_tmsi_null_nri_1_round_robin() runs on test_CT {
2167 f_TC_cnpool_LU_by_tmsi_null_nri_N_round_robin(ps_domain := false, nri_val := 1);
2168}
2169function f_TC_cnpool_LU_by_tmsi_null_nri_N_round_robin(boolean ps_domain, integer nri_val) runs on test_CT {
2170
2171 f_init(nr_msc := 2, nr_sgsn := 2);
2172 f_sleep(1.0);
2173
2174 /* Control which MSC gets chosen next by the round-robin, otherwise
2175 * would be randomly affected by which other tests ran before this. */
2176 f_vty_set_roundrobin_next(HNBGWVTY, ps_domain, 0);
2177
2178 f_ctrs_cn_init(ps_domain := ps_domain);
2179
2180 var ro_MobileIdentityLV mis := { valueof(ts_MI_TMSI_NRI_LV(nri_val)) };
2181 var ro_octetstring compl3;
2182 if (ps_domain) {
2183 compl3 := {
2184 f_gen_one_compl_l3(ATTACHREQ, mis[0], nri_val)
2185 };
2186 } else {
2187 compl3 := f_gen_compl_l3({LU}, mis, 1);
2188 }
2189
2190 f_TC_cnpool_compl_l3_list(ps_domain, compl3,
2191 /* The third Complete Layer 3 wraps back to msc 0 */
2192 {0, 1, 0},
2193 "cnpool:subscr:reattach");
2194 f_shutdown_helper();
2195}
2196
2197/* Three Layer 3 Complete by TMSI are round-robin'ed across two connected MSCs, because they contain an NRI not
2198 * assigned to any MSC (configured in osmo-hnbgw.cfg). */
2199testcase TC_mscpool_L3Complete_by_tmsi_unassigned_nri_round_robin() runs on test_CT {
2200 f_TC_cnpool_L3Complete_by_tmsi_unassigned_nri_round_robin(ps_domain := false);
2201}
2202function f_TC_cnpool_L3Complete_by_tmsi_unassigned_nri_round_robin(boolean ps_domain) runs on test_CT {
2203
2204 f_init(nr_msc := 2, nr_sgsn := 2);
2205 f_sleep(1.0);
2206
2207 /* Control which MSC gets chosen next by the round-robin, otherwise
2208 * would be randomly affected by which other tests ran before this. */
2209 f_vty_set_roundrobin_next(HNBGWVTY, ps_domain, 0);
2210
2211 f_ctrs_cn_init(ps_domain := ps_domain);
2212
2213 /* 3 NRIs that are not assigned to any MSC */
2214 var ro_MobileIdentityLV mis := {
2215 valueof(ts_MI_TMSI_NRI_LV(1000)),
2216 valueof(ts_MI_TMSI_NRI_LV(768)),
2217 valueof(ts_MI_TMSI_NRI_LV(819))
2218 };
2219
2220 var ro_octetstring compl3 := f_gen_compl3_by_domain(ps_domain, 3, mis);
2221 f_TC_cnpool_compl_l3_list(ps_domain, compl3, { 0, 1, 0 }, "cnpool:subscr:new");
2222
2223 f_shutdown_helper();
2224}
2225
2226/* Three Layer 3 Complete by TMSI are round-robin'ed across two connected MSCs, because they contain an NRI
2227 * assigned to a CN link that is currently not connected (configured in osmo-hnbgw.cfg). */
2228testcase TC_mscpool_L3Complete_by_tmsi_valid_nri_msc_not_connected_round_robin() runs on test_CT {
2229 f_TC_cnpool_L3Complete_by_tmsi_valid_nri_msc_not_connected_round_robin(ps_domain := false);
2230}
2231function f_TC_cnpool_L3Complete_by_tmsi_valid_nri_msc_not_connected_round_robin(boolean ps_domain) runs on test_CT {
2232
2233 f_init(nr_msc := 2, nr_sgsn := 2);
2234 f_sleep(1.0);
2235
2236 /* Control which MSC gets chosen next by the round-robin, otherwise
2237 * would be randomly affected by which other tests ran before this. */
2238 f_vty_set_roundrobin_next(HNBGWVTY, ps_domain, 0);
2239
2240 f_ctrs_cn_init(ps_domain := ps_domain);
2241
2242 /* 3 NRIs that are assigned to an unconnected MSC */
2243 var ro_MobileIdentityLV mis := {
2244 valueof(ts_MI_TMSI_NRI_LV(512)),
2245 valueof(ts_MI_TMSI_NRI_LV(767)),
2246 valueof(ts_MI_TMSI_NRI_LV(750))
2247 };
2248
2249 var ro_octetstring compl3 := f_gen_compl3_by_domain(ps_domain, 3, mis);
2250
2251 f_TC_cnpool_compl_l3(ps_domain, compl3[0], cn_nr := 0);
2252 f_ctrs_cn_add(2, "cnpool:subscr:attach_lost");
2253 f_ctrs_cn_add(0, "cnpool:subscr:new");
2254 f_ctrs_cn_verify();
2255
2256 f_TC_cnpool_compl_l3(ps_domain, compl3[1], cn_nr := 1);
2257 f_ctrs_cn_add(2, "cnpool:subscr:attach_lost");
2258 f_ctrs_cn_add(1, "cnpool:subscr:new");
2259 f_ctrs_cn_verify();
2260
2261 f_TC_cnpool_compl_l3(ps_domain, compl3[2], cn_nr := 0);
2262 f_ctrs_cn_add(2, "cnpool:subscr:attach_lost");
2263 f_ctrs_cn_add(0, "cnpool:subscr:new");
2264 f_ctrs_cn_verify();
2265
2266 f_shutdown_helper();
2267}
2268
2269/* Three Layer 3 Complete by TMSI with valid NRI for the second MSC are all directed to the second MSC (configured in
2270 * osmo-hnbgw.cfg). */
2271testcase TC_mscpool_L3Complete_by_tmsi_valid_nri_1() runs on test_CT {
2272 f_TC_cnpool_L3Complete_valid_nri_1(ps_domain := false);
2273}
2274testcase TC_sgsnpool_L3Complete_valid_nri_1() runs on test_CT {
2275 f_TC_cnpool_L3Complete_valid_nri_1(ps_domain := true);
2276}
2277function f_TC_cnpool_L3Complete_valid_nri_1(boolean ps_domain) runs on test_CT {
2278
2279 f_init(nr_msc := 2, nr_sgsn := 2);
2280 f_sleep(1.0);
2281
2282 /* All TMSIs in this test point at the second MSC, set the round robin to point at the first MSC to make sure
2283 * this is not using round-robin. */
2284 f_vty_set_roundrobin_next(HNBGWVTY, ps_domain, 0);
2285
2286 f_ctrs_cn_init(ps_domain := ps_domain);
2287
2288 var ro_octetstring compl3;
2289
2290 /* 3 NRIs of the second MSC's range (256-511) */
2291 var ro_MobileIdentityLV mis := {
2292 valueof(ts_MI_TMSI_NRI_LV(256)),
2293 valueof(ts_MI_TMSI_NRI_LV(260)),
2294 valueof(ts_MI_TMSI_NRI_LV(511))
2295 };
2296 if (ps_domain) {
2297 compl3 := {
2298 f_gen_one_compl_l3(RAUREQ, mis[0], 256),
2299 f_gen_one_compl_l3(RAUREQ, mis[1], 260),
2300 f_gen_one_compl_l3(RAUREQ, mis[2], 511)
2301 };
2302 } else {
2303 compl3 := f_gen_compl3_by_domain(ps_domain, 3, mis);
2304 }
2305
2306 f_TC_cnpool_compl_l3_list(ps_domain, compl3, {1, 1, 1}, "cnpool:subscr:known");
2307
2308 f_shutdown_helper();
2309}
2310
2311/* Layer 3 Complete by TMSI with valid NRI for the third MSC are directed to the third MSC (configured in osmo-hnbgw.cfg),
2312 * while a round-robin remains unaffected by that. */
2313testcase TC_mscpool_L3Complete_by_tmsi_valid_nri_2() runs on test_CT {
2314 f_TC_cnpool_L3Complete_valid_nri_2(ps_domain := false);
2315}
2316testcase TC_sgsnpool_L3Complete_valid_nri_2() runs on test_CT {
2317 f_TC_cnpool_L3Complete_valid_nri_2(ps_domain := true);
2318}
2319function f_TC_cnpool_L3Complete_valid_nri_2(boolean ps_domain) runs on test_CT {
2320
2321 f_init(nr_msc := 3, nr_sgsn := 3);
2322 f_sleep(1.0);
2323
2324 /* All TMSIs in this test point at the third MSC, set the round robin to point at the second MSC to make sure
2325 * this is not using round-robin. */
2326 f_vty_set_roundrobin_next(HNBGWVTY, ps_domain, 1);
2327
2328 f_ctrs_cn_init(ps_domain := ps_domain);
2329
2330 var ro_octetstring compl3;
2331
2332 /* 2 NRIs of the third MSC's range (512-767) */
2333 var ro_MobileIdentityLV mis := {
2334 valueof(ts_MI_TMSI_NRI_LV(512)),
2335 valueof(ts_MI_TMSI_NRI_LV(678))
2336 };
2337 if (ps_domain) {
2338 compl3 := {
2339 f_gen_one_compl_l3(ATTACHREQ, mis[0], 512),
2340 f_gen_one_compl_l3(ATTACHREQ, mis[1], 678)
2341 };
2342 } else {
2343 compl3 := f_gen_compl3_by_domain(ps_domain, 2, mis);
2344 }
2345
2346 f_TC_cnpool_compl_l3_list(ps_domain, compl3, {2, 2}, "cnpool:subscr:known");
2347
2348 /* The above forwardings to third MSC have not affected the round robin, which still points at the second MSC */
2349 f_TC_cnpool_compl_l3_list(ps_domain, f_gen_compl3_by_domain(ps_domain, 1), {1}, "cnpool:subscr:new");
2350
2351 f_shutdown_helper();
2352}
2353
2354/* LU with a TMSI but indicating a different PLMN in its previous LAI: ignore the NRI. */
2355testcase TC_mscpool_LU_by_tmsi_from_other_PLMN() runs on test_CT {
2356 f_TC_cnpool_nri_from_other_PLMN(ps_domain := false);
2357}
2358testcase TC_sgsnpool_nri_from_other_PLMN() runs on test_CT {
2359 f_TC_cnpool_nri_from_other_PLMN(ps_domain := true);
2360}
2361function f_TC_cnpool_nri_from_other_PLMN(boolean ps_domain) runs on test_CT {
2362
2363 f_init(nr_msc := 3, nr_sgsn := 3);
2364 f_sleep(1.0);
2365
2366 /* The TMSIs in this test points at the second MSC, but since it is from a different PLMN, round-robin is used
2367 * instead, and hits msc 0. */
2368 f_vty_set_roundrobin_next(HNBGWVTY, ps_domain, 0);
2369
2370 f_ctrs_cn_init(ps_domain := ps_domain);
2371
2372 var ro_octetstring compl3;
2373
2374 var ro_MobileIdentityLV mis := {
2375 valueof(ts_MI_TMSI_NRI_LV(260)),
2376 valueof(ts_MI_TMSI_NRI_LV(555))
2377 };
2378 if (ps_domain) {
2379 compl3 := {
2380 /* An NRI of the second MSC's range (256-511), but a PLMN that doesn't match with osmo-hnbgw.cfg */
2381 enc_PDU_L3_MS_SGSN(valueof(ts_GMM_ATTACH_REQ(mis[0], f_RAI('999'H, '99'H, '2a2a'O,
2382 '17'O),
2383 nri := ts_GMM_NRI(260)
2384 ))),
2385 /* An NRI of the third MSC's range (512-767) and a matching PLMN gets directed by NRI. */
2386 f_gen_one_compl_l3(ATTACHREQ, mis[1], 555)
2387 }
2388 } else {
2389 compl3 := {
2390 /* An NRI of the second MSC's range (256-511), but a PLMN that doesn't match with osmo-hnbgw.cfg */
2391 enc_PDU_ML3_MS_NW(valueof(ts_LU_REQ(LU_Type_IMSI_Attach, mis[0], '99F999'O))),
2392 /* An NRI of the third MSC's range (512-767) and a matching PLMN gets directed by NRI. */
2393 enc_PDU_ML3_MS_NW(valueof(ts_LU_REQ(LU_Type_IMSI_Attach, mis[1], '00F110'O)))
2394 };
2395 }
2396
2397 /* Foreign NRI: roundrobin */
2398 f_TC_cnpool_compl_l3(ps_domain, compl3[0], cn_nr := 0, inc_countername := "cnpool:subscr:new");
2399
2400 /* Local NRI: matching msc */
2401 f_TC_cnpool_compl_l3(ps_domain, compl3[1], cn_nr := 2, inc_countername := "cnpool:subscr:known");
2402
2403 f_shutdown_helper();
2404}
2405
Neels Hofmeyrb1bf16d2023-06-27 02:10:04 +02002406/* Make sure that whichever MSC paged a subscriber will also get the Paging Response. Page by IMSI, which would be
2407 * round-robined to another MSC, to make sure the Paging->Response relation is stronger than the NRI->MSC mapping. */
2408friend function f_tc_mscpool_paging_imsi(charstring id, TestHdlrParams pars) runs on ConnHdlr {
2409 f_init_handler(pars);
2410
2411 var hexstring imsi := '001010000000123'H;
2412 var RANAP_IEs.CN_DomainIndicator domain_ind;
2413 if (pars.ps_domain) {
2414 domain_ind := ps_domain;
2415 } else {
2416 domain_ind := cs_domain;
2417 }
2418 var template (value) RANAP_PDU paging := ts_RANAP_Paging(domain_ind, imsi_hex2oct(imsi));
2419 BSSAP.send(ts_RANAP_UNITDATA_req(pars.sccp_addr_hnbgw, pars.sccp_addr_msc, paging));
2420 /* TODO: Expect RUA ConnectionlessTransfer Paging (on all HNB).
2421 * We could verify the Paging sent from osmo-hnbgw to RUA with some effort,
2422 * but, this test does not care whether the Paging was forwarded to RUA or not, only that osmo-hnbgw *received*
2423 * the Paging. In the CN pool decisions, osmo-hnbgw should match up Paging Response to an earlier Paging.
2424 */
2425
2426 f_sleep(1.0);
2427
2428 /* Despite the round robin pointing at the second MSC ('roundrobin next msc 1'), the earlier Paging for the same IMSI
2429 * causes this Paging Response to go to the first MSC ('msc 0'). */
2430 f_perform_compl_l3(f_gen_one_compl_l3(PAGRESP, ts_MI_IMSI_LV(imsi)));
2431 f_sleep(1.0);
2432}
2433
2434testcase TC_mscpool_paging_imsi() runs on test_CT {
2435 f_init(nr_msc := 3);
2436 f_sleep(1.0);
2437
2438 var boolean ps_domain := false;
2439
2440 /* Testing a Paging on the first MSC to get a Paging Response back to the first MSC. Set round robin to the
2441 * second MSC to make sure we're getting the Paging logic, not a coincidental round robin match. */
2442 f_vty_set_roundrobin_next(HNBGWVTY, ps_domain, 0);
2443
2444 f_ctrs_cn_init(ps_domain := ps_domain);
2445
2446 var ConnHdlr vc_conn1;
2447 var template (value) TestHdlrParams pars1 := t_pars(0, ps_domain := ps_domain, cn_nr := 0);
2448 pars1.sccp_addr_hnbgw := g_cn[valueof(pars1.cn_idx)].sccp_addr_peer;
2449 pars1.sccp_addr_msc := g_cn[valueof(pars1.cn_idx)].sccp_addr_own;
2450 vc_conn1 := f_start_handler_with_pars(refers(f_tc_mscpool_paging_imsi), pars1);
2451 vc_conn1.done;
2452 f_ctrs_cn_expect(0, "cnpool:subscr:paged");
2453 f_shutdown_helper();
2454}
2455
2456/* Make sure that whichever MSC paged a subscriber will also get the Paging Response. Page by TMSI with an NRI value
2457 * that matches a different MSC, to make sure the Paging->Response relation is stronger than the NRI->MSC mapping. */
2458friend function f_tc_mscpool_paging_tmsi(charstring id, TestHdlrParams pars) runs on ConnHdlr {
2459 f_init_handler(pars);
2460
2461 var hexstring imsi := '001010000000124'H;
2462 var integer nri_v := 300; /* <-- second MSC's NRI */
2463 var octetstring tmsi := f_gen_tmsi(suffix := 0, nri_v := nri_v);
2464
2465 var RANAP_IEs.CN_DomainIndicator domain_ind;
2466 if (pars.ps_domain) {
2467 domain_ind := ps_domain;
2468 } else {
2469 domain_ind := cs_domain;
2470 }
2471 var template (value) RANAP_PDU paging := ts_RANAP_Paging_temp_id(domain_ind, imsi_hex2oct(imsi),
2472 ts_RANAP_TemporaryUE_ID_TMSI(tmsi));
2473 BSSAP.send(ts_RANAP_UNITDATA_req(pars.sccp_addr_hnbgw, pars.sccp_addr_msc, paging));
2474 /* TODO: Expect RUA ConnectionlessTransfer Paging (on all HNB).
2475 * We could verify the Paging sent from osmo-hnbgw to RUA with some effort,
2476 * but, this test does not care whether the Paging was forwarded to RUA or not, only that osmo-hnbgw *received*
2477 * the Paging. In the CN pool decisions, osmo-hnbgw should match up Paging Response to an earlier Paging.
2478 */
2479
2480 f_sleep(1.0);
2481
2482 /* Despite the round robin pointing at the third MSC ('roundrobin next msc 2'), the earlier Paging for the same
2483 * TMSI causes this Paging Response to go to the first MSC ('msc 0'). */
2484 f_perform_compl_l3(f_gen_one_compl_l3(PAGRESP, ts_MI_TMSI_NRI_LV(nri_v)));
2485 f_sleep(1.0);
2486}
2487testcase TC_mscpool_paging_tmsi() runs on test_CT {
2488 f_init(nr_msc := 3);
2489 f_sleep(1.0);
2490
2491 var boolean ps_domain := false;
2492
2493 /* Testing a Paging on the first MSC to get a Paging Response back to the first MSC. Set round robin to the
2494 * third MSC to make sure we're getting the Paging logic, not a coincidental round robin match. */
2495 f_vty_set_roundrobin_next(HNBGWVTY, ps_domain, 0);
2496
2497 f_ctrs_cn_init(ps_domain := ps_domain);
2498
2499 var ConnHdlr vc_conn1;
2500 var template (value) TestHdlrParams pars1 := t_pars(0, ps_domain := ps_domain, cn_nr := 0);
2501 pars1.sccp_addr_hnbgw := g_cn[valueof(pars1.cn_idx)].sccp_addr_peer;
2502 pars1.sccp_addr_msc := g_cn[valueof(pars1.cn_idx)].sccp_addr_own;
2503 vc_conn1 := f_start_handler_with_pars(refers(f_tc_mscpool_paging_tmsi), pars1);
2504 vc_conn1.done;
2505 f_ctrs_cn_expect(0, "cnpool:subscr:paged");
2506 f_shutdown_helper();
2507}
2508
Neels Hofmeyr7d0e6802023-04-20 20:43:55 +02002509/* For round-robin, skip a CN link that has 'no allow-attach' set. */
2510testcase TC_mscpool_no_allow_attach_round_robin() runs on test_CT {
2511
2512 f_init(nr_msc := 3);
2513 f_sleep(1.0);
2514
2515 var boolean ps_domain := false;
2516
2517 /* Mark the second MSC as offloading, round-robin should skip this MSC now. */
2518 f_vty_cnlink_allow_attach(HNBGWVTY, ps_domain, {true, false, true});
2519
2520 /* Control which MSC gets chosen next by the round-robin, otherwise
2521 * would be randomly affected by which other tests ran before this. */
2522 f_vty_set_roundrobin_next(HNBGWVTY, ps_domain, 0);
2523
2524 f_ctrs_cn_init(ps_domain := ps_domain);
2525
2526 f_TC_cnpool_compl_l3_list(ps_domain, f_gen_compl3_by_domain(ps_domain, 3),
2527 /* msc 1 is skipped */
2528 {0, 2, 0},
2529 "cnpool:subscr:new");
2530
2531 f_shutdown_helper();
2532}
2533
2534/* An MSC that has 'no allow-attach' set should still serve subscribers that are already attached according to their
2535 * TMSI NRI. */
2536testcase TC_mscpool_no_allow_attach_valid_nri() runs on test_CT {
2537
2538 f_init(nr_msc := 3);
2539 f_sleep(1.0);
2540
2541 var boolean ps_domain := false;
2542
2543 /* Mark the second MSC as offloading, round-robin should skip this MSC now. */
2544 f_vty_cnlink_allow_attach(HNBGWVTY, ps_domain, {true, false, true});
2545
2546 /* Control which MSC gets chosen next by the round-robin, otherwise
2547 * would be randomly affected by which other tests ran before this. */
2548 f_vty_set_roundrobin_next(HNBGWVTY, ps_domain, 0);
2549
2550 f_ctrs_cn_init(ps_domain := ps_domain);
2551
2552 var ro_MobileIdentityLV mis := {
2553 valueof(ts_MI_TMSI_NRI_LV(260)),
2554 valueof(ts_MI_IMSI_LV('001010000000002'H)),
2555 valueof(ts_MI_IMSI_LV('001010000000003'H))
2556 };
2557
2558 var ro_octetstring compl3 := f_gen_compl3_by_domain(ps_domain, 3, mis);
2559
2560 /* Round robin points at msc 0, but the valid NRI directs to msc 1, even though msc 1 has 'no allow-attach'. */
2561 f_TC_cnpool_compl_l3(ps_domain, compl3[0], cn_nr := 1, inc_countername := "cnpool:subscr:known");
2562
2563 /* Normal round robin skips msc 1, because it has 'no allow-attach' */
2564 f_TC_cnpool_compl_l3(ps_domain, compl3[1], cn_nr := 0, inc_countername := "cnpool:subscr:new");
2565 f_TC_cnpool_compl_l3(ps_domain, compl3[2], cn_nr := 2, inc_countername := "cnpool:subscr:new");
2566
2567 f_shutdown_helper();
2568}
2569
2570/* When a peer point-code gets an SCCP N-PCSTATE saying it is unreachable, immediately mark the CN link as unusable. */
2571testcase TC_mscpool_sccp_n_pcstate_detaches_cnlink() runs on test_CT {
2572 f_TC_cnpool_sccp_n_pcstate_detaches_cnlink(ps_domain := false);
2573}
2574testcase TC_sgsnpool_sccp_n_pcstate_detaches_cnlink() runs on test_CT {
2575 f_TC_cnpool_sccp_n_pcstate_detaches_cnlink(ps_domain := true);
2576}
2577function f_TC_cnpool_sccp_n_pcstate_detaches_cnlink(boolean ps_domain) runs on test_CT
2578{
2579
2580 f_init(nr_msc := 2, nr_sgsn := 2);
2581 f_sleep(1.0);
2582
2583 /* Control which MSC gets chosen next by the round-robin, otherwise
2584 * would be randomly affected by which other tests ran before this. */
2585 f_vty_set_roundrobin_next(HNBGWVTY, ps_domain, 0);
2586
2587 f_ctrs_cn_init(ps_domain := ps_domain);
2588
2589 var ro_octetstring compl3 := f_gen_compl3_by_domain(ps_domain, 3);
2590
2591 f_TC_cnpool_compl_l3(ps_domain, compl3[0], cn_nr := 0, inc_countername := "cnpool:subscr:new");
2592 f_TC_cnpool_compl_l3(ps_domain, compl3[1], cn_nr := 1, inc_countername := "cnpool:subscr:new");
2593
2594 f_logp(HNBGWVTY, "disconnecting msc0");
2595 f_cn_idx_disconnect(f_cn_idx(ps_domain, 0));
2596
2597 /* Now round-robin would wrap to the first MSC, but since the first MSC is disconnected, it wraps around to the
2598 * second. */
2599 f_TC_cnpool_compl_l3(ps_domain, compl3[2], cn_nr := 1, inc_countername := "cnpool:subscr:new");
2600
2601 f_shutdown_helper();
2602}
2603
2604/* When a CN link point-code gets an SCCP N-PCSTATE saying it is now reachable, immediately trigger RESET and bring up the
2605 * MSC. */
2606testcase TC_mscpool_sccp_n_pcstate_attaches_cnlink() runs on test_CT {
2607 f_TC_cnpool_sccp_n_pcstate_attaches_cnlink(ps_domain := false);
2608}
2609testcase TC_sgsnpool_sccp_n_pcstate_attaches_cnlink() runs on test_CT {
2610 f_TC_cnpool_sccp_n_pcstate_attaches_cnlink(ps_domain := true);
2611}
2612function f_TC_cnpool_sccp_n_pcstate_attaches_cnlink(boolean ps_domain) runs on test_CT
2613{
2614 f_init(nr_msc := 1, nr_sgsn := 1);
2615 f_sleep(1.0);
2616
2617 /* Control which MSC gets chosen next by the round-robin, otherwise
2618 * would be randomly affected by which other tests ran before this. */
2619 f_vty_set_roundrobin_next(HNBGWVTY, ps_domain, 0);
2620
2621 var ro_octetstring compl3 := f_gen_compl3_by_domain(ps_domain, 3);
2622
2623 f_ctrs_cn_init(ps_domain := ps_domain);
2624
2625 /* There is only one MSC, round robin stays on msc0 */
2626 f_TC_cnpool_compl_l3(ps_domain := ps_domain, nas_pdu := compl3[0], cn_nr := 0, inc_countername := "cnpool:subscr:new");
2627 f_TC_cnpool_compl_l3(ps_domain := ps_domain, nas_pdu := compl3[1], cn_nr := 0, inc_countername := "cnpool:subscr:new");
2628
2629 f_logp(HNBGWVTY, "connecting cnlink 1");
2630 f_cn_nr_init(ps_domain, 1);
2631 f_vty_cnlink_allow_attach(HNBGWVTY, ps_domain, { true, true });
2632 f_sleep(1.0);
2633
2634 /* This time round-robin wraps to the second MSC, because it is now online. */
2635 f_TC_cnpool_compl_l3(ps_domain := ps_domain, nas_pdu := compl3[2], cn_nr := 1, inc_countername := "cnpool:subscr:new");
2636
2637 f_shutdown_helper();
2638}
2639
Neels Hofmeyrd019cc02023-06-02 16:31:23 +02002640private function f_vty_add_sccp_addr(TELNETasp_PT pt, charstring addr_name, charstring pc, integer cs7_nr := 0)
2641{
2642 f_vty_enter_config(pt);
2643 f_vty_transceive(pt, "cs7 instance 0");
2644 f_vty_transceive(pt, "sccp-address " & addr_name);
2645 f_vty_transceive(pt, "point-code " & pc);
2646 f_vty_transceive(pt, "end");
2647}
2648
2649private function f_vty_set_cnlink_addr(TELNETasp_PT pt, charstring cnlink_and_nr, charstring addr_name)
2650{
2651 f_vty_enter_config(pt);
2652 f_vty_transceive(pt, cnlink_and_nr);
2653 f_vty_transceive(pt, "remote-addr " & addr_name);
2654 f_vty_transceive(pt, "end");
2655}
2656
2657private function f_vty_apply_sccp(TELNETasp_PT pt)
2658{
2659 f_vty_enter_config(pt);
2660 f_vty_transceive(pt, "apply sccp");
2661 f_vty_transceive(pt, "end");
2662}
2663
2664template (present) RUA_Disc_Req tr_RUA_Disc_Req := {
2665 ranap := ?,
2666 cause := ?
2667};
2668
2669/* With a cnlink up, change the SCCP address, and verify that it restarts upon vty 'apply sccp' */
2670private function f_tc_apply_sccp(charstring id, TestHdlrParams pars) runs on ConnHdlr
2671{
2672 f_init_handler(pars);
2673 f_perform_compl_l3(f_gen_compl3_by_domain(pars.ps_domain, 1)[0]);
2674
2675 f_sleep(1.0);
2676 f_logp(HNBGWVTY, "Changing SCCP address, don't apply yet");
2677
2678 f_vty_add_sccp_addr(HNBGWVTY, "msc-foo", "0.42.4");
2679 f_vty_set_cnlink_addr(HNBGWVTY, "msc 0", "msc-foo");
2680
2681 /* No effect yet, link still open both ways */
2682 f_sleep(1.0);
2683 f_iuh2iu(ts_RANAP_DirectTransfer(f_rnd_octstring(10)));
2684 f_iu2iuh(ts_RANAP_DirectTransfer(f_rnd_octstring(10)));
2685
2686 f_logp(HNBGWVTY, "Apply SCCP address changes");
2687 f_vty_apply_sccp(HNBGWVTY);
2688
2689 /* We modified the SCCP configuration, expect disconnect of UE that was active on the aborted link. */
2690 RUA.receive(RUA_Disc_Ind:?);
2691 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_IND);
2692
2693 /* Would be nice to test reconnection on the other point-code, too. That would require another cnlink in
2694 * osmo-stp.cfg and module parameters... */
2695
2696 f_sleep(1.0);
2697}
2698testcase TC_apply_sccp() runs on test_CT
2699{
2700 f_init();
2701 f_sleep(1.0);
2702
2703 var ConnHdlr vc_conn;
2704 var template (value) TestHdlrParams pars := t_pars(0);
2705 vc_conn := f_start_handler_with_pars(refers(f_tc_apply_sccp), pars);
2706 vc_conn.done;
2707
2708 f_shutdown_helper();
2709}
2710
Neels Hofmeyrc3c01d32023-11-07 02:19:00 +01002711/* In the field, we encountered a "normal" RAB Assignment that concludes successfully, followed by another RAB
2712 * Assignment that has different SDU subflow parameters, and does not contain RTP information. At the time of writing,
2713 * it seems that the second RAB Assignment causes a crash. Play through this scenario. */
2714friend function f_tc_second_rab_assignment(charstring id, TestHdlrParams pars) runs on ConnHdlr {
2715 var MgcpCommand mgcp_cmd;
2716 var RANAP_PDU tx;
2717 timer T := 5.0;
2718
2719 f_init_handler(pars);
2720 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
2721
2722 tx := f_build_initial_ue(g_pars);
2723 f_iuh2iu_connect(tx);
2724
2725 f_create_rab(pars.mgcp_pars);
2726
2727 /* Now send a second RAB Assignment with different subflows and omitting transportLayerInformation. (Assuming
2728 * the first RAB Assignment's transportLayerInformation remains in use unchanged.) */
2729 var template RAB_SetupOrModifyList rab_sml;
2730 rab_sml := ts_RAB_SML2(t_RAB_id(23),
2731 ts_RabParams,
2732 user_plane_info := omit,
2733 transport_layer_info := omit);
2734 tx := valueof(ts_RANAP_RabAssReq(rab_sml));
2735 BSSAP.send(tx);
2736 T.start;
2737
2738 /* Expect this secondary RAB Assignment to go through unchanged. */
2739 f_rua_expect(tx);
2740
2741 /* I'm guessing that the RAB Assignment Response also omits transportLayerInformation, so far not known because
2742 * osmo-hnbgw crashed before we could receive the response. */
2743
2744 /* Send back RAB Assignment Response via Iuh */
2745 var template RAB_SetupOrModifiedList rab_smdl;
2746 rab_smdl := ts_RAB_SMdL_no_tla(t_RAB_id(23));
2747 tx := valueof(ts_RANAP_RabAssResp(rab_smdl));
2748 RUA.send(tx);
2749 f_bssap_expect(tx);
2750
2751 /* Send Iu Release */
2752 tx := valueof(ts_RANAP_IuReleaseCommand(ts_RanapCause_om_intervention));
2753 f_iu2iuh(tx);
2754
2755 T.start;
2756 alt {
2757 [] as_mgcp_dlcx(pars) {}
2758 [] T.timeout {
2759 setverdict(fail, "Timeout waiting for DLCX");
2760 }
2761 }
2762
2763 tx := valueof(ts_RANAP_IuReleaseComplete());
2764 f_iuh2iu(tx);
2765}
2766
2767testcase TC_second_rab_assignment() runs on test_CT {
2768 var ConnHdlr vc_conn;
2769 g_num_hnbs := 1;
2770 f_init();
2771
2772 vc_conn := f_start_handler_with_pars(refers(f_tc_second_rab_assignment), t_pars(3));
2773 vc_conn.done;
2774
2775 f_shutdown_helper();
2776}
2777
Daniel Willmann19b8d902022-01-05 09:12:34 +01002778control {
2779 execute(TC_hnb_register());
Daniel Willmannc79679a2022-08-23 17:48:39 +02002780 execute(TC_hnb_register_duplicate());
Pau Espin Pedrolacf4f222022-09-27 14:33:40 +02002781 execute(TC_hnb_register_duplicate_reuse_sctp_assoc());
Harald Welteaf3e2162024-03-27 21:54:20 +01002782 execute(TC_ue_register());
Harald Weltef60044d2024-04-04 00:54:34 +02002783 execute(TC_ue_register_tmsi_lai());
Harald Welteaf3e2162024-03-27 21:54:20 +01002784 execute(TC_ue_register_before_hnb_register());
Daniel Willmann19b8d902022-01-05 09:12:34 +01002785 execute(TC_ranap_cs_initial_ue());
2786 execute(TC_ranap_ps_initial_ue());
Neels Hofmeyrf0b9ed12022-06-07 17:46:32 +02002787 execute(TC_ranap_cs_initial_ue_empty_cr());
2788 execute(TC_ranap_ps_initial_ue_empty_cr());
Daniel Willmann19b8d902022-01-05 09:12:34 +01002789 execute(TC_ranap_cs_bidir());
2790 execute(TC_ranap_ps_bidir());
2791 execute(TC_rab_assignment());
2792 execute(TC_rab_release());
Daniel Willmann3e15b7b2022-02-21 17:07:02 +01002793 execute(TC_rab_assign_fail());
Daniel Willmann37c877f2022-02-22 16:47:06 +01002794 execute(TC_rab_assign_mgcp_to());
Pau Espin Pedrolaf746502023-11-29 16:18:28 +01002795 execute(TC_rab_assign_mgw_iuup_addr_chg());
Daniel Willmann19b8d902022-01-05 09:12:34 +01002796 execute(TC_ranap_cs_mo_disconnect());
2797 execute(TC_ranap_ps_mo_disconnect());
Neels Hofmeyrbacb74f2022-08-29 16:24:12 +02002798
2799 if (mp_enable_pfcp_tests) {
2800 execute(TC_ps_rab_assignment_with_pfcp());
2801 } else {
2802 execute(TC_ps_rab_assignment_without_pfcp());
2803 }
Pau Espin Pedrolf0b9fa02022-09-12 13:31:07 +02002804
Neels Hofmeyr7d0e6802023-04-20 20:43:55 +02002805 execute( TC_mscpool_L3Compl_on_1_cnlink() );
2806 execute( TC_mscpool_L3Complete_by_imsi_round_robin() );
2807 execute( TC_mscpool_LU_by_tmsi_null_nri_0_round_robin() );
2808 execute( TC_mscpool_LU_by_tmsi_null_nri_1_round_robin() );
2809 execute( TC_mscpool_L3Complete_by_tmsi_unassigned_nri_round_robin() );
2810 execute( TC_mscpool_L3Complete_by_tmsi_valid_nri_msc_not_connected_round_robin() );
2811 execute( TC_mscpool_L3Complete_by_tmsi_valid_nri_1() );
2812 execute( TC_mscpool_L3Complete_by_tmsi_valid_nri_2() );
2813 execute( TC_mscpool_LU_by_tmsi_from_other_PLMN() );
Neels Hofmeyrb1bf16d2023-06-27 02:10:04 +02002814 execute( TC_mscpool_paging_imsi() );
2815 execute( TC_mscpool_paging_tmsi() );
Neels Hofmeyr7d0e6802023-04-20 20:43:55 +02002816 execute( TC_mscpool_no_allow_attach_round_robin() );
2817 execute( TC_mscpool_no_allow_attach_valid_nri() );
2818 execute( TC_mscpool_sccp_n_pcstate_detaches_cnlink() );
2819 execute( TC_mscpool_sccp_n_pcstate_attaches_cnlink() );
2820
2821 execute( TC_sgsnpool_L3Compl_on_1_cnlink() );
2822 execute( TC_sgsnpool_L3Complete_no_nri_round_robin() );
2823 execute( TC_sgsnpool_L3Complete_valid_nri_1() );
2824 execute( TC_sgsnpool_L3Complete_valid_nri_2() );
2825 execute( TC_sgsnpool_nri_from_other_PLMN() );
2826 execute( TC_sgsnpool_sccp_n_pcstate_detaches_cnlink() );
2827 execute( TC_sgsnpool_sccp_n_pcstate_attaches_cnlink() );
2828
Oliver Smithaa919b42023-11-14 11:30:55 +01002829 /* Run only on nightly since it makes osmo-hnbgw <= 1.5.0 crash: OS#6253 */
2830 if (f_osmo_repo_is("nightly")) {
2831 execute(TC_second_rab_assignment());
2832 }
Neels Hofmeyrc3c01d32023-11-07 02:19:00 +01002833
Pau Espin Pedrolf0b9fa02022-09-12 13:31:07 +02002834 /* Run at the end since it makes osmo-hnbgw <= 1.3.0 crash: OS#5676 */
2835 execute(TC_hnb_reregister_reuse_sctp_assoc());
Neels Hofmeyrd019cc02023-06-02 16:31:23 +02002836
2837 /* Run at the end since it messes with the SCCP config */
2838 execute( TC_apply_sccp() );
Daniel Willmann19b8d902022-01-05 09:12:34 +01002839}
2840
2841}