blob: 88b8c1ea5d79e848cc308ab85e8b1ed5d624e781 [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;
Pau Espin Pedrol831cb692024-04-16 12:42:28 +020091
92 /* Our emulated StatsD server: */
93 charstring mp_local_statsd_ip := "127.0.0.1";
94 integer mp_local_statsd_port := 8125;
Daniel Willmann19b8d902022-01-05 09:12:34 +010095
96 charstring mp_mgw_ip := "127.0.0.1";
97 integer mp_mgw_port := 2427;
98
Neels Hofmeyr7a48df12023-04-20 20:43:43 +020099 RAN_Configurations mp_cn_cfg := {
100 /* MSCs (NUM_MSC entries) */
101 {
102 transport := RANAP_TRANSPORT_IuCS,
103 sccp_service_type := "mtp3_itu",
104 sctp_addr := { 23905, "127.0.0.1", 2905, "127.0.0.1" },
105 own_pc := 188, /* 0.23.4 first MSC emulation */
106 own_ssn := 142,
107 peer_pc := 189, /* 0.23.5 osmo-hnbgw */
108 peer_ssn := 142,
109 sio := '83'O,
110 rctx := 1
111 },
112 {
113 transport := RANAP_TRANSPORT_IuCS,
114 sccp_service_type := "mtp3_itu",
115 sctp_addr := { 23907, "127.0.0.1", 2905, "127.0.0.1" },
116 own_pc := 2, /* 0.0.2 second MSC emulation */
117 own_ssn := 142,
118 peer_pc := 189, /* 0.23.5 osmo-hnbgw */
119 peer_ssn := 142,
120 sio := '83'O,
121 rctx := 3
122 },
123 {
124 transport := RANAP_TRANSPORT_IuCS,
125 sccp_service_type := "mtp3_itu",
126 sctp_addr := { 23909, "127.0.0.1", 2905, "127.0.0.1" },
127 own_pc := 3, /* 0.0.3 third MSC emulation */
128 own_ssn := 142,
129 peer_pc := 189, /* 0.23.5 osmo-hnbgw */
130 peer_ssn := 142,
131 sio := '83'O,
132 rctx := 5
133 },
134 {
135 transport := RANAP_TRANSPORT_IuCS,
136 sccp_service_type := "mtp3_itu",
137 sctp_addr := { 23911, "127.0.0.1", 2905, "127.0.0.1" },
138 own_pc := 4, /* 0.0.4 fourth MSC emulation */
139 own_ssn := 142,
140 peer_pc := 189, /* 0.23.5 osmo-hnbgw */
141 peer_ssn := 142,
142 sio := '83'O,
143 rctx := 7
144 },
145
146 /* SGSNs (NUM_SGSN entries) */
147 {
148 transport := RANAP_TRANSPORT_IuCS,
149 sccp_service_type := "mtp3_itu",
150 sctp_addr := { /* local */ 23906, "127.0.0.1", /* remote */ 2905, "127.0.0.1" },
151 own_pc := 185, /* 0.23.1 first SGSN emulation */
152 own_ssn := 142,
153 peer_pc := 189, /* 2237, 1.23.5 osmo-hnbgw */
154 peer_ssn := 142,
155 sio := '83'O,
156 rctx := 2
157 },
158 {
159 transport := RANAP_TRANSPORT_IuCS,
160 sccp_service_type := "mtp3_itu",
161 sctp_addr := { /* local */ 23908, "127.0.0.1", /* remote */ 2905, "127.0.0.1" },
162 own_pc := 10, /* 0.1.2 second SGSN emulation */
163 own_ssn := 142,
164 peer_pc := 189, /* 2237, 1.23.5 osmo-hnbgw */
165 peer_ssn := 142,
166 sio := '83'O,
167 rctx := 4
168 },
169 {
170 transport := RANAP_TRANSPORT_IuCS,
171 sccp_service_type := "mtp3_itu",
172 sctp_addr := { /* local */ 23910, "127.0.0.1", /* remote */ 2905, "127.0.0.1" },
173 own_pc := 11, /* 0.1.3 third SGSN emulation */
174 own_ssn := 142,
175 peer_pc := 189, /* 2237, 1.23.5 osmo-hnbgw */
176 peer_ssn := 142,
177 sio := '83'O,
178 rctx := 6
179 },
180 {
181 transport := RANAP_TRANSPORT_IuCS,
182 sccp_service_type := "mtp3_itu",
183 sctp_addr := { /* local */ 23912, "127.0.0.1", /* remote */ 2905, "127.0.0.1" },
184 own_pc := 12, /* 0.1.4 fourth SGSN emulation */
185 own_ssn := 142,
186 peer_pc := 189, /* 2237, 1.23.5 osmo-hnbgw */
187 peer_ssn := 142,
188 sio := '83'O,
189 rctx := 8
190 }
Daniel Willmann19b8d902022-01-05 09:12:34 +0100191 };
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +0200192
Neels Hofmeyrbacb74f2022-08-29 16:24:12 +0200193 boolean mp_enable_pfcp_tests := false;
194
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +0200195 /* IP address at which we listen for PFCP to emulate a UPF in ttcn3 */
196 charstring mp_pfcp_ip_local := "127.0.0.1";
197
198 /* IP address from which the SUT (osmo-hnbgw) sends PFCP requests, and to which the ttcn3 UPF emulation sends
199 * PFCP responses. */
200 charstring mp_pfcp_ip_remote := "127.0.0.2";
Pau Espin Pedrol6c87ad92023-07-18 11:24:25 +0200201
202 boolean mp_validate_talloc_asn1 := true;
Pau Espin Pedrolee4ce862023-11-02 12:23:25 +0100203
204 /* The X31 timer configured at osmo-hnbgw (seconds). This provided an idea on
205 * minimum time the test must wait to consider this timer triggered */
206 integer mp_hnbgw_timer_x31 := 5;
Daniel Willmann19b8d902022-01-05 09:12:34 +0100207}
208
209function MSC_UnitdataCallback(RANAP_PDU ranap) runs on RAN_Emulation_CT return template RANAP_PDU {
210 // TODO: Actually implement unitdata handling
Neels Hofmeyrcf6dc492023-06-27 00:51:08 +0200211 return omit;
Daniel Willmann19b8d902022-01-05 09:12:34 +0100212}
213
214const RanOps MSC_RanOps := {
215 ranap_create_cb := refers(RAN_Emulation.RanapExpectedCreateCallback),
216 ranap_unitdata_cb := refers(MSC_UnitdataCallback),
217 ps_domain := false,
218 decode_dtap := false,
219 role_ms := false,
220 protocol := RAN_PROTOCOL_RANAP,
221 transport := RANAP_TRANSPORT_IuCS,
222 use_osmux := false,
Eric Wild6e511ce2022-04-02 21:35:56 +0200223 bssap_reset_retries := 1,
Daniel Willmann19b8d902022-01-05 09:12:34 +0100224 sccp_addr_local := omit,
225 sccp_addr_peer := omit
226}
227
Pau Espin Pedrol264679f2023-11-29 15:52:00 +0100228type record MgwResponse {
Daniel Willmann19b8d902022-01-05 09:12:34 +0100229 integer resp,
230 HostName mgw_rtp_ip,
Pau Espin Pedrol0c35a632023-11-29 16:00:35 +0100231 /* if set, used after first received MDCX: */
232 HostName mgw_rtp_ip_mdcx optional,
Daniel Willmann19b8d902022-01-05 09:12:34 +0100233 PortNumber mgw_rtp_port,
234 MgcpConnectionId mgcp_connection_id
235}
236type record MgcpParameters {
237 integer got_crcx_count,
238 integer got_dlcx_count,
239 MgcpCallId mgcp_call_id optional,
240 MgcpEndpoint mgcp_ep,
Pau Espin Pedrol264679f2023-11-29 15:52:00 +0100241 MgwResponse mgw_conn_ran,
242 MgwResponse mgw_conn_cn,
Daniel Willmann19b8d902022-01-05 09:12:34 +0100243 uint7_t rtp_payload_type,
244 charstring rtp_sdp_format,
245 HostName hnb_rtp_ip,
246 PortNumber hnb_rtp_port,
247 HostName cn_rtp_ip,
248 PortNumber cn_rtp_port,
249 boolean use_osmux,
250 integer got_osmux_count
251}
252
253template (value) MgcpParameters t_MgcpParams := {
254 got_crcx_count := 0,
255 got_dlcx_count := 0,
256 mgcp_call_id := omit,
257 mgcp_ep := "rtpbridge/1@mgw",
Pau Espin Pedrolb85ac2f2023-11-29 15:48:57 +0100258 mgw_conn_ran := {
Daniel Willmann19b8d902022-01-05 09:12:34 +0100259 resp := 1,
260 mgw_rtp_ip := "127.1.2.1",
Pau Espin Pedrol0c35a632023-11-29 16:00:35 +0100261 mgw_rtp_ip_mdcx := omit,
Daniel Willmann19b8d902022-01-05 09:12:34 +0100262 mgw_rtp_port := 10000,
263 mgcp_connection_id := '11111'H
264 },
Pau Espin Pedrolb85ac2f2023-11-29 15:48:57 +0100265 mgw_conn_cn := {
Daniel Willmann19b8d902022-01-05 09:12:34 +0100266 resp := 1,
267 mgw_rtp_ip := "127.1.2.2",
Pau Espin Pedrol0c35a632023-11-29 16:00:35 +0100268 mgw_rtp_ip_mdcx := omit,
Daniel Willmann19b8d902022-01-05 09:12:34 +0100269 mgw_rtp_port := 20000,
270 mgcp_connection_id := '22222'H
271 },
Philipp Maier6c5ba0752023-07-04 16:53:40 +0200272 rtp_payload_type := 112,
273 rtp_sdp_format := "VND.3GPP.IUFP",
Daniel Willmann19b8d902022-01-05 09:12:34 +0100274 hnb_rtp_ip := "127.1.1.1",
275 hnb_rtp_port := 10001,
276 cn_rtp_ip := "127.1.3.1",
277 cn_rtp_port := 20001,
278 use_osmux := false,
279 got_osmux_count := 0
280}
281
282type record TestHdlrParams {
283 integer hnb_idx,
Neels Hofmeyr7a48df12023-04-20 20:43:43 +0200284 /* cn_idx indicates which CN link from g_cn[] to connect to the test component.
285 * See also f_cn_idx(). */
286 integer cn_idx,
Daniel Willmann19b8d902022-01-05 09:12:34 +0100287 hexstring imsi,
288 boolean ps_domain,
289 MgcpParameters mgcp_pars optional,
Neels Hofmeyrf0b9ed12022-06-07 17:46:32 +0200290 HnbConfig hnb optional,
Neels Hofmeyrf2c95022023-04-19 01:24:39 +0200291 boolean expect_separate_sccp_cr,
292 integer tx_sccp_cr_data_len,
Neels Hofmeyr7d0e6802023-04-20 20:43:55 +0200293 charstring pfcp_local_addr,
Neels Hofmeyrb1bf16d2023-06-27 02:10:04 +0200294 octetstring nas_pdu optional,
295 /* local and remote SCCP addresses, used in TC_mscpool_paging_* */
296 SCCP_PAR_Address sccp_addr_msc optional,
Harald Welte0d4a8432024-04-04 01:12:11 +0200297 SCCP_PAR_Address sccp_addr_hnbgw optional,
298 /* RAB release cause */
299 RANAP_IEs.Cause rab_rel_cause
Daniel Willmann19b8d902022-01-05 09:12:34 +0100300}
301
302/* We extend:
303 * RUA_ConnHdlr (for the Iuh side, emulating the HNB)
304 * RAN_ConnHdlr (for the Iu side, emulating the MSC)
305 * MGCP_ConnHdlr (for the MGCP side, emulating the MGW)
Harald Welte904b5f12024-04-04 02:47:30 +0200306 * StatsD_ConnHdlr (for the statsd interface, verifying counters)
Daniel Willmann19b8d902022-01-05 09:12:34 +0100307 */
Harald Welte904b5f12024-04-04 02:47:30 +0200308type component ConnHdlr extends RAN_ConnHdlr, MGCP_ConnHdlr, RUA_ConnHdlr, PFCP_ConnHdlr, StatsD_ConnHdlr {
Daniel Willmann19b8d902022-01-05 09:12:34 +0100309 var integer g_sccp_conn_id;
310 var TestHdlrParams g_pars;
311 timer g_Tguard;
Neels Hofmeyr72a8d622023-01-26 13:47:01 +0100312
313 port TELNETasp_PT HNBGWVTY;
Daniel Willmann19b8d902022-01-05 09:12:34 +0100314}
315
316
317const MGCPOps MSC_MGCPOps := {
318 create_cb := refers(MGCP_Emulation.ExpectedCreateCallback),
319 unitdata_cb := refers(MGCP_Emulation.DummyUnitdataCallback)
320}
321
322function f_create_ranap_exp(octetstring l3_enc) runs on ConnHdlr {
323 BSSAP_PROC.call(RAN_register:{l3_enc, self}) {
324 [] BSSAP_PROC.getreply(RAN_register:{?, ?}) {};
325 }
326}
327
328
Daniel Willmannc79679a2022-08-23 17:48:39 +0200329const integer NUM_HNB := 2;
Daniel Willmann19b8d902022-01-05 09:12:34 +0100330
Daniel Willmann19b8d902022-01-05 09:12:34 +0100331type record HnbConfig {
332 LocationAreaIdentification lai,
333 integer sac
334}
335
Harald Welte904b5f12024-04-04 02:47:30 +0200336type component test_CT extends CTRL_Adapter_CT, StatsD_Checker_CT {
Daniel Willmann19b8d902022-01-05 09:12:34 +0100337 var boolean g_initialized := false;
338
339 /********************* Iu side */
Neels Hofmeyr7a48df12023-04-20 20:43:43 +0200340 var RAN_Adapter g_cn[NUM_MSC + NUM_SGSN];
Daniel Willmann19b8d902022-01-05 09:12:34 +0100341
342 /********************* Iuh side */
343 var HnbConfig g_hnb_cfg[NUM_HNB];
344 var Iuh_Emulation_CT vc_Iuh[NUM_HNB];
345 var RUA_Emulation_CT vc_RUA[NUM_HNB];
346 port HNBAP_PT HNBAP[NUM_HNB];
Pau Espin Pedrol83a49612022-09-12 21:11:05 +0200347 /* Number of HNBs to be used/started by the test */
348 var integer g_num_hnbs := NUM_HNB;
Daniel Willmann19b8d902022-01-05 09:12:34 +0100349
350 var MGCP_Emulation_CT vc_MGCP;
351 port TELNETasp_PT HNBGWVTY;
Harald Welte904b5f12024-04-04 02:47:30 +0200352 var StatsD_Checker_CT vc_STATSD;
Daniel Willmann19b8d902022-01-05 09:12:34 +0100353 /* global test case guard timer (actual timeout value is set in f_init()) */
354 timer T_guard := 30.0;
Neels Hofmeyr7d0e6802023-04-20 20:43:55 +0200355
356 /* The cnlink type 'msc' or 'sgsn', to be used in CTRL commands to obtain counters */
357 var charstring g_ctr_cn_node_name;
358 /* Counter state */
359 var CounterNameValsList g_ctr_cn;
Daniel Willmann19b8d902022-01-05 09:12:34 +0100360}
361
362/* global altstep for global guard timer; */
363altstep as_Tguard() runs on test_CT {
364 [] T_guard.timeout {
365 setverdict(fail, "Timeout of T_guard");
366 mtc.stop;
367 }
368}
369
Daniel Willmann19b8d902022-01-05 09:12:34 +0100370function f_init_vty(charstring id := "foo") runs on test_CT {
371 if (HNBGWVTY.checkstate("Mapped")) {
372 /* skip initialization if already executed once */
373 return;
374 }
375 map(self:HNBGWVTY, system:HNBGWVTY);
376 f_vty_set_prompts(HNBGWVTY);
377 f_vty_transceive(HNBGWVTY, "enable");
378}
379
380function f_init_mgcp(charstring id) runs on test_CT {
381 id := id & "-MGCP";
382 var MGCPOps ops := {
383 create_cb := refers(MGCP_Emulation.ExpectedCreateCallback),
384 unitdata_cb := refers(MGCP_Emulation.DummyUnitdataCallback)
385 }
386 var MGCP_conn_parameters pars := {
387 callagent_ip := mp_hnbgw_ip,
388 callagent_udp_port := -1,
389 mgw_ip := mp_mgw_ip,
390 mgw_udp_port := mp_mgw_port,
391 multi_conn_mode := false
392 }
393
394 vc_MGCP := MGCP_Emulation_CT.create(id);
395 map(vc_MGCP:MGCP, system:MGCP_CODEC_PT);
396 vc_MGCP.start(MGCP_Emulation.main(ops, pars, id));
397}
398
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +0200399function f_init_pfcp(charstring id) runs on ConnHdlr {
400 id := id & "-PFCP";
401
402 var PFCP_Emulation_Cfg pfcp_cfg := {
403 pfcp_bind_ip := mp_pfcp_ip_local,
404 pfcp_bind_port := PFCP_PORT,
405 pfcp_remote_ip := mp_pfcp_ip_remote,
406 pfcp_remote_port := PFCP_PORT,
407 role := UPF
408 };
409
410 vc_PFCP := PFCP_Emulation_CT.create(id) alive;
411 connect(self:PFCP, vc_PFCP:CLIENT);
412 connect(self:PFCP_PROC, vc_PFCP:CLIENT_PROC);
413 vc_PFCP.start(PFCP_Emulation.main(pfcp_cfg));
414}
415
Daniel Willmann19b8d902022-01-05 09:12:34 +0100416function f_init_hnodeb(charstring id, integer hnb_idx, RuaOps rua_ops) runs on test_CT {
417 id := id & "-Iuh" & int2str(hnb_idx);
418
419 /* Iuh lower layer (RUA/HNBAP demux) */
420 var Iuh_conn_parameters iuh_pars;
421 iuh_pars.remote_ip := mp_hnbgw_ip;
422 iuh_pars.remote_sctp_port := mp_hnbgw_iuh_port;
423 iuh_pars.local_ip := mp_hnodeb_ip;
424 iuh_pars.local_sctp_port := mp_hnodeb_port + hnb_idx;
425 vc_Iuh[hnb_idx] := Iuh_Emulation_CT.create(id);
426 connect(self:HNBAP[hnb_idx], vc_Iuh[hnb_idx]:HNBAP);
427
428 vc_RUA[hnb_idx] := RUA_Emulation_CT.create(id & "-RUA");
429 connect(vc_RUA[hnb_idx]:RUA, vc_Iuh[hnb_idx]:RUA);
430
431 /* Start Iuh side components */
432 vc_Iuh[hnb_idx].start(Iuh_Emulation.main(iuh_pars, id));
433 vc_RUA[hnb_idx].start(RUA_Emulation.main(rua_ops, id & "-RUA"));
434}
435
Neels Hofmeyr3d5a0da2023-06-27 00:57:46 +0200436private type record of boolean BooleanList;
437
438private function f_vty_cnlink_allow_attach(TELNETasp_PT pt, boolean ps_domain, BooleanList allow_attach_list)
439{
440 var charstring config := f_vty_transceive_ret(pt, "show running-config");
441
442 var charstring msc_sgsn;
443 if (ps_domain) {
444 msc_sgsn := "sgsn";
445 } else {
446 msc_sgsn := "msc";
447 }
448
449 f_vty_enter_config(pt);
450 for (var integer cn_nr := 0; cn_nr < sizeof(allow_attach_list); cn_nr := cn_nr+1) {
451 if (f_strstr(config, "\n" & msc_sgsn & " " & int2str(cn_nr) & "\n") < 0) {
452 /* There is no 'msc N' for this cn_nr in the running config, so don't create an empty cn by
453 * stepping into that config node. */
454 log(msc_sgsn, cn_nr, " is not configured, skipping");
455 continue;
456 }
457 f_vty_transceive(pt, msc_sgsn & " " & int2str(cn_nr));
458
459 if (allow_attach_list[cn_nr]) {
460 /* strict := false: ignore if osmo-hnbgw does not support this config option (latest build) */
461 f_vty_transceive(pt, "allow-attach", strict := false);
462 } else {
463 f_vty_transceive(pt, "no allow-attach", strict := false);
464 }
465 f_vty_transceive(pt, "exit");
466 }
467 f_vty_transceive(pt, "exit");
468}
469
470/* Start RAN adapter for CN link N.
471 * e.g. link for 'msc 0' = (ps_domain := false, cn_nr := 0)
472 * link for 'sgsn 3' = (ps_domain := true, cn_nr := 3)
473 */
474private function f_cn_nr_init(boolean ps_domain, integer cn_nr) runs on test_CT {
475 var RanOps ranops := MSC_RanOps;
476 ranops.ps_domain := ps_domain;
477 var integer cn_idx := f_cn_idx(ps_domain, cn_nr);
478 var charstring msc_sgsn := "msc";
479 if (ps_domain) {
480 msc_sgsn := "sgsn";
481 }
482 f_ran_adapter_init(g_cn[cn_idx], mp_cn_cfg[cn_idx], "HNBGW_Test." & msc_sgsn & int2str(cn_nr), ranops);
483 f_ran_adapter_start(g_cn[cn_idx]);
484}
485
486private function f_cn_idx_disconnect(integer cn_idx) runs on test_CT {
487 f_ran_adapter_cleanup(g_cn[cn_idx]);
488}
489
Daniel Willmann19b8d902022-01-05 09:12:34 +0100490/* global initialization function */
Neels Hofmeyr333ea392023-06-27 00:58:05 +0200491function f_init(charstring id := "HNBGW", float guard_timeout := 30.0, integer nr_msc := 1, integer nr_sgsn := 1,
492 boolean start_hnb := true) runs on test_CT {
Daniel Willmann19b8d902022-01-05 09:12:34 +0100493
Daniel Willmann19b8d902022-01-05 09:12:34 +0100494 T_guard.start(guard_timeout);
495 activate(as_Tguard());
496
Pau Espin Pedrol831cb692024-04-16 12:42:28 +0200497 f_init_statsd("VirtHNBGW", vc_STATSD, mp_local_statsd_ip, mp_local_statsd_port);
Harald Welte904b5f12024-04-04 02:47:30 +0200498
Daniel Willmann19b8d902022-01-05 09:12:34 +0100499 /* RUA/RANAP emulation on top of lower-layer Iuh */
500 var RuaOps rua_ops := {
501 create_cb := refers(IuhRanapCreateCallback),
502 unitdata_cb := refers(IuhRanapUnitdataCallback)
503 };
Pau Espin Pedrol83a49612022-09-12 21:11:05 +0200504 for (var integer i := 0; i < g_num_hnbs; i := i+1) {
Daniel Willmannc79679a2022-08-23 17:48:39 +0200505 g_hnb_cfg[i] := {
506 lai := {
Neels Hofmeyr497216f2023-06-27 00:59:26 +0200507 mcc_mnc := '00F110'H,
Daniel Willmannc79679a2022-08-23 17:48:39 +0200508 lac := 2342 + i
509 },
510 sac := 55
511 };
Daniel Willmann19b8d902022-01-05 09:12:34 +0100512 f_init_hnodeb(testcasename(), i, rua_ops);
513 }
514
Neels Hofmeyr3d5a0da2023-06-27 00:57:46 +0200515 f_init_vty("VirtHNBGW");
Neels Hofmeyrffcb8892023-06-27 01:09:57 +0200516 f_ipa_ctrl_start_client(mp_hnbgw_ip, mp_hnbgw_ctrl_port);
517
Daniel Willmann19b8d902022-01-05 09:12:34 +0100518 /* MSC emulation */
Neels Hofmeyr3d5a0da2023-06-27 00:57:46 +0200519
520 /* Make sure each MSC's internal state is "DISCONNECTED" at first */
521 for (var integer i := 0; i < NUM_MSC; i := i + 1) {
522 f_vty_transceive(HNBGWVTY, "msc " & int2str(i) & " ranap reset", strict := false);
523 }
524
525 var BooleanList allow_attach := { false, false, false, false };
Neels Hofmeyr7a48df12023-04-20 20:43:43 +0200526 for (var integer i := 0; i < nr_msc; i := i + 1) {
527 var integer cn_idx := FIRST_MSC_IDX + i;
Neels Hofmeyr3d5a0da2023-06-27 00:57:46 +0200528 allow_attach[i] := true;
529 f_cn_nr_init(ps_domain := false, cn_nr := i);
Neels Hofmeyr7a48df12023-04-20 20:43:43 +0200530 }
Neels Hofmeyr3d5a0da2023-06-27 00:57:46 +0200531 /* start the test with exactly all enabled MSCs allowed to attach */
532 f_vty_cnlink_allow_attach(HNBGWVTY, false, allow_attach);
Daniel Willmann19b8d902022-01-05 09:12:34 +0100533
534 /* SGSN emulation */
Neels Hofmeyr3d5a0da2023-06-27 00:57:46 +0200535
536 /* Make sure each SGSN's internal state is "DISCONNECTED" at first */
537 for (var integer i := 0; i < NUM_SGSN; i := i + 1) {
538 f_vty_transceive(HNBGWVTY, "sgsn " & int2str(i) & " ranap reset", strict := false);
Neels Hofmeyr7a48df12023-04-20 20:43:43 +0200539 }
Daniel Willmann19b8d902022-01-05 09:12:34 +0100540
Neels Hofmeyr3d5a0da2023-06-27 00:57:46 +0200541 allow_attach := { false, false, false, false };
542 for (var integer i := 0; i < nr_sgsn; i := i + 1) {
543 var integer cn_idx := FIRST_SGSN_IDX + i;
544 allow_attach[i] := true;
545 f_cn_nr_init(ps_domain := true, cn_nr := i);
546 }
547 f_vty_cnlink_allow_attach(HNBGWVTY, true, allow_attach);
548
Daniel Willmann19b8d902022-01-05 09:12:34 +0100549 f_init_mgcp(id);
Neels Hofmeyr333ea392023-06-27 00:58:05 +0200550
551 if (start_hnb) {
552 f_start_hnbs();
553 }
Neels Hofmeyr467eb7e2023-08-10 03:38:07 +0200554
555 /* Sometimes, the RUA InitialUE-Message from a test happens too quickly, before the RANAP RESET from
556 * RAN_Emulation is through, after above f_cn_nr_init(). In the pcap it seems to be a matter of 50 ms. Give some
557 * grace. */
558 f_sleep(1.0);
Daniel Willmann19b8d902022-01-05 09:12:34 +0100559}
560
561friend function f_shutdown_helper() runs on test_CT {
Pau Espin Pedrol6c87ad92023-07-18 11:24:25 +0200562 if (mp_validate_talloc_asn1) {
563 f_verify_talloc_bytes(HNBGWVTY, {"asn1_context"}, 1);
564 }
Neels Hofmeyr75d905b2023-04-27 00:30:25 +0200565
Daniel Willmann19b8d902022-01-05 09:12:34 +0100566 all component.stop;
567 setverdict(pass);
568 mtc.stop;
569}
570
571/* helper function to start all of the simulated hNodeBs */
572function f_start_hnbs() runs on test_CT {
Pau Espin Pedrol83a49612022-09-12 21:11:05 +0200573 for (var integer i:= 0; i < g_num_hnbs; i := i+1) {
Harald Welted71d5962024-03-27 19:17:19 +0100574 f_hnbap_hnb_register(i, i);
Daniel Willmann19b8d902022-01-05 09:12:34 +0100575 }
576}
577
578/***********************************************************************
579 * code running in test_CT, preparing start of per-UE ConnHdlr
580 ***********************************************************************/
581
582/* inbound RUA connection establishment on Iuh side */
583function IuhRanapCreateCallback(ContextId context_id, RUA_IEs.CN_DomainIndicator domain, charstring id)
584runs on RUA_Emulation_CT return RUA_ConnHdlr {
585 log("CreateCallback");
586 return null;
587}
588
589/* inbound RUA connectionless data on Iuh side */
590function IuhRanapUnitdataCallback(RANAP_PDU ranap)
591runs on RUA_Emulation_CT return template RANAP_PDU {
592 log("UnitdataCallback");
593 return omit;
594}
595
596private function f_start_handler_create(TestHdlrParams pars) runs on test_CT return ConnHdlr {
597 var ConnHdlr vc_conn;
598 var charstring id := testcasename() & int2str(pars.hnb_idx);
599
600 vc_conn := ConnHdlr.create(id);
601
602 /* Iuh RUA part */
603 connect(vc_conn:RUA, vc_RUA[pars.hnb_idx]:CLIENT);
604
Neels Hofmeyr7a48df12023-04-20 20:43:43 +0200605 /* MSC or SGSN */
606 connect(vc_conn:BSSAP, g_cn[pars.cn_idx].vc_RAN:CLIENT);
607 connect(vc_conn:BSSAP_PROC, g_cn[pars.cn_idx].vc_RAN:PROC);
608
Daniel Willmann19b8d902022-01-05 09:12:34 +0100609 /* MGCP part */
610 connect(vc_conn:MGCP, vc_MGCP:MGCP_CLIENT);
611 connect(vc_conn:MGCP_PROC, vc_MGCP:MGCP_PROC);
612
Harald Welte904b5f12024-04-04 02:47:30 +0200613 connect(vc_conn:STATSD_PROC, vc_STATSD:STATSD_PROC);
614
Daniel Willmann19b8d902022-01-05 09:12:34 +0100615 return vc_conn;
616}
617
618private function f_start_handler_run(ConnHdlr vc_conn, void_fn fn, TestHdlrParams pars) runs on test_CT {
619 var charstring id := testcasename(); // & int2str(pars.ran_idx);
620 /* We cannot use vc_conn.start(f_init_handler(fn, id, pars)); as we cannot have
621 * a stand-alone 'derefers()' call, see https://www.eclipse.org/forums/index.php/t/1091364/ */
622 pars.hnb := g_hnb_cfg[pars.hnb_idx];
Daniel Willmann19b8d902022-01-05 09:12:34 +0100623 vc_conn.start(derefers(fn)(id, pars));
624}
625
626function f_start_handler_with_pars(void_fn fn, template (value) TestHdlrParams pars)
627runs on test_CT return ConnHdlr {
628 var ConnHdlr vc_conn;
629 vc_conn := f_start_handler_create(valueof(pars));
630 f_start_handler_run(vc_conn, fn, valueof(pars));
631 return vc_conn;
632}
633
634/***********************************************************************
635 * code running inside per-UE ConnHdlr
636 ***********************************************************************/
637
638type function void_fn(charstring id, TestHdlrParams pars) runs on ConnHdlr;
639
640function f_init_handler(TestHdlrParams pars, float t_guard := 20.0) runs on ConnHdlr {
641 /* make parameters available via component variable */
642 g_pars := pars;
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +0200643
644 f_init_pfcp(testcasename());
645
Daniel Willmann19b8d902022-01-05 09:12:34 +0100646 /* start guard timer and activate it as default */
647 g_Tguard.start(t_guard);
648 activate(as_Tguard_ConnHdlr());
649
Neels Hofmeyr72a8d622023-01-26 13:47:01 +0100650 map(self:HNBGWVTY, system:HNBGWVTY);
651 f_vty_set_prompts(HNBGWVTY);
652 f_vty_transceive(HNBGWVTY, "enable");
653
Daniel Willmann19b8d902022-01-05 09:12:34 +0100654 /* TODO: CTRL? */
Neels Hofmeyr59517222023-06-23 04:46:59 +0200655
656 f_sleep(1.0);
Daniel Willmann19b8d902022-01-05 09:12:34 +0100657}
658
659/* global altstep for global guard timer; */
660private altstep as_Tguard_ConnHdlr() runs on ConnHdlr {
661 [] g_Tguard.timeout {
662 setverdict(fail, "Timeout of T_guard");
663 mtc.stop;
664 }
665}
666
Neels Hofmeyrdc416c92023-03-09 02:47:50 +0100667private function f_bssap_expect(template (present) RANAP_PDU exp_rx) runs on ConnHdlr return RANAP_PDU
668{
669 var RANAP_PDU rx;
670 timer T := 5.0;
671 T.start;
672 alt {
673 [] BSSAP.receive(exp_rx) -> value rx {
674 setverdict(pass);
675 }
676 [] BSSAP.receive(RANAP_PDU:?) {
677 setverdict(fail, "Got an unexpected RANAP message on BSSAP port, was waiting for ", exp_rx);
678 mtc.stop;
679 }
680 [] T.timeout {
681 setverdict(fail, "Timeout waiting for RANAP on BSSAP port: ", exp_rx);
682 mtc.stop;
683 }
684 }
685 T.stop;
686 return rx;
687}
688
Daniel Willmann19b8d902022-01-05 09:12:34 +0100689/* send RANAP on Iuh and expect it to show up on Iu */
690function f_iuh2iu(template (present) RANAP_PDU tx, template RANAP_PDU exp_rx := omit)
691runs on ConnHdlr return RANAP_PDU {
692 var RANAP_PDU rx;
693 timer T := 5.0;
694
695 if (istemplatekind(exp_rx, "omit")) {
696 exp_rx := tx;
697 }
698
699 RUA.send(tx);
Daniel Willmann19b8d902022-01-05 09:12:34 +0100700
Neels Hofmeyrdc416c92023-03-09 02:47:50 +0100701 return f_bssap_expect(exp_rx);
Daniel Willmann19b8d902022-01-05 09:12:34 +0100702}
703
704/* send RANAP on Iu and expect it to show up on Iuh */
705function f_iu2iuh(template (present) RANAP_PDU tx, template RANAP_PDU exp_rx := omit)
706runs on ConnHdlr return RANAP_PDU {
Daniel Willmann19b8d902022-01-05 09:12:34 +0100707 if (istemplatekind(exp_rx, "omit")) {
708 exp_rx := tx;
709 }
710
711 BSSAP.send(tx);
Daniel Willmann19b8d902022-01-05 09:12:34 +0100712
Neels Hofmeyr735b6562023-03-09 02:51:28 +0100713 return f_rua_expect(exp_rx)
714}
715
716/* expect to receive a specific RUA message on Iuh */
717private function f_rua_expect(template (present) RANAP_PDU exp_rx) runs on ConnHdlr return RANAP_PDU
718{
719 var RANAP_PDU rx;
720 timer T := 5.0;
721 T.start;
Daniel Willmann19b8d902022-01-05 09:12:34 +0100722 alt {
723 [] RUA.receive(exp_rx) -> value rx {
724 setverdict(pass);
725 }
Neels Hofmeyr735b6562023-03-09 02:51:28 +0100726 [] RUA.receive(RANAP_PDU:?) {
727 setverdict(fail, "Got an unexpected RUA message, was waiting for ", exp_rx);
728 mtc.stop;
729 }
Daniel Willmann19b8d902022-01-05 09:12:34 +0100730 [] T.timeout {
731 setverdict(fail, "Timeout waiting for Iuh ", exp_rx);
Neels Hofmeyr735b6562023-03-09 02:51:28 +0100732 mtc.stop;
Daniel Willmann19b8d902022-01-05 09:12:34 +0100733 }
734 }
Neels Hofmeyr735b6562023-03-09 02:51:28 +0100735 T.stop;
Daniel Willmann19b8d902022-01-05 09:12:34 +0100736 return rx;
737}
738
739/* send RANAP on Iuh and expect it to show up on Iu */
740function f_iuh2iu_connect(template (present) RANAP_PDU tx, template RANAP_PDU exp_rx := omit)
741runs on ConnHdlr return RANAP_PDU {
742 var RANAP_PDU rx;
743 timer T := 5.0;
744
745 if (istemplatekind(exp_rx, "omit")) {
746 exp_rx := tx;
747 }
748
749 /* create an expect on the Iu side for the random NAS portion */
Neels Hofmeyrf2c95022023-04-19 01:24:39 +0200750 if (g_pars.expect_separate_sccp_cr) {
Neels Hofmeyrf0b9ed12022-06-07 17:46:32 +0200751 f_ran_register_sccp_cr_without_payload();
752 } else {
753 var template (omit) octetstring nas := f_ranap_extract_l3(valueof(tx));
754 f_ran_register_exp(valueof(nas));
755 }
Daniel Willmann19b8d902022-01-05 09:12:34 +0100756
757 /* send it via Iuh (creating a RUA connection) */
758 RUA.send(RUA_Conn_Req:{g_pars.ps_domain, tx});
759
Neels Hofmeyrf2c95022023-04-19 01:24:39 +0200760 if (g_pars.expect_separate_sccp_cr) {
Neels Hofmeyrf0b9ed12022-06-07 17:46:32 +0200761 /* Acknowledge the empty SCCP CR. RAN_Emulation does the confirmation, no need to respond. */
762 BSSAP.receive(tr_RANAP_Conn_Req());
763 }
764
Daniel Willmann19b8d902022-01-05 09:12:34 +0100765 /* expect to receive it on the Iu side */
Neels Hofmeyrdc416c92023-03-09 02:47:50 +0100766 return f_bssap_expect(exp_rx);
Daniel Willmann19b8d902022-01-05 09:12:34 +0100767}
768
Neels Hofmeyr99b7d402023-02-20 14:26:31 +0100769/* 3GPP TS 48.006 9.2 Connection release:
770 *
771 * The MSC sends a SCCP released message. This message shall not contain
772 * any user data field.
773 *
774 * So what we expect normally is:
775 *
776 * HNBGW MSC
777 * RUA --id-Disconnect-------> | ---Data-Form-1(!)---> | Iu-ReleaseComplete
778 * | <--Released---------- | (no data)
779 *
780 * This function tests osmo-hnbgw behavior if the CN fails to send a RLSD:
781 * after some timeout, osmo-hnbgw should send a RLSD to the CN.
782 */
Daniel Willmann19b8d902022-01-05 09:12:34 +0100783function f_iuh2iu_disconnect(template (present) RANAP_PDU tx, RUA_IEs.Cause cause,
784 template RANAP_PDU exp_rx := omit)
785runs on ConnHdlr return RANAP_PDU {
786 var RANAP_PDU rx
Pau Espin Pedrolee4ce862023-11-02 12:23:25 +0100787 timer T := int2float(mp_hnbgw_timer_x31) + 1.0;
Daniel Willmann19b8d902022-01-05 09:12:34 +0100788
789 if (istemplatekind(exp_rx, "omit")) {
790 exp_rx := tx;
791 }
792
793 /* send it via Iuh (creating a RUA connection) */
794 RUA.send(RUA_Disc_Req:{tx, cause});
795
796 /* expect to receive it on the Iu side */
Neels Hofmeyrdc416c92023-03-09 02:47:50 +0100797 rx := f_bssap_expect(exp_rx);
Daniel Willmann19b8d902022-01-05 09:12:34 +0100798
799 /* expect disconnect on the Iu side */
Neels Hofmeyrdc416c92023-03-09 02:47:50 +0100800 T.start;
Daniel Willmann19b8d902022-01-05 09:12:34 +0100801 alt {
802 [] BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_IND) {
803 setverdict(pass);
804 }
805 [] T.timeout {
806 setverdict(fail, "Timeout waiting for Iu disconnect");
807 return rx;
808 }
809
810 }
811 return rx;
812}
813
Neels Hofmeyrf2c95022023-04-19 01:24:39 +0200814private function f_build_initial_ue_with_nas(TestHdlrParams pars, octetstring nas)
815 return RANAP_PDU {
Harald Welte3f216c52024-03-27 20:40:17 +0100816 var RANAP_IEs.LAI lai := {
Daniel Willmann19b8d902022-01-05 09:12:34 +0100817 pLMNidentity := hex2oct(pars.hnb.lai.mcc_mnc),
818 lAC := int2oct(pars.hnb.lai.lac, 2),
819 iE_Extensions := omit
820 };
Harald Welte3f216c52024-03-27 20:40:17 +0100821 var RANAP_IEs.SAI sai := {
Daniel Willmann19b8d902022-01-05 09:12:34 +0100822 pLMNidentity := lai.pLMNidentity,
823 lAC := lai.lAC,
824 sAC := int2oct(pars.hnb.sac, 2),
825 iE_Extensions := omit
826 }
Daniel Willmann19b8d902022-01-05 09:12:34 +0100827 var IuSignallingConnectionIdentifier sigc_id := int2bit(f_rnd_int(1000), 24);
828 var GlobalRNC_ID grnc_id := {
829 pLMNidentity := lai.pLMNidentity,
830 rNC_ID := 2342
831 }
Neels Hofmeyrf2c95022023-04-19 01:24:39 +0200832 var template RANAP_PDU ret;
Daniel Willmann19b8d902022-01-05 09:12:34 +0100833 if (pars.ps_domain) {
Harald Welte3f216c52024-03-27 20:40:17 +0100834 var RANAP_IEs.RAC rac := '00'O;
Neels Hofmeyrf2c95022023-04-19 01:24:39 +0200835 ret := ts_RANAP_initialUE_PS(lai, rac, sai, nas, sigc_id, grnc_id);
Daniel Willmann19b8d902022-01-05 09:12:34 +0100836 } else {
Neels Hofmeyrf2c95022023-04-19 01:24:39 +0200837 ret := ts_RANAP_initialUE_CS(lai, sai, nas, sigc_id, grnc_id);
Daniel Willmann19b8d902022-01-05 09:12:34 +0100838 }
Neels Hofmeyrf2c95022023-04-19 01:24:39 +0200839 return valueof(ret);
840}
841
842/* build a RANAP InitialUE based on the TestHdlrParams */
843friend function f_build_initial_ue(TestHdlrParams pars) return RANAP_PDU {
844
845 var octetstring nas;
846
847 if (pars.tx_sccp_cr_data_len == 0) {
848 nas := f_rnd_octstring(10);
849 } else {
850 /* The test asks for an exact number of Optional Data bytes. */
851
852 /* First see what size the RANAP part of the payload data is,
853 * to adjust the NAS PDU size to the size requested by the test (pars.tx_sccp_cr_data_len). */
854 var RANAP_PDU initial_ue := f_build_initial_ue_with_nas(pars, '00'O);
855
856 var octetstring ranap_plus_one_byte_nas := enc_RANAP_PDU(initial_ue);
857 var integer ranap_length := lengthof(ranap_plus_one_byte_nas) - 1;
858
859 log("ranap_plus_one_byte_nas = ", lengthof(ranap_plus_one_byte_nas), " bytes, ", initial_ue, " = ",
860 ranap_plus_one_byte_nas);
861 log("ranap_length = ", ranap_length);
862
863 /* SCCP CR has a payload length limit of 130 bytes. To trigger this limit, the RANAP + NAS PDU has to be
864 * > 130 bytes. It doesn't need to be 131 bytes in the NAS PDU alone, but let's just make it definitely
865 * large enough. To test for this limit, pars.tx_sccp_cr_data_len asks for a specific amount of data len. */
866 nas := f_rnd_octstring(pars.tx_sccp_cr_data_len - ranap_length);
867 }
868
869 var RANAP_PDU ret := f_build_initial_ue_with_nas(pars, nas);
870
871 if (pars.tx_sccp_cr_data_len != 0) {
872 for (var integer attempts := 0; attempts < 2; attempts := attempts + 1) {
873 var octetstring check_len := enc_RANAP_PDU(ret);
874 log("final RANAP PDU length = ", lengthof(check_len));
875 if (lengthof(check_len) == pars.tx_sccp_cr_data_len) {
876 return ret;
877 }
878 nas := f_rnd_octstring(lengthof(nas) + (pars.tx_sccp_cr_data_len - lengthof(check_len)));
879 log("that was off, changed NAS length to ", lengthof(nas), " and trying again");
880 ret := f_build_initial_ue_with_nas(pars, nas);
881 }
882 setverdict(fail, "Ended up with wrong Optional Data length");
883 mtc.stop;
884 }
885 return ret;
Daniel Willmann19b8d902022-01-05 09:12:34 +0100886}
887
888/* build a RANAP RAB AssignmentResponse based on the TestHdlrParams */
889friend function f_build_rab_ass_resp(TestHdlrParams pars) return RANAP_PDU {
890 var template RAB_SetupOrModifiedList rab_sml;
891
892 rab_sml := ts_RAB_SMdL(t_RAB_id(23), f_ts_RAB_TLA("192.168.1.23"), t_RAB_binding_port(1234));
893
894 return valueof(ts_RANAP_RabAssResp(rab_sml));
895}
896
897
898/***********************************************************************
899 * HNBAP Testing
900 ***********************************************************************/
901
902
Harald Welted71d5962024-03-27 19:17:19 +0100903function 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 +0100904{
905 timer T := 2.0;
906
Neels Hofmeyrfffe79b2023-06-27 01:16:15 +0200907 HNBAP[hnb_idx].send(ts_HNBAP_HNBRegisterRequest(char2oct("TTCN3-HNB-" & int2str(hnb_idx)),
Harald Welte7a9e7962024-04-04 02:46:45 +0200908 hex2oct(g_hnb_cfg[hnb_idx].lai.mcc_mnc),
Daniel Willmannc79679a2022-08-23 17:48:39 +0200909 int2bit(1 + cell_id, 28),
Harald Welte7a9e7962024-04-04 02:46:45 +0200910 int2oct(g_hnb_cfg[hnb_idx].lai.lac, 2),
911 int2oct(0, 1),
912 int2oct(g_hnb_cfg[hnb_idx].sac, 2)));
Daniel Willmann19b8d902022-01-05 09:12:34 +0100913
914 T.start;
915 alt {
916 [] HNBAP[hnb_idx].receive(tr_HNBAP_HNBRegisterAccept(?)) {
Daniel Willmannc79679a2022-08-23 17:48:39 +0200917 if (expect_reject) {
918 setverdict(fail, "Rx HNB Register Accept while expecting reject");
919 } else {
920 setverdict(pass);
921 }
922 }
923 [] HNBAP[hnb_idx].receive(tr_HNBAP_HNBRegisterReject(?)) {
924 if (expect_reject) {
925 setverdict(pass);
926 } else {
927 setverdict(fail, "Rx HNB Register Reject while expecting accept");
928 }
Daniel Willmann19b8d902022-01-05 09:12:34 +0100929 }
930 [] HNBAP[hnb_idx].receive(IUHEM_Event:?) {
931 repeat;
932 }
933 [] T.timeout {
Daniel Willmannc79679a2022-08-23 17:48:39 +0200934 setverdict(fail, "Timeout waiting for HNB Register response");
Daniel Willmann19b8d902022-01-05 09:12:34 +0100935 }
936 }
937}
938
Harald Welteaf3e2162024-03-27 21:54:20 +0100939function f_hnbap_ue_register(integer hnb_idx := 0, template (present) UE_Identity ue_id, boolean expect_reject := false) runs on test_CT
940{
941 timer T := 2.0;
942
943 HNBAP[hnb_idx].send(ts_HNBAP_UERegisterRequest(ue_id));
944
945 T.start;
946 alt {
947 [] HNBAP[hnb_idx].receive(tr_HNBAP_UERegisterAccept(ue_id)) {
948 if (expect_reject) {
949 setverdict(fail, "Rx UE Register Accept while expecting reject");
950 } else {
951 setverdict(pass);
952 }
953 }
954 [] HNBAP[hnb_idx].receive(tr_HNBAP_UERegisterReject(ue_id, ?)) {
955 if (expect_reject) {
956 setverdict(pass);
957 } else {
958 setverdict(fail, "Rx UE Register Reject while expecting accept");
959 }
960 }
961 [] HNBAP[hnb_idx].receive(IUHEM_Event:?) {
962 repeat;
963 }
964 [] T.timeout {
965 setverdict(fail, "Timeout waiting for UE Register response");
966 }
967 }
968}
969
970
Daniel Willmann19b8d902022-01-05 09:12:34 +0100971testcase TC_hnb_register() runs on test_CT {
Pau Espin Pedrol83a49612022-09-12 21:11:05 +0200972 g_num_hnbs := 1;
Neels Hofmeyr333ea392023-06-27 00:58:05 +0200973 f_init(start_hnb := false);
Harald Welted71d5962024-03-27 19:17:19 +0100974 f_hnbap_hnb_register(0);
Daniel Willmann19b8d902022-01-05 09:12:34 +0100975 f_shutdown_helper();
976}
977
Pau Espin Pedrolacf4f222022-09-27 14:33:40 +0200978/* Try to register the same HNB from 2 different concurrent connections. Second
979 * one should be rejected. */
Daniel Willmannc79679a2022-08-23 17:48:39 +0200980testcase TC_hnb_register_duplicate() runs on test_CT {
Pau Espin Pedrol83a49612022-09-12 21:11:05 +0200981 g_num_hnbs := 2;
Neels Hofmeyr333ea392023-06-27 00:58:05 +0200982 f_init(start_hnb := false);
Pau Espin Pedrolfa2095b2024-04-16 17:46:44 +0200983
984 /* Make HNB REQ look as if it came from the same HnodeB (LAI+SAC),
985 * but from different IP address (underlaying link): */
986 g_hnb_cfg[1] := g_hnb_cfg[0];
Harald Welted71d5962024-03-27 19:17:19 +0100987 f_hnbap_hnb_register(0);
988 f_hnbap_hnb_register(1, 0, expect_reject := true);
Pau Espin Pedrolfa2095b2024-04-16 17:46:44 +0200989
Daniel Willmannc79679a2022-08-23 17:48:39 +0200990 f_verify_talloc_count(HNBGWVTY, {"struct hnb_context"}, expect_count := 1);
Pau Espin Pedrolfa2095b2024-04-16 17:46:44 +0200991
Daniel Willmannc79679a2022-08-23 17:48:39 +0200992 f_shutdown_helper();
993}
994
Pau Espin Pedrolacf4f222022-09-27 14:33:40 +0200995/* Try to register the same HNB in the same connection already established, aka
996 * duplicate HNB Register Request. It should be accepted and new configuration
997 * applied. TS 25.469 8.2.4 */
998testcase TC_hnb_register_duplicate_reuse_sctp_assoc() runs on test_CT {
999 g_num_hnbs := 1;
Neels Hofmeyr333ea392023-06-27 00:58:05 +02001000 f_init(start_hnb := false);
Harald Welted71d5962024-03-27 19:17:19 +01001001 f_hnbap_hnb_register(0);
1002 f_hnbap_hnb_register(0);
Pau Espin Pedrolacf4f222022-09-27 14:33:40 +02001003 f_verify_talloc_count(HNBGWVTY, {"struct hnb_context"}, expect_count := 1);
1004 f_shutdown_helper();
1005}
1006
Pau Espin Pedrolf0b9fa02022-09-12 13:31:07 +02001007/* Drop HNBAP conn (HNBAP DEREG) and reconnect it (HNBAP REG) using same SCTP association.
1008 * Related: OS#5676, SYS#6113 */
1009testcase TC_hnb_reregister_reuse_sctp_assoc() runs on test_CT {
1010 g_num_hnbs := 1;
Neels Hofmeyr333ea392023-06-27 00:58:05 +02001011 f_init(start_hnb := false);
Harald Welted71d5962024-03-27 19:17:19 +01001012 f_hnbap_hnb_register(0);
Pau Espin Pedrolf0b9fa02022-09-12 13:31:07 +02001013 HNBAP[0].send(ts_HNBAP_HNBDe_Register(ts_HnbapCause(unspecified)));
Harald Welted71d5962024-03-27 19:17:19 +01001014 f_hnbap_hnb_register(0);
Pau Espin Pedrolf0b9fa02022-09-12 13:31:07 +02001015 f_verify_talloc_count(HNBGWVTY, {"struct hnb_context"}, expect_count := 1);
1016 f_shutdown_helper();
1017}
1018
Harald Welteaf3e2162024-03-27 21:54:20 +01001019/* regular UE registration */
1020testcase TC_ue_register() runs on test_CT {
1021 var UE_Identity ue_id := { iMSI := imsi_hex2oct(f_gen_imsi(1)) };
1022 g_num_hnbs := 1;
1023 f_init(start_hnb := true);
1024 f_hnbap_ue_register(0, ue_id);
1025 f_shutdown_helper();
1026}
1027
Harald Weltef60044d2024-04-04 00:54:34 +02001028/* regular UE registration (UE Identity: TMSI+LAI) */
1029testcase TC_ue_register_tmsi_lai() runs on test_CT {
1030 var UE_Identity ue_id := { tMSILAI := { tMSI := oct2bit(f_gen_tmsi(0)),
1031 lAI := { pLMNID := '00F110'O, lAC := '2342'O }
1032 }
1033 };
1034 g_num_hnbs := 1;
1035 f_init(start_hnb := true);
1036 f_hnbap_ue_register(0, ue_id);
1037 f_shutdown_helper();
1038}
1039
1040
Harald Welteaf3e2162024-03-27 21:54:20 +01001041/* UE registration from unregistered HNB */
1042testcase TC_ue_register_before_hnb_register() runs on test_CT {
1043 var UE_Identity ue_id := { iMSI := imsi_hex2oct(f_gen_imsi(1)) };
1044 g_num_hnbs := 1;
1045 f_init(start_hnb := false);
1046 f_hnbap_ue_register(0, ue_id, expect_reject := true);
1047 f_shutdown_helper();
1048}
1049
Daniel Willmann19b8d902022-01-05 09:12:34 +01001050/***********************************************************************
1051 * RUA / RANAP Testing
1052 ***********************************************************************/
1053
Neels Hofmeyr7a48df12023-04-20 20:43:43 +02001054/* Translate from {msc,sgsn}x{0..n} to the proper index to use in g_cn[].
1055 * g_cn[] stores CN links, MSCs and SGSNs in the same array.
1056 * For example, for 'sgsn 23', use g_cn[ f_cn_idx(ps_domain := true, cn_nr := 23) ].
1057 *
1058 * Note the naming:
1059 * cn_nr is the number used in the cfg file, as in 'msc 0'.
1060 * cn_idx is the array index in g_cn[].
1061 */
1062private function f_cn_idx(boolean ps_domain, integer cn_nr := 0) return integer
1063{
1064 if (ps_domain) {
1065 return FIRST_SGSN_IDX + cn_nr;
1066 }
1067 return FIRST_MSC_IDX + cn_nr;
1068}
1069
Daniel Willmann19b8d902022-01-05 09:12:34 +01001070private template (value) TestHdlrParams
Neels Hofmeyrf0b9ed12022-06-07 17:46:32 +02001071t_pars(integer imsi_suffix, boolean ps_domain := false, integer hnb_idx := 0,
Neels Hofmeyr7a48df12023-04-20 20:43:43 +02001072 boolean expect_separate_sccp_cr := false, integer tx_sccp_cr_data_len := 0,
Harald Welte18188342024-04-04 01:36:56 +02001073 integer cn_nr := 0, template (value) RANAP_IEs.Cause rab_rel_cause := ts_RanapCause_nas_normal) := {
Daniel Willmann19b8d902022-01-05 09:12:34 +01001074 hnb_idx := hnb_idx,
Neels Hofmeyr7a48df12023-04-20 20:43:43 +02001075 cn_idx := f_cn_idx(ps_domain, cn_nr),
Daniel Willmann19b8d902022-01-05 09:12:34 +01001076 imsi := f_gen_imsi(imsi_suffix),
1077 ps_domain := ps_domain,
Pau Espin Pedrolaf746502023-11-29 16:18:28 +01001078 mgcp_pars := t_MgcpParams,
Neels Hofmeyrf0b9ed12022-06-07 17:46:32 +02001079 hnb := omit, /* filled in later */
Neels Hofmeyrf2c95022023-04-19 01:24:39 +02001080 expect_separate_sccp_cr := expect_separate_sccp_cr,
1081 tx_sccp_cr_data_len := tx_sccp_cr_data_len,
Neels Hofmeyr7d0e6802023-04-20 20:43:55 +02001082 pfcp_local_addr := mp_pfcp_ip_local,
Neels Hofmeyrb1bf16d2023-06-27 02:10:04 +02001083 nas_pdu := omit,
1084 sccp_addr_msc := omit,
Harald Welte0d4a8432024-04-04 01:12:11 +02001085 sccp_addr_hnbgw := omit,
1086 rab_rel_cause := rab_rel_cause
Daniel Willmann19b8d902022-01-05 09:12:34 +01001087}
1088
1089/* Create an Iuh connection; send InitialUE; expect it to appear on new SCCP conenction */
1090friend function f_tc_initial_ue(charstring id, TestHdlrParams pars) runs on ConnHdlr {
1091 f_init_handler(pars);
1092 var RANAP_PDU tx := f_build_initial_ue(g_pars);
1093 f_iuh2iu_connect(tx);
1094}
1095testcase TC_ranap_cs_initial_ue() runs on test_CT {
1096 var ConnHdlr vc_conn;
1097
Pau Espin Pedrol83a49612022-09-12 21:11:05 +02001098 g_num_hnbs := 1;
Daniel Willmann19b8d902022-01-05 09:12:34 +01001099 f_init();
Daniel Willmann19b8d902022-01-05 09:12:34 +01001100
1101 vc_conn := f_start_handler_with_pars(refers(f_tc_initial_ue), t_pars(1));
1102 vc_conn.done;
Neels Hofmeyr3a9140e2023-06-23 04:50:39 +02001103
1104 f_shutdown_helper();
Daniel Willmann19b8d902022-01-05 09:12:34 +01001105}
1106testcase TC_ranap_ps_initial_ue() runs on test_CT {
1107 var ConnHdlr vc_conn;
1108
Pau Espin Pedrol83a49612022-09-12 21:11:05 +02001109 g_num_hnbs := 1;
Daniel Willmann19b8d902022-01-05 09:12:34 +01001110 f_init();
Daniel Willmann19b8d902022-01-05 09:12:34 +01001111
1112 vc_conn := f_start_handler_with_pars(refers(f_tc_initial_ue), t_pars(2, true));
1113 vc_conn.done;
Neels Hofmeyr3a9140e2023-06-23 04:50:39 +02001114
1115 f_shutdown_helper();
Daniel Willmann19b8d902022-01-05 09:12:34 +01001116}
1117
Neels Hofmeyrf2c95022023-04-19 01:24:39 +02001118private function f_vty_set_sccp_max_optional_data(TELNETasp_PT pt, integer val := -1)
Neels Hofmeyrf0b9ed12022-06-07 17:46:32 +02001119{
Neels Hofmeyrf2c95022023-04-19 01:24:39 +02001120 var charstring valstr;
1121 if (val < 0) {
1122 valstr := "standard";
1123 } else {
1124 valstr := int2str(val);
1125 }
Neels Hofmeyrf0b9ed12022-06-07 17:46:32 +02001126 f_vty_enter_config(pt);
Neels Hofmeyrf2c95022023-04-19 01:24:39 +02001127 f_vty_transceive(pt, "cs7 instance 0");
1128 f_vty_transceive(pt, "sccp max-optional-data " & valstr);
Neels Hofmeyrf0b9ed12022-06-07 17:46:32 +02001129 f_vty_transceive(pt, "end");
1130}
1131
1132testcase TC_ranap_cs_initial_ue_empty_cr() runs on test_CT {
1133 var ConnHdlr vc_conn;
1134
Pau Espin Pedrol83a49612022-09-12 21:11:05 +02001135 g_num_hnbs := 1;
Neels Hofmeyrf0b9ed12022-06-07 17:46:32 +02001136 f_init();
Neels Hofmeyrf0b9ed12022-06-07 17:46:32 +02001137
Neels Hofmeyrf2c95022023-04-19 01:24:39 +02001138 f_vty_set_sccp_max_optional_data(HNBGWVTY, 0);
Neels Hofmeyrf0b9ed12022-06-07 17:46:32 +02001139
Neels Hofmeyrf2c95022023-04-19 01:24:39 +02001140 vc_conn := f_start_handler_with_pars(refers(f_tc_initial_ue), t_pars(1, expect_separate_sccp_cr := true));
Neels Hofmeyrf0b9ed12022-06-07 17:46:32 +02001141 vc_conn.done;
1142
1143 /* reset */
Neels Hofmeyrf2c95022023-04-19 01:24:39 +02001144 f_vty_set_sccp_max_optional_data(HNBGWVTY);
Neels Hofmeyr3a9140e2023-06-23 04:50:39 +02001145
1146 f_shutdown_helper();
Neels Hofmeyrf0b9ed12022-06-07 17:46:32 +02001147}
1148testcase TC_ranap_ps_initial_ue_empty_cr() runs on test_CT {
1149 var ConnHdlr vc_conn;
1150
Pau Espin Pedrol83a49612022-09-12 21:11:05 +02001151 g_num_hnbs := 1;
Neels Hofmeyrf0b9ed12022-06-07 17:46:32 +02001152 f_init();
Neels Hofmeyrf0b9ed12022-06-07 17:46:32 +02001153
Neels Hofmeyrf2c95022023-04-19 01:24:39 +02001154 f_vty_set_sccp_max_optional_data(HNBGWVTY, 0);
Neels Hofmeyrf0b9ed12022-06-07 17:46:32 +02001155
Neels Hofmeyrf2c95022023-04-19 01:24:39 +02001156 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 +02001157 vc_conn.done;
1158
1159 /* reset */
Neels Hofmeyrf2c95022023-04-19 01:24:39 +02001160 f_vty_set_sccp_max_optional_data(HNBGWVTY);
Neels Hofmeyr3a9140e2023-06-23 04:50:39 +02001161
1162 f_shutdown_helper();
Neels Hofmeyrf2c95022023-04-19 01:24:39 +02001163}
1164
1165type record Testdata_CR_Limit {
1166 integer data_len,
1167 integer max_optional_data,
1168 boolean expect_separate_sccp_cr
1169};
1170type record of Testdata_CR_Limit Testdata_CR_Limits;
1171
1172testcase TC_sccp_cr_limit() runs on test_CT {
1173 g_num_hnbs := 1;
1174 f_init();
Neels Hofmeyrf2c95022023-04-19 01:24:39 +02001175
1176 const Testdata_CR_Limits tests := {
1177 { data_len := 130, max_optional_data := -1, expect_separate_sccp_cr := false },
1178 { data_len := 131, max_optional_data := -1, expect_separate_sccp_cr := true },
1179
1180 { data_len := 100, max_optional_data := 100, expect_separate_sccp_cr := false },
1181 { data_len := 101, max_optional_data := 100, expect_separate_sccp_cr := true },
1182
1183 { data_len := 200, max_optional_data := 200, expect_separate_sccp_cr := false },
1184 { data_len := 201, max_optional_data := 200, expect_separate_sccp_cr := true }
1185 };
1186
1187 var integer csps;
1188 for (csps := 0; csps < 2; csps := csps + 1) {
1189 var boolean ps_domain := (csps > 0);
1190
1191 var integer i;
1192 for (i := 0; i < lengthof(tests); i := i + 1) {
1193 var Testdata_CR_Limit t := tests[i];
1194 f_logp(HNBGWVTY,
1195 "TEST PART TC_sccp_cr_limit ps_domain=" & f_bool2str(ps_domain)
1196 & " data_len=" & int2str(t.data_len)
1197 & " max_optional_data=" & int2str(t.max_optional_data)
1198 & " expect_separate_sccp_cr=" & f_bool2str(t.expect_separate_sccp_cr)
1199 );
1200
1201 f_vty_set_sccp_max_optional_data(HNBGWVTY, t.max_optional_data);
1202 var ConnHdlr vc_conn;
1203 vc_conn := f_start_handler_with_pars(refers(f_tc_initial_ue),
1204 t_pars(100 + i,
1205 ps_domain := ps_domain,
1206 expect_separate_sccp_cr := t.expect_separate_sccp_cr,
1207 tx_sccp_cr_data_len := t.data_len));
1208 vc_conn.done;
1209 }
1210 }
1211
1212 /* reset */
1213 f_vty_set_sccp_max_optional_data(HNBGWVTY);
Neels Hofmeyr3a9140e2023-06-23 04:50:39 +02001214
1215 f_shutdown_helper();
Neels Hofmeyrf0b9ed12022-06-07 17:46:32 +02001216}
1217
Daniel Willmann19b8d902022-01-05 09:12:34 +01001218/* Reply to a received CRCX with an OK (or the reply configured in cpars), using the given parameters.
1219 * Return true when an OK reply was sent, false otherwise.
1220 * Count occurrence of Osmux, include Osmux parameters in the reply if necessary. */
1221function f_handle_crcx(inout MgcpParameters pars, MgcpCommand mgcp_cmd) return template MgcpResponse {
Pau Espin Pedrol264679f2023-11-29 15:52:00 +01001222 var MgwResponse conn := pars.mgw_conn_ran;
Daniel Willmann19b8d902022-01-05 09:12:34 +01001223 if (pars.got_crcx_count > 0) {
Pau Espin Pedrolb85ac2f2023-11-29 15:48:57 +01001224 conn := pars.mgw_conn_cn;
Daniel Willmann19b8d902022-01-05 09:12:34 +01001225 }
1226 pars.got_crcx_count := pars.got_crcx_count + 1;
1227
1228 var MgcpMessage mgcp_msg := {
1229 command := mgcp_cmd
1230 }
1231 var template MgcpResponse mgcp_resp;
1232 var MgcpOsmuxCID osmux_cid;
1233 var MgcpCallId call_id := f_MgcpCmd_extract_call_id(mgcp_cmd);
1234 if (ispresent(pars.mgcp_call_id)) {
1235 if (pars.mgcp_call_id != call_id) {
1236 setverdict(fail, "CRCX contained unexpected call id. Expected:", pars.mgcp_call_id, " got:", call_id);
1237 mtc.stop;
1238 }
1239 } else {
1240 pars.mgcp_call_id := call_id;
1241 }
1242
1243 /* When the endpoint contains a wildcard we keep the endpoint
1244 * identifier we have set up in pars. Otherwise we use the
1245 * endpoint name that the call agent has supplied */
1246 if (match(mgcp_cmd.line.ep, t_MGCP_EP_wildcard) == false) {
1247 pars.mgcp_ep := mgcp_cmd.line.ep;
1248 }
1249
1250 if (conn.resp == -1) {
1251 /* Reply with rror */
1252 var MgcpResponse mgcp_rsp := {
1253 line := {
1254 code := "542",
1255 trans_id := mgcp_cmd.line.trans_id,
1256 string := "FORCED_FAIL"
1257 },
1258 sdp := omit
1259
1260 }
1261 var MgcpParameter mgcp_rsp_param := {
1262 code := "Z",
1263 val := pars.mgcp_ep
1264 };
1265 mgcp_rsp.params[0] := mgcp_rsp_param;
1266 return mgcp_rsp;
1267 }
1268
1269 if (conn.resp == 0) {
1270 /* Do not reply at all */
1271 return omit;
1272 }
1273
1274 if (conn.resp != 1) {
1275 setverdict(fail, "Unexpected value for pars.mgw_conn_*.resp, expect -1, 0 or 1");
1276 mtc.stop;
1277 }
1278
1279 var SDP_Message sdp := valueof(ts_SDP(conn.mgw_rtp_ip, conn.mgw_rtp_ip,
1280 hex2str(pars.mgcp_call_id), "42",
1281 conn.mgw_rtp_port,
1282 { int2str(pars.rtp_payload_type) },
1283 { valueof(ts_SDP_rtpmap(pars.rtp_payload_type,
1284 pars.rtp_sdp_format)),
1285 valueof(ts_SDP_ptime(20)) }));
1286
1287 if (f_mgcp_contains_par(mgcp_msg, "X-OSMUX")) {
1288 if (not pars.use_osmux) {
1289 setverdict(fail, "MSC sent X-Osmux parameter in MGCP, but not expecting any Osmux");
1290 mtc.stop;
1291 }
1292 pars.got_osmux_count := pars.got_osmux_count + 1;
1293 /* we expect MSC to use wildcard here, i.e. osmux_cid == -1 */
1294 osmux_cid := f_MgcpCmd_extract_osmux_cid(mgcp_cmd);
1295 log("f_handle_crcx(): got Osmux CID: ", osmux_cid);
1296 if (osmux_cid != -1) {
1297 setverdict(fail, "MSC using unexpected CID " & int2str(osmux_cid) & " != -1");
1298 mtc.stop;
1299 }
1300
1301 osmux_cid := 0;
1302 mgcp_resp := ts_CRCX_ACK_osmux(mgcp_cmd.line.trans_id, conn.mgcp_connection_id, osmux_cid, sdp);
1303 } else {
1304 mgcp_resp := ts_CRCX_ACK(mgcp_cmd.line.trans_id, conn.mgcp_connection_id, sdp);
1305 }
1306
1307 f_mgcp_par_append(mgcp_resp.params, ts_MgcpParSpecEP(pars.mgcp_ep));
1308
1309 return mgcp_resp;
1310}
1311
Daniel Willmann3e15b7b2022-02-21 17:07:02 +01001312friend function f_create_rab(inout MgcpParameters pars) runs on ConnHdlr {
1313 f_rab_ass_req(pars);
1314 f_rab_ass_resp(pars);
1315}
1316
1317friend function f_rab_ass_req(inout MgcpParameters pars) runs on ConnHdlr {
Daniel Willmann19b8d902022-01-05 09:12:34 +01001318 var MgcpCommand mgcp_cmd;
1319 var RANAP_PDU tx;
1320 var template RAB_SetupOrModifyList rab_sml;
Daniel Willmann19b8d902022-01-05 09:12:34 +01001321 timer T := 5.0;
1322
1323 /* Send RAB Assignment Request */
1324 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));
1325 tx := valueof(ts_RANAP_RabAssReq(rab_sml));
1326 BSSAP.send(tx);
1327 T.start;
1328
1329 /* Handle MGCP CRCX */
1330 alt {
1331 [] MGCP.receive(tr_CRCX) -> value mgcp_cmd {
1332 log("CRCX1", mgcp_cmd);
1333 var template MgcpResponse mgcp_rsp := f_handle_crcx(pars, mgcp_cmd);
1334 MGCP.send(valueof(mgcp_rsp));
1335 }
1336 [] T.timeout {
1337 setverdict(fail, "Timeout waiting for MGCP");
1338 }
1339 }
Neels Hofmeyr735b6562023-03-09 02:51:28 +01001340 T.stop;
Daniel Willmann19b8d902022-01-05 09:12:34 +01001341
1342 /* Expect RAB Assignment Request with IP/port from CRCX ACK via Iuh */
Pau Espin Pedrolb85ac2f2023-11-29 15:48:57 +01001343 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 +01001344 tx := valueof(ts_RANAP_RabAssReq(rab_sml));
1345
Neels Hofmeyr735b6562023-03-09 02:51:28 +01001346 f_rua_expect(tx);
Daniel Willmann3e15b7b2022-02-21 17:07:02 +01001347}
1348
1349friend function f_rab_ass_resp(inout MgcpParameters pars) runs on ConnHdlr {
1350 var MgcpCommand mgcp_cmd;
1351 var RANAP_PDU tx;
1352 var template RAB_SetupOrModifiedList rab_smdl;
Daniel Willmann19b8d902022-01-05 09:12:34 +01001353
1354 /* Send back RAB Assignment Response via Iuh */
1355 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));
1356 tx := valueof(ts_RANAP_RabAssResp(rab_smdl));
1357 RUA.send(tx);
Daniel Willmann19b8d902022-01-05 09:12:34 +01001358
1359 interleave {
1360 /* Expect MDCX with IP/port from RAB Assignment Response */
1361 [] 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 +01001362 var HostName mgw_rtp_ip;
Pau Espin Pedrolaf746502023-11-29 16:18:28 +01001363 var boolean exp_rua_rab_reass := false;
Daniel Willmann19b8d902022-01-05 09:12:34 +01001364 log("MDCX1", mgcp_cmd);
Pau Espin Pedrol0c35a632023-11-29 16:00:35 +01001365 if (ispresent(pars.mgw_conn_ran.mgw_rtp_ip_mdcx)) {
1366 mgw_rtp_ip := pars.mgw_conn_ran.mgw_rtp_ip_mdcx;
Pau Espin Pedrolaf746502023-11-29 16:18:28 +01001367 if (pars.mgw_conn_ran.mgw_rtp_ip != pars.mgw_conn_ran.mgw_rtp_ip_mdcx) {
1368 exp_rua_rab_reass := true;
1369 }
Pau Espin Pedrol0c35a632023-11-29 16:00:35 +01001370 } else {
1371 mgw_rtp_ip := pars.mgw_conn_ran.mgw_rtp_ip;
1372 }
1373
Daniel Willmann19b8d902022-01-05 09:12:34 +01001374 /* Verify SDP of MDCX */
Pau Espin Pedrol0c35a632023-11-29 16:00:35 +01001375 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 +01001376 { 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 +01001377 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 +01001378 MGCP.send(valueof(mgcp_rsp));
Pau Espin Pedrolaf746502023-11-29 16:18:28 +01001379
1380 /* If IP address changed, we expect HNBGW to Modify the RAB through RAB-Ass-Req: */
1381 if (exp_rua_rab_reass) {
1382 var template RAB_SetupOrModifyList rab_sml;
1383 /* Expect RAB Assignment Request with IP/port from MDCX ACK via Iuh */
1384 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));
1385 tx := valueof(ts_RANAP_RabAssReq(rab_sml));
1386
1387 f_rua_expect(tx);
1388 /* Send back RAB Assignment Response via Iuh */
1389 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));
1390 tx := valueof(ts_RANAP_RabAssResp(rab_smdl));
1391 RUA.send(tx);
1392 /* This shouldn't trigger any MGCP, since nothing changed on the HNB IP side. Continue below. */
1393 }
Daniel Willmann19b8d902022-01-05 09:12:34 +01001394 }
1395 /* Handle CRCX for second leg of endpoint, answer with IP/port */
1396 [] MGCP.receive(tr_CRCX(pars.mgcp_ep, tr_SDP(pars.cn_rtp_ip, pars.cn_rtp_port))) -> value mgcp_cmd {
1397 log("CRCX2", mgcp_cmd);
1398 /* Verify SDP of CRCX */
1399 var template MgcpResponse mgcp_rsp := f_handle_crcx(pars, mgcp_cmd);
1400 MGCP.send(valueof(mgcp_rsp));
1401 }
1402 }
1403
1404 /* Expect RAB Assignment Response with IP/port from second CRCX ACK */
Pau Espin Pedrolb85ac2f2023-11-29 15:48:57 +01001405 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 +01001406 tx := valueof(ts_RANAP_RabAssResp(rab_smdl));
1407
Neels Hofmeyrdc416c92023-03-09 02:47:50 +01001408 f_bssap_expect(tx);
Daniel Willmann19b8d902022-01-05 09:12:34 +01001409}
1410
1411private altstep as_mgcp_dlcx(inout TestHdlrParams pars) runs on ConnHdlr {
1412 var MgcpCommand mgcp_cmd;
1413
1414 [] MGCP.receive(tr_DLCX(pars.mgcp_pars.mgcp_ep)) -> value mgcp_cmd {
1415 log("DLCX", mgcp_cmd);
1416 MGCP.send(ts_DLCX_ACK2(mgcp_cmd.line.trans_id));
1417 pars.mgcp_pars.got_dlcx_count := pars.mgcp_pars.got_dlcx_count + 1;
Daniel Willmann3e15b7b2022-02-21 17:07:02 +01001418 if (pars.mgcp_pars.got_dlcx_count != pars.mgcp_pars.got_crcx_count) {
Daniel Willmann19b8d902022-01-05 09:12:34 +01001419 repeat;
1420 }
1421 setverdict(pass);
1422 }
1423}
1424
1425friend function f_tc_rab_assignment(charstring id, TestHdlrParams pars) runs on ConnHdlr {
Harald Welte904b5f12024-04-04 02:47:30 +02001426 const charstring hnb0_ctr_prefix := "TTCN3.hnb.001-01-L2342-R0-S55-C1.";
Daniel Willmann19b8d902022-01-05 09:12:34 +01001427 var MgcpCommand mgcp_cmd;
1428 var RANAP_PDU tx;
1429 timer T := 5.0;
1430
1431 f_init_handler(pars);
1432 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
1433
Harald Welte904b5f12024-04-04 02:47:30 +02001434 f_statsd_reset();
1435
Daniel Willmann19b8d902022-01-05 09:12:34 +01001436 tx := f_build_initial_ue(g_pars);
1437 f_iuh2iu_connect(tx);
1438
Harald Welte904b5f12024-04-04 02:47:30 +02001439 /* Expect stats to be 0 */
1440 var StatsDExpects expect := {
1441 {name := hnb0_ctr_prefix & "ranap.cs.rab_act.req", mtype := "c", min := 0, max := 0},
1442 {name := hnb0_ctr_prefix & "ranap.cs.rab_act.cnf", mtype := "c", min := 0, max := 0},
1443 {name := hnb0_ctr_prefix & "ranap.cs.rab_act.fail", mtype := "c", min := 0, max := 0}
1444 };
Oliver Smitha4b72ce2024-04-30 11:57:50 +02001445 if (f_osmo_repo_is("nightly")) {
1446 f_statsd_expect(expect);
1447 }
Harald Welte904b5f12024-04-04 02:47:30 +02001448
Daniel Willmann19b8d902022-01-05 09:12:34 +01001449 f_create_rab(pars.mgcp_pars);
1450
Harald Welte904b5f12024-04-04 02:47:30 +02001451 expect := {
1452 {name := hnb0_ctr_prefix & "ranap.cs.rab_act.req", mtype := "c", min := 1, max := 1},
1453 {name := hnb0_ctr_prefix & "ranap.cs.rab_act.cnf", mtype := "c", min := 1, max := 1},
1454 {name := hnb0_ctr_prefix & "ranap.cs.rab_act.fail", mtype := "c", min := 0, max := 0}
1455 };
Oliver Smitha4b72ce2024-04-30 11:57:50 +02001456 if (f_osmo_repo_is("nightly")) {
1457 f_statsd_expect(expect);
1458 }
Harald Welte904b5f12024-04-04 02:47:30 +02001459
Daniel Willmann19b8d902022-01-05 09:12:34 +01001460 /* Send Iu Release */
Harald Welte0d4a8432024-04-04 01:12:11 +02001461 tx := valueof(ts_RANAP_IuReleaseCommand(pars.rab_rel_cause));
Daniel Willmann19b8d902022-01-05 09:12:34 +01001462 f_iu2iuh(tx);
1463
1464 T.start;
1465 alt {
1466 [] as_mgcp_dlcx(pars) {}
1467 [] T.timeout {
1468 setverdict(fail, "Timeout waiting for DLCX");
1469 }
1470 }
1471
1472 tx := valueof(ts_RANAP_IuReleaseComplete());
1473 f_iuh2iu(tx);
1474}
1475
1476testcase TC_rab_assignment() runs on test_CT {
1477 var ConnHdlr vc_conn;
Pau Espin Pedrol83a49612022-09-12 21:11:05 +02001478 g_num_hnbs := 1;
Daniel Willmann19b8d902022-01-05 09:12:34 +01001479 f_init();
Daniel Willmann19b8d902022-01-05 09:12:34 +01001480
1481 vc_conn := f_start_handler_with_pars(refers(f_tc_rab_assignment), t_pars(3));
1482 vc_conn.done;
Neels Hofmeyr3a9140e2023-06-23 04:50:39 +02001483
1484 f_shutdown_helper();
Daniel Willmann19b8d902022-01-05 09:12:34 +01001485}
1486
Daniel Willmann3e15b7b2022-02-21 17:07:02 +01001487friend function f_tc_rab_assign_fail(charstring id, TestHdlrParams pars) runs on ConnHdlr {
Harald Welte904b5f12024-04-04 02:47:30 +02001488 const charstring hnb0_ctr_prefix := "TTCN3.hnb.001-01-L2342-R0-S55-C1.";
Daniel Willmann3e15b7b2022-02-21 17:07:02 +01001489 var MgcpCommand mgcp_cmd;
1490 var RANAP_PDU tx;
1491 timer T := 5.0;
1492
1493 f_init_handler(pars);
1494 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
1495
Harald Welte904b5f12024-04-04 02:47:30 +02001496 f_statsd_reset();
1497
Daniel Willmann3e15b7b2022-02-21 17:07:02 +01001498 tx := f_build_initial_ue(g_pars);
1499 f_iuh2iu_connect(tx);
1500
Harald Welte904b5f12024-04-04 02:47:30 +02001501 /* Expect stats to be 0 */
1502 var StatsDExpects expect := {
1503 {name := hnb0_ctr_prefix & "ranap.cs.rab_act.req", mtype := "c", min := 0, max := 0},
1504 {name := hnb0_ctr_prefix & "ranap.cs.rab_act.cnf", mtype := "c", min := 0, max := 0},
1505 {name := hnb0_ctr_prefix & "ranap.cs.rab_act.fail", mtype := "c", min := 0, max := 0}
1506 };
Oliver Smitha4b72ce2024-04-30 11:57:50 +02001507 if (f_osmo_repo_is("nightly")) {
1508 f_statsd_expect(expect);
1509 }
Harald Welte904b5f12024-04-04 02:47:30 +02001510
Daniel Willmann3e15b7b2022-02-21 17:07:02 +01001511 f_rab_ass_req(pars.mgcp_pars);
1512
1513 /* Send RAB failed list in response */
Harald Welte0d4a8432024-04-04 01:12:11 +02001514 tx := valueof(ts_RANAP_RabAssResp(rab_fl := ts_RAB_FL(t_RAB_id(23), pars.rab_rel_cause)));
Daniel Willmann3e15b7b2022-02-21 17:07:02 +01001515 f_iuh2iu(tx);
1516
Harald Welte904b5f12024-04-04 02:47:30 +02001517 expect := {
1518 {name := hnb0_ctr_prefix & "ranap.cs.rab_act.req", mtype := "c", min := 1, max := 1},
1519 {name := hnb0_ctr_prefix & "ranap.cs.rab_act.cnf", mtype := "c", min := 0, max := 0},
1520 {name := hnb0_ctr_prefix & "ranap.cs.rab_act.fail", mtype := "c", min := 1, max := 1}
1521 };
Oliver Smitha4b72ce2024-04-30 11:57:50 +02001522 if (f_osmo_repo_is("nightly")) {
1523 f_statsd_expect(expect);
1524 }
Harald Welte904b5f12024-04-04 02:47:30 +02001525
1526
Daniel Willmann3e15b7b2022-02-21 17:07:02 +01001527 T.start;
1528 alt {
1529 [] as_mgcp_dlcx(pars) {}
1530 [] T.timeout {
1531 setverdict(fail, "Timeout waiting for DLCX");
1532 }
1533 }
1534}
1535
1536testcase TC_rab_assign_fail() runs on test_CT {
1537 var ConnHdlr vc_conn;
Pau Espin Pedrol83a49612022-09-12 21:11:05 +02001538 g_num_hnbs := 1;
Daniel Willmann3e15b7b2022-02-21 17:07:02 +01001539 f_init();
Daniel Willmann3e15b7b2022-02-21 17:07:02 +01001540
Harald Welte18188342024-04-04 01:36:56 +02001541 vc_conn := f_start_handler_with_pars(refers(f_tc_rab_assign_fail), t_pars(4, rab_rel_cause := ts_RanapCause_radio_conn_lost));
Daniel Willmann3e15b7b2022-02-21 17:07:02 +01001542 vc_conn.done;
Neels Hofmeyr3a9140e2023-06-23 04:50:39 +02001543
1544 f_shutdown_helper();
Daniel Willmann3e15b7b2022-02-21 17:07:02 +01001545}
1546
Daniel Willmann19b8d902022-01-05 09:12:34 +01001547friend function f_tc_rab_release(charstring id, TestHdlrParams pars) runs on ConnHdlr {
Harald Welte904b5f12024-04-04 02:47:30 +02001548 const charstring hnb0_ctr_prefix := "TTCN3.hnb.001-01-L2342-R0-S55-C1.";
Daniel Willmann19b8d902022-01-05 09:12:34 +01001549 var MgcpCommand mgcp_cmd;
1550 var RANAP_PDU tx;
1551 timer T := 15.0;
1552
1553 f_init_handler(pars);
1554 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
1555
Harald Welte904b5f12024-04-04 02:47:30 +02001556 f_statsd_reset();
1557
Daniel Willmann19b8d902022-01-05 09:12:34 +01001558 tx := f_build_initial_ue(g_pars);
1559 f_iuh2iu_connect(tx);
1560
1561 f_create_rab(pars.mgcp_pars);
1562
Harald Welte904b5f12024-04-04 02:47:30 +02001563 var charstring ctr_name;
1564 if (pars.rab_rel_cause == valueof(ts_RanapCause_nas_normal)) {
1565 ctr_name := "ranap.cs.rab_rel.req.normal";
1566 } else {
1567 ctr_name := "ranap.cs.rab_rel.req.abnormal";
1568 }
1569
1570 /* Expect stats to be 0 */
1571 var StatsDExpects expect := {
1572 {name := hnb0_ctr_prefix & ctr_name, mtype := "c", min := 0, max := 0}
1573 };
Oliver Smitha4b72ce2024-04-30 11:57:50 +02001574 if (f_osmo_repo_is("nightly")) {
1575 f_statsd_expect(expect);
1576 }
Harald Welte904b5f12024-04-04 02:47:30 +02001577
Daniel Willmann19b8d902022-01-05 09:12:34 +01001578 /* Send RAB Release */
Harald Welte0d4a8432024-04-04 01:12:11 +02001579 tx := valueof(ts_RANAP_RabAssReq(rab_rl := ts_RAB_RL(t_RAB_id(23), pars.rab_rel_cause)));
Daniel Willmann19b8d902022-01-05 09:12:34 +01001580 BSSAP.send(tx);
1581
Harald Welte904b5f12024-04-04 02:47:30 +02001582 expect := {
1583 {name := hnb0_ctr_prefix & ctr_name, mtype := "c", min := 1, max := 1}
1584 };
Oliver Smitha4b72ce2024-04-30 11:57:50 +02001585 if (f_osmo_repo_is("nightly")) {
1586 f_statsd_expect(expect);
1587 }
Harald Welte904b5f12024-04-04 02:47:30 +02001588
Daniel Willmann19b8d902022-01-05 09:12:34 +01001589 T.start;
1590
1591 alt {
1592 [] as_mgcp_dlcx(pars) {}
1593 [] T.timeout {
1594 setverdict(fail, "Timeout waiting for DLCX");
1595 }
1596 }
Neels Hofmeyr735b6562023-03-09 02:51:28 +01001597 T.stop;
Daniel Willmann19b8d902022-01-05 09:12:34 +01001598
Neels Hofmeyr735b6562023-03-09 02:51:28 +01001599 f_rua_expect(tx);
Daniel Willmann19b8d902022-01-05 09:12:34 +01001600}
1601
Harald Weltef95ab2d2024-04-04 01:32:20 +02001602/* RAB release with Cause NAS/Normal (successful/orderly release) */
Daniel Willmann19b8d902022-01-05 09:12:34 +01001603testcase TC_rab_release() runs on test_CT {
1604 var ConnHdlr vc_conn;
Pau Espin Pedrol83a49612022-09-12 21:11:05 +02001605 g_num_hnbs := 1;
Daniel Willmann19b8d902022-01-05 09:12:34 +01001606 f_init();
Daniel Willmann19b8d902022-01-05 09:12:34 +01001607
1608 vc_conn := f_start_handler_with_pars(refers(f_tc_rab_release), t_pars(5));
1609 vc_conn.done;
Neels Hofmeyr3a9140e2023-06-23 04:50:39 +02001610
1611 f_shutdown_helper();
Daniel Willmann19b8d902022-01-05 09:12:34 +01001612}
1613
Harald Weltef95ab2d2024-04-04 01:32:20 +02001614/* RAB release with Cause abnormal */
1615testcase TC_rab_release_abnormal() runs on test_CT {
1616 var ConnHdlr vc_conn;
1617 g_num_hnbs := 1;
1618 f_init();
1619
Harald Welte7a9e7962024-04-04 02:46:45 +02001620 vc_conn := f_start_handler_with_pars(refers(f_tc_rab_release),
1621 t_pars(8, rab_rel_cause := ts_RanapCause_radio_conn_lost));
Harald Weltef95ab2d2024-04-04 01:32:20 +02001622 vc_conn.done;
1623
1624 f_shutdown_helper();
1625}
1626
Daniel Willmann37c877f2022-02-22 16:47:06 +01001627friend function f_tc_rab_assign_mgcp_to(charstring id, TestHdlrParams pars) runs on ConnHdlr {
1628 var MgcpCommand mgcp_cmd;
1629 var RANAP_PDU tx;
1630 var template RAB_SetupOrModifyList rab_sml;
1631 timer T := 15.0;
1632
1633 T.start;
1634 f_init_handler(pars);
1635 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
1636
1637 tx := f_build_initial_ue(g_pars);
1638 f_iuh2iu_connect(tx);
1639
1640
1641 /* Send RAB Assignment Request */
1642 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));
1643 tx := valueof(ts_RANAP_RabAssReq(rab_sml));
1644 BSSAP.send(tx);
1645
1646 /* Ignore MGCP CRCX */
1647 alt {
1648 [] MGCP.receive(tr_CRCX) -> value mgcp_cmd {
1649 log("Ignoreing CRCX1", mgcp_cmd);
1650 repeat;
1651 }
1652 [] BSSAP.receive(tr_RANAP_IuReleaseRequest(?)) { }
1653 [] T.timeout {
1654 setverdict(fail, "Timeout waiting for IuRelease");
1655 }
1656 }
1657
1658 /* Send Iu Release */
Harald Welte0d4a8432024-04-04 01:12:11 +02001659 tx := valueof(ts_RANAP_IuReleaseCommand(pars.rab_rel_cause));
Daniel Willmann37c877f2022-02-22 16:47:06 +01001660 f_iu2iuh(tx);
1661
1662 tx := valueof(ts_RANAP_IuReleaseComplete());
1663 f_iuh2iu(tx);
1664}
1665
1666testcase TC_rab_assign_mgcp_to() runs on test_CT {
1667 var ConnHdlr vc_conn;
Pau Espin Pedrol83a49612022-09-12 21:11:05 +02001668 g_num_hnbs := 1;
Daniel Willmann37c877f2022-02-22 16:47:06 +01001669 f_init();
Daniel Willmann37c877f2022-02-22 16:47:06 +01001670
1671 vc_conn := f_start_handler_with_pars(refers(f_tc_rab_assign_mgcp_to), t_pars(6));
1672 vc_conn.done;
Neels Hofmeyr3a9140e2023-06-23 04:50:39 +02001673
1674 f_shutdown_helper();
Daniel Willmann37c877f2022-02-22 16:47:06 +01001675}
1676
Pau Espin Pedrolaf746502023-11-29 16:18:28 +01001677/* Test case where IuUP IP address announced by HNB and updated through MDCX
1678 * makes MGW select a new local IuUP address. HNBGW is expected to update the HNB
1679 * through RAB-Modify-Req. */
1680testcase TC_rab_assign_mgw_iuup_addr_chg() runs on test_CT {
1681 var ConnHdlr vc_conn;
1682 g_num_hnbs := 1;
1683 f_init();
1684 var template (value) TestHdlrParams pars := t_pars(3);
1685 /* Emulate change of local IuUP IP address after rx MDCX: */
1686 pars.mgcp_pars.mgw_conn_ran.mgw_rtp_ip_mdcx := "127.3.2.1";
1687
1688 vc_conn := f_start_handler_with_pars(refers(f_tc_rab_assignment), pars);
1689 vc_conn.done;
1690
1691 f_shutdown_helper();
1692}
1693
Daniel Willmann19b8d902022-01-05 09:12:34 +01001694/* Create an Iuh connection; send InitialUE; transceive data both directions */
1695friend function f_tc_ranap_bidir(charstring id, TestHdlrParams pars) runs on ConnHdlr {
1696 f_init_handler(pars);
1697
1698 /* HNB -> MSC: InitialUE */
1699 f_iuh2iu_connect(f_build_initial_ue(g_pars));
1700
1701 /* MSC <- HNB: DirectTransfer */
1702 f_iu2iuh(ts_RANAP_DirectTransfer(f_rnd_octstring(10)));
1703 /* MSC -> HNB: DirectTransfer */
1704 f_iuh2iu(ts_RANAP_DirectTransfer(f_rnd_octstring(10)));
1705
1706 /* HNB <- MSC: CommonID */
1707 f_iu2iuh(ts_RANAP_CommonId(hex2oct(pars.imsi)));
1708}
1709testcase TC_ranap_cs_bidir() runs on test_CT {
1710 var ConnHdlr vc_conn;
Pau Espin Pedrol83a49612022-09-12 21:11:05 +02001711 g_num_hnbs := 1;
Daniel Willmann19b8d902022-01-05 09:12:34 +01001712 f_init();
Daniel Willmann19b8d902022-01-05 09:12:34 +01001713
1714 vc_conn := f_start_handler_with_pars(refers(f_tc_ranap_bidir), t_pars(3));
1715 vc_conn.done;
Neels Hofmeyr3a9140e2023-06-23 04:50:39 +02001716
1717 f_shutdown_helper();
Daniel Willmann19b8d902022-01-05 09:12:34 +01001718}
1719testcase TC_ranap_ps_bidir() runs on test_CT {
1720 var ConnHdlr vc_conn;
Pau Espin Pedrol83a49612022-09-12 21:11:05 +02001721 g_num_hnbs := 1;
Daniel Willmann19b8d902022-01-05 09:12:34 +01001722 f_init();
Daniel Willmann19b8d902022-01-05 09:12:34 +01001723
1724 vc_conn := f_start_handler_with_pars(refers(f_tc_ranap_bidir), t_pars(4, true));
1725 vc_conn.done;
Neels Hofmeyr3a9140e2023-06-23 04:50:39 +02001726
1727 f_shutdown_helper();
Daniel Willmann19b8d902022-01-05 09:12:34 +01001728}
1729
1730
1731private function f_tc_ranap_mo_disconnect(charstring id, TestHdlrParams pars) runs on ConnHdlr {
1732 f_init_handler(pars);
1733
1734 /* HNB -> MSC: InitialUE */
1735 f_iuh2iu_connect(f_build_initial_ue(g_pars));
1736
1737 /* MSC <- HNB: DirectTransfer */
1738 f_iu2iuh(ts_RANAP_DirectTransfer(f_rnd_octstring(10)));
1739 /* MSC -> HNB: DirectTransfer */
1740 f_iuh2iu(ts_RANAP_DirectTransfer(f_rnd_octstring(10)));
1741
1742 /* MSC <- HNB: RUA disconnect */
1743 f_iuh2iu_disconnect(ts_RANAP_IuReleaseComplete, RUA_IEs.Cause:{misc:=processing_overload});
1744}
1745testcase TC_ranap_cs_mo_disconnect() runs on test_CT {
1746 var ConnHdlr vc_conn;
Pau Espin Pedrol83a49612022-09-12 21:11:05 +02001747 g_num_hnbs := 1;
Daniel Willmann19b8d902022-01-05 09:12:34 +01001748 f_init();
Daniel Willmann19b8d902022-01-05 09:12:34 +01001749
1750 vc_conn := f_start_handler_with_pars(refers(f_tc_ranap_mo_disconnect), t_pars(5));
1751 vc_conn.done;
Neels Hofmeyr3a9140e2023-06-23 04:50:39 +02001752
1753 f_shutdown_helper();
Daniel Willmann19b8d902022-01-05 09:12:34 +01001754}
1755testcase TC_ranap_ps_mo_disconnect() runs on test_CT {
1756 var ConnHdlr vc_conn;
Pau Espin Pedrol83a49612022-09-12 21:11:05 +02001757 g_num_hnbs := 1;
Daniel Willmann19b8d902022-01-05 09:12:34 +01001758 f_init();
Daniel Willmann19b8d902022-01-05 09:12:34 +01001759
1760 vc_conn := f_start_handler_with_pars(refers(f_tc_ranap_mo_disconnect), t_pars(6));
1761 vc_conn.done;
Neels Hofmeyr3a9140e2023-06-23 04:50:39 +02001762
1763 f_shutdown_helper();
Daniel Willmann19b8d902022-01-05 09:12:34 +01001764}
1765
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001766type record FTeid {
1767 HostName addr,
1768 OCT4 teid
1769}
1770
1771type record FTeids {
1772 FTeid local,
1773 FTeid remote
1774}
Daniel Willmann19b8d902022-01-05 09:12:34 +01001775
1776
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001777/* 'local' and 'remote' refer to the GTP information from the UPF's point of view:
1778 * HNB UPF CN
1779 * access.remote <---> access.local | core.local <---> core.remote
1780 */
1781type record GtpParameters {
1782 FTeids core,
1783 FTeids access
1784}
1785
1786/* HNB UPF CN
1787 * access.remote <---> access.local | core.local <---> core.remote
1788 * 127.0.0.4 127.0.0.3 127.0.0.2 127.0.0.1
1789 * 0x44004400 0x30303030 0x22002200 0x10101010
1790 */
1791template GtpParameters t_GtpParameters := {
1792 core := {
1793 local := {
1794 addr := "127.0.0.2",
1795 teid := '22002200'O
1796 },
1797 remote := {
1798 addr := "127.0.0.1",
1799 teid := '10101010'O
1800 }
1801 },
1802 access := {
1803 local := {
1804 addr := "127.0.0.3",
1805 teid := '30303030'O
1806 },
1807 remote := {
1808 addr := "127.0.0.4",
1809 teid := '44004400'O
1810 }
1811 }
1812}
1813
Neels Hofmeyr65499282023-04-25 02:31:51 +02001814private 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 +01001815{
1816 var PDU_PFCP rx;
Neels Hofmeyr65499282023-04-25 02:31:51 +02001817 timer T := wait_time;
Neels Hofmeyr6bbfe052023-03-09 02:51:46 +01001818 T.start;
1819 alt {
1820 [] PFCP.receive(exp_rx) -> value rx {
1821 setverdict(pass);
1822 }
1823 [] PFCP.receive(PDU_PFCP:?) {
1824 setverdict(fail, "Got an unexpected PFCP message, was waiting for ", exp_rx);
1825 mtc.stop;
1826 }
1827 [] T.timeout {
1828 setverdict(fail, "Timeout waiting for PFCP ", exp_rx);
1829 mtc.stop;
1830 }
1831 }
1832 T.stop;
1833 return rx;
1834}
1835
Neels Hofmeyrbacb74f2022-08-29 16:24:12 +02001836friend function f_tc_ps_rab_assignment_with_pfcp(charstring id, TestHdlrParams pars) runs on ConnHdlr {
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001837 var RANAP_PDU tx;
1838 var RANAP_PDU rx;
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001839
1840 f_init_handler(pars);
1841
1842 f_pfcp_register();
1843
1844 var PDU_PFCP m;
1845 var Node_ID upf_node_id := valueof(ts_PFCP_Node_ID_fqdn("\07osmocom\03org"));
1846
Neels Hofmeyr65499282023-04-25 02:31:51 +02001847 m := f_pfcp_expect(tr_PFCP_Assoc_Setup_Req(), wait_time := 15.0);
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001848 PFCP.send(ts_PFCP_Assoc_Setup_Resp(m.sequence_number, upf_node_id,
1849 ts_PFCP_Cause(REQUEST_ACCEPTED), 1234));
1850
1851 tx := f_build_initial_ue(g_pars);
1852 f_iuh2iu_connect(tx);
1853
1854 var GtpParameters gtp_pars := valueof(t_GtpParameters);
1855 var template RAB_SetupOrModifyList rab_sml;
1856
1857 /* Send RAB Assignment Request */
1858 rab_sml := ts_RAB_SML_ps(t_RAB_id(23), f_ts_RAB_TLA(gtp_pars.core.remote.addr), gtp_pars.core.remote.teid);
1859 tx := valueof(ts_RANAP_RabAssReq(rab_sml));
1860 BSSAP.send(tx);
1861
1862 /* Expect PFCP Session Establishment Request. */
Neels Hofmeyr6bbfe052023-03-09 02:51:46 +01001863 m := f_pfcp_expect(tr_PFCP_Session_Est_Req());
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001864 var F_SEID hnbgw_f_seid := m.message_body.pfcp_session_establishment_request.CP_F_SEID;
1865 var PFCP_Session_Establishment_Request serq := m.message_body.pfcp_session_establishment_request;
1866
1867 /* Acting as UPF, invent a new PFCP SEID to send to HNBGW. Respond to the Session Establishment.
1868 * The PFCP response must have the same sequence_number as the request. */
Neels Hofmeyr1e311462023-01-11 01:19:12 +01001869 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 +02001870 var template PDU_PFCP r := ts_PFCP_Session_Est_Resp(m.sequence_number, upf_node_id, hnbgw_f_seid.seid);
1871 r.message_body.pfcp_session_establishment_response := {
1872 offending_ie := omit,
1873 UP_F_SEID := up_f_seid,
1874 created_PDR_list := {
1875 ts_PFCP_Created_PDR(pdr_id := serq.create_PDR_list[0].grouped_ie.pdr_id,
1876 local_F_TEID := ts_PFCP_F_TEID_ipv4(gtp_pars.core.local.teid,
Neels Hofmeyr1e311462023-01-11 01:19:12 +01001877 f_inet_addr(gtp_pars.core.local.addr))),
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001878 ts_PFCP_Created_PDR(pdr_id := serq.create_PDR_list[1].grouped_ie.pdr_id,
1879 local_F_TEID := ts_PFCP_F_TEID_ipv4(gtp_pars.access.local.teid,
Neels Hofmeyr1e311462023-01-11 01:19:12 +01001880 f_inet_addr(gtp_pars.access.local.addr)))
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001881 },
1882 load_control_information := omit,
1883 overload_control_information := omit,
1884 node_list := omit,
1885 failed_rule_id := omit,
1886 created_traffic_endpoint_list := omit
1887 };
1888 PFCP.send(r);
1889
1890 /* Expect on Iuh: RAB Assignment Request with IP/port from PFCP Session Est Resp */
1891 rab_sml := ts_RAB_SML_ps(t_RAB_id(23), f_ts_RAB_TLA(gtp_pars.access.local.addr),
1892 gtp_pars.access.local.teid);
1893 rx := valueof(ts_RANAP_RabAssReq(rab_sml));
Neels Hofmeyr735b6562023-03-09 02:51:28 +01001894 f_rua_expect(rx);
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001895
1896 /* Send back RAB Assignment Response via Iuh */
1897 var template RAB_SetupOrModifiedList rab_smdl;
1898 rab_smdl := ts_RAB_SMdL_ps(t_RAB_id(23), f_ts_RAB_TLA(gtp_pars.access.remote.addr),
1899 gtp_pars.access.remote.teid);
1900 tx := valueof(ts_RANAP_RabAssResp(rab_smdl));
1901 RUA.send(tx);
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001902
Neels Hofmeyr6bbfe052023-03-09 02:51:46 +01001903 m := f_pfcp_expect(tr_PFCP_Session_Mod_Req(up_f_seid.seid));
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001904 r := ts_PFCP_Session_Mod_Resp(m.sequence_number, hnbgw_f_seid.seid);
1905 PFCP.send(r);
1906
1907 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 +01001908 f_bssap_expect(tr_RANAP_RabAssResp(rab_smdl));
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001909
1910 f_sleep(2.0);
Harald Welte0d4a8432024-04-04 01:12:11 +02001911 tx := valueof(ts_RANAP_IuReleaseCommand(pars.rab_rel_cause));
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001912 f_iu2iuh(tx);
1913
1914 tx := valueof(ts_RANAP_IuReleaseComplete());
1915 f_iuh2iu(tx);
1916
Neels Hofmeyr6bbfe052023-03-09 02:51:46 +01001917 m := f_pfcp_expect(tr_PFCP_Session_Del_Req(up_f_seid.seid));
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001918 PFCP.send(ts_PFCP_Session_Del_Resp(m.sequence_number, hnbgw_f_seid.seid));
1919
1920 f_sleep(2.0);
1921}
1922
Neels Hofmeyrbacb74f2022-08-29 16:24:12 +02001923testcase TC_ps_rab_assignment_with_pfcp() runs on test_CT {
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001924 var ConnHdlr vc_conn;
Pau Espin Pedrol83a49612022-09-12 21:11:05 +02001925 g_num_hnbs := 1;
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001926 f_init();
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001927 f_sleep(1.0);
1928
Neels Hofmeyrbacb74f2022-08-29 16:24:12 +02001929 vc_conn := f_start_handler_with_pars(refers(f_tc_ps_rab_assignment_with_pfcp), t_pars(7, ps_domain := true));
1930 vc_conn.done;
Neels Hofmeyr3a9140e2023-06-23 04:50:39 +02001931
1932 f_shutdown_helper();
Neels Hofmeyrbacb74f2022-08-29 16:24:12 +02001933}
1934
1935altstep as_disallow_pfcp() runs on ConnHdlr {
1936 [] PFCP.receive(PDU_PFCP:?) {
1937 setverdict(fail, "Received PFCP message, but no PFCP communication expected");
1938 mtc.stop;
1939 }
1940}
1941
1942friend function f_tc_ps_rab_assignment_without_pfcp(charstring id, TestHdlrParams pars) runs on ConnHdlr {
1943 var RANAP_PDU tx;
1944 var RANAP_PDU rx;
1945 timer T := 5.0;
1946
1947 f_init_handler(pars);
1948
1949 f_pfcp_register();
1950 activate(as_disallow_pfcp());
1951
1952 tx := f_build_initial_ue(g_pars);
1953 f_iuh2iu_connect(tx);
1954
1955 var GtpParameters gtp_pars := valueof(t_GtpParameters);
1956 var template RAB_SetupOrModifyList rab_sml;
1957
1958 /* Send RAB Assignment Request */
1959 rab_sml := ts_RAB_SML_ps(t_RAB_id(23), f_ts_RAB_TLA(gtp_pars.core.remote.addr), gtp_pars.core.remote.teid);
1960 tx := valueof(ts_RANAP_RabAssReq(rab_sml));
1961 BSSAP.send(tx);
1962
1963 /* Expect on Iuh: unmodified RAB Assignment Request */
1964 rx := valueof(ts_RANAP_RabAssReq(rab_sml));
Neels Hofmeyr735b6562023-03-09 02:51:28 +01001965 f_rua_expect(rx);
Neels Hofmeyrbacb74f2022-08-29 16:24:12 +02001966
1967 /* Send back RAB Assignment Response via Iuh */
1968 var template RAB_SetupOrModifiedList rab_smdl;
1969 rab_smdl := ts_RAB_SMdL_ps(t_RAB_id(23), f_ts_RAB_TLA(gtp_pars.access.remote.addr),
1970 gtp_pars.access.remote.teid);
1971 tx := valueof(ts_RANAP_RabAssResp(rab_smdl));
1972 RUA.send(tx);
1973
1974 /* Expect on IuPS: unmodified RAB Assignment Response */
Neels Hofmeyrdc416c92023-03-09 02:47:50 +01001975 f_bssap_expect(tr_RANAP_RabAssResp(rab_smdl));
Neels Hofmeyrbacb74f2022-08-29 16:24:12 +02001976
1977 f_sleep(2.0);
Harald Welte0d4a8432024-04-04 01:12:11 +02001978 tx := valueof(ts_RANAP_IuReleaseCommand(pars.rab_rel_cause));
Neels Hofmeyrbacb74f2022-08-29 16:24:12 +02001979 f_iu2iuh(tx);
1980
1981 tx := valueof(ts_RANAP_IuReleaseComplete());
1982 f_iuh2iu(tx);
1983
1984 f_sleep(2.0);
1985}
1986
1987testcase TC_ps_rab_assignment_without_pfcp() runs on test_CT {
1988 var ConnHdlr vc_conn;
1989 f_init();
Neels Hofmeyrbacb74f2022-08-29 16:24:12 +02001990 f_sleep(1.0);
1991
1992 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 +02001993 vc_conn.done;
Neels Hofmeyr3a9140e2023-06-23 04:50:39 +02001994
1995 f_shutdown_helper();
Neels Hofmeyra56e8fd2022-05-08 01:16:55 +02001996}
Daniel Willmann19b8d902022-01-05 09:12:34 +01001997
Neels Hofmeyr7d0e6802023-04-20 20:43:55 +02001998/* Default list of counters for a 'cn' entity to test the cnpool feature. */
1999const CounterNameVals counternames_cnpool := {
2000 { "cnpool:subscr:new", 0 },
2001 { "cnpool:subscr:known", 0 },
2002 { "cnpool:subscr:reattach", 0 },
2003 { "cnpool:subscr:attach_lost", 0 },
2004 { "cnpool:subscr:paged", 0 }
2005};
2006private function f_ctrs_cn_init(boolean ps_domain, integer cn_count := 0,
2007 CounterNameVals counternames := counternames_cnpool) runs on test_CT {
2008 if (ps_domain) {
2009 g_ctr_cn_node_name := "sgsn";
2010 if (cn_count == 0) {
2011 cn_count := NUM_SGSN;
2012 }
2013 } else {
2014 g_ctr_cn_node_name := "msc";
2015 if (cn_count == 0) {
2016 cn_count := NUM_MSC;
2017 }
2018 }
2019 g_ctr_cn := f_counter_name_vals_get_n(IPA_CTRL, g_ctr_cn_node_name, cn_count, counternames);
2020 log("initial " & g_ctr_cn_node_name & " rate counters: ", g_ctr_cn);
2021}
2022
2023/* f_ctrs_cn_init();
2024 * f_do_thing(on_cn := 0);
2025 * f_do_thing(on_cn := 0);
2026 * f_do_other(on_cn := 1);
2027 * f_ctrs_cn_add(0, "thing", 2);
2028 * f_ctrs_cn_add(1, "other");
2029 * f_ctrs_cn_verify();
2030 */
2031private function f_ctrs_cn_verify() runs on test_CT {
2032 log("verifying", g_ctr_cn_node_name, " rate counters: ", g_ctr_cn);
2033 f_counter_name_vals_expect_n(IPA_CTRL, g_ctr_cn_node_name, g_ctr_cn);
2034}
2035
2036/* convenience: f_ctrs_cn_add() and f_ctrs_cn_verify() in one call.
2037 * f_ctrs_cn_init();
2038 * f_do_thing(on_cn := 0);
2039 * f_do_thing(on_cn := 0);
2040 * f_do_thing(on_cn := 0);
2041 * f_ctrs_cn_expect(0, "thing", 3);
2042 */
2043private function f_ctrs_cn_expect(integer cn_nr, charstring countername, integer val := 1) runs on test_CT {
2044 f_ctrs_cn_add(cn_nr, countername, val);
2045 f_ctrs_cn_verify();
2046}
2047
2048private function f_ctrs_cn_add(integer cn_nr, charstring countername, integer val := 1) runs on test_CT {
2049 f_counter_name_vals_list_add(g_ctr_cn, cn_nr, countername, val);
2050}
2051
2052private function f_perform_compl_l3(octetstring nas, boolean do_clear := true, boolean expect_iu_l3 := true)
2053runs on ConnHdlr {
2054 timer T := 10.0;
2055
2056 /* create an expect on the Iu side for the random NAS portion */
2057 if (g_pars.expect_separate_sccp_cr) {
2058 f_ran_register_sccp_cr_without_payload();
2059 } else {
2060 f_ran_register_exp(nas);
2061 }
2062
2063 /* send Connect via Iuh (creating a RUA connection) */
2064 var RANAP_PDU tx := f_build_initial_ue_with_nas(g_pars, nas);
2065 RUA.send(RUA_Conn_Req:{g_pars.ps_domain, tx});
2066
2067 if (expect_iu_l3) {
2068 /* Expect same message to arrive at CN */
2069 f_bssap_expect(tx);
2070 }
2071}
2072
2073private function f_tc_cnpool_compl_l3(charstring id, TestHdlrParams pars) runs on ConnHdlr {
2074 f_init_handler(pars);
2075 f_perform_compl_l3(g_pars.nas_pdu);
2076}
2077
2078private function f_TC_cnpool_compl_l3(boolean ps_domain, octetstring nas_pdu, integer cn_nr,
2079 template (omit) charstring inc_countername := omit) runs on test_CT {
2080 var ConnHdlr vc_conn;
2081 var template (value) TestHdlrParams pars := t_pars(0, ps_domain := ps_domain, cn_nr := cn_nr);
2082 pars.nas_pdu := nas_pdu;
2083 log("XXX ", pars);
2084 vc_conn := f_start_handler_with_pars(refers(f_tc_cnpool_compl_l3), pars);
2085 vc_conn.done;
2086
2087 if (not istemplatekind(inc_countername, "omit")) {
2088 f_ctrs_cn_expect(cn_nr, valueof(inc_countername));
2089 }
2090}
2091
2092function f_TC_cnpool_compl_l3_list(boolean ps_domain, ro_octetstring compl3, Osmocom_Types.ro_integer cn_nrs,
2093 charstring inc_countername) runs on test_CT {
2094 var integer n := lengthof(compl3);
2095 if (n < lengthof(cn_nrs)) {
2096 n := lengthof(cn_nrs);
2097 }
2098 for (var integer i := 0; i < n; i := i + 1) {
2099 var integer cn_nr := cn_nrs[i mod lengthof(cn_nrs)];
2100 f_TC_cnpool_compl_l3(ps_domain, compl3[i mod lengthof(compl3)], cn_nr, inc_countername);
2101 }
2102}
2103
2104type enumerated Compl3Type {
2105 /* CS */
2106 LU,
2107 CMSERV,
2108 PAGRESP,
2109 IMSIDETACH,
2110
2111 /* PS */
2112 ATTACHREQ,
2113 RAUREQ,
2114 DETREQ
2115};
2116
2117private function f_gen_one_compl_l3(Compl3Type compl3type, template (value) MobileIdentityLV mi,
2118 integer ps_nri := -1
2119 ) return octetstring
2120{
2121 /* CS */
2122 if (compl3type == LU) {
2123 return enc_PDU_ML3_MS_NW(valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(mi), '00F110'O)));
2124 }
2125 if (compl3type == CMSERV) {
2126 return enc_PDU_ML3_MS_NW(valueof(ts_CM_SERV_REQ(CM_TYPE_MO_CALL, valueof(mi))));
2127 }
2128 if (compl3type == PAGRESP) {
2129 return enc_PDU_ML3_MS_NW(valueof(ts_PAG_RESP(valueof(mi))));
2130 }
2131 if (compl3type == IMSIDETACH) {
2132 return enc_PDU_ML3_MS_NW(valueof(ts_ML3_MO_MM_IMSI_DET_Ind(valueof(mi))));
2133 }
2134
2135 /* PS */
2136 var template (omit) NetworkResourceIdentifierContainerTLV nri := omit;
2137 if (ps_nri >= 0) {
2138 nri := valueof(ts_GMM_NRI(ps_nri));
2139 }
2140
2141 if (compl3type == ATTACHREQ) {
2142 return enc_PDU_L3_MS_SGSN(valueof(ts_GMM_ATTACH_REQ(valueof(mi), f_RAI('001'H, '01'H, '2a2a'O, '17'O),
2143 nri := nri)));
2144 }
2145 if (compl3type == RAUREQ) {
2146 return enc_PDU_L3_MS_SGSN(valueof(ts_GMM_RAU_REQ(valueof(mi), GPRS_UPD_T_PERIODIC,
2147 f_RAI('001'H, '01'H, '2a2a'O, '17'O),
2148 nri := nri)));
2149 }
2150 if (compl3type == DETREQ) {
2151 return enc_PDU_L3_MS_SGSN(valueof(ts_GMM_DET_REQ_MO_mi(c_GMM_DTT_MO_GPRS, power_off := false,
2152 p_tmsi := valueof(ts_MI_TLV(mi.mobileIdentityV)))));
2153 }
2154
2155 setverdict(fail, "unknown complete layer 3 type");
2156 mtc.stop;
2157}
2158
2159type record of Compl3Type ro_Compl3Type;
2160type record of MobileIdentityLV ro_MobileIdentityLV;
2161type record of octetstring ro_octetstring;
2162
2163/* Generate a list of n Complete Layer 3 NAS PDUs,
2164 * rotating through the message kinds listed in 'types' and the mobile identities in mis.
2165 */
2166private function f_gen_compl_l3(ro_Compl3Type types, ro_MobileIdentityLV mis, integer n) return ro_octetstring
2167{
2168 var ro_octetstring res := {};
2169 for (var integer i := 0; i < n; i := i + 1) {
2170 var integer ti := i mod lengthof(types);
2171 var integer mi := i mod lengthof(mis);
2172 res[i] := f_gen_one_compl_l3(types[ti], mis[mi]);
2173 }
2174 return res;
2175}
2176
2177private function f_gen_mi_imsi(integer n) return MobileIdentityLV
2178{
2179 return valueof(ts_MI_IMSI_LV(f_gen_imsi(n)));
2180}
2181
2182private function f_gen_mi_imsis(integer n) return ro_MobileIdentityLV
2183{
2184 var ro_MobileIdentityLV mis := {};
2185 for (var integer i := 0; i < n; i := i + 1) {
2186 mis[i] := f_gen_mi_imsi(n);
2187 }
2188 return mis;
2189}
2190
2191function f_vty_set_roundrobin_next(TELNETasp_PT VTY, boolean ps_domain, integer cn_nr)
2192{
2193 var charstring msc_sgsn;
2194 if (ps_domain) {
2195 msc_sgsn := "sgsn";
2196 } else {
2197 msc_sgsn := "msc";
2198 }
2199 f_vty_transceive(VTY, "cnpool roundrobin next " & msc_sgsn & " " & int2str(cn_nr));
2200}
2201
2202private function f_gen_compl3_by_domain(boolean ps_domain, integer n, template (omit) ro_MobileIdentityLV mis := omit) return ro_octetstring{
2203 var ro_Compl3Type types;
2204 if (ps_domain) {
2205 types := { ATTACHREQ, RAUREQ, DETREQ };
2206 } else {
2207 types := { LU, CMSERV, PAGRESP, IMSIDETACH };
2208 }
2209 if (istemplatekind(mis, "omit")) {
2210 mis := f_gen_mi_imsis(n);
2211 }
2212 return f_gen_compl_l3(types, valueof(mis), n);
2213}
2214
2215/* Various Complete Layer 3 by IMSI all end up with the first MSC, because the other MSCs are not connected. */
2216testcase TC_mscpool_L3Compl_on_1_cnlink() runs on test_CT {
2217 f_TC_cnpool_L3Compl_on_1_cnlink(ps_domain := false);
2218}
2219testcase TC_sgsnpool_L3Compl_on_1_cnlink() runs on test_CT {
2220 f_TC_cnpool_L3Compl_on_1_cnlink(ps_domain := true);
2221}
2222function f_TC_cnpool_L3Compl_on_1_cnlink(boolean ps_domain) runs on test_CT {
2223
2224 f_init();
2225
2226 f_ctrs_cn_init(ps_domain := ps_domain);
2227
2228 var ro_octetstring compl3 := f_gen_compl3_by_domain(ps_domain, 4);
2229 f_TC_cnpool_compl_l3_list(ps_domain, compl3, {0, 0, 0, 0}, "cnpool:subscr:new");
2230
2231 f_shutdown_helper();
2232}
2233
2234/* Three Layer 3 Complete by IMSI are round-robin'ed across two connected MSCs */
2235testcase TC_mscpool_L3Complete_by_imsi_round_robin() runs on test_CT {
2236 f_TC_cnpool_L3Complete_by_imsi_round_robin(ps_domain := false);
2237}
2238testcase TC_sgsnpool_L3Complete_no_nri_round_robin() runs on test_CT {
2239 f_TC_cnpool_L3Complete_by_imsi_round_robin(ps_domain := true);
2240}
2241function f_TC_cnpool_L3Complete_by_imsi_round_robin(boolean ps_domain) runs on test_CT {
2242
2243 f_init(nr_msc := 2, nr_sgsn := 2);
2244 f_sleep(1.0);
2245
2246 /* Control which MSC gets chosen next by the round-robin, otherwise
2247 * would be randomly affected by which other tests ran before this. */
2248 f_vty_set_roundrobin_next(HNBGWVTY, ps_domain, 0);
2249
2250 f_ctrs_cn_init(ps_domain := ps_domain);
2251
2252 var ro_octetstring compl3 := f_gen_compl3_by_domain(ps_domain, 3);
2253
2254 f_TC_cnpool_compl_l3_list(ps_domain, compl3,
2255 /* Third Complete Layer 3 wraps back to msc 0 */
2256 cn_nrs := {0, 1, 0},
2257 inc_countername := "cnpool:subscr:new");
2258
2259 f_shutdown_helper();
2260}
2261
2262/* Three LU by TMSI are round-robin'ed across two connected MSCs, because they contain a NULL-NRI (0, 1)
2263 * (configured in osmo-hnbgw.cfg). */
2264testcase TC_mscpool_LU_by_tmsi_null_nri_0_round_robin() runs on test_CT {
2265 f_TC_cnpool_LU_by_tmsi_null_nri_N_round_robin(ps_domain := false, nri_val := 0);
2266}
2267/* 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
2268 * than that. */
2269testcase TC_mscpool_LU_by_tmsi_null_nri_1_round_robin() runs on test_CT {
2270 f_TC_cnpool_LU_by_tmsi_null_nri_N_round_robin(ps_domain := false, nri_val := 1);
2271}
2272function f_TC_cnpool_LU_by_tmsi_null_nri_N_round_robin(boolean ps_domain, integer nri_val) runs on test_CT {
2273
2274 f_init(nr_msc := 2, nr_sgsn := 2);
2275 f_sleep(1.0);
2276
2277 /* Control which MSC gets chosen next by the round-robin, otherwise
2278 * would be randomly affected by which other tests ran before this. */
2279 f_vty_set_roundrobin_next(HNBGWVTY, ps_domain, 0);
2280
2281 f_ctrs_cn_init(ps_domain := ps_domain);
2282
2283 var ro_MobileIdentityLV mis := { valueof(ts_MI_TMSI_NRI_LV(nri_val)) };
2284 var ro_octetstring compl3;
2285 if (ps_domain) {
2286 compl3 := {
2287 f_gen_one_compl_l3(ATTACHREQ, mis[0], nri_val)
2288 };
2289 } else {
2290 compl3 := f_gen_compl_l3({LU}, mis, 1);
2291 }
2292
2293 f_TC_cnpool_compl_l3_list(ps_domain, compl3,
2294 /* The third Complete Layer 3 wraps back to msc 0 */
2295 {0, 1, 0},
2296 "cnpool:subscr:reattach");
2297 f_shutdown_helper();
2298}
2299
2300/* Three Layer 3 Complete by TMSI are round-robin'ed across two connected MSCs, because they contain an NRI not
2301 * assigned to any MSC (configured in osmo-hnbgw.cfg). */
2302testcase TC_mscpool_L3Complete_by_tmsi_unassigned_nri_round_robin() runs on test_CT {
2303 f_TC_cnpool_L3Complete_by_tmsi_unassigned_nri_round_robin(ps_domain := false);
2304}
2305function f_TC_cnpool_L3Complete_by_tmsi_unassigned_nri_round_robin(boolean ps_domain) runs on test_CT {
2306
2307 f_init(nr_msc := 2, nr_sgsn := 2);
2308 f_sleep(1.0);
2309
2310 /* Control which MSC gets chosen next by the round-robin, otherwise
2311 * would be randomly affected by which other tests ran before this. */
2312 f_vty_set_roundrobin_next(HNBGWVTY, ps_domain, 0);
2313
2314 f_ctrs_cn_init(ps_domain := ps_domain);
2315
2316 /* 3 NRIs that are not assigned to any MSC */
2317 var ro_MobileIdentityLV mis := {
2318 valueof(ts_MI_TMSI_NRI_LV(1000)),
2319 valueof(ts_MI_TMSI_NRI_LV(768)),
2320 valueof(ts_MI_TMSI_NRI_LV(819))
2321 };
2322
2323 var ro_octetstring compl3 := f_gen_compl3_by_domain(ps_domain, 3, mis);
2324 f_TC_cnpool_compl_l3_list(ps_domain, compl3, { 0, 1, 0 }, "cnpool:subscr:new");
2325
2326 f_shutdown_helper();
2327}
2328
2329/* Three Layer 3 Complete by TMSI are round-robin'ed across two connected MSCs, because they contain an NRI
2330 * assigned to a CN link that is currently not connected (configured in osmo-hnbgw.cfg). */
2331testcase TC_mscpool_L3Complete_by_tmsi_valid_nri_msc_not_connected_round_robin() runs on test_CT {
2332 f_TC_cnpool_L3Complete_by_tmsi_valid_nri_msc_not_connected_round_robin(ps_domain := false);
2333}
2334function f_TC_cnpool_L3Complete_by_tmsi_valid_nri_msc_not_connected_round_robin(boolean ps_domain) runs on test_CT {
2335
2336 f_init(nr_msc := 2, nr_sgsn := 2);
2337 f_sleep(1.0);
2338
2339 /* Control which MSC gets chosen next by the round-robin, otherwise
2340 * would be randomly affected by which other tests ran before this. */
2341 f_vty_set_roundrobin_next(HNBGWVTY, ps_domain, 0);
2342
2343 f_ctrs_cn_init(ps_domain := ps_domain);
2344
2345 /* 3 NRIs that are assigned to an unconnected MSC */
2346 var ro_MobileIdentityLV mis := {
2347 valueof(ts_MI_TMSI_NRI_LV(512)),
2348 valueof(ts_MI_TMSI_NRI_LV(767)),
2349 valueof(ts_MI_TMSI_NRI_LV(750))
2350 };
2351
2352 var ro_octetstring compl3 := f_gen_compl3_by_domain(ps_domain, 3, mis);
2353
2354 f_TC_cnpool_compl_l3(ps_domain, compl3[0], cn_nr := 0);
2355 f_ctrs_cn_add(2, "cnpool:subscr:attach_lost");
2356 f_ctrs_cn_add(0, "cnpool:subscr:new");
2357 f_ctrs_cn_verify();
2358
2359 f_TC_cnpool_compl_l3(ps_domain, compl3[1], cn_nr := 1);
2360 f_ctrs_cn_add(2, "cnpool:subscr:attach_lost");
2361 f_ctrs_cn_add(1, "cnpool:subscr:new");
2362 f_ctrs_cn_verify();
2363
2364 f_TC_cnpool_compl_l3(ps_domain, compl3[2], cn_nr := 0);
2365 f_ctrs_cn_add(2, "cnpool:subscr:attach_lost");
2366 f_ctrs_cn_add(0, "cnpool:subscr:new");
2367 f_ctrs_cn_verify();
2368
2369 f_shutdown_helper();
2370}
2371
2372/* Three Layer 3 Complete by TMSI with valid NRI for the second MSC are all directed to the second MSC (configured in
2373 * osmo-hnbgw.cfg). */
2374testcase TC_mscpool_L3Complete_by_tmsi_valid_nri_1() runs on test_CT {
2375 f_TC_cnpool_L3Complete_valid_nri_1(ps_domain := false);
2376}
2377testcase TC_sgsnpool_L3Complete_valid_nri_1() runs on test_CT {
2378 f_TC_cnpool_L3Complete_valid_nri_1(ps_domain := true);
2379}
2380function f_TC_cnpool_L3Complete_valid_nri_1(boolean ps_domain) runs on test_CT {
2381
2382 f_init(nr_msc := 2, nr_sgsn := 2);
2383 f_sleep(1.0);
2384
2385 /* All TMSIs in this test point at the second MSC, set the round robin to point at the first MSC to make sure
2386 * this is not using round-robin. */
2387 f_vty_set_roundrobin_next(HNBGWVTY, ps_domain, 0);
2388
2389 f_ctrs_cn_init(ps_domain := ps_domain);
2390
2391 var ro_octetstring compl3;
2392
2393 /* 3 NRIs of the second MSC's range (256-511) */
2394 var ro_MobileIdentityLV mis := {
2395 valueof(ts_MI_TMSI_NRI_LV(256)),
2396 valueof(ts_MI_TMSI_NRI_LV(260)),
2397 valueof(ts_MI_TMSI_NRI_LV(511))
2398 };
2399 if (ps_domain) {
2400 compl3 := {
2401 f_gen_one_compl_l3(RAUREQ, mis[0], 256),
2402 f_gen_one_compl_l3(RAUREQ, mis[1], 260),
2403 f_gen_one_compl_l3(RAUREQ, mis[2], 511)
2404 };
2405 } else {
2406 compl3 := f_gen_compl3_by_domain(ps_domain, 3, mis);
2407 }
2408
2409 f_TC_cnpool_compl_l3_list(ps_domain, compl3, {1, 1, 1}, "cnpool:subscr:known");
2410
2411 f_shutdown_helper();
2412}
2413
2414/* Layer 3 Complete by TMSI with valid NRI for the third MSC are directed to the third MSC (configured in osmo-hnbgw.cfg),
2415 * while a round-robin remains unaffected by that. */
2416testcase TC_mscpool_L3Complete_by_tmsi_valid_nri_2() runs on test_CT {
2417 f_TC_cnpool_L3Complete_valid_nri_2(ps_domain := false);
2418}
2419testcase TC_sgsnpool_L3Complete_valid_nri_2() runs on test_CT {
2420 f_TC_cnpool_L3Complete_valid_nri_2(ps_domain := true);
2421}
2422function f_TC_cnpool_L3Complete_valid_nri_2(boolean ps_domain) runs on test_CT {
2423
2424 f_init(nr_msc := 3, nr_sgsn := 3);
2425 f_sleep(1.0);
2426
2427 /* All TMSIs in this test point at the third MSC, set the round robin to point at the second MSC to make sure
2428 * this is not using round-robin. */
2429 f_vty_set_roundrobin_next(HNBGWVTY, ps_domain, 1);
2430
2431 f_ctrs_cn_init(ps_domain := ps_domain);
2432
2433 var ro_octetstring compl3;
2434
2435 /* 2 NRIs of the third MSC's range (512-767) */
2436 var ro_MobileIdentityLV mis := {
2437 valueof(ts_MI_TMSI_NRI_LV(512)),
2438 valueof(ts_MI_TMSI_NRI_LV(678))
2439 };
2440 if (ps_domain) {
2441 compl3 := {
2442 f_gen_one_compl_l3(ATTACHREQ, mis[0], 512),
2443 f_gen_one_compl_l3(ATTACHREQ, mis[1], 678)
2444 };
2445 } else {
2446 compl3 := f_gen_compl3_by_domain(ps_domain, 2, mis);
2447 }
2448
2449 f_TC_cnpool_compl_l3_list(ps_domain, compl3, {2, 2}, "cnpool:subscr:known");
2450
2451 /* The above forwardings to third MSC have not affected the round robin, which still points at the second MSC */
2452 f_TC_cnpool_compl_l3_list(ps_domain, f_gen_compl3_by_domain(ps_domain, 1), {1}, "cnpool:subscr:new");
2453
2454 f_shutdown_helper();
2455}
2456
2457/* LU with a TMSI but indicating a different PLMN in its previous LAI: ignore the NRI. */
2458testcase TC_mscpool_LU_by_tmsi_from_other_PLMN() runs on test_CT {
2459 f_TC_cnpool_nri_from_other_PLMN(ps_domain := false);
2460}
2461testcase TC_sgsnpool_nri_from_other_PLMN() runs on test_CT {
2462 f_TC_cnpool_nri_from_other_PLMN(ps_domain := true);
2463}
2464function f_TC_cnpool_nri_from_other_PLMN(boolean ps_domain) runs on test_CT {
2465
2466 f_init(nr_msc := 3, nr_sgsn := 3);
2467 f_sleep(1.0);
2468
2469 /* The TMSIs in this test points at the second MSC, but since it is from a different PLMN, round-robin is used
2470 * instead, and hits msc 0. */
2471 f_vty_set_roundrobin_next(HNBGWVTY, ps_domain, 0);
2472
2473 f_ctrs_cn_init(ps_domain := ps_domain);
2474
2475 var ro_octetstring compl3;
2476
2477 var ro_MobileIdentityLV mis := {
2478 valueof(ts_MI_TMSI_NRI_LV(260)),
2479 valueof(ts_MI_TMSI_NRI_LV(555))
2480 };
2481 if (ps_domain) {
2482 compl3 := {
2483 /* An NRI of the second MSC's range (256-511), but a PLMN that doesn't match with osmo-hnbgw.cfg */
2484 enc_PDU_L3_MS_SGSN(valueof(ts_GMM_ATTACH_REQ(mis[0], f_RAI('999'H, '99'H, '2a2a'O,
2485 '17'O),
2486 nri := ts_GMM_NRI(260)
2487 ))),
2488 /* An NRI of the third MSC's range (512-767) and a matching PLMN gets directed by NRI. */
2489 f_gen_one_compl_l3(ATTACHREQ, mis[1], 555)
2490 }
2491 } else {
2492 compl3 := {
2493 /* An NRI of the second MSC's range (256-511), but a PLMN that doesn't match with osmo-hnbgw.cfg */
2494 enc_PDU_ML3_MS_NW(valueof(ts_LU_REQ(LU_Type_IMSI_Attach, mis[0], '99F999'O))),
2495 /* An NRI of the third MSC's range (512-767) and a matching PLMN gets directed by NRI. */
2496 enc_PDU_ML3_MS_NW(valueof(ts_LU_REQ(LU_Type_IMSI_Attach, mis[1], '00F110'O)))
2497 };
2498 }
2499
2500 /* Foreign NRI: roundrobin */
2501 f_TC_cnpool_compl_l3(ps_domain, compl3[0], cn_nr := 0, inc_countername := "cnpool:subscr:new");
2502
2503 /* Local NRI: matching msc */
2504 f_TC_cnpool_compl_l3(ps_domain, compl3[1], cn_nr := 2, inc_countername := "cnpool:subscr:known");
2505
2506 f_shutdown_helper();
2507}
2508
Neels Hofmeyrb1bf16d2023-06-27 02:10:04 +02002509/* Make sure that whichever MSC paged a subscriber will also get the Paging Response. Page by IMSI, which would be
2510 * round-robined to another MSC, to make sure the Paging->Response relation is stronger than the NRI->MSC mapping. */
2511friend function f_tc_mscpool_paging_imsi(charstring id, TestHdlrParams pars) runs on ConnHdlr {
2512 f_init_handler(pars);
2513
2514 var hexstring imsi := '001010000000123'H;
2515 var RANAP_IEs.CN_DomainIndicator domain_ind;
2516 if (pars.ps_domain) {
2517 domain_ind := ps_domain;
2518 } else {
2519 domain_ind := cs_domain;
2520 }
2521 var template (value) RANAP_PDU paging := ts_RANAP_Paging(domain_ind, imsi_hex2oct(imsi));
2522 BSSAP.send(ts_RANAP_UNITDATA_req(pars.sccp_addr_hnbgw, pars.sccp_addr_msc, paging));
2523 /* TODO: Expect RUA ConnectionlessTransfer Paging (on all HNB).
2524 * We could verify the Paging sent from osmo-hnbgw to RUA with some effort,
2525 * but, this test does not care whether the Paging was forwarded to RUA or not, only that osmo-hnbgw *received*
2526 * the Paging. In the CN pool decisions, osmo-hnbgw should match up Paging Response to an earlier Paging.
2527 */
2528
2529 f_sleep(1.0);
2530
2531 /* Despite the round robin pointing at the second MSC ('roundrobin next msc 1'), the earlier Paging for the same IMSI
2532 * causes this Paging Response to go to the first MSC ('msc 0'). */
2533 f_perform_compl_l3(f_gen_one_compl_l3(PAGRESP, ts_MI_IMSI_LV(imsi)));
2534 f_sleep(1.0);
2535}
2536
2537testcase TC_mscpool_paging_imsi() runs on test_CT {
2538 f_init(nr_msc := 3);
2539 f_sleep(1.0);
2540
2541 var boolean ps_domain := false;
2542
2543 /* Testing a Paging on the first MSC to get a Paging Response back to the first MSC. Set round robin to the
2544 * second MSC to make sure we're getting the Paging logic, not a coincidental round robin match. */
2545 f_vty_set_roundrobin_next(HNBGWVTY, ps_domain, 0);
2546
2547 f_ctrs_cn_init(ps_domain := ps_domain);
2548
2549 var ConnHdlr vc_conn1;
2550 var template (value) TestHdlrParams pars1 := t_pars(0, ps_domain := ps_domain, cn_nr := 0);
2551 pars1.sccp_addr_hnbgw := g_cn[valueof(pars1.cn_idx)].sccp_addr_peer;
2552 pars1.sccp_addr_msc := g_cn[valueof(pars1.cn_idx)].sccp_addr_own;
2553 vc_conn1 := f_start_handler_with_pars(refers(f_tc_mscpool_paging_imsi), pars1);
2554 vc_conn1.done;
2555 f_ctrs_cn_expect(0, "cnpool:subscr:paged");
2556 f_shutdown_helper();
2557}
2558
2559/* Make sure that whichever MSC paged a subscriber will also get the Paging Response. Page by TMSI with an NRI value
2560 * that matches a different MSC, to make sure the Paging->Response relation is stronger than the NRI->MSC mapping. */
2561friend function f_tc_mscpool_paging_tmsi(charstring id, TestHdlrParams pars) runs on ConnHdlr {
2562 f_init_handler(pars);
2563
2564 var hexstring imsi := '001010000000124'H;
2565 var integer nri_v := 300; /* <-- second MSC's NRI */
2566 var octetstring tmsi := f_gen_tmsi(suffix := 0, nri_v := nri_v);
2567
2568 var RANAP_IEs.CN_DomainIndicator domain_ind;
2569 if (pars.ps_domain) {
2570 domain_ind := ps_domain;
2571 } else {
2572 domain_ind := cs_domain;
2573 }
2574 var template (value) RANAP_PDU paging := ts_RANAP_Paging_temp_id(domain_ind, imsi_hex2oct(imsi),
2575 ts_RANAP_TemporaryUE_ID_TMSI(tmsi));
2576 BSSAP.send(ts_RANAP_UNITDATA_req(pars.sccp_addr_hnbgw, pars.sccp_addr_msc, paging));
2577 /* TODO: Expect RUA ConnectionlessTransfer Paging (on all HNB).
2578 * We could verify the Paging sent from osmo-hnbgw to RUA with some effort,
2579 * but, this test does not care whether the Paging was forwarded to RUA or not, only that osmo-hnbgw *received*
2580 * the Paging. In the CN pool decisions, osmo-hnbgw should match up Paging Response to an earlier Paging.
2581 */
2582
2583 f_sleep(1.0);
2584
2585 /* Despite the round robin pointing at the third MSC ('roundrobin next msc 2'), the earlier Paging for the same
2586 * TMSI causes this Paging Response to go to the first MSC ('msc 0'). */
2587 f_perform_compl_l3(f_gen_one_compl_l3(PAGRESP, ts_MI_TMSI_NRI_LV(nri_v)));
2588 f_sleep(1.0);
2589}
2590testcase TC_mscpool_paging_tmsi() runs on test_CT {
2591 f_init(nr_msc := 3);
2592 f_sleep(1.0);
2593
2594 var boolean ps_domain := false;
2595
2596 /* Testing a Paging on the first MSC to get a Paging Response back to the first MSC. Set round robin to the
2597 * third MSC to make sure we're getting the Paging logic, not a coincidental round robin match. */
2598 f_vty_set_roundrobin_next(HNBGWVTY, ps_domain, 0);
2599
2600 f_ctrs_cn_init(ps_domain := ps_domain);
2601
2602 var ConnHdlr vc_conn1;
2603 var template (value) TestHdlrParams pars1 := t_pars(0, ps_domain := ps_domain, cn_nr := 0);
2604 pars1.sccp_addr_hnbgw := g_cn[valueof(pars1.cn_idx)].sccp_addr_peer;
2605 pars1.sccp_addr_msc := g_cn[valueof(pars1.cn_idx)].sccp_addr_own;
2606 vc_conn1 := f_start_handler_with_pars(refers(f_tc_mscpool_paging_tmsi), pars1);
2607 vc_conn1.done;
2608 f_ctrs_cn_expect(0, "cnpool:subscr:paged");
2609 f_shutdown_helper();
2610}
2611
Neels Hofmeyr7d0e6802023-04-20 20:43:55 +02002612/* For round-robin, skip a CN link that has 'no allow-attach' set. */
2613testcase TC_mscpool_no_allow_attach_round_robin() runs on test_CT {
2614
2615 f_init(nr_msc := 3);
2616 f_sleep(1.0);
2617
2618 var boolean ps_domain := false;
2619
2620 /* Mark the second MSC as offloading, round-robin should skip this MSC now. */
2621 f_vty_cnlink_allow_attach(HNBGWVTY, ps_domain, {true, false, true});
2622
2623 /* Control which MSC gets chosen next by the round-robin, otherwise
2624 * would be randomly affected by which other tests ran before this. */
2625 f_vty_set_roundrobin_next(HNBGWVTY, ps_domain, 0);
2626
2627 f_ctrs_cn_init(ps_domain := ps_domain);
2628
2629 f_TC_cnpool_compl_l3_list(ps_domain, f_gen_compl3_by_domain(ps_domain, 3),
2630 /* msc 1 is skipped */
2631 {0, 2, 0},
2632 "cnpool:subscr:new");
2633
2634 f_shutdown_helper();
2635}
2636
2637/* An MSC that has 'no allow-attach' set should still serve subscribers that are already attached according to their
2638 * TMSI NRI. */
2639testcase TC_mscpool_no_allow_attach_valid_nri() runs on test_CT {
2640
2641 f_init(nr_msc := 3);
2642 f_sleep(1.0);
2643
2644 var boolean ps_domain := false;
2645
2646 /* Mark the second MSC as offloading, round-robin should skip this MSC now. */
2647 f_vty_cnlink_allow_attach(HNBGWVTY, ps_domain, {true, false, true});
2648
2649 /* Control which MSC gets chosen next by the round-robin, otherwise
2650 * would be randomly affected by which other tests ran before this. */
2651 f_vty_set_roundrobin_next(HNBGWVTY, ps_domain, 0);
2652
2653 f_ctrs_cn_init(ps_domain := ps_domain);
2654
2655 var ro_MobileIdentityLV mis := {
2656 valueof(ts_MI_TMSI_NRI_LV(260)),
2657 valueof(ts_MI_IMSI_LV('001010000000002'H)),
2658 valueof(ts_MI_IMSI_LV('001010000000003'H))
2659 };
2660
2661 var ro_octetstring compl3 := f_gen_compl3_by_domain(ps_domain, 3, mis);
2662
2663 /* Round robin points at msc 0, but the valid NRI directs to msc 1, even though msc 1 has 'no allow-attach'. */
2664 f_TC_cnpool_compl_l3(ps_domain, compl3[0], cn_nr := 1, inc_countername := "cnpool:subscr:known");
2665
2666 /* Normal round robin skips msc 1, because it has 'no allow-attach' */
2667 f_TC_cnpool_compl_l3(ps_domain, compl3[1], cn_nr := 0, inc_countername := "cnpool:subscr:new");
2668 f_TC_cnpool_compl_l3(ps_domain, compl3[2], cn_nr := 2, inc_countername := "cnpool:subscr:new");
2669
2670 f_shutdown_helper();
2671}
2672
2673/* When a peer point-code gets an SCCP N-PCSTATE saying it is unreachable, immediately mark the CN link as unusable. */
2674testcase TC_mscpool_sccp_n_pcstate_detaches_cnlink() runs on test_CT {
2675 f_TC_cnpool_sccp_n_pcstate_detaches_cnlink(ps_domain := false);
2676}
2677testcase TC_sgsnpool_sccp_n_pcstate_detaches_cnlink() runs on test_CT {
2678 f_TC_cnpool_sccp_n_pcstate_detaches_cnlink(ps_domain := true);
2679}
2680function f_TC_cnpool_sccp_n_pcstate_detaches_cnlink(boolean ps_domain) runs on test_CT
2681{
2682
2683 f_init(nr_msc := 2, nr_sgsn := 2);
2684 f_sleep(1.0);
2685
2686 /* Control which MSC gets chosen next by the round-robin, otherwise
2687 * would be randomly affected by which other tests ran before this. */
2688 f_vty_set_roundrobin_next(HNBGWVTY, ps_domain, 0);
2689
2690 f_ctrs_cn_init(ps_domain := ps_domain);
2691
2692 var ro_octetstring compl3 := f_gen_compl3_by_domain(ps_domain, 3);
2693
2694 f_TC_cnpool_compl_l3(ps_domain, compl3[0], cn_nr := 0, inc_countername := "cnpool:subscr:new");
2695 f_TC_cnpool_compl_l3(ps_domain, compl3[1], cn_nr := 1, inc_countername := "cnpool:subscr:new");
2696
2697 f_logp(HNBGWVTY, "disconnecting msc0");
2698 f_cn_idx_disconnect(f_cn_idx(ps_domain, 0));
2699
2700 /* Now round-robin would wrap to the first MSC, but since the first MSC is disconnected, it wraps around to the
2701 * second. */
2702 f_TC_cnpool_compl_l3(ps_domain, compl3[2], cn_nr := 1, inc_countername := "cnpool:subscr:new");
2703
2704 f_shutdown_helper();
2705}
2706
2707/* When a CN link point-code gets an SCCP N-PCSTATE saying it is now reachable, immediately trigger RESET and bring up the
2708 * MSC. */
2709testcase TC_mscpool_sccp_n_pcstate_attaches_cnlink() runs on test_CT {
2710 f_TC_cnpool_sccp_n_pcstate_attaches_cnlink(ps_domain := false);
2711}
2712testcase TC_sgsnpool_sccp_n_pcstate_attaches_cnlink() runs on test_CT {
2713 f_TC_cnpool_sccp_n_pcstate_attaches_cnlink(ps_domain := true);
2714}
2715function f_TC_cnpool_sccp_n_pcstate_attaches_cnlink(boolean ps_domain) runs on test_CT
2716{
2717 f_init(nr_msc := 1, nr_sgsn := 1);
2718 f_sleep(1.0);
2719
2720 /* Control which MSC gets chosen next by the round-robin, otherwise
2721 * would be randomly affected by which other tests ran before this. */
2722 f_vty_set_roundrobin_next(HNBGWVTY, ps_domain, 0);
2723
2724 var ro_octetstring compl3 := f_gen_compl3_by_domain(ps_domain, 3);
2725
2726 f_ctrs_cn_init(ps_domain := ps_domain);
2727
2728 /* There is only one MSC, round robin stays on msc0 */
2729 f_TC_cnpool_compl_l3(ps_domain := ps_domain, nas_pdu := compl3[0], cn_nr := 0, inc_countername := "cnpool:subscr:new");
2730 f_TC_cnpool_compl_l3(ps_domain := ps_domain, nas_pdu := compl3[1], cn_nr := 0, inc_countername := "cnpool:subscr:new");
2731
2732 f_logp(HNBGWVTY, "connecting cnlink 1");
2733 f_cn_nr_init(ps_domain, 1);
2734 f_vty_cnlink_allow_attach(HNBGWVTY, ps_domain, { true, true });
2735 f_sleep(1.0);
2736
2737 /* This time round-robin wraps to the second MSC, because it is now online. */
2738 f_TC_cnpool_compl_l3(ps_domain := ps_domain, nas_pdu := compl3[2], cn_nr := 1, inc_countername := "cnpool:subscr:new");
2739
2740 f_shutdown_helper();
2741}
2742
Neels Hofmeyrd019cc02023-06-02 16:31:23 +02002743private function f_vty_add_sccp_addr(TELNETasp_PT pt, charstring addr_name, charstring pc, integer cs7_nr := 0)
2744{
2745 f_vty_enter_config(pt);
2746 f_vty_transceive(pt, "cs7 instance 0");
2747 f_vty_transceive(pt, "sccp-address " & addr_name);
2748 f_vty_transceive(pt, "point-code " & pc);
2749 f_vty_transceive(pt, "end");
2750}
2751
2752private function f_vty_set_cnlink_addr(TELNETasp_PT pt, charstring cnlink_and_nr, charstring addr_name)
2753{
2754 f_vty_enter_config(pt);
2755 f_vty_transceive(pt, cnlink_and_nr);
2756 f_vty_transceive(pt, "remote-addr " & addr_name);
2757 f_vty_transceive(pt, "end");
2758}
2759
2760private function f_vty_apply_sccp(TELNETasp_PT pt)
2761{
2762 f_vty_enter_config(pt);
2763 f_vty_transceive(pt, "apply sccp");
2764 f_vty_transceive(pt, "end");
2765}
2766
2767template (present) RUA_Disc_Req tr_RUA_Disc_Req := {
2768 ranap := ?,
2769 cause := ?
2770};
2771
2772/* With a cnlink up, change the SCCP address, and verify that it restarts upon vty 'apply sccp' */
2773private function f_tc_apply_sccp(charstring id, TestHdlrParams pars) runs on ConnHdlr
2774{
2775 f_init_handler(pars);
2776 f_perform_compl_l3(f_gen_compl3_by_domain(pars.ps_domain, 1)[0]);
2777
2778 f_sleep(1.0);
2779 f_logp(HNBGWVTY, "Changing SCCP address, don't apply yet");
2780
2781 f_vty_add_sccp_addr(HNBGWVTY, "msc-foo", "0.42.4");
2782 f_vty_set_cnlink_addr(HNBGWVTY, "msc 0", "msc-foo");
2783
2784 /* No effect yet, link still open both ways */
2785 f_sleep(1.0);
2786 f_iuh2iu(ts_RANAP_DirectTransfer(f_rnd_octstring(10)));
2787 f_iu2iuh(ts_RANAP_DirectTransfer(f_rnd_octstring(10)));
2788
2789 f_logp(HNBGWVTY, "Apply SCCP address changes");
2790 f_vty_apply_sccp(HNBGWVTY);
2791
2792 /* We modified the SCCP configuration, expect disconnect of UE that was active on the aborted link. */
2793 RUA.receive(RUA_Disc_Ind:?);
2794 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_IND);
2795
2796 /* Would be nice to test reconnection on the other point-code, too. That would require another cnlink in
2797 * osmo-stp.cfg and module parameters... */
2798
2799 f_sleep(1.0);
2800}
2801testcase TC_apply_sccp() runs on test_CT
2802{
2803 f_init();
2804 f_sleep(1.0);
2805
2806 var ConnHdlr vc_conn;
2807 var template (value) TestHdlrParams pars := t_pars(0);
2808 vc_conn := f_start_handler_with_pars(refers(f_tc_apply_sccp), pars);
2809 vc_conn.done;
2810
2811 f_shutdown_helper();
2812}
2813
Neels Hofmeyrc3c01d32023-11-07 02:19:00 +01002814/* In the field, we encountered a "normal" RAB Assignment that concludes successfully, followed by another RAB
2815 * Assignment that has different SDU subflow parameters, and does not contain RTP information. At the time of writing,
2816 * it seems that the second RAB Assignment causes a crash. Play through this scenario. */
2817friend function f_tc_second_rab_assignment(charstring id, TestHdlrParams pars) runs on ConnHdlr {
2818 var MgcpCommand mgcp_cmd;
2819 var RANAP_PDU tx;
2820 timer T := 5.0;
2821
2822 f_init_handler(pars);
2823 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
2824
2825 tx := f_build_initial_ue(g_pars);
2826 f_iuh2iu_connect(tx);
2827
2828 f_create_rab(pars.mgcp_pars);
2829
2830 /* Now send a second RAB Assignment with different subflows and omitting transportLayerInformation. (Assuming
2831 * the first RAB Assignment's transportLayerInformation remains in use unchanged.) */
2832 var template RAB_SetupOrModifyList rab_sml;
2833 rab_sml := ts_RAB_SML2(t_RAB_id(23),
2834 ts_RabParams,
2835 user_plane_info := omit,
2836 transport_layer_info := omit);
2837 tx := valueof(ts_RANAP_RabAssReq(rab_sml));
2838 BSSAP.send(tx);
2839 T.start;
2840
2841 /* Expect this secondary RAB Assignment to go through unchanged. */
2842 f_rua_expect(tx);
2843
2844 /* I'm guessing that the RAB Assignment Response also omits transportLayerInformation, so far not known because
2845 * osmo-hnbgw crashed before we could receive the response. */
2846
2847 /* Send back RAB Assignment Response via Iuh */
2848 var template RAB_SetupOrModifiedList rab_smdl;
2849 rab_smdl := ts_RAB_SMdL_no_tla(t_RAB_id(23));
2850 tx := valueof(ts_RANAP_RabAssResp(rab_smdl));
2851 RUA.send(tx);
2852 f_bssap_expect(tx);
2853
2854 /* Send Iu Release */
Harald Welte0d4a8432024-04-04 01:12:11 +02002855 tx := valueof(ts_RANAP_IuReleaseCommand(pars.rab_rel_cause));
Neels Hofmeyrc3c01d32023-11-07 02:19:00 +01002856 f_iu2iuh(tx);
2857
2858 T.start;
2859 alt {
2860 [] as_mgcp_dlcx(pars) {}
2861 [] T.timeout {
2862 setverdict(fail, "Timeout waiting for DLCX");
2863 }
2864 }
2865
2866 tx := valueof(ts_RANAP_IuReleaseComplete());
2867 f_iuh2iu(tx);
2868}
2869
2870testcase TC_second_rab_assignment() runs on test_CT {
2871 var ConnHdlr vc_conn;
2872 g_num_hnbs := 1;
2873 f_init();
2874
2875 vc_conn := f_start_handler_with_pars(refers(f_tc_second_rab_assignment), t_pars(3));
2876 vc_conn.done;
2877
2878 f_shutdown_helper();
2879}
2880
Daniel Willmann19b8d902022-01-05 09:12:34 +01002881control {
2882 execute(TC_hnb_register());
Daniel Willmannc79679a2022-08-23 17:48:39 +02002883 execute(TC_hnb_register_duplicate());
Pau Espin Pedrolacf4f222022-09-27 14:33:40 +02002884 execute(TC_hnb_register_duplicate_reuse_sctp_assoc());
Harald Welteaf3e2162024-03-27 21:54:20 +01002885 execute(TC_ue_register());
Harald Weltef60044d2024-04-04 00:54:34 +02002886 execute(TC_ue_register_tmsi_lai());
Harald Welteaf3e2162024-03-27 21:54:20 +01002887 execute(TC_ue_register_before_hnb_register());
Daniel Willmann19b8d902022-01-05 09:12:34 +01002888 execute(TC_ranap_cs_initial_ue());
2889 execute(TC_ranap_ps_initial_ue());
Neels Hofmeyrf0b9ed12022-06-07 17:46:32 +02002890 execute(TC_ranap_cs_initial_ue_empty_cr());
2891 execute(TC_ranap_ps_initial_ue_empty_cr());
Daniel Willmann19b8d902022-01-05 09:12:34 +01002892 execute(TC_ranap_cs_bidir());
2893 execute(TC_ranap_ps_bidir());
2894 execute(TC_rab_assignment());
2895 execute(TC_rab_release());
Harald Weltef95ab2d2024-04-04 01:32:20 +02002896 execute(TC_rab_release_abnormal());
Daniel Willmann3e15b7b2022-02-21 17:07:02 +01002897 execute(TC_rab_assign_fail());
Daniel Willmann37c877f2022-02-22 16:47:06 +01002898 execute(TC_rab_assign_mgcp_to());
Pau Espin Pedrolaf746502023-11-29 16:18:28 +01002899 execute(TC_rab_assign_mgw_iuup_addr_chg());
Daniel Willmann19b8d902022-01-05 09:12:34 +01002900 execute(TC_ranap_cs_mo_disconnect());
2901 execute(TC_ranap_ps_mo_disconnect());
Neels Hofmeyrbacb74f2022-08-29 16:24:12 +02002902
2903 if (mp_enable_pfcp_tests) {
2904 execute(TC_ps_rab_assignment_with_pfcp());
2905 } else {
2906 execute(TC_ps_rab_assignment_without_pfcp());
2907 }
Pau Espin Pedrolf0b9fa02022-09-12 13:31:07 +02002908
Neels Hofmeyr7d0e6802023-04-20 20:43:55 +02002909 execute( TC_mscpool_L3Compl_on_1_cnlink() );
2910 execute( TC_mscpool_L3Complete_by_imsi_round_robin() );
2911 execute( TC_mscpool_LU_by_tmsi_null_nri_0_round_robin() );
2912 execute( TC_mscpool_LU_by_tmsi_null_nri_1_round_robin() );
2913 execute( TC_mscpool_L3Complete_by_tmsi_unassigned_nri_round_robin() );
2914 execute( TC_mscpool_L3Complete_by_tmsi_valid_nri_msc_not_connected_round_robin() );
2915 execute( TC_mscpool_L3Complete_by_tmsi_valid_nri_1() );
2916 execute( TC_mscpool_L3Complete_by_tmsi_valid_nri_2() );
2917 execute( TC_mscpool_LU_by_tmsi_from_other_PLMN() );
Neels Hofmeyrb1bf16d2023-06-27 02:10:04 +02002918 execute( TC_mscpool_paging_imsi() );
2919 execute( TC_mscpool_paging_tmsi() );
Neels Hofmeyr7d0e6802023-04-20 20:43:55 +02002920 execute( TC_mscpool_no_allow_attach_round_robin() );
2921 execute( TC_mscpool_no_allow_attach_valid_nri() );
2922 execute( TC_mscpool_sccp_n_pcstate_detaches_cnlink() );
2923 execute( TC_mscpool_sccp_n_pcstate_attaches_cnlink() );
2924
2925 execute( TC_sgsnpool_L3Compl_on_1_cnlink() );
2926 execute( TC_sgsnpool_L3Complete_no_nri_round_robin() );
2927 execute( TC_sgsnpool_L3Complete_valid_nri_1() );
2928 execute( TC_sgsnpool_L3Complete_valid_nri_2() );
2929 execute( TC_sgsnpool_nri_from_other_PLMN() );
2930 execute( TC_sgsnpool_sccp_n_pcstate_detaches_cnlink() );
2931 execute( TC_sgsnpool_sccp_n_pcstate_attaches_cnlink() );
2932
Oliver Smithaa919b42023-11-14 11:30:55 +01002933 /* Run only on nightly since it makes osmo-hnbgw <= 1.5.0 crash: OS#6253 */
2934 if (f_osmo_repo_is("nightly")) {
2935 execute(TC_second_rab_assignment());
2936 }
Neels Hofmeyrc3c01d32023-11-07 02:19:00 +01002937
Pau Espin Pedrolf0b9fa02022-09-12 13:31:07 +02002938 /* Run at the end since it makes osmo-hnbgw <= 1.3.0 crash: OS#5676 */
2939 execute(TC_hnb_reregister_reuse_sctp_assoc());
Neels Hofmeyrd019cc02023-06-02 16:31:23 +02002940
2941 /* Run at the end since it messes with the SCCP config */
2942 execute( TC_apply_sccp() );
Daniel Willmann19b8d902022-01-05 09:12:34 +01002943}
2944
2945}